From f3b90a2ffa3bd3ba8221227158b849328859f274 Mon Sep 17 00:00:00 2001 From: taj-ny <79316397+taj-ny@users.noreply.github.com> Date: Tue, 24 Dec 2024 22:37:38 +0100 Subject: [PATCH] add ability to create more complex gestures --- README.md | 10 +- docs/configuration.md | 97 ++++++++++------- flake.lock | 14 +-- flake.nix | 2 +- src/kwin/config/config.cpp | 39 +++++-- src/kwin/impl/kwininput.cpp | 34 ++++-- src/kwin/impl/kwininput.h | 5 +- .../libgestures/actions/action.cpp | 77 +++++++++---- src/libgestures/libgestures/actions/action.h | 67 ++++++++---- .../libgestures/actions/command.cpp | 8 +- src/libgestures/libgestures/actions/command.h | 2 +- .../libgestures/actions/kdeglobalshortcut.cpp | 8 +- .../libgestures/actions/kdeglobalshortcut.h | 2 +- .../libgestures/actions/keysequence.cpp | 9 +- .../libgestures/actions/keysequence.h | 2 +- .../libgestures/gestures/gesture.cpp | 103 ++++++++++-------- .../libgestures/gestures/gesture.h | 38 +++---- .../gestures/gesturerecognizer.cpp | 48 +++++++- .../libgestures/gestures/gesturerecognizer.h | 12 +- .../libgestures/gestures/pinchgesture.cpp | 13 --- .../libgestures/gestures/pinchgesture.h | 4 +- .../libgestures/gestures/swipegesture.cpp | 5 - .../libgestures/gestures/swipegesture.h | 4 +- src/libgestures/libgestures/input.h | 4 +- tests/libgestures/actions/test_action.cpp | 8 +- 25 files changed, 400 insertions(+), 215 deletions(-) diff --git a/README.md b/README.md index 754a633..489f604 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ -# KWin Gestures -Custom touchpad gestures for KDE Plasma 6. +0# KWin Gestures +Highly customizable custom touchpad gestures for KDE Plasma 6. -Tested on 6.1.5 and 6.2. X11 is not supported. +Gestures are handled by **libgestures**, which is included in the project. It doesn't depend on KWin, so it could be used for other window managers or as a standalone application for X11. + +X11 is currently not supported. # Features -- Override built-in gestures +- Override built-in KWin gestures - Application-specific gestures # Installation diff --git a/docs/configuration.md b/docs/configuration.md index 6fa634e..e1a9dca 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1,55 +1,78 @@ # Configuration -There is currently no configuration UI and there probably won't be one. The configuration file is located at ``~/.config/kwingesturesrc``. The format may change at any time until 1.0.0 is released. Any changes will be mentioned in the release description. +> [!NOTE] +> The configuration format may change at any time until v1.0.0 is released. You will have to make manual changes to your configuration file. All changes will be mentioned in the release description. -Run ``qdbus org.kde.KWin /Effects org.kde.kwin.Effects.reconfigureEffect kwin_gestures`` or toggle the effect in system settings after updating the file. +There is currently no configuration UI and I have no intention of making one. + +The configuration file is located at ``~/.config/kwingesturesrc`` and **is not created automatically after installation**. Run ``qdbus org.kde.KWin /Effects org.kde.kwin.Effects.reconfigureEffect kwin_gestures`` or toggle the effect in system settings after updating it. See [example_gestures.md](example_gestures.md) for examples. -### Configuration file structure +Feel free to open an issue if something is unclear for you. +### Configuration file structure - **[Gestures]** - - **[$Device]** (enum) - Which device to add this gesture for (``Touchpad``).
- - **[$GestureId]** (int) - Unique ID for the gesture. - - **Type** (enum) - ``Hold``, ``Pinch``, ``Swipe`` - - **Fingers** (int) - Number of fingers required to trigger this gesture.
Sets **MinimumFingers** and **MaximumFingers**.
Minimum value: **2** for hold and pinch gestures, **3** for swipe.
Default: **none** - - **MinimumFingers** (int) - Minimum number of fingers required to trigger this gesture.
See **Fingers** for accepted values.
Default: **none** - - **MaximumFingers** (int) - Maximum number of fingers required to trigger this gesture.
See **Fingers** for accepted values.
Default: **none** - - **TriggerWhenThresholdReached** (bool) - Whether to trigger the gesture immediately after the specified threshold is reached.
Default: **false**  - - **[Hold]** - Configuration for hold gestures. - - **Threshold** (int) - In milliseconds.
Default: **0** - - **[Pinch]** - Configuration for pinch gestures. - - **Direction** (enum) - - ``Contracting`` - - ``Expanding`` - - ``Any`` - Either contracting or expanding, intended for repeating actions. - - **Threshold** (float) - Should be >= 1.0 for expanding gestures and =< 1.0 for contracting gestures.
Default: **1.0** - - **[Swipe]** - Configuration for swipe gestures. - - **Direction** (enum) + - **[$Device]** (enum) - Which device to add this gesture for (currently only ``Touchpad`` is supported).
+ - **[GestureRecognizer]** - Configuration for the gesture recognizer. + - **[Speed]** - Configuration for the determination of gesture speed. If the fast threshold is reached, the gesture will be treated as a fast gesture, otherwise as a slow one. + - **SampledEvents** (int) - How many input events to sample in order to determine the gesture speed. The deltas of each event are summed and compared against the specified thresholds.
Default: **5**

+ + - **SwipeThreshold** (int)
Default: **300**

+ + - **PinchContractingThreshold** (float)
Default: **0.4** + - **PinchExpandingThreshold** (float)
Default: **2.0**

+ - **[$GestureId]** (int) - Unique ID for the gesture. Gestures are handled in ascending order by their ID. + - **Type** (enum, **required**) - ``Hold``, ``Pinch``, ``Swipe``
Default: **none** + - **Direction** (enum, **required**) + - For pinch gestures: + - ``Contracting`` - Pinch in. + - ``Expanding`` - Pinch out. + - ``Any`` - Either contracting or expanding. + - For swipe gestures: - ``Left`` - ``Right`` - ``Up`` - ``Down`` - - ``LeftRight`` - Either left or right, intended for repeating actions. - - ``UpDown`` - Either up or down, intended for repeating actions. - - **Threshold** (int) - Threshold in pixels for the X axis if **Direction** is ``Left``, ``Right`` or ``LeftRight``, and Y axis if **Direction** is ``Up``, ``Down`` or ``UpDown``.
Must be positive.
Default: **0**
  + - ``LeftRight`` - Either left or right. + - ``UpDown`` - Either up or down.
