[PATCH weston v4] clients: Request the wl_pointer_gesture_swipe/pinch interfaces

Bryce Harrington bryce at osg.samsung.com
Wed Aug 26 16:55:57 PDT 2015


On Wed, Aug 05, 2015 at 04:03:21PM +0200, Carlos Garnacho wrote:
> This is accompanied by separate handlers for the different stages
> of swipe/pinch gestures, so those can be set in demos.
> 
> v4: Indenting fix.
> v3: added null checks around pointer gesture interface destruction,
>     nullify afterwards.
> v2: depend on standalone protocol xml.
> 
> Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
> Reviewed-by: Jonas Ã…dahl <jadahl at gmail.com>

LGTM
Reviewed-by: Bryce Harrington <bryce at osg.samsung.com>

> ---
>  Makefile.am      |   2 +
>  clients/window.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  clients/window.h |  54 ++++++++++++++
>  3 files changed, 268 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile.am b/Makefile.am
> index 6334865..0f0cf78 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -508,6 +508,8 @@ libtoytoolkit_la_SOURCES =				\
>  	shared/helpers.h
>  
>  nodist_libtoytoolkit_la_SOURCES =			\
> +	protocol/pointer-gestures-protocol.c		\
> +	protocol/pointer-gestures-client-protocol.h	\
>  	protocol/text-cursor-position-protocol.c	\
>  	protocol/text-cursor-position-client-protocol.h	\
>  	protocol/scaler-protocol.c			\
> diff --git a/clients/window.c b/clients/window.c
> index e97fe85..fd4a35e 100644
> --- a/clients/window.c
> +++ b/clients/window.c
> @@ -71,6 +71,7 @@ typedef void *EGLContext;
>  #include "xdg-shell-client-protocol.h"
>  #include "text-cursor-position-client-protocol.h"
>  #include "workspaces-client-protocol.h"
> +#include "pointer-gestures-client-protocol.h"
>  #include "shared/os-compatibility.h"
>  
>  #include "window.h"
> @@ -99,6 +100,7 @@ struct display {
>  	struct workspace_manager *workspace_manager;
>  	struct xdg_shell *xdg_shell;
>  	struct ivi_application *ivi_application; /* ivi style shell */
> +	struct _wl_pointer_gestures *pointer_gestures;
>  	EGLDisplay dpy;
>  	EGLConfig argb_config;
>  	EGLContext argb_ctx;
> @@ -239,7 +241,6 @@ struct window {
>  
>  	int fullscreen;
>  	int maximized;
> -
>  	enum preferred_format preferred_format;
>  
>  	window_key_handler_t key_handler;
> @@ -288,6 +289,12 @@ struct widget {
>  	widget_touch_frame_handler_t touch_frame_handler;
>  	widget_touch_cancel_handler_t touch_cancel_handler;
>  	widget_axis_handler_t axis_handler;
> +	widget_pointer_gesture_swipe_begin_handler_t swipe_begin_handler;
> +	widget_pointer_gesture_swipe_update_handler_t swipe_update_handler;
> +	widget_pointer_gesture_swipe_end_handler_t swipe_end_handler;
> +	widget_pointer_gesture_pinch_begin_handler_t pinch_begin_handler;
> +	widget_pointer_gesture_pinch_update_handler_t pinch_update_handler;
> +	widget_pointer_gesture_pinch_end_handler_t pinch_end_handler;
>  	void *user_data;
>  	int opaque;
>  	int tooltip_count;
> @@ -312,6 +319,8 @@ struct input {
>  	struct wl_pointer *pointer;
>  	struct wl_keyboard *keyboard;
>  	struct wl_touch *touch;
> +	struct _wl_pointer_gesture_pinch *pinch;
> +	struct _wl_pointer_gesture_swipe *swipe;
>  	struct wl_list touch_point_list;
>  	struct window *pointer_focus;
>  	struct window *keyboard_focus;
> @@ -1935,6 +1944,48 @@ widget_set_axis_handler(struct widget *widget,
>  	widget->axis_handler = handler;
>  }
>  
> +void
> +widget_set_pointer_gesture_swipe_begin_handler(struct widget *widget,
> +					       widget_pointer_gesture_swipe_begin_handler_t handler)
> +{
> +	widget->swipe_begin_handler = handler;
> +}
> +
> +void
> +widget_set_pointer_gesture_swipe_update_handler(struct widget *widget,
> +						widget_pointer_gesture_swipe_update_handler_t handler)
> +{
> +	widget->swipe_update_handler = handler;
> +}
> +
> +void
> +widget_set_pointer_gesture_swipe_end_handler(struct widget *widget,
> +					     widget_pointer_gesture_swipe_end_handler_t handler)
> +{
> +	widget->swipe_end_handler = handler;
> +}
> +
> +void
> +widget_set_pointer_gesture_pinch_begin_handler(struct widget *widget,
> +					       widget_pointer_gesture_pinch_begin_handler_t handler)
> +{
> +	widget->pinch_begin_handler = handler;
> +}
> +
> +void
> +widget_set_pointer_gesture_pinch_update_handler(struct widget *widget,
> +						widget_pointer_gesture_pinch_update_handler_t handler)
> +{
> +	widget->pinch_update_handler = handler;
> +}
> +
> +void
> +widget_set_pointer_gesture_pinch_end_handler(struct widget *widget,
> +					     widget_pointer_gesture_pinch_end_handler_t handler)
> +{
> +	widget->pinch_end_handler = handler;
> +}
> +
>  static void
>  window_schedule_redraw_task(struct window *window);
>  
> @@ -3245,19 +3296,175 @@ static const struct wl_touch_listener touch_listener = {
>  };
>  
>  static void
> +gesture_swipe_handle_begin(void *data, struct _wl_pointer_gesture_swipe *swipe,
> +			   uint32_t serial, uint32_t time,
> +			   struct wl_surface *surface, uint32_t n_fingers)
> +{
> +	struct input *input = data;
> +	struct widget *widget;
> +
> +	if (input->grab)
> +		widget = input->grab;
> +	else
> +		widget = input->focus_widget;
> +
> +	if (widget && widget->swipe_begin_handler) {
> +		widget->swipe_begin_handler(input->focus_widget, input,
> +					    time, n_fingers, widget->user_data);
> +	}
> +}
> +
> +static void
> +gesture_swipe_handle_update(void *data, struct _wl_pointer_gesture_swipe *swipe,
> +			    uint32_t time, wl_fixed_t dx, wl_fixed_t dy)
> +{
> +	struct input *input = data;
> +	struct widget *widget;
> +
> +	if (input->grab)
> +		widget = input->grab;
> +	else
> +		widget = input->focus_widget;
> +
> +	if (widget && widget->swipe_update_handler) {
> +		widget->swipe_update_handler(input->focus_widget, input, time,
> +					     wl_fixed_to_double(dx),
> +					     wl_fixed_to_double(dy),
> +					     widget->user_data);
> +	}
> +}
> +
> +static void
> +gesture_swipe_handle_end(void *data, struct _wl_pointer_gesture_swipe *swipe,
> +			 uint32_t serial, uint32_t time, int32_t cancelled)
> +{
> +	struct input *input = data;
> +	struct widget *widget;
> +
> +	if (input->grab)
> +		widget = input->grab;
> +	else
> +		widget = input->focus_widget;
> +
> +	if (widget && widget->swipe_end_handler) {
> +		widget->swipe_end_handler(input->focus_widget, input, time,
> +					  cancelled, widget->user_data);
> +	}
> +}
> +
> +static const struct _wl_pointer_gesture_swipe_listener pointer_swipe_listener = {
> +	gesture_swipe_handle_begin,
> +	gesture_swipe_handle_update,
> +	gesture_swipe_handle_end
> +};
> +
> +static void
> +gesture_pinch_handle_begin(void *data, struct _wl_pointer_gesture_pinch *pinch,
> +			   uint32_t serial, uint32_t time,
> +			   struct wl_surface *surface, uint32_t n_fingers)
> +{
> +	struct input *input = data;
> +	struct widget *widget;
> +
> +	if (input->grab)
> +		widget = input->grab;
> +	else
> +		widget = input->focus_widget;
> +
> +	if (widget && widget->pinch_begin_handler) {
> +		widget->pinch_begin_handler(input->focus_widget, input,
> +					    time, n_fingers, widget->user_data);
> +	}
> +}
> +
> +static void
> +gesture_pinch_handle_update(void *data, struct _wl_pointer_gesture_pinch *pinch,
> +			    uint32_t time, wl_fixed_t dx, wl_fixed_t dy,
> +			    wl_fixed_t scale, wl_fixed_t rotation_delta)
> +{
> +	struct input *input = data;
> +	struct widget *widget;
> +
> +	if (input->grab)
> +		widget = input->grab;
> +	else
> +		widget = input->focus_widget;
> +
> +	if (widget && widget->pinch_update_handler) {
> +		widget->pinch_update_handler(input->focus_widget, input, time,
> +					     wl_fixed_to_double(dx),
> +					     wl_fixed_to_double(dy),
> +					     wl_fixed_to_double(scale),
> +					     wl_fixed_to_double(rotation_delta),
> +					     widget->user_data);
> +	}
> +}
> +
> +static void
> +gesture_pinch_handle_end(void *data, struct _wl_pointer_gesture_pinch *pinch,
> +			 uint32_t serial, uint32_t time, int32_t cancelled)
> +{
> +	struct input *input = data;
> +	struct widget *widget;
> +
> +	if (input->grab)
> +		widget = input->grab;
> +	else
> +		widget = input->focus_widget;
> +
> +	if (widget && widget->pinch_end_handler) {
> +		widget->pinch_end_handler(input->focus_widget, input, time,
> +					  cancelled, widget->user_data);
> +	}
> +}
> +
> +static const struct _wl_pointer_gesture_pinch_listener pointer_pinch_listener = {
> +	gesture_pinch_handle_begin,
> +	gesture_pinch_handle_update,
> +	gesture_pinch_handle_end
> +};
> +
> +static void
>  seat_handle_capabilities(void *data, struct wl_seat *seat,
>  			 enum wl_seat_capability caps)
>  {
>  	struct input *input = data;
> +	struct display *d = input->display;
>  
>  	if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
>  		input->pointer = wl_seat_get_pointer(seat);
>  		wl_pointer_set_user_data(input->pointer, input);
>  		wl_pointer_add_listener(input->pointer, &pointer_listener,
>  					input);
> +
> +		if (d->pointer_gestures) {
> +			input->pinch =
> +				_wl_pointer_gestures_get_pinch_gesture(d->pointer_gestures,
> +								       input->pointer);
> +			_wl_pointer_gesture_pinch_add_listener(input->pinch,
> +							       &pointer_pinch_listener,
> +							       input);
> +			_wl_pointer_gesture_pinch_set_user_data(input->pinch,
> +								input);
> +
> +			input->swipe =
> +				_wl_pointer_gestures_get_swipe_gesture(d->pointer_gestures,
> +								       input->pointer);
> +			_wl_pointer_gesture_swipe_add_listener(input->swipe,
> +							       &pointer_swipe_listener,
> +							       input);
> +			_wl_pointer_gesture_swipe_set_user_data(input->swipe,
> +								input);
> +		}
>  	} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
> +		if (input->pinch)
> +			_wl_pointer_gesture_pinch_destroy(input->pinch);
> +		if (input->swipe)
> +			_wl_pointer_gesture_swipe_destroy(input->swipe);
>  		wl_pointer_destroy(input->pointer);
>  		input->pointer = NULL;
> +		input->pinch = NULL;
> +		input->swipe = NULL;
>  	}
>  
>  	if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) {
> @@ -5405,6 +5612,10 @@ registry_handle_global(void *data, struct wl_registry *registry, uint32_t id,
>  		d->subcompositor =
>  			wl_registry_bind(registry, id,
>  					 &wl_subcompositor_interface, 1);
> +	} else if (strcmp(interface, "_wl_pointer_gestures") == 0) {
> +		d->pointer_gestures =
> +			wl_registry_bind(registry, id,
> +					 &_wl_pointer_gestures_interface, 1);
>  	}
>  	else if (strcmp(interface, "ivi_application") == 0) {
>  		d->ivi_application =
> diff --git a/clients/window.h b/clients/window.h
> index b61a62a..bc8e278 100644
> --- a/clients/window.h
> +++ b/clients/window.h
> @@ -267,6 +267,41 @@ typedef void (*widget_axis_handler_t)(struct widget *widget,
>  				      wl_fixed_t value,
>  				      void *data);
>  
> +typedef void (*widget_pointer_gesture_swipe_begin_handler_t)(struct widget *widget,
> +							     struct input *input,
> +							     uint32_t time,
> +							     uint32_t n_fingers,
> +							     void *data);
> +typedef void (*widget_pointer_gesture_swipe_update_handler_t)(struct widget *widget,
> +							      struct input *input,
> +							      uint32_t time,
> +							      float dx,
> +							      float dy,
> +							      void *data);
> +typedef void (*widget_pointer_gesture_swipe_end_handler_t)(struct widget *widget,
> +							   struct input *input,
> +							   uint32_t time,
> +							   int32_t cancelled,
> +							   void *data);
> +typedef void (*widget_pointer_gesture_pinch_begin_handler_t)(struct widget *widget,
> +							     struct input *input,
> +							     uint32_t time,
> +							     uint32_t n_fingers,
> +							     void *data);
> +typedef void (*widget_pointer_gesture_pinch_update_handler_t)(struct widget *widget,
> +							      struct input *input,
> +							      uint32_t time,
> +							      float dx,
> +							      float dy,
> +							      float scale,
> +							      float rotation_delta,
> +							      void *data);
> +typedef void (*widget_pointer_gesture_pinch_end_handler_t)(struct widget *widget,
> +							   struct input *input,
> +							   uint32_t time,
> +							   int32_t cancelled,
> +							   void *data);
> +
>  struct window *
>  window_create(struct display *display);
>  struct window *
> @@ -520,6 +555,25 @@ void
>  widget_set_axis_handler(struct widget *widget,
>  			widget_axis_handler_t handler);
>  void
> +widget_set_pointer_gesture_swipe_begin_handler(struct widget *widget,
> +					       widget_pointer_gesture_swipe_begin_handler_t handler);
> +void
> +widget_set_pointer_gesture_swipe_update_handler(struct widget *widget,
> +						widget_pointer_gesture_swipe_update_handler_t handler);
> +void
> +widget_set_pointer_gesture_swipe_end_handler(struct widget *widget,
> +					     widget_pointer_gesture_swipe_end_handler_t handler);
> +void
> +widget_set_pointer_gesture_pinch_begin_handler(struct widget *widget,
> +					       widget_pointer_gesture_pinch_begin_handler_t handler);
> +void
> +widget_set_pointer_gesture_pinch_update_handler(struct widget *widget,
> +						widget_pointer_gesture_pinch_update_handler_t handler);
> +void
> +widget_set_pointer_gesture_pinch_end_handler(struct widget *widget,
> +					     widget_pointer_gesture_pinch_end_handler_t handler);
> +
> +void
>  widget_schedule_redraw(struct widget *widget);
>  void
>  widget_set_use_cairo(struct widget *widget, int use_cairo);
> -- 
> 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