From 48765c3465a403a457b6c6916c34c2b431db42f5 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 12 May 2024 23:04:05 +0000 Subject: [PATCH] Implement ext-virtual-keyboard-v1 --- include/sway/input/input-manager.h | 3 +++ sway/input/input-manager.c | 38 ++++++++++++++++++++++++++++++ sway/input/keyboard.c | 1 + 3 files changed, 42 insertions(+) diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index 45c75199..b8d666c0 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include "sway/server.h" @@ -23,6 +24,7 @@ struct sway_input_manager { struct wlr_keyboard_shortcuts_inhibit_manager_v1 *keyboard_shortcuts_inhibit; struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard; + struct wlr_ext_virtual_keyboard_manager_v1 *ext_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; @@ -32,6 +34,7 @@ struct sway_input_manager { struct wl_listener inhibit_deactivate; struct wl_listener keyboard_shortcuts_inhibit_new_inhibitor; struct wl_listener virtual_keyboard_new; + struct wl_listener ext_virtual_keyboard_new; struct wl_listener virtual_pointer_new; struct wl_listener transient_seat_create; }; diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 248ca34e..8a29e0c4 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "sway/config.h" #include "sway/input/cursor.h" @@ -396,6 +397,37 @@ void handle_virtual_keyboard(struct wl_listener *listener, void *data) { seat_add_device(seat, input_device); } +void handle_ext_virtual_keyboard(struct wl_listener *listener, void *data) { + struct sway_input_manager *input_manager = + wl_container_of(listener, input_manager, ext_virtual_keyboard_new); + struct wlr_ext_virtual_keyboard_v1 *keyboard = data; + struct wlr_input_device *device = &keyboard->keyboard.base; + + struct sway_seat *seat = keyboard->seat ? + input_manager_sway_seat_from_wlr_seat(keyboard->seat) : + input_manager_get_default_seat(); + + struct sway_input_device *input_device = + calloc(1, sizeof(struct sway_input_device)); + if (!sway_assert(input_device, "could not allocate input device")) { + return; + } + device->data = input_device; + + input_device->is_virtual = true; + input_device->wlr_device = device; + input_device->identifier = input_device_get_identifier(device); + wl_list_insert(&input_manager->devices, &input_device->link); + + sway_log(SWAY_DEBUG, "adding virtual keyboard: '%s'", + input_device->identifier); + + wl_signal_add(&device->events.destroy, &input_device->device_destroy); + input_device->device_destroy.notify = handle_device_destroy; + + seat_add_device(seat, input_device); +} + void handle_virtual_pointer(struct wl_listener *listener, void *data) { struct sway_input_manager *input_manager = wl_container_of(listener, input_manager, virtual_pointer_new); @@ -466,6 +498,12 @@ struct sway_input_manager *input_manager_create(struct sway_server *server) { &input->virtual_keyboard_new); input->virtual_keyboard_new.notify = handle_virtual_keyboard; + input->ext_virtual_keyboard = wlr_ext_virtual_keyboard_manager_v1_create( + server->wl_display); + wl_signal_add(&input->ext_virtual_keyboard->events.new_ext_virtual_keyboard, + &input->ext_virtual_keyboard_new); + input->ext_virtual_keyboard_new.notify = handle_ext_virtual_keyboard; + input->virtual_pointer = wlr_virtual_pointer_manager_v1_create( server->wl_display ); diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index f74d0658..c4cffdec 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -382,6 +382,7 @@ static void update_keyboard_state(struct sway_keyboard *keyboard, * Returns NULL if the keyboard is not grabbed by an input method, * or if event is from virtual keyboard of the same client as grab. * TODO: see swaywm/wlroots#2322 + * TODO: ext-virtual-keyboard-v1 */ static struct wlr_input_method_keyboard_grab_v2 *keyboard_get_im_grab( struct sway_keyboard *keyboard) {