From 9c833c661ac9e061bf4d666065e3090639f481ff Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 13 Oct 2018 16:14:35 +1000 Subject: swaylock: Use common event loop --- swaylock/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'swaylock') 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); -- cgit v1.2.3 From c242712262c5cb751fc0f89050a7f7a24433b105 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 13 Oct 2018 16:52:13 +1000 Subject: swaylock: Remove indicator after 3 seconds --- swaylock/password.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'swaylock') diff --git a/swaylock/password.c b/swaylock/password.c index 50b81f6b..fb610bf2 100644 --- a/swaylock/password.c +++ b/swaylock/password.c @@ -8,6 +8,7 @@ #include #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,21 @@ static void append_ch(struct swaylock_password *pw, uint32_t codepoint) { pw->len += utf8_size; } +static void clear_indicator(int fd, short mask, 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_event(state->eventloop, state->clear_indicator_timer); + } + state->clear_indicator_timer = loop_add_timer( + state->eventloop, 3000, clear_indicator, state); +} + void swaylock_handle_key(struct swaylock_state *state, xkb_keysym_t keysym, uint32_t codepoint) { switch (keysym) { @@ -79,11 +95,13 @@ void swaylock_handle_key(struct swaylock_state *state, state->auth_state = AUTH_STATE_CLEAR; } damage_state(state); + schedule_indicator_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 +109,7 @@ 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); break; case XKB_KEY_Shift_L: case XKB_KEY_Shift_R: @@ -104,12 +123,14 @@ 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); 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 +139,7 @@ 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); } break; } -- cgit v1.2.3 From fa11b7f7012d153ba9728fe718ffc1a2650d6e98 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 13 Oct 2018 16:56:35 +1000 Subject: swaylock: clear password after 10 seconds --- swaylock/password.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'swaylock') diff --git a/swaylock/password.c b/swaylock/password.c index fb610bf2..5ab50042 100644 --- a/swaylock/password.c +++ b/swaylock/password.c @@ -55,6 +55,23 @@ static void schedule_indicator_clear(struct swaylock_state *state) { state->eventloop, 3000, clear_indicator, state); } +static void clear_password(int fd, short mask, 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_event(state->eventloop, state->clear_password_timer); + } + state->clear_password_timer = loop_add_timer( + state->eventloop, 10000, clear_password, state); +} + void swaylock_handle_key(struct swaylock_state *state, xkb_keysym_t keysym, uint32_t codepoint) { switch (keysym) { @@ -96,6 +113,7 @@ void swaylock_handle_key(struct swaylock_state *state, } damage_state(state); schedule_indicator_clear(state); + schedule_password_clear(state); break; case XKB_KEY_Escape: clear_password_buffer(&state->password); @@ -110,6 +128,7 @@ void swaylock_handle_key(struct swaylock_state *state, 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: @@ -124,6 +143,7 @@ void swaylock_handle_key(struct swaylock_state *state, 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) { @@ -140,6 +160,7 @@ void swaylock_handle_key(struct swaylock_state *state, state->auth_state = AUTH_STATE_INPUT; damage_state(state); schedule_indicator_clear(state); + schedule_password_clear(state); } break; } -- cgit v1.2.3 From f98f351a5275967c46482e1c9c754fee927d72ee Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 13 Oct 2018 17:06:33 +1000 Subject: swaylock: Don't wait too long for surface damage before verifying --- swaylock/password.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'swaylock') diff --git a/swaylock/password.c b/swaylock/password.c index 5ab50042..3f9949b2 100644 --- a/swaylock/password.c +++ b/swaylock/password.c @@ -72,6 +72,11 @@ static void schedule_password_clear(struct swaylock_state *state) { state->eventloop, 10000, clear_password, state); } +static void handle_preverify_timeout(int fd, short mask, 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) { @@ -83,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) { @@ -103,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: -- cgit v1.2.3 From 6921fdc6d6134fd7aaf38ffc1686623eca9bbd18 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 14 Oct 2018 12:28:38 +1000 Subject: Remove timerfd from loop implementation timerfd doesn't work on the BSDs, so this replaces it with a timespec for the expiry and uses a poll timeout to check the timers when needed. --- swaylock/password.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'swaylock') diff --git a/swaylock/password.c b/swaylock/password.c index 3f9949b2..fecaecbf 100644 --- a/swaylock/password.c +++ b/swaylock/password.c @@ -40,7 +40,7 @@ static void append_ch(struct swaylock_password *pw, uint32_t codepoint) { pw->len += utf8_size; } -static void clear_indicator(int fd, short mask, void *data) { +static void clear_indicator(void *data) { struct swaylock_state *state = data; state->clear_indicator_timer = NULL; state->auth_state = AUTH_STATE_IDLE; @@ -49,13 +49,13 @@ static void clear_indicator(int fd, short mask, void *data) { static void schedule_indicator_clear(struct swaylock_state *state) { if (state->clear_indicator_timer) { - loop_remove_event(state->eventloop, 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(int fd, short mask, void *data) { +static void clear_password(void *data) { struct swaylock_state *state = data; state->clear_password_timer = NULL; state->auth_state = AUTH_STATE_CLEAR; @@ -66,13 +66,13 @@ static void clear_password(int fd, short mask, void *data) { static void schedule_password_clear(struct swaylock_state *state) { if (state->clear_password_timer) { - loop_remove_event(state->eventloop, 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(int fd, short mask, void *data) { +static void handle_preverify_timeout(void *data) { struct swaylock_state *state = data; state->verify_password_timer = NULL; } -- cgit v1.2.3