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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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>
57 #include "wine/debug.h"
58 #include "wine/unicode.h"
65 #include "dinput_private.h"
66 #include "device_private.h"
68 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
70 #ifdef HAVE_LINUX_22_JOYSTICK_API
72 #define JOYDEV "/dev/js"
86 typedef struct JoystickImpl JoystickImpl
;
87 static const IDirectInputDevice8AVtbl JoystickAvt
;
88 static const IDirectInputDevice8WVtbl JoystickWvt
;
96 /* The 'parent' DInput */
97 IDirectInputImpl
*dinput
;
99 /* joystick private */
101 DIJOYSTATE2 js
; /* wine data */
102 LPDIDATAFORMAT user_df
; /* user defined format */
103 DataFormat
*transform
; /* wine to user format converter */
104 int *offsets
; /* object offsets */
107 LPDIDEVICEOBJECTDATA data_queue
;
108 int queue_head
, queue_tail
, queue_len
;
117 CRITICAL_SECTION crit
;
121 static GUID DInput_Wine_Joystick_GUID
= { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
125 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
128 static void _dump_DIDEVCAPS(LPDIDEVCAPS lpDIDevCaps
)
130 TRACE("dwSize: %ld\n", lpDIDevCaps
->dwSize
);
131 TRACE("dwFlags: %08lx\n",lpDIDevCaps
->dwFlags
);
132 TRACE("dwDevType: %08lx %s\n", lpDIDevCaps
->dwDevType
,
133 lpDIDevCaps
->dwDevType
== DIDEVTYPE_DEVICE
? "DIDEVTYPE_DEVICE" :
134 lpDIDevCaps
->dwDevType
== DIDEVTYPE_DEVICE
? "DIDEVTYPE_DEVICE" :
135 lpDIDevCaps
->dwDevType
== DIDEVTYPE_MOUSE
? "DIDEVTYPE_MOUSE" :
136 lpDIDevCaps
->dwDevType
== DIDEVTYPE_KEYBOARD
? "DIDEVTYPE_KEYBOARD" :
137 lpDIDevCaps
->dwDevType
== DIDEVTYPE_JOYSTICK
? "DIDEVTYPE_JOYSTICK" :
138 lpDIDevCaps
->dwDevType
== DIDEVTYPE_HID
? "DIDEVTYPE_HID" : "UNKNOWN");
139 TRACE("dwAxes: %ld\n",lpDIDevCaps
->dwAxes
);
140 TRACE("dwButtons: %ld\n",lpDIDevCaps
->dwButtons
);
141 TRACE("dwPOVs: %ld\n",lpDIDevCaps
->dwPOVs
);
142 if (lpDIDevCaps
->dwSize
> sizeof(DIDEVCAPS_DX3
)) {
143 TRACE("dwFFSamplePeriod: %ld\n",lpDIDevCaps
->dwFFSamplePeriod
);
144 TRACE("dwFFMinTimeResolution: %ld\n",lpDIDevCaps
->dwFFMinTimeResolution
);
145 TRACE("dwFirmwareRevision: %ld\n",lpDIDevCaps
->dwFirmwareRevision
);
146 TRACE("dwHardwareRevision: %ld\n",lpDIDevCaps
->dwHardwareRevision
);
147 TRACE("dwFFDriverVersion: %ld\n",lpDIDevCaps
->dwFFDriverVersion
);
151 static BOOL
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
156 if (dwFlags
& DIEDFL_FORCEFEEDBACK
) {
157 WARN("force feedback not supported\n");
161 if ((dwDevType
== 0) ||
162 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
163 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))) {
164 /* check whether we have a joystick */
165 sprintf(dev
, "%s%d", JOYDEV
, id
);
166 if ((fd
= open(dev
,O_RDONLY
)) < 0) {
167 WARN("open(%s,O_RDONLY) failed: %s\n", dev
, strerror(errno
));
171 /* Return joystick */
172 lpddi
->guidInstance
= DInput_Wine_Joystick_GUID
;
173 lpddi
->guidInstance
.Data3
= id
;
174 lpddi
->guidProduct
= DInput_Wine_Joystick_GUID
;
175 /* we only support traditional joysticks for now */
176 if (version
>= 0x0800)
177 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
179 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
180 sprintf(lpddi
->tszInstanceName
, "Joystick %d", id
);
181 #if defined(JSIOCGNAME)
182 if (ioctl(fd
,JSIOCGNAME(sizeof(lpddi
->tszProductName
)),lpddi
->tszProductName
) < 0) {
183 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", dev
, strerror(errno
));
184 strcpy(lpddi
->tszProductName
, "Wine Joystick");
187 strcpy(lpddi
->tszProductName
, "Wine Joystick");
190 lpddi
->guidFFDriver
= GUID_NULL
;
192 TRACE("Enumerating the linux Joystick device: %s (%s)\n", dev
, lpddi
->tszProductName
);
199 static BOOL
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
206 if (dwFlags
& DIEDFL_FORCEFEEDBACK
) {
207 WARN("force feedback not supported\n");
211 if ((dwDevType
== 0) ||
212 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
213 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))) {
214 /* check whether we have a joystick */
215 sprintf(dev
, "%s%d", JOYDEV
, id
);
216 if ((fd
= open(dev
,O_RDONLY
)) < 0) {
217 WARN("open(%s,O_RDONLY) failed: %s\n", dev
, strerror(errno
));
221 /* Return joystick */
222 lpddi
->guidInstance
= DInput_Wine_Joystick_GUID
;
223 lpddi
->guidInstance
.Data3
= id
;
224 lpddi
->guidProduct
= DInput_Wine_Joystick_GUID
;
225 /* we only support traditional joysticks for now */
226 if (version
>= 0x0800)
227 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
229 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
230 sprintf(friendly
, "Joystick %d", id
);
231 MultiByteToWideChar(CP_ACP
, 0, friendly
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
232 #if defined(JSIOCGNAME)
233 if (ioctl(fd
,JSIOCGNAME(sizeof(name
)),name
) < 0) {
234 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", dev
, strerror(errno
));
235 strcpy(name
, "Wine Joystick");
238 strcpy(name
, "Wine Joystick");
240 MultiByteToWideChar(CP_ACP
, 0, name
, -1, lpddi
->tszProductName
, MAX_PATH
);
241 lpddi
->guidFFDriver
= GUID_NULL
;
243 TRACE("Enumerating the linux Joystick device: %s (%s)\n",dev
,name
);
251 * Get a config key from either the app-specific or the default config
254 inline static DWORD
get_config_key( HKEY defkey
, HKEY appkey
, const char *name
,
255 char *buffer
, DWORD size
)
257 if (appkey
&& !RegQueryValueExA( appkey
, name
, 0, NULL
, (LPBYTE
)buffer
, &size
))
260 if (defkey
&& !RegQueryValueExA( defkey
, name
, 0, NULL
, (LPBYTE
)buffer
, &size
))
263 return ERROR_FILE_NOT_FOUND
;
267 * Setup the dinput options.
270 static HRESULT
setup_dinput_options(JoystickImpl
* device
)
272 char buffer
[MAX_PATH
+16];
273 HKEY hkey
, appkey
= 0;
276 buffer
[MAX_PATH
]='\0';
278 /* @@ Wine registry key: HKCU\Software\Wine\DirectInput */
279 if (RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\DirectInput", &hkey
)) hkey
= 0;
281 len
= GetModuleFileNameA( 0, buffer
, MAX_PATH
);
282 if (len
&& len
< MAX_PATH
) {
284 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectInput */
285 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\AppDefaults", &tmpkey
))
287 char *p
, *appname
= buffer
;
288 if ((p
= strrchr( appname
, '/' ))) appname
= p
+ 1;
289 if ((p
= strrchr( appname
, '\\' ))) appname
= p
+ 1;
290 strcat( appname
, "\\DirectInput" );
291 if (RegOpenKeyA( tmpkey
, appname
, &appkey
)) appkey
= 0;
292 RegCloseKey( tmpkey
);
298 if (!get_config_key( hkey
, appkey
, "DefaultDeadZone", buffer
, MAX_PATH
)) {
299 device
->deadzone
= atoi(buffer
);
300 TRACE("setting default deadzone to: \"%s\" %ld\n", buffer
, device
->deadzone
);
303 if (!get_config_key( hkey
, appkey
, device
->name
, buffer
, MAX_PATH
)) {
307 const char *delim
= ",";
309 TRACE("\"%s\" = \"%s\"\n", device
->name
, buffer
);
311 device
->axis_map
= HeapAlloc(GetProcessHeap(), 0, device
->axes
* sizeof(int));
312 if (device
->axis_map
== 0)
313 return DIERR_OUTOFMEMORY
;
315 if ((ptr
= strtok(buffer
, delim
)) != NULL
) {
317 if (strcmp(ptr
, "X") == 0) {
318 device
->axis_map
[tokens
] = 0;
320 } else if (strcmp(ptr
, "Y") == 0) {
321 device
->axis_map
[tokens
] = 1;
323 } else if (strcmp(ptr
, "Z") == 0) {
324 device
->axis_map
[tokens
] = 2;
326 } else if (strcmp(ptr
, "Rx") == 0) {
327 device
->axis_map
[tokens
] = 3;
329 } else if (strcmp(ptr
, "Ry") == 0) {
330 device
->axis_map
[tokens
] = 4;
332 } else if (strcmp(ptr
, "Rz") == 0) {
333 device
->axis_map
[tokens
] = 5;
335 } else if (strcmp(ptr
, "Slider1") == 0) {
336 device
->axis_map
[tokens
] = 6;
338 } else if (strcmp(ptr
, "Slider2") == 0) {
339 device
->axis_map
[tokens
] = 7;
341 } else if (strcmp(ptr
, "POV1") == 0) {
342 device
->axis_map
[tokens
++] = 8;
343 device
->axis_map
[tokens
] = 8;
345 } else if (strcmp(ptr
, "POV2") == 0) {
346 device
->axis_map
[tokens
++] = 9;
347 device
->axis_map
[tokens
] = 9;
349 } else if (strcmp(ptr
, "POV3") == 0) {
350 device
->axis_map
[tokens
++] = 10;
351 device
->axis_map
[tokens
] = 10;
353 } else if (strcmp(ptr
, "POV4") == 0) {
354 device
->axis_map
[tokens
++] = 11;
355 device
->axis_map
[tokens
] = 11;
358 ERR("invalid joystick axis type: %s\n", ptr
);
359 device
->axis_map
[tokens
] = tokens
;
364 } while ((ptr
= strtok(NULL
, delim
)) != NULL
);
366 if (tokens
!= device
->devcaps
.dwAxes
) {
367 ERR("not all joystick axes mapped: %d axes(%d,%d), %d arguments\n", device
->axes
, axis
, pov
,tokens
);
368 while (tokens
< device
->axes
) {
369 device
->axis_map
[tokens
] = tokens
;
375 device
->devcaps
.dwAxes
= axis
;
376 device
->devcaps
.dwPOVs
= pov
;
380 RegCloseKey( appkey
);
388 static void calculate_ids(JoystickImpl
* device
)
398 /* Make two passes over the format. The first counts the number
399 * for each type and the second sets the id */
400 for (i
= 0; i
< device
->user_df
->dwNumObjs
; i
++) {
401 if (DIDFT_GETTYPE(device
->user_df
->rgodf
[i
].dwType
) & DIDFT_AXIS
)
403 else if (DIDFT_GETTYPE(device
->user_df
->rgodf
[i
].dwType
) & DIDFT_POV
)
405 else if (DIDFT_GETTYPE(device
->user_df
->rgodf
[i
].dwType
) & DIDFT_BUTTON
)
411 button_base
= axis
+ pov
;
417 for (i
= 0; i
< device
->user_df
->dwNumObjs
; i
++) {
419 if (DIDFT_GETTYPE(device
->user_df
->rgodf
[i
].dwType
) & DIDFT_AXIS
) {
421 type
= DIDFT_GETTYPE(device
->user_df
->rgodf
[i
].dwType
) |
422 DIDFT_MAKEINSTANCE(axis
+ axis_base
);
423 TRACE("axis type = 0x%08lx\n", type
);
424 } else if (DIDFT_GETTYPE(device
->user_df
->rgodf
[i
].dwType
) & DIDFT_POV
) {
426 type
= DIDFT_GETTYPE(device
->user_df
->rgodf
[i
].dwType
) |
427 DIDFT_MAKEINSTANCE(pov
+ pov_base
);
428 TRACE("POV type = 0x%08lx\n", type
);
429 } else if (DIDFT_GETTYPE(device
->user_df
->rgodf
[i
].dwType
) & DIDFT_BUTTON
) {
431 type
= DIDFT_GETTYPE(device
->user_df
->rgodf
[i
].dwType
) |
432 DIDFT_MAKEINSTANCE(button
+ button_base
);
433 TRACE("button type = 0x%08lx\n", type
);
435 device
->user_df
->rgodf
[i
].dwType
= type
;
439 static HRESULT
alloc_device(REFGUID rguid
, const void *jvt
, IDirectInputImpl
*dinput
, LPDIRECTINPUTDEVICEA
* pdev
)
442 JoystickImpl
* newDevice
;
446 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(JoystickImpl
));
447 if (newDevice
== 0) {
448 WARN("out of memory\n");
450 return DIERR_OUTOFMEMORY
;
453 sprintf(newDevice
->dev
, "%s%d", JOYDEV
, rguid
->Data3
);
455 if ((newDevice
->joyfd
= open(newDevice
->dev
,O_RDONLY
)) < 0) {
456 WARN("open(%s,O_RDONLY) failed: %s\n", newDevice
->dev
, strerror(errno
));
457 HeapFree(GetProcessHeap(), 0, newDevice
);
458 return DIERR_DEVICENOTREG
;
461 /* get the device name */
462 #if defined(JSIOCGNAME)
463 if (ioctl(newDevice
->joyfd
,JSIOCGNAME(MAX_PATH
),name
) < 0) {
464 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", newDevice
->dev
, strerror(errno
));
465 strcpy(name
, "Wine Joystick");
468 strcpy(name
, "Wine Joystick");
471 /* copy the device name */
472 newDevice
->name
= HeapAlloc(GetProcessHeap(),0,strlen(name
) + 1);
473 strcpy(newDevice
->name
, name
);
476 if (ioctl(newDevice
->joyfd
,JSIOCGAXES
,&newDevice
->axes
) < 0) {
477 WARN("ioctl(%s,JSIOCGAXES) failed: %s, defauting to 2\n", newDevice
->dev
, strerror(errno
));
482 if (ioctl(newDevice
->joyfd
,JSIOCGBUTTONS
,&newDevice
->buttons
) < 0) {
483 WARN("ioctl(%s,JSIOCGBUTTONS) failed: %s, defauting to 2\n", newDevice
->dev
, strerror(errno
));
484 newDevice
->buttons
= 2;
488 newDevice
->lpVtbl
= jvt
;
490 newDevice
->dinput
= dinput
;
491 newDevice
->acquired
= FALSE
;
492 newDevice
->overflow
= FALSE
;
493 CopyMemory(&(newDevice
->guid
),rguid
,sizeof(*rguid
));
495 /* setup_dinput_options may change these */
496 newDevice
->deadzone
= 5000;
497 newDevice
->devcaps
.dwButtons
= newDevice
->buttons
;
498 newDevice
->devcaps
.dwAxes
= newDevice
->axes
;
499 newDevice
->devcaps
.dwPOVs
= 0;
501 /* do any user specified configuration */
502 hr
= setup_dinput_options(newDevice
);
506 if (newDevice
->axis_map
== 0) {
507 newDevice
->axis_map
= HeapAlloc(GetProcessHeap(), 0, newDevice
->axes
* sizeof(int));
508 if (newDevice
->axis_map
== 0)
511 for (i
= 0; i
< newDevice
->axes
; i
++)
512 newDevice
->axis_map
[i
] = i
;
515 /* wine uses DIJOYSTATE2 as it's internal format so copy
516 * the already defined format c_dfDIJoystick2 */
517 newDevice
->user_df
= HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2
.dwSize
);
518 if (newDevice
->user_df
== 0)
521 CopyMemory(newDevice
->user_df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
523 /* copy default objects */
524 newDevice
->user_df
->rgodf
= HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2
.dwNumObjs
*c_dfDIJoystick2
.dwObjSize
);
525 if (newDevice
->user_df
->rgodf
== 0)
528 CopyMemory(newDevice
->user_df
->rgodf
,c_dfDIJoystick2
.rgodf
,c_dfDIJoystick2
.dwNumObjs
*c_dfDIJoystick2
.dwObjSize
);
530 /* create default properties */
531 newDevice
->props
= HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2
.dwNumObjs
*sizeof(ObjProps
));
532 if (newDevice
->props
== 0)
535 /* initialize default properties */
536 for (i
= 0; i
< c_dfDIJoystick2
.dwNumObjs
; i
++) {
537 newDevice
->props
[i
].lMin
= 0;
538 newDevice
->props
[i
].lMax
= 0xffff;
539 newDevice
->props
[i
].lDeadZone
= newDevice
->deadzone
; /* % * 1000 */
540 newDevice
->props
[i
].lSaturation
= 0;
543 /* create an offsets array */
544 newDevice
->offsets
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,c_dfDIJoystick2
.dwNumObjs
*sizeof(int));
545 if (newDevice
->offsets
== 0)
548 /* create the default transform filter */
549 newDevice
->transform
= create_DataFormat(&c_dfDIJoystick2
, newDevice
->user_df
, newDevice
->offsets
);
551 calculate_ids(newDevice
);
553 IDirectInputDevice_AddRef((LPDIRECTINPUTDEVICE8A
)newDevice
->dinput
);
554 InitializeCriticalSection(&(newDevice
->crit
));
555 newDevice
->crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)"DINPUT_Mouse";
557 newDevice
->devcaps
.dwSize
= sizeof(newDevice
->devcaps
);
558 newDevice
->devcaps
.dwFlags
= DIDC_ATTACHED
;
559 if (newDevice
->dinput
->dwVersion
>= 0x0800)
560 newDevice
->devcaps
.dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
562 newDevice
->devcaps
.dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
563 newDevice
->devcaps
.dwFFSamplePeriod
= 0;
564 newDevice
->devcaps
.dwFFMinTimeResolution
= 0;
565 newDevice
->devcaps
.dwFirmwareRevision
= 0;
566 newDevice
->devcaps
.dwHardwareRevision
= 0;
567 newDevice
->devcaps
.dwFFDriverVersion
= 0;
569 if (TRACE_ON(dinput
)) {
570 _dump_DIDATAFORMAT(newDevice
->user_df
);
571 for (i
= 0; i
< (newDevice
->axes
); i
++)
572 TRACE("axis_map[%ld] = %d\n", i
, newDevice
->axis_map
[i
]);
573 _dump_DIDEVCAPS(&newDevice
->devcaps
);
576 *pdev
= (LPDIRECTINPUTDEVICEA
)newDevice
;
581 hr
= DIERR_OUTOFMEMORY
;
583 HeapFree(GetProcessHeap(),0,newDevice
->axis_map
);
584 HeapFree(GetProcessHeap(),0,newDevice
->name
);
585 HeapFree(GetProcessHeap(),0,newDevice
->props
);
586 HeapFree(GetProcessHeap(),0,newDevice
->user_df
->rgodf
);
587 HeapFree(GetProcessHeap(),0,newDevice
->user_df
);
588 HeapFree(GetProcessHeap(),0,newDevice
);
594 static BOOL
IsJoystickGUID(REFGUID guid
)
596 GUID wine_joystick
= DInput_Wine_Joystick_GUID
;
597 GUID dev_guid
= *guid
;
599 wine_joystick
.Data3
= 0;
602 return IsEqualGUID(&wine_joystick
, &dev_guid
);
605 static HRESULT
joydev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
607 if ((IsEqualGUID(&GUID_Joystick
,rguid
)) ||
608 (IsJoystickGUID(rguid
))) {
609 if ((riid
== NULL
) ||
610 IsEqualGUID(&IID_IDirectInputDeviceA
,riid
) ||
611 IsEqualGUID(&IID_IDirectInputDevice2A
,riid
) ||
612 IsEqualGUID(&IID_IDirectInputDevice7A
,riid
) ||
613 IsEqualGUID(&IID_IDirectInputDevice8A
,riid
)) {
614 return alloc_device(rguid
, &JoystickAvt
, dinput
, pdev
);
616 WARN("no interface\n");
618 return DIERR_NOINTERFACE
;
622 WARN("invalid device GUID\n");
624 return DIERR_DEVICENOTREG
;
627 static HRESULT
joydev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
629 if ((IsEqualGUID(&GUID_Joystick
,rguid
)) ||
630 (IsJoystickGUID(rguid
))) {
631 if ((riid
== NULL
) ||
632 IsEqualGUID(&IID_IDirectInputDeviceW
,riid
) ||
633 IsEqualGUID(&IID_IDirectInputDevice2W
,riid
) ||
634 IsEqualGUID(&IID_IDirectInputDevice7W
,riid
) ||
635 IsEqualGUID(&IID_IDirectInputDevice8W
,riid
)) {
636 return alloc_device(rguid
, &JoystickWvt
, dinput
, (LPDIRECTINPUTDEVICEA
*)pdev
);
638 WARN("no interface\n");
640 return DIERR_NOINTERFACE
;
644 WARN("invalid device GUID\n");
646 return DIERR_DEVICENOTREG
;
649 const struct dinput_device joystick_linux_device
= {
650 "Wine Linux joystick driver",
653 joydev_create_deviceA
,
654 joydev_create_deviceW
657 /******************************************************************************
660 static ULONG WINAPI
JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface
)
662 JoystickImpl
*This
= (JoystickImpl
*)iface
;
665 ref
= InterlockedDecrement((&This
->ref
));
669 /* Free the device name */
670 HeapFree(GetProcessHeap(),0,This
->name
);
672 /* Free the axis map */
673 HeapFree(GetProcessHeap(),0,This
->axis_map
);
675 /* Free the data queue */
676 HeapFree(GetProcessHeap(),0,This
->data_queue
);
678 /* Free the DataFormat */
679 HeapFree(GetProcessHeap(), 0, This
->user_df
->rgodf
);
680 HeapFree(GetProcessHeap(), 0, This
->user_df
);
682 /* Free the properties */
683 HeapFree(GetProcessHeap(), 0, This
->props
);
685 /* Free the offsets array */
686 HeapFree(GetProcessHeap(),0,This
->offsets
);
688 /* release the data transform filter */
689 release_DataFormat(This
->transform
);
691 This
->crit
.DebugInfo
->Spare
[0] = 0;
692 DeleteCriticalSection(&(This
->crit
));
693 IDirectInputDevice_Release((LPDIRECTINPUTDEVICE8A
)This
->dinput
);
695 HeapFree(GetProcessHeap(),0,This
);
699 /******************************************************************************
700 * SetDataFormat : the application can choose the format of the data
701 * the device driver sends back with GetDeviceState.
703 static HRESULT WINAPI
JoystickAImpl_SetDataFormat(
704 LPDIRECTINPUTDEVICE8A iface
,
707 JoystickImpl
*This
= (JoystickImpl
*)iface
;
709 LPDIDATAFORMAT new_df
= 0;
710 LPDIOBJECTDATAFORMAT new_rgodf
= 0;
711 ObjProps
* new_props
= 0;
713 TRACE("(%p,%p)\n",This
,df
);
716 WARN("invalid pointer\n");
720 if (df
->dwSize
!= sizeof(*df
)) {
721 WARN("invalid argument\n");
722 return DIERR_INVALIDPARAM
;
725 if (This
->acquired
) {
727 return DIERR_ACQUIRED
;
730 if (TRACE_ON(dinput
))
731 _dump_DIDATAFORMAT(df
);
733 /* Store the new data format */
734 new_df
= HeapAlloc(GetProcessHeap(),0,df
->dwSize
);
738 new_rgodf
= HeapAlloc(GetProcessHeap(),0,df
->dwNumObjs
*df
->dwObjSize
);
742 new_props
= HeapAlloc(GetProcessHeap(),0,df
->dwNumObjs
*sizeof(ObjProps
));
746 HeapFree(GetProcessHeap(),0,This
->user_df
);
747 HeapFree(GetProcessHeap(),0,This
->user_df
->rgodf
);
748 HeapFree(GetProcessHeap(),0,This
->props
);
749 release_DataFormat(This
->transform
);
751 This
->user_df
= new_df
;
752 CopyMemory(This
->user_df
, df
, df
->dwSize
);
753 This
->user_df
->rgodf
= new_rgodf
;
754 CopyMemory(This
->user_df
->rgodf
,df
->rgodf
,df
->dwNumObjs
*df
->dwObjSize
);
755 This
->props
= new_props
;
756 for (i
= 0; i
< df
->dwNumObjs
; i
++) {
757 This
->props
[i
].lMin
= 0;
758 This
->props
[i
].lMax
= 0xffff;
759 This
->props
[i
].lDeadZone
= 1000;
760 This
->props
[i
].lSaturation
= 0;
762 This
->transform
= create_DataFormat(&c_dfDIJoystick2
, This
->user_df
, This
->offsets
);
769 WARN("out of memory\n");
770 HeapFree(GetProcessHeap(),0,new_props
);
771 HeapFree(GetProcessHeap(),0,new_rgodf
);
772 HeapFree(GetProcessHeap(),0,new_df
);
773 return DIERR_OUTOFMEMORY
;
776 /******************************************************************************
777 * Acquire : gets exclusive control of the joystick
779 static HRESULT WINAPI
JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
781 JoystickImpl
*This
= (JoystickImpl
*)iface
;
783 TRACE("(%p)\n",This
);
785 if (This
->acquired
) {
786 WARN("already acquired\n");
790 /* open the joystick device */
791 if (This
->joyfd
==-1) {
792 TRACE("opening joystick device %s\n", This
->dev
);
794 This
->joyfd
=open(This
->dev
,O_RDONLY
);
795 if (This
->joyfd
==-1) {
796 ERR("open(%s) failed: %s\n", This
->dev
, strerror(errno
));
797 return DIERR_NOTFOUND
;
801 This
->acquired
= TRUE
;
806 /******************************************************************************
807 * Unacquire : frees the joystick
809 static HRESULT WINAPI
JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
811 JoystickImpl
*This
= (JoystickImpl
*)iface
;
813 TRACE("(%p)\n",This
);
815 if (!This
->acquired
) {
816 WARN("not acquired\n");
817 return DIERR_NOTACQUIRED
;
820 if (This
->joyfd
!=-1) {
821 TRACE("closing joystick device\n");
824 This
->acquired
= FALSE
;
828 This
->acquired
= FALSE
;
833 static LONG
map_axis(JoystickImpl
* This
, short val
, short index
)
836 double fmin
= This
->props
[index
].lMin
;
837 double fmax
= This
->props
[index
].lMax
;
840 fret
= (((fval
+ 32767.0) * (fmax
- fmin
)) / (32767.0*2.0)) + fmin
;
850 /* convert wine format offset to user format object index */
851 static int offset_to_object(JoystickImpl
*This
, int offset
)
855 for (i
= 0; i
< This
->user_df
->dwNumObjs
; i
++) {
856 if (This
->user_df
->rgodf
[i
].dwOfs
== offset
)
863 static LONG
calculate_pov(JoystickImpl
*This
, int index
)
865 if (This
->povs
[index
].lX
< 16384) {
866 if (This
->povs
[index
].lY
< 16384)
867 This
->js
.rgdwPOV
[index
] = 31500;
868 else if (This
->povs
[index
].lY
> 49150)
869 This
->js
.rgdwPOV
[index
] = 22500;
871 This
->js
.rgdwPOV
[index
] = 27000;
872 } else if (This
->povs
[index
].lX
> 49150) {
873 if (This
->povs
[index
].lY
< 16384)
874 This
->js
.rgdwPOV
[index
] = 4500;
875 else if (This
->povs
[index
].lY
> 49150)
876 This
->js
.rgdwPOV
[index
] = 13500;
878 This
->js
.rgdwPOV
[index
] = 9000;
880 if (This
->povs
[index
].lY
< 16384)
881 This
->js
.rgdwPOV
[index
] = 0;
882 else if (This
->povs
[index
].lY
> 49150)
883 This
->js
.rgdwPOV
[index
] = 18000;
885 This
->js
.rgdwPOV
[index
] = -1;
888 return This
->js
.rgdwPOV
[index
];
891 static void joy_polldev(JoystickImpl
*This
) {
895 TRACE("(%p)\n", This
);
897 if (This
->joyfd
==-1) {
902 memset(&tv
,0,sizeof(tv
));
903 FD_ZERO(&readfds
);FD_SET(This
->joyfd
,&readfds
);
904 if (1>select(This
->joyfd
+1,&readfds
,NULL
,NULL
,&tv
))
906 /* we have one event, so we can read */
907 if (sizeof(jse
)!=read(This
->joyfd
,&jse
,sizeof(jse
))) {
910 TRACE("js_event: type 0x%x, number %d, value %d\n",
911 jse
.type
,jse
.number
,jse
.value
);
912 if (jse
.type
& JS_EVENT_BUTTON
) {
913 int offset
= This
->offsets
[jse
.number
+ 12];
914 int value
= jse
.value
?0x80:0x00;
916 This
->js
.rgbButtons
[jse
.number
] = value
;
917 GEN_EVENT(offset
,value
,jse
.time
,(This
->dinput
->evsequence
)++);
918 } else if (jse
.type
& JS_EVENT_AXIS
) {
919 int number
= This
->axis_map
[jse
.number
]; /* wine format object index */
921 int offset
= This
->offsets
[number
];
922 int index
= offset_to_object(This
, offset
);
923 LONG value
= map_axis(This
, jse
.value
, index
);
925 /* FIXME do deadzone and saturation here */
927 TRACE("changing axis %d => %d\n", jse
.number
, number
);
939 This
->js
.lRx
= value
;
942 This
->js
.lRy
= value
;
945 This
->js
.lRz
= value
;
948 This
->js
.rglSlider
[0] = value
;
951 This
->js
.rglSlider
[1] = value
;
954 /* FIXME don't go off array */
955 if (This
->axis_map
[jse
.number
+ 1] == number
)
956 This
->povs
[0].lX
= value
;
957 else if (This
->axis_map
[jse
.number
- 1] == number
)
958 This
->povs
[0].lY
= value
;
959 value
= calculate_pov(This
, 0);
962 if (This
->axis_map
[jse
.number
+ 1] == number
)
963 This
->povs
[1].lX
= value
;
964 else if (This
->axis_map
[jse
.number
- 1] == number
)
965 This
->povs
[1].lY
= value
;
966 value
= calculate_pov(This
, 1);
969 if (This
->axis_map
[jse
.number
+ 1] == number
)
970 This
->povs
[2].lX
= value
;
971 else if (This
->axis_map
[jse
.number
- 1] == number
)
972 This
->povs
[2].lY
= value
;
973 value
= calculate_pov(This
, 2);
976 if (This
->axis_map
[jse
.number
+ 1] == number
)
977 This
->povs
[3].lX
= value
;
978 else if (This
->axis_map
[jse
.number
- 1] == number
)
979 This
->povs
[3].lY
= value
;
980 value
= calculate_pov(This
, 3);
984 GEN_EVENT(offset
,value
,jse
.time
,(This
->dinput
->evsequence
)++);
986 WARN("axis %d not supported\n", number
);
991 /******************************************************************************
992 * GetDeviceState : returns the "state" of the joystick.
995 static HRESULT WINAPI
JoystickAImpl_GetDeviceState(
996 LPDIRECTINPUTDEVICE8A iface
,
1000 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1002 TRACE("(%p,0x%08lx,%p)\n",This
,len
,ptr
);
1004 if (!This
->acquired
) {
1005 WARN("not acquired\n");
1006 return DIERR_NOTACQUIRED
;
1009 /* update joystick state */
1012 /* convert and copy data to user supplied buffer */
1013 fill_DataFormat(ptr
, &This
->js
, This
->transform
);
1018 /******************************************************************************
1019 * GetDeviceData : gets buffered input data.
1021 static HRESULT WINAPI
JoystickAImpl_GetDeviceData(
1022 LPDIRECTINPUTDEVICE8A iface
,
1024 LPDIDEVICEOBJECTDATA dod
,
1028 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1033 TRACE("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx)\n",This
,dodsize
,*entries
,flags
);
1035 if (!This
->acquired
) {
1036 WARN("not acquired\n");
1037 return DIERR_NOTACQUIRED
;
1040 EnterCriticalSection(&(This
->crit
));
1044 len
= ((This
->queue_head
< This
->queue_tail
) ? This
->queue_len
: 0)
1045 + (This
->queue_head
- This
->queue_tail
);
1051 TRACE("Application discarding %ld event(s).\n", len
);
1054 nqtail
= This
->queue_tail
+ len
;
1055 while (nqtail
>= This
->queue_len
)
1056 nqtail
-= This
->queue_len
;
1058 if (dodsize
< sizeof(DIDEVICEOBJECTDATA_DX3
)) {
1059 ERR("Wrong structure size !\n");
1060 LeaveCriticalSection(&(This
->crit
));
1061 return DIERR_INVALIDPARAM
;
1065 TRACE("Application retrieving %ld event(s).\n", len
);
1068 nqtail
= This
->queue_tail
;
1070 /* Copy the buffered data into the application queue */
1071 memcpy((char *)dod
+ *entries
* dodsize
, This
->data_queue
+ nqtail
, dodsize
);
1072 /* Advance position */
1074 if (nqtail
>= This
->queue_len
)
1075 nqtail
-= This
->queue_len
;
1081 if (This
->overflow
) {
1082 hr
= DI_BUFFEROVERFLOW
;
1083 if (!(flags
& DIGDD_PEEK
)) {
1084 This
->overflow
= FALSE
;
1088 if (!(flags
& DIGDD_PEEK
))
1089 This
->queue_tail
= nqtail
;
1091 LeaveCriticalSection(&(This
->crit
));
1096 static int find_property(JoystickImpl
* This
, LPCDIPROPHEADER ph
)
1099 if (ph
->dwHow
== DIPH_BYOFFSET
) {
1100 return offset_to_object(This
, ph
->dwObj
);
1101 } else if (ph
->dwHow
== DIPH_BYID
) {
1102 for (i
= 0; i
< This
->user_df
->dwNumObjs
; i
++) {
1103 if ((This
->user_df
->rgodf
[i
].dwType
& 0x00ffffff) == (ph
->dwObj
& 0x00ffffff)) {
1112 /******************************************************************************
1113 * SetProperty : change input device properties
1115 static HRESULT WINAPI
JoystickAImpl_SetProperty(
1116 LPDIRECTINPUTDEVICE8A iface
,
1120 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1123 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(rguid
),ph
);
1126 WARN("invalid parameter: ph == NULL\n");
1127 return DIERR_INVALIDPARAM
;
1130 if (TRACE_ON(dinput
))
1131 _dump_DIPROPHEADER(ph
);
1133 if (!HIWORD(rguid
)) {
1134 switch (LOWORD(rguid
)) {
1135 case (DWORD
) DIPROP_BUFFERSIZE
: {
1136 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
1137 TRACE("buffersize = %ld\n",pd
->dwData
);
1138 if (This
->data_queue
)
1139 This
->data_queue
= HeapReAlloc(GetProcessHeap(),0, This
->data_queue
, pd
->dwData
* sizeof(DIDEVICEOBJECTDATA
));
1141 This
->data_queue
= HeapAlloc(GetProcessHeap(),0, pd
->dwData
* sizeof(DIDEVICEOBJECTDATA
));
1142 This
->queue_head
= 0;
1143 This
->queue_tail
= 0;
1144 This
->queue_len
= pd
->dwData
;
1147 case (DWORD
)DIPROP_RANGE
: {
1148 LPCDIPROPRANGE pr
= (LPCDIPROPRANGE
)ph
;
1149 if (ph
->dwHow
== DIPH_DEVICE
) {
1150 TRACE("proprange(%ld,%ld) all\n",pr
->lMin
,pr
->lMax
);
1151 for (i
= 0; i
< This
->user_df
->dwNumObjs
; i
++) {
1152 This
->props
[i
].lMin
= pr
->lMin
;
1153 This
->props
[i
].lMax
= pr
->lMax
;
1156 int obj
= find_property(This
, ph
);
1157 TRACE("proprange(%ld,%ld) obj=%d\n",pr
->lMin
,pr
->lMax
,obj
);
1159 This
->props
[obj
].lMin
= pr
->lMin
;
1160 This
->props
[obj
].lMax
= pr
->lMax
;
1166 case (DWORD
)DIPROP_DEADZONE
: {
1167 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
1168 if (ph
->dwHow
== DIPH_DEVICE
) {
1169 TRACE("deadzone(%ld) all\n",pd
->dwData
);
1170 for (i
= 0; i
< This
->user_df
->dwNumObjs
; i
++)
1171 This
->props
[i
].lDeadZone
= pd
->dwData
;
1173 int obj
= find_property(This
, ph
);
1174 TRACE("deadzone(%ld) obj=%d\n",pd
->dwData
,obj
);
1176 This
->props
[obj
].lDeadZone
= pd
->dwData
;
1182 case (DWORD
)DIPROP_SATURATION
: {
1183 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
1184 if (ph
->dwHow
== DIPH_DEVICE
) {
1185 TRACE("saturation(%ld) all\n",pd
->dwData
);
1186 for (i
= 0; i
< This
->user_df
->dwNumObjs
; i
++)
1187 This
->props
[i
].lSaturation
= pd
->dwData
;
1189 int obj
= find_property(This
, ph
);
1190 TRACE("saturation(%ld) obj=%d\n",pd
->dwData
,obj
);
1192 This
->props
[obj
].lSaturation
= pd
->dwData
;
1199 FIXME("Unknown type %p (%s)\n",rguid
,debugstr_guid(rguid
));
1207 /******************************************************************************
1208 * SetEventNotification : specifies event to be sent on state change
1210 static HRESULT WINAPI
JoystickAImpl_SetEventNotification(
1211 LPDIRECTINPUTDEVICE8A iface
, HANDLE hnd
1213 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1215 TRACE("(this=%p,%p)\n",This
,hnd
);
1220 static HRESULT WINAPI
JoystickAImpl_GetCapabilities(
1221 LPDIRECTINPUTDEVICE8A iface
,
1222 LPDIDEVCAPS lpDIDevCaps
)
1224 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1227 TRACE("%p->(%p)\n",iface
,lpDIDevCaps
);
1229 if (lpDIDevCaps
== NULL
) {
1230 WARN("invalid pointer\n");
1234 size
= lpDIDevCaps
->dwSize
;
1236 if (!(size
== sizeof(DIDEVCAPS
) || size
== sizeof(DIDEVCAPS_DX3
))) {
1237 WARN("invalid parameter\n");
1238 return DIERR_INVALIDPARAM
;
1241 CopyMemory(lpDIDevCaps
, &This
->devcaps
, size
);
1242 lpDIDevCaps
->dwSize
= size
;
1244 if (TRACE_ON(dinput
))
1245 _dump_DIDEVCAPS(lpDIDevCaps
);
1250 static HRESULT WINAPI
JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface
)
1252 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1254 TRACE("(%p)\n",This
);
1256 if (!This
->acquired
) {
1257 WARN("not acquired\n");
1258 return DIERR_NOTACQUIRED
;
1265 /******************************************************************************
1266 * EnumObjects : enumerate the different buttons and axis...
1268 static HRESULT WINAPI
JoystickAImpl_EnumObjects(
1269 LPDIRECTINPUTDEVICE8A iface
,
1270 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback
,
1274 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1275 DIDEVICEOBJECTINSTANCEA ddoi
;
1280 TRACE("(this=%p,%p,%p,%08lx)\n", This
, lpCallback
, lpvRef
, dwFlags
);
1281 if (TRACE_ON(dinput
)) {
1282 TRACE(" - flags = ");
1283 _dump_EnumObjects_flags(dwFlags
);
1287 /* Only the fields till dwFFMaxForce are relevant */
1288 ddoi
.dwSize
= FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA
, dwFFMaxForce
);
1290 /* For the joystick, do as is done in the GetCapabilities function */
1291 if ((dwFlags
== DIDFT_ALL
) ||
1292 (dwFlags
& DIDFT_AXIS
) ||
1293 (dwFlags
& DIDFT_POV
)) {
1294 int pov
[4] = { 0, 0, 0, 0 };
1298 for (i
= 0; i
< This
->axes
; i
++) {
1299 int wine_obj
= This
->axis_map
[i
];
1304 ddoi
.guidType
= GUID_XAxis
;
1307 ddoi
.guidType
= GUID_YAxis
;
1310 ddoi
.guidType
= GUID_ZAxis
;
1313 ddoi
.guidType
= GUID_RxAxis
;
1316 ddoi
.guidType
= GUID_RyAxis
;
1319 ddoi
.guidType
= GUID_RzAxis
;
1322 ddoi
.guidType
= GUID_Slider
;
1325 ddoi
.guidType
= GUID_Slider
;
1329 ddoi
.guidType
= GUID_POV
;
1333 ddoi
.guidType
= GUID_POV
;
1337 ddoi
.guidType
= GUID_POV
;
1341 ddoi
.guidType
= GUID_POV
;
1344 ddoi
.guidType
= GUID_Unknown
;
1347 user_offset
= This
->offsets
[wine_obj
]; /* get user offset from wine index */
1348 user_object
= offset_to_object(This
, user_offset
);
1350 ddoi
.dwType
= This
->user_df
->rgodf
[user_object
].dwType
& 0x00ffffff;
1351 ddoi
.dwOfs
= This
->user_df
->rgodf
[user_object
].dwOfs
;
1352 sprintf(ddoi
.tszName
, "Axis %d", axes
);
1355 if (pov
[wine_obj
- 8] < 2) {
1356 user_offset
= This
->offsets
[wine_obj
]; /* get user offset from wine index */
1357 user_object
= offset_to_object(This
, user_offset
);
1359 ddoi
.dwType
= This
->user_df
->rgodf
[user_object
].dwType
& 0x00ffffff;
1360 ddoi
.dwOfs
= This
->user_df
->rgodf
[user_object
].dwOfs
;
1361 sprintf(ddoi
.tszName
, "POV %d", povs
);
1367 _dump_OBJECTINSTANCEA(&ddoi
);
1368 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
)
1374 if ((dwFlags
== DIDFT_ALL
) ||
1375 (dwFlags
& DIDFT_BUTTON
)) {
1377 /* The DInput SDK says that GUID_Button is only for mouse buttons but well... */
1378 ddoi
.guidType
= GUID_Button
;
1380 for (i
= 0; i
< This
->buttons
; i
++) {
1381 user_offset
= This
->offsets
[i
+ 12]; /* get user offset from wine index */
1382 user_object
= offset_to_object(This
, user_offset
);
1383 ddoi
.guidType
= GUID_Button
;
1384 ddoi
.dwType
= This
->user_df
->rgodf
[user_object
].dwType
& 0x00ffffff;
1385 ddoi
.dwOfs
= This
->user_df
->rgodf
[user_object
].dwOfs
;
1386 sprintf(ddoi
.tszName
, "Button %d", i
);
1387 _dump_OBJECTINSTANCEA(&ddoi
);
1388 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) return DI_OK
;
1395 /******************************************************************************
1396 * EnumObjects : enumerate the different buttons and axis...
1398 static HRESULT WINAPI
JoystickWImpl_EnumObjects(
1399 LPDIRECTINPUTDEVICE8W iface
,
1400 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback
,
1404 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1406 device_enumobjects_AtoWcb_data data
;
1408 data
.lpCallBack
= lpCallback
;
1409 data
.lpvRef
= lpvRef
;
1411 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A
) This
, (LPDIENUMDEVICEOBJECTSCALLBACKA
) DIEnumDevicesCallbackAtoW
, (LPVOID
) &data
, dwFlags
);
1414 /******************************************************************************
1415 * GetProperty : get input device properties
1417 static HRESULT WINAPI
JoystickAImpl_GetProperty(
1418 LPDIRECTINPUTDEVICE8A iface
,
1420 LPDIPROPHEADER pdiph
)
1422 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1424 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
1426 if (TRACE_ON(dinput
))
1427 _dump_DIPROPHEADER(pdiph
);
1429 if (!HIWORD(rguid
)) {
1430 switch (LOWORD(rguid
)) {
1431 case (DWORD
) DIPROP_BUFFERSIZE
: {
1432 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1433 TRACE(" return buffersize = %d\n",This
->queue_len
);
1434 pd
->dwData
= This
->queue_len
;
1437 case (DWORD
) DIPROP_RANGE
: {
1438 LPDIPROPRANGE pr
= (LPDIPROPRANGE
) pdiph
;
1439 int obj
= find_property(This
, pdiph
);
1440 /* The app is querying the current range of the axis
1441 * return the lMin and lMax values */
1443 pr
->lMin
= This
->props
[obj
].lMin
;
1444 pr
->lMax
= This
->props
[obj
].lMax
;
1445 TRACE("range(%ld, %ld) obj=%d\n", pr
->lMin
, pr
->lMax
, obj
);
1450 case (DWORD
) DIPROP_DEADZONE
: {
1451 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1452 int obj
= find_property(This
, pdiph
);
1454 pd
->dwData
= This
->props
[obj
].lDeadZone
;
1455 TRACE("deadzone(%ld) obj=%d\n", pd
->dwData
, obj
);
1460 case (DWORD
) DIPROP_SATURATION
: {
1461 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
1462 int obj
= find_property(This
, pdiph
);
1464 pd
->dwData
= This
->props
[obj
].lSaturation
;
1465 TRACE("saturation(%ld) obj=%d\n", pd
->dwData
, obj
);
1471 FIXME("Unknown type %p (%s)\n",rguid
,debugstr_guid(rguid
));
1479 /******************************************************************************
1480 * GetObjectInfo : get object info
1482 HRESULT WINAPI
JoystickAImpl_GetObjectInfo(
1483 LPDIRECTINPUTDEVICE8A iface
,
1484 LPDIDEVICEOBJECTINSTANCEA pdidoi
,
1488 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1489 DIDEVICEOBJECTINSTANCEA didoiA
;
1492 TRACE("(%p,%p,%ld,0x%08lx(%s))\n",
1493 iface
, pdidoi
, dwObj
, dwHow
,
1494 dwHow
== DIPH_BYOFFSET
? "DIPH_BYOFFSET" :
1495 dwHow
== DIPH_BYID
? "DIPH_BYID" :
1496 dwHow
== DIPH_BYUSAGE
? "DIPH_BYUSAGE" :
1499 if (pdidoi
== NULL
) {
1500 WARN("invalid parameter: pdidoi = NULL\n");
1501 return DIERR_INVALIDPARAM
;
1504 if ((pdidoi
->dwSize
!= sizeof(DIDEVICEOBJECTINSTANCEA
)) &&
1505 (pdidoi
->dwSize
!= sizeof(DIDEVICEOBJECTINSTANCE_DX3A
))) {
1506 WARN("invalid parameter: pdidoi->dwSize = %ld != %d or %d\n",
1507 pdidoi
->dwSize
, sizeof(DIDEVICEOBJECTINSTANCEA
),
1508 sizeof(DIDEVICEOBJECTINSTANCE_DX3A
));
1509 return DIERR_INVALIDPARAM
;
1512 ZeroMemory(&didoiA
, sizeof(didoiA
));
1513 didoiA
.dwSize
= pdidoi
->dwSize
;
1516 case DIPH_BYOFFSET
: {
1520 for (i
= 0; i
< This
->user_df
->dwNumObjs
; i
++) {
1521 if (This
->user_df
->rgodf
[i
].dwOfs
== dwObj
) {
1522 if (This
->user_df
->rgodf
[i
].pguid
)
1523 didoiA
.guidType
= *This
->user_df
->rgodf
[i
].pguid
;
1525 didoiA
.guidType
= GUID_NULL
;
1527 didoiA
.dwOfs
= dwObj
;
1528 didoiA
.dwType
= This
->user_df
->rgodf
[i
].dwType
;
1529 didoiA
.dwFlags
= This
->user_df
->rgodf
[i
].dwFlags
;
1531 if (DIDFT_GETTYPE(This
->user_df
->rgodf
[i
].dwType
) & DIDFT_AXIS
)
1532 sprintf(didoiA
.tszName
, "Axis %d", axis
);
1533 else if (DIDFT_GETTYPE(This
->user_df
->rgodf
[i
].dwType
) & DIDFT_POV
)
1534 sprintf(didoiA
.tszName
, "POV %d", pov
);
1535 else if (DIDFT_GETTYPE(This
->user_df
->rgodf
[i
].dwType
) & DIDFT_BUTTON
)
1536 sprintf(didoiA
.tszName
, "Button %d", button
);
1538 CopyMemory(pdidoi
, &didoiA
, pdidoi
->dwSize
);
1542 if (DIDFT_GETTYPE(This
->user_df
->rgodf
[i
].dwType
) & DIDFT_AXIS
)
1544 else if (DIDFT_GETTYPE(This
->user_df
->rgodf
[i
].dwType
) & DIDFT_POV
)
1546 else if (DIDFT_GETTYPE(This
->user_df
->rgodf
[i
].dwType
) & DIDFT_BUTTON
)
1552 FIXME("dwHow = DIPH_BYID not implemented\n");
1555 FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1558 WARN("invalid parameter: dwHow = %08lx\n", dwHow
);
1559 return DIERR_INVALIDPARAM
;
1562 CopyMemory(pdidoi
, &didoiA
, pdidoi
->dwSize
);
1567 /******************************************************************************
1568 * GetDeviceInfo : get information about a device's identity
1570 HRESULT WINAPI
JoystickAImpl_GetDeviceInfo(
1571 LPDIRECTINPUTDEVICE8A iface
,
1572 LPDIDEVICEINSTANCEA pdidi
)
1574 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1576 TRACE("(%p,%p)\n", iface
, pdidi
);
1578 if (pdidi
== NULL
) {
1579 WARN("invalid pointer\n");
1583 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3A
)) &&
1584 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
))) {
1585 WARN("invalid parameter: pdidi->dwSize = %ld != %d or %d\n",
1586 pdidi
->dwSize
, sizeof(DIDEVICEINSTANCE_DX3A
),
1587 sizeof(DIDEVICEINSTANCEA
));
1588 return DIERR_INVALIDPARAM
;
1591 /* Return joystick */
1592 pdidi
->guidInstance
= GUID_Joystick
;
1593 pdidi
->guidProduct
= DInput_Wine_Joystick_GUID
;
1594 /* we only support traditional joysticks for now */
1595 pdidi
->dwDevType
= This
->devcaps
.dwDevType
;
1596 strcpy(pdidi
->tszInstanceName
, "Joystick");
1597 strcpy(pdidi
->tszProductName
, This
->name
);
1598 if (pdidi
->dwSize
> sizeof(DIDEVICEINSTANCE_DX3A
)) {
1599 pdidi
->guidFFDriver
= GUID_NULL
;
1600 pdidi
->wUsagePage
= 0;
1607 /******************************************************************************
1608 * GetDeviceInfo : get information about a device's identity
1610 HRESULT WINAPI
JoystickWImpl_GetDeviceInfo(
1611 LPDIRECTINPUTDEVICE8W iface
,
1612 LPDIDEVICEINSTANCEW pdidi
)
1614 JoystickImpl
*This
= (JoystickImpl
*)iface
;
1616 TRACE("(%p,%p)\n", iface
, pdidi
);
1618 if ((pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCE_DX3W
)) &&
1619 (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
))) {
1620 WARN("invalid parameter: pdidi->dwSize = %ld != %d or %d\n",
1621 pdidi
->dwSize
, sizeof(DIDEVICEINSTANCE_DX3W
),
1622 sizeof(DIDEVICEINSTANCEW
));
1623 return DIERR_INVALIDPARAM
;
1626 /* Return joystick */
1627 pdidi
->guidInstance
= GUID_Joystick
;
1628 pdidi
->guidProduct
= DInput_Wine_Joystick_GUID
;
1629 /* we only support traditional joysticks for now */
1630 pdidi
->dwDevType
= This
->devcaps
.dwDevType
;
1631 MultiByteToWideChar(CP_ACP
, 0, "Joystick", -1, pdidi
->tszInstanceName
, MAX_PATH
);
1632 MultiByteToWideChar(CP_ACP
, 0, This
->name
, -1, pdidi
->tszProductName
, MAX_PATH
);
1633 if (pdidi
->dwSize
> sizeof(DIDEVICEINSTANCE_DX3W
)) {
1634 pdidi
->guidFFDriver
= GUID_NULL
;
1635 pdidi
->wUsagePage
= 0;
1642 static const IDirectInputDevice8AVtbl JoystickAvt
=
1644 IDirectInputDevice2AImpl_QueryInterface
,
1645 IDirectInputDevice2AImpl_AddRef
,
1646 JoystickAImpl_Release
,
1647 JoystickAImpl_GetCapabilities
,
1648 JoystickAImpl_EnumObjects
,
1649 JoystickAImpl_GetProperty
,
1650 JoystickAImpl_SetProperty
,
1651 JoystickAImpl_Acquire
,
1652 JoystickAImpl_Unacquire
,
1653 JoystickAImpl_GetDeviceState
,
1654 JoystickAImpl_GetDeviceData
,
1655 JoystickAImpl_SetDataFormat
,
1656 JoystickAImpl_SetEventNotification
,
1657 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1658 JoystickAImpl_GetObjectInfo
,
1659 JoystickAImpl_GetDeviceInfo
,
1660 IDirectInputDevice2AImpl_RunControlPanel
,
1661 IDirectInputDevice2AImpl_Initialize
,
1662 IDirectInputDevice2AImpl_CreateEffect
,
1663 IDirectInputDevice2AImpl_EnumEffects
,
1664 IDirectInputDevice2AImpl_GetEffectInfo
,
1665 IDirectInputDevice2AImpl_GetForceFeedbackState
,
1666 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
1667 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
1668 IDirectInputDevice2AImpl_Escape
,
1670 IDirectInputDevice2AImpl_SendDeviceData
,
1671 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1672 IDirectInputDevice7AImpl_WriteEffectToFile
,
1673 IDirectInputDevice8AImpl_BuildActionMap
,
1674 IDirectInputDevice8AImpl_SetActionMap
,
1675 IDirectInputDevice8AImpl_GetImageInfo
1678 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1679 # define XCAST(fun) (typeof(SysJoystickWvt.fun))
1681 # define XCAST(fun) (void*)
1684 static const IDirectInputDevice8WVtbl SysJoystickWvt
=
1686 IDirectInputDevice2WImpl_QueryInterface
,
1687 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
1688 XCAST(Release
)JoystickAImpl_Release
,
1689 XCAST(GetCapabilities
)JoystickAImpl_GetCapabilities
,
1690 JoystickWImpl_EnumObjects
,
1691 XCAST(GetProperty
)JoystickAImpl_GetProperty
,
1692 XCAST(SetProperty
)JoystickAImpl_SetProperty
,
1693 XCAST(Acquire
)JoystickAImpl_Acquire
,
1694 XCAST(Unacquire
)JoystickAImpl_Unacquire
,
1695 XCAST(GetDeviceState
)JoystickAImpl_GetDeviceState
,
1696 XCAST(GetDeviceData
)JoystickAImpl_GetDeviceData
,
1697 XCAST(SetDataFormat
)JoystickAImpl_SetDataFormat
,
1698 XCAST(SetEventNotification
)JoystickAImpl_SetEventNotification
,
1699 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
1700 IDirectInputDevice2WImpl_GetObjectInfo
,
1701 JoystickWImpl_GetDeviceInfo
,
1702 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
1703 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
1704 XCAST(CreateEffect
)IDirectInputDevice2AImpl_CreateEffect
,
1705 IDirectInputDevice2WImpl_EnumEffects
,
1706 IDirectInputDevice2WImpl_GetEffectInfo
,
1707 XCAST(GetForceFeedbackState
)IDirectInputDevice2AImpl_GetForceFeedbackState
,
1708 XCAST(SendForceFeedbackCommand
)IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
1709 XCAST(EnumCreatedEffectObjects
)IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
1710 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
1711 XCAST(Poll
)JoystickAImpl_Poll
,
1712 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
1713 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1714 IDirectInputDevice7WImpl_WriteEffectToFile
,
1715 IDirectInputDevice8WImpl_BuildActionMap
,
1716 IDirectInputDevice8WImpl_SetActionMap
,
1717 IDirectInputDevice8WImpl_GetImageInfo
1721 #else /* HAVE_LINUX_22_JOYSTICK_API */
1723 const struct dinput_device joystick_linux_device
= {
1724 "Wine Linux joystick driver",
1731 #endif /* HAVE_LINUX_22_JOYSTICK_API */