11.4.2 Selecting Events Using a Predicate Procedure

Each of the functions discussed in this section requires you to pass a predicate procedure that determines if an event matches what you want. Your predicate procedure must decide if the event is useful without calling any Xlib functions. If the predicate directly or indirectly causes the state of the event queue to change, the result is not defined. If Xlib has been initialized for threads, the predicate is called with the display locked and the result of a call by the predicate to any Xlib function that locks the display is not defined unless the caller has first called XLockDisplay().

The predicate procedure and its associated arguments are:

Bool (*predicate)(display, event, arg)
     Display *display;
     XEvent *event;
     XPointer arg;
display Specifies the connection to the X server.
event Specifies the XEvent structure.
arg Specifies the argument passed in from the XIfEvent(), XCheckIfEvent(), or XPeekIfEvent() function.

The predicate procedure is called once for each event in the queue until it finds a match. After finding a match, the predicate procedure must return True. If it did not find a match, it must return False.

To check the event queue for a matching event and, if found, remove the event from the queue, use XIfEvent().

To check the event queue for a matching event without blocking, use XCheckIfEvent().

To check the event queue for a matching event without removing the event from the queue, use XPeekIfEvent().

Next: Selecting Events Using a Window or Event Mask

Christophe Tronche, [email protected]