Merge branch 'wip/carlosg/for-master' into 'master'

gtkpopover: Revert focus to parent on hide()

Closes #3214

See merge request GNOME/gtk!2653
This commit is contained in:
Matthias Clasen 2020-10-06 02:14:54 +00:00
commit b6d4067717

View File

@ -5206,44 +5206,41 @@ gtk_window_css_changed (GtkWidget *widget,
} }
} }
/** /*
* _gtk_window_unset_focus_and_default: * _gtk_window_unset_focus_and_default:
* @window: a #GtkWindow * @window: a #GtkWindow
* @widget: a widget inside of @window * @widget: a widget inside of @window
* *
* Checks whether the focus and default widgets of @window are * Checks whether the focus and default widgets of @window are
* @widget or a descendent of @widget, and if so, unset them. * @widget or a descendent of @widget, and if so, unset them.
**/ */
void void
_gtk_window_unset_focus_and_default (GtkWindow *window, _gtk_window_unset_focus_and_default (GtkWindow *window,
GtkWidget *widget) GtkWidget *widget)
{ {
GtkWindowPrivate *priv = gtk_window_get_instance_private (window); GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
GtkWidget *child; GtkWidget *child;
GtkWidget *parent; GtkWidget *parent;
GtkWidget *focus;
g_object_ref (window); g_object_ref (window);
g_object_ref (widget); g_object_ref (widget);
parent = _gtk_widget_get_parent (widget); focus = priv->focus_widget;
if (gtk_widget_get_focus_child (parent) == widget) if (focus && (focus == widget || gtk_widget_is_ancestor (focus, widget)))
{ {
child = priv->focus_widget; parent = _gtk_widget_get_parent (widget);
while (child && child != widget) while (parent)
child = _gtk_widget_get_parent (child);
if (child == widget)
{ {
GtkWidget *new_focus; if (_gtk_widget_get_visible (parent))
{
gtk_window_set_focus (window, parent);
break;
}
if (GTK_IS_NATIVE (widget)) parent = gtk_widget_get_parent (parent);
new_focus = gtk_widget_get_parent (widget);
else
new_focus = NULL;
gtk_window_set_focus (GTK_WINDOW (window), new_focus);
} }
} }