diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c index 3813a679f..33d683329 100644 --- a/gdk/gdkwindow.c +++ b/gdk/gdkwindow.c @@ -5407,18 +5407,19 @@ _gdk_window_process_updates_recurse (GdkWindow *window, GdkWindowObject *private = (GdkWindowObject *)window; GdkWindowObject *child; GdkRegion *child_region; - GdkRectangle r; + GdkRectangle r, extents; GList *l, *children; if (gdk_region_empty (expose_region)) return; - /* Make this reentrancy safe for expose handlers freeing windows */ - children = g_list_copy (private->children); - g_list_foreach (children, (GFunc)g_object_ref, NULL); + gdk_region_get_clipbox (expose_region, &extents); - /* Iterate over children, starting at topmost */ - for (l = children; l != NULL; l = l->next) + /* Only the children the exposed area reaches: the others take + * neither region work nor references. The list holds references, + * so expose handlers can free windows. */ + children = NULL; + for (l = private->children; l != NULL; l = l->next) { child = l->data; @@ -5435,6 +5436,26 @@ _gdk_window_process_updates_recurse (GdkWindow *window, r.width = child->width; r.height = child->height; + if (!gdk_rectangle_intersect (&extents, &r, NULL)) + continue; + + children = g_list_prepend (children, g_object_ref (child)); + } + children = g_list_reverse (children); + + /* Iterate over children, starting at topmost */ + for (l = children; l != NULL; l = l->next) + { + child = l->data; + + if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child)) + continue; + + r.x = child->x; + r.y = child->y; + r.width = child->width; + r.height = child->height; + child_region = gdk_region_rectangle (&r); if (child->shape) {