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.

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState