Notice! This document is currently in Archived status.
The content of this document may be incorrect or outdated.

Print this article Edit this article

Using the .Xdefaults file.

Purdue Engineering Computer Network


The file called .Xdefaults in your home directory is loaded into the X server using the xrdb program when you start your X session. In this file, each X application has a number of options which can be set, such as reverse video, window size, window location, and many others. You can set these options so that they are set every time you start up an application. A line in your .Xdefaults file follows this format:

	
name.class.resource: value
name
is usually the name of the program (e.g., xterm, or xclock). You can, however, change the name a program uses to find its options in the .Xdefaults by invoking the command with -name argument.

 

class
is used for grouping resources together. For example, the class Geometry would contain all the resources which affect the geometry of any of the application's windows. For example, xterm uses the resources geometry for the size and location of the VT window: iconGeometry for the size and location of the icon and tekGeometry for the size and location of the Tek window. All of these are members of the class Geometry. The purpose of a class is to allow you to set things more easily. If you set a class to a given value, then all the individual resources in that class will be set to that value, just as if you set them individually. Thus you could set all three xterm geometries individually, or if you wanted them all to be the same you could just set the Geometry class. The names of classes conventionally start with an upper-case letter.

Those classes, which are understood by each application program, are described in the manual entry for that program or you can use xprop. Simply start up the X program in question, type "xprop" at a unix prompt, and click in the window of the X program. This will give you the class and instance of the program. For example, using xprop on an "xterm" window gives:

% xprop

WM_STATE(WM_STATE):
window state: Normal
icon window: 0xc004a2
WM_PROTOCOLS(ATOM): protocols WM_DELETE_WINDOW
WM_CLASS(STRING) = "xterm", "XTerm"
WM_HINTS(WM_HINTS):
Client accepts input or input focus: True
Initial state is Normal State.
WM_NORMAL_HINTS(WM_SIZE_HINTS):
program specified size: 899 by 412
program specified minimum size: 30 by 21
program specified resize increment: 11 by 17
program specified base size: 19 by 4
WM_CLIENT_MACHINE(STRING) = "america.ecn.purdue.edu"
WM_COMMAND(STRING) = { "xterm" }
WM_ICON_NAME(STRING) = "xterm"
WM_NAME(STRING) = "xterm"
There can actually be more than one class for a given object. That is, there can be classes of classes. A good example of this is xterm which has a major class (or "super-class") called VT100, and several minor classes (or "sub-classes"), such as Font, Geometry, so on. Generally, if you're not sure of how many classes and sub-classes there are, you can use the "*" character to specify "match anything".

 

resource
indicates the name of some resource whose value can be changed. Some resources include foreground (the foreground color), background (the background color), geometry (the size and location of the window), ScrollBar, (indicate whether or not scrollbars should be used) and so on. The names of resources conventionally start with a lower-case letter. Each application program has a different set of resources which you can modify; they are described in the manual entry for the program.

Note on class and resource names: Capitalization is used to distinguish class names from resource names. Class names always begin with a capital letter, while resource names always begin with a lowercase letter. Note however that if a resource name is a compound word (such as cursorColor), the second word is capitalized.

 

value
can be set to three types:
  • integer (a whole number)
  • Boolean (on/off, yes/no)
  • string (sequence of characters, e.g., a pathname or window title).

Changing the Foreground and Background Colors

To change the foreground color for an application, use the -fg command line option or the foreground resource. For example, suppose you have a color display and want the text in your xterm windows to be blue instead of black:

	% xterm -fg blue &

or set the following resource:

	XTerm*foreground:blue

To change the background color, use the -bg command line option or the background resource. For example, suppose you want the same xterm window on your color display to have a yellow background instead of white:

	%xterm -bg yellow &

or set the following resource:

	
XTerm*background:yellow

Reverse-video Option

The -rv (reverse-video) command line option specifies that a client be started with its foreground and background colors swapped. In many cases, this means that a window will be white on black, rather than black on white.

 

Changing the Title

Most window managers have a titlebar which may be named for the application (program) you are running. However, you can change the name of your titlebar using the title command line option or the title resource.

There is also a -name command line option (and corresponding name resource). This basically changes the name of the client. The new name appears in the titlebar and in the icon name and also affects what resources apply to the client.

For example, using -name we have a class of XTerm, but an instance of xterm-big. So, you could create resources like this:

	XTerm*reverseVideo:   	    on
xterm*VT100.geometry: 80x24
xterm-big*VT100.geometry: 80x48
xterm-small*VT100.geometry: 80x10

where EVERY xterm you start will have reverse video on. However, one started with the -name xterm-big option will have one geometry; one started with the -name xterm-small option will have another geometry, and one started with no specific name will default to the name 'xterm' and have yet a different geometry. (The VT100 designation is used to indicate that the geometry is for the main text window, not the menus, subwindows, or Tek window).

The resource name (e.g. 'geometry' in the above example) is a particular aspect of an X program. NOTE: Only particular spellings of resources are correct. Example: 'reverseVideo' and 'ReverseVideo' will function correctly as xterm resources, but not other spellings.

Other examples are:

	oneko*tora: true

matlab*reverseVideo: false ! matlab windows in "reverse video"

emacs*Font: 8x13 ! emacs with 8x13 font, 80 columns
emacs*geometry: 80x48+0+0 ! wide, 48 columns high

XTerm*scrollBar: on ! Xterms with a scrollbar that
XTerm*saveLines: 250 ! keep track of last 250 lines

XTerm*VT100.geometry:80x48+0+0 ! Make only the main xterm
! window be 80x48

Tight Bindings and Loose Bindings

An asterisk is a kind of wildcard, referred to as a "loose binding". When you use the asterisk as a separator, you say: "I don't care how many levels in the widget hierarchy occur between these two points". So you can say:

	xterm*scrollbar:  on

without having to know what widgets have been introduced.

A period, by contrast, is considered a "tight binding" between two levels in the hierarchy. It specifies an exact relationship.

In an application that supports multiple levels of widgets, you can mix asterisks and periods. In general, though, the developers of X recommend always using * rather than . as the separator even with simple applications, since this gives application developers the freedom to insert new levels in the hierarchy as they produce new releases of an application.

The manual page for each application should always tell you to what widget the resource belongs, so that you can correctly specify the hierarchy. If you are in doubt, use the * separator.

Additional Information

  • The exclamation mark (!) or /*...*/ is used to comment a line in the .Xdefaults file. For example:
    	 /* this is a comment */
  • Instance names are considered more specific than class names. If you use both the class and instance names of a program to specify a resource with different values, the instance resource value will be used. For example:
    	xterm*Background: blue
    will be used, instead of:
    	XTerm*Background: green
  • To reread your .Xresources file, and throw away your old resources, you can type:
     	xrdb ~/.Xdefaults
  • To reread your .Xresources file, and keep your old resources, type:
     	xrdb -merge ~/.Xdefaults
    This will merge any new resources you've put in with the currently active resource settings.

     

  • Avoid blank spaces at the beginning and end of lines in the .Xdefaults file.

     

  • You can change the instance of many X programs by starting them with the -name option. For example, if you start an xterm window by typing "xterm -name XT1", then you can specify resources for it in your .Xdefaults file with "XT1,", like this:
    	XT1*Background: yellow

Last Modified: Dec 19, 2016 11:12 am US/Eastern
Created: May 31, 2007 1:18 pm GMT-4 by admin
JumpURL: