Created
August 20, 2011 18:59
-
-
Save lfzawacki/1159498 to your computer and use it in GitHub Desktop.
EnumDevicesBySemantics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From ff9900e11c47341431bd8a9a574520e514686086 Mon Sep 17 00:00:00 2001 | |
From: Lucas Fialho Zawacki <lfzawacki@gmail.com> | |
Date: Thu, 11 Aug 2011 21:41:50 -0300 | |
Subject: dinput: Refactor of EnumDevicesBySemantics and proper remaining devices count. | |
In addition to that, the devices are now realeased after the callback is over. | |
--- | |
dlls/dinput/dinput_main.c | 129 ++++++++++++++++++++++++++------------------ | |
dlls/dinput/keyboard.c | 6 ++ | |
dlls/dinput/mouse.c | 6 ++ | |
3 files changed, 88 insertions(+), 53 deletions(-) | |
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c | |
index a6d4a5c..8f8da7e 100644 | |
--- a/dlls/dinput/dinput_main.c | |
+++ b/dlls/dinput/dinput_main.c | |
@@ -919,14 +919,10 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( | |
LPVOID pvRef, DWORD dwFlags | |
) | |
{ | |
- static REFGUID guids[2] = { &GUID_SysKeyboard, &GUID_SysMouse }; | |
- static const DWORD actionMasks[] = { DIKEYBOARD_MASK, DIMOUSE_MASK }; | |
IDirectInputImpl *This = impl_from_IDirectInput8A( iface ); | |
DIDEVICEINSTANCEA didevi; | |
- LPDIRECTINPUTDEVICE8A lpdid; | |
- DWORD callbackFlags; | |
- int i, j; | |
- | |
+ IDirectInputDevice8A *lpdid; | |
+ int i, j, remaining = 0; | |
FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This, ptszUserName, lpdiActionFormat, | |
lpCallback, pvRef, dwFlags); | |
@@ -943,8 +939,22 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( | |
didevi.dwSize = sizeof(didevi); | |
- /* Enumerate all the joysticks */ | |
- for (i = 0; i < NB_DINPUT_DEVICES; i++) | |
+ /* Count the devices */ | |
+ for (i = NB_DINPUT_DEVICES-1; i >= 0 ; i--) | |
+ { | |
+ BOOL enumSuccess; | |
+ if (!dinput_devices[i]->enum_deviceA) continue; | |
+ | |
+ for (j = 0, enumSuccess = -1; enumSuccess != 0; j++) | |
+ { | |
+ enumSuccess = dinput_devices[i]->enum_deviceA(DI8DEVCLASS_ALL, DIEDFL_ATTACHEDONLY | dwFlags, &didevi, This->dwVersion, j); | |
+ | |
+ if (enumSuccess) remaining++; | |
+ } | |
+ } | |
+ | |
+ /* Enumerate each of the devices */ | |
+ for (i = NB_DINPUT_DEVICES-1; i >= 0 ; i--) | |
{ | |
BOOL enumSuccess; | |
@@ -954,31 +964,32 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( | |
{ | |
TRACE(" - checking device %u ('%s')\n", i, dinput_devices[i]->name); | |
- callbackFlags = _diactionformat_priorityA(lpdiActionFormat, lpdiActionFormat->dwGenre); | |
- /* Default behavior is to enumerate attached game controllers */ | |
- enumSuccess = dinput_devices[i]->enum_deviceA(DI8DEVCLASS_GAMECTRL, DIEDFL_ATTACHEDONLY | dwFlags, &didevi, This->dwVersion, j); | |
+ /* Default behavior is to enumerate all attached devices */ | |
+ enumSuccess = dinput_devices[i]->enum_deviceA(DI8DEVCLASS_ALL, DIEDFL_ATTACHEDONLY | dwFlags, &didevi, This->dwVersion, j); | |
+ | |
if (enumSuccess) | |
{ | |
- IDirectInput_CreateDevice(iface, &didevi.guidInstance, &lpdid, NULL); | |
- | |
- if (lpCallback(&didevi, lpdid, callbackFlags, 0, pvRef) == DIENUM_STOP) | |
- return DI_OK; | |
- } | |
- } | |
- } | |
+ BOOL cb_return = DIENUM_CONTINUE; | |
+ DWORD callbackFlags = 0; | |
- if (dwFlags & DIEDBSFL_FORCEFEEDBACK) return DI_OK; | |
+ remaining--; | |
+ IDirectInput_CreateDevice(iface, &didevi.guidInstance, &lpdid, NULL); | |
- /* Enumerate keyboard and mouse */ | |
- for(i=0; i < sizeof(guids)/sizeof(guids[0]); i++) | |
- { | |
- callbackFlags = _diactionformat_priorityA(lpdiActionFormat, actionMasks[i]); | |
+ /* Assign priority flags */ | |
+ if (GET_DIDEVICE_TYPE(didevi.dwDevType) == DI8DEVTYPE_KEYBOARD) | |
+ callbackFlags = _diactionformat_priorityA(lpdiActionFormat, DIKEYBOARD_MASK); | |
+ else if (GET_DIDEVICE_TYPE(didevi.dwDevType) == DI8DEVTYPE_MOUSE) | |
+ callbackFlags = _diactionformat_priorityA(lpdiActionFormat, DIMOUSE_MASK); | |
+ else | |
+ callbackFlags = _diactionformat_priorityA(lpdiActionFormat, lpdiActionFormat->dwGenre); | |
- IDirectInput_CreateDevice(iface, guids[i], &lpdid, NULL); | |
- IDirectInputDevice_GetDeviceInfo(lpdid, &didevi); | |
+ cb_return = lpCallback(&didevi, lpdid, callbackFlags, remaining, pvRef); | |
- if (lpCallback(&didevi, lpdid, callbackFlags, sizeof(guids)/sizeof(guids[0]) - (i+1), pvRef) == DIENUM_STOP) | |
- return DI_OK; | |
+ /* Cleanup */ | |
+ IDirectInputDevice_Release(lpdid); | |
+ if (cb_return == DIENUM_STOP) return DI_OK; | |
+ } | |
+ } | |
} | |
return DI_OK; | |
@@ -990,21 +1001,32 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics( | |
LPVOID pvRef, DWORD dwFlags | |
) | |
{ | |
- static REFGUID guids[2] = { &GUID_SysKeyboard, &GUID_SysMouse }; | |
- static const DWORD actionMasks[] = { DIKEYBOARD_MASK, DIMOUSE_MASK }; | |
IDirectInputImpl *This = impl_from_IDirectInput8W(iface); | |
DIDEVICEINSTANCEW didevi; | |
- LPDIRECTINPUTDEVICE8W lpdid; | |
- DWORD callbackFlags; | |
- int i, j; | |
+ IDirectInputDevice8W *lpdid; | |
+ int i, j, remaining = 0; | |
FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This, debugstr_w(ptszUserName), lpdiActionFormat, | |
lpCallback, pvRef, dwFlags); | |
didevi.dwSize = sizeof(didevi); | |
- /* Enumerate all the joysticks */ | |
- for (i = 0; i < NB_DINPUT_DEVICES; i++) | |
+ /* Count the devices */ | |
+ for (i = NB_DINPUT_DEVICES-1; i >= 0 ; i--) | |
+ { | |
+ BOOL enumSuccess; | |
+ if (!dinput_devices[i]->enum_deviceW) continue; | |
+ | |
+ for (j = 0, enumSuccess = -1; enumSuccess != 0; j++) | |
+ { | |
+ enumSuccess = dinput_devices[i]->enum_deviceW(DI8DEVCLASS_ALL, DIEDFL_ATTACHEDONLY | dwFlags, &didevi, This->dwVersion, j); | |
+ | |
+ if (enumSuccess) remaining++; | |
+ } | |
+ } | |
+ | |
+ /* Enumerate each of the devices */ | |
+ for (i = NB_DINPUT_DEVICES-1; i >= 0 ; i--) | |
{ | |
BOOL enumSuccess; | |
@@ -1014,31 +1036,32 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics( | |
{ | |
TRACE(" - checking device %u ('%s')\n", i, dinput_devices[i]->name); | |
- callbackFlags = _diactionformat_priorityW(lpdiActionFormat, lpdiActionFormat->dwGenre); | |
- /* Default behavior is to enumerate attached game controllers */ | |
- enumSuccess = dinput_devices[i]->enum_deviceW(DI8DEVCLASS_GAMECTRL, DIEDFL_ATTACHEDONLY | dwFlags, &didevi, This->dwVersion, j); | |
+ /* Default behavior is to enumerate all attached devices */ | |
+ enumSuccess = dinput_devices[i]->enum_deviceW(DI8DEVCLASS_ALL, DIEDFL_ATTACHEDONLY | dwFlags, &didevi, This->dwVersion, j); | |
+ | |
if (enumSuccess) | |
{ | |
- IDirectInput_CreateDevice(iface, &didevi.guidInstance, &lpdid, NULL); | |
- | |
- if (lpCallback(&didevi, lpdid, callbackFlags, 0, pvRef) == DIENUM_STOP) | |
- return DI_OK; | |
- } | |
- } | |
- } | |
+ BOOL cb_return = DIENUM_CONTINUE; | |
+ DWORD callbackFlags = 0; | |
- if (dwFlags & DIEDBSFL_FORCEFEEDBACK) return DI_OK; | |
+ remaining--; | |
+ IDirectInput_CreateDevice(iface, &didevi.guidInstance, &lpdid, NULL); | |
- /* Enumerate keyboard and mouse */ | |
- for(i=0; i < sizeof(guids)/sizeof(guids[0]); i++) | |
- { | |
- callbackFlags = _diactionformat_priorityW(lpdiActionFormat, actionMasks[i]); | |
+ /* Assign priority flags */ | |
+ if (GET_DIDEVICE_TYPE(didevi.dwDevType) == DI8DEVTYPE_KEYBOARD) | |
+ callbackFlags = _diactionformat_priorityW(lpdiActionFormat, DIKEYBOARD_MASK); | |
+ else if (GET_DIDEVICE_TYPE(didevi.dwDevType) == DI8DEVTYPE_MOUSE) | |
+ callbackFlags = _diactionformat_priorityW(lpdiActionFormat, DIMOUSE_MASK); | |
+ else | |
+ callbackFlags = _diactionformat_priorityW(lpdiActionFormat, lpdiActionFormat->dwGenre); | |
- IDirectInput_CreateDevice(iface, guids[i], &lpdid, NULL); | |
- IDirectInputDevice_GetDeviceInfo(lpdid, &didevi); | |
+ cb_return = lpCallback(&didevi, lpdid, callbackFlags, remaining, pvRef); | |
- if (lpCallback(&didevi, lpdid, callbackFlags, sizeof(guids)/sizeof(guids[0]) - (i+1), pvRef) == DIENUM_STOP) | |
- return DI_OK; | |
+ /* Cleanup */ | |
+ IDirectInputDevice_Release(lpdid); | |
+ if (cb_return == DIENUM_STOP) return DI_OK; | |
+ } | |
+ } | |
} | |
return DI_OK; | |
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c | |
index 4877469..6409b35 100644 | |
--- a/dlls/dinput/keyboard.c | |
+++ b/dlls/dinput/keyboard.c | |
@@ -189,6 +189,9 @@ static BOOL keyboarddev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEI | |
if (id != 0) | |
return FALSE; | |
+ if (dwFlags & DIEDFL_FORCEFEEDBACK) | |
+ return FALSE; | |
+ | |
if ((dwDevType == 0) || | |
((dwDevType == DIDEVTYPE_KEYBOARD) && (version < 0x0800)) || | |
(((dwDevType == DI8DEVCLASS_KEYBOARD) || (dwDevType == DI8DEVTYPE_KEYBOARD)) && (version >= 0x0800))) { | |
@@ -207,6 +210,9 @@ static BOOL keyboarddev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEI | |
if (id != 0) | |
return FALSE; | |
+ if (dwFlags & DIEDFL_FORCEFEEDBACK) | |
+ return FALSE; | |
+ | |
if ((dwDevType == 0) || | |
((dwDevType == DIDEVTYPE_KEYBOARD) && (version < 0x0800)) || | |
(((dwDevType == DI8DEVCLASS_KEYBOARD) || (dwDevType == DI8DEVTYPE_KEYBOARD)) && (version >= 0x0800))) { | |
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c | |
index 2890f93..5cd7939 100644 | |
--- a/dlls/dinput/mouse.c | |
+++ b/dlls/dinput/mouse.c | |
@@ -165,6 +165,9 @@ static BOOL mousedev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINST | |
if (id != 0) | |
return FALSE; | |
+ if (dwFlags & DIEDFL_FORCEFEEDBACK) | |
+ return FALSE; | |
+ | |
if ((dwDevType == 0) || | |
((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) || | |
(((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 0x0800))) { | |
@@ -183,6 +186,9 @@ static BOOL mousedev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINST | |
if (id != 0) | |
return FALSE; | |
+ if (dwFlags & DIEDFL_FORCEFEEDBACK) | |
+ return FALSE; | |
+ | |
if ((dwDevType == 0) || | |
((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) || | |
(((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 0x0800))) { | |
-- | |
1.7.0.4 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From c84c3f57f75ee00004b8bc1e460f81904e4f15ec Mon Sep 17 00:00:00 2001 | |
From: Lucas Fialho Zawacki <lfzawacki@gmail.com> | |
Date: Sun, 14 Aug 2011 23:20:14 -0300 | |
Subject: dinput: EnumDevicesBySemantics device usage flags | |
--- | |
dlls/dinput/device.c | 31 +++++++++++++++++++++++ | |
dlls/dinput/dinput_main.c | 55 ++++++++++++++++++++++++++++++++++++++++++ | |
dlls/dinput/dinput_private.h | 1 + | |
3 files changed, 87 insertions(+), 0 deletions(-) | |
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c | |
index 1068660..20b6ecf 100644 | |
--- a/dlls/dinput/device.c | |
+++ b/dlls/dinput/device.c | |
@@ -695,6 +695,37 @@ WCHAR* _get_mapping_path(const WCHAR *device, const WCHAR *username) | |
return ret; | |
} | |
+/* | |
+ * _get_mapping_time | |
+ * Retrieves a FILETIME structure indicating when this device was last mapped to this application | |
+ */ | |
+FILETIME _get_mapping_time(REFGUID app_guid, const WCHAR *device, const WCHAR* username) | |
+{ | |
+ FILETIME last; | |
+ WCHAR *guid_str, *time_high, *time_low, *map_path; | |
+ const char* guid_strA = debugstr_guid(app_guid); | |
+ int guid_size; | |
+ | |
+ guid_size = MultiByteToWideChar(CP_ACP, 0, guid_strA, -1, NULL, 0); | |
+ guid_str = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*guid_size); | |
+ MultiByteToWideChar(CP_ACP, 0, guid_strA, -1, guid_str, guid_size); | |
+ | |
+ time_high = heap_printfW("%s.TimestampHigh", guid_str); | |
+ time_low = heap_printfW("%s.TimestampLow", guid_str); | |
+ | |
+ map_path = _get_mapping_path(device, username); | |
+ | |
+ last.dwHighDateTime = GetPrivateProfileIntW(device, time_high, DIAFTS_NEWDEVICEHIGH, map_path); | |
+ last.dwLowDateTime = GetPrivateProfileIntW(device, time_low, DIAFTS_NEWDEVICELOW, map_path); | |
+ | |
+ HeapFree(GetProcessHeap(), 0, guid_str); | |
+ HeapFree(GetProcessHeap(), 0, time_high); | |
+ HeapFree(GetProcessHeap(), 0, time_low); | |
+ HeapFree(GetProcessHeap(), 0, map_path); | |
+ | |
+ return last; | |
+} | |
+ | |
static HRESULT _save_mapping_settings(IDirectInputDevice8W *iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUsername) | |
{ | |
DIDEVICEINSTANCEW didev; | |
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c | |
index 8f8da7e..35898c2 100644 | |
--- a/dlls/dinput/dinput_main.c | |
+++ b/dlls/dinput/dinput_main.c | |
@@ -922,6 +922,8 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( | |
IDirectInputImpl *This = impl_from_IDirectInput8A( iface ); | |
DIDEVICEINSTANCEA didevi; | |
IDirectInputDevice8A *lpdid; | |
+ WCHAR username[MAX_PATH]; | |
+ DWORD username_size = MAX_PATH; | |
int i, j, remaining = 0; | |
FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This, ptszUserName, lpdiActionFormat, | |
@@ -939,6 +941,11 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( | |
didevi.dwSize = sizeof(didevi); | |
+ if (ptszUserName == NULL) | |
+ GetUserNameW(username, &username_size); | |
+ else | |
+ MultiByteToWideChar(CP_ACP, 0, ptszUserName, -1, username, MAX_PATH); | |
+ | |
/* Count the devices */ | |
for (i = NB_DINPUT_DEVICES-1; i >= 0 ; i--) | |
{ | |
@@ -971,6 +978,19 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( | |
{ | |
BOOL cb_return = DIENUM_CONTINUE; | |
DWORD callbackFlags = 0; | |
+ SYSTEMTIME system_now; | |
+ FILETIME last_used, file_now; | |
+ WCHAR *dev_name; | |
+ int dev_name_size; | |
+ | |
+ /* WCHAR device name */ | |
+ dev_name_size = MultiByteToWideChar(CP_ACP, 0, didevi.tszInstanceName, -1, NULL, 0); | |
+ dev_name = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*dev_name_size); | |
+ MultiByteToWideChar(CP_ACP, 0, didevi.tszInstanceName, -1, dev_name, dev_name_size); | |
+ | |
+ last_used = _get_mapping_time(&lpdiActionFormat->guidActionMap, dev_name, username); | |
+ | |
+ HeapFree(GetProcessHeap(), 0, dev_name); | |
remaining--; | |
IDirectInput_CreateDevice(iface, &didevi.guidInstance, &lpdid, NULL); | |
@@ -983,6 +1003,18 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( | |
else | |
callbackFlags = _diactionformat_priorityA(lpdiActionFormat, lpdiActionFormat->dwGenre); | |
+ /* Compare with current time and assign usage flag */ | |
+ GetSystemTime(&system_now); | |
+ SystemTimeToFileTime(&system_now, &file_now); | |
+ | |
+ if (last_used.dwLowDateTime != 0 || last_used.dwHighDateTime != 0) | |
+ { | |
+ if (CompareFileTime(&last_used, &file_now) < 0) | |
+ callbackFlags |= DIEDBS_RECENTDEVICE; | |
+ else | |
+ callbackFlags |= DIEDBS_NEWDEVICE; | |
+ } | |
+ | |
cb_return = lpCallback(&didevi, lpdid, callbackFlags, remaining, pvRef); | |
/* Cleanup */ | |
@@ -1004,6 +1036,8 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics( | |
IDirectInputImpl *This = impl_from_IDirectInput8W(iface); | |
DIDEVICEINSTANCEW didevi; | |
IDirectInputDevice8W *lpdid; | |
+ WCHAR username[MAX_PATH]; | |
+ DWORD username_size = MAX_PATH; | |
int i, j, remaining = 0; | |
FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This, debugstr_w(ptszUserName), lpdiActionFormat, | |
@@ -1011,6 +1045,11 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics( | |
didevi.dwSize = sizeof(didevi); | |
+ if (ptszUserName == NULL) | |
+ GetUserNameW(username, &username_size); | |
+ else | |
+ lstrcpyW(username, ptszUserName); | |
+ | |
/* Count the devices */ | |
for (i = NB_DINPUT_DEVICES-1; i >= 0 ; i--) | |
{ | |
@@ -1043,6 +1082,10 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics( | |
{ | |
BOOL cb_return = DIENUM_CONTINUE; | |
DWORD callbackFlags = 0; | |
+ SYSTEMTIME system_now; | |
+ FILETIME last_used, file_now; | |
+ | |
+ last_used = _get_mapping_time(&lpdiActionFormat->guidActionMap, didevi.tszInstanceName, username); | |
remaining--; | |
IDirectInput_CreateDevice(iface, &didevi.guidInstance, &lpdid, NULL); | |
@@ -1055,6 +1098,18 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics( | |
else | |
callbackFlags = _diactionformat_priorityW(lpdiActionFormat, lpdiActionFormat->dwGenre); | |
+ /* Compare with current time and assign usage flag */ | |
+ GetSystemTime(&system_now); | |
+ SystemTimeToFileTime(&system_now, &file_now); | |
+ | |
+ if (last_used.dwLowDateTime != 0 || last_used.dwHighDateTime != 0) | |
+ { | |
+ if (CompareFileTime(&last_used, &file_now) < 0) | |
+ callbackFlags |= DIEDBS_RECENTDEVICE; | |
+ else | |
+ callbackFlags |= DIEDBS_NEWDEVICE; | |
+ } | |
+ | |
cb_return = lpCallback(&didevi, lpdid, callbackFlags, remaining, pvRef); | |
/* Cleanup */ | |
diff --git a/dlls/dinput/dinput_private.h b/dlls/dinput/dinput_private.h | |
index 0cafcab..e2e58e7 100644 | |
--- a/dlls/dinput/dinput_private.h | |
+++ b/dlls/dinput/dinput_private.h | |
@@ -68,6 +68,7 @@ extern void _copy_diactionformatWtoA(LPDIACTIONFORMATA, LPDIACTIONFORMATW) DECLS | |
extern WCHAR* heap_printfW(const char *format, ...) DECLSPEC_HIDDEN; | |
extern WCHAR* _get_mapping_path(const WCHAR *device, const WCHAR *username) DECLSPEC_HIDDEN; | |
+extern FILETIME _get_mapping_time(REFGUID app_guid, const WCHAR *device, const WCHAR* username) DECLSPEC_HIDDEN; | |
extern HRESULT _configure_devices(LPDIRECTINPUT8W iface, LPDICONFIGUREDEVICESCALLBACK lpdiCallback, LPDICONFIGUREDEVICESPARAMSW lpdiCDParams, DWORD dwFlags, LPVOID pvRefData, HINSTANCE hinstance) DECLSPEC_HIDDEN; | |
-- | |
1.7.0.4 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 88e7389c14d99ead8c1f910d268c37c7d270d840 Mon Sep 17 00:00:00 2001 | |
From: Lucas Fialho Zawacki <lfzawacki@gmail.com> | |
Date: Tue, 16 Aug 2011 21:22:26 -0300 | |
Subject: dinput: EnumDevicesBySemantics treating THISUSER and AVAILABLEDEVICES flags | |
--- | |
dlls/dinput/dinput_main.c | 38 ++++++++++++++++++++++++++++++++++++++ | |
dlls/dinput8/tests/dinput.c | 6 +++--- | |
2 files changed, 41 insertions(+), 3 deletions(-) | |
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c | |
index 35898c2..3795d07 100644 | |
--- a/dlls/dinput/dinput_main.c | |
+++ b/dlls/dinput/dinput_main.c | |
@@ -924,6 +924,7 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( | |
IDirectInputDevice8A *lpdid; | |
WCHAR username[MAX_PATH]; | |
DWORD username_size = MAX_PATH; | |
+ DIPROPSTRING dps; | |
int i, j, remaining = 0; | |
FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This, ptszUserName, lpdiActionFormat, | |
@@ -946,6 +947,10 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( | |
else | |
MultiByteToWideChar(CP_ACP, 0, ptszUserName, -1, username, MAX_PATH); | |
+ dps.diph.dwSize = sizeof(dps); | |
+ dps.diph.dwHeaderSize = sizeof(DIPROPHEADER); | |
+ dps.diph.dwHow = DIPH_DEVICE; | |
+ | |
/* Count the devices */ | |
for (i = NB_DINPUT_DEVICES-1; i >= 0 ; i--) | |
{ | |
@@ -1015,8 +1020,22 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( | |
callbackFlags |= DIEDBS_NEWDEVICE; | |
} | |
+ /* Skips devices already owned by a user */ | |
+ if (dwFlags & DIEDBSFL_AVAILABLEDEVICES) | |
+ if (!IDirectInputDevice_GetProperty(lpdid, DIPROP_USERNAME, &dps.diph)) goto skipped; | |
+ | |
+ /* Skips devices not owned by the given user */ | |
+ if (dwFlags & DIEDBSFL_THISUSER) | |
+ { | |
+ HRESULT hr; | |
+ hr = IDirectInputDevice_GetProperty(lpdid, DIPROP_USERNAME, &dps.diph); | |
+ | |
+ if (FAILED(hr) || lstrcmpW(dps.wsz, username)) goto skipped; | |
+ } | |
+ | |
cb_return = lpCallback(&didevi, lpdid, callbackFlags, remaining, pvRef); | |
+ skipped: | |
/* Cleanup */ | |
IDirectInputDevice_Release(lpdid); | |
if (cb_return == DIENUM_STOP) return DI_OK; | |
@@ -1038,6 +1057,7 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics( | |
IDirectInputDevice8W *lpdid; | |
WCHAR username[MAX_PATH]; | |
DWORD username_size = MAX_PATH; | |
+ DIPROPSTRING dps; | |
int i, j, remaining = 0; | |
FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This, debugstr_w(ptszUserName), lpdiActionFormat, | |
@@ -1050,6 +1070,10 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics( | |
else | |
lstrcpyW(username, ptszUserName); | |
+ dps.diph.dwSize = sizeof(dps); | |
+ dps.diph.dwHeaderSize = sizeof(DIPROPHEADER); | |
+ dps.diph.dwHow = DIPH_DEVICE; | |
+ | |
/* Count the devices */ | |
for (i = NB_DINPUT_DEVICES-1; i >= 0 ; i--) | |
{ | |
@@ -1110,8 +1134,22 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics( | |
callbackFlags |= DIEDBS_NEWDEVICE; | |
} | |
+ /* Skips devices already owned by a user */ | |
+ if (dwFlags & DIEDBSFL_AVAILABLEDEVICES) | |
+ if (!IDirectInputDevice_GetProperty(lpdid, DIPROP_USERNAME, &dps.diph)) goto skipped; | |
+ | |
+ /* Skips devices not owned by the given user */ | |
+ if (dwFlags & DIEDBSFL_THISUSER) | |
+ { | |
+ HRESULT hr; | |
+ hr = IDirectInputDevice_GetProperty(lpdid, DIPROP_USERNAME, &dps.diph); | |
+ | |
+ if (FAILED(hr) || lstrcmpW(dps.wsz, username)) goto skipped; | |
+ } | |
+ | |
cb_return = lpCallback(&didevi, lpdid, callbackFlags, remaining, pvRef); | |
+ skipped: | |
/* Cleanup */ | |
IDirectInputDevice_Release(lpdid); | |
if (cb_return == DIENUM_STOP) return DI_OK; | |
diff --git a/dlls/dinput8/tests/dinput.c b/dlls/dinput8/tests/dinput.c | |
index 7251939..7773b39 100644 | |
--- a/dlls/dinput8/tests/dinput.c | |
+++ b/dlls/dinput8/tests/dinput.c | |
@@ -536,7 +536,7 @@ static void test_EnumDevicesBySemantics(void) | |
data.device_count = 0; | |
hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &diaf, enum_semantics_callback, &data, DIEDBSFL_AVAILABLEDEVICES); | |
ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr); | |
- todo_wine ok (data.device_count == 0, "No device should be available after action mapping available=%d\n", data.device_count); | |
+ ok (data.device_count == 0, "No device should be available after action mapping available=%d\n", data.device_count); | |
/* Now we'll give all the devices to a specific user */ | |
data.username = "Sh4d0w M4g3"; | |
@@ -547,13 +547,13 @@ static void test_EnumDevicesBySemantics(void) | |
data.device_count = 0; | |
hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &diaf, enum_semantics_callback, &data, DIEDBSFL_THISUSER); | |
ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr); | |
- todo_wine ok (data.device_count == 0, "This user should own no devices owned=%d\n", data.device_count); | |
+ ok (data.device_count == 0, "This user should own no devices owned=%d\n", data.device_count); | |
/* Testing with another user */ | |
data.device_count = 0; | |
hr = IDirectInput8_EnumDevicesBySemantics(pDI, "Ninja Brian", &diaf, enum_semantics_callback, &data, DIEDBSFL_THISUSER); | |
ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr); | |
- todo_wine ok (data.device_count == 0, "This user should own no devices owned=%d\n", data.device_count); | |
+ ok (data.device_count == 0, "This user should own no devices owned=%d\n", data.device_count); | |
/* Sh4d0w M4g3 has ownership of all devices */ | |
data.device_count = 0; | |
-- | |
1.7.0.4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment