summaryrefslogtreecommitdiff
path: root/unlock_indicator.c
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2012-01-03 22:18:33 +0000
committerMichael Stapelberg <michael@stapelberg.de>2012-01-03 22:18:33 +0000
commit0e7e009f4500e970c3ec7e598350d1859724ec7e (patch)
treef92ddb62a6bb032728b20ad64e3e5212b5807d97 /unlock_indicator.c
parentf94fb9b5f8705065e0e7a244adce0f785ba700ee (diff)
Properly free timeouts, move one of the timeouts to unlock_indicator.c
Diffstat (limited to 'unlock_indicator.c')
-rw-r--r--unlock_indicator.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/unlock_indicator.c b/unlock_indicator.c
index 2c4d054..de2e2c2 100644
--- a/unlock_indicator.c
+++ b/unlock_indicator.c
@@ -11,6 +11,7 @@
#include <math.h>
#include <xcb/xcb.h>
#include <xcb/xcb_keysyms.h>
+#include <ev.h>
#ifndef NOLIBCAIRO
#include <cairo.h>
@@ -29,6 +30,13 @@
* Variables defined in i3lock.c.
******************************************************************************/
+/* The current position in the input buffer. Useful to determine if any
+ * 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;
@@ -49,6 +57,8 @@ 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;
@@ -240,3 +250,51 @@ void redraw_screen() {
xcb_free_pixmap(conn, bg_pixmap);
xcb_flush(conn);
}
+
+/*
+ * Hides the unlock indicator completely when there is no content in the
+ * password buffer.
+ *
+ */
+static void clear_indicator(EV_P_ ev_timer *w, int revents) {
+ 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() {
+ 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() {
+ if (clear_indicator_timeout) {
+ ev_timer_stop(main_loop, clear_indicator_timeout);
+ free(clear_indicator_timeout);
+ clear_indicator_timeout = NULL;
+ }
+}