From fb7ee16f7b2456cc581b2431912d2271ca253291 Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Sat, 9 Jan 2021 13:39:50 -0500 Subject: [PATCH] [client] clipboard/wayland: support keyboard capability hotplug --- client/clipboards/Wayland/src/wayland.c | 27 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/client/clipboards/Wayland/src/wayland.c b/client/clipboards/Wayland/src/wayland.c index f198e14b..a9d42aba 100644 --- a/client/clipboards/Wayland/src/wayland.c +++ b/client/clipboards/Wayland/src/wayland.c @@ -200,7 +200,19 @@ static const struct wl_keyboard_listener keyboard_listener = { static void seat_capabilities_handler(void * data, struct wl_seat * seat, uint32_t capabilities) { - this->capabilities = capabilities; + this->capabilities = capabilities; + + bool has_keyboard = capabilities & WL_SEAT_CAPABILITY_KEYBOARD; + if (!has_keyboard && this->keyboard) + { + wl_keyboard_destroy(this->keyboard); + this->keyboard = NULL; + } + else if (has_keyboard && !this->keyboard) + { + this->keyboard = wl_seat_get_keyboard(this->seat); + wl_keyboard_add_listener(this->keyboard, &keyboard_listener, NULL); + } } static void seat_name_handler(void * data, struct wl_seat * seat, @@ -375,15 +387,6 @@ static bool wayland_cb_init( // Wait for the compositor to let us know of capabilities. wl_seat_add_listener(this->seat, &seat_listener, NULL); wl_display_roundtrip(this->display); - if (!(this->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)) - { - // TODO: keyboard hotplug support. - DEBUG_ERROR("no keyboard"); - return false; - } - - this->keyboard = wl_seat_get_keyboard(this->seat); - wl_keyboard_add_listener(this->keyboard, &keyboard_listener, NULL); return true; } @@ -467,6 +470,10 @@ static void wayland_cb_notice(LG_ClipboardRequestFn requestFn, LG_ClipboardData if (!this->requestFn) return; + // Won't have a keyboard enter serial if we don't have the keyboard capability. + if (!this->keyboard) + return; + this->requestFn(wayland_cb_reply_fn, NULL); }