From 0165a9ed8679f3f2c62cc868bdaf620e4520d504 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Wed, 27 Dec 2023 04:34:24 +0100 Subject: [PATCH] refactor: split gestures into multiple files (#72) * cleanup * refactor: generalize action * refactor: split into multiple files * refactor: split into multiple files --- src/gestures/Actions.cpp | 154 ++++++++++++++++++++++++++++++++ src/gestures/Actions.hpp | 116 ++++++++++++++++++++++++ src/gestures/Gestures.cpp | 175 ++----------------------------------- src/gestures/Gestures.hpp | 146 ++----------------------------- src/gestures/Shared.hpp | 24 +++++ src/gestures/meson.build | 1 + src/gestures/test/test.cpp | 2 +- 7 files changed, 309 insertions(+), 309 deletions(-) create mode 100644 src/gestures/Actions.cpp create mode 100644 src/gestures/Actions.hpp create mode 100644 src/gestures/Shared.hpp diff --git a/src/gestures/Actions.cpp b/src/gestures/Actions.cpp new file mode 100644 index 0000000..a0c156a --- /dev/null +++ b/src/gestures/Actions.cpp @@ -0,0 +1,154 @@ +#include "Actions.hpp" +#include + +wf::touch::action_status_t CMultiAction::update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) { + if (event.time - this->start_time > *this->timeout) { + return wf::touch::ACTION_STATUS_CANCELLED; + } + + if (event.type == wf::touch::EVENT_TYPE_TOUCH_UP) { + return wf::touch::ACTION_STATUS_CANCELLED; + } + + if (event.type == wf::touch::EVENT_TYPE_TOUCH_DOWN) { + // cancel if previous fingers moved too much + this->finger_count = state.fingers.size(); + for (auto& finger : state.fingers) { + // TODO multiply tolerance by sensitivity? + if (glm::length(finger.second.delta()) > GESTURE_INITIAL_TOLERANCE) { + return wf::touch::ACTION_STATUS_CANCELLED; + } + } + + return wf::touch::ACTION_STATUS_RUNNING; + } + + if ((glm::length(state.get_center().delta()) >= MIN_SWIPE_DISTANCE) && (this->target_direction == 0)) { + this->target_direction = state.get_center().get_direction(); + } + + if (this->target_direction == 0) { + return wf::touch::ACTION_STATUS_RUNNING; + } + + for (auto& finger : state.fingers) { + if (finger.second.get_incorrect_drag_distance(this->target_direction) > this->get_move_tolerance()) { + return wf::touch::ACTION_STATUS_CANCELLED; + } + } + + if (state.get_center().get_drag_distance(target_direction) >= base_threshold / *sensitivity) { + return wf::touch::ACTION_STATUS_COMPLETED; + } + return wf::touch::ACTION_STATUS_RUNNING; +} + +wf::touch::action_status_t MultiFingerDownAction::update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) { + if (event.time - this->start_time > this->get_duration()) { + return wf::touch::ACTION_STATUS_CANCELLED; + } + + if (event.type == wf::touch::EVENT_TYPE_TOUCH_UP) { + return wf::touch::ACTION_STATUS_CANCELLED; + } + + if (event.type == wf::touch::EVENT_TYPE_TOUCH_DOWN && state.fingers.size() >= SEND_CANCEL_EVENT_FINGER_COUNT) { + return wf::touch::ACTION_STATUS_COMPLETED; + } + + return wf::touch::ACTION_STATUS_RUNNING; +} + +wf::touch::action_status_t MultiFingerTap::update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) { + if (event.time - this->start_time > *this->timeout) { + return wf::touch::ACTION_STATUS_CANCELLED; + } + + if (event.type == wf::touch::EVENT_TYPE_TOUCH_UP) { + return wf::touch::ACTION_STATUS_COMPLETED; + } + + if (event.type == wf::touch::EVENT_TYPE_MOTION) { + for (const auto& finger : state.fingers) { + const auto delta = finger.second.delta(); + if (delta.x * delta.x + delta.y + delta.y > this->base_threshold / *this->sensitivity) { + return wf::touch::ACTION_STATUS_CANCELLED; + } + } + } + + return wf::touch::ACTION_STATUS_RUNNING; +} + +wf::touch::action_status_t LongPress::update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) { + if (event.time - this->start_time > *this->delay) { + return wf::touch::ACTION_STATUS_COMPLETED; + } + + switch (event.type) { + case wf::touch::EVENT_TYPE_MOTION: + for (const auto& finger : state.fingers) { + const auto delta = finger.second.delta(); + if (delta.x * delta.x + delta.y + delta.y > this->base_threshold / *this->sensitivity) { + return wf::touch::ACTION_STATUS_CANCELLED; + } + } + break; + + case wf::touch::EVENT_TYPE_TOUCH_DOWN: + // TODO: also reset wl_timer here + gesture_action_t::reset(event.time); + this->update_external_timer_callback(event.time, *this->delay); + break; + + case wf::touch::EVENT_TYPE_TOUCH_UP: + return wf::touch::ACTION_STATUS_CANCELLED; + } + + return wf::touch::ACTION_STATUS_RUNNING; +} + +wf::touch::action_status_t LiftoffAction::update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) { + if (event.time - this->start_time > this->get_duration()) { + return wf::touch::ACTION_STATUS_CANCELLED; + } + + if (event.type == wf::touch::EVENT_TYPE_TOUCH_UP) { + return wf::touch::ACTION_STATUS_COMPLETED; + } + + if (event.type == wf::touch::EVENT_TYPE_TOUCH_DOWN) { + return wf::touch::ACTION_STATUS_CANCELLED; + } + + return wf::touch::ACTION_STATUS_RUNNING; +} + +wf::touch::action_status_t TouchUpOrDownAction::update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) { + if (event.time - this->start_time > this->get_duration()) { + return wf::touch::ACTION_STATUS_CANCELLED; + } + + if (event.type == wf::touch::EVENT_TYPE_TOUCH_UP || event.type == wf::touch::EVENT_TYPE_TOUCH_DOWN) { + return wf::touch::ACTION_STATUS_COMPLETED; + } + + return wf::touch::ACTION_STATUS_RUNNING; +} + +wf::touch::action_status_t OnCompleteAction::update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) { + auto status = this->action->update_state(state, event); + + if (status == wf::touch::ACTION_STATUS_COMPLETED) { + this->callback(); + } + + return status; +} diff --git a/src/gestures/Actions.hpp b/src/gestures/Actions.hpp new file mode 100644 index 0000000..5200d1c --- /dev/null +++ b/src/gestures/Actions.hpp @@ -0,0 +1,116 @@ +#include "Shared.hpp" +#include +#include +#include +#include + +using UpdateExternalTimerCallback = std::function; + +// swipe and with multiple fingers and directions +class CMultiAction : public wf::touch::gesture_action_t { + private: + double base_threshold; + const float* sensitivity; + const int64_t* timeout; + + public: + // threshold = base_threshold / sensitivity + // if the threshold needs to be adjusted dynamically, the sensitivity + // pointer is used + CMultiAction(double base_threshold, const float* sensitivity, const int64_t* timeout) + : base_threshold(base_threshold), sensitivity(sensitivity), timeout(timeout){}; + + GestureDirection target_direction = 0; + int finger_count = 0; + + // The action is completed if any number of fingers is moved enough. + // + // This action should be followed by another that completes upon lifting a + // finger to achieve a gesture that completes after a multi-finger swipe is + // done and lifted. + wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) override; + + void reset(uint32_t time) override { + gesture_action_t::reset(time); + target_direction = 0; + }; +}; + +class MultiFingerTap : public wf::touch::gesture_action_t { + private: + double base_threshold; + const float* sensitivity; + const int64_t* timeout; + + public: + MultiFingerTap(double base_threshold, const float* sensitivity, const int64_t* timeout) + : base_threshold(base_threshold), sensitivity(sensitivity), timeout(timeout){}; + + wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) override; +}; + +class LongPress : public wf::touch::gesture_action_t { + private: + double base_threshold; + const float* sensitivity; + const int64_t* delay; + UpdateExternalTimerCallback update_external_timer_callback; + + public: + // TODO: I hope one day I can figure out how not to pass a function for the update timer callback + LongPress(double base_threshold, const float* sensitivity, const int64_t* delay, + UpdateExternalTimerCallback update_external_timer) + : base_threshold(base_threshold), sensitivity(sensitivity), delay(delay), + update_external_timer_callback(update_external_timer){}; + + wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) override; +}; + +// Completes upon receiving enough touch down events within a short duration +class MultiFingerDownAction : public wf::touch::gesture_action_t { + // upon completion, calls the given callback. + // + // Intended to be used to send cancel events to surfaces when enough fingers + // touch down in quick succession. + public: + MultiFingerDownAction() {} + + wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) override; +}; + +// Completes upon receiving a touch up event and cancels upon receiving a touch +// down event. +class LiftoffAction : public wf::touch::gesture_action_t { + wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) override; +}; + +// Completes upon receiving a touch up or touch down event +class TouchUpOrDownAction : public wf::touch::gesture_action_t { + wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) override; +}; + +// This action is used to call a function right after another action is completed +class OnCompleteAction : public wf::touch::gesture_action_t { + private: + std::unique_ptr action; + const std::function callback; + + public: + OnCompleteAction(std::unique_ptr action, std::function callback) + : callback(callback) { + this->action = std::move(action); + } + + wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, + const wf::touch::gesture_event_t& event) override; + + void reset(uint32_t time) override { + this->action->reset(time); + } +}; diff --git a/src/gestures/Gestures.cpp b/src/gestures/Gestures.cpp index bb92564..943eb55 100644 --- a/src/gestures/Gestures.cpp +++ b/src/gestures/Gestures.cpp @@ -1,4 +1,5 @@ #include "Gestures.hpp" +#include "Actions.hpp" #include #include #include @@ -7,7 +8,7 @@ #include #include -std::string stringifyDirection(gestureDirection direction) { +std::string stringifyDirection(GestureDirection direction) { std::string bind; if (direction & GESTURE_DIRECTION_LEFT) { bind += 'l'; @@ -55,159 +56,6 @@ std::string DragGesture::to_string() const { return ""; } -wf::touch::action_status_t CMultiAction::update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) { - if (event.time - this->start_time > *this->timeout) { - return wf::touch::ACTION_STATUS_CANCELLED; - } - - if (event.type == wf::touch::EVENT_TYPE_TOUCH_UP) { - return wf::touch::ACTION_STATUS_CANCELLED; - } - - if (event.type == wf::touch::EVENT_TYPE_TOUCH_DOWN) { - // cancel if previous fingers moved too much - this->finger_count = state.fingers.size(); - for (auto& finger : state.fingers) { - // TODO multiply tolerance by sensitivity? - if (glm::length(finger.second.delta()) > GESTURE_INITIAL_TOLERANCE) { - return wf::touch::ACTION_STATUS_CANCELLED; - } - } - - return wf::touch::ACTION_STATUS_RUNNING; - } - - if ((glm::length(state.get_center().delta()) >= MIN_SWIPE_DISTANCE) && (this->target_direction == 0)) { - this->target_direction = state.get_center().get_direction(); - } - - if (this->target_direction == 0) { - return wf::touch::ACTION_STATUS_RUNNING; - } - - for (auto& finger : state.fingers) { - if (finger.second.get_incorrect_drag_distance(this->target_direction) > this->get_move_tolerance()) { - return wf::touch::ACTION_STATUS_CANCELLED; - } - } - - if (state.get_center().get_drag_distance(target_direction) >= base_threshold / *sensitivity) { - return wf::touch::ACTION_STATUS_COMPLETED; - } - return wf::touch::ACTION_STATUS_RUNNING; -} - -wf::touch::action_status_t MultiFingerDownAction::update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) { - if (event.time - this->start_time > this->get_duration()) { - return wf::touch::ACTION_STATUS_CANCELLED; - } - - if (event.type == wf::touch::EVENT_TYPE_TOUCH_UP) { - return wf::touch::ACTION_STATUS_CANCELLED; - } - - if (event.type == wf::touch::EVENT_TYPE_TOUCH_DOWN && state.fingers.size() >= SEND_CANCEL_EVENT_FINGER_COUNT) { - this->callback(); - return wf::touch::ACTION_STATUS_COMPLETED; - } - - return wf::touch::ACTION_STATUS_RUNNING; -} - -wf::touch::action_status_t MultiFingerTap::update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) { - if (event.time - this->start_time > *this->timeout) { - return wf::touch::ACTION_STATUS_CANCELLED; - } - - if (event.type == wf::touch::EVENT_TYPE_TOUCH_UP) { - return wf::touch::ACTION_STATUS_COMPLETED; - } - - if (event.type == wf::touch::EVENT_TYPE_MOTION) { - for (const auto& finger : state.fingers) { - const auto delta = finger.second.delta(); - if (delta.x * delta.x + delta.y + delta.y > this->base_threshold / *this->sensitivity) { - return wf::touch::ACTION_STATUS_CANCELLED; - } - } - } - - return wf::touch::ACTION_STATUS_RUNNING; -} - -wf::touch::action_status_t LongPress::update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) { - if (event.time - this->start_time > *this->delay) { - return wf::touch::ACTION_STATUS_COMPLETED; - } - - switch (event.type) { - case wf::touch::EVENT_TYPE_MOTION: - for (const auto& finger : state.fingers) { - const auto delta = finger.second.delta(); - if (delta.x * delta.x + delta.y + delta.y > this->base_threshold / *this->sensitivity) { - return wf::touch::ACTION_STATUS_CANCELLED; - } - } - break; - - case wf::touch::EVENT_TYPE_TOUCH_DOWN: - // TODO: also reset wl_timer here - gesture_action_t::reset(event.time); - this->update_external_timer_callback(event.time, *this->delay); - break; - - case wf::touch::EVENT_TYPE_TOUCH_UP: - return wf::touch::ACTION_STATUS_CANCELLED; - } - - return wf::touch::ACTION_STATUS_RUNNING; -} - -wf::touch::action_status_t LiftoffAction::update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) { - if (event.time - this->start_time > this->get_duration()) { - return wf::touch::ACTION_STATUS_CANCELLED; - } - - if (event.type == wf::touch::EVENT_TYPE_TOUCH_UP) { - return wf::touch::ACTION_STATUS_COMPLETED; - } - - if (event.type == wf::touch::EVENT_TYPE_TOUCH_DOWN) { - return wf::touch::ACTION_STATUS_CANCELLED; - } - - return wf::touch::ACTION_STATUS_RUNNING; -} - -wf::touch::action_status_t TouchUpOrDownAction::update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) { - if (event.time - this->start_time > this->get_duration()) { - return wf::touch::ACTION_STATUS_CANCELLED; - } - - if (event.type == wf::touch::EVENT_TYPE_TOUCH_UP || event.type == wf::touch::EVENT_TYPE_TOUCH_DOWN) { - return wf::touch::ACTION_STATUS_COMPLETED; - } - - return wf::touch::ACTION_STATUS_RUNNING; -} - -wf::touch::action_status_t OnCompleteAction::update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) { - auto status = this->action->update_state(state, event); - - if (status == wf::touch::ACTION_STATUS_COMPLETED) { - this->callback(); - } - - return status; -} - void IGestureManager::updateGestures(const wf::touch::gesture_event_t& ev) { if (m_sGestureState.fingers.size() == 1 && ev.type == wf::touch::EVENT_TYPE_TOUCH_DOWN) { this->inhibitTouchEvents = false; @@ -267,10 +115,10 @@ bool IGestureManager::onTouchMove(const wf::touch::gesture_event_t& ev) { return this->eventForwardingInhibited(); } -gestureDirection IGestureManager::find_swipe_edges(wf::touch::point_t point) { +GestureDirection IGestureManager::find_swipe_edges(wf::touch::point_t point) { auto mon = this->getMonitorArea(); - gestureDirection edge_directions = 0; + GestureDirection edge_directions = 0; if (point.x <= mon.x + EDGE_SWIPE_THRESHOLD) { edge_directions |= GESTURE_DIRECTION_LEFT; @@ -295,17 +143,10 @@ void IGestureManager::addTouchGesture(std::unique_ptr gest this->m_vGestures.emplace_back(std::move(gesture)); } -// Adds a Multi-fingered swipe: -// * inhibits events to client windows/surfaces when enough fingers touch -// down within a short duration. -// * emits a TouchGestureType::SWIPE_HOLD event once fingers moved over the -// threshold. -// * further emits a TouchGestureType::SWIPE event if the SWIPE_HOLD event was -// emitted and once a finger is lifted -// TODO: ^^^ remove void IGestureManager::addMultiFingerGesture(const float* sensitivity, const int64_t* timeout) { - auto multi_down = std::make_unique([this]() { this->cancelTouchEventsOnAllWindows(); }); - multi_down->set_duration(GESTURE_BASE_DURATION); + auto multi_down_and_send_cancel = std::make_unique( + std::make_unique(), [this]() { this->cancelTouchEventsOnAllWindows(); }); + multi_down_and_send_cancel->set_duration(GESTURE_BASE_DURATION); auto swipe = std::make_unique(SWIPE_INCORRECT_DRAG_TOLERANCE, sensitivity, timeout); @@ -325,7 +166,7 @@ void IGestureManager::addMultiFingerGesture(const float* sensitivity, const int6 // swipe_liftoff->set_duration(GESTURE_BASE_DURATION / 2); std::vector> swipe_actions; - swipe_actions.emplace_back(std::move(multi_down)); + swipe_actions.emplace_back(std::move(multi_down_and_send_cancel)); swipe_actions.emplace_back(std::move(swipe_and_emit)); swipe_actions.emplace_back(std::move(swipe_liftoff)); diff --git a/src/gestures/Gestures.hpp b/src/gestures/Gestures.hpp index 93fecb5..a79d062 100644 --- a/src/gestures/Gestures.hpp +++ b/src/gestures/Gestures.hpp @@ -1,31 +1,10 @@ #pragma once -#include +#include "Shared.hpp" #include #include #include #include -// Swipe params -constexpr static int EDGE_SWIPE_THRESHOLD = 10; -constexpr static double MIN_SWIPE_DISTANCE = 30; -constexpr static double MAX_SWIPE_DISTANCE = 450; -constexpr static double SWIPE_INCORRECT_DRAG_TOLERANCE = 150; - -// Pinch params -constexpr static double PINCH_INCORRECT_DRAG_TOLERANCE = 200; -constexpr static double PINCH_THRESHOLD = 1.5; - -// Hold params -constexpr static double HOLD_INCORRECT_DRAG_TOLERANCE = 100; - -// General -constexpr static double GESTURE_INITIAL_TOLERANCE = 40; -constexpr static uint32_t GESTURE_BASE_DURATION = 400; - -constexpr static uint32_t SEND_CANCEL_EVENT_FINGER_COUNT = 3; - -using UpdateExternalTimerCallback = std::function; - enum class CompletedGestureType { // Invalid Gesture SWIPE, @@ -51,9 +30,6 @@ enum TouchGestureDirection { // GESTURE_DIRECTION_OUT = (1 << 5), }; -// can be one of @eTouchGestureDirection or a combination of them -using gestureDirection = uint32_t; - /** * Represents a touch gesture. * @@ -61,19 +37,19 @@ using gestureDirection = uint32_t; */ struct CompletedGesture { CompletedGestureType type; - gestureDirection direction; + GestureDirection direction; int finger_count; // TODO turn this whole struct into a sum type? // edge swipe specific - gestureDirection edge_origin; + GestureDirection edge_origin; std::string to_string() const; }; struct DragGesture { DragGestureType type; - gestureDirection direction; + GestureDirection direction; int finger_count; std::string to_string() const; @@ -83,118 +59,6 @@ struct SMonitorArea { double x, y, w, h; }; -// swipe and with multiple fingers and directions -class CMultiAction : public wf::touch::gesture_action_t { - private: - double base_threshold; - const float* sensitivity; - const int64_t* timeout; - - public: - // threshold = base_threshold / sensitivity - // if the threshold needs to be adjusted dynamically, the sensitivity - // pointer is used - CMultiAction(double base_threshold, const float* sensitivity, const int64_t* timeout) - : base_threshold(base_threshold), sensitivity(sensitivity), timeout(timeout){}; - - gestureDirection target_direction = 0; - int finger_count = 0; - - // The action is completed if any number of fingers is moved enough. - // - // This action should be followed by another that completes upon lifting a - // finger to achieve a gesture that completes after a multi-finger swipe is - // done and lifted. - wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) override; - - void reset(uint32_t time) override { - gesture_action_t::reset(time); - target_direction = 0; - }; -}; - -class MultiFingerTap : public wf::touch::gesture_action_t { - private: - double base_threshold; - const float* sensitivity; - const int64_t* timeout; - - public: - MultiFingerTap(double base_threshold, const float* sensitivity, const int64_t* timeout) - : base_threshold(base_threshold), sensitivity(sensitivity), timeout(timeout){}; - - wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) override; -}; - -class LongPress : public wf::touch::gesture_action_t { - private: - double base_threshold; - const float* sensitivity; - const int64_t* delay; - UpdateExternalTimerCallback update_external_timer_callback; - - public: - // TODO: I hope one day I can figure out how not to pass a function for the update timer callback - LongPress(double base_threshold, const float* sensitivity, const int64_t* delay, - UpdateExternalTimerCallback update_external_timer) - : base_threshold(base_threshold), sensitivity(sensitivity), delay(delay), - update_external_timer_callback(update_external_timer){}; - - wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) override; -}; - -// Completes upon receiving enough touch down events within a short duration -class MultiFingerDownAction : public wf::touch::gesture_action_t { - // upon completion, calls the given callback. - // - // Intended to be used to send cancel events to surfaces when enough fingers - // touch down in quick succession. - public: - MultiFingerDownAction(std::function callback) : callback(callback) {} - - wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) override; - - private: - std::function callback; -}; - -// Completes upon receiving a touch up event and cancels upon receiving a touch -// down event. -class LiftoffAction : public wf::touch::gesture_action_t { - wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) override; -}; - -// Completes upon receiving a touch up or touch down event -class TouchUpOrDownAction : public wf::touch::gesture_action_t { - wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) override; -}; - -// This action is used to call a function right after another action is completed -class OnCompleteAction : public wf::touch::gesture_action_t { - private: - std::unique_ptr action; - const std::function callback; - - public: - OnCompleteAction(std::unique_ptr action, std::function callback) - : callback(callback) { - this->action = std::move(action); - } - - wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state, - const wf::touch::gesture_event_t& event) override; - - void reset(uint32_t time) override { - this->action->reset(time); - } -}; - /* * Interface; there's only @CGestures and the mock gesture manager for testing * that implements this @@ -239,7 +103,7 @@ class IGestureManager { std::vector> m_vGestures; wf::touch::gesture_state_t m_sGestureState; - gestureDirection find_swipe_edges(wf::touch::point_t point); + GestureDirection find_swipe_edges(wf::touch::point_t point); virtual SMonitorArea getMonitorArea() const = 0; // handles gesture events and returns whether or not the event is used. diff --git a/src/gestures/Shared.hpp b/src/gestures/Shared.hpp new file mode 100644 index 0000000..487b675 --- /dev/null +++ b/src/gestures/Shared.hpp @@ -0,0 +1,24 @@ +#pragma once +#include + +// Swipe params +constexpr static int EDGE_SWIPE_THRESHOLD = 10; +constexpr static double MIN_SWIPE_DISTANCE = 30; +constexpr static double MAX_SWIPE_DISTANCE = 450; +constexpr static double SWIPE_INCORRECT_DRAG_TOLERANCE = 150; + +// Pinch params +constexpr static double PINCH_INCORRECT_DRAG_TOLERANCE = 200; +constexpr static double PINCH_THRESHOLD = 1.5; + +// Hold params +constexpr static double HOLD_INCORRECT_DRAG_TOLERANCE = 100; + +// General +constexpr static double GESTURE_INITIAL_TOLERANCE = 40; +constexpr static uint32_t GESTURE_BASE_DURATION = 400; + +constexpr static uint32_t SEND_CANCEL_EVENT_FINGER_COUNT = 3; + +// can be one of @eTouchGestureDirection or a combination of them +using GestureDirection = uint32_t; diff --git a/src/gestures/meson.build b/src/gestures/meson.build index 973c4db..894874d 100644 --- a/src/gestures/meson.build +++ b/src/gestures/meson.build @@ -1,5 +1,6 @@ gestures = static_library('gestures', 'Gestures.cpp', + 'Actions.cpp', dependencies: [ wftouch, ]) diff --git a/src/gestures/test/test.cpp b/src/gestures/test/test.cpp index 7186864..f14e073 100644 --- a/src/gestures/test/test.cpp +++ b/src/gestures/test/test.cpp @@ -13,7 +13,7 @@ constexpr int64_t LONG_PRESS_DELAY = GESTURE_BASE_DURATION; void Tester::testFindSwipeEdges() { using Test = struct { wf::touch::point_t origin; - gestureDirection result; + GestureDirection result; }; const auto L = GESTURE_DIRECTION_LEFT; const auto R = GESTURE_DIRECTION_RIGHT;