You are on page 1of 14

Chapter 1

Your Workstation and X

From Apple Macintoshes and 80x86 PCs at the low end to Sun, Hewlett-
Packard, IBM, and DEC workstations at the nigh end, graphics work-
station~ have changed the way people interact with computers. Built-in'
graphics capabilities have made graphical user interfaces such as the
Macintosh User Interface and Microsoft Windows possible. With these
interfaces, instead of entering commands from the keyboard, you can use
the mouse pointing device to run programs and to edit, copy, and delete
files. Additionally a hical interfaces divide the h sical dis la screen
If this ,summary description of X is too terse for you, don't despair-there is much more to come.
This book is designed to help 'You become familiar with X, see how typical X applications work,
and learn how to write your own X applications using the C routines in Xlib and other libraries
such as Xt and Motif. This chapter introduces you, the prospective X programmer, to the X Win-
dow System and gives an overview of its capabilities and benefits. Chapter 2, "Clients, Servers, and
Window Managers," shows how to set up and use X on a workstation and how to run X applica-
ti-ons;it also explains the terminology used to describe the X Window System. Chapter 3, "Explor-
ing X Applications," walks you through a number of common X applications to gr\1eYou a feel for
the windowing· system and prepare you to learn how to create similar applications. The final chap-

ter in Part One, Chapter 4, "Graphical User Interfaces and X," describes Motif and OPEN LOOK-
two graphical user interfaces built on top ofXlib, the C-callable library of routines that represent
,heb~i, "p,bili,~
Graphics displ~ys have two distinct (X)mponents:
• Video monitor, the terminal where the output appears 'What Is X? ~ "r\~iCl'fic
• Video controller, the circuitry that causes the output to appear by sending the" x is a combinatio ~eral
0 thin s' ·he X ,rQ~01 X dis 1£ eITeJ:Xclients and Xlib..Joutim~s
appropriate signals to the monitor ' , lications.=thauusethe workstation!.s-dis la ~t's start by taking a 100 at the overaIl
In a bitmapped graphics display) the monitor displays an array of dots (known as pixels),
and the appearance of each pixel corresponds to the c09tents of a memory location in the
video (X)ntroller. For a black-and-white display in which each pixel is either bright or dim1
a single bit of memory can store the' state of a pixel. The term ~tJ refers to this
(X)rrespondence of each bit in memory to a pixel ~n the .screen:
RAster graphics is another (X)mmon name for bitmapped graphics 'because the graphics
display appearing on the monitor is (X)nsiructedfrom a large num~ of horizontal lines
known as raster lines. Raster lines are generated in the monitor by an electron beam
sweeping back and forth on a phosphor-coated screen. Because each dot of phosphor,
(X)uesponding to a pixel, glows in proportion to the intensity of the beam, each line of the
~e can be ge~erated by (X)ntrolling the inte~ity of the beam as it scans ~ the
screen. By drawmg the raster tines repeatedly, tHe illusion of a steady image IS created.
Figure 1.1.
A workstation with the X
Window Systnn.

Window 1
is a login
Figure 1.2.
for this The client-server model
Server sends
replies to clients.
when needed.
Graphics I--·~-'-
Computer that 1
supports X I
o 0 1
1--1 I

disk, tape)

In contrast with file and database servers-which usually are processes executing in remote ma-
chines-the X disRlay server is a process executing in your workstation.with dients that may be
nning in-remote computers.
In most operating systems, the word process refers to an executing program in memory and
its asso~iated environment. eImt.Qnment.Jls IX it1cludes the input and outj?ut files ~
belongmg to the program 'and a collection of variab es known as environment variables.
You cr~ate a process when you run a program .. he command interpreter of the operating
system (called the shellin UNIX) is also a process--one that creates processes at your

Clients and Servers )< kYA..t1J
Behind the scene in the scenario shown in Figure 1.1 is eX dis fa server Lor X Server for short),
~('t r")Li!~~' ) I:..c..._-..,-;--

runnin in our workstation listenin to the network connectlon at a specific port, and actmg on ---- "j

comm n en t e c ients (a p icacions that-use the workstation s ISP . at the X servefh~applica-

~ ity, owever, most X aImlicatioJls us
This arrangement, shown in Figure 1.2, is known as the client-server model. 'the server provicfe~a
service that the clients reqllest Usuall)', the diems-communicate with the server rou h a network,.
-== ---
Figure 1.3.
n' dows Each scroll bar window; in rum, has three children: two arrow windows and
twO scra llbar WI

A simplified view of . . ... . . .
the X server. a thumbwheel window. This results In a tree-Itke hierarch of willdows for the text edItor (Figure 1.6).

