From 490a370546cc95ca7fcf2d7727cb819e973f01c2 Mon Sep 17 00:00:00 2001 From: javalsai Date: Thu, 11 Jul 2024 00:09:29 +0200 Subject: [PATCH] feat: add session types --- include/sessions.h | 1 + src/main.c | 12 ++++++++++-- src/sessions.c | 15 ++++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/sessions.h b/include/sessions.h index 7839e22..c4f1f6e 100644 --- a/include/sessions.h +++ b/include/sessions.h @@ -1,6 +1,7 @@ #include struct session { + const char *type; char *name; char *path; }; diff --git a/src/main.c b/src/main.c index 07925aa..721ce6c 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include #include @@ -16,8 +18,14 @@ int main() { users->users[i].display_name); for (uint i = 0; i < sessions->length; i++) - printf("s[%d]: %s %s\n", i, sessions->sessions[i].name, - sessions->sessions[i].path); + printf("s[%d]: %s %s %s\n", i, sessions->sessions[i].type, + sessions->sessions[i].name, sessions->sessions[i].path); + + struct winsize w; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + + printf("lines %d\n", w.ws_row); + printf("columns %d\n", w.ws_col); return 0; } diff --git a/src/sessions.c b/src/sessions.c index ce7ba02..0aeb8c0 100644 --- a/src/sessions.c +++ b/src/sessions.c @@ -9,12 +9,15 @@ #include #include -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);