mirror of
https://github.com/PixlOne/logiops.git
synced 2025-07-13 21:02:43 +08:00
Add several IPC interfaces
This commit is contained in:
parent
c69ae325d3
commit
605ccdc07d
@ -1 +1 @@
|
||||
Subproject commit e86f1987bc40c840d3cef758619783e5bdec1c41
|
||||
Subproject commit 200df3c202739de5249b2fd7c43900fcb25c01cb
|
@ -62,4 +62,11 @@ void Configuration::save()
|
||||
_config_file.c_str(), e.what());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
Configuration::IPC::IPC(Configuration *config) :
|
||||
ipcgull::interface("pizza.pixl.LogiOps.Config", {
|
||||
{"Save", {config, &Configuration::save}}
|
||||
}, {}, {})
|
||||
{
|
||||
}
|
@ -24,6 +24,7 @@
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <set>
|
||||
#include <ipcgull/interface.h>
|
||||
|
||||
#include "config/schema.h"
|
||||
|
||||
@ -44,6 +45,13 @@ namespace logid
|
||||
// Reloading is not safe, references will be invalidated
|
||||
//void reload();
|
||||
void save();
|
||||
|
||||
class IPC : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
IPC(Configuration* config);
|
||||
};
|
||||
|
||||
private:
|
||||
std::string _config_file;
|
||||
libconfig::Config _config;
|
||||
|
@ -67,7 +67,7 @@ std::shared_ptr<Device> Device::make(
|
||||
std::move(manager));
|
||||
ret->_self = ret;
|
||||
ret->_ipc_node->manage(ret);
|
||||
ret->_ipc_interface = ret->_ipc_node->make_interface<DeviceIPC>(ret.get());
|
||||
ret->_ipc_interface = ret->_ipc_node->make_interface<IPC>(ret.get());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ std::shared_ptr<Device> Device::make(
|
||||
std::move(manager));
|
||||
ret->_self = ret;
|
||||
ret->_ipc_node->manage(ret);
|
||||
ret->_ipc_interface = ret->_ipc_node->make_interface<DeviceIPC>(ret.get());
|
||||
ret->_ipc_interface = ret->_ipc_node->make_interface<IPC>(ret.get());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ std::shared_ptr<Device> Device::make(
|
||||
auto ret = std::make_shared<_Device>(receiver, index, std::move(manager));
|
||||
ret->_self = ret;
|
||||
ret->_ipc_node->manage(ret);
|
||||
ret->_ipc_interface = ret->_ipc_node->make_interface<DeviceIPC>(ret.get());
|
||||
ret->_ipc_interface = ret->_ipc_node->make_interface<IPC>(ret.get());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ void Device::_makeResetMechanism()
|
||||
}
|
||||
}
|
||||
|
||||
Device::DeviceIPC::DeviceIPC(Device* device) :
|
||||
Device::IPC::IPC(Device* device) :
|
||||
ipcgull::interface(
|
||||
"pizza.pixl.LogiOps.Device",
|
||||
{},
|
||||
@ -274,7 +274,8 @@ Device::DeviceIPC::DeviceIPC(Device* device) :
|
||||
ipcgull::property_readable, device->name())},
|
||||
{"ProductID", ipcgull::property<uint16_t>(
|
||||
ipcgull::property_readable, device->pid())},
|
||||
{"Active", device->_awake}
|
||||
{"Active", device->_awake},
|
||||
{"DefaultProfile", device->_config.default_profile}
|
||||
}, {
|
||||
{"StatusChanged",
|
||||
ipcgull::signal::make_signal<bool>({"active"})}
|
||||
@ -282,7 +283,7 @@ Device::DeviceIPC::DeviceIPC(Device* device) :
|
||||
{
|
||||
}
|
||||
|
||||
void Device::DeviceIPC::notifyStatus() const
|
||||
void Device::IPC::notifyStatus() const
|
||||
{
|
||||
emit_signal("StatusChanged", (bool)(_device._awake));
|
||||
}
|
||||
|
@ -142,17 +142,17 @@ namespace logid
|
||||
const DeviceNickname _nickname;
|
||||
std::shared_ptr<ipcgull::node> _ipc_node;
|
||||
|
||||
class DeviceIPC : public ipcgull::interface {
|
||||
class IPC : public ipcgull::interface {
|
||||
private:
|
||||
Device& _device;
|
||||
public:
|
||||
DeviceIPC(Device* device);
|
||||
IPC(Device* device);
|
||||
void notifyStatus() const;
|
||||
};
|
||||
|
||||
ipcgull::property<bool> _awake;
|
||||
std::mutex _state_lock;
|
||||
std::shared_ptr<DeviceIPC> _ipc_interface;
|
||||
std::shared_ptr<IPC> _ipc_interface;
|
||||
|
||||
std::weak_ptr<Device> _self;
|
||||
};
|
||||
|
@ -52,6 +52,7 @@ DeviceManager::DeviceManager(std::shared_ptr<Configuration> config,
|
||||
{
|
||||
_ipc_devices = _root_node->make_interface<DevicesIPC>(this);
|
||||
_ipc_receivers = _root_node->make_interface<ReceiversIPC>(this);
|
||||
_ipc_config = _root_node->make_interface<Configuration::IPC>(_config.get());
|
||||
_device_node->add_server(_server);
|
||||
_receiver_node->add_server(_server);
|
||||
_root_node->add_server(_server);
|
||||
|
@ -88,6 +88,7 @@ namespace logid
|
||||
std::shared_ptr<ipcgull::node> _device_node;
|
||||
std::shared_ptr<ipcgull::node> _receiver_node;
|
||||
|
||||
std::shared_ptr<Configuration::IPC> _ipc_config;
|
||||
std::shared_ptr<DevicesIPC> _ipc_devices;
|
||||
std::shared_ptr<ReceiversIPC> _ipc_receivers;
|
||||
|
||||
|
@ -33,6 +33,11 @@ InputDevice::InvalidEventCode::InvalidEventCode(const std::string& name) :
|
||||
{
|
||||
}
|
||||
|
||||
InputDevice::InvalidEventCode::InvalidEventCode(uint code) :
|
||||
_what ("Invalid event code " + std::to_string(code))
|
||||
{
|
||||
}
|
||||
|
||||
const char* InputDevice::InvalidEventCode::what() const noexcept
|
||||
{
|
||||
return _what.c_str();
|
||||
@ -115,11 +120,21 @@ void InputDevice::releaseKey(uint code)
|
||||
_sendEvent(EV_KEY, code, 0);
|
||||
}
|
||||
|
||||
std::string InputDevice::toKeyName(uint code)
|
||||
{
|
||||
return _toEventName(EV_KEY, code);
|
||||
}
|
||||
|
||||
uint InputDevice::toKeyCode(const std::string& name)
|
||||
{
|
||||
return _toEventCode(EV_KEY, name);
|
||||
}
|
||||
|
||||
std::string InputDevice::toAxisName(uint code)
|
||||
{
|
||||
return _toEventName(EV_REL, code);
|
||||
}
|
||||
|
||||
uint InputDevice::toAxisCode(const std::string& name)
|
||||
{
|
||||
return _toEventCode(EV_REL, name);
|
||||
@ -141,6 +156,16 @@ int InputDevice::getLowResAxis(const uint axis_code)
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string InputDevice::_toEventName(uint type, uint code)
|
||||
{
|
||||
const char* ret = libevdev_event_code_get_name(type, code);
|
||||
|
||||
if(!ret)
|
||||
throw InvalidEventCode(code);
|
||||
|
||||
return {ret};
|
||||
}
|
||||
|
||||
uint InputDevice::_toEventCode(uint type, const std::string& name)
|
||||
{
|
||||
int code = libevdev_event_code_from_name(type, name.c_str());
|
||||
|
@ -37,6 +37,7 @@ namespace logid
|
||||
{
|
||||
public:
|
||||
explicit InvalidEventCode(const std::string& name);
|
||||
explicit InvalidEventCode(uint code);
|
||||
const char* what() const noexcept override;
|
||||
private:
|
||||
const std::string _what;
|
||||
@ -50,7 +51,9 @@ namespace logid
|
||||
void pressKey(uint code);
|
||||
void releaseKey(uint code);
|
||||
|
||||
static std::string toKeyName(uint code);
|
||||
static uint toKeyCode(const std::string& name);
|
||||
static std::string toAxisName(uint code);
|
||||
static uint toAxisCode(const std::string& name);
|
||||
static int getLowResAxis(uint axis_code);
|
||||
|
||||
@ -58,6 +61,7 @@ namespace logid
|
||||
void _sendEvent(uint type, uint code, int value);
|
||||
void _enableEvent(uint type, uint name);
|
||||
|
||||
static std::string _toEventName(uint type, uint code);
|
||||
static uint _toEventCode(uint type, const std::string& name);
|
||||
|
||||
bool registered_keys[KEY_CNT];
|
||||
|
@ -43,9 +43,11 @@ struct action_type<T&> : action_type<T> { };
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<Action> _makeAction(
|
||||
Device* device, T action,
|
||||
const std::shared_ptr<ipcgull::node>& parent) {
|
||||
return std::make_shared<typename action_type<T>::type>(device, action, parent);
|
||||
Device* device, T& action,
|
||||
const std::shared_ptr<ipcgull::node>& parent)
|
||||
{
|
||||
return parent->make_interface<typename action_type<T>::type>(
|
||||
device, std::forward<T&>(action), parent);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -75,7 +77,8 @@ std::shared_ptr<Action> _makeAction(
|
||||
} else if(name == ToggleSmartShift::interface_name) {
|
||||
config = config::ToggleHiresScroll();
|
||||
return Action::makeAction(device, config.value(), parent);
|
||||
} else if(name == "pizza.pixl.LogiOps.Action.Default") {
|
||||
} else if(name == "Default") {
|
||||
config.reset();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -127,3 +130,9 @@ std::shared_ptr<Action> Action::makeAction(
|
||||
}, action);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Action::Action(Device* device, const std::string& name, tables t) :
|
||||
ipcgull::interface("pizza.pixl.LogiOps.Action." + name, std::move(t)),
|
||||
_device (device), _pressed (false)
|
||||
{
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ namespace actions {
|
||||
std::string _action;
|
||||
};
|
||||
|
||||
class Action
|
||||
class Action : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<Action> makeAction(
|
||||
@ -84,9 +84,8 @@ namespace actions {
|
||||
virtual ~Action() = default;
|
||||
|
||||
protected:
|
||||
explicit Action(Device* device) : _device (device), _pressed (false)
|
||||
{
|
||||
}
|
||||
Action(Device* device, const std::string& name, tables t={});
|
||||
|
||||
Device* _device;
|
||||
std::atomic<bool> _pressed;
|
||||
};
|
||||
|
@ -24,13 +24,12 @@
|
||||
|
||||
using namespace logid::actions;
|
||||
|
||||
const char* ChangeDPI::interface_name =
|
||||
"pizza.pixl.LogiOps.Action.ChangeDPI";
|
||||
const char* ChangeDPI::interface_name = "ChangeDPI";
|
||||
|
||||
ChangeDPI::ChangeDPI(
|
||||
Device *device, config::ChangeDPI& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action(device), _config (config)
|
||||
Action(device, interface_name), _config (config)
|
||||
{
|
||||
_dpi = _device->getFeature<features::DPI>("dpi");
|
||||
if(!_dpi)
|
||||
@ -38,19 +37,17 @@ ChangeDPI::ChangeDPI(
|
||||
"ChangeDPI action.",
|
||||
_device->hidpp20().devicePath().c_str(),
|
||||
_device->hidpp20().deviceIndex());
|
||||
|
||||
_ipc = parent->make_interface<IPC>(this);
|
||||
}
|
||||
|
||||
void ChangeDPI::press()
|
||||
{
|
||||
_pressed = true;
|
||||
if(_dpi) {
|
||||
if(_dpi && _config.inc.has_value()) {
|
||||
spawn_task(
|
||||
[this]{
|
||||
try {
|
||||
uint16_t last_dpi = _dpi->getDPI(_config.sensor.value_or(0));
|
||||
_dpi->setDPI(last_dpi + _config.inc,
|
||||
_dpi->setDPI(last_dpi + _config.inc.value(),
|
||||
_config.sensor.value_or(0));
|
||||
} catch (backend::hidpp20::Error& e) {
|
||||
if(e.code() == backend::hidpp20::Error::InvalidArgument)
|
||||
@ -75,8 +72,3 @@ uint8_t ChangeDPI::reprogFlags() const
|
||||
{
|
||||
return backend::hidpp20::ReprogControls::TemporaryDiverted;
|
||||
}
|
||||
|
||||
ChangeDPI::IPC::IPC(ChangeDPI *action) :
|
||||
ipcgull::interface(interface_name, {}, {}, {}), _action (*action)
|
||||
{
|
||||
}
|
||||
|
@ -40,16 +40,6 @@ namespace logid {
|
||||
protected:
|
||||
config::ChangeDPI& _config;
|
||||
std::shared_ptr<features::DPI> _dpi;
|
||||
private:
|
||||
class IPC : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
IPC(ChangeDPI* action);
|
||||
private:
|
||||
ChangeDPI& _action;
|
||||
};
|
||||
|
||||
std::shared_ptr<IPC> _ipc;
|
||||
};
|
||||
}}
|
||||
|
||||
|
@ -24,16 +24,15 @@
|
||||
using namespace logid::actions;
|
||||
using namespace logid::backend;
|
||||
|
||||
const char* ChangeHostAction::interface_name =
|
||||
"pizza.pixl.LogiOps.Action.ChangeHost";
|
||||
const char* ChangeHostAction::interface_name = "ChangeHost";
|
||||
|
||||
ChangeHostAction::ChangeHostAction(
|
||||
Device *device, config::ChangeHost& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent)
|
||||
: Action(device), _config (config)
|
||||
[[maybe_unused]] const std::shared_ptr<ipcgull::node>& parent)
|
||||
: Action(device, interface_name), _config (config)
|
||||
{
|
||||
if(std::holds_alternative<std::string>(_config.host)) {
|
||||
auto& host = std::get<std::string>(_config.host);
|
||||
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);
|
||||
}
|
||||
@ -44,8 +43,6 @@ ChangeHostAction::ChangeHostAction(
|
||||
"ChangeHostAction will not work.", device->hidpp20()
|
||||
.devicePath().c_str(), device->hidpp20().deviceIndex());
|
||||
}
|
||||
|
||||
_ipc = parent->make_interface<IPC>(this);
|
||||
}
|
||||
|
||||
void ChangeHostAction::press()
|
||||
@ -55,13 +52,13 @@ void ChangeHostAction::press()
|
||||
|
||||
void ChangeHostAction::release()
|
||||
{
|
||||
if(_change_host) {
|
||||
if(_change_host && _config.host.has_value()) {
|
||||
spawn_task(
|
||||
[this] {
|
||||
auto host_info = _change_host->getHostInfo();
|
||||
int next_host;
|
||||
if(std::holds_alternative<std::string>(_config.host)) {
|
||||
const auto& host = std::get<std::string>(_config.host);
|
||||
if(std::holds_alternative<std::string>(_config.host.value())) {
|
||||
const auto& host = std::get<std::string>(_config.host.value());
|
||||
if(host == "next")
|
||||
next_host = host_info.currentHost + 1;
|
||||
else if(host == "prev" || host == "previous")
|
||||
@ -69,7 +66,7 @@ void ChangeHostAction::release()
|
||||
else
|
||||
next_host = host_info.currentHost;
|
||||
} else {
|
||||
next_host = std::get<int>(_config.host)-1;
|
||||
next_host = std::get<int>(_config.host.value())-1;
|
||||
}
|
||||
next_host %= host_info.hostCount;
|
||||
if(next_host != host_info.currentHost)
|
||||
@ -82,8 +79,3 @@ uint8_t ChangeHostAction::reprogFlags() const
|
||||
{
|
||||
return hidpp20::ReprogControls::TemporaryDiverted;
|
||||
}
|
||||
|
||||
ChangeHostAction::IPC::IPC(ChangeHostAction *action) :
|
||||
ipcgull::interface(interface_name, {}, {}, {}), _action (*action)
|
||||
{
|
||||
}
|
||||
|
@ -41,16 +41,6 @@ namespace actions
|
||||
protected:
|
||||
std::shared_ptr<backend::hidpp20::ChangeHost> _change_host;
|
||||
config::ChangeHost& _config;
|
||||
private:
|
||||
class IPC : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
IPC(ChangeHostAction* action);
|
||||
private:
|
||||
ChangeHostAction& _action;
|
||||
};
|
||||
|
||||
std::shared_ptr<IPC> _ipc;
|
||||
};
|
||||
}}
|
||||
|
||||
|
@ -25,12 +25,12 @@
|
||||
using namespace logid::actions;
|
||||
using namespace libconfig;
|
||||
|
||||
const char* CycleDPI::interface_name =
|
||||
"pizza.pixl.LogiOps.Action.CycleDPI";
|
||||
const char* CycleDPI::interface_name = "CycleDPI";
|
||||
|
||||
CycleDPI::CycleDPI(Device* device, config::CycleDPI& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action (device), _config (config), _current_dpi (_config.dpis.begin())
|
||||
Action (device, interface_name),
|
||||
_config (config)
|
||||
{
|
||||
_dpi = _device->getFeature<features::DPI>("dpi");
|
||||
if(!_dpi)
|
||||
@ -39,27 +39,29 @@ CycleDPI::CycleDPI(Device* device, config::CycleDPI& config,
|
||||
_device->hidpp20().devicePath().c_str(),
|
||||
_device->hidpp20().deviceIndex());
|
||||
|
||||
_ipc = parent->make_interface<IPC>(this);
|
||||
if(_config.dpis.has_value()) {
|
||||
_current_dpi = _config.dpis.value().begin();
|
||||
}
|
||||
}
|
||||
|
||||
void CycleDPI::press()
|
||||
{
|
||||
_pressed = true;
|
||||
if(_dpi && !_config.dpis.empty()) {
|
||||
spawn_task(
|
||||
[this](){
|
||||
std::lock_guard<std::mutex> lock(_dpi_lock);
|
||||
++_current_dpi;
|
||||
if(_current_dpi == _config.dpis.end())
|
||||
_current_dpi = _config.dpis.begin();
|
||||
std::lock_guard<std::mutex> lock(_dpi_lock);
|
||||
if(_dpi && _config.dpis.has_value() && _config.dpis.value().empty()) {
|
||||
++_current_dpi;
|
||||
if(_current_dpi == _config.dpis.value().end())
|
||||
_current_dpi = _config.dpis.value().begin();
|
||||
|
||||
spawn_task([this, dpi=*_current_dpi]{
|
||||
try {
|
||||
_dpi->setDPI(*_current_dpi, _config.sensor.value_or(0));
|
||||
_dpi->setDPI(dpi, _config.sensor.value_or(0));
|
||||
} catch (backend::hidpp20::Error& e) {
|
||||
if(e.code() == backend::hidpp20::Error::InvalidArgument)
|
||||
logPrintf(WARN, "%s:%d: Could not set DPI to %d for "
|
||||
"sensor %d", _device->hidpp20().devicePath().c_str(),
|
||||
_device->hidpp20().deviceIndex(), *_current_dpi,
|
||||
_config.sensor.value_or(0));
|
||||
"sensor %d", _device->hidpp20().devicePath().c_str(),
|
||||
_device->hidpp20().deviceIndex(), dpi,
|
||||
_config.sensor.value_or(0));
|
||||
else
|
||||
throw e;
|
||||
}
|
||||
@ -76,8 +78,3 @@ uint8_t CycleDPI::reprogFlags() const
|
||||
{
|
||||
return backend::hidpp20::ReprogControls::TemporaryDiverted;
|
||||
}
|
||||
|
||||
CycleDPI::IPC::IPC(CycleDPI *action) :
|
||||
ipcgull::interface(interface_name, {}, {}, {}), _action (*action)
|
||||
{
|
||||
}
|
||||
|
@ -42,16 +42,6 @@ namespace actions {
|
||||
config::CycleDPI& _config;
|
||||
std::shared_ptr<features::DPI> _dpi;
|
||||
std::list<int>::const_iterator _current_dpi;
|
||||
private:
|
||||
class IPC : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
IPC(CycleDPI* action);
|
||||
private:
|
||||
CycleDPI& _action;
|
||||
};
|
||||
|
||||
std::shared_ptr<IPC> _ipc;
|
||||
};
|
||||
}}
|
||||
|
||||
|
@ -24,8 +24,7 @@ using namespace logid::actions;
|
||||
using namespace logid;
|
||||
using namespace logid::backend;
|
||||
|
||||
const char* GestureAction::interface_name =
|
||||
"pizza.pixl.LogiOps.Action.Gesture";
|
||||
const char* GestureAction::interface_name = "Gesture";
|
||||
|
||||
GestureAction::Direction GestureAction::toDirection(std::string direction)
|
||||
{
|
||||
@ -78,7 +77,14 @@ GestureAction::Direction GestureAction::toDirection(int16_t x, int16_t y)
|
||||
|
||||
GestureAction::GestureAction(Device* dev, config::GestureAction& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action (dev), _config (config)
|
||||
Action (dev, interface_name,
|
||||
{
|
||||
{
|
||||
{"SetGesture", {this, &GestureAction::setGesture,
|
||||
{"direction", "type"}}}
|
||||
}, {}, {}
|
||||
}),
|
||||
_node (parent->make_child("gestures")), _config (config)
|
||||
{
|
||||
if(_config.gestures.has_value()) {
|
||||
auto& gestures = _config.gestures.value();
|
||||
@ -87,19 +93,20 @@ GestureAction::GestureAction(Device* dev, config::GestureAction& config,
|
||||
auto direction = toDirection(x.first);
|
||||
_gestures.emplace(direction,
|
||||
Gesture::makeGesture(
|
||||
dev, x.second, parent,
|
||||
fromDirection(direction)));
|
||||
dev, x.second,
|
||||
_node->make_child(
|
||||
fromDirection(direction))));
|
||||
} catch(std::invalid_argument& e) {
|
||||
logPrintf(WARN, "%s is not a direction", x.first.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_ipc = parent->make_interface<IPC>(this);
|
||||
}
|
||||
|
||||
void GestureAction::press()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_config_lock);
|
||||
|
||||
_pressed = true;
|
||||
_x = 0, _y = 0;
|
||||
for(auto& gesture : _gestures)
|
||||
@ -108,6 +115,8 @@ void GestureAction::press()
|
||||
|
||||
void GestureAction::release()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_config_lock);
|
||||
|
||||
_pressed = false;
|
||||
bool threshold_met = false;
|
||||
|
||||
@ -147,6 +156,8 @@ void GestureAction::release()
|
||||
|
||||
void GestureAction::move(int16_t x, int16_t y)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_config_lock);
|
||||
|
||||
auto new_x = _x + x, new_y = _y + y;
|
||||
|
||||
if(abs(x) > 0) {
|
||||
@ -218,7 +229,34 @@ uint8_t GestureAction::reprogFlags() const
|
||||
hidpp20::ReprogControls::RawXYDiverted);
|
||||
}
|
||||
|
||||
GestureAction::IPC::IPC(GestureAction *action) :
|
||||
ipcgull::interface(interface_name, {}, {}, {}), _action (*action)
|
||||
void GestureAction::setGesture(const std::string &direction,
|
||||
const std::string &type)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_config_lock);
|
||||
|
||||
Direction d = toDirection(direction);
|
||||
|
||||
auto it = _gestures.find(d);
|
||||
|
||||
if(it != _gestures.end()) {
|
||||
if(pressed()) {
|
||||
auto current = toDirection(_x, _y);
|
||||
if(it->second)
|
||||
it->second->release(current == d);
|
||||
}
|
||||
}
|
||||
|
||||
auto dir_name = fromDirection(d);
|
||||
|
||||
_gestures[d].reset();
|
||||
try {
|
||||
_gestures[d] = Gesture::makeGesture(
|
||||
_device, type, _config.gestures.value()[dir_name],
|
||||
_node->make_child(dir_name));
|
||||
} catch (InvalidGesture& e) {
|
||||
_gestures[d] = Gesture::makeGesture(
|
||||
_device, _config.gestures.value()[dir_name],
|
||||
_node->make_child(dir_name));
|
||||
throw std::invalid_argument("Invalid gesture type");
|
||||
}
|
||||
}
|
||||
|
@ -51,21 +51,14 @@ namespace actions {
|
||||
|
||||
virtual uint8_t reprogFlags() const;
|
||||
|
||||
void setGesture(const std::string& direction,
|
||||
const std::string& type);
|
||||
protected:
|
||||
int16_t _x, _y;
|
||||
std::shared_ptr<ipcgull::node> _node;
|
||||
std::map<Direction, std::shared_ptr<Gesture>> _gestures;
|
||||
config::GestureAction& _config;
|
||||
|
||||
private:
|
||||
class IPC : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
explicit IPC(GestureAction* action);
|
||||
private:
|
||||
GestureAction& _action;
|
||||
};
|
||||
|
||||
std::shared_ptr<IPC> _ipc;
|
||||
mutable std::mutex _config_lock;
|
||||
};
|
||||
}}
|
||||
|
||||
|
@ -24,15 +24,48 @@
|
||||
using namespace logid::actions;
|
||||
using namespace logid::backend;
|
||||
|
||||
const char* KeypressAction::interface_name =
|
||||
"pizza.pixl.LogiOps.Action.Keypress";
|
||||
const char* KeypressAction::interface_name = "Keypress";
|
||||
|
||||
KeypressAction::KeypressAction(Device *device, config::KeypressAction& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action(device), _config (config)
|
||||
KeypressAction::KeypressAction(
|
||||
Device *device, config::KeypressAction& config,
|
||||
[[maybe_unused]] const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action(device, interface_name, {
|
||||
{
|
||||
{"GetKeys", {this, &KeypressAction::getKeys, {"keys"}}},
|
||||
{"SetKeys", {this, &KeypressAction::setKeys, {"keys"}}}
|
||||
}, {}, {}
|
||||
}), _config (config)
|
||||
{
|
||||
if(std::holds_alternative<std::string>(_config.keys)) {
|
||||
const auto& key = std::get<std::string>(_config.keys);
|
||||
_setConfig();
|
||||
}
|
||||
|
||||
void KeypressAction::press()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_config_lock);
|
||||
_pressed = true;
|
||||
for(auto& key : _keys)
|
||||
_device->virtualInput()->pressKey(key);
|
||||
}
|
||||
|
||||
void KeypressAction::release()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_config_lock);
|
||||
_pressed = false;
|
||||
for(auto& key : _keys)
|
||||
_device->virtualInput()->releaseKey(key);
|
||||
}
|
||||
|
||||
void KeypressAction::_setConfig()
|
||||
{
|
||||
_keys.clear();
|
||||
|
||||
if(!_config.keys.has_value())
|
||||
return;
|
||||
|
||||
auto& config = _config.keys.value();
|
||||
|
||||
if(std::holds_alternative<std::string>(config)) {
|
||||
const auto& key = std::get<std::string>(config);
|
||||
try {
|
||||
auto code = _device->virtualInput()->toKeyCode(key);
|
||||
_device->virtualInput()->registerKey(code);
|
||||
@ -40,14 +73,14 @@ KeypressAction::KeypressAction(Device *device, config::KeypressAction& config,
|
||||
} catch(InputDevice::InvalidEventCode& e) {
|
||||
logPrintf(WARN, "Invalid keycode %s, skipping.", key.c_str());
|
||||
}
|
||||
} else if(std::holds_alternative<uint>(_config.keys)) {
|
||||
const auto& key = std::get<uint>(_config.keys);
|
||||
} else if(std::holds_alternative<uint>(_config.keys.value())) {
|
||||
const auto& key = std::get<uint>(config);
|
||||
_device->virtualInput()->registerKey(key);
|
||||
_keys.emplace_back(key);
|
||||
} else if(std::holds_alternative<std::list<std::variant<uint, std::string
|
||||
>>>(_config.keys)) {
|
||||
const auto& keys = std::get<std::list<std::variant<uint, std::string>>>(
|
||||
_config.keys);
|
||||
} else if(std::holds_alternative<
|
||||
std::list<std::variant<uint, std::string>>>(config)) {
|
||||
const auto& keys = std::get<
|
||||
std::list<std::variant<uint, std::string>>>(config);
|
||||
for(const auto& key : keys) {
|
||||
if(std::holds_alternative<std::string>(key)) {
|
||||
const auto& key_str = std::get<std::string>(key);
|
||||
@ -66,22 +99,6 @@ KeypressAction::KeypressAction(Device *device, config::KeypressAction& config,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_ipc = parent->make_interface<IPC>(this);
|
||||
}
|
||||
|
||||
void KeypressAction::press()
|
||||
{
|
||||
_pressed = true;
|
||||
for(auto& key : _keys)
|
||||
_device->virtualInput()->pressKey(key);
|
||||
}
|
||||
|
||||
void KeypressAction::release()
|
||||
{
|
||||
_pressed = false;
|
||||
for(auto& key : _keys)
|
||||
_device->virtualInput()->releaseKey(key);
|
||||
}
|
||||
|
||||
uint8_t KeypressAction::reprogFlags() const
|
||||
@ -89,7 +106,26 @@ uint8_t KeypressAction::reprogFlags() const
|
||||
return hidpp20::ReprogControls::TemporaryDiverted;
|
||||
}
|
||||
|
||||
KeypressAction::IPC::IPC(KeypressAction *action) : ipcgull::interface(
|
||||
interface_name, {}, {}, {}), _action (*action)
|
||||
std::vector<std::string> KeypressAction::getKeys() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_config_lock);
|
||||
std::vector<std::string> ret;
|
||||
for(auto& x : _keys)
|
||||
ret.push_back(InputDevice::toKeyName(x));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void KeypressAction::setKeys(const std::vector<std::string> &keys)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_config_lock);
|
||||
if(_pressed)
|
||||
for(auto& key : _keys)
|
||||
_device->virtualInput()->releaseKey(key);
|
||||
_config.keys = std::list<std::variant<uint, std::string>>();
|
||||
auto& config = std::get<std::list<std::variant<uint, std::string>>>(
|
||||
_config.keys.value());
|
||||
for(auto& x : keys)
|
||||
config.emplace_back(x);
|
||||
_setConfig();
|
||||
}
|
||||
|
@ -36,20 +36,16 @@ namespace actions {
|
||||
virtual void press();
|
||||
virtual void release();
|
||||
|
||||
[[nodiscard]] std::vector<std::string> getKeys() const;
|
||||
void setKeys(const std::vector<std::string>& keys);
|
||||
|
||||
virtual uint8_t reprogFlags() const;
|
||||
protected:
|
||||
mutable std::mutex _config_lock;
|
||||
config::KeypressAction& _config;
|
||||
std::list<uint> _keys;
|
||||
private:
|
||||
class IPC : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
explicit IPC(KeypressAction* action);
|
||||
private:
|
||||
KeypressAction& _action;
|
||||
};
|
||||
|
||||
std::shared_ptr<IPC> _ipc;
|
||||
void _setConfig();
|
||||
};
|
||||
}}
|
||||
|
||||
|
@ -21,12 +21,12 @@
|
||||
|
||||
using namespace logid::actions;
|
||||
|
||||
const char* NullAction::interface_name =
|
||||
"pizza.pixl.LogiOps.Action.None";
|
||||
const char* NullAction::interface_name = "None";
|
||||
|
||||
NullAction::NullAction(Device* device,
|
||||
const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action(device), _ipc (parent->make_interface<IPC>())
|
||||
NullAction::NullAction(
|
||||
Device* device,
|
||||
[[maybe_unused]] const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action(device, interface_name)
|
||||
{
|
||||
}
|
||||
|
||||
@ -43,8 +43,4 @@ void NullAction::release()
|
||||
uint8_t NullAction::reprogFlags() const
|
||||
{
|
||||
return backend::hidpp20::ReprogControls::TemporaryDiverted;
|
||||
}
|
||||
|
||||
NullAction::IPC::IPC() : ipcgull::interface(interface_name, {}, {}, {})
|
||||
{
|
||||
}
|
||||
}
|
@ -38,12 +38,6 @@ namespace actions
|
||||
virtual void release();
|
||||
|
||||
virtual uint8_t reprogFlags() const;
|
||||
private:
|
||||
class IPC : public ipcgull::interface {
|
||||
public:
|
||||
IPC();
|
||||
};
|
||||
std::shared_ptr<IPC> _ipc;
|
||||
};
|
||||
}}
|
||||
|
||||
|
@ -23,12 +23,12 @@
|
||||
using namespace logid::actions;
|
||||
using namespace logid::backend;
|
||||
|
||||
const char* ToggleHiresScroll::interface_name =
|
||||
"pizza.pixl.LogiOps.Action.ToggleHiresScroll";
|
||||
const char* ToggleHiresScroll::interface_name = "ToggleHiresScroll";
|
||||
|
||||
ToggleHiresScroll::ToggleHiresScroll(
|
||||
Device *dev, const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action (dev), _ipc (parent->make_interface<IPC>())
|
||||
Device *dev,
|
||||
[[maybe_unused]] const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action (dev, interface_name)
|
||||
{
|
||||
_hires_scroll = _device->getFeature<features::HiresScroll>("hiresscroll");
|
||||
if(!_hires_scroll)
|
||||
@ -61,7 +61,3 @@ uint8_t ToggleHiresScroll::reprogFlags() const
|
||||
{
|
||||
return hidpp20::ReprogControls::TemporaryDiverted;
|
||||
}
|
||||
|
||||
ToggleHiresScroll::IPC::IPC() : ipcgull::interface(interface_name, {}, {}, {})
|
||||
{
|
||||
}
|
||||
|
@ -41,14 +41,6 @@ namespace actions
|
||||
virtual uint8_t reprogFlags() const;
|
||||
protected:
|
||||
std::shared_ptr<features::HiresScroll> _hires_scroll;
|
||||
private:
|
||||
class IPC : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
IPC();
|
||||
};
|
||||
|
||||
std::shared_ptr<IPC> _ipc;
|
||||
};
|
||||
}}
|
||||
|
||||
|
@ -23,12 +23,12 @@
|
||||
using namespace logid::actions;
|
||||
using namespace logid::backend;
|
||||
|
||||
const char* ToggleSmartShift::interface_name =
|
||||
"pizza.pixl.LogiOps.Action.ToggleSmartShift";
|
||||
const char* ToggleSmartShift::interface_name = "ToggleSmartShift";
|
||||
|
||||
ToggleSmartShift::ToggleSmartShift(
|
||||
Device *dev, const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action (dev), _ipc (parent->make_interface<IPC>())
|
||||
Device *dev,
|
||||
[[maybe_unused]] const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Action (dev, interface_name)
|
||||
{
|
||||
_smartshift = _device->getFeature<features::SmartShift>("smartshift");
|
||||
if(!_smartshift)
|
||||
@ -61,7 +61,3 @@ uint8_t ToggleSmartShift::reprogFlags() const
|
||||
{
|
||||
return hidpp20::ReprogControls::TemporaryDiverted;
|
||||
}
|
||||
|
||||
ToggleSmartShift::IPC::IPC() : ipcgull::interface(interface_name, {}, {}, {})
|
||||
{
|
||||
}
|
||||
|
@ -42,14 +42,6 @@ namespace actions {
|
||||
virtual uint8_t reprogFlags() const;
|
||||
protected:
|
||||
std::shared_ptr<features::SmartShift> _smartshift;
|
||||
private:
|
||||
class IPC : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
IPC();
|
||||
};
|
||||
|
||||
std::shared_ptr<IPC> _ipc;
|
||||
};
|
||||
}}
|
||||
|
||||
|
@ -23,24 +23,29 @@
|
||||
|
||||
using namespace logid::actions;
|
||||
|
||||
const char* AxisGesture::interface_name = "Axis";
|
||||
|
||||
AxisGesture::AxisGesture(Device *device, config::AxisGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction) :
|
||||
Gesture (device, parent, direction), _multiplier (1), _config (config)
|
||||
const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Gesture (device, parent, interface_name), _multiplier (1), _config (config)
|
||||
{
|
||||
if(std::holds_alternative<uint>(_config.axis)) {
|
||||
_input_axis = std::get<uint>(_config.axis);
|
||||
} else {
|
||||
const auto& axis = std::get<std::string>(_config.axis);
|
||||
try {
|
||||
_input_axis = _device->virtualInput()->toAxisCode(axis);
|
||||
_device->virtualInput()->registerAxis(_input_axis);
|
||||
} catch(InputDevice::InvalidEventCode& e) {
|
||||
logPrintf(WARN, "Invalid axis %s.");
|
||||
throw InvalidGesture();
|
||||
if(_config.axis.has_value()) {
|
||||
if(std::holds_alternative<uint>(_config.axis.value())) {
|
||||
_input_axis = std::get<uint>(_config.axis.value());
|
||||
} else {
|
||||
const auto& axis = std::get<std::string>(_config.axis.value());
|
||||
try {
|
||||
_input_axis = _device->virtualInput()->toAxisCode(axis);
|
||||
_device->virtualInput()->registerAxis(_input_axis.value());
|
||||
} catch(InputDevice::InvalidEventCode& e) {
|
||||
logPrintf(WARN, "Invalid axis %s.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
_device->virtualInput()->registerAxis(_input_axis);
|
||||
|
||||
if(_input_axis.has_value())
|
||||
_device->virtualInput()->registerAxis(_input_axis.value());
|
||||
}
|
||||
|
||||
void AxisGesture::press(bool init_threshold)
|
||||
@ -59,6 +64,9 @@ void AxisGesture::release(bool primary)
|
||||
|
||||
void AxisGesture::move(int16_t axis)
|
||||
{
|
||||
if(!_input_axis.has_value())
|
||||
return;
|
||||
|
||||
const auto threshold = _config.threshold.value_or(
|
||||
defaults::gesture_threshold);
|
||||
int16_t new_axis = _axis+axis;
|
||||
@ -90,7 +98,7 @@ void AxisGesture::move(int16_t axis)
|
||||
|
||||
if(low_res_axis != -1) {
|
||||
int lowres_movement = 0, hires_movement = move_floor;
|
||||
_device->virtualInput()->moveAxis(_input_axis, hires_movement);
|
||||
_device->virtualInput()->moveAxis(_input_axis.value(), hires_movement);
|
||||
hires_remainder += hires_movement;
|
||||
if(abs(hires_remainder) >= 60) {
|
||||
lowres_movement = hires_remainder/120;
|
||||
@ -102,7 +110,7 @@ void AxisGesture::move(int16_t axis)
|
||||
|
||||
_hires_remainder = hires_remainder;
|
||||
} else {
|
||||
_device->virtualInput()->moveAxis(_input_axis, move_floor);
|
||||
_device->virtualInput()->moveAxis(_input_axis.value(), move_floor);
|
||||
}
|
||||
}
|
||||
_axis = new_axis;
|
||||
|
@ -26,9 +26,10 @@ namespace logid {
|
||||
class AxisGesture : public Gesture
|
||||
{
|
||||
public:
|
||||
static const char* interface_name;
|
||||
|
||||
AxisGesture(Device* device, config::AxisGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction);
|
||||
const std::shared_ptr<ipcgull::node>& parent);
|
||||
|
||||
virtual void press(bool init_threshold=false);
|
||||
virtual void release(bool primary=false);
|
||||
@ -43,7 +44,7 @@ namespace logid {
|
||||
int16_t _axis;
|
||||
double _axis_remainder;
|
||||
int _hires_remainder;
|
||||
uint _input_axis;
|
||||
std::optional<uint> _input_axis;
|
||||
double _multiplier;
|
||||
config::AxisGesture& _config;
|
||||
};
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include "Gesture.h"
|
||||
#include "ReleaseGesture.h"
|
||||
#include "ThresholdGesture.h"
|
||||
@ -28,9 +29,10 @@ using namespace logid;
|
||||
using namespace logid::actions;
|
||||
|
||||
Gesture::Gesture(Device *device,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction) : _device (device),
|
||||
_node (parent->make_child(direction))
|
||||
std::shared_ptr<ipcgull::node> node,
|
||||
const std::string& name, tables t) :
|
||||
ipcgull::interface("pizza.pixl.LogiOps.Gesture." + name, std::move(t)),
|
||||
_node (std::move(node)), _device (device)
|
||||
{
|
||||
}
|
||||
|
||||
@ -48,20 +50,41 @@ struct gesture_type<T&> : gesture_type<T> { };
|
||||
template <typename T>
|
||||
std::shared_ptr<Gesture> _makeGesture(
|
||||
Device* device, T gesture,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction) {
|
||||
return std::make_shared<typename gesture_type<T>::type>(
|
||||
device, gesture, parent, std::move(direction));
|
||||
const std::shared_ptr<ipcgull::node>& parent) {
|
||||
return parent->make_interface<typename gesture_type<T>::type>(
|
||||
device, gesture, parent);
|
||||
}
|
||||
|
||||
std::shared_ptr<Gesture> Gesture::makeGesture(
|
||||
Device *device, config::Gesture& gesture,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction)
|
||||
const std::shared_ptr<ipcgull::node>& parent)
|
||||
{
|
||||
std::shared_ptr<Gesture> ret;
|
||||
std::visit([&device, &ret, &parent, &direction](auto&& x) {
|
||||
ret = _makeGesture(device, x, parent, direction);
|
||||
return std::visit([&device, &parent](auto&& x) {
|
||||
return _makeGesture(device, x, parent);
|
||||
}, gesture);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<Gesture> Gesture::makeGesture(
|
||||
Device *device, const std::string& type,
|
||||
config::Gesture& config,
|
||||
const std::shared_ptr<ipcgull::node> &parent)
|
||||
{
|
||||
if(type == AxisGesture::interface_name) {
|
||||
config = config::AxisGesture();
|
||||
return makeGesture(device, config, parent);
|
||||
} else if(type == IntervalGesture::interface_name) {
|
||||
config = config::IntervalGesture();
|
||||
return makeGesture(device, config, parent);
|
||||
} else if(type == ReleaseGesture::interface_name) {
|
||||
config = config::IntervalGesture();
|
||||
return makeGesture(device, config, parent);
|
||||
} else if(type == ThresholdGesture::interface_name) {
|
||||
config = config::ThresholdGesture();
|
||||
return makeGesture(device, config, parent);
|
||||
} else if(type == NullGesture::interface_name) {
|
||||
config = config::NoGesture();
|
||||
return makeGesture(device, config, parent);
|
||||
}
|
||||
|
||||
throw InvalidGesture();
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ namespace actions
|
||||
std::string _what;
|
||||
};
|
||||
|
||||
class Gesture
|
||||
class Gesture : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
virtual void press(bool init_threshold=false) = 0;
|
||||
@ -53,15 +53,19 @@ namespace actions
|
||||
|
||||
static std::shared_ptr<Gesture> makeGesture(Device* device,
|
||||
config::Gesture& gesture,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction);
|
||||
const std::shared_ptr<ipcgull::node>& parent);
|
||||
|
||||
static std::shared_ptr<Gesture> makeGesture(
|
||||
Device* device, const std::string& type,
|
||||
config::Gesture& gesture,
|
||||
const std::shared_ptr<ipcgull::node>& parent);
|
||||
|
||||
protected:
|
||||
explicit Gesture(Device* device,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction);
|
||||
Gesture(Device* device,
|
||||
std::shared_ptr<ipcgull::node> parent,
|
||||
const std::string& name, tables t={});
|
||||
const std::shared_ptr<ipcgull::node> _node;
|
||||
Device* _device;
|
||||
std::shared_ptr<ipcgull::node> _node;
|
||||
};
|
||||
}}
|
||||
|
||||
|
@ -21,10 +21,13 @@
|
||||
|
||||
using namespace logid::actions;
|
||||
|
||||
IntervalGesture::IntervalGesture(Device *device, config::IntervalGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction) :
|
||||
Gesture (device, parent, direction), _config (config)
|
||||
const char* IntervalGesture::interface_name = "OnInterval";
|
||||
|
||||
IntervalGesture::IntervalGesture(
|
||||
Device *device, config::IntervalGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Gesture (device, parent, interface_name),
|
||||
_axis (0), _interval_pass_count (0), _config (config)
|
||||
{
|
||||
if(config.action) {
|
||||
try {
|
||||
@ -50,6 +53,9 @@ void IntervalGesture::release(bool primary)
|
||||
|
||||
void IntervalGesture::move(int16_t axis)
|
||||
{
|
||||
if(!_config.interval.has_value())
|
||||
return;
|
||||
|
||||
const auto threshold =
|
||||
_config.threshold.value_or(defaults::gesture_threshold);
|
||||
_axis += axis;
|
||||
@ -57,7 +63,7 @@ void IntervalGesture::move(int16_t axis)
|
||||
return;
|
||||
|
||||
int16_t new_interval_count = (_axis - threshold)/
|
||||
_config.interval;
|
||||
_config.interval.value();
|
||||
if(new_interval_count > _interval_pass_count) {
|
||||
if(_action) {
|
||||
_action->press();
|
||||
|
@ -26,9 +26,10 @@ namespace actions
|
||||
class IntervalGesture : public Gesture
|
||||
{
|
||||
public:
|
||||
static const char* interface_name;
|
||||
|
||||
IntervalGesture(Device* device, config::IntervalGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction);
|
||||
const std::shared_ptr<ipcgull::node>& parent);
|
||||
|
||||
virtual void press(bool init_threshold=false);
|
||||
virtual void release(bool primary=false);
|
||||
@ -42,6 +43,18 @@ namespace actions
|
||||
int16_t _interval_pass_count;
|
||||
std::shared_ptr<Action> _action;
|
||||
config::IntervalGesture& _config;
|
||||
private:
|
||||
class IPC : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
IPC(IntervalGesture* parent);
|
||||
|
||||
void setAction(const std::string& type);
|
||||
void setInterval(int interval);
|
||||
void setThreshold(int threshold);
|
||||
private:
|
||||
IntervalGesture& parent;
|
||||
};
|
||||
};
|
||||
}}
|
||||
|
||||
|
@ -20,11 +20,12 @@
|
||||
|
||||
using namespace logid::actions;
|
||||
|
||||
const char* NullGesture::interface_name = "None";
|
||||
|
||||
NullGesture::NullGesture(Device *device,
|
||||
config::NoGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction) :
|
||||
Gesture (device, parent, direction), _config (config)
|
||||
const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Gesture (device, parent, interface_name), _config (config)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -26,10 +26,11 @@ namespace actions
|
||||
class NullGesture : public Gesture
|
||||
{
|
||||
public:
|
||||
static const char* interface_name;
|
||||
|
||||
NullGesture(Device* device,
|
||||
config::NoGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction);
|
||||
const std::shared_ptr<ipcgull::node>& parent);
|
||||
|
||||
virtual void press(bool init_threshold=false);
|
||||
virtual void release(bool primary=false);
|
||||
|
@ -20,10 +20,11 @@
|
||||
|
||||
using namespace logid::actions;
|
||||
|
||||
const char* ReleaseGesture::interface_name = "OnRelease";
|
||||
|
||||
ReleaseGesture::ReleaseGesture(Device *device, config::ReleaseGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction) :
|
||||
Gesture (device, parent, direction), _config (config)
|
||||
const std::shared_ptr<ipcgull::node>& parent) :
|
||||
Gesture (device, parent, interface_name), _config (config)
|
||||
{
|
||||
if(_config.action.has_value())
|
||||
_action = Action::makeAction(device, _config.action.value(), _node);
|
||||
|
@ -26,9 +26,10 @@ namespace actions
|
||||
class ReleaseGesture : public Gesture
|
||||
{
|
||||
public:
|
||||
static const char* interface_name;
|
||||
|
||||
ReleaseGesture(Device* device, config::ReleaseGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction);
|
||||
const std::shared_ptr<ipcgull::node>& parent);
|
||||
|
||||
virtual void press(bool init_threshold=false);
|
||||
virtual void release(bool primary=false);
|
||||
|
@ -20,11 +20,12 @@
|
||||
|
||||
using namespace logid::actions;
|
||||
|
||||
ThresholdGesture::ThresholdGesture(Device *device,
|
||||
config::ThresholdGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction) :
|
||||
Gesture (device, parent, direction), _config (config)
|
||||
const char* ThresholdGesture::interface_name = "OnRelease";
|
||||
|
||||
ThresholdGesture::ThresholdGesture(
|
||||
Device *device, config::ThresholdGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent ) :
|
||||
Gesture (device, parent, interface_name), _config (config)
|
||||
{
|
||||
if(config.action) {
|
||||
try {
|
||||
|
@ -26,9 +26,10 @@ namespace actions
|
||||
class ThresholdGesture : public Gesture
|
||||
{
|
||||
public:
|
||||
static const char* interface_name;
|
||||
|
||||
ThresholdGesture(Device* device, config::ThresholdGesture& config,
|
||||
const std::shared_ptr<ipcgull::node>& parent,
|
||||
const std::string& direction);
|
||||
const std::shared_ptr<ipcgull::node>& parent);
|
||||
|
||||
virtual void press(bool init_threshold=false);
|
||||
virtual void release(bool primary=false);
|
||||
|
@ -85,9 +85,7 @@ IOMonitor::~IOMonitor() noexcept
|
||||
|
||||
void IOMonitor::_listen()
|
||||
{
|
||||
std::unique_lock<std::mutex> run_lock(_run_lock, std::try_to_lock);
|
||||
if(!run_lock.owns_lock())
|
||||
throw std::runtime_error("IOMonitor already listening");
|
||||
std::lock_guard<std::mutex> run_lock(_run_lock);
|
||||
std::vector<struct epoll_event> events;
|
||||
|
||||
_is_running = true;
|
||||
@ -130,7 +128,7 @@ void IOMonitor::_stop() noexcept
|
||||
bool IOMonitor::_running() const
|
||||
{
|
||||
std::unique_lock<std::mutex> run_lock(_run_lock, std::try_to_lock);
|
||||
return !run_lock.owns_lock();
|
||||
return !run_lock.owns_lock() || _is_running;
|
||||
}
|
||||
|
||||
void IOMonitor::add(int fd, IOHandler handler)
|
||||
|
@ -34,7 +34,7 @@ namespace logid::config {
|
||||
void set(libconfig::Setting& parent, const T& t);
|
||||
|
||||
template <typename T>
|
||||
T get(const libconfig::Setting& parent, const std::string& name);
|
||||
auto get(const libconfig::Setting& parent, const std::string& name);
|
||||
|
||||
template <typename T>
|
||||
void append(libconfig::Setting& list, const T& t);
|
||||
@ -189,7 +189,7 @@ namespace logid::config {
|
||||
}
|
||||
|
||||
void _save(libconfig::Setting& setting) const override {
|
||||
set(setting, _signature, _sig_field);
|
||||
set(setting, _sig_field, _signature);
|
||||
_setter(setting, this, _names);
|
||||
}
|
||||
|
||||
|
@ -33,13 +33,27 @@ namespace logid::config {
|
||||
char value[N];
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct less_caseless {
|
||||
constexpr bool operator()(const T& a, const T& b) const noexcept {
|
||||
auto a_it = a.begin(), b_it = b.begin();
|
||||
for(; a_it != a.end() && b_it != b.end(); ++a_it, ++b_it) {
|
||||
if(tolower(*a_it) != tolower(*b_it))
|
||||
return tolower(*a_it) < tolower(*b_it);
|
||||
}
|
||||
return b_it != b.end();
|
||||
}
|
||||
};
|
||||
|
||||
// Warning: map must be a variant of groups or a group
|
||||
template <typename K, typename V, string_literal KeyName>
|
||||
class map : public std::map<K, V> {
|
||||
template <typename K, typename V, string_literal KeyName,
|
||||
typename Compare=typename std::map<K, V>::key_compare,
|
||||
typename Allocator=typename std::map<K, V>::allocator_type>
|
||||
class map : public std::map<K, V, Compare, Allocator> {
|
||||
public:
|
||||
template <typename... Args>
|
||||
map(Args... args) :
|
||||
std::map<K, V>(std::forward<Args>(args)...) { }
|
||||
std::map<K, V, Compare, Allocator>(std::forward<Args>(args)...) { }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -46,11 +46,14 @@ namespace logid::config {
|
||||
|
||||
struct KeypressAction : public signed_group<std::string> {
|
||||
typedef actions::KeypressAction action;
|
||||
std::variant<std::string, uint,
|
||||
std::list<std::variant<uint, std::string>>> keys;
|
||||
std::optional<
|
||||
std::variant<std::string, uint,
|
||||
std::list<std::variant<uint, std::string>>>> keys;
|
||||
KeypressAction() : signed_group<std::string>(
|
||||
"type", "Keypress",
|
||||
{"keys"}, &KeypressAction::keys) { }
|
||||
{"keys"}, &KeypressAction::keys)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct ToggleSmartShift : public signed_group<std::string> {
|
||||
@ -67,7 +70,7 @@ namespace logid::config {
|
||||
|
||||
struct CycleDPI : public signed_group<std::string> {
|
||||
typedef actions::CycleDPI action;
|
||||
std::list<int> dpis;
|
||||
std::optional<std::list<int>> dpis;
|
||||
std::optional<int> sensor;
|
||||
CycleDPI() : signed_group<std::string>(
|
||||
"type", "CycleDPI",
|
||||
@ -78,7 +81,7 @@ namespace logid::config {
|
||||
|
||||
struct ChangeDPI : public signed_group<std::string> {
|
||||
typedef actions::ChangeDPI action;
|
||||
int inc;
|
||||
std::optional<int> inc;
|
||||
std::optional<int> sensor;
|
||||
ChangeDPI() : signed_group<std::string>(
|
||||
"type", "ChangeDPI",
|
||||
@ -89,7 +92,7 @@ namespace logid::config {
|
||||
|
||||
struct ChangeHost : public signed_group<std::string> {
|
||||
typedef actions::ChangeHostAction action;
|
||||
std::variant<int, std::string> host;
|
||||
std::optional<std::variant<int, std::string>> host;
|
||||
ChangeHost() : signed_group<std::string>(
|
||||
"type", "ChangeHost",
|
||||
{"host"}, &ChangeHost::host) { }
|
||||
@ -108,7 +111,7 @@ namespace logid::config {
|
||||
struct AxisGesture : public signed_group<std::string> {
|
||||
typedef actions::AxisGesture gesture;
|
||||
std::optional<int> threshold;
|
||||
std::variant<std::string, uint> axis;
|
||||
std::optional<std::variant<std::string, uint>> axis;
|
||||
std::optional<double> axis_multiplier;
|
||||
|
||||
AxisGesture() : signed_group("mode", "Axis",
|
||||
@ -122,7 +125,7 @@ namespace logid::config {
|
||||
typedef actions::IntervalGesture gesture;
|
||||
std::optional<int> threshold;
|
||||
std::optional<BasicAction> action;
|
||||
int interval;
|
||||
std::optional<int> interval;
|
||||
protected:
|
||||
IntervalGesture(const std::string& name) : signed_group(
|
||||
"mode", name,
|
||||
@ -180,7 +183,8 @@ namespace logid::config {
|
||||
|
||||
struct GestureAction : public signed_group<std::string> {
|
||||
typedef actions::GestureAction action;
|
||||
std::optional<map<std::string, Gesture, "direction">> gestures;
|
||||
std::optional<map<std::string, Gesture, "direction",
|
||||
less_caseless<std::string>>> gestures;
|
||||
|
||||
GestureAction() : signed_group<std::string>(
|
||||
"type", "Gestures",
|
||||
@ -263,12 +267,15 @@ namespace logid::config {
|
||||
};
|
||||
|
||||
struct Device : public group {
|
||||
std::string default_profile;
|
||||
ipcgull::property<std::string> default_profile;
|
||||
map<std::string, Profile, "name"> profiles;
|
||||
|
||||
Device() : group({"default_profile", "profiles"},
|
||||
&Device::default_profile,
|
||||
&Device::profiles) { }
|
||||
&Device::profiles),
|
||||
default_profile(ipcgull::property_full_permissions, "")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct Config : public group {
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <variant>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <ipcgull/property.h>
|
||||
#include "group.h"
|
||||
#include "map.h"
|
||||
#include "../util/log.h"
|
||||
@ -74,6 +75,9 @@ namespace logid::config {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct config_io<ipcgull::property<T>> : public config_io<T> { };
|
||||
|
||||
template <typename T, libconfig::Setting::Type TypeEnum>
|
||||
struct primitive_io {
|
||||
static T get(const libconfig::Setting& parent,
|
||||
@ -328,11 +332,13 @@ namespace logid::config {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V, string_literal KeyName>
|
||||
struct config_io<map<K, V, KeyName>> {
|
||||
static map<K, V, KeyName> get(const libconfig::Setting& setting) {
|
||||
template <typename K, typename V, string_literal KeyName,
|
||||
typename Cmp, typename Alloc>
|
||||
struct config_io<map<K, V, KeyName, Cmp, Alloc>> {
|
||||
static map<K, V, KeyName, Cmp, Alloc> get(
|
||||
const libconfig::Setting& setting) {
|
||||
const auto size = setting.getLength();
|
||||
map<K, V, KeyName> t;
|
||||
map<K, V, KeyName, Cmp, Alloc> t;
|
||||
for(int i = 0; i < size; ++i) {
|
||||
auto& s = setting[i];
|
||||
try {
|
||||
@ -343,13 +349,13 @@ namespace logid::config {
|
||||
return t;
|
||||
}
|
||||
|
||||
static map<K, V, KeyName> get(const libconfig::Setting& parent,
|
||||
const std::string& name) {
|
||||
static map<K, V, KeyName, Cmp, Alloc> get(
|
||||
const libconfig::Setting& parent, const std::string& name) {
|
||||
return get(parent.lookup(name));
|
||||
}
|
||||
|
||||
static void set(libconfig::Setting& setting,
|
||||
const map<K, V, KeyName>& t) {
|
||||
const map<K, V, KeyName, Cmp, Alloc>& t) {
|
||||
while(setting.getLength() != 0)
|
||||
setting.remove((int)0);
|
||||
for(auto& x : t) {
|
||||
@ -361,7 +367,7 @@ namespace logid::config {
|
||||
|
||||
static void set(libconfig::Setting& parent,
|
||||
const std::string& name,
|
||||
const map<K, V, KeyName>& t) {
|
||||
const map<K, V, KeyName, Cmp, Alloc>& t) {
|
||||
if (!parent.exists(name)) {
|
||||
parent.add(name, libconfig::Setting::TypeList);
|
||||
} else if(!parent.lookup(name).isArray()) {
|
||||
@ -372,7 +378,7 @@ namespace logid::config {
|
||||
}
|
||||
|
||||
static void append(libconfig::Setting& list,
|
||||
const map<K, V, KeyName>& t) {
|
||||
const map<K, V, KeyName, Cmp, Alloc>& t) {
|
||||
auto& s = list.add(libconfig::Setting::TypeList);
|
||||
set(s, t);
|
||||
}
|
||||
@ -428,16 +434,16 @@ namespace logid::config {
|
||||
|
||||
template <typename T>
|
||||
void append(libconfig::Setting& list, const T& t) {
|
||||
config_io<T>::set(list, t);
|
||||
config_io<T>::append(list, t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T get(const libconfig::Setting& setting) {
|
||||
auto get(const libconfig::Setting& setting) {
|
||||
return config_io<T>::get(setting);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T get(const libconfig::Setting& parent, const std::string& name) {
|
||||
auto get(const libconfig::Setting& parent, const std::string& name) {
|
||||
return config_io<T>::get(parent, name);
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ void HiresScroll::_makeAction(std::shared_ptr<actions::Gesture> &gesture,
|
||||
{
|
||||
if(config.has_value()) {
|
||||
gesture = actions::Gesture::makeGesture(_device, config.value(),
|
||||
_node, direction);
|
||||
_node->make_child(direction));
|
||||
try {
|
||||
auto axis = std::dynamic_pointer_cast<actions::AxisGesture>(
|
||||
gesture);
|
||||
|
@ -16,6 +16,7 @@
|
||||
*
|
||||
*/
|
||||
#include <sstream>
|
||||
#include "../actions/GestureAction.h"
|
||||
#include "../Device.h"
|
||||
#include "RemapButton.h"
|
||||
#include "../backend/hidpp20/Error.h"
|
||||
@ -67,14 +68,14 @@ RemapButton::RemapButton(Device *dev): DeviceFeature(dev),
|
||||
}
|
||||
_reprog_controls->setControlReporting(info.controlID, report);
|
||||
};
|
||||
_buttons.emplace(std::piecewise_construct,
|
||||
std::forward_as_tuple(control.second.controlID),
|
||||
std::forward_as_tuple(control.second, i,
|
||||
_device, func,
|
||||
_ipc_node,
|
||||
_config.value()[control.first]));
|
||||
_buttons.emplace(control.second.controlID,
|
||||
Button::make(control.second, i,
|
||||
_device, func, _ipc_node,
|
||||
_config.value()[control.first]));
|
||||
}
|
||||
|
||||
_ipc_interface = _device->ipcNode()->make_interface<IPC>(this);
|
||||
|
||||
if(global_loglevel <= DEBUG) {
|
||||
#define FLAG(x) (control.second.flags & hidpp20::ReprogControls::x ? \
|
||||
"YES" : "")
|
||||
@ -104,7 +105,7 @@ RemapButton::~RemapButton()
|
||||
void RemapButton::configure()
|
||||
{
|
||||
for(const auto& button : _buttons)
|
||||
button.second.configure();
|
||||
button.second->configure();
|
||||
}
|
||||
|
||||
void RemapButton::listen()
|
||||
@ -127,8 +128,8 @@ void RemapButton::listen()
|
||||
else { // RawXY
|
||||
auto divertedXY = _reprog_controls->divertedRawXYEvent(report);
|
||||
for(const auto& button : this->_buttons)
|
||||
if(button.second.pressed())
|
||||
button.second.move(divertedXY.x, divertedXY.y);
|
||||
if(button.second->pressed())
|
||||
button.second->move(divertedXY.x, divertedXY.y);
|
||||
}
|
||||
};
|
||||
|
||||
@ -149,7 +150,7 @@ void RemapButton::_buttonEvent(const std::set<uint16_t>& new_state)
|
||||
} else {
|
||||
auto action = _buttons.find(i);
|
||||
if(action != _buttons.end())
|
||||
action->second.press();
|
||||
action->second->press();
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,12 +158,34 @@ void RemapButton::_buttonEvent(const std::set<uint16_t>& new_state)
|
||||
for(auto& i : _pressed_buttons) {
|
||||
auto action = _buttons.find(i);
|
||||
if(action != _buttons.end())
|
||||
action->second.release();
|
||||
action->second->release();
|
||||
}
|
||||
|
||||
_pressed_buttons = new_state;
|
||||
}
|
||||
|
||||
namespace logid::features {
|
||||
class _Button : public Button {
|
||||
public:
|
||||
template <typename... Args>
|
||||
explicit _Button(Args&&... args) : Button(std::forward<Args&&>(args)...)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
std::shared_ptr<Button> Button::make(
|
||||
Info info, int index, Device *device, ConfigFunction conf_func,
|
||||
std::shared_ptr<ipcgull::node> root, config::Button &config)
|
||||
{
|
||||
auto ret = std::make_shared<_Button>(info, index, device, std::move(conf_func),
|
||||
std::move(root), config);
|
||||
ret->_self = ret;
|
||||
ret->_node->manage(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Button::Button(Info info, int index,
|
||||
Device *device, ConfigFunction conf_func,
|
||||
std::shared_ptr<ipcgull::node> root,
|
||||
@ -184,36 +207,55 @@ Button::Button(Info info, int index,
|
||||
_interface = _node->make_interface<IPC>(this, _info);
|
||||
}
|
||||
|
||||
void Button::press() const {
|
||||
void Button::press() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_action_lock);
|
||||
if(_action)
|
||||
_action->press();
|
||||
}
|
||||
|
||||
void Button::release() const {
|
||||
void Button::release() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_action_lock);
|
||||
if(_action)
|
||||
_action->release();
|
||||
}
|
||||
|
||||
void Button::move(int16_t x, int16_t y) const {
|
||||
void Button::move(int16_t x, int16_t y) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_action_lock);
|
||||
if(_action)
|
||||
_action->move(x, y);
|
||||
}
|
||||
|
||||
bool Button::pressed() const {
|
||||
bool Button::pressed() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_action_lock);
|
||||
if(_action)
|
||||
return _action->pressed();
|
||||
return false;
|
||||
}
|
||||
|
||||
void Button::configure() const {
|
||||
void Button::configure() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_action_lock);
|
||||
_conf_func(_action);
|
||||
}
|
||||
|
||||
std::shared_ptr<ipcgull::node> Button::node() const
|
||||
{
|
||||
return _node;
|
||||
}
|
||||
|
||||
Button::IPC::IPC(Button* parent,
|
||||
const Info& info) :
|
||||
ipcgull::interface("pizza.pixl.LogiOps.Device.Button", {}, {
|
||||
ipcgull::interface("pizza.pixl.LogiOps.Device.Button", {
|
||||
{"SetAction", {this, &IPC::setAction, {"type"}}}
|
||||
}, {
|
||||
{"ControlID", ipcgull::property<uint16_t>(
|
||||
ipcgull::property_readable, info.controlID)},
|
||||
{"TaskID", ipcgull::property<uint16_t>(
|
||||
ipcgull::property_readable, info.taskID)},
|
||||
{"Remappable", ipcgull::property<const bool>(
|
||||
ipcgull::property_readable,
|
||||
info.flags & hidpp20::ReprogControls::TemporaryDivertable)},
|
||||
@ -221,6 +263,41 @@ Button::IPC::IPC(Button* parent,
|
||||
ipcgull::property_readable,
|
||||
(info.additionalFlags & hidpp20::ReprogControls::RawXY)
|
||||
)}
|
||||
}, {})
|
||||
}, {}), _button (*parent)
|
||||
{
|
||||
}
|
||||
|
||||
void Button::IPC::setAction(const std::string &type)
|
||||
{
|
||||
if(!(_button._info.flags & hidpp20::ReprogControls::TemporaryDivertable))
|
||||
throw std::invalid_argument("Non-remappable");
|
||||
|
||||
if(type == GestureAction::interface_name &&
|
||||
!(_button._info.additionalFlags & hidpp20::ReprogControls::RawXY))
|
||||
throw std::invalid_argument("No gesture support");
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_button._action_lock);
|
||||
_button._action.reset();
|
||||
_button._action = Action::makeAction(
|
||||
_button._device,type,
|
||||
_button._config.action, _button._node);
|
||||
}
|
||||
_button.configure();
|
||||
}
|
||||
|
||||
RemapButton::IPC::IPC(RemapButton* parent) :
|
||||
ipcgull::interface("pizza.pixl.LogiOps.Buttons", {
|
||||
{"Enumerate", {this, &IPC::enumerate, {"buttons"}}}
|
||||
}, {}, {}),
|
||||
_parent (*parent)
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Button>> RemapButton::IPC::enumerate() const
|
||||
{
|
||||
std::vector<std::shared_ptr<Button>> ret;
|
||||
for(auto& x : _parent._buttons)
|
||||
ret.push_back(x.second);
|
||||
return ret;
|
||||
}
|
||||
|
@ -27,30 +27,42 @@ namespace features
|
||||
{
|
||||
class RemapButton;
|
||||
|
||||
class Button
|
||||
class Button : public ipcgull::object
|
||||
{
|
||||
public:
|
||||
typedef backend::hidpp20::ReprogControls::ControlInfo Info;
|
||||
typedef std::function<void(std::shared_ptr<actions::Action>)>
|
||||
ConfigFunction;
|
||||
|
||||
Button(Info info, int index,
|
||||
Device* device, ConfigFunction conf_func,
|
||||
std::shared_ptr<ipcgull::node> root,
|
||||
config::Button& config);
|
||||
static std::shared_ptr<Button> make(
|
||||
Info info, int index, Device* device, ConfigFunction conf_func,
|
||||
std::shared_ptr<ipcgull::node> root, config::Button& config);
|
||||
|
||||
void press() const;
|
||||
void release() const;
|
||||
void move(int16_t x, int16_t y) const;
|
||||
|
||||
[[nodiscard]] std::shared_ptr<ipcgull::node> node() const;
|
||||
|
||||
void configure() const;
|
||||
|
||||
bool pressed() const;
|
||||
private:
|
||||
friend class _Button;
|
||||
|
||||
Button(Info info, int index,
|
||||
Device* device, ConfigFunction conf_func,
|
||||
std::shared_ptr<ipcgull::node> root,
|
||||
config::Button& config);
|
||||
|
||||
class IPC : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
IPC(Button* parent,
|
||||
const Info& info);
|
||||
void setAction(const std::string& type);
|
||||
private:
|
||||
Button& _button;
|
||||
};
|
||||
|
||||
std::shared_ptr<ipcgull::node> _node;
|
||||
@ -60,8 +72,11 @@ namespace features
|
||||
|
||||
config::Button& _config;
|
||||
|
||||
mutable std::mutex _action_lock;
|
||||
std::shared_ptr<actions::Action> _action;
|
||||
const Info _info;
|
||||
|
||||
std::weak_ptr<Button> _self;
|
||||
};
|
||||
|
||||
class RemapButton : public DeviceFeature
|
||||
@ -79,9 +94,20 @@ namespace features
|
||||
std::mutex _button_lock;
|
||||
|
||||
std::optional<config::RemapButton>& _config;
|
||||
std::map<uint16_t, Button> _buttons;
|
||||
std::map<uint16_t, std::shared_ptr<Button>> _buttons;
|
||||
|
||||
std::shared_ptr<ipcgull::node> _ipc_node;
|
||||
|
||||
class IPC : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
IPC(RemapButton* parent);
|
||||
std::vector<std::shared_ptr<Button>> enumerate() const;
|
||||
private:
|
||||
RemapButton& _parent;
|
||||
};
|
||||
|
||||
std::shared_ptr<IPC> _ipc_interface;
|
||||
};
|
||||
}}
|
||||
|
||||
|
@ -30,13 +30,15 @@ SmartShift::SmartShift(Device* device) : DeviceFeature(device),
|
||||
} catch (hidpp20::UnsupportedFeature& e) {
|
||||
throw UnsupportedFeature();
|
||||
}
|
||||
|
||||
_ipc = _device->ipcNode()->make_interface<IPC>(this);
|
||||
}
|
||||
|
||||
void SmartShift::configure()
|
||||
{
|
||||
if(_config.has_value()) {
|
||||
const auto& conf = _config.value();
|
||||
hidpp20::SmartShift::SmartshiftStatus settings {};
|
||||
Status settings {};
|
||||
settings.setActive = conf.on.has_value();
|
||||
if(settings.setActive)
|
||||
settings.active = conf.on.value();
|
||||
@ -52,13 +54,97 @@ void SmartShift::listen()
|
||||
{
|
||||
}
|
||||
|
||||
hidpp20::SmartShift::SmartshiftStatus SmartShift::getStatus()
|
||||
SmartShift::Status SmartShift::getStatus() const
|
||||
{
|
||||
return _smartshift->getStatus();
|
||||
}
|
||||
|
||||
void SmartShift::setStatus(backend::hidpp20::SmartShift::SmartshiftStatus
|
||||
status)
|
||||
void SmartShift::setStatus(Status status)
|
||||
{
|
||||
_smartshift->setStatus(status);
|
||||
}
|
||||
|
||||
SmartShift::IPC::IPC(SmartShift *parent) :
|
||||
ipcgull::interface(
|
||||
"pizza.pixl.LogiOps.SmartShift", {
|
||||
{"GetStatus", {this, &IPC::getStatus, {"active", "threshold"}}},
|
||||
{"SetActive", {this, &IPC::setActive, {"active"}}},
|
||||
{"SetThreshold", {this, &IPC::setThreshold, {"threshold"}}},
|
||||
{"GetDefault",
|
||||
{this, &IPC::getDefault,
|
||||
{"setActive", "active", "setThreshold", "threshold"}}},
|
||||
{"ClearDefaultActive", {this, &IPC::clearDefaultActive}},
|
||||
{"SetDefaultActive",
|
||||
{this, &IPC::setDefaultActive, {"active"}}},
|
||||
{"ClearDefaultThreshold", {this, &IPC::clearDefaultThreshold}},
|
||||
{"SetDefaultThreshold",
|
||||
{this, &IPC::setDefaultThreshold, {"threshold"}}}
|
||||
}, {}, {}),
|
||||
_parent (*parent)
|
||||
{
|
||||
}
|
||||
|
||||
std::tuple<bool, uint8_t> SmartShift::IPC::getStatus() const
|
||||
{
|
||||
auto ret = _parent.getStatus();
|
||||
return std::make_tuple(ret.active, ret.autoDisengage);
|
||||
}
|
||||
|
||||
void SmartShift::IPC::setActive(bool active)
|
||||
{
|
||||
Status status {};
|
||||
status.setActive = true;
|
||||
status.active = active;
|
||||
_parent.setStatus(status);
|
||||
}
|
||||
|
||||
void SmartShift::IPC::setThreshold(uint8_t threshold)
|
||||
{
|
||||
Status status {};
|
||||
status.setAutoDisengage = true;
|
||||
status.autoDisengage = threshold;
|
||||
_parent.setStatus(status);
|
||||
}
|
||||
|
||||
std::tuple<bool, bool, bool, uint8_t> SmartShift::IPC::getDefault() const
|
||||
{
|
||||
if(!_parent._config.has_value())
|
||||
return {false, false, false, 0};
|
||||
|
||||
std::tuple<bool, bool, bool, uint8_t> ret;
|
||||
std::get<0>(ret) = _parent._config.value().on.has_value();
|
||||
if(std::get<0>(ret))
|
||||
std::get<1>(ret) = _parent._config.value().on.value();
|
||||
std::get<2>(ret) = _parent._config.value().threshold.has_value();
|
||||
if(std::get<2>(ret))
|
||||
std::get<3>(ret) = _parent._config.value().threshold.value();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SmartShift::IPC::clearDefaultActive()
|
||||
{
|
||||
if(_parent._config.has_value())
|
||||
_parent._config.value().on.reset();
|
||||
}
|
||||
|
||||
void SmartShift::IPC::setDefaultActive(bool active)
|
||||
{
|
||||
if(!_parent._config.has_value())
|
||||
_parent._config = config::SmartShift{};
|
||||
_parent._config.value().on = active;
|
||||
}
|
||||
|
||||
|
||||
void SmartShift::IPC::clearDefaultThreshold()
|
||||
{
|
||||
if(_parent._config.has_value())
|
||||
_parent._config.value().threshold.reset();
|
||||
}
|
||||
|
||||
void SmartShift::IPC::setDefaultThreshold(uint8_t threshold)
|
||||
{
|
||||
if(!_parent._config.has_value())
|
||||
_parent._config = config::SmartShift{};
|
||||
_parent._config.value().threshold = threshold;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#ifndef LOGID_FEATURE_SMARTSHIFT_H
|
||||
#define LOGID_FEATURE_SMARTSHIFT_H
|
||||
|
||||
#include <ipcgull/interface.h>
|
||||
#include "../backend/hidpp20/features/SmartShift.h"
|
||||
#include "DeviceFeature.h"
|
||||
#include "../config/schema.h"
|
||||
@ -32,12 +33,34 @@ namespace features
|
||||
virtual void configure();
|
||||
virtual void listen();
|
||||
|
||||
backend::hidpp20::SmartShift::SmartshiftStatus getStatus();
|
||||
void setStatus(backend::hidpp20::SmartShift::SmartshiftStatus status);
|
||||
typedef backend::hidpp20::SmartShift::SmartshiftStatus Status;
|
||||
|
||||
[[nodiscard]] Status getStatus() const;
|
||||
void setStatus(Status status);
|
||||
|
||||
private:
|
||||
std::optional<config::SmartShift>& _config;
|
||||
std::shared_ptr<backend::hidpp20::SmartShift> _smartshift;
|
||||
|
||||
class IPC : public ipcgull::interface
|
||||
{
|
||||
public:
|
||||
IPC(SmartShift* parent);
|
||||
|
||||
[[nodiscard]] std::tuple<bool, uint8_t> getStatus() const;;
|
||||
void setActive(bool active);
|
||||
void setThreshold(uint8_t threshold);
|
||||
|
||||
[[nodiscard]] std::tuple<bool, bool, bool, uint8_t> getDefault() const;
|
||||
void clearDefaultActive();
|
||||
void setDefaultActive(bool active);
|
||||
void clearDefaultThreshold();
|
||||
void setDefaultThreshold(uint8_t threshold);
|
||||
private:
|
||||
SmartShift& _parent;
|
||||
};
|
||||
|
||||
std::shared_ptr<IPC> _ipc;
|
||||
};
|
||||
}}
|
||||
|
||||
|
@ -50,7 +50,8 @@ std::shared_ptr<actions::Gesture> _genGesture(
|
||||
{
|
||||
if(conf.has_value()) {
|
||||
try {
|
||||
return actions::Gesture::makeGesture(dev, conf.value(), parent, direction);
|
||||
return actions::Gesture::makeGesture(
|
||||
dev, conf.value(), parent->make_child(direction));
|
||||
} catch (actions::InvalidAction &e) {
|
||||
logPrintf(WARN, "Mapping thumb wheel to invalid gesture");
|
||||
}
|
||||
@ -61,6 +62,7 @@ std::shared_ptr<actions::Gesture> _genGesture(
|
||||
|
||||
ThumbWheel::ThumbWheel(Device *dev) : DeviceFeature(dev), _wheel_info(),
|
||||
_node (dev->ipcNode()->make_child("thumbwheel")),
|
||||
_gesture_node (_node->make_child("scroll")),
|
||||
_proxy_node (_node->make_child("proxy")),
|
||||
_tap_node (_node->make_child("tap")),
|
||||
_touch_node (_node->make_child("touch")),
|
||||
@ -68,8 +70,8 @@ ThumbWheel::ThumbWheel(Device *dev) : DeviceFeature(dev), _wheel_info(),
|
||||
{
|
||||
if(_config.has_value()) {
|
||||
auto& conf = _config.value();
|
||||
_left_action = _genGesture(dev, conf.left, _node, "left");
|
||||
_right_action = _genGesture(dev, conf.right, _node, "right");
|
||||
_left_action = _genGesture(dev, conf.left, _gesture_node, "left");
|
||||
_right_action = _genGesture(dev, conf.right, _gesture_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);
|
||||
@ -114,7 +116,8 @@ ThumbWheel::ThumbWheel(Device *dev) : DeviceFeature(dev), _wheel_info(),
|
||||
}
|
||||
}
|
||||
|
||||
ThumbWheel::~ThumbWheel() {
|
||||
ThumbWheel::~ThumbWheel()
|
||||
{
|
||||
_device->hidpp20().removeEventHandler(SCROLL_EVENTHANDLER_NAME);
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ namespace features
|
||||
backend::hidpp20::ThumbWheel::ThumbwheelInfo _wheel_info;
|
||||
|
||||
std::shared_ptr<ipcgull::node> _node;
|
||||
std::shared_ptr<ipcgull::node> _gesture_node;
|
||||
|
||||
std::shared_ptr<actions::Gesture> _left_action;
|
||||
std::shared_ptr<actions::Gesture> _right_action;
|
||||
|
Loading…
Reference in New Issue
Block a user