|
Lines 6-13
Link Here
|
| 6 |
|
6 |
|
| 7 |
#include "X.h" |
7 |
#include "X.h" |
| 8 |
#include "xf86.h" |
8 |
#include "xf86.h" |
|
|
9 |
#include "xf86Priv.h" |
| 10 |
#include "xf86_OSlib.h" |
| 9 |
#include "xf86Xinput.h" |
11 |
#include "xf86Xinput.h" |
| 10 |
#include "xf86OSmouse.h" |
12 |
#include "xf86OSmouse.h" |
|
|
13 |
#include "mipointer.h" |
| 14 |
#include "lnx_evdev.h" |
| 15 |
|
| 16 |
/* Names of protocols that are handled internally here. */ |
| 17 |
static const char *internalNames[] = { |
| 18 |
"evdev", |
| 19 |
NULL |
| 20 |
}; |
| 11 |
|
21 |
|
| 12 |
static int |
22 |
static int |
| 13 |
SupportedInterfaces(void) |
23 |
SupportedInterfaces(void) |
|
Lines 15-20
Link Here
|
| 15 |
return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_XPS2 | MSE_AUTO; |
25 |
return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_XPS2 | MSE_AUTO; |
| 16 |
} |
26 |
} |
| 17 |
|
27 |
|
|
|
28 |
static const char ** |
| 29 |
BuiltinNames(void) |
| 30 |
{ |
| 31 |
return internalNames; |
| 32 |
} |
| 33 |
|
| 34 |
static Bool |
| 35 |
CheckProtocol(const char *protocol) |
| 36 |
{ |
| 37 |
int i; |
| 38 |
|
| 39 |
for (i = 0; internalNames[i]; i++) |
| 40 |
if (xf86NameCmp(protocol, internalNames[i]) == 0) |
| 41 |
return TRUE; |
| 42 |
return FALSE; |
| 43 |
} |
| 44 |
|
| 45 |
typedef struct _evdevMseRec { |
| 46 |
int packetSize; |
| 47 |
int buttons; |
| 48 |
Bool sync; |
| 49 |
evdevDriver evdev; |
| 50 |
} evdevMseRec, *evdevMsePtr; |
| 51 |
|
| 52 |
static void |
| 53 |
evdevMouseReadInput(InputInfoPtr pInfo) |
| 54 |
{ |
| 55 |
MouseDevPtr pMse; |
| 56 |
evdevMsePtr evdevMse; |
| 57 |
struct input_event *ev; |
| 58 |
int n, bit; |
| 59 |
int dx = 0, dy = 0, dz = 0, dw = 0; |
| 60 |
|
| 61 |
pMse = pInfo->private; |
| 62 |
ev = (struct input_event *) pMse->buffer; |
| 63 |
evdevMse = pMse->mousePriv; |
| 64 |
|
| 65 |
if (pInfo->fd == -1) |
| 66 |
return; |
| 67 |
|
| 68 |
do { |
| 69 |
n = read(pInfo->fd, pMse->buffer, sizeof(struct input_event)); |
| 70 |
if (n == -1) { |
| 71 |
xf86Msg(X_ERROR, "%s: Error in reading! (%s) Disabiling.\n", |
| 72 |
pInfo->name, strerror(errno)); |
| 73 |
RemoveEnabledDevice(pInfo->fd); |
| 74 |
xf86RemoveSIGIOHandler(pInfo->fd); |
| 75 |
close (pInfo->fd); |
| 76 |
pMse->device->public.on = FALSE; |
| 77 |
pInfo->fd = -1; |
| 78 |
pMse->PostEvent(pInfo, evdevMse->buttons, dx, dy, dz, dw); |
| 79 |
return; |
| 80 |
} |
| 81 |
if (n != sizeof(struct input_event)) { |
| 82 |
xf86Msg(X_WARNING, "%s: incomplete packet, size %d\n", pInfo->name, n); |
| 83 |
pMse->PostEvent(pInfo, evdevMse->buttons, dx, dy, dz, dw); |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
switch (ev->type) { |
| 88 |
case EV_REL: |
| 89 |
switch (ev->code) { |
| 90 |
case EV_REL_X: |
| 91 |
dx += ev->value; |
| 92 |
break; |
| 93 |
case EV_REL_Y: |
| 94 |
dy += ev->value; |
| 95 |
break; |
| 96 |
case EV_REL_Z: |
| 97 |
case EV_REL_WHEEL: |
| 98 |
dz -= ev->value; |
| 99 |
break; |
| 100 |
case EV_REL_HWHEEL: |
| 101 |
dw -= ev->value; |
| 102 |
break; |
| 103 |
} |
| 104 |
break; |
| 105 |
case EV_KEY: |
| 106 |
if ((ev->code < EV_BTN_MOUSE) || (ev->code >= EV_BTN_JOYSTICK)) |
| 107 |
break; |
| 108 |
switch (ev->code) { |
| 109 |
case EV_BTN_RIGHT: bit = 1 << 0; break; /* 1 */ |
| 110 |
case EV_BTN_MIDDLE: bit = 1 << 1; break; /* 2 */ |
| 111 |
case EV_BTN_LEFT: bit = 1 << 2; break; /* 3 */ |
| 112 |
default: bit = 1 << (ev->code - EV_BTN_MOUSE); break; |
| 113 |
} |
| 114 |
evdevMse->buttons &= ~bit; |
| 115 |
if (ev->value) |
| 116 |
evdevMse->buttons |= bit; |
| 117 |
break; |
| 118 |
case EV_SYN: |
| 119 |
switch (ev->code) { |
| 120 |
case EV_SYN_REPORT: |
| 121 |
pMse->PostEvent(pInfo,evdevMse->buttons,dx, dy, dz, dw); |
| 122 |
dx = dy = dz = dw = 0; |
| 123 |
break; |
| 124 |
} |
| 125 |
break; |
| 126 |
} |
| 127 |
if (!evdevMse->sync) { |
| 128 |
pMse->PostEvent(pInfo,evdevMse->buttons,dx, dy, dz, dw); |
| 129 |
dx = dy = dz = dw = 0; |
| 130 |
} |
| 131 |
} while (xf86WaitForInput(pInfo->fd, 0)); |
| 132 |
|
| 133 |
pMse->PostEvent(pInfo, evdevMse->buttons, dx, dy, dz, dw); |
| 134 |
|
| 135 |
return; |
| 136 |
} |
| 137 |
|
| 138 |
static void |
| 139 |
evdevMouseSigioReadInput (int fd, void *closure) |
| 140 |
{ |
| 141 |
evdevMouseReadInput ((InputInfoPtr) closure); |
| 142 |
} |
| 143 |
|
| 144 |
static int |
| 145 |
evdevMouseProc(DeviceIntPtr pPointer, int what) |
| 146 |
{ |
| 147 |
InputInfoPtr pInfo; |
| 148 |
MouseDevPtr pMse; |
| 149 |
evdevMsePtr evdevMse; |
| 150 |
unsigned char map[MSE_MAXBUTTONS + 1]; |
| 151 |
int i, j, blocked; |
| 152 |
unsigned long evtype_bits[NBITS(EV_MAX)]; |
| 153 |
unsigned long evkey_bits[NBITS(EV_KEY_MAX)]; |
| 154 |
|
| 155 |
pInfo = pPointer->public.devicePrivate; |
| 156 |
pMse = pInfo->private; |
| 157 |
pMse->device = pPointer; |
| 158 |
evdevMse = pMse->mousePriv; |
| 159 |
|
| 160 |
switch (what) { |
| 161 |
case DEVICE_INIT: |
| 162 |
pPointer->public.on = FALSE; |
| 163 |
|
| 164 |
evdevMse->evdev.name = xf86SetStrOption(pInfo->options,"Dev Name",NULL); |
| 165 |
evdevMse->evdev.phys = xf86SetStrOption(pInfo->options,"Dev Phys",NULL); |
| 166 |
evdevMse->evdev.cb_data = pInfo->dev; |
| 167 |
evdevMse->evdev.callback = evdevMouseProc; |
| 168 |
if (!evdevNewDriver (&evdevMse->evdev)) { |
| 169 |
xf86Msg(X_ERROR, "%s: cannot register with evdev brain\n", pInfo->name); |
| 170 |
return BadRequest; |
| 171 |
} |
| 172 |
if ((pInfo->fd = evdevGetFDForDriver (&evdevMse->evdev)) == -1) { |
| 173 |
xf86Msg(X_ERROR, "%s: cannot open input device\n", pInfo->name); |
| 174 |
return BadRequest; |
| 175 |
} |
| 176 |
|
| 177 |
ioctl(pInfo->fd, EVIOCGBIT(0, EV_MAX), evtype_bits); |
| 178 |
if (test_bit(EV_SYN, evtype_bits)) |
| 179 |
evdevMse->sync = TRUE; |
| 180 |
else |
| 181 |
evdevMse->sync = FALSE; |
| 182 |
|
| 183 |
if (test_bit(EV_KEY, evtype_bits)) { |
| 184 |
ioctl(pInfo->fd, EVIOCGBIT(EV_KEY, EV_KEY_MAX), evkey_bits); |
| 185 |
i = EV_BTN_LEFT; |
| 186 |
for (i = EV_BTN_LEFT, j = 0; i <= EV_BTN_BACK; i++) |
| 187 |
if (test_bit(i, evkey_bits)) |
| 188 |
j = i - EV_BTN_LEFT; |
| 189 |
if (++j > pMse->buttons) pMse->buttons = j; |
| 190 |
} |
| 191 |
|
| 192 |
close(pInfo->fd); |
| 193 |
pInfo->fd = -1; |
| 194 |
|
| 195 |
for (i = 0; i < MSE_MAXBUTTONS; ++i) |
| 196 |
map[i + 1] = i + 1; |
| 197 |
|
| 198 |
InitPointerDeviceStruct((DevicePtr)pPointer, map, |
| 199 |
min(pMse->buttons, MSE_MAXBUTTONS), |
| 200 |
miPointerGetMotionEvents, pMse->Ctrl, |
| 201 |
miPointerGetMotionBufferSize()); |
| 202 |
|
| 203 |
/* X valuator */ |
| 204 |
xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1); |
| 205 |
xf86InitValuatorDefaults(pPointer, 0); |
| 206 |
/* Y valuator */ |
| 207 |
xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1); |
| 208 |
xf86InitValuatorDefaults(pPointer, 1); |
| 209 |
xf86MotionHistoryAllocate(pInfo); |
| 210 |
break; |
| 211 |
|
| 212 |
case DEVICE_ON: |
| 213 |
if (pPointer->public.on) |
| 214 |
break; |
| 215 |
if ((pInfo->fd = evdevGetFDForDriver (&evdevMse->evdev)) == -1) { |
| 216 |
xf86Msg(X_ERROR, "%s: cannot open input device (name: '%s', phys: '%s')\n", pInfo->name, evdevMse->evdev.name, evdevMse->evdev.phys); |
| 217 |
return BadRequest; |
| 218 |
} |
| 219 |
|
| 220 |
xf86FlushInput(pInfo->fd); |
| 221 |
if (!xf86InstallSIGIOHandler (pInfo->fd, evdevMouseSigioReadInput, pInfo)) |
| 222 |
AddEnabledDevice(pInfo->fd); |
| 223 |
pMse->lastButtons = 0; |
| 224 |
pMse->emulateState = 0; |
| 225 |
evdevMse->buttons = 0; |
| 226 |
pPointer->public.on = TRUE; |
| 227 |
/* |
| 228 |
* send button up events for sanity. If no button down is pending |
| 229 |
* xf86PostButtonEvent() will discard them. So we are on the safe side. |
| 230 |
*/ |
| 231 |
blocked = xf86BlockSIGIO (); |
| 232 |
for (i = 1; i <= 5; i++) |
| 233 |
xf86PostButtonEvent(pPointer,0,i,0,0,0); |
| 234 |
xf86UnblockSIGIO (blocked); |
| 235 |
break; |
| 236 |
|
| 237 |
case DEVICE_OFF: |
| 238 |
case DEVICE_CLOSE: |
| 239 |
if (pInfo->fd != -1) { |
| 240 |
RemoveEnabledDevice(pInfo->fd); |
| 241 |
xf86RemoveSIGIOHandler(pInfo->fd); |
| 242 |
close (pInfo->fd); |
| 243 |
pInfo->fd = -1; |
| 244 |
} |
| 245 |
pPointer->public.on = FALSE; |
| 246 |
usleep(300000); |
| 247 |
break; |
| 248 |
} |
| 249 |
return Success; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
/* This function is called when the protocol is "evdev". */ |
| 254 |
static Bool |
| 255 |
evdevMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags) |
| 256 |
{ |
| 257 |
MouseDevPtr pMse = pInfo->private; |
| 258 |
evdevMsePtr evdevMse; |
| 259 |
|
| 260 |
pMse->protocol = protocol; |
| 261 |
xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol); |
| 262 |
|
| 263 |
/* Collect the options, and process the common options. */ |
| 264 |
xf86CollectInputOptions(pInfo, NULL, NULL); |
| 265 |
xf86ProcessCommonOptions(pInfo, pInfo->options); |
| 266 |
|
| 267 |
if (sizeof(struct input_event) <= sizeof(pMse->protoBuf)) |
| 268 |
pMse->buffer = pMse->protoBuf; |
| 269 |
else |
| 270 |
pMse->buffer = xcalloc(sizeof(struct input_event),1); |
| 271 |
pMse->mousePriv = evdevMse = xcalloc(sizeof(evdevMseRec), 1); |
| 272 |
if ((pMse->buffer == NULL) || (pMse->mousePriv == NULL)) { |
| 273 |
xf86Msg(X_ERROR, "%s: cannot allocate buffer\n", pInfo->name); |
| 274 |
xfree(pMse); |
| 275 |
return FALSE; |
| 276 |
} |
| 277 |
|
| 278 |
if (!evdevStart (pInfo->drv)) { |
| 279 |
xf86Msg(X_ERROR, "%s: cannot start evdev brain\n", pInfo->name); |
| 280 |
return FALSE; |
| 281 |
} |
| 282 |
|
| 283 |
pMse->CommonOptions(pInfo); |
| 284 |
|
| 285 |
/* Setup the local procs. */ |
| 286 |
pInfo->device_control = evdevMouseProc; |
| 287 |
pInfo->read_input = evdevMouseReadInput; |
| 288 |
|
| 289 |
pInfo->flags |= XI86_CONFIGURED; |
| 290 |
|
| 291 |
return TRUE; |
| 292 |
} |
| 293 |
|
| 18 |
OSMouseInfoPtr |
294 |
OSMouseInfoPtr |
| 19 |
xf86OSMouseInit(int flags) |
295 |
xf86OSMouseInit(int flags) |
| 20 |
{ |
296 |
{ |
|
Lines 24-29
Link Here
|
| 24 |
if (!p) |
300 |
if (!p) |
| 25 |
return NULL; |
301 |
return NULL; |
| 26 |
p->SupportedInterfaces = SupportedInterfaces; |
302 |
p->SupportedInterfaces = SupportedInterfaces; |
|
|
303 |
p->CheckProtocol = CheckProtocol; |
| 304 |
p->BuiltinNames = BuiltinNames; |
| 305 |
p->PreInit = evdevMousePreInit; |
| 27 |
return p; |
306 |
return p; |
| 28 |
} |
307 |
} |
| 29 |
|
|
|