30
30
#include <malloc.h>
33
static void tp_event(struct touch_dev *dev,
34
const struct input_event *ev)
36
struct grail *ge = dev->priv;
37
struct grail_impl *x = ge->impl;
38
if (ev->type == EV_ABS) {
41
if (ev->type == EV_KEY) {
45
case BTN_TOOL_DOUBLETAP:
46
case BTN_TOOL_TRIPLETAP:
47
case BTN_TOOL_QUADTAP:
51
evbuf_put(&x->evbuf, ev);
33
#define DIM_FRAMES 100
34
#define FRAME_RATE 100
36
void grail_filter_abs_events(struct grail *ge, int usage)
38
struct grail_impl *x = ge->impl;
39
x->filter_abs = usage;
42
static void init_impl(struct grail_impl *x)
46
if (evemu_has_event(x->evemu, EV_ABS, ABS_X)) {
47
x->emin_x = evemu_get_abs_minimum(x->evemu, ABS_X);
48
x->emin_y = evemu_get_abs_minimum(x->evemu, ABS_Y);
49
x->emax_x = evemu_get_abs_maximum(x->evemu, ABS_X);
50
x->emax_y = evemu_get_abs_maximum(x->evemu, ABS_Y);
52
struct utouch_surface *s = utouch_frame_get_surface(x->fh);
60
int grail_open(struct grail *ge, int fd)
64
x = calloc(1, sizeof(*x));
68
x->evemu = evemu_new(0);
73
ret = evemu_extract(x->evemu, fd);
76
if (!utouch_frame_is_supported_mtdev(x->evemu)) {
80
x->mtdev = mtdev_new_open(fd);
86
x->fh = utouch_frame_new_engine(DIM_FRAMES, DIM_TOUCH, FRAME_RATE);
91
ret = utouch_frame_init_mtdev(x->fh, x->evemu);
110
utouch_frame_delete_engine(x->fh);
112
mtdev_close_delete(x->mtdev);
114
evemu_delete(x->evemu);
120
void grail_close(struct grail *ge, int fd)
122
struct grail_impl *x = ge->impl;
126
utouch_frame_delete_engine(x->fh);
127
mtdev_close_delete(x->mtdev);
128
evemu_delete(x->evemu);
133
int grail_idle(struct grail *ge, int fd, int ms)
135
struct grail_impl *x = ge->impl;
136
return mtdev_idle(x->mtdev, fd, ms);
139
void grail_get_units(const struct grail *ge,
140
struct grail_coord *min, struct grail_coord *max)
142
struct utouch_surface *s = utouch_frame_get_surface(ge->impl->fh);
54
151
static void evput(struct grail_impl *x, struct timeval time,
55
152
unsigned type, unsigned code, int value)
76
173
impl->report_status = 0;
79
#define SYSCALL(call) while (((call) == -1) && (errno == EINTR))
81
static int getabs(struct input_absinfo *abs, int key, int fd)
84
SYSCALL(rc = ioctl(fd, EVIOCGABS(key), abs));
88
static void set_emulation_caps(struct grail_impl *impl, int fd)
90
struct touch_caps *emu = &impl->emu;
91
struct input_absinfo info;
93
memset(emu, 0, sizeof(*emu));
95
if (getabs(&info, ABS_X, fd)) {
96
emu->min_x = info.minimum;
97
emu->max_x = info.maximum;
99
if (getabs(&info, ABS_Y, fd)) {
100
emu->min_y = info.minimum;
101
emu->max_y = info.maximum;
105
176
static void set_pointer(struct grail_impl *impl)
107
struct touch_dev *dev = &impl->dev;
108
struct touch_caps *caps = &dev->caps;
109
struct touch_caps *emu = &impl->emu;
110
struct touch_frame *frame = &dev->frame;
178
struct utouch_surface *s = utouch_frame_get_surface(impl->fh);
179
const struct utouch_frame *frame = impl->frame;
111
180
int best_x, best_y, best_d = -1;
114
for (i = 0; i < frame->nactive; i++) {
115
struct touch *t = frame->active[i];
116
float u = (t->x - caps->min_x) / (caps->max_x - caps->min_x);
117
float v = (t->y - caps->min_y) / (caps->max_y - caps->min_y);
118
int x = emu->min_x + u * (emu->max_x - emu->min_x);
119
int y = emu->min_y + v * (emu->max_y - emu->min_y);
183
for (i = 0; i < frame->num_active; i++) {
184
const struct utouch_contact *t = frame->active[i];
185
float u = (t->x - s->min_x) / (s->max_x - s->min_x);
186
float v = (t->y - s->min_y) / (s->max_y - s->min_y);
187
int x = impl->emin_x + u * (impl->emax_x - impl->emin_x);
188
int y = impl->emin_y + v * (impl->emax_y - impl->emin_y);
120
189
int d = abs(x - impl->pointer_x) + abs(y - impl->pointer_y);
121
190
if (best_d < 0 || d < best_d) {
184
static void tp_sync(struct touch_dev *dev,
185
const struct input_event *syn)
253
static void report_frame(struct grail *ge,
254
const struct utouch_frame *frame,
255
const struct input_event *syn)
187
struct grail *ge = dev->priv;
188
258
struct grail_impl *impl = ge->impl;
189
259
int head = impl->evbuf.head;
190
260
struct input_event iev;
191
261
struct grail_event gev;
192
struct touch_frame *frame = &dev->frame;
263
ge->impl->frame = frame;
193
265
gin_frame_begin(ge, frame);
194
266
gru_recognize(ge, frame);
195
267
gin_frame_end(ge, frame);
214
void grail_filter_abs_events(struct grail *ge, int usage)
216
struct grail_impl *x = ge->impl;
217
x->filter_abs = usage;
220
int grail_open(struct grail *ge, int fd)
222
struct grail_impl *x;
224
x = calloc(1, sizeof(*x));
229
ret = touch_dev_open(&x->dev, fd);
232
set_emulation_caps(x, fd);
233
x->dev.event = tp_event;
234
x->dev.sync = tp_sync;
249
touch_dev_close(&x->dev, fd);
256
void grail_close(struct grail *ge, int fd)
258
struct grail_impl *x = ge->impl;
262
touch_dev_close(&x->dev, fd);
267
int grail_idle(struct grail *ge, int fd, int ms)
269
struct grail_impl *x = ge->impl;
270
return touch_dev_idle(&x->dev, fd, ms);
286
static void grail_pump_mtdev(struct grail *ge, const struct input_event *ev)
288
struct grail_impl *impl = ge->impl;
289
const struct utouch_frame *frame;
291
if (ev->type == EV_SYN || ev->type == EV_ABS) {
292
frame = utouch_frame_pump_mtdev(impl->fh, ev);
294
report_frame(ge, frame, ev);
295
} else if (ev->type == EV_KEY) {
298
case BTN_TOOL_FINGER:
299
case BTN_TOOL_DOUBLETAP:
300
case BTN_TOOL_TRIPLETAP:
301
case BTN_TOOL_QUADTAP:
304
evbuf_put(&impl->evbuf, ev);
308
evbuf_put(&impl->evbuf, ev);
273
312
int grail_pull(struct grail *ge, int fd)
275
struct grail_impl *x = ge->impl;
276
return touch_dev_pull(&x->dev, fd);
279
void grail_get_units(const struct grail *ge,
280
struct grail_coord *min, struct grail_coord *max)
282
const struct touch_caps *caps = &ge->impl->dev.caps;
283
min->x = caps->min_x;
284
min->y = caps->min_y;
285
max->x = caps->max_x;
286
max->y = caps->max_y;
314
struct grail_impl *impl = ge->impl;
315
struct input_event ev;
318
while ((ret = mtdev_get(impl->mtdev, fd, &ev, 1)) > 0) {
319
grail_pump_mtdev(ge, &ev);
323
return count > 0 ? count : ret;