summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2015-07-22 16:46:55 +0200
committerCarlos Garnacho <carlosg@gnome.org>2015-08-10 17:23:23 +0200
commit2fafa24305286bbeb1f29d7ced8c9bff51a29ab5 (patch)
tree67bbc5e749a98038760148e9dad888db9b60c43b
parent51a2f287235d3996ac2b883ac73cad6acfd4e966 (diff)
downloadmutter-2fafa24305286bbeb1f29d7ced8c9bff51a29ab5.tar.gz
wayland: Implement the wl_pointer_gesture_pinch interface
The pinch gesture resources are part of the MetaWaylandPointerClient, which will be used during the propagation of CLUTTER_TOUCHPAD_PINCH events.
-rw-r--r--src/Makefile.am2
-rw-r--r--src/wayland/meta-wayland-pointer-gesture-pinch.c160
-rw-r--r--src/wayland/meta-wayland-pointer-gesture-pinch.h39
-rw-r--r--src/wayland/meta-wayland-pointer.c13
-rw-r--r--src/wayland/meta-wayland-pointer.h2
-rw-r--r--src/wayland/meta-wayland-seat.c1
6 files changed, 216 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index cde939499..74b5a33b1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -257,6 +257,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 000000000..37022c9d1
--- /dev/null
+++ b/src/wayland/meta-wayland-pointer-gesture-pinch.c
@@ -0,0 +1,160 @@
+/*
+ * 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
+handle_pinch_begin (MetaWaylandPointer *pointer,
+ const ClutterEvent *event)
+{
+ MetaWaylandPointerClient *pointer_client;
+ struct wl_resource *resource;
+ uint32_t serial;
+
+ pointer_client = pointer->focus_client;
+ serial = wl_display_next_serial (pointer->display);
+
+ wl_resource_for_each (resource, &pointer_client->pinch_gesture_resources)
+ {
+ _wl_pointer_gesture_pinch_send_begin (resource, serial,
+ clutter_event_get_time (event),
+ pointer->focus_surface->resource,
+ 2);
+ }
+}
+
+static void
+handle_pinch_update (MetaWaylandPointer *pointer,
+ const ClutterEvent *event)
+{
+ MetaWaylandPointerClient *pointer_client;
+ struct wl_resource *resource;
+ gdouble dx, dy, scale, rotation;
+
+ pointer_client = pointer->focus_client;
+ 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, &pointer_client->pinch_gesture_resources)
+ {
+ _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 (MetaWaylandPointer *pointer,
+ const ClutterEvent *event)
+{
+ MetaWaylandPointerClient *pointer_client;
+ struct wl_resource *resource;
+ gboolean cancelled = FALSE;
+ uint32_t serial;
+
+ pointer_client = pointer->focus_client;
+ serial = wl_display_next_serial (pointer->display);
+
+ if (event->touchpad_pinch.phase == CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL)
+ cancelled = TRUE;
+
+ wl_resource_for_each (resource, &pointer_client->pinch_gesture_resources)
+ {
+ _wl_pointer_gesture_pinch_send_end (resource, serial,
+ clutter_event_get_time (event),
+ cancelled);
+ }
+}
+
+gboolean
+meta_wayland_pointer_gesture_pinch_handle_event (MetaWaylandPointer *pointer,
+ const ClutterEvent *event)
+{
+ if (event->type != CLUTTER_TOUCHPAD_PINCH)
+ return FALSE;
+
+ if (!pointer->focus_client)
+ return FALSE;
+
+ switch (event->touchpad_pinch.phase)
+ {
+ case CLUTTER_TOUCHPAD_GESTURE_PHASE_BEGIN:
+ handle_pinch_begin (pointer, event);
+ break;
+ case CLUTTER_TOUCHPAD_GESTURE_PHASE_UPDATE:
+ handle_pinch_update (pointer, event);
+ break;
+ case CLUTTER_TOUCHPAD_GESTURE_PHASE_END:
+ case CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL:
+ handle_pinch_end (pointer, event);
+ break;
+ default:
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+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 (MetaWaylandPointer *pointer,
+ struct wl_client *client,
+ struct wl_resource *gestures_resource,
+ uint32_t id)
+{
+ MetaWaylandPointerClient *pointer_client;
+ struct wl_resource *res;
+
+ pointer_client = meta_wayland_pointer_get_pointer_client (pointer, client);
+ g_return_if_fail (pointer_client != NULL);
+
+ 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, pointer,
+ meta_wayland_pointer_unbind_pointer_client_resource);
+ wl_list_insert (&pointer_client->pinch_gesture_resources,
+ wl_resource_get_link (res));
+}
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 000000000..9c4c691eb
--- /dev/null
+++ b/src/wayland/meta-wayland-pointer-gesture-pinch.h
@@ -0,0 +1,39 @@
+/*
+ * 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"
+
+gboolean meta_wayland_pointer_gesture_pinch_handle_event (MetaWaylandPointer *pointer,
+ const ClutterEvent *event);
+
+void meta_wayland_pointer_gesture_pinch_create_new_resource (MetaWaylandPointer *pointer,
+ struct wl_client *client,
+ struct wl_resource *gestures_resource,
+ uint32_t id);
+
+#endif /* META_WAYLAND_POINTER_GESTURE_PINCH_H */
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index 6269d9b83..0de7a61d9 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -66,6 +66,7 @@ meta_wayland_pointer_client_new (void)
pointer_client = g_slice_new0 (MetaWaylandPointerClient);
wl_list_init (&pointer_client->pointer_resources);
wl_list_init (&pointer_client->swipe_gesture_resources);
+ wl_list_init (&pointer_client->pinch_gesture_resources);
return pointer_client;
}
@@ -89,6 +90,11 @@ meta_wayland_pointer_client_free (MetaWaylandPointerClient *pointer_client)
wl_list_remove (wl_resource_get_link (resource));
wl_list_init (wl_resource_get_link (resource));
}
+ wl_resource_for_each (resource, &pointer_client->pinch_gesture_resources)
+ {
+ wl_list_remove (wl_resource_get_link (resource));
+ wl_list_init (wl_resource_get_link (resource));
+ }
g_slice_free (MetaWaylandPointerClient, pointer_client);
}
@@ -97,7 +103,8 @@ static gboolean
meta_wayland_pointer_client_is_empty (MetaWaylandPointerClient *pointer_client)
{
return (wl_list_empty (&pointer_client->pointer_resources) &&
- wl_list_empty (&pointer_client->swipe_gesture_resources));
+ wl_list_empty (&pointer_client->swipe_gesture_resources) &&
+ wl_list_empty (&pointer_client->pinch_gesture_resources));
}
MetaWaylandPointerClient *
@@ -546,6 +553,10 @@ meta_wayland_pointer_handle_event (MetaWaylandPointer *pointer,
meta_wayland_pointer_gesture_swipe_handle_event (pointer, event);
break;
+ case CLUTTER_TOUCHPAD_PINCH:
+ meta_wayland_pointer_gesture_pinch_handle_event (pointer, event);
+ break;
+
default:
break;
}
diff --git a/src/wayland/meta-wayland-pointer.h b/src/wayland/meta-wayland-pointer.h
index 744d9e480..8dfbf627f 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>
@@ -49,6 +50,7 @@ struct _MetaWaylandPointerClient
{
struct wl_list pointer_resources;
struct wl_list swipe_gesture_resources;
+ struct wl_list pinch_gesture_resources;
};
struct _MetaWaylandPointer
diff --git a/src/wayland/meta-wayland-seat.c b/src/wayland/meta-wayland-seat.c
index ec9c6c8cb..58f2697b0 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: