END_TEST START_TEST(device_group_ref) { struct libinput *li = litest_create_context(); struct litest_device *dev = litest_add_device(li, LITEST_MOUSE); struct libinput_device *device = dev->libinput_device; struct libinput_device_group *group; group = libinput_device_get_device_group(device); ck_assert_notnull(group); libinput_device_group_ref(group); libinput_device_ref(device); litest_drain_events(li); litest_delete_device(dev); litest_drain_events(li); /* make sure the device is dead but the group is still around */ ck_assert(libinput_device_unref(device) == NULL); libinput_device_group_ref(group); ck_assert_notnull(libinput_device_group_unref(group)); ck_assert(libinput_device_group_unref(group) == NULL); libinput_unref(li); }
END_TEST START_TEST(device_reenable_device_removed) { struct libinput *li; struct litest_device *litest_device; struct libinput_device *device; enum libinput_config_status status; li = litest_create_context(); litest_device = litest_add_device(li, LITEST_MOUSE); device = litest_device->libinput_device; libinput_device_ref(device); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_delete_device(litest_device); litest_drain_events(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* can't really check for much here, this really just exercises the code path. */ litest_assert_empty_queue(li); libinput_device_unref(device); libinput_unref(li); }
END_TEST START_TEST(device_reenable_syspath_changed) { struct libinput *li; struct litest_device *litest_device; struct libinput_device *device1, *device2; enum libinput_config_status status; struct libinput_event *event; li = litest_create_context(); litest_device = litest_add_device(li, LITEST_MOUSE); device1 = litest_device->libinput_device; libinput_device_ref(device1); status = libinput_device_config_send_events_set_mode(device1, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_delete_device(litest_device); litest_drain_events(li); litest_device = litest_add_device(li, LITEST_MOUSE); device2 = litest_device->libinput_device; /* Note: if the sysname isn't the same, some other device got added * or removed while this test was running. This is unlikely and * would result in a false positive, so let's fail the test here */ ck_assert_str_eq(libinput_device_get_sysname(device1), libinput_device_get_sysname(device2)); status = libinput_device_config_send_events_set_mode(device1, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* can't really check for much here, other than that if we pump events through libinput, none of them should be from the first device */ litest_event(litest_device, EV_REL, REL_X, 1); litest_event(litest_device, EV_REL, REL_Y, 1); litest_event(litest_device, EV_SYN, SYN_REPORT, 0); libinput_dispatch(li); while ((event = libinput_get_event(li))) { ck_assert(libinput_event_get_device(event) != device1); libinput_event_destroy(event); } litest_delete_device(litest_device); libinput_device_unref(device1); libinput_unref(li); }
static void clutter_input_device_evdev_finalize (GObject *object) { ClutterInputDevice *device = CLUTTER_INPUT_DEVICE (object); ClutterInputDeviceEvdev *device_evdev = CLUTTER_INPUT_DEVICE_EVDEV (object); ClutterDeviceManagerEvdev *manager_evdev = CLUTTER_DEVICE_MANAGER_EVDEV (device->device_manager); if (device_evdev->libinput_device) libinput_device_unref (device_evdev->libinput_device); _clutter_device_manager_evdev_release_device_id (manager_evdev, device); G_OBJECT_CLASS (clutter_input_device_evdev_parent_class)->finalize (object); }
static void clutter_input_device_evdev_finalize (GObject *object) { ClutterInputDevice *device = CLUTTER_INPUT_DEVICE (object); ClutterInputDeviceEvdev *device_evdev = CLUTTER_INPUT_DEVICE_EVDEV (object); ClutterDeviceManagerEvdev *manager_evdev = CLUTTER_DEVICE_MANAGER_EVDEV (device->device_manager); if (device_evdev->libinput_device) libinput_device_unref (device_evdev->libinput_device); clutter_input_device_evdev_release_touch_slots (device_evdev, g_get_monotonic_time ()); _clutter_device_manager_evdev_release_device_id (manager_evdev, device); clear_slow_keys (device_evdev); stop_bounce_keys (device_evdev); stop_toggle_slowkeys (device_evdev); stop_mousekeys_move (device_evdev); G_OBJECT_CLASS (clutter_input_device_evdev_parent_class)->finalize (object); }
END_TEST START_TEST(path_add_device_suspend_resume_remove_device) { struct libinput *li; struct libinput_device *device; struct libinput_event *event; struct libevdev_uinput *uinput1, *uinput2; int rc; int nevents; void *userdata = &rc; uinput1 = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); uinput2 = litest_create_uinput_device("test device 2", 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, userdata); ck_assert(li != NULL); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput1)); ck_assert(device != NULL); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput2)); libinput_device_ref(device); libinput_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); libinput_event_destroy(event); nevents++; } ck_assert_int_eq(nevents, 2); libinput_suspend(li); libinput_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_REMOVED); libinput_event_destroy(event); nevents++; } ck_assert_int_eq(nevents, 2); /* now drop and remove one of the devices */ libevdev_uinput_destroy(uinput2); libinput_path_remove_device(device); libinput_device_unref(device); rc = libinput_resume(li); ck_assert_int_eq(rc, 0); libinput_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); libinput_event_destroy(event); nevents++; } ck_assert_int_eq(nevents, 1); libevdev_uinput_destroy(uinput1); libinput_unref(li); open_func_count = 0; close_func_count = 0; }
END_TEST START_TEST(path_seat_change) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_device *device; struct libinput_seat *seat1, *seat2; const char *seat1_name; const char *seat2_name = "new seat"; int rc; libinput_dispatch(li); event = libinput_get_event(li); ck_assert_int_eq(libinput_event_get_type(event), LIBINPUT_EVENT_DEVICE_ADDED); device = libinput_event_get_device(event); libinput_device_ref(device); seat1 = libinput_device_get_seat(device); libinput_seat_ref(seat1); seat1_name = libinput_seat_get_logical_name(seat1); libinput_event_destroy(event); litest_drain_events(li); rc = libinput_device_set_seat_logical_name(device, seat2_name); ck_assert_int_eq(rc, 0); libinput_dispatch(li); event = libinput_get_event(li); ck_assert(event != NULL); ck_assert_int_eq(libinput_event_get_type(event), LIBINPUT_EVENT_DEVICE_REMOVED); ck_assert(libinput_event_get_device(event) == device); libinput_event_destroy(event); event = libinput_get_event(li); ck_assert(event != NULL); ck_assert_int_eq(libinput_event_get_type(event), LIBINPUT_EVENT_DEVICE_ADDED); ck_assert(libinput_event_get_device(event) != device); libinput_device_unref(device); device = libinput_event_get_device(event); seat2 = libinput_device_get_seat(device); ck_assert_str_ne(libinput_seat_get_logical_name(seat2), seat1_name); ck_assert_str_eq(libinput_seat_get_logical_name(seat2), seat2_name); libinput_event_destroy(event); libinput_seat_unref(seat1); /* litest: swap the new device in, so cleanup works */ libinput_device_unref(dev->libinput_device); libinput_device_ref(device); dev->libinput_device = device; }