The first task of a Motif application is to initialize the Intrinsics. Most applications can perform the initialization by calling the routine XtAppInitialize. This is a convenience routine that combines several initialization steps, each of which the application can take separately by calling a specialized Xt routine:
Following is an example of a simple call to XtAppInitialize:
int main(int argc, char **argv) { Widget app_shell; XtAppContext app; app_shell = XtAppInitialize(&app, "Example", (XrmOptionDescList) NULL, 0, &argc, argv, (String *) NULL, (ArgList) NULL, 0); }
The XtDisplayInitialize routine builds the initial resource database for the application. An application rarely needs to call this routine directly; it is called by XtOpenDisplay, which in turn is called by XtAppInitialize.
XtDisplayInitialize builds a separate resource database for each display connection. The initial database combines resource settings from the command line, the display, an application class defaults file, and user defaults files that may be specialized according to the application or the host on which the application is running. The application class defaults and the user's per-application defaults may be further specialized according to the language environment and possibly according to a general-purpose customization resource. The resources in the initial database may pertain to particular widgets or widget classes or to the application as a whole. When the application creates widgets, the resource settings from the database are often the source for the initial values of widget resources.
The remainder of this section describes the order in which XtDisplayInitialize loads each component of the database and how it derives the location of that component.
In loading the application class defaults and the user's per-application defaults, XtDisplayInitialize calls XtResolvePathname to determine which files to read. XtResolvePathname uses file search paths. Each path is a set of patterns that may contain special character sequences for which XtResolvePathname substitutes runtime values when it searches for a file. It uses the following substitutions in building the path:
If the language specification is not defined, or if one of its parts is missing, a % element that references it is replaced by NULL.
The paths contain a series of elements separated by colons. Each element denotes a filename, and the filenames are looked up left-to-right until one of them succeeds. Before doing the lookup, substitutions are performed.
Note: | The Intrinsics use the X/Open convention of collapsing multiple adjoining slashes in a filename into one slash. |
The XtDisplayInitialize function loads the resource database by merging in resources from these sources, in order of precedence (that is, each component takes precedence over the following components):
XtDisplayInitialize calls the X Resource Manager function XrmParseCommand to extract resource settings from the command line by which the user invoked the application. The arguments and number of arguments on the command line come from the argv and argc arguments to XtAppInitialize, XtOpenDisplay, or XtDisplayInitialize. Xt maintains a standard set of command-line options, such as -background and -geometry, for specifying resource settings. An application can specify additional options in arguments to XtAppInitialize, XtOpenDisplay, or XtDisplayInitialize. The user can supply the -xrm option to set any resource in the database.
To load the per-host user environment resources, XtDisplayInitialize uses the filename specified by the XENVIRONMENT environment variable. If XENVIRONMENT is not defined, XtDisplayInitialize looks for the file $HOME/.Xdefaults- host, where host is the name of the host on which the application is running (that is, the name of the client host, not the server host).
To load screen-specific resources, XtDisplayInitialize looks for a SCREEN_RESOURCES property on the root window of the default screen of the display. The SCREEN_RESOURCES property typically results from invoking the xrdb command when some resources are not defined for all screens.
Note: | When Xt needs to fetch resources for a screen other than the default screen of the display--for example, when the application creates a widget on another screen--it uses the SCREEN_RESOURCES property of that screen instead of the SCREEN_RESOURCES property of the default screen. |
To load the server resource property or user preference file, XtDisplayInitialize first looks for a RESOURCE_MANAGER property on the root window of the display's screen 0. The RESOURCE_MANAGER property typically results from invoking the xrdb command when some resources are defined for all screens. If that property does not exist, XtDisplayInitialize looks for the file $HOME/.Xdefaults.
To load the user's application resource file, XtDisplayInitialize performs the following steps:
$XAPPLRESDIR with %C, %N, %L or with %C, %N, %l, %t, %c $XAPPLRESDIR with %C, %N, %l $XAPPLRESDIR with %C, %N $XAPPLRESDIR with %N, %L or with %N, %l, %t, %c $XAPPLRESDIR with %N, %l $XAPPLRESDIR with %N $HOME with %N
where $XAPPLRESDIR is the value of the XAPPLRESDIR environment variable and $HOME is the user's home directory.
$HOME with %C, %N, %L or with %C, %N, %l, %t, %c $HOME with %C, %N, %l $HOME with %C, %N $HOME with %N, %L or with %N, %l, %t, %c $HOME with %N, %l $HOME with %N
To load the application-specific class resource file, XtDisplayInitialize performs the appropriate substitutions on the path specified by the XFILESEARCHPATH environment variable. If that fails, or if XFILESEARCHPATH is not defined, XtDisplayInitialize uses an implementation-dependent search path containing at least six entries, in the following order and with the following substitutions:
%C, %N, %S, %T, %L or %C, %N, %S, %T, %l, %t, %c %C, %N, %S, %T, %l %C, %N, %S, %T %N, %S, %T, %L or %N, %S, %T, %l, %t, %c %N, %S, %T, %l %N, %S, %T
where the substitution for %S is usually NULL and the substitution for %T is usually app-defaults.
If no application-specific class resource file is found, XtDisplayInitialize looks for any fallback resources that may have been defined by a call to XtAppInitialize or XtAppSetFallbackResources.