Commit 93a380e

Eric Bower  ·  2026-09-08 10:12:24 -0400 EDT
parent 26af88c
refactor: figbar impl to zig
3 files changed,  +58, -11
+47, -0
 1@@ -0,0 +1,47 @@
 2+#!/usr/bin/env python3
 3+import json
 4+import subprocess
 5+import sys
 6+
 7+def handle_click(event):
 8+    key = event.get("key")
 9+    btn = event.get("button", 1)
10+    if not key:
11+        return
12+
13+    if key.startswith("ws_"):
14+        ws_name = key[3:]
15+        subprocess.run(["swaymsg", "workspace", ws_name], stderr=subprocess.DEVNULL)
16+    elif key == "vol":
17+        if btn == 1:
18+            # Left click: open volume control GUI
19+            subprocess.Popen(["pavucontrol"], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
20+        elif btn in (2, 3):
21+            # Middle/Right click: toggle mute
22+            subprocess.run(["pamixer", "-t"], stderr=subprocess.DEVNULL)
23+        elif btn == 4:
24+            # Scroll up: increase volume
25+            subprocess.run(["pamixer", "-i", "5"], stderr=subprocess.DEVNULL)
26+        elif btn == 5:
27+            # Scroll down: decrease volume
28+            subprocess.run(["pamixer", "-d", "5"], stderr=subprocess.DEVNULL)
29+    elif key == "brt":
30+        if btn == 4:
31+            subprocess.run(["brightnessctl", "set", "5%+"], stderr=subprocess.DEVNULL)
32+        elif btn == 5:
33+            subprocess.run(["brightnessctl", "set", "5%-"], stderr=subprocess.DEVNULL)
34+
35+def main():
36+    for line in sys.stdin:
37+        line = line.strip()
38+        if not line:
39+            continue
40+        try:
41+            event = json.loads(line)
42+            if event.get("event") == "click":
43+                handle_click(event)
44+        except Exception:
45+            pass
46+
47+if __name__ == "__main__":
48+    main()
+10, -10
 1@@ -10,9 +10,9 @@ def get_sound():
 2         muted = subprocess.check_output(["pamixer", "--get-mute"], text=True, stderr=subprocess.DEVNULL).strip() == "true"
 3         vol = subprocess.check_output(["pamixer", "--get-volume"], text=True, stderr=subprocess.DEVNULL).strip()
 4         label = "MUTED" if muted else "VOL"
 5-        return f"{label} {vol}%"
 6+        return f"[[vol]]{label} {vol}%"
 7     except Exception:
 8-        return "VOL ?"
 9+        return "[[vol]]VOL ?"
10 
11 def get_battery():
12     if not os.path.exists("/sys/class/power_supply"):
13@@ -38,7 +38,7 @@ def get_battery():
14                     if f.read().strip() == "Charging":
15                         status = "CHR"
16 
17-            return f"{status} {cap}%"
18+            return f"[[bat]]{status} {cap}%"
19     except Exception:
20         pass
21 
22@@ -48,7 +48,7 @@ def get_brightness():
23     try:
24         act = subprocess.check_output(["brightnessctl", "-c", "backlight", "get"], text=True, stderr=subprocess.DEVNULL).strip()
25         max_b = subprocess.check_output(["brightnessctl", "-c", "backlight", "max"], text=True, stderr=subprocess.DEVNULL).strip()
26-        return f"BRT {int(int(act) * 100 / int(max_b))}%"
27+        return f"[[brt]]BRT {int(int(act) * 100 / int(max_b))}%"
28     except Exception:
29         return None
30 
31@@ -66,20 +66,20 @@ def get_net():
32     try:
33         route = subprocess.check_output(["ip", "route", "show", "default"], text=True, stderr=subprocess.DEVNULL)
34     except Exception:
35-        return "NET Disconnected"
36+        return "[[net]]NET Disconnected"
37 
38     if "dev" not in route:
39-        return "NET Disconnected"
40+        return "[[net]]NET Disconnected"
41 
42     iface = route.split("dev")[1].split()[0]
43     if not iface.startswith(("wl", "wlan")):
44-        return f"ETH {iface}"
45+        return f"[[net]]ETH {iface}"
46 
47     ssid = get_wifi_ssid(iface)
48-    return f"NET {ssid}" if ssid else f"NET {iface}"
49+    return f"[[net]]NET {ssid}" if ssid else f"[[net]]NET {iface}"
50 
51 def get_time():
52-    return time.strftime("%I:%M %m/%d").lstrip("0")
53+    return f"[[time]]{time.strftime('%I:%M %m/%d').lstrip('0')}"
54 
55 def get_workspaces():
56     try:
57@@ -92,7 +92,7 @@ def get_workspaces():
58         return None
59 
60     tags = [
61-        f"^ {w['name']} ^" if w.get("focused") else f" {w['name']} "
62+        f"^[[ws_{w['name']}]] {w['name']} ^" if w.get("focused") else f"[[ws_{w['name']}]] {w['name']} "
63         for w in sorted(workspaces, key=lambda x: x.get("num", 0))
64     ]
65     return "".join(tags)
+1, -1
1@@ -7,7 +7,7 @@ StartLimitBurst=10
2 
3 [Service]
4 Type=simple
5-ExecStart=/bin/sh -c 'python3 %h/.config/sway/figbar_status.py | %h/.local/bin/figbar -b -r -f "JetBrainsMono Nerd Font 10.5" -N 272822 -n f8f8f2 -S 66d9ef -s 272822'
6+ExecStart=/bin/sh -c 'python3 %h/.config/sway/figbar_status.py | %h/.local/bin/figbar -b -r -f "JetBrainsMono Nerd Font 10.5" -N 272822 -n f8f8f2 -S 66d9ef -s 272822 | python3 -u %h/.config/sway/figbar_event.py'
7 Restart=always
8 RestartSec=2s
9