END_TEST START_TEST(path_added_seat) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_device *device; struct libinput_seat *seat; const char *seat_name; enum libinput_event_type type; libinput_dispatch(li); event = libinput_get_event(li); ck_assert(event != NULL); type = libinput_event_get_type(event); ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); device = libinput_event_get_device(event); seat = libinput_device_get_seat(device); ck_assert(seat != NULL); seat_name = libinput_seat_get_logical_name(seat); ck_assert_str_eq(seat_name, "default"); libinput_event_destroy(event); }
static struct udev_seat * get_udev_seat(struct udev_input *input, struct libinput_device *device) { struct libinput_seat *libinput_seat; const char *seat_name; libinput_seat = libinput_device_get_seat(device); seat_name = libinput_seat_get_logical_name(libinput_seat); return udev_seat_get_named(input, seat_name); }
END_TEST /** * This test only works if there's at least one device in the system that is * assigned the default seat. Should cover the 99% case. */ START_TEST(udev_added_seat_default) { struct libinput *li; struct libinput_event *event; struct udev *udev; struct libinput_device *device; struct libinput_seat *seat; const char *seat_name; enum libinput_event_type type; int default_seat_found = 0; 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 (!default_seat_found && (event = libinput_get_event(li))) { type = libinput_event_get_type(event); if (type != LIBINPUT_EVENT_DEVICE_ADDED) { libinput_event_destroy(event); continue; } device = libinput_event_get_device(event); seat = libinput_device_get_seat(device); ck_assert(seat != NULL); seat_name = libinput_seat_get_logical_name(seat); default_seat_found = !strcmp(seat_name, "default"); libinput_event_destroy(event); } ck_assert(default_seat_found); libinput_unref(li); udev_unref(udev); }
static void device_added(struct udev_input *input, struct libinput_device *libinput_device) { struct weston_compositor *c; struct evdev_device *device; struct weston_output *output; const char *seat_name; const char *output_name; struct libinput_seat *libinput_seat; struct weston_seat *seat; struct udev_seat *udev_seat; c = input->compositor; libinput_seat = libinput_device_get_seat(libinput_device); seat_name = libinput_seat_get_logical_name(libinput_seat); udev_seat = udev_seat_get_named(input, seat_name); if (!udev_seat) return; seat = &udev_seat->base; device = evdev_device_create(libinput_device, seat); if (device == NULL) return; udev_seat = (struct udev_seat *) seat; wl_list_insert(udev_seat->devices_list.prev, &device->link); if (seat->output && seat->pointer) weston_pointer_clamp(seat->pointer, &seat->pointer->x, &seat->pointer->y); output_name = libinput_device_get_output_name(libinput_device); if (output_name) { device->output_name = strdup(output_name); wl_list_for_each(output, &c->output_list, link) if (strcmp(output->name, device->output_name) == 0) evdev_device_set_output(device, output); } else if (device->output == NULL && !wl_list_empty(&c->output_list)) {
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; }
static void print_device_notify(struct libinput_event *ev) { struct libinput_device *dev = libinput_event_get_device(ev); struct libinput_seat *seat = libinput_device_get_seat(dev); struct libinput_device_group *group; double w, h; static int next_group_id = 0; intptr_t group_id; const char *devnode; char *str; group = libinput_device_get_device_group(dev); group_id = (intptr_t)libinput_device_group_get_user_data(group); if (!group_id) { group_id = ++next_group_id; libinput_device_group_set_user_data(group, (void*)group_id); } devnode = udev_device_get_devnode( libinput_device_get_udev_device(dev)); printf("Device: %s\n" "Kernel: %s\n" "Group: %d\n" "Seat: %s, %s\n", libinput_device_get_name(dev), devnode, (int)group_id, libinput_seat_get_physical_name(seat), libinput_seat_get_logical_name(seat)); if (libinput_device_get_size(dev, &w, &h) == 0) printf("Size: %.2fx%.2fmm\n", w, h); printf("Capabilities: "); if (libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_KEYBOARD)) printf("keyboard "); if (libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_POINTER)) printf("pointer "); if (libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_TOUCH)) printf("touch"); printf("\n"); printf("Tap-to-click: %s\n", tap_default(dev)); printf("Left-handed: %s\n", left_handed_default(dev)); printf("Nat.scrolling: %s\n", nat_scroll_default(dev)); str = calibration_default(dev); printf("Calibration: %s\n", str); free(str); str = scroll_defaults(dev); printf("Scroll methods: %s\n", str); free(str); str = click_defaults(dev); printf("Click methods: %s\n", str); free(str); printf("\n"); }