mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-27 23:10:07 +01:00
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 <peter.hutterer@who-t.net>
This commit is contained in:
parent
7a65c1f636
commit
6e6cca47af
5 changed files with 56 additions and 0 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
16
test/path.c
16
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);
|
||||
|
|
|
|||
21
test/udev.c
21
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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue