Stop xscreensaver Interrupting Full Screen Videos

One of the reasons that Xubuntu is great is that it comes with xscreensaver enabled by default. However, there’s a problem; xscreensaver will kick in when you’ve been idle long enough no matter what – even if you’re watching a video. This post details a script which stops xscreensaver starting when a full-screen window has focus.

In the past xscreensaver and caffeine were best of buddies; stopping the screensaver intruding while you watched something.  However, recent builds of caffeine don’t play nice with non-gnome desktops out of the box.  To counter the problem I’ve produced a script that will stop xscreensaver kicking in when a full-screen window is in the foreground:

The script should be downloaded into any folder you think is best. To start the script a command similar to the following should be used:

bash path/to/script/

You should add this command to your session’s start up applications and next time you log in xscreensaver will be prevented from running while you have any full-screen windows in the foreground.  This include full-screen flash and HTML5 videos, meaning xscreensaver won’t interrupt Youtube or Netflix if you’re watching them full-screen.

The script works by performing a check every 30 seconds to see if the window that currently has focus is set to be full screen (not just maximised).  If so the script tells xscreensaver to restart its count of how long the user has been idle.

The script should be usable on other Linux platforms that can use bash scripts and xscreensaver.

Feel free to modify the script if you can think of any improvements.

If you’re interested in a version of the script that stops the screensaver when any window is set to be full screen (not just the one that has focus) see this post (useful for multiple monitors).


12 thoughts on “Stop xscreensaver Interrupting Full Screen Videos

  1. Hey there,

    I just updated from OpenSuse 13.1 to OS Leap, the xscreensaver was part of the system before but now no longer is. Your script would be perfect for me. However Bash stops at line 23 and reports anything after “done” as an unexpected symbol starting with the first “<". All commands should work the same way unless something is not native bash or was updated in the meantime. I can't really tell what the line does, does it detect the device id of the monitor?

    Thanks in advance for any help

    1. Hi Nicro,

      Do you have xvinfo installed? This is something external to bash that line 23 calls – I suspect Leap may not have it installed by default.

      I hope this helps.

      1. Correct. I have now installed xvinfo and made sure that it works on it’s own, it does however not change the error.
        “user@linux-xl8m:~> sh Zeile 23: Syntaxfehler beim unerwarteten Wort `<' Zeile 23: `done< <(xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p')'"
        The first line is German and should translate to "syntaxerror at unexpected symbol/word '<'"
        "Zeile" of course is equal to "line".
        Out of curiosity I tried removing the first < but not the second, the new unexpected symbol was "(".
        The loop before that seems to close successfully though.
        Any ideas?

      2. Hey @chaosnicro, you need to run it using bash, not sh. The normal way to do that is to set it as executable and then run ./ (Note the prefixed dot-slash to specify the current directory).

        Even better is to put it somewhere in your $PATH (~/bin or /usr/local/bin) and then you can just run it as a command without specifying the directory.

         sudo cp /usr/local/bin/
         sudo chmod +x /usr/local/bin/ &

        (Optional ampersand to make it run in the background.)

        P.S. J.A.McNaughton, could you please erase my other reply where I accidentally swapped the order of cp and chmod?

  2. By the way, J.A.McNaughton, if you’re the author of this script, good job! It works well. Someone should let JWZ (the author of Xscreensaver) know about it so he can implement it into xscreensaver.

  3. Thanks JAMcNaughton!

    This is a kindness for humankind. Being not able to think out such a script myself, I really thank you for your effort. I know a little bash scripting, but this is really great and simple. I can read your code and understand it half, but could never think out the idea and code it myself. Super!

  4. Alright, I got this to work for a LONG time during my 16.04 & 18.04 usage – my problem now lies in 20.04.

    For some reason my desktop screen/desktop isn’t :0 anymore, it’s :1 (had to figure out how to get VNC working with that). I’m curious as to what I need to tweak to get it working that way as Caffeine is broken (even on gnome-shell these days – at least for me).

    the piece I edited on this one (and the multiple monitors one) was:

    WIN_IDs=$(wmctrl -l | awk ‘$3 != “N/A” {print $1}’)
    for i in $WIN_IDs; do
    isWinFullscreen=`DISPLAY=:1.${display} xprop -id “$i” |>
    if [[ “$isWinFullscreen” == *NET_WM_STATE_FULLSCREEN* ]>
    xscreensaver-command -deactivate

    But it’s not working. What do I need to change to get it working as my default desktop is :1 now – not :0.

    Thanks for help in advance


  5. Thanks for taking the time to write and release this! To get it to start at boot on Raspberry OS (Buster), I made it a cronjob like so (I put it in a directory in my home folder called scripts)

    crontab -e

    (if this is your first time editing this file you’ll be asked to choose an editor – just choose ‘1’ – nano. Scroll to bottom and add the following line)

    @reboot /home/pi/scripts/ &

    ctrl-x, Y

    The ampersand (&) is necessary or it won’t work.

    reboot. You can verify that it’s running by checking the task manager. It should be there.

  6. I know this is OLD, but let me add my big ‘thank you’ to J.A.Mcnaughton for this (! Works fine ‘as-is’ under Debian-Buster-KDE, just copied it to a local directory, added a pointer under KDE’s AUTOSTART/SCRIPTS. Fixed a minor headache for me!

  7. Hi; MANY THANKS for sharing this script 🙂 👍 🙏!
    I modified the line with statement
    while sleep $((30))
    as so:
    while sleep $((599))
    This way, as on my computer xscreensaver delay is set to 10 mn (= 600 s), the check will be performed only once per xscreensaver cycle, thus avoiding to proceed to the check too often.
    Thanks again!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s