diff --git a/Makefile b/Makefile index a542b1e..422604c 100644 --- a/Makefile +++ b/Makefile @@ -12,10 +12,10 @@ ALLFLAGS=$(CFLAGS) -I$(IDIR) LIBS=-lpam -_DEPS = log.h util.h ui.h ui_state.h config.h desktop.h auth.h ofield.h efield.h keys.h users.h sessions.h chvt.h macros.h +_DEPS = log.h util.h ui.h ui_state.h config.h desktop.h auth.h ofield.h efield.h keys.h users.h sessions.h chvt.h macros.h launch_state.h DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS)) -_OBJ = main.o log.o util.o ui.o ui_state.o config.o desktop.o auth.o ofield.o efield.o users.o sessions.o chvt.o +_OBJ = main.o log.o util.o ui.o ui_state.o config.o desktop.o auth.o ofield.o efield.o users.o sessions.o chvt.o launch_state.o OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) $(ODIR)/%.o: $(CDIR)/%.c $(DEPS) diff --git a/include/launch_state.h b/include/launch_state.h new file mode 100644 index 0000000..bc05bba --- /dev/null +++ b/include/launch_state.h @@ -0,0 +1,12 @@ +#ifndef _LAUNCHSTATEH_ +#define _LAUNCHSTATEH_ + +struct LaunchState { + int user_opt; + int session_opt; +}; + +struct LaunchState read_launch_state(); +bool write_launch_state(struct LaunchState state); + +#endif diff --git a/src/launch_state.c b/src/launch_state.c new file mode 100644 index 0000000..9ac2ac6 --- /dev/null +++ b/src/launch_state.c @@ -0,0 +1,27 @@ +// Small file to save last selection + +#define STATE_PATH "/var/lib/lidm/state" + +#include +#include + +#include "launch_state.h" + +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; + fscanf(f, "%i;%i", &state.user_opt, &state.session_opt); + fclose(f); + return state; +} + +bool write_launch_state(struct LaunchState state) { + FILE* f = fopen(STATE_PATH, "w"); + if(!f) return false; + fprintf(f, "%i;%i", state.user_opt, state.session_opt); + fclose(f); + return true; +} diff --git a/src/ui.c b/src/ui.c index eb2c463..26c380b 100644 --- a/src/ui.c +++ b/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 + g_config->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)) {