Introduction to the X11 Window System





                                    RUTGERS
                      The State University of New Jersey
                   Laboratory for Computer Science Research

                               7 September 1990


Copyright  (C)  1990 Charles W. McGrew.  Anyone may reproduce this document, in
whole or in part, provided that:  (1) any copy or republication of  the  entire
document  must  show  Rutgers  University  as the source, and must include this
notice; and (2) any other use of this material must reference this  manual  and
Rutgers  University,  and  the  fact  that the material is copyright by Charles
McGrew and is used by permission.








1. Introduction to X
     This  guide  will  introduce  you  to  the  X  window  system  at  Rutgers
University.    The  X window system will allow you to use the Sun workstation's
capabilities more completely.  X allows you to have a Macintosh-like  interface
to  the  workstation.  When using X, you can have several windows open at once,
each doing something different.  An example: You might  have  separate  windows
open  editing  a  program  file, compiling a file you've just finished editing,
trying to find bugs, yet another with a game of 'hack' in it (when  things  get
boring),  a  fourth  for  reading netnews, and a fifth for general utility work
(listing directories and whatnot).  In addition,  each  of  these  windows  may
actually  be  executing  programs  on  other  machines,  not just on your local
machine.  It might seem at first that this is un-useful, but in fact people can
think  about more things than one when using a computer, and it's handy to have
a computer that can facilitate you doing this.  (How many times have you sat at
two terminals at once, doing things on both?)  For a bit more "Philosophy", see
section 5.  For a look at a typical "X" session, see figure 1.

     So, here is a quick introduction to X. First, some definitions:

                                  Definitions

     X - A window system, reminscent of the Apple Macintosh's  "desktop",  that
runs  on  many workstations, including Sun's.  It is a desktop on which you can
open, resize, close, or destroy windows that you can  do  things  in.    X  was
originally  written  primarily at MIT, but since then has been added to by many
people all over the country.  [Note: this document actually describes only  one
"window  manager" of X, called "twm", for "Tab Window Manager", named after the
way the window label appears as a 'tab' on the window.  There are  others,  but
this  one  is the recommended here at Rutgers.  Before embarking on journeys of
discovery of other window managers, I recommend that you learn this one.]

     Desktop - the grey areas of the screen not taken up by windows  or  icons.
Initially almost all of the screen is 'desktop area'.  (See Figure 2.)

     Window - a terminal-like interface on the screen.  You can safely think of
                                       2


each  window  as  a  separate  terminal  session  between  yourself  and  Unix.
Typically,  each  window  runs  its  own  shell.    A  window has a label, that
describes what it is.

     Mouse - the device used to select and manipulate windows.  It must sit  on
a  mousepad  (these are optical, rather than roll-around, mice).  The place the
mouse 'points to' on the screen is shown by the mouse cursor, which appears  as
an  "X" when on the desktop (specifically at the crossing point of the "X"), as
an arrow when in a window label (specifically at the point of the  arrow),  and
as an "I"-shaped cursor when in the body of a window.  See Figures 1, 2 and 5.

     Selected  Window - the window the mouse cursor is currently in.  This will
take some getting used to, believe me.  Keyboard input can only be done to  the
selected  window.    Typing  on  the  keyboard  when the mouse cursor is in the
desktop region results in the input  going  nowhere  (i.e.  into  none  of  the
windows).

     Icon - a closed-up window is represented by an icon, a small symbol on the
screen that you can reopen to use the window.  Programs that are running in  an
open  window  will  continue  to  run  if the window is closed up into an icon.
Closing up windows reduces window 'clutter' on the screen.    You  can't  enter
data  into  an  icon-ized  window.    In  X's  "twm"  window manager, icons are
collected into the "icon manager", a connected sequence of icons.

     Menu - commands  to  manipulate  windows  are  entered  by  selecting  the
appropriate  command  on a pop-up menu.  That is, pressing and holding down the
rightmost mouse button will cause the menu to appear and then  the  appropriate
command  can  be  selected.    After moving the mouse to the menu-selection you
want, release the mouse button and it  will  be  executed.    (Pressing  -  and
holding  down  -  the  centermost  mouse  button will cause a different menu to
appear, and so will the leftmost, but  the  main  "action  menu"  is  from  the
rightmost  mouse  button.    These  other menus will be addressed later in this
document.  See the  "Desktop  Commands"  section  of  this  document  for  more
information.)

     Local  Machine: the machine you're logged into, with the big screen, mouse
