[cairo] Xlib and XCopyArea

Carl Worth cworth at cworth.org
Fri Feb 9 12:59:27 PST 2007

On Fri, 9 Feb 2007 10:41:10 +0100, "Olivier Jolet" wrote:
>   XSelectInput(dpy, window, ExposureMask|ButtonPressMask);
>   XMapWindow(dpy, window);
>   drawable = XCreatePixmap (dpy, rootwin, SIZEX, SIZEY, DefaultDepth
> (dpy, screen));
>   surface = cairo_xlib_surface_create (dpy, drawable, DefaultVisual
> (dpy, screen), SIZEX, SIZEY);
>   cairo_xlib_surface_set_size (surface, SIZEX, SIZEY);
>   paint(surface);             /* just draw un circle *
>   XCopyArea(dpy, drawable, window, gc, 0, 0, SIZEX, SIZEY, 0, 0);

So, I think you're just suffering here from the pain that Xlib
inflicts on almost all initial users. Specifically, you don't want to
try to draw anything to your window before it's mapped, and you also
need to draw to it in response to each expose event you receive.

So, the XCopyArea that you're doing should be moved to a function
that's responding to expose events.

Meanwhile, as Daniel suggest in his response, you do have the option
of replacing some of the above with cairo calls rather than directly
calling into Xlib. For example, the call to cairo_xlib_surface_create
could be replaced with cairo_surface_create_similar, (if you first
create a surface for the window), and the call to XCopyArea could be
replaced with cairo_set_source_surface;cairo_paint, (if you also
do cairo_create on the surface you create for the window).

But neither of those two changes would affect any expose-event
handling bug. And neither is strictly necessary.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20070209/2f4ba837/attachment.pgp

More information about the cairo mailing list