[PATCH 2/2] compositor-wayland: Add touch support

Boyan Ding stu_dby at 126.com
Tue May 6 19:46:30 PDT 2014


Adding touch support to weston's nested wayland backend to make testing
easier.

https://bugs.freedesktop.org/show_bug.cgi?id=77769
---
 src/compositor-wayland.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index a08b71a..45040d4 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -1582,6 +1582,91 @@ static const struct wl_keyboard_listener keyboard_listener = {
 };
 
 static void
+input_handle_touch_down(void *data, struct wl_touch *touch, uint32_t serial,
+		        uint32_t time, struct wl_surface *surface, int32_t id,
+			wl_fixed_t x, wl_fixed_t y)
+{
+	struct wayland_input *input = data;
+	int32_t fx, fy;
+
+	if (input->output->frame) {
+		frame_touch_down(input->output->frame, input, id,
+				 wl_fixed_to_int(x), wl_fixed_to_int(y));
+		frame_interior(input->output->frame, &fx, &fy, NULL, NULL);
+		x -= wl_fixed_from_int(fx);
+		y -= wl_fixed_from_int(fy);
+
+		if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
+			weston_output_schedule_repaint(&input->output->base);
+	}
+
+	weston_output_transform_coordinate(&input->output->base, x, y, &x, &y);
+
+	notify_touch(&input->base, time, id, x, y, WL_TOUCH_DOWN);
+}
+
+static void
+input_handle_touch_up(void *data, struct wl_touch *touch, uint32_t serial,
+		      uint32_t time, int32_t id)
+{
+	struct wayland_input *input = data;
+
+	if (input->output->frame) {
+		frame_touch_up(input->output->frame, input, id);
+
+		if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
+			weston_output_schedule_repaint(&input->output->base);
+	}
+
+	notify_touch(&input->base, time, id, 0, 0, WL_TOUCH_UP);
+}
+
+static void
+input_handle_touch_motion(void *data, struct wl_touch *touch, uint32_t time,
+			  int32_t id, wl_fixed_t x, wl_fixed_t y)
+{
+	struct wayland_input *input = data;
+	int32_t fx, fy;
+
+	if (input->output->frame) {
+		frame_touch_motion(input->output->frame, input, id,
+				 wl_fixed_to_int(x), wl_fixed_to_int(y));
+
+		frame_interior(input->output->frame, &fx, &fy, NULL, NULL);
+		x -= wl_fixed_from_int(fx);
+		y -= wl_fixed_from_int(fy);
+
+		if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
+			weston_output_schedule_repaint(&input->output->base);
+	}
+
+	weston_output_transform_coordinate(&input->output->base, x, y, &x, &y);
+
+	notify_touch(&input->base, time, id, x, y, WL_TOUCH_MOTION);
+}
+
+static void
+input_handle_touch_frame(void *data, struct wl_touch *touch)
+{
+	struct wayland_input *input = data;
+
+	notify_touch_frame(&input->base);
+}
+
+static void
+input_handle_touch_cancel(void *data, struct wl_touch *touch)
+{
+}
+
+static const struct wl_touch_listener touch_listener = {
+	input_handle_touch_down,
+	input_handle_touch_up,
+	input_handle_touch_motion,
+	input_handle_touch_frame,
+	input_handle_touch_cancel
+};
+
+static void
 input_handle_capabilities(void *data, struct wl_seat *seat,
 		          enum wl_seat_capability caps)
 {
@@ -1607,6 +1692,16 @@ input_handle_capabilities(void *data, struct wl_seat *seat,
 		wl_keyboard_destroy(input->parent.keyboard);
 		input->parent.keyboard = NULL;
 	}
+
+	if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->parent.touch) {
+		input->parent.touch = wl_seat_get_touch(seat);
+		wl_touch_set_user_data(input->parent.touch, input);
+		wl_touch_add_listener(input->parent.touch,
+					 &touch_listener, input);
+	} else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->parent.touch) {
+		wl_touch_destroy(input->parent.touch);
+		input->parent.touch = NULL;
+	}
 }
 
 static const struct wl_seat_listener seat_listener = {
-- 
1.9.2




More information about the wayland-devel mailing list