[cairo] cairo / xlib not updating window content

Cedric Roux sed at free.fr
Sun Jul 29 10:29:39 UTC 2018


Hi,

On 07/28/2018 09:50 AM, Pavel Petrovic wrote:
> I am trying to learn how to use Cairo 2D drawing library with xlib surfaces.

attached a version that "works" for me.

At https://cairographics.org/Xlib/ it is said you
need to call cairo_push_group and cairo_pop_group_to_source
(and also cairo_surface_flush, which I didn't add; it
works for me without it).

That said, keep in mind that the content of an X window
may vanish at any time. So all you did between XMapWindow
and the current time may be displayed, or not.

That's why your white background is there for one window
and not for the others.

There is the notion of "backing store" for X windows. The X
server may store content, but it's not guarantied (by default,
when calling XCreateSimpleWindow at least).

You should thus change your inner thinking of what an X window
is. This is not a buffer that keeps all what you plot into.
You should (must?) react to the Expose event and redraw dirty
the dirty area indicated by this event.

I don't know what your ultimate goal is, but maybe you want
to use X pixmaps (that keep their contents), draw cairo into
them and copy the pixmaps to the X windows whenever the content
is ready, instead of directly draw to X windows.

If you minimize your windows or put another window in front
of them, and then put the window back in front, depending on
the X server you use (and maybe also the window manager),
the hidden content will have been preserved or not.

Anyway, in short: X windows are very "volatile" creatures.
Do not assume the content you send there will survive long.
React to Expose event, and redraw the area that is invalid.
Use X pixmaps if you want some kind of permanent content.

Something like that.

HTH.
Cedric.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_cairo2.c
Type: text/x-csrc
Size: 14646 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20180729/d81a7e51/attachment.c>


More information about the cairo mailing list