Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/decoration_input_test.cpp
Show All 27 Lines | |||||
28 | #include "wayland_server.h" | 28 | #include "wayland_server.h" | ||
29 | #include "workspace.h" | 29 | #include "workspace.h" | ||
30 | #include "shell_client.h" | 30 | #include "shell_client.h" | ||
31 | #include <kwineffects.h> | 31 | #include <kwineffects.h> | ||
32 | #include "decorations/decoratedclient.h" | 32 | #include "decorations/decoratedclient.h" | ||
33 | 33 | | |||
34 | #include <KWayland/Client/connection_thread.h> | 34 | #include <KWayland/Client/connection_thread.h> | ||
35 | #include <KWayland/Client/compositor.h> | 35 | #include <KWayland/Client/compositor.h> | ||
36 | #include <KWayland/Client/event_queue.h> | | |||
37 | #include <KWayland/Client/registry.h> | | |||
38 | #include <KWayland/Client/pointer.h> | 36 | #include <KWayland/Client/pointer.h> | ||
39 | #include <KWayland/Client/server_decoration.h> | 37 | #include <KWayland/Client/server_decoration.h> | ||
40 | #include <KWayland/Client/shell.h> | 38 | #include <KWayland/Client/shell.h> | ||
41 | #include <KWayland/Client/seat.h> | 39 | #include <KWayland/Client/seat.h> | ||
42 | #include <KWayland/Client/shm_pool.h> | 40 | #include <KWayland/Client/shm_pool.h> | ||
43 | #include <KWayland/Client/surface.h> | 41 | #include <KWayland/Client/surface.h> | ||
44 | 42 | | |||
45 | #include <KDecoration2/Decoration> | 43 | #include <KDecoration2/Decoration> | ||
Show All 23 Lines | 57 | private Q_SLOTS: | |||
69 | void testHover(); | 67 | void testHover(); | ||
70 | void testPressToMove_data(); | 68 | void testPressToMove_data(); | ||
71 | void testPressToMove(); | 69 | void testPressToMove(); | ||
72 | void testTapToMove_data(); | 70 | void testTapToMove_data(); | ||
73 | void testTapToMove(); | 71 | void testTapToMove(); | ||
74 | 72 | | |||
75 | private: | 73 | private: | ||
76 | AbstractClient *showWindow(); | 74 | AbstractClient *showWindow(); | ||
77 | KWayland::Client::ConnectionThread *m_connection = nullptr; | | |||
78 | KWayland::Client::Compositor *m_compositor = nullptr; | | |||
79 | KWayland::Client::ServerSideDecorationManager *m_deco = nullptr; | | |||
80 | KWayland::Client::Seat *m_seat = nullptr; | | |||
81 | KWayland::Client::ShmPool *m_shm = nullptr; | | |||
82 | KWayland::Client::Shell *m_shell = nullptr; | | |||
83 | KWayland::Client::EventQueue *m_queue = nullptr; | | |||
84 | QThread *m_thread = nullptr; | | |||
85 | }; | 75 | }; | ||
86 | 76 | | |||
87 | #define MOTION(target) \ | 77 | #define MOTION(target) \ | ||
88 | kwinApp()->platform()->pointerMotion(target, timestamp++) | 78 | kwinApp()->platform()->pointerMotion(target, timestamp++) | ||
89 | 79 | | |||
90 | #define PRESS \ | 80 | #define PRESS \ | ||
91 | kwinApp()->platform()->pointerButtonPressed(BTN_LEFT, timestamp++) | 81 | kwinApp()->platform()->pointerButtonPressed(BTN_LEFT, timestamp++) | ||
92 | 82 | | |||
93 | #define RELEASE \ | 83 | #define RELEASE \ | ||
94 | kwinApp()->platform()->pointerButtonReleased(BTN_LEFT, timestamp++) | 84 | kwinApp()->platform()->pointerButtonReleased(BTN_LEFT, timestamp++) | ||
95 | 85 | | |||
96 | AbstractClient *DecorationInputTest::showWindow() | 86 | AbstractClient *DecorationInputTest::showWindow() | ||
97 | { | 87 | { | ||
98 | using namespace KWayland::Client; | 88 | using namespace KWayland::Client; | ||
99 | #define VERIFY(statement) \ | 89 | #define VERIFY(statement) \ | ||
100 | if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ | 90 | if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ | ||
101 | return nullptr; | 91 | return nullptr; | ||
102 | #define COMPARE(actual, expected) \ | 92 | #define COMPARE(actual, expected) \ | ||
103 | if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ | 93 | if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ | ||
104 | return nullptr; | 94 | return nullptr; | ||
105 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | 95 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | ||
106 | VERIFY(clientAddedSpy.isValid()); | 96 | VERIFY(clientAddedSpy.isValid()); | ||
107 | 97 | | |||
108 | Surface *surface = m_compositor->createSurface(m_compositor); | 98 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||
109 | VERIFY(surface); | 99 | VERIFY(surface); | ||
110 | ShellSurface *shellSurface = m_shell->createSurface(surface, surface); | 100 | ShellSurface *shellSurface = Test::createShellSurface(surface, surface); | ||
111 | VERIFY(shellSurface); | 101 | VERIFY(shellSurface); | ||
112 | auto deco = m_deco->create(surface, surface); | 102 | auto deco = Test::waylandServerSideDecoration()->create(surface, surface); | ||
113 | QSignalSpy decoSpy(deco, &ServerSideDecoration::modeChanged); | 103 | QSignalSpy decoSpy(deco, &ServerSideDecoration::modeChanged); | ||
114 | VERIFY(decoSpy.isValid()); | 104 | VERIFY(decoSpy.isValid()); | ||
115 | VERIFY(decoSpy.wait()); | 105 | VERIFY(decoSpy.wait()); | ||
116 | deco->requestMode(ServerSideDecoration::Mode::Server); | 106 | deco->requestMode(ServerSideDecoration::Mode::Server); | ||
117 | VERIFY(decoSpy.wait()); | 107 | VERIFY(decoSpy.wait()); | ||
118 | COMPARE(deco->mode(), ServerSideDecoration::Mode::Server); | 108 | COMPARE(deco->mode(), ServerSideDecoration::Mode::Server); | ||
119 | // let's render | 109 | // let's render | ||
120 | QImage img(QSize(500, 50), QImage::Format_ARGB32); | 110 | Test::render(surface, QSize(500, 50), Qt::blue); | ||
121 | img.fill(Qt::blue); | | |||
122 | surface->attachBuffer(m_shm->createBuffer(img)); | | |||
123 | surface->damage(QRect(0, 0, 500, 50)); | | |||
124 | surface->commit(Surface::CommitFlag::None); | | |||
125 | 111 | | |||
126 | m_connection->flush(); | 112 | Test::flushWaylandConnection(); | ||
127 | VERIFY(clientAddedSpy.wait()); | 113 | VERIFY(clientAddedSpy.wait()); | ||
128 | AbstractClient *c = workspace()->activeClient(); | 114 | AbstractClient *c = workspace()->activeClient(); | ||
129 | VERIFY(c); | 115 | VERIFY(c); | ||
130 | COMPARE(clientAddedSpy.first().first().value<ShellClient*>(), c); | 116 | COMPARE(clientAddedSpy.first().first().value<ShellClient*>(), c); | ||
131 | 117 | | |||
132 | #undef VERIFY | 118 | #undef VERIFY | ||
133 | #undef COMPARE | 119 | #undef COMPARE | ||
134 | 120 | | |||
Show All 26 Lines | 125 | { | |||
161 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | 147 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | ||
162 | setenv("QT_QPA_PLATFORM", "wayland", true); | 148 | setenv("QT_QPA_PLATFORM", "wayland", true); | ||
163 | waylandServer()->initWorkspace(); | 149 | waylandServer()->initWorkspace(); | ||
164 | } | 150 | } | ||
165 | 151 | | |||
166 | void DecorationInputTest::init() | 152 | void DecorationInputTest::init() | ||
167 | { | 153 | { | ||
168 | using namespace KWayland::Client; | 154 | using namespace KWayland::Client; | ||
169 | // setup connection | 155 | QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat | Test::AdditionalWaylandInterface::Decoration)); | ||
170 | m_connection = new ConnectionThread; | 156 | QVERIFY(Test::waitForWaylandPointer()); | ||
171 | QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); | | |||
172 | QVERIFY(connectedSpy.isValid()); | | |||
173 | m_connection->setSocketName(s_socketName); | | |||
174 | | ||||
175 | m_thread = new QThread(this); | | |||
176 | m_connection->moveToThread(m_thread); | | |||
177 | m_thread->start(); | | |||
178 | | ||||
179 | m_connection->initConnection(); | | |||
180 | QVERIFY(connectedSpy.wait()); | | |||
181 | | ||||
182 | m_queue = new EventQueue(this); | | |||
183 | QVERIFY(!m_queue->isValid()); | | |||
184 | m_queue->setup(m_connection); | | |||
185 | QVERIFY(m_queue->isValid()); | | |||
186 | | ||||
187 | Registry registry; | | |||
188 | registry.setEventQueue(m_queue); | | |||
189 | QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); | | |||
190 | QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); | | |||
191 | QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); | | |||
192 | QSignalSpy seatSpy(®istry, &Registry::seatAnnounced); | | |||
193 | QSignalSpy decorationSpy(®istry, &Registry::serverSideDecorationManagerAnnounced); | | |||
194 | QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); | | |||
195 | QVERIFY(allAnnounced.isValid()); | | |||
196 | QVERIFY(shmSpy.isValid()); | | |||
197 | QVERIFY(shellSpy.isValid()); | | |||
198 | QVERIFY(compositorSpy.isValid()); | | |||
199 | QVERIFY(seatSpy.isValid()); | | |||
200 | QVERIFY(decorationSpy.isValid()); | | |||
201 | registry.create(m_connection->display()); | | |||
202 | QVERIFY(registry.isValid()); | | |||
203 | registry.setup(); | | |||
204 | QVERIFY(allAnnounced.wait()); | | |||
205 | QVERIFY(!compositorSpy.isEmpty()); | | |||
206 | QVERIFY(!shmSpy.isEmpty()); | | |||
207 | QVERIFY(!shellSpy.isEmpty()); | | |||
208 | QVERIFY(!seatSpy.isEmpty()); | | |||
209 | QVERIFY(!decorationSpy.isEmpty()); | | |||
210 | | ||||
211 | m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this); | | |||
212 | QVERIFY(m_compositor->isValid()); | | |||
213 | m_shm = registry.createShmPool(shmSpy.first().first().value<quint32>(), shmSpy.first().last().value<quint32>(), this); | | |||
214 | QVERIFY(m_shm->isValid()); | | |||
215 | m_shell = registry.createShell(shellSpy.first().first().value<quint32>(), shellSpy.first().last().value<quint32>(), this); | | |||
216 | QVERIFY(m_shell->isValid()); | | |||
217 | m_seat = registry.createSeat(seatSpy.first().first().value<quint32>(), seatSpy.first().last().value<quint32>(), this); | | |||
218 | QVERIFY(m_seat->isValid()); | | |||
219 | m_deco = registry.createServerSideDecorationManager(decorationSpy.first().first().value<quint32>(), decorationSpy.first().last().value<quint32>()); | | |||
220 | QVERIFY(m_deco->isValid()); | | |||
221 | QSignalSpy hasPointerSpy(m_seat, &Seat::hasPointerChanged); | | |||
222 | QVERIFY(hasPointerSpy.isValid()); | | |||
223 | QVERIFY(hasPointerSpy.wait()); | | |||
224 | 157 | | |||
225 | screens()->setCurrent(0); | 158 | screens()->setCurrent(0); | ||
226 | Cursor::setPos(QPoint(640, 512)); | 159 | Cursor::setPos(QPoint(640, 512)); | ||
227 | } | 160 | } | ||
228 | 161 | | |||
229 | void DecorationInputTest::cleanup() | 162 | void DecorationInputTest::cleanup() | ||
230 | { | 163 | { | ||
231 | delete m_compositor; | 164 | Test::destroyWaylandConnection(); | ||
232 | m_compositor = nullptr; | | |||
233 | delete m_deco; | | |||
234 | m_deco = nullptr; | | |||
235 | delete m_seat; | | |||
236 | m_seat = nullptr; | | |||
237 | delete m_shm; | | |||
238 | m_shm = nullptr; | | |||
239 | delete m_shell; | | |||
240 | m_shell = nullptr; | | |||
241 | delete m_queue; | | |||
242 | m_queue = nullptr; | | |||
243 | if (m_thread) { | | |||
244 | m_connection->deleteLater(); | | |||
245 | m_thread->quit(); | | |||
246 | m_thread->wait(); | | |||
247 | delete m_thread; | | |||
248 | m_thread = nullptr; | | |||
249 | m_connection = nullptr; | | |||
250 | } | | |||
251 | } | 165 | } | ||
252 | 166 | | |||
253 | void DecorationInputTest::testAxis_data() | 167 | void DecorationInputTest::testAxis_data() | ||
254 | { | 168 | { | ||
255 | QTest::addColumn<QPoint>("decoPoint"); | 169 | QTest::addColumn<QPoint>("decoPoint"); | ||
256 | QTest::addColumn<Qt::WindowFrameSection>("expectedSection"); | 170 | QTest::addColumn<Qt::WindowFrameSection>("expectedSection"); | ||
257 | 171 | | |||
258 | QTest::newRow("topLeft") << QPoint(0, 0) << Qt::TopLeftSection; | 172 | QTest::newRow("topLeft") << QPoint(0, 0) << Qt::TopLeftSection; | ||
▲ Show 20 Lines • Show All 301 Lines • Show Last 20 Lines |