From 87fb4371a4d443a68ad7c807c073a7517830ea82 Mon Sep 17 00:00:00 2001 From: pixl Date: Sat, 29 Jan 2022 00:07:22 -0500 Subject: [PATCH] Initial action and gesture ipc interfaces --- src/logid/actions/Action.cpp | 54 ++++++++++--------- src/logid/actions/Action.h | 18 ++++--- src/logid/actions/ChangeDPI.cpp | 11 +++- src/logid/actions/ChangeDPI.h | 13 ++++- src/logid/actions/ChangeHostAction.cpp | 11 +++- src/logid/actions/ChangeHostAction.h | 13 ++++- src/logid/actions/CycleDPI.cpp | 10 +++- src/logid/actions/CycleDPI.h | 13 ++++- src/logid/actions/GestureAction.cpp | 33 +++++++++++- src/logid/actions/GestureAction.h | 15 +++++- src/logid/actions/KeypressAction.cpp | 10 +++- src/logid/actions/KeypressAction.h | 14 ++++- src/logid/actions/NullAction.cpp | 10 +++- src/logid/actions/NullAction.h | 14 +++-- src/logid/actions/ToggleHiresScroll.cpp | 10 +++- src/logid/actions/ToggleHiresScroll.h | 15 ++++-- src/logid/actions/ToggleSmartShift.cpp | 10 +++- src/logid/actions/ToggleSmartShift.h | 16 ++++-- src/logid/actions/gesture/AxisGesture.cpp | 6 ++- src/logid/actions/gesture/AxisGesture.h | 4 +- src/logid/actions/gesture/Gesture.cpp | 24 ++++++--- src/logid/actions/gesture/Gesture.h | 9 +++- src/logid/actions/gesture/IntervalGesture.cpp | 8 +-- src/logid/actions/gesture/IntervalGesture.h | 4 +- src/logid/actions/gesture/NullGesture.cpp | 6 ++- src/logid/actions/gesture/NullGesture.h | 4 +- src/logid/actions/gesture/ReleaseGesture.cpp | 8 +-- src/logid/actions/gesture/ReleaseGesture.h | 4 +- .../actions/gesture/ThresholdGesture.cpp | 8 +-- src/logid/actions/gesture/ThresholdGesture.h | 4 +- src/logid/features/HiresScroll.cpp | 13 +++-- src/logid/features/HiresScroll.h | 5 +- src/logid/features/RemapButton.cpp | 5 +- src/logid/features/ThumbWheel.cpp | 24 +++++---- src/logid/features/ThumbWheel.h | 5 ++ 35 files changed, 330 insertions(+), 101 deletions(-) diff --git a/src/logid/actions/Action.cpp b/src/logid/actions/Action.cpp index 9123994..722b14c 100644 --- a/src/logid/actions/Action.cpp +++ b/src/logid/actions/Action.cpp @@ -42,37 +42,39 @@ template struct action_type : action_type { }; template -std::shared_ptr _makeAction(Device* device, - T action) { - return std::make_shared::type>(device, action); +std::shared_ptr _makeAction( + Device* device, T action, + const std::shared_ptr& parent) { + return std::make_shared::type>(device, action, parent); } template std::shared_ptr _makeAction( Device *device, const std::string &name, - std::optional& config) + std::optional& config, + const std::shared_ptr& parent) { if(name == ChangeDPI::interface_name) { config = config::ChangeDPI(); - return Action::makeAction(device, config.value()); + return Action::makeAction(device, config.value(), parent); } else if(name == ChangeHostAction::interface_name) { config = config::ChangeHost(); - return Action::makeAction(device, config.value()); + return Action::makeAction(device, config.value(), parent); } else if(name == CycleDPI::interface_name) { config = config::CycleDPI(); - return Action::makeAction(device, config.value()); + return Action::makeAction(device, config.value(), parent); } else if(name == KeypressAction::interface_name) { config = config::KeypressAction(); - return Action::makeAction(device, config.value()); + return Action::makeAction(device, config.value(), parent); } else if(name == NullAction::interface_name) { config = config::NoAction(); - return Action::makeAction(device, config.value()); + return Action::makeAction(device, config.value(), parent); } else if(name == ToggleHiresScroll::interface_name) { config = config::ToggleHiresScroll(); - return Action::makeAction(device, config.value()); + return Action::makeAction(device, config.value(), parent); } else if(name == ToggleSmartShift::interface_name) { config = config::ToggleHiresScroll(); - return Action::makeAction(device, config.value()); + return Action::makeAction(device, config.value(), parent); } else if(name == "pizza.pixl.LogiOps.Action.Default") { return nullptr; } @@ -82,42 +84,46 @@ std::shared_ptr _makeAction( std::shared_ptr Action::makeAction( Device *device, const std::string &name, - std::optional &config) + std::optional &config, + const std::shared_ptr& parent) { - return _makeAction(device, name, config); + return _makeAction(device, name, config, parent); } std::shared_ptr Action::makeAction( Device *device, const std::string &name, - std::optional &config) + std::optional &config, + const std::shared_ptr& parent) { try { - return _makeAction(device, name, config); + return _makeAction(device, name, config, parent); } catch(actions::InvalidAction& e) { if(name == GestureAction::interface_name) { config = config::GestureAction(); - return makeAction(device, config.value()); + return makeAction(device, config.value(), parent); } throw; } } -std::shared_ptr Action::makeAction(Device *device, - config::BasicAction& action) +std::shared_ptr Action::makeAction( + Device *device, config::BasicAction& action, + const std::shared_ptr& parent) { std::shared_ptr ret; - std::visit([&device, &ret](auto&& x) { - ret = _makeAction(device, x); + std::visit([&device, &ret, &parent](auto&& x) { + ret = _makeAction(device, x, parent); }, action); return ret; } -std::shared_ptr Action::makeAction(Device *device, - config::Action& action) +std::shared_ptr Action::makeAction( + Device *device, config::Action& action, + const std::shared_ptr& parent) { std::shared_ptr ret; - std::visit([&device, &ret](auto&& x) { - ret = _makeAction(device, x); + std::visit([&device, &ret, &parent](auto&& x) { + ret = _makeAction(device, x, parent); }, action); return ret; } diff --git a/src/logid/actions/Action.h b/src/logid/actions/Action.h index 1132c4b..d670906 100644 --- a/src/logid/actions/Action.h +++ b/src/logid/actions/Action.h @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "../config/schema.h" namespace logid { @@ -48,17 +50,21 @@ namespace actions { public: static std::shared_ptr makeAction( Device* device, const std::string& name, - std::optional& config); + std::optional& config, + const std::shared_ptr& parent); static std::shared_ptr makeAction( Device* device, const std::string& name, - std::optional& config); + std::optional& config, + const std::shared_ptr& parent); - static std::shared_ptr makeAction(Device* device, - config::BasicAction& action); + static std::shared_ptr makeAction( + Device* device, config::BasicAction& action, + const std::shared_ptr& parent); - static std::shared_ptr makeAction(Device* device, - config::Action& action); + static std::shared_ptr makeAction( + Device* device, config::Action& action, + const std::shared_ptr& parent); virtual void press() = 0; virtual void release() = 0; diff --git a/src/logid/actions/ChangeDPI.cpp b/src/logid/actions/ChangeDPI.cpp index 00f8217..78f05d1 100644 --- a/src/logid/actions/ChangeDPI.cpp +++ b/src/logid/actions/ChangeDPI.cpp @@ -27,7 +27,9 @@ using namespace logid::actions; const char* ChangeDPI::interface_name = "pizza.pixl.LogiOps.Action.ChangeDPI"; -ChangeDPI::ChangeDPI(Device *device, config::ChangeDPI& config) : +ChangeDPI::ChangeDPI( + Device *device, config::ChangeDPI& config, + const std::shared_ptr& parent) : Action(device), _config (config) { _dpi = _device->getFeature("dpi"); @@ -36,6 +38,8 @@ ChangeDPI::ChangeDPI(Device *device, config::ChangeDPI& config) : "ChangeDPI action.", _device->hidpp20().devicePath().c_str(), _device->hidpp20().deviceIndex()); + + _ipc = parent->make_interface(this); } void ChangeDPI::press() @@ -71,3 +75,8 @@ uint8_t ChangeDPI::reprogFlags() const { return backend::hidpp20::ReprogControls::TemporaryDiverted; } + +ChangeDPI::IPC::IPC(ChangeDPI *action) : + ipcgull::interface(interface_name, {}, {}, {}), _action (*action) +{ +} diff --git a/src/logid/actions/ChangeDPI.h b/src/logid/actions/ChangeDPI.h index 13b6423..d37dff9 100644 --- a/src/logid/actions/ChangeDPI.h +++ b/src/logid/actions/ChangeDPI.h @@ -29,7 +29,8 @@ namespace logid { public: static const char* interface_name; - explicit ChangeDPI(Device* device, config::ChangeDPI& setting); + ChangeDPI(Device* device, config::ChangeDPI& setting, + const std::shared_ptr& parent); virtual void press(); virtual void release(); @@ -39,6 +40,16 @@ namespace logid { protected: config::ChangeDPI& _config; std::shared_ptr _dpi; + private: + class IPC : public ipcgull::interface + { + public: + IPC(ChangeDPI* action); + private: + ChangeDPI& _action; + }; + + std::shared_ptr _ipc; }; }} diff --git a/src/logid/actions/ChangeHostAction.cpp b/src/logid/actions/ChangeHostAction.cpp index 87359c3..c0fcc5f 100644 --- a/src/logid/actions/ChangeHostAction.cpp +++ b/src/logid/actions/ChangeHostAction.cpp @@ -27,7 +27,9 @@ using namespace logid::backend; const char* ChangeHostAction::interface_name = "pizza.pixl.LogiOps.Action.ChangeHost"; -ChangeHostAction::ChangeHostAction(Device *device, config::ChangeHost& config) +ChangeHostAction::ChangeHostAction( + Device *device, config::ChangeHost& config, + const std::shared_ptr& parent) : Action(device), _config (config) { if(std::holds_alternative(_config.host)) { @@ -42,6 +44,8 @@ ChangeHostAction::ChangeHostAction(Device *device, config::ChangeHost& config) "ChangeHostAction will not work.", device->hidpp20() .devicePath().c_str(), device->hidpp20().deviceIndex()); } + + _ipc = parent->make_interface(this); } void ChangeHostAction::press() @@ -78,3 +82,8 @@ uint8_t ChangeHostAction::reprogFlags() const { return hidpp20::ReprogControls::TemporaryDiverted; } + +ChangeHostAction::IPC::IPC(ChangeHostAction *action) : + ipcgull::interface(interface_name, {}, {}, {}), _action (*action) +{ +} diff --git a/src/logid/actions/ChangeHostAction.h b/src/logid/actions/ChangeHostAction.h index e8a8aca..e5ac8e8 100644 --- a/src/logid/actions/ChangeHostAction.h +++ b/src/logid/actions/ChangeHostAction.h @@ -30,7 +30,8 @@ namespace actions public: static const char* interface_name; - ChangeHostAction(Device* device, config::ChangeHost& config); + ChangeHostAction(Device* device, config::ChangeHost& config, + const std::shared_ptr& parent); virtual void press(); virtual void release(); @@ -40,6 +41,16 @@ namespace actions protected: std::shared_ptr _change_host; config::ChangeHost& _config; + private: + class IPC : public ipcgull::interface + { + public: + IPC(ChangeHostAction* action); + private: + ChangeHostAction& _action; + }; + + std::shared_ptr _ipc; }; }} diff --git a/src/logid/actions/CycleDPI.cpp b/src/logid/actions/CycleDPI.cpp index 5113843..a169447 100644 --- a/src/logid/actions/CycleDPI.cpp +++ b/src/logid/actions/CycleDPI.cpp @@ -28,7 +28,8 @@ using namespace libconfig; const char* CycleDPI::interface_name = "pizza.pixl.LogiOps.Action.CycleDPI"; -CycleDPI::CycleDPI(Device* device, config::CycleDPI& config) : +CycleDPI::CycleDPI(Device* device, config::CycleDPI& config, + const std::shared_ptr& parent) : Action (device), _config (config), _current_dpi (_config.dpis.begin()) { _dpi = _device->getFeature("dpi"); @@ -37,6 +38,8 @@ CycleDPI::CycleDPI(Device* device, config::CycleDPI& config) : "CycleDPI action.", _device->hidpp20().devicePath().c_str(), _device->hidpp20().deviceIndex()); + + _ipc = parent->make_interface(this); } void CycleDPI::press() @@ -73,3 +76,8 @@ uint8_t CycleDPI::reprogFlags() const { return backend::hidpp20::ReprogControls::TemporaryDiverted; } + +CycleDPI::IPC::IPC(CycleDPI *action) : + ipcgull::interface(interface_name, {}, {}, {}), _action (*action) +{ +} diff --git a/src/logid/actions/CycleDPI.h b/src/logid/actions/CycleDPI.h index 1f70d61..d21c3bf 100644 --- a/src/logid/actions/CycleDPI.h +++ b/src/logid/actions/CycleDPI.h @@ -29,7 +29,8 @@ namespace actions { public: static const char* interface_name; - explicit CycleDPI(Device* device, config::CycleDPI& setting); + CycleDPI(Device* device, config::CycleDPI& setting, + const std::shared_ptr& parent); virtual void press(); virtual void release(); @@ -41,6 +42,16 @@ namespace actions { config::CycleDPI& _config; std::shared_ptr _dpi; std::list::const_iterator _current_dpi; + private: + class IPC : public ipcgull::interface + { + public: + IPC(CycleDPI* action); + private: + CycleDPI& _action; + }; + + std::shared_ptr _ipc; }; }} diff --git a/src/logid/actions/GestureAction.cpp b/src/logid/actions/GestureAction.cpp index 569f6a3..d654d22 100644 --- a/src/logid/actions/GestureAction.cpp +++ b/src/logid/actions/GestureAction.cpp @@ -45,6 +45,25 @@ GestureAction::Direction GestureAction::toDirection(std::string direction) throw std::invalid_argument("direction"); } +std::string GestureAction::fromDirection(Direction direction) +{ + switch(direction) { + case Up: + return "up"; + case Down: + return "down"; + case Left: + return "left"; + case Right: + return "right"; + case None: + return "none"; + } + + // This shouldn't happen + throw InvalidGesture(); +} + GestureAction::Direction GestureAction::toDirection(int16_t x, int16_t y) { if(x >= 0 && y >= 0) @@ -57,7 +76,8 @@ GestureAction::Direction GestureAction::toDirection(int16_t x, int16_t y) return x <= -y ? Up : Right; } -GestureAction::GestureAction(Device* dev, config::GestureAction& config) : +GestureAction::GestureAction(Device* dev, config::GestureAction& config, + const std::shared_ptr& parent) : Action (dev), _config (config) { if(_config.gestures.has_value()) { @@ -66,12 +86,16 @@ GestureAction::GestureAction(Device* dev, config::GestureAction& config) : try { auto direction = toDirection(x.first); _gestures.emplace(direction, - Gesture::makeGesture(dev, x.second)); + Gesture::makeGesture( + dev, x.second, parent, + fromDirection(direction))); } catch(std::invalid_argument& e) { logPrintf(WARN, "%s is not a direction", x.first.c_str()); } } } + + _ipc = parent->make_interface(this); } void GestureAction::press() @@ -193,3 +217,8 @@ uint8_t GestureAction::reprogFlags() const return (hidpp20::ReprogControls::TemporaryDiverted | hidpp20::ReprogControls::RawXYDiverted); } + +GestureAction::IPC::IPC(GestureAction *action) : + ipcgull::interface(interface_name, {}, {}, {}), _action (*action) +{ +} diff --git a/src/logid/actions/GestureAction.h b/src/logid/actions/GestureAction.h index cde4588..a66c732 100644 --- a/src/logid/actions/GestureAction.h +++ b/src/logid/actions/GestureAction.h @@ -39,9 +39,11 @@ namespace actions { Right }; static Direction toDirection(std::string direction); + static std::string fromDirection(Direction direction); static Direction toDirection(int16_t x, int16_t y); - GestureAction(Device* dev, config::GestureAction& config); + GestureAction(Device* dev, config::GestureAction& config, + const std::shared_ptr& parent); virtual void press(); virtual void release(); @@ -53,6 +55,17 @@ namespace actions { int16_t _x, _y; std::map> _gestures; config::GestureAction& _config; + + private: + class IPC : public ipcgull::interface + { + public: + explicit IPC(GestureAction* action); + private: + GestureAction& _action; + }; + + std::shared_ptr _ipc; }; }} diff --git a/src/logid/actions/KeypressAction.cpp b/src/logid/actions/KeypressAction.cpp index c2db8c2..ff6afac 100644 --- a/src/logid/actions/KeypressAction.cpp +++ b/src/logid/actions/KeypressAction.cpp @@ -27,7 +27,8 @@ using namespace logid::backend; const char* KeypressAction::interface_name = "pizza.pixl.LogiOps.Action.Keypress"; -KeypressAction::KeypressAction(Device *device, config::KeypressAction& config) : +KeypressAction::KeypressAction(Device *device, config::KeypressAction& config, + const std::shared_ptr& parent) : Action(device), _config (config) { if(std::holds_alternative(_config.keys)) { @@ -65,6 +66,8 @@ KeypressAction::KeypressAction(Device *device, config::KeypressAction& config) : } } } + + _ipc = parent->make_interface(this); } void KeypressAction::press() @@ -85,3 +88,8 @@ uint8_t KeypressAction::reprogFlags() const { return hidpp20::ReprogControls::TemporaryDiverted; } + +KeypressAction::IPC::IPC(KeypressAction *action) : ipcgull::interface( + interface_name, {}, {}, {}), _action (*action) +{ +} diff --git a/src/logid/actions/KeypressAction.h b/src/logid/actions/KeypressAction.h index 0d961b1..8cde45d 100644 --- a/src/logid/actions/KeypressAction.h +++ b/src/logid/actions/KeypressAction.h @@ -29,7 +29,9 @@ namespace actions { public: static const char* interface_name; - KeypressAction(Device* dev, config::KeypressAction& config); + KeypressAction(Device* dev, + config::KeypressAction& config, + const std::shared_ptr& parent); virtual void press(); virtual void release(); @@ -38,6 +40,16 @@ namespace actions { protected: config::KeypressAction& _config; std::list _keys; + private: + class IPC : public ipcgull::interface + { + public: + explicit IPC(KeypressAction* action); + private: + KeypressAction& _action; + }; + + std::shared_ptr _ipc; }; }} diff --git a/src/logid/actions/NullAction.cpp b/src/logid/actions/NullAction.cpp index cdb6972..d81d60e 100644 --- a/src/logid/actions/NullAction.cpp +++ b/src/logid/actions/NullAction.cpp @@ -24,7 +24,9 @@ using namespace logid::actions; const char* NullAction::interface_name = "pizza.pixl.LogiOps.Action.None"; -NullAction::NullAction(Device* device) : Action(device) +NullAction::NullAction(Device* device, + const std::shared_ptr& parent) : + Action(device), _ipc (parent->make_interface()) { } @@ -41,4 +43,8 @@ void NullAction::release() uint8_t NullAction::reprogFlags() const { return backend::hidpp20::ReprogControls::TemporaryDiverted; -} \ No newline at end of file +} + +NullAction::IPC::IPC() : ipcgull::interface(interface_name, {}, {}, {}) +{ +} diff --git a/src/logid/actions/NullAction.h b/src/logid/actions/NullAction.h index ef483a1..dd95f83 100644 --- a/src/logid/actions/NullAction.h +++ b/src/logid/actions/NullAction.h @@ -28,14 +28,22 @@ namespace actions public: static const char* interface_name; - explicit NullAction(Device* device); - NullAction(Device* device, [[maybe_unused]] config::NoAction& config) : - NullAction(device) { } + NullAction(Device* device, + const std::shared_ptr& parent); + NullAction(Device* device, [[maybe_unused]] config::NoAction& config, + const std::shared_ptr& parent) : + NullAction(device, parent) { } virtual void press(); virtual void release(); virtual uint8_t reprogFlags() const; + private: + class IPC : public ipcgull::interface { + public: + IPC(); + }; + std::shared_ptr _ipc; }; }} diff --git a/src/logid/actions/ToggleHiresScroll.cpp b/src/logid/actions/ToggleHiresScroll.cpp index 7ada225..40dfd0c 100644 --- a/src/logid/actions/ToggleHiresScroll.cpp +++ b/src/logid/actions/ToggleHiresScroll.cpp @@ -26,7 +26,9 @@ using namespace logid::backend; const char* ToggleHiresScroll::interface_name = "pizza.pixl.LogiOps.Action.ToggleHiresScroll"; -ToggleHiresScroll::ToggleHiresScroll(Device *dev) : Action (dev) +ToggleHiresScroll::ToggleHiresScroll( + Device *dev, const std::shared_ptr& parent) : + Action (dev), _ipc (parent->make_interface()) { _hires_scroll = _device->getFeature("hiresscroll"); if(!_hires_scroll) @@ -58,4 +60,8 @@ void ToggleHiresScroll::release() uint8_t ToggleHiresScroll::reprogFlags() const { return hidpp20::ReprogControls::TemporaryDiverted; -} \ No newline at end of file +} + +ToggleHiresScroll::IPC::IPC() : ipcgull::interface(interface_name, {}, {}, {}) +{ +} diff --git a/src/logid/actions/ToggleHiresScroll.h b/src/logid/actions/ToggleHiresScroll.h index 3dec044..2c1f3b1 100644 --- a/src/logid/actions/ToggleHiresScroll.h +++ b/src/logid/actions/ToggleHiresScroll.h @@ -29,10 +29,11 @@ namespace actions public: static const char* interface_name; - explicit ToggleHiresScroll(Device* dev); + ToggleHiresScroll(Device* dev, const std::shared_ptr& parent); ToggleHiresScroll(Device* device, - [[maybe_unused]] config::ToggleHiresScroll& action) : - ToggleHiresScroll(device) { } + [[maybe_unused]] config::ToggleHiresScroll& action, + const std::shared_ptr& parent) : + ToggleHiresScroll(device, parent) { } virtual void press(); virtual void release(); @@ -40,6 +41,14 @@ namespace actions virtual uint8_t reprogFlags() const; protected: std::shared_ptr _hires_scroll; + private: + class IPC : public ipcgull::interface + { + public: + IPC(); + }; + + std::shared_ptr _ipc; }; }} diff --git a/src/logid/actions/ToggleSmartShift.cpp b/src/logid/actions/ToggleSmartShift.cpp index 407ec7f..6767138 100644 --- a/src/logid/actions/ToggleSmartShift.cpp +++ b/src/logid/actions/ToggleSmartShift.cpp @@ -26,7 +26,9 @@ using namespace logid::backend; const char* ToggleSmartShift::interface_name = "pizza.pixl.LogiOps.Action.ToggleSmartShift"; -ToggleSmartShift::ToggleSmartShift(Device *dev) : Action (dev) +ToggleSmartShift::ToggleSmartShift( + Device *dev, const std::shared_ptr& parent) : + Action (dev), _ipc (parent->make_interface()) { _smartshift = _device->getFeature("smartshift"); if(!_smartshift) @@ -58,4 +60,8 @@ void ToggleSmartShift::release() uint8_t ToggleSmartShift::reprogFlags() const { return hidpp20::ReprogControls::TemporaryDiverted; -} \ No newline at end of file +} + +ToggleSmartShift::IPC::IPC() : ipcgull::interface(interface_name, {}, {}, {}) +{ +} diff --git a/src/logid/actions/ToggleSmartShift.h b/src/logid/actions/ToggleSmartShift.h index 8913ec6..7013c50 100644 --- a/src/logid/actions/ToggleSmartShift.h +++ b/src/logid/actions/ToggleSmartShift.h @@ -29,10 +29,12 @@ namespace actions { public: static const char* interface_name; - explicit ToggleSmartShift(Device* dev); + ToggleSmartShift(Device* dev, + const std::shared_ptr& parent); ToggleSmartShift(Device* device, - [[maybe_unused]] config::ToggleSmartShift& action) : - ToggleSmartShift(device) { } + [[maybe_unused]] config::ToggleSmartShift& action, + const std::shared_ptr& parent) : + ToggleSmartShift(device, parent) { } virtual void press(); virtual void release(); @@ -40,6 +42,14 @@ namespace actions { virtual uint8_t reprogFlags() const; protected: std::shared_ptr _smartshift; + private: + class IPC : public ipcgull::interface + { + public: + IPC(); + }; + + std::shared_ptr _ipc; }; }} diff --git a/src/logid/actions/gesture/AxisGesture.cpp b/src/logid/actions/gesture/AxisGesture.cpp index 248fa0c..9d8bd43 100644 --- a/src/logid/actions/gesture/AxisGesture.cpp +++ b/src/logid/actions/gesture/AxisGesture.cpp @@ -23,8 +23,10 @@ using namespace logid::actions; -AxisGesture::AxisGesture(Device *device, config::AxisGesture& config) : - Gesture (device), _multiplier (1), _config (config) +AxisGesture::AxisGesture(Device *device, config::AxisGesture& config, + const std::shared_ptr& parent, + const std::string& direction) : + Gesture (device, parent, direction), _multiplier (1), _config (config) { if(std::holds_alternative(_config.axis)) { _input_axis = std::get(_config.axis); diff --git a/src/logid/actions/gesture/AxisGesture.h b/src/logid/actions/gesture/AxisGesture.h index eaf42e6..491c201 100644 --- a/src/logid/actions/gesture/AxisGesture.h +++ b/src/logid/actions/gesture/AxisGesture.h @@ -26,7 +26,9 @@ namespace logid { class AxisGesture : public Gesture { public: - AxisGesture(Device* device, config::AxisGesture& config); + AxisGesture(Device* device, config::AxisGesture& config, + const std::shared_ptr& parent, + const std::string& direction); virtual void press(bool init_threshold=false); virtual void release(bool primary=false); diff --git a/src/logid/actions/gesture/Gesture.cpp b/src/logid/actions/gesture/Gesture.cpp index 55982ef..9bc9dc2 100644 --- a/src/logid/actions/gesture/Gesture.cpp +++ b/src/logid/actions/gesture/Gesture.cpp @@ -27,7 +27,10 @@ using namespace logid; using namespace logid::actions; -Gesture::Gesture(Device *device) : _device (device) +Gesture::Gesture(Device *device, + const std::shared_ptr& parent, + const std::string& direction) : _device (device), + _node (parent->make_child(direction)) { } @@ -43,17 +46,22 @@ template struct gesture_type : gesture_type { }; template -std::shared_ptr _makeGesture(Device* device, - T gesture) { - return std::make_shared::type>(device, gesture); +std::shared_ptr _makeGesture( + Device* device, T gesture, + const std::shared_ptr& parent, + const std::string& direction) { + return std::make_shared::type>( + device, gesture, parent, std::move(direction)); } -std::shared_ptr Gesture::makeGesture(Device *device, - config::Gesture& gesture) +std::shared_ptr Gesture::makeGesture( + Device *device, config::Gesture& gesture, + const std::shared_ptr& parent, + const std::string& direction) { std::shared_ptr ret; - std::visit([&device, &ret](auto&& x) { - ret = _makeGesture(device, x); + std::visit([&device, &ret, &parent, &direction](auto&& x) { + ret = _makeGesture(device, x, parent, direction); }, gesture); return ret; } diff --git a/src/logid/actions/gesture/Gesture.h b/src/logid/actions/gesture/Gesture.h index 58c39d5..6fc8816 100644 --- a/src/logid/actions/gesture/Gesture.h +++ b/src/logid/actions/gesture/Gesture.h @@ -52,11 +52,16 @@ namespace actions virtual ~Gesture() = default; static std::shared_ptr makeGesture(Device* device, - config::Gesture& gesture); + config::Gesture& gesture, + const std::shared_ptr& parent, + const std::string& direction); protected: - explicit Gesture(Device* device); + explicit Gesture(Device* device, + const std::shared_ptr& parent, + const std::string& direction); Device* _device; + std::shared_ptr _node; }; }} diff --git a/src/logid/actions/gesture/IntervalGesture.cpp b/src/logid/actions/gesture/IntervalGesture.cpp index 6f9988a..0acca9c 100644 --- a/src/logid/actions/gesture/IntervalGesture.cpp +++ b/src/logid/actions/gesture/IntervalGesture.cpp @@ -21,12 +21,14 @@ using namespace logid::actions; -IntervalGesture::IntervalGesture(Device *device, config::IntervalGesture& config) : - Gesture (device), _config (config) +IntervalGesture::IntervalGesture(Device *device, config::IntervalGesture& config, + const std::shared_ptr& parent, + const std::string& direction) : + Gesture (device, parent, direction), _config (config) { if(config.action) { try { - _action = Action::makeAction(device, config.action.value()); + _action = Action::makeAction(device, config.action.value(), _node); } catch(InvalidAction& e) { logPrintf(WARN, "Mapping gesture to invalid action"); } diff --git a/src/logid/actions/gesture/IntervalGesture.h b/src/logid/actions/gesture/IntervalGesture.h index cb68cd2..5ee4ecd 100644 --- a/src/logid/actions/gesture/IntervalGesture.h +++ b/src/logid/actions/gesture/IntervalGesture.h @@ -26,7 +26,9 @@ namespace actions class IntervalGesture : public Gesture { public: - IntervalGesture(Device* device, config::IntervalGesture& config); + IntervalGesture(Device* device, config::IntervalGesture& config, + const std::shared_ptr& parent, + const std::string& direction); virtual void press(bool init_threshold=false); virtual void release(bool primary=false); diff --git a/src/logid/actions/gesture/NullGesture.cpp b/src/logid/actions/gesture/NullGesture.cpp index 515746f..2b2c6ea 100644 --- a/src/logid/actions/gesture/NullGesture.cpp +++ b/src/logid/actions/gesture/NullGesture.cpp @@ -21,8 +21,10 @@ using namespace logid::actions; NullGesture::NullGesture(Device *device, - config::NoGesture& config) : - Gesture (device), _config (config) + config::NoGesture& config, + const std::shared_ptr& parent, + const std::string& direction) : + Gesture (device, parent, direction), _config (config) { } diff --git a/src/logid/actions/gesture/NullGesture.h b/src/logid/actions/gesture/NullGesture.h index 89b0158..9f08bab 100644 --- a/src/logid/actions/gesture/NullGesture.h +++ b/src/logid/actions/gesture/NullGesture.h @@ -27,7 +27,9 @@ namespace actions { public: NullGesture(Device* device, - config::NoGesture& config); + config::NoGesture& config, + const std::shared_ptr& parent, + const std::string& direction); virtual void press(bool init_threshold=false); virtual void release(bool primary=false); diff --git a/src/logid/actions/gesture/ReleaseGesture.cpp b/src/logid/actions/gesture/ReleaseGesture.cpp index e09989b..ca663c1 100644 --- a/src/logid/actions/gesture/ReleaseGesture.cpp +++ b/src/logid/actions/gesture/ReleaseGesture.cpp @@ -20,11 +20,13 @@ using namespace logid::actions; -ReleaseGesture::ReleaseGesture(Device *device, config::ReleaseGesture& config) : - Gesture (device), _config (config) +ReleaseGesture::ReleaseGesture(Device *device, config::ReleaseGesture& config, + const std::shared_ptr& parent, + const std::string& direction) : + Gesture (device, parent, direction), _config (config) { if(_config.action.has_value()) - _action = Action::makeAction(device, _config.action.value()); + _action = Action::makeAction(device, _config.action.value(), _node); } void ReleaseGesture::press(bool init_threshold) diff --git a/src/logid/actions/gesture/ReleaseGesture.h b/src/logid/actions/gesture/ReleaseGesture.h index 24166a7..f02c566 100644 --- a/src/logid/actions/gesture/ReleaseGesture.h +++ b/src/logid/actions/gesture/ReleaseGesture.h @@ -26,7 +26,9 @@ namespace actions class ReleaseGesture : public Gesture { public: - ReleaseGesture(Device* device, config::ReleaseGesture& config); + ReleaseGesture(Device* device, config::ReleaseGesture& config, + const std::shared_ptr& parent, + const std::string& direction); virtual void press(bool init_threshold=false); virtual void release(bool primary=false); diff --git a/src/logid/actions/gesture/ThresholdGesture.cpp b/src/logid/actions/gesture/ThresholdGesture.cpp index ccae5a9..3e79dd8 100644 --- a/src/logid/actions/gesture/ThresholdGesture.cpp +++ b/src/logid/actions/gesture/ThresholdGesture.cpp @@ -21,12 +21,14 @@ using namespace logid::actions; ThresholdGesture::ThresholdGesture(Device *device, - config::ThresholdGesture& config) : - Gesture (device), _config (config) + config::ThresholdGesture& config, + const std::shared_ptr& parent, + const std::string& direction) : + Gesture (device, parent, direction), _config (config) { if(config.action) { try { - _action = Action::makeAction(device, config.action.value()); + _action = Action::makeAction(device, config.action.value(), _node); } catch(InvalidAction& e) { logPrintf(WARN, "Mapping gesture to invalid action"); } diff --git a/src/logid/actions/gesture/ThresholdGesture.h b/src/logid/actions/gesture/ThresholdGesture.h index 501117d..802cbb5 100644 --- a/src/logid/actions/gesture/ThresholdGesture.h +++ b/src/logid/actions/gesture/ThresholdGesture.h @@ -26,7 +26,9 @@ namespace actions class ThresholdGesture : public Gesture { public: - ThresholdGesture(Device* device, config::ThresholdGesture& config); + ThresholdGesture(Device* device, config::ThresholdGesture& config, + const std::shared_ptr& parent, + const std::string& direction); virtual void press(bool init_threshold=false); virtual void release(bool primary=false); diff --git a/src/logid/features/HiresScroll.cpp b/src/logid/features/HiresScroll.cpp index b52b950..15f2cae 100644 --- a/src/logid/features/HiresScroll.cpp +++ b/src/logid/features/HiresScroll.cpp @@ -26,7 +26,8 @@ using namespace logid::backend; #define MOVE_EVENTHANDLER_NAME "HIRES_SCROLL" HiresScroll::HiresScroll(Device *dev) : DeviceFeature(dev), - _config (dev->activeProfile().hiresscroll), _mode (0), _mask (0) + _config (dev->activeProfile().hiresscroll), _mode (0), _mask (0), + _node (dev->ipcNode()->make_child("hires")) { if(_config.has_value()) { if(std::holds_alternative(_config.value())) { @@ -54,8 +55,8 @@ HiresScroll::HiresScroll(Device *dev) : DeviceFeature(dev), _mode |= hidpp20::HiresScroll::Mode::Target; } - _makeAction(_up_action, conf.up); - _makeAction(_down_action, conf.down); + _makeAction(_up_action, conf.up, "up"); + _makeAction(_down_action, conf.down, "down"); } try { @@ -110,10 +111,12 @@ void HiresScroll::setMode(uint8_t mode) } void HiresScroll::_makeAction(std::shared_ptr &gesture, - std::optional &config) + std::optional &config, + const std::string& direction) { if(config.has_value()) { - gesture = actions::Gesture::makeGesture(_device, config.value()); + gesture = actions::Gesture::makeGesture(_device, config.value(), + _node, direction); try { auto axis = std::dynamic_pointer_cast( gesture); diff --git a/src/logid/features/HiresScroll.h b/src/logid/features/HiresScroll.h index 1f74825..0ebdc4d 100644 --- a/src/logid/features/HiresScroll.h +++ b/src/logid/features/HiresScroll.h @@ -37,7 +37,8 @@ namespace features void setMode(uint8_t mode); private: void _makeAction(std::shared_ptr& gesture, - std::optional& config); + std::optional& config, + const std::string& direction); void _handleScroll(backend::hidpp20::HiresScroll::WheelStatus event); std::shared_ptr _hires_scroll; @@ -51,6 +52,8 @@ namespace features std::shared_ptr _up_action; std::shared_ptr _down_action; + + std::shared_ptr _node; }; }} diff --git a/src/logid/features/RemapButton.cpp b/src/logid/features/RemapButton.cpp index 647e127..b485ac8 100644 --- a/src/logid/features/RemapButton.cpp +++ b/src/logid/features/RemapButton.cpp @@ -168,19 +168,20 @@ Button::Button(Info info, int index, std::shared_ptr root, config::Button &config) : _node (root->make_child(std::to_string(index))), - _interface (_node->make_interface(this, info)), _device (device), _conf_func (std::move(conf_func)), _config (config), _info (info) { if(_config.action.has_value()) { try { - _action = Action::makeAction(_device, _config.action.value()); + _action = Action::makeAction(_device, _config.action.value(), _node); } catch(std::exception& e) { logPrintf(WARN, "Error creating button action: %s", e.what()); } } + + _interface = _node->make_interface(this, _info); } void Button::press() const { diff --git a/src/logid/features/ThumbWheel.cpp b/src/logid/features/ThumbWheel.cpp index 458de92..f2d81d0 100644 --- a/src/logid/features/ThumbWheel.cpp +++ b/src/logid/features/ThumbWheel.cpp @@ -30,11 +30,12 @@ using namespace logid; #define SCROLL_EVENTHANDLER_NAME "THUMB_WHEEL" std::shared_ptr _genAction( - Device* dev, std::optional& conf) + Device* dev, std::optional& conf, + const std::shared_ptr& parent) { if(conf.has_value()) { try { - return actions::Action::makeAction(dev, conf.value()); + return actions::Action::makeAction(dev, conf.value(), parent); } catch(actions::InvalidAction& e) { logPrintf(WARN, "Mapping thumb wheel to invalid action"); } @@ -44,11 +45,12 @@ std::shared_ptr _genAction( } std::shared_ptr _genGesture( - Device* dev, std::optional& conf) + Device* dev, std::optional& conf, + const std::shared_ptr& parent, const std::string& direction) { if(conf.has_value()) { try { - return actions::Gesture::makeGesture(dev, conf.value()); + return actions::Gesture::makeGesture(dev, conf.value(), parent, direction); } catch (actions::InvalidAction &e) { logPrintf(WARN, "Mapping thumb wheel to invalid gesture"); } @@ -58,15 +60,19 @@ std::shared_ptr _genGesture( } ThumbWheel::ThumbWheel(Device *dev) : DeviceFeature(dev), _wheel_info(), + _node (dev->ipcNode()->make_child("thumbwheel")), + _proxy_node (_node->make_child("proxy")), + _tap_node (_node->make_child("tap")), + _touch_node (_node->make_child("touch")), _config (dev->activeProfile().thumbwheel) { if(_config.has_value()) { auto& conf = _config.value(); - _left_action = _genGesture(dev, conf.left); - _right_action = _genGesture(dev, conf.right); - _touch_action = _genAction(dev, conf.touch); - _tap_action = _genAction(dev, conf.tap); - _proxy_action = _genAction(dev, conf.proxy); + _left_action = _genGesture(dev, conf.left, _node, "left"); + _right_action = _genGesture(dev, conf.right, _node, "right"); + _touch_action = _genAction(dev, conf.touch, _touch_node); + _tap_action = _genAction(dev, conf.tap, _tap_node); + _proxy_action = _genAction(dev, conf.proxy, _proxy_node); } try { diff --git a/src/logid/features/ThumbWheel.h b/src/logid/features/ThumbWheel.h index f76fd33..a71f8ef 100644 --- a/src/logid/features/ThumbWheel.h +++ b/src/logid/features/ThumbWheel.h @@ -40,11 +40,16 @@ namespace features std::shared_ptr _thumb_wheel; backend::hidpp20::ThumbWheel::ThumbwheelInfo _wheel_info; + std::shared_ptr _node; + std::shared_ptr _left_action; std::shared_ptr _right_action; std::shared_ptr _proxy_action; + std::shared_ptr _proxy_node; std::shared_ptr _tap_action; + std::shared_ptr _tap_node; std::shared_ptr _touch_action; + std::shared_ptr _touch_node; int8_t _last_direction = 0; bool _last_proxy = false;