These two files seem to have the same function. What is the difference between the two if any?
Xorg – Difference Between .Xresources and .Xdefaults
xorg
xorg
These two files seem to have the same function. What is the difference between the two if any?
Best Answer
~/.Xdefaults
is the older method of storing X resources. This file is re-read every time an Xlib program is started. If X11 is used over the network, the file must be present on the same filesystem as the programs.~/.Xresources
is newer. It is loaded withxrdb
into theRESOURCE_MANAGER
property of the X11 root window. Whenever any program looks up a resource, it is read straight fromRESOURCE_MANAGER
.If this property does not exist, Xlib falls back to the old method of reading
.Xdefaults
on every program startup. Note that most distributions will load~/.Xresources
automatically if it is present, causing.Xdefaults
to be ignored even if you have never runxrdb
manually.The advantage of the new method is that it's enough to call
xrdb
once, and the resources will be available to any program running on this display, whether local or remote. (The name~/.Xresources
is only a convention – you can usexrdb
to load any file, even.Xdefaults
.)Xlib Programming Manual P.441:
Wikipedia:
It doesn't quite end at that.
$XENVIRONMENT
variable, which defaults to~/.Xdefaults-hostname
if not set. This is used in the same way as.Xdefaults
, but is always read regardless of whetherRESOURCE_MANAGER
is present. You can use.Xdefaults-hostname
files to keep some settings machine-specific while usingxrdb
for the global ones.Both items #4 and #5 listed below appear to be used only by pure Xlib programs – not GTK 3 or other toolkits.
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
(
language
is derived from$LC_CTYPE
by stripping all but the first component; for example,en_US.utf-8
→en
.)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
.Everything mentioned above is documented in great detail in the X.org toolkit documentation – article X Toolkit Intrinsics - C Language Interface, section Loading the Resource Database.
Unfortunately, I could not find any recent user guide that describes X resources, mostly because they are irrelevant in year 2012. But for historical (read: horribly out of date) information, you can read X Window System user's guide for X11 R3 and R4 of the X Window System section 9: Setting Resources (starting with page 181).