Changeset View
Changeset View
Standalone View
Standalone View
input.cpp
Show First 20 Lines • Show All 760 Lines • ▼ Show 20 Line(s) | 715 | public: | |||
---|---|---|---|---|---|
761 | } | 761 | } | ||
762 | bool swipeGestureEnd(quint32 time) override { | 762 | bool swipeGestureEnd(quint32 time) override { | ||
763 | Q_UNUSED(time) | 763 | Q_UNUSED(time) | ||
764 | input()->shortcuts()->processSwipeEnd(); | 764 | input()->shortcuts()->processSwipeEnd(); | ||
765 | return false; | 765 | return false; | ||
766 | } | 766 | } | ||
767 | }; | 767 | }; | ||
768 | 768 | | |||
769 | | ||||
770 | namespace { | ||||
771 | | ||||
772 | enum class MouseAction { | ||||
773 | ModifierOnly, | ||||
774 | ModifierAndWindow | ||||
775 | }; | ||||
776 | std::pair<bool, bool> performClientMouseAction(QMouseEvent *event, AbstractClient *client, MouseAction action = MouseAction::ModifierOnly) | ||||
777 | { | ||||
778 | Options::MouseCommand command = Options::MouseNothing; | ||||
779 | bool wasAction = false; | ||||
780 | if (static_cast<MouseEvent*>(event)->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) { | ||||
781 | wasAction = true; | ||||
782 | switch (event->button()) { | ||||
783 | case Qt::LeftButton: | ||||
784 | command = options->commandAll1(); | ||||
785 | break; | ||||
786 | case Qt::MiddleButton: | ||||
787 | command = options->commandAll2(); | ||||
788 | break; | ||||
789 | case Qt::RightButton: | ||||
790 | command = options->commandAll3(); | ||||
791 | break; | ||||
792 | default: | ||||
793 | // nothing | ||||
794 | break; | ||||
795 | } | ||||
796 | } else { | ||||
797 | if (action == MouseAction::ModifierAndWindow) { | ||||
798 | command = client->getMouseCommand(event->button(), &wasAction); | ||||
799 | } | ||||
800 | } | ||||
801 | if (wasAction) { | ||||
802 | return std::make_pair(wasAction, !client->performMouseCommand(command, event->globalPos())); | ||||
803 | } | ||||
804 | return std::make_pair(wasAction, false); | ||||
805 | } | ||||
806 | | ||||
807 | std::pair<bool, bool> performClientWheelAction(QWheelEvent *event, AbstractClient *c, MouseAction action = MouseAction::ModifierOnly) | ||||
808 | { | ||||
809 | bool wasAction = false; | ||||
810 | Options::MouseCommand command = Options::MouseNothing; | ||||
811 | if (static_cast<WheelEvent*>(event)->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) { | ||||
812 | wasAction = true; | ||||
813 | command = options->operationWindowMouseWheel(-1 * event->angleDelta().y()); | ||||
814 | } else { | ||||
815 | if (action == MouseAction::ModifierAndWindow) { | ||||
816 | command = c->getWheelCommand(Qt::Vertical, &wasAction); | ||||
817 | } | ||||
818 | } | ||||
819 | if (wasAction) { | ||||
820 | return std::make_pair(wasAction, !c->performMouseCommand(command, event->globalPos())); | ||||
821 | } | ||||
822 | return std::make_pair(wasAction, false); | ||||
823 | } | ||||
824 | | ||||
825 | } | ||||
826 | | ||||
769 | class InternalWindowEventFilter : public InputEventFilter { | 827 | class InternalWindowEventFilter : public InputEventFilter { | ||
770 | bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override { | 828 | bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override { | ||
771 | Q_UNUSED(nativeButton) | 829 | Q_UNUSED(nativeButton) | ||
772 | auto internal = input()->pointer()->internalWindow(); | 830 | auto internal = input()->pointer()->internalWindow(); | ||
773 | if (!internal) { | 831 | if (!internal) { | ||
774 | return false; | 832 | return false; | ||
775 | } | 833 | } | ||
776 | if (event->buttons() == Qt::NoButton) { | 834 | if (event->buttons() == Qt::NoButton) { | ||
777 | // update pointer window only if no button is pressed | 835 | // update pointer window only if no button is pressed | ||
778 | input()->pointer()->update(); | 836 | input()->pointer()->update(); | ||
779 | } | 837 | } | ||
780 | if (!internal) { | 838 | if (!internal) { | ||
781 | return false; | 839 | return false; | ||
782 | } | 840 | } | ||
841 | // find client | ||||
842 | switch (event->type()) | ||||
843 | { | ||||
844 | case QEvent::MouseButtonPress: | ||||
845 | case QEvent::MouseButtonRelease: { | ||||
846 | auto s = waylandServer()->findClient(internal); | ||||
847 | if (s && s->isDecorated()) { | ||||
848 | // only perform mouse commands on decorated internal windows | ||||
849 | const auto actionResult = performClientMouseAction(event, s); | ||||
850 | if (actionResult.first) { | ||||
851 | return actionResult.second; | ||||
852 | } | ||||
853 | } | ||||
854 | break; | ||||
855 | } | ||||
856 | default: | ||||
857 | break; | ||||
858 | } | ||||
783 | QMouseEvent e(event->type(), | 859 | QMouseEvent e(event->type(), | ||
784 | event->pos() - internal->position(), | 860 | event->pos() - internal->position(), | ||
785 | event->globalPos(), | 861 | event->globalPos(), | ||
786 | event->button(), event->buttons(), event->modifiers()); | 862 | event->button(), event->buttons(), event->modifiers()); | ||
787 | e.setAccepted(false); | 863 | e.setAccepted(false); | ||
788 | QCoreApplication::sendEvent(internal.data(), &e); | 864 | QCoreApplication::sendEvent(internal.data(), &e); | ||
789 | return e.isAccepted(); | 865 | return e.isAccepted(); | ||
790 | } | 866 | } | ||
791 | bool wheelEvent(QWheelEvent *event) override { | 867 | bool wheelEvent(QWheelEvent *event) override { | ||
792 | auto internal = input()->pointer()->internalWindow(); | 868 | auto internal = input()->pointer()->internalWindow(); | ||
793 | if (!internal) { | 869 | if (!internal) { | ||
794 | return false; | 870 | return false; | ||
795 | } | 871 | } | ||
872 | if (event->angleDelta().y() != 0) { | ||||
873 | auto s = waylandServer()->findClient(internal); | ||||
874 | if (s && s->isDecorated()) { | ||||
875 | // client window action only on vertical scrolling | ||||
876 | const auto actionResult = performClientWheelAction(event, s); | ||||
877 | if (actionResult.first) { | ||||
878 | return actionResult.second; | ||||
879 | } | ||||
880 | } | ||||
881 | } | ||||
796 | const QPointF localPos = event->globalPosF() - QPointF(internal->x(), internal->y()); | 882 | const QPointF localPos = event->globalPosF() - QPointF(internal->x(), internal->y()); | ||
797 | const Qt::Orientation orientation = (event->angleDelta().x() != 0) ? Qt::Horizontal : Qt::Vertical; | 883 | const Qt::Orientation orientation = (event->angleDelta().x() != 0) ? Qt::Horizontal : Qt::Vertical; | ||
798 | const int delta = event->angleDelta().x() != 0 ? event->angleDelta().x() : event->angleDelta().y(); | 884 | const int delta = event->angleDelta().x() != 0 ? event->angleDelta().x() : event->angleDelta().y(); | ||
799 | QWheelEvent e(localPos, event->globalPosF(), QPoint(), | 885 | QWheelEvent e(localPos, event->globalPosF(), QPoint(), | ||
800 | event->angleDelta() * -1, | 886 | event->angleDelta() * -1, | ||
801 | delta * -1, | 887 | delta * -1, | ||
802 | orientation, | 888 | orientation, | ||
803 | event->buttons(), | 889 | event->buttons(), | ||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Line(s) | 989 | bool touchUp(quint32 id, quint32 time) override { | |||
924 | input()->touch()->setInternalPressId(-1); | 1010 | input()->touch()->setInternalPressId(-1); | ||
925 | return true; | 1011 | return true; | ||
926 | } | 1012 | } | ||
927 | private: | 1013 | private: | ||
928 | QPointF m_lastGlobalTouchPos; | 1014 | QPointF m_lastGlobalTouchPos; | ||
929 | QPointF m_lastLocalTouchPos; | 1015 | QPointF m_lastLocalTouchPos; | ||
930 | }; | 1016 | }; | ||
931 | 1017 | | |||
932 | namespace { | | |||
933 | | ||||
934 | enum class MouseAction { | | |||
935 | ModifierOnly, | | |||
936 | ModifierAndWindow | | |||
937 | }; | | |||
938 | std::pair<bool, bool> performClientMouseAction(QMouseEvent *event, AbstractClient *client, MouseAction action = MouseAction::ModifierOnly) | | |||
939 | { | | |||
940 | Options::MouseCommand command = Options::MouseNothing; | | |||
941 | bool wasAction = false; | | |||
942 | if (static_cast<MouseEvent*>(event)->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) { | | |||
943 | wasAction = true; | | |||
944 | switch (event->button()) { | | |||
945 | case Qt::LeftButton: | | |||
946 | command = options->commandAll1(); | | |||
947 | break; | | |||
948 | case Qt::MiddleButton: | | |||
949 | command = options->commandAll2(); | | |||
950 | break; | | |||
951 | case Qt::RightButton: | | |||
952 | command = options->commandAll3(); | | |||
953 | break; | | |||
954 | default: | | |||
955 | // nothing | | |||
956 | break; | | |||
957 | } | | |||
958 | } else { | | |||
959 | if (action == MouseAction::ModifierAndWindow) { | | |||
960 | command = client->getMouseCommand(event->button(), &wasAction); | | |||
961 | } | | |||
962 | } | | |||
963 | if (wasAction) { | | |||
964 | return std::make_pair(wasAction, !client->performMouseCommand(command, event->globalPos())); | | |||
965 | } | | |||
966 | return std::make_pair(wasAction, false); | | |||
967 | } | | |||
968 | | ||||
969 | std::pair<bool, bool> performClientWheelAction(QWheelEvent *event, AbstractClient *c, MouseAction action = MouseAction::ModifierOnly) | | |||
970 | { | | |||
971 | bool wasAction = false; | | |||
972 | Options::MouseCommand command = Options::MouseNothing; | | |||
973 | if (static_cast<WheelEvent*>(event)->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) { | | |||
974 | wasAction = true; | | |||
975 | command = options->operationWindowMouseWheel(-1 * event->angleDelta().y()); | | |||
976 | } else { | | |||
977 | if (action == MouseAction::ModifierAndWindow) { | | |||
978 | command = c->getWheelCommand(Qt::Vertical, &wasAction); | | |||
979 | } | | |||
980 | } | | |||
981 | if (wasAction) { | | |||
982 | return std::make_pair(wasAction, !c->performMouseCommand(command, event->globalPos())); | | |||
983 | } | | |||
984 | return std::make_pair(wasAction, false); | | |||
985 | } | | |||
986 | | ||||
987 | } | | |||
988 | | ||||
989 | class DecorationEventFilter : public InputEventFilter { | 1018 | class DecorationEventFilter : public InputEventFilter { | ||
990 | public: | 1019 | public: | ||
991 | bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override { | 1020 | bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override { | ||
992 | Q_UNUSED(nativeButton) | 1021 | Q_UNUSED(nativeButton) | ||
993 | auto decoration = input()->pointer()->decoration(); | 1022 | auto decoration = input()->pointer()->decoration(); | ||
994 | if (!decoration) { | 1023 | if (!decoration) { | ||
995 | return false; | 1024 | return false; | ||
996 | } | 1025 | } | ||
▲ Show 20 Lines • Show All 1235 Lines • Show Last 20 Lines |