[PATCH weston 1/4] compositor: Implement wl_pointer_gesture_swipe/pinch interfaces

Carlos Garnacho carlosg at gnome.org
Wed Jul 15 11:05:59 PDT 2015


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.

Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
---
 src/compositor.h |  5 +++
 src/input.c      | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 96 insertions(+), 3 deletions(-)

diff --git a/src/compositor.h b/src/compositor.h
index faaacc2..1340e26 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 568985f..12005a6 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);
@@ -1696,9 +1712,81 @@ pointer_release(struct wl_client *client, struct wl_resource *resource)
 	wl_resource_destroy(resource);
 }
 
+static void
+pointer_gesture_swipe_release (struct wl_client *client, struct wl_resource *resource)
+{
+	wl_resource_destroy(resource);
+}
+
+static const struct wl_pointer_gesture_swipe_interface pointer_gesture_swipe_interface = {
+	pointer_gesture_swipe_release
+};
+
+static void
+pointer_gesture_pinch_release (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_release
+};
+
+static void
+pointer_get_swipe_gesture (struct wl_client *client, struct wl_resource *resource, uint32_t id)
+{
+	struct weston_pointer *pointer = wl_resource_get_user_data(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_get_pinch_gesture(struct wl_client *client, struct wl_resource *resource, uint32_t id)
+{
+	struct weston_pointer *pointer = wl_resource_get_user_data(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);
+	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;
+
+	wl_list_insert (list, wl_resource_get_link (cr));
+}
+
 static const struct wl_pointer_interface pointer_interface = {
 	pointer_set_cursor,
-	pointer_release
+	pointer_release,
+	pointer_get_swipe_gesture,
+	pointer_get_pinch_gesture
 };
 
 static void
@@ -1896,7 +1984,7 @@ bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id)
 	enum wl_seat_capability caps = 0;
 
 	resource = wl_resource_create(client,
-				      &wl_seat_interface, MIN(version, 4), id);
+				      &wl_seat_interface, MIN(version, 5), id);
 	wl_list_insert(&seat->base_resource_list, wl_resource_get_link(resource));
 	wl_resource_set_implementation(resource, &seat_interface, data,
 				       unbind_resource);
@@ -2299,7 +2387,7 @@ weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec,
 	wl_signal_init(&seat->destroy_signal);
 	wl_signal_init(&seat->updated_caps_signal);
 
-	seat->global = wl_global_create(ec->wl_display, &wl_seat_interface, 4,
+	seat->global = wl_global_create(ec->wl_display, &wl_seat_interface, 5,
 					seat, bind_seat);
 
 	seat->compositor = ec;
-- 
2.4.3



More information about the wayland-devel mailing list