[PATCH weston 2/4 v2] Restructure output zoom.

Kristian Høgsberg hoegsberg at gmail.com
Tue May 22 09:33:36 PDT 2012


On Mon, May 21, 2012 at 03:21:25PM -0600, Scott Moreau wrote:
> A quick clean-up of zoom to prepare for the other patches in this series.

Committed.
Kristian

> ---
> 
> Rebased against master, 380deee3c7b18574d66511287bb01dde51027fbf
> 
>  src/compositor.c |   20 ++++++++++----------
>  src/compositor.h |    1 -
>  src/shell.c      |   13 ++++++++-----
>  3 files changed, 18 insertions(+), 16 deletions(-)
> 
> diff --git a/src/compositor.c b/src/compositor.c
> index 06e944f..75bda93 100644
> --- a/src/compositor.c
> +++ b/src/compositor.c
> @@ -2462,20 +2462,18 @@ weston_text_cursor_position_notify(struct weston_surface *surface,
>  WL_EXPORT void
>  weston_output_update_zoom(struct weston_output *output, wl_fixed_t fx, wl_fixed_t fy)
>  {
> -	float ratio;
>  	int32_t x, y;
>  
> -	if (output->zoom.level <= 0)
> +	if (output->zoom.level >= 1.0)
>  		return;
>  
>  	x = wl_fixed_to_int(fx);
>  	y = wl_fixed_to_int(fy);
>  
> -	output->zoom.magnification = 1 / output->zoom.level;
> -	ratio = 1 - (1 / output->zoom.magnification);
> -
> -	output->zoom.trans_x = (((float)(x - output->x) / output->current->width) * (ratio * 2)) - ratio;
> -	output->zoom.trans_y = (((float)(y - output->y) / output->current->height) * (ratio * 2)) - ratio;
> +	output->zoom.trans_x = (((float)(x - output->x) / output->current->width) *
> +					(output->zoom.level * 2)) - output->zoom.level;
> +	output->zoom.trans_y = (((float)(y - output->y) / output->current->height) *
> +					(output->zoom.level * 2)) - output->zoom.level;
>  
>  	output->dirty = 1;
>  	weston_output_damage(output);
> @@ -2485,6 +2483,7 @@ WL_EXPORT void
>  weston_output_update_matrix(struct weston_output *output)
>  {
>  	int flip;
> +	float magnification;
>  	struct weston_matrix camera;
>  	struct weston_matrix modelview;
>  
> @@ -2497,12 +2496,14 @@ weston_output_update_matrix(struct weston_output *output)
>  	weston_matrix_scale(&output->matrix,
>  			    2.0 / (output->current->width + output->border.left + output->border.right),
>  			    flip * 2.0 / (output->current->height + output->border.top + output->border.bottom), 1);
> +
>  	if (output->zoom.active) {
> +		magnification = 1 / (1 - output->zoom.level);
>  		weston_matrix_init(&camera);
>  		weston_matrix_init(&modelview);
>  		weston_matrix_translate(&camera, output->zoom.trans_x, flip * output->zoom.trans_y, 0);
>  		weston_matrix_invert(&modelview, &camera);
> -		weston_matrix_scale(&modelview, output->zoom.magnification, output->zoom.magnification, 1.0);
> +		weston_matrix_scale(&modelview, magnification, magnification, 1.0);
>  		weston_matrix_multiply(&output->matrix, &modelview);
>  	}
>  
> @@ -2539,8 +2540,7 @@ weston_output_init(struct weston_output *output, struct weston_compositor *c,
>  
>  	output->zoom.active = 0;
>  	output->zoom.increment = 0.05;
> -	output->zoom.level = 1.0;
> -	output->zoom.magnification = 1.0;
> +	output->zoom.level = 0.0;
>  	output->zoom.trans_x = 0.0;
>  	output->zoom.trans_y = 0.0;
>  
> diff --git a/src/compositor.h b/src/compositor.h
> index 59a97a7..1b3d08c 100644
> --- a/src/compositor.h
> +++ b/src/compositor.h
> @@ -77,7 +77,6 @@ struct weston_output_zoom {
>  	int active;
>  	float increment;
>  	float level;
> -	float magnification;
>  	float trans_x, trans_y;
>  };
>  
> diff --git a/src/shell.c b/src/shell.c
> index a4a98c7..6c9ee93 100644
> --- a/src/shell.c
> +++ b/src/shell.c
> @@ -1637,6 +1637,7 @@ zoom_binding(struct wl_seat *seat, uint32_t time,
>  	struct weston_seat *ws = (struct weston_seat *) seat;
>  	struct weston_compositor *compositor = ws->compositor;
>  	struct weston_output *output;
> +	float maximum_level;
>  
>  	wl_list_for_each(output, &compositor->output_list, link) {
>  		if (pixman_region32_contains_point(&output->region,
> @@ -1644,15 +1645,17 @@ zoom_binding(struct wl_seat *seat, uint32_t time,
>  						   wl_fixed_to_double(seat->pointer->y),
>  						   NULL)) {
>  			output->zoom.active = 1;
> -			output->zoom.level += output->zoom.increment * -value;
> +			output->zoom.level += output->zoom.increment * value;
>  
> -			if (output->zoom.level >= 1.0) {
> +			if (output->zoom.level <= 0.0) {
>  				output->zoom.active = 0;
> -				output->zoom.level = 1.0;
> +				output->zoom.level = 0.0;
>  			}
>  
> -			if (output->zoom.level < output->zoom.increment)
> -				output->zoom.level = output->zoom.increment;
> +			maximum_level = 1 - output->zoom.increment;
> +
> +			if (output->zoom.level > maximum_level)
> +				output->zoom.level = maximum_level;
>  
>  			weston_output_update_zoom(output,
>  			                          seat->pointer->x,
> -- 
> 1.7.7.6
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list