Screen does not turn off when inactive
Recently I have noticed that the brightness and lock settings to turn off the screen after a period of inactivity are being ignored.
I have my settings at 1 minute and to lock the screen when the screen turns off but my computer never seems to turn the screen off.
I have seen similar questions where people are noting an issue where the screens turn back on and the lock screen is showing but I am not getting the computer to lock at all.
Solution 1:
I can offer a workaround to this
Never mind the settings in the GUI, you can lock your screen and send your screens into standby via the command line
To lock your screen you could use
gnome-screensaver-command -l
or (if don't use gnome3)
xdg-screensaver lock
and to turn off your monitors (standby) you could use
xset dpms force off
Now, since you don't want to do this manually, but after a couple of minutes idle time, we need to find out how long you have been idle.
This can be done with xprintidle
sudo apt-get install xprintidle
xprintidle
will return miliseconds of (xserver) idletime
Now, lets combine this into a script(*). Use your favorite editor to copy/paste the following, modifying the IDLE_TIME
to your liking
nano /home/yourusername/idle_stby_lock_screen.sh
#!/bin/sh
# Wanted trigger timeout in milliseconds.
IDLE_TIME=$((5*60*1000)) # replace the '5' with how many minutes you'd like
# Sequence to execute when timeout triggers.
trigger_cmd() {
echo "Triggered action $(date)"
}
sleep_time=$IDLE_TIME
triggered=false
while sleep $(((sleep_time+999)/1000)); do
idle=$(xprintidle)
if [ $idle -ge $IDLE_TIME ]; then
if ! $triggered; then
gnome-screensaver-command -l
export DISPLAY=:0; xset dpms force off
triggered=true
sleep_time=$IDLE_TIME
fi
else
triggered=false
# Give 150 ms buffer to avoid frantic loops shortly before triggers.
sleep_time=$((IDLE_TIME-idle+150))
fi
done
Then make it executable with
chmod +x /home/yourusername/idle_stby_lock_screen.sh
You can test it out on the commandline
/home/yourusername/idle_stby_lock_screen.sh
if you are content with it, you can add it to the startup of your Ubuntu, like described in these answers here or with the "Startup" app in Ubuntu - just make sure to use the absolute path to your script.