This is the original text which was eventually edited, translated and published in Issue 7 of O'Reilly's The X Resource.

xrdb and Screen Specific Resources

The R5 release of the X Window System included significant but mostly unnoticed enhancements to xrdb. These are in the area of per-screen, or screen-dependent, resources.

Prior to R5, all resources were placed on the RESOURCE_MANAGER property on the root window of screen 0. R5 still uses this property for global resources, but adds the capability to use a SCREEN_RESOURCES property for each screen. This property is placed on the root window of any or all screens, as requested.

Once in place, the standard resource manager code handles this automatically for you; client code does not need to change.

Why would you need screen-dependent resources? I have run across two requirements for this in my work. The first is somewhat similar in concept to xrdb processing using the COLOR variable, but the execution is quite different.

Just as some system configurations include a mono and a color screen, others include two color screens of different resolution or depth. In this case, while red is probably recognizable as red on both screens, various shades of red may not be easily distinguished on a screen with less colors. Lower resolution screens may require different fonts, line widths, etc.

In the next case, color is used to allow the user to more easily determine what is being looked at. A subway monitoring system might use one screen per rail line, eg, a subway might have a Red Line and a Blue Line.

In either case, the easy solution is to use the new -screen option of the xrdb command. Unfortunately, the man page is not completely clear on proper usage of this feature.

xrdb does not set any screen-dependent variables which cpp can test. Instead, it simply applies all resources cpp passes through to the appropriate destination - the global resource or the designated screen resource. To set resources specific to screens 0 and 1 of display 0 on hostname, you could use the following commands (file names are suggestions only).

  xrdb -load -screen -display hostname:0.0 .Xdefaults_0
  xrdb -load -screen -display hostname:0.1 .Xdefaults_1
Any global (per-display) resources would remain unchanged; any screen-dependent resources would simply take precedence.

The -screen -display host:display.screen arguments are the all that is required to set or query screen-dependent resources.

To examine screen-dependent resources, you use the same syntax as you normally would, with the addition of the above arguments.

   xrdb -query -screen -display hostname:0.0
This will show the screen-dependent resources for screen 0.

To see the resources set on all screens, you would simply type

   xrdb -query -screens
resulting in output similar to the following.
   ! screen-independent resources

   ! screen 0 resources
   *RailLineColor: Red
   *Text*Background: Pink

   ! screen 1 resources
   *RailLineColor: Blue
   *Text*Background: LightBlue
Likewise, you can specify -screens with the -load, -remove, or -merge options. This is primarily used with -merge to override settings without a complete reloadm or with -remove.

To see all resources - ie, screen-independent and screen- dependent resources, you specify the -all option (this is the default for the R5 version of xrdb).

To see only screen-independent resources, specify the -global option.

Note that using -all has no effect on a display with only one screen. This is because xrdb assumes displays with 1 screen do not use screen-dependent resources. This is a rational assumption, and if you use per-screen resources in both multi-screen and single-screen environments, you will need to consider this.

Even in the single-screen case, if you specify screen-dependent resources, they will still have precedence over screen-independent resources.

To centralize my resources, I prefer to have everything which is loaded by xrdb handled through .Xdefaults . To easily utilize this configuration with screen-independent resources, I use the -D option of cpp, which xrdb handles correctly. The following is similar to a setup I used on a system with two screens on one display, the first a 4-bit screen, the second a 16-bit screen. (Note that I use cpp-defined and xrdb-defined symbols as well, to better configure whichever system I'm on.)

.Xdefaults:

   #ifdef SCREEN
   # if SCREEN == 0
   #   include "/u/meo/.Xdefaults_0"
   # elif SCREEN == 1
   #   include "/u/meo/.Xdefaults_1"
   # endif
   #else
     *DefaultFont: -*-courier-medium-r-normal--*-100-*-*-m-*-*-*
   # include "/u/meo/app-defaults/XTerm"
   # ifdef NeXT
       *WarningColor: Orange
       XTerm*Background: #000040
       XTerm*Foreground: White
   # else
       *WarningColor: Red
       XTerm*Background: MidnightBlue
       XTerm*Foreground: Wheat
   # endif
   !
   # if (SERVERHOST == hostname) && (CLIENTHOST == vulture)
   #   include "/u/meo/app-defaults/LoginMgr"
   # endif
   #endif

.Xdefaults_0:

   *RailLineColor: Red
   ! The following is because screen 0 is currently lower-res
   *DefaultFont: 9x15

.Xdefaults_1:

   *RailLineColor: Blue
The following commands then appear in my .xinitrc and .xsession files (based on the default files, which define the variable userresources as $HOME/.Xresources).
   xrdb -merge $userresources
   xrdb -screen -display :0.0 -merge $userresources -DSCREEN=0
   xrdb -screen -display :0.1 -merge $userresources -DSCREEN=1

Last updated: 10 July 1996

Copyright 1993, 1994 Miles O'Neal, Austin, TX. All rights reserved.

Miles O'Neal <roadkills.r.us@XYZZY.gmail.com> [remove the "XYZZY." to make things work!] c/o RNN / 1705 Oak Forest Dr / Round Rock, TX / 78681-1514