17
Resources
In the X Window System, the user can configure the interface according to options available
in specific applications. The user accomplishes this through a resource database that resides
in the X server. The X Protocol provides many ways to access the resource database, as well
as many functions to aid in this task. You should consult Chapter 11, Managing User Prefer-
ences, in Volume One, Xlib Programming Manual, for a complete, in-depth discussion of X
resource specification and management. Related programs include xrdb, and related func-
tions can be found in Volume Two, Xlib Reference Manual.
XView provides many functions that allow the programmer to interact with the server to get
or set resources specified by the user. Robust applications should account for user-definable
defaults. That is, your programs should always consider the user’s wishes for changing attri-
bute values for things like fonts, colors and maybe even window sizes, as long as the values
do not interfere with the normal running of the program. You should also provide the user
with a list of resources that can be set, and you should test for them in your application.
17.1 Predefined Defaults
All of the packages in XView look for predefined defaults that the user can set in his/her
resource environment. Table 17-1 outlines these defaults, their types and legal values. Refer
to Section 6, Command-line Arguments and XView Resources, in the XView Reference Man-
ual for a description of each of the XView resources. Note that the term maxint refers to the
maximum value for an integer on your particular machine. These values tend to be rather
large with respect to the intended values used by these resources. It is up to the user to use
“reasonable” values.
NOTE
Table 17-1 does not include the mouseless model resources. Refer to Section 6,
Command-line Arguments and XView Resources, in the XView Reference Man-
ual for a list of the mouseless resources.
Resources
Resources 381
Table 17-1. Resources and Default Values Understood by XView
Name Type Default Legal Values
alarm.audible boolean True True, False
alarm.visible
boolean True True, False
cmdtool.checkpointFrequency
integer 0 0, <maxint>
cmdtool.maxLogFileSize
integer <maxint> 0, <maxint>
font.name
string NULL fontname-size
icon.font.name
string NULL fontname-size
icon.pixmap
string NULL pixmap filename
icon.footer
string NULL footer string
icon.x
integer 0 —
icon.y
integer 0 —
keyboard.arrowKeys
string Yes Yes, No
keyboard.leftHanded
string No Yes, No
mouse.multiclick.space
integer
notice.PopupJumpCursor boolean True True, False
notice.beepCount
integer 1 —
openWindows.DragRightDistance
integer 100 0, <maxint>
openWindows.3DLook.color
boolean True True, False
openWindows.3DLook.monochrome
boolean True True, False
openWindows.multiClickTimeout
integer 4 1 through 10 (in sec/10)
openWindows.dragRightDistance
integer 5 —
openWindows.scrollbarPlacement
string right Left, Right
OpenWindows.MonospaceFont
string NULL fontname-size
OpenWindows.RegularFont
string NULL fontname-size
OpenWindows.BoldFont
string NULL fontname-size
OpenWindows.Scale
string NULL Small, Medium, Large, Extra-Large
scrollbar.repeatDelay
integer 100 0, 999 (msec delay interval)
scrollbar.pageInterval
integer 100 0, 999 (msec delay interval)
scrollbar.lineInterval
integer 1 0, 999 (msec delay interval)
server.name
string getenv(DISPLAY) hostnamedisplay
term.boldStyle
string Invert xview.ICCCMCompli-
ant@boolean@True@True, False
None,
OFFSET_X, OFFSET_Y,
OFFSET_X_AND_Y
,
OFFSET_X_AND_XY,
OFFSET_Y_AND_XY,
OFFSET_X_AND_Y_AND_XY,
OFFSET_XY, INVERT
term.enableEdit boolean True True, False
term.inverseStyle
string Enable ENABLED, DISABLED,
SAME_AS_BOLD
term.underlineStyle string Enable ENABLED, DISABLED,
SAME_AS_BOLD
text.againLimit integer 1 0, 500
text.autoIndent
boolean False True, False
text.autoScrollBy
integer 1 0, 100
382 XView Programming Manual
Table 17-1. Resources and Default Values Understood by XView (continued)
Name Type Default Legal Values
text.blinkcaret boolean True True, False
text.checkpointFrequency
integer 0 0, <maxint>
text.confirmOverwrite
boolean True True, False
text.displayControlChars
boolean False True, False
text.enableScrollbar
boolean True True, False
text.extrasMenuFilename
string .text_extra_menu filename
(in /usr/lib)
text.insertMakesCaretVisible
string If_auto_scroll If_auto_scroll, Always
text.lineBreak
string Wrap_word Clip, Wrap_char, Wrap_word
text.margin.bottom
integer 0 –1, 50
text.margin.left
integer 8 0, 2000
text.margin.right
integer 0 0, 2000
text.margin.top
integer 2 –1, 50
text.maxDocumentSize
integer 20000 0, 0x80000000
text.retained
boolean False True, False
text.storeChangesFile
boolean True True, False
text.tabWidth
integer 8 0, 50
text.undoLimit
integer 50 0, 500
window.color.foreground
string "0 0 0" 3 RGB values, 0-255
window.color.background
string "255 255 255" 3 RGB values, 0-255
window.columns
integer 80 —
window.height
integer 34 rows Greater than 0
window.header
string NULL header string
window.iconic
boolean False True, False
window.inheritcolor
integer 1
window.mono.disableRetained
boolean False True, False
window.rows
integer 34 —
window.scale
string Medium Small, Medium, Large,
Extra_Large
window.width
integer 80 columns Greater than 0
window.x
integer 0 —
window.y
integer 0 —
Note: In XView 3.2 and later, the resource Font.Name will still be read by any XView
application, however, if OpenWindows.MonospaceFont, OpenWindows.Regular-
Font or OpenWindows.BoldFont exist in the X Resource Database, they will take pre-
cedence.
XView 3.2 and later uses the new resource OpenWindows.Scale. In earlier releases of
XView, “scale” was determined by reading the resource “Window.Scale.” The new resource
is synonymous with the old resource name and XView will continue to look at the old
resource “Window.Scale” if the new resource, OpenWindows.Scale, does not exist.
XView provides many functions to get resource values from the database. Basically, values
Resources
Resources 383
come in several types: int, character (strings), boolean (which can be specified using
a number of string values; see below), and enumerated values.
Example 17-1 lists a simple application that introduces the use of one of the functions pro-
vided by the defaults package. The program default_text.c creates a frame with a text
subwindow whose font is specified by the user’s resource textsw.font.
Example 17-1. The default_text.c program
/*
* default_text.c -- use the defaults package to get a font name from
* the resource database to set the textsw’s font.
*/
#include <xview/xview.h>
#include <xview/font.h>
#include <xview/defaults.h>
#include <xview/textsw.h>
main(argc, argv)
char *argv[ ];
{
Frame frame;
Xv_Font font;
char *name;
xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
frame = (Frame)xv_create(NULL, FRAME, NULL);
name = defaults_get_string("textsw.font","Textsw.Font", "fixed"),
font = xv_find(frame, FONT,
FONT_NAME, name,
NULL);
xv_create(frame, TEXTSW,
XV_FONT, font,
WIN_COLUMNS, 80,
WIN_ROWS, 10,
NULL);
window_fit(frame);
xv_main_loop(frame);
}
default_text.c shows how an XView program queries the resource database for a string value
associated with a name-class pair. defaults_get_string() gets the string value asso-
ciated with Textsw.Font. If the resource database has this attribute, then the value is
returned. If not, the default (fixed) is returned.
384 XView Programming Manual
17.2 XView Resource Database Functions
The functions that XView provides are defined in <xview/defaults.h>. The following func-
tions are provided by XView for setting and getting resource values to and from the database.
Note that when setting resources to the database, the database on the server is updated—not
the user’s defaults database. Resources not updated to the user’s defaults database are not
retained for the next time the X server is started.
void
defaults_init_db()
This function is called automatically by xv_init(), so it need not be called by your appli-
cation. defaults_init_db() calls XrmInitialize().
void
defaults_load_db(filename)
char *filename;
defaults_load_db() loads the database residing in the specified filename or the server
database if filename is NULL. The database found in filename is loaded via XrmGet-
FileDatabase() and is merged into the existing resource database via XrmMergeDa-
tabases().
void
defaults_store_db(filename)
char *filename;
This function writes the database to the specified file via XrmPutFileDatabase(). This
must be done in order to ensure that the database is accessible the next time the server is
started.
Bool
defaults_exists(name, class)
char *name;
char *class;
This function returns TRUE if the resource exists in the database via XrmGetResource().
For more information, refer to Volume One, Chapter 11, Managing User Preferences.
17.2.1 Boolean Resources
Bool
defaults_get_boolean(name, class, default_value)
char *name, *class;
int default_value;
void
defaults_set_boolean(resource, value)
char *resource;
Bool value;
Resources
Resources 385
Get Volume 7A: XView Programming Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.