diff --git a/src/qwaylandlayershellintegration.cpp b/src/qwaylandlayershellintegration.cpp index 230f3be..df6bc16 100644 --- a/src/qwaylandlayershellintegration.cpp +++ b/src/qwaylandlayershellintegration.cpp @@ -22,26 +22,30 @@ QWaylandLayerShellIntegration::~QWaylandLayerShellIntegration() { } -bool QWaylandLayerShellIntegration::initialize(QtWaylandClient::QWaylandDisplay *display) +bool QWaylandLayerShellIntegration::initialize() { - QWaylandShellIntegration::initialize(display); - display->addRegistryListener(registryLayer, this); - return m_layerShell != nullptr; + if (m_layerShell) { + return true; + } + wl_registry *registry; + uint32_t id; + uint32_t version; + const bool found = findGlobal(QLatin1String("zwlr_layer_shell_v1"), ®istry, &id, &version); + if (!found) { + qWarning() << "Could not find the zwlr_layer_shell_v1 global. Compositor does not support the layer shell protocol?"; + return false; + } + + m_layerShell.reset(new QWaylandLayerShell(registry, id, std::min(version, 4u))); + return true; } QtWaylandClient::QWaylandShellSurface *QWaylandLayerShellIntegration::createShellSurface(QtWaylandClient::QWaylandWindow *window) { - return m_layerShell->createLayerSurface(window); -} - -void QWaylandLayerShellIntegration::registryLayer(void *data, struct wl_registry *registry, uint32_t id, const QString &interface, uint32_t version) -{ - QWaylandLayerShellIntegration *shell = static_cast(data); - - if (interface == zwlr_layer_shell_v1_interface.name) - shell->m_layerShell.reset(new QWaylandLayerShell(registry, id, std::min(version, 4u))); + if (m_layerShell) { + return m_layerShell->createLayerSurface(window); + } + return nullptr; } } - -//#include "qwaylandlayershellintegration.moc" diff --git a/src/qwaylandlayershellintegration_p.h b/src/qwaylandlayershellintegration_p.h index 2df4206..81d38a9 100644 --- a/src/qwaylandlayershellintegration_p.h +++ b/src/qwaylandlayershellintegration_p.h @@ -8,10 +8,9 @@ #ifndef _LAYERSHELLINTEGRATION_P_H #define _LAYERSHELLINTEGRATION_P_H -#include - #include "layershellqt_export.h" -#include + +#include namespace LayerShellQt { @@ -23,12 +22,10 @@ public: QWaylandLayerShellIntegration(); ~QWaylandLayerShellIntegration() override; - bool initialize(QtWaylandClient::QWaylandDisplay *display) override; + bool initialize() override; QtWaylandClient::QWaylandShellSurface *createShellSurface(QtWaylandClient::QWaylandWindow *window) override; private: - static void registryLayer(void *data, struct wl_registry *registry, uint32_t id, const QString &interface, uint32_t version); - QScopedPointer m_layerShell; };