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