Unix Power ToolsUnix Power ToolsSearch this book

6.8. Setting Resources with xrdb

The xrdb program saves you from maintaining multiple resource files if you run clients on multiple machines. It stores resources on the X server, where they are accessible to all clients using that server. (This property is also called the resource database.)

Place the appropriate xrdb command line in your .xinitrc file or .xsession file to initialize resources at login, although it can also be invoked interactively. It has the following syntax:

xrdb [options] [filename]

The xrdb client takes several options, all of which are documented on its manual page. We'll discuss the most useful options.

The optional filename argument specifies the name of a file from which the values of client variables (resources) will be read. If no filename is specified, xrdb will expect to read its data from standard input. Note that whatever you type will override the previous contents, so if you inadvertently type xrdb without a filename argument and then quit with CTRL-d, you will delete any previous values. (You can append new settings to current ones using the -merge option discussed later in this article.)

The resource filename can be anything you want. Two commonly used names are .Xresources and .Xdefaults.

You should load a resource file with the xrdb -load option. For example, to load the contents of your .Xresources file into the RESOURCE_MANAGER, you would type:

% xrdb -load .Xresources
Querying the resource database
You can find out what options are currently set by using the -query option. For example:

% xrdb -query
XTerm*ScrollBar:     True
bigxterm*font:       9x15
bigxterm*Geometry:   80x55
smallxterm*Font:     6x10
smallxterm*Geometry: 80x10
xterm*borderWidth:   3

If xrdb has not been run, this command will produce no output.

Loading new values into the resource database
By default, xrdb reads its input (either a file or standard input) and stores the results into the resource database, replacing the previous values. If you simply want to merge new values with the currently active ones (perhaps by specifying a single value from standard input), you can use the -merge option. Only the new values will be changed; variables that were already set will be preserved rather than overwritten with empty values.

For example, let's say you wanted to add new resources listed in the file new.values. You could say:

% xrdb -merge new.values

As another example, if you wanted all subsequently run xterm windows to have scrollbars, you could use standard input and enter:

% xrdb -merge
xterm*scrollBar:        True

and then press CTRL-d to end the standard input. Note that because of precedence rules for resource naming, you may not get what you want automatically. For example, if you specify:

xterm*scrollBar:        True

and the more specific value:

xterm*vt100.scrollBar:  False

has already been set, your new, less specific setting will be ignored. The problem isn't that you used the -merge option incorrectly -- you just got caught by the rules of precedence.

If your specifications don't seem to work, use the -query option to list the values in the RESOURCE_MANAGER property, and look for conflicting specifications.

Note also that when you add new specifications, they won't affect any programs already running -- only programs started after the new resource specifications are in effect. (This is also true even if you overwrite the existing specifications by loading a new resource file. Only programs run after this point will reflect the new specifications.)

Saving active resource definitions in a file
Assume that you've loaded the RESOURCE_MANAGER property from an .Xresources or other file. However, you've dynamically loaded a different value using the -merge option, and you'd like to make the new value your default.

You don't need to edit the file manually (although you certainly could.) The -edit option allows you to write the current value of the RESOURCE_MANAGER property to a file. If the file already exists, it is overwritten with the new values. However, xrdb is smart enough to preserve any comments and preprocessor declarations in the file being overwritten, replacing only the resource definitions. For example:

% xrdb -edit ~/.Xresources

will save the current contents of the RESOURCE_MANAGER property in the file .Xresources in your home directory.

If you want to save a backup copy of an existing file, use the -backup option:

% xrdb -edit .mydefaults -backup old

The string following the -backup option is an extension appended to the old filename. In the prior example, the previous copy of .mydefaults would be saved as .mydefaults.old.

Removing resource definitions
You can delete the definition of the RESOURCE_MANAGER property from the server by calling xrdb with the -remove option.

There is no way to delete a single resource definition other than to read the current xrdb values into a file. For example:

% xrdb -query > filename

Use an editor to edit the file, deleting the resource definitions you no longer want, and save the file:

% vi filename

Then read the edited values back into the RESOURCE_MANAGER with xrdb (note that we're replacing the values, not merging them, so we use -load):

% xrdb -load filename

--VQ and SJC

Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.