Add a function to get the size of a device
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 17 Jun 2014 05:45:07 +0000 (15:45 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 19 Jun 2014 03:38:15 +0000 (13:38 +1000)
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
src/evdev.c
src/evdev.h
src/libinput.c
src/libinput.h
tools/event-debug.c

index 2b2725c..70c232c 100644 (file)
@@ -871,6 +871,25 @@ evdev_device_has_capability(struct evdev_device *device,
        }
 }
 
+int
+evdev_device_get_size(struct evdev_device *device,
+                     double *width,
+                     double *height)
+{
+       const struct input_absinfo *x, *y;
+
+       x = libevdev_get_abs_info(device->evdev, ABS_X);
+       y = libevdev_get_abs_info(device->evdev, ABS_Y);
+
+       if (!x || !y || !x->resolution || !y->resolution)
+               return -1;
+
+       *width = evdev_convert_to_mm(x, x->maximum);
+       *height = evdev_convert_to_mm(y, y->maximum);
+
+       return 0;
+}
+
 void
 evdev_device_remove(struct evdev_device *device)
 {
index eebfab1..4a83a78 100644 (file)
@@ -148,6 +148,11 @@ int
 evdev_device_has_capability(struct evdev_device *device,
                            enum libinput_device_capability capability);
 
+int
+evdev_device_get_size(struct evdev_device *device,
+                     double *w,
+                     double *h);
+
 double
 evdev_device_transform_x(struct evdev_device *device,
                         double x,
index f384f43..c4f7fe1 100644 (file)
@@ -1185,6 +1185,16 @@ libinput_device_has_capability(struct libinput_device *device,
                                           capability);
 }
 
+LIBINPUT_EXPORT int
+libinput_device_get_size(struct libinput_device *device,
+                        double *width,
+                        double *height)
+{
+       return evdev_device_get_size((struct evdev_device *)device,
+                                    width,
+                                    height);
+}
+
 LIBINPUT_EXPORT struct libinput_event *
 libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event)
 {
index c19460b..fe75f87 100644 (file)
@@ -1303,6 +1303,25 @@ int
 libinput_device_has_capability(struct libinput_device *device,
                               enum libinput_device_capability capability);
 
+/**
+ * @ingroup device
+ *
+ * Get the physical size of a device in mm, where meaningful. This function
+ * only succeeds on devices with the required data, i.e. tablets, touchpads
+ * and touchscreens.
+ *
+ * If this function returns nonzero, width and height are unmodified.
+ *
+ * @param device The device
+ * @param width Set to the width of the device
+ * @param height Set to the height of the device
+ * @return 0 on success, or nonzero otherwise
+ */
+int
+libinput_device_get_size(struct libinput_device *device,
+                        double *width,
+                        double *height);
+
 #ifdef __cplusplus
 }
 #endif
index ffb4524..0f0d033 100644 (file)
@@ -231,10 +231,16 @@ print_device_notify(struct libinput_event *ev)
 {
        struct libinput_device *dev = libinput_event_get_device(ev);
        struct libinput_seat *seat = libinput_device_get_seat(dev);
+       double w, h;
 
-       printf("%s      %s\n",
+       printf("%s      %s",
               libinput_seat_get_physical_name(seat),
               libinput_seat_get_logical_name(seat));
+
+       if (libinput_device_get_size(dev, &w, &h) == 0)
+               printf("\tsize %.2f/%.2fmm", w, h);
+
+       printf("\n");
 }
 
 static void