Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/window_selection_test.cpp
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 48 | private Q_SLOTS: | |||
---|---|---|---|---|---|
50 | void init(); | 50 | void init(); | ||
51 | void cleanup(); | 51 | void cleanup(); | ||
52 | 52 | | |||
53 | void testSelectOnWindowPointer(); | 53 | void testSelectOnWindowPointer(); | ||
54 | void testSelectOnWindowKeyboard_data(); | 54 | void testSelectOnWindowKeyboard_data(); | ||
55 | void testSelectOnWindowKeyboard(); | 55 | void testSelectOnWindowKeyboard(); | ||
56 | void testCancelOnWindowPointer(); | 56 | void testCancelOnWindowPointer(); | ||
57 | void testCancelOnWindowKeyboard(); | 57 | void testCancelOnWindowKeyboard(); | ||
58 | | ||||
59 | void testSelectPointPointer(); | ||||
58 | }; | 60 | }; | ||
59 | 61 | | |||
60 | void TestWindowSelection::initTestCase() | 62 | void TestWindowSelection::initTestCase() | ||
61 | { | 63 | { | ||
62 | qRegisterMetaType<KWin::ShellClient*>(); | 64 | qRegisterMetaType<KWin::ShellClient*>(); | ||
63 | qRegisterMetaType<KWin::AbstractClient*>(); | 65 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
64 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 66 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
65 | QVERIFY(workspaceCreatedSpy.isValid()); | 67 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
▲ Show 20 Lines • Show All 294 Lines • ▼ Show 20 Line(s) | 312 | { | |||
360 | } | 362 | } | ||
361 | QCOMPARE(pointerLeftSpy.count(), 1); | 363 | QCOMPARE(pointerLeftSpy.count(), 1); | ||
362 | QCOMPARE(keyboardLeftSpy.count(), 1); | 364 | QCOMPARE(keyboardLeftSpy.count(), 1); | ||
363 | QCOMPARE(pointerEnteredSpy.count(), 2); | 365 | QCOMPARE(pointerEnteredSpy.count(), 2); | ||
364 | QCOMPARE(keyboardEnteredSpy.count(), 2); | 366 | QCOMPARE(keyboardEnteredSpy.count(), 2); | ||
365 | kwinApp()->platform()->keyboardKeyReleased(KEY_ESC, timestamp++); | 367 | kwinApp()->platform()->keyboardKeyReleased(KEY_ESC, timestamp++); | ||
366 | } | 368 | } | ||
367 | 369 | | |||
370 | void TestWindowSelection::testSelectPointPointer() | ||||
371 | { | ||||
372 | // this test verifies point selection through pointer works | ||||
373 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
374 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | ||||
375 | QScopedPointer<Pointer> pointer(Test::waylandSeat()->createPointer()); | ||||
376 | QScopedPointer<Keyboard> keyboard(Test::waylandSeat()->createKeyboard()); | ||||
377 | QSignalSpy pointerEnteredSpy(pointer.data(), &Pointer::entered); | ||||
378 | QVERIFY(pointerEnteredSpy.isValid()); | ||||
379 | QSignalSpy pointerLeftSpy(pointer.data(), &Pointer::left); | ||||
380 | QVERIFY(pointerLeftSpy.isValid()); | ||||
381 | QSignalSpy keyboardEnteredSpy(keyboard.data(), &Keyboard::entered); | ||||
382 | QVERIFY(keyboardEnteredSpy.isValid()); | ||||
383 | QSignalSpy keyboardLeftSpy(keyboard.data(), &Keyboard::left); | ||||
384 | QVERIFY(keyboardLeftSpy.isValid()); | ||||
385 | | ||||
386 | auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
387 | QVERIFY(client); | ||||
388 | QVERIFY(keyboardEnteredSpy.wait()); | ||||
389 | KWin::Cursor::setPos(client->geometry().center()); | ||||
390 | QCOMPARE(input()->pointer()->window().data(), client); | ||||
391 | QVERIFY(pointerEnteredSpy.wait()); | ||||
392 | | ||||
393 | QPoint point; | ||||
394 | auto callback = [&point] (const QPoint &p) { | ||||
395 | point = p; | ||||
396 | }; | ||||
397 | | ||||
398 | // start the interaction | ||||
399 | QCOMPARE(input()->isSelectingWindow(), false); | ||||
400 | kwinApp()->platform()->startInteractivePositionSelection(callback); | ||||
401 | QCOMPARE(input()->isSelectingWindow(), true); | ||||
402 | QCOMPARE(point, QPoint()); | ||||
403 | QCOMPARE(keyboardLeftSpy.count(), 0); | ||||
404 | QVERIFY(pointerLeftSpy.wait()); | ||||
405 | if (keyboardLeftSpy.isEmpty()) { | ||||
406 | QVERIFY(keyboardLeftSpy.wait()); | ||||
407 | } | ||||
408 | QCOMPARE(pointerLeftSpy.count(), 1); | ||||
409 | QCOMPARE(keyboardLeftSpy.count(), 1); | ||||
410 | | ||||
411 | // trying again should not be allowed | ||||
412 | QPoint point2; | ||||
413 | kwinApp()->platform()->startInteractivePositionSelection([&point2] (const QPoint &p) { | ||||
414 | point2 = p; | ||||
415 | }); | ||||
416 | QCOMPARE(point2, QPoint(-1, -1)); | ||||
417 | | ||||
418 | // simulate left button press | ||||
419 | quint32 timestamp = 0; | ||||
420 | kwinApp()->platform()->pointerButtonPressed(BTN_LEFT, timestamp++); | ||||
421 | // should not have ended the mode | ||||
422 | QCOMPARE(input()->isSelectingWindow(), true); | ||||
423 | QCOMPARE(point, QPoint()); | ||||
424 | QVERIFY(input()->pointer()->window().isNull()); | ||||
425 | | ||||
426 | // updating the pointer should not change anything | ||||
427 | input()->pointer()->update(); | ||||
428 | QVERIFY(input()->pointer()->window().isNull()); | ||||
429 | // updating keyboard should also not change | ||||
430 | input()->keyboard()->update(); | ||||
431 | | ||||
432 | // perform a right button click | ||||
433 | kwinApp()->platform()->pointerButtonPressed(BTN_RIGHT, timestamp++); | ||||
434 | kwinApp()->platform()->pointerButtonReleased(BTN_RIGHT, timestamp++); | ||||
435 | // should not have ended the mode | ||||
436 | QCOMPARE(input()->isSelectingWindow(), true); | ||||
437 | QCOMPARE(point, QPoint()); | ||||
438 | // now release | ||||
439 | kwinApp()->platform()->pointerButtonReleased(BTN_LEFT, timestamp++); | ||||
440 | QCOMPARE(input()->isSelectingWindow(), false); | ||||
441 | QCOMPARE(point, input()->globalPointer().toPoint()); | ||||
442 | QCOMPARE(input()->pointer()->window().data(), client); | ||||
443 | // should give back keyboard and pointer | ||||
444 | QVERIFY(pointerEnteredSpy.wait()); | ||||
445 | if (keyboardEnteredSpy.count() != 2) { | ||||
446 | QVERIFY(keyboardEnteredSpy.wait()); | ||||
447 | } | ||||
448 | QCOMPARE(pointerLeftSpy.count(), 1); | ||||
449 | QCOMPARE(keyboardLeftSpy.count(), 1); | ||||
450 | QCOMPARE(pointerEnteredSpy.count(), 2); | ||||
451 | QCOMPARE(keyboardEnteredSpy.count(), 2); | ||||
452 | } | ||||
453 | | ||||
368 | WAYLANDTEST_MAIN(TestWindowSelection) | 454 | WAYLANDTEST_MAIN(TestWindowSelection) | ||
369 | #include "window_selection_test.moc" | 455 | #include "window_selection_test.moc" |