From 994287b71fc208d9b810f15ef7fd6dfa6364737a Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 5 Nov 2017 04:05:55 +0100 Subject: [PATCH] widget: Make gtk_widget_pick() really slow We cannot fast-track picking by using gtk_widget_contains(). Child widgets may extend their parent using ie negative margins. This is not just a theoretical concern, this is what's happening right now with GtkScale's sliders relative to the trough. The problem is that we now iterate through all widgets, even when they aren't anywhere near the mouse pointer. So essentially every pick operation is now guaranteed O(N_WIDGETS) which used to be the worst case that pretty much never happened. --- gtk/gtkwidget.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 69dfe6d8ae..5d41c2d355 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -955,9 +955,6 @@ gtk_widget_real_pick (GtkWidget *widget, { GtkWidget *child; - if (!gtk_widget_contains (widget, x, y)) - return NULL; - for (child = _gtk_widget_get_last_child (widget); child; child = _gtk_widget_get_prev_sibling (child)) @@ -972,6 +969,9 @@ gtk_widget_real_pick (GtkWidget *widget, return picked; } + if (!gtk_widget_contains (widget, x, y)) + return NULL; + return widget; } @@ -13186,6 +13186,11 @@ gtk_widget_pick (GtkWidget *widget, { g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); + if (gtk_widget_get_pass_through (widget) || + !gtk_widget_is_sensitive (widget) || + !gtk_widget_is_drawable (widget)) + return NULL; + return GTK_WIDGET_GET_CLASS (widget)->pick (widget, x, y); }