From da81f4c9e8be15ec26c767bc42297648ee1b2779 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 6 Apr 2021 22:50:52 +0300 Subject: [PATCH] Send valid UUIDs for output device globals Currently, kwin sends invalid uuids. This change makes harder to send invalid uuids by porting relevant parts of the OutputDeviceInterface to QUuid. --- .../client/test_wayland_outputdevice.cpp | 19 ++++++------------- src/wayland/server/outputdevice_interface.cpp | 8 ++++---- src/wayland/server/outputdevice_interface.h | 7 ++++--- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/wayland/autotests/client/test_wayland_outputdevice.cpp b/src/wayland/autotests/client/test_wayland_outputdevice.cpp index f69306c630..163169f0f7 100644 --- a/src/wayland/autotests/client/test_wayland_outputdevice.cpp +++ b/src/wayland/autotests/client/test_wayland_outputdevice.cpp @@ -81,8 +81,7 @@ void TestWaylandOutputDevice::init() QVERIFY(m_display->isRunning()); m_serverOutputDevice = new OutputDeviceInterface(m_display, this); - m_serverOutputDevice->setUuid("1337"); - + m_serverOutputDevice->setUuid(QUuid("00000000-0000-0000-0000-000000000000")); OutputDeviceInterface::Mode m0; m0.id = 0; @@ -228,7 +227,7 @@ void TestWaylandOutputDevice::testRegistry() QCOMPARE(output.edid(), m_edid); QCOMPARE(output.enabled(), OutputDevice::Enablement::Enabled); - QCOMPARE(output.uuid(), QStringLiteral("1337")); + QCOMPARE(output.uuid(), QStringLiteral("00000000-0000-0000-0000-000000000000")); QCOMPARE(output.serialNumber(), m_serialNumber); QCOMPARE(output.eisaId(), m_eidaId); } @@ -596,22 +595,16 @@ void TestWaylandOutputDevice::testId() wl_display_flush(m_connection->display()); QVERIFY(outputChanged.wait()); - QCOMPARE(output.uuid(), QStringLiteral("1337")); + QCOMPARE(output.uuid(), QStringLiteral("00000000-0000-0000-0000-000000000000")); QSignalSpy idChanged(&output, &KWayland::Client::OutputDevice::uuidChanged); QVERIFY(idChanged.isValid()); - m_serverOutputDevice->setUuid("42"); + m_serverOutputDevice->setUuid(QUuid("00000000-0000-0000-0000-000000000001")); QVERIFY(idChanged.wait()); - QCOMPARE(idChanged.first().first().toByteArray(), QByteArray("42")); + QCOMPARE(idChanged.first().first().toByteArray(), QByteArray("00000000-0000-0000-0000-000000000001")); idChanged.clear(); - QCOMPARE(output.uuid(), QStringLiteral("42")); - - m_serverOutputDevice->setUuid("4711"); - QVERIFY(idChanged.wait()); - QCOMPARE(idChanged.first().first().toByteArray(), QByteArray("4711")); - idChanged.clear(); - QCOMPARE(output.uuid(), QStringLiteral("4711")); + QCOMPARE(output.uuid(), QStringLiteral("00000000-0000-0000-0000-000000000001")); } void TestWaylandOutputDevice::testDone() diff --git a/src/wayland/server/outputdevice_interface.cpp b/src/wayland/server/outputdevice_interface.cpp index 81829bb098..eaab48a079 100644 --- a/src/wayland/server/outputdevice_interface.cpp +++ b/src/wayland/server/outputdevice_interface.cpp @@ -62,7 +62,7 @@ public: QByteArray edid; OutputDeviceInterface::Enablement enabled = OutputDeviceInterface::Enablement::Enabled; - QString uuid; + QUuid uuid; QPointer display; OutputDeviceInterface *q; @@ -568,7 +568,7 @@ OutputDeviceInterface::Enablement OutputDeviceInterface::enabled() const return d->enabled; } -void OutputDeviceInterface::setUuid(const QString &uuid) +void OutputDeviceInterface::setUuid(const QUuid &uuid) { if (d->uuid != uuid) { d->uuid = uuid; @@ -577,7 +577,7 @@ void OutputDeviceInterface::setUuid(const QString &uuid) } } -QString OutputDeviceInterface::uuid() const +QUuid OutputDeviceInterface::uuid() const { return d->uuid; } @@ -598,7 +598,7 @@ void OutputDeviceInterfacePrivate::sendEnabled(Resource *resource) void OutputDeviceInterfacePrivate::sendUuid(Resource *resource) { - send_uuid(resource->handle, uuid); + send_uuid(resource->handle, uuid.toString(QUuid::WithoutBraces)); } void OutputDeviceInterfacePrivate::updateEnabled() diff --git a/src/wayland/server/outputdevice_interface.h b/src/wayland/server/outputdevice_interface.h index dfc0160cfa..e8a161c1c4 100644 --- a/src/wayland/server/outputdevice_interface.h +++ b/src/wayland/server/outputdevice_interface.h @@ -10,6 +10,7 @@ #include #include #include +#include #include struct wl_resource; @@ -41,7 +42,7 @@ class KWAYLANDSERVER_EXPORT OutputDeviceInterface : public QObject Q_PROPERTY(qreal scale READ scaleF WRITE setScaleF NOTIFY scaleFChanged) Q_PROPERTY(QByteArray edid READ edid WRITE setEdid NOTIFY edidChanged) Q_PROPERTY(OutputDeviceInterface::Enablement enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(QString uuid READ uuid WRITE setUuid NOTIFY uuidChanged) + Q_PROPERTY(QUuid uuid READ uuid WRITE setUuid NOTIFY uuidChanged) public: enum class SubPixel { Unknown, @@ -103,7 +104,7 @@ public: QByteArray edid() const; OutputDeviceInterface::Enablement enabled() const; - QString uuid() const; + QUuid uuid() const; void setPhysicalSize(const QSize &size); void setGlobalPosition(const QPoint &pos); @@ -133,7 +134,7 @@ public: void setEdid(const QByteArray &edid); void setEnabled(OutputDeviceInterface::Enablement enabled); - void setUuid(const QString &uuid); + void setUuid(const QUuid &uuid); static OutputDeviceInterface *get(wl_resource *native); static QListlist();