[PATCH weston v3 8/8] Convert wire input co-ordinates to signed_24_8

Daniel Stone daniel at fooishbar.org
Fri May 4 03:22:00 PDT 2012


To add greater precision when working with transformed surfaces and/or
high-resolution input devices.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 clients/simple-touch.c   |   20 ++++++++++----
 clients/window.c         |   22 +++++++++++-----
 src/compositor-wayland.c |    8 ++++--
 src/compositor.c         |   51 ++++++++++++++++++++++-------------
 src/shell.c              |   66 ++++++++++++++++++++++++----------------------
 tests/test-client.c      |   17 ++++++------
 6 files changed, 114 insertions(+), 70 deletions(-)

v3: Split from 7/7, typedefs are new, more conversion required.

diff --git a/clients/simple-touch.c b/clients/simple-touch.c
index 6da8aa6..384fcb9 100644
--- a/clients/simple-touch.c
+++ b/clients/simple-touch.c
@@ -103,7 +103,9 @@ struct wl_shm_listener shm_listenter = {
 
 static void
 input_device_handle_motion(void *data, struct wl_input_device *input_device,
-			   uint32_t time, int32_t sx, int32_t sy)
+			   uint32_t time,
+			   wl_signed_24_8_t sx_w,
+			   wl_signed_24_8_t sy_w)
 {
 }
 
@@ -132,7 +134,7 @@ static void
 input_device_handle_pointer_enter(void *data,
 				  struct wl_input_device *input_device,
 				  uint32_t serial, struct wl_surface *surface,
-				  int32_t sx, int32_t sy)
+				  wl_signed_24_8_t sx_w, wl_signed_24_8_t sy_w)
 {
 }
 
@@ -180,7 +182,7 @@ touch_paint(struct touch *touch, int32_t x, int32_t y, int32_t id)
 	    y < 1 || touch->height - 1 < y)
 		return;
 
-	p = (uint32_t *) touch->data + (x - 1) + (y -1 ) * touch->width;
+	p = (uint32_t *) touch->data + (x - 1) + (y - 1) * touch->width;
 	p[1] = c;
 	p += touch->width;
 	p[0] = c;
@@ -197,9 +199,13 @@ input_device_handle_touch_down(void *data,
 			       struct wl_input_device *wl_input_device,
 			       uint32_t serial, uint32_t time,
 			       struct wl_surface *surface,
-			       int32_t id, int32_t x, int32_t y)
+			       int32_t id,
+			       wl_signed_24_8_t x_w,
+			       wl_signed_24_8_t y_w)
 {
 	struct touch *touch = data;
+	double x = wl_signed_24_8_to_double(x_w);
+	double y = wl_signed_24_8_to_double(y_w);
 
 	touch_paint(touch, x, y, id);
 }
@@ -215,9 +221,13 @@ static void
 input_device_handle_touch_motion(void *data,
 				 struct wl_input_device *wl_input_device,
 				 uint32_t time,
-				 int32_t id, int32_t x, int32_t y)
+				 int32_t id,
+				 wl_signed_24_8_t x_w,
+				 wl_signed_24_8_t y_w)
 {
 	struct touch *touch = data;
+	double x = wl_signed_24_8_to_double(x_w);
+	double y = wl_signed_24_8_to_double(y_w);
 
 	touch_paint(touch, x, y, id);
 }
diff --git a/clients/window.c b/clients/window.c
index 0522af7..d29a31e 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -1342,12 +1342,14 @@ input_set_focus_widget(struct input *input, struct widget *focus,
 
 static void
 input_handle_motion(void *data, struct wl_input_device *input_device,
-		    uint32_t time, int32_t sx, int32_t sy)
+		    uint32_t time, wl_signed_24_8_t sx_w, wl_signed_24_8_t sy_w)
 {
 	struct input *input = data;
 	struct window *window = input->pointer_focus;
 	struct widget *widget;
 	int pointer = POINTER_LEFT_PTR;
+	double sx = wl_signed_24_8_to_double(sx_w);
+	double sy = wl_signed_24_8_to_double(sy_w);
 
 	input->sx = sx;
 	input->sy = sy;
@@ -1473,11 +1475,13 @@ static void
 input_handle_pointer_enter(void *data,
 			   struct wl_input_device *input_device,
 			   uint32_t serial, struct wl_surface *surface,
-			   int32_t sx, int32_t sy)
+			   wl_signed_24_8_t sx_w, wl_signed_24_8_t sy_w)
 {
 	struct input *input = data;
 	struct window *window;
 	struct widget *widget;
+	double sx = wl_signed_24_8_to_double(sx_w);
+	double sy = wl_signed_24_8_to_double(sy_w);
 
 	input->display->serial = serial;
 	input->pointer_enter_serial = serial;
@@ -1571,7 +1575,7 @@ input_handle_touch_down(void *data,
 			struct wl_input_device *wl_input_device,
 			uint32_t serial, uint32_t time,
 			struct wl_surface *surface,
-			int32_t id, int32_t x, int32_t y)
+			int32_t id, wl_signed_24_8_t x, wl_signed_24_8_t y)
 {
 }
 
