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 * Dead zone is in % multiplied by a 100 (range 0..10000)
94 LONG joystick_map_axis(ObjProps *props, int val)
97 LONG dead_zone = MulDiv( props->lDeadZone, props->lDevMax - props->lDevMin, 10000 );
98 LONG dev_range = props->lDevMax - props->lDevMin - dead_zone;
101 val -= (props->lDevMin + props->lDevMax) / 2;
103 /* Remove dead zone */
104 if (abs( val ) <= dead_zone / 2)
107 val = val < 0 ? val + dead_zone / 2 : val - dead_zone / 2;
109 /* Scale and map the value from the device range into the required range */
110 ret = MulDiv( val, props->lMax - props->lMin, dev_range ) +
111 (props->lMin + props->lMax) / 2;
113 TRACE( "(%d <%d> %d) -> (%d <%d> %d): val=%d ret=%d\n",
114 props->lDevMin, dead_zone, props->lDevMax,
115 props->lMin, props->lDeadZone, props->lMax,
121 #ifdef HAVE_CORRECT_LINUXINPUT_H
123 #define EVDEVPREFIX "/dev/input/event"
125 /* Wine joystick driver object instances */
126 #define WINE_JOYSTICK_MAX_AXES 8
127 #define WINE_JOYSTICK_MAX_POVS 4
128 #define WINE_JOYSTICK_MAX_BUTTONS 128
130 struct wine_input_absinfo {
138 typedef struct EffectListItem EffectListItem;
139 struct EffectListItem
141 LPDIRECTINPUTEFFECT ref;
142 struct EffectListItem* next;
145 /* implemented in effect_linuxinput.c */
146 HRESULT linuxinput_create_effect(int* fd, REFGUID rguid, LPDIRECTINPUTEFFECT* peff);
147 HRESULT linuxinput_get_info_A(int fd, REFGUID rguid, LPDIEFFECTINFOA info);
148 HRESULT linuxinput_get_info_W(int fd, REFGUID rguid, LPDIEFFECTINFOW info);
150 typedef struct JoystickImpl JoystickImpl;
151 static const IDirectInputDevice8AVtbl JoystickAvt;
152 static const IDirectInputDevice8WVtbl JoystickWvt;
162 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
163 BYTE evbits[(EV_MAX+7)/8];
164 BYTE absbits[(ABS_MAX+7)/8];
165 BYTE keybits[(KEY_MAX+7)/8];
166 BYTE ffbits[(FF_MAX+7)/8];
168 /* data returned by the EVIOCGABS() ioctl */
169 struct wine_input_absinfo axes[ABS_MAX];
174 struct IDirectInputDevice2AImpl base;
176 struct JoyDev *joydev;
178 /* joystick private */
183 ObjProps props[ABS_MAX];
188 /* LUT for KEY_ to offset in rgbButtons */
189 BYTE buttons[KEY_MAX];
195 /* Force feedback variables */
196 EffectListItem* top_effect;
200 static void fake_current_js_state(JoystickImpl *ji);
201 static void find_joydevs(void);
203 /* This GUID is slightly different from the linux joystick one. Take note. */
204 static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
208 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
211 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
213 #define MAX_JOYDEV 64
215 static int have_joydevs = -1;
216 static struct JoyDev *joydevs = NULL;
218 static void find_joydevs(void)
222 if (have_joydevs!=-1) {
228 for (i=0;i<MAX_JOYDEV;i++) {
230 struct JoyDev joydev = {0};
235 snprintf(buf,MAX_PATH,EVDEVPREFIX"%d",i);
238 if ((fd=open(buf, O_RDWR))==-1) {
239 fd = open(buf, O_RDONLY);
245 if ((-1==ioctl(fd,EVIOCGBIT(0,sizeof(joydev.evbits)),joydev.evbits))) {
246 perror("EVIOCGBIT 0");
250 if (-1==ioctl(fd,EVIOCGBIT(EV_ABS,sizeof(joydev.absbits)),joydev.absbits)) {
251 perror("EVIOCGBIT EV_ABS");
255 if (-1==ioctl(fd,EVIOCGBIT(EV_KEY,sizeof(joydev.keybits)),joydev.keybits)) {
256 perror("EVIOCGBIT EV_KEY");
260 /* A true joystick has at least axis X and Y, and at least 1
261 * button. copied from linux/drivers/input/joydev.c */
262 if (test_bit(joydev.absbits,ABS_X) && test_bit(joydev.absbits,ABS_Y) &&
263 ( test_bit(joydev.keybits,BTN_TRIGGER) ||
264 test_bit(joydev.keybits,BTN_A) ||
265 test_bit(joydev.keybits,BTN_1)
269 joydev.device = strdup(buf);
271 if (-1!=ioctl(fd, EVIOCGNAME(MAX_PATH-1), buf)) {
273 joydev.name = strdup(buf);
275 joydev.name = joydev.device;
278 joydev.guid = DInput_Wine_Joystick_Base_GUID;
279 joydev.guid.Data3 += have_joydevs;
281 TRACE("Found a joystick on %s: %s (%s)\n",
282 joydev.device, joydev.name,
283 debugstr_guid(&joydev.guid)
286 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
288 test_bit(joydev.evbits, EV_FF) &&
289 ioctl(fd, EVIOCGBIT(EV_FF, sizeof(joydev.ffbits)), joydev.ffbits) != -1 &&
290 ioctl(fd, EVIOCGEFFECTS, &joydev.num_effects) != -1 &&
291 joydev.num_effects > 0)
293 TRACE(" ... with force feedback\n");
298 for (j=0;j<ABS_MAX;j++) {
299 if (test_bit(joydev.absbits,j)) {
300 if (-1!=ioctl(fd,EVIOCGABS(j),&(joydev.axes[j]))) {
301 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
303 joydev.axes[j].value,
304 joydev.axes[j].minimum,
305 joydev.axes[j].maximum,
313 if (have_joydevs==0) {
314 joydevs = HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev));
316 HeapReAlloc(GetProcessHeap(), 0, joydevs, (1+have_joydevs) * sizeof(struct JoyDev));
318 memcpy(joydevs+have_joydevs, &joydev, sizeof(struct JoyDev));
327 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
329 DWORD dwSize = lpddi->dwSize;
331 TRACE("%d %p\n", dwSize, lpddi);
332 memset(lpddi, 0, dwSize);
334 lpddi->dwSize = dwSize;
335 lpddi->guidInstance = joydevs[id].guid;
336 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
337 lpddi->guidFFDriver = GUID_NULL;
339 if (version >= 0x0800)
340 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
342 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
344 strcpy(lpddi->tszInstanceName, joydevs[id].name);
345 strcpy(lpddi->tszProductName, joydevs[id].device);
348 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
350 DWORD dwSize = lpddi->dwSize;
352 TRACE("%d %p\n", dwSize, lpddi);
353 memset(lpddi, 0, dwSize);
355 lpddi->dwSize = dwSize;
356 lpddi->guidInstance = joydevs[id].guid;
357 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
358 lpddi->guidFFDriver = GUID_NULL;
360 if (version >= 0x0800)
361 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
363 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
365 MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
366 MultiByteToWideChar(CP_ACP, 0, joydevs[id].device, -1, lpddi->tszProductName, MAX_PATH);
369 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
373 if (id >= have_joydevs) {
377 if (!((dwDevType == 0) ||
378 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
379 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
382 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
383 if (dwFlags & DIEDFL_FORCEFEEDBACK)
387 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
388 fill_joystick_dideviceinstanceA(lpddi, version, id);
394 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
398 if (id >= have_joydevs) {
402 if (!((dwDevType == 0) ||
403 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
404 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
407 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
408 if (dwFlags & DIEDFL_FORCEFEEDBACK)
412 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
413 fill_joystick_dideviceinstanceW(lpddi, version, id);
419 static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, unsigned short index)
421 JoystickImpl* newDevice;
422 LPDIDATAFORMAT df = NULL;
424 char buffer[MAX_PATH+16];
426 LONG def_deadzone = -1;
428 newDevice = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(JoystickImpl));
429 if (!newDevice) return NULL;
431 newDevice->base.lpVtbl = jvt;
432 newDevice->base.ref = 1;
433 newDevice->base.guid = *rguid;
434 newDevice->base.dinput = dinput;
435 newDevice->joyfd = -1;
436 newDevice->joydev = &joydevs[index];
437 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
438 newDevice->ff_state = FF_STATUS_STOPPED;
440 InitializeCriticalSection(&newDevice->base.crit);
441 newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->base.crit");
444 get_app_key(&hkey, &appkey);
446 if (!get_config_key(hkey, appkey, "DefaultDeadZone", buffer, MAX_PATH))
448 def_deadzone = atoi(buffer);
449 TRACE("setting default deadzone to: %d\n", def_deadzone);
451 if (appkey) RegCloseKey(appkey);
452 if (hkey) RegCloseKey(hkey);
454 /* Create copy of default data format */
455 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto failed;
456 memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
457 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
459 /* Supported Axis & POVs should map 1-to-1 */
460 for (i = 0; i < WINE_JOYSTICK_MAX_AXES; i++)
462 if (!test_bit(newDevice->joydev->absbits, i)) {
463 newDevice->axes[i] = -1;
467 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i], df->dwObjSize);
468 newDevice->axes[i] = idx;
469 newDevice->props[idx].lDevMin = newDevice->joydev->axes[i].minimum;
470 newDevice->props[idx].lDevMax = newDevice->joydev->axes[i].maximum;
471 newDevice->props[idx].lMin = 0;
472 newDevice->props[idx].lMax = 0xffff;
473 newDevice->props[idx].lSaturation = 0;
474 newDevice->props[idx].lDeadZone = def_deadzone >= 0 ? def_deadzone :
475 MulDiv(newDevice->joydev->axes[i].flat, 0xffff,
476 newDevice->props[idx].lDevMax - newDevice->props[idx].lDevMin);
478 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->numAxes++) | DIDFT_ABSAXIS;
481 for (i = 0; i < WINE_JOYSTICK_MAX_POVS; i++)
483 if (!test_bit(newDevice->joydev->absbits, ABS_HAT0X + i * 2) ||
484 !test_bit(newDevice->joydev->absbits, ABS_HAT0Y + i * 2)) {
485 newDevice->axes[ABS_HAT0X + i * 2] = newDevice->axes[ABS_HAT0Y + i * 2] = -1;
489 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + WINE_JOYSTICK_MAX_AXES], df->dwObjSize);
490 newDevice->axes[ABS_HAT0X + i * 2] = newDevice->axes[ABS_HAT0Y + i * 2] = i;
491 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->numPOVs++) | DIDFT_POV;
494 /* Buttons can be anywhere, so check all */
495 for (i = 0; i < KEY_MAX && newDevice->numButtons < WINE_JOYSTICK_MAX_BUTTONS; i++)
497 if (!test_bit(newDevice->joydev->keybits, i)) continue;
499 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[newDevice->numButtons + WINE_JOYSTICK_MAX_AXES + WINE_JOYSTICK_MAX_POVS], df->dwObjSize);
500 newDevice->buttons[i] = 0x80 | newDevice->numButtons;
501 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->numButtons++) | DIDFT_PSHBUTTON;
505 fake_current_js_state(newDevice);
507 newDevice->base.data_format.wine_df = df;
508 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->base.dinput);
512 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
513 HeapFree(GetProcessHeap(), 0, df);
514 HeapFree(GetProcessHeap(), 0, newDevice);
518 /******************************************************************************
519 * get_joystick_index : Get the joystick index from a given GUID
521 static unsigned short get_joystick_index(REFGUID guid)
523 GUID wine_joystick = DInput_Wine_Joystick_Base_GUID;
524 GUID dev_guid = *guid;
526 wine_joystick.Data3 = 0;
529 /* for the standard joystick GUID use index 0 */
530 if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
532 /* for the wine joystick GUIDs use the index stored in Data3 */
533 if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3 - DInput_Wine_Joystick_Base_GUID.Data3;
538 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
540 unsigned short index;
544 if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
545 have_joydevs && index < have_joydevs)
547 if ((riid == NULL) ||
548 IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
549 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
550 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
551 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
553 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, index);
554 TRACE("Created a Joystick device (%p)\n", *pdev);
558 ERR("out of memory\n");
559 return DIERR_OUTOFMEMORY;
564 WARN("no interface\n");
565 return DIERR_NOINTERFACE;
568 return DIERR_DEVICENOTREG;
572 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
574 unsigned short index;
578 if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
579 have_joydevs && index < have_joydevs)
581 if ((riid == NULL) ||
582 IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
583 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
584 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
585 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
587 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, index);
588 TRACE("Created a Joystick device (%p)\n", *pdev);
592 ERR("out of memory\n");
593 return DIERR_OUTOFMEMORY;
597 WARN("no interface\n");
598 return DIERR_NOINTERFACE;
601 WARN("invalid device GUID\n");
602 return DIERR_DEVICENOTREG;
605 const struct dinput_device joystick_linuxinput_device = {
606 "Wine Linux-input joystick driver",
609 joydev_create_deviceA,
610 joydev_create_deviceW
613 /******************************************************************************
614 * Acquire : gets exclusive control of the joystick
616 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
618 JoystickImpl *This = (JoystickImpl *)iface;
621 TRACE("(this=%p)\n",This);
623 res = IDirectInputDevice2AImpl_Acquire(iface);
625 if (-1==(This->joyfd=open(This->joydev->device,O_RDWR))) {
626 if (-1==(This->joyfd=open(This->joydev->device,O_RDONLY))) {
627 /* Couldn't open the device at all */
628 perror(This->joydev->device);
629 IDirectInputDevice2AImpl_Unacquire(iface);
630 return DIERR_NOTFOUND;
632 /* Couldn't open in r/w but opened in read-only. */
633 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This->joydev->device);
641 /******************************************************************************
642 * Unacquire : frees the joystick
644 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
646 JoystickImpl *This = (JoystickImpl *)iface;
649 TRACE("(this=%p)\n",This);
650 res = IDirectInputDevice2AImpl_Unacquire(iface);
651 if (res==DI_OK && This->joyfd!=-1) {
659 * set the current state of the js device as it would be with the middle
662 #define CENTER_AXIS(a) \
663 (ji->axes[a] == -1 ? 0 : joystick_map_axis( &ji->props[ji->axes[a]], \
664 ji->joydev->axes[a].value ))
665 static void fake_current_js_state(JoystickImpl *ji)
669 /* center the axes */
670 ji->js.lX = CENTER_AXIS(ABS_X);
671 ji->js.lY = CENTER_AXIS(ABS_Y);
672 ji->js.lZ = CENTER_AXIS(ABS_Z);
673 ji->js.lRx = CENTER_AXIS(ABS_RX);
674 ji->js.lRy = CENTER_AXIS(ABS_RY);
675 ji->js.lRz = CENTER_AXIS(ABS_RZ);
676 ji->js.rglSlider[0] = CENTER_AXIS(ABS_THROTTLE);
677 ji->js.rglSlider[1] = CENTER_AXIS(ABS_RUDDER);
679 /* POV center is -1 */
680 for (i = 0; i < 4; i++)
681 ji->js.rgdwPOV[i] = -1;
685 /* convert wine format offset to user format object index */
686 static void joy_polldev(JoystickImpl *This)
689 struct input_event ie;
699 plfd.fd = This->joyfd;
700 plfd.events = POLLIN;
702 if (poll(&plfd,1,0) != 1)
705 /* we have one event, so we can read */
706 if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
709 TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
711 case EV_KEY: /* button */
713 int btn = This->buttons[ie.code];
715 TRACE("(%p) %d -> %d\n", This, ie.code, btn);
719 inst_id = DIDFT_MAKEINSTANCE(btn) | DIDFT_PSHBUTTON;
720 This->js.rgbButtons[btn] = value = ie.value ? 0x80 : 0x00;
726 int axis = This->axes[ie.code];
730 inst_id = DIDFT_MAKEINSTANCE(axis) | (ie.code < ABS_HAT0X ? DIDFT_ABSAXIS : DIDFT_POV);
731 value = joystick_map_axis(&This->props[id_to_object(This->base.data_format.wine_df, inst_id)], ie.value);
734 case ABS_X: This->js.lX = value; break;
735 case ABS_Y: This->js.lY = value; break;
736 case ABS_Z: This->js.lZ = value; break;
737 case ABS_RX: This->js.lRx = value; break;
738 case ABS_RY: This->js.lRy = value; break;
739 case ABS_RZ: This->js.lRz = value; break;
740 case ABS_THROTTLE: This->js.rglSlider[0] = value; break;
741 case ABS_RUDDER: This->js.rglSlider[1] = value; break;
742 case ABS_HAT0X: case ABS_HAT0Y: case ABS_HAT1X: case ABS_HAT1Y:
743 case ABS_HAT2X: case ABS_HAT2Y: case ABS_HAT3X: case ABS_HAT3Y:
745 int idx = (ie.code - ABS_HAT0X) / 2;
748 This->povs[idx].y = ie.value;
750 This->povs[idx].x = ie.value;
752 This->js.rgdwPOV[idx] = value = joystick_map_pov(&This->povs[idx]);
756 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie.code,ie.value);
760 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
762 This->ff_state = ie.value;
767 /* there is nothing to do */
771 FIXME("joystick cannot handle type %d event (code %d)\n",ie.type,ie.code);
775 queue_event((LPDIRECTINPUTDEVICE8A)This,
776 id_to_offset(&This->base.data_format, inst_id),
777 value, ie.time.tv_usec, This->base.dinput->evsequence++);
781 /******************************************************************************
782 * GetDeviceState : returns the "state" of the joystick.
785 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
786 LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
788 JoystickImpl *This = (JoystickImpl *)iface;
790 TRACE("(this=%p,0x%08x,%p)\n", This, len, ptr);
792 if (!This->base.acquired)
794 WARN("not acquired\n");
795 return DIERR_NOTACQUIRED;
800 /* convert and copy data to user supplied buffer */
801 fill_DataFormat(ptr, &This->js, &This->base.data_format);
806 /******************************************************************************
807 * SetProperty : change input device properties
809 static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
813 JoystickImpl *This = (JoystickImpl *)iface;
816 WARN("invalid argument\n");
817 return DIERR_INVALIDPARAM;
820 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
821 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
822 ph->dwSize, ph->dwHeaderSize, ph->dwObj, ph->dwHow);
824 if (!HIWORD(rguid)) {
825 switch (LOWORD(rguid)) {
826 case (DWORD)DIPROP_RANGE: {
827 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
829 if (ph->dwHow == DIPH_DEVICE) {
831 TRACE("proprange(%d,%d) all\n", pr->lMin, pr->lMax);
832 for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++) {
833 /* Scale dead-zone */
834 This->props[i].lDeadZone = MulDiv(This->props[i].lDeadZone, pr->lMax - pr->lMin,
835 This->props[i].lMax - This->props[i].lMin);
836 This->props[i].lMin = pr->lMin;
837 This->props[i].lMax = pr->lMax;
840 int obj = find_property(&This->base.data_format, ph);
842 TRACE("proprange(%d,%d) obj=%d\n", pr->lMin, pr->lMax, obj);
844 /* Scale dead-zone */
845 This->props[obj].lDeadZone = MulDiv(This->props[obj].lDeadZone, pr->lMax - pr->lMin,
846 This->props[obj].lMax - This->props[obj].lMin);
847 This->props[obj].lMin = pr->lMin;
848 This->props[obj].lMax = pr->lMax;
851 fake_current_js_state(This);
854 case (DWORD)DIPROP_DEADZONE: {
855 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
856 if (ph->dwHow == DIPH_DEVICE) {
858 TRACE("deadzone(%d) all\n", pd->dwData);
859 for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++) {
860 This->props[i].lDeadZone = pd->dwData;
863 int obj = find_property(&This->base.data_format, ph);
865 TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
867 This->props[obj].lDeadZone = pd->dwData;
870 fake_current_js_state(This);
873 case (DWORD)DIPROP_CALIBRATIONMODE: {
874 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
875 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd->dwData);
878 case (DWORD)DIPROP_AUTOCENTER: {
879 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
881 FIXME("DIPROP_AUTOCENTER(%d)\n", pd->dwData);
885 return IDirectInputDevice2AImpl_SetProperty(iface, rguid, ph);
891 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
892 LPDIRECTINPUTDEVICE8A iface,
893 LPDIDEVCAPS lpDIDevCaps)
895 JoystickImpl *This = (JoystickImpl *)iface;
897 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
900 WARN("invalid pointer\n");
904 if (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) {
905 WARN("invalid argument\n");
906 return DIERR_INVALIDPARAM;
909 lpDIDevCaps->dwFlags = DIDC_ATTACHED;
910 if (This->base.dinput->dwVersion >= 0x0800)
911 lpDIDevCaps->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
913 lpDIDevCaps->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
915 if (This->joydev->has_ff)
916 lpDIDevCaps->dwFlags |= DIDC_FORCEFEEDBACK;
918 lpDIDevCaps->dwAxes = This->numAxes;
919 lpDIDevCaps->dwButtons = This->numButtons;
920 lpDIDevCaps->dwPOVs = This->numPOVs;
925 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface)
927 JoystickImpl *This = (JoystickImpl *)iface;
929 TRACE("(%p)\n",This);
931 if (!This->base.acquired)
932 return DIERR_NOTACQUIRED;
938 /******************************************************************************
939 * GetProperty : get input device properties
941 static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
943 LPDIPROPHEADER pdiph)
945 JoystickImpl *This = (JoystickImpl *)iface;
947 TRACE("(this=%p,%s,%p)\n", iface, debugstr_guid(rguid), pdiph);
948 _dump_DIPROPHEADER(pdiph);
950 if (HIWORD(rguid)) return DI_OK;
952 switch (LOWORD(rguid)) {
953 case (DWORD) DIPROP_RANGE:
955 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
956 int obj = find_property(&This->base.data_format, pdiph);
958 if (obj < 0) return DIERR_OBJECTNOTFOUND;
960 pr->lMin = This->props[obj].lMin;
961 pr->lMax = This->props[obj].lMax;
962 TRACE("range(%d, %d) obj=%d\n", pr->lMin, pr->lMax, obj);
965 case (DWORD) DIPROP_DEADZONE:
967 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
968 int obj = find_property(&This->base.data_format, pdiph);
970 if (obj < 0) return DIERR_OBJECTNOTFOUND;
972 pd->dwData = This->props[obj].lDeadZone;
973 TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
978 return IDirectInputDevice2AImpl_GetProperty(iface, rguid, pdiph);
984 /******************************************************************************
985 * GetObjectInfo : get information about a device object such as a button
988 static HRESULT WINAPI JoystickWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
989 LPDIDEVICEOBJECTINSTANCEW pdidoi, DWORD dwObj, DWORD dwHow)
991 static const WCHAR axisW[] = {'A','x','i','s',' ','%','d',0};
992 static const WCHAR povW[] = {'P','O','V',' ','%','d',0};
993 static const WCHAR buttonW[] = {'B','u','t','t','o','n',' ','%','d',0};
996 res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
997 if (res != DI_OK) return res;
999 if (pdidoi->dwType & DIDFT_AXIS)
1000 sprintfW(pdidoi->tszName, axisW, DIDFT_GETINSTANCE(pdidoi->dwType));
1001 else if (pdidoi->dwType & DIDFT_POV)
1002 sprintfW(pdidoi->tszName, povW, DIDFT_GETINSTANCE(pdidoi->dwType));
1003 else if (pdidoi->dwType & DIDFT_BUTTON)
1004 sprintfW(pdidoi->tszName, buttonW, DIDFT_GETINSTANCE(pdidoi->dwType));
1006 _dump_OBJECTINSTANCEW(pdidoi);
1010 static HRESULT WINAPI JoystickAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface,
1011 LPDIDEVICEOBJECTINSTANCEA pdidoi, DWORD dwObj, DWORD dwHow)
1014 DIDEVICEOBJECTINSTANCEW didoiW;
1015 DWORD dwSize = pdidoi->dwSize;
1017 didoiW.dwSize = sizeof(didoiW);
1018 res = JoystickWImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W)iface, &didoiW, dwObj, dwHow);
1019 if (res != DI_OK) return res;
1021 memset(pdidoi, 0, pdidoi->dwSize);
1022 memcpy(pdidoi, &didoiW, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, tszName));
1023 pdidoi->dwSize = dwSize;
1024 WideCharToMultiByte(CP_ACP, 0, didoiW.tszName, -1, pdidoi->tszName,
1025 sizeof(pdidoi->tszName), NULL, NULL);
1030 /******************************************************************************
1031 * CreateEffect - Create a new FF effect with the specified params
1033 static HRESULT WINAPI JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface,
1036 LPDIRECTINPUTEFFECT *ppdef,
1037 LPUNKNOWN pUnkOuter)
1039 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1040 EffectListItem* new = NULL;
1041 HRESULT retval = DI_OK;
1044 JoystickImpl* This = (JoystickImpl*)iface;
1045 TRACE("(this=%p,%p,%p,%p,%p)\n", This, rguid, lpeff, ppdef, pUnkOuter);
1047 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1048 TRACE("not available (compiled w/o ff support)\n");
1053 new = HeapAlloc(GetProcessHeap(), 0, sizeof(EffectListItem));
1054 new->next = This->top_effect;
1055 This->top_effect = new;
1057 retval = linuxinput_create_effect(&(This->joyfd), rguid, &(new->ref));
1058 if (retval != DI_OK)
1062 retval = IDirectInputEffect_SetParameters(new->ref, lpeff, 0);
1063 if (retval != DI_OK && retval != DI_DOWNLOADSKIPPED)
1068 if (pUnkOuter != NULL)
1069 FIXME("Interface aggregation not implemented.\n");
1073 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1076 /*******************************************************************************
1077 * EnumEffects - Enumerate available FF effects
1079 static HRESULT WINAPI JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface,
1080 LPDIENUMEFFECTSCALLBACKA lpCallback,
1084 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1085 DIEFFECTINFOA dei; /* feif */
1086 DWORD type = DIEFT_GETTYPE(dwEffType);
1087 JoystickImpl* This = (JoystickImpl*)iface;
1089 TRACE("(this=%p,%p,%d) type=%d\n", This, pvRef, dwEffType, type);
1091 dei.dwSize = sizeof(DIEFFECTINFOA);
1093 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1094 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1095 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1096 (*lpCallback)(&dei, pvRef);
1099 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1100 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1101 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1102 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1103 (*lpCallback)(&dei, pvRef);
1105 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1106 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1107 (*lpCallback)(&dei, pvRef);
1109 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1110 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1111 (*lpCallback)(&dei, pvRef);
1113 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1114 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1115 (*lpCallback)(&dei, pvRef);
1117 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1118 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1119 (*lpCallback)(&dei, pvRef);
1123 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1124 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1125 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1126 (*lpCallback)(&dei, pvRef);
1129 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1130 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1131 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1132 (*lpCallback)(&dei, pvRef);
1134 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1135 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1136 (*lpCallback)(&dei, pvRef);
1138 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1139 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1140 (*lpCallback)(&dei, pvRef);
1142 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1143 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1144 (*lpCallback)(&dei, pvRef);
1153 static HRESULT WINAPI JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface,
1154 LPDIENUMEFFECTSCALLBACKW lpCallback,
1158 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1159 /* seems silly to duplicate all this code but all the structures and functions
1160 * are actually different (A/W) */
1161 DIEFFECTINFOW dei; /* feif */
1162 DWORD type = DIEFT_GETTYPE(dwEffType);
1163 JoystickImpl* This = (JoystickImpl*)iface;
1164 int xfd = This->joyfd;
1166 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This, pvRef, dwEffType, type, xfd);
1168 dei.dwSize = sizeof(DIEFFECTINFOW);
1170 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1171 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1172 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1173 (*lpCallback)(&dei, pvRef);
1176 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1177 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1178 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1179 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1180 (*lpCallback)(&dei, pvRef);
1182 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1183 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1184 (*lpCallback)(&dei, pvRef);
1186 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1187 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1188 (*lpCallback)(&dei, pvRef);
1190 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1191 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1192 (*lpCallback)(&dei, pvRef);
1194 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1195 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1196 (*lpCallback)(&dei, pvRef);
1200 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1201 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1202 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1203 (*lpCallback)(&dei, pvRef);
1206 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1207 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1208 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1209 (*lpCallback)(&dei, pvRef);
1211 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1212 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1213 (*lpCallback)(&dei, pvRef);
1215 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1216 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1217 (*lpCallback)(&dei, pvRef);
1219 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1220 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1221 (*lpCallback)(&dei, pvRef);
1225 /* return to unacquired state if that's where it was */
1227 IDirectInputDevice8_Unacquire(iface);
1233 /*******************************************************************************
1234 * GetEffectInfo - Get information about a particular effect
1236 static HRESULT WINAPI JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface,
1237 LPDIEFFECTINFOA pdei,
1240 JoystickImpl* This = (JoystickImpl*)iface;
1242 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1244 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1245 return linuxinput_get_info_A(This->joyfd, guid, pdei);
1251 static HRESULT WINAPI JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface,
1252 LPDIEFFECTINFOW pdei,
1255 JoystickImpl* This = (JoystickImpl*)iface;
1257 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1259 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1260 return linuxinput_get_info_W(This->joyfd, guid, pdei);
1266 /*******************************************************************************
1267 * GetForceFeedbackState - Get information about the device's FF state
1269 static HRESULT WINAPI JoystickAImpl_GetForceFeedbackState(
1270 LPDIRECTINPUTDEVICE8A iface,
1273 JoystickImpl* This = (JoystickImpl*)iface;
1275 TRACE("(this=%p,%p)\n", This, pdwOut);
1279 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1280 /* DIGFFS_STOPPED is the only mandatory flag to report */
1281 if (This->ff_state == FF_STATUS_STOPPED)
1282 (*pdwOut) |= DIGFFS_STOPPED;
1288 /*******************************************************************************
1289 * SendForceFeedbackCommand - Send a command to the device's FF system
1291 static HRESULT WINAPI JoystickAImpl_SendForceFeedbackCommand(
1292 LPDIRECTINPUTDEVICE8A iface,
1295 JoystickImpl* This = (JoystickImpl*)iface;
1296 TRACE("(this=%p,%d)\n", This, dwFlags);
1298 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1299 if (dwFlags == DISFFC_STOPALL) {
1300 /* Stop all effects */
1301 EffectListItem* itr = This->top_effect;
1303 IDirectInputEffect_Stop(itr->ref);
1306 } else if (dwFlags == DISFFC_RESET) {
1307 /* Stop, unload, release and free all effects */
1308 /* This returns the device to its "bare" state */
1309 while (This->top_effect) {
1310 EffectListItem* temp = This->top_effect;
1311 IDirectInputEffect_Stop(temp->ref);
1312 IDirectInputEffect_Unload(temp->ref);
1313 IDirectInputEffect_Release(temp->ref);
1314 This->top_effect = temp->next;
1315 HeapFree(GetProcessHeap(), 0, temp);
1317 } else if (dwFlags == DISFFC_PAUSE || dwFlags == DISFFC_CONTINUE) {
1318 FIXME("No support for Pause or Continue in linux\n");
1319 } else if (dwFlags == DISFFC_SETACTUATORSOFF
1320 || dwFlags == DISFFC_SETACTUATORSON) {
1321 FIXME("No direct actuator control in linux\n");
1323 FIXME("Unknown Force Feedback Command!\n");
1324 return DIERR_INVALIDPARAM;
1328 return DIERR_UNSUPPORTED;
1332 /*******************************************************************************
1333 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1334 * created for this device.
1336 static HRESULT WINAPI JoystickAImpl_EnumCreatedEffectObjects(
1337 LPDIRECTINPUTDEVICE8A iface,
1338 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1342 /* this function is safe to call on non-ff-enabled builds */
1344 JoystickImpl* This = (JoystickImpl*)iface;
1345 EffectListItem* itr = This->top_effect;
1346 TRACE("(this=%p,%p,%p,%d)\n", This, lpCallback, pvRef, dwFlags);
1349 return DIERR_INVALIDPARAM;
1352 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1355 (*lpCallback)(itr->ref, pvRef);
1362 /******************************************************************************
1363 * GetDeviceInfo : get information about a device's identity
1365 static HRESULT WINAPI JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface,
1366 LPDIDEVICEINSTANCEA pdidi)
1368 JoystickImpl *This = (JoystickImpl *)iface;
1370 TRACE("(%p) %p\n", This, pdidi);
1372 if (pdidi == NULL) return E_POINTER;
1373 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
1374 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)))
1375 return DIERR_INVALIDPARAM;
1377 fill_joystick_dideviceinstanceA(pdidi, This->base.dinput->dwVersion,
1378 get_joystick_index(&This->base.guid));
1382 static HRESULT WINAPI JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface,
1383 LPDIDEVICEINSTANCEW pdidi)
1385 JoystickImpl *This = (JoystickImpl *)iface;
1387 TRACE("(%p) %p\n", This, pdidi);
1389 if (pdidi == NULL) return E_POINTER;
1390 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3W)) &&
1391 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)))
1392 return DIERR_INVALIDPARAM;
1394 fill_joystick_dideviceinstanceW(pdidi, This->base.dinput->dwVersion,
1395 get_joystick_index(&This->base.guid));
1399 static const IDirectInputDevice8AVtbl JoystickAvt =
1401 IDirectInputDevice2AImpl_QueryInterface,
1402 IDirectInputDevice2AImpl_AddRef,
1403 IDirectInputDevice2AImpl_Release,
1404 JoystickAImpl_GetCapabilities,
1405 IDirectInputDevice2AImpl_EnumObjects,
1406 JoystickAImpl_GetProperty,
1407 JoystickAImpl_SetProperty,
1408 JoystickAImpl_Acquire,
1409 JoystickAImpl_Unacquire,
1410 JoystickAImpl_GetDeviceState,
1411 IDirectInputDevice2AImpl_GetDeviceData,
1412 IDirectInputDevice2AImpl_SetDataFormat,
1413 IDirectInputDevice2AImpl_SetEventNotification,
1414 IDirectInputDevice2AImpl_SetCooperativeLevel,
1415 JoystickAImpl_GetObjectInfo,
1416 JoystickAImpl_GetDeviceInfo,
1417 IDirectInputDevice2AImpl_RunControlPanel,
1418 IDirectInputDevice2AImpl_Initialize,
1419 JoystickAImpl_CreateEffect,
1420 JoystickAImpl_EnumEffects,
1421 JoystickAImpl_GetEffectInfo,
1422 JoystickAImpl_GetForceFeedbackState,
1423 JoystickAImpl_SendForceFeedbackCommand,
1424 JoystickAImpl_EnumCreatedEffectObjects,
1425 IDirectInputDevice2AImpl_Escape,
1427 IDirectInputDevice2AImpl_SendDeviceData,
1428 IDirectInputDevice7AImpl_EnumEffectsInFile,
1429 IDirectInputDevice7AImpl_WriteEffectToFile,
1430 IDirectInputDevice8AImpl_BuildActionMap,
1431 IDirectInputDevice8AImpl_SetActionMap,
1432 IDirectInputDevice8AImpl_GetImageInfo
1435 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1436 # define XCAST(fun) (typeof(JoystickWvt.fun))
1438 # define XCAST(fun) (void*)
1441 static const IDirectInputDevice8WVtbl JoystickWvt =
1443 IDirectInputDevice2WImpl_QueryInterface,
1444 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1445 XCAST(Release)IDirectInputDevice2AImpl_Release,
1446 XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1447 IDirectInputDevice2WImpl_EnumObjects,
1448 XCAST(GetProperty)JoystickAImpl_GetProperty,
1449 XCAST(SetProperty)JoystickAImpl_SetProperty,
1450 XCAST(Acquire)JoystickAImpl_Acquire,
1451 XCAST(Unacquire)JoystickAImpl_Unacquire,
1452 XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1453 XCAST(GetDeviceData)IDirectInputDevice2AImpl_GetDeviceData,
1454 XCAST(SetDataFormat)IDirectInputDevice2AImpl_SetDataFormat,
1455 XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
1456 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1457 JoystickWImpl_GetObjectInfo,
1458 JoystickWImpl_GetDeviceInfo,
1459 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1460 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1461 XCAST(CreateEffect)JoystickAImpl_CreateEffect,
1462 JoystickWImpl_EnumEffects,
1463 JoystickWImpl_GetEffectInfo,
1464 XCAST(GetForceFeedbackState)JoystickAImpl_GetForceFeedbackState,
1465 XCAST(SendForceFeedbackCommand)JoystickAImpl_SendForceFeedbackCommand,
1466 XCAST(EnumCreatedEffectObjects)JoystickAImpl_EnumCreatedEffectObjects,
1467 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1468 XCAST(Poll)JoystickAImpl_Poll,
1469 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1470 IDirectInputDevice7WImpl_EnumEffectsInFile,
1471 IDirectInputDevice7WImpl_WriteEffectToFile,
1472 IDirectInputDevice8WImpl_BuildActionMap,
1473 IDirectInputDevice8WImpl_SetActionMap,
1474 IDirectInputDevice8WImpl_GetImageInfo
1478 #else /* HAVE_CORRECT_LINUXINPUT_H */
1480 const struct dinput_device joystick_linuxinput_device = {
1481 "Wine Linux-input joystick driver",
1488 #endif /* HAVE_CORRECT_LINUXINPUT_H */