[mutter/wip/garnacho/touchpad-gestures: 15/16] wayland: Add MetaWaylandPointerGesturePinch
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/garnacho/touchpad-gestures: 15/16] wayland: Add MetaWaylandPointerGesturePinch
- Date: Mon, 3 Aug 2015 17:02:59 +0000 (UTC)
commit 840677d31d49e7459463aa2f8b6baea1d0f3b298
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Jul 22 16:46:55 2015 +0200
wayland: Add MetaWaylandPointerGesturePinch
This object will take care of the maintenance of
wl_pointer_gesture_pinch resources and ensure the right
resources get poked on CLUTTER_TOUCHPAD_PINCH events.
src/Makefile.am | 2 +
src/wayland/meta-wayland-pointer-gesture-pinch.c | 215 ++++++++++++++++++++++
src/wayland/meta-wayland-pointer-gesture-pinch.h | 52 ++++++
src/wayland/meta-wayland-pointer.c | 7 +
src/wayland/meta-wayland-pointer.h | 2 +
src/wayland/meta-wayland-seat.c | 1 +
src/wayland/meta-wayland-types.h | 1 +
7 files changed, 280 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 500526c..3e97231 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -255,6 +255,8 @@ libmutter_la_SOURCES += \
wayland/meta-wayland-data-device-private.h \
wayland/meta-wayland-pointer-gesture-swipe.c \
wayland/meta-wayland-pointer-gesture-swipe.h \
+ wayland/meta-wayland-pointer-gesture-pinch.c \
+ wayland/meta-wayland-pointer-gesture-pinch.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-pinch.c
b/src/wayland/meta-wayland-pointer-gesture-pinch.c
new file mode 100644
index 0000000..3aaba2e
--- /dev/null
+++ b/src/wayland/meta-wayland-pointer-gesture-pinch.c
@@ -0,0 +1,215 @@
+/*
+ * 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-pinch.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_pinch_begin (MetaWaylandPointerGesturePinch *pinch,
+ const ClutterEvent *event)
+{
+ struct wl_resource *resource;
+ struct wl_list *l;
+ uint32_t serial;
+
+ l = &pinch->focus_resource_list;
+ serial = wl_display_next_serial (pinch->pointer->display);
+
+ wl_resource_for_each (resource, l)
+ {
+ g_assert (pinch->pointer->focus_surface != NULL);
+ _wl_pointer_gesture_pinch_send_begin (resource, serial,
+ clutter_event_get_time (event),
+ pinch->pointer->focus_surface->resource,
+ 2);
+ }
+}
+
+static void
+handle_pinch_update (MetaWaylandPointerGesturePinch *pinch,
+ const ClutterEvent *event)
+{
+ struct wl_resource *resource;
+ gdouble dx, dy, scale, rotation;
+ struct wl_list *l;
+
+ l = &pinch->focus_resource_list;
+ clutter_event_get_gesture_motion_delta (event, &dx, &dy);
+ rotation = clutter_event_get_gesture_pinch_angle_delta (event);
+ scale = clutter_event_get_gesture_pinch_scale (event);
+
+ wl_resource_for_each (resource, l)
+ {
+ _wl_pointer_gesture_pinch_send_update (resource,
+ clutter_event_get_time (event),
+ wl_fixed_from_double (dx),
+ wl_fixed_from_double (dy),
+ wl_fixed_from_double (scale),
+ wl_fixed_from_double (rotation));
+ }
+}
+
+static void
+handle_pinch_end (MetaWaylandPointerGesturePinch *pinch,
+ const ClutterEvent *event)
+{
+ struct wl_resource *resource;
+ gboolean cancelled = FALSE;
+ struct wl_list *l;
+ uint32_t serial;
+
+ l = &pinch->focus_resource_list;
+ serial = wl_display_next_serial (pinch->pointer->display);
+
+ if (event->touchpad_pinch.phase == CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL)
+ cancelled = TRUE;
+
+ wl_resource_for_each (resource, l)
+ {
+ _wl_pointer_gesture_pinch_send_end (resource, serial,
+ clutter_event_get_time (event),
+ cancelled);
+ }
+}
+
+gboolean
+meta_wayland_pointer_gesture_pinch_handle_event (MetaWaylandPointerGesturePinch *pinch,
+ const ClutterEvent *event)
+{
+ if (event->type != CLUTTER_TOUCHPAD_PINCH)
+ return FALSE;
+
+ switch (event->touchpad_pinch.phase)
+ {
+ case CLUTTER_TOUCHPAD_GESTURE_PHASE_BEGIN:
+ handle_pinch_begin (pinch, event);
+ break;
+ case CLUTTER_TOUCHPAD_GESTURE_PHASE_UPDATE:
+ handle_pinch_update (pinch, event);
+ break;
+ case CLUTTER_TOUCHPAD_GESTURE_PHASE_END:
+ case CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL:
+ handle_pinch_end (pinch, event);
+ break;
+ default:
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void
+meta_wayland_pointer_gesture_pinch_init (MetaWaylandPointerGesturePinch *pinch,
+ MetaWaylandPointer *pointer)
+{
+ pinch->pointer = pointer;
+ wl_list_init (&pinch->resource_list);
+ wl_list_init (&pinch->focus_resource_list);
+}
+
+void
+meta_wayland_pointer_gesture_pinch_release (MetaWaylandPointerGesturePinch *pinch)
+{
+}
+
+static void
+pointer_gesture_pinch_destroy (struct wl_client *client,
+ struct wl_resource *resource)
+{
+ wl_resource_destroy (resource);
+}
+
+static const struct _wl_pointer_gesture_pinch_interface pointer_gesture_pinch_interface = {
+ pointer_gesture_pinch_destroy
+};
+
+void
+meta_wayland_pointer_gesture_pinch_create_new_resource (MetaWaylandPointerGesturePinch *pinch,
+ struct wl_client *client,
+ struct wl_resource *gestures_resource,
+ uint32_t id)
+{
+ MetaWaylandPointer *pointer = pinch->pointer;
+ struct wl_resource *res;
+ struct wl_list *l;
+
+ res = wl_resource_create (client, &_wl_pointer_gesture_pinch_interface, wl_resource_get_version
(gestures_resource), id);
+ wl_resource_set_implementation (res, &pointer_gesture_pinch_interface, pinch, unbind_resource);
+
+ if (pointer->focus_surface && wl_resource_get_client (pointer->focus_surface->resource) == client)
+ l = &pinch->focus_resource_list;
+ else
+ l = &pinch->resource_list;
+
+ wl_list_insert (l, wl_resource_get_link (res));
+}
+
+void
+meta_wayland_pointer_gesture_pinch_sync_focus (MetaWaylandPointerGesturePinch *pinch)
+{
+ MetaWaylandPointer *pointer = pinch->pointer;
+
+ move_resources (&pinch->resource_list, &pinch->focus_resource_list);
+
+ if (pointer->focus_surface)
+ move_resources_for_client (&pinch->focus_resource_list,
+ &pinch->resource_list,
+ wl_resource_get_client (pointer->focus_surface->resource));
+}
diff --git a/src/wayland/meta-wayland-pointer-gesture-pinch.h
b/src/wayland/meta-wayland-pointer-gesture-pinch.h
new file mode 100644
index 0000000..0975c63
--- /dev/null
+++ b/src/wayland/meta-wayland-pointer-gesture-pinch.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_PINCH_H
+#define META_WAYLAND_POINTER_GESTURE_PINCH_H
+
+#include <wayland-server.h>
+#include <clutter/clutter.h>
+#include <glib.h>
+
+#include "meta-wayland-types.h"
+
+struct _MetaWaylandPointerGesturePinch
+{
+ MetaWaylandPointer *pointer;
+ struct wl_list resource_list;
+ struct wl_list focus_resource_list;
+};
+
+void meta_wayland_pointer_gesture_pinch_init (MetaWaylandPointerGesturePinch *pinch,
+ MetaWaylandPointer *pointer);
+void meta_wayland_pointer_gesture_pinch_release (MetaWaylandPointerGesturePinch *pinch);
+
+gboolean meta_wayland_pointer_gesture_pinch_handle_event (MetaWaylandPointerGesturePinch *pinch,
+ const ClutterEvent *event);
+
+void meta_wayland_pointer_gesture_pinch_create_new_resource (MetaWaylandPointerGesturePinch *pinch,
+ struct wl_client *client,
+ struct wl_resource
*gestures_resource,
+ uint32_t id);
+
+void meta_wayland_pointer_gesture_pinch_sync_focus (MetaWaylandPointerGesturePinch *pinch);
+
+#endif /* META_WAYLAND_POINTER_GESTURE_PINCH_H */
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index 85dd96a..ae0135e 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -259,12 +259,14 @@ meta_wayland_pointer_init (MetaWaylandPointer *pointer,
pointer->cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
meta_wayland_pointer_gesture_swipe_init (&pointer->swipe, pointer);
+ meta_wayland_pointer_gesture_pinch_init (&pointer->pinch, pointer);
}
void
meta_wayland_pointer_release (MetaWaylandPointer *pointer)
{
meta_wayland_pointer_gesture_swipe_release (&pointer->swipe);
+ meta_wayland_pointer_gesture_pinch_release (&pointer->pinch);
meta_wayland_pointer_set_focus (pointer, NULL);
set_cursor_surface (pointer, NULL);
@@ -437,6 +439,10 @@ meta_wayland_pointer_handle_event (MetaWaylandPointer *pointer,
meta_wayland_pointer_gesture_swipe_handle_event (&pointer->swipe, event);
break;
+ case CLUTTER_TOUCHPAD_PINCH:
+ meta_wayland_pointer_gesture_pinch_handle_event (&pointer->pinch, event);
+ break;
+
default:
break;
}
@@ -548,6 +554,7 @@ meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer,
meta_wayland_pointer_update_cursor_surface (pointer);
meta_wayland_pointer_gesture_swipe_sync_focus (&pointer->swipe);
+ meta_wayland_pointer_gesture_pinch_sync_focus (&pointer->pinch);
}
void
diff --git a/src/wayland/meta-wayland-pointer.h b/src/wayland/meta-wayland-pointer.h
index 5719494..d420bd7 100644
--- a/src/wayland/meta-wayland-pointer.h
+++ b/src/wayland/meta-wayland-pointer.h
@@ -26,6 +26,7 @@
#include "meta-wayland-types.h"
#include "meta-wayland-pointer-gesture-swipe.h"
+#include "meta-wayland-pointer-gesture-pinch.h"
#include <meta/meta-cursor-tracker.h>
@@ -53,6 +54,7 @@ struct _MetaWaylandPointer
struct wl_list focus_resource_list;
MetaWaylandPointerGestureSwipe swipe;
+ MetaWaylandPointerGesturePinch pinch;
MetaWaylandSurface *focus_surface;
struct wl_listener focus_surface_listener;
diff --git a/src/wayland/meta-wayland-seat.c b/src/wayland/meta-wayland-seat.c
index ec9c6c8..58f2697 100644
--- a/src/wayland/meta-wayland-seat.c
+++ b/src/wayland/meta-wayland-seat.c
@@ -333,6 +333,7 @@ meta_wayland_seat_handle_event (MetaWaylandSeat *seat,
case CLUTTER_BUTTON_RELEASE:
case CLUTTER_SCROLL:
case CLUTTER_TOUCHPAD_SWIPE:
+ case CLUTTER_TOUCHPAD_PINCH:
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 010d028..094d3f2 100644
--- a/src/wayland/meta-wayland-types.h
+++ b/src/wayland/meta-wayland-types.h
@@ -44,5 +44,6 @@ typedef struct _MetaWaylandOutput MetaWaylandOutput;
typedef struct _MetaWaylandSerial MetaWaylandSerial;
typedef struct _MetaWaylandPointerGestureSwipe MetaWaylandPointerGestureSwipe;
+typedef struct _MetaWaylandPointerGesturePinch MetaWaylandPointerGesturePinch;
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]