Monthly Columns
 

An Introduction to X

Copyright © 1998 Glenn Ramalho

With today's high availability of graphics capable stations windows based environments have become very valuable in aiding people to get their work done. Under UNIX, one of the most popular windows based systems is the X Window System. This makes it a must to learn how to use, but to understand this system we must look at a overall of how X works and the parts involved it it.


X server/X client

The X Window System can be separated in two parts, the X server and the X client. This differs from the definitions of 'server' and 'client' that you might have heard in other places, so let's push out the idea of the big central server and several little clients connected to them. These are the definitions of X's server and client:

  • X server - is the software that manages one display, keyboard and mouse. The display is the output device and it usually is one monitor, which X calls a 'screen', but it also can be a combination of 'screens'. This software is the only one that knows how to communicate to the hardware and therefore all requests to either the display, the keyboard or the mouse must be done through the X server.
  • X client - a program that talks to the X server to reach the user in some way. An example of an X client is xterm, a program which emulates a terminal under X. Anything the user types is read from the keyboard by the X server and then sent to the xterm program. This program then returns to the server what should be drawn on the screen. Other X clients are: xclock, xwininfo, twm and fvwm.

Users who are familiar with other windowing systems like NeXT Step, MacOS, SunView and Microsoft Windows, might notice that these systems are structured similarly to X. These other environments provide a graphical engine under which several clients can be started. Two main differences give X a lot of flexibility over several other systems. The first one, covered in the next section, is X's internal communication mechanism. The other one is X's user interface, which I will explain later in the Window Managers section.


Client/Server Communication: The X protocol


Other windowing systems typically provide some Application Programmer Interface (API) that handles getting messages between the different programs. The API is usually implemented using function calls and system calls. The engine then has direct access to the memory of the client. Depending on how this API operates, the system can work with little overhead. Unfortunately, these techniques usually constrain the communications to one computer as all the clients and the graphical engine share a set of local resources.


By contrast, X is based on an asynchronous network protocol. Any time an X server needs to send a message to an X client, the client must prepare a bit stream with details of what needs to be done. The same occurs in the opposite direction. If an X client needs its window updated on the screen, for example, it must generate a message with exactly what changes must be made. This message is then sent via the X protocol to the server that then interprets and processes the request. This encoding and decoding of messages adds some overhead to the system, but it is usually quite low. The major advantage is all communication is done through a networking protocol, so X clients are already network ready without special extra work from the programmer. X tries to hide the idea of multiple machines by moving towards a distributed environment.

Let's take a network with five machines as an example:

A - a FreeBSD system with a display, keyboard and mouse.

B - a SPARCserver 1000 running Solaris 2.x also with a display, keyboard and mouse.

C - an Envizex X terminal with a display, keyboard and mouse.

D - a large NFS server built by Auspex Systems running SunOS 4.1.4 but without a display, keyboard and mouse.

E - A Macintosh running OpenBSD with a display, keyboard and mouse.


No two computers are binary compatible. A program compiled on B, for example, will not run on E as their processors are different. All these computers are using the X Window System. A, B, C and E all have a monitor, a keyboard and a mouse, so they all must run local X servers. D does not have a display, keyboard and mouse so it cannot run an X server.


Here are four examples to illustrate how X communications work:


(1) An X client interacting with a local X server:

An xclock, an X client which displays an image of a clock, started from either A, B or E can send its output to the display on the same machine. For this case, xclock on A talks to the X server on A, the one on B talks to the server on B and the same applies to E. There is no interaction between the different computers. Note: although the X protocol is a network protocol X uses OS specific resources to transmit messages within one computer without using a network interface. Exactly how this is done changes from one system to another, but this is transparent to the user.

(2) An X client interacting with a different X server:

Machine A can run xload, an X client which displays a graph of a system's load, and send the output to E. A's X client computes the load information on A and sends it directly to E's X server. The output then comes out on E's screen. There is no obvious difference between this method and running xload from E to its own X server, aside, of course, from the load information reported. Using this technique, system administrators can monitor several machines in from their offices even if these systems are in remote locations. They can have each machine start an xload or some other X based monitoring program and send its output to one screen.


Another case in which this might be useful is to get around binary compatibility software or licensing issues. Let's say there is a program that requires SPARC Solaris 2.x. The only Solaris 2.x computer is B. A is a common computer on some user's desk. Without a network based windowing environment, this user has to walk over to B, and run the program. This might not be easy if many people need to use this software and are in line for the machine to free up. With the X Window System A's user can telnet to B and run the program with the output set to A's screen. A does not need to be binary compatible with the software since B is processing the code.

(3) A system with X clients but no X server

Notice that in the previous case, A's X server had nothing to do with the interaction between A's X client and B's X server. A's screen did not change as its X server was not involved in the communication. This means that A's X server can be stopped without affecting the xload session in example (2). D can start an xload session on E's screen the same way. D does not have an X server, but it does not need one. An xload program on D can talk directly with E's X server the same way the one on A did. An example of a program that takes advantage of this is BudTool from Intelliguard Software, Inc, an X based backup management tool that can run on servers like D. This has allowed me to, from my office, manage tape backups for computers like D across the street.

(4) A system with an X server but no X clients

C is an X terminal. These systems have a reduced operating system that do not support regular users. They run an X server, but no local X clients, so an xload session on B can send its output to C's screen, but C can not run any X clients locally. Note: some X terminals also provide a few basic X clients as well but usually not enough to use them stand-alone.


Window Managers

