Changeset View
Changeset View
Standalone View
Standalone View
input.cpp
Show First 20 Lines • Show All 730 Lines • ▼ Show 20 Line(s) | 700 | private: | |||
---|---|---|---|---|---|
731 | bool m_active = false; | 731 | bool m_active = false; | ||
732 | std::function<void(KWin::Toplevel*)> m_callback; | 732 | std::function<void(KWin::Toplevel*)> m_callback; | ||
733 | std::function<void(const QPoint &)> m_pointSelectionFallback; | 733 | std::function<void(const QPoint &)> m_pointSelectionFallback; | ||
734 | QMap<quint32, QPointF> m_touchPoints; | 734 | QMap<quint32, QPointF> m_touchPoints; | ||
735 | }; | 735 | }; | ||
736 | 736 | | |||
737 | class GlobalShortcutFilter : public InputEventFilter { | 737 | class GlobalShortcutFilter : public InputEventFilter { | ||
738 | public: | 738 | public: | ||
739 | GlobalShortcutFilter() { | ||||
740 | m_powerDown = new QTimer; | ||||
741 | m_powerDown->setSingleShot(true); | ||||
742 | m_powerDown->setInterval(1000); | ||||
743 | } | ||||
744 | ~GlobalShortcutFilter() { | ||||
745 | delete m_powerDown; | ||||
746 | } | ||||
747 | | ||||
739 | bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override { | 748 | bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override { | ||
740 | Q_UNUSED(nativeButton); | 749 | Q_UNUSED(nativeButton); | ||
741 | if (event->type() == QEvent::MouseButtonPress) { | 750 | if (event->type() == QEvent::MouseButtonPress) { | ||
742 | if (input()->shortcuts()->processPointerPressed(event->modifiers(), event->buttons())) { | 751 | if (input()->shortcuts()->processPointerPressed(event->modifiers(), event->buttons())) { | ||
743 | return true; | 752 | return true; | ||
744 | } | 753 | } | ||
745 | } | 754 | } | ||
746 | return false; | 755 | return false; | ||
Show All 11 Lines | 766 | } else if (event->angleDelta().y() < 0) { | |||
758 | direction = PointerAxisDown; | 767 | direction = PointerAxisDown; | ||
759 | } else if (event->angleDelta().y() > 0) { | 768 | } else if (event->angleDelta().y() > 0) { | ||
760 | direction = PointerAxisUp; | 769 | direction = PointerAxisUp; | ||
761 | } | 770 | } | ||
762 | return input()->shortcuts()->processAxis(event->modifiers(), direction); | 771 | return input()->shortcuts()->processAxis(event->modifiers(), direction); | ||
763 | } | 772 | } | ||
764 | bool keyEvent(QKeyEvent *event) override { | 773 | bool keyEvent(QKeyEvent *event) override { | ||
765 | if (event->key() == Qt::Key_PowerOff) { | 774 | if (event->key() == Qt::Key_PowerOff) { | ||
766 | if (event->type() == QEvent::KeyPress) { | 775 | const auto modifiers = static_cast<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts(); | ||
767 | m_powerOffPress = event->timestamp(); | 776 | if (event->type() == QEvent::KeyPress && !event->isAutoRepeat()) { | ||
777 | QObject::connect(m_powerDown, &QTimer::timeout, input()->shortcuts(), [this, modifiers] { | ||||
778 | QObject::disconnect(m_powerDown, &QTimer::timeout, input()->shortcuts(), nullptr); | ||||
779 | m_powerDown->stop(); | ||||
780 | input()->shortcuts()->processKey(modifiers, Qt::Key_PowerDown); | ||||
781 | }); | ||||
782 | m_powerDown->start(); | ||||
783 | return true; | ||||
768 | } else if (event->type() == QEvent::KeyRelease) { | 784 | } else if (event->type() == QEvent::KeyRelease) { | ||
769 | const uint duration = (event->timestamp() - m_powerOffPress); | 785 | const bool ret = !m_powerDown->isActive() || input()->shortcuts()->processKey(modifiers, event->key()); | ||
770 | const Qt::Key key = duration > 1000 ? Qt::Key_PowerDown : Qt::Key_PowerOff; | 786 | m_powerDown->stop(); | ||
771 | const auto shortcuts = static_cast<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts(); | 787 | return ret; | ||
772 | return input()->shortcuts()->processKey(shortcuts, key | (event->key() & ~Qt::KeyboardModifierMask)); | | |||
773 | } | 788 | } | ||
774 | } else if (event->type() == QEvent::KeyPress) { | 789 | } else if (event->type() == QEvent::KeyPress) { | ||
775 | return input()->shortcuts()->processKey(static_cast<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts(), event->key()); | 790 | return input()->shortcuts()->processKey(static_cast<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts(), event->key()); | ||
776 | } | 791 | } | ||
777 | return false; | 792 | return false; | ||
778 | } | 793 | } | ||
779 | bool swipeGestureBegin(int fingerCount, quint32 time) override { | 794 | bool swipeGestureBegin(int fingerCount, quint32 time) override { | ||
780 | Q_UNUSED(time) | 795 | Q_UNUSED(time) | ||
Show All 12 Lines | |||||
793 | } | 808 | } | ||
794 | bool swipeGestureEnd(quint32 time) override { | 809 | bool swipeGestureEnd(quint32 time) override { | ||
795 | Q_UNUSED(time) | 810 | Q_UNUSED(time) | ||
796 | input()->shortcuts()->processSwipeEnd(); | 811 | input()->shortcuts()->processSwipeEnd(); | ||
797 | return false; | 812 | return false; | ||
798 | } | 813 | } | ||
799 | 814 | | |||
800 | private: | 815 | private: | ||
801 | uint m_powerOffPress; | 816 | QTimer* m_powerDown = nullptr; | ||
802 | }; | 817 | }; | ||
803 | 818 | | |||
804 | 819 | | |||
805 | namespace { | 820 | namespace { | ||
806 | 821 | | |||
807 | enum class MouseAction { | 822 | enum class MouseAction { | ||
808 | ModifierOnly, | 823 | ModifierOnly, | ||
809 | ModifierAndWindow | 824 | ModifierAndWindow | ||
▲ Show 20 Lines • Show All 1888 Lines • Show Last 20 Lines |