diff options
author | Giulio Camuffo <giulio.camuffo@kdab.com> | 2016-03-24 12:53:07 +0200 |
---|---|---|
committer | Giulio Camuffo <giulio.camuffo@kdab.com> | 2016-03-29 12:11:07 +0000 |
commit | 8b89cef7d50325d576fc1206fda840a05b0578fb (patch) | |
tree | 74358e0f2971d5ae8e79f150a6fbac813887468a | |
parent | f3913dddee41b4a2c52518e720ac1945fde3bbab (diff) | |
download | qtwayland-8b89cef7d50325d576fc1206fda840a05b0578fb.tar.gz |
Add QWaylandShellSurface::fromResource()
Also make sure that the generated *::Resource::fromResource() code
returns null if it doesn't own the resource or if the interface is
wrong.
Change-Id: I904e0dd49dd6e535ef8cab6687c6869e1000048d
Reviewed-by: Johan Helsing <johan.helsing@theqtcompany.com>
Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
-rw-r--r-- | src/compositor/extensions/qwaylandshell.cpp | 11 | ||||
-rw-r--r-- | src/compositor/extensions/qwaylandshell.h | 2 | ||||
-rw-r--r-- | src/qtwaylandscanner/qtwaylandscanner.cpp | 9 |
3 files changed, 21 insertions, 1 deletions
diff --git a/src/compositor/extensions/qwaylandshell.cpp b/src/compositor/extensions/qwaylandshell.cpp index 633129b2..7965c9c6 100644 --- a/src/compositor/extensions/qwaylandshell.cpp +++ b/src/compositor/extensions/qwaylandshell.cpp @@ -578,4 +578,15 @@ void QWaylandShellSurface::ping() d->ping(serial); } +/*! + * Returns the QWaylandShellSurface object associated with the given \a resource, or null if no such object exists. + */ +QWaylandShellSurface *QWaylandShellSurface::fromResource(wl_resource *resource) +{ + QWaylandShellSurfacePrivate::Resource *res = QWaylandShellSurfacePrivate::Resource::fromResource(resource); + if (res) + return static_cast<QWaylandShellSurfacePrivate *>(res->shell_surface_object)->q_func(); + return 0; +} + QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwaylandshell.h b/src/compositor/extensions/qwaylandshell.h index 3b0d1c25..5fec80ff 100644 --- a/src/compositor/extensions/qwaylandshell.h +++ b/src/compositor/extensions/qwaylandshell.h @@ -122,6 +122,8 @@ public: static QByteArray interfaceName(); static QWaylandSurfaceRole *role(); + static QWaylandShellSurface *fromResource(wl_resource *res); + Q_INVOKABLE QSize sizeForResize(const QSizeF &size, const QPointF &delta, ResizeEdge edges); Q_INVOKABLE void sendConfigure(const QSize &size, ResizeEdge edges); Q_INVOKABLE void sendPopupDone(); diff --git a/src/qtwaylandscanner/qtwaylandscanner.cpp b/src/qtwaylandscanner/qtwaylandscanner.cpp index b609523b..5b9707a5 100644 --- a/src/qtwaylandscanner/qtwaylandscanner.cpp +++ b/src/qtwaylandscanner/qtwaylandscanner.cpp @@ -439,7 +439,7 @@ void process(QXmlStreamReader &xml, const QByteArray &headerPath, const QByteArr printf(" struct ::wl_client *client() const { return handle->client; }\n"); printf(" int version() const { return wl_resource_get_version(handle); }\n"); printf("\n"); - printf(" static Resource *fromResource(struct ::wl_resource *resource) { return static_cast<Resource *>(resource->data); }\n"); + printf(" static Resource *fromResource(struct ::wl_resource *resource);\n"); printf(" };\n"); printf("\n"); printf(" void init(struct ::wl_client *client, int id, int version);\n"); @@ -708,6 +708,13 @@ void process(QXmlStreamReader &xml, const QByteArray &headerPath, const QByteArr printf(" return resource;\n"); printf(" }\n"); + printf(" %s::Resource *%s::Resource::fromResource(struct ::wl_resource *resource)\n", interfaceName, interfaceName); + printf(" {\n"); + printf(" if (wl_resource_instance_of(resource, &::%s_interface, %s))\n", interfaceName, interfaceMember.constData()); + printf(" return static_cast<Resource *>(resource->data);\n"); + printf(" return 0;\n"); + printf(" }\n"); + if (hasRequests) { printf("\n"); printf(" const struct ::%s_interface %s::m_%s_interface = {", interfaceName, interfaceName, interfaceName); |