diff options
author | Milkey Mouse <milkeymouse@meme.institute> | 2018-12-20 12:32:36 -0800 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-12-23 12:08:03 +0100 |
commit | 82b0296964d58e7029dc3775f58abe7a7fd51ec8 (patch) | |
tree | fd9867fc880bb08e1d253e0e7098019a06de9911 | |
parent | swaylock: Clear password buffer on Ctrl-C (diff) | |
download | sway-82b0296964d58e7029dc3775f58abe7a7fd51ec8.tar.gz sway-82b0296964d58e7029dc3775f58abe7a7fd51ec8.tar.zst sway-82b0296964d58e7029dc3775f58abe7a7fd51ec8.zip |
swaylock: Submit password on Ctrl-D
Ctrl-D functions as EOF in most cases on the terminal. login(1) & many other
programs check the password on EOF, same as Enter. To make behavior consistent,
have swaylock submit the password on Ctrl-D.
This commit moves the handling for Enter into its own static function, which is
now also called on Ctrl-D.
-rw-r--r-- | swaylock/password.c | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/swaylock/password.c b/swaylock/password.c index 44244519..3059203a 100644 --- a/swaylock/password.c +++ b/swaylock/password.c | |||
@@ -77,52 +77,56 @@ static void handle_preverify_timeout(void *data) { | |||
77 | state->verify_password_timer = NULL; | 77 | state->verify_password_timer = NULL; |
78 | } | 78 | } |
79 | 79 | ||
80 | void swaylock_handle_key(struct swaylock_state *state, | 80 | static void submit_password(struct swaylock_state *state) { |
81 | xkb_keysym_t keysym, uint32_t codepoint) { | 81 | if (state->args.ignore_empty && state->password.len == 0) { |
82 | switch (keysym) { | 82 | return; |
83 | case XKB_KEY_KP_Enter: /* fallthrough */ | 83 | } |
84 | case XKB_KEY_Return: | ||
85 | if (state->args.ignore_empty && state->password.len == 0) { | ||
86 | break; | ||
87 | } | ||
88 | 84 | ||
89 | state->auth_state = AUTH_STATE_VALIDATING; | 85 | state->auth_state = AUTH_STATE_VALIDATING; |
90 | damage_state(state); | 86 | damage_state(state); |
91 | 87 | ||
92 | // We generally want to wait until all surfaces are showing the | 88 | // We generally want to wait until all surfaces are showing the |
93 | // "verifying" state before we go and verify the password, because | 89 | // "verifying" state before we go and verify the password, because |
94 | // 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 |
95 | // 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. |
96 | state->verify_password_timer = loop_add_timer( | 92 | state->verify_password_timer = loop_add_timer( |
97 | state->eventloop, 50, handle_preverify_timeout, state); | 93 | state->eventloop, 50, handle_preverify_timeout, state); |
98 | 94 | ||
99 | while (state->run_display && state->verify_password_timer) { | 95 | while (state->run_display && state->verify_password_timer) { |
100 | errno = 0; | 96 | errno = 0; |
101 | if (wl_display_flush(state->display) == -1 && errno != EAGAIN) { | 97 | if (wl_display_flush(state->display) == -1 && errno != EAGAIN) { |
102 | break; | 98 | break; |
103 | } | 99 | } |
104 | loop_poll(state->eventloop); | 100 | loop_poll(state->eventloop); |
105 | 101 | ||
106 | bool ok = 1; | 102 | bool ok = 1; |
107 | struct swaylock_surface *surface; | 103 | struct swaylock_surface *surface; |
108 | wl_list_for_each(surface, &state->surfaces, link) { | 104 | wl_list_for_each(surface, &state->surfaces, link) { |
109 | if (surface->dirty) { | 105 | if (surface->dirty) { |
110 | ok = 0; | 106 | ok = 0; |
111 | } | ||
112 | } | ||
113 | if (ok) { | ||
114 | break; | ||
115 | } | 107 | } |
116 | } | 108 | } |
117 | wl_display_flush(state->display); | 109 | if (ok) { |
118 | |||
119 | if (attempt_password(&state->password)) { | ||
120 | state->run_display = false; | ||
121 | break; | 110 | break; |
122 | } | 111 | } |
123 | state->auth_state = AUTH_STATE_INVALID; | 112 | } |
124 | damage_state(state); | 113 | wl_display_flush(state->display); |
125 | 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 | |||
124 | void 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); | ||
126 | break; | 130 | break; |
127 | case XKB_KEY_Delete: | 131 | case XKB_KEY_Delete: |
128 | case XKB_KEY_BackSpace: | 132 | case XKB_KEY_BackSpace: |
@@ -165,6 +169,12 @@ void swaylock_handle_key(struct swaylock_state *state, | |||
165 | schedule_indicator_clear(state); | 169 | schedule_indicator_clear(state); |
166 | schedule_password_clear(state); | 170 | schedule_password_clear(state); |
167 | break; | 171 | break; |
172 | case XKB_KEY_d: | ||
173 | if (state->xkb.control) { | ||
174 | submit_password(state); | ||
175 | break; | ||
176 | } | ||
177 | // fallthrough | ||
168 | case XKB_KEY_c: /* fallthrough */ | 178 | case XKB_KEY_c: /* fallthrough */ |
169 | case XKB_KEY_u: | 179 | case XKB_KEY_u: |
170 | if (state->xkb.control) { | 180 | if (state->xkb.control) { |