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

Peter Harris git at peter.is-a-geek.org
Wed Aug 3 05:32:06 PDT 2011


On Wed, Aug 3, 2011 at 5:43 AM, Edder wrote:
> On 2 August 2011 19:49, Jamey Sharp <jamey at minilop.net> wrote:
>
> I there anyway I could control the xids/wids xcb uses?

If you aren't using any libraries, you could write your own
replacement for xcb_generate_id. XIDs don't have to be used
sequentially from the base, it's just easier to write that way.

If you are using libraries... LD_PRELOAD your replacement
xcb_generate_id, maybe?

Either way, this isn't the right answer. See below about the hard limit.

>> 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.

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?

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).

> 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.

>  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.

> 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

Practically speaking, you probably want to be using a toolkit (such as
Gtk or Qt), which takes care of the ICCCM, EWMH, event routing, etc so
you don't have to.

Peter Harris


More information about the Xcb mailing list