Beispiel #1
0
 def _relative_workspace_in_group(self,
                                  offset_from_current: int = 1
                                  ) -> i3ipc.Con:
     focused_workspace = self.get_tree().find_focused().workspace()
     focused_group = ws_names.get_group(focused_workspace)
     group_workspaces_all_monitors = ws_names.get_group_to_workspaces(
         self.get_tree().workspaces())[focused_group]
     current_workspace_index = 0
     for (current_workspace_index,
          workspace) in enumerate(group_workspaces_all_monitors):
         if workspace.id == focused_workspace.id:
             break
     next_workspace_index = (current_workspace_index + offset_from_current
                             ) % len(group_workspaces_all_monitors)
     return group_workspaces_all_monitors[next_workspace_index]
Beispiel #2
0
 def switch_active_group(self, target_group: str,
                         focused_monitor_only: bool) -> None:
     focused_monitor_name = self.i3_proxy.get_focused_monitor_name()
     monitor_to_workspaces = self.i3_proxy.get_monitor_to_workspaces()
     for monitor, workspaces in monitor_to_workspaces.items():
         group_exists = (target_group
                         in ws_names.get_group_to_workspaces(workspaces))
         if monitor == focused_monitor_name:
             logger.debug('Switching active group in focused monitor "%s"',
                          monitor)
         elif not focused_monitor_only and group_exists:
             logger.debug(
                 'Non focused monitor %s has workspaces in the group "%s", '
                 'switching to it.', monitor, target_group)
         else:
             continue
         self.switch_monitor_active_group(monitor, target_group)
     # NOTE: We only switch focus to the new workspace after renaming all the
     # workspaces in all monitors and groups. Otherwise, if the previously
     # focused workspace was renamed, i3's `workspace back_and_forth` will
     # switch focus to a non-existant workspace name.
     focused_group = ws_names.get_group(
         self.get_tree().find_focused().workspace())
     # The target group is already focused, no need to do anything.
     if focused_group == target_group:
         return
     group_to_monitor_workspaces = ws_names.get_group_to_workspaces(
         monitor_to_workspaces[focused_monitor_name])
     if target_group in group_to_monitor_workspaces:
         workspace_name = group_to_monitor_workspaces[target_group][0].name
     # The focused monitor doesn't have any workspaces in the target group,
     # so create one.
     else:
         workspace_name = self._create_new_active_group_workspace_name(
             focused_monitor_name, target_group)
     self.i3_proxy.focus_workspace(workspace_name,
                                   auto_back_and_forth=False)
Beispiel #3
0
 def get_group_name(tree: i3ipc.Con, _: GroupToWorkspaces) -> str:
     focused_workspace = tree.find_focused().workspace()
     return ws_names.get_group(focused_workspace)