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

-rw-r--r-- qtools/xresources/xresources.py


      1 """
      2 Qtile helper to get X resources from the root window.
      3 """
      4 
      5 
      6 import os
      7 
      8 import xcffib
      9 import xcffib.xproto
     10 from libqtile.log_utils import logger
     11 
     12 
     13 def get(DISPLAY=None, defaults=None):
     14     """
     15     Get the X resources in an X servers resource manager.
     16 
     17     Parameters
     18     ==========
     19     DISPLAY : str (optional)
     20         DISPLAY name to query. This will be taken from the environment if not specified.
     21 
     22     defaults : dict (optional)
     23         Default values to act as a fallback for missing values or in the event of a
     24         failed connection.
     25 
     26     Returns
     27     =======
     28     resources: dict
     29         Dictionary containing all (available) X resources. Resources that are specified
     30         in an Xresources/Xdefaults file as wildcards e.g. '*.color1' have the leading
     31         '*.' stripped.
     32 
     33     """
     34     if DISPLAY is None:
     35         DISPLAY = os.environ.get("DISPLAY")
     36 
     37     if defaults is None:
     38         resources = {}
     39     else:
     40         resources = defaults
     41 
     42     try:
     43         conn = xcffib.connect(display=DISPLAY)
     44     except xcffib.ConnectionException as e:
     45         logger.exception(e)
     46         return resources
     47 
     48     root = conn.get_setup().roots[0].root
     49     atom = conn.core.InternAtom(False, 16, 'RESOURCE_MANAGER').reply().atom
     50 
     51     reply = conn.core.GetProperty(
     52         False, root, atom,
     53         xcffib.xproto.Atom.STRING,
     54         0, (2 ** 32) - 1
     55     ).reply()
     56     conn.disconnect()
     57 
     58     resource_string = reply.value.buf().decode("utf-8")
     59     resource_list = filter(None, resource_string.split('\n'))
     60 
     61     for resource in resource_list:
     62         key, value = resource.split(':\t')
     63         resources[key.strip('*.')] = value
     64 
     65     return resources
     66