[Xcb] XNextEvent

Jamey Sharp jamey at minilop.net
Wed Jun 15 00:13:50 PDT 2005


On Wed, 2005-06-15 at 08:48 +0200, Vincent Torri wrote:
> > You should find that
> >
> >         XCBFlush(c);
> >         event = XCBWaitEvent(c);
> >
> > is sufficient. I don't see any other hidden semantics in XNextEvent.
> > Just remember that XCBWaitEvent can return X errors too.
> 
> Thank you ! So, to handle erros, should I use XCBPollForEvent instead ?

No, the point is that the response type may be 0 in the XCBGenericEvent
that you get back from either XCBWaitEvent or XCBPollForEvent. In that
case you need to cast it to XCBGenericError instead and process that.
You might also get a null pointer back from XCBWaitEvent, in which case
XCB encountered some internal error like an I/O error or running out of
memory.

> And, do you have some ideas for XPending ? I think it's the last thing
> that i have to translate for the ecore event loop.

I recommend a minor rewrite to the usual Xlib non-blocking event loop.

In Xlib you might write a loop like this:

        while(XPending(dpy))
        {
                XEvent *evt = XNextEvent(dpy);
                /* ... */
        }

For XCB you should write this instead:

        XCBGenericEvent *evt;
        while((evt = XCBPollForEvent(conn, 0)))
        {
                /* ... */
        }

(This example will raise SIGABRT if an I/O or memory error occurs. See
the documentation for XCBPollForEvent on the XcbApi page to see how this
function allows for proper error handling.)

XCB no longer provides any externally visible concept of an event queue,
so it has no XPending-like function that asks how long the event queue
is. (Internally it does still keep a queue, but if we can figure out how
to make that go away we might want to do so.)

This might be a good thing to add to your tutorial?

--Jamey



More information about the xcb mailing list