The other difference between X and many other windowing systems is where the interface is processed. Under X, the X server does not handle the user interface. This task is performed by one of the clients, the window manager, that is responsible for setting up the aspect of the borders of the windows and any pop up menus that may come up when you click on the root window - the space on the screen behind the other X clients. Other common tasks handled by the window manager include starting other X clients, moving, rearranging and switching between X programs. Some window managers also provide an area on the screen with a set of icons that start different X clients by clicking on them.

You may only have one window manager running on each X server at a time. This X client usually is on the same computer as the X server but this is not required. In particular, the X terminals use a remote window manager. There is nothing wrong with a user using one window manager for some time and then switch over to another one on the same X server.

Each X distribution comes with a set of window managers. If you do not like them, there are also several third party ones, both commercial and free. Find something you feel comfortable and use it. Some of the commercial distributions X come with a small set of window managers that they consider standard. As Prof. Jose' Fortes, one of my professors in college once told me: "The nice thing about standards is there are so many to choose from", (orig. author is Andrew Tannenbaum -- ed.) so this list varies quite a bit. If you use a lot of commercial software, you might want to check with any companies that you have support contracts with to make sure they do not require a specific window manager to be used. To reduce their work, some commercial software vendors will not provide technical support to users that do not use specific window managers. Incompatibilities between X programs and the window manager are rare but they do occur.

A wide selection of window managers is available. Each provides its own look and feel and list of features. Some window managers can get an X session look like other windowing environments, like NeXT Step, Plan 9, Windows 95, MacOS, etc. There are also window managers that specialized low memory usage, ease to use, high configurability, etc. Some popular window managers are: twm, vtwm, olwm, olvwm, fvwm, fvwm95, afterstep, dtwm, vuewm. Some come bundled in other larger packages while others are available separately. The NewHoo search engine provides several links to different window manager home pages and window manager comparisons. You also can search the Ports/Packages collection for FreeBSD, OpenBSD and NetBSD. All three provide extensive lists of window managers. If all this is not enough, there is a site (http://www2.osk.3web.ne.jp/~heuy/html3/index.shtml) with one of the largest lists of window managers I have ever seen. Unfortunately, this site is in Japanese. Even if you do not understand Japanese, you can still use the site to get screen shots and down load copies of the programs.


Libraries

To make the programmer's job easier, X comes with a set of libraries with functions that communicate with the X server. The Xlib library (libX11) is the most basic level and it is just enough to use X, which makes it cumbersome to program with. To make life easier for the programmers and help standardize the look of X programs, there are several other libraries, referred to as toolkits, that can be used in conjunction with Xlib. They contain functions that implement common tasks. Of course, it is possible to use Xlib directly, but that requires more effort and tedious, repetitive work. Some examples of common tool kits are the X toolkit (libXt), the Motif Toolkit (libXm) and the Tk toolkit (libtk).

Several libraries are available, each one with different features and short cuts. Some of them are commercial and others are freely available on the net. Most libraries are available both as static or as shared libraries. For precompiled binaries, you might need to install some of these shared libraries. Note that usually it is the X client, not the X server, that makes calls to these libraries, so they need to be on the same machine the X client starts up from.


Availability

A version of the X Window System is licensed by The Open Group to third party developers that distribute ports of the software together with their own work. For the free UNIXes, there are both commercial and free X distributions. Each one usually comes with one or more X servers plus a window manager and a few other basic X clients. The standard X libraries are also included.

The XFree86 Project, Inc. has an X package that is freely distributed and many times found bundled together with the installation CDs for the three free BSDs. S.u.S.E, GmbH provides a freely available enhanced X server developed jointly with The XFree86 Project, Inc. that runs on all three OSes. Metro Link, Inc. and Xi Graphics, Inc. also provide commercial versions of enhanced versions of the X Windows System for FreeBSD. You can purchase these versions with support contracts.

You can also run an X server or X clients on non-UNIX systems. Exceed is an X server from Hummingbird Communications Ltd. that runs on PCs under several versions of Microsoft Windows and Apple Macintosh computers running MacOS. MacX is an X server that Apple Computer, Inc. made for Macs. WinDD is an X client from Tektronix, Inc. that sends the output of Microsoft Windows NT based programs to any X server on any system including UNIX based systems.

The X clients and X libraries mentioned here are distributed either separately or incorporated in several versions of the X Window System. There is a set of window managers and other X clients that come with most X Window System distributions. There are several other files also available on the net. One of the popular places to find them is the X Consortium's ftp site. NewHoo also has a nice list on their XWindows page.

X clients are sometimes bundled in a package that includes a set of clients and libraries that work together. Common examples of these packages are the Common Desktop Environment (CDE) from The Open Group, OpenWindows from Sun Microsystems, Inc. and the K Desktop Environment (KDE). Xi Graphics provides a port CDE to the free BSDs for a price. OpenLook's window managers, olwm and olvwm, were ported to FreeBSD and can be found in the FreeBSD's ports collection. KDE was fully ported to all three UNIXes and it is distributed under the GPL. As the X clients come from different people they usually have very different sets of features and looks. To make X easier to use, the KDE developers are porting and are standardizing the apparence and features of many X tools.



The X Window System is an advanced windowing environment that works well over a network or on a single computer. Its portability and flexibility also make it very popular. X provides a modular system that gives the users freedom to modify different parts while maintaining portability between different systems. X is available for free. Some vendors also sell enhanced versions of X with technical support.

Glenn Ramalho, ramalho@best.com