summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2022-09-02 12:37:48 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2022-09-07 18:45:35 +0200
commit6f4d233062d44bd46b2f03596e72f0bc9709d2b5 (patch)
treecbd85008acd264327074698cf2e25b5f98dede6d /core/os
parent6b92dbfce2868f71926d2720014e45af999f21be (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/os')
-rw-r--r--core/os/keyboard.cpp16
-rw-r--r--core/os/keyboard.h17
2 files changed, 21 insertions, 12 deletions
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)
};