xdg-foreign-v1: 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:22:46 +02:00 committed by Kirill Primak
parent 4cc5bdc4d1
commit 053bb42a6d
1 changed files with 24 additions and 25 deletions

View File

@ -27,22 +27,21 @@ static void xdg_imported_handle_destroy(struct wl_client *client,
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) {
if (wlr_surface_is_xdg_surface(surface)) {
struct wlr_xdg_surface *xdg_surface =
wlr_xdg_surface_from_wlr_surface(surface);
if (xdg_surface == NULL || xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
wl_resource_post_error(client_resource, -1,
"surface must be an xdg_toplevel");
return false;
}
} else {
wl_resource_post_error(client_resource, -1,
"surface must be an xdg_surface");
return false;
if (!wlr_surface_is_xdg_surface(surface)) {
wl_resource_post_error(resource, -1, "surface must be an xdg_surface");
return NULL;
}
return true;
struct wlr_xdg_surface *xdg_surface =
wlr_xdg_surface_from_wlr_surface(surface);
if (xdg_surface == NULL || xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
wl_resource_post_error(resource, -1, "surface must be an xdg_toplevel");
return NULL;
}
return xdg_surface->toplevel;
}
static void destroy_imported_child(struct wlr_xdg_imported_child_v1 *child) {
@ -78,17 +77,17 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client,
struct wlr_surface *wlr_surface_child =
wlr_surface_from_resource(child_resource);
if (!verify_is_toplevel(resource, wlr_surface_child)) {
struct wlr_xdg_toplevel *child_toplevel =
verify_is_toplevel(resource, wlr_surface_child);
if (!child_toplevel) {
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);
wlr_xdg_toplevel_set_parent(child_toplevel, NULL);
return;
}
@ -108,10 +107,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_toplevel_set_parent.notify = handle_xdg_toplevel_set_parent;
wlr_xdg_toplevel_set_parent(surface_child->toplevel, surface->toplevel);
wl_signal_add(&surface_child->events.unmap,
wlr_xdg_toplevel_set_parent(child_toplevel, surface->toplevel);
wl_signal_add(&child_toplevel->base->events.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);
wl_list_insert(&imported->children, &child->link);
@ -203,7 +202,9 @@ static void xdg_exporter_handle_export(struct wl_client *wl_client,
xdg_foreign_from_exporter_resource(client_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;
}
@ -238,9 +239,7 @@ static void xdg_exporter_handle_export(struct wl_client *wl_client,
zxdg_exported_v1_send_handle(exported->resource, exported->base.handle);
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_unmap);
wl_signal_add(&xdg_toplevel->base->events.unmap, &exported->xdg_surface_unmap);
}
static const struct zxdg_exporter_v1_interface xdg_exporter_impl = {