Changeset View
Changeset View
Standalone View
Standalone View
autotests/test_screen_edges.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | Q_LOGGING_CATEGORY(KWIN_CORE, "kwin_core") | 44 | Q_LOGGING_CATEGORY(KWIN_CORE, "kwin_core") | ||
45 | 45 | | |||
46 | namespace KWin | 46 | namespace KWin | ||
47 | { | 47 | { | ||
48 | 48 | | |||
49 | Atoms* atoms; | 49 | Atoms* atoms; | ||
50 | int screen_number = 0; | 50 | int screen_number = 0; | ||
51 | 51 | | |||
52 | Cursor *Cursor::s_self = nullptr; | | |||
53 | static QPoint s_cursorPos = QPoint(); | | |||
54 | QPoint Cursor::pos() | | |||
55 | { | | |||
56 | return s_cursorPos; | | |||
57 | } | | |||
58 | | ||||
59 | void Cursor::setPos(const QPoint &pos) | | |||
60 | { | | |||
61 | s_cursorPos = pos; | | |||
62 | } | | |||
63 | | ||||
64 | void Cursor::setPos(int x, int y) | | |||
65 | { | | |||
66 | setPos(QPoint(x, y)); | | |||
67 | } | | |||
68 | | ||||
69 | void Cursor::startMousePolling() | | |||
70 | { | | |||
71 | } | | |||
72 | void Cursor::stopMousePolling() | | |||
73 | { | | |||
74 | } | | |||
75 | | ||||
76 | InputRedirection *InputRedirection::s_self = nullptr; | 52 | InputRedirection *InputRedirection::s_self = nullptr; | ||
77 | 53 | | |||
78 | void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action) | 54 | void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action) | ||
79 | { | 55 | { | ||
80 | Q_UNUSED(shortcut) | 56 | Q_UNUSED(shortcut) | ||
81 | Q_UNUSED(action) | 57 | Q_UNUSED(action) | ||
82 | } | 58 | } | ||
83 | 59 | | |||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
144 | 120 | | |||
145 | void TestScreenEdges::cleanupTestCase() | 121 | void TestScreenEdges::cleanupTestCase() | ||
146 | { | 122 | { | ||
147 | delete KWin::atoms; | 123 | delete KWin::atoms; | ||
148 | } | 124 | } | ||
149 | 125 | | |||
150 | void TestScreenEdges::init() | 126 | void TestScreenEdges::init() | ||
151 | { | 127 | { | ||
128 | KWin::Cursors::self()->setMouse(new KWin::Cursor(this)); | ||||
129 | | ||||
152 | using namespace KWin; | 130 | using namespace KWin; | ||
153 | new MockWorkspace; | 131 | new MockWorkspace; | ||
154 | auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); | 132 | auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); | ||
155 | Screens::create(); | 133 | Screens::create(); | ||
156 | 134 | | |||
157 | auto vd = VirtualDesktopManager::create(); | 135 | auto vd = VirtualDesktopManager::create(); | ||
158 | vd->setConfig(config); | 136 | vd->setConfig(config); | ||
159 | vd->load(); | 137 | vd->load(); | ||
▲ Show 20 Lines • Show All 290 Lines • ▼ Show 20 Line(s) | 398 | { | |||
450 | } | 428 | } | ||
451 | auto it = std::find_if(edges.constBegin(), edges.constEnd(), [](Edge *e) { | 429 | auto it = std::find_if(edges.constBegin(), edges.constEnd(), [](Edge *e) { | ||
452 | return e->isScreenEdge() && e->isLeft() && e->approachGeometry().bottom() < 768; | 430 | return e->isScreenEdge() && e->isLeft() && e->approachGeometry().bottom() < 768; | ||
453 | }); | 431 | }); | ||
454 | QVERIFY(it != edges.constEnd()); | 432 | QVERIFY(it != edges.constEnd()); | ||
455 | 433 | | |||
456 | xcb_enter_notify_event_t event; | 434 | xcb_enter_notify_event_t event; | ||
457 | auto setPos = [&event] (const QPoint &pos) { | 435 | auto setPos = [&event] (const QPoint &pos) { | ||
458 | Cursor::setPos(pos); | 436 | Cursors::self()->mouse()->setPos(pos); | ||
459 | event.root_x = pos.x(); | 437 | event.root_x = pos.x(); | ||
460 | event.root_y = pos.y(); | 438 | event.root_y = pos.y(); | ||
461 | event.event_x = pos.x(); | 439 | event.event_x = pos.x(); | ||
462 | event.event_y = pos.y(); | 440 | event.event_y = pos.y(); | ||
463 | }; | 441 | }; | ||
464 | event.root = XCB_WINDOW_NONE; | 442 | event.root = XCB_WINDOW_NONE; | ||
465 | event.child = XCB_WINDOW_NONE; | 443 | event.child = XCB_WINDOW_NONE; | ||
466 | event.event = (*it)->window(); | 444 | event.event = (*it)->window(); | ||
467 | event.same_screen_focus = 1; | 445 | event.same_screen_focus = 1; | ||
468 | event.time = QDateTime::currentMSecsSinceEpoch(); | 446 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
469 | setPos(QPoint(0, 50)); | 447 | setPos(QPoint(0, 50)); | ||
470 | auto isEntered = [s] (xcb_enter_notify_event_t *event) { | 448 | auto isEntered = [s] (xcb_enter_notify_event_t *event) { | ||
471 | return s->handleEnterNotifiy(event->event, QPoint(event->root_x, event->root_y), QDateTime::fromMSecsSinceEpoch(event->time, Qt::UTC)); | 449 | return s->handleEnterNotifiy(event->event, QPoint(event->root_x, event->root_y), QDateTime::fromMSecsSinceEpoch(event->time, Qt::UTC)); | ||
472 | }; | 450 | }; | ||
473 | QVERIFY(isEntered(&event)); | 451 | QVERIFY(isEntered(&event)); | ||
474 | // doesn't trigger as the edge was not triggered yet | 452 | // doesn't trigger as the edge was not triggered yet | ||
475 | QVERIFY(spy.isEmpty()); | 453 | QVERIFY(spy.isEmpty()); | ||
476 | QCOMPARE(Cursor::pos(), QPoint(1, 50)); | 454 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(1, 50)); | ||
477 | 455 | | |||
478 | // test doesn't trigger due to too much offset | 456 | // test doesn't trigger due to too much offset | ||
479 | QTest::qWait(160); | 457 | QTest::qWait(160); | ||
480 | setPos(QPoint(0, 100)); | 458 | setPos(QPoint(0, 100)); | ||
481 | event.time = QDateTime::currentMSecsSinceEpoch(); | 459 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
482 | QVERIFY(isEntered(&event)); | 460 | QVERIFY(isEntered(&event)); | ||
483 | QVERIFY(spy.isEmpty()); | 461 | QVERIFY(spy.isEmpty()); | ||
484 | QCOMPARE(Cursor::pos(), QPoint(1, 100)); | 462 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(1, 100)); | ||
485 | 463 | | |||
486 | // doesn't trigger as we are waiting too long already | 464 | // doesn't trigger as we are waiting too long already | ||
487 | QTest::qWait(200); | 465 | QTest::qWait(200); | ||
488 | setPos(QPoint(0, 101)); | 466 | setPos(QPoint(0, 101)); | ||
489 | event.time = QDateTime::currentMSecsSinceEpoch(); | 467 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
490 | QVERIFY(isEntered(&event)); | 468 | QVERIFY(isEntered(&event)); | ||
491 | QVERIFY(spy.isEmpty()); | 469 | QVERIFY(spy.isEmpty()); | ||
492 | QCOMPARE(Cursor::pos(), QPoint(1, 101)); | 470 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(1, 101)); | ||
493 | 471 | | |||
494 | // doesn't activate as we are waiting too short | 472 | // doesn't activate as we are waiting too short | ||
495 | QTest::qWait(50); | 473 | QTest::qWait(50); | ||
496 | setPos(QPoint(0, 100)); | 474 | setPos(QPoint(0, 100)); | ||
497 | event.time = QDateTime::currentMSecsSinceEpoch(); | 475 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
498 | QVERIFY(isEntered(&event)); | 476 | QVERIFY(isEntered(&event)); | ||
499 | QVERIFY(spy.isEmpty()); | 477 | QVERIFY(spy.isEmpty()); | ||
500 | QCOMPARE(Cursor::pos(), QPoint(1, 100)); | 478 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(1, 100)); | ||
501 | 479 | | |||
502 | // and this one triggers | 480 | // and this one triggers | ||
503 | QTest::qWait(110); | 481 | QTest::qWait(110); | ||
504 | setPos(QPoint(0, 101)); | 482 | setPos(QPoint(0, 101)); | ||
505 | event.time = QDateTime::currentMSecsSinceEpoch(); | 483 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
506 | QVERIFY(isEntered(&event)); | 484 | QVERIFY(isEntered(&event)); | ||
507 | QVERIFY(!spy.isEmpty()); | 485 | QVERIFY(!spy.isEmpty()); | ||
508 | QCOMPARE(Cursor::pos(), QPoint(1, 101)); | 486 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(1, 101)); | ||
509 | 487 | | |||
510 | // now let's try to trigger again | 488 | // now let's try to trigger again | ||
511 | QTest::qWait(351); | 489 | QTest::qWait(351); | ||
512 | setPos(QPoint(0, 100)); | 490 | setPos(QPoint(0, 100)); | ||
513 | event.time = QDateTime::currentMSecsSinceEpoch(); | 491 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
514 | QVERIFY(isEntered(&event)); | 492 | QVERIFY(isEntered(&event)); | ||
515 | QCOMPARE(spy.count(), 1); | 493 | QCOMPARE(spy.count(), 1); | ||
516 | QCOMPARE(Cursor::pos(), QPoint(1, 100)); | 494 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(1, 100)); | ||
517 | // it's still under the reactivation | 495 | // it's still under the reactivation | ||
518 | QTest::qWait(50); | 496 | QTest::qWait(50); | ||
519 | setPos(QPoint(0, 100)); | 497 | setPos(QPoint(0, 100)); | ||
520 | event.time = QDateTime::currentMSecsSinceEpoch(); | 498 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
521 | QVERIFY(isEntered(&event)); | 499 | QVERIFY(isEntered(&event)); | ||
522 | QCOMPARE(spy.count(), 1); | 500 | QCOMPARE(spy.count(), 1); | ||
523 | QCOMPARE(Cursor::pos(), QPoint(1, 100)); | 501 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(1, 100)); | ||
524 | // now it should trigger again | 502 | // now it should trigger again | ||
525 | QTest::qWait(250); | 503 | QTest::qWait(250); | ||
526 | setPos(QPoint(0, 100)); | 504 | setPos(QPoint(0, 100)); | ||
527 | event.time = QDateTime::currentMSecsSinceEpoch(); | 505 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
528 | QVERIFY(isEntered(&event)); | 506 | QVERIFY(isEntered(&event)); | ||
529 | QCOMPARE(spy.count(), 2); | 507 | QCOMPARE(spy.count(), 2); | ||
530 | QCOMPARE(spy.first().first().value<ElectricBorder>(), ElectricLeft); | 508 | QCOMPARE(spy.first().first().value<ElectricBorder>(), ElectricLeft); | ||
531 | QCOMPARE(spy.last().first().value<ElectricBorder>(), ElectricLeft); | 509 | QCOMPARE(spy.last().first().value<ElectricBorder>(), ElectricLeft); | ||
532 | QCOMPARE(Cursor::pos(), QPoint(1, 100)); | 510 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(1, 100)); | ||
533 | 511 | | |||
534 | // let's disable pushback | 512 | // let's disable pushback | ||
535 | auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); | 513 | auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); | ||
536 | config->group("Windows").writeEntry("ElectricBorderPushbackPixels", 0); | 514 | config->group("Windows").writeEntry("ElectricBorderPushbackPixels", 0); | ||
537 | config->sync(); | 515 | config->sync(); | ||
538 | s->setConfig(config); | 516 | s->setConfig(config); | ||
539 | s->reconfigure(); | 517 | s->reconfigure(); | ||
540 | // it should trigger directly | 518 | // it should trigger directly | ||
541 | QTest::qWait(350); | 519 | QTest::qWait(350); | ||
542 | event.time = QDateTime::currentMSecsSinceEpoch(); | 520 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
543 | QVERIFY(isEntered(&event)); | 521 | QVERIFY(isEntered(&event)); | ||
544 | QCOMPARE(spy.count(), 3); | 522 | QCOMPARE(spy.count(), 3); | ||
545 | QCOMPARE(spy.at(0).first().value<ElectricBorder>(), ElectricLeft); | 523 | QCOMPARE(spy.at(0).first().value<ElectricBorder>(), ElectricLeft); | ||
546 | QCOMPARE(spy.at(1).first().value<ElectricBorder>(), ElectricLeft); | 524 | QCOMPARE(spy.at(1).first().value<ElectricBorder>(), ElectricLeft); | ||
547 | QCOMPARE(spy.at(2).first().value<ElectricBorder>(), ElectricLeft); | 525 | QCOMPARE(spy.at(2).first().value<ElectricBorder>(), ElectricLeft); | ||
548 | QCOMPARE(Cursor::pos(), QPoint(0, 100)); | 526 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(0, 100)); | ||
549 | 527 | | |||
550 | // now let's unreserve again | 528 | // now let's unreserve again | ||
551 | s->unreserve(ElectricTopLeft, &callback); | 529 | s->unreserve(ElectricTopLeft, &callback); | ||
552 | s->unreserve(ElectricTop, &callback); | 530 | s->unreserve(ElectricTop, &callback); | ||
553 | s->unreserve(ElectricTopRight, &callback); | 531 | s->unreserve(ElectricTopRight, &callback); | ||
554 | s->unreserve(ElectricRight, &callback); | 532 | s->unreserve(ElectricRight, &callback); | ||
555 | s->unreserve(ElectricBottomRight, &callback); | 533 | s->unreserve(ElectricBottomRight, &callback); | ||
556 | s->unreserve(ElectricBottom, &callback); | 534 | s->unreserve(ElectricBottom, &callback); | ||
Show All 16 Lines | 545 | { | |||
573 | QVERIFY(spy.isValid()); | 551 | QVERIFY(spy.isValid()); | ||
574 | s->reserve(ElectricLeft, &callback, "callback"); | 552 | s->reserve(ElectricLeft, &callback, "callback"); | ||
575 | 553 | | |||
576 | // check activating a different edge doesn't do anything | 554 | // check activating a different edge doesn't do anything | ||
577 | s->check(QPoint(50, 0), QDateTime::currentDateTimeUtc(), true); | 555 | s->check(QPoint(50, 0), QDateTime::currentDateTimeUtc(), true); | ||
578 | QVERIFY(spy.isEmpty()); | 556 | QVERIFY(spy.isEmpty()); | ||
579 | 557 | | |||
580 | // try a direct activate without pushback | 558 | // try a direct activate without pushback | ||
581 | Cursor::setPos(0, 50); | 559 | Cursors::self()->mouse()->setPos(0, 50); | ||
582 | s->check(QPoint(0, 50), QDateTime::currentDateTimeUtc(), true); | 560 | s->check(QPoint(0, 50), QDateTime::currentDateTimeUtc(), true); | ||
583 | QCOMPARE(spy.count(), 1); | 561 | QCOMPARE(spy.count(), 1); | ||
584 | QEXPECT_FAIL("", "Argument says force no pushback, but it gets pushed back. Needs investigation", Continue); | 562 | QEXPECT_FAIL("", "Argument says force no pushback, but it gets pushed back. Needs investigation", Continue); | ||
585 | QCOMPARE(Cursor::pos(), QPoint(0, 50)); | 563 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(0, 50)); | ||
586 | 564 | | |||
587 | // use a different edge, this time with pushback | 565 | // use a different edge, this time with pushback | ||
588 | s->reserve(KWin::ElectricRight, &callback, "callback"); | 566 | s->reserve(KWin::ElectricRight, &callback, "callback"); | ||
589 | Cursor::setPos(99, 50); | 567 | Cursors::self()->mouse()->setPos(99, 50); | ||
590 | s->check(QPoint(99, 50), QDateTime::currentDateTimeUtc()); | 568 | s->check(QPoint(99, 50), QDateTime::currentDateTimeUtc()); | ||
591 | QCOMPARE(spy.count(), 1); | 569 | QCOMPARE(spy.count(), 1); | ||
592 | QCOMPARE(spy.last().first().value<ElectricBorder>(), ElectricLeft); | 570 | QCOMPARE(spy.last().first().value<ElectricBorder>(), ElectricLeft); | ||
593 | QCOMPARE(Cursor::pos(), QPoint(98, 50)); | 571 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(98, 50)); | ||
594 | // and trigger it again | 572 | // and trigger it again | ||
595 | QTest::qWait(160); | 573 | QTest::qWait(160); | ||
596 | Cursor::setPos(99, 50); | 574 | Cursors::self()->mouse()->setPos(99, 50); | ||
597 | s->check(QPoint(99, 50), QDateTime::currentDateTimeUtc()); | 575 | s->check(QPoint(99, 50), QDateTime::currentDateTimeUtc()); | ||
598 | QCOMPARE(spy.count(), 2); | 576 | QCOMPARE(spy.count(), 2); | ||
599 | QCOMPARE(spy.last().first().value<ElectricBorder>(), ElectricRight); | 577 | QCOMPARE(spy.last().first().value<ElectricBorder>(), ElectricRight); | ||
600 | QCOMPARE(Cursor::pos(), QPoint(98, 50)); | 578 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(98, 50)); | ||
601 | } | 579 | } | ||
602 | 580 | | |||
603 | void TestScreenEdges::testPushBack_data() | 581 | void TestScreenEdges::testPushBack_data() | ||
604 | { | 582 | { | ||
605 | QTest::addColumn<KWin::ElectricBorder>("border"); | 583 | QTest::addColumn<KWin::ElectricBorder>("border"); | ||
606 | QTest::addColumn<int>("pushback"); | 584 | QTest::addColumn<int>("pushback"); | ||
607 | QTest::addColumn<QPoint>("trigger"); | 585 | QTest::addColumn<QPoint>("trigger"); | ||
608 | QTest::addColumn<QPoint>("expected"); | 586 | QTest::addColumn<QPoint>("expected"); | ||
Show All 24 Lines | 600 | { | |||
633 | s->init(); | 611 | s->init(); | ||
634 | TestObject callback; | 612 | TestObject callback; | ||
635 | QSignalSpy spy(&callback, &TestObject::gotCallback); | 613 | QSignalSpy spy(&callback, &TestObject::gotCallback); | ||
636 | QVERIFY(spy.isValid()); | 614 | QVERIFY(spy.isValid()); | ||
637 | QFETCH(ElectricBorder, border); | 615 | QFETCH(ElectricBorder, border); | ||
638 | s->reserve(border, &callback, "callback"); | 616 | s->reserve(border, &callback, "callback"); | ||
639 | 617 | | |||
640 | QFETCH(QPoint, trigger); | 618 | QFETCH(QPoint, trigger); | ||
641 | Cursor::setPos(trigger); | 619 | Cursors::self()->mouse()->setPos(trigger); | ||
642 | xcb_enter_notify_event_t event; | 620 | xcb_enter_notify_event_t event; | ||
643 | event.root_x = trigger.x(); | 621 | event.root_x = trigger.x(); | ||
644 | event.root_y = trigger.y(); | 622 | event.root_y = trigger.y(); | ||
645 | event.event_x = trigger.x(); | 623 | event.event_x = trigger.x(); | ||
646 | event.event_y = trigger.y(); | 624 | event.event_y = trigger.y(); | ||
647 | event.root = XCB_WINDOW_NONE; | 625 | event.root = XCB_WINDOW_NONE; | ||
648 | event.child = XCB_WINDOW_NONE; | 626 | event.child = XCB_WINDOW_NONE; | ||
649 | event.event = s->windows().first(); | 627 | event.event = s->windows().first(); | ||
650 | event.same_screen_focus = 1; | 628 | event.same_screen_focus = 1; | ||
651 | event.time = QDateTime::currentMSecsSinceEpoch(); | 629 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
652 | auto isEntered = [s] (xcb_enter_notify_event_t *event) { | 630 | auto isEntered = [s] (xcb_enter_notify_event_t *event) { | ||
653 | return s->handleEnterNotifiy(event->event, QPoint(event->root_x, event->root_y), QDateTime::fromMSecsSinceEpoch(event->time)); | 631 | return s->handleEnterNotifiy(event->event, QPoint(event->root_x, event->root_y), QDateTime::fromMSecsSinceEpoch(event->time)); | ||
654 | }; | 632 | }; | ||
655 | QVERIFY(isEntered(&event)); | 633 | QVERIFY(isEntered(&event)); | ||
656 | QVERIFY(spy.isEmpty()); | 634 | QVERIFY(spy.isEmpty()); | ||
657 | QTEST(Cursor::pos(), "expected"); | 635 | QTEST(Cursors::self()->mouse()->pos(), "expected"); | ||
658 | 636 | | |||
659 | // do the same without the event, but the check method | 637 | // do the same without the event, but the check method | ||
660 | Cursor::setPos(trigger); | 638 | Cursors::self()->mouse()->setPos(trigger); | ||
661 | s->check(trigger, QDateTime::currentDateTimeUtc()); | 639 | s->check(trigger, QDateTime::currentDateTimeUtc()); | ||
662 | QVERIFY(spy.isEmpty()); | 640 | QVERIFY(spy.isEmpty()); | ||
663 | QTEST(Cursor::pos(), "expected"); | 641 | QTEST(Cursors::self()->mouse()->pos(), "expected"); | ||
664 | } | 642 | } | ||
665 | 643 | | |||
666 | void TestScreenEdges::testFullScreenBlocking() | 644 | void TestScreenEdges::testFullScreenBlocking() | ||
667 | { | 645 | { | ||
668 | using namespace KWin; | 646 | using namespace KWin; | ||
669 | MockWorkspace ws; | 647 | MockWorkspace ws; | ||
670 | X11Client client(&ws); | 648 | X11Client client(&ws); | ||
671 | auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); | 649 | auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); | ||
Show All 12 Lines | |||||
684 | s->reserveTouch(KWin::ElectricRight, &action); | 662 | s->reserveTouch(KWin::ElectricRight, &action); | ||
685 | // currently there is no active client yet, so check blocking shouldn't do anything | 663 | // currently there is no active client yet, so check blocking shouldn't do anything | ||
686 | emit s->checkBlocking(); | 664 | emit s->checkBlocking(); | ||
687 | for (auto e: s->findChildren<Edge*>()) { | 665 | for (auto e: s->findChildren<Edge*>()) { | ||
688 | QCOMPARE(e->activatesForTouchGesture(), e->border() == KWin::ElectricRight); | 666 | QCOMPARE(e->activatesForTouchGesture(), e->border() == KWin::ElectricRight); | ||
689 | } | 667 | } | ||
690 | 668 | | |||
691 | xcb_enter_notify_event_t event; | 669 | xcb_enter_notify_event_t event; | ||
692 | Cursor::setPos(0, 50); | 670 | Cursors::self()->mouse()->setPos(0, 50); | ||
693 | event.root_x = 0; | 671 | event.root_x = 0; | ||
694 | event.root_y = 50; | 672 | event.root_y = 50; | ||
695 | event.event_x = 0; | 673 | event.event_x = 0; | ||
696 | event.event_y = 50; | 674 | event.event_y = 50; | ||
697 | event.root = XCB_WINDOW_NONE; | 675 | event.root = XCB_WINDOW_NONE; | ||
698 | event.child = XCB_WINDOW_NONE; | 676 | event.child = XCB_WINDOW_NONE; | ||
699 | event.event = s->windows().first(); | 677 | event.event = s->windows().first(); | ||
700 | event.same_screen_focus = 1; | 678 | event.same_screen_focus = 1; | ||
701 | event.time = QDateTime::currentMSecsSinceEpoch(); | 679 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
702 | auto isEntered = [s] (xcb_enter_notify_event_t *event) { | 680 | auto isEntered = [s] (xcb_enter_notify_event_t *event) { | ||
703 | return s->handleEnterNotifiy(event->event, QPoint(event->root_x, event->root_y), QDateTime::fromMSecsSinceEpoch(event->time)); | 681 | return s->handleEnterNotifiy(event->event, QPoint(event->root_x, event->root_y), QDateTime::fromMSecsSinceEpoch(event->time)); | ||
704 | }; | 682 | }; | ||
705 | QVERIFY(isEntered(&event)); | 683 | QVERIFY(isEntered(&event)); | ||
706 | QVERIFY(spy.isEmpty()); | 684 | QVERIFY(spy.isEmpty()); | ||
707 | QCOMPARE(Cursor::pos(), QPoint(1, 50)); | 685 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(1, 50)); | ||
708 | 686 | | |||
709 | client.setFrameGeometry(screens()->geometry()); | 687 | client.setFrameGeometry(screens()->geometry()); | ||
710 | client.setActive(true); | 688 | client.setActive(true); | ||
711 | client.setFullScreen(true); | 689 | client.setFullScreen(true); | ||
712 | ws.setActiveClient(&client); | 690 | ws.setActiveClient(&client); | ||
713 | emit s->checkBlocking(); | 691 | emit s->checkBlocking(); | ||
714 | // the signal doesn't trigger for corners, let's go over all windows just to be sure that it doesn't call for corners | 692 | // the signal doesn't trigger for corners, let's go over all windows just to be sure that it doesn't call for corners | ||
715 | for (auto e: s->findChildren<Edge*>()) { | 693 | for (auto e: s->findChildren<Edge*>()) { | ||
716 | e->checkBlocking(); | 694 | e->checkBlocking(); | ||
717 | QCOMPARE(e->activatesForTouchGesture(), false); | 695 | QCOMPARE(e->activatesForTouchGesture(), false); | ||
718 | } | 696 | } | ||
719 | // calling again should not trigger | 697 | // calling again should not trigger | ||
720 | QTest::qWait(160); | 698 | QTest::qWait(160); | ||
721 | Cursor::setPos(0, 50); | 699 | Cursors::self()->mouse()->setPos(0, 50); | ||
722 | event.time = QDateTime::currentMSecsSinceEpoch(); | 700 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
723 | QVERIFY(isEntered(&event)); | 701 | QVERIFY(isEntered(&event)); | ||
724 | QVERIFY(spy.isEmpty()); | 702 | QVERIFY(spy.isEmpty()); | ||
725 | // and no pushback | 703 | // and no pushback | ||
726 | QCOMPARE(Cursor::pos(), QPoint(0, 50)); | 704 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(0, 50)); | ||
727 | 705 | | |||
728 | // let's make the client not fullscreen, which should trigger | 706 | // let's make the client not fullscreen, which should trigger | ||
729 | client.setFullScreen(false); | 707 | client.setFullScreen(false); | ||
730 | emit s->checkBlocking(); | 708 | emit s->checkBlocking(); | ||
731 | for (auto e: s->findChildren<Edge*>()) { | 709 | for (auto e: s->findChildren<Edge*>()) { | ||
732 | QCOMPARE(e->activatesForTouchGesture(), e->border() == KWin::ElectricRight); | 710 | QCOMPARE(e->activatesForTouchGesture(), e->border() == KWin::ElectricRight); | ||
733 | } | 711 | } | ||
734 | event.time = QDateTime::currentMSecsSinceEpoch(); | 712 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
735 | QVERIFY(isEntered(&event)); | 713 | QVERIFY(isEntered(&event)); | ||
736 | QVERIFY(!spy.isEmpty()); | 714 | QVERIFY(!spy.isEmpty()); | ||
737 | QCOMPARE(Cursor::pos(), QPoint(1, 50)); | 715 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(1, 50)); | ||
738 | 716 | | |||
739 | // let's make the client fullscreen again, but with a geometry not intersecting the left edge | 717 | // let's make the client fullscreen again, but with a geometry not intersecting the left edge | ||
740 | QTest::qWait(351); | 718 | QTest::qWait(351); | ||
741 | client.setFullScreen(true); | 719 | client.setFullScreen(true); | ||
742 | client.setFrameGeometry(client.frameGeometry().translated(10, 0)); | 720 | client.setFrameGeometry(client.frameGeometry().translated(10, 0)); | ||
743 | emit s->checkBlocking(); | 721 | emit s->checkBlocking(); | ||
744 | spy.clear(); | 722 | spy.clear(); | ||
745 | Cursor::setPos(0, 50); | 723 | Cursors::self()->mouse()->setPos(0, 50); | ||
746 | event.time = QDateTime::currentMSecsSinceEpoch(); | 724 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
747 | QVERIFY(isEntered(&event)); | 725 | QVERIFY(isEntered(&event)); | ||
748 | QVERIFY(spy.isEmpty()); | 726 | QVERIFY(spy.isEmpty()); | ||
749 | // and a pushback | 727 | // and a pushback | ||
750 | QCOMPARE(Cursor::pos(), QPoint(1, 50)); | 728 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(1, 50)); | ||
751 | 729 | | |||
752 | // just to be sure, let's set geometry back | 730 | // just to be sure, let's set geometry back | ||
753 | client.setFrameGeometry(screens()->geometry()); | 731 | client.setFrameGeometry(screens()->geometry()); | ||
754 | emit s->checkBlocking(); | 732 | emit s->checkBlocking(); | ||
755 | Cursor::setPos(0, 50); | 733 | Cursors::self()->mouse()->setPos(0, 50); | ||
756 | QVERIFY(isEntered(&event)); | 734 | QVERIFY(isEntered(&event)); | ||
757 | QVERIFY(spy.isEmpty()); | 735 | QVERIFY(spy.isEmpty()); | ||
758 | // and no pushback | 736 | // and no pushback | ||
759 | QCOMPARE(Cursor::pos(), QPoint(0, 50)); | 737 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(0, 50)); | ||
760 | 738 | | |||
761 | // the corner should always trigger | 739 | // the corner should always trigger | ||
762 | s->unreserve(KWin::ElectricLeft, &callback); | 740 | s->unreserve(KWin::ElectricLeft, &callback); | ||
763 | event.event_x = 99; | 741 | event.event_x = 99; | ||
764 | event.event_y = 99; | 742 | event.event_y = 99; | ||
765 | event.root_x = 99; | 743 | event.root_x = 99; | ||
766 | event.root_y = 99; | 744 | event.root_y = 99; | ||
767 | event.event = s->windows().first(); | 745 | event.event = s->windows().first(); | ||
768 | event.time = QDateTime::currentMSecsSinceEpoch(); | 746 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
769 | Cursor::setPos(99, 99); | 747 | Cursors::self()->mouse()->setPos(99, 99); | ||
770 | QVERIFY(isEntered(&event)); | 748 | QVERIFY(isEntered(&event)); | ||
771 | QVERIFY(spy.isEmpty()); | 749 | QVERIFY(spy.isEmpty()); | ||
772 | // and pushback | 750 | // and pushback | ||
773 | QCOMPARE(Cursor::pos(), QPoint(98, 98)); | 751 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(98, 98)); | ||
774 | QTest::qWait(160); | 752 | QTest::qWait(160); | ||
775 | event.time = QDateTime::currentMSecsSinceEpoch(); | 753 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
776 | Cursor::setPos(99, 99); | 754 | Cursors::self()->mouse()->setPos(99, 99); | ||
777 | QVERIFY(isEntered(&event)); | 755 | QVERIFY(isEntered(&event)); | ||
778 | QVERIFY(!spy.isEmpty()); | 756 | QVERIFY(!spy.isEmpty()); | ||
779 | } | 757 | } | ||
780 | 758 | | |||
781 | void TestScreenEdges::testClientEdge() | 759 | void TestScreenEdges::testClientEdge() | ||
782 | { | 760 | { | ||
783 | using namespace KWin; | 761 | using namespace KWin; | ||
784 | X11Client client(workspace()); | 762 | X11Client client(workspace()); | ||
Show All 22 Lines | |||||
807 | 785 | | |||
808 | // now let's try to set it and activate it | 786 | // now let's try to set it and activate it | ||
809 | client.setFrameGeometry(screens()->geometry()); | 787 | client.setFrameGeometry(screens()->geometry()); | ||
810 | client.setHiddenInternal(true); | 788 | client.setHiddenInternal(true); | ||
811 | s->reserve(&client, KWin::ElectricLeft); | 789 | s->reserve(&client, KWin::ElectricLeft); | ||
812 | QCOMPARE(client.isHiddenInternal(), true); | 790 | QCOMPARE(client.isHiddenInternal(), true); | ||
813 | 791 | | |||
814 | xcb_enter_notify_event_t event; | 792 | xcb_enter_notify_event_t event; | ||
815 | Cursor::setPos(0, 50); | 793 | Cursors::self()->mouse()->setPos(0, 50); | ||
816 | event.root_x = 0; | 794 | event.root_x = 0; | ||
817 | event.root_y = 50; | 795 | event.root_y = 50; | ||
818 | event.event_x = 0; | 796 | event.event_x = 0; | ||
819 | event.event_y = 50; | 797 | event.event_y = 50; | ||
820 | event.root = XCB_WINDOW_NONE; | 798 | event.root = XCB_WINDOW_NONE; | ||
821 | event.child = XCB_WINDOW_NONE; | 799 | event.child = XCB_WINDOW_NONE; | ||
822 | event.event = s->windows().first(); | 800 | event.event = s->windows().first(); | ||
823 | event.same_screen_focus = 1; | 801 | event.same_screen_focus = 1; | ||
824 | event.time = QDateTime::currentMSecsSinceEpoch(); | 802 | event.time = QDateTime::currentMSecsSinceEpoch(); | ||
825 | auto isEntered = [s] (xcb_enter_notify_event_t *event) { | 803 | auto isEntered = [s] (xcb_enter_notify_event_t *event) { | ||
826 | return s->handleEnterNotifiy(event->event, QPoint(event->root_x, event->root_y), QDateTime::fromMSecsSinceEpoch(event->time)); | 804 | return s->handleEnterNotifiy(event->event, QPoint(event->root_x, event->root_y), QDateTime::fromMSecsSinceEpoch(event->time)); | ||
827 | }; | 805 | }; | ||
828 | QVERIFY(isEntered(&event)); | 806 | QVERIFY(isEntered(&event)); | ||
829 | // autohiding panels shall activate instantly | 807 | // autohiding panels shall activate instantly | ||
830 | QCOMPARE(client.isHiddenInternal(), false); | 808 | QCOMPARE(client.isHiddenInternal(), false); | ||
831 | QCOMPARE(Cursor::pos(), QPoint(1, 50)); | 809 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(1, 50)); | ||
832 | 810 | | |||
833 | // now let's reserve the client for each of the edges, in the end for the right one | 811 | // now let's reserve the client for each of the edges, in the end for the right one | ||
834 | client.setHiddenInternal(true); | 812 | client.setHiddenInternal(true); | ||
835 | s->reserve(&client, KWin::ElectricTop); | 813 | s->reserve(&client, KWin::ElectricTop); | ||
836 | s->reserve(&client, KWin::ElectricBottom); | 814 | s->reserve(&client, KWin::ElectricBottom); | ||
837 | QCOMPARE(client.isHiddenInternal(), true); | 815 | QCOMPARE(client.isHiddenInternal(), true); | ||
838 | // corners shouldn't get reserved | 816 | // corners shouldn't get reserved | ||
839 | s->reserve(&client, KWin::ElectricTopLeft); | 817 | s->reserve(&client, KWin::ElectricTopLeft); | ||
Show All 17 Lines | |||||
857 | for (auto e : s->findChildren<Edge*>()) { | 835 | for (auto e : s->findChildren<Edge*>()) { | ||
858 | QVERIFY(!e->client()); | 836 | QVERIFY(!e->client()); | ||
859 | } | 837 | } | ||
860 | QCOMPARE(client.isHiddenInternal(), true); | 838 | QCOMPARE(client.isHiddenInternal(), true); | ||
861 | 839 | | |||
862 | // now let's try to trigger the client showing with the check method instead of enter notify | 840 | // now let's try to trigger the client showing with the check method instead of enter notify | ||
863 | s->reserve(&client, KWin::ElectricTop); | 841 | s->reserve(&client, KWin::ElectricTop); | ||
864 | QCOMPARE(client.isHiddenInternal(), true); | 842 | QCOMPARE(client.isHiddenInternal(), true); | ||
865 | Cursor::setPos(50, 0); | 843 | Cursors::self()->mouse()->setPos(50, 0); | ||
866 | s->check(QPoint(50, 0), QDateTime::currentDateTimeUtc()); | 844 | s->check(QPoint(50, 0), QDateTime::currentDateTimeUtc()); | ||
867 | QCOMPARE(client.isHiddenInternal(), false); | 845 | QCOMPARE(client.isHiddenInternal(), false); | ||
868 | QCOMPARE(Cursor::pos(), QPoint(50, 1)); | 846 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(50, 1)); | ||
869 | 847 | | |||
870 | // unreserve by setting to none edge | 848 | // unreserve by setting to none edge | ||
871 | s->reserve(&client, KWin::ElectricNone); | 849 | s->reserve(&client, KWin::ElectricNone); | ||
872 | // check on previous edge again, should fail | 850 | // check on previous edge again, should fail | ||
873 | client.setHiddenInternal(true); | 851 | client.setHiddenInternal(true); | ||
874 | Cursor::setPos(50, 0); | 852 | Cursors::self()->mouse()->setPos(50, 0); | ||
875 | s->check(QPoint(50, 0), QDateTime::currentDateTimeUtc()); | 853 | s->check(QPoint(50, 0), QDateTime::currentDateTimeUtc()); | ||
876 | QCOMPARE(client.isHiddenInternal(), true); | 854 | QCOMPARE(client.isHiddenInternal(), true); | ||
877 | QCOMPARE(Cursor::pos(), QPoint(50, 0)); | 855 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(50, 0)); | ||
878 | 856 | | |||
879 | // set to windows can cover | 857 | // set to windows can cover | ||
880 | client.setFrameGeometry(screens()->geometry()); | 858 | client.setFrameGeometry(screens()->geometry()); | ||
881 | client.setHiddenInternal(false); | 859 | client.setHiddenInternal(false); | ||
882 | client.setKeepBelow(true); | 860 | client.setKeepBelow(true); | ||
883 | s->reserve(&client, KWin::ElectricLeft); | 861 | s->reserve(&client, KWin::ElectricLeft); | ||
884 | QCOMPARE(client.keepBelow(), true); | 862 | QCOMPARE(client.keepBelow(), true); | ||
885 | QCOMPARE(client.isHiddenInternal(), false); | 863 | QCOMPARE(client.isHiddenInternal(), false); | ||
886 | 864 | | |||
887 | xcb_enter_notify_event_t event2; | 865 | xcb_enter_notify_event_t event2; | ||
888 | Cursor::setPos(0, 50); | 866 | Cursors::self()->mouse()->setPos(0, 50); | ||
889 | event2.root_x = 0; | 867 | event2.root_x = 0; | ||
890 | event2.root_y = 50; | 868 | event2.root_y = 50; | ||
891 | event2.event_x = 0; | 869 | event2.event_x = 0; | ||
892 | event2.event_y = 50; | 870 | event2.event_y = 50; | ||
893 | event2.root = XCB_WINDOW_NONE; | 871 | event2.root = XCB_WINDOW_NONE; | ||
894 | event2.child = XCB_WINDOW_NONE; | 872 | event2.child = XCB_WINDOW_NONE; | ||
895 | event2.event = s->windows().first(); | 873 | event2.event = s->windows().first(); | ||
896 | event2.same_screen_focus = 1; | 874 | event2.same_screen_focus = 1; | ||
897 | event2.time = QDateTime::currentMSecsSinceEpoch(); | 875 | event2.time = QDateTime::currentMSecsSinceEpoch(); | ||
898 | QVERIFY(isEntered(&event2)); | 876 | QVERIFY(isEntered(&event2)); | ||
899 | QCOMPARE(client.keepBelow(), false); | 877 | QCOMPARE(client.keepBelow(), false); | ||
900 | QCOMPARE(client.isHiddenInternal(), false); | 878 | QCOMPARE(client.isHiddenInternal(), false); | ||
901 | QCOMPARE(Cursor::pos(), QPoint(1, 50)); | 879 | QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(1, 50)); | ||
902 | } | 880 | } | ||
903 | 881 | | |||
904 | void TestScreenEdges::testTouchEdge() | 882 | void TestScreenEdges::testTouchEdge() | ||
905 | { | 883 | { | ||
906 | qRegisterMetaType<KWin::ElectricBorder>("ElectricBorder"); | 884 | qRegisterMetaType<KWin::ElectricBorder>("ElectricBorder"); | ||
907 | using namespace KWin; | 885 | using namespace KWin; | ||
908 | auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); | 886 | auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); | ||
909 | auto group = config->group("TouchEdges"); | 887 | auto group = config->group("TouchEdges"); | ||
Show All 32 Lines | |||||
942 | }); | 920 | }); | ||
943 | QVERIFY(it != edges.constEnd()); | 921 | QVERIFY(it != edges.constEnd()); | ||
944 | 922 | | |||
945 | QSignalSpy approachingSpy(s, &ScreenEdges::approaching); | 923 | QSignalSpy approachingSpy(s, &ScreenEdges::approaching); | ||
946 | QVERIFY(approachingSpy.isValid()); | 924 | QVERIFY(approachingSpy.isValid()); | ||
947 | 925 | | |||
948 | xcb_enter_notify_event_t event; | 926 | xcb_enter_notify_event_t event; | ||
949 | auto setPos = [&event] (const QPoint &pos) { | 927 | auto setPos = [&event] (const QPoint &pos) { | ||
950 | Cursor::setPos(pos); | 928 | Cursors::self()->mouse()->setPos(pos); | ||
951 | event.root_x = pos.x(); | 929 | event.root_x = pos.x(); | ||
952 | event.root_y = pos.y(); | 930 | event.root_y = pos.y(); | ||
953 | event.event_x = pos.x(); | 931 | event.event_x = pos.x(); | ||
954 | event.event_y = pos.y(); | 932 | event.event_y = pos.y(); | ||
955 | }; | 933 | }; | ||
956 | event.root = XCB_WINDOW_NONE; | 934 | event.root = XCB_WINDOW_NONE; | ||
957 | event.child = XCB_WINDOW_NONE; | 935 | event.child = XCB_WINDOW_NONE; | ||
958 | event.event = (*it)->window(); | 936 | event.event = (*it)->window(); | ||
▲ Show 20 Lines • Show All 130 Lines • Show Last 20 Lines |