[PATCH libinput 3/4] Change absolute and touch events to use mm as default unit
Peter Hutterer
peter.hutterer at who-t.net
Wed Jun 18 20:45:45 PDT 2014
Instead of device-specific coordinates that the caller can't interpret without
knowing the range anyway, return mm as the default value.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
src/evdev.h | 7 +++++++
src/libinput.c | 20 ++++++++++++++++----
src/libinput.h | 32 ++++++++++++--------------------
tools/event-debug.c | 7 +++++--
4 files changed, 40 insertions(+), 26 deletions(-)
diff --git a/src/evdev.h b/src/evdev.h
index 03b6742..eebfab1 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -164,4 +164,11 @@ evdev_device_remove(struct evdev_device *device);
void
evdev_device_destroy(struct evdev_device *device);
+static inline double
+evdev_convert_to_mm(const struct input_absinfo *absinfo, double v)
+{
+ double value = v - absinfo->minimum;
+ return value/absinfo->resolution;
+}
+
#endif /* EVDEV_H */
diff --git a/src/libinput.c b/src/libinput.c
index 5b10a10..f384f43 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -319,13 +319,19 @@ libinput_event_pointer_get_dy(struct libinput_event_pointer *event)
LIBINPUT_EXPORT double
libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event)
{
- return event->x;
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ return evdev_convert_to_mm(device->abs.absinfo_x, event->x);
}
LIBINPUT_EXPORT double
libinput_event_pointer_get_absolute_y(struct libinput_event_pointer *event)
{
- return event->y;
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ return evdev_convert_to_mm(device->abs.absinfo_y, event->y);
}
LIBINPUT_EXPORT double
@@ -402,7 +408,10 @@ libinput_event_touch_get_seat_slot(struct libinput_event_touch *event)
LIBINPUT_EXPORT double
libinput_event_touch_get_x(struct libinput_event_touch *event)
{
- return event->x;
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ return evdev_convert_to_mm(device->abs.absinfo_x, event->x);
}
LIBINPUT_EXPORT double
@@ -428,7 +437,10 @@ libinput_event_touch_get_y_transformed(struct libinput_event_touch *event,
LIBINPUT_EXPORT double
libinput_event_touch_get_y(struct libinput_event_touch *event)
{
- return event->y;
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ return evdev_convert_to_mm(device->abs.absinfo_y, event->y);
}
struct libinput_source *
diff --git a/src/libinput.h b/src/libinput.h
index 54c96e5..c19460b 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -452,11 +452,9 @@ libinput_event_pointer_get_dy(struct libinput_event_pointer *event);
/**
* @ingroup event_pointer
*
- * Return the current absolute x coordinate of the pointer event.
- *
- * The coordinate is in a device specific coordinate space; to get the
- * corresponding output screen coordinate, use
- * libinput_event_pointer_get_x_transformed().
+ * Return the current absolute x coordinate of the pointer event, in mm from
+ * the top left corner of the device. To get the corresponding output screen
+ * coordinate, use libinput_event_pointer_get_x_transformed().
*
* For pointer events that are not of type
* LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, this function returns 0.
@@ -472,11 +470,9 @@ libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event);
/**
* @ingroup event_pointer
*
- * Return the current absolute y coordinate of the pointer event.
- *
- * The coordinate is in a device specific coordinate space; to get the
- * corresponding output screen coordinate, use
- * libinput_event_pointer_get_y_transformed().
+ * Return the current absolute y coordinate of the pointer event, in mm from
+ * the top left corner of the device. To get the corresponding output screen
+ * coordinate, use libinput_event_pointer_get_x_transformed().
*
* For pointer events that are not of type
* LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, this function returns 0.
@@ -677,11 +673,9 @@ libinput_event_touch_get_seat_slot(struct libinput_event_touch *event);
/**
* @ingroup event_touch
*
- * Return the current absolute x coordinate of the touch event.
- *
- * The coordinate is in a device specific coordinate space; to get the
- * corresponding output screen coordinate, use
- * libinput_event_touch_get_x_transformed().
+ * Return the current absolute x coordinate of the touch event, in mm from
+ * the top left corner of the device. To get the corresponding output screen
+ * coordinate, use libinput_event_touch_get_x_transformed().
*
* @note this function should only be called for LIBINPUT_EVENT_TOUCH_DOWN and
* LIBINPUT_EVENT_TOUCH_MOTION.
@@ -695,11 +689,9 @@ libinput_event_touch_get_x(struct libinput_event_touch *event);
/**
* @ingroup event_touch
*
- * Return the current absolute y coordinate of the touch event.
- *
- * The coordinate is in a device specific coordinate space; to get the
- * corresponding output screen coordinate, use
- * libinput_event_touch_get_y_transformed().
+ * Return the current absolute y coordinate of the touch event, in mm from
+ * the top left corner of the device. To get the corresponding output screen
+ * coordinate, use libinput_event_touch_get_y_transformed().
*
* For LIBINPUT_EVENT_TOUCH_UP 0 is returned.
*
diff --git a/tools/event-debug.c b/tools/event-debug.c
index 864f77e..ffb4524 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -329,13 +329,16 @@ print_touch_event_with_coords(struct libinput_event *ev)
struct libinput_event_touch *t = libinput_event_get_touch_event(ev);
double x = libinput_event_touch_get_x_transformed(t, screen_width);
double y = libinput_event_touch_get_y_transformed(t, screen_height);
+ double xmm = libinput_event_touch_get_x(t);
+ double ymm = libinput_event_touch_get_y(t);
print_event_time(libinput_event_touch_get_time(t));
- printf("%d (%d) %5.2f/%5.2f\n",
+ printf("%d (%d) %5.2f/%5.2f (%5.2f/%5.2fmm)\n",
libinput_event_touch_get_slot(t),
libinput_event_touch_get_seat_slot(t),
- x, y);
+ x, y,
+ xmm, ymm);
}
static int
--
1.9.3
More information about the wayland-devel
mailing list