[gtk/wip/carlosg/for-master: 48/48] gtkwidget: Revert focus to parent on hide()




commit 851a4346c87e35a4413c35fb40dd2493c1864ab0
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Oct 1 16:54:10 2020 +0200

    gtkwidget: Revert focus to parent on hide()
    
    If a widget is being hidden while containing the focus, it can
    get caught on a state that it (or a child) is still the focus widget,
    but the focus cannot cycle back to visible widgets. One such case are
    popover menus, which will keep focus cycling within the hidden popover
    menu items after closed.
    
    It is generally undesirable to keep focus on a widget after hiding,
    so in order to fix this and other similar situations, ensure focus is
    restored to the parent after hiding a widget in the chain to the focus.
    
    Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/3214

 gtk/gtkwidget.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 2ea7fb9c3a..2c205c3b35 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -2637,6 +2637,16 @@ gtk_widget_hide (GtkWidget *widget)
 
       gtk_widget_queue_allocate (widget);
 
+      if (parent && root)
+        {
+          GtkWidget *focus = NULL;
+
+          focus = gtk_root_get_focus (root);
+
+          if (focus && (focus == widget || gtk_widget_is_ancestor (focus, widget)))
+            gtk_widget_grab_focus (parent);
+        }
+
       gtk_widget_pop_verify_invariants (widget);
       g_object_unref (widget);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]