| 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 # Check if we can use "mv -T" | 357 # Check if we can use "mv -T" |
| 358 if mv -T ... ... 2>&1 | grep '\.\.\.' > /dev/null ; then | 358 if mv -T ... ... 2>&1 | grep '\.\.\.' > /dev/null ; then |
| 359 # We can securely move files in /tmp with mv -T | 359 # We can securely move files in /tmp with mv -T |
| 360 DEBUG 1 "mv -T available" | 360 DEBUG 1 "mv -T available" |
| 361 MV="mv -T" | 361 MV="mv -T" |
| 362 screensaver_file="/tmp/xdg-screensaver-$USER-"`echo $DISPLAY | sed 's/:/-/g'` | 362 screensaver_file="/tmp/xdg-screensaver-$USER-"`echo $DISPLAY | sed 's/:/-/g'` |
| 363 else | 363 else |
| 364 # No secure moves available, use home dir | 364 # No secure moves available, use home dir |
| 365 DEBUG 1 "mv -T not available" | 365 DEBUG 1 "mv -T not available" |
| 366 MV="mv" | 366 MV="mv" |
| 367 screensaver_file="$HOME/.xdg-screensaver-"`echo $HOSTNAME-$DISPLAY | sed 's/:
/-/g'` | 367 screensaver_file="$HOME/.xdg-screensaver-"`echo $(hostname)-$DISPLAY | sed 's
/:/-/g'` |
| 368 fi | 368 fi |
| 369 lockfile_command=`which lockfile 2> /dev/null` | 369 lockfile_command=`which lockfile 2> /dev/null` |
| 370 | 370 |
| 371 lockfile() | 371 lockfile() |
| 372 { | 372 { |
| 373 if [ -n "$lockfile_command" ] ; then | 373 if [ -n "$lockfile_command" ] ; then |
| 374 $lockfile_command -1 -l 10 -s 3 "$screensaver_file".lock | 374 $lockfile_command -1 -l 10 -s 3 "$screensaver_file".lock |
| 375 else | 375 else |
| 376 # Poor man's attempt at doing a lockfile | 376 # Poor man's attempt at doing a lockfile |
| 377 # Be careful not to facilitate a symlink attack | 377 # Be careful not to facilitate a symlink attack |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 fi | 437 fi |
| 438 fi | 438 fi |
| 439 | 439 |
| 440 } | 440 } |
| 441 | 441 |
| 442 cleanup_suspend() | 442 cleanup_suspend() |
| 443 { | 443 { |
| 444 lockfile | 444 lockfile |
| 445 test "${TMPDIR+set}" = set || TMPDIR=/tmp | 445 test "${TMPDIR+set}" = set || TMPDIR=/tmp |
| 446 tmpfile=`mktemp $TMPDIR/tmp.XXXXXXXXXX` | 446 tmpfile=`mktemp $TMPDIR/tmp.XXXXXXXXXX` |
| 447 grep -v "$window_id:" "$screensaver_file" > "$tmpfile" 2> /dev/null | 447 grep -v "$window_id:$xprop_pid\$" "$screensaver_file" > "$tmpfile" 2> /dev/nul
l |
| 448 $MV "$tmpfile" "$screensaver_file" | 448 $MV "$tmpfile" "$screensaver_file" |
| 449 if [ ! -s "$screensaver_file" ] ; then | 449 if [ ! -s "$screensaver_file" ] ; then |
| 450 rm "$screensaver_file" | 450 rm "$screensaver_file" |
| 451 unlockfile | 451 unlockfile |
| 452 # $screensaver_file is empty, do resume | 452 # $screensaver_file is empty, do resume |
| 453 perform_action resume | 453 perform_action resume |
| 454 else | 454 else |
| 455 unlockfile | 455 unlockfile |
| 456 fi | 456 fi |
| 457 } | 457 } |
| 458 | 458 |
| 459 do_resume() | 459 do_resume() |
| 460 { | 460 { |
| 461 lockfile # Obtain lockfile | 461 lockfile # Obtain lockfile |
| 462 # Find the PID of the trackingprocess | 462 # Find the PID of the trackingprocess |
| 463 xprop_pid=`grep "$window_id:" "$screensaver_file" 2> /dev/null | cut -d ':' -f
2` | 463 xprop_pid=`grep "$window_id:" "$screensaver_file" 2> /dev/null | cut -d ':' -f
2` |
| 464 unlockfile # Free lockfile | 464 unlockfile # Free lockfile |
| 465 if [ -n "$xprop_pid" ] && ps -p "$xprop_pid" 2> /dev/null | grep xprop > /dev/
null; then | 465 if [ -n "$xprop_pid" ] && ps -p "$xprop_pid" 2> /dev/null | grep xprop > /dev/
null; then |
| 466 # Kill the tracking process | 466 # Kill the tracking process |
| 467 kill -TERM $xprop_pid | 467 kill -s TERM $xprop_pid |
| 468 fi | 468 fi |
| 469 cleanup_suspend | 469 cleanup_suspend |
| 470 } | 470 } |
| 471 | 471 |
| 472 XPROP=`which xprop 2> /dev/null` | 472 XPROP=`which xprop 2> /dev/null` |
| 473 | 473 |
| 474 check_window_id() | 474 check_window_id() |
| 475 { | 475 { |
| 476 if [ -z "$XPROP" ]; then | 476 if [ -z "$XPROP" ]; then |
| 477 DEBUG 3 "xprop not found" | 477 DEBUG 3 "xprop not found" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 IFS="$IFS_save" | 650 IFS="$IFS_save" |
| 651 ) > $tmpfile | 651 ) > $tmpfile |
| 652 if [ -s "$tmpfile" ] ; then | 652 if [ -s "$tmpfile" ] ; then |
| 653 # Suspend pending, don't do a thing | 653 # Suspend pending, don't do a thing |
| 654 $MV "$tmpfile" "$screensaver_file" | 654 $MV "$tmpfile" "$screensaver_file" |
| 655 unlockfile | 655 unlockfile |
| 656 return | 656 return |
| 657 fi | 657 fi |
| 658 $MV "$tmpfile" "$screensaver_file" | 658 $MV "$tmpfile" "$screensaver_file" |
| 659 unlockfile | 659 unlockfile |
| 660 (while [ -f "$screensaver_file" ]; do $*; sleep 59; done) > /dev/null 2> /dev/
null & | 660 (while [ -f "$screensaver_file" ]; do $*; sleep 50; done) > /dev/null 2> /dev/
null & |
| 661 } | 661 } |
| 662 | 662 |
| 663 screensaver_gnome() | 663 screensaver_gnome() |
| 664 { | 664 { |
| 665 # TODO | 665 # TODO |
| 666 # There seems to be a DBUS interface for gnome-screensaver | 666 # There seems to be a DBUS interface for gnome-screensaver |
| 667 # See http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2006-April/042579.html
and | 667 # See http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2006-April/042579.html
and |
| 668 # http://cvs.gnome.org/viewcvs/gnome-screensaver/src/gs-listener-dbus.c?rev=1.36
&view=log | 668 # http://cvs.gnome.org/viewcvs/gnome-screensaver/src/gs-listener-dbus.c?rev=1.36
&view=log |
| 669 # A problem seems to be that Inhibit is tied to the lifetime of the DBUS appname
and | 669 # A problem seems to be that Inhibit is tied to the lifetime of the DBUS appname
and |
| 670 # this can not be used from a script | 670 # this can not be used from a script |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 if [ "$action" = "suspend" ] ; then | 826 if [ "$action" = "suspend" ] ; then |
| 827 # Start tracking $window_id and resume the screensaver once it disappears | 827 # Start tracking $window_id and resume the screensaver once it disappears |
| 828 ( track_window ) 2> /dev/null > /dev/null & | 828 ( track_window ) 2> /dev/null > /dev/null & |
| 829 fi | 829 fi |
| 830 | 830 |
| 831 if [ $result -eq 0 ]; then | 831 if [ $result -eq 0 ]; then |
| 832 exit_success | 832 exit_success |
| 833 else | 833 else |
| 834 exit_failure_operation_failed | 834 exit_failure_operation_failed |
| 835 fi | 835 fi |
| OLD | NEW |