From b605a93a85d8ead753d87a2da5a0e40571d6f275 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Thu, 28 Apr 2011 15:41:49 +0200 Subject: Expose utouch-frame through grail API Start a gentle API change by exposing utouch-frame through grail, and deprecating the grail_contact struct. Old programs compile and run fine. To only use the new api, compile with -DGRAIL_NO_LEGACY_API. Signed-off-by: Henrik Rydberg --- configure.ac | 2 +- include/grail.h | 94 ++++++++++++++++++++++++++++-------------------------- src/Makefile.am | 3 +- src/grail-api.c | 13 +++++--- src/grail-event.c | 25 --------------- src/grail-legacy.c | 66 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 126 insertions(+), 77 deletions(-) create mode 100644 src/grail-legacy.c diff --git a/configure.ac b/configure.ac index f40631d..99569cc 100644 --- a/configure.ac +++ b/configure.ac @@ -12,7 +12,7 @@ AC_CONFIG_AUX_DIR([config-aux]) AM_INIT_AUTOMAKE([foreign dist-bzip2]) AM_MAINTAINER_MODE -LIB_VERSION=1:0:0 +LIB_VERSION=2:0:1 AC_SUBST([LIB_VERSION]) # Initialize libtool diff --git a/include/grail.h b/include/grail.h index d21d9e8..b208556 100644 --- a/include/grail.h +++ b/include/grail.h @@ -26,11 +26,14 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { #endif +#define GRAIL_VERSION 0x00011000 + #define DIM_GRAIL_TYPE 64 #define DIM_GRAIL_TYPE_BYTES ((DIM_GRAIL_TYPE + 7) >> 3) @@ -41,8 +44,21 @@ extern "C" { #define GRAIL_STATUS_UPDATE 1 #define GRAIL_STATUS_END 2 -typedef float grail_prop_t; /* gesture properties */ -typedef __u64 grail_time_t; /* time in milliseconds */ +typedef float grail_prop_t; /* gesture properties */ +typedef utouch_frame_time_t grail_time_t; /* time in milliseconds */ + +/** + * struct grail_get_version - get grail library version + * + * Report the version of the grail library, which can be different from + * the value of GRAIL_VERSION in this header file. + * + * This function allows for fallback options from major interface + * extensions within the same ABI version. For the normal cases of ABI + * agnostic or backwards incompatible changes, this function is not + * needed. + */ +unsigned int GRAIL_PUBLIC grail_get_version(void); /** * struct grail_coord - coordinate in bounding box units @@ -53,33 +69,6 @@ struct grail_coord { float x, y; }; -/** - * struct grail_contact - MT event information in bounding box units - * @id: Contact tracking id - * @tool_type: Tool type (ABS_MT_TOOL_TYPE) - * @pos: Position of contact (bbox units) - * @touch_major: Major axis of contact shape (bbox units) - * @touch_minor: Minor axis of contact shape (bbox units) - * @width_major: Major axis of perimeter (bbox units) - * @width_minor: Minor axis of perimeter (bbox units) - * @angle: Angle of orientation (vertical: 0 horizontal: +-M_PI_2) - * @pressure: Pressure of contact (min: 0 max: 1) - * - * Depending on the native support of the underlying device, some or all of - * the listed properties may be computed. - */ -struct grail_contact { - int id; - int tool_type; - struct grail_coord pos; - float touch_major; - float touch_minor; - float width_major; - float width_minor; - float angle; - float pressure; -}; - /** * struct grail_client_id - Gesture client information * @client: Client id @@ -230,19 +219,6 @@ void GRAIL_PUBLIC grail_set_bbox(struct grail *ge, const struct grail_coord *min, const struct grail_coord *max); -/** - * grail_filter_abs_events - filter kernel motion events - * @ge: the grail device in use - * @usage: When true, filter kernel motion events. - * - * Single-finger pointer events are treated as pointer gestures in - * grail. When filter_motion_events is non-zero, the kernel events - * corresponding to pointer movement are removed from the event - * stream. - * - */ -void GRAIL_PUBLIC grail_filter_abs_events(struct grail *ge, int usage); - /** * grail_get_units - get device coordinate ranges * @ge: the grail device in use @@ -260,17 +236,43 @@ void GRAIL_PUBLIC grail_get_units(const struct grail *ge, struct grail_coord *max); /** - * grail_get_contacts - get current contact state + * grail_get_contact_frame - get current contact frame * @ge: the grail device in use - * @touch: array of contacts to be filled in - * @max_touch: maximum number of contacts supported by the array * - * Extract the contact state as currently seen by grail. + * Return the contact frame current being processed. If called from + * within a gesture callback, it is guaranteed to return the frame + * corresponding to the gesture. + * + * The returned pointer can be NULL if no input has yet been extracted + * through the grail instance. * + * The frame pointer is ABI agnostic, owned by the grail instance, and + * has grail scope. */ +const struct utouch_frame GRAIL_PUBLIC * +grail_get_contact_frame(const struct grail *ge); + +#ifndef GRAIL_NO_LEGACY_API + +struct grail_contact { + int id; + int tool_type; + struct grail_coord pos; + float touch_major; + float touch_minor; + float width_major; + float width_minor; + float angle; + float pressure; +}; + +void GRAIL_PUBLIC grail_filter_abs_events(struct grail *ge, int usage); + int GRAIL_PUBLIC grail_get_contacts(const struct grail *ge, struct grail_contact *touch, int max_touch); +#endif + #ifdef __cplusplus } #endif diff --git a/src/Makefile.am b/src/Makefile.am index c344342..b26574c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,7 +25,8 @@ libutouch_grail_la_SOURCES = \ grail-recognizer.h \ grail-event.c \ grail-impl.h \ - grail-api.c + grail-api.c \ + grail-legacy.c # These are flags required to properly set up # the build. -fvisibility requires GCC > 4 (or clang) diff --git a/src/grail-api.c b/src/grail-api.c index 1236205..6ef4b7d 100644 --- a/src/grail-api.c +++ b/src/grail-api.c @@ -20,9 +20,9 @@ * ****************************************************************************/ +#include "grail-impl.h" #include "grail-inserter.h" #include "grail-recognizer.h" -#include "grail-impl.h" #include #include #include @@ -35,10 +35,9 @@ #define DIM_FRAMES 100 #define FRAME_RATE 100 -void GRAIL_PUBLIC grail_filter_abs_events(struct grail *ge, int usage) +unsigned int GRAIL_PUBLIC grail_get_version(void) { - struct grail_impl *x = ge->impl; - x->filter_abs = usage; + return GRAIL_VERSION; } int GRAIL_PUBLIC grail_open(struct grail *ge, int fd) @@ -152,6 +151,12 @@ void GRAIL_PUBLIC grail_get_units(const struct grail *ge, max->y = s->max_y; } +const struct utouch_frame GRAIL_PUBLIC * +grail_get_contact_frame(const struct grail *ge) +{ + return ge->impl->frame; +} + static void flush_events(struct grail *ge) { struct grail_impl *impl = ge->impl; diff --git a/src/grail-event.c b/src/grail-event.c index bb75a06..0c565ea 100644 --- a/src/grail-event.c +++ b/src/grail-event.c @@ -117,28 +117,3 @@ void gin_send_event(struct grail *ge, struct slot_state *s, grailbuf_put(&impl->gbuf, &gev); } } - -int GRAIL_PUBLIC grail_get_contacts(const struct grail *ge, - struct grail_contact *touch, int max_touch) -{ - const struct gesture_inserter *gin = ge->gin; - const struct utouch_frame *frame = ge->impl->frame; - int i; - if (frame->num_active < max_touch) - max_touch = frame->num_active; - for (i = 0; i < max_touch; i++) { - struct grail_contact *t = &touch[i]; - const struct utouch_contact *ct = frame->active[i]; - t->id = ct->id; - t->tool_type = ct->tool_type; - t->pos.x = ct->x; - t->pos.y = ct->y; - t->touch_major = ct->touch_major; - t->touch_minor = ct->touch_minor; - t->width_major = ct->width_major; - t->width_minor = ct->width_minor; - t->angle = ct->orientation; - t->pressure = ct->pressure; - } - return max_touch; -} diff --git a/src/grail-legacy.c b/src/grail-legacy.c new file mode 100644 index 0000000..779595b --- /dev/null +++ b/src/grail-legacy.c @@ -0,0 +1,66 @@ +/***************************************************************************** + * + * grail - Gesture Recognition And Instantiation Library + * + * Copyright (C) 2010 Canonical Ltd. + * Copyright (C) 2010 Henrik Rydberg + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + ****************************************************************************/ + +#include +#include "grail-inserter.h" +#include +#include +#include +#include +#include +#include +#include + +#ifndef GRAIL_NO_LEGACY_ABI + +void GRAIL_PUBLIC grail_filter_abs_events(struct grail *ge, int usage) +{ + struct grail_impl *x = ge->impl; + x->filter_abs = usage; +} + +int GRAIL_PUBLIC grail_get_contacts(const struct grail *ge, + struct grail_contact *touch, int max_touch) +{ + const struct gesture_inserter *gin = ge->gin; + const struct utouch_frame *frame = ge->impl->frame; + int i; + if (frame->num_active < max_touch) + max_touch = frame->num_active; + for (i = 0; i < max_touch; i++) { + struct grail_contact *t = &touch[i]; + const struct utouch_contact *ct = frame->active[i]; + t->id = ct->id; + t->tool_type = ct->tool_type; + t->pos.x = ct->x; + t->pos.y = ct->y; + t->touch_major = ct->touch_major; + t->touch_minor = ct->touch_minor; + t->width_major = ct->width_major; + t->width_minor = ct->width_minor; + t->angle = ct->orientation; + t->pressure = ct->pressure; + } + return max_touch; +} + +#endif -- cgit v1.2.3