macOS: Fix mapping of Qt to Carbon modifiers with AA_MacDontSwapCtrlAndMeta

The macOS platform plugin function toCarbonModifiers is based on a
mapping table with already swapped modifiers, where Qt::MetaModifier
maps to controlKey.

We were using the Carbon fooKeyBit constants instead of the fooKey
constants, so the logic for mapping from Qt to Carbon modifiers
when AA_MacDontSwapCtrlAndMeta was set to true would fail to reverse
the swap from the mapping table.

Since the command and control modifiers rarely produce different
unicode characters from the base keyboard layout, at least not in
the tested key layouts, and the AA_MacDontSwapCtrlAndMeta is not
commonly used, this bug was not that visible.

The logic maintains the behavior of mapping a single Qt modifier
to multiple Carbon modifiers (both left and right command e.g.).
This is a bit weird, but existing behavior that should be looked
at in a followup.

Change-Id: I8b30854770d1230a47f5144bf3245d0ac1493b51
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Tor Arne Vestbø 2020-07-02 15:24:37 +02:00
parent fdc5e91dcf
commit 7b2cc3fc75

View File

@ -119,11 +119,11 @@ static CarbonModifiers toCarbonModifiers(Qt::KeyboardModifiers qtModifiers)
if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
int oldModifiers = carbonModifiers;
carbonModifiers &= ~(controlKeyBit | cmdKeyBit);
if (oldModifiers & controlKeyBit)
carbonModifiers |= cmdKeyBit;
if (oldModifiers & cmdKeyBit)
carbonModifiers |= controlKeyBit;
carbonModifiers &= ~(controlKey | rightControlKey | cmdKey);
if (oldModifiers & (controlKey | rightControlKey))
carbonModifiers |= cmdKey;
if (oldModifiers & cmdKey)
carbonModifiers |= (controlKey | rightControlKey);
}
return carbonModifiers;
}