From cd566433c8fd5ede9c8da9fdbeda6b12114bf987 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 10 Jun 2022 05:12:17 +0300 Subject: [PATCH 19/19] gtk: Add logging about gtk initialization failure Both gtk clients and modpack installers changed. See osdn #44118 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.0/gui_main.c | 5 +++- client/gui-gtk-3.22/gui_main.c | 5 +++- client/gui-gtk-4.0/gui_main.c | 5 +++- tools/fcmp/mpgui_gtk3.c | 51 ++++++++++++++++++---------------- tools/fcmp/mpgui_gtk4.c | 15 ++++++---- 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/client/gui-gtk-3.0/gui_main.c b/client/gui-gtk-3.0/gui_main.c index 661b50972c..4cb49d6ada 100644 --- a/client/gui-gtk-3.0/gui_main.c +++ b/client/gui-gtk-3.0/gui_main.c @@ -1711,7 +1711,10 @@ void ui_main(int argc, char **argv) gtk_disable_setlocale(); /* GTK withdraw gtk options. Process GTK arguments */ - gtk_init(&argc, &argv); + if (!gtk_init_check(&argc, &argv)) { + log_fatal(_("Failed to open graphical mode.")); + exit(EXIT_FAILURE); + } toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_position(GTK_WINDOW(toplevel), GTK_WIN_POS_CENTER); diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c index dbd667d135..6dc9d69714 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -1790,7 +1790,10 @@ void ui_main(int argc, char **argv) gtk_disable_setlocale(); /* GTK withdraw gtk options. Process GTK arguments */ - gtk_init(&argc, &argv); + if (!gtk_init_check(&argc, &argv)) { + log_fatal(_("Failed to open graphical mode.")); + exit(EXIT_FAILURE); + } dlg_tab_provider_prepare(); diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index 0843ec7ae4..3aa6fab560 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -1808,7 +1808,10 @@ void ui_main(int argc, char **argv) * locale logic in gtk_init() causes problems with zh_CN (see PR#39475) */ gtk_disable_setlocale(); - gtk_init(); + if (!gtk_init_check()) { + log_fatal(_("Failed to open graphical mode.")); + exit(EXIT_FAILURE); + } gui_up = TRUE; fc_app = gtk_application_new(NULL, 0); diff --git a/tools/fcmp/mpgui_gtk3.c b/tools/fcmp/mpgui_gtk3.c index bcd39a578c..557631a2b0 100644 --- a/tools/fcmp/mpgui_gtk3.c +++ b/tools/fcmp/mpgui_gtk3.c @@ -588,41 +588,44 @@ int main(int argc, char *argv[]) load_install_info_lists(&fcmp); /* Process GTK arguments */ - gtk_init(&ui_options, &argv); + if (gtk_init_check(&ui_options, &argv)) { + toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); - toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_widget_realize(toplevel); + gtk_widget_set_name(toplevel, "Freeciv-modpack"); + gtk_window_set_title(GTK_WINDOW(toplevel), + _("Freeciv modpack installer (gtk3)")); - gtk_widget_realize(toplevel); - gtk_widget_set_name(toplevel, "Freeciv-modpack"); - gtk_window_set_title(GTK_WINDOW(toplevel), - _("Freeciv modpack installer (gtk3)")); - - /* Keep the icon of the executable on Windows */ + /* Keep the icon of the executable on Windows */ #ifndef FREECIV_MSWINDOWS - { - /* Unlike main client, this only works if installed. Ignore any - * errors loading the icon. */ - GError *err; + { + /* Unlike main client, this only works if installed. Ignore any + * errors loading the icon. */ + GError *err; - (void) gtk_window_set_icon_from_file(GTK_WINDOW(toplevel), MPICON_PATH, - &err); - } + (void) gtk_window_set_icon_from_file(GTK_WINDOW(toplevel), MPICON_PATH, + &err); + } #endif /* FREECIV_MSWINDOWS */ - g_signal_connect(toplevel, "delete_event", - G_CALLBACK(quit_dialog_callback), NULL); + g_signal_connect(toplevel, "delete_event", + G_CALLBACK(quit_dialog_callback), NULL); - modinst_setup_widgets(toplevel); + modinst_setup_widgets(toplevel); - gtk_widget_show_all(toplevel); + gtk_widget_show_all(toplevel); - if (fcmp.autoinstall != NULL) { - gui_download_modpack(fcmp.autoinstall); - } + if (fcmp.autoinstall != NULL) { + gui_download_modpack(fcmp.autoinstall); + } + + gtk_main(); - gtk_main(); + gtk_widget_destroy(toplevel); + } else { + log_fatal(_("Failed to open graphical mode.")); + } - gtk_widget_destroy(toplevel); close_mpdbs(); } diff --git a/tools/fcmp/mpgui_gtk4.c b/tools/fcmp/mpgui_gtk4.c index 306ba7965d..033b2a0806 100644 --- a/tools/fcmp/mpgui_gtk4.c +++ b/tools/fcmp/mpgui_gtk4.c @@ -633,13 +633,16 @@ int main(int argc, char *argv[]) if (ui_options != -1) { load_install_info_lists(&fcmp); - gtk_init(); - - fcmp_app = gtk_application_new(NULL, 0); - g_signal_connect(fcmp_app, "activate", G_CALLBACK(activate_gui), NULL); - g_application_run(G_APPLICATION(fcmp_app), 0, NULL); + if (gtk_init_check()) { + fcmp_app = gtk_application_new(NULL, 0); + g_signal_connect(fcmp_app, "activate", G_CALLBACK(activate_gui), NULL); + g_application_run(G_APPLICATION(fcmp_app), 0, NULL); + + g_object_unref(fcmp_app); + } else { + log_fatal(_("Failed to open graphical mode.")); + } - g_object_unref(fcmp_app); close_mpdbs(); } -- 2.35.1