2. Concepts in X Programming


You have seen in the last section that X is a networking windowing system which is device and operating system independent. This means that when we program in X, we can choose the user interface style of our choice and run programs on one machine while the display is on another machine.

In this section, we will find out the different application interface styles available, learn about X architecture and how to set the environment variable to determine the display of our application:

Interface Styles
Clients and Servers
Choosing the Display



2.1. Interface Styles

When we write our applications, it is up to us, the programmer to choose the look and feel of the program for ourselves. This was a deliberate design choice made by MIT and is one reason why X windows has become a standard (vendors would refuse to use a standard if it forced you to use the enemies interface).

In a commercial setting you will probably choose either to follow the


 
  Open Look style - on Sun workstations or
  Motif - on most other vendors workstations




In each case you will then be able to use a tool kit which will provide you with facilities to create windows, menus, buttons, etc. We will look at



 Xlib - the low level X routines
 Xt   - the Intrinsics Toolkit
 Xaw  - the Athena Widgets and
 Xm   - the Motif widgets






2.2. Clients and Servers

In X Windows we tend to talk about X client's and X servers.

An X server, or display, is the controlling program that talks to the graphics hardware, the keyboard and mouse. This is the program that you request to display windows, draw lines, and provide keyboard or mouse events. A display can consist of multiple screens, linked together by the keyboard and mouse. As long as a single user is limited to a single workstation, the multiple screens constitute a single display.

The server :



  1.  Allows access to the display by clients.
  2.  Does two-dimensional drawing, freeing up the client from
      processor intensive graphics.
  3.  Keeps track of resources (such as windows, cursors, fonts
      and graphics contexts) that are shared between clients.
  4.  Allows distributed processing




The application programs that make requests to the server (eg for windows to be displayed, for a line to be drawn) are known as X clients. The client and the server may communicate via inter process communication or a network library. The actual process used for communication is transparent to the applications.

While the above definitions of the client and the server seem reasonable in the above context, in practice many people get confused. You may be running a program on a Cray and displaying it on the NCD X terminal on your desk. In this case the application running on the Cray is the X client and the process running on your NCD X terminal is the X server. The confusion arises when people start being lazy and calling the Cray the X client and the terminal the X server, rather than referring to the processes running on each.


2.3. Choosing the DISPLAY

The DISPLAY environment variable is used by the client to find out which server to connect to. (Your program can specifically request a particular server, but normally will just specify NULL. When this happens, the value of the DISPLAY environment variable is used to determine the server to connect to). The format of the DISPLAY variable is as follows:



  hostname - `the network name of the machine which is running
    the desired X server, eg lust. For TCP/IP networks you can
    also use the Internet address, eg. 134.7.1.5'
  special character - `a separator character, usually a colon,
    which indicate what kind of network connection to use. One
    colon indicates ethernet, while two colons indicate DECnet.'
  X server # - `the number of the X server on the display node.
    In theory you could have many X servers running. In practise,
    I have not seen this situation. Usually you wish to connect
    to the first server which is number 0, eg. lust:0'
  screen number - `if the server is controlling more than one
    screen you will need to specify which screen you wish to
    display on. If there is only one screen you do not need
    to specify this number.'



You will find that most vendors will tend to just use the DISPLAY environment variable to determine the display of their applications. This is certainly the case with Sun and Silicon Graphics. One exception to this rule is IBM. With IBM's AIX applications you have to specify a -display lust:0 command line parameter.