window: Fix focus updates

This partially undoes changes from 3dbf5038fa.

That commit did two things:
1) Move the focus update to after-paint time
2) Change from grabbing focus to the visible parent
   to  calling move_focus (TAB)

The second part did have the unintended consequence
of moving focus laterally.

Fixes: #4903
This commit is contained in:
Matthias Clasen 2022-10-17 12:29:44 -04:00
parent 6f5d18a9f5
commit 100605ef0c

View File

@ -184,6 +184,7 @@ typedef struct
GtkWidget *default_widget;
GtkWidget *focus_widget;
GtkWidget *move_focus_widget;
GtkWindow *transient_parent;
GtkWindowGeometryInfo *geometry_info;
GtkWindowGroup *group;
@ -4675,7 +4676,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 +5150,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)))