%% LyX 1.1 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\setlength\parskip{\medskipamount}
\setlength\parindent{0pt}

\makeatletter


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\providecommand{\LyX}{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\setlength\parskip{\medskipamount}
\setlength\parindent{0pt}
\IfFileExists{url.sty}{\usepackage{url}}
                      {\newcommand{\url}{\texttt}}

\makeatletter


\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\topmargin}{0.0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textwidth}{6.5in}
\setlength{\textheight}{9.8in}
\setlength{\parindent}{0in}
\setlength{\parskip}{2mm}

\usepackage{times}    

\makeatother


\makeatother

\begin{document}

\title{Using X11 Windows}


\author{Norman Matloff \\
 Department of Computer Science \\
 University of California at Davis}


\date{January 6, 2001}

\maketitle
\tableofcontents{}


\section{Introduction}

The X11 windows system allows you to, in effect, use several terminals at once.
Each one is called a \textbf{window}. Each of these terminal-like windows, called
\textbf{xterm} windows (or variations of such, such as \textbf{dterm}) because
they are invoked by the \textbf{xterm} program, has its own invocation of the
Unix shell, and thus they work independently. So, you might be editing a file
in one window, using \textbf{talk} in another, and so on.

For some non-\textbf{xterm} X11 windows applications, a program will create
several windows which work in concert.

You will want to use X11 windows whenever possible. It will make your work faster
and more pleasant, and give you extremely valuable experience, since most programs
written today do have some kind of windows interface (X11-windows on Unix, Microsoft
Windows on PCs, etc.).


\section{Window Managers}

An X11 \textbf{window manager} controls the manipulation of windows, such as
moving and resizing windows, autoraising policies (see below) and so on, and
also provides \textbf{icons}, which are {}``buttons{}'' which the user can
click to start execution of programs etc.

