gtkwidget: skip the child walk when a widget covers the expose

This commit is contained in:
Daemonratte 2026-10-16 14:09:16 +02:00
commit 242681544a

View file

@ -3757,31 +3757,39 @@ widget_add_child_draw_rectangle (GtkWidget *widget,
gdk_rectangle_union (rect, &child_rect, rect);
}
/* The allocation of a widget without a window, with its draw border */
static void
gtk_widget_get_own_draw_rectangle (GtkWidget *widget,
GdkRectangle *rect)
{
const GtkBorder *draw_border;
GtkRcPropertyParser parser;
GParamSpec *pspec;
*rect = widget->allocation;
/* this runs for every child at every expose: look at the
* value instead of asking for a copy of it */
pspec = style_property_lookup (G_OBJECT_TYPE (widget), "draw-border", &parser);
draw_border = g_value_get_boxed (_gtk_style_peek_property_value (widget->style,
G_OBJECT_TYPE (widget),
pspec, parser));
if (draw_border)
{
rect->x -= draw_border->left;
rect->y -= draw_border->top;
rect->width += draw_border->left + draw_border->right;
rect->height += draw_border->top + draw_border->bottom;
}
}
static void
gtk_widget_get_draw_rectangle (GtkWidget *widget,
GdkRectangle *rect)
{
if (!gtk_widget_get_has_window (widget))
{
const GtkBorder *draw_border;
GtkRcPropertyParser parser;
GParamSpec *pspec;
*rect = widget->allocation;
/* this runs for every child at every expose: look at the
* value instead of asking for a copy of it */
pspec = style_property_lookup (G_OBJECT_TYPE (widget), "draw-border", &parser);
draw_border = g_value_get_boxed (_gtk_style_peek_property_value (widget->style,
G_OBJECT_TYPE (widget),
pspec, parser));
if (draw_border)
{
rect->x -= draw_border->left;
rect->y -= draw_border->top;
rect->width += draw_border->left + draw_border->right;
rect->height += draw_border->top + draw_border->bottom;
}
gtk_widget_get_own_draw_rectangle (widget, rect);
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget),
@ -5321,6 +5329,22 @@ gtk_widget_region_intersect (GtkWidget *widget,
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_return_val_if_fail (region != NULL, NULL);
/* The children of a widget without a window draw within its draw
* rectangle too, which takes a walk through all of them to find.
* Where the widget itself already covers the region that is not
* needed: every container on the way to an exposed widget does. */
if (!gtk_widget_get_has_window (widget))
{
GdkRectangle clip;
gtk_widget_get_own_draw_rectangle (widget, &rect);
gdk_region_get_clipbox (region, &clip);
if (clip.x >= rect.x && clip.y >= rect.y &&
clip.x + clip.width <= rect.x + rect.width &&
clip.y + clip.height <= rect.y + rect.height)
return gdk_region_copy (region);
}
gtk_widget_get_draw_rectangle (widget, &rect);
dest = gdk_region_rectangle (&rect);