[cairo] Cairo and multiple X11 windows

W.Boeke w.boeke at chello.nl
Thu Jul 31 14:38:56 PDT 2008

Carl Worth wrote:
> On Thu, 2008-07-31 at 18:34 +0200, W.Boeke wrote:
>> A normal application with a GUI may contain hundreds of small windows.
>> If I want to place text in these windows using Cairo, am I supposed
>> to instantiate a surface and a context for each individual window?
>> And if so, must I use cairo_set_source_rgb(), cairo_select_font_face()
>> and cairo_set_font_size() for each context? 
> Yes, that's what you would do.
>> I suppose that I missed something, cause this can't be true ...
> I don't see why not. Are you running into some practical problem with
> this kind of approach?
> Note that many modern toolkits don't use the "hundreds of small windows"
> approach with X at all. It's mostly just one window these days. And that
> approach does work better, (makes things like smooth window
> layout/resizing actually feasible for example).
An example of a (rather) modern toolkit is e.g. FLTK, which is used for
a lot of projects. Here every button, every canvas is instantiating its
own window. An that is a good thing, because X-windows is designed to be
used this way. E.g. if a parent window contains a lot of subwindows, then
during a redraw of the parent window only the rectangular area's between
the subwindows are redrawn. This is fully automatic, your program does
not have to care for that.
X-windows works with 'graphic contexts', containing data for fonts, colors
etc. These objects need to be assigned only once and can be used by each
procedure that needs them.
Also the widely used Xft anti-alias text rendering library is organized
this way.

> But I wouldn't anticipate any real problem from using cairo with a
> toolkit/application that does use many windows.

I think there will be a performance problem, e.g. a statement like
will be executed very often, with each time a search in a font database for
the string "Georgia".

Is someone who reads this a designer of a 'modern' toolkit, using only one
window? How do you implement all those different buttons, sliders and menu's?


More information about the cairo mailing list