From 2e5a881d347b2b20cfe19f0a9d9cb89f2c441408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 1 Apr 2025 16:49:58 +0200 Subject: [PATCH] =?UTF-8?q?Account=20for=20Qt::AA=5FMacDontSwapCtrlAndMeta?= =?UTF-8?q?=20when=20mapping=20Latin=20=E2=8C=98-shortcuts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/gui/platform/darwin/qapplekeymapper.mm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/gui/platform/darwin/qapplekeymapper.mm b/src/gui/platform/darwin/qapplekeymapper.mm index c3c74539248..214865864ff 100644 --- a/src/gui/platform/darwin/qapplekeymapper.mm +++ b/src/gui/platform/darwin/qapplekeymapper.mm @@ -535,9 +535,14 @@ QList 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