From 61a387183b120cf8e6108a6146bf06cc189d8cc5 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sun, 21 Aug 2011 13:13:58 -0400 Subject: [PATCH 01/12] meh --- xpybutil/icccm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xpybutil/icccm.py b/xpybutil/icccm.py index 4e170ae..1beb6b4 100644 --- a/xpybutil/icccm.py +++ b/xpybutil/icccm.py @@ -1,6 +1,8 @@ from collections import defaultdict import struct +from xpybutil import conn, root + import xcb.xproto import util From c7751e60140c0fff1d313adb35dd7646a5d7658b Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sun, 21 Aug 2011 13:18:04 -0400 Subject: [PATCH 02/12] hmm --- xpybutil/ewmh.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xpybutil/ewmh.py b/xpybutil/ewmh.py index 3e97fd7..821ad6f 100644 --- a/xpybutil/ewmh.py +++ b/xpybutil/ewmh.py @@ -4,6 +4,7 @@ import xcb.xproto from xpybutil import conn, root + import util __atoms = [ From d4eda3ab5bf9fd4d0c9cd2f9ffd2aafb4dee4ff7 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sun, 21 Aug 2011 13:18:58 -0400 Subject: [PATCH 03/12] gah --- xpybutil/ewmh.py | 1 - xpybutil/icccm.py | 1 - 2 files changed, 2 deletions(-) diff --git a/xpybutil/ewmh.py b/xpybutil/ewmh.py index 821ad6f..3e97fd7 100644 --- a/xpybutil/ewmh.py +++ b/xpybutil/ewmh.py @@ -4,7 +4,6 @@ import xcb.xproto from xpybutil import conn, root - import util __atoms = [ diff --git a/xpybutil/icccm.py b/xpybutil/icccm.py index 1beb6b4..12e1c4f 100644 --- a/xpybutil/icccm.py +++ b/xpybutil/icccm.py @@ -2,7 +2,6 @@ import struct from xpybutil import conn, root - import xcb.xproto import util From 34ebfa60d6772890dc72f6b6817359286ad7a526 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sun, 21 Aug 2011 16:41:56 -0400 Subject: [PATCH 04/12] thread conn through xpybutil instead of making the user carry it around --- xpybutil/cursor.py | 23 +- xpybutil/event.py | 60 +- xpybutil/ewmh.py | 1416 +++++++++++++++++------------------------- xpybutil/font.py | 9 +- xpybutil/icccm.py | 293 ++++----- xpybutil/image.py | 28 +- xpybutil/keysym.py | 101 ++- xpybutil/motif.py | 40 +- xpybutil/render.py | 8 + xpybutil/util.py | 119 +--- xpybutil/xinerama.py | 10 +- 11 files changed, 898 insertions(+), 1209 deletions(-) diff --git a/xpybutil/cursor.py b/xpybutil/cursor.py index 3297c69..6c0ff0a 100644 --- a/xpybutil/cursor.py +++ b/xpybutil/cursor.py @@ -1,3 +1,5 @@ +from xpybutil import conn + class FontCursor: XCursor = 0 Arrow = 2 @@ -77,16 +79,17 @@ class FontCursor: Watch = 150 XTerm = 152 -def create_font_cursor(c, cursor_id, fore_red=0, fore_green=0, fore_blue=0, +def create_font_cursor(cursor_id, fore_red=0, fore_green=0, fore_blue=0, back_red=0xffff, back_green=0xffff, back_blue=0xffff): - font = c.generate_id() - cursor = c.generate_id() + font = conn.generate_id() + cursor = conn.generate_id() + + conn.core.OpenFontChecked(font, len('cursor'), 'cursor').check() + conn.core.CreateGlyphCursorChecked(cursor, font, font, cursor_id, + cursor_id + 1, fore_red, fore_green, + fore_blue, back_red, back_green, + back_blue).check() + conn.core.CloseFont(font) - c.core.OpenFontChecked(font, len('cursor'), 'cursor').check() - c.core.CreateGlyphCursorChecked(cursor, font, font, cursor_id, - cursor_id + 1, fore_red, fore_green, - fore_blue, back_red, back_green, - back_blue).check() - c.core.CloseFont(font) + return cursor - return cursor \ No newline at end of file diff --git a/xpybutil/event.py b/xpybutil/event.py index fb59d39..a9feec0 100644 --- a/xpybutil/event.py +++ b/xpybutil/event.py @@ -5,12 +5,14 @@ import xcb.xproto +from xpybutil import conn, root import util __queue = deque() __callbacks = [] +EM = xcb.xproto.EventMask -class Event: +class Event(object): KeyPressEvent = 2 KeyReleaseEvent = 3 ButtonPressEvent = 4 @@ -45,6 +47,40 @@ class Event: ClientMessageEvent = 33 MappingNotifyEvent = 34 +def replay_pointer(): + conn.core.AllowEventsChecked(xcb.xproto.Allow.ReplayPointer, + xcb.xproto.Time.CurrentTime).check() + +def send_event(destination, event_mask, event, propagate=False): + return conn.core.SendEvent(propagate, destination, event_mask, event) + +def send_event_checked(destination, event_mask, event, propagate=False): + return conn.core.SendEventChecked(propagate, destination, event_mask, event) + +def pack_client_message(window, message_type, *data): + assert len(data) <= 5 + + if isinstance(message_type, basestring): + message_type = util.get_atom(message_type) + + data = list(data) + data += [0] * (5 - len(data)) + + # Taken from + # http://xcb.freedesktop.org/manual/structxcb__client__message__event__t.html + return struct.pack('BBH7I', Event.ClientMessageEvent, 32, 0, window, + message_type, *data) + +def root_send_client_event(window, message_type, *data): + mask = EM.SubstructureNotify | EM.SubstructureRedirect + packed = pack_client_message(window, message_type, *data) + return send_event(root, mask, packed) + +def root_send_client_event_checked(window, message_type, *data): + mask = EM.SubstructureNotify | EM.SubstructureRedirect + packed = pack_client_message(window, message_type, *data) + return send_event_checked(root, mask, packed) + def connect(event_name, window, callback): member = '%sEvent' % event_name assert hasattr(xcb.xproto, member) @@ -61,35 +97,23 @@ def disconnect(event_name, window): for item in cbs: __callbacks.remove(item) -def send_event(c, destination, event_mask, event, propagate=False): - return c.core.SendEvent(propagate, destination, event_mask, event) - -def pack_client_message(window, message_type, *data): - assert len(data) <= 5 - - data = list(data) - data += ([0] * (5 - len(data))) - - return struct.pack('BBH7I', Event.ClientMessageEvent, 32, 0, window, - message_type, *data) - -def read(c, block=False): +def read(block=False): if block: - e = c.wait_for_event() + e = conn.wait_for_event() __queue.appendleft(e) while True: - e = c.poll_for_event() + e = conn.poll_for_event() if not e: break __queue.appendleft(e) -def event_loop(conn): +def event_loop(): try: while True: - read(conn, block=True) + read(block=True) for e in queue(): w = None if hasattr(e, 'window'): diff --git a/xpybutil/ewmh.py b/xpybutil/ewmh.py index 3e97fd7..0ee459b 100644 --- a/xpybutil/ewmh.py +++ b/xpybutil/ewmh.py @@ -1,71 +1,71 @@ import struct -import time import xcb.xproto -from xpybutil import conn, root +from xpybutil import root +import event import util __atoms = [ - # Non-standard - '_NET_VISIBLE_DESKTOPS', '_NET_WM_WINDOW_OPACITY', - - # Root Window Properties (and Related Messages) - '_NET_SUPPORTED', '_NET_CLIENT_LIST', '_NET_CLIENT_LIST_STACKING', - '_NET_NUMBER_OF_DESKTOPS', '_NET_DESKTOP_GEOMETRY', - '_NET_DESKTOP_VIEWPORT', '_NET_CURRENT_DESKTOP', - '_NET_DESKTOP_NAMES', '_NET_ACTIVE_WINDOW', '_NET_WORKAREA', - '_NET_SUPPORTING_WM_CHECK', '_NET_VIRTUAL_ROOTS', - '_NET_DESKTOP_LAYOUT', '_NET_SHOWING_DESKTOP', - - # Other Root Window Messages - '_NET_CLOSE_WINDOW', '_NET_MORERESIZE_WINDOW', '_NET_WM_MOVERESIZE', - '_NET_RESTACK_WINDOW', '_NET_REQUEST_FRAME_EXTENTS', - - # Application Window Properties - '_NET_WM_NAME', '_NET_WM_VISIBLE_NAME', '_NET_WM_ICON_NAME', - '_NET_WM_VISIBLE_ICON_NAME', '_NET_WM_DESKTOP', - '_NET_WM_WINDOW_TYPE', '_NET_WM_STATE', '_NET_WM_ALLOWED_ACTIONS', - '_NET_WM_STRUT', '_NET_WM_STRUT_PARTIAL', '_NET_WM_ICON_GEOMETRY', - '_NET_WM_ICON', '_NET_WM_PID', '_NET_WM_HANDLED_ICONS', - '_NET_WM_USER_TIME', '_NET_WM_USER_TIME_WINDOW', - '_NET_FRAME_EXTENTS', - - # Window Manager Protocols - '_NET_WM_PING', '_NET_WM_SYNC_REQUEST', - '_NET_WM_FULLSCREEN_MONITORS', - - # Other Properties - '_NET_WM_FULL_PLACEMENT', - - # _NET_WM_WINDOW_TYPE_* - '_NET_WM_WINDOW_TYPE_DESKTOP', '_NET_WM_WINDOW_TYPE_DOCK', - '_NET_WM_WINDOW_TYPE_TOOLBAR', '_NET_WM_WINDOW_TYPE_MENU', - '_NET_WM_WINDOW_TYPE_UTILITY', '_NET_WM_WINDOW_TYPE_SPLASH', - '_NET_WM_WINDOW_TYPE_DIALOG', '_NET_WM_WINDOW_TYPE_DROPDOWN_MENU', - '_NET_WM_WINDOW_TYPE_POPUP_MENU', '_NET_WM_WINDOW_TYPE_TOOLTIP', - '_NET_WM_WINDOW_TYPE_NOTIFICATION', '_NET_WM_WINDOW_TYPE_COMBO', - '_NET_WM_WINDOW_TYPE_DND', '_NET_WM_WINDOW_TYPE_NORMAL', - - # _NET_WM_STATE_* - '_NET_WM_STATE_MODAL', '_NET_WM_STATE_STICKY', - '_NET_WM_STATE_MAXIMIZED_VERT', '_NET_WM_STATE_MAXIMIZED_HORZ', - '_NET_WM_STATE_SHADED', '_NET_WM_STATE_SKIP_TASKBAR', - '_NET_WM_STATE_SKIP_PAGER', '_NET_WM_STATE_HIDDEN', - '_NET_WM_STATE_FULLSCREEN', '_NET_WM_STATE_ABOVE', - '_NET_WM_STATE_BELOW', '_NET_WM_STATE_DEMANDS_ATTENTION', - - # _NET_WM_ACTION_* - '_NET_WM_ACTION_MOVE', '_NET_WM_ACTION_RESIZE', - '_NET_WM_ACTION_MINIMIZE', '_NET_WM_ACTION_SHADE', - '_NET_WM_ACTION_STICK', '_NET_WM_ACTION_MAXIMIZE_HORZ', - '_NET_WM_ACTION_MAXIMIZE_VERT', '_NET_WM_ACTION_FULLSCREEN', - '_NET_WM_ACTION_CHANGE_DESKTOP', '_NET_WM_ACTION_CLOSE', - '_NET_WM_ACTION_ABOVE', '_NET_WM_ACTION_BELOW', - - # Additional TEXT Type - 'UTF8_STRING' - ] + # Non-standard + '_NET_VISIBLE_DESKTOPS', '_NET_WM_WINDOW_OPACITY', + + # Root Window Properties (and Related Messages) + '_NET_SUPPORTED', '_NET_CLIENT_LIST', '_NET_CLIENT_LIST_STACKING', + '_NET_NUMBER_OF_DESKTOPS', '_NET_DESKTOP_GEOMETRY', + '_NET_DESKTOP_VIEWPORT', '_NET_CURRENT_DESKTOP', + '_NET_DESKTOP_NAMES', '_NET_ACTIVE_WINDOW', '_NET_WORKAREA', + '_NET_SUPPORTING_WM_CHECK', '_NET_VIRTUAL_ROOTS', + '_NET_DESKTOP_LAYOUT', '_NET_SHOWING_DESKTOP', + + # Other Root Window Messages + '_NET_CLOSE_WINDOW', '_NET_MORERESIZE_WINDOW', '_NET_WM_MOVERESIZE', + '_NET_RESTACK_WINDOW', '_NET_REQUEST_FRAME_EXTENTS', + + # Application Window Properties + '_NET_WM_NAME', '_NET_WM_VISIBLE_NAME', '_NET_WM_ICON_NAME', + '_NET_WM_VISIBLE_ICON_NAME', '_NET_WM_DESKTOP', + '_NET_WM_WINDOW_TYPE', '_NET_WM_STATE', '_NET_WM_ALLOWED_ACTIONS', + '_NET_WM_STRUT', '_NET_WM_STRUT_PARTIAL', '_NET_WM_ICON_GEOMETRY', + '_NET_WM_ICON', '_NET_WM_PID', '_NET_WM_HANDLED_ICONS', + '_NET_WM_USER_TIME', '_NET_WM_USER_TIME_WINDOW', + '_NET_FRAME_EXTENTS', + + # Window Manager Protocols + '_NET_WM_PING', '_NET_WM_SYNC_REQUEST', + '_NET_WM_FULLSCREEN_MONITORS', + + # Other Properties + '_NET_WM_FULL_PLACEMENT', + + # _NET_WM_WINDOW_TYPE_* + '_NET_WM_WINDOW_TYPE_DESKTOP', '_NET_WM_WINDOW_TYPE_DOCK', + '_NET_WM_WINDOW_TYPE_TOOLBAR', '_NET_WM_WINDOW_TYPE_MENU', + '_NET_WM_WINDOW_TYPE_UTILITY', '_NET_WM_WINDOW_TYPE_SPLASH', + '_NET_WM_WINDOW_TYPE_DIALOG', '_NET_WM_WINDOW_TYPE_DROPDOWN_MENU', + '_NET_WM_WINDOW_TYPE_POPUP_MENU', '_NET_WM_WINDOW_TYPE_TOOLTIP', + '_NET_WM_WINDOW_TYPE_NOTIFICATION', '_NET_WM_WINDOW_TYPE_COMBO', + '_NET_WM_WINDOW_TYPE_DND', '_NET_WM_WINDOW_TYPE_NORMAL', + + # _NET_WM_STATE_* + '_NET_WM_STATE_MODAL', '_NET_WM_STATE_STICKY', + '_NET_WM_STATE_MAXIMIZED_VERT', '_NET_WM_STATE_MAXIMIZED_HORZ', + '_NET_WM_STATE_SHADED', '_NET_WM_STATE_SKIP_TASKBAR', + '_NET_WM_STATE_SKIP_PAGER', '_NET_WM_STATE_HIDDEN', + '_NET_WM_STATE_FULLSCREEN', '_NET_WM_STATE_ABOVE', + '_NET_WM_STATE_BELOW', '_NET_WM_STATE_DEMANDS_ATTENTION', + + # _NET_WM_ACTION_* + '_NET_WM_ACTION_MOVE', '_NET_WM_ACTION_RESIZE', + '_NET_WM_ACTION_MINIMIZE', '_NET_WM_ACTION_SHADE', + '_NET_WM_ACTION_STICK', '_NET_WM_ACTION_MAXIMIZE_HORZ', + '_NET_WM_ACTION_MAXIMIZE_VERT', '_NET_WM_ACTION_FULLSCREEN', + '_NET_WM_ACTION_CHANGE_DESKTOP', '_NET_WM_ACTION_CLOSE', + '_NET_WM_ACTION_ABOVE', '_NET_WM_ACTION_BELOW', + + # Additional TEXT Type + 'UTF8_STRING' +] class Orientation: Horz = 0 @@ -98,190 +98,166 @@ class State: # Some aliases atom = util.get_atom -root = util.get_root -revent = util.root_send_client_event -revent_checked = util.root_send_client_event_checked +revent = event.root_send_client_event +revent_checked = event.root_send_client_event_checked +ATOM = xcb.xproto.Atom.ATOM CARDINAL = xcb.xproto.Atom.CARDINAL +WINDOW = xcb.xproto.Atom.WINDOW + +# Build the atom cache for quicker access +util.build_atom_cache(__atoms) + # _NET_SUPPORTED -def get_supported(c, window): +def get_supported(): """ Returns a list of hints supported by the window manager. - @param c: An xpyb connection object. - @param window: A window identifier. @return: A list of atoms in the _NET_SUPPORTED property. @rtype: util.PropertyCookie (ATOM[]/32) """ - return util.PropertyCookie( - util.get_property(c, window, atom(c, '_NET_SUPPORTED'))) + return util.PropertyCookie(util.get_property(root, '_NET_SUPPORTED')) -def get_supported_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, atom(c, '_NET_SUPPORTED'))) +def get_supported_unchecked(): + return util.PropertyCookie(util.get_property_unchecked(root, + '_NET_SUPPORTED')) -def set_supported(c, window, atoms): +def set_supported(atoms): """ Sets the list of hints supported by the window manager. - @param c: An xpyb connection object. - @param window: A window identifier. @param atoms: A list of atom identifiers. @type atoms: ATOM[]/32 @rtype: xcb.VoidCookie """ packed = struct.pack('I' * len(atoms), *atoms) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_SUPPORTED'), - xcb.xproto.Atom.ATOM, 32, len(atoms), + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_SUPPORTED'), ATOM, 32, len(atoms), packed) -def set_supported_checked(c, window, atoms): +def set_supported_checked(atoms): packed = struct.pack('I' * len(atoms), *atoms) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_SUPPORTED'), - xcb.xproto.Atom.ATOM, 32, len(atoms), - packed) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_SUPPORTED'), + ATOM, 32, len(atoms), packed) # _NET_CLIENT_LIST -def get_client_list(c, window): +def get_client_list(): """ Returns a list of windows managed by the window manager. - @param c: An xpyb connection object. - @param window: A window identifier. @return: A list of window identifiers. @rtype: util.PropertyCookie (ATOM[]/32) """ - return util.PropertyCookie( - util.get_property(c, window, atom(c, '_NET_CLIENT_LIST'))) + return util.PropertyCookie(util.get_property(root, '_NET_CLIENT_LIST')) -def get_client_list_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, atom(c, '_NET_CLIENT_LIST'))) +def get_client_list_unchecked(): + return util.PropertyCookie(util.get_property_unchecked(root, + '_NET_CLIENT_LIST')) -def set_client_list(c, window, windows): +def set_client_list(windows): """ Sets the list of windows managed by the window manager. - @param c: An xpyb connection object. - @param window: A window identifier. @param windows: A list of atom identifiers. @type windows: ATOM[]/32 @rtype: xcb.VoidCookie """ packed = struct.pack('I' * len(windows), *windows) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_CLIENT_LIST'), - xcb.xproto.Atom.WINDOW, 32, len(windows), - packed) + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_CLIENT_LIST'), + WINDOW, 32, len(windows), packed) -def set_client_list_checked(c, window, windows): +def set_client_list_checked(windows): packed = struct.pack('I' * len(windows), *windows) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_CLIENT_LIST'), - xcb.xproto.Atom.WINDOW, 32, len(windows), - packed) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_CLIENT_LIST'), + WINDOW, 32, len(windows), packed) # _NET_CLIENT_LIST_STACKING -def get_client_list_stacking(c, window): +def get_client_list_stacking(): """ Returns the window stacking order. - @param c: An xpyb connection object. - @param window: A window identifier. @return: A list of window identifiers. @rtype: util.PropertyCookie (ATOM[]/32) """ - return util.PropertyCookie( - util.get_property(c, window, atom(c, '_NET_CLIENT_LIST_STACKING'))) + return util.PropertyCookie(util.get_property(root, + '_NET_CLIENT_LIST_STACKING')) -def get_client_list_stacking_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_CLIENT_LIST_STACKING'))) +def get_client_list_stacking_unchecked(): + cook = util.get_property_unchecked(root, '_NET_CLIENT_LIST_STACKING') + return util.PropertyCookie(cook) -def set_client_list_stacking(c, window, windows): +def set_client_list_stacking(windows): """ Sets the window stacking order. - @param c: An xpyb connection object. - @param window: A window identifier. @param windows: A list of atom identifiers. @type windows: ATOM[]/32 @rtype: xcb.VoidCookie """ packed = struct.pack('I' * len(windows), *windows) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_CLIENT_LIST_STACKING'), - xcb.xproto.Atom.WINDOW, 32, len(windows), - packed) + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_CLIENT_LIST_STACKING'), + WINDOW, 32, len(windows), packed) -def set_client_list_stacking_checked(c, window, windows): +def set_client_list_stacking_checked(windows): packed = struct.pack('I' * len(windows), *windows) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_CLIENT_LIST_STACKING'), - xcb.xproto.Atom.WINDOW, 32, len(windows), - packed) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_CLIENT_LIST_STACKING'), + WINDOW, 32, len(windows), packed) # _NET_NUMBER_DESKTOPS -def get_number_of_desktops(c, window): +def get_number_of_desktops(): """ Returns the number of virtual desktops. - @param c: An xpyb connection object. - @param window: A window identifier. @return: The number of desktops. @rtype: util.PropertyCookieSingle (CARDINAL/32) """ - return util.PropertyCookieSingle( - util.get_property(c, window, atom(c, '_NET_NUMBER_OF_DESKTOPS'))) + cook = util.get_property(root, '_NET_NUMBER_OF_DESKTOPS') + return util.PropertyCookieSingle(cook) -def get_number_of_desktops_unchecked(c, window): - return util.PropertyCookieSingle( - util.get_property_unchecked(c, window, - atom(c, '_NET_NUMBER_OF_DESKTOPS'))) +def get_number_of_desktops_unchecked(): + cook = util.get_property_unchecked(root, '_NET_NUMBER_OF_DESKTOPS') + return util.PropertyCookieSingle(cook) -def set_number_of_desktops(c, window, number_of_desktops): +def set_number_of_desktops(number_of_desktops): """ Sets the number of desktops. - @param c: An xpyb connection object. - @param window: A window identifier. @param number_of_desktops: The number of desktops. @type number_of_desktops: CARDINAL/32 @rtype: xcb.VoidCookie """ - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_NUMBER_OF_DESKTOPS'), - CARDINAL, 32, len(str(number_of_desktops)), - [number_of_desktops]) + packed = struct.pack('I', number_of_desktops) + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_NUMBER_OF_DESKTOPS'), CARDINAL, 32, + 1, packed) -def set_number_of_desktops_checked(c, window, number_of_desktops): - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_NUMBER_OF_DESKTOPS'), - CARDINAL, 32, len(str(number_of_desktops)), - [number_of_desktops]) +def set_number_of_desktops_checked(number_of_desktops): + packed = struct.pack('I', number_of_desktops) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_NUMBER_OF_DESKTOPS'), + CARDINAL, 32, 1, packed) -def request_number_of_desktops(c, number_of_desktops): +def request_number_of_desktops(number_of_desktops): """ Sends event to root window to set the number of desktops. - @param c: An xpyb connection object. @param number_of_desktops: The number of desktops. @type number_of_desktops: CARDINAL/32 @rtype: xcb.VoidCookie """ - return revent(c, root(c), atom(c, '_NET_NUMBER_OF_DESKTOPS'), - [number_of_desktops]) + return revent(root, '_NET_NUMBER_OF_DESKTOPS', number_of_desktops) -def request_number_of_desktops_checked(c, number_of_desktops): - return revent_checked(c, root(c), atom(c, '_NET_NUMBER_OF_DESKTOPS'), - [number_of_desktops]) +def request_number_of_desktops_checked(number_of_desktops): + return revent_checked(root, '_NET_NUMBER_OF_DESKTOPS', number_of_desktops) # _NET_DESKTOP_GEOMETRY @@ -297,31 +273,26 @@ def reply(self): 'height': v[1] } -def get_desktop_geometry(c, window): +def get_desktop_geometry(): """ Returns the desktop geometry. - @param c: An xpyb connection object. - @param window: A window identifier. @return: A desktop geometry dictionary. Keys: width, height @rtype: DesktopGeometryCookie (CARDINAL[2]/32) """ - return DesktopGeometryCookie( - util.get_property(c, window, atom(c, '_NET_DESKTOP_GEOMETRY'))) + return DesktopGeometryCookie(util.get_property(root, + '_NET_DESKTOP_GEOMETRY')) -def get_desktop_geometry_unchecked(c, window): - return DesktopGeometryCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_DESKTOP_GEOMETRY'))) +def get_desktop_geometry_unchecked(): + cook = util.get_property_unchecked(root, '_NET_DESKTOP_GEOMETRY') + return DesktopGeometryCookie(cook) -def set_desktop_geometry(c, window, width, height): +def set_desktop_geometry(width, height): """ Sets the desktop geometry. - @param c: An xpyb connection object. - @param window: A window identifier. @param width: The width of the desktop. @type width: CARDINAL/32 @param height: The height of the desktop. @@ -329,35 +300,30 @@ def set_desktop_geometry(c, window, width, height): @rtype: xcb.VoidCookie """ packed = struct.pack('II', width, height) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_DESKTOP_GEOMETRY'), - CARDINAL, 32, 2, + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_DESKTOP_GEOMETRY'), CARDINAL, 32, 2, packed) -def set_desktop_geometry_checked(c, window, width, height): +def set_desktop_geometry_checked(width, height): packed = struct.pack('II', width, height) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_DESKTOP_GEOMETRY'), - CARDINAL, 32, 2, - packed) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_DESKTOP_GEOMETRY'), + CARDINAL, 32, 2, packed) -def request_desktop_geometry(c, width, height): +def request_desktop_geometry(width, height): """ Sends event to root window to set the desktop geometry. - @param c: An xpyb connection object. @param width: The width of the desktop. @type width: CARDINAL/32 @param height: The height of the desktop. @type height: CARDINAL/32 @rtype: xcb.VoidCookie """ - return revent(c, root(c), atom(c, '_NET_NUMBER_OF_DESKTOPS'), - [width, height]) + return revent(root, '_NET_NUMBER_OF_DESKTOPS', width, height) -def request_desktop_geometry_checked(c, width, height): - return revent_checked(c, root(c), atom(c, '_NET_NUMBER_OF_DESKTOPS'), - [width, height]) +def request_desktop_geometry_checked(width, height): + return revent_checked(root, '_NET_NUMBER_OF_DESKTOPS', width, height) # _NET_DESKTOP_VIEWPORT @@ -377,26 +343,23 @@ def reply(self): return ret -def get_desktop_viewport(c, window): +def get_desktop_viewport(): """ Returns x,y pairs defining the top-left corner of each desktop's viewport. - @param c: An xpyb connection object. - @param window: A window identifier. @return: A list of desktop viewport dictionaries. Keys: x, y @rtype: DesktopViewportCookie (CARDINAL[][2]/32) """ - return DesktopViewportCookie( - util.get_property(c, window, atom(c, '_NET_DESKTOP_VIEWPORT'))) + return DesktopViewportCookie(util.get_property(root, + '_NET_DESKTOP_VIEWPORT')) -def get_desktop_viewport_unchecked(c, window): - return DesktopViewportCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_DESKTOP_VIEWPORT'))) +def get_desktop_viewport_unchecked(): + cook = util.get_property_unchecked(root, '_NET_DESKTOP_VIEWPORT') + return DesktopViewportCookie(cook) -def set_desktop_viewport(c, window, pairs): +def set_desktop_viewport(pairs): """ Sets the x,y pairs defining the top-left corner of each desktop's viewport. @@ -418,8 +381,6 @@ def set_desktop_viewport(c, window, pairs): Which would set desktop 0's viewport top-left corner to 0,0 and desktop 1's viewport top-left corner to 500,500. - @param c: An xpyb connection object. - @param window: A window identifier. @param pairs: A list of x,y dictionary pairs. @type pairs: CARDINAL[][2]/32 @rtype: xcb.VoidCookie @@ -430,170 +391,144 @@ def set_desktop_viewport(c, window, pairs): flatten.append(pair['y']) packed = struct.pack('I' * len(flatten), *flatten) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_DESKTOP_VIEWPORT'), - CARDINAL, 32, len(flatten), - packed) + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_DESKTOP_VIEWPORT'), + CARDINAL, 32, len(flatten), packed) -def set_desktop_viewport_checked(c, window, pairs): +def set_desktop_viewport_checked(pairs): flatten = [] for pair in pairs: flatten.append(pair['x']) flatten.append(pair['y']) packed = struct.pack('I' * len(flatten), *flatten) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_DESKTOP_VIEWPORT'), - CARDINAL, 32, len(flatten), - packed) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_DESKTOP_VIEWPORT'), + CARDINAL, 32, len(flatten), packed) -def request_desktop_viewport(c, x, y): +def request_desktop_viewport(x, y): """ Sends event to root window to set the viewport position of current desktop. - @param c: An xpyb connection object. @param x: The x position of the top-left corner. @type x: CARDINAL/32 @param y: The y position of the top-left corner. @type y: CARDINAL/32 @rtype: xcb.VoidCookie """ - return revent(c, root(c), atom(c, '_NET_DESKTOP_VIEWPORT'), - [x, y]) + return revent(root, '_NET_DESKTOP_VIEWPORT', x, y) -def request_desktop_viewport_checked(c, x, y): - return revent_checked(c, root(c), atom(c, '_NET_DESKTOP_VIEWPORT'), - [x, y]) +def request_desktop_viewport_checked(x, y): + return revent_checked(root, '_NET_DESKTOP_VIEWPORT', x, y) # _NET_CURRENT_DESKTOP -def get_current_desktop(c, window): +def get_current_desktop(): """ Returns the current desktop number. - @param c: An xpyb connection object. - @param window: A window identifier. @return: The index of the current desktop. @rtype: util.PropertyCookieSingle (CARDINAL/32) """ - return util.PropertyCookieSingle( - util.get_property(c, window, atom(c, '_NET_CURRENT_DESKTOP'))) + return util.PropertyCookieSingle(util.get_property(root, + '_NET_CURRENT_DESKTOP')) -def get_current_desktop_unchecked(c, window): - return util.PropertyCookieSingle( - util.get_property_unchecked(c, window, - atom(c, '_NET_CURRENT_DESKTOP'))) +def get_current_desktop_unchecked(): + cook = util.get_property_unchecked(root, '_NET_CURRENT_DESKTOP') + return util.PropertyCookieSingle(cook) -def set_current_desktop(c, window, current_desktop): +def set_current_desktop(current_desktop): """ Sets the current desktop number. - @param c: An xpyb connection object. - @param window: A window identifier. @param current_desktop: The current desktop index. @type current_desktop: CARDINAL/32 @rtype: xcb.VoidCookie """ - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_CURRENT_DESKTOP'), - CARDINAL, 32, len(str(current_desktop)), - [current_desktop]) + packed = struct.pack('I', current_desktop) + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_CURRENT_DESKTOP'), CARDINAL, 32, 1, + packed) -def set_current_desktop_checked(c, window, current_desktop): - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_CURRENT_DESKTOP'), - CARDINAL, 32, len(str(current_desktop)), - [current_desktop]) +def set_current_desktop_checked(current_desktop): + packed = struct.pack('I', current_desktop) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_CURRENT_DESKTOP'), + CARDINAL, 32, 1, packed) -def request_current_desktop(c, desktop_number, +def request_current_desktop(desktop_number, timestamp=xcb.xproto.Time.CurrentTime): """ Sends event to root window to set the current desktop. - @param c: An xpyb connection object. @param desktop_number: The current desktop index. @type desktop_number: CARDINAL/32 @type timestamp: Milliseconds. @rtype: xcb.VoidCookie """ - return revent(c, root(c), atom(c, '_NET_CURRENT_DESKTOP'), - [desktop_number, timestamp]) + return revent(root, '_NET_CURRENT_DESKTOP', desktop_number, timestamp) -def request_current_desktop_checked(c, desktop_number, +def request_current_desktop_checked(desktop_number, timestamp=xcb.xproto.Time.CurrentTime): - return revent_checked(c, root(c), atom(c, '_NET_CURRENT_DESKTOP'), - [desktop_number, timestamp]) + return revent_checked(root, '_NET_CURRENT_DESKTOP', + desktop_number, timestamp) # _NET_VISIBLE_DESKTOPS -def get_visible_desktops(c, window): +def get_visible_desktops(): """ Returns a list of visible desktops. The first desktop is on Xinerama screen 0, the second is on Xinerama screen 1, etc. - @param c: An xpyb connection object. - @param window: A window identifier. @return: A list of visible desktops. @rtype: util.PropertyCookie (ATOM[]/32) """ - return util.PropertyCookie( - util.get_property(c, window, atom(c, '_NET_VISIBLE_DESKTOPS'))) + return util.PropertyCookie(util.get_property(root, '_NET_VISIBLE_DESKTOPS')) -def get_visible_desktops_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_VISIBLE_DESKTOPS'))) +def get_visible_desktops_unchecked(): + cook = util.get_property_unchecked(root, '_NET_VISIBLE_DESKTOPS') + return util.PropertyCookie(cook) -def set_visible_desktops(c, window, desktops): +def set_visible_desktops(desktops): """ Sets the list of visible desktops. - @param c: An xpyb connection object. - @param window: A window identifier. @param desktops: A list of desktops. @type desktops: ATOM[]/32 @rtype: xcb.VoidCookie """ packed = struct.pack('I' * len(desktops), *desktops) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_VISIBLE_DESKTOPS'), - xcb.xproto.Atom.WINDOW, 32, len(desktops), - packed) + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_VISIBLE_DESKTOPS'), + WINDOW, 32, len(desktops), packed) -def set_visible_desktops_checked(c, window, desktops): +def set_visible_desktops_checked(desktops): packed = struct.pack('I' * len(desktops), *desktops) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_VISIBLE_DESKTOPS'), - xcb.xproto.Atom.WINDOW, 32, len(desktops), - packed) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_VISIBLE_DESKTOPS'), + WINDOW, 32, len(desktops), packed) # _NET_DESKTOP_NAMES -def get_desktop_names(c, window): +def get_desktop_names(): """ Returns a list of names of the virtual desktops. - @param c: An xpyb connection object. - @param window: A window identifier. @return: A list of virutal desktop names. @rtype: util.PropertyCookie (UTF8_STRING[]) """ - return util.PropertyCookie( - util.get_property(c, window, atom(c, '_NET_DESKTOP_NAMES'))) + return util.PropertyCookie(util.get_property(root, '_NET_DESKTOP_NAMES')) -def get_desktop_names_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_DESKTOP_NAMES'))) +def get_desktop_names_unchecked(): + cook = util.get_property_unchecked(root, '_NET_DESKTOP_NAMES') + return util.PropertyCookie(cook) -def set_desktop_names(c, window, desktop_names): +def set_desktop_names(desktop_names): """ Sets the current list of desktop names. - @param c: An xpyb connection object. - @param window: A window identifier. @param desktop_names: A list of new desktop names. @type desktop_names: UTF8_STRING[] @rtype: xcb.VoidCookie @@ -604,76 +539,64 @@ def set_desktop_names(c, window, desktop_names): nullterm.append(desktop_name + chr(0)) nullterm = ''.join(nullterm) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_DESKTOP_NAMES'), - atom(c, 'UTF8_STRING'), 8, - len(nullterm), - nullterm) + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_DESKTOP_NAMES'), + atom('UTF8_STRING'), 8, + len(nullterm), nullterm) -def set_desktop_names_checked(c, window, desktop_names): +def set_desktop_names_checked(desktop_names): # Null terminate the list of desktop names nullterm = [] for desktop_name in desktop_names: nullterm.append(desktop_name + chr(0)) nullterm = ''.join(nullterm) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_DESKTOP_NAMES'), - atom(c, 'UTF8_STRING'), 8, - len(nullterm), - nullterm) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_DESKTOP_NAMES'), + atom('UTF8_STRING'), 8, + len(nullterm), nullterm) # _NET_ACTIVE_WINDOW -def get_active_window(c, window): +def get_active_window(): """ Returns the identifier of the currently active window. - @param c: An xpyb connection object. - @param window: A window identifier. @return: The window ID of the active window. @rtype: util.PropertyCookieSingle (WINDOW/32) """ - return util.PropertyCookieSingle( - util.get_property(c, window, atom(c, '_NET_ACTIVE_WINDOW'))) + return util.PropertyCookieSingle(util.get_property(root, + '_NET_ACTIVE_WINDOW')) -def get_active_window_unchecked(c, window): - return util.PropertyCookieSingle( - util.get_property_unchecked(c, window, - atom(c, '_NET_ACTIVE_WINDOW'))) +def get_active_window_unchecked(): + cook = util.get_property_unchecked(root, '_NET_ACTIVE_WINDOW') + return util.PropertyCookieSingle(cook) -def set_active_window(c, window, active): +def set_active_window(active): """ Sets the identifier of the currently active window. - @param c: An xpyb connection object. - @param window: A window identifier. @param active: The identifier of the window that is active. @type active: WINDOW/32 @rtype: xcb.VoidCookie """ packed = struct.pack('I', active) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_ACTIVE_WINDOW'), - xcb.xproto.Atom.WINDOW, 32, - 1, - packed) + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_ACTIVE_WINDOW'), + WINDOW, 32, 1, packed) -def set_active_window_checked(c, window, active): +def set_active_window_checked(active): packed = struct.pack('I', active) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_ACTIVE_WINDOW'), - xcb.xproto.Atom.WINDOW, 32, - 1, - packed) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_ACTIVE_WINDOW'), + WINDOW, 32, 1, packed) -def request_active_window(c, active, source=1, - timestamp=xcb.xproto.Time.CurrentTime, - current=0): +def request_active_window(active, source=1, + timestamp=xcb.xproto.Time.CurrentTime, + current=0): """ Sends event to root window to set the active window. - @param c: An xpyb connection object. @param active: The window ID of the window to make active. @type active: WINDOW/32 @param source: The source indication. @@ -681,14 +604,13 @@ def request_active_window(c, active, source=1, @param current: Client's active toplevel window @rtype: xcb.VoidCookie """ - return revent(c, active, atom(c, '_NET_ACTIVE_WINDOW'), - [source, timestamp, current]) + return revent(active, '_NET_ACTIVE_WINDOW', source, timestamp, current) -def request_active_window_checked(c, active, source=1, +def request_active_window_checked(active, source=1, timestamp=xcb.xproto.Time.CurrentTime, current=0): - return revent_checked(c, active, atom(c, '_NET_ACTIVE_WINDOW'), - [source, timestamp, current]) + return revent_checked(active, '_NET_ACTIVE_WINDOW', source, timestamp, + current) # _NET_WORKAREA @@ -710,30 +632,24 @@ def reply(self): return ret -def get_workarea(c, window): +def get_workarea(): """ Returns the x, y, width and height defining the desktop workarea. - @param c: An xpyb connection object. - @param window: A window identifier. @return: A list of workarea dictionaries. Keys: x, y, width, height @rtype: util.WorkareaCookie (CARDINAL[][4]/32) """ - return WorkareaCookie( - util.get_property(c, window, atom(c, '_NET_WORKAREA'))) + return WorkareaCookie(util.get_property(root, '_NET_WORKAREA')) -def get_workarea_unchecked(c, window): - return WorkareaCookie( - util.get_property_unchecked(c, window, atom(c, '_NET_WORKAREA'))) +def get_workarea_unchecked(): + return WorkareaCookie(util.get_property_unchecked(root, '_NET_WORKAREA')) -def set_workarea(c, window, workareas): +def set_workarea(workareas): """ Sets the workarea (x, y, width, height) for each desktop. - @param c: An xpyb connection object. - @param window: A window identifier. @param workareas: A list of x,y,width,height dictionaries. @type workareas: CARDINAL[][4]/32 @rtype: xcb.VoidCookie @@ -746,13 +662,11 @@ def set_workarea(c, window, workareas): flatten.append(workarea['height']) packed = struct.pack('I' * len(flatten), *flatten) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WORKAREA'), - CARDINAL, 32, - len(flatten), - packed) + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_WORKAREA'), CARDINAL, 32, + len(flatten), packed) -def set_workarea_checked(c, window, workareas): +def set_workarea_checked(workareas): flatten = [] for workarea in workareas: flatten.append(workarea['x']) @@ -761,99 +675,78 @@ def set_workarea_checked(c, window, workareas): flatten.append(workarea['height']) packed = struct.pack('I' * len(flatten), *flatten) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WORKAREA'), - CARDINAL, 32, - len(flatten), - packed) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_WORKAREA'), CARDINAL, 32, + len(flatten), packed) # _NET_SUPPORTING_WM_CHECK -def get_supporting_wm_check(c, window): +def get_supporting_wm_check(): """ Returns the identifier of the child window created by the window manager. - @param c: An xpyb connection object. - @param window: A window identifier. @return: The window ID of the child window. @rtype: util.PropertyCookieSingle (WINDOW/32) """ - return util.PropertyCookieSingle( - util.get_property(c, window, atom(c, '_NET_SUPPORTING_WM_CHECK'))) + cook = util.get_property(root, '_NET_SUPPORTING_WM_CHECK') + return util.PropertyCookieSingle(cook) -def get_supporting_wm_check_unchecked(c, window): - return util.PropertyCookieSingle( - util.get_property_unchecked(c, window, - atom(c, '_NET_SUPPORTING_WM_CHECK'))) +def get_supporting_wm_check_unchecked(): + cook = util.get_property_unchecked(root, '_NET_SUPPORTING_WM_CHECK') + return util.PropertyCookieSingle(cook) -def set_supporting_wm_check(c, window, child): +def set_supporting_wm_check(child): """ Sets the identifier of the child window created by the window manager. - @param c: An xpyb connection object. - @param window: A window identifier. @param child: The identifier of the child window. @type child: WINDOW/32 @rtype: xcb.VoidCookie """ packed = struct.pack('I', child) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_SUPPORTING_WM_CHECK'), - xcb.xproto.Atom.WINDOW, 32, - 1, - packed) + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_SUPPORTING_WM_CHECK'), + WINDOW, 32, 1, packed) -def set_supporting_wm_check_checked(c, window, child): +def set_supporting_wm_check_checked(child): packed = struct.pack('I', child) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_SUPPORTING_WM_CHECK'), - xcb.xproto.Atom.WINDOW, 32, - 1, - packed) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_SUPPORTING_WM_CHECK'), + WINDOW, 32, 1, packed) # _NET_VIRTUAL_ROOTS -def get_virtual_roots(c, window): +def get_virtual_roots(): """ Returns a list of identifiers for the virtual root windows. - @param c: An xpyb connection object. - @param window: A window identifier. @return: A list of window identifiers for the virtual root windows. @rtype: util.PropertyCookie (WINDOW[]/32) """ - return util.PropertyCookie( - util.get_property(c, window, atom(c, '_NET_VIRTUAL_ROOTS'))) + return util.PropertyCookie(util.get_property(root, '_NET_VIRTUAL_ROOTS')) -def get_virtual_roots_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_VIRTUAL_ROOTS'))) +def get_virtual_roots_unchecked(): + cook = util.get_property_unchecked(root, '_NET_VIRTUAL_ROOTS') + return util.PropertyCookie(cook) -def set_virtual_roots(c, window, vroots): +def set_virtual_roots(vroots): """ Sets the identifiers of the virtual root windows. - @param c: An xpyb connection object. - @param window: A window identifier. @param vroots: A list of window identifiers for the virtual root windows. @type vroots: WINDOW[]/32 @rtype: xcb.VoidCookie """ packed = struct.pack('I' * len(vroots), *vroots) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_VIRTUAL_ROOTS'), - xcb.xproto.Atom.WINDOW, 32, - len(vroots), - packed) + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_VIRTUAL_ROOTS'), + WINDOW, 32, len(vroots), packed) -def set_virtual_roots_checked(c, window, vroots): +def set_virtual_roots_checked(vroots): packed = struct.pack('I' * len(vroots), *vroots) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_VIRTUAL_ROOTS'), - xcb.xproto.Atom.WINDOW, 32, - len(vroots), - packed) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_VIRTUAL_ROOTS'), + WINDOW, 32, len(vroots), packed) # _NET_DESKTOP_LAYOUT @@ -871,41 +764,26 @@ def reply(self): 'starting_corner': v[3] if len(v) > 3 else StartingCorner.TopLeft } -def get_desktop_layout(c, window): +def get_desktop_layout(): """ Returns the desktop layout. - @param c: An xpyb connection object. - @param window: A window identifier. @return: A desktop layout dictionary. Keys: orientation, columns, rows, starting_corner @rtype: DesktopLayoutCookie (CARDINAL[4]/32) """ - return DesktopLayoutCookie( - util.get_property(c, window, atom(c, '_NET_DESKTOP_LAYOUT'))) - -def get_desktop_layout_unchecked(c, window): - """ - Returns the desktop layout. + return DesktopLayoutCookie(util.get_property(root, '_NET_DESKTOP_LAYOUT')) - @param c: An xpyb connection object. - @param window: A window identifier. - @return: A desktop layout dictionary. - - Keys: orientation, columns, rows, starting_corner - @rtype: DesktopLayoutCookie (CARDINAL[4]/32) - """ - return DesktopLayoutCookie( - util.get_property_unchecked(c, window, atom(c, '_NET_DESKTOP_LAYOUT'))) +def get_desktop_layout_unchecked(): + cook = util.get_property_unchecked(root, '_NET_DESKTOP_LAYOUT') + return DesktopLayoutCookie(cook) -def set_desktop_layout(c, window, orientation, columns, rows, +def set_desktop_layout(orientation, columns, rows, starting_corner=StartingCorner.TopLeft): """ Sets the desktop layout. - @param c: An xpyb connection object. - @param window: A window identifier. @param orientation: Horizontal or vertical orientation. @type orientation: CARDINAL/32 @param columns: Number of columns. @@ -918,18 +796,16 @@ def set_desktop_layout(c, window, orientation, columns, rows, @rtype: xcb.VoidCookie """ packed = struct.pack('IIII', orientation, columns, rows, starting_corner) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_DESKTOP_LAYOUT'), - CARDINAL, 32, 4, - packed) + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_DESKTOP_LAYOUT'), + CARDINAL, 32, 4, packed) -def set_desktop_layout_checked(c, window, orientation, columns, rows, +def set_desktop_layout_checked(orientation, columns, rows, starting_corner=StartingCorner.TopLeft): packed = struct.pack('IIII', orientation, columns, rows, starting_corner) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_DESKTOP_LAYOUT'), - CARDINAL, 32, 4, - packed) + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_DESKTOP_LAYOUT'), + CARDINAL, 32, 4, packed) # _NET_SHOWING_DESKTOP @@ -944,93 +820,78 @@ def reply(self): return True return False -def get_showing_desktop(c, window): +def get_showing_desktop(): """ Returns whether the window manager is in "showing the desktop" mode. - @param c: An xpyb connection object. - @param window: A window identifier. @return: Boolean whether the window manager is in "showing desktop" mode or not. @rtype: ShowingDesktopCookie (CARDINAL/32) """ - return ShowingDesktopCookie( - util.get_property(c, window, atom(c, '_NET_SHOWING_DESKTOP'))) + return ShowingDesktopCookie(util.get_property(root, '_NET_SHOWING_DESKTOP')) -def get_showing_desktop_unchecked(c, window): - return ShowingDesktopCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_SHOWING_DESKTOP'))) +def get_showing_desktop_unchecked(): + cook = util.get_property_unchecked(root, '_NET_SHOWING_DESKTOP') + return ShowingDesktopCookie(cook) -def set_showing_desktop(c, window, showing_desktop): +def set_showing_desktop(showing_desktop): """ Sets whether the window is in "showing the desktop" mode. - @param c: An xpyb connection object. - @param window: A window identifier. @param showing_desktop: Boolean whether the window manager is in "showing desktop" mode or not. @type showing_desktop: CARDINAL/32 @rtype: xcb.VoidCookie """ - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_SHOWING_DESKTOP'), - CARDINAL, 32, 1, + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + atom('_NET_SHOWING_DESKTOP'), CARDINAL, 32, 1, [showing_desktop]) -def set_showing_desktop_checked(c, window, showing_desktop): - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_SHOWING_DESKTOP'), - CARDINAL, 32, 1, - [showing_desktop]) +def set_showing_desktop_checked(showing_desktop): + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + atom('_NET_SHOWING_DESKTOP'), + CARDINAL, 32, 1, [showing_desktop]) -def request_showing_desktop(c, showing_desktop): +def request_showing_desktop(showing_desktop): """ Sends event to root window to put window manager in "showing desktop" mode. - @param c: An xpyb connection object. @param showing_desktop: Boolean whether the window manager is in "showing desktop" mode or not. @type showing_desktop: CARDINAL/32 @rtype: xcb.VoidCookie """ - return revent(c, root(c), atom(c, '_NET_SHOWING_DESKTOP'), - [showing_desktop]) + return revent(root, '_NET_SHOWING_DESKTOP', showing_desktop) -def request_showing_desktop_checked(c, showing_desktop): - return revent_checked(c, root(c), atom(c, '_NET_SHOWING_DESKTOP'), - [showing_desktop]) +def request_showing_desktop_checked(showing_desktop): + return revent_checked(root, '_NET_SHOWING_DESKTOP', showing_desktop) # _NET_CLOSE_WINDOW -def request_close_window(c, window, timestamp=xcb.xproto.Time.CurrentTime, +def request_close_window(window, timestamp=xcb.xproto.Time.CurrentTime, source=1): """ Sends event to root window to close a window. - @param c: An xpyb connection object. @param window: A window identifier. @param source: The source indication. @type timestamp: Milliseconds @rtype: xcb.VoidCookie """ - return revent(c, window, atom(c, '_NET_CLOSE_WINDOW'), - [timestamp, source]) + return revent(window, '_NET_CLOSE_WINDOW', timestamp, source) -def request_close_window_checked(c, window, timestamp=xcb.xproto.Time.CurrentTime, +def request_close_window_checked(window, timestamp=xcb.xproto.Time.CurrentTime, source=1): - return revent_checked(c, window, atom(c, '_NET_CLOSE_WINDOW'), - [timestamp, source]) + return revent_checked(window, '_NET_CLOSE_WINDOW', timestamp, source) # _NET_MOVERESIZE_WINDOW -def request_moveresize_window(c, window, x=None, y=None, width=None, +def request_moveresize_window(window, x=None, y=None, width=None, height=None, gravity=xcb.xproto.Gravity.BitForget, source=1): """ Sends event to root window to move/resize a window. - @param c: An xpyb connection object. @param window: A window identifier. @param x: x coordinate @param y: y coordinate @@ -1054,10 +915,10 @@ def request_moveresize_window(c, window, x=None, y=None, width=None, if height is not None: flags |= 1 << 11 - return revent(c, window, atom(c, '_NET_MOVERESIZE_WINDOW'), - [flags, x or 0, y or 0, width or 0, height or 0]) + return revent(window, '_NET_MOVERESIZE_WINDOW', + flags, x or 0, y or 0, width or 0, height or 0) -def request_moveresize_window_checked(c, window, x=None, y=None, width=None, +def request_moveresize_window_checked(window, x=None, y=None, width=None, height=None, gravity=xcb.xproto.Gravity.BitForget, source=1): @@ -1072,17 +933,16 @@ def request_moveresize_window_checked(c, window, x=None, y=None, width=None, if height is not None: flags |= 1 << 11 - return revent_checked(c, window, atom(c, '_NET_MOVERESIZE_WINDOW'), - [flags, x, y, width, height]) + return revent_checked(window, '_NET_MOVERESIZE_WINDOW', + flags, x, y, width, height) # _NET_WM_MOVERESIZE -def request_wm_moveresize(c, window, direction, x_root=0, y_root=0, +def request_wm_moveresize(window, direction, x_root=0, y_root=0, button=0, source=1): """ Sends event to root window to initiate window movement or resizing. - @param c: An xpyb connection object. @param window: A window identifier. @param direction: Whether it is moving or resizing, and if resizing, the direction. Can be one of the following flags: @@ -1117,22 +977,21 @@ def request_wm_moveresize(c, window, direction, x_root=0, y_root=0, @param source: The source indication. @rtype: xcb.VoidCookie """ - return revent(c, window, atom(c, '_NET_WM_MOVERESIZE'), - [x_root, y_root, direction, button, source]) + return revent(window, '_NET_WM_MOVERESIZE', + x_root, y_root, direction, button, source) -def request_wm_moveresize_checked(c, window, direction, x_root=0, y_root=0, +def request_wm_moveresize_checked(window, direction, x_root=0, y_root=0, button=0, source=1): - return revent_checked(c, window, atom(c, '_NET_WM_MOVERESIZE'), - [x_root, y_root, direction, button, source]) + return revent_checked(window, '_NET_WM_MOVERESIZE', + x_root, y_root, direction, button, source) # _NET_RESTACK_WINDOW -def request_restack_window(c, window, stack_mode=xcb.xproto.StackMode.Above, +def request_restack_window(window, stack_mode=xcb.xproto.StackMode.Above, sibling=0, source=1): """ Sends event to root window to restack a window. - @param c: An xpyb connection object. @param window: A window identifier. @param stack_mode: Stacking mode of window. Can be one of the following flags: Above, Below, TopIf, BottomIf, Opposite @@ -1140,185 +999,166 @@ def request_restack_window(c, window, stack_mode=xcb.xproto.StackMode.Above, @param source: The source indication. @rtype: xcb.VoidCookie """ - return revent(c, window, atom(c, '_NET_RESTACK_WINDOW'), - [source, sibling, stack_mode]) + return revent(window, '_NET_RESTACK_WINDOW', source, sibling, stack_mode) -def request_restack_window_checked(c, window, +def request_restack_window_checked(window, stack_mode=xcb.xproto.StackMode.Above, - sibling=0, - source=2): - return revent_checked(c, window, atom(c, '_NET_RESTACK_WINDOW'), - [source, sibling, stack_mode]) + sibling=0, source=2): + return revent_checked(window, '_NET_RESTACK_WINDOW', + source, sibling, stack_mode) # _NET_REQUEST_FRAME_EXTENTS -def request_request_frame_extents(c, window): +def request_request_frame_extents(window): """ Sends event to root window ask the WM to estimate the frame extents. - @param c: An xpyb connection object. @param window: A window identifier. @rtype: xcb.VoidCookie """ - return revent(c, window, atom(c, '_NET_REQUEST_FRAME_EXTENTS'), []) + return revent(window, '_NET_REQUEST_FRAME_EXTENTS') -def request_request_frame_extents_checked(c, window): - return revent_checked(c, window, atom(c, '_NET_REQUEST_FRAME_EXTENTS'), []) +def request_request_frame_extents_checked(window): + return revent_checked(window, '_NET_REQUEST_FRAME_EXTENTS') # _NET_WM_NAME -def get_wm_name(c, window): +def get_wm_name(window): """ Get the title of a window. - @param c: An xpyb connection object. @param window: A window identifier. @return: The window's title. @rtype: util.PropertyCookie (UTF8_STRING) """ - return util.PropertyCookie( - util.get_property(c, window, atom(c, '_NET_WM_NAME'))) + return util.PropertyCookie(util.get_property(window, '_NET_WM_NAME')) -def get_wm_name_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, atom(c, '_NET_WM_NAME'))) +def get_wm_name_unchecked(window): + return util.PropertyCookie(util.get_property_unchecked(window, + '_NET_WM_NAME')) -def set_wm_name(c, window, wm_name): +def set_wm_name(window, wm_name): """ Sets the title of a window. - @param c: An xpyb connection object. @param window: A window identifier. @param wm_name: The title of the window. @rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_NAME'), - atom(c, 'UTF8_STRING'), 8, len(wm_name), - wm_name) + atom('_NET_WM_NAME'), + atom('UTF8_STRING'), 8, len(wm_name), wm_name) -def set_wm_name_checked(c, window, wm_name): +def set_wm_name_checked(window, wm_name): return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_NAME'), - atom(c, 'UTF8_STRING'), 8, len(wm_name), - wm_name) + atom('_NET_WM_NAME'), + atom('UTF8_STRING'), 8, len(wm_name), + wm_name) # _NET_WM_VISIBLE_NAME -def get_wm_visible_name(c, window): +def get_wm_visible_name(window): """ Get the visible title of a window. - @param c: An xpyb connection object. @param window: A window identifier. @return: The window's visible title. @rtype: util.PropertyCookie (UTF8_STRING) """ - return util.PropertyCookie( - util.get_property(c, window, atom(c, '_NET_WM_VISIBLE_NAME'))) + return util.PropertyCookie(util.get_property(window, + '_NET_WM_VISIBLE_NAME')) -def get_wm_visible_name_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_WM_VISIBLE_NAME'))) +def get_wm_visible_name_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_VISIBLE_NAME') + return util.PropertyCookie(cook) -def set_wm_visible_name(c, window, wm_name): +def set_wm_visible_name(window, wm_name): """ Sets the visible title of a window. - @param c: An xpyb connection object. @param window: A window identifier. @param wm_name: The title of the window. @rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_VISIBLE_NAME'), - atom(c, 'UTF8_STRING'), 8, len(wm_name), - wm_name) + atom('_NET_WM_VISIBLE_NAME'), + atom('UTF8_STRING'), 8, len(wm_name), wm_name) -def set_wm_visible_name_checked(c, window, wm_name): +def set_wm_visible_name_checked(window, wm_name): return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_VISIBLE_NAME'), - atom(c, 'UTF8_STRING'), 8, len(wm_name), - wm_name) + atom('_NET_WM_VISIBLE_NAME'), + atom('UTF8_STRING'), 8, len(wm_name), + wm_name) # _NET_WM_ICON_NAME -def get_wm_icon_name(c, window): +def get_wm_icon_name(window): """ Get the icon name of a window. - @param c: An xpyb connection object. @param window: A window identifier. @return: The window's icon name. @rtype: util.PropertyCookie (UTF8_STRING) """ - return util.PropertyCookie( - util.get_property(c, window, atom(c, '_NET_WM_ICON_NAME'))) + return util.PropertyCookie(util.get_property(window, '_NET_WM_ICON_NAME')) -def get_wm_icon_name_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_WM_ICON_NAME'))) +def get_wm_icon_name_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_ICON_NAME') + return util.PropertyCookie(cook) -def set_wm_icon_name(c, window, icon_name): +def set_wm_icon_name(window, icon_name): """ Sets the icon name of a window. - @param c: An xpyb connection object. @param window: A window identifier. @param icon_name: The icon name of the window. @rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_ICON_NAME'), - atom(c, 'UTF8_STRING'), 8, len(icon_name), - icon_name) + atom('_NET_WM_ICON_NAME'), atom('UTF8_STRING'), + 8, len(icon_name), icon_name) -def set_wm_icon_name_checked(c, window, icon_name): +def set_wm_icon_name_checked(window, icon_name): return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_ICON_NAME'), - atom(c, 'UTF8_STRING'), 8, len(icon_name), - icon_name) + atom('_NET_WM_ICON_NAME'), + atom('UTF8_STRING'), 8, len(icon_name), + icon_name) # _NET_WM_VISIBLE_ICON_NAME -def get_wm_visible_icon_name(c, window): +def get_wm_visible_icon_name(window): """ Get the visible icon name of a window. - @param c: An xpyb connection object. @param window: A window identifier. @return: The window's visible icon name. @rtype: util.PropertyCookie (UTF8_STRING) """ - return util.PropertyCookie( - util.get_property(c, window, atom(c, '_NET_WM_VISIBLE_ICON_NAME'))) + return util.PropertyCookie(util.get_property(window, + '_NET_WM_VISIBLE_ICON_NAME')) -def get_wm_visible_icon_name_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_WM_VISIBLE_ICON_NAME'))) +def get_wm_visible_icon_name_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_VISIBLE_ICON_NAME') + return util.PropertyCookie(cook) -def set_wm_visible_icon_name(c, window, icon_name): +def set_wm_visible_icon_name(window, icon_name): """ Sets the visible icon name of a window. - @param c: An xpyb connection object. @param window: A window identifier. @param icon_name: The icon name of the window. @rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_VISIBLE_ICON_NAME'), - atom(c, 'UTF8_STRING'), 8, len(icon_name), - icon_name) + atom('_NET_WM_VISIBLE_ICON_NAME'), + atom('UTF8_STRING'), 8, len(icon_name), + icon_name) -def set_wm_visible_icon_name_checked(c, window, icon_name): +def set_wm_visible_icon_name_checked(window, icon_name): return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_VISIBLE_ICON_NAME'), - atom(c, 'UTF8_STRING'), 8, len(icon_name), - icon_name) + atom('_NET_WM_VISIBLE_ICON_NAME'), + atom('UTF8_STRING'), 8, len(icon_name), + icon_name) # _NET_WM_WINDOW_OPACITY @@ -1331,34 +1171,31 @@ def reply(self): return float(v) / float(0xffffffff) -def get_wm_window_opacity(c, window): +def get_wm_window_opacity(window): """ Get the opacity of the current window. N.B. If your window manager uses decorations, you'll typically want to pass your client's *parent* window to this function. - @param c: An xpyb connection object. @param window: A window identifier. @return: An opacity percentage between 0 and 1 (inclusive) @rtype: util.PropertyCookieSingle (CARDINAL/32) """ - return OpacityCookieSingle( - util.get_property(c, window, atom(c, '_NET_WM_WINDOW_OPACITY'))) + return OpacityCookieSingle(util.get_property(window, + '_NET_WM_WINDOW_OPACITY')) -def get_wm_window_opacity_unchecked(c, window): - return OpacityCookieSingle( - util.get_property_unchecked(c, window, - atom(c, '_NET_WM_WINDOW_OPACITY'))) +def get_wm_window_opacity_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_WINDOW_OPACITY') + return OpacityCookieSingle(cook) -def set_wm_window_opacity(c, window, opacity): +def set_wm_window_opacity(window, opacity): """ Sets the opacity of the current window. N.B. If your window manager uses decorations, you'll typically want to pass your client's *parent* window to this function. - @param c: An xpyb connection object. @param window: A window identifier. @param opacity: A float between 0 and 1 inclusive. @@ -1369,96 +1206,86 @@ def set_wm_window_opacity(c, window, opacity): assert 0 <= opacity <= 1 packed = struct.pack('I', int(opacity * 0xffffffff)) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_WINDOW_OPACITY'), - CARDINAL, 32, 1, packed) + atom('_NET_WM_WINDOW_OPACITY'), + CARDINAL, 32, 1, packed) -def set_wm_window_opacity_checked(c, window, opacity): +def set_wm_window_opacity_checked(window, opacity): assert 0 <= opacity <= 1 packed = struct.pack('I', int(opacity * 0xffffffff)) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_WINDOW_OPACITY'), - CARDINAL, 32, 1, - packed) + atom('_NET_WM_WINDOW_OPACITY'), + CARDINAL, 32, 1, packed) # _NET_WM_DESKTOP -def get_wm_desktop(c, window): +def get_wm_desktop(window): """ Get the desktop index of the window. - @param c: An xpyb connection object. @param window: A window identifier. @return: The window's virtual desktop index. @rtype: util.PropertyCookieSingle (CARDINAL/32) """ - return util.PropertyCookieSingle( - util.get_property(c, window, atom(c, '_NET_WM_DESKTOP'))) + return util.PropertyCookieSingle(util.get_property(window, + '_NET_WM_DESKTOP')) -def get_wm_desktop_unchecked(c, window): - return util.PropertyCookieSingle( - util.get_property_unchecked(c, window, atom(c, '_NET_WM_DESKTOP'))) +def get_wm_desktop_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_DESKTOP') + return util.PropertyCookieSingle(cook) -def set_wm_desktop(c, window, desktop): +def set_wm_desktop(window, desktop): """ Sets the desktop index of the window. - @param c: An xpyb connection object. @param window: A window identifier. @param desktop: A desktop index. @type desktop: CARDINAL/32 @rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_DESKTOP'), - CARDINAL, 32, 1, - [desktop]) + atom('_NET_WM_DESKTOP'), + CARDINAL, 32, 1, [desktop]) -def set_wm_desktop_checked(c, window, desktop): +def set_wm_desktop_checked(window, desktop): return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_DESKTOP'), - CARDINAL, 32, 1, - [desktop]) + atom('_NET_WM_DESKTOP'), + CARDINAL, 32, 1, [desktop]) -def request_wm_desktop(c, window, desktop, source=1): +def request_wm_desktop(window, desktop, source=1): """ Sends an event to root window to change the desktop of the window. - @param c: An xpyb connection object. @param window: A window identifier. @param desktop: A desktop index. @type desktop: CARDINAL/32 @param source: The source indication. @rtype: xcb.VoidCookie """ - return revent(c, window, atom(c, '_NET_WM_DESKTOP'), [desktop, source]) + return revent(window, '_NET_WM_DESKTOP', desktop, source) -def request_wm_desktop_checked(c, window, desktop, source=1): - return revent_checked(c, window, atom(c, '_NET_WM_DESKTOP'), - [desktop, source]) +def request_wm_desktop_checked(window, desktop, source=1): + return revent_checked(window, '_NET_WM_DESKTOP', desktop, source) # _NET_WM_WINDOW_TYPE -def get_wm_window_type(c, window): +def get_wm_window_type(window): """ Get a list of atoms representing the type of the window. - @param c: An xpyb connection object. @param window: A window identifier. @return: A list of atoms corresponding to this window's type. @rtype: util.PropertyCookie (ATOM[]/32) """ - return util.PropertyCookie( - util.get_property(c, window, atom(c, '_NET_WM_WINDOW_TYPE'))) + return util.PropertyCookie(util.get_property(window, '_NET_WM_WINDOW_TYPE')) -def get_wm_window_type_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, atom(c, '_NET_WM_WINDOW_TYPE'))) +def get_wm_window_type_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_WINDOW_TYPE') + return util.PropertyCookie(cook) -def set_wm_window_type(c, window, types): +def set_wm_window_type(window, types): """ Sets the list of atoms representing this window's type. - @param c: An xpyb connection object. @param window: A window identifier. @param types: A list of window type atoms. @type types: ATOM[]/32 @@ -1466,40 +1293,35 @@ def set_wm_window_type(c, window, types): """ packed = struct.pack('I' * len(types), *types) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_WINDOW_TYPE'), - xcb.xproto.Atom.ATOM, 32, len(types), - packed) + atom('_NET_WM_WINDOW_TYPE'), + ATOM, 32, len(types), packed) -def set_wm_window_type_checked(c, window, types): +def set_wm_window_type_checked(window, types): packed = struct.pack('I' * len(types), *types) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_WINDOW_TYPE'), - xcb.xproto.Atom.ATOM, 32, len(types), - packed) + atom('_NET_WM_WINDOW_TYPE'), + ATOM, 32, len(types), packed) # _NET_WM_STATE -def get_wm_state(c, window): +def get_wm_state(window): """ Get a list of atoms representing the state of the window. - @param c: An xpyb connection object. @param window: A window identifier. @return: A list of atoms corresponding to this window's state. @rtype: util.PropertyCookie (ATOM[]/32) """ - return util.PropertyCookie( - util.get_property(c, window, atom(c, '_NET_WM_STATE'))) + return util.PropertyCookie(util.get_property(window, '_NET_WM_STATE')) -def get_wm_state_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, atom(c, '_NET_WM_STATE'))) +def get_wm_state_unchecked(window): + return util.PropertyCookie(util.get_property_unchecked(window, + '_NET_WM_STATE')) -def set_wm_state(c, window, states): +def set_wm_state(window, states): """ Sets the list of atoms representing this window's state. - @param c: An xpyb connection object. @param window: A window identifier. @param states: A list of window state atoms. @type states: ATOM[]/32 @@ -1507,22 +1329,19 @@ def set_wm_state(c, window, states): """ packed = struct.pack('I' * len(states), *states) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_STATE'), - xcb.xproto.Atom.ATOM, 32, len(states), + atom('_NET_WM_STATE'), ATOM, 32, len(states), packed) -def set_wm_state_checked(c, window, states): +def set_wm_state_checked(window, states): packed = struct.pack('I' * len(states), *states) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_STATE'), - xcb.xproto.Atom.ATOM, 32, len(states), - packed) + atom('_NET_WM_STATE'), + ATOM, 32, len(states), packed) -def request_wm_state(c, window, action, first, second=0, source=1): +def request_wm_state(window, action, first, second=0, source=1): """ Sends an event to root window to change the state of the window. - @param c: An xpyb connection object. @param window: A window identifier. @param action: The kind of state action to perform. I tshould be one of the following flags: @@ -1536,38 +1355,34 @@ def request_wm_state(c, window, action, first, second=0, source=1): @param source: The source indication. @rtype: xcb.VoidCookie """ - return revent(c, window, atom(c, '_NET_WM_STATE'), [action, first, - second, source]) + return revent(window, '_NET_WM_STATE', action, first, second, source) -def request_wm_state_checked(c, window, action, first, second=0, source=1): - return revent_checked(c, window, atom(c, '_NET_WM_STATE'), [action, first, - second, source]) +def request_wm_state_checked(window, action, first, second=0, source=1): + return revent_checked(window, '_NET_WM_STATE', + action, first, second, source) # _NET_WM_ALLOWED_ACTIONS -def get_wm_allowed_actions(c, window): +def get_wm_allowed_actions(window): """ Get a list of atoms representing the WM supported actions on a window. - @param c: An xpyb connection object. @param window: A window identifier. @return: A list of atoms corresponding to this window's supported actions through the window manager. @rtype: util.PropertyCookie (ATOM[]/32) """ - return util.PropertyCookie( - util.get_property(c, window, atom(c, '_NET_WM_ALLOWED_ACTIONS'))) + return util.PropertyCookie(util.get_property(window, + '_NET_WM_ALLOWED_ACTIONS')) -def get_wm_allowed_actions_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_WM_ALLOWED_ACTIONS'))) +def get_wm_allowed_actions_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_ALLOWED_ACTIONS') + return util.PropertyCookie(cook) -def set_wm_allowed_actions(c, window, actions): +def set_wm_allowed_actions(window, actions): """ Sets the list of atoms representing the WM supported actions on a window. - @param c: An xpyb connection object. @param window: A window identifier. @param actions: A list of allowable action atoms. @type actions: ATOM[]/32 @@ -1575,16 +1390,14 @@ def set_wm_allowed_actions(c, window, actions): """ packed = struct.pack('I' * len(actions), *actions) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_ALLOWED_ACTIONS'), - xcb.xproto.Atom.ATOM, 32, len(actions), - packed) + atom('_NET_WM_ALLOWED_ACTIONS'), + ATOM, 32, len(actions), packed) -def set_wm_allowed_actions_checked(c, window, actions): +def set_wm_allowed_actions_checked(window, actions): packed = struct.pack('I' * len(actions), *actions) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_ALLOWED_ACTIONS'), - xcb.xproto.Atom.ATOM, 32, len(actions), - packed) + atom('_NET_WM_ALLOWED_ACTIONS'), + ATOM, 32, len(actions), packed) # _NET_WM_STRUT @@ -1602,29 +1415,25 @@ def reply(self): 'bottom': v[3] } -def get_wm_strut(c, window): +def get_wm_strut(window): """ Returns the struts for a window. - @param c: An xpyb connection object. @param window: A window identifier. @return: A strut dictionary. Keys: left, right, top, bottom @rtype: StrutCookie (CARDINAL[4]/32) """ - return StrutCookie( - util.get_property(c, window, atom(c, '_NET_WM_STRUT'))) + return StrutCookie(util.get_property(window, '_NET_WM_STRUT')) -def get_wm_strut_unchecked(c, window): - return StrutCookie( - util.get_property_unchecked(c, window, atom(c, '_NET_WM_STRUT'))) +def get_wm_strut_unchecked(window): + return StrutCookie(util.get_property_unchecked(window, '_NET_WM_STRUT')) -def set_wm_strut(c, window, left, right, top, bottom): +def set_wm_strut(window, left, right, top, bottom): """ Sets the struts for a window. - @param c: An xpyb connection object. @param window: A window identifier. @param left: Width of area at left side of screen. @type left: CARDINAL/32 @@ -1638,16 +1447,13 @@ def set_wm_strut(c, window, left, right, top, bottom): """ packed = struct.pack('IIII', left, right, top, bottom) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_STRUT'), - CARDINAL, 32, 4, - packed) + atom('_NET_WM_STRUT'), CARDINAL, 32, 4, packed) -def set_wm_strut_checked(c, window, left, right, top, bottom): +def set_wm_strut_checked(window, left, right, top, bottom): packed = struct.pack('IIII', left, right, top, bottom) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_STRUT'), - CARDINAL, 32, 4, - packed) + atom('_NET_WM_STRUT'), + CARDINAL, 32, 4, packed) # _NET_WM_STRUT_PARTIAL @@ -1673,11 +1479,10 @@ def reply(self): 'bottom_end_x': v[11] } -def get_wm_strut_partial(c, window): +def get_wm_strut_partial(window): """ Returns the partial struts for a window. - @param c: An xpyb connection object. @param window: A window identifier. @return: A strut dictionary. @@ -1686,21 +1491,19 @@ def get_wm_strut_partial(c, window): bottom_start_x, bottom_end_x @rtype: StrutPartialCookie (CARDINAL[12]/32) """ - return StrutPartialCookie( - util.get_property(c, window, atom(c, '_NET_WM_STRUT_PARTIAL'))) + return StrutPartialCookie(util.get_property(window, + '_NET_WM_STRUT_PARTIAL')) -def get_wm_strut_partial_unchecked(c, window): - return StrutPartialCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_WM_STRUT_PARTIAL'))) +def get_wm_strut_partial_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_STRUT_PARTIAL') + return StrutPartialCookie(cook) -def set_wm_strut_partial(c, window, left, right, top, bottom, left_start_y, +def set_wm_strut_partial(window, left, right, top, bottom, left_start_y, left_end_y, right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x, bottom_end_x): """ Sets the partial struts for a window. - @param c: An xpyb connection object. @param window: A window identifier. @param left: Width of area at left side of screen. @type left: CARDINAL/32 @@ -1724,11 +1527,10 @@ def set_wm_strut_partial(c, window, left, right, top, bottom, left_start_y, left_end_y, right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x, bottom_end_x) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_STRUT_PARTIAL'), - CARDINAL, 32, 12, - packed) + atom('_NET_WM_STRUT_PARTIAL'), + CARDINAL, 32, 12, packed) -def set_wm_strut_partial_checked(c, window, left, right, top, bottom, +def set_wm_strut_partial_checked(window, left, right, top, bottom, left_start_y, left_end_y, right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x, bottom_end_x): @@ -1736,9 +1538,8 @@ def set_wm_strut_partial_checked(c, window, left, right, top, bottom, left_end_y, right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x, bottom_end_x) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_STRUT_PARTIAL'), - CARDINAL, 32, 12, - packed) + atom('_NET_WM_STRUT_PARTIAL'), + CARDINAL, 32, 12, packed) # _NET_WM_ICON_GEOMETRY @@ -1756,30 +1557,27 @@ def reply(self): 'height': v[3] } -def get_wm_icon_geometry(c, window): +def get_wm_icon_geometry(window): """ Returns the icon geometry for a window. - @param c: An xpyb connection object. @param window: A window identifier. @return: An icon geometry dictionary. Keys: x, y, width, height @rtype: IconGeometryCookie (CARDINAL[4]/32) """ - return IconGeometryCookie( - util.get_property(c, window, atom(c, '_NET_WM_ICON_GEOMETRY'))) + return IconGeometryCookie(util.get_property(window, + '_NET_WM_ICON_GEOMETRY')) -def get_wm_icon_geometry_unchecked(c, window): - return IconGeometryCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_WM_ICON_GEOMETRY'))) +def get_wm_icon_geometry_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_ICON_GEOMETRY') + return IconGeometryCookie(cook) -def set_wm_icon_geometry(c, window, x, y, width, height): +def set_wm_icon_geometry(window, x, y, width, height): """ Sets the icon geometry for a window. - @param c: An xpyb connection object. @param window: A window identifier. @param x: x coordinate of icon area. @type x: CARDINAL/32 @@ -1793,16 +1591,14 @@ def set_wm_icon_geometry(c, window, x, y, width, height): """ packed = struct.pack('IIII', x, y, width, height) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_ICON_GEOMETRY'), - CARDINAL, 32, 4, - packed) + atom('_NET_WM_ICON_GEOMETRY'), + CARDINAL, 32, 4, packed) -def set_wm_icon_geometry_checked(c, window, x, y, width, height): +def set_wm_icon_geometry_checked(window, x, y, width, height): packed = struct.pack('IIII', x, y, width, height) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_ICON_GEOMETRY'), - CARDINAL, 32, 4, - packed) + atom('_NET_WM_ICON_GEOMETRY'), + CARDINAL, 32, 4, packed) # _NET_WM_ICON @@ -1829,30 +1625,25 @@ def reply(self): return ret -def get_wm_icon(c, window): +def get_wm_icon(window): """ Returns an array of possible icons for a window. - @param c: An xpyb connection object. @param window: A window identifier. @return: A list of icon dictionaries. Keys: width, height, data @rtype: IconCookie (CARDINAL[][2+n]/32) """ - return IconCookie( - util.get_property(c, window, atom(c, '_NET_WM_ICON'))) + return IconCookie(util.get_property(window, '_NET_WM_ICON')) -def get_wm_icon_unchecked(c, window): - return IconCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_WM_ICON'))) +def get_wm_icon_unchecked(window): + return IconCookie(util.get_property_unchecked(window, '_NET_WM_ICON')) -def set_wm_icon(c, window, icons): +def set_wm_icon(window, icons): """ Sets the array of possible icons for a window. - @param c: An xpyb connection object. @param window: A window identifier. @param icons: A list icon dictionaries. Each dictionary should have the following keys: width, height and data. @@ -1868,11 +1659,10 @@ def set_wm_icon(c, window, icons): packed = struct.pack('I' * len(flatten), *flatten) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_ICON'), - CARDINAL, 32, len(flatten), - packed) + atom('_NET_WM_ICON'), + CARDINAL, 32, len(flatten), packed) -def set_wm_icon_checked(c, window, icons): +def set_wm_icon_checked(window, icons): flatten = [] for icon in icons: flatten.append(icon['width']) @@ -1882,166 +1672,145 @@ def set_wm_icon_checked(c, window, icons): packed = struct.pack('I' * len(flatten), *flatten) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_ICON'), - CARDINAL, 32, len(flatten), - packed) + atom('_NET_WM_ICON'), + CARDINAL, 32, len(flatten), packed) # _NET_WM_PID -def get_wm_pid(c, window): +def get_wm_pid(window): """ Get the process ID of the client owning a window. - @param c: An xpyb connection object. @param window: A window identifier. @return: The window's client's process ID. @rtype: util.PropertyCookieSingle (CARDINAL/32) """ - return util.PropertyCookieSingle( - util.get_property(c, window, atom(c, '_NET_WM_PID'))) + return util.PropertyCookieSingle(util.get_property(window, '_NET_WM_PID')) -def get_wm_pid_unchecked(c, window): - return util.PropertyCookieSingle( - util.get_property_unchecked(c, window, atom(c, '_NET_WM_PID'))) +def get_wm_pid_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_PID') + return util.PropertyCookieSingle(cook) -def set_wm_pid(c, window, pid): +def set_wm_pid(window, pid): """ Sets the process ID of the client owning a window. - @param c: An xpyb connection object. @param window: A window identifier. @param pid: A process ID. @type pid: CARDINAL/32 @rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_PID'), - CARDINAL, 32, 1, - [pid]) + atom('_NET_WM_PID'), CARDINAL, 32, 1, [pid]) -def set_wm_pid_checked(c, window, pid): +def set_wm_pid_checked(window, pid): return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_PID'), - CARDINAL, 32, 1, + atom('_NET_WM_PID'), CARDINAL, 32, 1, [pid]) # _NET_WM_HANDLED_ICONS -def get_wm_handled_icons(c, window): +def get_wm_handled_icons(window): """ Gets the "handled icons" property. - @param c: An xpyb connection object. @param window: A window identifier. @return: Whether this property is set or not. @rtype: util.PropertyCookieSingle (CARDINAL/32) """ - return util.PropertyCookieSingle( - util.get_property(c, window, atom(c, '_NET_WM_HANDLED_ICONS'))) + return util.PropertyCookieSingle(util.get_property(window, + '_NET_WM_HANDLED_ICONS')) -def get_wm_handled_icons_unchecked(c, window): - return util.PropertyCookieSingle( - util.get_property_unchecked(c, window, - atom(c, '_NET_WM_HANDLED_ICONS'))) +def get_wm_handled_icons_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_HANDLED_ICONS') + return util.PropertyCookieSingle(cook) -def set_wm_handled_icons(c, window): +def set_wm_handled_icons(window): """ Sets the "handled icons" property. - @param c: An xpyb connection object. @param window: A window identifier. @return: Whether this property is set or not. @rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_HANDLED_ICONS'), - CARDINAL, 32, 1, + atom('_NET_WM_HANDLED_ICONS'), CARDINAL, 32, 1, [1]) -def set_wm_handled_icons_checked(c, window): +def set_wm_handled_icons_checked(window): return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_HANDLED_ICONS'), - CARDINAL, 32, 1, - [1]) + atom('_NET_WM_HANDLED_ICONS'), + CARDINAL, 32, 1, [1]) # _NET_WM_USER_TIME -def get_wm_user_time(c, window): +def get_wm_user_time(window): """ Get the time at which the last user activity occurred on a window. - @param c: An xpyb connection object. @param window: A window identifier. @return: The XServer time when user activity last occurred. @rtype: util.PropertyCookieSingle (CARDINAL/32) """ - return util.PropertyCookieSingle( - util.get_property(c, window, atom(c, '_NET_WM_USER_TIME'))) + return util.PropertyCookieSingle(util.get_property(window, + '_NET_WM_USER_TIME')) -def get_wm_user_time_unchecked(c, window): - return util.PropertyCookieSingle( - util.get_property_unchecked(c, window, atom(c, '_NET_WM_USER_TIME'))) +def get_wm_user_time_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_USER_TIME') + return util.PropertyCookieSingle(cook) -def set_wm_user_time(c, window, user_time): +def set_wm_user_time(window, user_time): """ Sets the time that user activity last occurred on this window. - @param c: An xpyb connection object. @param window: A window identifier. @param user_time: Last user activity time. @type user_time: CARDINAL/32 @rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_USER_TIME'), - CARDINAL, 32, 1, + atom('_NET_WM_USER_TIME'), CARDINAL, 32, 1, [user_time]) -def set_wm_user_time_checked(c, window, user_time): +def set_wm_user_time_checked(window, user_time): return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_USER_TIME'), - CARDINAL, 32, 1, - [user_time]) + atom('_NET_WM_USER_TIME'), + CARDINAL, 32, 1, [user_time]) # _NET_WM_USER_TIME_WINDOW -def get_wm_user_time_window(c, window): +def get_wm_user_time_window(window): """ Gets the window that sets the _NET_WM_USER_TIME property. - @param c: An xpyb connection object. @param window: A window identifier. @return: Window identifier that sets the _NET_WM_USER_TIME property. @rtype: util.PropertyCookieSingle (WINDOW/32) """ - return util.PropertyCookieSingle( - util.get_property(c, window, atom(c, '_NET_WM_USER_TIME_WINDOW'))) + cook = util.get_property(window, '_NET_WM_USER_TIME_WINDOW') + return util.PropertyCookieSingle(cook) -def get_wm_user_time_window_unchecked(c, window): - return util.PropertyCookieSingle( - util.get_property_unchecked(c, window, - atom(c, '_NET_WM_USER_TIME_WINDOW'))) +def get_wm_user_time_window_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_USER_TIME_WINDOW') + return util.PropertyCookieSingle(cook) -def set_wm_user_time_window(c, window, time_win): +def set_wm_user_time_window(window, time_win): """ Sets the window identifier that sets the _NET_WM_USER_TIME property. - @param c: An xpyb connection object. @param window: A window identifier. @param time_win: Window ID that sets the _NET_WM_USER_TIME property. @type time_win: WINDOW/32 @rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_USER_TIME_WINDOW'), - xcb.xproto.Atom.WINDOW, 32, 1, - [time_win]) + atom('_NET_WM_USER_TIME_WINDOW'), + WINDOW, 32, 1, [time_win]) -def set_wm_user_time_window_checked(c, window, time_win): +def set_wm_user_time_window_checked(window, time_win): return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_USER_TIME_WINDOW'), - xcb.xproto.Atom.WINDOW, 32, 1, - [time_win]) + atom('_NET_WM_USER_TIME_WINDOW'), + WINDOW, 32, 1, [time_win]) # _NET_FRAME_EXTENTS @@ -2059,30 +1828,26 @@ def reply(self): 'bottom': v[3] } -def get_frame_extents(c, window): +def get_frame_extents(window): """ Returns the frame extents for a window. - @param c: An xpyb connection object. @param window: A window identifier. @return: A frame extents dictionary. Keys: left, right, top, bottom @rtype: FrameExtentsCookie (CARDINAL[4]/32) """ - return FrameExtentsCookie( - util.get_property(c, window, atom(c, '_NET_FRAME_EXTENTS'))) + return FrameExtentsCookie(util.get_property(window, '_NET_FRAME_EXTENTS')) -def get_frame_extents_unchecked(c, window): - return FrameExtentsCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_FRAME_EXTENTS'))) +def get_frame_extents_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_FRAME_EXTENTS') + return FrameExtentsCookie(cook) -def set_frame_extents(c, window, left, right, top, bottom): +def set_frame_extents(window, left, right, top, bottom): """ Sets the frame extents for a window. - @param c: An xpyb connection object. @param window: A window identifier. @param left: Width of left border. @type left: CARDINAL/32 @@ -2096,48 +1861,42 @@ def set_frame_extents(c, window, left, right, top, bottom): """ packed = struct.pack('IIII', left, right, top, bottom) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_FRAME_EXTENTS'), - CARDINAL, 32, 4, + atom('_NET_FRAME_EXTENTS'), CARDINAL, 32, 4, packed) -def set_frame_extents_checked(c, window, left, right, top, bottom): +def set_frame_extents_checked(window, left, right, top, bottom): packed = struct.pack('IIII', left, right, top, bottom) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_FRAME_EXTENTS'), - CARDINAL, 32, 4, - packed) + atom('_NET_FRAME_EXTENTS'), + CARDINAL, 32, 4, packed) # _NET_WM_PING -def request_wm_ping(c, window, response=False, +def request_wm_ping(window, response=False, timestamp=xcb.xproto.Time.CurrentTime): """ Sends an event to root window to ping a window or respond to a ping. - @param c: An xpyb connection object. @param window: A window identifier. @param response: Whether this is a response to a ping request or not. @type timestamp: Milliseconds @rtype: xcb.VoidCookie """ - return revent(c, window if not response else root(c), - atom(c, 'WM_PROTOCOLS'), [atom(c, '_NET_WM_PING'), timestamp, - window]) + return revent(window if not response else root(c), + 'WM_PROTOCOLS', atom('_NET_WM_PING'), timestamp, window) -def request_wm_ping_checked(c, window, response=False, +def request_wm_ping_checked(window, response=False, timestamp=xcb.xproto.Time.CurrentTime): - return revent_checked(c, window if not response else root(c), - atom(c, 'WM_PROTOCOLS'), [atom(c, '_NET_WM_PING'), - timestamp, window]) + return revent_checked(window if not response else root(c), 'WM_PROTOCOLS', + atom('_NET_WM_PING'), timestamp, window) # _NET_WM_SYNC_REQUEST -def request_wm_sync_request(c, window, req_num, +def request_wm_sync_request(window, req_num, timestamp=xcb.xproto.Time.CurrentTime): """ Sends an event to root window to sync with a client. - @param c: An xpyb connection object. @param window: A window identifier. @param req_num: The XSync request number. @type timestamp: Milliseconds @@ -2146,41 +1905,38 @@ def request_wm_sync_request(c, window, req_num, high = req_num >> 32 low = (high << 32) ^ req_num - return revent(c, window, atom(c, 'WM_PROTOCOLS'), - [atom(c, '_NET_WM_SYNC_REQUEST'), timestamp, low, high]) + return revent(window, 'WM_PROTOCOLS', + atom('_NET_WM_SYNC_REQUEST'), timestamp, low, high) -def request_wm_sync_request_checked(c, window, req_num, +def request_wm_sync_request_checked(window, req_num, timestamp=xcb.xproto.Time.CurrentTime): high = req_num >> 32 low = (high << 32) ^ req_num - return revent_checked(c, window, atom(c, 'WM_PROTOCOLS'), - [atom(c, '_NET_WM_SYNC_REQUEST'), timestamp, low, high]) + return revent_checked(window, 'WM_PROTOCOLS', + atom('_NET_WM_SYNC_REQUEST'), timestamp, low, high) # _NET_WM_SYNC_REQUEST_COUNTER -def get_wm_sync_request_counter(c, window): +def get_wm_sync_request_counter(window): """ Gets XSync counter for this client. - @param c: An xpyb connection object. @param window: A window identifier. @return: An XSync XID. @rtype: util.PropertyCookieSingle (CARDINAL/32) """ - return util.PropertyCookieSingle( - util.get_property(c, window, atom(c, '_NET_WM_SYNC_REQUEST_COUNTER'))) + cook = util.get_property(window, '_NET_WM_SYNC_REQUEST_COUNTER') + return util.PropertyCookieSingle(cook) -def get_wm_sync_request_counter_unchecked(c, window): - return util.PropertyCookieSingle( - util.get_property_unchecked(c, window, - atom(c, '_NET_WM_SYNC_REQUEST_COUNTER'))) +def get_wm_sync_request_counter_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_SYNC_REQUEST_COUNTER') + return util.PropertyCookieSingle(cook) -def set_wm_sync_request_counter(c, window, counter): +def set_wm_sync_request_counter(window, counter): """ Sets the XSync counter for this client. - @param c: An xpyb connection object. @param window: A window identifier. @param counter: An XSync XID. @type counter: CARDINAL @@ -2188,17 +1944,14 @@ def set_wm_sync_request_counter(c, window, counter): """ packed = struct.pack('I', counter) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_SYNC_REQUEST_COUNTER'), - CARDINAL, 32, 1, - packed) + atom('_NET_WM_SYNC_REQUEST_COUNTER'), + CARDINAL, 32, 1, packed) -def set_wm_sync_request_counter_checked(c, window, counter): +def set_wm_sync_request_counter_checked(window, counter): packed = struct.pack('I', counter) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, - '_NET_WM_SYNC_REQUEST_COUNTER'), - CARDINAL, 32, 1, - packed) + atom('_NET_WM_SYNC_REQUEST_COUNTER'), + CARDINAL, 32, 1, packed) # _NET_WM_FULLSCREEN_MONITORS @@ -2216,28 +1969,25 @@ def reply(self): 'right': v[3] } -def get_wm_fullscreen_monitors(c, window): +def get_wm_fullscreen_monitors(window): """ Get list of monitor edges for this window. - @param c: An xpyb connection object. @param window: A window identifier. @return: The window's monitor edges. @rtype: FullscreenMonitorsCookie (CARDINAL[4]/32) """ return FullscreenMonitorsCookie( - util.get_property(c, window, atom(c, '_NET_WM_FULLSCREEN_MONITORS'))) + util.get_property(window, '_NET_WM_FULLSCREEN_MONITORS')) -def get_wm_fullscreen_monitors_unchecked(c, window): - return FullscreenMonitorsCookie( - util.get_property_unchecked(c, window, - atom(c, '_NET_WM_FULLSCREEN_MONITORS'))) +def get_wm_fullscreen_monitors_unchecked(window): + cook = util.get_property_unchecked(window, '_NET_WM_FULLSCREEN_MONITORS') + return FullscreenMonitorsCookie(cook) -def set_wm_fullscreen_monitors(c, window, top, bottom, left, right): +def set_wm_fullscreen_monitors(window, top, bottom, left, right): """ Sets list of monitor edges for this window. - @param c: An xpyb connection object. @param window: A window identifier. @param top: The monitor whose top edge defines the top edge of window. @param bottom: The monitor whose bottom edge defines the bottom edge of @@ -2250,23 +2000,20 @@ def set_wm_fullscreen_monitors(c, window, top, bottom, left, right): """ packed = struct.pack('IIII', top, bottom, left, right) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_FULLSCREEN_MONITORS'), - CARDINAL, 32, 4, - packed) + atom('_NET_WM_FULLSCREEN_MONITORS'), + CARDINAL, 32, 4, packed) -def set_wm_fullscreen_monitors_checked(c, window, top, bottom, left, right): +def set_wm_fullscreen_monitors_checked(window, top, bottom, left, right): packed = struct.pack('IIII', top, bottom, left, right) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_NET_WM_FULLSCREEN_MONITORS'), - CARDINAL, 32, 4, - packed) + atom('_NET_WM_FULLSCREEN_MONITORS'), + CARDINAL, 32, 4, packed) -def request_wm_fullscreen_monitors(c, window, top, bottom, left, right, +def request_wm_fullscreen_monitors(window, top, bottom, left, right, source=1): """ Sends an event to root window to change monitor edges for this window. - @param c: An xpyb connection object. @param window: A window identifier. @param top: The monitor whose top edge defines the top edge of window. @param bottom: The monitor whose bottom edge defines the bottom edge of @@ -2278,10 +2025,11 @@ def request_wm_fullscreen_monitors(c, window, top, bottom, left, right, @param source: The source indication. @rtype: xcb.VoidCookie """ - return revent(c, window, atom(c, '_NET_WM_FULLSCREEN_MONITORS'), - [top, bottom, left, right, source]) + return revent(window, '_NET_WM_FULLSCREEN_MONITORS', + top, bottom, left, right, source) -def request_wm_fullscreen_monitors_checked(c, window, top, bottom, left, right, +def request_wm_fullscreen_monitors_checked(window, top, bottom, left, right, source=1): - return revent_checked(c, window, atom(c, '_NET_WM_FULLSCREEN_MONITORS'), - [top, bottom, left, right, source]) + return revent_checked(window, '_NET_WM_FULLSCREEN_MONITORS', + top, bottom, left, right, source) + diff --git a/xpybutil/font.py b/xpybutil/font.py index cc20294..3cffa82 100644 --- a/xpybutil/font.py +++ b/xpybutil/font.py @@ -1,17 +1,18 @@ import xcb.xproto +# This is woefully incomplete. + def get_font_height(qfont): return qfont.max_bounds.ascent + qfont.max_bounds.descent def get_text_width(qfont, text): assert isinstance(qfont, xcb.xproto.QueryFontReply) - return sum([qfont.char_infos[ord(i)].character_width - for i in text]) + return sum([qfont.char_infos[ord(i)].character_width for i in text]) def get_text_height(qfont, text): assert isinstance(qfont, xcb.xproto.QueryFontReply) cinfo = qfont.char_infos - return max([cinfo[ord(i)].ascent + cinfo[ord(i)].descent - for i in text]) + return max([cinfo[ord(i)].ascent + cinfo[ord(i)].descent for i in text]) + diff --git a/xpybutil/icccm.py b/xpybutil/icccm.py index 12e1c4f..d4851a0 100644 --- a/xpybutil/icccm.py +++ b/xpybutil/icccm.py @@ -1,9 +1,9 @@ from collections import defaultdict import struct -from xpybutil import conn, root import xcb.xproto +from xpybutil import root import util __atoms = ['WM_PROTOCOLS', 'WM_TAKE_FOCUS', 'WM_SAVE_YOURSELF', @@ -39,49 +39,50 @@ class State: Iconic = 3 Inactive = 4 +# Some aliases +atom = util.get_atom +atoms = xcb.xproto.Atom + +# Build the atom cache for quicker access +util.build_atom_cache(__atoms) + # WM_NAME -def get_wm_name(c, window): - return util.PropertyCookie( - util.get_property(c, window, xcb.xproto.Atom.WM_NAME)) +def get_wm_name(window): + return util.PropertyCookie(util.get_property(window, atoms.WM_NAME)) -def get_wm_name_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, xcb.xproto.Atom.WM_NAME)) +def get_wm_name_unchecked(window): + return util.PropertyCookie(util.get_property_unchecked(window, + atoms.WM_NAME)) -def set_wm_name(c, window, wm_name): +def set_wm_name(window, wm_name): return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_NAME, - xcb.xproto.Atom.STRING, 8, len(wm_name), - wm_name) + atoms.WM_NAME, atoms.STRING, 8, len(wm_name), + wm_name) -def set_wm_name_checked(c, window, wm_name): +def set_wm_name_checked(window, wm_name): return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_NAME, - xcb.xproto.Atom.STRING, 8, len(wm_name), - wm_name) + atoms.WM_NAME, atoms.STRING, 8, + len(wm_name), wm_name) # WM_ICON_NAME -def get_wm_icon_name(c, window): - return util.PropertyCookie( - util.get_property(c, window, xcb.xproto.Atom.WM_ICON_NAME)) +def get_wm_icon_name(window): + return util.PropertyCookie(util.get_property(window, atoms.WM_ICON_NAME)) -def get_wm_icon_name_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, xcb.xproto.Atom.WM_ICON_NAME)) +def get_wm_icon_name_unchecked(window): + return util.PropertyCookie(util.get_property_unchecked(window, + atoms.WM_ICON_NAME)) -def set_wm_icon_name(c, window, wm_icon_name): +def set_wm_icon_name(window, wm_icon_name): return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_ICON_NAME, - xcb.xproto.Atom.STRING, 8, - len(wm_icon_name), wm_icon_name) + atoms.WM_ICON_NAME, atoms.STRING, 8, + len(wm_icon_name), wm_icon_name) -def set_wm_icon_name_checked(c, window, wm_icon_name): +def set_wm_icon_name_checked(window, wm_icon_name): return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_ICON_NAME, - xcb.xproto.Atom.STRING, 8, - len(wm_icon_name), wm_icon_name) + atoms.WM_ICON_NAME, atoms.STRING, 8, + len(wm_icon_name), wm_icon_name) # WM_NORMAL_HINTS @@ -124,13 +125,12 @@ def reply(self): return retval -def get_wm_normal_hints(c, window): - return NormalHintsCookie( - util.get_property(c, window, xcb.xproto.Atom.WM_NORMAL_HINTS)) +def get_wm_normal_hints(window): + return NormalHintsCookie(util.get_property(window, atoms.WM_NORMAL_HINTS)) -def get_wm_normal_hints_unchecked(c, window): - return NormalHintsCookie( - util.get_property(c, window, xcb.xproto.Atom.WM_NORMAL_HINTS)) +def get_wm_normal_hints_unchecked(window): + return NormalHintsCookie(util.get_property_unchecked(window, + atoms.WM_NORMAL_HINTS)) def _pack_normal_hints(flags, x, y, width, height, min_width, min_height, max_width, max_height, width_inc, height_inc, @@ -171,7 +171,7 @@ def _pack_normal_hints(flags, x, y, width, height, min_width, min_height, return struct.pack('I' * 18, *hints) -def set_wm_normal_hints(c, window, flags, x=0, y=0, width=0, +def set_wm_normal_hints(window, flags, x=0, y=0, width=0, height=0, min_width=0, min_height=0, max_width=0, max_height=0, width_inc=0, height_inc=0, min_aspect_num=0, @@ -184,11 +184,10 @@ def set_wm_normal_hints(c, window, flags, x=0, y=0, width=0, max_aspect_num, max_aspect_den, base_width, base_height, win_gravity) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_NORMAL_HINTS, - xcb.xproto.Atom.WM_SIZE_HINTS, 32, - 18, packed) + atoms.WM_NORMAL_HINTS, atoms.WM_SIZE_HINTS, 32, + 18, packed) -def set_wm_normal_hints_checked(c, window, flags, x=0, y=0, width=0, +def set_wm_normal_hints_checked(window, flags, x=0, y=0, width=0, height=0, min_width=0, min_height=0, max_width=0, max_height=0, width_inc=0, height_inc=0, min_aspect_num=0, @@ -201,9 +200,8 @@ def set_wm_normal_hints_checked(c, window, flags, x=0, y=0, width=0, max_aspect_num, max_aspect_den, base_width, base_height, win_gravity) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_NORMAL_HINTS, - xcb.xproto.Atom.WM_SIZE_HINTS, 32, - 18, packed) + atoms.WM_NORMAL_HINTS, + atoms.WM_SIZE_HINTS, 32, 18, packed) # WM_HINTS @@ -236,13 +234,11 @@ def reply(self): 'window_group': v[8], } -def get_wm_hints(c, window): - return HintsCookie( - util.get_property(c, window, xcb.xproto.Atom.WM_HINTS)) +def get_wm_hints(window): + return HintsCookie(util.get_property(window, atoms.WM_HINTS)) -def get_wm_hints_unchecked(c, window): - return HintsCookie( - util.get_property_unchecked(c, window, xcb.xproto.Atom.WM_HINTS)) +def get_wm_hints_unchecked(window): + return HintsCookie(util.get_property_unchecked(window, atoms.WM_HINTS)) def _pack_hints(flags, input, initial_state, icon_pixmap, icon_window, icon_x, icon_y, icon_mask, window_group): @@ -273,148 +269,131 @@ def _pack_hints(flags, input, initial_state, icon_pixmap, icon_window, return struct.pack('I' * 9, *hints) -def set_wm_hints(c, window, flags, input=1, initial_state=State.Normal, +def set_wm_hints(window, flags, input=1, initial_state=State.Normal, icon_pixmap=0, icon_window=0, icon_x=0, icon_y=0, icon_mask=0, window_group=0): packed = _pack_hints(flags, input, initial_state, icon_pixmap, icon_window, icon_x, icon_y, icon_mask, window_group) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_HINTS, - xcb.xproto.Atom.WM_HINTS, 32, - 9, packed) + atoms.WM_HINTS, atoms.WM_HINTS, 32, 9, packed) -def set_wm_hints_checked(c, window, flags, input=1, +def set_wm_hints_checked(window, flags, input=1, initial_state=State.Normal, icon_pixmap=0, icon_window=0, icon_x=0, icon_y=0, icon_mask=0, window_group=0): packed = _pack_hints(flags, input, initial_state, icon_pixmap, icon_window, icon_x, icon_y, icon_mask, window_group) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_HINTS, - xcb.xproto.Atom.WM_HINTS, 32, - 9, packed) + atoms.WM_HINTS, atoms.WM_HINTS, 32, + 9, packed) # WM_CLASS -def get_wm_class(c, window): - return util.PropertyCookie( - util.get_property(c, window, xcb.xproto.Atom.WM_CLASS)) +def get_wm_class(window): + return util.PropertyCookie(util.get_property(window, atoms.WM_CLASS)) -def get_wm_class_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, xcb.xproto.Atom.WM_CLASS)) +def get_wm_class_unchecked(window): + return util.PropertyCookie(util.get_property_unchecked(window, + atoms.WM_CLASS)) -def set_wm_class(c, window, instance, cls): +def set_wm_class(window, instance, cls): return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_CLASS, - xcb.xproto.Atom.STRING, 8, - len(instance) + len(cls) + 2, - instance + chr(0) + cls + chr(0)) + atoms.WM_CLASS, atoms.STRING, 8, + len(instance) + len(cls) + 2, + instance + chr(0) + cls + chr(0)) -def set_wm_class_checked(c, window, instance, cls): +def set_wm_class_checked(window, instance, cls): return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_CLASS, - xcb.xproto.Atom.STRING, 8, - len(instance) + len(cls) + 2, - instance + chr(0) + cls + chr(0)) + atoms.WM_CLASS, atoms.STRING, 8, + len(instance) + len(cls) + 2, + instance + chr(0) + cls + chr(0)) # WM_TRANSIENT_FOR -def get_wm_transient_for(c, window): - return util.PropertyCookie( - util.get_property(c, window, xcb.xproto.Atom.WM_TRANSIENT_FOR)) +def get_wm_transient_for(window): + return util.PropertyCookie(util.get_property(window, + atoms.WM_TRANSIENT_FOR)) -def get_wm_transient_for_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, - xcb.xproto.Atom.WM_TRANSIENT_FOR)) +def get_wm_transient_for_unchecked(window): + cook = util.get_property_unchecked(window, atoms.WM_TRANSIENT_FOR) + return util.PropertyCookie(cook) -def set_wm_transient_for(c, window, transient_window): +def set_wm_transient_for(window, transient_window): packed = struct.pack('I', transient_window) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_TRANSIENT_FOR, - xcb.xproto.Atom.WINDOW, 32, - 1, packed) + atoms.WM_TRANSIENT_FOR, atoms.WINDOW, 32, + 1, packed) -def set_wm_transient_for_checked(c, window, transient_window): +def set_wm_transient_for_checked(window, transient_window): packed = struct.pack('I', transient_window) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_TRANSIENT_FOR, - xcb.xproto.Atom.WINDOW, 32, - 1, packed) + atoms.WM_TRANSIENT_FOR, + atoms.WINDOW, 32, 1, packed) # WM_PROTOCOLS -def get_wm_protocols(c, window): - return util.PropertyCookie( - util.get_property(c, window, util.get_atom(c, 'WM_PROTOCOLS'))) +def get_wm_protocols(window): + return util.PropertyCookie(util.get_property(window, 'WM_PROTOCOLS')) -def get_wm_protocols(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, - util.get_atom(c, 'WM_PROTOCOLS'))) +def get_wm_protocols(window): + return util.PropertyCookie(util.get_property_unchecked(window, + 'WM_PROTOCOLS')) -def set_wm_protocols(c, window, protocol_atoms): +def set_wm_protocols(window, protocol_atoms): packed = struct.pack('I', transient_window) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_TRANSIENT_FOR, - xcb.xproto.Atom.WINDOW, 32, + atoms.WM_TRANSIENT_FOR, + atoms.WINDOW, 32, 1, packed) -def set_wm_protocols_checked(c, window, protocol_atoms): +def set_wm_protocols_checked(window, protocol_atoms): packed = struct.pack('I' * len(protocol_atoms), *protocol_atoms) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - util.get_atom(c, 'WM_PROTOCOLS'), - xcb.xproto.Atom.ATOM, 32, - len(protocol_atoms), packed) + atom('WM_PROTOCOLS'), atoms.ATOM, 32, + len(protocol_atoms), packed) # WM_COLORMAP_WINDOWS -def get_wm_colormap_windows(c, window): - return util.PropertyCookie( - util.get_property(c, window, util.get_atom(c, 'WM_COLORMAP_WINDOWS'))) +def get_wm_colormap_windows(window): + return util.PropertyCookie(util.get_property(window, 'WM_COLORMAP_WINDOWS')) -def get_wm_colormap_windows_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, - util.get_atom(c, 'WM_COLORMAP_WINDOWS'))) +def get_wm_colormap_windows_unchecked(window): + cook = util.get_property_unchecked(window, 'WM_COLORMAP_WINDOWS') + return util.PropertyCookie(cook) -def set_wm_colormap_windows(c, window, colormap_windows): +def set_wm_colormap_windows(window, colormap_windows): packed = struct.pack('I' * len(colormap_windows), *colormap_windows) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - util.get_atom(c, 'WM_COLORMAP_WINDOWS'), - xcb.xproto.Atom.WINDOW, 32, - len(colormap_windows), packed) + atom('WM_COLORMAP_WINDOWS'), atoms.WINDOW, 32, + len(colormap_windows), packed) -def set_wm_colormap_windows_checked(c, window, transient_window): +def set_wm_colormap_windows_checked(window, transient_window): packed = struct.pack('I' * len(colormap_windows), *colormap_windows) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - util.get_atom(c, 'WM_COLORMAP_WINDOWS'), - xcb.xproto.Atom.WINDOW, 32, - len(colormap_windows), packed) + atom('WM_COLORMAP_WINDOWS'), + atoms.WINDOW, 32, + len(colormap_windows), packed) # WM_CLIENT_MACHINE -def get_wm_client_machine(c, window): - return util.PropertyCookie( - util.get_property(c, window, xcb.xproto.Atom.WM_CLIENT_MACHINE)) +def get_wm_client_machine(window): + return util.PropertyCookie(util.get_property(window, + atoms.WM_CLIENT_MACHINE)) -def get_wm_client_machine_unchecked(c, window): - return util.PropertyCookie( - util.get_property_unchecked(c, window, - xcb.xproto.Atom.WM_CLIENT_MACHINE)) +def get_wm_client_machine_unchecked(window): + cook = util.get_property_unchecked(window, atoms.WM_CLIENT_MACHINE) + return util.PropertyCookie(cook) -def set_wm_client_machine(c, window, client_machine): +def set_wm_client_machine(window, client_machine): return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_CLIENT_MACHINE, - xcb.xproto.Atom.STRING, 8, - len(client_machine), client_machine) + atoms.WM_CLIENT_MACHINE, atoms.STRING, 8, + len(client_machine), client_machine) -def set_wm_client_machine_checked(c, window, client_machine): +def set_wm_client_machine_checked(window, client_machine): return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_CLIENT_MACHINE, - xcb.xproto.Atom.STRING, 8, - len(client_machine), client_machine) + atoms.WM_CLIENT_MACHINE, + atoms.STRING, 8, + len(client_machine), client_machine) # WM_STATE @@ -430,27 +409,23 @@ def reply(self): 'icon': v[1] } -def get_wm_state(c, window): - return StateCookie( - util.get_property(c, window, util.get_atom(c, 'WM_STATE'))) +def get_wm_state(window): + return StateCookie(util.get_property(window, 'WM_STATE')) -def get_wm_state_unchecked(c, window): - return StateCookie( - util.get_property_unchecked(c, window, util.get_atom(c, 'WM_STATE'))) +def get_wm_state_unchecked(window): + return StateCookie(util.get_property_unchecked(window, 'WM_STATE')) -def set_wm_state(c, window, state, icon): +def set_wm_state(window, state, icon): packed = struct.pack('II', state, icon) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - util.get_atom(c, 'WM_STATE'), - util.get_atom(c, 'WM_STATE'), 32, - 2, packed) + atom('WM_STATE'), atom('WM_STATE'), 32, + 2, packed) -def set_wm_state_checked(c, window, state, icon): +def set_wm_state_checked(window, state, icon): packed = struct.pack('II', state, icon) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - util.get_atom(c, 'WM_STATE'), - util.get_atom(c, 'WM_STATE'), 32, - 2, packed) + atom('WM_STATE'), atom('WM_STATE'), 32, + 2, packed) # WM_ICON_SIZE @@ -470,28 +445,26 @@ def reply(self): 'height_inc': v[5] } -def get_icon_size(c, window): - return IconSizeCookie( - util.get_property(c, window, xcb.xproto.Atom.WM_ICON_SIZE)) +def get_icon_size(window): + return IconSizeCookie(util.get_property(window, atoms.WM_ICON_SIZE)) -def get_icon_size_unchecked(c, window): - return IconSizeCookie( - util.get_property_unchecked(c, window, xcb.xproto.Atom.WM_ICON_SIZE)) +def get_icon_size_unchecked(window): + return IconSizeCookie(util.get_property_unchecked(window, + atoms.WM_ICON_SIZE)) -def set_icon_size(c, window, min_width=0, min_height=0, max_width=0, +def set_icon_size(window, min_width=0, min_height=0, max_width=0, max_height=0, width_inc=0, height_inc=0): packed = struct.pack('I' * 6, min_width, min_height, max_width, max_height, width_inc, height_inc) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_ICON_SIZE, - xcb.xproto.Atom.WM_ICON_SIZE, 32, - 6, packed) + atoms.WM_ICON_SIZE, atoms.WM_ICON_SIZE, 32, + 6, packed) -def set_icon_size_checked(c, window, min_width=0, min_height=0, max_width=0, +def set_icon_size_checked(window, min_width=0, min_height=0, max_width=0, max_height=0, width_inc=0, height_inc=0): packed = struct.pack('I' * 6, min_width, min_height, max_width, max_height, width_inc, height_inc) return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - xcb.xproto.Atom.WM_ICON_SIZE, - xcb.xproto.Atom.WM_ICON_SIZE, 32, - 6, packed) + atoms.WM_ICON_SIZE, + atoms.WM_ICON_SIZE, 32, 6, packed) + diff --git a/xpybutil/image.py b/xpybutil/image.py index 995c91b..02a2426 100644 --- a/xpybutil/image.py +++ b/xpybutil/image.py @@ -1,20 +1,24 @@ +# This module is woefully incomplete, but may be useful to anyone that wants +# to interoperate xpyb with PIL. + import xcb.xproto + +from xpybutil import conn from PIL import Image def net_wm_icon_to_bgra(data): - ret = [] + ret = [0] * (len(data) * 4) for i, d in enumerate(data): - pixel = i * 4 - alpha = d >> 24 red = ((alpha << 24) ^ d) >> 16 green = (((alpha << 24) + (red << 16)) ^ d) >> 8 blue = (((alpha << 24) + (red << 16) + (green << 8)) ^ d) >> 0 - ret.append(blue) - ret.append(green) - ret.append(red) - ret.append(alpha) + pixel = i * 4 + ret[pixel] = blue + ret[pixel + 1] = green + ret[pixel + 2] = red + ret[pixel + 3] = alpha return ret @@ -26,12 +30,12 @@ def hex_to_rgb(h): s = color_humanize(h) return (int(s[1:3], 16), int(s[3:5], 16), int(s[5:7], 16)) -def get_image_from_pixmap(c, pid): +def get_image_from_pixmap(pid): try: - geom = c.core.GetGeometry(pid).reply() - pimg = c.core.GetImage(xcb.xproto.ImageFormat.ZPixmap, pid, - 0, 0, geom.width, geom.height, - 2**32 - 1).reply().data + geom = conn.core.GetGeometry(pid).reply() + pimg = conn.core.GetImage(xcb.xproto.ImageFormat.ZPixmap, pid, + 0, 0, geom.width, geom.height, + 2**32 - 1).reply().data return geom.width, geom.height, pimg except xcb.xproto.BadDrawable: diff --git a/xpybutil/keysym.py b/xpybutil/keysym.py index b8909b8..73f989b 100644 --- a/xpybutil/keysym.py +++ b/xpybutil/keysym.py @@ -1,7 +1,10 @@ import xcb.xproto +from xpybutil import conn from keysymdef import keysyms, keycodes +EM = xcb.xproto.EventMask +GM = GM TRIVIAL_MODS = [ 0, xcb.xproto.ModMask.Lock, @@ -9,7 +12,7 @@ xcb.xproto.ModMask.Lock | xcb.xproto.ModMask._2 ] -def parse_keystring(c, key_string, kbmap): +def parse_keystring(key_string, kbmap): """ A utility function to turn strings like 'Mod1-Mod4-a' into a pair corresponding to its modifiers and keycode. @@ -23,7 +26,7 @@ def parse_keystring(c, key_string, kbmap): else: if len(part) == 1: part = part.lower() - keycode = lookup_string(c, kbmap, part) + keycode = lookup_string(kbmap, part) return modifiers, keycode @@ -37,13 +40,13 @@ def parse_buttonstring(button_string): return mods, button -def lookup_string(c, syms, kstr): +def lookup_string(syms, kstr): assert isinstance(syms, xcb.xproto.GetKeyboardMappingReply) if kstr in keysyms: - return get_keycode(c, syms, keysyms[kstr]) + return get_keycode(syms, keysyms[kstr]) elif len(kstr) > 1 and kstr.capitalize() in keysyms: - return get_keycode(c, syms, keysyms[kstr.capitalize()]) + return get_keycode(syms, keysyms[kstr.capitalize()]) return None @@ -52,55 +55,53 @@ def lookup_keysym(keysym): return keycodes[keysym][0] return None -def get_min_max_keycode(c): - return c.get_setup().min_keycode, c.get_setup().max_keycode +def get_min_max_keycode(): + return conn.get_setup().min_keycode, conn.get_setup().max_keycode -def get_keyboard_mapping(c): - mn, mx = get_min_max_keycode(c) +def get_keyboard_mapping(): + mn, mx = get_min_max_keycode() - return c.core.GetKeyboardMapping(mn, mx - mn + 1) + return conn.core.GetKeyboardMapping(mn, mx - mn + 1) def get_keyboard_mapping_unchecked(c): - mn, mx = get_min_max_keycode(c) + mn, mx = get_min_max_keycode() - return c.core.GetKeyboardMappingUnchecked(mn, mx - mn + 1) + return conn.core.GetKeyboardMappingUnchecked(mn, mx - mn + 1) -def get_keysym(c, syms, keycode, col=0): +def get_keysym(syms, keycode, col=0): assert isinstance(syms, xcb.xproto.GetKeyboardMappingReply) - mn, mx = get_min_max_keycode(c) + mn, mx = get_min_max_keycode() per = syms.keysyms_per_keycode ind = (keycode - mn) * per + col return syms.keysyms[ind] - # if ind in syms.keysyms: - # return None -def get_keysym_string(c, syms, keysym, col=0): +def get_keysym_string(syms, keysym, col=0): assert isinstance(syms, xcb.xproto.GetKeyboardMappingReply) return keycodes[keysym][col] -def get_keycode(c, syms, keysym): +def get_keycode(syms, keysym): assert isinstance(syms, xcb.xproto.GetKeyboardMappingReply) res = [] - mn, mx = get_min_max_keycode(c) + mn, mx = get_min_max_keycode() cols = syms.keysyms_per_keycode for i in xrange(mn, mx + 1): for j in xrange(0, cols): - ks = get_keysym(c, syms, i, col=j) + ks = get_keysym(syms, i, col=j) if ks == keysym: return i return None -def get_keys_to_mods(c): +def get_keys_to_mods(): mm = xcb.xproto.ModMask modmasks = [mm.Shift, mm.Lock, mm.Control, mm._1, mm._2, mm._3, mm._4, mm._5] # order matters - mods = c.core.GetModifierMapping().reply() + mods = conn.core.GetModifierMapping().reply() res = {} keyspermod = mods.keycodes_per_modifier @@ -143,68 +144,58 @@ def get_modifiers(state): return ret -def grab_pointer(c, grab_win, confine, cursor): - c.core.GrabPointer( - False, grab_win, - xcb.xproto.EventMask.PointerMotion | - xcb.xproto.EventMask.ButtonRelease | - xcb.xproto.EventMask.ButtonPress, - xcb.xproto.GrabMode.Async, xcb.xproto.GrabMode.Async, - confine, cursor, xcb.xproto.Time.CurrentTime - ) +def grab_pointer(grab_win, confine, cursor): + mask = EM.PointerMotion | EM.ButtonRelease | EM.ButtonPress + conn.core.GrabPointer(False, grab_win, mask, GM.Async, GM.Async, + confine, cursor, xcb.xproto.Time.CurrentTime) -def ungrab_pointer(c): - c.core.UngrabPointer(xcb.xproto.Time.CurrentTime) +def ungrab_pointer(): + conn.core.UngrabPointer(xcb.xproto.Time.CurrentTime) -def grab_keyboard(c, grab_win): - return c.core.GrabKeyboard(False, grab_win, xcb.xproto.Time.CurrentTime, - xcb.xproto.GrabMode.Async, - xcb.xproto.GrabMode.Async).reply() +def grab_keyboard(grab_win): + return conn.core.GrabKeyboard(False, grab_win, xcb.xproto.Time.CurrentTime, + GM.Async, GM.Async).reply() -def ungrab_keyboard(c): - c.core.UngrabKeyboardChecked(xcb.xproto.Time.CurrentTime).check() +def ungrab_keyboard(): + conn.core.UngrabKeyboardChecked(xcb.xproto.Time.CurrentTime).check() -def grab_key(c, wid, modifiers, key): +def grab_key(wid, modifiers, key): try: for mod in TRIVIAL_MODS: - c.core.GrabKeyChecked(True, wid, modifiers | mod, key, - xcb.xproto.GrabMode.Async, - xcb.xproto.GrabMode.Async).check() + conn.core.GrabKeyChecked(True, wid, modifiers | mod, key, GM.Async, + GM.Async).check() return True except xcb.xproto.BadAccess: return False -def ungrab_key(c, wid, modifiers, key): +def ungrab_key(wid, modifiers, key): try: for mod in TRIVIAL_MODS: - c.core.UngrabKeyChecked(key, wid, modifiers | mod).check() + conn.core.UngrabKeyChecked(key, wid, modifiers | mod).check() return True except xcb.xproto.BadAccess: return False -def grab_button(c, wid, modifiers, button, propagate=False): - emask = (xcb.xproto.EventMask.ButtonPress | - xcb.xproto.EventMask.ButtonRelease | - xcb.xproto.EventMask.ButtonMotion) - mode = xcb.xproto.GrabMode.Sync if propagate else xcb.xproto.GrabMode.Async +def grab_button(wid, modifiers, button, propagate=False): + mask = EM.ButtonPress | EM.ButtonRelease | EM.ButtonMotion try: for mod in TRIVIAL_MODS: - c.core.GrabButtonChecked(True, wid, emask, - mode, - xcb.xproto.GrabMode.Async, 0, 0, + c.core.GrabButtonChecked(True, wid, mask, + GM.Sync if propagate else GM.Async, + GM.Async, 0, 0, button, modifiers | mod).check() return True except xcb.xproto.BadAccess: return False -def ungrab_button(c, wid, modifiers, button): +def ungrab_button(wid, modifiers, button): try: for mod in TRIVIAL_MODS: - c.core.UngrabButtonChecked(button, wid, modifiers | mod).check() + conn.core.UngrabButtonChecked(button, wid, modifiers | mod).check() return True except xcb.xproto.BadAccess: diff --git a/xpybutil/motif.py b/xpybutil/motif.py index 3bcd047..d3edcac 100644 --- a/xpybutil/motif.py +++ b/xpybutil/motif.py @@ -2,6 +2,7 @@ import xcb.xproto +from xpybutil import root import util __atoms = ['_MOTIF_WM_HINTS'] @@ -40,14 +41,12 @@ class Input: class Status: TearoffWindow = 1 << 0 -# Handle atom caching -def build_atom_cache(c): - for atom in __atoms: - util.__atom_cache[atom] = util.get_atom_cookie(c, atom, - only_if_exists=False) - # Some aliases atom = util.get_atom +preplace = xcb.xproto.PropMode.Replace + +# Build the atom cache for quicker access +util.build_atom_cache(__atoms) # _MOTIF_WM_HINTS @@ -71,13 +70,12 @@ def reply(self): 'status': v[4] } -def get_hints(c, window): - return MotifHintsCookie( - util.get_property(c, window, atom(c, '_MOTIF_WM_HINTS'))) +def get_hints(window): + return MotifHintsCookie(util.get_property(window, '_MOTIF_WM_HINTS')) -def get_hints_unchecked(c, window): - return MotifHintsCookie( - util.get_property_unchecked(c, window, atom(c, '_MOTIF_WM_HINTS'))) +def get_hints_unchecked(window): + cook = util.get_property_unchecked(window, '_MOTIF_WM_HINTS') + return MotifHintsCookie(cook) def _pack_hints(flags, function, decoration, input, status): hints = [0] * 5 @@ -98,20 +96,18 @@ def _pack_hints(flags, function, decoration, input, status): return struct.pack('I' * 5, *hints) -def set_hints(c, window, flags, function=Function._None, +def set_hints(window, flags, function=Function._None, decoration=Decoration._None, input=Input.Modeless, status=Status.TearoffWindow): packed = _pack_hints(flags, function, decoration, input, status) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, - atom(c, '_MOTIF_WM_HINTS'), - atom(c, '_MOTIF_WM_HINTS'), 32, - 5, packed) + return c.core.ChangeProperty(preplace, window, atom('_MOTIF_WM_HINTS'), + atom('_MOTIF_WM_HINTS'), 32, 5, packed) -def set_hints_checked(c, window, flags, function=Function._None, +def set_hints_checked(window, flags, function=Function._None, decoration=Decoration._None, input=Input.Modeless, status=Status.TearoffWindow): packed = _pack_hints(flags, function, decoration, input, status) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, window, - atom(c, '_MOTIF_WM_HINTS'), - atom(c, '_MOTIF_WM_HINTS'), 32, - 5, packed) \ No newline at end of file + return c.core.ChangePropertyChecked(preplace, window, + atom('_MOTIF_WM_HINTS'), + atom('_MOTIF_WM_HINTS'), 32, 5, packed) + diff --git a/xpybutil/render.py b/xpybutil/render.py index e9cf42a..9acd5f7 100644 --- a/xpybutil/render.py +++ b/xpybutil/render.py @@ -1,3 +1,10 @@ +# I once used the help of this module to implement a basic compositing manager +# using xpyb. It only did transparency, and not well. (Performance was actually +# quite nice.) It's called pycompmgr. +# +# This is meant to be a very close translation to the corresponding xcb-util +# module. Mostly because I lack a depp understanding of everything here. + import xcb, xcb.xproto, xcb.render class PictFormat: @@ -209,3 +216,4 @@ def find_standard_format(formats, format): standardFormats[format]['template'], 0 ) + diff --git a/xpybutil/util.py b/xpybutil/util.py index a301ddd..74ef380 100644 --- a/xpybutil/util.py +++ b/xpybutil/util.py @@ -2,7 +2,7 @@ import xcb.xproto -import event +from xpybutil import conn, root __atom_cache = {} __atom_nm_cache = {} @@ -35,68 +35,58 @@ def reply(self): return str(self.cookie.reply().name.buf()) # Handle atom caching -def build_atom_cache(c, module): +def build_atom_cache(atoms): global __atom_cache, __atom_nm_cache - for atom in module.__atoms: - __atom_cache[atom] = get_atom_cookie(c, atom, only_if_exists=False) + for atom in atoms: + __atom_cache[atom] = get_atom_cookie(atom, only_if_exists=False) for atom in __atom_cache: if isinstance(__atom_cache[atom], AtomCookie): __atom_cache[atom] = __atom_cache[atom].reply() __atom_nm_cache = dict((v, k) for k, v in __atom_cache.iteritems()) -def atom(atom_name): +def get_atom(atom_name, only_if_exists=False): global __atom_cache - if atom_name in __atom_cache: - if isinstance(__atom_cache[atom_name], AtomCookie): - __atom_cache[atom_name] = __atom_cache[atom_name].reply() - return __atom_cache[atom_name] - - return None - -def get_atom(c, atom_name, only_if_exists=False): - global __atom_cache - - if atom_name in __atom_cache: - if isinstance(__atom_cache[atom_name], AtomCookie): - __atom_cache[atom_name] = __atom_cache[atom_name].reply() - else: - __atom_cache[atom_name] = get_atom_cookie(c, atom_name, - only_if_exists).reply() + a = __atom_cache.setdefault(atom_name, + get_atom_cookie(atom_name, only_if_exists)) + if isinstance(a, AtomCookie): + a = a.reply() + return a - return __atom_cache[atom_name] - -def get_parent_window(c, window): - return c.core.QueryTree(window).reply().parent - -def get_atom_name(c, atom): +def get_atom_name(atom): global __atom_nm_cache - if atom not in __atom_nm_cache: - __atom_nm_cache[atom] = get_atom_name_cookie(c, atom).reply() + a = __atom_nm_cache.setdefault(atom, get_atom_name_cookie(atom)) - return __atom_nm_cache[atom] + if isinstance(a, AtomNameCookie): + a = a.reply() + + return a -def get_atom_cookie(c, atom_name, only_if_exists=False): - return AtomCookie( - c.core.InternAtomUnchecked(only_if_exists, len(atom_name), - atom_name)) +def get_atom_cookie(atom_name, only_if_exists=False): + atom = conn.core.InternAtomUnchecked(only_if_exists, len(atom_name), + atom_name) + return AtomCookie(atom) -def get_atom_name_cookie(c, atom): - return AtomNameCookie(c.core.GetAtomNameUnchecked(atom)) +def get_atom_name_cookie(atom): + return AtomNameCookie(conn.core.GetAtomNameUnchecked(atom)) -def get_property(conn, window, atom): +def get_property(window, atom): + if isinstance(atom, basestring): + atom = get_atom(atom) return conn.core.GetProperty(False, window, atom, xcb.xproto.GetPropertyType.Any, 0, 2 ** 32 - 1) -def get_property_unchecked(conn, window, atom): +def get_property_unchecked(window, atom): + if isinstance(atom, basestring): + atom = get_atom(atom) return conn.core.GetPropertyUnchecked(False, window, atom, - xcb.xproto.GetPropertyType.Any, 0, - 2 ** 32 - 1) + xcb.xproto.GetPropertyType.Any, 0, + 2 ** 32 - 1) def get_property_value(property_reply): assert isinstance(property_reply, xcb.xproto.GetPropertyReply) @@ -121,49 +111,6 @@ def get_property_value(property_reply): return None -# I know this is bad... But i'm really not interested in -# developing for multiple screens... -def get_root(c): - return c.get_setup().roots[0].root - -def send_event(c, destination, event_mask, event, propagate=False): - return c.core.SendEvent(propagate, destination, event_mask, event) - -def replay_pointer(c): - c.core.AllowEventsChecked(xcb.xproto.Allow.ReplayPointer, - xcb.xproto.Time.CurrentTime).check() - -# Sends a client event to the root window -def _root_send_client_event_pack(window, message_type, data): - # Pad the data - data = data + ([0] * (5 - len(data))) - - # Taken from - # http://xcb.freedesktop.org/manual/structxcb__client__message__event__t.html - return struct.pack( - 'BBH7I', - event.Event.ClientMessageEvent, # Event type - 32, # Format - 0, # Sequence - window, # Window - message_type, # Message type - *data # Data - ) - -def root_send_client_event(c, window, message_type, data): - return c.core.SendEvent(False, get_root(c), - (xcb.xproto.EventMask.SubstructureNotify | - xcb.xproto.EventMask.SubstructureRedirect), - _root_send_client_event_pack(window, message_type, - data)) - -def root_send_client_event_checked(c, window, message_type, data): - # I know this is bad... But i'm really not interested in - # developing for multiple screens... - root = c.get_setup().roots[0].root - return c.core.SendEventChecked( - False, root, - (xcb.xproto.EventMask.SubstructureNotify | - xcb.xproto.EventMask.SubstructureRedirect), - _root_send_client_event_pack(window, message_type, - data)) +def get_parent_window(window): + return conn.core.QueryTree(window).reply().parent + diff --git a/xpybutil/xinerama.py b/xpybutil/xinerama.py index 4091643..d0f0aed 100644 --- a/xpybutil/xinerama.py +++ b/xpybutil/xinerama.py @@ -1,12 +1,9 @@ import xcb.xinerama +from xpybutil import conn import util -ext = None - -def init(conn): - global ext - ext = conn(xcb.xinerama.key) +ext = conn(xcb.xinerama.key) def get_monitors(): ''' @@ -15,9 +12,6 @@ def get_monitors(): @rtype: List of (x, y, w, h) rectangles ''' - assert ext is not None, \ - 'call xinerama.init(conn) before using the xinerama module' - retval = [] ms = ext.QueryScreens().reply() if ms: From 0935ffe3ad577bf2ef6ddd85105ed7e57ffa799e Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sun, 21 Aug 2011 16:44:09 -0400 Subject: [PATCH 05/12] don't track my testing file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2c1998e..bace5f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ tests *.pyc .*swp +testing.py From 75c7feefd5b6c11792d135e5f22b276b474b1f3d Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Tue, 23 Aug 2011 21:47:53 -0400 Subject: [PATCH 06/12] rounding out v2 changes --- .gitignore | 1 + xpybutil/event.py | 47 ++++++----- xpybutil/keysym.py | 192 ++++++++++++++++++++++++++++++++------------- xpybutil/util.py | 5 +- xpybutil/window.py | 25 +++--- 5 files changed, 183 insertions(+), 87 deletions(-) diff --git a/.gitignore b/.gitignore index bace5f4..f3b1b1b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ tests *.pyc .*swp testing.py +tags diff --git a/xpybutil/event.py b/xpybutil/event.py index a9feec0..557d25c 100644 --- a/xpybutil/event.py +++ b/xpybutil/event.py @@ -1,16 +1,17 @@ -from collections import deque +from collections import defaultdict, deque import struct import sys import traceback -import xcb.xproto +import xcb +import xcb.xproto as xproto from xpybutil import conn, root import util __queue = deque() -__callbacks = [] -EM = xcb.xproto.EventMask +__callbacks = defaultdict(list) +EM = xproto.EventMask class Event(object): KeyPressEvent = 2 @@ -48,8 +49,8 @@ class Event(object): MappingNotifyEvent = 34 def replay_pointer(): - conn.core.AllowEventsChecked(xcb.xproto.Allow.ReplayPointer, - xcb.xproto.Time.CurrentTime).check() + conn.core.AllowEventsChecked(xproto.Allow.ReplayPointer, + xproto.Time.CurrentTime).check() def send_event(destination, event_mask, event, propagate=False): return conn.core.SendEvent(propagate, destination, event_mask, event) @@ -81,21 +82,27 @@ def root_send_client_event_checked(window, message_type, *data): packed = pack_client_message(window, message_type, *data) return send_event_checked(root, mask, packed) +def is_connected(event_name, window, callback): + member = '%sEvent' % event_name + assert hasattr(xproto, member) + + key = (getattr(xproto, member), window) + return key in __callbacks and callback in __callbacks[key] + def connect(event_name, window, callback): member = '%sEvent' % event_name - assert hasattr(xcb.xproto, member) + assert hasattr(xproto, member) - __callbacks.append((getattr(xcb.xproto, member), window, callback)) + key = (getattr(xproto, member), window) + __callbacks[key].append(callback) def disconnect(event_name, window): member = '%sEvent' % event_name - assert hasattr(xcb.xproto, member) + assert hasattr(xproto, member) - member = getattr(xcb.xproto, member) - cbs = filter(lambda (et, win, cb): et == member and win == window, - __callbacks) - for item in cbs: - __callbacks.remove(item) + key = (getattr(xproto, member), window) + if key in __callbacks: + del __callbacks[key] def read(block=False): if block: @@ -110,22 +117,24 @@ def read(block=False): __queue.appendleft(e) -def event_loop(): +def main(): try: while True: read(block=True) for e in queue(): w = None - if hasattr(e, 'window'): + if isinstance(e, xproto.MappingNotifyEvent): + w = None + elif hasattr(e, 'window'): w = e.window elif hasattr(e, 'event'): w = e.event elif hasattr(e, 'requestor'): w = e.requestor - for event_type, win, cb in __callbacks: - if win == w and isinstance(e, event_type): - cb(e) + key = (e.__class__, w) + for cb in __callbacks.get(key, []): + cb(e) except xcb.Exception: traceback.print_exc() sys.exit(1) diff --git a/xpybutil/keysym.py b/xpybutil/keysym.py index 73f989b..3673faf 100644 --- a/xpybutil/keysym.py +++ b/xpybutil/keysym.py @@ -1,18 +1,30 @@ -import xcb.xproto +from collections import defaultdict -from xpybutil import conn +import xcb.xproto as xproto + +from xpybutil import conn, root +import event from keysymdef import keysyms, keycodes -EM = xcb.xproto.EventMask -GM = GM +__kbmap = None +__keysmods = None + +__keybinds = defaultdict(list) +__mousebinds = defaultdict(list) + +__keygrabs = defaultdict(int) # Key grab key -> number of grabs +__mousegrabs = defaultdict(int) + +EM = xproto.EventMask +GM = xproto.GrabMode TRIVIAL_MODS = [ 0, - xcb.xproto.ModMask.Lock, - xcb.xproto.ModMask._2, - xcb.xproto.ModMask.Lock | xcb.xproto.ModMask._2 + xproto.ModMask.Lock, + xproto.ModMask._2, + xproto.ModMask.Lock | xproto.ModMask._2 ] -def parse_keystring(key_string, kbmap): +def parse_keystring(key_string): """ A utility function to turn strings like 'Mod1-Mod4-a' into a pair corresponding to its modifiers and keycode. @@ -21,32 +33,30 @@ def parse_keystring(key_string, kbmap): keycode = None for part in key_string.split('-'): - if hasattr(xcb.xproto.KeyButMask, part): - modifiers |= getattr(xcb.xproto.KeyButMask, part) + if hasattr(xproto.KeyButMask, part): + modifiers |= getattr(xproto.KeyButMask, part) else: if len(part) == 1: part = part.lower() - keycode = lookup_string(kbmap, part) + keycode = lookup_string(part) return modifiers, keycode def parse_buttonstring(button_string): mods, button = 0, None for part in button_string.split('-'): - if hasattr(xcb.xproto.KeyButMask, part): - mods |= getattr(xcb.xproto.KeyButMask, part) + if hasattr(xproto.KeyButMask, part): + mods |= getattr(xproto.KeyButMask, part) else: button = int(part) return mods, button -def lookup_string(syms, kstr): - assert isinstance(syms, xcb.xproto.GetKeyboardMappingReply) - +def lookup_string(kstr): if kstr in keysyms: - return get_keycode(syms, keysyms[kstr]) + return get_keycode(keysyms[kstr]) elif len(kstr) > 1 and kstr.capitalize() in keysyms: - return get_keycode(syms, keysyms[kstr.capitalize()]) + return get_keycode(keysyms[kstr.capitalize()]) return None @@ -63,41 +73,41 @@ def get_keyboard_mapping(): return conn.core.GetKeyboardMapping(mn, mx - mn + 1) -def get_keyboard_mapping_unchecked(c): +def get_keyboard_mapping_unchecked(): mn, mx = get_min_max_keycode() return conn.core.GetKeyboardMappingUnchecked(mn, mx - mn + 1) -def get_keysym(syms, keycode, col=0): - assert isinstance(syms, xcb.xproto.GetKeyboardMappingReply) +def get_keysym(keycode, col=0, kbmap=None): + if kbmap is None: + kbmap = __kbmap mn, mx = get_min_max_keycode() - per = syms.keysyms_per_keycode + per = kbmap.keysyms_per_keycode ind = (keycode - mn) * per + col - return syms.keysyms[ind] - -def get_keysym_string(syms, keysym, col=0): - assert isinstance(syms, xcb.xproto.GetKeyboardMappingReply) + return __kbmap.keysyms[ind] +def get_keysym_string(keysym, col=0): return keycodes[keysym][col] -def get_keycode(syms, keysym): - assert isinstance(syms, xcb.xproto.GetKeyboardMappingReply) - +def get_keycode(keysym): res = [] mn, mx = get_min_max_keycode() - cols = syms.keysyms_per_keycode + cols = __kbmap.keysyms_per_keycode for i in xrange(mn, mx + 1): for j in xrange(0, cols): - ks = get_keysym(syms, i, col=j) + ks = get_keysym(i, col=j) if ks == keysym: return i return None +def get_mod_for_key(keycode): + return __keysmods.get(keycode, 0) + def get_keys_to_mods(): - mm = xcb.xproto.ModMask + mm = xproto.ModMask modmasks = [mm.Shift, mm.Lock, mm.Control, mm._1, mm._2, mm._3, mm._4, mm._5] # order matters @@ -107,7 +117,7 @@ def get_keys_to_mods(): keyspermod = mods.keycodes_per_modifier for mmi in xrange(0, len(modmasks)): row = mmi * keyspermod - for kc in mods.keycodes[row:row + 4]: + for kc in mods.keycodes[row:row + keyspermod]: res[kc] = modmasks[mmi] return res @@ -115,31 +125,31 @@ def get_keys_to_mods(): def get_modifiers(state): ret = [] - if state & xcb.xproto.ModMask.Shift: + if state & xproto.ModMask.Shift: ret.append('Shift') - if state & xcb.xproto.ModMask.Lock: + if state & xproto.ModMask.Lock: ret.append('Lock') - if state & xcb.xproto.ModMask.Control: + if state & xproto.ModMask.Control: ret.append('Control') - if state & xcb.xproto.ModMask._1: + if state & xproto.ModMask._1: ret.append('Mod1') - if state & xcb.xproto.ModMask._2: + if state & xproto.ModMask._2: ret.append('Mod2') - if state & xcb.xproto.ModMask._3: + if state & xproto.ModMask._3: ret.append('Mod3') - if state & xcb.xproto.ModMask._4: + if state & xproto.ModMask._4: ret.append('Mod4') - if state & xcb.xproto.ModMask._5: + if state & xproto.ModMask._5: ret.append('Mod5') - if state & xcb.xproto.KeyButMask.Button1: + if state & xproto.KeyButMask.Button1: ret.append('Button1') - if state & xcb.xproto.KeyButMask.Button2: + if state & xproto.KeyButMask.Button2: ret.append('Button2') - if state & xcb.xproto.KeyButMask.Button3: + if state & xproto.KeyButMask.Button3: ret.append('Button3') - if state & xcb.xproto.KeyButMask.Button4: + if state & xproto.KeyButMask.Button4: ret.append('Button4') - if state & xcb.xproto.KeyButMask.Button5: + if state & xproto.KeyButMask.Button5: ret.append('Button5') return ret @@ -147,17 +157,17 @@ def get_modifiers(state): def grab_pointer(grab_win, confine, cursor): mask = EM.PointerMotion | EM.ButtonRelease | EM.ButtonPress conn.core.GrabPointer(False, grab_win, mask, GM.Async, GM.Async, - confine, cursor, xcb.xproto.Time.CurrentTime) + confine, cursor, xproto.Time.CurrentTime) def ungrab_pointer(): - conn.core.UngrabPointer(xcb.xproto.Time.CurrentTime) + conn.core.UngrabPointer(xproto.Time.CurrentTime) def grab_keyboard(grab_win): - return conn.core.GrabKeyboard(False, grab_win, xcb.xproto.Time.CurrentTime, + return conn.core.GrabKeyboard(False, grab_win, xproto.Time.CurrentTime, GM.Async, GM.Async).reply() def ungrab_keyboard(): - conn.core.UngrabKeyboardChecked(xcb.xproto.Time.CurrentTime).check() + conn.core.UngrabKeyboardChecked(xproto.Time.CurrentTime).check() def grab_key(wid, modifiers, key): try: @@ -166,7 +176,7 @@ def grab_key(wid, modifiers, key): GM.Async).check() return True - except xcb.xproto.BadAccess: + except xproto.BadAccess: return False def ungrab_key(wid, modifiers, key): @@ -175,7 +185,7 @@ def ungrab_key(wid, modifiers, key): conn.core.UngrabKeyChecked(key, wid, modifiers | mod).check() return True - except xcb.xproto.BadAccess: + except xproto.BadAccess: return False def grab_button(wid, modifiers, button, propagate=False): @@ -189,7 +199,7 @@ def grab_button(wid, modifiers, button, propagate=False): button, modifiers | mod).check() return True - except xcb.xproto.BadAccess: + except xproto.BadAccess: return False def ungrab_button(wid, modifiers, button): @@ -198,6 +208,80 @@ def ungrab_button(wid, modifiers, button): conn.core.UngrabButtonChecked(button, wid, modifiers | mod).check() return True - except xcb.xproto.BadAccess: + except xproto.BadAccess: return False +def update_keyboard_mapping(e): + global __kbmap, __keysmods + + newmap = get_keyboard_mapping().reply() + print 'updating keyboard mapping' + + if e is None: + __kbmap = newmap + __keysmods = get_keys_to_mods() + return + + if e.request == xproto.Mapping.Keyboard: + changes = {} + for kc in xrange(*get_min_max_keycode()): + knew = get_keysym(kc, kbmap=newmap) + oldkc = get_keycode(knew) + if oldkc != kc: + changes[oldkc] = kc + + __kbmap = newmap + __regrab(changes) + elif e.request == xproto.Mapping.Modifier: + __keysmods = get_keys_to_mods() + +def __run_keybind_callbacks(e): + kc, mods = e.detail, e.state + for mod in TRIVIAL_MODS: + mods &= ~mod + + key = (e.event, mods, kc) + for cb in __keybinds.get(key, []): + cb() + +def __regrab(changes): + print 'regrabbing!' + for wid, mods, kc in __keybinds: + if kc in changes: + ungrab_key(wid, mods, kc) + grab_key(wid, mods, changes[kc]) + + old = (wid, mods, kc) + new = (wid, mods, changes[kc]) + __keybinds[new] = __keybinds[old] + del __keybinds[old] + + # XXX: todo mouse regrabbing + +def bind_key(event_type, wid, key_string, cb): + assert event_type in ('KeyPress', 'KeyRelease') + + mods, kc = parse_keystring(key_string) + key = (wid, mods, kc) + + if not kc: + print >> sys.stderr, 'Could not find a keycode for %s' % key_string + return False + + if not __keygrabs[key] and not grab_key(wid, mods, kc): + return False + + __keybinds[key].append(cb) + __keygrabs[key] += 1 + + if not event.is_connected(event_type, wid, __run_keybind_callbacks): + event.connect(event_type, wid, __run_keybind_callbacks) + + return True + +def bind_mouse(event_type, wid, button_string, cb): + raise NotImplemented + +update_keyboard_mapping(None) +event.connect('MappingNotify', None, update_keyboard_mapping) + diff --git a/xpybutil/util.py b/xpybutil/util.py index 74ef380..690ea59 100644 --- a/xpybutil/util.py +++ b/xpybutil/util.py @@ -50,7 +50,8 @@ def get_atom(atom_name, only_if_exists=False): global __atom_cache a = __atom_cache.setdefault(atom_name, - get_atom_cookie(atom_name, only_if_exists)) + get_atom_cookie(atom_name, + only_if_exists).reply()) if isinstance(a, AtomCookie): a = a.reply() @@ -59,7 +60,7 @@ def get_atom(atom_name, only_if_exists=False): def get_atom_name(atom): global __atom_nm_cache - a = __atom_nm_cache.setdefault(atom, get_atom_name_cookie(atom)) + a = __atom_nm_cache.setdefault(atom, get_atom_name_cookie(atom).reply()) if isinstance(a, AtomNameCookie): a = a.reply() diff --git a/xpybutil/window.py b/xpybutil/window.py index 94e8ec5..b9a93b9 100644 --- a/xpybutil/window.py +++ b/xpybutil/window.py @@ -1,5 +1,6 @@ import xcb.xproto +from xpybutil import conn import util class WindowManagers(object): @@ -7,7 +8,7 @@ class WindowManagers(object): Openbox = 1 KWin = 2 -def listen(conn, window, event_mask_names): +def listen(window, *event_mask_names): masks = 0 for mask_name in event_mask_names: assert hasattr(xcb.xproto.EventMask, mask_name) @@ -16,11 +17,11 @@ def listen(conn, window, event_mask_names): conn.core.ChangeWindowAttributesChecked(window, xcb.xproto.CW.EventMask, [masks]).check() -def _get_geometry(conn, win): +def _get_geometry(win): raw = conn.core.GetGeometry(win).reply() return raw.x, raw.y, raw.width, raw.height -def get_geometry(conn, window, window_manager=None): +def get_geometry(window, window_manager=None): ''' Returns the geometry of a window. This function will do its best to get the real geometry of a window; typically by inspecting the window's @@ -31,12 +32,12 @@ def get_geometry(conn, window, window_manager=None): ''' if window_manager is WindowManagers.KWin: - p = util.get_parent_window(conn, window) - return _get_geometry(conn, util.get_parent_window(conn, p)) + p = util.get_parent_window(window) + return _get_geometry(conn, util.get_parent_window(p)) else: - return _get_geometry(conn, util.get_parent_window(conn, window)) + return _get_geometry(conn, util.get_parent_window(window)) -def moveresize(conn, win, x=None, y=None, w=None, h=None, window_manager=None): +def moveresize(win, x=None, y=None, w=None, h=None, window_manager=None): ''' This function attempts to properly move/resize a window, accounting for its decorations. @@ -47,17 +48,17 @@ def moveresize(conn, win, x=None, y=None, w=None, h=None, window_manager=None): import ewmh if window_manager is WindowManagers.KWin: - tomove = util.get_parent_window(conn, util.get_parent_window(conn, win)) + tomove = util.get_parent_window(util.get_parent_window(win)) else: - tomove = util.get_parent_window(conn, win) + tomove = util.get_parent_window(win) if tomove: - cx, cy, cw, ch = _get_geometry(conn, win) - px, py, pw, ph = _get_geometry(conn, tomove) + cx, cy, cw, ch = _get_geometry(win) + px, py, pw, ph = _get_geometry(tomove) w -= pw - cw h -= ph - ch - ewmh.request_moveresize_window(conn, win, x=x, y=y, width=max(1, w), + ewmh.request_moveresize_window(win, x=x, y=y, width=max(1, w), height=max(1, h), source=2) From dbd7fd32826d46b779ab9343975f9a8f3dc984a8 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Thu, 25 Aug 2011 09:47:29 -0400 Subject: [PATCH 07/12] mostly fixes --- xpybutil/ewmh.py | 20 ++++++++++++-------- xpybutil/keysym.py | 3 +++ xpybutil/window.py | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/xpybutil/ewmh.py b/xpybutil/ewmh.py index 0ee459b..a8dd663 100644 --- a/xpybutil/ewmh.py +++ b/xpybutil/ewmh.py @@ -681,36 +681,40 @@ def set_workarea_checked(workareas): # _NET_SUPPORTING_WM_CHECK -def get_supporting_wm_check(): +def get_supporting_wm_check(wid): """ Returns the identifier of the child window created by the window manager. + @param wid: The identifier of the window with the property. + @type wid: WINDOW/32 @return: The window ID of the child window. @rtype: util.PropertyCookieSingle (WINDOW/32) """ - cook = util.get_property(root, '_NET_SUPPORTING_WM_CHECK') + cook = util.get_property(wid, '_NET_SUPPORTING_WM_CHECK') return util.PropertyCookieSingle(cook) -def get_supporting_wm_check_unchecked(): - cook = util.get_property_unchecked(root, '_NET_SUPPORTING_WM_CHECK') +def get_supporting_wm_check_unchecked(wid): + cook = util.get_property_unchecked(wid, '_NET_SUPPORTING_WM_CHECK') return util.PropertyCookieSingle(cook) -def set_supporting_wm_check(child): +def set_supporting_wm_check(wid, child): """ Sets the identifier of the child window created by the window manager. + @param wid: The identifier of the window with the property. + @type wid: WINDOW/32 @param child: The identifier of the child window. @type child: WINDOW/32 @rtype: xcb.VoidCookie """ packed = struct.pack('I', child) - return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, + return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, wid, atom('_NET_SUPPORTING_WM_CHECK'), WINDOW, 32, 1, packed) -def set_supporting_wm_check_checked(child): +def set_supporting_wm_check_checked(wid, child): packed = struct.pack('I', child) - return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, root, + return c.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, wid, atom('_NET_SUPPORTING_WM_CHECK'), WINDOW, 32, 1, packed) diff --git a/xpybutil/keysym.py b/xpybutil/keysym.py index 3673faf..0c76c19 100644 --- a/xpybutil/keysym.py +++ b/xpybutil/keysym.py @@ -258,6 +258,9 @@ def __regrab(changes): # XXX: todo mouse regrabbing +def bind_global_key(event_type, key_string, cb): + return bind_key(event_type, root, key_string, cb) + def bind_key(event_type, wid, key_string, cb): assert event_type in ('KeyPress', 'KeyRelease') diff --git a/xpybutil/window.py b/xpybutil/window.py index b9a93b9..9af94e7 100644 --- a/xpybutil/window.py +++ b/xpybutil/window.py @@ -33,9 +33,9 @@ def get_geometry(window, window_manager=None): if window_manager is WindowManagers.KWin: p = util.get_parent_window(window) - return _get_geometry(conn, util.get_parent_window(p)) + return _get_geometry(util.get_parent_window(p)) else: - return _get_geometry(conn, util.get_parent_window(window)) + return _get_geometry(util.get_parent_window(window)) def moveresize(win, x=None, y=None, w=None, h=None, window_manager=None): ''' From e148bbe8e543c1c89ccadf4be0b89897e7653ae3 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sat, 27 Aug 2011 15:18:45 -0400 Subject: [PATCH 08/12] make strings a list if there is a null terminator anywhere but the end --- xpybutil/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xpybutil/util.py b/xpybutil/util.py index 690ea59..4ed9aa6 100644 --- a/xpybutil/util.py +++ b/xpybutil/util.py @@ -93,7 +93,7 @@ def get_property_value(property_reply): assert isinstance(property_reply, xcb.xproto.GetPropertyReply) if property_reply.format == 8: - if 0 in property_reply.value: + if 0 in property_reply.value[:-1]: ret = [] s = '' for o in property_reply.value: From 2647ce71bdb390749224489dfb91bd1b1535d472 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Thu, 12 Jan 2012 01:00:23 -0500 Subject: [PATCH 09/12] some bug fixes --- examples/get-current-desktop.py | 4 ++-- xpybutil/ewmh.py | 2 +- xpybutil/icccm.py | 2 +- xpybutil/keysym.py | 10 +++++----- xpybutil/motif.py | 2 +- xpybutil/xinerama.py | 1 - 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/get-current-desktop.py b/examples/get-current-desktop.py index 4923cde..7e6de49 100644 --- a/examples/get-current-desktop.py +++ b/examples/get-current-desktop.py @@ -1,8 +1,8 @@ from xpybutil import conn, root import xpybutil.ewmh as ewmh -names = ewmh.get_desktop_names(conn, root).reply() -desk = ewmh.get_current_desktop(conn, root).reply() +names = ewmh.get_desktop_names().reply() +desk = ewmh.get_current_desktop().reply() print names[desk] if desk < len(names) else desk diff --git a/xpybutil/ewmh.py b/xpybutil/ewmh.py index a8dd663..de0d40b 100644 --- a/xpybutil/ewmh.py +++ b/xpybutil/ewmh.py @@ -2,7 +2,7 @@ import xcb.xproto -from xpybutil import root +from xpybutil import conn as c, root import event import util diff --git a/xpybutil/icccm.py b/xpybutil/icccm.py index d4851a0..740421f 100644 --- a/xpybutil/icccm.py +++ b/xpybutil/icccm.py @@ -3,7 +3,7 @@ import xcb.xproto -from xpybutil import root +from xpybutil import conn as c import util __atoms = ['WM_PROTOCOLS', 'WM_TAKE_FOCUS', 'WM_SAVE_YOURSELF', diff --git a/xpybutil/keysym.py b/xpybutil/keysym.py index 0c76c19..027105b 100644 --- a/xpybutil/keysym.py +++ b/xpybutil/keysym.py @@ -1,4 +1,5 @@ from collections import defaultdict +import sys import xcb.xproto as xproto @@ -92,7 +93,6 @@ def get_keysym_string(keysym, col=0): return keycodes[keysym][col] def get_keycode(keysym): - res = [] mn, mx = get_min_max_keycode() cols = __kbmap.keysyms_per_keycode for i in xrange(mn, mx + 1): @@ -193,10 +193,10 @@ def grab_button(wid, modifiers, button, propagate=False): try: for mod in TRIVIAL_MODS: - c.core.GrabButtonChecked(True, wid, mask, - GM.Sync if propagate else GM.Async, - GM.Async, 0, 0, - button, modifiers | mod).check() + conn.core.GrabButtonChecked(True, wid, mask, + GM.Sync if propagate else GM.Async, + GM.Async, 0, 0, + button, modifiers | mod).check() return True except xproto.BadAccess: diff --git a/xpybutil/motif.py b/xpybutil/motif.py index d3edcac..091160a 100644 --- a/xpybutil/motif.py +++ b/xpybutil/motif.py @@ -2,7 +2,7 @@ import xcb.xproto -from xpybutil import root +from xpybutil import conn as c import util __atoms = ['_MOTIF_WM_HINTS'] diff --git a/xpybutil/xinerama.py b/xpybutil/xinerama.py index d0f0aed..cb69f8d 100644 --- a/xpybutil/xinerama.py +++ b/xpybutil/xinerama.py @@ -1,7 +1,6 @@ import xcb.xinerama from xpybutil import conn -import util ext = conn(xcb.xinerama.key) From f3e1efdd5e8625e36c7438dd885c3ab51758f5d1 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sun, 19 Feb 2012 22:08:25 -0500 Subject: [PATCH 10/12] some rectangle/strut math functions --- xpybutil/rect.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 xpybutil/rect.py diff --git a/xpybutil/rect.py b/xpybutil/rect.py new file mode 100644 index 0000000..7759e65 --- /dev/null +++ b/xpybutil/rect.py @@ -0,0 +1,26 @@ +import xcb.xproto + +import xpybutil.ewmh as ewmh +import xpybutil.window as window + +def rect_intersect_area(r1, r2): + ''' + Returns the area of the intersection of two rectangles. If the rectangles + do not intersect, the area returned is 0. + + @param r1: A 4-tuple representing a rectangle: + (top_left_x, top_left_y, width, height) + @param r2: A 4-tuple representing a rectangle: + (top_left_x, top_left_y, width, height) + @return: Area of intersection of r1 and r2. + @rtype: Integer + ''' + x1, y1, w1, h1 = r1 + x2, y2, w2, h2 = r2 + if x2 < x1 + w1 and x2 + w2 > x1 and y2 < y1 + h1 and y2 + h2 > y1: + iw = min(x1 + w1 - 1, x2 + w2 - 1) - max(x1, x2) + 1 + ih = min(y1 + h1 - 1, y2 + h2 - 1) - max(y1, y2) + 1 + return iw * ih + + return 0 + From c9cafbd6a94f35b2135f57cad296d002353e5cef Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sun, 19 Feb 2012 22:08:39 -0500 Subject: [PATCH 11/12] remove some debugging output --- xpybutil/keysym.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xpybutil/keysym.py b/xpybutil/keysym.py index 027105b..350e867 100644 --- a/xpybutil/keysym.py +++ b/xpybutil/keysym.py @@ -245,7 +245,6 @@ def __run_keybind_callbacks(e): cb() def __regrab(changes): - print 'regrabbing!' for wid, mods, kc in __keybinds: if kc in changes: ungrab_key(wid, mods, kc) From 3415e18cd3eb54a4a9d3da6afb953273e526aa28 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Mon, 20 Feb 2012 00:17:08 -0500 Subject: [PATCH 12/12] rounding out changes for xpybutil2 --- xpybutil/ewmh.py | 672 ++++++++++++++++----------------- xpybutil/keysym.py | 8 +- xpybutil/keysymdef/__init__.py | 17 +- xpybutil/rect.py | 102 ++++- xpybutil/window.py | 8 +- xpybutil/xinerama.py | 6 +- 6 files changed, 456 insertions(+), 357 deletions(-) diff --git a/xpybutil/ewmh.py b/xpybutil/ewmh.py index de0d40b..89f95a3 100644 --- a/xpybutil/ewmh.py +++ b/xpybutil/ewmh.py @@ -114,8 +114,8 @@ def get_supported(): """ Returns a list of hints supported by the window manager. - @return: A list of atoms in the _NET_SUPPORTED property. - @rtype: util.PropertyCookie (ATOM[]/32) + :return: A list of atoms in the _NET_SUPPORTED property. + :rtype: util.PropertyCookie (ATOM[]/32) """ return util.PropertyCookie(util.get_property(root, '_NET_SUPPORTED')) @@ -127,9 +127,9 @@ def set_supported(atoms): """ Sets the list of hints supported by the window manager. - @param atoms: A list of atom identifiers. - @type atoms: ATOM[]/32 - @rtype: xcb.VoidCookie + :param atoms: A list of atom identifiers. + :type atoms: ATOM[]/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('I' * len(atoms), *atoms) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, @@ -148,8 +148,8 @@ def get_client_list(): """ Returns a list of windows managed by the window manager. - @return: A list of window identifiers. - @rtype: util.PropertyCookie (ATOM[]/32) + :return: A list of window identifiers. + :rtype: util.PropertyCookie (ATOM[]/32) """ return util.PropertyCookie(util.get_property(root, '_NET_CLIENT_LIST')) @@ -161,9 +161,9 @@ def set_client_list(windows): """ Sets the list of windows managed by the window manager. - @param windows: A list of atom identifiers. - @type windows: ATOM[]/32 - @rtype: xcb.VoidCookie + :param windows: A list of atom identifiers. + :type windows: ATOM[]/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('I' * len(windows), *windows) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, @@ -182,8 +182,8 @@ def get_client_list_stacking(): """ Returns the window stacking order. - @return: A list of window identifiers. - @rtype: util.PropertyCookie (ATOM[]/32) + :return: A list of window identifiers. + :rtype: util.PropertyCookie (ATOM[]/32) """ return util.PropertyCookie(util.get_property(root, '_NET_CLIENT_LIST_STACKING')) @@ -196,9 +196,9 @@ def set_client_list_stacking(windows): """ Sets the window stacking order. - @param windows: A list of atom identifiers. - @type windows: ATOM[]/32 - @rtype: xcb.VoidCookie + :param windows: A list of atom identifiers. + :type windows: ATOM[]/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('I' * len(windows), *windows) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, @@ -217,8 +217,8 @@ def get_number_of_desktops(): """ Returns the number of virtual desktops. - @return: The number of desktops. - @rtype: util.PropertyCookieSingle (CARDINAL/32) + :return: The number of desktops. + :rtype: util.PropertyCookieSingle (CARDINAL/32) """ cook = util.get_property(root, '_NET_NUMBER_OF_DESKTOPS') return util.PropertyCookieSingle(cook) @@ -231,9 +231,9 @@ def set_number_of_desktops(number_of_desktops): """ Sets the number of desktops. - @param number_of_desktops: The number of desktops. - @type number_of_desktops: CARDINAL/32 - @rtype: xcb.VoidCookie + :param number_of_desktops: The number of desktops. + :type number_of_desktops: CARDINAL/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('I', number_of_desktops) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, @@ -250,9 +250,9 @@ def request_number_of_desktops(number_of_desktops): """ Sends event to root window to set the number of desktops. - @param number_of_desktops: The number of desktops. - @type number_of_desktops: CARDINAL/32 - @rtype: xcb.VoidCookie + :param number_of_desktops: The number of desktops. + :type number_of_desktops: CARDINAL/32 + :rtype: xcb.VoidCookie """ return revent(root, '_NET_NUMBER_OF_DESKTOPS', number_of_desktops) @@ -274,13 +274,11 @@ def reply(self): } def get_desktop_geometry(): - """ - Returns the desktop geometry. - - @return: A desktop geometry dictionary. + """Returns the desktop geometry. + :return: A desktop geometry dictionary. Keys: width, height - @rtype: DesktopGeometryCookie (CARDINAL[2]/32) + :rtype: DesktopGeometryCookie (CARDINAL[2]/32) """ return DesktopGeometryCookie(util.get_property(root, '_NET_DESKTOP_GEOMETRY')) @@ -293,11 +291,11 @@ def set_desktop_geometry(width, height): """ Sets the desktop geometry. - @param width: The width of the desktop. - @type width: CARDINAL/32 - @param height: The height of the desktop. - @type height: CARDINAL/32 - @rtype: xcb.VoidCookie + :param width: The width of the desktop. + :type width: CARDINAL/32 + :param height: The height of the desktop. + :type height: CARDINAL/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('II', width, height) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, @@ -314,11 +312,11 @@ def request_desktop_geometry(width, height): """ Sends event to root window to set the desktop geometry. - @param width: The width of the desktop. - @type width: CARDINAL/32 - @param height: The height of the desktop. - @type height: CARDINAL/32 - @rtype: xcb.VoidCookie + :param width: The width of the desktop. + :type width: CARDINAL/32 + :param height: The height of the desktop. + :type height: CARDINAL/32 + :rtype: xcb.VoidCookie """ return revent(root, '_NET_NUMBER_OF_DESKTOPS', width, height) @@ -347,10 +345,10 @@ def get_desktop_viewport(): """ Returns x,y pairs defining the top-left corner of each desktop's viewport. - @return: A list of desktop viewport dictionaries. + :return: A list of desktop viewport dictionaries. Keys: x, y - @rtype: DesktopViewportCookie (CARDINAL[][2]/32) + :rtype: DesktopViewportCookie (CARDINAL[][2]/32) """ return DesktopViewportCookie(util.get_property(root, '_NET_DESKTOP_VIEWPORT')) @@ -381,9 +379,9 @@ def set_desktop_viewport(pairs): Which would set desktop 0's viewport top-left corner to 0,0 and desktop 1's viewport top-left corner to 500,500. - @param pairs: A list of x,y dictionary pairs. - @type pairs: CARDINAL[][2]/32 - @rtype: xcb.VoidCookie + :param pairs: A list of x,y dictionary pairs. + :type pairs: CARDINAL[][2]/32 + :rtype: xcb.VoidCookie """ flatten = [] for pair in pairs: @@ -410,11 +408,11 @@ def request_desktop_viewport(x, y): """ Sends event to root window to set the viewport position of current desktop. - @param x: The x position of the top-left corner. - @type x: CARDINAL/32 - @param y: The y position of the top-left corner. - @type y: CARDINAL/32 - @rtype: xcb.VoidCookie + :param x: The x position of the top-left corner. + :type x: CARDINAL/32 + :param y: The y position of the top-left corner. + :type y: CARDINAL/32 + :rtype: xcb.VoidCookie """ return revent(root, '_NET_DESKTOP_VIEWPORT', x, y) @@ -427,8 +425,8 @@ def get_current_desktop(): """ Returns the current desktop number. - @return: The index of the current desktop. - @rtype: util.PropertyCookieSingle (CARDINAL/32) + :return: The index of the current desktop. + :rtype: util.PropertyCookieSingle (CARDINAL/32) """ return util.PropertyCookieSingle(util.get_property(root, '_NET_CURRENT_DESKTOP')) @@ -441,9 +439,9 @@ def set_current_desktop(current_desktop): """ Sets the current desktop number. - @param current_desktop: The current desktop index. - @type current_desktop: CARDINAL/32 - @rtype: xcb.VoidCookie + :param current_desktop: The current desktop index. + :type current_desktop: CARDINAL/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('I', current_desktop) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, @@ -461,10 +459,10 @@ def request_current_desktop(desktop_number, """ Sends event to root window to set the current desktop. - @param desktop_number: The current desktop index. - @type desktop_number: CARDINAL/32 - @type timestamp: Milliseconds. - @rtype: xcb.VoidCookie + :param desktop_number: The current desktop index. + :type desktop_number: CARDINAL/32 + :type timestamp: Milliseconds. + :rtype: xcb.VoidCookie """ return revent(root, '_NET_CURRENT_DESKTOP', desktop_number, timestamp) @@ -482,8 +480,8 @@ def get_visible_desktops(): The first desktop is on Xinerama screen 0, the second is on Xinerama screen 1, etc. - @return: A list of visible desktops. - @rtype: util.PropertyCookie (ATOM[]/32) + :return: A list of visible desktops. + :rtype: util.PropertyCookie (ATOM[]/32) """ return util.PropertyCookie(util.get_property(root, '_NET_VISIBLE_DESKTOPS')) @@ -495,9 +493,9 @@ def set_visible_desktops(desktops): """ Sets the list of visible desktops. - @param desktops: A list of desktops. - @type desktops: ATOM[]/32 - @rtype: xcb.VoidCookie + :param desktops: A list of desktops. + :type desktops: ATOM[]/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('I' * len(desktops), *desktops) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, @@ -516,8 +514,8 @@ def get_desktop_names(): """ Returns a list of names of the virtual desktops. - @return: A list of virutal desktop names. - @rtype: util.PropertyCookie (UTF8_STRING[]) + :return: A list of virutal desktop names. + :rtype: util.PropertyCookie (UTF8_STRING[]) """ return util.PropertyCookie(util.get_property(root, '_NET_DESKTOP_NAMES')) @@ -529,9 +527,9 @@ def set_desktop_names(desktop_names): """ Sets the current list of desktop names. - @param desktop_names: A list of new desktop names. - @type desktop_names: UTF8_STRING[] - @rtype: xcb.VoidCookie + :param desktop_names: A list of new desktop names. + :type desktop_names: UTF8_STRING[] + :rtype: xcb.VoidCookie """ # Null terminate the list of desktop names nullterm = [] @@ -562,8 +560,8 @@ def get_active_window(): """ Returns the identifier of the currently active window. - @return: The window ID of the active window. - @rtype: util.PropertyCookieSingle (WINDOW/32) + :return: The window ID of the active window. + :rtype: util.PropertyCookieSingle (WINDOW/32) """ return util.PropertyCookieSingle(util.get_property(root, '_NET_ACTIVE_WINDOW')) @@ -576,9 +574,9 @@ def set_active_window(active): """ Sets the identifier of the currently active window. - @param active: The identifier of the window that is active. - @type active: WINDOW/32 - @rtype: xcb.VoidCookie + :param active: The identifier of the window that is active. + :type active: WINDOW/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('I', active) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, @@ -597,12 +595,12 @@ def request_active_window(active, source=1, """ Sends event to root window to set the active window. - @param active: The window ID of the window to make active. - @type active: WINDOW/32 - @param source: The source indication. - @type timestamp: Milliseconds - @param current: Client's active toplevel window - @rtype: xcb.VoidCookie + :param active: The window ID of the window to make active. + :type active: WINDOW/32 + :param source: The source indication. + :type timestamp: Milliseconds + :param current: Client's active toplevel window + :rtype: xcb.VoidCookie """ return revent(active, '_NET_ACTIVE_WINDOW', source, timestamp, current) @@ -636,10 +634,10 @@ def get_workarea(): """ Returns the x, y, width and height defining the desktop workarea. - @return: A list of workarea dictionaries. + :return: A list of workarea dictionaries. Keys: x, y, width, height - @rtype: util.WorkareaCookie (CARDINAL[][4]/32) + :rtype: util.WorkareaCookie (CARDINAL[][4]/32) """ return WorkareaCookie(util.get_property(root, '_NET_WORKAREA')) @@ -650,9 +648,9 @@ def set_workarea(workareas): """ Sets the workarea (x, y, width, height) for each desktop. - @param workareas: A list of x,y,width,height dictionaries. - @type workareas: CARDINAL[][4]/32 - @rtype: xcb.VoidCookie + :param workareas: A list of x,y,width,height dictionaries. + :type workareas: CARDINAL[][4]/32 + :rtype: xcb.VoidCookie """ flatten = [] for workarea in workareas: @@ -685,10 +683,10 @@ def get_supporting_wm_check(wid): """ Returns the identifier of the child window created by the window manager. - @param wid: The identifier of the window with the property. - @type wid: WINDOW/32 - @return: The window ID of the child window. - @rtype: util.PropertyCookieSingle (WINDOW/32) + :param wid: The identifier of the window with the property. + :type wid: WINDOW/32 + :return: The window ID of the child window. + :rtype: util.PropertyCookieSingle (WINDOW/32) """ cook = util.get_property(wid, '_NET_SUPPORTING_WM_CHECK') return util.PropertyCookieSingle(cook) @@ -701,11 +699,11 @@ def set_supporting_wm_check(wid, child): """ Sets the identifier of the child window created by the window manager. - @param wid: The identifier of the window with the property. - @type wid: WINDOW/32 - @param child: The identifier of the child window. - @type child: WINDOW/32 - @rtype: xcb.VoidCookie + :param wid: The identifier of the window with the property. + :type wid: WINDOW/32 + :param child: The identifier of the child window. + :type child: WINDOW/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('I', child) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, wid, @@ -724,8 +722,8 @@ def get_virtual_roots(): """ Returns a list of identifiers for the virtual root windows. - @return: A list of window identifiers for the virtual root windows. - @rtype: util.PropertyCookie (WINDOW[]/32) + :return: A list of window identifiers for the virtual root windows. + :rtype: util.PropertyCookie (WINDOW[]/32) """ return util.PropertyCookie(util.get_property(root, '_NET_VIRTUAL_ROOTS')) @@ -737,9 +735,9 @@ def set_virtual_roots(vroots): """ Sets the identifiers of the virtual root windows. - @param vroots: A list of window identifiers for the virtual root windows. - @type vroots: WINDOW[]/32 - @rtype: xcb.VoidCookie + :param vroots: A list of window identifiers for the virtual root windows. + :type vroots: WINDOW[]/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('I' * len(vroots), *vroots) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, @@ -772,10 +770,10 @@ def get_desktop_layout(): """ Returns the desktop layout. - @return: A desktop layout dictionary. + :return: A desktop layout dictionary. Keys: orientation, columns, rows, starting_corner - @rtype: DesktopLayoutCookie (CARDINAL[4]/32) + :rtype: DesktopLayoutCookie (CARDINAL[4]/32) """ return DesktopLayoutCookie(util.get_property(root, '_NET_DESKTOP_LAYOUT')) @@ -788,16 +786,16 @@ def set_desktop_layout(orientation, columns, rows, """ Sets the desktop layout. - @param orientation: Horizontal or vertical orientation. - @type orientation: CARDINAL/32 - @param columns: Number of columns. - @type columns: CARDINAL/32 - @param rows: Number of rows. - @type rows: CARDINAL/32 - @param starting_corner: Top left, top right, bottom right, or bottom + :param orientation: Horizontal or vertical orientation. + :type orientation: CARDINAL/32 + :param columns: Number of columns. + :type columns: CARDINAL/32 + :param rows: Number of rows. + :type rows: CARDINAL/32 + :param starting_corner: Top left, top right, bottom right, or bottom left may be specified as a starting corner. - @type starting_corner: CARDINAL/32 - @rtype: xcb.VoidCookie + :type starting_corner: CARDINAL/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('IIII', orientation, columns, rows, starting_corner) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, @@ -828,9 +826,9 @@ def get_showing_desktop(): """ Returns whether the window manager is in "showing the desktop" mode. - @return: Boolean whether the window manager is in "showing desktop" + :return: Boolean whether the window manager is in "showing desktop" mode or not. - @rtype: ShowingDesktopCookie (CARDINAL/32) + :rtype: ShowingDesktopCookie (CARDINAL/32) """ return ShowingDesktopCookie(util.get_property(root, '_NET_SHOWING_DESKTOP')) @@ -842,10 +840,10 @@ def set_showing_desktop(showing_desktop): """ Sets whether the window is in "showing the desktop" mode. - @param showing_desktop: Boolean whether the window manager is in "showing + :param showing_desktop: Boolean whether the window manager is in "showing desktop" mode or not. - @type showing_desktop: CARDINAL/32 - @rtype: xcb.VoidCookie + :type showing_desktop: CARDINAL/32 + :rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, root, atom('_NET_SHOWING_DESKTOP'), CARDINAL, 32, 1, @@ -860,10 +858,10 @@ def request_showing_desktop(showing_desktop): """ Sends event to root window to put window manager in "showing desktop" mode. - @param showing_desktop: Boolean whether the window manager is in "showing + :param showing_desktop: Boolean whether the window manager is in "showing desktop" mode or not. - @type showing_desktop: CARDINAL/32 - @rtype: xcb.VoidCookie + :type showing_desktop: CARDINAL/32 + :rtype: xcb.VoidCookie """ return revent(root, '_NET_SHOWING_DESKTOP', showing_desktop) @@ -877,10 +875,10 @@ def request_close_window(window, timestamp=xcb.xproto.Time.CurrentTime, """ Sends event to root window to close a window. - @param window: A window identifier. - @param source: The source indication. - @type timestamp: Milliseconds - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param source: The source indication. + :type timestamp: Milliseconds + :rtype: xcb.VoidCookie """ return revent(window, '_NET_CLOSE_WINDOW', timestamp, source) @@ -896,17 +894,17 @@ def request_moveresize_window(window, x=None, y=None, width=None, """ Sends event to root window to move/resize a window. - @param window: A window identifier. - @param x: x coordinate - @param y: y coordinate - @param width: Width - @param height: Height - @param gravity: Should be one of NorthWest, North, NorthEast, West, + :param window: A window identifier. + :param x: x coordinate + :param y: y coordinate + :param width: Width + :param height: Height + :param gravity: Should be one of NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast, and Static. If set to 0, the window manager should use the default gravity for the window. - @param source: The source indication. - @rtype: xcb.VoidCookie + :param source: The source indication. + :rtype: xcb.VoidCookie """ flags = gravity flags |= source << 12 @@ -947,8 +945,8 @@ def request_wm_moveresize(window, direction, x_root=0, y_root=0, """ Sends event to root window to initiate window movement or resizing. - @param window: A window identifier. - @param direction: Whether it is moving or resizing, and if resizing, + :param window: A window identifier. + :param direction: Whether it is moving or resizing, and if resizing, the direction. Can be one of the following flags: _NET_WM_MOVERESIZE_SIZE_TOPLEFT = 0 @@ -974,12 +972,12 @@ def request_wm_moveresize(window, direction, x_root=0, y_root=0, _NET_WM_MOVERESIZE_MOVE_KEYBOARD = 10 _NET_WM_MOVERESIZE_CANCEL = 11 - @param x_root: x coordinate of the pointer. - @param y_root: y coordinate of the pointer. - @param button: Which button was pressed, if a mouse button was used + :param x_root: x coordinate of the pointer. + :param y_root: y coordinate of the pointer. + :param button: Which button was pressed, if a mouse button was used to initiate this request. - @param source: The source indication. - @rtype: xcb.VoidCookie + :param source: The source indication. + :rtype: xcb.VoidCookie """ return revent(window, '_NET_WM_MOVERESIZE', x_root, y_root, direction, button, source) @@ -996,12 +994,12 @@ def request_restack_window(window, stack_mode=xcb.xproto.StackMode.Above, """ Sends event to root window to restack a window. - @param window: A window identifier. - @param stack_mode: Stacking mode of window. Can be one of the following + :param window: A window identifier. + :param stack_mode: Stacking mode of window. Can be one of the following flags: Above, Below, TopIf, BottomIf, Opposite - @param sibling: A sibling window identifier. - @param source: The source indication. - @rtype: xcb.VoidCookie + :param sibling: A sibling window identifier. + :param source: The source indication. + :rtype: xcb.VoidCookie """ return revent(window, '_NET_RESTACK_WINDOW', source, sibling, stack_mode) @@ -1017,8 +1015,8 @@ def request_request_frame_extents(window): """ Sends event to root window ask the WM to estimate the frame extents. - @param window: A window identifier. - @rtype: xcb.VoidCookie + :param window: A window identifier. + :rtype: xcb.VoidCookie """ return revent(window, '_NET_REQUEST_FRAME_EXTENTS') @@ -1031,9 +1029,9 @@ def get_wm_name(window): """ Get the title of a window. - @param window: A window identifier. - @return: The window's title. - @rtype: util.PropertyCookie (UTF8_STRING) + :param window: A window identifier. + :return: The window's title. + :rtype: util.PropertyCookie (UTF8_STRING) """ return util.PropertyCookie(util.get_property(window, '_NET_WM_NAME')) @@ -1045,9 +1043,9 @@ def set_wm_name(window, wm_name): """ Sets the title of a window. - @param window: A window identifier. - @param wm_name: The title of the window. - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param wm_name: The title of the window. + :rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, atom('_NET_WM_NAME'), @@ -1065,9 +1063,9 @@ def get_wm_visible_name(window): """ Get the visible title of a window. - @param window: A window identifier. - @return: The window's visible title. - @rtype: util.PropertyCookie (UTF8_STRING) + :param window: A window identifier. + :return: The window's visible title. + :rtype: util.PropertyCookie (UTF8_STRING) """ return util.PropertyCookie(util.get_property(window, '_NET_WM_VISIBLE_NAME')) @@ -1080,9 +1078,9 @@ def set_wm_visible_name(window, wm_name): """ Sets the visible title of a window. - @param window: A window identifier. - @param wm_name: The title of the window. - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param wm_name: The title of the window. + :rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, atom('_NET_WM_VISIBLE_NAME'), @@ -1100,9 +1098,9 @@ def get_wm_icon_name(window): """ Get the icon name of a window. - @param window: A window identifier. - @return: The window's icon name. - @rtype: util.PropertyCookie (UTF8_STRING) + :param window: A window identifier. + :return: The window's icon name. + :rtype: util.PropertyCookie (UTF8_STRING) """ return util.PropertyCookie(util.get_property(window, '_NET_WM_ICON_NAME')) @@ -1114,9 +1112,9 @@ def set_wm_icon_name(window, icon_name): """ Sets the icon name of a window. - @param window: A window identifier. - @param icon_name: The icon name of the window. - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param icon_name: The icon name of the window. + :rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, atom('_NET_WM_ICON_NAME'), atom('UTF8_STRING'), @@ -1134,9 +1132,9 @@ def get_wm_visible_icon_name(window): """ Get the visible icon name of a window. - @param window: A window identifier. - @return: The window's visible icon name. - @rtype: util.PropertyCookie (UTF8_STRING) + :param window: A window identifier. + :return: The window's visible icon name. + :rtype: util.PropertyCookie (UTF8_STRING) """ return util.PropertyCookie(util.get_property(window, '_NET_WM_VISIBLE_ICON_NAME')) @@ -1149,9 +1147,9 @@ def set_wm_visible_icon_name(window, icon_name): """ Sets the visible icon name of a window. - @param window: A window identifier. - @param icon_name: The icon name of the window. - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param icon_name: The icon name of the window. + :rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, atom('_NET_WM_VISIBLE_ICON_NAME'), @@ -1182,9 +1180,9 @@ def get_wm_window_opacity(window): N.B. If your window manager uses decorations, you'll typically want to pass your client's *parent* window to this function. - @param window: A window identifier. - @return: An opacity percentage between 0 and 1 (inclusive) - @rtype: util.PropertyCookieSingle (CARDINAL/32) + :param window: A window identifier. + :return: An opacity percentage between 0 and 1 (inclusive) + :rtype: util.PropertyCookieSingle (CARDINAL/32) """ return OpacityCookieSingle(util.get_property(window, '_NET_WM_WINDOW_OPACITY')) @@ -1200,12 +1198,12 @@ def set_wm_window_opacity(window, opacity): N.B. If your window manager uses decorations, you'll typically want to pass your client's *parent* window to this function. - @param window: A window identifier. - @param opacity: A float between 0 and 1 inclusive. + :param window: A window identifier. + :param opacity: A float between 0 and 1 inclusive. 0 is completely transparent and 1 is completely opaque. - @type opacity: CARDINAL/32 - @rtype: xcb.VoidCookie + :type opacity: CARDINAL/32 + :rtype: xcb.VoidCookie """ assert 0 <= opacity <= 1 packed = struct.pack('I', int(opacity * 0xffffffff)) @@ -1226,9 +1224,9 @@ def get_wm_desktop(window): """ Get the desktop index of the window. - @param window: A window identifier. - @return: The window's virtual desktop index. - @rtype: util.PropertyCookieSingle (CARDINAL/32) + :param window: A window identifier. + :return: The window's virtual desktop index. + :rtype: util.PropertyCookieSingle (CARDINAL/32) """ return util.PropertyCookieSingle(util.get_property(window, '_NET_WM_DESKTOP')) @@ -1241,10 +1239,10 @@ def set_wm_desktop(window, desktop): """ Sets the desktop index of the window. - @param window: A window identifier. - @param desktop: A desktop index. - @type desktop: CARDINAL/32 - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param desktop: A desktop index. + :type desktop: CARDINAL/32 + :rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, atom('_NET_WM_DESKTOP'), @@ -1259,11 +1257,11 @@ def request_wm_desktop(window, desktop, source=1): """ Sends an event to root window to change the desktop of the window. - @param window: A window identifier. - @param desktop: A desktop index. - @type desktop: CARDINAL/32 - @param source: The source indication. - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param desktop: A desktop index. + :type desktop: CARDINAL/32 + :param source: The source indication. + :rtype: xcb.VoidCookie """ return revent(window, '_NET_WM_DESKTOP', desktop, source) @@ -1276,9 +1274,9 @@ def get_wm_window_type(window): """ Get a list of atoms representing the type of the window. - @param window: A window identifier. - @return: A list of atoms corresponding to this window's type. - @rtype: util.PropertyCookie (ATOM[]/32) + :param window: A window identifier. + :return: A list of atoms corresponding to this window's type. + :rtype: util.PropertyCookie (ATOM[]/32) """ return util.PropertyCookie(util.get_property(window, '_NET_WM_WINDOW_TYPE')) @@ -1290,10 +1288,10 @@ def set_wm_window_type(window, types): """ Sets the list of atoms representing this window's type. - @param window: A window identifier. - @param types: A list of window type atoms. - @type types: ATOM[]/32 - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param types: A list of window type atoms. + :type types: ATOM[]/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('I' * len(types), *types) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, @@ -1312,9 +1310,9 @@ def get_wm_state(window): """ Get a list of atoms representing the state of the window. - @param window: A window identifier. - @return: A list of atoms corresponding to this window's state. - @rtype: util.PropertyCookie (ATOM[]/32) + :param window: A window identifier. + :return: A list of atoms corresponding to this window's state. + :rtype: util.PropertyCookie (ATOM[]/32) """ return util.PropertyCookie(util.get_property(window, '_NET_WM_STATE')) @@ -1326,10 +1324,10 @@ def set_wm_state(window, states): """ Sets the list of atoms representing this window's state. - @param window: A window identifier. - @param states: A list of window state atoms. - @type states: ATOM[]/32 - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param states: A list of window state atoms. + :type states: ATOM[]/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('I' * len(states), *states) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, @@ -1346,18 +1344,18 @@ def request_wm_state(window, action, first, second=0, source=1): """ Sends an event to root window to change the state of the window. - @param window: A window identifier. - @param action: The kind of state action to perform. I tshould be one + :param window: A window identifier. + :param action: The kind of state action to perform. I tshould be one of the following flags: _NET_WM_STATE_REMOVE = 0 _NET_WM_STATE_ADD = 1 _NET_WM_STATE_TOGGLE = 2 - @param first: The first property to be changed. - @param second: The second property to be changed (should be 0 if only + :param first: The first property to be changed. + :param second: The second property to be changed (should be 0 if only one property is being changed). - @param source: The source indication. - @rtype: xcb.VoidCookie + :param source: The source indication. + :rtype: xcb.VoidCookie """ return revent(window, '_NET_WM_STATE', action, first, second, source) @@ -1371,10 +1369,10 @@ def get_wm_allowed_actions(window): """ Get a list of atoms representing the WM supported actions on a window. - @param window: A window identifier. - @return: A list of atoms corresponding to this window's supported + :param window: A window identifier. + :return: A list of atoms corresponding to this window's supported actions through the window manager. - @rtype: util.PropertyCookie (ATOM[]/32) + :rtype: util.PropertyCookie (ATOM[]/32) """ return util.PropertyCookie(util.get_property(window, '_NET_WM_ALLOWED_ACTIONS')) @@ -1387,10 +1385,10 @@ def set_wm_allowed_actions(window, actions): """ Sets the list of atoms representing the WM supported actions on a window. - @param window: A window identifier. - @param actions: A list of allowable action atoms. - @type actions: ATOM[]/32 - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param actions: A list of allowable action atoms. + :type actions: ATOM[]/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('I' * len(actions), *actions) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, @@ -1423,11 +1421,11 @@ def get_wm_strut(window): """ Returns the struts for a window. - @param window: A window identifier. - @return: A strut dictionary. + :param window: A window identifier. + :return: A strut dictionary. Keys: left, right, top, bottom - @rtype: StrutCookie (CARDINAL[4]/32) + :rtype: StrutCookie (CARDINAL[4]/32) """ return StrutCookie(util.get_property(window, '_NET_WM_STRUT')) @@ -1438,16 +1436,16 @@ def set_wm_strut(window, left, right, top, bottom): """ Sets the struts for a window. - @param window: A window identifier. - @param left: Width of area at left side of screen. - @type left: CARDINAL/32 - @param right: Width of area at right side of screen. - @type right: CARDINAL/32 - @param top: Height of area at top side of screen. - @type top: CARDINAL/32 - @param bottom: Height of area at bottom side of screen. - @type bottom: CARDINAL/32 - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param left: Width of area at left side of screen. + :type left: CARDINAL/32 + :param right: Width of area at right side of screen. + :type right: CARDINAL/32 + :param top: Height of area at top side of screen. + :type top: CARDINAL/32 + :param bottom: Height of area at bottom side of screen. + :type bottom: CARDINAL/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('IIII', left, right, top, bottom) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, @@ -1487,13 +1485,13 @@ def get_wm_strut_partial(window): """ Returns the partial struts for a window. - @param window: A window identifier. - @return: A strut dictionary. + :param window: A window identifier. + :return: A strut dictionary. Keys: left, right, top, bottom, left_start_y, left_end_y, right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x, bottom_end_x - @rtype: StrutPartialCookie (CARDINAL[12]/32) + :rtype: StrutPartialCookie (CARDINAL[12]/32) """ return StrutPartialCookie(util.get_property(window, '_NET_WM_STRUT_PARTIAL')) @@ -1508,24 +1506,24 @@ def set_wm_strut_partial(window, left, right, top, bottom, left_start_y, """ Sets the partial struts for a window. - @param window: A window identifier. - @param left: Width of area at left side of screen. - @type left: CARDINAL/32 - @param right: Width of area at right side of screen. - @type right: CARDINAL/32 - @param top: Height of area at top side of screen. - @type top: CARDINAL/32 - @param bottom: Height of area at bottom side of screen. - @type bottom: CARDINAL/32 - @param left_start_y: - @param left_end_y: - @param right_start_y: - @param right_end_y: - @param top_start_x: - @param top_end_x: - @param bottom_start_x: - @param bottom_end_x: - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param left: Width of area at left side of screen. + :type left: CARDINAL/32 + :param right: Width of area at right side of screen. + :type right: CARDINAL/32 + :param top: Height of area at top side of screen. + :type top: CARDINAL/32 + :param bottom: Height of area at bottom side of screen. + :type bottom: CARDINAL/32 + :param left_start_y: + :param left_end_y: + :param right_start_y: + :param right_end_y: + :param top_start_x: + :param top_end_x: + :param bottom_start_x: + :param bottom_end_x: + :rtype: xcb.VoidCookie """ packed = struct.pack('I' * 12, left, right, top, bottom, left_start_y, left_end_y, right_start_y, right_end_y, top_start_x, @@ -1565,11 +1563,11 @@ def get_wm_icon_geometry(window): """ Returns the icon geometry for a window. - @param window: A window identifier. - @return: An icon geometry dictionary. + :param window: A window identifier. + :return: An icon geometry dictionary. Keys: x, y, width, height - @rtype: IconGeometryCookie (CARDINAL[4]/32) + :rtype: IconGeometryCookie (CARDINAL[4]/32) """ return IconGeometryCookie(util.get_property(window, '_NET_WM_ICON_GEOMETRY')) @@ -1582,16 +1580,16 @@ def set_wm_icon_geometry(window, x, y, width, height): """ Sets the icon geometry for a window. - @param window: A window identifier. - @param x: x coordinate of icon area. - @type x: CARDINAL/32 - @param y: y coordinate of icon area. - @type y: CARDINAL/32 - @param width: Width of icon area. - @type width: CARDINAL/32 - @param height: Height of icon area. - @type height: CARDINAL/32 - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param x: x coordinate of icon area. + :type x: CARDINAL/32 + :param y: y coordinate of icon area. + :type y: CARDINAL/32 + :param width: Width of icon area. + :type width: CARDINAL/32 + :param height: Height of icon area. + :type height: CARDINAL/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('IIII', x, y, width, height) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, @@ -1633,11 +1631,11 @@ def get_wm_icon(window): """ Returns an array of possible icons for a window. - @param window: A window identifier. - @return: A list of icon dictionaries. + :param window: A window identifier. + :return: A list of icon dictionaries. Keys: width, height, data - @rtype: IconCookie (CARDINAL[][2+n]/32) + :rtype: IconCookie (CARDINAL[][2+n]/32) """ return IconCookie(util.get_property(window, '_NET_WM_ICON')) @@ -1648,11 +1646,11 @@ def set_wm_icon(window, icons): """ Sets the array of possible icons for a window. - @param window: A window identifier. - @param icons: A list icon dictionaries. Each dictionary should have + :param window: A window identifier. + :param icons: A list icon dictionaries. Each dictionary should have the following keys: width, height and data. - @type icons: CARDINAL[][2+n]/32 - @rtype: xcb.VoidCookie + :type icons: CARDINAL[][2+n]/32 + :rtype: xcb.VoidCookie """ flatten = [] for icon in icons: @@ -1685,9 +1683,9 @@ def get_wm_pid(window): """ Get the process ID of the client owning a window. - @param window: A window identifier. - @return: The window's client's process ID. - @rtype: util.PropertyCookieSingle (CARDINAL/32) + :param window: A window identifier. + :return: The window's client's process ID. + :rtype: util.PropertyCookieSingle (CARDINAL/32) """ return util.PropertyCookieSingle(util.get_property(window, '_NET_WM_PID')) @@ -1699,10 +1697,10 @@ def set_wm_pid(window, pid): """ Sets the process ID of the client owning a window. - @param window: A window identifier. - @param pid: A process ID. - @type pid: CARDINAL/32 - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param pid: A process ID. + :type pid: CARDINAL/32 + :rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, atom('_NET_WM_PID'), CARDINAL, 32, 1, [pid]) @@ -1718,9 +1716,9 @@ def get_wm_handled_icons(window): """ Gets the "handled icons" property. - @param window: A window identifier. - @return: Whether this property is set or not. - @rtype: util.PropertyCookieSingle (CARDINAL/32) + :param window: A window identifier. + :return: Whether this property is set or not. + :rtype: util.PropertyCookieSingle (CARDINAL/32) """ return util.PropertyCookieSingle(util.get_property(window, '_NET_WM_HANDLED_ICONS')) @@ -1733,9 +1731,9 @@ def set_wm_handled_icons(window): """ Sets the "handled icons" property. - @param window: A window identifier. - @return: Whether this property is set or not. - @rtype: xcb.VoidCookie + :param window: A window identifier. + :return: Whether this property is set or not. + :rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, atom('_NET_WM_HANDLED_ICONS'), CARDINAL, 32, 1, @@ -1752,9 +1750,9 @@ def get_wm_user_time(window): """ Get the time at which the last user activity occurred on a window. - @param window: A window identifier. - @return: The XServer time when user activity last occurred. - @rtype: util.PropertyCookieSingle (CARDINAL/32) + :param window: A window identifier. + :return: The XServer time when user activity last occurred. + :rtype: util.PropertyCookieSingle (CARDINAL/32) """ return util.PropertyCookieSingle(util.get_property(window, '_NET_WM_USER_TIME')) @@ -1767,10 +1765,10 @@ def set_wm_user_time(window, user_time): """ Sets the time that user activity last occurred on this window. - @param window: A window identifier. - @param user_time: Last user activity time. - @type user_time: CARDINAL/32 - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param user_time: Last user activity time. + :type user_time: CARDINAL/32 + :rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, atom('_NET_WM_USER_TIME'), CARDINAL, 32, 1, @@ -1787,9 +1785,9 @@ def get_wm_user_time_window(window): """ Gets the window that sets the _NET_WM_USER_TIME property. - @param window: A window identifier. - @return: Window identifier that sets the _NET_WM_USER_TIME property. - @rtype: util.PropertyCookieSingle (WINDOW/32) + :param window: A window identifier. + :return: Window identifier that sets the _NET_WM_USER_TIME property. + :rtype: util.PropertyCookieSingle (WINDOW/32) """ cook = util.get_property(window, '_NET_WM_USER_TIME_WINDOW') return util.PropertyCookieSingle(cook) @@ -1802,10 +1800,10 @@ def set_wm_user_time_window(window, time_win): """ Sets the window identifier that sets the _NET_WM_USER_TIME property. - @param window: A window identifier. - @param time_win: Window ID that sets the _NET_WM_USER_TIME property. - @type time_win: WINDOW/32 - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param time_win: Window ID that sets the _NET_WM_USER_TIME property. + :type time_win: WINDOW/32 + :rtype: xcb.VoidCookie """ return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, atom('_NET_WM_USER_TIME_WINDOW'), @@ -1836,11 +1834,11 @@ def get_frame_extents(window): """ Returns the frame extents for a window. - @param window: A window identifier. - @return: A frame extents dictionary. + :param window: A window identifier. + :return: A frame extents dictionary. Keys: left, right, top, bottom - @rtype: FrameExtentsCookie (CARDINAL[4]/32) + :rtype: FrameExtentsCookie (CARDINAL[4]/32) """ return FrameExtentsCookie(util.get_property(window, '_NET_FRAME_EXTENTS')) @@ -1852,16 +1850,16 @@ def set_frame_extents(window, left, right, top, bottom): """ Sets the frame extents for a window. - @param window: A window identifier. - @param left: Width of left border. - @type left: CARDINAL/32 - @param right: Width of right border. - @type right: CARDINAL/32 - @param top: Height of top border. - @type top: CARDINAL/32 - @param bottom: Height of bottom border. - @type bottom: CARDINAL/32 - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param left: Width of left border. + :type left: CARDINAL/32 + :param right: Width of right border. + :type right: CARDINAL/32 + :param top: Height of top border. + :type top: CARDINAL/32 + :param bottom: Height of bottom border. + :type bottom: CARDINAL/32 + :rtype: xcb.VoidCookie """ packed = struct.pack('IIII', left, right, top, bottom) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, @@ -1881,10 +1879,10 @@ def request_wm_ping(window, response=False, """ Sends an event to root window to ping a window or respond to a ping. - @param window: A window identifier. - @param response: Whether this is a response to a ping request or not. - @type timestamp: Milliseconds - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param response: Whether this is a response to a ping request or not. + :type timestamp: Milliseconds + :rtype: xcb.VoidCookie """ return revent(window if not response else root(c), 'WM_PROTOCOLS', atom('_NET_WM_PING'), timestamp, window) @@ -1901,10 +1899,10 @@ def request_wm_sync_request(window, req_num, """ Sends an event to root window to sync with a client. - @param window: A window identifier. - @param req_num: The XSync request number. - @type timestamp: Milliseconds - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param req_num: The XSync request number. + :type timestamp: Milliseconds + :rtype: xcb.VoidCookie """ high = req_num >> 32 low = (high << 32) ^ req_num @@ -1926,9 +1924,9 @@ def get_wm_sync_request_counter(window): """ Gets XSync counter for this client. - @param window: A window identifier. - @return: An XSync XID. - @rtype: util.PropertyCookieSingle (CARDINAL/32) + :param window: A window identifier. + :return: An XSync XID. + :rtype: util.PropertyCookieSingle (CARDINAL/32) """ cook = util.get_property(window, '_NET_WM_SYNC_REQUEST_COUNTER') return util.PropertyCookieSingle(cook) @@ -1941,10 +1939,10 @@ def set_wm_sync_request_counter(window, counter): """ Sets the XSync counter for this client. - @param window: A window identifier. - @param counter: An XSync XID. - @type counter: CARDINAL - @rtype: xcb.VoidCookie + :param window: A window identifier. + :param counter: An XSync XID. + :type counter: CARDINAL + :rtype: xcb.VoidCookie """ packed = struct.pack('I', counter) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, @@ -1977,9 +1975,9 @@ def get_wm_fullscreen_monitors(window): """ Get list of monitor edges for this window. - @param window: A window identifier. - @return: The window's monitor edges. - @rtype: FullscreenMonitorsCookie (CARDINAL[4]/32) + :param window: A window identifier. + :return: The window's monitor edges. + :rtype: FullscreenMonitorsCookie (CARDINAL[4]/32) """ return FullscreenMonitorsCookie( util.get_property(window, '_NET_WM_FULLSCREEN_MONITORS')) @@ -1992,15 +1990,15 @@ def set_wm_fullscreen_monitors(window, top, bottom, left, right): """ Sets list of monitor edges for this window. - @param window: A window identifier. - @param top: The monitor whose top edge defines the top edge of window. - @param bottom: The monitor whose bottom edge defines the bottom edge of + :param window: A window identifier. + :param top: The monitor whose top edge defines the top edge of window. + :param bottom: The monitor whose bottom edge defines the bottom edge of window. - @param left: The monitor whose left edge defines the left edge of + :param left: The monitor whose left edge defines the left edge of window. - @param right: The monitor whose right edge defines the right edge of + :param right: The monitor whose right edge defines the right edge of window. - @rtype: xcb.VoidCookie + :rtype: xcb.VoidCookie """ packed = struct.pack('IIII', top, bottom, left, right) return c.core.ChangeProperty(xcb.xproto.PropMode.Replace, window, @@ -2018,16 +2016,16 @@ def request_wm_fullscreen_monitors(window, top, bottom, left, right, """ Sends an event to root window to change monitor edges for this window. - @param window: A window identifier. - @param top: The monitor whose top edge defines the top edge of window. - @param bottom: The monitor whose bottom edge defines the bottom edge of + :param window: A window identifier. + :param top: The monitor whose top edge defines the top edge of window. + :param bottom: The monitor whose bottom edge defines the bottom edge of window. - @param left: The monitor whose left edge defines the left edge of + :param left: The monitor whose left edge defines the left edge of window. - @param right: The monitor whose right edge defines the right edge of + :param right: The monitor whose right edge defines the right edge of window. - @param source: The source indication. - @rtype: xcb.VoidCookie + :param source: The source indication. + :rtype: xcb.VoidCookie """ return revent(window, '_NET_WM_FULLSCREEN_MONITORS', top, bottom, left, right, source) diff --git a/xpybutil/keysym.py b/xpybutil/keysym.py index 350e867..0979552 100644 --- a/xpybutil/keysym.py +++ b/xpybutil/keysym.py @@ -5,7 +5,7 @@ from xpybutil import conn, root import event -from keysymdef import keysyms, keycodes +from keysymdef import keysyms, keysym_strings __kbmap = None __keysmods = None @@ -62,8 +62,8 @@ def lookup_string(kstr): return None def lookup_keysym(keysym): - if keysym in keycodes: - return keycodes[keysym][0] + if keysym in keysym_strings: + return keysym_strings[keysym][0] return None def get_min_max_keycode(): @@ -90,7 +90,7 @@ def get_keysym(keycode, col=0, kbmap=None): return __kbmap.keysyms[ind] def get_keysym_string(keysym, col=0): - return keycodes[keysym][col] + return keysym_strings[keysym][col] def get_keycode(keysym): mn, mx = get_min_max_keycode() diff --git a/xpybutil/keysymdef/__init__.py b/xpybutil/keysymdef/__init__.py index c4e51b0..d910c45 100644 --- a/xpybutil/keysymdef/__init__.py +++ b/xpybutil/keysymdef/__init__.py @@ -1,3 +1,13 @@ +""" +A module that creates a dictionary mapping from an english string of a key, +to a keysym (an X data type) in ``keysyms``. + +The module also creates a reverse mapping called ``keysym_strings`` that maps +a keysym to a **list** of english string versions of that keysym. (There are +more string representations than there are keysyms.) + +This list is taken from Xlib. +""" from collections import defaultdict keysyms = { @@ -2008,6 +2018,7 @@ 'braille_dots_12345678': 0x10028ff, } -keycodes = defaultdict(list) -for keysym in keysyms: - keycodes[keysyms[keysym]].append(keysym) +keysym_strings = defaultdict(list) +for keysym_string, keysym in keysyms.iteritems(): + keysym_strings[keysym].append(keysym_string) + diff --git a/xpybutil/rect.py b/xpybutil/rect.py index 7759e65..5ca68d1 100644 --- a/xpybutil/rect.py +++ b/xpybutil/rect.py @@ -1,20 +1,29 @@ +""" +This module has a few utility functions that perform math on rectangles. + +For example, finding the area of intersection of two rectangles with +``rect_intersect_area``, or getting the rectangle of a monitor after accounting +for struts with ``monitor_rects``. +""" import xcb.xproto import xpybutil.ewmh as ewmh import xpybutil.window as window def rect_intersect_area(r1, r2): - ''' + """ Returns the area of the intersection of two rectangles. If the rectangles do not intersect, the area returned is 0. - @param r1: A 4-tuple representing a rectangle: + :param r1: A 4-tuple representing a rectangle: + (top_left_x, top_left_y, width, height) - @param r2: A 4-tuple representing a rectangle: + :param r2: A 4-tuple representing a rectangle: + (top_left_x, top_left_y, width, height) - @return: Area of intersection of r1 and r2. - @rtype: Integer - ''' + :return: Area of intersection of r1 and r2. + :rtype: Integer + """ x1, y1, w1, h1 = r1 x2, y2, w2, h2 = r2 if x2 < x1 + w1 and x2 + w2 > x1 and y2 < y1 + h1 and y2 + h2 > y1: @@ -24,3 +33,84 @@ def rect_intersect_area(r1, r2): return 0 +def get_monitor_area(search, monitors): + """ + Returns the monitor with the most overlap with the 'search' rectangle. + + :param search: A 4-tuple representing a rectangle: + (top_left_x, top_left_y, width, height) + :param monitors: A list of 4-tuples representing each monitor's rectangle. + :return: The monitor rectangle with the most overlap with 'search'. + :rtype: (top_left_x, top_left_y, width, height) + """ + marea = 0 + mon = None + for mx, my, mw, mh in monitors: + a = rect_intersect_area((mx, my, mw, mh), search) + if a > marea: + marea = a + mon = (mx, my, mw, mh) + + return mon + +def monitor_rects(monitors): + """ + Takes a list of monitors returned by ``xinerama.get_monitors`` and returns + a new list of rectangles, in the same order, of monitor areas that account + for all struts set by all windows. Duplicate struts are ignored. + + :param monitors: A list of 4-tuples representing monitor rectangles. + :return: A list of 4-tuples representing monitor rectangles after + subtracting strut areas. + :rtype: [(top_left_x, top_left_y, width, height)] + """ + mons = monitors # alias + wa = mons[:] + + clients = ewmh.get_client_list().reply() + + log = [] # Identical struts should be ignored + + for c in clients: + try: + cx, cy, cw, ch = window.get_geometry(c) + except xcb.xproto.BadWindow: + continue + + for i, (x, y, w, h) in enumerate(wa): + if rect_intersect_area((x, y, w, h), (cx, cy, cw, ch)) > 0: + struts = ewmh.get_wm_strut_partial(c).reply() + if not struts: + struts = ewmh.get_wm_strut(c).reply() + + key = (cx, cy, cw, ch, struts) + if key in log: + continue + log.append(key) + + if struts and not all([v == 0 for v in struts.itervalues()]): + if struts['left'] or struts['right']: + if struts['left']: + x += cw + w -= cw + if struts['top'] or struts['bottom']: + if struts['top']: + y += ch + h -= ch + elif struts: + # x/y shouldn't be zero + if cx > 0 and w == cx + cw: + w -= cw + elif cy > 0 and h == cy + ch: + h -= ch + elif cx > 0 and x == cx: + x += cw + w -= cw + elif cy > 0 and y == cy: + y += ch + h -= ch + + wa[i] = (x, y, w, h) + + return wa + diff --git a/xpybutil/window.py b/xpybutil/window.py index 9af94e7..2a1d195 100644 --- a/xpybutil/window.py +++ b/xpybutil/window.py @@ -22,14 +22,14 @@ def _get_geometry(win): return raw.x, raw.y, raw.width, raw.height def get_geometry(window, window_manager=None): - ''' + """ Returns the geometry of a window. This function will do its best to get the real geometry of a window; typically by inspecting the window's decorations if there are any. Since decorations are different for each window manager, you'll get the best possible results by passing a supported window manager in. - ''' + """ if window_manager is WindowManagers.KWin: p = util.get_parent_window(window) @@ -38,13 +38,13 @@ def get_geometry(window, window_manager=None): return _get_geometry(util.get_parent_window(window)) def moveresize(win, x=None, y=None, w=None, h=None, window_manager=None): - ''' + """ This function attempts to properly move/resize a window, accounting for its decorations. It doesn't rely upon _NET_FRAME_EXTENTS, but instead, uses the actual parent window to adjust the width and height. - ''' + """ import ewmh if window_manager is WindowManagers.KWin: diff --git a/xpybutil/xinerama.py b/xpybutil/xinerama.py index cb69f8d..67917c6 100644 --- a/xpybutil/xinerama.py +++ b/xpybutil/xinerama.py @@ -9,7 +9,7 @@ def get_monitors(): Returns a list of Xinerama screen rectangles. They come in the order that the Xinerama extension specifies. - @rtype: List of (x, y, w, h) rectangles + :rtype: List of (x, y, w, h) rectangles ''' retval = [] ms = ext.QueryScreens().reply() @@ -23,8 +23,8 @@ def get_physical_mapping(monitors): ''' Returns a list of Xinerama screen indices in their physical order. - @param monitors: List of (x, y, w, h) rectangles - @rtype: List of Xinerama indices + :param monitors: List of (x, y, w, h) rectangles + :rtype: List of Xinerama indices ''' retval = []