1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
/*
* Copyright © 2011 Alexandr Shadchin
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <xorg-server.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <string.h>
#include "synproto.h"
#include "synapticsstr.h"
#include <xf86.h>
#include <fcntl.h>
#include <dev/wscons/wsconsio.h>
#ifdef X_PRIVSEP
extern int priv_open_device(const char *);
#endif
#define DEFAULT_WSMOUSE_DEV "/dev/wsmouse0"
static Bool
WSConsIsTouchpad(InputInfoPtr pInfo, const char *device)
{
int wsmouse_type, fd = -1;
Bool rc = FALSE;
if (device) {
#ifndef X_PRIVSEP
fd = open(device, O_RDWR);
#else
fd = priv_open_device(device);
#endif
} else
fd = pInfo->fd;
if (fd < 0)
return FALSE;
if (ioctl(fd, WSMOUSEIO_GTYPE, &wsmouse_type) == -1) {
xf86IDrvMsg(pInfo, X_ERROR, "cannot get mouse type\n");
goto out;
}
if (wsmouse_type == WSMOUSE_TYPE_SYNAPTICS ||
wsmouse_type == WSMOUSE_TYPE_ALPS ||
wsmouse_type == WSMOUSE_TYPE_ELANTECH)
rc = TRUE;
out:
if (device)
close(fd);
return rc;
}
static Bool
WSConsReadEvent(InputInfoPtr pInfo, struct wscons_event *event)
{
Bool rc = TRUE;
ssize_t len;
len = read(pInfo->fd, event, sizeof(struct wscons_event));
if (len <= 0) {
if (errno != EAGAIN)
xf86IDrvMsg(pInfo, X_ERROR, "read error %s\n", strerror(errno));
rc = FALSE;
} else if (len % sizeof(struct wscons_event)) {
xf86IDrvMsg(pInfo, X_ERROR, "read error, invalid number of bytes\n");
rc = FALSE;
}
return rc;
}
static Bool
WSConsDeviceOnHook(InputInfoPtr pInfo, SynapticsParameters *para)
{
int wsmouse_mode = WSMOUSE_NATIVE;
if (ioctl(pInfo->fd, WSMOUSEIO_SETMODE, &wsmouse_mode) == -1) {
xf86IDrvMsg(pInfo, X_ERROR, "cannot set native mode\n");
return FALSE;
}
return TRUE;
}
static Bool
WSConsDeviceOffHook(InputInfoPtr pInfo)
{
int wsmouse_mode = WSMOUSE_COMPAT;
if (ioctl(pInfo->fd, WSMOUSEIO_SETMODE, &wsmouse_mode) == -1) {
xf86IDrvMsg(pInfo, X_ERROR, "cannot set compat mode\n");
return FALSE;
}
return TRUE;
}
static Bool
WSConsQueryHardware(InputInfoPtr pInfo)
{
return WSConsIsTouchpad(pInfo, NULL);
}
static Bool
WSConsReadHwState(InputInfoPtr pInfo,
struct CommData *comm, struct SynapticsHwState *hwRet)
{
SynapticsPrivate *priv = (SynapticsPrivate *)pInfo->private;
struct SynapticsHwState *hw = comm->hwState;
struct wscons_event event;
Bool v;
/* Reset cumulative values if buttons were not previously pressed */
if (!hw->left && !hw->right && !hw->middle) {
hw->cumulative_dx = hw->x;
hw->cumulative_dy = hw->y;
}
while (WSConsReadEvent(pInfo, &event)) {
switch (event.type) {
case WSCONS_EVENT_MOUSE_UP:
case WSCONS_EVENT_MOUSE_DOWN:
v = (event.type == WSCONS_EVENT_MOUSE_DOWN) ? TRUE : FALSE;
switch (event.value) {
case 0:
hw->left = v;
break;
case 1:
hw->middle = v;
break;
case 2:
hw->right = v;
break;
case 3:
hw->up = v;
break;
case 4:
hw->down = v;
break;
case 5:
hw->multi[0] = v;
break;
case 6:
hw->multi[1] = v;
break;
case 7:
hw->multi[2] = v;
break;
case 8:
hw->multi[3] = v;
break;
case 9:
hw->multi[4] = v;
break;
case 10:
hw->multi[5] = v;
break;
case 11:
hw->multi[6] = v;
break;
case 12:
hw->multi[7] = v;
break;
}
break;
case WSCONS_EVENT_MOUSE_ABSOLUTE_X:
hw->x = event.value;
break;
case WSCONS_EVENT_MOUSE_ABSOLUTE_Y:
hw->y = priv->maxy - event.value + priv->miny;
break;
case WSCONS_EVENT_MOUSE_ABSOLUTE_Z:
hw->z = event.value;
break;
case WSCONS_EVENT_MOUSE_ABSOLUTE_W:
if (priv->model == MODEL_ELANTECH) {
/* Elantech touchpads report number of fingers directly. */
hw->fingerWidth = 5;
hw->numFingers = event.value;
break;
}
/* XXX magic number mapping which is mirrored in pms driver */
switch (event.value) {
case 0:
hw->fingerWidth = 5;
hw->numFingers = 2;
break;
case 1:
hw->fingerWidth = 5;
hw->numFingers = 3;
break;
case 4 ... 5:
hw->fingerWidth = event.value;
hw->numFingers = 1;
break;
}
break;
case WSCONS_EVENT_SYNC:
hw->millis = 1000 * event.time.tv_sec + event.time.tv_nsec / 1000000;
SynapticsCopyHwState(hwRet, hw);
return TRUE;
default:
return FALSE;
}
}
return FALSE;
}
static Bool
WSConsAutoDevProbe(InputInfoPtr pInfo, const char *device)
{
int i;
if (device && WSConsIsTouchpad(pInfo, device))
return TRUE;
if (WSConsIsTouchpad(pInfo, DEFAULT_WSMOUSE_DEV)) {
xf86IDrvMsg(pInfo, X_PROBED, "auto-dev sets device to %s\n",
DEFAULT_WSMOUSE_DEV);
xf86ReplaceStrOption(pInfo->options, "Device", DEFAULT_WSMOUSE_DEV);
return TRUE;
}
return FALSE;
}
static void
WSConsReadDevDimensions(InputInfoPtr pInfo)
{
SynapticsPrivate *priv = (SynapticsPrivate *)pInfo->private;
struct wsmouse_calibcoords wsmc;
int wsmouse_type;
if (ioctl(pInfo->fd, WSMOUSEIO_GCALIBCOORDS, &wsmc) != 0) {
xf86IDrvMsg(pInfo, X_ERROR, "failed to query axis range (%s)\n",
strerror(errno));
return;
}
priv->minx = wsmc.minx;
priv->maxx = wsmc.maxx;
priv->resx = wsmc.resx;
xf86IDrvMsg(pInfo, X_PROBED, "x-axis range %d - %d resolution %d\n",
priv->minx, priv->maxx, priv->resx);
priv->miny = wsmc.miny;
priv->maxy = wsmc.maxy;
priv->resy = wsmc.resy;
xf86IDrvMsg(pInfo, X_PROBED, "y-axis range %d - %d resolution %d\n",
priv->miny, priv->maxy, priv->resy);
priv->minp = 0;
priv->maxp = 255;
priv->minw = 0;
priv->maxw = 15;
priv->has_pressure = TRUE;
priv->has_left = TRUE;
priv->has_right = TRUE;
priv->has_middle = TRUE;
if (ioctl(pInfo->fd, WSMOUSEIO_GTYPE, &wsmouse_type) == -1)
xf86IDrvMsg(pInfo, X_ERROR, "cannot get mouse type\n");
switch (wsmouse_type) {
default:
case WSMOUSE_TYPE_SYNAPTICS:
priv->model = MODEL_SYNAPTICS;
priv->has_width = TRUE;
priv->has_double = TRUE;
priv->has_triple = TRUE;
break;
case WSMOUSE_TYPE_ALPS:
priv->model = MODEL_ALPS;
priv->has_width = FALSE;
priv->has_double = FALSE;
priv->has_triple = FALSE;
break;
case WSMOUSE_TYPE_ELANTECH:
priv->model = MODEL_ELANTECH;
priv->has_width = TRUE;
priv->has_double = TRUE;
priv->has_triple = TRUE;
break;
}
}
struct SynapticsProtocolOperations wscons_proto_operations = {
WSConsDeviceOnHook,
WSConsDeviceOffHook,
WSConsQueryHardware,
WSConsReadHwState,
WSConsAutoDevProbe,
WSConsReadDevDimensions
};
|