22
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

Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

Embed Size (px)

Citation preview

Page 1: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

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

Page 2: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

Two Simple Examples ...

Page 3: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

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?

Page 4: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

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

Page 5: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

X Windows Architecture

Client

Server

request

event

response

2

Page 6: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

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

Page 7: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

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

Page 8: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

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

Page 9: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

Client Program Structure

Application

Xlib

Motif

Xt Intrinsics

Page 10: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

Xlib and Toolkits

Windows, Graphics, colour etc.

“Designer” Widgets

Widget basics and event processing

Page 11: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

Example 1

Page 12: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

•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:

Page 13: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

Example 2

Page 14: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

•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:

Page 15: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

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

Page 16: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

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.

Page 17: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

Recap - 2

•Widget CreationDestroy Managing (and Mapping)

•Callbacks and Event Handlers

•Also …XmStringsColormaps

Page 18: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

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()

Page 19: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

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.

Page 20: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

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 ;

Page 21: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

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

together with a Makefile, is available from the

CM212 / CM304 web page

Sample source code

Page 22: Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like

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 ...