Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/internal_window.cpp
Show All 22 Lines | |||||
23 | #include "shell_client.h" | 23 | #include "shell_client.h" | ||
24 | #include "screens.h" | 24 | #include "screens.h" | ||
25 | #include "wayland_server.h" | 25 | #include "wayland_server.h" | ||
26 | #include "workspace.h" | 26 | #include "workspace.h" | ||
27 | 27 | | |||
28 | #include <QPainter> | 28 | #include <QPainter> | ||
29 | #include <QRasterWindow> | 29 | #include <QRasterWindow> | ||
30 | 30 | | |||
31 | #include <KWayland/Client/keyboard.h> | ||||
32 | #include <KWayland/Client/surface.h> | ||||
33 | #include <KWayland/Client/seat.h> | ||||
34 | #include <KWayland/Client/shell.h> | ||||
35 | | ||||
31 | #include <linux/input.h> | 36 | #include <linux/input.h> | ||
32 | 37 | | |||
38 | using namespace KWayland::Client; | ||||
39 | | ||||
33 | namespace KWin | 40 | namespace KWin | ||
34 | { | 41 | { | ||
35 | 42 | | |||
36 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_internal_window-0"); | 43 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_internal_window-0"); | ||
37 | 44 | | |||
38 | class InternalWindowTest : public QObject | 45 | class InternalWindowTest : public QObject | ||
39 | { | 46 | { | ||
40 | Q_OBJECT | 47 | Q_OBJECT | ||
41 | private Q_SLOTS: | 48 | private Q_SLOTS: | ||
42 | void initTestCase(); | 49 | void initTestCase(); | ||
43 | void init(); | 50 | void init(); | ||
51 | void cleanup(); | ||||
44 | void testEnterLeave(); | 52 | void testEnterLeave(); | ||
45 | void testPointerPressRelease(); | 53 | void testPointerPressRelease(); | ||
46 | void testPointerAxis(); | 54 | void testPointerAxis(); | ||
47 | void testKeyboard_data(); | 55 | void testKeyboard_data(); | ||
48 | void testKeyboard(); | 56 | void testKeyboard(); | ||
49 | void testTouch(); | 57 | void testTouch(); | ||
50 | }; | 58 | }; | ||
51 | 59 | | |||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Line(s) | 164 | { | |||
168 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | 176 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | ||
169 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | 177 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | ||
170 | waylandServer()->initWorkspace(); | 178 | waylandServer()->initWorkspace(); | ||
171 | } | 179 | } | ||
172 | 180 | | |||
173 | void InternalWindowTest::init() | 181 | void InternalWindowTest::init() | ||
174 | { | 182 | { | ||
175 | Cursor::setPos(QPoint(1280, 512)); | 183 | Cursor::setPos(QPoint(1280, 512)); | ||
184 | QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); | ||||
185 | QVERIFY(Test::waitForWaylandKeyboard()); | ||||
186 | } | ||||
187 | | ||||
188 | void InternalWindowTest::cleanup() | ||||
189 | { | ||||
190 | Test::destroyWaylandConnection(); | ||||
176 | } | 191 | } | ||
177 | 192 | | |||
178 | void InternalWindowTest::testEnterLeave() | 193 | void InternalWindowTest::testEnterLeave() | ||
179 | { | 194 | { | ||
180 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | 195 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | ||
181 | QVERIFY(clientAddedSpy.isValid()); | 196 | QVERIFY(clientAddedSpy.isValid()); | ||
182 | HelperWindow win; | 197 | HelperWindow win; | ||
183 | win.setGeometry(0, 0, 100, 100); | 198 | win.setGeometry(0, 0, 100, 100); | ||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | 291 | { | |||
280 | win.setGeometry(0, 0, 100, 100); | 295 | win.setGeometry(0, 0, 100, 100); | ||
281 | win.show(); | 296 | win.show(); | ||
282 | QSignalSpy pressSpy(&win, &HelperWindow::keyPressed); | 297 | QSignalSpy pressSpy(&win, &HelperWindow::keyPressed); | ||
283 | QVERIFY(pressSpy.isValid()); | 298 | QVERIFY(pressSpy.isValid()); | ||
284 | QSignalSpy releaseSpy(&win, &HelperWindow::keyReleased); | 299 | QSignalSpy releaseSpy(&win, &HelperWindow::keyReleased); | ||
285 | QVERIFY(releaseSpy.isValid()); | 300 | QVERIFY(releaseSpy.isValid()); | ||
286 | QVERIFY(clientAddedSpy.wait()); | 301 | QVERIFY(clientAddedSpy.wait()); | ||
287 | QCOMPARE(clientAddedSpy.count(), 1); | 302 | QCOMPARE(clientAddedSpy.count(), 1); | ||
303 | auto internalClient = clientAddedSpy.first().first().value<ShellClient*>(); | ||||
304 | QVERIFY(internalClient); | ||||
305 | QVERIFY(internalClient->isInternal()); | ||||
288 | 306 | | |||
289 | quint32 timestamp = 1; | 307 | quint32 timestamp = 1; | ||
290 | QFETCH(QPoint, cursorPos); | 308 | QFETCH(QPoint, cursorPos); | ||
291 | kwinApp()->platform()->pointerMotion(cursorPos, timestamp++); | 309 | kwinApp()->platform()->pointerMotion(cursorPos, timestamp++); | ||
292 | 310 | | |||
293 | kwinApp()->platform()->keyboardKeyPressed(KEY_A, timestamp++); | 311 | kwinApp()->platform()->keyboardKeyPressed(KEY_A, timestamp++); | ||
294 | QTRY_COMPARE(pressSpy.count(), 1); | 312 | QTRY_COMPARE(pressSpy.count(), 1); | ||
295 | QCOMPARE(releaseSpy.count(), 0); | 313 | QCOMPARE(releaseSpy.count(), 0); | ||
296 | kwinApp()->platform()->keyboardKeyReleased(KEY_A, timestamp++); | 314 | kwinApp()->platform()->keyboardKeyReleased(KEY_A, timestamp++); | ||
297 | QTRY_COMPARE(releaseSpy.count(), 1); | 315 | QTRY_COMPARE(releaseSpy.count(), 1); | ||
298 | QCOMPARE(pressSpy.count(), 1); | 316 | QCOMPARE(pressSpy.count(), 1); | ||
317 | | ||||
318 | // let's hide the window again and create a "real" window | ||||
319 | win.hide(); | ||||
320 | clientAddedSpy.clear(); | ||||
321 | | ||||
322 | QScopedPointer<Keyboard> keyboard(Test::waylandSeat()->createKeyboard()); | ||||
323 | QVERIFY(!keyboard.isNull()); | ||||
324 | QVERIFY(keyboard->isValid()); | ||||
325 | QSignalSpy enteredSpy(keyboard.data(), &Keyboard::entered); | ||||
326 | QVERIFY(enteredSpy.isValid()); | ||||
327 | QSignalSpy leftSpy(keyboard.data(), &Keyboard::left); | ||||
328 | QVERIFY(leftSpy.isValid()); | ||||
329 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
330 | QScopedPointer<QObject> shellSurface(Test::createShellSurface(Test::ShellSurfaceType::WlShell, surface.data())); | ||||
331 | | ||||
332 | // now let's render | ||||
333 | auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
334 | QVERIFY(c); | ||||
335 | QVERIFY(c->isActive()); | ||||
336 | | ||||
337 | if (enteredSpy.isEmpty()) { | ||||
338 | QVERIFY(enteredSpy.wait()); | ||||
339 | } | ||||
340 | QCOMPARE(enteredSpy.count(), 1); | ||||
341 | | ||||
342 | QSignalSpy windowShownSpy(internalClient, &ShellClient::windowShown); | ||||
343 | QVERIFY(windowShownSpy.isValid()); | ||||
344 | win.show(); | ||||
345 | QCOMPARE(windowShownSpy.count(), 1); | ||||
346 | QVERIFY(leftSpy.isEmpty()); | ||||
347 | QVERIFY(!leftSpy.wait(100)); | ||||
348 | | ||||
349 | // now let's trigger a key, which should result in a leave | ||||
350 | kwinApp()->platform()->keyboardKeyPressed(KEY_A, timestamp++); | ||||
351 | QVERIFY(leftSpy.wait()); | ||||
352 | QCOMPARE(pressSpy.count(), 2); | ||||
353 | | ||||
354 | kwinApp()->platform()->keyboardKeyReleased(KEY_A, timestamp++); | ||||
355 | QTRY_COMPARE(releaseSpy.count(), 2); | ||||
356 | | ||||
357 | // after hiding the internal window, next key press should trigger an enter | ||||
358 | win.hide(); | ||||
359 | kwinApp()->platform()->keyboardKeyPressed(KEY_A, timestamp++); | ||||
360 | QVERIFY(enteredSpy.wait()); | ||||
361 | kwinApp()->platform()->keyboardKeyReleased(KEY_A, timestamp++); | ||||
299 | } | 362 | } | ||
300 | 363 | | |||
301 | void InternalWindowTest::testTouch() | 364 | void InternalWindowTest::testTouch() | ||
302 | { | 365 | { | ||
303 | // touch events for internal windows are emulated through mouse events | 366 | // touch events for internal windows are emulated through mouse events | ||
304 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | 367 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | ||
305 | QVERIFY(clientAddedSpy.isValid()); | 368 | QVERIFY(clientAddedSpy.isValid()); | ||
306 | HelperWindow win; | 369 | HelperWindow win; | ||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |