Skip to content

Commit

Permalink
hrt: properly cleanup destroyed views
Browse files Browse the repository at this point in the history
Free and destroy the wlr_scene objects associated with it.
  • Loading branch information
sdilts committed Nov 3, 2024
1 parent e7cd922 commit 6f4d2d7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions heart/include/hrt/hrt_view.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef HRT_VIEW
#define HRT_VIEW

#include <stdint.h>
#include <wayland-server-core.h>
#include <hrt/hrt_server.h>
Expand Down Expand Up @@ -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
13 changes: 13 additions & 0 deletions heart/include/view_impl.h
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions heart/src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions heart/src/xdg_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "hrt/hrt_input.h"
#include "xdg_impl.h"
#include "hrt/hrt_view.h"
#include "view_impl.h"

#include <wlr/types/wlr_xdg_shell.h>

Expand All @@ -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);
}

Expand Down

0 comments on commit 6f4d2d7

Please sign in to comment.