Add libinput_set_user_data
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 23 Dec 2014 03:37:28 +0000 (13:37 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 23 Dec 2014 04:49:39 +0000 (14:49 +1000)
Previously, the pointer could only be passed into the context on creation
time and was immutable after that.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/libinput.c
src/libinput.h
src/libinput.sym
test/path.c
test/udev.c

index fbefbb3..d78e26d 100644 (file)
@@ -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)
 {
index e156a3a..d43b0f6 100644 (file)
@@ -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().
  */
index f35a0cd..057919c 100644 (file)
@@ -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;
index 3a2bf2f..243edd7 100644 (file)
@@ -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);
index f5d2c88..c351bed 100644 (file)
@@ -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);