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 IDirectInputDevice8AVtbl JoystickAvt
;
74 static IDirectInputDevice8WVtbl 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 static void fake_current_js_state(JoystickImpl
*ji
);
128 #define test_bit(arr,bit) (((BYTE*)arr)[bit>>3]&(1<<(bit&7)))
130 static int joydev_have(void)
137 BYTE absbits
[(ABS_MAX
+7)/8],keybits
[(KEY_MAX
+7)/8];
139 sprintf(buf
,EVDEVPREFIX
"%d",i
);
140 if (-1!=(fd
=open(buf
,O_RDONLY
))) {
141 if (-1==ioctl(fd
,EVIOCGBIT(EV_ABS
,sizeof(absbits
)),absbits
)) {
142 perror("EVIOCGBIT EV_ABS");
146 if (-1==ioctl(fd
,EVIOCGBIT(EV_KEY
,sizeof(keybits
)),keybits
)) {
147 perror("EVIOCGBIT EV_KEY");
151 /* A true joystick has at least axis X and Y, and at least 1
152 * button. copied from linux/drivers/input/joydev.c */
153 if (test_bit(absbits
,ABS_X
) && test_bit(absbits
,ABS_Y
) &&
154 ( test_bit(keybits
,BTN_TRIGGER
) ||
155 test_bit(keybits
,BTN_A
) ||
156 test_bit(keybits
,BTN_1
)
159 FIXME("found a joystick at %s!\n",buf
);
164 if (havejoy
|| (errno
==ENODEV
))
170 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, int version
)
174 if ((dwDevType
!= 0) && (GET_DIDEVICE_TYPE(dwDevType
) != DIDEVTYPE_JOYSTICK
))
177 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
180 havejoy
= joydev_have();
185 TRACE("Enumerating the linuxinput Joystick device\n");
187 /* Return joystick */
188 lpddi
->guidInstance
= GUID_Joystick
;
189 lpddi
->guidProduct
= DInput_Wine_Joystick_GUID
;
191 lpddi
->guidFFDriver
= GUID_NULL
;
193 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
195 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
197 strcpy(lpddi
->tszInstanceName
, "Joystick");
198 /* ioctl JSIOCGNAME(len) */
199 strcpy(lpddi
->tszProductName
, "Wine Joystick");
203 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, int version
)
207 if ((dwDevType
!= 0) && (GET_DIDEVICE_TYPE(dwDevType
) != DIDEVTYPE_JOYSTICK
))
210 if (dwFlags
& DIEDFL_FORCEFEEDBACK
)
213 havejoy
= joydev_have();
218 TRACE("Enumerating the linuxinput Joystick device\n");
220 /* Return joystick */
221 lpddi
->guidInstance
= GUID_Joystick
;
222 lpddi
->guidProduct
= DInput_Wine_Joystick_GUID
;
224 lpddi
->guidFFDriver
= GUID_NULL
;
225 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<<8);
227 MultiByteToWideChar(CP_ACP
, 0, "Joystick", -1, lpddi
->tszInstanceName
, MAX_PATH
);
228 /* ioctl JSIOCGNAME(len) */
229 MultiByteToWideChar(CP_ACP
, 0, "Wine Joystick", -1, lpddi
->tszProductName
, MAX_PATH
);
233 static JoystickImpl
*alloc_device(REFGUID rguid
, LPVOID jvt
, IDirectInputImpl
*dinput
)
235 JoystickImpl
* newDevice
;
238 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(JoystickImpl
));
239 newDevice
->lpVtbl
= jvt
;
241 newDevice
->joyfd
= -1;
242 newDevice
->dinput
= dinput
;
243 memcpy(&(newDevice
->guid
),rguid
,sizeof(*rguid
));
244 for (i
=0;i
<ABS_MAX
;i
++) {
245 newDevice
->wantmin
[i
] = -32768;
246 newDevice
->wantmax
[i
] = 32767;
248 * direct input defines a default for the deadzone somewhere; but as long
249 * as in map_axis the code for the dead zone is commented out its no
252 newDevice
->deadz
[i
] = 0;
254 fake_current_js_state(newDevice
);
258 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
262 havejoy
= joydev_have();
265 return DIERR_DEVICENOTREG
;
267 if ((IsEqualGUID(&GUID_Joystick
,rguid
)) ||
268 (IsEqualGUID(&DInput_Wine_Joystick_GUID
,rguid
))) {
269 if ((riid
== NULL
) ||
270 IsEqualGUID(&IID_IDirectInputDeviceA
,riid
) ||
271 IsEqualGUID(&IID_IDirectInputDevice2A
,riid
) ||
272 IsEqualGUID(&IID_IDirectInputDevice7A
,riid
) ||
273 IsEqualGUID(&IID_IDirectInputDevice8A
,riid
)) {
274 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &JoystickAvt
, dinput
);
275 TRACE("Creating a Joystick device (%p)\n", *pdev
);
278 return DIERR_NOINTERFACE
;
281 return DIERR_DEVICENOTREG
;
285 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
289 havejoy
= joydev_have();
292 return DIERR_DEVICENOTREG
;
294 if ((IsEqualGUID(&GUID_Joystick
,rguid
)) ||
295 (IsEqualGUID(&DInput_Wine_Joystick_GUID
,rguid
))) {
296 if ((riid
== NULL
) ||
297 IsEqualGUID(&IID_IDirectInputDeviceW
,riid
) ||
298 IsEqualGUID(&IID_IDirectInputDevice2W
,riid
) ||
299 IsEqualGUID(&IID_IDirectInputDevice7W
,riid
) ||
300 IsEqualGUID(&IID_IDirectInputDevice8W
,riid
)) {
301 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &JoystickWvt
, dinput
);
302 TRACE("Creating a Joystick device (%p)\n", *pdev
);
305 return DIERR_NOINTERFACE
;
308 return DIERR_DEVICENOTREG
;
311 static dinput_device joydev
= {
313 "Wine Linux-input joystick driver",
316 joydev_create_deviceA
,
317 joydev_create_deviceW
320 DECL_GLOBAL_CONSTRUCTOR(joydev_register
) { dinput_register_device(&joydev
); }
322 /******************************************************************************
325 static ULONG WINAPI
JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface
)
327 ICOM_THIS(JoystickImpl
,iface
);
333 /* Free the data queue */
334 if (This
->data_queue
!= NULL
)
335 HeapFree(GetProcessHeap(),0,This
->data_queue
);
337 /* Free the DataFormat */
338 HeapFree(GetProcessHeap(), 0, This
->df
);
340 HeapFree(GetProcessHeap(),0,This
);
344 /******************************************************************************
345 * SetDataFormat : the application can choose the format of the data
346 * the device driver sends back with GetDeviceState.
348 static HRESULT WINAPI
JoystickAImpl_SetDataFormat(
349 LPDIRECTINPUTDEVICE8A iface
,LPCDIDATAFORMAT df
352 ICOM_THIS(JoystickImpl
,iface
);
354 TRACE("(this=%p,%p)\n",This
,df
);
356 _dump_DIDATAFORMAT(df
);
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
->havemin
[i
] = This
->axes
[i
][AXE_ABSMIN
];
416 This
->havemax
[i
] = This
->axes
[i
][AXE_ABSMAX
];
421 fake_current_js_state(This
);
426 /******************************************************************************
427 * Unacquire : frees the joystick
429 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
431 ICOM_THIS(JoystickImpl
,iface
);
433 TRACE("(this=%p)\n",This
);
434 if (This
->joyfd
!=-1) {
444 * This maps the read value (from the input event) to a value in the
445 * 'wanted' range. It also autodetects the possible range of the axe and
446 * adapts values accordingly.
449 map_axis(JoystickImpl
* This
, int axis
, int val
) {
450 int xmin
= This
->axes
[axis
][AXE_ABSMIN
];
451 int xmax
= This
->axes
[axis
][AXE_ABSMAX
];
452 int hmax
= This
->havemax
[axis
];
453 int hmin
= This
->havemin
[axis
];
454 int wmin
= This
->wantmin
[axis
];
455 int wmax
= This
->wantmax
[axis
];
458 if (val
> hmax
) This
->havemax
[axis
] = hmax
= val
;
459 if (val
< hmin
) This
->havemin
[axis
] = hmin
= val
;
461 if (xmin
== xmax
) return val
;
463 /* map the value from the hmin-hmax range into the wmin-wmax range */
464 ret
= (val
* (wmax
-wmin
)) / (hmax
-hmin
) + wmin
;
467 /* deadzone doesn't work comfortably enough right now. needs more testing*/
468 if ((ret
> -deadz
/2 ) && (ret
< deadz
/2)) {
469 FIXME("%d in deadzone, return mid.\n",val
);
470 return (wmax
-wmin
)/2+wmin
;
477 * set the current state of the js device as it would be with the middle
480 static void fake_current_js_state(JoystickImpl
*ji
)
482 ji
->js
.lX
= map_axis(ji
, ABS_X
, ji
->axes
[ABS_X
][AXE_ABS
]);
483 ji
->js
.lY
= map_axis(ji
, ABS_Y
, ji
->axes
[ABS_Y
][AXE_ABS
]);
484 ji
->js
.lZ
= map_axis(ji
, ABS_Z
, ji
->axes
[ABS_Z
][AXE_ABS
]);
485 ji
->js
.lRx
= map_axis(ji
, ABS_RX
, ji
->axes
[ABS_RX
][AXE_ABS
]);
486 ji
->js
.lRy
= map_axis(ji
, ABS_RY
, ji
->axes
[ABS_RY
][AXE_ABS
]);
487 ji
->js
.lRz
= map_axis(ji
, ABS_RZ
, ji
->axes
[ABS_RZ
][AXE_ABS
]);
490 static void joy_polldev(JoystickImpl
*This
) {
493 struct input_event ie
;
499 memset(&tv
,0,sizeof(tv
));
501 FD_SET(This
->joyfd
,&readfds
);
503 if (1>select(This
->joyfd
+1,&readfds
,NULL
,NULL
,&tv
))
506 /* we have one event, so we can read */
507 if (sizeof(ie
)!=read(This
->joyfd
,&ie
,sizeof(ie
)))
510 TRACE("input_event: type %d, code %d, value %d\n",ie
.type
,ie
.code
,ie
.value
);
512 case EV_KEY
: /* button */
514 case BTN_TRIGGER
: /* normal flight stick */
515 case BTN_A
: /* gamepad */
516 case BTN_1
: /* generic */
517 This
->js
.rgbButtons
[0] = ie
.value
?0x80:0x00;
518 GEN_EVENT(DIJOFS_BUTTON(0),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
523 This
->js
.rgbButtons
[1] = ie
.value
?0x80:0x00;
524 GEN_EVENT(DIJOFS_BUTTON(1),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
529 This
->js
.rgbButtons
[2] = ie
.value
?0x80:0x00;
530 GEN_EVENT(DIJOFS_BUTTON(2),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
535 This
->js
.rgbButtons
[3] = ie
.value
?0x80:0x00;
536 GEN_EVENT(DIJOFS_BUTTON(3),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
541 This
->js
.rgbButtons
[4] = ie
.value
?0x80:0x00;
542 GEN_EVENT(DIJOFS_BUTTON(4),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
547 This
->js
.rgbButtons
[5] = ie
.value
?0x80:0x00;
548 GEN_EVENT(DIJOFS_BUTTON(5),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
553 This
->js
.rgbButtons
[6] = ie
.value
?0x80:0x00;
554 GEN_EVENT(DIJOFS_BUTTON(6),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
559 This
->js
.rgbButtons
[7] = ie
.value
?0x80:0x00;
560 GEN_EVENT(DIJOFS_BUTTON(7),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
565 This
->js
.rgbButtons
[8] = ie
.value
?0x80:0x00;
566 GEN_EVENT(DIJOFS_BUTTON(8),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
570 This
->js
.rgbButtons
[9] = ie
.value
?0x80:0x00;
571 GEN_EVENT(DIJOFS_BUTTON(9),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
575 This
->js
.rgbButtons
[10] = ie
.value
?0x80:0x00;
576 GEN_EVENT(DIJOFS_BUTTON(10),ie
.value
?0x80:0x0,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
579 FIXME("unhandled joystick button %x, value %d\n",ie
.code
,ie
.value
);
586 This
->js
.lX
= map_axis(This
,ABS_X
,ie
.value
);
587 GEN_EVENT(DIJOFS_X
,This
->js
.lX
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
590 This
->js
.lY
= map_axis(This
,ABS_Y
,ie
.value
);
591 GEN_EVENT(DIJOFS_Y
,This
->js
.lY
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
594 This
->js
.lZ
= map_axis(This
,ABS_Z
,ie
.value
);
595 GEN_EVENT(DIJOFS_Z
,This
->js
.lZ
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
598 This
->js
.lRx
= map_axis(This
,ABS_RX
,ie
.value
);
599 GEN_EVENT(DIJOFS_RX
,This
->js
.lRx
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
602 This
->js
.lRy
= map_axis(This
,ABS_RY
,ie
.value
);
603 GEN_EVENT(DIJOFS_RY
,This
->js
.lRy
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
606 This
->js
.lRz
= map_axis(This
,ABS_RZ
,ie
.value
);
607 GEN_EVENT(DIJOFS_RZ
,This
->js
.lRz
,ie
.time
.tv_usec
,(This
->dinput
->evsequence
)++);
610 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie
.code
,ie
.value
);
615 FIXME("joystick cannot handle type %d event (code %d)\n",ie
.type
,ie
.code
);
621 /******************************************************************************
622 * GetDeviceState : returns the "state" of the joystick.
625 static HRESULT WINAPI
JoystickAImpl_GetDeviceState(
626 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
628 ICOM_THIS(JoystickImpl
,iface
);
632 TRACE("(this=%p,0x%08lx,%p)\n",This
,len
,ptr
);
633 if ((len
!= sizeof(DIJOYSTATE
)) && (len
!= sizeof(DIJOYSTATE2
))) {
634 FIXME("len %ld is not sizeof(DIJOYSTATE) or DIJOYSTATE2, unsupported format.\n",len
);
637 memcpy(ptr
,&(This
->js
),len
);
638 This
->queue_head
= 0;
639 This
->queue_tail
= 0;
643 /******************************************************************************
644 * GetDeviceData : gets buffered input data.
646 static HRESULT WINAPI
JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface
,
648 LPDIDEVICEOBJECTDATA dod
,
652 ICOM_THIS(JoystickImpl
,iface
);
654 FIXME("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx),STUB!\n",This
,dodsize
,*entries
,flags
);
657 if (flags
& DIGDD_PEEK
)
658 FIXME("DIGDD_PEEK\n");
666 /******************************************************************************
667 * SetProperty : change input device properties
669 static HRESULT WINAPI
JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface
,
673 ICOM_THIS(JoystickImpl
,iface
);
675 FIXME("(this=%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
676 FIXME("ph.dwSize = %ld, ph.dwHeaderSize =%ld, ph.dwObj = %ld, ph.dwHow= %ld\n",ph
->dwSize
, ph
->dwHeaderSize
,ph
->dwObj
,ph
->dwHow
);
678 if (!HIWORD(rguid
)) {
679 switch ((DWORD
)rguid
) {
680 case (DWORD
) DIPROP_BUFFERSIZE
: {
681 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
683 FIXME("buffersize = %ld\n",pd
->dwData
);
686 case (DWORD
)DIPROP_RANGE
: {
687 LPCDIPROPRANGE pr
= (LPCDIPROPRANGE
)ph
;
689 FIXME("proprange(%ld,%ld)\n",pr
->lMin
,pr
->lMax
);
697 This
->wantmin
[ph
->dwObj
/4] = pr
->lMin
;
698 This
->wantmax
[ph
->dwObj
/4] = pr
->lMax
;
701 FIXME("setting proprange %ld - %ld for dwObj %ld\n",pr
->lMin
,pr
->lMax
,ph
->dwObj
);
705 case (DWORD
)DIPROP_DEADZONE
: {
706 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
708 FIXME("setting deadzone(%ld)\n",pd
->dwData
);
709 This
->deadz
[ph
->dwObj
/4] = pd
->dwData
;
713 FIXME("Unknown type %ld (%s)\n",(DWORD
)rguid
,debugstr_guid(rguid
));
717 fake_current_js_state(This
);
721 /******************************************************************************
722 * SetEventNotification : specifies event to be sent on state change
724 static HRESULT WINAPI
JoystickAImpl_SetEventNotification(
725 LPDIRECTINPUTDEVICE8A iface
, HANDLE hnd
727 ICOM_THIS(JoystickImpl
,iface
);
729 TRACE("(this=%p,0x%08lx)\n",This
,(DWORD
)hnd
);
734 static HRESULT WINAPI
JoystickAImpl_GetCapabilities(
735 LPDIRECTINPUTDEVICE8A iface
,
736 LPDIDEVCAPS lpDIDevCaps
)
738 ICOM_THIS(JoystickImpl
,iface
);
739 int xfd
= This
->joyfd
;
743 TRACE("%p->(%p)\n",iface
,lpDIDevCaps
);
745 /* yes, games assume we return something, even if unacquired */
746 JoystickAImpl_Acquire(iface
);
750 lpDIDevCaps
->dwFlags
= DIDC_ATTACHED
;
751 lpDIDevCaps
->dwDevType
= DIDEVTYPE_JOYSTICK
;
754 for (i
=0;i
<ABS_MAX
;i
++) if (test_bit(This
->absbits
,i
)) axes
++;
756 for (i
=0;i
<KEY_MAX
;i
++) if (test_bit(This
->keybits
,i
)) buttons
++;
758 lpDIDevCaps
->dwAxes
= axes
;
759 lpDIDevCaps
->dwButtons
= buttons
;
762 JoystickAImpl_Unacquire(iface
);
767 static HRESULT WINAPI
JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface
) {
768 ICOM_THIS(JoystickImpl
,iface
);
775 /******************************************************************************
776 * EnumObjects : enumerate the different buttons and axis...
778 static HRESULT WINAPI
JoystickAImpl_EnumObjects(
779 LPDIRECTINPUTDEVICE8A iface
,
780 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback
,
784 ICOM_THIS(JoystickImpl
,iface
);
785 DIDEVICEOBJECTINSTANCEA ddoi
;
786 int xfd
= This
->joyfd
;
789 TRACE("(this=%p,%p,%p,%08lx)\n", This
, lpCallback
, lpvRef
, dwFlags
);
790 if (TRACE_ON(dinput
)) {
791 TRACE(" - flags = ");
792 _dump_EnumObjects_flags(dwFlags
);
796 if (xfd
== -1) return DIERR_NOTACQUIRED
;
798 /* Only the fields till dwFFMaxForce are relevant */
799 ddoi
.dwSize
= FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA
, dwFFMaxForce
);
801 /* For the joystick, do as is done in the GetCapabilities function */
802 /* FIXME: needs more items */
803 if ((dwFlags
== DIDFT_ALL
) ||
804 (dwFlags
& DIDFT_AXIS
)) {
807 for (i
= 0; i
< ABS_MAX
; i
++) {
808 if (!test_bit(This
->absbits
,i
)) continue;
812 ddoi
.guidType
= GUID_XAxis
;
813 ddoi
.dwOfs
= DIJOFS_X
;
816 ddoi
.guidType
= GUID_YAxis
;
817 ddoi
.dwOfs
= DIJOFS_Y
;
820 ddoi
.guidType
= GUID_ZAxis
;
821 ddoi
.dwOfs
= DIJOFS_Z
;
824 ddoi
.guidType
= GUID_RxAxis
;
825 ddoi
.dwOfs
= DIJOFS_RX
;
828 ddoi
.guidType
= GUID_RyAxis
;
829 ddoi
.dwOfs
= DIJOFS_RY
;
832 ddoi
.guidType
= GUID_RzAxis
;
833 ddoi
.dwOfs
= DIJOFS_RZ
;
836 ddoi
.guidType
= GUID_Slider
;
837 ddoi
.dwOfs
= DIJOFS_SLIDER(0);
840 FIXME("unhandled abs axis %d, ignoring!\n",i
);
842 ddoi
.dwType
= DIDFT_MAKEINSTANCE((1<<i
) << WINE_JOYSTICK_AXIS_BASE
) | DIDFT_ABSAXIS
;
843 sprintf(ddoi
.tszName
, "%d-Axis", i
);
844 _dump_OBJECTINSTANCEA(&ddoi
);
845 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
)
850 if ((dwFlags
== DIDFT_ALL
) ||
851 (dwFlags
& DIDFT_BUTTON
)) {
854 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
856 ddoi
.guidType
= GUID_Button
;
858 for (i
= 0; i
< KEY_MAX
; i
++) {
859 if (!test_bit(This
->keybits
,i
)) continue;
865 ddoi
.dwOfs
= DIJOFS_BUTTON(0);
866 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 0) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
871 ddoi
.dwOfs
= DIJOFS_BUTTON(1);
872 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 1) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
877 ddoi
.dwOfs
= DIJOFS_BUTTON(2);
878 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 2) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
883 ddoi
.dwOfs
= DIJOFS_BUTTON(3);
884 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 3) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
889 ddoi
.dwOfs
= DIJOFS_BUTTON(4);
890 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 4) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
895 ddoi
.dwOfs
= DIJOFS_BUTTON(5);
896 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 5) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
901 ddoi
.dwOfs
= DIJOFS_BUTTON(6);
902 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 6) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
907 ddoi
.dwOfs
= DIJOFS_BUTTON(7);
908 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 7) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
913 ddoi
.dwOfs
= DIJOFS_BUTTON(8);
914 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 8) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
918 ddoi
.dwOfs
= DIJOFS_BUTTON(9);
919 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 9) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
923 ddoi
.dwOfs
= DIJOFS_BUTTON(10);
924 ddoi
.dwType
= DIDFT_MAKEINSTANCE((0x0001 << 10) << WINE_JOYSTICK_BUTTON_BASE
) | DIDFT_PSHBUTTON
;
927 sprintf(ddoi
.tszName
, "%d-Button", i
);
928 _dump_OBJECTINSTANCEA(&ddoi
);
929 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
)
934 if (xfd
!=This
->joyfd
)
940 static HRESULT WINAPI
JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface
,
941 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback
,
945 ICOM_THIS(JoystickImpl
,iface
);
947 device_enumobjects_AtoWcb_data data
;
949 data
.lpCallBack
= lpCallback
;
950 data
.lpvRef
= lpvRef
;
952 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A
) This
, (LPDIENUMDEVICEOBJECTSCALLBACKA
) DIEnumDevicesCallbackAtoW
, (LPVOID
) &data
, dwFlags
);
955 /******************************************************************************
956 * GetProperty : get input device properties
958 static HRESULT WINAPI
JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
960 LPDIPROPHEADER pdiph
)
962 ICOM_THIS(JoystickImpl
,iface
);
964 TRACE("(this=%p,%s,%p): stub!\n",
965 iface
, debugstr_guid(rguid
), pdiph
);
967 if (TRACE_ON(dinput
))
968 _dump_DIPROPHEADER(pdiph
);
970 if (!HIWORD(rguid
)) {
971 switch ((DWORD
)rguid
) {
972 case (DWORD
) DIPROP_BUFFERSIZE
: {
973 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
975 TRACE(" return buffersize = %d\n",This
->queue_len
);
976 pd
->dwData
= This
->queue_len
;
980 case (DWORD
) DIPROP_RANGE
: {
981 /* LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph; */
982 if ((pdiph
->dwHow
== DIPH_BYID
) &&
983 (pdiph
->dwObj
& DIDFT_ABSAXIS
)) {
984 /* The app is querying the current range of the axis : return the lMin and lMax values */
985 FIXME("unimplemented axis range query.\n");
992 FIXME("Unknown type %ld (%s)\n",(DWORD
)rguid
,debugstr_guid(rguid
));
1001 static IDirectInputDevice8AVtbl JoystickAvt
=
1003 IDirectInputDevice2AImpl_QueryInterface
,
1004 IDirectInputDevice2AImpl_AddRef
,
1005 JoystickAImpl_Release
,
1006 JoystickAImpl_GetCapabilities
,
1007 JoystickAImpl_EnumObjects
,
1008 JoystickAImpl_GetProperty
,
1009 JoystickAImpl_SetProperty
,
1010 JoystickAImpl_Acquire
,
1011 JoystickAImpl_Unacquire
,
1012 JoystickAImpl_GetDeviceState
,
1013 JoystickAImpl_GetDeviceData
,
1014 JoystickAImpl_SetDataFormat
,
1015 JoystickAImpl_SetEventNotification
,
1016 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1017 IDirectInputDevice2AImpl_GetObjectInfo
,
1018 IDirectInputDevice2AImpl_GetDeviceInfo
,
1019 IDirectInputDevice2AImpl_RunControlPanel
,
1020 IDirectInputDevice2AImpl_Initialize
,
1021 IDirectInputDevice2AImpl_CreateEffect
,
1022 IDirectInputDevice2AImpl_EnumEffects
,
1023 IDirectInputDevice2AImpl_GetEffectInfo
,
1024 IDirectInputDevice2AImpl_GetForceFeedbackState
,
1025 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
1026 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
1027 IDirectInputDevice2AImpl_Escape
,
1029 IDirectInputDevice2AImpl_SendDeviceData
,
1030 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1031 IDirectInputDevice7AImpl_WriteEffectToFile
,
1032 IDirectInputDevice8AImpl_BuildActionMap
,
1033 IDirectInputDevice8AImpl_SetActionMap
,
1034 IDirectInputDevice8AImpl_GetImageInfo
1037 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1038 # define XCAST(fun) (typeof(JoystickWvt.fun))
1040 # define XCAST(fun) (void*)
1043 static IDirectInputDevice8WVtbl JoystickWvt
=
1045 IDirectInputDevice2WImpl_QueryInterface
,
1046 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
1047 XCAST(Release
)JoystickAImpl_Release
,
1048 XCAST(GetCapabilities
)JoystickAImpl_GetCapabilities
,
1049 JoystickWImpl_EnumObjects
,
1050 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1051 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1052 XCAST(Acquire
)JoystickAImpl_Acquire
,
1053 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1054 XCAST(GetDeviceState
)JoystickAImpl_GetDeviceState
,
1055 XCAST(GetDeviceData
)JoystickAImpl_GetDeviceData
,
1056 XCAST(SetDataFormat
)JoystickAImpl_SetDataFormat
,
1057 XCAST(SetEventNotification
)JoystickAImpl_SetEventNotification
,
1058 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
1059 IDirectInputDevice2WImpl_GetObjectInfo
,
1060 IDirectInputDevice2WImpl_GetDeviceInfo
,
1061 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
1062 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
1063 XCAST(CreateEffect
)IDirectInputDevice2AImpl_CreateEffect
,
1064 IDirectInputDevice2WImpl_EnumEffects
,
1065 IDirectInputDevice2WImpl_GetEffectInfo
,
1066 XCAST(GetForceFeedbackState
)IDirectInputDevice2AImpl_GetForceFeedbackState
,
1067 XCAST(SendForceFeedbackCommand
)IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
1068 XCAST(EnumCreatedEffectObjects
)IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
1069 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1070 XCAST(Poll
)JoystickAImpl_Poll
,
1071 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1072 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1073 IDirectInputDevice7WImpl_WriteEffectToFile
,
1074 IDirectInputDevice8WImpl_BuildActionMap
,
1075 IDirectInputDevice8WImpl_SetActionMap
,
1076 IDirectInputDevice8WImpl_GetImageInfo
1080 #endif /* HAVE_LINUX_INPUT_H */