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>
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_NEW "/dev/input/js"
73 #define JOYDEV_OLD "/dev/js"
87 typedef struct JoystickImpl JoystickImpl;
88 static const IDirectInputDevice8AVtbl JoystickAvt;
89 static const IDirectInputDevice8WVtbl JoystickWvt;
92 struct IDirectInputDevice2AImpl base;
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 */
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: %d\n", lpDIDevCaps->dwSize);
130 TRACE("dwFlags: %08x\n", lpDIDevCaps->dwFlags);
131 TRACE("dwDevType: %08x %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: %d\n", lpDIDevCaps->dwAxes);
139 TRACE("dwButtons: %d\n", lpDIDevCaps->dwButtons);
140 TRACE("dwPOVs: %d\n", lpDIDevCaps->dwPOVs);
141 if (lpDIDevCaps->dwSize > sizeof(DIDEVCAPS_DX3)) {
142 TRACE("dwFFSamplePeriod: %d\n", lpDIDevCaps->dwFFSamplePeriod);
143 TRACE("dwFFMinTimeResolution: %d\n", lpDIDevCaps->dwFFMinTimeResolution);
144 TRACE("dwFirmwareRevision: %d\n", lpDIDevCaps->dwFirmwareRevision);
145 TRACE("dwHardwareRevision: %d\n", lpDIDevCaps->dwHardwareRevision);
146 TRACE("dwFFDriverVersion: %d\n", lpDIDevCaps->dwFFDriverVersion);
150 static int joydev_get_device(char *dev, int id)
153 sprintf(dev, "%s%d", JOYDEV_NEW, id);
154 if ((ret = open(dev, O_RDONLY)) < 0) {
155 sprintf(dev, "%s%d", JOYDEV_OLD, id);
156 if ((ret = open(dev, O_RDONLY)) < 0) {
163 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
168 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
169 WARN("force feedback not supported\n");
173 if ((dwDevType == 0) ||
174 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
175 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
176 /* check whether we have a joystick */
177 if ((fd = joydev_get_device(dev, id)) < 0) {
178 WARN("open(%s,O_RDONLY) failed: %s\n", dev, strerror(errno));
182 /* Return joystick */
183 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
184 lpddi->guidInstance.Data3 = id;
185 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
186 /* we only support traditional joysticks for now */
187 if (version >= 0x0800)
188 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
190 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
191 sprintf(lpddi->tszInstanceName, "Joystick %d", id);
192 #if defined(JSIOCGNAME)
193 if (ioctl(fd,JSIOCGNAME(sizeof(lpddi->tszProductName)),lpddi->tszProductName) < 0) {
194 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", dev, strerror(errno));
195 strcpy(lpddi->tszProductName, "Wine Joystick");
198 strcpy(lpddi->tszProductName, "Wine Joystick");
201 lpddi->guidFFDriver = GUID_NULL;
203 TRACE("Enumerating the linux Joystick device: %s (%s)\n", dev, lpddi->tszProductName);
210 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
217 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
218 WARN("force feedback not supported\n");
222 if ((dwDevType == 0) ||
223 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
224 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
225 /* check whether we have a joystick */
226 if ((fd = joydev_get_device(dev, id)) < 0) {
227 WARN("open(%s,O_RDONLY) failed: %s\n", dev, strerror(errno));
231 /* Return joystick */
232 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
233 lpddi->guidInstance.Data3 = id;
234 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
235 /* we only support traditional joysticks for now */
236 if (version >= 0x0800)
237 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
239 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
240 sprintf(friendly, "Joystick %d", id);
241 MultiByteToWideChar(CP_ACP, 0, friendly, -1, lpddi->tszInstanceName, MAX_PATH);
242 #if defined(JSIOCGNAME)
243 if (ioctl(fd,JSIOCGNAME(sizeof(name)),name) < 0) {
244 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", dev, strerror(errno));
245 strcpy(name, "Wine Joystick");
248 strcpy(name, "Wine Joystick");
250 MultiByteToWideChar(CP_ACP, 0, name, -1, lpddi->tszProductName, MAX_PATH);
251 lpddi->guidFFDriver = GUID_NULL;
253 TRACE("Enumerating the linux Joystick device: %s (%s)\n",dev,name);
261 * Get a config key from either the app-specific or the default config
264 inline static DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
265 char *buffer, DWORD size )
267 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size ))
270 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size ))
273 return ERROR_FILE_NOT_FOUND;
277 * Setup the dinput options.
280 static HRESULT setup_dinput_options(JoystickImpl * device)
282 char buffer[MAX_PATH+16];
283 HKEY hkey, appkey = 0;
286 buffer[MAX_PATH]='\0';
288 /* @@ Wine registry key: HKCU\Software\Wine\DirectInput */
289 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectInput", &hkey)) hkey = 0;
291 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
292 if (len && len < MAX_PATH) {
294 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectInput */
295 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
297 char *p, *appname = buffer;
298 if ((p = strrchr( appname, '/' ))) appname = p + 1;
299 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
300 strcat( appname, "\\DirectInput" );
301 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
302 RegCloseKey( tmpkey );
308 if (!get_config_key( hkey, appkey, "DefaultDeadZone", buffer, MAX_PATH )) {
309 device->deadzone = atoi(buffer);
310 TRACE("setting default deadzone to: \"%s\" %d\n", buffer, device->deadzone);
313 if (!get_config_key( hkey, appkey, device->name, buffer, MAX_PATH )) {
317 const char *delim = ",";
319 TRACE("\"%s\" = \"%s\"\n", device->name, buffer);
321 device->axis_map = HeapAlloc(GetProcessHeap(), 0, device->axes * sizeof(int));
322 if (device->axis_map == 0)
323 return DIERR_OUTOFMEMORY;
325 if ((ptr = strtok(buffer, delim)) != NULL) {
327 if (strcmp(ptr, "X") == 0) {
328 device->axis_map[tokens] = 0;
330 } else if (strcmp(ptr, "Y") == 0) {
331 device->axis_map[tokens] = 1;
333 } else if (strcmp(ptr, "Z") == 0) {
334 device->axis_map[tokens] = 2;
336 } else if (strcmp(ptr, "Rx") == 0) {
337 device->axis_map[tokens] = 3;
339 } else if (strcmp(ptr, "Ry") == 0) {
340 device->axis_map[tokens] = 4;
342 } else if (strcmp(ptr, "Rz") == 0) {
343 device->axis_map[tokens] = 5;
345 } else if (strcmp(ptr, "Slider1") == 0) {
346 device->axis_map[tokens] = 6;
348 } else if (strcmp(ptr, "Slider2") == 0) {
349 device->axis_map[tokens] = 7;
351 } else if (strcmp(ptr, "POV1") == 0) {
352 device->axis_map[tokens++] = 8;
353 device->axis_map[tokens] = 8;
355 } else if (strcmp(ptr, "POV2") == 0) {
356 device->axis_map[tokens++] = 9;
357 device->axis_map[tokens] = 9;
359 } else if (strcmp(ptr, "POV3") == 0) {
360 device->axis_map[tokens++] = 10;
361 device->axis_map[tokens] = 10;
363 } else if (strcmp(ptr, "POV4") == 0) {
364 device->axis_map[tokens++] = 11;
365 device->axis_map[tokens] = 11;
368 ERR("invalid joystick axis type: %s\n", ptr);
369 device->axis_map[tokens] = tokens;
374 } while ((ptr = strtok(NULL, delim)) != NULL);
376 if (tokens != device->devcaps.dwAxes) {
377 ERR("not all joystick axes mapped: %d axes(%d,%d), %d arguments\n", device->axes, axis, pov,tokens);
378 while (tokens < device->axes) {
379 device->axis_map[tokens] = tokens;
385 device->devcaps.dwAxes = axis;
386 device->devcaps.dwPOVs = pov;
390 RegCloseKey( appkey );
398 static void calculate_ids(JoystickImpl* device)
408 /* Make two passes over the format. The first counts the number
409 * for each type and the second sets the id */
410 for (i = 0; i < device->user_df->dwNumObjs; i++) {
411 if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_AXIS)
413 else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_POV)
415 else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_BUTTON)
421 button_base = axis + pov;
427 for (i = 0; i < device->user_df->dwNumObjs; i++) {
429 if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_AXIS) {
431 type = DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) |
432 DIDFT_MAKEINSTANCE(axis + axis_base);
433 TRACE("axis type = 0x%08x\n", type);
434 } else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_POV) {
436 type = DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) |
437 DIDFT_MAKEINSTANCE(pov + pov_base);
438 TRACE("POV type = 0x%08x\n", type);
439 } else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_BUTTON) {
441 type = DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) |
442 DIDFT_MAKEINSTANCE(button + button_base);
443 TRACE("button type = 0x%08x\n", type);
445 device->user_df->rgodf[i].dwType = type;
449 static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, LPDIRECTINPUTDEVICEA* pdev)
452 JoystickImpl* newDevice;
456 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
457 if (newDevice == 0) {
458 WARN("out of memory\n");
460 return DIERR_OUTOFMEMORY;
463 if ((newDevice->joyfd = joydev_get_device(newDevice->dev, rguid->Data3)) < 0) {
464 WARN("open(%s,O_RDONLY) failed: %s\n", newDevice->dev, strerror(errno));
465 HeapFree(GetProcessHeap(), 0, newDevice);
466 return DIERR_DEVICENOTREG;
469 /* get the device name */
470 #if defined(JSIOCGNAME)
471 if (ioctl(newDevice->joyfd,JSIOCGNAME(MAX_PATH),name) < 0) {
472 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", newDevice->dev, strerror(errno));
473 strcpy(name, "Wine Joystick");
476 strcpy(name, "Wine Joystick");
479 /* copy the device name */
480 newDevice->name = HeapAlloc(GetProcessHeap(),0,strlen(name) + 1);
481 strcpy(newDevice->name, name);
484 if (ioctl(newDevice->joyfd,JSIOCGAXES,&newDevice->axes) < 0) {
485 WARN("ioctl(%s,JSIOCGAXES) failed: %s, defauting to 2\n", newDevice->dev, strerror(errno));
490 if (ioctl(newDevice->joyfd,JSIOCGBUTTONS,&newDevice->buttons) < 0) {
491 WARN("ioctl(%s,JSIOCGBUTTONS) failed: %s, defauting to 2\n", newDevice->dev, strerror(errno));
492 newDevice->buttons = 2;
496 newDevice->base.lpVtbl = jvt;
497 newDevice->base.ref = 1;
498 newDevice->dinput = dinput;
499 newDevice->acquired = FALSE;
500 newDevice->overflow = FALSE;
501 CopyMemory(&newDevice->base.guid, rguid, sizeof(*rguid));
503 /* setup_dinput_options may change these */
504 newDevice->deadzone = 5000;
505 newDevice->devcaps.dwButtons = newDevice->buttons;
506 newDevice->devcaps.dwAxes = newDevice->axes;
507 newDevice->devcaps.dwPOVs = 0;
509 /* do any user specified configuration */
510 hr = setup_dinput_options(newDevice);
514 if (newDevice->axis_map == 0) {
515 newDevice->axis_map = HeapAlloc(GetProcessHeap(), 0, newDevice->axes * sizeof(int));
516 if (newDevice->axis_map == 0)
519 for (i = 0; i < newDevice->axes; i++)
520 newDevice->axis_map[i] = i;
523 /* wine uses DIJOYSTATE2 as it's internal format so copy
524 * the already defined format c_dfDIJoystick2 */
525 newDevice->user_df = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwSize);
526 if (newDevice->user_df == 0)
529 CopyMemory(newDevice->user_df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
531 /* copy default objects */
532 newDevice->user_df->rgodf = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
533 if (newDevice->user_df->rgodf == 0)
536 CopyMemory(newDevice->user_df->rgodf,c_dfDIJoystick2.rgodf,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
538 /* create default properties */
539 newDevice->props = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwNumObjs*sizeof(ObjProps));
540 if (newDevice->props == 0)
543 /* initialize default properties */
544 for (i = 0; i < c_dfDIJoystick2.dwNumObjs; i++) {
545 newDevice->props[i].lMin = 0;
546 newDevice->props[i].lMax = 0xffff;
547 newDevice->props[i].lDeadZone = newDevice->deadzone; /* % * 1000 */
548 newDevice->props[i].lSaturation = 0;
551 /* create an offsets array */
552 newDevice->offsets = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,c_dfDIJoystick2.dwNumObjs*sizeof(int));
553 if (newDevice->offsets == 0)
556 /* create the default transform filter */
557 newDevice->transform = create_DataFormat(&c_dfDIJoystick2, newDevice->user_df, newDevice->offsets);
559 calculate_ids(newDevice);
561 IDirectInputDevice_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
562 InitializeCriticalSection(&(newDevice->crit));
563 newDevice->crit.DebugInfo->Spare[0] = (DWORD_PTR)"DINPUT_Mouse";
565 newDevice->devcaps.dwSize = sizeof(newDevice->devcaps);
566 newDevice->devcaps.dwFlags = DIDC_ATTACHED;
567 if (newDevice->dinput->dwVersion >= 0x0800)
568 newDevice->devcaps.dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
570 newDevice->devcaps.dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
571 newDevice->devcaps.dwFFSamplePeriod = 0;
572 newDevice->devcaps.dwFFMinTimeResolution = 0;
573 newDevice->devcaps.dwFirmwareRevision = 0;
574 newDevice->devcaps.dwHardwareRevision = 0;
575 newDevice->devcaps.dwFFDriverVersion = 0;
577 if (TRACE_ON(dinput)) {
578 _dump_DIDATAFORMAT(newDevice->user_df);
579 for (i = 0; i < (newDevice->axes); i++)
580 TRACE("axis_map[%d] = %d\n", i, newDevice->axis_map[i]);
581 _dump_DIDEVCAPS(&newDevice->devcaps);
584 *pdev = (LPDIRECTINPUTDEVICEA)newDevice;
589 hr = DIERR_OUTOFMEMORY;
591 HeapFree(GetProcessHeap(),0,newDevice->axis_map);
592 HeapFree(GetProcessHeap(),0,newDevice->name);
593 HeapFree(GetProcessHeap(),0,newDevice->props);
594 HeapFree(GetProcessHeap(),0,newDevice->user_df->rgodf);
595 HeapFree(GetProcessHeap(),0,newDevice->user_df);
596 HeapFree(GetProcessHeap(),0,newDevice);
602 static BOOL IsJoystickGUID(REFGUID guid)
604 GUID wine_joystick = DInput_Wine_Joystick_GUID;
605 GUID dev_guid = *guid;
607 wine_joystick.Data3 = 0;
610 return IsEqualGUID(&wine_joystick, &dev_guid);
613 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
615 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
616 (IsJoystickGUID(rguid))) {
617 if ((riid == NULL) ||
618 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
619 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
620 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
621 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
622 return alloc_device(rguid, &JoystickAvt, dinput, pdev);
624 WARN("no interface\n");
626 return DIERR_NOINTERFACE;
630 WARN("invalid device GUID\n");
632 return DIERR_DEVICENOTREG;
635 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
637 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
638 (IsJoystickGUID(rguid))) {
639 if ((riid == NULL) ||
640 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
641 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
642 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
643 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
644 return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA *)pdev);
646 WARN("no interface\n");
648 return DIERR_NOINTERFACE;
652 WARN("invalid device GUID\n");
654 return DIERR_DEVICENOTREG;
657 const struct dinput_device joystick_linux_device = {
658 "Wine Linux joystick driver",
661 joydev_create_deviceA,
662 joydev_create_deviceW
665 /******************************************************************************
668 static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
670 JoystickImpl *This = (JoystickImpl *)iface;
673 ref = InterlockedDecrement(&This->base.ref);
677 /* Free the device name */
678 HeapFree(GetProcessHeap(),0,This->name);
680 /* Free the axis map */
681 HeapFree(GetProcessHeap(),0,This->axis_map);
683 /* Free the data queue */
684 HeapFree(GetProcessHeap(),0,This->data_queue);
686 /* Free the DataFormat */
687 HeapFree(GetProcessHeap(), 0, This->user_df->rgodf);
688 HeapFree(GetProcessHeap(), 0, This->user_df);
690 /* Free the properties */
691 HeapFree(GetProcessHeap(), 0, This->props);
693 /* Free the offsets array */
694 HeapFree(GetProcessHeap(),0,This->offsets);
696 /* release the data transform filter */
697 release_DataFormat(This->transform);
699 This->crit.DebugInfo->Spare[0] = 0;
700 DeleteCriticalSection(&(This->crit));
701 IDirectInputDevice_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
703 HeapFree(GetProcessHeap(),0,This);
707 /******************************************************************************
708 * SetDataFormat : the application can choose the format of the data
709 * the device driver sends back with GetDeviceState.
711 static HRESULT WINAPI JoystickAImpl_SetDataFormat(
712 LPDIRECTINPUTDEVICE8A iface,
715 JoystickImpl *This = (JoystickImpl *)iface;
717 LPDIDATAFORMAT new_df = 0;
718 LPDIOBJECTDATAFORMAT new_rgodf = 0;
719 ObjProps * new_props = 0;
721 TRACE("(%p,%p)\n",This,df);
724 WARN("invalid pointer\n");
728 if (df->dwSize != sizeof(*df)) {
729 WARN("invalid argument\n");
730 return DIERR_INVALIDPARAM;
733 if (This->acquired) {
735 return DIERR_ACQUIRED;
738 if (TRACE_ON(dinput))
739 _dump_DIDATAFORMAT(df);
741 /* Store the new data format */
742 new_df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
746 new_rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
750 new_props = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*sizeof(ObjProps));
754 HeapFree(GetProcessHeap(),0,This->user_df);
755 HeapFree(GetProcessHeap(),0,This->user_df->rgodf);
756 HeapFree(GetProcessHeap(),0,This->props);
757 release_DataFormat(This->transform);
759 This->user_df = new_df;
760 CopyMemory(This->user_df, df, df->dwSize);
761 This->user_df->rgodf = new_rgodf;
762 CopyMemory(This->user_df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
763 This->props = new_props;
764 for (i = 0; i < df->dwNumObjs; i++) {
765 This->props[i].lMin = 0;
766 This->props[i].lMax = 0xffff;
767 This->props[i].lDeadZone = 1000;
768 This->props[i].lSaturation = 0;
770 This->transform = create_DataFormat(&c_dfDIJoystick2, This->user_df, This->offsets);
777 WARN("out of memory\n");
778 HeapFree(GetProcessHeap(),0,new_props);
779 HeapFree(GetProcessHeap(),0,new_rgodf);
780 HeapFree(GetProcessHeap(),0,new_df);
781 return DIERR_OUTOFMEMORY;
784 /******************************************************************************
785 * Acquire : gets exclusive control of the joystick
787 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
789 JoystickImpl *This = (JoystickImpl *)iface;
791 TRACE("(%p)\n",This);
793 if (This->acquired) {
794 WARN("already acquired\n");
798 /* open the joystick device */
799 if (This->joyfd==-1) {
800 TRACE("opening joystick device %s\n", This->dev);
802 This->joyfd=open(This->dev,O_RDONLY);
803 if (This->joyfd==-1) {
804 ERR("open(%s) failed: %s\n", This->dev, strerror(errno));
805 return DIERR_NOTFOUND;
809 This->acquired = TRUE;
814 /******************************************************************************
815 * Unacquire : frees the joystick
817 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
819 JoystickImpl *This = (JoystickImpl *)iface;
821 TRACE("(%p)\n",This);
823 if (!This->acquired) {
824 WARN("not acquired\n");
825 return DIERR_NOTACQUIRED;
828 if (This->joyfd!=-1) {
829 TRACE("closing joystick device\n");
832 This->acquired = FALSE;
836 This->acquired = FALSE;
841 static LONG map_axis(JoystickImpl * This, short val, short index)
844 double fmin = This->props[index].lMin;
845 double fmax = This->props[index].lMax;
848 fret = (((fval + 32767.0) * (fmax - fmin)) / (32767.0*2.0)) + fmin;
858 /* convert wine format offset to user format object index */
859 static int offset_to_object(JoystickImpl *This, int offset)
863 for (i = 0; i < This->user_df->dwNumObjs; i++) {
864 if (This->user_df->rgodf[i].dwOfs == offset)
871 static LONG calculate_pov(JoystickImpl *This, int index)
873 if (This->povs[index].lX < -16384) {
874 if (This->povs[index].lY < -16384)
875 This->js.rgdwPOV[index] = 31500;
876 else if (This->povs[index].lY > 16384)
877 This->js.rgdwPOV[index] = 22500;
879 This->js.rgdwPOV[index] = 27000;
880 } else if (This->povs[index].lX > 16384) {
881 if (This->povs[index].lY < -16384)
882 This->js.rgdwPOV[index] = 4500;
883 else if (This->povs[index].lY > 16384)
884 This->js.rgdwPOV[index] = 13500;
886 This->js.rgdwPOV[index] = 9000;
888 if (This->povs[index].lY < -16384)
889 This->js.rgdwPOV[index] = 0;
890 else if (This->povs[index].lY > 16384)
891 This->js.rgdwPOV[index] = 18000;
893 This->js.rgdwPOV[index] = -1;
896 return This->js.rgdwPOV[index];
899 static void joy_polldev(JoystickImpl *This) {
903 TRACE("(%p)\n", This);
905 if (This->joyfd==-1) {
910 memset(&tv,0,sizeof(tv));
911 FD_ZERO(&readfds);FD_SET(This->joyfd,&readfds);
912 if (1>select(This->joyfd+1,&readfds,NULL,NULL,&tv))
914 /* we have one event, so we can read */
915 if (sizeof(jse)!=read(This->joyfd,&jse,sizeof(jse))) {
918 TRACE("js_event: type 0x%x, number %d, value %d\n",
919 jse.type,jse.number,jse.value);
920 if (jse.type & JS_EVENT_BUTTON) {
921 int offset = This->offsets[jse.number + 12];
922 int value = jse.value?0x80:0x00;
924 This->js.rgbButtons[jse.number] = value;
925 GEN_EVENT(offset,value,jse.time,(This->dinput->evsequence)++);
926 } else if (jse.type & JS_EVENT_AXIS) {
927 int number = This->axis_map[jse.number]; /* wine format object index */
929 int offset = This->offsets[number];
930 int index = offset_to_object(This, offset);
931 LONG value = map_axis(This, jse.value, index);
933 /* FIXME do deadzone and saturation here */
935 TRACE("changing axis %d => %d\n", jse.number, number);
947 This->js.lRx = value;
950 This->js.lRy = value;
953 This->js.lRz = value;
956 This->js.rglSlider[0] = value;
959 This->js.rglSlider[1] = value;
962 /* FIXME don't go off array */
963 if (This->axis_map[jse.number + 1] == number)
964 This->povs[0].lX = jse.value;
965 else if (This->axis_map[jse.number - 1] == number)
966 This->povs[0].lY = jse.value;
967 value = calculate_pov(This, 0);
970 if (This->axis_map[jse.number + 1] == number)
971 This->povs[1].lX = jse.value;
972 else if (This->axis_map[jse.number - 1] == number)
973 This->povs[1].lY = jse.value;
974 value = calculate_pov(This, 1);
977 if (This->axis_map[jse.number + 1] == number)
978 This->povs[2].lX = jse.value;
979 else if (This->axis_map[jse.number - 1] == number)
980 This->povs[2].lY = jse.value;
981 value = calculate_pov(This, 2);
984 if (This->axis_map[jse.number + 1] == number)
985 This->povs[3].lX = jse.value;
986 else if (This->axis_map[jse.number - 1] == number)
987 This->povs[3].lY = jse.value;
988 value = calculate_pov(This, 3);
992 GEN_EVENT(offset,value,jse.time,(This->dinput->evsequence)++);
994 WARN("axis %d not supported\n", number);
999 /******************************************************************************
1000 * GetDeviceState : returns the "state" of the joystick.
1003 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
1004 LPDIRECTINPUTDEVICE8A iface,
1008 JoystickImpl *This = (JoystickImpl *)iface;
1010 TRACE("(%p,0x%08x,%p)\n", This, len, ptr);
1012 if (!This->acquired) {
1013 WARN("not acquired\n");
1014 return DIERR_NOTACQUIRED;
1017 /* update joystick state */
1020 /* convert and copy data to user supplied buffer */
1021 fill_DataFormat(ptr, &This->js, This->transform);
1026 /******************************************************************************
1027 * GetDeviceData : gets buffered input data.
1029 static HRESULT WINAPI JoystickAImpl_GetDeviceData(
1030 LPDIRECTINPUTDEVICE8A iface,
1032 LPDIDEVICEOBJECTDATA dod,
1036 JoystickImpl *This = (JoystickImpl *)iface;
1041 TRACE("(%p)->(dods=%d,entries=%d,fl=0x%08x)\n", This, dodsize, *entries, flags);
1043 if (!This->acquired) {
1044 WARN("not acquired\n");
1045 return DIERR_NOTACQUIRED;
1048 EnterCriticalSection(&(This->crit));
1052 len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0)
1053 + (This->queue_head - This->queue_tail);
1059 TRACE("Application discarding %d event(s).\n", len);
1062 nqtail = This->queue_tail + len;
1063 while (nqtail >= This->queue_len)
1064 nqtail -= This->queue_len;
1066 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
1067 ERR("Wrong structure size !\n");
1068 LeaveCriticalSection(&(This->crit));
1069 return DIERR_INVALIDPARAM;
1073 TRACE("Application retrieving %d event(s).\n", len);
1076 nqtail = This->queue_tail;
1078 /* Copy the buffered data into the application queue */
1079 memcpy((char *)dod + *entries * dodsize, This->data_queue + nqtail, dodsize);
1080 /* Advance position */
1082 if (nqtail >= This->queue_len)
1083 nqtail -= This->queue_len;
1089 if (This->overflow) {
1090 hr = DI_BUFFEROVERFLOW;
1091 if (!(flags & DIGDD_PEEK)) {
1092 This->overflow = FALSE;
1096 if (!(flags & DIGDD_PEEK))
1097 This->queue_tail = nqtail;
1099 LeaveCriticalSection(&(This->crit));
1104 static int find_property(JoystickImpl * This, LPCDIPROPHEADER ph)
1107 if (ph->dwHow == DIPH_BYOFFSET) {
1108 return offset_to_object(This, ph->dwObj);
1109 } else if (ph->dwHow == DIPH_BYID) {
1110 for (i = 0; i < This->user_df->dwNumObjs; i++) {
1111 if ((This->user_df->rgodf[i].dwType & 0x00ffffff) == (ph->dwObj & 0x00ffffff)) {
1120 /******************************************************************************
1121 * SetProperty : change input device properties
1123 static HRESULT WINAPI JoystickAImpl_SetProperty(
1124 LPDIRECTINPUTDEVICE8A iface,
1128 JoystickImpl *This = (JoystickImpl *)iface;
1131 TRACE("(%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
1134 WARN("invalid parameter: ph == NULL\n");
1135 return DIERR_INVALIDPARAM;
1138 if (TRACE_ON(dinput))
1139 _dump_DIPROPHEADER(ph);
1141 if (!HIWORD(rguid)) {
1142 switch (LOWORD(rguid)) {
1143 case (DWORD) DIPROP_BUFFERSIZE: {
1144 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1145 TRACE("buffersize = %d\n", pd->dwData);
1146 if (This->data_queue)
1147 This->data_queue = HeapReAlloc(GetProcessHeap(),0, This->data_queue, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
1149 This->data_queue = HeapAlloc(GetProcessHeap(),0, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
1150 This->queue_head = 0;
1151 This->queue_tail = 0;
1152 This->queue_len = pd->dwData;
1155 case (DWORD)DIPROP_RANGE: {
1156 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
1157 if (ph->dwHow == DIPH_DEVICE) {
1158 TRACE("proprange(%d,%d) all\n", pr->lMin, pr->lMax);
1159 for (i = 0; i < This->user_df->dwNumObjs; i++) {
1160 This->props[i].lMin = pr->lMin;
1161 This->props[i].lMax = pr->lMax;
1164 int obj = find_property(This, ph);
1165 TRACE("proprange(%d,%d) obj=%d\n", pr->lMin, pr->lMax, obj);
1167 This->props[obj].lMin = pr->lMin;
1168 This->props[obj].lMax = pr->lMax;
1174 case (DWORD)DIPROP_DEADZONE: {
1175 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1176 if (ph->dwHow == DIPH_DEVICE) {
1177 TRACE("deadzone(%d) all\n", pd->dwData);
1178 for (i = 0; i < This->user_df->dwNumObjs; i++)
1179 This->props[i].lDeadZone = pd->dwData;
1181 int obj = find_property(This, ph);
1182 TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
1184 This->props[obj].lDeadZone = pd->dwData;
1190 case (DWORD)DIPROP_SATURATION: {
1191 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1192 if (ph->dwHow == DIPH_DEVICE) {
1193 TRACE("saturation(%d) all\n", pd->dwData);
1194 for (i = 0; i < This->user_df->dwNumObjs; i++)
1195 This->props[i].lSaturation = pd->dwData;
1197 int obj = find_property(This, ph);
1198 TRACE("saturation(%d) obj=%d\n", pd->dwData, obj);
1200 This->props[obj].lSaturation = pd->dwData;
1207 FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
1215 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
1216 LPDIRECTINPUTDEVICE8A iface,
1217 LPDIDEVCAPS lpDIDevCaps)
1219 JoystickImpl *This = (JoystickImpl *)iface;
1222 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
1224 if (lpDIDevCaps == NULL) {
1225 WARN("invalid pointer\n");
1229 size = lpDIDevCaps->dwSize;
1231 if (!(size == sizeof(DIDEVCAPS) || size == sizeof(DIDEVCAPS_DX3))) {
1232 WARN("invalid parameter\n");
1233 return DIERR_INVALIDPARAM;
1236 CopyMemory(lpDIDevCaps, &This->devcaps, size);
1237 lpDIDevCaps->dwSize = size;
1239 if (TRACE_ON(dinput))
1240 _dump_DIDEVCAPS(lpDIDevCaps);
1245 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface)
1247 JoystickImpl *This = (JoystickImpl *)iface;
1249 TRACE("(%p)\n",This);
1251 if (!This->acquired) {
1252 WARN("not acquired\n");
1253 return DIERR_NOTACQUIRED;
1260 /******************************************************************************
1261 * EnumObjects : enumerate the different buttons and axis...
1263 static HRESULT WINAPI JoystickAImpl_EnumObjects(
1264 LPDIRECTINPUTDEVICE8A iface,
1265 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
1269 JoystickImpl *This = (JoystickImpl *)iface;
1270 DIDEVICEOBJECTINSTANCEA ddoi;
1275 TRACE("(this=%p,%p,%p,%08x)\n", This, lpCallback, lpvRef, dwFlags);
1276 if (TRACE_ON(dinput)) {
1277 TRACE(" - flags = ");
1278 _dump_EnumObjects_flags(dwFlags);
1282 /* Only the fields till dwFFMaxForce are relevant */
1283 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
1285 /* For the joystick, do as is done in the GetCapabilities function */
1286 if ((dwFlags == DIDFT_ALL) ||
1287 (dwFlags & DIDFT_AXIS) ||
1288 (dwFlags & DIDFT_POV)) {
1289 int pov[4] = { 0, 0, 0, 0 };
1293 for (i = 0; i < This->axes; i++) {
1294 int wine_obj = This->axis_map[i];
1299 ddoi.guidType = GUID_XAxis;
1302 ddoi.guidType = GUID_YAxis;
1305 ddoi.guidType = GUID_ZAxis;
1308 ddoi.guidType = GUID_RxAxis;
1311 ddoi.guidType = GUID_RyAxis;
1314 ddoi.guidType = GUID_RzAxis;
1317 ddoi.guidType = GUID_Slider;
1320 ddoi.guidType = GUID_Slider;
1324 ddoi.guidType = GUID_POV;
1328 ddoi.guidType = GUID_POV;
1332 ddoi.guidType = GUID_POV;
1336 ddoi.guidType = GUID_POV;
1339 ddoi.guidType = GUID_Unknown;
1342 user_offset = This->offsets[wine_obj]; /* get user offset from wine index */
1343 user_object = offset_to_object(This, user_offset);
1345 ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
1346 ddoi.dwOfs = This->user_df->rgodf[user_object].dwOfs;
1347 sprintf(ddoi.tszName, "Axis %d", axes);
1350 if (pov[wine_obj - 8] < 2) {
1351 user_offset = This->offsets[wine_obj]; /* get user offset from wine index */
1352 user_object = offset_to_object(This, user_offset);
1354 ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
1355 ddoi.dwOfs = This->user_df->rgodf[user_object].dwOfs;
1356 sprintf(ddoi.tszName, "POV %d", povs);
1362 _dump_OBJECTINSTANCEA(&ddoi);
1363 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE)
1369 if ((dwFlags == DIDFT_ALL) ||
1370 (dwFlags & DIDFT_BUTTON)) {
1372 /* The DInput SDK says that GUID_Button is only for mouse buttons but well... */
1373 ddoi.guidType = GUID_Button;
1375 for (i = 0; i < This->buttons; i++) {
1376 user_offset = This->offsets[i + 12]; /* get user offset from wine index */
1377 user_object = offset_to_object(This, user_offset);
1378 ddoi.guidType = GUID_Button;
1379 ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
1380 ddoi.dwOfs = This->user_df->rgodf[user_object].dwOfs;
1381 sprintf(ddoi.tszName, "Button %d", i);
1382 _dump_OBJECTINSTANCEA(&ddoi);
1383 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1390 /******************************************************************************
1391 * EnumObjects : enumerate the different buttons and axis...
1393 static HRESULT WINAPI JoystickWImpl_EnumObjects(
1394 LPDIRECTINPUTDEVICE8W iface,
1395 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
1399 JoystickImpl *This = (JoystickImpl *)iface;
1401 device_enumobjects_AtoWcb_data data;
1403 data.lpCallBack = lpCallback;
1404 data.lpvRef = lpvRef;
1406 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
1409 /******************************************************************************
1410 * GetProperty : get input device properties
1412 static HRESULT WINAPI JoystickAImpl_GetProperty(
1413 LPDIRECTINPUTDEVICE8A iface,
1415 LPDIPROPHEADER pdiph)
1417 JoystickImpl *This = (JoystickImpl *)iface;
1419 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(rguid), pdiph);
1421 if (TRACE_ON(dinput))
1422 _dump_DIPROPHEADER(pdiph);
1424 if (!HIWORD(rguid)) {
1425 switch (LOWORD(rguid)) {
1426 case (DWORD) DIPROP_BUFFERSIZE: {
1427 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1428 TRACE(" return buffersize = %d\n",This->queue_len);
1429 pd->dwData = This->queue_len;
1432 case (DWORD) DIPROP_RANGE: {
1433 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
1434 int obj = find_property(This, pdiph);
1435 /* The app is querying the current range of the axis
1436 * return the lMin and lMax values */
1438 pr->lMin = This->props[obj].lMin;
1439 pr->lMax = This->props[obj].lMax;
1440 TRACE("range(%d, %d) obj=%d\n", pr->lMin, pr->lMax, obj);
1445 case (DWORD) DIPROP_DEADZONE: {
1446 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1447 int obj = find_property(This, pdiph);
1449 pd->dwData = This->props[obj].lDeadZone;
1450 TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
1455 case (DWORD) DIPROP_SATURATION: {
1456 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1457 int obj = find_property(This, pdiph);
1459 pd->dwData = This->props[obj].lSaturation;
1460 TRACE("saturation(%d) obj=%d\n", pd->dwData, obj);
1466 FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
1474 /******************************************************************************
1475 * GetObjectInfo : get object info
1477 HRESULT WINAPI JoystickAImpl_GetObjectInfo(
1478 LPDIRECTINPUTDEVICE8A iface,
1479 LPDIDEVICEOBJECTINSTANCEA pdidoi,
1483 JoystickImpl *This = (JoystickImpl *)iface;
1484 DIDEVICEOBJECTINSTANCEA didoiA;
1487 TRACE("(%p,%p,%d,0x%08x(%s))\n",
1488 iface, pdidoi, dwObj, dwHow,
1489 dwHow == DIPH_BYOFFSET ? "DIPH_BYOFFSET" :
1490 dwHow == DIPH_BYID ? "DIPH_BYID" :
1491 dwHow == DIPH_BYUSAGE ? "DIPH_BYUSAGE" :
1494 if (pdidoi == NULL) {
1495 WARN("invalid parameter: pdidoi = NULL\n");
1496 return DIERR_INVALIDPARAM;
1499 if ((pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCEA)) &&
1500 (pdidoi->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3A))) {
1501 WARN("invalid parameter: pdidoi->dwSize = %d != %d or %d\n",
1502 pdidoi->dwSize, sizeof(DIDEVICEOBJECTINSTANCEA),
1503 sizeof(DIDEVICEOBJECTINSTANCE_DX3A));
1504 return DIERR_INVALIDPARAM;
1507 ZeroMemory(&didoiA, sizeof(didoiA));
1508 didoiA.dwSize = pdidoi->dwSize;
1511 case DIPH_BYOFFSET: {
1515 for (i = 0; i < This->user_df->dwNumObjs; i++) {
1516 if (This->user_df->rgodf[i].dwOfs == dwObj) {
1517 if (This->user_df->rgodf[i].pguid)
1518 didoiA.guidType = *This->user_df->rgodf[i].pguid;
1520 didoiA.guidType = GUID_NULL;
1522 didoiA.dwOfs = dwObj;
1523 didoiA.dwType = This->user_df->rgodf[i].dwType;
1524 didoiA.dwFlags = This->user_df->rgodf[i].dwFlags;
1526 if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_AXIS)
1527 sprintf(didoiA.tszName, "Axis %d", axis);
1528 else if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_POV)
1529 sprintf(didoiA.tszName, "POV %d", pov);
1530 else if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_BUTTON)
1531 sprintf(didoiA.tszName, "Button %d", button);
1533 CopyMemory(pdidoi, &didoiA, pdidoi->dwSize);
1537 if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_AXIS)
1539 else if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_POV)
1541 else if (DIDFT_GETTYPE(This->user_df->rgodf[i].dwType) & DIDFT_BUTTON)
1547 FIXME("dwHow = DIPH_BYID not implemented\n");
1550 FIXME("dwHow = DIPH_BYUSAGE not implemented\n");
1553 WARN("invalid parameter: dwHow = %08x\n", dwHow);
1554 return DIERR_INVALIDPARAM;
1557 CopyMemory(pdidoi, &didoiA, pdidoi->dwSize);
1562 /******************************************************************************
1563 * GetDeviceInfo : get information about a device's identity
1565 HRESULT WINAPI JoystickAImpl_GetDeviceInfo(
1566 LPDIRECTINPUTDEVICE8A iface,
1567 LPDIDEVICEINSTANCEA pdidi)
1569 JoystickImpl *This = (JoystickImpl *)iface;
1571 TRACE("(%p,%p)\n", iface, pdidi);
1573 if (pdidi == NULL) {
1574 WARN("invalid pointer\n");
1578 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
1579 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA))) {
1580 WARN("invalid parameter: pdidi->dwSize = %d != %d or %d\n",
1581 pdidi->dwSize, sizeof(DIDEVICEINSTANCE_DX3A),
1582 sizeof(DIDEVICEINSTANCEA));
1583 return DIERR_INVALIDPARAM;
1586 /* Return joystick */
1587 pdidi->guidInstance = GUID_Joystick;
1588 pdidi->guidProduct = DInput_Wine_Joystick_GUID;
1589 /* we only support traditional joysticks for now */
1590 pdidi->dwDevType = This->devcaps.dwDevType;
1591 strcpy(pdidi->tszInstanceName, "Joystick");
1592 strcpy(pdidi->tszProductName, This->name);
1593 if (pdidi->dwSize > sizeof(DIDEVICEINSTANCE_DX3A)) {
1594 pdidi->guidFFDriver = GUID_NULL;
1595 pdidi->wUsagePage = 0;
1602 /******************************************************************************
1603 * GetDeviceInfo : get information about a device's identity
1605 HRESULT WINAPI JoystickWImpl_GetDeviceInfo(
1606 LPDIRECTINPUTDEVICE8W iface,
1607 LPDIDEVICEINSTANCEW pdidi)
1609 JoystickImpl *This = (JoystickImpl *)iface;
1611 TRACE("(%p,%p)\n", iface, pdidi);
1613 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3W)) &&
1614 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW))) {
1615 WARN("invalid parameter: pdidi->dwSize = %d != %d or %d\n",
1616 pdidi->dwSize, sizeof(DIDEVICEINSTANCE_DX3W),
1617 sizeof(DIDEVICEINSTANCEW));
1618 return DIERR_INVALIDPARAM;
1621 /* Return joystick */
1622 pdidi->guidInstance = GUID_Joystick;
1623 pdidi->guidProduct = DInput_Wine_Joystick_GUID;
1624 /* we only support traditional joysticks for now */
1625 pdidi->dwDevType = This->devcaps.dwDevType;
1626 MultiByteToWideChar(CP_ACP, 0, "Joystick", -1, pdidi->tszInstanceName, MAX_PATH);
1627 MultiByteToWideChar(CP_ACP, 0, This->name, -1, pdidi->tszProductName, MAX_PATH);
1628 if (pdidi->dwSize > sizeof(DIDEVICEINSTANCE_DX3W)) {
1629 pdidi->guidFFDriver = GUID_NULL;
1630 pdidi->wUsagePage = 0;
1637 static const IDirectInputDevice8AVtbl JoystickAvt =
1639 IDirectInputDevice2AImpl_QueryInterface,
1640 IDirectInputDevice2AImpl_AddRef,
1641 JoystickAImpl_Release,
1642 JoystickAImpl_GetCapabilities,
1643 JoystickAImpl_EnumObjects,
1644 JoystickAImpl_GetProperty,
1645 JoystickAImpl_SetProperty,
1646 JoystickAImpl_Acquire,
1647 JoystickAImpl_Unacquire,
1648 JoystickAImpl_GetDeviceState,
1649 JoystickAImpl_GetDeviceData,
1650 JoystickAImpl_SetDataFormat,
1651 IDirectInputDevice2AImpl_SetEventNotification,
1652 IDirectInputDevice2AImpl_SetCooperativeLevel,
1653 JoystickAImpl_GetObjectInfo,
1654 JoystickAImpl_GetDeviceInfo,
1655 IDirectInputDevice2AImpl_RunControlPanel,
1656 IDirectInputDevice2AImpl_Initialize,
1657 IDirectInputDevice2AImpl_CreateEffect,
1658 IDirectInputDevice2AImpl_EnumEffects,
1659 IDirectInputDevice2AImpl_GetEffectInfo,
1660 IDirectInputDevice2AImpl_GetForceFeedbackState,
1661 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1662 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1663 IDirectInputDevice2AImpl_Escape,
1665 IDirectInputDevice2AImpl_SendDeviceData,
1666 IDirectInputDevice7AImpl_EnumEffectsInFile,
1667 IDirectInputDevice7AImpl_WriteEffectToFile,
1668 IDirectInputDevice8AImpl_BuildActionMap,
1669 IDirectInputDevice8AImpl_SetActionMap,
1670 IDirectInputDevice8AImpl_GetImageInfo
1673 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1674 # define XCAST(fun) (typeof(SysJoystickWvt.fun))
1676 # define XCAST(fun) (void*)
1679 static const IDirectInputDevice8WVtbl SysJoystickWvt =
1681 IDirectInputDevice2WImpl_QueryInterface,
1682 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1683 XCAST(Release)JoystickAImpl_Release,
1684 XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1685 JoystickWImpl_EnumObjects,
1686 XCAST(GetProperty)JoystickAImpl_GetProperty,
1687 XCAST(SetProperty)JoystickAImpl_SetProperty,
1688 XCAST(Acquire)JoystickAImpl_Acquire,
1689 XCAST(Unacquire)JoystickAImpl_Unacquire,
1690 XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1691 XCAST(GetDeviceData)JoystickAImpl_GetDeviceData,
1692 XCAST(SetDataFormat)JoystickAImpl_SetDataFormat,
1693 XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
1694 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1695 IDirectInputDevice2WImpl_GetObjectInfo,
1696 JoystickWImpl_GetDeviceInfo,
1697 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1698 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1699 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
1700 IDirectInputDevice2WImpl_EnumEffects,
1701 IDirectInputDevice2WImpl_GetEffectInfo,
1702 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
1703 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1704 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1705 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1706 XCAST(Poll)JoystickAImpl_Poll,
1707 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1708 IDirectInputDevice7WImpl_EnumEffectsInFile,
1709 IDirectInputDevice7WImpl_WriteEffectToFile,
1710 IDirectInputDevice8WImpl_BuildActionMap,
1711 IDirectInputDevice8WImpl_SetActionMap,
1712 IDirectInputDevice8WImpl_GetImageInfo
1716 #else /* HAVE_LINUX_22_JOYSTICK_API */
1718 const struct dinput_device joystick_linux_device = {
1719 "Wine Linux joystick driver",
1726 #endif /* HAVE_LINUX_22_JOYSTICK_API */