From 519038a7e903caae731007b276f5666a341498e9 Mon Sep 17 00:00:00 2001 From: Daniel De Graaf Date: Tue, 8 Mar 2022 21:14:26 -0500 Subject: Implement ext-session-lock-v1 --- sway/input/input-manager.c | 4 ++++ sway/input/keyboard.c | 3 ++- sway/input/seat.c | 27 ++++++++++++++++++++++----- sway/input/switch.c | 3 ++- 4 files changed, 30 insertions(+), 7 deletions(-) (limited to 'sway/input') diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 8538d97c..4a0bce0e 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -289,6 +289,10 @@ static void handle_inhibit_deactivate(struct wl_listener *listener, void *data) struct sway_input_manager *input_manager = wl_container_of( listener, input_manager, inhibit_deactivate); struct sway_seat *seat; + if (server.session_lock.locked) { + // Don't deactivate the grab of a screenlocker + return; + } wl_list_for_each(seat, &input_manager->seats, link) { seat_set_exclusive_client(seat, NULL); struct sway_node *previous = seat_get_focus(seat); diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 1aa30655..8f18b8ba 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -409,7 +409,8 @@ static void handle_key_event(struct sway_keyboard *keyboard, char *device_identifier = input_device_get_identifier(wlr_device); bool exact_identifier = wlr_device->keyboard->group != NULL; seat_idle_notify_activity(seat, IDLE_SOURCE_KEYBOARD); - bool input_inhibited = seat->exclusive_client != NULL; + bool input_inhibited = seat->exclusive_client != NULL || + server.session_lock.locked; struct sway_keyboard_shortcuts_inhibitor *sway_inhibitor = keyboard_shortcuts_inhibitor_get_for_focused_surface(seat); bool shortcuts_inhibited = sway_inhibitor && sway_inhibitor->inhibitor->active; diff --git a/sway/input/seat.c b/sway/input/seat.c index 85179dc7..fa83050b 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -212,6 +212,15 @@ static void seat_send_focus(struct sway_node *node, struct sway_seat *seat) { } } +void sway_force_focus(struct wlr_surface *surface) { + struct sway_seat *seat; + wl_list_for_each(seat, &server.input->seats, link) { + seat_keyboard_notify_enter(seat, surface); + seat_tablet_pads_notify_enter(seat, surface); + sway_input_method_relay_set_focus(&seat->im_relay, surface); + } +} + void seat_for_each_node(struct sway_seat *seat, void (*f)(struct sway_node *node, void *data), void *data) { struct sway_seat_node *current = NULL; @@ -814,11 +823,13 @@ static void seat_configure_keyboard(struct sway_seat *seat, sway_keyboard_configure(seat_device->keyboard); wlr_seat_set_keyboard(seat->wlr_seat, seat_device->input_device->wlr_device->keyboard); - struct sway_node *focus = seat_get_focus(seat); - if (focus && node_is_view(focus)) { - // force notify reenter to pick up the new configuration + + // force notify reenter to pick up the new configuration. This reuses + // the current focused surface to avoid breaking input grabs. + struct wlr_surface *surface = seat->wlr_seat->keyboard_state.focused_surface; + if (surface) { wlr_seat_keyboard_notify_clear_focus(seat->wlr_seat); - seat_keyboard_notify_enter(seat, focus->sway_container->view->surface); + seat_keyboard_notify_enter(seat, surface); } } @@ -1070,7 +1081,8 @@ void seat_configure_xcursor(struct sway_seat *seat) { bool seat_is_input_allowed(struct sway_seat *seat, struct wlr_surface *surface) { struct wl_client *client = wl_resource_get_client(surface->resource); - return !seat->exclusive_client || seat->exclusive_client == client; + return seat->exclusive_client == client || + (seat->exclusive_client == NULL && !server.session_lock.locked); } static void send_unfocus(struct sway_container *con, void *data) { @@ -1171,6 +1183,11 @@ void seat_set_focus(struct sway_seat *seat, struct sway_node *node) { return; } + // Deny setting focus when an input grab or lockscreen is active + if (container && !seat_is_input_allowed(seat, container->view->surface)) { + return; + } + struct sway_output *new_output = new_workspace ? new_workspace->output : NULL; diff --git a/sway/input/switch.c b/sway/input/switch.c index af5a2385..ac4baece 100644 --- a/sway/input/switch.c +++ b/sway/input/switch.c @@ -34,7 +34,8 @@ static bool sway_switch_trigger_test(enum sway_switch_trigger trigger, static void execute_binding(struct sway_switch *sway_switch) { struct sway_seat* seat = sway_switch->seat_device->sway_seat; - bool input_inhibited = seat->exclusive_client != NULL; + bool input_inhibited = seat->exclusive_client != NULL || + server.session_lock.locked; list_t *bindings = config->current_mode->switch_bindings; struct sway_switch_binding *matched_binding = NULL; -- cgit v1.2.3-54-g00ecf