1 /* DirectInput Joystick device
3 * Copyright 1998,2000 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
6 * Copyright 2005 Daniel Remenak
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
34 #ifdef HAVE_SYS_TIME_H
35 # include <sys/time.h>
38 #ifdef HAVE_SYS_IOCTL_H
39 # include <sys/ioctl.h>
42 #ifdef HAVE_SYS_ERRNO_H
43 # include <sys/errno.h>
45 #ifdef HAVE_LINUX_INPUT_H
46 # include <linux/input.h>
48 # if defined(EVIOCGBIT) && defined(EV_ABS) && defined(BTN_PINKIE)
49 # define HAVE_CORRECT_LINUXINPUT_H
52 #ifdef HAVE_SYS_POLL_H
53 # include <sys/poll.h>
56 #include "wine/debug.h"
57 #include "wine/unicode.h"
58 #include "wine/list.h"
65 #include "dinput_private.h"
66 #include "device_private.h"
67 #include "joystick_private.h"
69 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
71 #ifdef HAVE_CORRECT_LINUXINPUT_H
73 #define EVDEVPREFIX "/dev/input/event"
75 /* Wine joystick driver object instances */
76 #define WINE_JOYSTICK_MAX_AXES 8
77 #define WINE_JOYSTICK_MAX_POVS 4
78 #define WINE_JOYSTICK_MAX_BUTTONS 128
80 struct wine_input_absinfo
{
88 /* implemented in effect_linuxinput.c */
89 HRESULT
linuxinput_create_effect(int* fd
, REFGUID rguid
, struct list
*parent_list_entry
, LPDIRECTINPUTEFFECT
* peff
);
90 HRESULT
linuxinput_get_info_A(int fd
, REFGUID rguid
, LPDIEFFECTINFOA info
);
91 HRESULT
linuxinput_get_info_W(int fd
, REFGUID rguid
, LPDIEFFECTINFOW info
);
93 typedef struct JoystickImpl JoystickImpl
;
94 static const IDirectInputDevice8AVtbl JoystickAvt
;
95 static const IDirectInputDevice8WVtbl JoystickWvt
;
105 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
106 BYTE evbits
[(EV_MAX
+7)/8];
107 BYTE absbits
[(ABS_MAX
+7)/8];
108 BYTE keybits
[(KEY_MAX
+7)/8];
109 BYTE ffbits
[(FF_MAX
+7)/8];
111 /* data returned by the EVIOCGABS() ioctl */
112 struct wine_input_absinfo axes
[ABS_MAX
];
117 struct JoystickGenericImpl generic
;
118 struct JoyDev
*joydev
;
120 /* joystick private */
123 int dev_axes_to_di
[ABS_MAX
];
126 /* LUT for KEY_ to offset in rgbButtons */
127 BYTE buttons
[KEY_MAX
];
129 /* Force feedback variables */
130 struct list ff_effects
;
136 static void fake_current_js_state(JoystickImpl
*ji
);
137 static void find_joydevs(void);
138 static void joy_polldev(JoystickGenericImpl
*This
);
140 /* This GUID is slightly different from the linux joystick one. Take note. */
141 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
145 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
148 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
150 #define MAX_JOYDEV 64
152 static int have_joydevs
= -1;
153 static struct JoyDev
*joydevs
= NULL
;
155 static void find_joydevs(void)
159 if (InterlockedCompareExchange(&have_joydevs
, 0, -1) != -1)
160 /* Someone beat us to it */
163 for (i
= 0; i
< MAX_JOYDEV
; i
++)
166 struct JoyDev joydev
= {0};
170 struct JoyDev
*new_joydevs
;
172 snprintf(buf
, sizeof(buf
), EVDEVPREFIX
"%d", i
);
174 if ((fd
= open(buf
, O_RDWR
)) == -1)
176 fd
= open(buf
, O_RDONLY
);
182 WARN("Failed to open \"%s\": %d %s\n", buf
, errno
, strerror(errno
));
186 if (ioctl(fd
, EVIOCGBIT(0, sizeof(joydev
.evbits
)), joydev
.evbits
) == -1)
188 WARN("ioct(EVIOCGBIT, 0) failed: %d %s\n", errno
, strerror(errno
));
192 if (ioctl(fd
, EVIOCGBIT(EV_ABS
, sizeof(joydev
.absbits
)), joydev
.absbits
) == -1)
194 WARN("ioct(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
198 if (ioctl(fd
, EVIOCGBIT(EV_KEY
, sizeof(joydev
.keybits
)), joydev
.keybits
) == -1)
200 WARN("ioct(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno
, strerror(errno
));
205 /* A true joystick has at least axis X and Y, and at least 1
206 * button. copied from linux/drivers/input/joydev.c */
207 if (!test_bit(joydev
.absbits
, ABS_X
) || !test_bit(joydev
.absbits
, ABS_Y
) ||
208 !(test_bit(joydev
.keybits
, BTN_TRIGGER
) ||
209 test_bit(joydev
.keybits
, BTN_A
) ||
210 test_bit(joydev
.keybits
, BTN_1
)))
216 if (!(joydev
.device
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
221 strcpy(joydev
.device
, buf
);
223 buf
[MAX_PATH
- 1] = 0;
224 if (ioctl(fd
, EVIOCGNAME(MAX_PATH
- 1), buf
) != -1 &&
225 (joydev
.name
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
226 strcpy(joydev
.name
, buf
);
228 joydev
.name
= joydev
.device
;
230 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
231 joydev
.guid
.Data3
+= have_joydevs
;
233 TRACE("Found a joystick on %s: %s (%s)\n",
234 joydev
.device
, joydev
.name
,
235 debugstr_guid(&joydev
.guid
)
238 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
240 test_bit(joydev
.evbits
, EV_FF
) &&
241 ioctl(fd
, EVIOCGBIT(EV_FF
, sizeof(joydev
.ffbits
)), joydev
.ffbits
) != -1 &&
242 ioctl(fd
, EVIOCGEFFECTS
, &joydev
.num_effects
) != -1 &&
243 joydev
.num_effects
> 0)
245 TRACE(" ... with force feedback\n");
250 for (j
= 0; j
< ABS_MAX
;j
++)
252 if (!test_bit(joydev
.absbits
, j
)) continue;
253 if (ioctl(fd
, EVIOCGABS(j
), &(joydev
.axes
[j
])) != -1)
255 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
257 joydev
.axes
[j
].value
,
258 joydev
.axes
[j
].minimum
,
259 joydev
.axes
[j
].maximum
,
267 new_joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
269 new_joydevs
= HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1 + have_joydevs
) * sizeof(struct JoyDev
));
276 joydevs
= new_joydevs
;
277 memcpy(joydevs
+ have_joydevs
, &joydev
, sizeof(joydev
));
284 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
286 DWORD dwSize
= lpddi
->dwSize
;
288 TRACE("%d %p\n", dwSize
, lpddi
);
289 memset(lpddi
, 0, dwSize
);
291 lpddi
->dwSize
= dwSize
;
292 lpddi
->guidInstance
= joydevs
[id
].guid
;
293 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
294 lpddi
->guidFFDriver
= GUID_NULL
;
296 if (version
>= 0x0800)
297 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
299 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
301 strcpy(lpddi
->tszInstanceName
, joydevs
[id
].name
);
302 strcpy(lpddi
->tszProductName
, joydevs
[id
].name
);
305 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
307 DWORD dwSize
= lpddi
->dwSize
;
309 TRACE("%d %p\n", dwSize
, lpddi
);
310 memset(lpddi
, 0, dwSize
);
312 lpddi
->dwSize
= dwSize
;
313 lpddi
->guidInstance
= joydevs
[id
].guid
;
314 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
315 lpddi
->guidFFDriver
= GUID_NULL
;
317 if (version
>= 0x0800)
318 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
320 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
322 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
323 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszProductName
, MAX_PATH
);
326 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
330 if (id
>= have_joydevs
) {
334 if (!((dwDevType
== 0) ||
335 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
336 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
339 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
340 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
344 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
345 fill_joystick_dideviceinstanceA(lpddi
, version
, id
);
351 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
355 if (id
>= have_joydevs
) {
359 if (!((dwDevType
== 0) ||
360 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
361 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
364 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
365 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
369 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
370 fill_joystick_dideviceinstanceW(lpddi
, version
, id
);
376 static JoystickImpl
*alloc_device(REFGUID rguid
, const void *jvt
, IDirectInputImpl
*dinput
, unsigned short index
)
378 JoystickImpl
* newDevice
;
379 LPDIDATAFORMAT df
= NULL
;
382 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
383 if (!newDevice
) return NULL
;
385 newDevice
->generic
.base
.lpVtbl
= jvt
;
386 newDevice
->generic
.base
.ref
= 1;
387 newDevice
->generic
.base
.guid
= *rguid
;
388 newDevice
->generic
.base
.dinput
= dinput
;
389 newDevice
->generic
.joy_polldev
= joy_polldev
;
390 newDevice
->joyfd
= -1;
391 newDevice
->joydev
= &joydevs
[index
];
392 newDevice
->generic
.name
= newDevice
->joydev
->name
;
393 list_init(&newDevice
->ff_effects
);
394 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
395 newDevice
->ff_state
= FF_STATUS_STOPPED
;
397 /* There is no way in linux to query force feedback autocenter status.
398 Instead, track it with ff_autocenter, and assume it's initialy
400 newDevice
->ff_autocenter
= 1;
401 newDevice
->ff_gain
= 0xFFFF;
402 InitializeCriticalSection(&newDevice
->generic
.base
.crit
);
403 newDevice
->generic
.base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
405 /* Count number of available axes - supported Axis & POVs */
406 for (i
= 0; i
< WINE_JOYSTICK_MAX_AXES
; i
++)
408 if (test_bit(newDevice
->joydev
->absbits
, i
))
410 newDevice
->generic
.device_axis_count
++;
411 newDevice
->dev_axes_to_di
[i
] = idx
;
412 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[i
].minimum
;
413 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[i
].maximum
;
417 newDevice
->dev_axes_to_di
[i
] = -1;
420 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
422 if (test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) &&
423 test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2))
425 newDevice
->generic
.device_axis_count
+= 2;
426 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].minimum
;
427 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = idx
++;
428 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].maximum
;
429 newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = idx
++;
432 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = -1;
435 /* do any user specified configuration */
436 if (setup_dinput_options(&newDevice
->generic
) != DI_OK
) goto failed
;
438 /* Create copy of default data format */
439 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
440 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
441 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
444 /* Construct internal data format */
446 /* Supported Axis & POVs */
447 for (i
= 0, idx
= 0; i
< newDevice
->generic
.device_axis_count
; i
++)
449 int wine_obj
= newDevice
->generic
.axis_map
[i
];
451 if (wine_obj
< 0) continue;
453 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[wine_obj
], df
->dwObjSize
);
455 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
) | DIDFT_ABSAXIS
;
458 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
- 8) | DIDFT_POV
;
459 i
++; /* POV takes 2 axes */
462 newDevice
->generic
.props
[idx
].lMin
= 0;
463 newDevice
->generic
.props
[idx
].lMax
= 0xffff;
464 newDevice
->generic
.props
[idx
].lSaturation
= 0;
465 newDevice
->generic
.props
[idx
].lDeadZone
= newDevice
->generic
.deadzone
;
467 /* Linux supports force-feedback on X & Y axes only */
468 if (newDevice
->joydev
->has_ff
&& (i
== 0 || i
== 1))
469 df
->rgodf
[idx
].dwFlags
|= DIDOI_FFACTUATOR
;
474 /* Buttons can be anywhere, so check all */
475 for (i
= 0; i
< KEY_MAX
&& newDevice
->generic
.devcaps
.dwButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
477 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
479 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->generic
.devcaps
.dwButtons
+ 12], df
->dwObjSize
);
480 newDevice
->buttons
[i
] = 0x80 | newDevice
->generic
.devcaps
.dwButtons
;
481 df
->rgodf
[idx
].pguid
= &GUID_Button
;
482 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->generic
.devcaps
.dwButtons
++) | DIDFT_PSHBUTTON
;
485 newDevice
->generic
.base
.data_format
.wine_df
= df
;
487 fake_current_js_state(newDevice
);
490 newDevice
->generic
.devcaps
.dwSize
= sizeof(newDevice
->generic
.devcaps
);
491 newDevice
->generic
.devcaps
.dwFlags
= DIDC_ATTACHED
;
492 if (newDevice
->generic
.base
.dinput
->dwVersion
>= 0x0800)
493 newDevice
->generic
.devcaps
.dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
495 newDevice
->generic
.devcaps
.dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
497 if (newDevice
->joydev
->has_ff
)
498 newDevice
->generic
.devcaps
.dwFlags
|= DIDC_FORCEFEEDBACK
;
500 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A
)newDevice
->generic
.base
.dinput
);
504 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
505 HeapFree(GetProcessHeap(), 0, df
);
506 HeapFree(GetProcessHeap(), 0, newDevice
->generic
.axis_map
);
507 HeapFree(GetProcessHeap(), 0, newDevice
);
511 /******************************************************************************
512 * get_joystick_index : Get the joystick index from a given GUID
514 static unsigned short get_joystick_index(REFGUID guid
)
516 GUID wine_joystick
= DInput_Wine_Joystick_Base_GUID
;
517 GUID dev_guid
= *guid
;
519 wine_joystick
.Data3
= 0;
522 /* for the standard joystick GUID use index 0 */
523 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
525 /* for the wine joystick GUIDs use the index stored in Data3 */
526 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
- DInput_Wine_Joystick_Base_GUID
.Data3
;
531 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
533 unsigned short index
;
537 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
538 have_joydevs
&& index
< have_joydevs
)
540 if ((riid
== NULL
) ||
541 IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
542 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
543 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
544 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
546 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &JoystickAvt
, dinput
, index
);
547 TRACE("Created a Joystick device (%p)\n", *pdev
);
551 ERR("out of memory\n");
552 return DIERR_OUTOFMEMORY
;
557 WARN("no interface\n");
558 return DIERR_NOINTERFACE
;
561 return DIERR_DEVICENOTREG
;
565 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
567 unsigned short index
;
571 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
572 have_joydevs
&& index
< have_joydevs
)
574 if ((riid
== NULL
) ||
575 IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
576 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
577 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
578 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
580 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &JoystickWvt
, dinput
, index
);
581 TRACE("Created a Joystick device (%p)\n", *pdev
);
585 ERR("out of memory\n");
586 return DIERR_OUTOFMEMORY
;
590 WARN("no interface\n");
591 return DIERR_NOINTERFACE
;
594 WARN("invalid device GUID\n");
595 return DIERR_DEVICENOTREG
;
598 const struct dinput_device joystick_linuxinput_device
= {
599 "Wine Linux-input joystick driver",
602 joydev_create_deviceA
,
603 joydev_create_deviceW
606 /******************************************************************************
607 * Acquire : gets exclusive control of the joystick
609 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
611 JoystickImpl
*This
= (JoystickImpl
*)iface
;
614 TRACE("(this=%p)\n",This
);
616 if ((res
= IDirectInputDevice2AImpl_Acquire(iface
)) != DI_OK
)
618 WARN("Failed to acquire: %x\n", res
);
622 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDWR
)) == -1)
624 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDONLY
)) == -1)
626 /* Couldn't open the device at all */
627 ERR("Failed to open device %s: %d %s\n", This
->joydev
->device
, errno
, strerror(errno
));
628 IDirectInputDevice2AImpl_Unacquire(iface
);
629 return DIERR_NOTFOUND
;
633 /* Couldn't open in r/w but opened in read-only. */
634 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
639 struct input_event event
;
642 event
.code
= FF_GAIN
;
643 event
.value
= This
->ff_gain
;
644 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
645 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
646 if (!This
->ff_autocenter
)
648 /* Disable autocenter. */
649 event
.code
= FF_AUTOCENTER
;
651 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
652 ERR("Failed disabling autocenter: %d %s\n", errno
, strerror(errno
));
659 /******************************************************************************
660 * Unacquire : frees the joystick
662 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
664 JoystickImpl
*This
= (JoystickImpl
*)iface
;
667 TRACE("(this=%p)\n",This
);
668 res
= IDirectInputDevice2AImpl_Unacquire(iface
);
669 if (res
==DI_OK
&& This
->joyfd
!=-1) {
670 effect_list_item
*itr
;
671 struct input_event event
;
673 /* For each known effect:
676 * But, unlike DISFFC_RESET, do not release the effect.
678 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
) {
679 IDirectInputEffect_Stop(itr
->ref
);
680 IDirectInputEffect_Unload(itr
->ref
);
683 /* Enable autocenter. */
685 event
.code
= FF_AUTOCENTER
;
686 /* TODO: Read autocenter strengh before disabling it, and use it here
687 * instead of 0xFFFF (maximum strengh).
689 event
.value
= 0xFFFF;
690 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
691 ERR("Failed to set autocenter to %04x: %d %s\n", event
.value
, errno
, strerror(errno
));
700 * set the current state of the js device as it would be with the middle
703 #define CENTER_AXIS(a) \
704 (ji->dev_axes_to_di[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->dev_axes_to_di[a]], \
705 ji->joydev->axes[a].value ))
706 static void fake_current_js_state(JoystickImpl
*ji
)
710 /* center the axes */
711 ji
->generic
.js
.lX
= CENTER_AXIS(ABS_X
);
712 ji
->generic
.js
.lY
= CENTER_AXIS(ABS_Y
);
713 ji
->generic
.js
.lZ
= CENTER_AXIS(ABS_Z
);
714 ji
->generic
.js
.lRx
= CENTER_AXIS(ABS_RX
);
715 ji
->generic
.js
.lRy
= CENTER_AXIS(ABS_RY
);
716 ji
->generic
.js
.lRz
= CENTER_AXIS(ABS_RZ
);
717 ji
->generic
.js
.rglSlider
[0] = CENTER_AXIS(ABS_THROTTLE
);
718 ji
->generic
.js
.rglSlider
[1] = CENTER_AXIS(ABS_RUDDER
);
720 /* POV center is -1 */
721 for (i
= 0; i
< 4; i
++)
722 ji
->generic
.js
.rgdwPOV
[i
] = -1;
726 /* convert wine format offset to user format object index */
727 static void joy_polldev(JoystickGenericImpl
*iface
)
730 struct input_event ie
;
731 JoystickImpl
*This
= (JoystickImpl
*) iface
;
741 plfd
.fd
= This
->joyfd
;
742 plfd
.events
= POLLIN
;
744 if (poll(&plfd
,1,0) != 1)
747 /* we have one event, so we can read */
748 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
751 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
753 case EV_KEY
: /* button */
755 int btn
= This
->buttons
[ie
.code
];
757 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
761 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
762 This
->generic
.js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
768 int axis
= This
->dev_axes_to_di
[ie
.code
];
770 /* User axis remapping */
772 axis
= This
->generic
.axis_map
[axis
];
775 inst_id
= DIDFT_MAKEINSTANCE(axis
) | (axis
< 8 ? DIDFT_ABSAXIS
: DIDFT_POV
);
776 value
= joystick_map_axis(&This
->generic
.props
[id_to_object(This
->generic
.base
.data_format
.wine_df
, inst_id
)], ie
.value
);
779 case 0: This
->generic
.js
.lX
= value
; break;
780 case 1: This
->generic
.js
.lY
= value
; break;
781 case 2: This
->generic
.js
.lZ
= value
; break;
782 case 3: This
->generic
.js
.lRx
= value
; break;
783 case 4: This
->generic
.js
.lRy
= value
; break;
784 case 5: This
->generic
.js
.lRz
= value
; break;
785 case 6: This
->generic
.js
.rglSlider
[0] = value
; break;
786 case 7: This
->generic
.js
.rglSlider
[1] = value
; break;
787 case 8: case 9: case 10: case 11:
792 This
->povs
[idx
].y
= ie
.value
;
794 This
->povs
[idx
].x
= ie
.value
;
796 This
->generic
.js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
800 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
804 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
806 This
->ff_state
= ie
.value
;
811 /* there is nothing to do */
815 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
819 queue_event((LPDIRECTINPUTDEVICE8A
)This
,
820 id_to_offset(&This
->generic
.base
.data_format
, inst_id
),
821 value
, ie
.time
.tv_usec
, This
->generic
.base
.dinput
->evsequence
++);
825 /******************************************************************************
826 * SetProperty : change input device properties
828 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
832 JoystickImpl
*This
= (JoystickImpl
*)iface
;
835 WARN("invalid argument\n");
836 return DIERR_INVALIDPARAM
;
839 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
840 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
841 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
843 if (!HIWORD(rguid
)) {
844 switch (LOWORD(rguid
)) {
845 case (DWORD_PTR
)DIPROP_CALIBRATIONMODE
: {
846 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
847 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd
->dwData
);
850 case (DWORD_PTR
)DIPROP_AUTOCENTER
: {
851 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
853 TRACE("autocenter(%d)\n", pd
->dwData
);
854 This
->ff_autocenter
= pd
->dwData
== DIPROPAUTOCENTER_ON
;
858 case (DWORD_PTR
)DIPROP_FFGAIN
: {
859 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
861 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
862 This
->ff_gain
= MulDiv(pd
->dwData
, 0xFFFF, 10000);
863 if (This
->generic
.base
.acquired
) {
864 /* Update immediately. */
865 struct input_event event
;
868 event
.code
= FF_GAIN
;
869 event
.value
= This
->ff_gain
;
870 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
871 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
876 return JoystickAGenericImpl_SetProperty(iface
, rguid
, ph
);
882 /******************************************************************************
883 * GetProperty : get input device properties
885 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
887 LPDIPROPHEADER pdiph
)
889 JoystickImpl
*This
= (JoystickImpl
*)iface
;
891 TRACE("(this=%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
892 _dump_DIPROPHEADER(pdiph
);
894 if (HIWORD(rguid
)) return DI_OK
;
896 switch (LOWORD(rguid
)) {
897 case (DWORD_PTR
) DIPROP_AUTOCENTER
:
899 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
901 pd
->dwData
= This
->ff_autocenter
? DIPROPAUTOCENTER_ON
: DIPROPAUTOCENTER_OFF
;
902 TRACE("autocenter(%d)\n", pd
->dwData
);
905 case (DWORD_PTR
) DIPROP_FFGAIN
:
907 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
909 pd
->dwData
= MulDiv(This
->ff_gain
, 10000, 0xFFFF);
910 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
915 return JoystickAGenericImpl_GetProperty(iface
, rguid
, pdiph
);
921 /******************************************************************************
922 * CreateEffect - Create a new FF effect with the specified params
924 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
,
927 LPDIRECTINPUTEFFECT
*ppdef
,
930 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
931 effect_list_item
* new_effect
= NULL
;
932 HRESULT retval
= DI_OK
;
935 JoystickImpl
* This
= (JoystickImpl
*)iface
;
936 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
938 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
939 TRACE("not available (compiled w/o ff support)\n");
944 if (!(new_effect
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect
))))
945 return DIERR_OUTOFMEMORY
;
947 retval
= linuxinput_create_effect(&This
->joyfd
, rguid
, &new_effect
->entry
, &new_effect
->ref
);
950 HeapFree(GetProcessHeap(), 0, new_effect
);
956 retval
= IDirectInputEffect_SetParameters(new_effect
->ref
, lpeff
, 0);
958 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
960 HeapFree(GetProcessHeap(), 0, new_effect
);
965 list_add_tail(&This
->ff_effects
, &new_effect
->entry
);
966 *ppdef
= new_effect
->ref
;
968 if (pUnkOuter
!= NULL
)
969 FIXME("Interface aggregation not implemented.\n");
973 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
976 /*******************************************************************************
977 * EnumEffects - Enumerate available FF effects
979 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
980 LPDIENUMEFFECTSCALLBACKA lpCallback
,
984 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
985 DIEFFECTINFOA dei
; /* feif */
986 DWORD type
= DIEFT_GETTYPE(dwEffType
);
987 JoystickImpl
* This
= (JoystickImpl
*)iface
;
989 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
991 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
993 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
994 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
995 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
996 (*lpCallback
)(&dei
, pvRef
);
999 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1000 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1001 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1002 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1003 (*lpCallback
)(&dei
, pvRef
);
1005 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1006 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1007 (*lpCallback
)(&dei
, pvRef
);
1009 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1010 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1011 (*lpCallback
)(&dei
, pvRef
);
1013 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1014 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1015 (*lpCallback
)(&dei
, pvRef
);
1017 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1018 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1019 (*lpCallback
)(&dei
, pvRef
);
1023 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1024 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1025 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1026 (*lpCallback
)(&dei
, pvRef
);
1029 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1030 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1031 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1032 (*lpCallback
)(&dei
, pvRef
);
1034 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1035 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1036 (*lpCallback
)(&dei
, pvRef
);
1038 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1039 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1040 (*lpCallback
)(&dei
, pvRef
);
1042 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1043 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1044 (*lpCallback
)(&dei
, pvRef
);
1053 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1054 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1058 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1059 /* seems silly to duplicate all this code but all the structures and functions
1060 * are actually different (A/W) */
1061 DIEFFECTINFOW dei
; /* feif */
1062 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1063 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1064 int xfd
= This
->joyfd
;
1066 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1068 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1070 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1071 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1072 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1073 (*lpCallback
)(&dei
, pvRef
);
1076 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1077 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1078 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1079 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1080 (*lpCallback
)(&dei
, pvRef
);
1082 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1083 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1084 (*lpCallback
)(&dei
, pvRef
);
1086 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1087 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1088 (*lpCallback
)(&dei
, pvRef
);
1090 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1091 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1092 (*lpCallback
)(&dei
, pvRef
);
1094 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1095 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1096 (*lpCallback
)(&dei
, pvRef
);
1100 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1101 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1102 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1103 (*lpCallback
)(&dei
, pvRef
);
1106 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1107 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1108 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1109 (*lpCallback
)(&dei
, pvRef
);
1111 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1112 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1113 (*lpCallback
)(&dei
, pvRef
);
1115 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1116 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1117 (*lpCallback
)(&dei
, pvRef
);
1119 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1120 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1121 (*lpCallback
)(&dei
, pvRef
);
1125 /* return to unacquired state if that's where it was */
1127 IDirectInputDevice8_Unacquire(iface
);
1133 /*******************************************************************************
1134 * GetEffectInfo - Get information about a particular effect
1136 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1137 LPDIEFFECTINFOA pdei
,
1140 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1142 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1144 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1145 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1151 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1152 LPDIEFFECTINFOW pdei
,
1155 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1157 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1159 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1160 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1166 /*******************************************************************************
1167 * GetForceFeedbackState - Get information about the device's FF state
1169 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(
1170 LPDIRECTINPUTDEVICE8A iface
,
1173 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1175 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1179 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1180 /* DIGFFS_STOPPED is the only mandatory flag to report */
1181 if (This
->ff_state
== FF_STATUS_STOPPED
)
1182 (*pdwOut
) |= DIGFFS_STOPPED
;
1188 /*******************************************************************************
1189 * SendForceFeedbackCommand - Send a command to the device's FF system
1191 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(
1192 LPDIRECTINPUTDEVICE8A iface
,
1195 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1196 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1198 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1201 case DISFFC_STOPALL
:
1203 /* Stop all effects */
1204 effect_list_item
*itr
;
1206 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1207 IDirectInputEffect_Stop(itr
->ref
);
1213 effect_list_item
*itr
, *ptr
;
1215 /* Stop, unload, release and free all effects */
1216 /* This returns the device to its "bare" state */
1217 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1218 IDirectInputEffect_Release(itr
->ref
);
1222 case DISFFC_CONTINUE
:
1223 FIXME("No support for Pause or Continue in linux\n");
1226 case DISFFC_SETACTUATORSOFF
:
1227 case DISFFC_SETACTUATORSON
:
1228 FIXME("No direct actuator control in linux\n");
1232 FIXME("Unknown Force Feedback Command!\n");
1233 return DIERR_INVALIDPARAM
;
1237 return DIERR_UNSUPPORTED
;
1241 /*******************************************************************************
1242 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1243 * created for this device.
1245 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(
1246 LPDIRECTINPUTDEVICE8A iface
,
1247 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1251 /* this function is safe to call on non-ff-enabled builds */
1252 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1253 effect_list_item
*itr
, *ptr
;
1255 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1258 return DIERR_INVALIDPARAM
;
1261 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1263 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1264 (*lpCallback
)(itr
->ref
, pvRef
);
1269 /******************************************************************************
1270 * GetDeviceInfo : get information about a device's identity
1272 static HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface
,
1273 LPDIDEVICEINSTANCEA pdidi
)
1275 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1277 TRACE("(%p) %p\n", This
, pdidi
);
1279 if (pdidi
== NULL
) return E_POINTER
;
1280 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1281 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)))
1282 return DIERR_INVALIDPARAM
;
1284 fill_joystick_dideviceinstanceA(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1285 get_joystick_index(&This
->generic
.base
.guid
));
1289 static HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
,
1290 LPDIDEVICEINSTANCEW pdidi
)
1292 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1294 TRACE("(%p) %p\n", This
, pdidi
);
1296 if (pdidi
== NULL
) return E_POINTER
;
1297 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1298 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)))
1299 return DIERR_INVALIDPARAM
;
1301 fill_joystick_dideviceinstanceW(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1302 get_joystick_index(&This
->generic
.base
.guid
));
1306 static const IDirectInputDevice8AVtbl JoystickAvt
=
1308 IDirectInputDevice2AImpl_QueryInterface
,
1309 IDirectInputDevice2AImpl_AddRef
,
1310 IDirectInputDevice2AImpl_Release
,
1311 JoystickAGenericImpl_GetCapabilities
,
1312 IDirectInputDevice2AImpl_EnumObjects
,
1313 JoystickAImpl_GetProperty
,
1314 JoystickAImpl_SetProperty
,
1315 JoystickAImpl_Acquire
,
1316 JoystickAImpl_Unacquire
,
1317 JoystickAGenericImpl_GetDeviceState
,
1318 IDirectInputDevice2AImpl_GetDeviceData
,
1319 IDirectInputDevice2AImpl_SetDataFormat
,
1320 IDirectInputDevice2AImpl_SetEventNotification
,
1321 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1322 JoystickAGenericImpl_GetObjectInfo
,
1323 JoystickAImpl_GetDeviceInfo
,
1324 IDirectInputDevice2AImpl_RunControlPanel
,
1325 IDirectInputDevice2AImpl_Initialize
,
1326 JoystickAImpl_CreateEffect
,
1327 JoystickAImpl_EnumEffects
,
1328 JoystickAImpl_GetEffectInfo
,
1329 JoystickAImpl_GetForceFeedbackState
,
1330 JoystickAImpl_SendForceFeedbackCommand
,
1331 JoystickAImpl_EnumCreatedEffectObjects
,
1332 IDirectInputDevice2AImpl_Escape
,
1333 JoystickAGenericImpl_Poll
,
1334 IDirectInputDevice2AImpl_SendDeviceData
,
1335 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1336 IDirectInputDevice7AImpl_WriteEffectToFile
,
1337 IDirectInputDevice8AImpl_BuildActionMap
,
1338 IDirectInputDevice8AImpl_SetActionMap
,
1339 IDirectInputDevice8AImpl_GetImageInfo
1342 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1343 # define XCAST(fun) (typeof(JoystickWvt.fun))
1345 # define XCAST(fun) (void*)
1348 static const IDirectInputDevice8WVtbl JoystickWvt
=
1350 IDirectInputDevice2WImpl_QueryInterface
,
1351 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
1352 XCAST(Release
)IDirectInputDevice2AImpl_Release
,
1353 XCAST(GetCapabilities
)JoystickAGenericImpl_GetCapabilities
,
1354 IDirectInputDevice2WImpl_EnumObjects
,
1355 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1356 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1357 XCAST(Acquire
)JoystickAImpl_Acquire
,
1358 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1359 XCAST(GetDeviceState
)JoystickAGenericImpl_GetDeviceState
,
1360 XCAST(GetDeviceData
)IDirectInputDevice2AImpl_GetDeviceData
,
1361 XCAST(SetDataFormat
)IDirectInputDevice2AImpl_SetDataFormat
,
1362 XCAST(SetEventNotification
)IDirectInputDevice2AImpl_SetEventNotification
,
1363 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
1364 JoystickWGenericImpl_GetObjectInfo
,
1365 JoystickWImpl_GetDeviceInfo
,
1366 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
1367 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
1368 XCAST(CreateEffect
)JoystickAImpl_CreateEffect
,
1369 JoystickWImpl_EnumEffects
,
1370 JoystickWImpl_GetEffectInfo
,
1371 XCAST(GetForceFeedbackState
)JoystickAImpl_GetForceFeedbackState
,
1372 XCAST(SendForceFeedbackCommand
)JoystickAImpl_SendForceFeedbackCommand
,
1373 XCAST(EnumCreatedEffectObjects
)JoystickAImpl_EnumCreatedEffectObjects
,
1374 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1375 XCAST(Poll
)JoystickAGenericImpl_Poll
,
1376 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1377 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1378 IDirectInputDevice7WImpl_WriteEffectToFile
,
1379 IDirectInputDevice8WImpl_BuildActionMap
,
1380 IDirectInputDevice8WImpl_SetActionMap
,
1381 IDirectInputDevice8WImpl_GetImageInfo
1385 #else /* HAVE_CORRECT_LINUXINPUT_H */
1387 const struct dinput_device joystick_linuxinput_device
= {
1388 "Wine Linux-input joystick driver",
1395 #endif /* HAVE_CORRECT_LINUXINPUT_H */