summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-06-21 18:56:49 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-06-21 18:56:49 +0200
commit7380af2c93dc83f4f09e293717d46eadf7799e89 (patch)
tree2eb11199ef87e3181411bb848252bb5d6fed0be6 /src
parent71168e1fb794f4a24e97177508bb1d54ae24b266 (diff)
Simplify event reading
This patch puts the reading code more in line with the upcoming mtdev library, and should remove some spurious input behavior. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src')
-rw-r--r--src/hwstate.c16
-rw-r--r--src/mtouch.c34
-rw-r--r--src/test.c10
3 files changed, 33 insertions, 27 deletions
diff --git a/src/hwstate.c b/src/hwstate.c
index b29ee54..82a3a10 100644
--- a/src/hwstate.c
+++ b/src/hwstate.c
@@ -43,8 +43,8 @@ static void finish_packet(struct HWState *s, const struct Capabilities *caps,
43 s->evtime = syn->time.tv_usec / ms + syn->time.tv_sec * ms; 43 s->evtime = syn->time.tv_usec / ms + syn->time.tv_sec * ms;
44} 44}
45 45
46static int read_event(struct HWState *s, const struct Capabilities *caps, 46int hwstate_read(struct HWState *s, const struct Capabilities *caps,
47 const struct input_event *ev) 47 const struct input_event *ev)
48{ 48{
49 switch (ev->type) { 49 switch (ev->type) {
50 case EV_SYN: 50 case EV_SYN:
@@ -107,15 +107,3 @@ static int read_event(struct HWState *s, const struct Capabilities *caps,
107 } 107 }
108 return 0; 108 return 0;
109} 109}
110
111int modify_hwstate(struct HWState *s, struct MTDev *dev,
112 const struct Capabilities *caps)
113{
114 struct input_event ev;
115 while (!mtdev_empty(dev)) {
116 mtdev_get(dev, &ev);
117 if (read_event(s, caps, &ev))
118 return 1;
119 }
120 return 0;
121}
diff --git a/src/mtouch.c b/src/mtouch.c
index 14c0fd9..f7a2710 100644
--- a/src/mtouch.c
+++ b/src/mtouch.c
@@ -48,6 +48,23 @@ int open_mtouch(struct MTouch *mt, int fd)
48 return 0; 48 return 0;
49} 49}
50 50
51
52int get_mtouch(struct MTouch *mt, int fd, struct input_event* ev, int ev_max)
53{
54 const struct input_event *kev;
55 int count = 0;
56 while (count < ev_max) {
57 while (mtdev_empty(&mt->dev)) {
58 kev = get_iobuf_event(&mt->buf, fd);
59 if (!kev)
60 return count;
61 mtdev_put(&mt->dev, &mt->caps, kev);
62 }
63 mtdev_get(&mt->dev, &ev[count++]);
64 }
65 return count;
66}
67
51int close_mtouch(struct MTouch *mt, int fd) 68int close_mtouch(struct MTouch *mt, int fd)
52{ 69{
53 if (use_grab) { 70 if (use_grab) {
@@ -58,11 +75,15 @@ int close_mtouch(struct MTouch *mt, int fd)
58 return 0; 75 return 0;
59} 76}
60 77
61int parse_event(struct MTouch *mt, const struct input_event *ev) 78int read_packet(struct MTouch *mt, int fd)
62{ 79{
63 mtdev_put(&mt->dev, &mt->caps, ev); 80 struct input_event ev;
64 if (!modify_hwstate(&mt->hs, &mt->dev, &mt->caps)) 81 int ret;
65 return 0; 82 while ((ret = get_mtouch(mt, fd, &ev, 1)) > 0)
83 if (hwstate_read(&mt->hs, &mt->caps, &ev))
84 break;
85 if (ret <= 0)
86 return ret;
66 extract_mtstate(&mt->state, &mt->hs, &mt->caps); 87 extract_mtstate(&mt->state, &mt->hs, &mt->caps);
67#if 0 88#if 0
68 output_mtstate(&mt->state); 89 output_mtstate(&mt->state);
@@ -74,10 +95,9 @@ int parse_event(struct MTouch *mt, const struct input_event *ev)
74 return 1; 95 return 1;
75} 96}
76 97
77int mt_is_idle(struct MTouch *mt, int fd) 98int has_delayed_gestures(struct MTouch *mt, int fd)
78{ 99{
79 return mt->mem.wait && 100 return mt->mem.wait &&
80 evbuf_empty(&mt->dev.outbuf) && 101 mtdev_empty(&mt->dev) &&
81 evbuf_empty(&mt->dev.inbuf) &&
82 poll_iobuf(&mt->buf, fd, mt->mem.wait) == 0; 102 poll_iobuf(&mt->buf, fd, mt->mem.wait) == 0;
83} 103}
diff --git a/src/test.c b/src/test.c
index ce2fdf5..e4247d2 100644
--- a/src/test.c
+++ b/src/test.c
@@ -27,8 +27,6 @@ static void loop_device(int fd)
27{ 27{
28 struct Gestures gs; 28 struct Gestures gs;
29 struct MTouch mt; 29 struct MTouch mt;
30 const struct input_event *ev;
31 struct input_event event;
32 if (configure_mtouch(&mt, fd)) { 30 if (configure_mtouch(&mt, fd)) {
33 fprintf(stderr, "error: could not configure device\n"); 31 fprintf(stderr, "error: could not configure device\n");
34 return; 32 return;
@@ -37,12 +35,12 @@ static void loop_device(int fd)
37 fprintf(stderr, "error: could not open device\n"); 35 fprintf(stderr, "error: could not open device\n");
38 return; 36 return;
39 } 37 }
40 while (ev = get_iobuf_event(&mt.buf, fd)) { 38 while (poll_iobuf(&mt.buf, fd, 5000)) {
41 if (parse_event(&mt, ev)) { 39 while (read_packet(&mt, fd) > 0) {
42 extract_gestures(&gs, &mt); 40 extract_gestures(&gs, &mt);
43 output_gesture(&gs); 41 output_gesture(&gs);
44 } 42 }
45 if (mt_is_idle(&mt, fd)) { 43 if (has_delayed_gestures(&mt, fd)) {
46 extract_delayed_gestures(&gs, &mt); 44 extract_delayed_gestures(&gs, &mt);
47 output_gesture(&gs); 45 output_gesture(&gs);
48 } 46 }
@@ -56,7 +54,7 @@ int main(int argc, char *argv[])
56 fprintf(stderr, "Usage: test <mtdev>\n"); 54 fprintf(stderr, "Usage: test <mtdev>\n");
57 return -1; 55 return -1;
58 } 56 }
59 int fd = open(argv[1], O_RDONLY); 57 int fd = open(argv[1], O_RDONLY | O_NONBLOCK);
60 if (fd < 0) { 58 if (fd < 0) {
61 fprintf(stderr, "error: could not open file\n"); 59 fprintf(stderr, "error: could not open file\n");
62 return -1; 60 return -1;