summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2015-09-04 22:50:11 +0200
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2015-10-12 17:14:00 +0000
commit676edc006e9f439d839fd77c0cce1a2e7f064359 (patch)
tree0a3165be8c8d6d32f99033aa55ea4d35f36db25d /src/plugins/platforms/cocoa
parenta623fe8d2a60ff333d5779f877e3b20f0e141ff1 (diff)
OS X: Forward key events to popup window if present
On OS X we don't treat popup windows as worthy of being activated and focus windows (key windows). Instead we keep track of the active popup windows and forward events to them manually. The forwarding logic is split between QPA, which handles mouse, and QWidgetWindow and QQuickWindowPrivate, which handles key events. This commit adds the logic for key events to QPA, which is the right platform layer for this kind of workarounds. The widget code is left as is for now, and the QQuickWindowPrivate code can be removed in a follow up. Task-number: QTBUG-39415 Change-Id: Iee411fcba9fc81ddcc3a7bc82591184675a6d7a2 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index 24ee26ce46..8c22e51fe2 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -1441,12 +1441,17 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
if (!(modifiers & (Qt::ControlModifier | Qt::MetaModifier)) && (ch.unicode() < 0xf700 || ch.unicode() > 0xf8ff))
text = QCFString::toQString(characters);
- QWindow *focusWindow = [self topLevelWindow];
+ QWindow *window = [self topLevelWindow];
+
+ // Popups implicitly grab key events; forward to the active popup if there is one.
+ // This allows popups to e.g. intercept shortcuts and close the popup in response.
+ if (QCocoaWindow *popup = QCocoaIntegration::instance()->activePopupWindow())
+ window = popup->window();
if (eventType == QEvent::KeyPress) {
if (m_composingText.isEmpty()) {
- m_sendKeyEvent = !QWindowSystemInterface::handleShortcutEvent(focusWindow, timestamp, keyCode,
+ m_sendKeyEvent = !QWindowSystemInterface::handleShortcutEvent(window, timestamp, keyCode,
modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, [nsevent isARepeat], 1);
}
@@ -1469,7 +1474,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
}
if (m_sendKeyEvent && m_composingText.isEmpty())
- QWindowSystemInterface::handleExtendedKeyEvent(focusWindow, timestamp, QEvent::Type(eventType), keyCode, modifiers,
+ QWindowSystemInterface::handleExtendedKeyEvent(window, timestamp, QEvent::Type(eventType), keyCode, modifiers,
nativeScanCode, nativeVirtualKey, nativeModifiers, text, [nsevent isARepeat], 1, false);
m_sendKeyEvent = false;