diff options
| author | Nick Moore <nicholasvmoore@gmail.com> | 2026-11-07 07:53:41 -0600 |
|---|---|---|
| committer | Nick Moore <nicholasvmoore@gmail.com> | 2026-11-07 07:53:41 -0600 |
| commit | f0bcbef5a603c16ee5639aac7dc79e7714b2d27f (patch) | |
| tree | f897d73edcac85069cb14d4cc82630f22ec24c92 /waybar/.config | |
| parent | fdd75214837275a1fe37ba991e45bd1ae4fa5814 (diff) | |
Add AGENTS.md context files, prune backup/state, restage waybar for stow
- AGENTS.md at repo root + waybar/AGENTS.md component layer
- untrack *.bak and fish_variables (machine-local session state)
- waybar restructured to .config/waybar/ and synced from rigel (laptop wins): sway modules, doom-one style, ppd-glyph.py + wifi-icon.py
Diffstat (limited to 'waybar/.config')
| -rw-r--r-- | waybar/.config/waybar/config.jsonc | 109 | ||||
| -rwxr-xr-x | waybar/.config/waybar/ppd-glyph.py | 92 | ||||
| -rw-r--r-- | waybar/.config/waybar/style.css | 182 | ||||
| -rwxr-xr-x | waybar/.config/waybar/wifi-icon.py | 157 |
4 files changed, 540 insertions, 0 deletions
diff --git a/waybar/.config/waybar/config.jsonc b/waybar/.config/waybar/config.jsonc new file mode 100644 index 0000000..6e03c31 --- /dev/null +++ b/waybar/.config/waybar/config.jsonc @@ -0,0 +1,109 @@ +{ + "layer": "top", + "position": "top", + "height": 36, + "spacing": 2, + "modules-left": [ + "sway/workspaces", + "sway/mode" + ], + "modules-center": [ + "clock#date", + "clock" + ], + "modules-right": [ + "custom/ppd-glyph", + "battery", + "wireplumber", + "network", + "cpu", + "memory", + "tray" + ], + "sway/workspaces": { + "format": "{name}", + "disable-scroll": true, + "on-click": "activate" + }, + "sway/mode": { + "format": " {}" + }, + "clock": { + "format": "{:%H:%M}", + "tooltip-format": "{:%A %d %B %Y}", + "tooltip": true + }, + "clock#date": { + "format": "{:%m-%d}", + "tooltip-format": "{:%A %d %B %Y}", + "tooltip": true + }, + "custom/ppd-glyph": { + // profile glyph left of the battery icon (ppd-glyph.py): leaf on + // power-saver, rocket on performance, nothing (CSS-collapsed) on + // balanced. Persistent JSONP: the script watches ActiveProfile over the + // system D-Bus and prints one line per change; waybar re-renders per + // newline. restart-interval 0 keeps waybar from ever restarting it. + "exec": "/home/nicholas/.config/waybar/ppd-glyph.py", + "return-type": "json", + "restart-interval": 0 + }, + "battery": { + "interval": 30, + "format": "{icon} {capacity}%", + "format-charging": " {capacity}%", + "format-plugged": " {capacity}%", + "format-not-charging": " {capacity}%", + "format-full": " {capacity}%", + "format-warning": " {capacity}%", + "format-critical": " {capacity}%", + "format-icons": [ + "", + "", + "", + "" + ], + "states": { + "warning": 50, + "critical": 25 + } + }, + "wireplumber": { + "format": "{icon} {volume}%", + "format-muted": " {volume}%", + "format-icons": [ + "", + "", + "" + ], + "tooltip-format": "{node_name}", + "on-click": "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle", + "on-scroll-up": "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+", + "on-scroll-down": "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-" + }, + "network": { + "format-wifi": "{icon} {signaldBm} dBm", + "format-ethernet": " {ifname}", + "format-linked": " {ifname}", + "format-disconnected": "", + "format-icons": [ + "", + "", + "", + "" + ], + "tooltip-format": "{ifname} via {gwaddr}" + }, + "cpu": { + "interval": 5, + "format": " {usage}%" + }, + "memory": { + "interval": 5, + "format": " {percentage}%" + }, + "tray": { + "icon-size": 18, + "spacing": 2 + } +} diff --git a/waybar/.config/waybar/ppd-glyph.py b/waybar/.config/waybar/ppd-glyph.py new file mode 100755 index 0000000..0f02bfd --- /dev/null +++ b/waybar/.config/waybar/ppd-glyph.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +"""waybar custom/ppd-glyph — nerd glyph for the active power profile. + +Leaf (power-saver) and rocket (performance) render just left of the battery +module; balanced renders nothing — CSS (#custom-ppd-glyph.balanced) collapses +the node, so the bar reads identically to before on the vanilla profile. + +Persistent JSONP: prints the current profile once, then watches ActiveProfile +on the *system* bus (org.freedesktop.UPower.PowerProfiles) and re-prints one +JSON line per change; waybar re-renders on every newline. No polling: the +gdbus monitor blocks until something changes; the outer loop restarts it on +bus hiccups, same belt-and-brace as ppd-switch.sh. + +Codepoints were verified against the font's own glyph names (Terminess Nerd +Font md-leaf at U+F032B, md-rocket_launch at U+F14DF) — plausible PUA guesses +like U+F0243/U+F083B turned out to be md-flash_auto / md-television_classic +in this font, so the cmap was read (see the opencode session log) rather +than trusted from memory. +""" + +import json +import re +import subprocess +import sys +import time + +DEST = "org.freedesktop.UPower.PowerProfiles" +OBJPATH = "/org/freedesktop/UPower/PowerProfiles" + +GLYPHS = { + "balanced": "", # stock bar: CSS also collapses the node + "power-saver": "\U000f032b", # md-leaf + "performance": "\U000f14df", # md-rocket-launch +} +TOOLTIPS = { + "balanced": "Balanced (auto: flips to power-saver on battery)", + "power-saver": "Power saver (auto: battery mode)", + "performance": "Performance (manual — sticks through plug/unplug)", +} +# gdbus prints property values as (<'balanced'>,) style S-variants; +# monitor also echoes its own startup banner lines, but extra reads are +# silent under the equality gate, so banners are harmless. +PROFILE_RE = re.compile(r"^.*< *'([a-z][a-z-]*)' *>.*$") + + +def active_profile(): + res = subprocess.run( + ["gdbus", "call", "--system", "--dest", DEST, + "--object-path", OBJPATH, + "--method", "org.freedesktop.DBus.Properties.Get", + DEST, "ActiveProfile"], + capture_output=True, text=True, check=False) + m = PROFILE_RE.search(res.stdout) + return m.group(1) if m else None + + +def emit(profile): + if profile is None: + return # ppd mid-restart; wait for the next Property update instead + print(json.dumps({ + "text": GLYPHS.get(profile, ""), + "class": profile, + "tooltip": TOOLTIPS.get(profile, profile), + }), flush=True) + + +def main(): + last = None + while True: + try: + proc = subprocess.Popen( + ["gdbus", "monitor", "--system", "--dest", DEST], + stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True) + for _ in proc.stdout: + cur = active_profile() + if cur != last: + last = cur + emit(cur) + except BrokenPipeError: + return 0 # waybar went away (bar restart/reload); exit quietly + # Anything else (bus blip, monitor SIGSEGV): linger briefly and + # re-loop with a fresh monitor; the equality gate means the bar + # does not re-flash. + try: + proc.terminate() + except Exception: + pass + time.sleep(5) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/waybar/.config/waybar/style.css b/waybar/.config/waybar/style.css new file mode 100644 index 0000000..9b69712 --- /dev/null +++ b/waybar/.config/waybar/style.css @@ -0,0 +1,182 @@ +/* Waybar — doom-one + * bg #282c34 · fg #bbc2cf · blue #51afef · magenta #c678dd + * red #ff6c6b · green #98be65 · yellow #ecbe7b · cyan #46d9ff + * orange #da8548 · violet #a9a1e1 · base3 #3f444a · base5 #5b6268 + */ + +* { + font-family: "Terminess Nerd Font", "Terminess Nerd Font Mono", monospace; + font-size: 15px; + border: none; + border-radius: 0; + min-height: 0; +} + +window#waybar { + background-color: transparent; + border: none; + color: #bbc2cf; +} + +tooltip { + background: #21242b; + border: 1px solid #51afef; + border-radius: 0px; +} + +tooltip label { + color: #bbc2cf; + padding: 4px; +} + +.modules-left, +.modules-center, +.modules-right { + background-color: rgba(40, 44, 52, 0.94); + border: 1px solid #21242b; + border-radius: 0px; + margin: 4px 0; + padding: 0 6px; +} + +.modules-left { + margin-left: 6px; +} + +.modules-right { + margin-right: 6px; +} + +#workspaces, +#mode, +#clock, +#clock.date, +#battery, +#wireplumber, +#network, +#cpu, +#memory, +#tray { + background: transparent; + border: none; + border-radius: 0; + padding: 0 6px; + margin: 0; +} + +#workspaces { + padding: 0; +} + +#workspaces button { + padding: 0 7px; + margin: 4px 2px; + background: transparent; + color: #5b6268; + border-radius: 0px; +} + +#workspaces button.visible { + color: #bbc2cf; +} + +#workspaces button.focused, +#workspaces button.active { + background: #51afef; + color: #282c34; + font-weight: bold; +} + +#workspaces button.urgent { + background: #ff6c6b; + color: #282c34; +} + +#workspaces button:hover { + background: #3f444a; + color: #bbc2cf; +} + +#mode { + background: #da8548; + color: #282c34; + padding: 0 8px; + margin: 4px 2px 4px 6px; + border-radius: 0px; + font-weight: bold; +} + +#clock { + color: #46d9ff; +} + +#clock.date { + color: #a9a1e1; +} + +#battery { + color: #98be65; +} + +#battery.warning { + color: #da8548; +} + +#battery.critical { + color: #ff6c6b; +} + +/* volume widget (wireplumber module): waybar adds both .muted and + * .sink-muted when the sink is muted — style either. */ +#wireplumber { + color: #98be65; +} + +#wireplumber.muted, +#wireplumber.sink-muted { + color: #ff6c6b; +} + +#network { + color: #51afef; +} + +#network.disconnected { + color: #ff6c6b; +} + +#cpu { + color: #da8548; +} + +#memory { + color: #c678dd; +} + +/* ppd profile glyph (ppd-glyph.py): leaf = power-saver, rocket = performance. + * balanced emits an empty label: with padding, min-width and font-size all + * zeroed the module renders zero pixels — note waybar's (GTK-based) CSS + * parser rejects `display: none` as a fatal property error, so the collapse + * must be done the GTK way. */ +#custom-ppd-glyph { + background: transparent; + border: none; + border-radius: 0; + padding: 0; + margin: 0; + min-width: 0; + font-size: 0px; +} + +#custom-ppd-glyph.power-saver, +#custom-ppd-glyph.performance { + font-size: 15px; +} + +#custom-ppd-glyph.power-saver { + color: #98be65; /* green */ +} + +#custom-ppd-glyph.performance { + color: #da8548; /* orange */ +} diff --git a/waybar/.config/waybar/wifi-icon.py b/waybar/.config/waybar/wifi-icon.py new file mode 100755 index 0000000..a39df1a --- /dev/null +++ b/waybar/.config/waybar/wifi-icon.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python3 +"""Print a Nerd Font wifi glyph for the currently associated access point. + +waybar's own {icon} cannot do this. v0.15 turns dBm into a percentage with +a formula that peaks at -45 dBm and then falls off again for *stronger* links, +and it splits that percentage into equal buckets. A great -31 dBm connection +therefore lands in a lower bucket than a mediocre -40 dBm one, so the icon +reads "worse" as you walk towards the router. + +This helper asks nl80211 directly for the associated AP's signal and maps it +onto four glyphs with fixed dBm cut-offs, so the icon rises monotonically with +the link quality. + +Usage: wifi-icon.py [interface] +""" + +import socket +import struct +import sys +import time + +NETLINK_GENERIC = 16 +GENL_ID_CTRL = 16 +NLM_F_REQUEST = 0x001 +NLM_F_DUMP = 0x300 + +NL80211_CMD_GET_SCAN = 32 +NL80211_ATTR_IFINDEX = 3 +NL80211_ATTR_BSS = 47 +NL80211_BSS_SIGNAL_MBM = 7 +NL80211_BSS_STATUS = 9 +NL80211_BSS_STATUS_ASSOCIATED = 1 + +CTRL_CMD_GETFAMILY = 3 +CTRL_ATTR_FAMILY_ID = 1 +CTRL_ATTR_FAMILY_NAME = 2 + +# dBm cut-offs, strongest first. -50 dBm is the usual "excellent" mark, so +# anything from there up (including the -31 dBm you get sitting next to the +# router) shows as full bars. +GLYPHS = ( + (-50, "\U000f0928"), # full + (-60, "\U000f0925"), # good + (-70, "\U000f0922"), # fair + (-90, "\U000f091f"), # weak +) + +TIMEOUT = 2.0 + + +def _attr(atype, payload): + """Build one netlink attribute, padded to a 4 byte boundary.""" + length = 4 + len(payload) + pad = -length % 4 + return struct.pack("=HH", length + pad, atype) + payload + b"\x00" * pad + + +def _parse(data): + """Split a netlink attribute blob into (type, payload) pairs.""" + out = [] + off = 0 + while off + 4 <= len(data): + length, atype = struct.unpack_from("=HH", data, off) + if length < 4: + break + out.append((atype & 0x3FFF, data[off + 4:off + length])) + off += (length + 3) & ~3 + return out + + +def _messages(sock, deadline): + """Yield the payload of every netlink message that arrives in time.""" + while time.monotonic() < deadline: + try: + data = sock.recv(65536) + except socket.timeout: + return + except OSError: + return + off = 0 + while off + 16 <= len(data): + length = struct.unpack_from("=I", data, off)[0] + if length < 16: + break + yield data[off + 16:off + length] + off += (length + 3) & ~3 + + +def _family_id(sock, deadline): + """Ask the kernel for the dynamically assigned 'nl80211' family id.""" + name = _attr(CTRL_ATTR_FAMILY_NAME, b"nl80211\x00") + genl = struct.pack("BBH", CTRL_CMD_GETFAMILY, 0, 0) + payload = genl + name + sock.send(struct.pack("=IHHII", 16 + len(payload), GENL_ID_CTRL, + NLM_F_REQUEST, 1, 0) + payload) + for body in _messages(sock, deadline): + # body is genlmsghdr (4 bytes) followed by the attributes + for atype, payload in _parse(body[4:]): + if atype == CTRL_ATTR_FAMILY_ID: + return struct.unpack("=H", payload[:2])[0] + raise OSError("no nl80211 family id") + + +def _associated_dbm(sock, family, ifindex, deadline): + """Return the signal of the AP we are associated with, in dBm.""" + genl = struct.pack("BBH", NL80211_CMD_GET_SCAN, 0, 0) + attrs = _attr(NL80211_ATTR_IFINDEX, struct.pack("=I", ifindex)) + payload = genl + attrs + sock.send(struct.pack("=IHHII", 16 + len(payload), family, + NLM_F_DUMP, 1, 0) + payload) + for body in _messages(sock, deadline): + for atype, bss in _parse(body[4:]): + if atype != NL80211_ATTR_BSS: + continue + fields = dict(_parse(bss)) + status = fields.get(NL80211_BSS_STATUS) + signal = fields.get(NL80211_BSS_SIGNAL_MBM) + if status is None or signal is None: + continue + if struct.unpack("=I", status)[0] & NL80211_BSS_STATUS_ASSOCIATED: + return struct.unpack("=i", signal)[0] // 100 + return None + + +def main(): + ifname = sys.argv[1] if len(sys.argv) > 1 else "wlan0" + try: + ifindex = socket.if_nametoindex(ifname) + if not ifindex: + return 1 + sock = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, NETLINK_GENERIC) + except OSError: + return 1 + try: + sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1 << 20) + sock.bind((0, 0)) + sock.settimeout(0.5) + deadline = time.monotonic() + TIMEOUT + family = _family_id(sock, deadline) + dbm = _associated_dbm(sock, family, ifindex, deadline) + except (OSError, struct.error): + return 1 + finally: + sock.close() + + if dbm is None: + return 0 + + for threshold, glyph in GLYPHS: + if dbm >= threshold: + print(glyph) + break + return 0 + + +if __name__ == "__main__": + sys.exit(main()) |
