Prevent screensaver when flash is running in linux

4

3

I imagine that my problem is not unique to my circumstances, and I have been having it for some time.

I am running Arch Linux, and quite frequently watch videos, particularly flash, in fullscreen. However, eventually, the screensaver appears, and starts dimming the screen. I have the screensaver set to run whenever the computer is 'idle'. Does anyone know a way to either

  • Stop the screensaver from appearing when in a flash video or watching other video?
  • Stop the screensaver from appearing when a flash video or normal video is full-screened? Heck, even...
  • Let the screensaver know that my machine is not idle when watching flash.

NT3RP

Posted 2011-04-06T02:35:32.007

Reputation: 425

Answers

2

You can disable the screensaver by running xset s off.

Enable it again by writing xset s 5, where 5 is the number of seconds it takes your screensaver to come back on.

If you want to write a script, you could attempt to do something like this:

#!/bin/bash
# Wrapper around the main body to facilitate being run
# from a startup file like .xinitrc, ~/.config/autostart, ...

while :; do
    if pgrep xscreensaver >/dev/null; then
        METHOD="xscreensaver"
        pkill xscreensaver
    else
        METHOD="xset"
        xset s off
    fi

    # If you want to be really fancy:
    ## notify-send "Screensaver Disabled" $"The Flash plugin is running"

    while ps ax | grep libflashplayer.so >/dev/null; do
          sleep 1 # Sleep while waiting for Flash to exit
    done

    if [ "$METHOD" = "xscreensaver" ]; then
        xscreensaver &
    else
        xset s 30
    fi

    # If you want to be really fancy:
    ## notify-send "Screensaver Enabled" $"The Flash plugin has exited"

    sleep 30
done

At @snapfractalpop's request, a short use guide:

  1. Put this somewhere in your home directory - it doesn't matter. You probably want to make a ~/bin directory if you don't have anywhere for personal scripts already. For the purpose of this explanation, I'll assume you put it in ~/bin/youtube-scrn-svr.sh.

  2. chmod +x ~/bin/youtube-scrn-svr.sh or make it executable some other way.

  3. Assuming your DE is one of the common ones (XFCE, GNOME, and KDE can load scripts this way), create a file called ~/.config/autostart/flash-screensaver.desktop and add the following to it.

    [Desktop Entry]
    Name=Flash Screensaver Disabler
    Exec=/home/WHATEVER_YOUR_USERNAME_IS/bin/youtube-scrn-svr.sh
    Terminal=false
    Categories=Network;
    StartupNotify=false
    
  4. Try logging out and watching a suitably long video, and see if the screensaver is enabled.

new123456

Posted 2011-04-06T02:35:32.007

Reputation: 3 707

1if [ "$(pgrep xscreensaver)" ];if pgrep xscreensaver;. Just sayin'. – user1686 – 2011-10-23T20:21:01.590

@grawity Thanks for the tip - I'm more used to Tcl and C, so the extra syntax feels a little more natural. – new123456 – 2011-10-23T21:05:00.837

Can you elaborate on this a little? Where does this script go? Does one have to manually run it every time they view a youtube video that is longer than 5 mins? Why isn't this working out of the box? – snapfractalpop – 2013-01-11T22:45:46.580

1@snapfractalpop Try it now. There's an added section at the bottom explaining how best to use it. – new123456 – 2013-01-18T20:10:19.740

This has to be the most stereotypically over-engineered response to a "how to" question about Linux ever. Where do I vote this into the hall of fame? – Mark E. Haase – 2013-10-08T04:41:55.977

0

Have you check this: https://bbs.archlinux.org/viewtopic.php?id=130447

I made this some time ago and want to share. It's a Bash script that checks when you are watching flash videos fullscreen in Firefox and Chromium and prevents the screensaver and DPMS (turns off screen) from activating.

Francesco

Posted 2011-04-06T02:35:32.007

Reputation: 209