diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2010-12-30 14:26:55 +0100 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2011-01-02 09:17:00 +0100 |
| commit | 4b0f0873f91f7f37106fa39c6b8b5fa74f6a3dcc (patch) | |
| tree | ba572d2162b9dc0133ab1877d6bb95b6e012437c /src | |
| parent | 4623dc6c963b79d2cc6cfa4530b90f039ef3b6cb (diff) | |
Use utouch-frame instead of grail
With the introduction of utouch-frame, the dependence of this package
may be simplified. This patch removes the dependency on grail, and
instead uses evemu and frame, which are targeting touch usage only.
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src')
| -rw-r--r-- | src/mtview.c | 112 |
1 files changed, 67 insertions, 45 deletions
diff --git a/src/mtview.c b/src/mtview.c index 9126141..ea6730c 100644 --- a/src/mtview.c +++ b/src/mtview.c | |||
| @@ -1,16 +1,17 @@ | |||
| 1 | #include <X11/Xlib.h> | 1 | #include <X11/Xlib.h> |
| 2 | #include <stdio.h> | 2 | #include <stdio.h> |
| 3 | #include <fcntl.h> | 3 | #include <fcntl.h> |
| 4 | #include <grail-touch.h> | 4 | #include <utouch/frame-mtdev.h> |
| 5 | #include <string.h> | 5 | #include <string.h> |
| 6 | #include <math.h> | 6 | #include <math.h> |
| 7 | 7 | ||
| 8 | #define XMARG 16 | 8 | #define XMARG 16 |
| 9 | #define YMARG 16 | 9 | #define YMARG 16 |
| 10 | #define FLUSH_MS 10 | ||
| 11 | #define DEF_FRAC 0.15 | 10 | #define DEF_FRAC 0.15 |
| 12 | #define DEF_WIDTH 0.05 | 11 | #define DEF_WIDTH 0.05 |
| 13 | 12 | ||
| 13 | #define DIM_TOUCH 32 | ||
| 14 | |||
| 14 | struct windata { | 15 | struct windata { |
| 15 | Display *dsp; | 16 | Display *dsp; |
| 16 | Window root, win; | 17 | Window root, win; |
| @@ -19,7 +20,6 @@ struct windata { | |||
| 19 | unsigned long white, black; | 20 | unsigned long white, black; |
| 20 | unsigned long color[DIM_TOUCH]; | 21 | unsigned long color[DIM_TOUCH]; |
| 21 | int id[DIM_TOUCH]; | 22 | int id[DIM_TOUCH]; |
| 22 | touch_time_t last_flush; | ||
| 23 | }; | 23 | }; |
| 24 | 24 | ||
| 25 | static inline float max(float a, float b) | 25 | static inline float max(float a, float b) |
| @@ -38,26 +38,26 @@ static void clear_screen(struct windata *w) | |||
| 38 | XFillRectangle(w->dsp, w->win, w->gc, 0, 0, w->width, w->height); | 38 | XFillRectangle(w->dsp, w->win, w->gc, 0, 0, w->width, w->height); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | static void output_touch(struct touch_dev *dev, struct windata *w, | 41 | static void output_touch(utouch_frame_handle fh, struct windata *w, |
| 42 | const struct touch *t) | 42 | const struct utouch_contact *t) |
| 43 | { | 43 | { |
| 44 | float x1 = dev->caps.min_x, y1 = dev->caps.min_y; | 44 | const struct utouch_surface *s = utouch_frame_get_surface(fh); |
| 45 | float x2 = dev->caps.max_x, y2 = dev->caps.max_y; | 45 | |
| 46 | float x1 = s->min_x, y1 = s->min_y; | ||
| 47 | float x2 = s->max_x, y2 = s->max_y; | ||
| 46 | float dx = x2 - x1, dy = y2 - y1; | 48 | float dx = x2 - x1, dy = y2 - y1; |
| 47 | float major = 0, minor = 0, angle = 0; | 49 | float major = 0, minor = 0, angle = 0; |
| 48 | 50 | ||
| 49 | if (t->pressure > 0) { | 51 | if (s->use_pressure) { |
| 50 | float p = DEF_FRAC / dev->caps.max_press; | 52 | float p = DEF_FRAC / s->max_pressure; |
| 51 | major = t->pressure * p * dx; | 53 | major = t->pressure * p * dx; |
| 52 | minor = t->pressure * p * dx; | 54 | minor = t->pressure * p * dx; |
| 53 | angle = 0; | 55 | angle = 0; |
| 54 | } | 56 | } |
| 55 | if (t->touch_major > 0 || t->touch_minor > 0) { | 57 | if (s->use_touch_major) { |
| 56 | major = t->touch_major; | 58 | major = t->touch_major; |
| 57 | minor = t->touch_minor; | 59 | minor = t->touch_minor; |
| 58 | if (major && !minor) | 60 | angle = t->orientation; |
| 59 | minor = major; | ||
| 60 | angle = touch_angle(dev, t->orientation); | ||
| 61 | } | 61 | } |
| 62 | if (major == 0 && minor == 0) { | 62 | if (major == 0 && minor == 0) { |
| 63 | major = DEF_WIDTH * dy; | 63 | major = DEF_WIDTH * dy; |
| @@ -85,35 +85,26 @@ static void output_touch(struct touch_dev *dev, struct windata *w, | |||
| 85 | 85 | ||
| 86 | XSetForeground(w->dsp, w->gc, w->color[t->slot]); | 86 | XSetForeground(w->dsp, w->gc, w->color[t->slot]); |
| 87 | XFillArc(w->dsp, w->win, w->gc, px, py, qx - px, qy - py, 0, 360 * 64); | 87 | XFillArc(w->dsp, w->win, w->gc, px, py, qx - px, qy - py, 0, 360 * 64); |
| 88 | 88 | XFlush(w->dsp); | |
| 89 | if (dev->frame.time - w->last_flush > FLUSH_MS) { | ||
| 90 | XFlush(w->dsp); | ||
| 91 | w->last_flush = dev->frame.time; | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | static void tp_event(struct touch_dev *dev, | ||
| 96 | const struct input_event *ev) | ||
| 97 | { | ||
| 98 | } | 89 | } |
| 99 | 90 | ||
| 100 | static void tp_sync(struct touch_dev *dev, | 91 | static void report_frame(utouch_frame_handle fh, |
| 101 | const struct input_event *syn) | 92 | const struct utouch_frame *frame, |
| 93 | struct windata *w) | ||
| 102 | { | 94 | { |
| 103 | struct windata *w = dev->priv; | ||
| 104 | struct touch_frame *frame = &dev->frame; | ||
| 105 | int i; | 95 | int i; |
| 106 | for (i = 0; i < frame->nactive; i++) | 96 | |
| 107 | output_touch(dev, w, frame->active[i]); | 97 | for (i = 0; i < frame->num_active; i++) |
| 98 | output_touch(fh, w, frame->active[i]); | ||
| 108 | } | 99 | } |
| 109 | 100 | ||
| 110 | static void event_loop(struct touch_dev *dev, int fd, struct windata *w) | 101 | static void event_loop(utouch_frame_handle fh, |
| 102 | struct mtdev *dev, int fd, | ||
| 103 | struct windata *w) | ||
| 111 | { | 104 | { |
| 112 | XEvent ev; | 105 | const struct utouch_frame *frame; |
| 113 | 106 | struct input_event iev; | |
| 114 | dev->event = tp_event; | 107 | XEvent xev; |
| 115 | dev->sync = tp_sync; | ||
| 116 | dev->priv = w; | ||
| 117 | 108 | ||
| 118 | XSelectInput(w->dsp, w->win, | 109 | XSelectInput(w->dsp, w->win, |
| 119 | ButtonPressMask | ButtonReleaseMask | | 110 | ButtonPressMask | ButtonReleaseMask | |
| @@ -121,15 +112,20 @@ static void event_loop(struct touch_dev *dev, int fd, struct windata *w) | |||
| 121 | 112 | ||
| 122 | clear_screen(w); | 113 | clear_screen(w); |
| 123 | while (1) { | 114 | while (1) { |
| 124 | if(!touch_dev_idle(dev, fd, 100)) | 115 | while (!mtdev_idle(dev, fd, 100)) { |
| 125 | touch_dev_pull(dev, fd); | 116 | while (mtdev_get(dev, fd, &iev, 1) > 0) { |
| 117 | frame = utouch_frame_pump_mtdev(fh, &iev); | ||
| 118 | if (frame) | ||
| 119 | report_frame(fh, frame, w); | ||
| 120 | } | ||
| 121 | } | ||
| 126 | while (XPending(w->dsp)) { | 122 | while (XPending(w->dsp)) { |
| 127 | XNextEvent(w->dsp, &ev); | 123 | XNextEvent(w->dsp, &xev); |
| 128 | } | 124 | } |
| 129 | } | 125 | } |
| 130 | } | 126 | } |
| 131 | 127 | ||
| 132 | static void run_window(struct touch_dev *dev, int fd) | 128 | static void run_window(utouch_frame_handle fh, struct mtdev *dev, int fd) |
| 133 | { | 129 | { |
| 134 | struct windata w; | 130 | struct windata w; |
| 135 | int i; | 131 | int i; |
| @@ -165,7 +161,7 @@ static void run_window(struct touch_dev *dev, int fd) | |||
| 165 | 161 | ||
| 166 | w.gc = XCreateGC(w.dsp, w.win, 0, NULL); | 162 | w.gc = XCreateGC(w.dsp, w.win, 0, NULL); |
| 167 | 163 | ||
| 168 | event_loop(dev, fd, &w); | 164 | event_loop(fh, dev, fd, &w); |
| 169 | 165 | ||
| 170 | XDestroyWindow(w.dsp, w.win); | 166 | XDestroyWindow(w.dsp, w.win); |
| 171 | XCloseDisplay(w.dsp); | 167 | XCloseDisplay(w.dsp); |
| @@ -173,12 +169,16 @@ static void run_window(struct touch_dev *dev, int fd) | |||
| 173 | 169 | ||
| 174 | int main(int argc, char *argv[]) | 170 | int main(int argc, char *argv[]) |
| 175 | { | 171 | { |
| 176 | struct touch_dev dev; | 172 | struct evemu_device *evemu; |
| 173 | struct mtdev *mtdev; | ||
| 174 | utouch_frame_handle fh; | ||
| 177 | int fd; | 175 | int fd; |
| 176 | |||
| 178 | if (argc < 2) { | 177 | if (argc < 2) { |
| 179 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); | 178 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); |
| 180 | return -1; | 179 | return -1; |
| 181 | } | 180 | } |
| 181 | |||
| 182 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); | 182 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); |
| 183 | if (fd < 0) { | 183 | if (fd < 0) { |
| 184 | fprintf(stderr, "error: could not open device\n"); | 184 | fprintf(stderr, "error: could not open device\n"); |
| @@ -188,13 +188,35 @@ int main(int argc, char *argv[]) | |||
| 188 | fprintf(stderr, "error: could not grab the device\n"); | 188 | fprintf(stderr, "error: could not grab the device\n"); |
| 189 | return -1; | 189 | return -1; |
| 190 | } | 190 | } |
| 191 | if (touch_dev_open(&dev, fd)) { | 191 | |
| 192 | fprintf(stderr, "error: could not open touch device\n"); | 192 | evemu = evemu_new(0); |
| 193 | if (!evemu || evemu_extract(evemu, fd)) { | ||
| 194 | fprintf(stderr, "error: could not describe device\n"); | ||
| 195 | return -1; | ||
| 196 | } | ||
| 197 | if (!utouch_frame_is_supported_mtdev(evemu)) { | ||
| 198 | fprintf(stderr, "error: unsupported device\n"); | ||
| 199 | return -1; | ||
| 200 | } | ||
| 201 | mtdev = mtdev_new_open(fd); | ||
| 202 | if (!mtdev) { | ||
| 203 | fprintf(stderr, "error: could not open mtdev\n"); | ||
| 193 | return -1; | 204 | return -1; |
| 194 | } | 205 | } |
| 195 | run_window(&dev, fd); | 206 | fh = utouch_frame_new_engine(100, 32, 100); |
| 196 | touch_dev_close(&dev, fd); | 207 | if (!fh || utouch_frame_init_mtdev(fh, evemu)) { |
| 208 | fprintf(stderr, "error: could not init frame\n"); | ||
| 209 | return -1; | ||
| 210 | } | ||
| 211 | |||
| 212 | run_window(fh, mtdev, fd); | ||
| 213 | |||
| 214 | utouch_frame_delete_engine(fh); | ||
| 215 | mtdev_close_delete(mtdev); | ||
| 216 | evemu_delete(evemu); | ||
| 217 | |||
| 197 | ioctl(fd, EVIOCGRAB, 0); | 218 | ioctl(fd, EVIOCGRAB, 0); |
| 198 | close(fd); | 219 | close(fd); |
| 220 | |||
| 199 | return 0; | 221 | return 0; |
| 200 | } | 222 | } |
