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) {
440 * This maps the read value (from the input event) to a value in the
441 * 'wanted' range. It also autodetects the possible range of the axe and
442 * adapts values accordingly.
445 map_axis(JoystickImpl
* This
, int axis
, int val
) {
446 int xmid
= This
->axes
[axis
][AXE_ABS
];
447 int xmin
= This
->axes
[axis
][AXE_ABSMIN
];
448 int xmax
= This
->axes
[axis
][AXE_ABSMAX
];
449 int hmax
= This
->havemax
[axis
];
450 int hmin
= This
->havemin
[axis
];
451 int wmin
= This
->wantmin
[axis
];
452 int wmax
= This
->wantmax
[axis
];
455 if (val
> hmax
) This
->havemax
[axis
] = hmax
= val
;
456 if (val
< hmin
) This
->havemin
[axis
] = hmin
= val
;
458 if (xmin
== xmax
) return val
;
459 if ((hmin
== hmax
) || (hmax
==xmid
) || (hmin
==xmid
)) return val
;
461 /* dont assume total linearity, but linearity starting from a zeropoint */
463 ret
= (val
-xmid
)*((wmax
-wmin
)/2)/(hmax
-xmid
)+0;
465 ret
= (xmid
-val
)*((wmax
-wmin
)/2)/(hmin
-xmid
)+0;
469 /* deadzone doesn't work comfortably enough right now. needs more testing*/
470 if ((ret
> -deadz
/2 ) && (ret
< deadz
/2)) {
471 FIXME("%d in deadzone, return mid.\n",val
);
472 return (wmax
-wmin
)/2+wmin
;
478 static void joy_polldev(JoystickImpl
*This
) {
481 struct input_event ie
;
487 memset(&tv
,0,sizeof(tv
));
489 FD_SET(This
->joyfd
,&readfds
);
491 if (1>select(This
->joyfd
+1,&readfds
,NULL
,NULL
,&tv
))
494 /* we have one event, so we can read */
495 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
498 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
500 case EV_KEY
: /* button */
502 case BTN_TRIGGER
: /* normal flight stick */
503 case BTN_A
: /* gamepad */
504 case BTN_1
: /* generic */
505 GEN_EVENT(DIJOFS_BUTTON(0),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
506 This
->js
.rgbButtons
[0] = ie
.value
?0x80:0x00;
511 GEN_EVENT(DIJOFS_BUTTON(1),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
512 This
->js
.rgbButtons
[1] = ie
.value
?0x80:0x00;
517 GEN_EVENT(DIJOFS_BUTTON(2),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
518 This
->js
.rgbButtons
[2] = ie
.value
?0x80:0x00;
521 FIXME("unhandled joystick axe %x, value %d\n",ie
.code
,ie
.value
);
528 GEN_EVENT(DIJOFS_X
,ie
.value
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
529 This
->js
.lX
= map_axis(This
,0,ie
.value
);
532 GEN_EVENT(DIJOFS_Y
,ie
.value
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
533 This
->js
.lY
= map_axis(This
,1,ie
.value
);
535 GEN_EVENT(DIJOFS_Z
,ie
.value
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
536 This
->js
.lZ
= map_axis(This
,2,ie
.value
);
539 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie
.code
,ie
.value
);
544 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
550 /******************************************************************************
551 * GetDeviceState : returns the "state" of the joystick.
554 static HRESULT WINAPI
JoystickAImpl_GetDeviceState(
555 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
557 ICOM_THIS(JoystickImpl
,iface
);
561 TRACE("(this=%p,0x%08lx,%p)\n",This
,len
,ptr
);
562 if (len
!= sizeof(DIJOYSTATE
)) {
563 FIXME("len %ld is not sizeof(DIJOYSTATE), unsupported format.\n",len
);
565 memcpy(ptr
,&(This
->js
),len
);
566 This
->queue_head
= 0;
567 This
->queue_tail
= 0;
571 /******************************************************************************
572 * GetDeviceData : gets buffered input data.
574 static HRESULT WINAPI
JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface
,
576 LPDIDEVICEOBJECTDATA dod
,
580 ICOM_THIS(JoystickImpl
,iface
);
582 FIXME("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx),STUB!\n",This
,dodsize
,*entries
,flags
);
585 if (flags
& DIGDD_PEEK
)
586 FIXME("DIGDD_PEEK\n");
594 /******************************************************************************
595 * SetProperty : change input device properties
597 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
601 ICOM_THIS(JoystickImpl
,iface
);
603 FIXME("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
604 FIXME("ph.dwSize = %ld, ph.dwHeaderSize =%ld, ph.dwObj = %ld, ph.dwHow= %ld\n",ph
->dwSize
, ph
->dwHeaderSize
,ph
->dwObj
,ph
->dwHow
);
606 if (!HIWORD(rguid
)) {
607 switch ((DWORD
)rguid
) {
608 case (DWORD
) DIPROP_BUFFERSIZE
: {
609 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
611 FIXME("buffersize = %ld\n",pd
->dwData
);
614 case (DWORD
)DIPROP_RANGE
: {
615 LPCDIPROPRANGE pr
= (LPCDIPROPRANGE
)ph
;
617 FIXME("proprange(%ld,%ld)\n",pr
->lMin
,pr
->lMax
);
625 This
->wantmin
[ph
->dwObj
/4] = pr
->lMin
;
626 This
->wantmax
[ph
->dwObj
/4] = pr
->lMax
;
629 FIXME("setting proprange %ld - %ld for dwObj %ld\n",pr
->lMin
,pr
->lMax
,ph
->dwObj
);
633 case (DWORD
)DIPROP_DEADZONE
: {
634 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
636 FIXME("setting deadzone(%ld)\n",pd
->dwData
);
637 This
->deadz
[ph
->dwObj
/4] = pd
->dwData
;
641 FIXME("Unknown type %ld (%s)\n",(DWORD
)rguid
,debugstr_guid(rguid
));
648 /******************************************************************************
649 * SetEventNotification : specifies event to be sent on state change
651 static HRESULT WINAPI
JoystickAImpl_SetEventNotification(
652 LPDIRECTINPUTDEVICE8A iface
, HANDLE hnd
654 ICOM_THIS(JoystickImpl
,iface
);
656 TRACE("(this=%p,0x%08lx)\n",This
,(DWORD
)hnd
);
661 static HRESULT WINAPI
JoystickAImpl_GetCapabilities(
662 LPDIRECTINPUTDEVICE8A iface
,
663 LPDIDEVCAPS lpDIDevCaps
)
665 ICOM_THIS(JoystickImpl
,iface
);
666 int xfd
= This
->joyfd
;
670 TRACE("%p->(%p)\n",iface
,lpDIDevCaps
);
672 /* yes, games assume we return something, even if unacquired */
673 JoystickAImpl_Acquire(iface
);
677 lpDIDevCaps
->dwFlags
= DIDC_ATTACHED
;
678 lpDIDevCaps
->dwDevType
= DIDEVTYPE_JOYSTICK
;
681 for (i
=0;i
<ABS_MAX
;i
++) if (test_bit(This
->absbits
,i
)) axes
++;
683 for (i
=0;i
<KEY_MAX
;i
++) if (test_bit(This
->keybits
,i
)) buttons
++;
685 lpDIDevCaps
->dwAxes
= axes
;
686 lpDIDevCaps
->dwButtons
= buttons
;
689 JoystickAImpl_Unacquire(iface
);
694 static HRESULT WINAPI
JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface
) {
695 ICOM_THIS(JoystickImpl
,iface
);
702 /******************************************************************************
703 * EnumObjects : enumerate the different buttons and axis...
705 static HRESULT WINAPI
JoystickAImpl_EnumObjects(
706 LPDIRECTINPUTDEVICE8A iface
,
707 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback
,
711 ICOM_THIS(JoystickImpl
,iface
);
712 DIDEVICEOBJECTINSTANCEA ddoi
;
713 int xfd
= This
->joyfd
;
716 TRACE("(this=%p,%p,%p,%08lx)\n", This
, lpCallback
, lpvRef
, dwFlags
);
717 if (TRACE_ON(dinput
)) {
718 TRACE(" - flags = ");
719 _dump_EnumObjects_flags(dwFlags
);
723 if (xfd
== -1) return DIERR_NOTACQUIRED
;
725 /* Only the fields till dwFFMaxForce are relevant */
726 ddoi
.dwSize
= FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA
, dwFFMaxForce
);
728 /* For the joystick, do as is done in the GetCapabilities function */
729 /* FIXME: needs more items */
730 if ((dwFlags
== DIDFT_ALL
) ||
731 (dwFlags
& DIDFT_AXIS
)) {
734 for (i
= 0; i
< ABS_MAX
; i
++) {
735 if (!test_bit(This
->absbits
,i
)) continue;
739 ddoi
.guidType
= GUID_XAxis
;
740 ddoi
.dwOfs
= DIJOFS_X
;
743 ddoi
.guidType
= GUID_YAxis
;
744 ddoi
.dwOfs
= DIJOFS_Y
;
747 ddoi
.guidType
= GUID_ZAxis
;
748 ddoi
.dwOfs
= DIJOFS_Z
;
751 ddoi
.guidType
= GUID_RxAxis
;
752 ddoi
.dwOfs
= DIJOFS_RX
;
755 ddoi
.guidType
= GUID_RyAxis
;
756 ddoi
.dwOfs
= DIJOFS_RY
;
759 ddoi
.guidType
= GUID_RzAxis
;
760 ddoi
.dwOfs
= DIJOFS_RZ
;
763 ddoi
.guidType
= GUID_Slider
;
764 ddoi
.dwOfs
= DIJOFS_SLIDER(0);
767 FIXME("unhandled abs axis %d, ignoring!\n",i
);
769 ddoi
.dwType
= DIDFT_MAKEINSTANCE((1<<i
) << WINE_JOYSTICK_AXIS_BASE
) | DIDFT_ABSAXIS
;
770 sprintf(ddoi
.tszName
, "%d-Axis", i
);
771 _dump_OBJECTINSTANCEA(&ddoi
);
772 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
)
777 if ((dwFlags
== DIDFT_ALL
) ||
778 (dwFlags
& DIDFT_BUTTON
)) {
781 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
783 ddoi
.guidType
= GUID_Button
;
785 for (i
= 0; i
< KEY_MAX
; i
++) {
786 if (!test_bit(This
->keybits
,i
)) continue;
792 ddoi
.dwOfs
= DIJOFS_BUTTON(0);
793 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 0) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
798 ddoi
.dwOfs
= DIJOFS_BUTTON(1);
799 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 1) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
804 ddoi
.dwOfs
= DIJOFS_BUTTON(2);
805 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 2) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
810 ddoi
.dwOfs
= DIJOFS_BUTTON(3);
811 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 3) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
816 ddoi
.dwOfs
= DIJOFS_BUTTON(4);
817 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 4) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
822 ddoi
.dwOfs
= DIJOFS_BUTTON(5);
823 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 5) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
828 ddoi
.dwOfs
= DIJOFS_BUTTON(6);
829 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 6) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
834 ddoi
.dwOfs
= DIJOFS_BUTTON(7);
835 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 7) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
840 ddoi
.dwOfs
= DIJOFS_BUTTON(8);
841 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 8) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
845 ddoi
.dwOfs
= DIJOFS_BUTTON(9);
846 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 9) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
850 ddoi
.dwOfs
= DIJOFS_BUTTON(10);
851 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 10) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
854 sprintf(ddoi
.tszName
, "%d-Button", i
);
855 _dump_OBJECTINSTANCEA(&ddoi
);
856 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
)
861 if (xfd
!=This
->joyfd
)
867 static HRESULT WINAPI
JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface
,
868 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback
,
872 ICOM_THIS(JoystickImpl
,iface
);
874 device_enumobjects_AtoWcb_data data
;
876 data
.lpCallBack
= lpCallback
;
877 data
.lpvRef
= lpvRef
;
879 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A
) This
, (LPDIENUMDEVICEOBJECTSCALLBACKA
) DIEnumDevicesCallbackAtoW
, (LPVOID
) &data
, dwFlags
);
882 /******************************************************************************
883 * GetProperty : get input device properties
885 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
887 LPDIPROPHEADER pdiph
)
889 ICOM_THIS(JoystickImpl
,iface
);
891 TRACE("(this=%p,%s,%p): stub!\n",
892 iface
, debugstr_guid(rguid
), pdiph
);
894 if (TRACE_ON(dinput
))
895 _dump_DIPROPHEADER(pdiph
);
897 if (!HIWORD(rguid
)) {
898 switch ((DWORD
)rguid
) {
899 case (DWORD
) DIPROP_BUFFERSIZE
: {
900 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
902 TRACE(" return buffersize = %d\n",This
->queue_len
);
903 pd
->dwData
= This
->queue_len
;
907 case (DWORD
) DIPROP_RANGE
: {
908 /* LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph; */
909 if ((pdiph
->dwHow
== DIPH_BYID
) &&
910 (pdiph
->dwObj
& DIDFT_ABSAXIS
)) {
911 /* The app is querying the current range of the axis : return the lMin and lMax values */
912 FIXME("unimplemented axis range query.\n");
919 FIXME("Unknown type %ld (%s)\n",(DWORD
)rguid
,debugstr_guid(rguid
));
928 static ICOM_VTABLE(IDirectInputDevice8A
) JoystickAvt
=
930 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
931 IDirectInputDevice2AImpl_QueryInterface
,
932 IDirectInputDevice2AImpl_AddRef
,
933 JoystickAImpl_Release
,
934 JoystickAImpl_GetCapabilities
,
935 JoystickAImpl_EnumObjects
,
936 JoystickAImpl_GetProperty
,
937 JoystickAImpl_SetProperty
,
938 JoystickAImpl_Acquire
,
939 JoystickAImpl_Unacquire
,
940 JoystickAImpl_GetDeviceState
,
941 JoystickAImpl_GetDeviceData
,
942 JoystickAImpl_SetDataFormat
,
943 JoystickAImpl_SetEventNotification
,
944 IDirectInputDevice2AImpl_SetCooperativeLevel
,
945 IDirectInputDevice2AImpl_GetObjectInfo
,
946 IDirectInputDevice2AImpl_GetDeviceInfo
,
947 IDirectInputDevice2AImpl_RunControlPanel
,
948 IDirectInputDevice2AImpl_Initialize
,
949 IDirectInputDevice2AImpl_CreateEffect
,
950 IDirectInputDevice2AImpl_EnumEffects
,
951 IDirectInputDevice2AImpl_GetEffectInfo
,
952 IDirectInputDevice2AImpl_GetForceFeedbackState
,
953 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
954 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
955 IDirectInputDevice2AImpl_Escape
,
957 IDirectInputDevice2AImpl_SendDeviceData
,
958 IDirectInputDevice7AImpl_EnumEffectsInFile
,
959 IDirectInputDevice7AImpl_WriteEffectToFile
,
960 IDirectInputDevice8AImpl_BuildActionMap
,
961 IDirectInputDevice8AImpl_SetActionMap
,
962 IDirectInputDevice8AImpl_GetImageInfo
965 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
966 # define XCAST(fun) (typeof(JoystickWvt.fun))
968 # define XCAST(fun) (void*)
971 static ICOM_VTABLE(IDirectInputDevice8W
) JoystickWvt
=
973 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
974 IDirectInputDevice2WImpl_QueryInterface
,
975 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
976 XCAST(Release
)JoystickAImpl_Release
,
977 XCAST(GetCapabilities
)JoystickAImpl_GetCapabilities
,
978 JoystickWImpl_EnumObjects
,
979 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
980 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
981 XCAST(Acquire
)JoystickAImpl_Acquire
,
982 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
983 XCAST(GetDeviceState
)JoystickAImpl_GetDeviceState
,
984 XCAST(GetDeviceData
)JoystickAImpl_GetDeviceData
,
985 XCAST(SetDataFormat
)JoystickAImpl_SetDataFormat
,
986 XCAST(SetEventNotification
)JoystickAImpl_SetEventNotification
,
987 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
988 IDirectInputDevice2WImpl_GetObjectInfo
,
989 IDirectInputDevice2WImpl_GetDeviceInfo
,
990 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
991 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
992 XCAST(CreateEffect
)IDirectInputDevice2AImpl_CreateEffect
,
993 IDirectInputDevice2WImpl_EnumEffects
,
994 IDirectInputDevice2WImpl_GetEffectInfo
,
995 XCAST(GetForceFeedbackState
)IDirectInputDevice2AImpl_GetForceFeedbackState
,
996 XCAST(SendForceFeedbackCommand
)IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
997 XCAST(EnumCreatedEffectObjects
)IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
998 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
999 XCAST(Poll
)JoystickAImpl_Poll
,
1000 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1001 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1002 IDirectInputDevice7WImpl_WriteEffectToFile
,
1003 IDirectInputDevice8WImpl_BuildActionMap
,
1004 IDirectInputDevice8WImpl_SetActionMap
,
1005 IDirectInputDevice8WImpl_GetImageInfo
1009 #endif /* HAVE_LINUX_INPUT_H */