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.
This commit is contained in:
parent
1d3e62c67f
commit
75e837c31a
@ -87,6 +87,7 @@ struct swaylock_state {
|
|||||||
cairo_surface_t *test_surface;
|
cairo_surface_t *test_surface;
|
||||||
cairo_t *test_cairo; // used to estimate font/text sizes
|
cairo_t *test_cairo; // used to estimate font/text sizes
|
||||||
enum auth_state auth_state;
|
enum auth_state auth_state;
|
||||||
|
uint32_t highlight_start; // position of highlight; 2048 = 1 full turn
|
||||||
int failed_attempts;
|
int failed_attempts;
|
||||||
bool run_display, locked;
|
bool run_display, locked;
|
||||||
struct ext_session_lock_manager_v1 *ext_session_lock_manager_v1;
|
struct ext_session_lock_manager_v1 *ext_session_lock_manager_v1;
|
||||||
|
@ -93,6 +93,12 @@ static void submit_password(struct swaylock_state *state) {
|
|||||||
damage_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,
|
void swaylock_handle_key(struct swaylock_state *state,
|
||||||
xkb_keysym_t keysym, uint32_t codepoint) {
|
xkb_keysym_t keysym, uint32_t codepoint) {
|
||||||
// Ignore input events if validating
|
// Ignore input events if validating
|
||||||
@ -109,6 +115,7 @@ void swaylock_handle_key(struct swaylock_state *state,
|
|||||||
case XKB_KEY_BackSpace:
|
case XKB_KEY_BackSpace:
|
||||||
if (backspace(&state->password)) {
|
if (backspace(&state->password)) {
|
||||||
state->auth_state = AUTH_STATE_BACKSPACE;
|
state->auth_state = AUTH_STATE_BACKSPACE;
|
||||||
|
update_highlight(state);
|
||||||
} else {
|
} else {
|
||||||
state->auth_state = AUTH_STATE_CLEAR;
|
state->auth_state = AUTH_STATE_CLEAR;
|
||||||
}
|
}
|
||||||
@ -160,6 +167,7 @@ void swaylock_handle_key(struct swaylock_state *state,
|
|||||||
if (codepoint) {
|
if (codepoint) {
|
||||||
append_ch(&state->password, codepoint);
|
append_ch(&state->password, codepoint);
|
||||||
state->auth_state = AUTH_STATE_INPUT;
|
state->auth_state = AUTH_STATE_INPUT;
|
||||||
|
update_highlight(state);
|
||||||
damage_state(state);
|
damage_state(state);
|
||||||
schedule_indicator_clear(state);
|
schedule_indicator_clear(state);
|
||||||
schedule_password_clear(state);
|
schedule_password_clear(state);
|
||||||
|
4
render.c
4
render.c
@ -271,9 +271,7 @@ void render_frame(struct swaylock_surface *surface) {
|
|||||||
// Typing indicator: Highlight random part on keypress
|
// Typing indicator: Highlight random part on keypress
|
||||||
if (state->auth_state == AUTH_STATE_INPUT
|
if (state->auth_state == AUTH_STATE_INPUT
|
||||||
|| state->auth_state == AUTH_STATE_BACKSPACE) {
|
|| state->auth_state == AUTH_STATE_BACKSPACE) {
|
||||||
static double highlight_start = 0;
|
double highlight_start = state->highlight_start * (M_PI / 1024.0);
|
||||||
highlight_start +=
|
|
||||||
(rand() % (int)(M_PI * 100)) / 100.0 + M_PI * 0.5;
|
|
||||||
cairo_arc(cairo, buffer_width / 2, buffer_diameter / 2,
|
cairo_arc(cairo, buffer_width / 2, buffer_diameter / 2,
|
||||||
arc_radius, highlight_start,
|
arc_radius, highlight_start,
|
||||||
highlight_start + TYPE_INDICATOR_RANGE);
|
highlight_start + TYPE_INDICATOR_RANGE);
|
||||||
|
Loading…
Reference in New Issue
Block a user