xcb: Reflect geometry of foreign window on creation

Pick-to: 6.6
Change-Id: I305b256696a32454f64c12c5a8901b65506fc520
Reviewed-by: Liang Qi <liang.qi@qt.io>
This commit is contained in:
Tor Arne Vestbø 2023-08-15 21:17:53 +02:00
parent f2a2c669f6
commit 4e2e3a6b4f
3 changed files with 13 additions and 4 deletions

View File

@ -472,6 +472,18 @@ QXcbWindow::~QXcbWindow()
destroy();
}
QXcbForeignWindow::QXcbForeignWindow(QWindow *window, WId nativeHandle)
: QXcbWindow(window)
{
m_window = nativeHandle;
// Reflect the foreign window's geometry as our own
if (auto geometry = Q_XCB_REPLY(xcb_get_geometry, xcb_connection(), m_window)) {
QRect nativeGeometry(geometry->x, geometry->y, geometry->width, geometry->height);
QPlatformWindow::setGeometry(nativeGeometry);
}
}
QXcbForeignWindow::~QXcbForeignWindow()
{
// Clear window so that destroy() does not affect it

View File

@ -258,8 +258,7 @@ protected:
class QXcbForeignWindow : public QXcbWindow
{
public:
QXcbForeignWindow(QWindow *window, WId nativeHandle)
: QXcbWindow(window) { m_window = nativeHandle; }
QXcbForeignWindow(QWindow *window, WId nativeHandle);
~QXcbForeignWindow();
bool isForeignWindow() const override { return true; }

View File

@ -67,8 +67,6 @@ void tst_ForeignWindow::initialState()
// For extra bonus points, the foreign window should actually
// reflect the state of the native window.
if (!QGuiApplication::platformName().compare(QLatin1String("xcb"), Qt::CaseInsensitive))
QEXPECT_FAIL("", "QXcbWindow does not pick up foreign window geometry", Continue);
QCOMPARE(foreignWindow->geometry(), initialGeometry);
}