aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/wlr/types/wlr_compositor.h3
-rw-r--r--include/wlr/types/wlr_region.h3
-rw-r--r--types/wlr_compositor.c47
-rw-r--r--types/wlr_region.c10
4 files changed, 39 insertions, 24 deletions
diff --git a/include/wlr/types/wlr_compositor.h b/include/wlr/types/wlr_compositor.h
index 816ff713..5dd2ce98 100644
--- a/include/wlr/types/wlr_compositor.h
+++ b/include/wlr/types/wlr_compositor.h
@@ -15,7 +15,8 @@ struct wlr_compositor {
struct wl_global *wl_global;
struct wl_list wl_resources;
struct wlr_renderer *renderer;
- struct wl_list surfaces;
+ struct wl_list surface_resources;
+ struct wl_list region_resources;
struct wlr_subcompositor subcompositor;
diff --git a/include/wlr/types/wlr_region.h b/include/wlr/types/wlr_region.h
index ffacea72..a79ab61d 100644
--- a/include/wlr/types/wlr_region.h
+++ b/include/wlr/types/wlr_region.h
@@ -8,8 +8,7 @@ struct wl_resource;
/*
* Implements the given resource as region.
*/
-void wlr_region_create(struct wl_client *client, struct wl_resource *res,
- uint32_t id);
+struct wl_resource *wlr_region_create(struct wl_client *client, uint32_t id);
pixman_region32_t *wlr_region_from_resource(struct wl_resource *resource);
diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c
index 2d9eec0f..f9bd43fd 100644
--- a/types/wlr_compositor.c
+++ b/types/wlr_compositor.c
@@ -99,6 +99,10 @@ static void subcompositor_init(struct wlr_subcompositor *subcompositor,
static void subcompositor_finish(struct wlr_subcompositor *subcompositor) {
wl_global_destroy(subcompositor->wl_global);
+ struct wl_resource *resource, *tmp;
+ wl_resource_for_each_safe(resource, tmp, &subcompositor->wl_resources) {
+ wl_resource_destroy(resource);
+ }
}
@@ -111,7 +115,8 @@ static struct wlr_compositor *compositor_from_resource(
return wl_resource_get_user_data(resource);
}
-static void destroy_surface_listener(struct wl_listener *listener, void *data) {
+static void compositor_handle_surface_destroy(struct wl_listener *listener,
+ void *data) {
wl_list_remove(wl_resource_get_link(data));
}
@@ -134,35 +139,36 @@ static void wl_compositor_create_surface(struct wl_client *client,
return;
}
surface->compositor_data = compositor;
- surface->compositor_listener.notify = &destroy_surface_listener;
+ surface->compositor_listener.notify = compositor_handle_surface_destroy;
wl_resource_add_destroy_listener(surface_resource,
&surface->compositor_listener);
- wl_list_insert(&compositor->surfaces,
+ wl_list_insert(&compositor->surface_resources,
wl_resource_get_link(surface_resource));
wlr_signal_emit_safe(&compositor->events.new_surface, surface);
}
static void wl_compositor_create_region(struct wl_client *client,
struct wl_resource *resource, uint32_t id) {
- wlr_region_create(client, resource, id);
+ struct wlr_compositor *compositor = compositor_from_resource(resource);
+
+ struct wl_resource *region_resource = wlr_region_create(client, id);
+ if (region_resource == NULL) {
+ wl_resource_post_no_memory(resource);
+ return;
+ }
+
+ wl_list_insert(&compositor->region_resources,
+ wl_resource_get_link(region_resource));
}
static const struct wl_compositor_interface wl_compositor_impl = {
.create_surface = wl_compositor_create_surface,
- .create_region = wl_compositor_create_region
+ .create_region = wl_compositor_create_region,
};
static void wl_compositor_destroy(struct wl_resource *resource) {
- struct wlr_compositor *compositor = compositor_from_resource(resource);
- struct wl_resource *_resource = NULL;
- wl_resource_for_each(_resource, &compositor->wl_resources) {
- if (_resource == resource) {
- struct wl_list *link = wl_resource_get_link(_resource);
- wl_list_remove(link);
- break;
- }
- }
+ wl_list_remove(wl_resource_get_link(resource));
}
static void wl_compositor_bind(struct wl_client *wl_client, void *data,
@@ -189,6 +195,16 @@ void wlr_compositor_destroy(struct wlr_compositor *compositor) {
subcompositor_finish(&compositor->subcompositor);
wl_list_remove(&compositor->display_destroy.link);
wl_global_destroy(compositor->wl_global);
+ struct wl_resource *resource, *tmp;
+ wl_resource_for_each_safe(resource, tmp, &compositor->surface_resources) {
+ wl_resource_destroy(resource);
+ }
+ wl_resource_for_each_safe(resource, tmp, &compositor->region_resources) {
+ wl_resource_destroy(resource);
+ }
+ wl_resource_for_each_safe(resource, tmp, &compositor->wl_resources) {
+ wl_resource_destroy(resource);
+ }
free(compositor);
}
@@ -218,7 +234,8 @@ struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
compositor->renderer = renderer;
wl_list_init(&compositor->wl_resources);
- wl_list_init(&compositor->surfaces);
+ wl_list_init(&compositor->surface_resources);
+ wl_list_init(&compositor->region_resources);
wl_signal_init(&compositor->events.new_surface);
wl_signal_init(&compositor->events.destroy);
diff --git a/types/wlr_region.c b/types/wlr_region.c
index 6309c1a9..f452bbdf 100644
--- a/types/wlr_region.c
+++ b/types/wlr_region.c
@@ -38,12 +38,10 @@ static void destroy_region(struct wl_resource *resource) {
free(reg);
}
-void wlr_region_create(struct wl_client *client, struct wl_resource *res,
- uint32_t id) {
+struct wl_resource *wlr_region_create(struct wl_client *client, uint32_t id) {
pixman_region32_t *region = calloc(1, sizeof(pixman_region32_t));
if (region == NULL) {
- wl_resource_post_no_memory(res);
- return;
+ return NULL;
}
pixman_region32_init(region);
@@ -52,11 +50,11 @@ void wlr_region_create(struct wl_client *client, struct wl_resource *res,
&wl_region_interface, 1, id);
if (region_resource == NULL) {
free(region);
- wl_resource_post_no_memory(res);
- return;
+ return NULL;
}
wl_resource_set_implementation(region_resource, &region_impl, region,
destroy_region);
+ return region_resource;
}
pixman_region32_t *wlr_region_from_resource(struct wl_resource *resource) {