kiosk-screen: toggle by DPMS state, and print the state it set
X wakes the monitor on any key press, so by the time the Del key reaches the backend the monitor is already on and a toggle going by the monitor would switch it straight back off. Only `off` ever enables DPMS, so toggle goes by that instead. on/off now print the state they set, which the backend uses for its blubb's direction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,13 @@
|
|||||||
# .xinitrc turns DPMS off so the screen never blanks by itself. Forcing it off has to
|
# .xinitrc turns DPMS off so the screen never blanks by itself. Forcing it off has to
|
||||||
# turn DPMS on, so `on` turns it back off again - otherwise the screen would blank on
|
# turn DPMS on, so `on` turns it back off again - otherwise the screen would blank on
|
||||||
# its own ten minutes after every switch-on.
|
# its own ten minutes after every switch-on.
|
||||||
|
#
|
||||||
|
# `toggle` therefore goes by whether DPMS is enabled, not by whether the monitor is lit:
|
||||||
|
# only `off` ever enables it. That matters for the keyboard. X wakes the monitor on any
|
||||||
|
# key press, so by the time the browser hands the Del key to the backend the monitor is
|
||||||
|
# already on again - going by that, toggle would switch it straight back off. Going by
|
||||||
|
# DPMS, the press reads as "switch on", which is what it was. (Woken by any other key,
|
||||||
|
# the screen stays on until the next toggle, which then makes the "on" stick.)
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
export DISPLAY=:0
|
export DISPLAY=:0
|
||||||
@@ -21,24 +28,30 @@ status() {
|
|||||||
if xset q | grep -q "Monitor is Off"; then echo off; else echo on; fi
|
if xset q | grep -q "Monitor is Off"; then echo off; else echo on; fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switched_off() {
|
||||||
|
xset q | grep -q "DPMS is Enabled"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Each prints the state it set: the backend picks the blubb's direction from that word.
|
||||||
screen_on() {
|
screen_on() {
|
||||||
xset dpms force on
|
xset dpms force on
|
||||||
xset -dpms
|
xset -dpms
|
||||||
|
echo on
|
||||||
}
|
}
|
||||||
|
|
||||||
screen_off() {
|
screen_off() {
|
||||||
xset +dpms
|
xset +dpms
|
||||||
xset dpms force off
|
xset dpms force off
|
||||||
|
echo off
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
on) screen_on ;;
|
on) screen_on ;;
|
||||||
off) screen_off ;;
|
off) screen_off ;;
|
||||||
toggle) if [ "$(status)" = off ]; then screen_on; else screen_off; fi ;;
|
toggle) if switched_off; then screen_on; else screen_off; fi ;;
|
||||||
status) ;;
|
status) status ;;
|
||||||
*)
|
*)
|
||||||
echo "usage: $0 on|off|toggle|status" >&2
|
echo "usage: $0 on|off|toggle|status" >&2
|
||||||
exit 2
|
exit 2
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
status
|
|
||||||
|
|||||||
Reference in New Issue
Block a user