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
];
114 WORD vendor_id
, product_id
;
119 struct JoystickGenericImpl generic
;
120 struct JoyDev
*joydev
;
122 /* joystick private */
125 int dev_axes_to_di
[ABS_MAX
];
128 /* LUT for KEY_ to offset in rgbButtons */
129 BYTE buttons
[KEY_MAX
];
131 /* Force feedback variables */
132 struct list ff_effects
;
138 static inline JoystickImpl
*impl_from_IDirectInputDevice8A(IDirectInputDevice8A
*iface
)
140 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8A_iface
),
141 JoystickGenericImpl
, base
), JoystickImpl
, generic
);
143 static inline JoystickImpl
*impl_from_IDirectInputDevice8W(IDirectInputDevice8W
*iface
)
145 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8W_iface
),
146 JoystickGenericImpl
, base
), JoystickImpl
, generic
);
148 static inline IDirectInputDevice8A
*IDirectInputDevice8A_from_impl(JoystickImpl
*This
)
150 return &This
->generic
.base
.IDirectInputDevice8A_iface
;
152 static inline IDirectInputDevice8W
*IDirectInputDevice8W_from_impl(JoystickImpl
*This
)
154 return &This
->generic
.base
.IDirectInputDevice8W_iface
;
157 static void fake_current_js_state(JoystickImpl
*ji
);
158 static void find_joydevs(void);
159 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
);
161 /* This GUID is slightly different from the linux joystick one. Take note. */
162 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
166 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
169 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
171 #define MAX_JOYDEV 64
173 static int have_joydevs
= -1;
174 static struct JoyDev
*joydevs
= NULL
;
176 static void find_joydevs(void)
180 if (InterlockedCompareExchange(&have_joydevs
, 0, -1) != -1)
181 /* Someone beat us to it */
184 for (i
= 0; i
< MAX_JOYDEV
; i
++)
187 struct JoyDev joydev
= {0};
191 struct JoyDev
*new_joydevs
;
192 struct input_id device_id
= {0};
194 snprintf(buf
, sizeof(buf
), EVDEVPREFIX
"%d", i
);
196 if ((fd
= open(buf
, O_RDWR
)) == -1)
198 fd
= open(buf
, O_RDONLY
);
204 WARN("Failed to open \"%s\": %d %s\n", buf
, errno
, strerror(errno
));
208 if (ioctl(fd
, EVIOCGBIT(0, sizeof(joydev
.evbits
)), joydev
.evbits
) == -1)
210 WARN("ioct(EVIOCGBIT, 0) failed: %d %s\n", errno
, strerror(errno
));
214 if (ioctl(fd
, EVIOCGBIT(EV_ABS
, sizeof(joydev
.absbits
)), joydev
.absbits
) == -1)
216 WARN("ioct(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
220 if (ioctl(fd
, EVIOCGBIT(EV_KEY
, sizeof(joydev
.keybits
)), joydev
.keybits
) == -1)
222 WARN("ioct(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno
, strerror(errno
));
227 /* A true joystick has at least axis X and Y, and at least 1
228 * button. copied from linux/drivers/input/joydev.c */
229 if (!test_bit(joydev
.absbits
, ABS_X
) || !test_bit(joydev
.absbits
, ABS_Y
) ||
230 !(test_bit(joydev
.keybits
, BTN_TRIGGER
) ||
231 test_bit(joydev
.keybits
, BTN_A
) ||
232 test_bit(joydev
.keybits
, BTN_1
)))
238 if (!(joydev
.device
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
243 strcpy(joydev
.device
, buf
);
245 buf
[MAX_PATH
- 1] = 0;
246 if (ioctl(fd
, EVIOCGNAME(MAX_PATH
- 1), buf
) != -1 &&
247 (joydev
.name
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
248 strcpy(joydev
.name
, buf
);
250 joydev
.name
= joydev
.device
;
252 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
253 joydev
.guid
.Data3
+= have_joydevs
;
255 TRACE("Found a joystick on %s: %s (%s)\n",
256 joydev
.device
, joydev
.name
,
257 debugstr_guid(&joydev
.guid
)
260 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
262 test_bit(joydev
.evbits
, EV_FF
) &&
263 ioctl(fd
, EVIOCGBIT(EV_FF
, sizeof(joydev
.ffbits
)), joydev
.ffbits
) != -1 &&
264 ioctl(fd
, EVIOCGEFFECTS
, &joydev
.num_effects
) != -1 &&
265 joydev
.num_effects
> 0)
267 TRACE(" ... with force feedback\n");
272 for (j
= 0; j
< ABS_MAX
;j
++)
274 if (!test_bit(joydev
.absbits
, j
)) continue;
275 if (ioctl(fd
, EVIOCGABS(j
), &(joydev
.axes
[j
])) != -1)
277 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
279 joydev
.axes
[j
].value
,
280 joydev
.axes
[j
].minimum
,
281 joydev
.axes
[j
].maximum
,
288 if (ioctl(fd
, EVIOCGID
, &device_id
) == -1)
289 WARN("ioct(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
292 joydev
.vendor_id
= device_id
.vendor
;
293 joydev
.product_id
= device_id
.product
;
297 new_joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
299 new_joydevs
= HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1 + have_joydevs
) * sizeof(struct JoyDev
));
306 joydevs
= new_joydevs
;
307 memcpy(joydevs
+ have_joydevs
, &joydev
, sizeof(joydev
));
314 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
316 DWORD dwSize
= lpddi
->dwSize
;
318 TRACE("%d %p\n", dwSize
, lpddi
);
319 memset(lpddi
, 0, dwSize
);
321 lpddi
->dwSize
= dwSize
;
322 lpddi
->guidInstance
= joydevs
[id
].guid
;
323 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
324 lpddi
->guidFFDriver
= GUID_NULL
;
326 if (version
>= 0x0800)
327 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
329 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
331 strcpy(lpddi
->tszInstanceName
, joydevs
[id
].name
);
332 strcpy(lpddi
->tszProductName
, joydevs
[id
].name
);
335 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
337 DWORD dwSize
= lpddi
->dwSize
;
339 TRACE("%d %p\n", dwSize
, lpddi
);
340 memset(lpddi
, 0, dwSize
);
342 lpddi
->dwSize
= dwSize
;
343 lpddi
->guidInstance
= joydevs
[id
].guid
;
344 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
345 lpddi
->guidFFDriver
= GUID_NULL
;
347 if (version
>= 0x0800)
348 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
350 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
352 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
353 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszProductName
, MAX_PATH
);
356 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
360 if (id
>= have_joydevs
) {
364 if (!((dwDevType
== 0) ||
365 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
366 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
369 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
370 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
374 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
375 fill_joystick_dideviceinstanceA(lpddi
, version
, id
);
381 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
385 if (id
>= have_joydevs
) {
389 if (!((dwDevType
== 0) ||
390 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
391 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
394 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
395 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
399 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
400 fill_joystick_dideviceinstanceW(lpddi
, version
, id
);
406 static JoystickImpl
*alloc_device(REFGUID rguid
, IDirectInputImpl
*dinput
, unsigned short index
)
408 JoystickImpl
* newDevice
;
409 LPDIDATAFORMAT df
= NULL
;
411 int default_axis_map
[WINE_JOYSTICK_MAX_AXES
+ WINE_JOYSTICK_MAX_POVS
*2];
413 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
414 if (!newDevice
) return NULL
;
416 newDevice
->generic
.base
.IDirectInputDevice8A_iface
.lpVtbl
= &JoystickAvt
;
417 newDevice
->generic
.base
.IDirectInputDevice8W_iface
.lpVtbl
= &JoystickWvt
;
418 newDevice
->generic
.base
.ref
= 1;
419 newDevice
->generic
.base
.guid
= *rguid
;
420 newDevice
->generic
.base
.dinput
= dinput
;
421 newDevice
->generic
.joy_polldev
= joy_polldev
;
422 newDevice
->joyfd
= -1;
423 newDevice
->joydev
= &joydevs
[index
];
424 newDevice
->generic
.name
= newDevice
->joydev
->name
;
425 list_init(&newDevice
->ff_effects
);
426 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
427 newDevice
->ff_state
= FF_STATUS_STOPPED
;
429 /* There is no way in linux to query force feedback autocenter status.
430 Instead, track it with ff_autocenter, and assume it's initially
432 newDevice
->ff_autocenter
= 1;
433 newDevice
->ff_gain
= 0xFFFF;
434 InitializeCriticalSection(&newDevice
->generic
.base
.crit
);
435 newDevice
->generic
.base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
437 /* Count number of available axes - supported Axis & POVs */
438 for (i
= 0; i
< WINE_JOYSTICK_MAX_AXES
; i
++)
440 if (test_bit(newDevice
->joydev
->absbits
, i
))
442 newDevice
->generic
.device_axis_count
++;
443 newDevice
->dev_axes_to_di
[i
] = idx
;
444 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[i
].minimum
;
445 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[i
].maximum
;
446 default_axis_map
[idx
] = i
;
450 newDevice
->dev_axes_to_di
[i
] = -1;
453 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
455 if (test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) &&
456 test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2))
458 newDevice
->generic
.device_axis_count
+= 2;
459 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].minimum
;
460 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].maximum
;
461 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = idx
;
462 newDevice
->generic
.props
[idx
+1].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].minimum
;
463 newDevice
->generic
.props
[idx
+1].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].maximum
;
464 newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = idx
+ 1;
466 default_axis_map
[idx
] = default_axis_map
[idx
+ 1] = WINE_JOYSTICK_MAX_AXES
+ i
;
470 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = -1;
473 /* do any user specified configuration */
474 if (setup_dinput_options(&newDevice
->generic
, default_axis_map
) != DI_OK
) goto failed
;
476 /* Create copy of default data format */
477 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
478 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
479 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
482 /* Construct internal data format */
484 /* Supported Axis & POVs */
485 for (i
= 0, idx
= 0; i
< newDevice
->generic
.device_axis_count
; i
++)
487 int wine_obj
= newDevice
->generic
.axis_map
[i
];
489 if (wine_obj
< 0) continue;
491 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[wine_obj
], df
->dwObjSize
);
493 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
) | DIDFT_ABSAXIS
;
496 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
- 8) | DIDFT_POV
;
497 i
++; /* POV takes 2 axes */
500 newDevice
->generic
.props
[idx
].lMin
= 0;
501 newDevice
->generic
.props
[idx
].lMax
= 0xffff;
502 newDevice
->generic
.props
[idx
].lSaturation
= 0;
503 newDevice
->generic
.props
[idx
].lDeadZone
= newDevice
->generic
.deadzone
;
505 /* Linux supports force-feedback on X & Y axes only */
506 if (newDevice
->joydev
->has_ff
&& (i
== 0 || i
== 1))
507 df
->rgodf
[idx
].dwFlags
|= DIDOI_FFACTUATOR
;
512 /* Buttons can be anywhere, so check all */
513 for (i
= 0; i
< KEY_MAX
&& newDevice
->generic
.devcaps
.dwButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
515 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
517 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->generic
.devcaps
.dwButtons
+ 12], df
->dwObjSize
);
518 newDevice
->buttons
[i
] = 0x80 | newDevice
->generic
.devcaps
.dwButtons
;
519 df
->rgodf
[idx
].pguid
= &GUID_Button
;
520 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->generic
.devcaps
.dwButtons
++) | DIDFT_PSHBUTTON
;
523 newDevice
->generic
.base
.data_format
.wine_df
= df
;
525 fake_current_js_state(newDevice
);
528 newDevice
->generic
.devcaps
.dwSize
= sizeof(newDevice
->generic
.devcaps
);
529 newDevice
->generic
.devcaps
.dwFlags
= DIDC_ATTACHED
;
530 if (newDevice
->generic
.base
.dinput
->dwVersion
>= 0x0800)
531 newDevice
->generic
.devcaps
.dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
533 newDevice
->generic
.devcaps
.dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
535 if (newDevice
->joydev
->has_ff
)
536 newDevice
->generic
.devcaps
.dwFlags
|= DIDC_FORCEFEEDBACK
;
538 IDirectInput_AddRef(&newDevice
->generic
.base
.dinput
->IDirectInput7A_iface
);
540 EnterCriticalSection(&dinput
->crit
);
541 list_add_tail(&dinput
->devices_list
, &newDevice
->generic
.base
.entry
);
542 LeaveCriticalSection(&dinput
->crit
);
547 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
548 HeapFree(GetProcessHeap(), 0, df
);
549 HeapFree(GetProcessHeap(), 0, newDevice
->generic
.axis_map
);
550 HeapFree(GetProcessHeap(), 0, newDevice
);
554 /******************************************************************************
555 * get_joystick_index : Get the joystick index from a given GUID
557 static unsigned short get_joystick_index(REFGUID guid
)
559 GUID wine_joystick
= DInput_Wine_Joystick_Base_GUID
;
560 GUID dev_guid
= *guid
;
562 wine_joystick
.Data3
= 0;
565 /* for the standard joystick GUID use index 0 */
566 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
568 /* for the wine joystick GUIDs use the index stored in Data3 */
569 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
- DInput_Wine_Joystick_Base_GUID
.Data3
;
574 static HRESULT
joydev_create_device(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPVOID
*pdev
, int unicode
)
576 unsigned short index
;
578 TRACE("%p %s %s %p %i\n", dinput
, debugstr_guid(rguid
), debugstr_guid(riid
), pdev
, unicode
);
582 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
583 have_joydevs
&& index
< have_joydevs
)
589 else if (IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
590 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
591 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
592 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
596 else if (IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
597 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
598 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
599 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
605 WARN("no interface\n");
606 return DIERR_NOINTERFACE
;
609 This
= alloc_device(rguid
, dinput
, index
);
610 TRACE("Created a Joystick device (%p)\n", This
);
612 if (!This
) return DIERR_OUTOFMEMORY
;
615 *pdev
= &This
->generic
.base
.IDirectInputDevice8W_iface
;
617 *pdev
= &This
->generic
.base
.IDirectInputDevice8A_iface
;
622 return DIERR_DEVICENOTREG
;
626 const struct dinput_device joystick_linuxinput_device
= {
627 "Wine Linux-input joystick driver",
633 /******************************************************************************
634 * Acquire : gets exclusive control of the joystick
636 static HRESULT WINAPI
JoystickWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface
)
638 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
641 TRACE("(this=%p)\n",This
);
643 if ((res
= IDirectInputDevice2WImpl_Acquire(iface
)) != DI_OK
)
645 WARN("Failed to acquire: %x\n", res
);
649 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDWR
)) == -1)
651 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDONLY
)) == -1)
653 /* Couldn't open the device at all */
654 ERR("Failed to open device %s: %d %s\n", This
->joydev
->device
, errno
, strerror(errno
));
655 IDirectInputDevice2WImpl_Unacquire(iface
);
656 return DIERR_NOTFOUND
;
660 /* Couldn't open in r/w but opened in read-only. */
661 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
666 struct input_event event
;
669 event
.code
= FF_GAIN
;
670 event
.value
= This
->ff_gain
;
671 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
672 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
673 if (!This
->ff_autocenter
)
675 /* Disable autocenter. */
676 event
.code
= FF_AUTOCENTER
;
678 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
679 ERR("Failed disabling autocenter: %d %s\n", errno
, strerror(errno
));
686 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
688 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
689 return JoystickWImpl_Acquire(IDirectInputDevice8W_from_impl(This
));
692 /******************************************************************************
693 * Unacquire : frees the joystick
695 static HRESULT WINAPI
JoystickWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface
)
697 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
700 TRACE("(this=%p)\n",This
);
701 res
= IDirectInputDevice2WImpl_Unacquire(iface
);
702 if (res
==DI_OK
&& This
->joyfd
!=-1) {
703 effect_list_item
*itr
;
704 struct input_event event
;
706 /* For each known effect:
709 * But, unlike DISFFC_RESET, do not release the effect.
711 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
) {
712 IDirectInputEffect_Stop(itr
->ref
);
713 IDirectInputEffect_Unload(itr
->ref
);
716 /* Enable autocenter. */
718 event
.code
= FF_AUTOCENTER
;
719 /* TODO: Read autocenter strength before disabling it, and use it here
720 * instead of 0xFFFF (maximum strength).
722 event
.value
= 0xFFFF;
723 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
724 ERR("Failed to set autocenter to %04x: %d %s\n", event
.value
, errno
, strerror(errno
));
732 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
734 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
735 return JoystickWImpl_Unacquire(IDirectInputDevice8W_from_impl(This
));
739 * set the current state of the js device as it would be with the middle
742 #define CENTER_AXIS(a) \
743 (ji->dev_axes_to_di[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->dev_axes_to_di[a]], \
744 ji->joydev->axes[a].value ))
745 static void fake_current_js_state(JoystickImpl
*ji
)
749 /* center the axes */
750 ji
->generic
.js
.lX
= CENTER_AXIS(ABS_X
);
751 ji
->generic
.js
.lY
= CENTER_AXIS(ABS_Y
);
752 ji
->generic
.js
.lZ
= CENTER_AXIS(ABS_Z
);
753 ji
->generic
.js
.lRx
= CENTER_AXIS(ABS_RX
);
754 ji
->generic
.js
.lRy
= CENTER_AXIS(ABS_RY
);
755 ji
->generic
.js
.lRz
= CENTER_AXIS(ABS_RZ
);
756 ji
->generic
.js
.rglSlider
[0] = CENTER_AXIS(ABS_THROTTLE
);
757 ji
->generic
.js
.rglSlider
[1] = CENTER_AXIS(ABS_RUDDER
);
759 /* POV center is -1 */
760 for (i
= 0; i
< 4; i
++)
761 ji
->generic
.js
.rgdwPOV
[i
] = -1;
765 /* convert wine format offset to user format object index */
766 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
)
769 struct input_event ie
;
770 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
780 plfd
.fd
= This
->joyfd
;
781 plfd
.events
= POLLIN
;
783 if (poll(&plfd
,1,0) != 1)
786 /* we have one event, so we can read */
787 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
790 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
792 case EV_KEY
: /* button */
794 int btn
= This
->buttons
[ie
.code
];
796 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
800 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
801 This
->generic
.js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
807 int axis
= This
->dev_axes_to_di
[ie
.code
];
809 /* User axis remapping */
811 axis
= This
->generic
.axis_map
[axis
];
814 inst_id
= axis
< 8 ? DIDFT_MAKEINSTANCE(axis
) | DIDFT_ABSAXIS
:
815 DIDFT_MAKEINSTANCE(axis
- 8) | DIDFT_POV
;
816 value
= joystick_map_axis(&This
->generic
.props
[id_to_object(This
->generic
.base
.data_format
.wine_df
, inst_id
)], ie
.value
);
819 case 0: This
->generic
.js
.lX
= value
; break;
820 case 1: This
->generic
.js
.lY
= value
; break;
821 case 2: This
->generic
.js
.lZ
= value
; break;
822 case 3: This
->generic
.js
.lRx
= value
; break;
823 case 4: This
->generic
.js
.lRy
= value
; break;
824 case 5: This
->generic
.js
.lRz
= value
; break;
825 case 6: This
->generic
.js
.rglSlider
[0] = value
; break;
826 case 7: This
->generic
.js
.rglSlider
[1] = value
; break;
827 case 8: case 9: case 10: case 11:
832 This
->povs
[idx
].y
= ie
.value
;
834 This
->povs
[idx
].x
= ie
.value
;
836 This
->generic
.js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
840 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
844 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
846 This
->ff_state
= ie
.value
;
851 /* there is nothing to do */
860 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
864 queue_event(iface
, inst_id
,
865 value
, ie
.time
.tv_usec
, This
->generic
.base
.dinput
->evsequence
++);
869 /******************************************************************************
870 * SetProperty : change input device properties
872 static HRESULT WINAPI
JoystickWImpl_SetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPCDIPROPHEADER ph
)
874 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
877 WARN("invalid argument\n");
878 return DIERR_INVALIDPARAM
;
881 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
882 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
883 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
885 if (IS_DIPROP(rguid
)) {
886 switch (LOWORD(rguid
)) {
887 case (DWORD_PTR
)DIPROP_CALIBRATIONMODE
: {
888 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
889 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd
->dwData
);
892 case (DWORD_PTR
)DIPROP_AUTOCENTER
: {
893 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
895 TRACE("autocenter(%d)\n", pd
->dwData
);
896 This
->ff_autocenter
= pd
->dwData
== DIPROPAUTOCENTER_ON
;
900 case (DWORD_PTR
)DIPROP_FFGAIN
: {
901 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
903 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
904 This
->ff_gain
= MulDiv(pd
->dwData
, 0xFFFF, 10000);
905 if (This
->generic
.base
.acquired
) {
906 /* Update immediately. */
907 struct input_event event
;
910 event
.code
= FF_GAIN
;
911 event
.value
= This
->ff_gain
;
912 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
913 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
918 return JoystickWGenericImpl_SetProperty(iface
, rguid
, ph
);
924 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPCDIPROPHEADER ph
)
926 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
927 return JoystickWImpl_SetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, ph
);
930 /******************************************************************************
931 * GetProperty : get input device properties
933 static HRESULT WINAPI
JoystickWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
935 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
937 TRACE("(this=%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
938 _dump_DIPROPHEADER(pdiph
);
940 if (!IS_DIPROP(rguid
)) return DI_OK
;
942 switch (LOWORD(rguid
)) {
943 case (DWORD_PTR
) DIPROP_AUTOCENTER
:
945 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
947 pd
->dwData
= This
->ff_autocenter
? DIPROPAUTOCENTER_ON
: DIPROPAUTOCENTER_OFF
;
948 TRACE("autocenter(%d)\n", pd
->dwData
);
951 case (DWORD_PTR
) DIPROP_FFGAIN
:
953 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
955 pd
->dwData
= MulDiv(This
->ff_gain
, 10000, 0xFFFF);
956 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
960 case (DWORD_PTR
) DIPROP_VIDPID
:
962 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
964 if (!This
->joydev
->product_id
|| !This
->joydev
->vendor_id
)
965 return DIERR_UNSUPPORTED
;
966 pd
->dwData
= MAKELONG(This
->joydev
->vendor_id
, This
->joydev
->product_id
);
967 TRACE("DIPROP_VIDPID(%08x)\n", pd
->dwData
);
972 return JoystickWGenericImpl_GetProperty(iface
, rguid
, pdiph
);
978 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
980 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
981 return JoystickWImpl_GetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, pdiph
);
984 /******************************************************************************
985 * CreateEffect - Create a new FF effect with the specified params
987 static HRESULT WINAPI
JoystickWImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
,
988 LPCDIEFFECT lpeff
, LPDIRECTINPUTEFFECT
*ppdef
,
991 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
992 effect_list_item
* new_effect
= NULL
;
993 HRESULT retval
= DI_OK
;
996 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
997 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
999 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1000 TRACE("not available (compiled w/o ff support)\n");
1005 if (!(new_effect
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect
))))
1006 return DIERR_OUTOFMEMORY
;
1008 retval
= linuxinput_create_effect(&This
->joyfd
, rguid
, &new_effect
->entry
, &new_effect
->ref
);
1009 if (retval
!= DI_OK
)
1011 HeapFree(GetProcessHeap(), 0, new_effect
);
1017 retval
= IDirectInputEffect_SetParameters(new_effect
->ref
, lpeff
, 0);
1019 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1021 HeapFree(GetProcessHeap(), 0, new_effect
);
1026 list_add_tail(&This
->ff_effects
, &new_effect
->entry
);
1027 *ppdef
= new_effect
->ref
;
1029 if (pUnkOuter
!= NULL
)
1030 FIXME("Interface aggregation not implemented.\n");
1034 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1037 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
,
1038 LPCDIEFFECT lpeff
, LPDIRECTINPUTEFFECT
*ppdef
,
1039 LPUNKNOWN pUnkOuter
)
1041 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1042 return JoystickWImpl_CreateEffect(IDirectInputDevice8W_from_impl(This
), rguid
, lpeff
, ppdef
, pUnkOuter
);
1045 /*******************************************************************************
1046 * EnumEffects - Enumerate available FF effects
1048 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1049 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1053 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1054 DIEFFECTINFOA dei
; /* feif */
1055 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1056 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1058 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
1060 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1062 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1063 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1064 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1065 (*lpCallback
)(&dei
, pvRef
);
1068 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1069 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1070 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1071 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1072 (*lpCallback
)(&dei
, pvRef
);
1074 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1075 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1076 (*lpCallback
)(&dei
, pvRef
);
1078 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1079 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1080 (*lpCallback
)(&dei
, pvRef
);
1082 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1083 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1084 (*lpCallback
)(&dei
, pvRef
);
1086 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1087 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1088 (*lpCallback
)(&dei
, pvRef
);
1092 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1093 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1094 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1095 (*lpCallback
)(&dei
, pvRef
);
1098 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1099 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1100 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1101 (*lpCallback
)(&dei
, pvRef
);
1103 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1104 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1105 (*lpCallback
)(&dei
, pvRef
);
1107 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1108 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1109 (*lpCallback
)(&dei
, pvRef
);
1111 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1112 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1113 (*lpCallback
)(&dei
, pvRef
);
1122 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1123 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1127 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1128 /* seems silly to duplicate all this code but all the structures and functions
1129 * are actually different (A/W) */
1130 DIEFFECTINFOW dei
; /* feif */
1131 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1132 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1133 int xfd
= This
->joyfd
;
1135 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1137 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1139 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1140 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1141 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1142 (*lpCallback
)(&dei
, pvRef
);
1145 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1146 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1147 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1148 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1149 (*lpCallback
)(&dei
, pvRef
);
1151 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1152 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1153 (*lpCallback
)(&dei
, pvRef
);
1155 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1156 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1157 (*lpCallback
)(&dei
, pvRef
);
1159 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1160 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1161 (*lpCallback
)(&dei
, pvRef
);
1163 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1164 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1165 (*lpCallback
)(&dei
, pvRef
);
1169 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1170 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1171 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1172 (*lpCallback
)(&dei
, pvRef
);
1175 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1176 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1177 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1178 (*lpCallback
)(&dei
, pvRef
);
1180 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1181 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1182 (*lpCallback
)(&dei
, pvRef
);
1184 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1185 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1186 (*lpCallback
)(&dei
, pvRef
);
1188 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1189 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1190 (*lpCallback
)(&dei
, pvRef
);
1194 /* return to unacquired state if that's where it was */
1196 IDirectInputDevice8_Unacquire(iface
);
1202 /*******************************************************************************
1203 * GetEffectInfo - Get information about a particular effect
1205 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1206 LPDIEFFECTINFOA pdei
,
1209 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1211 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1213 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1214 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1220 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1221 LPDIEFFECTINFOW pdei
,
1224 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1226 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1228 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1229 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1235 /*******************************************************************************
1236 * GetForceFeedbackState - Get information about the device's FF state
1238 static HRESULT WINAPI
JoystickWImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface
, LPDWORD pdwOut
)
1240 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1242 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1246 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1247 /* DIGFFS_STOPPED is the only mandatory flag to report */
1248 if (This
->ff_state
== FF_STATUS_STOPPED
)
1249 (*pdwOut
) |= DIGFFS_STOPPED
;
1255 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8A iface
, LPDWORD pdwOut
)
1257 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1258 return JoystickWImpl_GetForceFeedbackState(IDirectInputDevice8W_from_impl(This
), pdwOut
);
1261 /*******************************************************************************
1262 * SendForceFeedbackCommand - Send a command to the device's FF system
1264 static HRESULT WINAPI
JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface
, DWORD dwFlags
)
1266 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1267 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1269 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1272 case DISFFC_STOPALL
:
1274 /* Stop all effects */
1275 effect_list_item
*itr
;
1277 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1278 IDirectInputEffect_Stop(itr
->ref
);
1284 effect_list_item
*itr
, *ptr
;
1286 /* Stop, unload, release and free all effects */
1287 /* This returns the device to its "bare" state */
1288 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1289 IDirectInputEffect_Release(itr
->ref
);
1293 case DISFFC_CONTINUE
:
1294 FIXME("No support for Pause or Continue in linux\n");
1297 case DISFFC_SETACTUATORSOFF
:
1298 case DISFFC_SETACTUATORSON
:
1299 FIXME("No direct actuator control in linux\n");
1303 FIXME("Unknown Force Feedback Command!\n");
1304 return DIERR_INVALIDPARAM
;
1308 return DIERR_UNSUPPORTED
;
1312 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8A iface
, DWORD dwFlags
)
1314 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1315 return JoystickWImpl_SendForceFeedbackCommand(IDirectInputDevice8W_from_impl(This
), dwFlags
);
1318 /*******************************************************************************
1319 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1320 * created for this device.
1322 static HRESULT WINAPI
JoystickWImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface
,
1323 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1324 LPVOID pvRef
, DWORD dwFlags
)
1326 /* this function is safe to call on non-ff-enabled builds */
1327 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1328 effect_list_item
*itr
, *ptr
;
1330 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1333 return DIERR_INVALIDPARAM
;
1336 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1338 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1339 (*lpCallback
)(itr
->ref
, pvRef
);
1344 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8A iface
,
1345 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1346 LPVOID pvRef
, DWORD dwFlags
)
1348 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1349 return JoystickWImpl_EnumCreatedEffectObjects(IDirectInputDevice8W_from_impl(This
), lpCallback
, pvRef
, dwFlags
);
1352 /******************************************************************************
1353 * GetDeviceInfo : get information about a device's identity
1355 static HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface
,
1356 LPDIDEVICEINSTANCEA pdidi
)
1358 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1360 TRACE("(%p) %p\n", This
, pdidi
);
1362 if (pdidi
== NULL
) return E_POINTER
;
1363 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1364 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)))
1365 return DIERR_INVALIDPARAM
;
1367 fill_joystick_dideviceinstanceA(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1368 get_joystick_index(&This
->generic
.base
.guid
));
1372 static HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
,
1373 LPDIDEVICEINSTANCEW pdidi
)
1375 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
1377 TRACE("(%p) %p\n", This
, pdidi
);
1379 if (pdidi
== NULL
) return E_POINTER
;
1380 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1381 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)))
1382 return DIERR_INVALIDPARAM
;
1384 fill_joystick_dideviceinstanceW(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1385 get_joystick_index(&This
->generic
.base
.guid
));
1389 static const IDirectInputDevice8AVtbl JoystickAvt
=
1391 IDirectInputDevice2AImpl_QueryInterface
,
1392 IDirectInputDevice2AImpl_AddRef
,
1393 IDirectInputDevice2AImpl_Release
,
1394 JoystickAGenericImpl_GetCapabilities
,
1395 IDirectInputDevice2AImpl_EnumObjects
,
1396 JoystickAImpl_GetProperty
,
1397 JoystickAImpl_SetProperty
,
1398 JoystickAImpl_Acquire
,
1399 JoystickAImpl_Unacquire
,
1400 JoystickAGenericImpl_GetDeviceState
,
1401 IDirectInputDevice2AImpl_GetDeviceData
,
1402 IDirectInputDevice2AImpl_SetDataFormat
,
1403 IDirectInputDevice2AImpl_SetEventNotification
,
1404 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1405 JoystickAGenericImpl_GetObjectInfo
,
1406 JoystickAImpl_GetDeviceInfo
,
1407 IDirectInputDevice2AImpl_RunControlPanel
,
1408 IDirectInputDevice2AImpl_Initialize
,
1409 JoystickAImpl_CreateEffect
,
1410 JoystickAImpl_EnumEffects
,
1411 JoystickAImpl_GetEffectInfo
,
1412 JoystickAImpl_GetForceFeedbackState
,
1413 JoystickAImpl_SendForceFeedbackCommand
,
1414 JoystickAImpl_EnumCreatedEffectObjects
,
1415 IDirectInputDevice2AImpl_Escape
,
1416 JoystickAGenericImpl_Poll
,
1417 IDirectInputDevice2AImpl_SendDeviceData
,
1418 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1419 IDirectInputDevice7AImpl_WriteEffectToFile
,
1420 JoystickAGenericImpl_BuildActionMap
,
1421 JoystickAGenericImpl_SetActionMap
,
1422 IDirectInputDevice8AImpl_GetImageInfo
1425 static const IDirectInputDevice8WVtbl JoystickWvt
=
1427 IDirectInputDevice2WImpl_QueryInterface
,
1428 IDirectInputDevice2WImpl_AddRef
,
1429 IDirectInputDevice2WImpl_Release
,
1430 JoystickWGenericImpl_GetCapabilities
,
1431 IDirectInputDevice2WImpl_EnumObjects
,
1432 JoystickWImpl_GetProperty
,
1433 JoystickWImpl_SetProperty
,
1434 JoystickWImpl_Acquire
,
1435 JoystickWImpl_Unacquire
,
1436 JoystickWGenericImpl_GetDeviceState
,
1437 IDirectInputDevice2WImpl_GetDeviceData
,
1438 IDirectInputDevice2WImpl_SetDataFormat
,
1439 IDirectInputDevice2WImpl_SetEventNotification
,
1440 IDirectInputDevice2WImpl_SetCooperativeLevel
,
1441 JoystickWGenericImpl_GetObjectInfo
,
1442 JoystickWImpl_GetDeviceInfo
,
1443 IDirectInputDevice2WImpl_RunControlPanel
,
1444 IDirectInputDevice2WImpl_Initialize
,
1445 JoystickWImpl_CreateEffect
,
1446 JoystickWImpl_EnumEffects
,
1447 JoystickWImpl_GetEffectInfo
,
1448 JoystickWImpl_GetForceFeedbackState
,
1449 JoystickWImpl_SendForceFeedbackCommand
,
1450 JoystickWImpl_EnumCreatedEffectObjects
,
1451 IDirectInputDevice2WImpl_Escape
,
1452 JoystickWGenericImpl_Poll
,
1453 IDirectInputDevice2WImpl_SendDeviceData
,
1454 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1455 IDirectInputDevice7WImpl_WriteEffectToFile
,
1456 JoystickWGenericImpl_BuildActionMap
,
1457 JoystickWGenericImpl_SetActionMap
,
1458 IDirectInputDevice8WImpl_GetImageInfo
1461 #else /* HAVE_CORRECT_LINUXINPUT_H */
1463 const struct dinput_device joystick_linuxinput_device
= {
1464 "Wine Linux-input joystick driver",
1470 #endif /* HAVE_CORRECT_LINUXINPUT_H */