Page 1 of 1

Fold only when Ubuntu/Linux Mint screensaver enabled

Posted: Fri Jan 15, 2021 7:40 pm
by gunnarre
I think the Folding@Home client relies on xscreensaver to check if a Linux machine is idle, but this has been replaced with cinnamon-screensaver in newer Ubuntu and Linux Mint versions.

To get idle detection working again, there are two possible solutions: Note 1: Only use this script if you really have to. Most of the time, new GPUs can fold comfortably while you use the desktop, and manual pausing when playing demanding games is a better strategy.
Note 2: Remove any "On idle" settings on the slots or client first - we're going to explicitly pause and unpause the slots when the screensaver enables, rather than relying on the broken idle detection.
Note 3: Set "pause-on-start" to "True" on any slots that you're controlling with this script, if you don't want to fold until you've logged in and started the screensaver.
Note 4: It is assumed that you want the screensaver to control slot 01 (the GPU) here. Adjust the script as needed by changing the slot number, remove the slot number if you want to control the whole client, or just add command lines.

Run

Code: Select all

sudo pico /usr/local/bin/cinnamon-lockscreen-folding.sh
And put this in the file, then save it with Ctrl+o, accept with filename, then exit with ctrl+x:

Code: Select all

#!/bin/bash
# Check for existing instances and kill them leaving current instance running
for PID in $(pidof -o %PPID -x "${0##*/}"); do
    if [ "$PID" != $$ ]; then
        kill -9 "$PID"
    fi 
done
dbus-monitor --session "interface='org.cinnamon.ScreenSaver', member='ActiveChanged'" | while read -r msg
do
  case "$msg" in
    "boolean true")
		# Unpause command(s) for when screensaver enables. The number is for the folding slot. Leave out the number to unpause the whole client:
        FAHClient --send-unpause 01
      ;;
    "boolean false")
		# Pause command for when desktop in use:
        FAHClient --send-pause 01
      ;;
    *) ;;
  esac
done
To keep the script running at every reboot, run

Code: Select all

pico ~/.config/autostart/cinnamon-lockscreen-folding-autostart.desktop
enter this in the file and save it:

Code: Select all

[Desktop Entry]
Type=Application
Exec=/bin/bash /usr/local/bin/cinnamon-lockscreen-folding.sh
X-GNOME-Autostart-enabled=true
NoDisplay=false
Hidden=false
Name=cinnamon-lockscreen-folding.desktop
Comment=Change folding
X-GNOME-Autostart-Delay=1