From cb383867cf25237e02b046669e6be237983d60ab Mon Sep 17 00:00:00 2001 From: Paul Wolneykien Date: Mon, 12 Aug 2019 17:35:55 +0300 Subject: [PATCH] Use the first available session config as default If there is no "default.desktop" session then use the first available .desktop file as default. Signed-off-by: Paul Wolneykien --- src/seat.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/seat.c b/src/seat.c index b1850332a..2f500f87b 100644 --- a/src/seat.c +++ b/src/seat.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "seat.h" #include "configuration.h" @@ -946,6 +947,41 @@ get_session_argv (Seat *seat, SessionConfig *session_config, const gchar *sessio return g_steal_pointer (&argv); } +static SessionConfig * +find_default_session_config (Seat *seat, const gchar *sessions_dir) +{ + g_return_val_if_fail (sessions_dir != NULL, NULL); + + g_auto(GStrv) dirs = g_strsplit (sessions_dir, ":", -1); + for (int i = 0; dirs[i]; i++) + { + const gchar *default_session_type = "x"; + if (strcmp (dirs[i], WAYLAND_SESSIONS_DIR) == 0) + default_session_type = "wayland"; + + g_autoptr(GError) error = NULL; + GDir *directory = g_dir_open (dirs[i], 0, &error); + if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) + g_warning ("Failed to open sessions directory: %s", error->message); + + if (directory) + { + const gchar *filename; + while ((filename = g_dir_read_name (directory))) + { + if (!g_str_has_suffix (filename, ".desktop")) + continue; + g_autofree gchar *path = g_build_filename (dirs[i], filename, NULL); + SessionConfig *session_config = session_config_new_from_file (path, default_session_type, &error); + if (session_config) + return session_config; + } + } + } + + return NULL; +} + static SessionConfig * find_session_config (Seat *seat, const gchar *sessions_dir, const gchar *session_name) { @@ -967,6 +1003,13 @@ find_session_config (Seat *seat, const gchar *sessions_dir, const gchar *session return session_config; } + if (0 == g_strcmp0 (session_name, DEFAULT_USER_SESSION)) + { + SessionConfig *session_config = find_default_session_config (seat, sessions_dir); + if (session_config) + return session_config; + } + l_debug (seat, "Failed to find session configuration %s", session_name); return NULL;