diff options
| author | Daniel De Graaf <code@danieldg.net> | 2022-05-14 14:23:27 -0400 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2022-09-24 12:15:53 +0200 |
| commit | dafbef3ade130317ad0d941f9ce312bb68a708df (patch) | |
| tree | 0c7e0b043faa3f3096f09e4d1b0a616d53bf63be /main.c | |
| parent | 605859cdd494b82fe206fe8d4737cda73cb6d467 (diff) | |
Unlock the screen on SIGUSR1
When the screen is locked using ext_session_lock, killing swaylock will
leave the session locked. This is normally desirable if the kill is due
to the OOM killer or swaylock crashing, but can be undesirable if an
unlock is desired. This adds a signal handler for SIGUSR1 if using
ext_session_lock.
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -5,6 +5,7 @@ #include <fcntl.h> #include <getopt.h> #include <poll.h> +#include <signal.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> @@ -392,6 +393,12 @@ static const struct wl_registry_listener registry_listener = { .global_remove = handle_global_remove, }; +static int sigusr_fds[2] = {-1, -1}; + +void do_sigusr(int sig) { + (void)write(sigusr_fds[1], "1", 1); +} + static cairo_surface_t *select_image(struct swaylock_state *state, struct swaylock_surface *surface) { struct swaylock_image *image; @@ -1124,6 +1131,10 @@ static void comm_in(int fd, short mask, void *data) { } } +static void term_in(int fd, short mask, void *data) { + state.run_display = false; +} + int main(int argc, char **argv) { swaylock_log_init(LOG_ERROR); initialize_pw_backend(argc, argv); @@ -1195,6 +1206,11 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } + if (pipe(sigusr_fds) != 0) { + swaylock_log(LOG_ERROR, "Failed to pipe"); + return 1; + } + wl_list_init(&state.surfaces); state.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); state.display = wl_display_connect(NULL); @@ -1255,6 +1271,9 @@ int main(int argc, char **argv) { loop_add_fd(state.eventloop, get_comm_reply_fd(), POLLIN, comm_in, NULL); + loop_add_fd(state.eventloop, sigusr_fds[0], POLLIN, term_in, NULL); + signal(SIGUSR1, do_sigusr); + state.run_display = true; while (state.run_display) { errno = 0; |
