From 0052d0ed13eebb7e884d4796726b6f33df28dde9 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 16 Nov 2022 15:13:17 +0200 Subject: [PATCH] Client: Provide support for custom shells Currently, an application can use only one shell surface protocol at a time. However, there are applications that need to use more than one shell surface protocol, e.g. xdg-shell + layer-shell. layer-shell can be used for the desktop background window, and xdg-shell for popups, etc. This change introduces an API in QWaylandWindow that allows specifying the shell integration per window. Custom shell code needs to call QWaylandWindow::setShellIntegration() while the window is unmapped. By default, QWaylandWindow will use QWaylandDisplay's shell integration plugin. This change should be source compatible with existing shell integration plugins deployed in the wild. If the custom shell wants to track additional state for the window, it should do it using its own means. Perhaps we could improve this in the future releases of Qt. [ChangeLog][QtWaylandClient] It is possible to run Qt applications using more than one shell surface protocol, e.g. xdg-shell + layer-shell. Change-Id: Id0458b32af623f114c06d51d0d21ad06efd69328 Reviewed-by: David Edmundson Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../wayland/qwaylandnativeinterface.cpp | 5 +++-- .../platforms/wayland/qwaylandwindow.cpp | 17 ++++++++++++++--- .../platforms/wayland/qwaylandwindow_p.h | 5 +++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylandnativeinterface.cpp b/src/plugins/platforms/wayland/qwaylandnativeinterface.cpp index ea3da8b4881..2c1cdb98b09 100644 --- a/src/plugins/platforms/wayland/qwaylandnativeinterface.cpp +++ b/src/plugins/platforms/wayland/qwaylandnativeinterface.cpp @@ -148,8 +148,9 @@ void *QWaylandNativeInterface::nativeResourceForWindow(const QByteArray &resourc } #endif - if (auto shellIntegration = m_integration->shellIntegration()) - return shellIntegration->nativeResourceForWindow(resourceString, window); + QWaylandWindow *platformWindow = static_cast(window->handle()); + if (platformWindow && platformWindow->shellIntegration()) + return platformWindow->shellIntegration()->nativeResourceForWindow(resourceString, window); return nullptr; } diff --git a/src/plugins/platforms/wayland/qwaylandwindow.cpp b/src/plugins/platforms/wayland/qwaylandwindow.cpp index 4e254dee973..f5327c05c6c 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.cpp +++ b/src/plugins/platforms/wayland/qwaylandwindow.cpp @@ -45,6 +45,7 @@ QWaylandWindow::QWaylandWindow(QWindow *window, QWaylandDisplay *display) : QPlatformWindow(window) , mDisplay(display) , mSurfaceLock(QReadWriteLock::Recursive) + , mShellIntegration(display->shellIntegration()) , mResizeAfterSwap(qEnvironmentVariableIsSet("QT_WAYLAND_RESIZE_AFTER_SWAP")) { { @@ -130,9 +131,9 @@ void QWaylandWindow::initWindow() } } else if (shouldCreateShellSurface()) { Q_ASSERT(!mShellSurface); - Q_ASSERT(mDisplay->shellIntegration()); + Q_ASSERT(mShellIntegration); - mShellSurface = mDisplay->shellIntegration()->createShellSurface(this); + mShellSurface = mShellIntegration->createShellSurface(this); if (mShellSurface) { // Set initial surface title setWindowTitle(window()->title()); @@ -216,9 +217,19 @@ void QWaylandWindow::initializeWlSurface() emit wlSurfaceCreated(); } +void QWaylandWindow::setShellIntegration(QWaylandShellIntegration *shellIntegration) +{ + Q_ASSERT(shellIntegration); + if (mShellSurface) { + qCWarning(lcQpaWayland) << "Cannot set shell integration while there's already a shell surface created"; + return; + } + mShellIntegration = shellIntegration; +} + bool QWaylandWindow::shouldCreateShellSurface() const { - if (!mDisplay->shellIntegration()) + if (!shellIntegration()) return false; if (shouldCreateSubSurface()) diff --git a/src/plugins/platforms/wayland/qwaylandwindow_p.h b/src/plugins/platforms/wayland/qwaylandwindow_p.h index 2eb6b64cec2..185de69a96a 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow_p.h +++ b/src/plugins/platforms/wayland/qwaylandwindow_p.h @@ -50,6 +50,7 @@ class QWaylandSubSurface; class QWaylandAbstractDecoration; class QWaylandInputDevice; class QWaylandScreen; +class QWaylandShellIntegration; class QWaylandShmBackingStore; class QWaylandPointerEvent; class QWaylandPointerGestureSwipeEvent; @@ -202,6 +203,9 @@ public: void setBackingStore(QWaylandShmBackingStore *backingStore) { mBackingStore = backingStore; } QWaylandShmBackingStore *backingStore() const { return mBackingStore; } + void setShellIntegration(QWaylandShellIntegration *shellIntegration); + QWaylandShellIntegration *shellIntegration() const { return mShellIntegration; } + bool setKeyboardGrabEnabled(bool) override { return false; } void propagateSizeHints() override; void addAttachOffset(const QPoint point); @@ -245,6 +249,7 @@ protected: QScopedPointer mFractionalScale; QScopedPointer mViewport; + QWaylandShellIntegration *mShellIntegration = nullptr; QWaylandShellSurface *mShellSurface = nullptr; QWaylandSubSurface *mSubSurfaceWindow = nullptr; QList mChildren;