Repository: godotengine/godot (language: cpp)

Issue:
`keys_pressed` does not seem to accurately reflect the keys being pressed on Wayland
### Tested versions

- Reproducible in [75ce426](https://github.com/godotengine/godot/commit/75ce4266c4774b30ed5df67e6c43365418fcce5f) & 4.3

### System information

Manjaro Gnome Wayland

### Issue description

Keys pressed seems to not be reset sometimes. 

I noticed this issue because the method `is_anything_pressed` returns `true` when I was trying out the new tooltip feature, even it should be returning `false`. 
https://github.com/godotengine/godot/blob/75ce4266c4774b30ed5df67e6c43365418fcce5f/core/input/input.cpp#L298 

### Steps to reproduce

It seems like I can trigger it fairly consistently by searching and then opening a file in the filesystem browser.

https://github.com/user-attachments/assets/911fe0be-904b-400f-b83e-c25e32aadb4c



### Minimal reproduction project (MRP)

This is just a simple project with a tool script that calls `is_anything_pressed`
[project.zip](https://github.com/user-attachments/files/18267684/project.zip)



Discussion / hints:
Looking into this further.. It seems to be reproducible by:
1. Pressing any key
2. Pressing shift
3. Releasing both keys

Some logging of the bug (print statements put in the if and else block of: https://github.com/godotengine/godot/blob/2582793d408ade0b6ed42f913ae33e7da5fb9184/core/input/input.cpp#L694


```
INSERT: Minus 45
INSERT: Shift 4194325
ERASE: Shift+UnderScore 95
ERASE: Shift+Shift 4194325
```
I don't think this is a wayland issue. I have a PR open that moves away from using the `keys_pressed` set to detect if a key is pressed [here](https://github.com/godotengine/godot/pull/101131). I'm not sure what the proper solution is for this issue. Maybe deriving the the set of keys pressed from `physical_keys_pressed` instead of attempting to keep track of them?

Fix patch:
diff --git a/platform/linuxbsd/wayland/wayland_thread.cpp b/platform/linuxbsd/wayland/wayland_thread.cpp
index c6efeac9698f..8708f979f9f3 100644
--- a/platform/linuxbsd/wayland/wayland_thread.cpp
+++ b/platform/linuxbsd/wayland/wayland_thread.cpp
@@ -193,12 +193,20 @@ Vector<uint8_t> 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<InputEventKey> 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;
 	}


Test patch: