Changeset View
Changeset View
Standalone View
Standalone View
input.cpp
Show First 20 Lines • Show All 914 Lines • ▼ Show 20 Line(s) | 894 | bool touchUp(quint32 id, quint32 time) override { | |||
---|---|---|---|---|---|
915 | input()->touch()->setInternalPressId(-1); | 915 | input()->touch()->setInternalPressId(-1); | ||
916 | return true; | 916 | return true; | ||
917 | } | 917 | } | ||
918 | private: | 918 | private: | ||
919 | QPointF m_lastGlobalTouchPos; | 919 | QPointF m_lastGlobalTouchPos; | ||
920 | QPointF m_lastLocalTouchPos; | 920 | QPointF m_lastLocalTouchPos; | ||
921 | }; | 921 | }; | ||
922 | 922 | | |||
923 | namespace { | ||||
924 | | ||||
925 | enum class MouseAction { | ||||
926 | ModifierOnly, | ||||
927 | ModifierAndWindow | ||||
928 | }; | ||||
929 | std::pair<bool, bool> performClientMouseAction(QMouseEvent *event, AbstractClient *client, MouseAction action = MouseAction::ModifierOnly) | ||||
930 | { | ||||
931 | Options::MouseCommand command = Options::MouseNothing; | ||||
932 | bool wasAction = false; | ||||
933 | if (static_cast<MouseEvent*>(event)->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) { | ||||
934 | wasAction = true; | ||||
935 | switch (event->button()) { | ||||
936 | case Qt::LeftButton: | ||||
937 | command = options->commandAll1(); | ||||
938 | break; | ||||
939 | case Qt::MiddleButton: | ||||
940 | command = options->commandAll2(); | ||||
941 | break; | ||||
942 | case Qt::RightButton: | ||||
943 | command = options->commandAll3(); | ||||
944 | break; | ||||
945 | default: | ||||
946 | // nothing | ||||
947 | break; | ||||
948 | } | ||||
949 | } else { | ||||
950 | if (action == MouseAction::ModifierAndWindow) { | ||||
951 | command = client->getMouseCommand(event->button(), &wasAction); | ||||
952 | } | ||||
953 | } | ||||
954 | if (wasAction) { | ||||
955 | return std::make_pair(wasAction, !client->performMouseCommand(command, event->globalPos())); | ||||
956 | } | ||||
957 | return std::make_pair(wasAction, false); | ||||
958 | } | ||||
959 | | ||||
960 | std::pair<bool, bool> performClientWheelAction(QWheelEvent *event, AbstractClient *c, MouseAction action = MouseAction::ModifierOnly) | ||||
davidedmundson: if we're always going to do:
if (actionResult.first) {
return… | |||||
if actionResult.first is true we should not further process and return the result of actionResult.second. If actionResult.second is false we don't know anymore what the result of actionResult.first was if we and them. graesslin: if actionResult.first is true we should not further process and return the result of… | |||||
961 | { | ||||
962 | bool wasAction = false; | ||||
963 | Options::MouseCommand command = Options::MouseNothing; | ||||
964 | if (static_cast<WheelEvent*>(event)->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) { | ||||
965 | wasAction = true; | ||||
966 | command = options->operationWindowMouseWheel(-1 * event->angleDelta().y()); | ||||
967 | } else { | ||||
968 | if (action == MouseAction::ModifierAndWindow) { | ||||
969 | command = c->getWheelCommand(Qt::Vertical, &wasAction); | ||||
970 | } | ||||
971 | } | ||||
972 | if (wasAction) { | ||||
973 | return std::make_pair(wasAction, !c->performMouseCommand(command, event->globalPos())); | ||||
974 | } | ||||
975 | return std::make_pair(wasAction, false); | ||||
976 | } | ||||
977 | | ||||
978 | } | ||||
979 | | ||||
923 | class DecorationEventFilter : public InputEventFilter { | 980 | class DecorationEventFilter : public InputEventFilter { | ||
924 | public: | 981 | public: | ||
925 | bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override { | 982 | bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override { | ||
926 | Q_UNUSED(nativeButton) | 983 | Q_UNUSED(nativeButton) | ||
927 | auto decoration = input()->pointer()->decoration(); | 984 | auto decoration = input()->pointer()->decoration(); | ||
928 | if (!decoration) { | 985 | if (!decoration) { | ||
929 | return false; | 986 | return false; | ||
930 | } | 987 | } | ||
931 | const QPointF p = event->globalPos() - decoration->client()->pos(); | 988 | const QPointF p = event->globalPos() - decoration->client()->pos(); | ||
932 | switch (event->type()) { | 989 | switch (event->type()) { | ||
933 | case QEvent::MouseMove: { | 990 | case QEvent::MouseMove: { | ||
934 | if (event->buttons() == Qt::NoButton) { | 991 | if (event->buttons() == Qt::NoButton) { | ||
935 | return false; | 992 | return false; | ||
936 | } | 993 | } | ||
937 | QHoverEvent e(QEvent::HoverMove, p, p); | 994 | QHoverEvent e(QEvent::HoverMove, p, p); | ||
938 | QCoreApplication::instance()->sendEvent(decoration->decoration(), &e); | 995 | QCoreApplication::instance()->sendEvent(decoration->decoration(), &e); | ||
939 | decoration->client()->processDecorationMove(p.toPoint(), event->globalPos()); | 996 | decoration->client()->processDecorationMove(p.toPoint(), event->globalPos()); | ||
940 | return true; | 997 | return true; | ||
941 | } | 998 | } | ||
942 | case QEvent::MouseButtonPress: | 999 | case QEvent::MouseButtonPress: | ||
943 | case QEvent::MouseButtonRelease: { | 1000 | case QEvent::MouseButtonRelease: { | ||
1001 | const auto actionResult = performClientMouseAction(event, decoration->client()); | ||||
1002 | if (actionResult.first) { | ||||
1003 | return actionResult.second; | ||||
1004 | } | ||||
944 | QMouseEvent e(event->type(), p, event->globalPos(), event->button(), event->buttons(), event->modifiers()); | 1005 | QMouseEvent e(event->type(), p, event->globalPos(), event->button(), event->buttons(), event->modifiers()); | ||
945 | e.setAccepted(false); | 1006 | e.setAccepted(false); | ||
946 | QCoreApplication::sendEvent(decoration->decoration(), &e); | 1007 | QCoreApplication::sendEvent(decoration->decoration(), &e); | ||
947 | if (!e.isAccepted() && event->type() == QEvent::MouseButtonPress) { | 1008 | if (!e.isAccepted() && event->type() == QEvent::MouseButtonPress) { | ||
948 | decoration->client()->processDecorationButtonPress(&e); | 1009 | decoration->client()->processDecorationButtonPress(&e); | ||
949 | } | 1010 | } | ||
950 | if (event->type() == QEvent::MouseButtonRelease) { | 1011 | if (event->type() == QEvent::MouseButtonRelease) { | ||
951 | decoration->client()->processDecorationButtonRelease(&e); | 1012 | decoration->client()->processDecorationButtonRelease(&e); | ||
952 | } | 1013 | } | ||
953 | return true; | 1014 | return true; | ||
954 | } | 1015 | } | ||
955 | default: | 1016 | default: | ||
956 | break; | 1017 | break; | ||
957 | } | 1018 | } | ||
958 | return false; | 1019 | return false; | ||
959 | } | 1020 | } | ||
960 | bool wheelEvent(QWheelEvent *event) override { | 1021 | bool wheelEvent(QWheelEvent *event) override { | ||
961 | auto decoration = input()->pointer()->decoration(); | 1022 | auto decoration = input()->pointer()->decoration(); | ||
962 | if (!decoration) { | 1023 | if (!decoration) { | ||
963 | return false; | 1024 | return false; | ||
964 | } | 1025 | } | ||
1026 | if (event->angleDelta().y() != 0) { | ||||
1027 | // client window action only on vertical scrolling | ||||
1028 | const auto actionResult = performClientWheelAction(event, decoration->client()); | ||||
1029 | if (actionResult.first) { | ||||
1030 | return actionResult.second; | ||||
1031 | } | ||||
1032 | } | ||||
965 | const QPointF localPos = event->globalPosF() - decoration->client()->pos(); | 1033 | const QPointF localPos = event->globalPosF() - decoration->client()->pos(); | ||
966 | const Qt::Orientation orientation = (event->angleDelta().x() != 0) ? Qt::Horizontal : Qt::Vertical; | 1034 | const Qt::Orientation orientation = (event->angleDelta().x() != 0) ? Qt::Horizontal : Qt::Vertical; | ||
967 | const int delta = event->angleDelta().x() != 0 ? event->angleDelta().x() : event->angleDelta().y(); | 1035 | const int delta = event->angleDelta().x() != 0 ? event->angleDelta().x() : event->angleDelta().y(); | ||
968 | QWheelEvent e(localPos, event->globalPosF(), QPoint(), | 1036 | QWheelEvent e(localPos, event->globalPosF(), QPoint(), | ||
969 | event->angleDelta(), | 1037 | event->angleDelta(), | ||
970 | delta, | 1038 | delta, | ||
971 | orientation, | 1039 | orientation, | ||
972 | event->buttons(), | 1040 | event->buttons(), | ||
▲ Show 20 Lines • Show All 183 Lines • ▼ Show 20 Line(s) | 1223 | bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override { | |||
1156 | Q_UNUSED(nativeButton) | 1224 | Q_UNUSED(nativeButton) | ||
1157 | if (event->type() != QEvent::MouseButtonPress) { | 1225 | if (event->type() != QEvent::MouseButtonPress) { | ||
1158 | return false; | 1226 | return false; | ||
1159 | } | 1227 | } | ||
1160 | AbstractClient *c = dynamic_cast<AbstractClient*>(input()->pointer()->window().data()); | 1228 | AbstractClient *c = dynamic_cast<AbstractClient*>(input()->pointer()->window().data()); | ||
1161 | if (!c) { | 1229 | if (!c) { | ||
1162 | return false; | 1230 | return false; | ||
1163 | } | 1231 | } | ||
1164 | bool wasAction = false; | 1232 | const auto actionResult = performClientMouseAction(event, c, MouseAction::ModifierAndWindow); | ||
1165 | Options::MouseCommand command = Options::MouseNothing; | 1233 | if (actionResult.first) { | ||
1166 | if (static_cast<MouseEvent*>(event)->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) { | 1234 | return actionResult.second; | ||
1167 | wasAction = true; | | |||
1168 | switch (event->button()) { | | |||
1169 | case Qt::LeftButton: | | |||
1170 | command = options->commandAll1(); | | |||
1171 | break; | | |||
1172 | case Qt::MiddleButton: | | |||
1173 | command = options->commandAll2(); | | |||
1174 | break; | | |||
1175 | case Qt::RightButton: | | |||
1176 | command = options->commandAll3(); | | |||
1177 | break; | | |||
1178 | default: | | |||
1179 | // nothing | | |||
1180 | break; | | |||
1181 | } | | |||
1182 | } else { | | |||
1183 | command = c->getMouseCommand(event->button(), &wasAction); | | |||
1184 | } | | |||
1185 | if (wasAction) { | | |||
1186 | return !c->performMouseCommand(command, event->globalPos()); | | |||
1187 | } | 1235 | } | ||
1188 | return false; | 1236 | return false; | ||
1189 | } | 1237 | } | ||
1190 | bool wheelEvent(QWheelEvent *event) override { | 1238 | bool wheelEvent(QWheelEvent *event) override { | ||
1191 | if (event->angleDelta().y() == 0) { | 1239 | if (event->angleDelta().y() == 0) { | ||
1192 | // only actions on vertical scroll | 1240 | // only actions on vertical scroll | ||
1193 | return false; | 1241 | return false; | ||
1194 | } | 1242 | } | ||
1195 | AbstractClient *c = dynamic_cast<AbstractClient*>(input()->pointer()->window().data()); | 1243 | AbstractClient *c = dynamic_cast<AbstractClient*>(input()->pointer()->window().data()); | ||
1196 | if (!c) { | 1244 | if (!c) { | ||
1197 | return false; | 1245 | return false; | ||
1198 | } | 1246 | } | ||
1199 | bool wasAction = false; | 1247 | const auto actionResult = performClientWheelAction(event, c, MouseAction::ModifierAndWindow); | ||
1200 | Options::MouseCommand command = Options::MouseNothing; | 1248 | if (actionResult.first) { | ||
1201 | if (static_cast<WheelEvent*>(event)->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) { | 1249 | return actionResult.second; | ||
1202 | wasAction = true; | | |||
1203 | command = options->operationWindowMouseWheel(-1 * event->angleDelta().y()); | | |||
1204 | } else { | | |||
1205 | command = c->getWheelCommand(Qt::Vertical, &wasAction); | | |||
1206 | } | | |||
1207 | if (wasAction) { | | |||
1208 | return !c->performMouseCommand(command, event->globalPos()); | | |||
1209 | } | 1250 | } | ||
1210 | return false; | 1251 | return false; | ||
1211 | } | 1252 | } | ||
1212 | bool touchDown(quint32 id, const QPointF &pos, quint32 time) override { | 1253 | bool touchDown(quint32 id, const QPointF &pos, quint32 time) override { | ||
1213 | Q_UNUSED(id) | 1254 | Q_UNUSED(id) | ||
1214 | Q_UNUSED(time) | 1255 | Q_UNUSED(time) | ||
1215 | auto seat = waylandServer()->seat(); | 1256 | auto seat = waylandServer()->seat(); | ||
1216 | if (seat->isTouchSequence()) { | 1257 | if (seat->isTouchSequence()) { | ||
▲ Show 20 Lines • Show All 925 Lines • Show Last 20 Lines |
if we're always going to do:
why return two bools and not just "and" them here?