Rémi Bernon : dinput: Cleanup mouse device enumeration and creation.
Alexandre Julliard
julliard at winehq.org
Fri Oct 22 14:46:10 CDT 2021
Module: wine
Branch: master
Commit: 3dcb888a59aab67df6a6d6ebbd80f6be2200a620
URL: https://source.winehq.org/git/wine.git/?a=commit;h=3dcb888a59aab67df6a6d6ebbd80f6be2200a620
Author: Rémi Bernon <rbernon at codeweavers.com>
Date: Fri Oct 22 09:33:52 2021 +0200
dinput: Cleanup mouse device enumeration and creation.
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/dinput/mouse.c | 134 ++++++++++++++++++++--------------------------------
1 file changed, 51 insertions(+), 83 deletions(-)
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index 1b91fa12189..4e353dba200 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -76,120 +76,88 @@ static inline SysMouseImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W
return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface), SysMouseImpl, base);
}
-static void fill_mouse_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version) {
- DWORD dwSize;
- DIDEVICEINSTANCEW ddi;
-
- dwSize = lpddi->dwSize;
-
- TRACE("%d %p\n", dwSize, lpddi);
-
- memset(lpddi, 0, dwSize);
- memset(&ddi, 0, sizeof(ddi));
-
- ddi.dwSize = dwSize;
- ddi.guidInstance = GUID_SysMouse;/* DInput's GUID */
- ddi.guidProduct = GUID_SysMouse;
- if (version >= 0x0800)
- ddi.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
- else
- ddi.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
- MultiByteToWideChar(CP_ACP, 0, "Mouse", -1, ddi.tszInstanceName, MAX_PATH);
- MultiByteToWideChar(CP_ACP, 0, "Wine Mouse", -1, ddi.tszProductName, MAX_PATH);
-
- memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
-}
-
-static HRESULT mousedev_enum_device(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
+static HRESULT mouse_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, DWORD version, int index )
{
- if (id != 0)
- return E_FAIL;
-
- if (dwFlags & DIEDFL_FORCEFEEDBACK)
- return S_FALSE;
-
- if ((dwDevType == 0) ||
- ((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) ||
- (((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 0x0800))) {
- TRACE("Enumerating the mouse device\n");
-
- fill_mouse_dideviceinstanceW(lpddi, version);
-
- return S_OK;
- }
-
- return S_FALSE;
+ DWORD size;
+
+ TRACE( "type %#x, flags %#x, instance %p, version %#04x, index %d\n", type, flags, instance, version, index );
+
+ if (index != 0) return DIERR_GENERIC;
+ if (flags & DIEDFL_FORCEFEEDBACK) return DI_NOEFFECT;
+ if (version < 0x0800 && type != 0 && type != DIDEVTYPE_MOUSE) return DI_NOEFFECT;
+ if (version >= 0x0800 && type != DI8DEVCLASS_ALL && type != DI8DEVCLASS_POINTER && type != DI8DEVTYPE_MOUSE)
+ return DI_NOEFFECT;
+
+ if (instance->dwSize != sizeof(DIDEVICEINSTANCEW) &&
+ instance->dwSize != sizeof(DIDEVICEINSTANCE_DX3W))
+ return DIERR_INVALIDPARAM;
+
+ size = instance->dwSize;
+ memset( instance, 0, size );
+ instance->dwSize = size;
+ instance->guidInstance = GUID_SysMouse;
+ instance->guidProduct = GUID_SysMouse;
+ if (version >= 0x0800) instance->dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
+ else instance->dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
+ MultiByteToWideChar( CP_ACP, 0, "Mouse", -1, instance->tszInstanceName, MAX_PATH );
+ MultiByteToWideChar( CP_ACP, 0, "Wine Mouse", -1, instance->tszProductName, MAX_PATH );
+
+ return DI_OK;
}
-static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseImpl **out )
+static HRESULT mouse_create_device( IDirectInputImpl *dinput, const GUID *guid, IDirectInputDevice8W **out )
{
- SysMouseImpl* newDevice;
- WCHAR buffer[20];
+ SysMouseImpl *impl;
HKEY hkey, appkey;
+ WCHAR buffer[20];
HRESULT hr;
+ TRACE( "dinput %p, guid %s, out %p\n", dinput, debugstr_guid( guid ), out );
+
+ *out = NULL;
+ if (!IsEqualGUID( &GUID_SysMouse, guid )) return DIERR_DEVICENOTREG;
+
if (FAILED(hr = direct_input_device_alloc( sizeof(SysMouseImpl), &SysMouseWvt, &mouse_internal_vtbl,
- rguid, dinput, (void **)&newDevice )))
+ guid, dinput, (void **)&impl )))
return hr;
- newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit");
+ impl->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit");
- fill_mouse_dideviceinstanceW( &newDevice->base.instance, newDevice->base.dinput->dwVersion );
- newDevice->base.caps.dwDevType = newDevice->base.instance.dwDevType;
- newDevice->base.caps.dwFirmwareRevision = 100;
- newDevice->base.caps.dwHardwareRevision = 100;
- newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
+ mouse_enum_device( 0, 0, &impl->base.instance, dinput->dwVersion, 0 );
+ impl->base.caps.dwDevType = impl->base.instance.dwDevType;
+ impl->base.caps.dwFirmwareRevision = 100;
+ impl->base.caps.dwHardwareRevision = 100;
+ impl->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
get_app_key(&hkey, &appkey);
if (!get_config_key( hkey, appkey, L"MouseWarpOverride", buffer, sizeof(buffer) ))
{
- if (!wcsnicmp( buffer, L"disable", -1 )) newDevice->warp_override = WARP_DISABLE;
- else if (!wcsnicmp( buffer, L"force", -1 )) newDevice->warp_override = WARP_FORCE_ON;
+ if (!wcsnicmp( buffer, L"disable", -1 )) impl->warp_override = WARP_DISABLE;
+ else if (!wcsnicmp( buffer, L"force", -1 )) impl->warp_override = WARP_FORCE_ON;
}
if (appkey) RegCloseKey(appkey);
if (hkey) RegCloseKey(hkey);
- if (FAILED(hr = direct_input_device_init( &newDevice->base.IDirectInputDevice8W_iface )))
+ if (FAILED(hr = direct_input_device_init( &impl->base.IDirectInputDevice8W_iface )))
{
- IDirectInputDevice_Release( &newDevice->base.IDirectInputDevice8W_iface );
+ IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface );
return hr;
}
if (dinput->dwVersion >= 0x0800)
{
- newDevice->base.use_raw_input = TRUE;
- newDevice->base.raw_device.usUsagePage = 1; /* HID generic device page */
- newDevice->base.raw_device.usUsage = 2; /* HID generic mouse */
+ impl->base.use_raw_input = TRUE;
+ impl->base.raw_device.usUsagePage = 1; /* HID generic device page */
+ impl->base.raw_device.usUsage = 2; /* HID generic mouse */
}
- *out = newDevice;
+ *out = &impl->base.IDirectInputDevice8W_iface;
return DI_OK;
}
-static HRESULT mousedev_create_device( IDirectInputImpl *dinput, REFGUID rguid, IDirectInputDevice8W **out )
-{
- TRACE( "%p %s %p\n", dinput, debugstr_guid( rguid ), out );
- *out = NULL;
-
- if (IsEqualGUID(&GUID_SysMouse, rguid)) /* Wine Mouse */
- {
- SysMouseImpl *This;
- HRESULT hr;
-
- if (FAILED(hr = alloc_device( rguid, dinput, &This ))) return hr;
-
- TRACE( "Created a Mouse device (%p)\n", This );
-
- *out = &This->base.IDirectInputDevice8W_iface;
- return DI_OK;
- }
-
- return DIERR_DEVICENOTREG;
-}
-
const struct dinput_device mouse_device = {
"Wine mouse driver",
- mousedev_enum_device,
- mousedev_create_device
+ mouse_enum_device,
+ mouse_create_device
};
/******************************************************************************
More information about the wine-cvs
mailing list