From 54fca8b5b6a2b5443a84f9b2106ebc49463dec44 Mon Sep 17 00:00:00 2001 From: Michael Webster Date: Fri, 2 Aug 2024 11:28:07 -0400 Subject: [PATCH] Don't try to initialize gtk, use GMainLoop instead. The xdg-desktop-portal process is not exiting when the session ends (because of linuxmint/cinnamon-session@a5d4be9515 - the session bus is never killed). Because its background implementation regularly polls for app states, it can trigger xdg-desktop-portal-xapp to launch while no session is running, and no xserver (for that dead session). This fails because gtk_init() kills our xapp portal process immediately, and xdg-desktop-portal is stuck waiting on a dbus response that will never arrive. It eventually times out, and things generally right themselves. The Gtk code was added back while refactoring the settings portal. We've ended up not using any gtk code for now, so this can just be removed. If we ever do need to ignore gtk failure in the future (if we don't fix the cinnamon-session bug), we might use gtk_init_check instead of gtk_init. This will fail but not terminate the program. The main issue here is that xdg-desktop-portal isn't terminating, and/or shouldn't be requesting app states when there's no active session. This needs to be fixed in cinnamon-session. Fixes: #20 Fixes: linuxmint/cinnamon#12321 --- debian/control | 1 - src/meson.build | 5 +++-- src/settings.c | 2 -- src/xdg-desktop-portal-xapp.c | 8 ++++---- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/debian/control b/debian/control index 1da4b96..0385eb5 100644 --- a/debian/control +++ b/debian/control @@ -5,7 +5,6 @@ Maintainer: Linux Mint Build-Depends: debhelper-compat (= 13), libglib2.0-dev (>= 2.44), - libgtk-3-dev (>= 3.0), meson (>= 0.53.0), systemd (>= 242), xdg-desktop-portal-dev (>= 1.7.1), diff --git a/src/meson.build b/src/meson.build index 98e81ce..f4128c8 100644 --- a/src/meson.build +++ b/src/meson.build @@ -50,7 +50,9 @@ built_sources += gnome.gdbus_codegen( config_entries = { 'GETTEXT_PACKAGE' : '"@0@"'.format(meson.project_name()), 'LOCALEDIR': '"@0@"'.format(prefix / get_option('localedir')), - 'PACKAGE_STRING': '"xdg-desktop-portal-xapp @0@"'.format(meson.project_version()) + 'PACKAGE_STRING': '"xdg-desktop-portal-xapp @0@"'.format(meson.project_version()), + 'G_LOG_DOMAIN': '"xdg-desktop-portal-xapp"' + } config = configuration_data(config_entries) built_sources += configure_file(output: 'config.h', configuration: config) @@ -59,7 +61,6 @@ deps = [ meson.get_compiler('c').find_library('m'), dependency('glib-2.0', version: '>= 2.44'), dependency('gio-unix-2.0'), - dependency('gtk+-3.0'), dependency('gdk-3.0'), xdg_desktop_portal_dep, ] diff --git a/src/settings.c b/src/settings.c index 8d6b949..55014fb 100644 --- a/src/settings.c +++ b/src/settings.c @@ -25,7 +25,6 @@ #include #include #include -#include #include "settings.h" #include "utils.h" @@ -57,7 +56,6 @@ settings_bundle_free (SettingsBundle *bundle) g_free (bundle); } -// static GVariant *get_gtk_theme (gpointer data); static GVariant *get_color_scheme (gpointer data); static GVariant *get_high_contrast (gpointer data); diff --git a/src/xdg-desktop-portal-xapp.c b/src/xdg-desktop-portal-xapp.c index 38cc6b3..8f65797 100644 --- a/src/xdg-desktop-portal-xapp.c +++ b/src/xdg-desktop-portal-xapp.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include @@ -51,6 +50,7 @@ #include "settings.h" #include "wallpaper.h" +static GMainLoop *loop = NULL; static GHashTable *outstanding_handles = NULL; static gboolean opt_verbose; @@ -160,7 +160,7 @@ on_name_lost (GDBusConnection *connection, gpointer user_data) { g_debug ("name lost"); - gtk_main_quit (); + g_main_loop_quit (loop); } int @@ -244,7 +244,7 @@ main (int argc, char *argv[]) g_set_prgname ("xdg-desktop-portal-xapp"); - gtk_init (NULL, NULL); + loop = g_main_loop_new (NULL, FALSE); outstanding_handles = g_hash_table_new (g_str_hash, g_str_equal); @@ -264,7 +264,7 @@ main (int argc, char *argv[]) NULL, NULL); - gtk_main (); + g_main_loop_run (loop); g_bus_unown_name (owner_id); return 0;