#!/bin/sh

LIST=`ps ax --format "%p:%a" | grep "$0.bin" | grep -v grep | cut -d : -f 1 | tail -n +1`

echo $LIST on $DISPLAY | logger -t "kdesktop_lock"
# check if DISPLAY is open, if not TTFN
test -n "$DISPLAY" || exit

# loop through all kdesktop_locks.bin, and 
# check if any are running on current display
for P in $LIST; do
	D=`grep -z DISPLAY /proc/$P/environ|cut -f2 -d=`
	M=`grep -z KDE_MULTIHEAD /proc/$P/environ|cut -f2 -d=`
	if [ "$D" == "$DISPLAY" ] ; then
		exit
	fi
	if [ "$M" == "true" -a "$KDE_MULTIHEAD" == "true" ] ; then
		exit
	fi
done

# run lock
$0.bin "$@"
