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 HAVE_CORRECT_LINUXINPUT_H
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 HAVE_CORRECT_LINUXINPUT_H
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
);
146 static inline IDirectInputDevice8A
*IDirectInputDevice8A_from_impl(JoystickImpl
*This
)
148 return &This
->generic
.base
.IDirectInputDevice8A_iface
;
150 static inline IDirectInputDevice8W
*IDirectInputDevice8W_from_impl(JoystickImpl
*This
)
152 return &This
->generic
.base
.IDirectInputDevice8W_iface
;
155 static void fake_current_js_state(JoystickImpl
*ji
);
156 static void find_joydevs(void);
157 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
);
159 /* This GUID is slightly different from the linux joystick one. Take note. */
160 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
164 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
167 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
169 #define MAX_JOYDEV 64
171 static int have_joydevs
= -1;
172 static struct JoyDev
*joydevs
= NULL
;
174 static void find_joydevs(void)
178 if (InterlockedCompareExchange(&have_joydevs
, 0, -1) != -1)
179 /* Someone beat us to it */
182 for (i
= 0; i
< MAX_JOYDEV
; i
++)
185 struct JoyDev joydev
= {0};
189 struct JoyDev
*new_joydevs
;
190 struct input_id device_id
= {0};
192 snprintf(buf
, sizeof(buf
), EVDEVPREFIX
"%d", i
);
194 if ((fd
= open(buf
, O_RDWR
)) == -1)
196 fd
= open(buf
, O_RDONLY
);
202 WARN("Failed to open \"%s\": %d %s\n", buf
, errno
, strerror(errno
));
206 if (ioctl(fd
, EVIOCGBIT(0, sizeof(joydev
.evbits
)), joydev
.evbits
) == -1)
208 WARN("ioct(EVIOCGBIT, 0) failed: %d %s\n", errno
, strerror(errno
));
212 if (ioctl(fd
, EVIOCGBIT(EV_ABS
, sizeof(joydev
.absbits
)), joydev
.absbits
) == -1)
214 WARN("ioct(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
218 if (ioctl(fd
, EVIOCGBIT(EV_KEY
, sizeof(joydev
.keybits
)), joydev
.keybits
) == -1)
220 WARN("ioct(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno
, strerror(errno
));
225 /* A true joystick has at least axis X and Y, and at least 1
226 * button. copied from linux/drivers/input/joydev.c */
227 if (!test_bit(joydev
.absbits
, ABS_X
) || !test_bit(joydev
.absbits
, ABS_Y
) ||
228 !(test_bit(joydev
.keybits
, BTN_TRIGGER
) ||
229 test_bit(joydev
.keybits
, BTN_A
) ||
230 test_bit(joydev
.keybits
, BTN_1
)))
236 if (!(joydev
.device
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
241 strcpy(joydev
.device
, buf
);
243 buf
[MAX_PATH
- 1] = 0;
244 if (ioctl(fd
, EVIOCGNAME(MAX_PATH
- 1), buf
) != -1 &&
245 (joydev
.name
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + strlen(EVDEVDRIVER
) + 1)))
247 strcpy(joydev
.name
, buf
);
248 /* Append driver name */
249 strcat(joydev
.name
, EVDEVDRIVER
);
252 joydev
.name
= joydev
.device
;
254 if (device_disabled_registry(joydev
.name
)) {
256 HeapFree(GetProcessHeap(), 0, joydev
.name
);
257 if (joydev
.name
!= joydev
.device
)
258 HeapFree(GetProcessHeap(), 0, joydev
.device
);
262 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
263 joydev
.guid
.Data3
+= have_joydevs
;
265 TRACE("Found a joystick on %s: %s (%s)\n",
266 joydev
.device
, joydev
.name
,
267 debugstr_guid(&joydev
.guid
)
270 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
272 test_bit(joydev
.evbits
, EV_FF
) &&
273 ioctl(fd
, EVIOCGBIT(EV_FF
, sizeof(joydev
.ffbits
)), joydev
.ffbits
) != -1 &&
274 ioctl(fd
, EVIOCGEFFECTS
, &joydev
.num_effects
) != -1 &&
275 joydev
.num_effects
> 0)
277 TRACE(" ... with force feedback\n");
282 for (j
= 0; j
< ABS_MAX
;j
++)
284 if (!test_bit(joydev
.absbits
, j
)) continue;
285 if (ioctl(fd
, EVIOCGABS(j
), &(joydev
.axes
[j
])) != -1)
287 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
289 joydev
.axes
[j
].value
,
290 joydev
.axes
[j
].minimum
,
291 joydev
.axes
[j
].maximum
,
298 if (ioctl(fd
, EVIOCGID
, &device_id
) == -1)
299 WARN("ioct(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
302 joydev
.vendor_id
= device_id
.vendor
;
303 joydev
.product_id
= device_id
.product
;
307 new_joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
309 new_joydevs
= HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1 + have_joydevs
) * sizeof(struct JoyDev
));
316 joydevs
= new_joydevs
;
317 memcpy(joydevs
+ have_joydevs
, &joydev
, sizeof(joydev
));
324 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
326 DWORD dwSize
= lpddi
->dwSize
;
328 TRACE("%d %p\n", dwSize
, lpddi
);
329 memset(lpddi
, 0, dwSize
);
331 lpddi
->dwSize
= dwSize
;
332 lpddi
->guidInstance
= joydevs
[id
].guid
;
333 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
334 lpddi
->guidFFDriver
= GUID_NULL
;
336 if (version
>= 0x0800)
337 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
339 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
341 strcpy(lpddi
->tszInstanceName
, joydevs
[id
].name
);
342 strcpy(lpddi
->tszProductName
, joydevs
[id
].name
);
345 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
347 DWORD dwSize
= lpddi
->dwSize
;
349 TRACE("%d %p\n", dwSize
, lpddi
);
350 memset(lpddi
, 0, dwSize
);
352 lpddi
->dwSize
= dwSize
;
353 lpddi
->guidInstance
= joydevs
[id
].guid
;
354 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
355 lpddi
->guidFFDriver
= GUID_NULL
;
357 if (version
>= 0x0800)
358 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
360 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
362 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
363 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszProductName
, MAX_PATH
);
366 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
370 if (id
>= have_joydevs
) {
374 if (!((dwDevType
== 0) ||
375 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
376 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
379 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
380 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
384 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
385 fill_joystick_dideviceinstanceA(lpddi
, version
, id
);
391 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
395 if (id
>= have_joydevs
) {
399 if (!((dwDevType
== 0) ||
400 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
401 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
404 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
405 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
409 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
410 fill_joystick_dideviceinstanceW(lpddi
, version
, id
);
416 static JoystickImpl
*alloc_device(REFGUID rguid
, IDirectInputImpl
*dinput
, unsigned short index
)
418 JoystickImpl
* newDevice
;
419 LPDIDATAFORMAT df
= NULL
;
421 int default_axis_map
[WINE_JOYSTICK_MAX_AXES
+ WINE_JOYSTICK_MAX_POVS
*2];
423 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
424 if (!newDevice
) return NULL
;
426 newDevice
->generic
.base
.IDirectInputDevice8A_iface
.lpVtbl
= &JoystickAvt
;
427 newDevice
->generic
.base
.IDirectInputDevice8W_iface
.lpVtbl
= &JoystickWvt
;
428 newDevice
->generic
.base
.ref
= 1;
429 newDevice
->generic
.base
.guid
= *rguid
;
430 newDevice
->generic
.base
.dinput
= dinput
;
431 newDevice
->generic
.joy_polldev
= joy_polldev
;
432 newDevice
->joyfd
= -1;
433 newDevice
->joydev
= &joydevs
[index
];
434 newDevice
->generic
.name
= newDevice
->joydev
->name
;
435 list_init(&newDevice
->ff_effects
);
436 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
437 newDevice
->ff_state
= FF_STATUS_STOPPED
;
439 /* There is no way in linux to query force feedback autocenter status.
440 Instead, track it with ff_autocenter, and assume it's initially
442 newDevice
->ff_autocenter
= 1;
443 newDevice
->ff_gain
= 0xFFFF;
444 InitializeCriticalSection(&newDevice
->generic
.base
.crit
);
445 newDevice
->generic
.base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
447 /* Count number of available axes - supported Axis & POVs */
448 for (i
= 0; i
< WINE_JOYSTICK_MAX_AXES
; i
++)
450 if (test_bit(newDevice
->joydev
->absbits
, i
))
452 newDevice
->generic
.device_axis_count
++;
453 newDevice
->dev_axes_to_di
[i
] = idx
;
454 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[i
].minimum
;
455 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[i
].maximum
;
456 default_axis_map
[idx
] = i
;
460 newDevice
->dev_axes_to_di
[i
] = -1;
463 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
465 if (test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) &&
466 test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2))
468 newDevice
->generic
.device_axis_count
+= 2;
469 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].minimum
;
470 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].maximum
;
471 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = idx
;
472 newDevice
->generic
.props
[idx
+1].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].minimum
;
473 newDevice
->generic
.props
[idx
+1].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].maximum
;
474 newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = idx
+ 1;
476 default_axis_map
[idx
] = default_axis_map
[idx
+ 1] = WINE_JOYSTICK_MAX_AXES
+ i
;
480 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = -1;
483 /* do any user specified configuration */
484 if (setup_dinput_options(&newDevice
->generic
, default_axis_map
) != DI_OK
) goto failed
;
486 /* Create copy of default data format */
487 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
488 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
489 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
492 /* Construct internal data format */
494 /* Supported Axis & POVs */
495 for (i
= 0, idx
= 0; i
< newDevice
->generic
.device_axis_count
; i
++)
497 int wine_obj
= newDevice
->generic
.axis_map
[i
];
499 if (wine_obj
< 0) continue;
501 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[wine_obj
], df
->dwObjSize
);
503 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
) | DIDFT_ABSAXIS
;
506 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
- 8) | DIDFT_POV
;
507 i
++; /* POV takes 2 axes */
510 newDevice
->generic
.props
[idx
].lMin
= 0;
511 newDevice
->generic
.props
[idx
].lMax
= 0xffff;
512 newDevice
->generic
.props
[idx
].lSaturation
= 0;
513 newDevice
->generic
.props
[idx
].lDeadZone
= newDevice
->generic
.deadzone
;
515 /* Linux supports force-feedback on X & Y axes only */
516 if (newDevice
->joydev
->has_ff
&& (i
== 0 || i
== 1))
517 df
->rgodf
[idx
].dwFlags
|= DIDOI_FFACTUATOR
;
522 /* Buttons can be anywhere, so check all */
523 for (i
= 0; i
< KEY_MAX
&& newDevice
->generic
.devcaps
.dwButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
525 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
527 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->generic
.devcaps
.dwButtons
+ 12], df
->dwObjSize
);
528 newDevice
->buttons
[i
] = 0x80 | newDevice
->generic
.devcaps
.dwButtons
;
529 df
->rgodf
[idx
].pguid
= &GUID_Button
;
530 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->generic
.devcaps
.dwButtons
++) | DIDFT_PSHBUTTON
;
533 newDevice
->generic
.base
.data_format
.wine_df
= df
;
535 fake_current_js_state(newDevice
);
538 newDevice
->generic
.devcaps
.dwSize
= sizeof(newDevice
->generic
.devcaps
);
539 newDevice
->generic
.devcaps
.dwFlags
= DIDC_ATTACHED
;
540 if (newDevice
->generic
.base
.dinput
->dwVersion
>= 0x0800)
541 newDevice
->generic
.devcaps
.dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
543 newDevice
->generic
.devcaps
.dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
545 if (newDevice
->joydev
->has_ff
)
546 newDevice
->generic
.devcaps
.dwFlags
|= DIDC_FORCEFEEDBACK
;
548 IDirectInput_AddRef(&newDevice
->generic
.base
.dinput
->IDirectInput7A_iface
);
550 EnterCriticalSection(&dinput
->crit
);
551 list_add_tail(&dinput
->devices_list
, &newDevice
->generic
.base
.entry
);
552 LeaveCriticalSection(&dinput
->crit
);
557 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
558 HeapFree(GetProcessHeap(), 0, df
);
559 HeapFree(GetProcessHeap(), 0, newDevice
->generic
.axis_map
);
560 HeapFree(GetProcessHeap(), 0, newDevice
);
564 /******************************************************************************
565 * get_joystick_index : Get the joystick index from a given GUID
567 static unsigned short get_joystick_index(REFGUID guid
)
569 GUID wine_joystick
= DInput_Wine_Joystick_Base_GUID
;
570 GUID dev_guid
= *guid
;
572 wine_joystick
.Data3
= 0;
575 /* for the standard joystick GUID use index 0 */
576 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
578 /* for the wine joystick GUIDs use the index stored in Data3 */
579 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
- DInput_Wine_Joystick_Base_GUID
.Data3
;
584 static HRESULT
joydev_create_device(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPVOID
*pdev
, int unicode
)
586 unsigned short index
;
588 TRACE("%p %s %s %p %i\n", dinput
, debugstr_guid(rguid
), debugstr_guid(riid
), pdev
, unicode
);
592 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
593 have_joydevs
&& index
< have_joydevs
)
599 else if (IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
600 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
601 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
602 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
606 else if (IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
607 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
608 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
609 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
615 WARN("no interface\n");
616 return DIERR_NOINTERFACE
;
619 This
= alloc_device(rguid
, dinput
, index
);
620 TRACE("Created a Joystick device (%p)\n", This
);
622 if (!This
) return DIERR_OUTOFMEMORY
;
625 *pdev
= &This
->generic
.base
.IDirectInputDevice8W_iface
;
627 *pdev
= &This
->generic
.base
.IDirectInputDevice8A_iface
;
632 return DIERR_DEVICENOTREG
;
636 const struct dinput_device joystick_linuxinput_device
= {
637 "Wine Linux-input joystick driver",
643 /******************************************************************************
644 * Acquire : gets exclusive control of the joystick
646 static HRESULT WINAPI
JoystickWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface
)
648 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
651 TRACE("(this=%p)\n",This
);
653 if ((res
= IDirectInputDevice2WImpl_Acquire(iface
)) != DI_OK
)
655 WARN("Failed to acquire: %x\n", res
);
659 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDWR
)) == -1)
661 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDONLY
)) == -1)
663 /* Couldn't open the device at all */
664 ERR("Failed to open device %s: %d %s\n", This
->joydev
->device
, errno
, strerror(errno
));
665 IDirectInputDevice2WImpl_Unacquire(iface
);
666 return DIERR_NOTFOUND
;
670 /* Couldn't open in r/w but opened in read-only. */
671 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
676 struct input_event event
;
679 event
.code
= FF_GAIN
;
680 event
.value
= This
->ff_gain
;
681 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
682 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
683 if (!This
->ff_autocenter
)
685 /* Disable autocenter. */
686 event
.code
= FF_AUTOCENTER
;
688 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
689 ERR("Failed disabling autocenter: %d %s\n", errno
, strerror(errno
));
696 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
698 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
699 return JoystickWImpl_Acquire(IDirectInputDevice8W_from_impl(This
));
702 /******************************************************************************
703 * Unacquire : frees the joystick
705 static HRESULT WINAPI
JoystickWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface
)
707 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
710 TRACE("(this=%p)\n",This
);
711 res
= IDirectInputDevice2WImpl_Unacquire(iface
);
712 if (res
==DI_OK
&& This
->joyfd
!=-1) {
713 effect_list_item
*itr
;
714 struct input_event event
;
716 /* For each known effect:
719 * But, unlike DISFFC_RESET, do not release the effect.
721 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
) {
722 IDirectInputEffect_Stop(itr
->ref
);
723 IDirectInputEffect_Unload(itr
->ref
);
726 /* Enable autocenter. */
728 event
.code
= FF_AUTOCENTER
;
729 /* TODO: Read autocenter strength before disabling it, and use it here
730 * instead of 0xFFFF (maximum strength).
732 event
.value
= 0xFFFF;
733 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
734 ERR("Failed to set autocenter to %04x: %d %s\n", event
.value
, errno
, strerror(errno
));
742 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
744 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
745 return JoystickWImpl_Unacquire(IDirectInputDevice8W_from_impl(This
));
749 * set the current state of the js device as it would be with the middle
752 #define CENTER_AXIS(a) \
753 (ji->dev_axes_to_di[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->dev_axes_to_di[a]], \
754 ji->joydev->axes[a].value ))
755 static void fake_current_js_state(JoystickImpl
*ji
)
759 /* center the axes */
760 ji
->generic
.js
.lX
= CENTER_AXIS(ABS_X
);
761 ji
->generic
.js
.lY
= CENTER_AXIS(ABS_Y
);
762 ji
->generic
.js
.lZ
= CENTER_AXIS(ABS_Z
);
763 ji
->generic
.js
.lRx
= CENTER_AXIS(ABS_RX
);
764 ji
->generic
.js
.lRy
= CENTER_AXIS(ABS_RY
);
765 ji
->generic
.js
.lRz
= CENTER_AXIS(ABS_RZ
);
766 ji
->generic
.js
.rglSlider
[0] = CENTER_AXIS(ABS_THROTTLE
);
767 ji
->generic
.js
.rglSlider
[1] = CENTER_AXIS(ABS_RUDDER
);
769 /* POV center is -1 */
770 for (i
= 0; i
< 4; i
++)
771 ji
->generic
.js
.rgdwPOV
[i
] = -1;
775 /* convert wine format offset to user format object index */
776 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
)
779 struct input_event ie
;
780 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
790 plfd
.fd
= This
->joyfd
;
791 plfd
.events
= POLLIN
;
793 if (poll(&plfd
,1,0) != 1)
796 /* we have one event, so we can read */
797 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
800 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
802 case EV_KEY
: /* button */
804 int btn
= This
->buttons
[ie
.code
];
806 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
810 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
811 This
->generic
.js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
817 int axis
= This
->dev_axes_to_di
[ie
.code
];
819 /* User axis remapping */
821 axis
= This
->generic
.axis_map
[axis
];
824 inst_id
= axis
< 8 ? DIDFT_MAKEINSTANCE(axis
) | DIDFT_ABSAXIS
:
825 DIDFT_MAKEINSTANCE(axis
- 8) | DIDFT_POV
;
826 value
= joystick_map_axis(&This
->generic
.props
[id_to_object(This
->generic
.base
.data_format
.wine_df
, inst_id
)], ie
.value
);
829 case 0: This
->generic
.js
.lX
= value
; break;
830 case 1: This
->generic
.js
.lY
= value
; break;
831 case 2: This
->generic
.js
.lZ
= value
; break;
832 case 3: This
->generic
.js
.lRx
= value
; break;
833 case 4: This
->generic
.js
.lRy
= value
; break;
834 case 5: This
->generic
.js
.lRz
= value
; break;
835 case 6: This
->generic
.js
.rglSlider
[0] = value
; break;
836 case 7: This
->generic
.js
.rglSlider
[1] = value
; break;
837 case 8: case 9: case 10: case 11:
842 This
->povs
[idx
].y
= ie
.value
;
844 This
->povs
[idx
].x
= ie
.value
;
846 This
->generic
.js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
850 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
854 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
856 This
->ff_state
= ie
.value
;
861 /* there is nothing to do */
870 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
874 queue_event(iface
, inst_id
,
875 value
, ie
.time
.tv_usec
, This
->generic
.base
.dinput
->evsequence
++);
879 /******************************************************************************
880 * SetProperty : change input device properties
882 static HRESULT WINAPI
JoystickWImpl_SetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPCDIPROPHEADER ph
)
884 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
887 WARN("invalid argument\n");
888 return DIERR_INVALIDPARAM
;
891 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
892 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
893 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
895 if (IS_DIPROP(rguid
)) {
896 switch (LOWORD(rguid
)) {
897 case (DWORD_PTR
)DIPROP_CALIBRATIONMODE
: {
898 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
899 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd
->dwData
);
902 case (DWORD_PTR
)DIPROP_AUTOCENTER
: {
903 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
905 TRACE("autocenter(%d)\n", pd
->dwData
);
906 This
->ff_autocenter
= pd
->dwData
== DIPROPAUTOCENTER_ON
;
910 case (DWORD_PTR
)DIPROP_FFGAIN
: {
911 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
913 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
914 This
->ff_gain
= MulDiv(pd
->dwData
, 0xFFFF, 10000);
915 if (This
->generic
.base
.acquired
) {
916 /* Update immediately. */
917 struct input_event event
;
920 event
.code
= FF_GAIN
;
921 event
.value
= This
->ff_gain
;
922 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
923 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
928 return JoystickWGenericImpl_SetProperty(iface
, rguid
, ph
);
934 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPCDIPROPHEADER ph
)
936 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
937 return JoystickWImpl_SetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, ph
);
940 /******************************************************************************
941 * GetProperty : get input device properties
943 static HRESULT WINAPI
JoystickWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
945 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
947 TRACE("(this=%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
948 _dump_DIPROPHEADER(pdiph
);
950 if (!IS_DIPROP(rguid
)) return DI_OK
;
952 switch (LOWORD(rguid
)) {
953 case (DWORD_PTR
) DIPROP_AUTOCENTER
:
955 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
957 pd
->dwData
= This
->ff_autocenter
? DIPROPAUTOCENTER_ON
: DIPROPAUTOCENTER_OFF
;
958 TRACE("autocenter(%d)\n", pd
->dwData
);
961 case (DWORD_PTR
) DIPROP_FFGAIN
:
963 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
965 pd
->dwData
= MulDiv(This
->ff_gain
, 10000, 0xFFFF);
966 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
970 case (DWORD_PTR
) DIPROP_VIDPID
:
972 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
974 if (!This
->joydev
->product_id
|| !This
->joydev
->vendor_id
)
975 return DIERR_UNSUPPORTED
;
976 pd
->dwData
= MAKELONG(This
->joydev
->vendor_id
, This
->joydev
->product_id
);
977 TRACE("DIPROP_VIDPID(%08x)\n", pd
->dwData
);
981 case (DWORD_PTR
) DIPROP_JOYSTICKID
:
983 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
985 pd
->dwData
= get_joystick_index(&This
->generic
.base
.guid
);
986 TRACE("DIPROP_JOYSTICKID(%d)\n", pd
->dwData
);
991 return JoystickWGenericImpl_GetProperty(iface
, rguid
, pdiph
);
997 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
999 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1000 return JoystickWImpl_GetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, pdiph
);
1003 /******************************************************************************
1004 * CreateEffect - Create a new FF effect with the specified params
1006 static HRESULT WINAPI
JoystickWImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
,
1007 LPCDIEFFECT lpeff
, LPDIRECTINPUTEFFECT
*ppdef
,
1008 LPUNKNOWN pUnkOuter
)
1010 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1011 effect_list_item
* new_effect
= NULL
;
1012 HRESULT retval
= DI_OK
;
1015 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1016 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
1018 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1019 TRACE("not available (compiled w/o ff support)\n");
1024 if (!(new_effect
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect
))))
1025 return DIERR_OUTOFMEMORY
;
1027 retval
= linuxinput_create_effect(&This
->joyfd
, rguid
, &new_effect
->entry
, &new_effect
->ref
);
1028 if (retval
!= DI_OK
)
1030 HeapFree(GetProcessHeap(), 0, new_effect
);
1036 retval
= IDirectInputEffect_SetParameters(new_effect
->ref
, lpeff
, 0);
1038 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1040 HeapFree(GetProcessHeap(), 0, new_effect
);
1045 list_add_tail(&This
->ff_effects
, &new_effect
->entry
);
1046 *ppdef
= new_effect
->ref
;
1048 if (pUnkOuter
!= NULL
)
1049 FIXME("Interface aggregation not implemented.\n");
1053 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1056 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
,
1057 LPCDIEFFECT lpeff
, LPDIRECTINPUTEFFECT
*ppdef
,
1058 LPUNKNOWN pUnkOuter
)
1060 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1061 return JoystickWImpl_CreateEffect(IDirectInputDevice8W_from_impl(This
), rguid
, lpeff
, ppdef
, pUnkOuter
);
1064 /*******************************************************************************
1065 * EnumEffects - Enumerate available FF effects
1067 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1068 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1072 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1073 DIEFFECTINFOA dei
; /* feif */
1074 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1075 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1077 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
1079 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1081 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1082 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1083 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1084 (*lpCallback
)(&dei
, pvRef
);
1087 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1088 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1089 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1090 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1091 (*lpCallback
)(&dei
, pvRef
);
1093 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1094 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1095 (*lpCallback
)(&dei
, pvRef
);
1097 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1098 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1099 (*lpCallback
)(&dei
, pvRef
);
1101 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1102 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1103 (*lpCallback
)(&dei
, pvRef
);
1105 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1106 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1107 (*lpCallback
)(&dei
, pvRef
);
1111 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1112 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1113 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1114 (*lpCallback
)(&dei
, pvRef
);
1117 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1118 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1119 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1120 (*lpCallback
)(&dei
, pvRef
);
1122 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1123 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1124 (*lpCallback
)(&dei
, pvRef
);
1126 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1127 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1128 (*lpCallback
)(&dei
, pvRef
);
1130 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1131 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1132 (*lpCallback
)(&dei
, pvRef
);
1141 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1142 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1146 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1147 /* seems silly to duplicate all this code but all the structures and functions
1148 * are actually different (A/W) */
1149 DIEFFECTINFOW dei
; /* feif */
1150 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1151 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1152 int xfd
= This
->joyfd
;
1154 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1156 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1158 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1159 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1160 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1161 (*lpCallback
)(&dei
, pvRef
);
1164 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1165 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1166 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1167 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1168 (*lpCallback
)(&dei
, pvRef
);
1170 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1171 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1172 (*lpCallback
)(&dei
, pvRef
);
1174 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1175 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1176 (*lpCallback
)(&dei
, pvRef
);
1178 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1179 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1180 (*lpCallback
)(&dei
, pvRef
);
1182 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1183 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1184 (*lpCallback
)(&dei
, pvRef
);
1188 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1189 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1190 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1191 (*lpCallback
)(&dei
, pvRef
);
1194 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1195 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1196 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1197 (*lpCallback
)(&dei
, pvRef
);
1199 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1200 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1201 (*lpCallback
)(&dei
, pvRef
);
1203 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1204 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1205 (*lpCallback
)(&dei
, pvRef
);
1207 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1208 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1209 (*lpCallback
)(&dei
, pvRef
);
1213 /* return to unacquired state if that's where it was */
1215 IDirectInputDevice8_Unacquire(iface
);
1221 /*******************************************************************************
1222 * GetEffectInfo - Get information about a particular effect
1224 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1225 LPDIEFFECTINFOA pdei
,
1228 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1230 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1232 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1233 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1239 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1240 LPDIEFFECTINFOW pdei
,
1243 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1245 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1247 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1248 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1254 /*******************************************************************************
1255 * GetForceFeedbackState - Get information about the device's FF state
1257 static HRESULT WINAPI
JoystickWImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface
, LPDWORD pdwOut
)
1259 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1261 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1265 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1266 /* DIGFFS_STOPPED is the only mandatory flag to report */
1267 if (This
->ff_state
== FF_STATUS_STOPPED
)
1268 (*pdwOut
) |= DIGFFS_STOPPED
;
1274 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8A iface
, LPDWORD pdwOut
)
1276 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1277 return JoystickWImpl_GetForceFeedbackState(IDirectInputDevice8W_from_impl(This
), pdwOut
);
1280 /*******************************************************************************
1281 * SendForceFeedbackCommand - Send a command to the device's FF system
1283 static HRESULT WINAPI
JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface
, DWORD dwFlags
)
1285 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1286 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1288 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1291 case DISFFC_STOPALL
:
1293 /* Stop all effects */
1294 effect_list_item
*itr
;
1296 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1297 IDirectInputEffect_Stop(itr
->ref
);
1303 effect_list_item
*itr
, *ptr
;
1305 /* Stop, unload, release and free all effects */
1306 /* This returns the device to its "bare" state */
1307 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1308 IDirectInputEffect_Release(itr
->ref
);
1312 case DISFFC_CONTINUE
:
1313 FIXME("No support for Pause or Continue in linux\n");
1316 case DISFFC_SETACTUATORSOFF
:
1317 case DISFFC_SETACTUATORSON
:
1318 FIXME("No direct actuator control in linux\n");
1322 FIXME("Unknown Force Feedback Command!\n");
1323 return DIERR_INVALIDPARAM
;
1327 return DIERR_UNSUPPORTED
;
1331 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8A iface
, DWORD dwFlags
)
1333 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1334 return JoystickWImpl_SendForceFeedbackCommand(IDirectInputDevice8W_from_impl(This
), dwFlags
);
1337 /*******************************************************************************
1338 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1339 * created for this device.
1341 static HRESULT WINAPI
JoystickWImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface
,
1342 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1343 LPVOID pvRef
, DWORD dwFlags
)
1345 /* this function is safe to call on non-ff-enabled builds */
1346 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1347 effect_list_item
*itr
, *ptr
;
1349 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1352 return DIERR_INVALIDPARAM
;
1355 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1357 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1358 (*lpCallback
)(itr
->ref
, pvRef
);
1363 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8A iface
,
1364 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1365 LPVOID pvRef
, DWORD dwFlags
)
1367 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1368 return JoystickWImpl_EnumCreatedEffectObjects(IDirectInputDevice8W_from_impl(This
), lpCallback
, pvRef
, dwFlags
);
1371 /******************************************************************************
1372 * GetDeviceInfo : get information about a device's identity
1374 static HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface
,
1375 LPDIDEVICEINSTANCEA pdidi
)
1377 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1379 TRACE("(%p) %p\n", This
, pdidi
);
1381 if (pdidi
== NULL
) return E_POINTER
;
1382 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1383 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)))
1384 return DIERR_INVALIDPARAM
;
1386 fill_joystick_dideviceinstanceA(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1387 get_joystick_index(&This
->generic
.base
.guid
));
1391 static HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
,
1392 LPDIDEVICEINSTANCEW pdidi
)
1394 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
1396 TRACE("(%p) %p\n", This
, pdidi
);
1398 if (pdidi
== NULL
) return E_POINTER
;
1399 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1400 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)))
1401 return DIERR_INVALIDPARAM
;
1403 fill_joystick_dideviceinstanceW(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1404 get_joystick_index(&This
->generic
.base
.guid
));
1408 static const IDirectInputDevice8AVtbl JoystickAvt
=
1410 IDirectInputDevice2AImpl_QueryInterface
,
1411 IDirectInputDevice2AImpl_AddRef
,
1412 IDirectInputDevice2AImpl_Release
,
1413 JoystickAGenericImpl_GetCapabilities
,
1414 IDirectInputDevice2AImpl_EnumObjects
,
1415 JoystickAImpl_GetProperty
,
1416 JoystickAImpl_SetProperty
,
1417 JoystickAImpl_Acquire
,
1418 JoystickAImpl_Unacquire
,
1419 JoystickAGenericImpl_GetDeviceState
,
1420 IDirectInputDevice2AImpl_GetDeviceData
,
1421 IDirectInputDevice2AImpl_SetDataFormat
,
1422 IDirectInputDevice2AImpl_SetEventNotification
,
1423 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1424 JoystickAGenericImpl_GetObjectInfo
,
1425 JoystickAImpl_GetDeviceInfo
,
1426 IDirectInputDevice2AImpl_RunControlPanel
,
1427 IDirectInputDevice2AImpl_Initialize
,
1428 JoystickAImpl_CreateEffect
,
1429 JoystickAImpl_EnumEffects
,
1430 JoystickAImpl_GetEffectInfo
,
1431 JoystickAImpl_GetForceFeedbackState
,
1432 JoystickAImpl_SendForceFeedbackCommand
,
1433 JoystickAImpl_EnumCreatedEffectObjects
,
1434 IDirectInputDevice2AImpl_Escape
,
1435 JoystickAGenericImpl_Poll
,
1436 IDirectInputDevice2AImpl_SendDeviceData
,
1437 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1438 IDirectInputDevice7AImpl_WriteEffectToFile
,
1439 JoystickAGenericImpl_BuildActionMap
,
1440 JoystickAGenericImpl_SetActionMap
,
1441 IDirectInputDevice8AImpl_GetImageInfo
1444 static const IDirectInputDevice8WVtbl JoystickWvt
=
1446 IDirectInputDevice2WImpl_QueryInterface
,
1447 IDirectInputDevice2WImpl_AddRef
,
1448 IDirectInputDevice2WImpl_Release
,
1449 JoystickWGenericImpl_GetCapabilities
,
1450 IDirectInputDevice2WImpl_EnumObjects
,
1451 JoystickWImpl_GetProperty
,
1452 JoystickWImpl_SetProperty
,
1453 JoystickWImpl_Acquire
,
1454 JoystickWImpl_Unacquire
,
1455 JoystickWGenericImpl_GetDeviceState
,
1456 IDirectInputDevice2WImpl_GetDeviceData
,
1457 IDirectInputDevice2WImpl_SetDataFormat
,
1458 IDirectInputDevice2WImpl_SetEventNotification
,
1459 IDirectInputDevice2WImpl_SetCooperativeLevel
,
1460 JoystickWGenericImpl_GetObjectInfo
,
1461 JoystickWImpl_GetDeviceInfo
,
1462 IDirectInputDevice2WImpl_RunControlPanel
,
1463 IDirectInputDevice2WImpl_Initialize
,
1464 JoystickWImpl_CreateEffect
,
1465 JoystickWImpl_EnumEffects
,
1466 JoystickWImpl_GetEffectInfo
,
1467 JoystickWImpl_GetForceFeedbackState
,
1468 JoystickWImpl_SendForceFeedbackCommand
,
1469 JoystickWImpl_EnumCreatedEffectObjects
,
1470 IDirectInputDevice2WImpl_Escape
,
1471 JoystickWGenericImpl_Poll
,
1472 IDirectInputDevice2WImpl_SendDeviceData
,
1473 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1474 IDirectInputDevice7WImpl_WriteEffectToFile
,
1475 JoystickWGenericImpl_BuildActionMap
,
1476 JoystickWGenericImpl_SetActionMap
,
1477 IDirectInputDevice8WImpl_GetImageInfo
1480 #else /* HAVE_CORRECT_LINUXINPUT_H */
1482 const struct dinput_device joystick_linuxinput_device
= {
1483 "Wine Linux-input joystick driver",
1489 #endif /* HAVE_CORRECT_LINUXINPUT_H */