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>
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"
58 #include "wine/list.h"
65 #include "dinput_private.h"
66 #include "device_private.h"
67 #include "joystick_private.h"
69 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
71 #ifdef HAVE_CORRECT_LINUXINPUT_H
73 #define EVDEVPREFIX "/dev/input/event"
75 /* Wine joystick driver object instances */
76 #define WINE_JOYSTICK_MAX_AXES 8
77 #define WINE_JOYSTICK_MAX_POVS 4
78 #define WINE_JOYSTICK_MAX_BUTTONS 128
80 struct wine_input_absinfo {
88 /* implemented in effect_linuxinput.c */
89 HRESULT linuxinput_create_effect(int* fd, REFGUID rguid, struct list *parent_list_entry, LPDIRECTINPUTEFFECT* peff);
90 HRESULT linuxinput_get_info_A(int fd, REFGUID rguid, LPDIEFFECTINFOA info);
91 HRESULT linuxinput_get_info_W(int fd, REFGUID rguid, LPDIEFFECTINFOW info);
93 typedef struct JoystickImpl JoystickImpl;
94 static const IDirectInputDevice8AVtbl JoystickAvt;
95 static const IDirectInputDevice8WVtbl JoystickWvt;
105 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
106 BYTE evbits[(EV_MAX+7)/8];
107 BYTE absbits[(ABS_MAX+7)/8];
108 BYTE keybits[(KEY_MAX+7)/8];
109 BYTE ffbits[(FF_MAX+7)/8];
111 /* data returned by the EVIOCGABS() ioctl */
112 struct wine_input_absinfo axes[ABS_MAX];
117 struct JoystickGenericImpl generic;
118 struct JoyDev *joydev;
120 /* joystick private */
123 int dev_axes_to_di[ABS_MAX];
126 /* LUT for KEY_ to offset in rgbButtons */
127 BYTE buttons[KEY_MAX];
129 /* Force feedback variables */
130 struct list ff_effects;
136 static inline JoystickImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface)
138 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface),
139 JoystickGenericImpl, base), JoystickImpl, generic);
141 static inline JoystickImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface)
143 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface),
144 JoystickGenericImpl, base), JoystickImpl, generic);
146 static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl(JoystickImpl *This)
148 return &This->generic.base.IDirectInputDevice8A_iface;
150 static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(JoystickImpl *This)
152 return &This->generic.base.IDirectInputDevice8W_iface;
155 static void fake_current_js_state(JoystickImpl *ji);
156 static void find_joydevs(void);
157 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface);
159 /* This GUID is slightly different from the linux joystick one. Take note. */
160 static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
164 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
167 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
169 #define MAX_JOYDEV 64
171 static int have_joydevs = -1;
172 static struct JoyDev *joydevs = NULL;
174 static void find_joydevs(void)
178 if (InterlockedCompareExchange(&have_joydevs, 0, -1) != -1)
179 /* Someone beat us to it */
182 for (i = 0; i < MAX_JOYDEV; i++)
185 struct JoyDev joydev = {0};
189 struct JoyDev *new_joydevs;
191 snprintf(buf, sizeof(buf), EVDEVPREFIX"%d", i);
193 if ((fd = open(buf, O_RDWR)) == -1)
195 fd = open(buf, O_RDONLY);
201 WARN("Failed to open \"%s\": %d %s\n", buf, errno, strerror(errno));
205 if (ioctl(fd, EVIOCGBIT(0, sizeof(joydev.evbits)), joydev.evbits) == -1)
207 WARN("ioct(EVIOCGBIT, 0) failed: %d %s\n", errno, strerror(errno));
211 if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(joydev.absbits)), joydev.absbits) == -1)
213 WARN("ioct(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno, strerror(errno));
217 if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(joydev.keybits)), joydev.keybits) == -1)
219 WARN("ioct(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno, strerror(errno));
224 /* A true joystick has at least axis X and Y, and at least 1
225 * button. copied from linux/drivers/input/joydev.c */
226 if (!test_bit(joydev.absbits, ABS_X) || !test_bit(joydev.absbits, ABS_Y) ||
227 !(test_bit(joydev.keybits, BTN_TRIGGER) ||
228 test_bit(joydev.keybits, BTN_A) ||
229 test_bit(joydev.keybits, BTN_1)))
235 if (!(joydev.device = HeapAlloc(GetProcessHeap(), 0, strlen(buf) + 1)))
240 strcpy(joydev.device, buf);
242 buf[MAX_PATH - 1] = 0;
243 if (ioctl(fd, EVIOCGNAME(MAX_PATH - 1), buf) != -1 &&
244 (joydev.name = HeapAlloc(GetProcessHeap(), 0, strlen(buf) + 1)))
245 strcpy(joydev.name, buf);
247 joydev.name = joydev.device;
249 joydev.guid = DInput_Wine_Joystick_Base_GUID;
250 joydev.guid.Data3 += have_joydevs;
252 TRACE("Found a joystick on %s: %s (%s)\n",
253 joydev.device, joydev.name,
254 debugstr_guid(&joydev.guid)
257 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
259 test_bit(joydev.evbits, EV_FF) &&
260 ioctl(fd, EVIOCGBIT(EV_FF, sizeof(joydev.ffbits)), joydev.ffbits) != -1 &&
261 ioctl(fd, EVIOCGEFFECTS, &joydev.num_effects) != -1 &&
262 joydev.num_effects > 0)
264 TRACE(" ... with force feedback\n");
269 for (j = 0; j < ABS_MAX;j ++)
271 if (!test_bit(joydev.absbits, j)) continue;
272 if (ioctl(fd, EVIOCGABS(j), &(joydev.axes[j])) != -1)
274 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
276 joydev.axes[j].value,
277 joydev.axes[j].minimum,
278 joydev.axes[j].maximum,
286 new_joydevs = HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev));
288 new_joydevs = HeapReAlloc(GetProcessHeap(), 0, joydevs, (1 + have_joydevs) * sizeof(struct JoyDev));
295 joydevs = new_joydevs;
296 memcpy(joydevs + have_joydevs, &joydev, sizeof(joydev));
303 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
305 DWORD dwSize = lpddi->dwSize;
307 TRACE("%d %p\n", dwSize, lpddi);
308 memset(lpddi, 0, dwSize);
310 lpddi->dwSize = dwSize;
311 lpddi->guidInstance = joydevs[id].guid;
312 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
313 lpddi->guidFFDriver = GUID_NULL;
315 if (version >= 0x0800)
316 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
318 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
320 strcpy(lpddi->tszInstanceName, joydevs[id].name);
321 strcpy(lpddi->tszProductName, joydevs[id].name);
324 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
326 DWORD dwSize = lpddi->dwSize;
328 TRACE("%d %p\n", dwSize, lpddi);
329 memset(lpddi, 0, dwSize);
331 lpddi->dwSize = dwSize;
332 lpddi->guidInstance = joydevs[id].guid;
333 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
334 lpddi->guidFFDriver = GUID_NULL;
336 if (version >= 0x0800)
337 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
339 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
341 MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
342 MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszProductName, MAX_PATH);
345 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
349 if (id >= have_joydevs) {
353 if (!((dwDevType == 0) ||
354 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
355 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
358 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
359 if (dwFlags & DIEDFL_FORCEFEEDBACK)
363 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
364 fill_joystick_dideviceinstanceA(lpddi, version, id);
370 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
374 if (id >= have_joydevs) {
378 if (!((dwDevType == 0) ||
379 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
380 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
383 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
384 if (dwFlags & DIEDFL_FORCEFEEDBACK)
388 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
389 fill_joystick_dideviceinstanceW(lpddi, version, id);
395 static JoystickImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput, unsigned short index)
397 JoystickImpl* newDevice;
398 LPDIDATAFORMAT df = NULL;
400 int default_axis_map[WINE_JOYSTICK_MAX_AXES + WINE_JOYSTICK_MAX_POVS*2];
402 newDevice = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(JoystickImpl));
403 if (!newDevice) return NULL;
405 newDevice->generic.base.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt;
406 newDevice->generic.base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt;
407 newDevice->generic.base.ref = 1;
408 newDevice->generic.base.guid = *rguid;
409 newDevice->generic.base.dinput = dinput;
410 newDevice->generic.joy_polldev = joy_polldev;
411 newDevice->joyfd = -1;
412 newDevice->joydev = &joydevs[index];
413 newDevice->generic.name = newDevice->joydev->name;
414 list_init(&newDevice->ff_effects);
415 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
416 newDevice->ff_state = FF_STATUS_STOPPED;
418 /* There is no way in linux to query force feedback autocenter status.
419 Instead, track it with ff_autocenter, and assume it's initialy
421 newDevice->ff_autocenter = 1;
422 newDevice->ff_gain = 0xFFFF;
423 InitializeCriticalSection(&newDevice->generic.base.crit);
424 newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->base.crit");
426 /* Count number of available axes - supported Axis & POVs */
427 for (i = 0; i < WINE_JOYSTICK_MAX_AXES; i++)
429 if (test_bit(newDevice->joydev->absbits, i))
431 newDevice->generic.device_axis_count++;
432 newDevice->dev_axes_to_di[i] = idx;
433 newDevice->generic.props[idx].lDevMin = newDevice->joydev->axes[i].minimum;
434 newDevice->generic.props[idx].lDevMax = newDevice->joydev->axes[i].maximum;
435 default_axis_map[idx] = i;
439 newDevice->dev_axes_to_di[i] = -1;
442 for (i = 0; i < WINE_JOYSTICK_MAX_POVS; i++)
444 if (test_bit(newDevice->joydev->absbits, ABS_HAT0X + i * 2) &&
445 test_bit(newDevice->joydev->absbits, ABS_HAT0Y + i * 2))
447 newDevice->generic.device_axis_count += 2;
448 newDevice->generic.props[idx ].lDevMin = newDevice->joydev->axes[ABS_HAT0X + i * 2].minimum;
449 newDevice->generic.props[idx ].lDevMax = newDevice->joydev->axes[ABS_HAT0X + i * 2].maximum;
450 newDevice->dev_axes_to_di[ABS_HAT0X + i * 2] = idx;
451 newDevice->generic.props[idx+1].lDevMin = newDevice->joydev->axes[ABS_HAT0Y + i * 2].minimum;
452 newDevice->generic.props[idx+1].lDevMax = newDevice->joydev->axes[ABS_HAT0Y + i * 2].maximum;
453 newDevice->dev_axes_to_di[ABS_HAT0Y + i * 2] = idx + 1;
455 default_axis_map[idx] = default_axis_map[idx + 1] = WINE_JOYSTICK_MAX_AXES + i;
459 newDevice->dev_axes_to_di[ABS_HAT0X + i * 2] = newDevice->dev_axes_to_di[ABS_HAT0Y + i * 2] = -1;
462 /* do any user specified configuration */
463 if (setup_dinput_options(&newDevice->generic, default_axis_map) != DI_OK) goto failed;
465 /* Create copy of default data format */
466 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto failed;
467 memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
468 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
471 /* Construct internal data format */
473 /* Supported Axis & POVs */
474 for (i = 0, idx = 0; i < newDevice->generic.device_axis_count; i++)
476 int wine_obj = newDevice->generic.axis_map[i];
478 if (wine_obj < 0) continue;
480 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize);
482 df->rgodf[idx].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS;
485 df->rgodf[idx].dwType = DIDFT_MAKEINSTANCE(wine_obj - 8) | DIDFT_POV;
486 i++; /* POV takes 2 axes */
489 newDevice->generic.props[idx].lMin = 0;
490 newDevice->generic.props[idx].lMax = 0xffff;
491 newDevice->generic.props[idx].lSaturation = 0;
492 newDevice->generic.props[idx].lDeadZone = newDevice->generic.deadzone;
494 /* Linux supports force-feedback on X & Y axes only */
495 if (newDevice->joydev->has_ff && (i == 0 || i == 1))
496 df->rgodf[idx].dwFlags |= DIDOI_FFACTUATOR;
501 /* Buttons can be anywhere, so check all */
502 for (i = 0; i < KEY_MAX && newDevice->generic.devcaps.dwButtons < WINE_JOYSTICK_MAX_BUTTONS; i++)
504 if (!test_bit(newDevice->joydev->keybits, i)) continue;
506 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[newDevice->generic.devcaps.dwButtons + 12], df->dwObjSize);
507 newDevice->buttons[i] = 0x80 | newDevice->generic.devcaps.dwButtons;
508 df->rgodf[idx ].pguid = &GUID_Button;
509 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->generic.devcaps.dwButtons++) | DIDFT_PSHBUTTON;
512 newDevice->generic.base.data_format.wine_df = df;
514 fake_current_js_state(newDevice);
517 newDevice->generic.devcaps.dwSize = sizeof(newDevice->generic.devcaps);
518 newDevice->generic.devcaps.dwFlags = DIDC_ATTACHED;
519 if (newDevice->generic.base.dinput->dwVersion >= 0x0800)
520 newDevice->generic.devcaps.dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
522 newDevice->generic.devcaps.dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
524 if (newDevice->joydev->has_ff)
525 newDevice->generic.devcaps.dwFlags |= DIDC_FORCEFEEDBACK;
527 IDirectInput_AddRef(&newDevice->generic.base.dinput->IDirectInput7A_iface);
531 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
532 HeapFree(GetProcessHeap(), 0, df);
533 HeapFree(GetProcessHeap(), 0, newDevice->generic.axis_map);
534 HeapFree(GetProcessHeap(), 0, newDevice);
538 /******************************************************************************
539 * get_joystick_index : Get the joystick index from a given GUID
541 static unsigned short get_joystick_index(REFGUID guid)
543 GUID wine_joystick = DInput_Wine_Joystick_Base_GUID;
544 GUID dev_guid = *guid;
546 wine_joystick.Data3 = 0;
549 /* for the standard joystick GUID use index 0 */
550 if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
552 /* for the wine joystick GUIDs use the index stored in Data3 */
553 if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3 - DInput_Wine_Joystick_Base_GUID.Data3;
558 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
560 unsigned short index;
564 if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
565 have_joydevs && index < have_joydevs)
567 if ((riid == NULL) ||
568 IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
569 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
570 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
571 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
573 JoystickImpl *This = alloc_device(rguid, dinput, index);
574 TRACE("Created a Joystick device (%p)\n", This);
578 ERR("out of memory\n");
580 return DIERR_OUTOFMEMORY;
582 *pdev = (IDirectInputDeviceA*) &This->generic.base.IDirectInputDevice8A_iface;
586 WARN("no interface\n");
587 return DIERR_NOINTERFACE;
590 return DIERR_DEVICENOTREG;
594 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
596 unsigned short index;
600 if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
601 have_joydevs && index < have_joydevs)
603 if ((riid == NULL) ||
604 IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
605 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
606 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
607 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
609 JoystickImpl *This = alloc_device(rguid, dinput, index);
610 TRACE("Created a Joystick device (%p)\n", This);
614 ERR("out of memory\n");
615 return DIERR_OUTOFMEMORY;
617 *pdev = (IDirectInputDeviceW*) &This->generic.base.IDirectInputDevice8W_iface;
620 WARN("no interface\n");
621 return DIERR_NOINTERFACE;
624 WARN("invalid device GUID\n");
625 return DIERR_DEVICENOTREG;
628 const struct dinput_device joystick_linuxinput_device = {
629 "Wine Linux-input joystick driver",
632 joydev_create_deviceA,
633 joydev_create_deviceW
636 /******************************************************************************
637 * Acquire : gets exclusive control of the joystick
639 static HRESULT WINAPI JoystickWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
641 JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
644 TRACE("(this=%p)\n",This);
646 if ((res = IDirectInputDevice2WImpl_Acquire(iface)) != DI_OK)
648 WARN("Failed to acquire: %x\n", res);
652 if ((This->joyfd = open(This->joydev->device, O_RDWR)) == -1)
654 if ((This->joyfd = open(This->joydev->device, O_RDONLY)) == -1)
656 /* Couldn't open the device at all */
657 ERR("Failed to open device %s: %d %s\n", This->joydev->device, errno, strerror(errno));
658 IDirectInputDevice2WImpl_Unacquire(iface);
659 return DIERR_NOTFOUND;
663 /* Couldn't open in r/w but opened in read-only. */
664 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This->joydev->device);
669 struct input_event event;
672 event.code = FF_GAIN;
673 event.value = This->ff_gain;
674 if (write(This->joyfd, &event, sizeof(event)) == -1)
675 ERR("Failed to set gain (%i): %d %s\n", This->ff_gain, errno, strerror(errno));
676 if (!This->ff_autocenter)
678 /* Disable autocenter. */
679 event.code = FF_AUTOCENTER;
681 if (write(This->joyfd, &event, sizeof(event)) == -1)
682 ERR("Failed disabling autocenter: %d %s\n", errno, strerror(errno));
689 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
691 JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
692 return JoystickWImpl_Acquire(IDirectInputDevice8W_from_impl(This));
695 /******************************************************************************
696 * Unacquire : frees the joystick
698 static HRESULT WINAPI JoystickWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface)
700 JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
703 TRACE("(this=%p)\n",This);
704 res = IDirectInputDevice2WImpl_Unacquire(iface);
705 if (res==DI_OK && This->joyfd!=-1) {
706 effect_list_item *itr;
707 struct input_event event;
709 /* For each known effect:
712 * But, unlike DISFFC_RESET, do not release the effect.
714 LIST_FOR_EACH_ENTRY(itr, &This->ff_effects, effect_list_item, entry) {
715 IDirectInputEffect_Stop(itr->ref);
716 IDirectInputEffect_Unload(itr->ref);
719 /* Enable autocenter. */
721 event.code = FF_AUTOCENTER;
722 /* TODO: Read autocenter strengh before disabling it, and use it here
723 * instead of 0xFFFF (maximum strengh).
725 event.value = 0xFFFF;
726 if (write(This->joyfd, &event, sizeof(event)) == -1)
727 ERR("Failed to set autocenter to %04x: %d %s\n", event.value, errno, strerror(errno));
735 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
737 JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
738 return JoystickWImpl_Unacquire(IDirectInputDevice8W_from_impl(This));
742 * set the current state of the js device as it would be with the middle
745 #define CENTER_AXIS(a) \
746 (ji->dev_axes_to_di[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->dev_axes_to_di[a]], \
747 ji->joydev->axes[a].value ))
748 static void fake_current_js_state(JoystickImpl *ji)
752 /* center the axes */
753 ji->generic.js.lX = CENTER_AXIS(ABS_X);
754 ji->generic.js.lY = CENTER_AXIS(ABS_Y);
755 ji->generic.js.lZ = CENTER_AXIS(ABS_Z);
756 ji->generic.js.lRx = CENTER_AXIS(ABS_RX);
757 ji->generic.js.lRy = CENTER_AXIS(ABS_RY);
758 ji->generic.js.lRz = CENTER_AXIS(ABS_RZ);
759 ji->generic.js.rglSlider[0] = CENTER_AXIS(ABS_THROTTLE);
760 ji->generic.js.rglSlider[1] = CENTER_AXIS(ABS_RUDDER);
762 /* POV center is -1 */
763 for (i = 0; i < 4; i++)
764 ji->generic.js.rgdwPOV[i] = -1;
768 /* convert wine format offset to user format object index */
769 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface)
772 struct input_event ie;
773 JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
783 plfd.fd = This->joyfd;
784 plfd.events = POLLIN;
786 if (poll(&plfd,1,0) != 1)
789 /* we have one event, so we can read */
790 if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
793 TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
795 case EV_KEY: /* button */
797 int btn = This->buttons[ie.code];
799 TRACE("(%p) %d -> %d\n", This, ie.code, btn);
803 inst_id = DIDFT_MAKEINSTANCE(btn) | DIDFT_PSHBUTTON;
804 This->generic.js.rgbButtons[btn] = value = ie.value ? 0x80 : 0x00;
810 int axis = This->dev_axes_to_di[ie.code];
812 /* User axis remapping */
814 axis = This->generic.axis_map[axis];
817 inst_id = axis < 8 ? DIDFT_MAKEINSTANCE(axis) | DIDFT_ABSAXIS :
818 DIDFT_MAKEINSTANCE(axis - 8) | DIDFT_POV;
819 value = joystick_map_axis(&This->generic.props[id_to_object(This->generic.base.data_format.wine_df, inst_id)], ie.value);
822 case 0: This->generic.js.lX = value; break;
823 case 1: This->generic.js.lY = value; break;
824 case 2: This->generic.js.lZ = value; break;
825 case 3: This->generic.js.lRx = value; break;
826 case 4: This->generic.js.lRy = value; break;
827 case 5: This->generic.js.lRz = value; break;
828 case 6: This->generic.js.rglSlider[0] = value; break;
829 case 7: This->generic.js.rglSlider[1] = value; break;
830 case 8: case 9: case 10: case 11:
835 This->povs[idx].y = ie.value;
837 This->povs[idx].x = ie.value;
839 This->generic.js.rgdwPOV[idx] = value = joystick_map_pov(&This->povs[idx]);
843 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie.code,ie.value);
847 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
849 This->ff_state = ie.value;
854 /* there is nothing to do */
858 FIXME("joystick cannot handle type %d event (code %d)\n",ie.type,ie.code);
862 queue_event(iface, inst_id,
863 value, ie.time.tv_usec, This->generic.base.dinput->evsequence++);
867 /******************************************************************************
868 * SetProperty : change input device properties
870 static HRESULT WINAPI JoystickWImpl_SetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPCDIPROPHEADER ph)
872 JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
875 WARN("invalid argument\n");
876 return DIERR_INVALIDPARAM;
879 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
880 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
881 ph->dwSize, ph->dwHeaderSize, ph->dwObj, ph->dwHow);
883 if (IS_DIPROP(rguid)) {
884 switch (LOWORD(rguid)) {
885 case (DWORD_PTR)DIPROP_CALIBRATIONMODE: {
886 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
887 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd->dwData);
890 case (DWORD_PTR)DIPROP_AUTOCENTER: {
891 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
893 TRACE("autocenter(%d)\n", pd->dwData);
894 This->ff_autocenter = pd->dwData == DIPROPAUTOCENTER_ON;
898 case (DWORD_PTR)DIPROP_FFGAIN: {
899 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
901 TRACE("DIPROP_FFGAIN(%d)\n", pd->dwData);
902 This->ff_gain = MulDiv(pd->dwData, 0xFFFF, 10000);
903 if (This->generic.base.acquired) {
904 /* Update immediately. */
905 struct input_event event;
908 event.code = FF_GAIN;
909 event.value = This->ff_gain;
910 if (write(This->joyfd, &event, sizeof(event)) == -1)
911 ERR("Failed to set gain (%i): %d %s\n", This->ff_gain, errno, strerror(errno));
916 return JoystickWGenericImpl_SetProperty(iface, rguid, ph);
922 static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER ph)
924 JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
925 return JoystickWImpl_SetProperty(IDirectInputDevice8W_from_impl(This), rguid, ph);
928 /******************************************************************************
929 * GetProperty : get input device properties
931 static HRESULT WINAPI JoystickWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPDIPROPHEADER pdiph)
933 JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
935 TRACE("(this=%p,%s,%p)\n", iface, debugstr_guid(rguid), pdiph);
936 _dump_DIPROPHEADER(pdiph);
938 if (!IS_DIPROP(rguid)) return DI_OK;
940 switch (LOWORD(rguid)) {
941 case (DWORD_PTR) DIPROP_AUTOCENTER:
943 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
945 pd->dwData = This->ff_autocenter ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF;
946 TRACE("autocenter(%d)\n", pd->dwData);
949 case (DWORD_PTR) DIPROP_FFGAIN:
951 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
953 pd->dwData = MulDiv(This->ff_gain, 10000, 0xFFFF);
954 TRACE("DIPROP_FFGAIN(%d)\n", pd->dwData);
959 return JoystickWGenericImpl_GetProperty(iface, rguid, pdiph);
965 static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
967 JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
968 return JoystickWImpl_GetProperty(IDirectInputDevice8W_from_impl(This), rguid, pdiph);
971 /******************************************************************************
972 * CreateEffect - Create a new FF effect with the specified params
974 static HRESULT WINAPI JoystickWImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid,
975 LPCDIEFFECT lpeff, LPDIRECTINPUTEFFECT *ppdef,
978 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
979 effect_list_item* new_effect = NULL;
980 HRESULT retval = DI_OK;
983 JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
984 TRACE("(this=%p,%p,%p,%p,%p)\n", This, rguid, lpeff, ppdef, pUnkOuter);
986 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
987 TRACE("not available (compiled w/o ff support)\n");
992 if (!(new_effect = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect))))
993 return DIERR_OUTOFMEMORY;
995 retval = linuxinput_create_effect(&This->joyfd, rguid, &new_effect->entry, &new_effect->ref);
998 HeapFree(GetProcessHeap(), 0, new_effect);
1004 retval = IDirectInputEffect_SetParameters(new_effect->ref, lpeff, 0);
1006 if (retval != DI_OK && retval != DI_DOWNLOADSKIPPED)
1008 HeapFree(GetProcessHeap(), 0, new_effect);
1013 list_add_tail(&This->ff_effects, &new_effect->entry);
1014 *ppdef = new_effect->ref;
1016 if (pUnkOuter != NULL)
1017 FIXME("Interface aggregation not implemented.\n");
1021 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1024 static HRESULT WINAPI JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface, REFGUID rguid,
1025 LPCDIEFFECT lpeff, LPDIRECTINPUTEFFECT *ppdef,
1026 LPUNKNOWN pUnkOuter)
1028 JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
1029 return JoystickWImpl_CreateEffect(IDirectInputDevice8W_from_impl(This), rguid, lpeff, ppdef, pUnkOuter);
1032 /*******************************************************************************
1033 * EnumEffects - Enumerate available FF effects
1035 static HRESULT WINAPI JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface,
1036 LPDIENUMEFFECTSCALLBACKA lpCallback,
1040 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1041 DIEFFECTINFOA dei; /* feif */
1042 DWORD type = DIEFT_GETTYPE(dwEffType);
1043 JoystickImpl* This = impl_from_IDirectInputDevice8A(iface);
1045 TRACE("(this=%p,%p,%d) type=%d\n", This, pvRef, dwEffType, type);
1047 dei.dwSize = sizeof(DIEFFECTINFOA);
1049 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1050 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1051 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1052 (*lpCallback)(&dei, pvRef);
1055 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1056 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1057 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1058 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1059 (*lpCallback)(&dei, pvRef);
1061 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1062 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1063 (*lpCallback)(&dei, pvRef);
1065 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1066 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1067 (*lpCallback)(&dei, pvRef);
1069 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1070 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1071 (*lpCallback)(&dei, pvRef);
1073 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1074 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1075 (*lpCallback)(&dei, pvRef);
1079 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1080 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1081 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1082 (*lpCallback)(&dei, pvRef);
1085 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1086 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1087 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1088 (*lpCallback)(&dei, pvRef);
1090 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1091 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1092 (*lpCallback)(&dei, pvRef);
1094 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1095 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1096 (*lpCallback)(&dei, pvRef);
1098 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1099 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1100 (*lpCallback)(&dei, pvRef);
1109 static HRESULT WINAPI JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface,
1110 LPDIENUMEFFECTSCALLBACKW lpCallback,
1114 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1115 /* seems silly to duplicate all this code but all the structures and functions
1116 * are actually different (A/W) */
1117 DIEFFECTINFOW dei; /* feif */
1118 DWORD type = DIEFT_GETTYPE(dwEffType);
1119 JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
1120 int xfd = This->joyfd;
1122 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This, pvRef, dwEffType, type, xfd);
1124 dei.dwSize = sizeof(DIEFFECTINFOW);
1126 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1127 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1128 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1129 (*lpCallback)(&dei, pvRef);
1132 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1133 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1134 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1135 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1136 (*lpCallback)(&dei, pvRef);
1138 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1139 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1140 (*lpCallback)(&dei, pvRef);
1142 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1143 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1144 (*lpCallback)(&dei, pvRef);
1146 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1147 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1148 (*lpCallback)(&dei, pvRef);
1150 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1151 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1152 (*lpCallback)(&dei, pvRef);
1156 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1157 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1158 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1159 (*lpCallback)(&dei, pvRef);
1162 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1163 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1164 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1165 (*lpCallback)(&dei, pvRef);
1167 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1168 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1169 (*lpCallback)(&dei, pvRef);
1171 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1172 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1173 (*lpCallback)(&dei, pvRef);
1175 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1176 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1177 (*lpCallback)(&dei, pvRef);
1181 /* return to unacquired state if that's where it was */
1183 IDirectInputDevice8_Unacquire(iface);
1189 /*******************************************************************************
1190 * GetEffectInfo - Get information about a particular effect
1192 static HRESULT WINAPI JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface,
1193 LPDIEFFECTINFOA pdei,
1196 JoystickImpl* This = impl_from_IDirectInputDevice8A(iface);
1198 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1200 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1201 return linuxinput_get_info_A(This->joyfd, guid, pdei);
1207 static HRESULT WINAPI JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface,
1208 LPDIEFFECTINFOW pdei,
1211 JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
1213 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1215 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1216 return linuxinput_get_info_W(This->joyfd, guid, pdei);
1222 /*******************************************************************************
1223 * GetForceFeedbackState - Get information about the device's FF state
1225 static HRESULT WINAPI JoystickWImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface, LPDWORD pdwOut)
1227 JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
1229 TRACE("(this=%p,%p)\n", This, pdwOut);
1233 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1234 /* DIGFFS_STOPPED is the only mandatory flag to report */
1235 if (This->ff_state == FF_STATUS_STOPPED)
1236 (*pdwOut) |= DIGFFS_STOPPED;
1242 static HRESULT WINAPI JoystickAImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8A iface, LPDWORD pdwOut)
1244 JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
1245 return JoystickWImpl_GetForceFeedbackState(IDirectInputDevice8W_from_impl(This), pdwOut);
1248 /*******************************************************************************
1249 * SendForceFeedbackCommand - Send a command to the device's FF system
1251 static HRESULT WINAPI JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface, DWORD dwFlags)
1253 JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
1254 TRACE("(this=%p,%d)\n", This, dwFlags);
1256 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1259 case DISFFC_STOPALL:
1261 /* Stop all effects */
1262 effect_list_item *itr;
1264 LIST_FOR_EACH_ENTRY(itr, &This->ff_effects, effect_list_item, entry)
1265 IDirectInputEffect_Stop(itr->ref);
1271 effect_list_item *itr, *ptr;
1273 /* Stop, unload, release and free all effects */
1274 /* This returns the device to its "bare" state */
1275 LIST_FOR_EACH_ENTRY_SAFE(itr, ptr, &This->ff_effects, effect_list_item, entry)
1276 IDirectInputEffect_Release(itr->ref);
1280 case DISFFC_CONTINUE:
1281 FIXME("No support for Pause or Continue in linux\n");
1284 case DISFFC_SETACTUATORSOFF:
1285 case DISFFC_SETACTUATORSON:
1286 FIXME("No direct actuator control in linux\n");
1290 FIXME("Unknown Force Feedback Command!\n");
1291 return DIERR_INVALIDPARAM;
1295 return DIERR_UNSUPPORTED;
1299 static HRESULT WINAPI JoystickAImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8A iface, DWORD dwFlags)
1301 JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
1302 return JoystickWImpl_SendForceFeedbackCommand(IDirectInputDevice8W_from_impl(This), dwFlags);
1305 /*******************************************************************************
1306 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1307 * created for this device.
1309 static HRESULT WINAPI JoystickWImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface,
1310 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1311 LPVOID pvRef, DWORD dwFlags)
1313 /* this function is safe to call on non-ff-enabled builds */
1314 JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
1315 effect_list_item *itr, *ptr;
1317 TRACE("(this=%p,%p,%p,%d)\n", This, lpCallback, pvRef, dwFlags);
1320 return DIERR_INVALIDPARAM;
1323 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1325 LIST_FOR_EACH_ENTRY_SAFE(itr, ptr, &This->ff_effects, effect_list_item, entry)
1326 (*lpCallback)(itr->ref, pvRef);
1331 static HRESULT WINAPI JoystickAImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8A iface,
1332 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1333 LPVOID pvRef, DWORD dwFlags)
1335 JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
1336 return JoystickWImpl_EnumCreatedEffectObjects(IDirectInputDevice8W_from_impl(This), lpCallback, pvRef, dwFlags);
1339 /******************************************************************************
1340 * GetDeviceInfo : get information about a device's identity
1342 static HRESULT WINAPI JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface,
1343 LPDIDEVICEINSTANCEA pdidi)
1345 JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
1347 TRACE("(%p) %p\n", This, pdidi);
1349 if (pdidi == NULL) return E_POINTER;
1350 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
1351 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)))
1352 return DIERR_INVALIDPARAM;
1354 fill_joystick_dideviceinstanceA(pdidi, This->generic.base.dinput->dwVersion,
1355 get_joystick_index(&This->generic.base.guid));
1359 static HRESULT WINAPI JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface,
1360 LPDIDEVICEINSTANCEW pdidi)
1362 JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
1364 TRACE("(%p) %p\n", This, pdidi);
1366 if (pdidi == NULL) return E_POINTER;
1367 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3W)) &&
1368 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)))
1369 return DIERR_INVALIDPARAM;
1371 fill_joystick_dideviceinstanceW(pdidi, This->generic.base.dinput->dwVersion,
1372 get_joystick_index(&This->generic.base.guid));
1376 static const IDirectInputDevice8AVtbl JoystickAvt =
1378 IDirectInputDevice2AImpl_QueryInterface,
1379 IDirectInputDevice2AImpl_AddRef,
1380 IDirectInputDevice2AImpl_Release,
1381 JoystickAGenericImpl_GetCapabilities,
1382 IDirectInputDevice2AImpl_EnumObjects,
1383 JoystickAImpl_GetProperty,
1384 JoystickAImpl_SetProperty,
1385 JoystickAImpl_Acquire,
1386 JoystickAImpl_Unacquire,
1387 JoystickAGenericImpl_GetDeviceState,
1388 IDirectInputDevice2AImpl_GetDeviceData,
1389 IDirectInputDevice2AImpl_SetDataFormat,
1390 IDirectInputDevice2AImpl_SetEventNotification,
1391 IDirectInputDevice2AImpl_SetCooperativeLevel,
1392 JoystickAGenericImpl_GetObjectInfo,
1393 JoystickAImpl_GetDeviceInfo,
1394 IDirectInputDevice2AImpl_RunControlPanel,
1395 IDirectInputDevice2AImpl_Initialize,
1396 JoystickAImpl_CreateEffect,
1397 JoystickAImpl_EnumEffects,
1398 JoystickAImpl_GetEffectInfo,
1399 JoystickAImpl_GetForceFeedbackState,
1400 JoystickAImpl_SendForceFeedbackCommand,
1401 JoystickAImpl_EnumCreatedEffectObjects,
1402 IDirectInputDevice2AImpl_Escape,
1403 JoystickAGenericImpl_Poll,
1404 IDirectInputDevice2AImpl_SendDeviceData,
1405 IDirectInputDevice7AImpl_EnumEffectsInFile,
1406 IDirectInputDevice7AImpl_WriteEffectToFile,
1407 IDirectInputDevice8AImpl_BuildActionMap,
1408 IDirectInputDevice8AImpl_SetActionMap,
1409 IDirectInputDevice8AImpl_GetImageInfo
1412 static const IDirectInputDevice8WVtbl JoystickWvt =
1414 IDirectInputDevice2WImpl_QueryInterface,
1415 IDirectInputDevice2WImpl_AddRef,
1416 IDirectInputDevice2WImpl_Release,
1417 JoystickWGenericImpl_GetCapabilities,
1418 IDirectInputDevice2WImpl_EnumObjects,
1419 JoystickWImpl_GetProperty,
1420 JoystickWImpl_SetProperty,
1421 JoystickWImpl_Acquire,
1422 JoystickWImpl_Unacquire,
1423 JoystickWGenericImpl_GetDeviceState,
1424 IDirectInputDevice2WImpl_GetDeviceData,
1425 IDirectInputDevice2WImpl_SetDataFormat,
1426 IDirectInputDevice2WImpl_SetEventNotification,
1427 IDirectInputDevice2WImpl_SetCooperativeLevel,
1428 JoystickWGenericImpl_GetObjectInfo,
1429 JoystickWImpl_GetDeviceInfo,
1430 IDirectInputDevice2WImpl_RunControlPanel,
1431 IDirectInputDevice2WImpl_Initialize,
1432 JoystickWImpl_CreateEffect,
1433 JoystickWImpl_EnumEffects,
1434 JoystickWImpl_GetEffectInfo,
1435 JoystickWImpl_GetForceFeedbackState,
1436 JoystickWImpl_SendForceFeedbackCommand,
1437 JoystickWImpl_EnumCreatedEffectObjects,
1438 IDirectInputDevice2WImpl_Escape,
1439 JoystickWGenericImpl_Poll,
1440 IDirectInputDevice2WImpl_SendDeviceData,
1441 IDirectInputDevice7WImpl_EnumEffectsInFile,
1442 IDirectInputDevice7WImpl_WriteEffectToFile,
1443 IDirectInputDevice8WImpl_BuildActionMap,
1444 IDirectInputDevice8WImpl_SetActionMap,
1445 IDirectInputDevice8WImpl_GetImageInfo
1448 #else /* HAVE_CORRECT_LINUXINPUT_H */
1450 const struct dinput_device joystick_linuxinput_device = {
1451 "Wine Linux-input joystick driver",
1458 #endif /* HAVE_CORRECT_LINUXINPUT_H */