1 /* DirectInput Joystick device
3 * Copyright 1998,2000 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
33 #ifdef HAVE_SYS_TIME_H
34 # include <sys/time.h>
36 #include <sys/fcntl.h>
37 #ifdef HAVE_SYS_IOCTL_H
38 # include <sys/ioctl.h>
41 #ifdef HAVE_SYS_ERRNO_H
42 # include <sys/errno.h>
44 #ifdef HAVE_LINUX_INPUT_H
45 # include <linux/input.h>
48 #include "wine/debug.h"
49 #include "wine/unicode.h"
55 #include "dinput_private.h"
56 #include "device_private.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
60 #ifdef HAVE_CORRECT_LINUXINPUT_H
62 #define EVDEVPREFIX "/dev/input/event"
64 /* Wine joystick driver object instances */
65 #define WINE_JOYSTICK_AXIS_BASE 0
66 #define WINE_JOYSTICK_BUTTON_BASE 8
68 typedef struct JoystickImpl JoystickImpl;
69 static const IDirectInputDevice8AVtbl JoystickAvt;
70 static const IDirectInputDevice8WVtbl JoystickWvt;
78 /* The 'parent' DInput */
79 IDirectInputImpl *dinput;
81 /* joystick private */
82 /* what range and deadzone the game wants */
83 LONG wantmin[ABS_MAX];
84 LONG wantmax[ABS_MAX];
87 /* autodetecting ranges per axe by following movement */
88 LONG havemax[ABS_MAX];
89 LONG havemin[ABS_MAX];
95 LPDIDEVICEOBJECTDATA data_queue;
96 int queue_head, queue_tail, queue_len;
100 /* data returned by the EVIOCGABS() ioctl */
101 int axes[ABS_MAX+1][5];
106 #define AXE_ABSFUZZ 3
107 #define AXE_ABSFLAT 4
110 /* data returned by EVIOCGBIT for EV_ABS and EV_KEY */
111 BYTE absbits[(ABS_MAX+7)/8];
112 BYTE keybits[(KEY_MAX+7)/8];
115 /* This GUID is slightly different from the linux joystick one. Take note. */
116 static GUID DInput_Wine_Joystick_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
120 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
123 static void fake_current_js_state(JoystickImpl *ji);
125 #define test_bit(arr,bit) (((BYTE*)arr)[bit>>3]&(1<<(bit&7)))
127 static int joydev_have(void)
134 BYTE absbits[(ABS_MAX+7)/8],keybits[(KEY_MAX+7)/8];
136 sprintf(buf,EVDEVPREFIX"%d",i);
137 if (-1!=(fd=open(buf,O_RDONLY))) {
138 if (-1==ioctl(fd,EVIOCGBIT(EV_ABS,sizeof(absbits)),absbits)) {
139 perror("EVIOCGBIT EV_ABS");
143 if (-1==ioctl(fd,EVIOCGBIT(EV_KEY,sizeof(keybits)),keybits)) {
144 perror("EVIOCGBIT EV_KEY");
148 /* A true joystick has at least axis X and Y, and at least 1
149 * button. copied from linux/drivers/input/joydev.c */
150 if (test_bit(absbits,ABS_X) && test_bit(absbits,ABS_Y) &&
151 ( test_bit(keybits,BTN_TRIGGER) ||
152 test_bit(keybits,BTN_A) ||
153 test_bit(keybits,BTN_1)
156 FIXME("found a joystick at %s!\n",buf);
161 if (havejoy || (errno==ENODEV))
167 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
174 if (!((dwDevType == 0) ||
175 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
176 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
179 if (dwFlags & DIEDFL_FORCEFEEDBACK)
182 havejoy = joydev_have();
187 TRACE("Enumerating the linuxinput Joystick device\n");
189 /* Return joystick */
190 lpddi->guidInstance = GUID_Joystick;
191 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
193 lpddi->guidFFDriver = GUID_NULL;
194 if (version >= 0x0800)
195 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
197 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
199 strcpy(lpddi->tszInstanceName, "Joystick");
200 /* ioctl JSIOCGNAME(len) */
201 strcpy(lpddi->tszProductName, "Wine Joystick");
205 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
212 if (!((dwDevType == 0) ||
213 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 0x0800)) ||
214 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
217 if (dwFlags & DIEDFL_FORCEFEEDBACK)
220 havejoy = joydev_have();
225 TRACE("Enumerating the linuxinput Joystick device\n");
227 /* Return joystick */
228 lpddi->guidInstance = GUID_Joystick;
229 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
231 lpddi->guidFFDriver = GUID_NULL;
232 if (version >= 0x0800)
233 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
235 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
237 MultiByteToWideChar(CP_ACP, 0, "Joystick", -1, lpddi->tszInstanceName, MAX_PATH);
238 /* ioctl JSIOCGNAME(len) */
239 MultiByteToWideChar(CP_ACP, 0, "Wine Joystick", -1, lpddi->tszProductName, MAX_PATH);
243 static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput)
245 JoystickImpl* newDevice;
248 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
249 newDevice->lpVtbl = jvt;
251 newDevice->joyfd = -1;
252 newDevice->dinput = dinput;
253 memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
254 for (i=0;i<ABS_MAX;i++) {
255 newDevice->wantmin[i] = -32768;
256 newDevice->wantmax[i] = 32767;
258 * direct input defines a default for the deadzone somewhere; but as long
259 * as in map_axis the code for the dead zone is commented out its no
262 newDevice->deadz[i] = 0;
264 fake_current_js_state(newDevice);
268 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
272 havejoy = joydev_have();
275 return DIERR_DEVICENOTREG;
277 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
278 (IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) {
279 if ((riid == NULL) ||
280 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
281 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
282 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
283 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
284 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput);
285 TRACE("Creating a Joystick device (%p)\n", *pdev);
288 return DIERR_NOINTERFACE;
291 return DIERR_DEVICENOTREG;
295 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
299 havejoy = joydev_have();
302 return DIERR_DEVICENOTREG;
304 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
305 (IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) {
306 if ((riid == NULL) ||
307 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
308 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
309 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
310 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
311 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput);
312 TRACE("Creating a Joystick device (%p)\n", *pdev);
315 return DIERR_NOINTERFACE;
318 return DIERR_DEVICENOTREG;
321 const struct dinput_device joystick_linuxinput_device = {
322 "Wine Linux-input joystick driver",
325 joydev_create_deviceA,
326 joydev_create_deviceW
329 /******************************************************************************
332 static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
334 JoystickImpl *This = (JoystickImpl *)iface;
337 ref = InterlockedDecrement(&(This->ref));
341 /* Free the data queue */
342 HeapFree(GetProcessHeap(),0,This->data_queue);
344 /* Free the DataFormat */
345 HeapFree(GetProcessHeap(), 0, This->df);
347 HeapFree(GetProcessHeap(),0,This);
351 /******************************************************************************
352 * SetDataFormat : the application can choose the format of the data
353 * the device driver sends back with GetDeviceState.
355 static HRESULT WINAPI JoystickAImpl_SetDataFormat(
356 LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
359 JoystickImpl *This = (JoystickImpl *)iface;
361 TRACE("(this=%p,%p)\n",This,df);
363 _dump_DIDATAFORMAT(df);
365 /* Store the new data format */
366 This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
367 memcpy(This->df, df, df->dwSize);
368 This->df->rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
369 memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
374 /******************************************************************************
375 * Acquire : gets exclusive control of the joystick
377 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
380 JoystickImpl *This = (JoystickImpl *)iface;
383 TRACE("(this=%p)\n",This);
387 sprintf(buf,EVDEVPREFIX"%d",i);
388 if (-1==(This->joyfd=open(buf,O_RDONLY))) {
390 return DIERR_NOTFOUND;
394 if ((-1!=ioctl(This->joyfd,EVIOCGBIT(EV_ABS,sizeof(This->absbits)),This->absbits)) &&
395 (-1!=ioctl(This->joyfd,EVIOCGBIT(EV_KEY,sizeof(This->keybits)),This->keybits)) &&
396 (test_bit(This->absbits,ABS_X) && test_bit(This->absbits,ABS_Y) &&
397 (test_bit(This->keybits,BTN_TRIGGER)||
398 test_bit(This->keybits,BTN_A) ||
399 test_bit(This->keybits,BTN_1)
408 return DIERR_NOTFOUND;
410 for (i=0;i<ABS_MAX;i++) {
411 if (test_bit(This->absbits,i)) {
412 if (-1==ioctl(This->joyfd,EVIOCGABS(i),&(This->axes[i])))
414 FIXME("axe %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
416 This->axes[i][AXE_ABS],
417 This->axes[i][AXE_ABSMIN],
418 This->axes[i][AXE_ABSMAX],
419 This->axes[i][AXE_ABSFUZZ],
420 This->axes[i][AXE_ABSFLAT]
422 This->havemin[i] = This->axes[i][AXE_ABSMIN];
423 This->havemax[i] = This->axes[i][AXE_ABSMAX];
428 fake_current_js_state(This);
433 /******************************************************************************
434 * Unacquire : frees the joystick
436 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
438 JoystickImpl *This = (JoystickImpl *)iface;
440 TRACE("(this=%p)\n",This);
441 if (This->joyfd!=-1) {
451 * This maps the read value (from the input event) to a value in the
452 * 'wanted' range. It also autodetects the possible range of the axe and
453 * adapts values accordingly.
456 map_axis(JoystickImpl* This, int axis, int val) {
457 int xmin = This->axes[axis][AXE_ABSMIN];
458 int xmax = This->axes[axis][AXE_ABSMAX];
459 int hmax = This->havemax[axis];
460 int hmin = This->havemin[axis];
461 int wmin = This->wantmin[axis];
462 int wmax = This->wantmax[axis];
465 if (val > hmax) This->havemax[axis] = hmax = val;
466 if (val < hmin) This->havemin[axis] = hmin = val;
468 if (xmin == xmax) return val;
470 /* map the value from the hmin-hmax range into the wmin-wmax range */
471 ret = (val * (wmax-wmin)) / (hmax-hmin) + wmin;
474 /* deadzone doesn't work comfortably enough right now. needs more testing*/
475 if ((ret > -deadz/2 ) && (ret < deadz/2)) {
476 FIXME("%d in deadzone, return mid.\n",val);
477 return (wmax-wmin)/2+wmin;
484 * set the current state of the js device as it would be with the middle
487 static void fake_current_js_state(JoystickImpl *ji)
489 ji->js.lX = map_axis(ji, ABS_X, ji->axes[ABS_X ][AXE_ABS]);
490 ji->js.lY = map_axis(ji, ABS_Y, ji->axes[ABS_Y ][AXE_ABS]);
491 ji->js.lZ = map_axis(ji, ABS_Z, ji->axes[ABS_Z ][AXE_ABS]);
492 ji->js.lRx = map_axis(ji, ABS_RX, ji->axes[ABS_RX][AXE_ABS]);
493 ji->js.lRy = map_axis(ji, ABS_RY, ji->axes[ABS_RY][AXE_ABS]);
494 ji->js.lRz = map_axis(ji, ABS_RZ, ji->axes[ABS_RZ][AXE_ABS]);
497 static void joy_polldev(JoystickImpl *This) {
500 struct input_event ie;
506 memset(&tv,0,sizeof(tv));
508 FD_SET(This->joyfd,&readfds);
510 if (1>select(This->joyfd+1,&readfds,NULL,NULL,&tv))
513 /* we have one event, so we can read */
514 if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
517 TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
519 case EV_KEY: /* button */
521 case BTN_TRIGGER: /* normal flight stick */
522 case BTN_A: /* gamepad */
523 case BTN_1: /* generic */
524 This->js.rgbButtons[0] = ie.value?0x80:0x00;
525 GEN_EVENT(DIJOFS_BUTTON(0),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
530 This->js.rgbButtons[1] = ie.value?0x80:0x00;
531 GEN_EVENT(DIJOFS_BUTTON(1),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
536 This->js.rgbButtons[2] = ie.value?0x80:0x00;
537 GEN_EVENT(DIJOFS_BUTTON(2),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
542 This->js.rgbButtons[3] = ie.value?0x80:0x00;
543 GEN_EVENT(DIJOFS_BUTTON(3),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
548 This->js.rgbButtons[4] = ie.value?0x80:0x00;
549 GEN_EVENT(DIJOFS_BUTTON(4),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
554 This->js.rgbButtons[5] = ie.value?0x80:0x00;
555 GEN_EVENT(DIJOFS_BUTTON(5),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
560 This->js.rgbButtons[6] = ie.value?0x80:0x00;
561 GEN_EVENT(DIJOFS_BUTTON(6),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
566 This->js.rgbButtons[7] = ie.value?0x80:0x00;
567 GEN_EVENT(DIJOFS_BUTTON(7),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
572 This->js.rgbButtons[8] = ie.value?0x80:0x00;
573 GEN_EVENT(DIJOFS_BUTTON(8),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
577 This->js.rgbButtons[9] = ie.value?0x80:0x00;
578 GEN_EVENT(DIJOFS_BUTTON(9),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
582 This->js.rgbButtons[10] = ie.value?0x80:0x00;
583 GEN_EVENT(DIJOFS_BUTTON(10),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
586 FIXME("unhandled joystick button %x, value %d\n",ie.code,ie.value);
593 This->js.lX = map_axis(This,ABS_X,ie.value);
594 GEN_EVENT(DIJOFS_X,This->js.lX,ie.time.tv_usec,(This->dinput->evsequence)++);
597 This->js.lY = map_axis(This,ABS_Y,ie.value);
598 GEN_EVENT(DIJOFS_Y,This->js.lY,ie.time.tv_usec,(This->dinput->evsequence)++);
601 This->js.lZ = map_axis(This,ABS_Z,ie.value);
602 GEN_EVENT(DIJOFS_Z,This->js.lZ,ie.time.tv_usec,(This->dinput->evsequence)++);
605 This->js.lRx = map_axis(This,ABS_RX,ie.value);
606 GEN_EVENT(DIJOFS_RX,This->js.lRx,ie.time.tv_usec,(This->dinput->evsequence)++);
609 This->js.lRy = map_axis(This,ABS_RY,ie.value);
610 GEN_EVENT(DIJOFS_RY,This->js.lRy,ie.time.tv_usec,(This->dinput->evsequence)++);
613 This->js.lRz = map_axis(This,ABS_RZ,ie.value);
614 GEN_EVENT(DIJOFS_RZ,This->js.lRz,ie.time.tv_usec,(This->dinput->evsequence)++);
617 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie.code,ie.value);
622 FIXME("joystick cannot handle type %d event (code %d)\n",ie.type,ie.code);
628 /******************************************************************************
629 * GetDeviceState : returns the "state" of the joystick.
632 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
633 LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
635 JoystickImpl *This = (JoystickImpl *)iface;
639 TRACE("(this=%p,0x%08lx,%p)\n",This,len,ptr);
640 if ((len != sizeof(DIJOYSTATE)) && (len != sizeof(DIJOYSTATE2))) {
641 FIXME("len %ld is not sizeof(DIJOYSTATE) or DIJOYSTATE2, unsupported format.\n",len);
644 memcpy(ptr,&(This->js),len);
645 This->queue_head = 0;
646 This->queue_tail = 0;
650 /******************************************************************************
651 * GetDeviceData : gets buffered input data.
653 static HRESULT WINAPI JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
655 LPDIDEVICEOBJECTDATA dod,
659 JoystickImpl *This = (JoystickImpl *)iface;
661 FIXME("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx),STUB!\n",This,dodsize,*entries,flags);
664 if (flags & DIGDD_PEEK)
665 FIXME("DIGDD_PEEK\n");
673 /******************************************************************************
674 * SetProperty : change input device properties
676 static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
680 JoystickImpl *This = (JoystickImpl *)iface;
682 FIXME("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
683 FIXME("ph.dwSize = %ld, ph.dwHeaderSize =%ld, ph.dwObj = %ld, ph.dwHow= %ld\n",ph->dwSize, ph->dwHeaderSize,ph->dwObj,ph->dwHow);
685 if (!HIWORD(rguid)) {
686 switch ((DWORD)rguid) {
687 case (DWORD) DIPROP_BUFFERSIZE: {
688 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
690 FIXME("buffersize = %ld\n",pd->dwData);
693 case (DWORD)DIPROP_RANGE: {
694 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
696 FIXME("proprange(%ld,%ld)\n",pr->lMin,pr->lMax);
704 This->wantmin[ph->dwObj/4] = pr->lMin;
705 This->wantmax[ph->dwObj/4] = pr->lMax;
708 FIXME("setting proprange %ld - %ld for dwObj %ld\n",pr->lMin,pr->lMax,ph->dwObj);
712 case (DWORD)DIPROP_DEADZONE: {
713 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
715 FIXME("setting deadzone(%ld)\n",pd->dwData);
716 This->deadz[ph->dwObj/4] = pd->dwData;
720 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
724 fake_current_js_state(This);
728 /******************************************************************************
729 * SetEventNotification : specifies event to be sent on state change
731 static HRESULT WINAPI JoystickAImpl_SetEventNotification(
732 LPDIRECTINPUTDEVICE8A iface, HANDLE hnd
734 JoystickImpl *This = (JoystickImpl *)iface;
736 TRACE("(this=%p,0x%08lx)\n",This,(DWORD)hnd);
741 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
742 LPDIRECTINPUTDEVICE8A iface,
743 LPDIDEVCAPS lpDIDevCaps)
745 JoystickImpl *This = (JoystickImpl *)iface;
746 int xfd = This->joyfd;
750 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
752 /* yes, games assume we return something, even if unacquired */
753 JoystickAImpl_Acquire(iface);
757 lpDIDevCaps->dwFlags = DIDC_ATTACHED;
758 if (This->dinput->dwVersion >= 0x0800)
759 lpDIDevCaps->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
761 lpDIDevCaps->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
764 for (i=0;i<ABS_MAX;i++) if (test_bit(This->absbits,i)) axes++;
766 for (i=0;i<KEY_MAX;i++) if (test_bit(This->keybits,i)) buttons++;
768 lpDIDevCaps->dwAxes = axes;
769 lpDIDevCaps->dwButtons = buttons;
772 JoystickAImpl_Unacquire(iface);
777 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface) {
778 JoystickImpl *This = (JoystickImpl *)iface;
785 /******************************************************************************
786 * EnumObjects : enumerate the different buttons and axis...
788 static HRESULT WINAPI JoystickAImpl_EnumObjects(
789 LPDIRECTINPUTDEVICE8A iface,
790 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
794 JoystickImpl *This = (JoystickImpl *)iface;
795 DIDEVICEOBJECTINSTANCEA ddoi;
796 int xfd = This->joyfd;
799 TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
800 if (TRACE_ON(dinput)) {
801 TRACE(" - flags = ");
802 _dump_EnumObjects_flags(dwFlags);
806 if (xfd == -1) return DIERR_NOTACQUIRED;
808 /* Only the fields till dwFFMaxForce are relevant */
809 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
811 /* For the joystick, do as is done in the GetCapabilities function */
812 /* FIXME: needs more items */
813 if ((dwFlags == DIDFT_ALL) ||
814 (dwFlags & DIDFT_AXIS)) {
817 for (i = 0; i < ABS_MAX; i++) {
818 if (!test_bit(This->absbits,i)) continue;
822 ddoi.guidType = GUID_XAxis;
823 ddoi.dwOfs = DIJOFS_X;
826 ddoi.guidType = GUID_YAxis;
827 ddoi.dwOfs = DIJOFS_Y;
830 ddoi.guidType = GUID_ZAxis;
831 ddoi.dwOfs = DIJOFS_Z;
834 ddoi.guidType = GUID_RxAxis;
835 ddoi.dwOfs = DIJOFS_RX;
838 ddoi.guidType = GUID_RyAxis;
839 ddoi.dwOfs = DIJOFS_RY;
842 ddoi.guidType = GUID_RzAxis;
843 ddoi.dwOfs = DIJOFS_RZ;
846 ddoi.guidType = GUID_Slider;
847 ddoi.dwOfs = DIJOFS_SLIDER(0);
850 FIXME("unhandled abs axis %d, ignoring!\n",i);
852 ddoi.dwType = DIDFT_MAKEINSTANCE((1<<i) << WINE_JOYSTICK_AXIS_BASE) | DIDFT_ABSAXIS;
853 sprintf(ddoi.tszName, "%d-Axis", i);
854 _dump_OBJECTINSTANCEA(&ddoi);
855 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE)
860 if ((dwFlags == DIDFT_ALL) ||
861 (dwFlags & DIDFT_BUTTON)) {
864 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
866 ddoi.guidType = GUID_Button;
868 for (i = 0; i < KEY_MAX; i++) {
869 if (!test_bit(This->keybits,i)) continue;
875 ddoi.dwOfs = DIJOFS_BUTTON(0);
876 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 0) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
881 ddoi.dwOfs = DIJOFS_BUTTON(1);
882 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 1) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
887 ddoi.dwOfs = DIJOFS_BUTTON(2);
888 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 2) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
893 ddoi.dwOfs = DIJOFS_BUTTON(3);
894 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 3) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
899 ddoi.dwOfs = DIJOFS_BUTTON(4);
900 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 4) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
905 ddoi.dwOfs = DIJOFS_BUTTON(5);
906 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 5) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
911 ddoi.dwOfs = DIJOFS_BUTTON(6);
912 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 6) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
917 ddoi.dwOfs = DIJOFS_BUTTON(7);
918 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 7) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
923 ddoi.dwOfs = DIJOFS_BUTTON(8);
924 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 8) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
928 ddoi.dwOfs = DIJOFS_BUTTON(9);
929 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 9) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
933 ddoi.dwOfs = DIJOFS_BUTTON(10);
934 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 10) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
937 sprintf(ddoi.tszName, "%d-Button", i);
938 _dump_OBJECTINSTANCEA(&ddoi);
939 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE)
944 if (xfd!=This->joyfd)
950 static HRESULT WINAPI JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
951 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
955 JoystickImpl *This = (JoystickImpl *)iface;
957 device_enumobjects_AtoWcb_data data;
959 data.lpCallBack = lpCallback;
960 data.lpvRef = lpvRef;
962 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
965 /******************************************************************************
966 * GetProperty : get input device properties
968 static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
970 LPDIPROPHEADER pdiph)
972 JoystickImpl *This = (JoystickImpl *)iface;
974 TRACE("(this=%p,%s,%p)\n",
975 iface, debugstr_guid(rguid), pdiph);
977 if (TRACE_ON(dinput))
978 _dump_DIPROPHEADER(pdiph);
980 if (!HIWORD(rguid)) {
981 switch ((DWORD)rguid) {
982 case (DWORD) DIPROP_BUFFERSIZE: {
983 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
985 TRACE(" return buffersize = %d\n",This->queue_len);
986 pd->dwData = This->queue_len;
990 case (DWORD) DIPROP_RANGE: {
991 /* LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph; */
992 if ((pdiph->dwHow == DIPH_BYID) &&
993 (pdiph->dwObj & DIDFT_ABSAXIS)) {
994 /* The app is querying the current range of the axis : return the lMin and lMax values */
995 FIXME("unimplemented axis range query.\n");
1002 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
1011 static const IDirectInputDevice8AVtbl JoystickAvt =
1013 IDirectInputDevice2AImpl_QueryInterface,
1014 IDirectInputDevice2AImpl_AddRef,
1015 JoystickAImpl_Release,
1016 JoystickAImpl_GetCapabilities,
1017 JoystickAImpl_EnumObjects,
1018 JoystickAImpl_GetProperty,
1019 JoystickAImpl_SetProperty,
1020 JoystickAImpl_Acquire,
1021 JoystickAImpl_Unacquire,
1022 JoystickAImpl_GetDeviceState,
1023 JoystickAImpl_GetDeviceData,
1024 JoystickAImpl_SetDataFormat,
1025 JoystickAImpl_SetEventNotification,
1026 IDirectInputDevice2AImpl_SetCooperativeLevel,
1027 IDirectInputDevice2AImpl_GetObjectInfo,
1028 IDirectInputDevice2AImpl_GetDeviceInfo,
1029 IDirectInputDevice2AImpl_RunControlPanel,
1030 IDirectInputDevice2AImpl_Initialize,
1031 IDirectInputDevice2AImpl_CreateEffect,
1032 IDirectInputDevice2AImpl_EnumEffects,
1033 IDirectInputDevice2AImpl_GetEffectInfo,
1034 IDirectInputDevice2AImpl_GetForceFeedbackState,
1035 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1036 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1037 IDirectInputDevice2AImpl_Escape,
1039 IDirectInputDevice2AImpl_SendDeviceData,
1040 IDirectInputDevice7AImpl_EnumEffectsInFile,
1041 IDirectInputDevice7AImpl_WriteEffectToFile,
1042 IDirectInputDevice8AImpl_BuildActionMap,
1043 IDirectInputDevice8AImpl_SetActionMap,
1044 IDirectInputDevice8AImpl_GetImageInfo
1047 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1048 # define XCAST(fun) (typeof(JoystickWvt.fun))
1050 # define XCAST(fun) (void*)
1053 static const IDirectInputDevice8WVtbl JoystickWvt =
1055 IDirectInputDevice2WImpl_QueryInterface,
1056 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1057 XCAST(Release)JoystickAImpl_Release,
1058 XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1059 JoystickWImpl_EnumObjects,
1060 XCAST(GetProperty)JoystickAImpl_GetProperty,
1061 XCAST(SetProperty)JoystickAImpl_SetProperty,
1062 XCAST(Acquire)JoystickAImpl_Acquire,
1063 XCAST(Unacquire)JoystickAImpl_Unacquire,
1064 XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1065 XCAST(GetDeviceData)JoystickAImpl_GetDeviceData,
1066 XCAST(SetDataFormat)JoystickAImpl_SetDataFormat,
1067 XCAST(SetEventNotification)JoystickAImpl_SetEventNotification,
1068 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1069 IDirectInputDevice2WImpl_GetObjectInfo,
1070 IDirectInputDevice2WImpl_GetDeviceInfo,
1071 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1072 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1073 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
1074 IDirectInputDevice2WImpl_EnumEffects,
1075 IDirectInputDevice2WImpl_GetEffectInfo,
1076 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
1077 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1078 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1079 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1080 XCAST(Poll)JoystickAImpl_Poll,
1081 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1082 IDirectInputDevice7WImpl_EnumEffectsInFile,
1083 IDirectInputDevice7WImpl_WriteEffectToFile,
1084 IDirectInputDevice8WImpl_BuildActionMap,
1085 IDirectInputDevice8WImpl_SetActionMap,
1086 IDirectInputDevice8WImpl_GetImageInfo
1090 #else /* HAVE_CORRECT_LINUXINPUT_H */
1092 const struct dinput_device joystick_linuxinput_device = {
1093 "Wine Linux-input joystick driver",
1100 #endif /* HAVE_CORRECT_LINUXINPUT_H */