diff options
| -rw-r--r-- | driver/multitouch.c | 17 | ||||
| -rw-r--r-- | include/hwstate.h | 4 | ||||
| -rw-r--r-- | include/mtouch.h | 3 | ||||
| -rw-r--r-- | src/hwstate.c | 16 | ||||
| -rw-r--r-- | src/mtouch.c | 34 | ||||
| -rw-r--r-- | src/test.c | 10 |
6 files changed, 44 insertions, 40 deletions
diff --git a/driver/multitouch.c b/driver/multitouch.c index 73a025d..eef86c5 100644 --- a/driver/multitouch.c +++ b/driver/multitouch.c | |||
| @@ -256,16 +256,13 @@ static void read_input(LocalDevicePtr local) | |||
| 256 | { | 256 | { |
| 257 | struct Gestures gs; | 257 | struct Gestures gs; |
| 258 | struct MTouch *mt = local->private; | 258 | struct MTouch *mt = local->private; |
| 259 | const struct input_event *ev; | 259 | while (read_packet(mt, local->fd) > 0) { |
| 260 | while (ev = get_iobuf_event(&mt->buf, local->fd)) { | 260 | extract_gestures(&gs, mt); |
| 261 | if (parse_event(mt, ev)) { | 261 | handle_gestures(local, &gs, &mt->caps); |
| 262 | extract_gestures(&gs, mt); | 262 | } |
| 263 | handle_gestures(local, &gs, &mt->caps); | 263 | if (has_delayed_gestures(mt, local->fd)) { |
| 264 | } | 264 | extract_delayed_gestures(&gs, mt); |
| 265 | if (mt_is_idle(mt, local->fd)) { | 265 | handle_gestures(local, &gs, &mt->caps); |
| 266 | extract_delayed_gestures(&gs, mt); | ||
| 267 | handle_gestures(local, &gs, &mt->caps); | ||
| 268 | } | ||
| 269 | } | 266 | } |
| 270 | } | 267 | } |
| 271 | 268 | ||
diff --git a/include/hwstate.h b/include/hwstate.h index 4243292..efd291f 100644 --- a/include/hwstate.h +++ b/include/hwstate.h | |||
| @@ -42,8 +42,8 @@ struct HWState { | |||
| 42 | 42 | ||
| 43 | void init_hwstate(struct HWState *s, | 43 | void init_hwstate(struct HWState *s, |
| 44 | const struct Capabilities *caps); | 44 | const struct Capabilities *caps); |
| 45 | int modify_hwstate(struct HWState *s, struct MTDev *dev, | 45 | int hwstate_read(struct HWState *s, const struct Capabilities *caps, |
| 46 | const struct Capabilities *caps); | 46 | const struct input_event *ev); |
| 47 | void output_hwstate(const struct HWState *s); | 47 | void output_hwstate(const struct HWState *s); |
| 48 | 48 | ||
| 49 | static inline int finger_dist2(const struct FingerState *a, | 49 | static inline int finger_dist2(const struct FingerState *a, |
diff --git a/include/mtouch.h b/include/mtouch.h index c73eb29..482d010 100644 --- a/include/mtouch.h +++ b/include/mtouch.h | |||
| @@ -36,11 +36,12 @@ struct MTouch { | |||
| 36 | 36 | ||
| 37 | int configure_mtouch(struct MTouch *mt, int fd); | 37 | int configure_mtouch(struct MTouch *mt, int fd); |
| 38 | int open_mtouch(struct MTouch *mt, int fd); | 38 | int open_mtouch(struct MTouch *mt, int fd); |
| 39 | int get_mtouch(struct MTouch *mt, int fd, struct input_event* ev, int ev_max); | ||
| 39 | int close_mtouch(struct MTouch *mt, int fd); | 40 | int close_mtouch(struct MTouch *mt, int fd); |
| 40 | 41 | ||
| 41 | int parse_event(struct MTouch *mt, const struct input_event *ev); | 42 | int parse_event(struct MTouch *mt, const struct input_event *ev); |
| 42 | 43 | ||
| 43 | int mt_is_idle(struct MTouch *mt, int fd); | 44 | int has_delayed_gestures(struct MTouch *mt, int fd); |
| 44 | 45 | ||
| 45 | static inline void mt_delay_movement(struct MTouch *mt, int t) | 46 | static inline void mt_delay_movement(struct MTouch *mt, int t) |
| 46 | { | 47 | { |
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 | ||
| 46 | static int read_event(struct HWState *s, const struct Capabilities *caps, | 46 | int 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 | |||
| 111 | int 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 | |||
| 52 | int 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 | |||
| 51 | int close_mtouch(struct MTouch *mt, int fd) | 68 | int 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 | ||
| 61 | int parse_event(struct MTouch *mt, const struct input_event *ev) | 78 | int 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 | ||
| 77 | int mt_is_idle(struct MTouch *mt, int fd) | 98 | int 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 | } |
| @@ -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; |
