XtAppNextEvent(), XtAppPending(), XtAppPeekEvent(), XtAppProcessEvent(), XtDispatchEvent(), XtAppMainLoop() - query and process events and input
void XtAppNextEvent (XtAppContext app_context, XEvent *event_return)
Boolean XtAppPeekEvent (XtAppContext app_context, XEvent *event_return)
XtInputMask XtAppPending (XtAppContext app_context)
void XtAppProcessEvent (XtAppContext app_context, XtInputMask mask)
Boolean XtDispatchEvent (XEvent *event)
void XtAppMainLoop (XtAppContext app_context)
If no input is on the X input queue, XtAppNextEvent(3) flushes the X output buffer and waits for an event while looking at the other input sources and time-out values and calling any callback procedures triggered by them. This wait time can be used for background processing (see Section 7.8).
If there is an event in the queue, XtAppPeekEvent(3) fills in the event and returns a nonzero value. If no X input is on the queue, XtAppPeekEvent(3) flushes the output buffer and blocks until input is available (possibly calling some time-out callbacks in the process). If the input is an event, XtAppPeekEvent(3) fills in the event and returns a nonzero value. Otherwise, the input is for an alternate input source, and XtAppPeekEvent(3) returns zero.
The XtAppPending(3) function returns a nonzero value if there are events pending from the X server, timer pending, or other input sources pending. The value returned is a bit mask that is the OR of XtIMXEvent, XtIMTimer, and XtIMAlternateInput (see XtAppProcessEvent(3)). If there are no events pending, XtAppPending(3) flushes the output buffer and returns zero.
The XtAppProcessEvent(3) function processes one timer, alternate input, or X event. If there is nothing of the appropriate type to process, XtAppProcessEvent(3) blocks until there is. If there is more than one type of thing available to process, it is undefined which will get processed. Usually, this procedure is not called by client applications (see XtAppMainLoop(3)). XtAppProcessEvent(3) processes timer events by calling any appropriate timer callbacks, alternate input by calling any appropriate alternate input callbacks, and X events by calling XtDispatchEvent(3).
When an X event is received, it is passed to XtDispatchEvent(3), which calls the appropriate event handlers and passes them the widget, the event, and client-specific data registered with each procedure. If there are no handlers for that event registered, the event is ignored and the dispatcher simply returns. The order in which the handlers are called is undefined.
The XtDispatchEvent(3) function sends those events to the event handler functions that have been previously registered with the dispatch routine. XtDispatchEvent(3) returns True if it dispatched the event to some handler and False if it found no handler to dispatch the event to. The most common use of XtDispatchEvent(3) is to dispatch events acquired with the XtAppNextEvent(3) procedure. However, it also can be used to dispatch user-constructed events. XtDispatchEvent(3) also is responsible for implementing the grab semantics for XtAddGrab(3).
The XtAppMainLoop(3) function first reads the next incoming X event by calling XtAppNextEvent(3) and then it dispatches the event to the appropriate registered procedure by calling XtDispatchEvent(3). This constitutes the main loop of X Toolkit applications, and, as such, it does not return. Applications are expected to exit in response to some user action. There is nothing special about XtAppMainLoop(3); it is simply an infinite loop that calls XtAppNextEvent(3) and then XtDispatchEvent(3).
Applications can provide their own version of this loop, which tests some global termination flag or tests that the number of top-level widgets is larger than zero before circling back to the call to XtAppNextEvent(3).
X Toolkit Intrinsics - C Language Interface
Xlib - C Language X Interface