Register keys for keypress only when needed
there seems to be an issue that with too many registered events some window manager cannot recognize the device as input device with systemd 247. PixlOne#166
This commit is contained in:
parent
911e91eeeb
commit
f8eb77cad7
|
@ -43,12 +43,7 @@ InputDevice::InputDevice(const char* name)
|
||||||
device = libevdev_new();
|
device = libevdev_new();
|
||||||
libevdev_set_name(device, name);
|
libevdev_set_name(device, name);
|
||||||
|
|
||||||
///TODO: Is it really a good idea to enable all events?
|
|
||||||
libevdev_enable_event_type(device, EV_KEY);
|
libevdev_enable_event_type(device, EV_KEY);
|
||||||
// KEY_ROTATE_LOCK_TOGGLE is the highest key mapped by
|
|
||||||
// /usr/share/X11/xkb/keycodes/evdev
|
|
||||||
for(unsigned int i = 0; i <= KEY_ROTATE_LOCK_TOGGLE; i++)
|
|
||||||
libevdev_enable_event_code(device, EV_KEY, i, nullptr);
|
|
||||||
libevdev_enable_event_type(device, EV_REL);
|
libevdev_enable_event_type(device, EV_REL);
|
||||||
for(unsigned int i = 0; i < REL_CNT; i++)
|
for(unsigned int i = 0; i < REL_CNT; i++)
|
||||||
libevdev_enable_event_code(device, EV_REL, i, nullptr);
|
libevdev_enable_event_code(device, EV_REL, i, nullptr);
|
||||||
|
@ -68,6 +63,18 @@ InputDevice::~InputDevice()
|
||||||
libevdev_free(device);
|
libevdev_free(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputDevice::registerKey(uint code)
|
||||||
|
{
|
||||||
|
libevdev_enable_event_code(device, EV_KEY, code, nullptr);
|
||||||
|
int err = libevdev_uinput_create_from_device(device,
|
||||||
|
LIBEVDEV_UINPUT_OPEN_MANAGED, &ui_device);
|
||||||
|
|
||||||
|
if(err != 0) {
|
||||||
|
libevdev_free(device);
|
||||||
|
throw std::system_error(-err, std::generic_category());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void InputDevice::moveAxis(uint axis, int movement)
|
void InputDevice::moveAxis(uint axis, int movement)
|
||||||
{
|
{
|
||||||
_sendEvent(EV_REL, axis, movement);
|
_sendEvent(EV_REL, axis, movement);
|
||||||
|
|
|
@ -44,6 +44,7 @@ namespace logid
|
||||||
explicit InputDevice(const char *name);
|
explicit InputDevice(const char *name);
|
||||||
~InputDevice();
|
~InputDevice();
|
||||||
|
|
||||||
|
void registerKey(uint code);
|
||||||
void moveAxis(uint axis, int movement);
|
void moveAxis(uint axis, int movement);
|
||||||
void pressKey(uint code);
|
void pressKey(uint code);
|
||||||
void releaseKey(uint code);
|
void releaseKey(uint code);
|
||||||
|
|
|
@ -64,9 +64,11 @@ KeypressAction::Config::Config(Device* device, libconfig::Setting& config) :
|
||||||
auto& key = keys[i];
|
auto& key = keys[i];
|
||||||
if(key.isNumber()) {
|
if(key.isNumber()) {
|
||||||
_keys.push_back(key);
|
_keys.push_back(key);
|
||||||
|
virtual_input->registerKey(key);
|
||||||
} else if(key.getType() == libconfig::Setting::TypeString) {
|
} else if(key.getType() == libconfig::Setting::TypeString) {
|
||||||
try {
|
try {
|
||||||
_keys.push_back(virtual_input->toKeyCode(key));
|
_keys.push_back(virtual_input->toKeyCode(key));
|
||||||
|
virtual_input->registerKey(virtual_input->toKeyCode(key));
|
||||||
} catch(InputDevice::InvalidEventCode& e) {
|
} catch(InputDevice::InvalidEventCode& e) {
|
||||||
logPrintf(WARN, "Line %d: Invalid keycode %s, skipping."
|
logPrintf(WARN, "Line %d: Invalid keycode %s, skipping."
|
||||||
, key.getSourceLine(), key.c_str());
|
, key.getSourceLine(), key.c_str());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user