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
];
141 /* Force feedback variables */
142 EffectListItem
* top_effect
;
146 static void fake_current_js_state(JoystickImpl
*ji
);
147 static DWORD
map_pov(int event_value
, int is_x
);
148 static void find_joydevs(void);
150 /* This GUID is slightly different from the linux joystick one. Take note. */
151 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
155 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
158 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
160 #define MAX_JOYDEV 64
162 static int have_joydevs
= -1;
163 static struct JoyDev
*joydevs
= NULL
;
165 static void find_joydevs(void)
169 if (have_joydevs
!=-1) {
175 for (i
=0;i
<MAX_JOYDEV
;i
++) {
177 struct JoyDev joydev
= {0};
182 snprintf(buf
,MAX_PATH
,EVDEVPREFIX
"%d",i
);
185 if ((fd
=open(buf
, O_RDWR
))==-1) {
186 fd
= open(buf
, O_RDONLY
);
191 if ((-1==ioctl(fd
,EVIOCGBIT(0,sizeof(joydev
.evbits
)),joydev
.evbits
))) {
192 perror("EVIOCGBIT 0");
196 if (-1==ioctl(fd
,EVIOCGBIT(EV_ABS
,sizeof(joydev
.absbits
)),joydev
.absbits
)) {
197 perror("EVIOCGBIT EV_ABS");
201 if (-1==ioctl(fd
,EVIOCGBIT(EV_KEY
,sizeof(joydev
.keybits
)),joydev
.keybits
)) {
202 perror("EVIOCGBIT EV_KEY");
206 /* A true joystick has at least axis X and Y, and at least 1
207 * button. copied from linux/drivers/input/joydev.c */
208 if (test_bit(joydev
.absbits
,ABS_X
) && test_bit(joydev
.absbits
,ABS_Y
) &&
209 ( test_bit(joydev
.keybits
,BTN_TRIGGER
) ||
210 test_bit(joydev
.keybits
,BTN_A
) ||
211 test_bit(joydev
.keybits
,BTN_1
)
215 joydev
.device
= strdup(buf
);
217 if (-1!=ioctl(fd
, EVIOCGNAME(MAX_PATH
-1), buf
)) {
219 joydev
.name
= strdup(buf
);
221 joydev
.name
= joydev
.device
;
224 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
225 joydev
.guid
.Data3
+= have_joydevs
;
227 TRACE("Found a joystick on %s: %s (%s)\n",
228 joydev
.device
, joydev
.name
,
229 debugstr_guid(&joydev
.guid
)
232 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
234 if ((!test_bit(joydev
.evbits
,EV_FF
))
235 || (-1==ioctl(fd
,EVIOCGBIT(EV_FF
,sizeof(joydev
.ffbits
)),joydev
.ffbits
))
236 || (-1==ioctl(fd
,EVIOCGEFFECTS
,&joydev
.num_effects
))
237 || (joydev
.num_effects
<= 0)) {
240 TRACE(" ... with force feedback\n");
246 for (j
=0;j
<ABS_MAX
;j
++) {
247 if (test_bit(joydev
.absbits
,j
)) {
248 if (-1!=ioctl(fd
,EVIOCGABS(j
),&(joydev
.axes
[j
]))) {
249 TRACE(" ... with axe %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
251 joydev
.axes
[j
][AXE_ABS
],
252 joydev
.axes
[j
][AXE_ABSMIN
],
253 joydev
.axes
[j
][AXE_ABSMAX
],
254 joydev
.axes
[j
][AXE_ABSFUZZ
],
255 joydev
.axes
[j
][AXE_ABSFLAT
]
257 joydev
.havemin
[j
] = joydev
.axes
[j
][AXE_ABSMIN
];
258 joydev
.havemax
[j
] = joydev
.axes
[j
][AXE_ABSMAX
];
264 for (j
=0;j
<KEY_MAX
;j
++) {
265 if (test_bit(joydev
.keybits
,j
)) {
266 TRACE(" ... with button %d: %d\n", j
, buttons
);
267 joydev
.buttons
[j
] = 0x80 | buttons
;
272 if (have_joydevs
==0) {
273 joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
275 HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1+have_joydevs
) * sizeof(struct JoyDev
));
277 memcpy(joydevs
+have_joydevs
, &joydev
, sizeof(struct JoyDev
));
286 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
290 if (id
>= have_joydevs
) {
294 if (!((dwDevType
== 0) ||
295 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
< 0x0800)) ||
296 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
299 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
300 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
304 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
305 lpddi
->guidInstance
= joydevs
[id
].guid
;
306 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
308 lpddi
->guidFFDriver
= GUID_NULL
;
309 if (version
>= 0x0800)
310 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
312 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
314 strcpy(lpddi
->tszInstanceName
, joydevs
[id
].name
);
315 strcpy(lpddi
->tszProductName
, joydevs
[id
].device
);
321 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
325 if (id
>= have_joydevs
) {
329 if (!((dwDevType
== 0) ||
330 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
< 0x0800)) ||
331 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
334 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
335 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
339 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
340 lpddi
->guidInstance
= joydevs
[id
].guid
;
341 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
343 lpddi
->guidFFDriver
= GUID_NULL
;
344 if (version
>= 0x0800)
345 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
347 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
349 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
350 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].device
, -1, lpddi
->tszProductName
, MAX_PATH
);
356 static JoystickImpl
*alloc_device(REFGUID rguid
, const void *jvt
, IDirectInputImpl
*dinput
, struct JoyDev
*joydev
)
358 JoystickImpl
* newDevice
;
359 LPDIDATAFORMAT df
= NULL
;
361 int axis
= 0, pov
= 0, btn
= 0;
363 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
364 if (!newDevice
) return NULL
;
366 newDevice
->base
.lpVtbl
= jvt
;
367 newDevice
->base
.ref
= 1;
368 memcpy(&newDevice
->base
.guid
, rguid
, sizeof(*rguid
));
369 InitializeCriticalSection(&newDevice
->base
.crit
);
370 newDevice
->joyfd
= -1;
371 newDevice
->dinput
= dinput
;
372 newDevice
->joydev
= joydev
;
373 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
374 newDevice
->ff_state
= FF_STATUS_STOPPED
;
376 for (i
=0;i
<ABS_MAX
;i
++) {
377 /* apps expect the range to be the same they would get from the
378 * GetProperty/range method */
379 newDevice
->wantmin
[i
] = newDevice
->joydev
->havemin
[i
];
380 newDevice
->wantmax
[i
] = newDevice
->joydev
->havemax
[i
];
382 * direct input defines a default for the deadzone somewhere; but as long
383 * as in map_axis the code for the dead zone is commented out its no
386 newDevice
->deadz
[i
] = 0;
388 fake_current_js_state(newDevice
);
390 /* Create copy of default data format */
391 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
392 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
393 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
395 /* Supported Axis & POVs should map 1-to-1 */
396 for (i
= 0; i
< 8; i
++)
398 if (!test_bit(newDevice
->joydev
->absbits
, i
)) continue;
400 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[axis
+ WINE_JOYSTICK_AXIS_BASE
], df
->dwObjSize
);
401 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(axis
++) | DIDFT_ABSAXIS
;
403 for (i
= 0; i
< 4; i
++)
405 if (!test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) ||
406 !test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2))
409 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[pov
+ WINE_JOYSTICK_POV_BASE
], df
->dwObjSize
);
410 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(pov
++) | DIDFT_POV
;
412 /* Buttons can be anywhere, so check all */
413 for (i
= 0; i
< KEY_MAX
&& btn
< 128; i
++)
415 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
417 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[btn
+ WINE_JOYSTICK_BUTTON_BASE
], df
->dwObjSize
);
418 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(btn
++) | DIDFT_PSHBUTTON
;
422 newDevice
->base
.data_format
.wine_df
= df
;
423 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A
)newDevice
->dinput
);
427 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
428 HeapFree(GetProcessHeap(), 0, df
);
429 HeapFree(GetProcessHeap(), 0, newDevice
);
433 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
439 for (i
=0; i
<have_joydevs
; i
++) {
440 if (IsEqualGUID(&GUID_Joystick
,rguid
) ||
441 IsEqualGUID(&joydevs
[i
].guid
,rguid
)
443 if ((riid
== NULL
) ||
444 IsEqualGUID(&IID_IDirectInputDeviceA
,riid
) ||
445 IsEqualGUID(&IID_IDirectInputDevice2A
,riid
) ||
446 IsEqualGUID(&IID_IDirectInputDevice7A
,riid
) ||
447 IsEqualGUID(&IID_IDirectInputDevice8A
,riid
)) {
448 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &JoystickAvt
, dinput
, &joydevs
[i
]);
449 TRACE("Creating a Joystick device (%p)\n", *pdev
);
451 ERR("out of memory\n");
452 return DIERR_OUTOFMEMORY
;
456 return DIERR_NOINTERFACE
;
461 return DIERR_DEVICENOTREG
;
465 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
471 for (i
=0; i
<have_joydevs
; i
++) {
472 if (IsEqualGUID(&GUID_Joystick
,rguid
) ||
473 IsEqualGUID(&joydevs
[i
].guid
,rguid
)
475 if ((riid
== NULL
) ||
476 IsEqualGUID(&IID_IDirectInputDeviceW
,riid
) ||
477 IsEqualGUID(&IID_IDirectInputDevice2W
,riid
) ||
478 IsEqualGUID(&IID_IDirectInputDevice7W
,riid
) ||
479 IsEqualGUID(&IID_IDirectInputDevice8W
,riid
)) {
480 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &JoystickWvt
, dinput
, &joydevs
[i
]);
481 TRACE("Creating a Joystick device (%p)\n", *pdev
);
483 ERR("out of memory\n");
484 return DIERR_OUTOFMEMORY
;
488 return DIERR_NOINTERFACE
;
493 return DIERR_DEVICENOTREG
;
496 const struct dinput_device joystick_linuxinput_device
= {
497 "Wine Linux-input joystick driver",
500 joydev_create_deviceA
,
501 joydev_create_deviceW
504 /******************************************************************************
507 static ULONG WINAPI
JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface
)
509 JoystickImpl
*This
= (JoystickImpl
*)iface
;
512 ref
= InterlockedDecrement(&This
->base
.ref
);
516 /* Reset the FF state, free all effects, etc */
517 IDirectInputDevice8_SendForceFeedbackCommand(iface
, DISFFC_RESET
);
519 /* Free the data queue */
520 HeapFree(GetProcessHeap(), 0, This
->base
.data_queue
);
522 /* release the data transform filter */
523 HeapFree(GetProcessHeap(), 0, This
->base
.data_format
.wine_df
->rgodf
);
524 HeapFree(GetProcessHeap(), 0, This
->base
.data_format
.wine_df
);
525 release_DataFormat(&This
->base
.data_format
);
527 IDirectInput_Release((LPDIRECTINPUTDEVICE8A
)This
->dinput
);
528 DeleteCriticalSection(&This
->base
.crit
);
530 HeapFree(GetProcessHeap(),0,This
);
534 /******************************************************************************
535 * Acquire : gets exclusive control of the joystick
537 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
539 JoystickImpl
*This
= (JoystickImpl
*)iface
;
542 TRACE("(this=%p)\n",This
);
544 res
= IDirectInputDevice2AImpl_Acquire(iface
);
546 if (-1==(This
->joyfd
=open(This
->joydev
->device
,O_RDWR
))) {
547 if (-1==(This
->joyfd
=open(This
->joydev
->device
,O_RDONLY
))) {
548 /* Couldn't open the device at all */
549 perror(This
->joydev
->device
);
550 IDirectInputDevice2AImpl_Unacquire(iface
);
551 return DIERR_NOTFOUND
;
553 /* Couldn't open in r/w but opened in read-only. */
554 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
562 /******************************************************************************
563 * Unacquire : frees the joystick
565 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
567 JoystickImpl
*This
= (JoystickImpl
*)iface
;
570 TRACE("(this=%p)\n",This
);
571 res
= IDirectInputDevice2AImpl_Unacquire(iface
);
572 if (res
==DI_OK
&& This
->joyfd
!=-1) {
580 * This maps the read value (from the input event) to a value in the
581 * 'wanted' range. It also autodetects the possible range of the axe and
582 * adapts values accordingly.
585 map_axis(JoystickImpl
* This
, int axis
, int val
) {
586 int xmin
= This
->joydev
->axes
[axis
][AXE_ABSMIN
];
587 int xmax
= This
->joydev
->axes
[axis
][AXE_ABSMAX
];
588 int hmax
= This
->joydev
->havemax
[axis
];
589 int hmin
= This
->joydev
->havemin
[axis
];
590 int wmin
= This
->wantmin
[axis
];
591 int wmax
= This
->wantmax
[axis
];
594 if (val
> hmax
) This
->joydev
->havemax
[axis
] = hmax
= val
;
595 if (val
< hmin
) This
->joydev
->havemin
[axis
] = hmin
= val
;
597 if (xmin
== xmax
) return val
;
599 /* map the value from the hmin-hmax range into the wmin-wmax range */
600 ret
= MulDiv( val
- hmin
, wmax
- wmin
, hmax
- hmin
) + wmin
;
602 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
);
605 /* deadzone doesn't work comfortably enough right now. needs more testing*/
606 if ((ret
> -deadz
/2 ) && (ret
< deadz
/2)) {
607 FIXME("%d in deadzone, return mid.\n",val
);
608 return (wmax
-wmin
)/2+wmin
;
615 * set the current state of the js device as it would be with the middle
618 static void fake_current_js_state(JoystickImpl
*ji
)
621 /* center the axes */
622 ji
->js
.lX
= test_bit(ji
->joydev
->absbits
, ABS_X
) ? map_axis(ji
, ABS_X
, ji
->joydev
->axes
[ABS_X
][AXE_ABS
]) : 0;
623 ji
->js
.lY
= test_bit(ji
->joydev
->absbits
, ABS_Y
) ? map_axis(ji
, ABS_Y
, ji
->joydev
->axes
[ABS_Y
][AXE_ABS
]) : 0;
624 ji
->js
.lZ
= test_bit(ji
->joydev
->absbits
, ABS_Z
) ? map_axis(ji
, ABS_Z
, ji
->joydev
->axes
[ABS_Z
][AXE_ABS
]) : 0;
625 ji
->js
.lRx
= test_bit(ji
->joydev
->absbits
, ABS_RX
) ? map_axis(ji
, ABS_RX
, ji
->joydev
->axes
[ABS_RX
][AXE_ABS
]) : 0;
626 ji
->js
.lRy
= test_bit(ji
->joydev
->absbits
, ABS_RY
) ? map_axis(ji
, ABS_RY
, ji
->joydev
->axes
[ABS_RY
][AXE_ABS
]) : 0;
627 ji
->js
.lRz
= test_bit(ji
->joydev
->absbits
, ABS_RZ
) ? map_axis(ji
, ABS_RZ
, ji
->joydev
->axes
[ABS_RZ
][AXE_ABS
]) : 0;
628 ji
->js
.rglSlider
[0] = test_bit(ji
->joydev
->absbits
, ABS_THROTTLE
) ? map_axis(ji
, ABS_THROTTLE
, ji
->joydev
->axes
[ABS_THROTTLE
][AXE_ABS
]) : 0;
629 ji
->js
.rglSlider
[1] = test_bit(ji
->joydev
->absbits
, ABS_RUDDER
) ? map_axis(ji
, ABS_RUDDER
, ji
->joydev
->axes
[ABS_RUDDER
][AXE_ABS
]) : 0;
630 /* POV center is -1 */
631 for (i
=0; i
<4; i
++) {
632 ji
->js
.rgdwPOV
[i
] = -1;
637 * Maps an event value to a DX "clock" position:
642 static DWORD
map_pov(int event_value
, int is_x
)
648 } else if (event_value
>0) {
654 } else if (event_value
>0) {
661 /* defines how the linux input system offset mappings into c_dfDIJoystick2 */
662 static int lxinput_to_user_index(JoystickImpl
*This
, int ie_type
, int ie_code
)
668 case ABS_X
: offset
= 0; break;
669 case ABS_Y
: offset
= 1; break;
670 case ABS_Z
: offset
= 2; break;
671 case ABS_RX
: offset
= 3; break;
672 case ABS_RY
: offset
= 4; break;
673 case ABS_RZ
: offset
= 5; break;
674 case ABS_THROTTLE
: offset
= 6; break;
675 case ABS_RUDDER
: offset
= 7; break;
676 case ABS_HAT0X
: case ABS_HAT0Y
: offset
= 8; break;
677 case ABS_HAT1X
: case ABS_HAT1Y
: offset
= 9; break;
678 case ABS_HAT2X
: case ABS_HAT2Y
: offset
= 10; break;
679 case ABS_HAT3X
: case ABS_HAT3Y
: offset
= 11; break;
680 /* XXX when adding new axes here also fix the offset for the buttons bellow */
682 FIXME("Unhandled EV_ABS(0x%02X)\n", ie_code
);
687 if (ie_code
>= 128) {
688 WARN("DX8 does not support more than 128 buttons\n");
691 offset
= 12 + ie_code
; /* XXX */
694 FIXME("Unhandled type(0x%02X)\n", ie_type
);
700 /* convert wine format offset to user format object index */
701 static void joy_polldev(JoystickImpl
*This
)
704 struct input_event ie
;
714 plfd
.fd
= This
->joyfd
;
715 plfd
.events
= POLLIN
;
717 if (poll(&plfd
,1,0) != 1)
720 /* we have one event, so we can read */
721 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
724 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
726 case EV_KEY
: /* button */
728 int btn
= This
->joydev
->buttons
[ie
.code
];
730 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
734 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
735 This
->js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
740 if ((inst_id
= lxinput_to_user_index(This
, ie
.type
, ie
.code
)) == -1)
742 inst_id
= DIDFT_MAKEINSTANCE(inst_id
) | (inst_id
< ABS_HAT0X
? DIDFT_AXIS
: DIDFT_POV
);
743 value
= map_axis(This
, ie
.code
, ie
.value
);
746 case ABS_X
: This
->js
.lX
= value
; break;
747 case ABS_Y
: This
->js
.lY
= value
; break;
748 case ABS_Z
: This
->js
.lZ
= value
; break;
749 case ABS_RX
: This
->js
.lRx
= value
; break;
750 case ABS_RY
: This
->js
.lRy
= value
; break;
751 case ABS_RZ
: This
->js
.lRz
= value
; break;
752 case ABS_THROTTLE
: This
->js
.rglSlider
[0] = value
; break;
753 case ABS_RUDDER
: This
->js
.rglSlider
[1] = value
; break;
756 This
->js
.rgdwPOV
[0] = value
= map_pov(ie
.value
, ie
.code
==ABS_HAT0X
);
760 This
->js
.rgdwPOV
[1] = value
= map_pov(ie
.value
, ie
.code
==ABS_HAT1X
);
764 This
->js
.rgdwPOV
[2] = value
= map_pov(ie
.value
, ie
.code
==ABS_HAT2X
);
768 This
->js
.rgdwPOV
[3] = value
= map_pov(ie
.value
, ie
.code
==ABS_HAT3X
);
771 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie
.code
,ie
.value
);
775 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
777 This
->ff_state
= ie
.value
;
782 /* there is nothing to do */
786 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
790 queue_event((LPDIRECTINPUTDEVICE8A
)This
,
791 id_to_offset(&This
->base
.data_format
, inst_id
),
792 value
, ie
.time
.tv_usec
, This
->dinput
->evsequence
++);
796 /******************************************************************************
797 * GetDeviceState : returns the "state" of the joystick.
800 static HRESULT WINAPI
JoystickAImpl_GetDeviceState(
801 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
803 JoystickImpl
*This
= (JoystickImpl
*)iface
;
805 TRACE("(this=%p,0x%08x,%p)\n", This
, len
, ptr
);
807 if (This
->joyfd
==-1) {
808 WARN("not acquired\n");
809 return DIERR_NOTACQUIRED
;
814 /* convert and copy data to user supplied buffer */
815 fill_DataFormat(ptr
, &This
->js
, &This
->base
.data_format
);
820 /******************************************************************************
821 * SetProperty : change input device properties
823 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
827 JoystickImpl
*This
= (JoystickImpl
*)iface
;
830 WARN("invalid argument\n");
831 return DIERR_INVALIDPARAM
;
834 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
835 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
836 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
838 if (!HIWORD(rguid
)) {
839 switch (LOWORD(rguid
)) {
840 case (DWORD
)DIPROP_RANGE
: {
841 LPCDIPROPRANGE pr
= (LPCDIPROPRANGE
)ph
;
843 if (ph
->dwHow
== DIPH_DEVICE
) {
845 TRACE("proprange(%d,%d) all\n", pr
->lMin
, pr
->lMax
);
846 for (i
= 0; i
< This
->base
.data_format
.wine_df
->dwNumObjs
; i
++) {
847 This
->wantmin
[i
] = pr
->lMin
;
848 This
->wantmax
[i
] = pr
->lMax
;
851 int obj
= find_property(&This
->base
.data_format
, ph
);
853 TRACE("proprange(%d,%d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
855 This
->wantmin
[obj
] = pr
->lMin
;
856 This
->wantmax
[obj
] = pr
->lMax
;
859 fake_current_js_state(This
);
862 case (DWORD
)DIPROP_DEADZONE
: {
863 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
864 if (ph
->dwHow
== DIPH_DEVICE
) {
866 TRACE("deadzone(%d) all\n", pd
->dwData
);
867 for (i
= 0; i
< This
->base
.data_format
.wine_df
->dwNumObjs
; i
++) {
868 This
->deadz
[i
] = pd
->dwData
;
871 int obj
= find_property(&This
->base
.data_format
, ph
);
873 TRACE("deadzone(%d) obj=%d\n", pd
->dwData
, obj
);
875 This
->deadz
[obj
] = pd
->dwData
;
878 fake_current_js_state(This
);
881 case (DWORD
)DIPROP_CALIBRATIONMODE
: {
882 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
883 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd
->dwData
);
887 return IDirectInputDevice2AImpl_SetProperty(iface
, rguid
, ph
);
893 static HRESULT WINAPI
JoystickAImpl_GetCapabilities(
894 LPDIRECTINPUTDEVICE8A iface
,
895 LPDIDEVCAPS lpDIDevCaps
)
897 JoystickImpl
*This
= (JoystickImpl
*)iface
;
898 int i
,axes
,buttons
,povs
;
900 TRACE("%p->(%p)\n",iface
,lpDIDevCaps
);
903 WARN("invalid pointer\n");
907 if (lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS
)) {
908 WARN("invalid argument\n");
909 return DIERR_INVALIDPARAM
;
912 lpDIDevCaps
->dwFlags
= DIDC_ATTACHED
;
913 if (This
->dinput
->dwVersion
>= 0x0800)
914 lpDIDevCaps
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
916 lpDIDevCaps
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
919 for (i
=0;i
<ABS_MAX
;i
++) {
920 if (!test_bit(This
->joydev
->absbits
,i
)) continue;
922 case ABS_HAT0X
: case ABS_HAT0Y
:
923 case ABS_HAT1X
: case ABS_HAT1Y
:
924 case ABS_HAT2X
: case ABS_HAT2Y
:
925 case ABS_HAT3X
: case ABS_HAT3Y
:
926 /* will be handled as POV - see below */
933 for (i
=0;i
<KEY_MAX
;i
++) if (test_bit(This
->joydev
->keybits
,i
)) buttons
++;
935 for (i
=0; i
<4; i
++) {
936 if (test_bit(This
->joydev
->absbits
,ABS_HAT0X
+(i
<<1)) && test_bit(This
->joydev
->absbits
,ABS_HAT0Y
+(i
<<1))) {
941 if (This
->joydev
->has_ff
)
942 lpDIDevCaps
->dwFlags
|= DIDC_FORCEFEEDBACK
;
944 lpDIDevCaps
->dwAxes
= axes
;
945 lpDIDevCaps
->dwButtons
= buttons
;
946 lpDIDevCaps
->dwPOVs
= povs
;
951 static HRESULT WINAPI
JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface
) {
952 JoystickImpl
*This
= (JoystickImpl
*)iface
;
953 TRACE("(%p)\n",This
);
955 if (This
->joyfd
==-1) {
956 return DIERR_NOTACQUIRED
;
963 /******************************************************************************
964 * GetProperty : get input device properties
966 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
968 LPDIPROPHEADER pdiph
)
970 JoystickImpl
*This
= (JoystickImpl
*)iface
;
972 TRACE("(this=%p,%s,%p)\n",
973 iface
, debugstr_guid(rguid
), pdiph
);
975 if (TRACE_ON(dinput
))
976 _dump_DIPROPHEADER(pdiph
);
978 if (!HIWORD(rguid
)) {
979 switch (LOWORD(rguid
)) {
980 case (DWORD
) DIPROP_RANGE
: {
981 LPDIPROPRANGE pr
= (LPDIPROPRANGE
) pdiph
;
982 int obj
= find_property(&This
->base
.data_format
, pdiph
);
985 pr
->lMin
= This
->joydev
->havemin
[obj
];
986 pr
->lMax
= This
->joydev
->havemax
[obj
];
987 TRACE("range(%d, %d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
993 return IDirectInputDevice2AImpl_GetProperty(iface
, rguid
, pdiph
);
1001 /******************************************************************************
1002 * GetObjectInfo : get information about a device object such as a button
1005 static HRESULT WINAPI
JoystickWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface
,
1006 LPDIDEVICEOBJECTINSTANCEW pdidoi
, DWORD dwObj
, DWORD dwHow
)
1008 static const WCHAR axisW
[] = {'A','x','i','s',' ','%','d',0};
1009 static const WCHAR povW
[] = {'P','O','V',' ','%','d',0};
1010 static const WCHAR buttonW
[] = {'B','u','t','t','o','n',' ','%','d',0};
1013 res
= IDirectInputDevice2WImpl_GetObjectInfo(iface
, pdidoi
, dwObj
, dwHow
);
1014 if (res
!= DI_OK
) return res
;
1016 if (pdidoi
->dwType
& DIDFT_AXIS
)
1017 sprintfW(pdidoi
->tszName
, axisW
, DIDFT_GETINSTANCE(pdidoi
->dwType
));
1018 else if (pdidoi
->dwType
& DIDFT_POV
)
1019 sprintfW(pdidoi
->tszName
, povW
, DIDFT_GETINSTANCE(pdidoi
->dwType
));
1020 else if (pdidoi
->dwType
& DIDFT_BUTTON
)
1021 sprintfW(pdidoi
->tszName
, buttonW
, DIDFT_GETINSTANCE(pdidoi
->dwType
));
1023 _dump_OBJECTINSTANCEW(pdidoi
);
1027 static HRESULT WINAPI
JoystickAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface
,
1028 LPDIDEVICEOBJECTINSTANCEA pdidoi
, DWORD dwObj
, DWORD dwHow
)
1031 DIDEVICEOBJECTINSTANCEW didoiW
;
1032 DWORD dwSize
= pdidoi
->dwSize
;
1034 didoiW
.dwSize
= sizeof(didoiW
);
1035 res
= JoystickWImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W
)iface
, &didoiW
, dwObj
, dwHow
);
1036 if (res
!= DI_OK
) return res
;
1038 memset(pdidoi
, 0, pdidoi
->dwSize
);
1039 memcpy(pdidoi
, &didoiW
, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW
, tszName
));
1040 pdidoi
->dwSize
= dwSize
;
1041 WideCharToMultiByte(CP_ACP
, 0, didoiW
.tszName
, -1, pdidoi
->tszName
,
1042 sizeof(pdidoi
->tszName
), NULL
, NULL
);
1047 /******************************************************************************
1048 * CreateEffect - Create a new FF effect with the specified params
1050 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
,
1053 LPDIRECTINPUTEFFECT
*ppdef
,
1054 LPUNKNOWN pUnkOuter
)
1056 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1057 EffectListItem
* new = NULL
;
1058 HRESULT retval
= DI_OK
;
1061 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1062 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
1064 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1065 TRACE("not available (compiled w/o ff support)\n");
1070 new = HeapAlloc(GetProcessHeap(), 0, sizeof(EffectListItem
));
1071 new->next
= This
->top_effect
;
1072 This
->top_effect
= new;
1074 retval
= linuxinput_create_effect(&(This
->joyfd
), rguid
, &(new->ref
));
1075 if (retval
!= DI_OK
)
1079 retval
= IDirectInputEffect_SetParameters(new->ref
, lpeff
, 0);
1080 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1085 if (pUnkOuter
!= NULL
)
1086 FIXME("Interface aggregation not implemented.\n");
1090 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1093 /*******************************************************************************
1094 * EnumEffects - Enumerate available FF effects
1096 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1097 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1101 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1102 DIEFFECTINFOA dei
; /* feif */
1103 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1104 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1106 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
1108 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1110 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1111 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1112 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1113 (*lpCallback
)(&dei
, pvRef
);
1116 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1117 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1118 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1119 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1120 (*lpCallback
)(&dei
, pvRef
);
1122 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1123 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1124 (*lpCallback
)(&dei
, pvRef
);
1126 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1127 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1128 (*lpCallback
)(&dei
, pvRef
);
1130 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1131 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1132 (*lpCallback
)(&dei
, pvRef
);
1134 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1135 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1136 (*lpCallback
)(&dei
, pvRef
);
1140 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1141 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1142 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1143 (*lpCallback
)(&dei
, pvRef
);
1146 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1147 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1148 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1149 (*lpCallback
)(&dei
, pvRef
);
1151 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1152 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1153 (*lpCallback
)(&dei
, pvRef
);
1155 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1156 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1157 (*lpCallback
)(&dei
, pvRef
);
1159 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1160 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1161 (*lpCallback
)(&dei
, pvRef
);
1170 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1171 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1175 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1176 /* seems silly to duplicate all this code but all the structures and functions
1177 * are actually different (A/W) */
1178 DIEFFECTINFOW dei
; /* feif */
1179 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1180 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1181 int xfd
= This
->joyfd
;
1183 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1185 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1187 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1188 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1189 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1190 (*lpCallback
)(&dei
, pvRef
);
1193 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1194 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1195 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1196 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1197 (*lpCallback
)(&dei
, pvRef
);
1199 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1200 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1201 (*lpCallback
)(&dei
, pvRef
);
1203 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1204 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1205 (*lpCallback
)(&dei
, pvRef
);
1207 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1208 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1209 (*lpCallback
)(&dei
, pvRef
);
1211 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1212 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1213 (*lpCallback
)(&dei
, pvRef
);
1217 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1218 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1219 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1220 (*lpCallback
)(&dei
, pvRef
);
1223 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1224 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1225 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1226 (*lpCallback
)(&dei
, pvRef
);
1228 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1229 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1230 (*lpCallback
)(&dei
, pvRef
);
1232 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1233 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1234 (*lpCallback
)(&dei
, pvRef
);
1236 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1237 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1238 (*lpCallback
)(&dei
, pvRef
);
1242 /* return to unacquired state if that's where it was */
1244 IDirectInputDevice8_Unacquire(iface
);
1250 /*******************************************************************************
1251 * GetEffectInfo - Get information about a particular effect
1253 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1254 LPDIEFFECTINFOA pdei
,
1257 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1259 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1261 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1262 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1268 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1269 LPDIEFFECTINFOW pdei
,
1272 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1274 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1276 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1277 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1283 /*******************************************************************************
1284 * GetForceFeedbackState - Get information about the device's FF state
1286 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(
1287 LPDIRECTINPUTDEVICE8A iface
,
1290 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1292 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1296 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1297 /* DIGFFS_STOPPED is the only mandatory flag to report */
1298 if (This
->ff_state
== FF_STATUS_STOPPED
)
1299 (*pdwOut
) |= DIGFFS_STOPPED
;
1305 /*******************************************************************************
1306 * SendForceFeedbackCommand - Send a command to the device's FF system
1308 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(
1309 LPDIRECTINPUTDEVICE8A iface
,
1312 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1313 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1315 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1316 if (dwFlags
== DISFFC_STOPALL
) {
1317 /* Stop all effects */
1318 EffectListItem
* itr
= This
->top_effect
;
1320 IDirectInputEffect_Stop(itr
->ref
);
1323 } else if (dwFlags
== DISFFC_RESET
) {
1324 /* Stop, unload, release and free all effects */
1325 /* This returns the device to its "bare" state */
1326 while (This
->top_effect
) {
1327 EffectListItem
* temp
= This
->top_effect
;
1328 IDirectInputEffect_Stop(temp
->ref
);
1329 IDirectInputEffect_Unload(temp
->ref
);
1330 IDirectInputEffect_Release(temp
->ref
);
1331 This
->top_effect
= temp
->next
;
1332 HeapFree(GetProcessHeap(), 0, temp
);
1334 } else if (dwFlags
== DISFFC_PAUSE
|| dwFlags
== DISFFC_CONTINUE
) {
1335 FIXME("No support for Pause or Continue in linux\n");
1336 } else if (dwFlags
== DISFFC_SETACTUATORSOFF
1337 || dwFlags
== DISFFC_SETACTUATORSON
) {
1338 FIXME("No direct actuator control in linux\n");
1340 FIXME("Unknown Force Feedback Command!\n");
1341 return DIERR_INVALIDPARAM
;
1345 return DIERR_UNSUPPORTED
;
1349 /*******************************************************************************
1350 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1351 * created for this device.
1353 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(
1354 LPDIRECTINPUTDEVICE8A iface
,
1355 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1359 /* this function is safe to call on non-ff-enabled builds */
1361 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1362 EffectListItem
* itr
= This
->top_effect
;
1363 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1366 return DIERR_INVALIDPARAM
;
1369 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1372 (*lpCallback
)(itr
->ref
, pvRef
);
1379 static const IDirectInputDevice8AVtbl JoystickAvt
=
1381 IDirectInputDevice2AImpl_QueryInterface
,
1382 IDirectInputDevice2AImpl_AddRef
,
1383 JoystickAImpl_Release
,
1384 JoystickAImpl_GetCapabilities
,
1385 IDirectInputDevice2AImpl_EnumObjects
,
1386 JoystickAImpl_GetProperty
,
1387 JoystickAImpl_SetProperty
,
1388 JoystickAImpl_Acquire
,
1389 JoystickAImpl_Unacquire
,
1390 JoystickAImpl_GetDeviceState
,
1391 IDirectInputDevice2AImpl_GetDeviceData
,
1392 IDirectInputDevice2AImpl_SetDataFormat
,
1393 IDirectInputDevice2AImpl_SetEventNotification
,
1394 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1395 JoystickAImpl_GetObjectInfo
,
1396 IDirectInputDevice2AImpl_GetDeviceInfo
,
1397 IDirectInputDevice2AImpl_RunControlPanel
,
1398 IDirectInputDevice2AImpl_Initialize
,
1399 JoystickAImpl_CreateEffect
,
1400 JoystickAImpl_EnumEffects
,
1401 JoystickAImpl_GetEffectInfo
,
1402 JoystickAImpl_GetForceFeedbackState
,
1403 JoystickAImpl_SendForceFeedbackCommand
,
1404 JoystickAImpl_EnumCreatedEffectObjects
,
1405 IDirectInputDevice2AImpl_Escape
,
1407 IDirectInputDevice2AImpl_SendDeviceData
,
1408 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1409 IDirectInputDevice7AImpl_WriteEffectToFile
,
1410 IDirectInputDevice8AImpl_BuildActionMap
,
1411 IDirectInputDevice8AImpl_SetActionMap
,
1412 IDirectInputDevice8AImpl_GetImageInfo
1415 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1416 # define XCAST(fun) (typeof(JoystickWvt.fun))
1418 # define XCAST(fun) (void*)
1421 static const IDirectInputDevice8WVtbl JoystickWvt
=
1423 IDirectInputDevice2WImpl_QueryInterface
,
1424 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
1425 XCAST(Release
)JoystickAImpl_Release
,
1426 XCAST(GetCapabilities
)JoystickAImpl_GetCapabilities
,
1427 IDirectInputDevice2WImpl_EnumObjects
,
1428 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1429 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1430 XCAST(Acquire
)JoystickAImpl_Acquire
,
1431 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1432 XCAST(GetDeviceState
)JoystickAImpl_GetDeviceState
,
1433 XCAST(GetDeviceData
)IDirectInputDevice2AImpl_GetDeviceData
,
1434 XCAST(SetDataFormat
)IDirectInputDevice2AImpl_SetDataFormat
,
1435 XCAST(SetEventNotification
)IDirectInputDevice2AImpl_SetEventNotification
,
1436 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
1437 JoystickWImpl_GetObjectInfo
,
1438 IDirectInputDevice2WImpl_GetDeviceInfo
,
1439 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
1440 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
1441 XCAST(CreateEffect
)JoystickAImpl_CreateEffect
,
1442 JoystickWImpl_EnumEffects
,
1443 JoystickWImpl_GetEffectInfo
,
1444 XCAST(GetForceFeedbackState
)JoystickAImpl_GetForceFeedbackState
,
1445 XCAST(SendForceFeedbackCommand
)JoystickAImpl_SendForceFeedbackCommand
,
1446 XCAST(EnumCreatedEffectObjects
)JoystickAImpl_EnumCreatedEffectObjects
,
1447 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1448 XCAST(Poll
)JoystickAImpl_Poll
,
1449 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1450 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1451 IDirectInputDevice7WImpl_WriteEffectToFile
,
1452 IDirectInputDevice8WImpl_BuildActionMap
,
1453 IDirectInputDevice8WImpl_SetActionMap
,
1454 IDirectInputDevice8WImpl_GetImageInfo
1458 #else /* HAVE_CORRECT_LINUXINPUT_H */
1460 const struct dinput_device joystick_linuxinput_device
= {
1461 "Wine Linux-input joystick driver",
1468 #endif /* HAVE_CORRECT_LINUXINPUT_H */