From 6e6cca47af6e8858c0e3ae9ec8309f7f59ba8708 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 23 Dec 2014 13:37:28 +1000 Subject: [PATCH] Add libinput_set_user_data Previously, the pointer could only be passed into the context on creation time and was immutable after that. Signed-off-by: Peter Hutterer --- src/libinput.c | 7 +++++++ src/libinput.h | 11 +++++++++++ src/libinput.sym | 1 + test/path.c | 16 ++++++++++++++++ test/udev.c | 21 +++++++++++++++++++++ 5 files changed, 56 insertions(+) diff --git a/src/libinput.c b/src/libinput.c index fbefbb3..d78e26d 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1173,6 +1173,13 @@ libinput_next_event_type(struct libinput *libinput) return event->type; } +LIBINPUT_EXPORT void +libinput_set_user_data(struct libinput *libinput, + void *user_data) +{ + libinput->user_data = user_data; +} + LIBINPUT_EXPORT void * libinput_get_user_data(struct libinput *libinput) { diff --git a/src/libinput.h b/src/libinput.h index e156a3a..d43b0f6 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1006,6 +1006,17 @@ libinput_next_event_type(struct libinput *libinput); * @ingroup base * * @param libinput A previously initialized libinput context + * @param user_data Caller-specific data passed to the various callback + * interfaces. + */ +void +libinput_set_user_data(struct libinput *libinput, + void *user_data); + +/** + * @ingroup base + * + * @param libinput A previously initialized libinput context * @return the caller-specific data previously assigned in * libinput_create_udev(). */ diff --git a/src/libinput.sym b/src/libinput.sym index f35a0cd..057919c 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -108,6 +108,7 @@ global: libinput_seat_ref; libinput_seat_set_user_data; libinput_seat_unref; + libinput_set_user_data; libinput_suspend; libinput_udev_assign_seat; libinput_udev_create_context; diff --git a/test/path.c b/test/path.c index 3a2bf2f..243edd7 100644 --- a/test/path.c +++ b/test/path.c @@ -133,6 +133,21 @@ START_TEST(path_create_destroy) } END_TEST +START_TEST(path_set_user_data) +{ + struct libinput *li; + int data1, data2; + + li = libinput_path_create_context(&simple_interface, &data1); + ck_assert(li != NULL); + ck_assert(libinput_get_user_data(li) == &data1); + libinput_set_user_data(li, &data2); + ck_assert(libinput_get_user_data(li) == &data2); + + libinput_unref(li); +} +END_TEST + START_TEST(path_added_seat) { struct litest_device *dev = litest_current_device(); @@ -867,6 +882,7 @@ main(int argc, char **argv) litest_add_no_device("path:create", path_create_NULL); litest_add_no_device("path:create", path_create_invalid); litest_add_no_device("path:create", path_create_destroy); + litest_add_no_device("path:create", path_set_user_data); litest_add_no_device("path:suspend", path_suspend); litest_add_no_device("path:suspend", path_double_suspend); litest_add_no_device("path:suspend", path_double_resume); diff --git a/test/udev.c b/test/udev.c index f5d2c88..c351bed 100644 --- a/test/udev.c +++ b/test/udev.c @@ -129,6 +129,26 @@ START_TEST(udev_create_empty_seat) } END_TEST +START_TEST(udev_set_user_data) +{ + struct libinput *li; + struct udev *udev; + int data1, data2; + + udev = udev_new(); + ck_assert(udev != NULL); + + li = libinput_udev_create_context(&simple_interface, &data1, udev); + ck_assert(li != NULL); + ck_assert(libinput_get_user_data(li) == &data1); + libinput_set_user_data(li, &data2); + ck_assert(libinput_get_user_data(li) == &data2); + + libinput_unref(li); + udev_unref(udev); +} +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. @@ -488,6 +508,7 @@ main(int argc, char **argv) litest_add_no_device("udev:create", udev_create_NULL); litest_add_no_device("udev:create", udev_create_seat0); litest_add_no_device("udev:create", udev_create_empty_seat); + litest_add_no_device("udev:create", udev_set_user_data); litest_add_no_device("udev:seat", udev_added_seat_default); litest_add_no_device("udev:seat", udev_change_seat); -- 2.7.4