chiark / gitweb /
Offsets: In button zone code, cope with negative "pos" values
[xf86-input-mtrack.git] / tools / mtrack-test.c
1 /***************************************************************************
2  *
3  * Multitouch X driver
4  * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
5  * Copyright (C) 2011 Ryan Bourgeois <bluedragonx@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  *
21  **************************************************************************/
22
23 #include "mtouch.h"
24 #include <fcntl.h>
25 #include <stdarg.h>
26 #include <unistd.h>
27
28 void xf86Msg(int type, const char *format, ...)
29 {
30         va_list args;
31         va_start(args, format);
32         vfprintf(stderr, format, args);
33         va_end(args);
34 }
35
36 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) <= 13
37 typedef XF86OptionPtr pointer;
38 #endif
39
40 int xf86SetIntOption(XF86OptionPtr opts, const char *name, int deflt)
41 {
42         return deflt;
43 }
44
45 int xf86SetBoolOption(XF86OptionPtr opts, const char *name, int deflt)
46 {
47         return deflt;
48 }
49
50 double xf86SetRealOption(XF86OptionPtr opts, const char *name, double deflt)
51 {
52         return deflt;
53 }
54
55 static void print_gestures(const struct Gestures* gs)
56 {
57         int i;
58         static bitmask_t buttons_prev = 0U;
59         for (i = 0; i < 32; i++) {
60                 if (GETBIT(gs->buttons, i) == GETBIT(buttons_prev, i))
61                         continue;
62
63                 if (GETBIT(gs->buttons, i))
64                         printf("button %d down\n", i+1);
65                 else
66                         printf("button %d up\n", i+1);
67         }
68
69         if (gs->move_dx != 0 || gs->move_dy != 0)
70                 printf("moving (%+4d, %+4d)\n", gs->move_dx, gs->move_dy);
71
72         buttons_prev = gs->buttons;
73 }
74
75 static void loop_device(int fd)
76 {
77         struct MTouch mt;
78         if (mtouch_configure(&mt, fd)) {
79                 fprintf(stderr, "error: could not configure device\n");
80                 return;
81         }
82         if (mtouch_open(&mt, fd)) {
83                 fprintf(stderr, "error: could not open device\n");
84                 return;
85         }
86         
87         mconfig_defaults(&mt.cfg);
88         printf("width:  %d\n", mt.hs.max_x);
89         printf("height: %d\n", mt.hs.max_y);
90
91         //while (!mtdev_idle(&mt.dev, fd, 5000)) {
92         while (1) {
93                 while (mtouch_read(&mt) > 0)
94                         print_gestures(&mt.gs);
95                 if (mtouch_delayed(&mt))
96                         print_gestures(&mt.gs);
97         }
98         mtouch_close(&mt);
99 }
100
101 int main(int argc, char *argv[])
102 {
103         if (argc < 2) {
104                 fprintf(stderr, "Usage: test <mtdev>\n");
105                 return -1;
106         }
107         int fd = open(argv[1], O_RDONLY | O_NONBLOCK);
108         if (fd < 0) {
109                 fprintf(stderr, "error: could not open file\n");
110                 return -1;
111         }
112         loop_device(fd);
113         close(fd);
114         return 0;
115 }