dinput: Cleanup mouse device enumeration and creation.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-10-22 09:33:52 +02:00 committed by Alexandre Julliard
parent b7386cec71
commit 3dcb888a59
1 changed files with 51 additions and 83 deletions

View File

@ -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;
DWORD size;
if (dwFlags & DIEDFL_FORCEFEEDBACK)
return S_FALSE;
TRACE( "type %#x, flags %#x, instance %p, version %#04x, index %d\n", type, flags, instance, version, index );
if ((dwDevType == 0) ||
((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) ||
(((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 0x0800))) {
TRACE("Enumerating the mouse device\n");
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;
fill_mouse_dideviceinstanceW(lpddi, version);
if (instance->dwSize != sizeof(DIDEVICEINSTANCEW) &&
instance->dwSize != sizeof(DIDEVICEINSTANCE_DX3W))
return DIERR_INVALIDPARAM;
return S_OK;
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;
}
return S_FALSE;
}
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;
if (FAILED(hr = direct_input_device_alloc( sizeof(SysMouseImpl), &SysMouseWvt, &mouse_internal_vtbl,
rguid, dinput, (void **)&newDevice )))
return hr;
newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit");
TRACE( "dinput %p, guid %s, out %p\n", dinput, debugstr_guid( guid ), out );
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;
*out = NULL;
if (!IsEqualGUID( &GUID_SysMouse, guid )) return DIERR_DEVICENOTREG;
if (FAILED(hr = direct_input_device_alloc( sizeof(SysMouseImpl), &SysMouseWvt, &mouse_internal_vtbl,
guid, dinput, (void **)&impl )))
return hr;
impl->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit");
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
};
/******************************************************************************