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 6.6
Change-Id: I94434d6ebfe2c9ece6eac7f83f17ead250ccc07a
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Tor Arne Vestbø 2023-10-27 14:59:36 +02:00
parent a9c47dde50
commit be7e5f94a1
2 changed files with 21 additions and 1 deletions

View File

@ -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;
}

View File

@ -94,6 +94,7 @@ private slots:
void enterLeaveOnWindowShowHide_data();
void enterLeaveOnWindowShowHide();
#endif
void windowExposedAfterReparent();
private:
QPoint m_availableTopLeft;
@ -3007,6 +3008,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 <tst_qwindow.moc>
QTEST_MAIN(tst_QWindow)