From 12be9f1e11e253f85df2c9d3cda21313e0f26d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 27 Oct 2023 14:59:36 +0200 Subject: [PATCH] macOS: Check NSWindow as well when determining if setVisible can bail out In be268ae19731ab854931e43eea83e0e140ec2538 we made QCocoaWindow::setVisible idempotent by checking if NSView.hidden needed update. This failed to take into account the case when a window is moved from being a child window to a top level, where the window is still visible and the NSView's hidden state doesn't change, but we need to order in the NSWindow that we're now managing. We now check NSWindow.visible as well, if we're a top level window. Pick-to: 6.5 Change-Id: I94434d6ebfe2c9ece6eac7f83f17ead250ccc07a Reviewed-by: Timur Pocheptsov (cherry picked from commit be7e5f94a1c0e63d6e4dbea5649d12cdc879d8f6) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/cocoa/qcocoawindow.mm | 2 +- tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 7eb2a350d35..dcdbaedc202 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -320,7 +320,7 @@ void QCocoaWindow::setVisible(bool visible) return; // We'll get another setVisible call after create is done } - if (visible == !m_view.hidden) { + if (visible == !m_view.hidden && (!isContentView() || visible == m_view.window.visible)) { qCDebug(lcQpaWindow) << "No change in visible status. Ignoring."; return; } diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index fa7ab96efe6..5fa84b31eed 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -94,6 +94,7 @@ private slots: void enterLeaveOnWindowShowHide_data(); void enterLeaveOnWindowShowHide(); #endif + void windowExposedAfterReparent(); private: QPoint m_availableTopLeft; @@ -3003,6 +3004,25 @@ void tst_QWindow::enterLeaveOnWindowShowHide() } #endif +void tst_QWindow::windowExposedAfterReparent() +{ + QWindow parent; + QWindow child(&parent); + child.show(); + parent.show(); + + QVERIFY(QTest::qWaitForWindowExposed(&parent)); + QVERIFY(QTest::qWaitForWindowExposed(&child)); + + child.setParent(nullptr); + QCoreApplication::processEvents(); + QVERIFY(QTest::qWaitForWindowExposed(&child)); + + child.setParent(&parent); + QCoreApplication::processEvents(); + QVERIFY(QTest::qWaitForWindowExposed(&child)); +} + #include QTEST_MAIN(tst_QWindow)