Running XScreenSaver on a laptop? Let’s run cool…

For most people these days, screensavers have died off.

XScreenSaver Settings on Debian 12
XScreenSaver Settings on Debian 12

I still like having them. And while most people have moved on from X.Org on Linux, well… here we are.

The 5300U in my ThinkPad has more than enough GPU power to display some beautiful screensavers. But by default, the system will ramp up into a higher performance state — because normally, that’s exactly what you’d want. Like if you were playing a game, or trying to load some bloated modern website.

But my idle laptop? I don’t want it getting all hot while it’s sitting on my lap or on the bed, just because it’s running a screensaver. So this is my little attempt to fix that — and it’s looking pretty promising.

The idea:

When XScreenSaver runs one of its screen hacks (screensavers), we’ll put the CPU into its lowest available frequency. That way, even when running hardware-accelerated 3D, the system will stay nice and cool.

Fortunately, the author of XScreenSaver — Jamie Zawinski — is a pretty smart dude, and the software already includes a clean little mechanism we can hook into to make this work.

Here’s how I’ve got it set up:

Create a script in your home folder, or wherever you want. xscreensaver_freq_watch.sh

#!/bin/bash

# Save current CPU and GPU max frequencies
CPU_MAX_BEFORE=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq)
GPU_MAX_BEFORE=$(cat /sys/class/drm/card0/gt_max_freq_mhz)

# Watch xscreensaver events
xscreensaver-command -watch | while read -r line
do
case “$line” in
LOCK*)
# Optional: do something on screen lock
;;
UNBLANK*)
echo “Screensaver stopped — restoring frequencies…”
echo $CPU_MAX_BEFORE | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq > /dev/null
echo $GPU_MAX_BEFORE | sudo tee /sys/class/drm/card0/gt_max_freq_mhz > /dev/null
;;
BLANK*)
echo “Screensaver started — limiting frequencies…”
echo 500000 | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq > /dev/null
echo 300 | sudo tee /sys/class/drm/card0/gt_max_freq_mhz > /dev/null
;;
esac
done

Of course, make it exactable with chmod +x. Also, use nopasswd in your /etc/sudoers line for your user.

Now because I’m using MATE / LightDM, I’m going to use a .desktop file. You could do something else, .xinitrc or a systemd service, but this is how I did it.

mkdir -p ~/.config/autostart
nano ~/.config/autostart/screensaver-watch.desktop

And inside that, we have the following

[Desktop Entry]
Type=Application
Exec=/home/ben/screensaver_freq_watch.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Screensaver Frequency Watcher
Comment=Limits CPU and GPU frequencies while the screensaver is running

So far, it’s looking good! You may need to change this a bit depending on your configuration.

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2025 LostGeek.NET - All Rights Reserved. Powered by ClassicPress, NGINX, Debian GNU/Linux.