From e7a09946ca44a4f4fae6fa847f08e681cfd877cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 24 Mar 2023 00:02:16 +0100 Subject: [PATCH] shell-app-system: Do not compare startup-wm classes with full desktop IDs When fetching the desktop ids into a map of startup-wm classes we meant to give the ones that match the desktop ID more priority, however this did not happen because we were always comparing a desktop file id, including the `.desktop` suffix, with a wm-class that generally does not include that. This is the case of gnome-system-monitor, that provides two desktop files, one of which is OnlyShowIn=KDE but both have the same StartupWMClass and thus the first parsed is preferred, even though its desktop-id is gnome-system-monitor-kde. As per this, remove the .desktop suffix when comparing it with the startup-wm-class, keeping the old check just in case. Part-of: --- src/shell-app-system.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/shell-app-system.c b/src/shell-app-system.c index f9d74ed5c..e042a6747 100644 --- a/src/shell-app-system.c +++ b/src/shell-app-system.c @@ -91,6 +91,25 @@ static void shell_app_system_class_init(ShellAppSystemClass *klass) G_TYPE_NONE, 0); } +/* + * Check whether @wm_class matches @id exactly when ignoring the .desktop suffix + */ +static gboolean +startup_wm_class_is_exact_match (const char *id, + const char *wm_class) +{ + size_t wm_class_len; + + if (!g_str_has_prefix (id, wm_class)) + return FALSE; + + wm_class_len = strlen (wm_class); + if (id[wm_class_len] == '\0') + return TRUE; + + return g_str_equal (id + wm_class_len, ".desktop"); +} + static void scan_startup_wm_class_to_id (ShellAppSystem *self) { @@ -116,7 +135,8 @@ scan_startup_wm_class_to_id (ShellAppSystem *self) /* In case multiple .desktop files set the same StartupWMClass, prefer * the one where ID and StartupWMClass match */ old_id = g_hash_table_lookup (priv->startup_wm_class_to_id, startup_wm_class); - if (old_id == NULL || strcmp (id, startup_wm_class) == 0) + if (old_id == NULL || + startup_wm_class_is_exact_match (id, startup_wm_class)) g_hash_table_insert (priv->startup_wm_class_to_id, g_strdup (startup_wm_class), g_strdup (id)); }