push 149f0a5527ac85057a8ef03858d34d91c36f97e8
[wine/hacks.git] / dlls / dinput / joystick_linux.c
blob1396ea56d8486c345df53e288d2e014fe5836863
1 /* DirectInput Joystick device
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
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.
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.
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
23 * To Do:
24 * dead zone
25 * force feedback
28 #include "config.h"
29 #include "wine/port.h"
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
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"
67 #include "dinput_private.h"
68 #include "device_private.h"
69 #include "joystick_private.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
73 #ifdef HAVE_LINUX_22_JOYSTICK_API
75 #define JOYDEV_NEW "/dev/input/js"
76 #define JOYDEV_OLD "/dev/js"
78 struct JoyDev
80 char device[MAX_PATH];
81 char name[MAX_PATH];
83 BYTE axis_count;
84 BYTE button_count;
85 int *dev_axes_map;
88 typedef struct JoystickImpl JoystickImpl;
89 static const IDirectInputDevice8AVtbl JoystickAvt;
90 static const IDirectInputDevice8WVtbl JoystickWvt;
91 struct JoystickImpl
93 struct JoystickGenericImpl generic;
95 struct JoyDev *joydev;
97 /* joystick private */
98 int joyfd;
99 POINTL povs[4];
102 static const GUID DInput_Wine_Joystick_GUID = { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
103 0x9e573ed9,
104 0x7734,
105 0x11d2,
106 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
109 #define MAX_JOYSTICKS 64
110 static INT joystick_devices_count = -1;
111 static struct JoyDev *joystick_devices;
113 static void joy_polldev(JoystickGenericImpl *This);
115 static INT find_joystick_devices(void)
117 INT i;
119 if (joystick_devices_count != -1) return joystick_devices_count;
121 joystick_devices_count = 0;
122 for (i = 0; i < MAX_JOYSTICKS; i++)
124 int fd;
125 struct JoyDev joydev, *new_joydevs;
126 BYTE axes_map[ABS_MAX + 1];
128 snprintf(joydev.device, sizeof(joydev.device), "%s%d", JOYDEV_NEW, i);
129 if ((fd = open(joydev.device, O_RDONLY)) < 0)
131 snprintf(joydev.device, sizeof(joydev.device), "%s%d", JOYDEV_OLD, i);
132 if ((fd = open(joydev.device, O_RDONLY)) < 0) continue;
135 strcpy(joydev.name, "Wine Joystick");
136 #if defined(JSIOCGNAME)
137 if (ioctl(fd, JSIOCGNAME(sizeof(joydev.name)), joydev.name) < 0)
138 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", joydev.device, strerror(errno));
139 #endif
140 #ifdef JSIOCGAXES
141 if (ioctl(fd, JSIOCGAXES, &joydev.axis_count) < 0)
143 WARN("ioctl(%s,JSIOCGAXES) failed: %s, defauting to 2\n", joydev.device, strerror(errno));
144 joydev.axis_count = 2;
146 #endif
147 #ifdef JSIOCGBUTTONS
148 if (ioctl(fd, JSIOCGBUTTONS, &joydev.button_count) < 0)
150 WARN("ioctl(%s,JSIOCGBUTTONS) failed: %s, defauting to 2\n", joydev.device, strerror(errno));
151 joydev.button_count = 2;
153 #endif
155 if (ioctl(fd, JSIOCGAXMAP, axes_map) < 0)
157 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", joydev.device, strerror(errno));
158 joydev.dev_axes_map = NULL;
160 else
161 if ((joydev.dev_axes_map = HeapAlloc(GetProcessHeap(), 0, joydev.axis_count * sizeof(int))))
163 INT j;
165 /* Remap to DI numbers */
166 for (j = 0; j < joydev.axis_count; j++)
167 if (axes_map[j] < 8)
168 /* Axis match 1-to-1 */
169 joydev.dev_axes_map[j] = j;
170 else if (axes_map[j] == 16 ||
171 axes_map[j] == 17)
172 /* POV axis */
173 joydev.dev_axes_map[j] = 8;
174 else
175 joydev.dev_axes_map[j] = -1;
178 close(fd);
180 if (!joystick_devices_count)
181 new_joydevs = HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev));
182 else
183 new_joydevs = HeapReAlloc(GetProcessHeap(), 0, joystick_devices,
184 (joystick_devices_count + 1) * sizeof(struct JoyDev));
185 if (!new_joydevs) continue;
187 TRACE("Found a joystick on %s: %s\n with %d axes and %d buttons\n", joydev.device,
188 joydev.name, joydev.axis_count, joydev.button_count);
190 joystick_devices = new_joydevs;
191 joystick_devices[joystick_devices_count++] = joydev;
194 return joystick_devices_count;
197 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
199 int fd = -1;
201 if (id >= find_joystick_devices()) return FALSE;
203 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
204 WARN("force feedback not supported\n");
205 return FALSE;
208 if ((dwDevType == 0) ||
209 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
210 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
211 /* check whether we have a joystick */
212 if ((fd = open(joystick_devices[id].device, O_RDONLY)) < 0)
214 WARN("open(%s, O_RDONLY) failed: %s\n", joystick_devices[id].name, strerror(errno));
215 return FALSE;
218 /* Return joystick */
219 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
220 lpddi->guidInstance.Data3 = id;
221 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
222 /* we only support traditional joysticks for now */
223 if (version >= 0x0800)
224 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
225 else
226 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
228 strcpy(lpddi->tszInstanceName, joystick_devices[id].name);
229 strcpy(lpddi->tszProductName, joystick_devices[id].name);
231 lpddi->guidFFDriver = GUID_NULL;
232 close(fd);
233 TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id].device, lpddi->tszProductName);
234 return TRUE;
237 return FALSE;
240 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
242 int fd = -1;
244 if (id >= find_joystick_devices()) return FALSE;
246 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
247 WARN("force feedback not supported\n");
248 return FALSE;
251 if ((dwDevType == 0) ||
252 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
253 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
254 /* check whether we have a joystick */
255 if ((fd = open(joystick_devices[id].device, O_RDONLY)) < 0)
257 WARN("open(%s,O_RDONLY) failed: %s\n", joystick_devices[id].device, strerror(errno));
258 return FALSE;
261 /* Return joystick */
262 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
263 lpddi->guidInstance.Data3 = id;
264 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
265 /* we only support traditional joysticks for now */
266 if (version >= 0x0800)
267 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
268 else
269 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
271 MultiByteToWideChar(CP_ACP, 0, joystick_devices[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
272 MultiByteToWideChar(CP_ACP, 0, joystick_devices[id].name, -1, lpddi->tszProductName, MAX_PATH);
273 lpddi->guidFFDriver = GUID_NULL;
274 close(fd);
275 TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id].device, joystick_devices[id].name);
276 return TRUE;
279 return FALSE;
282 static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput,
283 LPDIRECTINPUTDEVICEA* pdev, unsigned short index)
285 DWORD i;
286 JoystickImpl* newDevice;
287 HRESULT hr;
288 LPDIDATAFORMAT df = NULL;
289 int idx = 0;
291 TRACE("%s %p %p %p %hu\n", debugstr_guid(rguid), jvt, dinput, pdev, index);
293 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
294 if (newDevice == 0) {
295 WARN("out of memory\n");
296 *pdev = 0;
297 return DIERR_OUTOFMEMORY;
300 newDevice->joydev = &joystick_devices[index];
301 newDevice->joyfd = -1;
302 newDevice->generic.guidInstance = DInput_Wine_Joystick_GUID;
303 newDevice->generic.guidInstance.Data3 = index;
304 newDevice->generic.guidProduct = DInput_Wine_Joystick_GUID;
305 newDevice->generic.joy_polldev = joy_polldev;
306 newDevice->generic.name = newDevice->joydev->name;
307 newDevice->generic.device_axis_count = newDevice->joydev->axis_count;
308 newDevice->generic.devcaps.dwButtons = newDevice->joydev->button_count;
310 if (newDevice->generic.devcaps.dwButtons > 128)
312 WARN("Can't support %d buttons. Clamping down to 128\n", newDevice->generic.devcaps.dwButtons);
313 newDevice->generic.devcaps.dwButtons = 128;
316 newDevice->generic.base.lpVtbl = jvt;
317 newDevice->generic.base.ref = 1;
318 newDevice->generic.base.dinput = dinput;
319 newDevice->generic.base.guid = *rguid;
320 InitializeCriticalSection(&newDevice->generic.base.crit);
321 newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit");
323 /* setup_dinput_options may change these */
324 newDevice->generic.deadzone = 0;
326 /* do any user specified configuration */
327 hr = setup_dinput_options(&newDevice->generic, newDevice->joydev->dev_axes_map);
328 if (hr != DI_OK)
329 goto FAILED1;
331 /* Create copy of default data format */
332 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto FAILED;
333 memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
335 df->dwNumObjs = newDevice->generic.devcaps.dwAxes + newDevice->generic.devcaps.dwPOVs + newDevice->generic.devcaps.dwButtons;
336 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto FAILED;
338 for (i = 0; i < newDevice->generic.device_axis_count; i++)
340 int wine_obj = newDevice->generic.axis_map[i];
342 if (wine_obj < 0) continue;
344 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize);
345 if (wine_obj < 8)
346 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS;
347 else
349 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj - 8) | DIDFT_POV;
350 i++; /* POV takes 2 axes */
353 for (i = 0; i < newDevice->generic.devcaps.dwButtons; i++)
355 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + 12], df->dwObjSize);
356 df->rgodf[idx ].pguid = &GUID_Button;
357 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
359 newDevice->generic.base.data_format.wine_df = df;
361 /* initialize default properties */
362 for (i = 0; i < c_dfDIJoystick2.dwNumObjs; i++) {
363 newDevice->generic.props[i].lDevMin = -32767;
364 newDevice->generic.props[i].lDevMax = +32767;
365 newDevice->generic.props[i].lMin = 0;
366 newDevice->generic.props[i].lMax = 0xffff;
367 newDevice->generic.props[i].lDeadZone = newDevice->generic.deadzone; /* % * 1000 */
368 newDevice->generic.props[i].lSaturation = 0;
371 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->generic.base.dinput);
373 newDevice->generic.devcaps.dwSize = sizeof(newDevice->generic.devcaps);
374 newDevice->generic.devcaps.dwFlags = DIDC_ATTACHED;
375 if (newDevice->generic.base.dinput->dwVersion >= 0x0800)
376 newDevice->generic.devcaps.dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
377 else
378 newDevice->generic.devcaps.dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
379 newDevice->generic.devcaps.dwFFSamplePeriod = 0;
380 newDevice->generic.devcaps.dwFFMinTimeResolution = 0;
381 newDevice->generic.devcaps.dwFirmwareRevision = 0;
382 newDevice->generic.devcaps.dwHardwareRevision = 0;
383 newDevice->generic.devcaps.dwFFDriverVersion = 0;
385 if (TRACE_ON(dinput)) {
386 _dump_DIDATAFORMAT(newDevice->generic.base.data_format.wine_df);
387 for (i = 0; i < (newDevice->generic.device_axis_count); i++)
388 TRACE("axis_map[%d] = %d\n", i, newDevice->generic.axis_map[i]);
389 _dump_DIDEVCAPS(&newDevice->generic.devcaps);
392 *pdev = (LPDIRECTINPUTDEVICEA)newDevice;
394 return DI_OK;
396 FAILED:
397 hr = DIERR_OUTOFMEMORY;
398 FAILED1:
399 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
400 HeapFree(GetProcessHeap(), 0, df);
401 release_DataFormat(&newDevice->generic.base.data_format);
402 HeapFree(GetProcessHeap(),0,newDevice->generic.axis_map);
403 HeapFree(GetProcessHeap(),0,newDevice);
404 *pdev = 0;
406 return hr;
409 /******************************************************************************
410 * get_joystick_index : Get the joystick index from a given GUID
412 static unsigned short get_joystick_index(REFGUID guid)
414 GUID wine_joystick = DInput_Wine_Joystick_GUID;
415 GUID dev_guid = *guid;
417 wine_joystick.Data3 = 0;
418 dev_guid.Data3 = 0;
420 /* for the standard joystick GUID use index 0 */
421 if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
423 /* for the wine joystick GUIDs use the index stored in Data3 */
424 if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3;
426 return MAX_JOYSTICKS;
429 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
431 unsigned short index;
433 TRACE("%p %s %p %p\n",dinput, debugstr_guid(rguid), riid, pdev);
434 find_joystick_devices();
435 *pdev = NULL;
437 if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS &&
438 joystick_devices_count && index < joystick_devices_count)
440 if ((riid == NULL) ||
441 IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
442 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
443 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
444 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
446 return alloc_device(rguid, &JoystickAvt, dinput, pdev, index);
449 WARN("no interface\n");
450 return DIERR_NOINTERFACE;
453 return DIERR_DEVICENOTREG;
456 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
458 unsigned short index;
460 TRACE("%p %s %p %p\n",dinput, debugstr_guid(rguid), riid, pdev);
461 find_joystick_devices();
462 *pdev = NULL;
464 if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS &&
465 joystick_devices_count && index < joystick_devices_count)
467 if ((riid == NULL) ||
468 IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
469 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
470 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
471 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
473 return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA *)pdev, index);
475 WARN("no interface\n");
476 return DIERR_NOINTERFACE;
479 WARN("invalid device GUID %s\n",debugstr_guid(rguid));
480 return DIERR_DEVICENOTREG;
483 #undef MAX_JOYSTICKS
485 const struct dinput_device joystick_linux_device = {
486 "Wine Linux joystick driver",
487 joydev_enum_deviceA,
488 joydev_enum_deviceW,
489 joydev_create_deviceA,
490 joydev_create_deviceW
493 /******************************************************************************
494 * Acquire : gets exclusive control of the joystick
496 static HRESULT WINAPI JoystickLinuxAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
498 JoystickImpl *This = (JoystickImpl *)iface;
499 HRESULT res;
501 TRACE("(%p)\n",This);
503 res = IDirectInputDevice2AImpl_Acquire(iface);
504 if (res != DI_OK)
505 return res;
507 /* open the joystick device */
508 if (This->joyfd==-1) {
509 TRACE("opening joystick device %s\n", This->joydev->device);
511 This->joyfd = open(This->joydev->device, O_RDONLY);
512 if (This->joyfd==-1) {
513 ERR("open(%s) failed: %s\n", This->joydev->device, strerror(errno));
514 IDirectInputDevice2AImpl_Unacquire(iface);
515 return DIERR_NOTFOUND;
519 return DI_OK;
522 /******************************************************************************
523 * Unacquire : frees the joystick
525 static HRESULT WINAPI JoystickLinuxAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
527 JoystickImpl *This = (JoystickImpl *)iface;
528 HRESULT res;
530 TRACE("(%p)\n",This);
532 res = IDirectInputDevice2AImpl_Unacquire(iface);
534 if (res != DI_OK)
535 return res;
537 if (This->joyfd!=-1) {
538 TRACE("closing joystick device\n");
539 close(This->joyfd);
540 This->joyfd = -1;
541 return DI_OK;
544 return DI_NOEFFECT;
547 static void joy_polldev(JoystickGenericImpl *This_in) {
548 struct pollfd plfd;
549 struct js_event jse;
550 JoystickImpl *This = (JoystickImpl*) This_in;
552 TRACE("(%p)\n", This);
554 if (This->joyfd==-1) {
555 WARN("no device\n");
556 return;
558 while (1)
560 LONG value;
561 int inst_id = -1;
563 plfd.fd = This->joyfd;
564 plfd.events = POLLIN;
565 if (poll(&plfd,1,0) != 1)
566 return;
567 /* we have one event, so we can read */
568 if (sizeof(jse)!=read(This->joyfd,&jse,sizeof(jse))) {
569 return;
571 TRACE("js_event: type 0x%x, number %d, value %d\n",
572 jse.type,jse.number,jse.value);
573 if (jse.type & JS_EVENT_BUTTON)
575 if (jse.number >= This->generic.devcaps.dwButtons) return;
577 inst_id = DIDFT_MAKEINSTANCE(jse.number) | DIDFT_PSHBUTTON;
578 This->generic.js.rgbButtons[jse.number] = value = jse.value ? 0x80 : 0x00;
580 else if (jse.type & JS_EVENT_AXIS)
582 int number = This->generic.axis_map[jse.number]; /* wine format object index */
584 if (number < 0) return;
585 inst_id = number < 8 ? DIDFT_MAKEINSTANCE(number) | DIDFT_ABSAXIS :
586 DIDFT_MAKEINSTANCE(number - 8) | DIDFT_POV;
587 value = joystick_map_axis(&This->generic.props[id_to_object(This->generic.base.data_format.wine_df, inst_id)], jse.value);
589 TRACE("changing axis %d => %d\n", jse.number, number);
590 switch (number)
592 case 0: This->generic.js.lX = value; break;
593 case 1: This->generic.js.lY = value; break;
594 case 2: This->generic.js.lZ = value; break;
595 case 3: This->generic.js.lRx = value; break;
596 case 4: This->generic.js.lRy = value; break;
597 case 5: This->generic.js.lRz = value; break;
598 case 6: This->generic.js.rglSlider[0] = value; break;
599 case 7: This->generic.js.rglSlider[1] = value; break;
600 case 8: case 9: case 10: case 11:
602 int idx = number - 8;
604 if (jse.number % 2)
605 This->povs[idx].y = jse.value;
606 else
607 This->povs[idx].x = jse.value;
609 This->generic.js.rgdwPOV[idx] = value = joystick_map_pov(&This->povs[idx]);
610 break;
612 default:
613 WARN("axis %d not supported\n", number);
616 if (inst_id >= 0)
617 queue_event((LPDIRECTINPUTDEVICE8A)This, inst_id,
618 value, jse.time, This->generic.base.dinput->evsequence++);
622 static const IDirectInputDevice8AVtbl JoystickAvt =
624 IDirectInputDevice2AImpl_QueryInterface,
625 IDirectInputDevice2AImpl_AddRef,
626 IDirectInputDevice2AImpl_Release,
627 JoystickAGenericImpl_GetCapabilities,
628 IDirectInputDevice2AImpl_EnumObjects,
629 JoystickAGenericImpl_GetProperty,
630 JoystickAGenericImpl_SetProperty,
631 JoystickLinuxAImpl_Acquire,
632 JoystickLinuxAImpl_Unacquire,
633 JoystickAGenericImpl_GetDeviceState,
634 IDirectInputDevice2AImpl_GetDeviceData,
635 IDirectInputDevice2AImpl_SetDataFormat,
636 IDirectInputDevice2AImpl_SetEventNotification,
637 IDirectInputDevice2AImpl_SetCooperativeLevel,
638 JoystickAGenericImpl_GetObjectInfo,
639 JoystickAGenericImpl_GetDeviceInfo,
640 IDirectInputDevice2AImpl_RunControlPanel,
641 IDirectInputDevice2AImpl_Initialize,
642 IDirectInputDevice2AImpl_CreateEffect,
643 IDirectInputDevice2AImpl_EnumEffects,
644 IDirectInputDevice2AImpl_GetEffectInfo,
645 IDirectInputDevice2AImpl_GetForceFeedbackState,
646 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
647 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
648 IDirectInputDevice2AImpl_Escape,
649 JoystickAGenericImpl_Poll,
650 IDirectInputDevice2AImpl_SendDeviceData,
651 IDirectInputDevice7AImpl_EnumEffectsInFile,
652 IDirectInputDevice7AImpl_WriteEffectToFile,
653 IDirectInputDevice8AImpl_BuildActionMap,
654 IDirectInputDevice8AImpl_SetActionMap,
655 IDirectInputDevice8AImpl_GetImageInfo
658 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
659 # define XCAST(fun) (typeof(JoystickWvt.fun))
660 #else
661 # define XCAST(fun) (void*)
662 #endif
664 static const IDirectInputDevice8WVtbl JoystickWvt =
666 IDirectInputDevice2WImpl_QueryInterface,
667 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
668 XCAST(Release)IDirectInputDevice2AImpl_Release,
669 XCAST(GetCapabilities)JoystickAGenericImpl_GetCapabilities,
670 IDirectInputDevice2WImpl_EnumObjects,
671 XCAST(GetProperty)JoystickAGenericImpl_GetProperty,
672 XCAST(SetProperty)JoystickAGenericImpl_SetProperty,
673 XCAST(Acquire)JoystickLinuxAImpl_Acquire,
674 XCAST(Unacquire)JoystickLinuxAImpl_Unacquire,
675 XCAST(GetDeviceState)JoystickAGenericImpl_GetDeviceState,
676 XCAST(GetDeviceData)IDirectInputDevice2AImpl_GetDeviceData,
677 XCAST(SetDataFormat)IDirectInputDevice2AImpl_SetDataFormat,
678 XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
679 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
680 JoystickWGenericImpl_GetObjectInfo,
681 JoystickWGenericImpl_GetDeviceInfo,
682 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
683 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
684 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
685 IDirectInputDevice2WImpl_EnumEffects,
686 IDirectInputDevice2WImpl_GetEffectInfo,
687 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
688 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
689 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
690 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
691 XCAST(Poll)JoystickAGenericImpl_Poll,
692 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
693 IDirectInputDevice7WImpl_EnumEffectsInFile,
694 IDirectInputDevice7WImpl_WriteEffectToFile,
695 IDirectInputDevice8WImpl_BuildActionMap,
696 IDirectInputDevice8WImpl_SetActionMap,
697 IDirectInputDevice8WImpl_GetImageInfo
699 #undef XCAST
701 #else /* HAVE_LINUX_22_JOYSTICK_API */
703 const struct dinput_device joystick_linux_device = {
704 "Wine Linux joystick driver",
705 NULL,
706 NULL,
707 NULL,
708 NULL
711 #endif /* HAVE_LINUX_22_JOYSTICK_API */