From 4e2e3a6b4fe0ff5e1930707808f02e3be9343312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 15 Aug 2023 21:17:53 +0200 Subject: [PATCH] xcb: Reflect geometry of foreign window on creation Pick-to: 6.6 Change-Id: I305b256696a32454f64c12c5a8901b65506fc520 Reviewed-by: Liang Qi --- src/plugins/platforms/xcb/qxcbwindow.cpp | 12 ++++++++++++ src/plugins/platforms/xcb/qxcbwindow.h | 3 +-- tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp | 2 -- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 584f1e5406..7e3c32d387 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -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 diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h index 54a96a7a0a..6a13c4b676 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.h +++ b/src/plugins/platforms/xcb/qxcbwindow.h @@ -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; } diff --git a/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp index ce4d9f28c8..c42bb9d974 100644 --- a/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp @@ -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); }