mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-27 04:30:06 +01:00
path: add libinput_path_create_context instead of libinput_create_from_path
Creates an empty context that is not hooked up to a device. Callers can then add and remove devices to this context using libinput_path_add_device() and libinput_path_remove_device(). Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
69dcea11b9
commit
606249f91c
6 changed files with 65 additions and 53 deletions
|
|
@ -706,25 +706,26 @@ libinput_create_from_udev(const struct libinput_interface *interface,
|
|||
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
|
||||
|
|
|
|||
29
src/path.c
29
src/path.c
|
|
@ -241,49 +241,26 @@ static const struct libinput_interface_backend interface_backend = {
|
|||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -356,9 +356,13 @@ litest_create_device(enum litest_device_type which)
|
|||
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);
|
||||
|
|
@ -386,6 +390,7 @@ litest_delete_device(struct litest_device *d)
|
|||
if (!d)
|
||||
return;
|
||||
|
||||
libinput_device_unref(d->libinput_device);
|
||||
libinput_destroy(d->libinput);
|
||||
libevdev_free(d->evdev);
|
||||
libevdev_uinput_destroy(d->uinput);
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ struct litest_device {
|
|||
struct libevdev *evdev;
|
||||
struct libevdev_uinput *uinput;
|
||||
struct libinput *libinput;
|
||||
struct libinput_device *libinput_device;
|
||||
struct litest_device_interface *interface;
|
||||
};
|
||||
|
||||
|
|
|
|||
50
test/path.c
50
test/path.c
|
|
@ -58,17 +58,15 @@ START_TEST(path_create_NULL)
|
|||
{
|
||||
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);
|
||||
|
|
@ -81,13 +79,16 @@ END_TEST
|
|||
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);
|
||||
|
|
@ -103,6 +104,7 @@ END_TEST
|
|||
START_TEST(path_create_destroy)
|
||||
{
|
||||
struct libinput *li;
|
||||
struct libinput_device *device;
|
||||
struct libevdev *evdev;
|
||||
struct libevdev_uinput *uinput;
|
||||
int rc;
|
||||
|
|
@ -123,10 +125,14 @@ START_TEST(path_create_destroy)
|
|||
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);
|
||||
|
|
@ -334,6 +340,7 @@ END_TEST
|
|||
START_TEST(path_suspend)
|
||||
{
|
||||
struct libinput *li;
|
||||
struct libinput_device *device;
|
||||
struct libevdev *evdev;
|
||||
struct libevdev_uinput *uinput;
|
||||
int rc;
|
||||
|
|
@ -354,10 +361,13 @@ START_TEST(path_suspend)
|
|||
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);
|
||||
|
||||
|
|
@ -372,6 +382,7 @@ END_TEST
|
|||
START_TEST(path_double_suspend)
|
||||
{
|
||||
struct libinput *li;
|
||||
struct libinput_device *device;
|
||||
struct libevdev *evdev;
|
||||
struct libevdev_uinput *uinput;
|
||||
int rc;
|
||||
|
|
@ -392,10 +403,13 @@ START_TEST(path_double_suspend)
|
|||
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);
|
||||
|
|
@ -411,6 +425,7 @@ END_TEST
|
|||
START_TEST(path_double_resume)
|
||||
{
|
||||
struct libinput *li;
|
||||
struct libinput_device *device;
|
||||
struct libevdev *evdev;
|
||||
struct libevdev_uinput *uinput;
|
||||
int rc;
|
||||
|
|
@ -431,10 +446,13 @@ START_TEST(path_double_resume)
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -151,11 +151,21 @@ open_udev(struct libinput **li)
|
|||
static int
|
||||
open_device(struct libinput **li, const char *path)
|
||||
{
|
||||
*li = libinput_create_from_path(&interface, NULL, path);
|
||||
struct libinput_device *device;
|
||||
|
||||
*li = libinput_path_create_context(&interface, NULL);
|
||||
if (!*li) {
|
||||
fprintf(stderr, "Failed to initialize context from %s\n", path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
device = libinput_path_add_device(*li, path);
|
||||
if (!device) {
|
||||
fprintf(stderr, "Failed to initialized device %s\n", path);
|
||||
libinput_destroy(*li);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue