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"
25 #ifdef HAVE_LINUX_INPUT_H
35 #ifdef HAVE_SYS_TIME_H
36 # include <sys/time.h>
38 #include <sys/fcntl.h>
39 #ifdef HAVE_SYS_IOCTL_H
40 # include <sys/ioctl.h>
43 #ifdef HAVE_SYS_ERRNO_H
44 # include <sys/errno.h>
47 #ifdef HAVE_CORRECT_LINUXINPUT_H
49 #ifdef HAVE_LINUX_INPUT_H
50 # include <linux/input.h>
54 #define EVDEVPREFIX "/dev/input/event"
56 #include "wine/debug.h"
57 #include "wine/unicode.h"
63 #include "dinput_private.h"
64 #include "device_private.h"
66 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
68 /* Wine joystick driver object instances */
69 #define WINE_JOYSTICK_AXIS_BASE 0
70 #define WINE_JOYSTICK_BUTTON_BASE 8
72 typedef struct JoystickImpl JoystickImpl;
73 static IDirectInputDevice8AVtbl JoystickAvt;
74 static IDirectInputDevice8WVtbl JoystickWvt;
82 /* The 'parent' DInput */
83 IDirectInputImpl *dinput;
85 /* joystick private */
86 /* what range and deadzone the game wants */
87 LONG wantmin[ABS_MAX];
88 LONG wantmax[ABS_MAX];
91 /* autodetecting ranges per axe by following movement */
92 LONG havemax[ABS_MAX];
93 LONG havemin[ABS_MAX];
99 LPDIDEVICEOBJECTDATA data_queue;
100 int queue_head, queue_tail, queue_len;
104 /* data returned by the EVIOCGABS() ioctl */
105 int axes[ABS_MAX+1][5];
110 #define AXE_ABSFUZZ 3
111 #define AXE_ABSFLAT 4
114 /* data returned by EVIOCGBIT for EV_ABS and EV_KEY */
115 BYTE absbits[(ABS_MAX+7)/8];
116 BYTE keybits[(KEY_MAX+7)/8];
119 /* This GUID is slightly different from the linux joystick one. Take note. */
120 static GUID DInput_Wine_Joystick_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
124 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
127 static void fake_current_js_state(JoystickImpl *ji);
129 #define test_bit(arr,bit) (((BYTE*)arr)[bit>>3]&(1<<(bit&7)))
131 static int joydev_have(void)
138 BYTE absbits[(ABS_MAX+7)/8],keybits[(KEY_MAX+7)/8];
140 sprintf(buf,EVDEVPREFIX"%d",i);
141 if (-1!=(fd=open(buf,O_RDONLY))) {
142 if (-1==ioctl(fd,EVIOCGBIT(EV_ABS,sizeof(absbits)),absbits)) {
143 perror("EVIOCGBIT EV_ABS");
147 if (-1==ioctl(fd,EVIOCGBIT(EV_KEY,sizeof(keybits)),keybits)) {
148 perror("EVIOCGBIT EV_KEY");
152 /* A true joystick has at least axis X and Y, and at least 1
153 * button. copied from linux/drivers/input/joydev.c */
154 if (test_bit(absbits,ABS_X) && test_bit(absbits,ABS_Y) &&
155 ( test_bit(keybits,BTN_TRIGGER) ||
156 test_bit(keybits,BTN_A) ||
157 test_bit(keybits,BTN_1)
160 FIXME("found a joystick at %s!\n",buf);
165 if (havejoy || (errno==ENODEV))
171 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, int version, int id)
178 if (!((dwDevType == 0) ||
179 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 8)) ||
180 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 8))))
183 if (dwFlags & DIEDFL_FORCEFEEDBACK)
186 havejoy = joydev_have();
191 TRACE("Enumerating the linuxinput Joystick device\n");
193 /* Return joystick */
194 lpddi->guidInstance = GUID_Joystick;
195 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
197 lpddi->guidFFDriver = GUID_NULL;
199 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
201 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
203 strcpy(lpddi->tszInstanceName, "Joystick");
204 /* ioctl JSIOCGNAME(len) */
205 strcpy(lpddi->tszProductName, "Wine Joystick");
209 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, int version, int id)
216 if (!((dwDevType == 0) ||
217 ((dwDevType == DIDEVTYPE_JOYSTICK) && (version < 8)) ||
218 (((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 8))))
221 if (dwFlags & DIEDFL_FORCEFEEDBACK)
224 havejoy = joydev_have();
229 TRACE("Enumerating the linuxinput Joystick device\n");
231 /* Return joystick */
232 lpddi->guidInstance = GUID_Joystick;
233 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
235 lpddi->guidFFDriver = GUID_NULL;
237 lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
239 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
241 MultiByteToWideChar(CP_ACP, 0, "Joystick", -1, lpddi->tszInstanceName, MAX_PATH);
242 /* ioctl JSIOCGNAME(len) */
243 MultiByteToWideChar(CP_ACP, 0, "Wine Joystick", -1, lpddi->tszProductName, MAX_PATH);
247 static JoystickImpl *alloc_device(REFGUID rguid, LPVOID jvt, IDirectInputImpl *dinput)
249 JoystickImpl* newDevice;
252 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
253 newDevice->lpVtbl = jvt;
255 newDevice->joyfd = -1;
256 newDevice->dinput = dinput;
257 memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
258 for (i=0;i<ABS_MAX;i++) {
259 newDevice->wantmin[i] = -32768;
260 newDevice->wantmax[i] = 32767;
262 * direct input defines a default for the deadzone somewhere; but as long
263 * as in map_axis the code for the dead zone is commented out its no
266 newDevice->deadz[i] = 0;
268 fake_current_js_state(newDevice);
272 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
276 havejoy = joydev_have();
279 return DIERR_DEVICENOTREG;
281 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
282 (IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) {
283 if ((riid == NULL) ||
284 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
285 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
286 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
287 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
288 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput);
289 TRACE("Creating a Joystick device (%p)\n", *pdev);
292 return DIERR_NOINTERFACE;
295 return DIERR_DEVICENOTREG;
299 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
303 havejoy = joydev_have();
306 return DIERR_DEVICENOTREG;
308 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
309 (IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) {
310 if ((riid == NULL) ||
311 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
312 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
313 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
314 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
315 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput);
316 TRACE("Creating a Joystick device (%p)\n", *pdev);
319 return DIERR_NOINTERFACE;
322 return DIERR_DEVICENOTREG;
325 static dinput_device joydev = {
327 "Wine Linux-input joystick driver",
330 joydev_create_deviceA,
331 joydev_create_deviceW
334 DECL_GLOBAL_CONSTRUCTOR(joydev_register) { dinput_register_device(&joydev); }
336 /******************************************************************************
339 static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
341 JoystickImpl *This = (JoystickImpl *)iface;
344 ref = InterlockedDecrement(&(This->ref));
348 /* Free the data queue */
349 HeapFree(GetProcessHeap(),0,This->data_queue);
351 /* Free the DataFormat */
352 HeapFree(GetProcessHeap(), 0, This->df);
354 HeapFree(GetProcessHeap(),0,This);
358 /******************************************************************************
359 * SetDataFormat : the application can choose the format of the data
360 * the device driver sends back with GetDeviceState.
362 static HRESULT WINAPI JoystickAImpl_SetDataFormat(
363 LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
366 JoystickImpl *This = (JoystickImpl *)iface;
368 TRACE("(this=%p,%p)\n",This,df);
370 _dump_DIDATAFORMAT(df);
372 /* Store the new data format */
373 This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
374 memcpy(This->df, df, df->dwSize);
375 This->df->rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
376 memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
381 /******************************************************************************
382 * Acquire : gets exclusive control of the joystick
384 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
387 JoystickImpl *This = (JoystickImpl *)iface;
390 TRACE("(this=%p)\n",This);
394 sprintf(buf,EVDEVPREFIX"%d",i);
395 if (-1==(This->joyfd=open(buf,O_RDONLY))) {
397 return DIERR_NOTFOUND;
401 if ((-1!=ioctl(This->joyfd,EVIOCGBIT(EV_ABS,sizeof(This->absbits)),This->absbits)) &&
402 (-1!=ioctl(This->joyfd,EVIOCGBIT(EV_KEY,sizeof(This->keybits)),This->keybits)) &&
403 (test_bit(This->absbits,ABS_X) && test_bit(This->absbits,ABS_Y) &&
404 (test_bit(This->keybits,BTN_TRIGGER)||
405 test_bit(This->keybits,BTN_A) ||
406 test_bit(This->keybits,BTN_1)
415 return DIERR_NOTFOUND;
417 for (i=0;i<ABS_MAX;i++) {
418 if (test_bit(This->absbits,i)) {
419 if (-1==ioctl(This->joyfd,EVIOCGABS(i),&(This->axes[i])))
421 FIXME("axe %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
423 This->axes[i][AXE_ABS],
424 This->axes[i][AXE_ABSMIN],
425 This->axes[i][AXE_ABSMAX],
426 This->axes[i][AXE_ABSFUZZ],
427 This->axes[i][AXE_ABSFLAT]
429 This->havemin[i] = This->axes[i][AXE_ABSMIN];
430 This->havemax[i] = This->axes[i][AXE_ABSMAX];
435 fake_current_js_state(This);
440 /******************************************************************************
441 * Unacquire : frees the joystick
443 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
445 JoystickImpl *This = (JoystickImpl *)iface;
447 TRACE("(this=%p)\n",This);
448 if (This->joyfd!=-1) {
458 * This maps the read value (from the input event) to a value in the
459 * 'wanted' range. It also autodetects the possible range of the axe and
460 * adapts values accordingly.
463 map_axis(JoystickImpl* This, int axis, int val) {
464 int xmin = This->axes[axis][AXE_ABSMIN];
465 int xmax = This->axes[axis][AXE_ABSMAX];
466 int hmax = This->havemax[axis];
467 int hmin = This->havemin[axis];
468 int wmin = This->wantmin[axis];
469 int wmax = This->wantmax[axis];
472 if (val > hmax) This->havemax[axis] = hmax = val;
473 if (val < hmin) This->havemin[axis] = hmin = val;
475 if (xmin == xmax) return val;
477 /* map the value from the hmin-hmax range into the wmin-wmax range */
478 ret = (val * (wmax-wmin)) / (hmax-hmin) + wmin;
481 /* deadzone doesn't work comfortably enough right now. needs more testing*/
482 if ((ret > -deadz/2 ) && (ret < deadz/2)) {
483 FIXME("%d in deadzone, return mid.\n",val);
484 return (wmax-wmin)/2+wmin;
491 * set the current state of the js device as it would be with the middle
494 static void fake_current_js_state(JoystickImpl *ji)
496 ji->js.lX = map_axis(ji, ABS_X, ji->axes[ABS_X ][AXE_ABS]);
497 ji->js.lY = map_axis(ji, ABS_Y, ji->axes[ABS_Y ][AXE_ABS]);
498 ji->js.lZ = map_axis(ji, ABS_Z, ji->axes[ABS_Z ][AXE_ABS]);
499 ji->js.lRx = map_axis(ji, ABS_RX, ji->axes[ABS_RX][AXE_ABS]);
500 ji->js.lRy = map_axis(ji, ABS_RY, ji->axes[ABS_RY][AXE_ABS]);
501 ji->js.lRz = map_axis(ji, ABS_RZ, ji->axes[ABS_RZ][AXE_ABS]);
504 static void joy_polldev(JoystickImpl *This) {
507 struct input_event ie;
513 memset(&tv,0,sizeof(tv));
515 FD_SET(This->joyfd,&readfds);
517 if (1>select(This->joyfd+1,&readfds,NULL,NULL,&tv))
520 /* we have one event, so we can read */
521 if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
524 TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
526 case EV_KEY: /* button */
528 case BTN_TRIGGER: /* normal flight stick */
529 case BTN_A: /* gamepad */
530 case BTN_1: /* generic */
531 This->js.rgbButtons[0] = ie.value?0x80:0x00;
532 GEN_EVENT(DIJOFS_BUTTON(0),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
537 This->js.rgbButtons[1] = ie.value?0x80:0x00;
538 GEN_EVENT(DIJOFS_BUTTON(1),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
543 This->js.rgbButtons[2] = ie.value?0x80:0x00;
544 GEN_EVENT(DIJOFS_BUTTON(2),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
549 This->js.rgbButtons[3] = ie.value?0x80:0x00;
550 GEN_EVENT(DIJOFS_BUTTON(3),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
555 This->js.rgbButtons[4] = ie.value?0x80:0x00;
556 GEN_EVENT(DIJOFS_BUTTON(4),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
561 This->js.rgbButtons[5] = ie.value?0x80:0x00;
562 GEN_EVENT(DIJOFS_BUTTON(5),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
567 This->js.rgbButtons[6] = ie.value?0x80:0x00;
568 GEN_EVENT(DIJOFS_BUTTON(6),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
573 This->js.rgbButtons[7] = ie.value?0x80:0x00;
574 GEN_EVENT(DIJOFS_BUTTON(7),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
579 This->js.rgbButtons[8] = ie.value?0x80:0x00;
580 GEN_EVENT(DIJOFS_BUTTON(8),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
584 This->js.rgbButtons[9] = ie.value?0x80:0x00;
585 GEN_EVENT(DIJOFS_BUTTON(9),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
589 This->js.rgbButtons[10] = ie.value?0x80:0x00;
590 GEN_EVENT(DIJOFS_BUTTON(10),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
593 FIXME("unhandled joystick button %x, value %d\n",ie.code,ie.value);
600 This->js.lX = map_axis(This,ABS_X,ie.value);
601 GEN_EVENT(DIJOFS_X,This->js.lX,ie.time.tv_usec,(This->dinput->evsequence)++);
604 This->js.lY = map_axis(This,ABS_Y,ie.value);
605 GEN_EVENT(DIJOFS_Y,This->js.lY,ie.time.tv_usec,(This->dinput->evsequence)++);
608 This->js.lZ = map_axis(This,ABS_Z,ie.value);
609 GEN_EVENT(DIJOFS_Z,This->js.lZ,ie.time.tv_usec,(This->dinput->evsequence)++);
612 This->js.lRx = map_axis(This,ABS_RX,ie.value);
613 GEN_EVENT(DIJOFS_RX,This->js.lRx,ie.time.tv_usec,(This->dinput->evsequence)++);
616 This->js.lRy = map_axis(This,ABS_RY,ie.value);
617 GEN_EVENT(DIJOFS_RY,This->js.lRy,ie.time.tv_usec,(This->dinput->evsequence)++);
620 This->js.lRz = map_axis(This,ABS_RZ,ie.value);
621 GEN_EVENT(DIJOFS_RZ,This->js.lRz,ie.time.tv_usec,(This->dinput->evsequence)++);
624 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie.code,ie.value);
629 FIXME("joystick cannot handle type %d event (code %d)\n",ie.type,ie.code);
635 /******************************************************************************
636 * GetDeviceState : returns the "state" of the joystick.
639 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
640 LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
642 JoystickImpl *This = (JoystickImpl *)iface;
646 TRACE("(this=%p,0x%08lx,%p)\n",This,len,ptr);
647 if ((len != sizeof(DIJOYSTATE)) && (len != sizeof(DIJOYSTATE2))) {
648 FIXME("len %ld is not sizeof(DIJOYSTATE) or DIJOYSTATE2, unsupported format.\n",len);
651 memcpy(ptr,&(This->js),len);
652 This->queue_head = 0;
653 This->queue_tail = 0;
657 /******************************************************************************
658 * GetDeviceData : gets buffered input data.
660 static HRESULT WINAPI JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
662 LPDIDEVICEOBJECTDATA dod,
666 JoystickImpl *This = (JoystickImpl *)iface;
668 FIXME("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx),STUB!\n",This,dodsize,*entries,flags);
671 if (flags & DIGDD_PEEK)
672 FIXME("DIGDD_PEEK\n");
680 /******************************************************************************
681 * SetProperty : change input device properties
683 static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
687 JoystickImpl *This = (JoystickImpl *)iface;
689 FIXME("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
690 FIXME("ph.dwSize = %ld, ph.dwHeaderSize =%ld, ph.dwObj = %ld, ph.dwHow= %ld\n",ph->dwSize, ph->dwHeaderSize,ph->dwObj,ph->dwHow);
692 if (!HIWORD(rguid)) {
693 switch ((DWORD)rguid) {
694 case (DWORD) DIPROP_BUFFERSIZE: {
695 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
697 FIXME("buffersize = %ld\n",pd->dwData);
700 case (DWORD)DIPROP_RANGE: {
701 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
703 FIXME("proprange(%ld,%ld)\n",pr->lMin,pr->lMax);
711 This->wantmin[ph->dwObj/4] = pr->lMin;
712 This->wantmax[ph->dwObj/4] = pr->lMax;
715 FIXME("setting proprange %ld - %ld for dwObj %ld\n",pr->lMin,pr->lMax,ph->dwObj);
719 case (DWORD)DIPROP_DEADZONE: {
720 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
722 FIXME("setting deadzone(%ld)\n",pd->dwData);
723 This->deadz[ph->dwObj/4] = pd->dwData;
727 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
731 fake_current_js_state(This);
735 /******************************************************************************
736 * SetEventNotification : specifies event to be sent on state change
738 static HRESULT WINAPI JoystickAImpl_SetEventNotification(
739 LPDIRECTINPUTDEVICE8A iface, HANDLE hnd
741 JoystickImpl *This = (JoystickImpl *)iface;
743 TRACE("(this=%p,0x%08lx)\n",This,(DWORD)hnd);
748 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
749 LPDIRECTINPUTDEVICE8A iface,
750 LPDIDEVCAPS lpDIDevCaps)
752 JoystickImpl *This = (JoystickImpl *)iface;
753 int xfd = This->joyfd;
757 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
759 /* yes, games assume we return something, even if unacquired */
760 JoystickAImpl_Acquire(iface);
764 lpDIDevCaps->dwFlags = DIDC_ATTACHED;
765 if (This->dinput->version >= 8)
766 lpDIDevCaps->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
768 lpDIDevCaps->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
771 for (i=0;i<ABS_MAX;i++) if (test_bit(This->absbits,i)) axes++;
773 for (i=0;i<KEY_MAX;i++) if (test_bit(This->keybits,i)) buttons++;
775 lpDIDevCaps->dwAxes = axes;
776 lpDIDevCaps->dwButtons = buttons;
779 JoystickAImpl_Unacquire(iface);
784 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface) {
785 JoystickImpl *This = (JoystickImpl *)iface;
792 /******************************************************************************
793 * EnumObjects : enumerate the different buttons and axis...
795 static HRESULT WINAPI JoystickAImpl_EnumObjects(
796 LPDIRECTINPUTDEVICE8A iface,
797 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
801 JoystickImpl *This = (JoystickImpl *)iface;
802 DIDEVICEOBJECTINSTANCEA ddoi;
803 int xfd = This->joyfd;
806 TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
807 if (TRACE_ON(dinput)) {
808 TRACE(" - flags = ");
809 _dump_EnumObjects_flags(dwFlags);
813 if (xfd == -1) return DIERR_NOTACQUIRED;
815 /* Only the fields till dwFFMaxForce are relevant */
816 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
818 /* For the joystick, do as is done in the GetCapabilities function */
819 /* FIXME: needs more items */
820 if ((dwFlags == DIDFT_ALL) ||
821 (dwFlags & DIDFT_AXIS)) {
824 for (i = 0; i < ABS_MAX; i++) {
825 if (!test_bit(This->absbits,i)) continue;
829 ddoi.guidType = GUID_XAxis;
830 ddoi.dwOfs = DIJOFS_X;
833 ddoi.guidType = GUID_YAxis;
834 ddoi.dwOfs = DIJOFS_Y;
837 ddoi.guidType = GUID_ZAxis;
838 ddoi.dwOfs = DIJOFS_Z;
841 ddoi.guidType = GUID_RxAxis;
842 ddoi.dwOfs = DIJOFS_RX;
845 ddoi.guidType = GUID_RyAxis;
846 ddoi.dwOfs = DIJOFS_RY;
849 ddoi.guidType = GUID_RzAxis;
850 ddoi.dwOfs = DIJOFS_RZ;
853 ddoi.guidType = GUID_Slider;
854 ddoi.dwOfs = DIJOFS_SLIDER(0);
857 FIXME("unhandled abs axis %d, ignoring!\n",i);
859 ddoi.dwType = DIDFT_MAKEINSTANCE((1<<i) << WINE_JOYSTICK_AXIS_BASE) | DIDFT_ABSAXIS;
860 sprintf(ddoi.tszName, "%d-Axis", i);
861 _dump_OBJECTINSTANCEA(&ddoi);
862 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE)
867 if ((dwFlags == DIDFT_ALL) ||
868 (dwFlags & DIDFT_BUTTON)) {
871 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
873 ddoi.guidType = GUID_Button;
875 for (i = 0; i < KEY_MAX; i++) {
876 if (!test_bit(This->keybits,i)) continue;
882 ddoi.dwOfs = DIJOFS_BUTTON(0);
883 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 0) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
888 ddoi.dwOfs = DIJOFS_BUTTON(1);
889 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 1) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
894 ddoi.dwOfs = DIJOFS_BUTTON(2);
895 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 2) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
900 ddoi.dwOfs = DIJOFS_BUTTON(3);
901 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 3) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
906 ddoi.dwOfs = DIJOFS_BUTTON(4);
907 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 4) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
912 ddoi.dwOfs = DIJOFS_BUTTON(5);
913 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 5) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
918 ddoi.dwOfs = DIJOFS_BUTTON(6);
919 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 6) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
924 ddoi.dwOfs = DIJOFS_BUTTON(7);
925 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 7) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
930 ddoi.dwOfs = DIJOFS_BUTTON(8);
931 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 8) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
935 ddoi.dwOfs = DIJOFS_BUTTON(9);
936 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 9) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
940 ddoi.dwOfs = DIJOFS_BUTTON(10);
941 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 10) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
944 sprintf(ddoi.tszName, "%d-Button", i);
945 _dump_OBJECTINSTANCEA(&ddoi);
946 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE)
951 if (xfd!=This->joyfd)
957 static HRESULT WINAPI JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
958 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
962 JoystickImpl *This = (JoystickImpl *)iface;
964 device_enumobjects_AtoWcb_data data;
966 data.lpCallBack = lpCallback;
967 data.lpvRef = lpvRef;
969 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
972 /******************************************************************************
973 * GetProperty : get input device properties
975 static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
977 LPDIPROPHEADER pdiph)
979 JoystickImpl *This = (JoystickImpl *)iface;
981 TRACE("(this=%p,%s,%p): stub!\n",
982 iface, debugstr_guid(rguid), pdiph);
984 if (TRACE_ON(dinput))
985 _dump_DIPROPHEADER(pdiph);
987 if (!HIWORD(rguid)) {
988 switch ((DWORD)rguid) {
989 case (DWORD) DIPROP_BUFFERSIZE: {
990 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
992 TRACE(" return buffersize = %d\n",This->queue_len);
993 pd->dwData = This->queue_len;
997 case (DWORD) DIPROP_RANGE: {
998 /* LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph; */
999 if ((pdiph->dwHow == DIPH_BYID) &&
1000 (pdiph->dwObj & DIDFT_ABSAXIS)) {
1001 /* The app is querying the current range of the axis : return the lMin and lMax values */
1002 FIXME("unimplemented axis range query.\n");
1009 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
1018 static IDirectInputDevice8AVtbl JoystickAvt =
1020 IDirectInputDevice2AImpl_QueryInterface,
1021 IDirectInputDevice2AImpl_AddRef,
1022 JoystickAImpl_Release,
1023 JoystickAImpl_GetCapabilities,
1024 JoystickAImpl_EnumObjects,
1025 JoystickAImpl_GetProperty,
1026 JoystickAImpl_SetProperty,
1027 JoystickAImpl_Acquire,
1028 JoystickAImpl_Unacquire,
1029 JoystickAImpl_GetDeviceState,
1030 JoystickAImpl_GetDeviceData,
1031 JoystickAImpl_SetDataFormat,
1032 JoystickAImpl_SetEventNotification,
1033 IDirectInputDevice2AImpl_SetCooperativeLevel,
1034 IDirectInputDevice2AImpl_GetObjectInfo,
1035 IDirectInputDevice2AImpl_GetDeviceInfo,
1036 IDirectInputDevice2AImpl_RunControlPanel,
1037 IDirectInputDevice2AImpl_Initialize,
1038 IDirectInputDevice2AImpl_CreateEffect,
1039 IDirectInputDevice2AImpl_EnumEffects,
1040 IDirectInputDevice2AImpl_GetEffectInfo,
1041 IDirectInputDevice2AImpl_GetForceFeedbackState,
1042 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1043 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1044 IDirectInputDevice2AImpl_Escape,
1046 IDirectInputDevice2AImpl_SendDeviceData,
1047 IDirectInputDevice7AImpl_EnumEffectsInFile,
1048 IDirectInputDevice7AImpl_WriteEffectToFile,
1049 IDirectInputDevice8AImpl_BuildActionMap,
1050 IDirectInputDevice8AImpl_SetActionMap,
1051 IDirectInputDevice8AImpl_GetImageInfo
1054 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1055 # define XCAST(fun) (typeof(JoystickWvt.fun))
1057 # define XCAST(fun) (void*)
1060 static IDirectInputDevice8WVtbl JoystickWvt =
1062 IDirectInputDevice2WImpl_QueryInterface,
1063 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1064 XCAST(Release)JoystickAImpl_Release,
1065 XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1066 JoystickWImpl_EnumObjects,
1067 XCAST(GetProperty)JoystickAImpl_GetProperty,
1068 XCAST(SetProperty)JoystickAImpl_SetProperty,
1069 XCAST(Acquire)JoystickAImpl_Acquire,
1070 XCAST(Unacquire)JoystickAImpl_Unacquire,
1071 XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1072 XCAST(GetDeviceData)JoystickAImpl_GetDeviceData,
1073 XCAST(SetDataFormat)JoystickAImpl_SetDataFormat,
1074 XCAST(SetEventNotification)JoystickAImpl_SetEventNotification,
1075 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1076 IDirectInputDevice2WImpl_GetObjectInfo,
1077 IDirectInputDevice2WImpl_GetDeviceInfo,
1078 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1079 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1080 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
1081 IDirectInputDevice2WImpl_EnumEffects,
1082 IDirectInputDevice2WImpl_GetEffectInfo,
1083 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
1084 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1085 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1086 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1087 XCAST(Poll)JoystickAImpl_Poll,
1088 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1089 IDirectInputDevice7WImpl_EnumEffectsInFile,
1090 IDirectInputDevice7WImpl_WriteEffectToFile,
1091 IDirectInputDevice8WImpl_BuildActionMap,
1092 IDirectInputDevice8WImpl_SetActionMap,
1093 IDirectInputDevice8WImpl_GetImageInfo
1097 #endif /* HAVE_LINUX_INPUT_H */