@@ -1585,7 +1589,8 @@ input_handle_touch_up(void *data,
 static void
 input_handle_touch_motion(void *data,
 			  struct wl_input_device *wl_input_device,
-			  uint32_t time, int32_t id, int32_t x, int32_t y)
+			  uint32_t time, int32_t id,
+			  wl_signed_24_8_t x, wl_signed_24_8_t y)
 {
 }
 
@@ -1708,10 +1713,13 @@ data_device_data_offer(void *data,
 static void
 data_device_enter(void *data, struct wl_data_device *data_device,
 		  uint32_t serial, struct wl_surface *surface,
-		  int32_t x, int32_t y, struct wl_data_offer *offer)
+		  wl_signed_24_8_t x_w, wl_signed_24_8_t y_w,
+		  struct wl_data_offer *offer)
 {
 	struct input *input = data;
 	struct window *window;
+	double x = wl_signed_24_8_to_double(x_w);
+	double y = wl_signed_24_8_to_double(y_w);
 	char **p;
 
 	input->pointer_enter_serial = serial;
@@ -1740,10 +1748,12 @@ data_device_leave(void *data, struct wl_data_device *data_device)
 
 static void
 data_device_motion(void *data, struct wl_data_device *data_device,
-		   uint32_t time, int32_t x, int32_t y)
+		   uint32_t time, wl_signed_24_8_t x_w, wl_signed_24_8_t y_w)
 {
 	struct input *input = data;
 	struct window *window = input->pointer_focus;
+	double x = wl_signed_24_8_to_double(x_w);
+	double y = wl_signed_24_8_to_double(y_w);
 
 	input->sx = x;
 	input->sy = y;
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index 6b804f3..6c4b8c5 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -508,10 +508,12 @@ static const struct wl_output_listener output_listener = {
 /* parent input interface */
 static void
 input_handle_motion(void *data, struct wl_input_device *input_device,
-		    uint32_t time, int32_t sx, int32_t sy)
+		    uint32_t time, wl_signed_24_8_t sx_w, wl_signed_24_8_t sy_w)
 {
 	struct wayland_input *input = data;
 	struct wayland_compositor *c = input->compositor;
+	double sx = wl_signed_24_8_to_double(sx_w);
+	double sy = wl_signed_24_8_to_double(sy_w);
 
 	notify_motion(c->base.input_device, time,
 		      sx - c->border.left, sy - c->border.top);
@@ -553,11 +555,13 @@ static void
 input_handle_pointer_enter(void *data,
 			   struct wl_input_device *input_device,
 			   uint32_t time, struct wl_surface *surface,
-			   int32_t sx, int32_t sy)
+			   wl_signed_24_8_t sx_w, wl_signed_24_8_t sy_w)
 {
 	struct wayland_input *input = data;
 	struct wayland_output *output;
 	struct wayland_compositor *c = input->compositor;
+	double sx = wl_signed_24_8_to_double(sx_w);
+	double sy = wl_signed_24_8_to_double(sy_w);
 
 	output = wl_surface_get_user_data(surface);
 	notify_pointer_focus(c->base.input_device, &output->base, sx, sy);
diff --git a/src/compositor.c b/src/compositor.c
index 190a585..e0d60d1 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -600,14 +600,17 @@ weston_compositor_get_time(void)
 
 static struct weston_surface *
 weston_compositor_pick_surface(struct weston_compositor *compositor,
-			       int32_t x, int32_t y, int32_t *sx, int32_t *sy)
+			       wl_signed_24_8_t x, wl_signed_24_8_t y,
+			       wl_signed_24_8_t *sx, wl_signed_24_8_t *sy)
 {
 	struct weston_surface *surface;
 
 	wl_list_for_each(surface, &compositor->surface_list, link) {
-		weston_surface_from_global(surface, x, y, sx, sy);
+		weston_surface_from_global_248(surface, x, y, sx, sy);
 		if (pixman_region32_contains_point(&surface->input,
-						   *sx, *sy, NULL))
+						   wl_signed_24_8_to_int(*sx),
+						   wl_signed_24_8_to_int(*sy),
+						   NULL))
 			return surface;
 	}
 
