aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-03-24 18:00:01 -0400
committerDrew DeVault <sir@cmpwn.com>2018-03-27 18:50:32 -0400
commitd1c0e6fe2c21b4c7f651a82fb7342b54a4989c39 (patch)
tree2267e9a27e454f09c3145ddbffaa1ec91de9b556
parentb73c4f48c10ae79a33d1611fb641d22b8b619c39 (diff)
Add layer_surface.close
-rw-r--r--examples/layer-shell.c13
-rw-r--r--include/wlr/types/wlr_layer_shell.h7
-rw-r--r--protocol/wlr-layer-shell-unstable-v1.xml10
-rw-r--r--rootston/layer_shell.c6
-rw-r--r--types/wlr_layer_shell.c11
5 files changed, 43 insertions, 4 deletions
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 @@
<arg name="height" type="uint"/>
</event>
+ <event name="closed">
+ <description summary="surface should be closed">
+ 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.
+ </description>
+ </event>
+
<enum name="error">
<entry name="invalid_surface_state" value="0" summary="provided surface state is invalid"/>
<entry name="invalid_size" value="1" summary="size is invalid"/>
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;