From d12137bdda2fa9acf89ac60b1817d117ea746fe8 Mon Sep 17 00:00:00 2001 From: Riteo Date: Mon, 20 Jan 2025 18:13:45 +0100 Subject: [PATCH] Wayland: Pass unmodified symbols to key events Before this change we would internationalize the keycode itself in all `InputEventKey`s, confusing the whole input subsystem. --- platform/linuxbsd/wayland/wayland_thread.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/platform/linuxbsd/wayland/wayland_thread.cpp b/platform/linuxbsd/wayland/wayland_thread.cpp index c6efeac9698..8708f979f9f 100644 --- a/platform/linuxbsd/wayland/wayland_thread.cpp +++ b/platform/linuxbsd/wayland/wayland_thread.cpp @@ -193,12 +193,20 @@ Vector WaylandThread::_wp_primary_selection_offer_read(struct wl_displa // Sets up an `InputEventKey` and returns whether it has any meaningful value. bool WaylandThread::_seat_state_configure_key_event(SeatState &p_ss, Ref p_event, xkb_keycode_t p_keycode, bool p_pressed) { - // TODO: Handle keys that release multiple symbols? - Key keycode = KeyMappingXKB::get_keycode(xkb_state_key_get_one_sym(p_ss.xkb_state, p_keycode)); + // NOTE: xkbcommon's API really encourages to apply the modifier state but we + // only want a "plain" symbol so that we can convert it into a godot keycode. + const xkb_keysym_t *syms = nullptr; + int num_sys = xkb_keymap_key_get_syms_by_level(p_ss.xkb_keymap, p_keycode, p_ss.current_layout_index, 0, &syms); + Key physical_keycode = KeyMappingXKB::get_scancode(p_keycode); KeyLocation key_location = KeyMappingXKB::get_location(p_keycode); uint32_t unicode = xkb_state_key_get_utf32(p_ss.xkb_state, p_keycode); + Key keycode = Key::NONE; + if (num_sys > 0 && syms) { + keycode = KeyMappingXKB::get_keycode(syms[0]); + } + if (keycode == Key::NONE) { keycode = physical_keycode; }