#!/bin/sh # Managed by ansible (pi_kiosk role). # # kiosk-screen on|off|toggle|status - switch the kiosk's monitor on or off. # # "Off" is DPMS: X stops the HDMI signal and the monitor drops into standby. The # session, the browser and everything playing carry on. The MusicMouse backend runs # `kiosk-screen toggle` for the IR remote's power key (its config's screen: section); # it works over ssh as root too. # # .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 export XAUTHORITY=/home/{{ pi_kiosk_user }}/.Xauthority # With DPMS disabled `xset q` prints no monitor line at all, and the monitor is on. 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 switched_off; then screen_on; else screen_off; fi ;; status) status ;; *) echo "usage: $0 on|off|toggle|status" >&2 exit 2 ;; esac