summaryrefslogtreecommitdiffstats
path: root/swaylock/password.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaylock/password.c')
-rw-r--r--swaylock/password.c96
1 files changed, 49 insertions, 47 deletions
diff --git a/swaylock/password.c b/swaylock/password.c
index 6138e1fe..3bd113ad 100644
--- a/swaylock/password.c
+++ b/swaylock/password.c
@@ -1,4 +1,3 @@
1#define _XOPEN_SOURCE 500
2#include <assert.h> 1#include <assert.h>
3#include <errno.h> 2#include <errno.h>
4#include <pwd.h> 3#include <pwd.h>
@@ -78,52 +77,56 @@ static void handle_preverify_timeout(void *data) {
78 state->verify_password_timer = NULL; 77 state->verify_password_timer = NULL;
79} 78}
80 79
81void swaylock_handle_key(struct swaylock_state *state, 80static void submit_password(struct swaylock_state *state) {
82 xkb_keysym_t keysym, uint32_t codepoint) { 81 if (state->args.ignore_empty && state->password.len == 0) {
83 switch (keysym) { 82 return;
84 case XKB_KEY_KP_Enter: /* fallthrough */ 83 }
85 case XKB_KEY_Return:
86 if (state->args.ignore_empty && state->password.len == 0) {
87 break;
88 }
89 84
90 state->auth_state = AUTH_STATE_VALIDATING; 85 state->auth_state = AUTH_STATE_VALIDATING;
91 damage_state(state); 86 damage_state(state);
92 87
93 // We generally want to wait until all surfaces are showing the 88 // We generally want to wait until all surfaces are showing the
94 // "verifying" state before we go and verify the password, because 89 // "verifying" state before we go and verify the password, because
95 // verifying it is a blocking operation. However, if the surface is on 90 // verifying it is a blocking operation. However, if the surface is on
96 // an output with DPMS off then it won't update, so we set a timer. 91 // an output with DPMS off then it won't update, so we set a timer.
97 state->verify_password_timer = loop_add_timer( 92 state->verify_password_timer = loop_add_timer(
98 state->eventloop, 50, handle_preverify_timeout, state); 93 state->eventloop, 50, handle_preverify_timeout, state);
99 94
100 while (state->run_display && state->verify_password_timer) { 95 while (state->run_display && state->verify_password_timer) {
101 errno = 0; 96 errno = 0;
102 if (wl_display_flush(state->display) == -1 && errno != EAGAIN) { 97 if (wl_display_flush(state->display) == -1 && errno != EAGAIN) {
103 break; 98 break;
104 } 99 }
105 loop_poll(state->eventloop); 100 loop_poll(state->eventloop);
106 101
107 bool ok = 1; 102 bool ok = 1;
108 struct swaylock_surface *surface; 103 struct swaylock_surface *surface;
109 wl_list_for_each(surface, &state->surfaces, link) { 104 wl_list_for_each(surface, &state->surfaces, link) {
110 if (surface->dirty) { 105 if (surface->dirty) {
111 ok = 0; 106 ok = 0;
112 }
113 }
114 if (ok) {
115 break;
116 } 107 }
117 } 108 }
118 wl_display_flush(state->display); 109 if (ok) {
119
120 if (attempt_password(&state->password)) {
121 state->run_display = false;
122 break; 110 break;
123 } 111 }
124 state->auth_state = AUTH_STATE_INVALID; 112 }
125 damage_state(state); 113 wl_display_flush(state->display);
126 schedule_indicator_clear(state); 114
115 if (attempt_password(&state->password)) {
116 state->run_display = false;
117 return;
118 }
119 state->auth_state = AUTH_STATE_INVALID;
120 damage_state(state);
121 schedule_indicator_clear(state);
122}
123
124void swaylock_handle_key(struct swaylock_state *state,
125 xkb_keysym_t keysym, uint32_t codepoint) {
126 switch (keysym) {
127 case XKB_KEY_KP_Enter: /* fallthrough */
128 case XKB_KEY_Return:
129 submit_password(state);
127 break; 130 break;
128 case XKB_KEY_Delete: 131 case XKB_KEY_Delete:
129 case XKB_KEY_BackSpace: 132 case XKB_KEY_BackSpace:
@@ -143,14 +146,6 @@ void swaylock_handle_key(struct swaylock_state *state,
143 schedule_indicator_clear(state); 146 schedule_indicator_clear(state);
144 break; 147 break;
145 case XKB_KEY_Caps_Lock: 148 case XKB_KEY_Caps_Lock:
146 /* The state is getting active after this
147 * so we need to manually toggle it */
148 state->xkb.caps_lock = !state->xkb.caps_lock;
149 state->auth_state = AUTH_STATE_INPUT_NOP;
150 damage_state(state);
151 schedule_indicator_clear(state);
152 schedule_password_clear(state);
153 break;
154 case XKB_KEY_Shift_L: 149 case XKB_KEY_Shift_L:
155 case XKB_KEY_Shift_R: 150 case XKB_KEY_Shift_R:
156 case XKB_KEY_Control_L: 151 case XKB_KEY_Control_L:
@@ -166,6 +161,13 @@ void swaylock_handle_key(struct swaylock_state *state,
166 schedule_indicator_clear(state); 161 schedule_indicator_clear(state);
167 schedule_password_clear(state); 162 schedule_password_clear(state);
168 break; 163 break;
164 case XKB_KEY_d:
165 if (state->xkb.control) {
166 submit_password(state);
167 break;
168 }
169 // fallthrough
170 case XKB_KEY_c: /* fallthrough */
169 case XKB_KEY_u: 171 case XKB_KEY_u:
170 if (state->xkb.control) { 172 if (state->xkb.control) {
171 clear_password_buffer(&state->password); 173 clear_password_buffer(&state->password);