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