widl: Move support for stub arguments to typegen.c to make it usable for proxies...
[wine/multimedia.git] / dlls / dinput / joystick_linux.c
blobba63d9c8dabdec1852998afb74b8c4fbd1c0f838
1 /* DirectInput Joystick device
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * To Do:
24 * dead zone
25 * force feedback
28 #include "config.h"
29 #include "wine/port.h"
31 #include <stdarg.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <time.h>
35 #include <errno.h>
36 #ifdef HAVE_UNISTD_H
37 # include <unistd.h>
38 #endif
39 #ifdef HAVE_SYS_TIME_H
40 # include <sys/time.h>
41 #endif
42 #include <sys/fcntl.h>
43 #ifdef HAVE_SYS_IOCTL_H
44 # include <sys/ioctl.h>
45 #endif
46 #include <errno.h>
47 #ifdef HAVE_SYS_ERRNO_H
48 # include <sys/errno.h>
49 #endif
50 #ifdef HAVE_LINUX_IOCTL_H
51 # include <linux/ioctl.h>
52 #endif
53 #ifdef HAVE_LINUX_JOYSTICK_H
54 # include <linux/joystick.h>
55 # undef SW_MAX
56 #endif
57 #ifdef HAVE_SYS_POLL_H
58 # include <sys/poll.h>
59 #endif
61 #include "wine/debug.h"
62 #include "wine/unicode.h"
63 #include "windef.h"
64 #include "winbase.h"
65 #include "winerror.h"
66 #include "winreg.h"
67 #include "dinput.h"
69 #include "dinput_private.h"
70 #include "device_private.h"
72 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
74 #ifdef HAVE_LINUX_22_JOYSTICK_API
76 #define JOYDEV_NEW "/dev/input/js"
77 #define JOYDEV_OLD "/dev/js"
79 typedef struct {
80 LONG lMin;
81 LONG lMax;
82 LONG lDeadZone;
83 LONG lSaturation;
84 } ObjProps;
86 typedef struct {
87 LONG lX;
88 LONG lY;
89 } POV;
91 typedef struct JoystickImpl JoystickImpl;
92 static const IDirectInputDevice8AVtbl JoystickAvt;
93 static const IDirectInputDevice8WVtbl JoystickWvt;
94 struct JoystickImpl
96 struct IDirectInputDevice2AImpl base;
98 char dev[32];
100 /* The 'parent' DInput */
101 IDirectInputImpl *dinput;
103 /* joystick private */
104 int joyfd;
105 DIJOYSTATE2 js; /* wine data */
106 ObjProps *props;
107 char *name;
108 DIDEVCAPS devcaps;
109 LONG deadzone;
110 int *axis_map;
111 int axes;
112 int buttons;
113 POV povs[4];
116 static GUID DInput_Wine_Joystick_GUID = { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
117 0x9e573ed9,
118 0x7734,
119 0x11d2,
120 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
123 static void _dump_DIDEVCAPS(LPDIDEVCAPS lpDIDevCaps)
125 TRACE("dwSize: %d\n", lpDIDevCaps->dwSize);
126 TRACE("dwFlags: %08x\n", lpDIDevCaps->dwFlags);
127 TRACE("dwDevType: %08x %s\n", lpDIDevCaps->dwDevType,
128 lpDIDevCaps->dwDevType == DIDEVTYPE_DEVICE ? "DIDEVTYPE_DEVICE" :
129 lpDIDevCaps->dwDevType == DIDEVTYPE_DEVICE ? "DIDEVTYPE_DEVICE" :
130 lpDIDevCaps->dwDevType == DIDEVTYPE_MOUSE ? "DIDEVTYPE_MOUSE" :
131 lpDIDevCaps->dwDevType == DIDEVTYPE_KEYBOARD ? "DIDEVTYPE_KEYBOARD" :
132 lpDIDevCaps->dwDevType == DIDEVTYPE_JOYSTICK ? "DIDEVTYPE_JOYSTICK" :
133 lpDIDevCaps->dwDevType == DIDEVTYPE_HID ? "DIDEVTYPE_HID" : "UNKNOWN");
134 TRACE("dwAxes: %d\n", lpDIDevCaps->dwAxes);
135 TRACE("dwButtons: %d\n", lpDIDevCaps->dwButtons);
136 TRACE("dwPOVs: %d\n", lpDIDevCaps->dwPOVs);
137 if (lpDIDevCaps->dwSize > sizeof(DIDEVCAPS_DX3)) {
138 TRACE("dwFFSamplePeriod: %d\n", lpDIDevCaps->dwFFSamplePeriod);
139 TRACE("dwFFMinTimeResolution: %d\n", lpDIDevCaps->dwFFMinTimeResolution);
140 TRACE("dwFirmwareRevision: %d\n", lpDIDevCaps->dwFirmwareRevision);
141 TRACE("dwHardwareRevision: %d\n", lpDIDevCaps->dwHardwareRevision);
142 TRACE("dwFFDriverVersion: %d\n", lpDIDevCaps->dwFFDriverVersion);
146 static int joydev_get_device(char *dev, int id)
148 int ret;
149 sprintf(dev, "%s%d", JOYDEV_NEW, id);
150 if ((ret = open(dev, O_RDONLY)) < 0) {
151 sprintf(dev, "%s%d", JOYDEV_OLD, id);
152 if ((ret = open(dev, O_RDONLY)) < 0) {
153 return -1;
156 return ret;
159 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
161 int fd = -1;
162 char dev[32];
164 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
165 WARN("force feedback not supported\n");
166 return FALSE;
169 if ((dwDevType == 0) ||
170 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
171 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
172 /* check whether we have a joystick */
173 if ((fd = joydev_get_device(dev, id)) < 0) {
174 WARN("open(%s,O_RDONLY) failed: %s\n", dev, strerror(errno));
175 return FALSE;
178 /* Return joystick */
179 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
180 lpddi->guidInstance.Data3 = id;
181 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
182 /* we only support traditional joysticks for now */
183 if (version >= 0x0800)
184 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
185 else
186 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
187 sprintf(lpddi->tszInstanceName, "Joystick %d", id);
188 #if defined(JSIOCGNAME)
189 if (ioctl(fd,JSIOCGNAME(sizeof(lpddi->tszProductName)),lpddi->tszProductName) < 0) {
190 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", dev, strerror(errno));
191 strcpy(lpddi->tszProductName, "Wine Joystick");
193 #else
194 strcpy(lpddi->tszProductName, "Wine Joystick");
195 #endif
197 lpddi->guidFFDriver = GUID_NULL;
198 close(fd);
199 TRACE("Enumerating the linux Joystick device: %s (%s)\n", dev, lpddi->tszProductName);
200 return TRUE;
203 return FALSE;
206 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
208 int fd = -1;
209 char name[MAX_PATH];
210 char dev[32];
211 char friendly[32];
213 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
214 WARN("force feedback not supported\n");
215 return FALSE;
218 if ((dwDevType == 0) ||
219 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
220 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
221 /* check whether we have a joystick */
222 if ((fd = joydev_get_device(dev, id)) < 0) {
223 WARN("open(%s,O_RDONLY) failed: %s\n", dev, strerror(errno));
224 return FALSE;
227 /* Return joystick */
228 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
229 lpddi->guidInstance.Data3 = id;
230 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
231 /* we only support traditional joysticks for now */
232 if (version >= 0x0800)
233 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
234 else
235 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
236 sprintf(friendly, "Joystick %d", id);
237 MultiByteToWideChar(CP_ACP, 0, friendly, -1, lpddi->tszInstanceName, MAX_PATH);
238 #if defined(JSIOCGNAME)
239 if (ioctl(fd,JSIOCGNAME(sizeof(name)),name) < 0) {
240 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", dev, strerror(errno));
241 strcpy(name, "Wine Joystick");
243 #else
244 strcpy(name, "Wine Joystick");
245 #endif
246 MultiByteToWideChar(CP_ACP, 0, name, -1, lpddi->tszProductName, MAX_PATH);
247 lpddi->guidFFDriver = GUID_NULL;
248 close(fd);
249 TRACE("Enumerating the linux Joystick device: %s (%s)\n",dev,name);
250 return TRUE;
253 return FALSE;
257 * Get a config key from either the app-specific or the default config
260 inline static DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
261 char *buffer, DWORD size )
263 if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size ))
264 return 0;
266 if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size ))
267 return 0;
269 return ERROR_FILE_NOT_FOUND;
273 * Setup the dinput options.
276 static HRESULT setup_dinput_options(JoystickImpl * device)
278 char buffer[MAX_PATH+16];
279 HKEY hkey, appkey = 0;
280 DWORD len;
282 buffer[MAX_PATH]='\0';
284 /* @@ Wine registry key: HKCU\Software\Wine\DirectInput */
285 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectInput", &hkey)) hkey = 0;
287 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
288 if (len && len < MAX_PATH) {
289 HKEY tmpkey;
290 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectInput */
291 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
293 char *p, *appname = buffer;
294 if ((p = strrchr( appname, '/' ))) appname = p + 1;
295 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
296 strcat( appname, "\\DirectInput" );
297 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
298 RegCloseKey( tmpkey );
302 /* get options */
304 if (!get_config_key( hkey, appkey, "DefaultDeadZone", buffer, MAX_PATH )) {
305 device->deadzone = atoi(buffer);
306 TRACE("setting default deadzone to: \"%s\" %d\n", buffer, device->deadzone);
309 if (!get_config_key( hkey, appkey, device->name, buffer, MAX_PATH )) {
310 int tokens = 0;
311 int axis = 0;
312 int pov = 0;
313 const char *delim = ",";
314 char * ptr;
315 TRACE("\"%s\" = \"%s\"\n", device->name, buffer);
317 device->axis_map = HeapAlloc(GetProcessHeap(), 0, device->axes * sizeof(int));
318 if (device->axis_map == 0)
319 return DIERR_OUTOFMEMORY;
321 if ((ptr = strtok(buffer, delim)) != NULL) {
322 do {
323 if (strcmp(ptr, "X") == 0) {
324 device->axis_map[tokens] = 0;
325 axis++;
326 } else if (strcmp(ptr, "Y") == 0) {
327 device->axis_map[tokens] = 1;
328 axis++;
329 } else if (strcmp(ptr, "Z") == 0) {
330 device->axis_map[tokens] = 2;
331 axis++;
332 } else if (strcmp(ptr, "Rx") == 0) {
333 device->axis_map[tokens] = 3;
334 axis++;
335 } else if (strcmp(ptr, "Ry") == 0) {
336 device->axis_map[tokens] = 4;
337 axis++;
338 } else if (strcmp(ptr, "Rz") == 0) {
339 device->axis_map[tokens] = 5;
340 axis++;
341 } else if (strcmp(ptr, "Slider1") == 0) {
342 device->axis_map[tokens] = 6;
343 axis++;
344 } else if (strcmp(ptr, "Slider2") == 0) {
345 device->axis_map[tokens] = 7;
346 axis++;
347 } else if (strcmp(ptr, "POV1") == 0) {
348 device->axis_map[tokens++] = 8;
349 device->axis_map[tokens] = 8;
350 pov++;
351 } else if (strcmp(ptr, "POV2") == 0) {
352 device->axis_map[tokens++] = 9;
353 device->axis_map[tokens] = 9;
354 pov++;
355 } else if (strcmp(ptr, "POV3") == 0) {
356 device->axis_map[tokens++] = 10;
357 device->axis_map[tokens] = 10;
358 pov++;
359 } else if (strcmp(ptr, "POV4") == 0) {
360 device->axis_map[tokens++] = 11;
361 device->axis_map[tokens] = 11;
362 pov++;
363 } else {
364 ERR("invalid joystick axis type: %s\n", ptr);
365 device->axis_map[tokens] = tokens;
366 axis++;
369 tokens++;
370 } while ((ptr = strtok(NULL, delim)) != NULL);
372 if (tokens != device->devcaps.dwAxes) {
373 ERR("not all joystick axes mapped: %d axes(%d,%d), %d arguments\n", device->axes, axis, pov,tokens);
374 while (tokens < device->axes) {
375 device->axis_map[tokens] = tokens;
376 tokens++;
381 device->devcaps.dwAxes = axis;
382 device->devcaps.dwPOVs = pov;
385 if (appkey)
386 RegCloseKey( appkey );
388 if (hkey)
389 RegCloseKey( hkey );
391 return DI_OK;
394 static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, LPDIRECTINPUTDEVICEA* pdev)
396 DWORD i;
397 JoystickImpl* newDevice;
398 char name[MAX_PATH];
399 HRESULT hr;
400 LPDIDATAFORMAT df = NULL;
401 int idx = 0;
403 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
404 if (newDevice == 0) {
405 WARN("out of memory\n");
406 *pdev = 0;
407 return DIERR_OUTOFMEMORY;
410 if ((newDevice->joyfd = joydev_get_device(newDevice->dev, rguid->Data3)) < 0) {
411 WARN("open(%s,O_RDONLY) failed: %s\n", newDevice->dev, strerror(errno));
412 HeapFree(GetProcessHeap(), 0, newDevice);
413 return DIERR_DEVICENOTREG;
416 /* get the device name */
417 #if defined(JSIOCGNAME)
418 if (ioctl(newDevice->joyfd,JSIOCGNAME(MAX_PATH),name) < 0) {
419 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", newDevice->dev, strerror(errno));
420 strcpy(name, "Wine Joystick");
422 #else
423 strcpy(name, "Wine Joystick");
424 #endif
426 /* copy the device name */
427 newDevice->name = HeapAlloc(GetProcessHeap(),0,strlen(name) + 1);
428 strcpy(newDevice->name, name);
430 #ifdef JSIOCGAXES
431 if (ioctl(newDevice->joyfd,JSIOCGAXES,&newDevice->axes) < 0) {
432 WARN("ioctl(%s,JSIOCGAXES) failed: %s, defauting to 2\n", newDevice->dev, strerror(errno));
433 newDevice->axes = 2;
435 #endif
436 #ifdef JSIOCGBUTTONS
437 if (ioctl(newDevice->joyfd,JSIOCGBUTTONS,&newDevice->buttons) < 0) {
438 WARN("ioctl(%s,JSIOCGBUTTONS) failed: %s, defauting to 2\n", newDevice->dev, strerror(errno));
439 newDevice->buttons = 2;
441 #endif
443 newDevice->base.lpVtbl = jvt;
444 newDevice->base.ref = 1;
445 newDevice->dinput = dinput;
446 CopyMemory(&newDevice->base.guid, rguid, sizeof(*rguid));
447 InitializeCriticalSection(&newDevice->base.crit);
448 newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)"DINPUT_joystick";
450 /* setup_dinput_options may change these */
451 newDevice->deadzone = 5000;
452 newDevice->devcaps.dwButtons = newDevice->buttons;
453 newDevice->devcaps.dwAxes = newDevice->axes;
454 newDevice->devcaps.dwPOVs = 0;
456 /* do any user specified configuration */
457 hr = setup_dinput_options(newDevice);
458 if (hr != DI_OK)
459 goto FAILED1;
461 if (newDevice->axis_map == 0) {
462 newDevice->axis_map = HeapAlloc(GetProcessHeap(), 0, newDevice->axes * sizeof(int));
463 if (newDevice->axis_map == 0)
464 goto FAILED;
466 for (i = 0; i < newDevice->axes; i++)
467 newDevice->axis_map[i] = i;
470 /* Create copy of default data format */
471 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto FAILED;
472 memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
474 /* Axes include POVs */
475 df->dwNumObjs = newDevice->axes + newDevice->buttons;
476 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto FAILED;
478 for (i = 0; i < newDevice->axes; i++)
480 int wine_obj = newDevice->axis_map[i];
482 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize);
483 if (wine_obj < 8)
484 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS;
485 else
486 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj - 8) | DIDFT_POV;
488 for (i = 0; i < newDevice->buttons; i++)
490 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + 12], df->dwObjSize);
491 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
493 newDevice->base.data_format.wine_df = df;
495 /* create default properties */
496 newDevice->props = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwNumObjs*sizeof(ObjProps));
497 if (newDevice->props == 0)
498 goto FAILED;
500 /* initialize default properties */
501 for (i = 0; i < c_dfDIJoystick2.dwNumObjs; i++) {
502 newDevice->props[i].lMin = 0;
503 newDevice->props[i].lMax = 0xffff;
504 newDevice->props[i].lDeadZone = newDevice->deadzone; /* % * 1000 */
505 newDevice->props[i].lSaturation = 0;
508 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
510 newDevice->devcaps.dwSize = sizeof(newDevice->devcaps);
511 newDevice->devcaps.dwFlags = DIDC_ATTACHED;
512 if (newDevice->dinput->dwVersion >= 0x0800)
513 newDevice->devcaps.dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
514 else
515 newDevice->devcaps.dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
516 newDevice->devcaps.dwFFSamplePeriod = 0;
517 newDevice->devcaps.dwFFMinTimeResolution = 0;
518 newDevice->devcaps.dwFirmwareRevision = 0;
519 newDevice->devcaps.dwHardwareRevision = 0;
520 newDevice->devcaps.dwFFDriverVersion = 0;
522 if (TRACE_ON(dinput)) {
523 _dump_DIDATAFORMAT(newDevice->base.data_format.wine_df);
524 for (i = 0; i < (newDevice->axes); i++)
525 TRACE("axis_map[%d] = %d\n", i, newDevice->axis_map[i]);
526 _dump_DIDEVCAPS(&newDevice->devcaps);
529 *pdev = (LPDIRECTINPUTDEVICEA)newDevice;
531 return DI_OK;
533 FAILED:
534 hr = DIERR_OUTOFMEMORY;
535 FAILED1:
536 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
537 HeapFree(GetProcessHeap(), 0, df);
538 release_DataFormat(&newDevice->base.data_format);
539 HeapFree(GetProcessHeap(),0,newDevice->axis_map);
540 HeapFree(GetProcessHeap(),0,newDevice->name);
541 HeapFree(GetProcessHeap(),0,newDevice->props);
542 HeapFree(GetProcessHeap(),0,newDevice);
543 *pdev = 0;
545 return hr;
548 static BOOL IsJoystickGUID(REFGUID guid)
550 GUID wine_joystick = DInput_Wine_Joystick_GUID;
551 GUID dev_guid = *guid;
553 wine_joystick.Data3 = 0;
554 dev_guid.Data3 = 0;
556 return IsEqualGUID(&wine_joystick, &dev_guid);
559 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
561 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
562 (IsJoystickGUID(rguid))) {
563 if ((riid == NULL) ||
564 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
565 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
566 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
567 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
568 return alloc_device(rguid, &JoystickAvt, dinput, pdev);
569 } else {
570 WARN("no interface\n");
571 *pdev = 0;
572 return DIERR_NOINTERFACE;
576 WARN("invalid device GUID\n");
577 *pdev = 0;
578 return DIERR_DEVICENOTREG;
581 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
583 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
584 (IsJoystickGUID(rguid))) {
585 if ((riid == NULL) ||
586 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
587 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
588 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
589 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
590 return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA *)pdev);
591 } else {
592 WARN("no interface\n");
593 *pdev = 0;
594 return DIERR_NOINTERFACE;
598 WARN("invalid device GUID\n");
599 *pdev = 0;
600 return DIERR_DEVICENOTREG;
603 const struct dinput_device joystick_linux_device = {
604 "Wine Linux joystick driver",
605 joydev_enum_deviceA,
606 joydev_enum_deviceW,
607 joydev_create_deviceA,
608 joydev_create_deviceW
611 /******************************************************************************
612 * Joystick
614 static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
616 JoystickImpl *This = (JoystickImpl *)iface;
617 ULONG ref;
619 ref = InterlockedDecrement(&This->base.ref);
620 if (ref)
621 return ref;
623 /* Free the device name */
624 HeapFree(GetProcessHeap(),0,This->name);
626 /* Free the axis map */
627 HeapFree(GetProcessHeap(),0,This->axis_map);
629 /* Free the data queue */
630 HeapFree(GetProcessHeap(), 0, This->base.data_queue);
632 /* Free the properties */
633 HeapFree(GetProcessHeap(), 0, This->props);
635 /* release the data transform filter */
636 HeapFree(GetProcessHeap(), 0, This->base.data_format.wine_df->rgodf);
637 HeapFree(GetProcessHeap(), 0, This->base.data_format.wine_df);
638 release_DataFormat(&This->base.data_format);
640 This->base.crit.DebugInfo->Spare[0] = 0;
641 IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
642 DeleteCriticalSection(&This->base.crit);
644 HeapFree(GetProcessHeap(),0,This);
645 return 0;
648 /******************************************************************************
649 * SetDataFormat : the application can choose the format of the data
650 * the device driver sends back with GetDeviceState.
652 static HRESULT WINAPI JoystickAImpl_SetDataFormat(
653 LPDIRECTINPUTDEVICE8A iface,
654 LPCDIDATAFORMAT df)
656 JoystickImpl *This = (JoystickImpl *)iface;
657 unsigned int i;
658 HRESULT hr;
660 TRACE("(%p,%p)\n",This,df);
662 hr = IDirectInputDevice2AImpl_SetDataFormat(iface, df);
663 if (FAILED(hr)) return hr;
665 for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++)
667 This->props[i].lMin = 0;
668 This->props[i].lMax = 0xffff;
669 This->props[i].lDeadZone = 1000;
670 This->props[i].lSaturation = 0;
673 return DI_OK;
676 /******************************************************************************
677 * Acquire : gets exclusive control of the joystick
679 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
681 JoystickImpl *This = (JoystickImpl *)iface;
683 TRACE("(%p)\n",This);
685 if (This->base.acquired) {
686 WARN("already acquired\n");
687 return S_FALSE;
690 /* open the joystick device */
691 if (This->joyfd==-1) {
692 TRACE("opening joystick device %s\n", This->dev);
694 This->joyfd=open(This->dev,O_RDONLY);
695 if (This->joyfd==-1) {
696 ERR("open(%s) failed: %s\n", This->dev, strerror(errno));
697 return DIERR_NOTFOUND;
701 This->base.acquired = 1;
703 return DI_OK;
706 /******************************************************************************
707 * Unacquire : frees the joystick
709 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
711 JoystickImpl *This = (JoystickImpl *)iface;
712 HRESULT res;
714 TRACE("(%p)\n",This);
716 if ((res = IDirectInputDevice2AImpl_Unacquire(iface)) != DI_OK) return res;
718 if (This->joyfd!=-1) {
719 TRACE("closing joystick device\n");
720 close(This->joyfd);
721 This->joyfd = -1;
722 return DI_OK;
725 return DI_NOEFFECT;
728 static LONG map_axis(JoystickImpl * This, short val, short index)
730 double fval = val;
731 double fmin = This->props[index].lMin;
732 double fmax = This->props[index].lMax;
733 double fret;
735 fret = (((fval + 32767.0) * (fmax - fmin)) / (32767.0*2.0)) + fmin;
737 if (fret >= 0.0)
738 fret += 0.5;
739 else
740 fret -= 0.5;
742 return fret;
745 static LONG calculate_pov(JoystickImpl *This, int index)
747 if (This->povs[index].lX < -16384) {
748 if (This->povs[index].lY < -16384)
749 This->js.rgdwPOV[index] = 31500;
750 else if (This->povs[index].lY > 16384)
751 This->js.rgdwPOV[index] = 22500;
752 else
753 This->js.rgdwPOV[index] = 27000;
754 } else if (This->povs[index].lX > 16384) {
755 if (This->povs[index].lY < -16384)
756 This->js.rgdwPOV[index] = 4500;
757 else if (This->povs[index].lY > 16384)
758 This->js.rgdwPOV[index] = 13500;
759 else
760 This->js.rgdwPOV[index] = 9000;
761 } else {
762 if (This->povs[index].lY < -16384)
763 This->js.rgdwPOV[index] = 0;
764 else if (This->povs[index].lY > 16384)
765 This->js.rgdwPOV[index] = 18000;
766 else
767 This->js.rgdwPOV[index] = -1;
770 return This->js.rgdwPOV[index];
773 static void joy_polldev(JoystickImpl *This) {
774 struct pollfd plfd;
775 struct js_event jse;
776 TRACE("(%p)\n", This);
778 if (This->joyfd==-1) {
779 WARN("no device\n");
780 return;
782 while (1)
784 LONG value;
785 int inst_id = -1;
787 plfd.fd = This->joyfd;
788 plfd.events = POLLIN;
789 if (poll(&plfd,1,0) != 1)
790 return;
791 /* we have one event, so we can read */
792 if (sizeof(jse)!=read(This->joyfd,&jse,sizeof(jse))) {
793 return;
795 TRACE("js_event: type 0x%x, number %d, value %d\n",
796 jse.type,jse.number,jse.value);
797 if (jse.type & JS_EVENT_BUTTON)
799 inst_id = DIDFT_MAKEINSTANCE(jse.number) | DIDFT_PSHBUTTON;
800 This->js.rgbButtons[jse.number] = value = jse.value ? 0x80 : 0x00;
802 else if (jse.type & JS_EVENT_AXIS)
804 int number = This->axis_map[jse.number]; /* wine format object index */
806 if (number < 12)
808 inst_id = DIDFT_MAKEINSTANCE(jse.number) | (number < 8 ? DIDFT_AXIS : DIDFT_POV);
809 value = map_axis(This, jse.value, number);
810 /* FIXME do deadzone and saturation here */
812 TRACE("changing axis %d => %d\n", jse.number, number);
813 switch (number) {
814 case 0:
815 This->js.lX = value;
816 break;
817 case 1:
818 This->js.lY = value;
819 break;
820 case 2:
821 This->js.lZ = value;
822 break;
823 case 3:
824 This->js.lRx = value;
825 break;
826 case 4:
827 This->js.lRy = value;
828 break;
829 case 5:
830 This->js.lRz = value;
831 break;
832 case 6:
833 This->js.rglSlider[0] = value;
834 break;
835 case 7:
836 This->js.rglSlider[1] = value;
837 break;
838 case 8:
839 /* FIXME don't go off array */
840 if (This->axis_map[jse.number + 1] == number)
841 This->povs[0].lX = jse.value;
842 else if (This->axis_map[jse.number - 1] == number)
843 This->povs[0].lY = jse.value;
844 value = calculate_pov(This, 0);
845 break;
846 case 9:
847 if (This->axis_map[jse.number + 1] == number)
848 This->povs[1].lX = jse.value;
849 else if (This->axis_map[jse.number - 1] == number)
850 This->povs[1].lY = jse.value;
851 value = calculate_pov(This, 1);
852 break;
853 case 10:
854 if (This->axis_map[jse.number + 1] == number)
855 This->povs[2].lX = jse.value;
856 else if (This->axis_map[jse.number - 1] == number)
857 This->povs[2].lY = jse.value;
858 value = calculate_pov(This, 2);
859 break;
860 case 11:
861 if (This->axis_map[jse.number + 1] == number)
862 This->povs[3].lX = jse.value;
863 else if (This->axis_map[jse.number - 1] == number)
864 This->povs[3].lY = jse.value;
865 value = calculate_pov(This, 3);
866 break;
868 } else
869 WARN("axis %d not supported\n", number);
871 if (inst_id >= 0)
872 queue_event((LPDIRECTINPUTDEVICE8A)This,
873 id_to_offset(&This->base.data_format, inst_id),
874 value, jse.time, This->dinput->evsequence++);
878 /******************************************************************************
879 * GetDeviceState : returns the "state" of the joystick.
882 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
883 LPDIRECTINPUTDEVICE8A iface,
884 DWORD len,
885 LPVOID ptr)
887 JoystickImpl *This = (JoystickImpl *)iface;
889 TRACE("(%p,0x%08x,%p)\n", This, len, ptr);
891 if (!This->base.acquired) {
892 WARN("not acquired\n");
893 return DIERR_NOTACQUIRED;
896 /* update joystick state */
897 joy_polldev(This);
899 /* convert and copy data to user supplied buffer */
900 fill_DataFormat(ptr, &This->js, &This->base.data_format);
902 return DI_OK;
905 /******************************************************************************
906 * SetProperty : change input device properties
908 static HRESULT WINAPI JoystickAImpl_SetProperty(
909 LPDIRECTINPUTDEVICE8A iface,
910 REFGUID rguid,
911 LPCDIPROPHEADER ph)
913 JoystickImpl *This = (JoystickImpl *)iface;
914 int i;
916 TRACE("(%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
918 if (ph == NULL) {
919 WARN("invalid parameter: ph == NULL\n");
920 return DIERR_INVALIDPARAM;
923 if (TRACE_ON(dinput))
924 _dump_DIPROPHEADER(ph);
926 if (!HIWORD(rguid)) {
927 switch (LOWORD(rguid)) {
928 case (DWORD)DIPROP_RANGE: {
929 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
930 if (ph->dwHow == DIPH_DEVICE) {
931 TRACE("proprange(%d,%d) all\n", pr->lMin, pr->lMax);
932 for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++) {
933 This->props[i].lMin = pr->lMin;
934 This->props[i].lMax = pr->lMax;
936 } else {
937 int obj = find_property(&This->base.data_format, ph);
939 TRACE("proprange(%d,%d) obj=%d\n", pr->lMin, pr->lMax, obj);
940 if (obj >= 0) {
941 This->props[obj].lMin = pr->lMin;
942 This->props[obj].lMax = pr->lMax;
943 return DI_OK;
946 break;
948 case (DWORD)DIPROP_DEADZONE: {
949 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
950 if (ph->dwHow == DIPH_DEVICE) {
951 TRACE("deadzone(%d) all\n", pd->dwData);
952 for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++)
953 This->props[i].lDeadZone = pd->dwData;
954 } else {
955 int obj = find_property(&This->base.data_format, ph);
957 TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
958 if (obj >= 0) {
959 This->props[obj].lDeadZone = pd->dwData;
960 return DI_OK;
963 break;
965 case (DWORD)DIPROP_SATURATION: {
966 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
967 if (ph->dwHow == DIPH_DEVICE) {
968 TRACE("saturation(%d) all\n", pd->dwData);
969 for (i = 0; i < This->base.data_format.wine_df->dwNumObjs; i++)
970 This->props[i].lSaturation = pd->dwData;
971 } else {
972 int obj = find_property(&This->base.data_format, ph);
974 TRACE("saturation(%d) obj=%d\n", pd->dwData, obj);
975 if (obj >= 0) {
976 This->props[obj].lSaturation = pd->dwData;
977 return DI_OK;
980 break;
982 default:
983 return IDirectInputDevice2AImpl_SetProperty(iface, rguid, ph);
987 return DI_OK;
990 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
991 LPDIRECTINPUTDEVICE8A iface,
992 LPDIDEVCAPS lpDIDevCaps)
994 JoystickImpl *This = (JoystickImpl *)iface;
995 int size;
997 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
999 if (lpDIDevCaps == NULL) {
1000 WARN("invalid pointer\n");
1001 return E_POINTER;
1004 size = lpDIDevCaps->dwSize;
1006 if (!(size == sizeof(DIDEVCAPS) || size == sizeof(DIDEVCAPS_DX3))) {
1007 WARN("invalid parameter\n");
1008 return DIERR_INVALIDPARAM;
1011 CopyMemory(lpDIDevCaps, &This->devcaps, size);
1012 lpDIDevCaps->dwSize = size;
1014 if (TRACE_ON(dinput))
1015 _dump_DIDEVCAPS(lpDIDevCaps);
1017 return DI_OK;
1020 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface)
1022 JoystickImpl *This = (JoystickImpl *)iface;
1024 TRACE("(%p)\n",This);
1026 if (!This->base.acquired) {
1027 WARN("not acquired\n");
1028 return DIERR_NOTACQUIRED;
1031 joy_polldev(This);
1032 return DI_OK;
1035 /******************************************************************************
1036 * GetProperty : get input device properties
1038 static HRESULT WINAPI JoystickAImpl_GetProperty(
1039 LPDIRECTINPUTDEVICE8A iface,
1040 REFGUID rguid,
1041 LPDIPROPHEADER pdiph)
1043 JoystickImpl *This = (JoystickImpl *)iface;
1045 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(rguid), pdiph);
1047 if (TRACE_ON(dinput))
1048 _dump_DIPROPHEADER(pdiph);
1050 if (!HIWORD(rguid)) {
1051 switch (LOWORD(rguid)) {
1052 case (DWORD) DIPROP_RANGE: {
1053 LPDIPROPRANGE pr = (LPDIPROPRANGE)pdiph;
1054 int obj = find_property(&This->base.data_format, pdiph);
1056 /* The app is querying the current range of the axis
1057 * return the lMin and lMax values */
1058 if (obj >= 0) {
1059 pr->lMin = This->props[obj].lMin;
1060 pr->lMax = This->props[obj].lMax;
1061 TRACE("range(%d, %d) obj=%d\n", pr->lMin, pr->lMax, obj);
1062 return DI_OK;
1064 break;
1066 case (DWORD) DIPROP_DEADZONE: {
1067 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1068 int obj = find_property(&This->base.data_format, pdiph);
1070 if (obj >= 0) {
1071 pd->dwData = This->props[obj].lDeadZone;
1072 TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
1073 return DI_OK;
1075 break;
1077 case (DWORD) DIPROP_SATURATION: {
1078 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1079 int obj = find_property(&This->base.data_format, pdiph);
1081 if (obj >= 0) {
1082 pd->dwData = This->props[obj].lSaturation;
1083 TRACE("saturation(%d) obj=%d\n", pd->dwData, obj);
1084 return DI_OK;
1086 break;
1088 default:
1089 return IDirectInputDevice2AImpl_GetProperty(iface, rguid, pdiph);
1093 return DI_OK;
1096 /******************************************************************************
1097 * GetObjectInfo : get object info
1099 static HRESULT WINAPI JoystickWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
1100 LPDIDEVICEOBJECTINSTANCEW pdidoi, DWORD dwObj, DWORD dwHow)
1102 static const WCHAR axisW[] = {'A','x','i','s',' ','%','d',0};
1103 static const WCHAR povW[] = {'P','O','V',' ','%','d',0};
1104 static const WCHAR buttonW[] = {'B','u','t','t','o','n',' ','%','d',0};
1105 HRESULT res;
1107 res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
1108 if (res != DI_OK) return res;
1110 if (pdidoi->dwType & DIDFT_AXIS)
1111 sprintfW(pdidoi->tszName, axisW, DIDFT_GETINSTANCE(pdidoi->dwType));
1112 else if (pdidoi->dwType & DIDFT_POV)
1113 sprintfW(pdidoi->tszName, povW, DIDFT_GETINSTANCE(pdidoi->dwType));
1114 else if (pdidoi->dwType & DIDFT_BUTTON)
1115 sprintfW(pdidoi->tszName, buttonW, DIDFT_GETINSTANCE(pdidoi->dwType));
1117 _dump_OBJECTINSTANCEW(pdidoi);
1118 return res;
1121 static HRESULT WINAPI JoystickAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface,
1122 LPDIDEVICEOBJECTINSTANCEA pdidoi, DWORD dwObj, DWORD dwHow)
1124 HRESULT res;
1125 DIDEVICEOBJECTINSTANCEW didoiW;
1126 DWORD dwSize = pdidoi->dwSize;
1128 didoiW.dwSize = sizeof(didoiW);
1129 res = JoystickWImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W)iface, &didoiW, dwObj, dwHow);
1130 if (res != DI_OK) return res;
1132 memset(pdidoi, 0, pdidoi->dwSize);
1133 memcpy(pdidoi, &didoiW, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, tszName));
1134 pdidoi->dwSize = dwSize;
1135 WideCharToMultiByte(CP_ACP, 0, didoiW.tszName, -1, pdidoi->tszName,
1136 sizeof(pdidoi->tszName), NULL, NULL);
1138 return res;
1141 /******************************************************************************
1142 * GetDeviceInfo : get information about a device's identity
1144 static HRESULT WINAPI JoystickAImpl_GetDeviceInfo(
1145 LPDIRECTINPUTDEVICE8A iface,
1146 LPDIDEVICEINSTANCEA pdidi)
1148 JoystickImpl *This = (JoystickImpl *)iface;
1150 TRACE("(%p,%p)\n", iface, pdidi);
1152 if (pdidi == NULL) {
1153 WARN("invalid pointer\n");
1154 return E_POINTER;
1157 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
1158 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA))) {
1159 WARN("invalid parameter: pdidi->dwSize = %d != %d or %d\n",
1160 pdidi->dwSize, sizeof(DIDEVICEINSTANCE_DX3A),
1161 sizeof(DIDEVICEINSTANCEA));
1162 return DIERR_INVALIDPARAM;
1165 /* Return joystick */
1166 pdidi->guidInstance = GUID_Joystick;
1167 pdidi->guidProduct = DInput_Wine_Joystick_GUID;
1168 /* we only support traditional joysticks for now */
1169 pdidi->dwDevType = This->devcaps.dwDevType;
1170 strcpy(pdidi->tszInstanceName, "Joystick");
1171 strcpy(pdidi->tszProductName, This->name);
1172 if (pdidi->dwSize > sizeof(DIDEVICEINSTANCE_DX3A)) {
1173 pdidi->guidFFDriver = GUID_NULL;
1174 pdidi->wUsagePage = 0;
1175 pdidi->wUsage = 0;
1178 return DI_OK;
1181 /******************************************************************************
1182 * GetDeviceInfo : get information about a device's identity
1184 static HRESULT WINAPI JoystickWImpl_GetDeviceInfo(
1185 LPDIRECTINPUTDEVICE8W iface,
1186 LPDIDEVICEINSTANCEW pdidi)
1188 JoystickImpl *This = (JoystickImpl *)iface;
1190 TRACE("(%p,%p)\n", iface, pdidi);
1192 if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3W)) &&
1193 (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW))) {
1194 WARN("invalid parameter: pdidi->dwSize = %d != %d or %d\n",
1195 pdidi->dwSize, sizeof(DIDEVICEINSTANCE_DX3W),
1196 sizeof(DIDEVICEINSTANCEW));
1197 return DIERR_INVALIDPARAM;
1200 /* Return joystick */
1201 pdidi->guidInstance = GUID_Joystick;
1202 pdidi->guidProduct = DInput_Wine_Joystick_GUID;
1203 /* we only support traditional joysticks for now */
1204 pdidi->dwDevType = This->devcaps.dwDevType;
1205 MultiByteToWideChar(CP_ACP, 0, "Joystick", -1, pdidi->tszInstanceName, MAX_PATH);
1206 MultiByteToWideChar(CP_ACP, 0, This->name, -1, pdidi->tszProductName, MAX_PATH);
1207 if (pdidi->dwSize > sizeof(DIDEVICEINSTANCE_DX3W)) {
1208 pdidi->guidFFDriver = GUID_NULL;
1209 pdidi->wUsagePage = 0;
1210 pdidi->wUsage = 0;
1213 return DI_OK;
1216 static const IDirectInputDevice8AVtbl JoystickAvt =
1218 IDirectInputDevice2AImpl_QueryInterface,
1219 IDirectInputDevice2AImpl_AddRef,
1220 JoystickAImpl_Release,
1221 JoystickAImpl_GetCapabilities,
1222 IDirectInputDevice2AImpl_EnumObjects,
1223 JoystickAImpl_GetProperty,
1224 JoystickAImpl_SetProperty,
1225 JoystickAImpl_Acquire,
1226 JoystickAImpl_Unacquire,
1227 JoystickAImpl_GetDeviceState,
1228 IDirectInputDevice2AImpl_GetDeviceData,
1229 JoystickAImpl_SetDataFormat,
1230 IDirectInputDevice2AImpl_SetEventNotification,
1231 IDirectInputDevice2AImpl_SetCooperativeLevel,
1232 JoystickAImpl_GetObjectInfo,
1233 JoystickAImpl_GetDeviceInfo,
1234 IDirectInputDevice2AImpl_RunControlPanel,
1235 IDirectInputDevice2AImpl_Initialize,
1236 IDirectInputDevice2AImpl_CreateEffect,
1237 IDirectInputDevice2AImpl_EnumEffects,
1238 IDirectInputDevice2AImpl_GetEffectInfo,
1239 IDirectInputDevice2AImpl_GetForceFeedbackState,
1240 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1241 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1242 IDirectInputDevice2AImpl_Escape,
1243 JoystickAImpl_Poll,
1244 IDirectInputDevice2AImpl_SendDeviceData,
1245 IDirectInputDevice7AImpl_EnumEffectsInFile,
1246 IDirectInputDevice7AImpl_WriteEffectToFile,
1247 IDirectInputDevice8AImpl_BuildActionMap,
1248 IDirectInputDevice8AImpl_SetActionMap,
1249 IDirectInputDevice8AImpl_GetImageInfo
1252 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1253 # define XCAST(fun) (typeof(SysJoystickWvt.fun))
1254 #else
1255 # define XCAST(fun) (void*)
1256 #endif
1258 static const IDirectInputDevice8WVtbl SysJoystickWvt =
1260 IDirectInputDevice2WImpl_QueryInterface,
1261 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1262 XCAST(Release)JoystickAImpl_Release,
1263 XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1264 IDirectInputDevice2WImpl_EnumObjects,
1265 XCAST(GetProperty)JoystickAImpl_GetProperty,
1266 XCAST(SetProperty)JoystickAImpl_SetProperty,
1267 XCAST(Acquire)JoystickAImpl_Acquire,
1268 XCAST(Unacquire)JoystickAImpl_Unacquire,
1269 XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1270 XCAST(GetDeviceData)IDirectInputDevice2AImpl_GetDeviceData,
1271 XCAST(SetDataFormat)JoystickAImpl_SetDataFormat,
1272 XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
1273 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1274 IDirectInputDevice2WImpl_GetObjectInfo,
1275 JoystickWImpl_GetDeviceInfo,
1276 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1277 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1278 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
1279 IDirectInputDevice2WImpl_EnumEffects,
1280 IDirectInputDevice2WImpl_GetEffectInfo,
1281 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
1282 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1283 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1284 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1285 XCAST(Poll)JoystickAImpl_Poll,
1286 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1287 IDirectInputDevice7WImpl_EnumEffectsInFile,
1288 IDirectInputDevice7WImpl_WriteEffectToFile,
1289 IDirectInputDevice8WImpl_BuildActionMap,
1290 IDirectInputDevice8WImpl_SetActionMap,
1291 IDirectInputDevice8WImpl_GetImageInfo
1293 #undef XCAST
1295 #else /* HAVE_LINUX_22_JOYSTICK_API */
1297 const struct dinput_device joystick_linux_device = {
1298 "Wine Linux joystick driver",
1299 NULL,
1300 NULL,
1301 NULL,
1302 NULL
1305 #endif /* HAVE_LINUX_22_JOYSTICK_API */