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