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"
31 #ifdef HAVE_LINUX_22_JOYSTICK_API
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
44 #include <sys/fcntl.h>
45 #ifdef HAVE_SYS_IOCTL_H
46 # include <sys/ioctl.h>
49 #ifdef HAVE_SYS_ERRNO_H
50 # include <sys/errno.h>
52 #ifdef HAVE_LINUX_IOCTL_H
53 # include <linux/ioctl.h>
55 #ifdef HAVE_LINUX_JOYSTICK_H
56 # include <linux/joystick.h>
58 #define JOYDEV "/dev/js"
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);
85 typedef struct JoystickImpl JoystickImpl;
86 static IDirectInputDevice8AVtbl JoystickAvt;
87 static IDirectInputDevice8WVtbl JoystickWvt;
95 /* The 'parent' DInput */
96 IDirectInputImpl *dinput;
98 /* joystick private */
100 DIJOYSTATE2 js; /* wine data */
101 LPDIDATAFORMAT user_df; /* user defined format */
102 DataFormat *transform; /* wine to user format converter */
103 int *offsets; /* object offsets */
106 LPDIDEVICEOBJECTDATA data_queue;
107 int queue_head, queue_tail, queue_len;
116 CRITICAL_SECTION crit;
120 static GUID DInput_Wine_Joystick_GUID = { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
124 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
127 static void _dump_DIDEVCAPS(LPDIDEVCAPS lpDIDevCaps)
129 TRACE("dwSize: %ld\n", lpDIDevCaps->dwSize);
130 TRACE("dwFlags: %08lx\n",lpDIDevCaps->dwFlags);
131 TRACE("dwDevType: %08lx %s\n", lpDIDevCaps->dwDevType,
132 lpDIDevCaps->dwDevType == DIDEVTYPE_DEVICE ? "DIDEVTYPE_DEVICE" :
133 lpDIDevCaps->dwDevType == DIDEVTYPE_DEVICE ? "DIDEVTYPE_DEVICE" :
134 lpDIDevCaps->dwDevType == DIDEVTYPE_MOUSE ? "DIDEVTYPE_MOUSE" :
135 lpDIDevCaps->dwDevType == DIDEVTYPE_KEYBOARD ? "DIDEVTYPE_KEYBOARD" :
136 lpDIDevCaps->dwDevType == DIDEVTYPE_JOYSTICK ? "DIDEVTYPE_JOYSTICK" :
137 lpDIDevCaps->dwDevType == DIDEVTYPE_HID ? "DIDEVTYPE_HID" : "UNKNOWN");
138 TRACE("dwAxes: %ld\n",lpDIDevCaps->dwAxes);
139 TRACE("dwButtons: %ld\n",lpDIDevCaps->dwButtons);
140 TRACE("dwPOVs: %ld\n",lpDIDevCaps->dwPOVs);
141 if (lpDIDevCaps->dwSize > sizeof(DIDEVCAPS_DX3)) {
142 TRACE("dwFFSamplePeriod: %ld\n",lpDIDevCaps->dwFFSamplePeriod);
143 TRACE("dwFFMinTimeResolution: %ld\n",lpDIDevCaps->dwFFMinTimeResolution);
144 TRACE("dwFirmwareRevision: %ld\n",lpDIDevCaps->dwFirmwareRevision);
145 TRACE("dwHardwareRevision: %ld\n",lpDIDevCaps->dwHardwareRevision);
146 TRACE("dwFFDriverVersion: %ld\n",lpDIDevCaps->dwFFDriverVersion);
150 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, int version, int id)
155 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
156 WARN("force feedback not supported\n");
160 if ((dwDevType == 0) ||
161 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 8)) ||
162 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 8))) {
163 /* check whether we have a joystick */
164 sprintf(dev, "%s%d", JOYDEV, id);
165 if ((fd = open(dev,O_RDONLY)) < 0) {
166 WARN("open(%s,O_RDONLY) failed: %s\n", dev, strerror(errno));
170 /* Return joystick */
171 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
172 lpddi->guidInstance.Data3 = id;
173 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
174 /* we only support traditional joysticks for now */
176 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
178 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
179 sprintf(lpddi->tszInstanceName, "Joystick %d", id);
180 #if defined(JSIOCGNAME)
181 if (ioctl(fd,JSIOCGNAME(sizeof(lpddi->tszProductName)),lpddi->tszProductName) < 0) {
182 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", dev, strerror(errno));
183 strcpy(lpddi->tszProductName, "Wine Joystick");
186 strcpy(lpddi->tszProductName, "Wine Joystick");
189 lpddi->guidFFDriver = GUID_NULL;
191 TRACE("Enumerating the linux Joystick device: %s (%s)\n", dev, lpddi->tszProductName);
198 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, int version, int id)
205 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
206 WARN("force feedback not supported\n");
210 if ((dwDevType == 0) ||
211 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 8)) ||
212 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 8))) {
213 /* check whether we have a joystick */
214 sprintf(dev, "%s%d", JOYDEV, id);
215 if ((fd = open(dev,O_RDONLY)) < 0) {
216 WARN("open(%s,O_RDONLY) failed: %s\n", dev, strerror(errno));
220 /* Return joystick */
221 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
222 lpddi->guidInstance.Data3 = id;
223 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
224 /* we only support traditional joysticks for now */
226 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
228 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
229 sprintf(friendly, "Joystick %d", id);
230 MultiByteToWideChar(CP_ACP, 0, friendly, -1, lpddi->tszInstanceName, MAX_PATH);
231 #if defined(JSIOCGNAME)
232 if (ioctl(fd,JSIOCGNAME(sizeof(name)),name) < 0) {
233 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", dev, strerror(errno));
234 strcpy(name, "Wine Joystick");
237 strcpy(name, "Wine Joystick");
239 MultiByteToWideChar(CP_ACP, 0, name, -1, lpddi->tszProductName, MAX_PATH);
240 lpddi->guidFFDriver = GUID_NULL;
242 TRACE("Enumerating the linux Joystick device: %s (%s)\n",dev,name);
250 * Get a config key from either the app-specific or the default config
253 inline static DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
254 char *buffer, DWORD size )
256 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, buffer, &size ))
259 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, buffer, &size ))
262 return ERROR_FILE_NOT_FOUND;
266 * Setup the dinput options.
269 static HRESULT setup_dinput_options(JoystickImpl * device)
271 char buffer[MAX_PATH+1];
272 HKEY hkey, appkey = 0;
275 buffer[MAX_PATH]='\0';
277 if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\dinput", &hkey)) hkey = 0;
279 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
280 if (len && len < MAX_PATH) {
283 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\AppDefaults", &tmpkey )) {
284 char appname[MAX_PATH+16];
285 char *p = strrchr( buffer, '\\' );
288 strcat(appname,"\\dinput");
289 TRACE("appname = [%s] \n",appname);
290 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 )) {
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 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, LPVOID 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[1] = (DWORD)"DINPUT_Mouse";
557 newDevice->devcaps.dwSize = sizeof(newDevice->devcaps);
558 newDevice->devcaps.dwFlags = DIDC_ATTACHED;
559 if (newDevice->dinput->version >= 8)
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 if (newDevice->axis_map)
584 HeapFree(GetProcessHeap(),0,newDevice->axis_map);
586 HeapFree(GetProcessHeap(),0,newDevice->name);
587 if (newDevice->props)
588 HeapFree(GetProcessHeap(),0,newDevice->props);
589 if (newDevice->user_df->rgodf)
590 HeapFree(GetProcessHeap(),0,newDevice->user_df->rgodf);
591 if (newDevice->user_df)
592 HeapFree(GetProcessHeap(),0,newDevice->user_df);
594 HeapFree(GetProcessHeap(),0,newDevice);
600 static BOOL IsJoystickGUID(REFGUID guid)
602 GUID wine_joystick = DInput_Wine_Joystick_GUID;
603 GUID dev_guid = *guid;
605 wine_joystick.Data3 = 0;
608 return IsEqualGUID(&wine_joystick, &dev_guid);
611 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
613 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
614 (IsJoystickGUID(rguid))) {
615 if ((riid == NULL) ||
616 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
617 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
618 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
619 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
620 return alloc_device(rguid, &JoystickAvt, dinput, pdev);
622 WARN("no interface\n");
624 return DIERR_NOINTERFACE;
628 WARN("invalid device GUID\n");
630 return DIERR_DEVICENOTREG;
633 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
635 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
636 (IsJoystickGUID(rguid))) {
637 if ((riid == NULL) ||
638 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
639 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
640 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
641 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
642 return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA *)pdev);
644 WARN("no interface\n");
646 return DIERR_NOINTERFACE;
650 WARN("invalid device GUID\n");
652 return DIERR_DEVICENOTREG;
655 static dinput_device joydev = {
657 "Wine Linux joystick driver",
660 joydev_create_deviceA,
661 joydev_create_deviceW
664 DECL_GLOBAL_CONSTRUCTOR(joydev_register) { dinput_register_device(&joydev); }
666 /******************************************************************************
669 static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
671 JoystickImpl *This = (JoystickImpl *)iface;
674 ref = InterlockedDecrement((&This->ref));
678 /* Free the device name */
680 HeapFree(GetProcessHeap(),0,This->name);
682 /* Free the axis map */
684 HeapFree(GetProcessHeap(),0,This->axis_map);
686 /* Free the data queue */
687 if (This->data_queue != NULL)
688 HeapFree(GetProcessHeap(),0,This->data_queue);
690 /* Free the DataFormat */
691 HeapFree(GetProcessHeap(), 0, This->user_df->rgodf);
692 HeapFree(GetProcessHeap(), 0, This->user_df);
694 /* Free the properties */
695 HeapFree(GetProcessHeap(), 0, This->props);
697 /* Free the offsets array */
698 HeapFree(GetProcessHeap(),0,This->offsets);
700 /* release the data transform filter */
701 release_DataFormat(This->transform);
703 This->crit.DebugInfo->Spare[1] = 0;
704 DeleteCriticalSection(&(This->crit));
705 IDirectInputDevice_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
707 HeapFree(GetProcessHeap(),0,This);
711 /******************************************************************************
712 * SetDataFormat : the application can choose the format of the data
713 * the device driver sends back with GetDeviceState.
715 static HRESULT WINAPI JoystickAImpl_SetDataFormat(
716 LPDIRECTINPUTDEVICE8A iface,
719 JoystickImpl *This = (JoystickImpl *)iface;
721 LPDIDATAFORMAT new_df = 0;
722 LPDIOBJECTDATAFORMAT new_rgodf = 0;
723 ObjProps * new_props = 0;
725 TRACE("(%p,%p)\n",This,df);
727 if (This->acquired) {
729 return DIERR_ACQUIRED;
732 if (TRACE_ON(dinput))
733 _dump_DIDATAFORMAT(df);
735 /* Store the new data format */
736 new_df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
740 new_rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
744 new_props = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*sizeof(ObjProps));
748 HeapFree(GetProcessHeap(),0,This->user_df);
749 HeapFree(GetProcessHeap(),0,This->user_df->rgodf);
750 HeapFree(GetProcessHeap(),0,This->props);
751 release_DataFormat(This->transform);
753 This->user_df = new_df;
754 CopyMemory(This->user_df, df, df->dwSize);
755 This->user_df->rgodf = new_rgodf;
756 CopyMemory(This->user_df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
757 This->props = new_props;
758 for (i = 0; i < df->dwNumObjs; i++) {
759 This->props[i].lMin = 0;
760 This->props[i].lMax = 0xffff;
761 This->props[i].lDeadZone = 1000;
762 This->props[i].lSaturation = 0;
764 This->transform = create_DataFormat(&c_dfDIJoystick2, This->user_df, This->offsets);
771 WARN("out of memory\n");
773 HeapFree(GetProcessHeap(),0,new_props);
775 HeapFree(GetProcessHeap(),0,new_rgodf);
777 HeapFree(GetProcessHeap(),0,new_df);
778 return DIERR_OUTOFMEMORY;
781 /******************************************************************************
782 * Acquire : gets exclusive control of the joystick
784 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
786 JoystickImpl *This = (JoystickImpl *)iface;
788 TRACE("(%p)\n",This);
790 if (This->acquired) {
791 WARN("already acquired\n");
795 /* open the joystick device */
796 if (This->joyfd==-1) {
797 TRACE("opening joystick device %s\n", This->dev);
799 This->joyfd=open(This->dev,O_RDONLY);
800 if (This->joyfd==-1) {
801 ERR("open(%s) failed: %s\n", This->dev, strerror(errno));
802 return DIERR_NOTFOUND;
806 This->acquired = TRUE;
811 /******************************************************************************
812 * Unacquire : frees the joystick
814 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
816 JoystickImpl *This = (JoystickImpl *)iface;
818 TRACE("(%p)\n",This);
820 if (!This->acquired) {
821 WARN("not acquired\n");
822 return DIERR_NOTACQUIRED;
825 if (This->joyfd!=-1) {
826 TRACE("closing joystick device\n");
829 This->acquired = FALSE;
833 This->acquired = FALSE;
838 LONG map_axis(JoystickImpl * This, short val, short index)
841 double fmin = This->props[index].lMin;
842 double fmax = This->props[index].lMax;
845 fret = (((fval + 32767.0) * (fmax - fmin)) / (32767.0*2.0)) + fmin;
855 /* convert wine format offset to user format object index */
856 int offset_to_object(JoystickImpl *This, int offset)
860 for (i = 0; i < This->user_df->dwNumObjs; i++) {
861 if (This->user_df->rgodf[i].dwOfs == offset)
868 static LONG calculate_pov(JoystickImpl *This, int index)
870 if (This->povs[index].lX < 16384) {
871 if (This->povs[index].lY < 16384)
872 This->js.rgdwPOV[index] = 31500;
873 else if (This->povs[index].lY > 49150)
874 This->js.rgdwPOV[index] = 22500;
876 This->js.rgdwPOV[index] = 27000;
877 } else if (This->povs[index].lX > 49150) {
878 if (This->povs[index].lY < 16384)
879 This->js.rgdwPOV[index] = 4500;
880 else if (This->povs[index].lY > 49150)
881 This->js.rgdwPOV[index] = 13500;
883 This->js.rgdwPOV[index] = 9000;
885 if (This->povs[index].lY < 16384)
886 This->js.rgdwPOV[index] = 0;
887 else if (This->povs[index].lY > 49150)
888 This->js.rgdwPOV[index] = 18000;
890 This->js.rgdwPOV[index] = -1;
893 return This->js.rgdwPOV[index];
896 static void joy_polldev(JoystickImpl *This) {
900 TRACE("(%p)\n", This);
902 if (This->joyfd==-1) {
907 memset(&tv,0,sizeof(tv));
908 FD_ZERO(&readfds);FD_SET(This->joyfd,&readfds);
909 if (1>select(This->joyfd+1,&readfds,NULL,NULL,&tv))
911 /* we have one event, so we can read */
912 if (sizeof(jse)!=read(This->joyfd,&jse,sizeof(jse))) {
915 TRACE("js_event: type 0x%x, number %d, value %d\n",
916 jse.type,jse.number,jse.value);
917 if (jse.type & JS_EVENT_BUTTON) {
918 int offset = This->offsets[jse.number + 12];
919 int value = jse.value?0x80:0x00;
921 This->js.rgbButtons[jse.number] = value;
922 GEN_EVENT(offset,value,jse.time,(This->dinput->evsequence)++);
923 } else if (jse.type & JS_EVENT_AXIS) {
924 int number = This->axis_map[jse.number]; /* wine format object index */
926 int offset = This->offsets[number];
927 int index = offset_to_object(This, offset);
928 LONG value = map_axis(This, jse.value, index);
930 /* FIXME do deadzone and saturation here */
932 TRACE("changing axis %d => %d\n", jse.number, number);
944 This->js.lRx = value;
947 This->js.lRy = value;
950 This->js.lRz = value;
953 This->js.rglSlider[0] = value;
956 This->js.rglSlider[1] = value;
959 /* FIXME don't go off array */
960 if (This->axis_map[jse.number + 1] == number)
961 This->povs[0].lX = value;
962 else if (This->axis_map[jse.number - 1] == number)
963 This->povs[0].lY = value;
964 value = calculate_pov(This, 0);
967 if (This->axis_map[jse.number + 1] == number)
968 This->povs[1].lX = value;
969 else if (This->axis_map[jse.number - 1] == number)
970 This->povs[1].lY = value;
971 value = calculate_pov(This, 1);
974 if (This->axis_map[jse.number + 1] == number)
975 This->povs[2].lX = value;
976 else if (This->axis_map[jse.number - 1] == number)
977 This->povs[2].lY = value;
978 value = calculate_pov(This, 2);
981 if (This->axis_map[jse.number + 1] == number)
982 This->povs[3].lX = value;
983 else if (This->axis_map[jse.number - 1] == number)
984 This->povs[3].lY = value;
985 value = calculate_pov(This, 3);
989 GEN_EVENT(offset,value,jse.time,(This->dinput->evsequence)++);
991 WARN("axis %d not supported\n", number);
996 /******************************************************************************
997 * GetDeviceState : returns the "state" of the joystick.
1000 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
1001 LPDIRECTINPUTDEVICE8A iface,
1005 JoystickImpl *This = (JoystickImpl *)iface;
1007 TRACE("(%p,0x%08lx,%p)\n",This,len,ptr);
1009 if (!This->acquired) {
1010 WARN("not acquired\n");
1011 return DIERR_NOTACQUIRED;
1014 /* update joystick state */
1017 /* convert and copy data to user supplied buffer */
1018 fill_DataFormat(ptr, &This->js, This->transform);
1023 /******************************************************************************
1024 * GetDeviceData : gets buffered input data.
1026 static HRESULT WINAPI JoystickAImpl_GetDeviceData(
1027 LPDIRECTINPUTDEVICE8A iface,
1029 LPDIDEVICEOBJECTDATA dod,
1033 JoystickImpl *This = (JoystickImpl *)iface;
1038 TRACE("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx)\n",This,dodsize,*entries,flags);
1040 if (!This->acquired) {
1041 WARN("not acquired\n");
1042 return DIERR_NOTACQUIRED;
1045 EnterCriticalSection(&(This->crit));
1049 len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0)
1050 + (This->queue_head - This->queue_tail);
1056 TRACE("Application discarding %ld event(s).\n", len);
1059 nqtail = This->queue_tail + len;
1060 while (nqtail >= This->queue_len)
1061 nqtail -= This->queue_len;
1063 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
1064 ERR("Wrong structure size !\n");
1065 LeaveCriticalSection(&(This->crit));
1066 return DIERR_INVALIDPARAM;
1070 TRACE("Application retrieving %ld event(s).\n", len);
1073 nqtail = This->queue_tail;
1075 DWORD span = ((This->queue_head < nqtail) ? This->queue_len : This->queue_head) - nqtail;
1079 /* Copy the buffered data into the application queue */
1080 memcpy(dod + *entries, This->data_queue + nqtail, span * dodsize);
1081 /* Advance position */
1083 if (nqtail >= This->queue_len)
1084 nqtail -= This->queue_len;
1090 if (This->overflow) {
1091 hr = DI_BUFFEROVERFLOW;
1092 if (!(flags & DIGDD_PEEK)) {
1093 This->overflow = FALSE;
1097 if (!(flags & DIGDD_PEEK))
1098 This->queue_tail = nqtail;
1100 LeaveCriticalSection(&(This->crit));
1105 int find_property(JoystickImpl * This, LPCDIPROPHEADER ph)
1108 if (ph->dwHow == DIPH_BYOFFSET) {
1109 return offset_to_object(This, ph->dwObj);
1110 } else if (ph->dwHow == DIPH_BYID) {
1111 for (i = 0; i < This->user_df->dwNumObjs; i++) {
1112 if ((This->user_df->rgodf[i].dwType & 0x00ffffff) == (ph->dwObj & 0x00ffffff)) {
1121 /******************************************************************************
1122 * SetProperty : change input device properties
1124 static HRESULT WINAPI JoystickAImpl_SetProperty(
1125 LPDIRECTINPUTDEVICE8A iface,
1129 JoystickImpl *This = (JoystickImpl *)iface;
1132 TRACE("(%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
1134 if (TRACE_ON(dinput))
1135 _dump_DIPROPHEADER(ph);
1137 if (!HIWORD(rguid)) {
1138 switch ((DWORD)rguid) {
1139 case (DWORD) DIPROP_BUFFERSIZE: {
1140 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1141 TRACE("buffersize = %ld\n",pd->dwData);
1142 if (This->data_queue)
1143 This->data_queue = HeapReAlloc(GetProcessHeap(),0, This->data_queue, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
1145 This->data_queue = HeapAlloc(GetProcessHeap(),0, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
1146 This->queue_head = 0;
1147 This->queue_tail = 0;
1148 This->queue_len = pd->dwData;
1151 case (DWORD)DIPROP_RANGE: {
1152 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
1153 if (ph->dwHow == DIPH_DEVICE) {
1154 TRACE("proprange(%ld,%ld) all\n",pr->lMin,pr->lMax);
1155 for (i = 0; i < This->user_df->dwNumObjs; i++) {
1156 This->props[i].lMin = pr->lMin;
1157 This->props[i].lMax = pr->lMax;
1160 int obj = find_property(This, ph);
1161 TRACE("proprange(%ld,%ld) obj=%d\n",pr->lMin,pr->lMax,obj);
1163 This->props[obj].lMin = pr->lMin;
1164 This->props[obj].lMax = pr->lMax;
1170 case (DWORD)DIPROP_DEADZONE: {
1171 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1172 if (ph->dwHow == DIPH_DEVICE) {
1173 TRACE("deadzone(%ld) all\n",pd->dwData);
1174 for (i = 0; i < This->user_df->dwNumObjs; i++)
1175 This->props[i].lDeadZone = pd->dwData;
1177 int obj = find_property(This, ph);
1178 TRACE("deadzone(%ld) obj=%d\n",pd->dwData,obj);
1180 This->props[obj].lDeadZone = pd->dwData;
1186 case (DWORD)DIPROP_SATURATION: {
1187 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1188 if (ph->dwHow == DIPH_DEVICE) {
1189 TRACE("saturation(%ld) all\n",pd->dwData);
1190 for (i = 0; i < This->user_df->dwNumObjs; i++)
1191 This->props[i].lSaturation = pd->dwData;
1193 int obj = find_property(This, ph);
1194 TRACE("saturation(%ld) obj=%d\n",pd->dwData,obj);
1196 This->props[obj].lSaturation = pd->dwData;
1203 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
1211 /******************************************************************************
1212 * SetEventNotification : specifies event to be sent on state change
1214 static HRESULT WINAPI JoystickAImpl_SetEventNotification(
1215 LPDIRECTINPUTDEVICE8A iface, HANDLE hnd
1217 JoystickImpl *This = (JoystickImpl *)iface;
1219 TRACE("(this=%p,0x%08lx)\n",This,(DWORD)hnd);
1224 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
1225 LPDIRECTINPUTDEVICE8A iface,
1226 LPDIDEVCAPS lpDIDevCaps)
1228 JoystickImpl *This = (JoystickImpl *)iface;
1231 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
1233 if (lpDIDevCaps == NULL) {
1234 WARN("invalid parameter: lpDIDevCaps = NULL\n");
1235 return DIERR_INVALIDPARAM;
1238 size = lpDIDevCaps->dwSize;
1239 CopyMemory(lpDIDevCaps, &This->devcaps, size);
1240 lpDIDevCaps->dwSize = size;
1242 if (TRACE_ON(dinput))
1243 _dump_DIDEVCAPS(lpDIDevCaps);
1248 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface)
1250 JoystickImpl *This = (JoystickImpl *)iface;
1252 TRACE("(%p)\n",This);
1254 if (!This->acquired) {
1255 WARN("not acquired\n");
1256 return DIERR_NOTACQUIRED;
1263 /******************************************************************************
1264 * EnumObjects : enumerate the different buttons and axis...
1266 static HRESULT WINAPI JoystickAImpl_EnumObjects(
1267 LPDIRECTINPUTDEVICE8A iface,
1268 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
1272 JoystickImpl *This = (JoystickImpl *)iface;
1273 DIDEVICEOBJECTINSTANCEA ddoi;
1278 TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
1279 if (TRACE_ON(dinput)) {
1280 TRACE(" - flags = ");
1281 _dump_EnumObjects_flags(dwFlags);
1285 /* Only the fields till dwFFMaxForce are relevant */
1286 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
1288 /* For the joystick, do as is done in the GetCapabilities function */
1289 if ((dwFlags == DIDFT_ALL) ||
1290 (dwFlags & DIDFT_AXIS) ||
1291 (dwFlags & DIDFT_POV)) {
1292 int pov[4] = { 0, 0, 0, 0 };
1296 for (i = 0; i < This->axes; i++) {
1297 int wine_obj = This->axis_map[i];
1302 ddoi.guidType = GUID_XAxis;
1305 ddoi.guidType = GUID_YAxis;
1308 ddoi.guidType = GUID_ZAxis;
1311 ddoi.guidType = GUID_RxAxis;
1314 ddoi.guidType = GUID_RyAxis;
1317 ddoi.guidType = GUID_RzAxis;
1320 ddoi.guidType = GUID_Slider;
1323 ddoi.guidType = GUID_Slider;
1327 ddoi.guidType = GUID_POV;
1331 ddoi.guidType = GUID_POV;
1335 ddoi.guidType = GUID_POV;
1339 ddoi.guidType = GUID_POV;
1342 ddoi.guidType = GUID_Unknown;
1345 user_offset = This->offsets[wine_obj]; /* get user offset from wine index */
1346 user_object = offset_to_object(This, user_offset);
1348 ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
1349 ddoi.dwOfs = This->user_df->rgodf[user_object].dwOfs;
1350 sprintf(ddoi.tszName, "Axis %d", axes);
1353 if (pov[wine_obj - 8] < 2) {
1354 user_offset = This->offsets[wine_obj]; /* get user offset from wine index */
1355 user_object = offset_to_object(This, user_offset);
1357 ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
1358 ddoi.dwOfs = This->user_df->rgodf[user_object].dwOfs;
1359 sprintf(ddoi.tszName, "POV %d", povs);
1365 _dump_OBJECTINSTANCEA(&ddoi);
1366 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE)
1372 if ((dwFlags == DIDFT_ALL) ||
1373 (dwFlags & DIDFT_BUTTON)) {
1375 /* The DInput SDK says that GUID_Button is only for mouse buttons but well... */
1376 ddoi.guidType = GUID_Button;
1378 for (i = 0; i < This->buttons; i++) {
1379 user_offset = This->offsets[i + 12]; /* get user offset from wine index */
1380 user_object = offset_to_object(This, user_offset);
1381 ddoi.guidType = GUID_Button;
1382 ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
1383 ddoi.dwOfs = This->user_df->rgodf[user_object].dwOfs;
1384 sprintf(ddoi.tszName, "Button %d", i);
1385 _dump_OBJECTINSTANCEA(&ddoi);
1386 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1393 /******************************************************************************
1394 * EnumObjects : enumerate the different buttons and axis...
1396 static HRESULT WINAPI JoystickWImpl_EnumObjects(
1397 LPDIRECTINPUTDEVICE8W iface,
1398 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
1402 JoystickImpl *This = (JoystickImpl *)iface;
1404 device_enumobjects_AtoWcb_data data;
1406 data.lpCallBack = lpCallback;
1407 data.lpvRef = lpvRef;
1409 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
1412 /******************************************************************************
1413 * GetProperty : get input device properties
1415 static HRESULT WINAPI JoystickAImpl_GetProperty(
1416 LPDIRECTINPUTDEVICE8A iface,
1418 LPDIPROPHEADER pdiph)
1420 JoystickImpl *This = (JoystickImpl *)iface;
1422 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(rguid), pdiph);
1424 if (TRACE_ON(dinput))
1425 _dump_DIPROPHEADER(pdiph);
1427 if (!HIWORD(rguid)) {
1428 switch ((DWORD)rguid) {
1429 case (DWORD) DIPROP_BUFFERSIZE: {
1430 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1431 TRACE(" return buffersize = %d\n",This->queue_len);
1432 pd->dwData = This->queue_len;
1435 case (DWORD) DIPROP_RANGE: {
1436 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
1437 int obj = find_property(This, pdiph);
1438 /* The app is querying the current range of the axis
1439 * return the lMin and lMax values */
1441 pr->lMin = This->props[obj].lMin;
1442 pr->lMax = This->props[obj].lMax;
1443 TRACE("range(%ld, %ld) obj=%d\n", pr->lMin, pr->lMax, obj);
1448 case (DWORD) DIPROP_DEADZONE: {
1449 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1450 int obj = find_property(This, pdiph);
1452 pd->dwData = This->props[obj].lDeadZone;
1453 TRACE("deadzone(%ld) obj=%d\n", pd->dwData, obj);
1458 case (DWORD) DIPROP_SATURATION: {
1459 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1460 int obj = find_property(This, pdiph);
1462 pd->dwData = This->props[obj].lSaturation;
1463 TRACE("saturation(%ld) obj=%d\n", pd->dwData, obj);
1469 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
1477 /******************************************************************************
1478 * GetObjectInfo : get object info
1480 HRESULT WINAPI JoystickAImpl_GetObjectInfo(
1481 LPDIRECTINPUTDEVICE8A iface,
1482 LPDIDEVICEOBJECTINSTANCEA pdidoi,
1486 JoystickImpl *This = (JoystickImpl *)iface;
1487 DIDEVICEOBJECTINSTANCEA didoiA;
1490 TRACE("(%p,%p,%ld,0x%08lx(%s))\n",
1491 iface, pdidoi, dwObj, dwHow,
1492 dwHow == DIPH_BYOFFSET ? "DIPH_BYOFFSET" :
1493 dwHow == DIPH_BYID ? "DIPH_BYID" :
1494 dwHow == DIPH_BYUSAGE ? "DIPH_BYUSAGE" :
1497 if (pdidoi == NULL) {
1498 WARN("invalid parameter: pdidoi = NULL\n");
1499 return DIERR_INVALIDPARAM;
1502 if ((pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEA)) &&
1503 (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3A))) {
1504 WARN("invalid parameter: pdidoi->dwSize = %ld != %d or %d\n",
1505 pdidoi->dwSize, sizeof(DIDEVICEOBJECTINSTANCEA),
1506 sizeof(DIDEVICEOBJECTINSTANCE_DX3A));
1507 return DIERR_INVALIDPARAM;
1510 ZeroMemory(&didoiA, sizeof(didoiA));
1511 didoiA.dwSize = pdidoi->dwSize;
1514 case DIPH_BYOFFSET: {
1518 for (i = 0; i < This->user_df->dwNumObjs; i++) {
1519 if (This->user_df->rgodf[i].dwOfs == dwObj) {
1520 if (This->user_df->rgodf[i].pguid)
1521 didoiA.guidType = *This->user_df->rgodf[i].pguid;
1523 didoiA.guidType = GUID_NULL;
1525 didoiA.dwOfs = dwObj;
1526 didoiA.dwType = This->user_df->rgodf[i].dwType;
1527 didoiA.dwFlags = This->user_df->rgodf[i].dwFlags;
1529 if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_AXIS)
1530 sprintf(didoiA.tszName, "Axis %d", axis);
1531 else if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_POV)
1532 sprintf(didoiA.tszName, "POV %d", pov);
1533 else if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_BUTTON)
1534 sprintf(didoiA.tszName, "Button %d", button);
1536 CopyMemory(pdidoi, &didoiA, pdidoi->dwSize);
1540 if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_AXIS)
1542 else if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_POV)
1544 else if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_BUTTON)
1550 FIXME("dwHow = DIPH_BYID not implemented\n");
1553 FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1556 WARN("invalid parameter: dwHow = %08lx\n", dwHow);
1557 return DIERR_INVALIDPARAM;
1560 CopyMemory(pdidoi, &didoiA, pdidoi->dwSize);
1565 /******************************************************************************
1566 * GetDeviceInfo : get information about a device's identity
1568 HRESULT WINAPI JoystickAImpl_GetDeviceInfo(
1569 LPDIRECTINPUTDEVICE8A iface,
1570 LPDIDEVICEINSTANCEA pdidi)
1572 JoystickImpl *This = (JoystickImpl *)iface;
1574 TRACE("(%p,%p)\n", iface, pdidi);
1576 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
1577 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA))) {
1578 WARN("invalid parameter: pdidi->dwSize = %ld != %d or %d\n",
1579 pdidi->dwSize, sizeof(DIDEVICEINSTANCE_DX3A),
1580 sizeof(DIDEVICEINSTANCEA));
1581 return DIERR_INVALIDPARAM;
1584 /* Return joystick */
1585 pdidi->guidInstance = GUID_Joystick;
1586 pdidi->guidProduct = DInput_Wine_Joystick_GUID;
1587 /* we only support traditional joysticks for now */
1588 pdidi->dwDevType = This->devcaps.dwDevType;
1589 strcpy(pdidi->tszInstanceName, "Joystick");
1590 strcpy(pdidi->tszProductName, This->name);
1591 if (pdidi->dwSize > sizeof(DIDEVICEINSTANCE_DX3A)) {
1592 pdidi->guidFFDriver = GUID_NULL;
1593 pdidi->wUsagePage = 0;
1600 /******************************************************************************
1601 * GetDeviceInfo : get information about a device's identity
1603 HRESULT WINAPI JoystickWImpl_GetDeviceInfo(
1604 LPDIRECTINPUTDEVICE8W iface,
1605 LPDIDEVICEINSTANCEW pdidi)
1607 JoystickImpl *This = (JoystickImpl *)iface;
1609 TRACE("(%p,%p)\n", iface, pdidi);
1611 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3W)) &&
1612 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW))) {
1613 WARN("invalid parameter: pdidi->dwSize = %ld != %d or %d\n",
1614 pdidi->dwSize, sizeof(DIDEVICEINSTANCE_DX3W),
1615 sizeof(DIDEVICEINSTANCEW));
1616 return DIERR_INVALIDPARAM;
1619 /* Return joystick */
1620 pdidi->guidInstance = GUID_Joystick;
1621 pdidi->guidProduct = DInput_Wine_Joystick_GUID;
1622 /* we only support traditional joysticks for now */
1623 pdidi->dwDevType = This->devcaps.dwDevType;
1624 MultiByteToWideChar(CP_ACP, 0, "Joystick", -1, pdidi->tszInstanceName, MAX_PATH);
1625 MultiByteToWideChar(CP_ACP, 0, This->name, -1, pdidi->tszProductName, MAX_PATH);
1626 if (pdidi->dwSize > sizeof(DIDEVICEINSTANCE_DX3W)) {
1627 pdidi->guidFFDriver = GUID_NULL;
1628 pdidi->wUsagePage = 0;
1635 static IDirectInputDevice8AVtbl JoystickAvt =
1637 IDirectInputDevice2AImpl_QueryInterface,
1638 IDirectInputDevice2AImpl_AddRef,
1639 JoystickAImpl_Release,
1640 JoystickAImpl_GetCapabilities,
1641 JoystickAImpl_EnumObjects,
1642 JoystickAImpl_GetProperty,
1643 JoystickAImpl_SetProperty,
1644 JoystickAImpl_Acquire,
1645 JoystickAImpl_Unacquire,
1646 JoystickAImpl_GetDeviceState,
1647 JoystickAImpl_GetDeviceData,
1648 JoystickAImpl_SetDataFormat,
1649 JoystickAImpl_SetEventNotification,
1650 IDirectInputDevice2AImpl_SetCooperativeLevel,
1651 JoystickAImpl_GetObjectInfo,
1652 JoystickAImpl_GetDeviceInfo,
1653 IDirectInputDevice2AImpl_RunControlPanel,
1654 IDirectInputDevice2AImpl_Initialize,
1655 IDirectInputDevice2AImpl_CreateEffect,
1656 IDirectInputDevice2AImpl_EnumEffects,
1657 IDirectInputDevice2AImpl_GetEffectInfo,
1658 IDirectInputDevice2AImpl_GetForceFeedbackState,
1659 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1660 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1661 IDirectInputDevice2AImpl_Escape,
1663 IDirectInputDevice2AImpl_SendDeviceData,
1664 IDirectInputDevice7AImpl_EnumEffectsInFile,
1665 IDirectInputDevice7AImpl_WriteEffectToFile,
1666 IDirectInputDevice8AImpl_BuildActionMap,
1667 IDirectInputDevice8AImpl_SetActionMap,
1668 IDirectInputDevice8AImpl_GetImageInfo
1671 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1672 # define XCAST(fun) (typeof(SysJoystickWvt.fun))
1674 # define XCAST(fun) (void*)
1677 static IDirectInputDevice8WVtbl SysJoystickWvt =
1679 IDirectInputDevice2WImpl_QueryInterface,
1680 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1681 XCAST(Release)JoystickAImpl_Release,
1682 XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1683 JoystickWImpl_EnumObjects,
1684 XCAST(GetProperty)JoystickAImpl_GetProperty,
1685 XCAST(SetProperty)JoystickAImpl_SetProperty,
1686 XCAST(Acquire)JoystickAImpl_Acquire,
1687 XCAST(Unacquire)JoystickAImpl_Unacquire,
1688 XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1689 XCAST(GetDeviceData)JoystickAImpl_GetDeviceData,
1690 XCAST(SetDataFormat)JoystickAImpl_SetDataFormat,
1691 XCAST(SetEventNotification)JoystickAImpl_SetEventNotification,
1692 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1693 IDirectInputDevice2WImpl_GetObjectInfo,
1694 JoystickWImpl_GetDeviceInfo,
1695 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1696 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1697 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
1698 IDirectInputDevice2WImpl_EnumEffects,
1699 IDirectInputDevice2WImpl_GetEffectInfo,
1700 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
1701 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1702 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1703 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1704 XCAST(Poll)JoystickAImpl_Poll,
1705 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1706 IDirectInputDevice7WImpl_EnumEffectsInFile,
1707 IDirectInputDevice7WImpl_WriteEffectToFile,
1708 IDirectInputDevice8WImpl_BuildActionMap,
1709 IDirectInputDevice8WImpl_SetActionMap,
1710 IDirectInputDevice8WImpl_GetImageInfo
1714 #endif /* HAVE_LINUX_22_JOYSTICK_API */