You are not logged in.

#1 2011-11-17 04:35:34

iye
Member
From: Argentina
Registered: 2011-07-27
Posts: 6

lightsOn.sh - stop screensaver and DPMS when watching flash vids

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. It can detect when VLC and Mplayer are fullscreen too but this is disabled by default.

You can get it from https://github.com/iye/lightsOn

# HOW TO USE: Start the script with the number of seconds you want the checks
# for fullscreen to be done. Example:
# "./lightsOn.sh 120 &" will Check every 120 seconds if Mplayer,
# VLC, Firefox or Chromium are fullscreen and delay screensaver and Power Management if so.
# You want the number of seconds to be ~10 seconds less than the time it takes
# your screensaver or Power Management to activate.
# If you don't pass an argument, the checks are done every 50 seconds.


iye

Offline

#2 2011-11-22 02:43:35

stqn
Member
Registered: 2010-03-19
Posts: 1,189
Website

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

Hi iye smile

Your script is interesting, but I rarely watch flash videos in fullscreen and was wondering if something could be done to detect non-fullscreen flash videos...

The only idea I've got is to check the title of the (currently active ?) window(s) to check if it contains "youtube" or "dailymotion" etc. and if it does then check if plugin-container is taking "enough" CPU time.

This CPU time threshold would depend on the website (dailymotion's player takes an awful lot of CPU time even when paused, for example) and on the system (CPU power, VDPAU or not...), so it should be configurable by the user unless we can find a smart way to compute it.

Offline

#3 2011-11-22 04:34:35

iye
Member
From: Argentina
Registered: 2011-07-27
Posts: 6

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

It can be done, "xprop" does report the title of the active window. The thing is there could be situations where it would ilegimately block the screensaver. What if a webpage in another tab has a flash ad, so plugin-container is using a bit of CPU, and you are browsing youtube when you leave the computer. The screensaver would never activate. I would have to see how much CPU to check for too, in my computer, watching videos on youtube makes plugin-container use <10% of CPU, and my computer is old so newer computer may require much less. I think it's not very reliable to just check CPU usage.
For me it's not usefull because if I'm watching a video that is long enough, I would go fullscreen. Youtube videos last 10 minutes or so (most of them), so setting the screensaver to 10 minutes does it. If more people ask for this, I will add your sugestion as an option. You can help add it if you want, the proyect is on Github ;P

Offline

#4 2012-02-11 19:17:14

xCrucialDudex
Member
Registered: 2007-08-19
Posts: 144

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

iye wrote:

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. It can detect when VLC and Mplayer are fullscreen too but this is disabled by default.

You can get it from https://github.com/iye/lightsOn

# HOW TO USE: Start the script with the number of seconds you want the checks
# for fullscreen to be done. Example:
# "./lightsOn.sh 120 &" will Check every 120 seconds if Mplayer,
# VLC, Firefox or Chromium are fullscreen and delay screensaver and Power Management if so.
# You want the number of seconds to be ~10 seconds less than the time it takes
# your screensaver or Power Management to activate.
# If you don't pass an argument, the checks are done every 50 seconds.


iye

Thank you for the script, however it doesn't work on my setup. I use chromium and the screen still is dimmed after 10 minutes.

I took a quick look at your code and it seem to me at the time you wrote it, you were looking for a completely different match to detect whether Flash Player was working. As it can be seen from the console output below there's nothing to match your pgrep option:

% grep flash scripts/lightsOn.sh
flash_detection=1
    # Check if user want to detect Flash Video fullscreen on Firefox, modify variable flash_detection
    if [ $flash_detection == 1 ];then
            flash_process=`pgrep -l plugin-containe | grep -wc plugin-containe`
            if [[ $flash_process -ge 1 ]];then
% pgrep -l plugin-contane
% ps axuwf |grep plugin
xxx      19958  0.1  0.3  89096  9396 ?        Sl   18:57   0:09  \_ /usr/lib/chromium/chromium --type=plugin --plugin-path=/opt/google/talkplugin/libnpgoogletalk.so --lang=en-US --channel=19387.0xdd4e9a0.150090717
xxx      22757 52.1  1.1 284432 36684 ?        Sl   20:00  36:59  \_ /usr/lib/chromium/chromium --type=plugin --plugin-path=/usr/lib/mozilla/plugins/libflashplayer.so --lang=en-US --channel=19387.0xe9d1370.702370740
xxx      19967  0.0  0.2  54372  7248 ?        Sl   18:57   0:01 /opt/google/talkplugin/GoogleTalkPlugin

Offline

#5 2012-02-13 03:39:11

iye
Member
From: Argentina
Registered: 2011-07-27
Posts: 6

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

The code you posted detects flash for Firefox. If you go on reading the code, you will see this:

    # Check if user want to detect Video fullscreen on Chromium, modify variable chromium_flash_detection if you dont want Chromium detection
    if [ $chromium_flash_detection == 1 ];then
        if [[ "$activ_win_title" = *exe* ]];then   
        # Check if Chromium Flash process is running
            flash_process=`pgrep -lfc "chromium-browser --type=plugin --plugin-path=/usr/lib/adobe-flashplugin"`
            if [[ $flash_process -ge 1 ]];then
                return 1
            fi
        fi
    fi

I don't have Chromium available right now to test as I don't use it. Try replacing the line that says:

            flash_process=`pgrep -lfc "chromium-browser --type=plugin --plugin-path=/usr/lib/adobe-flashplugin"`

with this one:

            flash_process=`pgrep -lfc "chromium --type=plugin --plugin-path=/usr/lib/mozilla/plugins/libflashplayer.so"`

Works now?

Offline

#6 2012-02-13 04:40:34

xCrucialDudex
Member
Registered: 2007-08-19
Posts: 144

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

iye wrote:

The code you posted detects flash for Firefox. If you go on reading the code, you will see this:

    # Check if user want to detect Video fullscreen on Chromium, modify variable chromium_flash_detection if you dont want Chromium detection
    if [ $chromium_flash_detection == 1 ];then
        if [[ "$activ_win_title" = *exe* ]];then   
        # Check if Chromium Flash process is running
            flash_process=`pgrep -lfc "chromium-browser --type=plugin --plugin-path=/usr/lib/adobe-flashplugin"`
            if [[ $flash_process -ge 1 ]];then
                return 1
            fi
        fi
    fi

...

Works now?

Ha! But this code isn't just there!

Offline

#7 2012-02-13 13:24:43

iye
Member
From: Argentina
Registered: 2011-07-27
Posts: 6

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

Problem is you downloaded an older version. Here you have the latest: https://raw.github.com/iye/lightsOn/master/lightsOn.sh

Offline

#8 2012-02-14 05:58:53

xCrucialDudex
Member
Registered: 2007-08-19
Posts: 144

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

iye wrote:

Problem is you downloaded an older version. Here you have the latest: https://raw.github.com/iye/lightsOn/master/lightsOn.sh

Ironically, I intentionally went to github to grab the latest version of the script and I still failed lol Thanks, though.

UPD: Nope, still doesn't work. GNOME 3.0.2, fall-back mode. No xscreensaver, just a default GNOME screensaver (blank black screen with lock icon and time at the top of the screen.) After 10 minutes, default, screensaver kicks in even though the script is running.

Last edited by xCrucialDudex (2012-02-14 06:20:34)

Offline

#9 2012-02-14 17:28:37

iye
Member
From: Argentina
Registered: 2011-07-27
Posts: 6

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

Sorry, lightsOn only works with xscreensaver and kscreensaver. I don't know much about Gnome 3, but you could try disabling the screensaver and activating DPMS so the monitor turns off at the desired time. Then lightsOn will disable DPMS while you are watching flash in fullscreen. DPMS would be your screensaver wink

Offline

#10 2012-02-14 20:41:48

xCrucialDudex
Member
Registered: 2007-08-19
Posts: 144

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

iye wrote:

Sorry, lightsOn only works with xscreensaver and kscreensaver. I don't know much about Gnome 3, but you could try disabling the screensaver and activating DPMS so the monitor turns off at the desired time. Then lightsOn will disable DPMS while you are watching flash in fullscreen. DPMS would be your screensaver wink

Here's a little patch, maybe not the best take on this but whatever.

47c47
< elif [ $screensaver -eq 0 ];then
---
> else
51,56c51
<     fi
< elif [ $screensaver -eq 0 ];then
<     screensaver=`pgrep -l gnome-screensaver | grep -wc gnome-screensaver`
<     if [ $screensaver -ge 1 ]; then
<         screensaver=gnome-screensaver
<     else	
---
>     else
120c115
<             flash_process=`pgrep -lf "chromium --type=plugin --plugin-path=/usr/lib/mozilla/plugins/libflashplayer" |grep -wc libflashplayer`
---
>             flash_process=`pgrep -lfc "chromium-browser --type=plugin --plugin-path=/usr/lib/adobe-flashplugin"`
166,167d160
<     elif [ "$screensaver" == "gnome-screensaver" ];then
< 	qdbus org.gnome.ScreenSaver / org.gnome.ScreenSaver.SimulateUserActivity > /dev/null

If I got the logic right and script was supposed to work... well, it still did not. Which is a bummer. I could try killing gnome-screensaver process and resorting to DPMS, but that's kinda intrusive, if you ask me (given there's gnome-screensaver and DBUS method to emulate user activity).

