summaryrefslogtreecommitdiffstats
path: root/src/client/global/qwaylandclientextension.cpp
diff options
context:
space:
mode:
authorErik Larsson <erik@ortogonal.com>2016-02-27 23:00:02 +0100
committerErik Larsson <erik@ortogonal.com>2016-04-21 11:29:56 +0000
commitbfa66ccb29f747e2cb07a4f2e561b165be9f211d (patch)
tree35745d3f2ee0772bb9fe18ca5e309001396d21de /src/client/global/qwaylandclientextension.cpp
parentfb417c301cace4825d13e818e4e7e4e1b966c630 (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/global/qwaylandclientextension.cpp')
-rw-r--r--src/client/global/qwaylandclientextension.cpp27
1 files changed, 24 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