9 from .settings import CACHE_DIR, MODULE_DIR, OS
14 """Load colors in tty."""
15 tty_script = os.path.join(CACHE_DIR, "colors-tty.sh")
16 term = os.environ.get("TERM")
18 if tty_reload and term == "linux":
19 subprocess.Popen(["sh", tty_script])
22 def xrdb(xrdb_files=None):
23 """Merge the colors into the X db so new terminals use them."""
24 xrdb_files = xrdb_files or \
25 [os.path.join(CACHE_DIR, "colors.Xresources")]
27 if shutil.which("xrdb") and OS != "Darwin":
28 for file in xrdb_files:
29 subprocess.run(["xrdb", "-merge", "-quiet", file])
33 """Reload GTK theme on the fly."""
34 # Here we call a Python 2 script to reload the GTK themes.
35 # This is done because the Python 3 GTK/Gdk libraries don't
36 # provide a way of doing this.
37 if shutil.which("python2"):
38 gtk_reload = os.path.join(MODULE_DIR, "scripts", "gtk_reload.py")
39 util.disown(["python2", gtk_reload])
42 logging.warning("GTK2 reload support requires Python 2.")
46 """Reload i3 colors."""
47 if shutil.which("i3-msg") and util.get_pid("i3"):
48 util.disown(["i3-msg", "reload"])
52 """ Reload kitty colors. """
53 if shutil.which("kitty") and util.get_pid("kitty"):
54 util.disown(["kitty", "@", "set-colors", "--all"])
58 """Reload polybar colors."""
59 if shutil.which("polybar") and util.get_pid("polybar"):
60 util.disown(["pkill", "-USR1", "polybar"])
64 """Reload sway colors."""
65 if shutil.which("swaymsg") and util.get_pid("sway"):
66 util.disown(["swaymsg", "reload"])
69 def colors(cache_dir=CACHE_DIR):
70 """Reload colors. (Deprecated)"""
71 sequences = os.path.join(cache_dir, "sequences")
73 logging.error("'wal -r' is deprecated: "
74 "Use 'cat %s' instead.", sequences)
76 if os.path.isfile(sequences):
77 print("".join(util.read_file(sequences)), end="")
80 def env(xrdb_file=None, tty_reload=True):
81 """Reload environment."""
87 logging.info("Reloaded environment.")