1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-31 18:41:20 +00:00

[Wayland] Implement keyboard_get_label_from_physical

This commit is contained in:
Pāvels Nadtočajevs
2025-12-10 13:19:35 +02:00
parent d743736f84
commit 1251348c96
4 changed files with 35 additions and 3 deletions

View File

@@ -1665,6 +1665,12 @@ Key DisplayServerWayland::keyboard_get_keycode_from_physical(Key p_keycode) cons
return key;
}
Key DisplayServerWayland::keyboard_get_label_from_physical(Key p_keycode) const {
MutexLock mutex_lock(wayland_thread.mutex);
return wayland_thread.keyboard_get_label_from_physical(p_keycode);
}
bool DisplayServerWayland::color_picker(const Callable &p_callback) {
#ifdef DBUS_ENABLED
if (!portal_desktop) {

View File

@@ -339,6 +339,7 @@ public:
virtual String keyboard_get_layout_language(int p_index) const override;
virtual String keyboard_get_layout_name(int p_index) const override;
virtual Key keyboard_get_keycode_from_physical(Key p_keycode) const override;
virtual Key keyboard_get_label_from_physical(Key p_keycode) const override;
virtual bool color_picker(const Callable &p_callback) override;

View File

@@ -4932,11 +4932,35 @@ Key WaylandThread::keyboard_get_key_from_physical(Key p_key) const {
SeatState *ss = wl_seat_get_seat_state(wl_seat_current);
if (ss && ss->xkb_state) {
xkb_keycode_t xkb_keycode = KeyMappingXKB::get_xkb_keycode(p_key);
return KeyMappingXKB::get_keycode(xkb_state_key_get_one_sym(ss->xkb_state, xkb_keycode));
Key modifiers = p_key & KeyModifierMask::MODIFIER_MASK;
Key keycode_no_mod = p_key & KeyModifierMask::CODE_MASK;
xkb_keycode_t xkb_keycode = KeyMappingXKB::get_xkb_keycode(keycode_no_mod);
Key key = KeyMappingXKB::get_keycode(xkb_state_key_get_one_sym(ss->xkb_state, xkb_keycode));
return (Key)(key | modifiers);
}
return Key::NONE;
return p_key;
}
Key WaylandThread::keyboard_get_label_from_physical(Key p_key) const {
SeatState *ss = wl_seat_get_seat_state(wl_seat_current);
if (ss && ss->xkb_state) {
Key modifiers = p_key & KeyModifierMask::MODIFIER_MASK;
Key keycode_no_mod = p_key & KeyModifierMask::CODE_MASK;
xkb_keycode_t xkb_keycode = KeyMappingXKB::get_xkb_keycode(keycode_no_mod);
xkb_keycode_t xkb_keysym = xkb_state_key_get_one_sym(ss->xkb_state, xkb_keycode);
char32_t chr = xkb_keysym_to_utf32(xkb_keysym_to_upper(xkb_keysym));
if (chr != 0) {
String keysym = String::chr(chr);
Key key = fix_key_label(keysym[0], KeyMappingXKB::get_keycode(xkb_keysym));
return (Key)(key | modifiers);
}
}
return p_key;
}
void WaylandThread::keyboard_echo_keys() {

View File

@@ -1148,6 +1148,7 @@ public:
String keyboard_get_layout_name(int p_index) const;
Key keyboard_get_key_from_physical(Key p_key) const;
Key keyboard_get_label_from_physical(Key p_key) const;
void keyboard_echo_keys();