diff options
| author | Manuel Stoeckl <code@mstoeckl.com> | 2023-05-02 21:00:41 -0400 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2023-05-09 12:40:41 +0200 |
| commit | 31ebd85fe09701146b7275de1ec8c8e9ce3c15c6 (patch) | |
| tree | c794f6e7a982a5ffc6d60f3aef0bbec66ce16f8a /password.c | |
| parent | 876965f944f127a32c0265bcaa47f716d9e1451b (diff) | |
Separate input and auth state
This commit establishes separate state machines for auth state (whether
the password submitted is being verified or is wrong) and input state
(typing indicators and clear message -- things relevant to the state of
the password being typed in, before it is submitted.) This makes it
possible to display the auth state while updating the input state (for
example, show that the previously submitted password is 'verifying' or
'wrong' while typing another.)
The two state machines interact only when submitting a password. There
is some interference with the rendering code -- a 'cleared' message
from the input state machine supersedes verifying/wrong messages from
the auth state machine; although since the 'clear' state has a shorter
timeout than the auth 'invalid' state, this is unlikely to hide the 'wrong'
message.
Diffstat (limited to 'password.c')
| -rw-r--r-- | password.c | 83 |
1 files changed, 59 insertions, 24 deletions
@@ -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; } |
