diff options
-rw-r--r-- | include/sway/tree/view.h | 6 | ||||
-rw-r--r-- | sway/tree/view.c | 39 |
2 files changed, 41 insertions, 4 deletions
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 4716c688..d74f1bc9 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h | |||
@@ -203,6 +203,12 @@ struct sway_view_child { | |||
203 | struct wl_listener surface_destroy; | 203 | struct wl_listener surface_destroy; |
204 | }; | 204 | }; |
205 | 205 | ||
206 | struct sway_subsurface { | ||
207 | struct sway_view_child child; | ||
208 | |||
209 | struct wl_listener destroy; | ||
210 | }; | ||
211 | |||
206 | struct sway_xdg_popup_v6 { | 212 | struct sway_xdg_popup_v6 { |
207 | struct sway_view_child child; | 213 | struct sway_view_child child; |
208 | 214 | ||
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 | ||
677 | static const struct sway_view_child_impl subsurface_impl; | ||
678 | |||
677 | static void subsurface_get_root_coords(struct sway_view_child *child, | 679 | static 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 | ||
694 | static 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 | |||
692 | static const struct sway_view_child_impl subsurface_impl = { | 704 | static 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 | ||
709 | static void view_child_damage(struct sway_view_child *child, bool whole); | ||
710 | |||
711 | static 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 | |||
696 | static void view_subsurface_create(struct sway_view *view, | 722 | static 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 | ||
706 | static void view_child_damage(struct sway_view_child *child, bool whole) { | 737 | static void view_child_damage(struct sway_view_child *child, bool whole) { |