xwayland/xwm: use role object destroy handler

This commit is contained in:
Kirill Primak 2022-11-06 13:39:34 +03:00
parent acd5a64fd1
commit 32daa43a45
2 changed files with 30 additions and 41 deletions

View File

@ -151,8 +151,6 @@ struct wlr_xwayland_surface {
struct wl_signal ping_timeout;
} events;
struct wl_listener surface_destroy;
void *data;
};

View File

@ -384,11 +384,11 @@ static void xsurface_set_net_wm_state(struct wlr_xwayland_surface *xsurface) {
i, property);
}
static void xsurface_unmap(struct wlr_xwayland_surface *surface);
static void xwayland_surface_destroy(
struct wlr_xwayland_surface *xsurface) {
xsurface_unmap(xsurface);
if (xsurface->surface != NULL) {
wlr_surface_destroy_role_object(xsurface->surface);
}
wl_signal_emit_mutable(&xsurface->events.destroy, xsurface);
@ -409,11 +409,6 @@ static void xwayland_surface_destroy(
wl_list_remove(&xsurface->unpaired_link);
if (xsurface->surface) {
wl_list_remove(&xsurface->surface_destroy.link);
xsurface->surface->role_data = NULL;
}
wl_event_source_remove(xsurface->ping_timer);
free(xsurface->title);
@ -858,18 +853,35 @@ static void xwayland_surface_role_precommit(struct wlr_surface *wlr_surface,
}
}
static void xwayland_surface_role_destroy(struct wlr_surface *wlr_surface) {
assert(wlr_surface->role == &xwayland_surface_role);
struct wlr_xwayland_surface *surface = wlr_surface->role_data;
if (surface == NULL) {
return;
}
if (surface->mapped) {
wl_signal_emit_mutable(&surface->events.unmap, surface);
surface->mapped = false;
xwm_set_net_client_list(surface->xwm);
}
// Make sure we're not on the unpaired surface list or we
// could be assigned a surface during surface creation that
// was mapped before this unmap request.
wl_list_remove(&surface->unpaired_link);
wl_list_init(&surface->unpaired_link);
surface->surface_id = 0;
surface->surface = NULL;
}
static const struct wlr_surface_role xwayland_surface_role = {
.name = "wlr_xwayland_surface",
.commit = xwayland_surface_role_commit,
.precommit = xwayland_surface_role_precommit,
.destroy = xwayland_surface_role_destroy,
};
static void handle_surface_destroy(struct wl_listener *listener, void *data) {
struct wlr_xwayland_surface *surface =
wl_container_of(listener, surface, surface_destroy);
xsurface_unmap(surface);
}
static void xwm_map_shell_surface(struct wlr_xwm *xwm,
struct wlr_xwayland_surface *xsurface, struct wlr_surface *surface) {
if (!wlr_surface_set_role(surface, &xwayland_surface_role, xsurface,
@ -904,30 +916,6 @@ static void xwm_map_shell_surface(struct wlr_xwm *xwm,
if (xwm->xres) {
read_surface_client_id(xwm, xsurface);
}
xsurface->surface_destroy.notify = handle_surface_destroy;
wl_signal_add(&surface->events.destroy, &xsurface->surface_destroy);
}
static void xsurface_unmap(struct wlr_xwayland_surface *surface) {
if (surface->mapped) {
wl_signal_emit_mutable(&surface->events.unmap, surface);
surface->mapped = false;
xwm_set_net_client_list(surface->xwm);
}
// Make sure we're not on the unpaired surface list or we
// could be assigned a surface during surface creation that
// was mapped before this unmap request.
wl_list_remove(&surface->unpaired_link);
wl_list_init(&surface->unpaired_link);
surface->surface_id = 0;
if (surface->surface) {
wl_list_remove(&surface->surface_destroy.link);
surface->surface->role_data = NULL;
surface->surface = NULL;
}
}
static void xwm_handle_create_notify(struct wlr_xwm *xwm,
@ -1098,7 +1086,10 @@ static void xwm_handle_unmap_notify(struct wlr_xwm *xwm,
return;
}
xsurface_unmap(xsurface);
if (xsurface->surface != NULL) {
wlr_surface_destroy_role_object(xsurface->surface);
}
xsurface_set_wm_state(xsurface, XCB_ICCCM_WM_STATE_WITHDRAWN);
}