Esempio n. 1
0
def cycle_monitors_all(winman: WindowManager,
                       win: Wnck.Window,
                       state: Dict[str, Any],
                       step: int = 1,
                       force_wrap: bool = False) -> None:
    """Cycle all windows between monitors.

    (Apply :func:`cycle_monitors` to all windows.)

    Attempts to preserve each window's position but will ensure that it doesn't
    get placed outside the available space on the target monitor.

    :param win: The window to operate on.
    :param step: Passed to :func:`cycle_monitors`
    :param force_wrap: Passed to :func:`cycle_monitors`
    """
    # Have to specify types in the description pending a fix for
    # https://github.com/agronholm/sphinx-autodoc-typehints/issues/124

    n_monitors = winman.gdk_screen.get_n_monitors()
    curr_workspace = win.get_workspace()

    if not curr_workspace:
        logging.debug("get_workspace() returned None")
        return

    for window in winman.get_relevant_windows(curr_workspace):
        cycle_monitors(winman, window, state, step, force_wrap, n_monitors)
Esempio n. 2
0
    def get_workspace(
        self,
        window: Wnck.Window = None,
        direction: Union[Wnck.MotionDirection, int] = None,
        wrap_around: bool = True,
    ) -> Optional[Wnck.Workspace]:
        """Get a workspace (virtual desktop) relative to the one containing
        the given or active window.

        :param window: The point of reference. :any:`None` for the
            active workspace.
        :param direction: The direction in which to look, relative to the point
            of reference. Accepts the following types:

            - :any:`Wnck.MotionDirection`: Absolute direction (will not cycle
              around when it reaches the edge)
            - :any:`int`: Relative position in the list of workspaces (eg.
              ``1`` or ``-2``).
            - :any:`None`: The workspace containing ``window``
        :param wrap_around: Whether relative indexes should wrap around.
        :returns: The workspace object or :any:`None` if no match was found.
        """
        if window:
            cur = window.get_workspace()
        else:
            cur = self.screen.get_active_workspace()

        if not cur:
            return None  # It's either pinned or on no workspaces

        if isinstance(direction, Wnck.MotionDirection):
            nxt = cur.get_neighbor(direction)
        elif isinstance(direction, int):
            # TODO: Deduplicate with the wrapping code in commands.py
            n_spaces = self.screen.get_workspace_count()

            nxt = self.screen.get_workspace(
                clamp_idx(cur.get_number() + direction, n_spaces, wrap_around))

        elif direction is None:
            nxt = cur
        else:
            nxt = None
            logging.warning("Unrecognized direction: %r", direction)

        return nxt
Esempio n. 3
0
	def get_active(self, window: Wnck.Window = None) -> Monitor:
		if not window:
			window = get_active_managed_window()
		return self.of(window.get_workspace(), monitor_of(window.get_xid())) if window else self.get_primary()