add quick actions tab

This commit is contained in:
soraefir
2026-06-13 14:04:33 +02:00
parent 43a074f355
commit 6117dca845
10 changed files with 198 additions and 37 deletions

View File

@@ -0,0 +1,28 @@
#!/usr/bin/env bash
BACKLIGHT="/sys/class/backlight"
DEV=$(ls "$BACKLIGHT" 2>/dev/null | head -n1)
gen_output() {
if [ -z "$DEV" ]; then
echo '{"percent":0,"available":false}'
return
fi
max=$(cat "$BACKLIGHT/$DEV/max_brightness")
cur=$(cat "$BACKLIGHT/$DEV/actual_brightness" 2>/dev/null || cat "$BACKLIGHT/$DEV/brightness")
percent=$(awk -v c="$cur" -v m="$max" 'BEGIN{print int(c/m*100+0.5)}')
printf '{"percent":%d,"available":true}\n' "$percent"
}
case "$1" in
set)
[ -z "$DEV" ] && exit 0
brightnessctl -d "$DEV" set "${2}%" -q 2>/dev/null
;;
*)
gen_output
[ -z "$DEV" ] && exit 0
# Poll for changes every 2s (sysfs files don't support inotify reliably)
while true; do sleep 2; gen_output; done
;;
esac