X/Motif Programming

And God said “Let there be light”!
Declaring Callback Functions

Callback functions have the following format:

void functionNameCallback (Widget w, XtPointer
client_data, XmPushButtonCallbackStruct *cbs)

The callback function parameters are:

  1. The first parameter of the function is the widget associated with the function (button in our case).

  2. The second parameter is used to pass client data to the function. It is not used in our sample program.

  3. The third parameter is a pointer to a structure that contains data specific to the particular widget that called the function and information on the event that triggered the call. The structure we have used is a XmPushButtonCallbackStruct, since we are using the PushButton Widget.

There are two final actions every Motif program must perform. First, it must tell X to display or realize the widgets. This is achieved via the XtRealizeWidget function; realizing the widget creates the actual window for the widget. In helloworld.c, we pass the top-level widget, topWidget, to the function so that all child widgets are displayed. Second, the Motif program enters the main event-handling loop; the call to XtAppMainLoop turns control of the application over to the X Toolkit Intrinsics. Xt handles the dispatching of events to the appropriate widgets, which in turn pass them to the application via callbacks.


This article was a mere introduction to the world of X/Motif programming. We've looked at a simple Motif program to introduce the basic concepts in building the graphical user interface. For more information, see Resources.

Naming Motif


Ibrahim Haddad (ibrahim@ieee.org) is a Ph.D. student in the computer science department at Concordia University in Montréal, Canada. Ibrahim was first introduced to Linux (0.99) and Motif at the Lebanese American University. Among his interests are e-commerce, web applications, distributed objects and helping his friends at LinuxLeb.com (Linux Lebanon).



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

how do i save this page?

Anonymous's picture

how do i save this page?

Funny cartoon.

Anonymous's picture

Yes.. But there is no god.