diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | include/grail-gesture.h | 90 | ||||
| -rw-r--r-- | include/grail-touch.h | 8 | ||||
| -rw-r--r-- | include/grail.h | 80 | ||||
| -rw-r--r-- | src/Makefile.am | 4 | ||||
| -rw-r--r-- | src/gesture-client.c | 2 | ||||
| -rw-r--r-- | src/gesture-dev.c | 2 | ||||
| -rw-r--r-- | src/grail-api.c | 151 | ||||
| -rw-r--r-- | src/touch-dev.c | 6 | ||||
| -rw-r--r-- | src/touch-engine.c | 9 | ||||
| -rw-r--r-- | test/Makefile.am | 5 | ||||
| -rw-r--r-- | test/evlink.c | 96 | ||||
| -rw-r--r-- | test/grail.c | 7 | ||||
| -rw-r--r-- | test/touch.c | 7 |
14 files changed, 398 insertions, 70 deletions
| @@ -78,6 +78,7 @@ core | |||
| 78 | # | 78 | # |
| 79 | test/touch | 79 | test/touch |
| 80 | test/grail | 80 | test/grail |
| 81 | test/evlink | ||
| 81 | patches | 82 | patches |
| 82 | .bzr | 83 | .bzr |
| 83 | .bzrignore | 84 | .bzrignore |
diff --git a/include/grail-gesture.h b/include/grail-gesture.h new file mode 100644 index 0000000..fe62b95 --- /dev/null +++ b/include/grail-gesture.h | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * grail - Gesture Recognition And Instantiation Library | ||
| 4 | * | ||
| 5 | * Copyright (C) 2010 Canonical Ltd. | ||
| 6 | * | ||
| 7 | * This program is free software: you can redistribute it and/or modify it | ||
| 8 | * under the terms of the GNU General Public License as published by the | ||
| 9 | * Free Software Foundation, either version 3 of the License, or (at your | ||
| 10 | * option) any later version. | ||
| 11 | * | ||
| 12 | * This program is distributed in the hope that it will be useful, but | ||
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License along | ||
| 18 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | * | ||
| 20 | * Authors: | ||
| 21 | * Henrik Rydberg <rydberg@bitmath.org> | ||
| 22 | * | ||
| 23 | ****************************************************************************/ | ||
| 24 | |||
| 25 | #ifndef _GRAIL_GESTURE_H | ||
| 26 | #define _GRAIL_GESTURE_H | ||
| 27 | |||
| 28 | #include <grail-touch.h> | ||
| 29 | |||
| 30 | #define DIM_GESTURE_PROP 8 | ||
| 31 | typedef int gesture_prop_t; | ||
| 32 | |||
| 33 | enum gesture_type { | ||
| 34 | GE_MOVE, | ||
| 35 | GE_VSCROLL, | ||
| 36 | DIM_GESTURE_TYPE | ||
| 37 | }; | ||
| 38 | |||
| 39 | enum gesture_state { | ||
| 40 | GS_CANCEL, | ||
| 41 | GS_BEGIN, | ||
| 42 | GS_END | ||
| 43 | }; | ||
| 44 | |||
| 45 | struct gesture_flag { | ||
| 46 | enum gesture_type type; | ||
| 47 | touch_time_t time; | ||
| 48 | enum gesture_state state; | ||
| 49 | }; | ||
| 50 | |||
| 51 | struct gesture_event { | ||
| 52 | enum gesture_type type; | ||
| 53 | touch_time_t time; | ||
| 54 | gesture_prop_t prop[DIM_GESTURE_PROP]; | ||
| 55 | }; | ||
| 56 | |||
| 57 | struct gesture_dev { | ||
| 58 | struct gedev_impl *impl; | ||
| 59 | void *priv; | ||
| 60 | }; | ||
| 61 | |||
| 62 | struct gesture_client { | ||
| 63 | void (*gesture)(struct gesture_client *client, | ||
| 64 | const struct gesture_event *ev); | ||
| 65 | int priority[DIM_GESTURE_TYPE]; | ||
| 66 | struct client_impl *impl; | ||
| 67 | void *priv; | ||
| 68 | }; | ||
| 69 | |||
| 70 | int client_init(struct gesture_client *client, void *priv); | ||
| 71 | void client_flag(struct gesture_client *client, | ||
| 72 | const struct gesture_flag *flag); | ||
| 73 | void client_event(struct gesture_client *client, | ||
| 74 | const struct gesture_event *ev); | ||
| 75 | void client_sync(struct gesture_client *client); | ||
| 76 | void client_destroy(struct gesture_client *client); | ||
| 77 | |||
| 78 | int gedev_init(struct gesture_dev *dev, void *priv); | ||
| 79 | int gedev_attach_client(struct gesture_dev *dev, | ||
| 80 | struct gesture_client *client); | ||
| 81 | |||
| 82 | void gedev_flag(struct gesture_dev *dev, const struct gesture_flag *flag); | ||
| 83 | void gedev_event(struct gesture_dev *dev, const struct gesture_event *ev); | ||
| 84 | void gedev_sync(struct gesture_dev *dev); | ||
| 85 | |||
| 86 | void gedev_detach_client(struct gesture_dev *dev, | ||
| 87 | struct gesture_client *client); | ||
| 88 | void gedev_destroy(struct gesture_dev *dev); | ||
| 89 | |||
| 90 | #endif | ||
diff --git a/include/grail-touch.h b/include/grail-touch.h index 9e8572b..e4bfd7b 100644 --- a/include/grail-touch.h +++ b/include/grail-touch.h | |||
| @@ -67,7 +67,7 @@ struct touch_dev { | |||
| 67 | void (*modify)(struct touch_dev *dev, int slot, | 67 | void (*modify)(struct touch_dev *dev, int slot, |
| 68 | const touch_prop_mask_t *mask, const touch_prop_t *prop); | 68 | const touch_prop_mask_t *mask, const touch_prop_t *prop); |
| 69 | void (*destroy)(struct touch_dev *dev, int slot); | 69 | void (*destroy)(struct touch_dev *dev, int slot); |
| 70 | void (*sync)(struct touch_dev *dev, touch_time_t time); | 70 | void (*sync)(struct touch_dev *dev, const struct input_event *syn); |
| 71 | struct touch_dev_impl *impl; | 71 | struct touch_dev_impl *impl; |
| 72 | void *priv; | 72 | void *priv; |
| 73 | }; | 73 | }; |
| @@ -75,7 +75,8 @@ struct touch_dev { | |||
| 75 | struct touch_engine { | 75 | struct touch_engine { |
| 76 | void (*event)(struct touch_engine *engine, | 76 | void (*event)(struct touch_engine *engine, |
| 77 | const struct input_event *ev); | 77 | const struct input_event *ev); |
| 78 | void (*sync)(struct touch_engine *engine); | 78 | void (*sync)(struct touch_engine *engine, |
| 79 | const struct input_event *syn); | ||
| 79 | struct touch_frame frame; | 80 | struct touch_frame frame; |
| 80 | void *priv; | 81 | void *priv; |
| 81 | }; | 82 | }; |
| @@ -98,7 +99,8 @@ void touch_dev_close(struct touch_dev *dev, int fd); | |||
| 98 | void touch_engine_init(struct touch_engine *engine, | 99 | void touch_engine_init(struct touch_engine *engine, |
| 99 | void (*event)(struct touch_engine *engine, | 100 | void (*event)(struct touch_engine *engine, |
| 100 | const struct input_event *ev), | 101 | const struct input_event *ev), |
| 101 | void (*sync)(struct touch_engine *engine), | 102 | void (*sync)(struct touch_engine *engine, |
| 103 | const struct input_event *ev), | ||
| 102 | void *priv); | 104 | void *priv); |
| 103 | void touch_engine_attach(struct touch_engine *engine, struct touch_dev *dev); | 105 | void touch_engine_attach(struct touch_engine *engine, struct touch_dev *dev); |
| 104 | void touch_engine_detach(struct touch_engine *engine, struct touch_dev *dev); | 106 | void touch_engine_detach(struct touch_engine *engine, struct touch_dev *dev); |
diff --git a/include/grail.h b/include/grail.h index 087cf0c..c390e22 100644 --- a/include/grail.h +++ b/include/grail.h | |||
| @@ -25,66 +25,44 @@ | |||
| 25 | #ifndef _GRAIL_H | 25 | #ifndef _GRAIL_H |
| 26 | #define _GRAIL_H | 26 | #define _GRAIL_H |
| 27 | 27 | ||
| 28 | #include <grail-touch.h> | 28 | #include <linux/input.h> |
| 29 | 29 | ||
| 30 | #define DIM_GESTURE_PROP 8 | 30 | #define DIM_GRAIL_PROP 8 |
| 31 | typedef int gesture_prop_t; | 31 | #define DIM_GRAIL_TYPE 64 |
| 32 | 32 | ||
| 33 | enum gesture_type { | 33 | typedef int grail_prop_t; |
| 34 | GE_MOVE, | 34 | typedef __u64 grail_time_t; |
| 35 | GE_VSCROLL, | 35 | typedef unsigned long grail_clientid_t; |
| 36 | DIM_GESTURE_TYPE | ||
| 37 | }; | ||
| 38 | |||
| 39 | enum gesture_state { | ||
| 40 | GS_CANCEL, | ||
| 41 | GS_BEGIN, | ||
| 42 | GS_END | ||
| 43 | }; | ||
| 44 | |||
| 45 | struct gesture_flag { | ||
| 46 | enum gesture_type type; | ||
| 47 | touch_time_t time; | ||
| 48 | enum gesture_state state; | ||
| 49 | }; | ||
| 50 | 36 | ||
| 51 | struct gesture_event { | 37 | struct grail_event { |
| 52 | enum gesture_type type; | 38 | int type; |
| 53 | touch_time_t time; | 39 | int id; |
| 54 | gesture_prop_t prop[DIM_GESTURE_PROP]; | 40 | int x; |
| 41 | int y; | ||
| 42 | int status; | ||
| 43 | grail_time_t time; | ||
| 44 | grail_prop_t prop[DIM_GRAIL_PROP]; | ||
| 55 | }; | 45 | }; |
| 56 | 46 | ||
| 57 | struct gesture_dev { | 47 | struct grail { |
| 58 | struct gedev_impl *impl; | 48 | int (*get_clients)(int x, int y, int screen, |
| 49 | grail_clientid_t *clients, int nclients); | ||
| 50 | void (*event)(struct grail *ge, | ||
| 51 | const struct input_event *ev); | ||
| 52 | void (*gesture)(struct grail *ge, | ||
| 53 | const struct grail_event *ev); | ||
| 54 | struct grail_impl *impl; | ||
| 59 | void *priv; | 55 | void *priv; |
| 60 | }; | 56 | }; |
| 61 | 57 | ||
| 62 | struct gesture_client { | 58 | int grail_open(struct grail *ge, int fd); |
| 63 | void (*gesture)(struct gesture_client *client, | 59 | int grail_idle(struct grail *ge, int fd, int ms); |
| 64 | const struct gesture_event *ev); | 60 | int grail_pull(struct grail *ge, int fd); |
| 65 | int priority[DIM_GESTURE_TYPE]; | 61 | void grail_close(struct grail *ge, int fd); |
| 66 | struct client_impl *impl; | ||
| 67 | void *priv; | ||
| 68 | }; | ||
| 69 | |||
| 70 | int client_init(struct gesture_client *client, void *priv); | ||
| 71 | void client_flag(struct gesture_client *client, | ||
| 72 | const struct gesture_flag *flag); | ||
| 73 | void client_event(struct gesture_client *client, | ||
| 74 | const struct gesture_event *ev); | ||
| 75 | void client_sync(struct gesture_client *client); | ||
| 76 | void client_destroy(struct gesture_client *client); | ||
| 77 | |||
| 78 | int gedev_init(struct gesture_dev *dev, void *priv); | ||
| 79 | int gedev_attach_client(struct gesture_dev *dev, | ||
| 80 | struct gesture_client *client); | ||
| 81 | 62 | ||
| 82 | void gedev_flag(struct gesture_dev *dev, const struct gesture_flag *flag); | 63 | void grail_add_client(struct grail *ge, grail_clientid_t id, |
| 83 | void gedev_event(struct gesture_dev *dev, const struct gesture_event *ev); | 64 | const int *types, const int *priority, int ntypes); |
| 84 | void gedev_sync(struct gesture_dev *dev); | 65 | void grail_remove_client(struct grail *ge, grail_clientid_t id); |
| 85 | 66 | ||
| 86 | void gedev_detach_client(struct gesture_dev *dev, | ||
| 87 | struct gesture_client *client); | ||
| 88 | void gedev_destroy(struct gesture_dev *dev); | ||
| 89 | 67 | ||
| 90 | #endif | 68 | #endif |
diff --git a/src/Makefile.am b/src/Makefile.am index 7ccacae..50a5afd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
| @@ -8,7 +8,8 @@ libgrail_la_SOURCES = \ | |||
| 8 | touch-dev.c \ | 8 | touch-dev.c \ |
| 9 | touch-engine.c \ | 9 | touch-engine.c \ |
| 10 | gesture-client.c \ | 10 | gesture-client.c \ |
| 11 | gesture-dev.c | 11 | gesture-dev.c \ |
| 12 | grail-api.c | ||
| 12 | 13 | ||
| 13 | AM_CFLAGS = $(CWARNFLAGS) -std=c99 | 14 | AM_CFLAGS = $(CWARNFLAGS) -std=c99 |
| 14 | 15 | ||
| @@ -17,4 +18,5 @@ INCLUDES = -I$(top_srcdir)/include/ | |||
| 17 | libgrailincludedir = $(includedir) | 18 | libgrailincludedir = $(includedir) |
| 18 | libgrailinclude_HEADERS = \ | 19 | libgrailinclude_HEADERS = \ |
| 19 | $(top_srcdir)/include/grail-touch.h \ | 20 | $(top_srcdir)/include/grail-touch.h \ |
| 21 | $(top_srcdir)/include/grail-gesture.h \ | ||
| 20 | $(top_srcdir)/include/grail.h | 22 | $(top_srcdir)/include/grail.h |
diff --git a/src/gesture-client.c b/src/gesture-client.c index 78328b7..91f1530 100644 --- a/src/gesture-client.c +++ b/src/gesture-client.c | |||
| @@ -22,7 +22,7 @@ | |||
| 22 | * | 22 | * |
| 23 | ****************************************************************************/ | 23 | ****************************************************************************/ |
| 24 | 24 | ||
| 25 | #include <grail.h> | 25 | #include <grail-gesture.h> |
| 26 | #include <malloc.h> | 26 | #include <malloc.h> |
| 27 | #include <string.h> | 27 | #include <string.h> |
| 28 | #include <errno.h> | 28 | #include <errno.h> |
diff --git a/src/gesture-dev.c b/src/gesture-dev.c index 8dd11a9..46c77d7 100644 --- a/src/gesture-dev.c +++ b/src/gesture-dev.c | |||
| @@ -22,7 +22,7 @@ | |||
| 22 | * | 22 | * |
| 23 | ****************************************************************************/ | 23 | ****************************************************************************/ |
| 24 | 24 | ||
| 25 | #include <grail.h> | 25 | #include <grail-gesture.h> |
| 26 | #include <malloc.h> | 26 | #include <malloc.h> |
| 27 | #include <string.h> | 27 | #include <string.h> |
| 28 | #include <errno.h> | 28 | #include <errno.h> |
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 @@ | |||
| 1 | #include <grail-gesture.h> | ||
| 2 | #include <grail.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | #include <unistd.h> | ||
| 6 | #include <fcntl.h> | ||
| 7 | #include <malloc.h> | ||
| 8 | #include <errno.h> | ||
| 9 | |||
| 10 | struct grail_impl { | ||
| 11 | struct touch_dev dev; | ||
| 12 | struct touch_engine engine; | ||
| 13 | struct touch_frame frame; | ||
| 14 | struct gesture_dev gedev; | ||
| 15 | struct gesture_client client; | ||
| 16 | touch_time_t last_scroll; | ||
| 17 | }; | ||
| 18 | |||
| 19 | static void gh_handle(struct grail_impl *gh, | ||
| 20 | const struct touch_frame *frame, | ||
| 21 | touch_time_t time) | ||
| 22 | { | ||
| 23 | #if 0 | ||
| 24 | struct gesture_flag flag; | ||
| 25 | struct grail_event ev; | ||
| 26 | if (frame->ntouch == 1 || frame->ntouch == 2) { | ||
| 27 | flag.type = GE_MOVE; | ||
| 28 | flag.time = time; | ||
| 29 | flag.state = GS_BEGIN; | ||
| 30 | gedev_flag(&gh->dev, &flag); | ||
| 31 | |||
| 32 | ev.type = GE_MOVE; | ||
| 33 | ev.time = time; | ||
| 34 | ev.prop[0] = | ||
| 35 | frame->touch[0].prop[TP_POS_X] - | ||
| 36 | gh->frame.touch[0].prop[TP_POS_X]; | ||
| 37 | ev.prop[1] = | ||
| 38 | frame->touch[0].prop[TP_POS_Y] - | ||
| 39 | gh->frame.touch[0].prop[TP_POS_Y]; | ||
| 40 | if (ev.prop[0] || ev.prop[1]) | ||
| 41 | gedev_event(&gh->dev, &ev); | ||
| 42 | |||
| 43 | flag.time = time + 1; | ||
| 44 | flag.state = GS_END; | ||
| 45 | gedev_flag(&gh->dev, &flag); | ||
| 46 | } | ||
| 47 | if (frame->ntouch == 2) { | ||
| 48 | flag.type = GE_VSCROLL; | ||
| 49 | flag.time = time; | ||
| 50 | flag.state = GS_BEGIN; | ||
| 51 | gedev_flag(&gh->dev, &flag); | ||
| 52 | |||
| 53 | ev.type = GE_VSCROLL; | ||
| 54 | ev.time = time; | ||
| 55 | ev.prop[0] = | ||
| 56 | frame->touch[0].prop[TP_POS_Y] - | ||
| 57 | gh->frame.touch[0].prop[TP_POS_Y]; | ||
| 58 | |||
| 59 | if (ev.prop[0]) | ||
| 60 | gedev_event(&gh->dev, &ev); | ||
| 61 | |||
| 62 | if (time > gh->last_scroll + 100) { | ||
| 63 | flag.time = time + 1; | ||
| 64 | flag.state = GS_END; | ||
| 65 | gedev_flag(&gh->dev, &flag); | ||
| 66 | gh->last_scroll = time; | ||
| 67 | } | ||
| 68 | } else { | ||
| 69 | flag.type = GE_VSCROLL; | ||
| 70 | flag.time = time; | ||
| 71 | flag.state = GS_CANCEL; | ||
| 72 | gedev_flag(&gh->dev, &flag); | ||
| 73 | } | ||
| 74 | gedev_sync(&gh->dev); | ||
| 75 | gh->frame = *frame; | ||
| 76 | #endif | ||
| 77 | } | ||
| 78 | |||
| 79 | static void tp_event(struct touch_engine *engine, | ||
| 80 | const struct input_event *ev) | ||
| 81 | { | ||
| 82 | struct grail *ge = engine->priv; | ||
| 83 | if (ge->event) | ||
| 84 | ge->event(ge, ev); | ||
| 85 | } | ||
| 86 | |||
| 87 | static void tp_sync(struct touch_engine *engine, | ||
| 88 | const struct input_event *syn) | ||
| 89 | { | ||
| 90 | struct grail *ge = engine->priv; | ||
| 91 | #if 0 | ||
| 92 | struct touch_frame *frame = &engine->frame; | ||
| 93 | gh_handle(ge, frame, frame->time); | ||
| 94 | #endif | ||
| 95 | if (ge->event) | ||
| 96 | ge->event(ge, syn); | ||
| 97 | } | ||
| 98 | |||
| 99 | int grail_open(struct grail *ge, int fd) | ||
| 100 | { | ||
| 101 | struct grail_impl *x; | ||
| 102 | int ret; | ||
| 103 | x = calloc(1, sizeof(*x)); | ||
| 104 | if (!x) | ||
| 105 | return -ENOMEM; | ||
| 106 | ret = touch_dev_open(&x->dev, fd); | ||
| 107 | if (ret) | ||
| 108 | goto error; | ||
| 109 | touch_engine_init(&x->engine, tp_event, tp_sync, ge); | ||
| 110 | touch_engine_attach(&x->engine, &x->dev); | ||
| 111 | ge->impl = x; | ||
| 112 | return 0; | ||
| 113 | error: | ||
| 114 | free(x); | ||
| 115 | return ret; | ||
| 116 | } | ||
| 117 | |||
| 118 | int grail_idle(struct grail *ge, int fd, int ms) | ||
| 119 | { | ||
| 120 | struct grail_impl *x = ge->impl; | ||
| 121 | return touch_dev_idle(&x->dev, fd, ms); | ||
| 122 | } | ||
| 123 | |||
| 124 | int grail_pull(struct grail *ge, int fd) | ||
| 125 | { | ||
| 126 | struct grail_impl *x = ge->impl; | ||
| 127 | return touch_dev_pull(&x->dev, fd); | ||
| 128 | } | ||
| 129 | |||
| 130 | void grail_close(struct grail *ge, int fd) | ||
| 131 | { | ||
| 132 | struct grail_impl *x = ge->impl; | ||
| 133 | touch_engine_detach(&x->engine, &x->dev); | ||
| 134 | touch_dev_close(&x->dev, fd); | ||
| 135 | free(ge->impl); | ||
| 136 | ge->impl = 0; | ||
| 137 | } | ||
| 138 | |||
| 139 | void grail_add_client(struct grail *ge, grail_clientid_t id, | ||
| 140 | const int *types, const int *priority, int ntypes) | ||
| 141 | { | ||
| 142 | struct grail_impl *x = ge->impl; | ||
| 143 | //gedev_attach_client(&x->dev, &x->client); | ||
| 144 | } | ||
| 145 | |||
| 146 | void grail_remove_client(struct grail *ge, grail_clientid_t id) | ||
| 147 | { | ||
| 148 | struct grail_impl *x = ge->impl; | ||
| 149 | //gedev_detach_client(&x->dev, &x->client); | ||
| 150 | } | ||
| 151 | |||
diff --git a/src/touch-dev.c b/src/touch-dev.c index 80cc82f..dc23baa 100644 --- a/src/touch-dev.c +++ b/src/touch-dev.c | |||
| @@ -65,11 +65,9 @@ static void finish_touch(struct touch_dev *dev, | |||
| 65 | static void finish_packet(struct touch_dev *dev, | 65 | static void finish_packet(struct touch_dev *dev, |
| 66 | const struct input_event *syn) | 66 | const struct input_event *syn) |
| 67 | { | 67 | { |
| 68 | static const touch_time_t ms = 1000; | ||
| 69 | touch_time_t time = syn->time.tv_usec / ms + syn->time.tv_sec * ms; | ||
| 70 | finish_touch(dev, dev->impl); | 68 | finish_touch(dev, dev->impl); |
| 71 | if (dev->sync) | 69 | if (dev->sync) |
| 72 | dev->sync(dev, time); | 70 | dev->sync(dev, syn); |
| 73 | } | 71 | } |
| 74 | 72 | ||
| 75 | static int handle_abs_event(struct touch_dev *dev, | 73 | static int handle_abs_event(struct touch_dev *dev, |
| @@ -133,6 +131,8 @@ int touch_dev_open(struct touch_dev *dev, int fd) | |||
| 133 | if (!x) | 131 | if (!x) |
| 134 | return -ENOMEM; | 132 | return -ENOMEM; |
| 135 | ret = mtdev_open(&x->mtdev, fd); | 133 | ret = mtdev_open(&x->mtdev, fd); |
| 134 | if (!ret && !x->mtdev.caps.has_mtdata) | ||
| 135 | ret = -ENODEV; | ||
| 136 | if (ret) | 136 | if (ret) |
| 137 | goto error; | 137 | goto error; |
| 138 | for (i = 0; i < DIM_TOUCH; i++) | 138 | for (i = 0; i < DIM_TOUCH; i++) |
diff --git a/src/touch-engine.c b/src/touch-engine.c index 6174e0d..8e43faf 100644 --- a/src/touch-engine.c +++ b/src/touch-engine.c | |||
| @@ -94,13 +94,15 @@ static void tp_destroy(struct touch_dev *dev, int slot) | |||
| 94 | } | 94 | } |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | static void tp_sync(struct touch_dev *dev, touch_time_t time) | 97 | static void tp_sync(struct touch_dev *dev, const struct input_event *syn) |
| 98 | { | 98 | { |
| 99 | static const touch_time_t ms = 1000; | ||
| 99 | struct touch_engine *engine = dev->priv; | 100 | struct touch_engine *engine = dev->priv; |
| 101 | touch_time_t time = syn->time.tv_usec / ms + syn->time.tv_sec * ms; | ||
| 100 | if (engine) { | 102 | if (engine) { |
| 101 | finalize_frame(&engine->frame, time); | 103 | finalize_frame(&engine->frame, time); |
| 102 | if (engine->sync) | 104 | if (engine->sync) |
| 103 | engine->sync(engine); | 105 | engine->sync(engine, syn); |
| 104 | engine->frame.ncreate = 0; | 106 | engine->frame.ncreate = 0; |
| 105 | engine->frame.nmodify = 0; | 107 | engine->frame.nmodify = 0; |
| 106 | engine->frame.ndestroy = 0; | 108 | engine->frame.ndestroy = 0; |
| @@ -110,7 +112,8 @@ static void tp_sync(struct touch_dev *dev, touch_time_t time) | |||
| 110 | void touch_engine_init(struct touch_engine *engine, | 112 | void touch_engine_init(struct touch_engine *engine, |
| 111 | void (*event)(struct touch_engine *engine, | 113 | void (*event)(struct touch_engine *engine, |
| 112 | const struct input_event *ev), | 114 | const struct input_event *ev), |
| 113 | void (*sync)(struct touch_engine *engine), | 115 | void (*sync)(struct touch_engine *engine, |
| 116 | const struct input_event *ev), | ||
| 114 | void *priv) | 117 | void *priv) |
| 115 | { | 118 | { |
| 116 | memset(engine, 0, sizeof(*engine)); | 119 | memset(engine, 0, sizeof(*engine)); |
diff --git a/test/Makefile.am b/test/Makefile.am index c8404f8..a24f615 100644 --- a/test/Makefile.am +++ b/test/Makefile.am | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | noinst_PROGRAMS = touch grail | 1 | noinst_PROGRAMS = touch grail evlink |
| 2 | 2 | ||
| 3 | INCLUDES=-I$(top_srcdir)/include/ | 3 | INCLUDES=-I$(top_srcdir)/include/ |
| 4 | 4 | ||
| @@ -7,3 +7,6 @@ touch_LDFLAGS = -L$(top_builddir)/src/.libs/ -lgrail -lmtdev | |||
| 7 | 7 | ||
| 8 | grail_SOURCES = grail.c | 8 | grail_SOURCES = grail.c |
| 9 | grail_LDFLAGS = -L$(top_builddir)/src/.libs/ -lgrail -lmtdev | 9 | grail_LDFLAGS = -L$(top_builddir)/src/.libs/ -lgrail -lmtdev |
| 10 | |||
| 11 | evlink_SOURCES = evlink.c | ||
| 12 | evlink_LDFLAGS = -L$(top_builddir)/src/.libs/ -lgrail -lmtdev | ||
diff --git a/test/evlink.c b/test/evlink.c new file mode 100644 index 0000000..bef5e22 --- /dev/null +++ b/test/evlink.c | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * grail - Gesture Recognition And Instantiation Library | ||
| 4 | * | ||
| 5 | * Copyright (C) 2010 Canonical Ltd. | ||
| 6 | * | ||
| 7 | * This program is free software: you can redistribute it and/or modify it | ||
| 8 | * under the terms of the GNU General Public License as published by the | ||
| 9 | * Free Software Foundation, either version 3 of the License, or (at your | ||
| 10 | * option) any later version. | ||
| 11 | * | ||
| 12 | * This program is distributed in the hope that it will be useful, but | ||
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License along | ||
| 18 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | * | ||
| 20 | * Authors: | ||
| 21 | * Henrik Rydberg <rydberg@bitmath.org> | ||
| 22 | * | ||
| 23 | ****************************************************************************/ | ||
| 24 | |||
| 25 | #include <grail.h> | ||
| 26 | #include <string.h> | ||
| 27 | #include <stdio.h> | ||
| 28 | #include <unistd.h> | ||
| 29 | #include <fcntl.h> | ||
| 30 | |||
| 31 | static int tp_get_clients(int x, int y, int screen, | ||
| 32 | grail_clientid_t *clients, int nclients) | ||
| 33 | { | ||
| 34 | return 0; | ||
| 35 | } | ||
| 36 | |||
| 37 | static void tp_event(struct grail *ge, const struct input_event *ev) | ||
| 38 | { | ||
| 39 | fprintf(stderr, "event %d %d %d\n", ev->type, ev->code, ev->value); | ||
| 40 | } | ||
| 41 | |||
| 42 | static void tp_gesture(struct grail *ge, const struct grail_event *ev) | ||
| 43 | { | ||
| 44 | fprintf(stderr, "gesture %d %d\n", ev->type, ev->id); | ||
| 45 | } | ||
| 46 | |||
| 47 | static void loop_device(struct grail *ge, int fd) | ||
| 48 | { | ||
| 49 | while (!grail_idle(ge, fd, 5000)) | ||
| 50 | grail_pull(ge, fd); | ||
| 51 | } | ||
| 52 | |||
| 53 | #if 0 | ||
| 54 | void grail_add_client(struct grail *ge, grail_clientid_t id, | ||
| 55 | const int *types, const int *priority, int ntypes); | ||
| 56 | void grail_remove_client(struct grail *ge, grail_clientid_t id); | ||
| 57 | |||
| 58 | #endif | ||
| 59 | |||
| 60 | |||
| 61 | int main(int argc, char *argv[]) | ||
| 62 | { | ||
| 63 | struct grail ge; | ||
| 64 | int fd; | ||
| 65 | |||
| 66 | if (argc < 2) { | ||
| 67 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); | ||
| 68 | return -1; | ||
| 69 | } | ||
| 70 | |||
| 71 | memset(&ge, 0, sizeof(ge)); | ||
| 72 | ge.get_clients = tp_get_clients; | ||
| 73 | ge.event = tp_event; | ||
| 74 | ge.gesture = tp_gesture; | ||
| 75 | |||
| 76 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); | ||
| 77 | if (fd < 0) { | ||
| 78 | fprintf(stderr, "error: could not open device\n"); | ||
| 79 | return -1; | ||
| 80 | } | ||
| 81 | if (ioctl(fd, EVIOCGRAB, 1)) { | ||
| 82 | fprintf(stderr, "error: could not grab the device\n"); | ||
| 83 | return -1; | ||
| 84 | } | ||
| 85 | |||
| 86 | if (grail_open(&ge, fd)) { | ||
| 87 | fprintf(stderr, "error: could not open touch device\n"); | ||
| 88 | return -1; | ||
| 89 | } | ||
| 90 | loop_device(&ge, fd); | ||
| 91 | grail_close(&ge, fd); | ||
| 92 | |||
| 93 | ioctl(fd, EVIOCGRAB, 0); | ||
| 94 | close(fd); | ||
| 95 | return 0; | ||
| 96 | } | ||
diff --git a/test/grail.c b/test/grail.c index 82de65f..e22ffd8 100644 --- a/test/grail.c +++ b/test/grail.c | |||
| @@ -22,7 +22,7 @@ | |||
| 22 | * | 22 | * |
| 23 | ****************************************************************************/ | 23 | ****************************************************************************/ |
| 24 | 24 | ||
| 25 | #include <grail.h> | 25 | #include <grail-gesture.h> |
| 26 | #include <string.h> | 26 | #include <string.h> |
| 27 | #include <stdio.h> | 27 | #include <stdio.h> |
| 28 | #include <unistd.h> | 28 | #include <unistd.h> |
| @@ -133,7 +133,8 @@ static void tp_event(struct touch_engine *engine, | |||
| 133 | { | 133 | { |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | static void tp_sync(struct touch_engine *engine) | 136 | static void tp_sync(struct touch_engine *engine, |
| 137 | const struct input_event *syn) | ||
| 137 | { | 138 | { |
| 138 | struct gesture_handler *gh = engine->priv; | 139 | struct gesture_handler *gh = engine->priv; |
| 139 | struct touch_frame *frame = &engine->frame; | 140 | struct touch_frame *frame = &engine->frame; |
| @@ -158,7 +159,7 @@ int main(int argc, char *argv[]) | |||
| 158 | struct touch_dev dev; | 159 | struct touch_dev dev; |
| 159 | int fd; | 160 | int fd; |
| 160 | if (argc < 2) { | 161 | if (argc < 2) { |
| 161 | fprintf(stderr, "Usage: mtdev <device>\n"); | 162 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); |
| 162 | return -1; | 163 | return -1; |
| 163 | } | 164 | } |
| 164 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); | 165 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); |
diff --git a/test/touch.c b/test/touch.c index 1f9213d..bc10b54 100644 --- a/test/touch.c +++ b/test/touch.c | |||
| @@ -22,7 +22,7 @@ | |||
| 22 | * | 22 | * |
| 23 | ****************************************************************************/ | 23 | ****************************************************************************/ |
| 24 | 24 | ||
| 25 | #include <grail.h> | 25 | #include <grail-touch.h> |
| 26 | #include <string.h> | 26 | #include <string.h> |
| 27 | #include <stdio.h> | 27 | #include <stdio.h> |
| 28 | #include <unistd.h> | 28 | #include <unistd.h> |
| @@ -34,7 +34,8 @@ static void tp_event(struct touch_engine *engine, | |||
| 34 | fprintf(stderr, "event %d %d %d\n", ev->type, ev->code, ev->value); | 34 | fprintf(stderr, "event %d %d %d\n", ev->type, ev->code, ev->value); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | static void tp_sync(struct touch_engine *engine) | 37 | static void tp_sync(struct touch_engine *engine, |
| 38 | const struct input_event *syn) | ||
| 38 | { | 39 | { |
| 39 | struct touch_frame *frame = &engine->frame; | 40 | struct touch_frame *frame = &engine->frame; |
| 40 | int slot, i; | 41 | int slot, i; |
| @@ -62,7 +63,7 @@ int main(int argc, char *argv[]) | |||
| 62 | struct touch_dev dev; | 63 | struct touch_dev dev; |
| 63 | int fd; | 64 | int fd; |
| 64 | if (argc < 2) { | 65 | if (argc < 2) { |
| 65 | fprintf(stderr, "Usage: mtdev <device>\n"); | 66 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); |
| 66 | return -1; | 67 | return -1; |
| 67 | } | 68 | } |
| 68 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); | 69 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); |