Figure 1.4.
The text editor window
and its components.


User \
Graphics workstation running X display server

Consider the sample X I'·' h . F' 4 h' .

_~ ~~p Icatlon s own In Igure 1. . T IS text editor has a text entry area and
two scrollbars for examining text that may not be visible in the window. Even at this basic level
there are ~o windows on the screen: the root window, which occu ies the whole display screen' Horizontal
and the edltor window who h" 'd . dO" . ' scroll bar
, 1C ISInSI e t e root Win ow. n c oser examination, the editor window
turns out to e a frame tnat ~olCis tliree ot er wlnaows: the document window where the text ap-
p~ars and the two sc~ollbarwmdows. Funher, as shown in Figure 1.5, each scrollbar window con- Event Delivery
tains three smaller Windows: the thumbwheel in the middle and two arrows at the ends.

~ran ement ~wj dowsj a arent-child,bierarchy ~t!J,e norm io "X....6e:ure 1.4 shows the edito
WI h Th··.· ~ r
n ow as a c lot e root. e edItor Win ow as tree c I ren: the document window and
Figure 1.5.
Components a/the
serollbar window.

Up-Down thumbwheel

Toolkits: T
Chapter One: Your Workstation and X

. . gTCPI
BSD UNIX) systems, X communicates USIn .
mple, in Berkeley UNIX (als~ ~o~~MS machines, the X protocol bytes are sent USIng

For exa .. al E 'pment Corporation s
I Digit qUI ,
IP. n CNET networking protocol. l'
the DE -;.~
Ft\ " ,-
Figure 1.7.
The general ~trUc:ure fik) ...-1'''1 ')
X Protocol, Xlib, or Toolkit?
'f~ ~. I, {'l

'> ~C>D3~~ k.

(~t 1

Figure 1.7 shows the general structure of an X application. The application primarily calls routines
" toolkit may call routines from the Xt Intrinsics, which, in turn, call Xlib. The
from a toolkit. TIle
application may also make direct calls to some Xlib routines for generating text and graphics output
in a window.
Learning about Xlib is important for an X programmer. Therefore, this book focuses on teaching
you how to write X applications using the Xlib. In later cnapters, you revisit the features of X sum-
marized in this chapter and learn more detail about working with Xlib.

. . UNIX System v.
REAMS mechanism that ISnative to .
Dependence on Operating System AT&T's implementation of X uses the ST ki tocol available for data transfer, the X
. common netwOr ng pro . d which the
The basic'aesign of X does not depend on any operating system. All X needs is a reliable data path Nevenheless, as long as t h ere ISa . .h/ d to the operating system un er
c chent Wit 6ut regar
between the clients and rhe X server. So far, X)mplementations have used TCP/IP, DECNET, and server can display output rrom any
STREAMS networking protocols for transferring data between the server and clients. However, client executes.
the operating system sometimes becomes a factor because of its close ties to the networking soft-
ware being used by a client application to transmit the X protocol requests to the display server.
~Be~ . n of menus, buttons, or labels in the X protocoL The application constructs its own user
If you have programmed a window system you do not need to b - . d
d ow system IS " ' e conVInce that add . , C ce using the primitive facilities of the X server. You can use X to build any type of user inter-
a good Idea. You know1~at with a standard s h X d stan ar Wln- Iiltena ,
. d f uc as you 0 not hav I face ou want. Fot example, the popular Motif toolkit is capable of producing the look and feel of
WIn ow system for evety new machine. With the widesp d X. e to earn a new
. " rea sue POrt enJovs I Mic:Csoft Windows. It also is possible to develop an X application that mimics the layout and be-
you can write ~!Jcatlons for a wide variety of workstat' Th ' ~ce you earn X,
IOns. ere are sev al h b fi havior of Macintosh applications.
well; these are described in the following sections. er Ot er ene ItS

Network Transparency Room for Future Extensions

The architects of the X Window System realized that they could not envision all the needs that an
X server may have to fulfill. ~low for unforeseen tasks they left room for extensions in the X
protocoL Already, there is much work done in adding a three-dimensional graphics extension to
t e X'server. This extension to the X protocol makes 'use of another standard, known a GS,
the Progtar11me ' Ie archical InteractiVJ: Graphics Standard, that supports three-dimensio!Jal
raphics. The new extension to Xjs geing c ed PHIGS Extended lGor PEX.

Versions of X ! tvt'~1-6 vC I'~ X·

Development of the Window System started in 1 84 at MIT under the auspices of the MIT
La oratoty or omputer clence an roJect thena. FTom~e beginning, had in ustry
because ofDEC's and IBM'7involvement in Project 'Athena. early 1986 DECintro-
Separation of Computing and Graphics duced the first commercial im12lementation of X running on the VAXstation- Gp)t u he
T ~ S
. 1dQ1tI . , tfiXoperating system. ThIS was X Version 10 ReJease 3 (X10R3). Soo~ X attracted the attention
x ..' I a clear .separ;tt!on o{ r h' cd . o ot er prominent workstation ven'dors, suc as Hewlett-P1ckard, Apollo Computer, Sun
• a plicatIOn is handled by sending X I _ g ap ICSan -{;om g-the output from
tlon can etform ItS cornpuratfons on a s ~:::co requests .to ~n X server. The r~ tea plica- Microsystems, and Tektronix. (Apollo has since merged with Hewlett-Packard.)
tion-intensive simulation model can use-; Cra t at est SUitS ItS nee. s. or example, a comp";ra- Feedback received from the users of Xl 0 urged project members to start a major redesign of the X
the tesults on a workstation or an X terminal. y for ItS work and provlQe a visual representation of protocol. While the design of what would become X Version 11 (XII) was proceeding, Xl OR4was
released in December of 1986. This was the last release of X Version 10.
Diverse Systems under X Aanuary 1987, durin the first X technical conference, eleven major cotnputer vendors announced
( A consequence of the cl" ;J.loint effort to support and standardize on XII. l'he first release of XII , XII R1, became available
--.- lent-server model db X d'
mix ana match computers and works . use y an l.tS network transparency is that you can i~ eptember of 198~To ensure continue evolution of X under the control of an open organiza-
and they can be networked Th" . tatl.ons from many different vendor., as long as they 1Than tion, the MIT X Consortium was formed in January 1988. Under the leadership of Robert W.
hardware and software p' ki' IS IS ~n Important benefit for people who have to s I sup-p Scheifler. one of the principal architects of X, the consortium has been a major reason for the suc-
har d ware upgrades mu. t IC ng fi a speCific d h
system oes not ave to mean that all futur
e ect computer
ftw cess ofX.
.- s Come rom th d f e so are and
additions to the facility b fi e same ven or. I the hardware and softw In March 1988, Release 2 of Xl X11R2, became available. XII Release 3 11R3, appeared in
• can e rom a f h are supports X
eneous com utina envir ny one,o t e many vendors that also suPPOrt X S -h h ' late ctober 19.88. In January 199 ,t e T X Consortium re eased""" 1R: and followed it with~
. to> onments alread " . .. . uc etero-
war d mlx-and-match Com' y eXist m UlllVerSltlesand laboratories and t
pUtlng Isbeg~nning to appea't in comtnerciaT environ:Uents a: :cl~ ~o-
X11R5 in August 199L .•••As X take~;oot in the ~orkstatio~ world, the'X Consortium continues to
Improve X in several areas, including support for X programming using the C++ programming lan-
Mechanism, Not POlicy ?uage and the addition of an object-based toolkit named Fresco, which was part of XII R6, released
IIIApril 1994. Throughout these releases, the XII protocol has remained unchanged. The enhance-
"- cYidesmechanism, nOt poli " . . ments have been through the XII protocol's capability of supporting extensions. When this book
phi osphy ofX. The X protoco . ThiS quote from the architects of X states the d I . was being written, the most prevalent version of X was X11R5, but X11R6 was already available
sets forth the basic tasks that an X server erfoxms TUhner.ymg
--._-- . ere IS no and this book covers all salient features ofX11R6. ......-----""
Chapter 2

Clients, Servers, and

Window Man.agers

Chapter 1, "Your Workstation and X," gave you an ovel view of the X
Window System. Now you have an opportunity to get acquainted with
X as a user. Suppose that you have been given a UNIX workstation with
X and your assignment is to become familiar with X so that you can imple-
ment an X-based user interface for an existing application. To do this,
you first want to find out how to run X on your workstation (assuming it
is already installed). You also want to see how typical X applications be-
have. This chapter and Chapter 3, "Exploring X Applications," help you
meet these objectives. The first section of this chapter shows you how to
install and run X.

VI/Installing X
epending on your situation, you mayor may not have to install X. Sev-
eral scenarios are possible. Let's consider them on(;:by one.

Because y:ou I1lan to write programs that need the-X Window System,
)Counee the standard UNIX development tools, regardless of your hard-
ware setup:

• Editor
• C compiler
• Linker
• ibraries, including Xlib and any toolkits.such as Xt and Motif
t at you plan to use
You.cannot get by with an X rerminal or a Macintosh or an MS-DOS PC that runs only anXserver.
_You need a workstation with J JNIX and X or an X terminal connected to a host computer that has
the X development tools.

I \J'.X on a Workstation
't' ul- ed ed UNIX workstation you can have a stand-alone X a lication development
ny workstation vendors inc ude the X Window System with UNIX. With t ose
theJ?rocess 0 installing UNIX also installs· .
The options are different for the lower-priced Intel 80386-based UNIX systems (often referred to
as 386 UNIX systems). Typically, the 386 UNIX vendors sell everything piecemeal. UNIX itself
may come as a run-time system geod only for running applications. To develop applications, you
need a development system. a come in rwo varieties as well: a run-time version and the deXelop-
ment system. If .y.ou plan to develop, .applications, you ee the de elopmem systems for both

If you have the necessary sofrware from your 386 UNIX vendor, installation is straightforward (as
long as you make sure that your video adapter and mouse work with the vendor's UNIX and X
Figure 2.1.
sofrware). An 80486-based PC running UNIX is an affordable choice for small companies and in-
Naming X displays and
dividuals. This is particularly true because of the availability of high-quality freely availabl U IX Network
screens. connection
and X development environments such as Linux.

X Terminal and a Host Com,euter


To work effectively with X terminals and a host computer, get the X libraries and toolkits on the
central computer, then connect it to as many X terminals as you need and do all programming on
the central machine, accessing it through the X terminals. f you are in this situation, you probably
do not need to worry about installing X because it is the system manager's job to install Xlib and lnbsys: 0
roolkits on the central system.
Screen Screen
Screen lnbsys: 0.1
Ilnbsys: 1.0 lnbsys: 0.0
Starting X J

. with 0 A screen is specified by ap-

V From the overview of X in Chapter 1, you know that our workstation must be running an X server In X, the screens within a display also are num b ere d startlng. fi
, ·th· d () as the separator The Irst screen
before you can display ourpur from X applications StalJing)0nvolves unning the X server, fol- pending the screen number to a display s name, WI a peno .. .C h d
'" . B d' I 0 has rwO screens, rerer to t e secon
lowed by the X applications you want. If lOU also wam to ~u app lcalions on remote mac iIies, rn Figure 2.1, display lnbsys: 0, ISlnbsys: 0.0. ecause ISP ay 0
~arsteps ~fe ~e<J:ullcdfol loggin in~e remote system, startrng the apphcatlon, and inak- . 'fi d h ssume ha ou want screen ,
one as lnbsys: 0 . 1. When screen IS not s eCI Ie t e server a
ing re-rhe ~pp1Jcatlon knows where to send the Output. The exact steps for doing t (s diffe"ffrom the default scr.een.
one workstatlon vendor to another. orkstations that so have their own windowing systems may
requjre you to start the X server manu~ly, then follow with the applications. Before you do any of
this, you have to learn how to name displays in X.
d Window Managers
Chaptel' Two: Clients, Servers, an

NOTE: NOTE: . l' f

~ ••.•andto see a 1St 0

'l;)'l f')
In UNIX System V, use the command uname • n to find the network na{l1.eof your syste Use the enV co•••.•••
In BSD UNIX (Berkeley UNIX), the equivalent {;ommand is host name.
• .-? J\ e'\V\ ~
"th xintt"- D f~
X Server Startup WI . 1 and set the DISPLAY var~ble, yo~ are ready to ~t~~t
know hoW to name an ~ d a iki cr sure that t e PATH ex:.vlronment vana e
:NoWthat o~d run some X applicatlons. _ter m ~"X server by typing this command:
In UNIX, the environment of a Rrocess consists of an array of strings; each string defining an e t e X server /bin/X11 directory, you can start t .
ronmentvaria eo e orm VARIABLE=value. eYalue of an enyironmentv'aria Ie is also astr contains the /usr
An environment variable is nothin more than a way to attach a standard name to an arbitrarx tri

Environment variables rovide a convenient way to pass information to processes. For exam
when you type me name of a program to be executed, the UNIX shell searches the-list of directo
given by the 8J.!t nvironment . b IN' ch is always set 0 a string containing a list of direct
names separateo y colons (:). You can examine the current setting of PATH with the sliett"'co
inand echo $PATH. A typical setting might appear as follows:

With this PATH setting, when you enter the name of a program, the shell searches the directo
/ bin, / us r / bin, / etc, I usr / bin / X11, and the current directory, in that order. When using X,
NOTE: . '. . <isfor n1lX'; . sh'-cu.
thoe TU~... l1
sure the PATH environment variable includes the directory that contains most X utiliry progra
usually /usr/bin/X11.
A shea script is a me contamUlg cornman. . . '.{,

der X. In the script, each pro-

Environm~nt variables are used not only by the shell, but also by many application Rrograms, i l' ' YGuwant to run un h .
c udmg X applications, that use the DISPLAY environment variable to determine which server The shell script ~xini t~c starts--th~app IC~tl~S ound Because the X server exits w~en.t e scnpt
ceives the output of a clien. ccordingly, on the machine where you start an X client, you have ram except the last one is started m the ~c ,r The trick is to make the last apphcatlon some-
set DISPLAY to the name or the server where you want that client's output to appear. If you ~nds, this keeps X going until the lasttP~lc:::~~~sed later in the chapter) fit t~e b~ll For exa: ~~
going to run X applications locally on your workstation, you have to set the DISPLAY variable 0 thing permanent, Window,ma~agers to e (mwm)and-sev ral::other a:pphmt~€lns,'you s 0
that system also. For example, if the system's name is Inbsys, to get the output on the first sere if you want to run the.,.Mou W.Jnd.ow..M~na~~ d In this case, the. xini t rc senpt might read as
of the first display, set DISPLAY to Inbsys: 0.0. start mwmast ecause it tends to be veq>:ong- Lve .
# Clients started by xinit
# Last client should not be ~'n background
In the Bourne shell, use the command DISPLAY=sysname: 0.0; export DISPLAY to set xlogo 2> /dev/null &
up the DISPLAY,variable for output on a workstation named sysname, In C shell, use xbiff 2> /dev/null &
.setenv DISPLAY sysname:0.0. .
xterm ·sb 2> /dev/null &

mwm2> /dev/null 'th llbar) and the Motif Win-

, h h . sb option enablmg e scro " th ull de-
Other imp?rtant environment variables are: HOMEwhich specifies your login direc Q ; SHELL,~ich This starts xlogo, xbi ff, xterm (Wit ted' rded (because of the redirectlon to e n
dow Manager (mwm),with all error messages ISca ,
in .cates the UNIX shell you are using (I bin / sh for oume shell, / bin / csh, or C shell); and TERM,
~h ~ y'our termLnal type:'X also uses an environment variable called XENVIRONMEN:i:0 • vice),
cate a file through which the user can s ecifl p'arameters such as colors, fonts, and window sizes)
to be used by various applications (see Chapter 3).
, this is how you start th X
e server and .1:
Make sure PATH contains /usr/b'
. 1n/X11s h h Most sites, however, have many more requirements. For example, a site may have a mix of X work-
your vendor the s' 0 t at t e shell can finci tb.
file to /usr/binLXH/X (0 erverkIn a file i~h ~ name different From e.xsel.}:er PLo~If stations and X terminals. Workstations may run local X clients, but the X terminals will run only
Set DISPLAY e a sJ!:mbollc lInk). 'm c0"Y. of that remote clients. The site administrator may want to have X terminal users log into a specific remote
to YOur workstation's scre n d s stem automatically. Site administrators can meet these tequirements by writing a site-specific
StartXbyrypingxinit h h an prepare an .xinitrcfile. ~artx script file. If your site uses startx to start an X session, consult its documentation or ask
at t e s ell prompt.
the system's staff for information on the site-specific features.
er some rearrangemen t ofth . d
ks . eWIn ows th
wor tatlon wi th X Th d' . ' e screen shown in F" 2
first command sho . .e. hlgltal clock shown in the lower-righ Igure .2 was produced on a UNIX
. wn In t e xte . d t corner of th . X Display Manager (xdm) "/
utility program being u d rm WIn ow. The other command' h e s.creen IS started by the
P amtBrush se to capt hInt at WI d h
format and d . . ure t e Screen to a file. (Th fil n ow sows the xwd
use In this book.) at I e was later converted to PC

Figure 2.2.
A typical screen layout in
an X workstation. .

When first run xdmr.eads in various confi uration arameters from a file named xdm· conf ill, which
IS usually in the directo~~usr / lib / xn / xdm. One of the paramete!s inhe name of a file \peci£y;-
ing the displays on which xdm will manage login sessions. Usually, this list is in the file /usr/lib
/X11 /xdm/Xservers. The name of a dis la also indicates whether it is local or remote. Suppose
you want to use xdm to access your workstation from the local display as well as through two remote
X terminals (named xremote1 and xremote2). In this case, the Xservers file may contain the fol.
lowing: ~
:0 local /usr/bin/X11/X :0
xremote1:0 foreign
xremote2:0 foreign

In X, the terms server and display are used interchangeably. Local displays are indicated by the
local keyword following the display numbet (and the name of the X server executable must be
given). For remote displays, the name followed by the keyword foreign suffices.

After reading the list of displays, xdm sRawns a subprocess f~r each displa . Each subprocess t~es
care of managing the login session, in the following order:
The startx Shell Seri t For a local X display, the subprocess starts the X server; for connections to a remote display
Usin xintt,i better th . . (for example, when connecting to X terminals), it establishes the network connection.
comp . d f( an Sfanmg the server and th .
. lcate or newcomers to X F' e aflphcations manu~ll . h '. . 2. Once connected to a display", the subprocess displays a dialog window containing fields for
statIOns provide a sh 11 . • or this reason, most system d . . "'l y, owever, It still IS rather enteting name and a assword.
. 1 a mlOlStrators
server and other appI"
e scnpt appr
. '
ICatlons starred I'
°enate y named startx
t d
, 0 0 eyerythin
d d
an ven ors of work-
3. When a user enters a name and password, xdm verifies them and executes a startup script
settmg the environ . . n lts simplest orm t g necessary to get the
PA menr varIables tH D ' e startx scnpt ty . al Xstartup (usually in /usr/lib/X11 /xdm).
TH to mc ude t e::l' - e ISPLP.Y variable to ;, ."(:.;~ piC Y Starts 0 Tby
X Ulrectory wh h en thy tue X
-.-..;;,;;".;;;:;;..'" 4. The subprocess in charge of the session looks for a scri t file named. xsession in the
server and ae.elicatlons going ere t e X server Qrogram resides-ana th server to X dien and
.' en uses XI n1.-t-to get the user's home directory. his file is similar to the. xinitrc file used by xinit. It should list
the commands for starting selected X clients. Typically, this includes xterm. If there is no
. xsession file, xdm's startup script Xstartup usually runs xterm.
5. From this point on, the user can interact . h h
Wn.. - WIt tMesystem through the xterm window
6. .~J1en the user logs off the s stem xdm ru I . Like most X utilities, xdm is highl configurable. !he names of the script files listed above are typi-
, ns a c ean-up sc . d
/usr/lib/X1'!7Xdm directOlY). t tne en ho npt name Xrese (also in the
. cOt IS, xdm returns t e era.! ' d ' d' I cal ones, but you can speci other names through the file named xdm-conf ig, which, by default,
an d walts ror another user to log in. I og wm ow ISPay
also resides in the ditectory /usr / lib/X11 /xdm.
This brief description of xdmshows that for a site with al h
X termm . al . 'd a centr ost computer c d
s, xdm ISI eal for enabling users to I' h . onnecte to several
nario, illustrated in Figure 2 3 each X t "
al° mt~ t e system from the X terminals. In this sce-
ning Remote X Clients
. , ermm runs ItSown X se d
tral host. rver an xdm executes in the cen- ou have...learnedhow to stan theXseryer and local clients by using xini t or the s~rtx script file.
How do you run remote X clients and have thelf output appear at your wor tation's screen? To
Figure 2.3. run a remote X client, you must follow this basic l2.fOcess:.r
_._. __ ' r
Using xdm to manage login
sessions on X terminals,
/ La jnto the remote system.
e DISPLAY environment variable on that system.
xecute the client application.
For an X terminal displaying the login window from a remote xdm process, enter your name and
password to get to the rem.2!e host, OtQerwise~ );OU have to 10 into the remote s stem from an
"Xtermwindow Oll-your workstation.

Logging Into Remote Systems from xterm

X i6nnina!s

E.lch runs X selVer

DIalog Windows " Login;
To access a remote system from xterm, a netWork connection must exist between o_uJ:.
"'name cornman, were rname is the name 0' e remote~'St m. If you have an account on t at
at system. fthere is a TCP1tP connectio.n, you can log into the remote system with the rlogin

system with the user name under which you have logged into the workstation, you may get the shell
prompt from the remote system' immediately. Otherwise} you are prompted for user name and
password. Once you are on the remote system, you can set the DISPLAY variable to your worksta-
tion and run the X clients of your choice.

Controlling Access to Your Workstation

User 2 Mouse
When running. a remote X client, a typical problem is that your workstation may refuse connection
The Xs:rvers file in the host lists the X terminals bein
l( termmals are named xremote1 d g managed bl,.Xdm. Assuming that the two to the client; the remote client fails with an error message. If this happens, examine the contents of
an xremote2, the Xservers file h ld . the file /etc/X0. hbsts (assuming that your workstation has only one display). This file is used as
:remot~1:0 foreign " s ou COntam the following:
.remote2:0 foreign an access liSt for display 0 and should contain the names of remote systems that are allowed to estab-
lish connection with your workstation's X server. If you want clients running in two remote sys-
1o10rerecently, the use of the Xservers file h b ..r.,
tems named remote1 andoof'emote2 to display on your workswion, your workstation's fete
v1anagerControl Protocol (XDMr-P) h' h ~ een superseded by the advent of the X Display /X0. hosts file shO~uldcontain the following:
fOrk. Now, X terminals use XDM'cP' w IC IS~e~nt for .requesting login service Over the net-
~mOtehost. to request ogm service from an xdmproeess running on a # list of authorized foreign hosts
~ e2

Alternatively, while logged into your workstation you can give the command xhost +remote1 to
add this system to the access'list of your display.
Part One'. usmg
T T • h .
t. eX lVtndow System

OSF/Motif, or M.otif for short, is the common user interface style selected by the Open
Software Foundation (OSF), The OSF was formed in 1988 by a gmup of major hardware
vendors that includes IBM, DEC, and Hewlett-Packard. OSF/Morifis a combination of
several things: an X toolkit· for developing applications, the Motif Window Manager (mwm),
and a style guide for developers, The MotifWmdow Manager has a three-dimensiona1look
.A window manager can provide a means to switch fro B and was derived from work done by Hewlett-Packard and Microsoft, The look and feel of
example, the ~tifWindow Manager mwm dd d m ~o4, even when B is ill-behaved. For
Motif comes from Microsoft's Presentation Manag~r, which, in turn, is gerived from
each application. Thi; frame enables y co' a
1 s ~d ec~rat~veframe to. the top-level window of
.,J.... to· OUto move an reSlze tne' . . Microsoft Windows, This heritage of OSF/Motif has eased its acceptance among the large
uoW oy pressing t e mouse urton w let. . WlO ows. ou can sFinn s win-
. th. e pOlOter ISm one 0 f !t:t;o~."....__ ••• number of PC users who are familiar with Microsoft Windows and Presentation Manager.
...E! . e mouse whlle the button is pressed Th M 'fW' d 0 tile frame an-chnov- /
. d th h- . e ot! lO ow Man h
wm ow at c anges size with movemem of the mouse Th' ager sows an ourline of the
smaller to expose other windows underneath Add' ~l 1~enables you }O make the top window.
by clicking at the upper-left corner of the fi . ltlO;. y, wlth mwm you16anget a ull-down menu
have options that enable you to move d ra~e (s~ed Igure 2.4). This menu can be configured to
an reSlZewm ows.
You ~eed a window mana er in order to comrol t I .
no wm ow ma~sLlffi.Hin---k . acemem and SIZ m's wi If
5' ",er s no way Fe change . d ' I .
~ a wm ow s ocation or alter its size.
Figure 2.4.
Frame and menu added to
a clientj· window by the
Motif Window Manager. The manner in which a window manager handles placement and sizing of windowJ. differs from
one window man ~r to anot Usually, the window managet adds a tide bar to the window when
ilie window trst appears on the screen. Simpler window managers may pop up a menu when you
press a particular m01Jsebutton in the tide bar. Advanced managers such as mwm also add a frame to
the main window of each client, enabling you to reSlZea client's window by pressing the mouse
button wEt e the POInter is m the border and dragging it in the desired direction.
W'.ndow man rovi es of layout for the main windows of client applications (see
Figure 2.5). Most window managers allow win ows to over ap an provide some mechanisms to
bring obscured windows to view. A few rearrange and resize the windows to ensure th.~ no win:..-
~ws overlap on the screen. The overlapped layout is the most general one, and the preferred style
for small screens. The tiled layout is a special case of the overlapped style. The Motif Window Manager
allows overlapped windows.

Figure 2.5.
Overlapped versus tiled
layout of windows.

Overlappe~ TIled-

"'" --=-
d Window Managers
Chapter Two: Clients, Servers, an

s. To
· nication is h
this pe of interc IIe 0 °d R enthal of Sun Microsystems as pre-
e extent, I' h future aVI os C h h
To som . h ens flawless Y In t e , t (ICCCM) which puts lOrt t e con-
Focus Window hat thiS app . C entions Manua ' h h (S
ensure t ct· nt Communicatwns onv II . act ro erlywith eac ot er. ee
d th Inter- te h OU
Id fo ow to Inter .' d h
~r usually controls another important aspect of an X application-which window pare. ethat clients and window man~ erfus s h discussi~n of inter client communlcauons ate
h-;?the mpUt focus. This refers to the wIndow that receIves the· keyboard e-ver;ts.Mouse Inpuris venuons dT . 'n X" lor rt er
6 "Advance 0PICSI , ~. ~
~ easy to conuol; the wi~ow that gets the mouse events ISthe WIndow with mouse pointer in it. The Chapter 1 , . •A\, ° (
keyboard, however, has no on-screen pointer to indicate which window should receive the actions ICCCM.) ~
generated by keypresses. X Wi?dow System solves this problem by specifYing that all keystrokes go
· -fWindow Manager
to the window with keyboard foc~_!he window helps determine which window gets the
focus. There are twO ways a window manager can do thIS;
Using the Motl . to-at a bare minimum-move and
Window managers play an im pOkrtant:~~~fl%::;~~~~::umanager, consider the Motif Window
---. Some window ma~ers gJ.vethe focus to the wi:dow with the mouse pointer in it. . . dows. For a closer 00 l at a u
reslze wrn
• Other window managers, including mwm,use the concept of a listener windo~ili..
Manager. .
'fW' d
Manager ISna
med mwm'it usually resides ip
window with the fo~us. The l.iS selects the listener window by moving the pointer into it e
Recall that the executable fIle-for tt Mo~ pic~IYo;ou start it from a snett cript that ~ inp~ to
~ and cltcking the mouse butt: _.~ nce selected, that window remains the focus window no
/usr/bin/X11 with the other X c le.nts~ Y d st~rtx. For example, you can run mwm y m ng
matter where the mouse pointer moves. .' r a site-speci ICX startup scnpt name .
nOl. to. d the last line in the scnpt:
In one case, the window with the mouse pointer gets the keyboard events. In the other, you have to the folloWing cornman
move the pointer into a window and click to indicate that all subsequent keyboard events should go
mwm2> I dev I null
to that window. r t wm. d ows. It ena bles users to move windows,h
ce started, mwmadds a frame to all.on-screen cleo. the in ~t focus. It also adds a menu to
Users familiar with Microsoft Windows or Macintosh applications tend to prefer the similar con- O~ them change a window to an Icon: an.d chbangle. tte window. Additionally, mwmprovides
vention adopted by mwm.You can, however, configure mwmto enable the keyboard focus to follow reslze '. kill h hcatlon Yc osmg .
window that enables you to t .at app bles you to launch new applications.
the mouse pointer. . d w ThIS root menu ena . . hi
a menu for the root wm 0 . . f I 'k ost X applications,1'1wmIShlg Y
. h d f ult settings 0 mwm.~I e m d b ave
The following diSCUSSiOn assumes tee ~ d'f ou fmd that mwmin your system oes not e
onfi urable. Therefore, do not be surpnse I Y
In the process of controlling the layout of windows and deciding how windows get the focus, a exactly as des ribed here.
window manager ends up imparting certain common characteristics to the client. Under a specific
window manager, the way you move o.r..resizea client's window becomes stand "'Moreover, the
rame an menus proVI e t e wmdow inanager also add to the appearance and behavior (t NOTE: .' '. {aith ugh in practice most workstations .
an feel) 0 tee lentS. evert e ess, t e Win ow manager alone cannot make all X applica- X provides for a mouse with up to :ve bu;to:; defa:lt, the buttons on a three-bud: gh
tions behave iJentica Iy. 0 achieve a common look and feel, the applications must follow a com- .
mon style guide and use a standard toolkit. Chapter 4, "Graphical User Interfaces and X," discusses
have mice with one, twO; or three ;
mouse are numbered one through
7' m left to right, but this can be change th roU
ree.. ~ tes the current location as you mov~ e
this issue further. configuration frles. The mouse poi~ter In ~th most X clients using the left mouse button
te that you can mter<lctWi
mouse aroun d . No .'
(button one). '. '.' with the mouse. To'
d 'be the usermteractlOns . of
An important responsibili of a window manager is to act as an iVteqnediary: between..clients. In- The terms click and drag are used to escn b while the pointer is in a pattlcular ~ea
teraction among clients is importaht so t at map.y different X app icatlons can coexIst In a display click the user presses and releases a mous.e ubtton . and moves the mouse while keepmg
'. mouse utton
creen and be used productively. Suppose, for example, t at you are using two <pjJlications: a oo.XL the screen. To drag, the user presses a ° .
-editor to write progr:UUsand an o'n-iine refer nce guide to rowse through the Xlib fuflctions. Both that button pressed. .
are useful stand-alone tools, but imagine how usen.Ifthey can be if the two applications can exchange
information. s'uppose, in your program, you want to call the Xlib routine XDrawArcto draw an arc,
but you cannot recall its exact syntax: You could go to the Xli5 browser, find more information on
XDrawArc,select the sample call shown there, switch to the editor, and paste the function call into
your program--all with a few mouse button presses.