mirror of
https://github.com/javalsai/lidm.git
synced 2025-09-01 02:47:59 +02:00
chore: organize code
add -Wextra by default pipefd to communicate better with parent and forked process rustify some stuff add the desktop parser to the file read
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
#include "config.h"
|
||||
#include "sessions.h"
|
||||
|
||||
bool launch(char* user, char* passwd, struct session session, void (*cb)(void),
|
||||
struct config* config);
|
||||
bool launch(char* NNULLABLE user, char* NNULLABLE passwd,
|
||||
struct session session, void (*NULLABLE cb)(void),
|
||||
struct config* NNULLABLE config);
|
||||
|
||||
#endif
|
||||
|
@@ -150,15 +150,15 @@ struct introspection_table {
|
||||
|
||||
static const struct introspection_table CONFIG_INSTROSPECTION[] = {
|
||||
{"colors", offsetof(struct config, colors), INTROS_TABLE_COLORS,
|
||||
sizeof(INTROS_TABLE_COLORS) / sizeof(INTROS_TABLE_COLORS[0])},
|
||||
LEN(INTROS_TABLE_COLORS)},
|
||||
{"chars", offsetof(struct config, chars), INTROS_TABLE_CHARS,
|
||||
sizeof(INTROS_TABLE_CHARS) / sizeof(INTROS_TABLE_CHARS[0])},
|
||||
LEN(INTROS_TABLE_CHARS)},
|
||||
{"functions", offsetof(struct config, functions), INTROS_TABLE_FUNCTIONS,
|
||||
sizeof(INTROS_TABLE_FUNCTIONS) / sizeof(INTROS_TABLE_FUNCTIONS[0])},
|
||||
LEN(INTROS_TABLE_FUNCTIONS)},
|
||||
{"strings", offsetof(struct config, strings), INTROS_TABLE_STRINGS,
|
||||
sizeof(INTROS_TABLE_STRINGS) / sizeof(INTROS_TABLE_STRINGS[0])},
|
||||
LEN(INTROS_TABLE_STRINGS)},
|
||||
{"behavior", offsetof(struct config, behavior), INTROS_TABLE_BEHAVIOR,
|
||||
sizeof(INTROS_TABLE_BEHAVIOR) / sizeof(INTROS_TABLE_BEHAVIOR[0])},
|
||||
LEN(INTROS_TABLE_BEHAVIOR)},
|
||||
};
|
||||
|
||||
//// FUNCTIONS
|
||||
|
@@ -36,5 +36,6 @@
|
||||
#endif
|
||||
|
||||
#define LEN(X) (sizeof(X) / sizeof((X)[0]))
|
||||
#define UNUSED(x) ((void)(x))
|
||||
|
||||
#endif
|
||||
|
@@ -24,7 +24,6 @@ struct pamh_getenv_status {
|
||||
|
||||
// Doesn't include `source`s
|
||||
struct pamh_getenv_status pamh_get_complete_env(pam_handle_t* handle,
|
||||
char* NNULLABLE user,
|
||||
struct passwd* NNULLABLE pw,
|
||||
enum SessionType session_typ);
|
||||
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#define SESSIONSH_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "macros.h"
|
||||
#include "util.h"
|
||||
@@ -12,10 +13,58 @@ enum SessionType {
|
||||
SHELL,
|
||||
};
|
||||
|
||||
enum ExecType {
|
||||
EXEC_SHELL,
|
||||
EXEC_DESKTOP,
|
||||
};
|
||||
|
||||
struct desktop_exec {
|
||||
char** args;
|
||||
int arg_count;
|
||||
};
|
||||
|
||||
struct session_exec {
|
||||
enum ExecType typ;
|
||||
union {
|
||||
char* shell;
|
||||
struct desktop_exec desktop;
|
||||
};
|
||||
};
|
||||
|
||||
static inline struct session_exec session_exec_shell(char* shell) {
|
||||
return (struct session_exec){
|
||||
.typ = EXEC_SHELL,
|
||||
.shell = shell,
|
||||
};
|
||||
}
|
||||
|
||||
static inline struct session_exec session_exec_desktop(int arg_count,
|
||||
char** args) {
|
||||
return (struct session_exec){
|
||||
.typ = EXEC_DESKTOP,
|
||||
.desktop =
|
||||
{
|
||||
.args = args,
|
||||
.arg_count = arg_count,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
static inline int session_exec_exec(struct session_exec* exec,
|
||||
char** NNULLABLE envlist) {
|
||||
switch (exec->typ) {
|
||||
case EXEC_SHELL:
|
||||
return execle(exec->shell, exec->shell, NULL, envlist);
|
||||
case EXEC_DESKTOP:
|
||||
return execve(exec->desktop.args[0], exec->desktop.args, envlist);
|
||||
default:
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
struct session {
|
||||
char* NNULLABLE name;
|
||||
char* NNULLABLE exec;
|
||||
char* NULLABLE tryexec;
|
||||
struct session_exec exec;
|
||||
enum SessionType type;
|
||||
};
|
||||
|
||||
|
@@ -11,11 +11,17 @@
|
||||
#include "keys.h"
|
||||
|
||||
int find_keyname(enum Keys* at, const char* name);
|
||||
enum Keys find_ansi(const char* seq);
|
||||
struct option_keys {
|
||||
bool is_some;
|
||||
enum Keys key;
|
||||
};
|
||||
struct option_keys find_ansi(const char* seq);
|
||||
void read_press(u_char* length, char* out);
|
||||
// non blocking, waits up to tv or interrupt, returns true if actually read
|
||||
bool read_press_nb(u_char* length, char* out, struct timeval* tv);
|
||||
|
||||
// UTF8
|
||||
//
|
||||
bool utf8_iscont(char byte);
|
||||
size_t utf8len(const char* str);
|
||||
size_t utf8len_until(const char* str, const char* until);
|
||||
@@ -24,6 +30,8 @@ const char* utf8back(const char* str);
|
||||
const char* utf8seek(const char* str);
|
||||
const char* utf8seekn(const char* str, size_t n);
|
||||
|
||||
// Vector
|
||||
//
|
||||
struct Vector {
|
||||
uint32_t length;
|
||||
uint32_t capacity;
|
||||
|
Reference in New Issue
Block a user