Make gesture constructor require fewer arguments
This commit is contained in:
parent
5a913552b1
commit
00298c00ab
|
@ -13,6 +13,21 @@
|
||||||
|
|
||||||
using namespace logid;
|
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)
|
NoAction* NoAction::copy(Device *dev)
|
||||||
{
|
{
|
||||||
auto action = new NoAction();
|
auto action = new NoAction();
|
||||||
|
@ -74,6 +89,9 @@ void KeyAction::release()
|
||||||
|
|
||||||
void GestureAction::press()
|
void GestureAction::press()
|
||||||
{
|
{
|
||||||
|
for(auto g : gestures)
|
||||||
|
g.second->per_pixel_mod = 0;
|
||||||
|
|
||||||
held = true;
|
held = true;
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
|
@ -89,7 +107,7 @@ void GestureAction::move(HIDPP20::IReprogControlsV4::Move m)
|
||||||
if(g != gestures.end())
|
if(g != gestures.end())
|
||||||
{
|
{
|
||||||
if (g->second->mode == GestureMode::Axis)
|
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)
|
if (g->second->mode == GestureMode::OnFewPixels)
|
||||||
{
|
{
|
||||||
g->second->per_pixel_mod += abs(m.y);
|
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 != gestures.end())
|
||||||
{
|
{
|
||||||
if (g->second->mode == GestureMode::Axis)
|
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)
|
if (g->second->mode == GestureMode::OnFewPixels)
|
||||||
{
|
{
|
||||||
g->second->per_pixel_mod += abs(m.x);
|
g->second->per_pixel_mod += abs(m.x);
|
||||||
|
|
|
@ -72,12 +72,15 @@ namespace logid
|
||||||
class Gesture
|
class Gesture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Gesture(ButtonAction* ba, GestureMode m, int pp=0, uint a=0, float am=1)
|
struct axis_info {
|
||||||
: action (ba), mode (m), per_pixel (pp), axis (a), axis_multiplier (am)
|
uint code;
|
||||||
{
|
float multiplier;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
Gesture(ButtonAction* ba, GestureMode m, void* aux=nullptr);
|
||||||
Gesture(const Gesture &g, Device* dev)
|
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;
|
GestureMode mode;
|
||||||
int per_pixel;
|
int per_pixel;
|
||||||
int per_pixel_mod;
|
int per_pixel_mod;
|
||||||
uint axis;
|
axis_info axis;
|
||||||
float axis_multiplier;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class GestureAction : public ButtonAction
|
class GestureAction : public ButtonAction
|
||||||
|
|
|
@ -325,13 +325,13 @@ ButtonAction* logid::parse_action(Action type, const Setting* action_config, boo
|
||||||
|
|
||||||
if(mode == GestureMode::Axis)
|
if(mode == GestureMode::Axis)
|
||||||
{
|
{
|
||||||
uint axis;
|
Gesture::axis_info axis;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::string axis_str;
|
std::string axis_str;
|
||||||
if(!gesture_config.lookupValue("axis", axis_str))
|
if(!gesture_config.lookupValue("axis", axis_str))
|
||||||
throw SettingTypeException(gesture_config["axis"]);
|
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)
|
catch(SettingNotFoundException &e)
|
||||||
{
|
{
|
||||||
|
@ -346,15 +346,15 @@ ButtonAction* logid::parse_action(Action type, const Setting* action_config, boo
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float multiplier = 1;
|
axis.multiplier = 1;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(!gesture_config.lookupValue("axis_multiplier", multiplier))
|
if(!gesture_config.lookupValue("axis_multiplier", axis.multiplier))
|
||||||
{
|
{
|
||||||
int im = 1;
|
int im = 1;
|
||||||
if(!gesture_config.lookupValue("axis_multiplier", im))
|
if(!gesture_config.lookupValue("axis_multiplier", im))
|
||||||
throw SettingTypeException(gesture_config["axis_multiplier"]);
|
throw SettingTypeException(gesture_config["axis_multiplier"]);
|
||||||
multiplier = im;
|
axis.multiplier = (float)im;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(SettingNotFoundException &e) { }
|
catch(SettingNotFoundException &e) { }
|
||||||
|
@ -364,7 +364,7 @@ ButtonAction* logid::parse_action(Action type, const Setting* action_config, boo
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
gestures.insert({direction, new Gesture(new NoAction(), GestureMode::Axis, 0, axis, multiplier)});
|
gestures.insert({direction, new Gesture(new NoAction(), GestureMode::Axis, &axis)});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ ButtonAction* logid::parse_action(Action type, const Setting* action_config, boo
|
||||||
int pp;
|
int pp;
|
||||||
if(!gesture_config.lookupValue("pixels", pp))
|
if(!gesture_config.lookupValue("pixels", pp))
|
||||||
throw SettingTypeException(gesture_config["pixels"]);
|
throw SettingTypeException(gesture_config["pixels"]);
|
||||||
gestures.insert({direction, new Gesture(ba, mode, pp)});
|
gestures.insert({direction, new Gesture(ba, mode, &pp)});
|
||||||
}
|
}
|
||||||
catch(SettingNotFoundException &e)
|
catch(SettingNotFoundException &e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user