From 5a7477cb8f568ce4aeb852215ad40899f18f3d91 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sat, 8 Feb 2020 18:17:42 +0000 Subject: [PATCH] Implement transient seat management --- include/sway/input/input-manager.h | 3 +++ include/sway/input/seat.h | 1 + sway/input/input-manager.c | 25 +++++++++++++++++++++++++ sway/input/seat.c | 11 ++++++++++- sway/server.c | 3 ++- 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index 145edd4b..45c75199 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "sway/server.h" #include "sway/config.h" #include "list.h" @@ -24,6 +25,7 @@ struct sway_input_manager { struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard; struct wlr_virtual_pointer_manager_v1 *virtual_pointer; struct wlr_pointer_gestures_v1 *pointer_gestures; + struct wlr_transient_seat_manager_v1 *transient_seat_manager; struct wl_listener new_input; struct wl_listener inhibit_activate; @@ -31,6 +33,7 @@ struct sway_input_manager { struct wl_listener keyboard_shortcuts_inhibit_new_inhibitor; struct wl_listener virtual_keyboard_new; struct wl_listener virtual_pointer_new; + struct wl_listener transient_seat_create; }; struct sway_input_manager *input_manager_create(struct sway_server *server); diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index 475753d8..428f9679 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -124,6 +124,7 @@ struct sway_seat { struct wl_listener start_drag; struct wl_listener request_set_selection; struct wl_listener request_set_primary_selection; + struct wl_listener destroy; struct wl_list devices; // sway_seat_device::link struct wl_list keyboard_groups; // sway_keyboard_group::link diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 089e1e71..248ca34e 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -2,7 +2,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -431,6 +433,20 @@ void handle_virtual_pointer(struct wl_listener *listener, void *data) { } } +static void handle_transient_seat_manager_create_seat( + struct wl_listener *listener, void *data) { + struct wlr_transient_seat_v1 *transient_seat = data; + static uint64_t i; + char name[256]; + snprintf(name, sizeof(name), "transient-%"PRIx64, i++); + struct sway_seat *seat = seat_create(name); + if (seat && seat->wlr_seat) { + wlr_transient_seat_v1_ready(transient_seat, seat->wlr_seat); + } else { + wlr_transient_seat_v1_deny(transient_seat); + } +} + struct sway_input_manager *input_manager_create(struct sway_server *server) { struct sway_input_manager *input = calloc(1, sizeof(struct sway_input_manager)); @@ -466,6 +482,15 @@ struct sway_input_manager *input_manager_create(struct sway_server *server) { input->pointer_gestures = wlr_pointer_gestures_v1_create(server->wl_display); + input->transient_seat_manager = + wlr_transient_seat_manager_v1_create(server->wl_display); + assert(input->transient_seat_manager); + + input->transient_seat_create.notify = + handle_transient_seat_manager_create_seat; + wl_signal_add(&input->transient_seat_manager->events.create_seat, + &input->transient_seat_create); + return input; } diff --git a/sway/input/seat.c b/sway/input/seat.c index f2486893..0c5672bc 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -67,6 +67,12 @@ static void seat_node_destroy(struct sway_seat_node *seat_node) { } void seat_destroy(struct sway_seat *seat) { + wlr_seat_destroy(seat->wlr_seat); +} + +static void handle_seat_destroy(struct wl_listener *listener, void *data) { + struct sway_seat *seat = wl_container_of(listener, seat, destroy); + if (seat == config->handler_context.seat) { config->handler_context.seat = input_manager_get_default_seat(); } @@ -87,7 +93,7 @@ void seat_destroy(struct sway_seat *seat) { wl_list_remove(&seat->request_set_selection.link); wl_list_remove(&seat->request_set_primary_selection.link); wl_list_remove(&seat->link); - wlr_seat_destroy(seat->wlr_seat); + wl_list_remove(&seat->destroy.link); for (int i = 0; i < seat->deferred_bindings->length; i++) { free_sway_binding(seat->deferred_bindings->items[i]); } @@ -534,6 +540,9 @@ struct sway_seat *seat_create(const char *seat_name) { return NULL; } + seat->destroy.notify = handle_seat_destroy; + wl_signal_add(&seat->wlr_seat->events.destroy, &seat->destroy); + seat->idle_inhibit_sources = seat->idle_wake_sources = IDLE_SOURCE_KEYBOARD | IDLE_SOURCE_POINTER | diff --git a/sway/server.c b/sway/server.c index 51bde794..d159dc9b 100644 --- a/sway/server.c +++ b/sway/server.c @@ -112,7 +112,8 @@ static bool is_privileged(const struct wl_global *global) { global == server.session_lock.manager->global || global == server.input->keyboard_shortcuts_inhibit->global || global == server.input->virtual_keyboard->global || - global == server.input->virtual_pointer->global; + global == server.input->virtual_pointer->global || + global == server.input->transient_seat_manager->global; } static bool filter_global(const struct wl_client *client,