diff options
author | Simon Ser <contact@emersion.fr> | 2021-10-23 17:39:16 +0200 |
---|---|---|
committer | Kirill Primak <vyivel@posteo.net> | 2021-10-25 18:22:11 +0300 |
commit | 3d6ca9942db43ca182d91b115597a4ca7f367eef (patch) | |
tree | 1bd61299a11b083ac590b90234e63d5ee1362ee4 | |
parent | fb393ddf84dd5ad14c00afaa25ee81bc5b8eef14 (diff) |
xdg-foreign-v2: use error enum
A wayland-protocols patch [1] has added error codes for invalid
surfaces.
[1]: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/57
Closes: https://github.com/swaywm/wlroots/issues/2600
-rw-r--r-- | types/wlr_xdg_foreign_v2.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/types/wlr_xdg_foreign_v2.c b/types/wlr_xdg_foreign_v2.c index d946e7f9..c9ef5496 100644 --- a/types/wlr_xdg_foreign_v2.c +++ b/types/wlr_xdg_foreign_v2.c @@ -30,19 +30,25 @@ static void xdg_imported_handle_destroy(struct wl_client *client, static bool verify_is_toplevel(struct wl_resource *client_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->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"); + // 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, + ZXDG_EXPORTER_V2_ERROR_INVALID_SURFACE, + "surface must be an xdg_surface"); + return false; + } + + struct wlr_xdg_surface *xdg_surface = + wlr_xdg_surface_from_wlr_surface(surface); + if (xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) { + wl_resource_post_error(client_resource, + ZXDG_EXPORTER_V2_ERROR_INVALID_SURFACE, + "surface must be an xdg_toplevel"); return false; } + return true; } |