void *user_data,
struct udev *udev,
const char *seat_id);
+
/**
* @ingroup base
*
- * Create a new libinput context from the given path. This context
- * represents one single device only, it will not respond to new devices
- * being added and reading from the device after it was removed will fail.
+ * Create a new libinput context that requires the caller to manually add or
+ * remove devices with libinput_path_add_device() and
+ * libinput_path_remove_device().
+ *
+ * The context is fully initialized but will not generate events until at
+ * least one device has been added.
*
* @param interface The callback interface
* @param user_data Caller-specific data passed to the various callback
* interfaces.
- * @param path Path to an input device
*
- * @return An initialized libinput context, ready to handle events or NULL on
- * error.
+ * @return An initialized, empty libinput context.
*/
struct libinput *
-libinput_create_from_path(const struct libinput_interface *interface,
- void *user_data,
- const char *path);
+libinput_path_create_context(const struct libinput_interface *interface,
+ void *user_data);
/**
* @ingroup base
};
LIBINPUT_EXPORT struct libinput *
-libinput_create_from_path(const struct libinput_interface *interface,
- void *user_data,
- const char *path)
+libinput_path_create_context(const struct libinput_interface *interface,
+ void *user_data)
{
struct path_input *input;
- struct path_device *dev;
- if (!interface || !path)
+ if (!interface)
return NULL;
input = zalloc(sizeof *input);
if (!input)
return NULL;
- dev = zalloc(sizeof *dev);
- if (!dev) {
- free(input);
- return NULL;
- }
-
if (libinput_init(&input->base, interface,
&interface_backend, user_data) != 0) {
free(input);
- free(dev);
return NULL;
}
list_init(&input->path_list);
- dev->path = strdup(path);
- if (!dev->path) {
- free(input);
- free(dev);
- return NULL;
- }
-
- list_insert(&input->path_list, &dev->link);
-
- if (path_input_enable(&input->base) < 0) {
- libinput_destroy(&input->base);
- return NULL;
- }
-
return &input->base;
}
rc = libevdev_new_from_fd(fd, &d->evdev);
ck_assert_int_eq(rc, 0);
- d->libinput = libinput_create_from_path(&interface, NULL, path);
+ d->libinput = libinput_path_create_context(&interface, NULL);
ck_assert(d->libinput != NULL);
+ d->libinput_device = libinput_path_add_device(d->libinput, path);
+ ck_assert(d->libinput_device != NULL);
+ libinput_device_ref(d->libinput_device);
+
d->interface->min[ABS_X] = libevdev_get_abs_minimum(d->evdev, ABS_X);
d->interface->max[ABS_X] = libevdev_get_abs_maximum(d->evdev, ABS_X);
d->interface->min[ABS_Y] = libevdev_get_abs_minimum(d->evdev, ABS_Y);
if (!d)
return;
+ libinput_device_unref(d->libinput_device);
libinput_destroy(d->libinput);
libevdev_free(d->evdev);
libevdev_uinput_destroy(d->uinput);
{
struct libinput *li;
const struct libinput_interface interface;
- const char *path = "foo";
open_func_count = 0;
close_func_count = 0;
- li = libinput_create_from_path(NULL, NULL, NULL);
- ck_assert(li == NULL);
- li = libinput_create_from_path(&interface, NULL, NULL);
- ck_assert(li == NULL);
- li = libinput_create_from_path(NULL, NULL, path);
+ li = libinput_path_create_context(NULL, NULL);
ck_assert(li == NULL);
+ li = libinput_path_create_context(&interface, NULL);
+ ck_assert(li != NULL);
+ libinput_destroy(li);
ck_assert_int_eq(open_func_count, 0);
ck_assert_int_eq(close_func_count, 0);
START_TEST(path_create_invalid)
{
struct libinput *li;
+ struct libinput_device *device;
const char *path = "/tmp";
open_func_count = 0;
close_func_count = 0;
- li = libinput_create_from_path(&simple_interface, NULL, path);
- ck_assert(li == NULL);
+ li = libinput_path_create_context(&simple_interface, NULL);
+ ck_assert(li != NULL);
+ device = libinput_path_add_device(li, path);
+ ck_assert(device == NULL);
ck_assert_int_eq(open_func_count, 0);
ck_assert_int_eq(close_func_count, 0);
START_TEST(path_create_destroy)
{
struct libinput *li;
+ struct libinput_device *device;
struct libevdev *evdev;
struct libevdev_uinput *uinput;
int rc;
ck_assert_int_eq(rc, 0);
libevdev_free(evdev);
- li = libinput_create_from_path(&simple_interface, userdata,
- libevdev_uinput_get_devnode(uinput));
+ li = libinput_path_create_context(&simple_interface, userdata);
ck_assert(li != NULL);
ck_assert(libinput_get_user_data(li) == userdata);
+
+ device = libinput_path_add_device(li,
+ libevdev_uinput_get_devnode(uinput));
+ ck_assert(device != NULL);
+
ck_assert_int_eq(open_func_count, 1);
libevdev_uinput_destroy(uinput);
START_TEST(path_suspend)
{
struct libinput *li;
+ struct libinput_device *device;
struct libevdev *evdev;
struct libevdev_uinput *uinput;
int rc;
ck_assert_int_eq(rc, 0);
libevdev_free(evdev);
- li = libinput_create_from_path(&simple_interface, userdata,
- libevdev_uinput_get_devnode(uinput));
+ li = libinput_path_create_context(&simple_interface, userdata);
ck_assert(li != NULL);
+ device = libinput_path_add_device(li,
+ libevdev_uinput_get_devnode(uinput));
+ ck_assert(device != NULL);
+
libinput_suspend(li);
libinput_resume(li);
START_TEST(path_double_suspend)
{
struct libinput *li;
+ struct libinput_device *device;
struct libevdev *evdev;
struct libevdev_uinput *uinput;
int rc;
ck_assert_int_eq(rc, 0);
libevdev_free(evdev);
- li = libinput_create_from_path(&simple_interface, userdata,
- libevdev_uinput_get_devnode(uinput));
+ li = libinput_path_create_context(&simple_interface, userdata);
ck_assert(li != NULL);
+ device = libinput_path_add_device(li,
+ libevdev_uinput_get_devnode(uinput));
+ ck_assert(device != NULL);
+
libinput_suspend(li);
libinput_suspend(li);
libinput_resume(li);
START_TEST(path_double_resume)
{
struct libinput *li;
+ struct libinput_device *device;
struct libevdev *evdev;
struct libevdev_uinput *uinput;
int rc;
ck_assert_int_eq(rc, 0);
libevdev_free(evdev);
- li = libinput_create_from_path(&simple_interface, userdata,
- libevdev_uinput_get_devnode(uinput));
+ li = libinput_path_create_context(&simple_interface, userdata);
ck_assert(li != NULL);
+ device = libinput_path_add_device(li,
+ libevdev_uinput_get_devnode(uinput));
+ ck_assert(device != NULL);
+
libinput_suspend(li);
libinput_resume(li);
libinput_resume(li);