mirror of
https://github.com/PixlOne/logiops.git
synced 2025-07-16 06:12:32 +08:00
Add ChangeProfile action
This commit is contained in:
parent
5e47bc6ae4
commit
f614bce4ce
@ -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
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <actions/CycleDPI.h>
|
||||
#include <actions/ChangeDPI.h>
|
||||
#include <actions/ChangeHostAction.h>
|
||||
#include <actions/ChangeProfile.h>
|
||||
#include <ipc_defs.h>
|
||||
|
||||
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;
|
||||
|
67
src/logid/actions/ChangeProfile.cpp
Normal file
67
src/logid/actions/ChangeProfile.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#include <actions/ChangeProfile.h>
|
||||
#include <backend/hidpp20/features/ReprogControls.h>
|
||||
#include <Device.h>
|
||||
|
||||
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<ipcgull::node>& 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);
|
||||
}
|
47
src/logid/actions/ChangeProfile.h
Normal file
47
src/logid/actions/ChangeProfile.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifndef LOGID_CHANGEPROFILE_H
|
||||
#define LOGID_CHANGEPROFILE_H
|
||||
|
||||
#include <actions/Action.h>
|
||||
|
||||
namespace logid::actions {
|
||||
class ChangeProfile : public Action {
|
||||
public:
|
||||
static const char* interface_name;
|
||||
|
||||
ChangeProfile(Device* device, config::ChangeProfile& setting,
|
||||
const std::shared_ptr<ipcgull::node>& 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
|
@ -22,7 +22,6 @@
|
||||
#include <util/log.h>
|
||||
|
||||
using namespace logid::actions;
|
||||
using namespace libconfig;
|
||||
|
||||
const char* CycleDPI::interface_name = "CycleDPI";
|
||||
|
||||
|
@ -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<std::string> {
|
||||
typedef actions::ChangeProfile action;
|
||||
std::optional<std::string> profile;
|
||||
|
||||
ChangeProfile() : signed_group<std::string>("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<std::string> {
|
||||
@ -219,6 +230,7 @@ namespace logid::config {
|
||||
CycleDPI,
|
||||
ChangeDPI,
|
||||
ChangeHost,
|
||||
ChangeProfile,
|
||||
GestureAction
|
||||
> Action;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user