Monday, 15 January 2018

Forcing power saving under my broken DPMS implementation

My monitor, or my X version, or my Xorg drivers, or my KMS kernel, or my xscreensaver version, or my goldfish has a broken DPMS implementation, so that my monitor doesn't turn of when idle. This is a particular waste of energy during the night. Luckily my monitor responds correctly to xset dpms force off when issued twice with a small delay. Using xprintidle-ng, I can work around the problem.

#!/bin/sh
ACTIVATE=$(expr 60 \* 1000 \* 45)  # sleep after 45 mins.
LASTIDLE=0
while sleep 60; do
    IDLE=$(xprintidle-ng)
    if [ "$LASTIDLE" -lt "$ACTIVATE" -a "$IDLE" -ge "$ACTIVATE" ]; then
        xset dpms force off
        sleep 10
        xset dpms force off
    fi
    LASTIDLE="$IDLE"
done