简体   繁体   中英

Determining if there are events in the queue with X11/Xlib

I'm working on an X11 application and I'm trying to write a function that will process any events currently in the queue and then return without blocking.

All of the Xlib tutorials that I've found use XNextEvent in a perpetual loop which blocks on each XNextEvent call until an event is ready.

I have looked at XEventsQueued with QueuedAlready, which seems like it should return the number of events ready to be processed, but it always returns 0 even when I know there are events that can be retrieved with XNextEvent.

Am I missing something here, or is there another way to determine if there are events available in the queue?

Well it looks like if you just call XEventsQueued with QueuedAlready that the events are never read from the connection and put into the queue. Calling XEventsQueued with QueuedAfterFlush will flush the output buffer and then read any events available on the connection into the event queue. XPending does the same thing. QueuedAfterFlush or XPending is what I needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM