]>
git.rmz.io Git - dotfiles.git/blob - bin/suspend_screensaver
e1081f4e970c013b142c19c89cbd033b584bc10a
4 # Copyright (c) 2011 iye.cba at gmail com
5 # url: https://github.com/iye/lightsOn
6 # This script is licensed under GNU GPL version 2.0 or above
8 # Description: Bash script that prevents the screensaver and display power
9 # management (DPMS) to be activated when you are watching Flash Videos
10 # fullscreen on Firefox and Chromium.
11 # Can detect mplayer and VLC when they are fullscreen too but I have disabled
13 # lightsOn.sh needs xscreensaver or kscreensaver to work.
15 # HOW TO USE: Start the script with the number of seconds you want the checks
16 # for fullscreen to be done. Example:
17 # "./lightsOn.sh 120 &" will Check every 120 seconds if Mplayer,
18 # VLC, Firefox or Chromium are fullscreen and delay screensaver and Power Management if so.
19 # You want the number of seconds to be ~10 seconds less than the time it takes
20 # your screensaver or Power Management to activate.
21 # If you don't pass an argument, the checks are done every 50 seconds.
24 # Modify these variables if you want this script to detect if Mplayer,
25 # VLC or Firefox Flash Video are Fullscreen and disable
26 # xscreensaver/kscreensaver and PowerManagement.
29 firefox_flash_detection
=1
30 chromium_flash_detection
=1
33 # YOU SHOULD NOT NEED TO MODIFY ANYTHING BELOW THIS LINE
35 [[ $(which xdg-screensaver 2> /dev/null) ]] || { echo "You need to install xdg-utils!"; exit 1; }
37 # enumerate all the attached screens
41 displays
="$displays $id"
42 done< <(xvinfo
| sed -n 's/^screen #\([0-9]\+\)$/\1/p')
47 # loop through every display looking for a fullscreen window
48 for display
in $displays
50 #get id of active window and clean output
51 activ_win_id
=`DISPLAY=:0.${display} xprop -root _NET_ACTIVE_WINDOW`
52 #activ_win_id=${activ_win_id#*# } #gives error if xprop returns extra ", 0x0" (happens on some distros)
53 activ_win_id
=${activ_win_id:40:9}
55 # Skip invalid window ids (commented as I could not reproduce a case
56 # where invalid id was returned, plus if id invalid
57 # isActivWinFullscreen will fail anyway.)
58 #if [ "$activ_win_id" = "0x0" ]; then
62 # Check if Active Window (the foremost window) is in fullscreen state
63 isActivWinFullscreen
=`DISPLAY=:0.${display} xprop -id $activ_win_id | grep _NET_WM_STATE_FULLSCREEN`
64 if [[ "$isActivWinFullscreen" = *NET_WM_STATE_FULLSCREEN
* ]];then
67 if [[ $delayed -eq 0 && $var -eq 1 ]];then
70 elif [[ $delayed -eq 1 && $var -ne 1 ]]; then
83 # check if active windows is mplayer, vlc or firefox
84 #TODO only window name in the variable activ_win_id, not whole line.
85 #Then change IFs to detect more specifically the apps "<vlc>" and if process name exist
89 #Get title of active window
90 activ_win_title
=`xprop -id $activ_win_id | grep "WM_CLASS(STRING)"` # I used WM_NAME(STRING) before, WM_CLASS more accurate.
93 # Check if user want to detect Video fullscreen on Firefox, modify variable firefox_flash_detection if you dont want Firefox detection
94 if [ $firefox_flash_detection == 1 ];then
95 if [[ "$activ_win_title" = *unknown
* || "$activ_win_title" = *plugin
-container* ]];then
96 # Check if plugin-container process is running
97 flash_process
=`pgrep -l plugin-containe | grep -wc plugin-containe`
98 #(why was I using this line avobe? delete if pgrep -lc works ok)
99 #flash_process=`pgrep -lc plugin-containe`
100 if [[ $flash_process -ge 1 ]];then
107 # Check if user want to detect Video fullscreen on Chromium, modify variable chromium_flash_detection if you dont want Chromium detection
108 if [ $chromium_flash_detection == 1 ];then
109 if [[ "$activ_win_title" = *exe
* ]];then
110 # Check if Chromium Flash process is running
111 flash_process
=`pgrep -fl "chromium --type=plugin --plugin-path=/usr/lib/mozilla/plugins/libflashplayer.so" | wc -l`
112 if [[ $flash_process -ge 1 ]];then
119 #check if user want to detect mplayer fullscreen, modify variable mplayer_detection
120 if [ $mplayer_detection == 1 ];then
121 if [[ "$activ_win_title" = *mplayer
* || "$activ_win_title" = *MPlayer
* ]];then
122 #check if mplayer is running.
123 mplayer_process
=`pgrep -l mplayer | grep -wc mplayer`
124 if [ $mplayer_process -ge 1 ]; then
131 # Check if user want to detect vlc fullscreen, modify variable vlc_detection
132 if [ $vlc_detection == 1 ];then
133 if [[ "$activ_win_title" = *vlc
* ]];then
134 #check if vlc is running.
135 vlc_process
=`pgrep -l vlc | grep -wc vlc`
136 if [ $vlc_process -ge 1 ]; then
150 # reset inactivity time counter so screensaver is not started
151 xdg
-screensaver suspend $activ_win_id
153 #Check if DPMS is on. If it is, deactivate and reactivate again. If it is not, do nothing.
154 dpmsStatus
=`xset -q | grep -ce 'DPMS is Enabled'`
155 if [ $dpmsStatus == 1 ];then
164 xdg
-screensaver resume
$activ_win_id
171 # If argument empty, use 50 seconds as default.
177 # If argument is not integer quit.
178 if [[ $1 = *[^0-9]* ]]; then
179 echo "The Argument \"$1\" is not valid, not an integer"
180 echo "Please use the time in seconds you want the checks to repeat."
181 echo "You want it to be ~10 seconds less than the time it takes your screensaver or DPMS to activate"