summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/main.c b/main.c
index a4279e0..b37cd8f 100644
--- a/main.c
+++ b/main.c
@@ -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;