summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-12-30 20:51:35 +0100
committerHenrik Rydberg <rydberg@euromail.se>2011-01-02 09:18:44 +0100
commit41197333c6779832bd718fa55ed1b17d97e02304 (patch)
treeb907e56978a81305e838e52be366c95f11dcf549 /src
parent4b0f0873f91f7f37106fa39c6b8b5fa74f6a3dcc (diff)
Switch to autotools
To simplify the creation of packages for mtview, swtich to using the autoconf make tools. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src')
-rw-r--r--src/mtview.c222
1 files changed, 0 insertions, 222 deletions
diff --git a/src/mtview.c b/src/mtview.c
deleted file mode 100644
index ea6730c..0000000
--- a/src/mtview.c
+++ /dev/null
@@ -1,222 +0,0 @@
1#include <X11/Xlib.h>
2#include <stdio.h>
3#include <fcntl.h>
4#include <utouch/frame-mtdev.h>
5#include <string.h>
6#include <math.h>
7
8#define XMARG 16
9#define YMARG 16
10#define DEF_FRAC 0.15
11#define DEF_WIDTH 0.05
12
13#define DIM_TOUCH 32
14
15struct windata {
16 Display *dsp;
17 Window root, win;
18 GC gc;
19 int screen, width, height;
20 unsigned long white, black;
21 unsigned long color[DIM_TOUCH];
22 int id[DIM_TOUCH];
23};
24
25static inline float max(float a, float b)
26{
27 return b > a ? b : a;
28}
29
30static unsigned long new_color(struct windata *w)
31{
32 return lrand48() & 0xffffff;
33}
34
35static void clear_screen(struct windata *w)
36{
37 XSetForeground(w->dsp, w->gc, w->black);
38 XFillRectangle(w->dsp, w->win, w->gc, 0, 0, w->width, w->height);
39}
40
41static void output_touch(utouch_frame_handle fh, struct windata *w,
42 const struct utouch_contact *t)
43{
44 const struct utouch_surface *s = utouch_frame_get_surface(fh);
45
46 float x1 = s->min_x, y1 = s->min_y;
47 float x2 = s->max_x, y2 = s->max_y;
48 float dx = x2 - x1, dy = y2 - y1;
49 float major = 0, minor = 0, angle = 0;
50
51 if (s->use_pressure) {
52 float p = DEF_FRAC / s->max_pressure;
53 major = t->pressure * p * dx;
54 minor = t->pressure * p * dx;
55 angle = 0;
56 }
57 if (s->use_touch_major) {
58 major = t->touch_major;
59 minor = t->touch_minor;
60 angle = t->orientation;
61 }
62 if (major == 0 && minor == 0) {
63 major = DEF_WIDTH * dy;
64 minor = DEF_WIDTH * dx;
65 }
66
67 float ac = fabs(cos(angle));
68 float as = fabs(sin(angle));
69 float mx = max(minor * ac, major * as);
70 float my = max(major * ac, minor * as);
71 float ux = t->x - 0.5 * mx;
72 float uy = t->y - 0.5 * my;
73 float vx = t->x + 0.5 * mx;
74 float vy = t->y + 0.5 * my;
75
76 float px = (ux - x1) / dx * w->width;
77 float py = (uy - y1) / dy * w->height;
78 float qx = (vx - x1) / dx * w->width;
79 float qy = (vy - y1) / dy * w->height;
80
81 if (w->id[t->slot] != t->id) {
82 w->id[t->slot] = t->id;
83 w->color[t->slot] = new_color(w);
84 }
85
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);
88 XFlush(w->dsp);
89}
90
91static void report_frame(utouch_frame_handle fh,
92 const struct utouch_frame *frame,
93 struct windata *w)
94{
95 int i;
96
97 for (i = 0; i < frame->num_active; i++)
98 output_touch(fh, w, frame->active[i]);
99}
100
101static void event_loop(utouch_frame_handle fh,
102 struct mtdev *dev, int fd,
103 struct windata *w)
104{
105 const struct utouch_frame *frame;
106 struct input_event iev;
107 XEvent xev;
108
109 XSelectInput(w->dsp, w->win,
110 ButtonPressMask | ButtonReleaseMask |
111 ExposureMask | StructureNotifyMask);
112
113 clear_screen(w);
114 while (1) {
115 while (!mtdev_idle(dev, fd, 100)) {
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 }
122 while (XPending(w->dsp)) {
123 XNextEvent(w->dsp, &xev);
124 }
125 }
126}
127
128static void run_window(utouch_frame_handle fh, struct mtdev *dev, int fd)
129{
130 struct windata w;
131 int i;
132 memset(&w, 0, sizeof(w));
133 for (i = 0; i < DIM_TOUCH; i++)
134 w.id[i] = -1;
135
136 w.dsp = XOpenDisplay(NULL);
137 if (!w.dsp)
138 return;
139
140 w.screen = DefaultScreen(w.dsp);
141 w.white = WhitePixel(w.dsp, w.screen);
142 w.black = BlackPixel(w.dsp, w.screen);
143 w.width = DisplayWidth(w.dsp, w.screen) - XMARG;
144 w.height = DisplayHeight(w.dsp, w.screen) - YMARG;
145
146 w.root = DefaultRootWindow(w.dsp);
147 w.win = XCreateSimpleWindow(w.dsp, w.root,
148 0, 0, w.width, w.height,
149 0, w.black, w.white);
150
151 XMapWindow(w.dsp, w.win);
152
153 long eventMask = StructureNotifyMask;
154 XSelectInput(w.dsp, w.win, eventMask);
155
156 XEvent ev;
157 do {
158 XNextEvent(w.dsp, &ev);
159 } while (ev.type != MapNotify);
160
161
162 w.gc = XCreateGC(w.dsp, w.win, 0, NULL);
163
164 event_loop(fh, dev, fd, &w);
165
166 XDestroyWindow(w.dsp, w.win);
167 XCloseDisplay(w.dsp);
168}
169
170int main(int argc, char *argv[])
171{
172 struct evemu_device *evemu;
173 struct mtdev *mtdev;
174 utouch_frame_handle fh;
175 int fd;
176
177 if (argc < 2) {
178 fprintf(stderr, "Usage: %s <device>\n", argv[0]);
179 return -1;
180 }
181
182 fd = open(argv[1], O_RDONLY | O_NONBLOCK);
183 if (fd < 0) {
184 fprintf(stderr, "error: could not open device\n");
185 return -1;
186 }
187 if (ioctl(fd, EVIOCGRAB, 1)) {
188 fprintf(stderr, "error: could not grab the device\n");
189 return -1;
190 }
191
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");
204 return -1;
205 }
206 fh = utouch_frame_new_engine(100, 32, 100);
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
218 ioctl(fd, EVIOCGRAB, 0);
219 close(fd);
220
221 return 0;
222}