15#include "KWayland/Client/compositor.h"
16#include "KWayland/Client/connection_thread.h"
17#include "KWayland/Client/contrast.h"
18#include "KWayland/Client/event_queue.h"
19#include "KWayland/Client/region.h"
20#include "KWayland/Client/registry.h"
21#include "KWayland/Client/surface.h"
23#include <wayland-util.h>
35 void testSurfaceDestroy();
41 KWayland::Client::ConnectionThread *m_connection;
42 KWayland::Client::Compositor *m_compositor;
43 KWayland::Client::ContrastManager *m_contrastManager;
44 KWayland::Client::EventQueue *m_queue;
48static const QString s_socketName = QStringLiteral(
"kwayland-test-wayland-contrast-0");
53 , m_compositorInterface(nullptr)
54 , m_connection(nullptr)
55 , m_compositor(nullptr)
61void TestContrast::init()
71 m_connection =
new KWayland::Client::ConnectionThread;
72 QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
73 m_connection->setSocketName(s_socketName);
75 m_thread =
new QThread(
this);
76 m_connection->moveToThread(m_thread);
79 m_connection->initConnection();
80 QVERIFY(connectedSpy.wait());
82 m_queue =
new KWayland::Client::EventQueue(
this);
83 QVERIFY(!m_queue->isValid());
84 m_queue->setup(m_connection);
85 QVERIFY(m_queue->isValid());
87 KWayland::Client::Registry registry;
88 QSignalSpy compositorSpy(®istry, &KWayland::Client::Registry::compositorAnnounced);
90 QSignalSpy contrastSpy(®istry, &KWayland::Client::Registry::contrastAnnounced);
92 QVERIFY(!registry.eventQueue());
93 registry.setEventQueue(m_queue);
94 QCOMPARE(registry.eventQueue(), m_queue);
95 registry.create(m_connection->display());
96 QVERIFY(registry.isValid());
100 QVERIFY(compositorSpy.wait());
101 m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(),
this);
105 QVERIFY(contrastSpy.wait());
106 m_contrastManager = registry.createContrastManager(contrastSpy.first().first().value<quint32>(), contrastSpy.first().last().value<quint32>(),
this);
109void TestContrast::cleanup()
111#define CLEANUP(variable) \
114 variable = nullptr; \
120 m_connection->deleteLater();
121 m_connection =
nullptr;
133 m_compositorInterface =
nullptr;
134 m_contrastManagerInterface =
nullptr;
137void TestContrast::testCreate()
141 std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
142 QVERIFY(serverSurfaceCreated.wait());
147 auto contrast = m_contrastManager->createContrast(surface.get(), surface.get());
148 contrast->setRegion(m_compositor->createRegion(QRegion(0, 0, 10, 20),
nullptr));
150 contrast->setContrast(0.2);
151 contrast->setIntensity(2.0);
152 contrast->setSaturation(1.7);
155 surface->commit(KWayland::Client::Surface::CommitFlag::None);
157 QVERIFY(contrastChanged.wait());
158 QCOMPARE(serverSurface->contrast()->region(), QRegion(0, 0, 10, 20));
159 QCOMPARE(wl_fixed_from_double(serverSurface->contrast()->contrast()), wl_fixed_from_double(0.2));
160 QCOMPARE(wl_fixed_from_double(serverSurface->contrast()->intensity()), wl_fixed_from_double(2.0));
161 QCOMPARE(wl_fixed_from_double(serverSurface->contrast()->saturation()), wl_fixed_from_double(1.7));
164 QSignalSpy destroyedSpy(serverSurface->contrast(), &QObject::destroyed);
166 QVERIFY(destroyedSpy.wait());
169void TestContrast::testSurfaceDestroy()
173 std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
174 QVERIFY(serverSurfaceCreated.wait());
179 std::unique_ptr<KWayland::Client::Contrast> contrast(m_contrastManager->createContrast(surface.get()));
180 contrast->setRegion(m_compositor->createRegion(QRegion(0, 0, 10, 20),
nullptr));
182 surface->commit(KWayland::Client::Surface::CommitFlag::None);
184 QVERIFY(contrastChanged.wait());
185 QCOMPARE(serverSurface->contrast()->region(), QRegion(0, 0, 10, 20));
188 QSignalSpy surfaceDestroyedSpy(serverSurface, &QObject::destroyed);
189 QSignalSpy contrastDestroyedSpy(serverSurface->contrast(), &QObject::destroyed);
191 QVERIFY(surfaceDestroyedSpy.wait());
192 QVERIFY(contrastDestroyedSpy.isEmpty());
195 QVERIFY(contrastDestroyedSpy.wait());
199#include "test_wayland_contrast.moc"
void surfaceCreated(KWin::SurfaceInterface *surface)
Represents the Global for org_kde_kwin_contrast_manager interface.
Class holding the Wayland server display loop.
bool addSocketName(const QString &name=QString())
Resource representing a wl_surface.
TestContrast(QObject *parent=nullptr)
#define CLEANUP(variable)