feat: add session types

This commit is contained in:
2024-07-11 00:09:29 +02:00
parent 07d2842be0
commit 490a370546
3 changed files with 21 additions and 7 deletions

View File

@@ -9,12 +9,15 @@
#include <sessions.h>
#include <util.h>
static const char *sources[] = {"/usr/share/xsessions",
"/usr/share/wayland-sessions"};
static const char *sources[][2] = {
{ "xorg", "/usr/share/xsessions" },
{ "wl", "/usr/share/wayland-sessions" },
};
static const size_t sources_size = sizeof(sources) / sizeof(sources[0]);
static struct session __new_session(char *name, const char *path) {
static struct session __new_session(const char *type, char *name, const char *path) {
struct session __session;
__session.type = type;
strcln(&__session.name, name);
strcln(&__session.path, path);
@@ -30,6 +33,7 @@ static u_int16_t used_size = 0;
static struct session *sessions = NULL;
static struct sessions_list *__sessions_list = NULL;
static const char* session_type;
static int fn(const char *fpath, const struct stat *sb, int typeflag) {
// practically impossible to reach this
// but will prevent break
@@ -69,7 +73,7 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
sessions = realloc(sessions, alloc_size * unit_size);
}
sessions[used_size] = __new_session(buf, fpath);
sessions[used_size] = __new_session(session_type, buf, fpath);
used_size++;
}
@@ -86,7 +90,8 @@ struct sessions_list *get_avaliable_sessions() {
sessions = malloc(alloc_size * unit_size);
for (uint i = 0; i < sources_size; i++) {
ftw(sources[i], &fn, 1);
session_type = sources[i][0];
ftw(sources[i][1], &fn, 1);
}
sessions = realloc(sessions, used_size * unit_size);