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}
169 * Construct the GUID in the same way of Windows doing this.
170 * Data1 is concatenation of productid and vendorid.
171 * Data2 and Data3 are NULL.
172 * Data4 seems to be a constant.
174 static const GUID DInput_Wine_Joystick_Constant_Part_GUID
= {
178 {0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44}
181 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
183 #define MAX_JOYDEV 64
185 static int have_joydevs
= -1;
186 static struct JoyDev
*joydevs
= NULL
;
188 static void find_joydevs(void)
192 if (InterlockedCompareExchange(&have_joydevs
, 0, -1) != -1)
193 /* Someone beat us to it */
196 for (i
= 0; i
< MAX_JOYDEV
; i
++)
199 struct JoyDev joydev
= {0};
201 BOOL no_ff_check
= FALSE
;
203 struct JoyDev
*new_joydevs
;
204 struct input_id device_id
= {0};
206 snprintf(buf
, sizeof(buf
), EVDEVPREFIX
"%d", i
);
208 if ((fd
= open(buf
, O_RDWR
)) == -1)
210 fd
= open(buf
, O_RDONLY
);
217 if (ioctl(fd
, EVIOCGBIT(0, sizeof(joydev
.evbits
)), joydev
.evbits
) == -1)
219 WARN("ioctl(EVIOCGBIT, 0) failed: %d %s\n", errno
, strerror(errno
));
223 if (ioctl(fd
, EVIOCGBIT(EV_ABS
, sizeof(joydev
.absbits
)), joydev
.absbits
) == -1)
225 WARN("ioctl(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
229 if (ioctl(fd
, EVIOCGBIT(EV_KEY
, sizeof(joydev
.keybits
)), joydev
.keybits
) == -1)
231 WARN("ioctl(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno
, strerror(errno
));
236 /* A true joystick has at least axis X and Y, and at least 1
237 * button. copied from linux/drivers/input/joydev.c */
238 if (((!test_bit(joydev
.absbits
, ABS_X
) || !test_bit(joydev
.absbits
, ABS_Y
)) &&
239 !test_bit(joydev
.absbits
, ABS_WHEEL
) &&
240 !test_bit(joydev
.absbits
, ABS_GAS
) &&
241 !test_bit(joydev
.absbits
, ABS_BRAKE
)) ||
242 !(test_bit(joydev
.keybits
, BTN_TRIGGER
) ||
243 test_bit(joydev
.keybits
, BTN_A
) ||
244 test_bit(joydev
.keybits
, BTN_1
) ||
245 test_bit(joydev
.keybits
, BTN_BASE
) ||
246 test_bit(joydev
.keybits
, BTN_GEAR_UP
) ||
247 test_bit(joydev
.keybits
, BTN_GEAR_DOWN
)))
253 /* in lieu of properly reporting HID usage, detect presence of
254 * "joystick buttons" and report those devices as joysticks instead of
257 test_bit(joydev
.keybits
, BTN_TRIGGER
) ||
258 test_bit(joydev
.keybits
, BTN_THUMB
) ||
259 test_bit(joydev
.keybits
, BTN_THUMB2
) ||
260 test_bit(joydev
.keybits
, BTN_TOP
) ||
261 test_bit(joydev
.keybits
, BTN_TOP2
) ||
262 test_bit(joydev
.keybits
, BTN_PINKIE
) ||
263 test_bit(joydev
.keybits
, BTN_BASE
) ||
264 test_bit(joydev
.keybits
, BTN_BASE2
) ||
265 test_bit(joydev
.keybits
, BTN_BASE3
) ||
266 test_bit(joydev
.keybits
, BTN_BASE4
) ||
267 test_bit(joydev
.keybits
, BTN_BASE5
) ||
268 test_bit(joydev
.keybits
, BTN_BASE6
) ||
269 test_bit(joydev
.keybits
, BTN_GEAR_UP
) ||
270 test_bit(joydev
.keybits
, BTN_GEAR_DOWN
) ||
271 test_bit(joydev
.keybits
, BTN_DEAD
);
273 if (!(joydev
.device
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
278 strcpy(joydev
.device
, buf
);
280 buf
[MAX_PATH
- 1] = 0;
281 if (ioctl(fd
, EVIOCGNAME(MAX_PATH
- 1), buf
) != -1 &&
282 (joydev
.name
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + strlen(EVDEVDRIVER
) + 1)))
284 strcpy(joydev
.name
, buf
);
285 /* Append driver name */
286 strcat(joydev
.name
, EVDEVDRIVER
);
289 joydev
.name
= joydev
.device
;
291 if (device_disabled_registry(joydev
.name
)) {
293 HeapFree(GetProcessHeap(), 0, joydev
.name
);
294 if (joydev
.name
!= joydev
.device
)
295 HeapFree(GetProcessHeap(), 0, joydev
.device
);
299 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
300 joydev
.guid
.Data3
+= have_joydevs
;
302 TRACE("Found a joystick on %s: %s (%s)\n",
303 joydev
.device
, joydev
.name
,
304 debugstr_guid(&joydev
.guid
)
307 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
309 test_bit(joydev
.evbits
, EV_FF
) &&
310 ioctl(fd
, EVIOCGBIT(EV_FF
, sizeof(joydev
.ffbits
)), joydev
.ffbits
) != -1 &&
311 ioctl(fd
, EVIOCGEFFECTS
, &joydev
.num_effects
) != -1 &&
312 joydev
.num_effects
> 0)
314 TRACE(" ... with force feedback\n");
315 joydev
.has_ff
= TRUE
;
319 for (j
= 0; j
< ABS_MAX
;j
++)
321 if (!test_bit(joydev
.absbits
, j
)) continue;
322 if (ioctl(fd
, EVIOCGABS(j
), &(joydev
.axes
[j
])) != -1)
324 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
326 joydev
.axes
[j
].value
,
327 joydev
.axes
[j
].minimum
,
328 joydev
.axes
[j
].maximum
,
335 if (ioctl(fd
, EVIOCGID
, &device_id
) == -1)
337 WARN("ioctl(EVIOCGID) failed: %d %s\n", errno
, strerror(errno
));
338 joydev
.guid_product
= DInput_Wine_Joystick_Base_GUID
;
342 joydev
.vendor_id
= device_id
.vendor
;
343 joydev
.product_id
= device_id
.product
;
344 joydev
.bus_type
= device_id
.bustype
;
346 /* Concatenate product_id with vendor_id to mimic Windows behaviour */
347 joydev
.guid_product
= DInput_Wine_Joystick_Constant_Part_GUID
;
348 joydev
.guid_product
.Data1
= MAKELONG(joydev
.vendor_id
, joydev
.product_id
);
352 new_joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
354 new_joydevs
= HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1 + have_joydevs
) * sizeof(struct JoyDev
));
361 joydevs
= new_joydevs
;
362 joydevs
[have_joydevs
] = joydev
;
369 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
371 DWORD dwSize
= lpddi
->dwSize
;
373 TRACE("%d %p\n", dwSize
, lpddi
);
374 memset(lpddi
, 0, dwSize
);
376 lpddi
->dwSize
= dwSize
;
377 lpddi
->guidInstance
= joydevs
[id
].guid
;
378 lpddi
->guidProduct
= joydevs
[id
].guid_product
;
379 lpddi
->guidFFDriver
= GUID_NULL
;
380 lpddi
->dwDevType
= get_device_type(version
, joydevs
[id
].is_joystick
);
382 /* Assume the joystick as HID if it is attached to USB bus and has a valid VID/PID */
383 if (joydevs
[id
].bus_type
== BUS_USB
&&
384 joydevs
[id
].vendor_id
&& joydevs
[id
].product_id
)
386 lpddi
->dwDevType
|= DIDEVTYPE_HID
;
387 lpddi
->wUsagePage
= 0x01; /* Desktop */
388 if (joydevs
[id
].is_joystick
)
389 lpddi
->wUsage
= 0x04; /* Joystick */
391 lpddi
->wUsage
= 0x05; /* Game Pad */
394 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
395 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszProductName
, MAX_PATH
);
398 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
400 DIDEVICEINSTANCEW lpddiW
;
401 DWORD dwSize
= lpddi
->dwSize
;
403 lpddiW
.dwSize
= sizeof(lpddiW
);
404 fill_joystick_dideviceinstanceW(&lpddiW
, version
, id
);
406 TRACE("%d %p\n", dwSize
, lpddi
);
407 memset(lpddi
, 0, dwSize
);
410 lpddi
->dwSize
= dwSize
;
411 lpddi
->guidInstance
= lpddiW
.guidInstance
;
412 lpddi
->guidProduct
= lpddiW
.guidProduct
;
413 lpddi
->dwDevType
= lpddiW
.dwDevType
;
414 lstrcpynA(lpddi
->tszInstanceName
, joydevs
[id
].name
, MAX_PATH
);
415 lstrcpynA(lpddi
->tszProductName
, joydevs
[id
].name
, MAX_PATH
);
416 lpddi
->guidFFDriver
= lpddiW
.guidFFDriver
;
417 lpddi
->wUsagePage
= lpddiW
.wUsagePage
;
418 lpddi
->wUsage
= lpddiW
.wUsage
;
421 static HRESULT
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
425 if (id
>= have_joydevs
) {
429 if (!((dwDevType
== 0) ||
430 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
>= 0x0300 && version
< 0x0800)) ||
431 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
434 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
435 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
439 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
440 fill_joystick_dideviceinstanceA(lpddi
, version
, id
);
446 static HRESULT
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
450 if (id
>= have_joydevs
) {
454 if (!((dwDevType
== 0) ||
455 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
>= 0x0300 && version
< 0x0800)) ||
456 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
459 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
460 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
464 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
465 fill_joystick_dideviceinstanceW(lpddi
, version
, id
);
471 static JoystickImpl
*alloc_device(REFGUID rguid
, IDirectInputImpl
*dinput
, unsigned short index
)
473 JoystickImpl
* newDevice
;
474 LPDIDATAFORMAT df
= NULL
;
476 int default_axis_map
[WINE_JOYSTICK_MAX_AXES
+ WINE_JOYSTICK_MAX_POVS
*2];
477 DIDEVICEINSTANCEW ddi
;
479 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
480 if (!newDevice
) return NULL
;
482 newDevice
->generic
.base
.IDirectInputDevice8A_iface
.lpVtbl
= &JoystickAvt
;
483 newDevice
->generic
.base
.IDirectInputDevice8W_iface
.lpVtbl
= &JoystickWvt
;
484 newDevice
->generic
.base
.ref
= 1;
485 newDevice
->generic
.base
.guid
= *rguid
;
486 newDevice
->generic
.base
.dinput
= dinput
;
487 newDevice
->generic
.joy_polldev
= joy_polldev
;
488 newDevice
->joyfd
= -1;
489 newDevice
->joydev
= &joydevs
[index
];
490 newDevice
->generic
.name
= newDevice
->joydev
->name
;
491 list_init(&newDevice
->ff_effects
);
492 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
493 newDevice
->ff_state
= FF_STATUS_STOPPED
;
495 /* There is no way in linux to query force feedback autocenter status.
496 Instead, track it with ff_autocenter, and assume it's initially
498 newDevice
->ff_autocenter
= 1;
499 newDevice
->ff_gain
= 0xFFFF;
500 InitializeCriticalSection(&newDevice
->generic
.base
.crit
);
501 newDevice
->generic
.base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
503 /* Count number of available axes - supported Axis & POVs */
504 for (i
= 0; i
< ABS_MAX
; i
++)
506 if (idx
< WINE_JOYSTICK_MAX_AXES
&&
508 test_bit(newDevice
->joydev
->absbits
, i
))
510 newDevice
->generic
.device_axis_count
++;
511 newDevice
->dev_axes_to_di
[i
] = idx
;
512 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[i
].minimum
;
513 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[i
].maximum
;
514 if (i
>= 8 && i
<= 10) /* If it's a wheel axis... */
515 default_axis_map
[idx
] = i
- 8; /* ... remap to X/Y/Z */
517 default_axis_map
[idx
] = i
;
521 newDevice
->dev_axes_to_di
[i
] = -1;
524 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
526 if (test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) &&
527 test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2))
529 newDevice
->generic
.device_axis_count
+= 2;
530 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].minimum
;
531 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].maximum
;
532 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = idx
;
533 newDevice
->generic
.props
[idx
+1].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].minimum
;
534 newDevice
->generic
.props
[idx
+1].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].maximum
;
535 newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = idx
+ 1;
537 default_axis_map
[idx
] = default_axis_map
[idx
+ 1] = WINE_JOYSTICK_MAX_AXES
+ i
;
541 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = -1;
544 /* do any user specified configuration */
545 if (setup_dinput_options(&newDevice
->generic
, default_axis_map
) != DI_OK
) goto failed
;
547 /* Create copy of default data format */
548 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
549 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
550 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
553 /* Construct internal data format */
555 /* Supported Axis & POVs */
556 for (i
= 0, idx
= 0; i
< newDevice
->generic
.device_axis_count
; i
++)
558 int wine_obj
= newDevice
->generic
.axis_map
[i
];
560 if (wine_obj
< 0) continue;
562 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[wine_obj
], df
->dwObjSize
);
564 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
) | DIDFT_ABSAXIS
;
567 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
- 8) | DIDFT_POV
;
568 i
++; /* POV takes 2 axes */
571 newDevice
->generic
.props
[idx
].lMin
= 0;
572 newDevice
->generic
.props
[idx
].lMax
= 0xffff;
573 newDevice
->generic
.props
[idx
].lSaturation
= 0;
574 newDevice
->generic
.props
[idx
].lDeadZone
= newDevice
->generic
.deadzone
;
576 /* Linux supports force-feedback on X & Y axes only */
577 if (newDevice
->joydev
->has_ff
&& (i
== 0 || i
== 1))
578 df
->rgodf
[idx
].dwFlags
|= DIDOI_FFACTUATOR
;
583 /* Buttons can be anywhere, so check all */
584 for (i
= 0; i
< KEY_MAX
&& newDevice
->generic
.devcaps
.dwButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
586 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
588 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->generic
.devcaps
.dwButtons
+ 12], df
->dwObjSize
);
589 newDevice
->buttons
[i
] = 0x80 | newDevice
->generic
.devcaps
.dwButtons
;
590 df
->rgodf
[idx
].pguid
= &GUID_Button
;
591 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->generic
.devcaps
.dwButtons
++) | DIDFT_PSHBUTTON
;
594 newDevice
->generic
.base
.data_format
.wine_df
= df
;
596 fake_current_js_state(newDevice
);
599 newDevice
->generic
.devcaps
.dwSize
= sizeof(newDevice
->generic
.devcaps
);
600 newDevice
->generic
.devcaps
.dwFlags
= DIDC_ATTACHED
;
602 ddi
.dwSize
= sizeof(ddi
);
603 fill_joystick_dideviceinstanceW(&ddi
, newDevice
->generic
.base
.dinput
->dwVersion
, index
);
604 newDevice
->generic
.devcaps
.dwDevType
= ddi
.dwDevType
;
606 if (newDevice
->joydev
->has_ff
)
607 newDevice
->generic
.devcaps
.dwFlags
|= DIDC_FORCEFEEDBACK
;
609 IDirectInput_AddRef(&newDevice
->generic
.base
.dinput
->IDirectInput7A_iface
);
611 EnterCriticalSection(&dinput
->crit
);
612 list_add_tail(&dinput
->devices_list
, &newDevice
->generic
.base
.entry
);
613 LeaveCriticalSection(&dinput
->crit
);
618 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
619 HeapFree(GetProcessHeap(), 0, df
);
620 HeapFree(GetProcessHeap(), 0, newDevice
->generic
.axis_map
);
621 HeapFree(GetProcessHeap(), 0, newDevice
);
625 /******************************************************************************
626 * get_joystick_index : Get the joystick index from a given GUID
628 static unsigned short get_joystick_index(REFGUID guid
)
630 GUID wine_joystick
= DInput_Wine_Joystick_Base_GUID
;
631 GUID dev_guid
= *guid
;
633 wine_joystick
.Data3
= 0;
636 /* for the standard joystick GUID use index 0 */
637 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
639 /* for the wine joystick GUIDs use the index stored in Data3 */
640 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
- DInput_Wine_Joystick_Base_GUID
.Data3
;
645 static HRESULT
joydev_create_device(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPVOID
*pdev
, int unicode
)
647 unsigned short index
;
649 TRACE("%p %s %s %p %i\n", dinput
, debugstr_guid(rguid
), debugstr_guid(riid
), pdev
, unicode
);
653 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
654 have_joydevs
&& index
< have_joydevs
)
660 else if (IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
661 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
662 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
663 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
667 else if (IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
668 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
669 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
670 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
676 WARN("no interface\n");
677 return DIERR_NOINTERFACE
;
680 This
= alloc_device(rguid
, dinput
, index
);
681 TRACE("Created a Joystick device (%p)\n", This
);
683 if (!This
) return DIERR_OUTOFMEMORY
;
686 *pdev
= &This
->generic
.base
.IDirectInputDevice8W_iface
;
688 *pdev
= &This
->generic
.base
.IDirectInputDevice8A_iface
;
693 return DIERR_DEVICENOTREG
;
697 const struct dinput_device joystick_linuxinput_device
= {
698 "Wine Linux-input joystick driver",
704 /******************************************************************************
705 * Acquire : gets exclusive control of the joystick
707 static HRESULT WINAPI
JoystickWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface
)
709 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
712 TRACE("(this=%p)\n",This
);
714 if ((res
= IDirectInputDevice2WImpl_Acquire(iface
)) != DI_OK
)
716 WARN("Failed to acquire: %x\n", res
);
720 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDWR
)) == -1)
722 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDONLY
)) == -1)
724 /* Couldn't open the device at all */
725 ERR("Failed to open device %s: %d %s\n", This
->joydev
->device
, errno
, strerror(errno
));
726 IDirectInputDevice2WImpl_Unacquire(iface
);
727 return DIERR_NOTFOUND
;
731 /* Couldn't open in r/w but opened in read-only. */
732 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
737 struct input_event event
;
740 event
.code
= FF_GAIN
;
741 event
.value
= This
->ff_gain
;
742 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
743 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
744 if (!This
->ff_autocenter
)
746 /* Disable autocenter. */
747 event
.code
= FF_AUTOCENTER
;
749 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
750 ERR("Failed disabling autocenter: %d %s\n", errno
, strerror(errno
));
757 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
759 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
760 return JoystickWImpl_Acquire(IDirectInputDevice8W_from_impl(This
));
763 /******************************************************************************
764 * Unacquire : frees the joystick
766 static HRESULT WINAPI
JoystickWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface
)
768 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
771 TRACE("(this=%p)\n",This
);
772 res
= IDirectInputDevice2WImpl_Unacquire(iface
);
773 if (res
==DI_OK
&& This
->joyfd
!=-1) {
774 struct input_event event
;
776 /* Stop and unload all effects */
777 JoystickWImpl_SendForceFeedbackCommand(iface
, DISFFC_RESET
);
779 /* Enable autocenter. */
781 event
.code
= FF_AUTOCENTER
;
782 /* TODO: Read autocenter strength before disabling it, and use it here
783 * instead of 0xFFFF (maximum strength).
785 event
.value
= 0xFFFF;
786 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
787 ERR("Failed to set autocenter to %04x: %d %s\n", event
.value
, errno
, strerror(errno
));
795 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
797 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
798 return JoystickWImpl_Unacquire(IDirectInputDevice8W_from_impl(This
));
802 * set the current state of the js device as it would be with the middle
805 #define CENTER_AXIS(a) \
806 (ji->dev_axes_to_di[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->dev_axes_to_di[a]], \
807 ji->joydev->axes[a].value ))
808 static void fake_current_js_state(JoystickImpl
*ji
)
812 /* center the axes */
813 ji
->generic
.js
.lX
= CENTER_AXIS(ABS_X
);
814 ji
->generic
.js
.lY
= CENTER_AXIS(ABS_Y
);
815 ji
->generic
.js
.lZ
= CENTER_AXIS(ABS_Z
);
816 ji
->generic
.js
.lRx
= CENTER_AXIS(ABS_RX
);
817 ji
->generic
.js
.lRy
= CENTER_AXIS(ABS_RY
);
818 ji
->generic
.js
.lRz
= CENTER_AXIS(ABS_RZ
);
819 ji
->generic
.js
.rglSlider
[0] = CENTER_AXIS(ABS_THROTTLE
);
820 ji
->generic
.js
.rglSlider
[1] = CENTER_AXIS(ABS_RUDDER
);
822 /* POV center is -1 */
823 for (i
= 0; i
< 4; i
++)
824 ji
->generic
.js
.rgdwPOV
[i
] = -1;
828 /* convert wine format offset to user format object index */
829 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
)
832 struct input_event ie
;
833 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
843 plfd
.fd
= This
->joyfd
;
844 plfd
.events
= POLLIN
;
846 if (poll(&plfd
,1,0) != 1)
849 /* we have one event, so we can read */
850 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
853 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
855 case EV_KEY
: /* button */
857 int btn
= This
->buttons
[ie
.code
];
859 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
863 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
864 This
->generic
.js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
870 int axis
= This
->dev_axes_to_di
[ie
.code
];
872 /* User axis remapping */
874 axis
= This
->generic
.axis_map
[axis
];
877 inst_id
= axis
< 8 ? DIDFT_MAKEINSTANCE(axis
) | DIDFT_ABSAXIS
:
878 DIDFT_MAKEINSTANCE(axis
- 8) | DIDFT_POV
;
879 value
= joystick_map_axis(&This
->generic
.props
[id_to_object(This
->generic
.base
.data_format
.wine_df
, inst_id
)], ie
.value
);
882 case 0: This
->generic
.js
.lX
= value
; break;
883 case 1: This
->generic
.js
.lY
= value
; break;
884 case 2: This
->generic
.js
.lZ
= value
; break;
885 case 3: This
->generic
.js
.lRx
= value
; break;
886 case 4: This
->generic
.js
.lRy
= value
; break;
887 case 5: This
->generic
.js
.lRz
= value
; break;
888 case 6: This
->generic
.js
.rglSlider
[0] = value
; break;
889 case 7: This
->generic
.js
.rglSlider
[1] = value
; break;
890 case 8: case 9: case 10: case 11:
895 This
->povs
[idx
].y
= ie
.value
;
897 This
->povs
[idx
].x
= ie
.value
;
899 This
->generic
.js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
903 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
907 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
909 This
->ff_state
= ie
.value
;
914 /* there is nothing to do */
923 TRACE("skipping event\n");
927 queue_event(iface
, inst_id
,
928 value
, GetCurrentTime(), This
->generic
.base
.dinput
->evsequence
++);
932 /******************************************************************************
933 * SetProperty : change input device properties
935 static HRESULT WINAPI
JoystickWImpl_SetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPCDIPROPHEADER ph
)
937 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
940 WARN("invalid argument\n");
941 return DIERR_INVALIDPARAM
;
944 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
945 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
946 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
948 if (IS_DIPROP(rguid
)) {
949 switch (LOWORD(rguid
)) {
950 case (DWORD_PTR
)DIPROP_AUTOCENTER
: {
951 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
953 TRACE("autocenter(%d)\n", pd
->dwData
);
954 This
->ff_autocenter
= pd
->dwData
== DIPROPAUTOCENTER_ON
;
958 case (DWORD_PTR
)DIPROP_FFGAIN
: {
959 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
961 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
962 This
->ff_gain
= MulDiv(pd
->dwData
, 0xFFFF, 10000);
963 if (This
->generic
.base
.acquired
) {
964 /* Update immediately. */
965 struct input_event event
;
968 event
.code
= FF_GAIN
;
969 event
.value
= This
->ff_gain
;
970 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
971 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
976 return JoystickWGenericImpl_SetProperty(iface
, rguid
, ph
);
982 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPCDIPROPHEADER ph
)
984 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
985 return JoystickWImpl_SetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, ph
);
988 /******************************************************************************
989 * GetProperty : get input device properties
991 static HRESULT WINAPI
JoystickWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
993 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
995 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(rguid
), pdiph
);
996 _dump_DIPROPHEADER(pdiph
);
998 if (!IS_DIPROP(rguid
)) return DI_OK
;
1000 switch (LOWORD(rguid
)) {
1001 case (DWORD_PTR
) DIPROP_AUTOCENTER
:
1003 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1005 pd
->dwData
= This
->ff_autocenter
? DIPROPAUTOCENTER_ON
: DIPROPAUTOCENTER_OFF
;
1006 TRACE("autocenter(%d)\n", pd
->dwData
);
1009 case (DWORD_PTR
) DIPROP_FFGAIN
:
1011 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1013 pd
->dwData
= MulDiv(This
->ff_gain
, 10000, 0xFFFF);
1014 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
1018 case (DWORD_PTR
) DIPROP_VIDPID
:
1020 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1022 if (!This
->joydev
->product_id
|| !This
->joydev
->vendor_id
)
1023 return DIERR_UNSUPPORTED
;
1024 pd
->dwData
= MAKELONG(This
->joydev
->vendor_id
, This
->joydev
->product_id
);
1025 TRACE("DIPROP_VIDPID(%08x)\n", pd
->dwData
);
1029 case (DWORD_PTR
) DIPROP_JOYSTICKID
:
1031 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1033 pd
->dwData
= get_joystick_index(&This
->generic
.base
.guid
);
1034 TRACE("DIPROP_JOYSTICKID(%d)\n", pd
->dwData
);
1038 case (DWORD_PTR
) DIPROP_GUIDANDPATH
:
1040 static const WCHAR formatW
[] = {'\\','\\','?','\\','h','i','d','#','v','i','d','_','%','0','4','x','&',
1041 'p','i','d','_','%','0','4','x','&','%','s','_','%','h','u',0};
1042 static const WCHAR miW
[] = {'m','i',0};
1043 static const WCHAR igW
[] = {'i','g',0};
1046 LPDIPROPGUIDANDPATH pd
= (LPDIPROPGUIDANDPATH
)pdiph
;
1047 WORD vid
= This
->joydev
->vendor_id
;
1048 WORD pid
= This
->joydev
->product_id
;
1051 return DIERR_UNSUPPORTED
;
1053 is_gamepad
= is_xinput_device(&This
->generic
.devcaps
, vid
, pid
);
1054 pd
->guidClass
= GUID_DEVCLASS_HIDCLASS
;
1055 sprintfW(pd
->wszPath
, formatW
, vid
, pid
, is_gamepad
? igW
: miW
, get_joystick_index(&This
->generic
.base
.guid
));
1057 TRACE("DIPROP_GUIDANDPATH(%s, %s): returning fake path\n", debugstr_guid(&pd
->guidClass
), debugstr_w(pd
->wszPath
));
1062 return JoystickWGenericImpl_GetProperty(iface
, rguid
, pdiph
);
1068 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
1070 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1071 return JoystickWImpl_GetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, pdiph
);
1074 /******************************************************************************
1075 * CreateEffect - Create a new FF effect with the specified params
1077 static HRESULT WINAPI
JoystickWImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
,
1078 LPCDIEFFECT lpeff
, LPDIRECTINPUTEFFECT
*ppdef
,
1079 LPUNKNOWN pUnkOuter
)
1081 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1082 effect_list_item
* new_effect
= NULL
;
1083 HRESULT retval
= DI_OK
;
1086 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1087 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
1090 if (!This
->joydev
->has_ff
)
1092 TRACE("No force feedback support\n");
1093 return DIERR_UNSUPPORTED
;
1096 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1097 TRACE("not available (compiled w/o force feedback support)\n");
1098 return DIERR_UNSUPPORTED
;
1101 if (!(new_effect
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect
))))
1102 return DIERR_OUTOFMEMORY
;
1104 retval
= linuxinput_create_effect(&This
->joyfd
, rguid
, &new_effect
->entry
, &new_effect
->ref
);
1105 if (retval
!= DI_OK
)
1107 HeapFree(GetProcessHeap(), 0, new_effect
);
1113 retval
= IDirectInputEffect_SetParameters(new_effect
->ref
, lpeff
, 0);
1115 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1117 HeapFree(GetProcessHeap(), 0, new_effect
);
1122 list_add_tail(&This
->ff_effects
, &new_effect
->entry
);
1123 *ppdef
= new_effect
->ref
;
1125 if (pUnkOuter
!= NULL
)
1126 FIXME("Interface aggregation not implemented.\n");
1130 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1133 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
,
1134 LPCDIEFFECT lpeff
, LPDIRECTINPUTEFFECT
*ppdef
,
1135 LPUNKNOWN pUnkOuter
)
1137 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1138 return JoystickWImpl_CreateEffect(IDirectInputDevice8W_from_impl(This
), rguid
, lpeff
, ppdef
, pUnkOuter
);
1141 /*******************************************************************************
1142 * EnumEffects - Enumerate available FF effects
1144 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1145 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1149 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1150 DIEFFECTINFOA dei
; /* feif */
1151 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1152 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1154 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
1156 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
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
);
1218 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1219 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1223 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1224 /* seems silly to duplicate all this code but all the structures and functions
1225 * are actually different (A/W) */
1226 DIEFFECTINFOW dei
; /* feif */
1227 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1228 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1229 int xfd
= This
->joyfd
;
1231 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1233 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1235 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1236 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1237 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1238 (*lpCallback
)(&dei
, pvRef
);
1241 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1242 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1243 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1244 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1245 (*lpCallback
)(&dei
, pvRef
);
1247 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1248 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1249 (*lpCallback
)(&dei
, pvRef
);
1251 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1252 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1253 (*lpCallback
)(&dei
, pvRef
);
1255 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1256 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1257 (*lpCallback
)(&dei
, pvRef
);
1259 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1260 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1261 (*lpCallback
)(&dei
, pvRef
);
1265 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1266 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1267 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1268 (*lpCallback
)(&dei
, pvRef
);
1271 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1272 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1273 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1274 (*lpCallback
)(&dei
, pvRef
);
1276 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1277 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1278 (*lpCallback
)(&dei
, pvRef
);
1280 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1281 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1282 (*lpCallback
)(&dei
, pvRef
);
1284 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1285 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1286 (*lpCallback
)(&dei
, pvRef
);
1290 /* return to unacquired state if that's where it was */
1292 IDirectInputDevice8_Unacquire(iface
);
1298 /*******************************************************************************
1299 * GetEffectInfo - Get information about a particular effect
1301 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1302 LPDIEFFECTINFOA pdei
,
1305 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1307 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1309 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1310 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1316 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1317 LPDIEFFECTINFOW pdei
,
1320 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1322 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1324 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1325 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1331 /*******************************************************************************
1332 * GetForceFeedbackState - Get information about the device's FF state
1334 static HRESULT WINAPI
JoystickWImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface
, LPDWORD pdwOut
)
1336 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1338 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1342 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1343 /* DIGFFS_STOPPED is the only mandatory flag to report */
1344 if (This
->ff_state
== FF_STATUS_STOPPED
)
1345 (*pdwOut
) |= DIGFFS_STOPPED
;
1351 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8A iface
, LPDWORD pdwOut
)
1353 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1354 return JoystickWImpl_GetForceFeedbackState(IDirectInputDevice8W_from_impl(This
), pdwOut
);
1357 /*******************************************************************************
1358 * SendForceFeedbackCommand - Send a command to the device's FF system
1360 static HRESULT WINAPI
JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface
, DWORD dwFlags
)
1362 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1363 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1365 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1368 case DISFFC_STOPALL
:
1370 effect_list_item
*itr
;
1372 /* Stop all effects */
1373 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1374 IDirectInputEffect_Stop(itr
->ref
);
1380 effect_list_item
*itr
;
1382 /* Stop and unload all effects. It is not true that effects are released */
1383 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1385 IDirectInputEffect_Stop(itr
->ref
);
1386 IDirectInputEffect_Unload(itr
->ref
);
1391 case DISFFC_CONTINUE
:
1392 FIXME("No support for Pause or Continue in linux\n");
1395 case DISFFC_SETACTUATORSOFF
:
1396 case DISFFC_SETACTUATORSON
:
1397 FIXME("No direct actuator control in linux\n");
1401 WARN("Unknown Force Feedback Command %u!\n", dwFlags
);
1402 return DIERR_INVALIDPARAM
;
1406 return DIERR_UNSUPPORTED
;
1410 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8A iface
, DWORD dwFlags
)
1412 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1413 return JoystickWImpl_SendForceFeedbackCommand(IDirectInputDevice8W_from_impl(This
), dwFlags
);
1416 /*******************************************************************************
1417 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1418 * created for this device.
1420 static HRESULT WINAPI
JoystickWImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface
,
1421 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1422 LPVOID pvRef
, DWORD dwFlags
)
1424 /* this function is safe to call on non-ff-enabled builds */
1425 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1426 effect_list_item
*itr
, *ptr
;
1428 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1431 return DIERR_INVALIDPARAM
;
1434 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1436 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1437 (*lpCallback
)(itr
->ref
, pvRef
);
1442 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8A iface
,
1443 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1444 LPVOID pvRef
, DWORD dwFlags
)
1446 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1447 return JoystickWImpl_EnumCreatedEffectObjects(IDirectInputDevice8W_from_impl(This
), lpCallback
, pvRef
, dwFlags
);
1450 /******************************************************************************
1451 * GetDeviceInfo : get information about a device's identity
1453 static HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface
,
1454 LPDIDEVICEINSTANCEA pdidi
)
1456 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1458 TRACE("(%p) %p\n", This
, pdidi
);
1460 if (pdidi
== NULL
) return E_POINTER
;
1461 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1462 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)))
1463 return DIERR_INVALIDPARAM
;
1465 fill_joystick_dideviceinstanceA(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1466 get_joystick_index(&This
->generic
.base
.guid
));
1470 static HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
,
1471 LPDIDEVICEINSTANCEW pdidi
)
1473 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
1475 TRACE("(%p) %p\n", This
, pdidi
);
1477 if (pdidi
== NULL
) return E_POINTER
;
1478 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1479 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)))
1480 return DIERR_INVALIDPARAM
;
1482 fill_joystick_dideviceinstanceW(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1483 get_joystick_index(&This
->generic
.base
.guid
));
1487 static const IDirectInputDevice8AVtbl JoystickAvt
=
1489 IDirectInputDevice2AImpl_QueryInterface
,
1490 IDirectInputDevice2AImpl_AddRef
,
1491 IDirectInputDevice2AImpl_Release
,
1492 JoystickAGenericImpl_GetCapabilities
,
1493 IDirectInputDevice2AImpl_EnumObjects
,
1494 JoystickAImpl_GetProperty
,
1495 JoystickAImpl_SetProperty
,
1496 JoystickAImpl_Acquire
,
1497 JoystickAImpl_Unacquire
,
1498 JoystickAGenericImpl_GetDeviceState
,
1499 IDirectInputDevice2AImpl_GetDeviceData
,
1500 IDirectInputDevice2AImpl_SetDataFormat
,
1501 IDirectInputDevice2AImpl_SetEventNotification
,
1502 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1503 JoystickAGenericImpl_GetObjectInfo
,
1504 JoystickAImpl_GetDeviceInfo
,
1505 IDirectInputDevice2AImpl_RunControlPanel
,
1506 IDirectInputDevice2AImpl_Initialize
,
1507 JoystickAImpl_CreateEffect
,
1508 JoystickAImpl_EnumEffects
,
1509 JoystickAImpl_GetEffectInfo
,
1510 JoystickAImpl_GetForceFeedbackState
,
1511 JoystickAImpl_SendForceFeedbackCommand
,
1512 JoystickAImpl_EnumCreatedEffectObjects
,
1513 IDirectInputDevice2AImpl_Escape
,
1514 JoystickAGenericImpl_Poll
,
1515 IDirectInputDevice2AImpl_SendDeviceData
,
1516 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1517 IDirectInputDevice7AImpl_WriteEffectToFile
,
1518 JoystickAGenericImpl_BuildActionMap
,
1519 JoystickAGenericImpl_SetActionMap
,
1520 IDirectInputDevice8AImpl_GetImageInfo
1523 static const IDirectInputDevice8WVtbl JoystickWvt
=
1525 IDirectInputDevice2WImpl_QueryInterface
,
1526 IDirectInputDevice2WImpl_AddRef
,
1527 IDirectInputDevice2WImpl_Release
,
1528 JoystickWGenericImpl_GetCapabilities
,
1529 IDirectInputDevice2WImpl_EnumObjects
,
1530 JoystickWImpl_GetProperty
,
1531 JoystickWImpl_SetProperty
,
1532 JoystickWImpl_Acquire
,
1533 JoystickWImpl_Unacquire
,
1534 JoystickWGenericImpl_GetDeviceState
,
1535 IDirectInputDevice2WImpl_GetDeviceData
,
1536 IDirectInputDevice2WImpl_SetDataFormat
,
1537 IDirectInputDevice2WImpl_SetEventNotification
,
1538 IDirectInputDevice2WImpl_SetCooperativeLevel
,
1539 JoystickWGenericImpl_GetObjectInfo
,
1540 JoystickWImpl_GetDeviceInfo
,
1541 IDirectInputDevice2WImpl_RunControlPanel
,
1542 IDirectInputDevice2WImpl_Initialize
,
1543 JoystickWImpl_CreateEffect
,
1544 JoystickWImpl_EnumEffects
,
1545 JoystickWImpl_GetEffectInfo
,
1546 JoystickWImpl_GetForceFeedbackState
,
1547 JoystickWImpl_SendForceFeedbackCommand
,
1548 JoystickWImpl_EnumCreatedEffectObjects
,
1549 IDirectInputDevice2WImpl_Escape
,
1550 JoystickWGenericImpl_Poll
,
1551 IDirectInputDevice2WImpl_SendDeviceData
,
1552 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1553 IDirectInputDevice7WImpl_WriteEffectToFile
,
1554 JoystickWGenericImpl_BuildActionMap
,
1555 JoystickWGenericImpl_SetActionMap
,
1556 IDirectInputDevice8WImpl_GetImageInfo
1559 #else /* HAS_PROPER_HEADER */
1561 const struct dinput_device joystick_linuxinput_device
= {
1562 "Wine Linux-input joystick driver",
1568 #endif /* HAS_PROPER_HEADER */