Make gesture constructor require fewer arguments
This commit is contained in:
parent
5a913552b1
commit
00298c00ab
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user