Next: Pixmaps Up: XEvents Previous: XEvent Types

Writing Your Own Event Handler

Most Motif applications will not need to do this. If you do it can quickly become complex involving a lot of Xlib programming.

We do not want to dwell on this too much. The Xlib handouts go into this in some detail.

From Motif (or Xt) if you attach a callback to a particular event use the function XtAddEventHandler(), which takes 5 parameters:

- This can be used to allow the widget to be receptive to specific events. (See Handout for more details).
- A Boolean almost False. If it is set to True then it can be activated on events not specified in the Eventmask.
- the callback function.
Client Data

Two functions are typically used to intercept and control events.

XtAppNextEvent(XtAppContext, XEvent*) gets the next event off the event queue for a given XtAppContext application.

XtDispatchEvent(XEvent*) dispatches the event so that callbacks can be invoked.

Let us look at how the XtAppMainLoop() function is coded and how we can modify this for our purposes.

void XtAppMainLoop(XtAppContext app)

{ XEvent event;

  for (;;) /* forever */
    { XtAppNextEvent(app, &event);

      /* Xevent read off queue */
      /* inspect structure and intercept perhaps? */

      /* intercept code would go here */

Tue May 24 16:52:56 BST 1994