foxygit / dotfiles Log in
commit 241914ce68a95a5daaddb08b1d3b36ad3d47d0f6
Author:     mrfox <jens.se@icloud.com>
AuthorDate: Sun Sep 20 21:53:23 2026 +0200
Commit:     mrfox <jens.se@icloud.com>
CommitDate: Sun Sep 20 21:53:23 2026 +0200

    screensaverd: stop the screensaver when DPMS blanks the display

    DPMS blanking (xset dpms, 300s by default) turns the physical panel off
    but doesn't stop X from delivering frames to mapped windows, so the TTE
    screensaver (already running since IDLE_SECONDS=150s, --frame-rate 120)
    just kept animating into a screen nobody could see. On this machine
    that pegged the CPU and kept the fans at 100% for as long as it stayed
    idle -- confirmed live: forcing DPMS off left `tte`/`st` running at
    80-100% CPU with `ps` until killed by hand.

    Added a monitor_off() check (parses `xset q`'s "Monitor is Off/Standby/
    Suspend") alongside the existing is_paused/media_playing guards: it now
    also stops the screensaver when the monitor blanks, not just on real
    input. Verified live with `xset dpms force off`: the daemon kills tte
    and the screensaver window within its 1s poll interval and CPU drops
    back to idle.

    Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
---
 bin/screensaverd | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/bin/screensaverd b/bin/screensaverd
index ec1edf2..e3e4080 100755
--- a/bin/screensaverd
+++ b/bin/screensaverd
@@ -1,6 +1,7 @@
 #!/bin/bash
 # Idle watcher: launches the screensaver after IDLE_SECONDS of inactivity
-# and kills it the moment real activity resumes.
+# and kills it the moment real activity resumes, or the display blanks via
+# DPMS -- whichever comes first.
 set -u

 # sxwm's `exec` runs commands via execvp with whatever PATH the X session
@@ -35,6 +36,15 @@ media_playing() {
   [ "$(playerctl status 2>/dev/null)" = "Playing" ]
 }

+# DPMS blanking (xset dpms, 300s by default -- see ~/.xinitrc) turns the
+# physical display off but doesn't stop X from rendering into windows, so
+# without this the screensaver just kept animating at --frame-rate 120 into
+# a screen nobody can see, burning CPU (and on this machine, spinning the
+# fans at 100%) for as long as the machine stayed idle.
+monitor_off() {
+  xset q 2>/dev/null | grep -q "Monitor is \(Off\|Standby\|Suspend\)"
+}
+
 stop_screensaver() {
   pkill -f "$SCRIPT_DIR/screensaver\$" 2>/dev/null
   pkill -x tte 2>/dev/null
@@ -47,9 +57,9 @@ while true; do
   idle_ms=$(xssstate -i)
   idle_s=$((idle_ms / 1000))

-  if (( idle_s >= IDLE_SECONDS )) && ! is_running && ! media_playing && ! is_paused; then
+  if (( idle_s >= IDLE_SECONDS )) && ! is_running && ! media_playing && ! is_paused && ! monitor_off; then
     "$SCRIPT_DIR/screensaver-launch"
-  elif is_running && { (( idle_s < 1 )) || media_playing || is_paused; }; then
+  elif is_running && { (( idle_s < 1 )) || media_playing || is_paused || monitor_off; }; then
     stop_screensaver
   fi