1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
* Wayland Support
*
* 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: José Expósito <jose.exposito89@gmail.com>
*/
#include "config.h"
#include "wayland/meta-wayland-pointer-gesture-hold.h"
#include <glib.h>
#include "wayland/meta-wayland-pointer.h"
#include "wayland/meta-wayland-seat.h"
#include "wayland/meta-wayland-surface.h"
#include "pointer-gestures-unstable-v1-server-protocol.h"
static void
handle_hold_begin (MetaWaylandPointer *pointer,
const ClutterEvent *event)
{
MetaWaylandPointerClient *pointer_client;
MetaWaylandSeat *seat;
struct wl_resource *resource;
uint32_t serial, fingers;
pointer_client = pointer->focus_client;
seat = meta_wayland_pointer_get_seat (pointer);
serial = wl_display_next_serial (seat->wl_display);
fingers = clutter_event_get_touchpad_gesture_finger_count (event);
pointer_client->active_touchpad_gesture = event->type;
wl_resource_for_each (resource, &pointer_client->hold_gesture_resources)
{
zwp_pointer_gesture_hold_v1_send_begin (resource, serial,
clutter_event_get_time (event),
pointer->focus_surface->resource,
fingers);
}
}
static void
broadcast_end (MetaWaylandPointer *pointer,
uint32_t serial,
uint32_t time,
gboolean cancelled)
{
MetaWaylandPointerClient *pointer_client;
struct wl_resource *resource;
pointer_client = pointer->focus_client;
wl_resource_for_each (resource, &pointer_client->hold_gesture_resources)
{
zwp_pointer_gesture_hold_v1_send_end (resource, serial,
time, cancelled);
}
pointer_client->active_touchpad_gesture = CLUTTER_NOTHING;
}
static void
handle_hold_end (MetaWaylandPointer *pointer,
const ClutterEvent *event)
{
MetaWaylandSeat *seat;
gboolean cancelled = FALSE;
uint32_t serial;
seat = meta_wayland_pointer_get_seat (pointer);
serial = wl_display_next_serial (seat->wl_display);
if (event->touchpad_hold.phase == CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL)
cancelled = TRUE;
broadcast_end (pointer, serial,
clutter_event_get_time (event),
cancelled);
}
gboolean
meta_wayland_pointer_gesture_hold_handle_event (MetaWaylandPointer *pointer,
const ClutterEvent *event)
{
if (event->type != CLUTTER_TOUCHPAD_HOLD)
return FALSE;
if (!pointer->focus_client)
return FALSE;
switch (event->touchpad_hold.phase)
{
case CLUTTER_TOUCHPAD_GESTURE_PHASE_BEGIN:
handle_hold_begin (pointer, event);
break;
case CLUTTER_TOUCHPAD_GESTURE_PHASE_END:
case CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL:
handle_hold_end (pointer, event);
break;
default:
return FALSE;
}
return TRUE;
}
static void
pointer_gesture_hold_release (struct wl_client *client,
struct wl_resource *resource)
{
wl_resource_destroy (resource);
}
static const struct zwp_pointer_gesture_hold_v1_interface pointer_gesture_hold_interface = {
pointer_gesture_hold_release
};
void
meta_wayland_pointer_gesture_hold_create_new_resource (MetaWaylandPointer *pointer,
struct wl_client *client,
struct wl_resource *pointer_resource,
uint32_t id)
{
MetaWaylandPointerClient *pointer_client;
struct wl_resource *res;
res = wl_resource_create (client, &zwp_pointer_gesture_hold_v1_interface,
wl_resource_get_version (pointer_resource), id);
wl_resource_set_implementation (res, &pointer_gesture_hold_interface, pointer,
meta_wayland_pointer_unbind_pointer_client_resource);
if (pointer)
{
pointer_client = meta_wayland_pointer_get_pointer_client (pointer, client);
g_return_if_fail (pointer_client != NULL);
wl_list_insert (&pointer_client->hold_gesture_resources,
wl_resource_get_link (res));
}
}
void
meta_wayland_pointer_gesture_hold_cancel (MetaWaylandPointer *pointer,
uint32_t serial)
{
broadcast_end (pointer, serial,
us2ms (g_get_monotonic_time ()),
TRUE);
}
|