xdg-foreign-v2: return wlr_xdg_toplevel in verify_is_toplevel()

This makes it clearer that the wlr_xdg_toplevel cannot be NULL.
This commit is contained in:
Simon Ser 2022-08-28 10:15:28 +02:00 committed by Kirill Primak
parent 053bb42a6d
commit d8ef9a95de

View file

@ -27,28 +27,28 @@ static void xdg_imported_handle_destroy(struct wl_client *client,
wl_resource_destroy(resource); wl_resource_destroy(resource);
} }
static bool verify_is_toplevel(struct wl_resource *client_resource, static struct wlr_xdg_toplevel *verify_is_toplevel(struct wl_resource *resource,
struct wlr_surface *surface) { struct wlr_surface *surface) {
// Note: the error codes are the same for zxdg_exporter_v2 and // Note: the error codes are the same for zxdg_exporter_v2 and
// zxdg_importer_v2 // zxdg_importer_v2
if (!wlr_surface_is_xdg_surface(surface)) { if (!wlr_surface_is_xdg_surface(surface)) {
wl_resource_post_error(client_resource, wl_resource_post_error(resource,
ZXDG_EXPORTER_V2_ERROR_INVALID_SURFACE, ZXDG_EXPORTER_V2_ERROR_INVALID_SURFACE,
"surface must be an xdg_surface"); "surface must be an xdg_surface");
return false; return NULL;
} }
struct wlr_xdg_surface *xdg_surface = struct wlr_xdg_surface *xdg_surface =
wlr_xdg_surface_from_wlr_surface(surface); wlr_xdg_surface_from_wlr_surface(surface);
if (xdg_surface == NULL || xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) { if (xdg_surface == NULL || xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
wl_resource_post_error(client_resource, wl_resource_post_error(resource,
ZXDG_EXPORTER_V2_ERROR_INVALID_SURFACE, ZXDG_EXPORTER_V2_ERROR_INVALID_SURFACE,
"surface must be an xdg_toplevel"); "surface must be an xdg_toplevel");
return false; return NULL;
} }
return true; return xdg_surface->toplevel;
} }
static void destroy_imported_child(struct wlr_xdg_imported_child_v2 *child) { static void destroy_imported_child(struct wlr_xdg_imported_child_v2 *child) {
@ -84,17 +84,16 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client,
struct wlr_surface *wlr_surface_child = struct wlr_surface *wlr_surface_child =
wlr_surface_from_resource(child_resource); wlr_surface_from_resource(child_resource);
if (!verify_is_toplevel(resource, wlr_surface_child)) { struct wlr_xdg_surface *surface =
wlr_xdg_surface_from_wlr_surface(wlr_surface);
struct wlr_xdg_toplevel *child_toplevel =
verify_is_toplevel(resource, wlr_surface_child);
if (!child_toplevel) {
return; 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) { if (!surface->mapped) {
wlr_xdg_toplevel_set_parent(surface_child->toplevel, NULL); wlr_xdg_toplevel_set_parent(child_toplevel, NULL);
return; return;
} }
@ -114,10 +113,10 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client,
child->xdg_surface_unmap.notify = handle_child_xdg_surface_unmap; child->xdg_surface_unmap.notify = handle_child_xdg_surface_unmap;
child->xdg_toplevel_set_parent.notify = handle_xdg_toplevel_set_parent; child->xdg_toplevel_set_parent.notify = handle_xdg_toplevel_set_parent;
wlr_xdg_toplevel_set_parent(surface_child->toplevel, surface->toplevel); wlr_xdg_toplevel_set_parent(child_toplevel, surface->toplevel);
wl_signal_add(&surface_child->events.unmap, wl_signal_add(&child_toplevel->base->events.unmap,
&child->xdg_surface_unmap); &child->xdg_surface_unmap);
wl_signal_add(&surface_child->toplevel->events.set_parent, wl_signal_add(&child_toplevel->events.set_parent,
&child->xdg_toplevel_set_parent); &child->xdg_toplevel_set_parent);
wl_list_insert(&imported->children, &child->link); wl_list_insert(&imported->children, &child->link);
@ -209,7 +208,9 @@ static void xdg_exporter_handle_export(struct wl_client *wl_client,
xdg_foreign_from_exporter_resource(client_resource); xdg_foreign_from_exporter_resource(client_resource);
struct wlr_surface *surface = wlr_surface_from_resource(surface_resource); struct wlr_surface *surface = wlr_surface_from_resource(surface_resource);
if (!verify_is_toplevel(client_resource, surface)) { struct wlr_xdg_toplevel *xdg_toplevel =
verify_is_toplevel(client_resource, surface);
if (!xdg_toplevel) {
return; return;
} }
@ -244,9 +245,7 @@ static void xdg_exporter_handle_export(struct wl_client *wl_client,
zxdg_exported_v2_send_handle(exported->resource, exported->base.handle); zxdg_exported_v2_send_handle(exported->resource, exported->base.handle);
exported->xdg_surface_unmap.notify = handle_xdg_surface_unmap; exported->xdg_surface_unmap.notify = handle_xdg_surface_unmap;
struct wlr_xdg_surface *xdg_surface = wl_signal_add(&xdg_toplevel->base->events.unmap, &exported->xdg_surface_unmap);
wlr_xdg_surface_from_wlr_surface(surface);
wl_signal_add(&xdg_surface->events.unmap, &exported->xdg_surface_unmap);
} }
static const struct zxdg_exporter_v2_interface xdg_exporter_impl = { static const struct zxdg_exporter_v2_interface xdg_exporter_impl = {