diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoakeymapper.h | 27 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoakeymapper.mm | 5 |
2 files changed, 8 insertions, 24 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoakeymapper.h b/src/plugins/platforms/cocoa/qcocoakeymapper.h index c0540bfe1d..dbf164c18e 100644 --- a/src/plugins/platforms/cocoa/qcocoakeymapper.h +++ b/src/plugins/platforms/cocoa/qcocoakeymapper.h @@ -49,27 +49,6 @@ QT_BEGIN_NAMESPACE -/* - \internal - A Mac KeyboardLayoutItem has 8 possible states: - 1. Unmodified - 2. Shift - 3. Control - 4. Control + Shift - 5. Alt - 6. Alt + Shift - 7. Alt + Control - 8. Alt + Control + Shift - 9. Meta - 10. Meta + Shift - 11. Meta + Control - 12. Meta + Control + Shift - 13. Meta + Alt - 14. Meta + Alt + Shift - 15. Meta + Alt + Control - 16. Meta + Alt + Control + Shift -*/ - class QCocoaKeyMapper { public: @@ -83,8 +62,8 @@ public: static Qt::Key fromCocoaKey(QChar keyCode); private: - using VirtualKeyCode = unsigned short; - struct KeyMap : std::array<char32_t, 16> + static constexpr int kNumModifierCombinations = 16; + struct KeyMap : std::array<char32_t, kNumModifierCombinations> { // Initialize first element to a sentinel that allows us // to distinguish an uninitialized map from an initialized. @@ -94,6 +73,8 @@ private: }; bool updateKeyboard(); + + using VirtualKeyCode = unsigned short; const KeyMap &keyMapForKey(VirtualKeyCode virtualKey, QChar unicodeKey) const; QCFType<TISInputSourceRef> m_currentInputSource = nullptr; diff --git a/src/plugins/platforms/cocoa/qcocoakeymapper.mm b/src/plugins/platforms/cocoa/qcocoakeymapper.mm index bcc5a9ef0c..d1654e84bb 100644 --- a/src/plugins/platforms/cocoa/qcocoakeymapper.mm +++ b/src/plugins/platforms/cocoa/qcocoakeymapper.mm @@ -444,6 +444,8 @@ static constexpr Qt::KeyboardModifiers modifierCombinations[] = { */ const QCocoaKeyMapper::KeyMap &QCocoaKeyMapper::keyMapForKey(VirtualKeyCode virtualKey, QChar unicodeKey) const { + static_assert(sizeof(modifierCombinations) / sizeof(Qt::KeyboardModifiers) == kNumModifierCombinations); + const_cast<QCocoaKeyMapper *>(this)->updateKeyboard(); auto &keyMap = m_keyMap[virtualKey]; @@ -452,7 +454,7 @@ const QCocoaKeyMapper::KeyMap &QCocoaKeyMapper::keyMapForKey(VirtualKeyCode virt qCDebug(lcQpaKeyMapper, "Updating key map for virtual key = 0x%02x!", (uint)virtualKey); - for (int i = 0; i < 16; ++i) { + for (int i = 0; i < kNumModifierCombinations; ++i) { Q_ASSERT(!i || keyMap[i] == 0); auto qtModifiers = modifierCombinations[i]; @@ -514,6 +516,7 @@ QList<int> QCocoaKeyMapper::possibleKeys(const QKeyEvent *event) const // is always valid, and the first priority. ret << int(unmodifiedKey + eventModifiers); + // FIXME: We only compute the first 8 combinations. Why? for (int i = 1; i < 8; ++i) { auto keyAfterApplyingModifiers = keyMap[i]; if (keyAfterApplyingModifiers == unmodifiedKey) |