Fix memory error with gesture configs

This commit is contained in:
pixl 2023-04-27 18:39:34 -04:00
parent 9efd121387
commit 6b2207d412
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
3 changed files with 10 additions and 14 deletions

View File

@ -77,8 +77,7 @@ GestureAction::GestureAction(Device* dev, config::GestureAction& config,
Action(dev, interface_name, Action(dev, interface_name,
{ {
{ {
{"SetGesture", {this, &GestureAction::setGesture, {"SetGesture", {this, &GestureAction::setGesture, {"direction", "type"}}}
{"direction", "type"}}}
}, },
{}, {},
{} {}
@ -86,14 +85,13 @@ GestureAction::GestureAction(Device* dev, config::GestureAction& config,
_node(parent->make_child("gestures")), _config(config) { _node(parent->make_child("gestures")), _config(config) {
if (_config.gestures.has_value()) { if (_config.gestures.has_value()) {
auto& gestures = _config.gestures.value(); auto& gestures = _config.gestures.value();
for (auto& x: gestures) { for (auto&& x: gestures) {
try { try {
auto direction = toDirection(x.first); auto direction = toDirection(x.first);
_gestures.emplace(direction, _gestures.emplace(
Gesture::makeGesture( direction,Gesture::makeGesture(
dev, x.second, dev, x.second,
_node->make_child( _node->make_child(fromDirection(direction))));
fromDirection(direction))));
} 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());
} }

View File

@ -50,10 +50,10 @@ namespace {
template<typename T> template<typename T>
std::shared_ptr<Gesture> _makeGesture( std::shared_ptr<Gesture> _makeGesture(
Device* device, T gesture, Device* device, T& gesture,
const std::shared_ptr<ipcgull::node>& parent) { const std::shared_ptr<ipcgull::node>& parent) {
return parent->make_interface<typename gesture_type<T>::type>( return parent->make_interface<typename gesture_type<T>::type>(
device, gesture, parent); device, std::forward<T&>(gesture), parent);
} }
} }

View File

@ -112,11 +112,9 @@ void HiresScroll::_makeAction(std::shared_ptr<actions::Gesture>& gesture,
gesture = actions::Gesture::makeGesture(_device, config.value(), gesture = actions::Gesture::makeGesture(_device, config.value(),
_node->make_child(direction)); _node->make_child(direction));
try { try {
auto axis = std::dynamic_pointer_cast<actions::AxisGesture>( auto axis = std::dynamic_pointer_cast<actions::AxisGesture>(gesture);
gesture);
if (axis) if (axis)
axis->setHiresMultiplier( axis->setHiresMultiplier(_hires_scroll->getCapabilities().multiplier);
_hires_scroll->getCapabilities().multiplier);
} catch (std::bad_cast& e) {} } catch (std::bad_cast& e) {}
if (gesture) if (gesture)
gesture->press(true); gesture->press(true);