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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
52 #include "wine/debug.h"
53 #include "wine/unicode.h"
59 #include "dinput_private.h"
60 #include "device_private.h"
62 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
64 #ifdef HAVE_CORRECT_LINUXINPUT_H
66 #define EVDEVPREFIX "/dev/input/event"
68 /* Wine joystick driver object instances */
69 #define WINE_JOYSTICK_AXIS_BASE 0
70 #define WINE_JOYSTICK_BUTTON_BASE 8
72 typedef struct EffectListItem EffectListItem;
75 LPDIRECTINPUTEFFECT ref;
76 struct EffectListItem* next;
79 /* implemented in effect_linuxinput.c */
80 HRESULT linuxinput_create_effect(int* fd, REFGUID rguid, LPDIRECTINPUTEFFECT* peff);
81 HRESULT linuxinput_get_info_A(int fd, REFGUID rguid, LPDIEFFECTINFOA info);
82 HRESULT linuxinput_get_info_W(int fd, REFGUID rguid, LPDIEFFECTINFOW info);
84 typedef struct JoystickImpl JoystickImpl;
85 static const IDirectInputDevice8AVtbl JoystickAvt;
86 static const IDirectInputDevice8WVtbl JoystickWvt;
94 /* The 'parent' DInput */
95 IDirectInputImpl *dinput;
97 /* joystick private */
98 /* what range and deadzone the game wants */
99 LONG wantmin[ABS_MAX];
100 LONG wantmax[ABS_MAX];
103 /* autodetecting ranges per axe by following movement */
104 LONG havemax[ABS_MAX];
105 LONG havemin[ABS_MAX];
111 LPDIDEVICEOBJECTDATA data_queue;
112 int queue_head, queue_tail, queue_len;
116 /* Force feedback variables */
119 EffectListItem* top_effect;
122 /* data returned by the EVIOCGABS() ioctl */
123 int axes[ABS_MAX][5];
124 /* LUT for KEY_ to offset in rgbButtons */
125 BYTE buttons[KEY_MAX];
130 #define AXE_ABSFUZZ 3
131 #define AXE_ABSFLAT 4
134 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
135 BYTE evbits[(EV_MAX+7)/8];
136 BYTE absbits[(ABS_MAX+7)/8];
137 BYTE keybits[(KEY_MAX+7)/8];
138 BYTE ffbits[(FF_MAX+7)/8];
141 /* This GUID is slightly different from the linux joystick one. Take note. */
142 static GUID DInput_Wine_Joystick_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
146 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
149 static void fake_current_js_state(JoystickImpl *ji);
150 static int find_property_offset(JoystickImpl *This, LPCDIPROPHEADER ph);
152 #define test_bit(arr,bit) (((BYTE*)arr)[bit>>3]&(1<<(bit&7)))
154 static int joydev_have(BOOL require_ff)
156 int i, fd, flags, num_effects;
161 BYTE absbits[(ABS_MAX+7)/8],keybits[(KEY_MAX+7)/8];
162 BYTE evbits[(EV_MAX+7)/8],ffbits[(FF_MAX+7)/8];
164 sprintf(buf,EVDEVPREFIX"%d",i);
171 if (-1!=(fd=open(buf,flags))) {
172 if (-1==ioctl(fd,EVIOCGBIT(EV_ABS,sizeof(absbits)),absbits)) {
173 perror("EVIOCGBIT EV_ABS");
177 if (-1==ioctl(fd,EVIOCGBIT(EV_KEY,sizeof(keybits)),keybits)) {
178 perror("EVIOCGBIT EV_KEY");
183 /* test for force feedback if it's required */
185 if ((-1==ioctl(fd,EVIOCGBIT(0,sizeof(evbits)),evbits))) {
186 perror("EVIOCGBIT 0");
190 if ( (!test_bit(evbits,EV_FF))
191 || (-1==ioctl(fd,EVIOCGBIT(EV_FF,sizeof(ffbits)),ffbits))
192 || (-1==ioctl(fd,EVIOCGEFFECTS,&num_effects))
193 || (num_effects <= 0)) {
199 /* A true joystick has at least axis X and Y, and at least 1
200 * button. copied from linux/drivers/input/joydev.c */
201 if (test_bit(absbits,ABS_X) && test_bit(absbits,ABS_Y) &&
202 ( test_bit(keybits,BTN_TRIGGER) ||
203 test_bit(keybits,BTN_A) ||
204 test_bit(keybits,BTN_1)
207 FIXME("found a joystick at %s!\n",buf);
212 if (havejoy || (errno==ENODEV))
218 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
225 if (!((dwDevType == 0) ||
226 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
227 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
230 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
231 if (dwFlags & DIEDFL_FORCEFEEDBACK)
235 havejoy = joydev_have(dwFlags & DIEDFL_FORCEFEEDBACK);
240 TRACE("Enumerating the linuxinput Joystick device\n");
242 /* Return joystick */
243 lpddi->guidInstance = GUID_Joystick;
244 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
246 lpddi->guidFFDriver = GUID_NULL;
247 if (version >= 0x0800)
248 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
250 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
252 strcpy(lpddi->tszInstanceName, "Joystick");
253 /* ioctl JSIOCGNAME(len) */
254 strcpy(lpddi->tszProductName, "Wine Joystick");
258 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
265 if (!((dwDevType == 0) ||
266 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
267 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
270 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
271 if (dwFlags & DIEDFL_FORCEFEEDBACK)
275 havejoy = joydev_have(dwFlags & DIEDFL_FORCEFEEDBACK);
280 TRACE("Enumerating the linuxinput Joystick device\n");
282 /* Return joystick */
283 lpddi->guidInstance = GUID_Joystick;
284 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
286 lpddi->guidFFDriver = GUID_NULL;
287 if (version >= 0x0800)
288 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
290 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
292 MultiByteToWideChar(CP_ACP, 0, "Joystick", -1, lpddi->tszInstanceName, MAX_PATH);
293 /* ioctl JSIOCGNAME(len) */
294 MultiByteToWideChar(CP_ACP, 0, "Wine Joystick", -1, lpddi->tszProductName, MAX_PATH);
298 static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput)
300 JoystickImpl* newDevice;
303 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
304 newDevice->lpVtbl = jvt;
306 newDevice->joyfd = -1;
307 newDevice->dinput = dinput;
308 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
309 newDevice->ff_state = FF_STATUS_STOPPED;
311 memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
312 for (i=0;i<ABS_MAX;i++) {
313 newDevice->wantmin[i] = -32768;
314 newDevice->wantmax[i] = 32767;
316 * direct input defines a default for the deadzone somewhere; but as long
317 * as in map_axis the code for the dead zone is commented out its no
320 newDevice->deadz[i] = 0;
322 fake_current_js_state(newDevice);
326 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
330 havejoy = joydev_have(FALSE);
333 return DIERR_DEVICENOTREG;
335 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
336 (IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) {
337 if ((riid == NULL) ||
338 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
339 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
340 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
341 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
342 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput);
343 TRACE("Creating a Joystick device (%p)\n", *pdev);
346 return DIERR_NOINTERFACE;
349 return DIERR_DEVICENOTREG;
353 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
357 havejoy = joydev_have(FALSE);
360 return DIERR_DEVICENOTREG;
362 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
363 (IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) {
364 if ((riid == NULL) ||
365 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
366 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
367 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
368 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
369 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput);
370 TRACE("Creating a Joystick device (%p)\n", *pdev);
373 return DIERR_NOINTERFACE;
376 return DIERR_DEVICENOTREG;
379 const struct dinput_device joystick_linuxinput_device = {
380 "Wine Linux-input joystick driver",
383 joydev_create_deviceA,
384 joydev_create_deviceW
387 /******************************************************************************
390 static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
392 JoystickImpl *This = (JoystickImpl *)iface;
395 ref = InterlockedDecrement(&(This->ref));
399 /* Reset the FF state, free all effects, etc */
400 IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
402 /* Free the data queue */
403 HeapFree(GetProcessHeap(),0,This->data_queue);
405 /* Free the DataFormat */
406 HeapFree(GetProcessHeap(), 0, This->df);
408 HeapFree(GetProcessHeap(),0,This);
412 /******************************************************************************
413 * SetDataFormat : the application can choose the format of the data
414 * the device driver sends back with GetDeviceState.
416 static HRESULT WINAPI JoystickAImpl_SetDataFormat(
417 LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
420 JoystickImpl *This = (JoystickImpl *)iface;
422 TRACE("(this=%p,%p)\n",This,df);
425 WARN("invalid pointer\n");
429 if (df->dwSize != sizeof(*df)) {
430 WARN("invalid argument\n");
431 return DIERR_INVALIDPARAM;
434 _dump_DIDATAFORMAT(df);
436 if (This->joyfd!=-1) {
438 return DIERR_ACQUIRED;
441 /* Store the new data format */
442 This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
443 if (This->df==NULL) {
444 return DIERR_OUTOFMEMORY;
446 memcpy(This->df, df, df->dwSize);
447 This->df->rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
448 if (This->df->rgodf==NULL) {
449 HeapFree(GetProcessHeap(), 0, This->df);
450 return DIERR_OUTOFMEMORY;
452 memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
457 /******************************************************************************
458 * Acquire : gets exclusive control of the joystick
460 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
463 JoystickImpl *This = (JoystickImpl *)iface;
465 BOOL readonly = TRUE;
467 TRACE("(this=%p)\n",This);
471 sprintf(buf,EVDEVPREFIX"%d",i);
472 if (-1==(This->joyfd=open(buf,O_RDWR))) {
473 if (-1==(This->joyfd=open(buf,O_RDONLY))) {
474 /* Couldn't open the device at all */
476 return DIERR_NOTFOUND;
481 /* Couldn't open in r/w but opened in read-only. */
482 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n",buf);
486 /* Opened device in read-write */
489 if ((-1!=ioctl(This->joyfd,EVIOCGBIT(0,sizeof(This->evbits)),This->evbits)) &&
490 (-1!=ioctl(This->joyfd,EVIOCGBIT(EV_ABS,sizeof(This->absbits)),This->absbits)) &&
491 (-1!=ioctl(This->joyfd,EVIOCGBIT(EV_KEY,sizeof(This->keybits)),This->keybits)) &&
492 (test_bit(This->absbits,ABS_X) && test_bit(This->absbits,ABS_Y) &&
493 (test_bit(This->keybits,BTN_TRIGGER)||
494 test_bit(This->keybits,BTN_A) ||
495 test_bit(This->keybits,BTN_1)
504 return DIERR_NOTFOUND;
506 This->has_ff = FALSE;
507 This->num_effects = 0;
509 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
510 if (!readonly && test_bit(This->evbits, EV_FF)) {
511 if (-1!=ioctl(This->joyfd,EVIOCGBIT(EV_FF,sizeof(This->ffbits)),This->ffbits)) {
512 if (-1!=ioctl(This->joyfd,EVIOCGEFFECTS,&This->num_effects)
513 && This->num_effects > 0) {
515 TRACE("Joystick seems to be capable of force feedback.\n");
518 TRACE("Joystick does not support any effects, disabling force feedback.\n");
522 TRACE("Could not get EV_FF bits; disabling force feedback.\n");
526 TRACE("Force feedback disabled (device is readonly or joystick incapable).\n");
530 for (i=0;i<ABS_MAX;i++) {
531 if (test_bit(This->absbits,i)) {
532 if (-1==ioctl(This->joyfd,EVIOCGABS(i),&(This->axes[i])))
534 TRACE("axe %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
536 This->axes[i][AXE_ABS],
537 This->axes[i][AXE_ABSMIN],
538 This->axes[i][AXE_ABSMAX],
539 This->axes[i][AXE_ABSFUZZ],
540 This->axes[i][AXE_ABSFLAT]
542 This->havemin[i] = This->axes[i][AXE_ABSMIN];
543 This->havemax[i] = This->axes[i][AXE_ABSMAX];
547 for (i=0;i<KEY_MAX;i++) {
548 if (test_bit(This->keybits,i)) {
549 TRACE("button %d: %d\n", i, buttons);
550 This->buttons[i] = 0x80 | buttons;
555 fake_current_js_state(This);
560 /******************************************************************************
561 * Unacquire : frees the joystick
563 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
565 JoystickImpl *This = (JoystickImpl *)iface;
567 TRACE("(this=%p)\n",This);
568 if (This->joyfd!=-1) {
578 * This maps the read value (from the input event) to a value in the
579 * 'wanted' range. It also autodetects the possible range of the axe and
580 * adapts values accordingly.
583 map_axis(JoystickImpl* This, int axis, int val) {
584 int xmin = This->axes[axis][AXE_ABSMIN];
585 int xmax = This->axes[axis][AXE_ABSMAX];
586 int hmax = This->havemax[axis];
587 int hmin = This->havemin[axis];
588 int wmin = This->wantmin[axis];
589 int wmax = This->wantmax[axis];
592 if (val > hmax) This->havemax[axis] = hmax = val;
593 if (val < hmin) This->havemin[axis] = hmin = val;
595 if (xmin == xmax) return val;
597 /* map the value from the hmin-hmax range into the wmin-wmax range */
598 ret = ((val-hmin) * (wmax-wmin)) / (hmax-hmin) + wmin;
600 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);
603 /* deadzone doesn't work comfortably enough right now. needs more testing*/
604 if ((ret > -deadz/2 ) && (ret < deadz/2)) {
605 FIXME("%d in deadzone, return mid.\n",val);
606 return (wmax-wmin)/2+wmin;
613 * set the current state of the js device as it would be with the middle
616 static void fake_current_js_state(JoystickImpl *ji)
618 ji->js.lX = map_axis(ji, ABS_X, ji->axes[ABS_X ][AXE_ABS]);
619 ji->js.lY = map_axis(ji, ABS_Y, ji->axes[ABS_Y ][AXE_ABS]);
620 ji->js.lZ = map_axis(ji, ABS_Z, ji->axes[ABS_Z ][AXE_ABS]);
621 ji->js.lRx = map_axis(ji, ABS_RX, ji->axes[ABS_RX][AXE_ABS]);
622 ji->js.lRy = map_axis(ji, ABS_RY, ji->axes[ABS_RY][AXE_ABS]);
623 ji->js.lRz = map_axis(ji, ABS_RZ, ji->axes[ABS_RZ][AXE_ABS]);
624 ji->js.rglSlider[0] = map_axis(ji, ABS_THROTTLE, ji->axes[ABS_THROTTLE][AXE_ABS]);
625 ji->js.rglSlider[1] = map_axis(ji, ABS_RUDDER, ji->axes[ABS_RUDDER ][AXE_ABS]);
628 static int find_property_offset(JoystickImpl *This, LPCDIPROPHEADER ph)
633 for (i=0; i<This->df->dwNumObjs; i++) {
634 if (This->df->rgodf[i].dwOfs == ph->dwObj) {
640 /* XXX: this is a hack - see below */
641 c = DIDFT_GETINSTANCE(ph->dwObj)>>WINE_JOYSTICK_AXIS_BASE;
642 for (i=0; (c&1)==0 && i<0x0F; i++) {
649 /* XXX - the following part won't work with LiveForSpeed
650 * - the game sets the dwTypes to something else then
651 * the ddoi.dwType set in EnumObjects
654 for (i=0; i<This->df->dwNumObjs; i++) {
655 TRACE("dwType='%08x'\n", This->df->rgodf[i].dwType);
656 if ((This->df->rgodf[i].dwType & 0x00ffffff) == (ph->dwObj & 0x00ffffff)) {
663 FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
669 static void joy_polldev(JoystickImpl *This) {
672 struct input_event ie;
679 memset(&tv,0,sizeof(tv));
681 FD_SET(This->joyfd,&readfds);
683 if (1>select(This->joyfd+1,&readfds,NULL,NULL,&tv))
686 /* we have one event, so we can read */
687 if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
690 TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
692 case EV_KEY: /* button */
693 btn = This->buttons[ie.code];
694 TRACE("(%p) %d -> %d\n", This, ie.code, btn);
697 This->js.rgbButtons[btn] = ie.value?0x80:0x00;
698 GEN_EVENT(DIJOFS_BUTTON(btn),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
704 This->js.lX = map_axis(This,ABS_X,ie.value);
705 GEN_EVENT(DIJOFS_X,This->js.lX,ie.time.tv_usec,(This->dinput->evsequence)++);
708 This->js.lY = map_axis(This,ABS_Y,ie.value);
709 GEN_EVENT(DIJOFS_Y,This->js.lY,ie.time.tv_usec,(This->dinput->evsequence)++);
712 This->js.lZ = map_axis(This,ABS_Z,ie.value);
713 GEN_EVENT(DIJOFS_Z,This->js.lZ,ie.time.tv_usec,(This->dinput->evsequence)++);
716 This->js.lRx = map_axis(This,ABS_RX,ie.value);
717 GEN_EVENT(DIJOFS_RX,This->js.lRx,ie.time.tv_usec,(This->dinput->evsequence)++);
720 This->js.lRy = map_axis(This,ABS_RY,ie.value);
721 GEN_EVENT(DIJOFS_RY,This->js.lRy,ie.time.tv_usec,(This->dinput->evsequence)++);
724 This->js.lRz = map_axis(This,ABS_RZ,ie.value);
725 GEN_EVENT(DIJOFS_RZ,This->js.lRz,ie.time.tv_usec,(This->dinput->evsequence)++);
728 This->js.rglSlider[0] = map_axis(This,ABS_THROTTLE,ie.value);
729 GEN_EVENT(DIJOFS_SLIDER(0),This->js.rglSlider[0],ie.time.tv_usec,(This->dinput->evsequence)++);
732 This->js.rglSlider[1] = map_axis(This,ABS_RUDDER,ie.value);
733 GEN_EVENT(DIJOFS_SLIDER(1),This->js.rglSlider[1],ie.time.tv_usec,(This->dinput->evsequence)++);
736 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie.code,ie.value);
740 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
742 This->ff_state = ie.value;
746 /* there is nothing to do */
749 FIXME("joystick cannot handle type %d event (code %d)\n",ie.type,ie.code);
755 /******************************************************************************
756 * GetDeviceState : returns the "state" of the joystick.
759 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
760 LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
762 JoystickImpl *This = (JoystickImpl *)iface;
766 TRACE("(this=%p,0x%08lx,%p)\n",This,len,ptr);
767 if ((len != sizeof(DIJOYSTATE)) && (len != sizeof(DIJOYSTATE2))) {
768 FIXME("len %ld is not sizeof(DIJOYSTATE) or DIJOYSTATE2, unsupported format.\n",len);
771 memcpy(ptr,&(This->js),len);
772 This->queue_head = 0;
773 This->queue_tail = 0;
777 /******************************************************************************
778 * GetDeviceData : gets buffered input data.
780 static HRESULT WINAPI JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
782 LPDIDEVICEOBJECTDATA dod,
786 JoystickImpl *This = (JoystickImpl *)iface;
791 TRACE("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx)\n",This,dodsize,*entries,flags);
793 if (This->joyfd==-!1) {
794 WARN("not acquired\n");
795 return DIERR_NOTACQUIRED;
799 if (flags & DIGDD_PEEK)
800 FIXME("DIGDD_PEEK\n");
802 len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0)
803 + (This->queue_head - This->queue_tail);
809 TRACE("Application discarding %ld event(s).\n", len);
812 nqtail = This->queue_tail + len;
813 while (nqtail >= This->queue_len)
814 nqtail -= This->queue_len;
816 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
817 ERR("Wrong structure size !\n");
818 return DIERR_INVALIDPARAM;
822 TRACE("Application retrieving %ld event(s).\n", len);
825 nqtail = This->queue_tail;
827 /* Copy the buffered data into the application queue */
828 memcpy((char *)dod + *entries * dodsize, This->data_queue + nqtail, dodsize);
829 /* Advance position */
831 if (nqtail >= This->queue_len)
832 nqtail -= This->queue_len;
838 if (This->overflow) {
839 hr = DI_BUFFEROVERFLOW;
840 if (!(flags & DIGDD_PEEK)) {
841 This->overflow = FALSE;
845 if (!(flags & DIGDD_PEEK))
846 This->queue_tail = nqtail;
851 /******************************************************************************
852 * SetProperty : change input device properties
854 static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
858 JoystickImpl *This = (JoystickImpl *)iface;
861 WARN("invalid argument\n");
862 return DIERR_INVALIDPARAM;
865 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
866 TRACE("ph.dwSize = %ld, ph.dwHeaderSize =%ld, ph.dwObj = %ld, ph.dwHow= %ld\n",ph->dwSize, ph->dwHeaderSize,ph->dwObj,ph->dwHow);
868 if (!HIWORD(rguid)) {
869 switch (LOWORD(rguid)) {
870 case (DWORD) DIPROP_BUFFERSIZE: {
871 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
873 TRACE("buffersize = %ld\n",pd->dwData);
874 if (This->data_queue) {
875 This->data_queue = HeapReAlloc(GetProcessHeap(),0, This->data_queue, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
877 This->data_queue = HeapAlloc(GetProcessHeap(),0, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
879 This->queue_head = 0;
880 This->queue_tail = 0;
881 This->queue_len = pd->dwData;
884 case (DWORD)DIPROP_RANGE: {
885 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
887 if (ph->dwHow == DIPH_DEVICE) {
889 TRACE("proprange(%ld,%ld) all\n",pr->lMin,pr->lMax);
890 for (i = 0; i < This->df->dwNumObjs; i++) {
891 This->wantmin[i] = pr->lMin;
892 This->wantmax[i] = pr->lMax;
895 int obj = find_property_offset(This, ph);
896 TRACE("proprange(%ld,%ld) obj=%d\n",pr->lMin,pr->lMax,obj);
898 This->wantmin[obj] = pr->lMin;
899 This->wantmax[obj] = pr->lMax;
904 case (DWORD)DIPROP_DEADZONE: {
905 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
906 if (ph->dwHow == DIPH_DEVICE) {
908 TRACE("deadzone(%ld) all\n",pd->dwData);
909 for (i = 0; i < This->df->dwNumObjs; i++) {
910 This->deadz[i] = pd->dwData;
913 int obj = find_property_offset(This, ph);
914 TRACE("deadzone(%ld) obj=%d\n",pd->dwData,obj);
916 This->deadz[obj] = pd->dwData;
922 FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
926 fake_current_js_state(This);
930 /******************************************************************************
931 * SetEventNotification : specifies event to be sent on state change
933 static HRESULT WINAPI JoystickAImpl_SetEventNotification(
934 LPDIRECTINPUTDEVICE8A iface, HANDLE hnd
936 JoystickImpl *This = (JoystickImpl *)iface;
938 TRACE("(this=%p,%p)\n",This,hnd);
943 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
944 LPDIRECTINPUTDEVICE8A iface,
945 LPDIDEVCAPS lpDIDevCaps)
947 JoystickImpl *This = (JoystickImpl *)iface;
948 int xfd = This->joyfd;
951 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
954 WARN("invalid pointer\n");
958 if (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) {
959 WARN("invalid argument\n");
960 return DIERR_INVALIDPARAM;
964 /* yes, games assume we return something, even if unacquired */
965 JoystickAImpl_Acquire(iface);
968 lpDIDevCaps->dwFlags = DIDC_ATTACHED;
969 if (This->dinput->dwVersion >= 0x0800)
970 lpDIDevCaps->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
972 lpDIDevCaps->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
975 for (i=0;i<ABS_MAX;i++) if (test_bit(This->absbits,i)) axes++;
977 for (i=0;i<KEY_MAX;i++) if (test_bit(This->keybits,i)) buttons++;
980 lpDIDevCaps->dwFlags |= DIDC_FORCEFEEDBACK;
982 lpDIDevCaps->dwAxes = axes;
983 lpDIDevCaps->dwButtons = buttons;
986 JoystickAImpl_Unacquire(iface);
992 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface) {
993 JoystickImpl *This = (JoystickImpl *)iface;
994 TRACE("(%p)\n",This);
996 if (This->joyfd==-1) {
997 return DIERR_NOTACQUIRED;
1004 /******************************************************************************
1005 * EnumObjects : enumerate the different buttons and axis...
1007 static HRESULT WINAPI JoystickAImpl_EnumObjects(
1008 LPDIRECTINPUTDEVICE8A iface,
1009 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
1013 JoystickImpl *This = (JoystickImpl *)iface;
1014 DIDEVICEOBJECTINSTANCEA ddoi;
1015 int xfd = This->joyfd;
1017 TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
1018 if (TRACE_ON(dinput)) {
1019 TRACE(" - flags = ");
1020 _dump_EnumObjects_flags(dwFlags);
1024 /* We need to work even if we're not yet acquired */
1026 IDirectInputDevice8_Acquire(iface);
1028 /* Only the fields till dwFFMaxForce are relevant */
1029 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
1031 /* For the joystick, do as is done in the GetCapabilities function */
1032 /* FIXME: needs more items */
1033 if ((dwFlags == DIDFT_ALL) ||
1034 (dwFlags & DIDFT_AXIS)) {
1037 for (i = 0; i < ABS_MAX; i++) {
1038 if (!test_bit(This->absbits,i)) continue;
1042 ddoi.guidType = GUID_XAxis;
1043 ddoi.dwOfs = DIJOFS_X;
1046 ddoi.guidType = GUID_YAxis;
1047 ddoi.dwOfs = DIJOFS_Y;
1050 ddoi.guidType = GUID_ZAxis;
1051 ddoi.dwOfs = DIJOFS_Z;
1054 ddoi.guidType = GUID_RxAxis;
1055 ddoi.dwOfs = DIJOFS_RX;
1058 ddoi.guidType = GUID_RyAxis;
1059 ddoi.dwOfs = DIJOFS_RY;
1062 ddoi.guidType = GUID_RzAxis;
1063 ddoi.dwOfs = DIJOFS_RZ;
1066 ddoi.guidType = GUID_Slider;
1067 ddoi.dwOfs = DIJOFS_SLIDER(0);
1070 ddoi.guidType = GUID_Slider;
1071 ddoi.dwOfs = DIJOFS_SLIDER(1);
1074 FIXME("unhandled abs axis %d, ignoring!\n",i);
1076 ddoi.dwType = DIDFT_MAKEINSTANCE((1<<i) << WINE_JOYSTICK_AXIS_BASE) | DIDFT_ABSAXIS;
1077 /* Linux event force feedback supports only (and always) x and y axes */
1078 if (i == ABS_X || i == ABS_Y) {
1080 ddoi.dwFlags |= DIDOI_FFACTUATOR;
1082 sprintf(ddoi.tszName, "%d-Axis", i);
1083 _dump_OBJECTINSTANCEA(&ddoi);
1084 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) {
1085 /* return to unaquired state if that's where we were */
1087 IDirectInputDevice8_Unacquire(iface);
1093 if ((dwFlags == DIDFT_ALL) ||
1094 (dwFlags & DIDFT_BUTTON)) {
1097 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
1099 ddoi.guidType = GUID_Button;
1101 for (i = 0; i < KEY_MAX; i++) {
1102 if (!test_bit(This->keybits,i)) continue;
1103 ddoi.dwOfs = DIJOFS_BUTTON(btncount);
1104 ddoi.dwType = DIDFT_MAKEINSTANCE(btncount << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
1105 sprintf(ddoi.tszName, "%d-Button", btncount);
1107 _dump_OBJECTINSTANCEA(&ddoi);
1108 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) {
1109 /* return to unaquired state if that's where we were */
1111 IDirectInputDevice8_Unacquire(iface);
1117 /* return to unaquired state if that's where we were */
1119 IDirectInputDevice8_Unacquire(iface);
1124 static HRESULT WINAPI JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
1125 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
1129 JoystickImpl *This = (JoystickImpl *)iface;
1131 device_enumobjects_AtoWcb_data data;
1133 data.lpCallBack = lpCallback;
1134 data.lpvRef = lpvRef;
1136 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
1139 /******************************************************************************
1140 * GetProperty : get input device properties
1142 static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
1144 LPDIPROPHEADER pdiph)
1146 JoystickImpl *This = (JoystickImpl *)iface;
1148 TRACE("(this=%p,%s,%p)\n",
1149 iface, debugstr_guid(rguid), pdiph);
1151 if (TRACE_ON(dinput))
1152 _dump_DIPROPHEADER(pdiph);
1154 if (!HIWORD(rguid)) {
1155 switch (LOWORD(rguid)) {
1156 case (DWORD) DIPROP_BUFFERSIZE: {
1157 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1159 TRACE(" return buffersize = %d\n",This->queue_len);
1160 pd->dwData = This->queue_len;
1164 case (DWORD) DIPROP_RANGE: {
1165 /* LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph; */
1166 if ((pdiph->dwHow == DIPH_BYID) &&
1167 (pdiph->dwObj & DIDFT_ABSAXIS)) {
1168 /* The app is querying the current range of the axis : return the lMin and lMax values */
1169 FIXME("unimplemented axis range query.\n");
1176 FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
1185 /******************************************************************************
1186 * CreateEffect - Create a new FF effect with the specified params
1188 static HRESULT WINAPI JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface,
1191 LPDIRECTINPUTEFFECT *ppdef,
1192 LPUNKNOWN pUnkOuter)
1194 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1195 EffectListItem* new = NULL;
1196 HRESULT retval = DI_OK;
1199 JoystickImpl* This = (JoystickImpl*)iface;
1200 TRACE("(this=%p,%p,%p,%p,%p)\n", This, rguid, lpeff, ppdef, pUnkOuter);
1202 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1203 TRACE("not available (compiled w/o ff support)\n");
1208 new = malloc(sizeof(EffectListItem));
1209 new->next = This->top_effect;
1210 This->top_effect = new;
1212 retval = linuxinput_create_effect(&(This->joyfd), rguid, &(new->ref));
1213 if (retval != DI_OK)
1217 retval = IDirectInputEffect_SetParameters(new->ref, lpeff, 0);
1218 if (retval != DI_OK && retval != DI_DOWNLOADSKIPPED)
1223 if (pUnkOuter != NULL)
1224 FIXME("Interface aggregation not implemented.\n");
1228 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1231 /*******************************************************************************
1232 * EnumEffects - Enumerate available FF effects
1234 static HRESULT WINAPI JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface,
1235 LPDIENUMEFFECTSCALLBACKA lpCallback,
1239 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1240 DIEFFECTINFOA dei; /* feif */
1241 DWORD type = DIEFT_GETTYPE(dwEffType);
1242 JoystickImpl* This = (JoystickImpl*)iface;
1243 int xfd = This->joyfd;
1245 TRACE("(this=%p,%p,%ld) type=%ld fd=%d\n", This, pvRef, dwEffType, type, xfd);
1247 dei.dwSize = sizeof(DIEFFECTINFOA);
1249 /* We need to return something even if we're not yet acquired */
1251 IDirectInputDevice8_Acquire(iface);
1253 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1254 && test_bit(This->ffbits, FF_CONSTANT)) {
1255 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1256 (*lpCallback)(&dei, pvRef);
1259 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1260 && test_bit(This->ffbits, FF_PERIODIC)) {
1261 if (test_bit(This->ffbits, FF_SQUARE)) {
1262 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1263 (*lpCallback)(&dei, pvRef);
1265 if (test_bit(This->ffbits, FF_SINE)) {
1266 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1267 (*lpCallback)(&dei, pvRef);
1269 if (test_bit(This->ffbits, FF_TRIANGLE)) {
1270 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1271 (*lpCallback)(&dei, pvRef);
1273 if (test_bit(This->ffbits, FF_SAW_UP)) {
1274 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1275 (*lpCallback)(&dei, pvRef);
1277 if (test_bit(This->ffbits, FF_SAW_DOWN)) {
1278 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1279 (*lpCallback)(&dei, pvRef);
1283 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1284 && test_bit(This->ffbits, FF_RAMP)) {
1285 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1286 (*lpCallback)(&dei, pvRef);
1289 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1290 if (test_bit(This->ffbits, FF_SPRING)) {
1291 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1292 (*lpCallback)(&dei, pvRef);
1294 if (test_bit(This->ffbits, FF_DAMPER)) {
1295 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1296 (*lpCallback)(&dei, pvRef);
1298 if (test_bit(This->ffbits, FF_INERTIA)) {
1299 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1300 (*lpCallback)(&dei, pvRef);
1302 if (test_bit(This->ffbits, FF_FRICTION)) {
1303 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1304 (*lpCallback)(&dei, pvRef);
1308 /* return to unaquired state if that's where it was */
1310 IDirectInputDevice8_Unacquire(iface);
1316 static HRESULT WINAPI JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface,
1317 LPDIENUMEFFECTSCALLBACKW lpCallback,
1321 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1322 /* seems silly to duplicate all this code but all the structures and functions
1323 * are actually different (A/W) */
1324 DIEFFECTINFOW dei; /* feif */
1325 DWORD type = DIEFT_GETTYPE(dwEffType);
1326 JoystickImpl* This = (JoystickImpl*)iface;
1327 int xfd = This->joyfd;
1329 TRACE("(this=%p,%p,%ld) type=%ld fd=%d\n", This, pvRef, dwEffType, type, xfd);
1331 dei.dwSize = sizeof(DIEFFECTINFOW);
1333 /* We need to return something even if we're not yet acquired */
1335 IDirectInputDevice8_Acquire(iface);
1337 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1338 && test_bit(This->ffbits, FF_CONSTANT)) {
1339 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1340 (*lpCallback)(&dei, pvRef);
1343 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1344 && test_bit(This->ffbits, FF_PERIODIC)) {
1345 if (test_bit(This->ffbits, FF_SQUARE)) {
1346 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1347 (*lpCallback)(&dei, pvRef);
1349 if (test_bit(This->ffbits, FF_SINE)) {
1350 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1351 (*lpCallback)(&dei, pvRef);
1353 if (test_bit(This->ffbits, FF_TRIANGLE)) {
1354 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1355 (*lpCallback)(&dei, pvRef);
1357 if (test_bit(This->ffbits, FF_SAW_UP)) {
1358 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1359 (*lpCallback)(&dei, pvRef);
1361 if (test_bit(This->ffbits, FF_SAW_DOWN)) {
1362 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1363 (*lpCallback)(&dei, pvRef);
1367 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1368 && test_bit(This->ffbits, FF_RAMP)) {
1369 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1370 (*lpCallback)(&dei, pvRef);
1373 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1374 if (test_bit(This->ffbits, FF_SPRING)) {
1375 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1376 (*lpCallback)(&dei, pvRef);
1378 if (test_bit(This->ffbits, FF_DAMPER)) {
1379 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1380 (*lpCallback)(&dei, pvRef);
1382 if (test_bit(This->ffbits, FF_INERTIA)) {
1383 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1384 (*lpCallback)(&dei, pvRef);
1386 if (test_bit(This->ffbits, FF_FRICTION)) {
1387 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1388 (*lpCallback)(&dei, pvRef);
1392 /* return to unaquired state if that's where it was */
1394 IDirectInputDevice8_Unacquire(iface);
1400 /*******************************************************************************
1401 * GetEffectInfo - Get information about a particular effect
1403 static HRESULT WINAPI JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface,
1404 LPDIEFFECTINFOA pdei,
1407 JoystickImpl* This = (JoystickImpl*)iface;
1409 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1411 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1412 return linuxinput_get_info_A(This->joyfd, guid, pdei);
1418 static HRESULT WINAPI JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface,
1419 LPDIEFFECTINFOW pdei,
1422 JoystickImpl* This = (JoystickImpl*)iface;
1424 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1426 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1427 return linuxinput_get_info_W(This->joyfd, guid, pdei);
1433 /*******************************************************************************
1434 * GetForceFeedbackState - Get information about the device's FF state
1436 static HRESULT WINAPI JoystickAImpl_GetForceFeedbackState(
1437 LPDIRECTINPUTDEVICE8A iface,
1440 JoystickImpl* This = (JoystickImpl*)iface;
1442 TRACE("(this=%p,%p)\n", This, pdwOut);
1446 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1447 /* DIGFFS_STOPPED is the only mandatory flag to report */
1448 if (This->ff_state == FF_STATUS_STOPPED)
1449 (*pdwOut) |= DIGFFS_STOPPED;
1455 /*******************************************************************************
1456 * SendForceFeedbackCommand - Send a command to the device's FF system
1458 static HRESULT WINAPI JoystickAImpl_SendForceFeedbackCommand(
1459 LPDIRECTINPUTDEVICE8A iface,
1462 JoystickImpl* This = (JoystickImpl*)iface;
1463 TRACE("(this=%p,%ld)\n", This, dwFlags);
1465 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1466 if (dwFlags == DISFFC_STOPALL) {
1467 /* Stop all effects */
1468 EffectListItem* itr = This->top_effect;
1470 IDirectInputEffect_Stop(itr->ref);
1473 } else if (dwFlags == DISFFC_RESET) {
1474 /* Stop, unload, release and free all effects */
1475 /* This returns the device to its "bare" state */
1476 while (This->top_effect) {
1477 EffectListItem* temp = This->top_effect;
1478 IDirectInputEffect_Stop(temp->ref);
1479 IDirectInputEffect_Unload(temp->ref);
1480 IDirectInputEffect_Release(temp->ref);
1481 This->top_effect = temp->next;
1484 } else if (dwFlags == DISFFC_PAUSE || dwFlags == DISFFC_CONTINUE) {
1485 FIXME("No support for Pause or Continue in linux\n");
1486 } else if (dwFlags == DISFFC_SETACTUATORSOFF
1487 || dwFlags == DISFFC_SETACTUATORSON) {
1488 FIXME("No direct actuator control in linux\n");
1490 FIXME("Unknown Force Feedback Command!\n");
1491 return DIERR_INVALIDPARAM;
1495 return DIERR_UNSUPPORTED;
1499 /*******************************************************************************
1500 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1501 * created for this device.
1503 static HRESULT WINAPI JoystickAImpl_EnumCreatedEffectObjects(
1504 LPDIRECTINPUTDEVICE8A iface,
1505 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1509 /* this function is safe to call on non-ff-enabled builds */
1511 JoystickImpl* This = (JoystickImpl*)iface;
1512 EffectListItem* itr = This->top_effect;
1513 TRACE("(this=%p,%p,%p,%ld)\n", This, lpCallback, pvRef, dwFlags);
1516 return DIERR_INVALIDPARAM;
1519 FIXME("Flags specified, but no flags exist yet (DX9)!");
1522 (*lpCallback)(itr->ref, pvRef);
1529 static const IDirectInputDevice8AVtbl JoystickAvt =
1531 IDirectInputDevice2AImpl_QueryInterface,
1532 IDirectInputDevice2AImpl_AddRef,
1533 JoystickAImpl_Release,
1534 JoystickAImpl_GetCapabilities,
1535 JoystickAImpl_EnumObjects,
1536 JoystickAImpl_GetProperty,
1537 JoystickAImpl_SetProperty,
1538 JoystickAImpl_Acquire,
1539 JoystickAImpl_Unacquire,
1540 JoystickAImpl_GetDeviceState,
1541 JoystickAImpl_GetDeviceData,
1542 JoystickAImpl_SetDataFormat,
1543 JoystickAImpl_SetEventNotification,
1544 IDirectInputDevice2AImpl_SetCooperativeLevel,
1545 IDirectInputDevice2AImpl_GetObjectInfo,
1546 IDirectInputDevice2AImpl_GetDeviceInfo,
1547 IDirectInputDevice2AImpl_RunControlPanel,
1548 IDirectInputDevice2AImpl_Initialize,
1549 JoystickAImpl_CreateEffect,
1550 JoystickAImpl_EnumEffects,
1551 JoystickAImpl_GetEffectInfo,
1552 JoystickAImpl_GetForceFeedbackState,
1553 JoystickAImpl_SendForceFeedbackCommand,
1554 JoystickAImpl_EnumCreatedEffectObjects,
1555 IDirectInputDevice2AImpl_Escape,
1557 IDirectInputDevice2AImpl_SendDeviceData,
1558 IDirectInputDevice7AImpl_EnumEffectsInFile,
1559 IDirectInputDevice7AImpl_WriteEffectToFile,
1560 IDirectInputDevice8AImpl_BuildActionMap,
1561 IDirectInputDevice8AImpl_SetActionMap,
1562 IDirectInputDevice8AImpl_GetImageInfo
1565 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1566 # define XCAST(fun) (typeof(JoystickWvt.fun))
1568 # define XCAST(fun) (void*)
1571 static const IDirectInputDevice8WVtbl JoystickWvt =
1573 IDirectInputDevice2WImpl_QueryInterface,
1574 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1575 XCAST(Release)JoystickAImpl_Release,
1576 XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1577 JoystickWImpl_EnumObjects,
1578 XCAST(GetProperty)JoystickAImpl_GetProperty,
1579 XCAST(SetProperty)JoystickAImpl_SetProperty,
1580 XCAST(Acquire)JoystickAImpl_Acquire,
1581 XCAST(Unacquire)JoystickAImpl_Unacquire,
1582 XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1583 XCAST(GetDeviceData)JoystickAImpl_GetDeviceData,
1584 XCAST(SetDataFormat)JoystickAImpl_SetDataFormat,
1585 XCAST(SetEventNotification)JoystickAImpl_SetEventNotification,
1586 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1587 IDirectInputDevice2WImpl_GetObjectInfo,
1588 IDirectInputDevice2WImpl_GetDeviceInfo,
1589 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1590 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1591 XCAST(CreateEffect)JoystickAImpl_CreateEffect,
1592 JoystickWImpl_EnumEffects,
1593 JoystickWImpl_GetEffectInfo,
1594 XCAST(GetForceFeedbackState)JoystickAImpl_GetForceFeedbackState,
1595 XCAST(SendForceFeedbackCommand)JoystickAImpl_SendForceFeedbackCommand,
1596 XCAST(EnumCreatedEffectObjects)JoystickAImpl_EnumCreatedEffectObjects,
1597 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1598 XCAST(Poll)JoystickAImpl_Poll,
1599 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1600 IDirectInputDevice7WImpl_EnumEffectsInFile,
1601 IDirectInputDevice7WImpl_WriteEffectToFile,
1602 IDirectInputDevice8WImpl_BuildActionMap,
1603 IDirectInputDevice8WImpl_SetActionMap,
1604 IDirectInputDevice8WImpl_GetImageInfo
1608 #else /* HAVE_CORRECT_LINUXINPUT_H */
1610 const struct dinput_device joystick_linuxinput_device = {
1611 "Wine Linux-input joystick driver",
1618 #endif /* HAVE_CORRECT_LINUXINPUT_H */