[PATCH weston] Take into account the zoom when applying the output transform

Neil Roberts neil at linux.intel.com
Thu May 1 08:13:55 PDT 2014


When converting output-relative coordinates (such as from an input
event) to global coordinates it now takes into account the zoom
transform. Previously this would only work for the primary pointer
because the transform doesn't affect the primary pointer position due
to that way zoom follows the mouse. Touch events and multiple pointers
were not working correctly.

https://bugs.freedesktop.org/show_bug.cgi?id=68620
---
 src/compositor.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index ee8dc24..3d65e4c 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3333,6 +3333,7 @@ weston_output_transform_coordinate(struct weston_output *output,
 {
 	wl_fixed_t tx, ty;
 	wl_fixed_t width, height;
+	float zoom_scale, zx, zy;
 
 	width = wl_fixed_from_int(output->width * output->current_scale - 1);
 	height = wl_fixed_from_int(output->height * output->current_scale - 1);
@@ -3373,8 +3374,23 @@ weston_output_transform_coordinate(struct weston_output *output,
 		break;
 	}
 
-	*x = tx / output->current_scale + wl_fixed_from_int(output->x);
-	*y = ty / output->current_scale + wl_fixed_from_int(output->y);
+	tx /= output->current_scale;
+	ty /= output->current_scale;
+
+	if (output->zoom.active) {
+		zoom_scale = output->zoom.spring_z.current;
+		zx = (wl_fixed_to_double(tx) * (1.0f - zoom_scale) +
+		      output->width / 2.0f *
+		      (zoom_scale + output->zoom.trans_x));
+		zy = (wl_fixed_to_double(ty) * (1.0f - zoom_scale) +
+		      output->height / 2.0f *
+		      (zoom_scale + output->zoom.trans_y));
+		tx = wl_fixed_from_double(zx);
+		ty = wl_fixed_from_double(zy);
+	}
+
+	*x = tx + wl_fixed_from_int(output->x);
+	*y = ty + wl_fixed_from_int(output->y);
 }
 
 static void
-- 
1.9.0



More information about the wayland-devel mailing list