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 IDirectInputDevice8WVtbl JoystickWvt
;
103 BOOL has_ff
, is_joystick
;
106 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
107 BYTE evbits
[(EV_MAX
+7)/8];
108 BYTE absbits
[(ABS_MAX
+7)/8];
109 BYTE keybits
[(KEY_MAX
+7)/8];
110 BYTE ffbits
[(FF_MAX
+7)/8];
112 /* data returned by the EVIOCGABS() ioctl */
113 struct wine_input_absinfo axes
[ABS_MAX
];
115 WORD vendor_id
, product_id
, bus_type
;
120 struct JoystickGenericImpl generic
;
121 struct JoyDev
*joydev
;
123 /* joystick private */
126 int dev_axes_to_di
[ABS_MAX
];
129 /* LUT for KEY_ to offset in rgbButtons */
130 BYTE buttons
[KEY_MAX
];
132 /* Force feedback variables */
133 struct list ff_effects
;
139 static inline JoystickImpl
*impl_from_IDirectInputDevice8W(IDirectInputDevice8W
*iface
)
141 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8W_iface
),
142 JoystickGenericImpl
, base
), JoystickImpl
, generic
);
145 static void fake_current_js_state(JoystickImpl
*ji
);
146 static void find_joydevs(void);
147 static void joy_polldev( IDirectInputDevice8W
*iface
);
149 /* This GUID is slightly different from the linux joystick one. Take note. */
150 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
154 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
157 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
159 #define MAX_JOYDEV 64
161 static int have_joydevs
= -1;
162 static struct JoyDev
*joydevs
= NULL
;
164 static void find_joydevs(void)
168 if (InterlockedCompareExchange(&have_joydevs
, 0, -1) != -1)
169 /* Someone beat us to it */
172 for (i
= 0; i
< MAX_JOYDEV
; i
++)
175 struct JoyDev joydev
= {0};
177 BOOL no_ff_check
= FALSE
;
179 struct JoyDev
*new_joydevs
;
180 struct input_id device_id
= {0};
182 snprintf(buf
, sizeof(buf
), EVDEVPREFIX
"%d", i
);
184 if ((fd
= open(buf
, O_RDWR
)) == -1)
186 fd
= open(buf
, O_RDONLY
);
193 if (ioctl(fd
, EVIOCGBIT(0, sizeof(joydev
.evbits
)), joydev
.evbits
) == -1)
195 WARN("ioctl(EVIOCGBIT, 0) failed: %d %s\n", errno
, strerror(errno
));
199 if (ioctl(fd
, EVIOCGBIT(EV_ABS
, sizeof(joydev
.absbits
)), joydev
.absbits
) == -1)
201 WARN("ioctl(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
205 if (ioctl(fd
, EVIOCGBIT(EV_KEY
, sizeof(joydev
.keybits
)), joydev
.keybits
) == -1)
207 WARN("ioctl(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno
, strerror(errno
));
212 /* A true joystick has at least axis X and Y, and at least 1
213 * button. copied from linux/drivers/input/joydev.c */
214 if (((!test_bit(joydev
.absbits
, ABS_X
) || !test_bit(joydev
.absbits
, ABS_Y
)) &&
215 !test_bit(joydev
.absbits
, ABS_WHEEL
) &&
216 !test_bit(joydev
.absbits
, ABS_GAS
) &&
217 !test_bit(joydev
.absbits
, ABS_BRAKE
)) ||
218 !(test_bit(joydev
.keybits
, BTN_TRIGGER
) ||
219 test_bit(joydev
.keybits
, BTN_A
) ||
220 test_bit(joydev
.keybits
, BTN_1
) ||
221 test_bit(joydev
.keybits
, BTN_BASE
) ||
222 test_bit(joydev
.keybits
, BTN_GEAR_UP
) ||
223 test_bit(joydev
.keybits
, BTN_GEAR_DOWN
)))
229 /* in lieu of properly reporting HID usage, detect presence of
230 * "joystick buttons" and report those devices as joysticks instead of
233 test_bit(joydev
.keybits
, BTN_TRIGGER
) ||
234 test_bit(joydev
.keybits
, BTN_THUMB
) ||
235 test_bit(joydev
.keybits
, BTN_THUMB2
) ||
236 test_bit(joydev
.keybits
, BTN_TOP
) ||
237 test_bit(joydev
.keybits
, BTN_TOP2
) ||
238 test_bit(joydev
.keybits
, BTN_PINKIE
) ||
239 test_bit(joydev
.keybits
, BTN_BASE
) ||
240 test_bit(joydev
.keybits
, BTN_BASE2
) ||
241 test_bit(joydev
.keybits
, BTN_BASE3
) ||
242 test_bit(joydev
.keybits
, BTN_BASE4
) ||
243 test_bit(joydev
.keybits
, BTN_BASE5
) ||
244 test_bit(joydev
.keybits
, BTN_BASE6
) ||
245 test_bit(joydev
.keybits
, BTN_GEAR_UP
) ||
246 test_bit(joydev
.keybits
, BTN_GEAR_DOWN
) ||
247 test_bit(joydev
.keybits
, BTN_DEAD
);
249 if (!(joydev
.device
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
254 strcpy(joydev
.device
, buf
);
256 buf
[MAX_PATH
- 1] = 0;
257 if (ioctl(fd
, EVIOCGNAME(MAX_PATH
- 1), buf
) != -1 &&
258 (joydev
.name
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + strlen(EVDEVDRIVER
) + 1)))
260 strcpy(joydev
.name
, buf
);
261 /* Append driver name */
262 strcat(joydev
.name
, EVDEVDRIVER
);
265 joydev
.name
= joydev
.device
;
267 if (device_disabled_registry(joydev
.name
)) {
269 HeapFree(GetProcessHeap(), 0, joydev
.name
);
270 if (joydev
.name
!= joydev
.device
)
271 HeapFree(GetProcessHeap(), 0, joydev
.device
);
275 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
276 joydev
.guid
.Data3
+= have_joydevs
;
278 TRACE("Found a joystick on %s: %s (%s)\n",
279 joydev
.device
, joydev
.name
,
280 debugstr_guid(&joydev
.guid
)
283 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
285 test_bit(joydev
.evbits
, EV_FF
) &&
286 ioctl(fd
, EVIOCGBIT(EV_FF
, sizeof(joydev
.ffbits
)), joydev
.ffbits
) != -1 &&
287 ioctl(fd
, EVIOCGEFFECTS
, &joydev
.num_effects
) != -1 &&
288 joydev
.num_effects
> 0)
290 TRACE(" ... with force feedback\n");
291 joydev
.has_ff
= TRUE
;
295 for (j
= 0; j
< ABS_MAX
;j
++)
297 if (!test_bit(joydev
.absbits
, j
)) continue;
298 if (ioctl(fd
, EVIOCGABS(j
), &(joydev
.axes
[j
])) != -1)
300 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
302 joydev
.axes
[j
].value
,
303 joydev
.axes
[j
].minimum
,
304 joydev
.axes
[j
].maximum
,
311 if (ioctl(fd
, EVIOCGID
, &device_id
) == -1)
313 WARN("ioctl(EVIOCGID) failed: %d %s\n", errno
, strerror(errno
));
314 joydev
.guid_product
= DInput_Wine_Joystick_Base_GUID
;
318 joydev
.vendor_id
= device_id
.vendor
;
319 joydev
.product_id
= device_id
.product
;
320 joydev
.bus_type
= device_id
.bustype
;
322 /* Concatenate product_id with vendor_id to mimic Windows behaviour */
323 joydev
.guid_product
= DInput_PIDVID_Product_GUID
;
324 joydev
.guid_product
.Data1
= MAKELONG(joydev
.vendor_id
, joydev
.product_id
);
328 new_joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
330 new_joydevs
= HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1 + have_joydevs
) * sizeof(struct JoyDev
));
337 joydevs
= new_joydevs
;
338 joydevs
[have_joydevs
] = joydev
;
345 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
347 DWORD dwSize
= lpddi
->dwSize
;
349 TRACE("%d %p\n", dwSize
, lpddi
);
350 memset(lpddi
, 0, dwSize
);
352 lpddi
->dwSize
= dwSize
;
353 lpddi
->guidInstance
= joydevs
[id
].guid
;
354 lpddi
->guidProduct
= joydevs
[id
].guid_product
;
355 lpddi
->guidFFDriver
= GUID_NULL
;
356 lpddi
->dwDevType
= get_device_type(version
, joydevs
[id
].is_joystick
);
358 /* Assume the joystick as HID if it is attached to USB bus and has a valid VID/PID */
359 if (joydevs
[id
].bus_type
== BUS_USB
&&
360 joydevs
[id
].vendor_id
&& joydevs
[id
].product_id
)
362 lpddi
->dwDevType
|= DIDEVTYPE_HID
;
363 lpddi
->wUsagePage
= 0x01; /* Desktop */
364 if (joydevs
[id
].is_joystick
)
365 lpddi
->wUsage
= 0x04; /* Joystick */
367 lpddi
->wUsage
= 0x05; /* Game Pad */
370 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
371 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszProductName
, MAX_PATH
);
374 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
376 DIDEVICEINSTANCEW lpddiW
;
377 DWORD dwSize
= lpddi
->dwSize
;
379 lpddiW
.dwSize
= sizeof(lpddiW
);
380 fill_joystick_dideviceinstanceW(&lpddiW
, version
, id
);
382 TRACE("%d %p\n", dwSize
, lpddi
);
383 memset(lpddi
, 0, dwSize
);
386 lpddi
->dwSize
= dwSize
;
387 lpddi
->guidInstance
= lpddiW
.guidInstance
;
388 lpddi
->guidProduct
= lpddiW
.guidProduct
;
389 lpddi
->dwDevType
= lpddiW
.dwDevType
;
390 lstrcpynA(lpddi
->tszInstanceName
, joydevs
[id
].name
, MAX_PATH
);
391 lstrcpynA(lpddi
->tszProductName
, joydevs
[id
].name
, MAX_PATH
);
392 lpddi
->guidFFDriver
= lpddiW
.guidFFDriver
;
393 lpddi
->wUsagePage
= lpddiW
.wUsagePage
;
394 lpddi
->wUsage
= lpddiW
.wUsage
;
397 static HRESULT
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
401 if (id
>= have_joydevs
) {
405 if (!((dwDevType
== 0) ||
406 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
>= 0x0300 && version
< 0x0800)) ||
407 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
410 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
411 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
415 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
416 fill_joystick_dideviceinstanceA(lpddi
, version
, id
);
422 static HRESULT
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
426 if (id
>= have_joydevs
) {
430 if (!((dwDevType
== 0) ||
431 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
>= 0x0300 && version
< 0x0800)) ||
432 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
435 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
436 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
440 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
441 fill_joystick_dideviceinstanceW(lpddi
, version
, id
);
447 static HRESULT
alloc_device( REFGUID rguid
, IDirectInputImpl
*dinput
, JoystickImpl
**out
, unsigned short index
)
449 JoystickImpl
* newDevice
;
450 LPDIDATAFORMAT df
= NULL
;
452 int default_axis_map
[WINE_JOYSTICK_MAX_AXES
+ WINE_JOYSTICK_MAX_POVS
*2];
453 DIDEVICEINSTANCEW ddi
;
456 if (FAILED(hr
= direct_input_device_alloc( sizeof(JoystickImpl
), &JoystickWvt
, rguid
, dinput
, (void **)&newDevice
)))
458 newDevice
->generic
.base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
460 newDevice
->generic
.joy_polldev
= joy_polldev
;
461 newDevice
->joyfd
= -1;
462 newDevice
->joydev
= &joydevs
[index
];
463 newDevice
->generic
.name
= newDevice
->joydev
->name
;
464 list_init(&newDevice
->ff_effects
);
465 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
466 newDevice
->ff_state
= FF_STATUS_STOPPED
;
468 /* There is no way in linux to query force feedback autocenter status.
469 Instead, track it with ff_autocenter, and assume it's initially
471 newDevice
->ff_autocenter
= 1;
472 newDevice
->ff_gain
= 0xFFFF;
474 /* Count number of available axes - supported Axis & POVs */
475 for (i
= 0; i
< ABS_MAX
; i
++)
477 if (idx
< WINE_JOYSTICK_MAX_AXES
&&
479 test_bit(newDevice
->joydev
->absbits
, i
))
481 newDevice
->generic
.device_axis_count
++;
482 newDevice
->dev_axes_to_di
[i
] = idx
;
483 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[i
].minimum
;
484 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[i
].maximum
;
485 if (i
>= 8 && i
<= 10) /* If it's a wheel axis... */
486 default_axis_map
[idx
] = i
- 8; /* ... remap to X/Y/Z */
488 default_axis_map
[idx
] = i
;
492 newDevice
->dev_axes_to_di
[i
] = -1;
495 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
497 if (test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) &&
498 test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2))
500 newDevice
->generic
.device_axis_count
+= 2;
501 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].minimum
;
502 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].maximum
;
503 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = idx
;
504 newDevice
->generic
.props
[idx
+1].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].minimum
;
505 newDevice
->generic
.props
[idx
+1].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].maximum
;
506 newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = idx
+ 1;
508 default_axis_map
[idx
] = default_axis_map
[idx
+ 1] = WINE_JOYSTICK_MAX_AXES
+ i
;
512 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = -1;
515 /* do any user specified configuration */
516 if (setup_dinput_options(&newDevice
->generic
, default_axis_map
) != DI_OK
) goto failed
;
518 /* Create copy of default data format */
519 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
520 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
521 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
524 /* Construct internal data format */
526 /* Supported Axis & POVs */
527 for (i
= 0, idx
= 0; i
< newDevice
->generic
.device_axis_count
; i
++)
529 int wine_obj
= newDevice
->generic
.axis_map
[i
];
531 if (wine_obj
< 0) continue;
533 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[wine_obj
], df
->dwObjSize
);
535 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
) | DIDFT_ABSAXIS
;
538 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
- 8) | DIDFT_POV
;
539 i
++; /* POV takes 2 axes */
542 newDevice
->generic
.props
[idx
].lMin
= 0;
543 newDevice
->generic
.props
[idx
].lMax
= 0xffff;
544 newDevice
->generic
.props
[idx
].lSaturation
= 0;
545 newDevice
->generic
.props
[idx
].lDeadZone
= newDevice
->generic
.deadzone
;
547 /* Linux supports force-feedback on X & Y axes only */
548 if (newDevice
->joydev
->has_ff
&& (i
== 0 || i
== 1))
549 df
->rgodf
[idx
].dwFlags
|= DIDOI_FFACTUATOR
;
554 /* Buttons can be anywhere, so check all */
555 for (i
= 0; i
< KEY_MAX
&& newDevice
->generic
.devcaps
.dwButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
557 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
559 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->generic
.devcaps
.dwButtons
+ 12], df
->dwObjSize
);
560 newDevice
->buttons
[i
] = 0x80 | newDevice
->generic
.devcaps
.dwButtons
;
561 df
->rgodf
[idx
].pguid
= &GUID_Button
;
562 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->generic
.devcaps
.dwButtons
++) | DIDFT_PSHBUTTON
;
565 newDevice
->generic
.base
.data_format
.wine_df
= df
;
567 fake_current_js_state(newDevice
);
570 newDevice
->generic
.devcaps
.dwSize
= sizeof(newDevice
->generic
.devcaps
);
571 newDevice
->generic
.devcaps
.dwFlags
= DIDC_ATTACHED
;
573 ddi
.dwSize
= sizeof(ddi
);
574 fill_joystick_dideviceinstanceW(&ddi
, newDevice
->generic
.base
.dinput
->dwVersion
, index
);
575 newDevice
->generic
.devcaps
.dwDevType
= ddi
.dwDevType
;
577 if (newDevice
->joydev
->has_ff
)
578 newDevice
->generic
.devcaps
.dwFlags
|= DIDC_FORCEFEEDBACK
;
584 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
585 HeapFree(GetProcessHeap(), 0, df
);
586 HeapFree(GetProcessHeap(), 0, newDevice
->generic
.axis_map
);
587 HeapFree(GetProcessHeap(), 0, newDevice
);
588 return DIERR_OUTOFMEMORY
;
591 /******************************************************************************
592 * get_joystick_index : Get the joystick index from a given GUID
594 static unsigned short get_joystick_index(REFGUID guid
)
596 GUID wine_joystick
= DInput_Wine_Joystick_Base_GUID
;
597 GUID dev_guid
= *guid
;
600 wine_joystick
.Data3
= 0;
603 /* for the standard joystick GUID use index 0 */
604 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
606 /* for the wine joystick GUIDs use the index stored in Data3 */
607 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
- DInput_Wine_Joystick_Base_GUID
.Data3
;
609 for(i
= 0; i
< have_joydevs
; i
++)
610 if(IsEqualGUID(&joydevs
[i
].guid_product
, guid
)) return i
;
615 static HRESULT
joydev_create_device(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPVOID
*pdev
, int unicode
)
617 unsigned short index
;
619 TRACE("%p %s %s %p %i\n", dinput
, debugstr_guid(rguid
), debugstr_guid(riid
), pdev
, unicode
);
623 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
624 have_joydevs
&& index
< have_joydevs
)
631 else if (IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
632 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
633 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
634 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
638 else if (IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
639 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
640 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
641 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
647 WARN("no interface\n");
648 return DIERR_NOINTERFACE
;
651 if (FAILED(hr
= alloc_device( rguid
, dinput
, &This
, index
))) return hr
;
653 TRACE( "Created a Joystick device (%p)\n", This
);
656 *pdev
= &This
->generic
.base
.IDirectInputDevice8W_iface
;
658 *pdev
= &This
->generic
.base
.IDirectInputDevice8A_iface
;
663 return DIERR_DEVICENOTREG
;
667 const struct dinput_device joystick_linuxinput_device
= {
668 "Wine Linux-input joystick driver",
674 /******************************************************************************
675 * Acquire : gets exclusive control of the joystick
677 static HRESULT WINAPI
JoystickWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface
)
679 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
682 TRACE("(this=%p)\n",This
);
684 if ((res
= IDirectInputDevice2WImpl_Acquire(iface
)) != DI_OK
)
686 WARN("Failed to acquire: %x\n", res
);
690 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDWR
)) == -1)
692 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDONLY
)) == -1)
694 /* Couldn't open the device at all */
695 ERR("Failed to open device %s: %d %s\n", This
->joydev
->device
, errno
, strerror(errno
));
696 IDirectInputDevice2WImpl_Unacquire(iface
);
697 return DIERR_NOTFOUND
;
701 /* Couldn't open in r/w but opened in read-only. */
702 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
707 struct input_event event
;
710 event
.code
= FF_GAIN
;
711 event
.value
= This
->ff_gain
;
712 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
713 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
714 if (!This
->ff_autocenter
)
716 /* Disable autocenter. */
717 event
.code
= FF_AUTOCENTER
;
719 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
720 ERR("Failed disabling autocenter: %d %s\n", errno
, strerror(errno
));
727 /******************************************************************************
728 * Unacquire : frees the joystick
730 static HRESULT WINAPI
JoystickWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface
)
732 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
735 TRACE("(this=%p)\n",This
);
736 res
= IDirectInputDevice2WImpl_Unacquire(iface
);
737 if (res
==DI_OK
&& This
->joyfd
!=-1) {
738 struct input_event event
;
740 /* Stop and unload all effects */
741 JoystickWImpl_SendForceFeedbackCommand(iface
, DISFFC_RESET
);
743 /* Enable autocenter. */
745 event
.code
= FF_AUTOCENTER
;
746 /* TODO: Read autocenter strength before disabling it, and use it here
747 * instead of 0xFFFF (maximum strength).
749 event
.value
= 0xFFFF;
750 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
751 ERR("Failed to set autocenter to %04x: %d %s\n", event
.value
, errno
, strerror(errno
));
760 * set the current state of the js device as it would be with the middle
763 #define CENTER_AXIS(a) \
764 (ji->dev_axes_to_di[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->dev_axes_to_di[a]], \
765 ji->joydev->axes[a].value ))
766 static void fake_current_js_state(JoystickImpl
*ji
)
770 /* center the axes */
771 ji
->generic
.js
.lX
= CENTER_AXIS(ABS_X
);
772 ji
->generic
.js
.lY
= CENTER_AXIS(ABS_Y
);
773 ji
->generic
.js
.lZ
= CENTER_AXIS(ABS_Z
);
774 ji
->generic
.js
.lRx
= CENTER_AXIS(ABS_RX
);
775 ji
->generic
.js
.lRy
= CENTER_AXIS(ABS_RY
);
776 ji
->generic
.js
.lRz
= CENTER_AXIS(ABS_RZ
);
777 ji
->generic
.js
.rglSlider
[0] = CENTER_AXIS(ABS_THROTTLE
);
778 ji
->generic
.js
.rglSlider
[1] = CENTER_AXIS(ABS_RUDDER
);
780 /* POV center is -1 */
781 for (i
= 0; i
< 4; i
++)
782 ji
->generic
.js
.rgdwPOV
[i
] = -1;
786 /* convert wine format offset to user format object index */
787 static void joy_polldev( IDirectInputDevice8W
*iface
)
790 struct input_event ie
;
791 JoystickImpl
*This
= impl_from_IDirectInputDevice8W( iface
);
801 plfd
.fd
= This
->joyfd
;
802 plfd
.events
= POLLIN
;
804 if (poll(&plfd
,1,0) != 1)
807 /* we have one event, so we can read */
808 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
811 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
813 case EV_KEY
: /* button */
815 int btn
= This
->buttons
[ie
.code
];
817 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
821 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
822 This
->generic
.js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
828 int axis
= This
->dev_axes_to_di
[ie
.code
];
830 /* User axis remapping */
832 axis
= This
->generic
.axis_map
[axis
];
835 inst_id
= axis
< 8 ? DIDFT_MAKEINSTANCE(axis
) | DIDFT_ABSAXIS
:
836 DIDFT_MAKEINSTANCE(axis
- 8) | DIDFT_POV
;
837 value
= joystick_map_axis(&This
->generic
.props
[id_to_object(This
->generic
.base
.data_format
.wine_df
, inst_id
)], ie
.value
);
840 case 0: This
->generic
.js
.lX
= value
; break;
841 case 1: This
->generic
.js
.lY
= value
; break;
842 case 2: This
->generic
.js
.lZ
= value
; break;
843 case 3: This
->generic
.js
.lRx
= value
; break;
844 case 4: This
->generic
.js
.lRy
= value
; break;
845 case 5: This
->generic
.js
.lRz
= value
; break;
846 case 6: This
->generic
.js
.rglSlider
[0] = value
; break;
847 case 7: This
->generic
.js
.rglSlider
[1] = value
; break;
848 case 8: case 9: case 10: case 11:
853 This
->povs
[idx
].y
= ie
.value
;
855 This
->povs
[idx
].x
= ie
.value
;
857 This
->generic
.js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
861 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
865 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
867 This
->ff_state
= ie
.value
;
872 /* there is nothing to do */
881 TRACE("skipping event\n");
885 queue_event(iface
, inst_id
,
886 value
, GetCurrentTime(), This
->generic
.base
.dinput
->evsequence
++);
890 /******************************************************************************
891 * SetProperty : change input device properties
893 static HRESULT WINAPI
JoystickWImpl_SetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPCDIPROPHEADER ph
)
895 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
898 WARN("invalid argument\n");
899 return DIERR_INVALIDPARAM
;
902 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
903 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
904 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
906 if (IS_DIPROP(rguid
)) {
907 switch (LOWORD(rguid
)) {
908 case (DWORD_PTR
)DIPROP_AUTOCENTER
: {
909 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
911 TRACE("autocenter(%d)\n", pd
->dwData
);
912 This
->ff_autocenter
= pd
->dwData
== DIPROPAUTOCENTER_ON
;
916 case (DWORD_PTR
)DIPROP_FFGAIN
: {
917 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
919 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
920 This
->ff_gain
= MulDiv(pd
->dwData
, 0xFFFF, 10000);
921 if (This
->generic
.base
.acquired
) {
922 /* Update immediately. */
923 struct input_event event
;
926 event
.code
= FF_GAIN
;
927 event
.value
= This
->ff_gain
;
928 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
929 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
934 return JoystickWGenericImpl_SetProperty(iface
, rguid
, ph
);
940 /******************************************************************************
941 * GetProperty : get input device properties
943 static HRESULT WINAPI
JoystickWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
945 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
947 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(rguid
), pdiph
);
948 _dump_DIPROPHEADER(pdiph
);
950 if (!IS_DIPROP(rguid
)) return DI_OK
;
952 switch (LOWORD(rguid
)) {
953 case (DWORD_PTR
) DIPROP_AUTOCENTER
:
955 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
957 pd
->dwData
= This
->ff_autocenter
? DIPROPAUTOCENTER_ON
: DIPROPAUTOCENTER_OFF
;
958 TRACE("autocenter(%d)\n", pd
->dwData
);
961 case (DWORD_PTR
) DIPROP_FFGAIN
:
963 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
965 pd
->dwData
= MulDiv(This
->ff_gain
, 10000, 0xFFFF);
966 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
970 case (DWORD_PTR
) DIPROP_VIDPID
:
972 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
974 if (!This
->joydev
->product_id
|| !This
->joydev
->vendor_id
)
975 return DIERR_UNSUPPORTED
;
976 pd
->dwData
= MAKELONG(This
->joydev
->vendor_id
, This
->joydev
->product_id
);
977 TRACE("DIPROP_VIDPID(%08x)\n", pd
->dwData
);
981 case (DWORD_PTR
) DIPROP_JOYSTICKID
:
983 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
985 pd
->dwData
= get_joystick_index(&This
->generic
.base
.guid
);
986 TRACE("DIPROP_JOYSTICKID(%d)\n", pd
->dwData
);
990 case (DWORD_PTR
) DIPROP_GUIDANDPATH
:
992 static const WCHAR formatW
[] = {'\\','\\','?','\\','h','i','d','#','v','i','d','_','%','0','4','x','&',
993 'p','i','d','_','%','0','4','x','&','%','s','_','%','h','u',0};
994 static const WCHAR miW
[] = {'m','i',0};
995 static const WCHAR igW
[] = {'i','g',0};
998 LPDIPROPGUIDANDPATH pd
= (LPDIPROPGUIDANDPATH
)pdiph
;
999 WORD vid
= This
->joydev
->vendor_id
;
1000 WORD pid
= This
->joydev
->product_id
;
1003 return DIERR_UNSUPPORTED
;
1005 is_gamepad
= is_xinput_device(&This
->generic
.devcaps
, vid
, pid
);
1006 pd
->guidClass
= GUID_DEVCLASS_HIDCLASS
;
1007 sprintfW(pd
->wszPath
, formatW
, vid
, pid
, is_gamepad
? igW
: miW
, get_joystick_index(&This
->generic
.base
.guid
));
1009 TRACE("DIPROP_GUIDANDPATH(%s, %s): returning fake path\n", debugstr_guid(&pd
->guidClass
), debugstr_w(pd
->wszPath
));
1014 return JoystickWGenericImpl_GetProperty(iface
, rguid
, pdiph
);
1020 /******************************************************************************
1021 * CreateEffect - Create a new FF effect with the specified params
1023 static HRESULT WINAPI
JoystickWImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
,
1024 LPCDIEFFECT lpeff
, LPDIRECTINPUTEFFECT
*ppdef
,
1025 LPUNKNOWN pUnkOuter
)
1027 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1028 effect_list_item
* new_effect
= NULL
;
1029 HRESULT retval
= DI_OK
;
1032 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1033 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
1036 if (!This
->joydev
->has_ff
)
1038 TRACE("No force feedback support\n");
1039 return DIERR_UNSUPPORTED
;
1042 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1043 TRACE("not available (compiled w/o force feedback support)\n");
1044 return DIERR_UNSUPPORTED
;
1047 if (!(new_effect
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect
))))
1048 return DIERR_OUTOFMEMORY
;
1050 retval
= linuxinput_create_effect(&This
->joyfd
, rguid
, &new_effect
->entry
, &new_effect
->ref
);
1051 if (retval
!= DI_OK
)
1053 HeapFree(GetProcessHeap(), 0, new_effect
);
1059 retval
= IDirectInputEffect_SetParameters(new_effect
->ref
, lpeff
,
1060 DIEP_AXES
| DIEP_DIRECTION
| DIEP_DURATION
| DIEP_ENVELOPE
|
1061 DIEP_GAIN
| DIEP_SAMPLEPERIOD
| DIEP_STARTDELAY
| DIEP_TRIGGERBUTTON
|
1062 DIEP_TRIGGERREPEATINTERVAL
| DIEP_TYPESPECIFICPARAMS
);
1064 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1066 HeapFree(GetProcessHeap(), 0, new_effect
);
1071 list_add_tail(&This
->ff_effects
, &new_effect
->entry
);
1072 *ppdef
= new_effect
->ref
;
1074 if (pUnkOuter
!= NULL
)
1075 FIXME("Interface aggregation not implemented.\n");
1079 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1082 /*******************************************************************************
1083 * EnumEffects - Enumerate available FF effects
1085 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1086 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1090 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1091 /* seems silly to duplicate all this code but all the structures and functions
1092 * are actually different (A/W) */
1093 DIEFFECTINFOW dei
; /* feif */
1094 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1095 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1096 int xfd
= This
->joyfd
;
1098 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1100 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1102 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1103 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1104 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1105 (*lpCallback
)(&dei
, pvRef
);
1108 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1109 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1110 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1111 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1112 (*lpCallback
)(&dei
, pvRef
);
1114 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1115 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1116 (*lpCallback
)(&dei
, pvRef
);
1118 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1119 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1120 (*lpCallback
)(&dei
, pvRef
);
1122 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1123 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1124 (*lpCallback
)(&dei
, pvRef
);
1126 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1127 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1128 (*lpCallback
)(&dei
, pvRef
);
1132 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1133 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1134 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1135 (*lpCallback
)(&dei
, pvRef
);
1138 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1139 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1140 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1141 (*lpCallback
)(&dei
, pvRef
);
1143 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1144 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1145 (*lpCallback
)(&dei
, pvRef
);
1147 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1148 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1149 (*lpCallback
)(&dei
, pvRef
);
1151 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1152 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1153 (*lpCallback
)(&dei
, pvRef
);
1157 /* return to unacquired state if that's where it was */
1159 IDirectInputDevice8_Unacquire(iface
);
1165 /*******************************************************************************
1166 * GetEffectInfo - Get information about a particular effect
1168 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1169 LPDIEFFECTINFOW pdei
,
1172 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1174 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1176 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1177 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1183 /*******************************************************************************
1184 * GetForceFeedbackState - Get information about the device's FF state
1186 static HRESULT WINAPI
JoystickWImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface
, LPDWORD pdwOut
)
1188 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1190 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1194 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1195 /* DIGFFS_STOPPED is the only mandatory flag to report */
1196 if (This
->ff_state
== FF_STATUS_STOPPED
)
1197 (*pdwOut
) |= DIGFFS_STOPPED
;
1203 /*******************************************************************************
1204 * SendForceFeedbackCommand - Send a command to the device's FF system
1206 static HRESULT WINAPI
JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface
, DWORD dwFlags
)
1208 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1209 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1211 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1214 case DISFFC_STOPALL
:
1216 effect_list_item
*itr
;
1218 /* Stop all effects */
1219 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1220 IDirectInputEffect_Stop(itr
->ref
);
1226 effect_list_item
*itr
;
1228 /* Stop and unload all effects. It is not true that effects are released */
1229 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1231 IDirectInputEffect_Stop(itr
->ref
);
1232 IDirectInputEffect_Unload(itr
->ref
);
1237 case DISFFC_CONTINUE
:
1238 FIXME("No support for Pause or Continue in linux\n");
1241 case DISFFC_SETACTUATORSOFF
:
1242 case DISFFC_SETACTUATORSON
:
1243 FIXME("No direct actuator control in linux\n");
1247 WARN("Unknown Force Feedback Command %u!\n", dwFlags
);
1248 return DIERR_INVALIDPARAM
;
1252 return DIERR_UNSUPPORTED
;
1256 /*******************************************************************************
1257 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1258 * created for this device.
1260 static HRESULT WINAPI
JoystickWImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface
,
1261 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1262 LPVOID pvRef
, DWORD dwFlags
)
1264 /* this function is safe to call on non-ff-enabled builds */
1265 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1266 effect_list_item
*itr
, *ptr
;
1268 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1271 return DIERR_INVALIDPARAM
;
1274 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1276 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1277 (*lpCallback
)(itr
->ref
, pvRef
);
1282 /******************************************************************************
1283 * GetDeviceInfo : get information about a device's identity
1285 static HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
,
1286 LPDIDEVICEINSTANCEW pdidi
)
1288 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
1290 TRACE("(%p) %p\n", This
, pdidi
);
1292 if (pdidi
== NULL
) return E_POINTER
;
1293 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1294 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)))
1295 return DIERR_INVALIDPARAM
;
1297 fill_joystick_dideviceinstanceW(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1298 get_joystick_index(&This
->generic
.base
.guid
));
1300 pdidi
->guidInstance
= This
->generic
.base
.guid
;
1305 static const IDirectInputDevice8WVtbl JoystickWvt
=
1307 IDirectInputDevice2WImpl_QueryInterface
,
1308 IDirectInputDevice2WImpl_AddRef
,
1309 IDirectInputDevice2WImpl_Release
,
1310 JoystickWGenericImpl_GetCapabilities
,
1311 IDirectInputDevice2WImpl_EnumObjects
,
1312 JoystickWImpl_GetProperty
,
1313 JoystickWImpl_SetProperty
,
1314 JoystickWImpl_Acquire
,
1315 JoystickWImpl_Unacquire
,
1316 JoystickWGenericImpl_GetDeviceState
,
1317 IDirectInputDevice2WImpl_GetDeviceData
,
1318 IDirectInputDevice2WImpl_SetDataFormat
,
1319 IDirectInputDevice2WImpl_SetEventNotification
,
1320 IDirectInputDevice2WImpl_SetCooperativeLevel
,
1321 JoystickWGenericImpl_GetObjectInfo
,
1322 JoystickWImpl_GetDeviceInfo
,
1323 IDirectInputDevice2WImpl_RunControlPanel
,
1324 IDirectInputDevice2WImpl_Initialize
,
1325 JoystickWImpl_CreateEffect
,
1326 JoystickWImpl_EnumEffects
,
1327 JoystickWImpl_GetEffectInfo
,
1328 JoystickWImpl_GetForceFeedbackState
,
1329 JoystickWImpl_SendForceFeedbackCommand
,
1330 JoystickWImpl_EnumCreatedEffectObjects
,
1331 IDirectInputDevice2WImpl_Escape
,
1332 JoystickWGenericImpl_Poll
,
1333 IDirectInputDevice2WImpl_SendDeviceData
,
1334 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1335 IDirectInputDevice7WImpl_WriteEffectToFile
,
1336 JoystickWGenericImpl_BuildActionMap
,
1337 JoystickWGenericImpl_SetActionMap
,
1338 IDirectInputDevice8WImpl_GetImageInfo
1341 #else /* HAS_PROPER_HEADER */
1343 const struct dinput_device joystick_linuxinput_device
= {
1344 "Wine Linux-input joystick driver",
1350 #endif /* HAS_PROPER_HEADER */