Rémi Bernon : windows.gaming.input: Implement ICustomGameControllerFactory interface for RacingWheel.
Alexandre Julliard
julliard at winehq.org
Fri Apr 22 14:46:04 CDT 2022
Module: wine
Branch: master
Commit: acc2b32a5e81357c7cf37ccadaa7fd0d31e52773
URL: https://source.winehq.org/git/wine.git/?a=commit;h=acc2b32a5e81357c7cf37ccadaa7fd0d31e52773
Author: Rémi Bernon <rbernon at codeweavers.com>
Date: Fri Apr 22 11:49:07 2022 +0200
windows.gaming.input: Implement ICustomGameControllerFactory interface for RacingWheel.
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/windows.gaming.input/main.c | 2 +-
dlls/windows.gaming.input/private.h | 2 +-
dlls/windows.gaming.input/racing_wheel.c | 83 +++++++++++++++++++++++++++++++-
3 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/dlls/windows.gaming.input/main.c b/dlls/windows.gaming.input/main.c
index 2d8f6a340b0..21808d9c2ad 100644
--- a/dlls/windows.gaming.input/main.c
+++ b/dlls/windows.gaming.input/main.c
@@ -181,7 +181,7 @@ HRESULT WINAPI DllGetActivationFactory( HSTRING class_str, IActivationFactory **
if (!wcscmp( buffer, RuntimeClass_Windows_Gaming_Input_Gamepad ))
ICustomGameControllerFactory_QueryInterface( gamepad_factory, &IID_IActivationFactory, (void **)factory );
if (!wcscmp( buffer, RuntimeClass_Windows_Gaming_Input_RacingWheel ))
- IActivationFactory_QueryInterface( racing_wheel_factory, &IID_IActivationFactory, (void **)factory );
+ ICustomGameControllerFactory_QueryInterface( racing_wheel_factory, &IID_IActivationFactory, (void **)factory );
if (!wcscmp( buffer, RuntimeClass_Windows_Gaming_Input_Custom_GameControllerFactoryManager ))
IGameControllerFactoryManagerStatics2_QueryInterface( manager_factory, &IID_IActivationFactory, (void **)factory );
diff --git a/dlls/windows.gaming.input/private.h b/dlls/windows.gaming.input/private.h
index 73fab47a770..58b2040d3de 100644
--- a/dlls/windows.gaming.input/private.h
+++ b/dlls/windows.gaming.input/private.h
@@ -42,7 +42,7 @@
extern HINSTANCE windows_gaming_input;
extern ICustomGameControllerFactory *controller_factory;
extern ICustomGameControllerFactory *gamepad_factory;
-extern IActivationFactory *racing_wheel_factory;
+extern ICustomGameControllerFactory *racing_wheel_factory;
extern IGameControllerFactoryManagerStatics2 *manager_factory;
struct vector_iids
diff --git a/dlls/windows.gaming.input/racing_wheel.c b/dlls/windows.gaming.input/racing_wheel.c
index 458f79a2aa0..818e46bab42 100644
--- a/dlls/windows.gaming.input/racing_wheel.c
+++ b/dlls/windows.gaming.input/racing_wheel.c
@@ -60,6 +60,7 @@ struct racing_wheel_statics
{
IActivationFactory IActivationFactory_iface;
IRacingWheelStatics IRacingWheelStatics_iface;
+ ICustomGameControllerFactory ICustomGameControllerFactory_iface;
LONG ref;
};
@@ -89,6 +90,12 @@ static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID
return S_OK;
}
+ if (IsEqualGUID( iid, &IID_ICustomGameControllerFactory ))
+ {
+ IInspectable_AddRef( (*out = &impl->ICustomGameControllerFactory_iface) );
+ return S_OK;
+ }
+
FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) );
*out = NULL;
return E_NOINTERFACE;
@@ -207,11 +214,85 @@ static const struct IRacingWheelStaticsVtbl statics_vtbl =
statics_get_RacingWheels,
};
+DEFINE_IINSPECTABLE( controller_factory, ICustomGameControllerFactory, struct racing_wheel_statics, IActivationFactory_iface )
+
+static HRESULT WINAPI controller_factory_CreateGameController( ICustomGameControllerFactory *iface, IGameControllerProvider *provider,
+ IInspectable **value )
+{
+ FIXME( "iface %p, provider %p, value %p stub!.\n", iface, provider, value );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI controller_factory_OnGameControllerAdded( ICustomGameControllerFactory *iface, IGameController *value )
+{
+ IRacingWheel *racing_wheel;
+ HRESULT hr;
+
+ TRACE( "iface %p, value %p.\n", iface, value );
+
+ if (FAILED(hr = IGameController_QueryInterface( value, &IID_IRacingWheel, (void **)&racing_wheel )))
+ return hr;
+ event_handlers_notify( &racing_wheel_added_handlers, (IInspectable *)racing_wheel );
+ IRacingWheel_Release( racing_wheel );
+
+ return S_OK;
+}
+
+static HRESULT WINAPI controller_factory_OnGameControllerRemoved( ICustomGameControllerFactory *iface, IGameController *value )
+{
+ IRacingWheel *racing_wheel;
+ BOOLEAN found;
+ UINT32 index;
+ HRESULT hr;
+
+ TRACE( "iface %p, value %p.\n", iface, value );
+
+ if (FAILED(hr = IGameController_QueryInterface( value, &IID_IRacingWheel, (void **)&racing_wheel )))
+ return hr;
+
+ EnterCriticalSection( &racing_wheel_cs );
+ if (SUCCEEDED(hr = init_racing_wheels()))
+ {
+ if (FAILED(hr = IVector_RacingWheel_IndexOf( racing_wheels, racing_wheel, &index, &found )) || !found)
+ WARN( "Could not find RacingWheel %p, hr %#lx!\n", racing_wheel, hr );
+ else
+ hr = IVector_RacingWheel_RemoveAt( racing_wheels, index );
+ }
+ LeaveCriticalSection( &racing_wheel_cs );
+
+ if (FAILED(hr))
+ WARN( "Failed to remove RacingWheel %p, hr %#lx!\n", racing_wheel, hr );
+ else if (found)
+ {
+ TRACE( "Removed RacingWheel %p.\n", racing_wheel );
+ event_handlers_notify( &racing_wheel_removed_handlers, (IInspectable *)racing_wheel );
+ }
+ IRacingWheel_Release( racing_wheel );
+
+ return S_OK;
+}
+
+static const struct ICustomGameControllerFactoryVtbl controller_factory_vtbl =
+{
+ controller_factory_QueryInterface,
+ controller_factory_AddRef,
+ controller_factory_Release,
+ /* IInspectable methods */
+ controller_factory_GetIids,
+ controller_factory_GetRuntimeClassName,
+ controller_factory_GetTrustLevel,
+ /* ICustomGameControllerFactory methods */
+ controller_factory_CreateGameController,
+ controller_factory_OnGameControllerAdded,
+ controller_factory_OnGameControllerRemoved,
+};
+
static struct racing_wheel_statics racing_wheel_statics =
{
{&factory_vtbl},
{&statics_vtbl},
+ {&controller_factory_vtbl},
1,
};
-IActivationFactory *racing_wheel_factory = &racing_wheel_statics.IActivationFactory_iface;
+ICustomGameControllerFactory *racing_wheel_factory = &racing_wheel_statics.ICustomGameControllerFactory_iface;
More information about the wine-cvs
mailing list