[mutter/wip/garnacho/touchpad-gestures: 14/16] wayland: Add MetaWaylandPointerGestureSwipe



commit 3c4a9819d67a3d85c4dce0a1d292bc6f5b82ca19
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jul 22 16:43:25 2015 +0200

    wayland: Add MetaWaylandPointerGestureSwipe
    
    This object will take care of the maintenance of
    wl_pointer_gesture_swipe resources and ensure the right
    resources get poked on CLUTTER_TOUCHPAD_SWIPE events.

 src/Makefile.am                                  |    2 +
 src/wayland/meta-wayland-pointer-gesture-swipe.c |  211 ++++++++++++++++++++++
 src/wayland/meta-wayland-pointer-gesture-swipe.h |   52 ++++++
 src/wayland/meta-wayland-pointer.c               |    8 +
 src/wayland/meta-wayland-pointer.h               |    3 +
 src/wayland/meta-wayland-seat.c                  |    1 +
 src/wayland/meta-wayland-types.h                 |    2 +
 7 files changed, 279 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 353b598..500526c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -253,6 +253,8 @@ libmutter_la_SOURCES +=                             \
        wayland/meta-wayland-data-device.c      \
        wayland/meta-wayland-data-device.h      \
        wayland/meta-wayland-data-device-private.h      \
+       wayland/meta-wayland-pointer-gesture-swipe.c    \
+       wayland/meta-wayland-pointer-gesture-swipe.h    \
        wayland/meta-wayland-keyboard.c         \
        wayland/meta-wayland-keyboard.h         \
        wayland/meta-wayland-pointer.c          \
