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"
63 #include "dinput_private.h"
64 #include "device_private.h"
65 #include "joystick_private.h"
67 #ifdef HAS_PROPER_HEADER
69 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
71 #define EVDEVPREFIX "/dev/input/event"
72 #define EVDEVDRIVER " (event)"
74 /* Wine joystick driver object instances */
75 #define WINE_JOYSTICK_MAX_AXES 8
76 #define WINE_JOYSTICK_MAX_POVS 4
77 #define WINE_JOYSTICK_MAX_BUTTONS 128
79 struct wine_input_absinfo
{
87 /* implemented in effect_linuxinput.c */
88 HRESULT
linuxinput_create_effect(int* fd
, REFGUID rguid
, struct list
*parent_list_entry
, LPDIRECTINPUTEFFECT
* peff
);
89 HRESULT
linuxinput_get_info_A(int fd
, REFGUID rguid
, LPDIEFFECTINFOA info
);
90 HRESULT
linuxinput_get_info_W(int fd
, REFGUID rguid
, LPDIEFFECTINFOW info
);
92 static HRESULT WINAPI
JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface
, DWORD dwFlags
);
94 typedef struct JoystickImpl JoystickImpl
;
95 static const IDirectInputDevice8AVtbl JoystickAvt
;
96 static const IDirectInputDevice8WVtbl JoystickWvt
;
104 BOOL has_ff
, is_joystick
;
107 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
108 BYTE evbits
[(EV_MAX
+7)/8];
109 BYTE absbits
[(ABS_MAX
+7)/8];
110 BYTE keybits
[(KEY_MAX
+7)/8];
111 BYTE ffbits
[(FF_MAX
+7)/8];
113 /* data returned by the EVIOCGABS() ioctl */
114 struct wine_input_absinfo axes
[ABS_MAX
];
116 WORD vendor_id
, product_id
, bus_type
;
121 struct JoystickGenericImpl generic
;
122 struct JoyDev
*joydev
;
124 /* joystick private */
127 int dev_axes_to_di
[ABS_MAX
];
130 /* LUT for KEY_ to offset in rgbButtons */
131 BYTE buttons
[KEY_MAX
];
133 /* Force feedback variables */
134 struct list ff_effects
;
140 static inline JoystickImpl
*impl_from_IDirectInputDevice8A(IDirectInputDevice8A
*iface
)
142 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8A_iface
),
143 JoystickGenericImpl
, base
), JoystickImpl
, generic
);
145 static inline JoystickImpl
*impl_from_IDirectInputDevice8W(IDirectInputDevice8W
*iface
)
147 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8W_iface
),
148 JoystickGenericImpl
, base
), JoystickImpl
, generic
);
151 static inline IDirectInputDevice8W
*IDirectInputDevice8W_from_impl(JoystickImpl
*This
)
153 return &This
->generic
.base
.IDirectInputDevice8W_iface
;
156 static void fake_current_js_state(JoystickImpl
*ji
);
157 static void find_joydevs(void);
158 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
);
160 /* This GUID is slightly different from the linux joystick one. Take note. */
161 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
165 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
168 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
170 #define MAX_JOYDEV 64
172 static int have_joydevs
= -1;
173 static struct JoyDev
*joydevs
= NULL
;
175 static void find_joydevs(void)
179 if (InterlockedCompareExchange(&have_joydevs
, 0, -1) != -1)
180 /* Someone beat us to it */
183 for (i
= 0; i
< MAX_JOYDEV
; i
++)
186 struct JoyDev joydev
= {0};
188 BOOL no_ff_check
= FALSE
;
190 struct JoyDev
*new_joydevs
;
191 struct input_id device_id
= {0};
193 snprintf(buf
, sizeof(buf
), EVDEVPREFIX
"%d", i
);
195 if ((fd
= open(buf
, O_RDWR
)) == -1)
197 fd
= open(buf
, O_RDONLY
);
204 if (ioctl(fd
, EVIOCGBIT(0, sizeof(joydev
.evbits
)), joydev
.evbits
) == -1)
206 WARN("ioctl(EVIOCGBIT, 0) failed: %d %s\n", errno
, strerror(errno
));
210 if (ioctl(fd
, EVIOCGBIT(EV_ABS
, sizeof(joydev
.absbits
)), joydev
.absbits
) == -1)
212 WARN("ioctl(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
216 if (ioctl(fd
, EVIOCGBIT(EV_KEY
, sizeof(joydev
.keybits
)), joydev
.keybits
) == -1)
218 WARN("ioctl(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno
, strerror(errno
));
223 /* A true joystick has at least axis X and Y, and at least 1
224 * button. copied from linux/drivers/input/joydev.c */
225 if (((!test_bit(joydev
.absbits
, ABS_X
) || !test_bit(joydev
.absbits
, ABS_Y
)) &&
226 !test_bit(joydev
.absbits
, ABS_WHEEL
) &&
227 !test_bit(joydev
.absbits
, ABS_GAS
) &&
228 !test_bit(joydev
.absbits
, ABS_BRAKE
)) ||
229 !(test_bit(joydev
.keybits
, BTN_TRIGGER
) ||
230 test_bit(joydev
.keybits
, BTN_A
) ||
231 test_bit(joydev
.keybits
, BTN_1
) ||
232 test_bit(joydev
.keybits
, BTN_BASE
) ||
233 test_bit(joydev
.keybits
, BTN_GEAR_UP
) ||
234 test_bit(joydev
.keybits
, BTN_GEAR_DOWN
)))
240 /* in lieu of properly reporting HID usage, detect presence of
241 * "joystick buttons" and report those devices as joysticks instead of
244 test_bit(joydev
.keybits
, BTN_TRIGGER
) ||
245 test_bit(joydev
.keybits
, BTN_THUMB
) ||
246 test_bit(joydev
.keybits
, BTN_THUMB2
) ||
247 test_bit(joydev
.keybits
, BTN_TOP
) ||
248 test_bit(joydev
.keybits
, BTN_TOP2
) ||
249 test_bit(joydev
.keybits
, BTN_PINKIE
) ||
250 test_bit(joydev
.keybits
, BTN_BASE
) ||
251 test_bit(joydev
.keybits
, BTN_BASE2
) ||
252 test_bit(joydev
.keybits
, BTN_BASE3
) ||
253 test_bit(joydev
.keybits
, BTN_BASE4
) ||
254 test_bit(joydev
.keybits
, BTN_BASE5
) ||
255 test_bit(joydev
.keybits
, BTN_BASE6
) ||
256 test_bit(joydev
.keybits
, BTN_GEAR_UP
) ||
257 test_bit(joydev
.keybits
, BTN_GEAR_DOWN
) ||
258 test_bit(joydev
.keybits
, BTN_DEAD
);
260 if (!(joydev
.device
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
265 strcpy(joydev
.device
, buf
);
267 buf
[MAX_PATH
- 1] = 0;
268 if (ioctl(fd
, EVIOCGNAME(MAX_PATH
- 1), buf
) != -1 &&
269 (joydev
.name
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + strlen(EVDEVDRIVER
) + 1)))
271 strcpy(joydev
.name
, buf
);
272 /* Append driver name */
273 strcat(joydev
.name
, EVDEVDRIVER
);
276 joydev
.name
= joydev
.device
;
278 if (device_disabled_registry(joydev
.name
)) {
280 HeapFree(GetProcessHeap(), 0, joydev
.name
);
281 if (joydev
.name
!= joydev
.device
)
282 HeapFree(GetProcessHeap(), 0, joydev
.device
);
286 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
287 joydev
.guid
.Data3
+= have_joydevs
;
289 TRACE("Found a joystick on %s: %s (%s)\n",
290 joydev
.device
, joydev
.name
,
291 debugstr_guid(&joydev
.guid
)
294 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
296 test_bit(joydev
.evbits
, EV_FF
) &&
297 ioctl(fd
, EVIOCGBIT(EV_FF
, sizeof(joydev
.ffbits
)), joydev
.ffbits
) != -1 &&
298 ioctl(fd
, EVIOCGEFFECTS
, &joydev
.num_effects
) != -1 &&
299 joydev
.num_effects
> 0)
301 TRACE(" ... with force feedback\n");
302 joydev
.has_ff
= TRUE
;
306 for (j
= 0; j
< ABS_MAX
;j
++)
308 if (!test_bit(joydev
.absbits
, j
)) continue;
309 if (ioctl(fd
, EVIOCGABS(j
), &(joydev
.axes
[j
])) != -1)
311 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
313 joydev
.axes
[j
].value
,
314 joydev
.axes
[j
].minimum
,
315 joydev
.axes
[j
].maximum
,
322 if (ioctl(fd
, EVIOCGID
, &device_id
) == -1)
324 WARN("ioctl(EVIOCGID) failed: %d %s\n", errno
, strerror(errno
));
325 joydev
.guid_product
= DInput_Wine_Joystick_Base_GUID
;
329 joydev
.vendor_id
= device_id
.vendor
;
330 joydev
.product_id
= device_id
.product
;
331 joydev
.bus_type
= device_id
.bustype
;
333 /* Concatenate product_id with vendor_id to mimic Windows behaviour */
334 joydev
.guid_product
= DInput_PIDVID_Product_GUID
;
335 joydev
.guid_product
.Data1
= MAKELONG(joydev
.vendor_id
, joydev
.product_id
);
339 new_joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
341 new_joydevs
= HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1 + have_joydevs
) * sizeof(struct JoyDev
));
348 joydevs
= new_joydevs
;
349 joydevs
[have_joydevs
] = joydev
;
356 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
358 DWORD dwSize
= lpddi
->dwSize
;
360 TRACE("%d %p\n", dwSize
, lpddi
);
361 memset(lpddi
, 0, dwSize
);
363 lpddi
->dwSize
= dwSize
;
364 lpddi
->guidInstance
= joydevs
[id
].guid
;
365 lpddi
->guidProduct
= joydevs
[id
].guid_product
;
366 lpddi
->guidFFDriver
= GUID_NULL
;
367 lpddi
->dwDevType
= get_device_type(version
, joydevs
[id
].is_joystick
);
369 /* Assume the joystick as HID if it is attached to USB bus and has a valid VID/PID */
370 if (joydevs
[id
].bus_type
== BUS_USB
&&
371 joydevs
[id
].vendor_id
&& joydevs
[id
].product_id
)
373 lpddi
->dwDevType
|= DIDEVTYPE_HID
;
374 lpddi
->wUsagePage
= 0x01; /* Desktop */
375 if (joydevs
[id
].is_joystick
)
376 lpddi
->wUsage
= 0x04; /* Joystick */
378 lpddi
->wUsage
= 0x05; /* Game Pad */
381 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
382 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszProductName
, MAX_PATH
);
385 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
387 DIDEVICEINSTANCEW lpddiW
;
388 DWORD dwSize
= lpddi
->dwSize
;
390 lpddiW
.dwSize
= sizeof(lpddiW
);
391 fill_joystick_dideviceinstanceW(&lpddiW
, version
, id
);
393 TRACE("%d %p\n", dwSize
, lpddi
);
394 memset(lpddi
, 0, dwSize
);
397 lpddi
->dwSize
= dwSize
;
398 lpddi
->guidInstance
= lpddiW
.guidInstance
;
399 lpddi
->guidProduct
= lpddiW
.guidProduct
;
400 lpddi
->dwDevType
= lpddiW
.dwDevType
;
401 lstrcpynA(lpddi
->tszInstanceName
, joydevs
[id
].name
, MAX_PATH
);
402 lstrcpynA(lpddi
->tszProductName
, joydevs
[id
].name
, MAX_PATH
);
403 lpddi
->guidFFDriver
= lpddiW
.guidFFDriver
;
404 lpddi
->wUsagePage
= lpddiW
.wUsagePage
;
405 lpddi
->wUsage
= lpddiW
.wUsage
;
408 static HRESULT
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
412 if (id
>= have_joydevs
) {
416 if (!((dwDevType
== 0) ||
417 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
>= 0x0300 && version
< 0x0800)) ||
418 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
421 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
422 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
426 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
427 fill_joystick_dideviceinstanceA(lpddi
, version
, id
);
433 static HRESULT
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
437 if (id
>= have_joydevs
) {
441 if (!((dwDevType
== 0) ||
442 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
>= 0x0300 && version
< 0x0800)) ||
443 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
446 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
447 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
451 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
452 fill_joystick_dideviceinstanceW(lpddi
, version
, id
);
458 static JoystickImpl
*alloc_device(REFGUID rguid
, IDirectInputImpl
*dinput
, unsigned short index
)
460 JoystickImpl
* newDevice
;
461 LPDIDATAFORMAT df
= NULL
;
463 int default_axis_map
[WINE_JOYSTICK_MAX_AXES
+ WINE_JOYSTICK_MAX_POVS
*2];
464 DIDEVICEINSTANCEW ddi
;
466 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
467 if (!newDevice
) return NULL
;
469 newDevice
->generic
.base
.IDirectInputDevice8A_iface
.lpVtbl
= &JoystickAvt
;
470 newDevice
->generic
.base
.IDirectInputDevice8W_iface
.lpVtbl
= &JoystickWvt
;
471 newDevice
->generic
.base
.ref
= 1;
472 newDevice
->generic
.base
.guid
= *rguid
;
473 newDevice
->generic
.base
.dinput
= dinput
;
474 newDevice
->generic
.joy_polldev
= joy_polldev
;
475 newDevice
->joyfd
= -1;
476 newDevice
->joydev
= &joydevs
[index
];
477 newDevice
->generic
.name
= newDevice
->joydev
->name
;
478 list_init(&newDevice
->ff_effects
);
479 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
480 newDevice
->ff_state
= FF_STATUS_STOPPED
;
482 /* There is no way in linux to query force feedback autocenter status.
483 Instead, track it with ff_autocenter, and assume it's initially
485 newDevice
->ff_autocenter
= 1;
486 newDevice
->ff_gain
= 0xFFFF;
487 InitializeCriticalSection(&newDevice
->generic
.base
.crit
);
488 newDevice
->generic
.base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
490 /* Count number of available axes - supported Axis & POVs */
491 for (i
= 0; i
< ABS_MAX
; i
++)
493 if (idx
< WINE_JOYSTICK_MAX_AXES
&&
495 test_bit(newDevice
->joydev
->absbits
, i
))
497 newDevice
->generic
.device_axis_count
++;
498 newDevice
->dev_axes_to_di
[i
] = idx
;
499 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[i
].minimum
;
500 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[i
].maximum
;
501 if (i
>= 8 && i
<= 10) /* If it's a wheel axis... */
502 default_axis_map
[idx
] = i
- 8; /* ... remap to X/Y/Z */
504 default_axis_map
[idx
] = i
;
508 newDevice
->dev_axes_to_di
[i
] = -1;
511 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
513 if (test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) &&
514 test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2))
516 newDevice
->generic
.device_axis_count
+= 2;
517 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].minimum
;
518 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].maximum
;
519 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = idx
;
520 newDevice
->generic
.props
[idx
+1].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].minimum
;
521 newDevice
->generic
.props
[idx
+1].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].maximum
;
522 newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = idx
+ 1;
524 default_axis_map
[idx
] = default_axis_map
[idx
+ 1] = WINE_JOYSTICK_MAX_AXES
+ i
;
528 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = -1;
531 /* do any user specified configuration */
532 if (setup_dinput_options(&newDevice
->generic
, default_axis_map
) != DI_OK
) goto failed
;
534 /* Create copy of default data format */
535 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
536 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
537 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
540 /* Construct internal data format */
542 /* Supported Axis & POVs */
543 for (i
= 0, idx
= 0; i
< newDevice
->generic
.device_axis_count
; i
++)
545 int wine_obj
= newDevice
->generic
.axis_map
[i
];
547 if (wine_obj
< 0) continue;
549 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[wine_obj
], df
->dwObjSize
);
551 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
) | DIDFT_ABSAXIS
;
554 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
- 8) | DIDFT_POV
;
555 i
++; /* POV takes 2 axes */
558 newDevice
->generic
.props
[idx
].lMin
= 0;
559 newDevice
->generic
.props
[idx
].lMax
= 0xffff;
560 newDevice
->generic
.props
[idx
].lSaturation
= 0;
561 newDevice
->generic
.props
[idx
].lDeadZone
= newDevice
->generic
.deadzone
;
563 /* Linux supports force-feedback on X & Y axes only */
564 if (newDevice
->joydev
->has_ff
&& (i
== 0 || i
== 1))
565 df
->rgodf
[idx
].dwFlags
|= DIDOI_FFACTUATOR
;
570 /* Buttons can be anywhere, so check all */
571 for (i
= 0; i
< KEY_MAX
&& newDevice
->generic
.devcaps
.dwButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
573 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
575 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->generic
.devcaps
.dwButtons
+ 12], df
->dwObjSize
);
576 newDevice
->buttons
[i
] = 0x80 | newDevice
->generic
.devcaps
.dwButtons
;
577 df
->rgodf
[idx
].pguid
= &GUID_Button
;
578 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->generic
.devcaps
.dwButtons
++) | DIDFT_PSHBUTTON
;
581 newDevice
->generic
.base
.data_format
.wine_df
= df
;
583 fake_current_js_state(newDevice
);
586 newDevice
->generic
.devcaps
.dwSize
= sizeof(newDevice
->generic
.devcaps
);
587 newDevice
->generic
.devcaps
.dwFlags
= DIDC_ATTACHED
;
589 ddi
.dwSize
= sizeof(ddi
);
590 fill_joystick_dideviceinstanceW(&ddi
, newDevice
->generic
.base
.dinput
->dwVersion
, index
);
591 newDevice
->generic
.devcaps
.dwDevType
= ddi
.dwDevType
;
593 if (newDevice
->joydev
->has_ff
)
594 newDevice
->generic
.devcaps
.dwFlags
|= DIDC_FORCEFEEDBACK
;
596 IDirectInput_AddRef(&newDevice
->generic
.base
.dinput
->IDirectInput7A_iface
);
598 EnterCriticalSection(&dinput
->crit
);
599 list_add_tail(&dinput
->devices_list
, &newDevice
->generic
.base
.entry
);
600 LeaveCriticalSection(&dinput
->crit
);
605 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
606 HeapFree(GetProcessHeap(), 0, df
);
607 HeapFree(GetProcessHeap(), 0, newDevice
->generic
.axis_map
);
608 HeapFree(GetProcessHeap(), 0, newDevice
);
612 /******************************************************************************
613 * get_joystick_index : Get the joystick index from a given GUID
615 static unsigned short get_joystick_index(REFGUID guid
)
617 GUID wine_joystick
= DInput_Wine_Joystick_Base_GUID
;
618 GUID dev_guid
= *guid
;
620 wine_joystick
.Data3
= 0;
623 /* for the standard joystick GUID use index 0 */
624 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
626 /* for the wine joystick GUIDs use the index stored in Data3 */
627 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
- DInput_Wine_Joystick_Base_GUID
.Data3
;
632 static HRESULT
joydev_create_device(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPVOID
*pdev
, int unicode
)
634 unsigned short index
;
636 TRACE("%p %s %s %p %i\n", dinput
, debugstr_guid(rguid
), debugstr_guid(riid
), pdev
, unicode
);
640 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
641 have_joydevs
&& index
< have_joydevs
)
647 else if (IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
648 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
649 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
650 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
654 else if (IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
655 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
656 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
657 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
663 WARN("no interface\n");
664 return DIERR_NOINTERFACE
;
667 This
= alloc_device(rguid
, dinput
, index
);
668 TRACE("Created a Joystick device (%p)\n", This
);
670 if (!This
) return DIERR_OUTOFMEMORY
;
673 *pdev
= &This
->generic
.base
.IDirectInputDevice8W_iface
;
675 *pdev
= &This
->generic
.base
.IDirectInputDevice8A_iface
;
680 return DIERR_DEVICENOTREG
;
684 const struct dinput_device joystick_linuxinput_device
= {
685 "Wine Linux-input joystick driver",
691 /******************************************************************************
692 * Acquire : gets exclusive control of the joystick
694 static HRESULT WINAPI
JoystickWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface
)
696 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
699 TRACE("(this=%p)\n",This
);
701 if ((res
= IDirectInputDevice2WImpl_Acquire(iface
)) != DI_OK
)
703 WARN("Failed to acquire: %x\n", res
);
707 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDWR
)) == -1)
709 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDONLY
)) == -1)
711 /* Couldn't open the device at all */
712 ERR("Failed to open device %s: %d %s\n", This
->joydev
->device
, errno
, strerror(errno
));
713 IDirectInputDevice2WImpl_Unacquire(iface
);
714 return DIERR_NOTFOUND
;
718 /* Couldn't open in r/w but opened in read-only. */
719 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
724 struct input_event event
;
727 event
.code
= FF_GAIN
;
728 event
.value
= This
->ff_gain
;
729 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
730 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
731 if (!This
->ff_autocenter
)
733 /* Disable autocenter. */
734 event
.code
= FF_AUTOCENTER
;
736 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
737 ERR("Failed disabling autocenter: %d %s\n", errno
, strerror(errno
));
744 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
746 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
747 return JoystickWImpl_Acquire(IDirectInputDevice8W_from_impl(This
));
750 /******************************************************************************
751 * Unacquire : frees the joystick
753 static HRESULT WINAPI
JoystickWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface
)
755 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
758 TRACE("(this=%p)\n",This
);
759 res
= IDirectInputDevice2WImpl_Unacquire(iface
);
760 if (res
==DI_OK
&& This
->joyfd
!=-1) {
761 struct input_event event
;
763 /* Stop and unload all effects */
764 JoystickWImpl_SendForceFeedbackCommand(iface
, DISFFC_RESET
);
766 /* Enable autocenter. */
768 event
.code
= FF_AUTOCENTER
;
769 /* TODO: Read autocenter strength before disabling it, and use it here
770 * instead of 0xFFFF (maximum strength).
772 event
.value
= 0xFFFF;
773 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
774 ERR("Failed to set autocenter to %04x: %d %s\n", event
.value
, errno
, strerror(errno
));
782 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
784 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
785 return JoystickWImpl_Unacquire(IDirectInputDevice8W_from_impl(This
));
789 * set the current state of the js device as it would be with the middle
792 #define CENTER_AXIS(a) \
793 (ji->dev_axes_to_di[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->dev_axes_to_di[a]], \
794 ji->joydev->axes[a].value ))
795 static void fake_current_js_state(JoystickImpl
*ji
)
799 /* center the axes */
800 ji
->generic
.js
.lX
= CENTER_AXIS(ABS_X
);
801 ji
->generic
.js
.lY
= CENTER_AXIS(ABS_Y
);
802 ji
->generic
.js
.lZ
= CENTER_AXIS(ABS_Z
);
803 ji
->generic
.js
.lRx
= CENTER_AXIS(ABS_RX
);
804 ji
->generic
.js
.lRy
= CENTER_AXIS(ABS_RY
);
805 ji
->generic
.js
.lRz
= CENTER_AXIS(ABS_RZ
);
806 ji
->generic
.js
.rglSlider
[0] = CENTER_AXIS(ABS_THROTTLE
);
807 ji
->generic
.js
.rglSlider
[1] = CENTER_AXIS(ABS_RUDDER
);
809 /* POV center is -1 */
810 for (i
= 0; i
< 4; i
++)
811 ji
->generic
.js
.rgdwPOV
[i
] = -1;
815 /* convert wine format offset to user format object index */
816 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
)
819 struct input_event ie
;
820 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
830 plfd
.fd
= This
->joyfd
;
831 plfd
.events
= POLLIN
;
833 if (poll(&plfd
,1,0) != 1)
836 /* we have one event, so we can read */
837 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
840 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
842 case EV_KEY
: /* button */
844 int btn
= This
->buttons
[ie
.code
];
846 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
850 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
851 This
->generic
.js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
857 int axis
= This
->dev_axes_to_di
[ie
.code
];
859 /* User axis remapping */
861 axis
= This
->generic
.axis_map
[axis
];
864 inst_id
= axis
< 8 ? DIDFT_MAKEINSTANCE(axis
) | DIDFT_ABSAXIS
:
865 DIDFT_MAKEINSTANCE(axis
- 8) | DIDFT_POV
;
866 value
= joystick_map_axis(&This
->generic
.props
[id_to_object(This
->generic
.base
.data_format
.wine_df
, inst_id
)], ie
.value
);
869 case 0: This
->generic
.js
.lX
= value
; break;
870 case 1: This
->generic
.js
.lY
= value
; break;
871 case 2: This
->generic
.js
.lZ
= value
; break;
872 case 3: This
->generic
.js
.lRx
= value
; break;
873 case 4: This
->generic
.js
.lRy
= value
; break;
874 case 5: This
->generic
.js
.lRz
= value
; break;
875 case 6: This
->generic
.js
.rglSlider
[0] = value
; break;
876 case 7: This
->generic
.js
.rglSlider
[1] = value
; break;
877 case 8: case 9: case 10: case 11:
882 This
->povs
[idx
].y
= ie
.value
;
884 This
->povs
[idx
].x
= ie
.value
;
886 This
->generic
.js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
890 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
894 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
896 This
->ff_state
= ie
.value
;
901 /* there is nothing to do */
910 TRACE("skipping event\n");
914 queue_event(iface
, inst_id
,
915 value
, GetCurrentTime(), This
->generic
.base
.dinput
->evsequence
++);
919 /******************************************************************************
920 * SetProperty : change input device properties
922 static HRESULT WINAPI
JoystickWImpl_SetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPCDIPROPHEADER ph
)
924 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
927 WARN("invalid argument\n");
928 return DIERR_INVALIDPARAM
;
931 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
932 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
933 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
935 if (IS_DIPROP(rguid
)) {
936 switch (LOWORD(rguid
)) {
937 case (DWORD_PTR
)DIPROP_AUTOCENTER
: {
938 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
940 TRACE("autocenter(%d)\n", pd
->dwData
);
941 This
->ff_autocenter
= pd
->dwData
== DIPROPAUTOCENTER_ON
;
945 case (DWORD_PTR
)DIPROP_FFGAIN
: {
946 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
948 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
949 This
->ff_gain
= MulDiv(pd
->dwData
, 0xFFFF, 10000);
950 if (This
->generic
.base
.acquired
) {
951 /* Update immediately. */
952 struct input_event event
;
955 event
.code
= FF_GAIN
;
956 event
.value
= This
->ff_gain
;
957 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
958 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
963 return JoystickWGenericImpl_SetProperty(iface
, rguid
, ph
);
969 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPCDIPROPHEADER ph
)
971 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
972 return JoystickWImpl_SetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, ph
);
975 /******************************************************************************
976 * GetProperty : get input device properties
978 static HRESULT WINAPI
JoystickWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
980 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
982 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(rguid
), pdiph
);
983 _dump_DIPROPHEADER(pdiph
);
985 if (!IS_DIPROP(rguid
)) return DI_OK
;
987 switch (LOWORD(rguid
)) {
988 case (DWORD_PTR
) DIPROP_AUTOCENTER
:
990 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
992 pd
->dwData
= This
->ff_autocenter
? DIPROPAUTOCENTER_ON
: DIPROPAUTOCENTER_OFF
;
993 TRACE("autocenter(%d)\n", pd
->dwData
);
996 case (DWORD_PTR
) DIPROP_FFGAIN
:
998 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1000 pd
->dwData
= MulDiv(This
->ff_gain
, 10000, 0xFFFF);
1001 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
1005 case (DWORD_PTR
) DIPROP_VIDPID
:
1007 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1009 if (!This
->joydev
->product_id
|| !This
->joydev
->vendor_id
)
1010 return DIERR_UNSUPPORTED
;
1011 pd
->dwData
= MAKELONG(This
->joydev
->vendor_id
, This
->joydev
->product_id
);
1012 TRACE("DIPROP_VIDPID(%08x)\n", pd
->dwData
);
1016 case (DWORD_PTR
) DIPROP_JOYSTICKID
:
1018 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1020 pd
->dwData
= get_joystick_index(&This
->generic
.base
.guid
);
1021 TRACE("DIPROP_JOYSTICKID(%d)\n", pd
->dwData
);
1025 case (DWORD_PTR
) DIPROP_GUIDANDPATH
:
1027 static const WCHAR formatW
[] = {'\\','\\','?','\\','h','i','d','#','v','i','d','_','%','0','4','x','&',
1028 'p','i','d','_','%','0','4','x','&','%','s','_','%','h','u',0};
1029 static const WCHAR miW
[] = {'m','i',0};
1030 static const WCHAR igW
[] = {'i','g',0};
1033 LPDIPROPGUIDANDPATH pd
= (LPDIPROPGUIDANDPATH
)pdiph
;
1034 WORD vid
= This
->joydev
->vendor_id
;
1035 WORD pid
= This
->joydev
->product_id
;
1038 return DIERR_UNSUPPORTED
;
1040 is_gamepad
= is_xinput_device(&This
->generic
.devcaps
, vid
, pid
);
1041 pd
->guidClass
= GUID_DEVCLASS_HIDCLASS
;
1042 sprintfW(pd
->wszPath
, formatW
, vid
, pid
, is_gamepad
? igW
: miW
, get_joystick_index(&This
->generic
.base
.guid
));
1044 TRACE("DIPROP_GUIDANDPATH(%s, %s): returning fake path\n", debugstr_guid(&pd
->guidClass
), debugstr_w(pd
->wszPath
));
1049 return JoystickWGenericImpl_GetProperty(iface
, rguid
, pdiph
);
1055 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
1057 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1058 return JoystickWImpl_GetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, pdiph
);
1061 /******************************************************************************
1062 * CreateEffect - Create a new FF effect with the specified params
1064 static HRESULT WINAPI
JoystickWImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
,
1065 LPCDIEFFECT lpeff
, LPDIRECTINPUTEFFECT
*ppdef
,
1066 LPUNKNOWN pUnkOuter
)
1068 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1069 effect_list_item
* new_effect
= NULL
;
1070 HRESULT retval
= DI_OK
;
1073 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1074 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
1077 if (!This
->joydev
->has_ff
)
1079 TRACE("No force feedback support\n");
1080 return DIERR_UNSUPPORTED
;
1083 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1084 TRACE("not available (compiled w/o force feedback support)\n");
1085 return DIERR_UNSUPPORTED
;
1088 if (!(new_effect
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect
))))
1089 return DIERR_OUTOFMEMORY
;
1091 retval
= linuxinput_create_effect(&This
->joyfd
, rguid
, &new_effect
->entry
, &new_effect
->ref
);
1092 if (retval
!= DI_OK
)
1094 HeapFree(GetProcessHeap(), 0, new_effect
);
1100 retval
= IDirectInputEffect_SetParameters(new_effect
->ref
, lpeff
, 0);
1102 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1104 HeapFree(GetProcessHeap(), 0, new_effect
);
1109 list_add_tail(&This
->ff_effects
, &new_effect
->entry
);
1110 *ppdef
= new_effect
->ref
;
1112 if (pUnkOuter
!= NULL
)
1113 FIXME("Interface aggregation not implemented.\n");
1117 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1120 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
,
1121 LPCDIEFFECT lpeff
, LPDIRECTINPUTEFFECT
*ppdef
,
1122 LPUNKNOWN pUnkOuter
)
1124 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1125 return JoystickWImpl_CreateEffect(IDirectInputDevice8W_from_impl(This
), rguid
, lpeff
, ppdef
, pUnkOuter
);
1128 /*******************************************************************************
1129 * EnumEffects - Enumerate available FF effects
1131 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1132 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1136 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1137 DIEFFECTINFOA dei
; /* feif */
1138 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1139 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1141 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
1143 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1145 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1146 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1147 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1148 (*lpCallback
)(&dei
, pvRef
);
1151 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1152 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1153 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1154 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1155 (*lpCallback
)(&dei
, pvRef
);
1157 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1158 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1159 (*lpCallback
)(&dei
, pvRef
);
1161 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1162 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1163 (*lpCallback
)(&dei
, pvRef
);
1165 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1166 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1167 (*lpCallback
)(&dei
, pvRef
);
1169 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1170 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1171 (*lpCallback
)(&dei
, pvRef
);
1175 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1176 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1177 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1178 (*lpCallback
)(&dei
, pvRef
);
1181 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1182 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1183 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1184 (*lpCallback
)(&dei
, pvRef
);
1186 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1187 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1188 (*lpCallback
)(&dei
, pvRef
);
1190 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1191 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1192 (*lpCallback
)(&dei
, pvRef
);
1194 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1195 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1196 (*lpCallback
)(&dei
, pvRef
);
1205 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1206 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1210 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1211 /* seems silly to duplicate all this code but all the structures and functions
1212 * are actually different (A/W) */
1213 DIEFFECTINFOW dei
; /* feif */
1214 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1215 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1216 int xfd
= This
->joyfd
;
1218 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1220 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1222 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1223 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1224 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1225 (*lpCallback
)(&dei
, pvRef
);
1228 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1229 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1230 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1231 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1232 (*lpCallback
)(&dei
, pvRef
);
1234 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1235 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1236 (*lpCallback
)(&dei
, pvRef
);
1238 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1239 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1240 (*lpCallback
)(&dei
, pvRef
);
1242 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1243 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1244 (*lpCallback
)(&dei
, pvRef
);
1246 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1247 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1248 (*lpCallback
)(&dei
, pvRef
);
1252 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1253 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1254 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1255 (*lpCallback
)(&dei
, pvRef
);
1258 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1259 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1260 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1261 (*lpCallback
)(&dei
, pvRef
);
1263 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1264 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1265 (*lpCallback
)(&dei
, pvRef
);
1267 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1268 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1269 (*lpCallback
)(&dei
, pvRef
);
1271 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1272 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1273 (*lpCallback
)(&dei
, pvRef
);
1277 /* return to unacquired state if that's where it was */
1279 IDirectInputDevice8_Unacquire(iface
);
1285 /*******************************************************************************
1286 * GetEffectInfo - Get information about a particular effect
1288 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1289 LPDIEFFECTINFOA pdei
,
1292 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1294 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1296 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1297 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1303 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1304 LPDIEFFECTINFOW pdei
,
1307 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1309 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1311 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1312 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1318 /*******************************************************************************
1319 * GetForceFeedbackState - Get information about the device's FF state
1321 static HRESULT WINAPI
JoystickWImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface
, LPDWORD pdwOut
)
1323 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1325 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1329 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1330 /* DIGFFS_STOPPED is the only mandatory flag to report */
1331 if (This
->ff_state
== FF_STATUS_STOPPED
)
1332 (*pdwOut
) |= DIGFFS_STOPPED
;
1338 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8A iface
, LPDWORD pdwOut
)
1340 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1341 return JoystickWImpl_GetForceFeedbackState(IDirectInputDevice8W_from_impl(This
), pdwOut
);
1344 /*******************************************************************************
1345 * SendForceFeedbackCommand - Send a command to the device's FF system
1347 static HRESULT WINAPI
JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface
, DWORD dwFlags
)
1349 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1350 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1352 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1355 case DISFFC_STOPALL
:
1357 effect_list_item
*itr
;
1359 /* Stop all effects */
1360 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1361 IDirectInputEffect_Stop(itr
->ref
);
1367 effect_list_item
*itr
;
1369 /* Stop and unload all effects. It is not true that effects are released */
1370 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1372 IDirectInputEffect_Stop(itr
->ref
);
1373 IDirectInputEffect_Unload(itr
->ref
);
1378 case DISFFC_CONTINUE
:
1379 FIXME("No support for Pause or Continue in linux\n");
1382 case DISFFC_SETACTUATORSOFF
:
1383 case DISFFC_SETACTUATORSON
:
1384 FIXME("No direct actuator control in linux\n");
1388 WARN("Unknown Force Feedback Command %u!\n", dwFlags
);
1389 return DIERR_INVALIDPARAM
;
1393 return DIERR_UNSUPPORTED
;
1397 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8A iface
, DWORD dwFlags
)
1399 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1400 return JoystickWImpl_SendForceFeedbackCommand(IDirectInputDevice8W_from_impl(This
), dwFlags
);
1403 /*******************************************************************************
1404 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1405 * created for this device.
1407 static HRESULT WINAPI
JoystickWImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface
,
1408 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1409 LPVOID pvRef
, DWORD dwFlags
)
1411 /* this function is safe to call on non-ff-enabled builds */
1412 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1413 effect_list_item
*itr
, *ptr
;
1415 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1418 return DIERR_INVALIDPARAM
;
1421 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1423 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1424 (*lpCallback
)(itr
->ref
, pvRef
);
1429 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8A iface
,
1430 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1431 LPVOID pvRef
, DWORD dwFlags
)
1433 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1434 return JoystickWImpl_EnumCreatedEffectObjects(IDirectInputDevice8W_from_impl(This
), lpCallback
, pvRef
, dwFlags
);
1437 /******************************************************************************
1438 * GetDeviceInfo : get information about a device's identity
1440 static HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface
,
1441 LPDIDEVICEINSTANCEA pdidi
)
1443 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1445 TRACE("(%p) %p\n", This
, pdidi
);
1447 if (pdidi
== NULL
) return E_POINTER
;
1448 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1449 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)))
1450 return DIERR_INVALIDPARAM
;
1452 fill_joystick_dideviceinstanceA(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1453 get_joystick_index(&This
->generic
.base
.guid
));
1457 static HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
,
1458 LPDIDEVICEINSTANCEW pdidi
)
1460 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
1462 TRACE("(%p) %p\n", This
, pdidi
);
1464 if (pdidi
== NULL
) return E_POINTER
;
1465 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1466 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)))
1467 return DIERR_INVALIDPARAM
;
1469 fill_joystick_dideviceinstanceW(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1470 get_joystick_index(&This
->generic
.base
.guid
));
1474 static const IDirectInputDevice8AVtbl JoystickAvt
=
1476 IDirectInputDevice2AImpl_QueryInterface
,
1477 IDirectInputDevice2AImpl_AddRef
,
1478 IDirectInputDevice2AImpl_Release
,
1479 JoystickAGenericImpl_GetCapabilities
,
1480 IDirectInputDevice2AImpl_EnumObjects
,
1481 JoystickAImpl_GetProperty
,
1482 JoystickAImpl_SetProperty
,
1483 JoystickAImpl_Acquire
,
1484 JoystickAImpl_Unacquire
,
1485 JoystickAGenericImpl_GetDeviceState
,
1486 IDirectInputDevice2AImpl_GetDeviceData
,
1487 IDirectInputDevice2AImpl_SetDataFormat
,
1488 IDirectInputDevice2AImpl_SetEventNotification
,
1489 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1490 JoystickAGenericImpl_GetObjectInfo
,
1491 JoystickAImpl_GetDeviceInfo
,
1492 IDirectInputDevice2AImpl_RunControlPanel
,
1493 IDirectInputDevice2AImpl_Initialize
,
1494 JoystickAImpl_CreateEffect
,
1495 JoystickAImpl_EnumEffects
,
1496 JoystickAImpl_GetEffectInfo
,
1497 JoystickAImpl_GetForceFeedbackState
,
1498 JoystickAImpl_SendForceFeedbackCommand
,
1499 JoystickAImpl_EnumCreatedEffectObjects
,
1500 IDirectInputDevice2AImpl_Escape
,
1501 JoystickAGenericImpl_Poll
,
1502 IDirectInputDevice2AImpl_SendDeviceData
,
1503 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1504 IDirectInputDevice7AImpl_WriteEffectToFile
,
1505 JoystickAGenericImpl_BuildActionMap
,
1506 JoystickAGenericImpl_SetActionMap
,
1507 IDirectInputDevice8AImpl_GetImageInfo
1510 static const IDirectInputDevice8WVtbl JoystickWvt
=
1512 IDirectInputDevice2WImpl_QueryInterface
,
1513 IDirectInputDevice2WImpl_AddRef
,
1514 IDirectInputDevice2WImpl_Release
,
1515 JoystickWGenericImpl_GetCapabilities
,
1516 IDirectInputDevice2WImpl_EnumObjects
,
1517 JoystickWImpl_GetProperty
,
1518 JoystickWImpl_SetProperty
,
1519 JoystickWImpl_Acquire
,
1520 JoystickWImpl_Unacquire
,
1521 JoystickWGenericImpl_GetDeviceState
,
1522 IDirectInputDevice2WImpl_GetDeviceData
,
1523 IDirectInputDevice2WImpl_SetDataFormat
,
1524 IDirectInputDevice2WImpl_SetEventNotification
,
1525 IDirectInputDevice2WImpl_SetCooperativeLevel
,
1526 JoystickWGenericImpl_GetObjectInfo
,
1527 JoystickWImpl_GetDeviceInfo
,
1528 IDirectInputDevice2WImpl_RunControlPanel
,
1529 IDirectInputDevice2WImpl_Initialize
,
1530 JoystickWImpl_CreateEffect
,
1531 JoystickWImpl_EnumEffects
,
1532 JoystickWImpl_GetEffectInfo
,
1533 JoystickWImpl_GetForceFeedbackState
,
1534 JoystickWImpl_SendForceFeedbackCommand
,
1535 JoystickWImpl_EnumCreatedEffectObjects
,
1536 IDirectInputDevice2WImpl_Escape
,
1537 JoystickWGenericImpl_Poll
,
1538 IDirectInputDevice2WImpl_SendDeviceData
,
1539 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1540 IDirectInputDevice7WImpl_WriteEffectToFile
,
1541 JoystickWGenericImpl_BuildActionMap
,
1542 JoystickWGenericImpl_SetActionMap
,
1543 IDirectInputDevice8WImpl_GetImageInfo
1546 #else /* HAS_PROPER_HEADER */
1548 const struct dinput_device joystick_linuxinput_device
= {
1549 "Wine Linux-input joystick driver",
1555 #endif /* HAS_PROPER_HEADER */