diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c index 2286cff8f4..a5ed37754f 100644 --- a/gtk/gtkpopover.c +++ b/gtk/gtkpopover.c @@ -301,6 +301,19 @@ window_focus_out (GtkWidget *widget, return FALSE; } +static void +window_set_focus (GtkWindow *window, + GtkWidget *widget, + GtkPopover *popover) +{ + GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover); + + if (priv->modal && + gtk_widget_is_drawable (GTK_WIDGET (popover)) && + (!widget || !gtk_widget_is_ancestor (widget, GTK_WIDGET (popover)))) + gtk_widget_hide (GTK_WIDGET (popover)); +} + static void gtk_popover_apply_modality (GtkPopover *popover, gboolean modal) @@ -322,6 +335,8 @@ gtk_popover_apply_modality (GtkPopover *popover, G_CALLBACK (window_focus_in), popover); g_signal_connect (priv->window, "focus-out-event", G_CALLBACK (window_focus_out), popover); + g_signal_connect (priv->window, "set-focus", + G_CALLBACK (window_set_focus), popover); } else {