diff options
authorTor Arne Vestbø <>2015-09-04 22:50:11 +0200
committerTor Arne Vestbø <>2015-10-12 17:14:00 +0000
commit676edc006e9f439d839fd77c0cce1a2e7f064359 (patch)
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 <> Reviewed-by: Morten Johan Sørvig <>
1 files changed, 8 insertions, 3 deletions
diff --git a/src/plugins/platforms/cocoa/ b/src/plugins/platforms/cocoa/
index 24ee26ce46..8c22e51fe2 100644
--- a/src/plugins/platforms/cocoa/
+++ b/src/plugins/platforms/cocoa/
@@ -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;