summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-04-03 11:33:31 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-04-08 22:31:21 +0200
commit085d5db90dd4c148fe5dea6a3435166f6bdeedac (patch)
treee829caeef11320dae47f52ccaba1432646b4aad6 /src/plugins/platforms/cocoa
parent5994def6aba46772b28650945ba7b5ea4b036cee (diff)
macOS: Send key press as QKeyEvent if input context doesn't consume it
If IM is enabled we send key events through the macOS text input system, and we do this for all key pressed, including the ones with modifiers pressed. The latter allows the input method to respond to shortcut key combinations to switch its own mode or do more advanced operations on the text. We were relying on the IM to call doCommandBySelector with a noop selector if the shortcut didn't match any of its own internal key sequences, but this fails for key events with more than one modifier pressed. Instead of using [NSView interpretKeyEvents:] to pass the key event to the system IM we now go directly to the NSInputContext, which the former method is just a wrapper for. This allows us to use the result of [NSInputContext handleEvent:] to determine if the system IM consumed the event or not. For key events with multiple modifiers this will be false, which we interpret to send the event as a regular QKeyEvent instead. Fixes: QTBUG-123848 Fixes: QTBUG-106516 Pick-to: 6.7 6.5 6.2 Change-Id: I14a43c2029149514515dd9ece881aed3f6500a4e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qnsview_keys.mm5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview_keys.mm b/src/plugins/platforms/cocoa/qnsview_keys.mm
index 118678ffa5..d9d9f0a794 100644
--- a/src/plugins/platforms/cocoa/qnsview_keys.mm
+++ b/src/plugins/platforms/cocoa/qnsview_keys.mm
@@ -94,7 +94,10 @@ static bool isSpecialKey(const QString &text)
qCDebug(lcQpaKeys) << "Interpreting key event for focus object" << focusObject;
m_currentlyInterpretedKeyEvent = nsevent;
- [self interpretKeyEvents:@[nsevent]];
+ if (![self.inputContext handleEvent:nsevent]) {
+ qCDebug(lcQpaKeys) << "Input context did not consume event";
+ m_sendKeyEvent = true;
+ }
m_currentlyInterpretedKeyEvent = 0;
didInterpretKeyEvent = true;