+ - **Speed** (enum) - ``Slow``, ``Fast``, ``Any``
If a value other than ``Any`` is specified, this gesture will cause all other gestures of the same device and type to be delayed by **[Gestures][\$Device][GestureRecognizer][Speed] SampledEvents** input events until the speed is determined.
Default: **Any** + - **Fingers** (int) - Number of fingers required to trigger this gesture.
Sets **MinimumFingers** and **MaximumFingers**.
Minimum value: **1** for hold gestures, **2** for pinch gestures, **3** for swipe.
Maximum value: Depends on how many fingers the device can detect.
Default: **none** + - **MinimumFingers** (int) - Minimum number of fingers required to trigger this gesture.
See **Fingers**.
Default: **none** + - **MaximumFingers** (int) - Maximum number of fingers required to trigger this gesture.
See **Fingers**.
Default: **none** + - **MinimumThreshold** - TODO + - **MaximumThreshold** - TODO

+ - **[Conditions]** - At least one condition (or 0 if none specified) must be satisfied in order for this gesture to be triggered. - - **[$ConditionId]** (int) - Unique ID for this condition. - - **Negate** (bool) - If true, this condition will be satisfied only when none of its specified properties are.
Default: **false** + - **[$ConditionId]** (int) - Unique ID for this condition. Conditions are handled in ascending order by their ID. + - **Negate** (bool) - If true, this condition will be satisfied only when none of its specified subconditions are.
Default: **false** - **WindowClassRegex** (string) - A regular expression executed on the currently focused window's resource class and resource name. If a match is not found for either, the condition will not be satisfied.
Default: **none** - - **WindowState** (enum) - ``Fullscreen``, ``Maximized``. Values can be combined using the | separator, For example, ``Fullscreen|Maximized`` will match either fullscreen or maximized windows.
Default: **none**
  - - **[Actions]** - What do to when the gesture is triggered. Actions are executed in order as they appear in the configuration file. - - **[$ActionId]** (int) - Unique ID for this action. + - **WindowState** (enum) - ``Fullscreen``, ``Maximized``. Values can be combined using the | separator, For example, ``Fullscreen|Maximized`` will match either fullscreen or maximized windows.
Default: **none**

+ + - **[Actions]** - What do to when the gesture is triggered. + - **[$ActionId]** (int) - Unique ID for this action. Actions are handled in ascending order by their ID. - **Type** (enum) - ``Command`` - Run a command. - - ``GlobalShortcut`` - Invoke a global shortcut. - - ``KeySequence`` - Send keystrokes. - - **RepeatInterval** (int/float) - Whether and how often this action should repeat.
Can be negative for all gestures except hold.
Default: **0 (no repeating)** - - **BlockOtherActions** (bool) - Whether this action should block other actions if triggered.
Default: **false**
  + - ``GlobalShortcut`` - Invoke a global shortcut (KDE). + - ``KeySequence`` - Send keystrokes.
+ **Required** + - **When** (enum) - When the action should be triggered.
+ For actions that should trigger after the fingers have been lifted, use ``Ended`` and optionally specify **MinimumThreshold** and **MaximumThreshold**.
+ For actions that should trigger immediately when the specified **MinimumThreshold** is reached, use ``Updated``.
+ - ``Started`` - When the gesture has started. + - ``Ended`` - When the gesture has ended. + - ``Cancelled`` - When the gesture has been cancelled. A gesture can be cancelled for example when a finger is lifted or the direction changes. + - ``Updated`` - When the gesture has been updated. Can only be executed once, unless **RepeatInterval** is specified. + - ``EndedOrCancelled`` - Both ``Ended`` and ``Cancelled``. + - **RepeatInterval** (int/float) - Whether and how often an ``Update`` action should repeat.
Can be negative for all gestures except hold.
Default: **0 (no repeating)** + - **BlockOtherActions** (bool) - Whether this action should block other actions if triggered.
Default: **false** + - **MinimumThreshold** - Same as **[Gestures][\$Device][$GestureId] MinimumThreshold**, but only applied to this action.
+ - **MinimumThreshold** - Same as **[Gestures][\$Device][$GestureId] MaximumThreshold**, but only applied to this action.

+ - **[Command]** - Configuration for the GlobalShortcut action. - - **Command** (string) - The command to run.
Default: **none** + - **Command** (string, **required**) - The command to run.
Default: **none**
**Required** - **[GlobalShortcut]** - Configuration for the GlobalShortcut action. - - **Component** (string) - Run ``qdbus org.kde.kglobalaccel | grep /component`` for the list of components. Don't put the ``/component/`` prefix here.
Default: **none** - - **Shortcut** (string) - Run ``qdbus org.kde.kglobalaccel /component/$component org.kde.kglobalaccel.Component.shortcutNames`` for the list of shortcuts.
Default: **none** + - **Component** (string, **required**) - Run ``qdbus org.kde.kglobalaccel | grep /component`` for the list of components. Don't put the ``/component/`` prefix here.
Default: **none** + - **Shortcut** (string, **required**) - Run ``qdbus org.kde.kglobalaccel /component/$component org.kde.kglobalaccel.Component.shortcutNames`` for the list of shortcuts.
Default: **none** - **[KeySequence]** - Configuration for the KeySequence action. - - **Sequence** (string) - The key sequence to run. Case-sensitive. Invalid format will cause a crash (for now). For the full list of keys see [src/gestures/actions/keysequence.h](src/gestures/actions/keysequence.h).
Example: ``press LEFTCTRL,keyboardPressKey T,release LEFTCTRL,keyboardReleaseKey T``.
Default: **none**
  - - **[Conditions]** - Same as **[Gestures][\$Device][$GestureId][Conditions]**, but only applied to this action. + - **Sequence** (string, **required**) - The key sequence to run. Keys can be pressed in one action and released in another.
For the full list of keys see [src/gestures/actions/keysequence.h](src/gestures/actions/keysequence.h).
Example: ``press LEFTCTRL,press T,release LEFTCTRL,release T``.
Default: **none**

