10#include "KWayland/Client/compositor.h"
11#include "KWayland/Client/connection_thread.h"
12#include "KWayland/Client/datadevice.h"
13#include "KWayland/Client/datadevicemanager.h"
14#include "KWayland/Client/datasource.h"
15#include "KWayland/Client/event_queue.h"
16#include "KWayland/Client/keyboard.h"
17#include "KWayland/Client/registry.h"
18#include "KWayland/Client/seat.h"
19#include "KWayland/Client/surface.h"
34 void testClearOnEnter();
44 KWayland::Client::ConnectionThread *connection =
nullptr;
45 QThread *thread =
nullptr;
46 KWayland::Client::EventQueue *queue =
nullptr;
47 KWayland::Client::Compositor *compositor =
nullptr;
48 KWayland::Client::Seat *seat =
nullptr;
49 KWayland::Client::DataDeviceManager *ddm =
nullptr;
50 KWayland::Client::Keyboard *keyboard =
nullptr;
51 KWayland::Client::DataDevice *dataDevice =
nullptr;
53 bool setupConnection(Connection *c);
54 void cleanupConnection(Connection *c);
60static const QString s_socketName = QStringLiteral(
"kwayland-test-selection-0");
62void SelectionTest::init()
76 setupConnection(&m_client1);
77 setupConnection(&m_client2);
80bool SelectionTest::setupConnection(Connection *c)
82 c->connection =
new KWayland::Client::ConnectionThread;
83 QSignalSpy connectedSpy(c->connection, &KWayland::Client::ConnectionThread::connected);
84 if (!connectedSpy.isValid()) {
87 c->connection->setSocketName(s_socketName);
89 c->thread =
new QThread(
this);
90 c->connection->moveToThread(c->thread);
93 c->connection->initConnection();
94 if (!connectedSpy.wait(500)) {
98 c->queue =
new KWayland::Client::EventQueue(
this);
99 c->queue->setup(c->connection);
101 KWayland::Client::Registry
registry;
102 QSignalSpy interfacesAnnouncedSpy(®istry, &KWayland::Client::Registry::interfacesAnnounced);
103 if (!interfacesAnnouncedSpy.isValid()) {
112 if (!interfacesAnnouncedSpy.wait(500)) {
117 registry.createCompositor(
registry.interface(KWayland::Client::Registry::Interface::Compositor).name,
registry.interface(KWayland::Client::Registry::Interface::Compositor).version,
this);
118 if (!c->compositor->isValid()) {
121 c->ddm =
registry.createDataDeviceManager(
registry.interface(KWayland::Client::Registry::Interface::DataDeviceManager).name,
122 registry.interface(KWayland::Client::Registry::Interface::DataDeviceManager).version,
124 if (!c->ddm->isValid()) {
127 c->seat =
registry.createSeat(
registry.interface(KWayland::Client::Registry::Interface::Seat).name,
registry.interface(KWayland::Client::Registry::Interface::Seat).version,
this);
128 if (!c->seat->isValid()) {
131 QSignalSpy keyboardSpy(c->seat, &KWayland::Client::Seat::hasKeyboardChanged);
132 if (!keyboardSpy.isValid()) {
135 if (!keyboardSpy.wait(500)) {
138 if (!c->seat->hasKeyboard()) {
141 c->keyboard = c->seat->createKeyboard(c->seat);
142 if (!c->keyboard->isValid()) {
145 c->dataDevice = c->ddm->getDataDevice(c->seat,
this);
146 if (!c->dataDevice->isValid()) {
153void SelectionTest::cleanup()
155 cleanupConnection(&m_client1);
156 cleanupConnection(&m_client2);
157#define CLEANUP(variable) \
164 m_ddmInterface =
nullptr;
165 m_seatInterface =
nullptr;
166 m_compositorInterface =
nullptr;
169void SelectionTest::cleanupConnection(Connection *c)
171 delete c->dataDevice;
172 c->dataDevice =
nullptr;
174 c->keyboard =
nullptr;
179 delete c->compositor;
180 c->compositor =
nullptr;
184 c->connection->deleteLater();
185 c->connection =
nullptr;
195void SelectionTest::testClearOnEnter()
198 QSignalSpy selectionClearedClient1Spy(m_client1.dataDevice, &KWayland::Client::DataDevice::selectionCleared);
199 QSignalSpy keyboardEnteredClient1Spy(m_client1.keyboard, &KWayland::Client::Keyboard::entered);
203 std::unique_ptr<KWayland::Client::Surface> s1(m_client1.compositor->createSurface());
204 QVERIFY(surfaceCreatedSpy.wait());
205 auto serverSurface1 = surfaceCreatedSpy.first().first().value<
SurfaceInterface *>();
206 QVERIFY(serverSurface1);
211 QVERIFY(selectionClearedClient1Spy.wait());
214 std::unique_ptr<KWayland::Client::DataSource> dataSource(m_client1.ddm->createDataSource());
215 dataSource->offer(QStringLiteral(
"text/plain"));
216 m_client1.dataDevice->setSelection(keyboardEnteredClient1Spy.first().first().value<quint32>(), dataSource.get());
219 QSignalSpy selectionOfferedClient2Spy(m_client2.dataDevice, &KWayland::Client::DataDevice::selectionOffered);
220 QSignalSpy selectionClearedClient2Spy(m_client2.dataDevice, &KWayland::Client::DataDevice::selectionCleared);
221 QSignalSpy keyboardEnteredClient2Spy(m_client2.keyboard, &KWayland::Client::Keyboard::entered);
222 std::unique_ptr<KWayland::Client::Surface> s2(m_client2.compositor->createSurface());
223 QVERIFY(surfaceCreatedSpy.wait());
224 auto serverSurface2 = surfaceCreatedSpy.last().first().value<
SurfaceInterface *>();
225 QVERIFY(serverSurface2);
229 QVERIFY(selectionOfferedClient2Spy.wait());
230 QVERIFY(selectionClearedClient2Spy.isEmpty());
233 std::unique_ptr<KWayland::Client::DataSource> dataSource2(m_client2.ddm->createDataSource());
234 m_client2.dataDevice->setSelection(keyboardEnteredClient2Spy.first().first().value<quint32>(), dataSource2.get());
235 QVERIFY(selectionOfferedClient2Spy.wait());
237 m_client2.dataDevice->clearSelection(keyboardEnteredClient2Spy.first().first().value<quint32>());
238 QVERIFY(selectionClearedClient2Spy.wait());
243 QVERIFY(selectionClearedClient1Spy.wait());
247#include "test_selection.moc"
void surfaceCreated(KWin::SurfaceInterface *surface)
Represents the Global for wl_data_device_manager interface.
Class holding the Wayland server display loop.
bool addSocketName(const QString &name=QString())
Represents a Seat on the Wayland Display.
void setHasKeyboard(bool has)
void setFocusedKeyboardSurface(SurfaceInterface *surface)
Resource representing a wl_surface.
KWayland::Client::Registry * registry
#define CLEANUP(variable)