[gtk+/wip/garnacho/touchpad-gestures: 60/60] wayland: Implement wl_gesture_swipe/pinch



commit 857ed9dfeb233150550192ce9971dbbc01ca53a4
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  |  226 ++++++++++++++++++++++++++++++++++++++
 gdk/wayland/gdkdisplay-wayland.c |    2 +-
 2 files changed, 227 insertions(+), 1 deletions(-)
---
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index 7fb27c1..708014f 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_pointer_gesture_swipe *wl_pointer_gesture_swipe;
+  struct wl_pointer_gesture_pinch *wl_pointer_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
@@ -1653,6 +1659,204 @@ 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_pointer_gesture_swipe *swipe,
+                     uint32_t                         serial,
+                     uint32_t                         time,
+                     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_pointer_gesture_swipe *swipe,
+                      uint32_t                         time,
+                      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_pointer_gesture_swipe *swipe,
+                   uint32_t                         serial,
+                   uint32_t                         time,
+                   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_pointer_gesture_pinch *pinch,
+                     uint32_t                         serial,
+                     uint32_t                         time,
+                     uint32_t                         n_fingers)
+{
+  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_pointer_gesture_pinch *pinch,
+                      uint32_t                         time,
+                      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_pointer_gesture_pinch *pinch,
+                   uint32_t                         serial,
+                   uint32_t                         time,
+                   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,
@@ -1678,6 +1882,18 @@ static const struct wl_touch_listener touch_listener = {
   touch_handle_cancel
 };
 
+static const struct wl_pointer_gesture_swipe_listener gesture_swipe_listener = {
+  gesture_swipe_begin,
+  gesture_swipe_update,
+  gesture_swipe_end
+};
+
+static const struct wl_pointer_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,
@@ -1716,10 +1932,20 @@ seat_handle_capabilities (void                    *data,
       device->drop_context = _gdk_wayland_drop_context_new (device->master_pointer,
                                                             device->data_device);
 
+      device->wl_pointer_gesture_swipe = wl_pointer_get_swipe_gesture (device->wl_pointer);
+      wl_pointer_gesture_swipe_set_user_data (device->wl_pointer_gesture_swipe, device);
+      wl_pointer_gesture_swipe_add_listener (device->wl_pointer_gesture_swipe, &gesture_swipe_listener, 
device);
+
+      device->wl_pointer_gesture_pinch = wl_pointer_get_pinch_gesture (device->wl_pointer);
+      wl_pointer_gesture_pinch_set_user_data (device->wl_pointer_gesture_pinch, device);
+      wl_pointer_gesture_pinch_add_listener (device->wl_pointer_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_pointer_gesture_pinch_release (device->wl_pointer_gesture_pinch);
+      wl_pointer_gesture_swipe_release (device->wl_pointer_gesture_swipe);
       wl_pointer_release (device->wl_pointer);
       device->wl_pointer = NULL;
       _gdk_device_set_associated_device (device->pointer, NULL);
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index a0a5d0c..e80745a 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -250,7 +250,7 @@ _gdk_wayland_display_add_seat (GdkWaylandDisplay *display_wayland,
   struct wl_seat *seat;
 
   seat = wl_registry_bind (display_wayland->wl_registry,
-                           id, &wl_seat_interface, MIN (version, 4));
+                           id, &wl_seat_interface, MIN (version, 6));
   _gdk_wayland_device_manager_add_seat (gdk_display->device_manager,
                                         id, seat);
   _gdk_wayland_display_async_roundtrip (display_wayland);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]