XView and the X Window System
The XView Toolkit allows a programmer to build the interface to an application without hav-
ing to learn many of the details of the underlying windowing system. However, it is valuable
to have some understanding of X before attempting to build applications under XView. This
chapter introduces many of the most important concepts on which the X Window System is
based and describes the computing environment for X applications. It also describes the role
of the XView Toolkit in the X Window System.
For the most part, this chapter assumes that you are new to programming the X Window Sys-
tem. This chapter describes the basics of the X Window Systemfurther details will be
described as necessary later in the manual. However, this book does not repeat the detailed
description of Xlib programming found in Volume One, Xlib Programming Manual. If you
already have some experience programming the X Window System, you might wish to begin
at Chapter 2, The XView Programmer’s Model.
1.1 The X Window System
X controls a bit-mapped display in which every pixel (dot on the screen) is individually con-
trollable. This allows drawing of pictures in addition to text. Until recently, individual con-
trol of screen pixels was widely available only on personal computers (PCs) and high-priced
technical workstations, while more general-purpose machines were limited to output on text-
only terminals. X brings the same world of graphic output to both PCs and more powerful
machines. Figure 1-1 shows an X application in comparison with a traditional text terminal.
Like other windowing systems, X divides the screen into multiple input and output areas
called windows, each of which can act as an independent virtual terminal. Using a terminal
emulator, windows can run ordinary text-based applications. However, windows can also run
applications designed to take advantage of the graphic power of the bitmapped display.
X takes user input from a pointer, which is usually a mouse but could just as well be a track-
ball or tablet. The pointer allows the user to point at certain graphics on the screen and use
the buttons on the mouse to control a program without using the keyboard. This method of
using programs is often easier to learn than traditional keyboard control, because it is more
intuitive. Figure 1-2 shows a typical pointer being used to select a menu item.
XView and the
X Window System
XView and the X Window System 3
Dear Mr. Sekino:
This letter details the book distribution agreement we
reached in our
discussions on June 9, 1989 and in subsequent
The terms are as follows:
.Ls N
Toppan shall be the esclusive distributor
in Japan for all titles published by O'Reilly and
Associates, Inc. (ORA).
ORA will refer all sales inquiries
from Janpanese customers to Toppan. The only exption is
that we will
"sekinol" 108 lines, 3726 characters
Grouch-0 8%!g
text terminal
X window system
total 49
1 sbin/ 3 etc/ 1 preserve/
1 5include 1 hosts/ 1 pub/
1 5lib/ 2 include/ 1 sccs
1 Xlir3@ 1 kvm 1 share/
1 adm@ 4 lib/ 1 spool@
6 bin/ 1 local/ 1 sqps
1 boot/ 8 lost+found/ 1 stand/
1 demo/ 1 man@ 1 sys@
1 diag/ 1 mdc/ 1 tmp@
1 dict 1 old/ 2 ucb/
Clear Area
Invert Area
Set Area
Copy Area
Overlay Area
Move Area
Filled Circle
Flood Fill
Set Hot Spot
Write Output
Clear All
Invert All
Set All
Figure 1-1. An X application and a traditional text terminal
total 49
1 sbin/ 3 etc/ 1 preserve/
1 5include 1 hosts/ 1 pub/
1 5lib/ 2 include/ 1 sccs
1 Xlir3@ 1 kvm 1 share/
1 adm@ 4 lib/ 1 spool@
6 bin/ 1 local/ 1 sqps
1 boot/ 8 lost+found/ 1 stand/
1 demo/ 1 man@ 1 sys@
1 diag/ 1 mdc/ 1 tmp@
1 dict 1 old/ 2 ucb/
Figure 1-2. Selecting a menu item with the pointer
4 XView Programming Manual
Of course, X also handles keyboard input. The pointer is used to direct the input focus of the
keyboard (often called the keyboard focus) from window to window with only one applica-
tion at a time able to receive keyboard input.
In X, as in many other window systems, each application need not (and in fact usually does
not) consist of only a single window. Any part of an application can have its own separate
window, simplifying the management of input and output within the application code. Such
child windows are only visible within the confines of their parent window. Each window has
its own coordinate system where the origin is the upper-left corner of the window inside its
border. In basic X, windows are rectangular and oriented along the same axes as the edges of
the display. The application or the user can change the dimensions of windows.
Many of the above characteristics are also true of several other window systems. What has
made X a standard is that X is based on a network protocol—a predefined set of requests and
replies—instead of system-specific procedure calls. The X Protocol can be implemented for
different computer architectures and operating systems, making X device-independent.
Another advantage of a network-based windowing system is that programs can run on one
architecture while displaying on another. Because of this unique design, the X Window Sys-
tem can make a network of different computers cooperate. For example, a computationally-
intensive application might run on a supercomputer but take input from and display output on
a workstation across a network.
1.1.1 The Server and Client
To allow programs to be run on one machine and display on another, X was designed as a net-
work protocol between two processes, one of which is an application program called a client,
and the other, the server. The server is a resource server, controlling a user’s resources (such
as the display hardware, keyboard, and pointer) and making these resources available to user
applications. In other words, the X server isolates the device-specific code from the applica-
The server performs the following tasks:
Allows access to the display by multiple clients. The server can deny access from clients
running on certain machines.
Interprets network messages from clients and acts on them. These messages are known as
requests. Some requests command the server to do two-dimensional drawing or move
windows, while others ask the server for information.
Passes user input to clients sending network messages known as events, which represent
key or button presses, pointer motion, and so forth. Events are generated asynchronously,
and events from different devices might be intermingled. The server must de-multiplex
the event stream and pass the appropriate events to each client.
Maintains complex data structures, including windows and fonts, so that the server can
perform its tasks efficiently. Clients refer to these abstractions by ID numbers. Server-
maintained abstractions reduce the amount of data that has to be maintained by each cli-
ent and the amount of data that has to be transferred over the network.
XView and the
X Window System
XView and the X Window System 5
In X, the term display is often used as a synonym for server, as is the combined term display
server. However, the terms display and screen are not synonymous. A screen is the actual
piece of hardware on which the graphics are drawn. Both color and monochrome displays
are supported. A server might control more than one screen. For example, one server might
control a color screen and a monochrome screen for a user who wants to be able to debug an
application on both types of screens without leaving his or her seat.
The communication path between a client and the server is called a connection. Several cli-
ents may be connected to a single server. Clients may run on the same machine as the server
if that machine supports multitasking, or clients may run on other machines in the network.
In either case, the X Protocol is used by the client to send requests to draw graphics or to
query the server for information; it is used by the server to send user input or replies to
requests back to the client. All communication from the client to the server and from the
server to the client takes place using the X Protocol.*
It is common for a user to have programs running on several different hosts in the network,
all invoked from and displaying their windows on a single screen (see Figure 1-3). Clients
running remotely can be started from the remote machine or from the local machine using the
network utilities rlogin or rsh.
Personal Computer
Large Minicomputer
Display Server
Figure 1-3. Applications can run on any system across the network
*The X Protocol is independent of the networking hardware and runs on top of any network that provides point-to-
point packet communication. TCP/IP and DECnet are the only networks currently supported. For more information
about the X Protocol, see Volume Zero, The X Protocol Reference Manual.
6 XView Programming Manual
This use of the network is known as distributed processing. The most important application
of this concept is to provide graphic output for powerful systems that cannot have built-in
graphics capabilities. However, distributed processing can also help solve the problem of
unbalanced system loads. When one host machine is overloaded, the users running clients on
that machine can arrange for programs to run on other hosts.
1.2 The Software Hierarchy
There are many different ways to write X applications because X is not restricted to a single
language, operating system, or user interface. The only requirement of an X application is
that it generate and receive X Protocol messages.
Figure 1-4 shows the layering of software in an X application. Xlib is the lowest-level C lan-
guage interface to X. The main task of Xlib is to translate C data structures and procedures
into X Protocol events; it then sends them off and receives protocol packets in return that are
unpacked into C data structures. Xlib provides full access to the capabilities of the X Proto-
col but does little to make programming easier. It handles the interface between an applica-
tion and the network and includes some optimizations that encourage efficient network
usage. The list of functions that Xlib performs is so extensive that if the programmer were
responsible for handling all these pieces directly, application programs would be too large
and prone to performance degradation and potential bugginess. For this reason, toolkits are
used to modularize the more common functions that handle the user interface portion of an
XView is one of a half-dozen or so toolkits available for the X Window System. If you are
familiar with other toolkits, you will recognize that the XView Toolkit is equivalent to the Xt
Intrinsics and a widget set. Like the Intrinsics, XView is built upon Xlib. It is an object-
oriented toolkit that provides reusable, configurable user interface components, equivalent to
Toolkits handle many things for the programmer. They provide a framework for combining
pre-built user interface components with application-specific code. For example, if the appli-
cation needs to prompt the user for a filename, a toolkit should provide a component (a com-
mand frame) that is functionally capable of displaying the query to the user and providing the
user’s response to the application.
Any user interface component also needs to manage the interpretation of events delivered
from the window system. When events are generated, the toolkit decides whether or not to
propagate the event to the application or to use it for its own internal purposes. To continue
the example, when the user types a filename in the command frame, events are generated in
which the interface must decide whether that object should interpret the input or whether it
should be sent to the application. A toolkit thus comprises a mechanism to dispatch events
and a set of prebuilt interface objects that define the look and feel of an application.
*Widget sets are sometimes loosely referred to as toolkits. However, a toolkit comprises the functions of the Xt In-
trinsics layer and one widget set (e.g., the Athena widget set). There are several different widget sets from various
vendors that are designed to work with Xt. For more information on Xt Intrinsics-based toolkits, see Volume Four, X
Toolkit Intrinsics Programming Manual.
XView and the
X Window System
XView and the X Window System 7

Get Volume 7A: XView Programming Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.