desktop-shell: Do not try to add a child to a non-existent parent
authorMarius Vlad <marius.vlad@collabora.com>
Fri, 17 Jan 2020 10:32:55 +0000 (12:32 +0200)
committerMarius Vlad <marius.vlad@collabora.com>
Fri, 17 Jan 2020 10:47:32 +0000 (12:47 +0200)
Introduced with a8da2084, it seems that there are cases when there's no
parent available (zenity, for instance).

Removes any potential child and re-initialize it, in case the parent is
not set. (Simon Ser)

Fixes: #340
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Reviewed-by: Simon Ser <contact@emersion.fr>
Reported-by: n3rdopolis <bluescreenavenger@gmail.com>
desktop-shell/shell.c

index 7d9d703c025235372b85ecb5e7628c037945e416..442a625f8da6ab45e16b275043ec90bb41f86051 100644 (file)
@@ -2769,13 +2769,20 @@ desktop_surface_set_parent(struct weston_desktop_surface *desktop_surface,
                           struct weston_desktop_surface *parent,
                           void *shell)
 {
+       struct shell_surface *shsurf_parent;
        struct shell_surface *shsurf =
                weston_desktop_surface_get_user_data(desktop_surface);
-       struct shell_surface *shsurf_parent =
-               weston_desktop_surface_get_user_data(parent);
 
-       wl_list_insert(shsurf_parent->children_list.prev,
-                      &shsurf->children_link);
+       /* unlink any potential child */
+       wl_list_remove(&shsurf->children_link);
+
+       if (parent) {
+               shsurf_parent = weston_desktop_surface_get_user_data(parent);
+               wl_list_insert(shsurf_parent->children_list.prev,
+                              &shsurf->children_link);
+       } else {
+               wl_list_init(&shsurf->children_link);
+       }
 }
 
 static void