aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Magahern <james@magahern.com>2019-02-09 15:48:14 -0800
committerJames Magahern <james@magahern.com>2019-02-09 15:48:14 -0800
commit8dc7eb8b2fa9b6614cff27173cb556b4410ed6e2 (patch)
treebe2bd9d5d0f3f42f405bc403a9f50436899cf0c7
parentNeed to make sure to mark pw field as dirty when updating via xsl input too (diff)
Clean up the cursor animation a bit
Now the cursor won't start fading again until a short delay after the last keypress
-rw-r--r--src/animation.c3
-rw-r--r--src/main.c42
-rw-r--r--src/render.c2
3 files changed, 31 insertions, 16 deletions
diff --git a/src/animation.c b/src/animation.c
index 0ec403b..930c823 100644
--- a/src/animation.c
+++ b/src/animation.c
@@ -6,6 +6,7 @@
#include "animation.h"
#include <stdlib.h>
+#include <sys/param.h>
/*
* Easing functions
@@ -43,7 +44,7 @@ anim_time_interval_t anim_now()
double anim_progress_ease(animation_t *anim, const double duration, AnimationEasingFunc easing_f)
{
const anim_time_interval_t now = anim_now();
- double progress = (now - anim->start_time) / duration;
+ double progress = MAX(0.0, now - anim->start_time) / duration;
progress = easing_f(progress);
return (anim->direction == IN) ? progress : (1.0 - progress);
diff --git a/src/main.c b/src/main.c
index 4881b60..c62f482 100644
--- a/src/main.c
+++ b/src/main.c
@@ -27,9 +27,9 @@ static inline saver_state_t* saver_state(void *c)
static void clear_password(saver_state_t *state);
static void accept_password(saver_state_t *state);
-static int poll_events(saver_state_t *state);
+static void poll_events(saver_state_t *state);
-static void handle_key_event(saver_state_t *state, XKeyEvent *event);
+static bool handle_key_event(saver_state_t *state, XKeyEvent *event);
static void handle_xsl_key_input(saver_state_t *state, const char c);
static void window_changed_size(saver_state_t *state, XConfigureEvent *event);
@@ -97,20 +97,19 @@ static void handle_xsl_key_input(saver_state_t *state, const char c)
}
break;
}
-
- set_layer_needs_draw(state, LAYER_PASSWORD, true);
}
// This input handler is only when the locker is being run in "X11 mode" for development
// (See comment above for why this is separate)
-static void handle_key_event(saver_state_t *state, XKeyEvent *event)
+static bool handle_key_event(saver_state_t *state, XKeyEvent *event)
{
- if (!state->input_allowed) return;
+ if (!state->input_allowed) return false;
KeySym key;
char keybuf[8];
XLookupString(event, keybuf, sizeof(keybuf), &key, NULL);
+ bool handled = true;
char *password_buf = state->password_buffer;
size_t length = strlen(password_buf);
if (XK_BackSpace == key) {
@@ -125,14 +124,17 @@ static void handle_key_event(saver_state_t *state, XKeyEvent *event)
password_buf[length] = keybuf[0];
password_buf[length + 1] = '\0';
}
+ } else {
+ handled = false;
}
- set_layer_needs_draw(state, LAYER_PASSWORD, true);
+ return handled;
}
-static int poll_events(saver_state_t *state)
+static void poll_events(saver_state_t *state)
{
XEvent e;
+ bool handled_key_event = false;
const bool block_for_next_event = false;
// Via xsecurelock, take this route
@@ -140,6 +142,7 @@ static int poll_events(saver_state_t *state)
ssize_t read_res = read(kXSecureLockCharFD, &buf, 1);
if (read_res > 0) {
handle_xsl_key_input(state, buf);
+ handled_key_event = true;
}
// Temp: this should be handled by x11_support
@@ -149,24 +152,35 @@ static int poll_events(saver_state_t *state)
// XNextEvent blocks the caller until an event arrives
XNextEvent(display, &e);
} else {
- return 0;
+ break;
}
switch (e.type) {
case ConfigureNotify:
window_changed_size(state, (XConfigureEvent *)&e);
- return 1;
+ break;
case ButtonPress:
- return -e.xbutton.button;
+ break;
case KeyPress:
- handle_key_event(state, (XKeyEvent *)&e);
- return 1;
+ handled_key_event = handle_key_event(state, (XKeyEvent *)&e);
+ break;
default:
fprintf(stderr, "Dropping unhandled XEevent.type = %d.\n", e.type);
+ break;
}
}
- return 0;
+ if (handled_key_event) {
+ // Mark password layer dirty
+ set_layer_needs_draw(state, LAYER_PASSWORD, true);
+
+ // Reset cursor flash animation
+ animation_t *cursor_anim = get_animation_for_key(state, state->cursor_anim_key);
+ if (cursor_anim) {
+ cursor_anim->start_time = anim_now() + 0.3;
+ cursor_anim->direction = OUT;
+ }
+ }
}
/*
diff --git a/src/render.c b/src/render.c
index 4887628..f48f191 100644
--- a/src/render.c
+++ b/src/render.c
@@ -378,8 +378,8 @@ void draw_password_field(saver_state_t *state)
// Draw cursor
const double x_offset = (num_asterisks * asterisk_width);
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, MIN(state->password_opacity, state->cursor_opacity));
+ draw_background(state, field_x + x_offset, field_y, state->canvas_width, cursor_height);
if (!state->is_processing) {
- draw_background(state, field_x + x_offset, field_y, state->canvas_width, cursor_height);
cairo_rectangle(cr, field_x + x_offset, field_y, cursor_width, cursor_height);
} else {
// Fill asterisks