1 /* DirectInput Joystick device
2 *
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 /*
23 * To Do:
24 * dead zone
25 * force feedback
26 */
27
28 #include "config.h"
29 #include "wine/port.h"
30
31 #include <stdarg.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <time.h>
35 #ifdef HAVE_UNISTD_H
36 # include <unistd.h>
37 #endif
38 #ifdef HAVE_SYS_TIME_H
39 # include <sys/time.h>
40 #endif
41 #include <fcntl.h>
42 #ifdef HAVE_SYS_IOCTL_H
43 # include <sys/ioctl.h>
44 #endif
45 #include <errno.h>
46 #ifdef HAVE_SYS_ERRNO_H
47 # include <sys/errno.h>
48 #endif
49 #ifdef HAVE_LINUX_IOCTL_H
50 # include <linux/ioctl.h>
51 #endif
52 #ifdef HAVE_LINUX_JOYSTICK_H
53 # include <linux/joystick.h>
54 # undef SW_MAX
55 #endif
56 #ifdef HAVE_SYS_POLL_H
57 # include <sys/poll.h>
58 #endif
59
60 #include "wine/debug.h"
61 #include "wine/unicode.h"
62 #include "windef.h"
63 #include "winbase.h"
64 #include "winerror.h"
65 #include "dinput.h"
66
67 #include "dinput_private.h"
68 #include "device_private.h"
69 #include "joystick_private.h"
70
71 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
72
73 #ifdef HAVE_LINUX_22_JOYSTICK_API
74
75 #define JOYDEV_NEW "/dev/input/js"
76 #define JOYDEV_OLD "/dev/js"
77
78 struct JoyDev
79 {
80 char device[MAX_PATH];
81 char name[MAX_PATH];
82
83 BYTE dev_axes_map[ABS_MAX + 1];
84 int have_axes_map;
85 };
86
87 typedef struct JoystickImpl JoystickImpl;
88 static const IDirectInputDevice8AVtbl JoystickAvt;
89 static const IDirectInputDevice8WVtbl JoystickWvt;
90 struct JoystickImpl
91 {
92 struct JoystickGenericImpl generic;
93
94 struct JoyDev *joydev;
95
96 /* joystick private */
97 int joyfd;
98 POINTL povs[4];
99 };
100
101 static const GUID DInput_Wine_Joystick_GUID = { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
102 0x9e573ed9,
103 0x7734,
104 0x11d2,
105 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
106 };
107
108 #define MAX_JOYSTICKS 64
109 static INT joystick_devices_count = -1;
110 static struct JoyDev *joystick_devices;
111
112 static void joy_polldev(JoystickGenericImpl *This);
113
114 static INT find_joystick_devices(void)
115 {
116 INT i;
117
118 if (joystick_devices_count != -1) return joystick_devices_count;
119
120 joystick_devices_count = 0;
121 for (i = 0; i < MAX_JOYSTICKS; i++)
122 {
123 int fd;
124 struct JoyDev joydev, *new_joydevs;
125
126 snprintf(joydev.device, sizeof(joydev.device), "%s%d", JOYDEV_NEW, i);
127 if ((fd = open(joydev.device, O_RDONLY)) < 0)
128 {
129 snprintf(joydev.device, sizeof(joydev.device), "%s%d", JOYDEV_OLD, i);
130 if ((fd = open(joydev.device, O_RDONLY)) < 0) continue;
131 }
132
133 strcpy(joydev.name, "Wine Joystick");
134 #if defined(JSIOCGNAME)
135 if (ioctl(fd, JSIOCGNAME(sizeof(joydev.name)), joydev.name) < 0)
136 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", joydev.device, strerror(errno));
137 #endif
138
139 if (ioctl(fd, JSIOCGAXMAP, joydev.dev_axes_map) < 0)
140 {
141 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", joydev.device, strerror(errno));
142 joydev.have_axes_map = 0;
143 }
144 else
145 {
146 INT j;
147 joydev.have_axes_map = 1;
148
149 /* Remap to DI numbers */
150 for (j = 0; j < ABS_MAX; j++)
151 if (joydev.dev_axes_map[j] < 8)
152 /* Axis match 1-to-1 */
153 joydev.dev_axes_map[j] = j;
154 else if (joydev.dev_axes_map[j] == 16 ||
155 joydev.dev_axes_map[j] == 17)
156 /* POV axis */
157 joydev.dev_axes_map[j] = 8;
158 else
159 joydev.dev_axes_map[j] = -1;
160 }
161
162 close(fd);
163
164 if (!joystick_devices_count)
165 new_joydevs = HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev));
166 else
167 new_joydevs = HeapReAlloc(GetProcessHeap(), 0, joystick_devices,
168 (joystick_devices_count + 1) * sizeof(struct JoyDev));
169 if (!new_joydevs) continue;
170
171 joystick_devices = new_joydevs;
172 joystick_devices[joystick_devices_count++] = joydev;
173 }
174
175 return joystick_devices_count;
176 }
177
178 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
179 {
180 int fd = -1;
181
182 if (id >= find_joystick_devices()) return FALSE;
183
184 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
185 WARN("force feedback not supported\n");
186 return FALSE;
187 }
188
189 if ((dwDevType == 0) ||
190 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
191 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
192 /* check whether we have a joystick */
193 if ((fd = open(joystick_devices[id].device, O_RDONLY)) < 0)
194 {
195 WARN("open(%s, O_RDONLY) failed: %s\n", joystick_devices[id].name, strerror(errno));
196 return FALSE;
197 }
198
199 /* Return joystick */
200 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
201 lpddi->guidInstance.Data3 = id;
202 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
203 /* we only support traditional joysticks for now */
204 if (version >= 0x0800)
205 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
206 else
207 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
208
209 strcpy(lpddi->tszInstanceName, joystick_devices[id].name);
210 strcpy(lpddi->tszProductName, joystick_devices[id].name);
211
212 lpddi->guidFFDriver = GUID_NULL;
213 close(fd);
214 TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id].device, lpddi->tszProductName);
215 return TRUE;
216 }
217
218 return FALSE;
219 }
220
221 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
222 {
223 int fd = -1;
224
225 if (id >= find_joystick_devices()) return FALSE;
226
227 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
228 WARN("force feedback not supported\n");
229 return FALSE;
230 }
231
232 if ((dwDevType == 0) ||
233 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
234 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
235 /* check whether we have a joystick */
236 if ((fd = open(joystick_devices[id].device, O_RDONLY)) < 0)
237 {
238 WARN("open(%s,O_RDONLY) failed: %s\n", joystick_devices[id].device, strerror(errno));
239 return FALSE;
240 }
241
242 /* Return joystick */
243 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
244 lpddi->guidInstance.Data3 = id;
245 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
246 /* we only support traditional joysticks for now */
247 if (version >= 0x0800)
248 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
249 else
250 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
251
252 MultiByteToWideChar(CP_ACP, 0, joystick_devices[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
253 MultiByteToWideChar(CP_ACP, 0, joystick_devices[id].name, -1, lpddi->tszProductName, MAX_PATH);
254 lpddi->guidFFDriver = GUID_NULL;
255 close(fd);
256 TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id].device, joystick_devices[id].name);
257 return TRUE;
258 }
259
260 return FALSE;
261 }
262
263 static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput,
264 LPDIRECTINPUTDEVICEA* pdev, unsigned short index)
265 {
266 DWORD i;
267 JoystickImpl* newDevice;
268 HRESULT hr;
269 LPDIDATAFORMAT df = NULL;
270 int idx = 0;
271
272 TRACE("%s %p %p %p %hu\n", debugstr_guid(rguid), jvt, dinput, pdev, index);
273
274 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
275 if (newDevice == 0) {
276 WARN("out of memory\n");
277 *pdev = 0;
278 return DIERR_OUTOFMEMORY;
279 }
280
281 newDevice->joydev = &joystick_devices[index];
282 if ((newDevice->joyfd = open(newDevice->joydev->device, O_RDONLY)) < 0)
283 {
284 WARN("open(%s, O_RDONLY) failed: %s\n", newDevice->joydev->device, strerror(errno));
285 HeapFree(GetProcessHeap(), 0, newDevice);
286 return DIERR_DEVICENOTREG;
287 }
288
289 newDevice->generic.guidInstance = DInput_Wine_Joystick_GUID;
290 newDevice->generic.guidInstance.Data3 = index;
291 newDevice->generic.guidProduct = DInput_Wine_Joystick_GUID;
292 newDevice->generic.joy_polldev = joy_polldev;
293 newDevice->generic.name = newDevice->joydev->name;
294
295 #ifdef JSIOCGAXES
296 if (ioctl(newDevice->joyfd, JSIOCGAXES, &newDevice->generic.device_axis_count) < 0) {
297 WARN("ioctl(%s,JSIOCGAXES) failed: %s, defauting to 2\n", newDevice->joydev->device, strerror(errno));
298 newDevice->generic.device_axis_count = 2;
299 }
300 #endif
301 #ifdef JSIOCGBUTTONS
302 if (ioctl(newDevice->joyfd, JSIOCGBUTTONS, &newDevice->generic.devcaps.dwButtons) < 0) {
303 WARN("ioctl(%s,JSIOCGBUTTONS) failed: %s, defauting to 2\n", newDevice->joydev->device, strerror(errno));
304 newDevice->generic.devcaps.dwButtons = 2;
305 }
306 #endif
307
308 if (newDevice->generic.devcaps.dwButtons > 128)
309 {
310 WARN("Can't support %d buttons. Clamping down to 128\n", newDevice->generic.devcaps.dwButtons);
311 newDevice->generic.devcaps.dwButtons = 128;
312 }
313
314 newDevice->generic.base.lpVtbl = jvt;
315 newDevice->generic.base.ref = 1;
316 newDevice->generic.base.dinput = dinput;
317 newDevice->generic.base.guid = *rguid;
318 InitializeCriticalSection(&newDevice->generic.base.crit);
319 newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit");
320
321 /* setup_dinput_options may change these */
322 newDevice->generic.deadzone = 0;
323
324 /* do any user specified configuration */
325 hr = setup_dinput_options(&newDevice->generic, newDevice->joydev->have_axes_map ?
326 newDevice->joydev->dev_axes_map : NULL);
327 if (hr != DI_OK)
328 goto FAILED1;
329
330 /* Create copy of default data format */
331 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto FAILED;
332 memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
333
334 df->dwNumObjs = newDevice->generic.devcaps.dwAxes + newDevice->generic.devcaps.dwPOVs + newDevice->generic.devcaps.dwButtons;
335 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto FAILED;
336
337 for (i = 0; i < newDevice->generic.device_axis_count; i++)
338 {
339 int wine_obj = newDevice->generic.axis_map[i];
340
341 if (wine_obj < 0) continue;
342
343 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize);
344 if (wine_obj < 8)
345 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS;
346 else
347 {
348 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj - 8) | DIDFT_POV;
349 i++; /* POV takes 2 axes */
350 }
351 }
352 for (i = 0; i < newDevice->generic.devcaps.dwButtons; i++)
353 {
354 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + 12], df->dwObjSize);
355 df->rgodf[idx ].pguid = &GUID_Button;
356 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
357 }
358 newDevice->generic.base.data_format.wine_df = df;
359
360 /* initialize default properties */
361 for (i = 0; i < c_dfDIJoystick2.dwNumObjs; i++) {
362 newDevice->generic.props[i].lDevMin = -32767;
363 newDevice->generic.props[i].lDevMax = +32767;
364 newDevice->generic.props[i].lMin = 0;
365 newDevice->generic.props[i].lMax = 0xffff;
366 newDevice->generic.props[i].lDeadZone = newDevice->generic.deadzone; /* % * 1000 */
367 newDevice->generic.props[i].lSaturation = 0;
368 }
369
370 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->generic.base.dinput);
371
372 newDevice->generic.devcaps.dwSize = sizeof(newDevice->generic.devcaps);
373 newDevice->generic.devcaps.dwFlags = DIDC_ATTACHED;
374 if (newDevice->generic.base.dinput->dwVersion >= 0x0800)
375 newDevice->generic.devcaps.dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
376 else
377 newDevice->generic.devcaps.dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
378 newDevice->generic.devcaps.dwFFSamplePeriod = 0;
379 newDevice->generic.devcaps.dwFFMinTimeResolution = 0;
380 newDevice->generic.devcaps.dwFirmwareRevision = 0;
381 newDevice->generic.devcaps.dwHardwareRevision = 0;
382 newDevice->generic.devcaps.dwFFDriverVersion = 0;
383
384 if (TRACE_ON(dinput)) {
385 _dump_DIDATAFORMAT(newDevice->generic.base.data_format.wine_df);
386 for (i = 0; i < (newDevice->generic.device_axis_count); i++)
387 TRACE("axis_map[%d] = %d\n", i, newDevice->generic.axis_map[i]);
388 _dump_DIDEVCAPS(&newDevice->generic.devcaps);
389 }
390
391 *pdev = (LPDIRECTINPUTDEVICEA)newDevice;
392
393 return DI_OK;
394
395 FAILED:
396 hr = DIERR_OUTOFMEMORY;
397 FAILED1:
398 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
399 HeapFree(GetProcessHeap(), 0, df);
400 release_DataFormat(&newDevice->generic.base.data_format);
401 HeapFree(GetProcessHeap(),0,newDevice->generic.axis_map);
402 HeapFree(GetProcessHeap(),0,newDevice);
403 *pdev = 0;
404
405 return hr;
406 }
407
408 /******************************************************************************
409 * get_joystick_index : Get the joystick index from a given GUID
410 */
411 static unsigned short get_joystick_index(REFGUID guid)
412 {
413 GUID wine_joystick = DInput_Wine_Joystick_GUID;
414 GUID dev_guid = *guid;
415
416 wine_joystick.Data3 = 0;
417 dev_guid.Data3 = 0;
418
419 /* for the standard joystick GUID use index 0 */
420 if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
421
422 /* for the wine joystick GUIDs use the index stored in Data3 */
423 if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3;
424
425 return MAX_JOYSTICKS;
426 }
427
428 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
429 {
430 unsigned short index;
431
432 TRACE("%p %s %p %p\n",dinput, debugstr_guid(rguid), riid, pdev);
433 find_joystick_devices();
434 *pdev = NULL;
435
436 if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS &&
437 joystick_devices_count && index < joystick_devices_count)
438 {
439 if ((riid == NULL) ||
440 IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
441 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
442 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
443 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
444 {
445 return alloc_device(rguid, &JoystickAvt, dinput, pdev, index);
446 }
447
448 WARN("no interface\n");
449 return DIERR_NOINTERFACE;
450 }
451
452 return DIERR_DEVICENOTREG;
453 }
454
455 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
456 {
457 unsigned short index;
458
459 TRACE("%p %s %p %p\n",dinput, debugstr_guid(rguid), riid, pdev);
460 find_joystick_devices();
461 *pdev = NULL;
462
463 if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS &&
464 joystick_devices_count && index < joystick_devices_count)
465 {
466 if ((riid == NULL) ||
467 IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
468 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
469 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
470 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
471 {
472 return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA *)pdev, index);
473 }
474 WARN("no interface\n");
475 return DIERR_NOINTERFACE;
476 }
477
478 WARN("invalid device GUID %s\n",debugstr_guid(rguid));
479 return DIERR_DEVICENOTREG;
480 }
481
482 #undef MAX_JOYSTICKS
483
484 const struct dinput_device joystick_linux_device = {
485 "Wine Linux joystick driver",
486 joydev_enum_deviceA,
487 joydev_enum_deviceW,
488 joydev_create_deviceA,
489 joydev_create_deviceW
490 };
491
492 /******************************************************************************
493 * Acquire : gets exclusive control of the joystick
494 */
495 static HRESULT WINAPI JoystickLinuxAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
496 {
497 JoystickImpl *This = (JoystickImpl *)iface;
498 HRESULT res;
499
500 TRACE("(%p)\n",This);
501
502 res = IDirectInputDevice2AImpl_Acquire(iface);
503 if (res != DI_OK)
504 return res;
505
506 /* open the joystick device */
507 if (This->joyfd==-1) {
508 TRACE("opening joystick device %s\n", This->joydev->device);
509
510 This->joyfd = open(This->joydev->device, O_RDONLY);
511 if (This->joyfd==-1) {
512 ERR("open(%s) failed: %s\n", This->joydev->device, strerror(errno));
513 IDirectInputDevice2AImpl_Unacquire(iface);
514 return DIERR_NOTFOUND;
515 }
516 }
517
518 return DI_OK;
519 }
520
521 /******************************************************************************
522 * Unacquire : frees the joystick
523 */
524 static HRESULT WINAPI JoystickLinuxAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
525 {
526 JoystickImpl *This = (JoystickImpl *)iface;
527 HRESULT res;
528
529 TRACE("(%p)\n",This);
530
531 res = IDirectInputDevice2AImpl_Unacquire(iface);
532
533 if (res != DI_OK)
534 return res;
535
536 if (This->joyfd!=-1) {
537 TRACE("closing joystick device\n");
538 close(This->joyfd);
539 This->joyfd = -1;
540 return DI_OK;
541 }
542
543 return DI_NOEFFECT;
544 }
545
546 static void joy_polldev(JoystickGenericImpl *This_in) {
547 struct pollfd plfd;
548 struct js_event jse;
549 JoystickImpl *This = (JoystickImpl*) This_in;
550
551 TRACE("(%p)\n", This);
552
553 if (This->joyfd==-1) {
554 WARN("no device\n");
555 return;
556 }
557 while (1)
558 {
559 LONG value;
560 int inst_id = -1;
561
562 plfd.fd = This->joyfd;
563 plfd.events = POLLIN;
564 if (poll(&plfd,1,0) != 1)
565 return;
566 /* we have one event, so we can read */
567 if (sizeof(jse)!=read(This->joyfd,&jse,sizeof(jse))) {
568 return;
569 }
570 TRACE("js_event: type 0x%x, number %d, value %d\n",
571 jse.type,jse.number,jse.value);
572 if (jse.type & JS_EVENT_BUTTON)
573 {
574 if (jse.number >= This->generic.devcaps.dwButtons) return;
575
576 inst_id = DIDFT_MAKEINSTANCE(jse.number) | DIDFT_PSHBUTTON;
577 This->generic.js.rgbButtons[jse.number] = value = jse.value ? 0x80 : 0x00;
578 }
579 else if (jse.type & JS_EVENT_AXIS)
580 {
581 int number = This->generic.axis_map[jse.number]; /* wine format object index */
582
583 if (number < 0) return;
584 inst_id = DIDFT_MAKEINSTANCE(number) | (number < 8 ? DIDFT_ABSAXIS : DIDFT_POV);
585 value = joystick_map_axis(&This->generic.props[id_to_object(This->generic.base.data_format.wine_df, inst_id)], jse.value);
586
587 TRACE("changing axis %d => %d\n", jse.number, number);
588 switch (number)
589 {
590 case 0: This->generic.js.lX = value; break;
591 case 1: This->generic.js.lY = value; break;
592 case 2: This->generic.js.lZ = value; break;
593 case 3: This->generic.js.lRx = value; break;
594 case 4: This->generic.js.lRy = value; break;
595 case 5: This->generic.js.lRz = value; break;
596 case 6: This->generic.js.rglSlider[0] = value; break;
597 case 7: This->generic.js.rglSlider[1] = value; break;
598 case 8: case 9: case 10: case 11:
599 {
600 int idx = number - 8;
601
602 if (jse.number % 2)
603 This->povs[idx].y = jse.value;
604 else
605 This->povs[idx].x = jse.value;
606
607 This->generic.js.rgdwPOV[idx] = value = joystick_map_pov(&This->povs[idx]);
608 break;
609 }
610 default:
611 WARN("axis %d not supported\n", number);
612 }
613 }
614 if (inst_id >= 0)
615 queue_event((LPDIRECTINPUTDEVICE8A)This,
616 id_to_offset(&This->generic.base.data_format, inst_id),
617 value, jse.time, This->generic.base.dinput->evsequence++);
618 }
619 }
620
621 static const IDirectInputDevice8AVtbl JoystickAvt =
622 {
623 IDirectInputDevice2AImpl_QueryInterface,
624 IDirectInputDevice2AImpl_AddRef,
625 IDirectInputDevice2AImpl_Release,
626 JoystickAGenericImpl_GetCapabilities,
627 IDirectInputDevice2AImpl_EnumObjects,
628 JoystickAGenericImpl_GetProperty,
629 JoystickAGenericImpl_SetProperty,
630 JoystickLinuxAImpl_Acquire,
631 JoystickLinuxAImpl_Unacquire,
632 JoystickAGenericImpl_GetDeviceState,
633 IDirectInputDevice2AImpl_GetDeviceData,
634 IDirectInputDevice2AImpl_SetDataFormat,
635 IDirectInputDevice2AImpl_SetEventNotification,
636 IDirectInputDevice2AImpl_SetCooperativeLevel,
637 JoystickAGenericImpl_GetObjectInfo,
638 JoystickAGenericImpl_GetDeviceInfo,
639 IDirectInputDevice2AImpl_RunControlPanel,
640 IDirectInputDevice2AImpl_Initialize,
641 IDirectInputDevice2AImpl_CreateEffect,
642 IDirectInputDevice2AImpl_EnumEffects,
643 IDirectInputDevice2AImpl_GetEffectInfo,
644 IDirectInputDevice2AImpl_GetForceFeedbackState,
645 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
646 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
647 IDirectInputDevice2AImpl_Escape,
648 JoystickAGenericImpl_Poll,
649 IDirectInputDevice2AImpl_SendDeviceData,
650 IDirectInputDevice7AImpl_EnumEffectsInFile,
651 IDirectInputDevice7AImpl_WriteEffectToFile,
652 IDirectInputDevice8AImpl_BuildActionMap,
653 IDirectInputDevice8AImpl_SetActionMap,
654 IDirectInputDevice8AImpl_GetImageInfo
655 };
656
657 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
658 # define XCAST(fun) (typeof(JoystickWvt.fun))
659 #else
660 # define XCAST(fun) (void*)
661 #endif
662
663 static const IDirectInputDevice8WVtbl JoystickWvt =
664 {
665 IDirectInputDevice2WImpl_QueryInterface,
666 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
667 XCAST(Release)IDirectInputDevice2AImpl_Release,
668 XCAST(GetCapabilities)JoystickAGenericImpl_GetCapabilities,
669 IDirectInputDevice2WImpl_EnumObjects,
670 XCAST(GetProperty)JoystickAGenericImpl_GetProperty,
671 XCAST(SetProperty)JoystickAGenericImpl_SetProperty,
672 XCAST(Acquire)JoystickLinuxAImpl_Acquire,
673 XCAST(Unacquire)JoystickLinuxAImpl_Unacquire,
674 XCAST(GetDeviceState)JoystickAGenericImpl_GetDeviceState,
675 XCAST(GetDeviceData)IDirectInputDevice2AImpl_GetDeviceData,
676 XCAST(SetDataFormat)IDirectInputDevice2AImpl_SetDataFormat,
677 XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
678 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
679 JoystickWGenericImpl_GetObjectInfo,
680 JoystickWGenericImpl_GetDeviceInfo,
681 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
682 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
683 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
684 IDirectInputDevice2WImpl_EnumEffects,
685 IDirectInputDevice2WImpl_GetEffectInfo,
686 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
687 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
688 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
689 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
690 XCAST(Poll)JoystickAGenericImpl_Poll,
691 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
692 IDirectInputDevice7WImpl_EnumEffectsInFile,
693 IDirectInputDevice7WImpl_WriteEffectToFile,
694 IDirectInputDevice8WImpl_BuildActionMap,
695 IDirectInputDevice8WImpl_SetActionMap,
696 IDirectInputDevice8WImpl_GetImageInfo
697 };
698 #undef XCAST
699
700 #else /* HAVE_LINUX_22_JOYSTICK_API */
701
702 const struct dinput_device joystick_linux_device = {
703 "Wine Linux joystick driver",
704 NULL,
705 NULL,
706 NULL,
707 NULL
708 };
709
710 #endif /* HAVE_LINUX_22_JOYSTICK_API */
711
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.