[PATCH 6/6] desktop-shell: resize background, panel and lock surface on output resize

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


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

> When an output is resized (permanent mode switch), we should also notify the
> shell client so that the panel, background and the lock screen fits to the
> new screen dimensions.
> 
> Signed-off-by: David Fort <contact at hardening-consulting.com>
> ---
>  desktop-shell/shell.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  desktop-shell/shell.h |  7 ++++++
>  2 files changed, 67 insertions(+)
> 
> diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
> index cd269a8..99dcd3e 100644
> --- a/desktop-shell/shell.c
> +++ b/desktop-shell/shell.c
> @@ -4375,6 +4375,16 @@ background_configure(struct weston_surface *es, int32_t sx, int32_t sy)
>  }
>  
>  static void
> +handle_background_surface_destroy(struct wl_listener *listener, void *data)
> +{
> +	struct desktop_shell *shell =
> +	    container_of(listener, struct desktop_shell, background_surface_listener);
> +
> +	weston_log("background surface gone\n");
> +	shell->background_surface = NULL;
> +}
> +
> +static void
>  desktop_shell_set_background(struct wl_client *client,
>  			     struct wl_resource *resource,
>  			     struct wl_resource *output_resource,
> @@ -4405,6 +4415,10 @@ desktop_shell_set_background(struct wl_client *client,
>  					    surface_resource,
>  					    surface->output->width,
>  					    surface->output->height);
> +	shell->background_surface = surface;
> +
> +	shell->background_surface_listener.notify = handle_background_surface_destroy;
> +	wl_signal_add(&surface->destroy_signal, &shell->background_surface_listener);

This will cause list corruption with multiple outputs.

>  }
>  
>  static int
> @@ -4426,6 +4440,17 @@ panel_configure(struct weston_surface *es, int32_t sx, int32_t sy)
>  }
>  
>  static void
> +handle_panel_surface_destroy(struct wl_listener *listener, void *data)
> +{
> +	struct desktop_shell *shell =
> +	    container_of(listener, struct desktop_shell, panel_surface_listener);
> +
> +	weston_log("panel surface gone\n");
> +	shell->panel_surface = NULL;
> +}
> +
> +
> +static void
>  desktop_shell_set_panel(struct wl_client *client,
>  			struct wl_resource *resource,
>  			struct wl_resource *output_resource,
> @@ -4456,6 +4481,10 @@ desktop_shell_set_panel(struct wl_client *client,
>  					    surface_resource,
>  					    surface->output->width,
>  					    surface->output->height);
> +
> +	shell->panel_surface_listener.notify = handle_panel_surface_destroy;
> +	wl_signal_add(&surface->destroy_signal, &shell->panel_surface_listener);
> +	shell->panel_surface = surface;

This will cause list corruption with multiple outputs.

>  }
>  
>  static int
> @@ -6368,11 +6397,40 @@ handle_output_destroy(struct wl_listener *listener, void *data)
>  	shell_for_each_layer(shell, shell_output_destroy_move_layer, output);
>  
>  	wl_list_remove(&output_listener->destroy_listener.link);
> +	wl_list_remove(&output_listener->resized_listener.link);
>  	wl_list_remove(&output_listener->link);
>  	free(output_listener);
>  }
>  
>  static void
> +shell_resize_surface_to_output(struct desktop_shell *shell,
> +				struct weston_surface *surface,
> +				const struct weston_output *output)
> +{
> +	if (!surface)
> +		return;
> +
> +	weston_desktop_shell_send_configure(shell->child.desktop_shell, 0,
> +					surface->resource,
> +					output->width,
> +					output->height);
> +}
> +
> +
> +static void
> +handle_output_resized(struct wl_listener *listener, void *data)
> +{
> +	struct shell_output *output_listener =

That is not a listener, that is a shell_output. You probably looked at
a place that actually had a struct myfoo_listener for an example, but
here it is not like that.

> +		container_of(listener, struct shell_output, resized_listener);
> +	struct weston_output *output = output_listener->output;
> +	struct desktop_shell *shell = output_listener->shell;
> +
> +	shell_resize_surface_to_output(shell, shell->background_surface, output);
> +	shell_resize_surface_to_output(shell, shell->panel_surface, output);
> +	shell_resize_surface_to_output(shell, shell->lock_surface, output);

I don't think we ever had the lock surface resized to fill the whole
output. The lock surface is not per-output anyway, there is only one
even with multiple outputs.

Handling the lock surface correctly will need more work. Not only you
need to ensure it stays centered, one should also tell it to resize
only as necessary. We currently do not send any resizing events to it,
AFAIK. The w-d-s client chooses the size. It also looks like w-d-s is
not expecting a configure event for the lock surface, and would crash
if it ever got one.

I suggest leaving the lock surface handling out of this patch, and
address it in anoether patch, if you want to fix it.

> +}
> +
> +static void
>  create_shell_output(struct desktop_shell *shell,
>  					struct weston_output *output)
>  {
> @@ -6387,6 +6445,8 @@ create_shell_output(struct desktop_shell *shell,
>  	shell_output->destroy_listener.notify = handle_output_destroy;
>  	wl_signal_add(&output->destroy_signal,
>  		      &shell_output->destroy_listener);
> +	shell_output->resized_listener.notify = handle_output_resized;
> +	wl_signal_add(&output->compositor->output_resized_signal, &shell_output->resized_listener);
>  	wl_list_insert(shell->output_list.prev, &shell_output->link);
>  }
>  
> diff --git a/desktop-shell/shell.h b/desktop-shell/shell.h
> index b430fa2..88e8155 100644
> --- a/desktop-shell/shell.h
> +++ b/desktop-shell/shell.h
> @@ -112,6 +112,7 @@ struct shell_output {
>  	struct desktop_shell  *shell;
>  	struct weston_output  *output;
>  	struct exposay_output eoutput;
> +	struct wl_listener    resized_listener;

Since the signal is compositor-wide, not per-output, but gets emitted
once for each output resizing, the listener should be compositor-wide
and not per-output, too.

If you register a listener for each output, you will get the number of
outputs times the callback when one output resizes.

>  	struct wl_listener    destroy_listener;
>  	struct wl_list        link;
>  };
> @@ -156,6 +157,12 @@ struct desktop_shell {
>  		pixman_box32_t cursor_rectangle;
>  	} text_input;
>  
> +	struct weston_surface *panel_surface;
> +	struct wl_listener panel_surface_listener;
> +
> +	struct weston_surface *background_surface;
> +	struct wl_listener background_surface_listener;
> +

These OTOH need to be per-output, since each output may have one.

>  	struct weston_surface *lock_surface;
>  	struct wl_listener lock_surface_listener;
>  

A good idea, everything is just in the wrong place. ;-)


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/87319abf/attachment.sig>


More information about the wayland-devel mailing list