aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/view.c
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-11-26 23:57:33 +0100
committerLibravatar emersion <contact@emersion.fr>2018-11-27 11:46:30 +0100
commitfc79b7c2d27af881c57d193667d1efb2f7f90eb5 (patch)
tree3b45b771c4a0ff205de5431f043ad8b0298ba499 /sway/tree/view.c
parentMerge pull request #3175 from emersion/rename-gtk-primary-selection (diff)
downloadsway-fc79b7c2d27af881c57d193667d1efb2f7f90eb5.tar.gz
sway-fc79b7c2d27af881c57d193667d1efb2f7f90eb5.tar.zst
sway-fc79b7c2d27af881c57d193667d1efb2f7f90eb5.zip
Handle destroyed subsurfaces
Damage subsurfaces when they are destroyed. Since subsurfaces don't have an unmap event we need to do that on destroy. We also don't want to keep a sway_view_child when the wlr_subsurface has been destroyed. Fixes https://github.com/swaywm/sway/issues/3197
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r--sway/tree/view.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c
index febba3b9..c56b96f9 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -674,6 +674,8 @@ void view_update_size(struct sway_view *view, int width, int height) {
674 container_set_geometry_from_content(view->container); 674 container_set_geometry_from_content(view->container);
675} 675}
676 676
677static const struct sway_view_child_impl subsurface_impl;
678
677static void subsurface_get_root_coords(struct sway_view_child *child, 679static void subsurface_get_root_coords(struct sway_view_child *child,
678 int *root_sx, int *root_sy) { 680 int *root_sx, int *root_sy) {
679 struct wlr_surface *surface = child->surface; 681 struct wlr_surface *surface = child->surface;
@@ -689,18 +691,47 @@ static void subsurface_get_root_coords(struct sway_view_child *child,
689 } 691 }
690} 692}
691 693
694static void subsurface_destroy(struct sway_view_child *child) {
695 if (!sway_assert(child->impl == &subsurface_impl,
696 "Expected a subsurface")) {
697 return;
698 }
699 struct sway_subsurface *subsurface = (struct sway_subsurface *)child;
700 wl_list_remove(&subsurface->destroy.link);
701 free(subsurface);
702}
703
692static const struct sway_view_child_impl subsurface_impl = { 704static const struct sway_view_child_impl subsurface_impl = {
693 .get_root_coords = subsurface_get_root_coords, 705 .get_root_coords = subsurface_get_root_coords,
706 .destroy = subsurface_destroy,
694}; 707};
695 708
709static void view_child_damage(struct sway_view_child *child, bool whole);
710
711static void subsurface_handle_destroy(struct wl_listener *listener,
712 void *data) {
713 struct sway_subsurface *subsurface =
714 wl_container_of(listener, subsurface, destroy);
715 struct sway_view_child *child = &subsurface->child;
716 if (child->view->container != NULL) {
717 view_child_damage(child, true);
718 }
719 view_child_destroy(child);
720}
721
696static void view_subsurface_create(struct sway_view *view, 722static void view_subsurface_create(struct sway_view *view,
697 struct wlr_subsurface *subsurface) { 723 struct wlr_subsurface *wlr_subsurface) {
698 struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child)); 724 struct sway_subsurface *subsurface =
699 if (child == NULL) { 725 calloc(1, sizeof(struct sway_subsurface));
726 if (subsurface == NULL) {
700 wlr_log(WLR_ERROR, "Allocation failed"); 727 wlr_log(WLR_ERROR, "Allocation failed");
701 return; 728 return;
702 } 729 }
703 view_child_init(child, &subsurface_impl, view, subsurface->surface); 730 view_child_init(&subsurface->child, &subsurface_impl, view,
731 wlr_subsurface->surface);
732
733 wl_signal_add(&wlr_subsurface->events.destroy, &subsurface->destroy);
734 subsurface->destroy.notify = subsurface_handle_destroy;
704} 735}
705 736
706static void view_child_damage(struct sway_view_child *child, bool whole) { 737static void view_child_damage(struct sway_view_child *child, bool whole) {