dinput: Explicitly define ASCII and Unicode methods in joydev joystick.
[wine/multimedia.git] / dlls / dinput / joystick_linux.c
bloba858ecd20f79a40354156f7c4677f034df7e6b02
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 #ifdef HAVE_UNISTD_H
36 # include <unistd.h>
37 #endif
38 #ifdef HAVE_SYS_TIME_H
39 # include <sys/time.h>
40 #endif
41 #include <fcntl.h>
42 #ifdef HAVE_SYS_IOCTL_H
43 # include <sys/ioctl.h>
44 #endif
45 #include <errno.h>
46 #ifdef HAVE_SYS_ERRNO_H
47 # include <sys/errno.h>
48 #endif
49 #ifdef HAVE_LINUX_IOCTL_H
50 # include <linux/ioctl.h>
51 #endif
52 #ifdef HAVE_LINUX_JOYSTICK_H
53 # include <linux/joystick.h>
54 # undef SW_MAX
55 #endif
56 #ifdef HAVE_SYS_POLL_H
57 # include <sys/poll.h>
58 #endif
60 #include "wine/debug.h"
61 #include "wine/unicode.h"
62 #include "windef.h"
63 #include "winbase.h"
64 #include "winerror.h"
65 #include "dinput.h"
67 #include "dinput_private.h"
68 #include "device_private.h"
69 #include "joystick_private.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
73 #ifdef HAVE_LINUX_22_JOYSTICK_API
75 #define JOYDEV_NEW "/dev/input/js"
76 #define JOYDEV_OLD "/dev/js"
78 struct JoyDev
80 char device[MAX_PATH];
81 char name[MAX_PATH];
83 BYTE axis_count;
84 BYTE button_count;
85 int *dev_axes_map;
88 typedef struct JoystickImpl JoystickImpl;
89 static const IDirectInputDevice8AVtbl JoystickAvt;
90 static const IDirectInputDevice8WVtbl JoystickWvt;
91 struct JoystickImpl
93 struct JoystickGenericImpl generic;
95 struct JoyDev *joydev;
97 /* joystick private */
98 int joyfd;
99 POINTL povs[4];
102 static inline JoystickImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface)
104 return (JoystickImpl *) iface;
106 static inline JoystickImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface)
108 return (JoystickImpl *) iface;
110 static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl(JoystickImpl *This)
112 return (IDirectInputDevice8A *)This;
114 static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(JoystickImpl *This)
116 return (IDirectInputDevice8W *)This;
119 static const GUID DInput_Wine_Joystick_GUID = { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
120 0x9e573ed9,
121 0x7734,
122 0x11d2,
123 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
126 #define MAX_JOYSTICKS 64
127 static INT joystick_devices_count = -1;
128 static struct JoyDev *joystick_devices;
130 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface);
132 static INT find_joystick_devices(void)
134 INT i;
136 if (joystick_devices_count != -1) return joystick_devices_count;
138 joystick_devices_count = 0;
139 for (i = 0; i < MAX_JOYSTICKS; i++)
141 int fd;
142 struct JoyDev joydev, *new_joydevs;
143 BYTE axes_map[ABS_MAX + 1];
145 snprintf(joydev.device, sizeof(joydev.device), "%s%d", JOYDEV_NEW, i);
146 if ((fd = open(joydev.device, O_RDONLY)) < 0)
148 snprintf(joydev.device, sizeof(joydev.device), "%s%d", JOYDEV_OLD, i);
149 if ((fd = open(joydev.device, O_RDONLY)) < 0) continue;
152 strcpy(joydev.name, "Wine Joystick");
153 #if defined(JSIOCGNAME)
154 if (ioctl(fd, JSIOCGNAME(sizeof(joydev.name)), joydev.name) < 0)
155 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", joydev.device, strerror(errno));
156 #endif
157 #ifdef JSIOCGAXES
158 if (ioctl(fd, JSIOCGAXES, &joydev.axis_count) < 0)
160 WARN("ioctl(%s,JSIOCGAXES) failed: %s, defauting to 2\n", joydev.device, strerror(errno));
161 joydev.axis_count = 2;
163 #endif
164 #ifdef JSIOCGBUTTONS
165 if (ioctl(fd, JSIOCGBUTTONS, &joydev.button_count) < 0)
167 WARN("ioctl(%s,JSIOCGBUTTONS) failed: %s, defauting to 2\n", joydev.device, strerror(errno));
168 joydev.button_count = 2;
170 #endif
172 if (ioctl(fd, JSIOCGAXMAP, axes_map) < 0)
174 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", joydev.device, strerror(errno));
175 joydev.dev_axes_map = NULL;
177 else
178 if ((joydev.dev_axes_map = HeapAlloc(GetProcessHeap(), 0, joydev.axis_count * sizeof(int))))
180 INT j;
182 /* Remap to DI numbers */
183 for (j = 0; j < joydev.axis_count; j++)
184 if (axes_map[j] < 8)
185 /* Axis match 1-to-1 */
186 joydev.dev_axes_map[j] = j;
187 else if (axes_map[j] == 16 ||
188 axes_map[j] == 17)
189 /* POV axis */
190 joydev.dev_axes_map[j] = 8;
191 else
192 joydev.dev_axes_map[j] = -1;
195 close(fd);
197 if (!joystick_devices_count)
198 new_joydevs = HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev));
199 else
200 new_joydevs = HeapReAlloc(GetProcessHeap(), 0, joystick_devices,
201 (joystick_devices_count + 1) * sizeof(struct JoyDev));
202 if (!new_joydevs) continue;
204 TRACE("Found a joystick on %s: %s\n with %d axes and %d buttons\n", joydev.device,
205 joydev.name, joydev.axis_count, joydev.button_count);
207 joystick_devices = new_joydevs;
208 joystick_devices[joystick_devices_count++] = joydev;
211 return joystick_devices_count;
214 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
216 int fd = -1;
218 if (id >= find_joystick_devices()) return FALSE;
220 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
221 WARN("force feedback not supported\n");
222 return FALSE;
225 if ((dwDevType == 0) ||
226 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
227 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
228 /* check whether we have a joystick */
229 if ((fd = open(joystick_devices[id].device, O_RDONLY)) < 0)
231 WARN("open(%s, O_RDONLY) failed: %s\n", joystick_devices[id].name, strerror(errno));
232 return FALSE;
235 /* Return joystick */
236 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
237 lpddi->guidInstance.Data3 = id;
238 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
239 /* we only support traditional joysticks for now */
240 if (version >= 0x0800)
241 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
242 else
243 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
245 strcpy(lpddi->tszInstanceName, joystick_devices[id].name);
246 strcpy(lpddi->tszProductName, joystick_devices[id].name);
248 lpddi->guidFFDriver = GUID_NULL;
249 close(fd);
250 TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id].device, lpddi->tszProductName);
251 return TRUE;
254 return FALSE;
257 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
259 int fd = -1;
261 if (id >= find_joystick_devices()) return FALSE;
263 if (dwFlags & DIEDFL_FORCEFEEDBACK) {
264 WARN("force feedback not supported\n");
265 return FALSE;
268 if ((dwDevType == 0) ||
269 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
270 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
271 /* check whether we have a joystick */
272 if ((fd = open(joystick_devices[id].device, O_RDONLY)) < 0)
274 WARN("open(%s,O_RDONLY) failed: %s\n", joystick_devices[id].device, strerror(errno));
275 return FALSE;
278 /* Return joystick */
279 lpddi->guidInstance = DInput_Wine_Joystick_GUID;
280 lpddi->guidInstance.Data3 = id;
281 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
282 /* we only support traditional joysticks for now */
283 if (version >= 0x0800)
284 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
285 else
286 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
288 MultiByteToWideChar(CP_ACP, 0, joystick_devices[id].name, -1, lpddi->tszInstanceName, MAX_PATH);
289 MultiByteToWideChar(CP_ACP, 0, joystick_devices[id].name, -1, lpddi->tszProductName, MAX_PATH);
290 lpddi->guidFFDriver = GUID_NULL;
291 close(fd);
292 TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id].device, joystick_devices[id].name);
293 return TRUE;
296 return FALSE;
299 static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput,
300 LPDIRECTINPUTDEVICEA* pdev, unsigned short index)
302 DWORD i;
303 JoystickImpl* newDevice;
304 HRESULT hr;
305 LPDIDATAFORMAT df = NULL;
306 int idx = 0;
308 TRACE("%s %p %p %p %hu\n", debugstr_guid(rguid), jvt, dinput, pdev, index);
310 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
311 if (newDevice == 0) {
312 WARN("out of memory\n");
313 *pdev = 0;
314 return DIERR_OUTOFMEMORY;
317 newDevice->joydev = &joystick_devices[index];
318 newDevice->joyfd = -1;
319 newDevice->generic.guidInstance = DInput_Wine_Joystick_GUID;
320 newDevice->generic.guidInstance.Data3 = index;
321 newDevice->generic.guidProduct = DInput_Wine_Joystick_GUID;
322 newDevice->generic.joy_polldev = joy_polldev;
323 newDevice->generic.name = newDevice->joydev->name;
324 newDevice->generic.device_axis_count = newDevice->joydev->axis_count;
325 newDevice->generic.devcaps.dwButtons = newDevice->joydev->button_count;
327 if (newDevice->generic.devcaps.dwButtons > 128)
329 WARN("Can't support %d buttons. Clamping down to 128\n", newDevice->generic.devcaps.dwButtons);
330 newDevice->generic.devcaps.dwButtons = 128;
333 newDevice->generic.base.lpVtbl = jvt;
334 newDevice->generic.base.ref = 1;
335 newDevice->generic.base.dinput = dinput;
336 newDevice->generic.base.guid = *rguid;
337 InitializeCriticalSection(&newDevice->generic.base.crit);
338 newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit");
340 /* setup_dinput_options may change these */
341 newDevice->generic.deadzone = 0;
343 /* do any user specified configuration */
344 hr = setup_dinput_options(&newDevice->generic, newDevice->joydev->dev_axes_map);
345 if (hr != DI_OK)
346 goto FAILED1;
348 /* Create copy of default data format */
349 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto FAILED;
350 memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
352 df->dwNumObjs = newDevice->generic.devcaps.dwAxes + newDevice->generic.devcaps.dwPOVs + newDevice->generic.devcaps.dwButtons;
353 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto FAILED;
355 for (i = 0; i < newDevice->generic.device_axis_count; i++)
357 int wine_obj = newDevice->generic.axis_map[i];
359 if (wine_obj < 0) continue;
361 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize);
362 if (wine_obj < 8)
363 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS;
364 else
366 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj - 8) | DIDFT_POV;
367 i++; /* POV takes 2 axes */
370 for (i = 0; i < newDevice->generic.devcaps.dwButtons; i++)
372 memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + 12], df->dwObjSize);
373 df->rgodf[idx ].pguid = &GUID_Button;
374 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
376 newDevice->generic.base.data_format.wine_df = df;
378 /* initialize default properties */
379 for (i = 0; i < c_dfDIJoystick2.dwNumObjs; i++) {
380 newDevice->generic.props[i].lDevMin = -32767;
381 newDevice->generic.props[i].lDevMax = +32767;
382 newDevice->generic.props[i].lMin = 0;
383 newDevice->generic.props[i].lMax = 0xffff;
384 newDevice->generic.props[i].lDeadZone = newDevice->generic.deadzone; /* % * 1000 */
385 newDevice->generic.props[i].lSaturation = 0;
388 IDirectInput_AddRef(&newDevice->generic.base.dinput->IDirectInput7A_iface);
390 newDevice->generic.devcaps.dwSize = sizeof(newDevice->generic.devcaps);
391 newDevice->generic.devcaps.dwFlags = DIDC_ATTACHED;
392 if (newDevice->generic.base.dinput->dwVersion >= 0x0800)
393 newDevice->generic.devcaps.dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
394 else
395 newDevice->generic.devcaps.dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
396 newDevice->generic.devcaps.dwFFSamplePeriod = 0;
397 newDevice->generic.devcaps.dwFFMinTimeResolution = 0;
398 newDevice->generic.devcaps.dwFirmwareRevision = 0;
399 newDevice->generic.devcaps.dwHardwareRevision = 0;
400 newDevice->generic.devcaps.dwFFDriverVersion = 0;
402 if (TRACE_ON(dinput)) {
403 _dump_DIDATAFORMAT(newDevice->generic.base.data_format.wine_df);
404 for (i = 0; i < (newDevice->generic.device_axis_count); i++)
405 TRACE("axis_map[%d] = %d\n", i, newDevice->generic.axis_map[i]);
406 _dump_DIDEVCAPS(&newDevice->generic.devcaps);
409 *pdev = (LPDIRECTINPUTDEVICEA)newDevice;
411 return DI_OK;
413 FAILED:
414 hr = DIERR_OUTOFMEMORY;
415 FAILED1:
416 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
417 HeapFree(GetProcessHeap(), 0, df);
418 release_DataFormat(&newDevice->generic.base.data_format);
419 HeapFree(GetProcessHeap(),0,newDevice->generic.axis_map);
420 HeapFree(GetProcessHeap(),0,newDevice);
421 *pdev = 0;
423 return hr;
426 /******************************************************************************
427 * get_joystick_index : Get the joystick index from a given GUID
429 static unsigned short get_joystick_index(REFGUID guid)
431 GUID wine_joystick = DInput_Wine_Joystick_GUID;
432 GUID dev_guid = *guid;
434 wine_joystick.Data3 = 0;
435 dev_guid.Data3 = 0;
437 /* for the standard joystick GUID use index 0 */
438 if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
440 /* for the wine joystick GUIDs use the index stored in Data3 */
441 if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3;
443 return MAX_JOYSTICKS;
446 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
448 unsigned short index;
450 TRACE("%p %s %p %p\n",dinput, debugstr_guid(rguid), riid, pdev);
451 find_joystick_devices();
452 *pdev = NULL;
454 if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS &&
455 joystick_devices_count && index < joystick_devices_count)
457 if ((riid == NULL) ||
458 IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
459 IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
460 IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
461 IsEqualGUID(&IID_IDirectInputDevice8A, riid))
463 return alloc_device(rguid, &JoystickAvt, dinput, pdev, index);
466 WARN("no interface\n");
467 return DIERR_NOINTERFACE;
470 return DIERR_DEVICENOTREG;
473 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
475 unsigned short index;
477 TRACE("%p %s %p %p\n",dinput, debugstr_guid(rguid), riid, pdev);
478 find_joystick_devices();
479 *pdev = NULL;
481 if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS &&
482 joystick_devices_count && index < joystick_devices_count)
484 if ((riid == NULL) ||
485 IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
486 IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
487 IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
488 IsEqualGUID(&IID_IDirectInputDevice8W, riid))
490 return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA *)pdev, index);
492 WARN("no interface\n");
493 return DIERR_NOINTERFACE;
496 WARN("invalid device GUID %s\n",debugstr_guid(rguid));
497 return DIERR_DEVICENOTREG;
500 #undef MAX_JOYSTICKS
502 const struct dinput_device joystick_linux_device = {
503 "Wine Linux joystick driver",
504 joydev_enum_deviceA,
505 joydev_enum_deviceW,
506 joydev_create_deviceA,
507 joydev_create_deviceW
510 /******************************************************************************
511 * Acquire : gets exclusive control of the joystick
513 static HRESULT WINAPI JoystickLinuxWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
515 JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
516 HRESULT res;
518 TRACE("(%p)\n",This);
520 res = IDirectInputDevice2WImpl_Acquire(iface);
521 if (res != DI_OK)
522 return res;
524 /* open the joystick device */
525 if (This->joyfd==-1) {
526 TRACE("opening joystick device %s\n", This->joydev->device);
528 This->joyfd = open(This->joydev->device, O_RDONLY);
529 if (This->joyfd==-1) {
530 ERR("open(%s) failed: %s\n", This->joydev->device, strerror(errno));
531 IDirectInputDevice2WImpl_Unacquire(iface);
532 return DIERR_NOTFOUND;
536 return DI_OK;
539 static HRESULT WINAPI JoystickLinuxAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
541 JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
542 return JoystickLinuxWImpl_Acquire(IDirectInputDevice8W_from_impl(This));
545 /******************************************************************************
546 * Unacquire : frees the joystick
548 static HRESULT WINAPI JoystickLinuxWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface)
550 JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
551 HRESULT res;
553 TRACE("(%p)\n",This);
555 res = IDirectInputDevice2WImpl_Unacquire(iface);
557 if (res != DI_OK)
558 return res;
560 if (This->joyfd!=-1) {
561 TRACE("closing joystick device\n");
562 close(This->joyfd);
563 This->joyfd = -1;
564 return DI_OK;
567 return DI_NOEFFECT;
570 static HRESULT WINAPI JoystickLinuxAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
572 JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
573 return JoystickLinuxWImpl_Unacquire(IDirectInputDevice8W_from_impl(This));
576 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface)
578 struct pollfd plfd;
579 struct js_event jse;
580 JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
582 TRACE("(%p)\n", This);
584 if (This->joyfd==-1) {
585 WARN("no device\n");
586 return;
588 while (1)
590 LONG value;
591 int inst_id = -1;
593 plfd.fd = This->joyfd;
594 plfd.events = POLLIN;
595 if (poll(&plfd,1,0) != 1)
596 return;
597 /* we have one event, so we can read */
598 if (sizeof(jse)!=read(This->joyfd,&jse,sizeof(jse))) {
599 return;
601 TRACE("js_event: type 0x%x, number %d, value %d\n",
602 jse.type,jse.number,jse.value);
603 if (jse.type & JS_EVENT_BUTTON)
605 if (jse.number >= This->generic.devcaps.dwButtons) return;
607 inst_id = DIDFT_MAKEINSTANCE(jse.number) | DIDFT_PSHBUTTON;
608 This->generic.js.rgbButtons[jse.number] = value = jse.value ? 0x80 : 0x00;
610 else if (jse.type & JS_EVENT_AXIS)
612 int number = This->generic.axis_map[jse.number]; /* wine format object index */
614 if (number < 0) return;
615 inst_id = number < 8 ? DIDFT_MAKEINSTANCE(number) | DIDFT_ABSAXIS :
616 DIDFT_MAKEINSTANCE(number - 8) | DIDFT_POV;
617 value = joystick_map_axis(&This->generic.props[id_to_object(This->generic.base.data_format.wine_df, inst_id)], jse.value);
619 TRACE("changing axis %d => %d\n", jse.number, number);
620 switch (number)
622 case 0: This->generic.js.lX = value; break;
623 case 1: This->generic.js.lY = value; break;
624 case 2: This->generic.js.lZ = value; break;
625 case 3: This->generic.js.lRx = value; break;
626 case 4: This->generic.js.lRy = value; break;
627 case 5: This->generic.js.lRz = value; break;
628 case 6: This->generic.js.rglSlider[0] = value; break;
629 case 7: This->generic.js.rglSlider[1] = value; break;
630 case 8: case 9: case 10: case 11:
632 int idx = number - 8;
634 if (jse.number % 2)
635 This->povs[idx].y = jse.value;
636 else
637 This->povs[idx].x = jse.value;
639 This->generic.js.rgdwPOV[idx] = value = joystick_map_pov(&This->povs[idx]);
640 break;
642 default:
643 WARN("axis %d not supported\n", number);
646 if (inst_id >= 0)
647 queue_event(iface, inst_id,
648 value, jse.time, This->generic.base.dinput->evsequence++);
652 static const IDirectInputDevice8AVtbl JoystickAvt =
654 IDirectInputDevice2AImpl_QueryInterface,
655 IDirectInputDevice2AImpl_AddRef,
656 IDirectInputDevice2AImpl_Release,
657 JoystickAGenericImpl_GetCapabilities,
658 IDirectInputDevice2AImpl_EnumObjects,
659 JoystickAGenericImpl_GetProperty,
660 JoystickAGenericImpl_SetProperty,
661 JoystickLinuxAImpl_Acquire,
662 JoystickLinuxAImpl_Unacquire,
663 JoystickAGenericImpl_GetDeviceState,
664 IDirectInputDevice2AImpl_GetDeviceData,
665 IDirectInputDevice2AImpl_SetDataFormat,
666 IDirectInputDevice2AImpl_SetEventNotification,
667 IDirectInputDevice2AImpl_SetCooperativeLevel,
668 JoystickAGenericImpl_GetObjectInfo,
669 JoystickAGenericImpl_GetDeviceInfo,
670 IDirectInputDevice2AImpl_RunControlPanel,
671 IDirectInputDevice2AImpl_Initialize,
672 IDirectInputDevice2AImpl_CreateEffect,
673 IDirectInputDevice2AImpl_EnumEffects,
674 IDirectInputDevice2AImpl_GetEffectInfo,
675 IDirectInputDevice2AImpl_GetForceFeedbackState,
676 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
677 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
678 IDirectInputDevice2AImpl_Escape,
679 JoystickAGenericImpl_Poll,
680 IDirectInputDevice2AImpl_SendDeviceData,
681 IDirectInputDevice7AImpl_EnumEffectsInFile,
682 IDirectInputDevice7AImpl_WriteEffectToFile,
683 IDirectInputDevice8AImpl_BuildActionMap,
684 IDirectInputDevice8AImpl_SetActionMap,
685 IDirectInputDevice8AImpl_GetImageInfo
688 static const IDirectInputDevice8WVtbl JoystickWvt =
690 IDirectInputDevice2WImpl_QueryInterface,
691 IDirectInputDevice2WImpl_AddRef,
692 IDirectInputDevice2WImpl_Release,
693 JoystickWGenericImpl_GetCapabilities,
694 IDirectInputDevice2WImpl_EnumObjects,
695 JoystickWGenericImpl_GetProperty,
696 JoystickWGenericImpl_SetProperty,
697 JoystickLinuxWImpl_Acquire,
698 JoystickLinuxWImpl_Unacquire,
699 JoystickWGenericImpl_GetDeviceState,
700 IDirectInputDevice2WImpl_GetDeviceData,
701 IDirectInputDevice2WImpl_SetDataFormat,
702 IDirectInputDevice2WImpl_SetEventNotification,
703 IDirectInputDevice2WImpl_SetCooperativeLevel,
704 JoystickWGenericImpl_GetObjectInfo,
705 JoystickWGenericImpl_GetDeviceInfo,
706 IDirectInputDevice2WImpl_RunControlPanel,
707 IDirectInputDevice2WImpl_Initialize,
708 IDirectInputDevice2WImpl_CreateEffect,
709 IDirectInputDevice2WImpl_EnumEffects,
710 IDirectInputDevice2WImpl_GetEffectInfo,
711 IDirectInputDevice2WImpl_GetForceFeedbackState,
712 IDirectInputDevice2WImpl_SendForceFeedbackCommand,
713 IDirectInputDevice2WImpl_EnumCreatedEffectObjects,
714 IDirectInputDevice2WImpl_Escape,
715 JoystickWGenericImpl_Poll,
716 IDirectInputDevice2WImpl_SendDeviceData,
717 IDirectInputDevice7WImpl_EnumEffectsInFile,
718 IDirectInputDevice7WImpl_WriteEffectToFile,
719 IDirectInputDevice8WImpl_BuildActionMap,
720 IDirectInputDevice8WImpl_SetActionMap,
721 IDirectInputDevice8WImpl_GetImageInfo
724 #else /* HAVE_LINUX_22_JOYSTICK_API */
726 const struct dinput_device joystick_linux_device = {
727 "Wine Linux joystick driver",
728 NULL,
729 NULL,
730 NULL,
731 NULL
734 #endif /* HAVE_LINUX_22_JOYSTICK_API */