and keyboard.  This distingishes the machine from:

     Remote Machine: all other machines accessible from the local  machine  via
the  network.    These  machines can run programs that will open windows on the
local machine (provided you have a valid account  on  the  remote  machine,  of
course).

     Note  that  the X window system is only for use on the a bitmapped-display
workstation (for instance Suns) directly, not on  terminals  without  bitmapped
screens.



2. Getting Started
     The procedure below should be done one time only, the first time you start
out to run X. After doing the below that one time, you merely need to type  x11
to the shell command prompt to start up X.

     You should be at least marginally familiar and proficient in Unix and some
text editor in general before you start in on this, since that  knowledge  will
be useful.

   - Edit  your  .login  (or  .cshrc,  wherever  this  stuff  is), and add
     "/usr/local/X11R4/bin" to your PATH environment  variable.    Add  it
     before     "/usr/local/bin",    if    it's    there,    and    before
                                       3


     "/usr/local/X11/bin", if it's there.

   - Add this to your .login:

     setenv MANPATH/usr/local/X11R4/lib/man:/usr/man

     ... this will give you the X11 man pages, which by default you  don't
     get.

   - Exit your editor

   - Type "source .login" (or .cshrc, whichever you edited above)

   - Type "x11"

     You  should  now see the following on the screen.  What the computer types
is shown in boldface, what you would type in  response  is  in  italics.    The
question  you  have to answer concerns the size of printing on your windows.  I
recommend "medium" sized fonts, at least at first.

First time on this display - Welcome to X.
Copying default xinitrc

Would you prefer a small (12pt), medium (14pt), or large (19 pt) font [s/m/l?]m

Copying default Xdefaults '(medium font)'

Copying default .twmrc

     ... and then the X window manager ("twm") will run, and you'll  be  inside
X.  A  clock will appear in the upper righthand corner, a small mailbox next to
it (whose flag  will  go  up  if  you  get  mail;  see  "man  xbiff"  for  more
information), and the "icon strip" in the upper lefthand corner, with "xclock",
"xbiff", and "Console".  Put the mouse cursor over the "Console" box and  click
the  rightmost  mouse  button.    The console icon will open up to a full 80x34
window, in which you can type commands.  See figure 2.

     From now on, you can enter the X window system by just typing 'x11'.

     Many other windows and such things can be invoked via "Desktop  commands",
as described below.



2.0.1 Desktop commands/Menus
     These  commands  are  available to you if you move the mouse cursor to the
grey desktop area and press the rightmost mouse button, causing the  main  menu
to appear (see Figure 3).  Holding down the right mouse button, slide the mouse
cursor down the menu.  Release the button when the mouse cursor points  to  the
command  you  want  to  select.    If the entry you want to select is a menu (a
menu-within-menu, as it were - denoted by a little box on the menu entry), hold
down  the  mouse  cursor  on the menu-entry you want, and move the mouse cursor
slowly to the right.  The new menu you want  will  appear,  and  then  you  can
'slide down' that menu to select the item you want to invoke (see Figure 4).

     Hosts/xterms  -  move  the mouse cursor to the right of the "Hosts/xterms"
section toward the little box on that line.  Another menu (what? another?) will
appear, and in that menu will be a selection of various 'xterms' ('xterm' means
"X terminal").  To open a 'local' window, i.e. a shell  running  on  the  local
machine,  select "Local 80x24 xterm" from this submenu.  For remote logins, see
"man rlogin" for information about permissions that need to be set.
                                       4


     Handy Commands - this is also a menu-within-a-menu, allowing you to select
various  handy  things, including a clock, the 'lock screen' option that allows
you to leave the terminal for a short time without people being  able  to  mess
with your files.

     Window  Ops  - this menu-within-a-menu allows you to do various things, of
which the most interesting is "Refresh Screen" -- if  your  screen  has  become
messed up in some way, this will redraw everything on it.

     Neato  Nifty  Stuff  -  this  menu  allows  you  to access portions of the
