blog of pesa

.Xdefaults vs .Xresources

Many X programs have user-level configuration options that can be set in the X server’s resource database.

The two most common ways to achive persistent configuration for your X programs are to store them in either ~/.Xdefaults or ~/.Xresources files.

I will not go into detail of the syntax of these files. However, there are some things to take into consideration between the choice of the two files.

Consider the X program xterm. You want to make the background black and the foreground white. This can be achived by passing some command line arguments to xterm:

$ xterm -bg black -fg white

This is fine if you want this for only one time, but if you want it to be the default you put it in a configuration file.

XTerm*background: black
XTerm*foreground: white

If you put this in the ~/.Xdefaults file you will notice that the next time you start an xterm it has the new colors. Great! Or, is it?
It is easy to change configuration options and it will be in effect next time you start the program, but it comes at the cost that basically all X programs needs to parse this file everytime you run one.

A better way is to put the configuration options in the ~/.Xresources file and store the configuration in the X server’s resource database by using the xrdb command:

$ xrdb -merge ~/.Xresources

Doing this, (in simple terms) xterm will “ask” the X server for its resource options rather than reading a file. This is much quicker and avoids unnecessary reads on disk.
Another great thing about this is that remote X programs (e.g., tunneled through SSH) will be able to catch these options.

Once configurations are read into the X server’s resource databse (using xrdb), X programs should not look for configuration options in ~/.Xdefaults file.

As many desktop environments (like Gnome or KDE) will store the configurtion from both files into the resource database upon the start of X, the drawbacks stated above may not be a problem.
However, if you don’t run a desktop environment (like me) you need to manually run xrdb when starting X (e.g., by adding xrdb command line above to the ~/.xinitrc file).

If you run xrdb manually, you can of course name the ~/.Xresources file whatever you want, but it’s the defacto standard.

This entry was posted on Saturday, January 14th, 2012 at 20:09 and is filed under HowTo, Linux, Tools, X. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

« Experimenting with window managers

2 Responses to “.Xdefaults vs .Xresources”

  1. Multi head by catalyst – Huge mouse cursor/pointer issue in openbox | Notes Says:
    March 27th, 2014 at 23:25

    […] better way to fix this problem would be the xrdb -merge. But I won’t go into this too […]

  2. henk Says:
    May 9th, 2015 at 21:58

    Thanks you very much for your explaination.
    Have been struggling a long time with xterm to get a bigger font. Now i undertand how it should work and why. Installed xrdb and everything is running just fine now.

Leave a Reply

You must be logged in to post a comment.

  • Recent Posts

    • .Xdefaults vs .Xresources
    • Experimenting with window managers
    • About that time, eh chaps?
    • Goodbye Big-bloated-OTR-button
  • Recent Comments

    1. henk on .Xdefaults vs .Xresources
    2. Multi head by catalyst – Huge mouse cursor/pointer issue in openbox | Notes on .Xdefaults vs .Xresources
    3. Francisco on Experimenting with window managers
    4. wildcard on About that time, eh chaps?
    5. pesa on Goodbye Big-bloated-OTR-button

blog of pesa is proudly powered by WordPress | Bob