xcb surfaces and expose events

Uli Schlachter psychon at znc.in
Mon Jun 23 18:29:56 UTC 2025


Am 23.06.25 um 18:14 schrieb Steven J Abner:
> This simple demo causes severe flashing.

 From the demo:

>   mask      = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
>   values[0] = screen->white_pixel;
>   values[1] = XCB_EVENT_MASK_EXPOSURE       | XCB_EVENT_MASK_BUTTON_PRESS   |
>               XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION |
>               XCB_EVENT_MASK_ENTER_WINDOW   | XCB_EVENT_MASK_LEAVE_WINDOW   |
>               XCB_EVENT_MASK_KEY_PRESS      | XCB_EVENT_MASK_KEY_RELEASE    |
>               XCB_EVENT_MASK_FOCUS_CHANGE   | XCB_EVENT_MASK_STRUCTURE_NOTIFY |
>               XCB_EVENT_MASK_PROPERTY_CHANGE |
>               XCB_EVENT_MASK_VISIBILITY_CHANGE;
> 
>     /* ignores x, y, border_width (virus) */
>   xcb_create_window(connection,
>                     screen->root_depth,            /* depth          */
>                     window,                        /* generated id   */
>                     screen->root,                  /* parent window  */
>                     configure.x,                   /* x, y           */
>                     configure.y,
>                     configure.w,                   /* width, height  */
>                     configure.h,
>                     0,                             /* border_width   */
>                     XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class          */
>                     screen->root_visual,           /* visual         */
>                     mask, values);                 /* masks */

Try removing `XCB_CW_BACK_PIXEL` from mask and removing `values[0]` all 
together. You are basically asking the X11 server for white flashing.

(Feel free to replace `screen->white_pixel` with other values. I would 
guess that a value of 0xff should give you... either red or blue 
flashes. I am not 100% sure about the pixel encoding that 99% of X11 
servers use. Yours might also use something entirely different and the 
flashes will end up with a different color.)

What is going on? Let's ask some docs.

 From [0]:

> When no valid contents are available for regions of a window and the regions are
> either visible or the server is maintaining backing store, the server
> automatically tiles the regions with the window's background unless the window
> has a background of None. If the background is None, the previous screen
> contents from other windows of the same depth as the window are simply left in
> place if the contents come from the parent of the window or an inferior of the
> parent; otherwise, the initial contents of the exposed regions are undefined.
> Exposure events are then generated for the regions, even if the background is
> None.

What this means in English: You are asking the X11 server to fill your 
window with white *before* sending expose events. This causes white flashes.

More details:

When your window becomes larger, there are some pixels that are newly 
part of your window. This is what the "When no valid contents are 
available" above refers to. The text then continues with "the server 
automatically tiles the regions with the window's background". This is 
the part that says "these pixels are painted white". At the very end it 
says "Exposure events are then generated", so all of this happens 
*before* any Expose events is generated.

By not setting a back pixel, the default values from [0] apply. For the 
background, that is a background-pixmap of None (background pixel and 
pixmap are mutually exclusive and so basically "the background is None" 
by default). The above quote then says "If the background is None, the 
previous screen contents [...] are simply left in place". So this means 
that, even though these pixels are now part of your window, they still 
contain whatever values they contained before. So, basically, no resize 
visible yet. Thus, you get a chance to fill these pixels with the right 
content via the Expose events.

Cheers,
Uli

[0]: 
https://www.x.org/releases/X11R7.7/doc/xproto/x11protocol.html#requests:CreateWindow

-- 
"Why make things difficult, when it is possible to make them cryptic
and totally illogical, with just a little bit more effort?" -- A. P. J.


More information about the cairo mailing list