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