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 ICOM_VTABLE(IDirectInputDevice8A) JoystickAvt;
74 static ICOM_VTABLE(IDirectInputDevice8W) 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;
103 /* data returned by the EVIOCGABS() ioctl */
104 int axes[ABS_MAX+1][5];
109 #define AXE_ABSFUZZ 3
110 #define AXE_ABSFLAT 4
113 /* data returned by EVIOCGBIT for EV_ABS and EV_KEY */
114 BYTE absbits[(ABS_MAX+7)/8];
115 BYTE keybits[(KEY_MAX+7)/8];
118 /* This GUID is slightly different from the linux joystick one. Take note. */
119 static GUID DInput_Wine_Joystick_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
123 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
126 #define test_bit(arr,bit) (((BYTE*)arr)[bit>>3]&(1<<(bit&7)))
128 static int joydev_have(void)
135 BYTE absbits[(ABS_MAX+7)/8],keybits[(KEY_MAX+7)/8];
137 sprintf(buf,EVDEVPREFIX"%d",i);
138 if (-1!=(fd=open(buf,O_RDONLY))) {
139 if (-1==ioctl(fd,EVIOCGBIT(EV_ABS,sizeof(absbits)),absbits)) {
140 perror("EVIOCGBIT EV_ABS");
144 if (-1==ioctl(fd,EVIOCGBIT(EV_KEY,sizeof(keybits)),keybits)) {
145 perror("EVIOCGBIT EV_KEY");
149 /* A true joystick has at least axis X and Y, and at least 1
150 * button. copied from linux/drivers/input/joydev.c */
151 if (test_bit(absbits,ABS_X) && test_bit(absbits,ABS_Y) &&
152 ( test_bit(keybits,BTN_TRIGGER) ||
153 test_bit(keybits,BTN_A) ||
154 test_bit(keybits,BTN_1)
157 FIXME("found a joystick at %s!\n",buf);
162 if (havejoy || (errno==ENODEV))
168 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, int version)
172 if ((dwDevType != 0) && (GET_DIDEVICE_TYPE(dwDevType) != DIDEVTYPE_JOYSTICK))
175 if (dwFlags & DIEDFL_FORCEFEEDBACK)
178 havejoy = joydev_have();
183 TRACE("Enumerating the linuxinput Joystick device\n");
185 /* Return joystick */
186 lpddi->guidInstance = GUID_Joystick;
187 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
189 lpddi->guidFFDriver = GUID_NULL;
190 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL<<8);
192 strcpy(lpddi->tszInstanceName, "Joystick");
193 /* ioctl JSIOCGNAME(len) */
194 strcpy(lpddi->tszProductName, "Wine Joystick");
198 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, int version)
202 if ((dwDevType != 0) && (GET_DIDEVICE_TYPE(dwDevType) != DIDEVTYPE_JOYSTICK))
205 if (dwFlags & DIEDFL_FORCEFEEDBACK)
208 havejoy = joydev_have();
213 TRACE("Enumerating the linuxinput Joystick device\n");
215 /* Return joystick */
216 lpddi->guidInstance = GUID_Joystick;
217 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
219 lpddi->guidFFDriver = GUID_NULL;
220 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL<<8);
222 MultiByteToWideChar(CP_ACP, 0, "Joystick", -1, lpddi->tszInstanceName, MAX_PATH);
223 /* ioctl JSIOCGNAME(len) */
224 MultiByteToWideChar(CP_ACP, 0, "Wine Joystick", -1, lpddi->tszProductName, MAX_PATH);
228 static JoystickImpl *alloc_device(REFGUID rguid, LPVOID jvt, IDirectInputImpl *dinput)
230 JoystickImpl* newDevice;
233 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
234 newDevice->lpVtbl = jvt;
236 newDevice->joyfd = -1;
237 newDevice->dinput = dinput;
238 memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
239 for (i=0;i<ABS_MAX;i++) {
240 newDevice->wantmin[i] = -32768;
241 newDevice->wantmax[i] = 32767;
243 * direct input defines a default for the deadzone somewhere; but as long
244 * as in map_axis the code for the dead zone is commented out its no
247 newDevice->deadz[i] = 0;
252 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
256 havejoy = joydev_have();
259 return DIERR_DEVICENOTREG;
261 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
262 (IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) {
263 if ((riid == NULL) ||
264 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
265 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
266 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
267 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
268 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput);
269 TRACE("Creating a Joystick device (%p)\n", *pdev);
272 return DIERR_NOINTERFACE;
275 return DIERR_DEVICENOTREG;
279 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
283 havejoy = joydev_have();
286 return DIERR_DEVICENOTREG;
288 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
289 (IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) {
290 if ((riid == NULL) ||
291 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
292 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
293 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
294 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
295 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput);
296 TRACE("Creating a Joystick device (%p)\n", *pdev);
299 return DIERR_NOINTERFACE;
302 return DIERR_DEVICENOTREG;
305 static dinput_device joydev = {
309 joydev_create_deviceA,
310 joydev_create_deviceW
313 DECL_GLOBAL_CONSTRUCTOR(joydev_register) { dinput_register_device(&joydev); }
315 /******************************************************************************
318 static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
320 ICOM_THIS(JoystickImpl,iface);
326 /* Free the data queue */
327 if (This->data_queue != NULL)
328 HeapFree(GetProcessHeap(),0,This->data_queue);
330 /* Free the DataFormat */
331 HeapFree(GetProcessHeap(), 0, This->df);
333 HeapFree(GetProcessHeap(),0,This);
337 /******************************************************************************
338 * SetDataFormat : the application can choose the format of the data
339 * the device driver sends back with GetDeviceState.
341 static HRESULT WINAPI JoystickAImpl_SetDataFormat(
342 LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
345 ICOM_THIS(JoystickImpl,iface);
348 TRACE("(this=%p,%p)\n",This,df);
350 TRACE("(df.dwSize=%ld)\n",df->dwSize);
351 TRACE("(df.dwObjsize=%ld)\n",df->dwObjSize);
352 TRACE("(df.dwFlags=0x%08lx)\n",df->dwFlags);
353 TRACE("(df.dwDataSize=%ld)\n",df->dwDataSize);
354 TRACE("(df.dwNumObjs=%ld)\n",df->dwNumObjs);
356 for (i=0;i<df->dwNumObjs;i++) {
357 TRACE("df.rgodf[%d].guid %s (%p)\n",i,debugstr_guid(df->rgodf[i].pguid), df->rgodf[i].pguid);
358 TRACE("df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
359 TRACE("dwType 0x%02x,dwInstance %d\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
360 TRACE("df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
363 /* Store the new data format */
364 This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
365 memcpy(This->df, df, df->dwSize);
366 This->df->rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
367 memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
372 /******************************************************************************
373 * Acquire : gets exclusive control of the joystick
375 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
378 ICOM_THIS(JoystickImpl,iface);
381 TRACE("(this=%p)\n",This);
385 sprintf(buf,EVDEVPREFIX"%d",i);
386 if (-1==(This->joyfd=open(buf,O_RDONLY))) {
388 return DIERR_NOTFOUND;
392 if ((-1!=ioctl(This->joyfd,EVIOCGBIT(EV_ABS,sizeof(This->absbits)),This->absbits)) &&
393 (-1!=ioctl(This->joyfd,EVIOCGBIT(EV_KEY,sizeof(This->keybits)),This->keybits)) &&
394 (test_bit(This->absbits,ABS_X) && test_bit(This->absbits,ABS_Y) &&
395 (test_bit(This->keybits,BTN_TRIGGER)||
396 test_bit(This->keybits,BTN_A) ||
397 test_bit(This->keybits,BTN_1)
406 return DIERR_NOTFOUND;
408 for (i=0;i<ABS_MAX;i++) {
409 if (test_bit(This->absbits,i)) {
410 if (-1==ioctl(This->joyfd,EVIOCGABS(i),&(This->axes[i])))
412 FIXME("axe %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
414 This->axes[i][AXE_ABS],
415 This->axes[i][AXE_ABSMIN],
416 This->axes[i][AXE_ABSMAX],
417 This->axes[i][AXE_ABSFUZZ],
418 This->axes[i][AXE_ABSFLAT]
420 This->havemin[i] = This->axes[i][AXE_ABSMIN];
421 This->havemax[i] = This->axes[i][AXE_ABSMAX];
429 /******************************************************************************
430 * Unacquire : frees the joystick
432 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
434 ICOM_THIS(JoystickImpl,iface);
436 TRACE("(this=%p)\n",This);
437 if (This->joyfd!=-1) {
447 * This maps the read value (from the input event) to a value in the
448 * 'wanted' range. It also autodetects the possible range of the axe and
449 * adapts values accordingly.
452 map_axis(JoystickImpl* This, int axis, int val) {
453 int xmid = This->axes[axis][AXE_ABS];
454 int xmin = This->axes[axis][AXE_ABSMIN];
455 int xmax = This->axes[axis][AXE_ABSMAX];
456 int hmax = This->havemax[axis];
457 int hmin = This->havemin[axis];
458 int wmin = This->wantmin[axis];
459 int wmax = This->wantmax[axis];
462 if (val > hmax) This->havemax[axis] = hmax = val;
463 if (val < hmin) This->havemin[axis] = hmin = val;
465 if (xmin == xmax) return val;
466 if ((hmin == hmax) || (hmax==xmid) || (hmin==xmid)) return val;
468 /* map the value from the hmin-hmax range into the wmin-wmax range */
469 ret = (val * (wmax-wmin)) / (hmax-hmin) + wmin;
472 /* deadzone doesn't work comfortably enough right now. needs more testing*/
473 if ((ret > -deadz/2 ) && (ret < deadz/2)) {
474 FIXME("%d in deadzone, return mid.\n",val);
475 return (wmax-wmin)/2+wmin;
481 static void joy_polldev(JoystickImpl *This) {
484 struct input_event ie;
490 memset(&tv,0,sizeof(tv));
492 FD_SET(This->joyfd,&readfds);
494 if (1>select(This->joyfd+1,&readfds,NULL,NULL,&tv))
497 /* we have one event, so we can read */
498 if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
501 TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
503 case EV_KEY: /* button */
505 case BTN_TRIGGER: /* normal flight stick */
506 case BTN_A: /* gamepad */
507 case BTN_1: /* generic */
508 GEN_EVENT(DIJOFS_BUTTON(0),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
509 This->js.rgbButtons[0] = ie.value?0x80:0x00;
514 GEN_EVENT(DIJOFS_BUTTON(1),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
515 This->js.rgbButtons[1] = ie.value?0x80:0x00;
520 GEN_EVENT(DIJOFS_BUTTON(2),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
521 This->js.rgbButtons[2] = ie.value?0x80:0x00;
526 GEN_EVENT(DIJOFS_BUTTON(3),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
527 This->js.rgbButtons[3] = ie.value?0x80:0x00;
532 GEN_EVENT(DIJOFS_BUTTON(4),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
533 This->js.rgbButtons[4] = ie.value?0x80:0x00;
538 GEN_EVENT(DIJOFS_BUTTON(5),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
539 This->js.rgbButtons[5] = ie.value?0x80:0x00;
544 GEN_EVENT(DIJOFS_BUTTON(6),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
545 This->js.rgbButtons[6] = ie.value?0x80:0x00;
550 GEN_EVENT(DIJOFS_BUTTON(7),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
551 This->js.rgbButtons[7] = ie.value?0x80:0x00;
556 GEN_EVENT(DIJOFS_BUTTON(8),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
557 This->js.rgbButtons[8] = ie.value?0x80:0x00;
561 GEN_EVENT(DIJOFS_BUTTON(9),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
562 This->js.rgbButtons[9] = ie.value?0x80:0x00;
566 GEN_EVENT(DIJOFS_BUTTON(10),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
567 This->js.rgbButtons[10] = ie.value?0x80:0x00;
570 FIXME("unhandled joystick button %x, value %d\n",ie.code,ie.value);
577 GEN_EVENT(DIJOFS_X,ie.value,ie.time.tv_usec,(This->dinput->evsequence)++);
578 This->js.lX = map_axis(This,0,ie.value);
581 GEN_EVENT(DIJOFS_Y,ie.value,ie.time.tv_usec,(This->dinput->evsequence)++);
582 This->js.lY = map_axis(This,1,ie.value);
585 GEN_EVENT(DIJOFS_Z,ie.value,ie.time.tv_usec,(This->dinput->evsequence)++);
586 This->js.lZ = map_axis(This,2,ie.value);
589 GEN_EVENT(DIJOFS_RX,ie.value,ie.time.tv_usec,(This->dinput->evsequence)++);
590 This->js.lRx = map_axis(This,3,ie.value);
593 GEN_EVENT(DIJOFS_RY,ie.value,ie.time.tv_usec,(This->dinput->evsequence)++);
594 This->js.lRy = map_axis(This,4,ie.value);
597 GEN_EVENT(DIJOFS_RZ,ie.value,ie.time.tv_usec,(This->dinput->evsequence)++);
598 This->js.lRz = map_axis(This,5,ie.value);
601 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie.code,ie.value);
606 FIXME("joystick cannot handle type %d event (code %d)\n",ie.type,ie.code);
612 /******************************************************************************
613 * GetDeviceState : returns the "state" of the joystick.
616 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
617 LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
619 ICOM_THIS(JoystickImpl,iface);
623 TRACE("(this=%p,0x%08lx,%p)\n",This,len,ptr);
624 if ((len != sizeof(DIJOYSTATE)) && (len != sizeof(DIJOYSTATE2))) {
625 FIXME("len %ld is not sizeof(DIJOYSTATE) or DIJOYSTATE2, unsupported format.\n",len);
628 memcpy(ptr,&(This->js),len);
629 This->queue_head = 0;
630 This->queue_tail = 0;
634 /******************************************************************************
635 * GetDeviceData : gets buffered input data.
637 static HRESULT WINAPI JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
639 LPDIDEVICEOBJECTDATA dod,
643 ICOM_THIS(JoystickImpl,iface);
645 FIXME("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx),STUB!\n",This,dodsize,*entries,flags);
648 if (flags & DIGDD_PEEK)
649 FIXME("DIGDD_PEEK\n");
657 /******************************************************************************
658 * SetProperty : change input device properties
660 static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
664 ICOM_THIS(JoystickImpl,iface);
666 FIXME("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
667 FIXME("ph.dwSize = %ld, ph.dwHeaderSize =%ld, ph.dwObj = %ld, ph.dwHow= %ld\n",ph->dwSize, ph->dwHeaderSize,ph->dwObj,ph->dwHow);
669 if (!HIWORD(rguid)) {
670 switch ((DWORD)rguid) {
671 case (DWORD) DIPROP_BUFFERSIZE: {
672 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
674 FIXME("buffersize = %ld\n",pd->dwData);
677 case (DWORD)DIPROP_RANGE: {
678 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
680 FIXME("proprange(%ld,%ld)\n",pr->lMin,pr->lMax);
688 This->wantmin[ph->dwObj/4] = pr->lMin;
689 This->wantmax[ph->dwObj/4] = pr->lMax;
692 FIXME("setting proprange %ld - %ld for dwObj %ld\n",pr->lMin,pr->lMax,ph->dwObj);
696 case (DWORD)DIPROP_DEADZONE: {
697 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
699 FIXME("setting deadzone(%ld)\n",pd->dwData);
700 This->deadz[ph->dwObj/4] = pd->dwData;
704 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
711 /******************************************************************************
712 * SetEventNotification : specifies event to be sent on state change
714 static HRESULT WINAPI JoystickAImpl_SetEventNotification(
715 LPDIRECTINPUTDEVICE8A iface, HANDLE hnd
717 ICOM_THIS(JoystickImpl,iface);
719 TRACE("(this=%p,0x%08lx)\n",This,(DWORD)hnd);
724 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
725 LPDIRECTINPUTDEVICE8A iface,
726 LPDIDEVCAPS lpDIDevCaps)
728 ICOM_THIS(JoystickImpl,iface);
729 int xfd = This->joyfd;
733 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
735 /* yes, games assume we return something, even if unacquired */
736 JoystickAImpl_Acquire(iface);
740 lpDIDevCaps->dwFlags = DIDC_ATTACHED;
741 lpDIDevCaps->dwDevType = DIDEVTYPE_JOYSTICK;
744 for (i=0;i<ABS_MAX;i++) if (test_bit(This->absbits,i)) axes++;
746 for (i=0;i<KEY_MAX;i++) if (test_bit(This->keybits,i)) buttons++;
748 lpDIDevCaps->dwAxes = axes;
749 lpDIDevCaps->dwButtons = buttons;
752 JoystickAImpl_Unacquire(iface);
757 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface) {
758 ICOM_THIS(JoystickImpl,iface);
765 /******************************************************************************
766 * EnumObjects : enumerate the different buttons and axis...
768 static HRESULT WINAPI JoystickAImpl_EnumObjects(
769 LPDIRECTINPUTDEVICE8A iface,
770 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
774 ICOM_THIS(JoystickImpl,iface);
775 DIDEVICEOBJECTINSTANCEA ddoi;
776 int xfd = This->joyfd;
779 TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
780 if (TRACE_ON(dinput)) {
781 TRACE(" - flags = ");
782 _dump_EnumObjects_flags(dwFlags);
786 if (xfd == -1) return DIERR_NOTACQUIRED;
788 /* Only the fields till dwFFMaxForce are relevant */
789 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
791 /* For the joystick, do as is done in the GetCapabilities function */
792 /* FIXME: needs more items */
793 if ((dwFlags == DIDFT_ALL) ||
794 (dwFlags & DIDFT_AXIS)) {
797 for (i = 0; i < ABS_MAX; i++) {
798 if (!test_bit(This->absbits,i)) continue;
802 ddoi.guidType = GUID_XAxis;
803 ddoi.dwOfs = DIJOFS_X;
806 ddoi.guidType = GUID_YAxis;
807 ddoi.dwOfs = DIJOFS_Y;
810 ddoi.guidType = GUID_ZAxis;
811 ddoi.dwOfs = DIJOFS_Z;
814 ddoi.guidType = GUID_RxAxis;
815 ddoi.dwOfs = DIJOFS_RX;
818 ddoi.guidType = GUID_RyAxis;
819 ddoi.dwOfs = DIJOFS_RY;
822 ddoi.guidType = GUID_RzAxis;
823 ddoi.dwOfs = DIJOFS_RZ;
826 ddoi.guidType = GUID_Slider;
827 ddoi.dwOfs = DIJOFS_SLIDER(0);
830 FIXME("unhandled abs axis %d, ignoring!\n",i);
832 ddoi.dwType = DIDFT_MAKEINSTANCE((1<<i) << WINE_JOYSTICK_AXIS_BASE) | DIDFT_ABSAXIS;
833 sprintf(ddoi.tszName, "%d-Axis", i);
834 _dump_OBJECTINSTANCEA(&ddoi);
835 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE)
840 if ((dwFlags == DIDFT_ALL) ||
841 (dwFlags & DIDFT_BUTTON)) {
844 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
846 ddoi.guidType = GUID_Button;
848 for (i = 0; i < KEY_MAX; i++) {
849 if (!test_bit(This->keybits,i)) continue;
855 ddoi.dwOfs = DIJOFS_BUTTON(0);
856 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 0) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
861 ddoi.dwOfs = DIJOFS_BUTTON(1);
862 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 1) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
867 ddoi.dwOfs = DIJOFS_BUTTON(2);
868 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 2) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
873 ddoi.dwOfs = DIJOFS_BUTTON(3);
874 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 3) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
879 ddoi.dwOfs = DIJOFS_BUTTON(4);
880 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 4) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
885 ddoi.dwOfs = DIJOFS_BUTTON(5);
886 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 5) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
891 ddoi.dwOfs = DIJOFS_BUTTON(6);
892 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 6) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
897 ddoi.dwOfs = DIJOFS_BUTTON(7);
898 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 7) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
903 ddoi.dwOfs = DIJOFS_BUTTON(8);
904 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 8) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
908 ddoi.dwOfs = DIJOFS_BUTTON(9);
909 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 9) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
913 ddoi.dwOfs = DIJOFS_BUTTON(10);
914 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 10) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
917 sprintf(ddoi.tszName, "%d-Button", i);
918 _dump_OBJECTINSTANCEA(&ddoi);
919 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE)
924 if (xfd!=This->joyfd)
930 static HRESULT WINAPI JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
931 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
935 ICOM_THIS(JoystickImpl,iface);
937 device_enumobjects_AtoWcb_data data;
939 data.lpCallBack = lpCallback;
940 data.lpvRef = lpvRef;
942 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
945 /******************************************************************************
946 * GetProperty : get input device properties
948 static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
950 LPDIPROPHEADER pdiph)
952 ICOM_THIS(JoystickImpl,iface);
954 TRACE("(this=%p,%s,%p): stub!\n",
955 iface, debugstr_guid(rguid), pdiph);
957 if (TRACE_ON(dinput))
958 _dump_DIPROPHEADER(pdiph);
960 if (!HIWORD(rguid)) {
961 switch ((DWORD)rguid) {
962 case (DWORD) DIPROP_BUFFERSIZE: {
963 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
965 TRACE(" return buffersize = %d\n",This->queue_len);
966 pd->dwData = This->queue_len;
970 case (DWORD) DIPROP_RANGE: {
971 /* LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph; */
972 if ((pdiph->dwHow == DIPH_BYID) &&
973 (pdiph->dwObj & DIDFT_ABSAXIS)) {
974 /* The app is querying the current range of the axis : return the lMin and lMax values */
975 FIXME("unimplemented axis range query.\n");
982 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
991 static ICOM_VTABLE(IDirectInputDevice8A) JoystickAvt =
993 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
994 IDirectInputDevice2AImpl_QueryInterface,
995 IDirectInputDevice2AImpl_AddRef,
996 JoystickAImpl_Release,
997 JoystickAImpl_GetCapabilities,
998 JoystickAImpl_EnumObjects,
999 JoystickAImpl_GetProperty,
1000 JoystickAImpl_SetProperty,
1001 JoystickAImpl_Acquire,
1002 JoystickAImpl_Unacquire,
1003 JoystickAImpl_GetDeviceState,
1004 JoystickAImpl_GetDeviceData,
1005 JoystickAImpl_SetDataFormat,
1006 JoystickAImpl_SetEventNotification,
1007 IDirectInputDevice2AImpl_SetCooperativeLevel,
1008 IDirectInputDevice2AImpl_GetObjectInfo,
1009 IDirectInputDevice2AImpl_GetDeviceInfo,
1010 IDirectInputDevice2AImpl_RunControlPanel,
1011 IDirectInputDevice2AImpl_Initialize,
1012 IDirectInputDevice2AImpl_CreateEffect,
1013 IDirectInputDevice2AImpl_EnumEffects,
1014 IDirectInputDevice2AImpl_GetEffectInfo,
1015 IDirectInputDevice2AImpl_GetForceFeedbackState,
1016 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1017 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1018 IDirectInputDevice2AImpl_Escape,
1020 IDirectInputDevice2AImpl_SendDeviceData,
1021 IDirectInputDevice7AImpl_EnumEffectsInFile,
1022 IDirectInputDevice7AImpl_WriteEffectToFile,
1023 IDirectInputDevice8AImpl_BuildActionMap,
1024 IDirectInputDevice8AImpl_SetActionMap,
1025 IDirectInputDevice8AImpl_GetImageInfo
1028 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1029 # define XCAST(fun) (typeof(JoystickWvt.fun))
1031 # define XCAST(fun) (void*)
1034 static ICOM_VTABLE(IDirectInputDevice8W) JoystickWvt =
1036 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1037 IDirectInputDevice2WImpl_QueryInterface,
1038 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1039 XCAST(Release)JoystickAImpl_Release,
1040 XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
1041 JoystickWImpl_EnumObjects,
1042 XCAST(GetProperty)JoystickAImpl_GetProperty,
1043 XCAST(SetProperty)JoystickAImpl_SetProperty,
1044 XCAST(Acquire)JoystickAImpl_Acquire,
1045 XCAST(Unacquire)JoystickAImpl_Unacquire,
1046 XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
1047 XCAST(GetDeviceData)JoystickAImpl_GetDeviceData,
1048 XCAST(SetDataFormat)JoystickAImpl_SetDataFormat,
1049 XCAST(SetEventNotification)JoystickAImpl_SetEventNotification,
1050 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
1051 IDirectInputDevice2WImpl_GetObjectInfo,
1052 IDirectInputDevice2WImpl_GetDeviceInfo,
1053 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1054 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1055 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
1056 IDirectInputDevice2WImpl_EnumEffects,
1057 IDirectInputDevice2WImpl_GetEffectInfo,
1058 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
1059 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1060 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1061 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1062 XCAST(Poll)JoystickAImpl_Poll,
1063 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1064 IDirectInputDevice7WImpl_EnumEffectsInFile,
1065 IDirectInputDevice7WImpl_WriteEffectToFile,
1066 IDirectInputDevice8WImpl_BuildActionMap,
1067 IDirectInputDevice8WImpl_SetActionMap,
1068 IDirectInputDevice8WImpl_GetImageInfo
1072 #endif /* HAVE_LINUX_INPUT_H */