Just a thought, maybe you should support gnome-screensaver after all? It doesn't look like a lot of work:)

Offline

#11 2012-03-28 15:49:00

Gooberslot
Member
Registered: 2012-03-28
Posts: 8

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

Any chance of adding Opera support?

Offline

#12 2012-03-30 15:09:15

Gooberslot
Member
Registered: 2012-03-28
Posts: 8

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

I think I may have got this working under Opera.  I need to do more tests to make sure.

Offline

#13 2012-04-06 09:02:48

Gooberslot
Member
Registered: 2012-03-28
Posts: 8

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

It seems to be working so here's the changes I made if anyone is interested:

--- lightsOn.sh	2012-03-28 05:42:16.847647734 -0500
+++ lightsOn.sh	2012-03-31 02:40:23.030971873 -0500
@@ -28,7 +28,7 @@
 vlc_detection=0
 firefox_flash_detection=1
 chromium_flash_detection=1
-
+opera_flash_detection=1
 
 # YOU SHOULD NOT NEED TO MODIFY ANYTHING BELOW THIS LINE
 
@@ -112,7 +112,18 @@
         fi
     fi
 
-    
+#Opera section
+    if [ $opera_flash_detection == 1 ];then
+        if [[ "$activ_win_title" = *operapluginwrapper* ]];then
+            # Check if plugin-container process is running
+            flash_process=`pgrep -l operapluginwrap | grep -wc operapluginwrap`
+            #(why was I using this line avobe? delete if pgrep -lc works ok)
+            #flash_process=`pgrep -lc plugin-containe`
+            if [[ $flash_process -ge 1 ]];then
+                return 1
+            fi
+        fi
+    fi
     # Check if user want to detect Video fullscreen on Chromium, modify variable chromium_flash_detection if you dont want Chromium detection
     if [ $chromium_flash_detection == 1 ];then
         if [[ "$activ_win_title" = *exe* ]];then   

