[PATCH 5/6] compositor: recompute output position on mode switch

Pekka Paalanen ppaalanen at gmail.com
Fri May 27 08:22:58 UTC 2016


On Tue, 26 Apr 2016 23:34:07 +0200
David Fort <rdp.effort at gmail.com> wrote:

> When an output permanently changes its resolution, the output on the right
> should be moved accordingly. We also add an event for output resizing so that
> plugins can react when an output is resized.
> 
> Signed-off-by: David Fort <contact at hardening-consulting.com>
> ---
>  src/compositor.c | 34 ++++++++++++++++++++++++----------
>  src/compositor.h |  1 +
>  2 files changed, 25 insertions(+), 10 deletions(-)
> 
> diff --git a/src/compositor.c b/src/compositor.c
> index b88936b..6653bb2 100644
> --- a/src/compositor.c
> +++ b/src/compositor.c
> @@ -143,6 +143,11 @@ static void weston_mode_switch_finish(struct weston_output *output,
>  	}
>  }
>  
> +
> +static void
> +weston_compositor_reflow_outputs(struct weston_compositor *compositor,
> +				struct weston_output *resized_output, int delta_width);
> +
>  WL_EXPORT int
>  weston_output_mode_set_native(struct weston_output *output,
>  			      struct weston_mode *mode,
> @@ -150,6 +155,7 @@ weston_output_mode_set_native(struct weston_output *output,
>  {
>  	int ret;
>  	int mode_changed = 0, scale_changed = 0;
> +	struct weston_mode *old_mode;
>  
>  	if (!output->switch_mode)
>  		return -1;
> @@ -165,11 +171,16 @@ weston_output_mode_set_native(struct weston_output *output,
>  		}
>  	}
>  
> +	old_mode = output->native_mode;
>  	output->native_mode = mode;
>  	output->native_scale = scale;
>  
>  	weston_mode_switch_finish(output, mode_changed, scale_changed);
>  
> +	if (old_mode)
> +		weston_compositor_reflow_outputs(output->compositor, output, mode->width - old_mode->width);

Hi,

I think you have to account for the scale here, too. Output position
and size are in global units, while mode width and height are in output
pixels, and the difference between those is the output scale.

Since weston_mode_switch_finish() is already called, you could just
inspect output->width instead of mode, and you should get the units
right directly.

> +
> +	wl_signal_emit(&output->compositor->output_resized_signal, output);
>  	return 0;
>  }
>  
> @@ -4047,23 +4058,25 @@ bind_output(struct wl_client *client,
>  		wl_output_send_done(resource);
>  }
>  
> -/* Move other outputs when one is removed so the space remains contiguos. */
> +/* Move other outputs when one is resized so the space remains contiguous. */
>  static void
> -weston_compositor_remove_output(struct weston_compositor *compositor,
> -				struct weston_output *remove_output)
> +weston_compositor_reflow_outputs(struct weston_compositor *compositor,
> +				struct weston_output *resized_output, int delta_width)
>  {
>  	struct weston_output *output;
> -	int offset = 0;
> +	bool start_resizing = false;
> +
> +	if (!delta_width)
> +		return;
>  
>  	wl_list_for_each(output, &compositor->output_list, link) {
> -		if (output == remove_output) {
> -			offset = output->width;
> +		if (output == resized_output) {
> +			start_resizing = true;
>  			continue;
>  		}
>  
> -		if (offset > 0) {
> -			weston_output_move(output,
> -					   output->x - offset, output->y);
> +		if (start_resizing) {
> +			weston_output_move(output, output->x + delta_width, output->y);
>  			output->dirty = 1;
>  		}
>  	}
> @@ -4086,7 +4099,7 @@ weston_output_destroy(struct weston_output *output)
>  
>  	weston_presentation_feedback_discard_list(&output->feedback_list);
>  
> -	weston_compositor_remove_output(output->compositor, output);
> +	weston_compositor_reflow_outputs(output->compositor, output, output->width);
>  	wl_list_remove(&output->link);
>  
>  	wl_signal_emit(&output->compositor->output_destroyed_signal, output);
> @@ -4706,6 +4719,7 @@ weston_compositor_create(struct wl_display *display, void *user_data)
>  	wl_signal_init(&ec->output_created_signal);
>  	wl_signal_init(&ec->output_destroyed_signal);
>  	wl_signal_init(&ec->output_moved_signal);
> +	wl_signal_init(&ec->output_resized_signal);
>  	wl_signal_init(&ec->session_signal);
>  	ec->session_active = 1;
>  
> diff --git a/src/compositor.h b/src/compositor.h
> index cb9df00..b71ade0 100644
> --- a/src/compositor.h
> +++ b/src/compositor.h
> @@ -743,6 +743,7 @@ struct weston_compositor {
>  	struct wl_signal output_created_signal;
>  	struct wl_signal output_destroyed_signal;
>  	struct wl_signal output_moved_signal;
> +	struct wl_signal output_resized_signal;

Please add a comment explaining what the callback data argument is.

>  
>  	struct wl_signal session_signal;
>  	int session_active;

With those two fixed:
Reviewed-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>


Thanks,
pq
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 811 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20160527/dbbf59b3/attachment.sig>


More information about the wayland-devel mailing list