Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

These two files seem to have the same function. What is the difference between the two if any?

share|improve this question

1 Answer 1

up vote 36 down vote accepted

~/.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 with xrdb into the RESOURCE_MANAGER property of the X11 root window. Whenever any program looks up a resource, it is read straight from RESOURCE_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 run xrdb 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 use xrdb to load any file, even .Xdefaults.)

Xlib Programming Manual P.441:

Prior to X11R2, X resource settings were read from .Xdefaults file in users home directory and optionally on whatever machine the X client was running on, so multiple files was hard to maintain.

Later on, xrdb program was made to store users resource settings from in .Xresources into the XA_RESOURCE_MANAGER property of the root window on the current X server, so all clients connected to the same server has access to them. If the user hasn't called xrdb to set the property, then .Xdefaults is read.

Wikipedia:

[...] the X resources are stored in two standard locations, depending on whether they apply to all screens or to a particular one:

  • the RESOURCE_MANAGER property of the root window of screen 0
  • the SCREEN_RESOURCES property of the root window of an arbitrary screen

It doesn't quite end at that.

  • There also is the $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 whether RESOURCE_MANAGER is present. You can use .Xdefaults-hostname files to keep some settings machine-specific while using xrdb 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-8en.)

  • 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).

share|improve this answer
    
Great answer, but it should be noted that not all implementations follow the rules correctly. For instance, I remember SunOS 4 and Solaris 6 apps would not pick up .Xdefaults changes unless I explicitly ran "xrdb" afterward. There can also be some weirdness when the app and the X server are running on different hosts. Some apps read the local file and some read the database from the X server. –  David C. Sep 17 at 15:30
    
@DavidC.: That Xdefaults behavior is following the rules described above. If xrdb has ever been run for this X display since login – that is, if the X root property exists – then xlib will not use .Xdefaults at all anymore. –  grawity Sep 17 at 18:17
1  
That makes sense. But there are still many apparently-borken apps which will read the contents of ~/.Xresources and ignore the xrdb database. Which can be really annoying if you slogin to a different host (that has a different .Xresources) and find that the app isn't displaying its contents the way it does when run locally. –  David C. Sep 17 at 20:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.