From b5b15b26258bc5e29736b3eb0268fa460acc9dd0 Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Sat, 5 Feb 2022 10:29:42 +0300 Subject: [PATCH] xdg-{toplevel,popup}: extract destructors --- include/types/wlr_xdg_shell.h | 2 ++ types/xdg_shell/wlr_xdg_popup.c | 6 ++++++ types/xdg_shell/wlr_xdg_surface.c | 8 ++------ types/xdg_shell/wlr_xdg_toplevel.c | 5 +++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/types/wlr_xdg_shell.h b/include/types/wlr_xdg_shell.h index c0f97798..1ad6b0ae 100644 --- a/include/types/wlr_xdg_shell.h +++ b/include/types/wlr_xdg_shell.h @@ -31,11 +31,13 @@ void create_xdg_popup(struct wlr_xdg_surface *surface, struct wlr_xdg_surface *parent, struct wlr_xdg_positioner_resource *positioner, uint32_t id); void unmap_xdg_popup(struct wlr_xdg_popup *popup); +void destroy_xdg_popup(struct wlr_xdg_popup *popup); void handle_xdg_popup_committed(struct wlr_xdg_popup *popup); void create_xdg_toplevel(struct wlr_xdg_surface *surface, uint32_t id); void unmap_xdg_toplevel(struct wlr_xdg_toplevel *toplevel); +void destroy_xdg_toplevel(struct wlr_xdg_toplevel *toplevel); void handle_xdg_toplevel_committed(struct wlr_xdg_toplevel *toplevel); struct wlr_xdg_toplevel_configure *send_xdg_toplevel_configure( struct wlr_xdg_toplevel *toplevel); diff --git a/types/xdg_shell/wlr_xdg_popup.c b/types/xdg_shell/wlr_xdg_popup.c index d923e923..eba829cc 100644 --- a/types/xdg_shell/wlr_xdg_popup.c +++ b/types/xdg_shell/wlr_xdg_popup.c @@ -389,6 +389,12 @@ void unmap_xdg_popup(struct wlr_xdg_popup *popup) { } } +void destroy_xdg_popup(struct wlr_xdg_popup *popup) { + wl_list_remove(&popup->link); + wl_resource_set_user_data(popup->resource, NULL); + free(popup); +} + void wlr_xdg_popup_destroy(struct wlr_xdg_popup *popup) { if (popup == NULL) { return; diff --git a/types/xdg_shell/wlr_xdg_surface.c b/types/xdg_shell/wlr_xdg_surface.c index a9f7aa82..e65c6afd 100644 --- a/types/xdg_shell/wlr_xdg_surface.c +++ b/types/xdg_shell/wlr_xdg_surface.c @@ -411,15 +411,11 @@ void reset_xdg_surface(struct wlr_xdg_surface *surface) { switch (surface->role) { case WLR_XDG_SURFACE_ROLE_TOPLEVEL: - wl_resource_set_user_data(surface->toplevel->resource, NULL); - free(surface->toplevel); + destroy_xdg_toplevel(surface->toplevel); surface->toplevel = NULL; break; case WLR_XDG_SURFACE_ROLE_POPUP: - wl_list_remove(&surface->popup->link); - - wl_resource_set_user_data(surface->popup->resource, NULL); - free(surface->popup); + destroy_xdg_popup(surface->popup); surface->popup = NULL; break; case WLR_XDG_SURFACE_ROLE_NONE: diff --git a/types/xdg_shell/wlr_xdg_toplevel.c b/types/xdg_shell/wlr_xdg_toplevel.c index ad2f0501..ed304cfc 100644 --- a/types/xdg_shell/wlr_xdg_toplevel.c +++ b/types/xdg_shell/wlr_xdg_toplevel.c @@ -493,6 +493,11 @@ void unmap_xdg_toplevel(struct wlr_xdg_toplevel *toplevel) { toplevel->requested.minimized = false; } +void destroy_xdg_toplevel(struct wlr_xdg_toplevel *toplevel) { + wl_resource_set_user_data(toplevel->resource, NULL); + free(toplevel); +} + void wlr_xdg_toplevel_send_close(struct wlr_xdg_toplevel *toplevel) { xdg_toplevel_send_close(toplevel->resource); }