diff options
author | Vytautas Šaltenis <vytas@rtfb.lt> | 2014-03-06 22:22:02 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2014-03-11 09:11:20 +0100 |
commit | 2509c987d1d01a1890521a0c9d087dedbc7103dc (patch) | |
tree | 30038523f989d8e2d1dee443c8e97fc1f4d8ca9d /unlock_indicator.c | |
parent | d91fdc368e4e119f4673e23741dbf2718624de45 (diff) |
Extract start/stop timer code to reusable funcs
Diffstat (limited to 'unlock_indicator.c')
-rw-r--r-- | unlock_indicator.c | 43 |
1 files changed, 1 insertions, 42 deletions
diff --git a/unlock_indicator.c b/unlock_indicator.c index 5e4015c..daaeeb1 100644 --- a/unlock_indicator.c +++ b/unlock_indicator.c @@ -31,9 +31,6 @@ * 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; @@ -55,8 +52,6 @@ extern char color[7]; * 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; @@ -279,45 +274,9 @@ void redraw_screen(void) { * 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; - } } |