From 9492bd48b8b6b3015afc509163a1285d1a520195 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sun, 21 Jul 2024 11:25:04 +0200 Subject: [PATCH 1/5] feat: new option edge_margin --- src/GestureManager.cpp | 5 ++++- src/gestures/Gestures.cpp | 19 ++++++++++--------- src/gestures/Gestures.hpp | 4 ++-- src/gestures/Shared.hpp | 1 - src/gestures/test/test.cpp | 13 +++++++------ src/main.cpp | 2 ++ 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/GestureManager.cpp b/src/GestureManager.cpp index 3c4fcc6..f725bca 100644 --- a/src/GestureManager.cpp +++ b/src/GestureManager.cpp @@ -68,11 +68,14 @@ GestureManager::GestureManager() { static auto const LONG_PRESS_DELAY = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:touch_gestures:long_press_delay") ->getDataStaticPtr(); + static auto const EDGE_MARGIN = + (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:touch_gestures:edge_margin") + ->getDataStaticPtr(); this->addMultiFingerGesture(*PSENSITIVITY, *LONG_PRESS_DELAY); this->addMultiFingerTap(*PSENSITIVITY, *LONG_PRESS_DELAY); this->addLongPress(*PSENSITIVITY, *LONG_PRESS_DELAY); - this->addEdgeSwipeGesture(*PSENSITIVITY, *LONG_PRESS_DELAY); + this->addEdgeSwipeGesture(*PSENSITIVITY, *LONG_PRESS_DELAY, *EDGE_MARGIN); this->long_press_timer = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, handleLongPressTimer, this); } diff --git a/src/gestures/Gestures.cpp b/src/gestures/Gestures.cpp index 08792e0..af1ed82 100644 --- a/src/gestures/Gestures.cpp +++ b/src/gestures/Gestures.cpp @@ -94,24 +94,24 @@ 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, int edge_margin) { auto mon = this->getMonitorArea(); GestureDirection edge_directions = 0; - if (point.x <= mon.x + EDGE_SWIPE_THRESHOLD) { + if (point.x <= mon.x + edge_margin) { edge_directions |= GESTURE_DIRECTION_LEFT; } - if (point.x >= mon.x + mon.w - EDGE_SWIPE_THRESHOLD) { + if (point.x >= mon.x + mon.w - edge_margin) { edge_directions |= GESTURE_DIRECTION_RIGHT; } - if (point.y <= mon.y + EDGE_SWIPE_THRESHOLD) { + if (point.y <= mon.y + edge_margin) { edge_directions |= GESTURE_DIRECTION_UP; } - if (point.y >= mon.y + mon.h - EDGE_SWIPE_THRESHOLD) { + if (point.y >= mon.y + mon.h - edge_margin) { edge_directions |= GESTURE_DIRECTION_DOWN; } @@ -228,11 +228,12 @@ void IGestureManager::addLongPress(const float* sensitivity, const int64_t* dela this->addTouchGesture(std::make_unique(std::move(long_press_actions), ack, cancel)); } -void IGestureManager::addEdgeSwipeGesture(const float* sensitivity, const int64_t* timeout) { +void IGestureManager::addEdgeSwipeGesture(const float* sensitivity, const int64_t* timeout, + const long int* edge_margin) { auto edge = std::make_unique(SWIPE_INCORRECT_DRAG_TOLERANCE, sensitivity, timeout); auto edge_ptr = edge.get(); auto edge_drag_begin = std::make_unique(std::move(edge), [=, this]() { - auto origin_edges = this->find_swipe_edges(m_sGestureState.get_center().origin); + auto origin_edges = this->find_swipe_edges(m_sGestureState.get_center().origin, *edge_margin); if (origin_edges == 0) { return; @@ -258,8 +259,8 @@ void IGestureManager::addEdgeSwipeGesture(const float* sensitivity, const int64_ edge_swipe_actions.emplace_back(std::move(edge_drag_begin)); edge_swipe_actions.emplace_back(std::move(edge_release)); - auto ack = [edge_ptr, this]() { - auto origin_edges = find_swipe_edges(m_sGestureState.get_center().origin); + auto ack = [edge_ptr, edge_margin, this]() { + auto origin_edges = find_swipe_edges(m_sGestureState.get_center().origin, *edge_margin); auto direction = edge_ptr->target_direction; auto dragEvent = DragGestureEvent{ .type = DragGestureType::EDGE_SWIPE, diff --git a/src/gestures/Gestures.hpp b/src/gestures/Gestures.hpp index 0b76c31..c4aabec 100644 --- a/src/gestures/Gestures.hpp +++ b/src/gestures/Gestures.hpp @@ -40,7 +40,7 @@ class IGestureManager { void addMultiFingerGesture(const float* sensitivity, const int64_t* timeout); void addMultiFingerTap(const float* sensitivity, const int64_t* timeout); void addLongPress(const float* sensitivity, const int64_t* delay); - void addEdgeSwipeGesture(const float* sensitivity, const int64_t* timeout); + void addEdgeSwipeGesture(const float* sensitivity, const int64_t* timeout, const long* edge_margin); std::optional getActiveDragGesture() const { return activeDragGesture; @@ -56,7 +56,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, int edge_margin); 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 index 37b1481..972974d 100644 --- a/src/gestures/Shared.hpp +++ b/src/gestures/Shared.hpp @@ -3,7 +3,6 @@ #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; diff --git a/src/gestures/test/test.cpp b/src/gestures/test/test.cpp index 4781e0f..05de4e7 100644 --- a/src/gestures/test/test.cpp +++ b/src/gestures/test/test.cpp @@ -9,6 +9,7 @@ constexpr float SENSITIVITY = 1.0; constexpr int64_t LONG_PRESS_DELAY = GESTURE_BASE_DURATION; +constexpr long int EDGE_MARGIN = 10; void Tester::testFindSwipeEdges() { using Test = struct { @@ -33,7 +34,7 @@ void Tester::testFindSwipeEdges() { auto mockGM = CMockGestureManager::newCompletedGestureOnlyHandler(); for (auto& test : tests) { - CHECK_EQ(mockGM.find_swipe_edges(test.origin), test.result); + CHECK_EQ(mockGM.find_swipe_edges(test.origin, EDGE_MARGIN), test.result); } } @@ -276,7 +277,7 @@ TEST_CASE("Edge Swipe: Complete upon: \n" "3. lifting the finger, within the time limit.\n") { std::cout << " ==== stdout:" << std::endl; auto gm = CMockGestureManager::newCompletedGestureOnlyHandler(); - gm.addEdgeSwipeGesture(&SENSITIVITY, &LONG_PRESS_DELAY); + gm.addEdgeSwipeGesture(&SENSITIVITY, &LONG_PRESS_DELAY, &EDGE_MARGIN); const std::vector events{ {wf::touch::EVENT_TYPE_TOUCH_DOWN, 100, 0, {5, 300}}, @@ -292,7 +293,7 @@ TEST_CASE("Edge Swipe: Complete upon: \n" TEST_CASE("Edge Swipe: Timeout during swiping phase" * doctest::may_fail(true)) { std::cout << " ==== stdout:" << std::endl; auto gm = CMockGestureManager::newCompletedGestureOnlyHandler(); - gm.addEdgeSwipeGesture(&SENSITIVITY, &LONG_PRESS_DELAY); + gm.addEdgeSwipeGesture(&SENSITIVITY, &LONG_PRESS_DELAY, &EDGE_MARGIN); const std::vector events{ {wf::touch::EVENT_TYPE_TOUCH_DOWN, 100, 0, {5, 300}}, @@ -310,7 +311,7 @@ TEST_CASE("Edge Swipe: Fail check at the end for not starting swipe from an edge "fail.") { std::cout << " ==== stdout:" << std::endl; auto gm = CMockGestureManager::newCompletedGestureOnlyHandler(); - gm.addEdgeSwipeGesture(&SENSITIVITY, &LONG_PRESS_DELAY); + gm.addEdgeSwipeGesture(&SENSITIVITY, &LONG_PRESS_DELAY, &EDGE_MARGIN); const std::vector events{ {wf::touch::EVENT_TYPE_TOUCH_DOWN, 100, 0, {11, 300}}, @@ -326,7 +327,7 @@ TEST_CASE("Edge Swipe: Fail check at the end for not starting swipe from an edge TEST_CASE("Edge Swipe Drag: begin") { std::cout << " ==== stdout:" << std::endl; auto gm = CMockGestureManager::newDragHandler(); - gm.addEdgeSwipeGesture(&SENSITIVITY, &LONG_PRESS_DELAY); + gm.addEdgeSwipeGesture(&SENSITIVITY, &LONG_PRESS_DELAY, &EDGE_MARGIN); const std::vector events{ {wf::touch::EVENT_TYPE_TOUCH_DOWN, 100, 0, {5, 300}}, @@ -339,7 +340,7 @@ TEST_CASE("Edge Swipe Drag: begin") { TEST_CASE("Edge Swipe Drag: emits drag end event") { auto gm = CMockGestureManager::newDragHandler(); - gm.addEdgeSwipeGesture(&SENSITIVITY, &LONG_PRESS_DELAY); + gm.addEdgeSwipeGesture(&SENSITIVITY, &LONG_PRESS_DELAY, &EDGE_MARGIN); const std::vector events{ {wf::touch::EVENT_TYPE_TOUCH_DOWN, 100, 0, {5, 300}}, {wf::touch::EVENT_TYPE_MOTION, 150, 0, {250, 300}}, diff --git a/src/main.cpp b/src/main.cpp index 8018fdf..a9aed06 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,6 +98,8 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { Hyprlang::CConfigValue((Hyprlang::FLOAT)1.0)); HyprlandAPI::addConfigValue(PHANDLE, "plugin:touch_gestures:long_press_delay", Hyprlang::CConfigValue((Hyprlang::INT)400)); + HyprlandAPI::addConfigValue(PHANDLE, "plugin:touch_gestures:edge_margin", + Hyprlang::CConfigValue((Hyprlang::INT)10)); HyprlandAPI::addConfigValue(PHANDLE, "plugin:touch_gestures:experimental:send_cancel", Hyprlang::CConfigValue((Hyprlang::INT)0)); #pragma GCC diagnostic pop From 54ff83022f7351214bd0d843cab564c81fddb8a6 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sun, 21 Jul 2024 11:29:18 +0200 Subject: [PATCH 2/5] docs: add edge_margin --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7ebddd9..f034df8 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,9 @@ plugin:touch_gestures { # in milliseconds long_press_delay = 400 + # in pixels, the distance from the edge that is considered an edge + edge_margin = 10 + experimental { # send proper cancel events to windows instead of hacky touch_up events, # NOT recommended as it crashed a few times, once it's stabilized I'll make it the default From 7d30f113d12464108bb15a8ed1d8a5fb8bc85b3b Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Fri, 9 Aug 2024 19:52:32 +0200 Subject: [PATCH 3/5] flake: update --- flake.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/flake.lock b/flake.lock index da1b230..c0f60c4 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ ] }, "locked": { - "lastModified": 1722100913, - "narHash": "sha256-75Hcx5Zu0f+BeCkZxN1frkYacjbkwgCq+z3doVgr4Hw=", + "lastModified": 1722347739, + "narHash": "sha256-rAoh+K6KG+b1DwSWtqRVocdojnH6nGk6q07mNltoUSM=", "owner": "hyprwm", "repo": "aquamarine", - "rev": "4918e57979bbdbd05aabb20f63e1cb5dc289bcbd", + "rev": "7c3565f9bedc7cb601cc0baa14792247e4dc1d5a", "type": "github" }, "original": { @@ -74,11 +74,11 @@ "xdph": "xdph" }, "locked": { - "lastModified": 1722181325, - "narHash": "sha256-tBpry8IeRnwj8ThDsj4tzPo6WrOnERJe7HANCwN/rZY=", + "lastModified": 1723224800, + "narHash": "sha256-2b+cECwR+3FL/ikuZnXE94H8bXdlnYUbhmi1KNpD/tc=", "ref": "refs/heads/main", - "rev": "fcff2dcac24ca497a39c1cb271d449ade037b7ad", - "revCount": 5005, + "rev": "8b37e81374928856d8fd859b95a62c8bf4211901", + "revCount": 5073, "submodules": true, "type": "git", "url": "https://github.com/hyprwm/Hyprland" @@ -197,11 +197,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1721924956, - "narHash": "sha256-Sb1jlyRO+N8jBXEX9Pg9Z1Qb8Bw9QyOgLDNMEpmjZ2M=", + "lastModified": 1722185531, + "narHash": "sha256-veKR07psFoJjINLC8RK4DiLniGGMgF3QMlS4tb74S6k=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5ad6a14c6bf098e98800b091668718c336effc95", + "rev": "52ec9ac3b12395ad677e8b62106f0b98c1f8569d", "type": "github" }, "original": { @@ -248,11 +248,11 @@ ] }, "locked": { - "lastModified": 1722181019, - "narHash": "sha256-Lj/g1UzrsTZUixtveQix6eB3pon2j23qv5/5pzTx0LQ=", + "lastModified": 1722365976, + "narHash": "sha256-Khdm+mDzYA//XaU0M+hftod+rKr5q9SSHSEuiQ0/9ow=", "owner": "hyprwm", "repo": "xdg-desktop-portal-hyprland", - "rev": "0e2f3b9c85f7bab3983098a01366876d34daf383", + "rev": "7f2a77ddf60390248e2a3de2261d7102a13e5341", "type": "github" }, "original": { From c0af0f9e7e21afbe3588ec419760fe06d8236967 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Fri, 9 Aug 2024 20:07:37 +0200 Subject: [PATCH 4/5] add tests for edge margin --- src/gestures/test/MockGestureManager.hpp | 10 ++++- src/gestures/test/test.cpp | 54 +++++++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/gestures/test/MockGestureManager.hpp b/src/gestures/test/MockGestureManager.hpp index 21accc3..5748f1d 100644 --- a/src/gestures/test/MockGestureManager.hpp +++ b/src/gestures/test/MockGestureManager.hpp @@ -25,6 +25,14 @@ class CMockGestureManager final : public IGestureManager { bool cancelled = false; bool dragEnded = false; + struct { + double x, y; + } mon_offset = {MONITOR_X, MONITOR_Y}; + + struct { + double w, h; + } mon_size = {MONITOR_WIDTH, MONITOR_HEIGHT}; + // creates a gesture manager that handles all drag gestures static CMockGestureManager newDragHandler() { return CMockGestureManager(true); @@ -61,7 +69,7 @@ class CMockGestureManager final : public IGestureManager { protected: SMonitorArea getMonitorArea() const override { - return SMonitorArea{MONITOR_X, MONITOR_Y, MONITOR_WIDTH, MONITOR_HEIGHT}; + return SMonitorArea{this->mon_offset.x, this->mon_offset.y, this->mon_size.w, this->mon_size.h}; } private: diff --git a/src/gestures/test/test.cpp b/src/gestures/test/test.cpp index 05de4e7..a57cdbe 100644 --- a/src/gestures/test/test.cpp +++ b/src/gestures/test/test.cpp @@ -4,7 +4,6 @@ #include "MockGestureManager.hpp" #include "wayfire/touch/touch.hpp" -#include #include constexpr float SENSITIVITY = 1.0; @@ -44,6 +43,7 @@ enum class ExpectResultType { DRAG_ENDED, CANCELLED, CHECK_PROGRESS, + NOTHING_HAPPENED, }; struct ExpectResult { @@ -96,6 +96,10 @@ void ProcessEvents(CMockGestureManager& gm, ExpectResult expect, case ExpectResultType::CANCELLED: CHECK(gm.cancelled); break; + case ExpectResultType::NOTHING_HAPPENED: + CHECK(!gm.cancelled); + CHECK(!gm.dragEnded); + CHECK(!gm.getActiveDragGesture().has_value()); case ExpectResultType::CHECK_PROGRESS: const auto got = gm.getGestureAt(expect.gesture_index)->get()->get_progress(); // fuck floating point math @@ -351,3 +355,51 @@ TEST_CASE("Edge Swipe Drag: emits drag end event") { const ExpectResult expected_result = {ExpectResultType::DRAG_ENDED, 1.0}; ProcessEvents(gm, expected_result, events); } + +TEST_CASE("Edge Swipe: margins") { + SUBCASE("custom margin: less than threshold triggers") { + auto gm = CMockGestureManager::newDragHandler(); + long margin = 20; + gm.addEdgeSwipeGesture(&SENSITIVITY, &LONG_PRESS_DELAY, &margin); + + const std::vector events{ + {wf::touch::EVENT_TYPE_TOUCH_DOWN, 100, 0, {19, 300}}, {wf::touch::EVENT_TYPE_MOTION, 150, 0, {250, 300}}, + {wf::touch::EVENT_TYPE_MOTION, 200, 0, {455, 300}}, {wf::touch::EVENT_TYPE_MOTION, 250, 0, {600, 300}}, + {wf::touch::EVENT_TYPE_TOUCH_UP, 300, 0, {700, 400}}, + }; + + const ExpectResult expected_result = {ExpectResultType::DRAG_ENDED, 1.0}; + ProcessEvents(gm, expected_result, events); + } + + SUBCASE("with non-zero offset") { + auto gm = CMockGestureManager::newDragHandler(); + gm.mon_offset = {2000, 0}; + long margin = 20; + gm.addEdgeSwipeGesture(&SENSITIVITY, &LONG_PRESS_DELAY, &margin); + + const std::vector events{ + {wf::touch::EVENT_TYPE_TOUCH_DOWN, 100, 0, {2019, 300}}, {wf::touch::EVENT_TYPE_MOTION, 150, 0, {250, 300}}, + {wf::touch::EVENT_TYPE_MOTION, 200, 0, {2455, 300}}, {wf::touch::EVENT_TYPE_MOTION, 250, 0, {600, 300}}, + {wf::touch::EVENT_TYPE_TOUCH_UP, 300, 0, {2700, 400}}, + }; + + const ExpectResult expected_result = {ExpectResultType::DRAG_ENDED, 1.0}; + ProcessEvents(gm, expected_result, events); + } + + SUBCASE("custom margin: more than threshold does not trigger") { + auto gm = CMockGestureManager::newDragHandler(); + long margin = 20; + gm.addEdgeSwipeGesture(&SENSITIVITY, &LONG_PRESS_DELAY, &margin); + + const std::vector events{ + {wf::touch::EVENT_TYPE_TOUCH_DOWN, 100, 0, {21, 300}}, {wf::touch::EVENT_TYPE_MOTION, 150, 0, {250, 300}}, + {wf::touch::EVENT_TYPE_MOTION, 200, 0, {455, 300}}, {wf::touch::EVENT_TYPE_MOTION, 250, 0, {600, 300}}, + {wf::touch::EVENT_TYPE_TOUCH_UP, 300, 0, {700, 400}}, + }; + + const ExpectResult expected_result = {ExpectResultType::NOTHING_HAPPENED, 1.0}; + ProcessEvents(gm, expected_result, events); + } +} From 80a8b29593e0eef8fcf5969670094a0350922f2b Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Fri, 9 Aug 2024 21:04:27 +0200 Subject: [PATCH 5/5] add simple logger --- src/GestureManager.cpp | 3 ++- src/GestureManager.hpp | 3 ++- src/HyprLogger.hpp | 9 +++++++++ src/gestures/Gestures.cpp | 2 -- src/gestures/Gestures.hpp | 4 +++- src/gestures/Logger.hpp | 8 ++++++++ src/gestures/test/CoutLogger.hpp | 9 +++++++++ src/gestures/test/MockGestureManager.cpp | 2 -- src/gestures/test/MockGestureManager.hpp | 5 ++++- 9 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 src/HyprLogger.hpp create mode 100644 src/gestures/Logger.hpp create mode 100644 src/gestures/test/CoutLogger.hpp diff --git a/src/GestureManager.cpp b/src/GestureManager.cpp index f725bca..b92d244 100644 --- a/src/GestureManager.cpp +++ b/src/GestureManager.cpp @@ -1,4 +1,5 @@ #include "GestureManager.hpp" +#include "globals.hpp" #include "wayfire/touch/touch.hpp" #include #include @@ -61,7 +62,7 @@ int handleLongPressTimer(void* data) { return 0; } -GestureManager::GestureManager() { +GestureManager::GestureManager() : IGestureManager(std::make_unique()) { static auto const PSENSITIVITY = (Hyprlang::FLOAT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:touch_gestures:sensitivity") ->getDataStaticPtr(); diff --git a/src/GestureManager.hpp b/src/GestureManager.hpp index 77745b2..c4e7329 100644 --- a/src/GestureManager.hpp +++ b/src/GestureManager.hpp @@ -1,7 +1,8 @@ #pragma once #include "./gestures/Gestures.hpp" +#include "HyprLogger.hpp" #include "gestures/Shared.hpp" -#include "globals.hpp" +#include #define private public #include diff --git a/src/HyprLogger.hpp b/src/HyprLogger.hpp new file mode 100644 index 0000000..7167a4f --- /dev/null +++ b/src/HyprLogger.hpp @@ -0,0 +1,9 @@ +#include "gestures/Logger.hpp" +#include "src/debug/Log.hpp" + +class HyprLogger : public Logger { + public: + void debug(std::string s) { + Debug::log(INFO, s); + } +}; diff --git a/src/gestures/Gestures.cpp b/src/gestures/Gestures.cpp index af1ed82..bfa26cf 100644 --- a/src/gestures/Gestures.cpp +++ b/src/gestures/Gestures.cpp @@ -1,10 +1,8 @@ #include "Gestures.hpp" #include "Actions.hpp" -#include #include #include #include -#include #include #include diff --git a/src/gestures/Gestures.hpp b/src/gestures/Gestures.hpp index c4aabec..1caae4c 100644 --- a/src/gestures/Gestures.hpp +++ b/src/gestures/Gestures.hpp @@ -2,8 +2,8 @@ #include "CompletedGesture.hpp" #include "DragGesture.hpp" +#include "Logger.hpp" #include "Shared.hpp" -#include #include #include #include @@ -23,6 +23,7 @@ struct SMonitorArea { */ class IGestureManager { public: + IGestureManager(std::unique_ptr logger) : logger(std::move(logger)) {} virtual ~IGestureManager() {} // @return whether this touch event should be blocked from forwarding to the // client window/surface @@ -78,6 +79,7 @@ class IGestureManager { virtual void stopLongPressTimer() = 0; private: + std::unique_ptr logger; bool inhibitTouchEvents; std::optional activeDragGesture; diff --git a/src/gestures/Logger.hpp b/src/gestures/Logger.hpp new file mode 100644 index 0000000..e9e191d --- /dev/null +++ b/src/gestures/Logger.hpp @@ -0,0 +1,8 @@ +#pragma once +#include + +class Logger { + public: + virtual ~Logger() {} + virtual void debug(std::string s) = 0; +}; diff --git a/src/gestures/test/CoutLogger.hpp b/src/gestures/test/CoutLogger.hpp new file mode 100644 index 0000000..cfeaa82 --- /dev/null +++ b/src/gestures/test/CoutLogger.hpp @@ -0,0 +1,9 @@ +#pragma once +#include "../Logger.hpp" +#include + +class CoutLogger : public Logger { + void debug(std::string s) override { + std::cout << s << std::endl; + } +}; diff --git a/src/gestures/test/MockGestureManager.cpp b/src/gestures/test/MockGestureManager.cpp index b52c132..c43ba46 100644 --- a/src/gestures/test/MockGestureManager.cpp +++ b/src/gestures/test/MockGestureManager.cpp @@ -1,6 +1,4 @@ #include "MockGestureManager.hpp" -#include "../Gestures.hpp" -#include #include #define CONFIG_SENSITIVITY 1.0 diff --git a/src/gestures/test/MockGestureManager.hpp b/src/gestures/test/MockGestureManager.hpp index 5748f1d..236da64 100644 --- a/src/gestures/test/MockGestureManager.hpp +++ b/src/gestures/test/MockGestureManager.hpp @@ -1,6 +1,8 @@ #pragma once #include "../Gestures.hpp" +#include "CoutLogger.hpp" #include "wayfire/touch/touch.hpp" +#include #include constexpr double MONITOR_X = 0; @@ -15,7 +17,8 @@ class Tester { class CMockGestureManager final : public IGestureManager { public: - CMockGestureManager(bool handlesDragEvents) : handlesDragEvents(handlesDragEvents) {} + CMockGestureManager(bool handlesDragEvents) + : IGestureManager(std::make_unique()), handlesDragEvents(handlesDragEvents) {} ~CMockGestureManager() {} // if set to true, handleDragGesture() will return true