X resources
Encyclopedia
In the X Window System
X Window System
The X window system is a computer software system and network protocol that provides a basis for graphical user interfaces and rich input device capability for networked computers...

, the X resources are parameter
Parameter
Parameter from Ancient Greek παρά also “para” meaning “beside, subsidiary” and μέτρον also “metron” meaning “measure”, can be interpreted in mathematics, logic, linguistics, environmental science and other disciplines....

s of computer program
Computer program
A computer program is a sequence of instructions written to perform a specified task with a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute...

s such as the name of the font
Font
In typography, a font is traditionally defined as a quantity of sorts composing a complete character set of a single size and style of a particular typeface...

 used in the button
Button (computing)
In computing, a button is a user interface element that provides the user a simple way to trigger an event, like searching for a query at a search engine, or to interact with dialog boxes, like confirming an action.-Description:A typical button is a rectangle or rounded rectangle, wider than it is...

s, the background color of menu
Menu (computing)
In computing and telecommunications, a menu is a list of commands presented to an operator by a computer or communications system. A menu is used in contrast to a command-line interface, where instructions to the computer are given in the form of commands .Choices given from a menu may be selected...

s, etc. They are used in conjunction with or as an alternative to command line parameters and configuration file
Configuration file
In computing, configuration files, or config files configure the initial settings for some computer programs. They are used for user applications, server processes and operating system settings. The files are often written in ASCII and line-oriented, with lines terminated by a newline or carriage...

s.

Format

At the X protocol level, resources are strings that are stored in the server and have no special meaning. The syntax and meaning of these strings is given by client libraries and applications.

Every X resource specifies a parameter for a program or one of its components. A fully specified resource has the following format:
application.component.subcomponent.subcomponent.attribute: value


This resource specifies the value of attribute for the component named component.subcomponent.subcomponent of the program application. Resources are often used for specifying the parameters of widgets created by the application. Since these widgets are arranged in a tree, the sequence of component/subcomponent names is used to identify a widget by giving its path within the tree. The value of the resource is the value of an attribute for this widget, such as its background color, etc.

X resources are also used to specify parameters for the program that are not directly related to its widgets, using the same syntax.

X resources are designed to allow the same parameter to be specified for more than one program or component. This is realized by allowing wildcard character
Wildcard character
-Telecommunication:In telecommunications, a wildcard character is a character that may be substituted for any of a defined subset of all possible characters....

s in a resource specification. In particular, the ?
?
or is a letter derived from the Latin alphabet. Both glyphs of the majuscule and minuscule forms of this letter are based on the rotated form of a minuscule e; a similar letter with identical minuscule is used in the Pan-Nigerian Alphabet and some alphabets based on the African reference...

 character is used to match the application name or a single component. The *
Asterisk
An asterisk is a typographical symbol or glyph. It is so called because it resembles a conventional image of a star. Computer scientists and mathematicians often pronounce it as star...

 character is used to match any number of components. These two characters can be used anywhere but at the end of the resource name. In other words, an attribute cannot be replaced by a wildcard character.

While the resources can be loosely specified via the wildcard characters, queries for the value of a resource must specify that resource exactly. For example, a resource can specify that the background of every component of the xmail program must be red:
xmail*background: red


However, when a program (e.g., the xmail
XMail
XMail is a free open-source, developed by Davide Libenzi, POP3/ESMTP mail server for Unix and Microsoft Windows operating systems. Unlike other email servers, XMail does not require that each user have a system account, instead it uses flat-file databases to store user information...

 program itself, when it wants to find out which background color to use) accesses the resource database via Xlib
Xlib
Xlib is an X Window System protocol client library written in the C programming language. It contains functions for interacting with an X server. These functions allow programmers to write programs without knowing the details of the protocol...

 functions, it can only request the value of a specific resource. Contrary to most database
Database
A database is an organized collection of data for one or more purposes, usually in digital form. The data are typically organized to model relevant aspects of reality , in a way that supports processes requiring this information...

s, the stored data can be specified loosely (via wildcard characters), but the interrogation cannot. For example, a program can query for the value of xmail.main.background or of xmail.toc.buttons.background, but cannot use ? or * to check the background color of several components at once.

Resources can also be specified for classes of elements: for example, application.widget.widget.attribute: value can be generalized by replacing the application name with its class (e.g., Mail instead of xmh), each widget with its type (Pane, Button, etc.), and the attribute with its type.

Location and use

During X server execution, the X resources are stored in two standard locations, depending on whether they apply to all screens or to a particular one:
  1. the RESOURCE_MANAGER property of the root window of screen 0
  2. the SCREEN_RESOURCES property of the root window of an arbitrary screen

X resources are stored in the server rather than in a configuration file to allow programs started from other computers to use them. Indeed, a program connecting to an X server from another computer can access the resources via the X protocol. Using the old system of storing program parameters in the .Xdefaults file creates the need of copying this file to all other computers where a program can be started.

Resources are manipulated by the xrdb
Xrdb
xrdb is a program used for accessing the X resources of a server. Its main use is to read a set of resources from a file and store them in the server at startup.This program can access the resources in both read and write mode...

 program. In particular, many X server configurations run xrdb at start up, instructing it to read the resources from the .Xresources file in the user's home directory
Home directory
A Home directory is a file system directory on a multi-user operating system containing files for a given user of the system. The specifics of the home directory is defined by the operating system involved; for example, Windows systems between 2000 and 2003 keep home directories in a folder...

. From this point on, every other program finds the resources in the two standard locations.
You can view the current resources from a console with xrdb -query.

Client libraries

Xlib
Xlib
Xlib is an X Window System protocol client library written in the C programming language. It contains functions for interacting with an X server. These functions allow programmers to write programs without knowing the details of the protocol...

 contains a number of convenience function
Convenience function
A convenience function is a non-essential subroutine in a programming library or framework which is intended to ease commonly-performed tasks...

s for accessing the resources on the server and manipulating them locally. These functions are used both by xrdb and by every other program that needs these resources. Most of these functions manipulate a resource database, which is a local data structure representing a set of resource specifications. The Xlib functions for resource management are:
  • functions for reading the resources on the server into a local string (XResourceManagerString and XScreenResourceString)
  • functions for creating, manipulating, and destroying a local resource database (XrmInitialize, XrmDestroyDatabase, XrmGetFileDatabase, XrmPutFileDatabase, XrmGetStringDatabase, XrmLocaleOfDatabase, XrmSetDatabase, XrmGetDatabase, XrmCombineFileDatabase, XrmCombineDatabase, XrmMergeDatabases, XrmParseCommand)
  • functions for looking up resources and storing new ones (XrmGetResource, XrmQGetResource, XrmQGetSearchList, XrmQGetSearchResource, XrmPutResource, XrmQPutResource, XrmPutStringResource, XrmQPutStringResource, XrmPutLineResource, XrmEnumerateDatabase)


In particular, the function XrmParseCommand allow parsing the command line arguments, reading resources that are then added to a local resource database. This way, the resources can be read from the server and used as defaults that are overridden by command line arguments.

For the sake of efficiency, integers called quarks are defined to represent local strings. Quarks are similar to atoms, but they represent strings stored locally rather than on the server. A number of Xlib functions create an association between strings and quarks. Quarks can be used in place of component names when using one of the above functions; resource names therefore correspond to quark lists.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK