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];
139 LPDIDATAFORMAT internal_df;
141 DataFormat *transform; /* wine to user format converter */
142 int *offsets; /* object offsets */
143 LPDIDEVICEOBJECTDATA data_queue;
144 int queue_head, queue_tail, queue_len;
148 /* Force feedback variables */
149 EffectListItem* top_effect;
153 static void fake_current_js_state(JoystickImpl *ji);
154 static int find_property_offset(JoystickImpl *This, LPCDIPROPHEADER ph);
155 static DWORD map_pov(int event_value, int is_x);
156 static void find_joydevs(void);
157 static int lxinput_to_djoy2_offset(int ie_type, int ie_code);
158 static int offset_to_object(JoystickImpl *This, int offset);
159 static void calculate_ids(LPDIDATAFORMAT df);
161 /* This GUID is slightly different from the linux joystick one. Take note. */
162 static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
166 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
169 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
171 #define MAX_JOYDEV 64
173 static int have_joydevs = -1;
174 static struct JoyDev *joydevs = NULL;
176 static void find_joydevs(void)
180 if (have_joydevs!=-1) {
186 for (i=0;i<MAX_JOYDEV;i++) {
188 struct JoyDev joydev = {0};
193 snprintf(buf,MAX_PATH,EVDEVPREFIX"%d",i);
196 if ((fd=open(buf, O_RDWR))==-1) {
197 fd = open(buf, O_RDONLY);
202 if ((-1==ioctl(fd,EVIOCGBIT(0,sizeof(joydev.evbits)),joydev.evbits))) {
203 perror("EVIOCGBIT 0");
207 if (-1==ioctl(fd,EVIOCGBIT(EV_ABS,sizeof(joydev.absbits)),joydev.absbits)) {
208 perror("EVIOCGBIT EV_ABS");
212 if (-1==ioctl(fd,EVIOCGBIT(EV_KEY,sizeof(joydev.keybits)),joydev.keybits)) {
213 perror("EVIOCGBIT EV_KEY");
217 /* A true joystick has at least axis X and Y, and at least 1
218 * button. copied from linux/drivers/input/joydev.c */
219 if (test_bit(joydev.absbits,ABS_X) && test_bit(joydev.absbits,ABS_Y) &&
220 ( test_bit(joydev.keybits,BTN_TRIGGER) ||
221 test_bit(joydev.keybits,BTN_A) ||
222 test_bit(joydev.keybits,BTN_1)
226 joydev.device = strdup(buf);
228 if (-1!=ioctl(fd, EVIOCGNAME(MAX_PATH-1), buf)) {
230 joydev.name = strdup(buf);
232 joydev.name = joydev.device;
235 joydev.guid = DInput_Wine_Joystick_Base_GUID;
236 joydev.guid.Data3 += have_joydevs;
238 TRACE("Found a joystick on %s: %s (%s)\n",
239 joydev.device, joydev.name,
240 debugstr_guid(&joydev.guid)
243 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
245 if ((!test_bit(joydev.evbits,EV_FF))
246 || (-1==ioctl(fd,EVIOCGBIT(EV_FF,sizeof(joydev.ffbits)),joydev.ffbits))
247 || (-1==ioctl(fd,EVIOCGEFFECTS,&joydev.num_effects))
248 || (joydev.num_effects <= 0)) {
251 TRACE(" ... with force feedback\n");
257 for (j=0;j<ABS_MAX;j++) {
258 if (test_bit(joydev.absbits,j)) {
259 if (-1!=ioctl(fd,EVIOCGABS(j),&(joydev.axes[j]))) {
260 TRACE(" ... with axe %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
262 joydev.axes[j][AXE_ABS],
263 joydev.axes[j][AXE_ABSMIN],
264 joydev.axes[j][AXE_ABSMAX],
265 joydev.axes[j][AXE_ABSFUZZ],
266 joydev.axes[j][AXE_ABSFLAT]
268 joydev.havemin[j] = joydev.axes[j][AXE_ABSMIN];
269 joydev.havemax[j] = joydev.axes[j][AXE_ABSMAX];
275 for (j=0;j<KEY_MAX;j++) {
276 if (test_bit(joydev.keybits,j)) {
277 TRACE(" ... with button %d: %d\n", j, buttons);
278 joydev.buttons[j] = 0x80 | buttons;
283 if (have_joydevs==0) {
284 joydevs = HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev));
286 HeapReAlloc(GetProcessHeap(), 0, joydevs, (1+have_joydevs) * sizeof(struct JoyDev));
288 memcpy(joydevs+have_joydevs, &joydev, sizeof(struct JoyDev));
297 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
301 if (id >= have_joydevs) {
305 if (!((dwDevType == 0) ||
306 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
307 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
310 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
311 if (dwFlags & DIEDFL_FORCEFEEDBACK)
315 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
316 lpddi->guidInstance = joydevs[id].guid;
317 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
319 lpddi->guidFFDriver = GUID_NULL;
320 if (version >= 0x0800)
321 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
323 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
325 strcpy(lpddi->tszInstanceName, joydevs[id].name);
326 strcpy(lpddi->tszProductName, joydevs[id].device);
332 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
336 if (id >= have_joydevs) {
340 if (!((dwDevType == 0) ||
341 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
342 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
345 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
346 if (dwFlags & DIEDFL_FORCEFEEDBACK)
350 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
351 lpddi->guidInstance = joydevs[id].guid;
352 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
354 lpddi->guidFFDriver = GUID_NULL;
355 if (version >= 0x0800)
356 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
358 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
360 MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
361 MultiByteToWideChar(CP_ACP, 0, joydevs[id].device, -1, lpddi->tszProductName, MAX_PATH);
367 static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, struct JoyDev *joydev)
369 JoystickImpl* newDevice;
372 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
373 if (newDevice==NULL) {
377 newDevice->base.lpVtbl = jvt;
378 newDevice->base.ref = 1;
379 memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
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 for (i=0;i<ABS_MAX;i++) {
387 /* apps expect the range to be the same they would get from the
388 * GetProperty/range method */
389 newDevice->wantmin[i] = newDevice->joydev->havemin[i];
390 newDevice->wantmax[i] = newDevice->joydev->havemax[i];
392 * direct input defines a default for the deadzone somewhere; but as long
393 * as in map_axis the code for the dead zone is commented out its no
396 newDevice->deadz[i] = 0;
398 fake_current_js_state(newDevice);
400 /* wine uses DIJOYSTATE2 as it's internal format so copy
401 * the already defined format c_dfDIJoystick2 */
402 newDevice->df = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwSize);
403 if (newDevice->df == 0)
405 CopyMemory(newDevice->df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
407 /* copy default objects */
408 newDevice->df->rgodf = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
409 if (newDevice->df->rgodf == 0)
411 CopyMemory(newDevice->df->rgodf,c_dfDIJoystick2.rgodf,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
413 /* no do the same for the internal df */
414 newDevice->internal_df = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwSize);
415 if (newDevice->internal_df == 0)
417 CopyMemory(newDevice->internal_df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
419 /* copy default objects */
420 newDevice->internal_df->rgodf = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
421 if (newDevice->internal_df->rgodf == 0)
423 CopyMemory(newDevice->internal_df->rgodf,c_dfDIJoystick2.rgodf,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
425 /* create an offsets array */
426 newDevice->offsets = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,c_dfDIJoystick2.dwNumObjs*sizeof(int));
427 if (newDevice->offsets == 0)
430 calculate_ids(newDevice->internal_df);
432 /* create the default transform filter */
433 newDevice->transform = create_DataFormat(newDevice->internal_df, newDevice->df, newDevice->offsets);
434 calculate_ids(newDevice->df);
439 HeapFree(GetProcessHeap(),0,newDevice->df->rgodf);
440 HeapFree(GetProcessHeap(),0,newDevice->df);
441 HeapFree(GetProcessHeap(),0,newDevice->internal_df->rgodf);
442 HeapFree(GetProcessHeap(),0,newDevice->internal_df);
443 HeapFree(GetProcessHeap(),0,newDevice);
447 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
453 for (i=0; i<have_joydevs; i++) {
454 if (IsEqualGUID(&GUID_Joystick,rguid) ||
455 IsEqualGUID(&joydevs[i].guid,rguid)
457 if ((riid == NULL) ||
458 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
459 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
460 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
461 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
462 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, &joydevs[i]);
463 TRACE("Creating a Joystick device (%p)\n", *pdev);
465 ERR("out of memory\n");
466 return DIERR_OUTOFMEMORY;
470 return DIERR_NOINTERFACE;
475 return DIERR_DEVICENOTREG;
479 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
485 for (i=0; i<have_joydevs; i++) {
486 if (IsEqualGUID(&GUID_Joystick,rguid) ||
487 IsEqualGUID(&joydevs[i].guid,rguid)
489 if ((riid == NULL) ||
490 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
491 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
492 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
493 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
494 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, &joydevs[i]);
495 TRACE("Creating a Joystick device (%p)\n", *pdev);
497 ERR("out of memory\n");
498 return DIERR_OUTOFMEMORY;
502 return DIERR_NOINTERFACE;
507 return DIERR_DEVICENOTREG;
510 const struct dinput_device joystick_linuxinput_device = {
511 "Wine Linux-input joystick driver",
514 joydev_create_deviceA,
515 joydev_create_deviceW
518 /******************************************************************************
521 static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
523 JoystickImpl *This = (JoystickImpl *)iface;
526 ref = InterlockedDecrement(&This->base.ref);
530 /* Reset the FF state, free all effects, etc */
531 IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
533 /* Free the data queue */
534 HeapFree(GetProcessHeap(),0,This->data_queue);
536 /* Free the DataFormat */
537 HeapFree(GetProcessHeap(), 0, This->df->rgodf);
538 HeapFree(GetProcessHeap(), 0, This->df);
540 /* Free the offsets array */
541 HeapFree(GetProcessHeap(),0,This->offsets);
543 /* release the data transform filter */
544 release_DataFormat(This->transform);
546 HeapFree(GetProcessHeap(),0,This);
550 /******************************************************************************
551 * SetDataFormat : the application can choose the format of the data
552 * the device driver sends back with GetDeviceState.
554 static HRESULT WINAPI JoystickAImpl_SetDataFormat(
555 LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
558 JoystickImpl *This = (JoystickImpl *)iface;
560 TRACE("(this=%p,%p)\n",This,df);
563 WARN("invalid pointer\n");
567 if (df->dwSize != sizeof(*df)) {
568 WARN("invalid argument\n");
569 return DIERR_INVALIDPARAM;
572 _dump_DIDATAFORMAT(df);
574 if (This->joyfd!=-1) {
576 return DIERR_ACQUIRED;
579 HeapFree(GetProcessHeap(),0,This->df->rgodf);
580 HeapFree(GetProcessHeap(),0,This->df);
581 release_DataFormat(This->transform);
583 /* Store the new data format */
584 This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
585 if (This->df==NULL) {
586 return DIERR_OUTOFMEMORY;
588 memcpy(This->df, df, df->dwSize);
589 This->df->rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
590 if (This->df->rgodf==NULL) {
591 HeapFree(GetProcessHeap(), 0, This->df);
592 return DIERR_OUTOFMEMORY;
594 memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
596 This->transform = create_DataFormat(This->internal_df, This->df, This->offsets);
597 calculate_ids(This->df);
602 /******************************************************************************
603 * Acquire : gets exclusive control of the joystick
605 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
607 JoystickImpl *This = (JoystickImpl *)iface;
609 TRACE("(this=%p)\n",This);
612 if (This->df==NULL) {
613 return DIERR_INVALIDPARAM;
616 if (-1==(This->joyfd=open(This->joydev->device,O_RDWR))) {
617 if (-1==(This->joyfd=open(This->joydev->device,O_RDONLY))) {
618 /* Couldn't open the device at all */
619 perror(This->joydev->device);
620 return DIERR_NOTFOUND;
622 /* Couldn't open in r/w but opened in read-only. */
623 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This->joydev->device);
630 /******************************************************************************
631 * Unacquire : frees the joystick
633 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
635 JoystickImpl *This = (JoystickImpl *)iface;
637 TRACE("(this=%p)\n",This);
638 if (This->joyfd!=-1) {
648 * This maps the read value (from the input event) to a value in the
649 * 'wanted' range. It also autodetects the possible range of the axe and
650 * adapts values accordingly.
653 map_axis(JoystickImpl* This, int axis, int val) {
654 int xmin = This->joydev->axes[axis][AXE_ABSMIN];
655 int xmax = This->joydev->axes[axis][AXE_ABSMAX];
656 int hmax = This->joydev->havemax[axis];
657 int hmin = This->joydev->havemin[axis];
658 int wmin = This->wantmin[axis];
659 int wmax = This->wantmax[axis];
662 if (val > hmax) This->joydev->havemax[axis] = hmax = val;
663 if (val < hmin) This->joydev->havemin[axis] = hmin = val;
665 if (xmin == xmax) return val;
667 /* map the value from the hmin-hmax range into the wmin-wmax range */
668 ret = MulDiv( val - hmin, wmax - wmin, hmax - hmin ) + wmin;
670 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);
673 /* deadzone doesn't work comfortably enough right now. needs more testing*/
674 if ((ret > -deadz/2 ) && (ret < deadz/2)) {
675 FIXME("%d in deadzone, return mid.\n",val);
676 return (wmax-wmin)/2+wmin;
683 * set the current state of the js device as it would be with the middle
686 static void fake_current_js_state(JoystickImpl *ji)
689 /* center the axes */
690 ji->js.lX = test_bit(ji->joydev->absbits, ABS_X) ? map_axis(ji, ABS_X, ji->joydev->axes[ABS_X ][AXE_ABS]) : 0;
691 ji->js.lY = test_bit(ji->joydev->absbits, ABS_Y) ? map_axis(ji, ABS_Y, ji->joydev->axes[ABS_Y ][AXE_ABS]) : 0;
692 ji->js.lZ = test_bit(ji->joydev->absbits, ABS_Z) ? map_axis(ji, ABS_Z, ji->joydev->axes[ABS_Z ][AXE_ABS]) : 0;
693 ji->js.lRx = test_bit(ji->joydev->absbits, ABS_RX) ? map_axis(ji, ABS_RX, ji->joydev->axes[ABS_RX ][AXE_ABS]) : 0;
694 ji->js.lRy = test_bit(ji->joydev->absbits, ABS_RY) ? map_axis(ji, ABS_RY, ji->joydev->axes[ABS_RY ][AXE_ABS]) : 0;
695 ji->js.lRz = test_bit(ji->joydev->absbits, ABS_RZ) ? map_axis(ji, ABS_RZ, ji->joydev->axes[ABS_RZ ][AXE_ABS]) : 0;
696 ji->js.rglSlider[0] = test_bit(ji->joydev->absbits, ABS_THROTTLE) ? map_axis(ji, ABS_THROTTLE, ji->joydev->axes[ABS_THROTTLE][AXE_ABS]) : 0;
697 ji->js.rglSlider[1] = test_bit(ji->joydev->absbits, ABS_RUDDER) ? map_axis(ji, ABS_RUDDER, ji->joydev->axes[ABS_RUDDER ][AXE_ABS]) : 0;
698 /* POV center is -1 */
699 for (i=0; i<4; i++) {
700 ji->js.rgdwPOV[i] = -1;
705 * Maps an event value to a DX "clock" position:
710 static DWORD map_pov(int event_value, int is_x)
716 } else if (event_value>0) {
722 } else if (event_value>0) {
729 static int find_property_offset(JoystickImpl *This, LPCDIPROPHEADER ph)
734 for (i=0; i<This->df->dwNumObjs; i++) {
735 if (This->offsets[i]==ph->dwObj) {
741 for (i=0; i<This->df->dwNumObjs; i++) {
742 if ((This->df->rgodf[i].dwType & 0x00ffffff) == (ph->dwObj & 0x00ffffff)) {
743 ofs = This->df->rgodf[i].dwOfs;
748 for (i=0; i<This->df->dwNumObjs; i++) {
749 if (This->offsets[i]==ofs) {
756 FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
762 /* defines how the linux input system offset mappings into c_dfDIJoystick2 */
764 lxinput_to_djoy2_offset( int ie_type, int ie_code )
769 case ABS_X: return 0;
770 case ABS_Y: return 1;
771 case ABS_Z: return 2;
772 case ABS_RX: return 3;
773 case ABS_RY: return 4;
774 case ABS_RZ: return 5;
775 case ABS_THROTTLE: return 6;
776 case ABS_RUDDER: return 7;
778 case ABS_HAT0Y: return 8;
780 case ABS_HAT1Y: return 9;
782 case ABS_HAT2Y: return 10;
784 case ABS_HAT3Y: return 11;
786 FIXME("Unhandled EV_ABS(0x%02X)\n", ie_code);
793 WARN("DX8 does not support more than 128 buttons\n");
797 FIXME("Unhandled type(0x%02X)\n", ie_type);
801 /* convert wine format offset to user format object index */
802 static int offset_to_object(JoystickImpl *This, int offset)
806 for (i = 0; i < This->df->dwNumObjs; i++) {
807 if (This->df->rgodf[i].dwOfs == offset)
814 static void calculate_ids(LPDIDATAFORMAT df)
824 /* Make two passes over the format. The first counts the number
825 * for each type and the second sets the id */
826 for (i = 0; i < df->dwNumObjs; i++) {
827 if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS)
829 else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_POV)
831 else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_BUTTON)
837 button_base = axis + pov;
843 for (i = 0; i < df->dwNumObjs; i++) {
845 if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS) {
847 type = DIDFT_GETTYPE(df->rgodf[i].dwType) |
848 DIDFT_MAKEINSTANCE(axis + axis_base);
849 TRACE("axis type = 0x%08x\n", type);
850 } else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_POV) {
852 type = DIDFT_GETTYPE(df->rgodf[i].dwType) |
853 DIDFT_MAKEINSTANCE(pov + pov_base);
854 TRACE("POV type = 0x%08x\n", type);
855 } else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_BUTTON) {
857 type = DIDFT_GETTYPE(df->rgodf[i].dwType) |
858 DIDFT_MAKEINSTANCE(button + button_base);
859 TRACE("button type = 0x%08x\n", type);
861 df->rgodf[i].dwType = type;
865 static void joy_polldev(JoystickImpl *This) {
867 struct input_event ie;
874 plfd.fd = This->joyfd;
875 plfd.events = POLLIN;
877 if (poll(&plfd,1,0) != 1)
880 /* we have one event, so we can read */
881 if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
884 TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
886 case EV_KEY: /* button */
887 btn = This->joydev->buttons[ie.code];
888 TRACE("(%p) %d -> %d\n", This, ie.code, btn);
891 /* see if there is a mapping */
892 offset = lxinput_to_djoy2_offset(ie.type, btn);
896 /* and see if there is an offset in the df */
897 offset = This->offsets[offset];
901 This->js.rgbButtons[btn] = ie.value?0x80:0x00;
902 GEN_EVENT(offset,This->js.rgbButtons[btn],ie.time.tv_usec,(This->dinput->evsequence)++);
906 /* see if there is a mapping */
907 offset = lxinput_to_djoy2_offset(ie.type, ie.code);
911 /* and see if there is an offset in the df */
912 offset = This->offsets[offset];
918 This->js.lX = map_axis(This,ABS_X,ie.value);
919 GEN_EVENT(offset,This->js.lX,ie.time.tv_usec,(This->dinput->evsequence)++);
922 This->js.lY = map_axis(This,ABS_Y,ie.value);
923 GEN_EVENT(offset,This->js.lY,ie.time.tv_usec,(This->dinput->evsequence)++);
926 This->js.lZ = map_axis(This,ABS_Z,ie.value);
927 GEN_EVENT(offset,This->js.lZ,ie.time.tv_usec,(This->dinput->evsequence)++);
930 This->js.lRx = map_axis(This,ABS_RX,ie.value);
931 GEN_EVENT(offset,This->js.lRx,ie.time.tv_usec,(This->dinput->evsequence)++);
934 This->js.lRy = map_axis(This,ABS_RY,ie.value);
935 GEN_EVENT(offset,This->js.lRy,ie.time.tv_usec,(This->dinput->evsequence)++);
938 This->js.lRz = map_axis(This,ABS_RZ,ie.value);
939 GEN_EVENT(offset,This->js.lRz,ie.time.tv_usec,(This->dinput->evsequence)++);
942 This->js.rglSlider[0] = map_axis(This,ABS_THROTTLE,ie.value);
943 GEN_EVENT(offset,This->js.rglSlider[0],ie.time.tv_usec,(This->dinput->evsequence)++);
946 This->js.rglSlider[1] = map_axis(This,ABS_RUDDER,ie.value);
947 GEN_EVENT(offset,This->js.rglSlider[1],ie.time.tv_usec,(This->dinput->evsequence)++);
951 This->js.rgdwPOV[0] = map_pov(ie.value,ie.code==ABS_HAT0X);
952 GEN_EVENT(offset,This->js.rgdwPOV[0],ie.time.tv_usec,(This->dinput->evsequence)++);
956 This->js.rgdwPOV[1] = map_pov(ie.value,ie.code==ABS_HAT1X);
957 GEN_EVENT(offset,This->js.rgdwPOV[1],ie.time.tv_usec,(This->dinput->evsequence)++);
961 This->js.rgdwPOV[2] = map_pov(ie.value,ie.code==ABS_HAT2X);
962 GEN_EVENT(offset,This->js.rgdwPOV[2],ie.time.tv_usec,(This->dinput->evsequence)++);
966 This->js.rgdwPOV[3] = map_pov(ie.value,ie.code==ABS_HAT3X);
967 GEN_EVENT(offset,This->js.rgdwPOV[3],ie.time.tv_usec,(This->dinput->evsequence)++);
970 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie.code,ie.value);
974 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
976 This->ff_state = ie.value;
981 /* there is nothing to do */
985 FIXME("joystick cannot handle type %d event (code %d)\n",ie.type,ie.code);
991 /******************************************************************************
992 * GetDeviceState : returns the "state" of the joystick.
995 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
996 LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
998 JoystickImpl *This = (JoystickImpl *)iface;
1000 TRACE("(this=%p,0x%08x,%p)\n", This, len, ptr);
1002 if (This->joyfd==-1) {
1003 WARN("not acquired\n");
1004 return DIERR_NOTACQUIRED;
1009 /* convert and copy data to user supplied buffer */
1010 fill_DataFormat(ptr, &This->js, This->transform);
1015 /******************************************************************************
1016 * GetDeviceData : gets buffered input data.
1018 static HRESULT WINAPI JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
1020 LPDIDEVICEOBJECTDATA dod,
1024 JoystickImpl *This = (JoystickImpl *)iface;
1029 TRACE("(%p)->(dods=%d,entries=%d,fl=0x%08x)\n", This, dodsize, *entries, flags);
1031 if (This->joyfd==-!1) {
1032 WARN("not acquired\n");
1033 return DIERR_NOTACQUIRED;
1037 if (flags & DIGDD_PEEK)
1038 FIXME("DIGDD_PEEK\n");
1040 len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0)
1041 + (This->queue_head - This->queue_tail);
1047 TRACE("Application discarding %d event(s).\n", len);
1050 nqtail = This->queue_tail + len;
1051 while (nqtail >= This->queue_len)
1052 nqtail -= This->queue_len;
1054 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
1055 ERR("Wrong structure size !\n");
1056 return DIERR_INVALIDPARAM;
1060 TRACE("Application retrieving %d event(s).\n", len);
1063 nqtail = This->queue_tail;
1065 /* Copy the buffered data into the application queue */
1066 memcpy((char *)dod + *entries * dodsize, This->data_queue + nqtail, dodsize);
1067 /* Advance position */
1069 if (nqtail >= This->queue_len)
1070 nqtail -= This->queue_len;
1076 if (This->overflow) {
1077 hr = DI_BUFFEROVERFLOW;
1078 if (!(flags & DIGDD_PEEK)) {
1079 This->overflow = FALSE;
1083 if (!(flags & DIGDD_PEEK))
1084 This->queue_tail = nqtail;
1089 /******************************************************************************
1090 * SetProperty : change input device properties
1092 static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
1096 JoystickImpl *This = (JoystickImpl *)iface;
1099 WARN("invalid argument\n");
1100 return DIERR_INVALIDPARAM;
1103 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
1104 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
1105 ph->dwSize, ph->dwHeaderSize, ph->dwObj, ph->dwHow);
1107 if (!HIWORD(rguid)) {
1108 switch (LOWORD(rguid)) {
1109 case (DWORD) DIPROP_BUFFERSIZE: {
1110 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1112 TRACE("buffersize = %d\n", pd->dwData);
1113 if (This->data_queue) {
1114 This->data_queue = HeapReAlloc(GetProcessHeap(),0, This->data_queue, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
1116 This->data_queue = HeapAlloc(GetProcessHeap(),0, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
1118 This->queue_head = 0;
1119 This->queue_tail = 0;
1120 This->queue_len = pd->dwData;
1123 case (DWORD)DIPROP_RANGE: {
1124 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
1126 if (ph->dwHow == DIPH_DEVICE) {
1128 TRACE("proprange(%d,%d) all\n", pr->lMin, pr->lMax);
1129 for (i = 0; i < This->df->dwNumObjs; i++) {
1130 This->wantmin[i] = pr->lMin;
1131 This->wantmax[i] = pr->lMax;
1134 int obj = find_property_offset(This, ph);
1135 TRACE("proprange(%d,%d) obj=%d\n", pr->lMin, pr->lMax, obj);
1137 This->wantmin[obj] = pr->lMin;
1138 This->wantmax[obj] = pr->lMax;
1141 fake_current_js_state(This);
1144 case (DWORD)DIPROP_DEADZONE: {
1145 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1146 if (ph->dwHow == DIPH_DEVICE) {
1148 TRACE("deadzone(%d) all\n", pd->dwData);
1149 for (i = 0; i < This->df->dwNumObjs; i++) {
1150 This->deadz[i] = pd->dwData;
1153 int obj = find_property_offset(This, ph);
1154 TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
1156 This->deadz[obj] = pd->dwData;
1159 fake_current_js_state(This);
1163 FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
1170 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
1171 LPDIRECTINPUTDEVICE8A iface,
1172 LPDIDEVCAPS lpDIDevCaps)
1174 JoystickImpl *This = (JoystickImpl *)iface;
1175 int i,axes,buttons,povs;
1177 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
1180 WARN("invalid pointer\n");
1184 if (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) {
1185 WARN("invalid argument\n");
1186 return DIERR_INVALIDPARAM;
1189 lpDIDevCaps->dwFlags = DIDC_ATTACHED;
1190 if (This->dinput->dwVersion >= 0x0800)
1191 lpDIDevCaps->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
1193 lpDIDevCaps->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
1196 for (i=0;i<ABS_MAX;i++) {
1197 if (!test_bit(This->joydev->absbits,i)) continue;
1199 case ABS_HAT0X: case ABS_HAT0Y:
1200 case ABS_HAT1X: case ABS_HAT1Y:
1201 case ABS_HAT2X: case ABS_HAT2Y:
1202 case ABS_HAT3X: case ABS_HAT3Y:
1203 /* will be handled as POV - see below */
1210 for (i=0;i<KEY_MAX;i++) if (test_bit(This->joydev->keybits,i)) buttons++;
1212 for (i=0; i<4; i++) {
1213 if (test_bit(This->joydev->absbits,ABS_HAT0X+(i<<1)) && test_bit(This->joydev->absbits,ABS_HAT0Y+(i<<1))) {
1218 if (This->joydev->has_ff)
1219 lpDIDevCaps->dwFlags |= DIDC_FORCEFEEDBACK;
1221 lpDIDevCaps->dwAxes = axes;
1222 lpDIDevCaps->dwButtons = buttons;
1223 lpDIDevCaps->dwPOVs = povs;
1228 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface) {
1229 JoystickImpl *This = (JoystickImpl *)iface;
1230 TRACE("(%p)\n",This);
1232 if (This->joyfd==-1) {
1233 return DIERR_NOTACQUIRED;
1240 /******************************************************************************
1241 * EnumObjects : enumerate the different buttons and axis...
1243 static HRESULT WINAPI JoystickAImpl_EnumObjects(
1244 LPDIRECTINPUTDEVICE8A iface,
1245 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
1249 JoystickImpl *This = (JoystickImpl *)iface;
1250 DIDEVICEOBJECTINSTANCEA ddoi;
1251 int user_offset, user_object;
1253 TRACE("(this=%p,%p,%p,%08x)\n", This, lpCallback, lpvRef, dwFlags);
1254 if (TRACE_ON(dinput)) {
1255 TRACE(" - flags = ");
1256 _dump_EnumObjects_flags(dwFlags);
1260 /* Only the fields till dwFFMaxForce are relevant */
1261 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
1263 /* For the joystick, do as is done in the GetCapabilities function */
1264 /* FIXME: needs more items */
1265 if ((dwFlags == DIDFT_ALL) ||
1266 (dwFlags & DIDFT_AXIS)) {
1269 for (i = 0; i < ABS_MAX; i++) {
1270 if (!test_bit(This->joydev->absbits,i)) continue;
1274 ddoi.guidType = GUID_XAxis;
1277 ddoi.guidType = GUID_YAxis;
1280 ddoi.guidType = GUID_ZAxis;
1283 ddoi.guidType = GUID_RxAxis;
1286 ddoi.guidType = GUID_RyAxis;
1289 ddoi.guidType = GUID_RzAxis;
1292 ddoi.guidType = GUID_Slider;
1295 ddoi.guidType = GUID_Slider;
1297 case ABS_HAT0X: case ABS_HAT0Y:
1298 case ABS_HAT1X: case ABS_HAT1Y:
1299 case ABS_HAT2X: case ABS_HAT2Y:
1300 case ABS_HAT3X: case ABS_HAT3Y:
1301 /* will be handled as POV - see below */
1304 FIXME("unhandled abs axis 0x%02x, ignoring!\n",i);
1307 user_offset = lxinput_to_djoy2_offset(EV_ABS, i);
1308 if (user_offset == -1) {
1311 user_offset = This->offsets[user_offset];
1312 if (user_offset == -1) {
1315 user_object = offset_to_object(This, user_offset);
1316 ddoi.dwType = This->df->rgodf[user_object].dwType & 0x00ffffff;
1317 ddoi.dwOfs = This->df->rgodf[user_object].dwOfs;
1318 /* Linux event force feedback supports only (and always) x and y axes */
1319 if (i == ABS_X || i == ABS_Y) {
1320 if (This->joydev->has_ff)
1321 ddoi.dwFlags |= DIDOI_FFACTUATOR;
1323 sprintf(ddoi.tszName, "%d-Axis", i);
1324 _dump_OBJECTINSTANCEA(&ddoi);
1325 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) {
1331 if ((dwFlags == DIDFT_ALL) ||
1332 (dwFlags & DIDFT_POV)) {
1334 ddoi.guidType = GUID_POV;
1335 for (i=0; i<4; i++) {
1336 if (test_bit(This->joydev->absbits,ABS_HAT0X+(i<<1)) && test_bit(This->joydev->absbits,ABS_HAT0Y+(i<<1))) {
1337 user_offset = lxinput_to_djoy2_offset(EV_ABS, ABS_HAT0X+i);
1338 if (user_offset == -1) {
1341 user_offset = This->offsets[user_offset];
1342 if (user_offset == -1) {
1345 user_object = offset_to_object(This, user_offset);
1346 ddoi.dwType = This->df->rgodf[user_object].dwType & 0x00ffffff;
1347 ddoi.dwOfs = This->df->rgodf[user_object].dwOfs;
1348 sprintf(ddoi.tszName, "%d-POV", i);
1349 _dump_OBJECTINSTANCEA(&ddoi);
1350 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) {
1357 if ((dwFlags == DIDFT_ALL) ||
1358 (dwFlags & DIDFT_BUTTON)) {
1361 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
1363 ddoi.guidType = GUID_Button;
1365 for (i = 0; i < KEY_MAX; i++) {
1366 if (!test_bit(This->joydev->keybits,i)) continue;
1367 user_offset = lxinput_to_djoy2_offset(EV_KEY, btncount);
1368 if (user_offset == -1) {
1371 user_offset = This->offsets[user_offset];
1372 if (user_offset == -1) {
1375 user_object = offset_to_object(This, user_offset);
1376 ddoi.dwType = This->df->rgodf[user_object].dwType & 0x00ffffff;
1377 ddoi.dwOfs = This->df->rgodf[user_object].dwOfs;
1378 sprintf(ddoi.tszName, "%d-Button", btncount);
1380 _dump_OBJECTINSTANCEA(&ddoi);
1381 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) {
1390 static HRESULT WINAPI JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
1391 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
1395 JoystickImpl *This = (JoystickImpl *)iface;
1397 device_enumobjects_AtoWcb_data data;
1399 data.lpCallBack = lpCallback;
1400 data.lpvRef = lpvRef;
1402 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
1405 /******************************************************************************
1406 * GetProperty : get input device properties
1408 static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
1410 LPDIPROPHEADER pdiph)
1412 JoystickImpl *This = (JoystickImpl *)iface;
1414 TRACE("(this=%p,%s,%p)\n",
1415 iface, debugstr_guid(rguid), pdiph);
1417 if (TRACE_ON(dinput))
1418 _dump_DIPROPHEADER(pdiph);
1420 if (!HIWORD(rguid)) {
1421 switch (LOWORD(rguid)) {
1422 case (DWORD) DIPROP_BUFFERSIZE: {
1423 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1425 TRACE(" return buffersize = %d\n",This->queue_len);
1426 pd->dwData = This->queue_len;
1430 case (DWORD) DIPROP_RANGE: {
1431 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
1432 int obj = find_property_offset(This, pdiph);
1434 pr->lMin = This->joydev->havemin[obj];
1435 pr->lMax = This->joydev->havemax[obj];
1436 TRACE("range(%d, %d) obj=%d\n", pr->lMin, pr->lMax, obj);
1443 FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
1452 /******************************************************************************
1453 * CreateEffect - Create a new FF effect with the specified params
1455 static HRESULT WINAPI JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface,
1458 LPDIRECTINPUTEFFECT *ppdef,
1459 LPUNKNOWN pUnkOuter)
1461 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1462 EffectListItem* new = NULL;
1463 HRESULT retval = DI_OK;
1466 JoystickImpl* This = (JoystickImpl*)iface;
1467 TRACE("(this=%p,%p,%p,%p,%p)\n", This, rguid, lpeff, ppdef, pUnkOuter);
1469 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1470 TRACE("not available (compiled w/o ff support)\n");
1475 new = malloc(sizeof(EffectListItem));
1476 new->next = This->top_effect;
1477 This->top_effect = new;
1479 retval = linuxinput_create_effect(&(This->joyfd), rguid, &(new->ref));
1480 if (retval != DI_OK)
1484 retval = IDirectInputEffect_SetParameters(new->ref, lpeff, 0);
1485 if (retval != DI_OK && retval != DI_DOWNLOADSKIPPED)
1490 if (pUnkOuter != NULL)
1491 FIXME("Interface aggregation not implemented.\n");
1495 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1498 /*******************************************************************************
1499 * EnumEffects - Enumerate available FF effects
1501 static HRESULT WINAPI JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface,
1502 LPDIENUMEFFECTSCALLBACKA lpCallback,
1506 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1507 DIEFFECTINFOA dei; /* feif */
1508 DWORD type = DIEFT_GETTYPE(dwEffType);
1509 JoystickImpl* This = (JoystickImpl*)iface;
1511 TRACE("(this=%p,%p,%d) type=%d\n", This, pvRef, dwEffType, type);
1513 dei.dwSize = sizeof(DIEFFECTINFOA);
1515 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1516 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1517 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1518 (*lpCallback)(&dei, pvRef);
1521 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1522 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1523 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1524 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1525 (*lpCallback)(&dei, pvRef);
1527 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1528 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1529 (*lpCallback)(&dei, pvRef);
1531 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1532 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1533 (*lpCallback)(&dei, pvRef);
1535 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1536 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1537 (*lpCallback)(&dei, pvRef);
1539 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1540 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1541 (*lpCallback)(&dei, pvRef);
1545 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1546 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1547 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1548 (*lpCallback)(&dei, pvRef);
1551 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1552 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1553 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1554 (*lpCallback)(&dei, pvRef);
1556 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1557 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1558 (*lpCallback)(&dei, pvRef);
1560 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1561 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1562 (*lpCallback)(&dei, pvRef);
1564 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1565 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1566 (*lpCallback)(&dei, pvRef);
1575 static HRESULT WINAPI JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface,
1576 LPDIENUMEFFECTSCALLBACKW lpCallback,
1580 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1581 /* seems silly to duplicate all this code but all the structures and functions
1582 * are actually different (A/W) */
1583 DIEFFECTINFOW dei; /* feif */
1584 DWORD type = DIEFT_GETTYPE(dwEffType);
1585 JoystickImpl* This = (JoystickImpl*)iface;
1586 int xfd = This->joyfd;
1588 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This, pvRef, dwEffType, type, xfd);
1590 dei.dwSize = sizeof(DIEFFECTINFOW);
1592 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1593 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1594 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1595 (*lpCallback)(&dei, pvRef);
1598 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1599 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1600 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1601 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1602 (*lpCallback)(&dei, pvRef);
1604 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1605 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1606 (*lpCallback)(&dei, pvRef);
1608 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1609 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1610 (*lpCallback)(&dei, pvRef);
1612 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1613 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1614 (*lpCallback)(&dei, pvRef);
1616 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1617 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1618 (*lpCallback)(&dei, pvRef);
1622 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1623 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1624 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1625 (*lpCallback)(&dei, pvRef);
1628 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1629 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1630 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1631 (*lpCallback)(&dei, pvRef);
1633 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1634 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1635 (*lpCallback)(&dei, pvRef);
1637 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1638 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1639 (*lpCallback)(&dei, pvRef);
1641 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1642 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1643 (*lpCallback)(&dei, pvRef);
1647 /* return to unacquired state if that's where it was */
1649 IDirectInputDevice8_Unacquire(iface);
1655 /*******************************************************************************
1656 * GetEffectInfo - Get information about a particular effect
1658 static HRESULT WINAPI JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface,
1659 LPDIEFFECTINFOA pdei,
1662 JoystickImpl* This = (JoystickImpl*)iface;
1664 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1666 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1667 return linuxinput_get_info_A(This->joyfd, guid, pdei);
1673 static HRESULT WINAPI JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface,
1674 LPDIEFFECTINFOW 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_W(This->joyfd, guid, pdei);
1688 /*******************************************************************************
1689 * GetForceFeedbackState - Get information about the device's FF state
1691 static HRESULT WINAPI JoystickAImpl_GetForceFeedbackState(
1692 LPDIRECTINPUTDEVICE8A iface,
1695 JoystickImpl* This = (JoystickImpl*)iface;
1697 TRACE("(this=%p,%p)\n", This, pdwOut);
1701 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1702 /* DIGFFS_STOPPED is the only mandatory flag to report */
1703 if (This->ff_state == FF_STATUS_STOPPED)
1704 (*pdwOut) |= DIGFFS_STOPPED;
1710 /*******************************************************************************
1711 * SendForceFeedbackCommand - Send a command to the device's FF system
1713 static HRESULT WINAPI JoystickAImpl_SendForceFeedbackCommand(
1714 LPDIRECTINPUTDEVICE8A iface,
1717 JoystickImpl* This = (JoystickImpl*)iface;
1718 TRACE("(this=%p,%d)\n", This, dwFlags);
1720 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1721 if (dwFlags == DISFFC_STOPALL) {
1722 /* Stop all effects */
1723 EffectListItem* itr = This->top_effect;
1725 IDirectInputEffect_Stop(itr->ref);
1728 } else if (dwFlags == DISFFC_RESET) {
1729 /* Stop, unload, release and free all effects */
1730 /* This returns the device to its "bare" state */
1731 while (This->top_effect) {
1732 EffectListItem* temp = This->top_effect;
1733 IDirectInputEffect_Stop(temp->ref);
1734 IDirectInputEffect_Unload(temp->ref);
1735 IDirectInputEffect_Release(temp->ref);
1736 This->top_effect = temp->next;
1739 } else if (dwFlags == DISFFC_PAUSE || dwFlags == DISFFC_CONTINUE) {
1740 FIXME("No support for Pause or Continue in linux\n");
1741 } else if (dwFlags == DISFFC_SETACTUATORSOFF
1742 || dwFlags == DISFFC_SETACTUATORSON) {
1743 FIXME("No direct actuator control in linux\n");
1745 FIXME("Unknown Force Feedback Command!\n");
1746 return DIERR_INVALIDPARAM;
1750 return DIERR_UNSUPPORTED;
1754 /*******************************************************************************
1755 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1756 * created for this device.
1758 static HRESULT WINAPI JoystickAImpl_EnumCreatedEffectObjects(
1759 LPDIRECTINPUTDEVICE8A iface,
1760 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1764 /* this function is safe to call on non-ff-enabled builds */
1766 JoystickImpl* This = (JoystickImpl*)iface;
1767 EffectListItem* itr = This->top_effect;
1768 TRACE("(this=%p,%p,%p,%d)\n", This, lpCallback, pvRef, dwFlags);
1771 return DIERR_INVALIDPARAM;
1774 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1777 (*lpCallback)(itr->ref, pvRef);
1784 static const IDirectInputDevice8AVtbl JoystickAvt =
1786 IDirectInputDevice2AImpl_QueryInterface,
1787 IDirectInputDevice2AImpl_AddRef,
1788 JoystickAImpl_Release,
1789 JoystickAImpl_GetCapabilities,
1790 JoystickAImpl_EnumObjects,
1791 JoystickAImpl_GetProperty,
1792 JoystickAImpl_SetProperty,
1793 JoystickAImpl_Acquire,
1794 JoystickAImpl_Unacquire,
1795 JoystickAImpl_GetDeviceState,
1796 JoystickAImpl_GetDeviceData,
1797 JoystickAImpl_SetDataFormat,
1798 IDirectInputDevice2AImpl_SetEventNotification,
1799 IDirectInputDevice2AImpl_SetCooperativeLevel,
1800 IDirectInputDevice2AImpl_GetObjectInfo,
1801 IDirectInputDevice2AImpl_GetDeviceInfo,
1802 IDirectInputDevice2AImpl_RunControlPanel,
1803 IDirectInputDevice2AImpl_Initialize,
1804 JoystickAImpl_CreateEffect,
1805 JoystickAImpl_EnumEffects,
1806 JoystickAImpl_GetEffectInfo,
1807 JoystickAImpl_GetForceFeedbackState,
1808 JoystickAImpl_SendForceFeedbackCommand,
1809 JoystickAImpl_EnumCreatedEffectObjects,
1810 IDirectInputDevice2AImpl_Escape,
1812 IDirectInputDevice2AImpl_SendDeviceData,
1813 IDirectInputDevice7AImpl_EnumEffectsInFile,
1814 IDirectInputDevice7AImpl_WriteEffectToFile,
1815 IDirectInputDevice8AImpl_BuildActionMap,
1816 IDirectInputDevice8AImpl_SetActionMap,
1817 IDirectInputDevice8AImpl_GetImageInfo
1820 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1821 # define XCAST(fun) (typeof(JoystickWvt.fun))
1823 # define XCAST(fun) (void*)
1826 static const IDirectInputDevice8WVtbl JoystickWvt =
1828 IDirectInputDevice2WImpl_QueryInterface,
1829 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1830 XCAST(Release)JoystickAImpl_Release,
1831 XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1832 JoystickWImpl_EnumObjects,
1833 XCAST(GetProperty)JoystickAImpl_GetProperty,
1834 XCAST(SetProperty)JoystickAImpl_SetProperty,
1835 XCAST(Acquire)JoystickAImpl_Acquire,
1836 XCAST(Unacquire)JoystickAImpl_Unacquire,
1837 XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1838 XCAST(GetDeviceData)JoystickAImpl_GetDeviceData,
1839 XCAST(SetDataFormat)JoystickAImpl_SetDataFormat,
1840 XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
1841 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1842 IDirectInputDevice2WImpl_GetObjectInfo,
1843 IDirectInputDevice2WImpl_GetDeviceInfo,
1844 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1845 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1846 XCAST(CreateEffect)JoystickAImpl_CreateEffect,
1847 JoystickWImpl_EnumEffects,
1848 JoystickWImpl_GetEffectInfo,
1849 XCAST(GetForceFeedbackState)JoystickAImpl_GetForceFeedbackState,
1850 XCAST(SendForceFeedbackCommand)JoystickAImpl_SendForceFeedbackCommand,
1851 XCAST(EnumCreatedEffectObjects)JoystickAImpl_EnumCreatedEffectObjects,
1852 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1853 XCAST(Poll)JoystickAImpl_Poll,
1854 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1855 IDirectInputDevice7WImpl_EnumEffectsInFile,
1856 IDirectInputDevice7WImpl_WriteEffectToFile,
1857 IDirectInputDevice8WImpl_BuildActionMap,
1858 IDirectInputDevice8WImpl_SetActionMap,
1859 IDirectInputDevice8WImpl_GetImageInfo
1863 #else /* HAVE_CORRECT_LINUXINPUT_H */
1865 const struct dinput_device joystick_linuxinput_device = {
1866 "Wine Linux-input joystick driver",
1873 #endif /* HAVE_CORRECT_LINUXINPUT_H */