summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/capabilities.c87
-rw-r--r--src/capabilities.h27
-rw-r--r--src/common.h34
-rw-r--r--src/multitouch.c125
4 files changed, 149 insertions, 124 deletions
diff --git a/src/capabilities.c b/src/capabilities.c
new file mode 100644
index 0000000..3149131
--- /dev/null
+++ b/src/capabilities.c
@@ -0,0 +1,87 @@
1#include "capabilities.h"
2#include <errno.h>
3
4////////////////////////////////////////////////////////
5
6#define SETABS(c, x, map, key, fd) \
7 c->has_##x = getbit(map, key) && getabs(&c->abs_##x, key, fd)
8
9#define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "")
10
11////////////////////////////////////////////////////////
12
13static const int bits_per_long = 8 * sizeof(long);
14
15static inline int nlongs(int nbit)
16{
17 return (nbit + bits_per_long - 1) / bits_per_long;
18}
19
20static inline bool getbit(const unsigned long* map, int key)
21{
22 return (map[key / bits_per_long] >> (key % bits_per_long)) & 0x01;
23}
24
25static bool getabs(struct input_absinfo *abs, int key, int fd)
26{
27 int rc;
28 SYSCALL(rc = ioctl(fd, EVIOCGABS(key), abs));
29 return rc >= 0;
30}
31
32////////////////////////////////////////////////////////
33
34static int read_capabilities(struct Capabilities *cap, int fd)
35{
36 unsigned long evbits[nlongs(EV_MAX)];
37 unsigned long absbits[nlongs(ABS_MAX)];
38 unsigned long keybits[nlongs(KEY_MAX)];
39 int rc;
40
41 memset(cap, 0, sizeof(struct Capabilities));
42
43 SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_SYN, sizeof(evbits)), evbits));
44 if (rc < 0)
45 return rc;
46 SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits));
47 if (rc < 0)
48 return rc;
49 SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits));
50 if (rc < 0)
51 return rc;
52
53 cap->has_left = getbit(keybits, BTN_LEFT);
54 cap->has_middle = getbit(keybits, BTN_MIDDLE);
55 cap->has_right = getbit(keybits, BTN_RIGHT);
56 cap->has_mtdata = getbit(keybits, BTN_MT_REPORT_PACKET);
57
58 SETABS(cap, touch_major, absbits, ABS_MT_TOUCH_MAJOR, fd);
59 SETABS(cap, touch_minor, absbits, ABS_MT_TOUCH_MINOR, fd);
60 SETABS(cap, width_major, absbits, ABS_MT_WIDTH_MAJOR, fd);
61 SETABS(cap, width_minor, absbits, ABS_MT_WIDTH_MINOR, fd);
62 SETABS(cap, orientation, absbits, ABS_MT_ORIENTATION, fd);
63 SETABS(cap, position_x, absbits, ABS_MT_POSITION_X, fd);
64 SETABS(cap, position_y, absbits, ABS_MT_POSITION_Y, fd);
65}
66
67////////////////////////////////////////////////////////
68
69static int output_capabilities(const struct Capabilities *cap)
70{
71 char line[1024];
72 memset(line, 0, sizeof(line));
73 ADDCAP(line, cap, left);
74 ADDCAP(line, cap, middle);
75 ADDCAP(line, cap, right);
76 ADDCAP(line, cap, mtdata);
77 ADDCAP(line, cap, touch_major);
78 ADDCAP(line, cap, touch_minor);
79 ADDCAP(line, cap, width_major);
80 ADDCAP(line, cap, width_minor);
81 ADDCAP(line, cap, orientation);
82 ADDCAP(line, cap, position_x);
83 ADDCAP(line, cap, position_y);
84 xf86Msg(X_INFO, "multitouch: caps:%s\n", line);
85}
86
87////////////////////////////////////////////////////////
diff --git a/src/capabilities.h b/src/capabilities.h
new file mode 100644
index 0000000..f09a34e
--- /dev/null
+++ b/src/capabilities.h
@@ -0,0 +1,27 @@
1#ifndef CAPABILITIES_H
2#define CAPABILITIES_H
3
4#include "common.h"
5#include <linux/input.h>
6
7////////////////////////////////////////////////////////
8
9struct Capabilities {
10 bool has_left, has_middle;
11 bool has_right, has_mtdata;
12 bool has_touch_major, has_touch_minor;
13 bool has_width_major, has_width_minor;
14 bool has_orientation, has_dummy;
15 bool has_position_x, has_position_y;
16 struct input_absinfo abs_touch_major;
17 struct input_absinfo abs_touch_minor;
18 struct input_absinfo abs_width_major;
19 struct input_absinfo abs_width_minor;
20 struct input_absinfo abs_orientation;
21 struct input_absinfo abs_position_x;
22 struct input_absinfo abs_position_y;
23};
24
25////////////////////////////////////////////////////////
26
27#endif
diff --git a/src/common.h b/src/common.h
new file mode 100644
index 0000000..7aabd7e
--- /dev/null
+++ b/src/common.h
@@ -0,0 +1,34 @@
1#ifndef COMMON_H
2#define COMMON_H
3
4#include "xorg-server.h"
5#include <xf86.h>
6#include <xf86_OSproc.h>
7#include <xf86Xinput.h>
8//#include <exevents.h>
9
10////////////////////////////////////////////////////////
11//#define BTN_MT_REPORT_PACKET 0x210 /* report multitouch packet data */
12//#define BTN_MT_REPORT_FINGER 0x211 /* report multitouch finger data */
13#define BTN_TOOL_PRESS 0x148 /* The trackpad is a physical button */
14#define BTN_MT_REPORT_PACKET 0x14b /* multitouch device */
15#define BTN_MT_REPORT_FINGER 0x14c /* multitouch device */
16#define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */
17
18#define ABS_MT_TOUCH 0x30
19#define ABS_MT_TOUCH_MAJOR 0x30
20#define ABS_MT_TOUCH_MINOR 0x31
21#define ABS_MT_WIDTH 0x32
22#define ABS_MT_WIDTH_MAJOR 0x32
23#define ABS_MT_WIDTH_MINOR 0x33
24#define ABS_MT_ORIENTATION 0x34
25#define ABS_MT_POSITION_X 0x35
26#define ABS_MT_POSITION_Y 0x36
27
28typedef int bool;
29
30#define SYSCALL(call) while (((call) == -1) && (errno == EINTR))
31
32////////////////////////////////////////////////////////
33
34#endif
diff --git a/src/multitouch.c b/src/multitouch.c
index 439155f..6818e7c 100644
--- a/src/multitouch.c
+++ b/src/multitouch.c
@@ -21,132 +21,9 @@
21 * 21 *
22 **************************************************************************/ 22 **************************************************************************/
23 23
24#include "xorg-server.h" 24#include "capabilities.h"
25#include <xf86.h>
26#include <xf86_OSproc.h>
27#include <xf86Xinput.h>
28//#include <exevents.h>
29#include <linux/input.h>
30#include <errno.h>
31 25
32//////////////////////////////////////////////////////////////////////////// 26////////////////////////////////////////////////////////////////////////////
33//#define BTN_MT_REPORT_PACKET 0x210 /* report multitouch packet data */
34//#define BTN_MT_REPORT_FINGER 0x211 /* report multitouch finger data */
35#define BTN_TOOL_PRESS 0x148 /* The trackpad is a physical button */
36#define BTN_MT_REPORT_PACKET 0x14b /* multitouch device */
37#define BTN_MT_REPORT_FINGER 0x14c /* multitouch device */
38#define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */
39
40#define ABS_MT_TOUCH 0x30
41#define ABS_MT_TOUCH_MAJOR 0x30
42#define ABS_MT_TOUCH_MINOR 0x31
43#define ABS_MT_WIDTH 0x32
44#define ABS_MT_WIDTH_MAJOR 0x32
45#define ABS_MT_WIDTH_MINOR 0x33
46#define ABS_MT_ORIENTATION 0x34
47#define ABS_MT_POSITION_X 0x35
48#define ABS_MT_POSITION_Y 0x36
49
50typedef int bool;
51
52////////////////////////////////////////////////////////////////////////////
53
54#define SYSCALL(call) while (((call) == -1) && (errno == EINTR))
55
56static const int bits_per_long = 8 * sizeof(long);
57
58static inline int nlongs(int nbit)
59{
60 return (nbit + bits_per_long - 1) / bits_per_long;
61}
62
63static inline bool getbit(const unsigned long* map, int key)
64{
65 return (map[key / bits_per_long] >> (key % bits_per_long)) & 0x01;
66}
67
68static bool getabs(struct input_absinfo *abs, int key, int fd)
69{
70 int rc;
71 SYSCALL(rc = ioctl(fd, EVIOCGABS(key), abs));
72 return rc >= 0;
73}
74
75#define SETABS(c, x, map, key, fd) \
76 c->has_##x = getbit(map, key) && getabs(&c->abs_##x, key, fd)
77
78#define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "")
79
80////////////////////////////////////////////////////////////////////////////
81
82struct Capabilities {
83 bool has_left, has_middle;
84 bool has_right, has_mtdata;
85 bool has_touch_major, has_touch_minor;
86 bool has_width_major, has_width_minor;
87 bool has_orientation, has_dummy;
88 bool has_position_x, has_position_y;
89 struct input_absinfo abs_touch_major;
90 struct input_absinfo abs_touch_minor;
91 struct input_absinfo abs_width_major;
92 struct input_absinfo abs_width_minor;
93 struct input_absinfo abs_orientation;
94 struct input_absinfo abs_position_x;
95 struct input_absinfo abs_position_y;
96};
97
98////////////////////////////////////////////////////////////////////////////
99
100static int read_capabilities(struct Capabilities *cap, int fd)
101{
102 unsigned long evbits[nlongs(EV_MAX)];
103 unsigned long absbits[nlongs(ABS_MAX)];
104 unsigned long keybits[nlongs(KEY_MAX)];
105 int rc;
106
107 memset(cap, 0, sizeof(struct Capabilities));
108
109 SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_SYN, sizeof(evbits)), evbits));
110 if (rc < 0)
111 return rc;
112 SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits));
113 if (rc < 0)
114 return rc;
115 SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits));
116 if (rc < 0)
117 return rc;
118
119 cap->has_left = getbit(keybits, BTN_LEFT);
120 cap->has_middle = getbit(keybits, BTN_MIDDLE);
121 cap->has_right = getbit(keybits, BTN_RIGHT);
122 cap->has_mtdata = getbit(keybits, BTN_MT_REPORT_PACKET);
123
124 SETABS(cap, touch_major, absbits, ABS_MT_TOUCH_MAJOR, fd);
125 SETABS(cap, touch_minor, absbits, ABS_MT_TOUCH_MINOR, fd);
126 SETABS(cap, width_major, absbits, ABS_MT_WIDTH_MAJOR, fd);
127 SETABS(cap, width_minor, absbits, ABS_MT_WIDTH_MINOR, fd);
128 SETABS(cap, orientation, absbits, ABS_MT_ORIENTATION, fd);
129 SETABS(cap, position_x, absbits, ABS_MT_POSITION_X, fd);
130 SETABS(cap, position_y, absbits, ABS_MT_POSITION_Y, fd);
131}
132
133static int output_capabilities(const struct Capabilities *cap)
134{
135 char line[1024];
136 memset(line, 0, sizeof(line));
137 ADDCAP(line, cap, left);
138 ADDCAP(line, cap, middle);
139 ADDCAP(line, cap, right);
140 ADDCAP(line, cap, mtdata);
141 ADDCAP(line, cap, touch_major);
142 ADDCAP(line, cap, touch_minor);
143 ADDCAP(line, cap, width_major);
144 ADDCAP(line, cap, width_minor);
145 ADDCAP(line, cap, orientation);
146 ADDCAP(line, cap, position_x);
147 ADDCAP(line, cap, position_y);
148 xf86Msg(X_INFO, "multitouch: caps:%s\n", line);
149}
150 27
151static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags) 28static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags)
152{ 29{