THE X WINDOW SYSTEM
CS-360, Last Week of Class
R. Eckert

INTRODUCTION--

   An industry standard software system permitting development of
   portabable graphical interfaces for networked workstations. A
   specification and implementation for a window system.

Developed jointly by MIT's:

        Technology Laboratory for Computing Science

        Project Athena

Project Goal--

 Creation of better teaching tools using campus-wide network of workstations

 Should provide simulaneous access to many info sources in many formats

Funded initially by DEC and IBM

Work began in 1984

Built on earlier "W" system, Stanford (Paul Asente, Brian Reid)

Initial 10 versions mostly the work of: Robert Scheifler (MIT CS Lab)
                                        James Gettys (DEC)
                                        Ron Newman (Athena)

Version 10 released to public in 1985; first commercial implementation in
1986 (DEC on VAXstation II/GPX)

Provided a simple programming interface to windows and graphics.

Considered at the time to be "beta" software


Version 11 design work began in 1986 -- a major rewrite.

Tested by 100+ vendors and institutions, largest-ever software field test

X11 released in 1987

1988 -- X Specification and development turned over to MIT X Consortium

   An open union of computer vendors, universities, and other institutions

1993 X Consortium left MIT and became an independent, standalone company


Since its debut in 1986, X has been implemented on almost every type of
bitmapped graphics display.

First stable release was X11R2

Most recent release: X11R6


X FEATURES

  Independent of machine architecture and operating system

  Sources are freely distributed

  Graphics programming interface to X is the same on all platforms

  Programs running anwhere in a network can display on any workstation

  Multiple applications can display on a screen simultaneously (desktop)

  Programs running anywhere can "cut and paste" with other windows

  Applications can share access to windows and other screen resources

  Provides extensive programming libraries (new user interface tools)


THE X WINDOW SYSTEM: DETAILS--

Client-Server Model--

  X Display server:

    Single process manages workstation I/O devices

    Runs on workstation with graphics display

    Communicates with X Client applications over network

  X Clients:

    Apps that request server to display stuff

    Communicate with server using X-Protocol over a network

    Other software levels provide higher-level access to X-protocol


Client/Server Communication--

  REQUESTS--From client to server,
            about 100 types:

     Window manipulation (create, destroy, move, resize, etc.)

     2D graphics functions (draw line, circle, text, etc.)

     Resource allocation (fonts, colors, etc.)

     Event management

     Usually asynchronous

  REPLIES:

     Packets returned from server in response to a client request

     Usually synchronous with request (client waits for reply)

  EVENTS:

     Messages sent by server as direct or indirect result of user
     actions (usually input operations)

     Report something "interesting" has happened client may need
     to know about and respond to

     34 types:

       Keyboard input

       Locator (mouse) movement

       Input from locator (mouse) buttons

       Changes in window state, size, position, stacking order

       Changes in window properties

       Exposure of all or part of a window

       Selection (cut/paste) of info

       Messages sent by other clients

  Client indicates kinds of events it wants to receive by setting
  an event mask (each bit position corresponds to an event type)

  Requests and Events are queued. Server maintains Request and event
  queues for each client.


Server resources--

  Objects maintained by the server that can be used/shared by all
  clients. Include:

    Windows (most fundamental resource)

    Graphics Contexts (set of attributes)

    Fonts

    Cursors

    Color Maps

    Pixmaps (offscreen windows)


  Resource characteristics:

    Reside in server

    Client creates/uses/destroys them

    Identified by a resource ID assigned by server

    Can be shared among clients

    Created by one-way requests

    Ephemeral

    Cheap


A Window: the most fundamental X resource--

  A rectangular area of the screen

  Very simple--No decorations

  Possesses attributes and properties

  Combine with other windows to form higher-level interface objects

  Attributes/properties can be changed by a client request

  Organized into hierarchies called WINDOW TREES <show diagram>

  An app may have hundreds of windows

  Window tree properties

  Mapping windows

  Windows coordinate systems


Esposing a window--client has responsility of maintainig (redrawing) its
contents


WINDOW MANAGER--

  An application (client) that is permitted to manipulate other clients'
  windows.

  Many available window managers--twm, mwm, etc. Each has its own "look
  and feel".


PROGRAMMING AN X APPLICATION USING XLIB--

  A. Initialization:

    1. #include <X11/Xlib.h>
       #include <X11/Xutil.h>

    2. Declare variables

    3. Set up a connection to the workstation --> a display

    4. Get a screen from that diplay to draw on

    5. Create a window

    6. Inform window manager of desired windows properties

    7. Create other resources (e.g., a graphics context)

    8. Map window to screen (make it visible)

  B. Event management

    9. Tell server kinds of events of interest (event mask)

    10. Event loop:

         While there are more events
           Read, interpret, and take action on next event
           (Graphical output can take place here)

  C. Termination

    11, Destroy resources

    12. Close display

    13. Exit


Compilation--

  If libraries and include files are in the "standard" place
  (/usr/lib and /usr/include/X11), compile with:

     cc pgm_name.c -o pgm_name -lX11

  Will compile and link --> pgm_name executable

  On bingsuns, the include files are NOT in the right place, so
  compile with:

    cc pgm_name.c -o pgm_name -I/usr/openwin/include -lX11


Running the Program--

   If your program is to run on the same workstation that the 
   display server is running on, you just type in the executable
   name from an X Terminal session.

   If your executable is to run on one machine (e.g., remotely on
   bingsuns.cc.binghamton.edu) and your display server is running 
   on another machine--the machine you are sitting in front of (e.g.,
   xxx.cs.binghamton.edu), then you must do two things:

   1. before telnetting to the machine your program is to run on,
   enter the following from the local prompt:

   xhost +

   This tells the display server that any X client can connect to it.

   2. After telnetting to the machine where you program is, enter
   the following from the prompt:

   setenv DISPLAY xxx.cs.binghamton.edu:0.0

   (Here it is assumed that the machine where your program is has
   the specified address.) This sets the DISPLAY environment variable
   so that applications running on this client I/O will display on
   the specified X server.