[PATCH 3/6] windows.gaming.input: Implement ForceFeedbackMotor stub runtimeclass.
Rémi Bernon
rbernon at codeweavers.com
Mon Apr 25 07:56:17 CDT 2022
And create it for RawGameController and RacingWheel motors.
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
dlls/dinput/tests/force_feedback.c | 6 +-
dlls/windows.gaming.input/Makefile.in | 1 +
dlls/windows.gaming.input/controller.c | 11 +-
dlls/windows.gaming.input/force_feedback.c | 227 +++++++++++++++++++++
dlls/windows.gaming.input/private.h | 3 +
dlls/windows.gaming.input/provider.c | 16 ++
dlls/windows.gaming.input/provider.idl | 3 +
dlls/windows.gaming.input/racing_wheel.c | 7 +-
8 files changed, 267 insertions(+), 7 deletions(-)
create mode 100644 dlls/windows.gaming.input/force_feedback.c
diff --git a/dlls/dinput/tests/force_feedback.c b/dlls/dinput/tests/force_feedback.c
index 9880b65aca2..a11bd3420e9 100644
--- a/dlls/dinput/tests/force_feedback.c
+++ b/dlls/dinput/tests/force_feedback.c
@@ -5289,13 +5289,10 @@ static void test_windows_gaming_input(void)
hr = IVectorView_ForceFeedbackMotor_get_Size( motors_view, &size );
ok( hr == S_OK, "get_Size returned %#lx\n", hr );
- todo_wine
ok( size == 1, "got size %u\n", size );
hr = IVectorView_ForceFeedbackMotor_GetAt( motors_view, 0, &motor );
- todo_wine
ok( hr == S_OK, "GetAt returned %#lx\n", hr );
IVectorView_ForceFeedbackMotor_Release( motors_view );
- if (hr != S_OK) goto skip_tests;
check_interface( motor, &IID_IUnknown, TRUE );
check_interface( motor, &IID_IInspectable, TRUE );
@@ -5356,6 +5353,7 @@ static void test_windows_gaming_input(void)
todo_wine
ok( hr == S_OK, "TryDisableAsync returned %#lx\n", hr );
wait_hid_expect_( __FILE__, __LINE__, file, 100, TRUE );
+ if (hr != S_OK) goto skip_tests;
check_bool_async( bool_async, 1, Completed, S_OK, TRUE );
check_interface( bool_async, &IID_IUnknown, TRUE );
@@ -5529,9 +5527,9 @@ static void test_windows_gaming_input(void)
IAsyncOperation_boolean_Release( bool_async );
+skip_tests:
IForceFeedbackMotor_Release( motor );
-skip_tests:
IRawGameController_Release( raw_controller );
CloseHandle( file );
diff --git a/dlls/windows.gaming.input/Makefile.in b/dlls/windows.gaming.input/Makefile.in
index 1e0ce5c360c..b9a56992142 100644
--- a/dlls/windows.gaming.input/Makefile.in
+++ b/dlls/windows.gaming.input/Makefile.in
@@ -4,6 +4,7 @@ IMPORTS = combase uuid user32 dinput8 setupapi hid
C_SRCS = \
controller.c \
event_handlers.c \
+ force_feedback.c \
gamepad.c \
main.c \
manager.c \
diff --git a/dlls/windows.gaming.input/controller.c b/dlls/windows.gaming.input/controller.c
index d68da6b3142..e372ea6c9bf 100644
--- a/dlls/windows.gaming.input/controller.c
+++ b/dlls/windows.gaming.input/controller.c
@@ -236,13 +236,22 @@ static HRESULT WINAPI raw_controller_get_ForceFeedbackMotors( IRawGameController
.iterable = &IID_IIterable_ForceFeedbackMotor,
.iterator = &IID_IIterator_ForceFeedbackMotor,
};
+ struct controller *impl = impl_from_IRawGameController( iface );
IVector_ForceFeedbackMotor *vector;
+ IForceFeedbackMotor *motor;
HRESULT hr;
TRACE( "iface %p, value %p\n", iface, value );
if (FAILED(hr = vector_create( &iids, (void **)&vector ))) return hr;
- hr = IVector_ForceFeedbackMotor_GetView( vector, value );
+
+ if (SUCCEEDED(IWineGameControllerProvider_get_ForceFeedbackMotor( impl->wine_provider, &motor )) && motor)
+ {
+ hr = IVector_ForceFeedbackMotor_Append( vector, motor );
+ IForceFeedbackMotor_Release( motor );
+ }
+
+ if (SUCCEEDED(hr)) hr = IVector_ForceFeedbackMotor_GetView( vector, value );
IVector_ForceFeedbackMotor_Release( vector );
return hr;
diff --git a/dlls/windows.gaming.input/force_feedback.c b/dlls/windows.gaming.input/force_feedback.c
new file mode 100644
index 00000000000..24617d16733
--- /dev/null
+++ b/dlls/windows.gaming.input/force_feedback.c
@@ -0,0 +1,227 @@
+/* WinRT Windows.Gaming.Input implementation
+ *
+ * Copyright 2022 Rémi Bernon for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "private.h"
+
+#include "ddk/hidsdi.h"
+#include "dinput.h"
+#include "hidusage.h"
+
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(input);
+
+struct motor
+{
+ IForceFeedbackMotor IForceFeedbackMotor_iface;
+ LONG ref;
+
+ IDirectInputDevice8W *device;
+};
+
+static inline struct motor *impl_from_IForceFeedbackMotor( IForceFeedbackMotor *iface )
+{
+ return CONTAINING_RECORD( iface, struct motor, IForceFeedbackMotor_iface );
+}
+
+static HRESULT WINAPI motor_QueryInterface( IForceFeedbackMotor *iface, REFIID iid, void **out )
+{
+ struct motor *impl = impl_from_IForceFeedbackMotor( iface );
+
+ TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out );
+
+ if (IsEqualGUID( iid, &IID_IUnknown ) ||
+ IsEqualGUID( iid, &IID_IInspectable ) ||
+ IsEqualGUID( iid, &IID_IAgileObject ) ||
+ IsEqualGUID( iid, &IID_IForceFeedbackMotor ))
+ {
+ IInspectable_AddRef( (*out = &impl->IForceFeedbackMotor_iface) );
+ return S_OK;
+ }
+
+ FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) );
+ *out = NULL;
+ return E_NOINTERFACE;
+}
+
+static ULONG WINAPI motor_AddRef( IForceFeedbackMotor *iface )
+{
+ struct motor *impl = impl_from_IForceFeedbackMotor( iface );
+ ULONG ref = InterlockedIncrement( &impl->ref );
+ TRACE( "iface %p increasing refcount to %lu.\n", iface, ref );
+ return ref;
+}
+
+static ULONG WINAPI motor_Release( IForceFeedbackMotor *iface )
+{
+ struct motor *impl = impl_from_IForceFeedbackMotor( iface );
+ ULONG ref = InterlockedDecrement( &impl->ref );
+
+ TRACE( "iface %p decreasing refcount to %lu.\n", iface, ref );
+
+ if (!ref)
+ {
+ IDirectInputDevice8_Release( impl->device );
+ free( impl );
+ }
+
+ return ref;
+}
+
+static HRESULT WINAPI motor_GetIids( IForceFeedbackMotor *iface, ULONG *iid_count, IID **iids )
+{
+ FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_GetRuntimeClassName( IForceFeedbackMotor *iface, HSTRING *class_name )
+{
+ return WindowsCreateString( RuntimeClass_Windows_Gaming_Input_ForceFeedback_ForceFeedbackMotor,
+ ARRAY_SIZE(RuntimeClass_Windows_Gaming_Input_ForceFeedback_ForceFeedbackMotor),
+ class_name );
+}
+
+static HRESULT WINAPI motor_GetTrustLevel( IForceFeedbackMotor *iface, TrustLevel *trust_level )
+{
+ FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_get_AreEffectsPaused( IForceFeedbackMotor *iface, BOOLEAN *value )
+{
+ FIXME( "iface %p, value %p stub!\n", iface, value );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_get_MasterGain( IForceFeedbackMotor *iface, double *value )
+{
+ FIXME( "iface %p, value %p stub!\n", iface, value );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_put_MasterGain( IForceFeedbackMotor *iface, double value )
+{
+ FIXME( "iface %p, value %#I64x stub!\n", iface, *(UINT64 *)&value );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_get_IsEnabled( IForceFeedbackMotor *iface, BOOLEAN *value )
+{
+ FIXME( "iface %p, value %p stub!\n", iface, value );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_get_SupportedAxes( IForceFeedbackMotor *iface, enum ForceFeedbackEffectAxes *value )
+{
+ FIXME( "iface %p, value %p stub!\n", iface, value );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_LoadEffectAsync( IForceFeedbackMotor *iface, IForceFeedbackEffect *effect,
+ IAsyncOperation_ForceFeedbackLoadEffectResult **async_op )
+{
+ FIXME( "iface %p, effect %p, async_op %p stub!\n", iface, effect, async_op );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_PauseAllEffects( IForceFeedbackMotor *iface )
+{
+ FIXME( "iface %p stub!\n", iface );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_ResumeAllEffects( IForceFeedbackMotor *iface )
+{
+ FIXME( "iface %p stub!\n", iface );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_StopAllEffects( IForceFeedbackMotor *iface )
+{
+ FIXME( "iface %p stub!\n", iface );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_TryDisableAsync( IForceFeedbackMotor *iface, IAsyncOperation_boolean **async_op )
+{
+ FIXME( "iface %p, async_op %p stub!\n", iface, async_op );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_TryEnableAsync( IForceFeedbackMotor *iface, IAsyncOperation_boolean **async_op )
+{
+ FIXME( "iface %p, async_op %p stub!\n", iface, async_op );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_TryResetAsync( IForceFeedbackMotor *iface, IAsyncOperation_boolean **async_op )
+{
+ FIXME( "iface %p, async_op %p stub!\n", iface, async_op );
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI motor_TryUnloadEffectAsync( IForceFeedbackMotor *iface, IForceFeedbackEffect *effect,
+ IAsyncOperation_boolean **async_op )
+{
+ FIXME( "iface %p, effect %p, async_op %p stub!\n", iface, effect, async_op );
+ return E_NOTIMPL;
+}
+
+static const struct IForceFeedbackMotorVtbl motor_vtbl =
+{
+ motor_QueryInterface,
+ motor_AddRef,
+ motor_Release,
+ /* IInspectable methods */
+ motor_GetIids,
+ motor_GetRuntimeClassName,
+ motor_GetTrustLevel,
+ /* IForceFeedbackMotor methods */
+ motor_get_AreEffectsPaused,
+ motor_get_MasterGain,
+ motor_put_MasterGain,
+ motor_get_IsEnabled,
+ motor_get_SupportedAxes,
+ motor_LoadEffectAsync,
+ motor_PauseAllEffects,
+ motor_ResumeAllEffects,
+ motor_StopAllEffects,
+ motor_TryDisableAsync,
+ motor_TryEnableAsync,
+ motor_TryResetAsync,
+ motor_TryUnloadEffectAsync,
+};
+
+HRESULT force_feedback_motor_create( IDirectInputDevice8W *device, IForceFeedbackMotor **out )
+{
+ struct motor *impl;
+
+ TRACE( "device %p, out %p\n", device, out );
+
+ if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY;
+ impl->IForceFeedbackMotor_iface.lpVtbl = &motor_vtbl;
+ impl->ref = 1;
+
+ IDirectInputDevice_AddRef( device );
+ impl->device = device;
+
+ *out = &impl->IForceFeedbackMotor_iface;
+ TRACE( "created ForceFeedbackMotor %p\n", *out );
+ return S_OK;
+}
diff --git a/dlls/windows.gaming.input/private.h b/dlls/windows.gaming.input/private.h
index 58b2040d3de..562a84d49ed 100644
--- a/dlls/windows.gaming.input/private.h
+++ b/dlls/windows.gaming.input/private.h
@@ -25,6 +25,7 @@
#include "winbase.h"
#include "winstring.h"
#include "objbase.h"
+#include "dinput.h"
#include "activation.h"
@@ -64,6 +65,8 @@ extern HRESULT event_handlers_append( struct list *list, IEventHandler_IInspecta
extern HRESULT event_handlers_remove( struct list *list, EventRegistrationToken *token );
extern void event_handlers_notify( struct list *list, IInspectable *element );
+extern HRESULT force_feedback_motor_create( IDirectInputDevice8W *device, IForceFeedbackMotor **out );
+
#define DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from, iface_mem, expr ) \
static inline impl_type *impl_from( iface_type *iface ) \
{ \
diff --git a/dlls/windows.gaming.input/provider.c b/dlls/windows.gaming.input/provider.c
index 69098e8abb6..70900000eef 100644
--- a/dlls/windows.gaming.input/provider.c
+++ b/dlls/windows.gaming.input/provider.c
@@ -315,6 +315,21 @@ static HRESULT WINAPI wine_provider_put_Vibration( IWineGameControllerProvider *
return S_OK;
}
+static HRESULT WINAPI wine_provider_get_ForceFeedbackMotor( IWineGameControllerProvider *iface, IForceFeedbackMotor **value )
+{
+ struct provider *impl = impl_from_IWineGameControllerProvider( iface );
+ DIDEVCAPS caps = {.dwSize = sizeof(DIDEVCAPS)};
+ HRESULT hr;
+
+ TRACE( "iface %p, value %p.\n", iface, value );
+
+ if (SUCCEEDED(hr = IDirectInputDevice8_GetCapabilities( impl->dinput_device, &caps )) && (caps.dwFlags & DIDC_FORCEFEEDBACK))
+ return force_feedback_motor_create( impl->dinput_device, value );
+
+ *value = NULL;
+ return S_OK;
+}
+
static const struct IWineGameControllerProviderVtbl wine_provider_vtbl =
{
wine_provider_QueryInterface,
@@ -332,6 +347,7 @@ static const struct IWineGameControllerProviderVtbl wine_provider_vtbl =
wine_provider_get_State,
wine_provider_get_Vibration,
wine_provider_put_Vibration,
+ wine_provider_get_ForceFeedbackMotor,
};
DEFINE_IINSPECTABLE( game_provider, IGameControllerProvider, struct provider, IWineGameControllerProvider_iface )
diff --git a/dlls/windows.gaming.input/provider.idl b/dlls/windows.gaming.input/provider.idl
index 865a149eaa5..60eaab34506 100644
--- a/dlls/windows.gaming.input/provider.idl
+++ b/dlls/windows.gaming.input/provider.idl
@@ -29,6 +29,7 @@ import "windowscontracts.idl";
import "windows.foundation.idl";
import "windows.gaming.input.idl";
import "windows.gaming.input.custom.idl";
+import "windows.gaming.input.forcefeedback.idl";
namespace Windows.Gaming.Input.Custom {
typedef enum WineGameControllerType WineGameControllerType;
@@ -85,6 +86,8 @@ namespace Windows.Gaming.Input.Custom {
[propget] HRESULT State([out, retval] WineGameControllerState *state);
[propget] HRESULT Vibration([out, retval] WineGameControllerVibration *vibration);
[propput] HRESULT Vibration([in] WineGameControllerVibration vibration);
+
+ [propget] HRESULT ForceFeedbackMotor([out, retval] Windows.Gaming.Input.ForceFeedback.ForceFeedbackMotor **motor);
}
[
diff --git a/dlls/windows.gaming.input/racing_wheel.c b/dlls/windows.gaming.input/racing_wheel.c
index b4635d03153..4a494775dc2 100644
--- a/dlls/windows.gaming.input/racing_wheel.c
+++ b/dlls/windows.gaming.input/racing_wheel.c
@@ -245,8 +245,11 @@ static HRESULT WINAPI racing_wheel_get_MaxWheelAngle( IRacingWheel *iface, DOUBL
static HRESULT WINAPI racing_wheel_get_WheelMotor( IRacingWheel *iface, IForceFeedbackMotor **value )
{
- FIXME( "iface %p, value %p stub!\n", iface, value );
- return E_NOTIMPL;
+ struct racing_wheel *impl = impl_from_IRacingWheel( iface );
+
+ TRACE( "iface %p, value %p\n", iface, value );
+
+ return IWineGameControllerProvider_get_ForceFeedbackMotor( impl->wine_provider, value );
}
static HRESULT WINAPI racing_wheel_GetButtonLabel( IRacingWheel *iface, enum RacingWheelButtons button,
--
2.35.1
More information about the wine-devel
mailing list