1 /* DirectInput Joystick device
3 * Copyright 1998,2000 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
6 * Copyright 2005 Daniel Remenak
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
34 #ifdef HAVE_SYS_TIME_H
35 # include <sys/time.h>
38 #ifdef HAVE_SYS_IOCTL_H
39 # include <sys/ioctl.h>
42 #ifdef HAVE_SYS_ERRNO_H
43 # include <sys/errno.h>
45 #ifdef HAVE_LINUX_INPUT_H
46 # include <linux/input.h>
48 # if defined(EVIOCGBIT) && defined(EV_ABS) && defined(BTN_PINKIE)
49 # define HAVE_CORRECT_LINUXINPUT_H
52 #ifdef HAVE_SYS_POLL_H
53 # include <sys/poll.h>
56 #include "wine/debug.h"
57 #include "wine/unicode.h"
58 #include "wine/list.h"
65 #include "dinput_private.h"
66 #include "device_private.h"
67 #include "joystick_private.h"
69 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
71 #ifdef HAVE_CORRECT_LINUXINPUT_H
73 #define EVDEVPREFIX "/dev/input/event"
75 /* Wine joystick driver object instances */
76 #define WINE_JOYSTICK_MAX_AXES 8
77 #define WINE_JOYSTICK_MAX_POVS 4
78 #define WINE_JOYSTICK_MAX_BUTTONS 128
80 struct wine_input_absinfo
{
88 /* implemented in effect_linuxinput.c */
89 HRESULT
linuxinput_create_effect(int* fd
, REFGUID rguid
, struct list
*parent_list_entry
, LPDIRECTINPUTEFFECT
* peff
);
90 HRESULT
linuxinput_get_info_A(int fd
, REFGUID rguid
, LPDIEFFECTINFOA info
);
91 HRESULT
linuxinput_get_info_W(int fd
, REFGUID rguid
, LPDIEFFECTINFOW info
);
93 typedef struct JoystickImpl JoystickImpl
;
94 static const IDirectInputDevice8AVtbl JoystickAvt
;
95 static const IDirectInputDevice8WVtbl JoystickWvt
;
105 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
106 BYTE evbits
[(EV_MAX
+7)/8];
107 BYTE absbits
[(ABS_MAX
+7)/8];
108 BYTE keybits
[(KEY_MAX
+7)/8];
109 BYTE ffbits
[(FF_MAX
+7)/8];
111 /* data returned by the EVIOCGABS() ioctl */
112 struct wine_input_absinfo axes
[ABS_MAX
];
117 struct JoystickGenericImpl generic
;
118 struct JoyDev
*joydev
;
120 /* joystick private */
123 int dev_axes_to_di
[ABS_MAX
];
126 /* LUT for KEY_ to offset in rgbButtons */
127 BYTE buttons
[KEY_MAX
];
129 /* Force feedback variables */
130 struct list ff_effects
;
136 static inline JoystickImpl
*impl_from_IDirectInputDevice8A(IDirectInputDevice8A
*iface
)
138 return (JoystickImpl
*) iface
;
140 static inline JoystickImpl
*impl_from_IDirectInputDevice8W(IDirectInputDevice8W
*iface
)
142 return (JoystickImpl
*) iface
;
145 static void fake_current_js_state(JoystickImpl
*ji
);
146 static void find_joydevs(void);
147 static void joy_polldev(LPDIRECTINPUTDEVICE8A 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};
179 struct JoyDev
*new_joydevs
;
181 snprintf(buf
, sizeof(buf
), EVDEVPREFIX
"%d", i
);
183 if ((fd
= open(buf
, O_RDWR
)) == -1)
185 fd
= open(buf
, O_RDONLY
);
191 WARN("Failed to open \"%s\": %d %s\n", buf
, errno
, strerror(errno
));
195 if (ioctl(fd
, EVIOCGBIT(0, sizeof(joydev
.evbits
)), joydev
.evbits
) == -1)
197 WARN("ioct(EVIOCGBIT, 0) failed: %d %s\n", errno
, strerror(errno
));
201 if (ioctl(fd
, EVIOCGBIT(EV_ABS
, sizeof(joydev
.absbits
)), joydev
.absbits
) == -1)
203 WARN("ioct(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
207 if (ioctl(fd
, EVIOCGBIT(EV_KEY
, sizeof(joydev
.keybits
)), joydev
.keybits
) == -1)
209 WARN("ioct(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno
, strerror(errno
));
214 /* A true joystick has at least axis X and Y, and at least 1
215 * button. copied from linux/drivers/input/joydev.c */
216 if (!test_bit(joydev
.absbits
, ABS_X
) || !test_bit(joydev
.absbits
, ABS_Y
) ||
217 !(test_bit(joydev
.keybits
, BTN_TRIGGER
) ||
218 test_bit(joydev
.keybits
, BTN_A
) ||
219 test_bit(joydev
.keybits
, BTN_1
)))
225 if (!(joydev
.device
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
230 strcpy(joydev
.device
, buf
);
232 buf
[MAX_PATH
- 1] = 0;
233 if (ioctl(fd
, EVIOCGNAME(MAX_PATH
- 1), buf
) != -1 &&
234 (joydev
.name
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
235 strcpy(joydev
.name
, buf
);
237 joydev
.name
= joydev
.device
;
239 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
240 joydev
.guid
.Data3
+= have_joydevs
;
242 TRACE("Found a joystick on %s: %s (%s)\n",
243 joydev
.device
, joydev
.name
,
244 debugstr_guid(&joydev
.guid
)
247 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
249 test_bit(joydev
.evbits
, EV_FF
) &&
250 ioctl(fd
, EVIOCGBIT(EV_FF
, sizeof(joydev
.ffbits
)), joydev
.ffbits
) != -1 &&
251 ioctl(fd
, EVIOCGEFFECTS
, &joydev
.num_effects
) != -1 &&
252 joydev
.num_effects
> 0)
254 TRACE(" ... with force feedback\n");
259 for (j
= 0; j
< ABS_MAX
;j
++)
261 if (!test_bit(joydev
.absbits
, j
)) continue;
262 if (ioctl(fd
, EVIOCGABS(j
), &(joydev
.axes
[j
])) != -1)
264 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
266 joydev
.axes
[j
].value
,
267 joydev
.axes
[j
].minimum
,
268 joydev
.axes
[j
].maximum
,
276 new_joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
278 new_joydevs
= HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1 + have_joydevs
) * sizeof(struct JoyDev
));
285 joydevs
= new_joydevs
;
286 memcpy(joydevs
+ have_joydevs
, &joydev
, sizeof(joydev
));
293 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
295 DWORD dwSize
= lpddi
->dwSize
;
297 TRACE("%d %p\n", dwSize
, lpddi
);
298 memset(lpddi
, 0, dwSize
);
300 lpddi
->dwSize
= dwSize
;
301 lpddi
->guidInstance
= joydevs
[id
].guid
;
302 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
303 lpddi
->guidFFDriver
= GUID_NULL
;
305 if (version
>= 0x0800)
306 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
308 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
310 strcpy(lpddi
->tszInstanceName
, joydevs
[id
].name
);
311 strcpy(lpddi
->tszProductName
, joydevs
[id
].name
);
314 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
316 DWORD dwSize
= lpddi
->dwSize
;
318 TRACE("%d %p\n", dwSize
, lpddi
);
319 memset(lpddi
, 0, dwSize
);
321 lpddi
->dwSize
= dwSize
;
322 lpddi
->guidInstance
= joydevs
[id
].guid
;
323 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
324 lpddi
->guidFFDriver
= GUID_NULL
;
326 if (version
>= 0x0800)
327 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
329 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
331 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
332 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszProductName
, MAX_PATH
);
335 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
339 if (id
>= have_joydevs
) {
343 if (!((dwDevType
== 0) ||
344 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
345 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
348 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
349 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
353 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
354 fill_joystick_dideviceinstanceA(lpddi
, version
, id
);
360 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
364 if (id
>= have_joydevs
) {
368 if (!((dwDevType
== 0) ||
369 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
370 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
373 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
374 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
378 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
379 fill_joystick_dideviceinstanceW(lpddi
, version
, id
);
385 static JoystickImpl
*alloc_device(REFGUID rguid
, const void *jvt
, IDirectInputImpl
*dinput
, unsigned short index
)
387 JoystickImpl
* newDevice
;
388 LPDIDATAFORMAT df
= NULL
;
390 int default_axis_map
[WINE_JOYSTICK_MAX_AXES
+ WINE_JOYSTICK_MAX_POVS
*2];
392 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
393 if (!newDevice
) return NULL
;
395 newDevice
->generic
.base
.lpVtbl
= jvt
;
396 newDevice
->generic
.base
.ref
= 1;
397 newDevice
->generic
.base
.guid
= *rguid
;
398 newDevice
->generic
.base
.dinput
= dinput
;
399 newDevice
->generic
.joy_polldev
= joy_polldev
;
400 newDevice
->joyfd
= -1;
401 newDevice
->joydev
= &joydevs
[index
];
402 newDevice
->generic
.name
= newDevice
->joydev
->name
;
403 list_init(&newDevice
->ff_effects
);
404 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
405 newDevice
->ff_state
= FF_STATUS_STOPPED
;
407 /* There is no way in linux to query force feedback autocenter status.
408 Instead, track it with ff_autocenter, and assume it's initialy
410 newDevice
->ff_autocenter
= 1;
411 newDevice
->ff_gain
= 0xFFFF;
412 InitializeCriticalSection(&newDevice
->generic
.base
.crit
);
413 newDevice
->generic
.base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
415 /* Count number of available axes - supported Axis & POVs */
416 for (i
= 0; i
< WINE_JOYSTICK_MAX_AXES
; i
++)
418 if (test_bit(newDevice
->joydev
->absbits
, i
))
420 newDevice
->generic
.device_axis_count
++;
421 newDevice
->dev_axes_to_di
[i
] = idx
;
422 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[i
].minimum
;
423 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[i
].maximum
;
424 default_axis_map
[idx
] = i
;
428 newDevice
->dev_axes_to_di
[i
] = -1;
431 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
433 if (test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) &&
434 test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2))
436 newDevice
->generic
.device_axis_count
+= 2;
437 newDevice
->generic
.props
[idx
].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].minimum
;
438 newDevice
->generic
.props
[idx
].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0X
+ i
* 2].maximum
;
439 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = idx
;
440 newDevice
->generic
.props
[idx
+1].lDevMin
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].minimum
;
441 newDevice
->generic
.props
[idx
+1].lDevMax
= newDevice
->joydev
->axes
[ABS_HAT0Y
+ i
* 2].maximum
;
442 newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = idx
+ 1;
444 default_axis_map
[idx
] = default_axis_map
[idx
+ 1] = WINE_JOYSTICK_MAX_AXES
+ i
;
448 newDevice
->dev_axes_to_di
[ABS_HAT0X
+ i
* 2] = newDevice
->dev_axes_to_di
[ABS_HAT0Y
+ i
* 2] = -1;
451 /* do any user specified configuration */
452 if (setup_dinput_options(&newDevice
->generic
, default_axis_map
) != DI_OK
) goto failed
;
454 /* Create copy of default data format */
455 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
456 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
457 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
460 /* Construct internal data format */
462 /* Supported Axis & POVs */
463 for (i
= 0, idx
= 0; i
< newDevice
->generic
.device_axis_count
; i
++)
465 int wine_obj
= newDevice
->generic
.axis_map
[i
];
467 if (wine_obj
< 0) continue;
469 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[wine_obj
], df
->dwObjSize
);
471 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
) | DIDFT_ABSAXIS
;
474 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
- 8) | DIDFT_POV
;
475 i
++; /* POV takes 2 axes */
478 newDevice
->generic
.props
[idx
].lMin
= 0;
479 newDevice
->generic
.props
[idx
].lMax
= 0xffff;
480 newDevice
->generic
.props
[idx
].lSaturation
= 0;
481 newDevice
->generic
.props
[idx
].lDeadZone
= newDevice
->generic
.deadzone
;
483 /* Linux supports force-feedback on X & Y axes only */
484 if (newDevice
->joydev
->has_ff
&& (i
== 0 || i
== 1))
485 df
->rgodf
[idx
].dwFlags
|= DIDOI_FFACTUATOR
;
490 /* Buttons can be anywhere, so check all */
491 for (i
= 0; i
< KEY_MAX
&& newDevice
->generic
.devcaps
.dwButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
493 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
495 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->generic
.devcaps
.dwButtons
+ 12], df
->dwObjSize
);
496 newDevice
->buttons
[i
] = 0x80 | newDevice
->generic
.devcaps
.dwButtons
;
497 df
->rgodf
[idx
].pguid
= &GUID_Button
;
498 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->generic
.devcaps
.dwButtons
++) | DIDFT_PSHBUTTON
;
501 newDevice
->generic
.base
.data_format
.wine_df
= df
;
503 fake_current_js_state(newDevice
);
506 newDevice
->generic
.devcaps
.dwSize
= sizeof(newDevice
->generic
.devcaps
);
507 newDevice
->generic
.devcaps
.dwFlags
= DIDC_ATTACHED
;
508 if (newDevice
->generic
.base
.dinput
->dwVersion
>= 0x0800)
509 newDevice
->generic
.devcaps
.dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
511 newDevice
->generic
.devcaps
.dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
513 if (newDevice
->joydev
->has_ff
)
514 newDevice
->generic
.devcaps
.dwFlags
|= DIDC_FORCEFEEDBACK
;
516 IDirectInput_AddRef(&newDevice
->generic
.base
.dinput
->IDirectInput7A_iface
);
520 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
521 HeapFree(GetProcessHeap(), 0, df
);
522 HeapFree(GetProcessHeap(), 0, newDevice
->generic
.axis_map
);
523 HeapFree(GetProcessHeap(), 0, newDevice
);
527 /******************************************************************************
528 * get_joystick_index : Get the joystick index from a given GUID
530 static unsigned short get_joystick_index(REFGUID guid
)
532 GUID wine_joystick
= DInput_Wine_Joystick_Base_GUID
;
533 GUID dev_guid
= *guid
;
535 wine_joystick
.Data3
= 0;
538 /* for the standard joystick GUID use index 0 */
539 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
541 /* for the wine joystick GUIDs use the index stored in Data3 */
542 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
- DInput_Wine_Joystick_Base_GUID
.Data3
;
547 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
549 unsigned short index
;
553 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
554 have_joydevs
&& index
< have_joydevs
)
556 if ((riid
== NULL
) ||
557 IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
558 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
559 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
560 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
562 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &JoystickAvt
, dinput
, index
);
563 TRACE("Created a Joystick device (%p)\n", *pdev
);
567 ERR("out of memory\n");
568 return DIERR_OUTOFMEMORY
;
573 WARN("no interface\n");
574 return DIERR_NOINTERFACE
;
577 return DIERR_DEVICENOTREG
;
581 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
583 unsigned short index
;
587 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
588 have_joydevs
&& index
< have_joydevs
)
590 if ((riid
== NULL
) ||
591 IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
592 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
593 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
594 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
596 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &JoystickWvt
, dinput
, index
);
597 TRACE("Created a Joystick device (%p)\n", *pdev
);
601 ERR("out of memory\n");
602 return DIERR_OUTOFMEMORY
;
606 WARN("no interface\n");
607 return DIERR_NOINTERFACE
;
610 WARN("invalid device GUID\n");
611 return DIERR_DEVICENOTREG
;
614 const struct dinput_device joystick_linuxinput_device
= {
615 "Wine Linux-input joystick driver",
618 joydev_create_deviceA
,
619 joydev_create_deviceW
622 /******************************************************************************
623 * Acquire : gets exclusive control of the joystick
625 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
627 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
630 TRACE("(this=%p)\n",This
);
632 if ((res
= IDirectInputDevice2AImpl_Acquire(iface
)) != DI_OK
)
634 WARN("Failed to acquire: %x\n", res
);
638 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDWR
)) == -1)
640 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDONLY
)) == -1)
642 /* Couldn't open the device at all */
643 ERR("Failed to open device %s: %d %s\n", This
->joydev
->device
, errno
, strerror(errno
));
644 IDirectInputDevice2AImpl_Unacquire(iface
);
645 return DIERR_NOTFOUND
;
649 /* Couldn't open in r/w but opened in read-only. */
650 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
655 struct input_event event
;
658 event
.code
= FF_GAIN
;
659 event
.value
= This
->ff_gain
;
660 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
661 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
662 if (!This
->ff_autocenter
)
664 /* Disable autocenter. */
665 event
.code
= FF_AUTOCENTER
;
667 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
668 ERR("Failed disabling autocenter: %d %s\n", errno
, strerror(errno
));
675 /******************************************************************************
676 * Unacquire : frees the joystick
678 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
680 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
683 TRACE("(this=%p)\n",This
);
684 res
= IDirectInputDevice2AImpl_Unacquire(iface
);
685 if (res
==DI_OK
&& This
->joyfd
!=-1) {
686 effect_list_item
*itr
;
687 struct input_event event
;
689 /* For each known effect:
692 * But, unlike DISFFC_RESET, do not release the effect.
694 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
) {
695 IDirectInputEffect_Stop(itr
->ref
);
696 IDirectInputEffect_Unload(itr
->ref
);
699 /* Enable autocenter. */
701 event
.code
= FF_AUTOCENTER
;
702 /* TODO: Read autocenter strengh before disabling it, and use it here
703 * instead of 0xFFFF (maximum strengh).
705 event
.value
= 0xFFFF;
706 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
707 ERR("Failed to set autocenter to %04x: %d %s\n", event
.value
, errno
, strerror(errno
));
716 * set the current state of the js device as it would be with the middle
719 #define CENTER_AXIS(a) \
720 (ji->dev_axes_to_di[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->dev_axes_to_di[a]], \
721 ji->joydev->axes[a].value ))
722 static void fake_current_js_state(JoystickImpl
*ji
)
726 /* center the axes */
727 ji
->generic
.js
.lX
= CENTER_AXIS(ABS_X
);
728 ji
->generic
.js
.lY
= CENTER_AXIS(ABS_Y
);
729 ji
->generic
.js
.lZ
= CENTER_AXIS(ABS_Z
);
730 ji
->generic
.js
.lRx
= CENTER_AXIS(ABS_RX
);
731 ji
->generic
.js
.lRy
= CENTER_AXIS(ABS_RY
);
732 ji
->generic
.js
.lRz
= CENTER_AXIS(ABS_RZ
);
733 ji
->generic
.js
.rglSlider
[0] = CENTER_AXIS(ABS_THROTTLE
);
734 ji
->generic
.js
.rglSlider
[1] = CENTER_AXIS(ABS_RUDDER
);
736 /* POV center is -1 */
737 for (i
= 0; i
< 4; i
++)
738 ji
->generic
.js
.rgdwPOV
[i
] = -1;
742 /* convert wine format offset to user format object index */
743 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
)
746 struct input_event ie
;
747 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
757 plfd
.fd
= This
->joyfd
;
758 plfd
.events
= POLLIN
;
760 if (poll(&plfd
,1,0) != 1)
763 /* we have one event, so we can read */
764 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
767 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
769 case EV_KEY
: /* button */
771 int btn
= This
->buttons
[ie
.code
];
773 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
777 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
778 This
->generic
.js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
784 int axis
= This
->dev_axes_to_di
[ie
.code
];
786 /* User axis remapping */
788 axis
= This
->generic
.axis_map
[axis
];
791 inst_id
= axis
< 8 ? DIDFT_MAKEINSTANCE(axis
) | DIDFT_ABSAXIS
:
792 DIDFT_MAKEINSTANCE(axis
- 8) | DIDFT_POV
;
793 value
= joystick_map_axis(&This
->generic
.props
[id_to_object(This
->generic
.base
.data_format
.wine_df
, inst_id
)], ie
.value
);
796 case 0: This
->generic
.js
.lX
= value
; break;
797 case 1: This
->generic
.js
.lY
= value
; break;
798 case 2: This
->generic
.js
.lZ
= value
; break;
799 case 3: This
->generic
.js
.lRx
= value
; break;
800 case 4: This
->generic
.js
.lRy
= value
; break;
801 case 5: This
->generic
.js
.lRz
= value
; break;
802 case 6: This
->generic
.js
.rglSlider
[0] = value
; break;
803 case 7: This
->generic
.js
.rglSlider
[1] = value
; break;
804 case 8: case 9: case 10: case 11:
809 This
->povs
[idx
].y
= ie
.value
;
811 This
->povs
[idx
].x
= ie
.value
;
813 This
->generic
.js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
817 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
821 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
823 This
->ff_state
= ie
.value
;
828 /* there is nothing to do */
832 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
836 queue_event(iface
, inst_id
,
837 value
, ie
.time
.tv_usec
, This
->generic
.base
.dinput
->evsequence
++);
841 /******************************************************************************
842 * SetProperty : change input device properties
844 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
848 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
851 WARN("invalid argument\n");
852 return DIERR_INVALIDPARAM
;
855 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
856 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
857 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
859 if (IS_DIPROP(rguid
)) {
860 switch (LOWORD(rguid
)) {
861 case (DWORD_PTR
)DIPROP_CALIBRATIONMODE
: {
862 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
863 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd
->dwData
);
866 case (DWORD_PTR
)DIPROP_AUTOCENTER
: {
867 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
869 TRACE("autocenter(%d)\n", pd
->dwData
);
870 This
->ff_autocenter
= pd
->dwData
== DIPROPAUTOCENTER_ON
;
874 case (DWORD_PTR
)DIPROP_FFGAIN
: {
875 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
877 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
878 This
->ff_gain
= MulDiv(pd
->dwData
, 0xFFFF, 10000);
879 if (This
->generic
.base
.acquired
) {
880 /* Update immediately. */
881 struct input_event event
;
884 event
.code
= FF_GAIN
;
885 event
.value
= This
->ff_gain
;
886 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
887 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
892 return JoystickAGenericImpl_SetProperty(iface
, rguid
, ph
);
898 /******************************************************************************
899 * GetProperty : get input device properties
901 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
903 LPDIPROPHEADER pdiph
)
905 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
907 TRACE("(this=%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
908 _dump_DIPROPHEADER(pdiph
);
910 if (!IS_DIPROP(rguid
)) return DI_OK
;
912 switch (LOWORD(rguid
)) {
913 case (DWORD_PTR
) DIPROP_AUTOCENTER
:
915 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
917 pd
->dwData
= This
->ff_autocenter
? DIPROPAUTOCENTER_ON
: DIPROPAUTOCENTER_OFF
;
918 TRACE("autocenter(%d)\n", pd
->dwData
);
921 case (DWORD_PTR
) DIPROP_FFGAIN
:
923 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
925 pd
->dwData
= MulDiv(This
->ff_gain
, 10000, 0xFFFF);
926 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
931 return JoystickAGenericImpl_GetProperty(iface
, rguid
, pdiph
);
937 /******************************************************************************
938 * CreateEffect - Create a new FF effect with the specified params
940 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
,
943 LPDIRECTINPUTEFFECT
*ppdef
,
946 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
947 effect_list_item
* new_effect
= NULL
;
948 HRESULT retval
= DI_OK
;
951 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
952 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
954 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
955 TRACE("not available (compiled w/o ff support)\n");
960 if (!(new_effect
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect
))))
961 return DIERR_OUTOFMEMORY
;
963 retval
= linuxinput_create_effect(&This
->joyfd
, rguid
, &new_effect
->entry
, &new_effect
->ref
);
966 HeapFree(GetProcessHeap(), 0, new_effect
);
972 retval
= IDirectInputEffect_SetParameters(new_effect
->ref
, lpeff
, 0);
974 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
976 HeapFree(GetProcessHeap(), 0, new_effect
);
981 list_add_tail(&This
->ff_effects
, &new_effect
->entry
);
982 *ppdef
= new_effect
->ref
;
984 if (pUnkOuter
!= NULL
)
985 FIXME("Interface aggregation not implemented.\n");
989 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
992 /*******************************************************************************
993 * EnumEffects - Enumerate available FF effects
995 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
996 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1000 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1001 DIEFFECTINFOA dei
; /* feif */
1002 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1003 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1005 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
1007 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1009 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1010 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1011 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1012 (*lpCallback
)(&dei
, pvRef
);
1015 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1016 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1017 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1018 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1019 (*lpCallback
)(&dei
, pvRef
);
1021 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1022 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1023 (*lpCallback
)(&dei
, pvRef
);
1025 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1026 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1027 (*lpCallback
)(&dei
, pvRef
);
1029 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1030 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1031 (*lpCallback
)(&dei
, pvRef
);
1033 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1034 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1035 (*lpCallback
)(&dei
, pvRef
);
1039 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1040 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1041 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1042 (*lpCallback
)(&dei
, pvRef
);
1045 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1046 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1047 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1048 (*lpCallback
)(&dei
, pvRef
);
1050 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1051 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1052 (*lpCallback
)(&dei
, pvRef
);
1054 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1055 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1056 (*lpCallback
)(&dei
, pvRef
);
1058 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1059 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1060 (*lpCallback
)(&dei
, pvRef
);
1069 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1070 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1074 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1075 /* seems silly to duplicate all this code but all the structures and functions
1076 * are actually different (A/W) */
1077 DIEFFECTINFOW dei
; /* feif */
1078 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1079 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1080 int xfd
= This
->joyfd
;
1082 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1084 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1086 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1087 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1088 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1089 (*lpCallback
)(&dei
, pvRef
);
1092 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1093 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1094 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1095 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1096 (*lpCallback
)(&dei
, pvRef
);
1098 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1099 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1100 (*lpCallback
)(&dei
, pvRef
);
1102 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1103 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1104 (*lpCallback
)(&dei
, pvRef
);
1106 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1107 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1108 (*lpCallback
)(&dei
, pvRef
);
1110 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1111 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1112 (*lpCallback
)(&dei
, pvRef
);
1116 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1117 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1118 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1119 (*lpCallback
)(&dei
, pvRef
);
1122 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1123 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1124 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1125 (*lpCallback
)(&dei
, pvRef
);
1127 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1128 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1129 (*lpCallback
)(&dei
, pvRef
);
1131 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1132 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1133 (*lpCallback
)(&dei
, pvRef
);
1135 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1136 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1137 (*lpCallback
)(&dei
, pvRef
);
1141 /* return to unacquired state if that's where it was */
1143 IDirectInputDevice8_Unacquire(iface
);
1149 /*******************************************************************************
1150 * GetEffectInfo - Get information about a particular effect
1152 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1153 LPDIEFFECTINFOA pdei
,
1156 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1158 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1160 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1161 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1167 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1168 LPDIEFFECTINFOW pdei
,
1171 JoystickImpl
* This
= impl_from_IDirectInputDevice8W(iface
);
1173 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1175 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1176 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1182 /*******************************************************************************
1183 * GetForceFeedbackState - Get information about the device's FF state
1185 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(
1186 LPDIRECTINPUTDEVICE8A iface
,
1189 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1191 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1195 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1196 /* DIGFFS_STOPPED is the only mandatory flag to report */
1197 if (This
->ff_state
== FF_STATUS_STOPPED
)
1198 (*pdwOut
) |= DIGFFS_STOPPED
;
1204 /*******************************************************************************
1205 * SendForceFeedbackCommand - Send a command to the device's FF system
1207 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(
1208 LPDIRECTINPUTDEVICE8A iface
,
1211 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1212 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1214 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1217 case DISFFC_STOPALL
:
1219 /* Stop all effects */
1220 effect_list_item
*itr
;
1222 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1223 IDirectInputEffect_Stop(itr
->ref
);
1229 effect_list_item
*itr
, *ptr
;
1231 /* Stop, unload, release and free all effects */
1232 /* This returns the device to its "bare" state */
1233 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1234 IDirectInputEffect_Release(itr
->ref
);
1238 case DISFFC_CONTINUE
:
1239 FIXME("No support for Pause or Continue in linux\n");
1242 case DISFFC_SETACTUATORSOFF
:
1243 case DISFFC_SETACTUATORSON
:
1244 FIXME("No direct actuator control in linux\n");
1248 FIXME("Unknown Force Feedback Command!\n");
1249 return DIERR_INVALIDPARAM
;
1253 return DIERR_UNSUPPORTED
;
1257 /*******************************************************************************
1258 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1259 * created for this device.
1261 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(
1262 LPDIRECTINPUTDEVICE8A iface
,
1263 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1267 /* this function is safe to call on non-ff-enabled builds */
1268 JoystickImpl
* This
= impl_from_IDirectInputDevice8A(iface
);
1269 effect_list_item
*itr
, *ptr
;
1271 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1274 return DIERR_INVALIDPARAM
;
1277 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1279 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1280 (*lpCallback
)(itr
->ref
, pvRef
);
1285 /******************************************************************************
1286 * GetDeviceInfo : get information about a device's identity
1288 static HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface
,
1289 LPDIDEVICEINSTANCEA pdidi
)
1291 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1293 TRACE("(%p) %p\n", This
, pdidi
);
1295 if (pdidi
== NULL
) return E_POINTER
;
1296 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1297 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)))
1298 return DIERR_INVALIDPARAM
;
1300 fill_joystick_dideviceinstanceA(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1301 get_joystick_index(&This
->generic
.base
.guid
));
1305 static HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
,
1306 LPDIDEVICEINSTANCEW pdidi
)
1308 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
1310 TRACE("(%p) %p\n", This
, pdidi
);
1312 if (pdidi
== NULL
) return E_POINTER
;
1313 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1314 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)))
1315 return DIERR_INVALIDPARAM
;
1317 fill_joystick_dideviceinstanceW(pdidi
, This
->generic
.base
.dinput
->dwVersion
,
1318 get_joystick_index(&This
->generic
.base
.guid
));
1322 static const IDirectInputDevice8AVtbl JoystickAvt
=
1324 IDirectInputDevice2AImpl_QueryInterface
,
1325 IDirectInputDevice2AImpl_AddRef
,
1326 IDirectInputDevice2AImpl_Release
,
1327 JoystickAGenericImpl_GetCapabilities
,
1328 IDirectInputDevice2AImpl_EnumObjects
,
1329 JoystickAImpl_GetProperty
,
1330 JoystickAImpl_SetProperty
,
1331 JoystickAImpl_Acquire
,
1332 JoystickAImpl_Unacquire
,
1333 JoystickAGenericImpl_GetDeviceState
,
1334 IDirectInputDevice2AImpl_GetDeviceData
,
1335 IDirectInputDevice2AImpl_SetDataFormat
,
1336 IDirectInputDevice2AImpl_SetEventNotification
,
1337 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1338 JoystickAGenericImpl_GetObjectInfo
,
1339 JoystickAImpl_GetDeviceInfo
,
1340 IDirectInputDevice2AImpl_RunControlPanel
,
1341 IDirectInputDevice2AImpl_Initialize
,
1342 JoystickAImpl_CreateEffect
,
1343 JoystickAImpl_EnumEffects
,
1344 JoystickAImpl_GetEffectInfo
,
1345 JoystickAImpl_GetForceFeedbackState
,
1346 JoystickAImpl_SendForceFeedbackCommand
,
1347 JoystickAImpl_EnumCreatedEffectObjects
,
1348 IDirectInputDevice2AImpl_Escape
,
1349 JoystickAGenericImpl_Poll
,
1350 IDirectInputDevice2AImpl_SendDeviceData
,
1351 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1352 IDirectInputDevice7AImpl_WriteEffectToFile
,
1353 IDirectInputDevice8AImpl_BuildActionMap
,
1354 IDirectInputDevice8AImpl_SetActionMap
,
1355 IDirectInputDevice8AImpl_GetImageInfo
1358 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1359 # define XCAST(fun) (typeof(JoystickWvt.fun))
1361 # define XCAST(fun) (void*)
1364 static const IDirectInputDevice8WVtbl JoystickWvt
=
1366 IDirectInputDevice2WImpl_QueryInterface
,
1367 IDirectInputDevice2WImpl_AddRef
,
1368 IDirectInputDevice2WImpl_Release
,
1369 JoystickWGenericImpl_GetCapabilities
,
1370 IDirectInputDevice2WImpl_EnumObjects
,
1371 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1372 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1373 XCAST(Acquire
)JoystickAImpl_Acquire
,
1374 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1375 JoystickWGenericImpl_GetDeviceState
,
1376 IDirectInputDevice2WImpl_GetDeviceData
,
1377 IDirectInputDevice2WImpl_SetDataFormat
,
1378 IDirectInputDevice2WImpl_SetEventNotification
,
1379 IDirectInputDevice2WImpl_SetCooperativeLevel
,
1380 JoystickWGenericImpl_GetObjectInfo
,
1381 JoystickWImpl_GetDeviceInfo
,
1382 IDirectInputDevice2WImpl_RunControlPanel
,
1383 IDirectInputDevice2WImpl_Initialize
,
1384 XCAST(CreateEffect
)JoystickAImpl_CreateEffect
,
1385 JoystickWImpl_EnumEffects
,
1386 JoystickWImpl_GetEffectInfo
,
1387 XCAST(GetForceFeedbackState
)JoystickAImpl_GetForceFeedbackState
,
1388 XCAST(SendForceFeedbackCommand
)JoystickAImpl_SendForceFeedbackCommand
,
1389 XCAST(EnumCreatedEffectObjects
)JoystickAImpl_EnumCreatedEffectObjects
,
1390 IDirectInputDevice2WImpl_Escape
,
1391 JoystickWGenericImpl_Poll
,
1392 IDirectInputDevice2WImpl_SendDeviceData
,
1393 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1394 IDirectInputDevice7WImpl_WriteEffectToFile
,
1395 IDirectInputDevice8WImpl_BuildActionMap
,
1396 IDirectInputDevice8WImpl_SetActionMap
,
1397 IDirectInputDevice8WImpl_GetImageInfo
1401 #else /* HAVE_CORRECT_LINUXINPUT_H */
1403 const struct dinput_device joystick_linuxinput_device
= {
1404 "Wine Linux-input joystick driver",
1411 #endif /* HAVE_CORRECT_LINUXINPUT_H */