Fix none gesture not working

Also fixes gestures on MX Master 3S by ignoring the first movement
event. Fixes #366 and #339.
This commit is contained in:
pixl 2023-05-03 18:38:46 -04:00
parent 5547f52cad
commit 5e436a2bdf
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
4 changed files with 31 additions and 18 deletions

View File

@ -92,6 +92,12 @@ GestureAction::GestureAction(Device* dev, config::GestureAction& config,
direction,Gesture::makeGesture( direction,Gesture::makeGesture(
dev, x.second, dev, x.second,
_node->make_child(fromDirection(direction)))); _node->make_child(fromDirection(direction))));
if (direction == None) {
auto& gesture = x.second;
std::visit([](auto&& x) {
x.threshold.emplace(0);
}, gesture);
}
} catch (std::invalid_argument& e) { } catch (std::invalid_argument& e) {
logPrintf(WARN, "%s is not a direction", x.first.c_str()); logPrintf(WARN, "%s is not a direction", x.first.c_str());
} }
@ -122,7 +128,7 @@ void GestureAction::release() {
} }
for (auto& gesture: _gestures) { for (auto& gesture: _gestures) {
if (gesture.first == d) if (gesture.first == d || gesture.first == None)
continue; continue;
if (!threshold_met) { if (!threshold_met) {
if (gesture.second->metThreshold()) { if (gesture.second->metThreshold()) {
@ -130,21 +136,15 @@ void GestureAction::release() {
// secondary one. // secondary one.
threshold_met = true; threshold_met = true;
gesture.second->release(true); gesture.second->release(true);
break;
} }
} else { } else {
gesture.second->release(false); gesture.second->release(false);
} }
} }
if (!threshold_met) { auto none_gesture = _gestures.find(None);
try { if (none_gesture != _gestures.end()) {
auto none = _gestures.at(None); none_gesture->second->release(!threshold_met);
if (none) {
none->press(false);
none->release(false);
}
} catch (std::out_of_range& e) {}
} }
} }
@ -239,15 +239,23 @@ void GestureAction::setGesture(const std::string& direction, const std::string&
auto dir_name = fromDirection(d); auto dir_name = fromDirection(d);
auto& gesture = _config.gestures.value()[dir_name];
_gestures[d].reset(); _gestures[d].reset();
try { try {
_gestures[d] = Gesture::makeGesture( _gestures[d] = Gesture::makeGesture(
_device, type, _config.gestures.value()[dir_name], _device, type, gesture,
_node->make_child(dir_name)); _node->make_child(dir_name));
} catch (InvalidGesture& e) { } catch (InvalidGesture& e) {
_gestures[d] = Gesture::makeGesture( _gestures[d] = Gesture::makeGesture(
_device, _config.gestures.value()[dir_name], _device, gesture,
_node->make_child(dir_name)); _node->make_child(dir_name));
throw std::invalid_argument("Invalid gesture type"); throw std::invalid_argument("Invalid gesture type");
} }
if (d == None) {
std::visit([](auto&& x) {
x.threshold = 0;
}, gesture);
}
} }

View File

@ -47,5 +47,5 @@ bool NullGesture::wheelCompatibility() const {
} }
bool NullGesture::metThreshold() const { bool NullGesture::metThreshold() const {
return _axis > _config.threshold.value_or(defaults::gesture_threshold); return _axis >= _config.threshold.value_or(defaults::gesture_threshold);
} }

View File

@ -220,8 +220,9 @@ void Button::_makeConfig() {
} }
} }
void Button::press() const { void Button::press() {
std::shared_lock lock(_action_lock); std::shared_lock lock(_action_lock);
_first_move = true;
if (_action) if (_action)
_action->press(); _action->press();
} }
@ -232,10 +233,12 @@ void Button::release() const {
_action->release(); _action->release();
} }
void Button::move(int16_t x, int16_t y) const { void Button::move(int16_t x, int16_t y) {
std::shared_lock lock(_action_lock); std::shared_lock lock(_action_lock);
if (_action) if (_action && !_first_move)
_action->move(x, y); _action->move(x, y);
else if (_first_move)
_first_move = false;
} }
bool Button::pressed() const { bool Button::pressed() const {

View File

@ -36,11 +36,11 @@ namespace logid::features {
Info info, int index, Device* device, ConfigFunction conf_func, Info info, int index, Device* device, ConfigFunction conf_func,
const std::shared_ptr<ipcgull::node>& root, config::Button& config); const std::shared_ptr<ipcgull::node>& root, config::Button& config);
void press() const; void press();
void release() const; void release() const;
void move(int16_t x, int16_t y) const; void move(int16_t x, int16_t y);
void setProfile(config::Button& config); void setProfile(config::Button& config);
@ -82,6 +82,8 @@ namespace logid::features {
std::shared_ptr<actions::Action> _action; std::shared_ptr<actions::Action> _action;
const Info _info; const Info _info;
bool _first_move{};
std::weak_ptr<Button> _self; std::weak_ptr<Button> _self;
std::shared_ptr<IPC> _ipc_interface; std::shared_ptr<IPC> _ipc_interface;