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 TRACE( "(%d <%d> %d) -> (%d <%d> %d): val=%d ret=%d\n",
114 props
->lDevMin
, dead_zone
, props
->lDevMax
,
115 props
->lMin
, props
->lDeadZone
, props
->lMax
,
121 #ifdef HAVE_CORRECT_LINUXINPUT_H
123 #define EVDEVPREFIX "/dev/input/event"
125 /* Wine joystick driver object instances */
126 #define WINE_JOYSTICK_MAX_AXES 8
127 #define WINE_JOYSTICK_MAX_POVS 4
128 #define WINE_JOYSTICK_MAX_BUTTONS 128
130 struct wine_input_absinfo
{
138 typedef struct EffectListItem EffectListItem
;
139 struct EffectListItem
141 LPDIRECTINPUTEFFECT ref
;
142 struct EffectListItem
* next
;
145 /* implemented in effect_linuxinput.c */
146 HRESULT
linuxinput_create_effect(int* fd
, REFGUID rguid
, LPDIRECTINPUTEFFECT
* peff
);
147 HRESULT
linuxinput_get_info_A(int fd
, REFGUID rguid
, LPDIEFFECTINFOA info
);
148 HRESULT
linuxinput_get_info_W(int fd
, REFGUID rguid
, LPDIEFFECTINFOW info
);
150 typedef struct JoystickImpl JoystickImpl
;
151 static const IDirectInputDevice8AVtbl JoystickAvt
;
152 static const IDirectInputDevice8WVtbl JoystickWvt
;
162 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
163 BYTE evbits
[(EV_MAX
+7)/8];
164 BYTE absbits
[(ABS_MAX
+7)/8];
165 BYTE keybits
[(KEY_MAX
+7)/8];
166 BYTE ffbits
[(FF_MAX
+7)/8];
168 /* data returned by the EVIOCGABS() ioctl */
169 struct wine_input_absinfo axes
[ABS_MAX
];
174 struct IDirectInputDevice2AImpl base
;
176 struct JoyDev
*joydev
;
178 /* joystick private */
183 ObjProps props
[ABS_MAX
];
188 /* LUT for KEY_ to offset in rgbButtons */
189 BYTE buttons
[KEY_MAX
];
195 /* Force feedback variables */
196 EffectListItem
* top_effect
;
200 static void fake_current_js_state(JoystickImpl
*ji
);
201 static void find_joydevs(void);
203 /* This GUID is slightly different from the linux joystick one. Take note. */
204 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
208 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
211 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
213 #define MAX_JOYDEV 64
215 static int have_joydevs
= -1;
216 static struct JoyDev
*joydevs
= NULL
;
218 static void find_joydevs(void)
222 if (have_joydevs
!=-1) {
228 for (i
=0;i
<MAX_JOYDEV
;i
++) {
230 struct JoyDev joydev
= {0};
235 snprintf(buf
,MAX_PATH
,EVDEVPREFIX
"%d",i
);
238 if ((fd
=open(buf
, O_RDWR
))==-1) {
239 fd
= open(buf
, O_RDONLY
);
245 if ((-1==ioctl(fd
,EVIOCGBIT(0,sizeof(joydev
.evbits
)),joydev
.evbits
))) {
246 perror("EVIOCGBIT 0");
250 if (-1==ioctl(fd
,EVIOCGBIT(EV_ABS
,sizeof(joydev
.absbits
)),joydev
.absbits
)) {
251 perror("EVIOCGBIT EV_ABS");
255 if (-1==ioctl(fd
,EVIOCGBIT(EV_KEY
,sizeof(joydev
.keybits
)),joydev
.keybits
)) {
256 perror("EVIOCGBIT EV_KEY");
260 /* A true joystick has at least axis X and Y, and at least 1
261 * button. copied from linux/drivers/input/joydev.c */
262 if (test_bit(joydev
.absbits
,ABS_X
) && test_bit(joydev
.absbits
,ABS_Y
) &&
263 ( test_bit(joydev
.keybits
,BTN_TRIGGER
) ||
264 test_bit(joydev
.keybits
,BTN_A
) ||
265 test_bit(joydev
.keybits
,BTN_1
)
269 joydev
.device
= strdup(buf
);
271 if (-1!=ioctl(fd
, EVIOCGNAME(MAX_PATH
-1), buf
)) {
273 joydev
.name
= strdup(buf
);
275 joydev
.name
= joydev
.device
;
278 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
279 joydev
.guid
.Data3
+= have_joydevs
;
281 TRACE("Found a joystick on %s: %s (%s)\n",
282 joydev
.device
, joydev
.name
,
283 debugstr_guid(&joydev
.guid
)
286 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
288 test_bit(joydev
.evbits
, EV_FF
) &&
289 ioctl(fd
, EVIOCGBIT(EV_FF
, sizeof(joydev
.ffbits
)), joydev
.ffbits
) != -1 &&
290 ioctl(fd
, EVIOCGEFFECTS
, &joydev
.num_effects
) != -1 &&
291 joydev
.num_effects
> 0)
293 TRACE(" ... with force feedback\n");
298 for (j
=0;j
<ABS_MAX
;j
++) {
299 if (test_bit(joydev
.absbits
,j
)) {
300 if (-1!=ioctl(fd
,EVIOCGABS(j
),&(joydev
.axes
[j
]))) {
301 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
303 joydev
.axes
[j
].value
,
304 joydev
.axes
[j
].minimum
,
305 joydev
.axes
[j
].maximum
,
313 if (have_joydevs
==0) {
314 joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
316 HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1+have_joydevs
) * sizeof(struct JoyDev
));
318 memcpy(joydevs
+have_joydevs
, &joydev
, sizeof(struct JoyDev
));
327 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
329 DWORD dwSize
= lpddi
->dwSize
;
331 TRACE("%d %p\n", dwSize
, lpddi
);
332 memset(lpddi
, 0, dwSize
);
334 lpddi
->dwSize
= dwSize
;
335 lpddi
->guidInstance
= joydevs
[id
].guid
;
336 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
337 lpddi
->guidFFDriver
= GUID_NULL
;
339 if (version
>= 0x0800)
340 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
342 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
344 strcpy(lpddi
->tszInstanceName
, joydevs
[id
].name
);
345 strcpy(lpddi
->tszProductName
, joydevs
[id
].device
);
348 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
350 DWORD dwSize
= lpddi
->dwSize
;
352 TRACE("%d %p\n", dwSize
, lpddi
);
353 memset(lpddi
, 0, dwSize
);
355 lpddi
->dwSize
= dwSize
;
356 lpddi
->guidInstance
= joydevs
[id
].guid
;
357 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
358 lpddi
->guidFFDriver
= GUID_NULL
;
360 if (version
>= 0x0800)
361 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
363 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
365 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
366 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].device
, -1, lpddi
->tszProductName
, MAX_PATH
);
369 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
373 if (id
>= have_joydevs
) {
377 if (!((dwDevType
== 0) ||
378 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
379 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
382 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
383 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
387 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
388 fill_joystick_dideviceinstanceA(lpddi
, version
, id
);
394 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
398 if (id
>= have_joydevs
) {
402 if (!((dwDevType
== 0) ||
403 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
404 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
407 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
408 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
412 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
413 fill_joystick_dideviceinstanceW(lpddi
, version
, id
);
419 static JoystickImpl
*alloc_device(REFGUID rguid
, const void *jvt
, IDirectInputImpl
*dinput
, unsigned short index
)
421 JoystickImpl
* newDevice
;
422 LPDIDATAFORMAT df
= NULL
;
424 char buffer
[MAX_PATH
+16];
426 LONG def_deadzone
= 0;
428 newDevice
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(JoystickImpl
));
429 if (!newDevice
) return NULL
;
431 newDevice
->base
.lpVtbl
= jvt
;
432 newDevice
->base
.ref
= 1;
433 newDevice
->base
.guid
= *rguid
;
434 newDevice
->base
.dinput
= dinput
;
435 newDevice
->joyfd
= -1;
436 newDevice
->joydev
= &joydevs
[index
];
437 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
438 newDevice
->ff_state
= FF_STATUS_STOPPED
;
440 InitializeCriticalSection(&newDevice
->base
.crit
);
441 newDevice
->base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->base.crit");
444 get_app_key(&hkey
, &appkey
);
446 if (!get_config_key(hkey
, appkey
, "DefaultDeadZone", buffer
, MAX_PATH
))
448 def_deadzone
= atoi(buffer
);
449 TRACE("setting default deadzone to: %d\n", def_deadzone
);
451 if (appkey
) RegCloseKey(appkey
);
452 if (hkey
) RegCloseKey(hkey
);
454 /* Create copy of default data format */
455 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto failed
;
456 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
457 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
459 /* Supported Axis & POVs should map 1-to-1 */
460 for (i
= 0; i
< WINE_JOYSTICK_MAX_AXES
; i
++)
462 if (!test_bit(newDevice
->joydev
->absbits
, i
)) {
463 newDevice
->axes
[i
] = -1;
467 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[i
], df
->dwObjSize
);
468 newDevice
->axes
[i
] = idx
;
469 newDevice
->props
[idx
].lDevMin
= newDevice
->joydev
->axes
[i
].minimum
;
470 newDevice
->props
[idx
].lDevMax
= newDevice
->joydev
->axes
[i
].maximum
;
471 newDevice
->props
[idx
].lMin
= 0;
472 newDevice
->props
[idx
].lMax
= 0xffff;
473 newDevice
->props
[idx
].lSaturation
= 0;
474 newDevice
->props
[idx
].lDeadZone
= def_deadzone
;
476 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->numAxes
++) | DIDFT_ABSAXIS
;
479 for (i
= 0; i
< WINE_JOYSTICK_MAX_POVS
; i
++)
481 if (!test_bit(newDevice
->joydev
->absbits
, ABS_HAT0X
+ i
* 2) ||
482 !test_bit(newDevice
->joydev
->absbits
, ABS_HAT0Y
+ i
* 2)) {
483 newDevice
->axes
[ABS_HAT0X
+ i
* 2] = newDevice
->axes
[ABS_HAT0Y
+ i
* 2] = -1;
487 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[i
+ WINE_JOYSTICK_MAX_AXES
], df
->dwObjSize
);
488 newDevice
->axes
[ABS_HAT0X
+ i
* 2] = newDevice
->axes
[ABS_HAT0Y
+ i
* 2] = i
;
489 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->numPOVs
++) | DIDFT_POV
;
492 /* Buttons can be anywhere, so check all */
493 for (i
= 0; i
< KEY_MAX
&& newDevice
->numButtons
< WINE_JOYSTICK_MAX_BUTTONS
; i
++)
495 if (!test_bit(newDevice
->joydev
->keybits
, i
)) continue;
497 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[newDevice
->numButtons
+ WINE_JOYSTICK_MAX_AXES
+ WINE_JOYSTICK_MAX_POVS
], df
->dwObjSize
);
498 newDevice
->buttons
[i
] = 0x80 | newDevice
->numButtons
;
499 df
->rgodf
[idx
].pguid
= &GUID_Button
;
500 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(newDevice
->numButtons
++) | DIDFT_PSHBUTTON
;
504 fake_current_js_state(newDevice
);
506 newDevice
->base
.data_format
.wine_df
= df
;
507 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A
)newDevice
->base
.dinput
);
511 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
512 HeapFree(GetProcessHeap(), 0, df
);
513 HeapFree(GetProcessHeap(), 0, newDevice
);
517 /******************************************************************************
518 * get_joystick_index : Get the joystick index from a given GUID
520 static unsigned short get_joystick_index(REFGUID guid
)
522 GUID wine_joystick
= DInput_Wine_Joystick_Base_GUID
;
523 GUID dev_guid
= *guid
;
525 wine_joystick
.Data3
= 0;
528 /* for the standard joystick GUID use index 0 */
529 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
531 /* for the wine joystick GUIDs use the index stored in Data3 */
532 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
- DInput_Wine_Joystick_Base_GUID
.Data3
;
537 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
539 unsigned short index
;
543 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
544 have_joydevs
&& index
< have_joydevs
)
546 if ((riid
== NULL
) ||
547 IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
548 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
549 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
550 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
552 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &JoystickAvt
, dinput
, index
);
553 TRACE("Created a Joystick device (%p)\n", *pdev
);
557 ERR("out of memory\n");
558 return DIERR_OUTOFMEMORY
;
563 WARN("no interface\n");
564 return DIERR_NOINTERFACE
;
567 return DIERR_DEVICENOTREG
;
571 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
573 unsigned short index
;
577 if ((index
= get_joystick_index(rguid
)) < MAX_JOYDEV
&&
578 have_joydevs
&& index
< have_joydevs
)
580 if ((riid
== NULL
) ||
581 IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
582 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
583 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
584 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
586 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &JoystickWvt
, dinput
, index
);
587 TRACE("Created a Joystick device (%p)\n", *pdev
);
591 ERR("out of memory\n");
592 return DIERR_OUTOFMEMORY
;
596 WARN("no interface\n");
597 return DIERR_NOINTERFACE
;
600 WARN("invalid device GUID\n");
601 return DIERR_DEVICENOTREG
;
604 const struct dinput_device joystick_linuxinput_device
= {
605 "Wine Linux-input joystick driver",
608 joydev_create_deviceA
,
609 joydev_create_deviceW
612 /******************************************************************************
613 * Acquire : gets exclusive control of the joystick
615 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
617 JoystickImpl
*This
= (JoystickImpl
*)iface
;
620 TRACE("(this=%p)\n",This
);
622 res
= IDirectInputDevice2AImpl_Acquire(iface
);
624 if (-1==(This
->joyfd
=open(This
->joydev
->device
,O_RDWR
))) {
625 if (-1==(This
->joyfd
=open(This
->joydev
->device
,O_RDONLY
))) {
626 /* Couldn't open the device at all */
627 perror(This
->joydev
->device
);
628 IDirectInputDevice2AImpl_Unacquire(iface
);
629 return DIERR_NOTFOUND
;
631 /* Couldn't open in r/w but opened in read-only. */
632 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
640 /******************************************************************************
641 * Unacquire : frees the joystick
643 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
645 JoystickImpl
*This
= (JoystickImpl
*)iface
;
648 TRACE("(this=%p)\n",This
);
649 res
= IDirectInputDevice2AImpl_Unacquire(iface
);
650 if (res
==DI_OK
&& This
->joyfd
!=-1) {
658 * set the current state of the js device as it would be with the middle
661 #define CENTER_AXIS(a) \
662 (ji->axes[a] == -1 ? 0 : joystick_map_axis( &ji->props[ji->axes[a]], \
663 ji->joydev->axes[a].value ))
664 static void fake_current_js_state(JoystickImpl
*ji
)
668 /* center the axes */
669 ji
->js
.lX
= CENTER_AXIS(ABS_X
);
670 ji
->js
.lY
= CENTER_AXIS(ABS_Y
);
671 ji
->js
.lZ
= CENTER_AXIS(ABS_Z
);
672 ji
->js
.lRx
= CENTER_AXIS(ABS_RX
);
673 ji
->js
.lRy
= CENTER_AXIS(ABS_RY
);
674 ji
->js
.lRz
= CENTER_AXIS(ABS_RZ
);
675 ji
->js
.rglSlider
[0] = CENTER_AXIS(ABS_THROTTLE
);
676 ji
->js
.rglSlider
[1] = CENTER_AXIS(ABS_RUDDER
);
678 /* POV center is -1 */
679 for (i
= 0; i
< 4; i
++)
680 ji
->js
.rgdwPOV
[i
] = -1;
684 /* convert wine format offset to user format object index */
685 static void joy_polldev(JoystickImpl
*This
)
688 struct input_event ie
;
698 plfd
.fd
= This
->joyfd
;
699 plfd
.events
= POLLIN
;
701 if (poll(&plfd
,1,0) != 1)
704 /* we have one event, so we can read */
705 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
708 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
710 case EV_KEY
: /* button */
712 int btn
= This
->buttons
[ie
.code
];
714 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
718 inst_id
= DIDFT_MAKEINSTANCE(btn
) | DIDFT_PSHBUTTON
;
719 This
->js
.rgbButtons
[btn
] = value
= ie
.value
? 0x80 : 0x00;
725 int axis
= This
->axes
[ie
.code
];
729 inst_id
= DIDFT_MAKEINSTANCE(axis
) | (ie
.code
< ABS_HAT0X
? DIDFT_ABSAXIS
: DIDFT_POV
);
730 value
= joystick_map_axis(&This
->props
[id_to_object(This
->base
.data_format
.wine_df
, inst_id
)], ie
.value
);
733 case ABS_X
: This
->js
.lX
= value
; break;
734 case ABS_Y
: This
->js
.lY
= value
; break;
735 case ABS_Z
: This
->js
.lZ
= value
; break;
736 case ABS_RX
: This
->js
.lRx
= value
; break;
737 case ABS_RY
: This
->js
.lRy
= value
; break;
738 case ABS_RZ
: This
->js
.lRz
= value
; break;
739 case ABS_THROTTLE
: This
->js
.rglSlider
[0] = value
; break;
740 case ABS_RUDDER
: This
->js
.rglSlider
[1] = value
; break;
741 case ABS_HAT0X
: case ABS_HAT0Y
: case ABS_HAT1X
: case ABS_HAT1Y
:
742 case ABS_HAT2X
: case ABS_HAT2Y
: case ABS_HAT3X
: case ABS_HAT3Y
:
744 int idx
= (ie
.code
- ABS_HAT0X
) / 2;
747 This
->povs
[idx
].y
= ie
.value
;
749 This
->povs
[idx
].x
= ie
.value
;
751 This
->js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
755 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie
.code
,ie
.value
);
759 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
761 This
->ff_state
= ie
.value
;
766 /* there is nothing to do */
770 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
774 queue_event((LPDIRECTINPUTDEVICE8A
)This
,
775 id_to_offset(&This
->base
.data_format
, inst_id
),
776 value
, ie
.time
.tv_usec
, This
->base
.dinput
->evsequence
++);
780 /******************************************************************************
781 * GetDeviceState : returns the "state" of the joystick.
784 static HRESULT WINAPI
JoystickAImpl_GetDeviceState(
785 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
787 JoystickImpl
*This
= (JoystickImpl
*)iface
;
789 TRACE("(this=%p,0x%08x,%p)\n", This
, len
, ptr
);
791 if (!This
->base
.acquired
)
793 WARN("not acquired\n");
794 return DIERR_NOTACQUIRED
;
799 /* convert and copy data to user supplied buffer */
800 fill_DataFormat(ptr
, &This
->js
, &This
->base
.data_format
);
805 /******************************************************************************
806 * SetProperty : change input device properties
808 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
812 JoystickImpl
*This
= (JoystickImpl
*)iface
;
815 WARN("invalid argument\n");
816 return DIERR_INVALIDPARAM
;
819 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
820 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
821 ph
->dwSize
, ph
->dwHeaderSize
, ph
->dwObj
, ph
->dwHow
);
823 if (!HIWORD(rguid
)) {
824 switch (LOWORD(rguid
)) {
825 case (DWORD
)DIPROP_RANGE
: {
826 LPCDIPROPRANGE pr
= (LPCDIPROPRANGE
)ph
;
828 if (ph
->dwHow
== DIPH_DEVICE
) {
830 TRACE("proprange(%d,%d) all\n", pr
->lMin
, pr
->lMax
);
831 for (i
= 0; i
< This
->base
.data_format
.wine_df
->dwNumObjs
; i
++) {
832 /* Scale dead-zone */
833 This
->props
[i
].lDeadZone
= MulDiv(This
->props
[i
].lDeadZone
, pr
->lMax
- pr
->lMin
,
834 This
->props
[i
].lMax
- This
->props
[i
].lMin
);
835 This
->props
[i
].lMin
= pr
->lMin
;
836 This
->props
[i
].lMax
= pr
->lMax
;
839 int obj
= find_property(&This
->base
.data_format
, ph
);
841 TRACE("proprange(%d,%d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
843 /* Scale dead-zone */
844 This
->props
[obj
].lDeadZone
= MulDiv(This
->props
[obj
].lDeadZone
, pr
->lMax
- pr
->lMin
,
845 This
->props
[obj
].lMax
- This
->props
[obj
].lMin
);
846 This
->props
[obj
].lMin
= pr
->lMin
;
847 This
->props
[obj
].lMax
= pr
->lMax
;
850 fake_current_js_state(This
);
853 case (DWORD
)DIPROP_DEADZONE
: {
854 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
855 if (ph
->dwHow
== DIPH_DEVICE
) {
857 TRACE("deadzone(%d) all\n", pd
->dwData
);
858 for (i
= 0; i
< This
->base
.data_format
.wine_df
->dwNumObjs
; i
++) {
859 This
->props
[i
].lDeadZone
= pd
->dwData
;
862 int obj
= find_property(&This
->base
.data_format
, ph
);
864 TRACE("deadzone(%d) obj=%d\n", pd
->dwData
, obj
);
866 This
->props
[obj
].lDeadZone
= pd
->dwData
;
869 fake_current_js_state(This
);
872 case (DWORD
)DIPROP_CALIBRATIONMODE
: {
873 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
874 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd
->dwData
);
877 case (DWORD
)DIPROP_AUTOCENTER
: {
878 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
880 FIXME("DIPROP_AUTOCENTER(%d)\n", pd
->dwData
);
884 return IDirectInputDevice2AImpl_SetProperty(iface
, rguid
, ph
);
890 static HRESULT WINAPI
JoystickAImpl_GetCapabilities(
891 LPDIRECTINPUTDEVICE8A iface
,
892 LPDIDEVCAPS lpDIDevCaps
)
894 JoystickImpl
*This
= (JoystickImpl
*)iface
;
896 TRACE("%p->(%p)\n",iface
,lpDIDevCaps
);
899 WARN("invalid pointer\n");
903 if (lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS
)) {
904 WARN("invalid argument\n");
905 return DIERR_INVALIDPARAM
;
908 lpDIDevCaps
->dwFlags
= DIDC_ATTACHED
;
909 if (This
->base
.dinput
->dwVersion
>= 0x0800)
910 lpDIDevCaps
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
912 lpDIDevCaps
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
914 if (This
->joydev
->has_ff
)
915 lpDIDevCaps
->dwFlags
|= DIDC_FORCEFEEDBACK
;
917 lpDIDevCaps
->dwAxes
= This
->numAxes
;
918 lpDIDevCaps
->dwButtons
= This
->numButtons
;
919 lpDIDevCaps
->dwPOVs
= This
->numPOVs
;
924 static HRESULT WINAPI
JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface
)
926 JoystickImpl
*This
= (JoystickImpl
*)iface
;
928 TRACE("(%p)\n",This
);
930 if (!This
->base
.acquired
)
931 return DIERR_NOTACQUIRED
;
937 /******************************************************************************
938 * GetProperty : get input device properties
940 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
942 LPDIPROPHEADER pdiph
)
944 JoystickImpl
*This
= (JoystickImpl
*)iface
;
946 TRACE("(this=%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
947 _dump_DIPROPHEADER(pdiph
);
949 if (HIWORD(rguid
)) return DI_OK
;
951 switch (LOWORD(rguid
)) {
952 case (DWORD
) DIPROP_RANGE
:
954 LPDIPROPRANGE pr
= (LPDIPROPRANGE
) pdiph
;
955 int obj
= find_property(&This
->base
.data_format
, pdiph
);
957 if (obj
< 0) return DIERR_OBJECTNOTFOUND
;
959 pr
->lMin
= This
->props
[obj
].lMin
;
960 pr
->lMax
= This
->props
[obj
].lMax
;
961 TRACE("range(%d, %d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
964 case (DWORD
) DIPROP_DEADZONE
:
966 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
967 int obj
= find_property(&This
->base
.data_format
, pdiph
);
969 if (obj
< 0) return DIERR_OBJECTNOTFOUND
;
971 pd
->dwData
= This
->props
[obj
].lDeadZone
;
972 TRACE("deadzone(%d) obj=%d\n", pd
->dwData
, obj
);
977 return IDirectInputDevice2AImpl_GetProperty(iface
, rguid
, pdiph
);
983 /******************************************************************************
984 * GetObjectInfo : get information about a device object such as a button
987 static HRESULT WINAPI
JoystickWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface
,
988 LPDIDEVICEOBJECTINSTANCEW pdidoi
, DWORD dwObj
, DWORD dwHow
)
990 static const WCHAR axisW
[] = {'A','x','i','s',' ','%','d',0};
991 static const WCHAR povW
[] = {'P','O','V',' ','%','d',0};
992 static const WCHAR buttonW
[] = {'B','u','t','t','o','n',' ','%','d',0};
995 res
= IDirectInputDevice2WImpl_GetObjectInfo(iface
, pdidoi
, dwObj
, dwHow
);
996 if (res
!= DI_OK
) return res
;
998 if (pdidoi
->dwType
& DIDFT_AXIS
)
999 sprintfW(pdidoi
->tszName
, axisW
, DIDFT_GETINSTANCE(pdidoi
->dwType
));
1000 else if (pdidoi
->dwType
& DIDFT_POV
)
1001 sprintfW(pdidoi
->tszName
, povW
, DIDFT_GETINSTANCE(pdidoi
->dwType
));
1002 else if (pdidoi
->dwType
& DIDFT_BUTTON
)
1003 sprintfW(pdidoi
->tszName
, buttonW
, DIDFT_GETINSTANCE(pdidoi
->dwType
));
1005 _dump_OBJECTINSTANCEW(pdidoi
);
1009 static HRESULT WINAPI
JoystickAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface
,
1010 LPDIDEVICEOBJECTINSTANCEA pdidoi
, DWORD dwObj
, DWORD dwHow
)
1013 DIDEVICEOBJECTINSTANCEW didoiW
;
1014 DWORD dwSize
= pdidoi
->dwSize
;
1016 didoiW
.dwSize
= sizeof(didoiW
);
1017 res
= JoystickWImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W
)iface
, &didoiW
, dwObj
, dwHow
);
1018 if (res
!= DI_OK
) return res
;
1020 memset(pdidoi
, 0, pdidoi
->dwSize
);
1021 memcpy(pdidoi
, &didoiW
, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW
, tszName
));
1022 pdidoi
->dwSize
= dwSize
;
1023 WideCharToMultiByte(CP_ACP
, 0, didoiW
.tszName
, -1, pdidoi
->tszName
,
1024 sizeof(pdidoi
->tszName
), NULL
, NULL
);
1029 /******************************************************************************
1030 * CreateEffect - Create a new FF effect with the specified params
1032 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
,
1035 LPDIRECTINPUTEFFECT
*ppdef
,
1036 LPUNKNOWN pUnkOuter
)
1038 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1039 EffectListItem
* new = NULL
;
1040 HRESULT retval
= DI_OK
;
1043 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1044 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
1046 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1047 TRACE("not available (compiled w/o ff support)\n");
1052 new = HeapAlloc(GetProcessHeap(), 0, sizeof(EffectListItem
));
1053 new->next
= This
->top_effect
;
1054 This
->top_effect
= new;
1056 retval
= linuxinput_create_effect(&(This
->joyfd
), rguid
, &(new->ref
));
1057 if (retval
!= DI_OK
)
1061 retval
= IDirectInputEffect_SetParameters(new->ref
, lpeff
, 0);
1062 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1067 if (pUnkOuter
!= NULL
)
1068 FIXME("Interface aggregation not implemented.\n");
1072 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1075 /*******************************************************************************
1076 * EnumEffects - Enumerate available FF effects
1078 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1079 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1083 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1084 DIEFFECTINFOA dei
; /* feif */
1085 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1086 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1088 TRACE("(this=%p,%p,%d) type=%d\n", This
, pvRef
, dwEffType
, type
);
1090 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1092 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1093 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1094 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1095 (*lpCallback
)(&dei
, pvRef
);
1098 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1099 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1100 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1101 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1102 (*lpCallback
)(&dei
, pvRef
);
1104 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1105 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1106 (*lpCallback
)(&dei
, pvRef
);
1108 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1109 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1110 (*lpCallback
)(&dei
, pvRef
);
1112 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1113 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1114 (*lpCallback
)(&dei
, pvRef
);
1116 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1117 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1118 (*lpCallback
)(&dei
, pvRef
);
1122 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1123 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1124 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1125 (*lpCallback
)(&dei
, pvRef
);
1128 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1129 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1130 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1131 (*lpCallback
)(&dei
, pvRef
);
1133 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1134 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1135 (*lpCallback
)(&dei
, pvRef
);
1137 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1138 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1139 (*lpCallback
)(&dei
, pvRef
);
1141 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1142 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1143 (*lpCallback
)(&dei
, pvRef
);
1152 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1153 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1157 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1158 /* seems silly to duplicate all this code but all the structures and functions
1159 * are actually different (A/W) */
1160 DIEFFECTINFOW dei
; /* feif */
1161 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1162 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1163 int xfd
= This
->joyfd
;
1165 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1167 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1169 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1170 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1171 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1172 (*lpCallback
)(&dei
, pvRef
);
1175 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1176 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1177 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1178 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1179 (*lpCallback
)(&dei
, pvRef
);
1181 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1182 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1183 (*lpCallback
)(&dei
, pvRef
);
1185 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1186 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1187 (*lpCallback
)(&dei
, pvRef
);
1189 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1190 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1191 (*lpCallback
)(&dei
, pvRef
);
1193 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1194 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1195 (*lpCallback
)(&dei
, pvRef
);
1199 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1200 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1201 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1202 (*lpCallback
)(&dei
, pvRef
);
1205 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1206 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1207 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1208 (*lpCallback
)(&dei
, pvRef
);
1210 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1211 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1212 (*lpCallback
)(&dei
, pvRef
);
1214 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1215 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1216 (*lpCallback
)(&dei
, pvRef
);
1218 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1219 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1220 (*lpCallback
)(&dei
, pvRef
);
1224 /* return to unacquired state if that's where it was */
1226 IDirectInputDevice8_Unacquire(iface
);
1232 /*******************************************************************************
1233 * GetEffectInfo - Get information about a particular effect
1235 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1236 LPDIEFFECTINFOA pdei
,
1239 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1241 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1243 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1244 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1250 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1251 LPDIEFFECTINFOW pdei
,
1254 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1256 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1258 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1259 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1265 /*******************************************************************************
1266 * GetForceFeedbackState - Get information about the device's FF state
1268 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(
1269 LPDIRECTINPUTDEVICE8A iface
,
1272 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1274 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1278 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1279 /* DIGFFS_STOPPED is the only mandatory flag to report */
1280 if (This
->ff_state
== FF_STATUS_STOPPED
)
1281 (*pdwOut
) |= DIGFFS_STOPPED
;
1287 /*******************************************************************************
1288 * SendForceFeedbackCommand - Send a command to the device's FF system
1290 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(
1291 LPDIRECTINPUTDEVICE8A iface
,
1294 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1295 TRACE("(this=%p,%d)\n", This
, dwFlags
);
1297 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1298 if (dwFlags
== DISFFC_STOPALL
) {
1299 /* Stop all effects */
1300 EffectListItem
* itr
= This
->top_effect
;
1302 IDirectInputEffect_Stop(itr
->ref
);
1305 } else if (dwFlags
== DISFFC_RESET
) {
1306 /* Stop, unload, release and free all effects */
1307 /* This returns the device to its "bare" state */
1308 while (This
->top_effect
) {
1309 EffectListItem
* temp
= This
->top_effect
;
1310 IDirectInputEffect_Stop(temp
->ref
);
1311 IDirectInputEffect_Unload(temp
->ref
);
1312 IDirectInputEffect_Release(temp
->ref
);
1313 This
->top_effect
= temp
->next
;
1314 HeapFree(GetProcessHeap(), 0, temp
);
1316 } else if (dwFlags
== DISFFC_PAUSE
|| dwFlags
== DISFFC_CONTINUE
) {
1317 FIXME("No support for Pause or Continue in linux\n");
1318 } else if (dwFlags
== DISFFC_SETACTUATORSOFF
1319 || dwFlags
== DISFFC_SETACTUATORSON
) {
1320 FIXME("No direct actuator control in linux\n");
1322 FIXME("Unknown Force Feedback Command!\n");
1323 return DIERR_INVALIDPARAM
;
1327 return DIERR_UNSUPPORTED
;
1331 /*******************************************************************************
1332 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1333 * created for this device.
1335 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(
1336 LPDIRECTINPUTDEVICE8A iface
,
1337 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1341 /* this function is safe to call on non-ff-enabled builds */
1343 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1344 EffectListItem
* itr
= This
->top_effect
;
1345 TRACE("(this=%p,%p,%p,%d)\n", This
, lpCallback
, pvRef
, dwFlags
);
1348 return DIERR_INVALIDPARAM
;
1351 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1354 (*lpCallback
)(itr
->ref
, pvRef
);
1361 /******************************************************************************
1362 * GetDeviceInfo : get information about a device's identity
1364 static HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface
,
1365 LPDIDEVICEINSTANCEA pdidi
)
1367 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1369 TRACE("(%p) %p\n", This
, pdidi
);
1371 if (pdidi
== NULL
) return E_POINTER
;
1372 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1373 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)))
1374 return DIERR_INVALIDPARAM
;
1376 fill_joystick_dideviceinstanceA(pdidi
, This
->base
.dinput
->dwVersion
,
1377 get_joystick_index(&This
->base
.guid
));
1381 static HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
,
1382 LPDIDEVICEINSTANCEW pdidi
)
1384 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1386 TRACE("(%p) %p\n", This
, pdidi
);
1388 if (pdidi
== NULL
) return E_POINTER
;
1389 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1390 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)))
1391 return DIERR_INVALIDPARAM
;
1393 fill_joystick_dideviceinstanceW(pdidi
, This
->base
.dinput
->dwVersion
,
1394 get_joystick_index(&This
->base
.guid
));
1398 static const IDirectInputDevice8AVtbl JoystickAvt
=
1400 IDirectInputDevice2AImpl_QueryInterface
,
1401 IDirectInputDevice2AImpl_AddRef
,
1402 IDirectInputDevice2AImpl_Release
,
1403 JoystickAImpl_GetCapabilities
,
1404 IDirectInputDevice2AImpl_EnumObjects
,
1405 JoystickAImpl_GetProperty
,
1406 JoystickAImpl_SetProperty
,
1407 JoystickAImpl_Acquire
,
1408 JoystickAImpl_Unacquire
,
1409 JoystickAImpl_GetDeviceState
,
1410 IDirectInputDevice2AImpl_GetDeviceData
,
1411 IDirectInputDevice2AImpl_SetDataFormat
,
1412 IDirectInputDevice2AImpl_SetEventNotification
,
1413 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1414 JoystickAImpl_GetObjectInfo
,
1415 JoystickAImpl_GetDeviceInfo
,
1416 IDirectInputDevice2AImpl_RunControlPanel
,
1417 IDirectInputDevice2AImpl_Initialize
,
1418 JoystickAImpl_CreateEffect
,
1419 JoystickAImpl_EnumEffects
,
1420 JoystickAImpl_GetEffectInfo
,
1421 JoystickAImpl_GetForceFeedbackState
,
1422 JoystickAImpl_SendForceFeedbackCommand
,
1423 JoystickAImpl_EnumCreatedEffectObjects
,
1424 IDirectInputDevice2AImpl_Escape
,
1426 IDirectInputDevice2AImpl_SendDeviceData
,
1427 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1428 IDirectInputDevice7AImpl_WriteEffectToFile
,
1429 IDirectInputDevice8AImpl_BuildActionMap
,
1430 IDirectInputDevice8AImpl_SetActionMap
,
1431 IDirectInputDevice8AImpl_GetImageInfo
1434 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1435 # define XCAST(fun) (typeof(JoystickWvt.fun))
1437 # define XCAST(fun) (void*)
1440 static const IDirectInputDevice8WVtbl JoystickWvt
=
1442 IDirectInputDevice2WImpl_QueryInterface
,
1443 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
1444 XCAST(Release
)IDirectInputDevice2AImpl_Release
,
1445 XCAST(GetCapabilities
)JoystickAImpl_GetCapabilities
,
1446 IDirectInputDevice2WImpl_EnumObjects
,
1447 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1448 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1449 XCAST(Acquire
)JoystickAImpl_Acquire
,
1450 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1451 XCAST(GetDeviceState
)JoystickAImpl_GetDeviceState
,
1452 XCAST(GetDeviceData
)IDirectInputDevice2AImpl_GetDeviceData
,
1453 XCAST(SetDataFormat
)IDirectInputDevice2AImpl_SetDataFormat
,
1454 XCAST(SetEventNotification
)IDirectInputDevice2AImpl_SetEventNotification
,
1455 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
1456 JoystickWImpl_GetObjectInfo
,
1457 JoystickWImpl_GetDeviceInfo
,
1458 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
1459 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
1460 XCAST(CreateEffect
)JoystickAImpl_CreateEffect
,
1461 JoystickWImpl_EnumEffects
,
1462 JoystickWImpl_GetEffectInfo
,
1463 XCAST(GetForceFeedbackState
)JoystickAImpl_GetForceFeedbackState
,
1464 XCAST(SendForceFeedbackCommand
)JoystickAImpl_SendForceFeedbackCommand
,
1465 XCAST(EnumCreatedEffectObjects
)JoystickAImpl_EnumCreatedEffectObjects
,
1466 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1467 XCAST(Poll
)JoystickAImpl_Poll
,
1468 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1469 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1470 IDirectInputDevice7WImpl_WriteEffectToFile
,
1471 IDirectInputDevice8WImpl_BuildActionMap
,
1472 IDirectInputDevice8WImpl_SetActionMap
,
1473 IDirectInputDevice8WImpl_GetImageInfo
1477 #else /* HAVE_CORRECT_LINUXINPUT_H */
1479 const struct dinput_device joystick_linuxinput_device
= {
1480 "Wine Linux-input joystick driver",
1487 #endif /* HAVE_CORRECT_LINUXINPUT_H */