#!/bin/sh
#
# Initialization script. Must be called from $HOME/.xinitrc or equivalent.
#

WDIR=$HOME/gnustep/Library/WindowMaker




# search program in PATH
checkprog() {
	oIFS="$IFS"
	IFS="${IFS}:"	
	for pdir in $PATH; do
		if [ -f $pdir/$1 ]; then
			return 0
		fi
	done
	IFS="$oIFS"
	return 1
}


# set root background color
if [ -f $WDIR/.rootbg ]; then
	sh $WDIR/.rootbg&
fi



rm -f .autodetect
#
# find image loader

if checkprog display; then
	echo "#define TILEROOT display -window root" > $WDIR/.autodetect 
elif checkprog xv; then
	echo "#define TILEROOT xv -root -quit -rmode 2" > $WDIR/.autodetect 
fi

#
# file selector
if checkprog xgetfile; then
	echo "#define GETFILE(t) xgetfile -title t" >> $WDIR/.autodetect 
fi

#
# savews
if checkprog savews; then
	echo '#define SAVEWS savews' >> $WDIR/.autodetect 
else
	WMPATHS="/usr/local/GNUstep/Apps/WindowMaker.app /usr/GNUstep/Apps/WindowMaker.app"
	for pdir in $WMPATHS; do
		echo $pdir
		if test -f $pdir/savews; then
			echo "#define SAVEWS $pdir/savews" >> $WDIR/.autodetect
			break
		fi
	done
fi


# call saved clients
if [ -f $WDIR/.workspace_state ]; then
	sh $WDIR/.workspace_state
elif [ -f $HOME/.workspace_state ]; then
	sh $HOME/.workspace_state
fi

