Search code examples
cxlibxcb

Need for XEventsQueued(display, QueuedAfterReading) in XCB


I am migrating some code of CYBOI from Xlib to XCB.

CYBOI uses a couple of threads for different communication channels like: serial_port, terminal, socket, x_window_system. However, it uses these threads only for signal/event/data detection; the actual receiving and sending is done in the main thread, in order to avoid any multi-threading conflicts of address space.

For the x_window_system channel, I previously detected events in a thread:

int n = XEventsQueued(display, QueuedAfterReading);

Upon detection of an event, an "interrupt flag" was set. Afterwards, the main thread was reading the actual event using:

XNextEvent(display, &event);

When no more events were available, the main thread stopped receiving events and the x_window_system channel thread started listening with XEventsQueued again.

Now, I am migrating the code to X C Binding (XCB). There is a blocking function "xcb_wait_for_event" which is fine for reading an event. What I miss is some function "peeking ahead" if there are events pending, WITHOUT actually returning/removing the event from the queue.

I was reading the web for a couple of hours now, but am not able to find such a function. The "xcb_poll_for_event" does not help. Blocking is fine for me, since my event detection runs in its own thread. The "xcb_request_check" as third input function does not seem to be what I want.

Could somebody help me out?

Thanks, Christian


Solution

  • Are you looking for xcb_poll_for_queued_event(xcb_connection_t *c) which returns the next event without reading from the connection?