1 /* DirectInput Joystick device
3 * Copyright 1998 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/port.h"
39 #ifdef HAVE_SYS_TIME_H
40 # include <sys/time.h>
42 #include <sys/fcntl.h>
43 #ifdef HAVE_SYS_IOCTL_H
44 # include <sys/ioctl.h>
47 #ifdef HAVE_SYS_ERRNO_H
48 # include <sys/errno.h>
50 #ifdef HAVE_LINUX_IOCTL_H
51 # include <linux/ioctl.h>
53 #ifdef HAVE_LINUX_JOYSTICK_H
54 # include <linux/joystick.h>
56 #ifdef HAVE_SYS_POLL_H
57 # include <sys/poll.h>
60 #include "wine/debug.h"
61 #include "wine/unicode.h"
68 #include "dinput_private.h"
69 #include "device_private.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
73 #ifdef HAVE_LINUX_22_JOYSTICK_API
75 #define JOYDEV_NEW "/dev/input/js"
76 #define JOYDEV_OLD "/dev/js"
90 typedef struct JoystickImpl JoystickImpl
;
91 static const IDirectInputDevice8AVtbl JoystickAvt
;
92 static const IDirectInputDevice8WVtbl JoystickWvt
;
95 struct IDirectInputDevice2AImpl base
;
99 /* The 'parent' DInput */
100 IDirectInputImpl
*dinput
;
102 /* joystick private */
104 DIJOYSTATE2 js
; /* wine data */
105 LPDIDATAFORMAT user_df
; /* user defined format */
106 DataFormat
*transform
; /* wine to user format converter */
107 int *offsets
; /* object offsets */
118 static GUID DInput_Wine_Joystick_GUID
= { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
122 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
125 static void _dump_DIDEVCAPS(LPDIDEVCAPS lpDIDevCaps
)
127 TRACE("dwSize: %d\n", lpDIDevCaps
->dwSize
);
128 TRACE("dwFlags: %08x\n", lpDIDevCaps
->dwFlags
);
129 TRACE("dwDevType: %08x %s\n", lpDIDevCaps
->dwDevType
,
130 lpDIDevCaps
->dwDevType
== DIDEVTYPE_DEVICE
? "DIDEVTYPE_DEVICE" :
131 lpDIDevCaps
->dwDevType
== DIDEVTYPE_DEVICE
? "DIDEVTYPE_DEVICE" :
132 lpDIDevCaps
->dwDevType
== DIDEVTYPE_MOUSE
? "DIDEVTYPE_MOUSE" :
133 lpDIDevCaps
->dwDevType
== DIDEVTYPE_KEYBOARD
? "DIDEVTYPE_KEYBOARD" :
134 lpDIDevCaps
->dwDevType
== DIDEVTYPE_JOYSTICK
? "DIDEVTYPE_JOYSTICK" :
135 lpDIDevCaps
->dwDevType
== DIDEVTYPE_HID
? "DIDEVTYPE_HID" : "UNKNOWN");
136 TRACE("dwAxes: %d\n", lpDIDevCaps
->dwAxes
);
137 TRACE("dwButtons: %d\n", lpDIDevCaps
->dwButtons
);
138 TRACE("dwPOVs: %d\n", lpDIDevCaps
->dwPOVs
);
139 if (lpDIDevCaps
->dwSize
> sizeof(DIDEVCAPS_DX3
)) {
140 TRACE("dwFFSamplePeriod: %d\n", lpDIDevCaps
->dwFFSamplePeriod
);
141 TRACE("dwFFMinTimeResolution: %d\n", lpDIDevCaps
->dwFFMinTimeResolution
);
142 TRACE("dwFirmwareRevision: %d\n", lpDIDevCaps
->dwFirmwareRevision
);
143 TRACE("dwHardwareRevision: %d\n", lpDIDevCaps
->dwHardwareRevision
);
144 TRACE("dwFFDriverVersion: %d\n", lpDIDevCaps
->dwFFDriverVersion
);
148 static int joydev_get_device(char *dev
, int id
)
151 sprintf(dev
, "%s%d", JOYDEV_NEW
, id
);
152 if ((ret
= open(dev
, O_RDONLY
)) < 0) {
153 sprintf(dev
, "%s%d", JOYDEV_OLD
, id
);
154 if ((ret
= open(dev
, O_RDONLY
)) < 0) {
161 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
166 if (dwFlags
& DIEDFL_FORCEFEEDBACK
) {
167 WARN("force feedback not supported\n");
171 if ((dwDevType
== 0) ||
172 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
173 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))) {
174 /* check whether we have a joystick */
175 if ((fd
= joydev_get_device(dev
, id
)) < 0) {
176 WARN("open(%s,O_RDONLY) failed: %s\n", dev
, strerror(errno
));
180 /* Return joystick */
181 lpddi
->guidInstance
= DInput_Wine_Joystick_GUID
;
182 lpddi
->guidInstance
.Data3
= id
;
183 lpddi
->guidProduct
= DInput_Wine_Joystick_GUID
;
184 /* we only support traditional joysticks for now */
185 if (version
>= 0x0800)
186 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
188 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
189 sprintf(lpddi
->tszInstanceName
, "Joystick %d", id
);
190 #if defined(JSIOCGNAME)
191 if (ioctl(fd
,JSIOCGNAME(sizeof(lpddi
->tszProductName
)),lpddi
->tszProductName
) < 0) {
192 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", dev
, strerror(errno
));
193 strcpy(lpddi
->tszProductName
, "Wine Joystick");
196 strcpy(lpddi
->tszProductName
, "Wine Joystick");
199 lpddi
->guidFFDriver
= GUID_NULL
;
201 TRACE("Enumerating the linux Joystick device: %s (%s)\n", dev
, lpddi
->tszProductName
);
208 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
215 if (dwFlags
& DIEDFL_FORCEFEEDBACK
) {
216 WARN("force feedback not supported\n");
220 if ((dwDevType
== 0) ||
221 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
222 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))) {
223 /* check whether we have a joystick */
224 if ((fd
= joydev_get_device(dev
, id
)) < 0) {
225 WARN("open(%s,O_RDONLY) failed: %s\n", dev
, strerror(errno
));
229 /* Return joystick */
230 lpddi
->guidInstance
= DInput_Wine_Joystick_GUID
;
231 lpddi
->guidInstance
.Data3
= id
;
232 lpddi
->guidProduct
= DInput_Wine_Joystick_GUID
;
233 /* we only support traditional joysticks for now */
234 if (version
>= 0x0800)
235 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
237 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
238 sprintf(friendly
, "Joystick %d", id
);
239 MultiByteToWideChar(CP_ACP
, 0, friendly
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
240 #if defined(JSIOCGNAME)
241 if (ioctl(fd
,JSIOCGNAME(sizeof(name
)),name
) < 0) {
242 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", dev
, strerror(errno
));
243 strcpy(name
, "Wine Joystick");
246 strcpy(name
, "Wine Joystick");
248 MultiByteToWideChar(CP_ACP
, 0, name
, -1, lpddi
->tszProductName
, MAX_PATH
);
249 lpddi
->guidFFDriver
= GUID_NULL
;
251 TRACE("Enumerating the linux Joystick device: %s (%s)\n",dev
,name
);
259 * Get a config key from either the app-specific or the default config
262 inline static DWORD
get_config_key( HKEY defkey
, HKEY appkey
, const char *name
,
263 char *buffer
, DWORD size
)
265 if (appkey
&& !RegQueryValueExA( appkey
, name
, 0, NULL
, (LPBYTE
)buffer
, &size
))
268 if (defkey
&& !RegQueryValueExA( defkey
, name
, 0, NULL
, (LPBYTE
)buffer
, &size
))
271 return ERROR_FILE_NOT_FOUND
;
275 * Setup the dinput options.
278 static HRESULT
setup_dinput_options(JoystickImpl
* device
)
280 char buffer
[MAX_PATH
+16];
281 HKEY hkey
, appkey
= 0;
284 buffer
[MAX_PATH
]='\0';
286 /* @@ Wine registry key: HKCU\Software\Wine\DirectInput */
287 if (RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\DirectInput", &hkey
)) hkey
= 0;
289 len
= GetModuleFileNameA( 0, buffer
, MAX_PATH
);
290 if (len
&& len
< MAX_PATH
) {
292 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectInput */
293 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\AppDefaults", &tmpkey
))
295 char *p
, *appname
= buffer
;
296 if ((p
= strrchr( appname
, '/' ))) appname
= p
+ 1;
297 if ((p
= strrchr( appname
, '\\' ))) appname
= p
+ 1;
298 strcat( appname
, "\\DirectInput" );
299 if (RegOpenKeyA( tmpkey
, appname
, &appkey
)) appkey
= 0;
300 RegCloseKey( tmpkey
);
306 if (!get_config_key( hkey
, appkey
, "DefaultDeadZone", buffer
, MAX_PATH
)) {
307 device
->deadzone
= atoi(buffer
);
308 TRACE("setting default deadzone to: \"%s\" %d\n", buffer
, device
->deadzone
);
311 if (!get_config_key( hkey
, appkey
, device
->name
, buffer
, MAX_PATH
)) {
315 const char *delim
= ",";
317 TRACE("\"%s\" = \"%s\"\n", device
->name
, buffer
);
319 device
->axis_map
= HeapAlloc(GetProcessHeap(), 0, device
->axes
* sizeof(int));
320 if (device
->axis_map
== 0)
321 return DIERR_OUTOFMEMORY
;
323 if ((ptr
= strtok(buffer
, delim
)) != NULL
) {
325 if (strcmp(ptr
, "X") == 0) {
326 device
->axis_map
[tokens
] = 0;
328 } else if (strcmp(ptr
, "Y") == 0) {
329 device
->axis_map
[tokens
] = 1;
331 } else if (strcmp(ptr
, "Z") == 0) {
332 device
->axis_map
[tokens
] = 2;
334 } else if (strcmp(ptr
, "Rx") == 0) {
335 device
->axis_map
[tokens
] = 3;
337 } else if (strcmp(ptr
, "Ry") == 0) {
338 device
->axis_map
[tokens
] = 4;
340 } else if (strcmp(ptr
, "Rz") == 0) {
341 device
->axis_map
[tokens
] = 5;
343 } else if (strcmp(ptr
, "Slider1") == 0) {
344 device
->axis_map
[tokens
] = 6;
346 } else if (strcmp(ptr
, "Slider2") == 0) {
347 device
->axis_map
[tokens
] = 7;
349 } else if (strcmp(ptr
, "POV1") == 0) {
350 device
->axis_map
[tokens
++] = 8;
351 device
->axis_map
[tokens
] = 8;
353 } else if (strcmp(ptr
, "POV2") == 0) {
354 device
->axis_map
[tokens
++] = 9;
355 device
->axis_map
[tokens
] = 9;
357 } else if (strcmp(ptr
, "POV3") == 0) {
358 device
->axis_map
[tokens
++] = 10;
359 device
->axis_map
[tokens
] = 10;
361 } else if (strcmp(ptr
, "POV4") == 0) {
362 device
->axis_map
[tokens
++] = 11;
363 device
->axis_map
[tokens
] = 11;
366 ERR("invalid joystick axis type: %s\n", ptr
);
367 device
->axis_map
[tokens
] = tokens
;
372 } while ((ptr
= strtok(NULL
, delim
)) != NULL
);
374 if (tokens
!= device
->devcaps
.dwAxes
) {
375 ERR("not all joystick axes mapped: %d axes(%d,%d), %d arguments\n", device
->axes
, axis
, pov
,tokens
);
376 while (tokens
< device
->axes
) {
377 device
->axis_map
[tokens
] = tokens
;
383 device
->devcaps
.dwAxes
= axis
;
384 device
->devcaps
.dwPOVs
= pov
;
388 RegCloseKey( appkey
);
396 static HRESULT
alloc_device(REFGUID rguid
, const void *jvt
, IDirectInputImpl
*dinput
, LPDIRECTINPUTDEVICEA
* pdev
)
399 JoystickImpl
* newDevice
;
403 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(JoystickImpl
));
404 if (newDevice
== 0) {
405 WARN("out of memory\n");
407 return DIERR_OUTOFMEMORY
;
410 if ((newDevice
->joyfd
= joydev_get_device(newDevice
->dev
, rguid
->Data3
)) < 0) {
411 WARN("open(%s,O_RDONLY) failed: %s\n", newDevice
->dev
, strerror(errno
));
412 HeapFree(GetProcessHeap(), 0, newDevice
);
413 return DIERR_DEVICENOTREG
;
416 /* get the device name */
417 #if defined(JSIOCGNAME)
418 if (ioctl(newDevice
->joyfd
,JSIOCGNAME(MAX_PATH
),name
) < 0) {
419 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", newDevice
->dev
, strerror(errno
));
420 strcpy(name
, "Wine Joystick");
423 strcpy(name
, "Wine Joystick");
426 /* copy the device name */
427 newDevice
->name
= HeapAlloc(GetProcessHeap(),0,strlen(name
) + 1);
428 strcpy(newDevice
->name
, name
);
431 if (ioctl(newDevice
->joyfd
,JSIOCGAXES
,&newDevice
->axes
) < 0) {
432 WARN("ioctl(%s,JSIOCGAXES) failed: %s, defauting to 2\n", newDevice
->dev
, strerror(errno
));
437 if (ioctl(newDevice
->joyfd
,JSIOCGBUTTONS
,&newDevice
->buttons
) < 0) {
438 WARN("ioctl(%s,JSIOCGBUTTONS) failed: %s, defauting to 2\n", newDevice
->dev
, strerror(errno
));
439 newDevice
->buttons
= 2;
443 newDevice
->base
.lpVtbl
= jvt
;
444 newDevice
->base
.ref
= 1;
445 newDevice
->dinput
= dinput
;
446 CopyMemory(&newDevice
->base
.guid
, rguid
, sizeof(*rguid
));
447 InitializeCriticalSection(&newDevice
->base
.crit
);
448 newDevice
->base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)"DINPUT_joystick";
450 /* setup_dinput_options may change these */
451 newDevice
->deadzone
= 5000;
452 newDevice
->devcaps
.dwButtons
= newDevice
->buttons
;
453 newDevice
->devcaps
.dwAxes
= newDevice
->axes
;
454 newDevice
->devcaps
.dwPOVs
= 0;
456 /* do any user specified configuration */
457 hr
= setup_dinput_options(newDevice
);
461 if (newDevice
->axis_map
== 0) {
462 newDevice
->axis_map
= HeapAlloc(GetProcessHeap(), 0, newDevice
->axes
* sizeof(int));
463 if (newDevice
->axis_map
== 0)
466 for (i
= 0; i
< newDevice
->axes
; i
++)
467 newDevice
->axis_map
[i
] = i
;
470 /* wine uses DIJOYSTATE2 as it's internal format so copy
471 * the already defined format c_dfDIJoystick2 */
472 newDevice
->user_df
= HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2
.dwSize
);
473 if (newDevice
->user_df
== 0)
476 CopyMemory(newDevice
->user_df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
478 /* copy default objects */
479 newDevice
->user_df
->rgodf
= HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2
.dwNumObjs
*c_dfDIJoystick2
.dwObjSize
);
480 if (newDevice
->user_df
->rgodf
== 0)
483 CopyMemory(newDevice
->user_df
->rgodf
,c_dfDIJoystick2
.rgodf
,c_dfDIJoystick2
.dwNumObjs
*c_dfDIJoystick2
.dwObjSize
);
485 /* create default properties */
486 newDevice
->props
= HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2
.dwNumObjs
*sizeof(ObjProps
));
487 if (newDevice
->props
== 0)
490 /* initialize default properties */
491 for (i
= 0; i
< c_dfDIJoystick2
.dwNumObjs
; i
++) {
492 newDevice
->props
[i
].lMin
= 0;
493 newDevice
->props
[i
].lMax
= 0xffff;
494 newDevice
->props
[i
].lDeadZone
= newDevice
->deadzone
; /* % * 1000 */
495 newDevice
->props
[i
].lSaturation
= 0;
498 /* create an offsets array */
499 newDevice
->offsets
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,c_dfDIJoystick2
.dwNumObjs
*sizeof(int));
500 if (newDevice
->offsets
== 0)
503 /* create the default transform filter */
504 newDevice
->transform
= create_DataFormat(&c_dfDIJoystick2
, newDevice
->user_df
, newDevice
->offsets
);
506 IDirectInputDevice_AddRef((LPDIRECTINPUTDEVICE8A
)newDevice
->dinput
);
508 newDevice
->devcaps
.dwSize
= sizeof(newDevice
->devcaps
);
509 newDevice
->devcaps
.dwFlags
= DIDC_ATTACHED
;
510 if (newDevice
->dinput
->dwVersion
>= 0x0800)
511 newDevice
->devcaps
.dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
513 newDevice
->devcaps
.dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
514 newDevice
->devcaps
.dwFFSamplePeriod
= 0;
515 newDevice
->devcaps
.dwFFMinTimeResolution
= 0;
516 newDevice
->devcaps
.dwFirmwareRevision
= 0;
517 newDevice
->devcaps
.dwHardwareRevision
= 0;
518 newDevice
->devcaps
.dwFFDriverVersion
= 0;
520 if (TRACE_ON(dinput
)) {
521 _dump_DIDATAFORMAT(newDevice
->user_df
);
522 for (i
= 0; i
< (newDevice
->axes
); i
++)
523 TRACE("axis_map[%d] = %d\n", i
, newDevice
->axis_map
[i
]);
524 _dump_DIDEVCAPS(&newDevice
->devcaps
);
527 *pdev
= (LPDIRECTINPUTDEVICEA
)newDevice
;
532 hr
= DIERR_OUTOFMEMORY
;
534 HeapFree(GetProcessHeap(),0,newDevice
->axis_map
);
535 HeapFree(GetProcessHeap(),0,newDevice
->name
);
536 HeapFree(GetProcessHeap(),0,newDevice
->props
);
537 HeapFree(GetProcessHeap(),0,newDevice
->user_df
->rgodf
);
538 HeapFree(GetProcessHeap(),0,newDevice
->user_df
);
539 HeapFree(GetProcessHeap(),0,newDevice
);
545 static BOOL
IsJoystickGUID(REFGUID guid
)
547 GUID wine_joystick
= DInput_Wine_Joystick_GUID
;
548 GUID dev_guid
= *guid
;
550 wine_joystick
.Data3
= 0;
553 return IsEqualGUID(&wine_joystick
, &dev_guid
);
556 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
558 if ((IsEqualGUID(&GUID_Joystick
,rguid
)) ||
559 (IsJoystickGUID(rguid
))) {
560 if ((riid
== NULL
) ||
561 IsEqualGUID(&IID_IDirectInputDeviceA
,riid
) ||
562 IsEqualGUID(&IID_IDirectInputDevice2A
,riid
) ||
563 IsEqualGUID(&IID_IDirectInputDevice7A
,riid
) ||
564 IsEqualGUID(&IID_IDirectInputDevice8A
,riid
)) {
565 return alloc_device(rguid
, &JoystickAvt
, dinput
, pdev
);
567 WARN("no interface\n");
569 return DIERR_NOINTERFACE
;
573 WARN("invalid device GUID\n");
575 return DIERR_DEVICENOTREG
;
578 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
580 if ((IsEqualGUID(&GUID_Joystick
,rguid
)) ||
581 (IsJoystickGUID(rguid
))) {
582 if ((riid
== NULL
) ||
583 IsEqualGUID(&IID_IDirectInputDeviceW
,riid
) ||
584 IsEqualGUID(&IID_IDirectInputDevice2W
,riid
) ||
585 IsEqualGUID(&IID_IDirectInputDevice7W
,riid
) ||
586 IsEqualGUID(&IID_IDirectInputDevice8W
,riid
)) {
587 return alloc_device(rguid
, &JoystickWvt
, dinput
, (LPDIRECTINPUTDEVICEA
*)pdev
);
589 WARN("no interface\n");
591 return DIERR_NOINTERFACE
;
595 WARN("invalid device GUID\n");
597 return DIERR_DEVICENOTREG
;
600 const struct dinput_device joystick_linux_device
= {
601 "Wine Linux joystick driver",
604 joydev_create_deviceA
,
605 joydev_create_deviceW
608 /******************************************************************************
611 static ULONG WINAPI
JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface
)
613 JoystickImpl
*This
= (JoystickImpl
*)iface
;
616 ref
= InterlockedDecrement(&This
->base
.ref
);
620 /* Free the device name */
621 HeapFree(GetProcessHeap(),0,This
->name
);
623 /* Free the axis map */
624 HeapFree(GetProcessHeap(),0,This
->axis_map
);
626 /* Free the data queue */
627 HeapFree(GetProcessHeap(), 0, This
->base
.data_queue
);
629 /* Free the DataFormat */
630 HeapFree(GetProcessHeap(), 0, This
->user_df
->rgodf
);
631 HeapFree(GetProcessHeap(), 0, This
->user_df
);
633 /* Free the properties */
634 HeapFree(GetProcessHeap(), 0, This
->props
);
636 /* Free the offsets array */
637 HeapFree(GetProcessHeap(),0,This
->offsets
);
639 /* release the data transform filter */
640 release_DataFormat(This
->transform
);
642 This
->base
.crit
.DebugInfo
->Spare
[0] = 0;
643 DeleteCriticalSection(&This
->base
.crit
);
644 IDirectInputDevice_Release((LPDIRECTINPUTDEVICE8A
)This
->dinput
);
646 HeapFree(GetProcessHeap(),0,This
);
650 /******************************************************************************
651 * SetDataFormat : the application can choose the format of the data
652 * the device driver sends back with GetDeviceState.
654 static HRESULT WINAPI
JoystickAImpl_SetDataFormat(
655 LPDIRECTINPUTDEVICE8A iface
,
658 JoystickImpl
*This
= (JoystickImpl
*)iface
;
660 LPDIDATAFORMAT new_df
= 0;
661 LPDIOBJECTDATAFORMAT new_rgodf
= 0;
662 ObjProps
* new_props
= 0;
664 TRACE("(%p,%p)\n",This
,df
);
667 WARN("invalid pointer\n");
671 if (df
->dwSize
!= sizeof(*df
)) {
672 WARN("invalid argument\n");
673 return DIERR_INVALIDPARAM
;
676 if (This
->base
.acquired
) {
678 return DIERR_ACQUIRED
;
681 if (TRACE_ON(dinput
))
682 _dump_DIDATAFORMAT(df
);
684 /* Store the new data format */
685 new_df
= HeapAlloc(GetProcessHeap(),0,df
->dwSize
);
689 new_rgodf
= HeapAlloc(GetProcessHeap(),0,df
->dwNumObjs
*df
->dwObjSize
);
693 new_props
= HeapAlloc(GetProcessHeap(),0,df
->dwNumObjs
*sizeof(ObjProps
));
697 HeapFree(GetProcessHeap(),0,This
->user_df
);
698 HeapFree(GetProcessHeap(),0,This
->user_df
->rgodf
);
699 HeapFree(GetProcessHeap(),0,This
->props
);
700 release_DataFormat(This
->transform
);
702 This
->user_df
= new_df
;
703 CopyMemory(This
->user_df
, df
, df
->dwSize
);
704 This
->user_df
->rgodf
= new_rgodf
;
705 CopyMemory(This
->user_df
->rgodf
,df
->rgodf
,df
->dwNumObjs
*df
->dwObjSize
);
706 This
->props
= new_props
;
707 for (i
= 0; i
< df
->dwNumObjs
; i
++) {
708 This
->props
[i
].lMin
= 0;
709 This
->props
[i
].lMax
= 0xffff;
710 This
->props
[i
].lDeadZone
= 1000;
711 This
->props
[i
].lSaturation
= 0;
713 This
->transform
= create_DataFormat(&c_dfDIJoystick2
, This
->user_df
, This
->offsets
);
718 WARN("out of memory\n");
719 HeapFree(GetProcessHeap(),0,new_props
);
720 HeapFree(GetProcessHeap(),0,new_rgodf
);
721 HeapFree(GetProcessHeap(),0,new_df
);
722 return DIERR_OUTOFMEMORY
;
725 /******************************************************************************
726 * Acquire : gets exclusive control of the joystick
728 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
730 JoystickImpl
*This
= (JoystickImpl
*)iface
;
732 TRACE("(%p)\n",This
);
734 if (This
->base
.acquired
) {
735 WARN("already acquired\n");
739 /* open the joystick device */
740 if (This
->joyfd
==-1) {
741 TRACE("opening joystick device %s\n", This
->dev
);
743 This
->joyfd
=open(This
->dev
,O_RDONLY
);
744 if (This
->joyfd
==-1) {
745 ERR("open(%s) failed: %s\n", This
->dev
, strerror(errno
));
746 return DIERR_NOTFOUND
;
750 This
->base
.acquired
= 1;
755 /******************************************************************************
756 * Unacquire : frees the joystick
758 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
760 JoystickImpl
*This
= (JoystickImpl
*)iface
;
763 TRACE("(%p)\n",This
);
765 if ((res
= IDirectInputDevice2AImpl_Unacquire(iface
)) != DI_OK
) return res
;
767 if (This
->joyfd
!=-1) {
768 TRACE("closing joystick device\n");
777 static LONG
map_axis(JoystickImpl
* This
, short val
, short index
)
780 double fmin
= This
->props
[index
].lMin
;
781 double fmax
= This
->props
[index
].lMax
;
784 fret
= (((fval
+ 32767.0) * (fmax
- fmin
)) / (32767.0*2.0)) + fmin
;
794 /* convert wine format offset to user format object index */
795 static int offset_to_object(JoystickImpl
*This
, int offset
)
799 for (i
= 0; i
< This
->user_df
->dwNumObjs
; i
++) {
800 if (This
->user_df
->rgodf
[i
].dwOfs
== offset
)
807 static LONG
calculate_pov(JoystickImpl
*This
, int index
)
809 if (This
->povs
[index
].lX
< -16384) {
810 if (This
->povs
[index
].lY
< -16384)
811 This
->js
.rgdwPOV
[index
] = 31500;
812 else if (This
->povs
[index
].lY
> 16384)
813 This
->js
.rgdwPOV
[index
] = 22500;
815 This
->js
.rgdwPOV
[index
] = 27000;
816 } else if (This
->povs
[index
].lX
> 16384) {
817 if (This
->povs
[index
].lY
< -16384)
818 This
->js
.rgdwPOV
[index
] = 4500;
819 else if (This
->povs
[index
].lY
> 16384)
820 This
->js
.rgdwPOV
[index
] = 13500;
822 This
->js
.rgdwPOV
[index
] = 9000;
824 if (This
->povs
[index
].lY
< -16384)
825 This
->js
.rgdwPOV
[index
] = 0;
826 else if (This
->povs
[index
].lY
> 16384)
827 This
->js
.rgdwPOV
[index
] = 18000;
829 This
->js
.rgdwPOV
[index
] = -1;
832 return This
->js
.rgdwPOV
[index
];
835 static void joy_polldev(JoystickImpl
*This
) {
838 TRACE("(%p)\n", This
);
840 if (This
->joyfd
==-1) {
845 plfd
.fd
= This
->joyfd
;
846 plfd
.events
= POLLIN
;
847 if (poll(&plfd
,1,0) != 1)
849 /* we have one event, so we can read */
850 if (sizeof(jse
)!=read(This
->joyfd
,&jse
,sizeof(jse
))) {
853 TRACE("js_event: type 0x%x, number %d, value %d\n",
854 jse
.type
,jse
.number
,jse
.value
);
855 if (jse
.type
& JS_EVENT_BUTTON
) {
856 int offset
= This
->offsets
[jse
.number
+ 12];
857 int value
= jse
.value
?0x80:0x00;
859 This
->js
.rgbButtons
[jse
.number
] = value
;
860 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, value
, jse
.time
, This
->dinput
->evsequence
++);
861 } else if (jse
.type
& JS_EVENT_AXIS
) {
862 int number
= This
->axis_map
[jse
.number
]; /* wine format object index */
864 int offset
= This
->offsets
[number
];
865 int index
= offset_to_object(This
, offset
);
866 LONG value
= map_axis(This
, jse
.value
, index
);
868 /* FIXME do deadzone and saturation here */
870 TRACE("changing axis %d => %d\n", jse
.number
, number
);
882 This
->js
.lRx
= value
;
885 This
->js
.lRy
= value
;
888 This
->js
.lRz
= value
;
891 This
->js
.rglSlider
[0] = value
;
894 This
->js
.rglSlider
[1] = value
;
897 /* FIXME don't go off array */
898 if (This
->axis_map
[jse
.number
+ 1] == number
)
899 This
->povs
[0].lX
= jse
.value
;
900 else if (This
->axis_map
[jse
.number
- 1] == number
)
901 This
->povs
[0].lY
= jse
.value
;
902 value
= calculate_pov(This
, 0);
905 if (This
->axis_map
[jse
.number
+ 1] == number
)
906 This
->povs
[1].lX
= jse
.value
;
907 else if (This
->axis_map
[jse
.number
- 1] == number
)
908 This
->povs
[1].lY
= jse
.value
;
909 value
= calculate_pov(This
, 1);
912 if (This
->axis_map
[jse
.number
+ 1] == number
)
913 This
->povs
[2].lX
= jse
.value
;
914 else if (This
->axis_map
[jse
.number
- 1] == number
)
915 This
->povs
[2].lY
= jse
.value
;
916 value
= calculate_pov(This
, 2);
919 if (This
->axis_map
[jse
.number
+ 1] == number
)
920 This
->povs
[3].lX
= jse
.value
;
921 else if (This
->axis_map
[jse
.number
- 1] == number
)
922 This
->povs
[3].lY
= jse
.value
;
923 value
= calculate_pov(This
, 3);
927 queue_event((LPDIRECTINPUTDEVICE8A
)This
, offset
, value
, jse
.time
, This
->dinput
->evsequence
++);
929 WARN("axis %d not supported\n", number
);
934 /******************************************************************************
935 * GetDeviceState : returns the "state" of the joystick.
938 static HRESULT WINAPI
JoystickAImpl_GetDeviceState(
939 LPDIRECTINPUTDEVICE8A iface
,
943 JoystickImpl
*This
= (JoystickImpl
*)iface
;
945 TRACE("(%p,0x%08x,%p)\n", This
, len
, ptr
);
947 if (!This
->base
.acquired
) {
948 WARN("not acquired\n");
949 return DIERR_NOTACQUIRED
;
952 /* update joystick state */
955 /* convert and copy data to user supplied buffer */
956 fill_DataFormat(ptr
, &This
->js
, This
->transform
);
961 static int find_property(JoystickImpl
* This
, LPCDIPROPHEADER ph
)
964 if (ph
->dwHow
== DIPH_BYOFFSET
) {
965 return offset_to_object(This
, ph
->dwObj
);
966 } else if (ph
->dwHow
== DIPH_BYID
) {
967 for (i
= 0; i
< This
->user_df
->dwNumObjs
; i
++) {
968 if ((This
->user_df
->rgodf
[i
].dwType
& 0x00ffffff) == (ph
->dwObj
& 0x00ffffff)) {
977 /******************************************************************************
978 * SetProperty : change input device properties
980 static HRESULT WINAPI
JoystickAImpl_SetProperty(
981 LPDIRECTINPUTDEVICE8A iface
,
985 JoystickImpl
*This
= (JoystickImpl
*)iface
;
988 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
991 WARN("invalid parameter: ph == NULL\n");
992 return DIERR_INVALIDPARAM
;
995 if (TRACE_ON(dinput
))
996 _dump_DIPROPHEADER(ph
);
998 if (!HIWORD(rguid
)) {
999 switch (LOWORD(rguid
)) {
1000 case (DWORD
)DIPROP_RANGE
: {
1001 LPCDIPROPRANGE pr
= (LPCDIPROPRANGE
)ph
;
1002 if (ph
->dwHow
== DIPH_DEVICE
) {
1003 TRACE("proprange(%d,%d) all\n", pr
->lMin
, pr
->lMax
);
1004 for (i
= 0; i
< This
->user_df
->dwNumObjs
; i
++) {
1005 This
->props
[i
].lMin
= pr
->lMin
;
1006 This
->props
[i
].lMax
= pr
->lMax
;
1009 int obj
= find_property(This
, ph
);
1010 TRACE("proprange(%d,%d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
1012 This
->props
[obj
].lMin
= pr
->lMin
;
1013 This
->props
[obj
].lMax
= pr
->lMax
;
1019 case (DWORD
)DIPROP_DEADZONE
: {
1020 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
1021 if (ph
->dwHow
== DIPH_DEVICE
) {
1022 TRACE("deadzone(%d) all\n", pd
->dwData
);
1023 for (i
= 0; i
< This
->user_df
->dwNumObjs
; i
++)
1024 This
->props
[i
].lDeadZone
= pd
->dwData
;
1026 int obj
= find_property(This
, ph
);
1027 TRACE("deadzone(%d) obj=%d\n", pd
->dwData
, obj
);
1029 This
->props
[obj
].lDeadZone
= pd
->dwData
;
1035 case (DWORD
)DIPROP_SATURATION
: {
1036 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
1037 if (ph
->dwHow
== DIPH_DEVICE
) {
1038 TRACE("saturation(%d) all\n", pd
->dwData
);
1039 for (i
= 0; i
< This
->user_df
->dwNumObjs
; i
++)
1040 This
->props
[i
].lSaturation
= pd
->dwData
;
1042 int obj
= find_property(This
, ph
);
1043 TRACE("saturation(%d) obj=%d\n", pd
->dwData
, obj
);
1045 This
->props
[obj
].lSaturation
= pd
->dwData
;
1052 return IDirectInputDevice2AImpl_SetProperty(iface
, rguid
, ph
);
1059 static HRESULT WINAPI
JoystickAImpl_GetCapabilities(
1060 LPDIRECTINPUTDEVICE8A iface
,
1061 LPDIDEVCAPS lpDIDevCaps
)
1063 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1066 TRACE("%p->(%p)\n",iface
,lpDIDevCaps
);
1068 if (lpDIDevCaps
== NULL
) {
1069 WARN("invalid pointer\n");
1073 size
= lpDIDevCaps
->dwSize
;
1075 if (!(size
== sizeof(DIDEVCAPS
) || size
== sizeof(DIDEVCAPS_DX3
))) {
1076 WARN("invalid parameter\n");
1077 return DIERR_INVALIDPARAM
;
1080 CopyMemory(lpDIDevCaps
, &This
->devcaps
, size
);
1081 lpDIDevCaps
->dwSize
= size
;
1083 if (TRACE_ON(dinput
))
1084 _dump_DIDEVCAPS(lpDIDevCaps
);
1089 static HRESULT WINAPI
JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface
)
1091 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1093 TRACE("(%p)\n",This
);
1095 if (!This
->base
.acquired
) {
1096 WARN("not acquired\n");
1097 return DIERR_NOTACQUIRED
;
1104 /******************************************************************************
1105 * EnumObjects : enumerate the different buttons and axis...
1107 static HRESULT WINAPI
JoystickAImpl_EnumObjects(
1108 LPDIRECTINPUTDEVICE8A iface
,
1109 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback
,
1113 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1114 DIDEVICEOBJECTINSTANCEA ddoi
;
1119 TRACE("(this=%p,%p,%p,%08x)\n", This
, lpCallback
, lpvRef
, dwFlags
);
1120 if (TRACE_ON(dinput
)) {
1121 TRACE(" - flags = ");
1122 _dump_EnumObjects_flags(dwFlags
);
1126 /* Only the fields till dwFFMaxForce are relevant */
1127 ddoi
.dwSize
= FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA
, dwFFMaxForce
);
1129 /* For the joystick, do as is done in the GetCapabilities function */
1130 if ((dwFlags
== DIDFT_ALL
) ||
1131 (dwFlags
& DIDFT_AXIS
) ||
1132 (dwFlags
& DIDFT_POV
)) {
1133 int pov
[4] = { 0, 0, 0, 0 };
1137 for (i
= 0; i
< This
->axes
; i
++) {
1138 int wine_obj
= This
->axis_map
[i
];
1143 ddoi
.guidType
= GUID_XAxis
;
1146 ddoi
.guidType
= GUID_YAxis
;
1149 ddoi
.guidType
= GUID_ZAxis
;
1152 ddoi
.guidType
= GUID_RxAxis
;
1155 ddoi
.guidType
= GUID_RyAxis
;
1158 ddoi
.guidType
= GUID_RzAxis
;
1161 ddoi
.guidType
= GUID_Slider
;
1164 ddoi
.guidType
= GUID_Slider
;
1168 ddoi
.guidType
= GUID_POV
;
1172 ddoi
.guidType
= GUID_POV
;
1176 ddoi
.guidType
= GUID_POV
;
1180 ddoi
.guidType
= GUID_POV
;
1183 ddoi
.guidType
= GUID_Unknown
;
1186 user_offset
= This
->offsets
[wine_obj
]; /* get user offset from wine index */
1187 user_object
= offset_to_object(This
, user_offset
);
1189 ddoi
.dwType
= This
->user_df
->rgodf
[user_object
].dwType
& 0x00ffffff;
1190 ddoi
.dwOfs
= This
->user_df
->rgodf
[user_object
].dwOfs
;
1191 sprintf(ddoi
.tszName
, "Axis %d", axes
);
1194 if (pov
[wine_obj
- 8] < 2) {
1195 user_offset
= This
->offsets
[wine_obj
]; /* get user offset from wine index */
1196 user_object
= offset_to_object(This
, user_offset
);
1198 ddoi
.dwType
= This
->user_df
->rgodf
[user_object
].dwType
& 0x00ffffff;
1199 ddoi
.dwOfs
= This
->user_df
->rgodf
[user_object
].dwOfs
;
1200 sprintf(ddoi
.tszName
, "POV %d", povs
);
1206 _dump_OBJECTINSTANCEA(&ddoi
);
1207 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
)
1213 if ((dwFlags
== DIDFT_ALL
) ||
1214 (dwFlags
& DIDFT_BUTTON
)) {
1216 /* The DInput SDK says that GUID_Button is only for mouse buttons but well... */
1217 ddoi
.guidType
= GUID_Button
;
1219 for (i
= 0; i
< This
->buttons
; i
++) {
1220 user_offset
= This
->offsets
[i
+ 12]; /* get user offset from wine index */
1221 user_object
= offset_to_object(This
, user_offset
);
1222 ddoi
.guidType
= GUID_Button
;
1223 ddoi
.dwType
= This
->user_df
->rgodf
[user_object
].dwType
& 0x00ffffff;
1224 ddoi
.dwOfs
= This
->user_df
->rgodf
[user_object
].dwOfs
;
1225 sprintf(ddoi
.tszName
, "Button %d", i
);
1226 _dump_OBJECTINSTANCEA(&ddoi
);
1227 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) return DI_OK
;
1234 /******************************************************************************
1235 * EnumObjects : enumerate the different buttons and axis...
1237 static HRESULT WINAPI
JoystickWImpl_EnumObjects(
1238 LPDIRECTINPUTDEVICE8W iface
,
1239 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback
,
1243 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1245 device_enumobjects_AtoWcb_data data
;
1247 data
.lpCallBack
= lpCallback
;
1248 data
.lpvRef
= lpvRef
;
1250 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A
) This
, (LPDIENUMDEVICEOBJECTSCALLBACKA
) DIEnumDevicesCallbackAtoW
, (LPVOID
) &data
, dwFlags
);
1253 /******************************************************************************
1254 * GetProperty : get input device properties
1256 static HRESULT WINAPI
JoystickAImpl_GetProperty(
1257 LPDIRECTINPUTDEVICE8A iface
,
1259 LPDIPROPHEADER pdiph
)
1261 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1263 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
1265 if (TRACE_ON(dinput
))
1266 _dump_DIPROPHEADER(pdiph
);
1268 if (!HIWORD(rguid
)) {
1269 switch (LOWORD(rguid
)) {
1270 case (DWORD
) DIPROP_RANGE
: {
1271 LPDIPROPRANGE pr
= (LPDIPROPRANGE
) pdiph
;
1272 int obj
= find_property(This
, pdiph
);
1273 /* The app is querying the current range of the axis
1274 * return the lMin and lMax values */
1276 pr
->lMin
= This
->props
[obj
].lMin
;
1277 pr
->lMax
= This
->props
[obj
].lMax
;
1278 TRACE("range(%d, %d) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
1283 case (DWORD
) DIPROP_DEADZONE
: {
1284 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1285 int obj
= find_property(This
, pdiph
);
1287 pd
->dwData
= This
->props
[obj
].lDeadZone
;
1288 TRACE("deadzone(%d) obj=%d\n", pd
->dwData
, obj
);
1293 case (DWORD
) DIPROP_SATURATION
: {
1294 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1295 int obj
= find_property(This
, pdiph
);
1297 pd
->dwData
= This
->props
[obj
].lSaturation
;
1298 TRACE("saturation(%d) obj=%d\n", pd
->dwData
, obj
);
1304 return IDirectInputDevice2AImpl_GetProperty(iface
, rguid
, pdiph
);
1311 /******************************************************************************
1312 * GetObjectInfo : get object info
1314 HRESULT WINAPI
JoystickAImpl_GetObjectInfo(
1315 LPDIRECTINPUTDEVICE8A iface
,
1316 LPDIDEVICEOBJECTINSTANCEA pdidoi
,
1320 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1321 DIDEVICEOBJECTINSTANCEA didoiA
;
1324 TRACE("(%p,%p,%d,0x%08x(%s))\n",
1325 iface
, pdidoi
, dwObj
, dwHow
,
1326 dwHow
== DIPH_BYOFFSET
? "DIPH_BYOFFSET" :
1327 dwHow
== DIPH_BYID
? "DIPH_BYID" :
1328 dwHow
== DIPH_BYUSAGE
? "DIPH_BYUSAGE" :
1331 if (pdidoi
== NULL
) {
1332 WARN("invalid parameter: pdidoi = NULL\n");
1333 return DIERR_INVALIDPARAM
;
1336 if ((pdidoi
->dwSize
!= sizeof(DIDEVICEOBJECTINSTANCEA
)) &&
1337 (pdidoi
->dwSize
!= sizeof(DIDEVICEOBJECTINSTANCE_DX3A
))) {
1338 WARN("invalid parameter: pdidoi->dwSize = %d != %d or %d\n",
1339 pdidoi
->dwSize
, sizeof(DIDEVICEOBJECTINSTANCEA
),
1340 sizeof(DIDEVICEOBJECTINSTANCE_DX3A
));
1341 return DIERR_INVALIDPARAM
;
1344 ZeroMemory(&didoiA
, sizeof(didoiA
));
1345 didoiA
.dwSize
= pdidoi
->dwSize
;
1348 case DIPH_BYOFFSET
: {
1352 for (i
= 0; i
< This
->user_df
->dwNumObjs
; i
++) {
1353 if (This
->user_df
->rgodf
[i
].dwOfs
== dwObj
) {
1354 if (This
->user_df
->rgodf
[i
].pguid
)
1355 didoiA
.guidType
= *This
->user_df
->rgodf
[i
].pguid
;
1357 didoiA
.guidType
= GUID_NULL
;
1359 didoiA
.dwOfs
= dwObj
;
1360 didoiA
.dwType
= This
->user_df
->rgodf
[i
].dwType
;
1361 didoiA
.dwFlags
= This
->user_df
->rgodf
[i
].dwFlags
;
1363 if (DIDFT_GETTYPE(This
->user_df
->rgodf
[i
].dwType
) & DIDFT_AXIS
)
1364 sprintf(didoiA
.tszName
, "Axis %d", axis
);
1365 else if (DIDFT_GETTYPE(This
->user_df
->rgodf
[i
].dwType
) & DIDFT_POV
)
1366 sprintf(didoiA
.tszName
, "POV %d", pov
);
1367 else if (DIDFT_GETTYPE(This
->user_df
->rgodf
[i
].dwType
) & DIDFT_BUTTON
)
1368 sprintf(didoiA
.tszName
, "Button %d", button
);
1370 CopyMemory(pdidoi
, &didoiA
, pdidoi
->dwSize
);
1374 if (DIDFT_GETTYPE(This
->user_df
->rgodf
[i
].dwType
) & DIDFT_AXIS
)
1376 else if (DIDFT_GETTYPE(This
->user_df
->rgodf
[i
].dwType
) & DIDFT_POV
)
1378 else if (DIDFT_GETTYPE(This
->user_df
->rgodf
[i
].dwType
) & DIDFT_BUTTON
)
1384 FIXME("dwHow = DIPH_BYID not implemented\n");
1387 FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1390 WARN("invalid parameter: dwHow = %08x\n", dwHow
);
1391 return DIERR_INVALIDPARAM
;
1394 CopyMemory(pdidoi
, &didoiA
, pdidoi
->dwSize
);
1399 /******************************************************************************
1400 * GetDeviceInfo : get information about a device's identity
1402 HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(
1403 LPDIRECTINPUTDEVICE8A iface
,
1404 LPDIDEVICEINSTANCEA pdidi
)
1406 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1408 TRACE("(%p,%p)\n", iface
, pdidi
);
1410 if (pdidi
== NULL
) {
1411 WARN("invalid pointer\n");
1415 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1416 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
))) {
1417 WARN("invalid parameter: pdidi->dwSize = %d != %d or %d\n",
1418 pdidi
->dwSize
, sizeof(DIDEVICEINSTANCE_DX3A
),
1419 sizeof(DIDEVICEINSTANCEA
));
1420 return DIERR_INVALIDPARAM
;
1423 /* Return joystick */
1424 pdidi
->guidInstance
= GUID_Joystick
;
1425 pdidi
->guidProduct
= DInput_Wine_Joystick_GUID
;
1426 /* we only support traditional joysticks for now */
1427 pdidi
->dwDevType
= This
->devcaps
.dwDevType
;
1428 strcpy(pdidi
->tszInstanceName
, "Joystick");
1429 strcpy(pdidi
->tszProductName
, This
->name
);
1430 if (pdidi
->dwSize
> sizeof(DIDEVICEINSTANCE_DX3A
)) {
1431 pdidi
->guidFFDriver
= GUID_NULL
;
1432 pdidi
->wUsagePage
= 0;
1439 /******************************************************************************
1440 * GetDeviceInfo : get information about a device's identity
1442 HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(
1443 LPDIRECTINPUTDEVICE8W iface
,
1444 LPDIDEVICEINSTANCEW pdidi
)
1446 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1448 TRACE("(%p,%p)\n", iface
, pdidi
);
1450 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1451 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
))) {
1452 WARN("invalid parameter: pdidi->dwSize = %d != %d or %d\n",
1453 pdidi
->dwSize
, sizeof(DIDEVICEINSTANCE_DX3W
),
1454 sizeof(DIDEVICEINSTANCEW
));
1455 return DIERR_INVALIDPARAM
;
1458 /* Return joystick */
1459 pdidi
->guidInstance
= GUID_Joystick
;
1460 pdidi
->guidProduct
= DInput_Wine_Joystick_GUID
;
1461 /* we only support traditional joysticks for now */
1462 pdidi
->dwDevType
= This
->devcaps
.dwDevType
;
1463 MultiByteToWideChar(CP_ACP
, 0, "Joystick", -1, pdidi
->tszInstanceName
, MAX_PATH
);
1464 MultiByteToWideChar(CP_ACP
, 0, This
->name
, -1, pdidi
->tszProductName
, MAX_PATH
);
1465 if (pdidi
->dwSize
> sizeof(DIDEVICEINSTANCE_DX3W
)) {
1466 pdidi
->guidFFDriver
= GUID_NULL
;
1467 pdidi
->wUsagePage
= 0;
1474 static const IDirectInputDevice8AVtbl JoystickAvt
=
1476 IDirectInputDevice2AImpl_QueryInterface
,
1477 IDirectInputDevice2AImpl_AddRef
,
1478 JoystickAImpl_Release
,
1479 JoystickAImpl_GetCapabilities
,
1480 JoystickAImpl_EnumObjects
,
1481 JoystickAImpl_GetProperty
,
1482 JoystickAImpl_SetProperty
,
1483 JoystickAImpl_Acquire
,
1484 JoystickAImpl_Unacquire
,
1485 JoystickAImpl_GetDeviceState
,
1486 IDirectInputDevice2AImpl_GetDeviceData
,
1487 JoystickAImpl_SetDataFormat
,
1488 IDirectInputDevice2AImpl_SetEventNotification
,
1489 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1490 JoystickAImpl_GetObjectInfo
,
1491 JoystickAImpl_GetDeviceInfo
,
1492 IDirectInputDevice2AImpl_RunControlPanel
,
1493 IDirectInputDevice2AImpl_Initialize
,
1494 IDirectInputDevice2AImpl_CreateEffect
,
1495 IDirectInputDevice2AImpl_EnumEffects
,
1496 IDirectInputDevice2AImpl_GetEffectInfo
,
1497 IDirectInputDevice2AImpl_GetForceFeedbackState
,
1498 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
1499 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
1500 IDirectInputDevice2AImpl_Escape
,
1502 IDirectInputDevice2AImpl_SendDeviceData
,
1503 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1504 IDirectInputDevice7AImpl_WriteEffectToFile
,
1505 IDirectInputDevice8AImpl_BuildActionMap
,
1506 IDirectInputDevice8AImpl_SetActionMap
,
1507 IDirectInputDevice8AImpl_GetImageInfo
1510 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1511 # define XCAST(fun) (typeof(SysJoystickWvt.fun))
1513 # define XCAST(fun) (void*)
1516 static const IDirectInputDevice8WVtbl SysJoystickWvt
=
1518 IDirectInputDevice2WImpl_QueryInterface
,
1519 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
1520 XCAST(Release
)JoystickAImpl_Release
,
1521 XCAST(GetCapabilities
)JoystickAImpl_GetCapabilities
,
1522 JoystickWImpl_EnumObjects
,
1523 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1524 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1525 XCAST(Acquire
)JoystickAImpl_Acquire
,
1526 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1527 XCAST(GetDeviceState
)JoystickAImpl_GetDeviceState
,
1528 XCAST(GetDeviceData
)IDirectInputDevice2AImpl_GetDeviceData
,
1529 XCAST(SetDataFormat
)JoystickAImpl_SetDataFormat
,
1530 XCAST(SetEventNotification
)IDirectInputDevice2AImpl_SetEventNotification
,
1531 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
1532 IDirectInputDevice2WImpl_GetObjectInfo
,
1533 JoystickWImpl_GetDeviceInfo
,
1534 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
1535 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
1536 XCAST(CreateEffect
)IDirectInputDevice2AImpl_CreateEffect
,
1537 IDirectInputDevice2WImpl_EnumEffects
,
1538 IDirectInputDevice2WImpl_GetEffectInfo
,
1539 XCAST(GetForceFeedbackState
)IDirectInputDevice2AImpl_GetForceFeedbackState
,
1540 XCAST(SendForceFeedbackCommand
)IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
1541 XCAST(EnumCreatedEffectObjects
)IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
1542 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1543 XCAST(Poll
)JoystickAImpl_Poll
,
1544 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1545 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1546 IDirectInputDevice7WImpl_WriteEffectToFile
,
1547 IDirectInputDevice8WImpl_BuildActionMap
,
1548 IDirectInputDevice8WImpl_SetActionMap
,
1549 IDirectInputDevice8WImpl_GetImageInfo
1553 #else /* HAVE_LINUX_22_JOYSTICK_API */
1555 const struct dinput_device joystick_linux_device
= {
1556 "Wine Linux joystick driver",
1563 #endif /* HAVE_LINUX_22_JOYSTICK_API */