Window Manager API Wrapper (wm.py)¶
Wrapper around libwnck for interacting with the window manager
- class WindowManager(screen=None, x_display=None)[source]¶
A simple API-wrapper class for manipulating window positioning.
- Parameters:
screen (
Gdk.Screen) – The screen to operate on. IfNone, the default screen as retrieved byGdk.Screen.get_defaultwill be used.x_display (
Optional[Display]) – TheXlib.display.Displayto operate on. IfNone, a new X connection will be created.
- Raises:
XInitError –
Nonewas specified forx_displayand the attempt to open a new X connection failed.
- get_monitor(win)[source]¶
Given a window, retrieve the ID and geometry of the monitor it’s on.
- Parameters:
win (
Wnck.Window) – The window to find the containing monitor for.- Return type:
- Returns:
(monitor_id, geometry)
- get_property(win, name, prop_type, empty=None)[source]¶
Get the value of the X11 property
nameon windowwin- Parameters:
win (
Union[Gdk.Window,Wnck.Window,int]) – A GTK or Wnck Window object or a raw X11 window ID.name (
Union[str,int]) – An atom name or a handle returned byXlib.display.Display.create_resource_object().prop_type (
int) – A constant fromXlib.Xatomempty (
Any) – The value to return if the property is unset.
As this is a semi-internal API not meriting too much work to make pretty, the design follows the underlying XGetWindowProperty API.
Some variable names have been changed to avoid colliding with Python built-ins while others are abstracted away to present a simpler API.
prop_typeinstructs the client library how to correctly un-marshall the data it receives.
- get_relevant_windows(workspace)[source]¶
Wrapper for
Wnck.Screen.get_windows()that filters out windows of typeWnck.WindowType.DESKTOPorWnck.WindowType.DOCK.- Parameters:
workspace (
Wnck.Workspace) – The virtual desktop to retrieve windows from.- Return type:
- get_workspace(window=None, direction=None, wrap_around=True)[source]¶
Get a workspace (virtual desktop) relative to the one containing the given or active window.
- Parameters:
window (
Wnck.Window) – The point of reference.Nonefor the active workspace.direction (
Union[Wnck.MotionDirection,int]) –The direction in which to look, relative to the point of reference. Accepts the following types:
Wnck.MotionDirection: Absolute direction (will not cycle around when it reaches the edge)int: Relative position in the list of workspaces (eg.1or-2).None: The workspace containingwindow
wrap_around (
bool) – Whether relative indexes should wrap around.
- Return type:
- Returns:
The workspace object or
Noneif no match was found.
- static is_relevant(window)[source]¶
Return
Falseif the window should be ignored.(i.e. If it’s the desktop or a panel)
- Parameters:
window (
Wnck.Window)- Return type:
- reposition(win, geom=None, monitor=(0, 0, 0, 0), keep_maximize=False, geometry_mask=<flags WNCK_WINDOW_CHANGE_X | WNCK_WINDOW_CHANGE_Y | WNCK_WINDOW_CHANGE_WIDTH | WNCK_WINDOW_CHANGE_HEIGHT of type Wnck.WindowMoveResizeMask>)[source]¶
Move and resize a window, decorations inclusive, according to the provided target window and monitor geometry rectangles.
If no monitor rectangle is specified, the target position will be relative to the desktop as a whole.
- Parameters:
win (
Wnck.Window) – The window to reposition.geom (
Optional[Rectangle]) – The new geometry for the window. Can be left unspecified if the intent is to move the window to another monitor without repositioning it.monitor (
Rectangle) – The frame relative to whichgeomshould be interpreted. The whole desktop if unspecified.keep_maximize (
bool) – Whether to re-maximize the window if it had to be un-maximized to ensure it would move.geometry_mask (
Wnck.WindowMoveResizeMask) – A set of flags determining which aspects of the requested geometry should actually be applied to the window. (Allows the same geometry definition to easily be shared between operations like move and resize.)
- Return type:
- set_property(win, name, value, prop_type=31, format_size=8)[source]¶
Set the value of X11 property
nameon windowwinto the contents ofvalue.- Parameters:
win (
Union[Gdk.Window,Wnck.Window,int]) – A GTK or Wnck Window object or a raw X11 window ID.name (
Union[str,int]) – An atom name or a handle returned byXlib.display.Display.create_resource_object().value – The value to be stored
prop_type (
int) – A constant fromXlib.Xatomformat_size (
int) – The size of the value in bits.
As this is a semi-internal API not meriting too much work to make pretty, the design follows the underlying XChangeProperty API, which expects a C-style “list of items as a packed sequence of bits with out-of-band metadata” data type.
Some variable names have been changed to avoid colliding with Python built-ins while others are abstracted away to present a simpler API.
prop_typeis metadata for the X client library to correctly un-marshall the data later and the server doesn’t use it for anything.format_sizespecifies the size of an item in the sequence (even if it’s a sequence of length 1) and is also necessary for correct operation if the X server decides that it needs to byte-swap the values.This is why
format_sizeis necessary for things where you’d think thatprop_typewould be enough to describe the data type.
- update_geometry_cache()[source]¶
Update the internal cache of monitor & panel shapes by querying them from the desktop, either using
_GTK_WORKAREAS_D0or by running and processing them into aquicktile.util.UsableRegion.- Raises:
Exception – Unable to retrieve monitor geometries
- persist_maximization(win, keep_maximize=True)[source]¶
Context manager to persist maximization state after a call to
WindowManager.reposition.- Parameters:
win (
Wnck.Window) – The window to operate on.keep_maximize (
bool) – IfFalse, this decoration becomes a no-op to ease writing clean code which needs to support both behaviours.


Install Dependencies