Created attachment 64019[details]
Small program replicating the bug
Drawing surface based patterns breaks when using non-default pattern matrix in Xlib backend. The same code works correctly in, at least, image backend.
If you have a 32x32 px pattern image, then in the following code, first two rectangles will have incorrect patterns.
pattern_surface = cairo_image_surface_create_from_png("pattern.png");
pattern = cairo_pattern_create_for_surface(pattern_surface);
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
cairo_matrix_t matrix;
cairo_matrix_init_translate(&matrix, 14.1, 0);
cairo_pattern_set_matrix(pattern, &matrix);
cairo_set_source(cr, pattern);
for (int i = 0; i < 8; i++){
cairo_rectangle(cr, i * 3.5, i * 32, 256, 32);
cairo_fill(cr);
}
The same code works correctly when using image backend.
I attached a small program replicating this bug. This program shows the output of Xlib backend in a window and saves the output of image backend into a file test.png

Wow, that is odd.
Can you add:
if (event->area.width == widget->allocation.width &&
event->area.height == widget->allocation.height) {
cairo_surface_write_to_png(cairo_get_target(cr), "out.png");
}
to on_expose_event() and attach your out.png? I just want to confirm that you are seeing the same oddity I am!