Resources - Customizing the look of your Windows

A user can change the appearance and behavior of an application by changing the resources that are use by the applications. Resources define the value of the properties of a widget. In other words, if a widget has a forground color,then you can specify a resource to set the color.

Each widget in the hierarchy contains all of the properties of all of its ancestors. This means that for every widget, you can specify any resource in that widget, or in any of its ancestors.

Specifying resources

A user has two ways to specify a resource. A resource can be specified by a command line option or in a resource file (.Xdefaults).

Command line options

The command line specification of a resource usually applies to all parts of a program. The command line option will override any other specification of the same resource. Below are some common command line option that are used by most Widget based applications.
 
parameter  resource
-geometry  Size and position of the main window
-forground  forground color
-background  background color
-fn  font name
-title program title
-iconImage  Image to use for the icon

 

Resource File

Using the resource file is the most common way to specify resources. Each entry in the resource file is a resource specification/value pair.

The syntax of the entry in the resource file is
 

ResourceSpecification: Value


Where the ResourceSpecification syntax is
 

{Application}[.|*]{WidgetName}[.|*]{WidgetName}...[.|*]Property


The WidgetName can be either a Class name, or an instance name.

The resource specification specifies the path in the widget hierarchy for the applications.  The specification starts with the name of the application, and is followed by a series of widget names or classes. The last part of a specification is the actual property of the widget.

Each part of the resource specification has a degree of binding. The degree of binding specifies how closely a resource specification must match the actual widget tree.

A period (.) is a tight binding. An asterisk (*) is a loose binding. A tight binding means that whatever widget is specified on the left must be the \fBdirect ancestor\fR of the widget on the right in order for thespecification to match.

A loose binding means that the widget specified on the left must be an ancestor, but not necessarily a direct ancestor.

If a widget name is specified, then the specification will match only if the corresponding widget in the widget tree has that name.

If a widget class is specified, then the specification will match if the corresponding widget in the widget tree is of the correct type. The instance
name doesn't matter.

A question mark can also be used to specify the existence of a widget, but not to specify the name or class of the widget. In other words, '?' means one widget, and '*' means zero or more widgets.
 

xrn.vpane.textinfo.foreground: black
xrn*background: light blue


Using loose binding can have some side effects. In this example, the background of every widget in xrn is set to light blue. The forground of \fIonly\fR the textinfo widget is set to black.
 

xrn.vpane.?.font: 6x10


This example specifies that all widgets that have one widget between them and the vpane widget will have their font property set to 6x10.
 

xrn.vpane*font: 6x10


This example specifies that all widgets that are descendants of the vpane widget will have their font property set to 6x10.

An exclamation (!) is used to designate a comment line.

Where the resources live

The resources that are used by an application come from several places. In addition to the command line and the .Xdefaults file described above, most applications also have some compiled in resources, and most also have an application defaults file.

The application defaults files are located in \fC/usr/lib/X11/app-defaults\fR. These file can be thought of as a place to set system wide resource defaults. These files are usually not modified very often.
 

{Application}[.|*]{WidgetName}[.|*]{WidgetName}...[.|*]Property


The WidgetName can be either a Class name, or an instance name.

The resource specification specifies the path in the widget hierarchy for the applications.  The specification starts with the name of the application, and is followed by a series of widget names or classes. The last part of a specification is the actual property of the widget.

Each part of the resource specification has a degree of binding. The degree of binding specifies how closely a resource specification must match the actual widget tree.

A period (.) is a tight binding. An asterisk (*) is a loose binding. A tight binding means that whatever widget is specified on the left must be the \fBdirect ancestor\fR of the widget on the right in order for the specification to match.

A loose binding means that the widget specified on the left must be an ancestor, but not necessarily a direct ancestor.

If a widget name is specified, then the specification will match only if the corresponding widget in the widget tree has that name.

If a widget class is specified, then the specification will match if the corresponding widget in the widget tree is of the correct type. The instance name doesn't matter.

The RESOURCE_MANGER property

An application will also get its resources from the RESOURCE_MANAGER property on the root widow of a display. Two utilities can be used to look this property, xprop and xrdb.

