inhibit.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. # Three-state idle inhibitor for waybar (custom/inhibit):
  3. # off -> normal: swayidle active, wluma adjusting brightness
  4. # idle -> idle inhibited (wlinhibit running)
  5. # movie -> idle inhibited AND wluma stopped (brightness held steady)
  6. # Usage: inhibit.sh [status|cycle]
  7. SIGNAL=9
  8. has_wluma() { systemctl --user cat wluma.service >/dev/null 2>&1; }
  9. inhibiting() { pgrep -x -u "$USER" wlinhibit >/dev/null; }
  10. wluma_on() { systemctl --user -q is-active wluma.service; }
  11. state() {
  12. if ! inhibiting; then
  13. echo off
  14. elif has_wluma && ! wluma_on; then
  15. echo movie
  16. else
  17. echo idle
  18. fi
  19. }
  20. inhibit_on() { inhibiting || setsid -f wlinhibit >/dev/null 2>&1; }
  21. inhibit_off() { pkill -x -u "$USER" wlinhibit; }
  22. case "${1:-status}" in
  23. cycle)
  24. case "$(state)" in
  25. off)
  26. inhibit_on
  27. ;;
  28. idle)
  29. if has_wluma; then
  30. systemctl --user stop wluma.service
  31. else
  32. inhibit_off
  33. fi
  34. ;;
  35. movie)
  36. inhibit_off
  37. systemctl --user start wluma.service
  38. ;;
  39. esac
  40. sleep 0.2
  41. pkill -RTMIN+$SIGNAL waybar
  42. ;;
  43. status)
  44. case "$(state)" in
  45. off) printf '{"text":"","alt":"off","class":"off","tooltip":"Idle inhibitor: OFF"}\n' ;;
  46. idle) printf '{"text":"","alt":"idle","class":"activated","tooltip":"Idle inhibitor: ON"}\n' ;;
  47. movie) printf '{"text":"","alt":"movie","class":"movie","tooltip":"Movie mode: idle inhibited, wluma paused"}\n' ;;
  48. esac
  49. ;;
  50. esac