diff --git a/src/shell-window-tracker.c b/src/shell-window-tracker.c index ad1219c13..f87e6a3ae 100644 --- a/src/shell-window-tracker.c +++ b/src/shell-window-tracker.c @@ -202,9 +202,39 @@ get_app_from_window_wmclass (MetaWindow *window) return NULL; } +/* + * get_app_from_id: + * @window: a #MetaWindow + * + * Looks only at the given window, and attempts to determine + * an application based on %id. If one can't be determined, + * return %NULL. + * + * Return value: (transfer full): A newly-referenced #ShellApp, or %NULL + */ +static ShellApp * +get_app_from_id (MetaWindow *window, + const char *id) +{ + ShellApp *app; + ShellAppSystem *appsys; + char *desktop_file; + + g_return_val_if_fail (id != NULL, NULL); + + appsys = shell_app_system_get_default (); + + desktop_file = g_strconcat (id, ".desktop", NULL); + app = shell_app_system_lookup_app (appsys, desktop_file); + if (app) + g_object_ref (app); + + g_free (desktop_file); + return app; +} + /* * get_app_from_gapplication_id: - * @monitor: a #ShellWindowTracker * @window: a #MetaWindow * * Looks only at the given window, and attempts to determine @@ -216,24 +246,35 @@ get_app_from_window_wmclass (MetaWindow *window) static ShellApp * get_app_from_gapplication_id (MetaWindow *window) { - ShellApp *app; - ShellAppSystem *appsys; const char *id; - char *desktop_file; - - appsys = shell_app_system_get_default (); id = meta_window_get_gtk_application_id (window); if (!id) return NULL; - desktop_file = g_strconcat (id, ".desktop", NULL); - app = shell_app_system_lookup_app (appsys, desktop_file); - if (app) - g_object_ref (app); + return get_app_from_id (window, id); +} - g_free (desktop_file); - return app; +/* + * get_app_from_flatpak_id: + * @window: a #MetaWindow + * + * Looks only at the given window, and attempts to determine + * an application based on its Flatpak ID. If one can't be determined, + * return %NULL. + * + * Return value: (transfer full): A newly-referenced #ShellApp, or %NULL + */ +static ShellApp * +get_app_from_flatpak_id (MetaWindow *window) +{ + const char *id; + + id = meta_window_get_flatpak_id (window); + if (!id) + return NULL; + + return get_app_from_id (window, id); } /* @@ -354,6 +395,13 @@ get_app_for_window (ShellWindowTracker *tracker, if (meta_window_is_remote (window)) return _shell_app_new_for_window (window); + /* Check if the window was opened from within a Flatpak sandbox; if this + * is the case, a corresponding .desktop file is guaranteed to match; + */ + result = get_app_from_flatpak_id (window); + if (result != NULL) + return result; + /* Check if the window has a GApplication ID attached; this is * canonical if it does */