From 17bfc653f705f9ec43bf1ce7aba7056df8bb8a09 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Thu, 15 Oct 2026 16:31:08 +0200 Subject: [PATCH] gtkwidget: no walk through all children of a widget that covers the exposed region --- gtk/gtkwidget.c | 62 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 53196014a..d622758e2 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -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);