home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Running Linux, 4th Ed.Running Linux, 4th Ed.Search this book

Chapter 11. Customizing Your X Environment

X is now running. But that's only half the story. In the last chapter, you learned how to set up the X Window System so that it recognizes your graphics board and your monitor. While this is clearly necessary, it is of course not the whole story. In this chapter, we will explain the other half: customizing your X environment. Why is customization important? When working in the X Window System, you might want to change your work environment from time to time because your work habits have changed, because new and better environments are available, or simply because the old one has become boring to you. Some of these environments are quite sophisticated. For example, they let you start up a program with all the options you want at the press of a key or the click of a mouse, they let you drag file icons onto a printer to have text printed, and they can do lots of other things that make you more productive in your daily work.

In this chapter, we'll first talk about some very basic aspects of X customization and then introduce you to the two most prominent desktop environments on Linux: KDE and GNOME. For readers who want to dig deeper or need a type of application that is provided with neither KDE nor GNOME, we'll then look at a general means of configuring (older) X applications, the X resources, as well as some general X applications that run independent of any desktop environment.

Until recently, the problem with using X on Unix systems in general and Linux in particular was that nothing was integrated. You would use a window manager and a number of X applications, but they would all look and behave differently, and operate in a manner that was not integrated. For example, drag-and-drop — ubiquitous on Windows or the Macintosh — was hardly heard of on Linux, and if it was, it was difficult to find two applications that could interact together with drag-and-drop.

A relatively new category of software, the so-called desktop environment, has accepted the challenge to produce a state-of-the-art Unix GUI and tries to provide an integrated, consistent desktop where all programs have the same look-and-feel, behave the same, and even provide the same menus in all applications (to the extent where this is possible).

Currently, two main desktop environments are available for Linux: the K Desktop Environment (KDE) and GNOME. KDE is a little bit older and much more advanced with respect to functionality and stability. It aims at making people coming from other computing environments feel at home, as well as providing long-term Unix users a more productive and friendly work environment. GNOME, on the other hand, has put a lot of work into the visual aspects of a desktop environment with colorful icons and the like, but it is less stable than KDE, and the individual programs are less integrated. KDE is the default environment with most distributions, but almost all of them ship both. If yours doesn't, this could mean that the distribution vendor is trying to decide over your head what to use. We will cover both KDE and GNOME here.

In Version 8.0 of Red Hat Linux, the appearance for both KDE and GNOME has been set to a custom Red Hat theme that makes them much more similar to each other. The goal is to provide a single, consistent look and feel for the software, regardless of whether they choose KDE or GNOME. That similarity is intended to make Red Hat Linux easier to support and to provide it with an identifiable appearance, regardless of the destop framework used. In some cases, it may even be difficult to tell whether you're running GNOME or KDE. If you don't like the new appearance, it's easy enough to change the settings back. Very little aside from the settings is different from the software as shipped by the GNOME and KDE projects themselves.

11.1. Basics of X Customization

Before running X applications, it's a good idea to learn the rudiments of X customization so that you're not forced to live with the (often unappealing) default configuration used on many systems. Note that the next few sections do not usually apply to the aforementioned desktop environments, which have more user-friendly, GUI-based ways to configure applications and the environment. It's still good to know the old-fashioned way of configuring things because you are likely to come across applications that still follow this scheme.

11.1.1. xinit

You run X with the startx command. This in turn is a frontend for xinit, the program responsible for starting the X server and running various X clients that you specify. xinit (via startx) executes the shell script .xinitrc in your home directory. This script merely contains commands that you wish to run when starting X, such as xterm, xclock, and so on. If you don't have a .xinitrc file, the system default /usr/lib/X11/xinit/xinitrc is used instead.

TIP: When using KDE, you will often have only one single command in your .xinitrc file: startkde. This is a shell script shipped with KDE that starts all necessary services. Your distributor might add other stuff to .xinitrc, though.

Here, we'll present a sample .xinitrc file for a bare-bones X system without any desktop environment and explain what it does. You could use this as your own, very bare-bones .xinitrc or copy the system default xinitrc as a starting point:

          1  #!/bin/sh
          2  # Sample .xinitrc shell script
          4  # Start xterms
          5  xterm -geometry 80x40+10+100 -fg black -bg white &
          6  xterm -geometry -20+10 -fn 7x13bold -fg darkslategray -bg white &
          7  xterm -geometry -20-30 -fn 7x13bold -fg black -bg white &
          9  # Other useful X clients
          10 oclock -geometry 70x70+5+5 &
          11 xload -geometry 85x60+85+5 &
          12 xbiff -geometry +200+5 &
          13 xsetroot -solid darkslateblue &
          15 # Start the window manager
          16 exec fvwm2