Offline

#14 2012-04-08 21:27:27

bloom
Member
Registered: 2010-08-18
Posts: 749
Website

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

I wrote something similar:

civilised_screensaver


gh · da · ds · cr · ab · fkr

Offline

#15 2012-05-02 00:36:27

cupantae
Member
Registered: 2010-03-15
Posts: 18

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

Nice one, iye!

However, I didn't install it yet. I was wondering first why you don't have a package in AUR for this? I think a simple, effective solution to this is almost a necessity for a modern operating system and I reckon it could find its way into [community] if it covers all common full-screen programmes. Sure, anyone can xset -dpms, but that's not a great solution. It's easy to forget to set and unset it.

Some suggestions for further programme support:
skype, uzbl, mplayer, mproject

Some more comments:
Why not turn on for all flash processes, regardless of browser? That might make compatibility a bit easier.
Could it be run as a daemon?
A config file in the home directory would be handy to manually blacklist programmes, set the check interval, etc.

I know I probably sound like I'm asking for a lot without contributing anything. On the contrary, I will gladly help, but I have 12 university exams this month and I'm working (almost) round the clock for them. It will be June before I have the time for it. I'm just saying that if this is to take off, good compatibility is a must.

Thanks for starting this off, though. I'm very surprised that an external script is needed for this.

