diff --git a/roles/pi_kiosk/templates/kiosk-screen.j2 b/roles/pi_kiosk/templates/kiosk-screen.j2 index 49694f8..57ab83f 100644 --- a/roles/pi_kiosk/templates/kiosk-screen.j2 +++ b/roles/pi_kiosk/templates/kiosk-screen.j2 @@ -11,6 +11,13 @@ # .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 # 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 export DISPLAY=:0 @@ -21,24 +28,30 @@ status() { 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() { xset dpms force on xset -dpms + echo on } screen_off() { xset +dpms xset dpms force off + echo off } case "$1" in on) screen_on ;; off) screen_off ;; - toggle) if [ "$(status)" = off ]; then screen_on; else screen_off; fi ;; - status) ;; + toggle) if switched_off; then screen_on; else screen_off; fi ;; + status) status ;; *) echo "usage: $0 on|off|toggle|status" >&2 exit 2 ;; esac -status