Implement ext-virtual-keyboard-v1

This commit is contained in:
Andri Yngvason 2024-05-12 23:04:05 +00:00
parent dcdb72757a
commit 48765c3465
3 changed files with 42 additions and 0 deletions

View file

@ -3,6 +3,7 @@
#include <libinput.h> #include <libinput.h>
#include <wlr/types/wlr_keyboard_shortcuts_inhibit_v1.h> #include <wlr/types/wlr_keyboard_shortcuts_inhibit_v1.h>
#include <wlr/types/wlr_virtual_keyboard_v1.h> #include <wlr/types/wlr_virtual_keyboard_v1.h>
#include <wlr/types/wlr_ext_virtual_keyboard_v1.h>
#include <wlr/types/wlr_virtual_pointer_v1.h> #include <wlr/types/wlr_virtual_pointer_v1.h>
#include <wlr/types/wlr_transient_seat_v1.h> #include <wlr/types/wlr_transient_seat_v1.h>
#include "sway/server.h" #include "sway/server.h"
@ -23,6 +24,7 @@ struct sway_input_manager {
struct wlr_keyboard_shortcuts_inhibit_manager_v1 *keyboard_shortcuts_inhibit; struct wlr_keyboard_shortcuts_inhibit_manager_v1 *keyboard_shortcuts_inhibit;
struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard; 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_virtual_pointer_manager_v1 *virtual_pointer;
struct wlr_pointer_gestures_v1 *pointer_gestures; struct wlr_pointer_gestures_v1 *pointer_gestures;
struct wlr_transient_seat_manager_v1 *transient_seat_manager; 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 inhibit_deactivate;
struct wl_listener keyboard_shortcuts_inhibit_new_inhibitor; struct wl_listener keyboard_shortcuts_inhibit_new_inhibitor;
struct wl_listener virtual_keyboard_new; struct wl_listener virtual_keyboard_new;
struct wl_listener ext_virtual_keyboard_new;
struct wl_listener virtual_pointer_new; struct wl_listener virtual_pointer_new;
struct wl_listener transient_seat_create; struct wl_listener transient_seat_create;
}; };

View file

@ -8,6 +8,7 @@
#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_keyboard_group.h> #include <wlr/types/wlr_keyboard_group.h>
#include <wlr/types/wlr_virtual_keyboard_v1.h> #include <wlr/types/wlr_virtual_keyboard_v1.h>
#include <wlr/types/wlr_ext_virtual_keyboard_v1.h>
#include <wlr/types/wlr_virtual_pointer_v1.h> #include <wlr/types/wlr_virtual_pointer_v1.h>
#include "sway/config.h" #include "sway/config.h"
#include "sway/input/cursor.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); 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) { void handle_virtual_pointer(struct wl_listener *listener, void *data) {
struct sway_input_manager *input_manager = struct sway_input_manager *input_manager =
wl_container_of(listener, input_manager, virtual_pointer_new); 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);
input->virtual_keyboard_new.notify = handle_virtual_keyboard; 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( input->virtual_pointer = wlr_virtual_pointer_manager_v1_create(
server->wl_display server->wl_display
); );

View file

@ -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, * 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. * or if event is from virtual keyboard of the same client as grab.
* TODO: see swaywm/wlroots#2322 * TODO: see swaywm/wlroots#2322
* TODO: ext-virtual-keyboard-v1
*/ */
static struct wlr_input_method_keyboard_grab_v2 *keyboard_get_im_grab( static struct wlr_input_method_keyboard_grab_v2 *keyboard_get_im_grab(
struct sway_keyboard *keyboard) { struct sway_keyboard *keyboard) {