From: Pekka Paalanen <pekka.paala...@collabora.co.uk>

If for some reason the helper client weston-desktop-shell would create
more than one background surface for the same weston_output, this code
would corrupt the surface destroy listener list by adding a link already
in one list into another list.

Instead, do not store the new, redundant background surface and do not
subscribe to its destruction. Also, tell the helper that the surface is
redundant by configuring it with a 0x0 size, so that we don't waste
memory on a background that is never used.

(Clone mode is a valid reason why weston-desktop-shell could do that.)

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
---
 desktop-shell/shell.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index de76ebe5..331269ad 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -2971,16 +2971,27 @@ desktop_shell_set_background(struct wl_client *client,
        weston_surface_set_label_func(surface, background_get_label);
        surface->output = weston_output_from_resource(output_resource);
        view->output = surface->output;
-       weston_desktop_shell_send_configure(resource, 0,
-                                           surface_resource,
-                                           surface->output->width,
-                                           surface->output->height);
 
        sh_output = find_shell_output_from_weston_output(shell, 
surface->output);
-       sh_output->background_surface = surface;
+       if (sh_output->background_surface) {
+               /* The output already has a background, tell our helper
+                * there is no need for another one. */
+               weston_desktop_shell_send_configure(resource, 0,
+                                                   surface_resource,
+                                                   0, 0);
+       } else {
+               weston_desktop_shell_send_configure(resource, 0,
+                                                   surface_resource,
+                                                   surface->output->width,
+                                                   surface->output->height);
+
+               sh_output->background_surface = surface;
 
-       sh_output->background_surface_listener.notify = 
handle_background_surface_destroy;
-       wl_signal_add(&surface->destroy_signal, 
&sh_output->background_surface_listener);
+               sh_output->background_surface_listener.notify =
+                                       handle_background_surface_destroy;
+               wl_signal_add(&surface->destroy_signal,
+                             &sh_output->background_surface_listener);
+       }
 }
 
 static int
-- 
2.13.6

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to