Cupán Tae


By the way, I didn't read any of the posts above me.

Offline

#16 2012-06-15 20:07:00

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,071

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

Nice. I was looking for something to disable DPMS on flash full screens videos. My mplayer full screen never had problems and DPMS doesn't activate for the entire movie, but online videos gave me this problem.

I will try this out tonight...


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#17 2012-11-23 15:30:22

Stalafin
Member
From: Berlin, Germany
Registered: 2007-10-26
Posts: 616

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

Ressurecting the dead; there seems to be a problem with xprop
Line 64 from https://github.com/iye/lightsOn/blob/master/lightsOn.sh gives me:

$ display=xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p'                                        
0
$ DISPLAY=:0.${display} xprop -root _NET_ACTIVE_WINDOW
_NET_ACTIVE_WINDOW:  not found.

Therefore, all the following code fails and line 76 necessarily results in:

sage:  xprop [-options ...] [[format [dformat]] atom] ...

where options include:
    -grammar                       print out full grammar for command line
    -display host:dpy              the X server to contact
    -id id                         resource id of window to examine
    -name name                     name of window to examine
    -font name                     name of font to examine
    -remove propname               remove a property
    -set propname value            set a property to a given value
    -root                          examine the root window
    -len n                         display at most n bytes of any property
    -notype                        do not display the type field
    -fs filename                   where to look for formats for properties
    -frame                         don't ignore window manager frames
    -f propname format [dformat]   formats to use for property of given name
    -spy 

