NIKOLA Computing User Documentation
Home
User Docs and FAQ
FAQ
Tutorials
About NIKOLA
Links

Editing your .Xdefaults file

Warning: This tutorial contains advanced information. You can seriously disrupt your environment if you do not know what you're doing. We recommend you leave this alone.

Understanding resources

X uses a system called resources to configure many to most applications. While initially confusing, resources are a powerful tool when used properly.

Resources are kept in a file in your home directory called .Xdefaults. This .Xdefaults might look like this:

    !xload defaults
    xload*geometry: 180x80-5+195
    xload*update: 1
    !xterm defaults
    xterm*background: ivory
    xterm*cursorColor: black
    xterm*foreground: black
    xterm*jumpScroll: on
    xterm*pointerColor: red
    xterm*reverseVideo: false
    xterm*saveLines: 10000
    xterm*scrollBar: true
    xterm*scrollKey: on
    

In this file the ! sign marks the beginning of a comment. Usually this is placed at the beginning of a line. It is used similarly to the # sign in shell scripts (for those of you familiar with them).

What we need to describe next is what a resource is. Each of the lines (excluding comments) above is a resource. Resources are the name(s) of a property (or propeties) followed by a colon, some optional blank space, and an appropriate value. Depending on the resource it could be a number, true/false, a color name, a color identifier, a string, a filename, or a number of other things.

The first part of a resource, which is what we often refer to when we are speaking of resources, is often the hardest to understand and determine. Essentially it is the name of a specific component or property in the program. For a good explanation of how the naming scheme works see "X Window System User's Guide: Volume Three", from O'Reilly and Associates, Chapter 9. It discusses in detail the nature of resources. Essentially the first portion of a resource is the "Class name" of the application. This may be determined using xprop (check the man page, xprop(1)). Next usually comes a . or a *. The . is a separator which must be followed by the name of a resource (To those familiar with C/C++ it is similar to the structure operator for referencing members). It simply allows you to specify a piece of the application. You could have a resource name like "ansixterm.scrollbar.slider.background", which specifies the background of the scrollbar slider on something called ansixterm (This example does not actually work as this property does not exist for the example application). The *, however, is as you would expect. It matches everything it can. "xterm*background" means any property of an xterm that has its own background property. In many case resources using *'s are more useful.

Adding a resource

The first step to adding a resource is to determine the resource's name you wish to add. Let's say you want to set the background color of a program called termprog to blue. Suppose we've determined the resource name to be termprog.background. So you open up your .Xdefaults file with your favorite editor, and start a new line (it can be anywhere, preferably near other resources for this program if they exist, or at the bottom if there aren't any). Then enter the resource name, a colon, a space or more, and the value. In the case of termprog we'd write:
termprog.background: blue

Then save the resources file. Now we're almost done. Resources are kept in a database, which has a manager. You now need to update the database so run the following command:
xrdb -merge ~/.Xdefaults

DO NOT do this:
xrdb -load ~/.Xdefaults
As this will wipe out any currently active resources you might have (and some applications set them on their own).

Caveats

Changing resources won't affect running programs. Programs usually only check the resource database on startup, and set all their properties then. Also, finding the right resource name is often a process of trial and error if you're not given it in the man page. xrdb's man page is probably worth looking at, but may be confusing. Also, be careful with the * operator. In applications, especially any of the emacses, the * operator can have unexpected results. When in doubt try . first.

For further details, see: