You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-15 13:51:40 +00:00
Merge pull request #80231 from romlok/input-key-location
Support detecting and mapping ctrl/alt/shift/meta by their left/right physical location
This commit is contained in:
@@ -3512,6 +3512,7 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
|
||||
bool keypress = xkeyevent->type == KeyPress;
|
||||
Key keycode = KeyMappingX11::get_keycode(keysym_keycode);
|
||||
Key physical_keycode = KeyMappingX11::get_scancode(xkeyevent->keycode);
|
||||
KeyLocation key_location = KeyMappingX11::get_location(xkeyevent->keycode);
|
||||
|
||||
if (keycode >= Key::A + 32 && keycode <= Key::Z + 32) {
|
||||
keycode -= 'a' - 'A';
|
||||
@@ -3549,6 +3550,8 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
|
||||
k->set_unicode(fix_unicode(tmp[i]));
|
||||
}
|
||||
|
||||
k->set_location(key_location);
|
||||
|
||||
k->set_echo(false);
|
||||
|
||||
if (k->get_keycode() == Key::BACKTAB) {
|
||||
@@ -3574,6 +3577,8 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
|
||||
Key keycode = KeyMappingX11::get_keycode(keysym_keycode);
|
||||
Key physical_keycode = KeyMappingX11::get_scancode(xkeyevent->keycode);
|
||||
|
||||
KeyLocation key_location = KeyMappingX11::get_location(xkeyevent->keycode);
|
||||
|
||||
/* Phase 3, obtain a unicode character from the keysym */
|
||||
|
||||
// KeyMappingX11 also translates keysym to unicode.
|
||||
@@ -3673,6 +3678,9 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
|
||||
if (keypress) {
|
||||
k->set_unicode(fix_unicode(unicode));
|
||||
}
|
||||
|
||||
k->set_location(key_location);
|
||||
|
||||
k->set_echo(p_echo);
|
||||
|
||||
if (k->get_keycode() == Key::BACKTAB) {
|
||||
|
||||
@@ -1113,6 +1113,20 @@ void KeyMappingX11::initialize() {
|
||||
xkeysym_unicode_map[0x13BD] = 0x0153;
|
||||
xkeysym_unicode_map[0x13BE] = 0x0178;
|
||||
xkeysym_unicode_map[0x20AC] = 0x20AC;
|
||||
|
||||
// Scancode to physical location map.
|
||||
// Ctrl.
|
||||
location_map[0x25] = KeyLocation::LEFT;
|
||||
location_map[0x69] = KeyLocation::RIGHT;
|
||||
// Shift.
|
||||
location_map[0x32] = KeyLocation::LEFT;
|
||||
location_map[0x3E] = KeyLocation::RIGHT;
|
||||
// Alt.
|
||||
location_map[0x40] = KeyLocation::LEFT;
|
||||
location_map[0x6C] = KeyLocation::RIGHT;
|
||||
// Meta.
|
||||
location_map[0x85] = KeyLocation::LEFT;
|
||||
location_map[0x86] = KeyLocation::RIGHT;
|
||||
}
|
||||
|
||||
Key KeyMappingX11::get_keycode(KeySym p_keysym) {
|
||||
@@ -1173,3 +1187,11 @@ char32_t KeyMappingX11::get_unicode_from_keysym(KeySym p_keysym) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
KeyLocation KeyMappingX11::get_location(unsigned int p_code) {
|
||||
const KeyLocation *location = location_map.getptr(p_code);
|
||||
if (location) {
|
||||
return *location;
|
||||
}
|
||||
return KeyLocation::UNSPECIFIED;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ class KeyMappingX11 {
|
||||
static inline HashMap<unsigned int, Key, HashMapHasherKeys> scancode_map;
|
||||
static inline HashMap<Key, unsigned int, HashMapHasherKeys> scancode_map_inv;
|
||||
static inline HashMap<KeySym, char32_t, HashMapHasherKeys> xkeysym_unicode_map;
|
||||
static inline HashMap<unsigned int, KeyLocation, HashMapHasherKeys> location_map;
|
||||
|
||||
KeyMappingX11() {}
|
||||
|
||||
@@ -64,6 +65,7 @@ public:
|
||||
static unsigned int get_xlibcode(Key p_keysym);
|
||||
static Key get_scancode(unsigned int p_code);
|
||||
static char32_t get_unicode_from_keysym(KeySym p_keysym);
|
||||
static KeyLocation get_location(unsigned int p_code);
|
||||
};
|
||||
|
||||
#endif // KEY_MAPPING_X11_H
|
||||
|
||||
Reference in New Issue
Block a user