14.4 Getting User Preferences

This section describes and demonstrates the use of the resource manager in a typical application. For an additional theoretical description of the resource manager, see Chapter 13.

14.4.1 User Defaults for basecalc

As described in Chapter 13, the user’s default values for options are normally found in the XA_RESOURCE_MANAGER property on the root window. That property is normally set by the user with the xrdb program. For compatibility, if there is no XA_RESOURCE_MANAGER property defined (either because xrdb was not run or if the property was removed), your program should assume that the defaults can be found in a file called .Xdefaults in the user’s home directory.

Note that XGetDefault(), described in Chapter 13, only deals with some of this complexity. It does not read the XA_RESOURCE_MANAGER property, and it does not merge in the command line arguments. That is why, in this example, we have used a different, more thorough technique, using the native resource manager calls.

Example 14-3 shows a sample resource database file with two options for basecalc.

Example 14-3. A sample .Xdefaults file

basecalc.base:        2
basecalc.unsigned:    False

For a complete description of preference matching rules, see Chapter 13. The basecalc.base preference sets the base with which the calculator will start and is here specified as binary (base 2). The basecalc.unsigned preference specifies whether the calculator should start up in signed mode or unsigned mode.

14.4.2 Parsing the ...

Get XLIB Programming Manual, Rel. 5, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.