+ - **[Conditions]** - Same as **[Gestures][\$Device][$GestureId][Conditions]**, but only applied to this action. \ No newline at end of file diff --git a/flake.lock b/flake.lock index 8c72b9f..42d5e24 100644 --- a/flake.lock +++ b/flake.lock @@ -2,17 +2,17 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1727348695, - "narHash": "sha256-J+PeFKSDV+pHL7ukkfpVzCOO7mBSrrpJ3svwBFABbhI=", + "lastModified": 1732837521, + "narHash": "sha256-jNRNr49UiuIwaarqijgdTR2qLPifxsVhlJrKzQ8XUIE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "1925c603f17fc89f4c8f6bf6f631a802ad85d784", + "rev": "970e93b9f82e2a0f3675757eb0bfc73297cc6370", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "1925c603f17fc89f4c8f6bf6f631a802ad85d784", + "rev": "970e93b9f82e2a0f3675757eb0bfc73297cc6370", "type": "github" } }, @@ -42,11 +42,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1726560853, - "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 9d3e1f2..4239238 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "Custom touchpad and touchscreen shortcuts"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/1925c603f17fc89f4c8f6bf6f631a802ad85d784"; + nixpkgs.url = "github:NixOS/nixpkgs/970e93b9f82e2a0f3675757eb0bfc73297cc6370"; utils.url = "github:numtide/flake-utils"; }; diff --git a/src/kwin/config/config.cpp b/src/kwin/config/config.cpp index ca24e95..becc470 100644 --- a/src/kwin/config/config.cpp +++ b/src/kwin/config/config.cpp @@ -33,7 +33,6 @@ void Config::read(std::shared_ptr filter, std::shared_p { minimumFingers = maximumFingers = fingers; } - const bool triggerWhenThresholdReached = gestureGroup.readEntry("TriggerWhenThresholdReached", false); std::shared_ptr gesture; if (gestureType == "Hold") @@ -41,7 +40,6 @@ void Config::read(std::shared_ptr filter, std::shared_p const auto holdGestureGroup = gestureGroup.group("Hold"); const auto holdGesture = std::make_shared(); - holdGesture->setThreshold(holdGestureGroup.readEntry("Threshold", 0)); filter->registerTouchpadGesture(holdGesture); gesture = holdGesture; } @@ -50,14 +48,13 @@ void Config::read(std::shared_ptr filter, std::shared_p const auto pinchGestureGroup = gestureGroup.group("Pinch"); const auto pinchGesture = std::make_shared(); - const auto directionStr = pinchGestureGroup.readEntry("Direction", ""); + const auto directionStr = gestureGroup.readEntry("Direction", ""); libgestures::PinchDirection direction = libgestures::PinchDirection::Any; if (directionStr == "Contracting") direction = libgestures::PinchDirection::Contracting; else if (directionStr == "Expanding") direction = libgestures::PinchDirection::Expanding; pinchGesture->setDirection(direction); - pinchGesture->setThreshold(pinchGestureGroup.readEntry("Threshold", 1.0)); filter->registerTouchpadGesture(pinchGesture); gesture = pinchGesture; @@ -67,7 +64,7 @@ void Config::read(std::shared_ptr filter, std::shared_p const auto swipeGestureGroup = gestureGroup.group("Swipe"); const auto swipeGesture = std::make_shared(); - const auto directionString = swipeGestureGroup.readEntry("Direction", "Left"); + const auto directionString = gestureGroup.readEntry("Direction", "Left"); auto direction = libgestures::SwipeDirection::Left; if (directionString == "Right") direction = libgestures::SwipeDirection::Right; @@ -80,14 +77,22 @@ void Config::read(std::shared_ptr filter, std::shared_p else if (directionString == "UpDown") direction = libgestures::SwipeDirection::UpDown; swipeGesture->setDirection(direction); - swipeGesture->setThreshold(swipeGestureGroup.readEntry("Threshold", 0.0)); filter->registerTouchpadGesture(swipeGesture); gesture = swipeGesture; } + const auto speedStr = gestureGroup.readEntry("Speed", "Any"); + libgestures::GestureSpeed speed = libgestures::GestureSpeed::Any; + if (speedStr == "Slow") + speed = libgestures::GestureSpeed::Slow; + else if (speedStr == "Fast") + speed = libgestures::GestureSpeed::Fast; + gesture->setSpeed(speed); + gesture->setFingers(minimumFingers, maximumFingers); - gesture->setTriggerWhenThresholdReached(triggerWhenThresholdReached); + gesture->setThresholds(gestureGroup.readEntry("MinimumThreshold", -1.0), + gestureGroup.readEntry("MaximumThreshold", -1.0)); if (!gesture) continue; @@ -125,6 +130,26 @@ void Config::read(std::shared_ptr filter, std::shared_p if (!action) continue; + libgestures::When when; + auto whenStr = actionGroup.readEntry("When", ""); + if (whenStr == "Started") + when = libgestures::When::Started; + else if (whenStr == "Ended") + when = libgestures::When::Ended; + else if (whenStr == "Updated") + when = libgestures::When::Updated; + else if (whenStr == "Cancelled") + when = libgestures::When::Cancelled; + else if (whenStr == "EndedOrCancelled") + when = libgestures::When::EndedOrCancelled; + action->setWhen(when); + + action->setThresholds(actionGroup.readEntry("MinimumThreshold", -1.0), + actionGroup.readEntry("MaximumThreshold", -1.0)); + +// action->setTriggerWhenThresholdReached(actionGroup.readEntry("TriggerWhenThresholdReached", false)); + + action->setRepeatInterval(actionGroup.readEntry("RepeatInterval", 0.0)); action->setBlockOtherActions(actionGroup.readEntry("BlockOtherActions", false)); diff --git a/src/kwin/impl/kwininput.cpp b/src/kwin/impl/kwininput.cpp index ea1979a..1c347dc 100644 --- a/src/kwin/impl/kwininput.cpp +++ b/src/kwin/impl/kwininput.cpp @@ -2,6 +2,7 @@ #include "input_event_spy.h" #include "keyboard_input.h" #include "kwininput.h" +#include #include "wayland/keyboard.h" #include "xkb.h" @@ -16,13 +17,29 @@ KWinInput::~KWinInput() KWin::input()->removeInputDevice(m_device.get()); } -void KWinInput::keyboardPress(const uint32_t &key) const +void KWinInput::keyboardPress(const uint32_t &key) { sendKey(key, KWin::InputRedirection::KeyboardKeyState::KeyboardKeyPressed); -} - -void KWinInput::keyboardRelease(const uint32_t &key) const -{ + if (key == KEY_LEFTALT || key == KEY_RIGHTALT) + m_modifiers |= Qt::KeyboardModifier::AltModifier; + else if (key == KEY_LEFTSHIFT || key == KEY_RIGHTSHIFT) + m_modifiers |= Qt::KeyboardModifier::ShiftModifier; + else if (key == KEY_LEFTCTRL || key == KEY_RIGHTCTRL) + m_modifiers |= Qt::KeyboardModifier::ControlModifier; + else if (key == KEY_LEFTMETA || key == KEY_RIGHTMETA) + m_modifiers |= Qt::KeyboardModifier::MetaModifier; +} + +void KWinInput::keyboardRelease(const uint32_t &key) +{ + if (key == KEY_LEFTALT || key == KEY_RIGHTALT) + m_modifiers &= ~Qt::KeyboardModifier::AltModifier; + else if (key == KEY_LEFTSHIFT || key == KEY_RIGHTSHIFT) + m_modifiers &= ~Qt::KeyboardModifier::ShiftModifier; + else if (key == KEY_LEFTCTRL || key == KEY_RIGHTCTRL) + m_modifiers &= ~Qt::KeyboardModifier::ControlModifier; + else if (key == KEY_LEFTMETA || key == KEY_RIGHTMETA) + m_modifiers &= ~Qt::KeyboardModifier::MetaModifier; sendKey(key, KWin::InputRedirection::KeyboardKeyState::KeyboardKeyReleased); } @@ -33,11 +50,10 @@ void KWinInput::sendKey(const uint32_t &key, const KWin::InputRedirection::Keybo xkb->updateKey(key, state); const xkb_keysym_t keySym = xkb->toKeysym(key); - const Qt::KeyboardModifiers globalShortcutsModifiers = xkb->modifiersRelevantForGlobalShortcuts(key); KWin::KeyEvent event( state == KWin::InputRedirection::KeyboardKeyPressed ? QEvent::KeyPress : QEvent::KeyRelease, - xkb->toQtKey(keySym, key, globalShortcutsModifiers ? Qt::ControlModifier : Qt::KeyboardModifiers()), - Qt::KeyboardModifier::NoModifier, + xkb->toQtKey(keySym, key, m_modifiers), + m_modifiers, key, keySym, xkb->toString(xkb->currentKeysym()), @@ -45,7 +61,7 @@ void KWinInput::sendKey(const uint32_t &key, const KWin::InputRedirection::Keybo std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()), m_device.get()); event.setAccepted(false); - event.setModifiersRelevantForGlobalShortcuts(globalShortcutsModifiers); + event.setModifiersRelevantForGlobalShortcuts(m_modifiers); KWin::input()->processSpies(std::bind(&KWin::InputEventSpy::keyEvent, std::placeholders::_1, &event)); KWin::input()->processFilters(std::bind(&KWin::InputEventFilter::keyEvent, std::placeholders::_1, &event)); diff --git a/src/kwin/impl/kwininput.h b/src/kwin/impl/kwininput.h index 9898550..c83d855 100644 --- a/src/kwin/impl/kwininput.h +++ b/src/kwin/impl/kwininput.h @@ -28,10 +28,11 @@ class KWinInput : public libgestures::Input KWinInput(); ~KWinInput() override; - void keyboardPress(const uint32_t &key) const override; - void keyboardRelease(const uint32_t &key) const override; + void keyboardPress(const uint32_t &key) override; + void keyboardRelease(const uint32_t &key) override; private: void sendKey(const uint32_t &key, const KWin::InputRedirection::KeyboardKeyState &state) const; + Qt::KeyboardModifiers m_modifiers; std::unique_ptr m_device; }; \ No newline at end of file diff --git a/src/libgestures/libgestures/actions/action.cpp b/src/libgestures/libgestures/actions/action.cpp index 183ce7b..ea9ec56 100644 --- a/src/libgestures/libgestures/actions/action.cpp +++ b/src/libgestures/libgestures/actions/action.cpp @@ -24,15 +24,25 @@ bool GestureAction::satisfiesConditions() const }) != m_conditions.end(); } -void GestureAction::execute() +bool GestureAction::thresholdReached() const { + return (m_minimumThreshold == -1 || m_absoluteAccumulatedDelta >= m_minimumThreshold) + && (m_maximumThreshold == -1 || m_absoluteAccumulatedDelta <= m_maximumThreshold); +} + +bool GestureAction::tryExecute() +{ + if (!canExecute() || !thresholdReached()) + return false; + m_triggered = true; Q_EMIT executed(); + return true; } bool GestureAction::canExecute() const { - return m_repeatInterval != 0 || !m_triggered; + return (m_repeatInterval != 0 || !m_triggered) && satisfiesConditions(); } bool GestureAction::blocksOtherActions() const @@ -40,50 +50,66 @@ bool GestureAction::blocksOtherActions() const return m_triggered && m_blockOtherActions; } -void GestureAction::onGestureCancelled() +void GestureAction::onGestureCancelled(bool &actionExecuted) { - if (m_when == When::Cancelled && canExecute() && satisfiesConditions()) - execute(); + if ((m_when == When::Cancelled || m_when == When::EndedOrCancelled) && tryExecute()) + actionExecuted = true; - m_accumulatedDelta = 0; m_triggered = false; + m_accumulatedDelta = 0; + m_absoluteAccumulatedDelta = 0; } -void GestureAction::onGestureEnded() +void GestureAction::onGestureEnded(bool &actionExecuted) { - if (m_when == When::Ended && canExecute() && satisfiesConditions()) - execute(); + if ((m_when == When::Ended || m_when == When::EndedOrCancelled) && tryExecute()) + actionExecuted = true; - m_accumulatedDelta = 0; m_triggered = false; + m_accumulatedDelta = 0; + m_absoluteAccumulatedDelta = 0; } -void GestureAction::onGestureStarted() +void GestureAction::onGestureStarted(bool &actionExecuted) { - if (m_when == When::Started && canExecute() && satisfiesConditions()) - execute(); + if (m_when == When::Started && tryExecute()) + actionExecuted = true; m_triggered = false; m_accumulatedDelta = 0; + m_absoluteAccumulatedDelta = 0; } -void GestureAction::onGestureUpdated(const qreal &delta) +void GestureAction::onGestureUpdated(const qreal &delta, bool &actionExecuted) { - if (m_repeatInterval == 0 || m_when != When::Updated) - return; - if ((m_accumulatedDelta > 0 && delta < 0) || (m_accumulatedDelta < 0 && delta > 0)) { // Direction changed, reset delta m_accumulatedDelta = 0; } else + { m_accumulatedDelta += delta; + m_absoluteAccumulatedDelta += std::abs(delta); + } - while (((m_accumulatedDelta > 0 && m_repeatInterval > 0) || (m_accumulatedDelta < 0 && m_repeatInterval < 0)) && std::abs(m_accumulatedDelta / m_repeatInterval) >= 1) + if (m_when != When::Updated) + return; + + if (repeat()) { - execute(); - m_accumulatedDelta -= m_repeatInterval; + while (((m_accumulatedDelta > 0 && m_repeatInterval > 0) || (m_accumulatedDelta < 0 && m_repeatInterval < 0)) && std::abs(m_accumulatedDelta / m_repeatInterval) >= 1) + { + if (tryExecute()) + actionExecuted = true; + m_accumulatedDelta -= m_repeatInterval; + } + return; + } + + if (tryExecute()) { + qWarning("executing action from updated no repeat"); + actionExecuted = true; } } @@ -97,4 +123,15 @@ void GestureAction::setRepeatInterval(const qreal &interval) m_repeatInterval = interval; } +void GestureAction::setThresholds(const qreal &minimum, const qreal &maximum) +{ + m_minimumThreshold = minimum; + m_maximumThreshold = maximum; +} + +void GestureAction::setWhen(const libgestures::When &when) +{ + m_when = when; +} + } // namespace libgestures \ No newline at end of file diff --git a/src/libgestures/libgestures/actions/action.h b/src/libgestures/libgestures/actions/action.h index 8dbb4c4..a94e5d1 100644 --- a/src/libgestures/libgestures/actions/action.h +++ b/src/libgestures/libgestures/actions/action.h @@ -7,10 +7,11 @@ namespace libgestures enum When { - Cancelled, Ended, Started, - Updated + Updated, + Cancelled, + EndedOrCancelled }; class GestureAction : public QObject @@ -19,10 +20,22 @@ class GestureAction : public QObject public: GestureAction(); - virtual void execute(); - bool canExecute() const; + /** + * Executes the action. This function calls @c canExecute() and will do nothing if it returns @false. + * @return Whether the action has been executed. + */ + virtual bool tryExecute(); - bool repeat() const { return m_repeatInterval != 0; }; + /** + * Whether this action can be executed during a gesture, not necessarily right now. + * @remark @c execute() calls this method. + * @remark This method doesn't check whether the threshold has been reached. + * @return @c true if repeat interval is set or the action hasn't been triggered during a gesture, @c false + * otherwise or when none of the specified conditions have been satisfied. + */ + [[nodiscard]] bool canExecute() const; + + [[nodiscard]] bool repeat() const { return m_repeatInterval != 0; }; /** * @return Whether any other actions belonging to a gesture should not be executed. @c true if the action has been @@ -32,14 +45,10 @@ class GestureAction : public QObject void addCondition(const std::shared_ptr &condition); - /** - * @returns Whether the action satisfies at least one condition specified by the user, @c true when no conditions - * were specified. - */ - bool satisfiesConditions() const; - void setBlockOtherActions(const bool &blockOtherActions); void setRepeatInterval(const qreal &interval); + void setThresholds(const qreal &minimum, const qreal &maximum); + void setWhen(const When &when); signals: /** * Emitted when the action has been executed. @@ -49,34 +58,54 @@ class GestureAction : public QObject /** * Emitted when the gesture this action belongs to has been cancelled. */ - void gestureCancelled(); + void gestureCancelled(bool &actionExecuted); /* * Emitted when the gesture this action belongs to has ended. */ - void gestureEnded(); + void gestureEnded(bool &actionExecuted); /** * Emitted when the gesture this action belongs to has ended has been updated, its threshold reached and * the action's conditions satisfied. */ - void gestureStarted(); + void gestureStarted(bool &actionExecuted); /** * Emitted when the gesture this action belongs to has been updated. */ - void gestureUpdated(const qreal &delta); + void gestureUpdated(const qreal &delta, bool &actionExecuted); private slots: - void onGestureCancelled(); - void onGestureEnded(); - void onGestureStarted(); - void onGestureUpdated(const qreal &delta); + void onGestureCancelled(bool &actionExecuted); + void onGestureEnded(bool &actionExecuted); + void onGestureStarted(bool &actionExecuted); + void onGestureUpdated(const qreal &delta, bool &actionExecuted); private: + /** + * @return Whether the action satisfies at least one condition specified by the user, @c true when no conditions + * were specified. + */ + [[nodiscard]] bool satisfiesConditions() const; + + /** + * @return Whether the accumulated delta fits within the specified range. + */ + [[nodiscard]] bool thresholdReached() const; + bool m_blockOtherActions = false; qreal m_repeatInterval = 0; + qreal m_minimumThreshold = 0; + qreal m_maximumThreshold = 0; + bool m_triggerWhenThresholdReached = 0; std::vector> m_conditions; qreal m_accumulatedDelta = 0; + + /** + * Unlike @c m_accumulatedDelta, this member contains the absolute delta and is not reset when the direction is + * changed or subtracted from. + */ + qreal m_absoluteAccumulatedDelta = 0; bool m_triggered = false; When m_when = When::Updated; diff --git a/src/libgestures/libgestures/actions/command.cpp b/src/libgestures/libgestures/actions/command.cpp index f0c2ae8..6095e90 100644 --- a/src/libgestures/libgestures/actions/command.cpp +++ b/src/libgestures/libgestures/actions/command.cpp @@ -3,10 +3,14 @@ namespace libgestures { -void CommandGestureAction::execute() +bool CommandGestureAction::tryExecute() { - GestureAction::execute(); + if (!GestureAction::tryExecute()) + return false; + std::ignore = std::system((m_command + " &").toStdString().c_str()); + + return true; } void CommandGestureAction::setCommand(const QString &command) diff --git a/src/libgestures/libgestures/actions/command.h b/src/libgestures/libgestures/actions/command.h index 7f563b2..e630bdd 100644 --- a/src/libgestures/libgestures/actions/command.h +++ b/src/libgestures/libgestures/actions/command.h @@ -9,7 +9,7 @@ namespace libgestures class CommandGestureAction : public GestureAction { public: - void execute() override; + bool tryExecute() override; void setCommand(const QString &command); private: diff --git a/src/libgestures/libgestures/actions/kdeglobalshortcut.cpp b/src/libgestures/libgestures/actions/kdeglobalshortcut.cpp index c537bef..824a232 100644 --- a/src/libgestures/libgestures/actions/kdeglobalshortcut.cpp +++ b/src/libgestures/libgestures/actions/kdeglobalshortcut.cpp @@ -4,11 +4,15 @@ namespace libgestures { -void KDEGlobalShortcutGestureAction::execute() +bool KDEGlobalShortcutGestureAction::tryExecute() { - GestureAction::execute(); + if (!GestureAction::tryExecute()) + return false; + QDBusInterface interface("org.kde.kglobalaccel", "/component/" + m_component, "org.kde.kglobalaccel.Component"); interface.call("invokeShortcut", m_shortcut); + + return true; } void KDEGlobalShortcutGestureAction::setComponent(const QString &component) diff --git a/src/libgestures/libgestures/actions/kdeglobalshortcut.h b/src/libgestures/libgestures/actions/kdeglobalshortcut.h index 255f638..27b1143 100644 --- a/src/libgestures/libgestures/actions/kdeglobalshortcut.h +++ b/src/libgestures/libgestures/actions/kdeglobalshortcut.h @@ -9,7 +9,7 @@ namespace libgestures class KDEGlobalShortcutGestureAction : public GestureAction { public: - void execute() override; + bool tryExecute() override; void setComponent(const QString &component); void setShortcut(const QString &shortcut); diff --git a/src/libgestures/libgestures/actions/keysequence.cpp b/src/libgestures/libgestures/actions/keysequence.cpp index 5d2de0c..8184797 100644 --- a/src/libgestures/libgestures/actions/keysequence.cpp +++ b/src/libgestures/libgestures/actions/keysequence.cpp @@ -8,9 +8,12 @@ KeySequenceGestureAction::KeySequenceGestureAction(std::shared_ptr input) { } -void KeySequenceGestureAction::execute() +bool KeySequenceGestureAction::tryExecute() { - GestureAction::execute(); + if (!GestureAction::tryExecute()) + return false; + + qWarning() << "executing sequence " << m_sequence; for (const auto &command : m_sequence.split(",")) { const auto action = command.split(" ")[0]; @@ -24,6 +27,8 @@ void KeySequenceGestureAction::execute() else if (action == "release") m_input->keyboardRelease(s_keyMap.at(key)); } + + return true; } void KeySequenceGestureAction::setSequence(const QString &sequence) diff --git a/src/libgestures/libgestures/actions/keysequence.h b/src/libgestures/libgestures/actions/keysequence.h index f5407f9..4271578 100644 --- a/src/libgestures/libgestures/actions/keysequence.h +++ b/src/libgestures/libgestures/actions/keysequence.h @@ -526,7 +526,7 @@ class KeySequenceGestureAction : public GestureAction public: explicit KeySequenceGestureAction(std::shared_ptr input); - void execute() override; + bool tryExecute() override; void setSequence(const QString &sequence); private: diff --git a/src/libgestures/libgestures/gestures/gesture.cpp b/src/libgestures/libgestures/gestures/gesture.cpp index 3b41ee5..f1177b4 100644 --- a/src/libgestures/libgestures/gestures/gesture.cpp +++ b/src/libgestures/libgestures/gestures/gesture.cpp @@ -13,71 +13,77 @@ Gesture::Gesture() void Gesture::onCancelled() { + m_absoluteAccumulatedDelta = 0; + if (!m_hasStarted) return; - for (auto &action : m_actions) - Q_EMIT action->gestureCancelled(); - - m_accumulatedDelta = 0; m_hasStarted = false; - m_blockingAction = std::nullopt; + + for (const auto &action : m_actions) + { + bool actionExecuted = false; + Q_EMIT action->gestureCancelled(actionExecuted); + if (action->blocksOtherActions() && actionExecuted) + break; + } } void Gesture::onEnded() { + m_absoluteAccumulatedDelta = 0; + if (!m_hasStarted) return; + m_hasStarted = false; + for (const auto &action : m_actions) { - if (!action->repeat() && !m_triggerWhenThresholdReached && action->canExecute() && thresholdReached(m_accumulatedDelta) - && action->satisfiesConditions() && (!m_blockingAction || m_blockingAction->get() == action.get())) - action->execute(); - Q_EMIT action->gestureEnded(); + bool actionExecuted = false; + Q_EMIT action->gestureEnded(actionExecuted); + if (action->blocksOtherActions() && actionExecuted) + break; } - - m_accumulatedDelta = 0; - m_hasStarted = false; - m_blockingAction = std::nullopt; } void Gesture::onStarted() { - m_hasStarted = true; + if (!m_hasStarted) + return; for (const auto &action : m_actions) - Q_EMIT action->gestureStarted(); + { + bool actionExecuted = false; + Q_EMIT action->gestureStarted(actionExecuted); + if (action->blocksOtherActions() && actionExecuted) + break; + } } void Gesture::onUpdated(const qreal &delta, bool &endedPrematurely) { - m_accumulatedDelta += delta; - - if (!m_hasStarted && !thresholdReached(m_accumulatedDelta)) + m_absoluteAccumulatedDelta += std::abs(delta); + if (!thresholdReached()) return; - else if (!m_hasStarted) + + if (!m_hasStarted) + { + m_hasStarted = true; Q_EMIT started(); + } for (const auto &action : m_actions) { - if (!action->satisfiesConditions() || (m_blockingAction.has_value() && m_blockingAction.value().get() != action.get())) - continue; - - if (!action->repeat() && m_triggerWhenThresholdReached && action->canExecute()) + qWarning("trying to update"); + bool actionExecuted = false; + Q_EMIT action->gestureUpdated(delta, actionExecuted); + if (actionExecuted && action->blocksOtherActions()) { - action->execute(); - if (!action->blocksOtherActions()) - continue; - - Q_EMIT ended(); endedPrematurely = true; + Q_EMIT ended(); return; } - - Q_EMIT action->gestureUpdated(delta); - if (action->blocksOtherActions()) - m_blockingAction = action; } } @@ -95,16 +101,11 @@ bool Gesture::satisfiesConditions(const uint8_t &fingerCount) const const bool actionSatisfiesConditions = std::find_if(m_actions.begin(), m_actions.end(), [](const std::shared_ptr &triggerAction) { - return triggerAction->satisfiesConditions(); + return triggerAction->canExecute(); }) != m_actions.end(); return m_actions.empty() || actionSatisfiesConditions; } -bool Gesture::thresholdReached(const qreal &accumulatedDelta) const -{ - return accumulatedDelta >= m_threshold; -} - void Gesture::addAction(const std::shared_ptr &action) { m_actions.push_back(action); @@ -115,14 +116,10 @@ void Gesture::addCondition(const std::shared_ptr &condition) m_conditions.push_back(condition); } -void Gesture::setTriggerWhenThresholdReached(const bool &triggerWhenThresholdReached) -{ - m_triggerWhenThresholdReached = triggerWhenThresholdReached; -} - -void Gesture::setThreshold(const qreal &threshold) +void Gesture::setThresholds(const qreal &minimum, const qreal &maximum) { - m_threshold = threshold; + m_minimumThreshold = minimum; + m_maximumThreshold = maximum; } void Gesture::setFingers(const uint8_t &minimum, const uint8_t &maximum) @@ -131,4 +128,20 @@ void Gesture::setFingers(const uint8_t &minimum, const uint8_t &maximum) m_maximumFingers = maximum; } +bool Gesture::thresholdReached() const +{ + return ((m_minimumThreshold == -1 || m_absoluteAccumulatedDelta >= m_minimumThreshold) + && (m_maximumThreshold == -1 || m_absoluteAccumulatedDelta <= m_maximumThreshold)); +} + +void Gesture::setSpeed(const libgestures::GestureSpeed &speed) +{ + m_speed = speed; +} + +GestureSpeed Gesture::speed() const +{ + return m_speed; +} + } // namespace libgestures \ No newline at end of file diff --git a/src/libgestures/libgestures/gestures/gesture.h b/src/libgestures/libgestures/gestures/gesture.h index 5330bda..a3b6c47 100644 --- a/src/libgestures/libgestures/gestures/gesture.h +++ b/src/libgestures/libgestures/gestures/gesture.h @@ -7,6 +7,13 @@ namespace libgestures { +enum GestureSpeed +{ + Any, + Slow, + Fast +}; + class Gesture : public QObject { Q_OBJECT @@ -19,20 +26,13 @@ class Gesture : public QObject */ [[nodiscard]] bool satisfiesConditions(const uint8_t &fingerCount) const; - /** - * @returns Whether the specified threshold has been reached. - */ - [[nodiscard]] virtual bool thresholdReached(const qreal &accumulatedDelta) const; + GestureSpeed speed() const; void addAction(const std::shared_ptr &action); void addCondition(const std::shared_ptr &condition); - /** - * @param triggerWhenThresholdReached Whether gesture actions should be immediately triggered once the specified - * threshold is reached. - */ - void setTriggerWhenThresholdReached(const bool &triggerWhenThresholdReached); - void setThreshold(const qreal &threshold); + void setSpeed(const GestureSpeed &speed); + void setThresholds(const qreal &minimum, const qreal &maximum); void setFingers(const uint8_t &minimum, const uint8_t &maximum); signals: /** @@ -58,29 +58,29 @@ class Gesture : public QObject * triggered. */ void updated(const qreal &delta, bool &endedPrematurely); -protected: - bool m_triggerWhenThresholdReached = false; - qreal m_threshold = 0; private slots: void onCancelled(); void onEnded(); void onStarted(); void onUpdated(const qreal &delta, bool &endedPrematurely); private: + /** + * @return Whether the accumulated delta fits within the specified range. + */ + [[nodiscard]] bool thresholdReached() const; + uint8_t m_minimumFingers = 0; uint8_t m_maximumFingers = 0; + qreal m_minimumThreshold = -1; + qreal m_maximumThreshold = -1; + GestureSpeed m_speed = GestureSpeed::Any; std::vector> m_conditions; std::vector> m_actions; - qreal m_accumulatedDelta = 0; + qreal m_absoluteAccumulatedDelta = 0; bool m_hasStarted = false; - - /** - * The action that currently blocks other actions. Reset after gesture has been cancelled or ended. - */ - std::optional> m_blockingAction; }; } // namespace libgestures \ No newline at end of file diff --git a/src/libgestures/libgestures/gestures/gesturerecognizer.cpp b/src/libgestures/libgestures/gestures/gesturerecognizer.cpp index 12bb1c7..0cb35db 100644 --- a/src/libgestures/libgestures/gestures/gesturerecognizer.cpp +++ b/src/libgestures/libgestures/gestures/gesturerecognizer.cpp @@ -42,10 +42,27 @@ bool GestureRecognizer::pinchGestureUpdate(const qreal &scale, const qreal &angl // Determine the direction of the swipe PinchDirection direction = scale < 1 ? PinchDirection::Contracting : PinchDirection::Expanding; + if (m_isDeterminingSpeed) + { + if (m_sampledInputEvents++ != m_inputEventsToSample) + { + m_accumulatedAbsoluteSampledDelta += std::abs(pinchDelta); + return true; + } + + if (m_accumulatedAbsoluteSampledDelta >= (scale < 1 ? m_pinchContractingFastThreshold : m_pinchExpandingFastThreshold)) + m_speed = GestureSpeed::Fast; + else + m_speed = GestureSpeed::Slow; + + m_isDeterminingSpeed = false; + } + for (auto it = m_activePinchGestures.begin(); it != m_activePinchGestures.end();) { const auto &gesture = *it; - if (gesture->direction() != PinchDirection::Any && gesture->direction() != direction) + if ((gesture->direction() != PinchDirection::Any && gesture->direction() != direction) + || (gesture->speed() != GestureSpeed::Any && gesture->speed() != m_speed)) { gesture->cancelled(); it = m_activePinchGestures.erase(it); @@ -66,6 +83,22 @@ bool GestureRecognizer::swipeGestureUpdate(const QPointF &delta, bool &endedPrem { m_currentSwipeDelta += delta; + if (m_isDeterminingSpeed) + { + if (m_sampledInputEvents++ != m_inputEventsToSample) + { + m_accumulatedAbsoluteSampledDelta += std::abs(delta.x()) + std::abs(delta.y()); + return true; + } + + if (m_accumulatedAbsoluteSampledDelta >= m_swipeGestureFastThreshold) + m_speed = GestureSpeed::Fast; + else + m_speed = GestureSpeed::Slow; + + m_isDeterminingSpeed = false; + } + SwipeDirection direction; // Overall direction Axis swipeAxis; @@ -104,11 +137,12 @@ bool GestureRecognizer::swipeGestureUpdate(const QPointF &delta, bool &endedPrem { const auto gesture = *it; - if (!((gesture->direction() == SwipeDirection::LeftRight + if ((!((gesture->direction() == SwipeDirection::LeftRight && (direction == SwipeDirection::Left || direction == SwipeDirection::Right)) || (gesture->direction() == SwipeDirection::UpDown && (direction == SwipeDirection::Up || direction == SwipeDirection::Down))) && gesture->direction() != direction) + || (gesture->speed() != GestureSpeed::Any && gesture->speed() != m_speed)) { gesture->cancelled(); it = m_activeSwipeGestures.erase(it); @@ -173,8 +207,6 @@ bool GestureRecognizer::pinchGestureEnd() template void GestureRecognizer::gestureBegin(const uint8_t &fingerCount, std::vector> &activeGestures) { - m_currentFingerCount = fingerCount; - if (!activeGestures.empty()) return; @@ -184,6 +216,9 @@ void GestureRecognizer::gestureBegin(const uint8_t &fingerCount, std::vectorsatisfiesConditions(fingerCount)) continue; + if (castedGesture->speed() != GestureSpeed::Any) + m_isDeterminingSpeed = true; + activeGestures.push_back(castedGesture); } } @@ -213,10 +248,13 @@ void GestureRecognizer::gestureCancel(std::vector> &ac void GestureRecognizer::resetMembers() { - m_currentFingerCount = 0; + m_accumulatedAbsoluteSampledDelta = 0; + m_sampledInputEvents = 0; + m_isDeterminingSpeed = false; m_previousPinchScale = 1; m_currentSwipeAxis = Axis::None; m_currentSwipeDelta = QPointF(); + m_speed = GestureSpeed::Any; } } // namespace libgestures \ No newline at end of file diff --git a/src/libgestures/libgestures/gestures/gesturerecognizer.h b/src/libgestures/libgestures/gestures/gesturerecognizer.h index 79afbe0..3f4cd92 100644 --- a/src/libgestures/libgestures/gestures/gesturerecognizer.h +++ b/src/libgestures/libgestures/gestures/gesturerecognizer.h @@ -108,7 +108,17 @@ class GestureRecognizer : public QObject qreal m_previousPinchScale = 1; std::vector> m_activeHoldGestures; - uint m_currentFingerCount = 0; + + uint8_t m_inputEventsToSample = 5; + qreal m_swipeGestureFastThreshold = 150; + qreal m_pinchContractingFastThreshold = 0.3; + qreal m_pinchExpandingFastThreshold = 0.5; + + GestureSpeed m_speed = GestureSpeed::Any; + bool m_isDeterminingSpeed = false; + uint8_t m_sampledInputEvents = 0; + qreal m_accumulatedAbsoluteSampledDelta = 0; + friend class TestGestureRecognizer; }; diff --git a/src/libgestures/libgestures/gestures/pinchgesture.cpp b/src/libgestures/libgestures/gestures/pinchgesture.cpp index df167a9..57bac99 100644 --- a/src/libgestures/libgestures/gestures/pinchgesture.cpp +++ b/src/libgestures/libgestures/gestures/pinchgesture.cpp @@ -3,19 +3,6 @@ namespace libgestures { -bool PinchGesture::thresholdReached(const qreal &scale) const -{ - switch (m_direction) - { - case PinchDirection::Contracting: - return scale <= m_threshold; - case PinchDirection::Expanding: - return scale >= m_threshold; - default: - return scale >= m_threshold || scale <= m_threshold; - } -} - void PinchGesture::setDirection(const PinchDirection &direction) { m_direction = direction; diff --git a/src/libgestures/libgestures/gestures/pinchgesture.h b/src/libgestures/libgestures/gestures/pinchgesture.h index aaeee5e..bfdbce8 100644 --- a/src/libgestures/libgestures/gestures/pinchgesture.h +++ b/src/libgestures/libgestures/gestures/pinchgesture.h @@ -6,7 +6,7 @@ namespace libgestures { -enum PinchDirection +enum class PinchDirection { Any, Contracting, @@ -18,8 +18,6 @@ class PinchGesture : public Gesture public: PinchDirection direction() const { return m_direction; } - bool thresholdReached(const qreal &scale) const override; - void setDirection(const PinchDirection &direction); private: PinchDirection m_direction = PinchDirection::Any; diff --git a/src/libgestures/libgestures/gestures/swipegesture.cpp b/src/libgestures/libgestures/gestures/swipegesture.cpp index ebe7ed4..e2a2c90 100644 --- a/src/libgestures/libgestures/gestures/swipegesture.cpp +++ b/src/libgestures/libgestures/gestures/swipegesture.cpp @@ -3,11 +3,6 @@ namespace libgestures { -bool SwipeGesture::thresholdReached(const qreal &delta) const -{ - return std::abs(delta) >= std::abs(m_threshold); -} - void SwipeGesture::setDirection(const libgestures::SwipeDirection &direction) { m_direction = direction; diff --git a/src/libgestures/libgestures/gestures/swipegesture.h b/src/libgestures/libgestures/gestures/swipegesture.h index 29d5c34..6c86b3b 100644 --- a/src/libgestures/libgestures/gestures/swipegesture.h +++ b/src/libgestures/libgestures/gestures/swipegesture.h @@ -5,7 +5,7 @@ namespace libgestures { -enum SwipeDirection +enum class SwipeDirection { Left, Right, @@ -20,8 +20,6 @@ class SwipeGesture : public Gesture public: SwipeDirection direction() const { return m_direction; } - bool thresholdReached(const qreal &delta) const override; - void setDirection(const SwipeDirection &direction); private: SwipeDirection m_direction = SwipeDirection::Left; diff --git a/src/libgestures/libgestures/input.h b/src/libgestures/libgestures/input.h index b96542b..8e26532 100644 --- a/src/libgestures/libgestures/input.h +++ b/src/libgestures/libgestures/input.h @@ -14,8 +14,8 @@ class Input Input() = default; virtual ~Input() = default; - virtual void keyboardPress([[maybe_unused]] const uint32_t &key) const { }; - virtual void keyboardRelease([[maybe_unused]] const uint32_t &key) const { }; + virtual void keyboardPress([[maybe_unused]] const uint32_t &key) { }; + virtual void keyboardRelease([[maybe_unused]] const uint32_t &key) { }; }; } // namespace libgestures \ No newline at end of file diff --git a/tests/libgestures/actions/test_action.cpp b/tests/libgestures/actions/test_action.cpp index d43452e..45b24ca 100644 --- a/tests/libgestures/actions/test_action.cpp +++ b/tests/libgestures/actions/test_action.cpp @@ -45,27 +45,27 @@ void TestAction::canExecute_repeatingNotExecuted_returnsTrue() void TestAction::canExecute_nonRepeatingExecutedOnce_returnsFalse() { - m_action->execute(); + m_action->tryExecute(); QVERIFY(!m_action->canExecute()); } void TestAction::canExecute_repeatingExecutedOnce_returnsTrue() { m_action->setRepeatInterval(1); - m_action->execute(); + m_action->tryExecute(); QVERIFY(m_action->canExecute()); } void TestAction::canExecute_nonRepeatingExecutedOnceAndEnded_returnsTrue() { - m_action->execute(); + m_action->tryExecute(); Q_EMIT m_action->gestureEnded(); QVERIFY(m_action->canExecute()); } void TestAction::canExecute_nonRepeatingExecutedOnceAndCancelled_returnsTrue() { - m_action->execute(); + m_action->tryExecute(); Q_EMIT m_action->gestureCancelled(); QVERIFY(m_action->canExecute()); }