From fa668735822f9e2b3054a38b661c905243016d77 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Mon, 7 Dec 2020 08:59:56 +0100 Subject: [PATCH] [core/theme] add xresources support add support for reading foreground and background, and colors, from xresources.py many thanks to @Aliuakbar for the addition! fixes #731 --- bumblebee_status/core/theme.py | 13 +++++++++++-- bumblebee_status/util/xresources.py | 10 ++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 bumblebee_status/util/xresources.py diff --git a/bumblebee_status/core/theme.py b/bumblebee_status/core/theme.py index b52c465..800bd66 100644 --- a/bumblebee_status/core/theme.py +++ b/bumblebee_status/core/theme.py @@ -7,6 +7,7 @@ import glob import core.event import util.algorithm +import util.xresources log = logging.getLogger(__name__) @@ -89,13 +90,21 @@ class Theme(object): try: if isinstance(name, dict): return name + + result = {} if name.lower() == "wal": wal = self.__load_json("~/.cache/wal/colors.json") - result = {} for field in ["special", "colors"]: for key in wal.get(field, {}): result[key] = wal[field][key] - return result + if name.lower() == "xresources": + for key in ("background", "foreground"): + result[key] = xresources.query(key) + for i in range(16): + key = color + str(i) + result[key] = xresources.query(key) + + return result except Exception as e: log.error("failed to load colors: {}", e) diff --git a/bumblebee_status/util/xresources.py b/bumblebee_status/util/xresources.py new file mode 100644 index 0000000..70665a9 --- /dev/null +++ b/bumblebee_status/util/xresources.py @@ -0,0 +1,10 @@ +import subprocess +import shutil + +def query(key): + if shutil.which("xgetres"): + return subprocess.run(["xgetres", key], + capture_output=True).stdout.decode("utf-8").strip() + else: + raise Exception("xgetres must be installed for this theme") +