Introduction

  • the X Window System is a software system for producing graphical user interfaces in a networked environment
  • X is based on a client/server architecture the server runs on a workstation, it produces the graphics and collects input from the keyboard and mouse the client program can run anywhere on the network, it performs the actual computation
  • X is a very large system and has been evolving over the years, there are many details, any many ways of doing even the simplest things
  • learning X can take a long time if you concentrate on all of the details
  • we will not look at all the details of X programming, skip a lot of the details, concentrate on producing user interfaces without a lot of work

Why Use X?

  1. Industry Standard – all Unix workstations support some version of X – possible to write highly portable programs in X
  2. Vast Amount of Support Software – a large amount of software has been written to support the development of X applications, makes programming somewhat easier
  3. Network Support – X works well in a distributed, networked environment, X programs can work with multiple workstations, easier to write distributed applications
  4. Customization – users can easily customize X programs, can change the default appearance and screen layout, etc
  5. Features – X has more features that any other window system
  6. Cost – X is free

Software Layers

  • there are basically four software layers in an X application
  1. X Protocol – this is the actual byte stream that goes between the client and the server
  2. Xlib – a C library interface to the X protocol
  3. Xt or Intrinsics – a C library for constructing and using Widgets, a collection of Widgets is usually called a toolkit
  4. Widgets – a collection of user interface abstractions, each widget is a separate interaction technique
  • most X programming occurs at the widget level, though occasionally routines are the Xlib level are required
		  +-----------------------------+
		  |      application            |
		  |                             |
		  +--------------+              |
		  |   Widgets    |              |
		  |              |              |
		  +--------------+----+         |
		  |   Xt Intrinsics   |         |
		  |                   |         |
		  +-------------------+----+    |
		  |         Xlib           |    |
		  |                        |    |
		  +------------------------+----+
		  |         X Protocol          |
		  |                             |
		  +-----------------------------+

Terminology

  • there are a large number of terms in X programming, we will start by defining some of the important ones, some of them we will come back to later to fill in the details

Window

  • the basic unit in an X program, and abstraction of a terminal a window provides a place to draw graphics and collects input from devices
  • the important properties of windows are:
    1. parent all windows have a parent window, the windows in an application form a tree, a window must lie within the coordinate space of its parent
    2. window ID an integer that identifies the window, this is a server resource, several processes can refer to the same window using its ID
    3. position the location of the upper left corner of the window within its parent’s coordinate system
    4. width, height and border width, the width is the size of the window in the x direction, the height is the size of the window in the y direction, and the border width is the width of its border, all measured in pixels
    5. coordination system each window has its own coordinate system. The origin is in the upper left corner, x increases to the right, y increases towards the bottom, coordinates are integers and correspond to pixels
    6. attributes, there are many of these, including background colour, border colour, cursor, colourmap, etc
    +---------------------------------------++-
    |+--------------x increasing            ||
    ||                                      ||
    ||                                      ||
    ||    parent window                     ||
    ||                       child origin   ||
    ||                                      ||
    ||                                      ||
    ||              +-----------------+     ||
    |y increasing   |                 |     ||
    |               | child window    |     ||
    |               |                 |     ||height
    |               |                 |     ||
    |               |                 |     ||
    |               |                 |     ||
    |               |                 |     ||
    |               |                 |     ||
    |               +-----------------+     ||
    |                                       ||
    |                                       ||
    |                                       ||
    |                                       ||
    |                                       ||
    +---------------------------------------++-
    +---------------------------------------+
    |                 width                 |

2) Widget

  • a widget is a user interface abstraction, it implements some part of a user interface, for example menu, scrollbar, button, text entry, etc
  • each widget has a window where it displays its information, it also reacts to user actions, such as the mouse and keyboard
  • a widget is like an abstract data type, or an object in an object-oriented system
  • most X programming deals with widgets

3) Resources

  • a resource is a named piece of data, usually part of a widget
  • the user or application can set the value of a widget, the application can also retrieve resource values
  • resources are mainly used to control widgets, all the important properties of a widget are resources

4) Callbacks

  • a callback is an application procedure, has a particular format
  • a callback is called when something happens in a widget, for example, when a button is pressed, or a scrollbar is moved
  • this is the main communications mechanism between widgets and the application
  • X has control of the application, all application computing occurs through callbacks

5) Translations

  • translations specify how user events (button presses) are processed
  • for each widget you can specify what a button press “means”, the procedure that will be executed when the action occurs
  • this gives the user more control over the application

6) Widget Classes

  • all widgets belong to a widget class, all the widgets in a class have the same basic appearance and behave in the same way
  • like objects and classes in object-oriented programming
  • the class defines the widget, when a widget is created the widget class is used to specify the type of widget to be created
  • widget classes are organized into a hierarchy, each widget, except for the root (core widget) has a parent
  • a widget class inherits from its parent, it can inherit resources, appearance and behavior
  • in order to determine what a widget does you must know where its widget class fits into the widget class hierarchy

7) Widget Hierarchy

  • the widget instances also form a hierarchy
  • when a widget is created its parent instance must be specified, the widget instance is placed within its parent
  • the parent widget controls where the child widget is placed on the screen, and when it appears on the screen
  • the widget hierarchy is used in resource naming
  • the widget hierarchy is an important part of the user documentation for a X program, the user needs this information to customize the widgets

8) Widget Sets or Toolkits

  • widgets classes are collected into widget sets or toolkits, a set of widgets that work together, provide the basic functionality required to construct user interfaces
  • there are many widget sets, differ in appearance and some behavior, all have the same basic functionality
  • once you know one set, learning other is quite easy