swaylock: implement a proper render loop

This commit is contained in:
emersion 2018-05-25 19:34:36 +01:00
parent e4c54b04ce
commit cc10c7af65
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
4 changed files with 108 additions and 57 deletions

View file

@ -93,58 +93,58 @@ static void append_ch(struct swaylock_password *pw, uint32_t codepoint) {
void swaylock_handle_key(struct swaylock_state *state,
xkb_keysym_t keysym, uint32_t codepoint) {
switch (keysym) {
case XKB_KEY_KP_Enter: /* fallthrough */
case XKB_KEY_Return:
state->auth_state = AUTH_STATE_VALIDATING;
render_frames(state);
wl_display_roundtrip(state->display);
if (attempt_password(&state->password)) {
state->run_display = false;
break;
}
state->auth_state = AUTH_STATE_INVALID;
render_frames(state);
case XKB_KEY_KP_Enter: /* fallthrough */
case XKB_KEY_Return:
state->auth_state = AUTH_STATE_VALIDATING;
damage_state(state);
wl_display_roundtrip(state->display);
if (attempt_password(&state->password)) {
state->run_display = false;
break;
case XKB_KEY_Delete:
case XKB_KEY_BackSpace:
if (backspace(&state->password)) {
state->auth_state = AUTH_STATE_BACKSPACE;
} else {
state->auth_state = AUTH_STATE_CLEAR;
}
render_frames(state);
break;
case XKB_KEY_Escape:
clear_password_buffer(&state->password);
}
state->auth_state = AUTH_STATE_INVALID;
damage_state(state);
break;
case XKB_KEY_Delete:
case XKB_KEY_BackSpace:
if (backspace(&state->password)) {
state->auth_state = AUTH_STATE_BACKSPACE;
} else {
state->auth_state = AUTH_STATE_CLEAR;
render_frames(state);
break;
case XKB_KEY_Caps_Lock:
/* The state is getting active after this
* so we need to manually toggle it */
state->xkb.caps_lock = !state->xkb.caps_lock;
state->auth_state = AUTH_STATE_INPUT_NOP;
render_frames(state);
break;
case XKB_KEY_Shift_L:
case XKB_KEY_Shift_R:
case XKB_KEY_Control_L:
case XKB_KEY_Control_R:
case XKB_KEY_Meta_L:
case XKB_KEY_Meta_R:
case XKB_KEY_Alt_L:
case XKB_KEY_Alt_R:
case XKB_KEY_Super_L:
case XKB_KEY_Super_R:
state->auth_state = AUTH_STATE_INPUT_NOP;
render_frames(state);
break;
default:
if (codepoint) {
append_ch(&state->password, codepoint);
state->auth_state = AUTH_STATE_INPUT;
render_frames(state);
}
break;
}
damage_state(state);
break;
case XKB_KEY_Escape:
clear_password_buffer(&state->password);
state->auth_state = AUTH_STATE_CLEAR;
damage_state(state);
break;
case XKB_KEY_Caps_Lock:
/* The state is getting active after this
* so we need to manually toggle it */
state->xkb.caps_lock = !state->xkb.caps_lock;
state->auth_state = AUTH_STATE_INPUT_NOP;
damage_state(state);
break;
case XKB_KEY_Shift_L:
case XKB_KEY_Shift_R:
case XKB_KEY_Control_L:
case XKB_KEY_Control_R:
case XKB_KEY_Meta_L:
case XKB_KEY_Meta_R:
case XKB_KEY_Alt_L:
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);
break;
default:
if (codepoint) {
append_ch(&state->password, codepoint);
state->auth_state = AUTH_STATE_INPUT;
damage_state(state);
}
break;
}
}