Configuring your system to use
This chapter assumes that your system is already configured to run the X Window System, and that you only need to reconfigure it to allow graphical login.

Setting up
The fundamental thing that controls whether your computer boots to a terminal prompt (console mode) or a graphical login prompt is the default runlevel. The runlevel is set by the program /sbin/init under the control of the configuration file /etc/inittab. The default runlevels used by different Unix systems (and different Linux distributions) vary, but if you look at /etc/inittab the start of it should be something like this:

# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)

id:3:initdefault:

All but the last line of this extract are comments. The comments show that runlevel 5 is used for X11 and that runlevel 3 is used for multi-user mode without X11 (console mode). The final line specifies that the default runlevel of the system is 3 (console mode). If your system currently uses graphical login (for example, using xdm) its default runlevel will match the runlevel specified for X11.
The runlevel with graphical login (xdm) for some common Linux distributions are:
5 for Red Hat 3.x and later, and for Mandrake
4 for Slackware
3 for S.u.S.E. 4.x and 5.x
The first step in configuring your system is to ensure that you can start from the command line. Once this is working, you can change your system configuration so that starts automatically each time you reboot your system.
To test , you must first bring your system to a runlevel that doesn't run xdm. To do so, issue a command like this:

/sbin/init 3

Instead of the number "3" you should specify the appropriate runlevel for console mode on your system.
Next you need to locate your xdm configuration directory; normally /etc/X11/xdm/ or /usr/X11R6/lib/X11/xdm/. The configuration directory contains the file Xsetup_0. If you build from source code and the configure step is unable to find this directory, it will install a new version of Xsetup_0 from a template file in the source tree. You can include the line:

kdmdesktop

In your file to display some nice backgrounds (pictures and background colors). (I'm not sure if this still works; it is certainly not required). If your KDEDIR is not /opt/kde you may have to change the path to kdmdesktop.
If your system uses Pluggable Authentication Modules (PAM), which is normal with recent Red Hat and Mandrake systems, you should check that your PAM configuration permits login through the service named xdm. If you previously used xdm successfully, you should not need to make any changes to your PAM configuration in order to use . /etc/pam.conf or /etc/pam.d/xdm. Information on configuring PAM is beyond the scope of this handbook, but PAM comes with comprehensive documentation (try looking in /usr/doc/pam*/html).
Now it's time for you to test by issuing the following command:

kdm -nodaemon

If you get a login box and you are able to log in, things are going well. The main thing that can go wrong here is that the run-time linker might not find the shared Qt or KDE libraries. If you have a binary distribution of the KDE libraries, make sure is installed where the libraries believe kde is installed (usually /opt/kde/bin) and try setting some environment variables to point to your KDE and Qt libraries. For example:

export 
KDEDIR=/opt/kde
export 
QTDIR=/usr/lib/qt2
export 
PATH=$KDEDIR/bin:$QTDIR/bin:$PATH
export 
LD_LIBRARY_PATH=$KDEDIR/lib:$QTDIR/lib

If you are still unsuccessful, try starting xdm instead, to make sure that you are not suffering from a more serious X configuration problem.
When you are able to start successfully, you can start to replace xdm by . Again, this is distribution-dependent.
For Redhat, edit /etc/inittab, look for the string xdm and replace it with (including all paths).
For Mandrake, the X11 runlevel in /etc/inittab invokes the shell script /etc/X11/prefdm, which is set up to select from amongst several display managers, including . Make sure that all the paths are correct for your installation.
For S.u.S.E, edit /sbin/init.d/xdm to add a first line:

. /etc/rc.config
DISPLAYMANAGER=kdm
export DISPLAYMANAGER

Most other distributions are a variation of one of these.
If you don't like changing inittab, an alternative is to rename xdm to xdm.bak and make xdm a symbolic link to .
At this stage, you can test again by bringing your system to the runlevel that should now run . To do so, issue a command like this:

/sbin/init 5

Instead of the number "5" you should specify the appropriate runlevel for running X11 on your system.
The final step is to edit the initdefault entry in /etc/inittab to specify the appropriate runlevel for X11.
Before you make this change, ensure that you have a way to reboot your system if a problem occurs. This might be a "rescue" floppy-disk provided by your operating system distribution or a specially-designed "rescue" floppy-disk, such as tomsrtbt. Ignore this advice at your peril.
When you reboot your system, you should end up with the graphical login box.
If this step is unsuccessful the most likely problem is that the environment used at boot time differs from the environment that you used for testing at the command line. Check files like /etc/X11/xdm/Xsetup_0 (and any scripts that it invokes) to make sure that your path is not being changed without your knowledge. If you are trying to get two versions of KDE to co-exist, be particularly careful that the settings you use for your PATH and LD_LIBRARY_PATH environent variables are consistent, and that the startup scripts are not over-riding them in some way.

Supporting multiple window managers
The main dialogue box for includes a "session type" drop-down box, which allows you to select a window manager to use for your session. This chapter describes the changes that you must make to your configuration files in order to support this feature.
The options that appear in the "session type" drop-down box are configured by entries in the KDM section of kdmrc.
When you log in using , the shell script Xsession is executed. The session type that you select is passed as a command-line argument. (Xsession can be found in /etc/X11/xdm/ for Redhat and Mandrake, and in /usr/X11R6/lib/X11/xdm/ for S.u.S.E.). Whilst debugging, you might find it helpful to add this line to Xsession:

echo "$0 || $1 || $2" > $HOME/.Xsession_args

How you proceed now depends upon how your system usually starts up window managers. Here are two different approaches, with examples of the changes that you must make:
The window manager is started by commands within Xsession. In this case, you can add a case statement to start the appropriate window manager. Linux Mandrake uses this approach; here is an extract from Xsession:

# now, we see if xdm/gdm/kdm has asked for a specific environment
case $# in
1)
    case $1 in
        kde)
        source /opt/kde2/bin/kde1
        exec startkde
        ;;
        kde2)
        source /opt/kde2/bin/kde2
        exec startkde
        ;;
    	failsafe)
	exec xterm -geometry 80x24-0-0
	;;
	default)
	;;
	*)
	exec /bin/sh -c "$(/usr/sbin/chksession -x=$1)"
	;;
     esac
