diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-10-18 11:02:08 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-10-18 11:02:08 +0000 |
commit | 94ac1af293a8f2b5ec2ebc5509efe33703e9f750 (patch) | |
tree | b63c34548362626b67259420aa12e6f783702526 | |
parent | b4db48935d04afd6fcf7d6109f38cc2bf2ebb331 (diff) | |
parent | f5063c14357b2206c895e297ce855ac8363322e5 (diff) | |
download | gtk+-94ac1af293a8f2b5ec2ebc5509efe33703e9f750.tar.gz |
Merge branch 'fix-focus-changes' into 'main'
window: Fix focus updates
Closes #4903
See merge request GNOME/gtk!5127
-rw-r--r-- | gtk/gtkwindow.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 21e0ac3036..1de17f9048 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -184,6 +184,7 @@ typedef struct GtkWidget *default_widget; GtkWidget *focus_widget; + GtkWidget *move_focus_widget; GtkWindow *transient_parent; GtkWindowGeometryInfo *geometry_info; GtkWindowGroup *group; @@ -2003,7 +2004,9 @@ gtk_window_root_set_focus (GtkRoot *root, if (focus == priv->focus_widget) { - priv->move_focus = FALSE; + if (priv->move_focus && + focus && gtk_widget_is_visible (focus)) + priv->move_focus = FALSE; return; } @@ -2023,7 +2026,9 @@ gtk_window_root_set_focus (GtkRoot *root, g_clear_object (&old_focus); - priv->move_focus = FALSE; + if (priv->move_focus && + focus && gtk_widget_is_visible (focus)) + priv->move_focus = FALSE; g_object_notify (G_OBJECT (self), "focus-widget"); } @@ -4675,7 +4680,22 @@ maybe_unset_focus_and_default (GtkWindow *window) GtkWindowPrivate *priv = gtk_window_get_instance_private (window); if (priv->move_focus) - gtk_widget_child_focus (GTK_WIDGET (window), GTK_DIR_TAB_FORWARD); + { + GtkWidget *parent; + + parent = _gtk_widget_get_parent (priv->move_focus_widget); + + while (parent) + { + if (_gtk_widget_get_visible (parent)) + { + if (gtk_widget_grab_focus (parent)) + break; + } + + parent = _gtk_widget_get_parent (parent); + } + } if (priv->unset_default) gtk_window_set_default_widget (window, NULL); @@ -5134,7 +5154,10 @@ _gtk_window_unset_focus_and_default (GtkWindow *window, child = priv->focus_widget; if (child && (child == widget || gtk_widget_is_ancestor (child, widget))) - priv->move_focus = TRUE; + { + priv->move_focus_widget = widget; + priv->move_focus = TRUE; + } child = priv->default_widget; if (child && (child == widget || gtk_widget_is_ancestor (child, widget))) |