| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 #--------------------------------------------- | 2 #--------------------------------------------- |
| 3 # xdg-screensaver | 3 # xdg-screensaver |
| 4 # | 4 # |
| 5 # Utility script to control screensaver. | 5 # Utility script to control screensaver. |
| 6 # | 6 # |
| 7 # Refer to the usage() function below for usage. | 7 # Refer to the usage() function below for usage. |
| 8 # | 8 # |
| 9 # Copyright 2006, Bryce Harrington <bryce@osdl.org> | 9 # Copyright 2006, Bryce Harrington <bryce@osdl.org> |
| 10 # | 10 # |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 # Check if we can use "mv -T" | 29 # Check if we can use "mv -T" |
| 30 if mv -T ... ... 2>&1 | grep '\.\.\.' > /dev/null ; then | 30 if mv -T ... ... 2>&1 | grep '\.\.\.' > /dev/null ; then |
| 31 # We can securely move files in /tmp with mv -T | 31 # We can securely move files in /tmp with mv -T |
| 32 DEBUG 1 "mv -T available" | 32 DEBUG 1 "mv -T available" |
| 33 MV="mv -T" | 33 MV="mv -T" |
| 34 screensaver_file="/tmp/xdg-screensaver-$USER-"`echo $DISPLAY | sed 's/:/-/g'` | 34 screensaver_file="/tmp/xdg-screensaver-$USER-"`echo $DISPLAY | sed 's/:/-/g'` |
| 35 else | 35 else |
| 36 # No secure moves available, use home dir | 36 # No secure moves available, use home dir |
| 37 DEBUG 1 "mv -T not available" | 37 DEBUG 1 "mv -T not available" |
| 38 MV="mv" | 38 MV="mv" |
| 39 screensaver_file="$HOME/.xdg-screensaver-"`echo $HOSTNAME-$DISPLAY | sed 's/:
/-/g'` | 39 screensaver_file="$HOME/.xdg-screensaver-"`echo $(hostname)-$DISPLAY | sed 's
/:/-/g'` |
| 40 fi | 40 fi |
| 41 lockfile_command=`which lockfile 2> /dev/null` | 41 lockfile_command=`which lockfile 2> /dev/null` |
| 42 | 42 |
| 43 lockfile() | 43 lockfile() |
| 44 { | 44 { |
| 45 if [ -n "$lockfile_command" ] ; then | 45 if [ -n "$lockfile_command" ] ; then |
| 46 $lockfile_command -1 -l 10 -s 3 "$screensaver_file".lock | 46 $lockfile_command -1 -l 10 -s 3 "$screensaver_file".lock |
| 47 else | 47 else |
| 48 # Poor man's attempt at doing a lockfile | 48 # Poor man's attempt at doing a lockfile |
| 49 # Be careful not to facilitate a symlink attack | 49 # Be careful not to facilitate a symlink attack |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 fi | 109 fi |
| 110 fi | 110 fi |
| 111 | 111 |
| 112 } | 112 } |
| 113 | 113 |
| 114 cleanup_suspend() | 114 cleanup_suspend() |
| 115 { | 115 { |
| 116 lockfile | 116 lockfile |
| 117 test "${TMPDIR+set}" = set || TMPDIR=/tmp | 117 test "${TMPDIR+set}" = set || TMPDIR=/tmp |
| 118 tmpfile=`mktemp $TMPDIR/tmp.XXXXXXXXXX` | 118 tmpfile=`mktemp $TMPDIR/tmp.XXXXXXXXXX` |
| 119 grep -v "$window_id:" "$screensaver_file" > "$tmpfile" 2> /dev/null | 119 grep -v "$window_id:$xprop_pid\$" "$screensaver_file" > "$tmpfile" 2> /dev/nul
l |
| 120 $MV "$tmpfile" "$screensaver_file" | 120 $MV "$tmpfile" "$screensaver_file" |
| 121 if [ ! -s "$screensaver_file" ] ; then | 121 if [ ! -s "$screensaver_file" ] ; then |
| 122 rm "$screensaver_file" | 122 rm "$screensaver_file" |
| 123 unlockfile | 123 unlockfile |
| 124 # $screensaver_file is empty, do resume | 124 # $screensaver_file is empty, do resume |
| 125 perform_action resume | 125 perform_action resume |
| 126 else | 126 else |
| 127 unlockfile | 127 unlockfile |
| 128 fi | 128 fi |
| 129 } | 129 } |
| 130 | 130 |
| 131 do_resume() | 131 do_resume() |
| 132 { | 132 { |
| 133 lockfile # Obtain lockfile | 133 lockfile # Obtain lockfile |
| 134 # Find the PID of the trackingprocess | 134 # Find the PID of the trackingprocess |
| 135 xprop_pid=`grep "$window_id:" "$screensaver_file" 2> /dev/null | cut -d ':' -f
2` | 135 xprop_pid=`grep "$window_id:" "$screensaver_file" 2> /dev/null | cut -d ':' -f
2` |
| 136 unlockfile # Free lockfile | 136 unlockfile # Free lockfile |
| 137 if [ -n "$xprop_pid" ] && ps -p "$xprop_pid" 2> /dev/null | grep xprop > /dev/
null; then | 137 if [ -n "$xprop_pid" ] && ps -p "$xprop_pid" 2> /dev/null | grep xprop > /dev/
null; then |
| 138 # Kill the tracking process | 138 # Kill the tracking process |
| 139 kill -TERM $xprop_pid | 139 kill -s TERM $xprop_pid |
| 140 fi | 140 fi |
| 141 cleanup_suspend | 141 cleanup_suspend |
| 142 } | 142 } |
| 143 | 143 |
| 144 XPROP=`which xprop 2> /dev/null` | 144 XPROP=`which xprop 2> /dev/null` |
| 145 | 145 |
| 146 check_window_id() | 146 check_window_id() |
| 147 { | 147 { |
| 148 if [ -z "$XPROP" ]; then | 148 if [ -z "$XPROP" ]; then |
| 149 DEBUG 3 "xprop not found" | 149 DEBUG 3 "xprop not found" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 IFS="$IFS_save" | 322 IFS="$IFS_save" |
| 323 ) > $tmpfile | 323 ) > $tmpfile |
| 324 if [ -s "$tmpfile" ] ; then | 324 if [ -s "$tmpfile" ] ; then |
| 325 # Suspend pending, don't do a thing | 325 # Suspend pending, don't do a thing |
| 326 $MV "$tmpfile" "$screensaver_file" | 326 $MV "$tmpfile" "$screensaver_file" |
| 327 unlockfile | 327 unlockfile |
| 328 return | 328 return |
| 329 fi | 329 fi |
| 330 $MV "$tmpfile" "$screensaver_file" | 330 $MV "$tmpfile" "$screensaver_file" |
| 331 unlockfile | 331 unlockfile |
| 332 (while [ -f "$screensaver_file" ]; do $*; sleep 59; done) > /dev/null 2> /dev/
null & | 332 (while [ -f "$screensaver_file" ]; do $*; sleep 50; done) > /dev/null 2> /dev/
null & |
| 333 } | 333 } |
| 334 | 334 |
| 335 screensaver_gnome() | 335 screensaver_gnome() |
| 336 { | 336 { |
| 337 # TODO | 337 # TODO |
| 338 # There seems to be a DBUS interface for gnome-screensaver | 338 # There seems to be a DBUS interface for gnome-screensaver |
| 339 # See http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2006-April/042579.html
and | 339 # See http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2006-April/042579.html
and |
| 340 # http://cvs.gnome.org/viewcvs/gnome-screensaver/src/gs-listener-dbus.c?rev=1.36
&view=log | 340 # http://cvs.gnome.org/viewcvs/gnome-screensaver/src/gs-listener-dbus.c?rev=1.36
&view=log |
| 341 # A problem seems to be that Inhibit is tied to the lifetime of the DBUS appname
and | 341 # A problem seems to be that Inhibit is tied to the lifetime of the DBUS appname
and |
| 342 # this can not be used from a script | 342 # this can not be used from a script |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 if [ "$action" = "suspend" ] ; then | 498 if [ "$action" = "suspend" ] ; then |
| 499 # Start tracking $window_id and resume the screensaver once it disappears | 499 # Start tracking $window_id and resume the screensaver once it disappears |
| 500 ( track_window ) 2> /dev/null > /dev/null & | 500 ( track_window ) 2> /dev/null > /dev/null & |
| 501 fi | 501 fi |
| 502 | 502 |
| 503 if [ $result -eq 0 ]; then | 503 if [ $result -eq 0 ]; then |
| 504 exit_success | 504 exit_success |
| 505 else | 505 else |
| 506 exit_failure_operation_failed | 506 exit_failure_operation_failed |
| 507 fi | 507 fi |
| OLD | NEW |