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 <vlad.zahorodnii@kde.org>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Reviewed-by: David Edmundson <davidedmundson@kde.org>
This commit is contained in:
Paul Olav Tvete 2021-12-02 09:59:09 +01:00
parent 18df960499
commit c31a609bbd
8 changed files with 32 additions and 55 deletions

View File

@ -44,22 +44,23 @@ QT_BEGIN_NAMESPACE
namespace QtWaylandClient { namespace QtWaylandClient {
bool QWaylandFullScreenShellV1Integration::initialize() bool QWaylandFullScreenShellV1Integration::initialize(QWaylandDisplay *display)
{ {
if (m_shell) for (const QWaylandDisplay::RegistryGlobal &global : display->globals()) {
return true; if (global.interface == QLatin1String("zwp_fullscreen_shell_v1") && !m_shell) {
wl_registry *registry; m_shell.reset(new QtWayland::zwp_fullscreen_shell_v1(display->wl_registry(), global.id, global.version));
uint32_t id; break;
uint32_t version; }
bool found = findGlobal(QLatin1String("zwp_fullscreen_shell_v1"), &registry, &id, &version); }
if (found)
m_shell.reset(new QtWayland::zwp_fullscreen_shell_v1(registry, id, version));
if (!m_shell) { if (!m_shell) {
qCDebug(lcQpaWayland) << "Couldn't find global zwp_fullscreen_shell_v1 for fullscreen-shell"; qCDebug(lcQpaWayland) << "Couldn't find global zwp_fullscreen_shell_v1 for fullscreen-shell";
return false; return false;
} }
return true; return true;
} }
QWaylandShellSurface *QWaylandFullScreenShellV1Integration::createShellSurface(QWaylandWindow *window) QWaylandShellSurface *QWaylandFullScreenShellV1Integration::createShellSurface(QWaylandWindow *window)
{ {
return new QWaylandFullScreenShellV1Surface(m_shell.data(), window); return new QWaylandFullScreenShellV1Surface(m_shell.data(), window);

View File

@ -43,7 +43,6 @@
#include <wayland-client.h> #include <wayland-client.h>
#include <QtWaylandClient/private/qwayland-wayland.h> #include <QtWaylandClient/private/qwayland-wayland.h>
#include <QtWaylandClient/private/qwaylandshellintegration_p.h> #include <QtWaylandClient/private/qwaylandshellintegration_p.h>
#include <QScopedPointer>
#include "qwayland-fullscreen-shell-unstable-v1.h" #include "qwayland-fullscreen-shell-unstable-v1.h"
@ -54,7 +53,7 @@ namespace QtWaylandClient {
class Q_WAYLAND_CLIENT_EXPORT QWaylandFullScreenShellV1Integration : public QWaylandShellIntegration class Q_WAYLAND_CLIENT_EXPORT QWaylandFullScreenShellV1Integration : public QWaylandShellIntegration
{ {
public: public:
bool initialize() override; bool initialize(QWaylandDisplay *display) override;
QWaylandShellSurface *createShellSurface(QWaylandWindow *window) override; QWaylandShellSurface *createShellSurface(QWaylandWindow *window) override;
private: private:

View File

@ -47,16 +47,15 @@ QT_BEGIN_NAMESPACE
namespace QtWaylandClient { namespace QtWaylandClient {
bool QWaylandWlShellIntegration::initialize() bool QWaylandWlShellIntegration::initialize(QWaylandDisplay *display)
{ {
if (m_wlShell) const auto globals = display->globals();
return true; for (QWaylandDisplay::RegistryGlobal global : globals) {
wl_registry *registry; if (global.interface == QLatin1String("wl_shell")) {
uint32_t id; m_wlShell = new QtWayland::wl_shell(display->wl_registry(), global.id, 1);
uint32_t version; break;
bool found = findGlobal(QLatin1String("wl_shell"), &registry, &id, &version); }
if (found) }
m_wlShell = new QtWayland::wl_shell(registry, id, 1);
if (!m_wlShell) { if (!m_wlShell) {
qCDebug(lcQpaWayland) << "Couldn't find global wl_shell"; qCDebug(lcQpaWayland) << "Couldn't find global wl_shell";

View File

@ -63,7 +63,7 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandWlShellIntegration : public QWaylandShellI
{ {
public: public:
QWaylandWlShellIntegration() {} QWaylandWlShellIntegration() {}
bool initialize() override; bool initialize(QWaylandDisplay *) override;
QWaylandShellSurface *createShellSurface(QWaylandWindow *window) override; QWaylandShellSurface *createShellSurface(QWaylandWindow *window) override;
void *nativeResourceForWindow(const QByteArray &resource, QWindow *window) override; void *nativeResourceForWindow(const QByteArray &resource, QWindow *window) override;

View File

@ -47,20 +47,20 @@ QT_BEGIN_NAMESPACE
namespace QtWaylandClient { namespace QtWaylandClient {
bool QWaylandXdgShellIntegration::initialize() bool QWaylandXdgShellIntegration::initialize(QWaylandDisplay *display)
{ {
if (m_xdgShell) for (QWaylandDisplay::RegistryGlobal global : display->globals()) {
return true; if (global.interface == QLatin1String("xdg_wm_base")) {
wl_registry *registry; m_xdgShell.reset(new QWaylandXdgShell(display, global.id, global.version));
uint32_t id; break;
uint32_t version; }
bool found = findGlobal(QLatin1String("xdg_wm_base"), &registry, &id, &version); }
if (found)
m_xdgShell.reset(new QWaylandXdgShell(m_display, id, version));
if (!m_xdgShell) { if (!m_xdgShell) {
qCDebug(lcQpaWayland) << "Couldn't find global xdg_wm_base for xdg-shell stable"; qCDebug(lcQpaWayland) << "Couldn't find global xdg_wm_base for xdg-shell stable";
return false; return false;
} }
return true; return true;
} }

View File

@ -63,7 +63,7 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgShellIntegration : public QWaylandShell
{ {
public: public:
QWaylandXdgShellIntegration() {} QWaylandXdgShellIntegration() {}
bool initialize() override; bool initialize(QWaylandDisplay *display) override;
QWaylandShellSurface *createShellSurface(QWaylandWindow *window) override; QWaylandShellSurface *createShellSurface(QWaylandWindow *window) override;
void *nativeResourceForWindow(const QByteArray &resource, QWindow *window) override; void *nativeResourceForWindow(const QByteArray &resource, QWindow *window) override;

View File

@ -39,19 +39,6 @@ wl_surface *QWaylandShellIntegration::wlSurfaceForWindow(QWaylandWindow *window)
return window->wlSurface(); 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 QT_END_NAMESPACE

View File

@ -77,13 +77,7 @@ public:
QWaylandShellIntegration() {} QWaylandShellIntegration() {}
virtual ~QWaylandShellIntegration() {} virtual ~QWaylandShellIntegration() {}
bool initialize(QWaylandDisplay *display) { virtual bool initialize(QWaylandDisplay *display) = 0;
m_display = display;
return initialize();
}
virtual bool initialize() {
return false;
}
virtual QWaylandShellSurface *createShellSurface(QWaylandWindow *window) = 0; virtual QWaylandShellSurface *createShellSurface(QWaylandWindow *window) = 0;
virtual void *nativeResourceForWindow(const QByteArray &resource, QWindow *window) { virtual void *nativeResourceForWindow(const QByteArray &resource, QWindow *window) {
Q_UNUSED(resource); Q_UNUSED(resource);
@ -92,10 +86,7 @@ public:
} }
static wl_surface *wlSurfaceForWindow(QWaylandWindow *window); 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 <typename T> template <typename T>
@ -107,7 +98,7 @@ public:
{ {
} }
bool initialize() override bool initialize(QWaylandDisplay *) override
{ {
QWaylandClientExtension::initialize(); QWaylandClientExtension::initialize();
return isActive(); return isActive();