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 fbefbb38765e5df64e1183d89b1b3ba9417e356b..d78e26db6dadc9d49ef801165f139dc0fef3ccaa 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 e156a3a0cb1d30b38d4defedaa06872d4f0a3fe7..d43b0f6ae0147233e5f0766678050b49472c6221 100644 (file)
@@ -1002,6 +1002,17 @@ libinput_get_event(struct libinput *libinput);
 enum libinput_event_type
 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
  *
index f35a0cdfa011c1d3cde359bc245c3d6243836e31..057919c9edb5960e0681f808759c68391f343fe8 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 3a2bf2f8f1d06a45be839600b47f529e7f5eb643..243edd793d3b648c066956d2067d53290f6aa527 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 f5d2c883c7bf85d7a380f084040bb3f3a391d87a..c351bed57e8413a0ed93073d1d67dd5bbe5b1b32 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);