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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
52 #include "wine/debug.h"
53 #include "wine/unicode.h"
59 #include "dinput_private.h"
60 #include "device_private.h"
62 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
64 #ifdef HAVE_CORRECT_LINUXINPUT_H
66 #define EVDEVPREFIX "/dev/input/event"
68 /* Wine joystick driver object instances */
69 #define WINE_JOYSTICK_AXIS_BASE 0
70 #define WINE_JOYSTICK_BUTTON_BASE 8
72 typedef struct EffectListItem EffectListItem
;
75 LPDIRECTINPUTEFFECT ref
;
76 struct EffectListItem
* next
;
79 /* implemented in effect_linuxinput.c */
80 HRESULT
linuxinput_create_effect(int* fd
, REFGUID rguid
, LPDIRECTINPUTEFFECT
* peff
);
81 HRESULT
linuxinput_get_info_A(int fd
, REFGUID rguid
, LPDIEFFECTINFOA info
);
82 HRESULT
linuxinput_get_info_W(int fd
, REFGUID rguid
, LPDIEFFECTINFOW info
);
84 typedef struct JoystickImpl JoystickImpl
;
85 static const IDirectInputDevice8AVtbl JoystickAvt
;
86 static const IDirectInputDevice8WVtbl JoystickWvt
;
94 /* The 'parent' DInput */
95 IDirectInputImpl
*dinput
;
97 /* joystick private */
98 /* what range and deadzone the game wants */
99 LONG wantmin
[ABS_MAX
];
100 LONG wantmax
[ABS_MAX
];
103 /* autodetecting ranges per axe by following movement */
104 LONG havemax
[ABS_MAX
];
105 LONG havemin
[ABS_MAX
];
111 LPDIDEVICEOBJECTDATA data_queue
;
112 int queue_head
, queue_tail
, queue_len
;
116 /* Force feedback variables */
119 EffectListItem
* top_effect
;
122 /* data returned by the EVIOCGABS() ioctl */
123 int axes
[ABS_MAX
+1][5];
128 #define AXE_ABSFUZZ 3
129 #define AXE_ABSFLAT 4
132 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
133 BYTE evbits
[(EV_MAX
+7)/8];
134 BYTE absbits
[(ABS_MAX
+7)/8];
135 BYTE keybits
[(KEY_MAX
+7)/8];
136 BYTE ffbits
[(FF_MAX
+7)/8];
139 /* This GUID is slightly different from the linux joystick one. Take note. */
140 static GUID DInput_Wine_Joystick_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
144 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
147 static void fake_current_js_state(JoystickImpl
*ji
);
149 #define test_bit(arr,bit) (((BYTE*)arr)[bit>>3]&(1<<(bit&7)))
151 static int joydev_have(BOOL require_ff
)
153 int i
, fd
, flags
, num_effects
;
158 BYTE absbits
[(ABS_MAX
+7)/8],keybits
[(KEY_MAX
+7)/8];
159 BYTE evbits
[(EV_MAX
+7)/8],ffbits
[(FF_MAX
+7)/8];
161 sprintf(buf
,EVDEVPREFIX
"%d",i
);
168 if (-1!=(fd
=open(buf
,flags
))) {
169 if (-1==ioctl(fd
,EVIOCGBIT(EV_ABS
,sizeof(absbits
)),absbits
)) {
170 perror("EVIOCGBIT EV_ABS");
174 if (-1==ioctl(fd
,EVIOCGBIT(EV_KEY
,sizeof(keybits
)),keybits
)) {
175 perror("EVIOCGBIT EV_KEY");
180 /* test for force feedback if it's required */
182 if ((-1==ioctl(fd
,EVIOCGBIT(0,sizeof(evbits
)),evbits
))) {
183 perror("EVIOCGBIT 0");
187 if ( (!test_bit(evbits
,EV_FF
))
188 || (-1==ioctl(fd
,EVIOCGBIT(EV_FF
,sizeof(ffbits
)),ffbits
))
189 || (-1==ioctl(fd
,EVIOCGEFFECTS
,&num_effects
))
190 || (num_effects
<= 0)) {
196 /* A true joystick has at least axis X and Y, and at least 1
197 * button. copied from linux/drivers/input/joydev.c */
198 if (test_bit(absbits
,ABS_X
) && test_bit(absbits
,ABS_Y
) &&
199 ( test_bit(keybits
,BTN_TRIGGER
) ||
200 test_bit(keybits
,BTN_A
) ||
201 test_bit(keybits
,BTN_1
)
204 FIXME("found a joystick at %s!\n",buf
);
209 if (havejoy
|| (errno
==ENODEV
))
215 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
222 if (!((dwDevType
== 0) ||
223 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
< 0x0800)) ||
224 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
227 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
228 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
232 havejoy
= joydev_have(dwFlags
& DIEDFL_FORCEFEEDBACK
);
237 TRACE("Enumerating the linuxinput Joystick device\n");
239 /* Return joystick */
240 lpddi
->guidInstance
= GUID_Joystick
;
241 lpddi
->guidProduct
= DInput_Wine_Joystick_GUID
;
243 lpddi
->guidFFDriver
= GUID_NULL
;
244 if (version
>= 0x0800)
245 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
247 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
249 strcpy(lpddi
->tszInstanceName
, "Joystick");
250 /* ioctl JSIOCGNAME(len) */
251 strcpy(lpddi
->tszProductName
, "Wine Joystick");
255 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
262 if (!((dwDevType
== 0) ||
263 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
< 0x0800)) ||
264 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
267 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
268 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
272 havejoy
= joydev_have(dwFlags
& DIEDFL_FORCEFEEDBACK
);
277 TRACE("Enumerating the linuxinput Joystick device\n");
279 /* Return joystick */
280 lpddi
->guidInstance
= GUID_Joystick
;
281 lpddi
->guidProduct
= DInput_Wine_Joystick_GUID
;
283 lpddi
->guidFFDriver
= GUID_NULL
;
284 if (version
>= 0x0800)
285 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
287 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
289 MultiByteToWideChar(CP_ACP
, 0, "Joystick", -1, lpddi
->tszInstanceName
, MAX_PATH
);
290 /* ioctl JSIOCGNAME(len) */
291 MultiByteToWideChar(CP_ACP
, 0, "Wine Joystick", -1, lpddi
->tszProductName
, MAX_PATH
);
295 static JoystickImpl
*alloc_device(REFGUID rguid
, const void *jvt
, IDirectInputImpl
*dinput
)
297 JoystickImpl
* newDevice
;
300 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(JoystickImpl
));
301 newDevice
->lpVtbl
= jvt
;
303 newDevice
->joyfd
= -1;
304 newDevice
->dinput
= dinput
;
305 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
306 newDevice
->ff_state
= FF_STATUS_STOPPED
;
308 memcpy(&(newDevice
->guid
),rguid
,sizeof(*rguid
));
309 for (i
=0;i
<ABS_MAX
;i
++) {
310 newDevice
->wantmin
[i
] = -32768;
311 newDevice
->wantmax
[i
] = 32767;
313 * direct input defines a default for the deadzone somewhere; but as long
314 * as in map_axis the code for the dead zone is commented out its no
317 newDevice
->deadz
[i
] = 0;
319 fake_current_js_state(newDevice
);
323 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
327 havejoy
= joydev_have(FALSE
);
330 return DIERR_DEVICENOTREG
;
332 if ((IsEqualGUID(&GUID_Joystick
,rguid
)) ||
333 (IsEqualGUID(&DInput_Wine_Joystick_GUID
,rguid
))) {
334 if ((riid
== NULL
) ||
335 IsEqualGUID(&IID_IDirectInputDeviceA
,riid
) ||
336 IsEqualGUID(&IID_IDirectInputDevice2A
,riid
) ||
337 IsEqualGUID(&IID_IDirectInputDevice7A
,riid
) ||
338 IsEqualGUID(&IID_IDirectInputDevice8A
,riid
)) {
339 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &JoystickAvt
, dinput
);
340 TRACE("Creating a Joystick device (%p)\n", *pdev
);
343 return DIERR_NOINTERFACE
;
346 return DIERR_DEVICENOTREG
;
350 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
354 havejoy
= joydev_have(FALSE
);
357 return DIERR_DEVICENOTREG
;
359 if ((IsEqualGUID(&GUID_Joystick
,rguid
)) ||
360 (IsEqualGUID(&DInput_Wine_Joystick_GUID
,rguid
))) {
361 if ((riid
== NULL
) ||
362 IsEqualGUID(&IID_IDirectInputDeviceW
,riid
) ||
363 IsEqualGUID(&IID_IDirectInputDevice2W
,riid
) ||
364 IsEqualGUID(&IID_IDirectInputDevice7W
,riid
) ||
365 IsEqualGUID(&IID_IDirectInputDevice8W
,riid
)) {
366 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &JoystickWvt
, dinput
);
367 TRACE("Creating a Joystick device (%p)\n", *pdev
);
370 return DIERR_NOINTERFACE
;
373 return DIERR_DEVICENOTREG
;
376 const struct dinput_device joystick_linuxinput_device
= {
377 "Wine Linux-input joystick driver",
380 joydev_create_deviceA
,
381 joydev_create_deviceW
384 /******************************************************************************
387 static ULONG WINAPI
JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface
)
389 JoystickImpl
*This
= (JoystickImpl
*)iface
;
392 ref
= InterlockedDecrement(&(This
->ref
));
396 /* Reset the FF state, free all effects, etc */
397 iface
->lpVtbl
->SendForceFeedbackCommand(iface
, DISFFC_RESET
);
399 /* Free the data queue */
400 HeapFree(GetProcessHeap(),0,This
->data_queue
);
402 /* Free the DataFormat */
403 HeapFree(GetProcessHeap(), 0, This
->df
);
405 HeapFree(GetProcessHeap(),0,This
);
409 /******************************************************************************
410 * SetDataFormat : the application can choose the format of the data
411 * the device driver sends back with GetDeviceState.
413 static HRESULT WINAPI
JoystickAImpl_SetDataFormat(
414 LPDIRECTINPUTDEVICE8A iface
,LPCDIDATAFORMAT df
417 JoystickImpl
*This
= (JoystickImpl
*)iface
;
419 TRACE("(this=%p,%p)\n",This
,df
);
421 _dump_DIDATAFORMAT(df
);
423 /* Store the new data format */
424 This
->df
= HeapAlloc(GetProcessHeap(),0,df
->dwSize
);
425 memcpy(This
->df
, df
, df
->dwSize
);
426 This
->df
->rgodf
= HeapAlloc(GetProcessHeap(),0,df
->dwNumObjs
*df
->dwObjSize
);
427 memcpy(This
->df
->rgodf
,df
->rgodf
,df
->dwNumObjs
*df
->dwObjSize
);
432 /******************************************************************************
433 * Acquire : gets exclusive control of the joystick
435 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
438 JoystickImpl
*This
= (JoystickImpl
*)iface
;
440 BOOL readonly
= TRUE
;
442 TRACE("(this=%p)\n",This
);
446 sprintf(buf
,EVDEVPREFIX
"%d",i
);
447 if (-1==(This
->joyfd
=open(buf
,O_RDWR
))) {
448 if (-1==(This
->joyfd
=open(buf
,O_RDONLY
))) {
449 /* Couldn't open the device at all */
451 return DIERR_NOTFOUND
;
456 /* Couldn't open in r/w but opened in read-only. */
457 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n",buf
);
461 /* Opened device in read-write */
464 if ((-1!=ioctl(This
->joyfd
,EVIOCGBIT(0,sizeof(This
->evbits
)),This
->evbits
)) &&
465 (-1!=ioctl(This
->joyfd
,EVIOCGBIT(EV_ABS
,sizeof(This
->absbits
)),This
->absbits
)) &&
466 (-1!=ioctl(This
->joyfd
,EVIOCGBIT(EV_KEY
,sizeof(This
->keybits
)),This
->keybits
)) &&
467 (test_bit(This
->absbits
,ABS_X
) && test_bit(This
->absbits
,ABS_Y
) &&
468 (test_bit(This
->keybits
,BTN_TRIGGER
)||
469 test_bit(This
->keybits
,BTN_A
) ||
470 test_bit(This
->keybits
,BTN_1
)
479 return DIERR_NOTFOUND
;
481 This
->has_ff
= FALSE
;
482 This
->num_effects
= 0;
484 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
485 if (!readonly
&& test_bit(This
->evbits
, EV_FF
)) {
486 if (-1!=ioctl(This
->joyfd
,EVIOCGBIT(EV_FF
,sizeof(This
->ffbits
)),This
->ffbits
)) {
487 if (-1!=ioctl(This
->joyfd
,EVIOCGEFFECTS
,&This
->num_effects
)
488 && This
->num_effects
> 0) {
490 TRACE("Joystick seems to be capable of force feedback.\n");
493 TRACE("Joystick does not support any effects, disabling force feedback.\n");
497 TRACE("Could not get EV_FF bits; disabling force feedback.\n");
501 TRACE("Force feedback disabled (device is readonly or joystick incapable).\n");
505 for (i
=0;i
<ABS_MAX
;i
++) {
506 if (test_bit(This
->absbits
,i
)) {
507 if (-1==ioctl(This
->joyfd
,EVIOCGABS(i
),&(This
->axes
[i
])))
509 FIXME("axe %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
511 This
->axes
[i
][AXE_ABS
],
512 This
->axes
[i
][AXE_ABSMIN
],
513 This
->axes
[i
][AXE_ABSMAX
],
514 This
->axes
[i
][AXE_ABSFUZZ
],
515 This
->axes
[i
][AXE_ABSFLAT
]
517 This
->havemin
[i
] = This
->axes
[i
][AXE_ABSMIN
];
518 This
->havemax
[i
] = This
->axes
[i
][AXE_ABSMAX
];
523 fake_current_js_state(This
);
528 /******************************************************************************
529 * Unacquire : frees the joystick
531 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
533 JoystickImpl
*This
= (JoystickImpl
*)iface
;
535 TRACE("(this=%p)\n",This
);
536 if (This
->joyfd
!=-1) {
546 * This maps the read value (from the input event) to a value in the
547 * 'wanted' range. It also autodetects the possible range of the axe and
548 * adapts values accordingly.
551 map_axis(JoystickImpl
* This
, int axis
, int val
) {
552 int xmin
= This
->axes
[axis
][AXE_ABSMIN
];
553 int xmax
= This
->axes
[axis
][AXE_ABSMAX
];
554 int hmax
= This
->havemax
[axis
];
555 int hmin
= This
->havemin
[axis
];
556 int wmin
= This
->wantmin
[axis
];
557 int wmax
= This
->wantmax
[axis
];
560 if (val
> hmax
) This
->havemax
[axis
] = hmax
= val
;
561 if (val
< hmin
) This
->havemin
[axis
] = hmin
= val
;
563 if (xmin
== xmax
) return val
;
565 /* map the value from the hmin-hmax range into the wmin-wmax range */
566 ret
= ((val
-hmin
) * (wmax
-wmin
)) / (hmax
-hmin
) + wmin
;
568 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
);
571 /* deadzone doesn't work comfortably enough right now. needs more testing*/
572 if ((ret
> -deadz
/2 ) && (ret
< deadz
/2)) {
573 FIXME("%d in deadzone, return mid.\n",val
);
574 return (wmax
-wmin
)/2+wmin
;
581 * set the current state of the js device as it would be with the middle
584 static void fake_current_js_state(JoystickImpl
*ji
)
586 ji
->js
.lX
= map_axis(ji
, ABS_X
, ji
->axes
[ABS_X
][AXE_ABS
]);
587 ji
->js
.lY
= map_axis(ji
, ABS_Y
, ji
->axes
[ABS_Y
][AXE_ABS
]);
588 ji
->js
.lZ
= map_axis(ji
, ABS_Z
, ji
->axes
[ABS_Z
][AXE_ABS
]);
589 ji
->js
.lRx
= map_axis(ji
, ABS_RX
, ji
->axes
[ABS_RX
][AXE_ABS
]);
590 ji
->js
.lRy
= map_axis(ji
, ABS_RY
, ji
->axes
[ABS_RY
][AXE_ABS
]);
591 ji
->js
.lRz
= map_axis(ji
, ABS_RZ
, ji
->axes
[ABS_RZ
][AXE_ABS
]);
592 ji
->js
.rglSlider
[0] = map_axis(ji
, ABS_THROTTLE
, ji
->axes
[ABS_THROTTLE
][AXE_ABS
]);
593 ji
->js
.rglSlider
[1] = map_axis(ji
, ABS_RUDDER
, ji
->axes
[ABS_RUDDER
][AXE_ABS
]);
596 static void joy_polldev(JoystickImpl
*This
) {
599 struct input_event ie
;
605 memset(&tv
,0,sizeof(tv
));
607 FD_SET(This
->joyfd
,&readfds
);
609 if (1>select(This
->joyfd
+1,&readfds
,NULL
,NULL
,&tv
))
612 /* we have one event, so we can read */
613 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
616 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
618 case EV_KEY
: /* button */
620 case BTN_TRIGGER
: /* normal flight stick */
621 case BTN_A
: /* gamepad */
622 case BTN_1
: /* generic */
623 This
->js
.rgbButtons
[0] = ie
.value
?0x80:0x00;
624 GEN_EVENT(DIJOFS_BUTTON(0),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
629 This
->js
.rgbButtons
[1] = ie
.value
?0x80:0x00;
630 GEN_EVENT(DIJOFS_BUTTON(1),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
635 This
->js
.rgbButtons
[2] = ie
.value
?0x80:0x00;
636 GEN_EVENT(DIJOFS_BUTTON(2),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
641 This
->js
.rgbButtons
[3] = ie
.value
?0x80:0x00;
642 GEN_EVENT(DIJOFS_BUTTON(3),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
647 This
->js
.rgbButtons
[4] = ie
.value
?0x80:0x00;
648 GEN_EVENT(DIJOFS_BUTTON(4),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
653 This
->js
.rgbButtons
[5] = ie
.value
?0x80:0x00;
654 GEN_EVENT(DIJOFS_BUTTON(5),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
659 This
->js
.rgbButtons
[6] = ie
.value
?0x80:0x00;
660 GEN_EVENT(DIJOFS_BUTTON(6),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
665 This
->js
.rgbButtons
[7] = ie
.value
?0x80:0x00;
666 GEN_EVENT(DIJOFS_BUTTON(7),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
671 This
->js
.rgbButtons
[8] = ie
.value
?0x80:0x00;
672 GEN_EVENT(DIJOFS_BUTTON(8),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
676 This
->js
.rgbButtons
[9] = ie
.value
?0x80:0x00;
677 GEN_EVENT(DIJOFS_BUTTON(9),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
681 This
->js
.rgbButtons
[10] = ie
.value
?0x80:0x00;
682 GEN_EVENT(DIJOFS_BUTTON(10),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
685 FIXME("unhandled joystick button %x, value %d\n",ie
.code
,ie
.value
);
692 This
->js
.lX
= map_axis(This
,ABS_X
,ie
.value
);
693 GEN_EVENT(DIJOFS_X
,This
->js
.lX
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
696 This
->js
.lY
= map_axis(This
,ABS_Y
,ie
.value
);
697 GEN_EVENT(DIJOFS_Y
,This
->js
.lY
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
700 This
->js
.lZ
= map_axis(This
,ABS_Z
,ie
.value
);
701 GEN_EVENT(DIJOFS_Z
,This
->js
.lZ
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
704 This
->js
.lRx
= map_axis(This
,ABS_RX
,ie
.value
);
705 GEN_EVENT(DIJOFS_RX
,This
->js
.lRx
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
708 This
->js
.lRy
= map_axis(This
,ABS_RY
,ie
.value
);
709 GEN_EVENT(DIJOFS_RY
,This
->js
.lRy
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
712 This
->js
.lRz
= map_axis(This
,ABS_RZ
,ie
.value
);
713 GEN_EVENT(DIJOFS_RZ
,This
->js
.lRz
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
716 This
->js
.rglSlider
[0] = map_axis(This
,ABS_THROTTLE
,ie
.value
);
717 GEN_EVENT(DIJOFS_SLIDER(0),This
->js
.rglSlider
[0],ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
720 This
->js
.rglSlider
[1] = map_axis(This
,ABS_RUDDER
,ie
.value
);
721 GEN_EVENT(DIJOFS_SLIDER(1),This
->js
.rglSlider
[1],ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
724 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie
.code
,ie
.value
);
728 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
730 This
->ff_state
= ie
.value
;
734 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
740 /******************************************************************************
741 * GetDeviceState : returns the "state" of the joystick.
744 static HRESULT WINAPI
JoystickAImpl_GetDeviceState(
745 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
747 JoystickImpl
*This
= (JoystickImpl
*)iface
;
751 TRACE("(this=%p,0x%08lx,%p)\n",This
,len
,ptr
);
752 if ((len
!= sizeof(DIJOYSTATE
)) && (len
!= sizeof(DIJOYSTATE2
))) {
753 FIXME("len %ld is not sizeof(DIJOYSTATE) or DIJOYSTATE2, unsupported format.\n",len
);
756 memcpy(ptr
,&(This
->js
),len
);
757 This
->queue_head
= 0;
758 This
->queue_tail
= 0;
762 /******************************************************************************
763 * GetDeviceData : gets buffered input data.
765 static HRESULT WINAPI
JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface
,
767 LPDIDEVICEOBJECTDATA dod
,
771 JoystickImpl
*This
= (JoystickImpl
*)iface
;
773 FIXME("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx),STUB!\n",This
,dodsize
,*entries
,flags
);
776 if (flags
& DIGDD_PEEK
)
777 FIXME("DIGDD_PEEK\n");
785 /******************************************************************************
786 * SetProperty : change input device properties
788 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
792 JoystickImpl
*This
= (JoystickImpl
*)iface
;
794 FIXME("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
795 FIXME("ph.dwSize = %ld, ph.dwHeaderSize =%ld, ph.dwObj = %ld, ph.dwHow= %ld\n",ph
->dwSize
, ph
->dwHeaderSize
,ph
->dwObj
,ph
->dwHow
);
797 if (!HIWORD(rguid
)) {
798 switch ((DWORD
)rguid
) {
799 case (DWORD
) DIPROP_BUFFERSIZE
: {
800 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
802 FIXME("buffersize = %ld\n",pd
->dwData
);
805 case (DWORD
)DIPROP_RANGE
: {
806 LPCDIPROPRANGE pr
= (LPCDIPROPRANGE
)ph
;
808 FIXME("proprange(%ld,%ld)\n",pr
->lMin
,pr
->lMax
);
816 case 24: /* Slider 0 -> Throttle */
817 case 28: /* Slider 1 -> Rudder */
818 This
->wantmin
[ph
->dwObj
/4] = pr
->lMin
;
819 This
->wantmax
[ph
->dwObj
/4] = pr
->lMax
;
822 FIXME("setting proprange %ld - %ld for dwObj %ld\n",pr
->lMin
,pr
->lMax
,ph
->dwObj
);
826 case (DWORD
)DIPROP_DEADZONE
: {
827 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
829 FIXME("setting deadzone(%ld)\n",pd
->dwData
);
830 This
->deadz
[ph
->dwObj
/4] = pd
->dwData
;
834 FIXME("Unknown type %ld (%s)\n",(DWORD
)rguid
,debugstr_guid(rguid
));
838 fake_current_js_state(This
);
842 /******************************************************************************
843 * SetEventNotification : specifies event to be sent on state change
845 static HRESULT WINAPI
JoystickAImpl_SetEventNotification(
846 LPDIRECTINPUTDEVICE8A iface
, HANDLE hnd
848 JoystickImpl
*This
= (JoystickImpl
*)iface
;
850 TRACE("(this=%p,0x%08lx)\n",This
,(DWORD
)hnd
);
855 static HRESULT WINAPI
JoystickAImpl_GetCapabilities(
856 LPDIRECTINPUTDEVICE8A iface
,
857 LPDIDEVCAPS lpDIDevCaps
)
859 JoystickImpl
*This
= (JoystickImpl
*)iface
;
860 int xfd
= This
->joyfd
;
864 TRACE("%p->(%p)\n",iface
,lpDIDevCaps
);
866 /* yes, games assume we return something, even if unacquired */
867 JoystickAImpl_Acquire(iface
);
871 lpDIDevCaps
->dwFlags
= DIDC_ATTACHED
;
872 if (This
->dinput
->dwVersion
>= 0x0800)
873 lpDIDevCaps
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
875 lpDIDevCaps
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
878 for (i
=0;i
<ABS_MAX
;i
++) if (test_bit(This
->absbits
,i
)) axes
++;
880 for (i
=0;i
<KEY_MAX
;i
++) if (test_bit(This
->keybits
,i
)) buttons
++;
883 lpDIDevCaps
->dwFlags
|= DIDC_FORCEFEEDBACK
;
885 lpDIDevCaps
->dwAxes
= axes
;
886 lpDIDevCaps
->dwButtons
= buttons
;
889 JoystickAImpl_Unacquire(iface
);
894 static HRESULT WINAPI
JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface
) {
895 JoystickImpl
*This
= (JoystickImpl
*)iface
;
902 /******************************************************************************
903 * EnumObjects : enumerate the different buttons and axis...
905 static HRESULT WINAPI
JoystickAImpl_EnumObjects(
906 LPDIRECTINPUTDEVICE8A iface
,
907 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback
,
911 JoystickImpl
*This
= (JoystickImpl
*)iface
;
912 DIDEVICEOBJECTINSTANCEA ddoi
;
913 int xfd
= This
->joyfd
;
915 TRACE("(this=%p,%p,%p,%08lx)\n", This
, lpCallback
, lpvRef
, dwFlags
);
916 if (TRACE_ON(dinput
)) {
917 TRACE(" - flags = ");
918 _dump_EnumObjects_flags(dwFlags
);
922 /* We need to work even if we're not yet acquired */
924 iface
->lpVtbl
->Acquire(iface
);
926 /* Only the fields till dwFFMaxForce are relevant */
927 ddoi
.dwSize
= FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA
, dwFFMaxForce
);
929 /* For the joystick, do as is done in the GetCapabilities function */
930 /* FIXME: needs more items */
931 if ((dwFlags
== DIDFT_ALL
) ||
932 (dwFlags
& DIDFT_AXIS
)) {
935 for (i
= 0; i
< ABS_MAX
; i
++) {
936 if (!test_bit(This
->absbits
,i
)) continue;
940 ddoi
.guidType
= GUID_XAxis
;
941 ddoi
.dwOfs
= DIJOFS_X
;
944 ddoi
.guidType
= GUID_YAxis
;
945 ddoi
.dwOfs
= DIJOFS_Y
;
948 ddoi
.guidType
= GUID_ZAxis
;
949 ddoi
.dwOfs
= DIJOFS_Z
;
952 ddoi
.guidType
= GUID_RxAxis
;
953 ddoi
.dwOfs
= DIJOFS_RX
;
956 ddoi
.guidType
= GUID_RyAxis
;
957 ddoi
.dwOfs
= DIJOFS_RY
;
960 ddoi
.guidType
= GUID_RzAxis
;
961 ddoi
.dwOfs
= DIJOFS_RZ
;
964 ddoi
.guidType
= GUID_Slider
;
965 ddoi
.dwOfs
= DIJOFS_SLIDER(0);
968 ddoi
.guidType
= GUID_Slider
;
969 ddoi
.dwOfs
= DIJOFS_SLIDER(1);
972 FIXME("unhandled abs axis %d, ignoring!\n",i
);
974 ddoi
.dwType
= DIDFT_MAKEINSTANCE((1<<i
) << WINE_JOYSTICK_AXIS_BASE
) | DIDFT_ABSAXIS
;
975 /* Linux event force feedback supports only (and always) x and y axes */
976 if (i
== ABS_X
|| i
== ABS_Y
) {
978 ddoi
.dwFlags
|= DIDOI_FFACTUATOR
;
980 sprintf(ddoi
.tszName
, "%d-Axis", i
);
981 _dump_OBJECTINSTANCEA(&ddoi
);
982 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) {
983 /* return to unaquired state if that's where we were */
985 iface
->lpVtbl
->Unacquire(iface
);
991 if ((dwFlags
== DIDFT_ALL
) ||
992 (dwFlags
& DIDFT_BUTTON
)) {
995 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
997 ddoi
.guidType
= GUID_Button
;
999 for (i
= 0; i
< KEY_MAX
; i
++) {
1000 if (!test_bit(This
->keybits
,i
)) continue;
1006 ddoi
.dwOfs
= DIJOFS_BUTTON(0);
1007 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 0) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
1012 ddoi
.dwOfs
= DIJOFS_BUTTON(1);
1013 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 1) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
1018 ddoi
.dwOfs
= DIJOFS_BUTTON(2);
1019 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 2) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
1024 ddoi
.dwOfs
= DIJOFS_BUTTON(3);
1025 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 3) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
1030 ddoi
.dwOfs
= DIJOFS_BUTTON(4);
1031 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 4) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
1036 ddoi
.dwOfs
= DIJOFS_BUTTON(5);
1037 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 5) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
1042 ddoi
.dwOfs
= DIJOFS_BUTTON(6);
1043 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 6) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
1048 ddoi
.dwOfs
= DIJOFS_BUTTON(7);
1049 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 7) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
1054 ddoi
.dwOfs
= DIJOFS_BUTTON(8);
1055 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 8) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
1059 ddoi
.dwOfs
= DIJOFS_BUTTON(9);
1060 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 9) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
1064 ddoi
.dwOfs
= DIJOFS_BUTTON(10);
1065 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 10) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
1068 sprintf(ddoi
.tszName
, "%d-Button", i
);
1069 _dump_OBJECTINSTANCEA(&ddoi
);
1070 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) {
1071 /* return to unaquired state if that's where we were */
1073 iface
->lpVtbl
->Unacquire(iface
);
1079 /* return to unaquired state if that's where we were */
1081 iface
->lpVtbl
->Unacquire(iface
);
1086 static HRESULT WINAPI
JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface
,
1087 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback
,
1091 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1093 device_enumobjects_AtoWcb_data data
;
1095 data
.lpCallBack
= lpCallback
;
1096 data
.lpvRef
= lpvRef
;
1098 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A
) This
, (LPDIENUMDEVICEOBJECTSCALLBACKA
) DIEnumDevicesCallbackAtoW
, (LPVOID
) &data
, dwFlags
);
1101 /******************************************************************************
1102 * GetProperty : get input device properties
1104 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
1106 LPDIPROPHEADER pdiph
)
1108 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1110 TRACE("(this=%p,%s,%p)\n",
1111 iface
, debugstr_guid(rguid
), pdiph
);
1113 if (TRACE_ON(dinput
))
1114 _dump_DIPROPHEADER(pdiph
);
1116 if (!HIWORD(rguid
)) {
1117 switch ((DWORD
)rguid
) {
1118 case (DWORD
) DIPROP_BUFFERSIZE
: {
1119 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1121 TRACE(" return buffersize = %d\n",This
->queue_len
);
1122 pd
->dwData
= This
->queue_len
;
1126 case (DWORD
) DIPROP_RANGE
: {
1127 /* LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph; */
1128 if ((pdiph
->dwHow
== DIPH_BYID
) &&
1129 (pdiph
->dwObj
& DIDFT_ABSAXIS
)) {
1130 /* The app is querying the current range of the axis : return the lMin and lMax values */
1131 FIXME("unimplemented axis range query.\n");
1138 FIXME("Unknown type %ld (%s)\n",(DWORD
)rguid
,debugstr_guid(rguid
));
1147 /******************************************************************************
1148 * CreateEffect - Create a new FF effect with the specified params
1150 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
,
1153 LPDIRECTINPUTEFFECT
*ppdef
,
1154 LPUNKNOWN pUnkOuter
)
1156 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1157 EffectListItem
* new = NULL
;
1158 HRESULT retval
= DI_OK
;
1161 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1162 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
1164 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1165 TRACE("not available (compiled w/o ff support)\n");
1170 new = malloc(sizeof(EffectListItem
));
1171 new->next
= This
->top_effect
;
1172 This
->top_effect
= new;
1174 retval
= linuxinput_create_effect(&(This
->joyfd
), rguid
, &(new->ref
));
1175 if (retval
!= DI_OK
)
1179 retval
= new->ref
->lpVtbl
->SetParameters(new->ref
, lpeff
, 0);
1180 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1185 if (pUnkOuter
!= NULL
)
1186 FIXME("Interface aggregation not implemented.\n");
1190 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1193 /*******************************************************************************
1194 * EnumEffects - Enumerate available FF effects
1196 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1197 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1201 DIEFFECTINFOA dei
; /* feif */
1202 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1203 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1204 int xfd
= This
->joyfd
;
1206 TRACE("(this=%p,%p,%ld) type=%ld fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1208 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1209 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1211 /* We need to return something even if we're not yet acquired */
1213 iface
->lpVtbl
->Acquire(iface
);
1215 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1216 && test_bit(This
->ffbits
, FF_CONSTANT
)) {
1217 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1218 (*lpCallback
)(&dei
, pvRef
);
1221 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1222 && test_bit(This
->ffbits
, FF_PERIODIC
)) {
1223 if (test_bit(This
->ffbits
, FF_SQUARE
)) {
1224 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Square
);
1225 (*lpCallback
)(&dei
, pvRef
);
1227 if (test_bit(This
->ffbits
, FF_SINE
)) {
1228 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1229 (*lpCallback
)(&dei
, pvRef
);
1231 if (test_bit(This
->ffbits
, FF_TRIANGLE
)) {
1232 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1233 (*lpCallback
)(&dei
, pvRef
);
1235 if (test_bit(This
->ffbits
, FF_SAW_UP
)) {
1236 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1237 (*lpCallback
)(&dei
, pvRef
);
1239 if (test_bit(This
->ffbits
, FF_SAW_DOWN
)) {
1240 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1241 (*lpCallback
)(&dei
, pvRef
);
1245 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1246 && test_bit(This
->ffbits
, FF_RAMP
)) {
1247 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1248 (*lpCallback
)(&dei
, pvRef
);
1251 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1252 if (test_bit(This
->ffbits
, FF_SPRING
)) {
1253 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1254 (*lpCallback
)(&dei
, pvRef
);
1256 if (test_bit(This
->ffbits
, FF_DAMPER
)) {
1257 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1258 (*lpCallback
)(&dei
, pvRef
);
1260 if (test_bit(This
->ffbits
, FF_INERTIA
)) {
1261 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1262 (*lpCallback
)(&dei
, pvRef
);
1264 if (test_bit(This
->ffbits
, FF_FRICTION
)) {
1265 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1266 (*lpCallback
)(&dei
, pvRef
);
1270 /* return to unaquired state if that's where it was */
1272 iface
->lpVtbl
->Unacquire(iface
);
1278 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1279 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1283 /* seems silly to duplicate all this code but all the structures and functions
1284 * are actually different (A/W) */
1285 DIEFFECTINFOW dei
; /* feif */
1286 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1287 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1288 int xfd
= This
->joyfd
;
1290 TRACE("(this=%p,%p,%ld) type=%ld fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1292 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1293 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1295 /* We need to return something even if we're not yet acquired */
1297 iface
->lpVtbl
->Acquire(iface
);
1299 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1300 && test_bit(This
->ffbits
, FF_CONSTANT
)) {
1301 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1302 (*lpCallback
)(&dei
, pvRef
);
1305 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1306 && test_bit(This
->ffbits
, FF_PERIODIC
)) {
1307 if (test_bit(This
->ffbits
, FF_SQUARE
)) {
1308 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Square
);
1309 (*lpCallback
)(&dei
, pvRef
);
1311 if (test_bit(This
->ffbits
, FF_SINE
)) {
1312 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1313 (*lpCallback
)(&dei
, pvRef
);
1315 if (test_bit(This
->ffbits
, FF_TRIANGLE
)) {
1316 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1317 (*lpCallback
)(&dei
, pvRef
);
1319 if (test_bit(This
->ffbits
, FF_SAW_UP
)) {
1320 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1321 (*lpCallback
)(&dei
, pvRef
);
1323 if (test_bit(This
->ffbits
, FF_SAW_DOWN
)) {
1324 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1325 (*lpCallback
)(&dei
, pvRef
);
1329 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1330 && test_bit(This
->ffbits
, FF_RAMP
)) {
1331 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1332 (*lpCallback
)(&dei
, pvRef
);
1335 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1336 if (test_bit(This
->ffbits
, FF_SPRING
)) {
1337 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1338 (*lpCallback
)(&dei
, pvRef
);
1340 if (test_bit(This
->ffbits
, FF_DAMPER
)) {
1341 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1342 (*lpCallback
)(&dei
, pvRef
);
1344 if (test_bit(This
->ffbits
, FF_INERTIA
)) {
1345 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1346 (*lpCallback
)(&dei
, pvRef
);
1348 if (test_bit(This
->ffbits
, FF_FRICTION
)) {
1349 iface
->lpVtbl
->GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1350 (*lpCallback
)(&dei
, pvRef
);
1354 /* return to unaquired state if that's where it was */
1356 iface
->lpVtbl
->Unacquire(iface
);
1362 /*******************************************************************************
1363 * GetEffectInfo - Get information about a particular effect
1365 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1366 LPDIEFFECTINFOA pdei
,
1369 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1371 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1373 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1374 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1380 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1381 LPDIEFFECTINFOW pdei
,
1384 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1386 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1388 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1389 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1395 /*******************************************************************************
1396 * GetForceFeedbackState - Get information about the device's FF state
1398 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(
1399 LPDIRECTINPUTDEVICE8A iface
,
1402 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1404 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1408 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1409 /* DIGFFS_STOPPED is the only mandatory flag to report */
1410 if (This
->ff_state
== FF_STATUS_STOPPED
)
1411 (*pdwOut
) |= DIGFFS_STOPPED
;
1417 /*******************************************************************************
1418 * SendForceFeedbackCommand - Send a command to the device's FF system
1420 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(
1421 LPDIRECTINPUTDEVICE8A iface
,
1424 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1425 TRACE("(this=%p,%ld)\n", This
, dwFlags
);
1427 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1428 if (dwFlags
== DISFFC_STOPALL
) {
1429 /* Stop all effects */
1430 EffectListItem
* itr
= This
->top_effect
;
1432 itr
->ref
->lpVtbl
->Stop(itr
->ref
);
1435 } else if (dwFlags
== DISFFC_RESET
) {
1436 /* Stop, unload, release and free all effects */
1437 /* This returns the device to its "bare" state */
1438 while (This
->top_effect
) {
1439 EffectListItem
* temp
= This
->top_effect
;
1440 temp
->ref
->lpVtbl
->Stop(temp
->ref
);
1441 temp
->ref
->lpVtbl
->Unload(temp
->ref
);
1442 temp
->ref
->lpVtbl
->Release(temp
->ref
);
1443 This
->top_effect
= temp
->next
;
1446 } else if (dwFlags
== DISFFC_PAUSE
|| dwFlags
== DISFFC_CONTINUE
) {
1447 FIXME("No support for Pause or Continue in linux\n");
1448 } else if (dwFlags
== DISFFC_SETACTUATORSOFF
1449 || dwFlags
== DISFFC_SETACTUATORSON
) {
1450 FIXME("No direct actuator control in linux\n");
1452 FIXME("Unknown Force Feedback Command!\n");
1453 return DIERR_INVALIDPARAM
;
1457 return DIERR_UNSUPPORTED
;
1461 /*******************************************************************************
1462 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1463 * created for this device.
1465 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(
1466 LPDIRECTINPUTDEVICE8A iface
,
1467 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1471 /* this function is safe to call on non-ff-enabled builds */
1473 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1474 EffectListItem
* itr
= This
->top_effect
;
1475 TRACE("(this=%p,%p,%p,%ld)\n", This
, lpCallback
, pvRef
, dwFlags
);
1478 return DIERR_INVALIDPARAM
;
1481 FIXME("Flags specified, but no flags exist yet (DX9)!");
1484 (*lpCallback
)(itr
->ref
, pvRef
);
1491 static const IDirectInputDevice8AVtbl JoystickAvt
=
1493 IDirectInputDevice2AImpl_QueryInterface
,
1494 IDirectInputDevice2AImpl_AddRef
,
1495 JoystickAImpl_Release
,
1496 JoystickAImpl_GetCapabilities
,
1497 JoystickAImpl_EnumObjects
,
1498 JoystickAImpl_GetProperty
,
1499 JoystickAImpl_SetProperty
,
1500 JoystickAImpl_Acquire
,
1501 JoystickAImpl_Unacquire
,
1502 JoystickAImpl_GetDeviceState
,
1503 JoystickAImpl_GetDeviceData
,
1504 JoystickAImpl_SetDataFormat
,
1505 JoystickAImpl_SetEventNotification
,
1506 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1507 IDirectInputDevice2AImpl_GetObjectInfo
,
1508 IDirectInputDevice2AImpl_GetDeviceInfo
,
1509 IDirectInputDevice2AImpl_RunControlPanel
,
1510 IDirectInputDevice2AImpl_Initialize
,
1511 JoystickAImpl_CreateEffect
,
1512 JoystickAImpl_EnumEffects
,
1513 JoystickAImpl_GetEffectInfo
,
1514 JoystickAImpl_GetForceFeedbackState
,
1515 JoystickAImpl_SendForceFeedbackCommand
,
1516 JoystickAImpl_EnumCreatedEffectObjects
,
1517 IDirectInputDevice2AImpl_Escape
,
1519 IDirectInputDevice2AImpl_SendDeviceData
,
1520 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1521 IDirectInputDevice7AImpl_WriteEffectToFile
,
1522 IDirectInputDevice8AImpl_BuildActionMap
,
1523 IDirectInputDevice8AImpl_SetActionMap
,
1524 IDirectInputDevice8AImpl_GetImageInfo
1527 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1528 # define XCAST(fun) (typeof(JoystickWvt.fun))
1530 # define XCAST(fun) (void*)
1533 static const IDirectInputDevice8WVtbl JoystickWvt
=
1535 IDirectInputDevice2WImpl_QueryInterface
,
1536 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
1537 XCAST(Release
)JoystickAImpl_Release
,
1538 XCAST(GetCapabilities
)JoystickAImpl_GetCapabilities
,
1539 JoystickWImpl_EnumObjects
,
1540 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1541 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1542 XCAST(Acquire
)JoystickAImpl_Acquire
,
1543 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1544 XCAST(GetDeviceState
)JoystickAImpl_GetDeviceState
,
1545 XCAST(GetDeviceData
)JoystickAImpl_GetDeviceData
,
1546 XCAST(SetDataFormat
)JoystickAImpl_SetDataFormat
,
1547 XCAST(SetEventNotification
)JoystickAImpl_SetEventNotification
,
1548 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
1549 IDirectInputDevice2WImpl_GetObjectInfo
,
1550 IDirectInputDevice2WImpl_GetDeviceInfo
,
1551 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
1552 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
1553 XCAST(CreateEffect
)JoystickAImpl_CreateEffect
,
1554 JoystickWImpl_EnumEffects
,
1555 JoystickWImpl_GetEffectInfo
,
1556 XCAST(GetForceFeedbackState
)JoystickAImpl_GetForceFeedbackState
,
1557 XCAST(SendForceFeedbackCommand
)JoystickAImpl_SendForceFeedbackCommand
,
1558 XCAST(EnumCreatedEffectObjects
)JoystickAImpl_EnumCreatedEffectObjects
,
1559 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1560 XCAST(Poll
)JoystickAImpl_Poll
,
1561 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1562 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1563 IDirectInputDevice7WImpl_WriteEffectToFile
,
1564 IDirectInputDevice8WImpl_BuildActionMap
,
1565 IDirectInputDevice8WImpl_SetActionMap
,
1566 IDirectInputDevice8WImpl_GetImageInfo
1570 #else /* HAVE_CORRECT_LINUXINPUT_H */
1572 const struct dinput_device joystick_linuxinput_device
= {
1573 "Wine Linux-input joystick driver",
1580 #endif /* HAVE_CORRECT_LINUXINPUT_H */