Add libinput_device_get_context/libinput_seat_get_context
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 1 Dec 2014 06:00:13 +0000 (16:00 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 2 Dec 2014 23:09:42 +0000 (09:09 +1000)
Allow retrieval of the libinput context from the seat and the device.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
src/libinput.c
src/libinput.h
test/device.c

index 96b255a940801d8b5ecc13b626d0dd54dfc348f6..0d380fa818286519738f0d5ee0dc59664309c572 100644 (file)
@@ -651,6 +651,12 @@ libinput_seat_get_user_data(struct libinput_seat *seat)
        return seat->user_data;
 }
 
+LIBINPUT_EXPORT struct libinput *
+libinput_seat_get_context(struct libinput_seat *seat)
+{
+       return seat->libinput;
+}
+
 LIBINPUT_EXPORT const char *
 libinput_seat_get_physical_name(struct libinput_seat *seat)
 {
@@ -1177,6 +1183,12 @@ libinput_device_get_user_data(struct libinput_device *device)
        return device->user_data;
 }
 
+LIBINPUT_EXPORT struct libinput *
+libinput_device_get_context(struct libinput_device *device)
+{
+       return libinput_seat_get_context(device->seat);
+}
+
 LIBINPUT_EXPORT const char *
 libinput_device_get_sysname(struct libinput_device *device)
 {
index d567df440f44c7700591e7daddb3f1336829b0ad..db56da7f49ae917d1ca642c637048c78b30c3bc0 100644 (file)
@@ -1199,6 +1199,17 @@ libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data);
 void *
 libinput_seat_get_user_data(struct libinput_seat *seat);
 
+/**
+ * @ingroup seat
+ *
+ * Get the libinput context from the seat.
+ *
+ * @param seat A previously obtained seat
+ * @return The libinput context for this seat.
+ */
+struct libinput *
+libinput_seat_get_context(struct libinput_seat *seat);
+
 /**
  * @ingroup seat
  *
@@ -1288,6 +1299,17 @@ libinput_device_set_user_data(struct libinput_device *device, void *user_data);
 void *
 libinput_device_get_user_data(struct libinput_device *device);
 
+/**
+ * @ingroup device
+ *
+ * Get the libinput context from the device.
+ *
+ * @param device A previously obtained device
+ * @return The libinput context for this device.
+ */
+struct libinput *
+libinput_device_get_context(struct libinput_device *device);
+
 /**
  * @ingroup device
  *
index 84984f4c6c1df3ca4ad26c57c618749277166b91..28cdb06cda7eb2905be102d17a13b95c0fbfd5a5 100644 (file)
@@ -629,6 +629,17 @@ START_TEST(device_get_udev_handle)
 }
 END_TEST
 
+START_TEST(device_context)
+{
+       struct litest_device *dev = litest_current_device();
+       struct libinput_seat *seat;
+
+       ck_assert(dev->libinput == libinput_device_get_context(dev->libinput_device));
+       seat = libinput_device_get_seat(dev->libinput_device);
+       ck_assert(dev->libinput == libinput_seat_get_context(seat));
+}
+END_TEST
+
 int main (int argc, char **argv)
 {
        litest_add("device:sendevents", device_sendevents_config, LITEST_ANY, LITEST_TOUCHPAD);
@@ -650,6 +661,7 @@ int main (int argc, char **argv)
        litest_add("device:sendevents", device_disable_release_softbutton, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
        litest_add("device:sendevents", device_disable_topsoftbutton, LITEST_TOPBUTTONPAD, LITEST_ANY);
        litest_add("device:id", device_ids, LITEST_ANY, LITEST_ANY);
+       litest_add_for_device("device:context", device_context, LITEST_SYNAPTICS_CLICKPAD);
 
        litest_add("device:udev", device_get_udev_handle, LITEST_ANY, LITEST_ANY);