repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

Cache Ironbar workspace watcher state

5bb31c253741382dadc05a6110687549d7a8b5c3

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (1)

+18 / −2 text lines

ironbar/scripts/workspaces-watch.py

Modified

+18 / −2 text lines

28 28 "urgent",
30 30 last_vars: dict[str, str] = {}
31 +color_mtime = 0
32 +color_vars: dict[str, str] = {}
33 +hypr_socket_dir = ""
33 36 def css_vars() -> dict[str, str]:
37 + global color_mtime, color_vars
34 38 config_home = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config"))
39 + path = config_home / "ironbar" / "nugu.css"
40 + mtime = path.stat().st_mtime_ns
41 + if mtime == color_mtime:
42 + return color_vars
35 43 colors: dict[str, str] = {}
36 - for line in (config_home / "ironbar" / "nugu.css").read_text().splitlines():
44 + for line in path.read_text().splitlines():
37 45 if ":" not in line:
38 46 continue
39 47 name, value = line.strip().rstrip(";").split(":", 1)
41 49 value = value.strip()
42 50 if name.startswith("--") and value.startswith("#"):
43 51 colors[name[2:]] = value
52 + color_mtime = mtime
53 + color_vars = colors
44 54 return colors
47 57 def hypr_dir() -> str:
58 + global hypr_socket_dir
59 + if hypr_socket_dir:
60 + return hypr_socket_dir
48 61 sig = os.environ.get("HYPRLAND_INSTANCE_SIGNATURE")
49 62 if not sig:
50 63 result = subprocess.run(("hyprctl", "instances", "-j"), text=True, capture_output=True, check=False)
51 64 instances = json.loads(result.stdout or "[]")
52 65 sig = instances[0]["instance"]
53 - return f"{os.environ['XDG_RUNTIME_DIR']}/hypr/{sig}"
66 + hypr_socket_dir = f"{os.environ['XDG_RUNTIME_DIR']}/hypr/{sig}"
67 + return hypr_socket_dir
56 70 def hypr_cmd(command: str) -> str:
106 120 def watch() -> None:
121 + global hypr_socket_dir
107 122 while True:
108 123 update()
125 140 if line.startswith(EVENT_PREFIXES):
126 141 update()
127 142 except Exception:
143 + hypr_socket_dir = ""
128 144 time.sleep(1)