1 /* DirectInput Joystick device
3 * Copyright 1998,2000 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
25 #ifdef HAVE_LINUX_INPUT_H
35 #ifdef HAVE_SYS_TIME_H
36 # include <sys/time.h>
38 #include <sys/fcntl.h>
39 #ifdef HAVE_SYS_IOCTL_H
40 # include <sys/ioctl.h>
43 #ifdef HAVE_SYS_ERRNO_H
44 # include <sys/errno.h>
47 #ifdef HAVE_CORRECT_LINUXINPUT_H
49 #ifdef HAVE_LINUX_INPUT_H
50 # include <linux/input.h>
54 #define EVDEVPREFIX "/dev/input/event"
56 #include "wine/debug.h"
57 #include "wine/unicode.h"
63 #include "dinput_private.h"
64 #include "device_private.h"
66 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
68 /* Wine joystick driver object instances */
69 #define WINE_JOYSTICK_AXIS_BASE 0
70 #define WINE_JOYSTICK_BUTTON_BASE 8
72 typedef struct JoystickImpl JoystickImpl
;
73 static ICOM_VTABLE(IDirectInputDevice8A
) JoystickAvt
;
74 static ICOM_VTABLE(IDirectInputDevice8W
) JoystickWvt
;
82 /* The 'parent' DInput */
83 IDirectInputImpl
*dinput
;
85 /* joystick private */
86 /* what range and deadzone the game wants */
87 LONG wantmin
[ABS_MAX
];
88 LONG wantmax
[ABS_MAX
];
91 /* autodetecting ranges per axe by following movement */
92 LONG havemax
[ABS_MAX
];
93 LONG havemin
[ABS_MAX
];
99 LPDIDEVICEOBJECTDATA data_queue
;
100 int queue_head
, queue_tail
, queue_len
;
103 /* data returned by the EVIOCGABS() ioctl */
104 int axes
[ABS_MAX
+1][5];
109 #define AXE_ABSFUZZ 3
110 #define AXE_ABSFLAT 4
113 /* data returned by EVIOCGBIT for EV_ABS and EV_KEY */
114 BYTE absbits
[(ABS_MAX
+7)/8];
115 BYTE keybits
[(KEY_MAX
+7)/8];
118 /* This GUID is slightly different from the linux joystick one. Take note. */
119 static GUID DInput_Wine_Joystick_GUID
= { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
123 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
126 #define test_bit(arr,bit) (((BYTE*)arr)[bit>>3]&(1<<(bit&7)))
128 static int joydev_have(void)
135 BYTE absbits
[(ABS_MAX
+7)/8],keybits
[(KEY_MAX
+7)/8];
137 sprintf(buf
,EVDEVPREFIX
"%d",i
);
138 if (-1!=(fd
=open(buf
,O_RDONLY
))) {
139 if (-1==ioctl(fd
,EVIOCGBIT(EV_ABS
,sizeof(absbits
)),absbits
)) {
140 perror("EVIOCGBIT EV_ABS");
144 if (-1==ioctl(fd
,EVIOCGBIT(EV_KEY
,sizeof(keybits
)),keybits
)) {
145 perror("EVIOCGBIT EV_KEY");
149 /* A true joystick has at least axis X and Y, and at least 1
150 * button. copied from linux/drivers/input/joydev.c */
151 if (test_bit(absbits
,ABS_X
) && test_bit(absbits
,ABS_Y
) &&
152 ( test_bit(keybits
,BTN_TRIGGER
) ||
153 test_bit(keybits
,BTN_A
) ||
154 test_bit(keybits
,BTN_1
)
157 FIXME("found a joystick at %s!\n",buf
);
162 if (havejoy
|| (errno
==ENODEV
))
168 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, int version
)
172 if ((dwDevType
!= 0) && (GET_DIDEVICE_TYPE(dwDevType
) != DIDEVTYPE_JOYSTICK
))
175 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
178 havejoy
= joydev_have();
183 TRACE("Enumerating the linuxinput Joystick device\n");
185 /* Return joystick */
186 lpddi
->guidInstance
= GUID_Joystick
;
187 lpddi
->guidProduct
= DInput_Wine_Joystick_GUID
;
189 lpddi
->guidFFDriver
= GUID_NULL
;
190 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<<8);
192 strcpy(lpddi
->tszInstanceName
, "Joystick");
193 /* ioctl JSIOCGNAME(len) */
194 strcpy(lpddi
->tszProductName
, "Wine Joystick");
198 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, int version
)
202 if ((dwDevType
!= 0) && (GET_DIDEVICE_TYPE(dwDevType
) != DIDEVTYPE_JOYSTICK
))
205 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
208 havejoy
= joydev_have();
213 TRACE("Enumerating the linuxinput Joystick device\n");
215 /* Return joystick */
216 lpddi
->guidInstance
= GUID_Joystick
;
217 lpddi
->guidProduct
= DInput_Wine_Joystick_GUID
;
219 lpddi
->guidFFDriver
= GUID_NULL
;
220 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<<8);
222 MultiByteToWideChar(CP_ACP
, 0, "Joystick", -1, lpddi
->tszInstanceName
, MAX_PATH
);
223 /* ioctl JSIOCGNAME(len) */
224 MultiByteToWideChar(CP_ACP
, 0, "Wine Joystick", -1, lpddi
->tszProductName
, MAX_PATH
);
228 static JoystickImpl
*alloc_device(REFGUID rguid
, LPVOID jvt
, IDirectInputImpl
*dinput
)
230 JoystickImpl
* newDevice
;
233 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(JoystickImpl
));
234 newDevice
->lpVtbl
= jvt
;
236 newDevice
->joyfd
= -1;
237 newDevice
->dinput
= dinput
;
238 memcpy(&(newDevice
->guid
),rguid
,sizeof(*rguid
));
239 for (i
=0;i
<ABS_MAX
;i
++) {
240 newDevice
->wantmin
[i
] = -32768;
241 newDevice
->wantmax
[i
] = 32767;
242 newDevice
->deadz
[i
] = 1024; /* guessing */
247 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
251 havejoy
= joydev_have();
254 return DIERR_DEVICENOTREG
;
256 if ((IsEqualGUID(&GUID_Joystick
,rguid
)) ||
257 (IsEqualGUID(&DInput_Wine_Joystick_GUID
,rguid
))) {
258 if ((riid
== NULL
) ||
259 IsEqualGUID(&IID_IDirectInputDeviceA
,riid
) ||
260 IsEqualGUID(&IID_IDirectInputDevice2A
,riid
) ||
261 IsEqualGUID(&IID_IDirectInputDevice7A
,riid
) ||
262 IsEqualGUID(&IID_IDirectInputDevice8A
,riid
)) {
263 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &JoystickAvt
, dinput
);
264 TRACE("Creating a Joystick device (%p)\n", *pdev
);
267 return DIERR_NOINTERFACE
;
270 return DIERR_DEVICENOTREG
;
274 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
278 havejoy
= joydev_have();
281 return DIERR_DEVICENOTREG
;
283 if ((IsEqualGUID(&GUID_Joystick
,rguid
)) ||
284 (IsEqualGUID(&DInput_Wine_Joystick_GUID
,rguid
))) {
285 if ((riid
== NULL
) ||
286 IsEqualGUID(&IID_IDirectInputDeviceW
,riid
) ||
287 IsEqualGUID(&IID_IDirectInputDevice2W
,riid
) ||
288 IsEqualGUID(&IID_IDirectInputDevice7W
,riid
) ||
289 IsEqualGUID(&IID_IDirectInputDevice8W
,riid
)) {
290 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &JoystickWvt
, dinput
);
291 TRACE("Creating a Joystick device (%p)\n", *pdev
);
294 return DIERR_NOINTERFACE
;
297 return DIERR_DEVICENOTREG
;
300 static dinput_device joydev
= {
304 joydev_create_deviceA
,
305 joydev_create_deviceW
308 DECL_GLOBAL_CONSTRUCTOR(joydev_register
) { dinput_register_device(&joydev
); }
310 /******************************************************************************
313 static ULONG WINAPI
JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface
)
315 ICOM_THIS(JoystickImpl
,iface
);
321 /* Free the data queue */
322 if (This
->data_queue
!= NULL
)
323 HeapFree(GetProcessHeap(),0,This
->data_queue
);
325 /* Free the DataFormat */
326 HeapFree(GetProcessHeap(), 0, This
->df
);
328 HeapFree(GetProcessHeap(),0,This
);
332 /******************************************************************************
333 * SetDataFormat : the application can choose the format of the data
334 * the device driver sends back with GetDeviceState.
336 static HRESULT WINAPI
JoystickAImpl_SetDataFormat(
337 LPDIRECTINPUTDEVICE8A iface
,LPCDIDATAFORMAT df
340 ICOM_THIS(JoystickImpl
,iface
);
343 TRACE("(this=%p,%p)\n",This
,df
);
345 TRACE("(df.dwSize=%ld)\n",df
->dwSize
);
346 TRACE("(df.dwObjsize=%ld)\n",df
->dwObjSize
);
347 TRACE("(df.dwFlags=0x%08lx)\n",df
->dwFlags
);
348 TRACE("(df.dwDataSize=%ld)\n",df
->dwDataSize
);
349 TRACE("(df.dwNumObjs=%ld)\n",df
->dwNumObjs
);
351 for (i
=0;i
<df
->dwNumObjs
;i
++) {
352 TRACE("df.rgodf[%d].guid %s (%p)\n",i
,debugstr_guid(df
->rgodf
[i
].pguid
), df
->rgodf
[i
].pguid
);
353 TRACE("df.rgodf[%d].dwOfs %ld\n",i
,df
->rgodf
[i
].dwOfs
);
354 TRACE("dwType 0x%02x,dwInstance %d\n",DIDFT_GETTYPE(df
->rgodf
[i
].dwType
),DIDFT_GETINSTANCE(df
->rgodf
[i
].dwType
));
355 TRACE("df.rgodf[%d].dwFlags 0x%08lx\n",i
,df
->rgodf
[i
].dwFlags
);
358 /* Store the new data format */
359 This
->df
= HeapAlloc(GetProcessHeap(),0,df
->dwSize
);
360 memcpy(This
->df
, df
, df
->dwSize
);
361 This
->df
->rgodf
= HeapAlloc(GetProcessHeap(),0,df
->dwNumObjs
*df
->dwObjSize
);
362 memcpy(This
->df
->rgodf
,df
->rgodf
,df
->dwNumObjs
*df
->dwObjSize
);
367 /******************************************************************************
368 * Acquire : gets exclusive control of the joystick
370 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
373 ICOM_THIS(JoystickImpl
,iface
);
376 TRACE("(this=%p)\n",This
);
380 sprintf(buf
,EVDEVPREFIX
"%d",i
);
381 if (-1==(This
->joyfd
=open(buf
,O_RDONLY
))) {
383 return DIERR_NOTFOUND
;
387 if ((-1!=ioctl(This
->joyfd
,EVIOCGBIT(EV_ABS
,sizeof(This
->absbits
)),This
->absbits
)) &&
388 (-1!=ioctl(This
->joyfd
,EVIOCGBIT(EV_KEY
,sizeof(This
->keybits
)),This
->keybits
)) &&
389 (test_bit(This
->absbits
,ABS_X
) && test_bit(This
->absbits
,ABS_Y
) &&
390 (test_bit(This
->keybits
,BTN_TRIGGER
)||
391 test_bit(This
->keybits
,BTN_A
) ||
392 test_bit(This
->keybits
,BTN_1
)
401 return DIERR_NOTFOUND
;
403 for (i
=0;i
<ABS_MAX
;i
++) {
404 if (test_bit(This
->absbits
,i
)) {
405 if (-1==ioctl(This
->joyfd
,EVIOCGABS(i
),&(This
->axes
[i
])))
407 FIXME("axe %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
409 This
->axes
[i
][AXE_ABS
],
410 This
->axes
[i
][AXE_ABSMIN
],
411 This
->axes
[i
][AXE_ABSMAX
],
412 This
->axes
[i
][AXE_ABSFUZZ
],
413 This
->axes
[i
][AXE_ABSFLAT
]
415 This
->havemax
[i
] = This
->axes
[i
][AXE_ABSMIN
];
416 This
->havemin
[i
] = This
->axes
[i
][AXE_ABSMAX
];
424 /******************************************************************************
425 * Unacquire : frees the joystick
427 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
429 ICOM_THIS(JoystickImpl
,iface
);
431 TRACE("(this=%p)\n",This
);
432 if (This
->joyfd
!=-1) {
442 * This maps the read value (from the input event) to a value in the
443 * 'wanted' range. It also autodetects the possible range of the axe and
444 * adapts values accordingly.
447 map_axis(JoystickImpl
* This
, int axis
, int val
) {
448 int xmid
= This
->axes
[axis
][AXE_ABS
];
449 int xmin
= This
->axes
[axis
][AXE_ABSMIN
];
450 int xmax
= This
->axes
[axis
][AXE_ABSMAX
];
451 int hmax
= This
->havemax
[axis
];
452 int hmin
= This
->havemin
[axis
];
453 int wmin
= This
->wantmin
[axis
];
454 int wmax
= This
->wantmax
[axis
];
457 if (val
> hmax
) This
->havemax
[axis
] = hmax
= val
;
458 if (val
< hmin
) This
->havemin
[axis
] = hmin
= val
;
460 if (xmin
== xmax
) return val
;
461 if ((hmin
== hmax
) || (hmax
==xmid
) || (hmin
==xmid
)) return val
;
463 /* don't assume total linearity, but linearity starting from a zeropoint */
465 ret
= (val
-xmid
)*((wmax
-wmin
)/2)/(hmax
-xmid
)+0;
467 ret
= (xmid
-val
)*((wmax
-wmin
)/2)/(hmin
-xmid
)+0;
471 /* deadzone doesn't work comfortably enough right now. needs more testing*/
472 if ((ret
> -deadz
/2 ) && (ret
< deadz
/2)) {
473 FIXME("%d in deadzone, return mid.\n",val
);
474 return (wmax
-wmin
)/2+wmin
;
480 static void joy_polldev(JoystickImpl
*This
) {
483 struct input_event ie
;
489 memset(&tv
,0,sizeof(tv
));
491 FD_SET(This
->joyfd
,&readfds
);
493 if (1>select(This
->joyfd
+1,&readfds
,NULL
,NULL
,&tv
))
496 /* we have one event, so we can read */
497 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
500 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
502 case EV_KEY
: /* button */
504 case BTN_TRIGGER
: /* normal flight stick */
505 case BTN_A
: /* gamepad */
506 case BTN_1
: /* generic */
507 GEN_EVENT(DIJOFS_BUTTON(0),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
508 This
->js
.rgbButtons
[0] = ie
.value
?0x80:0x00;
513 GEN_EVENT(DIJOFS_BUTTON(1),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
514 This
->js
.rgbButtons
[1] = ie
.value
?0x80:0x00;
519 GEN_EVENT(DIJOFS_BUTTON(2),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
520 This
->js
.rgbButtons
[2] = ie
.value
?0x80:0x00;
523 FIXME("unhandled joystick axe %x, value %d\n",ie
.code
,ie
.value
);
530 GEN_EVENT(DIJOFS_X
,ie
.value
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
531 This
->js
.lX
= map_axis(This
,0,ie
.value
);
534 GEN_EVENT(DIJOFS_Y
,ie
.value
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
535 This
->js
.lY
= map_axis(This
,1,ie
.value
);
537 GEN_EVENT(DIJOFS_Z
,ie
.value
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
538 This
->js
.lZ
= map_axis(This
,2,ie
.value
);
541 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie
.code
,ie
.value
);
546 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
552 /******************************************************************************
553 * GetDeviceState : returns the "state" of the joystick.
556 static HRESULT WINAPI
JoystickAImpl_GetDeviceState(
557 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
559 ICOM_THIS(JoystickImpl
,iface
);
563 TRACE("(this=%p,0x%08lx,%p)\n",This
,len
,ptr
);
564 if ((len
!= sizeof(DIJOYSTATE
)) && (len
!= sizeof(DIJOYSTATE2
))) {
565 FIXME("len %ld is not sizeof(DIJOYSTATE) or DIJOYSTATE2, unsupported format.\n",len
);
568 memcpy(ptr
,&(This
->js
),len
);
569 This
->queue_head
= 0;
570 This
->queue_tail
= 0;
574 /******************************************************************************
575 * GetDeviceData : gets buffered input data.
577 static HRESULT WINAPI
JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface
,
579 LPDIDEVICEOBJECTDATA dod
,
583 ICOM_THIS(JoystickImpl
,iface
);
585 FIXME("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx),STUB!\n",This
,dodsize
,*entries
,flags
);
588 if (flags
& DIGDD_PEEK
)
589 FIXME("DIGDD_PEEK\n");
597 /******************************************************************************
598 * SetProperty : change input device properties
600 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
604 ICOM_THIS(JoystickImpl
,iface
);
606 FIXME("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
607 FIXME("ph.dwSize = %ld, ph.dwHeaderSize =%ld, ph.dwObj = %ld, ph.dwHow= %ld\n",ph
->dwSize
, ph
->dwHeaderSize
,ph
->dwObj
,ph
->dwHow
);
609 if (!HIWORD(rguid
)) {
610 switch ((DWORD
)rguid
) {
611 case (DWORD
) DIPROP_BUFFERSIZE
: {
612 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
614 FIXME("buffersize = %ld\n",pd
->dwData
);
617 case (DWORD
)DIPROP_RANGE
: {
618 LPCDIPROPRANGE pr
= (LPCDIPROPRANGE
)ph
;
620 FIXME("proprange(%ld,%ld)\n",pr
->lMin
,pr
->lMax
);
628 This
->wantmin
[ph
->dwObj
/4] = pr
->lMin
;
629 This
->wantmax
[ph
->dwObj
/4] = pr
->lMax
;
632 FIXME("setting proprange %ld - %ld for dwObj %ld\n",pr
->lMin
,pr
->lMax
,ph
->dwObj
);
636 case (DWORD
)DIPROP_DEADZONE
: {
637 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
639 FIXME("setting deadzone(%ld)\n",pd
->dwData
);
640 This
->deadz
[ph
->dwObj
/4] = pd
->dwData
;
644 FIXME("Unknown type %ld (%s)\n",(DWORD
)rguid
,debugstr_guid(rguid
));
651 /******************************************************************************
652 * SetEventNotification : specifies event to be sent on state change
654 static HRESULT WINAPI
JoystickAImpl_SetEventNotification(
655 LPDIRECTINPUTDEVICE8A iface
, HANDLE hnd
657 ICOM_THIS(JoystickImpl
,iface
);
659 TRACE("(this=%p,0x%08lx)\n",This
,(DWORD
)hnd
);
664 static HRESULT WINAPI
JoystickAImpl_GetCapabilities(
665 LPDIRECTINPUTDEVICE8A iface
,
666 LPDIDEVCAPS lpDIDevCaps
)
668 ICOM_THIS(JoystickImpl
,iface
);
669 int xfd
= This
->joyfd
;
673 TRACE("%p->(%p)\n",iface
,lpDIDevCaps
);
675 /* yes, games assume we return something, even if unacquired */
676 JoystickAImpl_Acquire(iface
);
680 lpDIDevCaps
->dwFlags
= DIDC_ATTACHED
;
681 lpDIDevCaps
->dwDevType
= DIDEVTYPE_JOYSTICK
;
684 for (i
=0;i
<ABS_MAX
;i
++) if (test_bit(This
->absbits
,i
)) axes
++;
686 for (i
=0;i
<KEY_MAX
;i
++) if (test_bit(This
->keybits
,i
)) buttons
++;
688 lpDIDevCaps
->dwAxes
= axes
;
689 lpDIDevCaps
->dwButtons
= buttons
;
692 JoystickAImpl_Unacquire(iface
);
697 static HRESULT WINAPI
JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface
) {
698 ICOM_THIS(JoystickImpl
,iface
);
705 /******************************************************************************
706 * EnumObjects : enumerate the different buttons and axis...
708 static HRESULT WINAPI
JoystickAImpl_EnumObjects(
709 LPDIRECTINPUTDEVICE8A iface
,
710 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback
,
714 ICOM_THIS(JoystickImpl
,iface
);
715 DIDEVICEOBJECTINSTANCEA ddoi
;
716 int xfd
= This
->joyfd
;
719 TRACE("(this=%p,%p,%p,%08lx)\n", This
, lpCallback
, lpvRef
, dwFlags
);
720 if (TRACE_ON(dinput
)) {
721 TRACE(" - flags = ");
722 _dump_EnumObjects_flags(dwFlags
);
726 if (xfd
== -1) return DIERR_NOTACQUIRED
;
728 /* Only the fields till dwFFMaxForce are relevant */
729 ddoi
.dwSize
= FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA
, dwFFMaxForce
);
731 /* For the joystick, do as is done in the GetCapabilities function */
732 /* FIXME: needs more items */
733 if ((dwFlags
== DIDFT_ALL
) ||
734 (dwFlags
& DIDFT_AXIS
)) {
737 for (i
= 0; i
< ABS_MAX
; i
++) {
738 if (!test_bit(This
->absbits
,i
)) continue;
742 ddoi
.guidType
= GUID_XAxis
;
743 ddoi
.dwOfs
= DIJOFS_X
;
746 ddoi
.guidType
= GUID_YAxis
;
747 ddoi
.dwOfs
= DIJOFS_Y
;
750 ddoi
.guidType
= GUID_ZAxis
;
751 ddoi
.dwOfs
= DIJOFS_Z
;
754 ddoi
.guidType
= GUID_RxAxis
;
755 ddoi
.dwOfs
= DIJOFS_RX
;
758 ddoi
.guidType
= GUID_RyAxis
;
759 ddoi
.dwOfs
= DIJOFS_RY
;
762 ddoi
.guidType
= GUID_RzAxis
;
763 ddoi
.dwOfs
= DIJOFS_RZ
;
766 ddoi
.guidType
= GUID_Slider
;
767 ddoi
.dwOfs
= DIJOFS_SLIDER(0);
770 FIXME("unhandled abs axis %d, ignoring!\n",i
);
772 ddoi
.dwType
= DIDFT_MAKEINSTANCE((1<<i
) << WINE_JOYSTICK_AXIS_BASE
) | DIDFT_ABSAXIS
;
773 sprintf(ddoi
.tszName
, "%d-Axis", i
);
774 _dump_OBJECTINSTANCEA(&ddoi
);
775 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
)
780 if ((dwFlags
== DIDFT_ALL
) ||
781 (dwFlags
& DIDFT_BUTTON
)) {
784 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
786 ddoi
.guidType
= GUID_Button
;
788 for (i
= 0; i
< KEY_MAX
; i
++) {
789 if (!test_bit(This
->keybits
,i
)) continue;
795 ddoi
.dwOfs
= DIJOFS_BUTTON(0);
796 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 0) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
801 ddoi
.dwOfs
= DIJOFS_BUTTON(1);
802 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 1) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
807 ddoi
.dwOfs
= DIJOFS_BUTTON(2);
808 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 2) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
813 ddoi
.dwOfs
= DIJOFS_BUTTON(3);
814 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 3) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
819 ddoi
.dwOfs
= DIJOFS_BUTTON(4);
820 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 4) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
825 ddoi
.dwOfs
= DIJOFS_BUTTON(5);
826 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 5) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
831 ddoi
.dwOfs
= DIJOFS_BUTTON(6);
832 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 6) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
837 ddoi
.dwOfs
= DIJOFS_BUTTON(7);
838 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 7) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
843 ddoi
.dwOfs
= DIJOFS_BUTTON(8);
844 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 8) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
848 ddoi
.dwOfs
= DIJOFS_BUTTON(9);
849 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 9) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
853 ddoi
.dwOfs
= DIJOFS_BUTTON(10);
854 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 10) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
857 sprintf(ddoi
.tszName
, "%d-Button", i
);
858 _dump_OBJECTINSTANCEA(&ddoi
);
859 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
)
864 if (xfd
!=This
->joyfd
)
870 static HRESULT WINAPI
JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface
,
871 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback
,
875 ICOM_THIS(JoystickImpl
,iface
);
877 device_enumobjects_AtoWcb_data data
;
879 data
.lpCallBack
= lpCallback
;
880 data
.lpvRef
= lpvRef
;
882 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A
) This
, (LPDIENUMDEVICEOBJECTSCALLBACKA
) DIEnumDevicesCallbackAtoW
, (LPVOID
) &data
, dwFlags
);
885 /******************************************************************************
886 * GetProperty : get input device properties
888 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
890 LPDIPROPHEADER pdiph
)
892 ICOM_THIS(JoystickImpl
,iface
);
894 TRACE("(this=%p,%s,%p): stub!\n",
895 iface
, debugstr_guid(rguid
), pdiph
);
897 if (TRACE_ON(dinput
))
898 _dump_DIPROPHEADER(pdiph
);
900 if (!HIWORD(rguid
)) {
901 switch ((DWORD
)rguid
) {
902 case (DWORD
) DIPROP_BUFFERSIZE
: {
903 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
905 TRACE(" return buffersize = %d\n",This
->queue_len
);
906 pd
->dwData
= This
->queue_len
;
910 case (DWORD
) DIPROP_RANGE
: {
911 /* LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph; */
912 if ((pdiph
->dwHow
== DIPH_BYID
) &&
913 (pdiph
->dwObj
& DIDFT_ABSAXIS
)) {
914 /* The app is querying the current range of the axis : return the lMin and lMax values */
915 FIXME("unimplemented axis range query.\n");
922 FIXME("Unknown type %ld (%s)\n",(DWORD
)rguid
,debugstr_guid(rguid
));
931 static ICOM_VTABLE(IDirectInputDevice8A
) JoystickAvt
=
933 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
934 IDirectInputDevice2AImpl_QueryInterface
,
935 IDirectInputDevice2AImpl_AddRef
,
936 JoystickAImpl_Release
,
937 JoystickAImpl_GetCapabilities
,
938 JoystickAImpl_EnumObjects
,
939 JoystickAImpl_GetProperty
,
940 JoystickAImpl_SetProperty
,
941 JoystickAImpl_Acquire
,
942 JoystickAImpl_Unacquire
,
943 JoystickAImpl_GetDeviceState
,
944 JoystickAImpl_GetDeviceData
,
945 JoystickAImpl_SetDataFormat
,
946 JoystickAImpl_SetEventNotification
,
947 IDirectInputDevice2AImpl_SetCooperativeLevel
,
948 IDirectInputDevice2AImpl_GetObjectInfo
,
949 IDirectInputDevice2AImpl_GetDeviceInfo
,
950 IDirectInputDevice2AImpl_RunControlPanel
,
951 IDirectInputDevice2AImpl_Initialize
,
952 IDirectInputDevice2AImpl_CreateEffect
,
953 IDirectInputDevice2AImpl_EnumEffects
,
954 IDirectInputDevice2AImpl_GetEffectInfo
,
955 IDirectInputDevice2AImpl_GetForceFeedbackState
,
956 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
957 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
958 IDirectInputDevice2AImpl_Escape
,
960 IDirectInputDevice2AImpl_SendDeviceData
,
961 IDirectInputDevice7AImpl_EnumEffectsInFile
,
962 IDirectInputDevice7AImpl_WriteEffectToFile
,
963 IDirectInputDevice8AImpl_BuildActionMap
,
964 IDirectInputDevice8AImpl_SetActionMap
,
965 IDirectInputDevice8AImpl_GetImageInfo
968 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
969 # define XCAST(fun) (typeof(JoystickWvt.fun))
971 # define XCAST(fun) (void*)
974 static ICOM_VTABLE(IDirectInputDevice8W
) JoystickWvt
=
976 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
977 IDirectInputDevice2WImpl_QueryInterface
,
978 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
979 XCAST(Release
)JoystickAImpl_Release
,
980 XCAST(GetCapabilities
)JoystickAImpl_GetCapabilities
,
981 JoystickWImpl_EnumObjects
,
982 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
983 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
984 XCAST(Acquire
)JoystickAImpl_Acquire
,
985 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
986 XCAST(GetDeviceState
)JoystickAImpl_GetDeviceState
,
987 XCAST(GetDeviceData
)JoystickAImpl_GetDeviceData
,
988 XCAST(SetDataFormat
)JoystickAImpl_SetDataFormat
,
989 XCAST(SetEventNotification
)JoystickAImpl_SetEventNotification
,
990 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
991 IDirectInputDevice2WImpl_GetObjectInfo
,
992 IDirectInputDevice2WImpl_GetDeviceInfo
,
993 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
994 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
995 XCAST(CreateEffect
)IDirectInputDevice2AImpl_CreateEffect
,
996 IDirectInputDevice2WImpl_EnumEffects
,
997 IDirectInputDevice2WImpl_GetEffectInfo
,
998 XCAST(GetForceFeedbackState
)IDirectInputDevice2AImpl_GetForceFeedbackState
,
999 XCAST(SendForceFeedbackCommand
)IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
1000 XCAST(EnumCreatedEffectObjects
)IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
1001 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1002 XCAST(Poll
)JoystickAImpl_Poll
,
1003 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1004 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1005 IDirectInputDevice7WImpl_WriteEffectToFile
,
1006 IDirectInputDevice8WImpl_BuildActionMap
,
1007 IDirectInputDevice8WImpl_SetActionMap
,
1008 IDirectInputDevice8WImpl_GetImageInfo
1012 #endif /* HAVE_LINUX_INPUT_H */