From d0ca22b59f381154a352c4986486e386b29fb902 Mon Sep 17 00:00:00 2001 From: Stuart Dilts Date: Sat, 2 Nov 2024 21:12:52 -0600 Subject: [PATCH] hrt: properly cleanup destroyed views Free and destroy the wlr_scene objects associated with it. --- heart/include/hrt/hrt_view.h | 5 +++++ heart/include/view_impl.h | 13 +++++++++++++ heart/src/view.c | 9 +++++++++ heart/src/xdg_shell.c | 2 ++ 4 files changed, 29 insertions(+) create mode 100644 heart/include/view_impl.h diff --git a/heart/include/hrt/hrt_view.h b/heart/include/hrt/hrt_view.h index de8351d..4c660e9 100644 --- a/heart/include/hrt/hrt_view.h +++ b/heart/include/hrt/hrt_view.h @@ -1,3 +1,6 @@ +#ifndef HRT_VIEW +#define HRT_VIEW + #include #include #include @@ -61,3 +64,5 @@ void hrt_view_focus(struct hrt_view *view, struct hrt_seat *seat); * Unfocus the given view. **/ void hrt_view_unfocus(struct hrt_view *view, struct hrt_seat *seat); + +#endif diff --git a/heart/include/view_impl.h b/heart/include/view_impl.h new file mode 100644 index 0000000..01b8b34 --- /dev/null +++ b/heart/include/view_impl.h @@ -0,0 +1,13 @@ +#ifndef HRT_VIEW_IMPL +#define HRT_VIEW_IMPL + +struct hrt_view; + +/** + * Cleanup the data initizlized during the hrt_view_init function + * This is internal, as it doesn't clean up everything and relies on + * other internal code to completely cleanup after a view. + */ +void hrt_view_cleanup(struct hrt_view *view); + +#endif diff --git a/heart/src/view.c b/heart/src/view.c index 38113aa..c3261a9 100644 --- a/heart/src/view.c +++ b/heart/src/view.c @@ -20,6 +20,15 @@ void hrt_view_init(struct hrt_view *view, struct wlr_scene_tree *tree) { view->xdg_surface->data = xdg_tree; } +void hrt_view_cleanup(struct hrt_view *view) { + if(view->xdg_surface->data) { + wlr_scene_node_destroy(view->xdg_surface->data); + } + if(view->scene_tree) { + wlr_scene_node_destroy(&view->scene_tree->node); + } +} + uint32_t hrt_view_set_size(struct hrt_view *view, int width, int height) { view->width = width; view->height = height; diff --git a/heart/src/xdg_shell.c b/heart/src/xdg_shell.c index 0feae8a..cc0882a 100644 --- a/heart/src/xdg_shell.c +++ b/heart/src/xdg_shell.c @@ -8,6 +8,7 @@ #include "hrt/hrt_input.h" #include "xdg_impl.h" #include "hrt/hrt_view.h" +#include "view_impl.h" #include @@ -33,6 +34,7 @@ static void handle_xdg_toplevel_destroy(struct wl_listener *listener, wl_list_remove(&view->destroy.link); wl_list_remove(&view->commit.link); + hrt_view_cleanup(view); free(view); }