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 <qt_ci_bot@qt-project.org>
Reviewed-by: David Edmundson <davidedmundson@kde.org>
This commit is contained in:
David Redondo 2023-02-22 14:33:22 +01:00 committed by David Edmundson
parent 0badceeb6d
commit cb71234bc9
4 changed files with 47 additions and 39 deletions

View File

@ -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,

View File

@ -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<QWaylandXdgDecorationManagerV1> m_xdgDecorationManager;
QScopedPointer<QWaylandXdgActivationV1> m_xdgActivation;
QScopedPointer<QWaylandXdgExporterV2> m_xdgExporter;

View File

@ -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 {
QWaylandXdgShellIntegration::QWaylandXdgShellIntegration() : QWaylandShellIntegrationTemplate(4)
{
connect(this, &QWaylandShellIntegrationTemplate::activeChanged, this, [this] {
if (isActive()) {
mXdgShell.reset(new QWaylandXdgShell(mDisplay, this));
} else {
mXdgShell.reset(nullptr);
destroy();
}
});
}
QWaylandXdgShellIntegration::~QWaylandXdgShellIntegration()
{
if (isActive())
destroy();
}
bool QWaylandXdgShellIntegration::initialize(QWaylandDisplay *display)
{
for (QWaylandDisplay::RegistryGlobal global : display->globals()) {
if (global.interface == QLatin1String("xdg_wm_base")) {
m_xdgShell.reset(new QWaylandXdgShell(display, global.id, global.version));
break;
}
mDisplay = display;
return QWaylandShellIntegrationTemplate::initialize(display);
}
if (!m_xdgShell) {
qCDebug(lcQpaWayland) << "Couldn't find global xdg_wm_base for xdg-shell stable";
return false;
}
return true;
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)

View File

@ -15,7 +15,7 @@
// We mean it.
//
#include "qwaylandxdgshell_p.h"
#include "qwayland-xdg-shell.h"
#include <QtWaylandClient/private/qwaylandshellintegration_p.h>
@ -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<QWaylandXdgShellIntegration>,
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<QWaylandXdgShell> m_xdgShell;
QWaylandDisplay *mDisplay;
QScopedPointer<QWaylandXdgShell> mXdgShell;
};
}