oh boy, Xlib is a can of worms. The fact that is pollutes the namespace with things like "Window", "Display" and "Bool" annoys me enough ;)
But the multithreaded stuff is where it gets hard.
To answer your question, look at "XPending" it will read more events from the socket connection and return to you the number of events in the queue. If you do not wish to block:
1. call "XPending" and store the count in a variable
2. Then loop until you have exhausted the queue with "XNextEvent".
3. Then Repeat until "XPending" returns 0.
Also XNextEvent will never return if it is called when no windows exist. So make sure you only call it when you have a Window that is subscribed with "XSelectInput". By using XPending how I listed above, it will prevent this from becoming a reality.
Hope this helps :)
| int count = 1;
XEvent xe;
while (count) {
count -= 1;
if (count == 0) {
count = XPending(display);
if (count == 0) break;
}
XNextEvent(display, &xe);
// process xe here
}
|