<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:12.800000190734863px">"Currently, Qt5 spawns </span><span style="font-family:arial,sans-serif;font-size:12.800000190734863px">a thread which just sits in xcb_wait_for_event() so that X11 events can get </span><span style="font-family:arial,sans-serif;font-size:12.800000190734863px">handled properly." This is sort of the intended way to use XCB for a program in which multiple threads touch the X connection. XCB supplies events in the simplest possible way, and applications can wrap whatever higher-level semantics they want. It seems to me pretty straightforward to implement the acquire/release semantics via thread IPC...</span><br>

<div><br></div><div style><font face="arial, sans-serif">I guess the issue is, as usual, interactions between library threads from different libraries, and interactions between library and client threads. Probably somebody needs to architect a convention for threads sharing an X connection, and then either modify XCB or layer on top of it to enforce this. I can think a little about what that might look like...</font></div>

<div style><font face="arial, sans-serif"><br></font></div><div style><font face="arial, sans-serif">--Bart</font></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 10, 2013 at 9:38 AM, Uli Schlachter <span dir="ltr"><<a href="mailto:psychon@znc.in" target="_blank">psychon@znc.in</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<div class="im"><br>
On 09.04.2013 06:14, Josh Triplett wrote:<br>
> On Mon, Apr 08, 2013 at 07:52:19PM -0400, Micah Nordland wrote:<br>
>> I believe this is what you are looking for:<br>
>><br>
>> int xcb_get_file_descriptor (xcb_connection_t *c)<br>
>>   Access the file descriptor of the connection. ]<br>
>><br>
>> Awesome WM currently uses this with glib, and in the past it used it with<br>
>> libev.<br>
>> bspwm uses this to do something similar to what you are doing.<br>
>> <a href="https://github.com/baskerville/bspwm" target="_blank">https://github.com/baskerville/bspwm</a><br>
><br>
> That does get a file descriptor referring to the X connection, but you<br>
> can't use that to wait for X responses without quite a bit of care,<br>
> because XCB might have some already read off the wire and stored in<br>
> internal buffers; thus, if you block on the X connection having data,<br>
> you might wait forever while XCB already has data to give you.<br>
<br>
</div>The following doesn't really help with Micah's issue directly, but it might make<br>
it possible to poll() the XCB fd for readability.<br>
<br>
There is currently a patch[0] for Wayland "in the pipe" which makes something<br>
similar possible. The (simplified) idea there is that there are two functions<br>
wl_display_acquire_fd() and wl_display_release_fd(). When a thread has acquired<br>
the fd, no other thread may read from it.<br>
<br>
This makes it relatively easy to integrate wayland into another main loop. In<br>
XCB-speak, before calling e.g. poll(), you would have to acquire the fd (and<br>
then check if there are any pending events?), call poll() and release the fd<br>
again afterwards.<br>
<br>
I am not 100% sure that the above description would really work for toolkits<br>
(can they really handle new events coming in while preparing for poll()?), but<br>
if would be great if something like this were implemented. Currently, Qt5 spawns<br>
a thread which just sits in xcb_wait_for_event() so that X11 events can get<br>
handled properly.<br>
<br>
Cheers,<br>
Uli<br>
<br>
[0]: <a href="http://lists.freedesktop.org/archives/wayland-devel/2013-April/008569.html" target="_blank">http://lists.freedesktop.org/archives/wayland-devel/2013-April/008569.html</a><br>
<span class="HOEnZb"><font color="#888888">--<br>
If you have to type the letters "A-E-S" into your source code, you're doing it<br>
wrong.<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
Xcb mailing list<br>
<a href="mailto:Xcb@lists.freedesktop.org">Xcb@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/xcb" target="_blank">http://lists.freedesktop.org/mailman/listinfo/xcb</a><br>
</div></div></blockquote></div><br></div>