evdev: remove device when it is gone

This was observed when running in device mode with:
`libinput debug-events $EVENT_NODE`

When removing the monitored device, the no "device removed" message was
not shown.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
This commit is contained in:
Thomas Weißschuh 2021-06-21 00:34:37 +02:00 committed by Peter Hutterer
parent 17783c24df
commit b7aac3c148
2 changed files with 40 additions and 0 deletions

View file

@ -1080,6 +1080,9 @@ evdev_device_dispatch(void *data)
once = true;
}
evdev_device_dispatch_one(device, &ev);
} else if (rc == -ENODEV) {
evdev_device_remove(device);
return;
}
} while (rc == LIBEVDEV_READ_STATUS_SUCCESS);

View file

@ -904,6 +904,42 @@ START_TEST(path_add_device_suspend_resume_remove_device)
}
END_TEST
START_TEST(path_device_gone)
{
struct libinput *li;
struct libinput_device *device;
struct libevdev_uinput *uinput;
struct libinput_event *event;
uinput = litest_create_uinput_device("test device", NULL,
EV_KEY, BTN_LEFT,
EV_KEY, BTN_RIGHT,
EV_REL, REL_X,
EV_REL, REL_Y,
-1);
li = libinput_path_create_context(&simple_interface, NULL);
ck_assert_notnull(li);
device = libinput_path_add_device(li,
libevdev_uinput_get_devnode(uinput));
ck_assert_notnull(device);
litest_drain_events(li);
libevdev_uinput_destroy(uinput);
libinput_dispatch(li);
event = libinput_get_event(li);
ck_assert_notnull(event);
litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_REMOVED);
libinput_event_destroy(event);
libinput_unref(li);
}
END_TEST
START_TEST(path_seat_recycle)
{
struct libinput *li;
@ -1036,6 +1072,7 @@ TEST_COLLECTION(path)
litest_add_no_device(path_add_invalid_path);
litest_add_for_device(path_remove_device, LITEST_SYNAPTICS_CLICKPAD_X220);
litest_add_for_device(path_double_remove_device, LITEST_SYNAPTICS_CLICKPAD_X220);
litest_add_no_device(path_device_gone);
litest_add_no_device(path_seat_recycle);
litest_add_for_device(path_udev_assign_seat, LITEST_SYNAPTICS_CLICKPAD_X220);