TIP: A number of programs are started here; obviously, this will work only if you have installed them. If you go with the default installation of your distribution, chances are that either the desktop environment KDE or GNOME will be installed and these older programs will not be available. They should be on the distribution media, though, waiting to be installed. While you cannot have more than one window manager running at the same time, you can have as many of them installed as you like.

This should be quite straightforward, even if you're not familiar with X. The first two lines simply identify the shell script. Lines 5-7 start up three xterm clients (recall that xterm is a terminal-emulator client). Other clients are started on lines 10-13, and on line 16 the window manager, fvwm, is started.

Running startx with this particular .xinitrc in place gives you something that looks like Figure 11-1.[40]

[40]All right, so it's not a work of art, but we needed something simple that would work correctly on most displays!

Figure 11-1

Figure 11-1. Screen created by sample .xinitrc file

Let's look at this in more detail. On line 5, we see that xterm is started with several options, -geometry, -fg, and -bg. Most X clients support these standard options, among others.

The -geometry option allows you to specify the size and position of the window on the display. The geometry specification has the format:


In this case, the option -geometry 80x40+10+100 puts the window at the location (10,100) on the screen (where (0,0) is the top-left corner), making it 80 characters wide by 40 characters high. Note that xterm measures the size of the window in characters, not pixels. The actual size of the window in pixels is determined by the font that is used.

The -fg and -bg arguments allow you to specify the foreground (text) and background colors for the xterm window, respectively. The colors used here are a rather boring black and white, but this should work on color and monochrome displays alike. Under X, colors are usually specified by name, although you can provide your own RGB values if you prefer. The list of color names (and corresponding RGB values) is given in the file /usr/lib/X11/rgb.txt. Running xcolors will display these colors, along with their names.

Line 6 runs another xterm, although the arguments are slightly different:

            xterm -geometry -20+10 -fn 7x13bold -fg darkslategray -bg white &

First of all, the geometry specification is just -20+10. Without size parameters, xterm will use the default, which is usually 80x25. Also, we see that the xoffset is prefixed with a -, instead of a +. This places the window 20 pixels from the right edge of the screen. Likewise, a geometry specification of -20-30 (as used on line 7) means to place the window 20 pixels from the right edge of the screen and 30 pixels from the bottom. In this way, the placement of windows is less dependent on the particular resolution you're using.

The -fn option on lines 6 and 7 specifies that the font used by xterm should be 7x13bold. Using the command xlsfonts displays a complete list of fonts on your system; the X client xfontsel allows you to select fonts interactively — more about fonts later.

On line 10 we start an oclock client, which is a simple analog clock. Line 11 starts xload, which displays a graph of the system load average (number of running processes) that changes with time. Line 12 starts xbiff, which just lets you know when mail is waiting to be read. Finally, on line 13 we do away with the bland gray X background and replace it with a flashy darkslateblue. (Fear not; there is more fun to be had with X decor than this example shows.)

You'll notice that each X client started on lines 6-13 is executed in the background (the ampersand on the end of each line forces this). If you forget to put each client in the background, xinit executes the first xterm, waits for it to exit (usually after you log out), executes the next xterm, and so on. The ampersands cause each client to start up concurrently.

What about line 16? Here, we start fvwm (Version 2), a window manager used on many Linux systems. As mentioned before, the window manager is responsible for decorating the windows, allowing you to place them with the mouse, and so forth. However, it is started with the command:

            exec fvwm2

This causes the fvwm2 process to replace the xinit process. This way, once you kill fvwm,[41] the X server shuts down. This is equivalent to, but more succinct than, using the Ctrl-Alt-Backspace key combination. Whether you are returned to the command line after the X server has shut down or are presented with a new graphical login depends on your system configuration.

[41]If you have experimented with fvwm, you'll notice that pressing the first mouse button while the cursor is on the background causes a menu to pop up. Selecting the Quit fvwm option from this menu causes fvwm to exit.

In general, you should put an ampersand after each X client started from .xinitrc, and exec the window manager at the end of the file. Of course, there are other ways of doing this, but many users employ this technique.

The fvwm2 window manager was the default window manager on most Linux systems for a very long time. It is still around, but has mostly been superseded by either the very advanced kwin window manager shipped with KDE or one of the more modern freestanding window managers, such as blackbox or sawfish.

If you read the manual pages for xterm and the other X clients, you'll see many more command-line options than those described here. As we said, virtually everything about X is configurable. fvwm (Version 2) uses a configuration file of its own, .fvwm2rc, described in its manual page. (If you have no .fvwm2rc file, the system default /usr/lib/X11/fvwm2/system.fvwmrc is used instead.) More modern window managers still use configuration files, but usually provide you with user-friendly, GUI-based configuration programs that let you make your settings and then save them to the configuration file in the correct format. The manual pages, as well as books on using X, such as the X Window System User's Guide (O'Reilly), provide more information on configuring individual clients.

Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.