"Andrew" system, an equation editor, graphics editor,  a  macdraw-like  editor,
and several games.

     User  Perferences - this menu allows you to set various options related to
the environment, like keyclick, mouse speed, 'bell' volume, etc.

     Exit X Window Manager - Destroys all  windows  and  returns  you  to  your
normal (34x80, sadly windowless) terminal interface (i.e. you exit X).



2.0.2 Window commands
     Windows  can be closed, opened, resized, and moved to suit you.  Here is a
quick guide on how to do this.  While window operations will be a little clumsy
at  first,  familiarity comes quickly.  For several operations, you can use one
of several methods.    I  recommend  you  start  out  using  the  first  method
described, but as your familiarity grows, you may find one of the other methods
is  easier  to  use.    (The  choices  are  listed  in  descending   order   of
'recommended-ness'.)  These are not all of the "window commands" available, but
these are the important ones.  Refer to Figure 5 and especially to Figure 6 for
graphic representations of what is described below.

Open:   To open a window (change it from a closed icon to an open window), move
                the mouse cursor onto the icon for the window,  and  click  the
                leftmost  mouse  button.    The  window  will open where it was
                before.

Close: To close (iconify) a window, either:

   - Move the mouse cursor into the window label (to the "X", specifically
     ),  and  click  the leftmost mouse button.  The window will disappear
     and the icon will change from having no little "X" in  it  to  having
     one, or

   - Move the mouse anywhere in the window and press the "L7" key.

   - Move  the  mouse cursor into the window label (anywhere in the label)
     and press the leftmost mouse button, and select "Iconify".

Resize: To resize a window:

   - Move the mouse into the upper left corner of the window label  (where
     the two "elbows" are), click the rightmost mouse button, and drag the
     window to be the size and shape you want, then release the button, or

   - Hold down the "diamond" on a 3/80 or sparcstation, or the  "Left"  or
     "Right"  key  on  a 3/50 (they are to the left and right of the space
     bar, either one will do), click and hold the rightmost  mouse  button
     and  drag  the window border to where you want it to go, then let go,
     or

   - Move the mouse into the  label,  press  the  leftmost  mouse  button,
                                       5


     select  the 'resize' option from the "window ops" menu, then drag the
     window to the dimensions you want; click any mouse button when you're
     done.

Move: To move a window, either:

   - Move  the mouse into the window label, press and hold down the center
     mouse button, and drag the window to where you want, or

   - Move the mouse into any portion of the window,  press  and  hold  the
     "diamond",  "left",  or "right" key and center mouse button, hold the
     mouse button down and drag the window where your want it to go, or

   - Move the mouse into  the  window  label,  press  the  leftmost  mouse
     button,  select  the  'move'  option from the "window ops" menu, then
     drag the window to where you want; press any mouse button when you're
     done.

Bring to Top: Windows can be thought of as sheets of paper on the desktop; they
                can be stacked on top of one another.  To bring a window to the
                "top" (or "foreground"), either:

   - Move  the  mouse  into  the window label and click the leftmost mouse
     button.

   - Move the mouse into the window and press the L5 button.

   - Move the mouse to the label (not on the  "X"),  press  the  rightmost
     mouse button, and select the "Raise Window" option.

Redisplay: Windows (or the whole screen) that get messed up (Note- this doesn't
                happen often) can be redrawn with the redisplay command.  To do
                this,  move  the  mouse cursor into the window label, and press
                and hold  the  rightmost  mouse  button,  and  select  "Refresh
                Window".    The  window  will  be  redrawn.    To redisplay all
                windows, and the  desktop,  move  the  mouse  cursor  into  the
                desktop,  select the "Window Ops" menu the same way, and select
                "Refresh Screen".



3. Startup Files
     Three files are used by X to determine the 'look' of your X windows.  They
are:

   - .xinitrc  -  this  file  contains  startup  information  for X to get
     started.  This tells the window manager what applications to  run  at
     startup.

   - .Xdefaults   -   sets  defaults  for  X  applications,  for  instance
     backgrounds, whether to put scrollbars on your xterms by default.

   - .twmrc - this file sets some defaults and defines your menu 'look'.

     .Xdefaults and .twmrc both set defaults. The difference is that .Xdefaults
