Johnson and Reichard are authors of X Window Applications Programming, Advanced X Window Applications Programming and Power Programming Motif (all MIS: Press, 800-MANUALS). Johnson can be reached at erc@pai.mn.org via UUCP mail. Reichard's Compuserve address is 73670,3422.
As any C programmer who has gone near Windows, OS/2, or the Macintosh knows, programming in graphical interface environments can be a struggle. Furthermore, the resulting application is usually tied to the machine for which it was written, defying the portability C provided in the first place. There exists, however, a graphical interface programming environment that retains the portability associated with C and that runs on everything from an Amiga to an IBM PS/2 to a Cray supercomputer the X Window System.
X acts as an elegant and highly functional link between disparate systems, serving as a common interface across many different computers running different operating systems with several different displays. For instance, using X, Cray supercomputers can display output on an Apollo workstation, on an Amiga, or on any X station across a network. Major computer vendors, such as Apple, Xerox, IBM, Hewlett-Packard, and Sun, offer and promote X products.
For the programmer, the X Window System offers a variety of tools, shared resources and widespread portability. For the user, X Window provides a consistent interface, regardless of the platform.This article begins a series that will cover some basic X Window programming techniques. In this series, we plan to cover not only the mechanics of X Window programming, but also the theoretical underpinnings that make X such a unique programming environment.
Why X?
Several reasons explain why X has gained momentum in the workplace. First of all, X is an open environment. MIT holds rights to X, but allows unrestricted use. Thus the X developer isn't tied to a single vendor (such as Microsoft/IBM and MS-DOS).The X Window System is also a graphical windowing system. Studies indicate that graphical interfaces make computing easier and users more productive.
X has also piggybacked on the growing interest in UNIX. While not designed specifically for UNIX, X's greatest acceptance as a windowing system has been on UNIX. Unlike other UNIX windowing systems, such as NeWS from Sun and the NeXT interface, X is an open system usable without licensing fees.
In an era where linking different kinds of computers is paramount for software designers, broad-based acceptance for a windowing system is paramount for cross-vendor development. X's client-server model makes it possible to link disparate makes of hardware without costly emulation cards and exotic networking schemes. The user interface, which makes only X calls, doesn't rely on any one operating system.
A list of important X features would include the following characteristics.
Portability
X runs on computers ranging from the Amiga personal computer to the Cray-2 supercomputer. You will find X on PCs, Macintoshes, Hewlett-Packards, PS/2s, Suns, Data Generals, DECs, and most everything else. Barring a few minor differences, the C interface is the same across all these platforms, a major benefit over most other graphics systems.
Network Transparency
An X program, if written correctly, can run on one machine and display its output on another machine. X, by being operating-system independent, encourages portable software. X's standard C library routines are common across hardware platforms, meaning that your interface code ports directly from one machine to the other.
Vendor Backing
X runs on most every UNIX workstation available today. Digital Equipment, Hewlett-Packard, IBM, and Apple all offer their own versions of X. Other vendors offer the generic MIT X with their workstations, such as Data General's Aviion series. For MS-DOS users, several companies Quarter-deck and Integrated Inference among them offer versions of X for MS-DOS and Windows. Those who use UNIX on a PC will discover that almost all major vendors Interactive, SCO, Apple, Everex offer X Window with their UNIX systems. And finally, other vendors have merged X with proprietary windowing systems (NeWS in the case of Sun Microsystems) and now offer merged X servers.
Inexpensive Licensing
You can obtain the X sources (written in C) free. The information later in this article will help you order X, sually for the price of a tape and a small handling fee. You are not required to pay licensing fees if you release X-based applications.
Shared Resources
The X Window System allows programs to concurrently share devices such as mice, keyboards, and graphics displays. With X, your entire workstation is a display, consisting of a keyboard, a pointing device (usually a mouse), and one or more monitor screens. Multiple screens can work together, linked by the keyboard and the pointing device.Lest we give the impression that X is a bed of roses, we should make it clear that X is a high-level programming environment. A good deal of X development today is done at the workstation level. PC users can't merely slap X on a hard disk and expect a high-performance system. Those interested in X should obtain as much RAM as possible and invest in large hard drives 80Mb is good, 120Mb is better, and 300Mb is even better. You should look into high- resolution displays, and in networking cards, Ethernet, and TCP/IP. As for software development expertise, there's a certain amount of sophistication required to program in X Window. Experience with C programming and net- working is necessary.
The History Of X
In 1984, Massachusetts Institute of Technology (MIT) officials were faced with a motley set of incompatible workstations acquired through donation and purchase. Their goal was to build a network of graphical workstations. Faced with a crazy quilt of operating systems and hardware vendors, MIT officials formed Project Athena, an MIT development team working in association with DEC and IBM.Project Athena's solution was to design a network-based windowing system that would run local applications while being able to call on remote sources. This system was loosely based on a Stanford University software environment called W. By linking these workstations through a graphical networking environment, the designers created the first operating environment that was truly hardware and vendor independent: The X Window System.
The development team had the following goals:
By 1986, the outside world was clamoring for access to the X Window system. In March 1988, MIT officially issued Version 11, Release 2. Later that year, Release 3 became available. In January 1990, Release 4 was unleashed. As of this writing, only a few vendor-supported X products are at Release 4. Release 5 will probably appear in late 1991.
- Do not add new functionality unless an implementation cannot complete a real application without it.
- Do not serve all the world's needs, but make the system extensible so that additional needs can be met in an upwardly compatible fashion.
- If a problem is not completely understood, it is probably best to provide no solution at all.
- If you get 90 percent of the desired effect for 10 percent of the work required to get 100 percent, use the simpler solution.
- Isolate complexity as much as possible.
- Provide mechanism rather than policy. In particular, place user-interface policy in the client's hands.
When the X Consortium people refer to X, they call it the "X Window System," "X Window," "X11," or just plain X." People in the know never call it "X Windows" (note the "s").
What Is X?
The X Window System is based on a client/server relationship. The display server program controls and draws all output to the display monitorsthat is, it draws the dots on your physical monitor, tracks client input, and updates windows accordingly. Clients are application programs that perform specific tasks. (The terms client and applications are used interchangeably.) Because X is a networked environment, the client and server don't necessarily compute on the same system (although they certainly can in a number of situations). Instead, X allows distributed processing. For example, a Macintosh running A/UX as an X server can call upon a Cray supercomputer's processing power within the network, displaying the Cray's computations on the Mac's monitor.In the micro and mini worlds, a server is the hardware device at the center of a network, distributing data and processing power to networked workstations and terminals. In contracts, an X server is a local software program that controls the display hardware and runs on your local workstation. Because other systems on the network can access your display, you cannot view the X server as a file server in local area networks (LANs).
In X, a display consists of a keyboard, pointing device (usually a mouse), and one or more screens. The display server tracks multiple input, allowing users to run several clients (such as a database manager, word processor, and graphics application). A display can power multiple screens linked by a keyboard and mouse.
The server controls traffic between clients, or applications, running on local or remote systems. It also controls the power of the local system. The server:
Most importantly, the server tracks input from the display and informs the clients. In X, such inputs are called events. Pressing down on a key is an event; letting the key back up is another event. Similarly, moving a cursor with a mouse is an event. These events are delivered to applications through an event queue.
- allows access to a display by a client
- sends network messages
- intercepts other network messages from other clients
- performs two-dimensional drawing, freeing the client from processing-intensive graphics
- tracks resources (such as windows, cursors, fonts, and graphics contexts) that are shared between clients
- allows distributed processing
- allows multitasking, if X is used with a multitasking operating system (such as UNIX)
The Sum Of Its Parts
MIT's generic X Window System consists of the Xlib graphics subroutine library, the X network protocol, an X toolkit, and several window managers (such as twm). The application programmer links the client program through Xlib.Xlib is the main programmer's interface to X. Xlib is a low-level library providing access to X graphics and interface functions. Unlike most DOS-based graphics, however, these low-level routines don't directly munge the hardware. With the Xlib routines, you almost never directly interface to the underlying hardware. While this may not seem optimal for performance, it does provide X's much-vaunted portability.
Xlib provides functions and macros for drawing lines, creating windows, displaying text and defining colors. Xlib hides most of the gory details of connecting with an X server and maintaining network links.
Xlib contains about 300 routines that map to X Protocol requests or provide utility functions. Xlib converts C function calls to the X protocol request that actually implements the given function, such as XDrawLine to draw a line. These functions include creating, destroying, moving, and sizing windows; drawing lines and polygons; setting background patterns; and tracking the mouse. Xlib provides various ways to access windows, including overlapping and simultaneous output to multiple windows. It supports multiple fonts, raster opera- operations, line drawing, and both color and monochrome applications.
All of these features facilitate portability, so your program should work the same on a Sun workstation as it does on a IBM PS/2 running SCO Open Desktop. Above Xlib sit many X toolkits, such as Motif and Open Look.
X toolkits are collections of sub-routines that can make programming easier. They are prewritten graphics routines you can put together different parts to form a program. Different vendors are constantly revising toolkits.
These toolkits (after a steep initial learning curve) can speed the creation of X applications. Even if you plan on using toolkits exclusively, you will still need to understand how Xlib operates in order to create quality, commercial- grade X applications.
The X network protocol defines data structures used to transmit requests between clients and servers. The X network protocol is not based on procedure calls or a kernel-call interface. It is an asynchronous stream-based inter-process communication.
The X Consortium supplies the protocol specification on tape. X Window System Protocol (Version 11) by Robert Scheifler defines the protocol specification. X Window System Protocol is included with the distribution tape. It can be found on UNIX systems under ~TOP-LEVEL/mit/doc/Protocol/spec (TOP-LEVEL is the base of your X directory tree).
Obtaining X Window
If you're a workstation or UNIX user, you can easily obtain the X Window System free, and you don't need to license X or pay royalties.You can obtain the X Window system directly from MIT, through Internet and UUCP, and from commercial consulting firms and vendors.
MIT sells X on a set of four 1,600bpi tapes in UNIX tar format. A book (X Window System: The Complete Reference to Xlib, X Protocol, ICCCM, XLFD) and manuals sell for $125. Tapes, book, and manuals sell for $400. If interested, write to:
MIT Software Distribution Center
Technology Licensing Office, room E32-300
77 Massachusetts Ave.
Cambridge, MA 02139
617/258-8330 (the "X Ordering Hotline")If you're on Internet or UUCP, you can retrieve the release from the locations shown in Table 1.
The FTP directories contain a README file with further instructions. (We don't have room to print the README file, but you should persue that file before proceeding.)
For DOS or PC users, implementing X means purchasing it from a commercial vendor. Many UNIX vendors support X Window. SCO, for instance, offers X Window and Motif as part of its Open Desktop software. Interactive Systems provides X Window and Motif as part of 386/ix. Apple Computer integrates X Window and the Macintosh operating system in v2.0 of A/UX. Hummingbird Communications (416/470-1203) sells HCL-eXceed, a family of X servers for DOS-based PCs. XVision (Visionware; sold through UniMarket 800-222-0550) displays both DOS and X Window applications on a PC. PC-XView (again through UniMarket) turns a PC into an X Window terminal.
Details regarding Desqview/X from Quarterdeck have been floating around for months. We haven't seen the product, but it appears to be an interesting marriage of X and DOS. Integrated Inference Machines (714-978- 6776) offers X11/AT, a marriage of MS-Windows and the X Window System.
You can also obtain X Window from consulting firms:
Integrated Computer Solutions
163 Harvard St.
Cambridge, MA 02139
617-547-0510
info@ics. com; uunet!ics.com!infoO'Reilly and Associates
632 Petaluma Ave.
Sebastopol, CA 95472
800/338-6887In addition, the following workstation and software vendors include the X Window System in their products: AT&T, Apple, Bull, DEC, Data General, Everex, Hewlett-Packard, IBM, IXI Limited, Intel, Interactive Systems, Motorola, NCR, Open Software Foundation, SCO, Solbourne, Sony, Sun Microsystems, Visix, and many more every day.
Information On Programming With X
These books are geared toward programming in X Window, and specifically Xlib. During this series of articles, we'll mention other books tied to specific topics. X beginners may want to start with any of the books on the following list. The easiest way to learn X programming is by doing it, so have fun.Johnson, Eric F. and Kevin Reichard, X Window Applications Programming, MIS: Press, Portland, OR, 1989. ISBN 1-55828-016-2.
Johnson, Eric F. and Kevin Reichard, Advanced X Window Applications Programming, MIS: Press, Portland, OR, 1990. ISBN 1-55828-029- 4.
Jones, Oliver, Introduction to the X Window System, Prentice-Hall, Englewood Cliffs, NJ, 1989. ISBN 0-13- 499997-5.
Nye, Adrian, Xlib Programming Manual, Vol. 1, 2nd Ed., O'Reilly and Assoc., Sebastopol, CA, 1990. ISBN 0- 937175-11-0.
Nye, Adrian (ed.), Xlib Reference Manual, vol. 2, 2nd Ed., O'Reilly and Assoc., Sebastopol, CA, 1990. ISBN 0- 937175-12-9.
Scheifler, Robert W. and James Gettys, with Jim Flowers, Ron Newman, and David Rosenthal, X Window System: The Complete Reference to Xlib, X Protocol, ICCCM, XLFD, 2nd Ed., Digital Press, Bedford, MA, 1990. ISBN (Digital Press) 1-5558-050-5, (Prentice-Hall) 0-13-972050-2.