mirror of
https://github.com/PixlOne/logiops.git
synced 2025-09-14 13:56:50 +08:00
Add gesture IPC interfaces
Also fixes concurrency issues when changing action configs.
This commit is contained in:
parent
0115aaa804
commit
53ce93c6a5
@ -24,6 +24,7 @@
|
||||
#include <utility>
|
||||
#include <ipcgull/node.h>
|
||||
#include <ipcgull/interface.h>
|
||||
#include <shared_mutex>
|
||||
#include "../config/schema.h"
|
||||
|
||||
namespace logid {
|
||||
@ -88,6 +89,7 @@ namespace logid::actions {
|
||||
|
||||
Device* _device;
|
||||
std::atomic<bool> _pressed;
|
||||
mutable std::shared_mutex _config_mutex;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -43,38 +43,21 @@ ChangeDPI::ChangeDPI(
|
||||
_device->hidpp20().deviceIndex());
|
||||
}
|
||||
|
||||
std::tuple<int16_t, uint16_t> 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<int16_t, uint16_t> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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<std::string>(_config.host.value()))
|
||||
return std::get<std::string>(_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<std::string>(_config.host.value())) {
|
||||
const auto& host = std::get<std::string>(_config.host.value());
|
||||
if (host == "next")
|
||||
if (std::holds_alternative<std::string>(host)) {
|
||||
const auto& host_str = std::get<std::string>(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<int>(_config.host.value()) - 1;
|
||||
next_host = std::get<int>(host) - 1;
|
||||
}
|
||||
next_host %= host_info.hostCount;
|
||||
if (next_host != host_info.currentHost)
|
||||
|
@ -49,19 +49,22 @@ CycleDPI::CycleDPI(Device* device, config::CycleDPI& config,
|
||||
}
|
||||
|
||||
std::vector<int> CycleDPI::getDPIs() const {
|
||||
std::shared_lock lock(_config_mutex);
|
||||
auto dpis = _config.dpis.value_or(std::list<int>());
|
||||
return {dpis.begin(), dpis.end()};
|
||||
}
|
||||
|
||||
void CycleDPI::setDPIs(const std::vector<int>& dpis) {
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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())
|
||||
|
@ -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<features::DPI> _dpi;
|
||||
std::list<int>::const_iterator _current_dpi;
|
||||
|
@ -100,7 +100,7 @@ GestureAction::GestureAction(Device* dev, config::GestureAction& config,
|
||||
}
|
||||
|
||||
void GestureAction::press() {
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> lock(_config_lock);
|
||||
void GestureAction::setGesture(const std::string& direction, const std::string& type) {
|
||||
std::unique_lock lock(_config_mutex);
|
||||
|
||||
Direction d = toDirection(direction);
|
||||
|
||||
|
@ -61,7 +61,6 @@ namespace logid::actions {
|
||||
std::shared_ptr<ipcgull::node> _node;
|
||||
std::map<Direction, std::shared_ptr<Gesture>> _gestures;
|
||||
config::GestureAction& _config;
|
||||
mutable std::mutex _config_lock;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -40,14 +40,14 @@ KeypressAction::KeypressAction(
|
||||
}
|
||||
|
||||
void KeypressAction::press() {
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<std::string> KeypressAction::getKeys() const {
|
||||
std::lock_guard<std::mutex> lock(_config_lock);
|
||||
std::shared_lock lock(_config_mutex);
|
||||
std::vector<std::string> ret;
|
||||
for (auto& x: _keys)
|
||||
ret.push_back(InputDevice::toKeyName(x));
|
||||
@ -112,7 +112,7 @@ std::vector<std::string> KeypressAction::getKeys() const {
|
||||
}
|
||||
|
||||
void KeypressAction::setKeys(const std::vector<std::string>& keys) {
|
||||
std::lock_guard<std::mutex> lock(_config_lock);
|
||||
std::unique_lock lock(_config_mutex);
|
||||
if (_pressed)
|
||||
for (auto& key: _keys)
|
||||
_device->virtualInput()->releaseKey(key);
|
||||
|
@ -42,7 +42,6 @@ namespace logid::actions {
|
||||
[[nodiscard]] uint8_t reprogFlags() const final;
|
||||
|
||||
protected:
|
||||
mutable std::mutex _config_lock;
|
||||
config::KeypressAction& _config;
|
||||
std::list<uint> _keys;
|
||||
|
||||
|
@ -26,7 +26,16 @@ const char* AxisGesture::interface_name = "Axis";
|
||||
|
||||
AxisGesture::AxisGesture(Device* device, config::AxisGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& 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<uint>(_config.axis.value())) {
|
||||
_input_axis = std::get<uint>(_config.axis.value());
|
||||
@ -34,7 +43,6 @@ AxisGesture::AxisGesture(Device* device, config::AxisGesture& config,
|
||||
const auto& axis = std::get<std::string>(_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<std::string, double, int> AxisGesture::getConfig() const {
|
||||
std::shared_lock lock(_config_mutex);
|
||||
std::string axis;
|
||||
if (_config.axis.has_value()) {
|
||||
if (std::holds_alternative<std::string>(_config.axis.value())) {
|
||||
axis = std::get<std::string>(_config.axis.value());
|
||||
} else {
|
||||
axis = _device->virtualInput()->toAxisName(std::get<uint>(_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;
|
||||
}
|
||||
|
@ -40,12 +40,21 @@ namespace logid::actions {
|
||||
|
||||
void setHiresMultiplier(double multiplier);
|
||||
|
||||
[[nodiscard]] std::tuple<std::string, double, int> 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<uint> _input_axis;
|
||||
double _multiplier;
|
||||
double _hires_multiplier = 1.0;
|
||||
config::AxisGesture& _config;
|
||||
};
|
||||
}
|
||||
|
@ -64,6 +64,8 @@ namespace logid::actions {
|
||||
std::shared_ptr<ipcgull::node> parent,
|
||||
const std::string& name, tables t = {});
|
||||
|
||||
mutable std::shared_mutex _config_mutex;
|
||||
|
||||
const std::shared_ptr<ipcgull::node> _node;
|
||||
Device* _device;
|
||||
};
|
||||
|
@ -25,7 +25,16 @@ const char* IntervalGesture::interface_name = "OnInterval";
|
||||
IntervalGesture::IntervalGesture(
|
||||
Device* device, config::IntervalGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& 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<int, int> 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);
|
||||
}
|
||||
|
@ -38,25 +38,20 @@ namespace logid::actions {
|
||||
|
||||
[[nodiscard]] bool metThreshold() const final;
|
||||
|
||||
[[nodiscard]] std::tuple<int, int> 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> _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;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -24,12 +24,21 @@ const char* ReleaseGesture::interface_name = "OnRelease";
|
||||
|
||||
ReleaseGesture::ReleaseGesture(Device* device, config::ReleaseGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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> _action;
|
||||
|
@ -25,7 +25,15 @@ const char* ThresholdGesture::interface_name = "OnRelease";
|
||||
ThresholdGesture::ThresholdGesture(
|
||||
Device* device, config::ThresholdGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& 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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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<actions::Action> _action;
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user