is  for  individual applications whereas .twmrc is for overall window structure
and appearance, and overall menus.  Samples of all the files can  be  found  in
/usr/local/X11R4/lib (as default.twmrc, default.xinitrc, etc.)  A discussion of
how to customize a setup to suit you is in the following section.
                                       6


3.1 For Different Menus
     Modifying your .twmrc file will allow you to give you the menu 'look'  you
want  from  X.  I  strongly recommend that you not embark on this customization
process until you are completely familiar with the default  behavior  (and  you
know what you want to change.) Here are some simple guidelines.

   - Your  best bet is to startup X, then edit your .twmrc.  You can cause
     X to reread your .twmrc by selecting "Restart Window Manager" in  the
     "Handy Commands" menu.

   - If  you make an error, twm will do the things in your .twmrc up until
     it finds the error, and then stop.  Twm  shouldn't  just  'die',  but
     things  after  the error will not work until you correct your .twmrc.
     You can repeatedly reload the .twmrc  (after  fixing  an  error,  for
     instance),   and  in  such  a  way  quickly  "protoype"  your  window
     interface.

   - If you have a 'direct command' in your .twmrc, don't forget to add  a
     '&'  at the end (this causes the command to be run in the background,
     which is what you want anyway).  For instance, to add  a  line  to  a
     menu to invoke 'xmille', you'd use:

        "xmille - kilometers of cards"  !"xmille&"

   - Add  the things you want before removing things.  Also, add things at
     the end of menus, so that if you make a mistake,  you'll  still  have
     enough  functionality  to  restart after fixing the mistake.  It *is*
     possible to mess things up so badly that X won't function  (the  only
     way  out  in this is to reboot the machine, or log in over the net to
     your machine,  log  yourself  out,  and  then  issue  "kbd_mode  -a".
     However, it is *very* hard to get twm to crash that badly.)

   - Menus should have the form:

     menu "Menuname"
     {
     "Menuname"    f.title
     "Menuitem-1"  f.menu "Another Menuname" (for a submenu, defined lower
     "Menuitem-2"  !"command &" (or a direct command)
     }

     ...  the  mix-and-match  of f.menu, direct commands is entirely up to
     you.

   - Until you are more familiar with the format of the .twmrc  file,  and
     what  things  mean, start with the 'main menu' section, and leave the
     default definitions above that as-is.  Most of the defaults  are  the
     'proper'  thing,  and  better  to get your menu set the way you want,
     before you embark on full-scale customization.

     You will find that the syntax of  the  .twmrc  menu  definitions  easy  to
understand and manipulate.  Certainly if you like the default settings, there's
no reason to change them; but if you want it,  you  can  get  pretty  much  any
'look' you like.



4. For Remote Execution
     By  default,  no  remote machines can open windows on your machine.  (This
includes emacs windows from remote machines,  or  shell  windows  from  "remote
shells".)  This requires:
                                       7


   - Permission  to  be granted for the local machine (i.e. the one you're
     on) to execute programs on the remote machine.

   - Permission for the remote machine's program to open a window  on  the
     local machine.



4.0.1 Remote Execution
     Remote execution may be accomplished one of two ways: either by logging in
to the remote machine (with telnet(1) or  rlogin(1)),  and  executing  commands
which  open  windows locally, or by executing a remote shell (rsh(1)).  See the
man pages for these commands for information on permissions you have to set up.



4.0.2 Opening Windows
     Permission for remote machines to open  windows  locally  is  accomplished
with  the  xauth  or  xhost  commands.   See the section on "Security" for more
information.

     To allow machines to do this, we must use the command xauth or xhost  (see
section on 'security').  This can be typed while running X, or be placed in the
.xinitrc file to be done at startup time.

     To execute a shell on a remote machine with a  local  window,  use  the  x
command, e.g.

x remus

     This  will  execute  a  shell  on  remus,  but with a window on your local
machine.

     Note that the local host must be in your .rhosts file on the remote  host.
Then entry should have your name and the local hostname, e.g.

darkstar.rutgers.edu mcgrew

     ...  so  that  you  can  execute  rsh's  ("Remote SHell") to it.  For more
information, see the 'rsh' man page.

4.1 Security
     Two mechanisms are available to make your display more secure -- that  is,
to  make it less accessible to people you don't want to be able to open windows
on your machine.  xhost controls at the level of machines,  and  xauth  at  the
level of individual users.  If an individual or system can open windows on your
display, they can also arrange to watch what your are typing.  Clever  programs
can  do  this  without giving you any visible evidence of it.  So security does
matter.



4.1.1 Xauth
     Xauth, provides security on a per-user level.  You, as the "owner" of  the
local  display  (while you are sitting at it, logged in) may give authorization
to yourself or other people on other machines to open windows on your display.

     Xauth grants this authority by the use of keeping 'magic files', which  it
examines  for  the  authorization  codes  when  trying  to open windows on your
display. [Note: the following section assumes you have already set up things so
you  can remotely execute commands on remote machines.  See rsh(1), and section
                                       8


4.0.1 of this document for more information.]

     Initialization of your xauth permissions files is handled automatically by
the  x11  command, and passing of permissions is handled automatically by the x
command.  However, if you do not wish to use x11 and/or x commands, please read
the following.

     You initialize your authorization file by typing:

xauth add `hostname`:0 . 410a

     ...  the  "410a"  can actually be any even-length hexadecimal string.  See
"man xauth" for more information.

     To give yourself, on say remus, acess to  open  a  window  on  your  local
display, you would type:

xauth extract - $DISPLAY | rsh remus xauth merge -

     ...  this  command  extracts the current display name's authorization, and
transmits it to the remote side, so that it will be able  to  open  windows  on
your display.



4.1.2 Xhost
     Xhost  gives  only very general restrictions to allow windows to be opened
on your machine from a given set of machines that you define.  Warning!    This
mechanism  of  security  is strongly discouraged here at Rutgers.  Xauth is the
recommended mechanism.

     For instance, if you have previously issued the command:

     xhost remus

     in your .xinitrc, for  instance,  or  typed  into  a  shell  window,  then
programs running on remus can open windows on your display.

     Xhost restrictions can be globalized; xhost +  allows any machine anywhere
to open a window on your display, and xhost -    disallows  all  machines  from
opening  windows  on your display (except for machines you have already by-name
allowed).

     For  individual  machines,  xhost  +hostname  (or  xhost  hostname)  gives
permission to machines, and xhost -hostname removes it.

     For instance, to add the host "remus", you can type:

xhost remus

remus being added to access control list

     To add "romulus" and "remus", type:

xhost romulus remus

romulus being added to access control list
remus being added to access control list


     To  see a list of hosts you have 'turned on', just type xhost by itself to
                                       9


a command prompt.  To add such permissions to your startup, you can add a  line
like:

     xhost remus romulus this that the other thing

     ...to your .xinitrc right after the line that starts out "xset".

     Notice  that  any individual on a machine with permission can open windows
on your display if you give permission to that machine (provided the individual
has set his/her DISPLAY variable properly).



5. Philosophy

                Philosophy I: Windows vs. 'Normal' 4.2 BSD Unix

     Berkeley  Unix  (4.2  BSD)  - like that on the Suns - will allow you to do
things very like you can with X. Using the  ^Z  (suspend  process),  'bg'  (run
process  in  the  backround), and 'fg' (continue in the foreground) commands of
csh,  one  can  get  an  effect  -  at  least  as  concerns  processes  running
concurrently  - very similar to what goes on in X. (In fact, old-fogey diehards
often scoff at X-like interfaces for this very reason.)

     The advantage of the graphical interface of X is that it allows  the  user
to  see  a  picture  of  what  is going on, rather than keeping track of it all
him/herself.




                      Philosophy II: Why X remote windows

     One may ask what value the remote executions-local display  feature  of  X
windows  is.    The  answer is that the machine that you generally run X on has
significantly less memory, slower disk, and a slower CPU  than  other  machines
that  are  available to you.  For instance, a 3/80 is much slower than a 4/380,
like remus.  Running a program on remus, but performing input and output on the
local machine maximizes the powers of both -- the 3/80 has a bitmapped display,
mouse and spiffy keyboard, while the 4/380 has speed of execution (and besides,
the 4/380 is in the machine room), and no bitmapped display or mouse.




                         Philosophy III: Programming X

     X  provides  a  number  of  toolkits to help programmers who want to write
their own X windows  applications  (that  is,  programs  that  open  their  own
windows,  rather  than  run inside xterms).  If you're interested, feel free to
prowl around  in  /usr/local/X11R4/lib/doc,  which  contains  many  informative
documents on how to do that.
                                      10


I. A Summary of X commands
     These  commands  can  be typed to a shell prompt when inside X. Each entry
has a notation; to tell you what sort of user would use such a command:

                [U] - Normal User
                [P] - Programmer (of X applications)
                [T] - Text Processing
                [F] - Fun Stuff


[P]     appres                  - list application resource database
[P]     bdftosnf                - BDF to SNF font compiler for X11
[P]     bitmap, bmtoa, atobm    - bitmap editor and converter utilities
                                  for X
[P]     constype                - print type of Sun console
[F]     ico                     - animate an icosahedron or other polyhedron
[P]     imake                   - C preprocessor interface to the make
                                  utility
[U]     kbd_mode                - recover the Sun console keyboard
[P]     listres                 - list resources in widgets
[P]     makedepend              - create dependencies in makefiles
[F]     maze                    - an automated maze program
[P]     mkfontdir               - create fonts.dir file from directory of
                                  font files.
[F]     muncher                 - draw interesting patterns in an X window
[U]     oclock                  - display time of day
[F]     plaid                   - paint some plaid-like patterns in an X
                                  window
[F]     puzzle                  - 15-puzzle game for X
[U]     resize                  - utility to set TERMCAP and terminal
                                  settings to current window size
[P]     showsnf                 - print contents of an SNF file
[U]     xauth                   - X authority file utility
[U]     xbiff                   - mailbox flag for X
[U]     xcalc                   - scientific calculator for X
[U]     xclipboard              - X clipboard client
[U]     xclock                  - analog / digital clock for X
[P]     xcutsel                 - interchange between cut buffer and
                                  selection
[T]     xditview                - display ditroff DVI files
[P]     xdm                     - X Display Manager
[U]     xdpr                    - dump an X window directly to a printer
[P]     xdpyinfo                - display information utility for X
[T]     xedit                   - simple text editor for X
[P]     xev                     - print contents of X events
[F]     xeyes                   - watch over your shoulder
[P]     xfd                     - font displayer for X
[F]     xgc                     - X graphics demo
[U]     xhost                   - server access control program for X
[U]     xinit                   - X Window System initializer
[P]     xkill                   - kill a client by its X resource
[U]     xload                   - load average display for X
[F]     xlogo                   - X Window System logo
[P]     xlsatoms                - list interned atoms defined on server
[P]     xlsclients              - list client applications running on a
                                  display
[P]     xlsfonts                - server font list displayer for X
[P]     xlswins                 - server window list displayer for X
[U]     xmag                    - magnify parts of the screen
[U]     xman                    - Manual page display program for
                                  the X Window System.
                                      11


[U]     xmh                     - X interface to the MH message handling
                                  system
[P]     xmodmap                 - utility for modifying keymaps in X
[U]     xpr                     - print an X window dump
[T]     xps                     - utility for previewing postscript files
                                  in an X window.  Invoke with
                                  "xps -c A4 filename".
                                  'next page' by hitting return in the
                                  invoking window.
[P]     xprop                   - property displayer for X
[P]     xrdb                    - X server resource database utility
[U]     xrefresh                - refresh all or part of an X screen
[U]     xset                    - user preference utility for X
[U]     xsetroot                - root window parameter setting utility
                                  for X
[P]     xstdcmap                - X standard colormap utility
[U]     xterm                   - terminal emulator for X
[U]     xwd                     - dump an image of an X window
[P]     xwininfo                - window information utility for X
[U]     xwud                    - image displayer for X
                                       i


                               Table of Contents

1. Introduction to X                                                          1

2. Getting Started                                                            2

       2.0.1 Desktop commands/Menus                                           3
       2.0.2 Window commands                                                  4

3. Startup Files                                                              5

   3.1 For Different Menus                                                    6

4. For Remote Execution                                                       6

       4.0.1 Remote Execution                                                 7
       4.0.2 Opening Windows                                                  7
   4.1 Security                                                               7
       4.1.1 Xauth                                                            7
       4.1.2 Xhost                                                            8

5. Philosophy                                                                 9

I. A Summary of X commands                                                   10