From bf48e21fa18df9d2c917b8577633107e4b1681de Mon Sep 17 00:00:00 2001 From: Jonas Ådahl Date: Fri, 6 Feb 2015 10:15:28 +0800 Subject: desktop-shell: Fail if get_xdg_surface is called on an xdg_surface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a client calls xdg_shell.get_xdg_surface on a surface that is already an xdg_surface would, prior to this patch, succeed, but cause weston to crash later when trying to configure. This patch instead sends a role error to the client complaining that it already is an xdg_surface. Note that .._set_role() only fails when changing roles, not when setting the same role twice. The same is done for xdg_popup. Signed-off-by: Jonas Ådahl Reviewed-by: Daniel Stone Reviewed-by: Bryce Harrington --- desktop-shell/shell.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'desktop-shell') diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index 26cadb63..f28fc10e 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -3978,6 +3978,14 @@ xdg_get_xdg_surface(struct wl_client *client, struct desktop_shell *shell = sc->shell; struct shell_surface *shsurf; + shsurf = get_shell_surface(surface); + if (shsurf && shell_surface_is_xdg_surface(shsurf)) { + wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, + "This wl_surface is already an " + "xdg_surface"); + return; + } + if (weston_surface_set_role(surface, "xdg_surface", resource, XDG_SHELL_ERROR_ROLE) < 0) return; @@ -4071,6 +4079,14 @@ xdg_get_xdg_popup(struct wl_client *client, struct weston_surface *parent; struct shell_seat *seat; + shsurf = get_shell_surface(surface); + if (shsurf && shell_surface_is_xdg_popup(shsurf)) { + wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, + "This wl_surface is already an " + "xdg_popup"); + return; + } + if (weston_surface_set_role(surface, "xdg_popup", resource, XDG_SHELL_ERROR_ROLE) < 0) return; -- cgit v1.2.3