From f10bae8fe955115b398029829d46f6ffd68de900 Mon Sep 17 00:00:00 2001 From: xurui Date: Wed, 23 Oct 2024 18:46:16 +0800 Subject: [PATCH] xdg-positioner: use enum_is_valid functions Signed-off-by: xurui --- types/xdg_shell/wlr_xdg_positioner.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/types/xdg_shell/wlr_xdg_positioner.c b/types/xdg_shell/wlr_xdg_positioner.c index 380c1131..e9800918 100644 --- a/types/xdg_shell/wlr_xdg_positioner.c +++ b/types/xdg_shell/wlr_xdg_positioner.c @@ -52,7 +52,8 @@ static void xdg_positioner_handle_set_anchor(struct wl_client *client, struct wlr_xdg_positioner *positioner = wlr_xdg_positioner_from_resource(resource); - if (anchor > XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT) { + uint32_t version = wl_resource_get_version(resource); + if (!xdg_positioner_anchor_is_valid(anchor, version)) { wl_resource_post_error(resource, XDG_POSITIONER_ERROR_INVALID_INPUT, "invalid anchor value"); @@ -67,7 +68,8 @@ static void xdg_positioner_handle_set_gravity(struct wl_client *client, struct wlr_xdg_positioner *positioner = wlr_xdg_positioner_from_resource(resource); - if (gravity > XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT) { + uint32_t version = wl_resource_get_version(resource); + if (!xdg_positioner_gravity_is_valid(gravity, version)) { wl_resource_post_error(resource, XDG_POSITIONER_ERROR_INVALID_INPUT, "invalid gravity value"); @@ -83,6 +85,14 @@ static void xdg_positioner_handle_set_constraint_adjustment( struct wlr_xdg_positioner *positioner = wlr_xdg_positioner_from_resource(resource); + uint32_t version = wl_resource_get_version(resource); + if (!xdg_positioner_constraint_adjustment_is_valid(constraint_adjustment, version)) { + wl_resource_post_error(resource, + XDG_POSITIONER_ERROR_INVALID_INPUT, + "invalid constraint_adjustment value"); + return; + } + positioner->rules.constraint_adjustment = constraint_adjustment; }