From 7e521fed9799d94b90bfd7f11951736d98fe30f8 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 24 Dec 2019 13:59:38 +0100 Subject: xdg-shell: fix inert xdg_surface handling Closes: https://github.com/swaywm/sway/issues/4834 Closes: https://github.com/swaywm/wlroots/issues/1890 --- include/wlr/types/wlr_xdg_shell.h | 5 +++++ types/xdg_shell/wlr_xdg_surface.c | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index 7c787a16..4bd286ce 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -244,6 +244,11 @@ struct wlr_xdg_toplevel_show_window_menu_event { struct wlr_xdg_shell *wlr_xdg_shell_create(struct wl_display *display); +/** Returns the wlr_xdg_surface from an xdg_surface resource. + * + * Aborts if the resource doesn't have the correct type. Returns NULL if the + * resource is inert. + */ struct wlr_xdg_surface *wlr_xdg_surface_from_resource( struct wl_resource *resource); struct wlr_xdg_surface *wlr_xdg_surface_from_popup_resource( diff --git a/types/xdg_shell/wlr_xdg_surface.c b/types/xdg_shell/wlr_xdg_surface.c index fcd3e0c9..c3ea9f44 100644 --- a/types/xdg_shell/wlr_xdg_surface.c +++ b/types/xdg_shell/wlr_xdg_surface.c @@ -96,6 +96,9 @@ void unmap_xdg_surface(struct wlr_xdg_surface *surface) { static void xdg_surface_handle_ack_configure(struct wl_client *client, struct wl_resource *resource, uint32_t serial) { struct wlr_xdg_surface *surface = wlr_xdg_surface_from_resource(resource); + if (surface == NULL) { + return; + } if (surface->role == WLR_XDG_SURFACE_ROLE_NONE) { wl_resource_post_error(surface->resource, @@ -236,6 +239,9 @@ static void xdg_surface_handle_get_popup(struct wl_client *client, wlr_xdg_surface_from_resource(resource); struct wlr_xdg_surface *parent = wlr_xdg_surface_from_resource(parent_resource); + if (xdg_surface == NULL) { + return; // TODO: create an inert xdg_popup + } struct wlr_xdg_positioner_resource *positioner = get_xdg_positioner_from_resource(positioner_resource); create_xdg_popup(xdg_surface, parent, positioner, id); @@ -245,6 +251,9 @@ static void xdg_surface_handle_get_toplevel(struct wl_client *client, struct wl_resource *resource, uint32_t id) { struct wlr_xdg_surface *xdg_surface = wlr_xdg_surface_from_resource(resource); + if (xdg_surface == NULL) { + return; // TODO: create an inert xdg_toplevel + } create_xdg_toplevel(xdg_surface, id); } @@ -252,6 +261,9 @@ static void xdg_surface_handle_set_window_geometry(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) { struct wlr_xdg_surface *surface = wlr_xdg_surface_from_resource(resource); + if (surface == NULL) { + return; + } if (surface->role == WLR_XDG_SURFACE_ROLE_NONE) { wl_resource_post_error(surface->resource, @@ -277,6 +289,9 @@ static void xdg_surface_handle_set_window_geometry(struct wl_client *client, static void xdg_surface_handle_destroy(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = wlr_xdg_surface_from_resource(resource); + if (surface == NULL) { + return; + } if (surface->role != WLR_XDG_SURFACE_ROLE_NONE) { wlr_log(WLR_ERROR, "Tried to destroy an xdg_surface before its role " @@ -502,7 +517,6 @@ void destroy_xdg_surface(struct wlr_xdg_surface *surface) { struct wlr_xdg_surface *wlr_xdg_surface_from_resource( struct wl_resource *resource) { - // TODO: Double check that all of the callers can deal with NULL if (!resource) { return NULL; } -- cgit v1.2.3