Skip to content

Commit

Permalink
[core/theme] add xresources support
Browse files Browse the repository at this point in the history
add support for reading foreground and background, and colors, from
xresources.py

many thanks to @Aliuakbar for the addition!

fixes #731
  • Loading branch information
tobi-wan-kenobi committed Dec 7, 2020
1 parent 13b0679 commit fa66873
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 11 additions & 2 deletions bumblebee_status/core/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import core.event
import util.algorithm
import util.xresources

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -89,13 +90,21 @@ def load_keywords(self, name):
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)

Expand Down
10 changes: 10 additions & 0 deletions bumblebee_status/util/xresources.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit fa66873

Please sign in to comment.