\chapter{The X Window System}\label{x-chapter}

\begin{quote}
Any good quotes about X11?
\end{quote}

\bindex{X Window System}

\blackdiamond This chapter only applies to those using the X Window
System.  If you encounter a screen with multiply windows, colors, or a
cursor that is only movable with your mouse, you are using X11. (If
you are interested in using X11, but are not by default, see
Section~\ref{x-start-stop-section}.)

\section{What is The X Window System?}

The X Window System is a distributed, graphical method of working
developed primarily at the Massachusetts Institute of
Technology\index{Massachusetts Institute of Technology}. It has since
been passed to a consortium of vendors (aptly named ``The X
Consortium'') and is being maintained by them.

The X Window System (hereafter abbreviated as ``X''\footnote{There
  are several acceptable ways to refer to The X Window System,
  although ``X Windows'' is {\em not\/} one of them.}) has new versions
every few years, called releases. As of this writing, the latest
revision is X11R6, or release six. The eleven in X11 is officially the
version number.

There are two terms when dealing with X that you should be familiar.
The {\bf client}\glossary{client} is a X program. For instance, {\tt
  xterm} is the client that displays your shell when you log on.  The
{\bf server}\glossary{server} is a program that provides services to
the client program. For instance, the server draws the window for {\tt
  xterm} and communicates with the user.

Since the client and the server are two seperate programs, it is
possible to run the client and the server {\em on two physically
  seperate machines\/}.  This is the real beauty of X. In addition
to supplying a standard method of doing graphics, you can run a
program on a remote machine (across the country, if you like!) and
have it display on the workstation right in front of you.

A third term you should be familiar with is the {\bf window
  manager}\glossary{window manager}. The window manager is a special
client that tells the server where to position various windows and
provides a way for the user to move these windows around. The server,
by itself, does nothing for the user. It is merely there to provide a
buffer between the user and the client.

