4
* Copyright (C) 2015 Red Hat
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation; either version 2 of the
9
* License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
* Author: Carlos Garnacho <carlosg@gnome.org>
28
#include "meta-wayland-pointer-gesture-pinch.h"
29
#include "meta-wayland-pointer.h"
30
#include "meta-wayland-seat.h"
31
#include "meta-wayland-surface.h"
32
#include "pointer-gestures-unstable-v1-server-protocol.h"
35
handle_pinch_begin (MetaWaylandPointer *pointer,
36
const ClutterEvent *event)
38
MetaWaylandPointerClient *pointer_client;
39
MetaWaylandSeat *seat;
40
struct wl_resource *resource;
41
uint32_t serial, fingers;
43
pointer_client = pointer->focus_client;
44
seat = meta_wayland_pointer_get_seat (pointer);
45
serial = wl_display_next_serial (seat->wl_display);
46
fingers = clutter_event_get_touchpad_gesture_finger_count (event);
48
wl_resource_for_each (resource, &pointer_client->pinch_gesture_resources)
50
zwp_pointer_gesture_pinch_v1_send_begin (resource, serial,
51
clutter_event_get_time (event),
52
pointer->focus_surface->resource,
58
handle_pinch_update (MetaWaylandPointer *pointer,
59
const ClutterEvent *event)
61
MetaWaylandPointerClient *pointer_client;
62
struct wl_resource *resource;
63
gdouble dx, dy, scale, rotation;
65
pointer_client = pointer->focus_client;
66
clutter_event_get_gesture_motion_delta (event, &dx, &dy);
67
rotation = clutter_event_get_gesture_pinch_angle_delta (event);
68
scale = clutter_event_get_gesture_pinch_scale (event);
70
wl_resource_for_each (resource, &pointer_client->pinch_gesture_resources)
72
zwp_pointer_gesture_pinch_v1_send_update (resource,
73
clutter_event_get_time (event),
74
wl_fixed_from_double (dx),
75
wl_fixed_from_double (dy),
76
wl_fixed_from_double (scale),
77
wl_fixed_from_double (rotation));
82
handle_pinch_end (MetaWaylandPointer *pointer,
83
const ClutterEvent *event)
85
MetaWaylandPointerClient *pointer_client;
86
MetaWaylandSeat *seat;
87
struct wl_resource *resource;
88
gboolean cancelled = FALSE;
91
pointer_client = pointer->focus_client;
92
seat = meta_wayland_pointer_get_seat (pointer);
93
serial = wl_display_next_serial (seat->wl_display);
95
if (event->touchpad_pinch.phase == CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL)
98
wl_resource_for_each (resource, &pointer_client->pinch_gesture_resources)
100
zwp_pointer_gesture_pinch_v1_send_end (resource, serial,
101
clutter_event_get_time (event),
107
meta_wayland_pointer_gesture_pinch_handle_event (MetaWaylandPointer *pointer,
108
const ClutterEvent *event)
110
if (event->type != CLUTTER_TOUCHPAD_PINCH)
113
if (!pointer->focus_client)
116
switch (event->touchpad_pinch.phase)
118
case CLUTTER_TOUCHPAD_GESTURE_PHASE_BEGIN:
119
handle_pinch_begin (pointer, event);
121
case CLUTTER_TOUCHPAD_GESTURE_PHASE_UPDATE:
122
handle_pinch_update (pointer, event);
124
case CLUTTER_TOUCHPAD_GESTURE_PHASE_END:
125
case CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL:
126
handle_pinch_end (pointer, event);
136
pointer_gesture_pinch_destroy (struct wl_client *client,
137
struct wl_resource *resource)
139
wl_resource_destroy (resource);
142
static const struct zwp_pointer_gesture_pinch_v1_interface pointer_gesture_pinch_interface = {
143
pointer_gesture_pinch_destroy
147
meta_wayland_pointer_gesture_pinch_create_new_resource (MetaWaylandPointer *pointer,
148
struct wl_client *client,
149
struct wl_resource *gestures_resource,
152
MetaWaylandPointerClient *pointer_client;
153
struct wl_resource *res;
155
pointer_client = meta_wayland_pointer_get_pointer_client (pointer, client);
156
g_return_if_fail (pointer_client != NULL);
158
res = wl_resource_create (client, &zwp_pointer_gesture_pinch_v1_interface,
159
wl_resource_get_version (gestures_resource), id);
160
wl_resource_set_implementation (res, &pointer_gesture_pinch_interface, pointer,
161
meta_wayland_pointer_unbind_pointer_client_resource);
162
wl_list_insert (&pointer_client->pinch_gesture_resources,
163
wl_resource_get_link (res));