[Xcb] Opening/closing (and resizing) many windows

Edder edder at tkwsping.nl
Thu Aug 4 12:36:58 PDT 2011


Hi,

>>> Finally, and most importantly, you can almost certainly avoid the
>>> problem by not rapidly closing and opening connections like your test
>>> program does. :)  You should maintain a single connection and use that
>>> for any X operations you want to do.
>>
>> I did at some point think that this might be the correct way of doing
>> things, but I couldn't find any examples of this.
>
> Pretty much every application ever does things this way.

I have now changed my library to do the same, and it has solved my problems :)

>
> The only applications I can think of that open multiple connections
> are (a) an ancient game that opens the different connections to
> different servers for multiple player support, and (b) collections of
> different applications that are presented to the user as a single
> application through the deceptive use of common UI elements.
>
>> I read the
>> documentation as implying that you need one connection per window.
>
> The implication is not correct. Which documentation?
>

I mostly looked at the tutorial:
http://www.x.org/releases/X11R7.6/doc/libxcb/tutorial/
and searched for simple examples on the web. Rereading it now it
indeed doesn't say anywhere that you would use multiple connections. I
guess it was unclear to me, because there are no clear multiple window
examples.

> In fact, you are encouraged to use as few connections as possible.
> There is a hard limit on the number of connections the server will
> accept. Especially in older servers, it's a small number like 128 or
> 256 (total, not per client, and many of those will already be in use
> by a modern desktop environment).

That is a lot lower than I would have expected. So basically you could
only have 128/256 programs open at the same time?

>> Also it will need a big refactoring of the code, since it will
>> suddenly need one main class in control of the connection, instead of
>> having each plot object in full control of its own window/connection
>> :(
>
> Multiple connections also makes resource cleanup easier. On the other
> hand, it makes resource (pixmaps/tiles, gcs) sharing amongst multiple
> windows much harder.
>
>> I have experimented a little bit with this and have two questions.
>> 1) Is there an easy way to see which event belongs to which
>> xcb_drawable_t,
>
> Every event (except I believe MappingNotify, a keyboard state event)
> has the xcb_drawable_t in it.

Thanks, that makes things a lot more straightforward.

>
>>  Related to that: will an expose/resize event by the window
>> manager always be send to the drawable in focus or can it be send to
>> the one in the background?
>
> Expose can be sent to any window at any time (and it's sent by the
> server). Window managers can resize any window at any time, not just
> the one in focus.
>

That makes sense.

>> 2) I noticed that if I closed one window, both windows will close. Is
>> there a way to not do this?
>
> If WM_PROTOCOLS/WM_DELETE_WINDOW isn't set, the window manager will
> close the entire connection. If it is set, it will send you a message
> and you are responsible for closing the window (or the entire
> application, if you prefer).
>
> See http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.2.7

I have managed to get this working (with great help from an older
message on the list). Weirdly though the documentation says that you
should get a ClientMessage, which I assume means that the
event->report_type should be XCB_CLIENT_MESSAGE. This didn't seem to
work and after some bug hunting I discovered that the
event->report_type that I got was number 161. Which seems to be an
undefined report_type.

>
> Peter Harris
>
Cheers,
Edwin


More information about the Xcb mailing list