My collection of plugins for the Qtile window manager.
git clone https://mcol.xyz/code/qtools
Log | Files | Refs | README

commit d5f3ad7666c6bcb1db84d651bbcf7429ec798677
parent e4d3b1585cd6accd15c77e0ec167ad55c9913405
Author: mcol <mcol@posteo.net>
Date:   Fri, 10 Jan 2020 18:41:23 +0000

add xresources plugin to query X resources from X server

Diffstat:
Axresources/__init__.py | 1+
Axresources/xresources.py | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/xresources/__init__.py b/xresources/__init__.py @@ -0,0 +1 @@ +from .xresources import get diff --git a/xresources/xresources.py b/xresources/xresources.py @@ -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