diff --git a/src/logid/CMakeLists.txt b/src/logid/CMakeLists.txt index 23f291b..15d8aa1 100644 --- a/src/logid/CMakeLists.txt +++ b/src/logid/CMakeLists.txt @@ -33,6 +33,7 @@ add_executable(logid actions/ChangeDPI.cpp actions/GestureAction.cpp actions/ChangeHostAction.cpp + actions/ChangeProfile.cpp actions/gesture/Gesture.cpp actions/gesture/ReleaseGesture.cpp actions/gesture/ThresholdGesture.cpp diff --git a/src/logid/actions/Action.cpp b/src/logid/actions/Action.cpp index 0abd9ee..317a2dc 100644 --- a/src/logid/actions/Action.cpp +++ b/src/logid/actions/Action.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include using namespace logid; @@ -71,6 +72,8 @@ namespace logid::actions { config = config::ToggleHiresScroll(); } else if (name == ToggleSmartShift::interface_name) { config = config::ToggleSmartShift(); + } else if (name == ChangeProfile::interface_name) { + config = config::ChangeProfile(); } else if (name == "Default") { config.reset(); return nullptr; diff --git a/src/logid/actions/ChangeProfile.cpp b/src/logid/actions/ChangeProfile.cpp new file mode 100644 index 0000000..4e0f7b0 --- /dev/null +++ b/src/logid/actions/ChangeProfile.cpp @@ -0,0 +1,67 @@ +/* + * 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 . + * + */ +#include +#include +#include + +using namespace logid; +using namespace logid::actions; + +const char* ChangeProfile::interface_name = "ChangeProfile"; + +ChangeProfile::ChangeProfile(Device* device, config::ChangeProfile& config, + [[maybe_unused]] const std::shared_ptr& parent) : + Action(device, interface_name, { + { + {"GetProfile", {this, &ChangeProfile::getProfile, {"profile"}}}, + {"SetProfile", {this, &ChangeProfile::setProfile, {"profile"}}} + }, + {}, + {} + }), _config(config) { +} + +void ChangeProfile::press() { +} + +void ChangeProfile::release() { + std::shared_lock lock(_config_mutex); + if (_config.profile.has_value()) + _device->setProfileDelayed(_config.profile.value()); +} + +uint8_t ChangeProfile::reprogFlags() const { + return backend::hidpp20::ReprogControls::TemporaryDiverted; +} + +std::string ChangeProfile::getProfile() { + std::shared_lock lock(_config_mutex); + if (_config.profile.has_value()) + return _config.profile.value(); + else + return ""; +} + +void ChangeProfile::setProfile(std::string profile) { + std::unique_lock lock(_config_mutex); + + if (profile.empty()) + _config.profile->clear(); + else + _config.profile = std::move(profile); +} diff --git a/src/logid/actions/ChangeProfile.h b/src/logid/actions/ChangeProfile.h new file mode 100644 index 0000000..0cbdc91 --- /dev/null +++ b/src/logid/actions/ChangeProfile.h @@ -0,0 +1,47 @@ +/* + * 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 LOGID_CHANGEPROFILE_H +#define LOGID_CHANGEPROFILE_H + +#include + +namespace logid::actions { + class ChangeProfile : public Action { + public: + static const char* interface_name; + + ChangeProfile(Device* device, config::ChangeProfile& setting, + const std::shared_ptr& parent); + + void press() final; + + void release() final; + + [[nodiscard]] uint8_t reprogFlags() const final; + + std::string getProfile(); + + void setProfile(std::string profile); + + private: + config::ChangeProfile& _config; + }; +} + + +#endif //LOGID_CHANGEPROFILE_H diff --git a/src/logid/actions/CycleDPI.cpp b/src/logid/actions/CycleDPI.cpp index 3c822da..ee23252 100644 --- a/src/logid/actions/CycleDPI.cpp +++ b/src/logid/actions/CycleDPI.cpp @@ -22,7 +22,6 @@ #include using namespace logid::actions; -using namespace libconfig; const char* CycleDPI::interface_name = "CycleDPI"; diff --git a/src/logid/config/schema.h b/src/logid/config/schema.h index 1fac35c..6ae249a 100644 --- a/src/logid/config/schema.h +++ b/src/logid/config/schema.h @@ -25,6 +25,8 @@ namespace logid::actions { class ChangeHostAction; + class ChangeProfile; + class CycleDPI; class GestureAction; @@ -115,6 +117,14 @@ namespace logid::config { {"host"}, &ChangeHost::host) {} }; + struct ChangeProfile : public signed_group { + typedef actions::ChangeProfile action; + std::optional profile; + + ChangeProfile() : signed_group("type", "ChangeProfile", + {"profile"}, &ChangeProfile::profile) {} + }; + typedef std::variant< NoAction, KeypressAction, @@ -122,7 +132,8 @@ namespace logid::config { ToggleHiresScroll, CycleDPI, ChangeDPI, - ChangeHost + ChangeHost, + ChangeProfile > BasicAction; struct AxisGesture : public signed_group { @@ -219,6 +230,7 @@ namespace logid::config { CycleDPI, ChangeDPI, ChangeHost, + ChangeProfile, GestureAction > Action;