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>
This commit is contained in:
Erik Larsson 2016-02-27 23:00:02 +01:00
parent c477d954ae
commit 4e697de346
3 changed files with 28 additions and 3 deletions

View File

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

View File

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

View File

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