diff --git a/examples/layer-shell.c b/examples/layer-shell.c
index f3b9d3a0..08826251 100644
--- a/examples/layer-shell.c
+++ b/examples/layer-shell.c
@@ -25,6 +25,7 @@ static uint32_t output = 0;
static uint32_t layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
static uint32_t anchor = 0;
static int32_t width = 256, height = 256;
+static bool run_display = true;
static struct {
struct timespec last_frame;
@@ -84,8 +85,18 @@ static void layer_surface_configure(void *data,
zwlr_layer_surface_v1_ack_configure(surface, serial);
}
+static void layer_surface_closed(void *data,
+ struct zwlr_layer_surface_v1 *surface) {
+ eglDestroySurface(egl.display, egl_surface);
+ wl_egl_window_destroy(egl_window);
+ zwlr_layer_surface_v1_destroy(surface);
+ wl_surface_destroy(wl_surface);
+ run_display = false;
+}
+
struct zwlr_layer_surface_v1_listener layer_surface_listener = {
.configure = layer_surface_configure,
+ .closed = layer_surface_closed,
};
static void handle_global(void *data, struct wl_registry *registry,
@@ -235,7 +246,7 @@ int main(int argc, char **argv) {
wl_display_roundtrip(display);
draw();
- while (wl_display_dispatch(display) != -1) {
+ while (wl_display_dispatch(display) != -1 && run_display) {
// This space intentionally left blank
}
return 0;
diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h
index 3002345d..5d9feb27 100644
--- a/include/wlr/types/wlr_layer_shell.h
+++ b/include/wlr/types/wlr_layer_shell.h
@@ -67,7 +67,7 @@ struct wlr_layer_surface {
const char *namespace;
enum zwlr_layer_shell_v1_layer layer;
- bool added, configured, mapped;
+ bool added, configured, mapped, closed;
uint32_t configure_serial;
struct wl_event_source *configure_idle;
uint32_t configure_next_serial;
@@ -99,4 +99,9 @@ void wlr_layer_shell_destroy(struct wlr_layer_shell *layer_shell);
void wlr_layer_surface_configure(struct wlr_layer_surface *surface,
uint32_t width, uint32_t height);
+/**
+ * Unmaps this layer surface and notifies the client that it has been closed.
+ */
+void wlr_layer_surface_close(struct wlr_layer_surface *surface);
+
#endif
diff --git a/protocol/wlr-layer-shell-unstable-v1.xml b/protocol/wlr-layer-shell-unstable-v1.xml
index d6de59ab..b5cb3d3a 100644
--- a/protocol/wlr-layer-shell-unstable-v1.xml
+++ b/protocol/wlr-layer-shell-unstable-v1.xml
@@ -237,6 +237,16 @@
+
+
+ The closed event is sent by the compositor when the surface will no
+ longer be shown. The output may have been destroyed or the user may have
+ asked for it to be removed. Further changes to the surface will be ignored.
+ The client should destroy the resource after receiving this event, and
+ create a new surface if they so choose.
+
+
+
diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c
index ac7b2b20..114a5f29 100644
--- a/rootston/layer_shell.c
+++ b/rootston/layer_shell.c
@@ -118,7 +118,7 @@ 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);
+ wlr_layer_surface_close(layer->layer_surface);
}
static void handle_surface_commit(struct wl_listener *listener, void *data) {
@@ -135,7 +135,9 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
static void unmap(struct wlr_layer_surface *layer_surface) {
struct roots_layer_surface *layer = layer_surface->data;
- wl_list_remove(&layer->link);
+ if (layer->link.prev) {
+ wl_list_remove(&layer->link);
+ }
struct wlr_output *wlr_output = layer_surface->output;
if (wlr_output != NULL) {
diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c
index 631b7009..59f8d568 100644
--- a/types/wlr_layer_shell.c
+++ b/types/wlr_layer_shell.c
@@ -244,6 +244,12 @@ void wlr_layer_surface_configure(struct wlr_layer_surface *surface,
wlr_layer_surface_schedule_configure(surface);
}
+void wlr_layer_surface_close(struct wlr_layer_surface *surface) {
+ surface->closed = true;
+ layer_surface_unmap(surface);
+ zwlr_layer_surface_v1_send_closed(surface->resource);
+}
+
static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface,
void *role_data) {
struct wlr_layer_surface *surface = role_data;
@@ -255,6 +261,11 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface,
return;
}
+ if (surface->closed) {
+ // Ignore commits after the compositor has closed it
+ return;
+ }
+
surface->current.anchor = surface->client_pending.anchor;
surface->current.exclusive_zone = surface->client_pending.exclusive_zone;
surface->current.margin = surface->client_pending.margin;