summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-04-08 17:19:10 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-04-19 14:54:17 +0200
commit988039729f55a5e62e32b82c6f29ff7457e91d9d (patch)
treedb0eb22f96befcf8e03b7d3cfc56725f932d5c0b /tests/auto/gui/kernel
parentde5c507a55097c08602f38062bf5291c9cbb4e24 (diff)
QWindow: Persist foreign winId to support destroy/create cycles
We used to set a private _q_foreignWinId property on QWindow when creating foreign windows, and this was the mechanism which we then passed the foreign winId to the platform plugin. With c585802e946d97e7d177ea334a162dc7bc286b84 this was removed, since we now were passing the winId through via explicit QPA APIs, and since 0c6911e5cde24c45d6f2c08b6e71064bdd1eccfa removed the ability to explicitly destroy() a foreign window. But when closing a QWindow, we destroy both the window itself, and all its children, including foreign windows. In this case we still want to support recreating the foreign window, for example when the parent window is shown again. To enable this we restore the _q_foreignWinId private property, but keep the limitation of not being able to explicitly destroy a foreign window. Pick-to: 6.7 6.5 Fixes: QTBUG-124160 Change-Id: Ia885ba9f043e64fb21eedd2b4c344679726f1b5c Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r--tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp
index e7b05e7037..526abd6ea3 100644
--- a/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp
@@ -26,6 +26,9 @@ private slots:
void embedForeignWindow();
void embedInForeignWindow();
+
+ void destroyExplicitly();
+ void destroyWhenParentIsDestroyed();
};
void tst_ForeignWindow::fromWinId()
@@ -138,5 +141,50 @@ void tst_ForeignWindow::embedInForeignWindow()
}
}
+void tst_ForeignWindow::destroyExplicitly()
+{
+ NativeWindow nativeWindow;
+ QVERIFY(nativeWindow);
+
+ std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(nativeWindow));
+ QVERIFY(foreignWindow->handle());
+
+ // Explicitly destroying a foreign window is a no-op, as
+ // the documentation claims that it "releases the native
+ // platform resources associated with this window.", which
+ // is not technically true for foreign windows.
+ auto *windowHandleBeforeDestroy = foreignWindow->handle();
+ foreignWindow->destroy();
+ QCOMPARE(foreignWindow->handle(), windowHandleBeforeDestroy);
+}
+
+void tst_ForeignWindow::destroyWhenParentIsDestroyed()
+{
+ QWindow parentWindow;
+
+ NativeWindow nativeWindow;
+ QVERIFY(nativeWindow);
+
+ std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(nativeWindow));
+ foreignWindow->setParent(&parentWindow);
+ QTRY_COMPARE(nativeWindow.parentWinId(), parentWindow.winId());
+
+ // Reparenting into a window will result in creating it
+ QVERIFY(parentWindow.handle());
+
+ // Destroying the parent window of the foreign window results
+ // in destroying the foreign window as well, as the foreign
+ // window no longer has a parent it can be embedded in.
+ QVERIFY(foreignWindow->handle());
+ parentWindow.destroy();
+ QVERIFY(!foreignWindow->handle());
+
+ // But the foreign window can be recreated again, and will
+ // continue to be a native child of the parent window.
+ foreignWindow->create();
+ QVERIFY(foreignWindow->handle());
+ QTRY_COMPARE(nativeWindow.parentWinId(), parentWindow.winId());
+}
+
#include <tst_foreignwindow.moc>
QTEST_MAIN(tst_ForeignWindow)