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); }
END_TEST START_TEST(path_add_device) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_device *device; const char *sysname1 = NULL, *sysname2 = NULL; libinput_dispatch(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_DEVICE_ADDED) { ck_assert(sysname1 == NULL); device = libinput_event_get_device(event); ck_assert(device != NULL); sysname1 = libinput_device_get_sysname(device); } libinput_event_destroy(event); } device = libinput_path_add_device(li, libevdev_uinput_get_devnode(dev->uinput)); ck_assert(device != NULL); libinput_dispatch(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_DEVICE_ADDED) { ck_assert(sysname2 == NULL); device = libinput_event_get_device(event); ck_assert(device != NULL); sysname2 = libinput_device_get_sysname(device); } libinput_event_destroy(event); } ck_assert_str_eq(sysname1, sysname2); libinput_event_destroy(event); }
END_TEST START_TEST(path_device_sysname) { struct litest_device *dev = litest_current_device(); struct libinput_event *ev; struct libinput_device *device; const char *sysname; enum libinput_event_type type; libinput_dispatch(dev->libinput); ev = libinput_get_event(dev->libinput); ck_assert_notnull(ev); type = libinput_event_get_type(ev); ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); device = libinput_event_get_device(ev); ck_assert_notnull(device); sysname = libinput_device_get_sysname(device); ck_assert(sysname != NULL && strlen(sysname) > 1); ck_assert(strchr(sysname, '/') == NULL); ck_assert_int_eq(strncmp(sysname, "event", 5), 0); libinput_event_destroy(ev); }
END_TEST START_TEST(udev_device_sysname) { struct libinput *li; struct libinput_event *ev; struct libinput_device *device; const char *sysname; struct udev *udev; udev = udev_new(); ck_assert(udev != NULL); li = libinput_udev_create_context(&simple_interface, NULL, udev); ck_assert(li != NULL); ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); libinput_dispatch(li); while ((ev = libinput_get_event(li))) { if (libinput_event_get_type(ev) != LIBINPUT_EVENT_DEVICE_ADDED) continue; device = libinput_event_get_device(ev); sysname = libinput_device_get_sysname(device); ck_assert(sysname != NULL && strlen(sysname) > 1); ck_assert(strchr(sysname, '/') == NULL); ck_assert_int_eq(strncmp(sysname, "event", 5), 0); libinput_event_destroy(ev); } libinput_unref(li); udev_unref(udev); }
/* * _clutter_input_device_evdev_new: * @manager: the device manager * @seat: the seat the device will belong to * @libinput_device: the libinput device * * Create a new ClutterInputDevice given a libinput device and associate * it with the provided seat. */ ClutterInputDevice * _clutter_input_device_evdev_new (ClutterDeviceManager *manager, ClutterSeatEvdev *seat, struct libinput_device *libinput_device) { ClutterInputDeviceEvdev *device; ClutterInputDeviceType type; ClutterDeviceManagerEvdev *manager_evdev; gchar *vendor, *product; gint device_id, n_rings = 0, n_strips = 0, n_groups = 1; gchar *node_path; gdouble width, height; type = _clutter_input_device_evdev_determine_type (libinput_device); vendor = g_strdup_printf ("%.4x", libinput_device_get_id_vendor (libinput_device)); product = g_strdup_printf ("%.4x", libinput_device_get_id_product (libinput_device)); manager_evdev = CLUTTER_DEVICE_MANAGER_EVDEV (manager); device_id = _clutter_device_manager_evdev_acquire_device_id (manager_evdev); node_path = g_strdup_printf ("/dev/input/%s", libinput_device_get_sysname (libinput_device)); if (libinput_device_has_capability (libinput_device, LIBINPUT_DEVICE_CAP_TABLET_PAD)) { n_rings = libinput_device_tablet_pad_get_num_rings (libinput_device); n_strips = libinput_device_tablet_pad_get_num_strips (libinput_device); n_groups = libinput_device_tablet_pad_get_num_mode_groups (libinput_device); } device = g_object_new (CLUTTER_TYPE_INPUT_DEVICE_EVDEV, "id", device_id, "name", libinput_device_get_name (libinput_device), "device-manager", manager, "device-type", type, "device-mode", CLUTTER_INPUT_MODE_SLAVE, "enabled", TRUE, "vendor-id", vendor, "product-id", product, "n-rings", n_rings, "n-strips", n_strips, "n-mode-groups", n_groups, "device-node", node_path, NULL); device->seat = seat; device->libinput_device = libinput_device; libinput_device_set_user_data (libinput_device, device); libinput_device_ref (libinput_device); g_free (vendor); g_free (product); g_free (node_path); if (libinput_device_get_size (libinput_device, &width, &height) == 0) device->device_aspect_ratio = width / height; return CLUTTER_INPUT_DEVICE (device); }
END_TEST START_TEST(path_add_device) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_device *device; char *sysname1 = NULL, *sysname2 = NULL; enum libinput_event_type type; libinput_dispatch(li); event = libinput_get_event(li); ck_assert_notnull(event); type = libinput_event_get_type(event); ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); device = libinput_event_get_device(event); ck_assert_notnull(device); sysname1 = strdup(libinput_device_get_sysname(device)); libinput_event_destroy(event); litest_assert_empty_queue(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(dev->uinput)); ck_assert(device != NULL); libinput_dispatch(li); event = libinput_get_event(li); ck_assert_notnull(event); type = libinput_event_get_type(event); ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); device = libinput_event_get_device(event); ck_assert_notnull(device); sysname2 = strdup(libinput_device_get_sysname(device)); libinput_event_destroy(event); ck_assert_str_eq(sysname1, sysname2); free(sysname1); free(sysname2); }
static void _device_calibration_set(Ecore_Drm_Evdev *edev) { const char *sysname; float cal[6]; const char *device; Eina_List *devices; const char *vals; enum libinput_config_status status; if ((!libinput_device_config_calibration_has_matrix(edev->device)) || (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0)) return; sysname = libinput_device_get_sysname(edev->device); devices = eeze_udev_find_by_subsystem_sysname("input", sysname); if (eina_list_count(devices) < 1) return; EINA_LIST_FREE(devices, device) { vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION"); if ((!vals) || (sscanf(vals, "%f %f %f %f %f %f", &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6)) goto cont; cal[2] /= edev->output->current_mode->width; cal[5] /= edev->output->current_mode->height; status = libinput_device_config_calibration_set_matrix(edev->device, cal); if (status != LIBINPUT_CONFIG_STATUS_SUCCESS) ERR("Failed to apply calibration"); cont: eina_stringshare_del(device); continue; }
/* * _clutter_input_device_evdev_new: * @manager: the device manager * @seat: the seat the device will belong to * @libinput_device: the libinput device * * Create a new ClutterInputDevice given a libinput device and associate * it with the provided seat. */ ClutterInputDevice * _clutter_input_device_evdev_new (ClutterDeviceManager *manager, ClutterSeatEvdev *seat, struct libinput_device *libinput_device) { ClutterInputDeviceEvdev *device; ClutterInputDeviceType type; ClutterDeviceManagerEvdev *manager_evdev; gchar *vendor, *product; gint device_id; type = _clutter_input_device_evdev_determine_type (libinput_device); vendor = g_strdup_printf ("%.4x", libinput_device_get_id_vendor (libinput_device)); product = g_strdup_printf ("%.4x", libinput_device_get_id_product (libinput_device)); manager_evdev = CLUTTER_DEVICE_MANAGER_EVDEV (manager); device_id = _clutter_device_manager_evdev_acquire_device_id (manager_evdev); device = g_object_new (CLUTTER_TYPE_INPUT_DEVICE_EVDEV, "id", device_id, "name", libinput_device_get_sysname (libinput_device), "device-manager", manager, "device-type", type, "device-mode", CLUTTER_INPUT_MODE_SLAVE, "enabled", TRUE, "vendor-id", vendor, "product-id", product, NULL); device->seat = seat; device->libinput_device = libinput_device; libinput_device_set_user_data (libinput_device, device); libinput_device_ref (libinput_device); g_free (vendor); g_free (product); return CLUTTER_INPUT_DEVICE (device); }