3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
9 * - Tomb Raider 2 Demo:
10 * Playable using keyboard only.
11 * - WingCommander Prophecy Demo:
12 * Doesn't get Input Focus.
14 * - Fallout : works great in X and DGA mode
16 * FIXME: The keyboard handling needs to (and will) be merged into keyboard.c
17 * (The current implementation is currently only a proof of concept and
25 #include <sys/signal.h>
29 #include "wine/obj_base.h"
37 #include "sysmetrics.h"
40 extern BYTE InputKeyStateTable
[256];
41 extern int min_keycode
, max_keycode
;
42 extern WORD keyc2vkey
[256];
44 static ICOM_VTABLE(IDirectInputA
) ddiavt
;
45 static ICOM_VTABLE(IDirectInputDevice2A
) SysKeyboardAvt
;
46 static ICOM_VTABLE(IDirectInputDevice2A
) SysMouseAvt
;
48 typedef struct IDirectInputAImpl IDirectInputAImpl
;
49 typedef struct IDirectInputDevice2AImpl IDirectInputDevice2AImpl
;
50 typedef struct SysKeyboardAImpl SysKeyboardAImpl
;
51 typedef struct SysMouseAImpl SysMouseAImpl
;
53 struct IDirectInputDevice2AImpl
55 ICOM_VTABLE(IDirectInputDevice2A
)* lpvtbl
;
60 struct SysKeyboardAImpl
62 /* IDirectInputDevice2AImpl */
63 ICOM_VTABLE(IDirectInputDevice2A
)* lpvtbl
;
66 /* SysKeyboardAImpl */
72 /* IDirectInputDevice2AImpl */
73 ICOM_VTABLE(IDirectInputDevice2A
)* lpvtbl
;
78 /* Previous position for relative moves */
80 LPMOUSE_EVENT_PROC prev_handler
;
83 DWORD win_centerX
, win_centerY
;
84 LPDIDEVICEOBJECTDATA data_queue
;
85 int queue_pos
, queue_len
;
91 /* UIDs for Wine "drivers".
92 When enumerating each device supporting DInput, they have two UIDs :
95 static GUID DInput_Wine_Mouse_GUID
= { /* 9e573ed8-7734-11d2-8d4a-23903fb6bdf7 */
99 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
101 static GUID DInput_Wine_Keyboard_GUID
= { /* 0ab8648a-7735-11d2-8c73-71df54a96441 */
105 {0x8c, 0x73, 0x71, 0xdf, 0x54, 0xa9, 0x64, 0x41}
108 /* FIXME: This is ugly and not thread safe :/ */
109 static IDirectInputDevice2A
* current_lock
= NULL
;
111 /******************************************************************************
112 * Various debugging tools
114 static void _dump_cooperativelevel(DWORD dwFlags
) {
120 #define FE(x) { x, #x},
124 FE(DISCL_NONEXCLUSIVE
)
126 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
127 if (flags
[i
].mask
& dwFlags
)
128 DUMP("%s ",flags
[i
].name
);
132 struct IDirectInputAImpl
134 ICOM_VTABLE(IDirectInputA
)* lpvtbl
;
138 /******************************************************************************
139 * DirectInputCreate32A
141 HRESULT WINAPI
DirectInputCreateA(HINSTANCE hinst
, DWORD dwVersion
, LPDIRECTINPUTA
*ppDI
, LPUNKNOWN punkOuter
)
143 IDirectInputAImpl
* This
;
144 TRACE(dinput
, "(0x%08lx,%04lx,%p,%p)\n",
145 (DWORD
)hinst
,dwVersion
,ppDI
,punkOuter
147 This
= (IDirectInputAImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputAImpl
));
149 This
->lpvtbl
= &ddiavt
;
150 *ppDI
=(IDirectInputA
*)This
;
153 /******************************************************************************
154 * IDirectInputA_EnumDevices
156 static HRESULT WINAPI
IDirectInputAImpl_EnumDevices(
157 LPDIRECTINPUTA iface
, DWORD dwDevType
, LPDIENUMDEVICESCALLBACKA lpCallback
,
158 LPVOID pvRef
, DWORD dwFlags
161 ICOM_THIS(IDirectInputAImpl
,iface
);
162 DIDEVICEINSTANCEA devInstance
;
165 TRACE(dinput
, "(this=%p,0x%04lx,%p,%p,%04lx)\n", This
, dwDevType
, lpCallback
, pvRef
, dwFlags
);
167 devInstance
.dwSize
= sizeof(DIDEVICEINSTANCEA
);
169 if ((dwDevType
== 0) || (dwDevType
== DIDEVTYPE_KEYBOARD
)) {
170 /* Return keyboard */
171 devInstance
.guidInstance
= GUID_SysKeyboard
; /* DInput's GUID */
172 devInstance
.guidProduct
= DInput_Wine_Keyboard_GUID
; /* Vendor's GUID */
173 devInstance
.dwDevType
= DIDEVTYPE_KEYBOARD
| (DIDEVTYPEKEYBOARD_UNKNOWN
<< 8);
174 strcpy(devInstance
.tszInstanceName
, "Keyboard");
175 strcpy(devInstance
.tszProductName
, "Wine Keyboard");
177 ret
= lpCallback(&devInstance
, pvRef
);
178 TRACE(dinput
, "Keyboard registered\n");
180 if (ret
== DIENUM_STOP
)
184 if ((dwDevType
== 0) || (dwDevType
== DIDEVTYPE_KEYBOARD
)) {
186 devInstance
.guidInstance
= GUID_SysMouse
; /* DInput's GUID */
187 devInstance
.guidProduct
= DInput_Wine_Mouse_GUID
; /* Vendor's GUID */
188 devInstance
.dwDevType
= DIDEVTYPE_MOUSE
| (DIDEVTYPEMOUSE_UNKNOWN
<< 8);
189 strcpy(devInstance
.tszInstanceName
, "Mouse");
190 strcpy(devInstance
.tszProductName
, "Wine Mouse");
192 ret
= lpCallback(&devInstance
, pvRef
);
193 TRACE(dinput
, "Mouse registered\n");
196 /* Should also do joystick enumerations.... */
201 static ULONG WINAPI
IDirectInputAImpl_AddRef(LPDIRECTINPUTA iface
)
203 ICOM_THIS(IDirectInputAImpl
,iface
);
204 return ++(This
->ref
);
207 static ULONG WINAPI
IDirectInputAImpl_Release(LPDIRECTINPUTA iface
)
209 ICOM_THIS(IDirectInputAImpl
,iface
);
210 if (!(--This
->ref
)) {
211 HeapFree(GetProcessHeap(),0,This
);
217 static HRESULT WINAPI
IDirectInputAImpl_CreateDevice(
218 LPDIRECTINPUTA iface
,REFGUID rguid
,LPDIRECTINPUTDEVICEA
* pdev
,
221 ICOM_THIS(IDirectInputAImpl
,iface
);
224 WINE_StringFromCLSID(rguid
,xbuf
);
225 FIXME(dinput
,"(this=%p,%s,%p,%p): stub\n",This
,xbuf
,pdev
,punk
);
226 if ((!memcmp(&GUID_SysKeyboard
,rguid
,sizeof(GUID_SysKeyboard
))) || /* Generic Keyboard */
227 (!memcmp(&DInput_Wine_Keyboard_GUID
,rguid
,sizeof(GUID_SysKeyboard
)))) { /* Wine Keyboard */
228 SysKeyboardAImpl
* newDevice
;
229 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(SysKeyboardAImpl
));
231 newDevice
->lpvtbl
= &SysKeyboardAvt
;
232 memcpy(&(newDevice
->guid
),rguid
,sizeof(*rguid
));
233 memset(newDevice
->keystate
,0,256);
234 *pdev
=(IDirectInputDeviceA
*)newDevice
;
237 if ((!memcmp(&GUID_SysMouse
,rguid
,sizeof(GUID_SysMouse
))) || /* Generic Mouse */
238 (!memcmp(&DInput_Wine_Mouse_GUID
,rguid
,sizeof(GUID_SysMouse
)))) { /* Wine Mouse */
239 SysKeyboardAImpl
* newDevice
;
240 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(SysMouseAImpl
));
242 newDevice
->lpvtbl
= &SysMouseAvt
;
243 memcpy(&(newDevice
->guid
),rguid
,sizeof(*rguid
));
244 *pdev
=(IDirectInputDeviceA
*)newDevice
;
250 static HRESULT WINAPI
IDirectInputAImpl_QueryInterface(
251 LPDIRECTINPUTA iface
,REFIID riid
,LPVOID
*ppobj
253 ICOM_THIS(IDirectInputAImpl
,iface
);
256 WINE_StringFromCLSID(riid
,xbuf
);
257 TRACE(dinput
,"(this=%p,%s,%p)\n",This
,xbuf
,ppobj
);
258 if (!memcmp(&IID_IUnknown
,riid
,sizeof(*riid
))) {
259 IDirectInputA_AddRef(iface
);
263 if (!memcmp(&IID_IDirectInputA
,riid
,sizeof(*riid
))) {
264 IDirectInputA_AddRef(iface
);
271 static HRESULT WINAPI
IDirectInputAImpl_Initialize(
272 LPDIRECTINPUTA iface
,HINSTANCE hinst
,DWORD x
274 return DIERR_ALREADYINITIALIZED
;
277 static HRESULT WINAPI
IDirectInputAImpl_GetDeviceStatus(LPDIRECTINPUTA iface
,
279 ICOM_THIS(IDirectInputAImpl
,iface
);
282 WINE_StringFromCLSID(rguid
,xbuf
);
283 FIXME(dinput
,"(%p)->(%s): stub\n",This
,xbuf
);
288 static HRESULT WINAPI
IDirectInputAImpl_RunControlPanel(LPDIRECTINPUTA iface
,
291 ICOM_THIS(IDirectInputAImpl
,iface
);
292 FIXME(dinput
,"(%p)->(%08lx,%08lx): stub\n",This
, (DWORD
) hwndOwner
, dwFlags
);
297 static ICOM_VTABLE(IDirectInputA
) ddiavt
= {
298 IDirectInputAImpl_QueryInterface
,
299 IDirectInputAImpl_AddRef
,
300 IDirectInputAImpl_Release
,
301 IDirectInputAImpl_CreateDevice
,
302 IDirectInputAImpl_EnumDevices
,
303 IDirectInputAImpl_GetDeviceStatus
,
304 IDirectInputAImpl_RunControlPanel
,
305 IDirectInputAImpl_Initialize
308 /******************************************************************************
309 * IDirectInputDeviceA
312 static HRESULT WINAPI
IDirectInputDevice2AImpl_SetDataFormat(
313 LPDIRECTINPUTDEVICE2A iface
,LPCDIDATAFORMAT df
317 TRACE(dinput,"(this=%p,%p)\n",This,df);
319 TRACE(dinput,"df.dwSize=%ld\n",df->dwSize);
320 TRACE(dinput,"(df.dwObjsize=%ld)\n",df->dwObjSize);
321 TRACE(dinput,"(df.dwFlags=0x%08lx)\n",df->dwFlags);
322 TRACE(dinput,"(df.dwDataSize=%ld)\n",df->dwDataSize);
323 TRACE(dinput,"(df.dwNumObjs=%ld)\n",df->dwNumObjs);
325 for (i=0;i<df->dwNumObjs;i++) {
328 if (df->rgodf[i].pguid)
329 WINE_StringFromCLSID(df->rgodf[i].pguid,xbuf);
331 strcpy(xbuf,"<no guid>");
332 TRACE(dinput,"df.rgodf[%d].guid %s\n",i,xbuf);
333 TRACE(dinput,"df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
334 TRACE(dinput,"dwType 0x%02lx,dwInstance %ld\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
335 TRACE(dinput,"df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
341 static HRESULT WINAPI
IDirectInputDevice2AImpl_SetCooperativeLevel(
342 LPDIRECTINPUTDEVICE2A iface
,HWND hwnd
,DWORD dwflags
344 ICOM_THIS(IDirectInputDevice2AImpl
,iface
);
345 FIXME(dinput
,"(this=%p,0x%08lx,0x%08lx): stub\n",This
,(DWORD
)hwnd
,dwflags
);
346 if (TRACE_ON(dinput
))
347 _dump_cooperativelevel(dwflags
);
351 static HRESULT WINAPI
IDirectInputDevice2AImpl_SetEventNotification(
352 LPDIRECTINPUTDEVICE2A iface
,HANDLE hnd
354 ICOM_THIS(IDirectInputDevice2AImpl
,iface
);
355 FIXME(dinput
,"(this=%p,0x%08lx): stub\n",This
,(DWORD
)hnd
);
359 static ULONG WINAPI
IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE2A iface
)
361 ICOM_THIS(IDirectInputDevice2AImpl
,iface
);
365 HeapFree(GetProcessHeap(),0,This
);
369 static HRESULT WINAPI
SysKeyboardAImpl_SetProperty(
370 LPDIRECTINPUTDEVICE2A iface
,REFGUID rguid
,LPCDIPROPHEADER ph
373 ICOM_THIS(SysKeyboardAImpl
,iface
);
377 WINE_StringFromCLSID(rguid
,xbuf
);
379 sprintf(xbuf
,"<special guid %ld>",(DWORD
)rguid
);
380 TRACE(dinput
,"(this=%p,%s,%p)\n",This
,xbuf
,ph
);
381 TRACE(dinput
,"(size=%ld,headersize=%ld,obj=%ld,how=%ld\n",
382 ph
->dwSize
,ph
->dwHeaderSize
,ph
->dwObj
,ph
->dwHow
);
383 if (!HIWORD(rguid
)) {
384 switch ((DWORD
)rguid
) {
385 case DIPROP_BUFFERSIZE
: {
386 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
388 TRACE(dinput
,"(buffersize=%ld)\n",pd
->dwData
);
392 WARN(dinput
,"Unknown type %ld\n",(DWORD
)rguid
);
399 static HRESULT WINAPI
SysKeyboardAImpl_GetDeviceState(
400 LPDIRECTINPUTDEVICE2A iface
,DWORD len
,LPVOID ptr
407 for (keyc
=min_keycode
;keyc
<max_keycode
;keyc
++)
409 /* X keycode to virtual key */
410 vkey
= keyc2vkey
[keyc
] & 0xFF;
411 /* The windows scancode is keyc-min_keycode */
412 if (InputKeyStateTable
[vkey
]&0x80) {
413 ((LPBYTE
)ptr
)[keyc
-min_keycode
]=0x80;
414 ((LPBYTE
)ptr
)[(keyc
-min_keycode
)|0x80]=0x80;
419 WARN(dinput
,"whoops, SysKeyboardAImpl_GetDeviceState got len %ld?\n",len
);
423 static HRESULT WINAPI
SysKeyboardAImpl_GetDeviceData(
424 LPDIRECTINPUTDEVICE2A iface
,DWORD dodsize
,LPDIDEVICEOBJECTDATA dod
,
425 LPDWORD entries
,DWORD flags
428 ICOM_THIS(SysKeyboardAImpl
,iface
);
429 int keyc
,n
,vkey
,xentries
;
431 TRACE(dinput
,"(this=%p,%ld,%p,%p(%ld)),0x%08lx)\n",
432 This
,dodsize
,dod
,entries
,entries
?*entries
:0,flags
);
433 EVENT_WaitNetEvent(FALSE
,TRUE
);
441 for (keyc
=min_keycode
;(keyc
<max_keycode
) && (n
<*entries
);keyc
++)
443 /* X keycode to virtual key */
444 vkey
= keyc2vkey
[keyc
] & 0xFF;
445 if (This
->keystate
[vkey
] == (InputKeyStateTable
[vkey
]&0x80))
449 dod
[n
].dwOfs
= keyc
-min_keycode
; /* scancode */
450 dod
[n
].dwData
= InputKeyStateTable
[vkey
]&0x80;
451 dod
[n
].dwTimeStamp
= 0; /* umm */
452 dod
[n
].dwSequence
= 0; /* umm */
455 if (!(flags
& DIGDD_PEEK
))
456 This
->keystate
[vkey
] = InputKeyStateTable
[vkey
]&0x80;
460 if (n
) fprintf(stderr
,"%d entries\n",n
);
465 static HRESULT WINAPI
SysKeyboardAImpl_Acquire(LPDIRECTINPUTDEVICE2A iface
)
467 ICOM_THIS(SysKeyboardAImpl
,iface
);
468 TRACE(dinput
,"(this=%p): stub\n",This
);
472 static HRESULT WINAPI
SysKeyboardAImpl_Unacquire(LPDIRECTINPUTDEVICE2A iface
)
474 ICOM_THIS(SysKeyboardAImpl
,iface
);
475 TRACE(dinput
,"(this=%p): stub\n",This
);
479 static HRESULT WINAPI
IDirectInputDevice2AImpl_QueryInterface(
480 LPDIRECTINPUTDEVICE2A iface
,REFIID riid
,LPVOID
*ppobj
483 ICOM_THIS(IDirectInputDevice2AImpl
,iface
);
486 WINE_StringFromCLSID(riid
,xbuf
);
487 TRACE(dinput
,"(this=%p,%s,%p)\n",This
,xbuf
,ppobj
);
488 if (!memcmp(&IID_IUnknown
,riid
,sizeof(*riid
))) {
489 IDirectInputDevice2_AddRef(iface
);
493 if (!memcmp(&IID_IDirectInputDeviceA
,riid
,sizeof(*riid
))) {
494 IDirectInputDevice2_AddRef(iface
);
498 if (!memcmp(&IID_IDirectInputDevice2A
,riid
,sizeof(*riid
))) {
499 IDirectInputDevice2_AddRef(iface
);
506 static ULONG WINAPI
IDirectInputDevice2AImpl_AddRef(
507 LPDIRECTINPUTDEVICE2A iface
)
509 ICOM_THIS(IDirectInputDevice2AImpl
,iface
);
513 static HRESULT WINAPI
IDirectInputDevice2AImpl_GetCapabilities(
514 LPDIRECTINPUTDEVICE2A iface
,
515 LPDIDEVCAPS lpDIDevCaps
)
517 FIXME(dinput
, "stub!\n");
521 static HRESULT WINAPI
IDirectInputDevice2AImpl_EnumObjects(
522 LPDIRECTINPUTDEVICE2A iface
,
523 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback
,
527 FIXME(dinput
, "stub!\n");
530 lpCallback(NULL
, lpvRef
);
535 static HRESULT WINAPI
IDirectInputDevice2AImpl_GetProperty(
536 LPDIRECTINPUTDEVICE2A iface
,
538 LPDIPROPHEADER pdiph
)
540 FIXME(dinput
, "stub!\n");
544 static HRESULT WINAPI
IDirectInputDevice2AImpl_GetObjectInfo(
545 LPDIRECTINPUTDEVICE2A iface
,
546 LPDIDEVICEOBJECTINSTANCEA pdidoi
,
550 FIXME(dinput
, "stub!\n");
554 static HRESULT WINAPI
IDirectInputDevice2AImpl_GetDeviceInfo(
555 LPDIRECTINPUTDEVICE2A iface
,
556 LPDIDEVICEINSTANCEA pdidi
)
558 FIXME(dinput
, "stub!\n");
562 static HRESULT WINAPI
IDirectInputDevice2AImpl_RunControlPanel(
563 LPDIRECTINPUTDEVICE2A iface
,
567 FIXME(dinput
, "stub!\n");
571 static HRESULT WINAPI
IDirectInputDevice2AImpl_Initialize(
572 LPDIRECTINPUTDEVICE2A iface
,
577 FIXME(dinput
, "stub!\n");
581 /******************************************************************************
582 * IDirectInputDevice2A
585 static HRESULT WINAPI
IDirectInputDevice2AImpl_CreateEffect(
586 LPDIRECTINPUTDEVICE2A iface
,
589 LPDIRECTINPUTEFFECT
*ppdef
,
592 FIXME(dinput
, "stub!\n");
596 static HRESULT WINAPI
IDirectInputDevice2AImpl_EnumEffects(
597 LPDIRECTINPUTDEVICE2A iface
,
598 LPDIENUMEFFECTSCALLBACKA lpCallback
,
602 FIXME(dinput
, "stub!\n");
604 lpCallback(NULL
, lpvRef
);
608 static HRESULT WINAPI
IDirectInputDevice2AImpl_GetEffectInfo(
609 LPDIRECTINPUTDEVICE2A iface
,
610 LPDIEFFECTINFOA lpdei
,
613 FIXME(dinput
, "stub!\n");
617 static HRESULT WINAPI
IDirectInputDevice2AImpl_GetForceFeedbackState(
618 LPDIRECTINPUTDEVICE2A iface
,
621 FIXME(dinput
, "stub!\n");
625 static HRESULT WINAPI
IDirectInputDevice2AImpl_SendForceFeedbackCommand(
626 LPDIRECTINPUTDEVICE2A iface
,
629 FIXME(dinput
, "stub!\n");
633 static HRESULT WINAPI
IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
634 LPDIRECTINPUTDEVICE2A iface
,
635 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback
,
639 FIXME(dinput
, "stub!\n");
641 lpCallback(NULL
, lpvRef
);
645 static HRESULT WINAPI
IDirectInputDevice2AImpl_Escape(
646 LPDIRECTINPUTDEVICE2A iface
,
647 LPDIEFFESCAPE lpDIEEsc
)
649 FIXME(dinput
, "stub!\n");
653 static HRESULT WINAPI
IDirectInputDevice2AImpl_Poll(
654 LPDIRECTINPUTDEVICE2A iface
)
656 FIXME(dinput
, "stub!\n");
660 static HRESULT WINAPI
IDirectInputDevice2AImpl_SendDeviceData(
661 LPDIRECTINPUTDEVICE2A iface
,
663 LPDIDEVICEOBJECTDATA rgdod
,
667 FIXME(dinput
, "stub!\n");
671 /******************************************************************************
672 * SysMouseA (DInput Mouse support)
675 /******************************************************************************
676 * Release : release the mouse buffer.
678 static ULONG WINAPI
SysMouseAImpl_Release(LPDIRECTINPUTDEVICE2A iface
)
680 ICOM_THIS(SysMouseAImpl
,iface
);
686 /* Free the data queue */
687 if (This
->data_queue
!= NULL
)
688 HeapFree(GetProcessHeap(),0,This
->data_queue
);
690 /* Install the previous event handler (in case of releasing an aquired
692 if (This
->prev_handler
!= NULL
)
693 MOUSE_Enable(This
->prev_handler
);
695 HeapFree(GetProcessHeap(),0,This
);
700 /******************************************************************************
701 * SetCooperativeLevel : store the window in which we will do our
704 static HRESULT WINAPI
SysMouseAImpl_SetCooperativeLevel(
705 LPDIRECTINPUTDEVICE2A iface
,HWND hwnd
,DWORD dwflags
708 ICOM_THIS(SysMouseAImpl
,iface
);
710 TRACE(dinput
,"(this=%p,0x%08lx,0x%08lx): stub\n",This
,(DWORD
)hwnd
,dwflags
);
712 if (TRACE_ON(dinput
))
713 _dump_cooperativelevel(dwflags
);
715 /* Store the window which asks for the mouse */
722 /******************************************************************************
723 * SetDataFormat : the application can choose the format of the data
724 * the device driver sends back with GetDeviceState.
726 * For the moment, only the "standard" configuration (c_dfDIMouse) is supported
727 * in absolute and relative mode.
729 static HRESULT WINAPI
SysMouseAImpl_SetDataFormat(
730 LPDIRECTINPUTDEVICE2A iface
,LPCDIDATAFORMAT df
733 ICOM_THIS(SysMouseAImpl
,iface
);
736 TRACE(dinput
,"(this=%p,%p)\n",This
,df
);
738 TRACE(dinput
,"(df.dwSize=%ld)\n",df
->dwSize
);
739 TRACE(dinput
,"(df.dwObjsize=%ld)\n",df
->dwObjSize
);
740 TRACE(dinput
,"(df.dwFlags=0x%08lx)\n",df
->dwFlags
);
741 TRACE(dinput
,"(df.dwDataSize=%ld)\n",df
->dwDataSize
);
742 TRACE(dinput
,"(df.dwNumObjs=%ld)\n",df
->dwNumObjs
);
744 for (i
=0;i
<df
->dwNumObjs
;i
++) {
747 if (df
->rgodf
[i
].pguid
)
748 WINE_StringFromCLSID(df
->rgodf
[i
].pguid
,xbuf
);
750 strcpy(xbuf
,"<no guid>");
751 TRACE(dinput
,"df.rgodf[%d].guid %s (%p)\n",i
,xbuf
, df
->rgodf
[i
].pguid
);
752 TRACE(dinput
,"df.rgodf[%d].dwOfs %ld\n",i
,df
->rgodf
[i
].dwOfs
);
753 TRACE(dinput
,"dwType 0x%02x,dwInstance %d\n",DIDFT_GETTYPE(df
->rgodf
[i
].dwType
),DIDFT_GETINSTANCE(df
->rgodf
[i
].dwType
));
754 TRACE(dinput
,"df.rgodf[%d].dwFlags 0x%08lx\n",i
,df
->rgodf
[i
].dwFlags
);
757 /* Check size of data format to prevent crashes if the applications
758 sends a smaller buffer */
759 if (df
->dwDataSize
!= sizeof(struct DIMOUSESTATE
)) {
760 FIXME(dinput
, "non-standard mouse configuration not supported yet.");
761 return DIERR_INVALIDPARAM
;
764 /* For the moment, ignore these fields and return always as if
765 c_dfDIMouse was passed as format... */
767 /* Check if the mouse is in absolute or relative mode */
768 if (df
->dwFlags
== DIDF_ABSAXIS
)
776 #define GEN_EVENT(offset,data,time,seq) \
778 if (This->queue_pos < This->queue_len) { \
779 This->data_queue[This->queue_pos].dwOfs = offset; \
780 This->data_queue[This->queue_pos].dwData = data; \
781 This->data_queue[This->queue_pos].dwTimeStamp = time; \
782 This->data_queue[This->queue_pos].dwSequence = seq; \
787 /* Our private mouse event handler */
788 static void WINAPI
dinput_mouse_event( DWORD dwFlags
, DWORD dx
, DWORD dy
,
789 DWORD cButtons
, DWORD dwExtraInfo
)
791 DWORD posX
, posY
, keyState
, time
, extra
;
792 SysMouseAImpl
* This
= (SysMouseAImpl
*) current_lock
;
794 if ( !IsBadReadPtr( (LPVOID
)dwExtraInfo
, sizeof(WINE_MOUSEEVENT
) )
795 && ((WINE_MOUSEEVENT
*)dwExtraInfo
)->magic
== WINE_MOUSEEVENT_MAGIC
) {
796 WINE_MOUSEEVENT
*wme
= (WINE_MOUSEEVENT
*)dwExtraInfo
;
797 keyState
= wme
->keyState
;
799 extra
= (DWORD
)wme
->hWnd
;
801 assert( dwFlags
& MOUSEEVENTF_ABSOLUTE
);
802 posX
= (dx
* SYSMETRICS_CXSCREEN
) >> 16;
803 posY
= (dy
* SYSMETRICS_CYSCREEN
) >> 16;
805 ERR(dinput
, "Mouse event not supported...\n");
809 TRACE(dinput
, " %ld %ld ", posX
, posY
);
811 if ( dwFlags
& MOUSEEVENTF_MOVE
) {
812 if (This
->absolute
) {
813 if (posX
!= This
->prevX
)
814 GEN_EVENT(DIMOFS_X
, posX
, time
, 0);
815 if (posY
!= This
->prevY
)
816 GEN_EVENT(DIMOFS_Y
, posY
, time
, 0);
818 /* Relative mouse input : the real fun starts here... */
819 if (This
->need_warp
) {
820 if (posX
!= This
->prevX
)
821 GEN_EVENT(DIMOFS_X
, posX
- This
->prevX
, time
, 0);
822 if (posY
!= This
->prevY
)
823 GEN_EVENT(DIMOFS_Y
, posY
- This
->prevY
, time
, 0);
825 /* This is the first time the event handler has been called after a
826 GetData of GetState. */
827 if (posX
!= This
->win_centerX
) {
828 GEN_EVENT(DIMOFS_X
, posX
- This
->win_centerX
, time
, 0);
832 if (posY
!= This
->win_centerY
) {
833 GEN_EVENT(DIMOFS_Y
, posY
- This
->win_centerY
, time
, 0);
839 if ( dwFlags
& MOUSEEVENTF_LEFTDOWN
) {
840 if (TRACE_ON(dinput
))
843 GEN_EVENT(DIMOFS_BUTTON0
, 0xFF, time
, 0);
845 if ( dwFlags
& MOUSEEVENTF_LEFTUP
) {
846 if (TRACE_ON(dinput
))
849 GEN_EVENT(DIMOFS_BUTTON0
, 0x00, time
, 0);
851 if ( dwFlags
& MOUSEEVENTF_RIGHTDOWN
) {
852 if (TRACE_ON(dinput
))
855 GEN_EVENT(DIMOFS_BUTTON1
, 0xFF, time
, 0);
857 if ( dwFlags
& MOUSEEVENTF_RIGHTUP
) {
858 if (TRACE_ON(dinput
))
861 GEN_EVENT(DIMOFS_BUTTON1
, 0x00, time
, 0);
863 if ( dwFlags
& MOUSEEVENTF_MIDDLEDOWN
) {
864 if (TRACE_ON(dinput
))
867 GEN_EVENT(DIMOFS_BUTTON2
, 0xFF, time
, 0);
869 if ( dwFlags
& MOUSEEVENTF_MIDDLEUP
) {
870 if (TRACE_ON(dinput
))
873 GEN_EVENT(DIMOFS_BUTTON2
, 0x00, time
, 0);
875 if (TRACE_ON(dinput
))
883 /******************************************************************************
884 * Acquire : gets exclusive control of the mouse
886 static HRESULT WINAPI
SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE2A iface
)
888 ICOM_THIS(SysMouseAImpl
,iface
);
891 TRACE(dinput
,"(this=%p)\n",This
);
893 if (This
->acquired
== 0) {
894 /* This stores the current mouse handler.
895 FIXME : need to be fixed for native USER use */
896 This
->prev_handler
= mouse_event
;
898 /* Store (in a global variable) the current lock */
899 current_lock
= (IDirectInputDevice2A
*)This
;
901 /* Install our own mouse event handler */
902 MOUSE_Enable(dinput_mouse_event
);
904 /* Get the window dimension and find the center */
905 GetWindowRect(This
->win
, &rect
);
906 This
->xwin
= ((X11DRV_WND_DATA
*) WIN_FindWndPtr(This
->win
)->pDriverData
)->window
;
907 This
->win_centerX
= (rect
.right
- rect
.left
) / 2;
908 This
->win_centerY
= (rect
.bottom
- rect
.top
) / 2;
909 /* Warp the mouse to the center of the window */
910 TRACE(dinput
, "Warping mouse to %ld - %ld\n", This
->win_centerX
, This
->win_centerY
);
911 TSXWarpPointer(display
, DefaultRootWindow(display
),
912 This
->xwin
, 0, 0, 0, 0,
913 This
->win_centerX
, This
->win_centerY
);
920 /******************************************************************************
921 * Unacquire : frees the mouse
923 static HRESULT WINAPI
SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE2A iface
)
925 ICOM_THIS(SysMouseAImpl
,iface
);
927 TRACE(dinput
,"(this=%p)\n",This
);
929 /* Reinstall previous mouse event handler */
930 MOUSE_Enable(This
->prev_handler
);
931 This
->prev_handler
= NULL
;
936 /* Unacquire device */
942 /******************************************************************************
943 * GetDeviceState : returns the "state" of the mouse.
945 * For the moment, only the "standard" return structure (DIMOUSESTATE) is
948 static HRESULT WINAPI
SysMouseAImpl_GetDeviceState(
949 LPDIRECTINPUTDEVICE2A iface
,DWORD len
,LPVOID ptr
951 ICOM_THIS(SysMouseAImpl
,iface
);
953 struct DIMOUSESTATE
*mstate
= (struct DIMOUSESTATE
*) ptr
;
955 TRACE(dinput
,"(this=%p,0x%08lx,%p): \n",This
,len
,ptr
);
957 /* Check if the buffer is big enough */
958 if (len
< sizeof(struct DIMOUSESTATE
)) {
959 FIXME(dinput
, "unsupported state structure.");
960 return DIERR_INVALIDPARAM
;
963 /* Get the mouse position */
964 EVENT_QueryPointer(&rx
, &ry
, &state
);
965 TRACE(dinput
,"(X:%ld - Y:%ld)\n", rx
, ry
);
967 /* Fill the mouse state structure */
968 if (This
->absolute
) {
972 mstate
->lX
= rx
- This
->win_centerX
;
973 mstate
->lY
= ry
- This
->win_centerY
;
975 if ((mstate
->lX
!= 0) || (mstate
->lY
!= 0))
979 mstate
->rgbButtons
[0] = (state
& MK_LBUTTON
? 0xFF : 0x00);
980 mstate
->rgbButtons
[1] = (state
& MK_RBUTTON
? 0xFF : 0x00);
981 mstate
->rgbButtons
[2] = (state
& MK_MBUTTON
? 0xFF : 0x00);
982 mstate
->rgbButtons
[3] = 0x00;
984 /* Check if we need to do a mouse warping */
985 if (This
->need_warp
) {
986 TRACE(dinput
, "Warping mouse to %ld - %ld\n", This
->win_centerX
, This
->win_centerY
);
987 TSXWarpPointer(display
, DefaultRootWindow(display
),
988 This
->xwin
, 0, 0, 0, 0,
989 This
->win_centerX
, This
->win_centerY
);
993 TRACE(dinput
, "(X: %ld - Y: %ld L: %02x M: %02x R: %02x)\n",
994 mstate
->lX
, mstate
->lY
,
995 mstate
->rgbButtons
[0], mstate
->rgbButtons
[2], mstate
->rgbButtons
[1]);
1000 /******************************************************************************
1001 * GetDeviceState : gets buffered input data.
1003 static HRESULT WINAPI
SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE2A iface
,
1005 LPDIDEVICEOBJECTDATA dod
,
1009 ICOM_THIS(SysMouseAImpl
,iface
);
1011 TRACE(dinput
,"(%p)->(%ld,%p,%p(0x%08lx),0x%08lx)\n",
1012 This
,dodsize
,dod
,entries
,*entries
,flags
);
1014 if (flags
& DIGDD_PEEK
)
1015 TRACE(dinput
, "DIGDD_PEEK\n");
1018 *entries
= This
->queue_pos
;
1019 This
->queue_pos
= 0;
1021 /* Check for buffer overflow */
1022 if (This
->queue_pos
> *entries
) {
1023 WARN(dinput
, "Buffer overflow not handled properly yet...\n");
1024 This
->queue_pos
= *entries
;
1026 if (dodsize
!= sizeof(DIDEVICEOBJECTDATA
)) {
1027 ERR(dinput
, "Wrong structure size !\n");
1028 return DIERR_INVALIDPARAM
;
1031 TRACE(dinput
, "Application retrieving %d event(s).\n", This
->queue_pos
);
1033 /* Copy the buffered data into the application queue */
1034 memcpy(dod
, This
->data_queue
, This
->queue_pos
* dodsize
);
1036 /* Reset the event queue */
1037 This
->queue_pos
= 0;
1040 /* Check if we need to do a mouse warping */
1041 if (This
->need_warp
) {
1042 TRACE(dinput
, "Warping mouse to %ld - %ld\n", This
->win_centerX
, This
->win_centerY
);
1043 TSXWarpPointer(display
, DefaultRootWindow(display
),
1044 This
->xwin
, 0, 0, 0, 0,
1045 This
->win_centerX
, This
->win_centerY
);
1046 This
->need_warp
= 0;
1052 /******************************************************************************
1053 * SetProperty : change input device properties
1055 static HRESULT WINAPI
SysMouseAImpl_SetProperty(LPDIRECTINPUTDEVICE2A iface
,
1059 ICOM_THIS(SysMouseAImpl
,iface
);
1063 WINE_StringFromCLSID(rguid
,xbuf
);
1065 sprintf(xbuf
,"<special guid %ld>",(DWORD
)rguid
);
1067 TRACE(dinput
,"(this=%p,%s,%p)\n",This
,xbuf
,ph
);
1069 if (!HIWORD(rguid
)) {
1070 switch ((DWORD
)rguid
) {
1071 case DIPROP_BUFFERSIZE
: {
1072 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
1074 TRACE(dinput
,"buffersize = %ld\n",pd
->dwData
);
1076 This
->data_queue
= (LPDIDEVICEOBJECTDATA
)HeapAlloc(GetProcessHeap(),0,
1077 pd
->dwData
* sizeof(DIDEVICEOBJECTDATA
));
1078 This
->queue_pos
= 0;
1079 This
->queue_len
= pd
->dwData
;
1083 WARN(dinput
,"Unknown type %ld\n",(DWORD
)rguid
);
1092 static ICOM_VTABLE(IDirectInputDevice2A
) SysKeyboardAvt
={
1093 IDirectInputDevice2AImpl_QueryInterface
,
1094 IDirectInputDevice2AImpl_AddRef
,
1095 IDirectInputDevice2AImpl_Release
,
1096 IDirectInputDevice2AImpl_GetCapabilities
,
1097 IDirectInputDevice2AImpl_EnumObjects
,
1098 IDirectInputDevice2AImpl_GetProperty
,
1099 SysKeyboardAImpl_SetProperty
,
1100 SysKeyboardAImpl_Acquire
,
1101 SysKeyboardAImpl_Unacquire
,
1102 SysKeyboardAImpl_GetDeviceState
,
1103 SysKeyboardAImpl_GetDeviceData
,
1104 IDirectInputDevice2AImpl_SetDataFormat
,
1105 IDirectInputDevice2AImpl_SetEventNotification
,
1106 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1107 IDirectInputDevice2AImpl_GetObjectInfo
,
1108 IDirectInputDevice2AImpl_GetDeviceInfo
,
1109 IDirectInputDevice2AImpl_RunControlPanel
,
1110 IDirectInputDevice2AImpl_Initialize
,
1111 IDirectInputDevice2AImpl_CreateEffect
,
1112 IDirectInputDevice2AImpl_EnumEffects
,
1113 IDirectInputDevice2AImpl_GetEffectInfo
,
1114 IDirectInputDevice2AImpl_GetForceFeedbackState
,
1115 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
1116 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
1117 IDirectInputDevice2AImpl_Escape
,
1118 IDirectInputDevice2AImpl_Poll
,
1119 IDirectInputDevice2AImpl_SendDeviceData
,
1122 static ICOM_VTABLE(IDirectInputDevice2A
) SysMouseAvt
={
1123 IDirectInputDevice2AImpl_QueryInterface
,
1124 IDirectInputDevice2AImpl_AddRef
,
1125 SysMouseAImpl_Release
,
1126 IDirectInputDevice2AImpl_GetCapabilities
,
1127 IDirectInputDevice2AImpl_EnumObjects
,
1128 IDirectInputDevice2AImpl_GetProperty
,
1129 SysMouseAImpl_SetProperty
,
1130 SysMouseAImpl_Acquire
,
1131 SysMouseAImpl_Unacquire
,
1132 SysMouseAImpl_GetDeviceState
,
1133 SysMouseAImpl_GetDeviceData
,
1134 SysMouseAImpl_SetDataFormat
,
1135 IDirectInputDevice2AImpl_SetEventNotification
,
1136 SysMouseAImpl_SetCooperativeLevel
,
1137 IDirectInputDevice2AImpl_GetObjectInfo
,
1138 IDirectInputDevice2AImpl_GetDeviceInfo
,
1139 IDirectInputDevice2AImpl_RunControlPanel
,
1140 IDirectInputDevice2AImpl_Initialize
,
1141 IDirectInputDevice2AImpl_CreateEffect
,
1142 IDirectInputDevice2AImpl_EnumEffects
,
1143 IDirectInputDevice2AImpl_GetEffectInfo
,
1144 IDirectInputDevice2AImpl_GetForceFeedbackState
,
1145 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
1146 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
1147 IDirectInputDevice2AImpl_Escape
,
1148 IDirectInputDevice2AImpl_Poll
,
1149 IDirectInputDevice2AImpl_SendDeviceData
,