From 93a82ae35d4e99a25ef1b5296ef502011bbd8d9d Mon Sep 17 00:00:00 2001 From: ronso0 Date: Wed, 17 Jul 2024 10:40:25 +0200 Subject: [PATCH] (fix) avoid catching Num key modifier on macOS fixes #13305 --- .../keyboard/keyboardeventfilter.cpp | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/controllers/keyboard/keyboardeventfilter.cpp b/src/controllers/keyboard/keyboardeventfilter.cpp index c11cdf4e3d6..45ac498cd40 100644 --- a/src/controllers/keyboard/keyboardeventfilter.cpp +++ b/src/controllers/keyboard/keyboardeventfilter.cpp @@ -125,23 +125,29 @@ QKeySequence KeyboardEventFilter::getKeySeq(QKeyEvent* e) { return {}; } + // Note: test for individual modifiers, don't use e->modifiers() for composing + // the QKeySequence because on macOS e->modifiers() would for some reason + // include the Num modifier for arrow keys which results in a key sequence + // for which there would be no match in our keyseq/control hash. + // See https://github.com/mixxxdj/mixxx/issues/13305 + QString modseq; + if (e->modifiers() & Qt::ShiftModifier) { + modseq += "Shift+"; + } + if (e->modifiers() & Qt::ControlModifier) { + modseq += "Ctrl+"; + } + if (e->modifiers() & Qt::AltModifier) { + modseq += "Alt+"; + } + if (e->modifiers() & Qt::MetaModifier) { + modseq += "Meta+"; + } + + const QString keyseq = QKeySequence(e->key()).toString(); + const QKeySequence k = QKeySequence(modseq + keyseq); + if (CmdlineArgs::Instance().getDeveloper()) { - QString modseq; - QKeySequence k; - if (e->modifiers() & Qt::ShiftModifier) { - modseq += "Shift+"; - } - if (e->modifiers() & Qt::ControlModifier) { - modseq += "Ctrl+"; - } - if (e->modifiers() & Qt::AltModifier) { - modseq += "Alt+"; - } - if (e->modifiers() & Qt::MetaModifier) { - modseq += "Meta+"; - } - QString keyseq = QKeySequence(e->key()).toString(); - k = QKeySequence(modseq + keyseq); if (e->type() == QEvent::KeyPress) { qDebug() << "keyboard press: " << k.toString(); } else if (e->type() == QEvent::KeyRelease) { @@ -149,11 +155,7 @@ QKeySequence KeyboardEventFilter::getKeySeq(QKeyEvent* e) { } } -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - return QKeySequence(e->modifiers() | e->key()); -#else - return QKeySequence(e->modifiers() + e->key()); -#endif + return k; } void KeyboardEventFilter::setKeyboardConfig(ConfigObject* pKbdConfigObject) {