diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-06-28 16:04:51 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-06-30 12:58:32 +0200 |
commit | 3021b1ecb7e1ec6e75e851c44f8ded9b8552235b (patch) | |
tree | d3b8260b0abb2004bb995ea08a64260226f1d6ca /src/plugins/platforms/cocoa/qcocoakeymapper.mm | |
parent | d962de314b0e78250952b5ea493bbe47f4f3e4c8 (diff) |
Simplify QCocoaKeyMapper by always returning a valid keymap
QCocoaKeyMapper::updateKeyMap would always end up creating a
valid key map, so the logic in CocoaKeyMapper::possibleKeys
for dealing with missing keymaps was not needed, and was
likely copied from one of the other key map implementations.
Since we know that we have a key map we might as well return
it after possibly updating it.
Change-Id: If83974f4ddedae8b1acefbadef48da3ee326eadd
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoakeymapper.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoakeymapper.mm | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoakeymapper.mm b/src/plugins/platforms/cocoa/qcocoakeymapper.mm index a0004f6f8f..c326c1ca84 100644 --- a/src/plugins/platforms/cocoa/qcocoakeymapper.mm +++ b/src/plugins/platforms/cocoa/qcocoakeymapper.mm @@ -363,15 +363,16 @@ static constexpr Qt::KeyboardModifiers modifierCombinations[] = { }; /* - Updates the key map for the given \macVirtualKey by applying - all possible modifier combinations. + Returns a key map for the given \macVirtualKey based on all + possible modifier combinations. */ -void QCocoaKeyMapper::updateKeyMap(unsigned short macVirtualKey, QChar unicodeKey) +KeyboardLayoutItem *QCocoaKeyMapper::keyMapForKey(unsigned short macVirtualKey, QChar unicodeKey) const { - updateKeyboard(); + const_cast<QCocoaKeyMapper *>(this)->updateKeyboard(); - if (m_keyLayout[macVirtualKey]) - return; + Q_ASSERT(macVirtualKey < 256); + if (auto *existingKeyMap = m_keyLayout[macVirtualKey]) + return existingKeyMap; qCDebug(lcQpaKeyMapper, "Updating key map for virtual key = 0x%02x!", (uint)macVirtualKey); @@ -402,27 +403,25 @@ void QCocoaKeyMapper::updateKeyMap(unsigned short macVirtualKey, QChar unicodeKe qCDebug(lcQpaKeyMapper, " [%d] (%d,0x%02x,'%c')", i, qtkey, qtkey, qtkey); } + + return m_keyLayout[macVirtualKey]; } QList<int> QCocoaKeyMapper::possibleKeys(const QKeyEvent *event) const { QList<int> ret; - auto virtualKey = event->nativeVirtualKey(); - const_cast<QCocoaKeyMapper *>(this)->updateKeyMap(virtualKey, QChar(event->key())); - KeyboardLayoutItem *keyLayout = m_keyLayout[virtualKey]; - - if (!keyLayout) // Key is not in any keyboard layout (e.g. eisu-key on Japanese keyboard) - return ret; + auto *keyMap = keyMapForKey(event->nativeVirtualKey(), QChar(event->key())); + Q_ASSERT(keyMap); - int baseKey = keyLayout->qtKey[Qt::NoModifier]; + int baseKey = keyMap->qtKey[Qt::NoModifier]; auto eventModifiers = event->modifiers(); // The base key is always valid ret << int(baseKey + eventModifiers); for (int i = 1; i < 8; ++i) { - int keyAfterApplyingModifiers = keyLayout->qtKey[i]; + int keyAfterApplyingModifiers = keyMap->qtKey[i]; if (!keyAfterApplyingModifiers) continue; if (keyAfterApplyingModifiers == baseKey) |