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
;
381 int default_axis_map
[WINE_JOYSTICK_MAX_AXES
+ WINE_JOYSTICK_MAX_POVS
*2];
383 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
384 if (!newDevice
) return NULL
;
386 newDevice
->generic
.base
.lpVtbl
= jvt
;
387 newDevice
->generic
.base
.ref
= 1;
388 newDevice
->generic
.base
.guid
= *rguid
;
389 newDevice
->generic
.base
.dinput
= dinput
;
390 newDevice
->generic
.joy_polldev
= joy_polldev
;
391 newDevice
->joyfd
= -1;
392 newDevice
->joydev
= &joydevs
[index
];
393 newDevice
->generic
.name
= newDevice
->joydev
->name
;
394 list_init(&newDevice
->ff_effects
);
395 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
396 newDevice
->ff_state
= FF_STATUS_STOPPED
;
398 /* There is no way in linux to query force feedback autocenter status.
399 Instead, track it with ff_autocenter, and assume it's initialy
401 newDevice
->ff_autocenter
= 1;
402 newDevice
->ff_gain
= 0xFFFF;
403 InitializeCriticalSection(&newDevice
->generic
.base
.crit
);
404 newDevice
->generic
.base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
406 /* Count number of available axes - supported Axis & POVs */
407 for (i
= 0; i
< WINE_JOYSTICK_MAX_AXES
; i
++)
409 if (test_bit(newDevice
->joydev
->absbits
, i
))
411 newDevice
->generic
.device_axis_count
++;
412 newDevice
->dev_axes_to_di
[i
] = idx
;
413 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[i
].minimum
;
414 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[i
].maximum
;
415 default_axis_map
[idx
] = i
;
419 newDevice
->dev_axes_to_di
[i
] = -1;
422 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
424 if (test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) &&
425 test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2))
427 newDevice
->generic
.device_axis_count
+= 2;
428 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].minimum
;
429 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].maximum
;
430 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = idx
;
431 newDevice
->generic
.props
[idx
+1].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].minimum
;
432 newDevice
->generic
.props
[idx
+1].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].maximum
;
433 newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = idx
+ 1;
435 default_axis_map
[idx
] = default_axis_map
[idx
+ 1] = WINE_JOYSTICK_MAX_AXES
+ i
;
439 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = -1;
442 /* do any user specified configuration */
443 if (setup_dinput_options(&newDevice
->generic
, default_axis_map
) != DI_OK
) goto failed
;
445 /* Create copy of default data format */
446 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
447 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
448 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
451 /* Construct internal data format */
453 /* Supported Axis & POVs */
454 for (i
= 0, idx
= 0; i
< newDevice
->generic
.device_axis_count
; i
++)
456 int wine_obj
= newDevice
->generic
.axis_map
[i
];
458 if (wine_obj
< 0) continue;
460 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[wine_obj
], df
->dwObjSize
);
462 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
) | DIDFT_ABSAXIS
;
465 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
- 8) | DIDFT_POV
;
466 i
++; /* POV takes 2 axes */
469 newDevice
->generic
.props
[idx
].lMin
= 0;
470 newDevice
->generic
.props
[idx
].lMax
= 0xffff;
471 newDevice
->generic
.props
[idx
].lSaturation
= 0;
472 newDevice
->generic
.props
[idx
].lDeadZone
= newDevice
->generic
.deadzone
;
474 /* Linux supports force-feedback on X & Y axes only */
475 if (newDevice
->joydev
->has_ff
&& (i
== 0 || i
== 1))
476 df
->rgodf
[idx
].dwFlags
|= DIDOI_FFACTUATOR
;
481 /* Buttons can be anywhere, so check all */
482 for (i
= 0; i
< KEY_MAX
&& newDevice
->generic
.devcaps
.dwButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
484 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
486 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->generic
.devcaps
.dwButtons
+ 12], df
->dwObjSize
);
487 newDevice
->buttons
[i
] = 0x80 | newDevice
->generic
.devcaps
.dwButtons
;
488 df
->rgodf
[idx
].pguid
= &GUID_Button
;
489 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->generic
.devcaps
.dwButtons
++) | DIDFT_PSHBUTTON
;
492 newDevice
->generic
.base
.data_format
.wine_df
= df
;
494 fake_current_js_state(newDevice
);
497 newDevice
->generic
.devcaps
.dwSize
= sizeof(newDevice
->generic
.devcaps
);
498 newDevice
->generic
.devcaps
.dwFlags
= DIDC_ATTACHED
;
499 if (newDevice
->generic
.base
.dinput
->dwVersion
>= 0x0800)
500 newDevice
->generic
.devcaps
.dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
502 newDevice
->generic
.devcaps
.dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
504 if (newDevice
->joydev
->has_ff
)
505 newDevice
->generic
.devcaps
.dwFlags
|= DIDC_FORCEFEEDBACK
;
507 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A
)newDevice
->generic
.base
.dinput
);
511 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
512 HeapFree(GetProcessHeap(), 0, df
);
513 HeapFree(GetProcessHeap(), 0, newDevice
->generic
.axis_map
);
514 HeapFree(GetProcessHeap(), 0, newDevice
);
518 /******************************************************************************
519 * get_joystick_index : Get the joystick index from a given GUID
521 static unsigned short get_joystick_index(REFGUID guid
)
523 GUID wine_joystick
= DInput_Wine_Joystick_Base_GUID
;
524 GUID dev_guid
= *guid
;
526 wine_joystick
.Data3
= 0;
529 /* for the standard joystick GUID use index 0 */
530 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
532 /* for the wine joystick GUIDs use the index stored in Data3 */
533 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
- DInput_Wine_Joystick_Base_GUID
.Data3
;
538 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
540 unsigned short index
;
544 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
545 have_joydevs
&& index
< have_joydevs
)
547 if ((riid
== NULL
) ||
548 IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
549 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
550 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
551 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
553 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &JoystickAvt
, dinput
, index
);
554 TRACE("Created a Joystick device (%p)\n", *pdev
);
558 ERR("out of memory\n");
559 return DIERR_OUTOFMEMORY
;
564 WARN("no interface\n");
565 return DIERR_NOINTERFACE
;
568 return DIERR_DEVICENOTREG
;
572 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
574 unsigned short index
;
578 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
579 have_joydevs
&& index
< have_joydevs
)
581 if ((riid
== NULL
) ||
582 IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
583 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
584 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
585 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
587 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &JoystickWvt
, dinput
, index
);
588 TRACE("Created a Joystick device (%p)\n", *pdev
);
592 ERR("out of memory\n");
593 return DIERR_OUTOFMEMORY
;
597 WARN("no interface\n");
598 return DIERR_NOINTERFACE
;
601 WARN("invalid device GUID\n");
602 return DIERR_DEVICENOTREG
;
605 const struct dinput_device joystick_linuxinput_device
= {
606 "Wine Linux-input joystick driver",
609 joydev_create_deviceA
,
610 joydev_create_deviceW
613 /******************************************************************************
614 * Acquire : gets exclusive control of the joystick
616 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
618 JoystickImpl
*This
= (JoystickImpl
*)iface
;
621 TRACE("(this=%p)\n",This
);
623 if ((res
= IDirectInputDevice2AImpl_Acquire(iface
)) != DI_OK
)
625 WARN("Failed to acquire: %x\n", res
);
629 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDWR
)) == -1)
631 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDONLY
)) == -1)
633 /* Couldn't open the device at all */
634 ERR("Failed to open device %s: %d %s\n", This
->joydev
->device
, errno
, strerror(errno
));
635 IDirectInputDevice2AImpl_Unacquire(iface
);
636 return DIERR_NOTFOUND
;
640 /* Couldn't open in r/w but opened in read-only. */
641 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
646 struct input_event event
;
649 event
.code
= FF_GAIN
;
650 event
.value
= This
->ff_gain
;
651 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
652 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
653 if (!This
->ff_autocenter
)
655 /* Disable autocenter. */
656 event
.code
= FF_AUTOCENTER
;
658 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
659 ERR("Failed disabling autocenter: %d %s\n", errno
, strerror(errno
));
666 /******************************************************************************
667 * Unacquire : frees the joystick
669 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
671 JoystickImpl
*This
= (JoystickImpl
*)iface
;
674 TRACE("(this=%p)\n",This
);
675 res
= IDirectInputDevice2AImpl_Unacquire(iface
);
676 if (res
==DI_OK
&& This
->joyfd
!=-1) {
677 effect_list_item
*itr
;
678 struct input_event event
;
680 /* For each known effect:
683 * But, unlike DISFFC_RESET, do not release the effect.
685 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
) {
686 IDirectInputEffect_Stop(itr
->ref
);
687 IDirectInputEffect_Unload(itr
->ref
);
690 /* Enable autocenter. */
692 event
.code
= FF_AUTOCENTER
;
693 /* TODO: Read autocenter strengh before disabling it, and use it here
694 * instead of 0xFFFF (maximum strengh).
696 event
.value
= 0xFFFF;
697 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
698 ERR("Failed to set autocenter to %04x: %d %s\n", event
.value
, errno
, strerror(errno
));
707 * set the current state of the js device as it would be with the middle
710 #define CENTER_AXIS(a) \
711 (ji->dev_axes_to_di[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->dev_axes_to_di[a]], \
712 ji->joydev->axes[a].value ))
713 static void fake_current_js_state(JoystickImpl
*ji
)
717 /* center the axes */
718 ji
->generic
.js
.lX
= CENTER_AXIS(ABS_X
);
719 ji
->generic
.js
.lY
= CENTER_AXIS(ABS_Y
);
720 ji
->generic
.js
.lZ
= CENTER_AXIS(ABS_Z
);
721 ji
->generic
.js
.lRx
= CENTER_AXIS(ABS_RX
);
722 ji
->generic
.js
.lRy
= CENTER_AXIS(ABS_RY
);
723 ji
->generic
.js
.lRz
= CENTER_AXIS(ABS_RZ
);
724 ji
->generic
.js
.rglSlider
[0] = CENTER_AXIS(ABS_THROTTLE
);
725 ji
->generic
.js
.rglSlider
[1] = CENTER_AXIS(ABS_RUDDER
);
727 /* POV center is -1 */
728 for (i
= 0; i
< 4; i
++)
729 ji
->generic
.js
.rgdwPOV
[i
] = -1;
733 /* convert wine format offset to user format object index */
734 static void joy_polldev(JoystickGenericImpl
*iface
)
737 struct input_event ie
;
738 JoystickImpl
*This
= (JoystickImpl
*) iface
;
748 plfd
.fd
= This
->joyfd
;
749 plfd
.events
= POLLIN
;
751 if (poll(&plfd
,1,0) != 1)
754 /* we have one event, so we can read */
755 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
758 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
760 case EV_KEY
: /* button */
762 int btn
= This
->buttons
[ie
.code
];
764 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
768 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
769 This
->generic
.js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
775 int axis
= This
->dev_axes_to_di
[ie
.code
];
777 /* User axis remapping */
779 axis
= This
->generic
.axis_map
[axis
];
782 inst_id
= axis
< 8 ? DIDFT_MAKEINSTANCE(axis
) | DIDFT_ABSAXIS
:
783 DIDFT_MAKEINSTANCE(axis
- 8) | DIDFT_POV
;
784 value
= joystick_map_axis(&This
->generic
.props
[id_to_object(This
->generic
.base
.data_format
.wine_df
, inst_id
)], ie
.value
);
787 case 0: This
->generic
.js
.lX
= value
; break;
788 case 1: This
->generic
.js
.lY
= value
; break;
789 case 2: This
->generic
.js
.lZ
= value
; break;
790 case 3: This
->generic
.js
.lRx
= value
; break;
791 case 4: This
->generic
.js
.lRy
= value
; break;
792 case 5: This
->generic
.js
.lRz
= value
; break;
793 case 6: This
->generic
.js
.rglSlider
[0] = value
; break;
794 case 7: This
->generic
.js
.rglSlider
[1] = value
; break;
795 case 8: case 9: case 10: case 11:
800 This
->povs
[idx
].y
= ie
.value
;
802 This
->povs
[idx
].x
= ie
.value
;
804 This
->generic
.js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
808 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
812 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
814 This
->ff_state
= ie
.value
;
819 /* there is nothing to do */
823 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
827 queue_event((LPDIRECTINPUTDEVICE8A
)This
, inst_id
,
828 value
, ie
.time
.tv_usec
, This
->generic
.base
.dinput
->evsequence
++);
832 /******************************************************************************
833 * SetProperty : change input device properties
835 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
839 JoystickImpl
*This
= (JoystickImpl
*)iface
;
842 WARN("invalid argument\n");
843 return DIERR_INVALIDPARAM
;
846 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
847 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
848 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
850 if (IS_DIPROP(rguid
)) {
851 switch (LOWORD(rguid
)) {
852 case (DWORD_PTR
)DIPROP_CALIBRATIONMODE
: {
853 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
854 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd
->dwData
);
857 case (DWORD_PTR
)DIPROP_AUTOCENTER
: {
858 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
860 TRACE("autocenter(%d)\n", pd
->dwData
);
861 This
->ff_autocenter
= pd
->dwData
== DIPROPAUTOCENTER_ON
;
865 case (DWORD_PTR
)DIPROP_FFGAIN
: {
866 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
868 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
869 This
->ff_gain
= MulDiv(pd
->dwData
, 0xFFFF, 10000);
870 if (This
->generic
.base
.acquired
) {
871 /* Update immediately. */
872 struct input_event event
;
875 event
.code
= FF_GAIN
;
876 event
.value
= This
->ff_gain
;
877 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
878 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
883 return JoystickAGenericImpl_SetProperty(iface
, rguid
, ph
);
889 /******************************************************************************
890 * GetProperty : get input device properties
892 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
894 LPDIPROPHEADER pdiph
)
896 JoystickImpl
*This
= (JoystickImpl
*)iface
;
898 TRACE("(this=%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
899 _dump_DIPROPHEADER(pdiph
);
901 if (!IS_DIPROP(rguid
)) return DI_OK
;
903 switch (LOWORD(rguid
)) {
904 case (DWORD_PTR
) DIPROP_AUTOCENTER
:
906 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
908 pd
->dwData
= This
->ff_autocenter
? DIPROPAUTOCENTER_ON
: DIPROPAUTOCENTER_OFF
;
909 TRACE("autocenter(%d)\n", pd
->dwData
);
912 case (DWORD_PTR
) DIPROP_FFGAIN
:
914 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
916 pd
->dwData
= MulDiv(This
->ff_gain
, 10000, 0xFFFF);
917 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
922 return JoystickAGenericImpl_GetProperty(iface
, rguid
, pdiph
);
928 /******************************************************************************
929 * CreateEffect - Create a new FF effect with the specified params
931 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
,
934 LPDIRECTINPUTEFFECT
*ppdef
,
937 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
938 effect_list_item
* new_effect
= NULL
;
939 HRESULT retval
= DI_OK
;
942 JoystickImpl
* This
= (JoystickImpl
*)iface
;
943 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
945 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
946 TRACE("not available (compiled w/o ff support)\n");
951 if (!(new_effect
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect
))))
952 return DIERR_OUTOFMEMORY
;
954 retval
= linuxinput_create_effect(&This
->joyfd
, rguid
, &new_effect
->entry
, &new_effect
->ref
);
957 HeapFree(GetProcessHeap(), 0, new_effect
);
963 retval
= IDirectInputEffect_SetParameters(new_effect
->ref
, lpeff
, 0);
965 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
967 HeapFree(GetProcessHeap(), 0, new_effect
);
972 list_add_tail(&This
->ff_effects
, &new_effect
->entry
);
973 *ppdef
= new_effect
->ref
;
975 if (pUnkOuter
!= NULL
)
976 FIXME("Interface aggregation not implemented.\n");
980 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
983 /*******************************************************************************
984 * EnumEffects - Enumerate available FF effects
986 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
987 LPDIENUMEFFECTSCALLBACKA lpCallback
,
991 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
992 DIEFFECTINFOA dei
; /* feif */
993 DWORD type
= DIEFT_GETTYPE(dwEffType
);
994 JoystickImpl
* This
= (JoystickImpl
*)iface
;
996 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
998 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1000 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1001 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1002 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1003 (*lpCallback
)(&dei
, pvRef
);
1006 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1007 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1008 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1009 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1010 (*lpCallback
)(&dei
, pvRef
);
1012 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1013 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1014 (*lpCallback
)(&dei
, pvRef
);
1016 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1017 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1018 (*lpCallback
)(&dei
, pvRef
);
1020 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1021 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1022 (*lpCallback
)(&dei
, pvRef
);
1024 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1025 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1026 (*lpCallback
)(&dei
, pvRef
);
1030 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1031 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1032 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1033 (*lpCallback
)(&dei
, pvRef
);
1036 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1037 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1038 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1039 (*lpCallback
)(&dei
, pvRef
);
1041 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1042 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1043 (*lpCallback
)(&dei
, pvRef
);
1045 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1046 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1047 (*lpCallback
)(&dei
, pvRef
);
1049 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1050 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1051 (*lpCallback
)(&dei
, pvRef
);
1060 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1061 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1065 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1066 /* seems silly to duplicate all this code but all the structures and functions
1067 * are actually different (A/W) */
1068 DIEFFECTINFOW dei
; /* feif */
1069 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1070 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1071 int xfd
= This
->joyfd
;
1073 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1075 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1077 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1078 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1079 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1080 (*lpCallback
)(&dei
, pvRef
);
1083 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1084 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1085 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1086 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1087 (*lpCallback
)(&dei
, pvRef
);
1089 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1090 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1091 (*lpCallback
)(&dei
, pvRef
);
1093 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1094 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1095 (*lpCallback
)(&dei
, pvRef
);
1097 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1098 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1099 (*lpCallback
)(&dei
, pvRef
);
1101 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1102 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1103 (*lpCallback
)(&dei
, pvRef
);
1107 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1108 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1109 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1110 (*lpCallback
)(&dei
, pvRef
);
1113 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1114 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1115 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1116 (*lpCallback
)(&dei
, pvRef
);
1118 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1119 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1120 (*lpCallback
)(&dei
, pvRef
);
1122 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1123 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1124 (*lpCallback
)(&dei
, pvRef
);
1126 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1127 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1128 (*lpCallback
)(&dei
, pvRef
);
1132 /* return to unacquired state if that's where it was */
1134 IDirectInputDevice8_Unacquire(iface
);
1140 /*******************************************************************************
1141 * GetEffectInfo - Get information about a particular effect
1143 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1144 LPDIEFFECTINFOA pdei
,
1147 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1149 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1151 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1152 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1158 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1159 LPDIEFFECTINFOW pdei
,
1162 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1164 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1166 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1167 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1173 /*******************************************************************************
1174 * GetForceFeedbackState - Get information about the device's FF state
1176 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(
1177 LPDIRECTINPUTDEVICE8A iface
,
1180 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1182 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1186 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1187 /* DIGFFS_STOPPED is the only mandatory flag to report */
1188 if (This
->ff_state
== FF_STATUS_STOPPED
)
1189 (*pdwOut
) |= DIGFFS_STOPPED
;
1195 /*******************************************************************************
1196 * SendForceFeedbackCommand - Send a command to the device's FF system
1198 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(
1199 LPDIRECTINPUTDEVICE8A iface
,
1202 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1203 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1205 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1208 case DISFFC_STOPALL
:
1210 /* Stop all effects */
1211 effect_list_item
*itr
;
1213 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1214 IDirectInputEffect_Stop(itr
->ref
);
1220 effect_list_item
*itr
, *ptr
;
1222 /* Stop, unload, release and free all effects */
1223 /* This returns the device to its "bare" state */
1224 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1225 IDirectInputEffect_Release(itr
->ref
);
1229 case DISFFC_CONTINUE
:
1230 FIXME("No support for Pause or Continue in linux\n");
1233 case DISFFC_SETACTUATORSOFF
:
1234 case DISFFC_SETACTUATORSON
:
1235 FIXME("No direct actuator control in linux\n");
1239 FIXME("Unknown Force Feedback Command!\n");
1240 return DIERR_INVALIDPARAM
;
1244 return DIERR_UNSUPPORTED
;
1248 /*******************************************************************************
1249 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1250 * created for this device.
1252 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(
1253 LPDIRECTINPUTDEVICE8A iface
,
1254 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1258 /* this function is safe to call on non-ff-enabled builds */
1259 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1260 effect_list_item
*itr
, *ptr
;
1262 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1265 return DIERR_INVALIDPARAM
;
1268 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1270 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1271 (*lpCallback
)(itr
->ref
, pvRef
);
1276 /******************************************************************************
1277 * GetDeviceInfo : get information about a device's identity
1279 static HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface
,
1280 LPDIDEVICEINSTANCEA pdidi
)
1282 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1284 TRACE("(%p) %p\n", This
, pdidi
);
1286 if (pdidi
== NULL
) return E_POINTER
;
1287 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1288 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)))
1289 return DIERR_INVALIDPARAM
;
1291 fill_joystick_dideviceinstanceA(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1292 get_joystick_index(&This
->generic
.base
.guid
));
1296 static HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
,
1297 LPDIDEVICEINSTANCEW pdidi
)
1299 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1301 TRACE("(%p) %p\n", This
, pdidi
);
1303 if (pdidi
== NULL
) return E_POINTER
;
1304 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1305 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)))
1306 return DIERR_INVALIDPARAM
;
1308 fill_joystick_dideviceinstanceW(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1309 get_joystick_index(&This
->generic
.base
.guid
));
1313 static const IDirectInputDevice8AVtbl JoystickAvt
=
1315 IDirectInputDevice2AImpl_QueryInterface
,
1316 IDirectInputDevice2AImpl_AddRef
,
1317 IDirectInputDevice2AImpl_Release
,
1318 JoystickAGenericImpl_GetCapabilities
,
1319 IDirectInputDevice2AImpl_EnumObjects
,
1320 JoystickAImpl_GetProperty
,
1321 JoystickAImpl_SetProperty
,
1322 JoystickAImpl_Acquire
,
1323 JoystickAImpl_Unacquire
,
1324 JoystickAGenericImpl_GetDeviceState
,
1325 IDirectInputDevice2AImpl_GetDeviceData
,
1326 IDirectInputDevice2AImpl_SetDataFormat
,
1327 IDirectInputDevice2AImpl_SetEventNotification
,
1328 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1329 JoystickAGenericImpl_GetObjectInfo
,
1330 JoystickAImpl_GetDeviceInfo
,
1331 IDirectInputDevice2AImpl_RunControlPanel
,
1332 IDirectInputDevice2AImpl_Initialize
,
1333 JoystickAImpl_CreateEffect
,
1334 JoystickAImpl_EnumEffects
,
1335 JoystickAImpl_GetEffectInfo
,
1336 JoystickAImpl_GetForceFeedbackState
,
1337 JoystickAImpl_SendForceFeedbackCommand
,
1338 JoystickAImpl_EnumCreatedEffectObjects
,
1339 IDirectInputDevice2AImpl_Escape
,
1340 JoystickAGenericImpl_Poll
,
1341 IDirectInputDevice2AImpl_SendDeviceData
,
1342 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1343 IDirectInputDevice7AImpl_WriteEffectToFile
,
1344 IDirectInputDevice8AImpl_BuildActionMap
,
1345 IDirectInputDevice8AImpl_SetActionMap
,
1346 IDirectInputDevice8AImpl_GetImageInfo
1349 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1350 # define XCAST(fun) (typeof(JoystickWvt.fun))
1352 # define XCAST(fun) (void*)
1355 static const IDirectInputDevice8WVtbl JoystickWvt
=
1357 IDirectInputDevice2WImpl_QueryInterface
,
1358 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
1359 XCAST(Release
)IDirectInputDevice2AImpl_Release
,
1360 XCAST(GetCapabilities
)JoystickAGenericImpl_GetCapabilities
,
1361 IDirectInputDevice2WImpl_EnumObjects
,
1362 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1363 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1364 XCAST(Acquire
)JoystickAImpl_Acquire
,
1365 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1366 XCAST(GetDeviceState
)JoystickAGenericImpl_GetDeviceState
,
1367 XCAST(GetDeviceData
)IDirectInputDevice2AImpl_GetDeviceData
,
1368 XCAST(SetDataFormat
)IDirectInputDevice2AImpl_SetDataFormat
,
1369 XCAST(SetEventNotification
)IDirectInputDevice2AImpl_SetEventNotification
,
1370 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
1371 JoystickWGenericImpl_GetObjectInfo
,
1372 JoystickWImpl_GetDeviceInfo
,
1373 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
1374 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
1375 XCAST(CreateEffect
)JoystickAImpl_CreateEffect
,
1376 JoystickWImpl_EnumEffects
,
1377 JoystickWImpl_GetEffectInfo
,
1378 XCAST(GetForceFeedbackState
)JoystickAImpl_GetForceFeedbackState
,
1379 XCAST(SendForceFeedbackCommand
)JoystickAImpl_SendForceFeedbackCommand
,
1380 XCAST(EnumCreatedEffectObjects
)JoystickAImpl_EnumCreatedEffectObjects
,
1381 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1382 XCAST(Poll
)JoystickAGenericImpl_Poll
,
1383 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1384 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1385 IDirectInputDevice7WImpl_WriteEffectToFile
,
1386 IDirectInputDevice8WImpl_BuildActionMap
,
1387 IDirectInputDevice8WImpl_SetActionMap
,
1388 IDirectInputDevice8WImpl_GetImageInfo
1392 #else /* HAVE_CORRECT_LINUXINPUT_H */
1394 const struct dinput_device joystick_linuxinput_device
= {
1395 "Wine Linux-input joystick driver",
1402 #endif /* HAVE_CORRECT_LINUXINPUT_H */