diff options
author | Erik Larsson <erik@ortogonal.com> | 2016-02-27 23:00:02 +0100 |
---|---|---|
committer | Erik Larsson <erik@ortogonal.com> | 2016-04-21 11:29:56 +0000 |
commit | bfa66ccb29f747e2cb07a4f2e561b165be9f211d (patch) | |
tree | 35745d3f2ee0772bb9fe18ca5e309001396d21de /src/client | |
parent | fb417c301cace4825d13e818e4e7e4e1b966c630 (diff) |
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 <giulio.camuffo@kdab.com>
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/global/qwaylandclientextension.cpp | 27 | ||||
-rw-r--r-- | src/client/global/qwaylandclientextension.h | 3 | ||||
-rw-r--r-- | src/client/global/qwaylandclientextension_p.h | 1 |
3 files changed, 28 insertions, 3 deletions
diff --git a/src/client/global/qwaylandclientextension.cpp b/src/client/global/qwaylandclientextension.cpp index 501f266f5..b71c41d11 100644 --- a/src/client/global/qwaylandclientextension.cpp +++ b/src/client/global/qwaylandclientextension.cpp @@ -38,6 +38,8 @@ #include "qwaylandclientextension_p.h" #include <QtWaylandClient/private/qwaylanddisplay_p.h> #include <QtWaylandClient/private/qwaylandintegration_p.h> +#include <QtGui/QGuiApplication> +#include <QtGui/qpa/qplatformnativeinterface.h> 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<struct ::wl_display*>(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<struct ::wl_registry *>(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/client/global/qwaylandclientextension.h b/src/client/global/qwaylandclientextension.h index efdfa46fb..aee03eb29 100644 --- a/src/client/global/qwaylandclientextension.h +++ b/src/client/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 <typename T> diff --git a/src/client/global/qwaylandclientextension_p.h b/src/client/global/qwaylandclientextension_p.h index 2676f0ee6..9287ee95a 100644 --- a/src/client/global/qwaylandclientextension_p.h +++ b/src/client/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; |