When you start the X Window System on Debian, an X session will be created. There are a few different types of X sessions; this page describes the default Debian X session, and how to work with it.
The man pages Xsession(5) and Xsession.options(5) offer technical descriptions.
Starting the Debian X session
Some display managers may offer a choice of session types. If you select something other than a Debian X session, the remainder of this page may not apply completely.
System-wide configuration of the Debian X session consists mainly of options inside the /etc/X11/Xsession.options file, and scripts inside the /etc/X11/Xsession.d directory. These scripts are all dotted in by a single /bin/sh shell, in the order determined by sorting their names. Administrators may edit the scripts, though caution is advised if you are not comfortable with shell programming.
The Debian reference manual describes how the defaults work:
If the user has a ~/.xsessionrc file, read it.
- If a specific session was selected in the DM (GDM, KDM, WDM, LightDM, ...) , run it.
Otherwise, if the user has a ~/.xsession or ~/.Xsession file, run it.
Otherwise, if the /usr/bin/x-session-manager command exists, run it.
Otherwise, if the /usr/bin/x-window-manager command exists, run it.
Otherwise, if the /usr/bin/x-terminal-emulator command exists, run it.
User configuration may be done in a few different ways. The simplest way is to create a ~/.xsessionrc file, which will be used by all X session types. It is read by a POSIX shell (/bin/sh, typically provided by dash). You should avoid using features that are not supported in POSIX sh.
There are typically three kinds of commands you may wish to use in this file:
You may place environment variable definitions here, directly: export SOME_VAR="some value"
You may dot in some other POSIX shell configuration file: if [ -r ~/.profile ]; then . ~/.profile; fi
You may directly run X client programs: xclock -geometry +0+0 &
If you choose to run an X client program, make sure it either terminates quickly on its own (e.g. xmodmap or xset or xsetbg commands), or that you run it in the background by terminating the command with the shell's & operator. Also note that because ~/.xsessionrc is read very early, any settings you place here may be overridden by your window manager or desktop environment, later in the login sequence.
If you selected a GNOME session, additional configuration will be read from the ~/.gnomerc file, if it exists.
A more advanced alternative is to use the ~/.xsession file. This file, if it exists, is used instead of the system-wide default x-session-manager or x-window-manager. Therefore, if you use it, you must ensure that it launches your desired window manager (WM) or desktop environment (DE).
Here is a simplistic ~/.xsession example:
xsetroot -solid gray xmodmap -e "keysym Super_L = Multi_key" xset s off; xset dpms 0 1800 0 exec fvwm
As with ~/.xsessionrc, any X client applications that you run before the WM or DE should either be naturally short-lived, or launched explicitly in the background. The final command in the script should be an exec which runs your WM's or DE's regular start command. (If you are unsure how to determine this, consult your WM or DE documentation, or stick with the simpler ~/.xsessionrc.)
Finally, note that the ~/.xsession file is only read if you are using a Debian X session. If you login with gdm3 and choose a GNOME session, the ~/.xsession file will be ignored completely. (But you may still use ~/.xsessionrc.)