Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Implement TouchpadScroll touchpad gesture
Dmitry Kazakovcd884df32c9d
diff --git a/krita/data/input/clipstudiopaintcompatible.profile b/krita/data/input/clipstudiopaintcompatible.profileindex 42578666b6..3667c78478 100644--- a/krita/data/input/clipstudiopaintcompatible.profile+++ b/krita/data/input/clipstudiopaintcompatible.profile@@ -24,7 +24,7 @@ version=73={2;1;[];0;0;0}4={3;1;[];0;0;0}5={4;1;[];0;0;0}-6={0;3;[];0;5;0}+6={0;5;[];0;0;5}7={0;4;[];0;0;6}[Rotate Canvas]diff --git a/krita/data/input/kritadefault.profile b/krita/data/input/kritadefault.profileindex 689624cc55..ea99add8eb 100644--- a/krita/data/input/kritadefault.profile+++ b/krita/data/input/kritadefault.profile@@ -25,7 +25,7 @@ version=74={2;1;[];0;0;0}5={3;1;[];0;0;0}6={4;1;[];0;0;0}-7={0;3;[];0;5;0}+7={0;5;[];0;0;5}[Rotate Canvas]0={0;2;[1000020,20];1;0;0}diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txtindex 80ea07cded..e2f6145b2c 100644--- a/libs/ui/CMakeLists.txt+++ b/libs/ui/CMakeLists.txt@@ -368,6 +368,7 @@ set(kritaui_LIB_SRCSinput/kis_stroke_shortcut.cppinput/kis_shortcut_matcher.cppinput/kis_select_layer_action.cpp+ input/KisTouchpadScrollShortcut.cppinput/KisQtWidgetsTweaker.cppinput/KisInputActionGroup.cppinput/kis_zoom_and_rotate_action.cppdiff --git a/libs/ui/input/KisInputEventsEater.cpp b/libs/ui/input/KisInputEventsEater.cppindex da1de20b80..401fb23f43 100644--- a/libs/ui/input/KisInputEventsEater.cpp+++ b/libs/ui/input/KisInputEventsEater.cpp@@ -252,23 +252,6 @@ bool KisInputEventsEater::eventFilter(QObject* target, QEvent* event )}}-#ifdef Q_OS_MACOS- /**- * MacOS is the only platform where we can differentiate between- * wheel events generated by a mouse and by a touchpad. More than- * that, on MacOS touchpad generates NativeGesture events, hence- * we should just blocked all the synthetic wheel events.- */-- if (event->type() == QEvent::Wheel) {- QWheelEvent *we = static_cast<QWheelEvent *>(event);- if (we->source() == Qt::MouseEventSource::MouseEventSynthesizedBySystem) {- debugEvent<QWheelEvent>(event, BlockedBySynthetic);- return true;- }- }-#endif-const bool shouldEatMouseEvents =// On MacOS Qt sends fake mouse events instead of hover events,// so we should not block mouse events when the tablet just hoversdiff --git a/libs/ui/input/KisInputProfileMigrator.cpp b/libs/ui/input/KisInputProfileMigrator.cppindex 8505b31047..ebd682d6a9 100644--- a/libs/ui/input/KisInputProfileMigrator.cpp+++ b/libs/ui/input/KisInputProfileMigrator.cpp@@ -19,6 +19,7 @@#include "kis_abstract_input_action.h"#include "kis_input_profile_manager.h"#include "kis_shortcut_configuration.h"+#include "kis_pan_action.h"#include "kis_zoom_and_rotate_action.h"KisInputProfileMigrator::~KisInputProfileMigrator()@@ -140,22 +141,50 @@ QList<KisShortcutConfiguration> KisInputProfileMigratorFrom6::migrate(const Prof}}- /**- * Now add the default connection between native gestures and- * "Zoom and Rotate Canvas" action- */+ for (auto it = shortcuts.begin(); it != shortcuts.end();) {+ if (it->type() == KisShortcutConfiguration::MouseWheelType+ && it->wheel() == KisShortcutConfiguration::WheelReserved_0) {+ it = shortcuts.erase(it);+ } else {+ ++it;+ }+ }auto actions = m_manager->actions();- auto it = std::find_if(actions.begin(), actions.end(), kismpl::mem_equal_to(&KisAbstractInputAction::id, "Zoom and Rotate Canvas"));- KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(it != actions.end(), shortcuts);+ {+ /**+ * Now add the default connection between native gestures and+ * "Zoom and Rotate Canvas" action+ */++ auto it = std::find_if(actions.begin(), actions.end(), kismpl::mem_equal_to(&KisAbstractInputAction::id, "Zoom and Rotate Canvas"));+ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(it != actions.end(), shortcuts);++ KisShortcutConfiguration newNativeGestureShortcut;+ newNativeGestureShortcut.setAction(*it);+ newNativeGestureShortcut.setType(KisShortcutConfiguration::NativeGestureType);+ newNativeGestureShortcut.setNativeGesture(KisShortcutConfiguration::PinchGesture);+ newNativeGestureShortcut.setMode(KisZoomAndRotateAction::PanAndZoomAndRotateMode);+ shortcuts.append(newNativeGestureShortcut);+ }- KisShortcutConfiguration newNativeGestureShortcut;- newNativeGestureShortcut.setAction(*it);- newNativeGestureShortcut.setType(KisShortcutConfiguration::NativeGestureType);- newNativeGestureShortcut.setNativeGesture(KisShortcutConfiguration::PinchGesture);- newNativeGestureShortcut.setMode(KisZoomAndRotateAction::PanAndZoomAndRotateMode);- shortcuts.append(newNativeGestureShortcut);+ {+ /**+ * Now add the default connection between native scroll and+ * "Pan Canvas" action+ */++ auto it = std::find_if(actions.begin(), actions.end(), kismpl::mem_equal_to(&KisAbstractInputAction::id, "Pan Canvas"));+ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(it != actions.end(), shortcuts);++ KisShortcutConfiguration newNativeGestureShortcut;+ newNativeGestureShortcut.setAction(*it);+ newNativeGestureShortcut.setType(KisShortcutConfiguration::NativeGestureType);+ newNativeGestureShortcut.setNativeGesture(KisShortcutConfiguration::TouchpadScroll);+ newNativeGestureShortcut.setMode(KisPanAction::PanModeShortcut);+ shortcuts.append(newNativeGestureShortcut);+ }return shortcuts;}\ No newline at end of filediff --git a/libs/ui/input/KisTouchpadScrollShortcut.cpp b/libs/ui/input/KisTouchpadScrollShortcut.cppnew file mode 100644index 0000000000..56397f25e1--- /dev/null+++ b/libs/ui/input/KisTouchpadScrollShortcut.cpp@@ -0,0 +1,28 @@+/*+ * SPDX-FileCopyrightText: 2026 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#include "KisTouchpadScrollShortcut.h"++#include <QWheelEvent>++KisTouchpadScrollShortcut::KisTouchpadScrollShortcut(KisAbstractInputAction* action, int index)+ : KisAbstractShortcut(action, index)+{+}++KisTouchpadScrollShortcut::~KisTouchpadScrollShortcut()+{+}++int KisTouchpadScrollShortcut::priority() const+{+ return 0;+}++bool KisTouchpadScrollShortcut::match(QWheelEvent* event)+{+ return event->phase() != Qt::NoScrollPhase;+}diff --git a/libs/ui/input/KisTouchpadScrollShortcut.h b/libs/ui/input/KisTouchpadScrollShortcut.hnew file mode 100644index 0000000000..bcc5dab9ee--- /dev/null+++ b/libs/ui/input/KisTouchpadScrollShortcut.h@@ -0,0 +1,23 @@+/*+ * SPDX-FileCopyrightText: 2026 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#ifndef KISTOUCHPADSCROLLSHORTCUT_H+#define KISTOUCHPADSCROLLSHORTCUT_H++#include "kis_abstract_shortcut.h"++class QWheelEvent;+class KisTouchpadScrollShortcut : public KisAbstractShortcut+{+public:+ KisTouchpadScrollShortcut(KisAbstractInputAction* action, int index);+ ~KisTouchpadScrollShortcut() override;++ int priority() const override;+ bool match(QWheelEvent* event);+};++#endif // KISTOUCHPADSCROLLSHORTCUT_Hdiff --git a/libs/ui/input/config/KisNativeGestureSelector.cpp b/libs/ui/input/config/KisNativeGestureSelector.cppindex b2217c80a2..c2492e9662 100644--- a/libs/ui/input/config/KisNativeGestureSelector.cpp+++ b/libs/ui/input/config/KisNativeGestureSelector.cpp@@ -11,6 +11,7 @@ KisNativeGestureSelector::KisNativeGestureSelector(QWidget *parent){insertItem(0, KisShortcutConfiguration::nativeGestureToText(KisShortcutConfiguration::PinchGesture), static_cast<int>(KisShortcutConfiguration::PinchGesture));insertItem(1, KisShortcutConfiguration::nativeGestureToText(KisShortcutConfiguration::SmartZoomGesture), static_cast<int>(KisShortcutConfiguration::SmartZoomGesture));+ insertItem(2, KisShortcutConfiguration::nativeGestureToText(KisShortcutConfiguration::TouchpadScroll), static_cast<int>(KisShortcutConfiguration::TouchpadScroll));}void KisNativeGestureSelector::setNativeGesture(KisShortcutConfiguration::NativeGestureAction gestureAction)diff --git a/libs/ui/input/kis_input_manager.cpp b/libs/ui/input/kis_input_manager.cppindex 829e09febd..4d9d329dc8 100644--- a/libs/ui/input/kis_input_manager.cpp+++ b/libs/ui/input/kis_input_manager.cpp@@ -492,19 +492,36 @@ bool KisInputManager::eventFilterImpl(QEvent * event)KisInputEventsEater::debugEvent<QWheelEvent>(event);QWheelEvent *wheelEvent = static_cast<QWheelEvent*>(event);+ if (wheelEvent->phase() != Qt::NoScrollPhase && d->matcher.hasTouchpadScrollShortcuts()) {+ /**+ * Wayland sends us a duplicated ScrollBegin event (one for+ * every axis), so we cannot rely just on status of the+ * running stroke and should use hasTouchpadScrollShortcuts()+ * instead.+ */++ if (wheelEvent->phase() == Qt::ScrollBegin) {+ d->matcher.touchpadScrollBeginEvent(wheelEvent);+ } else if (wheelEvent->phase() == Qt::ScrollEnd) {+ d->matcher.touchpadScrollEndEvent(wheelEvent);+ } else {+ d->matcher.touchpadScrollEvent(wheelEvent);+ }++ break;+ }+d->accumulatedScrollDelta += wheelEvent->angleDelta().y();KisSingleActionShortcut::WheelAction action;/**- * Ignore delta 0 events on OSX, since they are triggered by tablet- * proximity when using Wacom devices.+ * When wheelEvent->phase() is not Qt::NoScrollPhase, the delta+ * can be easily null, so we should ignore these events.*/-#ifdef Q_OS_MACOSif (wheelEvent->angleDelta().isNull()) {retval = true;break;}-#endifif (wheelEvent->angleDelta().x() < 0) {action = KisSingleActionShortcut::WheelRight;@@ -835,7 +852,6 @@ void KisInputManager::slotTextModeChanged()}}-void KisInputManager::profileChanged(){d->matcher.clearShortcuts();diff --git a/libs/ui/input/kis_input_manager_p.cpp b/libs/ui/input/kis_input_manager_p.cppindex 24be8e340e..438a8d6606 100644--- a/libs/ui/input/kis_input_manager_p.cpp+++ b/libs/ui/input/kis_input_manager_p.cpp@@ -21,6 +21,7 @@#include "kis_stroke_shortcut.h"#include "kis_touch_shortcut.h"#include "kis_native_gesture_shortcut.h"+#include "KisTouchpadScrollShortcut.h"#include "kis_input_profile_manager.h"#include "kis_extended_modifiers_mapper.h"@@ -358,28 +359,32 @@ void KisInputManager::Private::addWheelShortcut(KisAbstractInputAction* action,const QList<Qt::Key> &modifiers,KisShortcutConfiguration::MouseWheelMovement wheelAction){- std::unique_ptr<KisSingleActionShortcut> keyShortcut(- new KisSingleActionShortcut(action, index));- KisSingleActionShortcut::WheelAction a;++ auto addSingleActionShortcut = [&] (KisSingleActionShortcut::WheelAction a) {+ std::unique_ptr<KisSingleActionShortcut> keyShortcut(+ new KisSingleActionShortcut(action, index));+ keyShortcut->setWheel(QSet<Qt::Key>(modifiers.begin(), modifiers.end()), a);+ matcher.addShortcut(keyShortcut.release());+ };+switch(wheelAction) {case KisShortcutConfiguration::WheelUp:- a = KisSingleActionShortcut::WheelUp;+ addSingleActionShortcut(KisSingleActionShortcut::WheelUp);break;case KisShortcutConfiguration::WheelDown:- a = KisSingleActionShortcut::WheelDown;+ addSingleActionShortcut(KisSingleActionShortcut::WheelDown);break;case KisShortcutConfiguration::WheelLeft:- a = KisSingleActionShortcut::WheelLeft;+ addSingleActionShortcut(KisSingleActionShortcut::WheelLeft);break;case KisShortcutConfiguration::WheelRight:- a = KisSingleActionShortcut::WheelRight;+ addSingleActionShortcut(KisSingleActionShortcut::WheelRight);+ break;+ case KisShortcutConfiguration::WheelReserved_0:+ case KisShortcutConfiguration::NoMovement:break;- default:- return;}- keyShortcut->setWheel(QSet<Qt::Key>(modifiers.begin(), modifiers.end()), a);- matcher.addShortcut(keyShortcut.release());}void KisInputManager::Private::addTouchShortcut(KisAbstractInputAction* action, int index, KisShortcutConfiguration::TouchGestureAction gesture, bool isTouchPainting)@@ -424,22 +429,33 @@ void KisInputManager::Private::addTouchShortcut(KisAbstractInputAction* action,bool KisInputManager::Private::addNativeGestureShortcut(KisAbstractInputAction* action, int index, KisShortcutConfiguration::NativeGestureAction gesture){+ auto addNativeGesture = [&] (KisNativeGestureShortcut::Type type) {+ KisNativeGestureShortcut *shortcut = new KisNativeGestureShortcut(action, index, type);+ matcher.addShortcut(shortcut);+ };++ // Native gestures:// Qt5 only implements QNativeGestureEvent for macOS// Qt6 implements QNativeGestureEvent for macOS and Wayland- KisNativeGestureShortcut::Type type = KisNativeGestureShortcut::PinchNavigation;+ //+ // Touchpad pixel scrolling:+ // Qt5 only implements touchpad pixel scrolling for macOS+ // Qt6 implements touchpad pixel scrolling for macOS and Wayland+switch (gesture) {case KisShortcutConfiguration::PinchGesture:- type = KisNativeGestureShortcut::PinchNavigation;+ addNativeGesture(KisNativeGestureShortcut::PinchNavigation);break;case KisShortcutConfiguration::SmartZoomGesture:- type = KisNativeGestureShortcut::SmartZoomNativeGesture;+ addNativeGesture(KisNativeGestureShortcut::SmartZoomNativeGesture);+ break;+ case KisShortcutConfiguration::TouchpadScroll:+ matcher.addShortcut(new KisTouchpadScrollShortcut(action, index));break;default:return false;}- KisNativeGestureShortcut *shortcut = new KisNativeGestureShortcut(action, index, type);- matcher.addShortcut(shortcut);return true;}diff --git a/libs/ui/input/kis_pan_action.cpp b/libs/ui/input/kis_pan_action.cppindex 5725bf49ca..46b5e0abf2 100644--- a/libs/ui/input/kis_pan_action.cpp+++ b/libs/ui/input/kis_pan_action.cpp@@ -107,16 +107,19 @@ void KisPanAction::begin(int shortcut, QEvent *event)switch (shortcut) {case PanModeShortcut: {- // Some QT wheel events are actually be touch pad pan events. From the QT docs:- // "Wheel events are generated for both mouse wheels and trackpad scroll gestures."- QWheelEvent *wheelEvent = dynamic_cast<QWheelEvent*>(event);- if (wheelEvent) {+ if (event->type() == QEvent::Wheel) {+ // Some QT wheel events are actually be touch pad pan events. From the QT docs:+ // "Wheel events are generated for both mouse wheels and trackpad scroll gestures."+ QWheelEvent *wheelEvent = static_cast<QWheelEvent*>(event);inputManager()->canvas()->canvasController()->pan(-wheelEvent->pixelDelta());- overrideCursor = false;- break;- }- d->originalPreferredCenter = inputManager()->canvas()->canvasController()->preferredCenter();+ // native gestures don't have cursor tracking by the OS, so they shouldn't show any cursor+ QApplication::restoreOverrideCursor();++ return;+ } else {+ d->originalPreferredCenter = inputManager()->canvas()->canvasController()->preferredCenter();+ }break;}@@ -154,6 +157,9 @@ void KisPanAction::inputEvent(QEvent *event)if (d->actionStrategy && d->actionStrategy->supportsEvent(event)) {d->actionStrategy->inputEvent(event);+ } else if (event->type() == QEvent::Wheel) {+ QWheelEvent *wheelEvent = static_cast<QWheelEvent*>(event);+ inputManager()->canvas()->canvasController()->pan(-wheelEvent->pixelDelta());} else {KisAbstractInputAction::inputEvent(event);}diff --git a/libs/ui/input/kis_shortcut_configuration.cpp b/libs/ui/input/kis_shortcut_configuration.cppindex 53d5bf04ab..93d079b364 100644--- a/libs/ui/input/kis_shortcut_configuration.cpp+++ b/libs/ui/input/kis_shortcut_configuration.cpp@@ -7,6 +7,7 @@#include "kis_shortcut_configuration.h"+#include <QDebug>#include <QStringList>#include <QKeySequence>#include <KLocalizedString>@@ -157,6 +158,11 @@ bool KisShortcutConfiguration::unserialize(const QString &serialized)d->buttons = static_cast<Qt::MouseButtons>(parts.at(3).toInt(nullptr, 16));d->wheel = static_cast<MouseWheelMovement>(parts.at(4).toUInt(nullptr, 16));+ if (d->type == MouseWheelType && d->wheel == WheelReserved_0) {+ qWarning() << "WARNING: input profile contains deprecated Mouse Wheel shortcut (WheelReserved_0), skipping...";+ return false;+ }+if (d->type == NativeGestureType) {d->nativeGesture = static_cast<NativeGestureAction>(parts.at(5).toUInt(nullptr, 16));} else {@@ -472,6 +478,8 @@ QString KisShortcutConfiguration::nativeGestureToText(NativeGestureAction actionreturn i18n("Pinch Gesture");case SmartZoomGesture:return i18n("Smart Zoom Gesture");+ case TouchpadScroll:+ return i18n("Touchpad Scroll Gesture");default:return i18n("No Gesture");}diff --git a/libs/ui/input/kis_shortcut_configuration.h b/libs/ui/input/kis_shortcut_configuration.hindex 7250c52eea..7478ad3319 100644--- a/libs/ui/input/kis_shortcut_configuration.h+++ b/libs/ui/input/kis_shortcut_configuration.h@@ -50,6 +50,7 @@ public:WheelDown, ///< Downwards movement, toward the user.WheelLeft, ///< Left movement.WheelRight, ///< Right movement.+ WheelReserved_0, ///< Do not use! Previously was used for TouchpadScroll shortcut};/**@@ -80,6 +81,7 @@ public:// but now all three gestures are represented as a single PinchGesture.SmartZoomGesture = 4, ///< Smart zoom gesture, typically a double tap that is a boolean zoom/unzoom.+ TouchpadScroll = 5, ///< Two-dimensional pixel scrolling on a touchpad, supported on MacOS and Wayland onlyMaxNativeGesture,};diff --git a/libs/ui/input/kis_shortcut_matcher.cpp b/libs/ui/input/kis_shortcut_matcher.cppindex d2327cf48a..da0d13b4c9 100644--- a/libs/ui/input/kis_shortcut_matcher.cpp+++ b/libs/ui/input/kis_shortcut_matcher.cpp@@ -15,6 +15,7 @@#include "kis_stroke_shortcut.h"#include "kis_touch_shortcut.h"#include "kis_native_gesture_shortcut.h"+#include "KisTouchpadScrollShortcut.h"#include "kis_config.h"#include "kis_extended_modifiers_mapper.h"#include "KisTouchHoldEventsPostponer.h"@@ -92,6 +93,7 @@ public:, readyShortcut(0), touchShortcut(0), nativeGestureShortcut(0)+ , touchpadScrollShortcut(0), actionGroupMask([] () { return AllActionGroup; }), suppressAllActions(false), suppressAllKeyboardActions(false)@@ -110,6 +112,7 @@ public:QList<KisStrokeShortcut*> strokeShortcuts;QList<KisTouchShortcut*> touchShortcuts;QList<KisNativeGestureShortcut*> nativeGestureShortcuts;+ QList<KisTouchpadScrollShortcut*> touchpadScrollShortcuts;QSet<Qt::Key> keys; // Model of currently pressed keysQSet<Qt::MouseButton> buttons; // Model of currently pressed buttons@@ -122,8 +125,10 @@ public:KisTouchShortcut *touchShortcut;KisNativeGestureShortcut *nativeGestureShortcut;+ KisTouchpadScrollShortcut *touchpadScrollShortcut;std::optional<KisTouchHoldEventsPostponer> touchHoldEventPostponer;+int maxTouchPoints{0};int matchingIteration{0};bool isTouchDragDetected {false};@@ -220,7 +225,7 @@ KisShortcutMatcher::~KisShortcutMatcher()bool KisShortcutMatcher::hasRunningShortcut() const{- return m_d->runningShortcut || m_d->touchShortcut || m_d->nativeGestureShortcut;+ return m_d->runningShortcut || m_d->touchShortcut || m_d->nativeGestureShortcut || m_d->touchpadScrollShortcut;}bool KisShortcutMatcher::hasTouchHoldShortcut() const@@ -248,10 +253,16 @@ void KisShortcutMatcher::addShortcut( KisTouchShortcut* shortcut )m_d->touchShortcuts.append(shortcut);}-void KisShortcutMatcher::addShortcut(KisNativeGestureShortcut *shortcut) {+void KisShortcutMatcher::addShortcut(KisNativeGestureShortcut *shortcut)+{m_d->nativeGestureShortcuts.append(shortcut);}+void KisShortcutMatcher::addShortcut( KisTouchpadScrollShortcut* shortcut )+{+ m_d->touchpadScrollShortcuts.append(shortcut);+}+bool KisShortcutMatcher::supportsHiResInputEvents(){return (m_d->runningShortcut && m_d->runningShortcut->action()@@ -259,7 +270,9 @@ bool KisShortcutMatcher::supportsHiResInputEvents()|| (m_d->touchShortcut && m_d->touchShortcut->action()&& m_d->touchShortcut->action()->supportsHiResInputEvents(m_d->touchShortcut->shortcutIndex()))|| (m_d->nativeGestureShortcut && m_d->nativeGestureShortcut->action()- && m_d->nativeGestureShortcut->action()->supportsHiResInputEvents(m_d->nativeGestureShortcut->shortcutIndex()));+ && m_d->nativeGestureShortcut->action()->supportsHiResInputEvents(m_d->nativeGestureShortcut->shortcutIndex()))+ || (m_d->touchpadScrollShortcut && m_d->touchpadScrollShortcut->action()+ && m_d->touchpadScrollShortcut->action()->supportsHiResInputEvents(m_d->touchpadScrollShortcut->shortcutIndex()));}bool KisShortcutMatcher::keyPressed(Qt::Key key)@@ -843,8 +856,7 @@ bool KisShortcutMatcher::nativeGestureEndEvent(QNativeGestureEvent *event)DEBUG_EVENT_ACTION("entered", event);- // TODO: why &&?- if ( m_d->nativeGestureShortcut && !m_d->nativeGestureShortcut->match( event ) ) {+ if (m_d->nativeGestureShortcut) {tryEndNativeGestureShortcut( event );}@@ -858,6 +870,69 @@ bool KisShortcutMatcher::nativeGestureEndEvent(QNativeGestureEvent *event)return true;}+bool KisShortcutMatcher::hasTouchpadScrollShortcuts() const+{+ return !m_d->touchpadScrollShortcuts.isEmpty();+}++bool KisShortcutMatcher::touchpadScrollBeginEvent(QWheelEvent *event)+{+ Private::RecursionNotifier notifier(this);++ if (notifier.isInRecursion()) return false;++ DEBUG_EVENT_ACTION("entered", event);++ if (!hasRunningShortcut()) {+ tryRunTouchpadScrollShortcut(event);+ }++ if (m_d->touchpadScrollShortcut) {+ m_d->touchpadScrollShortcut->action()->inputEvent(event);+ }++ return bool(m_d->touchpadScrollShortcut);+}++bool KisShortcutMatcher::touchpadScrollEvent(QWheelEvent *event)+{+ Private::RecursionNotifier notifier(this);++ if (notifier.isInRecursion()) return false;++ DEBUG_EVENT_ACTION("entered", event);++ if (m_d->touchpadScrollShortcut) {+ m_d->touchpadScrollShortcut->action()->inputEvent(event);+ }++ return bool(m_d->touchpadScrollShortcut);+}++bool KisShortcutMatcher::touchpadScrollEndEvent(QWheelEvent *event)+{+ Private::RecursionNotifier notifier(this);++ if (notifier.isInRecursion()) return false;++ DEBUG_EVENT_ACTION("entered", event);++ bool retval = false;++ if (m_d->touchpadScrollShortcut) {+ retval = tryEndTouchpadScrollShortcut(event);+ }++ if (notifier.isInRecursion()) {+ forceDeactivateAllActions();+ } else if (!hasRunningShortcut()) {+ prepareReadyShortcuts();+ tryActivateReadyShortcut();+ }++ return retval;+}+Qt::MouseButtons listToFlags(const QList<Qt::MouseButton> &list) {Qt::MouseButtons flags;Q_FOREACH (Qt::MouseButton b, list) {@@ -1039,11 +1114,15 @@ void KisShortcutMatcher::clearShortcuts()qDeleteAll(m_d->nativeGestureShortcuts);m_d->nativeGestureShortcuts.clear();+ qDeleteAll(m_d->touchpadScrollShortcuts);+ m_d->touchpadScrollShortcuts.clear();+m_d->candidateShortcuts.clear();m_d->runningShortcut = 0;m_d->readyShortcut = 0;m_d->touchShortcut = 0;m_d->nativeGestureShortcut = 0;+ m_d->touchpadScrollShortcut = 0;}void KisShortcutMatcher::setInputActionGroupsMaskCallback(std::function<KisInputActionGroupsMask ()> func)@@ -1392,14 +1471,15 @@ bool KisShortcutMatcher::tryEndTouchShortcut( QTouchEvent* event )return false;}-bool KisShortcutMatcher::tryRunNativeGestureShortcut(QNativeGestureEvent* event)+template <typename EventType, typename ShortcutType>+bool KisShortcutMatcher::tryRunGestureBasedShortcutImpl(EventType *event, ShortcutType **resultShortcutPtr, const QList<ShortcutType*> allTypedShortcuts){- KisNativeGestureShortcut *goodCandidate = 0;+ ShortcutType *goodCandidate = 0;if (m_d->actionsSuppressed())return false;- Q_FOREACH (KisNativeGestureShortcut* shortcut, m_d->nativeGestureShortcuts) {+ Q_FOREACH (ShortcutType* shortcut, allTypedShortcuts) {if (shortcut->match(event) && (!goodCandidate || shortcut->priority() > goodCandidate->priority())) {goodCandidate = shortcut;}@@ -1412,7 +1492,7 @@ bool KisShortcutMatcher::tryRunNativeGestureShortcut(QNativeGestureEvent* event)// deactivate an activated readyShortcut, to not throw other statemachines out of place.forceDeactivateAllActions();- m_d->nativeGestureShortcut = goodCandidate;+ *resultShortcutPtr = goodCandidate;Private::RecursionGuard guard(this);@@ -1424,29 +1504,29 @@ bool KisShortcutMatcher::tryRunNativeGestureShortcut(QNativeGestureEvent* event)// the tool might have opened some dialog, which could break our event loopif (guard.brokenByRecursion()) {goodCandidate->action()->end(event);- m_d->nativeGestureShortcut = 0;+ *resultShortcutPtr = 0;forceDeactivateAllActions();}}- return m_d->nativeGestureShortcut;+ return bool(*resultShortcutPtr);}-bool KisShortcutMatcher::tryEndNativeGestureShortcut(QNativeGestureEvent* event)+template <typename EventType, typename ShortcutType>+bool KisShortcutMatcher::tryEndGestureBasedShortcutImpl(EventType *event, ShortcutType **resultShortcutPtr){Private::RecursionNotifier notifier(this);- if (m_d->nativeGestureShortcut) {+ if (*resultShortcutPtr) {// first reset running shortcut to avoid infinite recursion via end()- KisNativeGestureShortcut *nativeGestureShortcut = m_d->nativeGestureShortcut;-- DEBUG_SHORTCUT("ending", nativeGestureShortcut)+ ShortcutType *runningShortcut = *resultShortcutPtr;+ *resultShortcutPtr = nullptr;- nativeGestureShortcut->action()->end(event);- nativeGestureShortcut->action()->deactivate(m_d->nativeGestureShortcut->shortcutIndex());+ DEBUG_SHORTCUT("ending", runningShortcut)- m_d->nativeGestureShortcut = 0; // empty it out now that we are done with it+ runningShortcut->action()->end(event);+ runningShortcut->action()->deactivate(runningShortcut->shortcutIndex());return true;}@@ -1461,6 +1541,26 @@ bool KisShortcutMatcher::tryEndNativeGestureShortcut(QNativeGestureEvent* event)return false;}+bool KisShortcutMatcher::tryRunNativeGestureShortcut(QNativeGestureEvent* event)+{+ return tryRunGestureBasedShortcutImpl(event, &m_d->nativeGestureShortcut, m_d->nativeGestureShortcuts);+}++bool KisShortcutMatcher::tryEndNativeGestureShortcut(QNativeGestureEvent* event)+{+ return tryEndGestureBasedShortcutImpl(event, &m_d->nativeGestureShortcut);+}++bool KisShortcutMatcher::tryRunTouchpadScrollShortcut(QWheelEvent* event)+{+ return tryRunGestureBasedShortcutImpl(event, &m_d->touchpadScrollShortcut, m_d->touchpadScrollShortcuts);+}++bool KisShortcutMatcher::tryEndTouchpadScrollShortcut(QWheelEvent* event)+{+ return tryEndGestureBasedShortcutImpl(event, &m_d->touchpadScrollShortcut);+}+int KisShortcutMatcher::touchHoldDelay() const{return m_d->touchHoldDelayMs;diff --git a/libs/ui/input/kis_shortcut_matcher.h b/libs/ui/input/kis_shortcut_matcher.hindex 3a464521db..93140763ff 100644--- a/libs/ui/input/kis_shortcut_matcher.h+++ b/libs/ui/input/kis_shortcut_matcher.h@@ -23,6 +23,7 @@ class QPointF;class KisStrokeShortcut;class KisTouchShortcut;class KisNativeGestureShortcut;+class KisTouchpadScrollShortcut;/**@@ -82,11 +83,13 @@ public:bool hasRunningShortcut() const;bool hasTouchHoldShortcut() const;+ bool hasTouchpadScrollShortcuts() const;void addShortcut(KisSingleActionShortcut *shortcut);void addShortcut(KisStrokeShortcut *shortcut);void addShortcut(KisTouchShortcut *shortcut);void addShortcut(KisNativeGestureShortcut *shortcut);+ void addShortcut(KisTouchpadScrollShortcut *shortcut);/*** Returns true if the currently running shortcut supports@@ -191,6 +194,10 @@ public:bool nativeGestureEvent(QNativeGestureEvent *event);bool nativeGestureEndEvent(QNativeGestureEvent *event);+ bool touchpadScrollBeginEvent(QWheelEvent *event);+ bool touchpadScrollEvent(QWheelEvent *event);+ bool touchpadScrollEndEvent(QWheelEvent *event);+/*** Resets the internal state of the matcher and activates the* prepared action if possible.@@ -338,9 +345,17 @@ private:bool tryEndTouchShortcut(QTouchEvent *event);void tryCancelAllCurrentTouchActionsImpl();+ template <typename EventType, typename ShortcutType>+ bool tryRunGestureBasedShortcutImpl(EventType *event, ShortcutType **resultShortcutPtr, const QList<ShortcutType*> allTypedShortcuts);+ template <typename EventType, typename ShortcutType>+ bool tryEndGestureBasedShortcutImpl(EventType *event, ShortcutType **resultShortcutPtr);+bool tryRunNativeGestureShortcut(QNativeGestureEvent *event);bool tryEndNativeGestureShortcut(QNativeGestureEvent *event);+ bool tryRunTouchpadScrollShortcut(QWheelEvent* event);+ bool tryEndTouchpadScrollShortcut(QWheelEvent* event);+private:class Private;Private * const m_d;diff --git a/libs/ui/tests/KisInputProfileManagerTest.cpp b/libs/ui/tests/KisInputProfileManagerTest.cppindex ea4c09c5f6..02a0ef4566 100644--- a/libs/ui/tests/KisInputProfileManagerTest.cpp+++ b/libs/ui/tests/KisInputProfileManagerTest.cpp@@ -23,6 +23,7 @@// for native gestures migration testing#include <input/KisInputProfileMigrator.h>#include <input/kis_zoom_and_rotate_action.h>+#include <input/kis_pan_action.h>void KisInputProfileManagerTest::testProfileCreation()@@ -36,6 +37,13 @@ void KisInputProfileManagerTest::testProfileCreation()QCOMPARE(profileManager->currentProfile(), profile);}+void KisInputProfileManagerTest::testLoadProfileV6_data()+{+ QTest::addColumn<QString>("mode");+ QTest::addRow("native-gesture-convert") << "pinch-gesture";+ QTest::addRow("wheel-to-touchpad-scroll-convert") << "touchpad-scroll";+}+void KisInputProfileManagerTest::testLoadProfileV6(){auto *profileManager = KisInputProfileManager::instance();@@ -58,32 +66,64 @@ void KisInputProfileManagerTest::testLoadProfileV6()QList< KisShortcutConfiguration* > shortcuts = profile->allShortcuts();- KisShortcutConfiguration *foundNativeGestureShortcut = nullptr;- int numInvalidNativeGestureShortcuts = 0;- int totalNativeGestureShortcuts = 0;+ QFETCH(QString, mode);++ if (mode == "pinch-gesture") {+ KisShortcutConfiguration *foundNativeGestureShortcut = nullptr;+ int numInvalidNativeGestureShortcuts = 0;+ int totalNativeGestureShortcuts = 0;++ Q_FOREACH(KisShortcutConfiguration *shortcut, shortcuts) {+ if (shortcut->type() == KisShortcutConfiguration::NativeGestureType) {+ if (shortcut->nativeGesture() == KisShortcutConfiguration::PinchGesture) {+ totalNativeGestureShortcuts++;+ foundNativeGestureShortcut = shortcut;+ }+ if (shortcut->nativeGesture() > KisShortcutConfiguration::PinchGesture &&+ shortcut->nativeGesture() < KisShortcutConfiguration::SmartZoomGesture) {+ numInvalidNativeGestureShortcuts++;+ }+ }+ }++ if (foundNativeGestureShortcut) {+ QCOMPARE(foundNativeGestureShortcut->action()->id(), "Zoom and Rotate Canvas");+ QCOMPARE(foundNativeGestureShortcut->mode(), KisZoomAndRotateAction::PanAndZoomAndRotateMode);- Q_FOREACH(KisShortcutConfiguration *shortcut, shortcuts) {- if (shortcut->type() == KisShortcutConfiguration::NativeGestureType) {- if (shortcut->nativeGesture() == KisShortcutConfiguration::PinchGesture) {- totalNativeGestureShortcuts++;- foundNativeGestureShortcut = shortcut;+ }++ QCOMPARE(totalNativeGestureShortcuts, 1);+ QCOMPARE(numInvalidNativeGestureShortcuts, 0);+ } else if (mode == "touchpad-scroll") {+ KisShortcutConfiguration *foundTouchpadScrollShortcut = nullptr;+ int totalTouchpadScrollShortcuts = 0;+ int numInvalidWheelShortcuts = 0;++ Q_FOREACH(KisShortcutConfiguration *shortcut, shortcuts) {+ if (shortcut->type() == KisShortcutConfiguration::MouseWheelType) {+ if (shortcut->wheel() == KisShortcutConfiguration::WheelReserved_0) {+ numInvalidWheelShortcuts++;+ }}- if (shortcut->nativeGesture() > KisShortcutConfiguration::PinchGesture &&- shortcut->nativeGesture() < KisShortcutConfiguration::SmartZoomGesture) {- numInvalidNativeGestureShortcuts++;+ if (shortcut->type() == KisShortcutConfiguration::NativeGestureType) {+ if (shortcut->nativeGesture() == KisShortcutConfiguration::TouchpadScroll) {+ totalTouchpadScrollShortcuts++;+ foundTouchpadScrollShortcut = shortcut;+ }}}- }- if (foundNativeGestureShortcut) {- QCOMPARE(foundNativeGestureShortcut->action()->id(), "Zoom and Rotate Canvas");- QCOMPARE(foundNativeGestureShortcut->mode(), KisZoomAndRotateAction::PanAndZoomAndRotateMode);+ QCOMPARE(totalTouchpadScrollShortcuts, 1);+ if (foundTouchpadScrollShortcut) {+ QCOMPARE(foundTouchpadScrollShortcut->action()->id(), "Pan Canvas");+ QCOMPARE(foundTouchpadScrollShortcut->mode(), KisPanAction::PanModeShortcut);+ }+ QCOMPARE(numInvalidWheelShortcuts, 0);+ } else {+ qFatal("Unknown testing mode: %s", mode.toLatin1().data());}- QCOMPARE(totalNativeGestureShortcuts, 1);- QCOMPARE(numInvalidNativeGestureShortcuts, 0);-profileManager->removeProfile(profile->name());}@@ -157,6 +197,7 @@ void KisInputProfileManagerTest::testShortcutConfigurationNativeGesture_data()QTest::addRow("PinchGesture") << KisShortcutConfiguration::PinchGesture << "{3;5;[];0;0;1}";QTest::addRow("SmartZoomGesture") << KisShortcutConfiguration::SmartZoomGesture << "{3;5;[];0;0;4}";+ QTest::addRow("TouchpadScroll") << KisShortcutConfiguration::TouchpadScroll << "{3;5;[];0;0;5}";}void KisInputProfileManagerTest::testShortcutConfigurationNativeGesture()diff --git a/libs/ui/tests/KisInputProfileManagerTest.h b/libs/ui/tests/KisInputProfileManagerTest.hindex 258ad8e397..f50378e331 100644--- a/libs/ui/tests/KisInputProfileManagerTest.h+++ b/libs/ui/tests/KisInputProfileManagerTest.h@@ -15,6 +15,7 @@ class KisInputProfileManagerTest : public QObjectprivate Q_SLOTS:void testProfileCreation();+ void testLoadProfileV6_data();void testLoadProfileV6();void testShortcutConfigurationTouchGesture_data();