shell-app-system: Give priority to .desktop IDs that should be shown

If we have multiple desktop ID's that share the same startup-wm class
and none of them is actually matching the desktop-id, then we should
exclude the ones that should not be shown in the current desktop.

This will help preventing cases such as the previous one in case no
desktop file ID would match the startup-wm-class exactly.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2721>
This commit is contained in:
Marco Trevisan (Treviño) 2023-03-24 00:25:06 +01:00 committed by Marge Bot
parent e7a09946ca
commit 12bb3a601d

View File

@ -114,17 +114,20 @@ static void
scan_startup_wm_class_to_id (ShellAppSystem *self)
{
ShellAppSystemPrivate *priv = self->priv;
g_autoptr(GPtrArray) no_show_ids = NULL;
const GList *l;
GList *all;
g_hash_table_remove_all (priv->startup_wm_class_to_id);
all = shell_app_cache_get_all (shell_app_cache_get_default ());
no_show_ids = g_ptr_array_new ();
for (l = all; l != NULL; l = l->next)
{
GAppInfo *info = l->data;
const char *startup_wm_class, *id, *old_id;
gboolean should_show;
id = g_app_info_get_id (info);
startup_wm_class = g_desktop_app_info_get_startup_wm_class (G_DESKTOP_APP_INFO (info));
@ -132,11 +135,23 @@ scan_startup_wm_class_to_id (ShellAppSystem *self)
if (startup_wm_class == NULL)
continue;
should_show = g_app_info_should_show (info);
if (!should_show)
g_ptr_array_add (no_show_ids, (char *) id);
/* 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 ||
startup_wm_class_is_exact_match (id, startup_wm_class))
if (old_id && startup_wm_class_is_exact_match (id, startup_wm_class))
old_id = NULL;
/* Give priority to the desktop files that should be shown */
if (old_id && should_show &&
g_ptr_array_find_with_equal_func (no_show_ids, old_id, g_str_equal, NULL))
old_id = NULL;
if (!old_id)
g_hash_table_insert (priv->startup_wm_class_to_id,
g_strdup (startup_wm_class), g_strdup (id));
}