diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-07-10 12:13:36 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-07-13 14:57:13 +0200 |
commit | fab3dfff7d53d496a31c5d2df972ddacfe861a4d (patch) | |
tree | ccac517903441183245c525634978636785fb040 /src/plugins/platforms/cocoa/qcocoakeymapper.h | |
parent | ce9efcf4a901fbb245fc7a9a6605b8c8fc25e91d (diff) |
macOS: Modernize QCocoaKeyMapper key map
Change-Id: I3e8a4cfa611b6ae575466c493aac438dc831e89a
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoakeymapper.h')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoakeymapper.h | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoakeymapper.h b/src/plugins/platforms/cocoa/qcocoakeymapper.h index 7f20a37125..c0540bfe1d 100644 --- a/src/plugins/platforms/cocoa/qcocoakeymapper.h +++ b/src/plugins/platforms/cocoa/qcocoakeymapper.h @@ -69,16 +69,10 @@ QT_BEGIN_NAMESPACE 15. Meta + Alt + Control 16. Meta + Alt + Control + Shift */ -struct KeyboardLayoutItem { - quint32 qtKey[16]; // Can by any Qt::Key_<foo>, or unicode character -}; - class QCocoaKeyMapper { public: - QCocoaKeyMapper(); - ~QCocoaKeyMapper(); static Qt::KeyboardModifiers queryKeyboardModifiers(); QList<int> possibleKeys(const QKeyEvent *event) const; @@ -89,9 +83,18 @@ public: static Qt::Key fromCocoaKey(QChar keyCode); private: + using VirtualKeyCode = unsigned short; + struct KeyMap : std::array<char32_t, 16> + { + // Initialize first element to a sentinel that allows us + // to distinguish an uninitialized map from an initialized. + // Using 0 would not allow us to map U+0000 (NUL), however + // unlikely that is. + KeyMap() : std::array<char32_t, 16>{Qt::Key_unknown} {} + }; + bool updateKeyboard(); - void deleteLayouts(); - KeyboardLayoutItem *keyMapForKey(unsigned short macVirtualKey, QChar unicodeKey) const; + const KeyMap &keyMapForKey(VirtualKeyCode virtualKey, QChar unicodeKey) const; QCFType<TISInputSourceRef> m_currentInputSource = nullptr; @@ -99,7 +102,8 @@ private: const UCKeyboardLayout *m_keyboardLayoutFormat = nullptr; KeyboardLayoutKind m_keyboardKind = kKLKCHRuchrKind; mutable UInt32 m_deadKeyState = 0; // Maintains dead key state beween calls to UCKeyTranslate - mutable KeyboardLayoutItem *m_keyLayout[256]; + + mutable QHash<VirtualKeyCode, KeyMap> m_keyMap; }; QT_END_NAMESPACE |