1 /* DirectInput Joystick device
3 * Copyright 1998,2000 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
6 * Copyright 2005 Daniel Remenak
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
34 #ifdef HAVE_SYS_TIME_H
35 # include <sys/time.h>
37 #include <sys/fcntl.h>
38 #ifdef HAVE_SYS_IOCTL_H
39 # include <sys/ioctl.h>
42 #ifdef HAVE_SYS_ERRNO_H
43 # include <sys/errno.h>
45 #ifdef HAVE_LINUX_INPUT_H
46 # include <linux/input.h>
47 # if defined(EVIOCGBIT) && defined(EV_ABS) && defined(BTN_PINKIE)
48 # define HAVE_CORRECT_LINUXINPUT_H
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_POV_BASE 6
71 #define WINE_JOYSTICK_BUTTON_BASE 8
73 typedef struct EffectListItem EffectListItem
;
76 LPDIRECTINPUTEFFECT ref
;
77 struct EffectListItem
* next
;
80 /* implemented in effect_linuxinput.c */
81 HRESULT
linuxinput_create_effect(int* fd
, REFGUID rguid
, LPDIRECTINPUTEFFECT
* peff
);
82 HRESULT
linuxinput_get_info_A(int fd
, REFGUID rguid
, LPDIEFFECTINFOA info
);
83 HRESULT
linuxinput_get_info_W(int fd
, REFGUID rguid
, LPDIEFFECTINFOW info
);
85 typedef struct JoystickImpl JoystickImpl
;
86 static const IDirectInputDevice8AVtbl JoystickAvt
;
87 static const IDirectInputDevice8WVtbl JoystickWvt
;
97 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
98 BYTE evbits
[(EV_MAX
+7)/8];
99 BYTE absbits
[(ABS_MAX
+7)/8];
100 BYTE keybits
[(KEY_MAX
+7)/8];
101 BYTE ffbits
[(FF_MAX
+7)/8];
106 #define AXE_ABSFUZZ 3
107 #define AXE_ABSFLAT 4
109 /* data returned by the EVIOCGABS() ioctl */
110 int axes
[ABS_MAX
][5];
111 /* LUT for KEY_ to offset in rgbButtons */
112 BYTE buttons
[KEY_MAX
];
114 /* autodetecting ranges per axe by following movement */
115 LONG havemax
[ABS_MAX
];
116 LONG havemin
[ABS_MAX
];
124 struct JoyDev
*joydev
;
126 /* The 'parent' DInput */
127 IDirectInputImpl
*dinput
;
129 /* joystick private */
130 /* what range and deadzone the game wants */
131 LONG wantmin
[ABS_MAX
];
132 LONG wantmax
[ABS_MAX
];
137 LPDIDATAFORMAT internal_df
;
139 DataFormat
*transform
; /* wine to user format converter */
140 int *offsets
; /* object offsets */
142 LPDIDEVICEOBJECTDATA data_queue
;
143 int queue_head
, queue_tail
, queue_len
;
147 /* Force feedback variables */
148 EffectListItem
* top_effect
;
152 static void fake_current_js_state(JoystickImpl
*ji
);
153 static int find_property_offset(JoystickImpl
*This
, LPCDIPROPHEADER ph
);
154 static DWORD
map_pov(int event_value
, int is_x
);
155 static void find_joydevs(void);
156 static int lxinput_to_djoy2_offset(int ie_type
, int ie_code
);
157 static int offset_to_object(JoystickImpl
*This
, int offset
);
158 static void calculate_ids(LPDIDATAFORMAT df
);
160 /* This GUID is slightly different from the linux joystick one. Take note. */
161 static const GUID DInput_Wine_Joystick_Base_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
165 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
168 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
170 #define MAX_JOYDEV 64
172 static int have_joydevs
= -1;
173 static struct JoyDev
*joydevs
= NULL
;
175 static void find_joydevs(void)
179 if (have_joydevs
!=-1) {
185 for (i
=0;i
<MAX_JOYDEV
;i
++) {
187 struct JoyDev joydev
= {0};
192 snprintf(buf
,MAX_PATH
,EVDEVPREFIX
"%d",i
);
195 if ((fd
=open(buf
, O_RDWR
))==-1) {
196 fd
= open(buf
, O_RDONLY
);
201 if ((-1==ioctl(fd
,EVIOCGBIT(0,sizeof(joydev
.evbits
)),joydev
.evbits
))) {
202 perror("EVIOCGBIT 0");
206 if (-1==ioctl(fd
,EVIOCGBIT(EV_ABS
,sizeof(joydev
.absbits
)),joydev
.absbits
)) {
207 perror("EVIOCGBIT EV_ABS");
211 if (-1==ioctl(fd
,EVIOCGBIT(EV_KEY
,sizeof(joydev
.keybits
)),joydev
.keybits
)) {
212 perror("EVIOCGBIT EV_KEY");
216 /* A true joystick has at least axis X and Y, and at least 1
217 * button. copied from linux/drivers/input/joydev.c */
218 if (test_bit(joydev
.absbits
,ABS_X
) && test_bit(joydev
.absbits
,ABS_Y
) &&
219 ( test_bit(joydev
.keybits
,BTN_TRIGGER
) ||
220 test_bit(joydev
.keybits
,BTN_A
) ||
221 test_bit(joydev
.keybits
,BTN_1
)
225 joydev
.device
= strdup(buf
);
227 if (-1!=ioctl(fd
, EVIOCGNAME(MAX_PATH
-1), buf
)) {
229 joydev
.name
= strdup(buf
);
231 joydev
.name
= joydev
.device
;
234 joydev
.guid
= DInput_Wine_Joystick_Base_GUID
;
235 joydev
.guid
.Data3
+= have_joydevs
;
237 TRACE("Found a joystick on %s: %s (%s)\n",
238 joydev
.device
, joydev
.name
,
239 debugstr_guid(&joydev
.guid
)
242 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
244 if ((!test_bit(joydev
.evbits
,EV_FF
))
245 || (-1==ioctl(fd
,EVIOCGBIT(EV_FF
,sizeof(joydev
.ffbits
)),joydev
.ffbits
))
246 || (-1==ioctl(fd
,EVIOCGEFFECTS
,&joydev
.num_effects
))
247 || (joydev
.num_effects
<= 0)) {
250 TRACE(" ... with force feedback\n");
256 for (j
=0;j
<ABS_MAX
;j
++) {
257 if (test_bit(joydev
.absbits
,j
)) {
258 if (-1!=ioctl(fd
,EVIOCGABS(j
),&(joydev
.axes
[j
]))) {
259 TRACE(" ... with axe %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
261 joydev
.axes
[j
][AXE_ABS
],
262 joydev
.axes
[j
][AXE_ABSMIN
],
263 joydev
.axes
[j
][AXE_ABSMAX
],
264 joydev
.axes
[j
][AXE_ABSFUZZ
],
265 joydev
.axes
[j
][AXE_ABSFLAT
]
267 joydev
.havemin
[j
] = joydev
.axes
[j
][AXE_ABSMIN
];
268 joydev
.havemax
[j
] = joydev
.axes
[j
][AXE_ABSMAX
];
274 for (j
=0;j
<KEY_MAX
;j
++) {
275 if (test_bit(joydev
.keybits
,j
)) {
276 TRACE(" ... with button %d: %d\n", j
, buttons
);
277 joydev
.buttons
[j
] = 0x80 | buttons
;
282 if (have_joydevs
==0) {
283 joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
285 HeapReAlloc(GetProcessHeap(), 0, joydevs
, (1+have_joydevs
) * sizeof(struct JoyDev
));
287 memcpy(joydevs
+have_joydevs
, &joydev
, sizeof(struct JoyDev
));
296 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
300 if (id
>= have_joydevs
) {
304 if (!((dwDevType
== 0) ||
305 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
< 0x0800)) ||
306 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
309 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
310 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
314 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
315 lpddi
->guidInstance
= joydevs
[id
].guid
;
316 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
318 lpddi
->guidFFDriver
= GUID_NULL
;
319 if (version
>= 0x0800)
320 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
322 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
324 strcpy(lpddi
->tszInstanceName
, joydevs
[id
].name
);
325 strcpy(lpddi
->tszProductName
, joydevs
[id
].device
);
331 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
335 if (id
>= have_joydevs
) {
339 if (!((dwDevType
== 0) ||
340 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
< 0x0800)) ||
341 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))))
344 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
345 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
349 if (!(dwFlags
& DIEDFL_FORCEFEEDBACK
) || joydevs
[id
].has_ff
) {
350 lpddi
->guidInstance
= joydevs
[id
].guid
;
351 lpddi
->guidProduct
= DInput_Wine_Joystick_Base_GUID
;
353 lpddi
->guidFFDriver
= GUID_NULL
;
354 if (version
>= 0x0800)
355 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
357 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
359 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
360 MultiByteToWideChar(CP_ACP
, 0, joydevs
[id
].device
, -1, lpddi
->tszProductName
, MAX_PATH
);
366 static JoystickImpl
*alloc_device(REFGUID rguid
, const void *jvt
, IDirectInputImpl
*dinput
, struct JoyDev
*joydev
)
368 JoystickImpl
* newDevice
;
371 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(JoystickImpl
));
372 if (newDevice
==NULL
) {
376 newDevice
->lpVtbl
= jvt
;
378 newDevice
->joyfd
= -1;
379 newDevice
->dinput
= dinput
;
380 newDevice
->joydev
= joydev
;
381 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
382 newDevice
->ff_state
= FF_STATUS_STOPPED
;
384 memcpy(&(newDevice
->guid
),rguid
,sizeof(*rguid
));
385 for (i
=0;i
<ABS_MAX
;i
++) {
386 /* apps expect the range to be the same they would get from the
387 * GetProperty/range method */
388 newDevice
->wantmin
[i
] = newDevice
->joydev
->havemin
[i
];
389 newDevice
->wantmax
[i
] = newDevice
->joydev
->havemax
[i
];
391 * direct input defines a default for the deadzone somewhere; but as long
392 * as in map_axis the code for the dead zone is commented out its no
395 newDevice
->deadz
[i
] = 0;
397 fake_current_js_state(newDevice
);
399 /* wine uses DIJOYSTATE2 as it's internal format so copy
400 * the already defined format c_dfDIJoystick2 */
401 newDevice
->df
= HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2
.dwSize
);
402 if (newDevice
->df
== 0)
404 CopyMemory(newDevice
->df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
406 /* copy default objects */
407 newDevice
->df
->rgodf
= HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2
.dwNumObjs
*c_dfDIJoystick2
.dwObjSize
);
408 if (newDevice
->df
->rgodf
== 0)
410 CopyMemory(newDevice
->df
->rgodf
,c_dfDIJoystick2
.rgodf
,c_dfDIJoystick2
.dwNumObjs
*c_dfDIJoystick2
.dwObjSize
);
412 /* no do the same for the internal df */
413 newDevice
->internal_df
= HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2
.dwSize
);
414 if (newDevice
->internal_df
== 0)
416 CopyMemory(newDevice
->internal_df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
418 /* copy default objects */
419 newDevice
->internal_df
->rgodf
= HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2
.dwNumObjs
*c_dfDIJoystick2
.dwObjSize
);
420 if (newDevice
->internal_df
->rgodf
== 0)
422 CopyMemory(newDevice
->internal_df
->rgodf
,c_dfDIJoystick2
.rgodf
,c_dfDIJoystick2
.dwNumObjs
*c_dfDIJoystick2
.dwObjSize
);
424 /* create an offsets array */
425 newDevice
->offsets
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,c_dfDIJoystick2
.dwNumObjs
*sizeof(int));
426 if (newDevice
->offsets
== 0)
429 calculate_ids(newDevice
->internal_df
);
431 /* create the default transform filter */
432 newDevice
->transform
= create_DataFormat(newDevice
->internal_df
, newDevice
->df
, newDevice
->offsets
);
433 calculate_ids(newDevice
->df
);
438 HeapFree(GetProcessHeap(),0,newDevice
->df
->rgodf
);
439 HeapFree(GetProcessHeap(),0,newDevice
->df
);
440 HeapFree(GetProcessHeap(),0,newDevice
->internal_df
->rgodf
);
441 HeapFree(GetProcessHeap(),0,newDevice
->internal_df
);
442 HeapFree(GetProcessHeap(),0,newDevice
);
446 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
452 for (i
=0; i
<have_joydevs
; i
++) {
453 if (IsEqualGUID(&GUID_Joystick
,rguid
) ||
454 IsEqualGUID(&joydevs
[i
].guid
,rguid
)
456 if ((riid
== NULL
) ||
457 IsEqualGUID(&IID_IDirectInputDeviceA
,riid
) ||
458 IsEqualGUID(&IID_IDirectInputDevice2A
,riid
) ||
459 IsEqualGUID(&IID_IDirectInputDevice7A
,riid
) ||
460 IsEqualGUID(&IID_IDirectInputDevice8A
,riid
)) {
461 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &JoystickAvt
, dinput
, &joydevs
[i
]);
462 TRACE("Creating a Joystick device (%p)\n", *pdev
);
464 ERR("out of memory\n");
465 return DIERR_OUTOFMEMORY
;
469 return DIERR_NOINTERFACE
;
474 return DIERR_DEVICENOTREG
;
478 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
484 for (i
=0; i
<have_joydevs
; i
++) {
485 if (IsEqualGUID(&GUID_Joystick
,rguid
) ||
486 IsEqualGUID(&joydevs
[i
].guid
,rguid
)
488 if ((riid
== NULL
) ||
489 IsEqualGUID(&IID_IDirectInputDeviceW
,riid
) ||
490 IsEqualGUID(&IID_IDirectInputDevice2W
,riid
) ||
491 IsEqualGUID(&IID_IDirectInputDevice7W
,riid
) ||
492 IsEqualGUID(&IID_IDirectInputDevice8W
,riid
)) {
493 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &JoystickWvt
, dinput
, &joydevs
[i
]);
494 TRACE("Creating a Joystick device (%p)\n", *pdev
);
496 ERR("out of memory\n");
497 return DIERR_OUTOFMEMORY
;
501 return DIERR_NOINTERFACE
;
506 return DIERR_DEVICENOTREG
;
509 const struct dinput_device joystick_linuxinput_device
= {
510 "Wine Linux-input joystick driver",
513 joydev_create_deviceA
,
514 joydev_create_deviceW
517 /******************************************************************************
520 static ULONG WINAPI
JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface
)
522 JoystickImpl
*This
= (JoystickImpl
*)iface
;
525 ref
= InterlockedDecrement(&(This
->ref
));
529 /* Reset the FF state, free all effects, etc */
530 IDirectInputDevice8_SendForceFeedbackCommand(iface
, DISFFC_RESET
);
532 /* Free the data queue */
533 HeapFree(GetProcessHeap(),0,This
->data_queue
);
535 /* Free the DataFormat */
536 HeapFree(GetProcessHeap(), 0, This
->df
->rgodf
);
537 HeapFree(GetProcessHeap(), 0, This
->df
);
539 /* Free the offsets array */
540 HeapFree(GetProcessHeap(),0,This
->offsets
);
542 /* release the data transform filter */
543 release_DataFormat(This
->transform
);
545 HeapFree(GetProcessHeap(),0,This
);
549 /******************************************************************************
550 * SetDataFormat : the application can choose the format of the data
551 * the device driver sends back with GetDeviceState.
553 static HRESULT WINAPI
JoystickAImpl_SetDataFormat(
554 LPDIRECTINPUTDEVICE8A iface
,LPCDIDATAFORMAT df
557 JoystickImpl
*This
= (JoystickImpl
*)iface
;
559 TRACE("(this=%p,%p)\n",This
,df
);
562 WARN("invalid pointer\n");
566 if (df
->dwSize
!= sizeof(*df
)) {
567 WARN("invalid argument\n");
568 return DIERR_INVALIDPARAM
;
571 _dump_DIDATAFORMAT(df
);
573 if (This
->joyfd
!=-1) {
575 return DIERR_ACQUIRED
;
578 HeapFree(GetProcessHeap(),0,This
->df
->rgodf
);
579 HeapFree(GetProcessHeap(),0,This
->df
);
580 release_DataFormat(This
->transform
);
582 /* Store the new data format */
583 This
->df
= HeapAlloc(GetProcessHeap(),0,df
->dwSize
);
584 if (This
->df
==NULL
) {
585 return DIERR_OUTOFMEMORY
;
587 memcpy(This
->df
, df
, df
->dwSize
);
588 This
->df
->rgodf
= HeapAlloc(GetProcessHeap(),0,df
->dwNumObjs
*df
->dwObjSize
);
589 if (This
->df
->rgodf
==NULL
) {
590 HeapFree(GetProcessHeap(), 0, This
->df
);
591 return DIERR_OUTOFMEMORY
;
593 memcpy(This
->df
->rgodf
,df
->rgodf
,df
->dwNumObjs
*df
->dwObjSize
);
595 This
->transform
= create_DataFormat(This
->internal_df
, This
->df
, This
->offsets
);
596 calculate_ids(This
->df
);
601 /******************************************************************************
602 * Acquire : gets exclusive control of the joystick
604 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
606 JoystickImpl
*This
= (JoystickImpl
*)iface
;
608 TRACE("(this=%p)\n",This
);
611 if (This
->df
==NULL
) {
612 return DIERR_INVALIDPARAM
;
615 if (-1==(This
->joyfd
=open(This
->joydev
->device
,O_RDWR
))) {
616 if (-1==(This
->joyfd
=open(This
->joydev
->device
,O_RDONLY
))) {
617 /* Couldn't open the device at all */
618 perror(This
->joydev
->device
);
619 return DIERR_NOTFOUND
;
621 /* Couldn't open in r/w but opened in read-only. */
622 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This
->joydev
->device
);
629 /******************************************************************************
630 * Unacquire : frees the joystick
632 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
634 JoystickImpl
*This
= (JoystickImpl
*)iface
;
636 TRACE("(this=%p)\n",This
);
637 if (This
->joyfd
!=-1) {
647 * This maps the read value (from the input event) to a value in the
648 * 'wanted' range. It also autodetects the possible range of the axe and
649 * adapts values accordingly.
652 map_axis(JoystickImpl
* This
, int axis
, int val
) {
653 int xmin
= This
->joydev
->axes
[axis
][AXE_ABSMIN
];
654 int xmax
= This
->joydev
->axes
[axis
][AXE_ABSMAX
];
655 int hmax
= This
->joydev
->havemax
[axis
];
656 int hmin
= This
->joydev
->havemin
[axis
];
657 int wmin
= This
->wantmin
[axis
];
658 int wmax
= This
->wantmax
[axis
];
661 if (val
> hmax
) This
->joydev
->havemax
[axis
] = hmax
= val
;
662 if (val
< hmin
) This
->joydev
->havemin
[axis
] = hmin
= val
;
664 if (xmin
== xmax
) return val
;
666 /* map the value from the hmin-hmax range into the wmin-wmax range */
667 ret
= MulDiv( val
- hmin
, wmax
- wmin
, hmax
- hmin
) + wmin
;
669 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
);
672 /* deadzone doesn't work comfortably enough right now. needs more testing*/
673 if ((ret
> -deadz
/2 ) && (ret
< deadz
/2)) {
674 FIXME("%d in deadzone, return mid.\n",val
);
675 return (wmax
-wmin
)/2+wmin
;
682 * set the current state of the js device as it would be with the middle
685 static void fake_current_js_state(JoystickImpl
*ji
)
688 /* center the axes */
689 ji
->js
.lX
= test_bit(ji
->joydev
->absbits
, ABS_X
) ? map_axis(ji
, ABS_X
, ji
->joydev
->axes
[ABS_X
][AXE_ABS
]) : 0;
690 ji
->js
.lY
= test_bit(ji
->joydev
->absbits
, ABS_Y
) ? map_axis(ji
, ABS_Y
, ji
->joydev
->axes
[ABS_Y
][AXE_ABS
]) : 0;
691 ji
->js
.lZ
= test_bit(ji
->joydev
->absbits
, ABS_Z
) ? map_axis(ji
, ABS_Z
, ji
->joydev
->axes
[ABS_Z
][AXE_ABS
]) : 0;
692 ji
->js
.lRx
= test_bit(ji
->joydev
->absbits
, ABS_RX
) ? map_axis(ji
, ABS_RX
, ji
->joydev
->axes
[ABS_RX
][AXE_ABS
]) : 0;
693 ji
->js
.lRy
= test_bit(ji
->joydev
->absbits
, ABS_RY
) ? map_axis(ji
, ABS_RY
, ji
->joydev
->axes
[ABS_RY
][AXE_ABS
]) : 0;
694 ji
->js
.lRz
= test_bit(ji
->joydev
->absbits
, ABS_RZ
) ? map_axis(ji
, ABS_RZ
, ji
->joydev
->axes
[ABS_RZ
][AXE_ABS
]) : 0;
695 ji
->js
.rglSlider
[0] = test_bit(ji
->joydev
->absbits
, ABS_THROTTLE
) ? map_axis(ji
, ABS_THROTTLE
, ji
->joydev
->axes
[ABS_THROTTLE
][AXE_ABS
]) : 0;
696 ji
->js
.rglSlider
[1] = test_bit(ji
->joydev
->absbits
, ABS_RUDDER
) ? map_axis(ji
, ABS_RUDDER
, ji
->joydev
->axes
[ABS_RUDDER
][AXE_ABS
]) : 0;
697 /* POV center is -1 */
698 for (i
=0; i
<4; i
++) {
699 ji
->js
.rgdwPOV
[i
] = -1;
704 * Maps an event value to a DX "clock" position:
709 static DWORD
map_pov(int event_value
, int is_x
)
715 } else if (event_value
>0) {
721 } else if (event_value
>0) {
728 static int find_property_offset(JoystickImpl
*This
, LPCDIPROPHEADER ph
)
733 for (i
=0; i
<This
->df
->dwNumObjs
; i
++) {
734 if (This
->offsets
[i
]==ph
->dwObj
) {
740 for (i
=0; i
<This
->df
->dwNumObjs
; i
++) {
741 if ((This
->df
->rgodf
[i
].dwType
& 0x00ffffff) == (ph
->dwObj
& 0x00ffffff)) {
742 ofs
= This
->df
->rgodf
[i
].dwOfs
;
747 for (i
=0; i
<This
->df
->dwNumObjs
; i
++) {
748 if (This
->offsets
[i
]==ofs
) {
755 FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph
->dwHow
);
761 /* defines how the linux input system offset mappings into c_dfDIJoystick2 */
763 lxinput_to_djoy2_offset( int ie_type
, int ie_code
)
768 case ABS_X
: return 0;
769 case ABS_Y
: return 1;
770 case ABS_Z
: return 2;
771 case ABS_RX
: return 3;
772 case ABS_RY
: return 4;
773 case ABS_RZ
: return 5;
774 case ABS_THROTTLE
: return 6;
775 case ABS_RUDDER
: return 7;
777 case ABS_HAT0Y
: return 8;
779 case ABS_HAT1Y
: return 9;
781 case ABS_HAT2Y
: return 10;
783 case ABS_HAT3Y
: return 11;
785 FIXME("Unhandled EV_ABS(0x%02X)\n", ie_code
);
792 WARN("DX8 does not support more than 128 buttons\n");
796 FIXME("Unhandled type(0x%02X)\n", ie_type
);
800 /* convert wine format offset to user format object index */
801 static int offset_to_object(JoystickImpl
*This
, int offset
)
805 for (i
= 0; i
< This
->df
->dwNumObjs
; i
++) {
806 if (This
->df
->rgodf
[i
].dwOfs
== offset
)
813 static void calculate_ids(LPDIDATAFORMAT df
)
823 /* Make two passes over the format. The first counts the number
824 * for each type and the second sets the id */
825 for (i
= 0; i
< df
->dwNumObjs
; i
++) {
826 if (DIDFT_GETTYPE(df
->rgodf
[i
].dwType
) & DIDFT_AXIS
)
828 else if (DIDFT_GETTYPE(df
->rgodf
[i
].dwType
) & DIDFT_POV
)
830 else if (DIDFT_GETTYPE(df
->rgodf
[i
].dwType
) & DIDFT_BUTTON
)
836 button_base
= axis
+ pov
;
842 for (i
= 0; i
< df
->dwNumObjs
; i
++) {
844 if (DIDFT_GETTYPE(df
->rgodf
[i
].dwType
) & DIDFT_AXIS
) {
846 type
= DIDFT_GETTYPE(df
->rgodf
[i
].dwType
) |
847 DIDFT_MAKEINSTANCE(axis
+ axis_base
);
848 TRACE("axis type = 0x%08lx\n", type
);
849 } else if (DIDFT_GETTYPE(df
->rgodf
[i
].dwType
) & DIDFT_POV
) {
851 type
= DIDFT_GETTYPE(df
->rgodf
[i
].dwType
) |
852 DIDFT_MAKEINSTANCE(pov
+ pov_base
);
853 TRACE("POV type = 0x%08lx\n", type
);
854 } else if (DIDFT_GETTYPE(df
->rgodf
[i
].dwType
) & DIDFT_BUTTON
) {
856 type
= DIDFT_GETTYPE(df
->rgodf
[i
].dwType
) |
857 DIDFT_MAKEINSTANCE(button
+ button_base
);
858 TRACE("button type = 0x%08lx\n", type
);
860 df
->rgodf
[i
].dwType
= type
;
864 static void joy_polldev(JoystickImpl
*This
) {
867 struct input_event ie
;
874 memset(&tv
,0,sizeof(tv
));
876 FD_SET(This
->joyfd
,&readfds
);
878 if (1>select(This
->joyfd
+1,&readfds
,NULL
,NULL
,&tv
))
881 /* we have one event, so we can read */
882 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
885 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
887 case EV_KEY
: /* button */
888 btn
= This
->joydev
->buttons
[ie
.code
];
889 TRACE("(%p) %d -> %d\n", This
, ie
.code
, btn
);
892 /* see if there is a mapping */
893 offset
= lxinput_to_djoy2_offset(ie
.type
, btn
);
897 /* and see if there is an offset in the df */
898 offset
= This
->offsets
[offset
];
902 This
->js
.rgbButtons
[btn
] = ie
.value
?0x80:0x00;
903 GEN_EVENT(offset
,This
->js
.rgbButtons
[btn
],ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
907 /* see if there is a mapping */
908 offset
= lxinput_to_djoy2_offset(ie
.type
, ie
.code
);
912 /* and see if there is an offset in the df */
913 offset
= This
->offsets
[offset
];
919 This
->js
.lX
= map_axis(This
,ABS_X
,ie
.value
);
920 GEN_EVENT(offset
,This
->js
.lX
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
923 This
->js
.lY
= map_axis(This
,ABS_Y
,ie
.value
);
924 GEN_EVENT(offset
,This
->js
.lY
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
927 This
->js
.lZ
= map_axis(This
,ABS_Z
,ie
.value
);
928 GEN_EVENT(offset
,This
->js
.lZ
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
931 This
->js
.lRx
= map_axis(This
,ABS_RX
,ie
.value
);
932 GEN_EVENT(offset
,This
->js
.lRx
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
935 This
->js
.lRy
= map_axis(This
,ABS_RY
,ie
.value
);
936 GEN_EVENT(offset
,This
->js
.lRy
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
939 This
->js
.lRz
= map_axis(This
,ABS_RZ
,ie
.value
);
940 GEN_EVENT(offset
,This
->js
.lRz
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
943 This
->js
.rglSlider
[0] = map_axis(This
,ABS_THROTTLE
,ie
.value
);
944 GEN_EVENT(offset
,This
->js
.rglSlider
[0],ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
947 This
->js
.rglSlider
[1] = map_axis(This
,ABS_RUDDER
,ie
.value
);
948 GEN_EVENT(offset
,This
->js
.rglSlider
[1],ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
952 This
->js
.rgdwPOV
[0] = map_pov(ie
.value
,ie
.code
==ABS_HAT0X
);
953 GEN_EVENT(offset
,This
->js
.rgdwPOV
[0],ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
957 This
->js
.rgdwPOV
[1] = map_pov(ie
.value
,ie
.code
==ABS_HAT1X
);
958 GEN_EVENT(offset
,This
->js
.rgdwPOV
[1],ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
962 This
->js
.rgdwPOV
[2] = map_pov(ie
.value
,ie
.code
==ABS_HAT2X
);
963 GEN_EVENT(offset
,This
->js
.rgdwPOV
[2],ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
967 This
->js
.rgdwPOV
[3] = map_pov(ie
.value
,ie
.code
==ABS_HAT3X
);
968 GEN_EVENT(offset
,This
->js
.rgdwPOV
[3],ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
971 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie
.code
,ie
.value
);
975 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
977 This
->ff_state
= ie
.value
;
982 /* there is nothing to do */
986 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
992 /******************************************************************************
993 * GetDeviceState : returns the "state" of the joystick.
996 static HRESULT WINAPI
JoystickAImpl_GetDeviceState(
997 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
999 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1001 TRACE("(this=%p,0x%08lx,%p)\n",This
,len
,ptr
);
1003 if (This
->joyfd
==-1) {
1004 WARN("not acquired\n");
1005 return DIERR_NOTACQUIRED
;
1010 /* convert and copy data to user supplied buffer */
1011 fill_DataFormat(ptr
, &This
->js
, This
->transform
);
1016 /******************************************************************************
1017 * GetDeviceData : gets buffered input data.
1019 static HRESULT WINAPI
JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface
,
1021 LPDIDEVICEOBJECTDATA dod
,
1025 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1030 TRACE("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx)\n",This
,dodsize
,*entries
,flags
);
1032 if (This
->joyfd
==-!1) {
1033 WARN("not acquired\n");
1034 return DIERR_NOTACQUIRED
;
1038 if (flags
& DIGDD_PEEK
)
1039 FIXME("DIGDD_PEEK\n");
1041 len
= ((This
->queue_head
< This
->queue_tail
) ? This
->queue_len
: 0)
1042 + (This
->queue_head
- This
->queue_tail
);
1048 TRACE("Application discarding %ld event(s).\n", len
);
1051 nqtail
= This
->queue_tail
+ len
;
1052 while (nqtail
>= This
->queue_len
)
1053 nqtail
-= This
->queue_len
;
1055 if (dodsize
< sizeof(DIDEVICEOBJECTDATA_DX3
)) {
1056 ERR("Wrong structure size !\n");
1057 return DIERR_INVALIDPARAM
;
1061 TRACE("Application retrieving %ld event(s).\n", len
);
1064 nqtail
= This
->queue_tail
;
1066 /* Copy the buffered data into the application queue */
1067 memcpy((char *)dod
+ *entries
* dodsize
, This
->data_queue
+ nqtail
, dodsize
);
1068 /* Advance position */
1070 if (nqtail
>= This
->queue_len
)
1071 nqtail
-= This
->queue_len
;
1077 if (This
->overflow
) {
1078 hr
= DI_BUFFEROVERFLOW
;
1079 if (!(flags
& DIGDD_PEEK
)) {
1080 This
->overflow
= FALSE
;
1084 if (!(flags
& DIGDD_PEEK
))
1085 This
->queue_tail
= nqtail
;
1090 /******************************************************************************
1091 * SetProperty : change input device properties
1093 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
1097 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1100 WARN("invalid argument\n");
1101 return DIERR_INVALIDPARAM
;
1104 TRACE("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
1105 TRACE("ph.dwSize = %ld, ph.dwHeaderSize =%ld, ph.dwObj = %ld, ph.dwHow= %ld\n",ph
->dwSize
, ph
->dwHeaderSize
,ph
->dwObj
,ph
->dwHow
);
1107 if (!HIWORD(rguid
)) {
1108 switch (LOWORD(rguid
)) {
1109 case (DWORD
) DIPROP_BUFFERSIZE
: {
1110 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
1112 TRACE("buffersize = %ld\n",pd
->dwData
);
1113 if (This
->data_queue
) {
1114 This
->data_queue
= HeapReAlloc(GetProcessHeap(),0, This
->data_queue
, pd
->dwData
* sizeof(DIDEVICEOBJECTDATA
));
1116 This
->data_queue
= HeapAlloc(GetProcessHeap(),0, pd
->dwData
* sizeof(DIDEVICEOBJECTDATA
));
1118 This
->queue_head
= 0;
1119 This
->queue_tail
= 0;
1120 This
->queue_len
= pd
->dwData
;
1123 case (DWORD
)DIPROP_RANGE
: {
1124 LPCDIPROPRANGE pr
= (LPCDIPROPRANGE
)ph
;
1126 if (ph
->dwHow
== DIPH_DEVICE
) {
1128 TRACE("proprange(%ld,%ld) all\n",pr
->lMin
,pr
->lMax
);
1129 for (i
= 0; i
< This
->df
->dwNumObjs
; i
++) {
1130 This
->wantmin
[i
] = pr
->lMin
;
1131 This
->wantmax
[i
] = pr
->lMax
;
1134 int obj
= find_property_offset(This
, ph
);
1135 TRACE("proprange(%ld,%ld) obj=%d\n",pr
->lMin
,pr
->lMax
,obj
);
1137 This
->wantmin
[obj
] = pr
->lMin
;
1138 This
->wantmax
[obj
] = pr
->lMax
;
1141 fake_current_js_state(This
);
1144 case (DWORD
)DIPROP_DEADZONE
: {
1145 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
1146 if (ph
->dwHow
== DIPH_DEVICE
) {
1148 TRACE("deadzone(%ld) all\n",pd
->dwData
);
1149 for (i
= 0; i
< This
->df
->dwNumObjs
; i
++) {
1150 This
->deadz
[i
] = pd
->dwData
;
1153 int obj
= find_property_offset(This
, ph
);
1154 TRACE("deadzone(%ld) obj=%d\n",pd
->dwData
,obj
);
1156 This
->deadz
[obj
] = pd
->dwData
;
1159 fake_current_js_state(This
);
1163 FIXME("Unknown type %p (%s)\n",rguid
,debugstr_guid(rguid
));
1170 /******************************************************************************
1171 * SetEventNotification : specifies event to be sent on state change
1173 static HRESULT WINAPI
JoystickAImpl_SetEventNotification(
1174 LPDIRECTINPUTDEVICE8A iface
, HANDLE hnd
1176 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1178 TRACE("(this=%p,%p)\n",This
,hnd
);
1183 static HRESULT WINAPI
JoystickAImpl_GetCapabilities(
1184 LPDIRECTINPUTDEVICE8A iface
,
1185 LPDIDEVCAPS lpDIDevCaps
)
1187 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1188 int i
,axes
,buttons
,povs
;
1190 TRACE("%p->(%p)\n",iface
,lpDIDevCaps
);
1193 WARN("invalid pointer\n");
1197 if (lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS
)) {
1198 WARN("invalid argument\n");
1199 return DIERR_INVALIDPARAM
;
1202 lpDIDevCaps
->dwFlags
= DIDC_ATTACHED
;
1203 if (This
->dinput
->dwVersion
>= 0x0800)
1204 lpDIDevCaps
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
1206 lpDIDevCaps
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
1209 for (i
=0;i
<ABS_MAX
;i
++) {
1210 if (!test_bit(This
->joydev
->absbits
,i
)) continue;
1212 case ABS_HAT0X
: case ABS_HAT0Y
:
1213 case ABS_HAT1X
: case ABS_HAT1Y
:
1214 case ABS_HAT2X
: case ABS_HAT2Y
:
1215 case ABS_HAT3X
: case ABS_HAT3Y
:
1216 /* will be handled as POV - see below */
1223 for (i
=0;i
<KEY_MAX
;i
++) if (test_bit(This
->joydev
->keybits
,i
)) buttons
++;
1225 for (i
=0; i
<4; i
++) {
1226 if (test_bit(This
->joydev
->absbits
,ABS_HAT0X
+(i
<<1)) && test_bit(This
->joydev
->absbits
,ABS_HAT0Y
+(i
<<1))) {
1231 if (This
->joydev
->has_ff
)
1232 lpDIDevCaps
->dwFlags
|= DIDC_FORCEFEEDBACK
;
1234 lpDIDevCaps
->dwAxes
= axes
;
1235 lpDIDevCaps
->dwButtons
= buttons
;
1236 lpDIDevCaps
->dwPOVs
= povs
;
1241 static HRESULT WINAPI
JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface
) {
1242 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1243 TRACE("(%p)\n",This
);
1245 if (This
->joyfd
==-1) {
1246 return DIERR_NOTACQUIRED
;
1253 /******************************************************************************
1254 * EnumObjects : enumerate the different buttons and axis...
1256 static HRESULT WINAPI
JoystickAImpl_EnumObjects(
1257 LPDIRECTINPUTDEVICE8A iface
,
1258 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback
,
1262 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1263 DIDEVICEOBJECTINSTANCEA ddoi
;
1264 int user_offset
, user_object
;
1266 TRACE("(this=%p,%p,%p,%08lx)\n", This
, lpCallback
, lpvRef
, dwFlags
);
1267 if (TRACE_ON(dinput
)) {
1268 TRACE(" - flags = ");
1269 _dump_EnumObjects_flags(dwFlags
);
1273 /* Only the fields till dwFFMaxForce are relevant */
1274 ddoi
.dwSize
= FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA
, dwFFMaxForce
);
1276 /* For the joystick, do as is done in the GetCapabilities function */
1277 /* FIXME: needs more items */
1278 if ((dwFlags
== DIDFT_ALL
) ||
1279 (dwFlags
& DIDFT_AXIS
)) {
1282 for (i
= 0; i
< ABS_MAX
; i
++) {
1283 if (!test_bit(This
->joydev
->absbits
,i
)) continue;
1287 ddoi
.guidType
= GUID_XAxis
;
1290 ddoi
.guidType
= GUID_YAxis
;
1293 ddoi
.guidType
= GUID_ZAxis
;
1296 ddoi
.guidType
= GUID_RxAxis
;
1299 ddoi
.guidType
= GUID_RyAxis
;
1302 ddoi
.guidType
= GUID_RzAxis
;
1305 ddoi
.guidType
= GUID_Slider
;
1308 ddoi
.guidType
= GUID_Slider
;
1310 case ABS_HAT0X
: case ABS_HAT0Y
:
1311 case ABS_HAT1X
: case ABS_HAT1Y
:
1312 case ABS_HAT2X
: case ABS_HAT2Y
:
1313 case ABS_HAT3X
: case ABS_HAT3Y
:
1314 /* will be handled as POV - see below */
1317 FIXME("unhandled abs axis 0x%02x, ignoring!\n",i
);
1320 user_offset
= lxinput_to_djoy2_offset(EV_ABS
, i
);
1321 if (user_offset
== -1) {
1324 user_offset
= This
->offsets
[user_offset
];
1325 if (user_offset
== -1) {
1328 user_object
= offset_to_object(This
, user_offset
);
1329 ddoi
.dwType
= This
->df
->rgodf
[user_object
].dwType
& 0x00ffffff;
1330 ddoi
.dwOfs
= This
->df
->rgodf
[user_object
].dwOfs
;
1331 /* Linux event force feedback supports only (and always) x and y axes */
1332 if (i
== ABS_X
|| i
== ABS_Y
) {
1333 if (This
->joydev
->has_ff
)
1334 ddoi
.dwFlags
|= DIDOI_FFACTUATOR
;
1336 sprintf(ddoi
.tszName
, "%d-Axis", i
);
1337 _dump_OBJECTINSTANCEA(&ddoi
);
1338 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) {
1344 if ((dwFlags
== DIDFT_ALL
) ||
1345 (dwFlags
& DIDFT_POV
)) {
1347 ddoi
.guidType
= GUID_POV
;
1348 for (i
=0; i
<4; i
++) {
1349 if (test_bit(This
->joydev
->absbits
,ABS_HAT0X
+(i
<<1)) && test_bit(This
->joydev
->absbits
,ABS_HAT0Y
+(i
<<1))) {
1350 user_offset
= lxinput_to_djoy2_offset(EV_ABS
, ABS_HAT0X
+i
);
1351 if (user_offset
== -1) {
1354 user_offset
= This
->offsets
[user_offset
];
1355 if (user_offset
== -1) {
1358 user_object
= offset_to_object(This
, user_offset
);
1359 ddoi
.dwType
= This
->df
->rgodf
[user_object
].dwType
& 0x00ffffff;
1360 ddoi
.dwOfs
= This
->df
->rgodf
[user_object
].dwOfs
;
1361 sprintf(ddoi
.tszName
, "%d-POV", i
);
1362 _dump_OBJECTINSTANCEA(&ddoi
);
1363 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) {
1370 if ((dwFlags
== DIDFT_ALL
) ||
1371 (dwFlags
& DIDFT_BUTTON
)) {
1374 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
1376 ddoi
.guidType
= GUID_Button
;
1378 for (i
= 0; i
< KEY_MAX
; i
++) {
1379 if (!test_bit(This
->joydev
->keybits
,i
)) continue;
1380 user_offset
= lxinput_to_djoy2_offset(EV_KEY
, btncount
);
1381 if (user_offset
== -1) {
1384 user_offset
= This
->offsets
[user_offset
];
1385 if (user_offset
== -1) {
1388 user_object
= offset_to_object(This
, user_offset
);
1389 ddoi
.dwType
= This
->df
->rgodf
[user_object
].dwType
& 0x00ffffff;
1390 ddoi
.dwOfs
= This
->df
->rgodf
[user_object
].dwOfs
;
1391 sprintf(ddoi
.tszName
, "%d-Button", btncount
);
1393 _dump_OBJECTINSTANCEA(&ddoi
);
1394 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) {
1403 static HRESULT WINAPI
JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface
,
1404 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback
,
1408 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1410 device_enumobjects_AtoWcb_data data
;
1412 data
.lpCallBack
= lpCallback
;
1413 data
.lpvRef
= lpvRef
;
1415 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A
) This
, (LPDIENUMDEVICEOBJECTSCALLBACKA
) DIEnumDevicesCallbackAtoW
, (LPVOID
) &data
, dwFlags
);
1418 /******************************************************************************
1419 * GetProperty : get input device properties
1421 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
1423 LPDIPROPHEADER pdiph
)
1425 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1427 TRACE("(this=%p,%s,%p)\n",
1428 iface
, debugstr_guid(rguid
), pdiph
);
1430 if (TRACE_ON(dinput
))
1431 _dump_DIPROPHEADER(pdiph
);
1433 if (!HIWORD(rguid
)) {
1434 switch (LOWORD(rguid
)) {
1435 case (DWORD
) DIPROP_BUFFERSIZE
: {
1436 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1438 TRACE(" return buffersize = %d\n",This
->queue_len
);
1439 pd
->dwData
= This
->queue_len
;
1443 case (DWORD
) DIPROP_RANGE
: {
1444 LPDIPROPRANGE pr
= (LPDIPROPRANGE
) pdiph
;
1445 int obj
= find_property_offset(This
, pdiph
);
1447 pr
->lMin
= This
->joydev
->havemin
[obj
];
1448 pr
->lMax
= This
->joydev
->havemax
[obj
];
1449 TRACE("range(%ld, %ld) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
1456 FIXME("Unknown type %p (%s)\n",rguid
,debugstr_guid(rguid
));
1465 /******************************************************************************
1466 * CreateEffect - Create a new FF effect with the specified params
1468 static HRESULT WINAPI
JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface
,
1471 LPDIRECTINPUTEFFECT
*ppdef
,
1472 LPUNKNOWN pUnkOuter
)
1474 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1475 EffectListItem
* new = NULL
;
1476 HRESULT retval
= DI_OK
;
1479 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1480 TRACE("(this=%p,%p,%p,%p,%p)\n", This
, rguid
, lpeff
, ppdef
, pUnkOuter
);
1482 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1483 TRACE("not available (compiled w/o ff support)\n");
1488 new = malloc(sizeof(EffectListItem
));
1489 new->next
= This
->top_effect
;
1490 This
->top_effect
= new;
1492 retval
= linuxinput_create_effect(&(This
->joyfd
), rguid
, &(new->ref
));
1493 if (retval
!= DI_OK
)
1497 retval
= IDirectInputEffect_SetParameters(new->ref
, lpeff
, 0);
1498 if (retval
!= DI_OK
&& retval
!= DI_DOWNLOADSKIPPED
)
1503 if (pUnkOuter
!= NULL
)
1504 FIXME("Interface aggregation not implemented.\n");
1508 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1511 /*******************************************************************************
1512 * EnumEffects - Enumerate available FF effects
1514 static HRESULT WINAPI
JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface
,
1515 LPDIENUMEFFECTSCALLBACKA lpCallback
,
1519 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1520 DIEFFECTINFOA dei
; /* feif */
1521 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1522 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1524 TRACE("(this=%p,%p,%ld) type=%ld\n", This
, pvRef
, dwEffType
, type
);
1526 dei
.dwSize
= sizeof(DIEFFECTINFOA
);
1528 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1529 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1530 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1531 (*lpCallback
)(&dei
, pvRef
);
1534 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1535 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1536 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1537 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1538 (*lpCallback
)(&dei
, pvRef
);
1540 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1541 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1542 (*lpCallback
)(&dei
, pvRef
);
1544 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1545 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1546 (*lpCallback
)(&dei
, pvRef
);
1548 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1549 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1550 (*lpCallback
)(&dei
, pvRef
);
1552 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1553 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1554 (*lpCallback
)(&dei
, pvRef
);
1558 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1559 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1560 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1561 (*lpCallback
)(&dei
, pvRef
);
1564 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1565 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1566 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1567 (*lpCallback
)(&dei
, pvRef
);
1569 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1570 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1571 (*lpCallback
)(&dei
, pvRef
);
1573 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1574 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1575 (*lpCallback
)(&dei
, pvRef
);
1577 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1578 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1579 (*lpCallback
)(&dei
, pvRef
);
1588 static HRESULT WINAPI
JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface
,
1589 LPDIENUMEFFECTSCALLBACKW lpCallback
,
1593 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1594 /* seems silly to duplicate all this code but all the structures and functions
1595 * are actually different (A/W) */
1596 DIEFFECTINFOW dei
; /* feif */
1597 DWORD type
= DIEFT_GETTYPE(dwEffType
);
1598 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1599 int xfd
= This
->joyfd
;
1601 TRACE("(this=%p,%p,%ld) type=%ld fd=%d\n", This
, pvRef
, dwEffType
, type
, xfd
);
1603 dei
.dwSize
= sizeof(DIEFFECTINFOW
);
1605 if ((type
== DIEFT_ALL
|| type
== DIEFT_CONSTANTFORCE
)
1606 && test_bit(This
->joydev
->ffbits
, FF_CONSTANT
)) {
1607 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_ConstantForce
);
1608 (*lpCallback
)(&dei
, pvRef
);
1611 if ((type
== DIEFT_ALL
|| type
== DIEFT_PERIODIC
)
1612 && test_bit(This
->joydev
->ffbits
, FF_PERIODIC
)) {
1613 if (test_bit(This
->joydev
->ffbits
, FF_SQUARE
)) {
1614 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Square
);
1615 (*lpCallback
)(&dei
, pvRef
);
1617 if (test_bit(This
->joydev
->ffbits
, FF_SINE
)) {
1618 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Sine
);
1619 (*lpCallback
)(&dei
, pvRef
);
1621 if (test_bit(This
->joydev
->ffbits
, FF_TRIANGLE
)) {
1622 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Triangle
);
1623 (*lpCallback
)(&dei
, pvRef
);
1625 if (test_bit(This
->joydev
->ffbits
, FF_SAW_UP
)) {
1626 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothUp
);
1627 (*lpCallback
)(&dei
, pvRef
);
1629 if (test_bit(This
->joydev
->ffbits
, FF_SAW_DOWN
)) {
1630 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_SawtoothDown
);
1631 (*lpCallback
)(&dei
, pvRef
);
1635 if ((type
== DIEFT_ALL
|| type
== DIEFT_RAMPFORCE
)
1636 && test_bit(This
->joydev
->ffbits
, FF_RAMP
)) {
1637 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_RampForce
);
1638 (*lpCallback
)(&dei
, pvRef
);
1641 if (type
== DIEFT_ALL
|| type
== DIEFT_CONDITION
) {
1642 if (test_bit(This
->joydev
->ffbits
, FF_SPRING
)) {
1643 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Spring
);
1644 (*lpCallback
)(&dei
, pvRef
);
1646 if (test_bit(This
->joydev
->ffbits
, FF_DAMPER
)) {
1647 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Damper
);
1648 (*lpCallback
)(&dei
, pvRef
);
1650 if (test_bit(This
->joydev
->ffbits
, FF_INERTIA
)) {
1651 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Inertia
);
1652 (*lpCallback
)(&dei
, pvRef
);
1654 if (test_bit(This
->joydev
->ffbits
, FF_FRICTION
)) {
1655 IDirectInputDevice8_GetEffectInfo(iface
, &dei
, &GUID_Friction
);
1656 (*lpCallback
)(&dei
, pvRef
);
1660 /* return to unaquired state if that's where it was */
1662 IDirectInputDevice8_Unacquire(iface
);
1668 /*******************************************************************************
1669 * GetEffectInfo - Get information about a particular effect
1671 static HRESULT WINAPI
JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface
,
1672 LPDIEFFECTINFOA pdei
,
1675 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1677 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1679 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1680 return linuxinput_get_info_A(This
->joyfd
, guid
, pdei
);
1686 static HRESULT WINAPI
JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface
,
1687 LPDIEFFECTINFOW pdei
,
1690 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1692 TRACE("(this=%p,%p,%s)\n", This
, pdei
, _dump_dinput_GUID(guid
));
1694 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1695 return linuxinput_get_info_W(This
->joyfd
, guid
, pdei
);
1701 /*******************************************************************************
1702 * GetForceFeedbackState - Get information about the device's FF state
1704 static HRESULT WINAPI
JoystickAImpl_GetForceFeedbackState(
1705 LPDIRECTINPUTDEVICE8A iface
,
1708 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1710 TRACE("(this=%p,%p)\n", This
, pdwOut
);
1714 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1715 /* DIGFFS_STOPPED is the only mandatory flag to report */
1716 if (This
->ff_state
== FF_STATUS_STOPPED
)
1717 (*pdwOut
) |= DIGFFS_STOPPED
;
1723 /*******************************************************************************
1724 * SendForceFeedbackCommand - Send a command to the device's FF system
1726 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(
1727 LPDIRECTINPUTDEVICE8A iface
,
1730 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1731 TRACE("(this=%p,%ld)\n", This
, dwFlags
);
1733 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1734 if (dwFlags
== DISFFC_STOPALL
) {
1735 /* Stop all effects */
1736 EffectListItem
* itr
= This
->top_effect
;
1738 IDirectInputEffect_Stop(itr
->ref
);
1741 } else if (dwFlags
== DISFFC_RESET
) {
1742 /* Stop, unload, release and free all effects */
1743 /* This returns the device to its "bare" state */
1744 while (This
->top_effect
) {
1745 EffectListItem
* temp
= This
->top_effect
;
1746 IDirectInputEffect_Stop(temp
->ref
);
1747 IDirectInputEffect_Unload(temp
->ref
);
1748 IDirectInputEffect_Release(temp
->ref
);
1749 This
->top_effect
= temp
->next
;
1752 } else if (dwFlags
== DISFFC_PAUSE
|| dwFlags
== DISFFC_CONTINUE
) {
1753 FIXME("No support for Pause or Continue in linux\n");
1754 } else if (dwFlags
== DISFFC_SETACTUATORSOFF
1755 || dwFlags
== DISFFC_SETACTUATORSON
) {
1756 FIXME("No direct actuator control in linux\n");
1758 FIXME("Unknown Force Feedback Command!\n");
1759 return DIERR_INVALIDPARAM
;
1763 return DIERR_UNSUPPORTED
;
1767 /*******************************************************************************
1768 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1769 * created for this device.
1771 static HRESULT WINAPI
JoystickAImpl_EnumCreatedEffectObjects(
1772 LPDIRECTINPUTDEVICE8A iface
,
1773 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
1777 /* this function is safe to call on non-ff-enabled builds */
1779 JoystickImpl
* This
= (JoystickImpl
*)iface
;
1780 EffectListItem
* itr
= This
->top_effect
;
1781 TRACE("(this=%p,%p,%p,%ld)\n", This
, lpCallback
, pvRef
, dwFlags
);
1784 return DIERR_INVALIDPARAM
;
1787 FIXME("Flags specified, but no flags exist yet (DX9)!");
1790 (*lpCallback
)(itr
->ref
, pvRef
);
1797 static const IDirectInputDevice8AVtbl JoystickAvt
=
1799 IDirectInputDevice2AImpl_QueryInterface
,
1800 IDirectInputDevice2AImpl_AddRef
,
1801 JoystickAImpl_Release
,
1802 JoystickAImpl_GetCapabilities
,
1803 JoystickAImpl_EnumObjects
,
1804 JoystickAImpl_GetProperty
,
1805 JoystickAImpl_SetProperty
,
1806 JoystickAImpl_Acquire
,
1807 JoystickAImpl_Unacquire
,
1808 JoystickAImpl_GetDeviceState
,
1809 JoystickAImpl_GetDeviceData
,
1810 JoystickAImpl_SetDataFormat
,
1811 JoystickAImpl_SetEventNotification
,
1812 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1813 IDirectInputDevice2AImpl_GetObjectInfo
,
1814 IDirectInputDevice2AImpl_GetDeviceInfo
,
1815 IDirectInputDevice2AImpl_RunControlPanel
,
1816 IDirectInputDevice2AImpl_Initialize
,
1817 JoystickAImpl_CreateEffect
,
1818 JoystickAImpl_EnumEffects
,
1819 JoystickAImpl_GetEffectInfo
,
1820 JoystickAImpl_GetForceFeedbackState
,
1821 JoystickAImpl_SendForceFeedbackCommand
,
1822 JoystickAImpl_EnumCreatedEffectObjects
,
1823 IDirectInputDevice2AImpl_Escape
,
1825 IDirectInputDevice2AImpl_SendDeviceData
,
1826 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1827 IDirectInputDevice7AImpl_WriteEffectToFile
,
1828 IDirectInputDevice8AImpl_BuildActionMap
,
1829 IDirectInputDevice8AImpl_SetActionMap
,
1830 IDirectInputDevice8AImpl_GetImageInfo
1833 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1834 # define XCAST(fun) (typeof(JoystickWvt.fun))
1836 # define XCAST(fun) (void*)
1839 static const IDirectInputDevice8WVtbl JoystickWvt
=
1841 IDirectInputDevice2WImpl_QueryInterface
,
1842 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
1843 XCAST(Release
)JoystickAImpl_Release
,
1844 XCAST(GetCapabilities
)JoystickAImpl_GetCapabilities
,
1845 JoystickWImpl_EnumObjects
,
1846 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1847 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1848 XCAST(Acquire
)JoystickAImpl_Acquire
,
1849 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1850 XCAST(GetDeviceState
)JoystickAImpl_GetDeviceState
,
1851 XCAST(GetDeviceData
)JoystickAImpl_GetDeviceData
,
1852 XCAST(SetDataFormat
)JoystickAImpl_SetDataFormat
,
1853 XCAST(SetEventNotification
)JoystickAImpl_SetEventNotification
,
1854 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
1855 IDirectInputDevice2WImpl_GetObjectInfo
,
1856 IDirectInputDevice2WImpl_GetDeviceInfo
,
1857 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
1858 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
1859 XCAST(CreateEffect
)JoystickAImpl_CreateEffect
,
1860 JoystickWImpl_EnumEffects
,
1861 JoystickWImpl_GetEffectInfo
,
1862 XCAST(GetForceFeedbackState
)JoystickAImpl_GetForceFeedbackState
,
1863 XCAST(SendForceFeedbackCommand
)JoystickAImpl_SendForceFeedbackCommand
,
1864 XCAST(EnumCreatedEffectObjects
)JoystickAImpl_EnumCreatedEffectObjects
,
1865 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1866 XCAST(Poll
)JoystickAImpl_Poll
,
1867 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1868 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1869 IDirectInputDevice7WImpl_WriteEffectToFile
,
1870 IDirectInputDevice8WImpl_BuildActionMap
,
1871 IDirectInputDevice8WImpl_SetActionMap
,
1872 IDirectInputDevice8WImpl_GetImageInfo
1876 #else /* HAVE_CORRECT_LINUXINPUT_H */
1878 const struct dinput_device joystick_linuxinput_device
= {
1879 "Wine Linux-input joystick driver",
1886 #endif /* HAVE_CORRECT_LINUXINPUT_H */