[PATCH weston 3/4] clients: Request the wl_pointer_gesture_swipe/pinch interfaces
Carlos Garnacho
carlosg at gnome.org
Wed Jul 15 11:06:01 PDT 2015
This is accompanied by separate handlers for the different stages
of swipe/pinch gestures, so those can be set in demos.
Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
---
clients/window.c | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
clients/window.h | 54 +++++++++++++++
2 files changed, 248 insertions(+), 2 deletions(-)
diff --git a/clients/window.c b/clients/window.c
index 8e43e18..05706fb 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -239,7 +239,6 @@ struct window {
int fullscreen;
int maximized;
-
enum preferred_format preferred_format;
window_key_handler_t key_handler;
@@ -288,6 +287,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 +317,8 @@ struct input {
struct wl_pointer *pointer;
struct wl_keyboard *keyboard;
struct wl_touch *touch;
+ struct wl_pointer_gesture_swipe *swipe_gesture;
+ struct wl_pointer_gesture_pinch *pinch_gesture;
struct wl_list touch_point_list;
struct window *pointer_focus;
struct window *keyboard_focus;
@@ -1930,6 +1937,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);
@@ -3215,6 +3264,133 @@ 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, 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, 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)
{
@@ -3225,8 +3401,24 @@ seat_handle_capabilities(void *data, struct wl_seat *seat,
wl_pointer_set_user_data(input->pointer, input);
wl_pointer_add_listener(input->pointer, &pointer_listener,
input);
+
+ input->swipe_gesture = wl_pointer_get_swipe_gesture(input->pointer);
+ wl_pointer_gesture_swipe_set_user_data (input->swipe_gesture, input);
+ wl_pointer_gesture_swipe_add_listener (input->swipe_gesture,
+ &pointer_swipe_listener,
+ input);
+
+ input->pinch_gesture = wl_pointer_get_pinch_gesture(input->pointer);
+ wl_pointer_gesture_pinch_set_user_data (input->pinch_gesture, input);
+ wl_pointer_gesture_pinch_add_listener (input->pinch_gesture,
+ &pointer_pinch_listener,
+ input);
} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
+ wl_pointer_gesture_swipe_destroy(input->swipe_gesture);
+ wl_pointer_gesture_pinch_destroy(input->pinch_gesture);
wl_pointer_destroy(input->pointer);
+ input->swipe_gesture = NULL;
+ input->pinch_gesture = NULL;
input->pointer = NULL;
}
@@ -5149,7 +5341,7 @@ display_add_input(struct display *d, uint32_t id)
input = xzalloc(sizeof *input);
input->display = d;
input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface,
- MIN(d->seat_version, 4));
+ MIN(d->seat_version, 5));
input->touch_focus = NULL;
input->pointer_focus = NULL;
input->keyboard_focus = NULL;
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
More information about the wayland-devel
mailing list