[Xcb] How can I emit X replies as events from a main loop with no cookies?
robert at sixbynine.org
Mon Jun 2 16:10:45 PDT 2008
I've been using the XCB protocol descriptions to write/generate some
experimental glib/gobject bindings for X on top of the XCB api, but have
got a bit stuck with how I want to relay replies and events back to an
application, and hope someone can help me.
So far I'm basically generating the following gobject classes where X
requests become methods of the most appropriate class:
GXConnection - the catch all bucket
I want to translate X events into signals against a GXWindow, and
I want to support 3 mechanisms for handling replies and errors:
1) I'm exporting a simple xlib style synchronous API where functions
simply send a request and immediately block until a reply comes back.
rationale: I think much of the time it's good enough to work like this
and code is just that much simpler to read and write.
2) XCB's cookie based approach of deferring reply retrieval until the
moment you need it.
3) main loop event based dispatching of replies. (Where I'm stuck)
To implement 3) I essentially want to use xcb_get_file_descriptor to get
me a fd that I can use to create a new main loop event source (via
poll()) and when I know there is data to read, I want to have XCB parse
it by calling _xcb_in_read() (not currently exported from libxcb) and
sequentially iterate the corresponding data structures by calling in to
retrieve them from xcb.
If poll() says there is something to read I believe it can only be one
of three things, 1) an event, 2) a reply 3) an error.
I can identify events by calling xcb_poll_for_event() and also get back
a pointer to the event so I can dispatch it as a gobject signal.
The problem seems to be that the corresponding xcb_poll_for_reply needs
a sequence number that identified a specific request.
It seems that makes sense when the sequence can be taken from a cookie,
but in this context I don't have a cookie nor mind what sequence number
the replies/errors correspond to, I just want to access them in order so
that I can dispatch them as events. I think I essentially want a
xcb_poll_for_any_reply(), but I can't see that such a thing already
I had thought that I could potentially store a list of pending sequence
numbers that I can iterate with xcb_poll_for_reply, but that seems
rather yukky to me.
ok, I hope that made sense. In summary I wonder what you would think of
exporting _xcb_in_read and possibly adding a new xcb_poll_for_any_reply
Otherwise, maybe I've overlooked something, or you can give some
different ideas for how to make this work?
thanks for any time,
More information about the Xcb