[PATCH 4/5] evdev: Apply calibration values to absolute events

Rob Bradford robert.bradford at intel.com
Mon Dec 3 11:44:16 PST 2012


From: Rob Bradford <rob at linux.intel.com>

Store a set of calibration values per device - these calibration values are
just applied to the absolute motion events.
---
 src/evdev.c | 16 ++++++++++++++++
 src/evdev.h |  3 +++
 2 files changed, 19 insertions(+)

diff --git a/src/evdev.c b/src/evdev.c
index fa2c740..0b99c43 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -230,6 +230,21 @@ is_motion_event(struct input_event *e)
 }
 
 static void
+transform_absolute(struct evdev_device *device)
+{
+	if (!device->abs.apply_calibration)
+		return;
+
+	device->abs.x = device->abs.x * device->abs.calibration[0] +
+			device->abs.y * device->abs.calibration[1] +
+			device->abs.calibration[2];
+
+	device->abs.y = device->abs.x * device->abs.calibration[3] +
+			device->abs.y * device->abs.calibration[4] +
+			device->abs.calibration[5];
+}
+
+static void
 evdev_flush_motion(struct evdev_device *device, uint32_t time)
 {
 	struct weston_seat *master = device->seat;
@@ -269,6 +284,7 @@ evdev_flush_motion(struct evdev_device *device, uint32_t time)
 		device->pending_events &= ~EVDEV_ABSOLUTE_MT_UP;
 	}
 	if (device->pending_events & EVDEV_ABSOLUTE_MOTION) {
+		transform_absolute(device);
 		notify_motion(master, time,
 			      wl_fixed_from_int(device->abs.x),
 			      wl_fixed_from_int(device->abs.y));
diff --git a/src/evdev.h b/src/evdev.h
index 85c4739..a90f90c 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -56,6 +56,9 @@ struct evdev_device {
 	struct {
 		int min_x, max_x, min_y, max_y;
 		int32_t x, y;
+
+		int apply_calibration;
+		float calibration[6];
 	} abs;
 
 	struct {
-- 
1.7.11.7



More information about the wayland-devel mailing list