Skip to content

Commit

Permalink
Destroy sub-surfaces with parent layer-shell surface
Browse files Browse the repository at this point in the history
Closes: swaywm#6337
  • Loading branch information
emersion authored and GorrillaRibs committed Jan 18, 2022
1 parent 778af19 commit 885387c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions include/sway/layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct sway_layer_surface {
bool mapped;
struct wlr_box extent;
enum zwlr_layer_shell_v1_layer layer;

struct wl_list subsurfaces;
};

struct sway_layer_popup {
Expand All @@ -44,6 +46,7 @@ struct sway_layer_popup {
struct sway_layer_subsurface {
struct wlr_subsurface *wlr_subsurface;
struct sway_layer_surface *layer_surface;
struct wl_list link;

struct wl_listener map;
struct wl_listener unmap;
Expand Down
25 changes: 20 additions & 5 deletions sway/desktop/layer_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ static void unmap(struct sway_layer_surface *sway_layer) {
sway_layer->layer_surface->surface, true);
}

static void layer_subsurface_destroy(struct sway_layer_subsurface *subsurface);

static void handle_destroy(struct wl_listener *listener, void *data) {
struct sway_layer_surface *sway_layer =
wl_container_of(listener, sway_layer, destroy);
Expand All @@ -360,6 +362,12 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
if (sway_layer->layer_surface->mapped) {
unmap(sway_layer);
}

struct sway_layer_subsurface *subsurface, *subsurface_tmp;
wl_list_for_each_safe(subsurface, subsurface_tmp, &sway_layer->subsurfaces, link) {
layer_subsurface_destroy(subsurface);
}

wl_list_remove(&sway_layer->link);
wl_list_remove(&sway_layer->destroy.link);
wl_list_remove(&sway_layer->map.link);
Expand Down Expand Up @@ -428,18 +436,22 @@ static void subsurface_handle_commit(struct wl_listener *listener, void *data) {
subsurface_damage(subsurface, false);
}

static void subsurface_handle_destroy(struct wl_listener *listener,
void *data) {
struct sway_layer_subsurface *subsurface =
wl_container_of(listener, subsurface, destroy);

static void layer_subsurface_destroy(struct sway_layer_subsurface *subsurface) {
wl_list_remove(&subsurface->link);
wl_list_remove(&subsurface->map.link);
wl_list_remove(&subsurface->unmap.link);
wl_list_remove(&subsurface->destroy.link);
wl_list_remove(&subsurface->commit.link);
free(subsurface);
}

static void subsurface_handle_destroy(struct wl_listener *listener,
void *data) {
struct sway_layer_subsurface *subsurface =
wl_container_of(listener, subsurface, destroy);
layer_subsurface_destroy(subsurface);
}

static struct sway_layer_subsurface *create_subsurface(
struct wlr_subsurface *wlr_subsurface,
struct sway_layer_surface *layer_surface) {
Expand All @@ -451,6 +463,7 @@ static struct sway_layer_subsurface *create_subsurface(

subsurface->wlr_subsurface = wlr_subsurface;
subsurface->layer_surface = layer_surface;
wl_list_insert(&layer_surface->subsurfaces, &subsurface->link);

subsurface->map.notify = subsurface_handle_map;
wl_signal_add(&wlr_subsurface->events.map, &subsurface->map);
Expand Down Expand Up @@ -643,6 +656,8 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
return;
}

wl_list_init(&sway_layer->subsurfaces);

sway_layer->surface_commit.notify = handle_surface_commit;
wl_signal_add(&layer_surface->surface->events.commit,
&sway_layer->surface_commit);
Expand Down

0 comments on commit 885387c

Please sign in to comment.