7. Customizing X Clients

Contents of this section

Many programs written for X Windows (``X applications'' or ``X clients'') share a common way of configuring things like fonts, colors, default window size and placement (``geometry''), etc. These configurable items are called ``X resources'' or just ``resources''. Some X clients, in fact, need to have certain resources configured by default in order to run correctly. There are two main places that X Windows programs will look for resource settings when you run them:

7.1 Application Defaults

Each X application has a separate app-defaults file, which is located in the directory /usr/X11R6/lib/X11/app-defaults/ and is called by the ``application name'' or ``class name'', which does not necessarily have to be (and very often isn't) the same as the name of the program. For instance, the xcalc program for X Windows looks for its application defaults in the file /usr/X11R6/lib/X11/app-defaults/XCalc. This is true even if we rename xcalc to myxcalculator. Each resource in an app-defaults file automatically has the class name of the application prepended to it---by definition, an app-defaults file doesn't usually apply to more than one X application (although it applies to all COPIES of that application).

Note also that the resource settings in the app-defaults file apply to an X Windows program no matter who is running it---everyone gets to use the app-defaults. For this reason, it is generally a good idea to leave most of the resource settings in the app-defaults file alone and copy them to your .Xdefaults file instead (see below).

7.2 Your .Xdefaults file

The ``X resource database'' is a conglomeration of resources very similar to the ``environment'' for the Unix shell. When you start an X Windows session, any resource settings which are defined in a file in your home directory called .Xdefaults are automatically loaded into the resource database. Each resource setting in your .Xdefaults file should start with an application name, UNLESS you intend for the resource setting to apply to more than one application (see below).

Resource settings in your .Xdefaults file only get loaded every time YOU start an X session---they don't affect anyone else. For this reason, your .Xdefaults file is a good place to put customized resource settings, such as foreground and background colors, application fonts, etc. If you wish to customize an application's resource settings, you can copy the relevant portion from the app-defaults file and put it in your .Xdefaults file---don't forget to add the application name at the beginning of each resource setting.

7.3 Setting Resources

Since the syntax of resource settings is rather complex, it is best illustrated by example. Here is a simple .Xdefaults file, specifying several different types of resource settings:

! sample .Xdefaults file
!
! (exclamation points start comments)
! (resource names are on the left)
! (resource values appear on the right of the colon)
!
! set a general background color for most applications
?*Background:   gray
! note---this could also be simply
! `*Background: gray'
!
! some settings for xterm
!
! the first title here is superseded by the second one,
! not because of position (first/second), but because
! of precedence rules.  Resources starting with
! ``program names'' (e.g., `xterm') supersede those
! starting with ``class names'' (e.g., `XTerm').
*XTerm*title:   This Title Doesn't Work
*xterm*title:   Terminal
!
! here, the first setting is again superseded by the
! second one because of precedence rules.  Although
! the resources both begin with ``class names'', the
! second one is more specific (a `*' is a sort of
! ``wildcard'' character, while the `.' is not).
*XTerm*font:    fixed
*XTerm.font:    lucidasanstypewriter-12
!
! this setting overrides the Background setting above,
! but only for XTetris.  Again, more specific resource
! settings supersede more general ones.
*Xtetris*Background:    #303030
!
! -------- End of sample .Xdefaults --------

The best place to find out what resources an X application will accept is the documentation or manual page accompanying the application. The next best place is in the app-defaults file---just copy the entries you need, put them in your .Xdefaults, and add ``*'' plus the application name (which is the same as name of the app-defaults file) at the beginning of each resource. You can also use an X Windows program called editres to find out what resources an application responds to; you need to be running X to use it. See the editres manual page for more information.

7.4 Notes and Pointers

NOTE that, since your .Xdefaults resources are loaded each time you start an X Windows session, any changes you make won't take effect until you quit X and login (or start X) again. Or, to add changes to the resource database, see the manual page for xrdb.

For further information on X resources, see the manual page for X. For information on names of fonts to use in X resources, see the manual pages for xlsfonts and xfontsel.


Next Chapter, Previous Chapter

Table of contents of this chapter, General table of contents

Top of the document, Beginning of this Chapter