summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/capabilities.c171
-rw-r--r--src/hwstate.c24
-rw-r--r--src/memory.c4
-rw-r--r--src/mtouch.c32
-rw-r--r--src/mtstate.c14
-rw-r--r--src/test.c4
6 files changed, 203 insertions, 46 deletions
diff --git a/src/capabilities.c b/src/capabilities.c
new file mode 100644
index 0000000..0d11669
--- /dev/null
+++ b/src/capabilities.c
@@ -0,0 +1,171 @@
1/***************************************************************************
2 *
3 * Multitouch X driver
4 * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 **************************************************************************/
21
22#include "capabilities.h"
23
24#define SETABS(c, x, map, key, fd) \
25 (c->has_##x = getbit(map, key) && getabs(&c->x, key, fd))
26
27#define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "")
28
29static const int SN_COORD = 250; /* coordinate signal-to-noise ratio */
30static const int SN_WIDTH = 100; /* width signal-to-noise ratio */
31static const int SN_ORIENT = 10; /* orientation signal-to-noise ratio */
32
33static const int bits_per_long = 8 * sizeof(long);
34
35static inline int nlongs(int nbit)
36{
37 return (nbit + bits_per_long - 1) / bits_per_long;
38}
39
40static inline int getbit(const unsigned long *map, int key)
41{
42 return (map[key / bits_per_long] >> (key % bits_per_long)) & 0x01;
43}
44
45static int getabs(struct input_absinfo *abs, int key, int fd)
46{
47 int rc;
48 SYSCALL(rc = ioctl(fd, EVIOCGABS(key), abs));
49 return rc >= 0;
50}
51
52static int has_mt_data(const struct Capabilities *cap)
53{
54 return cap->has_abs[MTDEV_POSITION_X] && cap->has_abs[MTDEV_POSITION_Y];
55}
56
57static int has_integrated_button(const struct Capabilities *cap)
58{
59 static const int bcm5974_vmask_ibt = 1;
60 if (strcmp(cap->devname, "bcm5974"))
61 return 0;
62 return cap->devid.version & bcm5974_vmask_ibt;
63}
64
65static void default_fuzz(struct Capabilities *cap, unsigned int code, int sn)
66{
67 int bit = mtdev_abs2mt(code);
68 if (cap->has_abs[bit] && cap->abs[bit].fuzz == 0)
69 cap->abs[bit].fuzz =
70 (cap->abs[bit].maximum - cap->abs[bit].minimum) / sn;
71}
72
73int read_capabilities(struct Capabilities *cap, int fd)
74{
75 unsigned long evbits[nlongs(EV_MAX)];
76 unsigned long absbits[nlongs(ABS_MAX)];
77 unsigned long keybits[nlongs(KEY_MAX)];
78 int rc, i;
79
80 memset(cap, 0, sizeof(struct Capabilities));
81
82 SYSCALL(rc = ioctl(fd, EVIOCGID, &cap->devid));
83 if (rc < 0)
84 return rc;
85 SYSCALL(rc = ioctl(fd, EVIOCGNAME(sizeof(cap->devname)), cap->devname));
86 if (rc < 0)
87 return rc;
88 SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_SYN, sizeof(evbits)), evbits));
89 if (rc < 0)
90 return rc;
91 SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits));
92 if (rc < 0)
93 return rc;
94 SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits));
95 if (rc < 0)
96 return rc;
97
98 cap->has_left = getbit(keybits, BTN_LEFT);
99 cap->has_middle = getbit(keybits, BTN_MIDDLE);
100 cap->has_right = getbit(keybits, BTN_RIGHT);
101
102 SETABS(cap, slot, absbits, ABS_MT_SLOT, fd);
103 for (i = 0; i < MT_ABS_SIZE; i++)
104 SETABS(cap, abs[i], absbits, mtdev_mt2abs(i), fd);
105
106 cap->has_mtdata = has_mt_data(cap);
107 cap->has_ibt = has_integrated_button(cap);
108
109 default_fuzz(cap, ABS_MT_POSITION_X, SN_COORD);
110 default_fuzz(cap, ABS_MT_POSITION_Y, SN_COORD);
111 default_fuzz(cap, ABS_MT_TOUCH_MAJOR, SN_WIDTH);
112 default_fuzz(cap, ABS_MT_TOUCH_MINOR, SN_WIDTH);
113 default_fuzz(cap, ABS_MT_WIDTH_MAJOR, SN_WIDTH);
114 default_fuzz(cap, ABS_MT_WIDTH_MINOR, SN_WIDTH);
115 default_fuzz(cap, ABS_MT_ORIENTATION, SN_ORIENT);
116
117 return 0;
118}
119
120int get_cap_xsize(const struct Capabilities *cap)
121{
122 const struct input_absinfo *x = &cap->abs[MTDEV_POSITION_X];
123 return x->maximum - x->minimum;
124}
125
126int get_cap_ysize(const struct Capabilities *cap)
127{
128 const struct input_absinfo *y = &cap->abs[MTDEV_POSITION_Y];
129 return y->maximum - y->minimum;
130}
131
132int get_cap_wsize(const struct Capabilities *cap)
133{
134 const struct input_absinfo *w = &cap->abs[MTDEV_TOUCH_MAJOR];
135 return w->maximum - w->minimum;
136}
137
138int get_cap_xmid(const struct Capabilities *cap)
139{
140 const struct input_absinfo *x = &cap->abs[MTDEV_POSITION_X];
141 return (x->maximum + x->minimum) >> 1;
142}
143
144int get_cap_ymid(const struct Capabilities *cap)
145{
146 const struct input_absinfo *y = &cap->abs[MTDEV_POSITION_Y];
147 return (y->maximum + y->minimum) >> 1;
148}
149
150void output_capabilities(const struct Capabilities *cap)
151{
152 char line[1024];
153 int i;
154 memset(line, 0, sizeof(line));
155 ADDCAP(line, cap, left);
156 ADDCAP(line, cap, middle);
157 ADDCAP(line, cap, right);
158 ADDCAP(line, cap, mtdata);
159 ADDCAP(line, cap, ibt);
160 xf86Msg(X_INFO, "multitouch: devname: %s\n", cap->devname);
161 xf86Msg(X_INFO, "multitouch: devid: %x %x %x\n",
162 cap->devid.vendor, cap->devid.product, cap->devid.version);
163 xf86Msg(X_INFO, "multitouch: caps:%s\n", line);
164 for (i = 0; i < MT_ABS_SIZE; i++) {
165 if (cap->has_abs[i])
166 xf86Msg(X_INFO, "multitouch: %d: min: %d max: %d\n",
167 i,
168 cap->abs[i].minimum,
169 cap->abs[i].maximum);
170 }
171}
diff --git a/src/hwstate.c b/src/hwstate.c
index 82a3a10..076efa1 100644
--- a/src/hwstate.c
+++ b/src/hwstate.c
@@ -26,7 +26,7 @@ void init_hwstate(struct HWState *s, const struct Capabilities *caps)
26 int i; 26 int i;
27 memset(s, 0, sizeof(struct HWState)); 27 memset(s, 0, sizeof(struct HWState));
28 for (i = 0; i < DIM_FINGER; i++) 28 for (i = 0; i < DIM_FINGER; i++)
29 s->data[i].tracking_id = caps->nullid; 29 s->data[i].tracking_id = MT_ID_NULL;
30} 30}
31 31
32static void finish_packet(struct HWState *s, const struct Capabilities *caps, 32static void finish_packet(struct HWState *s, const struct Capabilities *caps,
@@ -35,16 +35,16 @@ static void finish_packet(struct HWState *s, const struct Capabilities *caps,
35 static const mstime_t ms = 1000; 35 static const mstime_t ms = 1000;
36 int i; 36 int i;
37 foreach_bit(i, s->used) { 37 foreach_bit(i, s->used) {
38 if (!caps->has_abs[BIT_TOUCH_MINOR]) 38 if (!caps->has_abs[MTDEV_TOUCH_MINOR])
39 s->data[i].touch_minor = s->data[i].touch_major; 39 s->data[i].touch_minor = s->data[i].touch_major;
40 if (!caps->has_abs[BIT_WIDTH_MINOR]) 40 if (!caps->has_abs[MTDEV_WIDTH_MINOR])
41 s->data[i].width_minor = s->data[i].width_major; 41 s->data[i].width_minor = s->data[i].width_major;
42 } 42 }
43 s->evtime = syn->time.tv_usec / ms + syn->time.tv_sec * ms; 43 s->evtime = syn->time.tv_usec / ms + syn->time.tv_sec * ms;
44} 44}
45 45
46int hwstate_read(struct HWState *s, const struct Capabilities *caps, 46static int read_event(struct HWState *s, const struct Capabilities *caps,
47 const struct input_event *ev) 47 const struct input_event *ev)
48{ 48{
49 switch (ev->type) { 49 switch (ev->type) {
50 case EV_SYN: 50 case EV_SYN:
@@ -99,11 +99,21 @@ int hwstate_read(struct HWState *s, const struct Capabilities *caps,
99 break; 99 break;
100 case ABS_MT_TRACKING_ID: 100 case ABS_MT_TRACKING_ID:
101 s->data[s->slot].tracking_id = ev->value; 101 s->data[s->slot].tracking_id = ev->value;
102 MODBIT(s->used, s->slot, 102 MODBIT(s->used, s->slot, ev->value != MT_ID_NULL);
103 ev->value != caps->nullid);
104 break; 103 break;
105 } 104 }
106 break; 105 break;
107 } 106 }
108 return 0; 107 return 0;
109} 108}
109
110int modify_hwstate(struct HWState *s, struct mtdev *dev, int fd,
111 const struct Capabilities *caps)
112{
113 struct input_event ev;
114 int ret;
115 while ((ret = mtdev_get(dev, fd, &ev, 1)) > 0)
116 if (read_event(s, caps, &ev))
117 return 1;
118 return ret;
119}
diff --git a/src/memory.c b/src/memory.c
index 974a531..63134ca 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -119,13 +119,13 @@ static void update_pointers(struct Memory *m,
119 const struct Capabilities *caps) 119 const struct Capabilities *caps)
120{ 120{
121 const struct FingerState *f = state->finger; 121 const struct FingerState *f = state->finger;
122 int yclick = caps->abs[BIT_POSITION_Y].maximum - CLICK_AREA(caps); 122 int yclick = caps->abs[MTDEV_POSITION_Y].maximum - CLICK_AREA(caps);
123 123
124 int i; 124 int i;
125 125
126 if (state->nfinger < 2) { 126 if (state->nfinger < 2) {
127 m->pointing = m->fingers; 127 m->pointing = m->fingers;
128 m->ybar = caps->abs[BIT_POSITION_Y].maximum; 128 m->ybar = caps->abs[MTDEV_POSITION_Y].maximum;
129 return; 129 return;
130 } 130 }
131 131
diff --git a/src/mtouch.c b/src/mtouch.c
index f7a2710..e2d9572 100644
--- a/src/mtouch.c
+++ b/src/mtouch.c
@@ -34,8 +34,7 @@ int configure_mtouch(struct MTouch *mt, int fd)
34 34
35int open_mtouch(struct MTouch *mt, int fd) 35int open_mtouch(struct MTouch *mt, int fd)
36{ 36{
37 mtdev_init(&mt->dev, &mt->caps); 37 mtdev_open(&mt->dev, fd);
38 init_iobuf(&mt->buf);
39 init_hwstate(&mt->hs, &mt->caps); 38 init_hwstate(&mt->hs, &mt->caps);
40 init_mtstate(&mt->prev_state); 39 init_mtstate(&mt->prev_state);
41 init_mtstate(&mt->state); 40 init_mtstate(&mt->state);
@@ -48,40 +47,19 @@ int open_mtouch(struct MTouch *mt, int fd)
48 return 0; 47 return 0;
49} 48}
50 49
51
52int get_mtouch(struct MTouch *mt, int fd, struct input_event* ev, int ev_max)
53{
54 const struct input_event *kev;
55 int count = 0;
56 while (count < ev_max) {
57 while (mtdev_empty(&mt->dev)) {
58 kev = get_iobuf_event(&mt->buf, fd);
59 if (!kev)
60 return count;
61 mtdev_put(&mt->dev, &mt->caps, kev);
62 }
63 mtdev_get(&mt->dev, &ev[count++]);
64 }
65 return count;
66}
67
68int close_mtouch(struct MTouch *mt, int fd) 50int close_mtouch(struct MTouch *mt, int fd)
69{ 51{
70 if (use_grab) { 52 if (use_grab) {
71 int rc; 53 int rc;
72 SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)0)); 54 SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)0));
73 } 55 }
74 mtdev_destroy(&mt->dev); 56 mtdev_close(&mt->dev);
75 return 0; 57 return 0;
76} 58}
77 59
78int read_packet(struct MTouch *mt, int fd) 60int read_packet(struct MTouch *mt, int fd)
79{ 61{
80 struct input_event ev; 62 int ret = modify_hwstate(&mt->hs, &mt->dev, fd, &mt->caps);
81 int ret;
82 while ((ret = get_mtouch(mt, fd, &ev, 1)) > 0)
83 if (hwstate_read(&mt->hs, &mt->caps, &ev))
84 break;
85 if (ret <= 0) 63 if (ret <= 0)
86 return ret; 64 return ret;
87 extract_mtstate(&mt->state, &mt->hs, &mt->caps); 65 extract_mtstate(&mt->state, &mt->hs, &mt->caps);
@@ -97,7 +75,5 @@ int read_packet(struct MTouch *mt, int fd)
97 75
98int has_delayed_gestures(struct MTouch *mt, int fd) 76int has_delayed_gestures(struct MTouch *mt, int fd)
99{ 77{
100 return mt->mem.wait && 78 return mt->mem.wait && mtdev_idle(&mt->dev, fd, mt->mem.wait);
101 mtdev_empty(&mt->dev) &&
102 poll_iobuf(&mt->buf, fd, mt->mem.wait) == 0;
103} 79}
diff --git a/src/mtstate.c b/src/mtstate.c
index 7a8ef19..4c893a2 100644
--- a/src/mtstate.c
+++ b/src/mtstate.c
@@ -22,7 +22,7 @@
22#include "mtstate.h" 22#include "mtstate.h"
23 23
24#define TOUCH_WIDTH(hw) (0.05 * hw->width_major) 24#define TOUCH_WIDTH(hw) (0.05 * hw->width_major)
25#define TOUCH_SCALE(caps) (0.05 * caps->abs[BIT_TOUCH_MAJOR].maximum) 25#define TOUCH_SCALE(caps) (0.05 * caps->abs[MTDEV_TOUCH_MAJOR].maximum)
26 26
27#define THUMB_TOUCH(hw) (1.2 * hw->touch_minor) 27#define THUMB_TOUCH(hw) (1.2 * hw->touch_minor)
28#define THUMB_WIDTH_TOUCH(hw) (3 * hw->touch_major) 28#define THUMB_WIDTH_TOUCH(hw) (3 * hw->touch_major)
@@ -37,9 +37,9 @@ void init_mtstate(struct MTState *s)
37static int touching_finger(const struct FingerState *hw, 37static int touching_finger(const struct FingerState *hw,
38 const struct Capabilities *caps) 38 const struct Capabilities *caps)
39{ 39{
40 if (caps->has_abs[BIT_TOUCH_MAJOR] && caps->has_abs[BIT_WIDTH_MAJOR]) 40 if (caps->has_abs[MTDEV_TOUCH_MAJOR] && caps->has_abs[MTDEV_WIDTH_MAJOR])
41 return hw->touch_major > TOUCH_WIDTH(hw); 41 return hw->touch_major > TOUCH_WIDTH(hw);
42 if (caps->has_abs[BIT_TOUCH_MAJOR]) 42 if (caps->has_abs[MTDEV_TOUCH_MAJOR])
43 return hw->touch_major > TOUCH_SCALE(caps); 43 return hw->touch_major > TOUCH_SCALE(caps);
44 return 1; 44 return 1;
45} 45}
@@ -55,10 +55,10 @@ static int touching_finger(const struct FingerState *hw,
55static int is_thumb(const struct FingerState *hw, 55static int is_thumb(const struct FingerState *hw,
56 const struct Capabilities *caps) 56 const struct Capabilities *caps)
57{ 57{
58 if (!caps->has_abs[BIT_TOUCH_MAJOR] || 58 if (!caps->has_abs[MTDEV_TOUCH_MAJOR] ||
59 !caps->has_abs[BIT_TOUCH_MINOR] || 59 !caps->has_abs[MTDEV_TOUCH_MINOR] ||
60 !caps->has_abs[BIT_WIDTH_MAJOR] || 60 !caps->has_abs[MTDEV_WIDTH_MAJOR] ||
61 !caps->has_abs[BIT_WIDTH_MINOR]) 61 !caps->has_abs[MTDEV_WIDTH_MINOR])
62 return 0; 62 return 0;
63 return hw->touch_major > THUMB_TOUCH(hw) && 63 return hw->touch_major > THUMB_TOUCH(hw) &&
64 hw->width_major > THUMB_WIDTH_TOUCH(hw) && 64 hw->width_major > THUMB_WIDTH_TOUCH(hw) &&
diff --git a/src/test.c b/src/test.c
index e4247d2..3a23db3 100644
--- a/src/test.c
+++ b/src/test.c
@@ -35,8 +35,8 @@ static void loop_device(int fd)
35 fprintf(stderr, "error: could not open device\n"); 35 fprintf(stderr, "error: could not open device\n");
36 return; 36 return;
37 } 37 }
38 while (poll_iobuf(&mt.buf, fd, 5000)) { 38 while (mtdev_pull(&mt.dev, fd, 1) > 0) {
39 while (read_packet(&mt, fd) > 0) { 39 if (parse_event(&mt)) {
40 extract_gestures(&gs, &mt); 40 extract_gestures(&gs, &mt);
41 output_gesture(&gs); 41 output_gesture(&gs);
42 } 42 }