[PATCH libinput 4/4] Add a function to get the size of a device

Peter Hutterer peter.hutterer at who-t.net
Wed Jun 18 20:45:46 PDT 2014


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev.c         | 19 +++++++++++++++++++
 src/evdev.h         |  5 +++++
 src/libinput.c      | 10 ++++++++++
 src/libinput.h      | 19 +++++++++++++++++++
 tools/event-debug.c |  8 +++++++-
 5 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/src/evdev.c b/src/evdev.c
index 2b2725c..70c232c 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -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)
 {
diff --git a/src/evdev.h b/src/evdev.h
index eebfab1..4a83a78 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -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,
diff --git a/src/libinput.c b/src/libinput.c
index f384f43..c4f7fe1 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -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)
 {
diff --git a/src/libinput.h b/src/libinput.h
index c19460b..fe75f87 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -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
diff --git a/tools/event-debug.c b/tools/event-debug.c
index ffb4524..0f0d033 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -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
-- 
1.9.3



More information about the wayland-devel mailing list