summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-07-24 11:48:44 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-07-24 12:33:46 +0200
commit8361c6252fecf8b95cf06560f852b1e9b5c6b82b (patch)
treec1d4b2cef3a48d10f9b53322ffa161402e150846 /src
parent865582bd7fd9b7e22c46db01245fc700e5e2bbd7 (diff)
macOS: Clarify that QCocoaKeyMapper only computes 8 modifier states
Change-Id: Ie4a53bbc16cde7b4aa68172015bbfeaa9e316bcc Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/cocoa/qcocoakeymapper.h27
-rw-r--r--src/plugins/platforms/cocoa/qcocoakeymapper.mm5
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)