#!/bin/sh
# This script launch a window manager when user calls 
# startx from a text console
#
# Licence : GNU GPL
# (c) Eko M. Budi, 2004
# (c) Vector Linux, 2004
#

# It search a Window manager according to the WMLIST
# Change this to reorder the priotity
WMLIST="XwmMenu starticewm startfluxbox startkde startxfce4"

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/usr/X11R6/lib/X11/xinit/.Xresources
sysmodmap=/usr/X11R6/lib/X11/xinit/.Xmodmap

# merge in defaults and keymaps

if [ -f $sysresources ]; then
    xrdb -merge $sysresources
fi
if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap
fi
if [ -f $userresources ]; then
    xrdb -merge $userresources
fi
if [ -f $usermodmap ]; then
    xmodmap $usermodmap
fi

# Launch xscreensaver if available, but only as non-root user
if test $UID -gt 0 && which xscreensaver 1>/dev/null 2>&1; then
    xscreensaver -no-splash &
fi

# Load X settings
if [ -x $HOME/.xset.sh ]; then
   . $HOME/.xset.sh
fi

# Allow su to launch X apps
# Warning, this is a security threat
# Turn it OFF when you are not using su very often
# see "man Xsecurity" for detail
xhost +si:localuser:root

for WM in $WMLIST; do
   which $WM &> /dev/null
   if [ $? = 0 ]; then
      exec $WM
   fi
done