diff --git a/src/wayland/meta-wayland-pointer-gesture-swipe.c 
b/src/wayland/meta-wayland-pointer-gesture-swipe.c
new file mode 100644
index 0000000..6bc5d60
--- /dev/null
+++ b/src/wayland/meta-wayland-pointer-gesture-swipe.c
@@ -0,0 +1,211 @@
+/*
+ * Wayland Support
+ *
+ * Copyright (C) 2015 Red Hat
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Author: Carlos Garnacho <carlosg gnome org>
+ */
+
+#define _GNU_SOURCE
+
+#include "config.h"
+
+#include <glib.h>
+
+#include "meta-wayland-pointer-gesture-swipe.h"
+#include "meta-wayland-pointer.h"
+#include "meta-wayland-surface.h"
+#include "pointer-gestures-server-protocol.h"
+
+static void
+unbind_resource (struct wl_resource *resource)
+{
+  wl_list_remove (wl_resource_get_link (resource));
+}
+
+static void
+move_resources (struct wl_list *destination, struct wl_list *source)
+{
+  wl_list_insert_list (destination, source);
+  wl_list_init (source);
+}
+
+static void
+move_resources_for_client (struct wl_list   *destination,
+                          struct wl_list   *source,
+                          struct wl_client *client)
+{
+  struct wl_resource *resource, *tmp;
+  wl_resource_for_each_safe (resource, tmp, source)
+    {
+      if (wl_resource_get_client (resource) == client)
+        {
+          wl_list_remove (wl_resource_get_link (resource));
+          wl_list_insert (destination, wl_resource_get_link (resource));
+        }
+    }
+}
+
+static void
+handle_swipe_begin (MetaWaylandPointerGestureSwipe *swipe,
+                    const ClutterEvent             *event)
+{
+  struct wl_resource *resource;
+  uint32_t serial, fingers;
+  struct wl_list *l;
+
+  l = &swipe->focus_resource_list;
+  serial = wl_display_next_serial (swipe->pointer->display);
+  fingers = clutter_event_get_gesture_swipe_finger_count (event);
+
+  wl_resource_for_each (resource, l)
+    {
+      g_assert (swipe->pointer->focus_surface != NULL);
+      _wl_pointer_gesture_swipe_send_begin (resource, serial,
+                                            clutter_event_get_time (event),
+                                            swipe->pointer->focus_surface->resource,
+                                            fingers);
+    }
+}
+
+static void
+handle_swipe_update (MetaWaylandPointerGestureSwipe *swipe,
+                     const ClutterEvent             *event)
+{
+  struct wl_resource *resource;
+  struct wl_list *l;
+  gdouble dx, dy;
+
+  l = &swipe->focus_resource_list;
+  clutter_event_get_gesture_motion_delta (event, &dx, &dy);
+
+  wl_resource_for_each (resource, l)
+    {
+      _wl_pointer_gesture_swipe_send_update (resource,
+                                             clutter_event_get_time (event),
+                                             wl_fixed_from_double (dx),
+                                             wl_fixed_from_double (dy));
+    }
+}
+
+static void
+handle_swipe_end (MetaWaylandPointerGestureSwipe *swipe,
+                  const ClutterEvent             *event)
+{
+  struct wl_resource *resource;
+  gboolean cancelled = FALSE;
+  struct wl_list *l;
+  uint32_t serial;
+
+  l = &swipe->focus_resource_list;
+  serial = wl_display_next_serial (swipe->pointer->display);
+
+  if (event->touchpad_swipe.phase == CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL)
+    cancelled = TRUE;
+
+  wl_resource_for_each (resource, l)
+    {
+      _wl_pointer_gesture_swipe_send_end (resource, serial,
+                                          clutter_event_get_time (event),
+                                          cancelled);
+    }
+}
+
+gboolean
+meta_wayland_pointer_gesture_swipe_handle_event (MetaWaylandPointerGestureSwipe *swipe,
+                                                 const ClutterEvent             *event)
+{
+  if (event->type != CLUTTER_TOUCHPAD_SWIPE)
+    return FALSE;
+
+  switch (event->touchpad_swipe.phase)
+    {
+    case CLUTTER_TOUCHPAD_GESTURE_PHASE_BEGIN:
+      handle_swipe_begin (swipe, event);
+      break;
+    case CLUTTER_TOUCHPAD_GESTURE_PHASE_UPDATE:
+      handle_swipe_update (swipe, event);
+      break;
+    case CLUTTER_TOUCHPAD_GESTURE_PHASE_END:
+      handle_swipe_end (swipe, event);
+      break;
+    default:
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
+void
+meta_wayland_pointer_gesture_swipe_init (MetaWaylandPointerGestureSwipe *swipe,
+                                         MetaWaylandPointer             *pointer)
+{
+  swipe->pointer = pointer;
+  wl_list_init (&swipe->resource_list);
+  wl_list_init (&swipe->focus_resource_list);
+}
+
+void
+meta_wayland_pointer_gesture_swipe_release (MetaWaylandPointerGestureSwipe *swipe)
+{
+}
+
+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
+};
+
+void
+meta_wayland_pointer_gesture_swipe_create_new_resource (MetaWaylandPointerGestureSwipe *swipe,
+                                                        struct wl_client               *client,
+                                                        struct wl_resource             *pointer_resource,
+                                                        uint32_t                        id)
+{
+  MetaWaylandPointer *pointer = swipe->pointer;
+  struct wl_resource *res;
+  struct wl_list *l;
+
+  res = wl_resource_create (client, &_wl_pointer_gesture_swipe_interface, wl_resource_get_version 
(pointer_resource), id);
+  wl_resource_set_implementation (res, &pointer_gesture_swipe_interface, swipe, unbind_resource);
+
+  if (pointer->focus_surface && wl_resource_get_client (pointer->focus_surface->resource) == client)
+    l = &swipe->focus_resource_list;
+  else
+    l = &swipe->resource_list;
+
+  wl_list_insert (l, wl_resource_get_link (res));
+}
+
+void
+meta_wayland_pointer_gesture_swipe_sync_focus (MetaWaylandPointerGestureSwipe *swipe)
+{
+  MetaWaylandPointer *pointer = swipe->pointer;
+
+  move_resources (&swipe->resource_list, &swipe->focus_resource_list);
+
+  if (pointer->focus_surface)
+    move_resources_for_client (&swipe->focus_resource_list,
+                               &swipe->resource_list,
+                               wl_resource_get_client (pointer->focus_surface->resource));
+}
diff --git a/src/wayland/meta-wayland-pointer-gesture-swipe.h 
b/src/wayland/meta-wayland-pointer-gesture-swipe.h
new file mode 100644
index 0000000..3028eb5
--- /dev/null
+++ b/src/wayland/meta-wayland-pointer-gesture-swipe.h
@@ -0,0 +1,52 @@
+/*
+ * Wayland Support
+ *
+ * Copyright (C) 2015 Red Hat
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Carlos Garnacho <carlosg gnome org>
+ */
+
+#ifndef META_WAYLAND_POINTER_GESTURE_SWIPE_H
+#define META_WAYLAND_POINTER_GESTURE_SWIPE_H
+
+#include <wayland-server.h>
+#include <clutter/clutter.h>
+#include <glib.h>
+
+#include "meta-wayland-types.h"
+
+struct _MetaWaylandPointerGestureSwipe
+{
+  MetaWaylandPointer *pointer;
+  struct wl_list resource_list;
+  struct wl_list focus_resource_list;
+};
+
+void meta_wayland_pointer_gesture_swipe_init    (MetaWaylandPointerGestureSwipe *swipe,
+                                                 MetaWaylandPointer             *pointer);
+void meta_wayland_pointer_gesture_swipe_release (MetaWaylandPointerGestureSwipe *swipe);
+
+gboolean meta_wayland_pointer_gesture_swipe_handle_event (MetaWaylandPointerGestureSwipe *swipe,
+                                                          const ClutterEvent             *event);
+
+void meta_wayland_pointer_gesture_swipe_create_new_resource (MetaWaylandPointerGestureSwipe *swipe,
+                                                             struct wl_client               *client,
+                                                             struct wl_resource             
*pointer_resource,
+                                                             uint32_t                        id);
+
+void meta_wayland_pointer_gesture_swipe_sync_focus (MetaWaylandPointerGestureSwipe *swipe);
+
+#endif /* META_WAYLAND_POINTER_GESTURE_SWIPE_H */
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index a229fe2..85dd96a 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -257,11 +257,14 @@ meta_wayland_pointer_init (MetaWaylandPointer *pointer,
   pointer->device = clutter_device_manager_get_core_device (manager, CLUTTER_POINTER_DEVICE);
 
   pointer->cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
+
+  meta_wayland_pointer_gesture_swipe_init (&pointer->swipe, pointer);
 }
 
 void
 meta_wayland_pointer_release (MetaWaylandPointer *pointer)
 {
+  meta_wayland_pointer_gesture_swipe_release (&pointer->swipe);
   meta_wayland_pointer_set_focus (pointer, NULL);
   set_cursor_surface (pointer, NULL);
 
@@ -430,6 +433,10 @@ meta_wayland_pointer_handle_event (MetaWaylandPointer *pointer,
       handle_scroll_event (pointer, event);
       break;
 
+    case CLUTTER_TOUCHPAD_SWIPE:
+      meta_wayland_pointer_gesture_swipe_handle_event (&pointer->swipe, event);
+      break;
+
     default:
       break;
     }
@@ -540,6 +547,7 @@ meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer,
     }
 
   meta_wayland_pointer_update_cursor_surface (pointer);
+  meta_wayland_pointer_gesture_swipe_sync_focus (&pointer->swipe);
 }
 
 void
