macOS: Move AA_MacDontSwapCtrlAndMeta logic out of QPlatformTheme
Change-Id: Ia36f60587d98902406de7de8acdc3c4521cfd05a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>bb10
parent
e255146183
commit
1c8953e520
|
|
@ -608,21 +608,6 @@ QIconEngine *QPlatformTheme::createIconEngine(const QString &iconName) const
|
|||
return new QIconLoaderEngine(iconName);
|
||||
}
|
||||
|
||||
#if defined(Q_OS_MACOS)
|
||||
static inline int maybeSwapShortcut(int shortcut)
|
||||
{
|
||||
if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
|
||||
uint oldshortcut = shortcut;
|
||||
shortcut &= ~(Qt::CTRL | Qt::META);
|
||||
if (oldshortcut & Qt::CTRL)
|
||||
shortcut |= Qt::META;
|
||||
if (oldshortcut & Qt::META)
|
||||
shortcut |= Qt::CTRL;
|
||||
}
|
||||
return shortcut;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if QT_CONFIG(shortcut)
|
||||
// mixed-mode predicate: all of these overloads are actually needed (but not all for every compiler)
|
||||
struct ByStandardKey {
|
||||
|
|
@ -660,12 +645,8 @@ QList<QKeySequence> QPlatformTheme::keyBindings(QKeySequence::StandardKey key) c
|
|||
if (!(it->platform & platform))
|
||||
continue;
|
||||
|
||||
uint shortcut =
|
||||
#if defined(Q_OS_MACOS)
|
||||
maybeSwapShortcut(it->shortcut);
|
||||
#else
|
||||
it->shortcut;
|
||||
#endif
|
||||
uint shortcut = it->shortcut;
|
||||
|
||||
if (it->priority > 0)
|
||||
list.prepend(QKeySequence(shortcut));
|
||||
else
|
||||
|
|
|
|||
|
|
@ -80,6 +80,10 @@ public:
|
|||
|
||||
void handleSystemThemeChange();
|
||||
|
||||
#ifndef QT_NO_SHORTCUT
|
||||
QList<QKeySequence> keyBindings(QKeySequence::StandardKey key) const override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
mutable QPalette *m_systemPalette;
|
||||
QMacNotificationObserver m_systemColorObserver;
|
||||
|
|
|
|||
|
|
@ -561,4 +561,41 @@ QPlatformMenuBar *QCocoaTheme::createPlatformMenuBar() const
|
|||
return new QCocoaMenuBar();
|
||||
}
|
||||
|
||||
#ifndef QT_NO_SHORTCUT
|
||||
QList<QKeySequence> QCocoaTheme::keyBindings(QKeySequence::StandardKey key) const
|
||||
{
|
||||
// The default key bindings in QPlatformTheme all hard-coded to use the Ctrl
|
||||
// modifier, to match other platforms. In the normal case, when translating
|
||||
// those to key sequences, we'll end up with Qt::ControlModifier+X, which is
|
||||
// then matched against incoming key events that have been mapped from the
|
||||
// command key to Qt::ControlModifier, and we'll get a match. If, however,
|
||||
// the AA_MacDontSwapCtrlAndMeta application attribute is set, we need to
|
||||
// fix the resulting key sequence so that it will match against unmapped
|
||||
// key events that contain Qt::MetaModifier.
|
||||
auto bindings = QPlatformTheme::keyBindings(key);
|
||||
|
||||
if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
|
||||
static auto swapCtrlMeta = [](int keySequence) {
|
||||
auto originalKeySequence = keySequence;
|
||||
keySequence &= ~(Qt::ControlModifier | Qt::MetaModifier);
|
||||
if (originalKeySequence & Qt::ControlModifier)
|
||||
keySequence |= Qt::MetaModifier;
|
||||
if (originalKeySequence & Qt::MetaModifier)
|
||||
keySequence |= Qt::ControlModifier;
|
||||
return keySequence;
|
||||
};
|
||||
|
||||
QList<QKeySequence> swappedBindings;
|
||||
for (auto binding : bindings) {
|
||||
Q_ASSERT(binding.count() == 1);
|
||||
swappedBindings.append(QKeySequence(swapCtrlMeta(binding[0])));
|
||||
}
|
||||
|
||||
bindings = swappedBindings;
|
||||
}
|
||||
|
||||
return bindings;
|
||||
}
|
||||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
Loading…
Reference in New Issue