xdg-shell: use role object destroy handler

This commit is contained in:
Kirill Primak 2022-11-06 12:18:56 +03:00
parent 92fbfda2ca
commit acd5a64fd1
6 changed files with 20 additions and 25 deletions

View file

@ -17,6 +17,7 @@ void destroy_xdg_surface(struct wlr_xdg_surface *surface);
void xdg_surface_role_commit(struct wlr_surface *wlr_surface);
void xdg_surface_role_precommit(struct wlr_surface *wlr_surface,
const struct wlr_surface_state *state);
void xdg_surface_role_destroy(struct wlr_surface *wlr_surface);
void create_xdg_positioner(struct wlr_xdg_client *client, uint32_t id);

View file

@ -258,7 +258,6 @@ struct wlr_xdg_surface {
struct wlr_xdg_surface_state current, pending;
struct wl_listener surface_destroy;
struct wl_listener surface_commit;
struct {

View file

@ -191,7 +191,7 @@ static void destroy_xdg_popup_grab(struct wlr_xdg_popup_grab *xdg_grab) {
struct wlr_xdg_popup *popup, *tmp;
wl_list_for_each_safe(popup, tmp, &xdg_grab->popups, grab_link) {
destroy_xdg_surface(popup->base);
wlr_surface_destroy_role_object(popup->base->surface);
}
wl_list_remove(&xdg_grab->link);
@ -361,6 +361,7 @@ const struct wlr_surface_role xdg_popup_surface_role = {
.name = "xdg_popup",
.commit = xdg_surface_role_commit,
.precommit = xdg_surface_role_precommit,
.destroy = xdg_surface_role_destroy,
};
void create_xdg_popup(struct wlr_xdg_surface *surface,

View file

@ -67,7 +67,7 @@ static void xdg_client_handle_resource_destroy(struct wl_resource *resource) {
struct wlr_xdg_surface *surface, *tmp = NULL;
wl_list_for_each_safe(surface, tmp, &client->surfaces, link) {
destroy_xdg_surface(surface);
wlr_surface_destroy_role_object(surface->surface);
}
if (client->ping_timer != NULL) {

View file

@ -256,7 +256,7 @@ static void xdg_surface_handle_resource_destroy(struct wl_resource *resource) {
struct wlr_xdg_surface *surface =
wlr_xdg_surface_from_resource(resource);
if (surface != NULL) {
destroy_xdg_surface(surface);
wlr_surface_destroy_role_object(surface->surface);
}
}
@ -331,11 +331,20 @@ void xdg_surface_role_precommit(struct wlr_surface *wlr_surface,
}
}
static void xdg_surface_handle_surface_destroy(struct wl_listener *listener,
void *data) {
struct wlr_xdg_surface *xdg_surface =
wl_container_of(listener, xdg_surface, surface_destroy);
destroy_xdg_surface(xdg_surface);
void xdg_surface_role_destroy(struct wlr_surface *wlr_surface) {
struct wlr_xdg_surface *surface =
wlr_xdg_surface_from_wlr_surface(wlr_surface);
if (surface == NULL) {
return;
}
reset_xdg_surface(surface);
wl_list_remove(&surface->link);
wl_list_remove(&surface->surface_commit.link);
wl_resource_set_user_data(surface->resource, NULL);
free(surface);
}
struct wlr_xdg_surface *create_xdg_surface(
@ -380,10 +389,6 @@ struct wlr_xdg_surface *create_xdg_surface(
wl_signal_init(&surface->events.configure);
wl_signal_init(&surface->events.ack_configure);
wl_signal_add(&surface->surface->events.destroy,
&surface->surface_destroy);
surface->surface_destroy.notify = xdg_surface_handle_surface_destroy;
wl_signal_add(&surface->surface->events.commit,
&surface->surface_commit);
surface->surface_commit.notify = xdg_surface_handle_surface_commit;
@ -425,18 +430,6 @@ void reset_xdg_surface(struct wlr_xdg_surface *surface) {
surface->role = WLR_XDG_SURFACE_ROLE_NONE;
}
void destroy_xdg_surface(struct wlr_xdg_surface *surface) {
reset_xdg_surface(surface);
wl_resource_set_user_data(surface->resource, NULL);
surface->surface->role_data = NULL;
wl_list_remove(&surface->link);
wl_list_remove(&surface->surface_destroy.link);
wl_list_remove(&surface->surface_commit.link);
free(surface);
}
struct wlr_xdg_surface *wlr_xdg_surface_from_resource(
struct wl_resource *resource) {
assert(wl_resource_instance_of(resource, &xdg_surface_interface,

View file

@ -453,6 +453,7 @@ const struct wlr_surface_role xdg_toplevel_surface_role = {
.name = "xdg_toplevel",
.commit = xdg_surface_role_commit,
.precommit = xdg_surface_role_precommit,
.destroy = xdg_surface_role_destroy,
};
void create_xdg_toplevel(struct wlr_xdg_surface *surface,