From cd1812c4d8bca7ffc0c27fc16561c40a935ab6c2 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Tue, 21 Sep 2010 11:00:11 +0200 Subject: Reorganize input event emulation code Inject the emulated events into the event buffer instead, and move the pointer logic into the emulation handler. Introduces no logical changes, but reveals the bug in the position event frequency. Signed-off-by: Henrik Rydberg --- src/grail-api.c | 57 +++++++++++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/grail-api.c b/src/grail-api.c index 9503889..9490659 100644 --- a/src/grail-api.c +++ b/src/grail-api.c @@ -55,42 +55,34 @@ static void tp_event(struct touch_dev *dev, evbuf_put(&x->evbuf, ev); } -static int handle_abs_events(struct grail *ge, - const struct input_event *syn, - int pointer) +static void evput(struct grail_impl *x, struct timeval time, + unsigned type, unsigned code, int value) { + struct input_event ev = { time, type, code, value }; + evbuf_put(&x->evbuf, &ev); +} + +static void handle_abs_events(struct grail *ge, const struct input_event *syn) +{ + static const int fm_mask = 0x03; struct grail_impl *impl = ge->impl; - struct input_event ev = *syn; - int nevent = 0; + struct gesture_inserter *gin = ge->gin; + struct gesture_recognizer *gru = ge->gru; + struct move_model *move = &gru->move; + struct tapping_model *tap = &gru->tapping; + int used_move = grail_mask_count(gin->types, sizeof(gin->types)); + int ismove = move->single && (move->active & fm_mask) && !used_move; + int ishold = move->single && tap->active && !used_move; + int pointer = ismove || ishold; + if (pointer != impl->pointer_status) { - ev.type = EV_KEY; - ev.code = BTN_TOUCH; - ev.value = pointer; - ge->event(ge, &ev); + evput(impl, syn->time, EV_KEY, BTN_TOUCH, pointer); impl->pointer_status = pointer; - nevent++; } if (pointer) { - ev.type = EV_ABS; - ev.code = ABS_X; - ev.value = impl->pointer_x; - ge->event(ge, &ev); - nevent++; - ev.type = EV_ABS; - ev.code = ABS_Y; - ev.value = impl->pointer_y; - ge->event(ge, &ev); - nevent++; + evput(impl, syn->time, EV_ABS, ABS_X, impl->pointer_x); + evput(impl, syn->time, EV_ABS, ABS_Y, impl->pointer_y); } - return nevent; -} - -static int pointer_active(const struct grail *ge) -{ - static const int fm_mask = 0x03; - const struct move_model *move = &ge->gru->move; - const struct tapping_model *tap = &ge->gru->tapping; - return move->single && ((move->active & fm_mask) || tap->active); } static void tp_sync(struct touch_dev *dev, @@ -99,21 +91,18 @@ static void tp_sync(struct touch_dev *dev, struct input_event ev; struct grail *ge = dev->priv; struct grail_impl *impl = ge->impl; - struct gesture_inserter *gin = ge->gin; struct touch_frame *frame = &dev->frame; - int pointer, used_move, nevent = 0; + int nevent = 0; gin_frame_begin(ge, frame); gru_recognize(ge, frame); gin_frame_end(ge, frame); - used_move = grail_mask_count(gin->types, sizeof(gin->types)); - pointer = pointer_active(ge) && !used_move; if (!ge->event) { evbuf_clear(&impl->evbuf); return; } if (!impl->filter_abs) - nevent += handle_abs_events(ge, syn, pointer); + handle_abs_events(ge, syn); while (!evbuf_empty(&impl->evbuf)) { evbuf_get(&impl->evbuf, &ev); ge->event(ge, &ev); -- cgit v1.2.3