Skip to content

Commit 014233e

Browse files
committed
Fixed behavior when user unlocks too early
If user has entered a correct password and pressed enter before the initialization has completed, i3lock used to verify the password but not exit correctly, which was easy to encounter with a high sigma value for blurring. I wonder if there is a more elegant implementation...
1 parent 2b00546 commit 014233e

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

i3lock.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ int failed_attempts = 0;
232232
bool show_failed_attempts = false;
233233
bool retry_verification = false;
234234

235+
/* Set to true by `input_done` when the password is correct.
236+
* Needed if user has entered password before intialization completed. */
237+
bool unlocked = false;
238+
235239
static struct xkb_state *xkb_state;
236240
static struct xkb_context *xkb_context;
237241
static struct xkb_keymap *xkb_keymap;
@@ -564,6 +568,7 @@ static void input_done(void) {
564568

565569
if (no_verify) {
566570
ev_break(EV_DEFAULT, EVBREAK_ALL);
571+
unlocked = true;
567572
return;
568573
}
569574

@@ -578,6 +583,7 @@ static void input_done(void) {
578583
clear_password_memory();
579584

580585
ev_break(EV_DEFAULT, EVBREAK_ALL);
586+
unlocked = true;
581587
return;
582588
}
583589
#else
@@ -593,6 +599,7 @@ static void input_done(void) {
593599
pam_cleanup = true;
594600

595601
ev_break(EV_DEFAULT, EVBREAK_ALL);
602+
unlocked = true;
596603
return;
597604
}
598605
#endif
@@ -2633,19 +2640,24 @@ int main(int argc, char *argv[]) {
26332640
* file descriptor becomes readable). */
26342641
ev_invoke(main_loop, xcb_check, 0);
26352642

2636-
if (show_clock || bar_enabled || slideshow_enabled) {
2637-
if (redraw_thread) {
2638-
struct timespec ts;
2639-
double s;
2640-
double ns = modf(refresh_rate, &s);
2641-
ts.tv_sec = (time_t) s;
2642-
ts.tv_nsec = ns * NANOSECONDS_IN_SECOND;
2643-
(void) pthread_create(&draw_thread, NULL, start_time_redraw_tick_pthread, (void*) &ts);
2644-
} else {
2645-
start_time_redraw_tick(main_loop);
2643+
/* If the user was fast enough to have typed their password (and pressed Enter) before
2644+
* i3lock has finished intializing, all of that is processed in the above `ev_invoke`.
2645+
* If the password was correct (`unlocked` is true), we should not enter the event loop. */
2646+
if (!unlocked) {
2647+
if (show_clock || bar_enabled || slideshow_enabled) {
2648+
if (redraw_thread) {
2649+
struct timespec ts;
2650+
double s;
2651+
double ns = modf(refresh_rate, &s);
2652+
ts.tv_sec = (time_t) s;
2653+
ts.tv_nsec = ns * NANOSECONDS_IN_SECOND;
2654+
(void) pthread_create(&draw_thread, NULL, start_time_redraw_tick_pthread, (void*) &ts);
2655+
} else {
2656+
start_time_redraw_tick(main_loop);
2657+
}
26462658
}
2659+
ev_loop(main_loop, 0);
26472660
}
2648-
ev_loop(main_loop, 0);
26492661

26502662
#ifndef __OpenBSD__
26512663
if (pam_cleanup) {

0 commit comments

Comments
 (0)