parent
295a469505
commit
9272666ffe
13 changed files with 387 additions and 350 deletions
@ -1,141 +1,144 @@ |
||||
#ifndef ACTIONS_H |
||||
#define ACTIONS_H |
||||
#ifndef LOGID_ACTIONS_H |
||||
#define LOGID_ACTIONS_H |
||||
#include "Device.h" |
||||
|
||||
#include <map> |
||||
#include <vector> |
||||
#include <hidpp20/IReprogControls.h> |
||||
|
||||
enum class Action |
||||
namespace logid |
||||
{ |
||||
None, |
||||
Keypress, |
||||
Gestures, |
||||
CycleDPI, |
||||
ChangeDPI, |
||||
ToggleSmartshift, |
||||
ToggleHiresScroll |
||||
}; |
||||
enum class Direction |
||||
{ |
||||
None, |
||||
Up, |
||||
Down, |
||||
Left, |
||||
Right |
||||
}; |
||||
enum class GestureMode |
||||
{ |
||||
NoPress, |
||||
OnRelease, |
||||
OnFewPixels, |
||||
Axis |
||||
}; |
||||
enum class Action |
||||
{ |
||||
None, |
||||
Keypress, |
||||
Gestures, |
||||
CycleDPI, |
||||
ChangeDPI, |
||||
ToggleSmartshift, |
||||
ToggleHiresScroll |
||||
}; |
||||
enum class Direction |
||||
{ |
||||
None, |
||||
Up, |
||||
Down, |
||||
Left, |
||||
Right |
||||
}; |
||||
enum class GestureMode |
||||
{ |
||||
NoPress, |
||||
OnRelease, |
||||
OnFewPixels, |
||||
Axis |
||||
}; |
||||
|
||||
class Device; |
||||
class Device; |
||||
|
||||
class ButtonAction |
||||
{ |
||||
public: |
||||
virtual ~ButtonAction() = default; |
||||
class ButtonAction |
||||
{ |
||||
public: |
||||
virtual ~ButtonAction() = default; |
||||
|
||||
Action type; |
||||
virtual ButtonAction* copy(Device* dev) = 0; |
||||
virtual void press() = 0; |
||||
virtual void release() = 0; |
||||
// ButtonAction(const ButtonAction &a, Device* d) : type (a.type), device (d) {}
|
||||
// ButtonAction* create_instance(Device* d);
|
||||
protected: |
||||
ButtonAction(Action a) : type (a) {}; |
||||
Device* device; |
||||
}; |
||||
class NoAction : public ButtonAction |
||||
{ |
||||
public: |
||||
NoAction() : ButtonAction(Action::None) {} |
||||
virtual NoAction* copy(Device* dev); |
||||
virtual void press() {} |
||||
virtual void release() {} |
||||
}; |
||||
class KeyAction : public ButtonAction |
||||
{ |
||||
public: |
||||
explicit KeyAction(std::vector<unsigned int> k) : ButtonAction(Action::Keypress), keys (std::move(k)) {}; |
||||
virtual KeyAction* copy(Device* dev); |
||||
virtual void press(); |
||||
virtual void release(); |
||||
private: |
||||
std::vector<unsigned int> keys; |
||||
}; |
||||
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) |
||||
Action type; |
||||
virtual ButtonAction* copy(Device* dev) = 0; |
||||
virtual void press() = 0; |
||||
virtual void release() = 0; |
||||
// ButtonAction(const ButtonAction &a, Device* d) : type (a.type), device (d) {}
|
||||
// ButtonAction* create_instance(Device* d);
|
||||
protected: |
||||
ButtonAction(Action a) : type (a) {}; |
||||
Device* device; |
||||
}; |
||||
class NoAction : public ButtonAction |
||||
{ |
||||
public: |
||||
NoAction() : ButtonAction(Action::None) {} |
||||
virtual NoAction* copy(Device* dev); |
||||
virtual void press() {} |
||||
virtual void release() {} |
||||
}; |
||||
class KeyAction : public ButtonAction |
||||
{ |
||||
} |
||||
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) |
||||
public: |
||||
explicit KeyAction(std::vector<unsigned int> k) : ButtonAction(Action::Keypress), keys (std::move(k)) {}; |
||||
virtual KeyAction* copy(Device* dev); |
||||
virtual void press(); |
||||
virtual void release(); |
||||
private: |
||||
std::vector<unsigned int> keys; |
||||
}; |
||||
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) |
||||
{ |
||||
} |
||||
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) |
||||
{ |
||||
} |
||||
|
||||
ButtonAction* action; |
||||
GestureMode mode; |
||||
int per_pixel; |
||||
int per_pixel_mod; |
||||
uint axis; |
||||
float axis_multiplier; |
||||
}; |
||||
ButtonAction* action; |
||||
GestureMode mode; |
||||
int per_pixel; |
||||
int per_pixel_mod; |
||||
uint axis; |
||||
float axis_multiplier; |
||||
}; |
||||
|
||||
class GestureAction : public ButtonAction |
||||
{ |
||||
public: |
||||
GestureAction(std::map<Direction, Gesture*> g) : ButtonAction(Action::Gestures), gestures (std::move(g)) {}; |
||||
std::map<Direction, Gesture*> gestures; |
||||
virtual GestureAction* copy(Device* dev); |
||||
virtual void press(); |
||||
virtual void release(); |
||||
void move(HIDPP20::IReprogControlsV4::Move m); |
||||
private: |
||||
bool held; |
||||
int x = 0; |
||||
int y = 0; |
||||
}; |
||||
class SmartshiftAction : public ButtonAction |
||||
{ |
||||
public: |
||||
SmartshiftAction() : ButtonAction(Action::ToggleSmartshift) {}; |
||||
virtual SmartshiftAction* copy(Device* dev); |
||||
virtual void press(); |
||||
virtual void release() {} |
||||
}; |
||||
class HiresScrollAction : public ButtonAction |
||||
{ |
||||
public: |
||||
HiresScrollAction() : ButtonAction(Action::ToggleHiresScroll) {}; |
||||
virtual HiresScrollAction* copy(Device* dev); |
||||
virtual void press(); |
||||
virtual void release() {} |
||||
}; |
||||
class CycleDPIAction : public ButtonAction |
||||
{ |
||||
public: |
||||
CycleDPIAction(std::vector<int> d) : ButtonAction(Action::CycleDPI), dpis (d) {}; |
||||
virtual CycleDPIAction* copy(Device* dev); |
||||
virtual void press(); |
||||
virtual void release() {} |
||||
private: |
||||
const std::vector<int> dpis; |
||||
}; |
||||
class ChangeDPIAction : public ButtonAction |
||||
{ |
||||
public: |
||||
ChangeDPIAction(int i) : ButtonAction(Action::ChangeDPI), dpi_inc (i) {}; |
||||
virtual ChangeDPIAction* copy(Device* dev); |
||||
virtual void press(); |
||||
virtual void release() {} |
||||
private: |
||||
int dpi_inc; |
||||
}; |
||||
class GestureAction : public ButtonAction |
||||
{ |
||||
public: |
||||
GestureAction(std::map<Direction, Gesture*> g) : ButtonAction(Action::Gestures), gestures (std::move(g)) {}; |
||||
std::map<Direction, Gesture*> gestures; |
||||
virtual GestureAction* copy(Device* dev); |
||||
virtual void press(); |
||||
virtual void release(); |
||||
void move(HIDPP20::IReprogControlsV4::Move m); |
||||
private: |
||||
bool held; |
||||
int x = 0; |
||||
int y = 0; |
||||
}; |
||||
class SmartshiftAction : public ButtonAction |
||||
{ |
||||
public: |
||||
SmartshiftAction() : ButtonAction(Action::ToggleSmartshift) {}; |
||||
virtual SmartshiftAction* copy(Device* dev); |
||||
virtual void press(); |
||||
virtual void release() {} |
||||
}; |
||||
class HiresScrollAction : public ButtonAction |
||||
{ |
||||
public: |
||||
HiresScrollAction() : ButtonAction(Action::ToggleHiresScroll) {}; |
||||
virtual HiresScrollAction* copy(Device* dev); |
||||
virtual void press(); |
||||
virtual void release() {} |
||||
}; |
||||
class CycleDPIAction : public ButtonAction |
||||
{ |
||||
public: |
||||
CycleDPIAction(std::vector<int> d) : ButtonAction(Action::CycleDPI), dpis (d) {}; |
||||
virtual CycleDPIAction* copy(Device* dev); |
||||
virtual void press(); |
||||
virtual void release() {} |
||||
private: |
||||
const std::vector<int> dpis; |
||||
}; |
||||
class ChangeDPIAction : public ButtonAction |
||||
{ |
||||
public: |
||||
ChangeDPIAction(int i) : ButtonAction(Action::ChangeDPI), dpi_inc (i) {}; |
||||
virtual ChangeDPIAction* copy(Device* dev); |
||||
virtual void press(); |
||||
virtual void release() {} |
||||
private: |
||||
int dpi_inc; |
||||
}; |
||||
} |
||||
|
||||
#endif //ACTIONS_H
|
||||
#endif //LOGID_ACTIONS_H
|
||||
|
@ -1,41 +1,44 @@ |
||||
#ifndef CONFIGURATION_H |
||||
#define CONFIGURATION_H |
||||
#ifndef LOGID_CONFIGURATION_H |
||||
#define LOGID_CONFIGURATION_H |
||||
|
||||
#include <map> |
||||
#include <libconfig.h++> |
||||
#include <hidpp20/ISmartShift.h> |
||||
#include "Actions.h" |
||||
|
||||
class DeviceConfig; |
||||
class ButtonAction; |
||||
enum class Action; |
||||
|
||||
class DeviceConfig |
||||
namespace logid |
||||
{ |
||||
public: |
||||
DeviceConfig(); |
||||
~DeviceConfig(); |
||||
DeviceConfig(DeviceConfig* dc, Device* dev); |
||||
DeviceConfig(const libconfig::Setting& root); |
||||
const int* dpi = nullptr; |
||||
HIDPP20::ISmartShift::SmartshiftStatus* smartshift; |
||||
const uint8_t* hiresscroll = nullptr; |
||||
std::map<uint16_t, ButtonAction*> actions; |
||||
const bool baseConfig = true; |
||||
}; |
||||
class DeviceConfig; |
||||
class ButtonAction; |
||||
enum class Action; |
||||
|
||||
class Configuration |
||||
{ |
||||
public: |
||||
Configuration(const char* config_file); |
||||
Configuration() {} |
||||
std::map<std::string, DeviceConfig*> devices; |
||||
private: |
||||
libconfig::Config cfg; |
||||
}; |
||||
class DeviceConfig |
||||
{ |
||||
public: |
||||
DeviceConfig(); |
||||
~DeviceConfig(); |
||||
DeviceConfig(DeviceConfig* dc, Device* dev); |
||||
DeviceConfig(const libconfig::Setting& root); |
||||
const int* dpi = nullptr; |
||||
HIDPP20::ISmartShift::SmartshiftStatus* smartshift; |
||||
const uint8_t* hiresscroll = nullptr; |
||||
std::map<uint16_t, ButtonAction*> actions; |
||||
const bool baseConfig = true; |
||||
}; |
||||
|
||||
class Configuration |
||||
{ |
||||
public: |
||||
Configuration(const char* config_file); |
||||
Configuration() {} |
||||
std::map<std::string, DeviceConfig*> devices; |
||||
private: |
||||
libconfig::Config cfg; |
||||
}; |
||||
|
||||
ButtonAction* parse_action(Action action, const libconfig::Setting* action_config, bool is_gesture=false); |
||||
ButtonAction* parse_action(Action action, const libconfig::Setting* action_config, bool is_gesture=false); |
||||
|
||||
extern Configuration* global_config; |
||||
extern Configuration* global_config; |
||||
} |
||||
|
||||
#endif //CONFIGURATION_H
|
||||
#endif //LOGID_CONFIGURATION_H
|
@ -1,20 +1,27 @@ |
||||
#ifndef EVDEVDEVICE_H |
||||
#define EVDEVDEVICE_H |
||||
#ifndef LOGID_EVDEVDEVICE_H |
||||
#define LOGID_EVDEVDEVICE_H |
||||
|
||||
#include <libevdev/libevdev.h> |
||||
#include <libevdev/libevdev-uinput.h> |
||||
|
||||
class EvdevDevice |
||||
namespace logid |
||||
{ |
||||
public: |
||||
EvdevDevice(const char* name); |
||||
~EvdevDevice(); |
||||
void move_axis(unsigned int axis, int movement); |
||||
void send_event(unsigned int type, unsigned int code, int value); |
||||
libevdev* device; |
||||
libevdev_uinput* ui_device; |
||||
}; |
||||
|
||||
extern EvdevDevice* global_evdev; |
||||
|
||||
#endif //EVDEVDEVICE_H
|
||||
class EvdevDevice |
||||
{ |
||||
public: |
||||
EvdevDevice(const char *name); |
||||
|
||||
~EvdevDevice(); |
||||
|
||||
void move_axis(unsigned int axis, int movement); |
||||
|
||||
void send_event(unsigned int type, unsigned int code, int value); |
||||
|
||||
libevdev *device; |
||||
libevdev_uinput *ui_device; |
||||
}; |
||||
|
||||
extern EvdevDevice* global_evdev; |
||||
} |
||||
|
||||
#endif //LOGID_EVDEVDEVICE_H
|
@ -1,26 +1,29 @@ |
||||
#ifndef UTIL_H |
||||
#define UTIL_H |
||||
#ifndef LOGID_UTIL_H |
||||
#define LOGID_UTIL_H |
||||
|
||||
#include "Actions.h" |
||||
|
||||
enum LogLevel |
||||
namespace logid |
||||
{ |
||||
DEBUG, |
||||
INFO, |
||||
WARN, |
||||
ERROR |
||||
}; |
||||
enum LogLevel |
||||
{ |
||||
DEBUG, |
||||
INFO, |
||||
WARN, |
||||
ERROR |
||||
}; |
||||
|
||||
extern LogLevel global_verbosity; |
||||
extern LogLevel global_verbosity; |
||||
|
||||
void log_printf(LogLevel level, const char* format, ...); |
||||
void log_printf(LogLevel level, const char* format, ...); |
||||
|
||||
const char* level_prefix(LogLevel level); |
||||
const char* level_prefix(LogLevel level); |
||||
|
||||
Direction get_direction(int x, int y); |
||||
Direction string_to_direction(std::string s); |
||||
GestureMode string_to_gesturemode(std::string s); |
||||
Action string_to_action(std::string s); |
||||
LogLevel string_to_loglevel(std::string s); |
||||
Direction get_direction(int x, int y); |
||||
Direction string_to_direction(std::string s); |
||||
GestureMode string_to_gesturemode(std::string s); |
||||
Action string_to_action(std::string s); |
||||
LogLevel string_to_loglevel(std::string s); |
||||
} |
||||
|
||||
#endif //UTIL_H
|
||||
#endif //LOGID_UTIL_H
|
Loading…
Reference in new issue