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 IDirectInputDevice2AImpl base
;
119 struct JoyDev
*joydev
;
121 /* joystick private */
126 ObjProps props
[ABS_MAX
];
131 /* LUT for KEY_ to offset in rgbButtons */
132 BYTE buttons
[KEY_MAX
];
138 /* Force feedback variables */
139 struct list ff_effects
;
145 static void fake_current_js_state(JoystickImpl
*ji
);
146 static void find_joydevs(void);
148 /* This GUID is slightly different from the linux joystick one. Take note. */
149 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
153 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
156 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
158 #define MAX_JOYDEV 64
160 static int have_joydevs
= -1;
161 static struct JoyDev
*joydevs
= NULL
;
163 static void find_joydevs(void)
167 if (InterlockedCompareExchange(&have_joydevs
, 0, -1) != -1)
168 /* Someone beat us to it */
171 for (i
= 0; i
< MAX_JOYDEV
; i
++)
174 struct JoyDev joydev
= {0};
178 struct JoyDev
*new_joydevs
;
180 snprintf(buf
, sizeof(buf
), EVDEVPREFIX
"%d", i
);
182 if ((fd
= open(buf
, O_RDWR
)) == -1)
184 fd
= open(buf
, O_RDONLY
);
190 WARN("Failed to open \"%s\": %d %s\n", buf
, errno
, strerror(errno
));
194 if (ioctl(fd
, EVIOCGBIT(0, sizeof(joydev
.evbits
)), joydev
.evbits
) == -1)
196 WARN("ioct(EVIOCGBIT, 0) failed: %d %s\n", errno
, strerror(errno
));
200 if (ioctl(fd
, EVIOCGBIT(EV_ABS
, sizeof(joydev
.absbits
)), joydev
.absbits
) == -1)
202 WARN("ioct(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
206 if (ioctl(fd
, EVIOCGBIT(EV_KEY
, sizeof(joydev
.keybits
)), joydev
.keybits
) == -1)
208 WARN("ioct(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno
, strerror(errno
));
213 /* A true joystick has at least axis X and Y, and at least 1
214 * button. copied from linux/drivers/input/joydev.c */
215 if (!test_bit(joydev
.absbits
, ABS_X
) || !test_bit(joydev
.absbits
, ABS_Y
) ||
216 !(test_bit(joydev
.keybits
, BTN_TRIGGER
) ||
217 test_bit(joydev
.keybits
, BTN_A
) ||
218 test_bit(joydev
.keybits
, BTN_1
)))
224 if (!(joydev
.device
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
229 strcpy(joydev
.device
, buf
);
231 buf
[MAX_PATH
- 1] = 0;
232 if (ioctl(fd
, EVIOCGNAME(MAX_PATH
- 1), buf
) != -1 &&
233 (joydev
.name
= HeapAlloc(GetProcessHeap(), 0, strlen(buf
) + 1)))
234 strcpy(joydev
.name
, buf
);
236 joydev
.name
= joydev
.device
;
238 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
239 joydev
.guid
.Data3
+= have_joydevs
;
241 TRACE("Found a joystick on %s: %s (%s)\n",
242 joydev
.device
, joydev
.name
,
243 debugstr_guid(&joydev
.guid
)
246 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
248 test_bit(joydev
.evbits
, EV_FF
) &&
249 ioctl(fd
, EVIOCGBIT(EV_FF
, sizeof(joydev
.ffbits
)), joydev
.ffbits
) != -1 &&
250 ioctl(fd
, EVIOCGEFFECTS
, &joydev
.num_effects
) != -1 &&
251 joydev
.num_effects
> 0)
253 TRACE(" ... with force feedback\n");
258 for (j
= 0; j
< ABS_MAX
;j
++)
260 if (!test_bit(joydev
.absbits
, j
)) continue;
261 if (ioctl(fd
, EVIOCGABS(j
), &(joydev
.axes
[j
])) != -1)
263 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
265 joydev
.axes
[j
].value
,
266 joydev
.axes
[j
].minimum
,
267 joydev
.axes
[j
].maximum
,
275 new_joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
277 new_joydevs
= HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1 + have_joydevs
) * sizeof(struct JoyDev
));
284 joydevs
= new_joydevs
;
285 memcpy(joydevs
+ have_joydevs
, &joydev
, sizeof(joydev
));
292 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
294 DWORD dwSize
= lpddi
->dwSize
;
296 TRACE("%d %p\n", dwSize
, lpddi
);
297 memset(lpddi
, 0, dwSize
);
299 lpddi
->dwSize
= dwSize
;
300 lpddi
->guidInstance
= joydevs
[id
].guid
;
301 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
302 lpddi
->guidFFDriver
= GUID_NULL
;
304 if (version
>= 0x0800)
305 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
307 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
309 strcpy(lpddi
->tszInstanceName
, joydevs
[id
].name
);
310 strcpy(lpddi
->tszProductName
, joydevs
[id
].device
);
313 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
315 DWORD dwSize
= lpddi
->dwSize
;
317 TRACE("%d %p\n", dwSize
, lpddi
);
318 memset(lpddi
, 0, dwSize
);
320 lpddi
->dwSize
= dwSize
;
321 lpddi
->guidInstance
= joydevs
[id
].guid
;
322 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
323 lpddi
->guidFFDriver
= GUID_NULL
;
325 if (version
>= 0x0800)
326 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
328 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
330 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
331 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].device
, -1, lpddi
->tszProductName
, MAX_PATH
);
334 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
338 if (id
>= have_joydevs
) {
342 if (!((dwDevType
== 0) ||
343 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
344 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
347 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
348 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
352 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
353 fill_joystick_dideviceinstanceA(lpddi
, version
, id
);
359 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
363 if (id
>= have_joydevs
) {
367 if (!((dwDevType
== 0) ||
368 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
369 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
372 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
373 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
377 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
378 fill_joystick_dideviceinstanceW(lpddi
, version
, id
);
384 static JoystickImpl
*alloc_device(REFGUID rguid
, const void *jvt
, IDirectInputImpl
*dinput
, unsigned short index
)
386 JoystickImpl
* newDevice
;
387 LPDIDATAFORMAT df
= NULL
;
389 char buffer
[MAX_PATH
+16];
391 LONG def_deadzone
= 0;
393 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
394 if (!newDevice
) return NULL
;
396 newDevice
->base
.lpVtbl
= jvt
;
397 newDevice
->base
.ref
= 1;
398 newDevice
->base
.guid
= *rguid
;
399 newDevice
->base
.dinput
= dinput
;
400 newDevice
->joyfd
= -1;
401 newDevice
->joydev
= &joydevs
[index
];
402 list_init(&newDevice
->ff_effects
);
403 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
404 newDevice
->ff_state
= FF_STATUS_STOPPED
;
406 /* There is no way in linux to query force feedback autocenter status.
407 Instead, track it with ff_autocenter, and assume it's initialy
409 newDevice
->ff_autocenter
= 1;
410 newDevice
->ff_gain
= 0xFFFF;
411 InitializeCriticalSection(&newDevice
->base
.crit
);
412 newDevice
->base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
415 get_app_key(&hkey
, &appkey
);
417 if (!get_config_key(hkey
, appkey
, "DefaultDeadZone", buffer
, MAX_PATH
))
419 def_deadzone
= atoi(buffer
);
420 TRACE("setting default deadzone to: %d\n", def_deadzone
);
422 if (appkey
) RegCloseKey(appkey
);
423 if (hkey
) RegCloseKey(hkey
);
425 /* Create copy of default data format */
426 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
427 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
428 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
430 /* Supported Axis & POVs should map 1-to-1 */
431 for (i
= 0; i
< WINE_JOYSTICK_MAX_AXES
; i
++)
433 if (!test_bit(newDevice
->joydev
->absbits
, i
)) {
434 newDevice
->axes
[i
] = -1;
438 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[i
], df
->dwObjSize
);
439 newDevice
->axes
[i
] = idx
;
440 newDevice
->props
[idx
].lDevMin
= newDevice
->joydev
->axes
[i
].minimum
;
441 newDevice
->props
[idx
].lDevMax
= newDevice
->joydev
->axes
[i
].maximum
;
442 newDevice
->props
[idx
].lMin
= 0;
443 newDevice
->props
[idx
].lMax
= 0xffff;
444 newDevice
->props
[idx
].lSaturation
= 0;
445 newDevice
->props
[idx
].lDeadZone
= def_deadzone
;
447 /* Linux supports force-feedback on X & Y axes only */
448 if (newDevice
->joydev
->has_ff
&& (i
== 0 || i
== 1))
449 df
->rgodf
[idx
].dwFlags
|= DIDOI_FFACTUATOR
;
451 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->numAxes
++) | DIDFT_ABSAXIS
;
454 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
456 if (!test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) ||
457 !test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2)) {
458 newDevice
->axes
[ABS_HAT0X
+ i
* 2] = newDevice
->axes
[ABS_HAT0Y
+ i
* 2] = -1;
462 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[i
+ WINE_JOYSTICK_MAX_AXES
], df
->dwObjSize
);
463 newDevice
->axes
[ABS_HAT0X
+ i
* 2] = newDevice
->axes
[ABS_HAT0Y
+ i
* 2] = i
;
464 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->numPOVs
++) | DIDFT_POV
;
467 /* Buttons can be anywhere, so check all */
468 for (i
= 0; i
< KEY_MAX
&& newDevice
->numButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
470 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
472 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->numButtons
+ WINE_JOYSTICK_MAX_AXES
+ WINE_JOYSTICK_MAX_POVS
], df
->dwObjSize
);
473 newDevice
->buttons
[i
] = 0x80 | newDevice
->numButtons
;
474 df
->rgodf
[idx
].pguid
= &GUID_Button
;
475 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->numButtons
++) | DIDFT_PSHBUTTON
;
479 fake_current_js_state(newDevice
);
481 newDevice
->base
.data_format
.wine_df
= df
;
482 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A
)newDevice
->base
.dinput
);
486 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
487 HeapFree(GetProcessHeap(), 0, df
);
488 HeapFree(GetProcessHeap(), 0, newDevice
);
492 /******************************************************************************
493 * get_joystick_index : Get the joystick index from a given GUID
495 static unsigned short get_joystick_index(REFGUID guid
)
497 GUID wine_joystick
= DInput_Wine_Joystick_Base_GUID
;
498 GUID dev_guid
= *guid
;
500 wine_joystick
.Data3
= 0;
503 /* for the standard joystick GUID use index 0 */
504 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
506 /* for the wine joystick GUIDs use the index stored in Data3 */
507 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
- DInput_Wine_Joystick_Base_GUID
.Data3
;
512 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
514 unsigned short index
;
518 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
519 have_joydevs
&& index
< have_joydevs
)
521 if ((riid
== NULL
) ||
522 IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
523 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
524 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
525 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
527 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &JoystickAvt
, dinput
, index
);
528 TRACE("Created a Joystick device (%p)\n", *pdev
);
532 ERR("out of memory\n");
533 return DIERR_OUTOFMEMORY
;
538 WARN("no interface\n");
539 return DIERR_NOINTERFACE
;
542 return DIERR_DEVICENOTREG
;
546 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
548 unsigned short index
;
552 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
553 have_joydevs
&& index
< have_joydevs
)
555 if ((riid
== NULL
) ||
556 IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
557 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
558 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
559 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
561 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &JoystickWvt
, dinput
, index
);
562 TRACE("Created a Joystick device (%p)\n", *pdev
);
566 ERR("out of memory\n");
567 return DIERR_OUTOFMEMORY
;
571 WARN("no interface\n");
572 return DIERR_NOINTERFACE
;
575 WARN("invalid device GUID\n");
576 return DIERR_DEVICENOTREG
;
579 const struct dinput_device joystick_linuxinput_device
= {
580 "Wine Linux-input joystick driver",
583 joydev_create_deviceA
,
584 joydev_create_deviceW
587 /******************************************************************************
588 * Acquire : gets exclusive control of the joystick
590 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
592 JoystickImpl
*This
= (JoystickImpl
*)iface
;
595 TRACE("(this=%p)\n",This
);
597 if ((res
= IDirectInputDevice2AImpl_Acquire(iface
)) != DI_OK
)
599 WARN("Failed to acquire: %x\n", res
);
603 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDWR
)) == -1)
605 if ((This
->joyfd
= open(This
->joydev
->device
, O_RDONLY
)) == -1)
607 /* Couldn't open the device at all */
608 ERR("Failed to open device %s: %d %s\n", This
->joydev
->device
, errno
, strerror(errno
));
609 IDirectInputDevice2AImpl_Unacquire(iface
);
610 return DIERR_NOTFOUND
;
614 /* Couldn't open in r/w but opened in read-only. */
615 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
620 struct input_event event
;
623 event
.code
= FF_GAIN
;
624 event
.value
= This
->ff_gain
;
625 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
626 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
627 if (!This
->ff_autocenter
)
629 /* Disable autocenter. */
630 event
.code
= FF_AUTOCENTER
;
632 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
633 ERR("Failed disabling autocenter: %d %s\n", errno
, strerror(errno
));
640 /******************************************************************************
641 * Unacquire : frees the joystick
643 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
645 JoystickImpl
*This
= (JoystickImpl
*)iface
;
648 TRACE("(this=%p)\n",This
);
649 res
= IDirectInputDevice2AImpl_Unacquire(iface
);
650 if (res
==DI_OK
&& This
->joyfd
!=-1) {
651 effect_list_item
*itr
;
652 struct input_event event
;
654 /* For each known effect:
657 * But, unlike DISFFC_RESET, do not release the effect.
659 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
) {
660 IDirectInputEffect_Stop(itr
->ref
);
661 IDirectInputEffect_Unload(itr
->ref
);
664 /* Enable autocenter. */
666 event
.code
= FF_AUTOCENTER
;
667 /* TODO: Read autocenter strengh before disabling it, and use it here
668 * instead of 0xFFFF (maximum strengh).
670 event
.value
= 0xFFFF;
671 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
672 ERR("Failed to set autocenter to %04x: %d %s\n", event
.value
, errno
, strerror(errno
));
681 * set the current state of the js device as it would be with the middle
684 #define CENTER_AXIS(a) \
685 (ji->axes[a] == -1 ? 0 : joystick_map_axis( &ji->props[ji->axes[a]], \
686 ji->joydev->axes[a].value ))
687 static void fake_current_js_state(JoystickImpl
*ji
)
691 /* center the axes */
692 ji
->js
.lX
= CENTER_AXIS(ABS_X
);
693 ji
->js
.lY
= CENTER_AXIS(ABS_Y
);
694 ji
->js
.lZ
= CENTER_AXIS(ABS_Z
);
695 ji
->js
.lRx
= CENTER_AXIS(ABS_RX
);
696 ji
->js
.lRy
= CENTER_AXIS(ABS_RY
);
697 ji
->js
.lRz
= CENTER_AXIS(ABS_RZ
);
698 ji
->js
.rglSlider
[0] = CENTER_AXIS(ABS_THROTTLE
);
699 ji
->js
.rglSlider
[1] = CENTER_AXIS(ABS_RUDDER
);
701 /* POV center is -1 */
702 for (i
= 0; i
< 4; i
++)
703 ji
->js
.rgdwPOV
[i
] = -1;
707 /* convert wine format offset to user format object index */
708 static void joy_polldev(JoystickImpl
*This
)
711 struct input_event ie
;
721 plfd
.fd
= This
->joyfd
;
722 plfd
.events
= POLLIN
;
724 if (poll(&plfd
,1,0) != 1)
727 /* we have one event, so we can read */
728 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
731 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
733 case EV_KEY
: /* button */
735 int btn
= This
->buttons
[ie
.code
];
737 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
741 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
742 This
->js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
748 int axis
= This
->axes
[ie
.code
];
752 inst_id
= DIDFT_MAKEINSTANCE(axis
) | (ie
.code
< ABS_HAT0X
? DIDFT_ABSAXIS
: DIDFT_POV
);
753 value
= joystick_map_axis(&This
->props
[id_to_object(This
->base
.data_format
.wine_df
, inst_id
)], ie
.value
);
756 case ABS_X
: This
->js
.lX
= value
; break;
757 case ABS_Y
: This
->js
.lY
= value
; break;
758 case ABS_Z
: This
->js
.lZ
= value
; break;
759 case ABS_RX
: This
->js
.lRx
= value
; break;
760 case ABS_RY
: This
->js
.lRy
= value
; break;
761 case ABS_RZ
: This
->js
.lRz
= value
; break;
762 case ABS_THROTTLE
: This
->js
.rglSlider
[0] = value
; break;
763 case ABS_RUDDER
: This
->js
.rglSlider
[1] = value
; break;
764 case ABS_HAT0X
: case ABS_HAT0Y
: case ABS_HAT1X
: case ABS_HAT1Y
:
765 case ABS_HAT2X
: case ABS_HAT2Y
: case ABS_HAT3X
: case ABS_HAT3Y
:
767 int idx
= (ie
.code
- ABS_HAT0X
) / 2;
770 This
->povs
[idx
].y
= ie
.value
;
772 This
->povs
[idx
].x
= ie
.value
;
774 This
->js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
778 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
782 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
784 This
->ff_state
= ie
.value
;
789 /* there is nothing to do */
793 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
797 queue_event((LPDIRECTINPUTDEVICE8A
)This
,
798 id_to_offset(&This
->base
.data_format
, inst_id
),
799 value
, ie
.time
.tv_usec
, This
->base
.dinput
->evsequence
++);
803 /******************************************************************************
804 * GetDeviceState : returns the "state" of the joystick.
807 static HRESULT WINAPI
JoystickAImpl_GetDeviceState(
808 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
810 JoystickImpl
*This
= (JoystickImpl
*)iface
;
812 TRACE("(this=%p,0x%08x,%p)\n", This
, len
, ptr
);
814 if (!This
->base
.acquired
)
816 WARN("not acquired\n");
817 return DIERR_NOTACQUIRED
;
822 /* convert and copy data to user supplied buffer */
823 fill_DataFormat(ptr
, len
, &This
->js
, &This
->base
.data_format
);
828 /******************************************************************************
829 * SetProperty : change input device properties
831 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
835 JoystickImpl
*This
= (JoystickImpl
*)iface
;
838 WARN("invalid argument\n");
839 return DIERR_INVALIDPARAM
;
842 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
843 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
844 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
846 if (!HIWORD(rguid
)) {
847 switch (LOWORD(rguid
)) {
848 case (DWORD_PTR
)DIPROP_RANGE
: {
849 LPCDIPROPRANGE pr
= (LPCDIPROPRANGE
)ph
;
851 if (ph
->dwHow
== DIPH_DEVICE
) {
853 TRACE("proprange(%d,%d) all\n", pr
->lMin
, pr
->lMax
);
854 for (i
= 0; i
< This
->base
.data_format
.wine_df
->dwNumObjs
; i
++) {
855 /* Scale dead-zone */
856 This
->props
[i
].lDeadZone
= MulDiv(This
->props
[i
].lDeadZone
, pr
->lMax
- pr
->lMin
,
857 This
->props
[i
].lMax
- This
->props
[i
].lMin
);
858 This
->props
[i
].lMin
= pr
->lMin
;
859 This
->props
[i
].lMax
= pr
->lMax
;
862 int obj
= find_property(&This
->base
.data_format
, ph
);
864 TRACE("proprange(%d,%d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
866 /* Scale dead-zone */
867 This
->props
[obj
].lDeadZone
= MulDiv(This
->props
[obj
].lDeadZone
, pr
->lMax
- pr
->lMin
,
868 This
->props
[obj
].lMax
- This
->props
[obj
].lMin
);
869 This
->props
[obj
].lMin
= pr
->lMin
;
870 This
->props
[obj
].lMax
= pr
->lMax
;
873 fake_current_js_state(This
);
876 case (DWORD_PTR
)DIPROP_DEADZONE
: {
877 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
878 if (ph
->dwHow
== DIPH_DEVICE
) {
880 TRACE("deadzone(%d) all\n", pd
->dwData
);
881 for (i
= 0; i
< This
->base
.data_format
.wine_df
->dwNumObjs
; i
++) {
882 This
->props
[i
].lDeadZone
= pd
->dwData
;
885 int obj
= find_property(&This
->base
.data_format
, ph
);
887 TRACE("deadzone(%d) obj=%d\n", pd
->dwData
, obj
);
889 This
->props
[obj
].lDeadZone
= pd
->dwData
;
892 fake_current_js_state(This
);
895 case (DWORD_PTR
)DIPROP_CALIBRATIONMODE
: {
896 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
897 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd
->dwData
);
900 case (DWORD_PTR
)DIPROP_AUTOCENTER
: {
901 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
903 TRACE("autocenter(%d)\n", pd
->dwData
);
904 This
->ff_autocenter
= pd
->dwData
== DIPROPAUTOCENTER_ON
;
908 case (DWORD_PTR
)DIPROP_SATURATION
: {
909 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
911 if (ph
->dwHow
== DIPH_DEVICE
) {
914 TRACE("saturation(%d) all\n", pd
->dwData
);
915 for (i
= 0; i
< This
->base
.data_format
.wine_df
->dwNumObjs
; i
++)
916 This
->props
[i
].lSaturation
= pd
->dwData
;
918 int obj
= find_property(&This
->base
.data_format
, ph
);
920 if (obj
< 0) return DIERR_OBJECTNOTFOUND
;
922 TRACE("saturation(%d) obj=%d\n", pd
->dwData
, obj
);
923 This
->props
[obj
].lSaturation
= pd
->dwData
;
925 fake_current_js_state(This
);
928 case (DWORD_PTR
)DIPROP_FFGAIN
: {
929 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
931 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
932 This
->ff_gain
= MulDiv(pd
->dwData
, 0xFFFF, 10000);
933 if (This
->base
.acquired
) {
934 /* Update immediately. */
935 struct input_event event
;
938 event
.code
= FF_GAIN
;
939 event
.value
= This
->ff_gain
;
940 if (write(This
->joyfd
, &event
, sizeof(event
)) == -1)
941 ERR("Failed to set gain (%i): %d %s\n", This
->ff_gain
, errno
, strerror(errno
));
946 return IDirectInputDevice2AImpl_SetProperty(iface
, rguid
, ph
);
952 static HRESULT WINAPI
JoystickAImpl_GetCapabilities(
953 LPDIRECTINPUTDEVICE8A iface
,
954 LPDIDEVCAPS lpDIDevCaps
)
956 JoystickImpl
*This
= (JoystickImpl
*)iface
;
958 TRACE("%p->(%p)\n",iface
,lpDIDevCaps
);
961 WARN("invalid pointer\n");
965 if (lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS
)) {
966 WARN("invalid argument\n");
967 return DIERR_INVALIDPARAM
;
970 lpDIDevCaps
->dwFlags
= DIDC_ATTACHED
;
971 if (This
->base
.dinput
->dwVersion
>= 0x0800)
972 lpDIDevCaps
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
974 lpDIDevCaps
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
976 if (This
->joydev
->has_ff
)
977 lpDIDevCaps
->dwFlags
|= DIDC_FORCEFEEDBACK
;
979 lpDIDevCaps
->dwAxes
= This
->numAxes
;
980 lpDIDevCaps
->dwButtons
= This
->numButtons
;
981 lpDIDevCaps
->dwPOVs
= This
->numPOVs
;
986 static HRESULT WINAPI
JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface
)
988 JoystickImpl
*This
= (JoystickImpl
*)iface
;
990 TRACE("(%p)\n",This
);
992 if (!This
->base
.acquired
)
993 return DIERR_NOTACQUIRED
;
999 /******************************************************************************
1000 * GetProperty : get input device properties
1002 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
1004 LPDIPROPHEADER pdiph
)
1006 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1008 TRACE("(this=%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
1009 _dump_DIPROPHEADER(pdiph
);
1011 if (HIWORD(rguid
)) return DI_OK
;
1013 switch (LOWORD(rguid
)) {
1014 case (DWORD_PTR
) DIPROP_RANGE
:
1016 LPDIPROPRANGE pr
= (LPDIPROPRANGE
) pdiph
;
1017 int obj
= find_property(&This
->base
.data_format
, pdiph
);
1019 if (obj
< 0) return DIERR_OBJECTNOTFOUND
;
1021 pr
->lMin
= This
->props
[obj
].lMin
;
1022 pr
->lMax
= This
->props
[obj
].lMax
;
1023 TRACE("range(%d, %d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
1026 case (DWORD_PTR
) DIPROP_DEADZONE
:
1028 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1029 int obj
= find_property(&This
->base
.data_format
, pdiph
);
1031 if (obj
< 0) return DIERR_OBJECTNOTFOUND
;
1033 pd
->dwData
= This
->props
[obj
].lDeadZone
;
1034 TRACE("deadzone(%d) obj=%d\n", pd
->dwData
, obj
);
1037 case (DWORD_PTR
) DIPROP_SATURATION
:
1039 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1040 int obj
= find_property(&This
->base
.data_format
, pdiph
);
1042 if (obj
< 0) return DIERR_OBJECTNOTFOUND
;
1044 pd
->dwData
= This
->props
[obj
].lSaturation
;
1045 TRACE("saturation(%d) obj=%d\n", pd
->dwData
, obj
);
1048 case (DWORD_PTR
) DIPROP_AUTOCENTER
:
1050 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1052 pd
->dwData
= This
->ff_autocenter
? DIPROPAUTOCENTER_ON
: DIPROPAUTOCENTER_OFF
;
1053 TRACE("autocenter(%d)\n", pd
->dwData
);
1056 case (DWORD_PTR
) DIPROP_FFGAIN
:
1058 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1060 pd
->dwData
= MulDiv(This
->ff_gain
, 10000, 0xFFFF);
1061 TRACE("DIPROP_FFGAIN(%d)\n", pd
->dwData
);
1066 return IDirectInputDevice2AImpl_GetProperty(iface
, rguid
, pdiph
);
1072 /******************************************************************************
1073 * CreateEffect - Create a new FF effect with the specified params
1075 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
,
1078 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
= (JoystickImpl
*)iface
;
1087 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
1089 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1090 TRACE("not available (compiled w/o ff support)\n");
1095 if (!(new_effect
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect
))))
1096 return DIERR_OUTOFMEMORY
;
1098 retval
= linuxinput_create_effect(&This
->joyfd
, rguid
, &new_effect
->entry
, &new_effect
->ref
);
1099 if (retval
!= DI_OK
)
1101 HeapFree(GetProcessHeap(), 0, new_effect
);
1107 retval
= IDirectInputEffect_SetParameters(new_effect
->ref
, lpeff
, 0);
1109 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1111 HeapFree(GetProcessHeap(), 0, new_effect
);
1116 list_add_tail(&This
->ff_effects
, &new_effect
->entry
);
1117 *ppdef
= new_effect
->ref
;
1119 if (pUnkOuter
!= NULL
)
1120 FIXME("Interface aggregation not implemented.\n");
1124 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1127 /*******************************************************************************
1128 * EnumEffects - Enumerate available FF effects
1130 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1131 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1135 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1136 DIEFFECTINFOA dei
; /* feif */
1137 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1138 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1140 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
1142 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1144 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1145 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1146 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1147 (*lpCallback
)(&dei
, pvRef
);
1150 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1151 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1152 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1153 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1154 (*lpCallback
)(&dei
, pvRef
);
1156 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1157 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1158 (*lpCallback
)(&dei
, pvRef
);
1160 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1161 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1162 (*lpCallback
)(&dei
, pvRef
);
1164 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1165 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1166 (*lpCallback
)(&dei
, pvRef
);
1168 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1169 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1170 (*lpCallback
)(&dei
, pvRef
);
1174 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1175 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1176 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1177 (*lpCallback
)(&dei
, pvRef
);
1180 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1181 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1182 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1183 (*lpCallback
)(&dei
, pvRef
);
1185 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1186 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1187 (*lpCallback
)(&dei
, pvRef
);
1189 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1190 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1191 (*lpCallback
)(&dei
, pvRef
);
1193 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1194 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1195 (*lpCallback
)(&dei
, pvRef
);
1204 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1205 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1209 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1210 /* seems silly to duplicate all this code but all the structures and functions
1211 * are actually different (A/W) */
1212 DIEFFECTINFOW dei
; /* feif */
1213 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1214 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1215 int xfd
= This
->joyfd
;
1217 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1219 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1221 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1222 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1223 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1224 (*lpCallback
)(&dei
, pvRef
);
1227 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1228 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1229 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1230 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1231 (*lpCallback
)(&dei
, pvRef
);
1233 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1234 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1235 (*lpCallback
)(&dei
, pvRef
);
1237 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1238 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1239 (*lpCallback
)(&dei
, pvRef
);
1241 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1242 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1243 (*lpCallback
)(&dei
, pvRef
);
1245 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1246 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1247 (*lpCallback
)(&dei
, pvRef
);
1251 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1252 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1253 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1254 (*lpCallback
)(&dei
, pvRef
);
1257 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1258 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1259 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1260 (*lpCallback
)(&dei
, pvRef
);
1262 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1263 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1264 (*lpCallback
)(&dei
, pvRef
);
1266 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1267 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1268 (*lpCallback
)(&dei
, pvRef
);
1270 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1271 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1272 (*lpCallback
)(&dei
, pvRef
);
1276 /* return to unacquired state if that's where it was */
1278 IDirectInputDevice8_Unacquire(iface
);
1284 /*******************************************************************************
1285 * GetEffectInfo - Get information about a particular effect
1287 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1288 LPDIEFFECTINFOA pdei
,
1291 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1293 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1295 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1296 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1302 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1303 LPDIEFFECTINFOW pdei
,
1306 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1308 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1310 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1311 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1317 /*******************************************************************************
1318 * GetForceFeedbackState - Get information about the device's FF state
1320 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(
1321 LPDIRECTINPUTDEVICE8A iface
,
1324 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1326 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1330 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1331 /* DIGFFS_STOPPED is the only mandatory flag to report */
1332 if (This
->ff_state
== FF_STATUS_STOPPED
)
1333 (*pdwOut
) |= DIGFFS_STOPPED
;
1339 /*******************************************************************************
1340 * SendForceFeedbackCommand - Send a command to the device's FF system
1342 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(
1343 LPDIRECTINPUTDEVICE8A iface
,
1346 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1347 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1349 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1352 case DISFFC_STOPALL
:
1354 /* Stop all effects */
1355 effect_list_item
*itr
;
1357 LIST_FOR_EACH_ENTRY(itr
, &This
->ff_effects
, effect_list_item
, entry
)
1358 IDirectInputEffect_Stop(itr
->ref
);
1364 effect_list_item
*itr
, *ptr
;
1366 /* Stop, unload, release and free all effects */
1367 /* This returns the device to its "bare" state */
1368 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1369 IDirectInputEffect_Release(itr
->ref
);
1373 case DISFFC_CONTINUE
:
1374 FIXME("No support for Pause or Continue in linux\n");
1377 case DISFFC_SETACTUATORSOFF
:
1378 case DISFFC_SETACTUATORSON
:
1379 FIXME("No direct actuator control in linux\n");
1383 FIXME("Unknown Force Feedback Command!\n");
1384 return DIERR_INVALIDPARAM
;
1388 return DIERR_UNSUPPORTED
;
1392 /*******************************************************************************
1393 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1394 * created for this device.
1396 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(
1397 LPDIRECTINPUTDEVICE8A iface
,
1398 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1402 /* this function is safe to call on non-ff-enabled builds */
1403 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1404 effect_list_item
*itr
, *ptr
;
1406 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1409 return DIERR_INVALIDPARAM
;
1412 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1414 LIST_FOR_EACH_ENTRY_SAFE(itr
, ptr
, &This
->ff_effects
, effect_list_item
, entry
)
1415 (*lpCallback
)(itr
->ref
, pvRef
);
1420 /******************************************************************************
1421 * GetDeviceInfo : get information about a device's identity
1423 static HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface
,
1424 LPDIDEVICEINSTANCEA pdidi
)
1426 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1428 TRACE("(%p) %p\n", This
, pdidi
);
1430 if (pdidi
== NULL
) return E_POINTER
;
1431 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1432 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)))
1433 return DIERR_INVALIDPARAM
;
1435 fill_joystick_dideviceinstanceA(pdidi
, This
->base
.dinput
->dwVersion
,
1436 get_joystick_index(&This
->base
.guid
));
1440 static HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
,
1441 LPDIDEVICEINSTANCEW pdidi
)
1443 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1445 TRACE("(%p) %p\n", This
, pdidi
);
1447 if (pdidi
== NULL
) return E_POINTER
;
1448 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1449 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)))
1450 return DIERR_INVALIDPARAM
;
1452 fill_joystick_dideviceinstanceW(pdidi
, This
->base
.dinput
->dwVersion
,
1453 get_joystick_index(&This
->base
.guid
));
1457 static const IDirectInputDevice8AVtbl JoystickAvt
=
1459 IDirectInputDevice2AImpl_QueryInterface
,
1460 IDirectInputDevice2AImpl_AddRef
,
1461 IDirectInputDevice2AImpl_Release
,
1462 JoystickAImpl_GetCapabilities
,
1463 IDirectInputDevice2AImpl_EnumObjects
,
1464 JoystickAImpl_GetProperty
,
1465 JoystickAImpl_SetProperty
,
1466 JoystickAImpl_Acquire
,
1467 JoystickAImpl_Unacquire
,
1468 JoystickAImpl_GetDeviceState
,
1469 IDirectInputDevice2AImpl_GetDeviceData
,
1470 IDirectInputDevice2AImpl_SetDataFormat
,
1471 IDirectInputDevice2AImpl_SetEventNotification
,
1472 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1473 JoystickAGenericImpl_GetObjectInfo
,
1474 JoystickAImpl_GetDeviceInfo
,
1475 IDirectInputDevice2AImpl_RunControlPanel
,
1476 IDirectInputDevice2AImpl_Initialize
,
1477 JoystickAImpl_CreateEffect
,
1478 JoystickAImpl_EnumEffects
,
1479 JoystickAImpl_GetEffectInfo
,
1480 JoystickAImpl_GetForceFeedbackState
,
1481 JoystickAImpl_SendForceFeedbackCommand
,
1482 JoystickAImpl_EnumCreatedEffectObjects
,
1483 IDirectInputDevice2AImpl_Escape
,
1485 IDirectInputDevice2AImpl_SendDeviceData
,
1486 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1487 IDirectInputDevice7AImpl_WriteEffectToFile
,
1488 IDirectInputDevice8AImpl_BuildActionMap
,
1489 IDirectInputDevice8AImpl_SetActionMap
,
1490 IDirectInputDevice8AImpl_GetImageInfo
1493 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1494 # define XCAST(fun) (typeof(JoystickWvt.fun))
1496 # define XCAST(fun) (void*)
1499 static const IDirectInputDevice8WVtbl JoystickWvt
=
1501 IDirectInputDevice2WImpl_QueryInterface
,
1502 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
1503 XCAST(Release
)IDirectInputDevice2AImpl_Release
,
1504 XCAST(GetCapabilities
)JoystickAImpl_GetCapabilities
,
1505 IDirectInputDevice2WImpl_EnumObjects
,
1506 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1507 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1508 XCAST(Acquire
)JoystickAImpl_Acquire
,
1509 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1510 XCAST(GetDeviceState
)JoystickAImpl_GetDeviceState
,
1511 XCAST(GetDeviceData
)IDirectInputDevice2AImpl_GetDeviceData
,
1512 XCAST(SetDataFormat
)IDirectInputDevice2AImpl_SetDataFormat
,
1513 XCAST(SetEventNotification
)IDirectInputDevice2AImpl_SetEventNotification
,
1514 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
1515 JoystickWGenericImpl_GetObjectInfo
,
1516 JoystickWImpl_GetDeviceInfo
,
1517 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
1518 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
1519 XCAST(CreateEffect
)JoystickAImpl_CreateEffect
,
1520 JoystickWImpl_EnumEffects
,
1521 JoystickWImpl_GetEffectInfo
,
1522 XCAST(GetForceFeedbackState
)JoystickAImpl_GetForceFeedbackState
,
1523 XCAST(SendForceFeedbackCommand
)JoystickAImpl_SendForceFeedbackCommand
,
1524 XCAST(EnumCreatedEffectObjects
)JoystickAImpl_EnumCreatedEffectObjects
,
1525 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1526 XCAST(Poll
)JoystickAImpl_Poll
,
1527 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1528 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1529 IDirectInputDevice7WImpl_WriteEffectToFile
,
1530 IDirectInputDevice8WImpl_BuildActionMap
,
1531 IDirectInputDevice8WImpl_SetActionMap
,
1532 IDirectInputDevice8WImpl_GetImageInfo
1536 #else /* HAVE_CORRECT_LINUXINPUT_H */
1538 const struct dinput_device joystick_linuxinput_device
= {
1539 "Wine Linux-input joystick driver",
1546 #endif /* HAVE_CORRECT_LINUXINPUT_H */