Prevent GNOME screensaver during full-screen Flash videos

While movie players (such as VLC) prevent the GNOME screensaver from activating during movie playback, playing Flash videos does not affect the screensaver, which means having to move the mouse occasionally, or turning off the screensaver while watching YouTube videos and the like.

There is no perfect solution to this, but using a script, it is possible to detect whether Firefox’s plugin-container process (which runs Flash) or Chrome is running in full-screen mode, which more often than not means that a Flash video is playing.  Of course, if you regularly use Firefox or Chrome in full-screen mode, or watch movies unattended in non-full-screen mode, then this is not a good heuristic for you.

This script uses xdotool to simulate user activity.  Other methods such as:
>gnome-screensaver-command -d
>dbus-send –session –type=method_call –dest=org.gnome.ScreenSaver –reply-timeout=20000 /org/gnome/ScreenSaver org.gnome.ScreenSaver.SimulateUserActivity
>xset -dpms; xset +dpms
didn’t work for me, but they might work for you.

Other dependencies are Perl and xprop.  To ensure that all dependencies exist use:
>yum install perl xorg-x11-utils xdotool

Create the script file, give it executable permissions, and run it in your console.  I added it to my autostart applications to ensure it always runs when I log in.


$ENV{DISPLAY} = ":0" if ! exists ( $ENV{DISPLAY} );

  foreach my $window ( `xdotool search --onlyvisible --class plugin-container`,
                       `xdotool search --onlyvisible --class google-chrome` )
    chop ( $window );

    my $state = ( split ( " = ", substr ( `xprop -id $window _NET_WM_STATE 2>/dev/null`, 0, -1 ) ) )[1];
    if ( grep ( /^_NET_WM_STATE_FULLSCREEN$/, split ( /\s*,\s*/, $state ) ) )
      system ( "xdotool", "key", "shift" );

  my $delay = `gsettings get org.gnome.settings-daemon.plugins.power sleep-display-ac` - 30;
  sleep ( $delay );

One thought on “Prevent GNOME screensaver during full-screen Flash videos

  1. Thanks ! I’m using it in gnome 3.18 and it works well. I just changed the command to get the delay with the following:
    gsettings get org.gnome.desktop.session idle-delay | cut -d’ ‘ -f 2

Leave a Reply

Your email address will not be published. Required fields are marked *