From bccff5bdd85c5512f7977488b12a9367f06c2ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 7 Oct 2016 17:55:32 +0200 Subject: [PATCH] window: Expose Flatpak application ID GNOME Shell's window matching currently fails frequently with Flatpak applications, as one of the primary hints used to link windows with .desktop files - the WM_CLASS - no longer matches when flatpak renames the exported .desktop file. Luckily, Flatpak provides us with a fail-safe way to map from the PID to the corresponding application ID, so expose an appropriate method that allows GNOME Shell to reliably match windows to the corresponding Flatpak app. https://bugzilla.gnome.org/show_bug.cgi?id=772614 --- src/core/window-private.h | 1 + src/core/window.c | 35 +++++++++++++++++++++++++++++++++++ src/meta/window.h | 1 + 3 files changed, 37 insertions(+) diff --git a/src/core/window-private.h b/src/core/window-private.h index 67abbccd8..c7d693412 100644 --- a/src/core/window-private.h +++ b/src/core/window-private.h @@ -164,6 +164,7 @@ struct _MetaWindow char *startup_id; char *mutter_hints; + char *flatpak_id; char *gtk_theme_variant; char *gtk_application_id; char *gtk_unique_bus_name; diff --git a/src/core/window.c b/src/core/window.c index 3fea48353..458e2d7b0 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -293,6 +293,7 @@ meta_window_finalize (GObject *object) g_free (window->res_name); g_free (window->title); g_free (window->desc); + g_free (window->flatpak_id); g_free (window->gtk_theme_variant); g_free (window->gtk_application_id); g_free (window->gtk_unique_bus_name); @@ -764,6 +765,27 @@ sync_client_window_mapped (MetaWindow *window) meta_error_trap_pop (window->display); } +static void +meta_window_update_flatpak_id (MetaWindow *window) +{ + uint32_t pid = meta_window_get_client_pid (window); + g_autoptr(GKeyFile) key_file = NULL; + g_autofree char *info_filename = NULL; + + g_clear_pointer (&window->flatpak_id, g_free); + + if (pid == 0) + return; + + key_file = g_key_file_new (); + info_filename = g_strdup_printf ("/proc/%u/root/.flatpak-info", pid); + + if (!g_key_file_load_from_file (key_file, info_filename, G_KEY_FILE_NONE, NULL)) + return; + + window->flatpak_id = g_key_file_get_string (key_file, "Application", "name", NULL); +} + static void meta_window_update_desc (MetaWindow *window) { @@ -863,6 +885,7 @@ _meta_window_shared_new (MetaDisplay *display, window->screen = screen; + meta_window_update_flatpak_id (window); meta_window_update_desc (window); window->override_redirect = attrs->override_redirect; @@ -6897,6 +6920,18 @@ meta_window_get_wm_class_instance (MetaWindow *window) return window->res_name; } +/** + * meta_window_get_flatpak_id: + * @window: a #MetaWindow + * + * Return value: (transfer none): the Flatpak application ID or %NULL + **/ +const char * +meta_window_get_flatpak_id (MetaWindow *window) +{ + return window->flatpak_id; +} + /** * meta_window_get_gtk_theme_variant: * @window: a #MetaWindow diff --git a/src/meta/window.h b/src/meta/window.h index 60c9997da..2ae325e07 100644 --- a/src/meta/window.h +++ b/src/meta/window.h @@ -138,6 +138,7 @@ const char * meta_window_get_wm_class (MetaWindow *window); const char * meta_window_get_wm_class_instance (MetaWindow *window); gboolean meta_window_showing_on_its_workspace (MetaWindow *window); +const char * meta_window_get_flatpak_id (MetaWindow *window); const char * meta_window_get_gtk_theme_variant (MetaWindow *window); const char * meta_window_get_gtk_application_id (MetaWindow *window); const char * meta_window_get_gtk_unique_bus_name (MetaWindow *window);