Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Based on https://github.com/iye/lightsOn
- # needed tools xprop, xdotool. xvinfo, kde4 & firefox :)
- # copy this script to ~/.kde4/Autostart
- displays=""
- while read id
- do
- displays="$displays $id"
- done < <(xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p')
- checkFullscreen()
- {
- for display in $displays
- do
- plugin_win_id=`DISPLAY=:0.${display} xdotool search --onlyvisible --class plugin-container`
- if [ -n "$plugin_win_id" ]; then
- isPluginWinFullscreen=`DISPLAY=:0.${display} xprop -id $plugin_win_id _NET_WM_STATE | grep _NET_WM_STATE_FULLSCREEN`
- else
- isPluginWinFullscreen=""
- fi
- if [[ "$isPluginWinFullscreen" != *NET_WM_STATE_FULLSCREEN* ]]; then
- plugin_win_id=`DISPLAY=:0.${display} xprop -root _NET_ACTIVE_WINDOW`
- plugin_win_id=${plugin_win_id:40:9}
- isPluginWinFullscreen=`DISPLAY=:0.${display} xprop -id $plugin_win_id _NET_WM_STATE | grep _NET_WM_STATE_FULLSCREEN`
- fi
- if [[ "$isPluginWinFullscreen" = *NET_WM_STATE_FULLSCREEN* ]]; then
- isAppRunning
- var=$?
- if [[ $var -eq 1 ]]; then
- delayScreensaver
- fi
- fi
- done
- }
- isAppRunning()
- {
- plugin_win_title=`xprop -id $plugin_win_id | grep "WM_CLASS(STRING)"`
- if [[ "$plugin_win_title" = *unknown* || "$plugin_win_title" = *plugin-container* ]]; then
- flash_process=`pgrep -l plugin-containe | grep -wc plugin-containe`
- if [[ $flash_process -ge 1 ]]; then
- return 1
- fi
- fi
- return 0
- }
- delayScreensaver()
- {
- echo "Simulating activity"
- qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity > /dev/null
- dpmsStatus=`xset -q | grep -ce 'DPMS is Enabled'`
- if [ $dpmsStatus == 1 ]; then
- xset -dpms
- xset dpms
- fi
- }
- delay=$1
- if [ -z "$delay" ]; then
- delay=30
- fi
- if [[ $delay = *[^0-9]* ]]; then
- echo "The Argument \"$delay\" is not valid, not an integer"
- echo "Please use the time in seconds you want the checks to repeat."
- echo "You want it to be ~10 seconds less than the time it takes your screensaver or DPMS to activate"
- exit 1
- fi
- app=`basename $0`
- app_pid=`pgrep -f $app`
- app_pid=${app_pid//$$/}
- if [[ $app_pid -ge 1 ]]; then
- echo "Already Runnin"
- exit 0
- fi
- while true
- do
- checkFullscreen
- sleep $delay
- done
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement