[PATCH weston v2 3/5] compositor: Emit wl_pointer_gesture_* events on libinput gesture events

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


On Thu, Jul 23, 2015 at 07:00:29PM +0200, Carlos Garnacho wrote:
> The translation is fairly straightforward so far, it would be convenient
> if gestures went through the pointer grab interface, but this is not done
> at the moment.
> 
> Signed-off-by: Carlos Garnacho <carlosg at gnome.org>

Oh, forgot to mention one thing. I don't think this patch should be
separate from from the previous one. As separate the first patch is
simply incomplete, which makes no sense. But together they implement the
protocol, so I'd prefer if the patch series represent that.


Jonas

> ---
>  src/compositor.h      |   7 +++
>  src/input.c           | 107 ++++++++++++++++++++++++++++++++++++++
>  src/libinput-device.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 255 insertions(+)
> 
> diff --git a/src/compositor.h b/src/compositor.h
> index 15f1b5c..4d43995 100644
> --- a/src/compositor.h
> +++ b/src/compositor.h
> @@ -1097,6 +1097,13 @@ void
>  notify_touch_frame(struct weston_seat *seat);
>  
>  void
> +notify_pointer_swipe(struct weston_seat *seat, uint32_t time, int cancelled,
> +		     int fingers, wl_fixed_t dx, wl_fixed_t dy, int gesture_type);
> +void
> +notify_pointer_pinch(struct weston_seat *seat, uint32_t time, int cancelled,
> +		     int fingers, wl_fixed_t dx, wl_fixed_t dy,
> +		     wl_fixed_t scale, wl_fixed_t rotation_diff, int gesture_type);
> +void
>  weston_layer_entry_insert(struct weston_layer_entry *list,
>  			  struct weston_layer_entry *entry);
>  void
> diff --git a/src/input.c b/src/input.c
> index 68a6365..352b6c9 100644
> --- a/src/input.c
> +++ b/src/input.c
> @@ -37,6 +37,7 @@
>  #include "shared/helpers.h"
>  #include "shared/os-compatibility.h"
>  #include "compositor.h"
> +#include "protocol/gestures-server-protocol.h"
>  
>  static void
>  empty_region(pixman_region32_t *region)
> @@ -1717,6 +1718,112 @@ static const struct wl_pointer_interface pointer_interface = {
>  	pointer_release
>  };
>  
> +WL_EXPORT void
> +notify_pointer_swipe(struct weston_seat *seat, uint32_t time, int cancelled,
> +		     int fingers, wl_fixed_t dx, wl_fixed_t dy, int gesture_type)
> +{
> +	struct weston_compositor *ec = seat->compositor;
> +	struct weston_pointer *pointer = seat->pointer;
> +	struct weston_view *focus;
> +	struct wl_display *display = ec->wl_display;
> +	struct wl_list *resource_list;
> +	struct wl_resource *resource;
> +	uint32_t serial;
> +
> +	/* XXX: make gestures go through grab interface? */
> +
> +	if (!seat->pointer || !seat->pointer->focus)
> +		return;
> +
> +	weston_compositor_wake(ec);
> +	resource_list = &pointer->swipe_gesture_focus_resource_list;
> +	focus = seat->pointer->focus;
> +
> +	if (wl_list_empty(resource_list))
> +		return;
> +
> +	switch (gesture_type) {
> +	case _WL_POINTER_GESTURE_SWIPE_BEGIN:
> +		serial = wl_display_next_serial(display);
> +		wl_resource_for_each(resource, resource_list) {
> +			_wl_pointer_gesture_swipe_send_begin(resource, serial,
> +							     time,
> +							     focus->surface->resource,
> +							     fingers);
> +		}
> +		break;
> +	case _WL_POINTER_GESTURE_SWIPE_UPDATE:
> +		wl_resource_for_each(resource, resource_list) {
> +			_wl_pointer_gesture_swipe_send_update(resource, time,
> +							      dx, dy);
> +		}
> +		break;
> +	case _WL_POINTER_GESTURE_SWIPE_END:
> +		serial = wl_display_next_serial(display);
> +		wl_resource_for_each(resource, resource_list) {
> +			_wl_pointer_gesture_swipe_send_end(resource, serial,
> +							   time, cancelled);
> +		}
> +		break;
> +	default:
> +		return;
> +	}
> +}
> +
> +WL_EXPORT void
> +notify_pointer_pinch(struct weston_seat *seat, uint32_t time, int cancelled,
> +		     int fingers, wl_fixed_t dx, wl_fixed_t dy,
> +		     wl_fixed_t scale, wl_fixed_t rotation_diff, int gesture_type)
> +{
> +	struct weston_compositor *ec = seat->compositor;
> +	struct weston_pointer *pointer = seat->pointer;
> +	struct weston_view *focus;
> +	struct wl_display *display = ec->wl_display;
> +	struct wl_list *resource_list;
> +	struct wl_resource *resource;
> +	uint32_t serial;
> +
> +	if (!seat->pointer || !seat->pointer->focus)
> +		return;
> +
> +	/* XXX: make gestures go through grab interface? */
> +
> +	weston_compositor_wake(ec);
> +	resource_list = &pointer->pinch_gesture_focus_resource_list;
> +	focus = seat->pointer->focus;
> +
> +	if (wl_list_empty(resource_list))
> +		return;
> +
> +	switch (gesture_type) {
> +	case _WL_POINTER_GESTURE_PINCH_BEGIN:
> +		serial = wl_display_next_serial(display);
> +		wl_resource_for_each(resource, resource_list) {
> +			_wl_pointer_gesture_pinch_send_begin(resource, serial,
> +							     time,
> +							     focus->surface->resource,
> +							     fingers);
> +		}
> +		break;
> +	case _WL_POINTER_GESTURE_PINCH_UPDATE:
> +		wl_resource_for_each(resource, resource_list) {
> +			_wl_pointer_gesture_pinch_send_update(resource, time,
> +							      dx, dy, scale,
> +							      rotation_diff);
> +		}
> +		break;
> +	case _WL_POINTER_GESTURE_PINCH_END:
> +		serial = wl_display_next_serial(display);
> +		wl_resource_for_each(resource, resource_list) {
> +			_wl_pointer_gesture_pinch_send_end(resource, serial,
> +							   time, cancelled);
> +		}
> +		break;
> +	default:
> +		return;
> +	}
> +}
> +
>  static void
>  seat_get_pointer(struct wl_client *client, struct wl_resource *resource,
>  		 uint32_t id)
> diff --git a/src/libinput-device.c b/src/libinput-device.c
> index 2cbfb88..d0cd494 100644
> --- a/src/libinput-device.c
> +++ b/src/libinput-device.c
> @@ -39,6 +39,7 @@
>  #include "compositor.h"
>  #include "libinput-device.h"
>  #include "shared/helpers.h"
> +#include "protocol/gestures-server-protocol.h"
>  
>  #define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int(10)
>  
> @@ -287,6 +288,122 @@ handle_touch_frame(struct libinput_device *libinput_device,
>  	notify_touch_frame(seat);
>  }
>  
> +static void
> +handle_pointer_swipe_begin(struct libinput_device *libinput_device,
> +			   struct libinput_event_gesture *gesture_event)
> +{
> +	struct evdev_device *device =
> +		libinput_device_get_user_data(libinput_device);
> +	struct weston_seat *seat = device->seat;
> +	uint32_t time, fingers;
> +
> +	time = libinput_event_gesture_get_time(gesture_event);
> +	fingers = libinput_event_gesture_get_finger_count(gesture_event);
> +	notify_pointer_swipe(seat, time, 0, fingers, 0, 0,
> +			     _WL_POINTER_GESTURE_SWIPE_BEGIN);
> +}
> +
> +static void
> +handle_pointer_swipe_update(struct libinput_device *libinput_device,
> +			   struct libinput_event_gesture *gesture_event)
> +{
> +	struct evdev_device *device =
> +		libinput_device_get_user_data(libinput_device);
> +	struct weston_seat *seat = device->seat;
> +	uint32_t time, fingers;
> +	double dx, dy;
> +
> +	time = libinput_event_gesture_get_time(gesture_event);
> +	fingers = libinput_event_gesture_get_finger_count(gesture_event);
> +	dx = libinput_event_gesture_get_dx(gesture_event);
> +	dy = libinput_event_gesture_get_dx(gesture_event);
> +
> +	notify_pointer_swipe(seat, time, 0, fingers,
> +			     wl_fixed_from_double(dx),
> +			     wl_fixed_from_double(dy),
> +			     _WL_POINTER_GESTURE_SWIPE_UPDATE);
> +}
> +
> +static void
> +handle_pointer_swipe_end(struct libinput_device *libinput_device,
> +			   struct libinput_event_gesture *gesture_event)
> +{
> +	struct evdev_device *device =
> +		libinput_device_get_user_data(libinput_device);
> +	struct weston_seat *seat = device->seat;
> +	uint32_t time, fingers, cancelled;
> +
> +	time = libinput_event_gesture_get_time(gesture_event);
> +	fingers = libinput_event_gesture_get_finger_count(gesture_event);
> +	cancelled = libinput_event_gesture_get_cancelled(gesture_event);
> +
> +	notify_pointer_swipe(seat, time, cancelled, fingers, 0, 0,
> +			     _WL_POINTER_GESTURE_SWIPE_END);
> +}
> +
> +static void
> +handle_pointer_pinch_begin(struct libinput_device *libinput_device,
> +			   struct libinput_event_gesture *gesture_event)
> +{
> +	struct evdev_device *device =
> +		libinput_device_get_user_data(libinput_device);
> +	struct weston_seat *seat = device->seat;
> +	uint32_t time, fingers;
> +	double scale;
> +
> +	time = libinput_event_gesture_get_time(gesture_event);
> +	fingers = libinput_event_gesture_get_finger_count(gesture_event);
> +	scale = libinput_event_gesture_get_scale(gesture_event);
> +
> +	notify_pointer_pinch(seat, time, 0, fingers, 0, 0, scale, 0,
> +			     _WL_POINTER_GESTURE_PINCH_BEGIN);
> +}
> +
> +static void
> +handle_pointer_pinch_update(struct libinput_device *libinput_device,
> +			   struct libinput_event_gesture *gesture_event)
> +{
> +	struct evdev_device *device =
> +		libinput_device_get_user_data(libinput_device);
> +	struct weston_seat *seat = device->seat;
> +	double scale, angle_delta, dx, dy;
> +	uint32_t time, fingers;
> +
> +	time = libinput_event_gesture_get_time(gesture_event);
> +	fingers = libinput_event_gesture_get_finger_count(gesture_event);
> +	scale = libinput_event_gesture_get_scale(gesture_event);
> +	angle_delta = libinput_event_gesture_get_angle_delta(gesture_event);
> +	dx = libinput_event_gesture_get_dx(gesture_event);
> +	dy = libinput_event_gesture_get_dx(gesture_event);
> +
> +	notify_pointer_pinch(seat, time, 0, fingers,
> +			     wl_fixed_from_double(dx),
> +			     wl_fixed_from_double(dy),
> +			     wl_fixed_from_double(scale),
> +			     wl_fixed_from_double(angle_delta),
> +			     _WL_POINTER_GESTURE_PINCH_UPDATE);
> +}
> +
> +static void
> +handle_pointer_pinch_end(struct libinput_device *libinput_device,
> +			 struct libinput_event_gesture *gesture_event)
> +{
> +	struct evdev_device *device =
> +		libinput_device_get_user_data(libinput_device);
> +	struct weston_seat *seat = device->seat;
> +	uint32_t time, fingers, cancelled;
> +	double scale;
> +
> +	time = libinput_event_gesture_get_time(gesture_event);
> +	fingers = libinput_event_gesture_get_finger_count(gesture_event);
> +	cancelled = libinput_event_gesture_get_cancelled(gesture_event);
> +	scale = libinput_event_gesture_get_scale(gesture_event);
> +
> +	notify_pointer_pinch(seat, time, cancelled, fingers,
> +			     0, 0, wl_fixed_from_double(scale), 0,
> +			     _WL_POINTER_GESTURE_PINCH_END);
> +}
> +
>  int
>  evdev_device_process_event(struct libinput_event *event)
>  {
> @@ -332,6 +449,30 @@ evdev_device_process_event(struct libinput_event *event)
>  		handle_touch_frame(libinput_device,
>  				   libinput_event_get_touch_event(event));
>  		break;
> +	case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
> +		handle_pointer_swipe_begin(libinput_device,
> +					   libinput_event_get_gesture_event(event));
> +		break;
> +	case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
> +		handle_pointer_swipe_update(libinput_device,
> +					    libinput_event_get_gesture_event(event));
> +		break;
> +	case LIBINPUT_EVENT_GESTURE_SWIPE_END:
> +		handle_pointer_swipe_end(libinput_device,
> +					 libinput_event_get_gesture_event(event));
> +		break;
> +	case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
> +		handle_pointer_pinch_begin(libinput_device,
> +					   libinput_event_get_gesture_event(event));
> +		break;
> +	case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
> +		handle_pointer_pinch_update(libinput_device,
> +					    libinput_event_get_gesture_event(event));
> +		break;
> +	case LIBINPUT_EVENT_GESTURE_PINCH_END:
> +		handle_pointer_pinch_end(libinput_device,
> +					 libinput_event_get_gesture_event(event));
> +		break;
>  	default:
>  		handled = 0;
>  		weston_log("unknown libinput event %d\n",
> -- 
> 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