From 8bbf06f8d0056ae30fdfaf260000e763fad2345c Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Thu, 5 Aug 2010 15:26:16 +0200 Subject: make event units public in the api Add grail_get_units() to the api, so so that applications can extract the min/max coordinates used in the gesture events. Signed-off-by: Henrik Rydberg --- include/grail.h | 3 +++ src/grail-api.c | 15 +++++++++++++-- src/grail-gestures.c | 8 +++++--- src/grail-gestures.h | 3 +-- src/grail-recognizer.c | 4 ++-- src/grail-recognizer.h | 2 +- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/include/grail.h b/include/grail.h index a100b36..0fa4473 100644 --- a/include/grail.h +++ b/include/grail.h @@ -88,4 +88,7 @@ int grail_idle(struct grail *ge, int fd, int ms); int grail_pull(struct grail *ge, int fd); void grail_close(struct grail *ge, int fd); +void grail_get_units(struct grail_coord *min, struct grail_coord *max, + const struct grail *ge); + #endif diff --git a/src/grail-api.c b/src/grail-api.c index c4a88df..2c6c438 100644 --- a/src/grail-api.c +++ b/src/grail-api.c @@ -95,13 +95,14 @@ int grail_open(struct grail *ge, int fd) x = calloc(1, sizeof(*x)); if (!x) return -ENOMEM; + ge->impl = x; ret = gin_init(ge); if (ret) goto freemem; ret = touch_dev_open(&x->dev, fd); if (ret) goto freegin; - ret = gru_init(ge, &x->dev.caps); + ret = gru_init(ge); if (ret) goto freedev; x->fd = fd; @@ -110,7 +111,6 @@ int grail_open(struct grail *ge, int fd) ret = pthread_create(&x->thread, NULL, grail_thread, x); if (ret) goto freegru; - ge->impl = x; touch_engine_init(&x->engine, tp_event, tp_sync, ge); touch_engine_attach(&x->engine, &x->dev); return 0; @@ -122,6 +122,7 @@ int grail_open(struct grail *ge, int fd) gin_destroy(ge); freemem: free(x); + ge->impl = 0; return ret; } @@ -168,3 +169,13 @@ int grail_pull(struct grail *ge, int fd) pthread_mutex_unlock(&x->mutex); return 1; } + +void grail_get_units(struct grail_coord *min, struct grail_coord *max, + const struct grail *ge) +{ + const struct touch_dev_caps *caps = &ge->impl->dev.caps; + min->x = caps->info[TP_POS_X].minimum; + min->y = caps->info[TP_POS_Y].minimum; + max->x = caps->info[TP_POS_X].maximum; + max->y = caps->info[TP_POS_Y].maximum; +} diff --git a/src/grail-gestures.c b/src/grail-gestures.c index 5ab12a8..e1bf622 100644 --- a/src/grail-gestures.c +++ b/src/grail-gestures.c @@ -119,12 +119,14 @@ static int move_update(struct filter_model *m, float val) return m->active; } -void gru_init_motion(struct grail *ge, const struct touch_dev_caps *caps) +void gru_init_motion(struct grail *ge) { struct gesture_recognizer *gru = ge->gru; struct move_model *state = &gru->move; - float x = caps->info[TP_POS_X].maximum - caps->info[TP_POS_X].minimum; - float y = caps->info[TP_POS_Y].maximum - caps->info[TP_POS_Y].minimum; + struct grail_coord min, max; + grail_get_units(&min, &max, ge); + float x = max.x - min.x; + float y = max.y - min.y; float r = sqrt(x * x + y * y); state->x.fuzz = x / SN_MOVE; state->y.fuzz = y / SN_MOVE; diff --git a/src/grail-gestures.h b/src/grail-gestures.h index 57204ad..663d357 100644 --- a/src/grail-gestures.h +++ b/src/grail-gestures.h @@ -43,8 +43,7 @@ struct move_model { grail_time_t time; }; -void gru_init_motion(struct grail *ge, - const struct touch_dev_caps *caps); +void gru_init_motion(struct grail *ge); void gru_motion(struct grail *ge, const struct touch_frame *frame); void gru_event(struct grail *ge, int gid, diff --git a/src/grail-recognizer.c b/src/grail-recognizer.c index bed704e..587a12a 100644 --- a/src/grail-recognizer.c +++ b/src/grail-recognizer.c @@ -27,14 +27,14 @@ #include #include -int gru_init(struct grail *ge, const struct touch_dev_caps *caps) +int gru_init(struct grail *ge) { struct gesture_recognizer *gru; gru = calloc(1, sizeof(struct gesture_recognizer)); if (!gru) return -ENOMEM; ge->gru = gru; - gru_init_motion(ge, caps); + gru_init_motion(ge); return 0; } diff --git a/src/grail-recognizer.h b/src/grail-recognizer.h index d3b24b3..8a5ac80 100644 --- a/src/grail-recognizer.h +++ b/src/grail-recognizer.h @@ -37,7 +37,7 @@ struct gesture_recognizer { struct tapping_model tapping; }; -int gru_init(struct grail *ge, const struct touch_dev_caps *caps); +int gru_init(struct grail *ge); void gru_recognize(struct grail *ge, const struct touch_frame *frame); void gru_destroy(struct grail *ge); -- cgit v1.2.3