mirror of
https://github.com/javalsai/lidm.git
synced 2025-07-03 22:38:41 +02:00
feat: add session types
This commit is contained in:
parent
07d2842be0
commit
490a370546
@ -1,6 +1,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
struct session {
|
struct session {
|
||||||
|
const char *type;
|
||||||
char *name;
|
char *name;
|
||||||
char *path;
|
char *path;
|
||||||
};
|
};
|
||||||
|
12
src/main.c
12
src/main.c
@ -1,6 +1,8 @@
|
|||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <sessions.h>
|
#include <sessions.h>
|
||||||
#include <users.h>
|
#include <users.h>
|
||||||
@ -16,8 +18,14 @@ int main() {
|
|||||||
users->users[i].display_name);
|
users->users[i].display_name);
|
||||||
|
|
||||||
for (uint i = 0; i < sessions->length; i++)
|
for (uint i = 0; i < sessions->length; i++)
|
||||||
printf("s[%d]: %s %s\n", i, sessions->sessions[i].name,
|
printf("s[%d]: %s %s %s\n", i, sessions->sessions[i].type,
|
||||||
sessions->sessions[i].path);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,15 @@
|
|||||||
#include <sessions.h>
|
#include <sessions.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
|
|
||||||
static const char *sources[] = {"/usr/share/xsessions",
|
static const char *sources[][2] = {
|
||||||
"/usr/share/wayland-sessions"};
|
{ "xorg", "/usr/share/xsessions" },
|
||||||
|
{ "wl", "/usr/share/wayland-sessions" },
|
||||||
|
};
|
||||||
static const size_t sources_size = sizeof(sources) / sizeof(sources[0]);
|
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;
|
struct session __session;
|
||||||
|
__session.type = type;
|
||||||
strcln(&__session.name, name);
|
strcln(&__session.name, name);
|
||||||
strcln(&__session.path, path);
|
strcln(&__session.path, path);
|
||||||
|
|
||||||
@ -30,6 +33,7 @@ static u_int16_t used_size = 0;
|
|||||||
static struct session *sessions = NULL;
|
static struct session *sessions = NULL;
|
||||||
static struct sessions_list *__sessions_list = 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) {
|
static int fn(const char *fpath, const struct stat *sb, int typeflag) {
|
||||||
// practically impossible to reach this
|
// practically impossible to reach this
|
||||||
// but will prevent break
|
// 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 = realloc(sessions, alloc_size * unit_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
sessions[used_size] = __new_session(buf, fpath);
|
sessions[used_size] = __new_session(session_type, buf, fpath);
|
||||||
used_size++;
|
used_size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +90,8 @@ struct sessions_list *get_avaliable_sessions() {
|
|||||||
sessions = malloc(alloc_size * unit_size);
|
sessions = malloc(alloc_size * unit_size);
|
||||||
|
|
||||||
for (uint i = 0; i < sources_size; i++) {
|
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);
|
sessions = realloc(sessions, used_size * unit_size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user