Implement additional gesture modes

This commit is contained in:
PixlOne
2019-08-08 18:22:54 -04:00
parent 52f6a667d0
commit 268908e5a7
9 changed files with 249 additions and 50 deletions
+88 -4
View File
@@ -1,17 +1,59 @@
#include <unistd.h>
#include <future>
#include <hidpp20/Error.h>
#include <hidpp/SimpleDispatcher.h>
#include <hidpp20/IAdjustableDPI.h>
#include <hidpp20/ISmartShift.h>
#include <hidpp20/IHiresScroll.h>
#include <cmath>
#include "Actions.h"
#include "util.h"
#include "EvdevDevice.h"
KeyAction::KeyAction(const KeyAction &a, Device* d) : ButtonAction(Action::Keypress)
NoAction* NoAction::copy(Device *dev)
{
device = d;
std::copy(a.keys.begin(), a.keys.end(), std::back_inserter(keys));
auto action = new NoAction();
action->device = dev;
return action;
}
KeyAction* KeyAction::copy(Device *dev)
{
auto action = new KeyAction(keys);
action->device = dev;
return action;
}
GestureAction* GestureAction::copy(Device* dev)
{
auto action = new GestureAction({});
action->device = dev;
for(auto it : gestures)
action->gestures.insert({it.first, new Gesture(*it.second, dev)});
return action;
}
SmartshiftAction* SmartshiftAction::copy(Device* dev)
{
auto action = new SmartshiftAction();
action->device = dev;
return action;
}
HiresScrollAction* HiresScrollAction::copy(Device* dev)
{
auto action = new HiresScrollAction();
action->device = dev;
return action;
}
CycleDPIAction* CycleDPIAction::copy(Device* dev)
{
auto action = new CycleDPIAction(dpis);
action->device = dev;
return action;
}
ChangeDPIAction* ChangeDPIAction::copy(Device* dev)
{
auto action = new ChangeDPIAction(dpi_inc);
action->device = dev;
return action;
}
void KeyAction::press()
@@ -39,12 +81,54 @@ void GestureAction::move(HIDPP20::IReprogControlsV4::Move m)
{
x += m.x;
y += m.y;
if(m.y != 0 && abs(y) > 50)
{
auto g = gestures.find(m.y > 0 ? Direction::Down : Direction::Up);
if(g != gestures.end())
{
if (g->second->mode == GestureMode::Axis)
global_evdev->move_axis(g->second->axis, abs(m.y) * g->second->axis_multiplier);
if (g->second->mode == GestureMode::OnFewPixels)
{
g->second->per_pixel_mod += abs(m.y);
if(g->second->per_pixel_mod >= g->second->per_pixel)
{
g->second->per_pixel_mod -= g->second->per_pixel;
g->second->action->press();
g->second->action->release();
}
}
}
}
if(m.x != 0 && abs(x) > 50)
{
auto g = gestures.find(m.x > 0 ? Direction::Right : Direction::Left);
if(g != gestures.end())
{
if (g->second->mode == GestureMode::Axis)
global_evdev->move_axis(g->second->axis, abs(m.x) * g->second->axis_multiplier);
if (g->second->mode == GestureMode::OnFewPixels)
{
g->second->per_pixel_mod += abs(m.x);
if (g->second->per_pixel_mod >= g->second->per_pixel)
{
g->second->per_pixel_mod -= g->second->per_pixel;
g->second->action->press();
g->second->action->release();
}
}
}
}
}
void GestureAction::release()
{
held = false;
auto direction = get_direction(x, y);
Direction direction;
if(abs(x) < 50 && abs(y) < 50) direction = Direction::None;
else direction = get_direction(x, y);
x = 0;
y = 0;
auto g = gestures.find(direction);