From cc2d67d0f9c6381080de1d666bccfb4b99221113 Mon Sep 17 00:00:00 2001 From: Chase Douglas Date: Mon, 14 Feb 2011 16:33:32 +0100 Subject: Remove pointer emulation With the assumption that X will be handle to handle the gesture cases correctly, remove the pointer emulation Signed-off-by: Chase Douglas Signed-off-by: Henrik Rydberg --- src/grail-api.c | 165 ++++++-------------------------------------------------- 1 file changed, 15 insertions(+), 150 deletions(-) (limited to 'src/grail-api.c') diff --git a/src/grail-api.c b/src/grail-api.c index a584e23..22724ee 100644 --- a/src/grail-api.c +++ b/src/grail-api.c @@ -40,22 +40,6 @@ void grail_filter_abs_events(struct grail *ge, int usage) x->filter_abs = usage; } -static void init_impl(struct grail_impl *x) -{ - if (evemu_has_event(x->evemu, EV_ABS, ABS_X)) { - x->emin_x = evemu_get_abs_minimum(x->evemu, ABS_X); - x->emin_y = evemu_get_abs_minimum(x->evemu, ABS_Y); - x->emax_x = evemu_get_abs_maximum(x->evemu, ABS_X); - x->emax_y = evemu_get_abs_maximum(x->evemu, ABS_Y); - } else { - struct utouch_surface *s = utouch_frame_get_surface(x->fh); - x->emin_x = s->min_x; - x->emin_y = s->min_y; - x->emax_x = s->max_x; - x->emax_y = s->max_y; - } -} - int grail_open(struct grail *ge, int fd) { struct grail_impl *x; @@ -91,7 +75,6 @@ int grail_open(struct grail *ge, int fd) if (ret) goto freeframe; - init_impl(x); ge->impl = x; ret = gin_init(ge); @@ -144,117 +127,12 @@ void grail_get_units(const struct grail *ge, max->y = s->max_y; } -// legacy glue below - -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 report_down(struct grail_impl *impl) -{ - if (impl->report_status) - return; - evput(impl, impl->report_time, EV_KEY, BTN_TOUCH, 1); - evput(impl, impl->report_time, EV_ABS, ABS_X, impl->report_x); - evput(impl, impl->report_time, EV_ABS, ABS_Y, impl->report_y); - impl->report_status = 1; -} - -static void report_up(struct grail_impl *impl, const struct input_event *syn) -{ - if (!impl->report_status) - return; - evput(impl, syn->time, EV_KEY, BTN_TOUCH, 0); - impl->report_status = 0; -} - -static void set_pointer(struct grail_impl *impl) -{ - struct utouch_surface *s = utouch_frame_get_surface(impl->fh); - const struct utouch_frame *frame = impl->frame; - int best_x, best_y, best_d = -1; - int i; - - for (i = 0; i < frame->num_active; i++) { - const struct utouch_contact *t = frame->active[i]; - float u = (t->x - s->min_x) / (s->max_x - s->min_x); - float v = (t->y - s->min_y) / (s->max_y - s->min_y); - int x = impl->emin_x + u * (impl->emax_x - impl->emin_x); - int y = impl->emin_y + v * (impl->emax_y - impl->emin_y); - int d = abs(x - impl->pointer_x) + abs(y - impl->pointer_y); - if (best_d < 0 || d < best_d) { - best_x = x; - best_y = y; - best_d = d; - } - } - if (best_d >= 0) { - impl->pointer_x = best_x; - impl->pointer_y = best_y; - } -} - -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 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 used_tap = grail_mask_get(gin->types, GRAIL_TYPE_TAP1); - int pointer = move->ntouch == 1; - int ismove = pointer && (move->active & fm_mask) && !used_move; - int ishold = pointer && tap->active && !used_move; - int istap = gru->tapping.tap == 1 && !used_tap; - - set_pointer(impl); - if (!impl->pointer_status && pointer) { - impl->report_x = impl->pointer_x; - impl->report_y = impl->pointer_y; - impl->report_time = syn->time; - impl->pointer_status = 1; - if (!used_move) - report_down(impl); - return; - } - - if (ishold) - return; - - if (istap) { - report_down(impl); - evput(impl, impl->report_time, EV_KEY, BTN_LEFT, 1); - evput(impl, impl->report_time, EV_SYN, SYN_REPORT, 0); - evput(impl, syn->time, EV_KEY, BTN_LEFT, 0); - } else if (ismove) { - report_down(impl); - if (impl->report_x != impl->pointer_x) { - evput(impl, syn->time, EV_ABS, ABS_X, impl->pointer_x); - impl->report_x = impl->pointer_x; - } - if (impl->report_y != impl->pointer_y) { - evput(impl, syn->time, EV_ABS, ABS_Y, impl->pointer_y); - impl->report_y = impl->pointer_y; - } - } - if (impl->pointer_status && !pointer) { - impl->pointer_status = 0; - report_up(impl, syn); - } -} - static void report_frame(struct grail *ge, const struct utouch_frame *frame, const struct input_event *syn) { struct grail_impl *impl = ge->impl; - int head = impl->evbuf.head; struct input_event iev; struct grail_event gev; @@ -264,20 +142,19 @@ static void report_frame(struct grail *ge, gru_recognize(ge, frame); gin_frame_end(ge, frame); - if (!impl->filter_abs) - handle_abs_events(ge, syn); - if (impl->evbuf.head != head) - evbuf_put(&impl->evbuf, syn); - - while (!grailbuf_empty(&impl->gbuf)) { - grailbuf_get(&impl->gbuf, &gev); - if (ge->gesture) - ge->gesture(ge, &gev); - } - while (!evbuf_empty(&impl->evbuf)) { - evbuf_get(&impl->evbuf, &iev); - if (ge->event) - ge->event(ge, &iev); + if (grailbuf_empty(&impl->gbuf)) { + while (!evbuf_empty(&impl->evbuf)) { + evbuf_get(&impl->evbuf, &iev); + if (ge->event) + ge->event(ge, &iev); + } + } else { + while (!grailbuf_empty(&impl->gbuf)) { + grailbuf_get(&impl->gbuf, &gev); + if (ge->gesture) + ge->gesture(ge, &gev); + } + evbuf_clear(&impl->evbuf); } } @@ -286,24 +163,12 @@ static void grail_pump_mtdev(struct grail *ge, const struct input_event *ev) struct grail_impl *impl = ge->impl; const struct utouch_frame *frame; + evbuf_put(&impl->evbuf, ev); + if (ev->type == EV_SYN || ev->type == EV_ABS) { frame = utouch_frame_pump_mtdev(impl->fh, ev); if (frame) report_frame(ge, frame, ev); - } else if (ev->type == EV_KEY) { - switch (ev->code) { - case BTN_TOUCH: - case BTN_TOOL_FINGER: - case BTN_TOOL_DOUBLETAP: - case BTN_TOOL_TRIPLETAP: - case BTN_TOOL_QUADTAP: - break; - default: - evbuf_put(&impl->evbuf, ev); - break; - } - } else { - evbuf_put(&impl->evbuf, ev); } } -- cgit v1.2.3