Fix hiding popover when focus moves outside

Commit a01fe14 changed the behaviour of popovers when the focus leaves
them to stop child popovers being hidden when the focus leaves their
parent. However they are now a bit too reluctant to hide - if the
focus passes to an unrelated popover the first popover is not
hidden. Also if the focus passes to another widget that does not
perform a gtk grab then the popover isn't hidden until the user
presses a non-movement key or clicks outside the popover.

The solution is to go back to checking if the focused widget is a
descendant of the popover, but to include popovers and their related
widgets in the ancestry chain.

https://bugzilla.gnome.org/show_bug.cgi?id=765595
This commit is contained in:
Phillip Wood 2016-04-25 13:16:21 +01:00 committed by Matthias Clasen
parent 0943c9f6b2
commit 72ea348ad6

View File

@ -439,17 +439,23 @@ window_set_focus (GtkWindow *window,
{
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
if (priv->modal && widget &&
gtk_widget_is_drawable (GTK_WIDGET (popover)) &&
!gtk_widget_is_ancestor (widget, GTK_WIDGET (popover)))
if (!priv->modal || !widget || !gtk_widget_is_drawable (GTK_WIDGET (popover)))
return;
widget = gtk_widget_get_ancestor (widget, GTK_TYPE_POPOVER);
while (widget != NULL)
{
GtkWidget *grab_widget;
if (widget == GTK_WIDGET (popover))
return;
grab_widget = gtk_grab_get_current ();
if (!grab_widget || !GTK_IS_POPOVER (grab_widget))
gtk_widget_hide (GTK_WIDGET (popover));
widget = gtk_popover_get_relative_to (GTK_POPOVER (widget));
if (widget == NULL)
break;
widget = gtk_widget_get_ancestor (widget, GTK_TYPE_POPOVER);
}
popover_unset_prev_focus (popover);
gtk_widget_hide (GTK_WIDGET (popover));
}
static void