Files
nixconfig/modules/home/wayland/apps/eww/bar/scripts/brightness
2026-06-14 12:37:21 +02:00

30 lines
760 B
Bash
Executable File

#!/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
udevadm monitor --udev --subsystem-match=backlight 2>/dev/null | while read -r _; do
gen_output
done
;;
esac