-->
Previous Table of Contents Next


X Resource Files

Another topic under X that is different from the Windows and Macintosh environments is resource files. You’ll find that X resource files are either the savior or bane of your existence. Like the Windows and Macintosh systems, resource files on X allow you to customize fonts, colors, and text messages, all without access to the application’s source code.

This concept is great. You can tell an application to use a more readable font, you can get rid of garish colors, you can even write Finnish messages in place of all the English ones, or you can fix up the English messages to something more to your liking.

X resource files provide a powerful mechanism to customize just about every X application. There are many locations—both within a resource file and on disk—to which you can place these resources files. Because many options conflict, it’s easy to get lost in all the details.

Stripped to its basics, an X resource file is an ASCII text file that specifies some option for a program or programs. Each line of the resource file specifies a resource to set and its value. For example, you can specify in an X resource file that all xterm programs should start up with the scrollbar turned on, which we’ll show how to do soon. You can also control fonts, colors, and a lot of the text displayed by most X programs.

To set up the scrollbar commands for xterm in a resource file, create a file named XTerm (note the capitalization) in your home directory. Both the file name, XTerm, and the location (your home directory) are essential. Put in the following lines:


  XTerm*scrollBar: True

  XTerm*saveLines: 1000

These X resource commands tell xterm to use a scrollbar and to save 1000 lines in its scroll buffer. Save this file and start another xterm program. You should see a scrollbar.

For more on X resource files, see the book list in Appendix A.

Controlling Fonts and Colors

Like most options, you can control xterm’s choice of fonts and colors from both command-line parameters and X resource files. What we usually do is set up the options we always want in an X resource file and then use the command-line parameters only for options we rarely need.

Normally, we’re happy with xterm’s color defaults: black text on a white background. It’s the font we’d like to change. By default, xterm uses the font named fixed, a fixed-character-size font (as opposed to a proportional font). We find this font far too small, so we’d like to use a larger one.

For setting the font, you can use the -font command-line parameter or set the font resource. To do the latter, you can add the following line to the XTerm file you created:


  XTerm*font: -*-courier-medium-r-normal--14-140-75-75-m-90-*

This sets up a much more pleasing (to our eyes at least) and larger font for xterm.

To get a list of the available fonts, use the program xlsfonts, which will present you with a huge list. For xterm, you want a fixed-width font. The Courier fonts typically are fixed-width, as are the Lucida typewriter fonts. In the very long font names, the fixed-width fonts should have an m or c, as shown here, after the two 75s:


  -adobe-courier-medium-r-normal--14-140-75-75-m-90-iso8859-1

As usual, to test this, save the XTerm file and start another xterm program.

For our XTerm file, we set the following resources:


  !

  !     XTerm resource file

  !

  XTerm*foreground:  black

  XTerm*cursorColor: black

  XTerm*background:  white

  XTerm*scrollBar:   True

  XTerm*saveLines:   1000

  XTerm*font: -*-courier-medium-r-normal--14-140-75-75-m-90-*

Lines beginning with an exclamation mark (!) are comments. We list the most-used xterm command-line parameters in Table 3.15.

Table 3.15 Commonly Used Xterm Command-Line Parameters
Parameter Meaning

-bg color Sets background color; defaults to white
-cr color Sets color of text cursor; defaults to black
-display hostname:0 Sets name of X display to which to connect
-e program [args] Runs program instead of shell
-fg color Sets foreground color; defaults to black
-fn fontname Uses the given font
-font fontname Uses the given font
-geometry geom Uses given size and location
-ls Turns shell into login shell
-sb Turns on scrollbar


Previous Table of Contents Next