From b76660d71e2ea77752025089bd71deffad64e325 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Mon, 26 Jul 2010 13:51:34 +0200 Subject: Test implementation of grail api This patch introduces the grail API, and a program to test it (evlink). Signed-off-by: Henrik Rydberg --- src/grail-api.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 src/grail-api.c (limited to 'src/grail-api.c') diff --git a/src/grail-api.c b/src/grail-api.c new file mode 100644 index 0000000..dbe4977 --- /dev/null +++ b/src/grail-api.c @@ -0,0 +1,151 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +struct grail_impl { + struct touch_dev dev; + struct touch_engine engine; + struct touch_frame frame; + struct gesture_dev gedev; + struct gesture_client client; + touch_time_t last_scroll; +}; + +static void gh_handle(struct grail_impl *gh, + const struct touch_frame *frame, + touch_time_t time) +{ +#if 0 + struct gesture_flag flag; + struct grail_event ev; + if (frame->ntouch == 1 || frame->ntouch == 2) { + flag.type = GE_MOVE; + flag.time = time; + flag.state = GS_BEGIN; + gedev_flag(&gh->dev, &flag); + + ev.type = GE_MOVE; + ev.time = time; + ev.prop[0] = + frame->touch[0].prop[TP_POS_X] - + gh->frame.touch[0].prop[TP_POS_X]; + ev.prop[1] = + frame->touch[0].prop[TP_POS_Y] - + gh->frame.touch[0].prop[TP_POS_Y]; + if (ev.prop[0] || ev.prop[1]) + gedev_event(&gh->dev, &ev); + + flag.time = time + 1; + flag.state = GS_END; + gedev_flag(&gh->dev, &flag); + } + if (frame->ntouch == 2) { + flag.type = GE_VSCROLL; + flag.time = time; + flag.state = GS_BEGIN; + gedev_flag(&gh->dev, &flag); + + ev.type = GE_VSCROLL; + ev.time = time; + ev.prop[0] = + frame->touch[0].prop[TP_POS_Y] - + gh->frame.touch[0].prop[TP_POS_Y]; + + if (ev.prop[0]) + gedev_event(&gh->dev, &ev); + + if (time > gh->last_scroll + 100) { + flag.time = time + 1; + flag.state = GS_END; + gedev_flag(&gh->dev, &flag); + gh->last_scroll = time; + } + } else { + flag.type = GE_VSCROLL; + flag.time = time; + flag.state = GS_CANCEL; + gedev_flag(&gh->dev, &flag); + } + gedev_sync(&gh->dev); + gh->frame = *frame; +#endif +} + +static void tp_event(struct touch_engine *engine, + const struct input_event *ev) +{ + struct grail *ge = engine->priv; + if (ge->event) + ge->event(ge, ev); +} + +static void tp_sync(struct touch_engine *engine, + const struct input_event *syn) +{ + struct grail *ge = engine->priv; +#if 0 + struct touch_frame *frame = &engine->frame; + gh_handle(ge, frame, frame->time); +#endif + if (ge->event) + ge->event(ge, syn); +} + +int grail_open(struct grail *ge, int fd) +{ + struct grail_impl *x; + int ret; + x = calloc(1, sizeof(*x)); + if (!x) + return -ENOMEM; + ret = touch_dev_open(&x->dev, fd); + if (ret) + goto error; + touch_engine_init(&x->engine, tp_event, tp_sync, ge); + touch_engine_attach(&x->engine, &x->dev); + ge->impl = x; + return 0; + error: + free(x); + return ret; +} + +int grail_idle(struct grail *ge, int fd, int ms) +{ + struct grail_impl *x = ge->impl; + return touch_dev_idle(&x->dev, fd, ms); +} + +int grail_pull(struct grail *ge, int fd) +{ + struct grail_impl *x = ge->impl; + return touch_dev_pull(&x->dev, fd); +} + +void grail_close(struct grail *ge, int fd) +{ + struct grail_impl *x = ge->impl; + touch_engine_detach(&x->engine, &x->dev); + touch_dev_close(&x->dev, fd); + free(ge->impl); + ge->impl = 0; +} + +void grail_add_client(struct grail *ge, grail_clientid_t id, + const int *types, const int *priority, int ntypes) +{ + struct grail_impl *x = ge->impl; + //gedev_attach_client(&x->dev, &x->client); +} + +void grail_remove_client(struct grail *ge, grail_clientid_t id) +{ + struct grail_impl *x = ge->impl; + //gedev_detach_client(&x->dev, &x->client); +} + -- cgit v1.2.3