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 (
Optional
[Gdk.Screen
]) – The screen to operate on. IfNone
, the default screen as retrieved byGdk.Screen.get_default
will be used.x_display (
Optional
[Display
]) – TheXlib.display.Display
to operate on. IfNone
, a new X connection will be created.
- Raises
XInitError –
None
was specified forx_display
and the attempt to open a new X connection failed.
-
_property_prep
(win, name)[source]¶ Common code for get_property and set_property
- 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()
.
-
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
name
on 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.Xatom
empty (
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_type
instructs 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.DESKTOP
orWnck.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 (
Optional
[Wnck.Window
]) – The point of reference.None
for the active workspace.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.1
or-2
).None
: The workspace containingwindow
wrap_around (
bool
) – Whether relative indexes should wrap around.
- Return type
- Returns
The workspace object or
None
if no match was found.
-
static
is_relevant
(window)[source]¶ Return
False
if 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=Rectangle(x=0, y=0, width=0, height=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 whichgeom
should 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
None
-
set_property
(win, name, value, prop_type=31, format_size=8)[source]¶ Set the value of X11 property
name
on windowwin
to 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.Xatom
format_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_type
is metadata for the X client library to correctly un-marshall the data later and the server doesn’t use it for anything.format_size
specifies 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_size
is necessary for things where you’d think thatprop_type
would 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 and processing them into a
quicktile.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.