From c31a609bbd60ac4ad0b9cb5dbe42179628b07bf1 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Thu, 2 Dec 2021 09:59:09 +0100 Subject: [PATCH] Remove QWaylandShellIntegration::findGlobal This is no longer necessary now that the recommended way of creating custom shells is to use QWaylandShellIntegrationTemplate. This also restores the old internal API in use by existing shells. Task-number: QTBUG-94330 Change-Id: I0fa0ba0d928baa2edf5d68e879558081026436c8 Reviewed-by: Vlad Zahorodnii Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: David Edmundson --- .../qwaylandfullscreenshellv1integration.cpp | 19 ++++++++++--------- .../qwaylandfullscreenshellv1integration.h | 3 +-- .../wl-shell/qwaylandwlshellintegration.cpp | 17 ++++++++--------- .../wl-shell/qwaylandwlshellintegration_p.h | 2 +- .../xdg-shell/qwaylandxdgshellintegration.cpp | 18 +++++++++--------- .../xdg-shell/qwaylandxdgshellintegration_p.h | 2 +- .../qwaylandshellintegration.cpp | 13 ------------- .../qwaylandshellintegration_p.h | 13 ++----------- 8 files changed, 32 insertions(+), 55 deletions(-) diff --git a/src/plugins/platforms/wayland/plugins/shellintegration/fullscreen-shell-v1/qwaylandfullscreenshellv1integration.cpp b/src/plugins/platforms/wayland/plugins/shellintegration/fullscreen-shell-v1/qwaylandfullscreenshellv1integration.cpp index 033cbf6ec02..418c7d3b373 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/fullscreen-shell-v1/qwaylandfullscreenshellv1integration.cpp +++ b/src/plugins/platforms/wayland/plugins/shellintegration/fullscreen-shell-v1/qwaylandfullscreenshellv1integration.cpp @@ -44,22 +44,23 @@ QT_BEGIN_NAMESPACE namespace QtWaylandClient { -bool QWaylandFullScreenShellV1Integration::initialize() +bool QWaylandFullScreenShellV1Integration::initialize(QWaylandDisplay *display) { - if (m_shell) - return true; - wl_registry *registry; - uint32_t id; - uint32_t version; - bool found = findGlobal(QLatin1String("zwp_fullscreen_shell_v1"), ®istry, &id, &version); - if (found) - m_shell.reset(new QtWayland::zwp_fullscreen_shell_v1(registry, id, version)); + for (const QWaylandDisplay::RegistryGlobal &global : display->globals()) { + if (global.interface == QLatin1String("zwp_fullscreen_shell_v1") && !m_shell) { + m_shell.reset(new QtWayland::zwp_fullscreen_shell_v1(display->wl_registry(), global.id, global.version)); + break; + } + } + if (!m_shell) { qCDebug(lcQpaWayland) << "Couldn't find global zwp_fullscreen_shell_v1 for fullscreen-shell"; return false; } + return true; } + QWaylandShellSurface *QWaylandFullScreenShellV1Integration::createShellSurface(QWaylandWindow *window) { return new QWaylandFullScreenShellV1Surface(m_shell.data(), window); diff --git a/src/plugins/platforms/wayland/plugins/shellintegration/fullscreen-shell-v1/qwaylandfullscreenshellv1integration.h b/src/plugins/platforms/wayland/plugins/shellintegration/fullscreen-shell-v1/qwaylandfullscreenshellv1integration.h index da99f6c4e0e..131f9e72097 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/fullscreen-shell-v1/qwaylandfullscreenshellv1integration.h +++ b/src/plugins/platforms/wayland/plugins/shellintegration/fullscreen-shell-v1/qwaylandfullscreenshellv1integration.h @@ -43,7 +43,6 @@ #include #include #include -#include #include "qwayland-fullscreen-shell-unstable-v1.h" @@ -54,7 +53,7 @@ namespace QtWaylandClient { class Q_WAYLAND_CLIENT_EXPORT QWaylandFullScreenShellV1Integration : public QWaylandShellIntegration { public: - bool initialize() override; + bool initialize(QWaylandDisplay *display) override; QWaylandShellSurface *createShellSurface(QWaylandWindow *window) override; private: diff --git a/src/plugins/platforms/wayland/plugins/shellintegration/wl-shell/qwaylandwlshellintegration.cpp b/src/plugins/platforms/wayland/plugins/shellintegration/wl-shell/qwaylandwlshellintegration.cpp index 7353cb1f968..262410f392e 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/wl-shell/qwaylandwlshellintegration.cpp +++ b/src/plugins/platforms/wayland/plugins/shellintegration/wl-shell/qwaylandwlshellintegration.cpp @@ -47,16 +47,15 @@ QT_BEGIN_NAMESPACE namespace QtWaylandClient { -bool QWaylandWlShellIntegration::initialize() +bool QWaylandWlShellIntegration::initialize(QWaylandDisplay *display) { - if (m_wlShell) - return true; - wl_registry *registry; - uint32_t id; - uint32_t version; - bool found = findGlobal(QLatin1String("wl_shell"), ®istry, &id, &version); - if (found) - m_wlShell = new QtWayland::wl_shell(registry, id, 1); + const auto globals = display->globals(); + for (QWaylandDisplay::RegistryGlobal global : globals) { + if (global.interface == QLatin1String("wl_shell")) { + m_wlShell = new QtWayland::wl_shell(display->wl_registry(), global.id, 1); + break; + } + } if (!m_wlShell) { qCDebug(lcQpaWayland) << "Couldn't find global wl_shell"; diff --git a/src/plugins/platforms/wayland/plugins/shellintegration/wl-shell/qwaylandwlshellintegration_p.h b/src/plugins/platforms/wayland/plugins/shellintegration/wl-shell/qwaylandwlshellintegration_p.h index 47815d54a18..3d76cc31073 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/wl-shell/qwaylandwlshellintegration_p.h +++ b/src/plugins/platforms/wayland/plugins/shellintegration/wl-shell/qwaylandwlshellintegration_p.h @@ -63,7 +63,7 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandWlShellIntegration : public QWaylandShellI { public: QWaylandWlShellIntegration() {} - bool initialize() override; + bool initialize(QWaylandDisplay *) override; QWaylandShellSurface *createShellSurface(QWaylandWindow *window) override; void *nativeResourceForWindow(const QByteArray &resource, QWindow *window) 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 8390d76f68e..0c9a2f2b299 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp +++ b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp @@ -47,20 +47,20 @@ QT_BEGIN_NAMESPACE namespace QtWaylandClient { -bool QWaylandXdgShellIntegration::initialize() +bool QWaylandXdgShellIntegration::initialize(QWaylandDisplay *display) { - if (m_xdgShell) - return true; - wl_registry *registry; - uint32_t id; - uint32_t version; - bool found = findGlobal(QLatin1String("xdg_wm_base"), ®istry, &id, &version); - if (found) - m_xdgShell.reset(new QWaylandXdgShell(m_display, id, version)); + for (QWaylandDisplay::RegistryGlobal global : display->globals()) { + if (global.interface == QLatin1String("xdg_wm_base")) { + m_xdgShell.reset(new QWaylandXdgShell(display, global.id, global.version)); + break; + } + } + if (!m_xdgShell) { qCDebug(lcQpaWayland) << "Couldn't find global xdg_wm_base for xdg-shell stable"; return false; } + return true; } 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 cd54dd489d3..fced9eb07c2 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 @@ -63,7 +63,7 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgShellIntegration : public QWaylandShell { public: QWaylandXdgShellIntegration() {} - bool initialize() override; + bool initialize(QWaylandDisplay *display) override; QWaylandShellSurface *createShellSurface(QWaylandWindow *window) override; void *nativeResourceForWindow(const QByteArray &resource, QWindow *window) override; diff --git a/src/plugins/platforms/wayland/shellintegration/qwaylandshellintegration.cpp b/src/plugins/platforms/wayland/shellintegration/qwaylandshellintegration.cpp index 7bc37792f8c..5bb617034fa 100644 --- a/src/plugins/platforms/wayland/shellintegration/qwaylandshellintegration.cpp +++ b/src/plugins/platforms/wayland/shellintegration/qwaylandshellintegration.cpp @@ -39,19 +39,6 @@ wl_surface *QWaylandShellIntegration::wlSurfaceForWindow(QWaylandWindow *window) return window->wlSurface(); } -bool QWaylandShellIntegration::findGlobal(const QString &interface, wl_registry **registry, uint32_t *id, uint32_t *version) -{ - for (QWaylandDisplay::RegistryGlobal &global : m_display->globals()) { - if (global.interface == interface) { - *registry = m_display->wl_registry(); - *id = global.id; - *version = global.version; - return true; - } - } - return false; -} - } QT_END_NAMESPACE diff --git a/src/plugins/platforms/wayland/shellintegration/qwaylandshellintegration_p.h b/src/plugins/platforms/wayland/shellintegration/qwaylandshellintegration_p.h index 4de19e7860c..8acbf967044 100644 --- a/src/plugins/platforms/wayland/shellintegration/qwaylandshellintegration_p.h +++ b/src/plugins/platforms/wayland/shellintegration/qwaylandshellintegration_p.h @@ -77,13 +77,7 @@ public: QWaylandShellIntegration() {} virtual ~QWaylandShellIntegration() {} - bool initialize(QWaylandDisplay *display) { - m_display = display; - return initialize(); - } - virtual bool initialize() { - return false; - } + virtual bool initialize(QWaylandDisplay *display) = 0; virtual QWaylandShellSurface *createShellSurface(QWaylandWindow *window) = 0; virtual void *nativeResourceForWindow(const QByteArray &resource, QWindow *window) { Q_UNUSED(resource); @@ -92,10 +86,7 @@ public: } static wl_surface *wlSurfaceForWindow(QWaylandWindow *window); - bool findGlobal(const QString &interface, wl_registry **registry, uint32_t *id, uint32_t *version); -protected: - QWaylandDisplay *m_display = nullptr; }; template @@ -107,7 +98,7 @@ public: { } - bool initialize() override + bool initialize(QWaylandDisplay *) override { QWaylandClientExtension::initialize(); return isActive();