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