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
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_POV_BASE 6
71 #define WINE_JOYSTICK_BUTTON_BASE 8
73 typedef struct EffectListItem EffectListItem;
76 LPDIRECTINPUTEFFECT ref;
77 struct EffectListItem* next;
80 /* implemented in effect_linuxinput.c */
81 HRESULT linuxinput_create_effect(int* fd, REFGUID rguid, LPDIRECTINPUTEFFECT* peff);
82 HRESULT linuxinput_get_info_A(int fd, REFGUID rguid, LPDIEFFECTINFOA info);
83 HRESULT linuxinput_get_info_W(int fd, REFGUID rguid, LPDIEFFECTINFOW info);
85 typedef struct JoystickImpl JoystickImpl;
86 static const IDirectInputDevice8AVtbl JoystickAvt;
87 static const IDirectInputDevice8WVtbl JoystickWvt;
97 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
98 BYTE evbits[(EV_MAX+7)/8];
99 BYTE absbits[(ABS_MAX+7)/8];
100 BYTE keybits[(KEY_MAX+7)/8];
101 BYTE ffbits[(FF_MAX+7)/8];
106 #define AXE_ABSFUZZ 3
107 #define AXE_ABSFLAT 4
109 /* data returned by the EVIOCGABS() ioctl */
110 int axes[ABS_MAX][5];
111 /* LUT for KEY_ to offset in rgbButtons */
112 BYTE buttons[KEY_MAX];
114 /* autodetecting ranges per axe by following movement */
115 LONG havemax[ABS_MAX];
116 LONG havemin[ABS_MAX];
124 struct JoyDev *joydev;
126 /* The 'parent' DInput */
127 IDirectInputImpl *dinput;
129 /* joystick private */
130 /* what range and deadzone the game wants */
131 LONG wantmin[ABS_MAX];
132 LONG wantmax[ABS_MAX];
137 LPDIDATAFORMAT internal_df;
139 DataFormat *transform; /* wine to user format converter */
140 int *offsets; /* object offsets */
142 LPDIDEVICEOBJECTDATA data_queue;
143 int queue_head, queue_tail, queue_len;
147 /* Force feedback variables */
150 EffectListItem* top_effect;
154 static void fake_current_js_state(JoystickImpl *ji);
155 static int find_property_offset(JoystickImpl *This, LPCDIPROPHEADER ph);
156 static DWORD map_pov(int event_value, int is_x);
157 static void find_joydevs(void);
158 static int lxinput_to_djoy2_offset(int ie_type, int ie_code);
159 static int offset_to_object(JoystickImpl *This, int offset);
160 static void calculate_ids(LPDIDATAFORMAT df);
162 /* This GUID is slightly different from the linux joystick one. Take note. */
163 static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
167 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
170 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
172 #define MAX_JOYDEV 64
174 static int have_joydevs = -1;
175 static struct JoyDev *joydevs = NULL;
177 static void find_joydevs(void)
181 if (have_joydevs!=-1) {
187 for (i=0;i<MAX_JOYDEV;i++) {
189 struct JoyDev joydev = {0};
194 snprintf(buf,MAX_PATH,EVDEVPREFIX"%d",i);
197 if ((fd=open(buf, O_RDWR))==-1) {
198 fd = open(buf, O_RDONLY);
203 if ((-1==ioctl(fd,EVIOCGBIT(0,sizeof(joydev.evbits)),joydev.evbits))) {
204 perror("EVIOCGBIT 0");
208 if (-1==ioctl(fd,EVIOCGBIT(EV_ABS,sizeof(joydev.absbits)),joydev.absbits)) {
209 perror("EVIOCGBIT EV_ABS");
213 if (-1==ioctl(fd,EVIOCGBIT(EV_KEY,sizeof(joydev.keybits)),joydev.keybits)) {
214 perror("EVIOCGBIT EV_KEY");
218 /* A true joystick has at least axis X and Y, and at least 1
219 * button. copied from linux/drivers/input/joydev.c */
220 if (test_bit(joydev.absbits,ABS_X) && test_bit(joydev.absbits,ABS_Y) &&
221 ( test_bit(joydev.keybits,BTN_TRIGGER) ||
222 test_bit(joydev.keybits,BTN_A) ||
223 test_bit(joydev.keybits,BTN_1)
227 joydev.device = strdup(buf);
229 if (-1!=ioctl(fd, EVIOCGNAME(MAX_PATH-1), buf)) {
231 joydev.name = strdup(buf);
233 joydev.name = joydev.device;
236 joydev.guid = DInput_Wine_Joystick_Base_GUID;
237 joydev.guid.Data3 += have_joydevs;
239 TRACE("Found a joystick on %s: %s (%s)\n",
240 joydev.device, joydev.name,
241 debugstr_guid(&joydev.guid)
244 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
246 if ((!test_bit(joydev.evbits,EV_FF))
247 || (-1==ioctl(fd,EVIOCGBIT(EV_FF,sizeof(joydev.ffbits)),joydev.ffbits))
248 || (-1==ioctl(fd,EVIOCGEFFECTS,&joydev.num_effects))
249 || (joydev.num_effects <= 0)) {
252 TRACE(" ... with force feedback\n");
258 for (j=0;j<ABS_MAX;j++) {
259 if (test_bit(joydev.absbits,j)) {
260 if (-1!=ioctl(fd,EVIOCGABS(j),&(joydev.axes[j]))) {
261 TRACE(" ... with axe %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
263 joydev.axes[j][AXE_ABS],
264 joydev.axes[j][AXE_ABSMIN],
265 joydev.axes[j][AXE_ABSMAX],
266 joydev.axes[j][AXE_ABSFUZZ],
267 joydev.axes[j][AXE_ABSFLAT]
269 joydev.havemin[j] = joydev.axes[j][AXE_ABSMIN];
270 joydev.havemax[j] = joydev.axes[j][AXE_ABSMAX];
276 for (j=0;j<KEY_MAX;j++) {
277 if (test_bit(joydev.keybits,j)) {
278 TRACE(" ... with button %d: %d\n", j, buttons);
279 joydev.buttons[j] = 0x80 | buttons;
284 if (have_joydevs==0) {
285 joydevs = HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev));
287 HeapReAlloc(GetProcessHeap(), 0, joydevs, (1+have_joydevs) * sizeof(struct JoyDev));
289 memcpy(joydevs+have_joydevs, &joydev, sizeof(struct JoyDev));
298 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
302 if (id >= have_joydevs) {
306 if (!((dwDevType == 0) ||
307 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
308 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
311 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
312 if (dwFlags & DIEDFL_FORCEFEEDBACK)
316 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
317 lpddi->guidInstance = joydevs[id].guid;
318 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
320 lpddi->guidFFDriver = GUID_NULL;
321 if (version >= 0x0800)
322 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
324 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
326 strcpy(lpddi->tszInstanceName, joydevs[id].name);
327 strcpy(lpddi->tszProductName, joydevs[id].device);
333 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
337 if (id >= have_joydevs) {
341 if (!((dwDevType == 0) ||
342 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
343 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
346 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
347 if (dwFlags & DIEDFL_FORCEFEEDBACK)
351 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
352 lpddi->guidInstance = joydevs[id].guid;
353 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
355 lpddi->guidFFDriver = GUID_NULL;
356 if (version >= 0x0800)
357 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
359 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
361 MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
362 MultiByteToWideChar(CP_ACP, 0, joydevs[id].device, -1, lpddi->tszProductName, MAX_PATH);
368 static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, struct JoyDev *joydev)
370 JoystickImpl* newDevice;
373 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
374 if (newDevice==NULL) {
378 newDevice->lpVtbl = jvt;
380 newDevice->joyfd = -1;
381 newDevice->dinput = dinput;
382 newDevice->joydev = joydev;
383 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
384 newDevice->ff_state = FF_STATUS_STOPPED;
386 memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
387 for (i=0;i<ABS_MAX;i++) {
388 /* apps expect the range to be the same they would get from the
389 * GetProperty/range method */
390 newDevice->wantmin[i] = newDevice->joydev->havemin[i];
391 newDevice->wantmax[i] = newDevice->joydev->havemax[i];
393 * direct input defines a default for the deadzone somewhere; but as long
394 * as in map_axis the code for the dead zone is commented out its no
397 newDevice->deadz[i] = 0;
399 fake_current_js_state(newDevice);
401 /* wine uses DIJOYSTATE2 as it's internal format so copy
402 * the already defined format c_dfDIJoystick2 */
403 newDevice->df = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwSize);
404 if (newDevice->df == 0)
406 CopyMemory(newDevice->df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
408 /* copy default objects */
409 newDevice->df->rgodf = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
410 if (newDevice->df->rgodf == 0)
412 CopyMemory(newDevice->df->rgodf,c_dfDIJoystick2.rgodf,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
414 /* no do the same for the internal df */
415 newDevice->internal_df = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwSize);
416 if (newDevice->internal_df == 0)
418 CopyMemory(newDevice->internal_df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
420 /* copy default objects */
421 newDevice->internal_df->rgodf = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
422 if (newDevice->internal_df->rgodf == 0)
424 CopyMemory(newDevice->internal_df->rgodf,c_dfDIJoystick2.rgodf,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
426 /* create an offsets array */
427 newDevice->offsets = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,c_dfDIJoystick2.dwNumObjs*sizeof(int));
428 if (newDevice->offsets == 0)
431 calculate_ids(newDevice->internal_df);
433 /* create the default transform filter */
434 newDevice->transform = create_DataFormat(newDevice->internal_df, newDevice->df, newDevice->offsets);
435 calculate_ids(newDevice->df);
440 HeapFree(GetProcessHeap(),0,newDevice->df->rgodf);
441 HeapFree(GetProcessHeap(),0,newDevice->df);
442 HeapFree(GetProcessHeap(),0,newDevice->internal_df->rgodf);
443 HeapFree(GetProcessHeap(),0,newDevice->internal_df);
444 HeapFree(GetProcessHeap(),0,newDevice);
448 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
454 for (i=0; i<have_joydevs; i++) {
455 if (IsEqualGUID(&GUID_Joystick,rguid) ||
456 IsEqualGUID(&joydevs[i].guid,rguid)
458 if ((riid == NULL) ||
459 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
460 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
461 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
462 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
463 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, &joydevs[i]);
464 TRACE("Creating a Joystick device (%p)\n", *pdev);
466 ERR("out of memory\n");
467 return DIERR_OUTOFMEMORY;
471 return DIERR_NOINTERFACE;
476 return DIERR_DEVICENOTREG;
480 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
486 for (i=0; i<have_joydevs; i++) {
487 if (IsEqualGUID(&GUID_Joystick,rguid) ||
488 IsEqualGUID(&joydevs[i].guid,rguid)
490 if ((riid == NULL) ||
491 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
492 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
493 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
494 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
495 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, &joydevs[i]);
496 TRACE("Creating a Joystick device (%p)\n", *pdev);
498 ERR("out of memory\n");
499 return DIERR_OUTOFMEMORY;
503 return DIERR_NOINTERFACE;
508 return DIERR_DEVICENOTREG;
511 const struct dinput_device joystick_linuxinput_device = {
512 "Wine Linux-input joystick driver",
515 joydev_create_deviceA,
516 joydev_create_deviceW
519 /******************************************************************************
522 static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
524 JoystickImpl *This = (JoystickImpl *)iface;
527 ref = InterlockedDecrement(&(This->ref));
531 /* Reset the FF state, free all effects, etc */
532 IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
534 /* Free the data queue */
535 HeapFree(GetProcessHeap(),0,This->data_queue);
537 /* Free the DataFormat */
538 HeapFree(GetProcessHeap(), 0, This->df->rgodf);
539 HeapFree(GetProcessHeap(), 0, This->df);
541 /* Free the offsets array */
542 HeapFree(GetProcessHeap(),0,This->offsets);
544 /* release the data transform filter */
545 release_DataFormat(This->transform);
547 HeapFree(GetProcessHeap(),0,This);
551 /******************************************************************************
552 * SetDataFormat : the application can choose the format of the data
553 * the device driver sends back with GetDeviceState.
555 static HRESULT WINAPI JoystickAImpl_SetDataFormat(
556 LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
559 JoystickImpl *This = (JoystickImpl *)iface;
561 TRACE("(this=%p,%p)\n",This,df);
564 WARN("invalid pointer\n");
568 if (df->dwSize != sizeof(*df)) {
569 WARN("invalid argument\n");
570 return DIERR_INVALIDPARAM;
573 _dump_DIDATAFORMAT(df);
575 if (This->joyfd!=-1) {
577 return DIERR_ACQUIRED;
580 HeapFree(GetProcessHeap(),0,This->df->rgodf);
581 HeapFree(GetProcessHeap(),0,This->df);
582 release_DataFormat(This->transform);
584 /* Store the new data format */
585 This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
586 if (This->df==NULL) {
587 return DIERR_OUTOFMEMORY;
589 memcpy(This->df, df, df->dwSize);
590 This->df->rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
591 if (This->df->rgodf==NULL) {
592 HeapFree(GetProcessHeap(), 0, This->df);
593 return DIERR_OUTOFMEMORY;
595 memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
597 This->transform = create_DataFormat(This->internal_df, This->df, This->offsets);
598 calculate_ids(This->df);
603 /******************************************************************************
604 * Acquire : gets exclusive control of the joystick
606 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
608 JoystickImpl *This = (JoystickImpl *)iface;
610 TRACE("(this=%p)\n",This);
613 if (This->df==NULL) {
614 return DIERR_INVALIDPARAM;
617 if (-1==(This->joyfd=open(This->joydev->device,O_RDWR))) {
618 if (-1==(This->joyfd=open(This->joydev->device,O_RDONLY))) {
619 /* Couldn't open the device at all */
620 perror(This->joydev->device);
621 return DIERR_NOTFOUND;
623 /* Couldn't open in r/w but opened in read-only. */
624 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This->joydev->device);
631 /******************************************************************************
632 * Unacquire : frees the joystick
634 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
636 JoystickImpl *This = (JoystickImpl *)iface;
638 TRACE("(this=%p)\n",This);
639 if (This->joyfd!=-1) {
649 * This maps the read value (from the input event) to a value in the
650 * 'wanted' range. It also autodetects the possible range of the axe and
651 * adapts values accordingly.
654 map_axis(JoystickImpl* This, int axis, int val) {
655 int xmin = This->joydev->axes[axis][AXE_ABSMIN];
656 int xmax = This->joydev->axes[axis][AXE_ABSMAX];
657 int hmax = This->joydev->havemax[axis];
658 int hmin = This->joydev->havemin[axis];
659 int wmin = This->wantmin[axis];
660 int wmax = This->wantmax[axis];
663 if (val > hmax) This->joydev->havemax[axis] = hmax = val;
664 if (val < hmin) This->joydev->havemin[axis] = hmin = val;
666 if (xmin == xmax) return val;
668 /* map the value from the hmin-hmax range into the wmin-wmax range */
669 ret = ((val-hmin) * (wmax-wmin)) / (hmax-hmin) + wmin;
671 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);
674 /* deadzone doesn't work comfortably enough right now. needs more testing*/
675 if ((ret > -deadz/2 ) && (ret < deadz/2)) {
676 FIXME("%d in deadzone, return mid.\n",val);
677 return (wmax-wmin)/2+wmin;
684 * set the current state of the js device as it would be with the middle
687 static void fake_current_js_state(JoystickImpl *ji)
690 /* center the axes */
691 ji->js.lX = test_bit(ji->joydev->absbits, ABS_X) ? map_axis(ji, ABS_X, ji->joydev->axes[ABS_X ][AXE_ABS]) : 0;
692 ji->js.lY = test_bit(ji->joydev->absbits, ABS_Y) ? map_axis(ji, ABS_Y, ji->joydev->axes[ABS_Y ][AXE_ABS]) : 0;
693 ji->js.lZ = test_bit(ji->joydev->absbits, ABS_Z) ? map_axis(ji, ABS_Z, ji->joydev->axes[ABS_Z ][AXE_ABS]) : 0;
694 ji->js.lRx = test_bit(ji->joydev->absbits, ABS_RX) ? map_axis(ji, ABS_RX, ji->joydev->axes[ABS_RX ][AXE_ABS]) : 0;
695 ji->js.lRy = test_bit(ji->joydev->absbits, ABS_RY) ? map_axis(ji, ABS_RY, ji->joydev->axes[ABS_RY ][AXE_ABS]) : 0;
696 ji->js.lRz = test_bit(ji->joydev->absbits, ABS_RZ) ? map_axis(ji, ABS_RZ, ji->joydev->axes[ABS_RZ ][AXE_ABS]) : 0;
697 ji->js.rglSlider[0] = test_bit(ji->joydev->absbits, ABS_THROTTLE) ? map_axis(ji, ABS_THROTTLE, ji->joydev->axes[ABS_THROTTLE][AXE_ABS]) : 0;
698 ji->js.rglSlider[1] = test_bit(ji->joydev->absbits, ABS_RUDDER) ? map_axis(ji, ABS_RUDDER, ji->joydev->axes[ABS_RUDDER ][AXE_ABS]) : 0;
699 /* POV center is -1 */
700 for (i=0; i<4; i++) {
701 ji->js.rgdwPOV[i] = -1;
706 * Maps an event value to a DX "clock" position:
711 static DWORD map_pov(int event_value, int is_x)
717 } else if (event_value>0) {
723 } else if (event_value>0) {
730 static int find_property_offset(JoystickImpl *This, LPCDIPROPHEADER ph)
735 for (i=0; i<This->df->dwNumObjs; i++) {
736 if (This->offsets[i]==ph->dwObj) {
742 for (i=0; i<This->df->dwNumObjs; i++) {
743 if ((This->df->rgodf[i].dwType & 0x00ffffff) == (ph->dwObj & 0x00ffffff)) {
744 ofs = This->df->rgodf[i].dwOfs;
749 for (i=0; i<This->df->dwNumObjs; i++) {
750 if (This->offsets[i]==ofs) {
757 FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
763 /* defines how the linux input system offset mappings into c_dfDIJoystick2 */
765 lxinput_to_djoy2_offset( int ie_type, int ie_code )
770 case ABS_X: return 0;
771 case ABS_Y: return 1;
772 case ABS_Z: return 2;
773 case ABS_RX: return 3;
774 case ABS_RY: return 4;
775 case ABS_RZ: return 5;
776 case ABS_THROTTLE: return 6;
777 case ABS_RUDDER: return 7;
779 case ABS_HAT0Y: return 8;
781 case ABS_HAT1Y: return 9;
783 case ABS_HAT2Y: return 10;
785 case ABS_HAT3Y: return 11;
787 FIXME("Unhandled EV_ABS(0x%02X)\n", ie_code);
794 WARN("DX8 does not support more than 128 buttons\n");
798 FIXME("Unhandled type(0x%02X)\n", ie_type);
802 /* convert wine format offset to user format object index */
803 static int offset_to_object(JoystickImpl *This, int offset)
807 for (i = 0; i < This->df->dwNumObjs; i++) {
808 if (This->df->rgodf[i].dwOfs == offset)
815 static void calculate_ids(LPDIDATAFORMAT df)
825 /* Make two passes over the format. The first counts the number
826 * for each type and the second sets the id */
827 for (i = 0; i < df->dwNumObjs; i++) {
828 if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS)
830 else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_POV)
832 else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_BUTTON)
838 button_base = axis + pov;
844 for (i = 0; i < df->dwNumObjs; i++) {
846 if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS) {
848 type = DIDFT_GETTYPE(df->rgodf[i].dwType) |
849 DIDFT_MAKEINSTANCE(axis + axis_base);
850 TRACE("axis type = 0x%08lx\n", type);
851 } else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_POV) {
853 type = DIDFT_GETTYPE(df->rgodf[i].dwType) |
854 DIDFT_MAKEINSTANCE(pov + pov_base);
855 TRACE("POV type = 0x%08lx\n", type);
856 } else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_BUTTON) {
858 type = DIDFT_GETTYPE(df->rgodf[i].dwType) |
859 DIDFT_MAKEINSTANCE(button + button_base);
860 TRACE("button type = 0x%08lx\n", type);
862 df->rgodf[i].dwType = type;
866 static void joy_polldev(JoystickImpl *This) {
869 struct input_event ie;
876 memset(&tv,0,sizeof(tv));
878 FD_SET(This->joyfd,&readfds);
880 if (1>select(This->joyfd+1,&readfds,NULL,NULL,&tv))
883 /* we have one event, so we can read */
884 if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
887 TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
889 case EV_KEY: /* button */
890 btn = This->joydev->buttons[ie.code];
891 TRACE("(%p) %d -> %d\n", This, ie.code, btn);
894 /* see if there is a mapping */
895 offset = lxinput_to_djoy2_offset(ie.type, btn);
899 /* and see if there is an offset in the df */
900 offset = This->offsets[offset];
904 This->js.rgbButtons[btn] = ie.value?0x80:0x00;
905 GEN_EVENT(offset,This->js.rgbButtons[btn],ie.time.tv_usec,(This->dinput->evsequence)++);
909 /* see if there is a mapping */
910 offset = lxinput_to_djoy2_offset(ie.type, ie.code);
914 /* and see if there is an offset in the df */
915 offset = This->offsets[offset];
921 This->js.lX = map_axis(This,ABS_X,ie.value);
922 GEN_EVENT(offset,This->js.lX,ie.time.tv_usec,(This->dinput->evsequence)++);
925 This->js.lY = map_axis(This,ABS_Y,ie.value);
926 GEN_EVENT(offset,This->js.lY,ie.time.tv_usec,(This->dinput->evsequence)++);
929 This->js.lZ = map_axis(This,ABS_Z,ie.value);
930 GEN_EVENT(offset,This->js.lZ,ie.time.tv_usec,(This->dinput->evsequence)++);
933 This->js.lRx = map_axis(This,ABS_RX,ie.value);
934 GEN_EVENT(offset,This->js.lRx,ie.time.tv_usec,(This->dinput->evsequence)++);
937 This->js.lRy = map_axis(This,ABS_RY,ie.value);
938 GEN_EVENT(offset,This->js.lRy,ie.time.tv_usec,(This->dinput->evsequence)++);
941 This->js.lRz = map_axis(This,ABS_RZ,ie.value);
942 GEN_EVENT(offset,This->js.lRz,ie.time.tv_usec,(This->dinput->evsequence)++);
945 This->js.rglSlider[0] = map_axis(This,ABS_THROTTLE,ie.value);
946 GEN_EVENT(offset,This->js.rglSlider[0],ie.time.tv_usec,(This->dinput->evsequence)++);
949 This->js.rglSlider[1] = map_axis(This,ABS_RUDDER,ie.value);
950 GEN_EVENT(offset,This->js.rglSlider[1],ie.time.tv_usec,(This->dinput->evsequence)++);
954 This->js.rgdwPOV[0] = map_pov(ie.value,ie.code==ABS_HAT0X);
955 GEN_EVENT(offset,This->js.rgdwPOV[0],ie.time.tv_usec,(This->dinput->evsequence)++);
959 This->js.rgdwPOV[1] = map_pov(ie.value,ie.code==ABS_HAT1X);
960 GEN_EVENT(offset,This->js.rgdwPOV[1],ie.time.tv_usec,(This->dinput->evsequence)++);
964 This->js.rgdwPOV[2] = map_pov(ie.value,ie.code==ABS_HAT2X);
965 GEN_EVENT(offset,This->js.rgdwPOV[2],ie.time.tv_usec,(This->dinput->evsequence)++);
969 This->js.rgdwPOV[3] = map_pov(ie.value,ie.code==ABS_HAT3X);
970 GEN_EVENT(offset,This->js.rgdwPOV[3],ie.time.tv_usec,(This->dinput->evsequence)++);
973 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie.code,ie.value);
977 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
979 This->ff_state = ie.value;
984 /* there is nothing to do */
988 FIXME("joystick cannot handle type %d event (code %d)\n",ie.type,ie.code);
994 /******************************************************************************
995 * GetDeviceState : returns the "state" of the joystick.
998 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
999 LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
1001 JoystickImpl *This = (JoystickImpl *)iface;
1003 TRACE("(this=%p,0x%08lx,%p)\n",This,len,ptr);
1005 if (This->joyfd==-1) {
1006 WARN("not acquired\n");
1007 return DIERR_NOTACQUIRED;
1012 /* convert and copy data to user supplied buffer */
1013 fill_DataFormat(ptr, &This->js, This->transform);
1018 /******************************************************************************
1019 * GetDeviceData : gets buffered input data.
1021 static HRESULT WINAPI JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
1023 LPDIDEVICEOBJECTDATA dod,
1027 JoystickImpl *This = (JoystickImpl *)iface;
1032 TRACE("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx)\n",This,dodsize,*entries,flags);
1034 if (This->joyfd==-!1) {
1035 WARN("not acquired\n");
1036 return DIERR_NOTACQUIRED;
1040 if (flags & DIGDD_PEEK)
1041 FIXME("DIGDD_PEEK\n");
1043 len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0)
1044 + (This->queue_head - This->queue_tail);
1050 TRACE("Application discarding %ld event(s).\n", len);
1053 nqtail = This->queue_tail + len;
1054 while (nqtail >= This->queue_len)
1055 nqtail -= This->queue_len;
1057 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
1058 ERR("Wrong structure size !\n");
1059 return DIERR_INVALIDPARAM;
1063 TRACE("Application retrieving %ld event(s).\n", len);
1066 nqtail = This->queue_tail;
1068 /* Copy the buffered data into the application queue */
1069 memcpy((char *)dod + *entries * dodsize, This->data_queue + nqtail, dodsize);
1070 /* Advance position */
1072 if (nqtail >= This->queue_len)
1073 nqtail -= This->queue_len;
1079 if (This->overflow) {
1080 hr = DI_BUFFEROVERFLOW;
1081 if (!(flags & DIGDD_PEEK)) {
1082 This->overflow = FALSE;
1086 if (!(flags & DIGDD_PEEK))
1087 This->queue_tail = nqtail;
1092 /******************************************************************************
1093 * SetProperty : change input device properties
1095 static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
1099 JoystickImpl *This = (JoystickImpl *)iface;
1102 WARN("invalid argument\n");
1103 return DIERR_INVALIDPARAM;
1106 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
1107 TRACE("ph.dwSize = %ld, ph.dwHeaderSize =%ld, ph.dwObj = %ld, ph.dwHow= %ld\n",ph->dwSize, ph->dwHeaderSize,ph->dwObj,ph->dwHow);
1109 if (!HIWORD(rguid)) {
1110 switch (LOWORD(rguid)) {
1111 case (DWORD) DIPROP_BUFFERSIZE: {
1112 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1114 TRACE("buffersize = %ld\n",pd->dwData);
1115 if (This->data_queue) {
1116 This->data_queue = HeapReAlloc(GetProcessHeap(),0, This->data_queue, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
1118 This->data_queue = HeapAlloc(GetProcessHeap(),0, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
1120 This->queue_head = 0;
1121 This->queue_tail = 0;
1122 This->queue_len = pd->dwData;
1125 case (DWORD)DIPROP_RANGE: {
1126 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
1128 if (ph->dwHow == DIPH_DEVICE) {
1130 TRACE("proprange(%ld,%ld) all\n",pr->lMin,pr->lMax);
1131 for (i = 0; i < This->df->dwNumObjs; i++) {
1132 This->wantmin[i] = pr->lMin;
1133 This->wantmax[i] = pr->lMax;
1136 int obj = find_property_offset(This, ph);
1137 TRACE("proprange(%ld,%ld) obj=%d\n",pr->lMin,pr->lMax,obj);
1139 This->wantmin[obj] = pr->lMin;
1140 This->wantmax[obj] = pr->lMax;
1143 fake_current_js_state(This);
1146 case (DWORD)DIPROP_DEADZONE: {
1147 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1148 if (ph->dwHow == DIPH_DEVICE) {
1150 TRACE("deadzone(%ld) all\n",pd->dwData);
1151 for (i = 0; i < This->df->dwNumObjs; i++) {
1152 This->deadz[i] = pd->dwData;
1155 int obj = find_property_offset(This, ph);
1156 TRACE("deadzone(%ld) obj=%d\n",pd->dwData,obj);
1158 This->deadz[obj] = pd->dwData;
1161 fake_current_js_state(This);
1165 FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
1172 /******************************************************************************
1173 * SetEventNotification : specifies event to be sent on state change
1175 static HRESULT WINAPI JoystickAImpl_SetEventNotification(
1176 LPDIRECTINPUTDEVICE8A iface, HANDLE hnd
1178 JoystickImpl *This = (JoystickImpl *)iface;
1180 TRACE("(this=%p,%p)\n",This,hnd);
1185 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
1186 LPDIRECTINPUTDEVICE8A iface,
1187 LPDIDEVCAPS lpDIDevCaps)
1189 JoystickImpl *This = (JoystickImpl *)iface;
1190 int i,axes,buttons,povs;
1192 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
1195 WARN("invalid pointer\n");
1199 if (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) {
1200 WARN("invalid argument\n");
1201 return DIERR_INVALIDPARAM;
1204 lpDIDevCaps->dwFlags = DIDC_ATTACHED;
1205 if (This->dinput->dwVersion >= 0x0800)
1206 lpDIDevCaps->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
1208 lpDIDevCaps->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
1211 for (i=0;i<ABS_MAX;i++) {
1212 if (!test_bit(This->joydev->absbits,i)) continue;
1214 case ABS_HAT0X: case ABS_HAT0Y:
1215 case ABS_HAT1X: case ABS_HAT1Y:
1216 case ABS_HAT2X: case ABS_HAT2Y:
1217 case ABS_HAT3X: case ABS_HAT3Y:
1218 /* will be handled as POV - see below */
1225 for (i=0;i<KEY_MAX;i++) if (test_bit(This->joydev->keybits,i)) buttons++;
1227 for (i=0; i<4; i++) {
1228 if (test_bit(This->joydev->absbits,ABS_HAT0X+(i<<1)) && test_bit(This->joydev->absbits,ABS_HAT0Y+(i<<1))) {
1234 lpDIDevCaps->dwFlags |= DIDC_FORCEFEEDBACK;
1236 lpDIDevCaps->dwAxes = axes;
1237 lpDIDevCaps->dwButtons = buttons;
1238 lpDIDevCaps->dwPOVs = povs;
1243 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface) {
1244 JoystickImpl *This = (JoystickImpl *)iface;
1245 TRACE("(%p)\n",This);
1247 if (This->joyfd==-1) {
1248 return DIERR_NOTACQUIRED;
1255 /******************************************************************************
1256 * EnumObjects : enumerate the different buttons and axis...
1258 static HRESULT WINAPI JoystickAImpl_EnumObjects(
1259 LPDIRECTINPUTDEVICE8A iface,
1260 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
1264 JoystickImpl *This = (JoystickImpl *)iface;
1265 DIDEVICEOBJECTINSTANCEA ddoi;
1266 int user_offset, user_object;
1268 TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
1269 if (TRACE_ON(dinput)) {
1270 TRACE(" - flags = ");
1271 _dump_EnumObjects_flags(dwFlags);
1275 /* Only the fields till dwFFMaxForce are relevant */
1276 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
1278 /* For the joystick, do as is done in the GetCapabilities function */
1279 /* FIXME: needs more items */
1280 if ((dwFlags == DIDFT_ALL) ||
1281 (dwFlags & DIDFT_AXIS)) {
1284 for (i = 0; i < ABS_MAX; i++) {
1285 if (!test_bit(This->joydev->absbits,i)) continue;
1289 ddoi.guidType = GUID_XAxis;
1292 ddoi.guidType = GUID_YAxis;
1295 ddoi.guidType = GUID_ZAxis;
1298 ddoi.guidType = GUID_RxAxis;
1301 ddoi.guidType = GUID_RyAxis;
1304 ddoi.guidType = GUID_RzAxis;
1307 ddoi.guidType = GUID_Slider;
1310 ddoi.guidType = GUID_Slider;
1312 case ABS_HAT0X: case ABS_HAT0Y:
1313 case ABS_HAT1X: case ABS_HAT1Y:
1314 case ABS_HAT2X: case ABS_HAT2Y:
1315 case ABS_HAT3X: case ABS_HAT3Y:
1316 /* will be handled as POV - see below */
1319 FIXME("unhandled abs axis 0x%02x, ignoring!\n",i);
1322 user_offset = lxinput_to_djoy2_offset(EV_ABS, i);
1323 if (user_offset == -1) {
1326 user_offset = This->offsets[user_offset];
1327 if (user_offset == -1) {
1330 user_object = offset_to_object(This, user_offset);
1331 ddoi.dwType = This->df->rgodf[user_object].dwType & 0x00ffffff;
1332 ddoi.dwOfs = This->df->rgodf[user_object].dwOfs;
1333 /* Linux event force feedback supports only (and always) x and y axes */
1334 if (i == ABS_X || i == ABS_Y) {
1336 ddoi.dwFlags |= DIDOI_FFACTUATOR;
1338 sprintf(ddoi.tszName, "%d-Axis", i);
1339 _dump_OBJECTINSTANCEA(&ddoi);
1340 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) {
1346 if ((dwFlags == DIDFT_ALL) ||
1347 (dwFlags & DIDFT_POV)) {
1349 ddoi.guidType = GUID_POV;
1350 for (i=0; i<4; i++) {
1351 if (test_bit(This->joydev->absbits,ABS_HAT0X+(i<<1)) && test_bit(This->joydev->absbits,ABS_HAT0Y+(i<<1))) {
1352 user_offset = lxinput_to_djoy2_offset(EV_ABS, ABS_HAT0X+i);
1353 if (user_offset == -1) {
1356 user_offset = This->offsets[user_offset];
1357 if (user_offset == -1) {
1360 user_object = offset_to_object(This, user_offset);
1361 ddoi.dwType = This->df->rgodf[user_object].dwType & 0x00ffffff;
1362 ddoi.dwOfs = This->df->rgodf[user_object].dwOfs;
1363 sprintf(ddoi.tszName, "%d-POV", i);
1364 _dump_OBJECTINSTANCEA(&ddoi);
1365 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) {
1372 if ((dwFlags == DIDFT_ALL) ||
1373 (dwFlags & DIDFT_BUTTON)) {
1376 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
1378 ddoi.guidType = GUID_Button;
1380 for (i = 0; i < KEY_MAX; i++) {
1381 if (!test_bit(This->joydev->keybits,i)) continue;
1382 user_offset = lxinput_to_djoy2_offset(EV_KEY, btncount);
1383 if (user_offset == -1) {
1386 user_offset = This->offsets[user_offset];
1387 if (user_offset == -1) {
1390 user_object = offset_to_object(This, user_offset);
1391 ddoi.dwType = This->df->rgodf[user_object].dwType & 0x00ffffff;
1392 ddoi.dwOfs = This->df->rgodf[user_object].dwOfs;
1393 sprintf(ddoi.tszName, "%d-Button", btncount);
1395 _dump_OBJECTINSTANCEA(&ddoi);
1396 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) {
1405 static HRESULT WINAPI JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
1406 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
1410 JoystickImpl *This = (JoystickImpl *)iface;
1412 device_enumobjects_AtoWcb_data data;
1414 data.lpCallBack = lpCallback;
1415 data.lpvRef = lpvRef;
1417 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
1420 /******************************************************************************
1421 * GetProperty : get input device properties
1423 static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
1425 LPDIPROPHEADER pdiph)
1427 JoystickImpl *This = (JoystickImpl *)iface;
1429 TRACE("(this=%p,%s,%p)\n",
1430 iface, debugstr_guid(rguid), pdiph);
1432 if (TRACE_ON(dinput))
1433 _dump_DIPROPHEADER(pdiph);
1435 if (!HIWORD(rguid)) {
1436 switch (LOWORD(rguid)) {
1437 case (DWORD) DIPROP_BUFFERSIZE: {
1438 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1440 TRACE(" return buffersize = %d\n",This->queue_len);
1441 pd->dwData = This->queue_len;
1445 case (DWORD) DIPROP_RANGE: {
1446 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
1447 int obj = find_property_offset(This, pdiph);
1449 pr->lMin = This->joydev->havemin[obj];
1450 pr->lMax = This->joydev->havemax[obj];
1451 TRACE("range(%ld, %ld) obj=%d\n", pr->lMin, pr->lMax, obj);
1458 FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
1467 /******************************************************************************
1468 * CreateEffect - Create a new FF effect with the specified params
1470 static HRESULT WINAPI JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface,
1473 LPDIRECTINPUTEFFECT *ppdef,
1474 LPUNKNOWN pUnkOuter)
1476 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1477 EffectListItem* new = NULL;
1478 HRESULT retval = DI_OK;
1481 JoystickImpl* This = (JoystickImpl*)iface;
1482 TRACE("(this=%p,%p,%p,%p,%p)\n", This, rguid, lpeff, ppdef, pUnkOuter);
1484 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1485 TRACE("not available (compiled w/o ff support)\n");
1490 new = malloc(sizeof(EffectListItem));
1491 new->next = This->top_effect;
1492 This->top_effect = new;
1494 retval = linuxinput_create_effect(&(This->joyfd), rguid, &(new->ref));
1495 if (retval != DI_OK)
1499 retval = IDirectInputEffect_SetParameters(new->ref, lpeff, 0);
1500 if (retval != DI_OK && retval != DI_DOWNLOADSKIPPED)
1505 if (pUnkOuter != NULL)
1506 FIXME("Interface aggregation not implemented.\n");
1510 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1513 /*******************************************************************************
1514 * EnumEffects - Enumerate available FF effects
1516 static HRESULT WINAPI JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface,
1517 LPDIENUMEFFECTSCALLBACKA lpCallback,
1521 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1522 DIEFFECTINFOA dei; /* feif */
1523 DWORD type = DIEFT_GETTYPE(dwEffType);
1524 JoystickImpl* This = (JoystickImpl*)iface;
1526 TRACE("(this=%p,%p,%ld) type=%ld\n", This, pvRef, dwEffType, type);
1528 dei.dwSize = sizeof(DIEFFECTINFOA);
1530 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1531 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1532 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1533 (*lpCallback)(&dei, pvRef);
1536 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1537 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1538 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1539 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1540 (*lpCallback)(&dei, pvRef);
1542 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1543 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1544 (*lpCallback)(&dei, pvRef);
1546 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1547 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1548 (*lpCallback)(&dei, pvRef);
1550 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1551 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1552 (*lpCallback)(&dei, pvRef);
1554 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1555 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1556 (*lpCallback)(&dei, pvRef);
1560 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1561 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1562 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1563 (*lpCallback)(&dei, pvRef);
1566 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1567 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1568 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1569 (*lpCallback)(&dei, pvRef);
1571 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1572 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1573 (*lpCallback)(&dei, pvRef);
1575 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1576 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1577 (*lpCallback)(&dei, pvRef);
1579 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1580 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1581 (*lpCallback)(&dei, pvRef);
1590 static HRESULT WINAPI JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface,
1591 LPDIENUMEFFECTSCALLBACKW lpCallback,
1595 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1596 /* seems silly to duplicate all this code but all the structures and functions
1597 * are actually different (A/W) */
1598 DIEFFECTINFOW dei; /* feif */
1599 DWORD type = DIEFT_GETTYPE(dwEffType);
1600 JoystickImpl* This = (JoystickImpl*)iface;
1601 int xfd = This->joyfd;
1603 TRACE("(this=%p,%p,%ld) type=%ld fd=%d\n", This, pvRef, dwEffType, type, xfd);
1605 dei.dwSize = sizeof(DIEFFECTINFOW);
1607 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1608 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1609 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1610 (*lpCallback)(&dei, pvRef);
1613 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1614 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1615 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1616 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1617 (*lpCallback)(&dei, pvRef);
1619 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1620 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1621 (*lpCallback)(&dei, pvRef);
1623 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1624 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1625 (*lpCallback)(&dei, pvRef);
1627 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1628 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1629 (*lpCallback)(&dei, pvRef);
1631 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1632 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1633 (*lpCallback)(&dei, pvRef);
1637 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1638 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1639 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1640 (*lpCallback)(&dei, pvRef);
1643 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1644 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1645 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1646 (*lpCallback)(&dei, pvRef);
1648 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1649 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1650 (*lpCallback)(&dei, pvRef);
1652 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1653 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1654 (*lpCallback)(&dei, pvRef);
1656 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1657 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1658 (*lpCallback)(&dei, pvRef);
1662 /* return to unaquired state if that's where it was */
1664 IDirectInputDevice8_Unacquire(iface);
1670 /*******************************************************************************
1671 * GetEffectInfo - Get information about a particular effect
1673 static HRESULT WINAPI JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface,
1674 LPDIEFFECTINFOA pdei,
1677 JoystickImpl* This = (JoystickImpl*)iface;
1679 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1681 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1682 return linuxinput_get_info_A(This->joyfd, guid, pdei);
1688 static HRESULT WINAPI JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface,
1689 LPDIEFFECTINFOW pdei,
1692 JoystickImpl* This = (JoystickImpl*)iface;
1694 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1696 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1697 return linuxinput_get_info_W(This->joyfd, guid, pdei);
1703 /*******************************************************************************
1704 * GetForceFeedbackState - Get information about the device's FF state
1706 static HRESULT WINAPI JoystickAImpl_GetForceFeedbackState(
1707 LPDIRECTINPUTDEVICE8A iface,
1710 JoystickImpl* This = (JoystickImpl*)iface;
1712 TRACE("(this=%p,%p)\n", This, pdwOut);
1716 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1717 /* DIGFFS_STOPPED is the only mandatory flag to report */
1718 if (This->ff_state == FF_STATUS_STOPPED)
1719 (*pdwOut) |= DIGFFS_STOPPED;
1725 /*******************************************************************************
1726 * SendForceFeedbackCommand - Send a command to the device's FF system
1728 static HRESULT WINAPI JoystickAImpl_SendForceFeedbackCommand(
1729 LPDIRECTINPUTDEVICE8A iface,
1732 JoystickImpl* This = (JoystickImpl*)iface;
1733 TRACE("(this=%p,%ld)\n", This, dwFlags);
1735 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1736 if (dwFlags == DISFFC_STOPALL) {
1737 /* Stop all effects */
1738 EffectListItem* itr = This->top_effect;
1740 IDirectInputEffect_Stop(itr->ref);
1743 } else if (dwFlags == DISFFC_RESET) {
1744 /* Stop, unload, release and free all effects */
1745 /* This returns the device to its "bare" state */
1746 while (This->top_effect) {
1747 EffectListItem* temp = This->top_effect;
1748 IDirectInputEffect_Stop(temp->ref);
1749 IDirectInputEffect_Unload(temp->ref);
1750 IDirectInputEffect_Release(temp->ref);
1751 This->top_effect = temp->next;
1754 } else if (dwFlags == DISFFC_PAUSE || dwFlags == DISFFC_CONTINUE) {
1755 FIXME("No support for Pause or Continue in linux\n");
1756 } else if (dwFlags == DISFFC_SETACTUATORSOFF
1757 || dwFlags == DISFFC_SETACTUATORSON) {
1758 FIXME("No direct actuator control in linux\n");
1760 FIXME("Unknown Force Feedback Command!\n");
1761 return DIERR_INVALIDPARAM;
1765 return DIERR_UNSUPPORTED;
1769 /*******************************************************************************
1770 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1771 * created for this device.
1773 static HRESULT WINAPI JoystickAImpl_EnumCreatedEffectObjects(
1774 LPDIRECTINPUTDEVICE8A iface,
1775 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1779 /* this function is safe to call on non-ff-enabled builds */
1781 JoystickImpl* This = (JoystickImpl*)iface;
1782 EffectListItem* itr = This->top_effect;
1783 TRACE("(this=%p,%p,%p,%ld)\n", This, lpCallback, pvRef, dwFlags);
1786 return DIERR_INVALIDPARAM;
1789 FIXME("Flags specified, but no flags exist yet (DX9)!");
1792 (*lpCallback)(itr->ref, pvRef);
1799 static const IDirectInputDevice8AVtbl JoystickAvt =
1801 IDirectInputDevice2AImpl_QueryInterface,
1802 IDirectInputDevice2AImpl_AddRef,
1803 JoystickAImpl_Release,
1804 JoystickAImpl_GetCapabilities,
1805 JoystickAImpl_EnumObjects,
1806 JoystickAImpl_GetProperty,
1807 JoystickAImpl_SetProperty,
1808 JoystickAImpl_Acquire,
1809 JoystickAImpl_Unacquire,
1810 JoystickAImpl_GetDeviceState,
1811 JoystickAImpl_GetDeviceData,
1812 JoystickAImpl_SetDataFormat,
1813 JoystickAImpl_SetEventNotification,
1814 IDirectInputDevice2AImpl_SetCooperativeLevel,
1815 IDirectInputDevice2AImpl_GetObjectInfo,
1816 IDirectInputDevice2AImpl_GetDeviceInfo,
1817 IDirectInputDevice2AImpl_RunControlPanel,
1818 IDirectInputDevice2AImpl_Initialize,
1819 JoystickAImpl_CreateEffect,
1820 JoystickAImpl_EnumEffects,
1821 JoystickAImpl_GetEffectInfo,
1822 JoystickAImpl_GetForceFeedbackState,
1823 JoystickAImpl_SendForceFeedbackCommand,
1824 JoystickAImpl_EnumCreatedEffectObjects,
1825 IDirectInputDevice2AImpl_Escape,
1827 IDirectInputDevice2AImpl_SendDeviceData,
1828 IDirectInputDevice7AImpl_EnumEffectsInFile,
1829 IDirectInputDevice7AImpl_WriteEffectToFile,
1830 IDirectInputDevice8AImpl_BuildActionMap,
1831 IDirectInputDevice8AImpl_SetActionMap,
1832 IDirectInputDevice8AImpl_GetImageInfo
1835 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1836 # define XCAST(fun) (typeof(JoystickWvt.fun))
1838 # define XCAST(fun) (void*)
1841 static const IDirectInputDevice8WVtbl JoystickWvt =
1843 IDirectInputDevice2WImpl_QueryInterface,
1844 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1845 XCAST(Release)JoystickAImpl_Release,
1846 XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1847 JoystickWImpl_EnumObjects,
1848 XCAST(GetProperty)JoystickAImpl_GetProperty,
1849 XCAST(SetProperty)JoystickAImpl_SetProperty,
1850 XCAST(Acquire)JoystickAImpl_Acquire,
1851 XCAST(Unacquire)JoystickAImpl_Unacquire,
1852 XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1853 XCAST(GetDeviceData)JoystickAImpl_GetDeviceData,
1854 XCAST(SetDataFormat)JoystickAImpl_SetDataFormat,
1855 XCAST(SetEventNotification)JoystickAImpl_SetEventNotification,
1856 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1857 IDirectInputDevice2WImpl_GetObjectInfo,
1858 IDirectInputDevice2WImpl_GetDeviceInfo,
1859 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1860 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1861 XCAST(CreateEffect)JoystickAImpl_CreateEffect,
1862 JoystickWImpl_EnumEffects,
1863 JoystickWImpl_GetEffectInfo,
1864 XCAST(GetForceFeedbackState)JoystickAImpl_GetForceFeedbackState,
1865 XCAST(SendForceFeedbackCommand)JoystickAImpl_SendForceFeedbackCommand,
1866 XCAST(EnumCreatedEffectObjects)JoystickAImpl_EnumCreatedEffectObjects,
1867 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1868 XCAST(Poll)JoystickAImpl_Poll,
1869 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1870 IDirectInputDevice7WImpl_EnumEffectsInFile,
1871 IDirectInputDevice7WImpl_WriteEffectToFile,
1872 IDirectInputDevice8WImpl_BuildActionMap,
1873 IDirectInputDevice8WImpl_SetActionMap,
1874 IDirectInputDevice8WImpl_GetImageInfo
1878 #else /* HAVE_CORRECT_LINUXINPUT_H */
1880 const struct dinput_device joystick_linuxinput_device = {
1881 "Wine Linux-input joystick driver",
1888 #endif /* HAVE_CORRECT_LINUXINPUT_H */