examples/tinyds: Clean up all views when finish server 76/278176/1
authorSeunghun Lee <shiin.lee@samsung.com>
Wed, 20 Apr 2022 11:11:59 +0000 (20:11 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 18 Jul 2022 05:58:31 +0000 (14:58 +0900)
Even though all view would have been cleaned up by an destroy event of
xdg_surface, this is just to clean up views explicitly just in case.

No functional changes.

Change-Id: I3a91adb68d665b334c56f607975734a7e95dbcfd

src/examples/tinyds.c

index 0c88849..64aac83 100644 (file)
@@ -109,6 +109,7 @@ static void output_handle_frame(struct wl_listener *listener, void *data);
 static void draw_server(struct tinyds_server *server);
 static void draw_server_with_damage(struct tinyds_server *server);
 static void draw_output(struct tinyds_output *output);
+static void view_destroy(struct tinyds_view *view);
 static void draw_view(struct tinyds_view *view, pixman_image_t *dst_image);
 
 int
@@ -195,12 +196,7 @@ view_handle_xdg_surface_destroy(struct wl_listener *listener,
 
     draw_server_with_damage(view->server);
 
-    wl_list_remove(&view->xdg_surface_destroy.link);
-    wl_list_remove(&view->xdg_surface_map.link);
-    wl_list_remove(&view->xdg_surface_unmap.link);
-    wl_list_remove(&view->surface_commit.link);
-    wl_list_remove(&view->link);
-    free(view);
+    view_destroy(view);
 }
 
 static void
@@ -288,6 +284,11 @@ init_server(struct tinyds_server *server, struct wl_display *display)
 static void
 fini_server(struct tinyds_server *server)
 {
+    struct tinyds_view *view, *tmp;
+
+    wl_list_for_each_safe(view, tmp, &server->views, link)
+        view_destroy(view);
+
     wl_list_remove(&server->new_xdg_surface.link);
 }
 
@@ -419,6 +420,19 @@ out:
 }
 
 static void
+view_destroy(struct tinyds_view *view)
+{
+    ds_inf("View(%p) destroyed", view);
+
+    wl_list_remove(&view->xdg_surface_destroy.link);
+    wl_list_remove(&view->xdg_surface_map.link);
+    wl_list_remove(&view->xdg_surface_unmap.link);
+    wl_list_remove(&view->surface_commit.link);
+    wl_list_remove(&view->link);
+    free(view);
+}
+
+static void
 draw_view(struct tinyds_view *view, pixman_image_t *dst_image)
 {
     struct ds_buffer *buffer;