[gtk+/wip/garnacho/touchpad-gestures: 14/14] wayland: Implement wl_gesture_swipe/pinch
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/garnacho/touchpad-gestures: 14/14] wayland: Implement wl_gesture_swipe/pinch
- Date: Thu, 9 Jul 2015 17:46:55 +0000 (UTC)
commit 3e0c815982f7e05ae0bfdddd9997a7483b77a7ad
Author: Carlos Garnacho <carlosg gnome org>
Date: Thu Jul 9 19:36:30 2015 +0200
wayland: Implement wl_gesture_swipe/pinch
Translate these into GdkEventTouchpadSwipe/Pinch events.
gdk/wayland/gdkdevice-wayland.c | 233 +++++++++++++++++++++++++++++++++++++++
1 files changed, 233 insertions(+), 0 deletions(-)
---
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index d16c92f..0427b1b 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -54,6 +54,8 @@ struct _GdkWaylandDeviceData
struct wl_pointer *wl_pointer;
struct wl_keyboard *wl_keyboard;
struct wl_touch *wl_touch;
+ struct _wl_gesture_swipe *wl_gesture_swipe;
+ struct _wl_gesture_pinch *wl_gesture_pinch;
GdkDisplay *display;
GdkDeviceManager *device_manager;
@@ -99,6 +101,10 @@ struct _GdkWaylandDeviceData
/* Source/dest for non-local dnd */
GdkWindow *foreign_dnd_window;
+
+ /* Some tracking on gesture events */
+ guint gesture_n_fingers;
+ gdouble gesture_scale;
};
struct _GdkWaylandDevice
@@ -1652,6 +1658,211 @@ touch_handle_cancel (void *data,
GDK_NOTE (EVENTS, g_message ("touch cancel"));
}
+static void
+emit_gesture_swipe_event (GdkWaylandDeviceData *device,
+ GdkEventType type,
+ guint32 _time,
+ guint32 n_fingers,
+ gdouble dx,
+ gdouble dy)
+{
+ GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (device->display);
+ GdkEvent *event;
+
+ if (!device->pointer_focus)
+ return;
+
+ device->time = _time;
+
+ event = gdk_event_new (type);
+ event->touchpad_swipe.window = g_object_ref (device->pointer_focus);
+ gdk_event_set_device (event, device->master_pointer);
+ gdk_event_set_source_device (event, device->pointer);
+ event->touchpad_swipe.time = _time;
+ event->touchpad_swipe.state = device->button_modifiers | device->key_modifiers;
+ gdk_event_set_screen (event, display->screen);
+ event->touchpad_swipe.dx = dx;
+ event->touchpad_swipe.dy = dy;
+ event->touchpad_swipe.n_fingers = n_fingers;
+
+ get_coordinates (device,
+ &event->touchpad_swipe.x,
+ &event->touchpad_swipe.y,
+ &event->touchpad_swipe.x_root,
+ &event->touchpad_swipe.y_root);
+
+ GDK_NOTE (EVENTS,
+ g_message ("swipe event %d, coords: %f %f, device %p state %d",
+ event->type, event->touchpad_swipe.x,
+ event->touchpad_swipe.y, device,
+ event->touchpad_swipe.state));
+
+ _gdk_wayland_display_deliver_event (device->display, event);
+}
+
+static void
+gesture_swipe_begin (void *data,
+ struct _wl_gesture_swipe *swipe,
+ uint32_t serial,
+ uint32_t time,
+ struct wl_surface *surface,
+ int32_t id,
+ uint32_t fingers)
+{
+ GdkWaylandDeviceData *device = data;
+ GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (device->display);
+
+ _gdk_wayland_display_update_serial (display, serial);
+
+ emit_gesture_swipe_event (device,
+ GDK_TOUCHPAD_SWIPE_BEGIN,
+ time, fingers, 0, 0);
+ device->gesture_n_fingers = fingers;
+}
+
+static void
+gesture_swipe_update (void *data,
+ struct _wl_gesture_swipe *swipe,
+ uint32_t time,
+ int32_t id,
+ wl_fixed_t dx,
+ wl_fixed_t dy)
+{
+ GdkWaylandDeviceData *device = data;
+
+ emit_gesture_swipe_event (device,
+ GDK_TOUCHPAD_SWIPE_UPDATE,
+ time,
+ device->gesture_n_fingers,
+ wl_fixed_to_double (dx),
+ wl_fixed_to_double (dy));
+}
+
+static void
+gesture_swipe_end (void *data,
+ struct _wl_gesture_swipe *swipe,
+ uint32_t serial,
+ uint32_t time,
+ int32_t id,
+ int32_t cancelled)
+{
+ GdkWaylandDeviceData *device = data;
+ GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (device->display);
+ GdkEventType evtype;
+
+ _gdk_wayland_display_update_serial (display, serial);
+
+ evtype = (cancelled) ?
+ GDK_TOUCHPAD_SWIPE_CANCEL :
+ GDK_TOUCHPAD_SWIPE_END;
+
+ emit_gesture_swipe_event (device, evtype, time,
+ device->gesture_n_fingers, 0, 0);
+}
+
+static void
+emit_gesture_pinch_event (GdkWaylandDeviceData *device,
+ GdkEventType type,
+ guint32 _time,
+ gdouble dx,
+ gdouble dy,
+ gdouble scale,
+ gdouble angle_delta)
+{
+ GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (device->display);
+ GdkEvent *event;
+
+ if (!device->pointer_focus)
+ return;
+
+ device->time = _time;
+
+ event = gdk_event_new (type);
+ event->touchpad_pinch.window = g_object_ref (device->pointer_focus);
+ gdk_event_set_device (event, device->master_pointer);
+ gdk_event_set_source_device (event, device->pointer);
+ event->touchpad_pinch.time = _time;
+ event->touchpad_pinch.state = device->button_modifiers | device->key_modifiers;
+ gdk_event_set_screen (event, display->screen);
+ event->touchpad_pinch.dx = dx;
+ event->touchpad_pinch.dy = dy;
+ event->touchpad_pinch.scale = scale;
+ event->touchpad_pinch.angle_delta = angle_delta;
+
+ get_coordinates (device,
+ &event->touchpad_pinch.x,
+ &event->touchpad_pinch.y,
+ &event->touchpad_pinch.x_root,
+ &event->touchpad_pinch.y_root);
+
+ GDK_NOTE (EVENTS,
+ g_message ("pinch event %d, coords: %f %f, device %p state %d",
+ event->type, event->touchpad_pinch.x,
+ event->touchpad_pinch.y, device,
+ event->touchpad_pinch.state));
+
+ _gdk_wayland_display_deliver_event (device->display, event);
+}
+
+static void
+gesture_pinch_begin (void *data,
+ struct _wl_gesture_pinch *pinch,
+ uint32_t serial,
+ uint32_t time,
+ struct wl_surface *surface,
+ int32_t id)
+{
+ GdkWaylandDeviceData *device = data;
+ GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (device->display);
+
+ _gdk_wayland_display_update_serial (display, serial);
+ emit_gesture_pinch_event (device,
+ GDK_TOUCHPAD_PINCH_BEGIN,
+ time, 0, 0, 1, 0);
+}
+
+static void
+gesture_pinch_update (void *data,
+ struct _wl_gesture_pinch *pinch,
+ uint32_t time,
+ int32_t id,
+ wl_fixed_t dx,
+ wl_fixed_t dy,
+ wl_fixed_t scale,
+ wl_fixed_t rotation)
+{
+ GdkWaylandDeviceData *device = data;
+
+ emit_gesture_pinch_event (device,
+ GDK_TOUCHPAD_PINCH_UPDATE, time,
+ wl_fixed_to_double (dx),
+ wl_fixed_to_double (dy),
+ wl_fixed_to_double (scale),
+ wl_fixed_to_double (rotation));
+}
+
+static void
+gesture_pinch_end (void *data,
+ struct _wl_gesture_pinch *pinch,
+ uint32_t serial,
+ uint32_t time,
+ int32_t id,
+ int32_t cancelled)
+{
+ GdkWaylandDeviceData *device = data;
+ GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (device->display);
+ GdkEventType evtype;
+
+ _gdk_wayland_display_update_serial (display, serial);
+
+ evtype = (cancelled) ?
+ GDK_TOUCHPAD_PINCH_CANCEL :
+ GDK_TOUCHPAD_PINCH_END;
+
+ emit_gesture_pinch_event (device, evtype,
+ time, 0, 0, 1, 0);
+}
+
static const struct wl_pointer_listener pointer_listener = {
pointer_handle_enter,
pointer_handle_leave,
@@ -1677,6 +1888,18 @@ static const struct wl_touch_listener touch_listener = {
touch_handle_cancel
};
+static const struct _wl_gesture_swipe_listener gesture_swipe_listener = {
+ gesture_swipe_begin,
+ gesture_swipe_update,
+ gesture_swipe_end
+};
+
+static const struct _wl_gesture_pinch_listener gesture_pinch_listener = {
+ gesture_pinch_begin,
+ gesture_pinch_update,
+ gesture_pinch_end
+};
+
static void
seat_handle_capabilities (void *data,
struct wl_seat *seat,
@@ -1715,10 +1938,20 @@ seat_handle_capabilities (void *data,
device->drop_context = _gdk_wayland_drop_context_new (device->master_pointer,
device->data_device);
+ device->wl_gesture_swipe = wl_pointer_get_swipe (device->wl_pointer);
+ _wl_gesture_swipe_set_user_data (device->wl_gesture_swipe, device);
+ _wl_gesture_swipe_add_listener (device->wl_gesture_swipe, &gesture_swipe_listener, device);
+
+ device->wl_gesture_pinch = wl_pointer_get_pinch (device->wl_pointer);
+ _wl_gesture_pinch_set_user_data (device->wl_gesture_pinch, device);
+ _wl_gesture_pinch_add_listener (device->wl_gesture_pinch, &gesture_pinch_listener, device);
+
g_signal_emit_by_name (device_manager, "device-added", device->pointer);
}
else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && device->wl_pointer)
{
+ _wl_gesture_pinch_release (device->wl_gesture_pinch);
+ _wl_gesture_swipe_release (device->wl_gesture_swipe);
wl_pointer_release (device->wl_pointer);
device->wl_pointer = NULL;
_gdk_device_set_associated_device (device->pointer, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]