From 65b18a4fc1605e2a142895c2e995b50a4964adbd Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 21 Jul 2017 17:48:53 +0200 Subject: [PATCH] main: Set the error if gtk_init_with_args fails This fixes a fallout from 8a7d0ab481345708 where the error wasn't being set when a display couldn't be opened right after parsing the commandline. It also fixes an older bug where the error would be left unset if the commandline had already been parsed before (ie. when gtk_initialized is TRUE). https://bugzilla.gnome.org/show_bug.cgi?id=771959 --- gtk/gtkmain.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index 08503249c7..af854ce054 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -992,15 +992,22 @@ gtk_init_with_args (gint *argc, return FALSE; done: - if (GDK_PRIVATE_CALL (gdk_display_open_default) () != NULL) + if (GDK_PRIVATE_CALL (gdk_display_open_default) () == NULL) { - if (gtk_get_debug_flags () & GTK_DEBUG_INTERACTIVE) - gtk_window_set_interactive_debugging (TRUE); + const char *display_name = gdk_get_display_arg_name (); + g_set_error (error, + G_OPTION_ERROR, + G_OPTION_ERROR_FAILED, + _("Cannot open display: %s"), + display_name ? display_name : "" ); - return TRUE; + return FALSE; } - return FALSE; + if (gtk_get_debug_flags () & GTK_DEBUG_INTERACTIVE) + gtk_window_set_interactive_debugging (TRUE); + + return TRUE; }