chiark / gitweb /
2f455a4af63b314b7ff1e67888959532bac49ac8
[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
27 void xf86Msg(int type, const char *format, ...)
28 {
29         va_list args;
30         va_start(args, format);
31         vfprintf(stderr, format, args);
32         va_end(args);
33 }
34
35 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) <= 13
36 typedef XF86OptionPtr pointer;
37 #endif
38
39 int xf86SetIntOption(XF86OptionPtr opts, const char *name, int deflt)
40 {
41         return deflt;
42 }
43
44 int xf86SetBoolOption(XF86OptionPtr opts, const char *name, int deflt)
45 {
46         return deflt;
47 }
48
49 double xf86SetRealOption(XF86OptionPtr opts, const char *name, double deflt)
50 {
51         return deflt;
52 }
53
54 static void print_gestures(const struct Gestures* gs)
55 {
56         int i;
57         static bitmask_t buttons_prev = 0U;
58         for (i = 0; i < 32; i++) {
59                 if (GETBIT(gs->buttons, i) == GETBIT(buttons_prev, i))
60                         continue;
61
62                 if (GETBIT(gs->buttons, i))
63                         printf("button %d down\n", i+1);
64                 else
65                         printf("button %d up\n", i+1);
66         }
67
68         if (gs->move_dx != 0 || gs->move_dy != 0)
69                 printf("moving (%+4d, %+4d)\n", gs->move_dx, gs->move_dy);
70
71         buttons_prev = gs->buttons;
72 }
73
74 static void loop_device(int fd)
75 {
76         struct MTouch mt;
77         if (mtouch_configure(&mt, fd)) {
78                 fprintf(stderr, "error: could not configure device\n");
79                 return;
80         }
81         if (mtouch_open(&mt, fd)) {
82                 fprintf(stderr, "error: could not open device\n");
83                 return;
84         }
85         
86         mconfig_defaults(&mt.cfg);
87         printf("width:  %d\n", mt.hs.max_x);
88         printf("height: %d\n", mt.hs.max_y);
89
90         //while (!mtdev_idle(&mt.dev, fd, 5000)) {
91         while (1) {
92                 while (mtouch_read(&mt) > 0)
93                         print_gestures(&mt.gs);
94                 if (mtouch_delayed(&mt))
95                         print_gestures(&mt.gs);
96         }
97         mtouch_close(&mt);
98 }
99
100 int main(int argc, char *argv[])
101 {
102         if (argc < 2) {
103                 fprintf(stderr, "Usage: test <mtdev>\n");
104                 return -1;
105         }
106         int fd = open(argv[1], O_RDONLY | O_NONBLOCK);
107         if (fd < 0) {
108                 fprintf(stderr, "error: could not open file\n");
109                 return -1;
110         }
111         loop_device(fd);
112         close(fd);
113         return 0;
114 }