inhibit.sh 1.8 KB

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