From c2fb5289c2909be10ce11ce9c0bcf58d110d1cdf Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Fri, 4 Nov 2022 21:56:11 +0300 Subject: [PATCH] xdg-shell: send invalid_size errors --- protocol/meson.build | 2 +- types/xdg_shell/wlr_xdg_surface.c | 6 +++--- types/xdg_shell/wlr_xdg_toplevel.c | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/protocol/meson.build b/protocol/meson.build index 6ba4bb6e..726b01fc 100644 --- a/protocol/meson.build +++ b/protocol/meson.build @@ -1,5 +1,5 @@ wayland_protos = dependency('wayland-protocols', - version: '>=1.27', + version: '>=1.28', fallback: 'wayland-protocols', default_options: ['tests=false'], ) diff --git a/types/xdg_shell/wlr_xdg_surface.c b/types/xdg_shell/wlr_xdg_surface.c index a03b90a1..0ba3c98e 100644 --- a/types/xdg_shell/wlr_xdg_surface.c +++ b/types/xdg_shell/wlr_xdg_surface.c @@ -216,9 +216,9 @@ static void xdg_surface_handle_set_window_geometry(struct wl_client *client, } if (width <= 0 || height <= 0) { - wlr_log(WLR_ERROR, "Client tried to set invalid geometry"); - //XXX: Switch to the proper error value once available - wl_resource_post_error(resource, -1, "Tried to set invalid xdg-surface geometry"); + wl_resource_post_error(resource, + XDG_SURFACE_ERROR_INVALID_SIZE, + "Tried to set invalid xdg-surface geometry"); return; } diff --git a/types/xdg_shell/wlr_xdg_toplevel.c b/types/xdg_shell/wlr_xdg_toplevel.c index a3d7f2ef..2ef1379f 100644 --- a/types/xdg_shell/wlr_xdg_toplevel.c +++ b/types/xdg_shell/wlr_xdg_toplevel.c @@ -116,6 +116,22 @@ struct wlr_xdg_toplevel_configure *send_xdg_toplevel_configure( } void handle_xdg_toplevel_committed(struct wlr_xdg_toplevel *toplevel) { + struct wlr_xdg_toplevel_state *pending = &toplevel->pending; + + // 1) Negative values are prohibited + // 2) If both min and max are set (aren't 0), min ≤ max + if (pending->min_width < 0 || pending->min_height < 0 || + pending->max_width < 0 || pending->max_height < 0 || + (pending->max_width != 0 && pending->max_width < pending->min_width) || + (pending->max_height != 0 && pending->max_height < pending->min_height)) { + wl_resource_post_error(toplevel->resource, + XDG_TOPLEVEL_ERROR_INVALID_SIZE, + "client provided an invalid min or max size"); + return; + } + + toplevel->current = toplevel->pending; + if (!toplevel->added) { // on the first commit, send a configure request to tell the client it // is added @@ -133,8 +149,6 @@ void handle_xdg_toplevel_committed(struct wlr_xdg_toplevel *toplevel) { } return; } - - toplevel->current = toplevel->pending; } static const struct xdg_toplevel_interface xdg_toplevel_implementation;