[PATCH weston v2 2/5] compositor: Implement wl_pointer_gesture_swipe/pinch interfaces

Jonas Ã…dahl jadahl at gmail.com
Tue Jul 28 23:42:45 PDT 2015


On Thu, Jul 23, 2015 at 07:00:28PM +0200, Carlos Garnacho wrote:
> Each of these come with a getter on wl_pointer, which takes care
> of creating the resource. The focused resources list is maintained
> in sync with the pointer's.

I guess this commit message needs to be updated.

> 
> Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
> ---
>  src/compositor.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++

Why not put all of this in input.c? It's not related to compositing, but
is related to input.

>  src/compositor.h |   5 +++
>  src/input.c      |  16 +++++++++
>  3 files changed, 121 insertions(+)
> 
> diff --git a/src/compositor.c b/src/compositor.c
> index 66c3eee..0bafd2a 100644
> --- a/src/compositor.c
> +++ b/src/compositor.c
> @@ -56,6 +56,7 @@
>  #include "compositor.h"
>  #include "scaler-server-protocol.h"
>  #include "presentation_timing-server-protocol.h"
> +#include "protocol/gestures-server-protocol.h"
>  #include "shared/helpers.h"
>  #include "shared/os-compatibility.h"
>  #include "shared/timespec-util.h"
> @@ -4373,6 +4374,83 @@ static const struct presentation_interface presentation_implementation = {
>  };
>  
>  static void
> +pointer_gesture_swipe_destroy(struct wl_client *client, struct wl_resource *resource)

Coding style: we have a 80 char line length limit in weston/wayland.
Here and many places below.

