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>
47 # if defined(EVIOCGBIT) && defined(EV_ABS) && defined(BTN_PINKIE)
48 # define HAVE_CORRECT_LINUXINPUT_H
51 #ifdef HAVE_SYS_POLL_H
52 # include <sys/poll.h>
55 #include "wine/debug.h"
56 #include "wine/unicode.h"
62 #include "dinput_private.h"
63 #include "device_private.h"
65 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
67 #ifdef HAVE_CORRECT_LINUXINPUT_H
69 #define EVDEVPREFIX "/dev/input/event"
71 /* Wine joystick driver object instances */
72 #define WINE_JOYSTICK_AXIS_BASE 0
73 #define WINE_JOYSTICK_POV_BASE 6
74 #define WINE_JOYSTICK_BUTTON_BASE 8
76 typedef struct EffectListItem EffectListItem;
79 LPDIRECTINPUTEFFECT ref;
80 struct EffectListItem* next;
83 /* implemented in effect_linuxinput.c */
84 HRESULT linuxinput_create_effect(int* fd, REFGUID rguid, LPDIRECTINPUTEFFECT* peff);
85 HRESULT linuxinput_get_info_A(int fd, REFGUID rguid, LPDIEFFECTINFOA info);
86 HRESULT linuxinput_get_info_W(int fd, REFGUID rguid, LPDIEFFECTINFOW info);
88 typedef struct JoystickImpl JoystickImpl;
89 static const IDirectInputDevice8AVtbl JoystickAvt;
90 static const IDirectInputDevice8WVtbl JoystickWvt;
100 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
101 BYTE evbits[(EV_MAX+7)/8];
102 BYTE absbits[(ABS_MAX+7)/8];
103 BYTE keybits[(KEY_MAX+7)/8];
104 BYTE ffbits[(FF_MAX+7)/8];
109 #define AXE_ABSFUZZ 3
110 #define AXE_ABSFLAT 4
112 /* data returned by the EVIOCGABS() ioctl */
113 int axes[ABS_MAX][5];
114 /* LUT for KEY_ to offset in rgbButtons */
115 BYTE buttons[KEY_MAX];
117 /* autodetecting ranges per axe by following movement */
118 LONG havemax[ABS_MAX];
119 LONG havemin[ABS_MAX];
124 struct IDirectInputDevice2AImpl base;
126 struct JoyDev *joydev;
128 /* The 'parent' DInput */
129 IDirectInputImpl *dinput;
131 /* joystick private */
132 /* what range and deadzone the game wants */
133 LONG wantmin[ABS_MAX];
134 LONG wantmax[ABS_MAX];
141 /* Force feedback variables */
142 EffectListItem* top_effect;
146 static void fake_current_js_state(JoystickImpl *ji);
147 static DWORD map_pov(int event_value, int is_x);
148 static void find_joydevs(void);
149 static int lxinput_to_user_offset(JoystickImpl *This, int ie_type, int ie_code);
151 /* This GUID is slightly different from the linux joystick one. Take note. */
152 static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
156 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
159 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
161 #define MAX_JOYDEV 64
163 static int have_joydevs = -1;
164 static struct JoyDev *joydevs = NULL;
166 static void find_joydevs(void)
170 if (have_joydevs!=-1) {
176 for (i=0;i<MAX_JOYDEV;i++) {
178 struct JoyDev joydev = {0};
183 snprintf(buf,MAX_PATH,EVDEVPREFIX"%d",i);
186 if ((fd=open(buf, O_RDWR))==-1) {
187 fd = open(buf, O_RDONLY);
192 if ((-1==ioctl(fd,EVIOCGBIT(0,sizeof(joydev.evbits)),joydev.evbits))) {
193 perror("EVIOCGBIT 0");
197 if (-1==ioctl(fd,EVIOCGBIT(EV_ABS,sizeof(joydev.absbits)),joydev.absbits)) {
198 perror("EVIOCGBIT EV_ABS");
202 if (-1==ioctl(fd,EVIOCGBIT(EV_KEY,sizeof(joydev.keybits)),joydev.keybits)) {
203 perror("EVIOCGBIT EV_KEY");
207 /* A true joystick has at least axis X and Y, and at least 1
208 * button. copied from linux/drivers/input/joydev.c */
209 if (test_bit(joydev.absbits,ABS_X) && test_bit(joydev.absbits,ABS_Y) &&
210 ( test_bit(joydev.keybits,BTN_TRIGGER) ||
211 test_bit(joydev.keybits,BTN_A) ||
212 test_bit(joydev.keybits,BTN_1)
216 joydev.device = strdup(buf);
218 if (-1!=ioctl(fd, EVIOCGNAME(MAX_PATH-1), buf)) {
220 joydev.name = strdup(buf);
222 joydev.name = joydev.device;
225 joydev.guid = DInput_Wine_Joystick_Base_GUID;
226 joydev.guid.Data3 += have_joydevs;
228 TRACE("Found a joystick on %s: %s (%s)\n",
229 joydev.device, joydev.name,
230 debugstr_guid(&joydev.guid)
233 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
235 if ((!test_bit(joydev.evbits,EV_FF))
236 || (-1==ioctl(fd,EVIOCGBIT(EV_FF,sizeof(joydev.ffbits)),joydev.ffbits))
237 || (-1==ioctl(fd,EVIOCGEFFECTS,&joydev.num_effects))
238 || (joydev.num_effects <= 0)) {
241 TRACE(" ... with force feedback\n");
247 for (j=0;j<ABS_MAX;j++) {
248 if (test_bit(joydev.absbits,j)) {
249 if (-1!=ioctl(fd,EVIOCGABS(j),&(joydev.axes[j]))) {
250 TRACE(" ... with axe %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
252 joydev.axes[j][AXE_ABS],
253 joydev.axes[j][AXE_ABSMIN],
254 joydev.axes[j][AXE_ABSMAX],
255 joydev.axes[j][AXE_ABSFUZZ],
256 joydev.axes[j][AXE_ABSFLAT]
258 joydev.havemin[j] = joydev.axes[j][AXE_ABSMIN];
259 joydev.havemax[j] = joydev.axes[j][AXE_ABSMAX];
265 for (j=0;j<KEY_MAX;j++) {
266 if (test_bit(joydev.keybits,j)) {
267 TRACE(" ... with button %d: %d\n", j, buttons);
268 joydev.buttons[j] = 0x80 | buttons;
273 if (have_joydevs==0) {
274 joydevs = HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev));
276 HeapReAlloc(GetProcessHeap(), 0, joydevs, (1+have_joydevs) * sizeof(struct JoyDev));
278 memcpy(joydevs+have_joydevs, &joydev, sizeof(struct JoyDev));
287 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
291 if (id >= have_joydevs) {
295 if (!((dwDevType == 0) ||
296 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
297 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
300 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
301 if (dwFlags & DIEDFL_FORCEFEEDBACK)
305 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
306 lpddi->guidInstance = joydevs[id].guid;
307 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
309 lpddi->guidFFDriver = GUID_NULL;
310 if (version >= 0x0800)
311 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
313 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
315 strcpy(lpddi->tszInstanceName, joydevs[id].name);
316 strcpy(lpddi->tszProductName, joydevs[id].device);
322 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
326 if (id >= have_joydevs) {
330 if (!((dwDevType == 0) ||
331 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
332 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
335 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
336 if (dwFlags & DIEDFL_FORCEFEEDBACK)
340 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
341 lpddi->guidInstance = joydevs[id].guid;
342 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
344 lpddi->guidFFDriver = GUID_NULL;
345 if (version >= 0x0800)
346 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
348 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
350 MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
351 MultiByteToWideChar(CP_ACP, 0, joydevs[id].device, -1, lpddi->tszProductName, MAX_PATH);
357 static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, struct JoyDev *joydev)
359 JoystickImpl* newDevice;
362 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
363 if (newDevice==NULL) {
367 newDevice->base.lpVtbl = jvt;
368 newDevice->base.ref = 1;
369 memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
370 InitializeCriticalSection(&newDevice->base.crit);
371 newDevice->joyfd = -1;
372 newDevice->dinput = dinput;
373 newDevice->joydev = joydev;
374 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
375 newDevice->ff_state = FF_STATUS_STOPPED;
377 for (i=0;i<ABS_MAX;i++) {
378 /* apps expect the range to be the same they would get from the
379 * GetProperty/range method */
380 newDevice->wantmin[i] = newDevice->joydev->havemin[i];
381 newDevice->wantmax[i] = newDevice->joydev->havemax[i];
383 * direct input defines a default for the deadzone somewhere; but as long
384 * as in map_axis the code for the dead zone is commented out its no
387 newDevice->deadz[i] = 0;
389 fake_current_js_state(newDevice);
391 /* wine uses DIJOYSTATE2 as it's internal format */
392 newDevice->base.data_format.wine_df = &c_dfDIJoystick2;
394 /* create the default transform filter */
395 if (create_DataFormat(&c_dfDIJoystick2, &c_dfDIJoystick2, &newDevice->base.data_format) == DI_OK)
398 HeapFree(GetProcessHeap(),0,newDevice);
402 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
408 for (i=0; i<have_joydevs; i++) {
409 if (IsEqualGUID(&GUID_Joystick,rguid) ||
410 IsEqualGUID(&joydevs[i].guid,rguid)
412 if ((riid == NULL) ||
413 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
414 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
415 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
416 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
417 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, &joydevs[i]);
418 TRACE("Creating a Joystick device (%p)\n", *pdev);
420 ERR("out of memory\n");
421 return DIERR_OUTOFMEMORY;
425 return DIERR_NOINTERFACE;
430 return DIERR_DEVICENOTREG;
434 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
440 for (i=0; i<have_joydevs; i++) {
441 if (IsEqualGUID(&GUID_Joystick,rguid) ||
442 IsEqualGUID(&joydevs[i].guid,rguid)
444 if ((riid == NULL) ||
445 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
446 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
447 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
448 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
449 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, &joydevs[i]);
450 TRACE("Creating a Joystick device (%p)\n", *pdev);
452 ERR("out of memory\n");
453 return DIERR_OUTOFMEMORY;
457 return DIERR_NOINTERFACE;
462 return DIERR_DEVICENOTREG;
465 const struct dinput_device joystick_linuxinput_device = {
466 "Wine Linux-input joystick driver",
469 joydev_create_deviceA,
470 joydev_create_deviceW
473 /******************************************************************************
476 static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
478 JoystickImpl *This = (JoystickImpl *)iface;
481 ref = InterlockedDecrement(&This->base.ref);
485 /* Reset the FF state, free all effects, etc */
486 IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
488 /* Free the data queue */
489 HeapFree(GetProcessHeap(), 0, This->base.data_queue);
491 /* release the data transform filter */
492 release_DataFormat(&This->base.data_format);
494 DeleteCriticalSection(&This->base.crit);
496 HeapFree(GetProcessHeap(),0,This);
500 /******************************************************************************
501 * Acquire : gets exclusive control of the joystick
503 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
505 JoystickImpl *This = (JoystickImpl *)iface;
508 TRACE("(this=%p)\n",This);
510 res = IDirectInputDevice2AImpl_Acquire(iface);
512 if (-1==(This->joyfd=open(This->joydev->device,O_RDWR))) {
513 if (-1==(This->joyfd=open(This->joydev->device,O_RDONLY))) {
514 /* Couldn't open the device at all */
515 perror(This->joydev->device);
516 IDirectInputDevice2AImpl_Unacquire(iface);
517 return DIERR_NOTFOUND;
519 /* Couldn't open in r/w but opened in read-only. */
520 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This->joydev->device);
528 /******************************************************************************
529 * Unacquire : frees the joystick
531 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
533 JoystickImpl *This = (JoystickImpl *)iface;
536 TRACE("(this=%p)\n",This);
537 res = IDirectInputDevice2AImpl_Unacquire(iface);
538 if (res==DI_OK && This->joyfd!=-1) {
546 * This maps the read value (from the input event) to a value in the
547 * 'wanted' range. It also autodetects the possible range of the axe and
548 * adapts values accordingly.
551 map_axis(JoystickImpl* This, int axis, int val) {
552 int xmin = This->joydev->axes[axis][AXE_ABSMIN];
553 int xmax = This->joydev->axes[axis][AXE_ABSMAX];
554 int hmax = This->joydev->havemax[axis];
555 int hmin = This->joydev->havemin[axis];
556 int wmin = This->wantmin[axis];
557 int wmax = This->wantmax[axis];
560 if (val > hmax) This->joydev->havemax[axis] = hmax = val;
561 if (val < hmin) This->joydev->havemin[axis] = hmin = val;
563 if (xmin == xmax) return val;
565 /* map the value from the hmin-hmax range into the wmin-wmax range */
566 ret = MulDiv( val - hmin, wmax - wmin, hmax - hmin ) + wmin;
568 TRACE("xmin=%d xmax=%d hmin=%d hmax=%d wmin=%d wmax=%d val=%d ret=%d\n", xmin, xmax, hmin, hmax, wmin, wmax, val, ret);
571 /* deadzone doesn't work comfortably enough right now. needs more testing*/
572 if ((ret > -deadz/2 ) && (ret < deadz/2)) {
573 FIXME("%d in deadzone, return mid.\n",val);
574 return (wmax-wmin)/2+wmin;
581 * set the current state of the js device as it would be with the middle
584 static void fake_current_js_state(JoystickImpl *ji)
587 /* center the axes */
588 ji->js.lX = test_bit(ji->joydev->absbits, ABS_X) ? map_axis(ji, ABS_X, ji->joydev->axes[ABS_X ][AXE_ABS]) : 0;
589 ji->js.lY = test_bit(ji->joydev->absbits, ABS_Y) ? map_axis(ji, ABS_Y, ji->joydev->axes[ABS_Y ][AXE_ABS]) : 0;
590 ji->js.lZ = test_bit(ji->joydev->absbits, ABS_Z) ? map_axis(ji, ABS_Z, ji->joydev->axes[ABS_Z ][AXE_ABS]) : 0;
591 ji->js.lRx = test_bit(ji->joydev->absbits, ABS_RX) ? map_axis(ji, ABS_RX, ji->joydev->axes[ABS_RX ][AXE_ABS]) : 0;
592 ji->js.lRy = test_bit(ji->joydev->absbits, ABS_RY) ? map_axis(ji, ABS_RY, ji->joydev->axes[ABS_RY ][AXE_ABS]) : 0;
593 ji->js.lRz = test_bit(ji->joydev->absbits, ABS_RZ) ? map_axis(ji, ABS_RZ, ji->joydev->axes[ABS_RZ ][AXE_ABS]) : 0;
594 ji->js.rglSlider[0] = test_bit(ji->joydev->absbits, ABS_THROTTLE) ? map_axis(ji, ABS_THROTTLE, ji->joydev->axes[ABS_THROTTLE][AXE_ABS]) : 0;
595 ji->js.rglSlider[1] = test_bit(ji->joydev->absbits, ABS_RUDDER) ? map_axis(ji, ABS_RUDDER, ji->joydev->axes[ABS_RUDDER ][AXE_ABS]) : 0;
596 /* POV center is -1 */
597 for (i=0; i<4; i++) {
598 ji->js.rgdwPOV[i] = -1;
603 * Maps an event value to a DX "clock" position:
608 static DWORD map_pov(int event_value, int is_x)
614 } else if (event_value>0) {
620 } else if (event_value>0) {
627 /* defines how the linux input system offset mappings into c_dfDIJoystick2 */
629 lxinput_to_user_offset(JoystickImpl *This, int ie_type, int ie_code )
635 case ABS_X: offset = 0; break;
636 case ABS_Y: offset = 1; break;
637 case ABS_Z: offset = 2; break;
638 case ABS_RX: offset = 3; break;
639 case ABS_RY: offset = 4; break;
640 case ABS_RZ: offset = 5; break;
641 case ABS_THROTTLE: offset = 6; break;
642 case ABS_RUDDER: offset = 7; break;
643 case ABS_HAT0X: case ABS_HAT0Y: offset = 8; break;
644 case ABS_HAT1X: case ABS_HAT1Y: offset = 9; break;
645 case ABS_HAT2X: case ABS_HAT2Y: offset = 10; break;
646 case ABS_HAT3X: case ABS_HAT3Y: offset = 11; break;
647 /* XXX when adding new axes here also fix the offset for the buttons bellow */
649 FIXME("Unhandled EV_ABS(0x%02X)\n", ie_code);
654 if (ie_code >= 128) {
655 WARN("DX8 does not support more than 128 buttons\n");
658 offset = 12 + ie_code; /* XXX */
661 FIXME("Unhandled type(0x%02X)\n", ie_type);
664 return This->base.data_format.offsets[offset];
667 /* convert wine format offset to user format object index */
668 static void joy_polldev(JoystickImpl *This) {
670 struct input_event ie;
677 plfd.fd = This->joyfd;
678 plfd.events = POLLIN;
680 if (poll(&plfd,1,0) != 1)
683 /* we have one event, so we can read */
684 if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
687 TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
689 case EV_KEY: /* button */
690 btn = This->joydev->buttons[ie.code];
691 TRACE("(%p) %d -> %d\n", This, ie.code, btn);
694 if ((offset = lxinput_to_user_offset(This, ie.type, btn)) == -1) {
697 This->js.rgbButtons[btn] = ie.value?0x80:0x00;
698 queue_event((LPDIRECTINPUTDEVICE8A)This, offset, This->js.rgbButtons[btn],
699 ie.time.tv_usec, This->dinput->evsequence++);
703 if ((offset = lxinput_to_user_offset(This, ie.type, ie.code)) == -1) {
708 This->js.lX = map_axis(This,ABS_X,ie.value);
709 queue_event((LPDIRECTINPUTDEVICE8A)This, offset, This->js.lX,
710 ie.time.tv_usec, This->dinput->evsequence++);
713 This->js.lY = map_axis(This,ABS_Y,ie.value);
714 queue_event((LPDIRECTINPUTDEVICE8A)This, offset, This->js.lY,
715 ie.time.tv_usec, This->dinput->evsequence++);
718 This->js.lZ = map_axis(This,ABS_Z,ie.value);
719 queue_event((LPDIRECTINPUTDEVICE8A)This, offset, This->js.lZ,
720 ie.time.tv_usec, This->dinput->evsequence++);
723 This->js.lRx = map_axis(This,ABS_RX,ie.value);
724 queue_event((LPDIRECTINPUTDEVICE8A)This, offset, This->js.lRx,
725 ie.time.tv_usec, This->dinput->evsequence++);
728 This->js.lRy = map_axis(This,ABS_RY,ie.value);
729 queue_event((LPDIRECTINPUTDEVICE8A)This, offset, This->js.lRy,
730 ie.time.tv_usec, This->dinput->evsequence++);
733 This->js.lRz = map_axis(This,ABS_RZ,ie.value);
734 queue_event((LPDIRECTINPUTDEVICE8A)This, offset, This->js.lRz,
735 ie.time.tv_usec, This->dinput->evsequence++);
738 This->js.rglSlider[0] = map_axis(This,ABS_THROTTLE,ie.value);
739 queue_event((LPDIRECTINPUTDEVICE8A)This, offset, This->js.rglSlider[0],
740 ie.time.tv_usec, This->dinput->evsequence++);
743 This->js.rglSlider[1] = map_axis(This,ABS_RUDDER,ie.value);
744 queue_event((LPDIRECTINPUTDEVICE8A)This, offset, This->js.rglSlider[1],
745 ie.time.tv_usec, This->dinput->evsequence++);
749 This->js.rgdwPOV[0] = map_pov(ie.value,ie.code==ABS_HAT0X);
750 queue_event((LPDIRECTINPUTDEVICE8A)This, offset, This->js.rgdwPOV[0],
751 ie.time.tv_usec, This->dinput->evsequence++);
755 This->js.rgdwPOV[1] = map_pov(ie.value,ie.code==ABS_HAT1X);
756 queue_event((LPDIRECTINPUTDEVICE8A)This, offset, This->js.rgdwPOV[1],
757 ie.time.tv_usec, This->dinput->evsequence++);
761 This->js.rgdwPOV[2] = map_pov(ie.value,ie.code==ABS_HAT2X);
762 queue_event((LPDIRECTINPUTDEVICE8A)This, offset, This->js.rgdwPOV[2],
763 ie.time.tv_usec, This->dinput->evsequence++);
767 This->js.rgdwPOV[3] = map_pov(ie.value,ie.code==ABS_HAT3X);
768 queue_event((LPDIRECTINPUTDEVICE8A)This, offset, This->js.rgdwPOV[3],
769 ie.time.tv_usec, This->dinput->evsequence++);
772 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie.code,ie.value);
776 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
778 This->ff_state = ie.value;
783 /* there is nothing to do */
787 FIXME("joystick cannot handle type %d event (code %d)\n",ie.type,ie.code);
793 /******************************************************************************
794 * GetDeviceState : returns the "state" of the joystick.
797 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
798 LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
800 JoystickImpl *This = (JoystickImpl *)iface;
802 TRACE("(this=%p,0x%08x,%p)\n", This, len, ptr);
804 if (This->joyfd==-1) {
805 WARN("not acquired\n");
806 return DIERR_NOTACQUIRED;
811 /* convert and copy data to user supplied buffer */
812 fill_DataFormat(ptr, &This->js, &This->base.data_format);
817 /******************************************************************************
818 * SetProperty : change input device properties
820 static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
824 JoystickImpl *This = (JoystickImpl *)iface;
827 WARN("invalid argument\n");
828 return DIERR_INVALIDPARAM;
831 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
832 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
833 ph->dwSize, ph->dwHeaderSize, ph->dwObj, ph->dwHow);
835 if (!HIWORD(rguid)) {
836 switch (LOWORD(rguid)) {
837 case (DWORD)DIPROP_RANGE: {
838 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
840 if (ph->dwHow == DIPH_DEVICE) {
842 TRACE("proprange(%d,%d) all\n", pr->lMin, pr->lMax);
843 for (i = 0; i < This->base.data_format.user_df->dwNumObjs; i++) {
844 This->wantmin[i] = pr->lMin;
845 This->wantmax[i] = pr->lMax;
848 int obj = find_property(This->base.data_format.user_df, ph);
849 TRACE("proprange(%d,%d) obj=%d\n", pr->lMin, pr->lMax, obj);
851 This->wantmin[obj] = pr->lMin;
852 This->wantmax[obj] = pr->lMax;
855 fake_current_js_state(This);
858 case (DWORD)DIPROP_DEADZONE: {
859 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
860 if (ph->dwHow == DIPH_DEVICE) {
862 TRACE("deadzone(%d) all\n", pd->dwData);
863 for (i = 0; i < This->base.data_format.user_df->dwNumObjs; i++) {
864 This->deadz[i] = pd->dwData;
867 int obj = find_property(This->base.data_format.user_df, ph);
868 TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
870 This->deadz[obj] = pd->dwData;
873 fake_current_js_state(This);
876 case (DWORD)DIPROP_CALIBRATIONMODE: {
877 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
878 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd->dwData);
882 return IDirectInputDevice2AImpl_SetProperty(iface, rguid, ph);
888 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
889 LPDIRECTINPUTDEVICE8A iface,
890 LPDIDEVCAPS lpDIDevCaps)
892 JoystickImpl *This = (JoystickImpl *)iface;
893 int i,axes,buttons,povs;
895 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
898 WARN("invalid pointer\n");
902 if (lpDIDevCaps->dwSize < sizeof(DIDEVCAPS)) {
903 WARN("invalid argument\n");
904 return DIERR_INVALIDPARAM;
907 lpDIDevCaps->dwFlags = DIDC_ATTACHED;
908 if (This->dinput->dwVersion >= 0x0800)
909 lpDIDevCaps->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
911 lpDIDevCaps->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
914 for (i=0;i<ABS_MAX;i++) {
915 if (!test_bit(This->joydev->absbits,i)) continue;
917 case ABS_HAT0X: case ABS_HAT0Y:
918 case ABS_HAT1X: case ABS_HAT1Y:
919 case ABS_HAT2X: case ABS_HAT2Y:
920 case ABS_HAT3X: case ABS_HAT3Y:
921 /* will be handled as POV - see below */
928 for (i=0;i<KEY_MAX;i++) if (test_bit(This->joydev->keybits,i)) buttons++;
930 for (i=0; i<4; i++) {
931 if (test_bit(This->joydev->absbits,ABS_HAT0X+(i<<1)) && test_bit(This->joydev->absbits,ABS_HAT0Y+(i<<1))) {
936 if (This->joydev->has_ff)
937 lpDIDevCaps->dwFlags |= DIDC_FORCEFEEDBACK;
939 lpDIDevCaps->dwAxes = axes;
940 lpDIDevCaps->dwButtons = buttons;
941 lpDIDevCaps->dwPOVs = povs;
946 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface) {
947 JoystickImpl *This = (JoystickImpl *)iface;
948 TRACE("(%p)\n",This);
950 if (This->joyfd==-1) {
951 return DIERR_NOTACQUIRED;
958 /******************************************************************************
959 * EnumObjects : enumerate the different buttons and axis...
961 static HRESULT WINAPI JoystickAImpl_EnumObjects(
962 LPDIRECTINPUTDEVICE8A iface,
963 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
967 JoystickImpl *This = (JoystickImpl *)iface;
968 DIDEVICEOBJECTINSTANCEA ddoi;
969 int user_offset, user_object;
971 TRACE("(this=%p,%p,%p,%08x)\n", This, lpCallback, lpvRef, dwFlags);
972 if (TRACE_ON(dinput)) {
973 TRACE(" - flags = ");
974 _dump_EnumObjects_flags(dwFlags);
978 /* Only the fields till dwFFMaxForce are relevant */
979 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
981 /* For the joystick, do as is done in the GetCapabilities function */
982 /* FIXME: needs more items */
983 if ((dwFlags == DIDFT_ALL) ||
984 (dwFlags & DIDFT_AXIS)) {
987 for (i = 0; i < ABS_MAX; i++) {
988 if (!test_bit(This->joydev->absbits,i)) continue;
992 ddoi.guidType = GUID_XAxis;
995 ddoi.guidType = GUID_YAxis;
998 ddoi.guidType = GUID_ZAxis;
1001 ddoi.guidType = GUID_RxAxis;
1004 ddoi.guidType = GUID_RyAxis;
1007 ddoi.guidType = GUID_RzAxis;
1011 ddoi.guidType = GUID_Slider;
1013 case ABS_HAT0X: case ABS_HAT0Y:
1014 case ABS_HAT1X: case ABS_HAT1Y:
1015 case ABS_HAT2X: case ABS_HAT2Y:
1016 case ABS_HAT3X: case ABS_HAT3Y:
1017 /* will be handled as POV - see below */
1020 FIXME("unhandled abs axis 0x%02x, ignoring!\n",i);
1023 if ((user_offset = lxinput_to_user_offset(This, EV_ABS, i)) == -1) {
1026 user_object = offset_to_object(This->base.data_format.user_df, user_offset);
1027 ddoi.dwType = This->base.data_format.user_df->rgodf[user_object].dwType & 0x00ffffff;
1028 ddoi.dwOfs = This->base.data_format.user_df->rgodf[user_object].dwOfs;
1029 /* Linux event force feedback supports only (and always) x and y axes */
1030 if (i == ABS_X || i == ABS_Y) {
1031 if (This->joydev->has_ff)
1032 ddoi.dwFlags |= DIDOI_FFACTUATOR;
1034 sprintf(ddoi.tszName, "%d-Axis", i);
1035 _dump_OBJECTINSTANCEA(&ddoi);
1036 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) {
1042 if ((dwFlags == DIDFT_ALL) ||
1043 (dwFlags & DIDFT_POV)) {
1045 ddoi.guidType = GUID_POV;
1046 for (i=0; i<4; i++) {
1047 if (test_bit(This->joydev->absbits,ABS_HAT0X+(i<<1)) && test_bit(This->joydev->absbits,ABS_HAT0Y+(i<<1))) {
1048 if ((user_offset = lxinput_to_user_offset(This, EV_ABS, ABS_HAT0X+i))== -1) {
1051 user_object = offset_to_object(This->base.data_format.user_df, user_offset);
1052 ddoi.dwType = This->base.data_format.user_df->rgodf[user_object].dwType & 0x00ffffff;
1053 ddoi.dwOfs = This->base.data_format.user_df->rgodf[user_object].dwOfs;
1054 sprintf(ddoi.tszName, "%d-POV", i);
1055 _dump_OBJECTINSTANCEA(&ddoi);
1056 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) {
1063 if ((dwFlags == DIDFT_ALL) ||
1064 (dwFlags & DIDFT_BUTTON)) {
1067 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
1069 ddoi.guidType = GUID_Button;
1071 for (i = 0; i < KEY_MAX; i++) {
1072 if (!test_bit(This->joydev->keybits,i)) continue;
1073 if ((user_offset = lxinput_to_user_offset(This, EV_KEY, btncount)) == -1) {
1076 user_object = offset_to_object(This->base.data_format.user_df, user_offset);
1077 ddoi.dwType = This->base.data_format.user_df->rgodf[user_object].dwType & 0x00ffffff;
1078 ddoi.dwOfs = This->base.data_format.user_df->rgodf[user_object].dwOfs;
1079 sprintf(ddoi.tszName, "%d-Button", btncount);
1081 _dump_OBJECTINSTANCEA(&ddoi);
1082 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) {
1091 static HRESULT WINAPI JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
1092 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
1096 JoystickImpl *This = (JoystickImpl *)iface;
1098 device_enumobjects_AtoWcb_data data;
1100 data.lpCallBack = lpCallback;
1101 data.lpvRef = lpvRef;
1103 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
1106 /******************************************************************************
1107 * GetProperty : get input device properties
1109 static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
1111 LPDIPROPHEADER pdiph)
1113 JoystickImpl *This = (JoystickImpl *)iface;
1115 TRACE("(this=%p,%s,%p)\n",
1116 iface, debugstr_guid(rguid), pdiph);
1118 if (TRACE_ON(dinput))
1119 _dump_DIPROPHEADER(pdiph);
1121 if (!HIWORD(rguid)) {
1122 switch (LOWORD(rguid)) {
1123 case (DWORD) DIPROP_RANGE: {
1124 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
1125 int obj = find_property(This->base.data_format.user_df, pdiph);
1127 pr->lMin = This->joydev->havemin[obj];
1128 pr->lMax = This->joydev->havemax[obj];
1129 TRACE("range(%d, %d) obj=%d\n", pr->lMin, pr->lMax, obj);
1135 return IDirectInputDevice2AImpl_GetProperty(iface, rguid, pdiph);
1143 /******************************************************************************
1144 * CreateEffect - Create a new FF effect with the specified params
1146 static HRESULT WINAPI JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface,
1149 LPDIRECTINPUTEFFECT *ppdef,
1150 LPUNKNOWN pUnkOuter)
1152 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1153 EffectListItem* new = NULL;
1154 HRESULT retval = DI_OK;
1157 JoystickImpl* This = (JoystickImpl*)iface;
1158 TRACE("(this=%p,%p,%p,%p,%p)\n", This, rguid, lpeff, ppdef, pUnkOuter);
1160 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1161 TRACE("not available (compiled w/o ff support)\n");
1166 new = HeapAlloc(GetProcessHeap(), 0, sizeof(EffectListItem));
1167 new->next = This->top_effect;
1168 This->top_effect = new;
1170 retval = linuxinput_create_effect(&(This->joyfd), rguid, &(new->ref));
1171 if (retval != DI_OK)
1175 retval = IDirectInputEffect_SetParameters(new->ref, lpeff, 0);
1176 if (retval != DI_OK && retval != DI_DOWNLOADSKIPPED)
1181 if (pUnkOuter != NULL)
1182 FIXME("Interface aggregation not implemented.\n");
1186 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1189 /*******************************************************************************
1190 * EnumEffects - Enumerate available FF effects
1192 static HRESULT WINAPI JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface,
1193 LPDIENUMEFFECTSCALLBACKA lpCallback,
1197 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1198 DIEFFECTINFOA dei; /* feif */
1199 DWORD type = DIEFT_GETTYPE(dwEffType);
1200 JoystickImpl* This = (JoystickImpl*)iface;
1202 TRACE("(this=%p,%p,%d) type=%d\n", This, pvRef, dwEffType, type);
1204 dei.dwSize = sizeof(DIEFFECTINFOA);
1206 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1207 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1208 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1209 (*lpCallback)(&dei, pvRef);
1212 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1213 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1214 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1215 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1216 (*lpCallback)(&dei, pvRef);
1218 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1219 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1220 (*lpCallback)(&dei, pvRef);
1222 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1223 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1224 (*lpCallback)(&dei, pvRef);
1226 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1227 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1228 (*lpCallback)(&dei, pvRef);
1230 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1231 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1232 (*lpCallback)(&dei, pvRef);
1236 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1237 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1238 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1239 (*lpCallback)(&dei, pvRef);
1242 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1243 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1244 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1245 (*lpCallback)(&dei, pvRef);
1247 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1248 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1249 (*lpCallback)(&dei, pvRef);
1251 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1252 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1253 (*lpCallback)(&dei, pvRef);
1255 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1256 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1257 (*lpCallback)(&dei, pvRef);
1266 static HRESULT WINAPI JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface,
1267 LPDIENUMEFFECTSCALLBACKW lpCallback,
1271 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1272 /* seems silly to duplicate all this code but all the structures and functions
1273 * are actually different (A/W) */
1274 DIEFFECTINFOW dei; /* feif */
1275 DWORD type = DIEFT_GETTYPE(dwEffType);
1276 JoystickImpl* This = (JoystickImpl*)iface;
1277 int xfd = This->joyfd;
1279 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This, pvRef, dwEffType, type, xfd);
1281 dei.dwSize = sizeof(DIEFFECTINFOW);
1283 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1284 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1285 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1286 (*lpCallback)(&dei, pvRef);
1289 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1290 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1291 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1292 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1293 (*lpCallback)(&dei, pvRef);
1295 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1296 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1297 (*lpCallback)(&dei, pvRef);
1299 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1300 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1301 (*lpCallback)(&dei, pvRef);
1303 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1304 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1305 (*lpCallback)(&dei, pvRef);
1307 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1308 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1309 (*lpCallback)(&dei, pvRef);
1313 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1314 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1315 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1316 (*lpCallback)(&dei, pvRef);
1319 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1320 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1321 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1322 (*lpCallback)(&dei, pvRef);
1324 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1325 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1326 (*lpCallback)(&dei, pvRef);
1328 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1329 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1330 (*lpCallback)(&dei, pvRef);
1332 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1333 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1334 (*lpCallback)(&dei, pvRef);
1338 /* return to unacquired state if that's where it was */
1340 IDirectInputDevice8_Unacquire(iface);
1346 /*******************************************************************************
1347 * GetEffectInfo - Get information about a particular effect
1349 static HRESULT WINAPI JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface,
1350 LPDIEFFECTINFOA pdei,
1353 JoystickImpl* This = (JoystickImpl*)iface;
1355 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1357 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1358 return linuxinput_get_info_A(This->joyfd, guid, pdei);
1364 static HRESULT WINAPI JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface,
1365 LPDIEFFECTINFOW pdei,
1368 JoystickImpl* This = (JoystickImpl*)iface;
1370 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1372 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1373 return linuxinput_get_info_W(This->joyfd, guid, pdei);
1379 /*******************************************************************************
1380 * GetForceFeedbackState - Get information about the device's FF state
1382 static HRESULT WINAPI JoystickAImpl_GetForceFeedbackState(
1383 LPDIRECTINPUTDEVICE8A iface,
1386 JoystickImpl* This = (JoystickImpl*)iface;
1388 TRACE("(this=%p,%p)\n", This, pdwOut);
1392 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1393 /* DIGFFS_STOPPED is the only mandatory flag to report */
1394 if (This->ff_state == FF_STATUS_STOPPED)
1395 (*pdwOut) |= DIGFFS_STOPPED;
1401 /*******************************************************************************
1402 * SendForceFeedbackCommand - Send a command to the device's FF system
1404 static HRESULT WINAPI JoystickAImpl_SendForceFeedbackCommand(
1405 LPDIRECTINPUTDEVICE8A iface,
1408 JoystickImpl* This = (JoystickImpl*)iface;
1409 TRACE("(this=%p,%d)\n", This, dwFlags);
1411 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1412 if (dwFlags == DISFFC_STOPALL) {
1413 /* Stop all effects */
1414 EffectListItem* itr = This->top_effect;
1416 IDirectInputEffect_Stop(itr->ref);
1419 } else if (dwFlags == DISFFC_RESET) {
1420 /* Stop, unload, release and free all effects */
1421 /* This returns the device to its "bare" state */
1422 while (This->top_effect) {
1423 EffectListItem* temp = This->top_effect;
1424 IDirectInputEffect_Stop(temp->ref);
1425 IDirectInputEffect_Unload(temp->ref);
1426 IDirectInputEffect_Release(temp->ref);
1427 This->top_effect = temp->next;
1428 HeapFree(GetProcessHeap(), 0, temp);
1430 } else if (dwFlags == DISFFC_PAUSE || dwFlags == DISFFC_CONTINUE) {
1431 FIXME("No support for Pause or Continue in linux\n");
1432 } else if (dwFlags == DISFFC_SETACTUATORSOFF
1433 || dwFlags == DISFFC_SETACTUATORSON) {
1434 FIXME("No direct actuator control in linux\n");
1436 FIXME("Unknown Force Feedback Command!\n");
1437 return DIERR_INVALIDPARAM;
1441 return DIERR_UNSUPPORTED;
1445 /*******************************************************************************
1446 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1447 * created for this device.
1449 static HRESULT WINAPI JoystickAImpl_EnumCreatedEffectObjects(
1450 LPDIRECTINPUTDEVICE8A iface,
1451 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1455 /* this function is safe to call on non-ff-enabled builds */
1457 JoystickImpl* This = (JoystickImpl*)iface;
1458 EffectListItem* itr = This->top_effect;
1459 TRACE("(this=%p,%p,%p,%d)\n", This, lpCallback, pvRef, dwFlags);
1462 return DIERR_INVALIDPARAM;
1465 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1468 (*lpCallback)(itr->ref, pvRef);
1475 static const IDirectInputDevice8AVtbl JoystickAvt =
1477 IDirectInputDevice2AImpl_QueryInterface,
1478 IDirectInputDevice2AImpl_AddRef,
1479 JoystickAImpl_Release,
1480 JoystickAImpl_GetCapabilities,
1481 JoystickAImpl_EnumObjects,
1482 JoystickAImpl_GetProperty,
1483 JoystickAImpl_SetProperty,
1484 JoystickAImpl_Acquire,
1485 JoystickAImpl_Unacquire,
1486 JoystickAImpl_GetDeviceState,
1487 IDirectInputDevice2AImpl_GetDeviceData,
1488 IDirectInputDevice2AImpl_SetDataFormat,
1489 IDirectInputDevice2AImpl_SetEventNotification,
1490 IDirectInputDevice2AImpl_SetCooperativeLevel,
1491 IDirectInputDevice2AImpl_GetObjectInfo,
1492 IDirectInputDevice2AImpl_GetDeviceInfo,
1493 IDirectInputDevice2AImpl_RunControlPanel,
1494 IDirectInputDevice2AImpl_Initialize,
1495 JoystickAImpl_CreateEffect,
1496 JoystickAImpl_EnumEffects,
1497 JoystickAImpl_GetEffectInfo,
1498 JoystickAImpl_GetForceFeedbackState,
1499 JoystickAImpl_SendForceFeedbackCommand,
1500 JoystickAImpl_EnumCreatedEffectObjects,
1501 IDirectInputDevice2AImpl_Escape,
1503 IDirectInputDevice2AImpl_SendDeviceData,
1504 IDirectInputDevice7AImpl_EnumEffectsInFile,
1505 IDirectInputDevice7AImpl_WriteEffectToFile,
1506 IDirectInputDevice8AImpl_BuildActionMap,
1507 IDirectInputDevice8AImpl_SetActionMap,
1508 IDirectInputDevice8AImpl_GetImageInfo
1511 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1512 # define XCAST(fun) (typeof(JoystickWvt.fun))
1514 # define XCAST(fun) (void*)
1517 static const IDirectInputDevice8WVtbl JoystickWvt =
1519 IDirectInputDevice2WImpl_QueryInterface,
1520 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1521 XCAST(Release)JoystickAImpl_Release,
1522 XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1523 JoystickWImpl_EnumObjects,
1524 XCAST(GetProperty)JoystickAImpl_GetProperty,
1525 XCAST(SetProperty)JoystickAImpl_SetProperty,
1526 XCAST(Acquire)JoystickAImpl_Acquire,
1527 XCAST(Unacquire)JoystickAImpl_Unacquire,
1528 XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1529 XCAST(GetDeviceData)IDirectInputDevice2AImpl_GetDeviceData,
1530 XCAST(SetDataFormat)IDirectInputDevice2AImpl_SetDataFormat,
1531 XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
1532 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1533 IDirectInputDevice2WImpl_GetObjectInfo,
1534 IDirectInputDevice2WImpl_GetDeviceInfo,
1535 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1536 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1537 XCAST(CreateEffect)JoystickAImpl_CreateEffect,
1538 JoystickWImpl_EnumEffects,
1539 JoystickWImpl_GetEffectInfo,
1540 XCAST(GetForceFeedbackState)JoystickAImpl_GetForceFeedbackState,
1541 XCAST(SendForceFeedbackCommand)JoystickAImpl_SendForceFeedbackCommand,
1542 XCAST(EnumCreatedEffectObjects)JoystickAImpl_EnumCreatedEffectObjects,
1543 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1544 XCAST(Poll)JoystickAImpl_Poll,
1545 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1546 IDirectInputDevice7WImpl_EnumEffectsInFile,
1547 IDirectInputDevice7WImpl_WriteEffectToFile,
1548 IDirectInputDevice8WImpl_BuildActionMap,
1549 IDirectInputDevice8WImpl_SetActionMap,
1550 IDirectInputDevice8WImpl_GetImageInfo
1554 #else /* HAVE_CORRECT_LINUXINPUT_H */
1556 const struct dinput_device joystick_linuxinput_device = {
1557 "Wine Linux-input joystick driver",
1564 #endif /* HAVE_CORRECT_LINUXINPUT_H */