Account for Qt::AA_MacDontSwapCtrlAndMeta when mapping Latin ⌘-shortcuts

To follow the system we map key events that include ⌘ as if they had
been made using a Latin/Roman keyboard layout. However when looking
for the ⌘-keymap, we were not taking Qt::AA_MacDontSwapCtrlAndMeta
into account, and since the keymap differs whether the attribute is
set or not we ended up pulling the Meta-keymap instead.

Fixes: QTBUG-133963
Pick-to: 6.9 6.8
Change-Id: I32dd06025e1e1d93f3792952e6ad842efc6245a6
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Tor Arne Vestbø 2025-04-01 16:49:58 +02:00
parent bb69d80975
commit 2e5a881d34

View File

@ -535,9 +535,14 @@ QList<QKeyCombination> QAppleKeyMapper::possibleKeyCombinations(const QKeyEvent
// modifier layer in all/most keyboard layouts contains a Latin
// layer. We then combine that with the modifiers of the event
// to produce the resulting "Latin" key combination.
static constexpr int kCommandLayer = 2;
ret << QKeyCombination::fromCombined(
int(eventModifiers) + int(keyMap[kCommandLayer]));
// Depending on whether Qt::AA_MacDontSwapCtrlAndMeta is set or not
// the index of the Command layer in modifierCombinations will differ.
const int commandLayer = qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta) ? 8 : 2;
// FIXME: We don't clear the key map when Qt::AA_MacDontSwapCtrlAndMeta
// is set, so changing Qt::AA_MacDontSwapCtrlAndMeta at runtime will
// fail once we've built the key map.
ret << QKeyCombination::fromCombined(int(eventModifiers) + int(keyMap[commandLayer]));
// If the unmodified key is outside of Latin1, we also treat
// that as a valid key combination, even if AppKit natively