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
23 #include "dinput_private.h"
28 #ifdef HAVE_SYS_TIME_H
29 # include <sys/time.h>
32 #ifdef HAVE_SYS_IOCTL_H
33 # include <sys/ioctl.h>
36 #ifdef HAVE_LINUX_INPUT_H
37 # include <linux/input.h>
39 # if defined(EVIOCGBIT) && defined(EV_ABS) && defined(BTN_PINKIE)
40 # define HAS_PROPER_HEADER
43 #ifdef HAVE_SYS_POLL_H
44 # include <sys/poll.h>
47 #include "device_private.h"
49 #ifdef HAS_PROPER_HEADER
51 #define EVDEVPREFIX "/dev/input/event"
52 #define EVDEVDRIVER " (event)"
54 /* Wine joystick driver object instances */
55 #define WINE_JOYSTICK_MAX_AXES 8
56 #define WINE_JOYSTICK_MAX_POVS 4
57 #define WINE_JOYSTICK_MAX_BUTTONS 128
59 struct wine_input_absinfo
{
67 /* implemented in effect_linuxinput.c */
68 HRESULT
linuxinput_create_effect(int* fd
, REFGUID rguid
, struct list
*parent_list_entry
, LPDIRECTINPUTEFFECT
* peff
);
69 HRESULT
linuxinput_get_info_A(int fd
, REFGUID rguid
, LPDIEFFECTINFOA info
);
70 HRESULT
linuxinput_get_info_W(int fd
, REFGUID rguid
, LPDIEFFECTINFOW info
);
72 typedef struct JoystickImpl JoystickImpl
;
73 static const IDirectInputDevice8AVtbl JoystickAvt
;
74 static const IDirectInputDevice8WVtbl JoystickWvt
;
84 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
85 BYTE evbits
[(EV_MAX
+7)/8];
86 BYTE absbits
[(ABS_MAX
+7)/8];
87 BYTE keybits
[(KEY_MAX
+7)/8];
88 BYTE ffbits
[(FF_MAX
+7)/8];
90 /* data returned by the EVIOCGABS() ioctl */
91 struct wine_input_absinfo axes
[ABS_MAX
];
93 WORD vendor_id
, product_id
;
98 struct JoystickGenericImpl generic
;
99 struct JoyDev
*joydev
;
101 /* joystick private */
104 int dev_axes_to_di
[ABS_MAX
];
107 /* LUT for KEY_ to offset in rgbButtons */
108 BYTE buttons
[KEY_MAX
];
110 /* Force feedback variables */
111 struct list ff_effects
;
117 static inline JoystickImpl
*impl_from_IDirectInputDevice8A(IDirectInputDevice8A
*iface
)
119 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8A_iface
),
120 JoystickGenericImpl
, base
), JoystickImpl
, generic
);
122 static inline JoystickImpl
*impl_from_IDirectInputDevice8W(IDirectInputDevice8W
*iface
)
124 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8W_iface
),
125 JoystickGenericImpl
, base
), JoystickImpl
, generic
);
128 static inline IDirectInputDevice8W
*IDirectInputDevice8W_from_impl(JoystickImpl
*This
)
130 return &This
->generic
.base
.IDirectInputDevice8W_iface
;
133 static void fake_current_js_state(JoystickImpl
*ji
);
134 static void find_joydevs(void);
135 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
);
137 /* This GUID is slightly different from the linux joystick one. Take note. */
138 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
142 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
145 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
147 #define MAX_JOYDEV 64
149 static int have_joydevs
= -1;
150 static struct JoyDev
*joydevs
= NULL
;
152 static void find_joydevs(void)
156 if (InterlockedCompareExchange(&have_joydevs
, 0, -1) != -1)
157 /* Someone beat us to it */
160 for (i
= 0; i
< MAX_JOYDEV
; i
++)
163 struct JoyDev joydev
= {0};
165 BOOL no_ff_check
= FALSE
;
167 struct JoyDev
*new_joydevs
;
168 struct input_id device_id
= {0};
170 snprintf(buf
, sizeof(buf
), EVDEVPREFIX
"%d", i
);
172 if ((fd
= open(buf
, O_RDWR
)) == -1)
174 fd
= open(buf
, O_RDONLY
);
180 WARN("Failed to open \"%s\": %d %s\n", buf
, errno
, strerror(errno
));
184 if (ioctl(fd
, EVIOCGBIT(0, sizeof(joydev
.evbits
)), joydev
.evbits
) == -1)
186 WARN("ioctl(EVIOCGBIT, 0) failed: %d %s\n", errno
, strerror(errno
));
190 if (ioctl(fd
, EVIOCGBIT(EV_ABS
, sizeof(joydev
.absbits
)), joydev
.absbits
) == -1)
192 WARN("ioctl(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
196 if (ioctl(fd
, EVIOCGBIT(EV_KEY
, sizeof(joydev
.keybits
)), joydev
.keybits
) == -1)
198 WARN("ioctl(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno
, strerror(errno
));
203 /* A true joystick has at least axis X and Y, and at least 1
204 * button. copied from linux/drivers/input/joydev.c */
205 if (!test_bit(joydev
.absbits
, ABS_X
) || !test_bit(joydev
.absbits
, ABS_Y
) ||
206 !(test_bit(joydev
.keybits
, BTN_TRIGGER
) ||
207 test_bit(joydev
.keybits
, BTN_A
) ||
208 test_bit(joydev
.keybits
, BTN_1
)))
214 if (!(joydev
.device
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
219 strcpy(joydev
.device
, buf
);
221 buf
[MAX_PATH
- 1] = 0;
222 if (ioctl(fd
, EVIOCGNAME(MAX_PATH
- 1), buf
) != -1 &&
223 (joydev
.name
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + strlen(EVDEVDRIVER
) + 1)))
225 strcpy(joydev
.name
, buf
);
226 /* Append driver name */
227 strcat(joydev
.name
, EVDEVDRIVER
);
230 joydev
.name
= joydev
.device
;
232 if (device_disabled_registry(joydev
.name
)) {
234 HeapFree(GetProcessHeap(), 0, joydev
.name
);
235 if (joydev
.name
!= joydev
.device
)
236 HeapFree(GetProcessHeap(), 0, joydev
.device
);
240 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
241 joydev
.guid
.Data3
+= have_joydevs
;
243 TRACE("Found a joystick on %s: %s (%s)\n",
244 joydev
.device
, joydev
.name
,
245 debugstr_guid(&joydev
.guid
)
248 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
250 test_bit(joydev
.evbits
, EV_FF
) &&
251 ioctl(fd
, EVIOCGBIT(EV_FF
, sizeof(joydev
.ffbits
)), joydev
.ffbits
) != -1 &&
252 ioctl(fd
, EVIOCGEFFECTS
, &joydev
.num_effects
) != -1 &&
253 joydev
.num_effects
> 0)
255 TRACE(" ... with force feedback\n");
256 joydev
.has_ff
= TRUE
;
260 for (j
= 0; j
< ABS_MAX
;j
++)
262 if (!test_bit(joydev
.absbits
, j
)) continue;
263 if (ioctl(fd
, EVIOCGABS(j
), &(joydev
.axes
[j
])) != -1)
265 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
267 joydev
.axes
[j
].value
,
268 joydev
.axes
[j
].minimum
,
269 joydev
.axes
[j
].maximum
,
276 if (ioctl(fd
, EVIOCGID
, &device_id
) == -1)
277 WARN("ioctl(EVIOCGID) failed: %d %s\n", errno
, strerror(errno
));
280 joydev
.vendor_id
= device_id
.vendor
;
281 joydev
.product_id
= device_id
.product
;
285 new_joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
287 new_joydevs
= HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1 + have_joydevs
) * sizeof(struct JoyDev
));
294 joydevs
= new_joydevs
;
295 joydevs
[have_joydevs
] = joydev
;
302 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
304 DWORD dwSize
= lpddi
->dwSize
;
306 TRACE("%d %p\n", dwSize
, lpddi
);
307 memset(lpddi
, 0, dwSize
);
309 lpddi
->dwSize
= dwSize
;
310 lpddi
->guidInstance
= joydevs
[id
].guid
;
311 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
312 lpddi
->guidFFDriver
= GUID_NULL
;
314 if (version
>= 0x0800)
315 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
317 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
319 strcpy(lpddi
->tszInstanceName
, joydevs
[id
].name
);
320 strcpy(lpddi
->tszProductName
, joydevs
[id
].name
);
323 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
325 DWORD dwSize
= lpddi
->dwSize
;
327 TRACE("%d %p\n", dwSize
, lpddi
);
328 memset(lpddi
, 0, dwSize
);
330 lpddi
->dwSize
= dwSize
;
331 lpddi
->guidInstance
= joydevs
[id
].guid
;
332 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
333 lpddi
->guidFFDriver
= GUID_NULL
;
335 if (version
>= 0x0800)
336 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
338 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
340 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
341 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszProductName
, MAX_PATH
);
344 static HRESULT
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
348 if (id
>= have_joydevs
) {
352 if (!((dwDevType
== 0) ||
353 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
354 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
357 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
358 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
362 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
363 fill_joystick_dideviceinstanceA(lpddi
, version
, id
);
369 static HRESULT
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
373 if (id
>= have_joydevs
) {
377 if (!((dwDevType
== 0) ||
378 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
379 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
382 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
383 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
387 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
388 fill_joystick_dideviceinstanceW(lpddi
, version
, id
);
394 static JoystickImpl
*alloc_device(REFGUID rguid
, IDirectInputImpl
*dinput
, unsigned short index
)
396 JoystickImpl
* newDevice
;
397 LPDIDATAFORMAT df
= NULL
;
399 int default_axis_map
[WINE_JOYSTICK_MAX_AXES
+ WINE_JOYSTICK_MAX_POVS
*2];
401 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
402 if (!newDevice
) return NULL
;
404 newDevice
->generic
.base
.IDirectInputDevice8A_iface
.lpVtbl
= &JoystickAvt
;
405 newDevice
->generic
.base
.IDirectInputDevice8W_iface
.lpVtbl
= &JoystickWvt
;
406 newDevice
->generic
.base
.ref
= 1;
407 newDevice
->generic
.base
.guid
= *rguid
;
408 newDevice
->generic
.base
.dinput
= dinput
;
409 newDevice
->generic
.joy_polldev
= joy_polldev
;
410 newDevice
->joyfd
= -1;
411 newDevice
->joydev
= &joydevs
[index
];
412 newDevice
->generic
.name
= newDevice
->joydev
->name
;
413 list_init(&newDevice
->ff_effects
);
414 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
415 newDevice
->ff_state
= FF_STATUS_STOPPED
;
417 /* There is no way in linux to query force feedback autocenter status.
418 Instead, track it with ff_autocenter, and assume it's initially
420 newDevice
->ff_autocenter
= 1;
421 newDevice
->ff_gain
= 0xFFFF;
422 InitializeCriticalSection(&newDevice
->generic
.base
.crit
);
423 newDevice
->generic
.base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
425 /* Count number of available axes - supported Axis & POVs */
426 for (i
= 0; i
< ABS_MAX
; i
++)
428 if (i
< WINE_JOYSTICK_MAX_AXES
&&
429 test_bit(newDevice
->joydev
->absbits
, i
))
431 newDevice
->generic
.device_axis_count
++;
432 newDevice
->dev_axes_to_di
[i
] = idx
;
433 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[i
].minimum
;
434 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[i
].maximum
;
435 default_axis_map
[idx
] = i
;
439 newDevice
->dev_axes_to_di
[i
] = -1;
442 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
444 if (test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) &&
445 test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2))
447 newDevice
->generic
.device_axis_count
+= 2;
448 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].minimum
;
449 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].maximum
;
450 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = idx
;
451 newDevice
->generic
.props
[idx
+1].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].minimum
;
452 newDevice
->generic
.props
[idx
+1].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].maximum
;
453 newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = idx
+ 1;
455 default_axis_map
[idx
] = default_axis_map
[idx
+ 1] = WINE_JOYSTICK_MAX_AXES
+ i
;
459 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = -1;
462 /* do any user specified configuration */
463 if (setup_dinput_options(&newDevice
->generic
, default_axis_map
) != DI_OK
) goto failed
;
465 /* Create copy of default data format */
466 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
467 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
468 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
471 /* Construct internal data format */
473 /* Supported Axis & POVs */
474 for (i
= 0, idx
= 0; i
< newDevice
->generic
.device_axis_count
; i
++)
476 int wine_obj
= newDevice
->generic
.axis_map
[i
];
478 if (wine_obj
< 0) continue;
480 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[wine_obj
], df
->dwObjSize
);
482 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
) | DIDFT_ABSAXIS
;
485 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
- 8) | DIDFT_POV
;
486 i
++; /* POV takes 2 axes */
489 newDevice
->generic
.props
[idx
].lMin
= 0;
490 newDevice
->generic
.props
[idx
].lMax
= 0xffff;
491 newDevice
->generic
.props
[idx
].lSaturation
= 0;
492 newDevice
->generic
.props
[idx
].lDeadZone
= newDevice
->generic
.deadzone
;
494 /* Linux supports force-feedback on X & Y axes only */
495 if (newDevice
->joydev
->has_ff
&& (i
== 0 || i
== 1))
496 df
->rgodf
[idx
].dwFlags
|= DIDOI_FFACTUATOR
;
501 /* Buttons can be anywhere, so check all */
502 for (i
= 0; i
< KEY_MAX
&& newDevice
->generic
.devcaps
.dwButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
504 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
506 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->generic
.devcaps
.dwButtons
+ 12], df
->dwObjSize
);
507 newDevice
->buttons
[i
] = 0x80 | newDevice
->generic
.devcaps
.dwButtons
;
508 df
->rgodf
[idx
].pguid
= &GUID_Button
;
509 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->generic
.devcaps
.dwButtons
++) | DIDFT_PSHBUTTON
;
512 newDevice
->generic
.base
.data_format
.wine_df
= df
;
514 fake_current_js_state(newDevice
);
517 newDevice
->generic
.devcaps
.dwSize
= sizeof(newDevice
->generic
.devcaps
);
518 newDevice
->generic
.devcaps
.dwFlags
= DIDC_ATTACHED
;
519 if (newDevice
->generic
.base
.dinput
->dwVersion
>= 0x0800)
520 newDevice
->generic
.devcaps
.dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
522 newDevice
->generic
.devcaps
.dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
524 if (newDevice
->joydev
->has_ff
)
525 newDevice
->generic
.devcaps
.dwFlags
|= DIDC_FORCEFEEDBACK
;
527 IDirectInput_AddRef(&newDevice
->generic
.base
.dinput
->IDirectInput7A_iface
);
529 EnterCriticalSection(&dinput
->crit
);
530 list_add_tail(&dinput
->devices_list
, &newDevice
->generic
.base
.entry
);
531 LeaveCriticalSection(&dinput
->crit
);
536 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
537 HeapFree(GetProcessHeap(), 0, df
);
538 HeapFree(GetProcessHeap(), 0, newDevice
->generic
.axis_map
);
539 HeapFree(GetProcessHeap(), 0, newDevice
);
543 /******************************************************************************
544 * get_joystick_index : Get the joystick index from a given GUID
546 static unsigned short get_joystick_index(REFGUID guid
)
548 GUID wine_joystick
= DInput_Wine_Joystick_Base_GUID
;
549 GUID dev_guid
= *guid
;
551 wine_joystick
.Data3
= 0;
554 /* for the standard joystick GUID use index 0 */
555 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
557 /* for the wine joystick GUIDs use the index stored in Data3 */
558 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
- DInput_Wine_Joystick_Base_GUID
.Data3
;
563 static HRESULT
joydev_create_device(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPVOID
*pdev
, int unicode
)
565 unsigned short index
;
567 TRACE("%p %s %s %p %i\n", dinput
, debugstr_guid(rguid
), debugstr_guid(riid
), pdev
, unicode
);
571 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
572 have_joydevs
&& index
< have_joydevs
)
578 else if (IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
579 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
580 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
581 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
585 else if (IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
586 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
587 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
588 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
594 WARN("no interface\n");
595 return DIERR_NOINTERFACE
;
598 This
= alloc_device(rguid
, dinput
, index
);
599 TRACE("Created a Joystick device (%p)\n", This
);
601 if (!This
) return DIERR_OUTOFMEMORY
;
604 *pdev
= &This
->generic
.base
.IDirectInputDevice8W_iface
;
606 *pdev
= &This
->generic
.base
.IDirectInputDevice8A_iface
;
611 return DIERR_DEVICENOTREG
;
615 const struct dinput_device joystick_linuxinput_device
= {
616 "Wine Linux-input joystick driver",
622 /******************************************************************************
623 * Acquire : gets exclusive control of the joystick
625 static HRESULT WINAPI
JoystickWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface
)
627 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
630 TRACE("(this=%p)\n",This
);
632 if ((res
= IDirectInputDevice2WImpl_Acquire(iface
)) != DI_OK
)
634 WARN("Failed to acquire: %x\n", res
);
638 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDWR
)) == -1)
640 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDONLY
)) == -1)
642 /* Couldn't open the device at all */
643 ERR("Failed to open device %s: %d %s\n", This
->joydev
->device
, errno
, strerror(errno
));
644 IDirectInputDevice2WImpl_Unacquire(iface
);
645 return DIERR_NOTFOUND
;
649 /* Couldn't open in r/w but opened in read-only. */
650 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
655 struct input_event event
;
658 event
.code
= FF_GAIN
;
659 event
.value
= This
->ff_gain
;
660 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
661 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
662 if (!This
->ff_autocenter
)
664 /* Disable autocenter. */
665 event
.code
= FF_AUTOCENTER
;
667 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
668 ERR("Failed disabling autocenter: %d %s\n", errno
, strerror(errno
));
675 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
677 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
678 return JoystickWImpl_Acquire(IDirectInputDevice8W_from_impl(This
));
681 /******************************************************************************
682 * Unacquire : frees the joystick
684 static HRESULT WINAPI
JoystickWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface
)
686 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
689 TRACE("(this=%p)\n",This
);
690 res
= IDirectInputDevice2WImpl_Unacquire(iface
);
691 if (res
==DI_OK
&& This
->joyfd
!=-1) {
692 effect_list_item
*itr
;
693 struct input_event event
;
695 /* For each known effect:
698 * But, unlike DISFFC_RESET, do not release the effect.
700 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
) {
701 IDirectInputEffect_Stop(itr
->ref
);
702 IDirectInputEffect_Unload(itr
->ref
);
705 /* Enable autocenter. */
707 event
.code
= FF_AUTOCENTER
;
708 /* TODO: Read autocenter strength before disabling it, and use it here
709 * instead of 0xFFFF (maximum strength).
711 event
.value
= 0xFFFF;
712 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
713 ERR("Failed to set autocenter to %04x: %d %s\n", event
.value
, errno
, strerror(errno
));
721 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
723 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
724 return JoystickWImpl_Unacquire(IDirectInputDevice8W_from_impl(This
));
728 * set the current state of the js device as it would be with the middle
731 #define CENTER_AXIS(a) \
732 (ji->dev_axes_to_di[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->dev_axes_to_di[a]], \
733 ji->joydev->axes[a].value ))
734 static void fake_current_js_state(JoystickImpl
*ji
)
738 /* center the axes */
739 ji
->generic
.js
.lX
= CENTER_AXIS(ABS_X
);
740 ji
->generic
.js
.lY
= CENTER_AXIS(ABS_Y
);
741 ji
->generic
.js
.lZ
= CENTER_AXIS(ABS_Z
);
742 ji
->generic
.js
.lRx
= CENTER_AXIS(ABS_RX
);
743 ji
->generic
.js
.lRy
= CENTER_AXIS(ABS_RY
);
744 ji
->generic
.js
.lRz
= CENTER_AXIS(ABS_RZ
);
745 ji
->generic
.js
.rglSlider
[0] = CENTER_AXIS(ABS_THROTTLE
);
746 ji
->generic
.js
.rglSlider
[1] = CENTER_AXIS(ABS_RUDDER
);
748 /* POV center is -1 */
749 for (i
= 0; i
< 4; i
++)
750 ji
->generic
.js
.rgdwPOV
[i
] = -1;
754 /* convert wine format offset to user format object index */
755 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
)
758 struct input_event ie
;
759 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
769 plfd
.fd
= This
->joyfd
;
770 plfd
.events
= POLLIN
;
772 if (poll(&plfd
,1,0) != 1)
775 /* we have one event, so we can read */
776 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
779 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
781 case EV_KEY
: /* button */
783 int btn
= This
->buttons
[ie
.code
];
785 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
789 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
790 This
->generic
.js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
796 int axis
= This
->dev_axes_to_di
[ie
.code
];
798 /* User axis remapping */
800 axis
= This
->generic
.axis_map
[axis
];
803 inst_id
= axis
< 8 ? DIDFT_MAKEINSTANCE(axis
) | DIDFT_ABSAXIS
:
804 DIDFT_MAKEINSTANCE(axis
- 8) | DIDFT_POV
;
805 value
= joystick_map_axis(&This
->generic
.props
[id_to_object(This
->generic
.base
.data_format
.wine_df
, inst_id
)], ie
.value
);
808 case 0: This
->generic
.js
.lX
= value
; break;
809 case 1: This
->generic
.js
.lY
= value
; break;
810 case 2: This
->generic
.js
.lZ
= value
; break;
811 case 3: This
->generic
.js
.lRx
= value
; break;
812 case 4: This
->generic
.js
.lRy
= value
; break;
813 case 5: This
->generic
.js
.lRz
= value
; break;
814 case 6: This
->generic
.js
.rglSlider
[0] = value
; break;
815 case 7: This
->generic
.js
.rglSlider
[1] = value
; break;
816 case 8: case 9: case 10: case 11:
821 This
->povs
[idx
].y
= ie
.value
;
823 This
->povs
[idx
].x
= ie
.value
;
825 This
->generic
.js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
829 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
833 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
835 This
->ff_state
= ie
.value
;
840 /* there is nothing to do */
849 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
853 queue_event(iface
, inst_id
,
854 value
, GetCurrentTime(), This
->generic
.base
.dinput
->evsequence
++);
858 /******************************************************************************
859 * SetProperty : change input device properties
861 static HRESULT WINAPI
JoystickWImpl_SetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPCDIPROPHEADER ph
)
863 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
866 WARN("invalid argument\n");
867 return DIERR_INVALIDPARAM
;
870 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
871 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
872 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
874 if (IS_DIPROP(rguid
)) {
875 switch (LOWORD(rguid
)) {
876 case (DWORD_PTR
)DIPROP_CALIBRATIONMODE
: {
877 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
878 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd
->dwData
);
881 case (DWORD_PTR
)DIPROP_AUTOCENTER
: {
882 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
884 TRACE("autocenter(%d)\n", pd
->dwData
);
885 This
->ff_autocenter
= pd
->dwData
== DIPROPAUTOCENTER_ON
;
889 case (DWORD_PTR
)DIPROP_FFGAIN
: {
890 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
892 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
893 This
->ff_gain
= MulDiv(pd
->dwData
, 0xFFFF, 10000);
894 if (This
->generic
.base
.acquired
) {
895 /* Update immediately. */
896 struct input_event event
;
899 event
.code
= FF_GAIN
;
900 event
.value
= This
->ff_gain
;
901 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
902 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
907 return JoystickWGenericImpl_SetProperty(iface
, rguid
, ph
);
913 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPCDIPROPHEADER ph
)
915 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
916 return JoystickWImpl_SetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, ph
);
919 /******************************************************************************
920 * GetProperty : get input device properties
922 static HRESULT WINAPI
JoystickWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
924 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
926 TRACE("(this=%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
927 _dump_DIPROPHEADER(pdiph
);
929 if (!IS_DIPROP(rguid
)) return DI_OK
;
931 switch (LOWORD(rguid
)) {
932 case (DWORD_PTR
) DIPROP_AUTOCENTER
:
934 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
936 pd
->dwData
= This
->ff_autocenter
? DIPROPAUTOCENTER_ON
: DIPROPAUTOCENTER_OFF
;
937 TRACE("autocenter(%d)\n", pd
->dwData
);
940 case (DWORD_PTR
) DIPROP_FFGAIN
:
942 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
944 pd
->dwData
= MulDiv(This
->ff_gain
, 10000, 0xFFFF);
945 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
949 case (DWORD_PTR
) DIPROP_VIDPID
:
951 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
953 if (!This
->joydev
->product_id
|| !This
->joydev
->vendor_id
)
954 return DIERR_UNSUPPORTED
;
955 pd
->dwData
= MAKELONG(This
->joydev
->vendor_id
, This
->joydev
->product_id
);
956 TRACE("DIPROP_VIDPID(%08x)\n", pd
->dwData
);
960 case (DWORD_PTR
) DIPROP_JOYSTICKID
:
962 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
964 pd
->dwData
= get_joystick_index(&This
->generic
.base
.guid
);
965 TRACE("DIPROP_JOYSTICKID(%d)\n", pd
->dwData
);
970 return JoystickWGenericImpl_GetProperty(iface
, rguid
, pdiph
);
976 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
978 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
979 return JoystickWImpl_GetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, pdiph
);
982 /******************************************************************************
983 * CreateEffect - Create a new FF effect with the specified params
985 static HRESULT WINAPI
JoystickWImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
,
986 LPCDIEFFECT lpeff
, LPDIRECTINPUTEFFECT
*ppdef
,
989 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
990 effect_list_item
* new_effect
= NULL
;
991 HRESULT retval
= DI_OK
;
994 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
995 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
997 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
998 TRACE("not available (compiled w/o ff support)\n");
1003 if (!(new_effect
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect
))))
1004 return DIERR_OUTOFMEMORY
;
1006 retval
= linuxinput_create_effect(&This
->joyfd
, rguid
, &new_effect
->entry
, &new_effect
->ref
);
1007 if (retval
!= DI_OK
)
1009 HeapFree(GetProcessHeap(), 0, new_effect
);
1015 retval
= IDirectInputEffect_SetParameters(new_effect
->ref
, lpeff
, 0);
1017 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1019 HeapFree(GetProcessHeap(), 0, new_effect
);
1024 list_add_tail(&This
->ff_effects
, &new_effect
->entry
);
1025 *ppdef
= new_effect
->ref
;
1027 if (pUnkOuter
!= NULL
)
1028 FIXME("Interface aggregation not implemented.\n");
1032 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1035 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
,
1036 LPCDIEFFECT lpeff
, LPDIRECTINPUTEFFECT
*ppdef
,
1037 LPUNKNOWN pUnkOuter
)
1039 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1040 return JoystickWImpl_CreateEffect(IDirectInputDevice8W_from_impl(This
), rguid
, lpeff
, ppdef
, pUnkOuter
);
1043 /*******************************************************************************
1044 * EnumEffects - Enumerate available FF effects
1046 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1047 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1051 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1052 DIEFFECTINFOA dei
; /* feif */
1053 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1054 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1056 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
1058 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1060 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1061 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1062 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1063 (*lpCallback
)(&dei
, pvRef
);
1066 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1067 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1068 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1069 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1070 (*lpCallback
)(&dei
, pvRef
);
1072 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1073 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1074 (*lpCallback
)(&dei
, pvRef
);
1076 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1077 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1078 (*lpCallback
)(&dei
, pvRef
);
1080 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1081 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1082 (*lpCallback
)(&dei
, pvRef
);
1084 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1085 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1086 (*lpCallback
)(&dei
, pvRef
);
1090 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1091 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1092 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1093 (*lpCallback
)(&dei
, pvRef
);
1096 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1097 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1098 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1099 (*lpCallback
)(&dei
, pvRef
);
1101 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1102 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1103 (*lpCallback
)(&dei
, pvRef
);
1105 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1106 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1107 (*lpCallback
)(&dei
, pvRef
);
1109 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1110 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1111 (*lpCallback
)(&dei
, pvRef
);
1120 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1121 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1125 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1126 /* seems silly to duplicate all this code but all the structures and functions
1127 * are actually different (A/W) */
1128 DIEFFECTINFOW dei
; /* feif */
1129 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1130 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1131 int xfd
= This
->joyfd
;
1133 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1135 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1137 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1138 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1139 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1140 (*lpCallback
)(&dei
, pvRef
);
1143 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1144 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1145 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1146 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1147 (*lpCallback
)(&dei
, pvRef
);
1149 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1150 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1151 (*lpCallback
)(&dei
, pvRef
);
1153 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1154 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1155 (*lpCallback
)(&dei
, pvRef
);
1157 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1158 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1159 (*lpCallback
)(&dei
, pvRef
);
1161 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1162 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1163 (*lpCallback
)(&dei
, pvRef
);
1167 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1168 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1169 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1170 (*lpCallback
)(&dei
, pvRef
);
1173 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1174 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1175 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1176 (*lpCallback
)(&dei
, pvRef
);
1178 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1179 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1180 (*lpCallback
)(&dei
, pvRef
);
1182 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1183 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1184 (*lpCallback
)(&dei
, pvRef
);
1186 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1187 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1188 (*lpCallback
)(&dei
, pvRef
);
1192 /* return to unacquired state if that's where it was */
1194 IDirectInputDevice8_Unacquire(iface
);
1200 /*******************************************************************************
1201 * GetEffectInfo - Get information about a particular effect
1203 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1204 LPDIEFFECTINFOA pdei
,
1207 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1209 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1211 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1212 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1218 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1219 LPDIEFFECTINFOW pdei
,
1222 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1224 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1226 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1227 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1233 /*******************************************************************************
1234 * GetForceFeedbackState - Get information about the device's FF state
1236 static HRESULT WINAPI
JoystickWImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface
, LPDWORD pdwOut
)
1238 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1240 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1244 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1245 /* DIGFFS_STOPPED is the only mandatory flag to report */
1246 if (This
->ff_state
== FF_STATUS_STOPPED
)
1247 (*pdwOut
) |= DIGFFS_STOPPED
;
1253 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8A iface
, LPDWORD pdwOut
)
1255 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1256 return JoystickWImpl_GetForceFeedbackState(IDirectInputDevice8W_from_impl(This
), pdwOut
);
1259 /*******************************************************************************
1260 * SendForceFeedbackCommand - Send a command to the device's FF system
1262 static HRESULT WINAPI
JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface
, DWORD dwFlags
)
1264 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1265 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1267 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1270 case DISFFC_STOPALL
:
1272 /* Stop all effects */
1273 effect_list_item
*itr
;
1275 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1276 IDirectInputEffect_Stop(itr
->ref
);
1282 effect_list_item
*itr
, *ptr
;
1284 /* Stop, unload, release and free all effects */
1285 /* This returns the device to its "bare" state */
1286 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1287 IDirectInputEffect_Release(itr
->ref
);
1291 case DISFFC_CONTINUE
:
1292 FIXME("No support for Pause or Continue in linux\n");
1295 case DISFFC_SETACTUATORSOFF
:
1296 case DISFFC_SETACTUATORSON
:
1297 FIXME("No direct actuator control in linux\n");
1301 FIXME("Unknown Force Feedback Command!\n");
1302 return DIERR_INVALIDPARAM
;
1306 return DIERR_UNSUPPORTED
;
1310 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8A iface
, DWORD dwFlags
)
1312 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1313 return JoystickWImpl_SendForceFeedbackCommand(IDirectInputDevice8W_from_impl(This
), dwFlags
);
1316 /*******************************************************************************
1317 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1318 * created for this device.
1320 static HRESULT WINAPI
JoystickWImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface
,
1321 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1322 LPVOID pvRef
, DWORD dwFlags
)
1324 /* this function is safe to call on non-ff-enabled builds */
1325 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1326 effect_list_item
*itr
, *ptr
;
1328 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1331 return DIERR_INVALIDPARAM
;
1334 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1336 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1337 (*lpCallback
)(itr
->ref
, pvRef
);
1342 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8A iface
,
1343 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1344 LPVOID pvRef
, DWORD dwFlags
)
1346 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1347 return JoystickWImpl_EnumCreatedEffectObjects(IDirectInputDevice8W_from_impl(This
), lpCallback
, pvRef
, dwFlags
);
1350 /******************************************************************************
1351 * GetDeviceInfo : get information about a device's identity
1353 static HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface
,
1354 LPDIDEVICEINSTANCEA pdidi
)
1356 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1358 TRACE("(%p) %p\n", This
, pdidi
);
1360 if (pdidi
== NULL
) return E_POINTER
;
1361 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1362 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)))
1363 return DIERR_INVALIDPARAM
;
1365 fill_joystick_dideviceinstanceA(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1366 get_joystick_index(&This
->generic
.base
.guid
));
1370 static HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
,
1371 LPDIDEVICEINSTANCEW pdidi
)
1373 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
1375 TRACE("(%p) %p\n", This
, pdidi
);
1377 if (pdidi
== NULL
) return E_POINTER
;
1378 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1379 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)))
1380 return DIERR_INVALIDPARAM
;
1382 fill_joystick_dideviceinstanceW(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1383 get_joystick_index(&This
->generic
.base
.guid
));
1387 static const IDirectInputDevice8AVtbl JoystickAvt
=
1389 IDirectInputDevice2AImpl_QueryInterface
,
1390 IDirectInputDevice2AImpl_AddRef
,
1391 IDirectInputDevice2AImpl_Release
,
1392 JoystickAGenericImpl_GetCapabilities
,
1393 IDirectInputDevice2AImpl_EnumObjects
,
1394 JoystickAImpl_GetProperty
,
1395 JoystickAImpl_SetProperty
,
1396 JoystickAImpl_Acquire
,
1397 JoystickAImpl_Unacquire
,
1398 JoystickAGenericImpl_GetDeviceState
,
1399 IDirectInputDevice2AImpl_GetDeviceData
,
1400 IDirectInputDevice2AImpl_SetDataFormat
,
1401 IDirectInputDevice2AImpl_SetEventNotification
,
1402 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1403 JoystickAGenericImpl_GetObjectInfo
,
1404 JoystickAImpl_GetDeviceInfo
,
1405 IDirectInputDevice2AImpl_RunControlPanel
,
1406 IDirectInputDevice2AImpl_Initialize
,
1407 JoystickAImpl_CreateEffect
,
1408 JoystickAImpl_EnumEffects
,
1409 JoystickAImpl_GetEffectInfo
,
1410 JoystickAImpl_GetForceFeedbackState
,
1411 JoystickAImpl_SendForceFeedbackCommand
,
1412 JoystickAImpl_EnumCreatedEffectObjects
,
1413 IDirectInputDevice2AImpl_Escape
,
1414 JoystickAGenericImpl_Poll
,
1415 IDirectInputDevice2AImpl_SendDeviceData
,
1416 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1417 IDirectInputDevice7AImpl_WriteEffectToFile
,
1418 JoystickAGenericImpl_BuildActionMap
,
1419 JoystickAGenericImpl_SetActionMap
,
1420 IDirectInputDevice8AImpl_GetImageInfo
1423 static const IDirectInputDevice8WVtbl JoystickWvt
=
1425 IDirectInputDevice2WImpl_QueryInterface
,
1426 IDirectInputDevice2WImpl_AddRef
,
1427 IDirectInputDevice2WImpl_Release
,
1428 JoystickWGenericImpl_GetCapabilities
,
1429 IDirectInputDevice2WImpl_EnumObjects
,
1430 JoystickWImpl_GetProperty
,
1431 JoystickWImpl_SetProperty
,
1432 JoystickWImpl_Acquire
,
1433 JoystickWImpl_Unacquire
,
1434 JoystickWGenericImpl_GetDeviceState
,
1435 IDirectInputDevice2WImpl_GetDeviceData
,
1436 IDirectInputDevice2WImpl_SetDataFormat
,
1437 IDirectInputDevice2WImpl_SetEventNotification
,
1438 IDirectInputDevice2WImpl_SetCooperativeLevel
,
1439 JoystickWGenericImpl_GetObjectInfo
,
1440 JoystickWImpl_GetDeviceInfo
,
1441 IDirectInputDevice2WImpl_RunControlPanel
,
1442 IDirectInputDevice2WImpl_Initialize
,
1443 JoystickWImpl_CreateEffect
,
1444 JoystickWImpl_EnumEffects
,
1445 JoystickWImpl_GetEffectInfo
,
1446 JoystickWImpl_GetForceFeedbackState
,
1447 JoystickWImpl_SendForceFeedbackCommand
,
1448 JoystickWImpl_EnumCreatedEffectObjects
,
1449 IDirectInputDevice2WImpl_Escape
,
1450 JoystickWGenericImpl_Poll
,
1451 IDirectInputDevice2WImpl_SendDeviceData
,
1452 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1453 IDirectInputDevice7WImpl_WriteEffectToFile
,
1454 JoystickWGenericImpl_BuildActionMap
,
1455 JoystickWGenericImpl_SetActionMap
,
1456 IDirectInputDevice8WImpl_GetImageInfo
1459 #else /* HAS_PROPER_HEADER */
1461 const struct dinput_device joystick_linuxinput_device
= {
1462 "Wine Linux-input joystick driver",
1468 #endif /* HAS_PROPER_HEADER */