From 4e697de346025f86adb36422072766b6056d1dde Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Sat, 27 Feb 2016 23:00:02 +0100 Subject: [PATCH] Add QML api for client side extension. This makes it simple to use client-side extensions in QML. The only thing that the user needs to do is register the extension class using qmlRegisterType() and the use the extension in QML. Also adds simple QML example which uses client-side extension. Change-Id: I2db99861d97c7bca5cfdbf86ba3a8ccc50fb24b0 Reviewed-by: Giulio Camuffo --- .../global/qwaylandclientextension.cpp | 27 ++++++++++++++++--- .../wayland/global/qwaylandclientextension.h | 3 +++ .../global/qwaylandclientextension_p.h | 1 + 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/wayland/global/qwaylandclientextension.cpp b/src/plugins/platforms/wayland/global/qwaylandclientextension.cpp index 501f266f534..b71c41d11e9 100644 --- a/src/plugins/platforms/wayland/global/qwaylandclientextension.cpp +++ b/src/plugins/platforms/wayland/global/qwaylandclientextension.cpp @@ -38,6 +38,8 @@ #include "qwaylandclientextension_p.h" #include #include +#include +#include QT_BEGIN_NAMESPACE @@ -45,11 +47,22 @@ namespace QtWaylandClient { QWaylandClientExtensionPrivate::QWaylandClientExtensionPrivate() : QObjectPrivate() - , waylandIntegration(new QWaylandIntegration()) + , waylandIntegration(NULL) , version(-1) + , active(false) { - QtWaylandClient::QWaylandDisplay *waylandDisplay = waylandIntegration->display(); - struct ::wl_registry *registry = wl_display_get_registry(waylandDisplay->wl_display()); + // Keep the possibility to use a custom waylandIntegration as a plugin, + // but also add the possibility to run it as a QML component. + struct ::wl_display *waylandDisplay = NULL; + if (QGuiApplication::platformNativeInterface()) { + waylandDisplay = static_cast(QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("wl_display")); + } else { + waylandIntegration = new QWaylandIntegration(); + waylandDisplay = waylandIntegration->display()->wl_display(); + } + + Q_ASSERT(waylandDisplay); + struct ::wl_registry *registry = wl_display_get_registry(waylandDisplay); QtWayland::wl_registry::init(registry); } @@ -59,6 +72,8 @@ void QWaylandClientExtensionPrivate::registry_global(uint32_t id, const QString if (interfaceName == QLatin1String(q->extensionInterface()->name)) { struct ::wl_registry *registry = static_cast(QtWayland::wl_registry::object()); q->bind(registry, id, ver); + active = true; + emit q->activeChanged(); } } @@ -90,6 +105,12 @@ void QWaylandClientExtension::setVersion(const int ver) } } +bool QWaylandClientExtension::active() const +{ + Q_D(const QWaylandClientExtension); + return d->active; +} + } QT_END_NAMESPACE diff --git a/src/plugins/platforms/wayland/global/qwaylandclientextension.h b/src/plugins/platforms/wayland/global/qwaylandclientextension.h index efdfa46fb65..aee03eb2911 100644 --- a/src/plugins/platforms/wayland/global/qwaylandclientextension.h +++ b/src/plugins/platforms/wayland/global/qwaylandclientextension.h @@ -54,11 +54,13 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandClientExtension : public QObject Q_OBJECT Q_DECLARE_PRIVATE(QWaylandClientExtension) Q_PROPERTY(int protocolVersion READ version NOTIFY versionChanged) + Q_PROPERTY(bool active READ active NOTIFY activeChanged) public: QWaylandClientExtension(const int version); QWaylandIntegration *integration() const; int version() const; + bool active() const; virtual const struct wl_interface *extensionInterface() const = 0; virtual void bind(struct ::wl_registry *registry, int id, int version) = 0; @@ -66,6 +68,7 @@ protected: void setVersion(const int version); Q_SIGNALS: void versionChanged(); + void activeChanged(); }; template diff --git a/src/plugins/platforms/wayland/global/qwaylandclientextension_p.h b/src/plugins/platforms/wayland/global/qwaylandclientextension_p.h index 2676f0ee632..9287ee95a50 100644 --- a/src/plugins/platforms/wayland/global/qwaylandclientextension_p.h +++ b/src/plugins/platforms/wayland/global/qwaylandclientextension_p.h @@ -65,6 +65,7 @@ public: QWaylandIntegration *waylandIntegration; int version; + bool active; protected: void registry_global(uint32_t id, const QString &interfaceName, uint32_t version) Q_DECL_OVERRIDE;