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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
/*****************************************************************************
*
* grail - Gesture Recognition And Instantiation Library
*
* Copyright (C) 2010 Canonical Ltd.
* Copyright (C) 2010 Henrik Rydberg <rydberg@bitmath.org>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
****************************************************************************/
#ifndef _GRAIL_H
#define _GRAIL_H
#include <linux/input.h>
#include <grail-bits.h>
#include <grail-types.h>
#include <utouch/frame.h>
#ifdef __cplusplus
extern "C" {
#endif
#define GRAIL_VERSION 0x00011000
#define DIM_GRAIL_TYPE 64
#define DIM_GRAIL_TYPE_BYTES ((DIM_GRAIL_TYPE + 7) >> 3)
#define DIM_GRAIL_PROP 32
#define DIM_GRAIL_PROP_BYTES ((DIM_GRAIL_PROP + 7) >> 3)
#define GRAIL_STATUS_BEGIN 0
#define GRAIL_STATUS_UPDATE 1
#define GRAIL_STATUS_END 2
typedef float grail_prop_t; /* gesture properties */
typedef utouch_frame_time_t grail_time_t; /* time in milliseconds */
/**
* struct grail_get_version - get grail library version
*
* Report the version of the grail library, which can be different from
* the value of GRAIL_VERSION in this header file.
*
* This function allows for fallback options from major interface
* extensions within the same ABI version. For the normal cases of ABI
* agnostic or backwards incompatible changes, this function is not
* needed.
*/
unsigned int GRAIL_PUBLIC grail_get_version(void);
/**
* struct grail_coord - coordinate in bounding box units
* @x: the horizontal position (bbox units)
* @y: the vertical position (bbox units)
*/
struct grail_coord {
float x, y;
};
/**
* struct grail_client_id - Gesture client information
* @client: Client id
* @root: Root window
* @event: Window to route events to
* @child: Window the event occured in
*
* This struct is treated opaquely, and only has meaning to the gesture
* client. Details are subject to change.
*/
struct grail_client_id {
int client;
int root, event, child;
};
/**
* struct grail_client_info - Gesture request information
* @id: Gesture client id
* @mask: Gestures the client is listening to
*/
struct grail_client_info {
struct grail_client_id id;
grail_mask_t mask[DIM_GRAIL_TYPE_BYTES];
};
/**
* struct grail_event - Gesture event
* @type: The gesture type
* @id: Unique identifier foof the gesture instance
* @status: Gesture status (begin, update, end)
* @ntouch: Number of current touches
* @nprop: Number of properties in the gesture
* @pos: Focus point of the gesture (bbox coordinates)
* @touch: Array of individual touch information
* @client_id: The gesture client to route the gesture to
* @time: Time of event (milliseconds)
* @prop: Array of properties of the event
*
* Gesture events are passed to the client via the gesture() callback.
*/
struct grail_event {
int type;
int id;
int status;
int ntouch;
int nprop;
struct grail_coord pos;
struct grail_client_id client_id;
grail_time_t time;
grail_prop_t prop[DIM_GRAIL_PROP];
};
/**
* struct grail - Main grail device
* @get_clients: Called at the onset of new gestures to retrieve the list
* of listening clients.
* @event: Callback for kernel events passing through grail.
* @gesture: Main gesture callback.
* @impl: Grail implementation details.
* @gin: Gesture instatiation details.
* @gru: Gesture recognition details.
* @priv: Generic pointer to user-defined content.
*
* The grail device pulls events from the underlying device, detects
* gestures, and passes them on to the client via the gesture()
* callback. Events that are not gesture or for other reasons held back are
* passed on via the event() callback. The user provides information about
* windows and listening clients via the get_clients callback, which is
* called during gesture instantiation.
*
*/
struct grail {
int (*get_clients)(struct grail *ge,
struct grail_client_info *client, int max_clients,
const struct grail_coord *coords, int num_coords,
const grail_mask_t *types, int type_bytes);
void (*event)(struct grail *ge,
const struct input_event *ev);
void (*gesture)(struct grail *ge,
const struct grail_event *ev);
struct grail_impl *impl;
struct gesture_inserter *gin;
struct gesture_recognizer *gru;
void *priv;
};
/**
* grail_open - open a grail device
* @ge: the grail device to open
* @fd: file descriptor of the kernel device
*
* Initialize the internal grail structures and configure it by reading the
* protocol capabilities through the file descriptor.
*
* The callbacks, parameters and priv pointer should be set prior to this
* call.
*
* Returns zero on success, negative error number otherwise.
*/
int GRAIL_PUBLIC grail_open(struct grail *ge, int fd);
/**
* grail_idle - check state of kernel device
* @ge: the grail device in use
* @fd: file descriptor of the kernel device
* @ms: number of milliseconds to wait for activity
*
* Returns true if the device is idle, i.e., there are no fetched
* events in the pipe and there is nothing to fetch from the device.
*/
int GRAIL_PUBLIC grail_idle(struct grail *ge, int fd, int ms);
/**
* grail_pull - pull and process available events from the kernel device
* @ge: the grail device in use
* @fd: file descriptor of the kernel device
*
* Pull all available events and process them. The grail callbacks are
* invoked during this call.
*
* The underlying file descriptor must have O_NONBLOCK set, or this method
* will not return until the file is closed.
*
* On success, returns the number of events read. Otherwise,
* a standard negative error number is returned.
*/
int GRAIL_PUBLIC grail_pull(struct grail *ge, int fd);
/**
* grail_close - close the grail device
* @ge: the grail device to close
* @fd: file descriptor of the kernel device
*
* Deallocates all memory associated with grail, and clears the grail
* structure.
*/
void GRAIL_PUBLIC grail_close(struct grail *ge, int fd);
/**
* grail_set_bbox - set the grail unit bounding box
* @ge: the grail device in use
* @min: the minimum (lower-left) corner of the bounding box
* @max: the maximum (upper-right) corner of the bounding box
*
* Sets the box within which the device coordinates should be presented.
*/
void GRAIL_PUBLIC grail_set_bbox(struct grail *ge,
const struct grail_coord *min,
const struct grail_coord *max);
/**
* grail_get_units - get device coordinate ranges
* @ge: the grail device in use
* @min: minimum x and y coordinates
* @max: maximum x and y coordinates
*
* The grail event attributes pos, touch_major, touch_minor,
* width_major, and width_minor are all given in device coordinate
* units, unless specified otherwise using the grail_set_bbox()
* function. This function reports the device coordinate ranges.
*
*/
void GRAIL_PUBLIC grail_get_units(const struct grail *ge,
struct grail_coord *min,
struct grail_coord *max);
/**
* grail_get_contact_frame - get current contact frame
* @ge: the grail device in use
*
* Return the contact frame current being processed. If called from
* within a gesture callback, it is guaranteed to return the frame
* corresponding to the gesture.
*
* The returned pointer can be NULL if no input has yet been extracted
* through the grail instance.
*
* The frame pointer is ABI agnostic, owned by the grail instance, and
* has grail scope.
*/
const struct utouch_frame GRAIL_PUBLIC *
grail_get_contact_frame(const struct grail *ge);
#ifndef GRAIL_NO_LEGACY_API
struct grail_contact {
int id;
int tool_type;
struct grail_coord pos;
float touch_major;
float touch_minor;
float width_major;
float width_minor;
float angle;
float pressure;
};
void GRAIL_PUBLIC grail_filter_abs_events(struct grail *ge, int usage);
int GRAIL_PUBLIC grail_get_contacts(const struct grail *ge,
struct grail_contact *touch, int max_touch);
#endif
#ifdef __cplusplus
}
#endif
#endif
|