summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Redondo <qt@david-redondo.de>2022-01-24 11:46:07 +0100
committerDavid Redondo <qt@david-redondo.de>2022-03-09 15:30:01 +0100
commitcdf85f33df601e6a2d1972977c92c9bc33a0e967 (patch)
treeb5f3408af4cad3e37f7fb1a5cf50afda0a207d8f /src
parent97b5ebb4d0ccc47805e685090c48fd514292252f (diff)
downloadqtwayland-cdf85f33df601e6a2d1972977c92c9bc33a0e967.tar.gz
Add globalRemove to QWaylandClientExtension
Adds support for handling of removal of the relevant global to QtWaylandClientExtension. The user is responsible for destroying the object once it becomes inactive to match the behavior on destruction. Two signals for globals and their removal are added to QWaylandDisplay to make it a bit nicer to use in a more "Qt-way". The addRregistryListener function is kept for now until other places are ported. Change-Id: I4ccbaa32e18a5ae15871aa23639e2b4a372cc34e Reviewed-by: David Edmundson <davidedmundson@kde.org>
Diffstat (limited to 'src')
-rw-r--r--src/client/global/qwaylandclientextension.cpp53
-rw-r--r--src/client/global/qwaylandclientextension_p.h9
-rw-r--r--src/client/qwaylanddisplay.cpp3
-rw-r--r--src/client/qwaylanddisplay_p.h4
4 files changed, 48 insertions, 21 deletions
diff --git a/src/client/global/qwaylandclientextension.cpp b/src/client/global/qwaylandclientextension.cpp
index f0bc950c..200dad07 100644
--- a/src/client/global/qwaylandclientextension.cpp
+++ b/src/client/global/qwaylandclientextension.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2017 Erik Larsson.
+** Copyright (C) 2021 David Redondo <qt@david-redondo.de>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWaylandCompositor module of the Qt Toolkit.
@@ -48,6 +49,8 @@
QT_BEGIN_NAMESPACE
+using RegistryGlobal = QtWaylandClient::QWaylandDisplay::RegistryGlobal;
+
QWaylandClientExtensionPrivate::QWaylandClientExtensionPrivate()
{
// Keep the possibility to use a custom waylandIntegration as a plugin,
@@ -60,23 +63,41 @@ QWaylandClientExtensionPrivate::QWaylandClientExtensionPrivate()
qWarning() << "This application requires a Wayland platform plugin";
}
-void QWaylandClientExtensionPrivate::handleRegistryGlobal(void *data, ::wl_registry *registry, uint32_t id,
- const QString &interface, uint32_t version)
+void QWaylandClientExtensionPrivate::globalAdded(const RegistryGlobal &global)
+{
+ Q_Q(QWaylandClientExtension);
+ if (!active && global.interface == QLatin1String(q->extensionInterface()->name)) {
+ q->bind(global.registry, global.id, global.version);
+ active = true;
+ emit q->activeChanged();
+ }
+}
+
+void QWaylandClientExtensionPrivate::globalRemoved(const RegistryGlobal &global)
{
- QWaylandClientExtension *extension = static_cast<QWaylandClientExtension *>(data);
- if (interface == QLatin1String(extension->extensionInterface()->name) && !extension->d_func()->active) {
- extension->bind(registry, id, version);
- extension->d_func()->active = true;
- emit extension->activeChanged();
+ Q_Q(QWaylandClientExtension);
+ if (active && global.interface == QLatin1String(q->extensionInterface()->name)) {
+ active = false;
+ emit q->activeChanged();
}
}
void QWaylandClientExtension::initialize()
{
Q_D(QWaylandClientExtension);
- if (!d->registered) {
- d->waylandIntegration->display()->addRegistryListener(&QWaylandClientExtensionPrivate::handleRegistryGlobal, this);
- d->registered = true;
+ if (d->active) {
+ return;
+ }
+ const QtWaylandClient::QWaylandDisplay *display = d->waylandIntegration->display();
+ const auto globals = display->globals();
+ auto global =
+ std::find_if(globals.cbegin(), globals.cend(), [this](const RegistryGlobal &global) {
+ return global.interface == QLatin1String(extensionInterface()->name);
+ });
+ if (global != globals.cend()) {
+ bind(global->registry, global->id, global->version);
+ d->active = true;
+ emit activeChanged();
}
}
@@ -85,17 +106,17 @@ QWaylandClientExtension::QWaylandClientExtension(const int ver)
{
Q_D(QWaylandClientExtension);
d->version = ver;
-
- // The registry listener uses virtual functions and we don't want it to be called from
- // the constructor.
+ auto display = d->waylandIntegration->display();
+ QObjectPrivate::connect(display, &QtWaylandClient::QWaylandDisplay::globalAdded, d,
+ &QWaylandClientExtensionPrivate::globalAdded);
+ QObjectPrivate::connect(display, &QtWaylandClient::QWaylandDisplay::globalRemoved, d,
+ &QWaylandClientExtensionPrivate::globalRemoved);
+ // This function uses virtual functions and we don't want it to be called from the constructor.
QMetaObject::invokeMethod(this, "initialize", Qt::QueuedConnection);
}
QWaylandClientExtension::~QWaylandClientExtension()
{
- Q_D(QWaylandClientExtension);
- if (d->registered && !QCoreApplication::closingDown())
- d->waylandIntegration->display()->removeListener(&QWaylandClientExtensionPrivate::handleRegistryGlobal, this);
}
QtWaylandClient::QWaylandIntegration *QWaylandClientExtension::integration() const
diff --git a/src/client/global/qwaylandclientextension_p.h b/src/client/global/qwaylandclientextension_p.h
index 9091efbe..621c14b7 100644
--- a/src/client/global/qwaylandclientextension_p.h
+++ b/src/client/global/qwaylandclientextension_p.h
@@ -53,22 +53,23 @@
#include <QtCore/private/qobject_p.h>
#include <QtWaylandClient/QWaylandClientExtension>
+#include <QtWaylandClient/private/qwaylanddisplay_p.h>
#include <QtWaylandClient/private/qwaylandintegration_p.h>
QT_BEGIN_NAMESPACE
class Q_WAYLAND_CLIENT_EXPORT QWaylandClientExtensionPrivate : public QObjectPrivate
{
- Q_DECLARE_PUBLIC(QWaylandClientExtension)
public:
+ Q_DECLARE_PUBLIC(QWaylandClientExtension)
QWaylandClientExtensionPrivate();
- static void handleRegistryGlobal(void *data, ::wl_registry *registry, uint32_t id,
- const QString &interface, uint32_t version);
+
+ void globalAdded(const QtWaylandClient::QWaylandDisplay::RegistryGlobal &global);
+ void globalRemoved(const QtWaylandClient::QWaylandDisplay::RegistryGlobal &global);
QtWaylandClient::QWaylandIntegration *waylandIntegration = nullptr;
int version = -1;
bool active = false;
- bool registered = false;
};
class Q_WAYLAND_CLIENT_EXPORT QWaylandClientExtensionTemplatePrivate : public QWaylandClientExtensionPrivate
diff --git a/src/client/qwaylanddisplay.cpp b/src/client/qwaylanddisplay.cpp
index f8cb75e9..79c68a93 100644
--- a/src/client/qwaylanddisplay.cpp
+++ b/src/client/qwaylanddisplay.cpp
@@ -634,6 +634,7 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin
}
mGlobals.append(RegistryGlobal(id, interface, version, registry));
+ emit globalAdded(mGlobals.back());
const auto copy = mRegistryListeners; // be prepared for listeners unregistering on notification
for (Listener l : copy)
@@ -690,7 +691,7 @@ void QWaylandDisplay::registry_global_remove(uint32_t id)
inputDevice->setTextInputMethod(nullptr);
mWaylandIntegration->reconfigureInputContext();
}
- mGlobals.removeAt(i);
+ emit globalRemoved(mGlobals.takeAt(i));
break;
}
}
diff --git a/src/client/qwaylanddisplay_p.h b/src/client/qwaylanddisplay_p.h
index cf123cba..5a83c324 100644
--- a/src/client/qwaylanddisplay_p.h
+++ b/src/client/qwaylanddisplay_p.h
@@ -228,6 +228,10 @@ public slots:
void blockingReadEvents();
void flushRequests();
+signals:
+ void globalAdded(const RegistryGlobal &global);
+ void globalRemoved(const RegistryGlobal &global);
+
private:
void handleWaylandSync();
void requestWaylandSync();