From 485788a74ec067cb336c4bce7c7efd91507c5611 Mon Sep 17 00:00:00 2001 From: pixl Date: Sat, 29 Apr 2023 14:16:19 -0400 Subject: [PATCH] Ensure wheel compaitiblity with gestures Also uses a definition for the root service name pizza.pixl.LogiOps. --- src/logid/Configuration.cpp | 3 ++- src/logid/Device.cpp | 3 ++- src/logid/DeviceManager.cpp | 5 +++-- src/logid/Receiver.cpp | 3 ++- src/logid/actions/Action.cpp | 3 ++- src/logid/actions/gesture/Gesture.cpp | 3 ++- src/logid/features/RemapButton.cpp | 10 ++++----- src/logid/features/SmartShift.cpp | 3 ++- src/logid/features/ThumbWheel.cpp | 31 ++++++++++++++++++++++----- src/logid/ipc_defs.h | 24 +++++++++++++++++++++ src/logid/logid.cpp | 5 ++--- 11 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 src/logid/ipc_defs.h diff --git a/src/logid/Configuration.cpp b/src/logid/Configuration.cpp index b489cc4..3d494fe 100644 --- a/src/logid/Configuration.cpp +++ b/src/logid/Configuration.cpp @@ -19,6 +19,7 @@ #include #include #include +#include using namespace logid; using namespace libconfig; @@ -60,7 +61,7 @@ void Configuration::save() { } Configuration::IPC::IPC(Configuration* config) : - ipcgull::interface("pizza.pixl.LogiOps.Config", { + ipcgull::interface(SERVICE_ROOT_NAME ".Config", { {"Save", {config, &Configuration::save}} }, {}, {}) { } \ No newline at end of file diff --git a/src/logid/Device.cpp b/src/logid/Device.cpp index b160fbe..a556e33 100644 --- a/src/logid/Device.cpp +++ b/src/logid/Device.cpp @@ -28,6 +28,7 @@ #include #include #include +#include using namespace logid; using namespace logid::backend; @@ -246,7 +247,7 @@ void Device::_makeResetMechanism() { Device::IPC::IPC(Device* device) : ipcgull::interface( - "pizza.pixl.LogiOps.Device", + SERVICE_ROOT_NAME ".Device", {}, { {"Name", ipcgull::property( diff --git a/src/logid/DeviceManager.cpp b/src/logid/DeviceManager.cpp index 4a1e448..55aa932 100644 --- a/src/logid/DeviceManager.cpp +++ b/src/logid/DeviceManager.cpp @@ -23,6 +23,7 @@ #include #include #include +#include using namespace logid; using namespace logid::backend; @@ -190,7 +191,7 @@ void DeviceManager::removeDevice(std::string path) { DeviceManager::DevicesIPC::DevicesIPC(DeviceManager* manager) : ipcgull::interface( - "pizza.pixl.LogiOps.Devices", + SERVICE_ROOT_NAME ".Devices", { {"Enumerate", {manager, &DeviceManager::listDevices, {"devices"}}} }, @@ -238,7 +239,7 @@ void DeviceManager::DevicesIPC::deviceRemoved( DeviceManager::ReceiversIPC::ReceiversIPC(DeviceManager* manager) : ipcgull::interface( - "pizza.pixl.LogiOps.Receivers", + SERVICE_ROOT_NAME ".Receivers", { {"Enumerate", {manager, &DeviceManager::listReceivers, {"receivers"}}} diff --git a/src/logid/Receiver.cpp b/src/logid/Receiver.cpp index 5700369..854b69f 100644 --- a/src/logid/Receiver.cpp +++ b/src/logid/Receiver.cpp @@ -20,6 +20,7 @@ #include #include #include +#include using namespace logid; using namespace logid::backend; @@ -166,5 +167,5 @@ std::shared_ptr Receiver::rawReceiver() { } Receiver::ReceiverIPC::ReceiverIPC(Receiver* receiver) : - ipcgull::interface("pizza.pixl.LogiOps.Receiver", {}, {}, {}) { + ipcgull::interface(SERVICE_ROOT_NAME ".Receiver", {}, {}, {}) { } diff --git a/src/logid/actions/Action.cpp b/src/logid/actions/Action.cpp index efb3113..bcefca5 100644 --- a/src/logid/actions/Action.cpp +++ b/src/logid/actions/Action.cpp @@ -25,6 +25,7 @@ #include #include #include +#include using namespace logid; using namespace logid::actions; @@ -124,6 +125,6 @@ std::shared_ptr Action::makeAction( } Action::Action(Device* device, const std::string& name, tables t) : - ipcgull::interface("pizza.pixl.LogiOps.Action." + name, std::move(t)), + ipcgull::interface(SERVICE_ROOT_NAME ".Action." + name, std::move(t)), _device(device), _pressed(false) { } diff --git a/src/logid/actions/gesture/Gesture.cpp b/src/logid/actions/gesture/Gesture.cpp index 201474d..53ec4ba 100644 --- a/src/logid/actions/gesture/Gesture.cpp +++ b/src/logid/actions/gesture/Gesture.cpp @@ -23,6 +23,7 @@ #include #include #include +#include using namespace logid; using namespace logid::actions; @@ -30,7 +31,7 @@ using namespace logid::actions; Gesture::Gesture(Device* device, std::shared_ptr node, const std::string& name, tables t) : - ipcgull::interface("pizza.pixl.LogiOps.Gesture." + name, std::move(t)), + ipcgull::interface(SERVICE_ROOT_NAME ".Gesture." + name, std::move(t)), _node(std::move(node)), _device(device) { } diff --git a/src/logid/features/RemapButton.cpp b/src/logid/features/RemapButton.cpp index 9a52d78..423b5e2 100644 --- a/src/logid/features/RemapButton.cpp +++ b/src/logid/features/RemapButton.cpp @@ -20,6 +20,7 @@ #include #include #include +#include using namespace logid::features; using namespace logid::backend; @@ -31,7 +32,7 @@ using namespace logid::actions; static constexpr auto hidpp20_reprog_rebind = (hidpp20::ReprogControls::ChangeTemporaryDivert | - hidpp20::ReprogControls::ChangeRawXYDivert); + hidpp20::ReprogControls::ChangeRawXYDivert); RemapButton::RemapButton(Device* dev) : DeviceFeature(dev), _config(dev->activeProfile().buttons), @@ -239,9 +240,8 @@ std::shared_ptr Button::node() const { return _node; } -Button::IPC::IPC(Button* parent, - const Info& info) : - ipcgull::interface("pizza.pixl.LogiOps.Device.Button", { +Button::IPC::IPC(Button* parent, const Info& info) : + ipcgull::interface(SERVICE_ROOT_NAME ".Button", { {"SetAction", {this, &IPC::setAction, {"type"}}} }, { {"ControlID", ipcgull::property( @@ -278,7 +278,7 @@ void Button::IPC::setAction(const std::string& type) { } RemapButton::IPC::IPC(RemapButton* parent) : - ipcgull::interface("pizza.pixl.LogiOps.Buttons", { + ipcgull::interface(SERVICE_ROOT_NAME ".Buttons", { {"Enumerate", {this, &IPC::enumerate, {"buttons"}}} }, {}, {}), _parent(*parent) { diff --git a/src/logid/features/SmartShift.cpp b/src/logid/features/SmartShift.cpp index 39cf478..1463733 100644 --- a/src/logid/features/SmartShift.cpp +++ b/src/logid/features/SmartShift.cpp @@ -17,6 +17,7 @@ */ #include #include +#include using namespace logid::features; using namespace logid::backend; @@ -60,7 +61,7 @@ void SmartShift::setStatus(Status status) { SmartShift::IPC::IPC(SmartShift* parent) : ipcgull::interface( - "pizza.pixl.LogiOps.SmartShift", { + SERVICE_ROOT_NAME ".SmartShift", { {"GetStatus", {this, &IPC::getStatus, {"active", "threshold"}}}, {"SetActive", {this, &IPC::setActive, {"active"}}}, {"SetThreshold", {this, &IPC::setThreshold, {"threshold"}}}, diff --git a/src/logid/features/ThumbWheel.cpp b/src/logid/features/ThumbWheel.cpp index d945034..9de1aa0 100644 --- a/src/logid/features/ThumbWheel.cpp +++ b/src/logid/features/ThumbWheel.cpp @@ -20,6 +20,7 @@ #include #include #include +#include using namespace logid::features; using namespace logid::backend; @@ -47,8 +48,14 @@ namespace { const std::shared_ptr& parent, const std::string& direction) { if (conf.has_value()) { try { - return actions::Gesture::makeGesture( - dev, conf.value(), parent->make_child(direction)); + auto result = actions::Gesture::makeGesture(dev, conf.value(), + parent->make_child(direction)); + if (!result->wheelCompatibility()) { + logPrintf(WARN, "Mapping thumb wheel to incompatible gesture"); + return nullptr; + } else { + return result; + } } catch (actions::InvalidAction& e) { logPrintf(WARN, "Mapping thumb wheel to invalid gesture"); } @@ -216,7 +223,7 @@ void ThumbWheel::_fixGesture(const std::shared_ptr& gesture) c ThumbWheel::IPC::IPC(ThumbWheel* parent) : ipcgull::interface( - "pizza.pixl.LogiOps.ThumbWheel", { + SERVICE_ROOT_NAME ".ThumbWheel", { {"GetConfig", {this, &IPC::getConfig, {"divert", "invert"}}}, {"SetDivert", {this, &IPC::setDivert, {"divert"}}}, {"SetInvert", {this, &IPC::setInvert, {"invert"}}}, @@ -276,7 +283,14 @@ void ThumbWheel::IPC::setLeft(const std::string& type) { } _parent._left_gesture = actions::Gesture::makeGesture( _parent._device, type, config.left.value(), _parent._left_node); - _parent._fixGesture(_parent._left_gesture); + if (!_parent._left_gesture->wheelCompatibility()) { + _parent._left_gesture.reset(); + config.left.reset(); + + throw std::invalid_argument("incompatible gesture"); + } else { + _parent._fixGesture(_parent._left_gesture); + } } void ThumbWheel::IPC::setRight(const std::string& type) { @@ -289,7 +303,14 @@ void ThumbWheel::IPC::setRight(const std::string& type) { } _parent._right_gesture = actions::Gesture::makeGesture( _parent._device, type, config.right.value(), _parent._right_node); - _parent._fixGesture(_parent._right_gesture); + if (!_parent._right_gesture->wheelCompatibility()) { + _parent._right_gesture.reset(); + config.right.reset(); + + throw std::invalid_argument("incompatible gesture"); + } else { + _parent._fixGesture(_parent._right_gesture); + } } void ThumbWheel::IPC::setProxy(const std::string& type) { diff --git a/src/logid/ipc_defs.h b/src/logid/ipc_defs.h new file mode 100644 index 0000000..5452821 --- /dev/null +++ b/src/logid/ipc_defs.h @@ -0,0 +1,24 @@ +/* + * Copyright 2019-2023 PixlOne + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#ifndef LOGIOPS_IPC_DEFS_H +#define LOGIOPS_IPC_DEFS_H + +#define SERVICE_ROOT_NAME "pizza.pixl.LogiOps" +static constexpr auto server_root_node = "/pizza/pixl/logiops"; + +#endif //LOGIOPS_IPC_DEFS_H diff --git a/src/logid/logid.cpp b/src/logid/logid.cpp index efa9a9c..20fed87 100644 --- a/src/logid/logid.cpp +++ b/src/logid/logid.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #ifndef LOGIOPS_VERSION #define LOGIOPS_VERSION "null" @@ -141,9 +142,7 @@ int main(int argc, char** argv) { config = std::make_shared(); } - auto server = ipcgull::make_server("pizza.pixl.LogiOps", - "/pizza/pixl/LogiOps", - ipcgull::IPCGULL_USER); + auto server = ipcgull::make_server(SERVICE_ROOT_NAME, server_root_node, ipcgull::IPCGULL_USER); //Create a virtual input device try {