aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/hyprland/.local/bin/waybar-airplane
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-21 17:48:47 -0400
committerCraig Jennings <c@cjennings.net>2026-05-21 17:48:47 -0400
commite2d3ca987b83a63aa39f7288c3fb7116c3fb0a00 (patch)
tree61e66e49855bcefdb62b00068323f240bf037a5a /dotfiles/hyprland/.local/bin/waybar-airplane
parent9208de9645ad8a5aae16ee0a3e90b4f0dd949e1d (diff)
downloadarchsetup-e2d3ca987b83a63aa39f7288c3fb7116c3fb0a00.tar.gz
archsetup-e2d3ca987b83a63aa39f7288c3fb7116c3fb0a00.zip
feat(hyprland): add airplane-mode waybar toggle
I added a laptop-only waybar button that drops the machine into a low-power state and restores it on a second click. Engaging turns wifi off, sets the CPU energy-performance preference to power, dims the backlight to 35%, and stops network-only services (tailscale, proton-vpn, avahi, cups, wsdd, geoclue, sshd, fail2ban, syncthing). Bluetooth is left alone so earbuds keep working. Disengaging replays the state recorded when airplane mode was engaged rather than writing hardcoded defaults. A lever already in its low-power position is left untouched: wifi that was already off stays off, and a service that was already stopped isn't restarted. The indicator hides itself on machines with no battery, so desktops never show the button. State lives in $XDG_RUNTIME_DIR/airplane-state, and the bar refreshes the moment the toggle fires via a realtime signal.
Diffstat (limited to 'dotfiles/hyprland/.local/bin/waybar-airplane')
-rwxr-xr-xdotfiles/hyprland/.local/bin/waybar-airplane33
1 files changed, 33 insertions, 0 deletions
diff --git a/dotfiles/hyprland/.local/bin/waybar-airplane b/dotfiles/hyprland/.local/bin/waybar-airplane
new file mode 100755
index 0000000..21f869c
--- /dev/null
+++ b/dotfiles/hyprland/.local/bin/waybar-airplane
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Airplane-mode indicator for waybar.
+# Reads the state file the airplane-mode toggle maintains; emits one JSON line
+# (text + tooltip + class) for the custom/airplane module. The file holds
+# key=value lines; only `mode` (on/off) matters here. Anything other than
+# "on" reads as off, so a missing or garbled state file fails safe (airplane
+# mode shown as inactive — i.e. radios assumed on).
+#
+# Laptop-only: airplane mode is meaningless on a desktop, so the module hides
+# itself (emits nothing → waybar drops it) on machines with no battery.
+
+STATE_FILE="${XDG_RUNTIME_DIR:-/tmp}/airplane-state"
+PS_DIR="${AIRPLANE_POWER_SUPPLY_DIR:-/sys/class/power_supply}"
+
+# Laptop check: a battery present means this is a portable machine.
+is_laptop() {
+ for b in "$PS_DIR"/BAT*; do
+ [ -e "$b" ] && return 0
+ done
+ return 1
+}
+
+is_laptop || exit 0
+
+mode=$(sed -n 's/^mode=//p' "$STATE_FILE" 2>/dev/null | head -n1)
+
+# Same clear plane glyph in both states; the class drives the color (gold when
+# engaged, default gray when not) so there's no slash to obscure the wings.
+if [ "$mode" = "on" ]; then
+ echo "{\"text\": \"<span size='large'></span>\", \"tooltip\": \"Airplane mode ON — wifi off, low power\", \"class\": \"active\"}"
+else
+ echo "{\"text\": \"<span size='large'></span>\", \"tooltip\": \"Airplane mode OFF\", \"class\": \"inactive\"}"
+fi