> +{
> +	wl_resource_destroy(resource);
> +}
> +
> +static const struct _wl_pointer_gesture_swipe_interface pointer_gesture_swipe_interface = {
> +	pointer_gesture_swipe_destroy
> +};
> +
> +static void
> +pointer_gesture_pinch_destroy(struct wl_client *client, struct wl_resource *resource)
> +{
> +	wl_resource_destroy(resource);
> +}
> +
> +static const struct _wl_pointer_gesture_swipe_interface pointer_gesture_pinch_interface = {
> +	pointer_gesture_pinch_destroy
> +};
> +
> +static void
> +pointer_gestures_get_swipe(struct wl_client *client, struct wl_resource *resource,
> +			   uint32_t id, struct wl_resource *pointer_resource)
> +{
> +	struct weston_pointer *pointer = wl_resource_get_user_data(pointer_resource);
> +	struct wl_resource *cr;
> +	struct wl_list *list;
> +
> +        cr = wl_resource_create(client, &_wl_pointer_gesture_swipe_interface,
> +				wl_resource_get_version(resource), id);
> +	if (cr == NULL) {
> +		wl_client_post_no_memory(client);
> +		return;
> +	}
> +
> +	wl_resource_set_implementation(cr, &pointer_gesture_swipe_interface,
> +				       pointer, unbind_resource);
> +
> +	if (pointer->focus && wl_resource_get_client(pointer->focus->surface->resource) == client)
> +		list = &pointer->swipe_gesture_focus_resource_list;
> +	else
> +		list = &pointer->swipe_gesture_resource_list;
> +
> +	wl_list_insert(list, wl_resource_get_link(cr));
> +}
> +
> +static void
> +pointer_gestures_get_pinch(struct wl_client *client, struct wl_resource *resource,
> +			   uint32_t id, struct wl_resource *pointer_resource)
> +{
> +	struct weston_pointer *pointer = wl_resource_get_user_data(pointer_resource);
> +	struct wl_resource *cr;
> +	struct wl_list *list;
> +
> +        cr = wl_resource_create(client, &_wl_pointer_gesture_pinch_interface,
> +				wl_resource_get_version(resource), id);

Use tabs instead of spaces for indentation.

> +	if (cr == NULL) {
> +		wl_client_post_no_memory(client);
> +		return;
> +	}
> +
> +	wl_resource_set_implementation(cr, &pointer_gesture_pinch_interface,
> +				       pointer, unbind_resource);
> +
> +	if (pointer->focus && wl_resource_get_client(pointer->focus->surface->resource) == client)
> +		list = &pointer->pinch_gesture_focus_resource_list;
> +	else
> +		list = &pointer->pinch_gesture_resource_list;

Would you mind rebasing these parts on top of the patch I just posted
introducing "pointer clients"[0]? It'll be a mess if we continue add
pointer extensions if they all have to have separately managed focus
resource lists.


Jonas

[0] http://lists.freedesktop.org/archives/wayland-devel/2015-July/023647.html

> +
> +	wl_list_insert(list, wl_resource_get_link(cr));
> +}
> +
> +static const struct _wl_pointer_gestures_interface pointer_gestures_interface = {
> +	pointer_gestures_get_swipe,
> +	pointer_gestures_get_pinch
> +};
> +
> +static void
>  bind_presentation(struct wl_client *client,
>  		  void *data, uint32_t version, uint32_t id)
>  {
> @@ -4409,6 +4487,24 @@ compositor_bind(struct wl_client *client,
>  				       compositor, NULL);
>  }
>  
> +static void
> +bind_pointer_gestures(struct wl_client *client,
> +		      void *data, uint32_t version, uint32_t id)
> +{
> +	struct weston_compositor *compositor = data;
> +	struct wl_resource *resource;
> +
> +	resource = wl_resource_create(client, &_wl_pointer_gestures_interface,
> +				      MIN(version, 1), id);
> +	if (resource == NULL) {
> +		wl_client_post_no_memory(client);
> +		return;
> +	}
> +
> +	wl_resource_set_implementation(resource, &pointer_gestures_interface,
> +				       compositor, NULL);
> +}
> +
>  WL_EXPORT int
>  weston_environment_get_fd(const char *env)
>  {
> @@ -4501,6 +4597,10 @@ weston_compositor_create(struct wl_display *display, void *user_data)
>  			      ec, bind_presentation))
>  		goto fail;
>  
> +	if (!wl_global_create(ec->wl_display, &_wl_pointer_gestures_interface, 1,
> +			      ec, bind_pointer_gestures))
> +		goto fail;
> +
>  	wl_list_init(&ec->view_list);
>  	wl_list_init(&ec->plane_list);
>  	wl_list_init(&ec->layer_list);
> diff --git a/src/compositor.h b/src/compositor.h
> index d0c6034..15f1b5c 100644
> --- a/src/compositor.h
> +++ b/src/compositor.h
> @@ -323,6 +323,11 @@ struct weston_pointer {
>  	struct wl_signal focus_signal;
>  	struct wl_signal motion_signal;
>  
> +	struct wl_list swipe_gesture_resource_list;
> +	struct wl_list swipe_gesture_focus_resource_list;
> +	struct wl_list pinch_gesture_resource_list;
> +	struct wl_list pinch_gesture_focus_resource_list;
> +
>  	struct weston_view *sprite;
>  	struct wl_listener sprite_destroy_listener;
>  	int32_t hotspot_x, hotspot_y;
> diff --git a/src/input.c b/src/input.c
> index 1d7e705..68a6365 100644
> --- a/src/input.c
> +++ b/src/input.c
> @@ -480,6 +480,11 @@ weston_pointer_create(struct weston_seat *seat)
>  	wl_signal_init(&pointer->focus_signal);
>  	wl_list_init(&pointer->focus_view_listener.link);
>  
> +	wl_list_init(&pointer->swipe_gesture_resource_list);
> +	wl_list_init(&pointer->swipe_gesture_focus_resource_list);
> +	wl_list_init(&pointer->pinch_gesture_resource_list);
> +	wl_list_init(&pointer->pinch_gesture_focus_resource_list);
> +
>  	pointer->sprite_destroy_listener.notify = pointer_handle_sprite_destroy;
>  
>  	/* FIXME: Pick better co-ords. */
> @@ -649,6 +654,10 @@ weston_pointer_set_focus(struct weston_pointer *pointer,
>  		}
>  
>  		move_resources(&pointer->resource_list, focus_resource_list);
> +		move_resources(&pointer->swipe_gesture_resource_list,
> +			       &pointer->swipe_gesture_focus_resource_list);
> +		move_resources(&pointer->pinch_gesture_resource_list,
> +			       &pointer->pinch_gesture_focus_resource_list);
>  	}
>  
>  	if (find_resource_for_view(&pointer->resource_list, view) && refocus) {
> @@ -675,6 +684,13 @@ weston_pointer_set_focus(struct weston_pointer *pointer,
>  		}
>  
>  		pointer->focus_serial = serial;
> +
> +		move_resources_for_client(&pointer->swipe_gesture_focus_resource_list,
> +					  &pointer->swipe_gesture_resource_list,
> +					  surface_client);
> +		move_resources_for_client(&pointer->pinch_gesture_focus_resource_list,
> +					  &pointer->pinch_gesture_resource_list,
> +					  surface_client);
>  	}
>  
>  	wl_list_remove(&pointer->focus_view_listener.link);
> -- 
> 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