diff options
Diffstat (limited to 'swaylock')
-rw-r--r-- | swaylock/main.c | 20 | ||||
-rw-r--r-- | swaylock/password.c | 6 | ||||
-rw-r--r-- | swaylock/seat.c | 22 |
3 files changed, 33 insertions, 15 deletions
diff --git a/swaylock/main.c b/swaylock/main.c index f2bb5c3e..9b74b671 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -2,6 +2,7 @@ #define _POSIX_C_SOURCE 200112L #include <assert.h> #include <ctype.h> +#include <errno.h> #include <fcntl.h> #include <getopt.h> #include <stdbool.h> @@ -279,7 +280,10 @@ static void handle_global(void *data, struct wl_registry *registry, } else if (strcmp(interface, wl_seat_interface.name) == 0) { struct wl_seat *seat = wl_registry_bind( registry, name, &wl_seat_interface, 3); - wl_seat_add_listener(seat, &seat_listener, state); + struct swaylock_seat *swaylock_seat = + calloc(1, sizeof(struct swaylock_seat)); + swaylock_seat->state = state; + wl_seat_add_listener(seat, &seat_listener, swaylock_seat); } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { state->layer_shell = wl_registry_bind( registry, name, &zwlr_layer_shell_v1_interface, 1); @@ -841,7 +845,9 @@ 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); + if (wl_display_dispatch(state.display) == -1) { + state.run_display = false; + } } int main(int argc, char **argv) { @@ -925,6 +931,11 @@ int main(int argc, char **argv) { } zwlr_input_inhibit_manager_v1_get_inhibitor(state.input_inhibit_manager); + if (wl_display_roundtrip(state.display) == -1) { + wlr_log(WLR_ERROR, "Exiting - failed to inhibit input:" + " is another lockscreen already running?"); + return 2; + } if (state.zxdg_output_manager) { struct swaylock_surface *surface; @@ -956,7 +967,10 @@ int main(int argc, char **argv) { state.run_display = true; while (state.run_display) { - wl_display_flush(state.display); + errno = 0; + if (wl_display_flush(state.display) == -1 && errno != EAGAIN) { + break; + } loop_poll(state.eventloop); } diff --git a/swaylock/password.c b/swaylock/password.c index fecaecbf..6138e1fe 100644 --- a/swaylock/password.c +++ b/swaylock/password.c @@ -1,5 +1,6 @@ #define _XOPEN_SOURCE 500 #include <assert.h> +#include <errno.h> #include <pwd.h> #include <stdlib.h> #include <string.h> @@ -97,7 +98,10 @@ void swaylock_handle_key(struct swaylock_state *state, state->eventloop, 50, handle_preverify_timeout, state); while (state->run_display && state->verify_password_timer) { - wl_display_flush(state->display); + errno = 0; + if (wl_display_flush(state->display) == -1 && errno != EAGAIN) { + break; + } loop_poll(state->eventloop); bool ok = 1; diff --git a/swaylock/seat.c b/swaylock/seat.c index 22dd9360..7b72114f 100644 --- a/swaylock/seat.c +++ b/swaylock/seat.c @@ -144,22 +144,22 @@ static const struct wl_pointer_listener pointer_listener = { static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, enum wl_seat_capability caps) { - struct swaylock_state *state = data; - if (state->pointer) { - wl_pointer_release(state->pointer); - state->pointer = NULL; + struct swaylock_seat *seat = data; + if (seat->pointer) { + wl_pointer_release(seat->pointer); + seat->pointer = NULL; } - if (state->keyboard) { - wl_keyboard_release(state->keyboard); - state->keyboard = NULL; + if (seat->keyboard) { + wl_keyboard_release(seat->keyboard); + seat->keyboard = NULL; } if ((caps & WL_SEAT_CAPABILITY_POINTER)) { - state->pointer = wl_seat_get_pointer(wl_seat); - wl_pointer_add_listener(state->pointer, &pointer_listener, NULL); + seat->pointer = wl_seat_get_pointer(wl_seat); + wl_pointer_add_listener(seat->pointer, &pointer_listener, NULL); } if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) { - state->keyboard = wl_seat_get_keyboard(wl_seat); - wl_keyboard_add_listener(state->keyboard, &keyboard_listener, state); + seat->keyboard = wl_seat_get_keyboard(wl_seat); + wl_keyboard_add_listener(seat->keyboard, &keyboard_listener, seat->state); } } |