[Contents] [Index] [Next] [Previous]

Resource Specification Syntax


A value is assigned to a resource in a single line specification, which has the following general, abbreviated format:

Client*resource: value

For example, you could use the following specifications in your .Xdefaults file to set resources for xterm clients on your system:

XTerm*background: Wheat
XTerm*foreground: Navy
XTerm*font: fixed
XTerm*scrollBar: true

In the preceding example, every instance of an xterm window on your system appears with a wheat-colored background and navy-colored foreground (the color of any text or graphics that appear in the window), uses the font named fixed, and provides a ScrollBar. XTerm is the class name.

You should be aware that the resource specifications in the preceding example are abbreviated in form. The full syntax of a resource depends on how the components of an application are organized, or in other words the relationship between parent and child widgets. For example, in a mail program there might be a MainWindow containing several PushButtons. Each PushButton might have an associated subwindow that contains any number of Menus. If you want to specify the font size for a single Menu in one of the subwindows, you need to know the names of the widgets and their positions in the widget hierarchy.

Components in the hierarchy that are immediately adjacent are separated by a . (dot). Usually the name of a class or an instance of the application comes first, followed by the name of the highest widget in the widget hierarchy. The name of the top widget in the hierarchy is followed by the specification of any number of widgets lower in the hierarchy. To simplify this complicated syntax, X provides the * (asterisk) abbreviation for representing any number of components in the widget hierarchy. For instance, you can use an * (asterisk) to substitute for the class name:

*Foreground: Blue

Using this specification ensures that the foreground (text and graphics) in all clients will be blue. Using the following specification in your .Xdefaults file sets the font for every window in every instance of the mailer application:

Mailer*fontList: fixed

The next example shows how you would specify the font only for the area in which you compose mail messages in the mailer application:

Mailer*messageArea*fontList: fixed

Release 5 of the X Window System (X11R5) provides the ? (question mark) as a substitution for any one component in the widget hierarchy. The following resource specification sets the background color for all of the widgets that are grandchildren of the top widget in the hierarchy for the application:

Mailer.?.?.Background: Red

With X11R5 you can use C preprocessor commands in your .Xdefaults file to specify per-screen resources. For example, you can separate resource specifications for color screens from monochrome screens as follows:

#ifdef COLOR
*Background: Grey
*Foreground: Navy
#else
*reverseVideo: True
#endif

The documentation for an application should provide the instance and class names of any components that the application allows you to customize. When appropriate, use the class name in a resource specification to ensure that all instances will use the same resource values.