Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle destroyed subsurfaces #3199

Merged
merged 2 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/sway/tree/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ struct sway_view_child {
struct wl_listener surface_destroy;
};

struct sway_subsurface {
struct sway_view_child child;

struct wl_listener destroy;
};

struct sway_xdg_popup_v6 {
struct sway_view_child child;

Expand Down
40 changes: 36 additions & 4 deletions sway/tree/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,8 @@ void view_update_size(struct sway_view *view, int width, int height) {
container_set_geometry_from_content(view->container);
}

static const struct sway_view_child_impl subsurface_impl;

static void subsurface_get_root_coords(struct sway_view_child *child,
int *root_sx, int *root_sy) {
struct wlr_surface *surface = child->surface;
Expand All @@ -689,18 +691,44 @@ static void subsurface_get_root_coords(struct sway_view_child *child,
}
}

static void subsurface_destroy(struct sway_view_child *child) {
if (!sway_assert(child->impl == &subsurface_impl,
"Expected a subsurface")) {
return;
}
struct sway_subsurface *subsurface = (struct sway_subsurface *)child;
wl_list_remove(&subsurface->destroy.link);
free(subsurface);
}

static const struct sway_view_child_impl subsurface_impl = {
.get_root_coords = subsurface_get_root_coords,
.destroy = subsurface_destroy,
};

static void view_child_damage(struct sway_view_child *child, bool whole);

static void subsurface_handle_destroy(struct wl_listener *listener,
void *data) {
struct sway_subsurface *subsurface =
wl_container_of(listener, subsurface, destroy);
struct sway_view_child *child = &subsurface->child;
view_child_destroy(child);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this mean we call view_child_destroy twice now? view_child_init already sets up a listener on the surface's destroy event and calls it from the destroy handler.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have two objects: the wl_surface itself and the wl_subsurface. This listener is listening on the subsurface destroy event.

Destructors remove all listeners, so we should be fine if one is called before the other.

}

static void view_subsurface_create(struct sway_view *view,
struct wlr_subsurface *subsurface) {
struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child));
if (child == NULL) {
struct wlr_subsurface *wlr_subsurface) {
struct sway_subsurface *subsurface =
calloc(1, sizeof(struct sway_subsurface));
if (subsurface == NULL) {
wlr_log(WLR_ERROR, "Allocation failed");
return;
}
view_child_init(child, &subsurface_impl, view, subsurface->surface);
view_child_init(&subsurface->child, &subsurface_impl, view,
wlr_subsurface->surface);

wl_signal_add(&wlr_subsurface->events.destroy, &subsurface->destroy);
subsurface->destroy.notify = subsurface_handle_destroy;
}

static void view_child_damage(struct sway_view_child *child, bool whole) {
Expand Down Expand Up @@ -781,6 +809,10 @@ void view_child_init(struct sway_view_child *child,
}

void view_child_destroy(struct sway_view_child *child) {
if (child->view->container != NULL) {
view_child_damage(child, true);
}

wl_list_remove(&child->surface_commit.link);
wl_list_remove(&child->surface_destroy.link);

Expand Down