Merge lp:~mtdev-team/mtview/trunk.v1.1.3 into lp:mtview
- trunk.v1.1.3
- Merge into trunk
Proposed by
Henrik Rydberg
Status: | Merged |
---|---|
Merged at revision: | 18 |
Proposed branch: | lp:~mtdev-team/mtview/trunk.v1.1.3 |
Merge into: | lp:mtview |
Diff against target: |
453 lines (+248/-87) 3 files modified
configure.ac (+9/-1) tools/Makefile.am (+8/-0) tools/mtview.c (+231/-86) |
To merge this branch: | bzr merge lp:~mtdev-team/mtview/trunk.v1.1.3 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chase Douglas | Approve | ||
Review via email: mp+50774@code.launchpad.net |
This proposal supersedes a proposal from 2011-02-21.
Commit message
Description of the change
v1.0.2: Reworked mtview with optional XI2.1 support and the ability to draw in multiple windows simultaneously.
v1.0.3: Adjusted api to latest version (February 2011).
To post a comment you must log in.
Revision history for this message
Chase Douglas (chasedouglas) wrote : Posted in a previous version of this proposal | # |
review:
Needs Fixing
Revision history for this message
Henrik Rydberg (rydberg) wrote : Posted in a previous version of this proposal | # |
Like this? (new branch pushed)
Revision history for this message
Henrik Rydberg (rydberg) wrote : | # |
I am going ahead and merging this since the problem is trivially fixed.
Revision history for this message
Chase Douglas (chasedouglas) wrote : | # |
To finish off, yes, this looks good :). I forgot about a dentist appointment, so I had to run!
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'configure.ac' | |||
2 | --- configure.ac 2011-01-03 18:56:34 +0000 | |||
3 | +++ configure.ac 2011-02-22 16:17:18 +0000 | |||
4 | @@ -1,7 +1,7 @@ | |||
5 | 1 | # Initialize Autoconf | 1 | # Initialize Autoconf |
6 | 2 | AC_PREREQ([2.60]) | 2 | AC_PREREQ([2.60]) |
7 | 3 | AC_INIT([Multitouch Viewer], | 3 | AC_INIT([Multitouch Viewer], |
9 | 4 | [1.1.1], | 4 | [1.1.3], |
10 | 5 | [], | 5 | [], |
11 | 6 | [mtview]) | 6 | [mtview]) |
12 | 7 | AC_CONFIG_SRCDIR([Makefile.am]) | 7 | AC_CONFIG_SRCDIR([Makefile.am]) |
13 | @@ -27,6 +27,14 @@ | |||
14 | 27 | PKG_CHECK_MODULES([FRAME], [utouch-frame >= 1.0]) | 27 | PKG_CHECK_MODULES([FRAME], [utouch-frame >= 1.0]) |
15 | 28 | PKG_CHECK_MODULES([X11], [x11]) | 28 | PKG_CHECK_MODULES([X11], [x11]) |
16 | 29 | 29 | ||
17 | 30 | AC_ARG_WITH([xi], AS_HELP_STRING([--with-xi], [Build with XI2.1 support])) | ||
18 | 31 | AM_CONDITIONAL([HAVE_XI], [test "x$with_xi" != "x"]) | ||
19 | 32 | |||
20 | 33 | AS_IF([test "x$with_xi" = "xyes"], [ | ||
21 | 34 | PKG_CHECK_MODULES(XINPUT, x11 xext [xi >= 1.4.1.99.1] [inputproto >= 2.0.99.1]) | ||
22 | 35 | AC_DEFINE([HAVE_XI], [1], [XI2.1 support]) | ||
23 | 36 | ]) | ||
24 | 37 | |||
25 | 30 | AC_CONFIG_FILES([Makefile | 38 | AC_CONFIG_FILES([Makefile |
26 | 31 | tools/Makefile | 39 | tools/Makefile |
27 | 32 | mtview.pc]) | 40 | mtview.pc]) |
28 | 33 | 41 | ||
29 | === modified file 'tools/Makefile.am' | |||
30 | --- tools/Makefile.am 2011-01-02 13:26:14 +0000 | |||
31 | +++ tools/Makefile.am 2011-02-22 16:17:18 +0000 | |||
32 | @@ -4,3 +4,11 @@ | |||
33 | 4 | 4 | ||
34 | 5 | mtview_SOURCES = mtview.c | 5 | mtview_SOURCES = mtview.c |
35 | 6 | mtview_LDFLAGS = -lX11 -lutouch-frame -lutouch-evemu -lmtdev -lm | 6 | mtview_LDFLAGS = -lX11 -lutouch-frame -lutouch-evemu -lmtdev -lm |
36 | 7 | |||
37 | 8 | if HAVE_XI | ||
38 | 9 | |||
39 | 10 | AM_CFLAGS = $(XINPUT_CFLAGS) | ||
40 | 11 | |||
41 | 12 | mtview_LDFLAGS += $(XINPUT_LIBS) | ||
42 | 13 | |||
43 | 14 | endif | ||
44 | 7 | 15 | ||
45 | === modified file 'tools/mtview.c' | |||
46 | --- tools/mtview.c 2011-01-02 13:26:14 +0000 | |||
47 | +++ tools/mtview.c 2011-02-22 16:17:18 +0000 | |||
48 | @@ -1,22 +1,29 @@ | |||
49 | 1 | #include "config.h" | ||
50 | 1 | #include <X11/Xlib.h> | 2 | #include <X11/Xlib.h> |
51 | 2 | #include <stdio.h> | 3 | #include <stdio.h> |
52 | 3 | #include <fcntl.h> | 4 | #include <fcntl.h> |
53 | 4 | #include <utouch/frame-mtdev.h> | 5 | #include <utouch/frame-mtdev.h> |
54 | 6 | #if HAVE_XI | ||
55 | 7 | #include <utouch/frame-xi2.h> | ||
56 | 8 | #endif | ||
57 | 9 | #include <stdlib.h> | ||
58 | 10 | #include <unistd.h> | ||
59 | 5 | #include <string.h> | 11 | #include <string.h> |
60 | 6 | #include <math.h> | 12 | #include <math.h> |
61 | 7 | 13 | ||
62 | 8 | #define XMARG 16 | ||
63 | 9 | #define YMARG 16 | ||
64 | 10 | #define DEF_FRAC 0.15 | 14 | #define DEF_FRAC 0.15 |
65 | 11 | #define DEF_WIDTH 0.05 | 15 | #define DEF_WIDTH 0.05 |
66 | 12 | 16 | ||
67 | 13 | #define DIM_TOUCH 32 | 17 | #define DIM_TOUCH 32 |
68 | 14 | 18 | ||
69 | 19 | static int opcode; | ||
70 | 20 | |||
71 | 15 | struct windata { | 21 | struct windata { |
72 | 16 | Display *dsp; | 22 | Display *dsp; |
74 | 17 | Window root, win; | 23 | Window win; |
75 | 18 | GC gc; | 24 | GC gc; |
77 | 19 | int screen, width, height; | 25 | int screen; |
78 | 26 | float off_x, off_y; | ||
79 | 20 | unsigned long white, black; | 27 | unsigned long white, black; |
80 | 21 | unsigned long color[DIM_TOUCH]; | 28 | unsigned long color[DIM_TOUCH]; |
81 | 22 | int id[DIM_TOUCH]; | 29 | int id[DIM_TOUCH]; |
82 | @@ -32,26 +39,28 @@ | |||
83 | 32 | return lrand48() & 0xffffff; | 39 | return lrand48() & 0xffffff; |
84 | 33 | } | 40 | } |
85 | 34 | 41 | ||
87 | 35 | static void clear_screen(struct windata *w) | 42 | static void clear_screen(utouch_frame_handle fh, struct windata *w) |
88 | 36 | { | 43 | { |
89 | 44 | const struct utouch_surface *s = utouch_frame_get_surface(fh); | ||
90 | 45 | int width = s->mapped_max_x - s->mapped_min_x; | ||
91 | 46 | int height = s->mapped_max_y - s->mapped_min_y; | ||
92 | 47 | |||
93 | 37 | XSetForeground(w->dsp, w->gc, w->black); | 48 | XSetForeground(w->dsp, w->gc, w->black); |
95 | 38 | XFillRectangle(w->dsp, w->win, w->gc, 0, 0, w->width, w->height); | 49 | XFillRectangle(w->dsp, w->win, w->gc, 0, 0, width, height); |
96 | 39 | } | 50 | } |
97 | 40 | 51 | ||
98 | 41 | static void output_touch(utouch_frame_handle fh, struct windata *w, | 52 | static void output_touch(utouch_frame_handle fh, struct windata *w, |
99 | 42 | const struct utouch_contact *t) | 53 | const struct utouch_contact *t) |
100 | 43 | { | 54 | { |
101 | 44 | const struct utouch_surface *s = utouch_frame_get_surface(fh); | 55 | const struct utouch_surface *s = utouch_frame_get_surface(fh); |
106 | 45 | 56 | float dx = s->mapped_max_x - s->mapped_min_x; | |
107 | 46 | float x1 = s->min_x, y1 = s->min_y; | 57 | float dy = s->mapped_max_y - s->mapped_min_y; |
108 | 47 | float x2 = s->max_x, y2 = s->max_y; | 58 | float x = t->x - w->off_x, y = t->y - w->off_y; |
105 | 48 | float dx = x2 - x1, dy = y2 - y1; | ||
109 | 49 | float major = 0, minor = 0, angle = 0; | 59 | float major = 0, minor = 0, angle = 0; |
110 | 50 | 60 | ||
111 | 51 | if (s->use_pressure) { | 61 | if (s->use_pressure) { |
115 | 52 | float p = DEF_FRAC / s->max_pressure; | 62 | major = DEF_FRAC * t->pressure * dy; |
116 | 53 | major = t->pressure * p * dx; | 63 | minor = DEF_FRAC * t->pressure * dx; |
114 | 54 | minor = t->pressure * p * dx; | ||
117 | 55 | angle = 0; | 64 | angle = 0; |
118 | 56 | } | 65 | } |
119 | 57 | if (s->use_touch_major) { | 66 | if (s->use_touch_major) { |
120 | @@ -68,15 +77,6 @@ | |||
121 | 68 | float as = fabs(sin(angle)); | 77 | float as = fabs(sin(angle)); |
122 | 69 | float mx = max(minor * ac, major * as); | 78 | float mx = max(minor * ac, major * as); |
123 | 70 | float my = max(major * ac, minor * as); | 79 | float my = max(major * ac, minor * as); |
124 | 71 | float ux = t->x - 0.5 * mx; | ||
125 | 72 | float uy = t->y - 0.5 * my; | ||
126 | 73 | float vx = t->x + 0.5 * mx; | ||
127 | 74 | float vy = t->y + 0.5 * my; | ||
128 | 75 | |||
129 | 76 | float px = (ux - x1) / dx * w->width; | ||
130 | 77 | float py = (uy - y1) / dy * w->height; | ||
131 | 78 | float qx = (vx - x1) / dx * w->width; | ||
132 | 79 | float qy = (vy - y1) / dy * w->height; | ||
133 | 80 | 80 | ||
134 | 81 | if (w->id[t->slot] != t->id) { | 81 | if (w->id[t->slot] != t->id) { |
135 | 82 | w->id[t->slot] = t->id; | 82 | w->id[t->slot] = t->id; |
136 | @@ -84,7 +84,9 @@ | |||
137 | 84 | } | 84 | } |
138 | 85 | 85 | ||
139 | 86 | XSetForeground(w->dsp, w->gc, w->color[t->slot]); | 86 | XSetForeground(w->dsp, w->gc, w->color[t->slot]); |
141 | 87 | XFillArc(w->dsp, w->win, w->gc, px, py, qx - px, qy - py, 0, 360 * 64); | 87 | |
142 | 88 | XFillArc(w->dsp, w->win, w->gc, x - mx / 2, y - my / 2, | ||
143 | 89 | mx, my, 0, 360 * 64); | ||
144 | 88 | XFlush(w->dsp); | 90 | XFlush(w->dsp); |
145 | 89 | } | 91 | } |
146 | 90 | 92 | ||
147 | @@ -98,88 +100,105 @@ | |||
148 | 98 | output_touch(fh, w, frame->active[i]); | 100 | output_touch(fh, w, frame->active[i]); |
149 | 99 | } | 101 | } |
150 | 100 | 102 | ||
154 | 101 | static void event_loop(utouch_frame_handle fh, | 103 | static int init_window(struct windata *w) |
155 | 102 | struct mtdev *dev, int fd, | 104 | { |
156 | 103 | struct windata *w) | 105 | int event, err; |
157 | 106 | int i; | ||
158 | 107 | |||
159 | 108 | memset(w, 0, sizeof(w)); | ||
160 | 109 | for (i = 0; i < DIM_TOUCH; i++) | ||
161 | 110 | w->id[i] = -1; | ||
162 | 111 | |||
163 | 112 | w->dsp = XOpenDisplay(NULL); | ||
164 | 113 | if (!w->dsp) | ||
165 | 114 | return -1; | ||
166 | 115 | if (!XQueryExtension(w->dsp, "XInputExtension", &opcode, &event, &err)) | ||
167 | 116 | return -1; | ||
168 | 117 | |||
169 | 118 | w->screen = DefaultScreen(w->dsp); | ||
170 | 119 | w->white = WhitePixel(w->dsp, w->screen); | ||
171 | 120 | w->black = BlackPixel(w->dsp, w->screen); | ||
172 | 121 | |||
173 | 122 | w->win = XCreateSimpleWindow(w->dsp, XDefaultRootWindow(w->dsp), | ||
174 | 123 | 0, 0, 200, 200, 0, w->black, w->white); | ||
175 | 124 | w->gc = DefaultGC(w->dsp, w->screen); | ||
176 | 125 | |||
177 | 126 | XMapWindow(w->dsp, w->win); | ||
178 | 127 | XFlush(w->dsp); | ||
179 | 128 | |||
180 | 129 | return 0; | ||
181 | 130 | } | ||
182 | 131 | |||
183 | 132 | static void term_window(struct windata *w) | ||
184 | 133 | { | ||
185 | 134 | XDestroyWindow(w->dsp, w->win); | ||
186 | 135 | XCloseDisplay(w->dsp); | ||
187 | 136 | } | ||
188 | 137 | |||
189 | 138 | static void set_screen_size_mtdev(utouch_frame_handle fh, | ||
190 | 139 | struct windata *w, | ||
191 | 140 | XEvent *xev) | ||
192 | 141 | { | ||
193 | 142 | struct utouch_surface *s = utouch_frame_get_surface(fh); | ||
194 | 143 | XConfigureEvent *cev = (XConfigureEvent *)xev; | ||
195 | 144 | |||
196 | 145 | s->mapped_min_x = 0; | ||
197 | 146 | s->mapped_min_y = 0; | ||
198 | 147 | s->mapped_max_x = DisplayWidth(w->dsp, w->screen); | ||
199 | 148 | s->mapped_max_y = DisplayHeight(w->dsp, w->screen); | ||
200 | 149 | s->mapped_max_pressure = 1; | ||
201 | 150 | |||
202 | 151 | if (cev) { | ||
203 | 152 | w->off_x = cev->x; | ||
204 | 153 | w->off_y = cev->y; | ||
205 | 154 | } | ||
206 | 155 | |||
207 | 156 | fprintf(stderr, "map: %f %f %f %f %f %f\n", | ||
208 | 157 | w->off_x, w->off_y, | ||
209 | 158 | s->mapped_min_x, s->mapped_min_y, | ||
210 | 159 | s->mapped_max_x, s->mapped_max_y); | ||
211 | 160 | } | ||
212 | 161 | |||
213 | 162 | static void run_window_mtdev(utouch_frame_handle fh, struct mtdev *dev, int fd) | ||
214 | 104 | { | 163 | { |
215 | 105 | const struct utouch_frame *frame; | 164 | const struct utouch_frame *frame; |
216 | 106 | struct input_event iev; | 165 | struct input_event iev; |
217 | 166 | struct windata w; | ||
218 | 107 | XEvent xev; | 167 | XEvent xev; |
219 | 108 | 168 | ||
225 | 109 | XSelectInput(w->dsp, w->win, | 169 | if (init_window(&w)) |
226 | 110 | ButtonPressMask | ButtonReleaseMask | | 170 | return; |
227 | 111 | ExposureMask | StructureNotifyMask); | 171 | |
228 | 112 | 172 | clear_screen(fh, &w); | |
229 | 113 | clear_screen(w); | 173 | |
230 | 174 | set_screen_size_mtdev(fh, &w, 0); | ||
231 | 175 | XSelectInput(w.dsp, w.win, StructureNotifyMask); | ||
232 | 176 | |||
233 | 114 | while (1) { | 177 | while (1) { |
234 | 115 | while (!mtdev_idle(dev, fd, 100)) { | 178 | while (!mtdev_idle(dev, fd, 100)) { |
235 | 116 | while (mtdev_get(dev, fd, &iev, 1) > 0) { | 179 | while (mtdev_get(dev, fd, &iev, 1) > 0) { |
236 | 117 | frame = utouch_frame_pump_mtdev(fh, &iev); | 180 | frame = utouch_frame_pump_mtdev(fh, &iev); |
237 | 118 | if (frame) | 181 | if (frame) |
239 | 119 | report_frame(fh, frame, w); | 182 | report_frame(fh, frame, &w); |
240 | 120 | } | 183 | } |
241 | 121 | } | 184 | } |
244 | 122 | while (XPending(w->dsp)) { | 185 | while (XPending(w.dsp)) { |
245 | 123 | XNextEvent(w->dsp, &xev); | 186 | XNextEvent(w.dsp, &xev); |
246 | 187 | set_screen_size_mtdev(fh, &w, &xev); | ||
247 | 124 | } | 188 | } |
248 | 125 | } | 189 | } |
294 | 126 | } | 190 | |
295 | 127 | 191 | term_window(&w); | |
296 | 128 | static void run_window(utouch_frame_handle fh, struct mtdev *dev, int fd) | 192 | } |
297 | 129 | { | 193 | |
298 | 130 | struct windata w; | 194 | static int run_mtdev(const char *name) |
254 | 131 | int i; | ||
255 | 132 | memset(&w, 0, sizeof(w)); | ||
256 | 133 | for (i = 0; i < DIM_TOUCH; i++) | ||
257 | 134 | w.id[i] = -1; | ||
258 | 135 | |||
259 | 136 | w.dsp = XOpenDisplay(NULL); | ||
260 | 137 | if (!w.dsp) | ||
261 | 138 | return; | ||
262 | 139 | |||
263 | 140 | w.screen = DefaultScreen(w.dsp); | ||
264 | 141 | w.white = WhitePixel(w.dsp, w.screen); | ||
265 | 142 | w.black = BlackPixel(w.dsp, w.screen); | ||
266 | 143 | w.width = DisplayWidth(w.dsp, w.screen) - XMARG; | ||
267 | 144 | w.height = DisplayHeight(w.dsp, w.screen) - YMARG; | ||
268 | 145 | |||
269 | 146 | w.root = DefaultRootWindow(w.dsp); | ||
270 | 147 | w.win = XCreateSimpleWindow(w.dsp, w.root, | ||
271 | 148 | 0, 0, w.width, w.height, | ||
272 | 149 | 0, w.black, w.white); | ||
273 | 150 | |||
274 | 151 | XMapWindow(w.dsp, w.win); | ||
275 | 152 | |||
276 | 153 | long eventMask = StructureNotifyMask; | ||
277 | 154 | XSelectInput(w.dsp, w.win, eventMask); | ||
278 | 155 | |||
279 | 156 | XEvent ev; | ||
280 | 157 | do { | ||
281 | 158 | XNextEvent(w.dsp, &ev); | ||
282 | 159 | } while (ev.type != MapNotify); | ||
283 | 160 | |||
284 | 161 | |||
285 | 162 | w.gc = XCreateGC(w.dsp, w.win, 0, NULL); | ||
286 | 163 | |||
287 | 164 | event_loop(fh, dev, fd, &w); | ||
288 | 165 | |||
289 | 166 | XDestroyWindow(w.dsp, w.win); | ||
290 | 167 | XCloseDisplay(w.dsp); | ||
291 | 168 | } | ||
292 | 169 | |||
293 | 170 | int main(int argc, char *argv[]) | ||
299 | 171 | { | 195 | { |
300 | 172 | struct evemu_device *evemu; | 196 | struct evemu_device *evemu; |
301 | 173 | struct mtdev *mtdev; | 197 | struct mtdev *mtdev; |
302 | 174 | utouch_frame_handle fh; | 198 | utouch_frame_handle fh; |
303 | 175 | int fd; | 199 | int fd; |
304 | 176 | 200 | ||
311 | 177 | if (argc < 2) { | 201 | fd = open(name, O_RDONLY | O_NONBLOCK); |
306 | 178 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); | ||
307 | 179 | return -1; | ||
308 | 180 | } | ||
309 | 181 | |||
310 | 182 | fd = open(argv[1], O_RDONLY | O_NONBLOCK); | ||
312 | 183 | if (fd < 0) { | 202 | if (fd < 0) { |
313 | 184 | fprintf(stderr, "error: could not open device\n"); | 203 | fprintf(stderr, "error: could not open device\n"); |
314 | 185 | return -1; | 204 | return -1; |
315 | @@ -209,7 +228,7 @@ | |||
316 | 209 | return -1; | 228 | return -1; |
317 | 210 | } | 229 | } |
318 | 211 | 230 | ||
320 | 212 | run_window(fh, mtdev, fd); | 231 | run_window_mtdev(fh, mtdev, fd); |
321 | 213 | 232 | ||
322 | 214 | utouch_frame_delete_engine(fh); | 233 | utouch_frame_delete_engine(fh); |
323 | 215 | mtdev_close_delete(mtdev); | 234 | mtdev_close_delete(mtdev); |
324 | @@ -220,3 +239,129 @@ | |||
325 | 220 | 239 | ||
326 | 221 | return 0; | 240 | return 0; |
327 | 222 | } | 241 | } |
328 | 242 | |||
329 | 243 | #if HAVE_XI | ||
330 | 244 | static void handle_event_xi2(struct windata *w, | ||
331 | 245 | utouch_frame_handle fh, | ||
332 | 246 | XEvent *ev) | ||
333 | 247 | { | ||
334 | 248 | XConfigureEvent *cev = (XConfigureEvent *)ev; | ||
335 | 249 | XGenericEventCookie *gev = &ev->xcookie; | ||
336 | 250 | const struct utouch_frame *frame; | ||
337 | 251 | |||
338 | 252 | switch(ev->type) { | ||
339 | 253 | case ConfigureNotify: | ||
340 | 254 | if (cev->window == XDefaultRootWindow(cev->display)) { | ||
341 | 255 | utouch_frame_configure_xi2(fh, cev); | ||
342 | 256 | } else { | ||
343 | 257 | w->off_x = cev->x; | ||
344 | 258 | w->off_y = cev->y; | ||
345 | 259 | } | ||
346 | 260 | break; | ||
347 | 261 | case GenericEvent: | ||
348 | 262 | if (!XGetEventData(w->dsp, gev)) | ||
349 | 263 | break; | ||
350 | 264 | if (gev->type == GenericEvent && gev->extension == opcode) { | ||
351 | 265 | frame = utouch_frame_pump_xi2(fh, gev->data); | ||
352 | 266 | if (frame) | ||
353 | 267 | report_frame(fh, frame, w); | ||
354 | 268 | } | ||
355 | 269 | XFreeEventData(w->dsp, gev); | ||
356 | 270 | break; | ||
357 | 271 | } | ||
358 | 272 | } | ||
359 | 273 | |||
360 | 274 | static void run_window_xi2(struct windata *w, | ||
361 | 275 | utouch_frame_handle fh, | ||
362 | 276 | XIDeviceInfo *dev) | ||
363 | 277 | { | ||
364 | 278 | const struct utouch_frame *frame; | ||
365 | 279 | XIEventMask mask; | ||
366 | 280 | |||
367 | 281 | fprintf(stderr, "xi2 running\n"); | ||
368 | 282 | |||
369 | 283 | XSelectInput(w->dsp, w->win, StructureNotifyMask); | ||
370 | 284 | XSelectInput(w->dsp, XDefaultRootWindow(w->dsp), StructureNotifyMask); | ||
371 | 285 | |||
372 | 286 | mask.deviceid = dev->deviceid; | ||
373 | 287 | mask.mask_len = XIMaskLen(XI_LASTEVENT); | ||
374 | 288 | mask.mask = calloc(mask.mask_len, sizeof(char)); | ||
375 | 289 | |||
376 | 290 | XISetMask(mask.mask, XI_PropertyEvent); | ||
377 | 291 | XISetMask(mask.mask, XI_TouchBegin); | ||
378 | 292 | XISetMask(mask.mask, XI_TouchUpdate); | ||
379 | 293 | XISetMask(mask.mask, XI_TouchEnd); | ||
380 | 294 | XISelectEvents(w->dsp, w->win, &mask, 1); | ||
381 | 295 | |||
382 | 296 | while (1) { | ||
383 | 297 | XEvent ev; | ||
384 | 298 | XNextEvent(w->dsp, &ev); | ||
385 | 299 | handle_event_xi2(w, fh, &ev); | ||
386 | 300 | } | ||
387 | 301 | } | ||
388 | 302 | |||
389 | 303 | static int run_xi2(int id) | ||
390 | 304 | { | ||
391 | 305 | struct windata w; | ||
392 | 306 | XIDeviceInfo *info, *dev; | ||
393 | 307 | utouch_frame_handle fh; | ||
394 | 308 | int ndevice; | ||
395 | 309 | int i; | ||
396 | 310 | |||
397 | 311 | if (init_window(&w)) { | ||
398 | 312 | fprintf(stderr, "error: could not init window\n"); | ||
399 | 313 | return -1; | ||
400 | 314 | } | ||
401 | 315 | |||
402 | 316 | info = XIQueryDevice(w.dsp, XIAllDevices, &ndevice); | ||
403 | 317 | dev = 0; | ||
404 | 318 | for (i = 0; i < ndevice; i++) | ||
405 | 319 | if (info[i].deviceid == id) | ||
406 | 320 | dev = &info[i]; | ||
407 | 321 | if (!dev) | ||
408 | 322 | return -1; | ||
409 | 323 | |||
410 | 324 | if (!utouch_frame_is_supported_xi2(w.dsp, dev)) { | ||
411 | 325 | fprintf(stderr, "error: unsupported device\n"); | ||
412 | 326 | return -1; | ||
413 | 327 | } | ||
414 | 328 | |||
415 | 329 | fh = utouch_frame_new_engine(100, 32, 100); | ||
416 | 330 | if (!fh || utouch_frame_init_xi2(fh, w.dsp, dev)) { | ||
417 | 331 | fprintf(stderr, "error: could not init frame\n"); | ||
418 | 332 | return -1; | ||
419 | 333 | } | ||
420 | 334 | |||
421 | 335 | run_window_xi2(&w, fh, dev); | ||
422 | 336 | |||
423 | 337 | utouch_frame_delete_engine(fh); | ||
424 | 338 | XIFreeDeviceInfo(info); | ||
425 | 339 | term_window(&w); | ||
426 | 340 | |||
427 | 341 | return 0; | ||
428 | 342 | } | ||
429 | 343 | #else | ||
430 | 344 | static int run_xi2(int id) | ||
431 | 345 | { | ||
432 | 346 | fprintf(stderr, "XI2.1 not supported\n"); | ||
433 | 347 | return 0; | ||
434 | 348 | } | ||
435 | 349 | #endif | ||
436 | 350 | |||
437 | 351 | int main(int argc, char *argv[]) | ||
438 | 352 | { | ||
439 | 353 | int id, ret; | ||
440 | 354 | |||
441 | 355 | if (argc < 2) { | ||
442 | 356 | fprintf(stderr, "Usage: %s <device>\n", argv[0]); | ||
443 | 357 | return -1; | ||
444 | 358 | } | ||
445 | 359 | |||
446 | 360 | id = atoi(argv[1]); | ||
447 | 361 | if (id) | ||
448 | 362 | ret = run_xi2(id); | ||
449 | 363 | else | ||
450 | 364 | ret = run_mtdev(argv[1]); | ||
451 | 365 | |||
452 | 366 | return ret; | ||
453 | 367 | } |
Looks fine except that configure.ac needs to be fixed up the same way as utouch-frame was fixed.