Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/window_selection_test.cpp
Show All 28 Lines | |||||
29 | 29 | | |||
30 | #include <KWayland/Client/compositor.h> | 30 | #include <KWayland/Client/compositor.h> | ||
31 | #include <KWayland/Client/keyboard.h> | 31 | #include <KWayland/Client/keyboard.h> | ||
32 | #include <KWayland/Client/pointer.h> | 32 | #include <KWayland/Client/pointer.h> | ||
33 | #include <KWayland/Client/shell.h> | 33 | #include <KWayland/Client/shell.h> | ||
34 | #include <KWayland/Client/seat.h> | 34 | #include <KWayland/Client/seat.h> | ||
35 | #include <KWayland/Client/shm_pool.h> | 35 | #include <KWayland/Client/shm_pool.h> | ||
36 | #include <KWayland/Client/surface.h> | 36 | #include <KWayland/Client/surface.h> | ||
37 | #include <KWayland/Client/touch.h> | ||||
37 | 38 | | |||
38 | #include <linux/input.h> | 39 | #include <linux/input.h> | ||
39 | 40 | | |||
40 | using namespace KWin; | 41 | using namespace KWin; | ||
41 | using namespace KWayland::Client; | 42 | using namespace KWayland::Client; | ||
42 | 43 | | |||
43 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_window_selection-0"); | 44 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_window_selection-0"); | ||
44 | 45 | | |||
45 | class TestWindowSelection : public QObject | 46 | class TestWindowSelection : public QObject | ||
46 | { | 47 | { | ||
47 | Q_OBJECT | 48 | Q_OBJECT | ||
48 | private Q_SLOTS: | 49 | private Q_SLOTS: | ||
49 | void initTestCase(); | 50 | void initTestCase(); | ||
50 | void init(); | 51 | void init(); | ||
51 | void cleanup(); | 52 | void cleanup(); | ||
52 | 53 | | |||
53 | void testSelectOnWindowPointer(); | 54 | void testSelectOnWindowPointer(); | ||
54 | void testSelectOnWindowKeyboard_data(); | 55 | void testSelectOnWindowKeyboard_data(); | ||
55 | void testSelectOnWindowKeyboard(); | 56 | void testSelectOnWindowKeyboard(); | ||
57 | void testSelectOnWindowTouch(); | ||||
56 | void testCancelOnWindowPointer(); | 58 | void testCancelOnWindowPointer(); | ||
57 | void testCancelOnWindowKeyboard(); | 59 | void testCancelOnWindowKeyboard(); | ||
58 | 60 | | |||
59 | void testSelectPointPointer(); | 61 | void testSelectPointPointer(); | ||
62 | void testSelectPointTouch(); | ||||
60 | }; | 63 | }; | ||
61 | 64 | | |||
62 | void TestWindowSelection::initTestCase() | 65 | void TestWindowSelection::initTestCase() | ||
63 | { | 66 | { | ||
64 | qRegisterMetaType<KWin::ShellClient*>(); | 67 | qRegisterMetaType<KWin::ShellClient*>(); | ||
65 | qRegisterMetaType<KWin::AbstractClient*>(); | 68 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
66 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 69 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
67 | QVERIFY(workspaceCreatedSpy.isValid()); | 70 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Line(s) | 184 | { | |||
244 | } | 247 | } | ||
245 | QCOMPARE(pointerLeftSpy.count(), 0); | 248 | QCOMPARE(pointerLeftSpy.count(), 0); | ||
246 | QCOMPARE(keyboardLeftSpy.count(), 1); | 249 | QCOMPARE(keyboardLeftSpy.count(), 1); | ||
247 | QCOMPARE(pointerEnteredSpy.count(), 1); | 250 | QCOMPARE(pointerEnteredSpy.count(), 1); | ||
248 | QCOMPARE(keyboardEnteredSpy.count(), 2); | 251 | QCOMPARE(keyboardEnteredSpy.count(), 2); | ||
249 | kwinApp()->platform()->keyboardKeyReleased(key, timestamp++); | 252 | kwinApp()->platform()->keyboardKeyReleased(key, timestamp++); | ||
250 | } | 253 | } | ||
251 | 254 | | |||
255 | void TestWindowSelection::testSelectOnWindowTouch() | ||||
256 | { | ||||
257 | // this test verifies window selection through touch | ||||
258 | QScopedPointer<Touch> touch(Test::waylandSeat()->createTouch()); | ||||
259 | QSignalSpy touchStartedSpy(touch.data(), &Touch::sequenceStarted); | ||||
260 | QVERIFY(touchStartedSpy.isValid()); | ||||
261 | QSignalSpy touchCanceledSpy(touch.data(), &Touch::sequenceCanceled); | ||||
262 | QVERIFY(touchCanceledSpy.isValid()); | ||||
263 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
264 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | ||||
265 | auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
266 | QVERIFY(client); | ||||
267 | | ||||
268 | Toplevel *selectedWindow = nullptr; | ||||
269 | auto callback = [&selectedWindow] (Toplevel *t) { | ||||
270 | selectedWindow = t; | ||||
271 | }; | ||||
272 | | ||||
273 | // start the interaction | ||||
274 | QCOMPARE(input()->isSelectingWindow(), false); | ||||
275 | kwinApp()->platform()->startInteractiveWindowSelection(callback); | ||||
276 | QCOMPARE(input()->isSelectingWindow(), true); | ||||
277 | QVERIFY(!selectedWindow); | ||||
278 | | ||||
279 | // simulate touch down | ||||
280 | quint32 timestamp = 0; | ||||
281 | kwinApp()->platform()->touchDown(0, client->geometry().center(), timestamp++); | ||||
282 | QVERIFY(!selectedWindow); | ||||
283 | kwinApp()->platform()->touchUp(0, timestamp++); | ||||
284 | QCOMPARE(input()->isSelectingWindow(), false); | ||||
285 | QCOMPARE(selectedWindow, client); | ||||
286 | | ||||
287 | // with movement | ||||
288 | selectedWindow = nullptr; | ||||
289 | kwinApp()->platform()->startInteractiveWindowSelection(callback); | ||||
290 | kwinApp()->platform()->touchDown(0, client->geometry().bottomRight() + QPoint(20, 20), timestamp++); | ||||
291 | QVERIFY(!selectedWindow); | ||||
292 | kwinApp()->platform()->touchMotion(0, client->geometry().bottomRight() - QPoint(1, 1), timestamp++); | ||||
293 | QVERIFY(!selectedWindow); | ||||
294 | kwinApp()->platform()->touchUp(0, timestamp++); | ||||
295 | QCOMPARE(selectedWindow, client); | ||||
296 | QCOMPARE(input()->isSelectingWindow(), false); | ||||
297 | | ||||
298 | // it cancels active touch sequence on the window | ||||
299 | kwinApp()->platform()->touchDown(0, client->geometry().center(), timestamp++); | ||||
300 | QVERIFY(touchStartedSpy.wait()); | ||||
301 | selectedWindow = nullptr; | ||||
302 | kwinApp()->platform()->startInteractiveWindowSelection(callback); | ||||
303 | QCOMPARE(input()->isSelectingWindow(), true); | ||||
304 | QVERIFY(touchCanceledSpy.wait()); | ||||
305 | QVERIFY(!selectedWindow); | ||||
306 | // this touch up does not yet select the window, it was started prior to the selection | ||||
307 | kwinApp()->platform()->touchUp(0, timestamp++); | ||||
308 | QVERIFY(!selectedWindow); | ||||
309 | kwinApp()->platform()->touchDown(0, client->geometry().center(), timestamp++); | ||||
310 | kwinApp()->platform()->touchUp(0, timestamp++); | ||||
311 | QCOMPARE(selectedWindow, client); | ||||
312 | QCOMPARE(input()->isSelectingWindow(), false); | ||||
313 | | ||||
314 | QCOMPARE(touchStartedSpy.count(), 1); | ||||
315 | QCOMPARE(touchCanceledSpy.count(), 1); | ||||
316 | } | ||||
317 | | ||||
252 | void TestWindowSelection::testCancelOnWindowPointer() | 318 | void TestWindowSelection::testCancelOnWindowPointer() | ||
253 | { | 319 | { | ||
254 | // this test verifies that window selection cancels through right button click | 320 | // this test verifies that window selection cancels through right button click | ||
255 | QScopedPointer<Surface> surface(Test::createSurface()); | 321 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
256 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | 322 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | ||
257 | QScopedPointer<Pointer> pointer(Test::waylandSeat()->createPointer()); | 323 | QScopedPointer<Pointer> pointer(Test::waylandSeat()->createPointer()); | ||
258 | QScopedPointer<Keyboard> keyboard(Test::waylandSeat()->createKeyboard()); | 324 | QScopedPointer<Keyboard> keyboard(Test::waylandSeat()->createKeyboard()); | ||
259 | QSignalSpy pointerEnteredSpy(pointer.data(), &Pointer::entered); | 325 | QSignalSpy pointerEnteredSpy(pointer.data(), &Pointer::entered); | ||
▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Line(s) | 511 | if (keyboardEnteredSpy.count() != 2) { | |||
446 | QVERIFY(keyboardEnteredSpy.wait()); | 512 | QVERIFY(keyboardEnteredSpy.wait()); | ||
447 | } | 513 | } | ||
448 | QCOMPARE(pointerLeftSpy.count(), 1); | 514 | QCOMPARE(pointerLeftSpy.count(), 1); | ||
449 | QCOMPARE(keyboardLeftSpy.count(), 1); | 515 | QCOMPARE(keyboardLeftSpy.count(), 1); | ||
450 | QCOMPARE(pointerEnteredSpy.count(), 2); | 516 | QCOMPARE(pointerEnteredSpy.count(), 2); | ||
451 | QCOMPARE(keyboardEnteredSpy.count(), 2); | 517 | QCOMPARE(keyboardEnteredSpy.count(), 2); | ||
452 | } | 518 | } | ||
453 | 519 | | |||
520 | void TestWindowSelection::testSelectPointTouch() | ||||
521 | { | ||||
522 | // this test verifies point selection through touch works | ||||
523 | QPoint point; | ||||
524 | auto callback = [&point] (const QPoint &p) { | ||||
525 | point = p; | ||||
526 | }; | ||||
527 | | ||||
528 | // start the interaction | ||||
529 | QCOMPARE(input()->isSelectingWindow(), false); | ||||
530 | kwinApp()->platform()->startInteractivePositionSelection(callback); | ||||
531 | QCOMPARE(input()->isSelectingWindow(), true); | ||||
532 | QCOMPARE(point, QPoint()); | ||||
533 | | ||||
534 | // let's create multiple touch points | ||||
535 | quint32 timestamp = 0; | ||||
536 | kwinApp()->platform()->touchDown(0, QPointF(0, 1), timestamp++); | ||||
537 | QCOMPARE(input()->isSelectingWindow(), true); | ||||
538 | kwinApp()->platform()->touchDown(1, QPointF(10, 20), timestamp++); | ||||
539 | QCOMPARE(input()->isSelectingWindow(), true); | ||||
540 | kwinApp()->platform()->touchDown(2, QPointF(30, 40), timestamp++); | ||||
541 | QCOMPARE(input()->isSelectingWindow(), true); | ||||
542 | | ||||
543 | // let's move our points | ||||
544 | kwinApp()->platform()->touchMotion(0, QPointF(5, 10), timestamp++); | ||||
545 | kwinApp()->platform()->touchMotion(2, QPointF(20, 25), timestamp++); | ||||
546 | kwinApp()->platform()->touchMotion(1, QPointF(25, 35), timestamp++); | ||||
547 | QCOMPARE(input()->isSelectingWindow(), true); | ||||
548 | kwinApp()->platform()->touchUp(0, timestamp++); | ||||
549 | QCOMPARE(input()->isSelectingWindow(), true); | ||||
550 | kwinApp()->platform()->touchUp(2, timestamp++); | ||||
551 | QCOMPARE(input()->isSelectingWindow(), true); | ||||
552 | kwinApp()->platform()->touchUp(1, timestamp++); | ||||
553 | QCOMPARE(input()->isSelectingWindow(), false); | ||||
554 | QCOMPARE(point, QPoint(25, 35)); | ||||
555 | } | ||||
556 | | ||||
454 | WAYLANDTEST_MAIN(TestWindowSelection) | 557 | WAYLANDTEST_MAIN(TestWindowSelection) | ||
455 | #include "window_selection_test.moc" | 558 | #include "window_selection_test.moc" |