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 static void fake_current_js_state(JoystickImpl *ji);
128 #define test_bit(arr,bit) (((BYTE*)arr)[bit>>3]&(1<<(bit&7)))
130 static int joydev_have(void)
137 BYTE absbits[(ABS_MAX+7)/8],keybits[(KEY_MAX+7)/8];
139 sprintf(buf,EVDEVPREFIX"%d",i);
140 if (-1!=(fd=open(buf,O_RDONLY))) {
141 if (-1==ioctl(fd,EVIOCGBIT(EV_ABS,sizeof(absbits)),absbits)) {
142 perror("EVIOCGBIT EV_ABS");
146 if (-1==ioctl(fd,EVIOCGBIT(EV_KEY,sizeof(keybits)),keybits)) {
147 perror("EVIOCGBIT EV_KEY");
151 /* A true joystick has at least axis X and Y, and at least 1
152 * button. copied from linux/drivers/input/joydev.c */
153 if (test_bit(absbits,ABS_X) && test_bit(absbits,ABS_Y) &&
154 ( test_bit(keybits,BTN_TRIGGER) ||
155 test_bit(keybits,BTN_A) ||
156 test_bit(keybits,BTN_1)
159 FIXME("found a joystick at %s!\n",buf);
164 if (havejoy || (errno==ENODEV))
170 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, int version)
174 if ((dwDevType != 0) && (GET_DIDEVICE_TYPE(dwDevType) != DIDEVTYPE_JOYSTICK))
177 if (dwFlags & DIEDFL_FORCEFEEDBACK)
180 havejoy = joydev_have();
185 TRACE("Enumerating the linuxinput Joystick device\n");
187 /* Return joystick */
188 lpddi->guidInstance = GUID_Joystick;
189 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
191 lpddi->guidFFDriver = GUID_NULL;
192 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL<<8);
194 strcpy(lpddi->tszInstanceName, "Joystick");
195 /* ioctl JSIOCGNAME(len) */
196 strcpy(lpddi->tszProductName, "Wine Joystick");
200 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, int version)
204 if ((dwDevType != 0) && (GET_DIDEVICE_TYPE(dwDevType) != DIDEVTYPE_JOYSTICK))
207 if (dwFlags & DIEDFL_FORCEFEEDBACK)
210 havejoy = joydev_have();
215 TRACE("Enumerating the linuxinput Joystick device\n");
217 /* Return joystick */
218 lpddi->guidInstance = GUID_Joystick;
219 lpddi->guidProduct = DInput_Wine_Joystick_GUID;
221 lpddi->guidFFDriver = GUID_NULL;
222 lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL<<8);
224 MultiByteToWideChar(CP_ACP, 0, "Joystick", -1, lpddi->tszInstanceName, MAX_PATH);
225 /* ioctl JSIOCGNAME(len) */
226 MultiByteToWideChar(CP_ACP, 0, "Wine Joystick", -1, lpddi->tszProductName, MAX_PATH);
230 static JoystickImpl *alloc_device(REFGUID rguid, LPVOID jvt, IDirectInputImpl *dinput)
232 JoystickImpl* newDevice;
235 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
236 newDevice->lpVtbl = jvt;
238 newDevice->joyfd = -1;
239 newDevice->dinput = dinput;
240 memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
241 for (i=0;i<ABS_MAX;i++) {
242 newDevice->wantmin[i] = -32768;
243 newDevice->wantmax[i] = 32767;
245 * direct input defines a default for the deadzone somewhere; but as long
246 * as in map_axis the code for the dead zone is commented out its no
249 newDevice->deadz[i] = 0;
251 fake_current_js_state(newDevice);
255 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
259 havejoy = joydev_have();
262 return DIERR_DEVICENOTREG;
264 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
265 (IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) {
266 if ((riid == NULL) ||
267 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
268 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
269 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
270 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
271 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput);
272 TRACE("Creating a Joystick device (%p)\n", *pdev);
275 return DIERR_NOINTERFACE;
278 return DIERR_DEVICENOTREG;
282 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
286 havejoy = joydev_have();
289 return DIERR_DEVICENOTREG;
291 if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
292 (IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) {
293 if ((riid == NULL) ||
294 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
295 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
296 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
297 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
298 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput);
299 TRACE("Creating a Joystick device (%p)\n", *pdev);
302 return DIERR_NOINTERFACE;
305 return DIERR_DEVICENOTREG;
308 static dinput_device joydev = {
312 joydev_create_deviceA,
313 joydev_create_deviceW
316 DECL_GLOBAL_CONSTRUCTOR(joydev_register) { dinput_register_device(&joydev); }
318 /******************************************************************************
321 static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
323 ICOM_THIS(JoystickImpl,iface);
329 /* Free the data queue */
330 if (This->data_queue != NULL)
331 HeapFree(GetProcessHeap(),0,This->data_queue);
333 /* Free the DataFormat */
334 HeapFree(GetProcessHeap(), 0, This->df);
336 HeapFree(GetProcessHeap(),0,This);
340 /******************************************************************************
341 * SetDataFormat : the application can choose the format of the data
342 * the device driver sends back with GetDeviceState.
344 static HRESULT WINAPI JoystickAImpl_SetDataFormat(
345 LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
348 ICOM_THIS(JoystickImpl,iface);
351 TRACE("(this=%p,%p)\n",This,df);
353 TRACE("(df.dwSize=%ld)\n",df->dwSize);
354 TRACE("(df.dwObjsize=%ld)\n",df->dwObjSize);
355 TRACE("(df.dwFlags=0x%08lx)\n",df->dwFlags);
356 TRACE("(df.dwDataSize=%ld)\n",df->dwDataSize);
357 TRACE("(df.dwNumObjs=%ld)\n",df->dwNumObjs);
359 for (i=0;i<df->dwNumObjs;i++) {
360 TRACE("df.rgodf[%d].guid %s (%p)\n",i,debugstr_guid(df->rgodf[i].pguid), df->rgodf[i].pguid);
361 TRACE("df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
362 TRACE("dwType 0x%02x,dwInstance %d\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
363 TRACE("df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
366 /* Store the new data format */
367 This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
368 memcpy(This->df, df, df->dwSize);
369 This->df->rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
370 memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
375 /******************************************************************************
376 * Acquire : gets exclusive control of the joystick
378 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
381 ICOM_THIS(JoystickImpl,iface);
384 TRACE("(this=%p)\n",This);
388 sprintf(buf,EVDEVPREFIX"%d",i);
389 if (-1==(This->joyfd=open(buf,O_RDONLY))) {
391 return DIERR_NOTFOUND;
395 if ((-1!=ioctl(This->joyfd,EVIOCGBIT(EV_ABS,sizeof(This->absbits)),This->absbits)) &&
396 (-1!=ioctl(This->joyfd,EVIOCGBIT(EV_KEY,sizeof(This->keybits)),This->keybits)) &&
397 (test_bit(This->absbits,ABS_X) && test_bit(This->absbits,ABS_Y) &&
398 (test_bit(This->keybits,BTN_TRIGGER)||
399 test_bit(This->keybits,BTN_A) ||
400 test_bit(This->keybits,BTN_1)
409 return DIERR_NOTFOUND;
411 for (i=0;i<ABS_MAX;i++) {
412 if (test_bit(This->absbits,i)) {
413 if (-1==ioctl(This->joyfd,EVIOCGABS(i),&(This->axes[i])))
415 FIXME("axe %d: cur=%d, min=%d, max=%d, fuzz=%d, flat=%d\n",
417 This->axes[i][AXE_ABS],
418 This->axes[i][AXE_ABSMIN],
419 This->axes[i][AXE_ABSMAX],
420 This->axes[i][AXE_ABSFUZZ],
421 This->axes[i][AXE_ABSFLAT]
423 This->havemin[i] = This->axes[i][AXE_ABSMIN];
424 This->havemax[i] = This->axes[i][AXE_ABSMAX];
429 fake_current_js_state(This);
434 /******************************************************************************
435 * Unacquire : frees the joystick
437 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
439 ICOM_THIS(JoystickImpl,iface);
441 TRACE("(this=%p)\n",This);
442 if (This->joyfd!=-1) {
452 * This maps the read value (from the input event) to a value in the
453 * 'wanted' range. It also autodetects the possible range of the axe and
454 * adapts values accordingly.
457 map_axis(JoystickImpl* This, int axis, int val) {
458 int xmin = This->axes[axis][AXE_ABSMIN];
459 int xmax = This->axes[axis][AXE_ABSMAX];
460 int hmax = This->havemax[axis];
461 int hmin = This->havemin[axis];
462 int wmin = This->wantmin[axis];
463 int wmax = This->wantmax[axis];
466 if (val > hmax) This->havemax[axis] = hmax = val;
467 if (val < hmin) This->havemin[axis] = hmin = val;
469 if (xmin == xmax) return val;
471 /* map the value from the hmin-hmax range into the wmin-wmax range */
472 ret = (val * (wmax-wmin)) / (hmax-hmin) + wmin;
475 /* deadzone doesn't work comfortably enough right now. needs more testing*/
476 if ((ret > -deadz/2 ) && (ret < deadz/2)) {
477 FIXME("%d in deadzone, return mid.\n",val);
478 return (wmax-wmin)/2+wmin;
485 * set the current state of the js device as it would be with the middle
488 static void fake_current_js_state(JoystickImpl *ji)
490 ji->js.lX = map_axis(ji, ABS_X, ji->axes[ABS_X ][AXE_ABS]);
491 ji->js.lY = map_axis(ji, ABS_Y, ji->axes[ABS_Y ][AXE_ABS]);
492 ji->js.lZ = map_axis(ji, ABS_Z, ji->axes[ABS_Z ][AXE_ABS]);
493 ji->js.lRx = map_axis(ji, ABS_RX, ji->axes[ABS_RX][AXE_ABS]);
494 ji->js.lRy = map_axis(ji, ABS_RY, ji->axes[ABS_RY][AXE_ABS]);
495 ji->js.lRz = map_axis(ji, ABS_RZ, ji->axes[ABS_RZ][AXE_ABS]);
498 static void joy_polldev(JoystickImpl *This) {
501 struct input_event ie;
507 memset(&tv,0,sizeof(tv));
509 FD_SET(This->joyfd,&readfds);
511 if (1>select(This->joyfd+1,&readfds,NULL,NULL,&tv))
514 /* we have one event, so we can read */
515 if (sizeof(ie)!=read(This->joyfd,&ie,sizeof(ie)))
518 TRACE("input_event: type %d, code %d, value %d\n",ie.type,ie.code,ie.value);
520 case EV_KEY: /* button */
522 case BTN_TRIGGER: /* normal flight stick */
523 case BTN_A: /* gamepad */
524 case BTN_1: /* generic */
525 This->js.rgbButtons[0] = ie.value?0x80:0x00;
526 GEN_EVENT(DIJOFS_BUTTON(0),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
531 This->js.rgbButtons[1] = ie.value?0x80:0x00;
532 GEN_EVENT(DIJOFS_BUTTON(1),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
537 This->js.rgbButtons[2] = ie.value?0x80:0x00;
538 GEN_EVENT(DIJOFS_BUTTON(2),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
543 This->js.rgbButtons[3] = ie.value?0x80:0x00;
544 GEN_EVENT(DIJOFS_BUTTON(3),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
549 This->js.rgbButtons[4] = ie.value?0x80:0x00;
550 GEN_EVENT(DIJOFS_BUTTON(4),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
555 This->js.rgbButtons[5] = ie.value?0x80:0x00;
556 GEN_EVENT(DIJOFS_BUTTON(5),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
561 This->js.rgbButtons[6] = ie.value?0x80:0x00;
562 GEN_EVENT(DIJOFS_BUTTON(6),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
567 This->js.rgbButtons[7] = ie.value?0x80:0x00;
568 GEN_EVENT(DIJOFS_BUTTON(7),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
573 This->js.rgbButtons[8] = ie.value?0x80:0x00;
574 GEN_EVENT(DIJOFS_BUTTON(8),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
578 This->js.rgbButtons[9] = ie.value?0x80:0x00;
579 GEN_EVENT(DIJOFS_BUTTON(9),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
583 This->js.rgbButtons[10] = ie.value?0x80:0x00;
584 GEN_EVENT(DIJOFS_BUTTON(10),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
587 FIXME("unhandled joystick button %x, value %d\n",ie.code,ie.value);
594 This->js.lX = map_axis(This,ABS_X,ie.value);
595 GEN_EVENT(DIJOFS_X,This->js.lX,ie.time.tv_usec,(This->dinput->evsequence)++);
598 This->js.lY = map_axis(This,ABS_Y,ie.value);
599 GEN_EVENT(DIJOFS_Y,This->js.lY,ie.time.tv_usec,(This->dinput->evsequence)++);
602 This->js.lZ = map_axis(This,ABS_Z,ie.value);
603 GEN_EVENT(DIJOFS_Z,This->js.lZ,ie.time.tv_usec,(This->dinput->evsequence)++);
606 This->js.lRx = map_axis(This,ABS_RX,ie.value);
607 GEN_EVENT(DIJOFS_RX,This->js.lRx,ie.time.tv_usec,(This->dinput->evsequence)++);
610 This->js.lRy = map_axis(This,ABS_RY,ie.value);
611 GEN_EVENT(DIJOFS_RY,This->js.lRy,ie.time.tv_usec,(This->dinput->evsequence)++);
614 This->js.lRz = map_axis(This,ABS_RZ,ie.value);
615 GEN_EVENT(DIJOFS_RZ,This->js.lRz,ie.time.tv_usec,(This->dinput->evsequence)++);
618 FIXME("unhandled joystick axe event (code %d, value %d)\n",ie.code,ie.value);
623 FIXME("joystick cannot handle type %d event (code %d)\n",ie.type,ie.code);
629 /******************************************************************************
630 * GetDeviceState : returns the "state" of the joystick.
633 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
634 LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
636 ICOM_THIS(JoystickImpl,iface);
640 TRACE("(this=%p,0x%08lx,%p)\n",This,len,ptr);
641 if ((len != sizeof(DIJOYSTATE)) && (len != sizeof(DIJOYSTATE2))) {
642 FIXME("len %ld is not sizeof(DIJOYSTATE) or DIJOYSTATE2, unsupported format.\n",len);
645 memcpy(ptr,&(This->js),len);
646 This->queue_head = 0;
647 This->queue_tail = 0;
651 /******************************************************************************
652 * GetDeviceData : gets buffered input data.
654 static HRESULT WINAPI JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
656 LPDIDEVICEOBJECTDATA dod,
660 ICOM_THIS(JoystickImpl,iface);
662 FIXME("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx),STUB!\n",This,dodsize,*entries,flags);
665 if (flags & DIGDD_PEEK)
666 FIXME("DIGDD_PEEK\n");
674 /******************************************************************************
675 * SetProperty : change input device properties
677 static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
681 ICOM_THIS(JoystickImpl,iface);
683 FIXME("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
684 FIXME("ph.dwSize = %ld, ph.dwHeaderSize =%ld, ph.dwObj = %ld, ph.dwHow= %ld\n",ph->dwSize, ph->dwHeaderSize,ph->dwObj,ph->dwHow);
686 if (!HIWORD(rguid)) {
687 switch ((DWORD)rguid) {
688 case (DWORD) DIPROP_BUFFERSIZE: {
689 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
691 FIXME("buffersize = %ld\n",pd->dwData);
694 case (DWORD)DIPROP_RANGE: {
695 LPCDIPROPRANGE pr = (LPCDIPROPRANGE)ph;
697 FIXME("proprange(%ld,%ld)\n",pr->lMin,pr->lMax);
705 This->wantmin[ph->dwObj/4] = pr->lMin;
706 This->wantmax[ph->dwObj/4] = pr->lMax;
709 FIXME("setting proprange %ld - %ld for dwObj %ld\n",pr->lMin,pr->lMax,ph->dwObj);
713 case (DWORD)DIPROP_DEADZONE: {
714 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
716 FIXME("setting deadzone(%ld)\n",pd->dwData);
717 This->deadz[ph->dwObj/4] = pd->dwData;
721 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
725 fake_current_js_state(This);
729 /******************************************************************************
730 * SetEventNotification : specifies event to be sent on state change
732 static HRESULT WINAPI JoystickAImpl_SetEventNotification(
733 LPDIRECTINPUTDEVICE8A iface, HANDLE hnd
735 ICOM_THIS(JoystickImpl,iface);
737 TRACE("(this=%p,0x%08lx)\n",This,(DWORD)hnd);
742 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
743 LPDIRECTINPUTDEVICE8A iface,
744 LPDIDEVCAPS lpDIDevCaps)
746 ICOM_THIS(JoystickImpl,iface);
747 int xfd = This->joyfd;
751 TRACE("%p->(%p)\n",iface,lpDIDevCaps);
753 /* yes, games assume we return something, even if unacquired */
754 JoystickAImpl_Acquire(iface);
758 lpDIDevCaps->dwFlags = DIDC_ATTACHED;
759 lpDIDevCaps->dwDevType = DIDEVTYPE_JOYSTICK;
762 for (i=0;i<ABS_MAX;i++) if (test_bit(This->absbits,i)) axes++;
764 for (i=0;i<KEY_MAX;i++) if (test_bit(This->keybits,i)) buttons++;
766 lpDIDevCaps->dwAxes = axes;
767 lpDIDevCaps->dwButtons = buttons;
770 JoystickAImpl_Unacquire(iface);
775 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface) {
776 ICOM_THIS(JoystickImpl,iface);
783 /******************************************************************************
784 * EnumObjects : enumerate the different buttons and axis...
786 static HRESULT WINAPI JoystickAImpl_EnumObjects(
787 LPDIRECTINPUTDEVICE8A iface,
788 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
792 ICOM_THIS(JoystickImpl,iface);
793 DIDEVICEOBJECTINSTANCEA ddoi;
794 int xfd = This->joyfd;
797 TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
798 if (TRACE_ON(dinput)) {
799 TRACE(" - flags = ");
800 _dump_EnumObjects_flags(dwFlags);
804 if (xfd == -1) return DIERR_NOTACQUIRED;
806 /* Only the fields till dwFFMaxForce are relevant */
807 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
809 /* For the joystick, do as is done in the GetCapabilities function */
810 /* FIXME: needs more items */
811 if ((dwFlags == DIDFT_ALL) ||
812 (dwFlags & DIDFT_AXIS)) {
815 for (i = 0; i < ABS_MAX; i++) {
816 if (!test_bit(This->absbits,i)) continue;
820 ddoi.guidType = GUID_XAxis;
821 ddoi.dwOfs = DIJOFS_X;
824 ddoi.guidType = GUID_YAxis;
825 ddoi.dwOfs = DIJOFS_Y;
828 ddoi.guidType = GUID_ZAxis;
829 ddoi.dwOfs = DIJOFS_Z;
832 ddoi.guidType = GUID_RxAxis;
833 ddoi.dwOfs = DIJOFS_RX;
836 ddoi.guidType = GUID_RyAxis;
837 ddoi.dwOfs = DIJOFS_RY;
840 ddoi.guidType = GUID_RzAxis;
841 ddoi.dwOfs = DIJOFS_RZ;
844 ddoi.guidType = GUID_Slider;
845 ddoi.dwOfs = DIJOFS_SLIDER(0);
848 FIXME("unhandled abs axis %d, ignoring!\n",i);
850 ddoi.dwType = DIDFT_MAKEINSTANCE((1<<i) << WINE_JOYSTICK_AXIS_BASE) | DIDFT_ABSAXIS;
851 sprintf(ddoi.tszName, "%d-Axis", i);
852 _dump_OBJECTINSTANCEA(&ddoi);
853 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE)
858 if ((dwFlags == DIDFT_ALL) ||
859 (dwFlags & DIDFT_BUTTON)) {
862 /*The DInput SDK says that GUID_Button is only for mouse buttons but well*/
864 ddoi.guidType = GUID_Button;
866 for (i = 0; i < KEY_MAX; i++) {
867 if (!test_bit(This->keybits,i)) continue;
873 ddoi.dwOfs = DIJOFS_BUTTON(0);
874 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 0) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
879 ddoi.dwOfs = DIJOFS_BUTTON(1);
880 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 1) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
885 ddoi.dwOfs = DIJOFS_BUTTON(2);
886 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 2) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
891 ddoi.dwOfs = DIJOFS_BUTTON(3);
892 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 3) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
897 ddoi.dwOfs = DIJOFS_BUTTON(4);
898 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 4) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
903 ddoi.dwOfs = DIJOFS_BUTTON(5);
904 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 5) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
909 ddoi.dwOfs = DIJOFS_BUTTON(6);
910 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 6) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
915 ddoi.dwOfs = DIJOFS_BUTTON(7);
916 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 7) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
921 ddoi.dwOfs = DIJOFS_BUTTON(8);
922 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 8) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
926 ddoi.dwOfs = DIJOFS_BUTTON(9);
927 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 9) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
931 ddoi.dwOfs = DIJOFS_BUTTON(10);
932 ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << 10) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
935 sprintf(ddoi.tszName, "%d-Button", i);
936 _dump_OBJECTINSTANCEA(&ddoi);
937 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE)
942 if (xfd!=This->joyfd)
948 static HRESULT WINAPI JoystickWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface,
949 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
953 ICOM_THIS(JoystickImpl,iface);
955 device_enumobjects_AtoWcb_data data;
957 data.lpCallBack = lpCallback;
958 data.lpvRef = lpvRef;
960 return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
963 /******************************************************************************
964 * GetProperty : get input device properties
966 static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
968 LPDIPROPHEADER pdiph)
970 ICOM_THIS(JoystickImpl,iface);
972 TRACE("(this=%p,%s,%p): stub!\n",
973 iface, debugstr_guid(rguid), pdiph);
975 if (TRACE_ON(dinput))
976 _dump_DIPROPHEADER(pdiph);
978 if (!HIWORD(rguid)) {
979 switch ((DWORD)rguid) {
980 case (DWORD) DIPROP_BUFFERSIZE: {
981 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
983 TRACE(" return buffersize = %d\n",This->queue_len);
984 pd->dwData = This->queue_len;
988 case (DWORD) DIPROP_RANGE: {
989 /* LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph; */
990 if ((pdiph->dwHow == DIPH_BYID) &&
991 (pdiph->dwObj & DIDFT_ABSAXIS)) {
992 /* The app is querying the current range of the axis : return the lMin and lMax values */
993 FIXME("unimplemented axis range query.\n");
1000 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
1009 static ICOM_VTABLE(IDirectInputDevice8A) JoystickAvt =
1011 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1012 IDirectInputDevice2AImpl_QueryInterface,
1013 IDirectInputDevice2AImpl_AddRef,
1014 JoystickAImpl_Release,
1015 JoystickAImpl_GetCapabilities,
1016 JoystickAImpl_EnumObjects,
1017 JoystickAImpl_GetProperty,
1018 JoystickAImpl_SetProperty,
1019 JoystickAImpl_Acquire,
1020 JoystickAImpl_Unacquire,
1021 JoystickAImpl_GetDeviceState,
1022 JoystickAImpl_GetDeviceData,
1023 JoystickAImpl_SetDataFormat,
1024 JoystickAImpl_SetEventNotification,
1025 IDirectInputDevice2AImpl_SetCooperativeLevel,
1026 IDirectInputDevice2AImpl_GetObjectInfo,
1027 IDirectInputDevice2AImpl_GetDeviceInfo,
1028 IDirectInputDevice2AImpl_RunControlPanel,
1029 IDirectInputDevice2AImpl_Initialize,
1030 IDirectInputDevice2AImpl_CreateEffect,
1031 IDirectInputDevice2AImpl_EnumEffects,
1032 IDirectInputDevice2AImpl_GetEffectInfo,
1033 IDirectInputDevice2AImpl_GetForceFeedbackState,
1034 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1035 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1036 IDirectInputDevice2AImpl_Escape,
1038 IDirectInputDevice2AImpl_SendDeviceData,
1039 IDirectInputDevice7AImpl_EnumEffectsInFile,
1040 IDirectInputDevice7AImpl_WriteEffectToFile,
1041 IDirectInputDevice8AImpl_BuildActionMap,
1042 IDirectInputDevice8AImpl_SetActionMap,
1043 IDirectInputDevice8AImpl_GetImageInfo
1046 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1047 # define XCAST(fun) (typeof(JoystickWvt.fun))
1049 # define XCAST(fun) (void*)
1052 static ICOM_VTABLE(IDirectInputDevice8W) JoystickWvt =
1054 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
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 #endif /* HAVE_LINUX_INPUT_H */