commit df5eb5e0a8866fb4c9f711056d31972b6ae7cec9
parent 50b8225d2905440e6599e181e52a8912b006414e
Author: Michael Forney <mforney@mforney.org>
Date: Fri, 29 Nov 2013 23:43:50 -0800
Improve window surface destruction handling
Now, the free() is in the same file as the malloc(), and the shell
surface isn't destroyed until it's resource is destroyed.
Diffstat:
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/libswc/shell_surface.c b/libswc/shell_surface.c
@@ -34,6 +34,7 @@ struct swc_shell_surface
struct swc_window_internal window;
struct wl_resource * resource;
+ struct wl_listener surface_destroy_listener;
enum
{
@@ -169,6 +170,22 @@ static const struct swc_window_impl shell_window_impl = {
.configure = &configure
};
+static void handle_surface_destroy(struct wl_listener * listener, void * data)
+{
+ struct swc_shell_surface * shell_surface = CONTAINER_OF
+ (listener, typeof(*shell_surface), surface_destroy_listener);
+
+ wl_resource_destroy(shell_surface->resource);
+}
+
+static void destroy_shell_surface(struct wl_resource * resource)
+{
+ struct swc_shell_surface * shell_surface
+ = wl_resource_get_user_data(resource);
+
+ free(shell_surface);
+}
+
struct swc_shell_surface * swc_shell_surface_new
(struct wl_client * client, uint32_t id, struct swc_surface * surface)
{
@@ -180,6 +197,10 @@ struct swc_shell_surface * swc_shell_surface_new
goto error0;
shell_surface->type = SHELL_SURFACE_TYPE_UNSPECIFIED;
+ shell_surface->surface_destroy_listener.notify = &handle_surface_destroy;
+ wl_resource_add_destroy_listener(surface->resource,
+ &shell_surface->surface_destroy_listener);
+
swc_window_initialize(&shell_surface->window.base,
&shell_window_impl, surface);
@@ -191,7 +212,7 @@ struct swc_shell_surface * swc_shell_surface_new
wl_resource_set_implementation(shell_surface->resource,
&shell_surface_implementation,
- shell_surface, NULL);
+ shell_surface, &destroy_shell_surface);
return shell_surface;
diff --git a/libswc/window.c b/libswc/window.c
@@ -102,7 +102,7 @@ static void handle_surface_destroy(struct wl_listener * listener, void * data)
(listener, struct swc_window_internal, surface_destroy_listener)->base;
swc_send_event(&window->event_signal, SWC_WINDOW_DESTROYED, NULL);
- free(window);
+ swc_surface_set_class(INTERNAL(window)->surface, NULL);
}
EXPORT