libweston: notify_touch API to use weston_touch_device

Relay touch input events into libweston core through the
weston_touch_device, so that the core can tell which individual physical
device they come from.

This is necessary for supporting touchscreen calibration, where one
needs to process a single physical device at a time instead of the
aggregate of all touch devices on the weston_seat.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v1 Tested-by: Matt Hoosier <matt.hoosier@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index 5ed90c0..e80ecc1 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -2146,7 +2146,7 @@
 
 	weston_output_transform_coordinate(&output->base, x, y, &x, &y);
 
-	notify_touch(&input->base, &ts, id, x, y, WL_TOUCH_DOWN);
+	notify_touch(input->touch_device, &ts, id, x, y, WL_TOUCH_DOWN);
 	input->touch_active = true;
 }
 
@@ -2187,7 +2187,7 @@
 	}
 
 	if (active)
-		notify_touch(&input->base, &ts, id, 0, 0, WL_TOUCH_UP);
+		notify_touch(input->touch_device, &ts, id, 0, 0, WL_TOUCH_UP);
 }
 
 static void
@@ -2216,7 +2216,7 @@
 
 	weston_output_transform_coordinate(&output->base, x, y, &x, &y);
 
-	notify_touch(&input->base, &ts, id, x, y, WL_TOUCH_MOTION);
+	notify_touch(input->touch_device, &ts, id, x, y, WL_TOUCH_MOTION);
 }
 
 static void
@@ -2227,7 +2227,7 @@
 	if (!input->touch_focus || !input->touch_active)
 		return;
 
-	notify_touch_frame(&input->base);
+	notify_touch_frame(input->touch_device);
 }
 
 static void
@@ -2238,7 +2238,7 @@
 	if (!input->touch_focus || !input->touch_active)
 		return;
 
-	notify_touch_cancel(&input->base);
+	notify_touch_cancel(input->touch_device);
 }
 
 static const struct wl_touch_listener touch_listener = {
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 7f3fdb9..09a9dab 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -1543,13 +1543,13 @@
 notify_keyboard_focus_out(struct weston_seat *seat);
 
 void
-notify_touch(struct weston_seat *seat, const struct timespec *time,
+notify_touch(struct weston_touch_device *device, const struct timespec *time,
 	     int touch_id, double x, double y, int touch_type);
 void
-notify_touch_frame(struct weston_seat *seat);
+notify_touch_frame(struct weston_touch_device *device);
 
 void
-notify_touch_cancel(struct weston_seat *seat);
+notify_touch_cancel(struct weston_touch_device *device);
 
 void
 weston_layer_entry_insert(struct weston_layer_entry *list,
diff --git a/libweston/input.c b/libweston/input.c
index acb564e..e02b306 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -2347,12 +2347,12 @@
  *
  */
 WL_EXPORT void
-notify_touch(struct weston_seat *seat, const struct timespec *time,
+notify_touch(struct weston_touch_device *device, const struct timespec *time,
 	     int touch_id, double double_x, double double_y, int touch_type)
 {
-	struct weston_compositor *ec = seat->compositor;
-	struct weston_touch *touch = weston_seat_get_touch(seat);
-	struct weston_touch_grab *grab = touch->grab;
+	struct weston_touch *touch = device->aggregate;
+	struct weston_touch_grab *grab = device->aggregate->grab;
+	struct weston_compositor *ec = device->aggregate->seat->compositor;
 	struct weston_view *ev;
 	wl_fixed_t sx, sy;
 	wl_fixed_t x = wl_fixed_from_double(double_x);
@@ -2426,19 +2426,17 @@
 }
 
 WL_EXPORT void
-notify_touch_frame(struct weston_seat *seat)
+notify_touch_frame(struct weston_touch_device *device)
 {
-	struct weston_touch *touch = weston_seat_get_touch(seat);
-	struct weston_touch_grab *grab = touch->grab;
+	struct weston_touch_grab *grab = device->aggregate->grab;
 
 	grab->interface->frame(grab);
 }
 
 WL_EXPORT void
-notify_touch_cancel(struct weston_seat *seat)
+notify_touch_cancel(struct weston_touch_device *device)
 {
-	struct weston_touch *touch = weston_seat_get_touch(seat);
-	struct weston_touch_grab *grab = touch->grab;
+	struct weston_touch_grab *grab = device->aggregate->grab;
 
 	grab->interface->cancel(grab);
 }
diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c
index 1fc0133..dda28fd 100644
--- a/libweston/libinput-device.c
+++ b/libweston/libinput-device.c
@@ -438,7 +438,7 @@
 	weston_output_transform_coordinate(device->output,
 					   x, y, &x, &y);
 
-	notify_touch(device->seat, &time, slot, x, y, touch_type);
+	notify_touch(device->touch_device, &time, slot, x, y, touch_type);
 }
 
 static void
@@ -467,7 +467,7 @@
 	timespec_from_usec(&time,
 			   libinput_event_touch_get_time_usec(touch_event));
 
-	notify_touch(device->seat, &time, slot, 0, 0, WL_TOUCH_UP);
+	notify_touch(device->touch_device, &time, slot, 0, 0, WL_TOUCH_UP);
 }
 
 static void
@@ -476,9 +476,8 @@
 {
 	struct evdev_device *device =
 		libinput_device_get_user_data(libinput_device);
-	struct weston_seat *seat = device->seat;
 
-	notify_touch_frame(seat);
+	notify_touch_frame(device->touch_device);
 }
 
 int
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 9662b67..412eb24 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -595,12 +595,14 @@
 	   int32_t touch_id, wl_fixed_t x, wl_fixed_t y, uint32_t touch_type)
 {
 	struct weston_test *test = wl_resource_get_user_data(resource);
-	struct weston_seat *seat = get_seat(test);
+	struct weston_touch_device *device = test->touch_device[0];
 	struct timespec time;
 
+	assert(device);
+
 	timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
 
-	notify_touch(seat, &time, touch_id, wl_fixed_to_double(x),
+	notify_touch(device, &time, touch_id, wl_fixed_to_double(x),
 		     wl_fixed_to_double(y), touch_type);
 }