mirror of
https://github.com/swaywm/sway.git
synced 2026-05-05 06:46:49 -04:00
Fix lock sequence to actually work
This commit is contained in:
parent
72054eba22
commit
20c113952a
1 changed files with 28 additions and 19 deletions
47
sway/idle.c
47
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue