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
29 #include "wine/port.h"
38 #ifdef HAVE_SYS_TIME_H
39 # include <sys/time.h>
42 #ifdef HAVE_SYS_IOCTL_H
43 # include <sys/ioctl.h>
46 #ifdef HAVE_LINUX_IOCTL_H
47 # include <linux/ioctl.h>
49 #ifdef HAVE_LINUX_JOYSTICK_H
50 # include <linux/joystick.h>
53 #ifdef HAVE_SYS_POLL_H
54 # include <sys/poll.h>
57 #include "wine/debug.h"
58 #include "wine/unicode.h"
64 #include "dinput_private.h"
65 #include "device_private.h"
66 #include "joystick_private.h"
68 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
70 #ifdef HAVE_LINUX_22_JOYSTICK_API
72 #define JOYDEV_NEW "/dev/input/js"
73 #define JOYDEV_OLD "/dev/js"
74 #define JOYDEVDRIVER " (js)"
78 char device
[MAX_PATH
];
86 typedef struct JoystickImpl JoystickImpl
;
87 static const IDirectInputDevice8AVtbl JoystickAvt
;
88 static const IDirectInputDevice8WVtbl JoystickWvt
;
91 struct JoystickGenericImpl generic
;
93 struct JoyDev
*joydev
;
95 /* joystick private */
100 static inline JoystickImpl
*impl_from_IDirectInputDevice8A(IDirectInputDevice8A
*iface
)
102 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8A_iface
),
103 JoystickGenericImpl
, base
), JoystickImpl
, generic
);
105 static inline JoystickImpl
*impl_from_IDirectInputDevice8W(IDirectInputDevice8W
*iface
)
107 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8W_iface
),
108 JoystickGenericImpl
, base
), JoystickImpl
, generic
);
111 static inline IDirectInputDevice8W
*IDirectInputDevice8W_from_impl(JoystickImpl
*This
)
113 return &This
->generic
.base
.IDirectInputDevice8W_iface
;
116 static const GUID DInput_Wine_Joystick_GUID
= { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
120 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
123 #define MAX_JOYSTICKS 64
124 static INT joystick_devices_count
= -1;
125 static struct JoyDev
*joystick_devices
;
127 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
);
129 static INT
find_joystick_devices(void)
133 if (joystick_devices_count
!= -1) return joystick_devices_count
;
135 joystick_devices_count
= 0;
136 for (i
= 0; i
< MAX_JOYSTICKS
; i
++)
139 struct JoyDev joydev
, *new_joydevs
;
140 BYTE axes_map
[ABS_MAX
+ 1];
142 snprintf(joydev
.device
, sizeof(joydev
.device
), "%s%d", JOYDEV_NEW
, i
);
143 if ((fd
= open(joydev
.device
, O_RDONLY
)) < 0)
145 snprintf(joydev
.device
, sizeof(joydev
.device
), "%s%d", JOYDEV_OLD
, i
);
146 if ((fd
= open(joydev
.device
, O_RDONLY
)) < 0) continue;
149 strcpy(joydev
.name
, "Wine Joystick");
150 #if defined(JSIOCGNAME)
151 if (ioctl(fd
, JSIOCGNAME(sizeof(joydev
.name
) - sizeof(JOYDEVDRIVER
)), joydev
.name
) < 0)
152 WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", joydev
.device
, strerror(errno
));
155 /* Append driver name */
156 strcat(joydev
.name
, JOYDEVDRIVER
);
158 if (device_disabled_registry(joydev
.name
)) {
164 if (ioctl(fd
, JSIOCGAXES
, &joydev
.axis_count
) < 0)
166 WARN("ioctl(%s,JSIOCGAXES) failed: %s, defauting to 2\n", joydev
.device
, strerror(errno
));
167 joydev
.axis_count
= 2;
170 WARN("reading number of joystick axes unsupported in this platform, defaulting to 2\n");
171 joydev
.axis_count
= 2;
174 if (ioctl(fd
, JSIOCGBUTTONS
, &joydev
.button_count
) < 0)
176 WARN("ioctl(%s,JSIOCGBUTTONS) failed: %s, defauting to 2\n", joydev
.device
, strerror(errno
));
177 joydev
.button_count
= 2;
180 WARN("reading number of joystick buttons unsupported in this platform, defaulting to 2\n");
181 joydev
.button_count
= 2;
184 if (ioctl(fd
, JSIOCGAXMAP
, axes_map
) < 0)
186 WARN("ioctl(%s,JSIOCGAXMAP) failed: %s\n", joydev
.device
, strerror(errno
));
187 joydev
.dev_axes_map
= NULL
;
190 if ((joydev
.dev_axes_map
= HeapAlloc(GetProcessHeap(), 0, joydev
.axis_count
* sizeof(int))))
194 /* Remap to DI numbers */
195 for (j
= 0; j
< joydev
.axis_count
; j
++)
197 /* Axis match 1-to-1 */
198 joydev
.dev_axes_map
[j
] = j
;
199 else if (axes_map
[j
] == 16 ||
202 joydev
.dev_axes_map
[j
] = 8;
204 joydev
.dev_axes_map
[j
] = -1;
209 if (!joystick_devices_count
)
210 new_joydevs
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct JoyDev
));
212 new_joydevs
= HeapReAlloc(GetProcessHeap(), 0, joystick_devices
,
213 (joystick_devices_count
+ 1) * sizeof(struct JoyDev
));
214 if (!new_joydevs
) continue;
216 TRACE("Found a joystick on %s: %s\n with %d axes and %d buttons\n", joydev
.device
,
217 joydev
.name
, joydev
.axis_count
, joydev
.button_count
);
219 joystick_devices
= new_joydevs
;
220 joystick_devices
[joystick_devices_count
++] = joydev
;
223 return joystick_devices_count
;
226 static HRESULT
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
230 if (id
>= find_joystick_devices()) return E_FAIL
;
232 if (dwFlags
& DIEDFL_FORCEFEEDBACK
) {
233 WARN("force feedback not supported\n");
237 if ((dwDevType
== 0) ||
238 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
239 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))) {
240 /* check whether we have a joystick */
241 if ((fd
= open(joystick_devices
[id
].device
, O_RDONLY
)) < 0)
243 WARN("open(%s, O_RDONLY) failed: %s\n", joystick_devices
[id
].name
, strerror(errno
));
247 /* Return joystick */
248 lpddi
->guidInstance
= DInput_Wine_Joystick_GUID
;
249 lpddi
->guidInstance
.Data3
= id
;
250 lpddi
->guidProduct
= DInput_Wine_Joystick_GUID
;
251 /* we only support traditional joysticks for now */
252 if (version
>= 0x0800)
253 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
255 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
257 strcpy(lpddi
->tszInstanceName
, joystick_devices
[id
].name
);
258 strcpy(lpddi
->tszProductName
, joystick_devices
[id
].name
);
260 lpddi
->guidFFDriver
= GUID_NULL
;
262 TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices
[id
].device
, lpddi
->tszProductName
);
269 static HRESULT
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
273 if (id
>= find_joystick_devices()) return E_FAIL
;
275 if (dwFlags
& DIEDFL_FORCEFEEDBACK
) {
276 WARN("force feedback not supported\n");
280 if ((dwDevType
== 0) ||
281 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
282 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))) {
283 /* check whether we have a joystick */
284 if ((fd
= open(joystick_devices
[id
].device
, O_RDONLY
)) < 0)
286 WARN("open(%s,O_RDONLY) failed: %s\n", joystick_devices
[id
].device
, strerror(errno
));
290 /* Return joystick */
291 lpddi
->guidInstance
= DInput_Wine_Joystick_GUID
;
292 lpddi
->guidInstance
.Data3
= id
;
293 lpddi
->guidProduct
= DInput_Wine_Joystick_GUID
;
294 /* we only support traditional joysticks for now */
295 if (version
>= 0x0800)
296 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
298 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
300 MultiByteToWideChar(CP_ACP
, 0, joystick_devices
[id
].name
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
301 MultiByteToWideChar(CP_ACP
, 0, joystick_devices
[id
].name
, -1, lpddi
->tszProductName
, MAX_PATH
);
302 lpddi
->guidFFDriver
= GUID_NULL
;
304 TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices
[id
].device
, joystick_devices
[id
].name
);
311 static HRESULT
alloc_device(REFGUID rguid
, IDirectInputImpl
*dinput
,
312 JoystickImpl
**pdev
, unsigned short index
)
315 JoystickImpl
* newDevice
;
317 LPDIDATAFORMAT df
= NULL
;
320 TRACE("%s %p %p %hu\n", debugstr_guid(rguid
), dinput
, pdev
, index
);
322 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(JoystickImpl
));
323 if (newDevice
== 0) {
324 WARN("out of memory\n");
326 return DIERR_OUTOFMEMORY
;
329 newDevice
->joydev
= &joystick_devices
[index
];
330 newDevice
->joyfd
= -1;
331 newDevice
->generic
.guidInstance
= DInput_Wine_Joystick_GUID
;
332 newDevice
->generic
.guidInstance
.Data3
= index
;
333 newDevice
->generic
.guidProduct
= DInput_Wine_Joystick_GUID
;
334 newDevice
->generic
.joy_polldev
= joy_polldev
;
335 newDevice
->generic
.name
= newDevice
->joydev
->name
;
336 newDevice
->generic
.device_axis_count
= newDevice
->joydev
->axis_count
;
337 newDevice
->generic
.devcaps
.dwButtons
= newDevice
->joydev
->button_count
;
339 if (newDevice
->generic
.devcaps
.dwButtons
> 128)
341 WARN("Can't support %d buttons. Clamping down to 128\n", newDevice
->generic
.devcaps
.dwButtons
);
342 newDevice
->generic
.devcaps
.dwButtons
= 128;
345 newDevice
->generic
.base
.IDirectInputDevice8A_iface
.lpVtbl
= &JoystickAvt
;
346 newDevice
->generic
.base
.IDirectInputDevice8W_iface
.lpVtbl
= &JoystickWvt
;
347 newDevice
->generic
.base
.ref
= 1;
348 newDevice
->generic
.base
.dinput
= dinput
;
349 newDevice
->generic
.base
.guid
= *rguid
;
350 InitializeCriticalSection(&newDevice
->generic
.base
.crit
);
351 newDevice
->generic
.base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->generic.base.crit");
353 /* setup_dinput_options may change these */
354 newDevice
->generic
.deadzone
= 0;
356 /* do any user specified configuration */
357 hr
= setup_dinput_options(&newDevice
->generic
, newDevice
->joydev
->dev_axes_map
);
361 /* Create copy of default data format */
362 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto FAILED
;
363 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
365 df
->dwNumObjs
= newDevice
->generic
.devcaps
.dwAxes
+ newDevice
->generic
.devcaps
.dwPOVs
+ newDevice
->generic
.devcaps
.dwButtons
;
366 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto FAILED
;
368 for (i
= 0; i
< newDevice
->generic
.device_axis_count
; i
++)
370 int wine_obj
= newDevice
->generic
.axis_map
[i
];
372 if (wine_obj
< 0) continue;
374 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[wine_obj
], df
->dwObjSize
);
376 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(wine_obj
) | DIDFT_ABSAXIS
;
379 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(wine_obj
- 8) | DIDFT_POV
;
380 i
++; /* POV takes 2 axes */
383 for (i
= 0; i
< newDevice
->generic
.devcaps
.dwButtons
; i
++)
385 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[i
+ 12], df
->dwObjSize
);
386 df
->rgodf
[idx
].pguid
= &GUID_Button
;
387 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(i
) | DIDFT_PSHBUTTON
;
389 newDevice
->generic
.base
.data_format
.wine_df
= df
;
391 /* initialize default properties */
392 for (i
= 0; i
< c_dfDIJoystick2
.dwNumObjs
; i
++) {
393 newDevice
->generic
.props
[i
].lDevMin
= -32767;
394 newDevice
->generic
.props
[i
].lDevMax
= +32767;
395 newDevice
->generic
.props
[i
].lMin
= 0;
396 newDevice
->generic
.props
[i
].lMax
= 0xffff;
397 newDevice
->generic
.props
[i
].lDeadZone
= newDevice
->generic
.deadzone
; /* % * 1000 */
398 newDevice
->generic
.props
[i
].lSaturation
= 0;
401 IDirectInput_AddRef(&newDevice
->generic
.base
.dinput
->IDirectInput7A_iface
);
403 EnterCriticalSection(&dinput
->crit
);
404 list_add_tail(&dinput
->devices_list
, &newDevice
->generic
.base
.entry
);
405 LeaveCriticalSection(&dinput
->crit
);
407 newDevice
->generic
.devcaps
.dwSize
= sizeof(newDevice
->generic
.devcaps
);
408 newDevice
->generic
.devcaps
.dwFlags
= DIDC_ATTACHED
;
409 if (newDevice
->generic
.base
.dinput
->dwVersion
>= 0x0800)
410 newDevice
->generic
.devcaps
.dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
412 newDevice
->generic
.devcaps
.dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
413 newDevice
->generic
.devcaps
.dwFFSamplePeriod
= 0;
414 newDevice
->generic
.devcaps
.dwFFMinTimeResolution
= 0;
415 newDevice
->generic
.devcaps
.dwFirmwareRevision
= 0;
416 newDevice
->generic
.devcaps
.dwHardwareRevision
= 0;
417 newDevice
->generic
.devcaps
.dwFFDriverVersion
= 0;
419 if (TRACE_ON(dinput
)) {
420 _dump_DIDATAFORMAT(newDevice
->generic
.base
.data_format
.wine_df
);
421 for (i
= 0; i
< (newDevice
->generic
.device_axis_count
); i
++)
422 TRACE("axis_map[%d] = %d\n", i
, newDevice
->generic
.axis_map
[i
]);
423 _dump_DIDEVCAPS(&newDevice
->generic
.devcaps
);
431 hr
= DIERR_OUTOFMEMORY
;
433 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
434 HeapFree(GetProcessHeap(), 0, df
);
435 release_DataFormat(&newDevice
->generic
.base
.data_format
);
436 HeapFree(GetProcessHeap(),0,newDevice
->generic
.axis_map
);
437 HeapFree(GetProcessHeap(),0,newDevice
);
443 /******************************************************************************
444 * get_joystick_index : Get the joystick index from a given GUID
446 static unsigned short get_joystick_index(REFGUID guid
)
448 GUID wine_joystick
= DInput_Wine_Joystick_GUID
;
449 GUID dev_guid
= *guid
;
451 wine_joystick
.Data3
= 0;
454 /* for the standard joystick GUID use index 0 */
455 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
457 /* for the wine joystick GUIDs use the index stored in Data3 */
458 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
;
460 return MAX_JOYSTICKS
;
463 static HRESULT
joydev_create_device(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPVOID
*pdev
, int unicode
)
465 unsigned short index
;
467 TRACE("%p %s %s %p %i\n", dinput
, debugstr_guid(rguid
), debugstr_guid(riid
), pdev
, unicode
);
468 find_joystick_devices();
471 if ((index
= get_joystick_index(rguid
)) < MAX_JOYSTICKS
&&
472 joystick_devices_count
&& index
< joystick_devices_count
)
479 else if (IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
480 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
481 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
482 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
486 else if (IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
487 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
488 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
489 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
495 WARN("no interface\n");
496 return DIERR_NOINTERFACE
;
499 hr
= alloc_device(rguid
, dinput
, &This
, index
);
500 if (!This
) return hr
;
503 *pdev
= &This
->generic
.base
.IDirectInputDevice8W_iface
;
505 *pdev
= &This
->generic
.base
.IDirectInputDevice8A_iface
;
510 return DIERR_DEVICENOTREG
;
515 const struct dinput_device joystick_linux_device
= {
516 "Wine Linux joystick driver",
522 /******************************************************************************
523 * Acquire : gets exclusive control of the joystick
525 static HRESULT WINAPI
JoystickLinuxWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface
)
527 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
530 TRACE("(%p)\n",This
);
532 res
= IDirectInputDevice2WImpl_Acquire(iface
);
536 /* open the joystick device */
537 if (This
->joyfd
==-1) {
538 TRACE("opening joystick device %s\n", This
->joydev
->device
);
540 This
->joyfd
= open(This
->joydev
->device
, O_RDONLY
);
541 if (This
->joyfd
==-1) {
542 ERR("open(%s) failed: %s\n", This
->joydev
->device
, strerror(errno
));
543 IDirectInputDevice2WImpl_Unacquire(iface
);
544 return DIERR_NOTFOUND
;
551 static HRESULT WINAPI
JoystickLinuxAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
553 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
554 return JoystickLinuxWImpl_Acquire(IDirectInputDevice8W_from_impl(This
));
557 /******************************************************************************
558 * GetProperty : get input device properties
560 static HRESULT WINAPI
JoystickLinuxWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
562 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
564 TRACE("(this=%p,%s,%p)\n", iface
, debugstr_guid(rguid
), pdiph
);
565 _dump_DIPROPHEADER(pdiph
);
567 if (!IS_DIPROP(rguid
)) return DI_OK
;
569 switch (LOWORD(rguid
)) {
571 case (DWORD_PTR
) DIPROP_JOYSTICKID
:
573 LPDIPROPDWORD pd
= (LPDIPROPDWORD
)pdiph
;
575 pd
->dwData
= get_joystick_index(&This
->generic
.base
.guid
);
576 TRACE("DIPROP_JOYSTICKID(%d)\n", pd
->dwData
);
581 return JoystickWGenericImpl_GetProperty(iface
, rguid
, pdiph
);
587 static HRESULT WINAPI
JoystickLinuxAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
, REFGUID rguid
, LPDIPROPHEADER pdiph
)
589 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
590 return JoystickLinuxWImpl_GetProperty(IDirectInputDevice8W_from_impl(This
), rguid
, pdiph
);
593 /******************************************************************************
594 * Unacquire : frees the joystick
596 static HRESULT WINAPI
JoystickLinuxWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface
)
598 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
601 TRACE("(%p)\n",This
);
603 res
= IDirectInputDevice2WImpl_Unacquire(iface
);
608 if (This
->joyfd
!=-1) {
609 TRACE("closing joystick device\n");
618 static HRESULT WINAPI
JoystickLinuxAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
620 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
621 return JoystickLinuxWImpl_Unacquire(IDirectInputDevice8W_from_impl(This
));
624 static void joy_polldev(LPDIRECTINPUTDEVICE8A iface
)
628 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
630 TRACE("(%p)\n", This
);
632 if (This
->joyfd
==-1) {
641 plfd
.fd
= This
->joyfd
;
642 plfd
.events
= POLLIN
;
643 if (poll(&plfd
,1,0) != 1)
645 /* we have one event, so we can read */
646 if (sizeof(jse
)!=read(This
->joyfd
,&jse
,sizeof(jse
))) {
649 TRACE("js_event: type 0x%x, number %d, value %d\n",
650 jse
.type
,jse
.number
,jse
.value
);
651 if (jse
.type
& JS_EVENT_BUTTON
)
653 if (jse
.number
>= This
->generic
.devcaps
.dwButtons
) return;
655 inst_id
= DIDFT_MAKEINSTANCE(jse
.number
) | DIDFT_PSHBUTTON
;
656 This
->generic
.js
.rgbButtons
[jse
.number
] = value
= jse
.value
? 0x80 : 0x00;
658 else if (jse
.type
& JS_EVENT_AXIS
)
660 int number
= This
->generic
.axis_map
[jse
.number
]; /* wine format object index */
662 if (number
< 0) return;
663 inst_id
= number
< 8 ? DIDFT_MAKEINSTANCE(number
) | DIDFT_ABSAXIS
:
664 DIDFT_MAKEINSTANCE(number
- 8) | DIDFT_POV
;
665 value
= joystick_map_axis(&This
->generic
.props
[id_to_object(This
->generic
.base
.data_format
.wine_df
, inst_id
)], jse
.value
);
667 TRACE("changing axis %d => %d\n", jse
.number
, number
);
670 case 0: This
->generic
.js
.lX
= value
; break;
671 case 1: This
->generic
.js
.lY
= value
; break;
672 case 2: This
->generic
.js
.lZ
= value
; break;
673 case 3: This
->generic
.js
.lRx
= value
; break;
674 case 4: This
->generic
.js
.lRy
= value
; break;
675 case 5: This
->generic
.js
.lRz
= value
; break;
676 case 6: This
->generic
.js
.rglSlider
[0] = value
; break;
677 case 7: This
->generic
.js
.rglSlider
[1] = value
; break;
678 case 8: case 9: case 10: case 11:
680 int idx
= number
- 8;
683 This
->povs
[idx
].y
= jse
.value
;
685 This
->povs
[idx
].x
= jse
.value
;
687 This
->generic
.js
.rgdwPOV
[idx
] = value
= joystick_map_pov(&This
->povs
[idx
]);
691 WARN("axis %d not supported\n", number
);
695 queue_event(iface
, inst_id
, value
, GetCurrentTime(), This
->generic
.base
.dinput
->evsequence
++);
699 static const IDirectInputDevice8AVtbl JoystickAvt
=
701 IDirectInputDevice2AImpl_QueryInterface
,
702 IDirectInputDevice2AImpl_AddRef
,
703 IDirectInputDevice2AImpl_Release
,
704 JoystickAGenericImpl_GetCapabilities
,
705 IDirectInputDevice2AImpl_EnumObjects
,
706 JoystickLinuxAImpl_GetProperty
,
707 JoystickAGenericImpl_SetProperty
,
708 JoystickLinuxAImpl_Acquire
,
709 JoystickLinuxAImpl_Unacquire
,
710 JoystickAGenericImpl_GetDeviceState
,
711 IDirectInputDevice2AImpl_GetDeviceData
,
712 IDirectInputDevice2AImpl_SetDataFormat
,
713 IDirectInputDevice2AImpl_SetEventNotification
,
714 IDirectInputDevice2AImpl_SetCooperativeLevel
,
715 JoystickAGenericImpl_GetObjectInfo
,
716 JoystickAGenericImpl_GetDeviceInfo
,
717 IDirectInputDevice2AImpl_RunControlPanel
,
718 IDirectInputDevice2AImpl_Initialize
,
719 IDirectInputDevice2AImpl_CreateEffect
,
720 IDirectInputDevice2AImpl_EnumEffects
,
721 IDirectInputDevice2AImpl_GetEffectInfo
,
722 IDirectInputDevice2AImpl_GetForceFeedbackState
,
723 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
724 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
725 IDirectInputDevice2AImpl_Escape
,
726 JoystickAGenericImpl_Poll
,
727 IDirectInputDevice2AImpl_SendDeviceData
,
728 IDirectInputDevice7AImpl_EnumEffectsInFile
,
729 IDirectInputDevice7AImpl_WriteEffectToFile
,
730 JoystickAGenericImpl_BuildActionMap
,
731 JoystickAGenericImpl_SetActionMap
,
732 IDirectInputDevice8AImpl_GetImageInfo
735 static const IDirectInputDevice8WVtbl JoystickWvt
=
737 IDirectInputDevice2WImpl_QueryInterface
,
738 IDirectInputDevice2WImpl_AddRef
,
739 IDirectInputDevice2WImpl_Release
,
740 JoystickWGenericImpl_GetCapabilities
,
741 IDirectInputDevice2WImpl_EnumObjects
,
742 JoystickLinuxWImpl_GetProperty
,
743 JoystickWGenericImpl_SetProperty
,
744 JoystickLinuxWImpl_Acquire
,
745 JoystickLinuxWImpl_Unacquire
,
746 JoystickWGenericImpl_GetDeviceState
,
747 IDirectInputDevice2WImpl_GetDeviceData
,
748 IDirectInputDevice2WImpl_SetDataFormat
,
749 IDirectInputDevice2WImpl_SetEventNotification
,
750 IDirectInputDevice2WImpl_SetCooperativeLevel
,
751 JoystickWGenericImpl_GetObjectInfo
,
752 JoystickWGenericImpl_GetDeviceInfo
,
753 IDirectInputDevice2WImpl_RunControlPanel
,
754 IDirectInputDevice2WImpl_Initialize
,
755 IDirectInputDevice2WImpl_CreateEffect
,
756 IDirectInputDevice2WImpl_EnumEffects
,
757 IDirectInputDevice2WImpl_GetEffectInfo
,
758 IDirectInputDevice2WImpl_GetForceFeedbackState
,
759 IDirectInputDevice2WImpl_SendForceFeedbackCommand
,
760 IDirectInputDevice2WImpl_EnumCreatedEffectObjects
,
761 IDirectInputDevice2WImpl_Escape
,
762 JoystickWGenericImpl_Poll
,
763 IDirectInputDevice2WImpl_SendDeviceData
,
764 IDirectInputDevice7WImpl_EnumEffectsInFile
,
765 IDirectInputDevice7WImpl_WriteEffectToFile
,
766 JoystickWGenericImpl_BuildActionMap
,
767 JoystickWGenericImpl_SetActionMap
,
768 IDirectInputDevice8WImpl_GetImageInfo
771 #else /* HAVE_LINUX_22_JOYSTICK_API */
773 const struct dinput_device joystick_linux_device
= {
774 "Wine Linux joystick driver",
780 #endif /* HAVE_LINUX_22_JOYSTICK_API */