From: Lucas Fialho Zawacki Subject: [PATCH 1/6] dinput: EnumDevicesBySemantics enumerating keyboard and mouse with priority flags (try 2) Message-Id: <1308769494-2517-1-git-send-email-lfzawacki@gmail.com> Date: Wed, 22 Jun 2011 16:04:54 -0300 Corrected COM cross calls as suggested by Vitaly. Straightened spacing through all the patches. Not zeroing memory where it's not necessary anymore. --- dlls/dinput/dinput_main.c | 69 ++++++++++++++++++++++++++++++++++++++--- dlls/dinput/dinput_private.h | 3 ++ 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index d3727bc..4d22cb1 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -681,8 +681,13 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( ) { IDirectInputImpl *This = impl_from_IDirectInput8A( iface ); + DIDEVICEINSTANCEA didevi; + LPDIRECTINPUTDEVICE8A lpdid; + BOOL ret; /* for the callback return */ + DWORD callbackFlags = 0; + int i; - FIXME("(this=%p,%s,%p,%p,%p,%04x): stub\n", This, ptszUserName, lpdiActionFormat, + FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This, ptszUserName, lpdiActionFormat, lpCallback, pvRef, dwFlags); #define X(x) if (dwFlags & x) FIXME("\tdwFlags |= "#x"\n"); X(DIEDBSFL_ATTACHEDONLY) @@ -695,6 +700,30 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( _dump_diactionformatA(lpdiActionFormat); + didevi.dwSize = sizeof(didevi); + + /* enum the keyboard first */ + IDirectInput_CreateDevice(iface, &GUID_SysKeyboard, &lpdid, NULL); + IDirectInputDevice_GetDeviceInfo(lpdid, &didevi); + /* if there's any DIKEYBOARD action, keyboard is priority 1*/ + for(i=0; i < lpdiActionFormat->dwActionSize; i++) + if ((lpdiActionFormat->rgoAction[i].dwSemantic & 0xff000000) == DIKEYBOARD_MASK) + callbackFlags |= DIEDBS_MAPPEDPRI1; + + ret = lpCallback(&didevi, lpdid, callbackFlags, 1, pvRef); + + if (ret == DIENUM_STOP) return DI_OK; + + /* and then the mouse */ + IDirectInput_CreateDevice(iface, &GUID_SysMouse, &lpdid, NULL); + IDirectInputDevice_GetDeviceInfo(lpdid, &didevi); + /* same as above, but for the mouse */ + for(i=0; i < lpdiActionFormat->dwActionSize; i++) + if ((lpdiActionFormat->rgoAction[i].dwSemantic & 0xff000000) == DIMOUSE_MASK) + callbackFlags |= DIEDBS_MAPPEDPRI1; + + ret = lpCallback(&didevi, lpdid, callbackFlags, 0, pvRef); + return DI_OK; } @@ -704,11 +733,41 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics( LPVOID pvRef, DWORD dwFlags ) { - IDirectInputImpl *This = impl_from_IDirectInput8W( iface ); + IDirectInputImpl *This = impl_from_IDirectInput8W( iface ); + DIDEVICEINSTANCEW didevi; + LPDIRECTINPUTDEVICE8W lpdid; + BOOL ret; /* for the callback return */ + DWORD callbackFlags = 0; + int i; - FIXME("(this=%p,%s,%p,%p,%p,%04x): stub\n", This, debugstr_w(ptszUserName), lpdiActionFormat, - lpCallback, pvRef, dwFlags); - return 0; + FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This, debugstr_w(ptszUserName), lpdiActionFormat, + lpCallback, pvRef, dwFlags); + + didevi.dwSize = sizeof(didevi); + + /* enum the keyboard first */ + IDirectInput_CreateDevice(iface, &GUID_SysKeyboard, &lpdid, NULL); + IDirectInputDevice_GetDeviceInfo(lpdid, &didevi); + /* if there's any DIKEYBOARD action, keyboard is priority 1*/ + for(i=0; i < lpdiActionFormat->dwActionSize; i++) + if ((lpdiActionFormat->rgoAction[i].dwSemantic & 0xff000000) == DIKEYBOARD_MASK) + callbackFlags |= DIEDBS_MAPPEDPRI1; + + ret = lpCallback(&didevi, lpdid, callbackFlags, 1, pvRef); + + if (ret == DIENUM_STOP) return DI_OK; + + /* and then the mouse */ + IDirectInput_CreateDevice(iface, &GUID_SysMouse, &lpdid, NULL); + IDirectInputDevice_GetDeviceInfo(lpdid, &didevi); + /* same as above, but for the mouse */ + for(i=0; i < lpdiActionFormat->dwActionSize; i++) + if ((lpdiActionFormat->rgoAction[i].dwSemantic & 0xff000000) == DIMOUSE_MASK) + callbackFlags |= DIEDBS_MAPPEDPRI1; + + ret = lpCallback(&didevi, lpdid, callbackFlags, 0, pvRef); + + return DI_OK; } static HRESULT WINAPI IDirectInput8AImpl_ConfigureDevices( diff --git a/dlls/dinput/dinput_private.h b/dlls/dinput/dinput_private.h index 5972081..33cc823 100644 --- a/dlls/dinput/dinput_private.h +++ b/dlls/dinput/dinput_private.h @@ -66,4 +66,7 @@ extern void _dump_diactionformatA(LPDIACTIONFORMATA) DECLSPEC_HIDDEN; #define IS_DIPROP(x) (((ULONG_PTR)(x) >> 16) == 0) +#define DIKEYBOARD_MASK 0x81000000 +#define DIMOUSE_MASK 0x82000000 + #endif /* __WINE_DLLS_DINPUT_DINPUT_PRIVATE_H */ -- 1.7.0.4