Merge pull request #185 from aragon999/feature/only-register-axes-if-used

Enable axis in virtual_input device only when needed
master
pixl 3 years ago committed by GitHub
commit 1f1a306334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 41
      src/logid/InputDevice.cpp
  2. 3
      src/logid/InputDevice.h
  3. 9
      src/logid/actions/gesture/AxisGesture.cpp

@ -77,24 +77,26 @@ InputDevice::~InputDevice()
void InputDevice::registerKey(uint code)
{
if (registered_keys[code]) {
// TODO: Maybe print error message, if wrong code is passed?
if(registered_keys[code] || code > KEY_CNT) {
return;
}
libevdev_uinput_destroy(ui_device);
_enableEvent(EV_KEY, code);
libevdev_enable_event_code(device, EV_KEY, code, nullptr);
int err = libevdev_uinput_create_from_device(device,
LIBEVDEV_UINPUT_OPEN_MANAGED, &ui_device);
registered_keys[code] = true;
}
if(err != 0) {
libevdev_free(device);
device = nullptr;
ui_device = nullptr;
throw std::system_error(-err, std::generic_category());
void InputDevice::registerAxis(uint axis)
{
// TODO: Maybe print error message, if wrong code is passed?
if(registered_axis[axis] || axis > REL_CNT) {
return;
}
registered_keys[code] = true;
_enableEvent(EV_REL, axis);
registered_axis[axis] = true;
}
void InputDevice::moveAxis(uint axis, int movement)
@ -148,6 +150,23 @@ uint InputDevice::_toEventCode(uint type, const std::string& name)
return code;
}
void InputDevice::_enableEvent(const uint type, const uint code)
{
libevdev_uinput_destroy(ui_device);
libevdev_enable_event_code(device, type, code, nullptr);
int err = libevdev_uinput_create_from_device(device,
LIBEVDEV_UINPUT_OPEN_MANAGED, &ui_device);
if(err != 0) {
libevdev_free(device);
device = nullptr;
ui_device = nullptr;
throw std::system_error(-err, std::generic_category());
}
}
void InputDevice::_sendEvent(uint type, uint code, int value)
{
libevdev_uinput_write_event(ui_device, type, code, value);

@ -45,6 +45,7 @@ namespace logid
~InputDevice();
void registerKey(uint code);
void registerAxis(uint axis);
void moveAxis(uint axis, int movement);
void pressKey(uint code);
void releaseKey(uint code);
@ -55,10 +56,12 @@ namespace logid
private:
void _sendEvent(uint type, uint code, int value);
void _enableEvent(uint type, uint name);
static uint _toEventCode(uint type, const std::string& name);
bool registered_keys[KEY_CNT];
bool registered_axis[REL_CNT];
libevdev* device;
libevdev_uinput* ui_device{};
};

@ -104,9 +104,11 @@ AxisGesture::Config::Config(Device *device, libconfig::Setting &setting) :
auto& axis = setting.lookup("axis");
if(axis.isNumber()) {
_axis = axis;
virtual_input->registerAxis(_axis);
} else if(axis.getType() == libconfig::Setting::TypeString) {
try {
_axis = virtual_input->toAxisCode(axis);
virtual_input->registerAxis(_axis);
} catch(InputDevice::InvalidEventCode& e) {
logPrintf(WARN, "Line %d: Invalid axis %s, skipping."
, axis.getSourceLine(), axis.c_str());
@ -138,8 +140,11 @@ AxisGesture::Config::Config(Device *device, libconfig::Setting &setting) :
// Ignore
}
if(InputDevice::getLowResAxis(_axis) != -1)
int low_res_axis = InputDevice::getLowResAxis(_axis);
if(low_res_axis != -1) {
_multiplier *= 120;
virtual_input->registerAxis(low_res_axis);
}
}
unsigned int AxisGesture::Config::axis() const
@ -168,4 +173,4 @@ void AxisGesture::Config::setHiresMultiplier(double multiplier)
}
_hires_multiplier = multiplier;
}
}

Loading…
Cancel
Save