#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";
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;
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
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();
/* 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;
/* 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) {
/* 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;
ev_timer_start(main_loop, timeout);
}
- stop_clear_indicator_timeout();
+ STOP_TIMER(clear_indicator_timeout);
}
/*
* characters of the password have already been entered or not. */
int input_position;
-/* The ev main loop. */
-struct ev_loop *main_loop;
-
/* The lock window. */
extern xcb_window_t win;
* Local variables.
******************************************************************************/
-static struct ev_timer *clear_indicator_timeout;
-
/* Cache the screen’s visual, necessary for creating a Cairo context. */
static xcb_visualtype_t *vistype;
* password buffer.
*
*/
-static void clear_indicator(EV_P_ ev_timer *w, int revents) {
+void clear_indicator(void) {
if (input_position == 0) {
unlock_state = STATE_STARTED;
} else unlock_state = STATE_KEY_PRESSED;
redraw_screen();
-
- ev_timer_stop(main_loop, clear_indicator_timeout);
- free(clear_indicator_timeout);
- clear_indicator_timeout = NULL;
-}
-
-/*
- * (Re-)starts the clear_indicator timeout. Called after pressing backspace or
- * after an unsuccessful authentication attempt.
- *
- */
-void start_clear_indicator_timeout(void) {
- if (clear_indicator_timeout) {
- ev_timer_stop(main_loop, clear_indicator_timeout);
- ev_timer_set(clear_indicator_timeout, 1.0, 0.);
- ev_timer_start(main_loop, clear_indicator_timeout);
- } else {
- /* When there is no memory, we just don’t have a timeout. We cannot
- * exit() here, since that would effectively unlock the screen. */
- if (!(clear_indicator_timeout = calloc(sizeof(struct ev_timer), 1)))
- return;
- ev_timer_init(clear_indicator_timeout, clear_indicator, 1.0, 0.);
- ev_timer_start(main_loop, clear_indicator_timeout);
- }
-}
-
-/*
- * Stops the clear_indicator timeout.
- *
- */
-void stop_clear_indicator_timeout(void) {
- if (clear_indicator_timeout) {
- ev_timer_stop(main_loop, clear_indicator_timeout);
- free(clear_indicator_timeout);
- clear_indicator_timeout = NULL;
- }
}