@@ -635,8 +638,9 @@ weston_device_repick(struct wl_input_device *device)
 
 	focus = (struct weston_surface *) device->pointer_grab->focus;
 	if (focus)
-		weston_surface_from_global(focus, device->x, device->y,
-					   &device->pointer_grab->x, &device->pointer_grab->y);
+		weston_surface_from_global_248(focus, device->x, device->y,
+					       &device->pointer_grab->x,
+					       &device->pointer_grab->y);
 }
 
 WL_EXPORT void
@@ -1599,8 +1603,8 @@ notify_motion(struct wl_input_device *device, uint32_t time, double x, double y)
 	weston_input_update_drag_surface(device,
 					 x - device->x, y - device->y);
 
-	device->x = x;
-	device->y = y;
+	device->x = wl_signed_24_8_from_double(x);
+	device->y = wl_signed_24_8_from_double(y);
 
 	wl_list_for_each(output, &ec->output_list, link)
 		if (output->zoom.active &&
@@ -1612,11 +1616,13 @@ notify_motion(struct wl_input_device *device, uint32_t time, double x, double y)
 	interface->motion(device->pointer_grab, time,
 			  device->pointer_grab->x, device->pointer_grab->y);
 
+	x = wl_signed_24_8_to_double(device->x);
+	y = wl_signed_24_8_to_double(device->y);
+
 	if (wd->sprite) {
 		weston_surface_set_position(wd->sprite,
-					    device->x - wd->hotspot_x,
-					    device->y - wd->hotspot_y);
-
+					    x - wd->hotspot_x,
+					    y - wd->hotspot_y);
 		weston_compositor_schedule_repaint(ec);
 	}
 }