xprop

This utility will show all properties on a window. Not all of the properties will be readable (or even understandable), but \fIxprop\fR will display them anyway. Properties are used to pass information between clients, and between clients and the window manager.

xrdb

This utility is the more useful of the two for manipulating resources. \fIXrdb\fR can take a .Xdefaults file and load it in the RESOURCE_MANAGER property of the root window of a display. This is useful if you are running applications from multiple hosts to the same display, but you don't want to have to maintain a .Xdefaults file on each of those hosts.

If you typically use two different X server with different characteristics (color vs. mono), \fIxrdb\fR will let you maintain a single .Xdefaults file, but have different resources specified depending on which X server you are using. \fIXrdb\fR uses \fIcpp\fR to process the .Xdefaults file before it is loaded in the RESOURCE_MANAGER property. \fIXrdb\fR defines several symbols that can be used in the .Xdefaults file. \fIxrbd -symbol\fR will show the currently defined symbols for your environment.
.bp
Below are the symbols defined for an X Station.
 

-DHOST=tvstu.ColumbiaSC.NCR.COM
-DSERVERHOST=tvstu.ColumbiaSC.NCR.COM
-DCLIENTHOST=kzin
-DVERSION=11
-DREVISION=0
-DVENDOR="NCR Corporation"
-DRELEASE=2020037
-DWIDTH=1280
-DHEIGHT=1024
-DX_RESOLUTION=3938
-DY_RESOLUTION=3938
-DPLANES=1
-DBITS_PER_RGB=1
-DCLASS=StaticGray


Below are the symbols defined for the R5 X server.
 

-DHOST=grok3
-DSERVERHOST=grok3
-DCLIENTHOST=kzin
-DVERSION=11
-DREVISION=0
-DVENDOR="NCR Corporation"
-DRELEASE=5000
-DWIDTH=1152
-DHEIGHT=900
-DX_RESOLUTION=2954
-DY_RESOLUTION=2961
-DPLANES=8
-DBITS_PER_RGB=8
-DCLASS=PseudoColor
-DCOLOR


.bp
Bellow is an example .Xdefaults file that uses these symbols to change the resources that will be specified.

!

 Stuart's Xdefaults file
!
xclock*showTitle:       off
xbiff*showTitle:        off
xbiff*geometry:         -0+290
#if RELEASE == 5000 || RELEASE == 3
xbiff*geometry:                -0+290
#else
xpbiff*geometry:                -0+100
#endif
xterm*showTitle:                on
xclock*mode:                    analog
xterm*paneSpread:               .25
#if RELEASE == 5000 || RELEASE == 3
xterm*font:                     5x7
#else
xterm*font:                     -*-fixed-bold-*13-*
#endif
xterm*scrollBar:                on
xterm*saveLines:                500
xterm*reverseVideo:             off
xterm*borderWidth:              1
#ifdef COLOR
xterm*cursorColor:              red
xterm*pointerColor:             red
#endif
xterm*loginShell:               true
#if RELEASE == 5000
oclock.geometry:                =100x100-0-0
oclock.customization:           -color
#else
#if RELEASE == 3
oclock.geometry:                =100x100-0-0
#else
oclock.geometry:                =100x100-0+0
#endif
#endif

Resource Precedence

Since there are so many places to get resources, a precedence is defined so the behavior will be predictable. The table below specifies this precedence, higher priority first.
 
Command line option
$XENVIRONMENT or $HOME/.Xdefaults-<hostname>
SCREEN_RESOURCE property
RESOURC_MANAGER property else $HOME/.Xdefaults
$HOME/<Classname>
app-default/<Classname>
Compiled in resources

Using editres to play with resources


First, run xcalendar, and use editres to get the widget tree. Note that under the Tree menu, you can choose the Show Class Names option to change the display to show what type of widgets are used.

Select the top Label widget (called SUN if you are showing Widget names instead of Class names) and under the Commands menu, choose Show Resource Box. You should see this popup. Select the label resource, and type in a new value for the label of this widget. Your window should look like this. Hit the Apply button, and the client will update the widget, and look like this.
.