From 0f17c828f7381ddd606e17347a7ee32347c167fd Mon Sep 17 00:00:00 2001 From: Lucas Fialho Zawacki Date: Tue, 28 Jun 2011 13:54:36 -0300 Subject: [PATCH] dinput: EnumDevicesBySemantics enumerating keyboard and mouse with priority flags. --- dlls/dinput/dinput_main.c | 73 +++++++++++++++++++++++++++++++++++++++++--- dlls/dinput/dinput_private.h | 3 ++ dlls/dinput8/tests/device.c | 10 +++--- 3 files changed, 76 insertions(+), 10 deletions(-) diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index d3727bcb570..c032642e9c5 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; + 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,32 @@ 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 & DIKEYBOARD_MASK) == DIKEYBOARD_MASK) + callbackFlags |= DIEDBS_MAPPEDPRI1; + + ret = lpCallback(&didevi, lpdid, callbackFlags, 1, pvRef); + + if (ret == DIENUM_STOP) return DI_OK; + + callbackFlags = 0; + + /* 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 & DIMOUSE_MASK) == DIMOUSE_MASK) + callbackFlags |= DIEDBS_MAPPEDPRI1; + + lpCallback(&didevi, lpdid, callbackFlags, 0, pvRef); + return DI_OK; } @@ -704,11 +735,43 @@ 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; + 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 & DIKEYBOARD_MASK) == DIKEYBOARD_MASK) + callbackFlags |= DIEDBS_MAPPEDPRI1; + + ret = lpCallback(&didevi, lpdid, callbackFlags, 1, pvRef); + + if (ret == DIENUM_STOP) return DI_OK; + + callbackFlags = 0; + + /* 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 & DIMOUSE_MASK) == DIMOUSE_MASK) + callbackFlags |= DIEDBS_MAPPEDPRI1; + + 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 5972081f7c9..33cc8230fd8 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 */ diff --git a/dlls/dinput8/tests/device.c b/dlls/dinput8/tests/device.c index 992821da368..83444862bf4 100644 --- a/dlls/dinput8/tests/device.c +++ b/dlls/dinput8/tests/device.c @@ -68,7 +68,7 @@ static BOOL CALLBACK enumeration_callback( IDirectInputDevice_AddRef(lpdid); data->keyboard = lpdid; - todo_wine ok (dwFlags & DIEDBS_MAPPEDPRI1, "Keyboard should be mapped as pri1 dwFlags=%08x\n", dwFlags); + ok (dwFlags & DIEDBS_MAPPEDPRI1, "Keyboard should be mapped as pri1 dwFlags=%08x\n", dwFlags); } if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysMouse)) @@ -76,7 +76,7 @@ static BOOL CALLBACK enumeration_callback( IDirectInputDevice_AddRef(lpdid); data->mouse = lpdid; - todo_wine ok (dwFlags & DIEDBS_MAPPEDPRI1, "Mouse should be mapped as pri1 dwFlags=%08x\n", dwFlags); + ok (dwFlags & DIEDBS_MAPPEDPRI1, "Mouse should be mapped as pri1 dwFlags=%08x\n", dwFlags); } return DIENUM_CONTINUE; @@ -122,9 +122,9 @@ static void test_action_mapping(void) hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, &data, 0); ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr); - todo_wine ok (data.ndevices > 0, "EnumDevicesBySemantics did not call the callback hr=%08x\n", hr); - todo_wine ok (data.keyboard != NULL, "EnumDevicesBySemantics should enumerate the keyboard\n"); - todo_wine ok (data.mouse != NULL, "EnumDevicesBySemantics should enumerate the mouse\n"); + ok (data.ndevices > 0, "EnumDevicesBySemantics did not call the callback hr=%08x\n", hr); + ok (data.keyboard != NULL, "EnumDevicesBySemantics should enumerate the keyboard\n"); + ok (data.mouse != NULL, "EnumDevicesBySemantics should enumerate the mouse\n"); /* The call fails with a zeroed GUID */ memset(&af.guidActionMap, 0, sizeof(GUID)); -- 2.11.4.GIT