From 04aa44b4dfa3ee7a299240794f77c2ef2d55e6f3 Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Fri, 4 Mar 2022 01:11:51 +0300 Subject: [PATCH] xdg-foreign-v2: treat unmapped parents as NULL --- include/wlr/types/wlr_xdg_foreign_v2.h | 2 +- types/wlr_xdg_foreign_v2.c | 31 ++++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/include/wlr/types/wlr_xdg_foreign_v2.h b/include/wlr/types/wlr_xdg_foreign_v2.h index d0fb506a..23c8247b 100644 --- a/include/wlr/types/wlr_xdg_foreign_v2.h +++ b/include/wlr/types/wlr_xdg_foreign_v2.h @@ -34,7 +34,7 @@ struct wlr_xdg_exported_v2 { struct wlr_xdg_foreign_exported base; struct wl_resource *resource; - struct wl_listener xdg_surface_destroy; + struct wl_listener xdg_surface_unmap; struct wl_list link; // wlr_xdg_foreign_v2::exporter::objects }; diff --git a/types/wlr_xdg_foreign_v2.c b/types/wlr_xdg_foreign_v2.c index abd99735..28efff14 100644 --- a/types/wlr_xdg_foreign_v2.c +++ b/types/wlr_xdg_foreign_v2.c @@ -88,6 +88,17 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client, if (!verify_is_toplevel(resource, wlr_surface_child)) { return; } + + struct wlr_xdg_surface *surface = + wlr_xdg_surface_from_wlr_surface(wlr_surface); + struct wlr_xdg_surface *surface_child = + wlr_xdg_surface_from_wlr_surface(wlr_surface_child); + + if (!surface->mapped) { + wlr_xdg_toplevel_set_parent(surface_child->toplevel, NULL); + return; + } + struct wlr_xdg_imported_child_v2 *child; wl_list_for_each(child, &imported->children, link) { if (child->surface == wlr_surface_child) { @@ -104,11 +115,6 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client, child->xdg_surface_unmap.notify = handle_child_xdg_surface_unmap; child->xdg_toplevel_set_parent.notify = handle_xdg_toplevel_set_parent; - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_wlr_surface(wlr_surface); - struct wlr_xdg_surface *surface_child = - wlr_xdg_surface_from_wlr_surface(wlr_surface_child); - wlr_xdg_toplevel_set_parent(surface_child->toplevel, surface->toplevel); wl_signal_add(&surface_child->events.unmap, &child->xdg_surface_unmap); @@ -157,10 +163,7 @@ static void destroy_imported(struct wlr_xdg_imported_v2 *imported) { wl_list_for_each_safe(child, child_tmp, &imported->children, link) { struct wlr_xdg_surface *xdg_child = wlr_xdg_surface_from_wlr_surface(child->surface); - - if (xdg_child != NULL) { - wlr_xdg_toplevel_set_parent(xdg_child->toplevel, NULL); - } + wlr_xdg_toplevel_set_parent(xdg_child->toplevel, NULL); } wl_list_remove(&imported->exported_destroyed.link); @@ -175,7 +178,7 @@ static void destroy_imported(struct wlr_xdg_imported_v2 *imported) { static void destroy_exported(struct wlr_xdg_exported_v2 *exported) { wlr_xdg_foreign_exported_finish(&exported->base); - wl_list_remove(&exported->xdg_surface_destroy.link); + wl_list_remove(&exported->xdg_surface_unmap.link); wl_list_remove(&exported->link); wl_resource_set_user_data(exported->resource, NULL); free(exported); @@ -191,10 +194,10 @@ static void xdg_exported_handle_resource_destroy( } } -static void handle_xdg_surface_destroy( +static void handle_xdg_surface_unmap( struct wl_listener *listener, void *data) { struct wlr_xdg_exported_v2 *exported = - wl_container_of(listener, exported, xdg_surface_destroy); + wl_container_of(listener, exported, xdg_surface_unmap); destroy_exported(exported); } @@ -241,10 +244,10 @@ static void xdg_exporter_handle_export(struct wl_client *wl_client, zxdg_exported_v2_send_handle(exported->resource, exported->base.handle); - exported->xdg_surface_destroy.notify = handle_xdg_surface_destroy; + exported->xdg_surface_unmap.notify = handle_xdg_surface_unmap; struct wlr_xdg_surface *xdg_surface = wlr_xdg_surface_from_wlr_surface(surface); - wl_signal_add(&xdg_surface->events.unmap, &exported->xdg_surface_destroy); + wl_signal_add(&xdg_surface->events.unmap, &exported->xdg_surface_unmap); } static const struct zxdg_exporter_v2_interface xdg_exporter_impl = {