Which window manager you use is a matter of personal taste. If the machine you
use has been set up by someone else, it probably already has a default window
manager in place, but you can run some other one if you wish. Common examples
of window managers are \textbf{fvwm}, \textbf{fvwm2}, \textbf{icewm}, \textbf{Enlightenment},
\textbf{kwm} (a manager integrated with the KDE desktop environment) and many,
many others. They are have eye-catching user interfaces, program buttons and
so on, and tend to appeal to people who are used to the Microsoft or Macintosh
window systems. There is a central Web page listing of most known window managers,
at \url{http://www.PLiG.org/xwinman/}

Many examples in this tutorial are for \textbf{fvwm}, but the tutorial is intended
to be general, and thus usable for those using other window managers as well.


\section{Starting a Window Manager}

The basic way to start a window manager is through the \textbf{xinit} command.
However, you may or may not use it directly. Instead, you may use \textbf{startx},
which is actually a wrapper for \textbf{xinit}, or you may not directly use
any command--your machine may be set up so that it starts the window manager
automatically upon bootup or login, which may be the case ifyou are running
a desktop environment such as GNOME or KDE.


\section{Startup Files}

Analogous to .cshrc for \textbf{csh}, .exrc for \textbf{vi}, .emacs for \textbf{emacs},
etc., various X11 windows programs have \textbf{startup files}. For example,
\textbf{xinit} typically executes \textasciitilde{}/.xinitrc, and the \textbf{fvwm}
window manager uses \textasciitilde{}/.fvwmrc as its startup file. Startup files
are usually in your home directory; you will have to check the \textbf{man}
pages for details.

Among other things, a startup file configures the layout of your screen, that
is which windows you want to have, and where you want them to be placed. For
instance, the entry

\begin{verbatim}
xterm -geometry 80x45+410+185 -fn 9x15bold &
\end{verbatim}

in a startup file such as .xinitrc will set up an \textbf{xterm} window of 80
rows and 45 columns, at the X and Y coordinates 410 and 185, respectively (the
upper-left corner of the screen is (0,0)), using `9x15bold' fonts.

A line

\begin{verbatim}
xrdb -merge .Xenv
\end{verbatim}

in .xinitrc would tell \textbf{xinit} to read in from the file .Xenv some settings
of various X-windows variables, and add them ({}``merge{}'') to its current
list of settings. For instance, the line

\begin{verbatim}
xterm*scrollBar:   on
\end{verbatim}

in .Xenv sets the variable xterm{*}scrollBar to the value `on' (the other possible
value is `off'), so that mouse-window-scrolling is enabled.

Windows managers tend to have myriad options, thus complex startup files. If
you are new to a window manager, it is easiest to copy the sample startup file
which typically comes with the window manager, such as the file /etc/X11/fvwm/system.fvwmrc
in the Red Hat Linux distribution, to your own startup file (~/.fvwmrc in the
case of \textbf{fvwm}), and then use your favorite text editor to customize
it to your liking. If you are using a desktop environment such as GNOME or KDE,
there will be a desktop tool which makes life easier in this regard; you just
use the tool to configure your window manager settings to your liking, instead
of editing the startup file yourself.


\section{Manipulating Windows}

Here are various actions which you can perform.


\subsection{Typing in a Window}

To type in any window, you first move the mouse to that window. This may or
may not be enough, though, depending on the \textbf{focus} setting you currently
have for the window manager. With a setting generally called something like
\textbf{click-to-focus}, you must first click the mouse within the window in
order to type there; if the setting is something like \textbf{focus-follows-mouse},
then you can begin typing in the window without a mouse click.

Depending on the window manager you are using, you may have to click the left
mouse button in the window before you can type there.


\subsection{Raising a Window}

The \textbf{autoraise} capability for windows is very important. What this capability
does, if you have set it, is to {}``raise{}'' a window, i.e. expose it completely
and have it ready for typing within that window. All X11 window managers allow
you to set autoraise. (By contrast, Microsoft Windows does not allow this, a
source of constant annoyance to me when I use that OS.)


\subsection{Focus/Autoraise Settings Recommendations}

I strongly recommend that you configure your window manager for focus-follows-mouse
and autoraise.


\subsection{Copy-and Paste Operations}

To copy text from one window to another, or from one point in a given window
to another point in the same window: Click the left mouse button on the first
character of the copy region, and then drag the mouse pointer to the last character,
which will result in a region being highlighted on the screen. (In some application
programs, you may also need to hold down the left Shift key.) Then insert the
text at your desired target point by clicking the middle mouse button at that
point: it will be inserted at the pointer of the window where the mouse points
at the time you click the middle button.


\subsection{Moving a Window}

An existing window can be moved to various locations in the screen. The way
to do it will depend on your window manager.

Most window managers allow you to move a window by applying the left mouse button
on the top border of the window, and then dragging to the desired spot. An important
exception to this is if the top border of the window is already at the top of
the screen, and you want to move the window further up, off the top of the screen.
This situation arises if you have a window which is vertically bigger than your
screen; this is an especially common situation if you have a small screen, e.g.
on a laptop. Here you need to see the bottom portion of the window, which is
currently hidden, so you need to move the window upward.

So, what should you do if you cannot move the window upward in this situation?
Most window managers allow you to drag the window using the left or right border.
For instance, if you are using KDE (or more precisely, you are using \textbf{kwm},
the window manager typically set up on KDE systems), then hold down the Alt
key and use the left mouse button on a left or right border to drag the window
wherever you want, in this case upward. If you are using \textbf{sawfish,} the
window manager usually used with GNOME, then use the middle mouse button, not
pressing Alt, to drag the window by its left or right border. (If you have a
2-button mouse but have 3-button emulation set, then simultaneously press both
buttons.) Still another manager, \textbf{icewm}, is similar to \textbf{sawfish},
except that the right mouse button is used.

Some window managers, e.g. \textbf{fvwm}, handle the problem of too-large windows
by using the idea of \textbf{virtual desktops}. This means that you can actually
move the mouse pointer off the screen. You just hold the mouse near the edge
that you want to move off of.


\subsection{Resizing a Window}

You can change the vertical and horizontal dimensions of a window by using the
mouse. Again, the exact method for doing this depends on which window manager
you are using. You can check the documentation, or better yet, just experiment
with various mouse buttons.


\subsection{What to Do About Cluttered Screens}

If you find your screen too cluttered at some time, you can temporarily \textbf{iconify}
some windows, i.e. reduce them to \textbf{icons}, tiny squares or other symbols
(including no symbol at all). The method you use to do this will depend on your
window manager, so again you will need to check its documentation.

In \textbf{fvwm}, for instance, one can click the left mouse on the little down-arrow
symbol at the top of a window. The window will disappear from the screen; when
you wish it to re-appear, click on the right mouse button anywhere in the background
of the screen; a little window listing all windows will appear, with iconified
ones in parentheses. Click on the appropriate entry to make the window re-appear.

Many window managers will keep a set of buttons for your various windows at
the bottom of the screen, as a Windows-style {}``task bar.{}'' You can click
on these to make an iconified window re-appear.

The \textbf{fvwm} window manager allows your {}``virtual screen{}'' to be
larger than your physical screen. So, you can temporarily move a window out
of the way, by using the mouse to drag the window off the edge of the screen,
into the portion of the virtual screen not currently shown on the physical screen.
(Note, by the way, that if you have your mouse pointer very close to the edge
of your screen, \textbf{fvwm} will then move to the previously-invisible portion
of the virtual screen. If that happens and you wish to return to the main portion
of the screen, move the mouse pointer to the edge.)


\section{Quitting X}

Amazingly, there is no graceful way to quit X11 windows; instead, you have to
kill whatever process invoked it. (And error messages will appear, which you
can ignore.)The easiest way to do this on Linux is to hit Ctrl-Alt-Backspace,
which will return you to the console.  If you are using a university
system, this may be disabled, in which case the desktop manager itself
will provide a "Logout" mechanism.  For KDE, for example, click on the
K/gear symbol in the left-corner of the toolbar.


\section{Running X-windows {}``Remotely{}''}

Suppose you are at the console of Machine A, and have X11 windows running there,
and in one of those windows you use \textbf{rlogin} or \textbf{telnet} to log
in to Machine B. Suppose you then wish to run some X11 windows application on
Machine B. We say that your X11 \textbf{server} is at Machine A, and you wish
to run an X11 \textbf{client} at Machine B. You must take the following steps:

On Machine B, type

\begin{verbatim}
setenv DISPLAY ANetworkAddress:0
\end{verbatim}

which tells the X11 windows application on Machine B that the window it will
use for input/output is on Machine A.

(If your Machine A is your own PC running Linux and you have a dialup connection
to the Internet, you can try to find ANetworkAddress by typing the command

\begin{verbatim}
echo $REMOTEHOST
\end{verbatim}

at Machine B.)

Then on Machine A, type

\begin{verbatim}
xhost BNetworkAddress
\end{verbatim}

which tells Machine A that it is OK for Machine B to communicate with your X11
windows system at Machine A. You are now ready to run the X11 windows application
on B, while using the window at A.

Suppose for instance I am physically at my office machine, heather.cs.ucdavis.edu,
and I wish to run an X11 application on toto.berkeley.edu. I have logged in
to the latter from the former via \textbf{telnet}. Then ANetworkAddress would
be heather.cs.ucdavis.edu and BNetworkAddress would be toto.berkeley.edu. (Numerical
IP addresses are fine too.)

Note, however, that if the X11 application uses special fonts, these need to
be physically present at A. If A doesn't have them, you must first copy them
(if they are legally copyable) from B to A, in some directory, and then use
the `fp+' option of the \textbf{xset} command to add this directory to X11's
font search path.


\section{Printing a Hard Copy of a Window}

You can also do window dumps, including of portions of a window, using \textbf{xgrabsc}.
(This is a free program; do a Web search to obtain it.) Some window managers
even have built-in screendump programs which can be invoked by clicking on the
top window bar. 
\end{document}
