summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoawindow.mm
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-08-01 18:47:45 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-08-03 16:09:17 +0200
commit3f3b2be870c34ef72034d4b853ef202e478c7cb7 (patch)
treee08128c36a93ebcd8489065916c94d5e77078362 /src/plugins/platforms/cocoa/qcocoawindow.mm
parent5e6d46a9f7055163182b080f0daea063889bfbd7 (diff)
macOS: Ensure foreign windows can be reparented via QWindow::setParent()
In b64b0c7947f9f2b0ab4ed33fe526880f54e3981f we bailed out from QCocoaWindow::recreateWindowIfNeeded() for foreign windows, as we should not manage any NSWindows on their behalf. Unfortunately QCocoaWindow::recreateWindowIfNeeded() also took care of adding the view as a subview to the potential non top level view, which we do want for foreign views. Ideally we'd move the reparenting out of recreateWindowIfNeeded() and into QCocoaWindow::setParent(), but this is a more intrusive change, so for now just restore the original missing logic. Pick-to: 6.6 6.5 Change-Id: Ic35ebf94d4adc2f19cedb1cb6a5d0215a1c9c2b4 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Christian Strømme <christian.stromme@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 3342f29614..470b3f4614 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -1448,16 +1448,22 @@ void QCocoaWindow::recreateWindowIfNeeded()
{
QMacAutoReleasePool pool;
+ QPlatformWindow *parentWindow = QPlatformWindow::parent();
+ auto *parentCocoaWindow = static_cast<QCocoaWindow *>(parentWindow);
+
if (isForeignWindow()) {
// A foreign window is created as such, and can never move between being
// foreign and not, so we don't need to get rid of any existing NSWindows,
// nor create new ones, as a foreign window is a single simple NSView.
qCDebug(lcQpaWindow) << "Skipping NSWindow management for foreign window" << this;
+
+ // We do however need to manage the parent relationship
+ if (parentCocoaWindow)
+ [parentCocoaWindow->m_view addSubview:m_view];
+
return;
}
- QPlatformWindow *parentWindow = QPlatformWindow::parent();
-
const bool isEmbeddedView = isEmbedded();
RecreationReasons recreateReason = RecreationNotNeeded;
@@ -1495,8 +1501,6 @@ void QCocoaWindow::recreateWindowIfNeeded()
if (recreateReason == RecreationNotNeeded)
return;
- QCocoaWindow *parentCocoaWindow = static_cast<QCocoaWindow *>(parentWindow);
-
// Remove current window (if any)
if ((isContentView() && !shouldBeContentView) || (recreateReason & PanelChanged)) {
if (m_nsWindow) {