summaryrefslogtreecommitdiff
path: root/password.c
diff options
context:
space:
mode:
Diffstat (limited to 'password.c')
-rw-r--r--password.c83
1 files changed, 59 insertions, 24 deletions
diff --git a/password.c b/password.c
index c4950b3..8dabb52 100644
--- a/password.c
+++ b/password.c
@@ -46,28 +46,50 @@ static void append_ch(struct swaylock_password *pw, uint32_t codepoint) {
pw->len += utf8_size;
}
-static void clear_indicator(void *data) {
+static void set_input_idle(void *data) {
struct swaylock_state *state = data;
- state->clear_indicator_timer = NULL;
+ state->input_idle_timer = NULL;
+ state->input_state = INPUT_STATE_IDLE;
+ damage_state(state);
+}
+
+static void set_auth_idle(void *data) {
+ struct swaylock_state *state = data;
+ state->auth_idle_timer = NULL;
state->auth_state = AUTH_STATE_IDLE;
damage_state(state);
}
-void schedule_indicator_clear(struct swaylock_state *state) {
- if (state->clear_indicator_timer) {
- loop_remove_timer(state->eventloop, state->clear_indicator_timer);
+static void schedule_input_idle(struct swaylock_state *state) {
+ if (state->input_idle_timer) {
+ loop_remove_timer(state->eventloop, state->input_idle_timer);
}
- state->clear_indicator_timer = loop_add_timer(
- state->eventloop, 3000, clear_indicator, state);
+ state->input_idle_timer = loop_add_timer(
+ state->eventloop, 1500, set_input_idle, state);
+}
+
+static void cancel_input_idle(struct swaylock_state *state) {
+ if (state->input_idle_timer) {
+ loop_remove_timer(state->eventloop, state->input_idle_timer);
+ state->input_idle_timer = NULL;
+ }
+}
+
+void schedule_auth_idle(struct swaylock_state *state) {
+ if (state->auth_idle_timer) {
+ loop_remove_timer(state->eventloop, state->auth_idle_timer);
+ }
+ state->auth_idle_timer = loop_add_timer(
+ state->eventloop, 3000, set_auth_idle, state);
}
static void clear_password(void *data) {
struct swaylock_state *state = data;
state->clear_password_timer = NULL;
- state->auth_state = AUTH_STATE_CLEAR;
+ state->input_state = INPUT_STATE_CLEAR;
+ schedule_input_idle(state);
clear_password_buffer(&state->password);
damage_state(state);
- schedule_indicator_clear(state);
}
static void schedule_password_clear(struct swaylock_state *state) {
@@ -78,16 +100,26 @@ static void schedule_password_clear(struct swaylock_state *state) {
state->eventloop, 10000, clear_password, state);
}
+static void cancel_password_clear(struct swaylock_state *state) {
+ if (state->clear_password_timer) {
+ loop_remove_timer(state->eventloop, state->clear_password_timer);
+ state->clear_password_timer = NULL;
+ }
+}
+
static void submit_password(struct swaylock_state *state) {
if (state->args.ignore_empty && state->password.len == 0) {
return;
}
+ state->input_state = INPUT_STATE_IDLE;
state->auth_state = AUTH_STATE_VALIDATING;
+ cancel_password_clear(state);
+ cancel_input_idle(state);
if (!write_comm_request(&state->password)) {
state->auth_state = AUTH_STATE_INVALID;
- schedule_indicator_clear(state);
+ schedule_auth_idle(state);
}
damage_state(state);
@@ -110,20 +142,22 @@ void swaylock_handle_key(struct swaylock_state *state,
case XKB_KEY_Delete:
case XKB_KEY_BackSpace:
if (backspace(&state->password)) {
- state->auth_state = AUTH_STATE_BACKSPACE;
+ state->input_state = INPUT_STATE_BACKSPACE;
+ schedule_password_clear(state);
update_highlight(state);
} else {
- state->auth_state = AUTH_STATE_CLEAR;
+ state->input_state = INPUT_STATE_CLEAR;
+ cancel_password_clear(state);
}
+ schedule_input_idle(state);
damage_state(state);
- schedule_indicator_clear(state);
- schedule_password_clear(state);
break;
case XKB_KEY_Escape:
clear_password_buffer(&state->password);
- state->auth_state = AUTH_STATE_CLEAR;
+ state->input_state = INPUT_STATE_CLEAR;
+ cancel_password_clear(state);
+ schedule_input_idle(state);
damage_state(state);
- schedule_indicator_clear(state);
break;
case XKB_KEY_Caps_Lock:
case XKB_KEY_Shift_L:
@@ -136,10 +170,10 @@ void swaylock_handle_key(struct swaylock_state *state,
case XKB_KEY_Alt_R:
case XKB_KEY_Super_L:
case XKB_KEY_Super_R:
- state->auth_state = AUTH_STATE_INPUT_NOP;
- damage_state(state);
- schedule_indicator_clear(state);
+ state->input_state = INPUT_STATE_NEUTRAL;
schedule_password_clear(state);
+ schedule_input_idle(state);
+ damage_state(state);
break;
case XKB_KEY_m: /* fallthrough */
case XKB_KEY_d:
@@ -153,20 +187,21 @@ void swaylock_handle_key(struct swaylock_state *state,
case XKB_KEY_u:
if (state->xkb.control) {
clear_password_buffer(&state->password);
- state->auth_state = AUTH_STATE_CLEAR;
+ state->input_state = INPUT_STATE_CLEAR;
+ cancel_password_clear(state);
+ schedule_input_idle(state);
damage_state(state);
- schedule_indicator_clear(state);
break;
}
// fallthrough
default:
if (codepoint) {
append_ch(&state->password, codepoint);
- state->auth_state = AUTH_STATE_INPUT;
+ state->input_state = INPUT_STATE_LETTER;
+ schedule_password_clear(state);
+ schedule_input_idle(state);
update_highlight(state);
damage_state(state);
- schedule_indicator_clear(state);
- schedule_password_clear(state);
}
break;
}