def set_geometry(window: Wnck.Window, x=None, y=None, w=None, h=None, synchronous=False, raise_exceptions=True): if not w and not h: geometry = window.get_geometry() w = geometry.widthp h = geometry.heightp xo, yo, wo, ho = calculate_geometry_offset(window) x, y, w, h = x + xo, y + yo, w + wo, h + ho x, y, w, h = int(x), int(y), int(w), int(h) geometry_cache[window.get_xid()] = (x, y, w, h) adjustment_cache[window.get_xid()] = False window.set_geometry(Wnck.WindowGravity.STATIC, X_Y_W_H_GEOMETRY_MASK, x, y, w, h) if synchronous: synchronized = wait_configure_event(window.get_xid(), Gdk.EventType.CONFIGURE, Gdk.Display.get_default()) return synchronized return False
def get_monitor(self, win: Wnck.Window) -> Tuple[int, Rectangle]: """Given a window, retrieve the ID and geometry of the monitor it's on. :param win: The window to find the containing monitor for. :returns: ``(monitor_id, geometry)`` .. todo:: Look for a way to get the monitor ID without having to instantiate a :class:`Gdk.Window`. Doing so would also remove the need to set ``self.gdk_display`` as this is the only user of it. """ if not isinstance(win, Gdk.Window): win = GdkX11.X11Window.foreign_new_for_display( self.gdk_display, win.get_xid()) # TODO: How do I retrieve the root window from a given one? # (Gdk.Display.get_default_screen().get_root_window()... now why did # I want to know?) monitor_id = self.gdk_screen.get_monitor_at_window(win) monitor_geom = Rectangle.from_gdk( self.gdk_screen.get_monitor_geometry(monitor_id)) # TODO: Unit test this monitor_geom *= self.gdk_screen.get_monitor_scale_factor(monitor_id) logging.debug(" Window is on monitor %s, which has geometry %s", monitor_id, Rectangle.from_gdk(monitor_geom)) return monitor_id, monitor_geom
def toggle_decorated( winman: WindowManager, win: Wnck.Window, state: Dict[str, Any] # pylint: disable=unused-argument ) -> None: """Toggle window decoration state on the active window. :param win: The window to operate on. :param state: Unused """ # Have to specify types in the description pending a fix for # https://github.com/agronholm/sphinx-autodoc-typehints/issues/124 # TODO: Switch to setting this via python-xlib display = winman.gdk_screen.get_display() win = GdkX11.X11Window.foreign_new_for_display(display, win.get_xid()) win.set_decorations( Gdk.WMDecoration(0) if win.get_decorations()[1] else Gdk.WMDecoration. ALL)
def resize(window: Wnck.Window, rectangle: Gdk.Rectangle = None, l=0, t=0, w=0, h=0): """ :param l: distance from left edge :param t: distance from top edge """ if not rectangle: rectangle = monitor_of(window.get_xid()).get_workarea() new_x = int(rectangle.width * l) + rectangle.x new_y = int(rectangle.height * t) + rectangle.y new_width = int(rectangle.width * w) new_height = int(rectangle.height * h) set_geometry(window, x=new_x, y=new_y, w=new_width, h=new_height)
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()
def wnck_to_x(self, window: Wnck.Window) -> GdkX11.X11Window: xid = window.get_xid() x_window = GdkX11.X11Window.foreign_new_for_display(self.display, xid) return x_window
def gdk_window_for(window: Wnck.Window = None, xid: int = None) -> GdkX11.X11Window: return window_for(window.get_xid())