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

hrt: properly cleanup destroyed views #74

Merged
merged 1 commit into from
Nov 3, 2024
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
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
Loading