XIfEvent(3)

πŸ’… XIfEvent(3) β€” event queue check with a predicate, bestie ✨

okay so this page is from XLIB FUNCTIONS, and it’s all about XIfEvent, XCheckIfEvent, and XPeekIfEvent β€” three functions with main-character energy for checking the event queue with a predicate procedure. no cap. 🫢

🌸 NAME 🌸

XIfEvent, XCheckIfEvent, XPeekIfEvent β€” check the event queue with a predicate procedure. periodt. πŸ’…

✨ SYNTAX ✨

int XIfEvent(Display *display, XEvent *event_return, Bool
       (*predicate)(), XPointer arg);

Bool XCheckIfEvent(Display *display, XEvent *event_return, Bool
       (*predicate)(), XPointer arg);

int XPeekIfEvent(Display *display, XEvent *event_return, Bool
       (*predicate)(), XPointer arg);

πŸŽ€ ARGUMENTS πŸŽ€

  • arg β€” this is the user-supplied argument that gets passed to the predicate procedure. iykyk.
  • display β€” the connection to the X server. iconic, essential, we love her. πŸ’–
  • event_return β€” returns either a copy of, or the matched event’s associated structure. yes bestie, it’s giving β€œhere’s your event.” 🎁
  • predicate β€” the procedure that gets called to decide if the next event in the queue matches what you want. vibe check: event edition. πŸ”₯

πŸ’– DESCRIPTION πŸ’–

okay so XIfEvent completes only when the specified predicate procedure returns True for an event, which means an event in the queue matches. XIfEvent flushes the output buffer if it blocks waiting for additional events. then it removes the matching event from the queue and copies the structure into the client-supplied XEvent structure. slay. ✨

when the predicate procedure finds a match, XCheckIfEvent copies the matched event into the client-supplied XEvent structure and returns True. (this event is removed from the queue.) if the predicate procedure finds no match, XCheckIfEvent returns False, and the output buffer will have been flushed. and listen β€” all earlier events stored in the queue are not discarded. they stay. periodt. πŸ™ˆ

XPeekIfEvent returns only when the specified predicate procedure returns True for an event. after the predicate procedure finds a match, XPeekIfEvent copies the matched event into the client-supplied XEvent structure without removing the event from the queue. XPeekIfEvent flushes the output buffer if it blocks waiting for additional events. peek but don’t yeet. πŸ‘€πŸ’…

each of these functions 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. not me warning you dramatically, it’s just facts. πŸ’€

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. bestie, that’s a big lock-energy caveat. πŸ”’πŸ˜­

the predicate procedure and its associated arguments are:

Bool (*predicate)(Display *display, XEvent *event, XPointer arg)
  • display β€” specifies the connection to the X server. yes, again, she’s everywhere. πŸ’–
  • event β€” specifies the XEvent structure. the event in question, the moment, the main character. ⭐
  • 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. no cap, those are the rules. πŸŽ€

note that the predicate procedure is called with the display locked, and thus is not allowed to call any function that would take the display lock again. 🚨

πŸ¦‹ SEE ALSO πŸ¦‹

πŸ’Œ footer tea, served fresh: X Version 11, libX11 1.8.14 β€” source/version noted, bestie. slay and goodbye 🫢✨

πŸ“¦ where this page comes from