#! /bin/bash
#
# openbox		Fix time shift during long suspend problem
#
# description: 		During long suspend openbox select() has lock up
#			because timers mad awake in another time

OBOX=/tmp/.openbox.time

# See how we were called.
  
suspend() {
  date +%s > $OBOX
  return 0
}

resume() {
    local TB
    local TE
    local TM
    local P
    
    test -e $OBOX || return 0
    
    TB=`cat $OBOX`
    TE=`date +%s`
    TM=`dc $TE $TB - p`

    if [ $TM -gt 21600 ]; then
	P=`pidof openbox`
	test $P && kill -SIGUSR1 $P
    fi
    rm -f $OBOX

    return 0
}	


case "$1" in
  suspend)
  	suspend
	;;
  resume)
  	resume
	;;
  *)
	echo "Usage: $0 {suspend|resume}"
	exit 1
esac

exit $?
