220 likes | 244 Views
Learn how to build Motif applications for X Window Systems. Dive into X Windows Architecture, Motif widgets, event handling, and resource management. Includes code examples and references for further learning.
E N D
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
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 1 Application (client) Display (server) Server handles all input and output Client requests action to a window Communications obey the X protocol The terms display and server are equivalent for X Server 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
X Windows Architecture 2 Client request response Server event
X Windows Architecture 3 Almost all client requests involve windows Window concept much as in other systems Hierarchical organisation Windows do not have to be visible all the time May be obscured Window - or an ancestor - may not be mapped
X Windows Architecture 4 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
X Windows Architecture 5 Application programs use three levels of interface, the lowest being Xlib. Commonest Xlib interface is in C Programs 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 Motif Xt Intrinsics Xlib
Xlib and Toolkits “Designer” Widgets Widget basics and event processing Windows, Graphics, colour etc.
See XMotifCode.doc (pages 1-5) for: • 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 6-12) for: • 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
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*fontList applies to all XmStrings X11cases*button.fontList applies to the PushButton(s) X11cases.topForm.container.button.fontList is 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 Creation Destroy Managing (and Mapping) • Callbacks and Event Handlers • Also … XmStrings Colormaps
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, which will 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 ;
Sample source code Source code for the two examples: eg1.c eg2.c together with a Makefile, is available from the CM212 / CM304 web page
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 0 Xlib Programming Manual: Volume 1 Xlib Reference Manual: Volume 2 X Toolkit Intrinsics Programming Manual: Volume 4 X Toolkit Intrinsics Programming Manual, Motif Edition: Volume 4M X Toolkit Intrinsics Reference Manual: Volume 5 Motif Programming Manual: Volume 6A Motif Reference Manual: Volume 6B … and there are many others ...