summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2013-09-30 16:40:55 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-16 17:10:15 +0200
commit42f0a4f2c91800830021ac974678e46d52f23ae7 (patch)
tree0fa7272bf260ceced9a0008dd286ebf12a546ab8 /src/plugins/platforms/cocoa
parent5b88f7b0ac1ac16ab7cc12242c675c6eb4413ff9 (diff)
Cocoa: Deliver key event to top-level QWidgetWindow
Having several QWidgetWindow in our hierarchy translates as as many NSViews. Clicking will make the NSView under the mouse cursor key, meaning it will receive all the Cocoa key events. In order to make sure the QWidgets hierarchy sees the key event "as usual," we climb the QWindow hierarchy in search for the top-level QWidgetWindow. (Something similar is already being done in -[QNSView becomeFirstResponder]). Task-number: QTBUG-32914 Change-Id: Idc700309d202820de326d4e2990fad24d7b692ae Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index 8813a934bf..f471a61aa0 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -208,6 +208,22 @@ static QTouchDevice *touchDevice = 0;
if ([self window])
[[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:[self window]];
}
+
+- (QWindow *)topLevelWindow
+{
+ QWindow *focusWindow = m_window;
+
+ // For widgets we need to do a bit of trickery as the window
+ // to activate is the window of the top-level widget.
+ if (m_window->metaObject()->className() == QStringLiteral("QWidgetWindow")) {
+ while (focusWindow->parent()) {
+ focusWindow = focusWindow->parent();
+ }
+ }
+
+ return focusWindow;
+}
+
- (void)updateGeometry
{
QRect geometry;
@@ -457,16 +473,7 @@ static QTouchDevice *touchDevice = 0;
{
if (m_window->flags() & Qt::WindowTransparentForInput)
return NO;
- QWindow *focusWindow = m_window;
-
- // For widgets we need to do a bit of trickery as the window
- // to activate is the window of the top-level widget.
- if (m_window->metaObject()->className() == QStringLiteral("QWidgetWindow")) {
- while (focusWindow->parent()) {
- focusWindow = focusWindow->parent();
- }
- }
- QWindowSystemInterface::handleWindowActivated(focusWindow);
+ QWindowSystemInterface::handleWindowActivated([self topLevelWindow]);
return YES;
}
@@ -1124,10 +1131,12 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
if (ch.unicode() < 0xf700 || ch.unicode() > 0xf8ff)
text = QCFString::toQString(characters);
+ QWindow *focusWindow = [self topLevelWindow];
+
if (eventType == QEvent::KeyPress) {
if (m_composingText.isEmpty())
- m_sendKeyEvent = !QWindowSystemInterface::tryHandleShortcutEvent(m_window, timestamp, keyCode, modifiers, text);
+ m_sendKeyEvent = !QWindowSystemInterface::tryHandleShortcutEvent(focusWindow, timestamp, keyCode, modifiers, text);
QObject *fo = QGuiApplication::focusObject();
if (m_sendKeyEvent && fo) {
@@ -1144,7 +1153,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
}
if (m_sendKeyEvent && m_composingText.isEmpty())
- QWindowSystemInterface::handleExtendedKeyEvent(m_window, timestamp, QEvent::Type(eventType), keyCode, modifiers,
+ QWindowSystemInterface::handleExtendedKeyEvent(focusWindow, timestamp, QEvent::Type(eventType), keyCode, modifiers,
nativeScanCode, nativeVirtualKey, nativeModifiers, text, [nsevent isARepeat]);
m_sendKeyEvent = false;