Loading of xinitrc,xserverrc,xresources,xdefaults,xprofile,xsession,xmodmap - Desktop Customization & Workflow

Users browsing this thread: 3 Guest(s)
venam
Administrators
Hello nixers,
In a previous forums thread there was a discussion about certain X configuration files and their roles. Namely: xinitrc,xserverrc,xresources,xdefaults,xprofile,xsession,xmodmap. So let's try to clear up this mumbo jumbo of words.

There's roughly two ways to start your X environment, one is via xinit and the other is via a display manager (fancy login screen). Depending on which one you use, different configuration files will be loaded.


If starting via xinit, or startx which is a wrapper over xinit, then the ~/.xinitrc will be loaded, and if not present will load the global /etc/X11/xinit/xinitrc. This will run all the lines found in it, interpreted by /bin/sh and will stop at the last one. The X session will stop when that last program terminates.

If using the globally available xinitrc it will include in an alphabetical order sub-xinitrc found in the /etc/X11/xinit/xinitrc.d/.

That globally available xinitrc loads two more configurations:
  • Xresources, found in ~/.Xresources or /etc/X11/xinit/.Xresources which consists of the key/value pair accessible for all X clients, the resources. xinit executes xrdb -merge ~/.Xresources or xrdb with the global one.
  • Xmodmap, locally in ~/.Xmodmap and globally in /etc/X11/xinit/.Xmodmap. This will run xmodmap $thefile. So in theory instead of having all those xmodmap lines that we find so commonly in the .xinitrc file (I'm guilty of this too) we can separate them into a .Xmodmap file instead.

xinit/startx will finally start the X server, it does it by executing a script found in ~/.xserverrc or globally /etc/X11/xinit/xserverrc. This consists of simply:
Code:
exec /usr/bin/X -nolisten tcp "$@"
However, replacing this xserverrc allows us to start X in different ways.


What about initiating a graphical session from the display manager.

Instead of xinitrc the file loaded at login will be the Xsession file. So similar to xinitrc we have globally a default located at /etc/X11/Xsession.options along with a directory of sub-xsessions to be loaded in /etc/X11/Xsession.d. Also similar to xinit the default Xsession will load the Xresources. As for local configs there are many of them depending on what the type of session, I quote:

Quote:If the user has a ~/.xsessionrc file, read it. (used by all sessions types)
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.

Some specific display manager include in their default Xsession an extra configuration called Xprofile.

For example:
  • GDM - /etc/gdm/Xsession
  • LightDM - /etc/lightdm/Xsession
  • LXDM - /etc/lxdm/Xsession
  • SDDM - /usr/share/sddm/scripts/Xsession

Otherwise, if you want the Xprofile, you have to source the file manually from startx/xinit or XDM or any other display manager.


Now for something unrelated, Xdefaults is the old version of Xresources.

The way it was done in the old days is that Xdefaults was read every single time a client program (Xlib) was started, unlike Xresources which have properties stored in the root window/resource manager (think xrdb). So that means the old method, Xdefaults, couldn't be used over the network because you needed direct access to the file.

Now that gets a bit complicated because there could be multiple Xdefaults files found in different ways other than ~/.Xdefaults.

I quote:
Quote:There also is the $XENVIRONMENT variable, which defaults to ~/.Xdefaults-hostname ($XENVIRONMENT/.Xdefaults) if not set. This is used in the same way as .Xdefaults, but is always read regardless of whether RESOURCE_MANAGER is present. You can use .Xdefaults-hostname files to keep some settings machine-specific while using xrdb for the global ones

Quote:The fourth location is the directory pointed to by the $XAPPLRESDIR environment variable. (Oddly, if the variable is not set, $HOME is used as the default.) When a program is started, it looks if any of the following files exist (the file name being the same as the program's class name):
$XAPPLRESDIR/$LC_CTYPE/XTerm
$XAPPLRESDIR/language/XTerm
$XAPPLRESDIR/XTerm

Quote:The fifth location is the system-wide "app-defaults" directories. Again, the app-defaults directories are checked on program startup if they have a file named after the program. For example, XTerm (on Arch Linux) uses:

/etc/X11/$LC_CTYPE/app-defaults/XTerm
/etc/X11/language/app-defaults/XTerm
/etc/X11/app-defaults/XTerm
/usr/share/X11/$LC_CTYPE/app-defaults/XTerm
/usr/share/X11/language/app-defaults/XTerm
/usr/share/X11/app-defaults/XTerm

The app-defaults files are usually installed into /usr/share along with the program itself; administrator overrides would go to /etc.

I hope that helps clear things up.



References:

https://wiki.archlinux.org/index.php/Xinit
https://wiki.archlinux.org/index.php/X_resources
https://wiki.debian.org/Xsession
https://wiki.archlinux.org/index.php/Xprofile
https://superuser.com/questions/243914/w...lts#243916
evbo
Members
Well done on the writeup, venam. I use a pretty simple .xinitrc these days, and have generally stayed away from display managers as they seemed unnecessary vs a simple script.

I remember the old days, back when I first started to use Debian... wrapping my head around early 2000's X configuration was real difficult for a complete newbie with no internet access at home. I basically had to fiddle with it until I got stuck, then use the computers at school to lookup information. I was also lucky that the local library had an excellent selection of UNIX and Linux books that I would check out constantly.
jkl
Long time nixers
(22-04-2019, 05:26 AM)venam Wrote: Hello nixers,
I hope that helps clear things up.

Let me confuse the nixers a bit:

1. You're talking about X11. What about X10? ;-)
2. With XWayland, the latest installment in the "we need a backwards-compatible X replacement which does everything differently than X" series, .Xresources is probably a file that needs to be loaded explicitly - as always, depending on the distribution's maintainers, I guess. (Welp, Red Hat...)
3. All folders mentioned above could be somewhere else than where you'd think they are.

--
<mort> choosing a terrible license just to be spiteful towards others is possibly the most tux0r thing I've ever seen
z3bra
Grey Hair Nixers
(22-04-2019, 06:56 PM)jkl Wrote: 1. You're talking about X11. What about X10? ;-)
2. With XWayland, the latest installment in the "we need a backwards-compatible X replacement which does everything differently than X" series, .Xresources is probably a file that needs to be loaded explicitly - as always, depending on the distribution's maintainers, I guess. (Welp, Red Hat...)
3. All folders mentioned above could be somewhere else than where you'd think they are.

The best questions would actually be "What about X2, X3, X4, X5, X7, X8 ?" :-P

As for the .Xresources, it as always been a file to load explicitely. It just happens that some default configurations load it by default:
Code:
$ grep userresources /etc/X11/xinit/xinitrc
userresources=$HOME/.Xresources
if [ -f "$userresources" ]; then
    xrdb -merge "$userresources"

This, of course, is up to the distro maintainers ;-)

What bother me with X11 though, is that it is designed to be a network protocol, yet you never see it in the wild (besides perhaps X11 forwarding over ssh).
X being a "network protocol" should allow awesome stuff like what you get on plan9, where your whole system is spread on multiple machines. Why don't we have people providing "graphics as a service" or similar?
Why do we have to use stuff like X11VNC or ffserver? Is it a lack of knowledge? Did X11 failed at being what it is?