From 2244d70a94288091d4c9f9f8bac0aaa376d8d40e Mon Sep 17 00:00:00 2001 From: Jehan Date: Thu, 12 Jun 2025 01:55:38 +0200 Subject: [PATCH] Issue #13183: use the renamed desktop filename in Flatpak. Since MR !2158, we set the desktop name as prgname, because that's what is expected for Wayland. But this doesn't work on Flatpak where the desktop file is renamed (and even to different names for the stable/beta vs. nightly flatpaks). This commit adds some special-casing when we detect we are inside a flatpak environment. Note that on X11 (whether or not we are in flatpak), we just always use the original desktop name, because then it will be set as windows' WM_CLASS which will also match the StartupWMClass key we set in the desktop file (cf. previous commit). --- app/main.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/app/main.c b/app/main.c index 9db78ed8e3..9711c6c1b8 100644 --- a/app/main.c +++ b/app/main.c @@ -46,6 +46,9 @@ #ifndef GIMP_CONSOLE_COMPILATION #include +#ifdef GDK_WINDOWING_X11 +#include +#endif #else #include #endif @@ -548,6 +551,9 @@ main (int argc, GFile *user_gimprc_file = NULL; GOptionGroup *gimp_group = NULL; gchar *backtrace_file = NULL; +#ifndef GIMP_CONSOLE_COMPILATION + GKeyFile *flatpak_keyfile; +#endif gint retval; gint i; @@ -755,6 +761,47 @@ main (int argc, app_exit (EXIT_FAILURE); } +#if GLIB_CHECK_VERSION(2,72,0) + /* g_set_prgname() can only be called several times since 2.72.0. */ +#ifndef GIMP_CONSOLE_COMPILATION + g_return_val_if_fail (gdk_display_get_default () != NULL, EXIT_FAILURE); + + flatpak_keyfile = g_key_file_new (); + + if ( +#ifdef GDK_WINDOWING_X11 + ! GDK_IS_X11_DISPLAY (gdk_display_get_default ()) && +#endif + g_key_file_load_from_file (flatpak_keyfile, "/.flatpak-info", G_KEY_FILE_NONE, NULL)) + { + /* Flatpak renames the desktop file. The .flatpak-info file tells + * us the right desktop name we must associate our process to, + * especially as we have flatpaks with different IDs. + * + * This logic should not apply on X11 which will instead + * apparently use the StartupWMClass set in the desktop file and + * expect it to be the same as the name set by g_set_prgname(). + * + * Cf. #13183 and #14233. + */ + gchar *flatpak_name = g_key_file_get_string (flatpak_keyfile, "Application", "name", NULL); + + if (flatpak_name != NULL) + { + g_set_prgname (flatpak_name); + g_free (flatpak_name); + } + /* The else case should never happen unless we are in some kind of + * broken flatpak environment or somehow in a non-flatpak + * environment with a .flatpak-info file at the root, which seems + * improbable. Fail silently. + */ + } + + g_key_file_free (flatpak_keyfile); +#endif +#endif + if (no_interface || be_verbose || console_messages || batch_commands != NULL) gimp_open_console_window ();