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.

Advertisement

22 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!

    1. Sorry about that, I wrote them on my phone without being able to test them. It was a basic syntax error: fixed now, re-download and try them again.

  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.

  10. Hello everyone
    I’ve been through these bash scripts you proposed, JAMcNaughton. I mixed them together with my own code added to create a script with these features:
    – works either for active window only or any window
    – works for full-screen, on top or maximised windows, separately or combined.
    All this can be configured with the -c or –config option (bash .xscreensaverstopper.sh -c (or –config)) through a simple dialog box (via the “zenity” command, see code below) with four checkboxes, which respectively allows the user to choose whether the xscreensaver blocking applies to:
    – the active window only or all windows
    – full-screen window(s)
    – maximised window(s)
    – on-top window(s)
    Changes in settings are immediately effective to xscreensaver blocking conditions of the running script (launched at startup), after the dialog box is validated.
    Settings are recorded in a tiny config file (weighing only 5 octets!) in the script’s directory. A default config file is created by the script if it doesn’t exist. This default file tells the script to block xscreensaver when any window (not only the active one) is in full-screen mode.
    This script has been tested on a Linux Mint 19.2 Cinnamon 64-bit machine with dual monitors and everything works as it is intended to. This script depends on zenity and wmctl packages that must be installed for the script to run without error.

    Here is the script:
    #!/bin/bash
    # xscreensaverstopper.sh

    # This script is licensed under GNU GPL version 2.0 or above

    # Uses elements from lightsOn.sh
    # Copyright (c) 2011 iye.cba at gmail com
    # url: https://github.com/iye/lightsOn
    # This script is licensed under GNU GPL version 2.0 or above

    # Description: Restarts xscreensaver’s idle countdown while
    # applications are running in windows with certain states.
    # Checks every 59 seconds to see if an application window in one of these states at least
    # has focus, if so then the xscreensaver is told to restart
    # its idle countdown.

    function set_config {
    #create configuration dialog box
    OPTIONS=$(zenity –list –checklist –width=480 –height=230 –hide-column=”2″\
    –title=”XScreensaver Stopper Configuration” \
    –text=”Disable XScreensaver for ” \
    –column=”Disable” –column “option-cl” –column=”Description” \
    $bSingleWin “SGW” “The active window only (all windows otherwise),
    in these states:” \
    $bWinFullSc “FSW” “Full-screen” \
    $bWinMax “MXW” “Maximised” \
    $bWinOnTop “OTW” “On-top” 2>/dev/null)
    #if dialog box validated, write new config file
    if [ $? = 0 ]; then
    #read config options from the dialog box
    sCONFIG=””
    if echo $OPTIONS | grep SGW; then sCONFIG=”1″; else sCONFIG=”0″; fi
    if echo $OPTIONS | grep FSW; then sCONFIG=$sCONFIG”1″; else sCONFIG=$sCONFIG”0″; fi
    if echo $OPTIONS | grep MXW; then sCONFIG=$sCONFIG”1″; else sCONFIG=$sCONFIG”0″; fi
    if echo $OPTIONS | grep OTW; then sCONFIG=$sCONFIG”1″; else sCONFIG=$sCONFIG”0″; fi
    #write config options to the config file
    echo $sCONFIG > .xss_config
    #if dialog box cancelled, create another dialog box stating the config file was not modified
    else
    zenity –warning –width=300 –height=130 –title=”XScreensaver Stopper Configuration cancelled”\
    –text=”The configuration file is not modified.” 2>/dev/null
    fi
    }

    checkWindowStates()
    {
    # loop through every display looking for a fullscreen window
    for display in $displays
    do
    #only active window or all windows?
    if [[ $bSingleWin ]];
    then
    WIN_IDs=`DISPLAY=:0.${display} xprop -root _NET_ACTIVE_WINDOW`
    WIN_IDs=${WIN_IDs:40:9}
    else
    WIN_IDs=$(wmctrl -l | awk ‘$3 != “N/A” {print $1}’)
    fi
    done
    # Check if Active Window (the foremost window) is in state(s) that stop(s) xscreensaver
    for i in $WIN_IDs;
    do
    if [[ $bWinFullSc ]]; then isWinFullSc=`DISPLAY=:0.${display} xprop -id “$i” | grep _NET_WM_STATE_FULLSCREEN`; else isWinFullSc=”0″; fi
    if [[ $bWinMax ]]; then isWinMax=`DISPLAY=:0.${display} xprop -id “$i” | grep _NET_WM_STATE_MAXIMIZED_VERT`; else isWinMax=”0″; fi
    if [[ $bWinOnTop ]]; then isWinOnTop=`DISPLAY=:0.${display} xprop -id “$i” | grep _NET_WM_STATE_ABOVE`; else iWinOnTop=”0″; fi
    if [[ “$isWinFullsc” == *NET_WM_STATE_FULLSCREEN* || “$isWinMax” == *NET_WM_STATE_MAXIMIZED_VERT* || “$isWinOnTop” == *NET_WM_STATE_ABOVE* ]];then
    xscreensaver-command -deactivate
    fi
    done
    }

    #MAIN
    #get config
    #create default config file if it doesn’t exist
    if [[ ! -e .xss_config ]]; then echo “0100” > .xss_config;fi
    #read config file and assign booleans variables
    CONFIGFILE=`cat .xss_config`
    if [[ ${CONFIGFILE:0:1} = “1” ]]; then bSingleWin=TRUE; else bSingleWin=FALSE;fi
    if [[ ${CONFIGFILE:1:1} = “1” ]]; then bWinFullSc=TRUE; else bWinFullSc=FALSE;fi
    if [[ ${CONFIGFILE:2:1} = “1” ]]; then bWinMax=TRUE; else bWinMax=FALSE;fi
    if [[ ${CONFIGFILE:3:1} = “1” ]]; then bWinOnTop=TRUE; else bWinOnTop=FALSE;fi
    #manage command line option
    getopt=getopt
    OPTIONLC=$($getopt -o ‘+c’ -l config -n “XScreensaver Stopper” — “$@”)
    case $? in
    0) : ;;
    1) exit 1 ;;
    *) exit 1 ;;
    esac
    eval set — “$OPTIONLC”
    while true; do
    case “$1″ in
    -c|–config) set_config; shift ;;
    –) shift; break ;;
    # *) zenity –error –title=”Unexpected option” –text=”This option is not available.
    #Only -c or –config are correct options.” 2>/dev/null
    # exit 1 ;;
    esac
    done
    # enumerate all the attached screens
    displays=””
    while read id
    do
    displays=”$displays $id”
    done < <(xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p')
    while sleep $((59)); do
    checkWindowStates
    done
    exit 0

  11. Edit : please read “wmctrl” instead of “wmctl” in the necessary packages for this script I named “.xscreensaverstopper.sh” (without quote marks).

    1. Sadly it doesnt work for me. I’m in Manjaro, installed the wmctrl, chmoded the script but when i call it from the terminal, it just sits there and doesnt do anything. No configuration box, no shell prompt, nothing…

  12. Nevermind, I’m a god damned idiot. I downloaded the multi-monitor one, changed the :0 to :1 and forgot to chmod a+x /path/to/xscreensaverstopper.sh (used old file name so I didn’t have to change the autostarted programs around.

    Thanks a TON for this script by the way!

Leave a Reply to Yashalta Cancel 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 )

Facebook photo

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

Connecting to %s