From 75e837c31abe2fa06167b6f1f1a253ab397faf81 Mon Sep 17 00:00:00 2001 From: Manuel Stoeckl Date: Tue, 28 Mar 2023 19:42:19 -0400 Subject: Synchronize highlight position between outputs This change has the additional benefit of ensuring that the position of the highlight only changes in reaction to a letter key or backspace being pressed, and not when the compositor sends a new configure event or the output needs to be redrawn for some other reason. --- password.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'password.c') diff --git a/password.c b/password.c index a3e7674..aa3d101 100644 --- a/password.c +++ b/password.c @@ -93,6 +93,12 @@ static void submit_password(struct swaylock_state *state) { damage_state(state); } +static void update_highlight(struct swaylock_state *state) { + // Advance a random amount between 1/4 and 3/4 of a full turn + state->highlight_start = + (state->highlight_start + (rand() % 1024) + 512) % 2048; +} + void swaylock_handle_key(struct swaylock_state *state, xkb_keysym_t keysym, uint32_t codepoint) { // Ignore input events if validating @@ -109,6 +115,7 @@ void swaylock_handle_key(struct swaylock_state *state, case XKB_KEY_BackSpace: if (backspace(&state->password)) { state->auth_state = AUTH_STATE_BACKSPACE; + update_highlight(state); } else { state->auth_state = AUTH_STATE_CLEAR; } @@ -160,6 +167,7 @@ void swaylock_handle_key(struct swaylock_state *state, if (codepoint) { append_ch(&state->password, codepoint); state->auth_state = AUTH_STATE_INPUT; + update_highlight(state); damage_state(state); schedule_indicator_clear(state); schedule_password_clear(state); -- cgit v1.2.3