repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

Make Ironbar workspace state instant

07abe51038f21ee8332f7eea66c6d86e315eae20

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (8)

enable_user_services.nu

Modified
15 15 [wezterm-mux-server wezterm-mux-server wezterm-mux-server.service]
16 16 [nugu-theme nu nugu-theme.service]
17 17 [ironbar ironbar ironbar.service]
18 + [ironbar-workspaces python ironbar-workspaces.service]
20 21 $services | each { | service |

hypr/systemd/ironbar-workspaces.service

Added
new file mode 100644
1 +[Unit]
2 +Description=Instant Ironbar workspace state
3 +After=graphical-session.target ironbar.service
4 +PartOf=graphical-session.target
6 +[Service]
7 +ExecStart=%h/.config/ironbar/scripts/workspaces-watch.py
8 +Restart=on-failure
9 +RestartSec=1
10 +Slice=session.slice
12 +[Install]
13 +WantedBy=graphical-session.target

ironbar/PLAN.md

Modified
56 56 - `hyprshutdown` installed; keybind uses `--dry-run`.
57 57 - Music config must use `player_type = "mpris"`, not `playerctl`.
58 58 - Builtin Ironbar workspaces dispatch legacy Hypr syntax; custom switcher is used for Lua-dispatcher compatibility.
59 +- Workspace highlighting is event-driven via Hypr socket2 + Ironbar vars; no polling labels.
60 61 ## Upstream feature note
313 314 - `pipewire-pulse.socket` active.
314 315 - Ironbar logs show volume client connected, no `PAErr(-1)`.
315 316 - `wiremix` spawned into WezTerm mux tab and activated.
317 +- Popup/device picker colors fixed for dark+light Nugu.
318 +- Slider drag verified with `wdotool`: volume changed from 55% to 7%, then restored to 55% and unmuted.
317 320 ### Step 7 — battery — done
581 584 - Each button uses Lua dispatcher syntax:
582 585 - `hyprctl eval 'hl.dispatch(hl.dsp.focus({ workspace = "N" }))'`
583 586 - Added `ironbar/scripts/workspace-label.lua` for active/occupied/empty Nugu-colored labels.
584 -- Workspace label script caches Hypr state in `$XDG_RUNTIME_DIR/ironbar-workspaces.cache` to avoid repeated `hyprctl` calls from six labels.
587 +- Replaced polling workspace label script with `ironbar/scripts/workspaces-watch.py`.
588 +- Watcher listens to Hypr socket2 and writes Ironbar vars (`#ws1`, `#ws2`, ...), making highlight update immediately on switch.
589 +- Added `hypr/systemd/ironbar-workspaces.service`, symlink manifest entry, and service enable recipe.
590 +- Removed old polling `ironbar/scripts/workspace-label.lua`.
585 591 - Removed unused builtin `.workspaces` CSS.
586 592 - Removed launcher underline styling after screenshot showed it clashed with the active workspace/focused launcher pills.
587 593 - Increased system-module spacing slightly; verified clock/power still fit on 1366px.
593 599 - Hypr reload ok; no config errors.
594 600 - Existing named `web`/`term` windows moved to numeric `1`/`3`.
595 601 - All six icons visible; no tofu/question mark glyphs.
596 -- Empty workspace active-state update verified after 2s poll interval.
597 -- Ironbar CPU checked after cache optimization: ~2.4% averaged shortly after restart on X230.
602 +- Empty workspace active-state update verified 0.2s after click.
603 +- Service active and low overhead: `ironbar` ~1.8% CPU shortly after restart, watcher ~0.2% CPU / 6.6M RSS on X230.
598 604 - Clicks verified via `wdotool`:
599 605 - workspace `1` focuses `id=1`
600 606 - empty workspace `2` focuses `id=2`
606 612 Start:
608 614 1. workspaces
609 -2. launcher
610 -3. focused window
611 -4. bindmode
615 +2. bindmode
617 +Removed:
619 +- focused window module; active app/title was redundant and made the left side noisy.
620 +- launcher module; colorful app icons broke the semantic Nugu bar aesthetic.
613 622 Center:
615 624 1. media/player
616 -2. cute cat
625 +2. clock
627 636 8. brightness
628 637 9. battery
629 638 10. inhibit
630 -11. clock
631 -12. power menu
639 +11. power menu
633 641 ## Open decisions

ironbar/config.json

Modified
17 17 "type": "button",
18 18 "class": "workspace-item",
19 - "label": "{{2000:lua ~/.config/ironbar/scripts/workspace-label.lua 1 󰖟}}",
19 + "label": "#ws1",
20 20 "on_click": "!hyprctl eval 'hl.dispatch(hl.dsp.focus({ workspace = \"1\" }))'"
23 23 "type": "button",
24 24 "class": "workspace-item",
25 - "label": "{{2000:lua ~/.config/ironbar/scripts/workspace-label.lua 2 󰅨}}",
25 + "label": "#ws2",
26 26 "on_click": "!hyprctl eval 'hl.dispatch(hl.dsp.focus({ workspace = \"2\" }))'"
29 29 "type": "button",
30 30 "class": "workspace-item",
31 - "label": "{{2000:lua ~/.config/ironbar/scripts/workspace-label.lua 3 󰆍}}",
31 + "label": "#ws3",
32 32 "on_click": "!hyprctl eval 'hl.dispatch(hl.dsp.focus({ workspace = \"3\" }))'"
35 35 "type": "button",
36 36 "class": "workspace-item",
37 - "label": "{{2000:lua ~/.config/ironbar/scripts/workspace-label.lua 4 󰭹}}",
37 + "label": "#ws4",
38 38 "on_click": "!hyprctl eval 'hl.dispatch(hl.dsp.focus({ workspace = \"4\" }))'"
41 41 "type": "button",
42 42 "class": "workspace-item",
43 - "label": "{{2000:lua ~/.config/ironbar/scripts/workspace-label.lua 5 󰎆}}",
43 + "label": "#ws5",
44 44 "on_click": "!hyprctl eval 'hl.dispatch(hl.dsp.focus({ workspace = \"5\" }))'"
47 47 "type": "button",
48 48 "class": "workspace-item",
49 - "label": "{{2000:lua ~/.config/ironbar/scripts/workspace-label.lua 9 󰉋}}",
49 + "label": "#ws9",
50 50 "on_click": "!hyprctl eval 'hl.dispatch(hl.dsp.focus({ workspace = \"9\" }))'"
55 55 "tooltip": "Workspaces: web code term chat media misc"
57 - {
58 - "type": "launcher",
59 - "icon_size": 16,
60 - "truncate": {
61 - "mode": "end",
62 - "max_length": 24
63 - }
64 - },
65 - {
66 - "type": "focused",
67 - "icon_size": 16,
68 - "truncate": {
69 - "mode": "end",
70 - "max_length": 18
71 - }
72 - },
74 58 "type": "bindmode",
75 59 "truncate": {
87 71 "mode": "end",
88 72 "max_length": 42
74 + },
75 + {
76 + "type": "clock",
77 + "format": "%H:%M"
92 80 "end": [
194 182 "format_off": "󰛊 {duration}",
195 183 "tooltip": "Inhibit: left toggles, right cycles duration"
197 - {
198 - "type": "clock",
199 - "format": "%H:%M"
200 - },
202 186 "type": "custom",
203 187 "name": "power-menu",

ironbar/scripts/workspace-label.lua

Deleted
deleted file mode 100755
1 -#!/usr/bin/env lua
3 -local id = tostring(arg[1] or "")
4 -local icon = arg[2] or id
6 -local home = os.getenv("HOME") or "/home/oli"
7 -local config_home = os.getenv("XDG_CONFIG_HOME") or (home .. "/.config")
8 -local runtime_dir = os.getenv("XDG_RUNTIME_DIR") or "/tmp"
9 -local css_path = config_home .. "/ironbar/nugu.css"
10 -local cache_path = runtime_dir .. "/ironbar-workspaces.cache"
11 -local cache_ttl = 1.8
13 -local vars = {}
14 -for line in io.lines(css_path) do
15 - local name, value = line:match("%s*%-%-([%w%-]+):%s*(#[%x]+)")
16 - if name and value then
17 - vars[name] = value
18 - end
19 -end
21 -local function read_file(path)
22 - local file = io.open(path, "r")
23 - if not file then return nil end
24 - local data = file:read("*a")
25 - file:close()
26 - return data
27 -end
29 -local function now()
30 - local uptime = read_file("/proc/uptime") or "0"
31 - return tonumber(uptime:match("^%d+%.?%d*")) or os.time()
32 -end
34 -local function sh(cmd)
35 - local handle = io.popen(cmd .. " 2>/dev/null")
36 - if not handle then return "" end
37 - local out = handle:read("*a") or ""
38 - handle:close()
39 - return out
40 -end
42 -local function pango_escape(s)
43 - return tostring(s)
44 - :gsub("&", "&amp;")
45 - :gsub("<", "&lt;")
46 - :gsub(">", "&gt;")
47 -end
49 -local function parse_cache(data)
50 - if not data or data == "" then return nil end
51 - local state = { windows = {} }
52 - for line in data:gmatch("[^\n]+") do
53 - local key, value = line:match("^([^=]+)=(.*)$")
54 - if key == "timestamp" then
55 - state.timestamp = tonumber(value)
56 - elseif key == "active" then
57 - state.active_id = value
58 - elseif key and key:match("^ws%-?%d+$") then
59 - state.windows[key:gsub("^ws", "")] = tonumber(value) or 0
60 - end
61 - end
62 - if not state.timestamp or not state.active_id then return nil end
63 - return state
64 -end
66 -local function current_state()
67 - local cached = parse_cache(read_file(cache_path))
68 - local t = now()
69 - if cached and (t - cached.timestamp) < cache_ttl then
70 - return cached
71 - end
73 - local state = { timestamp = t, active_id = nil, windows = {} }
74 - state.active_id = sh("hyprctl activeworkspace -j"):match('"id"%s*:%s*(-?%d+)') or ""
76 - for object in sh("hyprctl workspaces -j"):gmatch("%b{}") do
77 - local ws_id = object:match('"id"%s*:%s*(-?%d+)')
78 - if ws_id then
79 - state.windows[ws_id] = tonumber(object:match('"windows"%s*:%s*(%d+)') or "0") or 0
80 - end
81 - end
83 - local tmp = string.format("%s.%d", cache_path, os.time())
84 - local file = io.open(tmp, "w")
85 - if file then
86 - file:write("timestamp=", string.format("%.3f", state.timestamp), "\n")
87 - file:write("active=", state.active_id, "\n")
88 - for ws_id, windows in pairs(state.windows) do
89 - file:write("ws", ws_id, "=", tostring(windows), "\n")
90 - end
91 - file:close()
92 - os.rename(tmp, cache_path)
93 - end
95 - return state
96 -end
98 -local state = current_state()
99 -local windows = state.windows[id] or 0
100 -icon = pango_escape(icon)
102 -if state.active_id == id then
103 - print(string.format(
104 - '<span foreground="%s" background="%s" font_weight="bold"> %s </span>',
105 - vars["on-focus"] or "#121212",
106 - vars.focus or "#9aabae",
107 - icon
108 - ))
109 -elseif windows > 0 then
110 - print(string.format('<span foreground="%s">%s</span>', vars.fg or "#dbdbdb", icon))
111 -else
112 - print(string.format('<span foreground="%s">%s</span>', vars.muted or "#9d9d9d", icon))
113 -end

ironbar/scripts/workspaces-watch.py

Added
new file mode 100755
1 +#!/usr/bin/env python3
3 +import json
4 +import os
5 +import select
6 +import socket
7 +import subprocess
8 +import time
9 +from pathlib import Path
11 +WORKSPACES = [
12 + ("1", "󰖟"),
13 + ("2", "󰅨"),
14 + ("3", "󰆍"),
15 + ("4", "󰭹"),
16 + ("5", "󰎆"),
17 + ("9", "󰉋"),
19 +EVENT_PREFIXES = (
20 + "workspace",
21 + "focusedmon",
22 + "createworkspace",
23 + "destroyworkspace",
24 + "moveworkspace",
25 + "openwindow",
26 + "closewindow",
27 + "movewindow",
28 + "urgent",
32 +def run(*args: str) -> str:
33 + return subprocess.run(args, text=True, capture_output=True, check=False).stdout
36 +def css_vars() -> dict[str, str]:
37 + config_home = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config"))
38 + colors: dict[str, str] = {}
39 + for line in (config_home / "ironbar" / "nugu.css").read_text().splitlines():
40 + if ":" not in line:
41 + continue
42 + name, value = line.strip().rstrip(";").split(":", 1)
43 + name = name.strip()
44 + value = value.strip()
45 + if name.startswith("--") and value.startswith("#"):
46 + colors[name[2:]] = value
47 + return colors
50 +def markup(ws_id: str, icon: str, active: str, occupied: set[str], colors: dict[str, str]) -> str:
51 + if ws_id == active:
52 + return '<span foreground="{}" background="{}" font_weight="bold"> {} </span>'.format(
53 + colors.get("on-focus", "#121212"),
54 + colors.get("focus", "#9aabae"),
55 + icon,
56 + )
57 + if ws_id in occupied:
58 + return '<span foreground="{}">{}</span>'.format(colors.get("fg", "#dbdbdb"), icon)
59 + return '<span foreground="{}">{}</span>'.format(colors.get("muted", "#9d9d9d"), icon)
62 +def hypr_state() -> tuple[str, set[str]]:
63 + active = json.loads(run("hyprctl", "activeworkspace", "-j") or "{}")
64 + workspaces = json.loads(run("hyprctl", "workspaces", "-j") or "[]")
65 + return str(active.get("id", "")), {str(ws.get("id")) for ws in workspaces if ws.get("windows", 0) > 0}
68 +def set_var(name: str, value: str) -> None:
69 + subprocess.run(("ironbar", "var", "set", name, value), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False)
72 +def update() -> None:
73 + colors = css_vars()
74 + active, occupied = hypr_state()
75 + for ws_id, icon in WORKSPACES:
76 + set_var(f"ws{ws_id}", markup(ws_id, icon, active, occupied, colors))
79 +def socket_path() -> str:
80 + sig = os.environ.get("HYPRLAND_INSTANCE_SIGNATURE")
81 + if not sig:
82 + instances = json.loads(run("hyprctl", "instances", "-j") or "[]")
83 + sig = instances[0]["instance"]
84 + return f"{os.environ['XDG_RUNTIME_DIR']}/hypr/{sig}/.socket2.sock"
87 +def watch() -> None:
88 + while True:
89 + update()
90 + try:
91 + with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
92 + sock.connect(socket_path())
93 + pending = b""
94 + while True:
95 + ready, _, _ = select.select([sock], [], [], 5)
96 + if not ready:
97 + update()
98 + continue
99 + chunk = sock.recv(4096)
100 + if not chunk:
101 + break
102 + pending += chunk
103 + while b"\n" in pending:
104 + raw, pending = pending.split(b"\n", 1)
105 + line = raw.decode("utf-8", "replace")
106 + if line.startswith(EVENT_PREFIXES):
107 + update()
108 + except Exception:
109 + time.sleep(1)
112 +if __name__ == "__main__":
113 + watch()

ironbar/style.css

Modified
62 62 color: var(--on-focus);
65 -.launcher .item {
66 - min-height: 0;
67 - margin: 0 2px;
68 - padding: 0 5px;
71 -.launcher image,
72 -.focused image {
73 - -gtk-icon-size: 16px;
76 -.launcher .item.open {
77 - color: var(--fg);
80 -.launcher .item.focused {
81 - color: var(--on-focus);
82 - background: var(--focus);
85 -.launcher .item.focused label {
86 - color: var(--on-focus);
89 -.popup-launcher {
90 - padding: 8px;
93 -.popup-launcher .popup-item {
94 - padding: 8px 12px;
95 - border-radius: var(--radius);
98 -.popup-launcher .popup-item:hover {
99 - background-color: var(--surface);
102 -.focused {
103 - color: var(--focus);
104 - margin-left: 12px;
107 65 .bindmode {
108 66 margin-left: 8px;
109 67 padding: 1px 7px;
129 87 .popup-volume {
130 88 padding: 12px;
89 + background-color: var(--bg-transparent);
90 + color: var(--fg);
93 +.popup-volume .device-box,
94 +.popup-volume .apps-box {
95 + background-color: transparent;
96 + color: var(--fg);
99 +.popup-volume .device-selector,
100 +.popup-volume .device-selector button,
101 +.popup-volume dropdown,
102 +.popup-volume dropdown button {
103 + background: var(--accent);
104 + color: var(--on-focus);
105 + border-radius: var(--radius);
108 +.popup-volume .device-selector label,
109 +.popup-volume .device-selector arrow,
110 +.popup-volume .device-selector *,
111 +.popup-volume dropdown button,
112 +.popup-volume dropdown button * {
113 + background: transparent;
114 + color: var(--on-focus);
117 +.popup-volume .btn-mute {
118 + color: var(--fg);
121 +.popup-volume .btn-mute:hover,
122 +.popup-volume .btn-mute:checked {
123 + background: var(--focus);
124 + color: var(--on-focus);
127 +popover listview,
128 +popover list,
129 +popover row,
130 +popover modelbutton {
131 + background-color: var(--bg);
132 + color: var(--fg);
135 +popover listview row,
136 +popover list row {
137 + padding: 6px 10px;
140 +popover listview row label,
141 +popover list row label,
142 +popover row label,
143 +popover modelbutton label {
144 + color: var(--fg);
147 +popover listview row:hover,
148 +popover list row:hover,
149 +popover row:hover,
150 +popover modelbutton:hover {
151 + background-color: var(--unfocus);
152 + color: var(--fg);
155 +popover listview row:hover label,
156 +popover list row:hover label,
157 +popover row:hover label,
158 +popover modelbutton:hover label {
159 + color: var(--fg);
162 +popover listview row:selected,
163 +popover list row:selected,
164 +popover row:selected,
165 +popover modelbutton:checked {
166 + background-color: var(--focus);
167 + color: var(--on-focus);
170 +popover listview row:selected label,
171 +popover list row:selected label,
172 +popover row:selected label,
173 +popover modelbutton:checked label {
174 + color: var(--on-focus);
177 +/* GTK dropdown popovers are separate popovers, not children of .popup-volume. */
178 +popover contents listview,
179 +popover contents list,
180 +popover contents row,
181 +popover contents modelbutton,
182 +popover contents button {
183 + background: var(--bg);
184 + color: var(--fg);
187 +popover contents row *,
188 +popover contents modelbutton *,
189 +popover contents button * {
190 + color: var(--fg);
193 +popover contents row:hover,
194 +popover contents modelbutton:hover,
195 +popover contents button:hover {
196 + background: var(--unfocus);
197 + color: var(--fg);
200 +popover contents row:hover *,
201 +popover contents modelbutton:hover *,
202 +popover contents button:hover * {
203 + color: var(--fg);
206 +popover contents row:selected,
207 +popover contents modelbutton:checked,
208 +popover contents button:checked {
209 + background: var(--focus);
210 + color: var(--on-focus);
213 +popover contents row:selected *,
214 +popover contents modelbutton:checked *,
215 +popover contents button:checked * {
216 + color: var(--on-focus);
219 +.popup-volume dropdown popover,
220 +.popup-volume dropdown popover contents,
221 +.popup-volume dropdown popover listview,
222 +.popup-volume dropdown popover row {
223 + background: var(--bg);
224 + color: var(--fg);
227 +.popup-volume dropdown popover label,
228 +.popup-volume dropdown popover row *,
229 +.popup-volume dropdown popover listview * {
230 + color: var(--fg);
233 +.popup-volume dropdown popover row:hover {
234 + background: var(--unfocus);
237 +.popup-volume dropdown popover row:selected {
238 + background: var(--accent);
241 +.popup-volume dropdown popover row:selected * {
242 + color: var(--on-focus);
245 +scale trough {
246 + min-height: 6px;
247 + min-width: 6px;
248 + background-color: var(--unfocus);
249 + border-radius: var(--radius);
133 252 scale highlight {
253 + min-height: 6px;
254 + min-width: 6px;
134 255 background-color: var(--accent);
135 256 border-radius: var(--radius);

x230.symlinks

Modified
106 106 hypr/systemd/ironbar.service
107 107 ~/.config/systemd/user/ironbar.service
109 +hypr/systemd/ironbar-workspaces.service
110 +~/.config/systemd/user/ironbar-workspaces.service
109 112 wezterm/systemd/wezterm-mux-server.service
110 113 ~/.config/systemd/user/wezterm-mux-server.service