Unix Linux, and X Lecture Notes - X Window System
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Introduction
~~~~~~~~~~~~
The X Window System is the standard windowing system with Unix and Linux.
It was designed for top of the range workstations - the sort that has
up to three large, very high resolution screens and one keyboard and
mouse. It was designed to be networked and is network transparent.
Client-server
~~~~~~~~~~~~~
X has a client-server architecture although it differs from the norm in
that the client runs on the most powerful machine and the server runs
on the least powerful; also, the client runs remotely and the server
runs locally. In both respects, this is the opposite of what usually
happens with client-server.
X terminology
~~~~~~~~~~~~~
An X client is simply a program which does all its screen, keyboard and
mouse handling via an X server. Programs such as `xterm', `xedit', `xman'
and `xclock' are all X clients; these and many other X clients are
distributed free with X. Since their C sources are available, they
serve as examples of how to write X programs. They range from toys
such as `xeyes', through the noddy editor `xedit', to `xterm' which is the
most useful X client as well as one of the most powerful ones in the
standard distribution.
X server - hardware or software which handles screen, keyboard and
mouse for all the X clients that are currently using a particular
display. It maintains separate pairs of input and output queues for
each of the clients currently using the server. The different clients
using the server at any one time could be running on different
computers on different continents. If the network was fast enough,
there would be nothing to indicate that the clients were not all on the
same computer as the server.
X protocol - the method used for all communication for between X
clients and X servers. Programmers do not need to know about this -
they simply use calls to functions in a C library.
X terminal - a terminal which acts as a complete X server. They plug
straight into a network and use the X protocol directly. They cost about
1000 dollars and give workstation quality graphics. Because they are
disk-less, X terminal networks are easier and cheaper to maintain than
PC networks. Many US companies use networks of X terminals where we would
use a network of PCs.
X terminal emulator - a program which makes a PC pretend to be a low
quality X terminal. Vista/Exceed is one of the most popular X
terminal emulators.
X resource - an attribute that can have its value changed to configure
just one aspect of the behaviour of an X client. For example:
XTerm*cutToBeginningOfLine: False
makes `xterm's cut from the cursor position with treble click instead of
from the very start of the line.
X resource file - a file containing many X resources. These may be
system-wide like /X11/lib/X11/app-defaults/XTerm or personal like
$HOME/.Xdefaults.
Window - a rectangular area of the screen. What the user thinks of as
a window, for instance an `xedit' window, is actually just the top-level
window for an X client and contains many smaller windows.
Window manager - an X client that handles all the resizing and moving
of the top-level windows. It is the window manager that puts the frame
around the individual windows, allowing them to be re-sized. One of
the most powerful features of X is that Window managers are just X-
clients so you can choose which one to use. Our default window manager
is the CDE window manager (dtwm). More than anything, it is the window
manager that determines the look and feel of the whole windowing
system. The old Motif window manager was the model for MS-Windows.
Unfortunately, MS forgot the lower function!
Desktop - a collection of X-clients that deal with drag and drop, menus
shortcuts and multiple work-spaces. The chosen desktop also helps
determine the look and feel. On the Sun our desktop is CDE. Linux has
a wide choice of desktops; GNOME from the Free Software Foundation's
GNU (GNU is not Unix) project is the best known.
Widget - a window gadget. An area of the screen which looks like
something such as a button or a scroll-bar. For example, the maximise
button at the end of the title-bar in the Motif window manager frames.
Gadgets have an appearance and a behaviour. Behaviour is things such
as what happens to the cursor when it moves into the area of the screen
occupied by the widget. It is possible to link a C function to the
widget so that it is called when a particular mouse button is used over
the widget. The ideas which evolved with X are now widely accessible
in Java.
Widget set - a collection of widgets. The widgets are collected in the
sense that one C library file describes the whole collection. The best
known ones are the original Athena widgets (Xaw), the Motif widgets
(Xm) and the Openlook widgets (Xol). The Athena widgets include the
`xterm' scroll-bar and the buttons in the `xman' top-box. The Motif
widgets include the ones used to frame the windows by the Motif window
manager.
Look and feel - it is the widget set and the style guide that goes with
it that give a graphical user interface (GUI) its look and feel. The
idea is that users are given the same look and feel throughout a
company, application or system.
X libraries - C functions which handle the X protocol and widgets.
Xlib is the basic one; Xt is provided to assist people who want to
write their own widget sets; each widget set comes in the form of a
library and a C header file for each individual widget.
Widget tree - the collection of widgets used by any X client is always shown
as tree because every widget is displayed in a window and windows contain
other windows. Here are two views of the tree for `xedit':
Xedit xedit
Paned paned
Paned buttons
Command quit
Command save
Command load
Text filename
Label bc_label
Text messageWindow
Label labelWindow
Text editWindow
To completely specify a particular widget, all the components must be
specified. For example, the quit button is:
Xedit.Paned.Paned.Command OR xedit.paned.buttons.quit
Xclient command line options
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can specify command line options when you start an xclient just as
you can with any Unix command. However, there tend to be many
complicated options. The following are quite small examples:
$ xterm -ls -name login_xterm -title login_xterm -n login_xterm \
> -sb -sl 2000
$ xclock -geometry 130x130-0+0 -hd 'white' &
Because the command line options tend to be unwieldy, xclients pick up
their default attributes from resource files. There is a hierarchical
arrangement of resource files from system-wide to personal with the
latter over-riding the former.
Modifying resource files
~~~~~~~~~~~~~~~~~~~~~~~~
In resource files, you specify the widget and the attribute you wish to
set. For example, this:
xedit.paned.buttons.quit.background : red
sets the background of `xedit's quit button to red. A dot is used after
each widget name. You specify the widget and the attribute you wish to
set. A question mark means any single widget and an asterisk means any
number of widgets.
You have to read the manual pages for X and for the X client to see
what resources are available.
Classes
~~~~~~~
X is object oriented (but written in C). Every widget can be referred
to by its instance name or by its class name. In X, class names begin
with a capital letter. In the above diagram showing two views of a
tree, the left tree shows class names and the right one shows instance
names. In the quit button example I have used instance names. Using
class names and instance names in resource files allows us to specify
whether a resource setting applies to all instances of a widget or just
some particular ones. For example, this:
xedit.paned.buttons.quit.background : red
affects `xedit' if the name (in the title-bar) is `xedit', whereas this:
Xedit.paned.buttons.quit.background : red
affects all `xedit's regardless of their names. Similarly, this:
Xedit.paned.buttons.Commands.background : red
sets all button backgrounds.
Advantages of X
~~~~~~~~~~~~~~~
X was written by some of the best graphics programmers in the business
yet it is free! It is the result of a co-operative effort from many
people and companies.
Absolutely everything is configurable just by editing an ASCII file!
For example, in MS-Windows you CANNOT change the way the keyboard input
is associated with a window. (You HAVE to click the left mouse button
in the window, and that ALWAYS makes the window "come to top".) In X
you can choose from about six different schemes! Even the menus are
configurable - including those for the window manager! There are many
advantages to these ASCII configuration files. For instance we can:
give them easily to other people; keep them in a source code control
system; do global edits on them or generate them automatically with
software tools. Windows NT keeps such configuration information in its
registry - an approach with none of these advantages, but with those of
secrecy and sorcery!
X is fully networked. You could have a screen in the UK displaying the
output for several clients, one client could be running on on a machine
in the US and one client could be running on a machine in NZ. You
could copy and paste data from one to the other as if they were all
local.
X works with any operating system over any network so in the above
example, the US machine could be running DEC's VMS OS and the NZ machine
could be under IBM's VM OS while the UK machine could be running SUNOS
on a Sun.
Files
~~~~~
Look at these files in your home directory to see how to configure X:
.xsession - specifies which X clients will be started when you start X.
.Xdefaults - specifies your personal settings for X resources.
.mwmrc - specifies the menus used by the `mwm' window manager.
If you want to change them, you will first have to turn your link to my
file into an editable copy of my file with my `unlink' command. It would
be wise to back them up with the `bu' command before changing them.