#!/bin/bash
#
# Sample .xinitrc for SuSE Linux
# This script is called from 'startx' when you start an X session
#

#
# In case everything goes wrong, we at least fall back to a plain xterm
#
failsafe="xterm -ls -T Failsave -geometry 80x24-0-0"
trap "exec $failsafe" EXIT SIGHUP SIGINT SIGPIPE SIGTERM SIGIO

#
# Some bash (1 and 2) settings to avoid trouble on a
# failed program call.
#
test -n "$BASH" && set +o posix
no_exit_on_failed_exec=1
type shopt > /dev/null 2>&1 && shopt -s execfail
set +e > /dev/null 2>&1

#
# This should be the default
#
export TERM=xterm

#
# choose a window manager
#
if test -n "$WINDOWMANAGER" ; then
    WINDOWMANAGER=`type -p $WINDOWMANAGER`
fi
if test -z "$WINDOWMANAGER" ; then
    if test -x /usr/X11R6/bin/kde ; then
        WINDOWMANAGER=/usr/X11R6/bin/kde
    elif test -x /usr/X11R6/bin/startkde ; then
        WINDOWMANAGER=/usr/X11R6/bin/startkde
    elif test -x /usr/X11R6/bin/fvwm2 ; then
        WINDOWMANAGER=/usr/X11R6/bin/fvwm2
    elif test -x /usr/X11R6/bin/wmlist ; then
        for i in `/usr/X11R6/bin/wmlist` ; do
            WINDOWMANAGER=`type -p $i`
            test -n "$WINDOWMANAGER" && break
        done
    elif test -x /usr/X11R6/bin/twm ; then
        WINDOWMANAGER=/usr/X11R6/bin/twm
    fi
fi

if test -z "$WINDOWMANAGER" ; then
    echo "Error: Unable to find a window manager. Please make sure you installed one!"
    echo "Exiting..."
    xmessage -timeout 10 -default okay -center -file - <<-EOF
	Error: Unable to find a window manager. Please make sure you installed one!
	Exiting...
	EOF
    exit 1
fi

#
# Load system and users resources if not already done
# (XSESSION_IS_UP set by xdm in $XLIBDIR/xdm/Xsession)
#
if test "$XSESSION_IS_UP" != "yes" ; then
    XLIBDIR=/usr/X11R6/lib/X11
    test -r $XLIBDIR/Xmodmap    && xmodmap $XLIBDIR/Xmodmap
    test -r $HOME/.Xmodmap      && xmodmap $HOME/.Xmodmap
    test -r $XLIBDIR/Xresources && xrdb -load -retain $XLIBDIR/Xresources
    test -r $HOME/.Xdefaults    && xrdb -I$HOME -merge $HOME/.Xdefaults
    test -r $HOME/.Xresources   && xrdb -I$HOME -merge $HOME/.Xresources
fi

# Start the XIM server
test -r $HOME/.xim && source $HOME/.xim

# Enable Numlock if set
test -r /var/run/numlock-on -a -x /usr/X11R6/bin/numlock && /usr/X11R6/bin/numlock

# Disable new Xcursor themes if none is specified resp. located in $HOME
# (use "unset XCURSOR_CORE" to enable them again later)
#if [ "x$XCURSOR_THEME" == "x" -a ! -d $HOME/.icons ]; then 
#  export XCURSOR_CORE=true
#else
#  unset XCURSOR_CORE
#fi

# Prevent keyboard bouncing for Toshiba Notebooks
# Means, disable AccessX
test -r /etc/sysconfig/sax && source /etc/sysconfig/sax
if [ "x$KBD_BOUNCE_FIX" = "xyes" ]; then
	test -x /usr/X11R6/bin/xbounce && /usr/X11R6/bin/xbounce
fi

#
# Add your own lines here...
#


# day planer deamon
# pland &

# 
# finally start the window manager
#
exec $WINDOWMANAGER 

# call failsafe
exit 0

