| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #!/usr/bin/env bash
- # Three-state idle inhibitor for waybar (custom/inhibit):
- # off -> normal: swayidle active, wluma adjusting brightness
- # idle -> idle inhibited (wlinhibit running)
- # movie -> idle inhibited AND wluma stopped (brightness held steady)
- # Usage: inhibit.sh [status|cycle]
- SIGNAL=9
- has_wluma() { systemctl --user cat wluma.service >/dev/null 2>&1; }
- inhibiting() { pgrep -x -u "$USER" wlinhibit >/dev/null; }
- wluma_on() { systemctl --user -q is-active wluma.service; }
- state() {
- if ! inhibiting; then
- echo off
- elif has_wluma && ! wluma_on; then
- echo movie
- else
- echo idle
- fi
- }
- inhibit_on() { inhibiting || setsid -f wlinhibit >/dev/null 2>&1; }
- inhibit_off() { pkill -x -u "$USER" wlinhibit; }
- case "${1:-status}" in
- cycle)
- case "$(state)" in
- off)
- inhibit_on
- ;;
- idle)
- if has_wluma; then
- systemctl --user stop wluma.service
- else
- inhibit_off
- fi
- ;;
- movie)
- inhibit_off
- systemctl --user start wluma.service
- ;;
- esac
- sleep 0.2
- pkill -RTMIN+$SIGNAL waybar
- ;;
- status)
- case "$(state)" in
- off) printf '{"text":"","alt":"off","class":"off","tooltip":"Idle inhibitor: OFF"}\n' ;;
- idle) printf '{"text":"","alt":"idle","class":"activated","tooltip":"Idle inhibitor: ON"}\n' ;;
- movie) printf '{"text":"","alt":"movie","class":"movie","tooltip":"Movie mode: idle inhibited, wluma paused"}\n' ;;
- esac
- ;;
- esac
|