esac

The window manager is started by another script that is invoked by Xsession. In this case you must ensure that the parameter passed to Xsession is passed on to that other script. For example, if the window manager is started like this:

exec $startup

you would need to change it to:

exec $startup $@

Having made this change, you must trace your way through the startup to find the place where the window manager is started. One approach uses xinitrc to start the window manager; this allows a system-wide file /etc/X11/xinit/xinitrc or a user-specific file $HOME/.xinitrc to be used. If you edit $HOME/.xinitrc, you may want to save a copy in /etc/skel, so that it will be automatically generated in every user account you create from now on. Here is an example xinitrc for a system using this approach:

#!/bin/bash
#
# .xsession/.xinitrc
#
# choose a window manager
#

defaultwm=kde
#set the window manager to $1 if it was supplied
windowmgr=${1:-$defaultwm}

#start the respective window managers
case ${windowmgr} in
  kde|kwm|kdestart)
	WINDOWMANAGER=startkde
	;;
  fvwm|fvwm2)
	WINDOWMANAGER=fvwm2
	;;

  fvwm95)
	WINDOWMANAGER=fvwm95
	;;

  *)    WINDOWMANAGER=windowmgr   # default for unknown wm's

esac

#
# load resources
#

if [ -f /usr/X11R6/lib/X11/Xmodmap ]; then
    xmodmap /usr/X11R6/lib/X11/Xmodmap
fi

if [ -f ~/.Xmodmap ]; then
    xmodmap ~/.Xmodmap
fi

if [ -f ~/.Xdefaults ]; then
    xrdb -merge ~/.Xdefaults
fi

if [ -f ~/.Xresources ]; then
    xrdb -merge ~/.Xresources
fi
# 
# finally start the window manager
#
exec $WINDOWMANAGER