@@ -1775,11 +1781,12 @@ notify_pointer_focus(struct wl_input_device *device,
 	struct weston_compositor *compositor = wd->compositor;
 
 	if (output) {
-		weston_input_update_drag_surface(device, x - device->x,
-						 y - device->y);
+		weston_input_update_drag_surface(device,
+		                                 x - wl_signed_24_8_to_double(device->x),
+						 y - wl_signed_24_8_to_double(device->y));
 
-		device->x = x;
-		device->y = y;
+		device->x = wl_signed_24_8_from_double(x);
+		device->y = wl_signed_24_8_from_double(y);
 		compositor->focus = 1;
 		weston_compositor_repick(compositor);
 	} else {
@@ -1922,7 +1929,7 @@ notify_touch(struct wl_input_device *device, uint32_t time, int touch_id,
 	struct weston_input_device *wd = (struct weston_input_device *) device;
 	struct weston_compositor *ec = wd->compositor;
 	struct weston_surface *es;
-	int32_t sx, sy;
+	wl_signed_24_8_t sx, sy;
 	uint32_t serial = 0;
 
 	switch (touch_type) {
@@ -1939,12 +1946,17 @@ notify_touch(struct wl_input_device *device, uint32_t time, int touch_id,
 			touch_set_focus(wd, &es->surface);
 		} else if (wd->touch_focus) {
 			es = (struct weston_surface *) wd->touch_focus;
-			weston_surface_from_global(es, x, y, &sx, &sy);
+			weston_surface_from_global_248(es,
+			                               wl_signed_24_8_from_double(x),
+						       wl_signed_24_8_from_double(y),
+						       &sx,
+						       &sy);
 		}
 
 		if (wd->touch_focus_resource && wd->touch_focus)
 			wl_input_device_send_touch_down(wd->touch_focus_resource,
-							serial, time, &wd->touch_focus->resource,
+							serial, time,
+							&wd->touch_focus->resource,
 							touch_id, sx, sy);
 		break;
 	case WL_INPUT_DEVICE_TOUCH_MOTION:
@@ -1952,7 +1964,10 @@ notify_touch(struct wl_input_device *device, uint32_t time, int touch_id,
 		if (!es)
 			break;
 
-		weston_surface_from_global(es, x, y, &sx, &sy);
+		weston_surface_from_global_248(es,
+		                               wl_signed_24_8_from_double(x),
+					       wl_signed_24_8_from_double(y),
+					       &sx, &sy);
 		if (wd->touch_focus_resource)
 			wl_input_device_send_touch_motion(wd->touch_focus_resource,
 							  time, touch_id, sx, sy);
diff --git a/src/shell.c b/src/shell.c
index 437a72e..95b133a 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -165,7 +165,7 @@ struct shell_grab {
 
 struct weston_move_grab {
 	struct shell_grab base;
-	int32_t dx, dy;
+	wl_signed_24_8_t dx, dy;
 };
 
 struct rotate_grab {
@@ -307,7 +307,7 @@ noop_grab_focus(struct wl_pointer_grab *grab,
 
 static void
 move_grab_motion(struct wl_pointer_grab *grab,
-		 uint32_t time, int32_t x, int32_t y)
+		 uint32_t time, wl_signed_24_8_t x, wl_signed_24_8_t y)
 {
 	struct weston_move_grab *move = (struct weston_move_grab *) grab;
 	struct wl_input_device *device = grab->input_device;
@@ -320,8 +320,8 @@ move_grab_motion(struct wl_pointer_grab *grab,
 	es = shsurf->surface;
 
 	weston_surface_configure(es,
-				 device->x + move->dx,
-				 device->y + move->dy,
+				 wl_signed_24_8_to_int(device->x) + move->dx,
+				 wl_signed_24_8_to_int(device->y) + move->dy,
 				 es->geometry.width, es->geometry.height);
 }
 
@@ -513,8 +513,8 @@ weston_surface_move(struct weston_surface *es,
 
 	shell_grab_init(&move->base, &move_grab_interface, shsurf);
 
-	move->dx = es->geometry.x - wd->input_device.grab_x;
-	move->dy = es->geometry.y - wd->input_device.grab_y;
+	move->dx = es->geometry.x - wl_signed_24_8_to_int(wd->input_device.grab_x);
+	move->dy = es->geometry.y - wl_signed_24_8_to_int(wd->input_device.grab_y);
 
 	wl_input_device_start_pointer_grab(&wd->input_device,
 					   &move->base.grab);
@@ -548,37 +548,35 @@ struct weston_resize_grab {
 
 static void
 resize_grab_motion(struct wl_pointer_grab *grab,
-		   uint32_t time, int32_t x, int32_t y)
+		   uint32_t time, wl_signed_24_8_t x, wl_signed_24_8_t y)
 {
 	struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
 	struct wl_input_device *device = grab->input_device;
 	int32_t width, height;
-	int32_t from_x, from_y;
-	int32_t to_x, to_y;
+	wl_signed_24_8_t from_x, from_y;
+	wl_signed_24_8_t to_x, to_y;
 
 	if (!resize->base.shsurf)
 		return;
 
-	weston_surface_from_global(resize->base.shsurf->surface,
-				   device->grab_x, device->grab_y,
-				   &from_x, &from_y);
-	weston_surface_from_global(resize->base.shsurf->surface,
-				   device->x, device->y, &to_x, &to_y);
+	weston_surface_from_global_248(resize->base.shsurf->surface,
+				       device->grab_x, device->grab_y,
+				       &from_x, &from_y);
+	weston_surface_from_global_248(resize->base.shsurf->surface,
+				       device->x, device->y, &to_x, &to_y);
 
+	width = resize->width;
 	if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
-		width = resize->width + from_x - to_x;
+		width += wl_signed_24_8_to_int(from_x - to_x);
 	} else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
-		width = resize->width + to_x - from_x;
-	} else {
-		width = resize->width;
+		width += wl_signed_24_8_to_int(to_x - from_x);
 	}
 
+	height = resize->height;
 	if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
-		height = resize->height + from_y - to_y;
+		height += wl_signed_24_8_to_int(from_y - to_y);
 	} else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
-		height = resize->height + to_y - from_y;
-	} else {
-		height = resize->height;
+		height += wl_signed_24_8_to_int(to_y - from_y);
 	}
 
 	wl_shell_surface_send_configure(&resize->base.shsurf->resource,
@@ -1033,7 +1031,9 @@ shell_surface_set_fullscreen(struct wl_client *client,
 
 static void
 popup_grab_focus(struct wl_pointer_grab *grab,
-		 struct wl_surface *surface, int32_t x, int32_t y)
+		 struct wl_surface *surface,
+		 wl_signed_24_8_t x,
+		 wl_signed_24_8_t y)
 {
 	struct wl_input_device *device = grab->input_device;
 	struct shell_surface *priv =
@@ -1051,7 +1051,7 @@ popup_grab_focus(struct wl_pointer_grab *grab,
 
 static void
 popup_grab_motion(struct wl_pointer_grab *grab,
-		  uint32_t time, int32_t sx, int32_t sy)
+		  uint32_t time, wl_signed_24_8_t sx, wl_signed_24_8_t sy)
 {
 	struct wl_resource *resource;
 
@@ -1617,7 +1617,9 @@ zoom_binding(struct wl_input_device *device, uint32_t time,
 
 	wl_list_for_each(output, &compositor->output_list, link) {
 		if (pixman_region32_contains_point(&output->region,
-						device->x, device->y, NULL)) {
+						   wl_signed_24_8_to_double(device->x),
+						   wl_signed_24_8_to_double(device->y),
+						   NULL)) {
 			output->zoom.active = 1;
 			output->zoom.level += output->zoom.increment * -value;
 
@@ -1629,7 +1631,9 @@ zoom_binding(struct wl_input_device *device, uint32_t time,
 			if (output->zoom.level < output->zoom.increment)
 				output->zoom.level = output->zoom.increment;
 
-			weston_output_update_zoom(output, device->x, device->y);
+			weston_output_update_zoom(output,
+			                          wl_signed_24_8_to_int(device->x),
+						  wl_signed_24_8_to_int(device->y));
 		}
 	}
 }
@@ -1647,7 +1651,7 @@ terminate_binding(struct wl_input_device *device, uint32_t time,
 
 static void
 rotate_grab_motion(struct wl_pointer_grab *grab,
-		 uint32_t time, int32_t x, int32_t y)
+		   uint32_t time, wl_signed_24_8_t x, wl_signed_24_8_t y)
 {
 	struct rotate_grab *rotate =
 		container_of(grab, struct rotate_grab, base.grab);
@@ -1664,8 +1668,8 @@ rotate_grab_motion(struct wl_pointer_grab *grab,
 	cx = 0.5f * surface->geometry.width;
 	cy = 0.5f * surface->geometry.height;
 
-	dx = device->x - rotate->center.x;
-	dy = device->y - rotate->center.y;
+	dx = wl_signed_24_8_to_double(device->x) - rotate->center.x;
+	dy = wl_signed_24_8_to_double(device->y) - rotate->center.y;
 	r = sqrtf(dx * dx + dy * dy);
 
 	wl_list_remove(&shsurf->rotation.transform.link);
@@ -1781,8 +1785,8 @@ rotate_binding(struct wl_input_device *device, uint32_t time,
 
 	wl_input_device_start_pointer_grab(device, &rotate->base.grab);
 
-	dx = device->x - rotate->center.x;
-	dy = device->y - rotate->center.y;
+	dx = wl_signed_24_8_to_double(device->x) - rotate->center.x;
+	dy = wl_signed_24_8_to_double(device->y) - rotate->center.y;
 	r = sqrtf(dx * dx + dy * dy);
 	if (r > 20.0f) {
 		struct weston_matrix inverse;
diff --git a/tests/test-client.c b/tests/test-client.c
index 4b03fa6..b1dc98a 100644
--- a/tests/test-client.c
+++ b/tests/test-client.c
@@ -56,12 +56,12 @@ struct surface {
 
 static void
 input_handle_motion(void *data, struct wl_input_device *input_device,
-		    uint32_t time, int32_t x, int32_t y)
+		    uint32_t time, wl_signed_24_8_t x, wl_signed_24_8_t y)
 {
 	struct input *input = data;
 
-	input->x = x;
-	input->y = y;
+	input->x = wl_signed_24_8_to_double(x);
+	input->y = wl_signed_24_8_to_double(y);
 }
 
 static void
@@ -96,13 +96,13 @@ static void
 input_handle_pointer_enter(void *data,
 			   struct wl_input_device *input_device,
 			   uint32_t serial, struct wl_surface *surface,
-			   int32_t x, int32_t y)
+			   wl_signed_24_8_t x, wl_signed_24_8_t y)
 {
 	struct input *input = data;
 
 	input->pointer_focus = wl_surface_get_user_data(surface);
-	input->x = x;
-	input->y = y;
+	input->x = wl_signed_24_8_to_double(x);
+	input->y = wl_signed_24_8_to_double(y);
 }
 
 static void
@@ -143,7 +143,7 @@ input_handle_touch_down(void *data,
 			struct wl_input_device *wl_input_device,
 			uint32_t serial, uint32_t time,
 			struct wl_surface *surface,
-			int32_t id, int32_t x, int32_t y)
+			int32_t id, wl_signed_24_8_t x, wl_signed_24_8_t y)
 {
 }
 
@@ -157,7 +157,8 @@ input_handle_touch_up(void *data,
 static void
 input_handle_touch_motion(void *data,
 			  struct wl_input_device *wl_input_device,
-			  uint32_t time, int32_t id, int32_t x, int32_t y)
+			  uint32_t time, int32_t id,
+			  wl_signed_24_8_t x, wl_signed_24_8_t y)
 {
 }
 
-- 
1.7.10



More information about the wayland-devel mailing list