Stop XScreenSaver when fullscreen is playing

I want to disable XScreenSaver when playing YouTube videos. I looked for any browser plugins, but did not find anything suitable. Sure, I can always turn it off before I watch something in the browser, but come on. Therefore I decided to look for a more “global” solution.

I found the script, available at the xtendo GitHub repo. What it does is to restart XScreenSaver’s idle countdown every XX seconds, when an application is running in full screen and is on focus. The script itself uses elements from by iye.

I modified it a bit, making it check every 30 seconds:


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

# Uses elements from
# Copyright (c) 2011 at gmail com
# url:
# This script is licensed under GNU GPL version 2.0 or above

# Description: Restarts xscreensaver's idle countdown while 
# full screen applications are running.  
# Checks every 30 seconds to see if a full screen application
# has focus, if so then the xscreensaver is told to restart 
# its idle countdown.

# enumerate all the attached screens
while read id
    displays="$displays $id"
done< <(xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p')


    # loop through every display looking for a fullscreen window
    for display in $displays
        #get id of active window and clean output
        activ_win_id=`DISPLAY=:0.${display} xprop -root _NET_ACTIVE_WINDOW`
        # Check if Active Window (the foremost window) is in fullscreen state
        isActivWinFullscreen=`DISPLAY=:0.${display} xprop -id $activ_win_id | grep _NET_WM_STATE_FULLSCREEN`
        if [[ "$isActivWinFullscreen" == *NET_WM_STATE_FULLSCREEN* ]];then
        	xscreensaver-command -deactivate

while sleep $((30)); do

exit 0

I made the script executable, placed it in ~/.local/bin and specified it to autostart from the desktop environment. That’s it! Playing YouTube videos in fullscreen is no longer interrupted by the screensaver.

One Comment on “Stop XScreenSaver when fullscreen is playing”

  1. Jonathan Quimbly says:

    Thank you! Ran into this right after uninstalling gnome-screensaver and installing xscreensaver.

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 )

Twitter picture

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

Facebook photo

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

Connecting to %s