gtkwindow: Pick a suitable widget to continue the implicit grab
authorCarlos Garnacho <carlosg@gnome.org>
Mon, 18 Sep 2023 17:42:41 +0000 (19:42 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 19 Sep 2023 20:32:27 +0000 (16:32 -0400)
When a widget in the GtkPointerFocus stack becomes insensitive, we've
so far broken the implicit grab entirely. This has the side effect of
breaking accounting of the active state on the widgets that are
ancestors of the widget that became insensitive.

The easiest, and most consistent thing to do (i.e. giving widgets
in the GtkPointerFocus stack certain level of isolation wrt state
changes in other widgets) is to transfer the implicit grab to the
topmost actor of the GtkPointerFocus stack that can keep handling
events.

This fixes the unbalanced accounting of active state on ancestors
of widgets becoming insensitive, and avoids thorny questions about
how to handle implicit active state with broken implicit grabs.

gtk/gtkwindow.c

index 9c94d9726f4102c41c8357efde03aeefcad4af09..2eb94d6f7e09af09831f48da753153cc5acf23ea 100644 (file)
@@ -6554,7 +6554,8 @@ gtk_window_update_pointer_focus_on_state_change (GtkWindow *window,
            gtk_widget_is_ancestor (focus->grab_widget, widget)))
         {
           clear_widget_active_state (focus->grab_widget, widget);
-          gtk_pointer_focus_set_implicit_grab (focus, NULL);
+          gtk_pointer_focus_set_implicit_grab (focus,
+                                               gtk_widget_get_parent (widget));
         }
 
       if (GTK_WIDGET (focus->toplevel) == widget)