}
static int
+get_key_down_count(struct evdev_device *device, int code)
+{
+ return device->key_count[code];
+}
+
+static int
update_key_down_count(struct evdev_device *device, int code, int pressed)
{
int key_count;
return NULL;
libinput_device_init(&device->base, seat);
+ libinput_seat_ref(seat);
rc = libevdev_new_from_fd(fd, &device->evdev);
if (rc != 0)
- return NULL;
+ goto err;
libevdev_set_clock_id(device->evdev, CLOCK_MONOTONIC);
device->pending_event = EVDEV_NONE;
device->devname = libevdev_get_name(device->evdev);
- libinput_seat_ref(seat);
-
if (evdev_configure_device(device) == -1)
goto err;
return 0;
}
+static void
+release_pressed_keys(struct evdev_device *device)
+{
+ struct libinput *libinput = device->base.seat->libinput;
+ struct timespec ts;
+ uint64_t time;
+ int code;
+
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
+ log_bug_libinput(libinput, "clock_gettime: %s\n", strerror(errno));
+ return;
+ }
+
+ time = ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000;
+
+ for (code = 0; code < KEY_CNT; code++) {
+ if (get_key_down_count(device, code) > 0) {
+ switch (get_key_type(code)) {
+ case EVDEV_KEY_TYPE_NONE:
+ break;
+ case EVDEV_KEY_TYPE_KEY:
+ keyboard_notify_key(
+ &device->base,
+ time,
+ code,
+ LIBINPUT_KEY_STATE_RELEASED);
+ break;
+ case EVDEV_KEY_TYPE_BUTTON:
+ pointer_notify_button(
+ &device->base,
+ time,
+ code,
+ LIBINPUT_BUTTON_STATE_RELEASED);
+ break;
+ }
+ }
+ }
+}
+
void
evdev_device_remove(struct evdev_device *device)
{
libinput_remove_source(device->base.seat->libinput,
device->source);
+ release_pressed_keys(device);
+
if (device->mtdev)
mtdev_close_delete(device->mtdev);
close_restricted(device->base.seat->libinput, device->fd);