summaryrefslogtreecommitdiffstats
path: root/swaylock/password.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaylock/password.c')
-rw-r--r--swaylock/password.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/swaylock/password.c b/swaylock/password.c
index 9af7fe16..2bdf151f 100644
--- a/swaylock/password.c
+++ b/swaylock/password.c
@@ -50,21 +50,23 @@ static bool attempt_password(struct swaylock_password *pw) {
50 wlr_log(L_ERROR, "pam_end failed"); 50 wlr_log(L_ERROR, "pam_end failed");
51 goto fail; 51 goto fail;
52 } 52 }
53 // PAM freed this 53 // PAM frees this
54 pw->buffer = NULL; 54 pw->buffer = NULL;
55 pw->len = pw->size = 0; 55 pw->len = pw->size = 0;
56 return true; 56 return true;
57fail: 57fail:
58 // PAM freed this 58 // PAM frees this
59 pw->buffer = NULL; 59 pw->buffer = NULL;
60 pw->len = pw->size = 0; 60 pw->len = pw->size = 0;
61 return false; 61 return false;
62} 62}
63 63
64static void backspace(struct swaylock_password *pw) { 64static bool backspace(struct swaylock_password *pw) {
65 if (pw->len != 0) { 65 if (pw->len != 0) {
66 pw->buffer[--pw->len] = 0; 66 pw->buffer[--pw->len] = 0;
67 return true;
67 } 68 }
69 return false;
68} 70}
69 71
70static void append_ch(struct swaylock_password *pw, uint32_t codepoint) { 72static void append_ch(struct swaylock_password *pw, uint32_t codepoint) {
@@ -97,17 +99,27 @@ void swaylock_handle_key(struct swaylock_state *state,
97 switch (keysym) { 99 switch (keysym) {
98 case XKB_KEY_KP_Enter: /* fallthrough */ 100 case XKB_KEY_KP_Enter: /* fallthrough */
99 case XKB_KEY_Return: 101 case XKB_KEY_Return:
102 state->auth_state = AUTH_STATE_VALIDATING;
103 render_frames(state);
100 if (attempt_password(&state->password)) { 104 if (attempt_password(&state->password)) {
101 exit(0); 105 exit(0);
102 } 106 }
107 state->auth_state = AUTH_STATE_INVALID;
108 render_frames(state);
103 break; 109 break;
104 case XKB_KEY_BackSpace: 110 case XKB_KEY_BackSpace:
105 backspace(&state->password); 111 if (backspace(&state->password)) {
112 state->auth_state = AUTH_STATE_BACKSPACE;
113 render_frames(state);
114 }
106 break; 115 break;
107 default: 116 default:
108 if (codepoint) { 117 if (codepoint) {
109 append_ch(&state->password, codepoint); 118 append_ch(&state->password, codepoint);
119 state->auth_state = AUTH_STATE_INPUT;
120 render_frames(state);
110 } 121 }
111 break; 122 break;
112 } 123 }
124 // TODO: Expire state in a few seconds
113} 125}