Enable some keys by default and enable more on request
if the user chooses to use such keys in the config.
This commit is contained in:
parent
f8eb77cad7
commit
8280bc2505
|
@ -44,6 +44,18 @@ InputDevice::InputDevice(const char* name)
|
||||||
libevdev_set_name(device, name);
|
libevdev_set_name(device, name);
|
||||||
|
|
||||||
libevdev_enable_event_type(device, EV_KEY);
|
libevdev_enable_event_type(device, EV_KEY);
|
||||||
|
for (unsigned int i = 0; i < KEY_CNT; i++) {
|
||||||
|
// Enable some keys which a normal keyboard should have
|
||||||
|
// by default, i.e. a-z, modifier keys and so on, see:
|
||||||
|
// /usr/include/linux/input-event-codes.h
|
||||||
|
if (i < 128) {
|
||||||
|
registered_keys[i] = true;
|
||||||
|
libevdev_enable_event_code(device, EV_KEY, i, nullptr);
|
||||||
|
} else {
|
||||||
|
registered_keys[i] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -65,6 +77,12 @@ InputDevice::~InputDevice()
|
||||||
|
|
||||||
void InputDevice::registerKey(uint code)
|
void InputDevice::registerKey(uint code)
|
||||||
{
|
{
|
||||||
|
if (registered_keys[code]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
libevdev_uinput_destroy(ui_device);
|
||||||
|
|
||||||
libevdev_enable_event_code(device, EV_KEY, code, nullptr);
|
libevdev_enable_event_code(device, EV_KEY, code, nullptr);
|
||||||
int err = libevdev_uinput_create_from_device(device,
|
int err = libevdev_uinput_create_from_device(device,
|
||||||
LIBEVDEV_UINPUT_OPEN_MANAGED, &ui_device);
|
LIBEVDEV_UINPUT_OPEN_MANAGED, &ui_device);
|
||||||
|
@ -73,6 +91,8 @@ void InputDevice::registerKey(uint code)
|
||||||
libevdev_free(device);
|
libevdev_free(device);
|
||||||
throw std::system_error(-err, std::generic_category());
|
throw std::system_error(-err, std::generic_category());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registered_keys[code] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDevice::moveAxis(uint axis, int movement)
|
void InputDevice::moveAxis(uint axis, int movement)
|
||||||
|
|
|
@ -58,6 +58,7 @@ namespace logid
|
||||||
|
|
||||||
static uint _toEventCode(uint type, const std::string& name);
|
static uint _toEventCode(uint type, const std::string& name);
|
||||||
|
|
||||||
|
bool registered_keys[KEY_CNT];
|
||||||
libevdev* device;
|
libevdev* device;
|
||||||
libevdev_uinput* ui_device{};
|
libevdev_uinput* ui_device{};
|
||||||
};
|
};
|
||||||
|
@ -65,4 +66,4 @@ namespace logid
|
||||||
extern std::unique_ptr<InputDevice> virtual_input;
|
extern std::unique_ptr<InputDevice> virtual_input;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //LOGID_INPUTDEVICE_H
|
#endif //LOGID_INPUTDEVICE_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user