From 00298c00ab41f4d658935ed5713e1779d0a0b1b5 Mon Sep 17 00:00:00 2001 From: PixlOne <8843371+PixlOne@users.noreply.github.com> Date: Thu, 2 Apr 2020 02:06:52 -0400 Subject: [PATCH] Make gesture constructor require fewer arguments --- src/logid/Actions.cpp | 22 ++++++++++++++++++++-- src/logid/Actions.h | 16 +++++++++------- src/logid/Configuration.cpp | 14 +++++++------- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/logid/Actions.cpp b/src/logid/Actions.cpp index 360d839..747f44c 100644 --- a/src/logid/Actions.cpp +++ b/src/logid/Actions.cpp @@ -13,6 +13,21 @@ using namespace logid; +Gesture::Gesture(ButtonAction* ba, GestureMode m, void* aux) : action (ba), mode (m) +{ + switch(m) + { + case GestureMode::OnFewPixels: + per_pixel = *(int*)aux; + break; + case GestureMode::Axis: + axis = *(axis_info*)aux; + break; + default: + break; + } +} + NoAction* NoAction::copy(Device *dev) { auto action = new NoAction(); @@ -74,6 +89,9 @@ void KeyAction::release() void GestureAction::press() { + for(auto g : gestures) + g.second->per_pixel_mod = 0; + held = true; x = 0; y = 0; @@ -89,7 +107,7 @@ void GestureAction::move(HIDPP20::IReprogControlsV4::Move m) if(g != gestures.end()) { if (g->second->mode == GestureMode::Axis) - global_evdev->moveAxis(g->second->axis, abs(m.y) * g->second->axis_multiplier); + global_evdev->moveAxis(g->second->axis.code, abs(m.y) * g->second->axis.multiplier); if (g->second->mode == GestureMode::OnFewPixels) { g->second->per_pixel_mod += abs(m.y); @@ -108,7 +126,7 @@ void GestureAction::move(HIDPP20::IReprogControlsV4::Move m) if(g != gestures.end()) { if (g->second->mode == GestureMode::Axis) - global_evdev->moveAxis(g->second->axis, abs(m.x) * g->second->axis_multiplier); + global_evdev->moveAxis(g->second->axis.code, abs(m.x) * g->second->axis.multiplier); if (g->second->mode == GestureMode::OnFewPixels) { g->second->per_pixel_mod += abs(m.x); diff --git a/src/logid/Actions.h b/src/logid/Actions.h index 65e0b14..a283e3e 100644 --- a/src/logid/Actions.h +++ b/src/logid/Actions.h @@ -72,12 +72,15 @@ namespace logid class Gesture { public: - Gesture(ButtonAction* ba, GestureMode m, int pp=0, uint a=0, float am=1) - : action (ba), mode (m), per_pixel (pp), axis (a), axis_multiplier (am) - { - } + struct axis_info { + uint code; + float multiplier; + }; + + Gesture(ButtonAction* ba, GestureMode m, void* aux=nullptr); Gesture(const Gesture &g, Device* dev) - : action (g.action->copy(dev)), mode (g.mode), per_pixel (g.per_pixel), axis (g.axis), axis_multiplier (g.axis_multiplier) + : action (g.action->copy(dev)), mode (g.mode), per_pixel (g.per_pixel), + axis (g.axis) { } @@ -85,8 +88,7 @@ namespace logid GestureMode mode; int per_pixel; int per_pixel_mod; - uint axis; - float axis_multiplier; + axis_info axis; }; class GestureAction : public ButtonAction diff --git a/src/logid/Configuration.cpp b/src/logid/Configuration.cpp index e7f8a18..7ee716c 100644 --- a/src/logid/Configuration.cpp +++ b/src/logid/Configuration.cpp @@ -325,13 +325,13 @@ ButtonAction* logid::parse_action(Action type, const Setting* action_config, boo if(mode == GestureMode::Axis) { - uint axis; + Gesture::axis_info axis; try { std::string axis_str; if(!gesture_config.lookupValue("axis", axis_str)) throw SettingTypeException(gesture_config["axis"]); - axis = libevdev_event_code_from_name(EV_REL, axis_str.c_str()); + axis.code = libevdev_event_code_from_name(EV_REL, axis_str.c_str()); } catch(SettingNotFoundException &e) { @@ -346,15 +346,15 @@ ButtonAction* logid::parse_action(Action type, const Setting* action_config, boo continue; } - float multiplier = 1; + axis.multiplier = 1; try { - if(!gesture_config.lookupValue("axis_multiplier", multiplier)) + if(!gesture_config.lookupValue("axis_multiplier", axis.multiplier)) { int im = 1; if(!gesture_config.lookupValue("axis_multiplier", im)) throw SettingTypeException(gesture_config["axis_multiplier"]); - multiplier = im; + axis.multiplier = (float)im; } } catch(SettingNotFoundException &e) { } @@ -364,7 +364,7 @@ ButtonAction* logid::parse_action(Action type, const Setting* action_config, boo continue; } - gestures.insert({direction, new Gesture(new NoAction(), GestureMode::Axis, 0, axis, multiplier)}); + gestures.insert({direction, new Gesture(new NoAction(), GestureMode::Axis, &axis)}); continue; } @@ -406,7 +406,7 @@ ButtonAction* logid::parse_action(Action type, const Setting* action_config, boo int pp; if(!gesture_config.lookupValue("pixels", pp)) throw SettingTypeException(gesture_config["pixels"]); - gestures.insert({direction, new Gesture(ba, mode, pp)}); + gestures.insert({direction, new Gesture(ba, mode, &pp)}); } catch(SettingNotFoundException &e) {