From 5fe50b9a283f325cbc6e0dd4614192dddc298487 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 7 Jul 2018 23:02:08 +0100 Subject: output: make wl_output resources inert --- types/wlr_output.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index fc86f411..ccdc1978 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -85,9 +85,9 @@ static const struct wl_output_interface output_impl = { .release = output_handle_release, }; -static void wl_output_bind(struct wl_client *wl_client, void *data, +static void output_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { - struct wlr_output *wlr_output = data; + struct wlr_output *output = data; struct wl_resource *resource = wl_resource_create(wl_client, &wl_output_interface, version, id); @@ -95,9 +95,9 @@ static void wl_output_bind(struct wl_client *wl_client, void *data, wl_client_post_no_memory(wl_client); return; } - wl_resource_set_implementation(resource, &output_impl, wlr_output, + wl_resource_set_implementation(resource, &output_impl, output, output_handle_resource_destroy); - wl_list_insert(&wlr_output->wl_resources, wl_resource_get_link(resource)); + wl_list_insert(&output->wl_resources, wl_resource_get_link(resource)); output_send_to_resource(resource); } @@ -105,18 +105,23 @@ void wlr_output_create_global(struct wlr_output *output) { if (output->wl_global != NULL) { return; } - struct wl_global *wl_global = wl_global_create(output->display, - &wl_output_interface, OUTPUT_VERSION, output, wl_output_bind); - output->wl_global = wl_global; + output->wl_global = wl_global_create(output->display, + &wl_output_interface, OUTPUT_VERSION, output, output_bind); + if (output->wl_global == NULL) { + wlr_log(L_ERROR, "Failed to allocate wl_output global"); + } } void wlr_output_destroy_global(struct wlr_output *output) { if (output->wl_global == NULL) { return; } + // Make all output resources inert struct wl_resource *resource, *tmp; wl_resource_for_each_safe(resource, tmp, &output->wl_resources) { - wl_resource_destroy(resource); + wl_resource_set_user_data(resource, NULL); + wl_list_remove(wl_resource_get_link(resource)); + wl_list_init(wl_resource_get_link(resource)); } wl_global_destroy(output->wl_global); output->wl_global = NULL; -- cgit v1.2.3