X resources are defined for display aspects of the Digital UNIX operating system itself as well as for all the X client applications that are part of the operating system. X applications that are installed on top of the operating system also have resource definitions. Resources characteristics include color specifications for various elements in a window display, presence of scroll bars for a window, location of windows on the desk top area, font used for text, and width of window borders.
Resource definitions are used in all applications based on the X Window System, such as xterm, Calendar, and even the X Display Manager xdm. The Digital UNIX operating software provides default resource definitions for the X Window System. Users can modify some resource definitions to customize their workstation environment; for example, to set the colors and positions of windows.
There are three ways to set resources:
Only a subset of resources can be set from the command line, but the advantage of this method is that you do not need to edit any files to apply the definitions. Section 3.2 discusses this method.
The system administrator can use systemwide files to establish uniform settings for small or large groups of users; or special individual settings. Section 3.3 discusses this method.
Programmers who are writing X Window System client applications include resource definitions in their code so that they control the look and feel of the application. Section 3.4 describes some utilities that help users and programmers specify resource definitions.
Resource definitions for the Digital UNIX operating software clients are located in the /usr/lib/X11/app-defaults/ClassName files. These resources are used only by a client that runs on the local host, even if the client appears on a remote X display.
These definitions are usually located in files in the user's home directory, $HOME/ClassName. If several hosts share the home directory, the definitions in the directory will also be shared by those same hosts.
Host-specific resource definitions are located in either the $HOME/.Xdefaults-hostname file or a file pointed to by the $XENVIRONMENT variable. These definitions are only used by applications running on the host system and are not specific to the display.
Some users use a resource database loaded by the X Server Resource Database utility (xrdb) to specify display-specific default resource settings.
If no resource database exists for the user, the X server applies the resource definitions in the $HOME/.Xdefaults file.
Users can change some resource definitions by specifying the new resource
settings on the command line when they invoke the client application. Section 3.2 and the X
(1X) reference page provide
information on the standard resources that can be set from the command line
for most applications. Client applications can create additional flags that
set resource definitions which are specific to the particular application.
It is important to be aware of which resource definitions take precedence of other definitions; hence, the use of ascending numbers in the preceding list. System definitions are overridden by user definitions, which are, in turn, overridden by host-specific definition. A definition supplied through a command-line flag overrides any existing definition for that resource. However, only the 17 standard resources or resources for which the client application has provided a command flag can be defined using command-line flags. Other resources must be specified in definition files or by using the -xrm flag.
Note that host-specific and user-specific resource files do not necessarily have to reside in the user's home directory. There are several environment variables that can be set to specify a search path for default files:
This environment variable is used to set the path for systemwide application-specific resource definition files.
This environment variable is used in place of $HOME for application-specific user resource definition files.
If this environment variable is defined and XUSERFILESEARCHPATH is not, the search path becomes:
$XAPPLRESDIR/%L/%N:$XAPPLRESDIR/%l/%N:$XAPPLRESDIR/%N:$HOME/%N
$XAPPLRESDIR is replaced by the value of that environment variable; $HOME is replaced by the user's home directory. If there is no definition for $XAPPLRESDIR, the path is the user's home directory:
$HOME/%L/%N:HOME/%l/%N:$HOME/%N
The %L element resolves to a full-locale name if one exists; %l resolves to the language component element of the locale; %N resolves to the name of the file being searched for. If no file exists in the locale or if no locale has been defined, the path collapses to the next level.
To load resources using xrdb, use either the -load flag (the default) or the -merge flag and specify a new resource definition file. With the -load flag, all previous resource definitions in the X server are deleted and replaced with the new definitions in the specified file. If the new file does not contain a definition for a resource that was defined previously, that resource definition is either lost or reverts to a default. The -merge flag allows you to change and add resource definitions without losing existing ones that you do not modify in the new definition file that you specify with the xrdb command.
Table 3-1 lists the standard command-line flags and the resources they modify.
Flag | Resource | Description |
---|---|---|
-bg -background | background | Sets the background color of the window. |
-bd -bordercolor | borderColor | Sets the color of the window border. |
-bw -borderwidth | borderWidth | Sets the width of the window border in pixels. |
-display | display | Specifies the display on which the client runs. |
-fn -font | font | Sets the font used for text display. |
-fg -foreground | foreground | Sets the window's foreground color that is used for the text or graphics. |
-geometry | geometry | Specifies a geometry string that sets the startup size and placement of the window. |
-iconic | iconic | Invokes the application in the iconic state. |
-name | name | Specifies the name of the application. This name is used for the window icon. |
-rv -reverse | reverseVideo | Reverses the foreground and background colors. |
+rv | reverseVideo | Restores the foreground and background colors to their current specifications. |
-selectionTimeout | selectionTimeout | Specifies the timeout period in milliseconds. This value determines the timeout period within which two communicating applications must respond to one another after a selection request. |
-synchronous | synchronous | Enables synchronous debugging mode. |
+synchronous | synchronous | Disables synchronous debugging mode. |
-title | title | Specifies the application title that is used in the window's title bar. |
-xnllanguage | xnlLanguage | Sets the language, territory, and National Language Support codeset. |
-xrm | Allows you to specify a resource name and value to override any defaults. |
The following examples show how some of these standard flags are specified when an application is invoked:
dxterm -bg "pale green" -fg "sandy brown" &Starts a DECterm window with a pale green background. The text and graphics appear in sandy brown.
xterm -iconic -name Letters &Creates an xterm window, but places it immediately in the icon state. The name of the icon is Letters.
dxcalc -geometry +0-0 &Invokes the DECwindows Calculator application and places the window in the lower left corner of the screen.
Programmers need to understand resource definitions so they can use them when they create their applications. System administrators use resource definitions to set up a default working environment for the workstations they maintain. End users can use resource definitions to customize their workstation environment and even to customize some display characteristics of applications they run.
This section explains the structure of resource definitions, gives examples of how to create and modify the definitions, and describes the kinds of resource definition files that you can edit to customize your environment.
object.subobject[.subobject...].attribute: value
The parameters have the following definitions:
Specifying the object, attribute, and value parameters is relatively straightforward. In general, the object parameter is the name of the client program. The resource attribute refers to the characteristic you want to modify, add, or delete. The second column in Table 3-1 contains the names of some resource attributes. The description gives you an idea of the kinds of values you can specify such as a color name for foreground, pixel coordinates for geometry, a font string for font, and a locale for xnlLanguage.
Creating resource definitions can be a bit more complex if you have to deal with subobjects. When you want a value to apply to an attribute throughout the application, you can use an asterisk (*) to indicate all the subobjects. For example, if you want the background color to be light blue for every dialog box, menu, message box, and so on in the AccessX client, you could use the following resource definition:
accessx*background: lightblue
This kind of definition is known as a loose binding because the value applies to all appropriate widgets in the hierarchy.
If you want to have a dark-blue background only for the status boxes, you would use the following resource definition:
accessx.mousekeys.statusbox: darkblue
This definition requires that you know every element in the widget hierarchy from the main widget, accessx to the status box widgets. This kind of definition has a tight binding; that is, each subwidget between the accessx widget and the statusbox widget is listed in order, separated by periods.
To determine the elements in the widget hierarchy for an application,
you need to use the editres utility. This utility creates a display
of the hierarchy and also provides a way to test your resource definition.
See Section 3.4.1 and the editres
(1X) reference page for
details.
If your resource definition file will be run through the C language preprocessor, you can use #ifdef and #endif constructs to deal with definitions that are to be applied under certain circumstances. For example, you might have color definitions that would only be applied when you were working at a workstation with a color monitor.
The /usr/lib/X11/app-defaults directory contains resource definition files for many of the window client applications that are included with the Digital UNIX operating software. These files are read-only, so users cannot edit the contents to change or add resource definitions. However, you can use some of these definitions as models for your own definitions in a resource file or as part of the command line you issue to invoke the client. Note that many of these definitions specify things that you would not want to customize, such as the alignment of the buttons on the calculator application.
Host-specific resource definition files customize your display environment and are read by all client applications running on your host. One such file is called $HOME/.Xdefaults. You can set colors for the display background and foreground as well as for various elements of the windows that appear. You use this file to specify your default window manager. If you usually work on a system with a color monitor, but occasionally use a monochrome monitor, you can include color definitions in your .Xdefaults file surrounded by #ifdef and #endif statements. These definitions will only be processed if the COLOR C preprocessor symbol is defined. If you use dxsession, the definitions in the .Xdefaults file will be loaded into the X servers resource database. Otherwise, you can use the xrdb utility, which automatically uses the C preprocessor to deal with such programming constructs. Note that dxsession does not use the C preprocessor to process the .Xdefaults file and dxsession only understands a limited number of C preprocessor directives. You can use the xrdb -symbols command to see which symbols xrdb has defined.
In general, you will want to use xrdb to load one or more resource definition files into the X server's database. The xrdb utility is usually invoked by a session script such as $HOME/.xsession. See Section 3.4.4 for more information on xrdb.
If you do not load the X server's resource database either by using xrdb or by using the Session Manager, each time an X application starts up, it reads the .Xdefaults file and applies all relevant resource definitions. The dxsession program processes the local .Xdefaults file and loads the resource definitions into the X server's database.
The editres utility displays the widget hierarchy along with the names and definitions of all the resources for a particular X client application. This information enables a user or programmer to add, modify, or delete resource definitions for the application. The editres utility can dynamically apply the resource changes to the application. Thus, the user or programmer can immediately see the results of the new definition and decide whether or not to save the change, restore the original setting, or make another change.
The editres main window has four areas: Menu Bar, Panner, Message Area, and Application Widget Tree display. You use the Menu Bar to access the different editres features. The Panner provides an intuitive method for scrolling through the Application Widget Tree display. The display area shows the widget tree for the application specified through the Get Widget Tree menu item.
The Show Resource Box menu item creates a pop-up window that contains resource definitions for the widget that is currently selected in the Application Widget Tree display.
You use the Set Resource pop-up window to enter a resource definition for all the widgets currently selected in the Application Widget Tree display. (You can use Tree menu commands to select more than one widget by specifying such keywords as All, Children, Parents, Descendents, or Ancestors; or by specifying a widget class.)
In most instances, you use the Resource Box to determine whether a resource has been defined and what that definition is. You also use this box to add, modify, or delete resource definitions and to indicate to which widgets these changes apply. Once you have made your change, you use the Apply button to see the effects of your change. Press the Save button to save the change you have made. There is also a Save And Apply button, which performs both operations at once.
Note that some client applications have hard-coded the attributes for certain elements rather than use resource definitions. There is no way for editres to modify hard-coded attribute specifications.
You can use the -q flag with the xset command
to display the current settings for your workstation. To change a setting,
issue the xset command with the appropriate flag. See the xset
(1X)
reference page for the description of each flag.
The xsetroot command has a -def flag that
enables you to return the display to its default settings. See the xsetroot
(1X)
reference page for more details about the utility.
One of the features of the xrdb utility is that it uses a C preprocessor when it loads the resource definition file. This feature allows you to have #include and #ifdef statements and some other programming constructs in your resource definition files. In addition, you can define and undefine symbols by using the -D or -U flags.
The following example shows how you might include an #ifdef directive in your resource definition file that defines the colors to use for DECterm windows on color workstation monitors and the black and white values to use with noncolor monitors:
#ifdef COLOR DXterm*background: lightblue DXterm*foreground: darkblue #else DXterm*background: gray DXterm*foreground: black #endif
You can use the xrdb -query command to see the current settings for your system. If you want to change some of these resources, you can create a resource definition file and use the xrdb -merge filename command to add or replace existing definitions with your changes. With the -merge flag, xrdb replaces resource definitions for resources that are already defined for your system with those in the file you specify. If you have included resource definitions in that file for previously undefined resources, those new definitions are added. All other existing definitions remain the same.
There is also an xrdb -load filename command that you can use to erase all previous resource definitions and only use those in the file you specify. By default, xrdb behaves in this manner. Most of the time, you will probably want to use the xrdb -merge filename command because you will not want to lose the default settings for your environment.
For more information on the xrdb utility, see the X Window System User's Guide and the xrdb
(1X) reference page.
The utility has three basic mapping functions:
xmodmap -e "Control_R = Shift_R"
xmodmap -e "keycode 243 = slash exclam"
xmodmap -e "pointer = 3 2 1"
You can issue xmodmap commands during your work session or include them in an X session script. You can also create xmodmap definition files for the utility to read at startup time or when you invoke the utility during your work session.
The xmodmap command has the following syntax:
xmodmap: up to 2 keys per modifier, (keycodes in parentheses) shift Shift_R (0xab), Shift_L (0xae) lock BadKey (0xb0) control BadKey (0xaf) mod1 Multi_key (0xad), Multi_key (0xb1) mod2 Alt_L (0xac), Alt_R (0xb2) mod3 mod4 mod5
keycode 242 = semicolon colon keycode 243 = slash question keycode 244 = keycode 245 = equal plus keycode 246 = bracketright braceright stdin keycode 247 = backslash bar keycode 248 = keycode 249 = minus underscore keycode 250 = bracketleft braceleft keycode 251 = apostrophe quotedbl
xmodmap -e "keysym Select = Delete"
! Make the comma shift be < and the period shift be >. keysym comma = comma less keysym period = period greater ! Replace the Help key with the escape function. keysym 124 = escape
xmodmap $HOME/.Xmodmap
The xkbprint utility creates a PostScript
representation of an XKB keymap. If you specify the display as the input
file, it will read the XKB geometry from the server. Refer to the xkbprint
reference page or
run xkbprint with the -? switch for more information.
The xkbdfltmap utility queries the kernel
for the language and keyboard on the console. Given this information, Xdec will examine the /usr/lib/X11/xkb/keymaps.dir file to
determine the default keymap to use. The xkbdfltmap utility will
then display the appropriate xkbcomp command to run to download
the default XKB map to the server. If xkbdfltmap is run with the -exec switch, it will automatically execute the xkbcomp command
for you. Refer to the xkbdfltmap
reference page or run xkbdfltmap with the -? switch for more information.
The dxkbledpanel utility displays the
state of the keyboard indicators. This is useful for monitoring and changing
the state of indicators that may not have keyboard LEDs. For example, the
group indicator does not always have an LED on every keyboard. Refer to the dxkbledpanel
reference page
or run dxkbledpanel with the -? switch for more information.
The dxkeyboard utility allows you to select a localized keymap based upon your selection of language and keyboard type. The dxkeyboard utility optionally saves your selections and will load them if it is run with the -load switch. The dxkeyboard utility is available as the Keyboard Options object under CDE's Application Manager in the Desktop_Apps folder. Refer to the dxkeyboard reference page or run dxkeyboard with the -? switch for more information.
The accessx application for X11 R5 has been ported to use the XKB protocol for X11 R6. Refer to the accessx(1X) reference page for further information.
You can use a session script to invoke certain applications when you log in and place various windows on your display in specific positions. You can set the window manager in your session script as well as specify colors, fonts, and window features. The file can also contain xmodmap definitions or call an xmodmap definition file.
You can use a script to define certain environment variables before the session manager starts. For example, the following script defines the PRINTER environment variable, sets the default path, and invokes dxsession as the session manager.
#!/bin/csh setenv $PRINTER ln08r set path=($HOME/bin /bin /usr/bin /usr/bin/mh /usr/bin/X11 \ /usr/local /usr/local/bin) exec dxsession
The next example invokes the xconsole program and starts an xterm window as background processes. It then starts the twm window manager in the foreground. The twm window manager becomes the session's controlling process; that is, the session will last as long as the twm process is running. When twm exits, the .xsession script completes and the user's X session is over. If the last command line in the script had ended with an ampersand (&), the .xsession script would immediately complete and exit, the X session would be over, and xdm would cause the display to reset to the login box.
#!/bin/sh xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed -exitOnFail xclock & xterm -geometry 80x24+10+10 -ls & exec twm
You can include a wide variety of customizations in an X session script as shown in the following example. The comments within the example explain the code.
#!/bin/csh # # Define environment variables, paths, and so on. Keeping these # definitions in a separate file is useful. That way, .login # and/or .cshrc can reference the same set of definitions. # source ~/.environ.csh # # Create a pipe for dxconsole to read from, so it can display the # output of other commands. # setenv XSESSION_PIPE .xsession_pipe.$DISPLAY if ! { test -p .xsession_pipe.$DISPLAY } then /usr/sbin/mknod $XSESSION_PIPE p endif # # Use xrdb to load the resources in the .Xresources file into the # X server's resource database. # if ( -f .Xresources ) then xrdb -load -retain .Xresources endif # # Determine whether the display is the local graphics display, # that is, :0 or local:0 . # if ( "`echo $DISPLAY | cut -d':' -f1`" == || \ "`echo $DISPLAY | cut -d':' -f1`" == "local" ) then # # These applications are run only if the display is local. # dxconsole < $XSESSION_PIPE & # # Figure out how many screens the display has. # set SCREENS=`xdpyinfo | grep "number of screens" \ | cut -f 4- -d " "` # # The xset b flag sets the bell volume, pitch, and duration. # The xset c flag controls the key click. # The xset m flag controls the mouse acceleration and # threshold. # The xset s flag sets the screen save parameters. # xset b 18 400 100 c 22 m 7 5 s 600 600 >& $XSESSION_PIPE # # For each screen, set the background color and the colors # and shape of the cursor. This example uses custom colors # defined in an Xcms data file as well as customized bitmaps # (created # with /usr/bin/X11/bitmap) to define the shape # of the cursor. # set SCREEN=0 while ( $SCREEN < $SCREENS ) xsetroot -solid DarkBlueBackground -fg red -bg yellow \ -cursor cursor.bmp cursor_mask.bmp -display $DISPLAY.1 \ >& $XSESSION_PIPE @ SCREEN=($SCREEN + 1) end # Set the SCREEN variable to the screen number of the highest # numbered screen. # @ SCREEN=($SCREENS - 1) # # The xbiff command displays a small mailbox image that lets # you know when you have mail. This example uses the 'letters' # bitmap from /usr/include/X11/bitmaps as well as custom # bitmaps for the full and empty bitmaps and shape masks. # xbiff -shape -update 120 -geometry 60x60-0+0 \ -display $DISPLAY.0 -bg black -fg white \ -bd '#191919195c5c' -xrm "XBiff*fullPixmap: letters" \ -xrm "XBiff*emptyPixmap: $HOME/bitmaps/one.xbm" \ -xrm "XBiff*fullPixmapMask: $HOME/bitmaps/lettersmask.xbm" \ -xrm "XBiff*emptyPixmapMask: $HOME/bitmaps/one.xbm" \ >& $XSESSION_PIPE & # start oclock on screen 0 oclock >& $XSESSION_PIPE & # # Start dxcalendar, xload, and dxmail on the highest numbered # screen. # dxcalendar -display $DISPLAY.$SCREEN >& $XSESSION_PIPE & xload -geometry +0-0 \ -display $DISPLAY.$SCREEN >& $XSESSION_PIPE & dxmail -display $DISPLAY.$SCREEN >& $XSESSION_PIPE & # # Use xmodmap to reorder the mouse buttons and remap the Shift # Lock key on the LK401 or LK201 keyboard to be Escape. # xmodmap -e 'pointer = 2 3 1' >& $XSESSION_PIPE xmodmap -e "clear lock" >& $XSESSION_PIPE xmodmap -e "keycode 176 = Escape" >& $XSESSION_PIPE # # Start the Motif Window Manager as the controlling process. # When mwm exits, the X session will be over. # Using the shell's built-in exec command saves the cost of # creating another process. # exec mwm -multiscreen >& $XSESSION_PIPE # # End of Session # else # # These applications are run only if the display is not local, # that is, the session is run on a remote X Terminal. # # Invoking dxconsole is useful for displaying the stdout of # the commands that run, even though as a remote display, # the display console output will not actually be displayed. # dxconsole < $XSESSION_PIPE & xset b 18 400 100 c 22 m 7 5 s 600 600 >& $XSESSION_PIPE xsetroot -solid DarkBlueBackground -fg red -bg yellow \ -cursor cursor.bmp cursor_mask.bmp >& $XSESSION_PIPE oclock& # # If the X Terminal is running its own local window manager, # mwm is likely to exit immediately, so it is not used as the # controlling process. # mwm >& $XSESSION_PIPE & # # Instead, xterm is used as the controlling process. When # xterm exits, the X session will be over. # exec xterm # # End of Session # endif
# mv /sbin/rc3.d/S95xlogin /sbin/rc3.d/xS95xlogin
#!/bin/csh # # Start the X server. # Using the -ac option disables authentication checking. # /usr/bin/X11/X -ac & # # define anything you might need in your environment # setenv DISPLAY :0 # # You may also configure the X server's font path, keyboard, etc. # by calling Xsetup_0. This will also start dxconsole, but if # you don't want that make your own customized version of # Xsetup_0 and use that. But bear in mind that the X server # will reset when its last connection is closed, so you may need # to hold open a connection, something like this: # /usr/bin/X11/xlogo& /var/X11/xdm/Xsetup_0 # # Now start your application # /path-to-wherever/your-application &
# ln -s /path-to-wherever/my-startup-script /sbin/rc3.d/S95whatever
# mv /sbin/rc0.d/K19xlogin /sbin/rc0.d/xK19xlogin