Kolan Sh 2014-10-13 22:27:35 +04:00
parent 14c950da34
commit e1fac67736
1 changed files with 55 additions and 77 deletions

View File

@ -1,44 +1,34 @@
#!/bin/bash #!/bin/bash
# lightsOn.sh # lightsOn.sh
# Copyright (c) 2013 iye.cba at gmail com # Copyright (c) 2011 iye.cba at gmail com
# url: https://github.com/iye/lightsOn # url: https://github.com/iye/lightsOn
# This script is licensed under GNU GPL version 2.0 or above # This script is licensed under GNU GPL version 2.0 or above
# Description: Bash script that prevents the screensaver and display power # Description: Bash script that prevents the screensaver and display power
# management (DPMS) to be activated when you are watching Flash Videos # management (DPMS) to be activated when you are watching Flash Videos
# fullscreen on Firefox and Chromium. # fullscreen on Firefox and Chromium.
# Can detect mplayer, minitube, and VLC when they are fullscreen too. # Can detect mplayer and VLC when they are fullscreen too but I have disabled
# Also, screensaver can be prevented when certain specified programs are running. # this by default.
# lightsOn.sh needs xscreensaver or kscreensaver to work. # lightsOn.sh needs xscreensaver, kscreensaver or gnome-screensaver to work.
# HOW TO USE: Start the script with the number of seconds you want the checks # HOW TO USE: Start the script with the number of seconds you want the checks
# for fullscreen to be done. Example: # for fullscreen to be done. Example:
# "./lightsOn.sh 120 &" will Check every 120 seconds if Mplayer, Minitube # "./lightsOn.sh 120 &" will Check every 120 seconds if Mplayer,
# VLC, Firefox or Chromium are fullscreen and delay screensaver and Power Management if so. # 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 # You want the number of seconds to be ~10 seconds less than the time it takes
# your screensaver or Power Management to activate. # your screensaver or Power Management to activate.
# If you don't pass an argument, the checks are done every 50 seconds. # If you don't pass an argument, the checks are done every 50 seconds.
#
# An optional array variable exists here to add the names of programs that will delay the screensaver if they're running.
# This can be useful if you want to maintain a view of the program from a distance, like a music playlist for DJing,
# or if the screensaver eats up CPU that chops into any background processes you have running,
# such as realtime music programs like Ardour in MIDI keyboard mode.
# If you use this feature, make sure you use the name of the binary of the program (which may exist, for instance, in /usr/bin).
# Modify these variables if you want this script to detect if Mplayer, # Modify these variables if you want this script to detect if Mplayer,
# VLC, Minitube, or Firefox or Chromium Flash Video are Fullscreen and disable # VLC or Firefox Flash Video are Fullscreen and disable
# xscreensaver/kscreensaver and PowerManagement. # xscreensaver/kscreensaver/gnome-screensaver and PowerManagement.
mplayer_detection=1 mplayer_detection=0
vlc_detection=1 vlc_detection=0
firefox_flash_detection=1 firefox_flash_detection=1
chromium_flash_detection=1 chromium_flash_detection=1
minitube_detection=1 html5_detection=1 #checks if the browser window is fullscreen; will disable the screensaver if the browser window is in fullscreen so it doesn't work correctly if you always use the browser (Firefox or Chromium) in fullscreen
# Names of programs which, when running, you wish to delay the screensaver.
delay_progs=() # For example ('ardour2' 'gmpc')
# YOU SHOULD NOT NEED TO MODIFY ANYTHING BELOW THIS LINE # YOU SHOULD NOT NEED TO MODIFY ANYTHING BELOW THIS LINE
@ -51,31 +41,18 @@ do
displays="$displays $id" displays="$displays $id"
done< <(xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p') done< <(xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p')
# Detect screensaver been used (xscreensaver, kscreensaver, gnome-screensaver or none)
# Detect screensaver been used (xscreensaver, kscreensaver or none) if [ `pgrep -l xscreensaver | grep -wc xscreensaver` -ge 1 ];then
screensaver=`pgrep -l xscreensaver | grep -wc xscreensaver`
if [ $screensaver -ge 1 ]; then
screensaver=xscreensaver screensaver=xscreensaver
else elif [ `pgrep -l gnome-screensav | grep -wc gnome-screensav` -ge 1 ];then
screensaver=`pgrep -l kscreensaver | grep -wc kscreensaver` screensaver=gnome-screensav
if [ $screensaver -ge 1 ]; then elif [ `pgrep -l kscreensaver | grep -wc kscreensaver` -ge 1 ];then
screensaver=kscreensaver screensaver=kscreensaver
else else
screensaver=None screensaver=None
echo "No screensaver detected" echo "No screensaver detected"
fi fi
fi
checkDelayProgs()
{
for prog in "${delay_progs[@]}"; do
if [ `pgrep -lfc "$prog"` -ge 1 ]; then
echo "Delaying the screensaver because a program on the delay list, \"$prog\", is running..."
delayScreensaver
break
fi
done
}
checkFullscreen() checkFullscreen()
{ {
@ -138,9 +115,18 @@ isAppRunning()
# Check if user want to detect Video fullscreen on Chromium, modify variable chromium_flash_detection if you dont want Chromium detection # 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 [ $chromium_flash_detection == 1 ];then
if [[ "$activ_win_title" = *exe* ]];then if [[ "$activ_win_title" = *exe* ]];then
# Check if Chromium/Chrome Flash process is running # Check if Chromium Flash process is running
flash_process=`pgrep -lfc ".*((c|C)hrome|chromium).*flashp.*"` if [[ `pgrep -lfc "chromium-browser --type=plugin --plugin-path=/usr/lib/adobe-flashplugin"` -ge 1 || `pgrep -lfc "chromium-browser --type=plugin --plugin-path=/usr/lib/flashplugin-installer"` -ge 1 ]];then
if [[ $flash_process -ge 1 ]];then return 1
fi
fi
fi
#html5 (Firefox or Chromium full-screen)
if [ $html5_detection == 1 ];then
if [[ "$activ_win_title" = *chromium-browser* || "$activ_win_title" = *Firefox* ]];then
#check if firefox or chromium is running.
if [[ `pgrep -l firefox | grep -wc firefox` -ge 1 || `pgrep -l chromium-browse | grep -wc chromium-browse` -ge 1 ]]; then
return 1 return 1
fi fi
fi fi
@ -172,17 +158,6 @@ isAppRunning()
fi fi
fi fi
# Check if user want to detect minitube fullscreen, modify variable minitube_detection
if [ $minitube_detection == 1 ];then
if [[ "$activ_win_title" = *minitube* ]];then
#check if minitube is running.
#minitube_process=`pgrep -l minitube | grep -wc minitube`
minitube_process=`pgrep -lc minitube`
if [ $minitube_process -ge 1 ]; then
return 1
fi
fi
fi
return 0 return 0
} }
@ -193,7 +168,10 @@ delayScreensaver()
# reset inactivity time counter so screensaver is not started # reset inactivity time counter so screensaver is not started
if [ "$screensaver" == "xscreensaver" ]; then if [ "$screensaver" == "xscreensaver" ]; then
#This tells xscreensaver to pretend that there has just been user activity. This means that if the screensaver is active (the screen is blanked), then this command will cause the screen to un-blank as if there had been keyboard or mouse activity. If the screen is locked, then the password dialog will pop up first, as usual. If the screen is not blanked, then this simulated user activity will re-start the countdown (so, issuing the -deactivate command periodically is one way to prevent the screen from blanking.)
xscreensaver-command -deactivate > /dev/null xscreensaver-command -deactivate > /dev/null
elif [ "$screensaver" == "gnome-screensav" ]; then
dbus-send --session --type=method_call --dest=org.gnome.ScreenSaver --reply-timeout=20000 /org/gnome/ScreenSaver org.gnome.ScreenSaver.SimulateUserActivity > /dev/null
elif [ "$screensaver" == "kscreensaver" ]; then elif [ "$screensaver" == "kscreensaver" ]; then
qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity > /dev/null qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity > /dev/null
fi fi
@ -230,10 +208,10 @@ fi
while true while true
do do
checkDelayProgs
checkFullscreen checkFullscreen
sleep $delay sleep $delay
done done
exit 0 exit 0