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_LINUX_INPUT_H
43 # include <linux/input.h>
45 # if defined(EVIOCGBIT) && defined(EV_ABS) && defined(BTN_PINKIE)
46 # define HAS_PROPER_HEADER
49 #ifdef HAVE_SYS_POLL_H
50 # include <sys/poll.h>
53 #include "wine/debug.h"
54 #include "wine/unicode.h"
55 #include "wine/list.h"
62 #include "dinput_private.h"
63 #include "device_private.h"
64 #include "joystick_private.h"
66 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
68 #ifdef HAS_PROPER_HEADER
70 #define EVDEVPREFIX "/dev/input/event"
71 #define EVDEVDRIVER " (event)"
73 /* Wine joystick driver object instances */
74 #define WINE_JOYSTICK_MAX_AXES 8
75 #define WINE_JOYSTICK_MAX_POVS 4
76 #define WINE_JOYSTICK_MAX_BUTTONS 128
78 struct wine_input_absinfo
{
86 /* implemented in effect_linuxinput.c */
87 HRESULT
linuxinput_create_effect(int* fd
, REFGUID rguid
, struct list
*parent_list_entry
, LPDIRECTINPUTEFFECT
* peff
);
88 HRESULT
linuxinput_get_info_A(int fd
, REFGUID rguid
, LPDIEFFECTINFOA info
);
89 HRESULT
linuxinput_get_info_W(int fd
, REFGUID rguid
, LPDIEFFECTINFOW info
);
91 typedef struct JoystickImpl JoystickImpl
;
92 static const IDirectInputDevice8AVtbl JoystickAvt
;
93 static const IDirectInputDevice8WVtbl JoystickWvt
;
103 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
104 BYTE evbits
[(EV_MAX
+7)/8];
105 BYTE absbits
[(ABS_MAX
+7)/8];
106 BYTE keybits
[(KEY_MAX
+7)/8];
107 BYTE ffbits
[(FF_MAX
+7)/8];
109 /* data returned by the EVIOCGABS() ioctl */
110 struct wine_input_absinfo axes
[ABS_MAX
];
112 WORD vendor_id
, product_id
;
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 inline JoystickImpl
*impl_from_IDirectInputDevice8A(IDirectInputDevice8A
*iface
)
138 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8A_iface
),
139 JoystickGenericImpl
, base
), JoystickImpl
, generic
);
141 static inline JoystickImpl
*impl_from_IDirectInputDevice8W(IDirectInputDevice8W
*iface
)
143 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8W_iface
),
144 JoystickGenericImpl
, base
), JoystickImpl
, generic
);
147 static inline IDirectInputDevice8W
*IDirectInputDevice8W_from_impl(JoystickImpl
*This
)
149 return &This
->generic
.base
.IDirectInputDevice8W_iface
;
152 static void fake_current_js_state(JoystickImpl
*ji
);
153 static void find_joydevs(void);
154 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
);
156 /* This GUID is slightly different from the linux joystick one. Take note. */
157 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
161 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
164 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
166 #define MAX_JOYDEV 64
168 static int have_joydevs
= -1;
169 static struct JoyDev
*joydevs
= NULL
;
171 static void find_joydevs(void)
175 if (InterlockedCompareExchange(&have_joydevs
, 0, -1) != -1)
176 /* Someone beat us to it */
179 for (i
= 0; i
< MAX_JOYDEV
; i
++)
182 struct JoyDev joydev
= {0};
184 BOOL no_ff_check
= FALSE
;
186 struct JoyDev
*new_joydevs
;
187 struct input_id device_id
= {0};
189 snprintf(buf
, sizeof(buf
), EVDEVPREFIX
"%d", i
);
191 if ((fd
= open(buf
, O_RDWR
)) == -1)
193 fd
= open(buf
, O_RDONLY
);
199 WARN("Failed to open \"%s\": %d %s\n", buf
, errno
, strerror(errno
));
203 if (ioctl(fd
, EVIOCGBIT(0, sizeof(joydev
.evbits
)), joydev
.evbits
) == -1)
205 WARN("ioctl(EVIOCGBIT, 0) failed: %d %s\n", errno
, strerror(errno
));
209 if (ioctl(fd
, EVIOCGBIT(EV_ABS
, sizeof(joydev
.absbits
)), joydev
.absbits
) == -1)
211 WARN("ioctl(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
215 if (ioctl(fd
, EVIOCGBIT(EV_KEY
, sizeof(joydev
.keybits
)), joydev
.keybits
) == -1)
217 WARN("ioctl(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno
, strerror(errno
));
222 /* A true joystick has at least axis X and Y, and at least 1
223 * button. copied from linux/drivers/input/joydev.c */
224 if (!test_bit(joydev
.absbits
, ABS_X
) || !test_bit(joydev
.absbits
, ABS_Y
) ||
225 !(test_bit(joydev
.keybits
, BTN_TRIGGER
) ||
226 test_bit(joydev
.keybits
, BTN_A
) ||
227 test_bit(joydev
.keybits
, BTN_1
)))
233 if (!(joydev
.device
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
238 strcpy(joydev
.device
, buf
);
240 buf
[MAX_PATH
- 1] = 0;
241 if (ioctl(fd
, EVIOCGNAME(MAX_PATH
- 1), buf
) != -1 &&
242 (joydev
.name
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + strlen(EVDEVDRIVER
) + 1)))
244 strcpy(joydev
.name
, buf
);
245 /* Append driver name */
246 strcat(joydev
.name
, EVDEVDRIVER
);
249 joydev
.name
= joydev
.device
;
251 if (device_disabled_registry(joydev
.name
)) {
253 HeapFree(GetProcessHeap(), 0, joydev
.name
);
254 if (joydev
.name
!= joydev
.device
)
255 HeapFree(GetProcessHeap(), 0, joydev
.device
);
259 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
260 joydev
.guid
.Data3
+= have_joydevs
;
262 TRACE("Found a joystick on %s: %s (%s)\n",
263 joydev
.device
, joydev
.name
,
264 debugstr_guid(&joydev
.guid
)
267 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
269 test_bit(joydev
.evbits
, EV_FF
) &&
270 ioctl(fd
, EVIOCGBIT(EV_FF
, sizeof(joydev
.ffbits
)), joydev
.ffbits
) != -1 &&
271 ioctl(fd
, EVIOCGEFFECTS
, &joydev
.num_effects
) != -1 &&
272 joydev
.num_effects
> 0)
274 TRACE(" ... with force feedback\n");
275 joydev
.has_ff
= TRUE
;
279 for (j
= 0; j
< ABS_MAX
;j
++)
281 if (!test_bit(joydev
.absbits
, j
)) continue;
282 if (ioctl(fd
, EVIOCGABS(j
), &(joydev
.axes
[j
])) != -1)
284 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
286 joydev
.axes
[j
].value
,
287 joydev
.axes
[j
].minimum
,
288 joydev
.axes
[j
].maximum
,
295 if (ioctl(fd
, EVIOCGID
, &device_id
) == -1)
296 WARN("ioctl(EVIOCGID) failed: %d %s\n", errno
, strerror(errno
));
299 joydev
.vendor_id
= device_id
.vendor
;
300 joydev
.product_id
= device_id
.product
;
304 new_joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
306 new_joydevs
= HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1 + have_joydevs
) * sizeof(struct JoyDev
));
313 joydevs
= new_joydevs
;
314 joydevs
[have_joydevs
] = joydev
;
321 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
323 DWORD dwSize
= lpddi
->dwSize
;
325 TRACE("%d %p\n", dwSize
, lpddi
);
326 memset(lpddi
, 0, dwSize
);
328 lpddi
->dwSize
= dwSize
;
329 lpddi
->guidInstance
= joydevs
[id
].guid
;
330 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
331 lpddi
->guidFFDriver
= GUID_NULL
;
333 if (version
>= 0x0800)
334 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
336 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
338 strcpy(lpddi
->tszInstanceName
, joydevs
[id
].name
);
339 strcpy(lpddi
->tszProductName
, joydevs
[id
].name
);
342 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
344 DWORD dwSize
= lpddi
->dwSize
;
346 TRACE("%d %p\n", dwSize
, lpddi
);
347 memset(lpddi
, 0, dwSize
);
349 lpddi
->dwSize
= dwSize
;
350 lpddi
->guidInstance
= joydevs
[id
].guid
;
351 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
352 lpddi
->guidFFDriver
= GUID_NULL
;
354 if (version
>= 0x0800)
355 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
357 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
359 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
360 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszProductName
, MAX_PATH
);
363 static HRESULT
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
367 if (id
>= have_joydevs
) {
371 if (!((dwDevType
== 0) ||
372 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
373 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
376 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
377 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
381 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
382 fill_joystick_dideviceinstanceA(lpddi
, version
, id
);
388 static HRESULT
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
392 if (id
>= have_joydevs
) {
396 if (!((dwDevType
== 0) ||
397 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
398 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
401 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
402 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
406 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
407 fill_joystick_dideviceinstanceW(lpddi
, version
, id
);
413 static JoystickImpl
*alloc_device(REFGUID rguid
, IDirectInputImpl
*dinput
, unsigned short index
)
415 JoystickImpl
* newDevice
;
416 LPDIDATAFORMAT df
= NULL
;
418 int default_axis_map
[WINE_JOYSTICK_MAX_AXES
+ WINE_JOYSTICK_MAX_POVS
*2];
420 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
421 if (!newDevice
) return NULL
;
423 newDevice
->generic
.base
.IDirectInputDevice8A_iface
.lpVtbl
= &JoystickAvt
;
424 newDevice
->generic
.base
.IDirectInputDevice8W_iface
.lpVtbl
= &JoystickWvt
;
425 newDevice
->generic
.base
.ref
= 1;
426 newDevice
->generic
.base
.guid
= *rguid
;
427 newDevice
->generic
.base
.dinput
= dinput
;
428 newDevice
->generic
.joy_polldev
= joy_polldev
;
429 newDevice
->joyfd
= -1;
430 newDevice
->joydev
= &joydevs
[index
];
431 newDevice
->generic
.name
= newDevice
->joydev
->name
;
432 list_init(&newDevice
->ff_effects
);
433 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
434 newDevice
->ff_state
= FF_STATUS_STOPPED
;
436 /* There is no way in linux to query force feedback autocenter status.
437 Instead, track it with ff_autocenter, and assume it's initially
439 newDevice
->ff_autocenter
= 1;
440 newDevice
->ff_gain
= 0xFFFF;
441 InitializeCriticalSection(&newDevice
->generic
.base
.crit
);
442 newDevice
->generic
.base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
444 /* Count number of available axes - supported Axis & POVs */
445 for (i
= 0; i
< ABS_MAX
; i
++)
447 if (i
< WINE_JOYSTICK_MAX_AXES
&&
448 test_bit(newDevice
->joydev
->absbits
, i
))
450 newDevice
->generic
.device_axis_count
++;
451 newDevice
->dev_axes_to_di
[i
] = idx
;
452 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[i
].minimum
;
453 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[i
].maximum
;
454 default_axis_map
[idx
] = i
;
458 newDevice
->dev_axes_to_di
[i
] = -1;
461 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
463 if (test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) &&
464 test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2))
466 newDevice
->generic
.device_axis_count
+= 2;
467 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].minimum
;
468 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].maximum
;
469 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = idx
;
470 newDevice
->generic
.props
[idx
+1].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].minimum
;
471 newDevice
->generic
.props
[idx
+1].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].maximum
;
472 newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = idx
+ 1;
474 default_axis_map
[idx
] = default_axis_map
[idx
+ 1] = WINE_JOYSTICK_MAX_AXES
+ i
;
478 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = -1;
481 /* do any user specified configuration */
482 if (setup_dinput_options(&newDevice
->generic
, default_axis_map
) != DI_OK
) goto failed
;
484 /* Create copy of default data format */
485 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
486 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
487 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
490 /* Construct internal data format */
492 /* Supported Axis & POVs */
493 for (i
= 0, idx
= 0; i
< newDevice
->generic
.device_axis_count
; i
++)
495 int wine_obj
= newDevice
->generic
.axis_map
[i
];
497 if (wine_obj
< 0) continue;
499 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[wine_obj
], df
->dwObjSize
);
501 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
) | DIDFT_ABSAXIS
;
504 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
- 8) | DIDFT_POV
;
505 i
++; /* POV takes 2 axes */
508 newDevice
->generic
.props
[idx
].lMin
= 0;
509 newDevice
->generic
.props
[idx
].lMax
= 0xffff;
510 newDevice
->generic
.props
[idx
].lSaturation
= 0;
511 newDevice
->generic
.props
[idx
].lDeadZone
= newDevice
->generic
.deadzone
;
513 /* Linux supports force-feedback on X & Y axes only */
514 if (newDevice
->joydev
->has_ff
&& (i
== 0 || i
== 1))
515 df
->rgodf
[idx
].dwFlags
|= DIDOI_FFACTUATOR
;
520 /* Buttons can be anywhere, so check all */
521 for (i
= 0; i
< KEY_MAX
&& newDevice
->generic
.devcaps
.dwButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
523 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
525 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->generic
.devcaps
.dwButtons
+ 12], df
->dwObjSize
);
526 newDevice
->buttons
[i
] = 0x80 | newDevice
->generic
.devcaps
.dwButtons
;
527 df
->rgodf
[idx
].pguid
= &GUID_Button
;
528 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->generic
.devcaps
.dwButtons
++) | DIDFT_PSHBUTTON
;
531 newDevice
->generic
.base
.data_format
.wine_df
= df
;
533 fake_current_js_state(newDevice
);
536 newDevice
->generic
.devcaps
.dwSize
= sizeof(newDevice
->generic
.devcaps
);
537 newDevice
->generic
.devcaps
.dwFlags
= DIDC_ATTACHED
;
538 if (newDevice
->generic
.base
.dinput
->dwVersion
>= 0x0800)
539 newDevice
->generic
.devcaps
.dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
541 newDevice
->generic
.devcaps
.dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
543 if (newDevice
->joydev
->has_ff
)
544 newDevice
->generic
.devcaps
.dwFlags
|= DIDC_FORCEFEEDBACK
;
546 IDirectInput_AddRef(&newDevice
->generic
.base
.dinput
->IDirectInput7A_iface
);
548 EnterCriticalSection(&dinput
->crit
);
549 list_add_tail(&dinput
->devices_list
, &newDevice
->generic
.base
.entry
);
550 LeaveCriticalSection(&dinput
->crit
);
555 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
556 HeapFree(GetProcessHeap(), 0, df
);
557 HeapFree(GetProcessHeap(), 0, newDevice
->generic
.axis_map
);
558 HeapFree(GetProcessHeap(), 0, newDevice
);
562 /******************************************************************************
563 * get_joystick_index : Get the joystick index from a given GUID
565 static unsigned short get_joystick_index(REFGUID guid
)
567 GUID wine_joystick
= DInput_Wine_Joystick_Base_GUID
;
568 GUID dev_guid
= *guid
;
570 wine_joystick
.Data3
= 0;
573 /* for the standard joystick GUID use index 0 */
574 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
576 /* for the wine joystick GUIDs use the index stored in Data3 */
577 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
- DInput_Wine_Joystick_Base_GUID
.Data3
;
582 static HRESULT
joydev_create_device(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPVOID
*pdev
, int unicode
)
584 unsigned short index
;
586 TRACE("%p %s %s %p %i\n", dinput
, debugstr_guid(rguid
), debugstr_guid(riid
), pdev
, unicode
);
590 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
591 have_joydevs
&& index
< have_joydevs
)
597 else if (IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
598 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
599 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
600 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
604 else if (IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
605 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
606 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
607 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
613 WARN("no interface\n");
614 return DIERR_NOINTERFACE
;
617 This
= alloc_device(rguid
, dinput
, index
);
618 TRACE("Created a Joystick device (%p)\n", This
);
620 if (!This
) return DIERR_OUTOFMEMORY
;
623 *pdev
= &This
->generic
.base
.IDirectInputDevice8W_iface
;
625 *pdev
= &This
->generic
.base
.IDirectInputDevice8A_iface
;
630 return DIERR_DEVICENOTREG
;
634 const struct dinput_device joystick_linuxinput_device
= {
635 "Wine Linux-input joystick driver",
641 /******************************************************************************
642 * Acquire : gets exclusive control of the joystick
644 static HRESULT WINAPI
JoystickWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface
)
646 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
649 TRACE("(this=%p)\n",This
);
651 if ((res
= IDirectInputDevice2WImpl_Acquire(iface
)) != DI_OK
)
653 WARN("Failed to acquire: %x\n", res
);
657 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDWR
)) == -1)
659 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDONLY
)) == -1)
661 /* Couldn't open the device at all */
662 ERR("Failed to open device %s: %d %s\n", This
->joydev
->device
, errno
, strerror(errno
));
663 IDirectInputDevice2WImpl_Unacquire(iface
);
664 return DIERR_NOTFOUND
;
668 /* Couldn't open in r/w but opened in read-only. */
669 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
674 struct input_event event
;
677 event
.code
= FF_GAIN
;
678 event
.value
= This
->ff_gain
;
679 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
680 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
681 if (!This
->ff_autocenter
)
683 /* Disable autocenter. */
684 event
.code
= FF_AUTOCENTER
;
686 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
687 ERR("Failed disabling autocenter: %d %s\n", errno
, strerror(errno
));
694 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
696 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
697 return JoystickWImpl_Acquire(IDirectInputDevice8W_from_impl(This
));
700 /******************************************************************************
701 * Unacquire : frees the joystick
703 static HRESULT WINAPI
JoystickWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface
)
705 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
708 TRACE("(this=%p)\n",This
);
709 res
= IDirectInputDevice2WImpl_Unacquire(iface
);
710 if (res
==DI_OK
&& This
->joyfd
!=-1) {
711 effect_list_item
*itr
;
712 struct input_event event
;
714 /* For each known effect:
717 * But, unlike DISFFC_RESET, do not release the effect.
719 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
) {
720 IDirectInputEffect_Stop(itr
->ref
);
721 IDirectInputEffect_Unload(itr
->ref
);
724 /* Enable autocenter. */
726 event
.code
= FF_AUTOCENTER
;
727 /* TODO: Read autocenter strength before disabling it, and use it here
728 * instead of 0xFFFF (maximum strength).
730 event
.value
= 0xFFFF;
731 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
732 ERR("Failed to set autocenter to %04x: %d %s\n", event
.value
, errno
, strerror(errno
));
740 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
742 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
743 return JoystickWImpl_Unacquire(IDirectInputDevice8W_from_impl(This
));
747 * set the current state of the js device as it would be with the middle
750 #define CENTER_AXIS(a) \
751 (ji->dev_axes_to_di[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->dev_axes_to_di[a]], \
752 ji->joydev->axes[a].value ))
753 static void fake_current_js_state(JoystickImpl
*ji
)
757 /* center the axes */
758 ji
->generic
.js
.lX
= CENTER_AXIS(ABS_X
);
759 ji
->generic
.js
.lY
= CENTER_AXIS(ABS_Y
);
760 ji
->generic
.js
.lZ
= CENTER_AXIS(ABS_Z
);
761 ji
->generic
.js
.lRx
= CENTER_AXIS(ABS_RX
);
762 ji
->generic
.js
.lRy
= CENTER_AXIS(ABS_RY
);
763 ji
->generic
.js
.lRz
= CENTER_AXIS(ABS_RZ
);
764 ji
->generic
.js
.rglSlider
[0] = CENTER_AXIS(ABS_THROTTLE
);
765 ji
->generic
.js
.rglSlider
[1] = CENTER_AXIS(ABS_RUDDER
);
767 /* POV center is -1 */
768 for (i
= 0; i
< 4; i
++)
769 ji
->generic
.js
.rgdwPOV
[i
] = -1;
773 /* convert wine format offset to user format object index */
774 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
)
777 struct input_event ie
;
778 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
788 plfd
.fd
= This
->joyfd
;
789 plfd
.events
= POLLIN
;
791 if (poll(&plfd
,1,0) != 1)
794 /* we have one event, so we can read */
795 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
798 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
800 case EV_KEY
: /* button */
802 int btn
= This
->buttons
[ie
.code
];
804 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
808 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
809 This
->generic
.js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
815 int axis
= This
->dev_axes_to_di
[ie
.code
];
817 /* User axis remapping */
819 axis
= This
->generic
.axis_map
[axis
];
822 inst_id
= axis
< 8 ? DIDFT_MAKEINSTANCE(axis
) | DIDFT_ABSAXIS
:
823 DIDFT_MAKEINSTANCE(axis
- 8) | DIDFT_POV
;
824 value
= joystick_map_axis(&This
->generic
.props
[id_to_object(This
->generic
.base
.data_format
.wine_df
, inst_id
)], ie
.value
);
827 case 0: This
->generic
.js
.lX
= value
; break;
828 case 1: This
->generic
.js
.lY
= value
; break;
829 case 2: This
->generic
.js
.lZ
= value
; break;
830 case 3: This
->generic
.js
.lRx
= value
; break;
831 case 4: This
->generic
.js
.lRy
= value
; break;
832 case 5: This
->generic
.js
.lRz
= value
; break;
833 case 6: This
->generic
.js
.rglSlider
[0] = value
; break;
834 case 7: This
->generic
.js
.rglSlider
[1] = value
; break;
835 case 8: case 9: case 10: case 11:
840 This
->povs
[idx
].y
= ie
.value
;
842 This
->povs
[idx
].x
= ie
.value
;
844 This
->generic
.js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
848 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
852 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
854 This
->ff_state
= ie
.value
;
859 /* there is nothing to do */
868 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
872 queue_event(iface
, inst_id
,
873 value
, GetCurrentTime(), This
->generic
.base
.dinput
->evsequence
++);
877 /******************************************************************************
878 * SetProperty : change input device properties
880 static HRESULT WINAPI
JoystickWImpl_SetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPCDIPROPHEADER ph
)
882 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
885 WARN("invalid argument\n");
886 return DIERR_INVALIDPARAM
;
889 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
890 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
891 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
893 if (IS_DIPROP(rguid
)) {
894 switch (LOWORD(rguid
)) {
895 case (DWORD_PTR
)DIPROP_CALIBRATIONMODE
: {
896 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
897 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd
->dwData
);
900 case (DWORD_PTR
)DIPROP_AUTOCENTER
: {
901 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
903 TRACE("autocenter(%d)\n", pd
->dwData
);
904 This
->ff_autocenter
= pd
->dwData
== DIPROPAUTOCENTER_ON
;
908 case (DWORD_PTR
)DIPROP_FFGAIN
: {
909 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
911 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
912 This
->ff_gain
= MulDiv(pd
->dwData
, 0xFFFF, 10000);
913 if (This
->generic
.base
.acquired
) {
914 /* Update immediately. */
915 struct input_event event
;
918 event
.code
= FF_GAIN
;
919 event
.value
= This
->ff_gain
;
920 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
921 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
926 return JoystickWGenericImpl_SetProperty(iface
, rguid
, ph
);
932 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPCDIPROPHEADER ph
)
934 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
935 return JoystickWImpl_SetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, ph
);
938 /******************************************************************************
939 * GetProperty : get input device properties
941 static HRESULT WINAPI
JoystickWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
943 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
945 TRACE("(this=%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
946 _dump_DIPROPHEADER(pdiph
);
948 if (!IS_DIPROP(rguid
)) return DI_OK
;
950 switch (LOWORD(rguid
)) {
951 case (DWORD_PTR
) DIPROP_AUTOCENTER
:
953 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
955 pd
->dwData
= This
->ff_autocenter
? DIPROPAUTOCENTER_ON
: DIPROPAUTOCENTER_OFF
;
956 TRACE("autocenter(%d)\n", pd
->dwData
);
959 case (DWORD_PTR
) DIPROP_FFGAIN
:
961 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
963 pd
->dwData
= MulDiv(This
->ff_gain
, 10000, 0xFFFF);
964 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
968 case (DWORD_PTR
) DIPROP_VIDPID
:
970 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
972 if (!This
->joydev
->product_id
|| !This
->joydev
->vendor_id
)
973 return DIERR_UNSUPPORTED
;
974 pd
->dwData
= MAKELONG(This
->joydev
->vendor_id
, This
->joydev
->product_id
);
975 TRACE("DIPROP_VIDPID(%08x)\n", pd
->dwData
);
979 case (DWORD_PTR
) DIPROP_JOYSTICKID
:
981 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
983 pd
->dwData
= get_joystick_index(&This
->generic
.base
.guid
);
984 TRACE("DIPROP_JOYSTICKID(%d)\n", pd
->dwData
);
989 return JoystickWGenericImpl_GetProperty(iface
, rguid
, pdiph
);
995 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
997 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
998 return JoystickWImpl_GetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, pdiph
);
1001 /******************************************************************************
1002 * CreateEffect - Create a new FF effect with the specified params
1004 static HRESULT WINAPI
JoystickWImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
,
1005 LPCDIEFFECT lpeff
, LPDIRECTINPUTEFFECT
*ppdef
,
1006 LPUNKNOWN pUnkOuter
)
1008 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1009 effect_list_item
* new_effect
= NULL
;
1010 HRESULT retval
= DI_OK
;
1013 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1014 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
1016 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1017 TRACE("not available (compiled w/o ff support)\n");
1022 if (!(new_effect
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect
))))
1023 return DIERR_OUTOFMEMORY
;
1025 retval
= linuxinput_create_effect(&This
->joyfd
, rguid
, &new_effect
->entry
, &new_effect
->ref
);
1026 if (retval
!= DI_OK
)
1028 HeapFree(GetProcessHeap(), 0, new_effect
);
1034 retval
= IDirectInputEffect_SetParameters(new_effect
->ref
, lpeff
, 0);
1036 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1038 HeapFree(GetProcessHeap(), 0, new_effect
);
1043 list_add_tail(&This
->ff_effects
, &new_effect
->entry
);
1044 *ppdef
= new_effect
->ref
;
1046 if (pUnkOuter
!= NULL
)
1047 FIXME("Interface aggregation not implemented.\n");
1051 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1054 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
,
1055 LPCDIEFFECT lpeff
, LPDIRECTINPUTEFFECT
*ppdef
,
1056 LPUNKNOWN pUnkOuter
)
1058 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1059 return JoystickWImpl_CreateEffect(IDirectInputDevice8W_from_impl(This
), rguid
, lpeff
, ppdef
, pUnkOuter
);
1062 /*******************************************************************************
1063 * EnumEffects - Enumerate available FF effects
1065 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1066 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1070 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1071 DIEFFECTINFOA dei
; /* feif */
1072 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1073 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1075 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
1077 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1079 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1080 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1081 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1082 (*lpCallback
)(&dei
, pvRef
);
1085 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1086 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1087 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1088 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1089 (*lpCallback
)(&dei
, pvRef
);
1091 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1092 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1093 (*lpCallback
)(&dei
, pvRef
);
1095 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1096 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1097 (*lpCallback
)(&dei
, pvRef
);
1099 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1100 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1101 (*lpCallback
)(&dei
, pvRef
);
1103 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1104 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1105 (*lpCallback
)(&dei
, pvRef
);
1109 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1110 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1111 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1112 (*lpCallback
)(&dei
, pvRef
);
1115 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1116 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1117 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1118 (*lpCallback
)(&dei
, pvRef
);
1120 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1121 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1122 (*lpCallback
)(&dei
, pvRef
);
1124 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1125 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1126 (*lpCallback
)(&dei
, pvRef
);
1128 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1129 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1130 (*lpCallback
)(&dei
, pvRef
);
1139 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1140 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1144 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1145 /* seems silly to duplicate all this code but all the structures and functions
1146 * are actually different (A/W) */
1147 DIEFFECTINFOW dei
; /* feif */
1148 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1149 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1150 int xfd
= This
->joyfd
;
1152 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1154 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1156 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1157 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1158 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1159 (*lpCallback
)(&dei
, pvRef
);
1162 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1163 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1164 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1165 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1166 (*lpCallback
)(&dei
, pvRef
);
1168 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1169 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1170 (*lpCallback
)(&dei
, pvRef
);
1172 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1173 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1174 (*lpCallback
)(&dei
, pvRef
);
1176 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1177 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1178 (*lpCallback
)(&dei
, pvRef
);
1180 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1181 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1182 (*lpCallback
)(&dei
, pvRef
);
1186 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1187 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1188 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1189 (*lpCallback
)(&dei
, pvRef
);
1192 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1193 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1194 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1195 (*lpCallback
)(&dei
, pvRef
);
1197 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1198 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1199 (*lpCallback
)(&dei
, pvRef
);
1201 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1202 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1203 (*lpCallback
)(&dei
, pvRef
);
1205 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1206 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1207 (*lpCallback
)(&dei
, pvRef
);
1211 /* return to unacquired state if that's where it was */
1213 IDirectInputDevice8_Unacquire(iface
);
1219 /*******************************************************************************
1220 * GetEffectInfo - Get information about a particular effect
1222 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1223 LPDIEFFECTINFOA pdei
,
1226 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1228 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1230 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1231 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1237 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1238 LPDIEFFECTINFOW pdei
,
1241 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1243 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1245 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1246 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1252 /*******************************************************************************
1253 * GetForceFeedbackState - Get information about the device's FF state
1255 static HRESULT WINAPI
JoystickWImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface
, LPDWORD pdwOut
)
1257 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1259 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1263 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1264 /* DIGFFS_STOPPED is the only mandatory flag to report */
1265 if (This
->ff_state
== FF_STATUS_STOPPED
)
1266 (*pdwOut
) |= DIGFFS_STOPPED
;
1272 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8A iface
, LPDWORD pdwOut
)
1274 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1275 return JoystickWImpl_GetForceFeedbackState(IDirectInputDevice8W_from_impl(This
), pdwOut
);
1278 /*******************************************************************************
1279 * SendForceFeedbackCommand - Send a command to the device's FF system
1281 static HRESULT WINAPI
JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface
, DWORD dwFlags
)
1283 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1284 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1286 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1289 case DISFFC_STOPALL
:
1291 /* Stop all effects */
1292 effect_list_item
*itr
;
1294 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1295 IDirectInputEffect_Stop(itr
->ref
);
1301 effect_list_item
*itr
, *ptr
;
1303 /* Stop, unload, release and free all effects */
1304 /* This returns the device to its "bare" state */
1305 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1306 IDirectInputEffect_Release(itr
->ref
);
1310 case DISFFC_CONTINUE
:
1311 FIXME("No support for Pause or Continue in linux\n");
1314 case DISFFC_SETACTUATORSOFF
:
1315 case DISFFC_SETACTUATORSON
:
1316 FIXME("No direct actuator control in linux\n");
1320 FIXME("Unknown Force Feedback Command!\n");
1321 return DIERR_INVALIDPARAM
;
1325 return DIERR_UNSUPPORTED
;
1329 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8A iface
, DWORD dwFlags
)
1331 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1332 return JoystickWImpl_SendForceFeedbackCommand(IDirectInputDevice8W_from_impl(This
), dwFlags
);
1335 /*******************************************************************************
1336 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1337 * created for this device.
1339 static HRESULT WINAPI
JoystickWImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface
,
1340 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1341 LPVOID pvRef
, DWORD dwFlags
)
1343 /* this function is safe to call on non-ff-enabled builds */
1344 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1345 effect_list_item
*itr
, *ptr
;
1347 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1350 return DIERR_INVALIDPARAM
;
1353 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1355 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1356 (*lpCallback
)(itr
->ref
, pvRef
);
1361 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8A iface
,
1362 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1363 LPVOID pvRef
, DWORD dwFlags
)
1365 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1366 return JoystickWImpl_EnumCreatedEffectObjects(IDirectInputDevice8W_from_impl(This
), lpCallback
, pvRef
, dwFlags
);
1369 /******************************************************************************
1370 * GetDeviceInfo : get information about a device's identity
1372 static HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface
,
1373 LPDIDEVICEINSTANCEA pdidi
)
1375 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1377 TRACE("(%p) %p\n", This
, pdidi
);
1379 if (pdidi
== NULL
) return E_POINTER
;
1380 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1381 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)))
1382 return DIERR_INVALIDPARAM
;
1384 fill_joystick_dideviceinstanceA(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1385 get_joystick_index(&This
->generic
.base
.guid
));
1389 static HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
,
1390 LPDIDEVICEINSTANCEW pdidi
)
1392 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
1394 TRACE("(%p) %p\n", This
, pdidi
);
1396 if (pdidi
== NULL
) return E_POINTER
;
1397 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1398 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)))
1399 return DIERR_INVALIDPARAM
;
1401 fill_joystick_dideviceinstanceW(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1402 get_joystick_index(&This
->generic
.base
.guid
));
1406 static const IDirectInputDevice8AVtbl JoystickAvt
=
1408 IDirectInputDevice2AImpl_QueryInterface
,
1409 IDirectInputDevice2AImpl_AddRef
,
1410 IDirectInputDevice2AImpl_Release
,
1411 JoystickAGenericImpl_GetCapabilities
,
1412 IDirectInputDevice2AImpl_EnumObjects
,
1413 JoystickAImpl_GetProperty
,
1414 JoystickAImpl_SetProperty
,
1415 JoystickAImpl_Acquire
,
1416 JoystickAImpl_Unacquire
,
1417 JoystickAGenericImpl_GetDeviceState
,
1418 IDirectInputDevice2AImpl_GetDeviceData
,
1419 IDirectInputDevice2AImpl_SetDataFormat
,
1420 IDirectInputDevice2AImpl_SetEventNotification
,
1421 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1422 JoystickAGenericImpl_GetObjectInfo
,
1423 JoystickAImpl_GetDeviceInfo
,
1424 IDirectInputDevice2AImpl_RunControlPanel
,
1425 IDirectInputDevice2AImpl_Initialize
,
1426 JoystickAImpl_CreateEffect
,
1427 JoystickAImpl_EnumEffects
,
1428 JoystickAImpl_GetEffectInfo
,
1429 JoystickAImpl_GetForceFeedbackState
,
1430 JoystickAImpl_SendForceFeedbackCommand
,
1431 JoystickAImpl_EnumCreatedEffectObjects
,
1432 IDirectInputDevice2AImpl_Escape
,
1433 JoystickAGenericImpl_Poll
,
1434 IDirectInputDevice2AImpl_SendDeviceData
,
1435 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1436 IDirectInputDevice7AImpl_WriteEffectToFile
,
1437 JoystickAGenericImpl_BuildActionMap
,
1438 JoystickAGenericImpl_SetActionMap
,
1439 IDirectInputDevice8AImpl_GetImageInfo
1442 static const IDirectInputDevice8WVtbl JoystickWvt
=
1444 IDirectInputDevice2WImpl_QueryInterface
,
1445 IDirectInputDevice2WImpl_AddRef
,
1446 IDirectInputDevice2WImpl_Release
,
1447 JoystickWGenericImpl_GetCapabilities
,
1448 IDirectInputDevice2WImpl_EnumObjects
,
1449 JoystickWImpl_GetProperty
,
1450 JoystickWImpl_SetProperty
,
1451 JoystickWImpl_Acquire
,
1452 JoystickWImpl_Unacquire
,
1453 JoystickWGenericImpl_GetDeviceState
,
1454 IDirectInputDevice2WImpl_GetDeviceData
,
1455 IDirectInputDevice2WImpl_SetDataFormat
,
1456 IDirectInputDevice2WImpl_SetEventNotification
,
1457 IDirectInputDevice2WImpl_SetCooperativeLevel
,
1458 JoystickWGenericImpl_GetObjectInfo
,
1459 JoystickWImpl_GetDeviceInfo
,
1460 IDirectInputDevice2WImpl_RunControlPanel
,
1461 IDirectInputDevice2WImpl_Initialize
,
1462 JoystickWImpl_CreateEffect
,
1463 JoystickWImpl_EnumEffects
,
1464 JoystickWImpl_GetEffectInfo
,
1465 JoystickWImpl_GetForceFeedbackState
,
1466 JoystickWImpl_SendForceFeedbackCommand
,
1467 JoystickWImpl_EnumCreatedEffectObjects
,
1468 IDirectInputDevice2WImpl_Escape
,
1469 JoystickWGenericImpl_Poll
,
1470 IDirectInputDevice2WImpl_SendDeviceData
,
1471 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1472 IDirectInputDevice7WImpl_WriteEffectToFile
,
1473 JoystickWGenericImpl_BuildActionMap
,
1474 JoystickWGenericImpl_SetActionMap
,
1475 IDirectInputDevice8WImpl_GetImageInfo
1478 #else /* HAS_PROPER_HEADER */
1480 const struct dinput_device joystick_linuxinput_device
= {
1481 "Wine Linux-input joystick driver",
1487 #endif /* HAS_PROPER_HEADER */