Use QWaylandDisplay::addRegistryListener in QWaylandClientExtension
Gets rid of an unnecessary get_registry request Change-Id: Ic8c6a61271658e07fbd67c83df0ae9e3d955d938 Reviewed-by: Giulio Camuffo <giulio.camuffo@kdab.com>
This commit is contained in:
parent
e79aa19f67
commit
065557fa2b
@ -39,7 +39,7 @@
|
|||||||
#include <QtWaylandClient/private/qwaylanddisplay_p.h>
|
#include <QtWaylandClient/private/qwaylanddisplay_p.h>
|
||||||
#include <QtWaylandClient/private/qwaylandintegration_p.h>
|
#include <QtWaylandClient/private/qwaylandintegration_p.h>
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
#include <QtGui/qpa/qplatformnativeinterface.h>
|
#include <QtGui/private/qguiapplication_p.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -51,35 +51,37 @@ QWaylandClientExtensionPrivate::QWaylandClientExtensionPrivate()
|
|||||||
{
|
{
|
||||||
// Keep the possibility to use a custom waylandIntegration as a plugin,
|
// Keep the possibility to use a custom waylandIntegration as a plugin,
|
||||||
// but also add the possibility to run it as a QML component.
|
// but also add the possibility to run it as a QML component.
|
||||||
struct ::wl_display *waylandDisplay = NULL;
|
waylandIntegration = static_cast<QtWaylandClient::QWaylandIntegration *>(QGuiApplicationPrivate::platformIntegration());
|
||||||
if (QGuiApplication::platformNativeInterface()) {
|
if (!waylandIntegration)
|
||||||
waylandDisplay = static_cast<struct ::wl_display*>(QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("wl_display"));
|
|
||||||
} else {
|
|
||||||
waylandIntegration = new QtWaylandClient::QWaylandIntegration();
|
waylandIntegration = new QtWaylandClient::QWaylandIntegration();
|
||||||
waylandDisplay = waylandIntegration->display()->wl_display();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(waylandDisplay);
|
|
||||||
struct ::wl_registry *registry = wl_display_get_registry(waylandDisplay);
|
|
||||||
QtWayland::wl_registry::init(registry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWaylandClientExtensionPrivate::registry_global(uint32_t id, const QString &interfaceName, uint32_t ver)
|
void QWaylandClientExtensionPrivate::handleRegistryGlobal(void *data, ::wl_registry *registry, uint32_t id,
|
||||||
|
const QString &interface, uint32_t version)
|
||||||
{
|
{
|
||||||
Q_Q(QWaylandClientExtension);
|
QWaylandClientExtension *extension = static_cast<QWaylandClientExtension *>(data);
|
||||||
if (interfaceName == QLatin1String(q->extensionInterface()->name)) {
|
if (interface == QLatin1String(extension->extensionInterface()->name)) {
|
||||||
struct ::wl_registry *registry = static_cast<struct ::wl_registry *>(QtWayland::wl_registry::object());
|
extension->bind(registry, id, version);
|
||||||
q->bind(registry, id, ver);
|
extension->d_func()->active = true;
|
||||||
active = true;
|
emit extension->activeChanged();
|
||||||
emit q->activeChanged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QWaylandClientExtension::addRegistryListener()
|
||||||
|
{
|
||||||
|
Q_D(QWaylandClientExtension);
|
||||||
|
d->waylandIntegration->display()->addRegistryListener(&QWaylandClientExtensionPrivate::handleRegistryGlobal, this);
|
||||||
|
}
|
||||||
|
|
||||||
QWaylandClientExtension::QWaylandClientExtension(const int ver)
|
QWaylandClientExtension::QWaylandClientExtension(const int ver)
|
||||||
: QObject(*new QWaylandClientExtensionPrivate())
|
: QObject(*new QWaylandClientExtensionPrivate())
|
||||||
{
|
{
|
||||||
Q_D(QWaylandClientExtension);
|
Q_D(QWaylandClientExtension);
|
||||||
d->version = ver;
|
d->version = ver;
|
||||||
|
|
||||||
|
// The registry listener uses virtual functions and we don't want it to be called from
|
||||||
|
// the constructor.
|
||||||
|
QMetaObject::invokeMethod(this, "addRegistryListener", Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtWaylandClient::QWaylandIntegration *QWaylandClientExtension::integration() const
|
QtWaylandClient::QWaylandIntegration *QWaylandClientExtension::integration() const
|
||||||
|
@ -69,6 +69,9 @@ protected:
|
|||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void versionChanged();
|
void versionChanged();
|
||||||
void activeChanged();
|
void activeChanged();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void addRegistryListener();
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -51,22 +51,20 @@
|
|||||||
#include "qwaylandclientextension.h"
|
#include "qwaylandclientextension.h"
|
||||||
#include <QtCore/private/qobject_p.h>
|
#include <QtCore/private/qobject_p.h>
|
||||||
#include <QtWaylandClient/private/qwaylandintegration_p.h>
|
#include <QtWaylandClient/private/qwaylandintegration_p.h>
|
||||||
#include <QtWaylandClient/private/qwayland-wayland.h>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class Q_WAYLAND_CLIENT_EXPORT QWaylandClientExtensionPrivate : public QObjectPrivate, public QtWayland::wl_registry
|
class Q_WAYLAND_CLIENT_EXPORT QWaylandClientExtensionPrivate : public QObjectPrivate
|
||||||
{
|
{
|
||||||
Q_DECLARE_PUBLIC(QWaylandClientExtension)
|
Q_DECLARE_PUBLIC(QWaylandClientExtension)
|
||||||
public:
|
public:
|
||||||
QWaylandClientExtensionPrivate();
|
QWaylandClientExtensionPrivate();
|
||||||
|
static void handleRegistryGlobal(void *data, ::wl_registry *registry, uint32_t id,
|
||||||
|
const QString &interface, uint32_t version);
|
||||||
|
|
||||||
QtWaylandClient::QWaylandIntegration *waylandIntegration;
|
QtWaylandClient::QWaylandIntegration *waylandIntegration;
|
||||||
int version;
|
int version;
|
||||||
bool active;
|
bool active;
|
||||||
|
|
||||||
protected:
|
|
||||||
void registry_global(uint32_t id, const QString &interfaceName, uint32_t version) Q_DECL_OVERRIDE;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Q_WAYLAND_CLIENT_EXPORT QWaylandClientExtensionTemplatePrivate : public QWaylandClientExtensionPrivate
|
class Q_WAYLAND_CLIENT_EXPORT QWaylandClientExtensionTemplatePrivate : public QWaylandClientExtensionPrivate
|
||||||
|
Loading…
x
Reference in New Issue
Block a user