From af89d09f9208f81231a5ef2f866b26e54a1634ff Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Wed, 12 Aug 2020 14:42:41 +0100 Subject: [PATCH] Client: Expose XdgShell native resources Many new specifications now rely on passing xdg_surface/xdg_toplevel as arguments to other protocols. wl_shell is currently exposed through native resources but xdg-shell related classes were not. Fixes: QTBUG-81479 Change-Id: I2023f39ad6813ff58e8a86d739f307d791794b16 Reviewed-by: Paul Olav Tvete --- .../xdg-shell/qwaylandxdgshell.cpp | 12 ++++++++++++ .../xdg-shell/qwaylandxdgshell_p.h | 2 ++ .../xdg-shell/qwaylandxdgshellintegration.cpp | 10 ++++++++++ .../xdg-shell/qwaylandxdgshellintegration_p.h | 1 + tests/auto/wayland/xdgshell/tst_xdgshell.cpp | 19 +++++++++++++++++++ 5 files changed, 44 insertions(+) diff --git a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp index b6d23ac10a6..43360ede3a2 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp +++ b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp @@ -378,6 +378,18 @@ void QWaylandXdgSurface::setSizeHints() } } +void *QWaylandXdgSurface::nativeResource(const QByteArray &resource) +{ + QByteArray lowerCaseResource = resource.toLower(); + if (lowerCaseResource == "xdg_surface") + return object(); + else if (lowerCaseResource == "xdg_toplevel" && m_toplevel) + return m_toplevel->object(); + else if (lowerCaseResource == "xdg_popup" && m_popup) + return m_popup->object(); + return nullptr; +} + void QWaylandXdgSurface::requestWindowStates(Qt::WindowStates states) { if (m_toplevel) diff --git a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h index 0c98be35cdc..5aeec2eb910 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h +++ b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h @@ -97,6 +97,8 @@ public: void setSizeHints(); + void *nativeResource(const QByteArray &resource); + protected: void requestWindowStates(Qt::WindowStates states) override; void xdg_surface_configure(uint32_t serial) override; diff --git a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp index 8769d971667..b259a301016 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp +++ b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp @@ -83,6 +83,16 @@ void QWaylandXdgShellIntegration::handleKeyboardFocusChanged(QWaylandWindow *new } } +void *QWaylandXdgShellIntegration::nativeResourceForWindow(const QByteArray &resource, QWindow *window) +{ + if (auto waylandWindow = static_cast(window->handle())) { + if (auto xdgSurface = qobject_cast(waylandWindow->shellSurface())) { + return xdgSurface->nativeResource(resource); + } + } + return nullptr; +} + } QT_END_NAMESPACE diff --git a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration_p.h b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration_p.h index b6caa6c95c1..ceca0335db0 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration_p.h +++ b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration_p.h @@ -66,6 +66,7 @@ public: bool initialize(QWaylandDisplay *display) override; QWaylandShellSurface *createShellSurface(QWaylandWindow *window) override; void handleKeyboardFocusChanged(QWaylandWindow *newFocus, QWaylandWindow *oldFocus) override; + void *nativeResourceForWindow(const QByteArray &resource, QWindow *window) override; private: QScopedPointer m_xdgShell; diff --git a/tests/auto/wayland/xdgshell/tst_xdgshell.cpp b/tests/auto/wayland/xdgshell/tst_xdgshell.cpp index 3007fb32674..891bc0b28e3 100644 --- a/tests/auto/wayland/xdgshell/tst_xdgshell.cpp +++ b/tests/auto/wayland/xdgshell/tst_xdgshell.cpp @@ -51,6 +51,7 @@ private slots: void minMaxSize(); void windowGeometry(); void foreignSurface(); + void nativeResources(); }; void tst_xdgshell::showMinimized() @@ -563,5 +564,23 @@ void tst_xdgshell::foreignSurface() wl_surface_destroy(foreignSurface); } +void tst_xdgshell::nativeResources() +{ + QRasterWindow window; + window.resize(400, 320); + window.show(); + QCOMPOSITOR_TRY_VERIFY(xdgToplevel()); + + auto *ni = QGuiApplication::platformNativeInterface(); + auto *xdg_surface_proxy = static_cast<::wl_proxy *>(ni->nativeResourceForWindow("xdg_surface", &window)); + QCOMPARE(wl_proxy_get_class(xdg_surface_proxy), "xdg_surface"); + + auto *xdg_toplevel_proxy = static_cast<::wl_proxy *>(ni->nativeResourceForWindow("xdg_toplevel", &window)); + QCOMPARE(wl_proxy_get_class(xdg_toplevel_proxy), "xdg_toplevel"); + + auto *xdg_popup_proxy = static_cast<::wl_proxy *>(ni->nativeResourceForWindow("xdg_popup", &window)); + QCOMPARE(xdg_popup_proxy, nullptr); +} + QCOMPOSITOR_TEST_MAIN(tst_xdgshell) #include "tst_xdgshell.moc"