diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 91e3bdbb63..d82d7da67e 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -264,6 +264,7 @@ struct _GtkWindowPrivate guint use_subsurface : 1; guint hide_on_close : 1; + guint in_emit_close_request : 1; GdkWindowTypeHint type_hint; @@ -1363,6 +1364,9 @@ gtk_window_close (GtkWindow *window) if (!_gtk_widget_get_realized (GTK_WIDGET (window))) return; + if (window->priv->in_emit_close_request) + return; + g_object_ref (window); if (!gtk_window_emit_close_request (window)) @@ -5982,9 +5986,17 @@ gtk_window_close_request (GtkWindow *window) static gboolean gtk_window_emit_close_request (GtkWindow *window) { + GtkWindowPrivate *priv = gtk_window_get_instance_private (window); gboolean handled; + /* Avoid re-entrancy issues when calling gtk_window_close from a + * close-request handler */ + if (priv->in_emit_close_request) + return TRUE; + + priv->in_emit_close_request = TRUE; g_signal_emit (window, window_signals[CLOSE_REQUEST], 0, &handled); + priv->in_emit_close_request = FALSE; return handled; }