dinput: Limit number of axes in a different way - map all extra axes to -1.
[wine] / dlls / dinput / joystick_linux.c
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 "winreg.h"
66 #include "dinput.h"
67
68 #include "dinput_private.h"
69 #include "device_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 typedef struct JoystickImpl JoystickImpl;
79 static const IDirectInputDevice8AVtbl JoystickAvt;
80 static const IDirectInputDevice8WVtbl JoystickWvt;
81 struct JoystickImpl
82 {
83         struct IDirectInputDevice2AImpl base;
84
85         char                            dev[32];
86
87         /* joystick private */
88         int                             joyfd;
89         DIJOYSTATE2                     js;             /* wine data */
90         ObjProps                        *props;
91         char                            *name;
92         DIDEVCAPS                       devcaps;
93         LONG                            deadzone;
94         int                             *axis_map;
95         int                             axes;
96         POINTL                          povs[4];
97 };
98
99 static const GUID DInput_Wine_Joystick_GUID = { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
100   0x9e573ed9,
101   0x7734,
102   0x11d2,
103   {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
104 };
105
106 static void _dump_DIDEVCAPS(const DIDEVCAPS *lpDIDevCaps)
107 {
108     TRACE("dwSize: %d\n", lpDIDevCaps->dwSize);
109     TRACE("dwFlags: %08x\n", lpDIDevCaps->dwFlags);
110     TRACE("dwDevType: %08x %s\n", lpDIDevCaps->dwDevType,
111           lpDIDevCaps->dwDevType == DIDEVTYPE_DEVICE ? "DIDEVTYPE_DEVICE" :
112           lpDIDevCaps->dwDevType == DIDEVTYPE_DEVICE ? "DIDEVTYPE_DEVICE" :
113           lpDIDevCaps->dwDevType == DIDEVTYPE_MOUSE ? "DIDEVTYPE_MOUSE" :
114           lpDIDevCaps->dwDevType == DIDEVTYPE_KEYBOARD ? "DIDEVTYPE_KEYBOARD" :
115           lpDIDevCaps->dwDevType == DIDEVTYPE_JOYSTICK ? "DIDEVTYPE_JOYSTICK" :
116           lpDIDevCaps->dwDevType == DIDEVTYPE_HID ? "DIDEVTYPE_HID" : "UNKNOWN");
117     TRACE("dwAxes: %d\n", lpDIDevCaps->dwAxes);
118     TRACE("dwButtons: %d\n", lpDIDevCaps->dwButtons);
119     TRACE("dwPOVs: %d\n", lpDIDevCaps->dwPOVs);
120     if (lpDIDevCaps->dwSize > sizeof(DIDEVCAPS_DX3)) {
121         TRACE("dwFFSamplePeriod: %d\n", lpDIDevCaps->dwFFSamplePeriod);
122         TRACE("dwFFMinTimeResolution: %d\n", lpDIDevCaps->dwFFMinTimeResolution);
123         TRACE("dwFirmwareRevision: %d\n", lpDIDevCaps->dwFirmwareRevision);
124         TRACE("dwHardwareRevision: %d\n", lpDIDevCaps->dwHardwareRevision);
125         TRACE("dwFFDriverVersion: %d\n", lpDIDevCaps->dwFFDriverVersion);
126     }
127 }
128
129 #define MAX_JOYSTICKS 64
130 static INT joystick_devices_count = -1;
131 static LPSTR joystick_devices[MAX_JOYSTICKS];
132
133 static INT find_joystick_devices(void)
134 {
135     INT i;
136
137     if (joystick_devices_count != -1) return joystick_devices_count;
138
139     joystick_devices_count = 0;
140     for (i = 0; i < MAX_JOYSTICKS; i++)
141     {
142         CHAR device_name[MAX_PATH], *str;
143         INT len;
144         int fd;
145
146         len = sprintf(device_name, "%s%d", JOYDEV_NEW, i) + 1;
147         if ((fd = open(device_name, O_RDONLY)) < 0)
148         {
149             len = sprintf(device_name, "%s%d", JOYDEV_OLD, i) + 1;
150             if ((fd = open(device_name, O_RDONLY)) < 0) continue;
151         }
152
153         close(fd);
154
155         if (!(str = HeapAlloc(GetProcessHeap(), 0, len))) break;
156         memcpy(str, device_name, len);
157
158         joystick_devices[joystick_devices_count++] = str;
159     }
160
161     return joystick_devices_count;
162 }
163
164 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
165 {
166     int fd = -1;
167
168     if (id >= find_joystick_devices()) return FALSE;
169
170     if (dwFlags & DIEDFL_FORCEFEEDBACK) {
171         WARN("force feedback not supported\n");
172         return FALSE;
173     }
174
175     if ((dwDevType == 0) ||
176         ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
177         (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
178         /* check whether we have a joystick */
179         if ((fd = open(joystick_devices[id], O_RDONLY)) < 0)
180         {
181             WARN("open(%s, O_RDONLY) failed: %s\n", joystick_devices[id], strerror(errno));
182             return FALSE;
183         }
184
185         /* Return joystick */
186         lpddi->guidInstance = DInput_Wine_Joystick_GUID;
187         lpddi->guidInstance.Data3 = id;
188         lpddi->guidProduct = DInput_Wine_Joystick_GUID;
189         /* we only support traditional joysticks for now */
190         if (version >= 0x0800)
191             lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
192         else
193             lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
194         sprintf(lpddi->tszInstanceName, "Joystick %d", id);
195 #if defined(JSIOCGNAME)
196         if (ioctl(fd,JSIOCGNAME(sizeof(lpddi->tszProductName)),lpddi->tszProductName) < 0) {
197             WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", joystick_devices[id], strerror(errno));
198             strcpy(lpddi->tszProductName, "Wine Joystick");
199         }
200 #else
201         strcpy(lpddi->tszProductName, "Wine Joystick");
202 #endif
203
204         lpddi->guidFFDriver = GUID_NULL;
205         close(fd);
206         TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id], lpddi->tszProductName);
207         return TRUE;
208     }
209
210     return FALSE;
211 }
212
213 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
214 {
215     int fd = -1;
216     char name[MAX_PATH];
217     char friendly[32];
218
219     if (id >= find_joystick_devices()) return FALSE;
220
221     if (dwFlags & DIEDFL_FORCEFEEDBACK) {
222         WARN("force feedback not supported\n");
223         return FALSE;
224     }
225
226     if ((dwDevType == 0) ||
227         ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
228         (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
229         /* check whether we have a joystick */
230         if ((fd = open(joystick_devices[id], O_RDONLY)) < 0)
231         {
232             WARN("open(%s,O_RDONLY) failed: %s\n", joystick_devices[id], strerror(errno));
233             return FALSE;
234         }
235
236         /* Return joystick */
237         lpddi->guidInstance = DInput_Wine_Joystick_GUID;
238         lpddi->guidInstance.Data3 = id;
239         lpddi->guidProduct = DInput_Wine_Joystick_GUID;
240         /* we only support traditional joysticks for now */
241         if (version >= 0x0800)
242             lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
243         else
244             lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
245         sprintf(friendly, "Joystick %d", id);
246         MultiByteToWideChar(CP_ACP, 0, friendly, -1, lpddi->tszInstanceName, MAX_PATH);
247 #if defined(JSIOCGNAME)
248         if (ioctl(fd,JSIOCGNAME(sizeof(name)),name) < 0) {
249             WARN("ioctl(%s, JSIOCGNAME) failed: %s\n", joystick_devices[id], strerror(errno));
250             strcpy(name, "Wine Joystick");
251         }
252 #else
253         strcpy(name, "Wine Joystick");
254 #endif
255         MultiByteToWideChar(CP_ACP, 0, name, -1, lpddi->tszProductName, MAX_PATH);
256         lpddi->guidFFDriver = GUID_NULL;
257         close(fd);
258         TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id], name);
259         return TRUE;
260     }
261
262     return FALSE;
263 }
264
265 /*
266  * Setup the dinput options.
267  */
268
269 static HRESULT setup_dinput_options(JoystickImpl * device)
270 {
271     char buffer[MAX_PATH+16];
272     HKEY hkey, appkey;
273     int tokens = 0;
274     int axis = 0;
275     int pov = 0;
276
277     buffer[MAX_PATH]='\0';
278
279     get_app_key(&hkey, &appkey);
280
281     /* get options */
282
283     if (!get_config_key( hkey, appkey, "DefaultDeadZone", buffer, MAX_PATH )) {
284         device->deadzone = atoi(buffer);
285         TRACE("setting default deadzone to: \"%s\" %d\n", buffer, device->deadzone);
286     }
287
288     device->axis_map = HeapAlloc(GetProcessHeap(), 0, device->axes * sizeof(int));
289     if (!device->axis_map) return DIERR_OUTOFMEMORY;
290
291     if (!get_config_key( hkey, appkey, device->name, buffer, MAX_PATH )) {
292         static const char *axis_names[] = {"X", "Y", "Z", "Rx", "Ry", "Rz",
293                                            "Slider1", "Slider2",
294                                            "POV1", "POV2", "POV3", "POV4"};
295         const char *delim = ",";
296         char * ptr;
297         TRACE("\"%s\" = \"%s\"\n", device->name, buffer);
298
299         if ((ptr = strtok(buffer, delim)) != NULL) {
300             do {
301                 int i;
302
303                 for (i = 0; i < sizeof(axis_names) / sizeof(axis_names[0]); i++)
304                     if (!strcmp(ptr, axis_names[i]))
305                     {
306                         if (!strncmp(ptr, "POV", 3))
307                         {
308                             if (pov >= 4)
309                             {
310                                 WARN("Only 4 POVs supported - ignoring extra\n");
311                                 i = -1;
312                             }
313                             else
314                             {
315                                 /* Pov takes two axes */
316                                 device->axis_map[tokens++] = i;
317                                 pov++;
318                             }
319                         }
320                         else
321                         {
322                             if (axis >= 8)
323                             {
324                                 FIXME("Only 8 Axes supported - ignoring extra\n");
325                                 i = -1;
326                             }
327                             else
328                                 axis++;
329                         }
330                         break;
331                     }
332
333                 if (i == sizeof(axis_names) / sizeof(axis_names[0]))
334                 {
335                     ERR("invalid joystick axis type: \"%s\"\n", ptr);
336                     i = -1;
337                 }
338
339                 device->axis_map[tokens] = i;
340                 tokens++;
341             } while ((ptr = strtok(NULL, delim)) != NULL);
342
343             if (tokens != device->axes) {
344                 ERR("not all joystick axes mapped: %d axes(%d,%d), %d arguments\n", device->axes, axis, pov,tokens);
345                 while (tokens < device->axes) {
346                     device->axis_map[tokens] = -1;
347                     tokens++;
348                 }
349             }
350         }
351     }
352     else
353     {
354         for (tokens = 0; tokens < device->axes; tokens++)
355         {
356             if (tokens < 8)
357                 device->axis_map[tokens] = axis++;
358             else if (tokens < 16)
359             {
360                 device->axis_map[tokens++] = 8 + pov;
361                 device->axis_map[tokens  ] = 8 + pov++;
362             }
363             else
364                 device->axis_map[tokens] = -1;
365         }
366     }
367     device->devcaps.dwAxes = axis;
368     device->devcaps.dwPOVs = pov;
369
370     if (appkey)
371         RegCloseKey( appkey );
372
373     if (hkey)
374         RegCloseKey( hkey );
375
376     return DI_OK;
377 }
378
379 static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput,
380     LPDIRECTINPUTDEVICEA* pdev, unsigned short index)
381 {
382     DWORD i;
383     JoystickImpl* newDevice;
384     char name[MAX_PATH];
385     HRESULT hr;
386     LPDIDATAFORMAT df = NULL;
387     int idx = 0;
388
389     TRACE("%s %p %p %p %hu\n", debugstr_guid(rguid), jvt, dinput, pdev, index);
390
391     newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
392     if (newDevice == 0) {
393         WARN("out of memory\n");
394         *pdev = 0;
395         return DIERR_OUTOFMEMORY;
396     }
397
398     if (!lstrcpynA(newDevice->dev, joystick_devices[index], sizeof(newDevice->dev)) ||
399         (newDevice->joyfd = open(newDevice->dev, O_RDONLY)) < 0)
400     {
401         WARN("open(%s, O_RDONLY) failed: %s\n", newDevice->dev, strerror(errno));
402         HeapFree(GetProcessHeap(), 0, newDevice);
403         return DIERR_DEVICENOTREG;
404     }
405
406     /* get the device name */
407 #if defined(JSIOCGNAME)
408     if (ioctl(newDevice->joyfd,JSIOCGNAME(MAX_PATH),name) < 0) {
409         WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", newDevice->dev, strerror(errno));
410         strcpy(name, "Wine Joystick");
411     }
412 #else
413     strcpy(name, "Wine Joystick");
414 #endif
415
416     /* copy the device name */
417     newDevice->name = HeapAlloc(GetProcessHeap(),0,strlen(name) + 1);
418     strcpy(newDevice->name, name);
419
420 #ifdef JSIOCGAXES
421     if (ioctl(newDevice->joyfd,JSIOCGAXES,&newDevice->axes) < 0) {
422         WARN("ioctl(%s,JSIOCGAXES) failed: %s, defauting to 2\n", newDevice->dev, strerror(errno));
423         newDevice->axes = 2;
424     }
425 #endif
426 #ifdef JSIOCGBUTTONS
427     if (ioctl(newDevice->joyfd, JSIOCGBUTTONS, &newDevice->devcaps.dwButtons) < 0) {
428         WARN("ioctl(%s,JSIOCGBUTTONS) failed: %s, defauting to 2\n", newDevice->dev, strerror(errno));
429         newDevice->devcaps.dwButtons = 2;
430     }
431 #endif
432
433     if (newDevice->devcaps.dwButtons > 128)
434     {
435         WARN("Can't support %d buttons. Clamping down to 128\n", newDevice->devcaps.dwButtons);
436         newDevice->devcaps.dwButtons = 128;
437     }
438
439     newDevice->base.lpVtbl = jvt;
440     newDevice->base.ref = 1;
441     newDevice->base.dinput = dinput;
442     newDevice->base.guid = *rguid;
443     InitializeCriticalSection(&newDevice->base.crit);
444     newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->base.crit");
445
446     /* setup_dinput_options may change these */
447     newDevice->deadzone = 0;
448
449     /* do any user specified configuration */
450     hr = setup_dinput_options(newDevice);
451     if (hr != DI_OK)
452         goto FAILED1;
453
454     /* Create copy of default data format */
455     if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto FAILED;
456     memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
457
458     df->dwNumObjs = newDevice->devcaps.dwAxes + newDevice->devcaps.dwPOVs + newDevice->devcaps.dwButtons;
459     if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto FAILED;
460
461     for (i = 0; i < newDevice->axes; i++)
462     {
463         int wine_obj = newDevice->axis_map[i];
464
465         if (wine_obj < 0) continue;
466
467         memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize);
468         if (wine_obj < 8)
469             df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS;
470         else
471         {
472             df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj - 8) | DIDFT_POV;
473             i++; /* POV takes 2 axes */
474         }
475     }
476     for (i = 0; i < newDevice->devcaps.dwButtons; i++)
477     {
478         memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + 12], df->dwObjSize);
479         df->rgodf[idx  ].pguid = &GUID_Button;
480         df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
481     }
482     newDevice->base.data_format.wine_df = df;
483
484     /* create default properties */
485     newDevice->props = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwNumObjs*sizeof(ObjProps));
486     if (newDevice->props == 0)
487         goto FAILED;
488
489     /* initialize default properties */
490     for (i = 0; i < c_dfDIJoystick2.dwNumObjs; i++) {
491         newDevice->props[i].lDevMin = -32767;
492         newDevice->props[i].lDevMax = +32767;
493         newDevice->props[i].lMin = 0;
494         newDevice->props[i].lMax = 0xffff;
495         newDevice->props[i].lDeadZone = newDevice->deadzone;    /* % * 1000 */
496         newDevice->props[i].lSaturation = 0;
497     }
498
499     IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->base.dinput);
500
501     newDevice->devcaps.dwSize = sizeof(newDevice->devcaps);
502     newDevice->devcaps.dwFlags = DIDC_ATTACHED;
503     if (newDevice->base.dinput->dwVersion >= 0x0800)
504         newDevice->devcaps.dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
505     else
506         newDevice->devcaps.dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
507     newDevice->devcaps.dwFFSamplePeriod = 0;
508     newDevice->devcaps.dwFFMinTimeResolution = 0;
509     newDevice->devcaps.dwFirmwareRevision = 0;
510     newDevice->devcaps.dwHardwareRevision = 0;
511     newDevice->devcaps.dwFFDriverVersion = 0;
512
513     if (TRACE_ON(dinput)) {
514         _dump_DIDATAFORMAT(newDevice->base.data_format.wine_df);
515        for (i = 0; i < (newDevice->axes); i++)
516            TRACE("axis_map[%d] = %d\n", i, newDevice->axis_map[i]);
517         _dump_DIDEVCAPS(&newDevice->devcaps);
518     }
519
520     *pdev = (LPDIRECTINPUTDEVICEA)newDevice;
521
522     return DI_OK;
523
524 FAILED:
525     hr = DIERR_OUTOFMEMORY;
526 FAILED1:
527     if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
528     HeapFree(GetProcessHeap(), 0, df);
529     release_DataFormat(&newDevice->base.data_format);
530     HeapFree(GetProcessHeap(),0,newDevice->axis_map);
531     HeapFree(GetProcessHeap(),0,newDevice->name);
532     HeapFree(GetProcessHeap(),0,newDevice->props);
533     HeapFree(GetProcessHeap(),0,newDevice);
534     *pdev = 0;
535
536     return hr;
537 }
538
539 /******************************************************************************
540   *     get_joystick_index : Get the joystick index from a given GUID
541   */
542 static unsigned short get_joystick_index(REFGUID guid)
543 {
544     GUID wine_joystick = DInput_Wine_Joystick_GUID;
545     GUID dev_guid = *guid;
546
547     wine_joystick.Data3 = 0;
548     dev_guid.Data3 = 0;
549
550     /* for the standard joystick GUID use index 0 */
551     if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
552
553     /* for the wine joystick GUIDs use the index stored in Data3 */
554     if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3;
555
556     return MAX_JOYSTICKS;
557 }
558
559 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
560 {
561     unsigned short index;
562
563     TRACE("%p %s %p %p\n",dinput, debugstr_guid(rguid), riid, pdev);
564     find_joystick_devices();
565     *pdev = NULL;
566
567     if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS &&
568         joystick_devices_count && index < joystick_devices_count)
569     {
570         if ((riid == NULL) ||
571             IsEqualGUID(&IID_IDirectInputDeviceA,  riid) ||
572             IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
573             IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
574             IsEqualGUID(&IID_IDirectInputDevice8A, riid))
575         {
576             return alloc_device(rguid, &JoystickAvt, dinput, pdev, index);
577         }
578
579         WARN("no interface\n");
580         return DIERR_NOINTERFACE;
581     }
582
583     return DIERR_DEVICENOTREG;
584 }
585
586 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
587 {
588     unsigned short index;
589
590     TRACE("%p %s %p %p\n",dinput, debugstr_guid(rguid), riid, pdev);
591     find_joystick_devices();
592     *pdev = NULL;
593
594     if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS &&
595         joystick_devices_count && index < joystick_devices_count)
596     {
597         if ((riid == NULL) ||
598             IsEqualGUID(&IID_IDirectInputDeviceW,  riid) ||
599             IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
600             IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
601             IsEqualGUID(&IID_IDirectInputDevice8W, riid))
602         {
603             return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA *)pdev, index);
604         }
605         WARN("no interface\n");
606         return DIERR_NOINTERFACE;
607     }
608
609     WARN("invalid device GUID %s\n",debugstr_guid(rguid));
610     return DIERR_DEVICENOTREG;
611 }
612
613 #undef MAX_JOYSTICKS
614
615 const struct dinput_device joystick_linux_device = {
616   "Wine Linux joystick driver",
617   joydev_enum_deviceA,
618   joydev_enum_deviceW,
619   joydev_create_deviceA,
620   joydev_create_deviceW
621 };
622
623 /******************************************************************************
624   *     Acquire : gets exclusive control of the joystick
625   */
626 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
627 {
628     JoystickImpl *This = (JoystickImpl *)iface;
629
630     TRACE("(%p)\n",This);
631
632     if (This->base.acquired) {
633         WARN("already acquired\n");
634         return S_FALSE;
635     }
636
637     /* open the joystick device */
638     if (This->joyfd==-1) {
639         TRACE("opening joystick device %s\n", This->dev);
640
641         This->joyfd=open(This->dev,O_RDONLY);
642         if (This->joyfd==-1) {
643             ERR("open(%s) failed: %s\n", This->dev, strerror(errno));
644             return DIERR_NOTFOUND;
645         }
646     }
647
648     This->base.acquired = 1;
649
650     return DI_OK;
651 }
652
653 /******************************************************************************
654   *     Unacquire : frees the joystick
655   */
656 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
657 {
658     JoystickImpl *This = (JoystickImpl *)iface;
659     HRESULT res;
660
661     TRACE("(%p)\n",This);
662
663     if ((res = IDirectInputDevice2AImpl_Unacquire(iface)) != DI_OK) return res;
664
665     if (This->joyfd!=-1) {
666         TRACE("closing joystick device\n");
667         close(This->joyfd);
668         This->joyfd = -1;
669         return DI_OK;
670     }
671
672     return DI_NOEFFECT;
673 }
674
675 static void joy_polldev(JoystickImpl *This) {
676     struct pollfd plfd;
677     struct      js_event jse;
678     TRACE("(%p)\n", This);
679
680     if (This->joyfd==-1) {
681         WARN("no device\n");
682         return;
683     }
684     while (1)
685     {
686         LONG value;
687         int inst_id = -1;
688
689         plfd.fd = This->joyfd;
690         plfd.events = POLLIN;
691         if (poll(&plfd,1,0) != 1)
692             return;
693         /* we have one event, so we can read */
694         if (sizeof(jse)!=read(This->joyfd,&jse,sizeof(jse))) {
695             return;
696         }
697         TRACE("js_event: type 0x%x, number %d, value %d\n",
698               jse.type,jse.number,jse.value);
699         if (jse.type & JS_EVENT_BUTTON)
700         {
701             inst_id = DIDFT_MAKEINSTANCE(jse.number) | DIDFT_PSHBUTTON;
702             This->js.rgbButtons[jse.number] = value = jse.value ? 0x80 : 0x00;
703         }
704         else if (jse.type & JS_EVENT_AXIS)
705         {
706             int number = This->axis_map[jse.number];    /* wine format object index */
707
708             if (number < 0) return;
709             inst_id = DIDFT_MAKEINSTANCE(number) | (number < 8 ? DIDFT_ABSAXIS : DIDFT_POV);
710             value = joystick_map_axis(&This->props[id_to_object(This->base.data_format.wine_df, inst_id)], jse.value);
711
712             TRACE("changing axis %d => %d\n", jse.number, number);
713             switch (number)
714             {
715                 case 0: This->js.lX  = value; break;
716                 case 1: This->js.lY  = value; break;
717                 case 2: This->js.lZ  = value; break;
718                 case 3: This->js.lRx = value; break;
719                 case 4: This->js.lRy = value; break;
720                 case 5: This->js.lRz = value; break;
721                 case 6: This->js.rglSlider[0] = value; break;
722                 case 7: This->js.rglSlider[1] = value; break;
723                 case 8: case 9: case 10: case 11:
724                 {
725                     int idx = number - 8;
726
727                     if (jse.number % 2)
728                         This->povs[idx].y = jse.value;
729                     else
730                         This->povs[idx].x = jse.value;
731
732                     This->js.rgdwPOV[idx] = value = joystick_map_pov(&This->povs[idx]);
733                     break;
734                 }
735                 default:
736                     WARN("axis %d not supported\n", number);
737             }
738         }
739         if (inst_id >= 0)
740             queue_event((LPDIRECTINPUTDEVICE8A)This,
741                         id_to_offset(&This->base.data_format, inst_id),
742                         value, jse.time, This->base.dinput->evsequence++);
743     }
744 }
745
746 /******************************************************************************
747   *     GetDeviceState : returns the "state" of the joystick.
748   *
749   */
750 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
751     LPDIRECTINPUTDEVICE8A iface,
752     DWORD len,
753     LPVOID ptr)
754 {
755     JoystickImpl *This = (JoystickImpl *)iface;
756
757     TRACE("(%p,0x%08x,%p)\n", This, len, ptr);
758
759     if (!This->base.acquired) {
760         WARN("not acquired\n");
761         return DIERR_NOTACQUIRED;
762     }
763
764     /* update joystick state */
765     joy_polldev(This);
766
767     /* convert and copy data to user supplied buffer */
768     fill_DataFormat(ptr, &This->js, &This->base.data_format);
769
770     return DI_OK;
771 }
772
773 /******************************************************************************
774   *     SetProperty : change input device properties
775   */
776 static HRESULT WINAPI JoystickAImpl_SetProperty(
777     LPDIRECTINPUTDEVICE8A iface,
778     REFGUID rguid,
779     LPCDIPROPHEADER ph)
780 {
781     JoystickImpl *This = (JoystickImpl *)iface;
782     int i;
783
784     TRACE("(%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
785
786     if (ph == NULL) {
787         WARN("invalid parameter: ph == NULL\n");
788         return DIERR_INVALIDPARAM;
789     }
790
791     if (TRACE_ON(dinput))
792         _dump_DIPROPHEADER(ph);
793
794     if (!HIWORD(rguid)) {
795         switch (LOWORD(rguid)) {
796         case (DWORD)DIPROP_RANGE: {
797             LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
798             if (ph->dwHow == DIPH_DEVICE) {
799                 TRACE("proprange(%d,%d) all\n", pr->lMin, pr->lMax);
800                 for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++) {
801                     This->props[i].lMin = pr->lMin;
802                     This->props[i].lMax = pr->lMax;
803                 }
804             } else {
805                 int obj = find_property(&This->base.data_format, ph);
806
807                 TRACE("proprange(%d,%d) obj=%d\n", pr->lMin, pr->lMax, obj);
808                 if (obj >= 0) {
809                     This->props[obj].lMin = pr->lMin;
810                     This->props[obj].lMax = pr->lMax;
811                     return DI_OK;
812                 }
813             }
814             break;
815         }
816         case (DWORD)DIPROP_DEADZONE: {
817             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
818             if (ph->dwHow == DIPH_DEVICE) {
819                 TRACE("deadzone(%d) all\n", pd->dwData);
820                 for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++)
821                     This->props[i].lDeadZone  = pd->dwData;
822             } else {
823                 int obj = find_property(&This->base.data_format, ph);
824
825                 TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
826                 if (obj >= 0) {
827                     This->props[obj].lDeadZone  = pd->dwData;
828                     return DI_OK;
829                 }
830             }
831             break;
832         }
833         case (DWORD)DIPROP_SATURATION: {
834             LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
835             if (ph->dwHow == DIPH_DEVICE) {
836                 TRACE("saturation(%d) all\n", pd->dwData);
837                 for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++)
838                     This->props[i].lSaturation = pd->dwData;
839             } else {
840                 int obj = find_property(&This->base.data_format, ph);
841
842                 TRACE("saturation(%d) obj=%d\n", pd->dwData, obj);
843                 if (obj >= 0) {
844                     This->props[obj].lSaturation = pd->dwData;
845                     return DI_OK;
846                 }
847             }
848             break;
849         }
850         default:
851             return IDirectInputDevice2AImpl_SetProperty(iface, rguid, ph);
852         }
853     }
854
855     return DI_OK;
856 }
857
858 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
859         LPDIRECTINPUTDEVICE8A iface,
860         LPDIDEVCAPS lpDIDevCaps)
861 {
862     JoystickImpl *This = (JoystickImpl *)iface;
863     int size;
864
865     TRACE("%p->(%p)\n",iface,lpDIDevCaps);
866
867     if (lpDIDevCaps == NULL) {
868         WARN("invalid pointer\n");
869         return E_POINTER;
870     }
871
872     size = lpDIDevCaps->dwSize;
873
874     if (!(size == sizeof(DIDEVCAPS) || size == sizeof(DIDEVCAPS_DX3))) {
875         WARN("invalid parameter\n");
876         return DIERR_INVALIDPARAM;
877     }
878
879     CopyMemory(lpDIDevCaps, &This->devcaps, size);
880     lpDIDevCaps->dwSize = size;
881
882     if (TRACE_ON(dinput))
883         _dump_DIDEVCAPS(lpDIDevCaps);
884
885     return DI_OK;
886 }
887
888 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface)
889 {
890     JoystickImpl *This = (JoystickImpl *)iface;
891
892     TRACE("(%p)\n",This);
893
894     if (!This->base.acquired) {
895         WARN("not acquired\n");
896         return DIERR_NOTACQUIRED;
897     }
898
899     joy_polldev(This);
900     return DI_OK;
901 }
902
903 /******************************************************************************
904   *     GetProperty : get input device properties
905   */
906 static HRESULT WINAPI JoystickAImpl_GetProperty(
907     LPDIRECTINPUTDEVICE8A iface,
908     REFGUID rguid,
909     LPDIPROPHEADER pdiph)
910 {
911     JoystickImpl *This = (JoystickImpl *)iface;
912
913     TRACE("(%p,%s,%p)\n", iface, debugstr_guid(rguid), pdiph);
914
915     if (TRACE_ON(dinput))
916         _dump_DIPROPHEADER(pdiph);
917
918     if (!HIWORD(rguid)) {
919         switch (LOWORD(rguid)) {
920         case (DWORD) DIPROP_RANGE: {
921             LPDIPROPRANGE pr = (LPDIPROPRANGE)pdiph;
922             int obj = find_property(&This->base.data_format, pdiph);
923
924             /* The app is querying the current range of the axis
925              * return the lMin and lMax values */
926             if (obj >= 0) {
927                 pr->lMin = This->props[obj].lMin;
928                 pr->lMax = This->props[obj].lMax;
929                 TRACE("range(%d, %d) obj=%d\n", pr->lMin, pr->lMax, obj);
930                 return DI_OK;
931             }
932             break;
933         }
934         case (DWORD) DIPROP_DEADZONE: {
935             LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
936             int obj = find_property(&This->base.data_format, pdiph);
937
938             if (obj >= 0) {
939                 pd->dwData = This->props[obj].lDeadZone;
940                 TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
941                 return DI_OK;
942             }
943             break;
944         }
945         case (DWORD) DIPROP_SATURATION: {
946             LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
947             int obj = find_property(&This->base.data_format, pdiph);
948
949             if (obj >= 0) {
950                 pd->dwData = This->props[obj].lSaturation;
951                 TRACE("saturation(%d) obj=%d\n", pd->dwData, obj);
952                 return DI_OK;
953             }
954             break;
955         }
956         default:
957             return IDirectInputDevice2AImpl_GetProperty(iface, rguid, pdiph);
958         }
959     }
960
961     return DI_OK;
962 }
963
964 /******************************************************************************
965   *     GetObjectInfo : get object info
966   */
967 static HRESULT WINAPI JoystickWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
968         LPDIDEVICEOBJECTINSTANCEW pdidoi, DWORD dwObj, DWORD dwHow)
969 {
970     static const WCHAR axisW[] = {'A','x','i','s',' ','%','d',0};
971     static const WCHAR povW[] = {'P','O','V',' ','%','d',0};
972     static const WCHAR buttonW[] = {'B','u','t','t','o','n',' ','%','d',0};
973     HRESULT res;
974
975     res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
976     if (res != DI_OK) return res;
977
978     if      (pdidoi->dwType & DIDFT_AXIS)
979         sprintfW(pdidoi->tszName, axisW, DIDFT_GETINSTANCE(pdidoi->dwType));
980     else if (pdidoi->dwType & DIDFT_POV)
981         sprintfW(pdidoi->tszName, povW, DIDFT_GETINSTANCE(pdidoi->dwType));
982     else if (pdidoi->dwType & DIDFT_BUTTON)
983         sprintfW(pdidoi->tszName, buttonW, DIDFT_GETINSTANCE(pdidoi->dwType));
984
985     _dump_OBJECTINSTANCEW(pdidoi);
986     return res;
987 }
988
989 static HRESULT WINAPI JoystickAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface,
990         LPDIDEVICEOBJECTINSTANCEA pdidoi, DWORD dwObj, DWORD dwHow)
991 {
992     HRESULT res;
993     DIDEVICEOBJECTINSTANCEW didoiW;
994     DWORD dwSize = pdidoi->dwSize;
995
996     didoiW.dwSize = sizeof(didoiW);
997     res = JoystickWImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W)iface, &didoiW, dwObj, dwHow);
998     if (res != DI_OK) return res;
999
1000     memset(pdidoi, 0, pdidoi->dwSize);
1001     memcpy(pdidoi, &didoiW, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, tszName));
1002     pdidoi->dwSize = dwSize;
1003     WideCharToMultiByte(CP_ACP, 0, didoiW.tszName, -1, pdidoi->tszName,
1004                         sizeof(pdidoi->tszName), NULL, NULL);
1005
1006     return res;
1007 }
1008
1009 /******************************************************************************
1010   *     GetDeviceInfo : get information about a device's identity
1011   */
1012 static HRESULT WINAPI JoystickAImpl_GetDeviceInfo(
1013     LPDIRECTINPUTDEVICE8A iface,
1014     LPDIDEVICEINSTANCEA pdidi)
1015 {
1016     JoystickImpl *This = (JoystickImpl *)iface;
1017
1018     TRACE("(%p,%p)\n", iface, pdidi);
1019
1020     if (pdidi == NULL) {
1021         WARN("invalid pointer\n");
1022         return E_POINTER;
1023     }
1024
1025     if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
1026         (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA))) {
1027         WARN("invalid parameter: pdidi->dwSize = %d != %d or %d\n",
1028              pdidi->dwSize, sizeof(DIDEVICEINSTANCE_DX3A),
1029              sizeof(DIDEVICEINSTANCEA));
1030         return DIERR_INVALIDPARAM;
1031     }
1032
1033     /* Return joystick */
1034     pdidi->guidInstance = GUID_Joystick;
1035     pdidi->guidProduct = DInput_Wine_Joystick_GUID;
1036     /* we only support traditional joysticks for now */
1037     pdidi->dwDevType = This->devcaps.dwDevType;
1038     strcpy(pdidi->tszInstanceName, "Joystick");
1039     strcpy(pdidi->tszProductName, This->name);
1040     if (pdidi->dwSize > sizeof(DIDEVICEINSTANCE_DX3A)) {
1041         pdidi->guidFFDriver = GUID_NULL;
1042         pdidi->wUsagePage = 0;
1043         pdidi->wUsage = 0;
1044     }
1045
1046     return DI_OK;
1047 }
1048
1049 /******************************************************************************
1050   *     GetDeviceInfo : get information about a device's identity
1051   */
1052 static HRESULT WINAPI JoystickWImpl_GetDeviceInfo(
1053     LPDIRECTINPUTDEVICE8W iface,
1054     LPDIDEVICEINSTANCEW pdidi)
1055 {
1056     JoystickImpl *This = (JoystickImpl *)iface;
1057
1058     TRACE("(%p,%p)\n", iface, pdidi);
1059
1060     if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3W)) &&
1061         (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW))) {
1062         WARN("invalid parameter: pdidi->dwSize = %d != %d or %d\n",
1063              pdidi->dwSize, sizeof(DIDEVICEINSTANCE_DX3W),
1064              sizeof(DIDEVICEINSTANCEW));
1065         return DIERR_INVALIDPARAM;
1066     }
1067
1068     /* Return joystick */
1069     pdidi->guidInstance = GUID_Joystick;
1070     pdidi->guidProduct = DInput_Wine_Joystick_GUID;
1071     /* we only support traditional joysticks for now */
1072     pdidi->dwDevType = This->devcaps.dwDevType;
1073     MultiByteToWideChar(CP_ACP, 0, "Joystick", -1, pdidi->tszInstanceName, MAX_PATH);
1074     MultiByteToWideChar(CP_ACP, 0, This->name, -1, pdidi->tszProductName, MAX_PATH);
1075     if (pdidi->dwSize > sizeof(DIDEVICEINSTANCE_DX3W)) {
1076         pdidi->guidFFDriver = GUID_NULL;
1077         pdidi->wUsagePage = 0;
1078         pdidi->wUsage = 0;
1079     }
1080
1081     return DI_OK;
1082 }
1083
1084 static const IDirectInputDevice8AVtbl JoystickAvt =
1085 {
1086         IDirectInputDevice2AImpl_QueryInterface,
1087         IDirectInputDevice2AImpl_AddRef,
1088         IDirectInputDevice2AImpl_Release,
1089         JoystickAImpl_GetCapabilities,
1090         IDirectInputDevice2AImpl_EnumObjects,
1091         JoystickAImpl_GetProperty,
1092         JoystickAImpl_SetProperty,
1093         JoystickAImpl_Acquire,
1094         JoystickAImpl_Unacquire,
1095         JoystickAImpl_GetDeviceState,
1096         IDirectInputDevice2AImpl_GetDeviceData,
1097         IDirectInputDevice2AImpl_SetDataFormat,
1098         IDirectInputDevice2AImpl_SetEventNotification,
1099         IDirectInputDevice2AImpl_SetCooperativeLevel,
1100         JoystickAImpl_GetObjectInfo,
1101         JoystickAImpl_GetDeviceInfo,
1102         IDirectInputDevice2AImpl_RunControlPanel,
1103         IDirectInputDevice2AImpl_Initialize,
1104         IDirectInputDevice2AImpl_CreateEffect,
1105         IDirectInputDevice2AImpl_EnumEffects,
1106         IDirectInputDevice2AImpl_GetEffectInfo,
1107         IDirectInputDevice2AImpl_GetForceFeedbackState,
1108         IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1109         IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1110         IDirectInputDevice2AImpl_Escape,
1111         JoystickAImpl_Poll,
1112         IDirectInputDevice2AImpl_SendDeviceData,
1113         IDirectInputDevice7AImpl_EnumEffectsInFile,
1114         IDirectInputDevice7AImpl_WriteEffectToFile,
1115         IDirectInputDevice8AImpl_BuildActionMap,
1116         IDirectInputDevice8AImpl_SetActionMap,
1117         IDirectInputDevice8AImpl_GetImageInfo
1118 };
1119
1120 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1121 # define XCAST(fun)     (typeof(JoystickWvt.fun))
1122 #else
1123 # define XCAST(fun)     (void*)
1124 #endif
1125
1126 static const IDirectInputDevice8WVtbl JoystickWvt =
1127 {
1128         IDirectInputDevice2WImpl_QueryInterface,
1129         XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1130         XCAST(Release)IDirectInputDevice2AImpl_Release,
1131         XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1132         IDirectInputDevice2WImpl_EnumObjects,
1133         XCAST(GetProperty)JoystickAImpl_GetProperty,
1134         XCAST(SetProperty)JoystickAImpl_SetProperty,
1135         XCAST(Acquire)JoystickAImpl_Acquire,
1136         XCAST(Unacquire)JoystickAImpl_Unacquire,
1137         XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1138         XCAST(GetDeviceData)IDirectInputDevice2AImpl_GetDeviceData,
1139         XCAST(SetDataFormat)IDirectInputDevice2AImpl_SetDataFormat,
1140         XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
1141         XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1142         IDirectInputDevice2WImpl_GetObjectInfo,
1143         JoystickWImpl_GetDeviceInfo,
1144         XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1145         XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1146         XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
1147         IDirectInputDevice2WImpl_EnumEffects,
1148         IDirectInputDevice2WImpl_GetEffectInfo,
1149         XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
1150         XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1151         XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1152         XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1153         XCAST(Poll)JoystickAImpl_Poll,
1154         XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1155         IDirectInputDevice7WImpl_EnumEffectsInFile,
1156         IDirectInputDevice7WImpl_WriteEffectToFile,
1157         IDirectInputDevice8WImpl_BuildActionMap,
1158         IDirectInputDevice8WImpl_SetActionMap,
1159         IDirectInputDevice8WImpl_GetImageInfo
1160 };
1161 #undef XCAST
1162
1163 #else  /* HAVE_LINUX_22_JOYSTICK_API */
1164
1165 const struct dinput_device joystick_linux_device = {
1166   "Wine Linux joystick driver",
1167   NULL,
1168   NULL,
1169   NULL,
1170   NULL
1171 };
1172
1173 #endif  /* HAVE_LINUX_22_JOYSTICK_API */