diff options
Diffstat (limited to 'dotfiles/hyprland/.local/bin/waybar-airplane')
| -rwxr-xr-x | dotfiles/hyprland/.local/bin/waybar-airplane | 33 |
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 |
