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"
64 #include "dinput_private.h"
65 #include "device_private.h"
67 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
71 * Maps POV x & y event values to a DX "clock" position:
78 DWORD
joystick_map_pov(POINTL
*p
)
81 return p
->y
< 0 ? 4500 : !p
->y
? 9000 : 13500;
83 return p
->y
< 0 ? 31500 : !p
->y
? 27000 : 22500;
85 return p
->y
< 0 ? 0 : !p
->y
? -1 : 18000;
89 * This maps the read value (from the input event) to a value in the
92 * Dead zone is in % multiplied by a 100 (range 0..10000)
94 LONG
joystick_map_axis(ObjProps
*props
, int val
)
97 LONG dead_zone
= MulDiv( props
->lDeadZone
, props
->lDevMax
- props
->lDevMin
, 10000 );
98 LONG dev_range
= props
->lDevMax
- props
->lDevMin
- dead_zone
;
101 val
-= (props
->lDevMin
+ props
->lDevMax
) / 2;
103 /* Remove dead zone */
104 if (abs( val
) <= dead_zone
/ 2)
107 val
= val
< 0 ? val
+ dead_zone
/ 2 : val
- dead_zone
/ 2;
109 /* Scale and map the value from the device range into the required range */
110 ret
= MulDiv( val
, props
->lMax
- props
->lMin
, dev_range
) +
111 (props
->lMin
+ props
->lMax
) / 2;
113 /* Clamp in case or rounding errors */
114 if (ret
> props
->lMax
) ret
= props
->lMax
;
115 else if (ret
< props
->lMin
) ret
= props
->lMin
;
117 TRACE( "(%d <%d> %d) -> (%d <%d> %d): val=%d ret=%d\n",
118 props
->lDevMin
, dead_zone
, props
->lDevMax
,
119 props
->lMin
, props
->lDeadZone
, props
->lMax
,
125 #ifdef HAVE_CORRECT_LINUXINPUT_H
127 #define EVDEVPREFIX "/dev/input/event"
129 /* Wine joystick driver object instances */
130 #define WINE_JOYSTICK_MAX_AXES 8
131 #define WINE_JOYSTICK_MAX_POVS 4
132 #define WINE_JOYSTICK_MAX_BUTTONS 128
134 struct wine_input_absinfo
{
142 typedef struct EffectListItem EffectListItem
;
143 struct EffectListItem
145 LPDIRECTINPUTEFFECT ref
;
146 struct EffectListItem
* next
;
149 /* implemented in effect_linuxinput.c */
150 HRESULT
linuxinput_create_effect(int* fd
, REFGUID rguid
, LPDIRECTINPUTEFFECT
* peff
);
151 HRESULT
linuxinput_get_info_A(int fd
, REFGUID rguid
, LPDIEFFECTINFOA info
);
152 HRESULT
linuxinput_get_info_W(int fd
, REFGUID rguid
, LPDIEFFECTINFOW info
);
154 typedef struct JoystickImpl JoystickImpl
;
155 static const IDirectInputDevice8AVtbl JoystickAvt
;
156 static const IDirectInputDevice8WVtbl JoystickWvt
;
166 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
167 BYTE evbits
[(EV_MAX
+7)/8];
168 BYTE absbits
[(ABS_MAX
+7)/8];
169 BYTE keybits
[(KEY_MAX
+7)/8];
170 BYTE ffbits
[(FF_MAX
+7)/8];
172 /* data returned by the EVIOCGABS() ioctl */
173 struct wine_input_absinfo axes
[ABS_MAX
];
178 struct IDirectInputDevice2AImpl base
;
180 struct JoyDev
*joydev
;
182 /* joystick private */
187 ObjProps props
[ABS_MAX
];
192 /* LUT for KEY_ to offset in rgbButtons */
193 BYTE buttons
[KEY_MAX
];
199 /* Force feedback variables */
200 EffectListItem
* top_effect
;
204 static void fake_current_js_state(JoystickImpl
*ji
);
205 static void find_joydevs(void);
207 /* This GUID is slightly different from the linux joystick one. Take note. */
208 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
212 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
215 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
217 #define MAX_JOYDEV 64
219 static int have_joydevs
= -1;
220 static struct JoyDev
*joydevs
= NULL
;
222 static void find_joydevs(void)
226 if (have_joydevs
!=-1) {
232 for (i
=0;i
<MAX_JOYDEV
;i
++) {
234 struct JoyDev joydev
= {0};
239 snprintf(buf
,MAX_PATH
,EVDEVPREFIX
"%d",i
);
242 if ((fd
=open(buf
, O_RDWR
))==-1) {
243 fd
= open(buf
, O_RDONLY
);
249 if ((-1==ioctl(fd
,EVIOCGBIT(0,sizeof(joydev
.evbits
)),joydev
.evbits
))) {
250 perror("EVIOCGBIT 0");
254 if (-1==ioctl(fd
,EVIOCGBIT(EV_ABS
,sizeof(joydev
.absbits
)),joydev
.absbits
)) {
255 perror("EVIOCGBIT EV_ABS");
259 if (-1==ioctl(fd
,EVIOCGBIT(EV_KEY
,sizeof(joydev
.keybits
)),joydev
.keybits
)) {
260 perror("EVIOCGBIT EV_KEY");
264 /* A true joystick has at least axis X and Y, and at least 1
265 * button. copied from linux/drivers/input/joydev.c */
266 if (test_bit(joydev
.absbits
,ABS_X
) && test_bit(joydev
.absbits
,ABS_Y
) &&
267 ( test_bit(joydev
.keybits
,BTN_TRIGGER
) ||
268 test_bit(joydev
.keybits
,BTN_A
) ||
269 test_bit(joydev
.keybits
,BTN_1
)
273 joydev
.device
= strdup(buf
);
275 if (-1!=ioctl(fd
, EVIOCGNAME(MAX_PATH
-1), buf
)) {
277 joydev
.name
= strdup(buf
);
279 joydev
.name
= joydev
.device
;
282 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
283 joydev
.guid
.Data3
+= have_joydevs
;
285 TRACE("Found a joystick on %s: %s (%s)\n",
286 joydev
.device
, joydev
.name
,
287 debugstr_guid(&joydev
.guid
)
290 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
292 test_bit(joydev
.evbits
, EV_FF
) &&
293 ioctl(fd
, EVIOCGBIT(EV_FF
, sizeof(joydev
.ffbits
)), joydev
.ffbits
) != -1 &&
294 ioctl(fd
, EVIOCGEFFECTS
, &joydev
.num_effects
) != -1 &&
295 joydev
.num_effects
> 0)
297 TRACE(" ... with force feedback\n");
302 for (j
=0;j
<ABS_MAX
;j
++) {
303 if (test_bit(joydev
.absbits
,j
)) {
304 if (-1!=ioctl(fd
,EVIOCGABS(j
),&(joydev
.axes
[j
]))) {
305 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
307 joydev
.axes
[j
].value
,
308 joydev
.axes
[j
].minimum
,
309 joydev
.axes
[j
].maximum
,
317 if (have_joydevs
==0) {
318 joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
320 HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1+have_joydevs
) * sizeof(struct JoyDev
));
322 memcpy(joydevs
+have_joydevs
, &joydev
, sizeof(struct JoyDev
));
331 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
333 DWORD dwSize
= lpddi
->dwSize
;
335 TRACE("%d %p\n", dwSize
, lpddi
);
336 memset(lpddi
, 0, dwSize
);
338 lpddi
->dwSize
= dwSize
;
339 lpddi
->guidInstance
= joydevs
[id
].guid
;
340 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
341 lpddi
->guidFFDriver
= GUID_NULL
;
343 if (version
>= 0x0800)
344 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
346 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
348 strcpy(lpddi
->tszInstanceName
, joydevs
[id
].name
);
349 strcpy(lpddi
->tszProductName
, joydevs
[id
].device
);
352 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
354 DWORD dwSize
= lpddi
->dwSize
;
356 TRACE("%d %p\n", dwSize
, lpddi
);
357 memset(lpddi
, 0, dwSize
);
359 lpddi
->dwSize
= dwSize
;
360 lpddi
->guidInstance
= joydevs
[id
].guid
;
361 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
362 lpddi
->guidFFDriver
= GUID_NULL
;
364 if (version
>= 0x0800)
365 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
367 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
369 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
370 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].device
, -1, lpddi
->tszProductName
, MAX_PATH
);
373 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
377 if (id
>= have_joydevs
) {
381 if (!((dwDevType
== 0) ||
382 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
383 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
386 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
387 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
391 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
392 fill_joystick_dideviceinstanceA(lpddi
, version
, id
);
398 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
402 if (id
>= have_joydevs
) {
406 if (!((dwDevType
== 0) ||
407 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
408 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
411 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
412 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
416 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
417 fill_joystick_dideviceinstanceW(lpddi
, version
, id
);
423 static JoystickImpl
*alloc_device(REFGUID rguid
, const void *jvt
, IDirectInputImpl
*dinput
, unsigned short index
)
425 JoystickImpl
* newDevice
;
426 LPDIDATAFORMAT df
= NULL
;
428 char buffer
[MAX_PATH
+16];
430 LONG def_deadzone
= 0;
432 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
433 if (!newDevice
) return NULL
;
435 newDevice
->base
.lpVtbl
= jvt
;
436 newDevice
->base
.ref
= 1;
437 newDevice
->base
.guid
= *rguid
;
438 newDevice
->base
.dinput
= dinput
;
439 newDevice
->joyfd
= -1;
440 newDevice
->joydev
= &joydevs
[index
];
441 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
442 newDevice
->ff_state
= FF_STATUS_STOPPED
;
444 InitializeCriticalSection(&newDevice
->base
.crit
);
445 newDevice
->base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
448 get_app_key(&hkey
, &appkey
);
450 if (!get_config_key(hkey
, appkey
, "DefaultDeadZone", buffer
, MAX_PATH
))
452 def_deadzone
= atoi(buffer
);
453 TRACE("setting default deadzone to: %d\n", def_deadzone
);
455 if (appkey
) RegCloseKey(appkey
);
456 if (hkey
) RegCloseKey(hkey
);
458 /* Create copy of default data format */
459 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
460 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
461 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
463 /* Supported Axis & POVs should map 1-to-1 */
464 for (i
= 0; i
< WINE_JOYSTICK_MAX_AXES
; i
++)
466 if (!test_bit(newDevice
->joydev
->absbits
, i
)) {
467 newDevice
->axes
[i
] = -1;
471 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[i
], df
->dwObjSize
);
472 newDevice
->axes
[i
] = idx
;
473 newDevice
->props
[idx
].lDevMin
= newDevice
->joydev
->axes
[i
].minimum
;
474 newDevice
->props
[idx
].lDevMax
= newDevice
->joydev
->axes
[i
].maximum
;
475 newDevice
->props
[idx
].lMin
= 0;
476 newDevice
->props
[idx
].lMax
= 0xffff;
477 newDevice
->props
[idx
].lSaturation
= 0;
478 newDevice
->props
[idx
].lDeadZone
= def_deadzone
;
480 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->numAxes
++) | DIDFT_ABSAXIS
;
483 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
485 if (!test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) ||
486 !test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2)) {
487 newDevice
->axes
[ABS_HAT0X
+ i
* 2] = newDevice
->axes
[ABS_HAT0Y
+ i
* 2] = -1;
491 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[i
+ WINE_JOYSTICK_MAX_AXES
], df
->dwObjSize
);
492 newDevice
->axes
[ABS_HAT0X
+ i
* 2] = newDevice
->axes
[ABS_HAT0Y
+ i
* 2] = i
;
493 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->numPOVs
++) | DIDFT_POV
;
496 /* Buttons can be anywhere, so check all */
497 for (i
= 0; i
< KEY_MAX
&& newDevice
->numButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
499 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
501 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->numButtons
+ WINE_JOYSTICK_MAX_AXES
+ WINE_JOYSTICK_MAX_POVS
], df
->dwObjSize
);
502 newDevice
->buttons
[i
] = 0x80 | newDevice
->numButtons
;
503 df
->rgodf
[idx
].pguid
= &GUID_Button
;
504 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->numButtons
++) | DIDFT_PSHBUTTON
;
508 fake_current_js_state(newDevice
);
510 newDevice
->base
.data_format
.wine_df
= df
;
511 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A
)newDevice
->base
.dinput
);
515 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
516 HeapFree(GetProcessHeap(), 0, df
);
517 HeapFree(GetProcessHeap(), 0, newDevice
);
521 /******************************************************************************
522 * get_joystick_index : Get the joystick index from a given GUID
524 static unsigned short get_joystick_index(REFGUID guid
)
526 GUID wine_joystick
= DInput_Wine_Joystick_Base_GUID
;
527 GUID dev_guid
= *guid
;
529 wine_joystick
.Data3
= 0;
532 /* for the standard joystick GUID use index 0 */
533 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
535 /* for the wine joystick GUIDs use the index stored in Data3 */
536 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
- DInput_Wine_Joystick_Base_GUID
.Data3
;
541 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
543 unsigned short index
;
547 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
548 have_joydevs
&& index
< have_joydevs
)
550 if ((riid
== NULL
) ||
551 IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
552 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
553 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
554 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
556 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &JoystickAvt
, dinput
, index
);
557 TRACE("Created a Joystick device (%p)\n", *pdev
);
561 ERR("out of memory\n");
562 return DIERR_OUTOFMEMORY
;
567 WARN("no interface\n");
568 return DIERR_NOINTERFACE
;
571 return DIERR_DEVICENOTREG
;
575 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
577 unsigned short index
;
581 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
582 have_joydevs
&& index
< have_joydevs
)
584 if ((riid
== NULL
) ||
585 IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
586 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
587 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
588 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
590 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &JoystickWvt
, dinput
, index
);
591 TRACE("Created a Joystick device (%p)\n", *pdev
);
595 ERR("out of memory\n");
596 return DIERR_OUTOFMEMORY
;
600 WARN("no interface\n");
601 return DIERR_NOINTERFACE
;
604 WARN("invalid device GUID\n");
605 return DIERR_DEVICENOTREG
;
608 const struct dinput_device joystick_linuxinput_device
= {
609 "Wine Linux-input joystick driver",
612 joydev_create_deviceA
,
613 joydev_create_deviceW
616 /******************************************************************************
617 * Acquire : gets exclusive control of the joystick
619 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
621 JoystickImpl
*This
= (JoystickImpl
*)iface
;
624 TRACE("(this=%p)\n",This
);
626 res
= IDirectInputDevice2AImpl_Acquire(iface
);
628 if (-1==(This
->joyfd
=open(This
->joydev
->device
,O_RDWR
))) {
629 if (-1==(This
->joyfd
=open(This
->joydev
->device
,O_RDONLY
))) {
630 /* Couldn't open the device at all */
631 perror(This
->joydev
->device
);
632 IDirectInputDevice2AImpl_Unacquire(iface
);
633 return DIERR_NOTFOUND
;
635 /* Couldn't open in r/w but opened in read-only. */
636 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
644 /******************************************************************************
645 * Unacquire : frees the joystick
647 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
649 JoystickImpl
*This
= (JoystickImpl
*)iface
;
652 TRACE("(this=%p)\n",This
);
653 res
= IDirectInputDevice2AImpl_Unacquire(iface
);
654 if (res
==DI_OK
&& This
->joyfd
!=-1) {
662 * set the current state of the js device as it would be with the middle
665 #define CENTER_AXIS(a) \
666 (ji->axes[a] == -1 ? 0 : joystick_map_axis( &ji->props[ji->axes[a]], \
667 ji->joydev->axes[a].value ))
668 static void fake_current_js_state(JoystickImpl
*ji
)
672 /* center the axes */
673 ji
->js
.lX
= CENTER_AXIS(ABS_X
);
674 ji
->js
.lY
= CENTER_AXIS(ABS_Y
);
675 ji
->js
.lZ
= CENTER_AXIS(ABS_Z
);
676 ji
->js
.lRx
= CENTER_AXIS(ABS_RX
);
677 ji
->js
.lRy
= CENTER_AXIS(ABS_RY
);
678 ji
->js
.lRz
= CENTER_AXIS(ABS_RZ
);
679 ji
->js
.rglSlider
[0] = CENTER_AXIS(ABS_THROTTLE
);
680 ji
->js
.rglSlider
[1] = CENTER_AXIS(ABS_RUDDER
);
682 /* POV center is -1 */
683 for (i
= 0; i
< 4; i
++)
684 ji
->js
.rgdwPOV
[i
] = -1;
688 /* convert wine format offset to user format object index */
689 static void joy_polldev(JoystickImpl
*This
)
692 struct input_event ie
;
702 plfd
.fd
= This
->joyfd
;
703 plfd
.events
= POLLIN
;
705 if (poll(&plfd
,1,0) != 1)
708 /* we have one event, so we can read */
709 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
712 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
714 case EV_KEY
: /* button */
716 int btn
= This
->buttons
[ie
.code
];
718 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
722 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
723 This
->js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
729 int axis
= This
->axes
[ie
.code
];
733 inst_id
= DIDFT_MAKEINSTANCE(axis
) | (ie
.code
< ABS_HAT0X
? DIDFT_ABSAXIS
: DIDFT_POV
);
734 value
= joystick_map_axis(&This
->props
[id_to_object(This
->base
.data_format
.wine_df
, inst_id
)], ie
.value
);
737 case ABS_X
: This
->js
.lX
= value
; break;
738 case ABS_Y
: This
->js
.lY
= value
; break;
739 case ABS_Z
: This
->js
.lZ
= value
; break;
740 case ABS_RX
: This
->js
.lRx
= value
; break;
741 case ABS_RY
: This
->js
.lRy
= value
; break;
742 case ABS_RZ
: This
->js
.lRz
= value
; break;
743 case ABS_THROTTLE
: This
->js
.rglSlider
[0] = value
; break;
744 case ABS_RUDDER
: This
->js
.rglSlider
[1] = value
; break;
745 case ABS_HAT0X
: case ABS_HAT0Y
: case ABS_HAT1X
: case ABS_HAT1Y
:
746 case ABS_HAT2X
: case ABS_HAT2Y
: case ABS_HAT3X
: case ABS_HAT3Y
:
748 int idx
= (ie
.code
- ABS_HAT0X
) / 2;
751 This
->povs
[idx
].y
= ie
.value
;
753 This
->povs
[idx
].x
= ie
.value
;
755 This
->js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
759 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
763 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
765 This
->ff_state
= ie
.value
;
770 /* there is nothing to do */
774 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
778 queue_event((LPDIRECTINPUTDEVICE8A
)This
,
779 id_to_offset(&This
->base
.data_format
, inst_id
),
780 value
, ie
.time
.tv_usec
, This
->base
.dinput
->evsequence
++);
784 /******************************************************************************
785 * GetDeviceState : returns the "state" of the joystick.
788 static HRESULT WINAPI
JoystickAImpl_GetDeviceState(
789 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
791 JoystickImpl
*This
= (JoystickImpl
*)iface
;
793 TRACE("(this=%p,0x%08x,%p)\n", This
, len
, ptr
);
795 if (!This
->base
.acquired
)
797 WARN("not acquired\n");
798 return DIERR_NOTACQUIRED
;
803 /* convert and copy data to user supplied buffer */
804 fill_DataFormat(ptr
, &This
->js
, &This
->base
.data_format
);
809 /******************************************************************************
810 * SetProperty : change input device properties
812 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
816 JoystickImpl
*This
= (JoystickImpl
*)iface
;
819 WARN("invalid argument\n");
820 return DIERR_INVALIDPARAM
;
823 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
824 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
825 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
827 if (!HIWORD(rguid
)) {
828 switch (LOWORD(rguid
)) {
829 case (DWORD
)DIPROP_RANGE
: {
830 LPCDIPROPRANGE pr
= (LPCDIPROPRANGE
)ph
;
832 if (ph
->dwHow
== DIPH_DEVICE
) {
834 TRACE("proprange(%d,%d) all\n", pr
->lMin
, pr
->lMax
);
835 for (i
= 0; i
< This
->base
.data_format
.wine_df
->dwNumObjs
; i
++) {
836 /* Scale dead-zone */
837 This
->props
[i
].lDeadZone
= MulDiv(This
->props
[i
].lDeadZone
, pr
->lMax
- pr
->lMin
,
838 This
->props
[i
].lMax
- This
->props
[i
].lMin
);
839 This
->props
[i
].lMin
= pr
->lMin
;
840 This
->props
[i
].lMax
= pr
->lMax
;
843 int obj
= find_property(&This
->base
.data_format
, ph
);
845 TRACE("proprange(%d,%d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
847 /* Scale dead-zone */
848 This
->props
[obj
].lDeadZone
= MulDiv(This
->props
[obj
].lDeadZone
, pr
->lMax
- pr
->lMin
,
849 This
->props
[obj
].lMax
- This
->props
[obj
].lMin
);
850 This
->props
[obj
].lMin
= pr
->lMin
;
851 This
->props
[obj
].lMax
= pr
->lMax
;
854 fake_current_js_state(This
);
857 case (DWORD
)DIPROP_DEADZONE
: {
858 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
859 if (ph
->dwHow
== DIPH_DEVICE
) {
861 TRACE("deadzone(%d) all\n", pd
->dwData
);
862 for (i
= 0; i
< This
->base
.data_format
.wine_df
->dwNumObjs
; i
++) {
863 This
->props
[i
].lDeadZone
= pd
->dwData
;
866 int obj
= find_property(&This
->base
.data_format
, ph
);
868 TRACE("deadzone(%d) obj=%d\n", pd
->dwData
, obj
);
870 This
->props
[obj
].lDeadZone
= pd
->dwData
;
873 fake_current_js_state(This
);
876 case (DWORD
)DIPROP_CALIBRATIONMODE
: {
877 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
878 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd
->dwData
);
881 case (DWORD
)DIPROP_AUTOCENTER
: {
882 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
884 FIXME("DIPROP_AUTOCENTER(%d)\n", pd
->dwData
);
888 return IDirectInputDevice2AImpl_SetProperty(iface
, rguid
, ph
);
894 static HRESULT WINAPI
JoystickAImpl_GetCapabilities(
895 LPDIRECTINPUTDEVICE8A iface
,
896 LPDIDEVCAPS lpDIDevCaps
)
898 JoystickImpl
*This
= (JoystickImpl
*)iface
;
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
->base
.dinput
->dwVersion
>= 0x0800)
914 lpDIDevCaps
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
916 lpDIDevCaps
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
918 if (This
->joydev
->has_ff
)
919 lpDIDevCaps
->dwFlags
|= DIDC_FORCEFEEDBACK
;
921 lpDIDevCaps
->dwAxes
= This
->numAxes
;
922 lpDIDevCaps
->dwButtons
= This
->numButtons
;
923 lpDIDevCaps
->dwPOVs
= This
->numPOVs
;
928 static HRESULT WINAPI
JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface
)
930 JoystickImpl
*This
= (JoystickImpl
*)iface
;
932 TRACE("(%p)\n",This
);
934 if (!This
->base
.acquired
)
935 return DIERR_NOTACQUIRED
;
941 /******************************************************************************
942 * GetProperty : get input device properties
944 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
946 LPDIPROPHEADER pdiph
)
948 JoystickImpl
*This
= (JoystickImpl
*)iface
;
950 TRACE("(this=%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
951 _dump_DIPROPHEADER(pdiph
);
953 if (HIWORD(rguid
)) return DI_OK
;
955 switch (LOWORD(rguid
)) {
956 case (DWORD
) DIPROP_RANGE
:
958 LPDIPROPRANGE pr
= (LPDIPROPRANGE
) pdiph
;
959 int obj
= find_property(&This
->base
.data_format
, pdiph
);
961 if (obj
< 0) return DIERR_OBJECTNOTFOUND
;
963 pr
->lMin
= This
->props
[obj
].lMin
;
964 pr
->lMax
= This
->props
[obj
].lMax
;
965 TRACE("range(%d, %d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
968 case (DWORD
) DIPROP_DEADZONE
:
970 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
971 int obj
= find_property(&This
->base
.data_format
, pdiph
);
973 if (obj
< 0) return DIERR_OBJECTNOTFOUND
;
975 pd
->dwData
= This
->props
[obj
].lDeadZone
;
976 TRACE("deadzone(%d) obj=%d\n", pd
->dwData
, obj
);
981 return IDirectInputDevice2AImpl_GetProperty(iface
, rguid
, pdiph
);
987 /******************************************************************************
988 * GetObjectInfo : get information about a device object such as a button
991 static HRESULT WINAPI
JoystickWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface
,
992 LPDIDEVICEOBJECTINSTANCEW pdidoi
, DWORD dwObj
, DWORD dwHow
)
994 static const WCHAR axisW
[] = {'A','x','i','s',' ','%','d',0};
995 static const WCHAR povW
[] = {'P','O','V',' ','%','d',0};
996 static const WCHAR buttonW
[] = {'B','u','t','t','o','n',' ','%','d',0};
999 res
= IDirectInputDevice2WImpl_GetObjectInfo(iface
, pdidoi
, dwObj
, dwHow
);
1000 if (res
!= DI_OK
) return res
;
1002 if (pdidoi
->dwType
& DIDFT_AXIS
)
1003 sprintfW(pdidoi
->tszName
, axisW
, DIDFT_GETINSTANCE(pdidoi
->dwType
));
1004 else if (pdidoi
->dwType
& DIDFT_POV
)
1005 sprintfW(pdidoi
->tszName
, povW
, DIDFT_GETINSTANCE(pdidoi
->dwType
));
1006 else if (pdidoi
->dwType
& DIDFT_BUTTON
)
1007 sprintfW(pdidoi
->tszName
, buttonW
, DIDFT_GETINSTANCE(pdidoi
->dwType
));
1009 _dump_OBJECTINSTANCEW(pdidoi
);
1013 static HRESULT WINAPI
JoystickAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface
,
1014 LPDIDEVICEOBJECTINSTANCEA pdidoi
, DWORD dwObj
, DWORD dwHow
)
1017 DIDEVICEOBJECTINSTANCEW didoiW
;
1018 DWORD dwSize
= pdidoi
->dwSize
;
1020 didoiW
.dwSize
= sizeof(didoiW
);
1021 res
= JoystickWImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W
)iface
, &didoiW
, dwObj
, dwHow
);
1022 if (res
!= DI_OK
) return res
;
1024 memset(pdidoi
, 0, pdidoi
->dwSize
);
1025 memcpy(pdidoi
, &didoiW
, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW
, tszName
));
1026 pdidoi
->dwSize
= dwSize
;
1027 WideCharToMultiByte(CP_ACP
, 0, didoiW
.tszName
, -1, pdidoi
->tszName
,
1028 sizeof(pdidoi
->tszName
), NULL
, NULL
);
1033 /******************************************************************************
1034 * CreateEffect - Create a new FF effect with the specified params
1036 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
,
1039 LPDIRECTINPUTEFFECT
*ppdef
,
1040 LPUNKNOWN pUnkOuter
)
1042 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1043 EffectListItem
* new = NULL
;
1044 HRESULT retval
= DI_OK
;
1047 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1048 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
1050 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1051 TRACE("not available (compiled w/o ff support)\n");
1056 new = HeapAlloc(GetProcessHeap(), 0, sizeof(EffectListItem
));
1057 new->next
= This
->top_effect
;
1058 This
->top_effect
= new;
1060 retval
= linuxinput_create_effect(&(This
->joyfd
), rguid
, &(new->ref
));
1061 if (retval
!= DI_OK
)
1065 retval
= IDirectInputEffect_SetParameters(new->ref
, lpeff
, 0);
1066 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1071 if (pUnkOuter
!= NULL
)
1072 FIXME("Interface aggregation not implemented.\n");
1076 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1079 /*******************************************************************************
1080 * EnumEffects - Enumerate available FF effects
1082 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1083 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1087 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1088 DIEFFECTINFOA dei
; /* feif */
1089 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1090 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1092 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
1094 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1096 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1097 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1098 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1099 (*lpCallback
)(&dei
, pvRef
);
1102 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1103 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1104 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1105 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1106 (*lpCallback
)(&dei
, pvRef
);
1108 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1109 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1110 (*lpCallback
)(&dei
, pvRef
);
1112 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1113 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1114 (*lpCallback
)(&dei
, pvRef
);
1116 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1117 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1118 (*lpCallback
)(&dei
, pvRef
);
1120 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1121 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1122 (*lpCallback
)(&dei
, pvRef
);
1126 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1127 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1128 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1129 (*lpCallback
)(&dei
, pvRef
);
1132 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1133 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1134 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1135 (*lpCallback
)(&dei
, pvRef
);
1137 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1138 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1139 (*lpCallback
)(&dei
, pvRef
);
1141 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1142 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1143 (*lpCallback
)(&dei
, pvRef
);
1145 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1146 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1147 (*lpCallback
)(&dei
, pvRef
);
1156 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1157 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1161 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1162 /* seems silly to duplicate all this code but all the structures and functions
1163 * are actually different (A/W) */
1164 DIEFFECTINFOW dei
; /* feif */
1165 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1166 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1167 int xfd
= This
->joyfd
;
1169 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1171 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1173 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1174 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1175 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1176 (*lpCallback
)(&dei
, pvRef
);
1179 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1180 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1181 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1182 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1183 (*lpCallback
)(&dei
, pvRef
);
1185 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1186 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1187 (*lpCallback
)(&dei
, pvRef
);
1189 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1190 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1191 (*lpCallback
)(&dei
, pvRef
);
1193 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1194 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1195 (*lpCallback
)(&dei
, pvRef
);
1197 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1198 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1199 (*lpCallback
)(&dei
, pvRef
);
1203 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1204 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1205 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1206 (*lpCallback
)(&dei
, pvRef
);
1209 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1210 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1211 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1212 (*lpCallback
)(&dei
, pvRef
);
1214 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1215 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1216 (*lpCallback
)(&dei
, pvRef
);
1218 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1219 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1220 (*lpCallback
)(&dei
, pvRef
);
1222 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1223 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1224 (*lpCallback
)(&dei
, pvRef
);
1228 /* return to unacquired state if that's where it was */
1230 IDirectInputDevice8_Unacquire(iface
);
1236 /*******************************************************************************
1237 * GetEffectInfo - Get information about a particular effect
1239 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1240 LPDIEFFECTINFOA pdei
,
1243 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1245 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1247 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1248 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1254 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1255 LPDIEFFECTINFOW pdei
,
1258 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1260 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1262 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1263 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1269 /*******************************************************************************
1270 * GetForceFeedbackState - Get information about the device's FF state
1272 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(
1273 LPDIRECTINPUTDEVICE8A iface
,
1276 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1278 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1282 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1283 /* DIGFFS_STOPPED is the only mandatory flag to report */
1284 if (This
->ff_state
== FF_STATUS_STOPPED
)
1285 (*pdwOut
) |= DIGFFS_STOPPED
;
1291 /*******************************************************************************
1292 * SendForceFeedbackCommand - Send a command to the device's FF system
1294 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(
1295 LPDIRECTINPUTDEVICE8A iface
,
1298 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1299 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1301 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1302 if (dwFlags
== DISFFC_STOPALL
) {
1303 /* Stop all effects */
1304 EffectListItem
* itr
= This
->top_effect
;
1306 IDirectInputEffect_Stop(itr
->ref
);
1309 } else if (dwFlags
== DISFFC_RESET
) {
1310 /* Stop, unload, release and free all effects */
1311 /* This returns the device to its "bare" state */
1312 while (This
->top_effect
) {
1313 EffectListItem
* temp
= This
->top_effect
;
1314 IDirectInputEffect_Stop(temp
->ref
);
1315 IDirectInputEffect_Unload(temp
->ref
);
1316 IDirectInputEffect_Release(temp
->ref
);
1317 This
->top_effect
= temp
->next
;
1318 HeapFree(GetProcessHeap(), 0, temp
);
1320 } else if (dwFlags
== DISFFC_PAUSE
|| dwFlags
== DISFFC_CONTINUE
) {
1321 FIXME("No support for Pause or Continue in linux\n");
1322 } else if (dwFlags
== DISFFC_SETACTUATORSOFF
1323 || dwFlags
== DISFFC_SETACTUATORSON
) {
1324 FIXME("No direct actuator control in linux\n");
1326 FIXME("Unknown Force Feedback Command!\n");
1327 return DIERR_INVALIDPARAM
;
1331 return DIERR_UNSUPPORTED
;
1335 /*******************************************************************************
1336 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1337 * created for this device.
1339 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(
1340 LPDIRECTINPUTDEVICE8A iface
,
1341 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1345 /* this function is safe to call on non-ff-enabled builds */
1347 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1348 EffectListItem
* itr
= This
->top_effect
;
1349 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1352 return DIERR_INVALIDPARAM
;
1355 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1358 (*lpCallback
)(itr
->ref
, pvRef
);
1365 /******************************************************************************
1366 * GetDeviceInfo : get information about a device's identity
1368 static HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface
,
1369 LPDIDEVICEINSTANCEA pdidi
)
1371 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1373 TRACE("(%p) %p\n", This
, pdidi
);
1375 if (pdidi
== NULL
) return E_POINTER
;
1376 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1377 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)))
1378 return DIERR_INVALIDPARAM
;
1380 fill_joystick_dideviceinstanceA(pdidi
, This
->base
.dinput
->dwVersion
,
1381 get_joystick_index(&This
->base
.guid
));
1385 static HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
,
1386 LPDIDEVICEINSTANCEW pdidi
)
1388 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1390 TRACE("(%p) %p\n", This
, pdidi
);
1392 if (pdidi
== NULL
) return E_POINTER
;
1393 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1394 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)))
1395 return DIERR_INVALIDPARAM
;
1397 fill_joystick_dideviceinstanceW(pdidi
, This
->base
.dinput
->dwVersion
,
1398 get_joystick_index(&This
->base
.guid
));
1402 static const IDirectInputDevice8AVtbl JoystickAvt
=
1404 IDirectInputDevice2AImpl_QueryInterface
,
1405 IDirectInputDevice2AImpl_AddRef
,
1406 IDirectInputDevice2AImpl_Release
,
1407 JoystickAImpl_GetCapabilities
,
1408 IDirectInputDevice2AImpl_EnumObjects
,
1409 JoystickAImpl_GetProperty
,
1410 JoystickAImpl_SetProperty
,
1411 JoystickAImpl_Acquire
,
1412 JoystickAImpl_Unacquire
,
1413 JoystickAImpl_GetDeviceState
,
1414 IDirectInputDevice2AImpl_GetDeviceData
,
1415 IDirectInputDevice2AImpl_SetDataFormat
,
1416 IDirectInputDevice2AImpl_SetEventNotification
,
1417 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1418 JoystickAImpl_GetObjectInfo
,
1419 JoystickAImpl_GetDeviceInfo
,
1420 IDirectInputDevice2AImpl_RunControlPanel
,
1421 IDirectInputDevice2AImpl_Initialize
,
1422 JoystickAImpl_CreateEffect
,
1423 JoystickAImpl_EnumEffects
,
1424 JoystickAImpl_GetEffectInfo
,
1425 JoystickAImpl_GetForceFeedbackState
,
1426 JoystickAImpl_SendForceFeedbackCommand
,
1427 JoystickAImpl_EnumCreatedEffectObjects
,
1428 IDirectInputDevice2AImpl_Escape
,
1430 IDirectInputDevice2AImpl_SendDeviceData
,
1431 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1432 IDirectInputDevice7AImpl_WriteEffectToFile
,
1433 IDirectInputDevice8AImpl_BuildActionMap
,
1434 IDirectInputDevice8AImpl_SetActionMap
,
1435 IDirectInputDevice8AImpl_GetImageInfo
1438 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1439 # define XCAST(fun) (typeof(JoystickWvt.fun))
1441 # define XCAST(fun) (void*)
1444 static const IDirectInputDevice8WVtbl JoystickWvt
=
1446 IDirectInputDevice2WImpl_QueryInterface
,
1447 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
1448 XCAST(Release
)IDirectInputDevice2AImpl_Release
,
1449 XCAST(GetCapabilities
)JoystickAImpl_GetCapabilities
,
1450 IDirectInputDevice2WImpl_EnumObjects
,
1451 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1452 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1453 XCAST(Acquire
)JoystickAImpl_Acquire
,
1454 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1455 XCAST(GetDeviceState
)JoystickAImpl_GetDeviceState
,
1456 XCAST(GetDeviceData
)IDirectInputDevice2AImpl_GetDeviceData
,
1457 XCAST(SetDataFormat
)IDirectInputDevice2AImpl_SetDataFormat
,
1458 XCAST(SetEventNotification
)IDirectInputDevice2AImpl_SetEventNotification
,
1459 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
1460 JoystickWImpl_GetObjectInfo
,
1461 JoystickWImpl_GetDeviceInfo
,
1462 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
1463 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
1464 XCAST(CreateEffect
)JoystickAImpl_CreateEffect
,
1465 JoystickWImpl_EnumEffects
,
1466 JoystickWImpl_GetEffectInfo
,
1467 XCAST(GetForceFeedbackState
)JoystickAImpl_GetForceFeedbackState
,
1468 XCAST(SendForceFeedbackCommand
)JoystickAImpl_SendForceFeedbackCommand
,
1469 XCAST(EnumCreatedEffectObjects
)JoystickAImpl_EnumCreatedEffectObjects
,
1470 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1471 XCAST(Poll
)JoystickAImpl_Poll
,
1472 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1473 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1474 IDirectInputDevice7WImpl_WriteEffectToFile
,
1475 IDirectInputDevice8WImpl_BuildActionMap
,
1476 IDirectInputDevice8WImpl_SetActionMap
,
1477 IDirectInputDevice8WImpl_GetImageInfo
1481 #else /* HAVE_CORRECT_LINUXINPUT_H */
1483 const struct dinput_device joystick_linuxinput_device
= {
1484 "Wine Linux-input joystick driver",
1491 #endif /* HAVE_CORRECT_LINUXINPUT_H */