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>
37 #include <sys/fcntl.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>
47 # if defined(EVIOCGBIT) && defined(EV_ABS) && defined(BTN_PINKIE)
48 # define HAVE_CORRECT_LINUXINPUT_H
51 #ifdef HAVE_SYS_POLL_H
52 # include <sys/poll.h>
55 #include "wine/debug.h"
56 #include "wine/unicode.h"
62 #include "dinput_private.h"
63 #include "device_private.h"
65 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
67 #ifdef HAVE_CORRECT_LINUXINPUT_H
69 #define EVDEVPREFIX "/dev/input/event"
71 /* Wine joystick driver object instances */
72 #define WINE_JOYSTICK_AXIS_BASE 0
73 #define WINE_JOYSTICK_POV_BASE 6
74 #define WINE_JOYSTICK_BUTTON_BASE 8
76 typedef struct EffectListItem EffectListItem
;
79 LPDIRECTINPUTEFFECT ref
;
80 struct EffectListItem
* next
;
83 /* implemented in effect_linuxinput.c */
84 HRESULT
linuxinput_create_effect(int* fd
, REFGUID rguid
, LPDIRECTINPUTEFFECT
* peff
);
85 HRESULT
linuxinput_get_info_A(int fd
, REFGUID rguid
, LPDIEFFECTINFOA info
);
86 HRESULT
linuxinput_get_info_W(int fd
, REFGUID rguid
, LPDIEFFECTINFOW info
);
88 typedef struct JoystickImpl JoystickImpl
;
89 static const IDirectInputDevice8AVtbl JoystickAvt
;
90 static const IDirectInputDevice8WVtbl JoystickWvt
;
100 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
101 BYTE evbits
[(EV_MAX
+7)/8];
102 BYTE absbits
[(ABS_MAX
+7)/8];
103 BYTE keybits
[(KEY_MAX
+7)/8];
104 BYTE ffbits
[(FF_MAX
+7)/8];
109 #define AXE_ABSFUZZ 3
110 #define AXE_ABSFLAT 4
112 /* data returned by the EVIOCGABS() ioctl */
113 int axes
[ABS_MAX
][5];
114 /* LUT for KEY_ to offset in rgbButtons */
115 BYTE buttons
[KEY_MAX
];
117 /* autodetecting ranges per axe by following movement */
118 LONG havemax
[ABS_MAX
];
119 LONG havemin
[ABS_MAX
];
124 struct IDirectInputDevice2AImpl base
;
126 struct JoyDev
*joydev
;
128 /* The 'parent' DInput */
129 IDirectInputImpl
*dinput
;
131 /* joystick private */
132 /* what range and deadzone the game wants */
133 LONG wantmin
[ABS_MAX
];
134 LONG wantmax
[ABS_MAX
];
140 DataFormat
*transform
; /* wine to user format converter */
141 int *offsets
; /* object offsets */
144 /* Force feedback variables */
145 EffectListItem
* top_effect
;
149 static void fake_current_js_state(JoystickImpl
*ji
);
150 static int find_property_offset(JoystickImpl
*This
, LPCDIPROPHEADER ph
);
151 static DWORD
map_pov(int event_value
, int is_x
);
152 static void find_joydevs(void);
153 static int lxinput_to_user_offset(JoystickImpl
*This
, int ie_type
, int ie_code
);
154 static int offset_to_object(JoystickImpl
*This
, int offset
);
156 /* This GUID is slightly different from the linux joystick one. Take note. */
157 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
161 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
164 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
166 #define MAX_JOYDEV 64
168 static int have_joydevs
= -1;
169 static struct JoyDev
*joydevs
= NULL
;
171 static void find_joydevs(void)
175 if (have_joydevs
!=-1) {
181 for (i
=0;i
<MAX_JOYDEV
;i
++) {
183 struct JoyDev joydev
= {0};
188 snprintf(buf
,MAX_PATH
,EVDEVPREFIX
"%d",i
);
191 if ((fd
=open(buf
, O_RDWR
))==-1) {
192 fd
= open(buf
, O_RDONLY
);
197 if ((-1==ioctl(fd
,EVIOCGBIT(0,sizeof(joydev
.evbits
)),joydev
.evbits
))) {
198 perror("EVIOCGBIT 0");
202 if (-1==ioctl(fd
,EVIOCGBIT(EV_ABS
,sizeof(joydev
.absbits
)),joydev
.absbits
)) {
203 perror("EVIOCGBIT EV_ABS");
207 if (-1==ioctl(fd
,EVIOCGBIT(EV_KEY
,sizeof(joydev
.keybits
)),joydev
.keybits
)) {
208 perror("EVIOCGBIT EV_KEY");
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
.keybits
,BTN_TRIGGER
) ||
216 test_bit(joydev
.keybits
,BTN_A
) ||
217 test_bit(joydev
.keybits
,BTN_1
)
221 joydev
.device
= strdup(buf
);
223 if (-1!=ioctl(fd
, EVIOCGNAME(MAX_PATH
-1), buf
)) {
225 joydev
.name
= strdup(buf
);
227 joydev
.name
= joydev
.device
;
230 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
231 joydev
.guid
.Data3
+= have_joydevs
;
233 TRACE("Found a joystick on %s: %s (%s)\n",
234 joydev
.device
, joydev
.name
,
235 debugstr_guid(&joydev
.guid
)
238 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
240 if ((!test_bit(joydev
.evbits
,EV_FF
))
241 || (-1==ioctl(fd
,EVIOCGBIT(EV_FF
,sizeof(joydev
.ffbits
)),joydev
.ffbits
))
242 || (-1==ioctl(fd
,EVIOCGEFFECTS
,&joydev
.num_effects
))
243 || (joydev
.num_effects
<= 0)) {
246 TRACE(" ... with force feedback\n");
252 for (j
=0;j
<ABS_MAX
;j
++) {
253 if (test_bit(joydev
.absbits
,j
)) {
254 if (-1!=ioctl(fd
,EVIOCGABS(j
),&(joydev
.axes
[j
]))) {
255 TRACE(" ... with axe %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
257 joydev
.axes
[j
][AXE_ABS
],
258 joydev
.axes
[j
][AXE_ABSMIN
],
259 joydev
.axes
[j
][AXE_ABSMAX
],
260 joydev
.axes
[j
][AXE_ABSFUZZ
],
261 joydev
.axes
[j
][AXE_ABSFLAT
]
263 joydev
.havemin
[j
] = joydev
.axes
[j
][AXE_ABSMIN
];
264 joydev
.havemax
[j
] = joydev
.axes
[j
][AXE_ABSMAX
];
270 for (j
=0;j
<KEY_MAX
;j
++) {
271 if (test_bit(joydev
.keybits
,j
)) {
272 TRACE(" ... with button %d: %d\n", j
, buttons
);
273 joydev
.buttons
[j
] = 0x80 | buttons
;
278 if (have_joydevs
==0) {
279 joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
281 HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1+have_joydevs
) * sizeof(struct JoyDev
));
283 memcpy(joydevs
+have_joydevs
, &joydev
, sizeof(struct JoyDev
));
292 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
296 if (id
>= have_joydevs
) {
300 if (!((dwDevType
== 0) ||
301 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
< 0x0800)) ||
302 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
305 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
306 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
310 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
311 lpddi
->guidInstance
= joydevs
[id
].guid
;
312 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
314 lpddi
->guidFFDriver
= GUID_NULL
;
315 if (version
>= 0x0800)
316 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
318 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
320 strcpy(lpddi
->tszInstanceName
, joydevs
[id
].name
);
321 strcpy(lpddi
->tszProductName
, joydevs
[id
].device
);
327 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
331 if (id
>= have_joydevs
) {
335 if (!((dwDevType
== 0) ||
336 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
< 0x0800)) ||
337 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
340 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
341 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
345 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
346 lpddi
->guidInstance
= joydevs
[id
].guid
;
347 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
349 lpddi
->guidFFDriver
= GUID_NULL
;
350 if (version
>= 0x0800)
351 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
353 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
355 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
356 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].device
, -1, lpddi
->tszProductName
, MAX_PATH
);
362 static JoystickImpl
*alloc_device(REFGUID rguid
, const void *jvt
, IDirectInputImpl
*dinput
, struct JoyDev
*joydev
)
364 JoystickImpl
* newDevice
;
367 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(JoystickImpl
));
368 if (newDevice
==NULL
) {
372 newDevice
->base
.lpVtbl
= jvt
;
373 newDevice
->base
.ref
= 1;
374 memcpy(&newDevice
->base
.guid
, rguid
, sizeof(*rguid
));
375 InitializeCriticalSection(&newDevice
->base
.crit
);
376 newDevice
->joyfd
= -1;
377 newDevice
->dinput
= dinput
;
378 newDevice
->joydev
= joydev
;
379 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
380 newDevice
->ff_state
= FF_STATUS_STOPPED
;
382 for (i
=0;i
<ABS_MAX
;i
++) {
383 /* apps expect the range to be the same they would get from the
384 * GetProperty/range method */
385 newDevice
->wantmin
[i
] = newDevice
->joydev
->havemin
[i
];
386 newDevice
->wantmax
[i
] = newDevice
->joydev
->havemax
[i
];
388 * direct input defines a default for the deadzone somewhere; but as long
389 * as in map_axis the code for the dead zone is commented out its no
392 newDevice
->deadz
[i
] = 0;
394 fake_current_js_state(newDevice
);
396 /* wine uses DIJOYSTATE2 as it's internal format so copy
397 * the already defined format c_dfDIJoystick2 */
398 newDevice
->df
= HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2
.dwSize
);
399 if (newDevice
->df
== 0)
401 CopyMemory(newDevice
->df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
403 /* copy default objects */
404 newDevice
->df
->rgodf
= HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2
.dwNumObjs
*c_dfDIJoystick2
.dwObjSize
);
405 if (newDevice
->df
->rgodf
== 0)
407 CopyMemory(newDevice
->df
->rgodf
,c_dfDIJoystick2
.rgodf
,c_dfDIJoystick2
.dwNumObjs
*c_dfDIJoystick2
.dwObjSize
);
409 /* create an offsets array */
410 newDevice
->offsets
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,c_dfDIJoystick2
.dwNumObjs
*sizeof(int));
411 if (newDevice
->offsets
== 0)
414 /* create the default transform filter */
415 newDevice
->transform
= create_DataFormat(&c_dfDIJoystick2
, newDevice
->df
, newDevice
->offsets
);
420 HeapFree(GetProcessHeap(),0,newDevice
->df
->rgodf
);
421 HeapFree(GetProcessHeap(),0,newDevice
->df
);
422 HeapFree(GetProcessHeap(),0,newDevice
);
426 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
432 for (i
=0; i
<have_joydevs
; i
++) {
433 if (IsEqualGUID(&GUID_Joystick
,rguid
) ||
434 IsEqualGUID(&joydevs
[i
].guid
,rguid
)
436 if ((riid
== NULL
) ||
437 IsEqualGUID(&IID_IDirectInputDeviceA
,riid
) ||
438 IsEqualGUID(&IID_IDirectInputDevice2A
,riid
) ||
439 IsEqualGUID(&IID_IDirectInputDevice7A
,riid
) ||
440 IsEqualGUID(&IID_IDirectInputDevice8A
,riid
)) {
441 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &JoystickAvt
, dinput
, &joydevs
[i
]);
442 TRACE("Creating a Joystick device (%p)\n", *pdev
);
444 ERR("out of memory\n");
445 return DIERR_OUTOFMEMORY
;
449 return DIERR_NOINTERFACE
;
454 return DIERR_DEVICENOTREG
;
458 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
464 for (i
=0; i
<have_joydevs
; i
++) {
465 if (IsEqualGUID(&GUID_Joystick
,rguid
) ||
466 IsEqualGUID(&joydevs
[i
].guid
,rguid
)
468 if ((riid
== NULL
) ||
469 IsEqualGUID(&IID_IDirectInputDeviceW
,riid
) ||
470 IsEqualGUID(&IID_IDirectInputDevice2W
,riid
) ||
471 IsEqualGUID(&IID_IDirectInputDevice7W
,riid
) ||
472 IsEqualGUID(&IID_IDirectInputDevice8W
,riid
)) {
473 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &JoystickWvt
, dinput
, &joydevs
[i
]);
474 TRACE("Creating a Joystick device (%p)\n", *pdev
);
476 ERR("out of memory\n");
477 return DIERR_OUTOFMEMORY
;
481 return DIERR_NOINTERFACE
;
486 return DIERR_DEVICENOTREG
;
489 const struct dinput_device joystick_linuxinput_device
= {
490 "Wine Linux-input joystick driver",
493 joydev_create_deviceA
,
494 joydev_create_deviceW
497 /******************************************************************************
500 static ULONG WINAPI
JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface
)
502 JoystickImpl
*This
= (JoystickImpl
*)iface
;
505 ref
= InterlockedDecrement(&This
->base
.ref
);
509 /* Reset the FF state, free all effects, etc */
510 IDirectInputDevice8_SendForceFeedbackCommand(iface
, DISFFC_RESET
);
512 /* Free the data queue */
513 HeapFree(GetProcessHeap(), 0, This
->base
.data_queue
);
515 /* Free the DataFormat */
516 HeapFree(GetProcessHeap(), 0, This
->df
->rgodf
);
517 HeapFree(GetProcessHeap(), 0, This
->df
);
519 /* Free the offsets array */
520 HeapFree(GetProcessHeap(),0,This
->offsets
);
522 /* release the data transform filter */
523 release_DataFormat(This
->transform
);
525 DeleteCriticalSection(&This
->base
.crit
);
527 HeapFree(GetProcessHeap(),0,This
);
531 /******************************************************************************
532 * SetDataFormat : the application can choose the format of the data
533 * the device driver sends back with GetDeviceState.
535 static HRESULT WINAPI
JoystickAImpl_SetDataFormat(
536 LPDIRECTINPUTDEVICE8A iface
,LPCDIDATAFORMAT df
539 JoystickImpl
*This
= (JoystickImpl
*)iface
;
541 TRACE("(this=%p,%p)\n",This
,df
);
544 WARN("invalid pointer\n");
548 if (df
->dwSize
!= sizeof(*df
)) {
549 WARN("invalid argument\n");
550 return DIERR_INVALIDPARAM
;
553 _dump_DIDATAFORMAT(df
);
555 if (This
->joyfd
!=-1) {
557 return DIERR_ACQUIRED
;
560 HeapFree(GetProcessHeap(),0,This
->df
->rgodf
);
561 HeapFree(GetProcessHeap(),0,This
->df
);
562 release_DataFormat(This
->transform
);
564 /* Store the new data format */
565 This
->df
= HeapAlloc(GetProcessHeap(),0,df
->dwSize
);
566 if (This
->df
==NULL
) {
567 return DIERR_OUTOFMEMORY
;
569 memcpy(This
->df
, df
, df
->dwSize
);
570 This
->df
->rgodf
= HeapAlloc(GetProcessHeap(),0,df
->dwNumObjs
*df
->dwObjSize
);
571 if (This
->df
->rgodf
==NULL
) {
572 HeapFree(GetProcessHeap(), 0, This
->df
);
573 return DIERR_OUTOFMEMORY
;
575 memcpy(This
->df
->rgodf
,df
->rgodf
,df
->dwNumObjs
*df
->dwObjSize
);
577 This
->transform
= create_DataFormat(&c_dfDIJoystick2
, This
->df
, This
->offsets
);
582 /******************************************************************************
583 * Acquire : gets exclusive control of the joystick
585 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
587 JoystickImpl
*This
= (JoystickImpl
*)iface
;
590 TRACE("(this=%p)\n",This
);
592 if (This
->df
==NULL
) {
593 return DIERR_INVALIDPARAM
;
595 res
= IDirectInputDevice2AImpl_Acquire(iface
);
597 if (-1==(This
->joyfd
=open(This
->joydev
->device
,O_RDWR
))) {
598 if (-1==(This
->joyfd
=open(This
->joydev
->device
,O_RDONLY
))) {
599 /* Couldn't open the device at all */
600 perror(This
->joydev
->device
);
601 IDirectInputDevice2AImpl_Unacquire(iface
);
602 return DIERR_NOTFOUND
;
604 /* Couldn't open in r/w but opened in read-only. */
605 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
613 /******************************************************************************
614 * Unacquire : frees the joystick
616 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
618 JoystickImpl
*This
= (JoystickImpl
*)iface
;
621 TRACE("(this=%p)\n",This
);
622 res
= IDirectInputDevice2AImpl_Unacquire(iface
);
623 if (res
==DI_OK
&& This
->joyfd
!=-1) {
631 * This maps the read value (from the input event) to a value in the
632 * 'wanted' range. It also autodetects the possible range of the axe and
633 * adapts values accordingly.
636 map_axis(JoystickImpl
* This
, int axis
, int val
) {
637 int xmin
= This
->joydev
->axes
[axis
][AXE_ABSMIN
];
638 int xmax
= This
->joydev
->axes
[axis
][AXE_ABSMAX
];
639 int hmax
= This
->joydev
->havemax
[axis
];
640 int hmin
= This
->joydev
->havemin
[axis
];
641 int wmin
= This
->wantmin
[axis
];
642 int wmax
= This
->wantmax
[axis
];
645 if (val
> hmax
) This
->joydev
->havemax
[axis
] = hmax
= val
;
646 if (val
< hmin
) This
->joydev
->havemin
[axis
] = hmin
= val
;
648 if (xmin
== xmax
) return val
;
650 /* map the value from the hmin-hmax range into the wmin-wmax range */
651 ret
= MulDiv( val
- hmin
, wmax
- wmin
, hmax
- hmin
) + wmin
;
653 TRACE("xmin=%d xmax=%d hmin=%d hmax=%d wmin=%d wmax=%d val=%d ret=%d\n", xmin
, xmax
, hmin
, hmax
, wmin
, wmax
, val
, ret
);
656 /* deadzone doesn't work comfortably enough right now. needs more testing*/
657 if ((ret
> -deadz
/2 ) && (ret
< deadz
/2)) {
658 FIXME("%d in deadzone, return mid.\n",val
);
659 return (wmax
-wmin
)/2+wmin
;
666 * set the current state of the js device as it would be with the middle
669 static void fake_current_js_state(JoystickImpl
*ji
)
672 /* center the axes */
673 ji
->js
.lX
= test_bit(ji
->joydev
->absbits
, ABS_X
) ? map_axis(ji
, ABS_X
, ji
->joydev
->axes
[ABS_X
][AXE_ABS
]) : 0;
674 ji
->js
.lY
= test_bit(ji
->joydev
->absbits
, ABS_Y
) ? map_axis(ji
, ABS_Y
, ji
->joydev
->axes
[ABS_Y
][AXE_ABS
]) : 0;
675 ji
->js
.lZ
= test_bit(ji
->joydev
->absbits
, ABS_Z
) ? map_axis(ji
, ABS_Z
, ji
->joydev
->axes
[ABS_Z
][AXE_ABS
]) : 0;
676 ji
->js
.lRx
= test_bit(ji
->joydev
->absbits
, ABS_RX
) ? map_axis(ji
, ABS_RX
, ji
->joydev
->axes
[ABS_RX
][AXE_ABS
]) : 0;
677 ji
->js
.lRy
= test_bit(ji
->joydev
->absbits
, ABS_RY
) ? map_axis(ji
, ABS_RY
, ji
->joydev
->axes
[ABS_RY
][AXE_ABS
]) : 0;
678 ji
->js
.lRz
= test_bit(ji
->joydev
->absbits
, ABS_RZ
) ? map_axis(ji
, ABS_RZ
, ji
->joydev
->axes
[ABS_RZ
][AXE_ABS
]) : 0;
679 ji
->js
.rglSlider
[0] = test_bit(ji
->joydev
->absbits
, ABS_THROTTLE
) ? map_axis(ji
, ABS_THROTTLE
, ji
->joydev
->axes
[ABS_THROTTLE
][AXE_ABS
]) : 0;
680 ji
->js
.rglSlider
[1] = test_bit(ji
->joydev
->absbits
, ABS_RUDDER
) ? map_axis(ji
, ABS_RUDDER
, ji
->joydev
->axes
[ABS_RUDDER
][AXE_ABS
]) : 0;
681 /* POV center is -1 */
682 for (i
=0; i
<4; i
++) {
683 ji
->js
.rgdwPOV
[i
] = -1;
688 * Maps an event value to a DX "clock" position:
693 static DWORD
map_pov(int event_value
, int is_x
)
699 } else if (event_value
>0) {
705 } else if (event_value
>0) {
712 static int find_property_offset(JoystickImpl
*This
, LPCDIPROPHEADER ph
)
717 for (i
=0; i
<This
->df
->dwNumObjs
; i
++) {
718 if (This
->offsets
[i
]==ph
->dwObj
) {
724 for (i
=0; i
<This
->df
->dwNumObjs
; i
++) {
725 if ((This
->df
->rgodf
[i
].dwType
& 0x00ffffff) == (ph
->dwObj
& 0x00ffffff)) {
726 ofs
= This
->df
->rgodf
[i
].dwOfs
;
731 for (i
=0; i
<This
->df
->dwNumObjs
; i
++) {
732 if (This
->offsets
[i
]==ofs
) {
739 FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph
->dwHow
);
745 /* defines how the linux input system offset mappings into c_dfDIJoystick2 */
747 lxinput_to_user_offset(JoystickImpl
*This
, int ie_type
, int ie_code
)
753 case ABS_X
: offset
= 0; break;
754 case ABS_Y
: offset
= 1; break;
755 case ABS_Z
: offset
= 2; break;
756 case ABS_RX
: offset
= 3; break;
757 case ABS_RY
: offset
= 4; break;
758 case ABS_RZ
: offset
= 5; break;
759 case ABS_THROTTLE
: offset
= 6; break;
760 case ABS_RUDDER
: offset
= 7; break;
761 case ABS_HAT0X
: case ABS_HAT0Y
: offset
= 8; break;
762 case ABS_HAT1X
: case ABS_HAT1Y
: offset
= 9; break;
763 case ABS_HAT2X
: case ABS_HAT2Y
: offset
= 10; break;
764 case ABS_HAT3X
: case ABS_HAT3Y
: offset
= 11; break;
765 /* XXX when adding new axes here also fix the offset for the buttons bellow */
767 FIXME("Unhandled EV_ABS(0x%02X)\n", ie_code
);
772 if (ie_code
>= 128) {
773 WARN("DX8 does not support more than 128 buttons\n");
776 offset
= 12 + ie_code
; /* XXX */
779 FIXME("Unhandled type(0x%02X)\n", ie_type
);
782 return This
->offsets
[offset
];
785 /* convert wine format offset to user format object index */
786 static int offset_to_object(JoystickImpl
*This
, int offset
)
790 for (i
= 0; i
< This
->df
->dwNumObjs
; i
++) {
791 if (This
->df
->rgodf
[i
].dwOfs
== offset
)
798 static void joy_polldev(JoystickImpl
*This
) {
800 struct input_event ie
;
807 plfd
.fd
= This
->joyfd
;
808 plfd
.events
= POLLIN
;
810 if (poll(&plfd
,1,0) != 1)
813 /* we have one event, so we can read */
814 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
817 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
819 case EV_KEY
: /* button */
820 btn
= This
->joydev
->buttons
[ie
.code
];
821 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
824 if ((offset
= lxinput_to_user_offset(This
, ie
.type
, btn
)) == -1) {
827 This
->js
.rgbButtons
[btn
] = ie
.value
?0x80:0x00;
828 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, This
->js
.rgbButtons
[btn
],
829 ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
833 if ((offset
= lxinput_to_user_offset(This
, ie
.type
, ie
.code
)) == -1) {
838 This
->js
.lX
= map_axis(This
,ABS_X
,ie
.value
);
839 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, This
->js
.lX
,
840 ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
843 This
->js
.lY
= map_axis(This
,ABS_Y
,ie
.value
);
844 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, This
->js
.lY
,
845 ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
848 This
->js
.lZ
= map_axis(This
,ABS_Z
,ie
.value
);
849 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, This
->js
.lZ
,
850 ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
853 This
->js
.lRx
= map_axis(This
,ABS_RX
,ie
.value
);
854 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, This
->js
.lRx
,
855 ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
858 This
->js
.lRy
= map_axis(This
,ABS_RY
,ie
.value
);
859 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, This
->js
.lRy
,
860 ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
863 This
->js
.lRz
= map_axis(This
,ABS_RZ
,ie
.value
);
864 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, This
->js
.lRz
,
865 ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
868 This
->js
.rglSlider
[0] = map_axis(This
,ABS_THROTTLE
,ie
.value
);
869 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, This
->js
.rglSlider
[0],
870 ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
873 This
->js
.rglSlider
[1] = map_axis(This
,ABS_RUDDER
,ie
.value
);
874 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, This
->js
.rglSlider
[1],
875 ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
879 This
->js
.rgdwPOV
[0] = map_pov(ie
.value
,ie
.code
==ABS_HAT0X
);
880 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, This
->js
.rgdwPOV
[0],
881 ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
885 This
->js
.rgdwPOV
[1] = map_pov(ie
.value
,ie
.code
==ABS_HAT1X
);
886 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, This
->js
.rgdwPOV
[1],
887 ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
891 This
->js
.rgdwPOV
[2] = map_pov(ie
.value
,ie
.code
==ABS_HAT2X
);
892 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, This
->js
.rgdwPOV
[2],
893 ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
897 This
->js
.rgdwPOV
[3] = map_pov(ie
.value
,ie
.code
==ABS_HAT3X
);
898 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, This
->js
.rgdwPOV
[3],
899 ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
902 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie
.code
,ie
.value
);
906 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
908 This
->ff_state
= ie
.value
;
913 /* there is nothing to do */
917 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
923 /******************************************************************************
924 * GetDeviceState : returns the "state" of the joystick.
927 static HRESULT WINAPI
JoystickAImpl_GetDeviceState(
928 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
930 JoystickImpl
*This
= (JoystickImpl
*)iface
;
932 TRACE("(this=%p,0x%08x,%p)\n", This
, len
, ptr
);
934 if (This
->joyfd
==-1) {
935 WARN("not acquired\n");
936 return DIERR_NOTACQUIRED
;
941 /* convert and copy data to user supplied buffer */
942 fill_DataFormat(ptr
, &This
->js
, This
->transform
);
947 /******************************************************************************
948 * SetProperty : change input device properties
950 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
954 JoystickImpl
*This
= (JoystickImpl
*)iface
;
957 WARN("invalid argument\n");
958 return DIERR_INVALIDPARAM
;
961 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
962 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
963 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
965 if (!HIWORD(rguid
)) {
966 switch (LOWORD(rguid
)) {
967 case (DWORD
)DIPROP_RANGE
: {
968 LPCDIPROPRANGE pr
= (LPCDIPROPRANGE
)ph
;
970 if (ph
->dwHow
== DIPH_DEVICE
) {
972 TRACE("proprange(%d,%d) all\n", pr
->lMin
, pr
->lMax
);
973 for (i
= 0; i
< This
->df
->dwNumObjs
; i
++) {
974 This
->wantmin
[i
] = pr
->lMin
;
975 This
->wantmax
[i
] = pr
->lMax
;
978 int obj
= find_property_offset(This
, ph
);
979 TRACE("proprange(%d,%d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
981 This
->wantmin
[obj
] = pr
->lMin
;
982 This
->wantmax
[obj
] = pr
->lMax
;
985 fake_current_js_state(This
);
988 case (DWORD
)DIPROP_DEADZONE
: {
989 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
990 if (ph
->dwHow
== DIPH_DEVICE
) {
992 TRACE("deadzone(%d) all\n", pd
->dwData
);
993 for (i
= 0; i
< This
->df
->dwNumObjs
; i
++) {
994 This
->deadz
[i
] = pd
->dwData
;
997 int obj
= find_property_offset(This
, ph
);
998 TRACE("deadzone(%d) obj=%d\n", pd
->dwData
, obj
);
1000 This
->deadz
[obj
] = pd
->dwData
;
1003 fake_current_js_state(This
);
1006 case (DWORD
)DIPROP_CALIBRATIONMODE
: {
1007 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
1008 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd
->dwData
);
1012 return IDirectInputDevice2AImpl_SetProperty(iface
, rguid
, ph
);
1018 static HRESULT WINAPI
JoystickAImpl_GetCapabilities(
1019 LPDIRECTINPUTDEVICE8A iface
,
1020 LPDIDEVCAPS lpDIDevCaps
)
1022 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1023 int i
,axes
,buttons
,povs
;
1025 TRACE("%p->(%p)\n",iface
,lpDIDevCaps
);
1028 WARN("invalid pointer\n");
1032 if (lpDIDevCaps
->dwSize
< sizeof(DIDEVCAPS
)) {
1033 WARN("invalid argument\n");
1034 return DIERR_INVALIDPARAM
;
1037 lpDIDevCaps
->dwFlags
= DIDC_ATTACHED
;
1038 if (This
->dinput
->dwVersion
>= 0x0800)
1039 lpDIDevCaps
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
1041 lpDIDevCaps
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
1044 for (i
=0;i
<ABS_MAX
;i
++) {
1045 if (!test_bit(This
->joydev
->absbits
,i
)) continue;
1047 case ABS_HAT0X
: case ABS_HAT0Y
:
1048 case ABS_HAT1X
: case ABS_HAT1Y
:
1049 case ABS_HAT2X
: case ABS_HAT2Y
:
1050 case ABS_HAT3X
: case ABS_HAT3Y
:
1051 /* will be handled as POV - see below */
1058 for (i
=0;i
<KEY_MAX
;i
++) if (test_bit(This
->joydev
->keybits
,i
)) buttons
++;
1060 for (i
=0; i
<4; i
++) {
1061 if (test_bit(This
->joydev
->absbits
,ABS_HAT0X
+(i
<<1)) && test_bit(This
->joydev
->absbits
,ABS_HAT0Y
+(i
<<1))) {
1066 if (This
->joydev
->has_ff
)
1067 lpDIDevCaps
->dwFlags
|= DIDC_FORCEFEEDBACK
;
1069 lpDIDevCaps
->dwAxes
= axes
;
1070 lpDIDevCaps
->dwButtons
= buttons
;
1071 lpDIDevCaps
->dwPOVs
= povs
;
1076 static HRESULT WINAPI
JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface
) {
1077 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1078 TRACE("(%p)\n",This
);
1080 if (This
->joyfd
==-1) {
1081 return DIERR_NOTACQUIRED
;
1088 /******************************************************************************
1089 * EnumObjects : enumerate the different buttons and axis...
1091 static HRESULT WINAPI
JoystickAImpl_EnumObjects(
1092 LPDIRECTINPUTDEVICE8A iface
,
1093 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback
,
1097 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1098 DIDEVICEOBJECTINSTANCEA ddoi
;
1099 int user_offset
, user_object
;
1101 TRACE("(this=%p,%p,%p,%08x)\n", This
, lpCallback
, lpvRef
, dwFlags
);
1102 if (TRACE_ON(dinput
)) {
1103 TRACE(" - flags = ");
1104 _dump_EnumObjects_flags(dwFlags
);
1108 /* Only the fields till dwFFMaxForce are relevant */
1109 ddoi
.dwSize
= FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA
, dwFFMaxForce
);
1111 /* For the joystick, do as is done in the GetCapabilities function */
1112 /* FIXME: needs more items */
1113 if ((dwFlags
== DIDFT_ALL
) ||
1114 (dwFlags
& DIDFT_AXIS
)) {
1117 for (i
= 0; i
< ABS_MAX
; i
++) {
1118 if (!test_bit(This
->joydev
->absbits
,i
)) continue;
1122 ddoi
.guidType
= GUID_XAxis
;
1125 ddoi
.guidType
= GUID_YAxis
;
1128 ddoi
.guidType
= GUID_ZAxis
;
1131 ddoi
.guidType
= GUID_RxAxis
;
1134 ddoi
.guidType
= GUID_RyAxis
;
1137 ddoi
.guidType
= GUID_RzAxis
;
1141 ddoi
.guidType
= GUID_Slider
;
1143 case ABS_HAT0X
: case ABS_HAT0Y
:
1144 case ABS_HAT1X
: case ABS_HAT1Y
:
1145 case ABS_HAT2X
: case ABS_HAT2Y
:
1146 case ABS_HAT3X
: case ABS_HAT3Y
:
1147 /* will be handled as POV - see below */
1150 FIXME("unhandled abs axis 0x%02x, ignoring!\n",i
);
1153 if ((user_offset
= lxinput_to_user_offset(This
, EV_ABS
, i
)) == -1) {
1156 user_object
= offset_to_object(This
, user_offset
);
1157 ddoi
.dwType
= This
->df
->rgodf
[user_object
].dwType
& 0x00ffffff;
1158 ddoi
.dwOfs
= This
->df
->rgodf
[user_object
].dwOfs
;
1159 /* Linux event force feedback supports only (and always) x and y axes */
1160 if (i
== ABS_X
|| i
== ABS_Y
) {
1161 if (This
->joydev
->has_ff
)
1162 ddoi
.dwFlags
|= DIDOI_FFACTUATOR
;
1164 sprintf(ddoi
.tszName
, "%d-Axis", i
);
1165 _dump_OBJECTINSTANCEA(&ddoi
);
1166 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) {
1172 if ((dwFlags
== DIDFT_ALL
) ||
1173 (dwFlags
& DIDFT_POV
)) {
1175 ddoi
.guidType
= GUID_POV
;
1176 for (i
=0; i
<4; i
++) {
1177 if (test_bit(This
->joydev
->absbits
,ABS_HAT0X
+(i
<<1)) && test_bit(This
->joydev
->absbits
,ABS_HAT0Y
+(i
<<1))) {
1178 if ((user_offset
= lxinput_to_user_offset(This
, EV_ABS
, ABS_HAT0X
+i
))== -1) {
1181 user_object
= offset_to_object(This
, user_offset
);
1182 ddoi
.dwType
= This
->df
->rgodf
[user_object
].dwType
& 0x00ffffff;
1183 ddoi
.dwOfs
= This
->df
->rgodf
[user_object
].dwOfs
;
1184 sprintf(ddoi
.tszName
, "%d-POV", i
);
1185 _dump_OBJECTINSTANCEA(&ddoi
);
1186 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) {
1193 if ((dwFlags
== DIDFT_ALL
) ||
1194 (dwFlags
& DIDFT_BUTTON
)) {
1197 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
1199 ddoi
.guidType
= GUID_Button
;
1201 for (i
= 0; i
< KEY_MAX
; i
++) {
1202 if (!test_bit(This
->joydev
->keybits
,i
)) continue;
1203 if ((user_offset
= lxinput_to_user_offset(This
, EV_KEY
, btncount
)) == -1) {
1206 user_object
= offset_to_object(This
, user_offset
);
1207 ddoi
.dwType
= This
->df
->rgodf
[user_object
].dwType
& 0x00ffffff;
1208 ddoi
.dwOfs
= This
->df
->rgodf
[user_object
].dwOfs
;
1209 sprintf(ddoi
.tszName
, "%d-Button", btncount
);
1211 _dump_OBJECTINSTANCEA(&ddoi
);
1212 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) {
1221 static HRESULT WINAPI
JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface
,
1222 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback
,
1226 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1228 device_enumobjects_AtoWcb_data data
;
1230 data
.lpCallBack
= lpCallback
;
1231 data
.lpvRef
= lpvRef
;
1233 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A
) This
, (LPDIENUMDEVICEOBJECTSCALLBACKA
) DIEnumDevicesCallbackAtoW
, (LPVOID
) &data
, dwFlags
);
1236 /******************************************************************************
1237 * GetProperty : get input device properties
1239 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
1241 LPDIPROPHEADER pdiph
)
1243 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1245 TRACE("(this=%p,%s,%p)\n",
1246 iface
, debugstr_guid(rguid
), pdiph
);
1248 if (TRACE_ON(dinput
))
1249 _dump_DIPROPHEADER(pdiph
);
1251 if (!HIWORD(rguid
)) {
1252 switch (LOWORD(rguid
)) {
1253 case (DWORD
) DIPROP_RANGE
: {
1254 LPDIPROPRANGE pr
= (LPDIPROPRANGE
) pdiph
;
1255 int obj
= find_property_offset(This
, pdiph
);
1257 pr
->lMin
= This
->joydev
->havemin
[obj
];
1258 pr
->lMax
= This
->joydev
->havemax
[obj
];
1259 TRACE("range(%d, %d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
1265 return IDirectInputDevice2AImpl_GetProperty(iface
, rguid
, pdiph
);
1273 /******************************************************************************
1274 * CreateEffect - Create a new FF effect with the specified params
1276 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
,
1279 LPDIRECTINPUTEFFECT
*ppdef
,
1280 LPUNKNOWN pUnkOuter
)
1282 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1283 EffectListItem
* new = NULL
;
1284 HRESULT retval
= DI_OK
;
1287 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1288 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
1290 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1291 TRACE("not available (compiled w/o ff support)\n");
1296 new = HeapAlloc(GetProcessHeap(), 0, sizeof(EffectListItem
));
1297 new->next
= This
->top_effect
;
1298 This
->top_effect
= new;
1300 retval
= linuxinput_create_effect(&(This
->joyfd
), rguid
, &(new->ref
));
1301 if (retval
!= DI_OK
)
1305 retval
= IDirectInputEffect_SetParameters(new->ref
, lpeff
, 0);
1306 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1311 if (pUnkOuter
!= NULL
)
1312 FIXME("Interface aggregation not implemented.\n");
1316 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1319 /*******************************************************************************
1320 * EnumEffects - Enumerate available FF effects
1322 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1323 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1327 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1328 DIEFFECTINFOA dei
; /* feif */
1329 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1330 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1332 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
1334 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1336 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1337 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1338 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1339 (*lpCallback
)(&dei
, pvRef
);
1342 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1343 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1344 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1345 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1346 (*lpCallback
)(&dei
, pvRef
);
1348 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1349 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1350 (*lpCallback
)(&dei
, pvRef
);
1352 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1353 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1354 (*lpCallback
)(&dei
, pvRef
);
1356 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1357 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1358 (*lpCallback
)(&dei
, pvRef
);
1360 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1361 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1362 (*lpCallback
)(&dei
, pvRef
);
1366 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1367 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1368 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1369 (*lpCallback
)(&dei
, pvRef
);
1372 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1373 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1374 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1375 (*lpCallback
)(&dei
, pvRef
);
1377 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1378 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1379 (*lpCallback
)(&dei
, pvRef
);
1381 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1382 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1383 (*lpCallback
)(&dei
, pvRef
);
1385 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1386 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1387 (*lpCallback
)(&dei
, pvRef
);
1396 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1397 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1401 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1402 /* seems silly to duplicate all this code but all the structures and functions
1403 * are actually different (A/W) */
1404 DIEFFECTINFOW dei
; /* feif */
1405 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1406 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1407 int xfd
= This
->joyfd
;
1409 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1411 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1413 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1414 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1415 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1416 (*lpCallback
)(&dei
, pvRef
);
1419 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1420 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1421 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1422 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1423 (*lpCallback
)(&dei
, pvRef
);
1425 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1426 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1427 (*lpCallback
)(&dei
, pvRef
);
1429 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1430 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1431 (*lpCallback
)(&dei
, pvRef
);
1433 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1434 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1435 (*lpCallback
)(&dei
, pvRef
);
1437 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1438 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1439 (*lpCallback
)(&dei
, pvRef
);
1443 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1444 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1445 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1446 (*lpCallback
)(&dei
, pvRef
);
1449 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1450 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1451 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1452 (*lpCallback
)(&dei
, pvRef
);
1454 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1455 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1456 (*lpCallback
)(&dei
, pvRef
);
1458 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1459 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1460 (*lpCallback
)(&dei
, pvRef
);
1462 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1463 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1464 (*lpCallback
)(&dei
, pvRef
);
1468 /* return to unacquired state if that's where it was */
1470 IDirectInputDevice8_Unacquire(iface
);
1476 /*******************************************************************************
1477 * GetEffectInfo - Get information about a particular effect
1479 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1480 LPDIEFFECTINFOA pdei
,
1483 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1485 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1487 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1488 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1494 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1495 LPDIEFFECTINFOW pdei
,
1498 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1500 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1502 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1503 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1509 /*******************************************************************************
1510 * GetForceFeedbackState - Get information about the device's FF state
1512 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(
1513 LPDIRECTINPUTDEVICE8A iface
,
1516 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1518 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1522 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1523 /* DIGFFS_STOPPED is the only mandatory flag to report */
1524 if (This
->ff_state
== FF_STATUS_STOPPED
)
1525 (*pdwOut
) |= DIGFFS_STOPPED
;
1531 /*******************************************************************************
1532 * SendForceFeedbackCommand - Send a command to the device's FF system
1534 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(
1535 LPDIRECTINPUTDEVICE8A iface
,
1538 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1539 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1541 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1542 if (dwFlags
== DISFFC_STOPALL
) {
1543 /* Stop all effects */
1544 EffectListItem
* itr
= This
->top_effect
;
1546 IDirectInputEffect_Stop(itr
->ref
);
1549 } else if (dwFlags
== DISFFC_RESET
) {
1550 /* Stop, unload, release and free all effects */
1551 /* This returns the device to its "bare" state */
1552 while (This
->top_effect
) {
1553 EffectListItem
* temp
= This
->top_effect
;
1554 IDirectInputEffect_Stop(temp
->ref
);
1555 IDirectInputEffect_Unload(temp
->ref
);
1556 IDirectInputEffect_Release(temp
->ref
);
1557 This
->top_effect
= temp
->next
;
1558 HeapFree(GetProcessHeap(), 0, temp
);
1560 } else if (dwFlags
== DISFFC_PAUSE
|| dwFlags
== DISFFC_CONTINUE
) {
1561 FIXME("No support for Pause or Continue in linux\n");
1562 } else if (dwFlags
== DISFFC_SETACTUATORSOFF
1563 || dwFlags
== DISFFC_SETACTUATORSON
) {
1564 FIXME("No direct actuator control in linux\n");
1566 FIXME("Unknown Force Feedback Command!\n");
1567 return DIERR_INVALIDPARAM
;
1571 return DIERR_UNSUPPORTED
;
1575 /*******************************************************************************
1576 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1577 * created for this device.
1579 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(
1580 LPDIRECTINPUTDEVICE8A iface
,
1581 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1585 /* this function is safe to call on non-ff-enabled builds */
1587 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1588 EffectListItem
* itr
= This
->top_effect
;
1589 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1592 return DIERR_INVALIDPARAM
;
1595 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1598 (*lpCallback
)(itr
->ref
, pvRef
);
1605 static const IDirectInputDevice8AVtbl JoystickAvt
=
1607 IDirectInputDevice2AImpl_QueryInterface
,
1608 IDirectInputDevice2AImpl_AddRef
,
1609 JoystickAImpl_Release
,
1610 JoystickAImpl_GetCapabilities
,
1611 JoystickAImpl_EnumObjects
,
1612 JoystickAImpl_GetProperty
,
1613 JoystickAImpl_SetProperty
,
1614 JoystickAImpl_Acquire
,
1615 JoystickAImpl_Unacquire
,
1616 JoystickAImpl_GetDeviceState
,
1617 IDirectInputDevice2AImpl_GetDeviceData
,
1618 JoystickAImpl_SetDataFormat
,
1619 IDirectInputDevice2AImpl_SetEventNotification
,
1620 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1621 IDirectInputDevice2AImpl_GetObjectInfo
,
1622 IDirectInputDevice2AImpl_GetDeviceInfo
,
1623 IDirectInputDevice2AImpl_RunControlPanel
,
1624 IDirectInputDevice2AImpl_Initialize
,
1625 JoystickAImpl_CreateEffect
,
1626 JoystickAImpl_EnumEffects
,
1627 JoystickAImpl_GetEffectInfo
,
1628 JoystickAImpl_GetForceFeedbackState
,
1629 JoystickAImpl_SendForceFeedbackCommand
,
1630 JoystickAImpl_EnumCreatedEffectObjects
,
1631 IDirectInputDevice2AImpl_Escape
,
1633 IDirectInputDevice2AImpl_SendDeviceData
,
1634 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1635 IDirectInputDevice7AImpl_WriteEffectToFile
,
1636 IDirectInputDevice8AImpl_BuildActionMap
,
1637 IDirectInputDevice8AImpl_SetActionMap
,
1638 IDirectInputDevice8AImpl_GetImageInfo
1641 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1642 # define XCAST(fun) (typeof(JoystickWvt.fun))
1644 # define XCAST(fun) (void*)
1647 static const IDirectInputDevice8WVtbl JoystickWvt
=
1649 IDirectInputDevice2WImpl_QueryInterface
,
1650 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
1651 XCAST(Release
)JoystickAImpl_Release
,
1652 XCAST(GetCapabilities
)JoystickAImpl_GetCapabilities
,
1653 JoystickWImpl_EnumObjects
,
1654 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1655 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1656 XCAST(Acquire
)JoystickAImpl_Acquire
,
1657 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1658 XCAST(GetDeviceState
)JoystickAImpl_GetDeviceState
,
1659 XCAST(GetDeviceData
)IDirectInputDevice2AImpl_GetDeviceData
,
1660 XCAST(SetDataFormat
)JoystickAImpl_SetDataFormat
,
1661 XCAST(SetEventNotification
)IDirectInputDevice2AImpl_SetEventNotification
,
1662 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
1663 IDirectInputDevice2WImpl_GetObjectInfo
,
1664 IDirectInputDevice2WImpl_GetDeviceInfo
,
1665 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
1666 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
1667 XCAST(CreateEffect
)JoystickAImpl_CreateEffect
,
1668 JoystickWImpl_EnumEffects
,
1669 JoystickWImpl_GetEffectInfo
,
1670 XCAST(GetForceFeedbackState
)JoystickAImpl_GetForceFeedbackState
,
1671 XCAST(SendForceFeedbackCommand
)JoystickAImpl_SendForceFeedbackCommand
,
1672 XCAST(EnumCreatedEffectObjects
)JoystickAImpl_EnumCreatedEffectObjects
,
1673 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1674 XCAST(Poll
)JoystickAImpl_Poll
,
1675 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1676 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1677 IDirectInputDevice7WImpl_WriteEffectToFile
,
1678 IDirectInputDevice8WImpl_BuildActionMap
,
1679 IDirectInputDevice8WImpl_SetActionMap
,
1680 IDirectInputDevice8WImpl_GetImageInfo
1684 #else /* HAVE_CORRECT_LINUXINPUT_H */
1686 const struct dinput_device joystick_linuxinput_device
= {
1687 "Wine Linux-input joystick driver",
1694 #endif /* HAVE_CORRECT_LINUXINPUT_H */