Advertisement
Guest User

Untitled

a guest
Jun 21st, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.23 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Based on https://github.com/iye/lightsOn
  4. # needed tools xprop, xdotool. xvinfo, kde4 & firefox :)
  5. # copy this script to ~/.kde4/Autostart
  6.  
  7. displays=""
  8. while read id
  9. do
  10.     displays="$displays $id"
  11. done < <(xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p')
  12.  
  13. checkFullscreen()
  14. {
  15.     for display in $displays
  16.     do
  17.         plugin_win_id=`DISPLAY=:0.${display} xdotool search --onlyvisible --class plugin-container`
  18.         if [ -n "$plugin_win_id" ]; then
  19.             isPluginWinFullscreen=`DISPLAY=:0.${display} xprop -id $plugin_win_id _NET_WM_STATE | grep _NET_WM_STATE_FULLSCREEN`
  20.         else
  21.             isPluginWinFullscreen=""
  22.         fi
  23.  
  24.         if [[ "$isPluginWinFullscreen" != *NET_WM_STATE_FULLSCREEN* ]]; then
  25.             plugin_win_id=`DISPLAY=:0.${display} xprop -root _NET_ACTIVE_WINDOW`
  26.             plugin_win_id=${plugin_win_id:40:9}
  27.             isPluginWinFullscreen=`DISPLAY=:0.${display} xprop -id $plugin_win_id _NET_WM_STATE | grep _NET_WM_STATE_FULLSCREEN`
  28.         fi
  29.  
  30.         if [[ "$isPluginWinFullscreen" = *NET_WM_STATE_FULLSCREEN* ]]; then
  31.             isAppRunning
  32.             var=$?
  33.             if [[ $var -eq 1 ]]; then
  34.                 delayScreensaver
  35.             fi
  36.         fi
  37.     done
  38. }
  39.  
  40. isAppRunning()
  41. {
  42.     plugin_win_title=`xprop -id $plugin_win_id | grep "WM_CLASS(STRING)"`
  43.     if [[ "$plugin_win_title" = *unknown* || "$plugin_win_title" = *plugin-container* ]]; then
  44.         flash_process=`pgrep -l plugin-containe | grep -wc plugin-containe`
  45.         if [[ $flash_process -ge 1 ]]; then
  46.             return 1
  47.         fi
  48.     fi
  49.     return 0
  50. }
  51.  
  52. delayScreensaver()
  53. {
  54.     echo "Simulating activity"
  55.     qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity > /dev/null
  56.     dpmsStatus=`xset -q | grep -ce 'DPMS is Enabled'`
  57.     if [ $dpmsStatus == 1 ]; then
  58.         xset -dpms
  59.         xset dpms
  60.     fi
  61. }
  62.  
  63. delay=$1
  64. if [ -z "$delay" ]; then
  65.     delay=30
  66. fi
  67.  
  68. if [[ $delay = *[^0-9]* ]]; then
  69.     echo "The Argument \"$delay\" is not valid, not an integer"
  70.     echo "Please use the time in seconds you want the checks to repeat."
  71.     echo "You want it to be ~10 seconds less than the time it takes your screensaver or DPMS to activate"
  72.     exit 1
  73. fi
  74.  
  75. app=`basename $0`
  76. app_pid=`pgrep -f $app`
  77. app_pid=${app_pid//$$/}
  78. if [[ $app_pid -ge 1 ]]; then
  79.     echo "Already Runnin"
  80.     exit 0
  81. fi
  82.  
  83. while true
  84. do
  85.     checkFullscreen
  86.     sleep $delay
  87. done
  88.  
  89. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement