Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review...

Preview:

Citation preview

Building X Window GUIs with Motif

The X Window System:

Architecture

Applications

Sample code

Review function (as time permits)

… Introduce what it’s like to build Motif applications, not a comprehensive course ...… No advice on HCI design

Two Simple Examples ...

The X Window System

Developed at MIT; supported by DEC

Now an industry standard, controlled by the X Consortium, for developing portable GUIs

Available on most UNIX systems

Philosophy of device independence and freedom from any particular style

… History?

X Windows Architecture

Application (client) Display (server)

Server handles all input and outputClient requests action to a window

Communications obey the X protocol

The terms display and server are equivalent for XServer can be an X-station

can also be remote

Display is not just a single screen

Keyboard and mouse are also handled by the server

1

X Windows Architecture

Client

Server

request

event

response

2

Almost all client requests involve windows

Window concept much as in other systemsHierarchical organisation

Windows do not have to be visible all the timeMay be obscuredWindow - or an ancestor -

may not be mapped

X Windows Architecture 3

X Windows Architecture

Device independence means a client need not be concerned with the hardware on the server

The application designer determines the user interface style

•No specific “look and feel”

•No enforcement of any particular policy

•“Mechanisms” for generating a variety of styles

4

5X Windows Architecture

Application programs use three levels of interface, the lowest being Xlib.

Commonest Xlib interface is in CPrograms can be large and difficult

Most programs use higher-level toolkits:

X Toolkit - Intrinsics layer

Widget set - e.g. Motif

Window Managers - e.g. Mwm - clients that manipulate windows

Client Program Structure

Application

Xlib

Motif

Xt Intrinsics

Xlib and Toolkits

Windows, Graphics, colour etc.

“Designer” Widgets

Widget basics and event processing

Example 1

•Sample code - 1 : Creating PushButton

•Sample code - 2 : Setting colour

•Sample code - 3 : Application setup (1)

•Sample code - 4 : Application setup (2)

•Sample code - 5 : Callback code

See XMotifCode.doc (pages 1-5) for:

Example 2

•Sample code - 6 : Application setup

•Sample code - 7 : Set / Get Resources

•Programming Model : Basic functions

•Programming Model in Example 1

•Recap - 1 : Widgets

•Motif Widgets : /usr/include/Xm

•Widget Resources

See XMotifCode.doc (pages 6-12) for:

The X Resource Manager

… enables users to customise applications, because the programmer does not (always) get the user interface appearance or behaviour right!

•The resource database comprises information about the resources used in the application.

•It can also hold application-level resources.

•The Resource Manager has type converters:

e.g. String to Fontstruct

Matching Rules

X11cases*fontListapplies to all XmStrings

X11cases*button.fontListapplies to the PushButton(s)

X11cases.topForm.container.button.fontListis explicit

“Application programmers should avoid specifying widget resource values in the program except where absolutely necessary to ensure that the application works correctly” - Douglas Young.

Recap - 2

•Widget CreationDestroy Managing (and Mapping)

•Callbacks and Event Handlers

•Also …XmStringsColormaps

Managing Widgets

Parents manage their children !Size, location, mapping, input focus

Examples used:XtVaCreateManagedWidget()Convenient but not always the best way

XmRowColumn is a Manager widget, whichwill organise its children.Example 2 forces a rearrangement

XtCreateWidget() & XtManageChild()

Callbacks and Event Handlers

Event Handlers are procedures called when a specified event occurs within a widget.

e.g. ButtonRelease

Callbacks are procedures called when a specified condition occurs within a widget.

e.g. PushButton activate

Both receive clientData from the application;Callbacks also receive callData.

Processing clientData

void quitCallback( Widget w, XtPointer clientData, XtPointer callData ){ AppCtl * ctl = (AppCtl *)clientData ; ...

Often need to access more than one item ...Temptation is to use global variables.Better to encapsulate application variables.

typedef struct _AppCtl{ XtAppContext context ; Display *display ; Colormap colormap ; Widget top ;} AppCtl ;

Source code for the two examples:eg1.ceg2.c

together with a Makefile, is available from the

CM212 / CM304 web page

Sample source code

Reading and Reference Books

The X Window SystemProgramming and Applications with Xt OSF/Motif Edition

Douglas A Young, Prentice-Hall

The O’Reilly Books …X Protocol Reference Manual: Volume 0Xlib Programming Manual: Volume 1Xlib Reference Manual: Volume 2X Toolkit Intrinsics Programming Manual: Volume 4X Toolkit Intrinsics Programming Manual,

Motif Edition: Volume 4M

X Toolkit Intrinsics Reference Manual: Volume 5Motif Programming Manual: Volume 6A Motif Reference Manual: Volume 6B

… and there are many others ...

Recommended