Blame SOURCES/0002-libgdm-Sort-session-list.patch

3b7bb8
From 677d370e892788635c4086b139d78499510fa86c Mon Sep 17 00:00:00 2001
18ca79
From: Ray Strode <rstrode@redhat.com>
18ca79
Date: Tue, 20 Jul 2021 13:36:45 -0400
18ca79
Subject: [PATCH 2/2] libgdm: Sort session list
18ca79
18ca79
Right now the session list comes out in hash table order.
18ca79
18ca79
This commit changes the code to sort by description.
18ca79
---
18ca79
 libgdm/gdm-sessions.c | 19 +++++++++++++++++++
18ca79
 1 file changed, 19 insertions(+)
18ca79
18ca79
diff --git a/libgdm/gdm-sessions.c b/libgdm/gdm-sessions.c
3b7bb8
index 97ed5ef3..f078e04b 100644
18ca79
--- a/libgdm/gdm-sessions.c
18ca79
+++ b/libgdm/gdm-sessions.c
18ca79
@@ -311,92 +311,111 @@ collect_sessions (void)
18ca79
                 g_ptr_array_add (wayland_search_array, g_strdup (wayland_search_dirs[i]));
18ca79
         }
18ca79
 #endif
18ca79
 
18ca79
         if (gdm_available_sessions_map == NULL) {
18ca79
                 gdm_available_sessions_map = g_hash_table_new_full (g_str_hash, g_str_equal,
18ca79
                                                                     g_free, (GDestroyNotify)gdm_session_file_free);
18ca79
         }
18ca79
 
18ca79
         if (!supported_session_types || g_strv_contains ((const char * const *) supported_session_types, "x11")) {
18ca79
                 for (i = 0; i < xorg_search_array->len; i++) {
18ca79
                         collect_sessions_from_directory (g_ptr_array_index (xorg_search_array, i));
18ca79
                 }
18ca79
         }
18ca79
 
18ca79
 #ifdef ENABLE_WAYLAND_SUPPORT
18ca79
 #ifdef ENABLE_USER_DISPLAY_SERVER
18ca79
         if (!supported_session_types  || g_strv_contains ((const char * const *) supported_session_types, "wayland")) {
18ca79
                 for (i = 0; i < wayland_search_array->len; i++) {
18ca79
                         collect_sessions_from_directory (g_ptr_array_index (wayland_search_array, i));
18ca79
                 }
18ca79
         }
18ca79
 #endif
18ca79
 #endif
18ca79
 
18ca79
         g_hash_table_foreach_remove (gdm_available_sessions_map,
18ca79
                                      remove_duplicate_sessions,
18ca79
                                      names_seen_before);
18ca79
 }
18ca79
 
18ca79
+static gint
18ca79
+compare_session_ids (gconstpointer  a,
18ca79
+                     gconstpointer  b)
18ca79
+{
18ca79
+        GdmSessionFile *session_a, *session_b;
18ca79
+        session_a = (GdmSessionFile *) g_hash_table_lookup (gdm_available_sessions_map, a);
18ca79
+        session_b = (GdmSessionFile *) g_hash_table_lookup (gdm_available_sessions_map, b);
18ca79
+
18ca79
+        if (session_a == NULL)
18ca79
+                return -1;
18ca79
+
18ca79
+        if (session_b == NULL)
18ca79
+                return 1;
18ca79
+
18ca79
+        return g_strcmp0 (session_a->translated_name, session_b->translated_name);
18ca79
+}
18ca79
+
18ca79
 /**
18ca79
  * gdm_get_session_ids:
18ca79
  *
18ca79
  * Reads /usr/share/xsessions and other relevant places for possible sessions
18ca79
  * to log into and returns the complete list.
18ca79
  *
18ca79
  * Returns: (transfer full): a %NULL terminated list of session ids
18ca79
  */
18ca79
 char **
18ca79
 gdm_get_session_ids (void)
18ca79
 {
18ca79
         GHashTableIter iter;
18ca79
         gpointer key, value;
18ca79
         GPtrArray *array;
18ca79
 
18ca79
         if (!gdm_sessions_map_is_initialized) {
18ca79
                 collect_sessions ();
18ca79
 
18ca79
                 gdm_sessions_map_is_initialized = TRUE;
18ca79
         }
18ca79
 
18ca79
         array = g_ptr_array_new ();
18ca79
         g_hash_table_iter_init (&iter, gdm_available_sessions_map);
18ca79
         while (g_hash_table_iter_next (&iter, &key, &value)) {
18ca79
                 GdmSessionFile *session;
18ca79
 
18ca79
                 session = (GdmSessionFile *) value;
18ca79
 
18ca79
                 g_ptr_array_add (array, g_strdup (session->id));
18ca79
         }
18ca79
         g_ptr_array_add (array, NULL);
18ca79
 
18ca79
+        g_ptr_array_sort (array, compare_session_ids);
18ca79
+
18ca79
         return (char **) g_ptr_array_free (array, FALSE);
18ca79
 }
18ca79
 
18ca79
 /**
18ca79
  * gdm_get_session_name_and_description:
18ca79
  * @id: an id from gdm_get_session_ids()
18ca79
  * @description: (out): optional returned session description
18ca79
  *
18ca79
  * Takes an xsession id and returns the name and comment about it.
18ca79
  *
18ca79
  * Returns: The session name if found, or %NULL otherwise
18ca79
  */
18ca79
 char *
18ca79
 gdm_get_session_name_and_description (const char  *id,
18ca79
                                       char       **description)
18ca79
 {
18ca79
         GdmSessionFile *session;
18ca79
         char *name;
18ca79
 
18ca79
         if (!gdm_sessions_map_is_initialized) {
18ca79
                 collect_sessions ();
18ca79
 
18ca79
                 gdm_sessions_map_is_initialized = TRUE;
18ca79
         }
18ca79
 
18ca79
         session = (GdmSessionFile *) g_hash_table_lookup (gdm_available_sessions_map,
18ca79
                                                           id);
18ca79
 
18ca79
         if (session == NULL) {
18ca79
                 return NULL;
18ca79
-- 
3b7bb8
2.27.0
18ca79