Changeset View
Changeset View
Standalone View
Standalone View
input.cpp
Show First 20 Lines • Show All 549 Lines • ▼ Show 20 Line(s) | 549 | if (!m_active) { | |||
---|---|---|---|---|---|
550 | return false; | 550 | return false; | ||
551 | } | 551 | } | ||
552 | switch (event->type()) { | 552 | switch (event->type()) { | ||
553 | case QEvent::MouseButtonRelease: | 553 | case QEvent::MouseButtonRelease: | ||
554 | if (event->buttons() == Qt::NoButton) { | 554 | if (event->buttons() == Qt::NoButton) { | ||
555 | if (event->button() == Qt::RightButton) { | 555 | if (event->button() == Qt::RightButton) { | ||
556 | cancel(); | 556 | cancel(); | ||
557 | } else { | 557 | } else { | ||
558 | accept(); | 558 | accept(event->globalPos()); | ||
559 | } | 559 | } | ||
560 | } | 560 | } | ||
561 | break; | 561 | break; | ||
562 | default: | 562 | default: | ||
563 | break; | 563 | break; | ||
564 | } | 564 | } | ||
565 | return true; | 565 | return true; | ||
566 | } | 566 | } | ||
Show All 12 Lines | 572 | bool keyEvent(QKeyEvent *event) override { | |||
579 | 579 | | |||
580 | if (event->type() == QEvent::KeyPress) { | 580 | if (event->type() == QEvent::KeyPress) { | ||
581 | // x11 variant does this on key press, so do the same | 581 | // x11 variant does this on key press, so do the same | ||
582 | if (event->key() == Qt::Key_Escape) { | 582 | if (event->key() == Qt::Key_Escape) { | ||
583 | cancel(); | 583 | cancel(); | ||
584 | } else if (event->key() == Qt::Key_Enter || | 584 | } else if (event->key() == Qt::Key_Enter || | ||
585 | event->key() == Qt::Key_Return || | 585 | event->key() == Qt::Key_Return || | ||
586 | event->key() == Qt::Key_Space) { | 586 | event->key() == Qt::Key_Space) { | ||
587 | accept(); | 587 | accept(input()->globalPointer()); | ||
588 | } | 588 | } | ||
589 | if (input()->supportsPointerWarping()) { | 589 | if (input()->supportsPointerWarping()) { | ||
590 | int mx = 0; | 590 | int mx = 0; | ||
591 | int my = 0; | 591 | int my = 0; | ||
592 | if (event->key() == Qt::Key_Left) { | 592 | if (event->key() == Qt::Key_Left) { | ||
593 | mx = -10; | 593 | mx = -10; | ||
594 | } | 594 | } | ||
595 | if (event->key() == Qt::Key_Right) { | 595 | if (event->key() == Qt::Key_Right) { | ||
Show All 11 Lines | |||||
607 | } | 607 | } | ||
608 | input()->warpPointer(input()->globalPointer() + QPointF(mx, my)); | 608 | input()->warpPointer(input()->globalPointer() + QPointF(mx, my)); | ||
609 | } | 609 | } | ||
610 | } | 610 | } | ||
611 | // filter out while selecting a window | 611 | // filter out while selecting a window | ||
612 | return true; | 612 | return true; | ||
613 | } | 613 | } | ||
614 | 614 | | |||
615 | bool touchDown(quint32 id, const QPointF &pos, quint32 time) override { | ||||
616 | Q_UNUSED(time) | ||||
617 | if (!isActive()) { | ||||
618 | return false; | ||||
619 | } | ||||
620 | m_touchPoints.insert(id, pos); | ||||
621 | return true; | ||||
622 | } | ||||
623 | | ||||
624 | bool touchMotion(quint32 id, const QPointF &pos, quint32 time) override { | ||||
625 | Q_UNUSED(time) | ||||
626 | if (!isActive()) { | ||||
627 | return false; | ||||
628 | } | ||||
629 | auto it = m_touchPoints.find(id); | ||||
630 | if (it != m_touchPoints.end()) { | ||||
631 | *it = pos; | ||||
632 | } | ||||
633 | return true; | ||||
634 | } | ||||
635 | | ||||
636 | bool touchUp(quint32 id, quint32 time) override { | ||||
637 | Q_UNUSED(time) | ||||
638 | if (!isActive()) { | ||||
639 | return false; | ||||
640 | } | ||||
641 | auto it = m_touchPoints.find(id); | ||||
642 | if (it != m_touchPoints.end()) { | ||||
643 | const auto pos = it.value(); | ||||
644 | m_touchPoints.erase(it); | ||||
645 | if (m_touchPoints.isEmpty()) { | ||||
646 | accept(pos); | ||||
647 | } | ||||
648 | } | ||||
649 | return true; | ||||
650 | } | ||||
651 | | ||||
615 | bool isActive() const { | 652 | bool isActive() const { | ||
616 | return m_active; | 653 | return m_active; | ||
617 | } | 654 | } | ||
618 | void start(std::function<void(KWin::Toplevel*)> callback) { | 655 | void start(std::function<void(KWin::Toplevel*)> callback) { | ||
619 | Q_ASSERT(!m_active); | 656 | Q_ASSERT(!m_active); | ||
620 | m_active = true; | 657 | m_active = true; | ||
621 | m_callback = callback; | 658 | m_callback = callback; | ||
622 | input()->keyboard()->update(); | 659 | input()->keyboard()->update(); | ||
660 | input()->cancelTouch(); | ||||
623 | } | 661 | } | ||
624 | void start(std::function<void(const QPoint &)> callback) { | 662 | void start(std::function<void(const QPoint &)> callback) { | ||
625 | Q_ASSERT(!m_active); | 663 | Q_ASSERT(!m_active); | ||
626 | m_active = true; | 664 | m_active = true; | ||
627 | m_pointSelectionFallback = callback; | 665 | m_pointSelectionFallback = callback; | ||
628 | input()->keyboard()->update(); | 666 | input()->keyboard()->update(); | ||
667 | input()->cancelTouch(); | ||||
629 | } | 668 | } | ||
630 | private: | 669 | private: | ||
631 | void deactivate() { | 670 | void deactivate() { | ||
632 | m_active = false; | 671 | m_active = false; | ||
633 | m_callback = std::function<void(KWin::Toplevel*)>(); | 672 | m_callback = std::function<void(KWin::Toplevel*)>(); | ||
634 | m_pointSelectionFallback = std::function<void(const QPoint &)>(); | 673 | m_pointSelectionFallback = std::function<void(const QPoint &)>(); | ||
635 | input()->pointer()->removeWindowSelectionCursor(); | 674 | input()->pointer()->removeWindowSelectionCursor(); | ||
636 | input()->keyboard()->update(); | 675 | input()->keyboard()->update(); | ||
676 | m_touchPoints.clear(); | ||||
637 | } | 677 | } | ||
638 | void cancel() { | 678 | void cancel() { | ||
639 | if (m_callback) { | 679 | if (m_callback) { | ||
640 | m_callback(nullptr); | 680 | m_callback(nullptr); | ||
641 | } | 681 | } | ||
642 | if (m_pointSelectionFallback) { | 682 | if (m_pointSelectionFallback) { | ||
643 | m_pointSelectionFallback(QPoint(-1, -1)); | 683 | m_pointSelectionFallback(QPoint(-1, -1)); | ||
644 | } | 684 | } | ||
645 | deactivate(); | 685 | deactivate(); | ||
646 | } | 686 | } | ||
647 | void accept() { | 687 | void accept(const QPoint &pos) { | ||
648 | if (m_callback) { | 688 | if (m_callback) { | ||
649 | // TODO: this ignores shaped windows | 689 | // TODO: this ignores shaped windows | ||
650 | m_callback(input()->findToplevel(input()->globalPointer().toPoint())); | 690 | m_callback(input()->findToplevel(pos)); | ||
651 | } | 691 | } | ||
652 | if (m_pointSelectionFallback) { | 692 | if (m_pointSelectionFallback) { | ||
653 | m_pointSelectionFallback(input()->globalPointer().toPoint()); | 693 | m_pointSelectionFallback(pos); | ||
654 | } | 694 | } | ||
655 | deactivate(); | 695 | deactivate(); | ||
656 | } | 696 | } | ||
697 | void accept(const QPointF &pos) { | ||||
698 | accept(pos.toPoint()); | ||||
699 | } | ||||
657 | bool m_active = false; | 700 | bool m_active = false; | ||
658 | std::function<void(KWin::Toplevel*)> m_callback; | 701 | std::function<void(KWin::Toplevel*)> m_callback; | ||
659 | std::function<void(const QPoint &)> m_pointSelectionFallback; | 702 | std::function<void(const QPoint &)> m_pointSelectionFallback; | ||
703 | QMap<quint32, QPointF> m_touchPoints; | ||||
660 | }; | 704 | }; | ||
661 | 705 | | |||
662 | class GlobalShortcutFilter : public InputEventFilter { | 706 | class GlobalShortcutFilter : public InputEventFilter { | ||
663 | public: | 707 | public: | ||
664 | bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override { | 708 | bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override { | ||
665 | Q_UNUSED(nativeButton); | 709 | Q_UNUSED(nativeButton); | ||
666 | if (event->type() == QEvent::MouseButtonPress) { | 710 | if (event->type() == QEvent::MouseButtonPress) { | ||
667 | if (input()->shortcuts()->processPointerPressed(event->modifiers(), event->buttons())) { | 711 | if (input()->shortcuts()->processPointerPressed(event->modifiers(), event->buttons())) { | ||
▲ Show 20 Lines • Show All 1381 Lines • Show Last 20 Lines |