|
|
@ -34,6 +34,13 @@ |
|
|
|
#include "unlock_indicator.h" |
|
|
|
#include "xinerama.h" |
|
|
|
|
|
|
|
#define START_TIMER(timer_obj, timeout, callback) \ |
|
|
|
timer_obj = start_timer(timer_obj, timeout, callback) |
|
|
|
#define STOP_TIMER(timer_obj) \ |
|
|
|
timer_obj = stop_timer(timer_obj) |
|
|
|
|
|
|
|
typedef void (*ev_callback_t)(EV_P_ ev_timer *w, int revents); |
|
|
|
|
|
|
|
/* We need this for libxkbfile */ |
|
|
|
static Display *display; |
|
|
|
char color[7] = "ffffff"; |
|
|
@ -51,6 +58,7 @@ bool unlock_indicator = true; |
|
|
|
static bool dont_fork = false; |
|
|
|
struct ev_loop *main_loop; |
|
|
|
static struct ev_timer *clear_pam_wrong_timeout; |
|
|
|
static struct ev_timer *clear_indicator_timeout; |
|
|
|
extern unlock_state_t unlock_state; |
|
|
|
extern pam_state_t pam_state; |
|
|
|
|
|
|
@ -178,6 +186,30 @@ static void clear_password_memory(void) { |
|
|
|
vpassword[c] = c + (int)beep; |
|
|
|
} |
|
|
|
|
|
|
|
ev_timer* start_timer(ev_timer *timer_obj, ev_tstamp timeout, ev_callback_t callback) { |
|
|
|
if (timer_obj) { |
|
|
|
ev_timer_stop(main_loop, timer_obj); |
|
|
|
ev_timer_set(timer_obj, timeout, 0.); |
|
|
|
ev_timer_start(main_loop, timer_obj); |
|
|
|
} else { |
|
|
|
/* When there is no memory, we just don’t have a timeout. We cannot
|
|
|
|
* exit() here, since that would effectively unlock the screen. */ |
|
|
|
timer_obj = calloc(sizeof(struct ev_timer), 1); |
|
|
|
if (timer_obj) { |
|
|
|
ev_timer_init(timer_obj, callback, timeout, 0.); |
|
|
|
ev_timer_start(main_loop, timer_obj); |
|
|
|
} |
|
|
|
} |
|
|
|
return timer_obj; |
|
|
|
} |
|
|
|
|
|
|
|
ev_timer* stop_timer(ev_timer *timer_obj) { |
|
|
|
if (timer_obj) { |
|
|
|
ev_timer_stop(main_loop, timer_obj); |
|
|
|
free(timer_obj); |
|
|
|
} |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
* Resets pam_state to STATE_PAM_IDLE 2 seconds after an unsuccesful |
|
|
@ -196,6 +228,11 @@ static void clear_pam_wrong(EV_P_ ev_timer *w, int revents) { |
|
|
|
clear_pam_wrong_timeout = NULL; |
|
|
|
} |
|
|
|
|
|
|
|
static void clear_indicator_cb(EV_P_ ev_timer *w, int revents) { |
|
|
|
clear_indicator(); |
|
|
|
STOP_TIMER(clear_indicator_timeout); |
|
|
|
} |
|
|
|
|
|
|
|
static void clear_input(void) { |
|
|
|
input_position = 0; |
|
|
|
clear_password_memory(); |
|
|
@ -203,7 +240,7 @@ static void clear_input(void) { |
|
|
|
|
|
|
|
/* Hide the unlock indicator after a bit if the password buffer is
|
|
|
|
* empty. */ |
|
|
|
start_clear_indicator_timeout(); |
|
|
|
START_TIMER(clear_indicator_timeout, 1.0, clear_indicator_cb); |
|
|
|
unlock_state = STATE_BACKSPACE_ACTIVE; |
|
|
|
redraw_screen(); |
|
|
|
unlock_state = STATE_KEY_PRESSED; |
|
|
@ -245,7 +282,7 @@ static void input_done(void) { |
|
|
|
|
|
|
|
/* Cancel the clear_indicator_timeout, it would hide the unlock indicator
|
|
|
|
* too early. */ |
|
|
|
stop_clear_indicator_timeout(); |
|
|
|
STOP_TIMER(clear_indicator_timeout); |
|
|
|
|
|
|
|
/* beep on authentication failure, if enabled */ |
|
|
|
if (beep) { |
|
|
@ -326,7 +363,7 @@ static void handle_key_press(xcb_key_press_event_t *event) { |
|
|
|
|
|
|
|
/* Hide the unlock indicator after a bit if the password buffer is
|
|
|
|
* empty. */ |
|
|
|
start_clear_indicator_timeout(); |
|
|
|
START_TIMER(clear_indicator_timeout, 1.0, clear_indicator_cb); |
|
|
|
unlock_state = STATE_BACKSPACE_ACTIVE; |
|
|
|
redraw_screen(); |
|
|
|
unlock_state = STATE_KEY_PRESSED; |
|
|
@ -365,7 +402,7 @@ static void handle_key_press(xcb_key_press_event_t *event) { |
|
|
|
ev_timer_start(main_loop, timeout); |
|
|
|
} |
|
|
|
|
|
|
|
stop_clear_indicator_timeout(); |
|
|
|
STOP_TIMER(clear_indicator_timeout); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|