diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-10-14 16:34:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-14 16:34:22 +0200 |
commit | 53d90dd6a82205a20c3e97a8a396048588e1b5ef (patch) | |
tree | 10f5596fd0d90711af66281c38780c5a1d4d724f /swaylock | |
parent | 135f0fc7e7d9435c5f6bd1725b5d3113b23ac991 (diff) | |
parent | c6f153d8f9ad6c961c8dd8e620dc2e8fcb20e7bc (diff) |
Merge pull request #2826 from RyanDwyer/common-eventloop
Implement common event loop for swaybar and swaylock
Diffstat (limited to 'swaylock')
-rw-r--r-- | swaylock/main.c | 14 | ||||
-rw-r--r-- | swaylock/password.c | 62 |
2 files changed, 73 insertions, 3 deletions
diff --git a/swaylock/main.c b/swaylock/main.c index d1384c6f..27bcfe32 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -21,6 +21,7 @@ #include "pool-buffer.h" #include "cairo.h" #include "log.h" +#include "loop.h" #include "readline.h" #include "stringop.h" #include "util.h" @@ -844,6 +845,10 @@ static int load_config(char *path, struct swaylock_state *state, static struct swaylock_state state; +static void display_in(int fd, short mask, void *data) { + wl_display_dispatch(state.display); +} + int main(int argc, char **argv) { wlr_log_init(WLR_DEBUG, NULL); initialize_pw_backend(); @@ -946,9 +951,14 @@ int main(int argc, char **argv) { daemonize(); } + state.eventloop = loop_create(); + loop_add_fd(state.eventloop, wl_display_get_fd(state.display), POLL_IN, + display_in, NULL); + state.run_display = true; - while (wl_display_dispatch(state.display) != -1 && state.run_display) { - // This space intentionally left blank + while (state.run_display) { + wl_display_flush(state.display); + loop_poll(state.eventloop); } free(state.args.font); diff --git a/swaylock/password.c b/swaylock/password.c index 50b81f6b..fecaecbf 100644 --- a/swaylock/password.c +++ b/swaylock/password.c @@ -8,6 +8,7 @@ #include <xkbcommon/xkbcommon.h> #include "swaylock/swaylock.h" #include "swaylock/seat.h" +#include "loop.h" #include "unicode.h" void clear_password_buffer(struct swaylock_password *pw) { @@ -39,6 +40,43 @@ static void append_ch(struct swaylock_password *pw, uint32_t codepoint) { pw->len += utf8_size; } +static void clear_indicator(void *data) { + struct swaylock_state *state = data; + state->clear_indicator_timer = NULL; + state->auth_state = AUTH_STATE_IDLE; + damage_state(state); +} + +static void schedule_indicator_clear(struct swaylock_state *state) { + if (state->clear_indicator_timer) { + loop_remove_timer(state->eventloop, state->clear_indicator_timer); + } + state->clear_indicator_timer = loop_add_timer( + state->eventloop, 3000, clear_indicator, state); +} + +static void clear_password(void *data) { + struct swaylock_state *state = data; + state->clear_password_timer = NULL; + state->auth_state = AUTH_STATE_CLEAR; + clear_password_buffer(&state->password); + damage_state(state); + schedule_indicator_clear(state); +} + +static void schedule_password_clear(struct swaylock_state *state) { + if (state->clear_password_timer) { + loop_remove_timer(state->eventloop, state->clear_password_timer); + } + state->clear_password_timer = loop_add_timer( + state->eventloop, 10000, clear_password, state); +} + +static void handle_preverify_timeout(void *data) { + struct swaylock_state *state = data; + state->verify_password_timer = NULL; +} + void swaylock_handle_key(struct swaylock_state *state, xkb_keysym_t keysym, uint32_t codepoint) { switch (keysym) { @@ -50,7 +88,18 @@ void swaylock_handle_key(struct swaylock_state *state, state->auth_state = AUTH_STATE_VALIDATING; damage_state(state); - while (wl_display_dispatch(state->display) != -1 && state->run_display) { + + // 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) { + wl_display_flush(state->display); + loop_poll(state->eventloop); + bool ok = 1; struct swaylock_surface *surface; wl_list_for_each(surface, &state->surfaces, link) { @@ -70,6 +119,7 @@ void swaylock_handle_key(struct swaylock_state *state, } state->auth_state = AUTH_STATE_INVALID; damage_state(state); + schedule_indicator_clear(state); break; case XKB_KEY_Delete: case XKB_KEY_BackSpace: @@ -79,11 +129,14 @@ void swaylock_handle_key(struct swaylock_state *state, state->auth_state = AUTH_STATE_CLEAR; } damage_state(state); + schedule_indicator_clear(state); + schedule_password_clear(state); break; case XKB_KEY_Escape: clear_password_buffer(&state->password); state->auth_state = AUTH_STATE_CLEAR; damage_state(state); + schedule_indicator_clear(state); break; case XKB_KEY_Caps_Lock: /* The state is getting active after this @@ -91,6 +144,8 @@ void swaylock_handle_key(struct swaylock_state *state, 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: @@ -104,12 +159,15 @@ void swaylock_handle_key(struct swaylock_state *state, case XKB_KEY_Super_R: state->auth_state = AUTH_STATE_INPUT_NOP; damage_state(state); + schedule_indicator_clear(state); + schedule_password_clear(state); break; case XKB_KEY_u: if (state->xkb.control) { clear_password_buffer(&state->password); state->auth_state = AUTH_STATE_CLEAR; damage_state(state); + schedule_indicator_clear(state); break; } // fallthrough @@ -118,6 +176,8 @@ void swaylock_handle_key(struct swaylock_state *state, append_ch(&state->password, codepoint); state->auth_state = AUTH_STATE_INPUT; damage_state(state); + schedule_indicator_clear(state); + schedule_password_clear(state); } break; } |