diff --git a/src/wayland/meta-wayland-pointer.h b/src/wayland/meta-wayland-pointer.h
index 70b7b42..5719494 100644
--- a/src/wayland/meta-wayland-pointer.h
+++ b/src/wayland/meta-wayland-pointer.h
@@ -25,6 +25,7 @@
 #include <glib.h>
 
 #include "meta-wayland-types.h"
+#include "meta-wayland-pointer-gesture-swipe.h"
 
 #include <meta/meta-cursor-tracker.h>
 
@@ -51,6 +52,8 @@ struct _MetaWaylandPointer
   struct wl_list resource_list;
   struct wl_list focus_resource_list;
 
+  MetaWaylandPointerGestureSwipe swipe;
+
   MetaWaylandSurface *focus_surface;
   struct wl_listener focus_surface_listener;
   guint32 focus_serial;
diff --git a/src/wayland/meta-wayland-seat.c b/src/wayland/meta-wayland-seat.c
index f455ad8..ec9c6c8 100644
--- a/src/wayland/meta-wayland-seat.c
+++ b/src/wayland/meta-wayland-seat.c
@@ -332,6 +332,7 @@ meta_wayland_seat_handle_event (MetaWaylandSeat *seat,
     case CLUTTER_BUTTON_PRESS:
     case CLUTTER_BUTTON_RELEASE:
     case CLUTTER_SCROLL:
+    case CLUTTER_TOUCHPAD_SWIPE:
       return meta_wayland_pointer_handle_event (&seat->pointer, event);
 
     case CLUTTER_KEY_PRESS:
diff --git a/src/wayland/meta-wayland-types.h b/src/wayland/meta-wayland-types.h
index 6b134e6..010d028 100644
--- a/src/wayland/meta-wayland-types.h
+++ b/src/wayland/meta-wayland-types.h
@@ -43,4 +43,6 @@ typedef struct _MetaWaylandOutput MetaWaylandOutput;
 
 typedef struct _MetaWaylandSerial MetaWaylandSerial;
 
+typedef struct _MetaWaylandPointerGestureSwipe MetaWaylandPointerGestureSwipe;
+
 #endif



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