Re: [PATCH] xdg-shell: validate positioner object

2016-09-23 Thread Jonas Ådahl
On Fri, Sep 23, 2016 at 08:58:21AM +0200, Sjoerd Simons wrote:
> According to the xdg-shell v6 protocol a positioner object is only
> complete if both the size and its anchor are set. Ensure the weston

nit: anchor *rectangle*. You don't need to set the anchor, as it'll
default to 'none'.

> clients do this and let weston be more strict on checking if a client
> has done so.
> 
> This also fixes weston-terminal popups not showing up on gnome-shell
> 3.22.
> 
> Signed-off-by: Sjoerd Simons 
> ---
>  clients/window.c | 6 --
>  libweston-desktop/xdg-shell-v6.c | 9 +
>  2 files changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/clients/window.c b/clients/window.c
> index 216ef96..31bf236 100644
> --- a/clients/window.c
> +++ b/clients/window.c
> @@ -5409,13 +5409,14 @@ window_create_menu(struct display *display,
>  
>  static struct zxdg_positioner_v6 *
>  create_simple_positioner(struct display *display,
> -  int x, int y)
> +  int x, int y, int w, int h)
>  {
>   struct zxdg_positioner_v6 *positioner;
>  
>   positioner = zxdg_shell_v6_create_positioner(display->xdg_shell);
>   fail_on_null(positioner, 0, __FILE__, __LINE__);
>   zxdg_positioner_v6_set_anchor_rect(positioner, x, y, 1, 1);
> + zxdg_positioner_v6_set_size(positioner, w, h);
>   zxdg_positioner_v6_set_anchor(positioner,
> ZXDG_POSITIONER_V6_ANCHOR_TOP |
> ZXDG_POSITIONER_V6_ANCHOR_LEFT);
> @@ -5467,7 +5468,8 @@ window_show_menu(struct display *display,
>  
>   positioner = create_simple_positioner(display,
> window->x - (ix + 
> parent_geometry.x),
> -   window->y - (iy + 
> parent_geometry.y));
> +   window->y - (iy + 
> parent_geometry.y),
> +   frame_width(menu->frame), 
> frame_height(menu->frame));

nit: line break after ,

Otherwise looks good, and is

Reviewed-by: Jonas Ådahl 


Jonas

>   window->xdg_popup =
>   zxdg_surface_v6_get_popup(window->xdg_surface,
> parent->xdg_surface,
> diff --git a/libweston-desktop/xdg-shell-v6.c 
> b/libweston-desktop/xdg-shell-v6.c
> index 2afce81..359ebaa 100644
> --- a/libweston-desktop/xdg-shell-v6.c
> +++ b/libweston-desktop/xdg-shell-v6.c
> @@ -929,6 +929,15 @@ weston_desktop_xdg_surface_protocol_get_popup(struct 
> wl_client *wl_client,
>   struct weston_desktop_xdg_positioner *positioner =
>   wl_resource_get_user_data(positioner_resource);
>  
> + /* Checking whether the size and anchor rect both have a positive size
> +  * is enough to verify both have been correctly set */
> + if (positioner->size.width == 0 || positioner->anchor_rect.width == 0) {
> + wl_resource_post_error(resource,
> +ZXDG_SHELL_V6_ERROR_INVALID_POSITIONER,
> +"Positioner object is not complete");
> + return;
> + }
> +
>   if (weston_surface_set_role(wsurface, weston_desktop_xdg_popup_role,
>   resource, ZXDG_SHELL_V6_ERROR_ROLE) < 0)
>   return;
> -- 
> 2.9.3
> 
> ___
> wayland-devel mailing list
> wayland-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/wayland-devel
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH] xdg-shell: validate positioner object

2016-09-22 Thread Sjoerd Simons
According to the xdg-shell v6 protocol a positioner object is only
complete if both the size and its anchor are set. Ensure the weston
clients do this and let weston be more strict on checking if a client
has done so.

This also fixes weston-terminal popups not showing up on gnome-shell
3.22.

Signed-off-by: Sjoerd Simons 
---
 clients/window.c | 6 --
 libweston-desktop/xdg-shell-v6.c | 9 +
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/clients/window.c b/clients/window.c
index 216ef96..31bf236 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -5409,13 +5409,14 @@ window_create_menu(struct display *display,
 
 static struct zxdg_positioner_v6 *
 create_simple_positioner(struct display *display,
-int x, int y)
+int x, int y, int w, int h)
 {
struct zxdg_positioner_v6 *positioner;
 
positioner = zxdg_shell_v6_create_positioner(display->xdg_shell);
fail_on_null(positioner, 0, __FILE__, __LINE__);
zxdg_positioner_v6_set_anchor_rect(positioner, x, y, 1, 1);
+   zxdg_positioner_v6_set_size(positioner, w, h);
zxdg_positioner_v6_set_anchor(positioner,
  ZXDG_POSITIONER_V6_ANCHOR_TOP |
  ZXDG_POSITIONER_V6_ANCHOR_LEFT);
@@ -5467,7 +5468,8 @@ window_show_menu(struct display *display,
 
positioner = create_simple_positioner(display,
  window->x - (ix + 
parent_geometry.x),
- window->y - (iy + 
parent_geometry.y));
+ window->y - (iy + 
parent_geometry.y),
+ frame_width(menu->frame), 
frame_height(menu->frame));
window->xdg_popup =
zxdg_surface_v6_get_popup(window->xdg_surface,
  parent->xdg_surface,
diff --git a/libweston-desktop/xdg-shell-v6.c b/libweston-desktop/xdg-shell-v6.c
index 2afce81..359ebaa 100644
--- a/libweston-desktop/xdg-shell-v6.c
+++ b/libweston-desktop/xdg-shell-v6.c
@@ -929,6 +929,15 @@ weston_desktop_xdg_surface_protocol_get_popup(struct 
wl_client *wl_client,
struct weston_desktop_xdg_positioner *positioner =
wl_resource_get_user_data(positioner_resource);
 
+   /* Checking whether the size and anchor rect both have a positive size
+* is enough to verify both have been correctly set */
+   if (positioner->size.width == 0 || positioner->anchor_rect.width == 0) {
+   wl_resource_post_error(resource,
+  ZXDG_SHELL_V6_ERROR_INVALID_POSITIONER,
+  "Positioner object is not complete");
+   return;
+   }
+
if (weston_surface_set_role(wsurface, weston_desktop_xdg_popup_role,
resource, ZXDG_SHELL_V6_ERROR_ROLE) < 0)
return;
-- 
2.9.3

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel