An (outdated) collection of plugins for Qtile.
git clone https://github.com/m-col/qtools
Files | Refs | Readme

Commit d5f3ad7666c6bcb1db84d651bbcf7429ec798677
Parent: e4d3b1585cd6accd15c77e0ec167ad55c9913405
Author: mcol <mcol@posteo.net>
Date: 2020-01-10 18:41:23 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2020-01-10 18:41:23 +0000

add xresources plugin to query X resources from X server

xresources/xresources.py Added

@@ -0,0 +1,54 @@
+"""
+Qtile helper to get X resources from the root window.
+"""
+
+
+import xcffib
+import xcffib.xproto
+
+
+def get(DISPLAY, defaults={}):
+    """
+    Get the X resources in an X servers resource manager.
+
+    Parameters
+    ==========
+    DISPLAY : str
+        DISPLAY name to query.
+    
+    defaults : dict (optional)
+        Default values to act as a fallback for missing values or in the event of a
+        failed connection.
+
+    Returns
+    =======
+    resources: dict
+        Dictionary containing all (available) X resources. Resources that are specified
+        in an Xresources/Xdefaults file as wildcards e.g. '*.color1' have the leading
+        '*.' stripped.
+
+    """
+    try:
+        conn = xcffib.connect(display=DISPLAY)
+    except xcffib.ConnectionException:
+        return defaults
+
+    root = conn.get_setup().roots[0].root
+    atom = conn.core.InternAtom(False, 16, 'RESOURCE_MANAGER').reply().atom
+
+    reply = conn.core.GetProperty(
+        False, root, atom,
+        xcffib.xproto.Atom.STRING,
+        0, (2 ** 32) - 1
+    ).reply()
+    conn.disconnect()
+
+    resource_string = reply.value.buf().decode("utf-8")
+    resource_list = filter(None, resource_string.split('\n'))
+    resources = {}
+
+    for resource in resource_list:
+        key, value = resource.split(':\t')
+        resources[key.strip('*.')] = value
+
+    return resources

xresources/__init__.py Added

@@ -0,0 +1 @@
+from .xresources import get