From e63b70263a5dcd0e273b3ea8c233767363040646 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 22 Jul 2019 20:33:54 +0300 Subject: [PATCH] output: don't destroy global immediately Closes: https://github.com/swaywm/sway/issues/3625 --- types/wlr_output.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index 0d7e6858..2207c2e5 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -15,6 +15,7 @@ #include #include #include +#include "util/global.h" #include "util/signal.h" #define OUTPUT_VERSION 3 @@ -69,6 +70,7 @@ static const struct wl_output_interface output_impl = { static void output_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { + // `output` can be NULL if the output global is being destroyed struct wlr_output *output = data; struct wl_resource *resource = wl_resource_create(wl_client, @@ -79,6 +81,12 @@ static void output_bind(struct wl_client *wl_client, void *data, } wl_resource_set_implementation(resource, &output_impl, output, output_handle_resource_destroy); + + if (output == NULL) { + wl_list_init(wl_resource_get_link(resource)); + return; + } + wl_list_insert(&output->resources, wl_resource_get_link(resource)); send_geometry(resource); @@ -102,6 +110,7 @@ void wlr_output_destroy_global(struct wlr_output *output) { if (output->global == NULL) { return; } + // Make all output resources inert struct wl_resource *resource, *tmp; wl_resource_for_each_safe(resource, tmp, &output->resources) { @@ -109,7 +118,8 @@ void wlr_output_destroy_global(struct wlr_output *output) { wl_list_remove(wl_resource_get_link(resource)); wl_list_init(wl_resource_get_link(resource)); } - wl_global_destroy(output->global); + + wlr_global_destroy_safe(output->global, output->display); output->global = NULL; }