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

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