aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--types/wlr_xdg_foreign_v2.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/types/wlr_xdg_foreign_v2.c b/types/wlr_xdg_foreign_v2.c
index 8d256723..1ceeb8be 100644
--- a/types/wlr_xdg_foreign_v2.c
+++ b/types/wlr_xdg_foreign_v2.c
@@ -27,28 +27,28 @@ 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) {
// Note: the error codes are the same for zxdg_exporter_v2 and
// zxdg_importer_v2
if (!wlr_surface_is_xdg_surface(surface)) {
- wl_resource_post_error(client_resource,
+ wl_resource_post_error(resource,
ZXDG_EXPORTER_V2_ERROR_INVALID_SURFACE,
"surface must be an xdg_surface");
- return false;
+ return NULL;
}
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,
+ wl_resource_post_error(resource,
ZXDG_EXPORTER_V2_ERROR_INVALID_SURFACE,
"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) {
@@ -84,17 +84,16 @@ 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)) {
- 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);
+ struct wlr_xdg_toplevel *child_toplevel =
+ verify_is_toplevel(resource, wlr_surface_child);
+ if (!child_toplevel) {
+ return;
+ }
if (!surface->mapped) {
- wlr_xdg_toplevel_set_parent(surface_child->toplevel, NULL);
+ wlr_xdg_toplevel_set_parent(child_toplevel, NULL);
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_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);
@@ -209,7 +208,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;
}
@@ -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);
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_v2_interface xdg_exporter_impl = {