mirror of
https://github.com/PixlOne/logiops.git
synced 2025-09-14 13:56:50 +08:00
Add ChangeHostAction IPC interface
This commit is contained in:
parent
56dee076ea
commit
9af666f863
@ -58,31 +58,26 @@ std::shared_ptr<Action> _makeAction(
|
||||
{
|
||||
if(name == ChangeDPI::interface_name) {
|
||||
config = config::ChangeDPI();
|
||||
return Action::makeAction(device, config.value(), parent);
|
||||
} else if(name == ChangeHostAction::interface_name) {
|
||||
config = config::ChangeHost();
|
||||
return Action::makeAction(device, config.value(), parent);
|
||||
} else if(name == CycleDPI::interface_name) {
|
||||
config = config::CycleDPI();
|
||||
return Action::makeAction(device, config.value(), parent);
|
||||
} else if(name == KeypressAction::interface_name) {
|
||||
config = config::KeypressAction();
|
||||
return Action::makeAction(device, config.value(), parent);
|
||||
} else if(name == NullAction::interface_name) {
|
||||
config = config::NoAction();
|
||||
return Action::makeAction(device, config.value(), parent);
|
||||
} else if(name == ChangeHostAction::interface_name) {
|
||||
config = config::ChangeHost();
|
||||
} else if(name == ToggleHiresScroll::interface_name) {
|
||||
config = config::ToggleHiresScroll();
|
||||
return Action::makeAction(device, config.value(), parent);
|
||||
} else if(name == ToggleSmartShift::interface_name) {
|
||||
config = config::ToggleHiresScroll();
|
||||
return Action::makeAction(device, config.value(), parent);
|
||||
} else if(name == "Default") {
|
||||
config.reset();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
throw InvalidAction();
|
||||
return Action::makeAction(device, config.value(), parent);
|
||||
}
|
||||
|
||||
std::shared_ptr<Action> Action::makeAction(
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include "ChangeDPI.h"
|
||||
#include "../Device.h"
|
||||
#include "../util/task.h"
|
||||
#include "../util/log.h"
|
||||
#include "../backend/hidpp20/Error.h"
|
||||
#include "../backend/hidpp20/features/ReprogControls.h"
|
||||
|
||||
using namespace logid::actions;
|
||||
@ -28,7 +26,7 @@ const char* ChangeDPI::interface_name = "ChangeDPI";
|
||||
|
||||
ChangeDPI::ChangeDPI(
|
||||
Device *device, config::ChangeDPI& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent) :
|
||||
[[maybe_unused]] const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action(device, interface_name, {
|
||||
{
|
||||
{"GetConfig", {this, &ChangeDPI::getConfig, {"change", "sensor"}}},
|
||||
@ -44,7 +42,7 @@ ChangeDPI::ChangeDPI(
|
||||
_device->hidpp20().deviceIndex());
|
||||
}
|
||||
|
||||
std::tuple<int16_t, uint16_t> ChangeDPI::getConfig()
|
||||
std::tuple<int16_t, uint16_t> ChangeDPI::getConfig() const
|
||||
{
|
||||
return {_config.inc.value_or(0), _config.sensor.value_or(0)};
|
||||
}
|
||||
|
@ -22,8 +22,7 @@
|
||||
#include "Action.h"
|
||||
#include "../features/DPI.h"
|
||||
|
||||
namespace logid {
|
||||
namespace actions {
|
||||
namespace logid::actions {
|
||||
class ChangeDPI : public Action
|
||||
{
|
||||
public:
|
||||
@ -35,7 +34,7 @@ namespace logid {
|
||||
virtual void press();
|
||||
virtual void release();
|
||||
|
||||
std::tuple<int16_t, uint16_t> getConfig();
|
||||
[[nodiscard]] std::tuple<int16_t, uint16_t> getConfig() const;
|
||||
void setChange(int16_t change);
|
||||
void setSensor(uint8_t sensor, bool reset);
|
||||
|
||||
@ -45,6 +44,6 @@ namespace logid {
|
||||
config::ChangeDPI& _config;
|
||||
std::shared_ptr<features::DPI> _dpi;
|
||||
};
|
||||
}}
|
||||
}
|
||||
|
||||
#endif //LOGID_ACTION_CHANGEDPI_H
|
@ -29,12 +29,19 @@ const char* ChangeHostAction::interface_name = "ChangeHost";
|
||||
ChangeHostAction::ChangeHostAction(
|
||||
Device *device, config::ChangeHost& config,
|
||||
[[maybe_unused]] const std::shared_ptr<ipcgull::node>& parent)
|
||||
: Action(device, interface_name), _config (config)
|
||||
: Action(device, interface_name, {
|
||||
{
|
||||
{"GetHost", {this, &ChangeHostAction::getHost, {"host"}}},
|
||||
{"SetHost", {this, &ChangeHostAction::setHost, {"host"}}}
|
||||
}, {}, {}
|
||||
}), _config (config)
|
||||
{
|
||||
if(std::holds_alternative<std::string>(_config.host.value())) {
|
||||
auto& host = std::get<std::string>(_config.host.value());
|
||||
std::transform(host.begin(), host.end(),
|
||||
host.begin(), ::tolower);
|
||||
if (_config.host.has_value()) {
|
||||
if(std::holds_alternative<std::string>(_config.host.value())) {
|
||||
auto& host = std::get<std::string>(_config.host.value());
|
||||
std::transform(host.begin(), host.end(),
|
||||
host.begin(), ::tolower);
|
||||
}
|
||||
}
|
||||
try {
|
||||
_change_host = std::make_shared<hidpp20::ChangeHost>(&device->hidpp20());
|
||||
@ -45,6 +52,29 @@ ChangeHostAction::ChangeHostAction(
|
||||
}
|
||||
}
|
||||
|
||||
std::string ChangeHostAction::getHost() const
|
||||
{
|
||||
if(_config.host.has_value()) {
|
||||
if (std::holds_alternative<std::string>(_config.host.value()))
|
||||
return std::get<std::string>(_config.host.value());
|
||||
else
|
||||
return std::to_string(std::get<int>(_config.host.value()));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeHostAction::setHost(std::string host)
|
||||
{
|
||||
std::transform(host.begin(), host.end(),
|
||||
host.begin(), ::tolower);
|
||||
if (host == "next" || host == "prev" || host == "previous") {
|
||||
_config.host = std::move(host);
|
||||
} else {
|
||||
_config.host = std::stoi(host);
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeHostAction::press()
|
||||
{
|
||||
// Do nothing, wait until release
|
||||
@ -70,7 +100,7 @@ void ChangeHostAction::release()
|
||||
}
|
||||
next_host %= host_info.hostCount;
|
||||
if(next_host != host_info.currentHost)
|
||||
_change_host->setHost(next_host-1);
|
||||
_change_host->setHost(next_host);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,7 @@
|
||||
#include "Action.h"
|
||||
#include "../backend/hidpp20/features/ChangeHost.h"
|
||||
|
||||
namespace logid {
|
||||
namespace actions
|
||||
namespace logid::actions
|
||||
{
|
||||
class ChangeHostAction : public Action
|
||||
{
|
||||
@ -36,12 +35,16 @@ namespace actions
|
||||
virtual void press();
|
||||
virtual void release();
|
||||
|
||||
|
||||
[[nodiscard]] std::string getHost() const;
|
||||
void setHost(std::string host);
|
||||
|
||||
virtual uint8_t reprogFlags() const;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<backend::hidpp20::ChangeHost> _change_host;
|
||||
config::ChangeHost& _config;
|
||||
};
|
||||
}}
|
||||
}
|
||||
|
||||
#endif //LOGID_ACTION_CHANGEHOSTACTION_H
|
||||
|
@ -49,9 +49,8 @@ CycleDPI::CycleDPI(Device* device, config::CycleDPI& config,
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<int> CycleDPI::getDPIs()
|
||||
std::vector<int> CycleDPI::getDPIs() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_dpi_lock);
|
||||
auto dpis = _config.dpis.value_or(std::list<int>());
|
||||
return {dpis.begin(), dpis.end()};
|
||||
}
|
||||
|
@ -22,8 +22,7 @@
|
||||
#include "Action.h"
|
||||
#include "../features/DPI.h"
|
||||
|
||||
namespace logid {
|
||||
namespace actions {
|
||||
namespace logid::actions {
|
||||
class CycleDPI : public Action
|
||||
{
|
||||
public:
|
||||
@ -35,7 +34,7 @@ namespace actions {
|
||||
virtual void press();
|
||||
virtual void release();
|
||||
|
||||
std::vector<int> getDPIs();
|
||||
[[nodiscard]] std::vector<int> getDPIs() const;
|
||||
void setDPIs(const std::vector<int>& dpis);
|
||||
|
||||
virtual uint8_t reprogFlags() const;
|
||||
@ -46,6 +45,6 @@ namespace actions {
|
||||
std::shared_ptr<features::DPI> _dpi;
|
||||
std::list<int>::const_iterator _current_dpi;
|
||||
};
|
||||
}}
|
||||
}
|
||||
|
||||
#endif //LOGID_ACTION_CYCLEDPI_H
|
Loading…
Reference in New Issue
Block a user