Skip to content

Instantly share code, notes, and snippets.

@deomorxsy
Last active October 26, 2023 15:54
Show Gist options
  • Save deomorxsy/abdeea29ae42257bb268f4d60b892774 to your computer and use it in GitHub Desktop.
Save deomorxsy/abdeea29ae42257bb268f4d60b892774 to your computer and use it in GitHub Desktop.
Xinit's precedence order after invoked with startx

Part I

"If you log in in text mode then start a GUI session with xinit or with the wrapper script startx, then xinit does the following things:

  • Start an X server (typically through the script /etc/X11/xinit/xserverrc).
  • Usually run some scripts in /etc/X11 (typically /etc/X11/xinit/xinitrc), depending on how it's set up.
  • Run ~/.xinitrc, if it exists. If it doesn't exist, run a default client (traditionally xterm).
  • Once ~/.xinitrc terminates, kill the X server.

If you log in in graphical mode on an X display manager (xdm, gdm, kdm, wdm, lightdm, …), traditionally, what is executed after you log in is some scripts in /etc/X11 then ~/.xsession.

~/.xsession has the role of ~/.profile and ~/.xinitrc combined: it's supposed to perform the initial startup of your session (e.g. define environment variables), then launch programs specific to the GUI (usually at least window manager).

Nowadays, most X display managers give you a choice of a session. Choosing a particular session launched a specific desktop environment, session manager, window manager. What is executed then is only that DE/SM/WM and whatever programs it chooses to start based on whatever configuration files it chooses to read. Many environments provide a “custom session” that reads the traditional ~/.xsession. "


source: Gilles 'SO- stop being evil''s comment on "What is “.xsession” for?"

Part II

"~/.xinitrc is executed by xinit, which is usually invoked via startx. This program is executed after logging in: first you log in on a text console, then you start the GUI with startx. The role of .xinitrc is to start the GUI part of the session, typically by setting some GUI-related settings such as key bindings (with xmodmap or xkbcomp), X resources (with xrdb), etc., and to launch a session manager or a window manager (possibly as part of a desktop environment).

~/.xsession is executed when you log in in graphical mode (on a display manager) and the display manager invokes the “custom” session type. (With the historical display manager xdm, .xsession is always executed, but with modern display managers that give the user a choice of session type, you usually need to pick “custom” for .xsession to run.) Its role is both to set login-time parameters (such as environment variables) and to start the GUI session. A typical .xsession is

#!/bin/sh
. ~/.profile
. ~/.xinitrc

~/.xsessionrc is executed on Debian (and derivatives such as Ubuntu, Linux Mint, etc.) by the X startup scripts on a GUI login, for all session types and (I think) from all display managers. It's also executed from startx if the user doesn't have a .xinitrc, because in that case startx falls back on the same session startup scripts that are used for GUI login. It's executed relatively early, after loading resources but before starting any program such as a key agent, a D-Bus daemon, etc. It typically sets variables that can be used by later startup scripts. It doesn't have any official documentation that I know of, you have to dig into the source to see what works.

.xinitrc and .xsession are historical features of the X11 Window system so they should be available and have a similar behavior on all Unix systems. On the other hand, .xsessionrc is a Debian feature and distributions that are not based on Debian don't have it unless they've implemented something similar.

.xprofile is very similar to .xsessionrc, but it's part of the session startup script of GDM (the GNOME display manager), so it's only read if you log in with GDM."


source: Gilles 'SO- stop being evil''s comment on Difference between .xinitrc, .xsession and .xsessionrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment