mirror of
https://github.com/javalsai/lidm.git
synced 2025-08-31 18:38:00 +02:00
feature: saving previous selection
This commit is contained in:
35
src/launch_state.c
Normal file
35
src/launch_state.c
Normal file
@@ -0,0 +1,35 @@
|
||||
// Small file to save last selection
|
||||
|
||||
#define STATE_PATH "/var/lib/lidm/state"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "launch_state.h"
|
||||
|
||||
static void serialize_lstate(FILE* f, struct LaunchState st) {
|
||||
fprintf(f, "%i;%i", st.user_opt, st.session_opt);
|
||||
}
|
||||
|
||||
static void deserialize_lstate(FILE* f, struct LaunchState* st) {
|
||||
fscanf(f, "%i;%i", &st->user_opt, &st->session_opt);
|
||||
}
|
||||
|
||||
struct LaunchState read_launch_state() {
|
||||
struct LaunchState state;
|
||||
state.user_opt = 1;
|
||||
state.session_opt = 1;
|
||||
FILE* f = fopen(STATE_PATH, "r");
|
||||
if(!f) return state;
|
||||
deserialize_lstate(f, &state);
|
||||
fclose(f);
|
||||
return state;
|
||||
}
|
||||
|
||||
bool write_launch_state(struct LaunchState state) {
|
||||
FILE* f = fopen(STATE_PATH, "w");
|
||||
if(!f) return false;
|
||||
serialize_lstate(f, state);
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
14
src/ui.c
14
src/ui.c
@@ -26,6 +26,7 @@
|
||||
#include "ui_state.h"
|
||||
#include "users.h"
|
||||
#include "util.h"
|
||||
#include "launch_state.h"
|
||||
|
||||
const u_char INPUTS_N = 3;
|
||||
|
||||
@@ -198,6 +199,14 @@ int load(struct Vector* users, struct Vector* sessions) {
|
||||
of_user = ofield_new(users->length);
|
||||
of_passwd = ofield_new(0);
|
||||
|
||||
struct LaunchState initial_state = read_launch_state();
|
||||
if(initial_state.user_opt > users->length || initial_state.session_opt > sessions->length + behavior.include_defshell) {
|
||||
initial_state.user_opt = 1;
|
||||
initial_state.session_opt = 1;
|
||||
}
|
||||
of_user.current_opt = initial_state.user_opt;
|
||||
of_session.current_opt = initial_state.session_opt;
|
||||
|
||||
/// PRINTING
|
||||
const struct uint_point BOXSTART = box_start();
|
||||
|
||||
@@ -254,6 +263,11 @@ int load(struct Vector* users, struct Vector* sessions) {
|
||||
}
|
||||
} else {
|
||||
if (len == 1 && *seq == '\n') {
|
||||
struct LaunchState ls;
|
||||
ls.user_opt = of_user.current_opt;
|
||||
ls.session_opt = of_session.current_opt;
|
||||
write_launch_state(ls);
|
||||
|
||||
if (!launch(st_user().username, of_passwd.efield.content,
|
||||
st_session(g_config->behavior.include_defshell),
|
||||
&restore_all, g_config)) {
|
||||
|
Reference in New Issue
Block a user