\section{What's This on my Screen?}

When you first start X, several programs are started. First, the
server is started. Then, several clients are usually
started. Unfortunately, this is not standardized across various
distributions. It is likely that among these clients are a window
manager, either {\tt fvwm} or {\tt twm}, a prompt, {\tt xterm}, and a
clock, {\tt xclock}.

\subsection{XClock}

I'll explain the simpliest one first: {\tt xclock}\ttindex{xclock}
functions exactly as you'd expect it would.  It ticks off the seconds,
minutes and hours in a small window.

No amounts of clicking or typing in {\tt xclock}'s window will affect
it---that's {\em all\/} it does. Or is it? In fact, there are various
different options you can give to the program to have it act in
different ways. For instance, {\tt xclock -digital} will create a
digital clock. {\tt xclock -update 1} will create a second hand that
moves every second, while {\tt -update 5} will create a second hand
that moves every 5 seconds.

For more information on {\tt xclock}'s options, consult its
manpage---{\tt man xclock}. If you're going to try running a few of
your own {\tt xclock}s, you should probably read
Section~\ref{section-multitasking}.

\subsection{XTerm} % better section name?

The window with a prompt in it (something that probably looks like:
{\tt /home/larry\#} or some such, is being controlled by a program
called {\tt xterm}\impttindex{xterm}.  {\tt xterm} is a deceptively
complicated program.  At first glance, it doesn't seem to do much, but
it actually has to do a lot of work.  {\tt xterm} emulates a terminal
so that regular text-mode \unix\ applications work correctly.

For much of this book, we're going to be learning about the \unix\ 
command-line, and you'll find that inside your {\tt xterm} window.
In order to type into {\tt xterm}, you {\em usually\/} have to move
your mouse cursor (possibly shaped like an ``X'' or an arrow) into the
{\tt xterm} window.  However, this behavoir is dependant on the window
manager.

\section{Window Managers}

On \linux, there are two different window managers that are commonly
used.  One of them, called {\tt twm}\ttindex{twm} is short for ``Tab
Window Manager''. % this is from the manpage. is it correct?
It is larger than the other window manager usually used, {\tt fvwm}.
({\tt fvwm} stands for ``F(?) Virtual Window Manager''---the author
neglected to tie down exactly what the f stood for.)  Both {\tt twm}
and {\tt fvwm} are highly configurable, which means I can't tell you
exactly what keys do what in your particular setup.

To learn about {\tt twm}'s configuration, look at
Section~\ref{twm-config-section}. {\tt fvwm}'s configuration is
covered in Section~\ref{fvwm-config-section}.

\subsection{When New Windows are Created}

There are three possible things a window manager will do when a new
window is created.  It is possible to configure a window manager so
that an outline of the new window is shown, and you are allowed to
position it on your screen. That is called ``manual placement''.

It is also possible that the window manager will place the new window
somewhere on the screen by itself.  This is known as ``random
placement''.

Finally, sometimes an application will ask for a specific spot on the
screen, or the window manager will be configured to display certain
applications on the same place of the screen all the time. (For
instance, I could specify that I want {\tt xclock} to always appear in
the upper right hand corner of the screen.)

\subsection{Focus}

The window manager controls some important things. The first thing
you'll be interested in is ``focus''.  The focus of the server is
which window will get what you type into the keyboard. Usually in X
the focus is determined by the position of the mouse cursor.  If the
mouse cursor is in one {\tt xterm}'s window\footnote{You can have more
  then one copy of {\tt xterm} running at the same time!}, that {\tt
  xterm} will get your keypresses. Note that this is different from
many other windowing systems, such as Microsoft Windows, OS/2, or the
Macintosh where you must click the mouse in a window before that
window gets focus.  Also, usually under X, if your mouse cursor
wanders from that window, focus will be lost and you'll no longer be
able to type there.

Note, however, that it is possible to configure both {\tt
  twm}\ttindex{twm} and {\tt fvwm}\ttindex{fvwm} so that you must
click on or in a window to gain focus, and click somewhere else to
lose it. Either discover how your window manager is configured by
trial and error, or consult local documentation.

\subsection{Moving Windows}

Another very configurable thing in X is how to move windows around.
In my personal configuration of {\tt twm}, there are three different
ways of moving windows around.  The most obvious method is to move the
mouse cursor onto the {\bf title bar}\glossary{title bar} and drag the
window around the screen. Unfortunately, this may be done with any of
the left, right, or middle buttons\footnote{Many PCs have only two
  button mice. If this is the case for you, you should be able to
  emulate a middle button by using the left and right buttons
  simultaneously.}. (To drag, move the cursor above the title bar, and
hold down on the buttons {\em while\/} moving the mouse.)

Another way of moving windows may be holding down a key while dragging
the mouse. For instance, in {\em my\/} configuration, if I hold down
the \key{Alt} key, move the cursor above a window, I can drag the
window around.

Again, you may be able to understand how the window manager is
configured by trial and error, or by seeing local
documentation. Additionally, if you want to try to interpret the
window manager's configuration file, see
Section~\ref{twm-config-section} for {\tt twm}\ttindex{twm} or
Section~\ref{fvwm-config-section} for {\tt fvwm}\ttindex{fvwm}.

\subsection{Depth}

Since windows are allowed to overlap in X, there is a concept of {\bf
  depth}.  Even though the windows and the screen are both two
dimensional, one window can be in front of another, partially or
completely obscuring the rear window.

There are several operations that deal with depth:
\begin{itemize}
\item {\bf Raising} the window, or bringing a window to the front.
  This is usually accomplished by clicking on a window's title bar
  with one of the buttons.  Depending on how the window manager is
  configured, it could be any one of the buttons. (It is also possible
  that more then one button will do the job.)

\item {\bf Lowering} the window, or pushing the window to the back.
  This can generally be accomplished by a different click in the title
  bar. It is also possible to configure some window managers so that
  one click will bring the window foward if there is anything over it,
  while that same click will lower it when it is in the front.

\item {\bf Cycling} through windows is another operation many window
  managers allow. This brings each window to the front in an orderly
  cycle.  
\end{itemize}

\subsection{Iconization and Maximization}

There are several other operations that can obscure windows or hide
them completely. First is the idea of ``iconization''. Depending on
the window manager, this can be done in many different ways. In {\tt
  twm}, many people configure an {\bf icon manager}\index{icon
  manager}. This is a special window that contains a list of all the
other windows on the screen.  If you click on a name (depending on the
setup, it could be with any of the buttons!) the window
disappears---it is iconified.  The window is still active, but you
can't see it.  Another click in the icon manager restores the window
to the screen.

This is quite useful.  For instance, you could have remote {\tt
  xterm}s to many different computers that you occansionally use.
However, since you rarely use all of them at a given time, you can
keep most of the {\tt xterm} windows iconified while you work with a
small subset. The only problem with this is it becomes easy to
``lose'' windows. It is also easy to create new windows that duplicate
the functionality of iconified windows, since you forgot about the
iconified windows.

Other window managers might create actual icons across the bottom of
the screen, or might just leave icons littering across the root
window.\glossary{root window}

Another operation most window managers support is maximization.  In
{\tt twm}, for instance, you can maximize the height, the width, or
both dimensions of a window. This is called ``zooming'' in {\tt twm}'s
language although I prefer maximization since different applications
respond differently to changes in their window size. (For instance,
{\tt xterm} won't make the font bigger, it will give you a larger
workspace!)

Unfortunately, it is extremely non-standard on how to maximize windows.

\subsection{Menus}

Another purpose for window managers is for them to provide menus for
the user to quickly accomplish tasks that are done over and over.  For
instance, I might make a menu choice that automatically launches
Emacs, a powerful text editor, or an additional {\tt xterm} for
me. That way I don't need to type in an {\tt xterm}---an especially
good thing if there aren't any running {\tt xterm}s!

In general, different menus can be accessed by clicking on the root
window, which is an immovable window behind all the other ones. By
default, it is colored gray, but could look like anything. (There are
programs that put fish in the background for you.) To try to see a
menu, click and hold down a button on the desktop. A menu should pop
up. To make a selection, move (without releasing the mouse button) the
cursor over one of the items any then release the mouse button.

\section{Starting and Stopping the X Window System}\label{x-start-stop-section}

\subsection{Starting X}

Even if X doesn't start automatically when you login, it is possible
to start it from the regular text-mode shell prompt.  There are two
possible commands that will start X, either {\tt
  startx}\impttindex{startx} or {\tt xinit}\impttindex{xinit}. Try
{\tt startx} first. If the shell complains that no such command is
found, try using {\tt xinit} and see if X starts. If neither command
works, you may not have X installed on your system---consult local
documentation for your distribution.

\subsection{Exiting X}

One important menu entry should be ``Exit Window Manager'' or ``Exit X'' or
some like entry.  Try to find that entry (remember, there could be
more than one menu---try different mouse buttons!) and choose it. If X
was automatically started when you logged in, this should log you
out. Simply login again to return. If you started X manually, this
should return you to the text mode prompt.

\section{X Programs}

There are many programs that take advantage of X. Some programs, like
{\tt emacs}\ttindex{emacs}, can be run either as a text-mode program
{\em or\/} as a program that creates its own X window. However, most X
programs can only be run under X.

\subsection{Geometry}

There are a few things common to all programs running under X.  In X, the
concept of {\bf geometry} is where and how large a window is. 

\subsection{Standard Options}

\eindex{X Window System}
% Local Variables: 
% mode: latex
% TeX-master: "guide"
% End: 
