dinput: Factor out IDirectInputDevice ansi vtable.
[wine.git] / dlls / dinput / joystick_linuxinput.c
blob3bc6114322f4bfaff0682f002fa21775801738bb
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_LINUX_INPUT_H
43 # include <linux/input.h>
44 # undef SW_MAX
45 # if defined(EVIOCGBIT) && defined(EV_ABS) && defined(BTN_PINKIE)
46 # define HAS_PROPER_HEADER
47 # endif
48 #endif
49 #ifdef HAVE_SYS_POLL_H
50 # include <sys/poll.h>
51 #endif
53 #include "wine/debug.h"
54 #include "wine/unicode.h"
55 #include "wine/list.h"
56 #include "windef.h"
57 #include "winbase.h"
58 #include "winerror.h"
59 #include "winreg.h"
60 #include "devguid.h"
61 #include "dinput.h"
63 #include "dinput_private.h"
64 #include "device_private.h"
65 #include "joystick_private.h"
67 #ifdef HAS_PROPER_HEADER
69 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
71 #define EVDEVPREFIX "/dev/input/event"
72 #define EVDEVDRIVER " (event)"
74 /* Wine joystick driver object instances */
75 #define WINE_JOYSTICK_MAX_AXES 8
76 #define WINE_JOYSTICK_MAX_POVS 4
77 #define WINE_JOYSTICK_MAX_BUTTONS 128
79 struct wine_input_absinfo {
80 LONG value;
81 LONG minimum;
82 LONG maximum;
83 LONG fuzz;
84 LONG flat;
87 /* implemented in effect_linuxinput.c */
88 HRESULT linuxinput_create_effect(int* fd, REFGUID rguid, struct list *parent_list_entry, LPDIRECTINPUTEFFECT* peff);
89 HRESULT linuxinput_get_info_A(int fd, REFGUID rguid, LPDIEFFECTINFOA info);
90 HRESULT linuxinput_get_info_W(int fd, REFGUID rguid, LPDIEFFECTINFOW info);
92 static HRESULT WINAPI JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface, DWORD dwFlags);
94 typedef struct JoystickImpl JoystickImpl;
95 static const IDirectInputDevice8WVtbl JoystickWvt;
97 struct JoyDev {
98 char *device;
99 char *name;
100 GUID guid;
101 GUID guid_product;
103 BOOL has_ff, is_joystick;
104 int num_effects;
106 /* data returned by EVIOCGBIT for caps, EV_ABS, EV_KEY, and EV_FF */
107 BYTE evbits[(EV_MAX+7)/8];
108 BYTE absbits[(ABS_MAX+7)/8];
109 BYTE keybits[(KEY_MAX+7)/8];
110 BYTE ffbits[(FF_MAX+7)/8];
112 /* data returned by the EVIOCGABS() ioctl */
113 struct wine_input_absinfo axes[ABS_MAX];
115 WORD vendor_id, product_id, bus_type;
118 struct JoystickImpl
120 struct JoystickGenericImpl generic;
121 struct JoyDev *joydev;
123 /* joystick private */
124 int joyfd;
126 int dev_axes_to_di[ABS_MAX];
127 POINTL povs[4];
129 /* LUT for KEY_ to offset in rgbButtons */
130 BYTE buttons[KEY_MAX];
132 /* Force feedback variables */
133 struct list ff_effects;
134 int ff_state;
135 int ff_autocenter;
136 int ff_gain;
139 static inline JoystickImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface)
141 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface),
142 JoystickGenericImpl, base), JoystickImpl, generic);
145 static void fake_current_js_state(JoystickImpl *ji);
146 static void find_joydevs(void);
147 static void joy_polldev( IDirectInputDevice8W *iface );
149 /* This GUID is slightly different from the linux joystick one. Take note. */
150 static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
151 0x9e573eda,
152 0x7734,
153 0x11d2,
154 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
157 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
159 #define MAX_JOYDEV 64
161 static int have_joydevs = -1;
162 static struct JoyDev *joydevs = NULL;
164 static void find_joydevs(void)
166 int i;
168 if (InterlockedCompareExchange(&have_joydevs, 0, -1) != -1)
169 /* Someone beat us to it */
170 return;
172 for (i = 0; i < MAX_JOYDEV; i++)
174 char buf[MAX_PATH];
175 struct JoyDev joydev = {0};
176 int fd;
177 BOOL no_ff_check = FALSE;
178 int j;
179 struct JoyDev *new_joydevs;
180 struct input_id device_id = {0};
182 snprintf(buf, sizeof(buf), EVDEVPREFIX"%d", i);
184 if ((fd = open(buf, O_RDWR)) == -1)
186 fd = open(buf, O_RDONLY);
187 no_ff_check = TRUE;
190 if (fd == -1)
191 continue;
193 if (ioctl(fd, EVIOCGBIT(0, sizeof(joydev.evbits)), joydev.evbits) == -1)
195 WARN("ioctl(EVIOCGBIT, 0) failed: %d %s\n", errno, strerror(errno));
196 close(fd);
197 continue;
199 if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(joydev.absbits)), joydev.absbits) == -1)
201 WARN("ioctl(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno, strerror(errno));
202 close(fd);
203 continue;
205 if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(joydev.keybits)), joydev.keybits) == -1)
207 WARN("ioctl(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno, strerror(errno));
208 close(fd);
209 continue;
212 /* A true joystick has at least axis X and Y, and at least 1
213 * button. copied from linux/drivers/input/joydev.c */
214 if (((!test_bit(joydev.absbits, ABS_X) || !test_bit(joydev.absbits, ABS_Y)) &&
215 !test_bit(joydev.absbits, ABS_WHEEL) &&
216 !test_bit(joydev.absbits, ABS_GAS) &&
217 !test_bit(joydev.absbits, ABS_BRAKE)) ||
218 !(test_bit(joydev.keybits, BTN_TRIGGER) ||
219 test_bit(joydev.keybits, BTN_A) ||
220 test_bit(joydev.keybits, BTN_1) ||
221 test_bit(joydev.keybits, BTN_BASE) ||
222 test_bit(joydev.keybits, BTN_GEAR_UP) ||
223 test_bit(joydev.keybits, BTN_GEAR_DOWN)))
225 close(fd);
226 continue;
229 /* in lieu of properly reporting HID usage, detect presence of
230 * "joystick buttons" and report those devices as joysticks instead of
231 * gamepads */
232 joydev.is_joystick =
233 test_bit(joydev.keybits, BTN_TRIGGER) ||
234 test_bit(joydev.keybits, BTN_THUMB) ||
235 test_bit(joydev.keybits, BTN_THUMB2) ||
236 test_bit(joydev.keybits, BTN_TOP) ||
237 test_bit(joydev.keybits, BTN_TOP2) ||
238 test_bit(joydev.keybits, BTN_PINKIE) ||
239 test_bit(joydev.keybits, BTN_BASE) ||
240 test_bit(joydev.keybits, BTN_BASE2) ||
241 test_bit(joydev.keybits, BTN_BASE3) ||
242 test_bit(joydev.keybits, BTN_BASE4) ||
243 test_bit(joydev.keybits, BTN_BASE5) ||
244 test_bit(joydev.keybits, BTN_BASE6) ||
245 test_bit(joydev.keybits, BTN_GEAR_UP) ||
246 test_bit(joydev.keybits, BTN_GEAR_DOWN) ||
247 test_bit(joydev.keybits, BTN_DEAD);
249 if (!(joydev.device = HeapAlloc(GetProcessHeap(), 0, strlen(buf) + 1)))
251 close(fd);
252 continue;
254 strcpy(joydev.device, buf);
256 buf[MAX_PATH - 1] = 0;
257 if (ioctl(fd, EVIOCGNAME(MAX_PATH - 1), buf) != -1 &&
258 (joydev.name = HeapAlloc(GetProcessHeap(), 0, strlen(buf) + strlen(EVDEVDRIVER) + 1)))
260 strcpy(joydev.name, buf);
261 /* Append driver name */
262 strcat(joydev.name, EVDEVDRIVER);
264 else
265 joydev.name = joydev.device;
267 if (device_disabled_registry(joydev.name)) {
268 close(fd);
269 HeapFree(GetProcessHeap(), 0, joydev.name);
270 if (joydev.name != joydev.device)
271 HeapFree(GetProcessHeap(), 0, joydev.device);
272 continue;
275 joydev.guid = DInput_Wine_Joystick_Base_GUID;
276 joydev.guid.Data3 += have_joydevs;
278 TRACE("Found a joystick on %s: %s (%s)\n",
279 joydev.device, joydev.name,
280 debugstr_guid(&joydev.guid)
283 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
284 if (!no_ff_check &&
285 test_bit(joydev.evbits, EV_FF) &&
286 ioctl(fd, EVIOCGBIT(EV_FF, sizeof(joydev.ffbits)), joydev.ffbits) != -1 &&
287 ioctl(fd, EVIOCGEFFECTS, &joydev.num_effects) != -1 &&
288 joydev.num_effects > 0)
290 TRACE(" ... with force feedback\n");
291 joydev.has_ff = TRUE;
293 #endif
295 for (j = 0; j < ABS_MAX;j ++)
297 if (!test_bit(joydev.absbits, j)) continue;
298 if (ioctl(fd, EVIOCGABS(j), &(joydev.axes[j])) != -1)
300 TRACE(" ... with axis %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
302 joydev.axes[j].value,
303 joydev.axes[j].minimum,
304 joydev.axes[j].maximum,
305 joydev.axes[j].fuzz,
306 joydev.axes[j].flat
311 if (ioctl(fd, EVIOCGID, &device_id) == -1)
313 WARN("ioctl(EVIOCGID) failed: %d %s\n", errno, strerror(errno));
314 joydev.guid_product = DInput_Wine_Joystick_Base_GUID;
316 else
318 joydev.vendor_id = device_id.vendor;
319 joydev.product_id = device_id.product;
320 joydev.bus_type = device_id.bustype;
322 /* Concatenate product_id with vendor_id to mimic Windows behaviour */
323 joydev.guid_product = DInput_PIDVID_Product_GUID;
324 joydev.guid_product.Data1 = MAKELONG(joydev.vendor_id, joydev.product_id);
327 if (!have_joydevs)
328 new_joydevs = HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev));
329 else
330 new_joydevs = HeapReAlloc(GetProcessHeap(), 0, joydevs, (1 + have_joydevs) * sizeof(struct JoyDev));
332 if (!new_joydevs)
334 close(fd);
335 continue;
337 joydevs = new_joydevs;
338 joydevs[have_joydevs] = joydev;
339 have_joydevs++;
341 close(fd);
345 static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
347 DWORD dwSize = lpddi->dwSize;
349 TRACE("%d %p\n", dwSize, lpddi);
350 memset(lpddi, 0, dwSize);
352 lpddi->dwSize = dwSize;
353 lpddi->guidInstance = joydevs[id].guid;
354 lpddi->guidProduct = joydevs[id].guid_product;
355 lpddi->guidFFDriver = GUID_NULL;
356 lpddi->dwDevType = get_device_type(version, joydevs[id].is_joystick);
358 /* Assume the joystick as HID if it is attached to USB bus and has a valid VID/PID */
359 if (joydevs[id].bus_type == BUS_USB &&
360 joydevs[id].vendor_id && joydevs[id].product_id)
362 lpddi->dwDevType |= DIDEVTYPE_HID;
363 lpddi->wUsagePage = 0x01; /* Desktop */
364 if (joydevs[id].is_joystick)
365 lpddi->wUsage = 0x04; /* Joystick */
366 else
367 lpddi->wUsage = 0x05; /* Game Pad */
370 MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
371 MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszProductName, MAX_PATH);
374 static void fill_joystick_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
376 DIDEVICEINSTANCEW lpddiW;
377 DWORD dwSize = lpddi->dwSize;
379 lpddiW.dwSize = sizeof(lpddiW);
380 fill_joystick_dideviceinstanceW(&lpddiW, version, id);
382 TRACE("%d %p\n", dwSize, lpddi);
383 memset(lpddi, 0, dwSize);
385 /* Convert W->A */
386 lpddi->dwSize = dwSize;
387 lpddi->guidInstance = lpddiW.guidInstance;
388 lpddi->guidProduct = lpddiW.guidProduct;
389 lpddi->dwDevType = lpddiW.dwDevType;
390 lstrcpynA(lpddi->tszInstanceName, joydevs[id].name, MAX_PATH);
391 lstrcpynA(lpddi->tszProductName, joydevs[id].name, MAX_PATH);
392 lpddi->guidFFDriver = lpddiW.guidFFDriver;
393 lpddi->wUsagePage = lpddiW.wUsagePage;
394 lpddi->wUsage = lpddiW.wUsage;
397 static HRESULT joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
399 find_joydevs();
401 if (id >= have_joydevs) {
402 return E_FAIL;
405 if (!((dwDevType == 0) ||
406 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version >= 0x0300 && version < 0x0800)) ||
407 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
408 return S_FALSE;
410 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
411 if (dwFlags & DIEDFL_FORCEFEEDBACK)
412 return S_FALSE;
413 #endif
415 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
416 fill_joystick_dideviceinstanceA(lpddi, version, id);
417 return S_OK;
419 return S_FALSE;
422 static HRESULT joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
424 find_joydevs();
426 if (id >= have_joydevs) {
427 return E_FAIL;
430 if (!((dwDevType == 0) ||
431 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version >= 0x0300 && version < 0x0800)) ||
432 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
433 return S_FALSE;
435 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
436 if (dwFlags & DIEDFL_FORCEFEEDBACK)
437 return S_FALSE;
438 #endif
440 if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
441 fill_joystick_dideviceinstanceW(lpddi, version, id);
442 return S_OK;
444 return S_FALSE;
447 static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickImpl **out, unsigned short index )
449 JoystickImpl* newDevice;
450 LPDIDATAFORMAT df = NULL;
451 int i, idx = 0;
452 int default_axis_map[WINE_JOYSTICK_MAX_AXES + WINE_JOYSTICK_MAX_POVS*2];
453 DIDEVICEINSTANCEW ddi;
454 HRESULT hr;
456 if (FAILED(hr = direct_input_device_alloc( sizeof(JoystickImpl), &JoystickWvt, rguid, dinput, (void **)&newDevice )))
457 return hr;
458 newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->base.crit");
460 newDevice->generic.joy_polldev = joy_polldev;
461 newDevice->joyfd = -1;
462 newDevice->joydev = &joydevs[index];
463 newDevice->generic.name = newDevice->joydev->name;
464 list_init(&newDevice->ff_effects);
465 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
466 newDevice->ff_state = FF_STATUS_STOPPED;
467 #endif
468 /* There is no way in linux to query force feedback autocenter status.
469 Instead, track it with ff_autocenter, and assume it's initially
470 enabled. */
471 newDevice->ff_autocenter = 1;
472 newDevice->ff_gain = 0xFFFF;
474 /* Count number of available axes - supported Axis & POVs */
475 for (i = 0; i < ABS_MAX; i++)
477 if (idx < WINE_JOYSTICK_MAX_AXES &&
478 i < ABS_HAT0X &&
479 test_bit(newDevice->joydev->absbits, i))
481 newDevice->generic.device_axis_count++;
482 newDevice->dev_axes_to_di[i] = idx;
483 newDevice->generic.props[idx].lDevMin = newDevice->joydev->axes[i].minimum;
484 newDevice->generic.props[idx].lDevMax = newDevice->joydev->axes[i].maximum;
485 if (i >= 8 && i <= 10) /* If it's a wheel axis... */
486 default_axis_map[idx] = i - 8; /* ... remap to X/Y/Z */
487 else
488 default_axis_map[idx] = i;
489 idx++;
491 else
492 newDevice->dev_axes_to_di[i] = -1;
495 for (i = 0; i < WINE_JOYSTICK_MAX_POVS; i++)
497 if (test_bit(newDevice->joydev->absbits, ABS_HAT0X + i * 2) &&
498 test_bit(newDevice->joydev->absbits, ABS_HAT0Y + i * 2))
500 newDevice->generic.device_axis_count += 2;
501 newDevice->generic.props[idx ].lDevMin = newDevice->joydev->axes[ABS_HAT0X + i * 2].minimum;
502 newDevice->generic.props[idx ].lDevMax = newDevice->joydev->axes[ABS_HAT0X + i * 2].maximum;
503 newDevice->dev_axes_to_di[ABS_HAT0X + i * 2] = idx;
504 newDevice->generic.props[idx+1].lDevMin = newDevice->joydev->axes[ABS_HAT0Y + i * 2].minimum;
505 newDevice->generic.props[idx+1].lDevMax = newDevice->joydev->axes[ABS_HAT0Y + i * 2].maximum;
506 newDevice->dev_axes_to_di[ABS_HAT0Y + i * 2] = idx + 1;
508 default_axis_map[idx] = default_axis_map[idx + 1] = WINE_JOYSTICK_MAX_AXES + i;
509 idx += 2;
511 else
512 newDevice->dev_axes_to_di[ABS_HAT0X + i * 2] = newDevice->dev_axes_to_di[ABS_HAT0Y + i * 2] = -1;
515 /* do any user specified configuration */
516 if (setup_dinput_options(&newDevice->generic, default_axis_map) != DI_OK) goto failed;
518 /* Create copy of default data format */
519 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto failed;
520 memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
521 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
524 /* Construct internal data format */
526 /* Supported Axis & POVs */
527 for (i = 0, idx = 0; i < newDevice->generic.device_axis_count; i++)
529 int wine_obj = newDevice->generic.axis_map[i];
531 if (wine_obj < 0) continue;
533 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize);
534 if (wine_obj < 8)
535 df->rgodf[idx].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS;
536 else
538 df->rgodf[idx].dwType = DIDFT_MAKEINSTANCE(wine_obj - 8) | DIDFT_POV;
539 i++; /* POV takes 2 axes */
542 newDevice->generic.props[idx].lMin = 0;
543 newDevice->generic.props[idx].lMax = 0xffff;
544 newDevice->generic.props[idx].lSaturation = 0;
545 newDevice->generic.props[idx].lDeadZone = newDevice->generic.deadzone;
547 /* Linux supports force-feedback on X & Y axes only */
548 if (newDevice->joydev->has_ff && (i == 0 || i == 1))
549 df->rgodf[idx].dwFlags |= DIDOI_FFACTUATOR;
551 idx++;
554 /* Buttons can be anywhere, so check all */
555 for (i = 0; i < KEY_MAX && newDevice->generic.devcaps.dwButtons < WINE_JOYSTICK_MAX_BUTTONS; i++)
557 if (!test_bit(newDevice->joydev->keybits, i)) continue;
559 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[newDevice->generic.devcaps.dwButtons + 12], df->dwObjSize);
560 newDevice->buttons[i] = 0x80 | newDevice->generic.devcaps.dwButtons;
561 df->rgodf[idx ].pguid = &GUID_Button;
562 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->generic.devcaps.dwButtons++) | DIDFT_PSHBUTTON;
564 df->dwNumObjs = idx;
565 newDevice->generic.base.data_format.wine_df = df;
567 fake_current_js_state(newDevice);
569 /* Fill the caps */
570 newDevice->generic.devcaps.dwSize = sizeof(newDevice->generic.devcaps);
571 newDevice->generic.devcaps.dwFlags = DIDC_ATTACHED;
573 ddi.dwSize = sizeof(ddi);
574 fill_joystick_dideviceinstanceW(&ddi, newDevice->generic.base.dinput->dwVersion, index);
575 newDevice->generic.devcaps.dwDevType = ddi.dwDevType;
577 if (newDevice->joydev->has_ff)
578 newDevice->generic.devcaps.dwFlags |= DIDC_FORCEFEEDBACK;
580 *out = newDevice;
581 return DI_OK;
583 failed:
584 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
585 HeapFree(GetProcessHeap(), 0, df);
586 HeapFree(GetProcessHeap(), 0, newDevice->generic.axis_map);
587 HeapFree(GetProcessHeap(), 0, newDevice);
588 return DIERR_OUTOFMEMORY;
591 /******************************************************************************
592 * get_joystick_index : Get the joystick index from a given GUID
594 static unsigned short get_joystick_index(REFGUID guid)
596 GUID wine_joystick = DInput_Wine_Joystick_Base_GUID;
597 GUID dev_guid = *guid;
598 INT i;
600 wine_joystick.Data3 = 0;
601 dev_guid.Data3 = 0;
603 /* for the standard joystick GUID use index 0 */
604 if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
606 /* for the wine joystick GUIDs use the index stored in Data3 */
607 if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3 - DInput_Wine_Joystick_Base_GUID.Data3;
609 for(i = 0; i < have_joydevs; i++)
610 if(IsEqualGUID(&joydevs[i].guid_product, guid)) return i;
612 return MAX_JOYDEV;
615 static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
617 unsigned short index;
619 TRACE("%p %s %s %p %i\n", dinput, debugstr_guid(rguid), debugstr_guid(riid), pdev, unicode);
620 find_joydevs();
621 *pdev = NULL;
623 if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
624 have_joydevs && index < have_joydevs)
626 JoystickImpl *This;
627 HRESULT hr;
629 if (riid == NULL)
630 ;/* nothing */
631 else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
632 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
633 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
634 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
636 unicode = 0;
638 else if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
639 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
640 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
641 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
643 unicode = 1;
645 else
647 WARN("no interface\n");
648 return DIERR_NOINTERFACE;
651 if (FAILED(hr = alloc_device( rguid, dinput, &This, index ))) return hr;
653 TRACE( "Created a Joystick device (%p)\n", This );
655 if (unicode)
656 *pdev = &This->generic.base.IDirectInputDevice8W_iface;
657 else
658 *pdev = &This->generic.base.IDirectInputDevice8A_iface;
660 return DI_OK;
663 return DIERR_DEVICENOTREG;
667 const struct dinput_device joystick_linuxinput_device = {
668 "Wine Linux-input joystick driver",
669 joydev_enum_deviceA,
670 joydev_enum_deviceW,
671 joydev_create_device
674 /******************************************************************************
675 * Acquire : gets exclusive control of the joystick
677 static HRESULT WINAPI JoystickWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
679 JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
680 HRESULT res;
682 TRACE("(this=%p)\n",This);
684 if ((res = IDirectInputDevice2WImpl_Acquire(iface)) != DI_OK)
686 WARN("Failed to acquire: %x\n", res);
687 return res;
690 if ((This->joyfd = open(This->joydev->device, O_RDWR)) == -1)
692 if ((This->joyfd = open(This->joydev->device, O_RDONLY)) == -1)
694 /* Couldn't open the device at all */
695 ERR("Failed to open device %s: %d %s\n", This->joydev->device, errno, strerror(errno));
696 IDirectInputDevice2WImpl_Unacquire(iface);
697 return DIERR_NOTFOUND;
699 else
701 /* Couldn't open in r/w but opened in read-only. */
702 WARN("Could not open %s in read-write mode. Force feedback will be disabled.\n", This->joydev->device);
705 else
707 struct input_event event;
709 event.type = EV_FF;
710 event.code = FF_GAIN;
711 event.value = This->ff_gain;
712 if (write(This->joyfd, &event, sizeof(event)) == -1)
713 ERR("Failed to set gain (%i): %d %s\n", This->ff_gain, errno, strerror(errno));
714 if (!This->ff_autocenter)
716 /* Disable autocenter. */
717 event.code = FF_AUTOCENTER;
718 event.value = 0;
719 if (write(This->joyfd, &event, sizeof(event)) == -1)
720 ERR("Failed disabling autocenter: %d %s\n", errno, strerror(errno));
724 return DI_OK;
727 /******************************************************************************
728 * Unacquire : frees the joystick
730 static HRESULT WINAPI JoystickWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface)
732 JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
733 HRESULT res;
735 TRACE("(this=%p)\n",This);
736 res = IDirectInputDevice2WImpl_Unacquire(iface);
737 if (res==DI_OK && This->joyfd!=-1) {
738 struct input_event event;
740 /* Stop and unload all effects */
741 JoystickWImpl_SendForceFeedbackCommand(iface, DISFFC_RESET);
743 /* Enable autocenter. */
744 event.type = EV_FF;
745 event.code = FF_AUTOCENTER;
746 /* TODO: Read autocenter strength before disabling it, and use it here
747 * instead of 0xFFFF (maximum strength).
749 event.value = 0xFFFF;
750 if (write(This->joyfd, &event, sizeof(event)) == -1)
751 ERR("Failed to set autocenter to %04x: %d %s\n", event.value, errno, strerror(errno));
753 close(This->joyfd);
754 This->joyfd = -1;
756 return res;
760 * set the current state of the js device as it would be with the middle
761 * values on the axes
763 #define CENTER_AXIS(a) \
764 (ji->dev_axes_to_di[a] == -1 ? 0 : joystick_map_axis( &ji->generic.props[ji->dev_axes_to_di[a]], \
765 ji->joydev->axes[a].value ))
766 static void fake_current_js_state(JoystickImpl *ji)
768 int i;
770 /* center the axes */
771 ji->generic.js.lX = CENTER_AXIS(ABS_X);
772 ji->generic.js.lY = CENTER_AXIS(ABS_Y);
773 ji->generic.js.lZ = CENTER_AXIS(ABS_Z);
774 ji->generic.js.lRx = CENTER_AXIS(ABS_RX);
775 ji->generic.js.lRy = CENTER_AXIS(ABS_RY);
776 ji->generic.js.lRz = CENTER_AXIS(ABS_RZ);
777 ji->generic.js.rglSlider[0] = CENTER_AXIS(ABS_THROTTLE);
778 ji->generic.js.rglSlider[1] = CENTER_AXIS(ABS_RUDDER);
780 /* POV center is -1 */
781 for (i = 0; i < 4; i++)
782 ji->generic.js.rgdwPOV[i] = -1;
784 #undef CENTER_AXIS
786 /* convert wine format offset to user format object index */
787 static void joy_polldev( IDirectInputDevice8W *iface )
789 struct pollfd plfd;
790 struct input_event ie;
791 JoystickImpl *This = impl_from_IDirectInputDevice8W( iface );
793 if (This->joyfd==-1)
794 return;
796 while (1)
798 LONG value = 0;
799 int inst_id = -1;
801 plfd.fd = This->joyfd;
802 plfd.events = POLLIN;
804 if (poll(&plfd,1,0) != 1)
805 return;
807 /* we have one event, so we can read */
808 if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
809 return;
811 TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
812 switch (ie.type) {
813 case EV_KEY: /* button */
815 int btn = This->buttons[ie.code];
817 TRACE("(%p) %d -> %d\n", This, ie.code, btn);
818 if (btn & 0x80)
820 btn &= 0x7F;
821 inst_id = DIDFT_MAKEINSTANCE(btn) | DIDFT_PSHBUTTON;
822 This->generic.js.rgbButtons[btn] = value = ie.value ? 0x80 : 0x00;
824 break;
826 case EV_ABS:
828 int axis = This->dev_axes_to_di[ie.code];
830 /* User axis remapping */
831 if (axis < 0) break;
832 axis = This->generic.axis_map[axis];
833 if (axis < 0) break;
835 inst_id = axis < 8 ? DIDFT_MAKEINSTANCE(axis) | DIDFT_ABSAXIS :
836 DIDFT_MAKEINSTANCE(axis - 8) | DIDFT_POV;
837 value = joystick_map_axis(&This->generic.props[id_to_object(This->generic.base.data_format.wine_df, inst_id)], ie.value);
839 switch (axis) {
840 case 0: This->generic.js.lX = value; break;
841 case 1: This->generic.js.lY = value; break;
842 case 2: This->generic.js.lZ = value; break;
843 case 3: This->generic.js.lRx = value; break;
844 case 4: This->generic.js.lRy = value; break;
845 case 5: This->generic.js.lRz = value; break;
846 case 6: This->generic.js.rglSlider[0] = value; break;
847 case 7: This->generic.js.rglSlider[1] = value; break;
848 case 8: case 9: case 10: case 11:
850 int idx = axis - 8;
852 if (ie.code % 2)
853 This->povs[idx].y = ie.value;
854 else
855 This->povs[idx].x = ie.value;
857 This->generic.js.rgdwPOV[idx] = value = joystick_map_pov(&This->povs[idx]);
858 break;
860 default:
861 FIXME("unhandled joystick axis event (code %d, value %d)\n",ie.code,ie.value);
863 break;
865 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
866 case EV_FF_STATUS:
867 This->ff_state = ie.value;
868 break;
869 #endif
870 #ifdef EV_SYN
871 case EV_SYN:
872 /* there is nothing to do */
873 break;
874 #endif
875 #ifdef EV_MSC
876 case EV_MSC:
877 /* Ignore */
878 break;
879 #endif
880 default:
881 TRACE("skipping event\n");
882 break;
884 if (inst_id >= 0)
885 queue_event(iface, inst_id,
886 value, GetCurrentTime(), This->generic.base.dinput->evsequence++);
890 /******************************************************************************
891 * SetProperty : change input device properties
893 static HRESULT WINAPI JoystickWImpl_SetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPCDIPROPHEADER ph)
895 JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
897 if (!ph) {
898 WARN("invalid argument\n");
899 return DIERR_INVALIDPARAM;
902 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
903 TRACE("ph.dwSize = %d, ph.dwHeaderSize =%d, ph.dwObj = %d, ph.dwHow= %d\n",
904 ph->dwSize, ph->dwHeaderSize, ph->dwObj, ph->dwHow);
906 if (IS_DIPROP(rguid)) {
907 switch (LOWORD(rguid)) {
908 case (DWORD_PTR)DIPROP_AUTOCENTER: {
909 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
911 TRACE("autocenter(%d)\n", pd->dwData);
912 This->ff_autocenter = pd->dwData == DIPROPAUTOCENTER_ON;
914 break;
916 case (DWORD_PTR)DIPROP_FFGAIN: {
917 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
919 TRACE("DIPROP_FFGAIN(%d)\n", pd->dwData);
920 This->ff_gain = MulDiv(pd->dwData, 0xFFFF, 10000);
921 if (This->generic.base.acquired) {
922 /* Update immediately. */
923 struct input_event event;
925 event.type = EV_FF;
926 event.code = FF_GAIN;
927 event.value = This->ff_gain;
928 if (write(This->joyfd, &event, sizeof(event)) == -1)
929 ERR("Failed to set gain (%i): %d %s\n", This->ff_gain, errno, strerror(errno));
931 break;
933 default:
934 return JoystickWGenericImpl_SetProperty(iface, rguid, ph);
937 return DI_OK;
940 /******************************************************************************
941 * GetProperty : get input device properties
943 static HRESULT WINAPI JoystickWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPDIPROPHEADER pdiph)
945 JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
947 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(rguid), pdiph);
948 _dump_DIPROPHEADER(pdiph);
950 if (!IS_DIPROP(rguid)) return DI_OK;
952 switch (LOWORD(rguid)) {
953 case (DWORD_PTR) DIPROP_AUTOCENTER:
955 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
957 pd->dwData = This->ff_autocenter ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF;
958 TRACE("autocenter(%d)\n", pd->dwData);
959 break;
961 case (DWORD_PTR) DIPROP_FFGAIN:
963 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
965 pd->dwData = MulDiv(This->ff_gain, 10000, 0xFFFF);
966 TRACE("DIPROP_FFGAIN(%d)\n", pd->dwData);
967 break;
970 case (DWORD_PTR) DIPROP_VIDPID:
972 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
974 if (!This->joydev->product_id || !This->joydev->vendor_id)
975 return DIERR_UNSUPPORTED;
976 pd->dwData = MAKELONG(This->joydev->vendor_id, This->joydev->product_id);
977 TRACE("DIPROP_VIDPID(%08x)\n", pd->dwData);
978 break;
981 case (DWORD_PTR) DIPROP_JOYSTICKID:
983 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
985 pd->dwData = get_joystick_index(&This->generic.base.guid);
986 TRACE("DIPROP_JOYSTICKID(%d)\n", pd->dwData);
987 break;
990 case (DWORD_PTR) DIPROP_GUIDANDPATH:
992 static const WCHAR formatW[] = {'\\','\\','?','\\','h','i','d','#','v','i','d','_','%','0','4','x','&',
993 'p','i','d','_','%','0','4','x','&','%','s','_','%','h','u',0};
994 static const WCHAR miW[] = {'m','i',0};
995 static const WCHAR igW[] = {'i','g',0};
997 BOOL is_gamepad;
998 LPDIPROPGUIDANDPATH pd = (LPDIPROPGUIDANDPATH)pdiph;
999 WORD vid = This->joydev->vendor_id;
1000 WORD pid = This->joydev->product_id;
1002 if (!pid || !vid)
1003 return DIERR_UNSUPPORTED;
1005 is_gamepad = is_xinput_device(&This->generic.devcaps, vid, pid);
1006 pd->guidClass = GUID_DEVCLASS_HIDCLASS;
1007 sprintfW(pd->wszPath, formatW, vid, pid, is_gamepad ? igW : miW, get_joystick_index(&This->generic.base.guid));
1009 TRACE("DIPROP_GUIDANDPATH(%s, %s): returning fake path\n", debugstr_guid(&pd->guidClass), debugstr_w(pd->wszPath));
1010 break;
1013 default:
1014 return JoystickWGenericImpl_GetProperty(iface, rguid, pdiph);
1017 return DI_OK;
1020 /******************************************************************************
1021 * CreateEffect - Create a new FF effect with the specified params
1023 static HRESULT WINAPI JoystickWImpl_CreateEffect(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid,
1024 LPCDIEFFECT lpeff, LPDIRECTINPUTEFFECT *ppdef,
1025 LPUNKNOWN pUnkOuter)
1027 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1028 effect_list_item* new_effect = NULL;
1029 HRESULT retval = DI_OK;
1030 #endif
1032 JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
1033 TRACE("(this=%p,%p,%p,%p,%p)\n", This, rguid, lpeff, ppdef, pUnkOuter);
1035 *ppdef = NULL;
1036 if (!This->joydev->has_ff)
1038 TRACE("No force feedback support\n");
1039 return DIERR_UNSUPPORTED;
1042 #ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
1043 TRACE("not available (compiled w/o force feedback support)\n");
1044 return DIERR_UNSUPPORTED;
1045 #else
1047 if (!(new_effect = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_effect))))
1048 return DIERR_OUTOFMEMORY;
1050 retval = linuxinput_create_effect(&This->joyfd, rguid, &new_effect->entry, &new_effect->ref);
1051 if (retval != DI_OK)
1053 HeapFree(GetProcessHeap(), 0, new_effect);
1054 return retval;
1057 if (lpeff != NULL)
1059 retval = IDirectInputEffect_SetParameters(new_effect->ref, lpeff,
1060 DIEP_AXES | DIEP_DIRECTION | DIEP_DURATION | DIEP_ENVELOPE |
1061 DIEP_GAIN | DIEP_SAMPLEPERIOD | DIEP_STARTDELAY | DIEP_TRIGGERBUTTON |
1062 DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS);
1064 if (retval != DI_OK && retval != DI_DOWNLOADSKIPPED)
1066 HeapFree(GetProcessHeap(), 0, new_effect);
1067 return retval;
1071 list_add_tail(&This->ff_effects, &new_effect->entry);
1072 *ppdef = new_effect->ref;
1074 if (pUnkOuter != NULL)
1075 FIXME("Interface aggregation not implemented.\n");
1077 return DI_OK;
1079 #endif /* HAVE_STRUCT_FF_EFFECT_DIRECTION */
1082 /*******************************************************************************
1083 * EnumEffects - Enumerate available FF effects
1085 static HRESULT WINAPI JoystickWImpl_EnumEffects(LPDIRECTINPUTDEVICE8W iface,
1086 LPDIENUMEFFECTSCALLBACKW lpCallback,
1087 LPVOID pvRef,
1088 DWORD dwEffType)
1090 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1091 /* seems silly to duplicate all this code but all the structures and functions
1092 * are actually different (A/W) */
1093 DIEFFECTINFOW dei; /* feif */
1094 DWORD type = DIEFT_GETTYPE(dwEffType);
1095 JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
1096 int xfd = This->joyfd;
1098 TRACE("(this=%p,%p,%d) type=%d fd=%d\n", This, pvRef, dwEffType, type, xfd);
1100 dei.dwSize = sizeof(DIEFFECTINFOW);
1102 if ((type == DIEFT_ALL || type == DIEFT_CONSTANTFORCE)
1103 && test_bit(This->joydev->ffbits, FF_CONSTANT)) {
1104 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_ConstantForce);
1105 (*lpCallback)(&dei, pvRef);
1108 if ((type == DIEFT_ALL || type == DIEFT_PERIODIC)
1109 && test_bit(This->joydev->ffbits, FF_PERIODIC)) {
1110 if (test_bit(This->joydev->ffbits, FF_SQUARE)) {
1111 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Square);
1112 (*lpCallback)(&dei, pvRef);
1114 if (test_bit(This->joydev->ffbits, FF_SINE)) {
1115 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Sine);
1116 (*lpCallback)(&dei, pvRef);
1118 if (test_bit(This->joydev->ffbits, FF_TRIANGLE)) {
1119 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Triangle);
1120 (*lpCallback)(&dei, pvRef);
1122 if (test_bit(This->joydev->ffbits, FF_SAW_UP)) {
1123 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothUp);
1124 (*lpCallback)(&dei, pvRef);
1126 if (test_bit(This->joydev->ffbits, FF_SAW_DOWN)) {
1127 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_SawtoothDown);
1128 (*lpCallback)(&dei, pvRef);
1132 if ((type == DIEFT_ALL || type == DIEFT_RAMPFORCE)
1133 && test_bit(This->joydev->ffbits, FF_RAMP)) {
1134 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_RampForce);
1135 (*lpCallback)(&dei, pvRef);
1138 if (type == DIEFT_ALL || type == DIEFT_CONDITION) {
1139 if (test_bit(This->joydev->ffbits, FF_SPRING)) {
1140 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Spring);
1141 (*lpCallback)(&dei, pvRef);
1143 if (test_bit(This->joydev->ffbits, FF_DAMPER)) {
1144 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Damper);
1145 (*lpCallback)(&dei, pvRef);
1147 if (test_bit(This->joydev->ffbits, FF_INERTIA)) {
1148 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Inertia);
1149 (*lpCallback)(&dei, pvRef);
1151 if (test_bit(This->joydev->ffbits, FF_FRICTION)) {
1152 IDirectInputDevice8_GetEffectInfo(iface, &dei, &GUID_Friction);
1153 (*lpCallback)(&dei, pvRef);
1157 /* return to unacquired state if that's where it was */
1158 if (xfd == -1)
1159 IDirectInputDevice8_Unacquire(iface);
1160 #endif
1162 return DI_OK;
1165 /*******************************************************************************
1166 * GetEffectInfo - Get information about a particular effect
1168 static HRESULT WINAPI JoystickWImpl_GetEffectInfo(LPDIRECTINPUTDEVICE8W iface,
1169 LPDIEFFECTINFOW pdei,
1170 REFGUID guid)
1172 JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
1174 TRACE("(this=%p,%p,%s)\n", This, pdei, _dump_dinput_GUID(guid));
1176 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1177 return linuxinput_get_info_W(This->joyfd, guid, pdei);
1178 #else
1179 return DI_OK;
1180 #endif
1183 /*******************************************************************************
1184 * GetForceFeedbackState - Get information about the device's FF state
1186 static HRESULT WINAPI JoystickWImpl_GetForceFeedbackState(LPDIRECTINPUTDEVICE8W iface, LPDWORD pdwOut)
1188 JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
1190 TRACE("(this=%p,%p)\n", This, pdwOut);
1192 (*pdwOut) = 0;
1194 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1195 /* DIGFFS_STOPPED is the only mandatory flag to report */
1196 if (This->ff_state == FF_STATUS_STOPPED)
1197 (*pdwOut) |= DIGFFS_STOPPED;
1198 #endif
1200 return DI_OK;
1203 /*******************************************************************************
1204 * SendForceFeedbackCommand - Send a command to the device's FF system
1206 static HRESULT WINAPI JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface, DWORD dwFlags)
1208 JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
1209 TRACE("(this=%p,%d)\n", This, dwFlags);
1211 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
1212 switch (dwFlags)
1214 case DISFFC_STOPALL:
1216 effect_list_item *itr;
1218 /* Stop all effects */
1219 LIST_FOR_EACH_ENTRY(itr, &This->ff_effects, effect_list_item, entry)
1220 IDirectInputEffect_Stop(itr->ref);
1221 break;
1224 case DISFFC_RESET:
1226 effect_list_item *itr;
1228 /* Stop and unload all effects. It is not true that effects are released */
1229 LIST_FOR_EACH_ENTRY(itr, &This->ff_effects, effect_list_item, entry)
1231 IDirectInputEffect_Stop(itr->ref);
1232 IDirectInputEffect_Unload(itr->ref);
1234 break;
1236 case DISFFC_PAUSE:
1237 case DISFFC_CONTINUE:
1238 FIXME("No support for Pause or Continue in linux\n");
1239 break;
1241 case DISFFC_SETACTUATORSOFF:
1242 case DISFFC_SETACTUATORSON:
1243 FIXME("No direct actuator control in linux\n");
1244 break;
1246 default:
1247 WARN("Unknown Force Feedback Command %u!\n", dwFlags);
1248 return DIERR_INVALIDPARAM;
1250 return DI_OK;
1251 #else
1252 return DIERR_UNSUPPORTED;
1253 #endif
1256 /*******************************************************************************
1257 * EnumCreatedEffectObjects - Enumerate all the effects that have been
1258 * created for this device.
1260 static HRESULT WINAPI JoystickWImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface,
1261 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1262 LPVOID pvRef, DWORD dwFlags)
1264 /* this function is safe to call on non-ff-enabled builds */
1265 JoystickImpl* This = impl_from_IDirectInputDevice8W(iface);
1266 effect_list_item *itr, *ptr;
1268 TRACE("(this=%p,%p,%p,%d)\n", This, lpCallback, pvRef, dwFlags);
1270 if (!lpCallback)
1271 return DIERR_INVALIDPARAM;
1273 if (dwFlags != 0)
1274 FIXME("Flags specified, but no flags exist yet (DX9)!\n");
1276 LIST_FOR_EACH_ENTRY_SAFE(itr, ptr, &This->ff_effects, effect_list_item, entry)
1277 (*lpCallback)(itr->ref, pvRef);
1279 return DI_OK;
1282 /******************************************************************************
1283 * GetDeviceInfo : get information about a device's identity
1285 static HRESULT WINAPI JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface,
1286 LPDIDEVICEINSTANCEW pdidi)
1288 JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
1290 TRACE("(%p) %p\n", This, pdidi);
1292 if (pdidi == NULL) return E_POINTER;
1293 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3W)) &&
1294 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)))
1295 return DIERR_INVALIDPARAM;
1297 fill_joystick_dideviceinstanceW(pdidi, This->generic.base.dinput->dwVersion,
1298 get_joystick_index(&This->generic.base.guid));
1300 pdidi->guidInstance = This->generic.base.guid;
1302 return DI_OK;
1305 static const IDirectInputDevice8WVtbl JoystickWvt =
1307 IDirectInputDevice2WImpl_QueryInterface,
1308 IDirectInputDevice2WImpl_AddRef,
1309 IDirectInputDevice2WImpl_Release,
1310 JoystickWGenericImpl_GetCapabilities,
1311 IDirectInputDevice2WImpl_EnumObjects,
1312 JoystickWImpl_GetProperty,
1313 JoystickWImpl_SetProperty,
1314 JoystickWImpl_Acquire,
1315 JoystickWImpl_Unacquire,
1316 JoystickWGenericImpl_GetDeviceState,
1317 IDirectInputDevice2WImpl_GetDeviceData,
1318 IDirectInputDevice2WImpl_SetDataFormat,
1319 IDirectInputDevice2WImpl_SetEventNotification,
1320 IDirectInputDevice2WImpl_SetCooperativeLevel,
1321 JoystickWGenericImpl_GetObjectInfo,
1322 JoystickWImpl_GetDeviceInfo,
1323 IDirectInputDevice2WImpl_RunControlPanel,
1324 IDirectInputDevice2WImpl_Initialize,
1325 JoystickWImpl_CreateEffect,
1326 JoystickWImpl_EnumEffects,
1327 JoystickWImpl_GetEffectInfo,
1328 JoystickWImpl_GetForceFeedbackState,
1329 JoystickWImpl_SendForceFeedbackCommand,
1330 JoystickWImpl_EnumCreatedEffectObjects,
1331 IDirectInputDevice2WImpl_Escape,
1332 JoystickWGenericImpl_Poll,
1333 IDirectInputDevice2WImpl_SendDeviceData,
1334 IDirectInputDevice7WImpl_EnumEffectsInFile,
1335 IDirectInputDevice7WImpl_WriteEffectToFile,
1336 JoystickWGenericImpl_BuildActionMap,
1337 JoystickWGenericImpl_SetActionMap,
1338 IDirectInputDevice8WImpl_GetImageInfo
1341 #else /* HAS_PROPER_HEADER */
1343 const struct dinput_device joystick_linuxinput_device = {
1344 "Wine Linux-input joystick driver",
1345 NULL,
1346 NULL,
1347 NULL
1350 #endif /* HAS_PROPER_HEADER */