From 7380af2c93dc83f4f09e293717d46eadf7799e89 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Mon, 21 Jun 2010 18:56:49 +0200 Subject: 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 --- driver/multitouch.c | 17 +++++++---------- include/hwstate.h | 4 ++-- include/mtouch.h | 3 ++- src/hwstate.c | 16 ++-------------- src/mtouch.c | 34 +++++++++++++++++++++++++++------- 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) { struct Gestures gs; struct MTouch *mt = local->private; - const struct input_event *ev; - while (ev = get_iobuf_event(&mt->buf, local->fd)) { - if (parse_event(mt, ev)) { - extract_gestures(&gs, mt); - handle_gestures(local, &gs, &mt->caps); - } - if (mt_is_idle(mt, local->fd)) { - extract_delayed_gestures(&gs, mt); - handle_gestures(local, &gs, &mt->caps); - } + while (read_packet(mt, local->fd) > 0) { + extract_gestures(&gs, mt); + handle_gestures(local, &gs, &mt->caps); + } + if (has_delayed_gestures(mt, local->fd)) { + extract_delayed_gestures(&gs, mt); + handle_gestures(local, &gs, &mt->caps); } } 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 { void init_hwstate(struct HWState *s, const struct Capabilities *caps); -int modify_hwstate(struct HWState *s, struct MTDev *dev, - const struct Capabilities *caps); +int hwstate_read(struct HWState *s, const struct Capabilities *caps, + const struct input_event *ev); void output_hwstate(const struct HWState *s); 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 { int configure_mtouch(struct MTouch *mt, int fd); int open_mtouch(struct MTouch *mt, int fd); +int get_mtouch(struct MTouch *mt, int fd, struct input_event* ev, int ev_max); int close_mtouch(struct MTouch *mt, int fd); int parse_event(struct MTouch *mt, const struct input_event *ev); -int mt_is_idle(struct MTouch *mt, int fd); +int has_delayed_gestures(struct MTouch *mt, int fd); static inline void mt_delay_movement(struct MTouch *mt, int t) { 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, s->evtime = syn->time.tv_usec / ms + syn->time.tv_sec * ms; } -static int read_event(struct HWState *s, const struct Capabilities *caps, - const struct input_event *ev) +int hwstate_read(struct HWState *s, const struct Capabilities *caps, + const struct input_event *ev) { switch (ev->type) { case EV_SYN: @@ -107,15 +107,3 @@ static int read_event(struct HWState *s, const struct Capabilities *caps, } return 0; } - -int modify_hwstate(struct HWState *s, struct MTDev *dev, - const struct Capabilities *caps) -{ - struct input_event ev; - while (!mtdev_empty(dev)) { - mtdev_get(dev, &ev); - if (read_event(s, caps, &ev)) - return 1; - } - return 0; -} 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) return 0; } + +int get_mtouch(struct MTouch *mt, int fd, struct input_event* ev, int ev_max) +{ + const struct input_event *kev; + int count = 0; + while (count < ev_max) { + while (mtdev_empty(&mt->dev)) { + kev = get_iobuf_event(&mt->buf, fd); + if (!kev) + return count; + mtdev_put(&mt->dev, &mt->caps, kev); + } + mtdev_get(&mt->dev, &ev[count++]); + } + return count; +} + int close_mtouch(struct MTouch *mt, int fd) { if (use_grab) { @@ -58,11 +75,15 @@ int close_mtouch(struct MTouch *mt, int fd) return 0; } -int parse_event(struct MTouch *mt, const struct input_event *ev) +int read_packet(struct MTouch *mt, int fd) { - mtdev_put(&mt->dev, &mt->caps, ev); - if (!modify_hwstate(&mt->hs, &mt->dev, &mt->caps)) - return 0; + struct input_event ev; + int ret; + while ((ret = get_mtouch(mt, fd, &ev, 1)) > 0) + if (hwstate_read(&mt->hs, &mt->caps, &ev)) + break; + if (ret <= 0) + return ret; extract_mtstate(&mt->state, &mt->hs, &mt->caps); #if 0 output_mtstate(&mt->state); @@ -74,10 +95,9 @@ int parse_event(struct MTouch *mt, const struct input_event *ev) return 1; } -int mt_is_idle(struct MTouch *mt, int fd) +int has_delayed_gestures(struct MTouch *mt, int fd) { return mt->mem.wait && - evbuf_empty(&mt->dev.outbuf) && - evbuf_empty(&mt->dev.inbuf) && + mtdev_empty(&mt->dev) && poll_iobuf(&mt->buf, fd, mt->mem.wait) == 0; } 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) { struct Gestures gs; struct MTouch mt; - const struct input_event *ev; - struct input_event event; if (configure_mtouch(&mt, fd)) { fprintf(stderr, "error: could not configure device\n"); return; @@ -37,12 +35,12 @@ static void loop_device(int fd) fprintf(stderr, "error: could not open device\n"); return; } - while (ev = get_iobuf_event(&mt.buf, fd)) { - if (parse_event(&mt, ev)) { + while (poll_iobuf(&mt.buf, fd, 5000)) { + while (read_packet(&mt, fd) > 0) { extract_gestures(&gs, &mt); output_gesture(&gs); } - if (mt_is_idle(&mt, fd)) { + if (has_delayed_gestures(&mt, fd)) { extract_delayed_gestures(&gs, &mt); output_gesture(&gs); } @@ -56,7 +54,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Usage: test \n"); return -1; } - int fd = open(argv[1], O_RDONLY); + int fd = open(argv[1], O_RDONLY | O_NONBLOCK); if (fd < 0) { fprintf(stderr, "error: could not open file\n"); return -1; -- cgit v1.2.3