aboutsummaryrefslogtreecommitdiff
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 @@
-#define _XOPEN_SOURCE 500
#include <assert.h>
#include <errno.h>
#include <pwd.h>
@@ -78,52 +77,56 @@ static void handle_preverify_timeout(void *data) {
state->verify_password_timer = NULL;
}
-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:
- if (state->args.ignore_empty && state->password.len == 0) {
- break;
- }
+static void submit_password(struct swaylock_state *state) {
+ if (state->args.ignore_empty && state->password.len == 0) {
+ return;
+ }
- state->auth_state = AUTH_STATE_VALIDATING;
- damage_state(state);
+ state->auth_state = AUTH_STATE_VALIDATING;
+ damage_state(state);
- // We generally want to wait until all surfaces are showing the
- // "verifying" state before we go and verify the password, because
- // verifying it is a blocking operation. However, if the surface is on
- // an output with DPMS off then it won't update, so we set a timer.
- state->verify_password_timer = loop_add_timer(
- state->eventloop, 50, handle_preverify_timeout, state);
+ // We generally want to wait until all surfaces are showing the
+ // "verifying" state before we go and verify the password, because
+ // verifying it is a blocking operation. However, if the surface is on
+ // an output with DPMS off then it won't update, so we set a timer.
+ state->verify_password_timer = loop_add_timer(
+ state->eventloop, 50, handle_preverify_timeout, state);
- while (state->run_display && state->verify_password_timer) {
- errno = 0;
- if (wl_display_flush(state->display) == -1 && errno != EAGAIN) {
- break;
- }
- loop_poll(state->eventloop);
+ while (state->run_display && state->verify_password_timer) {
+ errno = 0;
+ if (wl_display_flush(state->display) == -1 && errno != EAGAIN) {
+ break;
+ }
+ loop_poll(state->eventloop);
- bool ok = 1;
- struct swaylock_surface *surface;
- wl_list_for_each(surface, &state->surfaces, link) {
- if (surface->dirty) {
- ok = 0;
- }
- }
- if (ok) {
- break;
+ bool ok = 1;
+ struct swaylock_surface *surface;
+ wl_list_for_each(surface, &state->surfaces, link) {
+ if (surface->dirty) {
+ ok = 0;
}
}
- wl_display_flush(state->display);
-
- if (attempt_password(&state->password)) {
- state->run_display = false;
+ if (ok) {
break;
}
- state->auth_state = AUTH_STATE_INVALID;
- damage_state(state);
- schedule_indicator_clear(state);
+ }
+ wl_display_flush(state->display);
+
+ if (attempt_password(&state->password)) {
+ state->run_display = false;
+ return;
+ }
+ state->auth_state = AUTH_STATE_INVALID;
+ damage_state(state);
+ schedule_indicator_clear(state);
+}
+
+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:
+ submit_password(state);
break;
case XKB_KEY_Delete:
case XKB_KEY_BackSpace:
@@ -143,14 +146,6 @@ void swaylock_handle_key(struct swaylock_state *state,
schedule_indicator_clear(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);
- schedule_indicator_clear(state);
- schedule_password_clear(state);
- break;
case XKB_KEY_Shift_L:
case XKB_KEY_Shift_R:
case XKB_KEY_Control_L:
@@ -166,6 +161,13 @@ void swaylock_handle_key(struct swaylock_state *state,
schedule_indicator_clear(state);
schedule_password_clear(state);
break;
+ case XKB_KEY_d:
+ if (state->xkb.control) {
+ submit_password(state);
+ break;
+ }
+ // fallthrough
+ case XKB_KEY_c: /* fallthrough */
case XKB_KEY_u:
if (state->xkb.control) {
clear_password_buffer(&state->password);