[PATCH weston v2 5/5] clients: Add pointer gesture support to weston-eventdemo

Jonas Ådahl jadahl at gmail.com
Wed Jul 29 00:12:24 PDT 2015


On Thu, Jul 23, 2015 at 07:00:31PM +0200, Carlos Garnacho wrote:
> Just print the output, as with the other events.
> 
> Signed-off-by: Carlos Garnacho <carlosg at gnome.org>

Another potential demonstration would be to use pinch gesture in
image.c. It already have all the necessary functionaity so it would just
be to plug in gesture events I imagine.

Anyway, this i Reviewed-by: Jonas Ådahl <jadahl at gmail.com>

> ---
>  clients/eventdemo.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 101 insertions(+), 1 deletion(-)
> 
> diff --git a/clients/eventdemo.c b/clients/eventdemo.c
> index dc69fd6..1401580 100644
> --- a/clients/eventdemo.c
> +++ b/clients/eventdemo.c
> @@ -80,6 +80,12 @@ static int log_axis = 0;
>  /** set to log motion events */
>  static int log_motion = 0;
>  
> +/** set to log swipe gesture events */
> +static int log_swipe_gesture = 0;
> +
> +/** set to log pinch gesture events */
> +static int log_pinch_gesture = 0;
> +
>  /**
>   * \struct eventdemo
>   * \brief Holds all data the program needs per window
> @@ -289,6 +295,83 @@ motion_handler(struct widget *widget, struct input *input, uint32_t time,
>  	return CURSOR_LEFT_PTR;
>  }
>  
> +static void
> +gesture_swipe_begin_handler(struct widget *widget,
> +			    struct input *input,
> +			    uint32_t time,
> +			    uint32_t n_fingers,
> +			    void *data)
> +{
> +	if (log_swipe_gesture) {
> +		printf("swipe gesture begin time: %d, fingers: %d\n", time, n_fingers);
> +	}
> +}
> +
> +static void
> +gesture_swipe_update_handler(struct widget *widget,
> +			     struct input *input,
> +			     uint32_t time,
> +			     float dx,
> +			     float dy,
> +			     void *data)
> +{
> +	if (log_swipe_gesture) {
> +		printf("swipe gesture update time: %d, dx: %f, dy: %f\n", time, dx, dy);
> +	}
> +}
> +
> +static void
> +gesture_swipe_end_handler(struct widget *widget,
> +			  struct input *input,
> +			  uint32_t time,
> +			  int32_t cancelled,
> +			  void *data)
> +{
> +	if (log_swipe_gesture) {
> +		printf("swipe gesture end time: %d, cancelled: %d\n", time, cancelled);
> +	}
> +}
> +
> +static void
> +gesture_pinch_begin_handler(struct widget *widget,
> +			    struct input *input,
> +			    uint32_t time,
> +			    uint32_t n_fingers,
> +			    void *data)
> +{
> +	if (log_pinch_gesture) {
> +		printf("pinch gesture begin time: %d, fingers: %d\n", time, n_fingers);
> +	}
> +}
> +
> +static void
> +gesture_pinch_update_handler(struct widget *widget,
> +			     struct input *input,
> +			     uint32_t time,
> +			     float dx,
> +			     float dy,
> +			     float scale,
> +			     float rotation_delta,
> +			     void *data)
> +{
> +	if (log_pinch_gesture) {
> +		printf("pinch gesture update time: %d, dx: %f, dy: %f, scale: %f, rotation delta: %f\n",
> +		       time, dx, dy, scale, rotation_delta);
> +	}
> +}
> +
> +static void
> +gesture_pinch_end_handler(struct widget *widget,
> +			  struct input *input,
> +			  uint32_t time,
> +			  int32_t cancelled,
> +			  void *data)
> +{
> +	if (log_pinch_gesture) {
> +		printf("pinch gesture end time: %d, cancelled: %d\n", time, cancelled);
> +	}
> +}
> +
>  /**
>   * \brief Create and initialise a new eventdemo window.
>   * The returned eventdemo instance should be destroyed using \c eventdemo_destroy().
> @@ -350,6 +433,20 @@ eventdemo_create(struct display *d)
>  	/* Set the callback axis handler for the window */
>  	widget_set_axis_handler(e->widget, axis_handler);
>  
> +	/* Set gesture handlers for the window */
> +	widget_set_pointer_gesture_swipe_begin_handler(e->widget,
> +						       gesture_swipe_begin_handler);
> +	widget_set_pointer_gesture_swipe_update_handler(e->widget,
> +							gesture_swipe_update_handler);
> +	widget_set_pointer_gesture_swipe_end_handler(e->widget,
> +						     gesture_swipe_end_handler);
> +	widget_set_pointer_gesture_pinch_begin_handler(e->widget,
> +						       gesture_pinch_begin_handler);
> +	widget_set_pointer_gesture_pinch_update_handler(e->widget,
> +							gesture_pinch_update_handler);
> +	widget_set_pointer_gesture_pinch_end_handler(e->widget,
> +						     gesture_pinch_end_handler);
> +
>  	/* Initial drawing of the window */
>  	window_schedule_resize(e->window, width, height);
>  
> @@ -382,6 +479,8 @@ static const struct weston_option eventdemo_options[] = {
>  	{ WESTON_OPTION_BOOLEAN, "log-button", 0, &log_button },
>  	{ WESTON_OPTION_BOOLEAN, "log-axis", 0, &log_axis },
>  	{ WESTON_OPTION_BOOLEAN, "log-motion", 0, &log_motion },
> +	{ WESTON_OPTION_BOOLEAN, "log-swipe-gesture", 0, &log_swipe_gesture },
> +	{ WESTON_OPTION_BOOLEAN, "log-pinch-gesture", 0, &log_pinch_gesture },
>  };
>  
>  /**
> @@ -419,7 +518,8 @@ main(int argc, char *argv[])
>  	if (!log_redraw && !log_resize && !log_focus && !log_key &&
>  	    !log_button && !log_axis && !log_motion)
>  	  log_redraw = log_resize = log_focus = log_key =
> -	    log_button = log_axis = log_motion = 1;
> +	    log_button = log_axis = log_motion =
> +	    log_swipe_gesture = log_pinch_gesture = 1;
>  
>  	/* Connect to the display and have the arguments parsed */
>  	d = display_create(&argc, argv);
> -- 
> 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