From 83dc21feb14b48c2ea209012d4a6ec9712cb3ec7 Mon Sep 17 00:00:00 2001 From: tiosgz Date: Fri, 1 Jul 2022 15:26:23 +0000 Subject: [PATCH] output: While destroying, destroy layers Also handle NULL output in output_damage(). Co-authored-by: Uks2 --- kiwmi/desktop/layer_shell.c | 6 ++++-- kiwmi/desktop/output.c | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/kiwmi/desktop/layer_shell.c b/kiwmi/desktop/layer_shell.c index c908c6c..16290d2 100644 --- a/kiwmi/desktop/layer_shell.c +++ b/kiwmi/desktop/layer_shell.c @@ -24,12 +24,14 @@ kiwmi_layer_destroy_notify(struct wl_listener *listener, void *UNUSED(data)) { struct kiwmi_layer *layer = wl_container_of(listener, layer, destroy); - wl_list_remove(&layer->link); wl_list_remove(&layer->destroy.link); wl_list_remove(&layer->map.link); wl_list_remove(&layer->unmap.link); - arrange_layers(layer->output); + if (layer->output != NULL) { + wl_list_remove(&layer->link); + arrange_layers(layer->output); + } free(layer); } diff --git a/kiwmi/desktop/output.c b/kiwmi/desktop/output.c index 7054c31..52a832f 100644 --- a/kiwmi/desktop/output.c +++ b/kiwmi/desktop/output.c @@ -261,13 +261,26 @@ output_destroy_notify(struct wl_listener *listener, void *UNUSED(data)) { struct kiwmi_output *output = wl_container_of(listener, output, destroy); + wl_signal_emit(&output->events.destroy, output); + + int n_layers = sizeof(output->layers) / sizeof(output->layers[0]); + for (int i = 0; i < n_layers; i++) { + struct kiwmi_layer *layer; + struct kiwmi_layer *tmp; + wl_list_for_each_safe (layer, tmp, &output->layers[i], link) { + // Set output to NULL to avoid rearranging the remaining layers. + // Our impl requires that we remove the layer from the list. + layer->output = NULL; + wl_list_remove(&layer->link); + wlr_layer_surface_v1_destroy(layer->layer_surface); + } + } + if (output->desktop->output_layout) { wlr_output_layout_remove( output->desktop->output_layout, output->wlr_output); } - wl_signal_emit(&output->events.destroy, output); - wl_list_remove(&output->link); wl_list_remove(&output->frame.link); wl_list_remove(&output->commit.link); @@ -384,5 +397,7 @@ new_output_notify(struct wl_listener *listener, void *data) void output_damage(struct kiwmi_output *output) { - output->damaged = 2; + if (output != NULL) { + output->damaged = 2; + } }