diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2022-09-02 12:37:48 +0300 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2022-09-07 18:45:35 +0200 |
commit | 6f4d233062d44bd46b2f03596e72f0bc9709d2b5 (patch) | |
tree | cbd85008acd264327074698cf2e25b5f98dede6d /core | |
parent | 6b92dbfce2868f71926d2720014e45af999f21be (diff) |
Fix key mapping changes when moving from macOS to other platform
Removes separate `Command` key (use `Meta` instead).
Adds an event flag to automatically remap `Command` <-> `Control` (cannot be set alongside `Control` or `Meta`).
Diffstat (limited to 'core')
-rw-r--r-- | core/core_constants.cpp | 2 | ||||
-rw-r--r-- | core/input/input_event.cpp | 90 | ||||
-rw-r--r-- | core/input/input_event.h | 25 | ||||
-rw-r--r-- | core/input/input_map.cpp | 62 | ||||
-rw-r--r-- | core/os/keyboard.cpp | 16 | ||||
-rw-r--r-- | core/os/keyboard.h | 17 |
6 files changed, 112 insertions, 100 deletions
diff --git a/core/core_constants.cpp b/core/core_constants.cpp index c4d83d4765..2f8b28363b 100644 --- a/core/core_constants.cpp +++ b/core/core_constants.cpp @@ -433,11 +433,11 @@ void register_global_constants() { BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(KeyModifierMask, KEY_CODE_MASK, CODE_MASK); BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(KeyModifierMask, KEY_MODIFIER_MASK, MODIFIER_MASK); + BIND_CORE_ENUM_CLASS_CONSTANT(KeyModifierMask, KEY_MASK, CMD_OR_CTRL); BIND_CORE_ENUM_CLASS_CONSTANT(KeyModifierMask, KEY_MASK, SHIFT); BIND_CORE_ENUM_CLASS_CONSTANT(KeyModifierMask, KEY_MASK, ALT); BIND_CORE_ENUM_CLASS_CONSTANT(KeyModifierMask, KEY_MASK, META); BIND_CORE_ENUM_CLASS_CONSTANT(KeyModifierMask, KEY_MASK, CTRL); - BIND_CORE_ENUM_CLASS_CONSTANT_NO_VAL(KeyModifierMask, KEY_MASK, CMD); BIND_CORE_ENUM_CLASS_CONSTANT(KeyModifierMask, KEY_MASK, KPAD); BIND_CORE_ENUM_CLASS_CONSTANT(KeyModifierMask, KEY_MASK, GROUP_SWITCH); diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 3f02d80c26..596b704732 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -142,13 +142,33 @@ int64_t InputEventFromWindow::get_window_id() const { /////////////////////////////////// -void InputEventWithModifiers::set_store_command(bool p_enabled) { - store_command = p_enabled; +void InputEventWithModifiers::set_command_or_control_autoremap(bool p_enabled) { + command_or_control_autoremap = p_enabled; + if (command_or_control_autoremap) { +#ifdef MACOS_ENABLED + ctrl_pressed = false; + meta_pressed = true; +#else + ctrl_pressed = true; + meta_pressed = false; +#endif + } else { + ctrl_pressed = false; + meta_pressed = false; + } emit_changed(); } -bool InputEventWithModifiers::is_storing_command() const { - return store_command; +bool InputEventWithModifiers::is_command_or_control_autoremap() const { + return command_or_control_autoremap; +} + +bool InputEventWithModifiers::is_command_or_control_pressed() const { +#ifdef MACOS_ENABLED + return meta_pressed; +#else + return ctrl_pressed; +#endif } void InputEventWithModifiers::set_shift_pressed(bool p_enabled) { @@ -170,6 +190,7 @@ bool InputEventWithModifiers::is_alt_pressed() const { } void InputEventWithModifiers::set_ctrl_pressed(bool p_enabled) { + ERR_FAIL_COND_MSG(command_or_control_autoremap, "Command/Control autoremaping is enabled, cannot set Control directly!"); ctrl_pressed = p_enabled; emit_changed(); } @@ -179,6 +200,7 @@ bool InputEventWithModifiers::is_ctrl_pressed() const { } void InputEventWithModifiers::set_meta_pressed(bool p_enabled) { + ERR_FAIL_COND_MSG(command_or_control_autoremap, "Command/Control autoremaping is enabled, cannot set Meta directly!"); meta_pressed = p_enabled; emit_changed(); } @@ -187,15 +209,6 @@ bool InputEventWithModifiers::is_meta_pressed() const { return meta_pressed; } -void InputEventWithModifiers::set_command_pressed(bool p_enabled) { - command_pressed = p_enabled; - emit_changed(); -} - -bool InputEventWithModifiers::is_command_pressed() const { - return command_pressed; -} - void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModifiers *event) { set_alt_pressed(event->is_alt_pressed()); set_shift_pressed(event->is_shift_pressed()); @@ -217,6 +230,13 @@ Key InputEventWithModifiers::get_modifiers_mask() const { if (is_meta_pressed()) { mask |= KeyModifierMask::META; } + if (is_command_or_control_autoremap()) { +#ifdef MACOS_ENABLED + mask |= KeyModifierMask::META; +#else + mask |= KeyModifierMask::CTRL; +#endif + } return mask; } @@ -248,8 +268,10 @@ String InputEventWithModifiers::to_string() { } void InputEventWithModifiers::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_store_command", "enable"), &InputEventWithModifiers::set_store_command); - ClassDB::bind_method(D_METHOD("is_storing_command"), &InputEventWithModifiers::is_storing_command); + ClassDB::bind_method(D_METHOD("set_command_or_control_autoremap", "enable"), &InputEventWithModifiers::set_command_or_control_autoremap); + ClassDB::bind_method(D_METHOD("is_command_or_control_autoremap"), &InputEventWithModifiers::is_command_or_control_autoremap); + + ClassDB::bind_method(D_METHOD("is_command_or_control_pressed"), &InputEventWithModifiers::is_command_or_control_pressed); ClassDB::bind_method(D_METHOD("set_alt_pressed", "pressed"), &InputEventWithModifiers::set_alt_pressed); ClassDB::bind_method(D_METHOD("is_alt_pressed"), &InputEventWithModifiers::is_alt_pressed); @@ -263,34 +285,24 @@ void InputEventWithModifiers::_bind_methods() { ClassDB::bind_method(D_METHOD("set_meta_pressed", "pressed"), &InputEventWithModifiers::set_meta_pressed); ClassDB::bind_method(D_METHOD("is_meta_pressed"), &InputEventWithModifiers::is_meta_pressed); - ClassDB::bind_method(D_METHOD("set_command_pressed", "pressed"), &InputEventWithModifiers::set_command_pressed); - ClassDB::bind_method(D_METHOD("is_command_pressed"), &InputEventWithModifiers::is_command_pressed); - - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "store_command"), "set_store_command", "is_storing_command"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command_or_control_autoremap"), "set_command_or_control_autoremap", "is_command_or_control_autoremap"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt_pressed"), "set_alt_pressed", "is_alt_pressed"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift_pressed"), "set_shift_pressed", "is_shift_pressed"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ctrl_pressed"), "set_ctrl_pressed", "is_ctrl_pressed"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta_pressed"), "set_meta_pressed", "is_meta_pressed"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command_pressed"), "set_command_pressed", "is_command_pressed"); } void InputEventWithModifiers::_validate_property(PropertyInfo &p_property) const { - if (store_command) { - // If we only want to Store "Command". -#ifdef APPLE_STYLE_KEYS - // Don't store "Meta" on Mac. + if (command_or_control_autoremap) { + // Cannot be used with Meta/Command or Control! if (p_property.name == "meta_pressed") { p_property.usage ^= PROPERTY_USAGE_STORAGE; } -#else - // Don't store "Ctrl". if (p_property.name == "ctrl_pressed") { p_property.usage ^= PROPERTY_USAGE_STORAGE; } -#endif } else { - // We don't want to store command, only ctrl or meta (on mac). - if (p_property.name == "command_pressed") { + if (p_property.name == "command_or_control_autoremap") { p_property.usage ^= PROPERTY_USAGE_STORAGE; } } @@ -399,14 +411,18 @@ Ref<InputEventKey> InputEventKey::create_reference(Key p_keycode) { if ((p_keycode & KeyModifierMask::ALT) != Key::NONE) { ie->set_alt_pressed(true); } - if ((p_keycode & KeyModifierMask::CTRL) != Key::NONE) { - ie->set_ctrl_pressed(true); - } - if ((p_keycode & KeyModifierMask::CMD) != Key::NONE) { - ie->set_command_pressed(true); - } - if ((p_keycode & KeyModifierMask::META) != Key::NONE) { - ie->set_meta_pressed(true); + if ((p_keycode & KeyModifierMask::CMD_OR_CTRL) != Key::NONE) { + ie->set_command_or_control_autoremap(true); + if ((p_keycode & KeyModifierMask::CTRL) != Key::NONE || (p_keycode & KeyModifierMask::META) != Key::NONE) { + WARN_PRINT("Invalid Key Modifiers: Command or Control autoremapping is enabled, Meta and Control values are ignored!"); + } + } else { + if ((p_keycode & KeyModifierMask::CTRL) != Key::NONE) { + ie->set_ctrl_pressed(true); + } + if ((p_keycode & KeyModifierMask::META) != Key::NONE) { + ie->set_meta_pressed(true); + } } return ie; diff --git a/core/input/input_event.h b/core/input/input_event.h index 6cfc031c8a..bc3ec3e7ac 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -107,32 +107,22 @@ public: class InputEventWithModifiers : public InputEventFromWindow { GDCLASS(InputEventWithModifiers, InputEventFromWindow); - bool store_command = true; + bool command_or_control_autoremap = false; bool shift_pressed = false; bool alt_pressed = false; -#ifdef APPLE_STYLE_KEYS - union { - bool command_pressed; - bool meta_pressed = false; //< windows/mac key - }; - + bool meta_pressed = false; // "Command" on macOS, "Meta/Win" key on other platforms. bool ctrl_pressed = false; -#else - union { - bool command_pressed; //< windows/mac key - bool ctrl_pressed = false; - }; - bool meta_pressed = false; //< windows/mac key -#endif protected: static void _bind_methods(); void _validate_property(PropertyInfo &p_property) const; public: - void set_store_command(bool p_enabled); - bool is_storing_command() const; + void set_command_or_control_autoremap(bool p_enabled); + bool is_command_or_control_autoremap() const; + + bool is_command_or_control_pressed() const; void set_shift_pressed(bool p_pressed); bool is_shift_pressed() const; @@ -146,9 +136,6 @@ public: void set_meta_pressed(bool p_pressed); bool is_meta_pressed() const; - void set_command_pressed(bool p_pressed); - bool is_command_pressed() const; - void set_modifiers_from_event(const InputEventWithModifiers *event); Key get_modifiers_mask() const; diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index 702e257fb4..ce76d11b6e 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -429,27 +429,27 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { // ///// UI basic Shortcuts ///// inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::X | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::X | KeyModifierMask::CMD_OR_CTRL)); inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE | KeyModifierMask::SHIFT)); default_builtin_cache.insert("ui_cut", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::C | KeyModifierMask::CMD)); - inputs.push_back(InputEventKey::create_reference(Key::INSERT | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::C | KeyModifierMask::CMD_OR_CTRL)); + inputs.push_back(InputEventKey::create_reference(Key::INSERT | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_copy", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::V | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::V | KeyModifierMask::CMD_OR_CTRL)); inputs.push_back(InputEventKey::create_reference(Key::INSERT | KeyModifierMask::SHIFT)); default_builtin_cache.insert("ui_paste", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::Z | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::Z | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_undo", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::Z | KeyModifierMask::CMD | KeyModifierMask::SHIFT)); - inputs.push_back(InputEventKey::create_reference(Key::Y | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::Z | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT)); + inputs.push_back(InputEventKey::create_reference(Key::Y | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_redo", inputs); // ///// UI Text Input Shortcuts ///// @@ -474,13 +474,13 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::ENTER | KeyModifierMask::CMD)); - inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::ENTER | KeyModifierMask::CMD_OR_CTRL)); + inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_newline_blank", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::ENTER | KeyModifierMask::SHIFT | KeyModifierMask::CMD)); - inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER | KeyModifierMask::SHIFT | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::ENTER | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL)); + inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_newline_above", inputs); // Indentation @@ -499,7 +499,7 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { default_builtin_cache.insert("ui_text_backspace", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_backspace_word", inputs); inputs = List<Ref<InputEvent>>(); @@ -510,7 +510,7 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { default_builtin_cache.insert("ui_text_backspace_all_to_left", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_backspace_all_to_left.macos", inputs); inputs = List<Ref<InputEvent>>(); @@ -518,7 +518,7 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { default_builtin_cache.insert("ui_text_delete", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_delete_word", inputs); inputs = List<Ref<InputEvent>>(); @@ -529,7 +529,7 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { default_builtin_cache.insert("ui_text_delete_all_to_right", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_delete_all_to_right.macos", inputs); // Text Caret Movement Left/Right @@ -539,7 +539,7 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { default_builtin_cache.insert("ui_text_caret_left", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::LEFT | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::LEFT | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_caret_word_left", inputs); inputs = List<Ref<InputEvent>>(); @@ -551,7 +551,7 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { default_builtin_cache.insert("ui_text_caret_right", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::RIGHT | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::RIGHT | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_caret_word_right", inputs); inputs = List<Ref<InputEvent>>(); @@ -576,7 +576,7 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { inputs = List<Ref<InputEvent>>(); inputs.push_back(InputEventKey::create_reference(Key::A | KeyModifierMask::CTRL)); - inputs.push_back(InputEventKey::create_reference(Key::LEFT | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::LEFT | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_caret_line_start.macos", inputs); inputs = List<Ref<InputEvent>>(); @@ -585,7 +585,7 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { inputs = List<Ref<InputEvent>>(); inputs.push_back(InputEventKey::create_reference(Key::E | KeyModifierMask::CTRL)); - inputs.push_back(InputEventKey::create_reference(Key::RIGHT | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::RIGHT | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_caret_line_end.macos", inputs); // Text Caret Movement Page Up/Down @@ -601,47 +601,47 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { // Text Caret Movement Document Start/End inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::HOME | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::HOME | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_caret_document_start", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_caret_document_start.macos", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::END | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::END | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_caret_document_end", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_caret_document_end.macos", inputs); // Text Scrolling inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_scroll_up", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::CMD | KeyModifierMask::ALT)); + inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::ALT)); default_builtin_cache.insert("ui_text_scroll_up.macos", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_scroll_down", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::CMD | KeyModifierMask::ALT)); + inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::ALT)); default_builtin_cache.insert("ui_text_scroll_down.macos", inputs); // Text Misc inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::A | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::A | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_select_all", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::D | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::D | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_select_word_under_caret", inputs); inputs = List<Ref<InputEvent>>(); @@ -660,7 +660,7 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { // ///// UI Graph Shortcuts ///// inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::D | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::D | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_graph_duplicate", inputs); inputs = List<Ref<InputEvent>>(); @@ -681,7 +681,7 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { default_builtin_cache.insert("ui_filedialog_show_hidden", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::QUOTELEFT | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::QUOTELEFT | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_swap_input_direction", inputs); return default_builtin_cache; diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index a592791d06..f3be495c8e 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -61,12 +61,16 @@ static const _KeyCodeText _keycodes[] = { {Key::PAGEDOWN ,"PageDown"}, {Key::SHIFT ,"Shift"}, {Key::CTRL ,"Ctrl"}, -#ifdef MACOS_ENABLED +#if defined(MACOS_ENABLED) {Key::META ,"Command"}, + {Key::ALT ,"Option"}, +#elif defined(WINDOWS_ENABLED) + {Key::META ,"Windows"}, + {Key::ALT ,"Alt"}, #else {Key::META ,"Meta"}, -#endif {Key::ALT ,"Alt"}, +#endif {Key::CAPSLOCK ,"CapsLock"}, {Key::NUMLOCK ,"NumLock"}, {Key::SCROLLLOCK ,"ScrollLock"}, @@ -437,6 +441,14 @@ String keycode_get_string(Key p_code) { codestr += find_keycode_name(Key::ALT); codestr += "+"; } + if ((p_code & KeyModifierMask::CMD_OR_CTRL) != Key::NONE) { +#ifdef MACOS_ENABLED + codestr += find_keycode_name(Key::META); +#else + codestr += find_keycode_name(Key::CTRL); +#endif + codestr += "+"; + } if ((p_code & KeyModifierMask::CTRL) != Key::NONE) { codestr += find_keycode_name(Key::CTRL); codestr += "+"; diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 29418049cb..e5d9b24e85 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -36,11 +36,11 @@ enum class Key { NONE = 0, // Special key: The strategy here is similar to the one used by toolkits, - // which consists in leaving the 24 bits unicode range for printable - // characters, and use the upper 8 bits for special keys and modifiers. + // which consists in leaving the 21 bits unicode range for printable + // characters, and use the upper 11 bits for special keys and modifiers. // This way everything (char/keycode) can fit nicely in one 32-bit // integer (the enum's underlying type is `int` by default). - SPECIAL = (1 << 24), + SPECIAL = (1 << 22), /* CURSOR/FUNCTION/BROWSER/MULTIMEDIA/MISC KEYS */ ESCAPE = SPECIAL | 0x01, TAB = SPECIAL | 0x02, @@ -312,17 +312,14 @@ enum class Key { }; enum class KeyModifierMask { - CODE_MASK = ((1 << 25) - 1), ///< Apply this mask to any keycode to remove modifiers. - MODIFIER_MASK = (0x7F << 24), ///< Apply this mask to isolate modifiers. + CODE_MASK = ((1 << 23) - 1), ///< Apply this mask to any keycode to remove modifiers. + MODIFIER_MASK = (0x7F << 22), ///< Apply this mask to isolate modifiers. + //RESERVED = (1 << 23), + CMD_OR_CTRL = (1 << 24), SHIFT = (1 << 25), ALT = (1 << 26), META = (1 << 27), CTRL = (1 << 28), -#ifdef APPLE_STYLE_KEYS - CMD = META, -#else - CMD = CTRL, -#endif KPAD = (1 << 29), GROUP_SWITCH = (1 << 30) }; |