push c6bab2db4fc296bd36abf8f7d9cf443d4a73048e
[wine/hacks.git] / dlls / dinput / joystick_linuxinput.c
blobf9f6146e7a3ce3ce833a1b7a747b7ec5bd462a58
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
23 #include "config.h"
24 #include "wine/port.h"
26 #include <assert.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <time.h>
31 #ifdef HAVE_UNISTD_H
32 # include <unistd.h>
33 #endif
34 #ifdef HAVE_SYS_TIME_H
35 # include <sys/time.h>
36 #endif
37 #include <fcntl.h>
38 #ifdef HAVE_SYS_IOCTL_H
39 # include <sys/ioctl.h>
40 #endif
41 #include <errno.h>
42 #ifdef HAVE_SYS_ERRNO_H
43 # include <sys/errno.h>
44 #endif
45 #ifdef HAVE_LINUX_INPUT_H
46 # include <linux/input.h>
47 # undef SW_MAX
48 # if defined(EVIOCGBIT) && defined(EV_ABS) && defined(BTN_PINKIE)
49 # define HAVE_CORRECT_LINUXINPUT_H
50 # endif
51 #endif
52 #ifdef HAVE_SYS_POLL_H
53 # include <sys/poll.h>
54 #endif
56 #include "wine/debug.h"
57 #include "wine/unicode.h"
58 #include "wine/list.h"
59 #include "windef.h"
60 #include "winbase.h"
61 #include "winerror.h"
62 #include "winreg.h"
63 #include "dinput.h"
65 #include "dinput_private.h"
66 #include "device_private.h"
67 #include "joystick_private.h"
69 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
71 #ifdef HAVE_CORRECT_LINUXINPUT_H
73 #define EVDEVPREFIX "/dev/input/event"
75 /* Wine joystick driver object instances */
76 #define WINE_JOYSTICK_MAX_AXES 8
77 #define WINE_JOYSTICK_MAX_POVS 4
78 #define WINE_JOYSTICK_MAX_BUTTONS 128
80 struct wine_input_absinfo {
81 LONG value;
82 LONG minimum;
83 LONG maximum;
84 LONG fuzz;
85 LONG flat;
88 /* implemented in effect_linuxinput.c */
89 HRESULT linuxinput_create_effect(int* fd, REFGUID rguid, struct list *parent_list_entry, LPDIRECTINPUTEFFECT* peff);
90 HRESULT linuxinput_get_info_A(int fd, REFGUID rguid, LPDIEFFECTINFOA info);
91 HRESULT linuxinput_get_info_W(int fd, REFGUID rguid, LPDIEFFECTINFOW info);
93 typedef struct JoystickImpl JoystickImpl;
94 static const IDirectInputDevice8AVtbl JoystickAvt;
95 static const IDirectInputDevice8WVtbl JoystickWvt;
97 struct JoyDev {
98 char *device;
99 char *name;
100 GUID guid;
102 int has_ff;
103 int num_effects;
105 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
106 BYTE evbits[(EV_MAX+7)/8];
107 BYTE absbits[(ABS_MAX+7)/8];
108 BYTE keybits[(KEY_MAX+7)/8];
109 BYTE ffbits[(FF_MAX+7)/8];
111 /* data returned by the EVIOCGABS() ioctl */
112 struct wine_input_absinfo axes[ABS_MAX];
115 struct JoystickImpl
117 struct JoystickGenericImpl generic;
118 struct JoyDev *joydev;
120 /* joystick private */
121 int joyfd;
123 int axes[ABS_MAX];
124 POINTL povs[4];
126 /* LUT for KEY_ to offset in rgbButtons */
127 BYTE buttons[KEY_MAX];
129 /* Force feedback variables */
130 struct list ff_effects;
131 int ff_state;
132 int ff_autocenter;
133 int ff_gain;
136 static void fake_current_js_state(JoystickImpl *ji);
137 static void find_joydevs(void);
138 static void joy_polldev(JoystickGenericImpl *This);
140 /* This GUID is slightly different from the linux joystick one. Take note. */
141 static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
142 0x9e573eda,
143 0x7734,
144 0x11d2,
145 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
148 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
150 #define MAX_JOYDEV 64
152 static int have_joydevs = -1;
153 static struct JoyDev *joydevs = NULL;
155 static void find_joydevs(void)
157 int i;
159 if (InterlockedCompareExchange(&have_joydevs, 0, -1) != -1)
160 /* Someone beat us to it */
161 return;
163 for (i = 0; i < MAX_JOYDEV; i++)
165 char buf[MAX_PATH];
166 struct JoyDev joydev = {0};
167 int fd;
168 int no_ff_check = 0;
169 int j;
170 struct JoyDev *new_joydevs;
172 snprintf(buf, sizeof(buf), EVDEVPREFIX"%d", i);
174 if ((fd = open(buf, O_RDWR)) == -1)
176 fd = open(buf, O_RDONLY);
177 no_ff_check = 1;
180 if (fd == -1)
182 WARN("Failed to open \"%s\": %d %s\n", buf, errno, strerror(errno));
183 continue;
186 if (ioctl(fd, EVIOCGBIT(0, sizeof(joydev.evbits)), joydev.evbits) == -1)
188 WARN("ioct(EVIOCGBIT, 0) failed: %d %s\n", errno, strerror(errno));
189 close(fd);
190 continue;
192 if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(joydev.absbits)), joydev.absbits) == -1)
194 WARN("ioct(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno, strerror(errno));
195 close(fd);
196 continue;
198 if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(joydev.keybits)), joydev.keybits) == -1)
200 WARN("ioct(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno, strerror(errno));
201 close(fd);
202 continue;
205 /* A true joystick has at least axis X and Y, and at least 1
206 * button. copied from linux/drivers/input/joydev.c */
207 if (!test_bit(joydev.absbits, ABS_X) || !test_bit(joydev.absbits, ABS_Y) ||
208 !(test_bit(joydev.keybits, BTN_TRIGGER) ||
209 test_bit(joydev.keybits, BTN_A) ||
210 test_bit(joydev.keybits, BTN_1)))
212 close(fd);
213 continue;
216 if (!(joydev.device = HeapAlloc(GetProcessHeap(), 0, strlen(buf) + 1)))
218 close(fd);
219 continue;
221 strcpy(joydev.device, buf);
223 buf[MAX_PATH - 1] = 0;
224 if (ioctl(fd, EVIOCGNAME(MAX_PATH - 1), buf) != -1 &&
225 (joydev.name = HeapAlloc(GetProcessHeap(), 0, strlen(buf) + 1)))
226 strcpy(joydev.name, buf);
227 else
228 joydev.name = joydev.device;
230 joydev.guid = DInput_Wine_Joystick_Base_GUID;
231 joydev.guid.Data3 += have_joydevs;
233 TRACE("Found a joystick on %s: %s (%s)\n",
234 joydev.device, joydev.name,
235 debugstr_guid(&joydev.guid)
238 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
239 if (!no_ff_check &&
240 test_bit(joydev.evbits, EV_FF) &&
241 ioctl(fd, EVIOCGBIT(EV_FF, sizeof(joydev.ffbits)), joydev.ffbits) != -1 &&
242 ioctl(fd, EVIOCGEFFECTS, &joydev.num_effects) != -1 &&
243 joydev.num_effects > 0)
245 TRACE(" ... with force feedback\n");
246 joydev.has_ff = 1;
248 #endif
250 for (j = 0; j < ABS_MAX;j ++)
252 if (!test_bit(joydev.absbits, j)) continue;
253 if (ioctl(fd, EVIOCGABS(j), &(joydev.axes[j])) != -1)
255 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
257 joydev.axes[j].value,
258 joydev.axes[j].minimum,
259 joydev.axes[j].maximum,
260 joydev.axes[j].fuzz,
261 joydev.axes[j].flat
266 if (!have_joydevs)
267 new_joydevs = HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev));
268 else
269 new_joydevs = HeapReAlloc(GetProcessHeap(), 0, joydevs, (1 + have_joydevs) * sizeof(struct JoyDev));
271 if (!new_joydevs)
273 close(fd);
274 continue;
276 joydevs = new_joydevs;
277 memcpy(joydevs + have_joydevs, &joydev, sizeof(joydev));
278 have_joydevs++;
280 close(fd);
284 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
286 DWORD dwSize = lpddi->dwSize;
288 TRACE("%d %p\n", dwSize, lpddi);
289 memset(lpddi, 0, dwSize);
291 lpddi->dwSize = dwSize;
292 lpddi->guidInstance = joydevs[id].guid;
293 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
294 lpddi->guidFFDriver = GUID_NULL;
296 if (version >= 0x0800)
297 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
298 else
299 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
301 strcpy(lpddi->tszInstanceName, joydevs[id].name);
302 strcpy(lpddi->tszProductName, joydevs[id].name);
305 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
307 DWORD dwSize = lpddi->dwSize;
309 TRACE("%d %p\n", dwSize, lpddi);
310 memset(lpddi, 0, dwSize);
312 lpddi->dwSize = dwSize;
313 lpddi->guidInstance = joydevs[id].guid;
314 lpddi->guidProduct = DInput_Wine_Joystick_Base_GUID;
315 lpddi->guidFFDriver = GUID_NULL;
317 if (version >= 0x0800)
318 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
319 else
320 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
322 MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
323 MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszProductName, MAX_PATH);
326 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
328 find_joydevs();
330 if (id >= have_joydevs) {
331 return FALSE;
334 if (!((dwDevType == 0) ||
335 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
336 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
337 return FALSE;
339 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
340 if (dwFlags & DIEDFL_FORCEFEEDBACK)
341 return FALSE;
342 #endif
344 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
345 fill_joystick_dideviceinstanceA(lpddi, version, id);
346 return TRUE;
348 return FALSE;
351 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
353 find_joydevs();
355 if (id >= have_joydevs) {
356 return FALSE;
359 if (!((dwDevType == 0) ||
360 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
361 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
362 return FALSE;
364 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
365 if (dwFlags & DIEDFL_FORCEFEEDBACK)
366 return FALSE;
367 #endif
369 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
370 fill_joystick_dideviceinstanceW(lpddi, version, id);
371 return TRUE;
373 return FALSE;
376 static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, unsigned short index)
378 JoystickImpl* newDevice;
379 LPDIDATAFORMAT df = NULL;
380 int i, idx = 0;
381 char buffer[MAX_PATH+16];
382 HKEY hkey, appkey;
383 LONG def_deadzone = 0;
385 newDevice = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(JoystickImpl));
386 if (!newDevice) return NULL;
388 newDevice->generic.base.lpVtbl = jvt;
389 newDevice->generic.base.ref = 1;
390 newDevice->generic.base.guid = *rguid;
391 newDevice->generic.base.dinput = dinput;
392 newDevice->generic.joy_polldev = joy_polldev;
393 newDevice->joyfd = -1;
394 newDevice->joydev = &joydevs[index];
395 newDevice->generic.name = newDevice->joydev->name;
396 list_init(&newDevice->ff_effects);
397 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
398 newDevice->ff_state = FF_STATUS_STOPPED;
399 #endif
400 /* There is no way in linux to query force feedback autocenter status.
401 Instead, track it with ff_autocenter, and assume it's initialy
402 enabled. */
403 newDevice->ff_autocenter = 1;
404 newDevice->ff_gain = 0xFFFF;
405 InitializeCriticalSection(&newDevice->generic.base.crit);
406 newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->base.crit");
408 /* get options */
409 get_app_key(&hkey, &appkey);
411 if (!get_config_key(hkey, appkey, "DefaultDeadZone", buffer, MAX_PATH))
413 def_deadzone = atoi(buffer);
414 TRACE("setting default deadzone to: %d\n", def_deadzone);
416 if (appkey) RegCloseKey(appkey);
417 if (hkey) RegCloseKey(hkey);
419 /* Create copy of default data format */
420 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto failed;
421 memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
422 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
424 /* Supported Axis & POVs should map 1-to-1 */
425 for (i = 0; i < WINE_JOYSTICK_MAX_AXES; i++)
427 if (!test_bit(newDevice->joydev->absbits, i)) {
428 newDevice->axes[i] = -1;
429 continue;
432 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i], df->dwObjSize);
433 newDevice->axes[i] = idx;
434 newDevice->generic.props[idx].lDevMin = newDevice->joydev->axes[i].minimum;
435 newDevice->generic.props[idx].lDevMax = newDevice->joydev->axes[i].maximum;
436 newDevice->generic.props[idx].lMin = 0;
437 newDevice->generic.props[idx].lMax = 0xffff;
438 newDevice->generic.props[idx].lSaturation = 0;
439 newDevice->generic.props[idx].lDeadZone = def_deadzone;
441 /* Linux supports force-feedback on X & Y axes only */
442 if (newDevice->joydev->has_ff && (i == 0 || i == 1))
443 df->rgodf[idx].dwFlags |= DIDOI_FFACTUATOR;
445 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->generic.devcaps.dwAxes++) | DIDFT_ABSAXIS;
448 for (i = 0; i < WINE_JOYSTICK_MAX_POVS; i++)
450 if (!test_bit(newDevice->joydev->absbits, ABS_HAT0X + i * 2) ||
451 !test_bit(newDevice->joydev->absbits, ABS_HAT0Y + i * 2)) {
452 newDevice->axes[ABS_HAT0X + i * 2] = newDevice->axes[ABS_HAT0Y + i * 2] = -1;
453 continue;
456 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + WINE_JOYSTICK_MAX_AXES], df->dwObjSize);
457 newDevice->axes[ABS_HAT0X + i * 2] = newDevice->axes[ABS_HAT0Y + i * 2] = i;
458 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->generic.devcaps.dwPOVs++) | DIDFT_POV;
461 /* Buttons can be anywhere, so check all */
462 for (i = 0; i < KEY_MAX && newDevice->generic.devcaps.dwButtons < WINE_JOYSTICK_MAX_BUTTONS; i++)
464 if (!test_bit(newDevice->joydev->keybits, i)) continue;
466 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[newDevice->generic.devcaps.dwButtons + 12], df->dwObjSize);
467 newDevice->buttons[i] = 0x80 | newDevice->generic.devcaps.dwButtons;
468 df->rgodf[idx ].pguid = &GUID_Button;
469 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->generic.devcaps.dwButtons++) | DIDFT_PSHBUTTON;
471 df->dwNumObjs = idx;
472 newDevice->generic.base.data_format.wine_df = df;
474 fake_current_js_state(newDevice);
476 /* Fill the caps */
477 newDevice->generic.devcaps.dwSize = sizeof(newDevice->generic.devcaps);
478 newDevice->generic.devcaps.dwFlags = DIDC_ATTACHED;
479 if (newDevice->generic.base.dinput->dwVersion >= 0x0800)
480 newDevice->generic.devcaps.dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
481 else
482 newDevice->generic.devcaps.dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
484 if (newDevice->joydev->has_ff)
485 newDevice->generic.devcaps.dwFlags |= DIDC_FORCEFEEDBACK;
487 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->generic.base.dinput);
488 return newDevice;
490 failed:
491 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
492 HeapFree(GetProcessHeap(), 0, df);
493 HeapFree(GetProcessHeap(), 0, newDevice);
494 return NULL;
497 /******************************************************************************
498 * get_joystick_index : Get the joystick index from a given GUID
500 static unsigned short get_joystick_index(REFGUID guid)
502 GUID wine_joystick = DInput_Wine_Joystick_Base_GUID;
503 GUID dev_guid = *guid;
505 wine_joystick.Data3 = 0;
506 dev_guid.Data3 = 0;
508 /* for the standard joystick GUID use index 0 */
509 if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
511 /* for the wine joystick GUIDs use the index stored in Data3 */
512 if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3 - DInput_Wine_Joystick_Base_GUID.Data3;
514 return MAX_JOYDEV;
517 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
519 unsigned short index;
521 find_joydevs();
523 if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
524 have_joydevs && index < have_joydevs)
526 if ((riid == NULL) ||
527 IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
528 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
529 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
530 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
532 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, index);
533 TRACE("Created a Joystick device (%p)\n", *pdev);
535 if (*pdev == NULL)
537 ERR("out of memory\n");
538 return DIERR_OUTOFMEMORY;
540 return DI_OK;
543 WARN("no interface\n");
544 return DIERR_NOINTERFACE;
547 return DIERR_DEVICENOTREG;
551 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
553 unsigned short index;
555 find_joydevs();
557 if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
558 have_joydevs && index < have_joydevs)
560 if ((riid == NULL) ||
561 IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
562 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
563 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
564 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
566 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, index);
567 TRACE("Created a Joystick device (%p)\n", *pdev);
569 if (*pdev == NULL)
571 ERR("out of memory\n");
572 return DIERR_OUTOFMEMORY;
574 return DI_OK;
576 WARN("no interface\n");
577 return DIERR_NOINTERFACE;
580 WARN("invalid device GUID\n");
581 return DIERR_DEVICENOTREG;
584 const struct dinput_device joystick_linuxinput_device = {
585 "Wine Linux-input joystick driver",
586 joydev_enum_deviceA,
587 joydev_enum_deviceW,
588 joydev_create_deviceA,
589 joydev_create_deviceW
592 /******************************************************************************
593 * Acquire : gets exclusive control of the joystick
595 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
597 JoystickImpl *This = (JoystickImpl *)iface;
598 HRESULT res;
600 TRACE("(this=%p)\n",This);
602 if ((res = IDirectInputDevice2AImpl_Acquire(iface)) != DI_OK)
604 WARN("Failed to acquire: %x\n", res);
605 return res;
608 if ((This->joyfd = open(This->joydev->device, O_RDWR)) == -1)
610 if ((This->joyfd = open(This->joydev->device, O_RDONLY)) == -1)
612 /* Couldn't open the device at all */
613 ERR("Failed to open device %s: %d %s\n", This->joydev->device, errno, strerror(errno));
614 IDirectInputDevice2AImpl_Unacquire(iface);
615 return DIERR_NOTFOUND;
617 else
619 /* Couldn't open in r/w but opened in read-only. */
620 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This->joydev->device);
623 else
625 struct input_event event;
627 event.type = EV_FF;
628 event.code = FF_GAIN;
629 event.value = This->ff_gain;
630 if (write(This->joyfd, &event, sizeof(event)) == -1)
631 ERR("Failed to set gain (%i): %d %s\n", This->ff_gain, errno, strerror(errno));
632 if (!This->ff_autocenter)
634 /* Disable autocenter. */
635 event.code = FF_AUTOCENTER;
636 event.value = 0;
637 if (write(This->joyfd, &event, sizeof(event)) == -1)
638 ERR("Failed disabling autocenter: %d %s\n", errno, strerror(errno));
642 return DI_OK;
645 /******************************************************************************
646 * Unacquire : frees the joystick
648 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
650 JoystickImpl *This = (JoystickImpl *)iface;
651 HRESULT res;
653 TRACE("(this=%p)\n",This);
654 res = IDirectInputDevice2AImpl_Unacquire(iface);
655 if (res==DI_OK && This->joyfd!=-1) {
656 effect_list_item *itr;
657 struct input_event event;
659 /* For each known effect:
660 * - stop it
661 * - unload it
662 * But, unlike DISFFC_RESET, do not release the effect.
664 LIST_FOR_EACH_ENTRY(itr, &This->ff_effects, effect_list_item, entry) {
665 IDirectInputEffect_Stop(itr->ref);
666 IDirectInputEffect_Unload(itr->ref);
669 /* Enable autocenter. */
670 event.type = EV_FF;
671 event.code = FF_AUTOCENTER;
672 /* TODO: Read autocenter strengh before disabling it, and use it here
673 * instead of 0xFFFF (maximum strengh).
675 event.value = 0xFFFF;
676 if (write(This->joyfd, &event, sizeof(event)) == -1)
677 ERR("Failed to set autocenter to %04x: %d %s\n", event.value, errno, strerror(errno));
679 close(This->joyfd);
680 This->joyfd = -1;
682 return res;
686 * set the current state of the js device as it would be with the middle
687 * values on the axes
689 #define CENTER_AXIS(a) \
690 (ji->axes[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->axes[a]], \
691 ji->joydev->axes[a].value ))
692 static void fake_current_js_state(JoystickImpl *ji)
694 int i;
696 /* center the axes */
697 ji->generic.js.lX = CENTER_AXIS(ABS_X);
698 ji->generic.js.lY = CENTER_AXIS(ABS_Y);
699 ji->generic.js.lZ = CENTER_AXIS(ABS_Z);
700 ji->generic.js.lRx = CENTER_AXIS(ABS_RX);
701 ji->generic.js.lRy = CENTER_AXIS(ABS_RY);
702 ji->generic.js.lRz = CENTER_AXIS(ABS_RZ);
703 ji->generic.js.rglSlider[0] = CENTER_AXIS(ABS_THROTTLE);
704 ji->generic.js.rglSlider[1] = CENTER_AXIS(ABS_RUDDER);
706 /* POV center is -1 */
707 for (i = 0; i < 4; i++)
708 ji->generic.js.rgdwPOV[i] = -1;
710 #undef CENTER_AXIS
712 /* convert wine format offset to user format object index */
713 static void joy_polldev(JoystickGenericImpl *iface)
715 struct pollfd plfd;
716 struct input_event ie;
717 JoystickImpl *This = (JoystickImpl*) iface;
719 if (This->joyfd==-1)
720 return;
722 while (1)
724 LONG value = 0;
725 int inst_id = -1;
727 plfd.fd = This->joyfd;
728 plfd.events = POLLIN;
730 if (poll(&plfd,1,0) != 1)
731 return;
733 /* we have one event, so we can read */
734 if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
735 return;
737 TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
738 switch (ie.type) {
739 case EV_KEY: /* button */
741 int btn = This->buttons[ie.code];
743 TRACE("(%p) %d -> %d\n", This, ie.code, btn);
744 if (btn & 0x80)
746 btn &= 0x7F;
747 inst_id = DIDFT_MAKEINSTANCE(btn) | DIDFT_PSHBUTTON;
748 This->generic.js.rgbButtons[btn] = value = ie.value ? 0x80 : 0x00;
750 break;
752 case EV_ABS:
754 int axis = This->axes[ie.code];
755 if (axis==-1) {
756 break;
758 inst_id = DIDFT_MAKEINSTANCE(axis) | (ie.code < ABS_HAT0X ? DIDFT_ABSAXIS : DIDFT_POV);
759 value = joystick_map_axis(&This->generic.props[id_to_object(This->generic.base.data_format.wine_df, inst_id)], ie.value);
761 switch (ie.code) {
762 case ABS_X: This->generic.js.lX = value; break;
763 case ABS_Y: This->generic.js.lY = value; break;
764 case ABS_Z: This->generic.js.lZ = value; break;
765 case ABS_RX: This->generic.js.lRx = value; break;
766 case ABS_RY: This->generic.js.lRy = value; break;
767 case ABS_RZ: This->generic.js.lRz = value; break;
768 case ABS_THROTTLE: This->generic.js.rglSlider[0] = value; break;
769 case ABS_RUDDER: This->generic.js.rglSlider[1] = value; break;
770 case ABS_HAT0X: case ABS_HAT0Y: case ABS_HAT1X: case ABS_HAT1Y:
771 case ABS_HAT2X: case ABS_HAT2Y: case ABS_HAT3X: case ABS_HAT3Y:
773 int idx = (ie.code - ABS_HAT0X) / 2;
775 if (ie.code % 2)
776 This->povs[idx].y = ie.value;
777 else
778 This->povs[idx].x = ie.value;
780 This->generic.js.rgdwPOV[idx] = value = joystick_map_pov(&This->povs[idx]);
781 break;
783 default:
784 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie.code,ie.value);
786 break;
788 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
789 case EV_FF_STATUS:
790 This->ff_state = ie.value;
791 break;
792 #endif
793 #ifdef EV_SYN
794 case EV_SYN:
795 /* there is nothing to do */
796 break;
797 #endif
798 default:
799 FIXME("joystick cannot handle type %d event (code %d)\n",ie.type,ie.code);
800 break;
802 if (inst_id >= 0)
803 queue_event((LPDIRECTINPUTDEVICE8A)This,
804 id_to_offset(&This->generic.base.data_format, inst_id),
805 value, ie.time.tv_usec, This->generic.base.dinput->evsequence++);
809 /******************************************************************************
810 * SetProperty : change input device properties
812 static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
813 REFGUID rguid,
814 LPCDIPROPHEADER ph)
816 JoystickImpl *This = (JoystickImpl *)iface;
818 if (!ph) {
819 WARN("invalid argument\n");
820 return DIERR_INVALIDPARAM;
823 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
824 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
825 ph->dwSize, ph->dwHeaderSize, ph->dwObj, ph->dwHow);
827 if (!HIWORD(rguid)) {
828 switch (LOWORD(rguid)) {
829 case (DWORD_PTR)DIPROP_CALIBRATIONMODE: {
830 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
831 FIXME("DIPROP_CALIBRATIONMODE(%d)\n", pd->dwData);
832 break;
834 case (DWORD_PTR)DIPROP_AUTOCENTER: {
835 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
837 TRACE("autocenter(%d)\n", pd->dwData);
838 This->ff_autocenter = pd->dwData == DIPROPAUTOCENTER_ON;
840 break;
842 case (DWORD_PTR)DIPROP_FFGAIN: {
843 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
845 TRACE("DIPROP_FFGAIN(%d)\n", pd->dwData);
846 This->ff_gain = MulDiv(pd->dwData, 0xFFFF, 10000);
847 if (This->generic.base.acquired) {
848 /* Update immediately. */
849 struct input_event event;
851 event.type = EV_FF;
852 event.code = FF_GAIN;
853 event.value = This->ff_gain;
854 if (write(This->joyfd, &event, sizeof(event)) == -1)
855 ERR("Failed to set gain (%i): %d %s\n", This->ff_gain, errno, strerror(errno));
857 break;
859 default:
860 return JoystickAGenericImpl_SetProperty(iface, rguid, ph);
863 return DI_OK;
866 /******************************************************************************
867 * GetProperty : get input device properties
869 static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
870 REFGUID rguid,
871 LPDIPROPHEADER pdiph)
873 JoystickImpl *This = (JoystickImpl *)iface;
875 TRACE("(this=%p,%s,%p)\n", iface, debugstr_guid(rguid), pdiph);
876 _dump_DIPROPHEADER(pdiph);
878 if (HIWORD(rguid)) return DI_OK;
880 switch (LOWORD(rguid)) {
881 case (DWORD_PTR) DIPROP_AUTOCENTER:
883 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
885 pd->dwData = This->ff_autocenter ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF;
886 TRACE("autocenter(%d)\n", pd->dwData);
887 break;
889 case (DWORD_PTR) DIPROP_FFGAIN:
891 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
893 pd->dwData = MulDiv(This->ff_gain, 10000, 0xFFFF);
894 TRACE("DIPROP_FFGAIN(%d)\n", pd->dwData);
895 break;
898 default:
899 return JoystickAGenericImpl_GetProperty(iface, rguid, pdiph);
902 return DI_OK;
905 /******************************************************************************
906 * CreateEffect - Create a new FF effect with the specified params
908 static HRESULT WINAPI JoystickAImpl_CreateEffect(LPDIRECTINPUTDEVICE8A iface,
909 REFGUID rguid,
910 LPCDIEFFECT lpeff,
911 LPDIRECTINPUTEFFECT *ppdef,
912 LPUNKNOWN pUnkOuter)
914 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
915 effect_list_item* new_effect = NULL;
916 HRESULT retval = DI_OK;
917 #endif
919 JoystickImpl* This = (JoystickImpl*)iface;
920 TRACE("(this=%p,%p,%p,%p,%p)\n", This, rguid, lpeff, ppdef, pUnkOuter);
922 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
923 TRACE("not available (compiled w/o ff support)\n");
924 *ppdef = NULL;
925 return DI_OK;
926 #else
928 if (!(new_effect = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect))))
929 return DIERR_OUTOFMEMORY;
931 retval = linuxinput_create_effect(&This->joyfd, rguid, &new_effect->entry, &new_effect->ref);
932 if (retval != DI_OK)
934 HeapFree(GetProcessHeap(), 0, new_effect);
935 return retval;
938 if (lpeff != NULL)
940 retval = IDirectInputEffect_SetParameters(new_effect->ref, lpeff, 0);
942 if (retval != DI_OK && retval != DI_DOWNLOADSKIPPED)
944 HeapFree(GetProcessHeap(), 0, new_effect);
945 return retval;
949 list_add_tail(&This->ff_effects, &new_effect->entry);
950 *ppdef = new_effect->ref;
952 if (pUnkOuter != NULL)
953 FIXME("Interface aggregation not implemented.\n");
955 return DI_OK;
957 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
960 /*******************************************************************************
961 * EnumEffects - Enumerate available FF effects
963 static HRESULT WINAPI JoystickAImpl_EnumEffects(LPDIRECTINPUTDEVICE8A iface,
964 LPDIENUMEFFECTSCALLBACKA lpCallback,
965 LPVOID pvRef,
966 DWORD dwEffType)
968 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
969 DIEFFECTINFOA dei; /* feif */
970 DWORD type = DIEFT_GETTYPE(dwEffType);
971 JoystickImpl* This = (JoystickImpl*)iface;
973 TRACE("(this=%p,%p,%d) type=%d\n", This, pvRef, dwEffType, type);
975 dei.dwSize = sizeof(DIEFFECTINFOA);
977 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
978 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
979 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
980 (*lpCallback)(&dei, pvRef);
983 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
984 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
985 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
986 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
987 (*lpCallback)(&dei, pvRef);
989 if (test_bit(This->joydev->ffbits, FF_SINE)) {
990 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
991 (*lpCallback)(&dei, pvRef);
993 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
994 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
995 (*lpCallback)(&dei, pvRef);
997 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
998 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
999 (*lpCallback)(&dei, pvRef);
1001 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1002 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1003 (*lpCallback)(&dei, pvRef);
1007 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1008 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1009 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1010 (*lpCallback)(&dei, pvRef);
1013 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1014 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1015 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1016 (*lpCallback)(&dei, pvRef);
1018 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1019 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1020 (*lpCallback)(&dei, pvRef);
1022 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1023 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1024 (*lpCallback)(&dei, pvRef);
1026 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1027 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1028 (*lpCallback)(&dei, pvRef);
1032 #endif
1034 return DI_OK;
1037 static HRESULT WINAPI JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface,
1038 LPDIENUMEFFECTSCALLBACKW lpCallback,
1039 LPVOID pvRef,
1040 DWORD dwEffType)
1042 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1043 /* seems silly to duplicate all this code but all the structures and functions
1044 * are actually different (A/W) */
1045 DIEFFECTINFOW dei; /* feif */
1046 DWORD type = DIEFT_GETTYPE(dwEffType);
1047 JoystickImpl* This = (JoystickImpl*)iface;
1048 int xfd = This->joyfd;
1050 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This, pvRef, dwEffType, type, xfd);
1052 dei.dwSize = sizeof(DIEFFECTINFOW);
1054 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1055 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1056 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1057 (*lpCallback)(&dei, pvRef);
1060 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1061 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1062 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1063 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1064 (*lpCallback)(&dei, pvRef);
1066 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1067 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1068 (*lpCallback)(&dei, pvRef);
1070 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1071 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1072 (*lpCallback)(&dei, pvRef);
1074 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1075 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1076 (*lpCallback)(&dei, pvRef);
1078 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1079 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1080 (*lpCallback)(&dei, pvRef);
1084 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1085 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1086 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1087 (*lpCallback)(&dei, pvRef);
1090 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1091 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1092 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1093 (*lpCallback)(&dei, pvRef);
1095 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1096 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1097 (*lpCallback)(&dei, pvRef);
1099 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1100 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1101 (*lpCallback)(&dei, pvRef);
1103 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1104 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1105 (*lpCallback)(&dei, pvRef);
1109 /* return to unacquired state if that's where it was */
1110 if (xfd == -1)
1111 IDirectInputDevice8_Unacquire(iface);
1112 #endif
1114 return DI_OK;
1117 /*******************************************************************************
1118 * GetEffectInfo - Get information about a particular effect
1120 static HRESULT WINAPI JoystickAImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8A iface,
1121 LPDIEFFECTINFOA pdei,
1122 REFGUID guid)
1124 JoystickImpl* This = (JoystickImpl*)iface;
1126 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1128 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1129 return linuxinput_get_info_A(This->joyfd, guid, pdei);
1130 #else
1131 return DI_OK;
1132 #endif
1135 static HRESULT WINAPI JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface,
1136 LPDIEFFECTINFOW pdei,
1137 REFGUID guid)
1139 JoystickImpl* This = (JoystickImpl*)iface;
1141 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1143 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1144 return linuxinput_get_info_W(This->joyfd, guid, pdei);
1145 #else
1146 return DI_OK;
1147 #endif
1150 /*******************************************************************************
1151 * GetForceFeedbackState - Get information about the device's FF state
1153 static HRESULT WINAPI JoystickAImpl_GetForceFeedbackState(
1154 LPDIRECTINPUTDEVICE8A iface,
1155 LPDWORD pdwOut)
1157 JoystickImpl* This = (JoystickImpl*)iface;
1159 TRACE("(this=%p,%p)\n", This, pdwOut);
1161 (*pdwOut) = 0;
1163 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1164 /* DIGFFS_STOPPED is the only mandatory flag to report */
1165 if (This->ff_state == FF_STATUS_STOPPED)
1166 (*pdwOut) |= DIGFFS_STOPPED;
1167 #endif
1169 return DI_OK;
1172 /*******************************************************************************
1173 * SendForceFeedbackCommand - Send a command to the device's FF system
1175 static HRESULT WINAPI JoystickAImpl_SendForceFeedbackCommand(
1176 LPDIRECTINPUTDEVICE8A iface,
1177 DWORD dwFlags)
1179 JoystickImpl* This = (JoystickImpl*)iface;
1180 TRACE("(this=%p,%d)\n", This, dwFlags);
1182 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1183 switch (dwFlags)
1185 case DISFFC_STOPALL:
1187 /* Stop all effects */
1188 effect_list_item *itr;
1190 LIST_FOR_EACH_ENTRY(itr, &This->ff_effects, effect_list_item, entry)
1191 IDirectInputEffect_Stop(itr->ref);
1192 break;
1195 case DISFFC_RESET:
1197 effect_list_item *itr, *ptr;
1199 /* Stop, unload, release and free all effects */
1200 /* This returns the device to its "bare" state */
1201 LIST_FOR_EACH_ENTRY_SAFE(itr, ptr, &This->ff_effects, effect_list_item, entry)
1202 IDirectInputEffect_Release(itr->ref);
1203 break;
1205 case DISFFC_PAUSE:
1206 case DISFFC_CONTINUE:
1207 FIXME("No support for Pause or Continue in linux\n");
1208 break;
1210 case DISFFC_SETACTUATORSOFF:
1211 case DISFFC_SETACTUATORSON:
1212 FIXME("No direct actuator control in linux\n");
1213 break;
1215 default:
1216 FIXME("Unknown Force Feedback Command!\n");
1217 return DIERR_INVALIDPARAM;
1219 return DI_OK;
1220 #else
1221 return DIERR_UNSUPPORTED;
1222 #endif
1225 /*******************************************************************************
1226 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1227 * created for this device.
1229 static HRESULT WINAPI JoystickAImpl_EnumCreatedEffectObjects(
1230 LPDIRECTINPUTDEVICE8A iface,
1231 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1232 LPVOID pvRef,
1233 DWORD dwFlags)
1235 /* this function is safe to call on non-ff-enabled builds */
1236 JoystickImpl* This = (JoystickImpl*)iface;
1237 effect_list_item *itr, *ptr;
1239 TRACE("(this=%p,%p,%p,%d)\n", This, lpCallback, pvRef, dwFlags);
1241 if (!lpCallback)
1242 return DIERR_INVALIDPARAM;
1244 if (dwFlags != 0)
1245 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1247 LIST_FOR_EACH_ENTRY_SAFE(itr, ptr, &This->ff_effects, effect_list_item, entry)
1248 (*lpCallback)(itr->ref, pvRef);
1250 return DI_OK;
1253 /******************************************************************************
1254 * GetDeviceInfo : get information about a device's identity
1256 static HRESULT WINAPI JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface,
1257 LPDIDEVICEINSTANCEA pdidi)
1259 JoystickImpl *This = (JoystickImpl *)iface;
1261 TRACE("(%p) %p\n", This, pdidi);
1263 if (pdidi == NULL) return E_POINTER;
1264 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
1265 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)))
1266 return DIERR_INVALIDPARAM;
1268 fill_joystick_dideviceinstanceA(pdidi, This->generic.base.dinput->dwVersion,
1269 get_joystick_index(&This->generic.base.guid));
1270 return DI_OK;
1273 static HRESULT WINAPI JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface,
1274 LPDIDEVICEINSTANCEW pdidi)
1276 JoystickImpl *This = (JoystickImpl *)iface;
1278 TRACE("(%p) %p\n", This, pdidi);
1280 if (pdidi == NULL) return E_POINTER;
1281 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3W)) &&
1282 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)))
1283 return DIERR_INVALIDPARAM;
1285 fill_joystick_dideviceinstanceW(pdidi, This->generic.base.dinput->dwVersion,
1286 get_joystick_index(&This->generic.base.guid));
1287 return DI_OK;
1290 static const IDirectInputDevice8AVtbl JoystickAvt =
1292 IDirectInputDevice2AImpl_QueryInterface,
1293 IDirectInputDevice2AImpl_AddRef,
1294 IDirectInputDevice2AImpl_Release,
1295 JoystickAGenericImpl_GetCapabilities,
1296 IDirectInputDevice2AImpl_EnumObjects,
1297 JoystickAImpl_GetProperty,
1298 JoystickAImpl_SetProperty,
1299 JoystickAImpl_Acquire,
1300 JoystickAImpl_Unacquire,
1301 JoystickAGenericImpl_GetDeviceState,
1302 IDirectInputDevice2AImpl_GetDeviceData,
1303 IDirectInputDevice2AImpl_SetDataFormat,
1304 IDirectInputDevice2AImpl_SetEventNotification,
1305 IDirectInputDevice2AImpl_SetCooperativeLevel,
1306 JoystickAGenericImpl_GetObjectInfo,
1307 JoystickAImpl_GetDeviceInfo,
1308 IDirectInputDevice2AImpl_RunControlPanel,
1309 IDirectInputDevice2AImpl_Initialize,
1310 JoystickAImpl_CreateEffect,
1311 JoystickAImpl_EnumEffects,
1312 JoystickAImpl_GetEffectInfo,
1313 JoystickAImpl_GetForceFeedbackState,
1314 JoystickAImpl_SendForceFeedbackCommand,
1315 JoystickAImpl_EnumCreatedEffectObjects,
1316 IDirectInputDevice2AImpl_Escape,
1317 JoystickAGenericImpl_Poll,
1318 IDirectInputDevice2AImpl_SendDeviceData,
1319 IDirectInputDevice7AImpl_EnumEffectsInFile,
1320 IDirectInputDevice7AImpl_WriteEffectToFile,
1321 IDirectInputDevice8AImpl_BuildActionMap,
1322 IDirectInputDevice8AImpl_SetActionMap,
1323 IDirectInputDevice8AImpl_GetImageInfo
1326 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1327 # define XCAST(fun) (typeof(JoystickWvt.fun))
1328 #else
1329 # define XCAST(fun) (void*)
1330 #endif
1332 static const IDirectInputDevice8WVtbl JoystickWvt =
1334 IDirectInputDevice2WImpl_QueryInterface,
1335 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1336 XCAST(Release)IDirectInputDevice2AImpl_Release,
1337 XCAST(GetCapabilities)JoystickAGenericImpl_GetCapabilities,
1338 IDirectInputDevice2WImpl_EnumObjects,
1339 XCAST(GetProperty)JoystickAImpl_GetProperty,
1340 XCAST(SetProperty)JoystickAImpl_SetProperty,
1341 XCAST(Acquire)JoystickAImpl_Acquire,
1342 XCAST(Unacquire)JoystickAImpl_Unacquire,
1343 XCAST(GetDeviceState)JoystickAGenericImpl_GetDeviceState,
1344 XCAST(GetDeviceData)IDirectInputDevice2AImpl_GetDeviceData,
1345 XCAST(SetDataFormat)IDirectInputDevice2AImpl_SetDataFormat,
1346 XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
1347 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1348 JoystickWGenericImpl_GetObjectInfo,
1349 JoystickWImpl_GetDeviceInfo,
1350 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1351 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1352 XCAST(CreateEffect)JoystickAImpl_CreateEffect,
1353 JoystickWImpl_EnumEffects,
1354 JoystickWImpl_GetEffectInfo,
1355 XCAST(GetForceFeedbackState)JoystickAImpl_GetForceFeedbackState,
1356 XCAST(SendForceFeedbackCommand)JoystickAImpl_SendForceFeedbackCommand,
1357 XCAST(EnumCreatedEffectObjects)JoystickAImpl_EnumCreatedEffectObjects,
1358 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1359 XCAST(Poll)JoystickAGenericImpl_Poll,
1360 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1361 IDirectInputDevice7WImpl_EnumEffectsInFile,
1362 IDirectInputDevice7WImpl_WriteEffectToFile,
1363 IDirectInputDevice8WImpl_BuildActionMap,
1364 IDirectInputDevice8WImpl_SetActionMap,
1365 IDirectInputDevice8WImpl_GetImageInfo
1367 #undef XCAST
1369 #else /* HAVE_CORRECT_LINUXINPUT_H */
1371 const struct dinput_device joystick_linuxinput_device = {
1372 "Wine Linux-input joystick driver",
1373 NULL,
1374 NULL,
1375 NULL,
1376 NULL
1379 #endif /* HAVE_CORRECT_LINUXINPUT_H */