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