Stop xscreensaver Interrupting Full Screen Videos on Multiple Monitors

Previously I posted a script for use on Linux systems which stops xscreensaver from kicking in when a full-screen window has focus. While useful for some setups this script isn’t well suited to multiple monitor configurations where the likelihood of a full-screen window not having focus is greater.  This post details a script which remedies this problem.

The script works by performing a check every 30 seconds for a full screen window (not maximised).  If there are any the script tells xscreensaver to restart its count of how long the user has been idle.

XScreensaverStopperAny.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/xscreensaverstopperany.sh

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

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.

Advertisements

18 thoughts on “Stop xscreensaver Interrupting Full Screen Videos on Multiple Monitors

  1. Thank you for your script, еverything works fine!

    But if you have just one monitor!
    But I using two monitors! One monitor something showing/playing in full screen mode, on the other I’m working usually with not in fullscreen mode windows.
    Here is the beginning problems with the script!
    Your script checking full-screen mode only the ACTIVE windows!

    for example:
    On the 2-nd monitor in full screen opened a page with some instructions.
    on the 1-st monitor Im working with no full screen mode of windows. In that situation your script does not delay screen saver because on the second monitor even if window is opened in full screen mode but it is not active vindow, becouse im working on the 1-st monitor with not full screen woíndows!

    Question:
    is it possible to do your script to checking not only the active window but INACTIVE windows also?

    PS – my screen server has wating time just 1 minut.

    1. Hi, the script in this post checks both active and inactive windows to see if any of them are fullscreen. (I know there’s a variable in the script called ‘isActivWinFullscreen’ but it doesn’t actually refer to an active windows, it refers to any window.)

      So in your example where there is a full screen window, this will stop the screensaver starting even if something has focus on top of it or on another monitor.

  2. Thanks for your response,
    today i had checked one more time your script it is don’t work!
    The last time I did not say that in the original version the script did not work at all at me! I did not say because I thought if everything is ok at everyone may be I’m doing something wrong?!?!
    And i just changed a two settings in you script! (without these changes the script will not work!)

    first i change
    _NET_WM_STATE_FULLSCREEN
    on
    _NET_WM_STATE_MAXIMIZED_VERT

    and second i change
    *NET_WM_STATE_FULLSCREEN*
    on
    *NET_WM_STATE_MAXIMIZED_VERT*

    And everything works fine if the windows to respond two conditions!
    1. if the window to full screen
    2. if the window is active ( if the window is not active it is not important opened a window in full screen, have you a just one monitor or multiple the script don’t work! )

    have you idea that’s wrong?

    ps – My OS it is Lubuntu 15.10x32bit.

    1. Ah, I think I see what the problem is here. You’re wanting to stop the screen saver for maximised windows instead of full-screen ones, is that right?

      There is a slight different between the two windows modes. The script in the post looks for windows in ‘full-screen mode’ (like when you press F11 on a browser or play a video full screen so that the video fills the full screen and leaves no bars or controls at the top and bottom) so it wouldn’t detect when a window is just maximised (it may be filling the screen but the window manager won’t count it as full screen unfortunately). This is why you had to change the flag checked to the maximised_vert as that checks if the window is in maximised mode instead of full-screen mode.

      Its strange that you’re still having problems with inactive maximised windows. Could you try this version of the script and let me know how you get on: https://raw.githubusercontent.com/jamcnaughton/useful-linux-scripts/master/xscreensaver/xscreensaverstopperany-maximised.sh

  3. Thanks for link!
    I tried this script https://raw.githubusercontent.com/jamcnaughton/useful-linux-scripts/master/xscreensaver/xscreensaverstopperany-maximised.sh
    It does not work, i tried by pressing the key F11 it also do not help me.
    previously (мy second comment) i wrote about this https://github.com/jamcnaughton/useful-linux-scripts/blob/master/xscreensaver/xscreensaverstopper.sh

    PS – I think that something has changed in Lubuntu 15.10 because I read the comments of 2009-2013 at everyone everything is working! I mean, before i tried “similar” scripts LightsOn.sh, had same problems with fullscreen mode of windows…

    1. Hi, you’re right – it looks like maximised windows may have a different flag for their state when not in focus. There’s a way you can find this flag:

      1. Open a maximised window
      2. Open a terminal
      3. Run ‘wmctrl -l
      4. Look for the line with the name of your maximised window
      5. Copy the ID (this should be at the start of the line as something like 0x00000000
      6. Run ‘xprop -id “0x00000000” ‘ where 0x00000000 is the id for your maximised window
      7. This will print out a lot of info (hopefully), look for the line starting with something like “_NET_WM_STATE(ATOM)”
      8. The following flags on the line are what the script should be looking for, post them in a reply and I can change the script to look for them.

      I hope this helps.

      By the way, xscreenstopper isn’t intended for multiple monitor setups, that’s why I made xscreenstopperany instead. Neither will work if you’re using a separate x11 session for each window either (though I think you’d get independent screensaver instances in that scenario anyway).

  4. I did everything according to your instructions, thanks for that!
    1.Run wmctrl -l
    2.Copy the ID and Run ‘xprop -id
    if briefly:
    when a window in full screen mode _NET_WM_STATE(ATOM) = _NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_MAXIMIZED_HORZ

    when a window in NOT full screen mode BUT is enabled the function “Always on top”
    _NET_WM_STATE(ATOM) = _NET_WM_STATE_ABOVE

    when a window in full screen mode + enabled the function “Always on top”
    _NET_WM_STATE(ATOM) = _NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_MAXIMIZED_HORZ, _NET_WM_STATE_ABOVE

    I redid your the script
    https://github.com/jamcnaughton/useful-linux-scripts/blob/master/xscreensaver/xscreensaverstopper.sh

    by replacing
    grep _NET_WM_STATE_FULLSCREEN on grep _NET_WM_STATE MAXIMIZED VERT
    and
    NET_WM_STATE_FULLSCREEN on NET_WM_STATE MAXIMIZED VERT

    And everything working nice!

    Also I made almost the same a second script for the function “Always on top” because I sometimes working not in full screen mode and to me need delay screensaver.
    by replacing grep _NET_WM_STATE_FULLSCREEN on grep _NET_WM_STATE_ABOVE
    and
    NET_WM_STATE_FULLSCREEN on NET_WM_STATE_ABOVE

    Question:
    how to make from two almost identical scripts just one script?

    The script should looking “NET_WM_STATE MAXIMIZED VERT” or “NET_WM_STATE_ABOVE”
    if it found one from two or two in same time delay screensaver.

    PS – https://www.dropbox.com/sh/d436e55frbu14d5/AABWc5tsQkzuMB349Bgp_7VTa?dl=0

    1. That’s great to hear. I’ve put together 2 scripts for you.

      This one should stop the screen saver when the windows with focus is either maximised or set to be always on top: https://raw.githubusercontent.com/jamcnaughton/useful-linux-scripts/master/xscreensaver/xscreensaverstopper-maximisedorontop.sh

      And this one should stop the screen saver when any windows with focus is either maximised or set to be always on top: https://raw.githubusercontent.com/jamcnaughton/useful-linux-scripts/master/xscreensaver/xscreensaverstopperany-maximisedorontop.sh

  5. Thanks for the quick response!
    I checked your scripts on my computer Lubuntu 16.04 x32bit by running it in a terminal
    the first does not work
    https://raw.githubusercontent.com/jamcnaughton/useful-linux-scripts/master/xscreensaver/xscreensaverstopper-maximisedorontop.sh

    Terminal wrote that script does not work because error
    line 38: Syntax error near ‘]’
    if [[ “$isWinMax” == *NET_WM_STATE_MAXIMIZED_VERT* ] || [ “$isWinOnTop” == *NET_WM_STATE_ABOVE* ]];then’

    and second script
    https://raw.githubusercontent.com/jamcnaughton/useful-linux-scripts/master/xscreensaver/xscreensaverstopperany-maximisedorontop.sh
    has a similar situation

    line 35: syntax error in conditional expression
    if [[ “$isWinMax” == *NET_WM_STATE MAXIMIZED VERT* ] ||[ “$isWinOnTop” == *NET_WM_STATE_ABOVE* ]];then’

    SP – I tried to find an error, but could not to find!

  6. Thank you very much!!!
    I have corrected all the errors here your code https://www.dropbox.com/s/ga1c21d6d6znrwn/checkall.sh?dl=0
    I checked It works exactly as I would like!
    1. No matter opened window is active or not
    2. No matter how many monitors

    question:
    Your script works fine in tandem with the script “LightsOn”.
    Your script looking “Fullscreen” and “Always on Top” and delay screensaver but not delay screen saver if working Flash player on fullscreen.
    If working Flash player on fullscreen then the script “LightsOn” delay screensaver…

    Сould you please see the code of “LightsOn” and remove his own solution of “checkFullscreen()” and paste your script that checking Fullscreen and “Always on Top” for active windows and non-active windows

    link on the script “LightsOn”
    https://www.dropbox.com/s/euds8c45eo9mf7g/lightsOn.sh?dl=0
    On the Internet you can finde many same versions of that scripts but that in my view a more comprehensive and take into account all the possible cases!

    PS – You can do not answer to me and one more time THANKS for your script!

    1. Hi, thanks for fixing it up. I’ve now updated the scripts with your corrections. I’ve also added a check in them to stop the screen saver starting when something is full screen (like full screen flash videos).

  7. Wow, super!!! I checked it is works!!!
    Youtube fullscreen, some “on line” video, everything works perfectly!

    I’m probably become impudent! 🙂
    The final request:
    Сan you to add the ability for adding a programs when they are working daley screensaver.
    As it is implemented in the “lightsOn.sh” or similar ability?

    # Names of programs which, when running, you wish to delay the screensaver.
    # For example (‘ardour2’ ‘gmpc’).
    delay_progs=()

    PS – Today i did system restore from my backup… I do not know why but the script has stopped working and “requested” to install the wmctrl

    sudo apt-get update
    sudo apt-get install wmctrl

    After this, everything works fine! I think it is necessary to write in the description of the script, for beginners like me!

  8. Thanks for all your hard work. Initially it wouldn’t work but I found once Kodi was opened directly to fullscreen it was ok. The screensaver is still activated when viewing mpv, vlc or youtube I guess due to the fact that they are opened maximised and not fullscreen. I’m using dual monitors. wmctrl -l && xprop -id shows when the program is running in fullscreen. Any ideas?

    1. Hi, you’re right – it’s likely because the windows are maximised and not full screen. Double clicking the video in vlc or pressing the full screen box in the corner of youtube videos should switch them to proper full screen and make the script stop the screensaver kicking in.

      The alternative (if you’ve got something that won’t go fullscreen, even with F11) is to modify the script to detect maximised windows instead. I wrote 2 versions of the script for a previous commenter which does this, just pick whichever behaviour fits your needs best:

  9. I got everything working!
    I’m using Devuan with XFCE and found I needed 2 adjustments.
    I changed “xscreensaver-command -deactivate” to “xscreensaver-command -dea & xset dpms s reset”
    and to I needed to open mpv like this “mpv –heartbeat-cmd=”xscreensaver-command -deactivate” %f”
    All good, Thanks again.

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