[PATCH weston 2/4] compositor: Emit wl_pointer_gesture_* events on libinput gesture events

Carlos Garnacho carlosg at gnome.org
Wed Jul 15 11:06:00 PDT 2015


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>
---
 src/compositor.h      |   7 +++
 src/input.c           |  92 +++++++++++++++++++++++++++++++++
 src/libinput-device.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 239 insertions(+)

diff --git a/src/compositor.h b/src/compositor.h
index 1340e26..872392a 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 12005a6..6933144 100644
--- a/src/input.c
+++ b/src/input.c
@@ -1789,6 +1789,98 @@ static const struct wl_pointer_interface pointer_interface = {
 	pointer_get_pinch_gesture
 };
 
+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 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? */
+
+	weston_compositor_wake(ec);
+	resource_list = &pointer->swipe_gesture_focus_resource_list;
+
+	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, 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 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? */
+
+	weston_compositor_wake(ec);
+	resource_list = &pointer->pinch_gesture_focus_resource_list;
+
+	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, 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_SWIPE_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..51bdb86 100644
--- a/src/libinput-device.c
+++ b/src/libinput-device.c
@@ -287,6 +287,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 +448,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



More information about the wayland-devel mailing list