From e2d3ca987b83a63aa39f7288c3fb7116c3fb0a00 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 21 May 2026 17:48:47 -0400 Subject: 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. --- dotfiles/hyprland/.local/bin/waybar-airplane | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 dotfiles/hyprland/.local/bin/waybar-airplane (limited to 'dotfiles/hyprland/.local/bin/waybar-airplane') 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\": \"\", \"tooltip\": \"Airplane mode ON — wifi off, low power\", \"class\": \"active\"}" +else + echo "{\"text\": \"\", \"tooltip\": \"Airplane mode OFF\", \"class\": \"inactive\"}" +fi -- cgit v1.2.3