paint-brush
The X Window Systemby@goerzenandothman
132 reads

The X Window System

by Goerzen & OthmanOctober 30th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

9. 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. 9.1 Introduction to X A GUI (Graphical User Interface) is part and parcel of the Windows and Mac operating systems. It’s basically impossible to write an application for those systems that does not use the GUI, and the systems can’t be used effectively from the command line. GNU/Linux is more modular, that is, it’s made up of many small, independent components that can be used or not according to one’s needs and preferences. One of these components is the X Window system, or simply X. This component is also sometimes called X11. Please note that “X Windows” is not correct. 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 that 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 that 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 title bars 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, twm, and enlightenment. You’ll probably want to try them all and pick your favorite. 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, and there are many of them available. The GNOME desktop project is developing an icon-based file manager and other GUI facilities. See the GNOME homepage[1] for the latest news on this. [1] http://www.gnome.org/ 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.
featured image - The X Window System
Goerzen & Othman HackerNoon profile picture

Debian GNU/Linux: Guide to Installation and Usage by John Goerzen and Ossama Othman is part of the HackerNoon Books Series. You can jump to any chapter in this book here. The X Window System

9. 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.

9.1 Introduction to X

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


This component is also sometimes called X11. Please note that “X Windows” is not correct.


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 that 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 that 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 title bars 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, twm, and enlightenment. You’ll probably want to try them all and pick your favorite.


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, and there are many of them available. The GNOME desktop project is developing an icon-based file manager and other GUI facilities. See the GNOME homepage[1] for the latest news on this.


[1] http://www.gnome.org/


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.

9.2 Starting the X Environment

There are two ways to start 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 book using xterm; the only difference between an xterm and the text console is that you don’t have to log on to the xterm because 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 window 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.


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


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


9.3 Basic X Operations

There are certain commonly used operations in X that you should familiarize yourself with. This section describes some of the basic operations that you may find useful.

9.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 has only two, you can simulate the middle button by clicking both buttons simultaneously. This is kind of tricky and annoying, so investing in a $15 three-button mouse probably isn’t a bad idea. These are available from most computer retailers.


The buttons are numbered from left to right assuming you have a right-handed mouse. So button one is on the left, two is in the middle, and three is 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 e-mail containing an URL, you can select the URL with the left button and then click in your web browser’s “Location” field with the middle button to paste it in.

9.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 window, and a new xterm client will appear on the screen.


You may notice that the original xterm is now useless, because your shell is waiting for the second xterm to finish. To avoid this problem, you can run the X client in the backgroundby adding 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 CTRL-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.

9.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.

9.3.4 Leaving the X Environment

To leave X, you need to use a menu. Unfortunately for beginners, this is different for every window manager, and for most window managers, it 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 CTRL-ALT-Backspace. Forcibly killing the server destroys any unsaved data in open applications.

9.4 Customizing Your X Startup

When you start X, Debian runs some shell scripts that start your window manager and other X clients. By default, a window manager, an xconsole, and an xterm are started for you.


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


You can see how Debian’s X startup works in the file /etc/X11/ Xsession. Note that you can change the behavior of /etc/X11/Xsession by modifying the file /etc/X11/config, which specifies a few system-wide preferences.


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


$ touch ~/.xsession


This creates the file.


$ chmod u+x ~/.xsession


This makes 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 also terminates.


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 you use exec, you will need to run them in the background. Otherwise .xsession will pause until each client exits and 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, as in 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 enter 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; just enter 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. Enter this command: 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 and 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; failure to do so is a common error.




About HackerNoon Book Series: We bring you the most important technical, scientific, and insightful public domain books.


This book is part of the public domain. John Goerzen and Ossama Othman (2004). Debian GNU/Linux : Guide to Installation and Usage. Urbana, Illinois: Project Gutenberg. Retrieved https://www.gutenberg.org/cache/epub/6527/pg6527-images.html


This eBook is for the use of anyone anywhere at no cost and with almost no restrictions whatsoever. You may copy it, give it away or re-use it under the terms of the Project Gutenberg License included with this eBook or online at www.gutenberg.org, located at https://www.gutenberg.org/policy/license.html.