Skip to content

Commit

Permalink
Use the first available session config as default
Browse files Browse the repository at this point in the history
If there is no "default.desktop" session then use the first available
.desktop file as default.

Signed-off-by: Paul Wolneykien <[email protected]>
  • Loading branch information
wolneykien committed Nov 18, 2022
1 parent de09f2c commit cb38386
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <config.h>

#include "seat.h"
#include "configuration.h"
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down

0 comments on commit cb38386

Please sign in to comment.