[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ 14 ] [ 15 ] [ 16 ] [ 17 ] [ 18 ] [ A ] [ B ] [ C ] [ D ] [ next ]


Debian Tutorial (Obsolete Documentation)
Chapter 10 - The X Window System


This chapter describes the X Window System graphical user interface. It assumes that you have already successfully configured X as described in the Installation Manual (again, the install manual is not yet written; for now you will need to use the XFree86 HOWTO, the contents of /usr/doc/X11, and this chapter). Once you install X, you can enter the X environment by typing startx or via xdm, depending on your choice during configuration.


10.1 Starting the X environment

There are two ways of starting X. The first is to start X manually when you feel like using it. To do so, log in to one of the text consoles, and type startx. This will start X and switch you to its virtual console.

The second (and recommended) way to use X is with xdm, or X Display Manager. Basically xdm gives you a nice graphical login prompt on the X virtual console (probably VC 7), and you log in there.

By default, either method will also start an xterm, which is a small window containing a shell prompt. At the shell prompt, you can type any commands just as you would on a text VC. So you can follow all the examples in this tutorial using xterm; the only difference between an xterm and the text console is that you don't have to log on to the xterm, since you already logged on to X.

There are also a lot of things you can do only in X, which are covered in this chapter.

One note: the default xterm has a smallish font. If you have a small monitor or very high resolution or bad eyesight, you may want to fix this. Follow these steps:

  1. Move the mouse pointer into the center of the xterm window.

  1. Hold down the Control key and the right mouse button simultaneously. This will give you a font menu.

  1. Point to the font you want and release the mouse button.


10.2 Intro: What is X

A GUI (Graphical User Interface) is part and parcel of the Windows or Mac operating systems. It's basically impossible to write an application for those systems which does not use the GUI, and the systems can't be used effectively from the command line. GNU/Linux is more modular, that is, made up of many small, independent components which can be used or not according to one's needs and preferences. One of these components is the X Window System, or simply X[14].

X itself is a means for programs to talk to your mouse and video card, without knowing what kind of mouse and video card you have. That is, it's an abstraction of the graphics hardware. User applications talk to X, in X's language; X then translates into the language of your particular hardware. This means that programs only have to be written once, and they work on everyone's computer.

In X jargon, the program which speaks to the hardware is known as an X server. User applications that ask the X server to show windows or graphics on the screen are called X clients. The X server includes a video driver, so you must have an X server which matches your video card.

The X server doesn't provide any of the features one might expect from a GUI, such as resizing and rearranging windows. A special X client, called a window manager, draws borders and titlebars for windows, resizes and arranges windows, and provides facilities for starting other X clients from a menu. Specific window managers may have additional features.

Window managers available on a Debian system include fvwm, fvwm2, icewm, afterstep, olvwm, wmaker, mwm, twm, enlightenment and others. You'll probably want to try them all and pick your favorite. (For information on window managers, and other fun stuff about X, X11.org is a nice site.)

Neither the X server nor the window manager provide a file manager; that is, there aren't any windows containing icons for your files and directories. You can launch a file manager as a separate application; there are many of them available, though unfortunately there aren't yet any good icon-based ones. The GNOME desktop project is developing an icon-based file manager and other GUI facilities, however. See the GNOME project home page for the latest news on this.

A final feature of X is its network transparency, meaning that X clients don't care if they're talking to an X server on the same machine or an X server somewhere on the network. In practical terms, this means you can run a program on a more powerful remote machine, but display it on your desktop computer.


10.3 Basic X operations


10.3.1 The mouse

The mouse in X works pretty much the same as the mouse on other systems, except that it has three buttons. If your mouse only has two, you can simulate the third (middle) button by clicking both buttons simultaneously. This is kind of tricky and annoying, so investing in a $15 3-button mouse probably isn't a bad idea. These are available from just any computer retailer.

The buttons are numbered from left to right, assuming you have a right-handed mouse, so button one is on the left, two in the middle, three on the right. You may see either the numbers or the locations in documentation.

X has a simple built-in copy-and-paste facility. To select text to copy, you click and drag with the left mouse button. This should select the text to copy, assuming the application you're using has copy-and-paste support. To paste the text, you click the middle mouse button in a different X application. For example, if you receive an email containing an URL, you can select the URL with the left button, then click in your web browser's "Location" field with the middle button to paste it in.


10.3.2 X clients

Programs that communicate with the X server are called X clients. Most of these programs will ask the X server to display windows on the screen.

You start an X client the same way you start any other Debian program. Simply type the name of the client on the command line. Try typing xterm into an existing xterm, and a new xterm client will appear on the screen.

