summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-06-20 14:08:20 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-06-26 20:47:45 +0200
commit21f3a6d8c5dc737c82cdc02c5debb6cf86894d98 (patch)
treef0d3c7df6194452d53882c4f0c1c5b3ab741ae41 /src/plugins/platforms/cocoa
parentdae24df07fb3db37939e9ece4cf94f223a125f16 (diff)
macOS: Propagate mouse enter/exit for windows embedded into foreign windows
Similar to the isEmbedded() case, when the parent of a QWindow is a foreign window, created via QWindow::fromWinId(), we don't have a QNSView parent that will handle mouse enter/exit on our behalf. Longer term we probably want to fold this case into the isEmbedded() case, but as that function is used other places too this requires some more research, so for now let's fix hover events. Fixes: QTBUG-114605 Pick-to: 6.5 6.6 Change-Id: Ib61aefc84ed080417a6820a4a365555424b208be Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qnsview_mouse.mm30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm
index 396029767c..2fd57fe68e 100644
--- a/src/plugins/platforms/cocoa/qnsview_mouse.mm
+++ b/src/plugins/platforms/cocoa/qnsview_mouse.mm
@@ -543,6 +543,30 @@ static const QPointingDevice *pointingDeviceFor(qint64 deviceID)
[self handleMouseEvent: theEvent];
}
+- (BOOL)shouldPropagateMouseEnterExit
+{
+ Q_ASSERT(m_platformWindow);
+
+ // We send out enter and leave events mainly from mouse move events (mouseMovedImpl),
+ // but in some case (see mouseEnteredImpl:) we also want to propagate enter/leave
+ // events from the platform. We only do this for windows that themselves are not
+ // handled by another parent QWindow.
+
+ if (m_platformWindow->isContentView())
+ return true;
+
+ // Windows manually embedded into a native view does not have a QWindow parent
+ if (m_platformWindow->isEmbedded())
+ return true;
+
+ // Windows embedded via fromWinId do, but the parent isn't a QNSView
+ QPlatformWindow *parentWindow = m_platformWindow->QPlatformWindow::parent();
+ if (parentWindow && parentWindow->isForeignWindow())
+ return true;
+
+ return false;
+}
+
- (void)mouseEnteredImpl:(NSEvent *)theEvent
{
Q_UNUSED(theEvent);
@@ -566,8 +590,7 @@ static const QPointingDevice *pointingDeviceFor(qint64 deviceID)
// in time (s_windowUnderMouse). The latter is also used to also send out enter/leave
// events when the application is activated/deactivated.
- // Root (top level or embedded) windows generate enter events for sub-windows
- if (!m_platformWindow->isContentView() && !m_platformWindow->isEmbedded())
+ if (![self shouldPropagateMouseEnterExit])
return;
QPointF windowPoint;
@@ -593,8 +616,7 @@ static const QPointingDevice *pointingDeviceFor(qint64 deviceID)
if (!m_platformWindow)
return;
- // Root (top level or embedded) windows generate enter events for sub-windows
- if (!m_platformWindow->isContentView() && !m_platformWindow->isEmbedded())
+ if (![self shouldPropagateMouseEnterExit])
return;
QCocoaWindow *windowToLeave = QCocoaWindow::s_windowUnderMouse;