| 41 | } |
| 42 | |
| 43 | InputDevice::InputDevice(const char* name) { |
| 44 | device = libevdev_new(); |
| 45 | libevdev_set_name(device, name); |
| 46 | |
| 47 | libevdev_enable_event_type(device, EV_KEY); |
| 48 | for (unsigned int i = 0; i < KEY_CNT; i++) { |
| 49 | // Enable some keys which a normal keyboard should have |
| 50 | // by default, i.e. a-z, modifier keys and so on, see: |
| 51 | // /usr/include/linux/input-event-codes.h |
| 52 | if (i < 128) { |
| 53 | registered_keys[i] = true; |
| 54 | libevdev_enable_event_code(device, EV_KEY, i, nullptr); |
| 55 | } else { |
| 56 | registered_keys[i] = false; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | for (bool& axis: registered_axis) |
| 61 | axis = false; |
| 62 | |
| 63 | libevdev_enable_event_type(device, EV_REL); |
| 64 | |
| 65 | int err = libevdev_uinput_create_from_device(device, |
| 66 | LIBEVDEV_UINPUT_OPEN_MANAGED, &ui_device); |
| 67 | |
| 68 | if (err != 0) { |
| 69 | libevdev_free(device); |
| 70 | throw std::system_error(-err, std::generic_category()); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | InputDevice::~InputDevice() { |
| 75 | libevdev_uinput_destroy(ui_device); |
nothing calls this directly
no outgoing calls
no test coverage detected