You may notice that the original xterm is now useless, since your shell is waiting for the second xterm to finish. To avoid this problem, you can run the X client in the background --- add a & after the command name, like this: xterm &. If you forget, you can place a running process in the background. First suspend the process with C-z, and then place it in the background with the bg command.

If you use a program often, your window manager will generally provide a way to put that program on a convenient graphical menu.


10.3.3 Troubleshooting

Sometimes when you launch an X client from a graphical menu, you won't be able to see any error messages if it fails. You can find any error messages in the file ~/.xsession-errors.


10.3.4 Leaving the X environment

To leave X, you will need to use a menu. Unfortunately for beginners, this is different for every window manager, and for most window managers can be configured in many ways. If there's an obvious menu, look for an entry like "Exit" or "Close Window Manager". If you don't see a menu, try clicking each of the mouse buttons on the background of the screen. If all else fails, you can forcibly kill the X server by pressing C-A-Backspace. Forcibly killing the server will destroy any unsaved data in open applications.


10.4 Customizing your X startup

When you start X, Debian will run some shell scripts which start your window manager and other X clients. By default, a window manager, an xconsole and an xterm will be started for you.

To customize your X startup, the file /etc/X11/config must contain the line allow-user-xsession. If it does not, become root and add the line now. Then log back in as yourself and continue the tutorial. [15]

To run the clients of your choice when X starts, you create an executable shell script called .xsession in your home directory.

  1. touch ~/.xsession

    This creates the file.

  1. chmod u+x ~/.xsession

    Make the file executable.

Once .xsession is created, you need to edit it to do something useful with your favorite text editor. You can do anything you want to in this script. However, when the script's process terminates, X will also terminate.

In practical terms this means that you often end the script with a call to exec. Whatever program you exec will replace the script process with itself, so commands found after the exec line will be ignored. The program you exec will become the new "owner" of the script process, which means that X will terminate when this new program's process terminates.

Say you end your .xsession with the line: exec fvwm. This means that the fvwm window manager will be run when X starts. When you quit the fvwm window manager, your X session will end and all other clients will be shut down. You do not have to use a window manager here; you could exec xterm, in which case typing exit in that particular xterm would cause the entire X session to end.

If you want to run other clients before doing your exec, you will need to run them in the background. Otherwise .xsession will pause until each client exits, then continue to the next line. See the previous section on running jobs in the background (basically you want to put an ampersand at the end, e.g. xterm &).

You can take advantage of this behavior, though. If you want to run commands at the end of your X session, you can have your .xsession run a window manager or the like and wait for it to finish. That is, leave off the exec and the &, just put fvwm by itself. Then put the commands of your choice after fvwm.

It would probably help to look at a few sample .xsession files. In all the examples, replace fvwm with the window manager of your choice.

The simplest .xsession just runs a window manager:

     exec fvwm

This will run fvwm, and the X session will end when fvwm exits. If you do it without the exec, everything will appear to behave the same way, but behind the scenes .xsession will hang around waiting for fvwm, and .xsession will exit after fvwm does. Using exec is slightly better because fvwm replaces .xsession instead of leaving it waiting. You can use the ps or top command to verify this.

A more useful .xsession runs a few clients before starting the window manager. For example, you might want some xterms and an xclock whenever you start X. No problem:

     xterm &
     xterm &
     xclock &
     exec fvwm

Two xterms and an xclock start up in the background, and then the window manager is launched. When you quit the window manager, you'll also quit X.

You might try it without the backgrounding just to see what happens. Do this:

     xterm
     xclock
     exec fvwm

xterm will start, and wait for you to exit it. Then xclock will start; you'll have to exit xclock before fvwm will start. The commands are run in sequence, since the script waits for each one to exit.

You can use sequential execution to your advantage. Perhaps you want to keep track of when you stop working every day:

     xterm &
     xclock &
     fvwm
     date >> ~/logout-time

This will fork off an xterm and an xclock, then run fvwm and wait for it to finish. When you exit fvwm, it will move on to the last line, which appends the current date and time to the file ~/logout-time.

Finally, you can have a program other than the window manager determine when X exits:

     xclock &
     fvwm &
     exec xterm

This script will run xclock and fvwm in the background, and then replace itself with xterm. When you exit the xterm, your X session will end.

The best way to learn how to use .xsession is to try some of these things out. Again, be sure you use chmod to make it executable --- this is a common error.


[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ 14 ] [ 15 ] [ 16 ] [ 17 ] [ 18 ] [ A ] [ B ] [ C ] [ D ] [ next ]


Debian Tutorial (Obsolete Documentation)

29 Dezember 2009

Havoc Pennington hp@debian.org