diff options
author | Robert Griebl <robert.griebl@qt.io> | 2024-03-14 12:50:11 +0100 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2024-03-18 16:56:50 +0100 |
commit | 0970e3f1d21c6bfaf0e2e6f897b38aa99c4d6f7e (patch) | |
tree | b1404ff10fa98ec5fd8a3e539df4599957437176 /src/window-lib | |
parent | 7295ea86053e1f64fd6895a5630521453a986808 (diff) |
Also support CBOR as a wire format for window properties on Wayland
Our extension now supports both the old style serialization via
QDataStream for Qt clients (version 1) and via CBOR for easy use in
non-Qt clients (version 2).
Change-Id: I757fda61af126fb273264133552b86f3e0127a6a
Reviewed-by: Bernd Weimer <bernd.weimer@qt.io>
Diffstat (limited to 'src/window-lib')
-rw-r--r-- | src/window-lib/waylandqtamserverextension.cpp | 46 | ||||
-rw-r--r-- | src/window-lib/window.cpp | 4 |
2 files changed, 38 insertions, 12 deletions
diff --git a/src/window-lib/waylandqtamserverextension.cpp b/src/window-lib/waylandqtamserverextension.cpp index a6c17204..57c645df 100644 --- a/src/window-lib/waylandqtamserverextension.cpp +++ b/src/window-lib/waylandqtamserverextension.cpp @@ -6,6 +6,7 @@ #include "waylandqtamserverextension_p.h" #include <QDataStream> +#include <QCborValue> #include <QtWaylandCompositor/QWaylandCompositor> #include <QtWaylandCompositor/QWaylandResource> #include <QtWaylandCompositor/QWaylandSurface> @@ -16,7 +17,7 @@ QT_BEGIN_NAMESPACE_AM WaylandQtAMServerExtension::WaylandQtAMServerExtension(QWaylandCompositor *compositor) : QWaylandCompositorExtensionTemplate(compositor) - , QtWaylandServer::qtam_extension(compositor->display(), 1) + , QtWaylandServer::qtam_extension(compositor->display(), 2) { } QVariantMap WaylandQtAMServerExtension::windowProperties(const QWaylandSurface *surface) const @@ -27,14 +28,25 @@ QVariantMap WaylandQtAMServerExtension::windowProperties(const QWaylandSurface * void WaylandQtAMServerExtension::setWindowProperty(QWaylandSurface *surface, const QString &name, const QVariant &value) { if (setWindowPropertyHelper(surface, name, value)) { - QByteArray byteValue; - QDataStream ds(&byteValue, QDataStream::WriteOnly); - ds << value; + if (Resource *target = resourceMap().value(surface->waylandClient())) { + QByteArray data; - Resource *target = resourceMap().value(surface->waylandClient()); - if (target) { - qDebug(LogWaylandDebug) << "window property: server send" << surface << name << value; - send_window_property_changed(target->handle, surface->resource(), name, byteValue); + switch (target->version()) { + case 1: { + QDataStream ds(&data, QDataStream::WriteOnly); + ds << value; + break; + } + case 2: + data = QCborValue::fromVariant(value).toCbor(); + break; + default: + qCWarning(LogWaylandDebug) << "Unsupported qtam_extension version:" << target->version(); + return; + } + + qCDebug(LogWaylandDebug) << "window property: server send" << surface << name << value; + send_window_property_changed(target->handle, surface->resource(), name, data); } } } @@ -59,13 +71,23 @@ bool WaylandQtAMServerExtension::setWindowPropertyHelper(QWaylandSurface *surfac void WaylandQtAMServerExtension::qtam_extension_set_window_property(QtWaylandServer::qtam_extension::Resource *resource, wl_resource *surface_resource, const QString &name, wl_array *value) { - Q_UNUSED(resource) QWaylandSurface *surface = QWaylandSurface::fromResource(surface_resource); - const QByteArray byteValue(static_cast<const char *>(value->data), static_cast<int>(value->size)); - QDataStream ds(byteValue); + const auto data = QByteArray::fromRawData(static_cast<const char *>(value->data), qsizetype(value->size)); QVariant variantValue; - ds >> variantValue; + switch (resource->version()) { + case 1: { + QDataStream ds(data); + ds >> variantValue; + break; + } + case 2: + variantValue = QCborValue::fromCbor(data).toVariant(); + break; + default: + qCWarning(LogWaylandDebug) << "Unsupported qtam_extension version:" << resource->version(); + return; + } qCDebug(LogWaylandDebug) << "window property: server receive" << surface << name << variantValue; setWindowPropertyHelper(surface, name, variantValue); } diff --git a/src/window-lib/window.cpp b/src/window-lib/window.cpp index cedbf4de..1e071aa1 100644 --- a/src/window-lib/window.cpp +++ b/src/window-lib/window.cpp @@ -31,6 +31,10 @@ surface Wayland extension. Changes from the client side are notified by the windowPropertyChanged() signal. + Starting with version 6.8, non-Qt Wayland clients can use version 2 of the extension, which + uses CBOR as a wire format, but only \l{QCborValue::fromVariant()}{types supported by CBOR} + can be used as values for these clients. + See ApplicationManagerWindow for the client side API. \sa windowProperty(), windowProperties(), windowPropertyChanged() |