You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-30 18:30:54 +00:00
[Wayland] Implement keyboard_get_label_from_physical
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user