#!/bin/sh
MY_NAME="xscreensaver-scripts.sh"
MY_VERSION="2001.09.11"
# Mon Sep 10 20:27:12 EDT 2001
# GPL < http://www.gnu.org/copyleft/gpl.html >
# (c) by Jouni.Lohikoski+xscreensaver-scripts@iki-nospam.fi

# Usefull (?) when wanting to run configurable scripts on xscreensaver (1)
# sleep and wakeup events. Personally I needed this to put galeon processes
# in STOP-mode when xscreensaver is "saving the screen", and CONT them when
# I want to use the system again. So I just have "killall -q -STOP galeon-bin"
# and "killall -q -CONT galeon-bin" in those scripts defined with SLEEP_SCRIPT
# and WAKEUP_SCRIPT (below).

# To make this work, well, to make sense, you would have to disable all
# other xscreensaver demo-programs in the preferences. If you do not run
# any programs, which will draw to the root window in the sleep- and
# wakeup-scripts, the screen will be blank.
# Read xscreensaver (1) manual page how # to add this xscreensaver-scripts.sh
# to one of the available xscreensaver programs. (to your .xscreensaver file) 
# Basically, you just insert there (~/.xscreensaver) for example this:
# '
# programs:   \
#      "xscreensaver-scripts"  /usr/local/bin/xscreensaver-scripts.sh \n\
# '	

# SLEEP_SCRIPT is a command or script which is run when the xscreensaver
# blanks the screen and activates. WAKEUP_SCRIPT is a command or script
# which is run when xscreensaver daemon sends SIGTERM to *this* script
# meaning there is user active on the X console again.
#
# Do not forget to set executable bits (flags) on the script files.

SLEEP_SCRIPT="$HOME/.xscreensaver-scripts-sleep.sh"
WAKEUP_SCRIPT="$HOME/.xscreensaver-scripts-wakeup.sh"

# If the above named scripts do not exist, it is not complained, just
# ignored.

#############################################################################

# We get session id of this running process, so we can later in the end
# kill children (sleep program) when this process is already TERMinated.
SID=`ps -o sid h $$`
KILL_CHILDREN="kill -TERM \`ps -s $SID -o pid h|grep -v $$|grep -v $PPID\`"

# We setup the wake-up script, which is executed when this script gets SIGTERM
# sent by xscreensaver daemon.
if [ -x "$WAKEUP_SCRIPT" ]; then
    trap "$WAKEUP_SCRIPT;$KILL_CHILDREN" EXIT
fi

# Run the sleep script.
if [ -x "$SLEEP_SCRIPT" ]; then
    source $SLEEP_SCRIPT
fi    

# Wait and loop forever, until xscreensaver (or some other) kills us.
while true;do sleep 360000;done



