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
|
#include <grail-gesture.h>
#include <grail.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <malloc.h>
#include <errno.h>
struct grail_impl {
struct touch_dev dev;
struct touch_engine engine;
struct touch_frame frame;
struct gesture_dev gedev;
struct gesture_client client;
touch_time_t last_scroll;
};
static void gh_handle(struct grail_impl *gh,
const struct touch_frame *frame,
touch_time_t time)
{
#if 0
struct gesture_flag flag;
struct grail_event ev;
if (frame->ntouch == 1 || frame->ntouch == 2) {
flag.type = GE_MOVE;
flag.time = time;
flag.state = GS_BEGIN;
gedev_flag(&gh->dev, &flag);
ev.type = GE_MOVE;
ev.time = time;
ev.prop[0] =
frame->touch[0].prop[TP_POS_X] -
gh->frame.touch[0].prop[TP_POS_X];
ev.prop[1] =
frame->touch[0].prop[TP_POS_Y] -
gh->frame.touch[0].prop[TP_POS_Y];
if (ev.prop[0] || ev.prop[1])
gedev_event(&gh->dev, &ev);
flag.time = time + 1;
flag.state = GS_END;
gedev_flag(&gh->dev, &flag);
}
if (frame->ntouch == 2) {
flag.type = GE_VSCROLL;
flag.time = time;
flag.state = GS_BEGIN;
gedev_flag(&gh->dev, &flag);
ev.type = GE_VSCROLL;
ev.time = time;
ev.prop[0] =
frame->touch[0].prop[TP_POS_Y] -
gh->frame.touch[0].prop[TP_POS_Y];
if (ev.prop[0])
gedev_event(&gh->dev, &ev);
if (time > gh->last_scroll + 100) {
flag.time = time + 1;
flag.state = GS_END;
gedev_flag(&gh->dev, &flag);
gh->last_scroll = time;
}
} else {
flag.type = GE_VSCROLL;
flag.time = time;
flag.state = GS_CANCEL;
gedev_flag(&gh->dev, &flag);
}
gedev_sync(&gh->dev);
gh->frame = *frame;
#endif
}
static void tp_event(struct touch_engine *engine,
const struct input_event *ev)
{
struct grail *ge = engine->priv;
if (ge->event)
ge->event(ge, ev);
}
static void tp_sync(struct touch_engine *engine,
const struct input_event *syn)
{
struct grail *ge = engine->priv;
#if 0
struct touch_frame *frame = &engine->frame;
gh_handle(ge, frame, frame->time);
#endif
if (ge->event)
ge->event(ge, syn);
}
int grail_open(struct grail *ge, int fd)
{
struct grail_impl *x;
int ret;
x = calloc(1, sizeof(*x));
if (!x)
return -ENOMEM;
ret = touch_dev_open(&x->dev, fd);
if (ret)
goto error;
touch_engine_init(&x->engine, tp_event, tp_sync, ge);
touch_engine_attach(&x->engine, &x->dev);
ge->impl = x;
return 0;
error:
free(x);
return ret;
}
int grail_idle(struct grail *ge, int fd, int ms)
{
struct grail_impl *x = ge->impl;
return touch_dev_idle(&x->dev, fd, ms);
}
int grail_pull(struct grail *ge, int fd)
{
struct grail_impl *x = ge->impl;
return touch_dev_pull(&x->dev, fd);
}
void grail_close(struct grail *ge, int fd)
{
struct grail_impl *x = ge->impl;
touch_engine_detach(&x->engine, &x->dev);
touch_dev_close(&x->dev, fd);
free(ge->impl);
ge->impl = 0;
}
void grail_add_client(struct grail *ge, grail_clientid_t id,
const int *types, const int *priority, int ntypes)
{
struct grail_impl *x = ge->impl;
//gedev_attach_client(&x->dev, &x->client);
}
void grail_remove_client(struct grail *ge, grail_clientid_t id)
{
struct grail_impl *x = ge->impl;
//gedev_detach_client(&x->dev, &x->client);
}
|