summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2024-04-11 15:20:52 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2024-04-13 09:24:41 +0200
commit285294b684ac973efcf2c8ff92b427db3fb75948 (patch)
treea4291f3ae3ffd0ab75fb01b1912b4b09e32b0e1a /src/plugins/platforms/cocoa
parentd4c7da9a07dc1434692fe08a61ba22c794574c4f (diff)
macOS: support shortcut for Ctrl-modified Tab
Ctrl+(Shift/Option/Cmd)+Tab presses are not handled as a regular key events, and are not seen by our NSView.keyDown implementation. But they are delivered to a performKeyEquivalent implementation, so if we see a Tab key being pressed with the Ctrl modifier down, then send a shortcut event and stop processing if that event got accepted by Qt. Pick-to: 6.7 Fixes: QTBUG-113492 Task-number: QTBUG-8596 Change-Id: Id3aa7021a689b94d97eb881b19ddf7cb039e1bd2 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.mm39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview_keys.mm b/src/plugins/platforms/cocoa/qnsview_keys.mm
index d9d9f0a794..abee622e65 100644
--- a/src/plugins/platforms/cocoa/qnsview_keys.mm
+++ b/src/plugins/platforms/cocoa/qnsview_keys.mm
@@ -30,8 +30,36 @@ static bool isSpecialKey(const QString &text)
return false;
}
+static bool sendAsShortcut(const KeyEvent &keyEvent, QWindow *window)
+{
+ KeyEvent shortcutEvent = keyEvent;
+ shortcutEvent.type = QEvent::Shortcut;
+ qCDebug(lcQpaKeys) << "Trying potential shortcuts in" << window
+ << "for" << shortcutEvent;
+
+ if (shortcutEvent.sendWindowSystemEvent(window)) {
+ qCDebug(lcQpaKeys) << "Found matching shortcut; will not send as key event";
+ return true;
+ }
+ qCDebug(lcQpaKeys) << "No matching shortcuts; continuing with key event delivery";
+ return false;
+}
+
@implementation QNSView (Keys)
+- (bool)performKeyEquivalent:(NSEvent *)nsevent
+{
+ // Implemented to handle shortcuts for modified Tab keys, which are
+ // handled by Cocoa and not delivered to your keyDown implementation.
+ if (nsevent.type == NSEventTypeKeyDown && m_composingText.isEmpty()) {
+ const bool ctrlDown = [nsevent modifierFlags] & NSEventModifierFlagControl;
+ const bool isTabKey = nsevent.keyCode == kVK_Tab;
+ if (ctrlDown && isTabKey && sendAsShortcut(KeyEvent(nsevent), [self topLevelWindow]))
+ return YES;
+ }
+ return NO;
+}
+
- (bool)handleKeyEvent:(NSEvent *)nsevent
{
qCDebug(lcQpaKeys) << "Handling" << nsevent;
@@ -52,17 +80,8 @@ static bool isSpecialKey(const QString &text)
if (keyEvent.type == QEvent::KeyPress) {
if (m_composingText.isEmpty()) {
- KeyEvent shortcutEvent = keyEvent;
- shortcutEvent.type = QEvent::Shortcut;
- qCDebug(lcQpaKeys) << "Trying potential shortcuts in" << window
- << "for" << shortcutEvent;
-
- if (shortcutEvent.sendWindowSystemEvent(window)) {
- qCDebug(lcQpaKeys) << "Found matching shortcut; will not send as key event";
+ if (sendAsShortcut(keyEvent, window))
return true;
- } else {
- qCDebug(lcQpaKeys) << "No matching shortcuts; continuing with key event delivery";
- }
}
QObject *focusObject = m_platformWindow ? m_platformWindow->window()->focusObject() : nullptr;