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,
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 <mtdev>\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;