From 8c98c188808e16f18349a89eb534e2bbf7ea65d8 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 20 Mar 2018 21:41:18 -0400 Subject: [PATCH] Gracefully deal with outputs being removed --- include/rootston/layers.h | 1 + rootston/layer_shell.c | 42 ++++++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/include/rootston/layers.h b/include/rootston/layers.h index f432d53d..43041786 100644 --- a/include/rootston/layers.h +++ b/include/rootston/layers.h @@ -14,6 +14,7 @@ struct roots_layer_surface { struct wl_listener map; struct wl_listener unmap; struct wl_listener surface_commit; + struct wl_listener output_destroy; bool configured; struct wlr_box geo; diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index 73addb7a..c0dff85a 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -114,13 +114,34 @@ static void arrange_layers(struct wlr_output *_output) { } } +static void handle_output_destroy(struct wl_listener *listener, void *data) { + struct roots_layer_surface *layer = + wl_container_of(listener, layer, output_destroy); + layer->layer_surface->output = NULL; + wl_resource_destroy(layer->layer_surface->resource); +} + +static void handle_surface_commit(struct wl_listener *listener, void *data) { + struct roots_layer_surface *layer = + wl_container_of(listener, layer, surface_commit); + struct wlr_layer_surface *layer_surface = layer->layer_surface; + struct wlr_output *wlr_output = layer_surface->output; + if (wlr_output != NULL) { + struct roots_output *output = wlr_output->data; + output_damage_from_local_surface(output, layer_surface->surface, + layer->geo.x, layer->geo.y, 0); + } +} + static void unmap(struct wlr_layer_surface *layer_surface) { struct roots_layer_surface *layer = layer_surface->data; wl_list_remove(&layer->link); struct wlr_output *wlr_output = layer_surface->output; - struct roots_output *output = wlr_output->data; - wlr_output_damage_add_box(output->damage, &layer->geo); + if (wlr_output != NULL) { + struct roots_output *output = wlr_output->data; + wlr_output_damage_add_box(output->damage, &layer->geo); + } } static void handle_destroy(struct wl_listener *listener, void *data) { @@ -129,19 +150,10 @@ static void handle_destroy(struct wl_listener *listener, void *data) { if (layer->layer_surface->mapped) { unmap(layer->layer_surface); } + wl_list_remove(&layer->output_destroy.link); free(layer); } -static void handle_surface_commit(struct wl_listener *listener, void *data) { - struct roots_layer_surface *layer = - wl_container_of(listener, layer, surface_commit); - struct wlr_layer_surface *layer_surface = layer->layer_surface; - struct wlr_output *wlr_output = layer_surface->output; - struct roots_output *output = wlr_output->data; - output_damage_from_local_surface(output, layer_surface->surface, - layer->geo.x, layer->geo.y, 0); -} - static void handle_map(struct wl_listener *listener, void *data) { struct wlr_layer_surface *layer_surface = data; struct roots_layer_surface *layer = layer_surface->data; @@ -174,9 +186,15 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { if (!roots_surface) { return; } + roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&layer_surface->surface->events.commit, &roots_surface->surface_commit); + + roots_surface->output_destroy.notify = handle_output_destroy; + wl_signal_add(&layer_surface->output->events.destroy, + &roots_surface->output_destroy); + roots_surface->destroy.notify = handle_destroy; wl_signal_add(&layer_surface->events.destroy, &roots_surface->destroy); roots_surface->map.notify = handle_map;