const struct libinput_interface *interface;
const struct libinput_interface_backend *interface_backend;
+
+ libinput_log_handler log_handler;
+ enum libinput_log_priority log_priority;
void *user_data;
+ int refcount;
};
typedef void (*libinput_seat_destroy_func) (struct libinput_seat *seat);
if (libinput_init(&input->base, interface,
&interface_backend, user_data) != 0) {
++ libinput_unref(&input->base);
free(input);
return NULL;
}
input->udev = udev_ref(udev);
+
+ return &input->base;
+}
+
+LIBINPUT_EXPORT int
+libinput_udev_assign_seat(struct libinput *libinput,
+ const char *seat_id)
+{
+ struct udev_input *input = (struct udev_input*)libinput;
+
+ if (!seat_id)
+ return -1;
+ if (input->seat_id != NULL)
+ return -1;
+
+ if (libinput->interface_backend != &interface_backend) {
+ log_bug_client(libinput, "Mismatching backends.\n");
+ return -1;
+ }
+
input->seat_id = strdup(seat_id);
- if (udev_input_enable(&input->base) < 0) {
- udev_unref(udev);
- libinput_unref(&input->base);
- free(input);
+ if (udev_input_enable(&input->base) < 0)
+ return -1;
+
+ return 0;
+}
+
+LIBINPUT_EXPORT struct libinput *
+libinput_udev_create_for_seat(const struct libinput_interface *interface,
+ void *user_data,
+ struct udev *udev,
+ const char *seat_id)
+{
+ struct libinput *libinput;
+
+ if (!interface || !udev || !seat_id)
return NULL;
- libinput_destroy(libinput);
+
+ libinput = libinput_udev_create_context(interface, user_data, udev);
+ if (!libinput)
+ return NULL;
+
+ if (libinput_udev_assign_seat(libinput, seat_id) != 0) {
++ libinput_unref(libinput);
+ libinput = NULL;
}
- return &input->base;
+ return libinput;
}
START_TEST(log_default_priority)
{
enum libinput_log_priority pri;
-
- pri = libinput_log_get_priority();
-
- ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR);
-}
-END_TEST
-
-START_TEST(log_handler_invoked)
-{
struct libinput *li;
- enum libinput_log_priority pri = libinput_log_get_priority();
-
- libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
- libinput_log_set_handler(simple_log_handler, NULL);
- log_handler_userdata = NULL;
li = libinput_path_create_context(&simple_interface, NULL);
- libinput_path_add_device(li, "/tmp");
+ pri = libinput_log_get_priority(li);
- ck_assert_int_gt(log_handler_called, 0);
- log_handler_called = 0;
+ ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR);
- libinput_destroy(li);
+ libinput_unref(li);
- libinput_log_set_priority(pri);
}
END_TEST
ck_assert_int_gt(log_handler_called, 0);
log_handler_called = 0;
- libinput_destroy(li);
+ libinput_unref(li);
- libinput_log_set_priority(pri);
+
+ log_handler_context = NULL;
}
END_TEST
ck_assert_int_eq(log_handler_called, 0);
log_handler_called = 0;
- libinput_log_set_handler(simple_log_handler, NULL);
- libinput_destroy(li);
+ libinput_unref(li);
- libinput_log_set_priority(pri);
}
END_TEST
log_handler_called = 0;
- libinput_destroy(li);
+ libinput_unref(li);
- libinput_log_set_priority(pri);
+ log_handler_context = NULL;
}
END_TEST
{
struct libinput *li;
const struct libinput_interface interface;
- struct udev *udev = (struct udev*)0xdeadbeef;
- const char *seat = (const char*)0xdeaddead;
+ struct udev *udev;
- li = libinput_udev_create_for_seat(NULL, NULL, NULL, NULL);
- ck_assert(li == NULL);
+ udev = udev_new();
- li = libinput_udev_create_for_seat(&interface, NULL, NULL, NULL);
- ck_assert(li == NULL);
- li = libinput_udev_create_for_seat(NULL, NULL, udev, NULL);
- ck_assert(li == NULL);
- li = libinput_udev_create_for_seat(NULL, NULL, NULL, seat);
+ li = libinput_udev_create_context(NULL, NULL, NULL);
ck_assert(li == NULL);
- li = libinput_udev_create_for_seat(&interface, NULL, udev, NULL);
- ck_assert(li == NULL);
- li = libinput_udev_create_for_seat(NULL, NULL, udev, seat);
+ li = libinput_udev_create_context(&interface, NULL, NULL);
ck_assert(li == NULL);
- li = libinput_udev_create_for_seat(&interface, NULL, NULL, seat);
+ li = libinput_udev_create_context(NULL, NULL, udev);
ck_assert(li == NULL);
- libinput_destroy(li);
+
+ li = libinput_udev_create_context(&interface, NULL, udev);
+ ck_assert(li != NULL);
+ ck_assert_int_eq(libinput_udev_assign_seat(li, NULL), -1);
++
++ libinput_unref(li);
+ udev_unref(udev);
}
END_TEST
return 1;
}
- libinput_destroy(*li);
+ if (verbose) {
+ libinput_log_set_handler(*li, log_handler);
+ libinput_log_set_priority(*li, LIBINPUT_LOG_PRIORITY_DEBUG);
+ }
+
+ if (libinput_udev_assign_seat(*li, seat)) {
+ fprintf(stderr, "Failed to set seat\n");
++ libinput_unref(*li);
+ return 1;
+ }
+
return 0;
}