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

Understanding the Resource Database


Many aspects of an application's appearance and behavior are controlled by sets of variables called resources. The visual or behavioral aspect of a resource is determined by its assigned value. There are several different types of values for resources. For example, resources that control color can be assigned predefined values such as DarkSlateBlue or Black. Resources that specify dimensions are assigned numeric values. Some resources take Boolean values (True or False).

Every application and resource in X has both an instance name and a class name. The instance name identifies each application and resource individually. The class name specifies the general category to which each individual instance of an application or resource belongs. For example, the class name Mailer specifies all instances of an application called mailer.

Class names always begin with an uppercase letter and instance names always begin with a lowercase letter. If the instance name of a specific component is a compound word, like pushButton, the second word usually begins with an uppercase letter. The class name and the instance name for an application are often the same, except for the case of the initial character(s). The instance name for an application is usually the name of the command that is used to start the application.

Each application builds its own initial resource database from a combination of resource settings primarily found in the start-up command line, a system-wide application defaults file, and user defaults files. These files can be specialized according to the application or the host on which the application is running. The application builds the resource database by merging in resources from these sources in the order of precedence (that is, each component takes precedence over the following components):

An application searches for resource files and any localized databases on a file search path. A file search path is an ordered set of pathnames. If a resource file is not found in the first location, the application searches in the next location, and so on, until a resource file is found or all of the locations have been searched.

File search paths can incorporate a set of substitution characters that represent variable data. At run time, an application looks at certain external data and supplies corresponding values for each substitution character in the file search path. For example, %N can represent the class name of an application. When %N is in a path description, the application class name is substituted into the pathname. If the first path in a search path hierarchy is /usr/lib/X11/app-defaults/%N and the application class name is Mailer, the %N substitution causes the application to look in the directory /usr/lib/X11/app-defaults for a file named Mailer, which contains its application class defaults.

There are a number of environment variables that you can set to specify the search paths that an application uses to find various resource files. For example, the XUSERFILESEARCHPATH environment variable controls the search path that applications use to find your application-specific resource files. You can also set the XENVIRONMENT, XFILESEARCHPATH, and XAPPLRESDIR environment variables to specify search paths for other aspects of resource lookup.

The resource lookup procedure reads the resources contained in the RESOURCE_MANAGER property on the root window of the default screen of the display. If this property does not exist, the contents of the file .Xdefaults in your home directory are used instead. The .Xdefaults file is the resource file where you typically put resource specifications that customize the applications that you are using.

As of Release 5 of the X Window System (X11R5) you can set resources on a per-screen basis. For example, you can specify color resources for a color screen and monochrome resources for a monochrome screen. A resource database is created for each screen and the application finds the resources that are appropriate for each screen. X11R5 also provides a customization resource for use in path substitution when searching for application defaults files. %C is used to represent the value of the customization resource. The application class defaults and your per-application defaults can be further specialized according to the language environment in use on a system. For more information about these features, refer to the Programmer's Supplement for Release 5, 1991, published by O'Reilly and Associates, Inc.