I am using this to log into X (from https://wiki.archlinux.org/index.php/Start_X_at_Login):

[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx

Offline

#18 2013-07-13 19:47:30

firekage
Member
From: Eastern Europe, Poland
Registered: 2013-06-30
Posts: 470

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

I tried to use this script but it doesen't work with my Arch installation. After 10 minutes, screen goes blank.

Offline

#19 2013-08-31 20:31:16

xorgx3
Member
From: Poland
Registered: 2011-11-29
Posts: 197

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

I start use xscreensaver and lightson, but the script working only for vlc, but don't working for chromium(what is more needed).
Comand:

pgrep -lfc ".*((c|C)hrome|chromium).*flashp.*"

shows me 0 if chromium is off, 15(or greater) if I am using flash(pepper flash) and another number otherwise.
I can't resolve problem myself so i hope you can.
If it important I am using awesomeWM.


EDIT:
Ok, i found solution.
Original code:

 if [ $chromium_flash_detection == 1 ];then
        if [[ "$activ_win_title" = *exe* ]];then
        # Check if Chromium/Chrome Flash process is running
            flash_process=`pgrep -lfc ".*((c|C)hrome|chromium).*flashp.*"`
            if [[ $flash_process -ge 1 ]];then
                return 1
            fi
        fi
    fi

little changed code:

    # Check if user want to detect Video fullscreen on Chromium, modify variable chromium_flash_detection if you dont want Chromium detection
    if [ $chromium_flash_detection == 1 ];then
        #if [[ "$activ_win_title" = *exe* ]];then
       if [[ "$activ_win_title" = *chromium* ]];then
        # Check if Chromium/Chrome Flash process is running
            #flash_process=`pgrep -lfc ".*((c|C)hrome|chromium).*flashp.*"`
	    flash_process=`pgrep -lfc "chromium --type=ppapi"`
            if [[ $flash_process -ge 1 ]];then
                return 1
            fi
        fi
    fi

It's looks like working smile
I don't know why in original code was "exe" instead of "chromium" or "chrome".

I think (if you need this) you can comment lines: if activ window bla bla and fi, then lightson will working always if you use flash.

Last edited by xorgx3 (2013-09-01 07:08:28)

Offline

#20 2014-03-11 13:06:23

kabolt
Member
Registered: 2012-03-31
Posts: 8

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

a fork for including my changes:
https://github.com/devkral/lightsonplus

I added support for other display numbers (e.g. remote desktop),  a manually inhibit command and include some mentioned fixes

Sorry for the name and for forking.

Last edited by kabolt (2014-03-11 13:25:28)

Offline

#21 2014-03-18 21:51:32

Young
Member
Registered: 2009-04-26
Posts: 43

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

This script is great, but it should search for "chromium" instead of "chromium-browser" when it tests for full screen HTML5 video (lines 183 and 185). Otherwise, it will not work with Chromium. I suggest you to change this in the code:

#html5 (Firefox or Chromium full-screen)
    if [ $html5_detection == 1 ];then
        if [[ "$activ_win_title" = *chromium* || "$activ_win_title" = *Firefox* ]];then   
            #check if firefox or chromium is running.
            if [[ `pgrep -l firefox | grep -wc firefox` -ge 1 || `pgrep -l chromium | grep -wc chromium` -ge 1 ]]; then
                return 1
            fi
        fi
    fi

Thanks for keeping it updated.

Offline

#22 2014-05-20 14:10:58

Lockheed
Member
Registered: 2010-03-16
Posts: 1,429

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

Could support for detecting PopconTime be added to the script? It is getting more and more popular.


Laptop: ThinkPad W500, C2D P9500, 8GB, Radeon RV635 (HD3650), Arch | Server/fw: Zotac AQ01, A4-5000 Kabini, 4GB, Arch/pfSense VM

Offline

#23 2014-05-24 22:56:29

moneytoo
Member
From: Czech Republic
Registered: 2012-04-04
Posts: 20

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

Once case that isn't covered by this script is playing videos on youtube and other sites in non fullscreen view. Therefore to me good enough solution is to check for visible browser window containing site name (as already mentioned) and test if audio output is running:

fuser /dev/snd/timer

Offline

#24 2014-07-16 06:34:08

xorgx3
Member
From: Poland
Registered: 2011-11-29
Posts: 197

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

@moneytoo (or someone else) - Can you more explain how to modify this script to working with playing videos in non fulscreen view?

Anyway in that lines sholud be *Chrom* instead of *chrom* (upper letter at the beginning).

 if [[ "$activ_win_title" = *Chrom* ]];then  
if [[ "$activ_win_title" = *Chromium* || "$activ_win_title" = *Firefox* ]];then   

and when we use Firefox:

 if [[ "$activ_win_title" = *Firefox* || "$activ_win_title" = *plugin-container* ]];then

instead of

 if [[ "$activ_win_title" = *unknown* || "$activ_win_title" = *plugin-container* ]];then

Last edited by xorgx3 (2014-07-16 12:23:38)

Offline

#25 2014-08-03 05:06:50

sistematico
Member
From: Campo Grande / MS / Brasil
Registered: 2008-07-26
Posts: 74
Website

Re: lightsOn.sh - stop screensaver and DPMS when watching flash vids

You should add support to the Popcorn-Time.

Thank you.


Lucas Saliés Brum
blog | medium | vk | twitter | github | .share
Forgive the spelling and grammar, English is not my native language.

Offline

Board footer

Powered by FluxBB