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
|
/*
* Copyright © 2006 Zephaniah E. Hull
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Soft-
* ware"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, provided that the above copyright
* notice(s) and this permission notice appear in all copies of the Soft-
* ware and that both the above copyright notice(s) and this permission
* notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
* ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
* RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
* THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
* QUENTIAL 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 PERFOR-
* MANCE OF THIS SOFTWARE.
*
* Except as contained in this notice, the name of a copyright holder shall
* not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization of
* the copyright holder.
*
* Author: Zephaniah E. Hull (warp@aehallh.com)
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <X11/keysym.h>
#include <X11/XF86keysym.h>
#include <X11/extensions/XIproto.h>
/* The libc wrapper just blows... linux/input.h must be included
* before xf86_ansic.h and xf86_libc.h so we avoid defining ioctl
* twice. */
#include <linux/input.h>
#include <misc.h>
#include <xf86.h>
#include <xf86str.h>
#include <xf86_OSproc.h>
#include <xf86_ansic.h>
#include <xf86_libc.h>
#include <xf86Xinput.h>
#include <exevents.h>
#include <mipointer.h>
#include <xf86Module.h>
#include "evdev.h"
#define ArrayLength(a) (sizeof(a) / (sizeof((a)[0])))
#define BITS_PER_LONG (sizeof(long) * 8)
#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
#define OFF(x) ((x)%BITS_PER_LONG)
#define LONG(x) ((x)/BITS_PER_LONG)
#define TestBit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
static char *axis_names[] = {
"X",
"Y",
"Z",
"RX",
"RY",
"RZ",
"HWHEEL",
"DIAL",
"WHEEL",
"MISC",
"10",
"11",
"12",
"13",
"14",
"15",
NULL
};
static void
EvdevPtrCtrlProc(DeviceIntPtr device, PtrCtrl *ctrl)
{
/* Nothing to do, dix handles all settings */
}
static Bool
EvdevConvert(InputInfoPtr pInfo, int first, int num, int v0, int v1, int v2,
int v3, int v4, int v5, int *x, int *y)
{
if (first == 0) {
*x = v0;
*y = v1;
return TRUE;
} else
return FALSE;
}
/*
* FIXME: Verify that the C standard lets us pass more variable arguments
* then we specify.
*/
void
EvdevRelSyn (InputInfoPtr pInfo)
{
evdevDevicePtr pEvdev = pInfo->private;
evdevStatePtr state = &pEvdev->state;
int i, btn;
if (!state->rel || state->mode != Relative)
return;
for (i = 0; i < state->rel->axes; i++) {
if ((state->rel->v[i] > 0) && (btn = state->rel->btnMap[i][0]))
EvdevBtnPostFakeClicks (pInfo, btn, state->rel->v[i]);
else if ((state->rel->v[i] < 0) && (btn = state->rel->btnMap[i][1]))
EvdevBtnPostFakeClicks (pInfo, btn, -state->rel->v[i]);
}
xf86PostMotionEvent(pInfo->dev, 0, 0, state->rel->axes,
state->rel->v[0], state->rel->v[1], state->rel->v[2], state->rel->v[3],
state->rel->v[4], state->rel->v[5], state->rel->v[6], state->rel->v[7],
state->rel->v[8], state->rel->v[9], state->rel->v[10], state->rel->v[11],
state->rel->v[12], state->rel->v[13], state->rel->v[14], state->rel->v[15]);
for (i = 0; i < REL_MAX; i++)
state->rel->v[i] = 0;
}
void
EvdevRelProcess (InputInfoPtr pInfo, struct input_event *ev)
{
evdevDevicePtr pEvdev = pInfo->private;
int map;
if (ev->code >= REL_MAX)
return;
map = pEvdev->state.rel->map[ev->code];
if (map >= 0)
pEvdev->state.rel->v[map] += ev->value;
else
pEvdev->state.rel->v[-map] -= ev->value;
if (!pEvdev->state.sync)
EvdevRelSyn (pInfo);
}
int
EvdevRelInit (DeviceIntPtr device)
{
InputInfoPtr pInfo = device->public.devicePrivate;
evdevDevicePtr pEvdev = pInfo->private;
int i;
if (!InitValuatorClassDeviceStruct(device, pEvdev->state.rel->axes,
miPointerGetMotionEvents,
miPointerGetMotionBufferSize(), 0))
return !Success;
for (i = 0; i < pEvdev->state.rel->axes; i++) {
xf86InitValuatorAxisStruct(device, i, 0, 0, 0, 0, 1);
xf86InitValuatorDefaults(device, i);
}
if (!InitPtrFeedbackClassDeviceStruct(device, EvdevPtrCtrlProc))
return !Success;
return Success;
}
int
EvdevRelOn (DeviceIntPtr device)
{
return Success;
}
int
EvdevRelOff (DeviceIntPtr device)
{
return Success;
}
int
EvdevRelNew(InputInfoPtr pInfo)
{
evdevDevicePtr pEvdev = pInfo->private;
evdevStatePtr state = &pEvdev->state;
char *s, option[64];
int i, j, k = 0, real_axes;
real_axes = 0;
for (i = 0; i < REL_MAX; i++)
if (TestBit (i, pEvdev->bits.rel))
real_axes++;
if (!real_axes && (!state->abs || state->abs->axes < 2))
return !Success;
state->rel = Xcalloc (sizeof (evdevRelRec));
xf86Msg(X_INFO, "%s: Found %d relative axes.\n", pInfo->name,
real_axes);
xf86Msg(X_INFO, "%s: Configuring as pointer.\n", pInfo->name);
pInfo->flags |= XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS |
XI86_CONFIGURED;
pInfo->type_name = XI_MOUSE;
pInfo->conversion_proc = EvdevConvert;
for (i = 0, j = 0; i < REL_MAX; i++) {
if (!TestBit (i, pEvdev->bits.rel))
continue;
snprintf(option, sizeof(option), "%sRelativeAxisMap", axis_names[i]);
s = xf86SetStrOption(pInfo->options, option, "0");
if (s && (k = strtol(s, NULL, 0)))
state->rel->map[i] = k;
else
state->rel->map[i] = j;
if (s && k)
xf86Msg(X_CONFIG, "%s: %s: %d.\n", pInfo->name, option, k);
snprintf(option, sizeof(option), "%sRelativeAxisButtons", axis_names[i]);
if (i == REL_WHEEL || i == REL_Z)
s = xf86SetStrOption(pInfo->options, option, "4 5");
else if (i == REL_HWHEEL)
s = xf86SetStrOption(pInfo->options, option, "6 7");
else
s = xf86SetStrOption(pInfo->options, option, "0 0");
k = state->rel->map[i];
if (!s || (sscanf(s, "%d %d", &state->rel->btnMap[k][0],
&state->rel->btnMap[k][1]) != 2))
state->rel->btnMap[k][0] = state->rel->btnMap[k][1] = 0;
if (state->rel->btnMap[k][0] || state->rel->btnMap[k][1])
xf86Msg(X_CONFIG, "%s: %s: %d %d.\n", pInfo->name, option,
state->rel->btnMap[k][0], state->rel->btnMap[k][1]);
j++;
}
state->rel->axes = real_axes;
for (i = 0; i < REL_MAX; i++)
if (state->rel->map[i] > state->rel->axes)
state->rel->axes = state->rel->map[i];
if (state->abs && (state->abs->axes >= 2) && (state->rel->axes < 2))
state->rel->axes = 2;
if (state->rel->axes != real_axes)
xf86Msg(X_CONFIG, "%s: Configuring %d relative axes.\n", pInfo->name,
state->rel->axes);
return Success;
}
|