From 20c113952ae30d5250935e5104eea0a42a167e98 Mon Sep 17 00:00:00 2001 From: Mattias Eriksson Date: Sat, 28 Apr 2018 09:38:11 +0200 Subject: [PATCH] Fix lock sequence to actually work --- sway/idle.c | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/sway/idle.c b/sway/idle.c index 78f0c7588..1e9ef48b7 100644 --- a/sway/idle.c +++ b/sway/idle.c @@ -57,51 +57,58 @@ bool have_lock() { return false; } -static int fd = -1; +static int lock_fd = -1; +static int ongoing_fd = -1; static int inhibit_cnt=0; -void cleanup_inhibit() { - if (fd >= 0) - close(fd); //Release lock - fd = -1; +void release_lock() { + wlr_log(L_DEBUG, "Release lock %d", ongoing_fd); + if (ongoing_fd >= 0) + close(ongoing_fd); + ongoing_fd = -1; inhibit_cnt=0; - wlr_log(L_DEBUG, "Cleanup inhibit"); return; } -static int check_for_lock(void *data) { +static int check_for_lockscreen(void *data) { struct sway_server *server = data; if(have_lock()) { //If we for some reason already have a lockscreen wlr_log(L_INFO, "Got lock, will release inhibit lock"); - cleanup_inhibit(); + release_lock(); return 0; } if(inhibit_cnt > 4) { wlr_log(L_INFO, "Reached inhibit timeout, releasing lock"); - cleanup_inhibit(); + release_lock(); return 0; } inhibit_cnt++; - struct wl_event_source *source = wl_event_loop_add_timer(server->wl_event_loop, check_for_lock, server); - wl_event_source_timer_update(source, 100); + struct wl_event_source *source = wl_event_loop_add_timer(server->wl_event_loop, check_for_lockscreen, server); + wl_event_source_timer_update(source, 100); return 0; } -static void prepare_for_sleep(struct wlr_session *session, void *data) { +static void prepare_for_sleep(struct wlr_session *session, bool going_down, void *data) { struct sway_server *server = data; - wlr_log(L_INFO, "PrepareForSleep signal received"); - fd = wlr_session_inhibit_sleep(session); - if(have_lock()) { //If we for some reason already have a lockscreen - wlr_log(L_INFO, "Already have lock, no inhibit"); - cleanup_inhibit(); + wlr_log(L_INFO, "PrepareForSleep signal received %d", going_down); + if (!going_down) { + lock_fd = wlr_session_aquire_sleep_lock(session); + wlr_log(L_INFO, "Got new lock %d", lock_fd); return; } + ongoing_fd = lock_fd; + if(have_lock()) { //If we for some reason already have a lockscreen + wlr_log(L_INFO, "Already have lock, no action"); + release_lock(); + return; + } + wlr_log(L_INFO, "Starting lockscreen, holding lock %d", ongoing_fd); invoke_swaylock(); - if (fd>=0) { - struct wl_event_source *source = wl_event_loop_add_timer(server->wl_event_loop, check_for_lock, server); + if (ongoing_fd>=0) { + struct wl_event_source *source = wl_event_loop_add_timer(server->wl_event_loop, check_for_lockscreen, server); wl_event_source_timer_update(source, 100); } return; @@ -119,6 +126,8 @@ void setup_sleep_listener(struct sway_server *server) { } wlr_session_prepare_for_sleep_listen(session, prepare_for_sleep, server); + lock_fd = wlr_session_aquire_sleep_lock(session); + wlr_log(L_INFO, "Got initial lock %d", lock_fd); } static int handle_idle(void* data) {