From 53ce93c6a553510d961b7444159a11b8156958b8 Mon Sep 17 00:00:00 2001 From: pixl Date: Fri, 28 Apr 2023 22:22:17 -0400 Subject: [PATCH] Add gesture IPC interfaces Also fixes concurrency issues when changing action configs. --- src/logid/actions/Action.h | 2 + src/logid/actions/ChangeDPI.cpp | 50 ++++++++------- src/logid/actions/ChangeHostAction.cpp | 15 +++-- src/logid/actions/CycleDPI.cpp | 7 ++- src/logid/actions/CycleDPI.h | 2 +- src/logid/actions/GestureAction.cpp | 11 ++-- src/logid/actions/GestureAction.h | 1 - src/logid/actions/KeypressAction.cpp | 8 +-- src/logid/actions/KeypressAction.h | 1 - src/logid/actions/gesture/AxisGesture.cpp | 63 +++++++++++++++++-- src/logid/actions/gesture/AxisGesture.h | 9 +++ src/logid/actions/gesture/Gesture.h | 2 + src/logid/actions/gesture/IntervalGesture.cpp | 45 +++++++++++-- src/logid/actions/gesture/IntervalGesture.h | 21 +++---- src/logid/actions/gesture/ReleaseGesture.cpp | 34 +++++++++- src/logid/actions/gesture/ReleaseGesture.h | 6 ++ .../actions/gesture/ThresholdGesture.cpp | 37 +++++++++-- src/logid/actions/gesture/ThresholdGesture.h | 6 ++ src/logid/features/RemapButton.cpp | 7 +-- 19 files changed, 249 insertions(+), 78 deletions(-) diff --git a/src/logid/actions/Action.h b/src/logid/actions/Action.h index b897214..1ef70cd 100644 --- a/src/logid/actions/Action.h +++ b/src/logid/actions/Action.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "../config/schema.h" namespace logid { @@ -88,6 +89,7 @@ namespace logid::actions { Device* _device; std::atomic _pressed; + mutable std::shared_mutex _config_mutex; }; } diff --git a/src/logid/actions/ChangeDPI.cpp b/src/logid/actions/ChangeDPI.cpp index 9bee923..e1fe3da 100644 --- a/src/logid/actions/ChangeDPI.cpp +++ b/src/logid/actions/ChangeDPI.cpp @@ -43,38 +43,21 @@ ChangeDPI::ChangeDPI( _device->hidpp20().deviceIndex()); } -std::tuple ChangeDPI::getConfig() const { - return {_config.inc.value_or(0), _config.sensor.value_or(0)}; -} - -void ChangeDPI::setChange(int16_t change) { - _config.inc = change; -} - -void ChangeDPI::setSensor(uint8_t sensor, bool reset) { - if (reset) { - _config.sensor.reset(); - } else { - _config.sensor = sensor; - } -} - void ChangeDPI::press() { _pressed = true; + std::shared_lock lock(_config_mutex); if (_dpi && _config.inc.has_value()) { spawn_task( - [this] { + [this, sensor = _config.sensor.value_or(0), + inc = _config.inc.value()] { try { - uint16_t last_dpi = _dpi->getDPI(_config.sensor.value_or(0)); - _dpi->setDPI(last_dpi + _config.inc.value(), - _config.sensor.value_or(0)); + uint16_t last_dpi = _dpi->getDPI(sensor); + _dpi->setDPI(last_dpi + inc,sensor); } catch (backend::hidpp20::Error& e) { if (e.code() == backend::hidpp20::Error::InvalidArgument) - logPrintf(WARN, "%s:%d: Could not get/set DPI for sensor " - "%d", + logPrintf(WARN, "%s:%d: Could not get/set DPI for sensor %d", _device->hidpp20().devicePath().c_str(), - _device->hidpp20().deviceIndex(), - _config.sensor.value_or(0)); + _device->hidpp20().deviceIndex(), sensor); else throw e; } @@ -89,3 +72,22 @@ void ChangeDPI::release() { uint8_t ChangeDPI::reprogFlags() const { return backend::hidpp20::ReprogControls::TemporaryDiverted; } + +std::tuple ChangeDPI::getConfig() const { + std::shared_lock lock(_config_mutex); + return {_config.inc.value_or(0), _config.sensor.value_or(0)}; +} + +void ChangeDPI::setChange(int16_t change) { + std::unique_lock lock(_config_mutex); + _config.inc = change; +} + +void ChangeDPI::setSensor(uint8_t sensor, bool reset) { + std::unique_lock lock(_config_mutex); + if (reset) { + _config.sensor.reset(); + } else { + _config.sensor = sensor; + } +} diff --git a/src/logid/actions/ChangeHostAction.cpp b/src/logid/actions/ChangeHostAction.cpp index c36831c..3b821fd 100644 --- a/src/logid/actions/ChangeHostAction.cpp +++ b/src/logid/actions/ChangeHostAction.cpp @@ -54,6 +54,7 @@ ChangeHostAction::ChangeHostAction( } std::string ChangeHostAction::getHost() const { + std::shared_lock lock(_config_mutex); if (_config.host.has_value()) { if (std::holds_alternative(_config.host.value())) return std::get(_config.host.value()); @@ -67,6 +68,7 @@ std::string ChangeHostAction::getHost() const { void ChangeHostAction::setHost(std::string host) { std::transform(host.begin(), host.end(), host.begin(), ::tolower); + std::unique_lock lock(_config_mutex); if (host == "next" || host == "prev" || host == "previous") { _config.host = std::move(host); } else { @@ -79,21 +81,22 @@ void ChangeHostAction::press() { } void ChangeHostAction::release() { + std::shared_lock lock(_config_mutex); if (_change_host && _config.host.has_value()) { spawn_task( - [this] { + [this, host=_config.host.value()] { auto host_info = _change_host->getHostInfo(); int next_host; - if (std::holds_alternative(_config.host.value())) { - const auto& host = std::get(_config.host.value()); - if (host == "next") + if (std::holds_alternative(host)) { + const auto& host_str = std::get(host); + if (host_str == "next") next_host = host_info.currentHost + 1; - else if (host == "prev" || host == "previous") + else if (host_str == "prev" || host_str == "previous") next_host = host_info.currentHost - 1; else next_host = host_info.currentHost; } else { - next_host = std::get(_config.host.value()) - 1; + next_host = std::get(host) - 1; } next_host %= host_info.hostCount; if (next_host != host_info.currentHost) diff --git a/src/logid/actions/CycleDPI.cpp b/src/logid/actions/CycleDPI.cpp index 0d29fc6..58c768c 100644 --- a/src/logid/actions/CycleDPI.cpp +++ b/src/logid/actions/CycleDPI.cpp @@ -49,19 +49,22 @@ CycleDPI::CycleDPI(Device* device, config::CycleDPI& config, } std::vector CycleDPI::getDPIs() const { + std::shared_lock lock(_config_mutex); auto dpis = _config.dpis.value_or(std::list()); return {dpis.begin(), dpis.end()}; } void CycleDPI::setDPIs(const std::vector& dpis) { - std::lock_guard lock(_dpi_lock); + std::unique_lock lock(_config_mutex); + std::lock_guard dpi_lock(_dpi_mutex); _config.dpis.emplace(dpis.begin(), dpis.end()); _current_dpi = _config.dpis->cbegin(); } void CycleDPI::press() { _pressed = true; - std::lock_guard lock(_dpi_lock); + std::shared_lock lock(_config_mutex); + std::lock_guard dpi_lock(_dpi_mutex); if (_dpi && _config.dpis.has_value() && _config.dpis.value().empty()) { ++_current_dpi; if (_current_dpi == _config.dpis.value().end()) diff --git a/src/logid/actions/CycleDPI.h b/src/logid/actions/CycleDPI.h index 38e2a75..b0cb4d8 100644 --- a/src/logid/actions/CycleDPI.h +++ b/src/logid/actions/CycleDPI.h @@ -41,7 +41,7 @@ namespace logid::actions { [[nodiscard]] uint8_t reprogFlags() const final; protected: - std::mutex _dpi_lock; + std::mutex _dpi_mutex; config::CycleDPI& _config; std::shared_ptr _dpi; std::list::const_iterator _current_dpi; diff --git a/src/logid/actions/GestureAction.cpp b/src/logid/actions/GestureAction.cpp index 32ea194..0ddebf2 100644 --- a/src/logid/actions/GestureAction.cpp +++ b/src/logid/actions/GestureAction.cpp @@ -100,7 +100,7 @@ GestureAction::GestureAction(Device* dev, config::GestureAction& config, } void GestureAction::press() { - std::lock_guard lock(_config_lock); + std::shared_lock lock(_config_mutex); _pressed = true; _x = 0, _y = 0; @@ -109,7 +109,7 @@ void GestureAction::press() { } void GestureAction::release() { - std::lock_guard lock(_config_lock); + std::shared_lock lock(_config_mutex); _pressed = false; bool threshold_met = false; @@ -149,7 +149,7 @@ void GestureAction::release() { } void GestureAction::move(int16_t x, int16_t y) { - std::lock_guard lock(_config_lock); + std::shared_lock lock(_config_mutex); int32_t new_x = _x + x, new_y = _y + y; @@ -222,9 +222,8 @@ uint8_t GestureAction::reprogFlags() const { hidpp20::ReprogControls::RawXYDiverted); } -void GestureAction::setGesture(const std::string& direction, - const std::string& type) { - std::lock_guard lock(_config_lock); +void GestureAction::setGesture(const std::string& direction, const std::string& type) { + std::unique_lock lock(_config_mutex); Direction d = toDirection(direction); diff --git a/src/logid/actions/GestureAction.h b/src/logid/actions/GestureAction.h index 52b0ab6..9b3859f 100644 --- a/src/logid/actions/GestureAction.h +++ b/src/logid/actions/GestureAction.h @@ -61,7 +61,6 @@ namespace logid::actions { std::shared_ptr _node; std::map> _gestures; config::GestureAction& _config; - mutable std::mutex _config_lock; }; } diff --git a/src/logid/actions/KeypressAction.cpp b/src/logid/actions/KeypressAction.cpp index 864aa10..091b212 100644 --- a/src/logid/actions/KeypressAction.cpp +++ b/src/logid/actions/KeypressAction.cpp @@ -40,14 +40,14 @@ KeypressAction::KeypressAction( } void KeypressAction::press() { - std::lock_guard lock(_config_lock); + std::shared_lock lock(_config_mutex); _pressed = true; for (auto& key: _keys) _device->virtualInput()->pressKey(key); } void KeypressAction::release() { - std::lock_guard lock(_config_lock); + std::shared_lock lock(_config_mutex); _pressed = false; for (auto& key: _keys) _device->virtualInput()->releaseKey(key); @@ -103,7 +103,7 @@ uint8_t KeypressAction::reprogFlags() const { } std::vector KeypressAction::getKeys() const { - std::lock_guard lock(_config_lock); + std::shared_lock lock(_config_mutex); std::vector ret; for (auto& x: _keys) ret.push_back(InputDevice::toKeyName(x)); @@ -112,7 +112,7 @@ std::vector KeypressAction::getKeys() const { } void KeypressAction::setKeys(const std::vector& keys) { - std::lock_guard lock(_config_lock); + std::unique_lock lock(_config_mutex); if (_pressed) for (auto& key: _keys) _device->virtualInput()->releaseKey(key); diff --git a/src/logid/actions/KeypressAction.h b/src/logid/actions/KeypressAction.h index a544bce..ea3ee12 100644 --- a/src/logid/actions/KeypressAction.h +++ b/src/logid/actions/KeypressAction.h @@ -42,7 +42,6 @@ namespace logid::actions { [[nodiscard]] uint8_t reprogFlags() const final; protected: - mutable std::mutex _config_lock; config::KeypressAction& _config; std::list _keys; diff --git a/src/logid/actions/gesture/AxisGesture.cpp b/src/logid/actions/gesture/AxisGesture.cpp index 0735473..82711d3 100644 --- a/src/logid/actions/gesture/AxisGesture.cpp +++ b/src/logid/actions/gesture/AxisGesture.cpp @@ -26,7 +26,16 @@ const char* AxisGesture::interface_name = "Axis"; AxisGesture::AxisGesture(Device* device, config::AxisGesture& config, const std::shared_ptr& parent) : - Gesture(device, parent, interface_name), _multiplier(1), _config(config) { + Gesture(device, parent, interface_name, { + { + {"GetConfig", {this, &AxisGesture::getConfig, {"axis", "multiplier", "threshold"}}}, + {"SetThreshold", {this, &AxisGesture::setThreshold, {"threshold"}}}, + {"SetMultiplier", {this, &AxisGesture::setMultiplier, {"multiplier"}}}, + {"SetAxis", {this, &AxisGesture::setAxis, {"axis"}}} + }, + {}, + {} + }), _multiplier(1), _config(config) { if (_config.axis.has_value()) { if (std::holds_alternative(_config.axis.value())) { _input_axis = std::get(_config.axis.value()); @@ -34,7 +43,6 @@ AxisGesture::AxisGesture(Device* device, config::AxisGesture& config, const auto& axis = std::get(_config.axis.value()); try { _input_axis = _device->virtualInput()->toAxisCode(axis); - _device->virtualInput()->registerAxis(_input_axis.value()); } catch (InputDevice::InvalidEventCode& e) { logPrintf(WARN, "Invalid axis %s."); } @@ -47,6 +55,7 @@ AxisGesture::AxisGesture(Device* device, config::AxisGesture& config, } void AxisGesture::press(bool init_threshold) { + std::shared_lock lock(_config_mutex); if (init_threshold) { _axis = (int32_t) (_config.threshold.value_or(defaults::gesture_threshold)); } else { @@ -62,6 +71,7 @@ void AxisGesture::release(bool primary) { } void AxisGesture::move(int16_t axis) { + std::shared_lock lock(_config_mutex); if (!_input_axis.has_value()) return; @@ -115,6 +125,7 @@ void AxisGesture::move(int16_t axis) { } bool AxisGesture::metThreshold() const { + std::shared_lock lock(_config_mutex); return _axis >= _config.threshold.value_or(defaults::gesture_threshold); } @@ -123,7 +134,51 @@ bool AxisGesture::wheelCompatibility() const { } void AxisGesture::setHiresMultiplier(double multiplier) { - if (InputDevice::getLowResAxis(_axis) != -1) { - _multiplier = multiplier; + _hires_multiplier = multiplier; + if (_input_axis.has_value()) { + if (InputDevice::getLowResAxis(_input_axis.value()) != -1) + _multiplier = _config.axis_multiplier.value_or(1) * multiplier; } } + +std::tuple AxisGesture::getConfig() const { + std::shared_lock lock(_config_mutex); + std::string axis; + if (_config.axis.has_value()) { + if (std::holds_alternative(_config.axis.value())) { + axis = std::get(_config.axis.value()); + } else { + axis = _device->virtualInput()->toAxisName(std::get(_config.axis.value())); + } + } + + return {axis, _config.axis_multiplier.value_or(1), _config.threshold.value_or(0)}; +} + +void AxisGesture::setAxis(const std::string& axis) { + std::unique_lock lock(_config_mutex); + if (axis.empty()) { + _config.axis.reset(); + _input_axis.reset(); + } else { + _input_axis = _device->virtualInput()->toAxisCode(axis); + _config.axis = axis; + _device->virtualInput()->registerAxis(_input_axis.value()); + } + setHiresMultiplier(_hires_multiplier); +} + +void AxisGesture::setMultiplier(double multiplier) { + std::unique_lock lock(_config_mutex); + _config.axis_multiplier = multiplier; + _multiplier = multiplier; + setHiresMultiplier(_hires_multiplier); +} + +void AxisGesture::setThreshold(int threshold) { + std::unique_lock lock(_config_mutex); + if (threshold == 0) + _config.threshold.reset(); + else + _config.threshold = threshold; +} diff --git a/src/logid/actions/gesture/AxisGesture.h b/src/logid/actions/gesture/AxisGesture.h index e00d9c2..af80c01 100644 --- a/src/logid/actions/gesture/AxisGesture.h +++ b/src/logid/actions/gesture/AxisGesture.h @@ -40,12 +40,21 @@ namespace logid::actions { void setHiresMultiplier(double multiplier); + [[nodiscard]] std::tuple getConfig() const; + + void setAxis(const std::string& axis); + + void setMultiplier(double multiplier); + + void setThreshold(int threshold); + protected: int32_t _axis{}; double _axis_remainder{}; int _hires_remainder{}; std::optional _input_axis; double _multiplier; + double _hires_multiplier = 1.0; config::AxisGesture& _config; }; } diff --git a/src/logid/actions/gesture/Gesture.h b/src/logid/actions/gesture/Gesture.h index 8204135..65dab68 100644 --- a/src/logid/actions/gesture/Gesture.h +++ b/src/logid/actions/gesture/Gesture.h @@ -64,6 +64,8 @@ namespace logid::actions { std::shared_ptr parent, const std::string& name, tables t = {}); + mutable std::shared_mutex _config_mutex; + const std::shared_ptr _node; Device* _device; }; diff --git a/src/logid/actions/gesture/IntervalGesture.cpp b/src/logid/actions/gesture/IntervalGesture.cpp index ac9cd4e..12d713b 100644 --- a/src/logid/actions/gesture/IntervalGesture.cpp +++ b/src/logid/actions/gesture/IntervalGesture.cpp @@ -25,7 +25,16 @@ const char* IntervalGesture::interface_name = "OnInterval"; IntervalGesture::IntervalGesture( Device* device, config::IntervalGesture& config, const std::shared_ptr& parent) : - Gesture(device, parent, interface_name), + Gesture(device, parent, interface_name, { + { + {"GetConfig", {this, &IntervalGesture::getConfig, {"interval", "threshold"}}}, + {"SetInterval", {this, &IntervalGesture::setInterval, {"interval"}}}, + {"SetThreshold", {this, &IntervalGesture::setThreshold, {"interval"}}}, + {"SetAction", {this, &IntervalGesture::setAction, {"type"}}} + }, + {}, + {} + }), _axis(0), _interval_pass_count(0), _config(config) { if (config.action) { try { @@ -37,6 +46,7 @@ IntervalGesture::IntervalGesture( } void IntervalGesture::press(bool init_threshold) { + std::shared_lock lock(_config_mutex); if (init_threshold) { _axis = (int32_t) _config.threshold.value_or(defaults::gesture_threshold); } else { @@ -45,12 +55,11 @@ void IntervalGesture::press(bool init_threshold) { _interval_pass_count = 0; } -void IntervalGesture::release(bool primary) { - // Do nothing - (void) primary; // Suppress unused warning +void IntervalGesture::release([[maybe_unused]] bool primary) { } void IntervalGesture::move(int16_t axis) { + std::shared_lock lock(_config_mutex); if (!_config.interval.has_value()) return; @@ -75,5 +84,33 @@ bool IntervalGesture::wheelCompatibility() const { } bool IntervalGesture::metThreshold() const { + std::shared_lock lock(_config_mutex); return _axis >= _config.threshold.value_or(defaults::gesture_threshold); } + +std::tuple IntervalGesture::getConfig() const { + std::shared_lock lock(_config_mutex); + return {_config.interval.value_or(0), _config.threshold.value_or(0)}; +} + +void IntervalGesture::setInterval(int interval) { + std::unique_lock lock(_config_mutex); + if (interval == 0) + _config.interval.reset(); + else + _config.interval = interval; +} + +void IntervalGesture::setThreshold(int threshold) { + std::unique_lock lock(_config_mutex); + if (threshold == 0) + _config.threshold.reset(); + else + _config.threshold = threshold; +} + +void IntervalGesture::setAction(const std::string& type) { + std::unique_lock lock(_config_mutex); + _action.reset(); + _action = Action::makeAction(_device, type, _config.action, _node); +} diff --git a/src/logid/actions/gesture/IntervalGesture.h b/src/logid/actions/gesture/IntervalGesture.h index 5a208ff..95081e0 100644 --- a/src/logid/actions/gesture/IntervalGesture.h +++ b/src/logid/actions/gesture/IntervalGesture.h @@ -38,25 +38,20 @@ namespace logid::actions { [[nodiscard]] bool metThreshold() const final; + [[nodiscard]] std::tuple getConfig() const; + + void setInterval(int interval); + + void setThreshold(int threshold); + + void setAction(const std::string& type); + protected: int32_t _axis; int32_t _interval_pass_count; std::shared_ptr _action; config::IntervalGesture& _config; private: - class IPC : public ipcgull::interface { - public: - explicit IPC(IntervalGesture* parent); - - void setAction(const std::string& type); - - void setInterval(int interval); - - void setThreshold(int threshold); - - private: - IntervalGesture& parent; - }; }; } diff --git a/src/logid/actions/gesture/ReleaseGesture.cpp b/src/logid/actions/gesture/ReleaseGesture.cpp index d7b5e69..568529f 100644 --- a/src/logid/actions/gesture/ReleaseGesture.cpp +++ b/src/logid/actions/gesture/ReleaseGesture.cpp @@ -24,12 +24,21 @@ const char* ReleaseGesture::interface_name = "OnRelease"; ReleaseGesture::ReleaseGesture(Device* device, config::ReleaseGesture& config, const std::shared_ptr& parent) : - Gesture(device, parent, interface_name), _config(config) { + Gesture(device, parent, interface_name, { + { + {"GetThreshold", {this, &ReleaseGesture::getThreshold, {"threshold"}}}, + {"SetThreshold", {this, &ReleaseGesture::setThreshold, {"threshold"}}}, + {"SetAction", {this, &ReleaseGesture::setAction, {"type"}}} + }, + {}, + {} + }), _config(config) { if (_config.action.has_value()) _action = Action::makeAction(device, _config.action.value(), _node); } void ReleaseGesture::press(bool init_threshold) { + std::shared_lock lock(_config_mutex); if (init_threshold) { _axis = (int32_t) (_config.threshold.value_or(defaults::gesture_threshold)); } else { @@ -55,5 +64,26 @@ bool ReleaseGesture::wheelCompatibility() const { } bool ReleaseGesture::metThreshold() const { + std::shared_lock lock(_config_mutex); return _axis >= _config.threshold.value_or(defaults::gesture_threshold); -} \ No newline at end of file +} + + +int ReleaseGesture::getThreshold() const { + std::shared_lock lock(_config_mutex); + return _config.threshold.value_or(0); +} + +void ReleaseGesture::setThreshold(int threshold) { + std::unique_lock lock(_config_mutex); + if (threshold == 0) + _config.threshold.reset(); + else + _config.threshold = threshold; +} + +void ReleaseGesture::setAction(const std::string& type) { + std::unique_lock lock(_config_mutex); + _action.reset(); + _action = Action::makeAction(_device, type, _config.action, _node); +} diff --git a/src/logid/actions/gesture/ReleaseGesture.h b/src/logid/actions/gesture/ReleaseGesture.h index f950e1e..c8f4c5b 100644 --- a/src/logid/actions/gesture/ReleaseGesture.h +++ b/src/logid/actions/gesture/ReleaseGesture.h @@ -38,6 +38,12 @@ namespace logid::actions { [[nodiscard]] bool metThreshold() const final; + [[nodiscard]] int getThreshold() const; + + void setThreshold(int threshold); + + void setAction(const std::string& type); + protected: int32_t _axis{}; std::shared_ptr _action; diff --git a/src/logid/actions/gesture/ThresholdGesture.cpp b/src/logid/actions/gesture/ThresholdGesture.cpp index 7741d32..0c2bfd6 100644 --- a/src/logid/actions/gesture/ThresholdGesture.cpp +++ b/src/logid/actions/gesture/ThresholdGesture.cpp @@ -25,7 +25,15 @@ const char* ThresholdGesture::interface_name = "OnRelease"; ThresholdGesture::ThresholdGesture( Device* device, config::ThresholdGesture& config, const std::shared_ptr& parent) : - Gesture(device, parent, interface_name), _config(config) { + Gesture(device, parent, interface_name, { + { + {"GetThreshold", {this, &ThresholdGesture::getThreshold, {"threshold"}}}, + {"SetThreshold", {this, &ThresholdGesture::setThreshold, {"threshold"}}}, + {"SetAction", {this, &ThresholdGesture::setAction, {"type"}}} + }, + {}, + {} + }), _config(config) { if (config.action) { try { _action = Action::makeAction(device, config.action.value(), _node); @@ -36,13 +44,12 @@ ThresholdGesture::ThresholdGesture( } void ThresholdGesture::press(bool init_threshold) { + std::shared_lock lock(_config_mutex); _axis = init_threshold ? (int32_t) _config.threshold.value_or(defaults::gesture_threshold) : 0; this->_executed = false; } -void ThresholdGesture::release(bool primary) { - (void) primary; // Suppress unused warning - +void ThresholdGesture::release([[maybe_unused]] bool primary) { this->_executed = false; } @@ -59,9 +66,29 @@ void ThresholdGesture::move(int16_t axis) { } bool ThresholdGesture::metThreshold() const { + std::shared_lock lock(_config_mutex); return _axis >= _config.threshold.value_or(defaults::gesture_threshold); } bool ThresholdGesture::wheelCompatibility() const { return false; -} \ No newline at end of file +} + +int ThresholdGesture::getThreshold() const { + std::shared_lock lock(_config_mutex); + return _config.threshold.value_or(0); +} + +void ThresholdGesture::setThreshold(int threshold) { + std::unique_lock lock(_config_mutex); + if (threshold == 0) + _config.threshold.reset(); + else + _config.threshold = threshold; +} + +void ThresholdGesture::setAction(const std::string& type) { + std::unique_lock lock(_config_mutex); + _action.reset(); + _action = Action::makeAction(_device, type, _config.action, _node); +} diff --git a/src/logid/actions/gesture/ThresholdGesture.h b/src/logid/actions/gesture/ThresholdGesture.h index 3cad303..d401c6a 100644 --- a/src/logid/actions/gesture/ThresholdGesture.h +++ b/src/logid/actions/gesture/ThresholdGesture.h @@ -38,6 +38,12 @@ namespace logid::actions { [[nodiscard]] bool wheelCompatibility() const final; + [[nodiscard]] int getThreshold() const; + + void setThreshold(int threshold); + + void setAction(const std::string& type); + protected: int32_t _axis{}; std::shared_ptr _action; diff --git a/src/logid/features/RemapButton.cpp b/src/logid/features/RemapButton.cpp index c7ba176..be898f5 100644 --- a/src/logid/features/RemapButton.cpp +++ b/src/logid/features/RemapButton.cpp @@ -128,13 +128,10 @@ void RemapButton::listen() { report)); break; case hidpp20::ReprogControls::DivertedRawXYEvent: { - auto divertedXY = _reprog_controls->divertedRawXYEvent( - report); + auto divertedXY = _reprog_controls->divertedRawXYEvent(report); for (const auto& button: this->_buttons) if (button.second->pressed()) - button.second->move( - divertedXY.x, - divertedXY.y); + button.second->move(divertedXY.x, divertedXY.y); break; } default: