macOS: Ensure foreign windows can be reparented via QWindow::setParent()

In b64b0c7947 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>
bb10
Tor Arne Vestbø 2023-08-01 18:47:45 +02:00
parent 5e6d46a9f7
commit 3f3b2be870
1 changed files with 8 additions and 4 deletions

View File

@ -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) {