1 /* DirectInput Joystick device
3 * Copyright 1998,2000 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
6 * Copyright 2005 Daniel Remenak
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
34 #ifdef HAVE_SYS_TIME_H
35 # include <sys/time.h>
37 #include <sys/fcntl.h>
38 #ifdef HAVE_SYS_IOCTL_H
39 # include <sys/ioctl.h>
42 #ifdef HAVE_SYS_ERRNO_H
43 # include <sys/errno.h>
45 #ifdef HAVE_LINUX_INPUT_H
46 # include <linux/input.h>
48 # if defined(EVIOCGBIT) && defined(EV_ABS) && defined(BTN_PINKIE)
49 # define HAVE_CORRECT_LINUXINPUT_H
52 #ifdef HAVE_SYS_POLL_H
53 # include <sys/poll.h>
56 #include "wine/debug.h"
57 #include "wine/unicode.h"
64 #include "dinput_private.h"
65 #include "device_private.h"
67 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
71 * Maps POV x & y event values to a DX "clock" position:
78 DWORD joystick_map_pov(POINTL *p)
81 return p->y < 0 ? 4500 : !p->y ? 9000 : 13500;
83 return p->y < 0 ? 31500 : !p->y ? 27000 : 22500;
85 return p->y < 0 ? 0 : !p->y ? -1 : 18000;
89 * This maps the read value (from the input event) to a value in the
92 LONG joystick_map_axis(ObjProps *props, int val)
95 LONG center = (props->lMax - props->lMin) / 2;
97 /* map the value from the hmin-hmax range into the wmin-wmax range */
98 ret = MulDiv( val - props->lDevMin, props->lMax - props->lMin,
99 props->lDevMax - props->lDevMin );
101 if (abs( ret - center ) <= props->lDeadZone / 2 )
106 TRACE( "(%d %d) -> (%d <%d> %d): val=%d ret=%d\n",
107 props->lDevMin, props->lDevMax,
108 props->lMin, props->lDeadZone, props->lMax,
114 #ifdef HAVE_CORRECT_LINUXINPUT_H
116 #define EVDEVPREFIX "/dev/input/event"
118 /* Wine joystick driver object instances */
119 #define WINE_JOYSTICK_MAX_AXES 8
120 #define WINE_JOYSTICK_MAX_POVS 4
121 #define WINE_JOYSTICK_MAX_BUTTONS 128
123 struct wine_input_absinfo {
131 typedef struct EffectListItem EffectListItem;
132 struct EffectListItem
134 LPDIRECTINPUTEFFECT ref;
135 struct EffectListItem* next;
138 /* implemented in effect_linuxinput.c */
139 HRESULT linuxinput_create_effect(int* fd, REFGUID rguid, LPDIRECTINPUTEFFECT* peff);
140 HRESULT linuxinput_get_info_A(int fd, REFGUID rguid, LPDIEFFECTINFOA info);
141 HRESULT linuxinput_get_info_W(int fd, REFGUID rguid, LPDIEFFECTINFOW info);
143 typedef struct JoystickImpl JoystickImpl;
144 static const IDirectInputDevice8AVtbl JoystickAvt;
145 static const IDirectInputDevice8WVtbl JoystickWvt;
155 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
156 BYTE evbits[(EV_MAX+7)/8];
157 BYTE absbits[(ABS_MAX+7)/8];
158 BYTE keybits[(KEY_MAX+7)/8];
159 BYTE ffbits[(FF_MAX+7)/8];
161 /* data returned by the EVIOCGABS() ioctl */
162 struct wine_input_absinfo axes[ABS_MAX];
167 struct IDirectInputDevice2AImpl base;
169 struct JoyDev *joydev;
171 /* joystick private */
176 ObjProps props[ABS_MAX];
181 /* LUT for KEY_ to offset in rgbButtons */
182 BYTE buttons[KEY_MAX];
188 /* Force feedback variables */
189 EffectListItem* top_effect;
193 static void fake_current_js_state(JoystickImpl *ji);
194 static void find_joydevs(void);
196 /* This GUID is slightly different from the linux joystick one. Take note. */
197 static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
201 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
204 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
206 #define MAX_JOYDEV 64
208 static int have_joydevs = -1;
209 static struct JoyDev *joydevs = NULL;
211 static void find_joydevs(void)
215 if (have_joydevs!=-1) {
221 for (i=0;i<MAX_JOYDEV;i++) {
223 struct JoyDev joydev = {0};
228 snprintf(buf,MAX_PATH,EVDEVPREFIX"%d",i);
231 if ((fd=open(buf, O_RDWR))==-1) {
232 fd = open(buf, O_RDONLY);
238 if ((-1==ioctl(fd,EVIOCGBIT(0,sizeof(joydev.evbits)),joydev.evbits))) {
239 perror("EVIOCGBIT 0");
243 if (-1==ioctl(fd,EVIOCGBIT(EV_ABS,sizeof(joydev.absbits)),joydev.absbits)) {
244 perror("EVIOCGBIT EV_ABS");
248 if (-1==ioctl(fd,EVIOCGBIT(EV_KEY,sizeof(joydev.keybits)),joydev.keybits)) {
249 perror("EVIOCGBIT EV_KEY");
253 /* A true joystick has at least axis X and Y, and at least 1
254 * button. copied from linux/drivers/input/joydev.c */
255 if (test_bit(joydev.absbits,ABS_X) && test_bit(joydev.absbits,ABS_Y) &&
256 ( test_bit(joydev.keybits,BTN_TRIGGER) ||
257 test_bit(joydev.keybits,BTN_A) ||
258 test_bit(joydev.keybits,BTN_1)
262 joydev.device = strdup(buf);
264 if (-1!=ioctl(fd, EVIOCGNAME(MAX_PATH-1), buf)) {
266 joydev.name = strdup(buf);
268 joydev.name = joydev.device;
271 joydev.guid = DInput_Wine_Joystick_Base_GUID;
272 joydev.guid.Data3 += have_joydevs;
274 TRACE("Found a joystick on %s: %s (%s)\n",
275 joydev.device, joydev.name,
276 debugstr_guid(&joydev.guid)
279 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
281 test_bit(joydev.evbits, EV_FF) &&
282 ioctl(fd, EVIOCGBIT(EV_FF, sizeof(joydev.ffbits)), joydev.ffbits) != -1 &&
283 ioctl(fd, EVIOCGEFFECTS, &joydev.num_effects) != -1 &&
284 joydev.num_effects > 0)
286 TRACE(" ... with force feedback\n");
291 for (j=0;j<ABS_MAX;j++) {
292 if (test_bit(joydev.absbits,j)) {
293 if (-1!=ioctl(fd,EVIOCGABS(j),&(joydev.axes[j]))) {
294 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
296 joydev.axes[j].value,
297 joydev.axes[j].minimum,
298 joydev.axes[j].maximum,
306 if (have_joydevs==0) {
307 joydevs = HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev));
309 HeapReAlloc(GetProcessHeap(), 0, joydevs, (1+have_joydevs) * sizeof(struct JoyDev));
311 memcpy(joydevs+have_joydevs, &joydev, sizeof(struct JoyDev));
320 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
322 DWORD dwSize = lpddi->dwSize;
324 TRACE("%d %p\n", dwSize, lpddi);
325 memset(lpddi, 0, dwSize);
327 lpddi->dwSize = dwSize;
328 lpddi->guidInstance = joydevs[id].guid;
329 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
330 lpddi->guidFFDriver = GUID_NULL;
332 if (version >= 0x0800)
333 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
335 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
337 strcpy(lpddi->tszInstanceName, joydevs[id].name);
338 strcpy(lpddi->tszProductName, joydevs[id].device);
341 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
343 DWORD dwSize = lpddi->dwSize;
345 TRACE("%d %p\n", dwSize, lpddi);
346 memset(lpddi, 0, dwSize);
348 lpddi->dwSize = dwSize;
349 lpddi->guidInstance = joydevs[id].guid;
350 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
351 lpddi->guidFFDriver = GUID_NULL;
353 if (version >= 0x0800)
354 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
356 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
358 MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
359 MultiByteToWideChar(CP_ACP, 0, joydevs[id].device, -1, lpddi->tszProductName, MAX_PATH);
362 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
366 if (id >= have_joydevs) {
370 if (!((dwDevType == 0) ||
371 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
372 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
375 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
376 if (dwFlags & DIEDFL_FORCEFEEDBACK)
380 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
381 fill_joystick_dideviceinstanceA(lpddi, version, id);
387 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
391 if (id >= have_joydevs) {
395 if (!((dwDevType == 0) ||
396 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
397 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
400 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
401 if (dwFlags & DIEDFL_FORCEFEEDBACK)
405 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
406 fill_joystick_dideviceinstanceW(lpddi, version, id);
412 static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, unsigned short index)
414 JoystickImpl* newDevice;
415 LPDIDATAFORMAT df = NULL;
417 char buffer[MAX_PATH+16];
419 LONG def_deadzone = -1;
421 newDevice = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(JoystickImpl));
422 if (!newDevice) return NULL;
424 newDevice->base.lpVtbl = jvt;
425 newDevice->base.ref = 1;
426 newDevice->base.guid = *rguid;
427 newDevice->base.dinput = dinput;
428 newDevice->joyfd = -1;
429 newDevice->joydev = &joydevs[index];
430 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
431 newDevice->ff_state = FF_STATUS_STOPPED;
433 InitializeCriticalSection(&newDevice->base.crit);
434 newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->base.crit");
437 get_app_key(&hkey, &appkey);
439 if (!get_config_key(hkey, appkey, "DefaultDeadZone", buffer, MAX_PATH))
441 def_deadzone = atoi(buffer);
442 TRACE("setting default deadzone to: %d\n", def_deadzone);
444 if (appkey) RegCloseKey(appkey);
445 if (hkey) RegCloseKey(hkey);
447 /* Create copy of default data format */
448 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto failed;
449 memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
450 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
452 /* Supported Axis & POVs should map 1-to-1 */
453 for (i = 0; i < WINE_JOYSTICK_MAX_AXES; i++)
455 if (!test_bit(newDevice->joydev->absbits, i)) {
456 newDevice->axes[i] = -1;
460 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i], df->dwObjSize);
461 newDevice->axes[i] = idx;
462 newDevice->props[idx].lDevMin = newDevice->joydev->axes[i].minimum;
463 newDevice->props[idx].lDevMax = newDevice->joydev->axes[i].maximum;
464 newDevice->props[idx].lMin = 0;
465 newDevice->props[idx].lMax = 0xffff;
466 newDevice->props[idx].lSaturation = 0;
467 newDevice->props[idx].lDeadZone = def_deadzone >= 0 ? def_deadzone :
468 MulDiv(newDevice->joydev->axes[i].flat, 0xffff,
469 newDevice->props[idx].lDevMax - newDevice->props[idx].lDevMin);
471 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->numAxes++) | DIDFT_ABSAXIS;
474 for (i = 0; i < WINE_JOYSTICK_MAX_POVS; i++)
476 if (!test_bit(newDevice->joydev->absbits, ABS_HAT0X + i * 2) ||
477 !test_bit(newDevice->joydev->absbits, ABS_HAT0Y + i * 2)) {
478 newDevice->axes[ABS_HAT0X + i * 2] = newDevice->axes[ABS_HAT0Y + i * 2] = -1;
482 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + WINE_JOYSTICK_MAX_AXES], df->dwObjSize);
483 newDevice->axes[ABS_HAT0X + i * 2] = newDevice->axes[ABS_HAT0Y + i * 2] = i;
484 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->numPOVs++) | DIDFT_POV;
487 /* Buttons can be anywhere, so check all */
488 for (i = 0; i < KEY_MAX && newDevice->numButtons < WINE_JOYSTICK_MAX_BUTTONS; i++)
490 if (!test_bit(newDevice->joydev->keybits, i)) continue;
492 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[newDevice->numButtons + WINE_JOYSTICK_MAX_AXES + WINE_JOYSTICK_MAX_POVS], df->dwObjSize);
493 newDevice->buttons[i] = 0x80 | newDevice->numButtons;
494 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->numButtons++) | DIDFT_PSHBUTTON;
498 fake_current_js_state(newDevice);
500 newDevice->base.data_format.wine_df = df;
501 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->base.dinput);
505 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
506 HeapFree(GetProcessHeap(), 0, df);
507 HeapFree(GetProcessHeap(), 0, newDevice);
511 /******************************************************************************
512 * get_joystick_index : Get the joystick index from a given GUID
514 static unsigned short get_joystick_index(REFGUID guid)
516 GUID wine_joystick = DInput_Wine_Joystick_Base_GUID;
517 GUID dev_guid = *guid;
519 wine_joystick.Data3 = 0;
522 /* for the standard joystick GUID use index 0 */
523 if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
525 /* for the wine joystick GUIDs use the index stored in Data3 */
526 if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3 - DInput_Wine_Joystick_Base_GUID.Data3;
531 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
533 unsigned short index;
537 if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
538 have_joydevs && index < have_joydevs)
540 if ((riid == NULL) ||
541 IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
542 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
543 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
544 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
546 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, index);
547 TRACE("Created a Joystick device (%p)\n", *pdev);
551 ERR("out of memory\n");
552 return DIERR_OUTOFMEMORY;
557 WARN("no interface\n");
558 return DIERR_NOINTERFACE;
561 WARN("invalid device GUID\n");
562 return DIERR_DEVICENOTREG;
566 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
568 unsigned short index;
572 if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
573 have_joydevs && index < have_joydevs)
575 if ((riid == NULL) ||
576 IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
577 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
578 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
579 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
581 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, index);
582 TRACE("Created a Joystick device (%p)\n", *pdev);
586 ERR("out of memory\n");
587 return DIERR_OUTOFMEMORY;
591 WARN("no interface\n");
592 return DIERR_NOINTERFACE;
595 WARN("invalid device GUID\n");
596 return DIERR_DEVICENOTREG;
599 const struct dinput_device joystick_linuxinput_device = {
600 "Wine Linux-input joystick driver",
603 joydev_create_deviceA,
604 joydev_create_deviceW
607 /******************************************************************************
608 * Acquire : gets exclusive control of the joystick
610 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
612 JoystickImpl *This = (JoystickImpl *)iface;
615 TRACE("(this=%p)\n",This);
617 res = IDirectInputDevice2AImpl_Acquire(iface);
619 if (-1==(This->joyfd=open(This->joydev->device,O_RDWR))) {
620 if (-1==(This->joyfd=open(This->joydev->device,O_RDONLY))) {
621 /* Couldn't open the device at all */
622 perror(This->joydev->device);
623 IDirectInputDevice2AImpl_Unacquire(iface);
624 return DIERR_NOTFOUND;
626 /* Couldn't open in r/w but opened in read-only. */
627 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This->joydev->device);
635 /******************************************************************************
636 * Unacquire : frees the joystick
638 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
640 JoystickImpl *This = (JoystickImpl *)iface;
643 TRACE("(this=%p)\n",This);
644 res = IDirectInputDevice2AImpl_Unacquire(iface);
645 if (res==DI_OK && This->joyfd!=-1) {
653 * set the current state of the js device as it would be with the middle
656 #define CENTER_AXIS(a) \
657 (ji->axes[a] == -1 ? 0 : joystick_map_axis( &ji->props[ji->axes[a]], \
658 ji->joydev->axes[a].value ))
659 static void fake_current_js_state(JoystickImpl *ji)
663 /* center the axes */
664 ji->js.lX = CENTER_AXIS(ABS_X);
665 ji->js.lY = CENTER_AXIS(ABS_Y);
666 ji->js.lZ = CENTER_AXIS(ABS_Z);
667 ji->js.lRx = CENTER_AXIS(ABS_RX);
668 ji->js.lRy = CENTER_AXIS(ABS_RY);
669 ji->js.lRz = CENTER_AXIS(ABS_RZ);
670 ji->js.rglSlider[0] = CENTER_AXIS(ABS_THROTTLE);
671 ji->js.rglSlider[1] = CENTER_AXIS(ABS_RUDDER);
673 /* POV center is -1 */
674 for (i = 0; i < 4; i++)
675 ji->js.rgdwPOV[i] = -1;
679 /* convert wine format offset to user format object index */
680 static void joy_polldev(JoystickImpl *This)
683 struct input_event ie;
693 plfd.fd = This->joyfd;
694 plfd.events = POLLIN;
696 if (poll(&plfd,1,0) != 1)
699 /* we have one event, so we can read */
700 if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
703 TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
705 case EV_KEY: /* button */
707 int btn = This->buttons[ie.code];
709 TRACE("(%p) %d -> %d\n", This, ie.code, btn);
713 inst_id = DIDFT_MAKEINSTANCE(btn) | DIDFT_PSHBUTTON;
714 This->js.rgbButtons[btn] = value = ie.value ? 0x80 : 0x00;
720 int axis = This->axes[ie.code];
724 inst_id = DIDFT_MAKEINSTANCE(axis) | (ie.code < ABS_HAT0X ? DIDFT_ABSAXIS : DIDFT_POV);
725 value = joystick_map_axis(&This->props[id_to_object(This->base.data_format.wine_df, inst_id)], ie.value);
728 case ABS_X: This->js.lX = value; break;
729 case ABS_Y: This->js.lY = value; break;
730 case ABS_Z: This->js.lZ = value; break;
731 case ABS_RX: This->js.lRx = value; break;
732 case ABS_RY: This->js.lRy = value; break;
733 case ABS_RZ: This->js.lRz = value; break;
734 case ABS_THROTTLE: This->js.rglSlider[0] = value; break;
735 case ABS_RUDDER: This->js.rglSlider[1] = value; break;
736 case ABS_HAT0X: case ABS_HAT0Y: case ABS_HAT1X: case ABS_HAT1Y:
737 case ABS_HAT2X: case ABS_HAT2Y: case ABS_HAT3X: case ABS_HAT3Y:
739 int idx = (ie.code - ABS_HAT0X) / 2;
742 This->povs[idx].y = ie.value;
744 This->povs[idx].x = ie.value;
746 This->js.rgdwPOV[idx] = value = joystick_map_pov(&This->povs[idx]);
750 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie.code,ie.value);
754 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
756 This->ff_state = ie.value;
761 /* there is nothing to do */
765 FIXME("joystick cannot handle type %d event (code %d)\n",ie.type,ie.code);
769 queue_event((LPDIRECTINPUTDEVICE8A)This,
770 id_to_offset(&This->base.data_format, inst_id),
771 value, ie.time.tv_usec, This->base.dinput->evsequence++);
775 /******************************************************************************
776 * GetDeviceState : returns the "state" of the joystick.
779 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
780 LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
782 JoystickImpl *This = (JoystickImpl *)iface;
784 TRACE("(this=%p,0x%08x,%p)\n", This, len, ptr);
786 if (!This->base.acquired)
788 WARN("not acquired\n");
789 return DIERR_NOTACQUIRED;
794 /* convert and copy data to user supplied buffer */
795 fill_DataFormat(ptr, &This->js, &This->base.data_format);
800 /******************************************************************************
801 * SetProperty : change input device properties
803 static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
807 JoystickImpl *This = (JoystickImpl *)iface;
810 WARN("invalid argument\n");
811 return DIERR_INVALIDPARAM;
814 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
815 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
816 ph->dwSize, ph->dwHeaderSize, ph->dwObj, ph->dwHow);
818 if (!HIWORD(rguid)) {
819 switch (LOWORD(rguid)) {
820 case (DWORD)DIPROP_RANGE: {
821 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
823 if (ph->dwHow == DIPH_DEVICE) {
825 TRACE("proprange(%d,%d) all\n", pr->lMin, pr->lMax);
826 for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++) {
827 /* Scale dead-zone */
828 This->props[i].lDeadZone = MulDiv(This->props[i].lDeadZone, pr->lMax - pr->lMin,
829 This->props[i].lMax - This->props[i].lMin);
830 This->props[i].lMin = pr->lMin;
831 This->props[i].lMax = pr->lMax;
834 int obj = find_property(&This->base.data_format, ph);
836 TRACE("proprange(%d,%d) obj=%d\n", pr->lMin, pr->lMax, obj);
838 /* Scale dead-zone */
839 This->props[obj].lDeadZone = MulDiv(This->props[obj].lDeadZone, pr->lMax - pr->lMin,
840 This->props[obj].lMax - This->props[obj].lMin);
841 This->props[obj].lMin = pr->lMin;
842 This->props[obj].lMax = pr->lMax;
845 fake_current_js_state(This);
848 case (DWORD)DIPROP_DEADZONE: {
849 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
850 if (ph->dwHow == DIPH_DEVICE) {
852 TRACE("deadzone(%d) all\n", pd->dwData);
853 for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++) {
854 This->props[i].lDeadZone = pd->dwData;
857 int obj = find_property(&This->base.data_format, ph);
859 TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
861 This->props[obj].lDeadZone = pd->dwData;
864 fake_current_js_state(This);
867 case (DWORD)DIPROP_CALIBRATIONMODE: {
868 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
869 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd->dwData);
872 case (DWORD)DIPROP_AUTOCENTER: {
873 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
875 FIXME("DIPROP_AUTOCENTER(%d)\n", pd->dwData);
879 return IDirectInputDevice2AImpl_SetProperty(iface, rguid, ph);
885 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
886 LPDIRECTINPUTDEVICE8A iface,
887 LPDIDEVCAPS lpDIDevCaps)
889 JoystickImpl *This = (JoystickImpl *)iface;
891 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
894 WARN("invalid pointer\n");
898 if (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) {
899 WARN("invalid argument\n");
900 return DIERR_INVALIDPARAM;
903 lpDIDevCaps->dwFlags = DIDC_ATTACHED;
904 if (This->base.dinput->dwVersion >= 0x0800)
905 lpDIDevCaps->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
907 lpDIDevCaps->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
909 if (This->joydev->has_ff)
910 lpDIDevCaps->dwFlags |= DIDC_FORCEFEEDBACK;
912 lpDIDevCaps->dwAxes = This->numAxes;
913 lpDIDevCaps->dwButtons = This->numButtons;
914 lpDIDevCaps->dwPOVs = This->numPOVs;
919 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface)
921 JoystickImpl *This = (JoystickImpl *)iface;
923 TRACE("(%p)\n",This);
925 if (!This->base.acquired)
926 return DIERR_NOTACQUIRED;
932 /******************************************************************************
933 * GetProperty : get input device properties
935 static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
937 LPDIPROPHEADER pdiph)
939 JoystickImpl *This = (JoystickImpl *)iface;
941 TRACE("(this=%p,%s,%p)\n", iface, debugstr_guid(rguid), pdiph);
942 _dump_DIPROPHEADER(pdiph);
944 if (HIWORD(rguid)) return DI_OK;
946 switch (LOWORD(rguid)) {
947 case (DWORD) DIPROP_RANGE:
949 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
950 int obj = find_property(&This->base.data_format, pdiph);
952 if (obj < 0) return DIERR_OBJECTNOTFOUND;
954 pr->lMin = This->props[obj].lMin;
955 pr->lMax = This->props[obj].lMax;
956 TRACE("range(%d, %d) obj=%d\n", pr->lMin, pr->lMax, obj);
959 case (DWORD) DIPROP_DEADZONE:
961 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
962 int obj = find_property(&This->base.data_format, pdiph);
964 if (obj < 0) return DIERR_OBJECTNOTFOUND;
966 pd->dwData = This->props[obj].lDeadZone;
967 TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
972 return IDirectInputDevice2AImpl_GetProperty(iface, rguid, pdiph);
978 /******************************************************************************
979 * GetObjectInfo : get information about a device object such as a button
982 static HRESULT WINAPI JoystickWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
983 LPDIDEVICEOBJECTINSTANCEW pdidoi, DWORD dwObj, DWORD dwHow)
985 static const WCHAR axisW[] = {'A','x','i','s',' ','%','d',0};
986 static const WCHAR povW[] = {'P','O','V',' ','%','d',0};
987 static const WCHAR buttonW[] = {'B','u','t','t','o','n',' ','%','d',0};
990 res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
991 if (res != DI_OK) return res;
993 if (pdidoi->dwType & DIDFT_AXIS)
994 sprintfW(pdidoi->tszName, axisW, DIDFT_GETINSTANCE(pdidoi->dwType));
995 else if (pdidoi->dwType & DIDFT_POV)
996 sprintfW(pdidoi->tszName, povW, DIDFT_GETINSTANCE(pdidoi->dwType));
997 else if (pdidoi->dwType & DIDFT_BUTTON)
998 sprintfW(pdidoi->tszName, buttonW, DIDFT_GETINSTANCE(pdidoi->dwType));
1000 _dump_OBJECTINSTANCEW(pdidoi);
1004 static HRESULT WINAPI JoystickAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface,
1005 LPDIDEVICEOBJECTINSTANCEA pdidoi, DWORD dwObj, DWORD dwHow)
1008 DIDEVICEOBJECTINSTANCEW didoiW;
1009 DWORD dwSize = pdidoi->dwSize;
1011 didoiW.dwSize = sizeof(didoiW);
1012 res = JoystickWImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W)iface, &didoiW, dwObj, dwHow);
1013 if (res != DI_OK) return res;
1015 memset(pdidoi, 0, pdidoi->dwSize);
1016 memcpy(pdidoi, &didoiW, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, tszName));
1017 pdidoi->dwSize = dwSize;
1018 WideCharToMultiByte(CP_ACP, 0, didoiW.tszName, -1, pdidoi->tszName,
1019 sizeof(pdidoi->tszName), NULL, NULL);
1024 /******************************************************************************
1025 * CreateEffect - Create a new FF effect with the specified params
1027 static HRESULT WINAPI JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface,
1030 LPDIRECTINPUTEFFECT *ppdef,
1031 LPUNKNOWN pUnkOuter)
1033 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1034 EffectListItem* new = NULL;
1035 HRESULT retval = DI_OK;
1038 JoystickImpl* This = (JoystickImpl*)iface;
1039 TRACE("(this=%p,%p,%p,%p,%p)\n", This, rguid, lpeff, ppdef, pUnkOuter);
1041 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1042 TRACE("not available (compiled w/o ff support)\n");
1047 new = HeapAlloc(GetProcessHeap(), 0, sizeof(EffectListItem));
1048 new->next = This->top_effect;
1049 This->top_effect = new;
1051 retval = linuxinput_create_effect(&(This->joyfd), rguid, &(new->ref));
1052 if (retval != DI_OK)
1056 retval = IDirectInputEffect_SetParameters(new->ref, lpeff, 0);
1057 if (retval != DI_OK && retval != DI_DOWNLOADSKIPPED)
1062 if (pUnkOuter != NULL)
1063 FIXME("Interface aggregation not implemented.\n");
1067 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1070 /*******************************************************************************
1071 * EnumEffects - Enumerate available FF effects
1073 static HRESULT WINAPI JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface,
1074 LPDIENUMEFFECTSCALLBACKA lpCallback,
1078 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1079 DIEFFECTINFOA dei; /* feif */
1080 DWORD type = DIEFT_GETTYPE(dwEffType);
1081 JoystickImpl* This = (JoystickImpl*)iface;
1083 TRACE("(this=%p,%p,%d) type=%d\n", This, pvRef, dwEffType, type);
1085 dei.dwSize = sizeof(DIEFFECTINFOA);
1087 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1088 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1089 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1090 (*lpCallback)(&dei, pvRef);
1093 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1094 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1095 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1096 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1097 (*lpCallback)(&dei, pvRef);
1099 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1100 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1101 (*lpCallback)(&dei, pvRef);
1103 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1104 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1105 (*lpCallback)(&dei, pvRef);
1107 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1108 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1109 (*lpCallback)(&dei, pvRef);
1111 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1112 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1113 (*lpCallback)(&dei, pvRef);
1117 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1118 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1119 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1120 (*lpCallback)(&dei, pvRef);
1123 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1124 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1125 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1126 (*lpCallback)(&dei, pvRef);
1128 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1129 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1130 (*lpCallback)(&dei, pvRef);
1132 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1133 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1134 (*lpCallback)(&dei, pvRef);
1136 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1137 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1138 (*lpCallback)(&dei, pvRef);
1147 static HRESULT WINAPI JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface,
1148 LPDIENUMEFFECTSCALLBACKW lpCallback,
1152 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1153 /* seems silly to duplicate all this code but all the structures and functions
1154 * are actually different (A/W) */
1155 DIEFFECTINFOW dei; /* feif */
1156 DWORD type = DIEFT_GETTYPE(dwEffType);
1157 JoystickImpl* This = (JoystickImpl*)iface;
1158 int xfd = This->joyfd;
1160 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This, pvRef, dwEffType, type, xfd);
1162 dei.dwSize = sizeof(DIEFFECTINFOW);
1164 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1165 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1166 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1167 (*lpCallback)(&dei, pvRef);
1170 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1171 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1172 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1173 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1174 (*lpCallback)(&dei, pvRef);
1176 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1177 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1178 (*lpCallback)(&dei, pvRef);
1180 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1181 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1182 (*lpCallback)(&dei, pvRef);
1184 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1185 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1186 (*lpCallback)(&dei, pvRef);
1188 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1189 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1190 (*lpCallback)(&dei, pvRef);
1194 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1195 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1196 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1197 (*lpCallback)(&dei, pvRef);
1200 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1201 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1202 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1203 (*lpCallback)(&dei, pvRef);
1205 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1206 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1207 (*lpCallback)(&dei, pvRef);
1209 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1210 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1211 (*lpCallback)(&dei, pvRef);
1213 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1214 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1215 (*lpCallback)(&dei, pvRef);
1219 /* return to unacquired state if that's where it was */
1221 IDirectInputDevice8_Unacquire(iface);
1227 /*******************************************************************************
1228 * GetEffectInfo - Get information about a particular effect
1230 static HRESULT WINAPI JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface,
1231 LPDIEFFECTINFOA pdei,
1234 JoystickImpl* This = (JoystickImpl*)iface;
1236 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1238 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1239 return linuxinput_get_info_A(This->joyfd, guid, pdei);
1245 static HRESULT WINAPI JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface,
1246 LPDIEFFECTINFOW pdei,
1249 JoystickImpl* This = (JoystickImpl*)iface;
1251 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1253 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1254 return linuxinput_get_info_W(This->joyfd, guid, pdei);
1260 /*******************************************************************************
1261 * GetForceFeedbackState - Get information about the device's FF state
1263 static HRESULT WINAPI JoystickAImpl_GetForceFeedbackState(
1264 LPDIRECTINPUTDEVICE8A iface,
1267 JoystickImpl* This = (JoystickImpl*)iface;
1269 TRACE("(this=%p,%p)\n", This, pdwOut);
1273 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1274 /* DIGFFS_STOPPED is the only mandatory flag to report */
1275 if (This->ff_state == FF_STATUS_STOPPED)
1276 (*pdwOut) |= DIGFFS_STOPPED;
1282 /*******************************************************************************
1283 * SendForceFeedbackCommand - Send a command to the device's FF system
1285 static HRESULT WINAPI JoystickAImpl_SendForceFeedbackCommand(
1286 LPDIRECTINPUTDEVICE8A iface,
1289 JoystickImpl* This = (JoystickImpl*)iface;
1290 TRACE("(this=%p,%d)\n", This, dwFlags);
1292 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1293 if (dwFlags == DISFFC_STOPALL) {
1294 /* Stop all effects */
1295 EffectListItem* itr = This->top_effect;
1297 IDirectInputEffect_Stop(itr->ref);
1300 } else if (dwFlags == DISFFC_RESET) {
1301 /* Stop, unload, release and free all effects */
1302 /* This returns the device to its "bare" state */
1303 while (This->top_effect) {
1304 EffectListItem* temp = This->top_effect;
1305 IDirectInputEffect_Stop(temp->ref);
1306 IDirectInputEffect_Unload(temp->ref);
1307 IDirectInputEffect_Release(temp->ref);
1308 This->top_effect = temp->next;
1309 HeapFree(GetProcessHeap(), 0, temp);
1311 } else if (dwFlags == DISFFC_PAUSE || dwFlags == DISFFC_CONTINUE) {
1312 FIXME("No support for Pause or Continue in linux\n");
1313 } else if (dwFlags == DISFFC_SETACTUATORSOFF
1314 || dwFlags == DISFFC_SETACTUATORSON) {
1315 FIXME("No direct actuator control in linux\n");
1317 FIXME("Unknown Force Feedback Command!\n");
1318 return DIERR_INVALIDPARAM;
1322 return DIERR_UNSUPPORTED;
1326 /*******************************************************************************
1327 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1328 * created for this device.
1330 static HRESULT WINAPI JoystickAImpl_EnumCreatedEffectObjects(
1331 LPDIRECTINPUTDEVICE8A iface,
1332 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1336 /* this function is safe to call on non-ff-enabled builds */
1338 JoystickImpl* This = (JoystickImpl*)iface;
1339 EffectListItem* itr = This->top_effect;
1340 TRACE("(this=%p,%p,%p,%d)\n", This, lpCallback, pvRef, dwFlags);
1343 return DIERR_INVALIDPARAM;
1346 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1349 (*lpCallback)(itr->ref, pvRef);
1356 /******************************************************************************
1357 * GetDeviceInfo : get information about a device's identity
1359 static HRESULT WINAPI JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface,
1360 LPDIDEVICEINSTANCEA pdidi)
1362 JoystickImpl *This = (JoystickImpl *)iface;
1364 TRACE("(%p) %p\n", This, pdidi);
1366 if (pdidi == NULL) return E_POINTER;
1367 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
1368 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)))
1369 return DIERR_INVALIDPARAM;
1371 fill_joystick_dideviceinstanceA(pdidi, This->base.dinput->dwVersion,
1372 get_joystick_index(&This->base.guid));
1376 static HRESULT WINAPI JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface,
1377 LPDIDEVICEINSTANCEW pdidi)
1379 JoystickImpl *This = (JoystickImpl *)iface;
1381 TRACE("(%p) %p\n", This, pdidi);
1383 if (pdidi == NULL) return E_POINTER;
1384 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3W)) &&
1385 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)))
1386 return DIERR_INVALIDPARAM;
1388 fill_joystick_dideviceinstanceW(pdidi, This->base.dinput->dwVersion,
1389 get_joystick_index(&This->base.guid));
1393 static const IDirectInputDevice8AVtbl JoystickAvt =
1395 IDirectInputDevice2AImpl_QueryInterface,
1396 IDirectInputDevice2AImpl_AddRef,
1397 IDirectInputDevice2AImpl_Release,
1398 JoystickAImpl_GetCapabilities,
1399 IDirectInputDevice2AImpl_EnumObjects,
1400 JoystickAImpl_GetProperty,
1401 JoystickAImpl_SetProperty,
1402 JoystickAImpl_Acquire,
1403 JoystickAImpl_Unacquire,
1404 JoystickAImpl_GetDeviceState,
1405 IDirectInputDevice2AImpl_GetDeviceData,
1406 IDirectInputDevice2AImpl_SetDataFormat,
1407 IDirectInputDevice2AImpl_SetEventNotification,
1408 IDirectInputDevice2AImpl_SetCooperativeLevel,
1409 JoystickAImpl_GetObjectInfo,
1410 JoystickAImpl_GetDeviceInfo,
1411 IDirectInputDevice2AImpl_RunControlPanel,
1412 IDirectInputDevice2AImpl_Initialize,
1413 JoystickAImpl_CreateEffect,
1414 JoystickAImpl_EnumEffects,
1415 JoystickAImpl_GetEffectInfo,
1416 JoystickAImpl_GetForceFeedbackState,
1417 JoystickAImpl_SendForceFeedbackCommand,
1418 JoystickAImpl_EnumCreatedEffectObjects,
1419 IDirectInputDevice2AImpl_Escape,
1421 IDirectInputDevice2AImpl_SendDeviceData,
1422 IDirectInputDevice7AImpl_EnumEffectsInFile,
1423 IDirectInputDevice7AImpl_WriteEffectToFile,
1424 IDirectInputDevice8AImpl_BuildActionMap,
1425 IDirectInputDevice8AImpl_SetActionMap,
1426 IDirectInputDevice8AImpl_GetImageInfo
1429 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1430 # define XCAST(fun) (typeof(JoystickWvt.fun))
1432 # define XCAST(fun) (void*)
1435 static const IDirectInputDevice8WVtbl JoystickWvt =
1437 IDirectInputDevice2WImpl_QueryInterface,
1438 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1439 XCAST(Release)IDirectInputDevice2AImpl_Release,
1440 XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1441 IDirectInputDevice2WImpl_EnumObjects,
1442 XCAST(GetProperty)JoystickAImpl_GetProperty,
1443 XCAST(SetProperty)JoystickAImpl_SetProperty,
1444 XCAST(Acquire)JoystickAImpl_Acquire,
1445 XCAST(Unacquire)JoystickAImpl_Unacquire,
1446 XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1447 XCAST(GetDeviceData)IDirectInputDevice2AImpl_GetDeviceData,
1448 XCAST(SetDataFormat)IDirectInputDevice2AImpl_SetDataFormat,
1449 XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
1450 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1451 JoystickWImpl_GetObjectInfo,
1452 JoystickWImpl_GetDeviceInfo,
1453 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1454 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1455 XCAST(CreateEffect)JoystickAImpl_CreateEffect,
1456 JoystickWImpl_EnumEffects,
1457 JoystickWImpl_GetEffectInfo,
1458 XCAST(GetForceFeedbackState)JoystickAImpl_GetForceFeedbackState,
1459 XCAST(SendForceFeedbackCommand)JoystickAImpl_SendForceFeedbackCommand,
1460 XCAST(EnumCreatedEffectObjects)JoystickAImpl_EnumCreatedEffectObjects,
1461 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1462 XCAST(Poll)JoystickAImpl_Poll,
1463 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1464 IDirectInputDevice7WImpl_EnumEffectsInFile,
1465 IDirectInputDevice7WImpl_WriteEffectToFile,
1466 IDirectInputDevice8WImpl_BuildActionMap,
1467 IDirectInputDevice8WImpl_SetActionMap,
1468 IDirectInputDevice8WImpl_GetImageInfo
1472 #else /* HAVE_CORRECT_LINUXINPUT_H */
1474 const struct dinput_device joystick_linuxinput_device = {
1475 "Wine Linux-input joystick driver",
1482 #endif /* HAVE_CORRECT_LINUXINPUT_H */