From ee92c05f34e96431e22b5735d3b864d08e2e4ad3 Mon Sep 17 00:00:00 2001 From: David Redondo Date: Wed, 22 Feb 2023 14:33:22 +0100 Subject: Port xdg shell plugin towards QWaylandShellIntegrationTemplate Ports manual initialization to the automatic handling of the template. For now the integration QWaylandXdgShellIntegration and QWaylandXdgShell are still separate but could be merged in a future step. Change-Id: I73bb9674e62f24f403349784e1b1e52a39aa8e9f Reviewed-by: Qt CI Bot Reviewed-by: David Edmundson --- .../xdg-shell/qwaylandxdgshell.cpp | 18 ++--------- .../xdg-shell/qwaylandxdgshell_p.h | 10 +++--- .../xdg-shell/qwaylandxdgshellintegration.cpp | 37 +++++++++++++++------- .../xdg-shell/qwaylandxdgshellintegration_p.h | 19 ++++++++--- 4 files changed, 46 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp index 6303fbc9..ee53341a 100644 --- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp +++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp @@ -444,7 +444,7 @@ void QWaylandXdgSurface::setPopup(QWaylandWindow *parent) { Q_ASSERT(!m_toplevel && !m_popup); - auto positioner = new QtWayland::xdg_positioner(m_shell->create_positioner()); + auto positioner = new QtWayland::xdg_positioner(m_shell->m_xdgWmBase->create_positioner()); // set_popup expects a position relative to the parent QRect windowGeometry = m_window->windowContentGeometry(); QMargins windowMargins = m_window->windowContentMargins() - m_window->clientSideMargins(); @@ -615,9 +615,8 @@ QString QWaylandXdgSurface::externWindowHandle() return m_toplevel->m_exported->handle(); } -QWaylandXdgShell::QWaylandXdgShell(QWaylandDisplay *display, uint32_t id, uint32_t availableVersion) - : QtWayland::xdg_wm_base(display->wl_registry(), id, qMin(availableVersion, 4u)) - , m_display(display) +QWaylandXdgShell::QWaylandXdgShell(QWaylandDisplay *display, QtWayland::xdg_wm_base *xdgWmBase) + : m_display(display), m_xdgWmBase(xdgWmBase) { display->addRegistryListener(&QWaylandXdgShell::handleRegistryGlobal, this); } @@ -625,17 +624,6 @@ QWaylandXdgShell::QWaylandXdgShell(QWaylandDisplay *display, uint32_t id, uint32 QWaylandXdgShell::~QWaylandXdgShell() { m_display->removeListener(&QWaylandXdgShell::handleRegistryGlobal, this); - destroy(); -} - -QWaylandXdgSurface *QWaylandXdgShell::getXdgSurface(QWaylandWindow *window) -{ - return new QWaylandXdgSurface(this, get_xdg_surface(window->wlSurface()), window); -} - -void QWaylandXdgShell::xdg_wm_base_ping(uint32_t serial) -{ - pong(serial); } void QWaylandXdgShell::handleRegistryGlobal(void *data, wl_registry *registry, uint id, diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h index 58860269..bf51888e 100644 --- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h +++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h @@ -143,11 +143,11 @@ private: friend class QWaylandXdgShell; }; -class Q_WAYLANDCLIENT_EXPORT QWaylandXdgShell : public QtWayland::xdg_wm_base +class Q_WAYLANDCLIENT_EXPORT QWaylandXdgShell { public: - QWaylandXdgShell(QWaylandDisplay *display, uint32_t id, uint32_t availableVersion); - ~QWaylandXdgShell() override; + QWaylandXdgShell(QWaylandDisplay *display, QtWayland::xdg_wm_base *xdg_wm_base); + ~QWaylandXdgShell(); QWaylandDisplay *display() const { return m_display; } @@ -156,14 +156,12 @@ public: QWaylandXdgExporterV2 *exporter() const { return m_xdgExporter.data(); } QWaylandXdgSurface *getXdgSurface(QWaylandWindow *window); -protected: - void xdg_wm_base_ping(uint32_t serial) override; - private: static void handleRegistryGlobal(void *data, ::wl_registry *registry, uint id, const QString &interface, uint version); QWaylandDisplay *m_display = nullptr; + QtWayland::xdg_wm_base *m_xdgWmBase = nullptr; QScopedPointer m_xdgDecorationManager; QScopedPointer m_xdgActivation; QScopedPointer m_xdgExporter; diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp index 8d648b62..c7b757dd 100644 --- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp +++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp @@ -1,6 +1,7 @@ // Copyright (C) 2017 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +#include "qwaylandxdgshell_p.h" #include "qwaylandxdgshellintegration_p.h" #include "qwaylandxdgdecorationv1_p.h" @@ -11,26 +12,38 @@ QT_BEGIN_NAMESPACE namespace QtWaylandClient { -bool QWaylandXdgShellIntegration::initialize(QWaylandDisplay *display) +QWaylandXdgShellIntegration::QWaylandXdgShellIntegration() : QWaylandShellIntegrationTemplate(4) { - for (QWaylandDisplay::RegistryGlobal global : display->globals()) { - if (global.interface == QLatin1String("xdg_wm_base")) { - m_xdgShell.reset(new QWaylandXdgShell(display, global.id, global.version)); - break; + connect(this, &QWaylandShellIntegrationTemplate::activeChanged, this, [this] { + if (isActive()) { + mXdgShell.reset(new QWaylandXdgShell(mDisplay, this)); + } else { + mXdgShell.reset(nullptr); + destroy(); } - } + }); +} - if (!m_xdgShell) { - qCDebug(lcQpaWayland) << "Couldn't find global xdg_wm_base for xdg-shell stable"; - return false; - } +QWaylandXdgShellIntegration::~QWaylandXdgShellIntegration() +{ + if (isActive()) + destroy(); +} - return true; +bool QWaylandXdgShellIntegration::initialize(QWaylandDisplay *display) +{ + mDisplay = display; + return QWaylandShellIntegrationTemplate::initialize(display); +} + +void QWaylandXdgShellIntegration::xdg_wm_base_ping(uint32_t serial) +{ + pong(serial); } QWaylandShellSurface *QWaylandXdgShellIntegration::createShellSurface(QWaylandWindow *window) { - return m_xdgShell->getXdgSurface(window); + return new QWaylandXdgSurface(mXdgShell.get(), get_xdg_surface(window->wlSurface()), window); } void *QWaylandXdgShellIntegration::nativeResourceForWindow(const QByteArray &resource, QWindow *window) diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration_p.h b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration_p.h index 2caa3a6e..b7627d80 100644 --- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration_p.h +++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration_p.h @@ -15,7 +15,7 @@ // We mean it. // -#include "qwaylandxdgshell_p.h" +#include "qwayland-xdg-shell.h" #include @@ -23,16 +23,25 @@ QT_BEGIN_NAMESPACE namespace QtWaylandClient { -class Q_WAYLANDCLIENT_EXPORT QWaylandXdgShellIntegration : public QWaylandShellIntegration +class QWaylandXdgShell; + +class Q_WAYLANDCLIENT_EXPORT QWaylandXdgShellIntegration + : public QWaylandShellIntegrationTemplate, + public QtWayland::xdg_wm_base { public: - QWaylandXdgShellIntegration() {} - bool initialize(QWaylandDisplay *display) override; + QWaylandXdgShellIntegration(); + ~QWaylandXdgShellIntegration() override; QWaylandShellSurface *createShellSurface(QWaylandWindow *window) override; void *nativeResourceForWindow(const QByteArray &resource, QWindow *window) override; + bool initialize(QWaylandDisplay *display) override; + +protected: + void xdg_wm_base_ping(uint32_t serial) override; private: - QScopedPointer m_xdgShell; + QWaylandDisplay *mDisplay; + QScopedPointer mXdgShell; }; } -- cgit v1.2.1