summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorMichael Brüning <michael.bruning@qt.io>2020-08-24 18:07:23 +0200
committerMichael Brüning <michael.bruning@qt.io>2020-09-10 17:33:21 +0200
commitac310d5b23b56a217c408f8ee549c36f73c7a437 (patch)
treeb44fe4e85c3ec6feb7d7516336d44691c1c77ad4 /src/plugins/platforms/cocoa
parenta4e4436e852c600a7ecd13b83fc487164dbc5ad7 (diff)
[macOS] Add native virtual key code to modifier keys
Not forwarding the native virtual key code when sending key events in the flagsChanged handler caused a number of problems, e.g. the inability to determine which of the Alt or Shift keys were pressed. Use handleExtendedKeyEvent to include the native virtual key code. Patch inspired by Nyan Pasu. Fixes: QTBUG-69608 Change-Id: I15e9ff1069528d4b50ee4638ab2d8a6fd279db0b Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qnsview_keys.mm27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview_keys.mm b/src/plugins/platforms/cocoa/qnsview_keys.mm
index 37c46204e1..f6599edb81 100644
--- a/src/plugins/platforms/cocoa/qnsview_keys.mm
+++ b/src/plugins/platforms/cocoa/qnsview_keys.mm
@@ -192,14 +192,20 @@
- (void)flagsChanged:(NSEvent *)nsevent
{
ulong timestamp = [nsevent timestamp] * 1000;
- ulong modifiers = [nsevent modifierFlags];
- Qt::KeyboardModifiers qmodifiers = QCocoaKeyMapper::fromCocoaModifiers(modifiers);
+ ulong nativeModifiers = [nsevent modifierFlags];
+ Qt::KeyboardModifiers modifiers = QCocoaKeyMapper::fromCocoaModifiers(nativeModifiers);
+
+ // There is no way to get the scan code from carbon/cocoa. But we cannot
+ // use the value 0, since it indicates that the event originates from somewhere
+ // else than the keyboard.
+ quint32 nativeScanCode = 1;
+ quint32 nativeVirtualKey = [nsevent keyCode];
// calculate the delta and remember the current modifiers for next time
static ulong m_lastKnownModifiers;
ulong lastKnownModifiers = m_lastKnownModifiers;
- ulong delta = lastKnownModifiers ^ modifiers;
- m_lastKnownModifiers = modifiers;
+ ulong delta = lastKnownModifiers ^ nativeModifiers;
+ m_lastKnownModifiers = nativeModifiers;
struct qt_mac_enum_mapper
{
@@ -225,11 +231,14 @@
else if (qtCode == Qt::Key_Control)
qtCode = Qt::Key_Meta;
}
- QWindowSystemInterface::handleKeyEvent(m_platformWindow->window(),
- timestamp,
- (lastKnownModifiers & mac_mask) ? QEvent::KeyRelease : QEvent::KeyPress,
- qtCode,
- qmodifiers ^ QCocoaKeyMapper::fromCocoaModifiers(mac_mask));
+ QWindowSystemInterface::handleExtendedKeyEvent(m_platformWindow->window(),
+ timestamp,
+ (lastKnownModifiers & mac_mask) ? QEvent::KeyRelease
+ : QEvent::KeyPress,
+ qtCode,
+ modifiers ^ QCocoaKeyMapper::fromCocoaModifiers(mac_mask),
+ nativeScanCode, nativeVirtualKey,
+ nativeModifiers ^ mac_mask);
}
}