Beispiel #1
0
 def organize_workspace_groups(self,
                               workspace_groups: OrderedWorkspaceGroups,
                               monitor_name: Optional[str] = None) -> None:
     if monitor_name is None:
         monitor_name = self.i3_proxy.get_focused_monitor_name()
     monitor_index = self.i3_proxy.get_monitor_index(monitor_name)
     group_to_all_workspaces = ws_names.get_group_to_workspaces(
         self.get_tree().workspaces())
     for group_index, (group, workspaces) in enumerate(workspace_groups):
         logger.debug('Organizing workspace group: "%s" in monitor "%s"',
                      group, monitor_name)
         local_numbers = ws_names.compute_local_numbers(
             workspaces, group_to_all_workspaces.get(group, []),
             self.config['renumber_workspaces'])
         for workspace, local_number in zip(workspaces, local_numbers):
             ws_metadata = ws_names.parse_name(workspace.name)
             ws_metadata.group = group
             ws_metadata.local_number = local_number
             ws_metadata.global_number = ws_names.compute_global_number(
                 monitor_index, group_index, local_number)
             dynamic_name = ''
             # Add window icons if needed.
             if self.config['icons']['enable'] and (
                     self.config['icons']['enable_all_groups']
                     or group_index == 0):
                 dynamic_name = self.icons_resolver.get_workspace_icons(
                     workspace)
             ws_metadata.dynamic_name = dynamic_name
             new_name = ws_names.create_name(ws_metadata)
             self.i3_proxy.rename_workspace(workspace.name, new_name)
             workspace.name = new_name
Beispiel #2
0
 def update_focused_workspace(
         self,
         metadata_updates: ws_names.WorkspaceGroupingMetadata) -> None:
     if metadata_updates.group is not None and (
             not ws_names.is_valid_group_name(metadata_updates.group)):
         raise WorkspaceGroupsError(
             f'Invalid group name provided: "{metadata_updates.group}"')
     focused_workspace = self.get_tree().find_focused().workspace()
     metadata = ws_names.parse_name(focused_workspace.name)
     for section in ['group', 'local_number', 'static_name']:
         value = getattr(metadata_updates, section)
         if value is not None:
             setattr(metadata, section, value)
     found_name, exists = self._get_workspace_by_local_number(
         metadata.group, metadata.local_number)
     if exists and focused_workspace.name != found_name:
         if not self.config['workspace_moves']['use_next_available_number']:
             raise WorkspaceGroupsError(
                 f'Workspace with local number "{metadata.local_number}" '
                 'already exists in group: "{metadata.group}": '
                 '"{found_name}"')
         group_to_all_workspaces = ws_names.get_group_to_workspaces(
             self.get_tree().workspaces())
         used_local_numbers = ws_names.get_used_local_numbers(
             group_to_all_workspaces[metadata.group])
         free_local_numbers = ws_names.get_lowest_free_local_numbers(
             1, used_local_numbers)
         metadata.local_number = next(iter(free_local_numbers))
     self.i3_proxy.rename_workspace(focused_workspace.name,
                                    self._create_workspace_name(metadata))
Beispiel #3
0
 def update_focused_workspace(
         self,
         metadata_updates: ws_names.WorkspaceGroupingMetadata) -> None:
     focused_workspace = self.get_tree().find_focused().workspace()
     metadata = ws_names.parse_name(focused_workspace.name)
     if metadata_updates.group is not None and (
             not ws_names.is_valid_group_name(metadata_updates.group)):
         raise WorkspaceGroupsError(
             'Invalid group name provided: "{}"'.format(
                 metadata_updates.group))
     for section in ['group', 'local_number', 'static_name']:
         value = getattr(metadata_updates, section)
         if value is not None:
             setattr(metadata, section, value)
     global_name, workspace_id = self._derive_workspace(metadata)
     if workspace_id is not None and workspace_id != focused_workspace.id:
         raise WorkspaceGroupsError(
             'Workspace with local number "{}" already exists in group: '
             '"{}": "{}"'.format(metadata.local_number, metadata.group,
                                 global_name))
     self.i3_proxy.rename_workspace(focused_workspace.name, global_name)
Beispiel #4
0
 def _derive_workspace(
     self, metadata: ws_names.WorkspaceGroupingMetadata
 ) -> Tuple[str, Optional[int]]:
     # i3 commands like `workspace number n` will focus on an existing
     # workspace in another monitor if possible. To preserve this behavior,
     # we check the group workspaces in all monitors.
     group_to_all_workspaces = ws_names.get_group_to_workspaces(
         self.get_tree().workspaces())
     # Every workspace must have a unique (group, local_number) pair. This
     # tracks whether we found a workspace that conflicts with the given
     # (group, local_number).
     for workspace in group_to_all_workspaces.get(metadata.group, []):
         if not ws_names.get_local_workspace_number(
                 workspace) == metadata.local_number:
             continue
         static_name = ws_names.parse_name(workspace.name).static_name
         if metadata.static_name is None or (metadata.static_name
                                             == static_name):
             return (workspace.name, workspace.id)
         return (self._create_workspace_name(metadata), workspace.id)
         # is_available = False
     return (self._create_workspace_name(metadata), None)