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:

XScreensaverStopper.sh

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/xscreensaverstopper.sh

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).

Advertisements

7 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
    -Nicro

    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 xscreensaverstopper.sh
        xscreensaverstopper.sh: Zeile 23: Syntaxfehler beim unerwarteten Wort `<'
        xscreensaverstopper.sh: 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 ./xscreensaverstopper.sh. (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 xscreensaverstopper.sh /usr/local/bin/
         sudo chmod +x /usr/local/bin/xscreensaverstopper.sh
         xscreensaverstopper.sh &

        (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.

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s