[PATCH weston v4 18/20] window: Add API for manually set confine region

Peter Hutterer peter.hutterer at who-t.net
Thu Nov 19 20:30:55 PST 2015


On Tue, Nov 17, 2015 at 06:11:04PM +0800, Jonas Ådahl wrote:
> We can use this to test more complex confine regions.
> 
> Signed-off-by: Jonas Ådahl <jadahl at gmail.com>

Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

Cheers,
   Peter

> ---
>  clients/window.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++--------
>  clients/window.h | 11 +++++++++
>  2 files changed, 70 insertions(+), 10 deletions(-)
> 
> diff --git a/clients/window.c b/clients/window.c
> index 6f5ca85..c911bc1 100644
> --- a/clients/window.c
> +++ b/clients/window.c
> @@ -4734,15 +4734,17 @@ static const struct zwp_confined_pointer_v1_listener confined_pointer_listener =
>  };
>  
>  int
> -window_confine_pointer_to_widget(struct window *window,
> -				 struct widget *widget,
> -				 struct input *input)
> +window_confine_pointer_to_rectangles(struct window *window,
> +				     struct input *input,
> +				     struct rectangle *rectangles,
> +				     int num_rectangles)
>  {
>  	struct zwp_pointer_constraints_v1 *pointer_constraints =
>  		window->display->pointer_constraints;
>  	struct zwp_confined_pointer_v1 *confined_pointer;
>  	struct wl_compositor *compositor = window->display->compositor;
>  	struct wl_region *region = NULL;
> +	int i;
>  
>  	if (!window->display->pointer_constraints)
>  		return -1;
> @@ -4756,13 +4758,15 @@ window_confine_pointer_to_widget(struct window *window,
>  	if (!input->pointer)
>  		return -1;
>  
> -	if (widget) {
> +	if (num_rectangles >= 1) {
>  		region = wl_compositor_create_region(compositor);
> -		wl_region_add(region,
> -			      widget->allocation.x,
> -			      widget->allocation.y,
> -			      widget->allocation.width,
> -			      widget->allocation.height);
> +		for (i = 0; i < num_rectangles; i++) {
> +			wl_region_add(region,
> +				      rectangles[i].x,
> +				      rectangles[i].y,
> +				      rectangles[i].width,
> +				      rectangles[i].height);
> +		}
>  	}
>  
>  	confined_pointer =
> @@ -4778,12 +4782,57 @@ window_confine_pointer_to_widget(struct window *window,
>  					     input);
>  
>  	window->confined_pointer = confined_pointer;
> -	window->confined_widget = widget;
> +	window->confined_widget = NULL;
>  
>  	return 0;
>  }
>  
>  void
> +window_update_confine_rectangles(struct window *window,
> +				 struct rectangle *rectangles,
> +				 int num_rectangles)
> +{
> +	struct wl_compositor *compositor = window->display->compositor;
> +	struct wl_region *region;
> +	int i;
> +
> +	region = wl_compositor_create_region(compositor);
> +	for (i = 0; i < num_rectangles; i++) {
> +		wl_region_add(region,
> +			      rectangles[i].x,
> +			      rectangles[i].y,
> +			      rectangles[i].width,
> +			      rectangles[i].height);
> +	}
> +
> +	zwp_confined_pointer_v1_set_region(window->confined_pointer, region);
> +
> +	wl_region_destroy(region);
> +}
> +
> +int
> +window_confine_pointer_to_widget(struct window *window,
> +				 struct widget *widget,
> +				 struct input *input)
> +{
> +	int ret;
> +
> +	if (widget) {
> +		ret = window_confine_pointer_to_rectangles(window,
> +							   input,
> +							   &widget->allocation,
> +							   1);
> +		window->confined_widget = widget;
> +		return ret;
> +	} else {
> +		return window_confine_pointer_to_rectangles(window,
> +							    input,
> +							    NULL,
> +							    0);
> +	}
> +}
> +
> +void
>  window_unconfine_pointer(struct window *window)
>  {
>  	if (!window->confined_pointer)
> diff --git a/clients/window.h b/clients/window.h
> index 42cf492..724e3a2 100644
> --- a/clients/window.h
> +++ b/clients/window.h
> @@ -381,6 +381,17 @@ widget_set_locked_pointer_cursor_hint(struct widget *widget,
>  				      float x, float y);
>  
>  int
> +window_confine_pointer_to_rectangles(struct window *window,
> +				     struct input *input,
> +				     struct rectangle *rectangles,
> +				     int num_rectangles);
> +
> +void
> +window_update_confine_rectangles(struct window *window,
> +				 struct rectangle *rectangles,
> +				 int num_rectangles);
> +
> +int
>  window_confine_pointer_to_widget(struct window *window,
>  				 struct widget *widget,
>  				 struct input *input);
> -- 
> 2.4.3
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> 


More information about the wayland-devel mailing list