Add layer_surface.close

This commit is contained in:
Drew DeVault 2018-03-24 18:00:01 -04:00
parent b73c4f48c1
commit d1c0e6fe2c
5 changed files with 43 additions and 4 deletions

View file

@ -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;

View file

@ -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

View file

@ -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"/>

View file

@ -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) {

View file

@ -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;