2015-05-24 04:32:32 +00:00
// Copyright 2010 Dolphin Emulator Project
2021-07-05 01:22:19 +00:00
// SPDX-License-Identifier: GPL-2.0-or-later
2015-05-24 04:32:32 +00:00
2013-10-19 09:27:57 +00:00
// XInput suffers a similar issue as XAudio2. Since Win8, it is part of the OS.
// However, unlike XAudio2 they have not made the API incompatible - so we just
// compile against the latest version and fall back to dynamically loading the
// old DLL.
2014-02-10 18:54:46 +00:00
# pragma once
2010-04-02 02:48:24 +00:00
2014-02-19 01:17:31 +00:00
# include <windows.h>
2017-01-23 07:08:45 +00:00
# include <XInput.h>
2010-04-02 02:48:24 +00:00
2016-06-12 15:08:04 +00:00
# include "InputCommon/ControllerInterface/ControllerInterface.h"
2014-02-19 01:17:31 +00:00
2013-10-19 09:27:57 +00:00
# ifndef XINPUT_DEVSUBTYPE_FLIGHT_STICK
# error You are building this module against the wrong version of DirectX. You probably need to remove DXSDK_DIR from your include path and / or _WIN32_WINNT is wrong.
# endif
2019-06-17 20:39:24 +00:00
namespace ciface : : XInput
2010-04-02 02:48:24 +00:00
{
2016-06-12 15:08:04 +00:00
void Init ( ) ;
2016-10-16 20:39:05 +00:00
void PopulateDevices ( ) ;
2013-10-19 09:27:57 +00:00
void DeInit ( ) ;
2010-04-02 02:48:24 +00:00
2020-02-08 21:45:01 +00:00
class Device final : public Core : : Device
2010-04-02 02:48:24 +00:00
{
2011-03-14 01:20:11 +00:00
public :
Device ( const XINPUT_CAPABILITIES & capabilities , u8 index ) ;
2010-04-02 02:48:24 +00:00
2020-02-08 21:45:01 +00:00
std : : string GetName ( ) const override ;
std : : string GetSource ( ) const override ;
std : : optional < int > GetPreferredId ( ) const override ;
InputCommon: fix default input config default device not being loaded/found
Fixes bug: https://bugs.dolphin-emu.org/issues/12744
Before https://github.com/dolphin-emu/dolphin/commit/e1e3db13baabefa89991388d37db0bb260c4f535
the ControllerInterface m_devices_mutex was "wrongfully" locked for the whole Initialize() call, which included the first device population refresh,
this has the unwanted (accidental) consequence of often preventing the different pads (GC Pad, Wii Contollers, ...) input configs from loading
until that mutex was released (the input config defaults loading was blocked in EmulatedController::LoadDefaults()), which meant that the devices
population would often have the time to finish adding its first device, which would then be selected as default device (by design, the first device
added to the CI is the default default device, usually the "Keyboard and Mouse" device).
After the commit mentioned above removed the unnecessary m_devices_mutex calls, the default default device would fail to load (be found)
causing the default input mappings, which are specifically written for the default default device on every platform, to not be bound to any
physical device input, breaking input on new dolphin installations (until a user tried to customize the default device manually).
Default devices are now always added synchronously to avoid the problem, and so they should in the future (I added comments and warnings to help with that)
2021-11-27 12:31:04 +00:00
int GetSortPriority ( ) const override { return - 1 ; }
2020-02-08 21:45:01 +00:00
void UpdateInput ( ) override ;
2010-04-02 02:48:24 +00:00
2014-11-13 09:10:55 +00:00
void UpdateMotors ( ) ;
2010-04-02 02:48:24 +00:00
private :
2020-02-08 21:02:54 +00:00
XINPUT_STATE m_state_in { } ;
2016-04-21 12:22:48 +00:00
XINPUT_VIBRATION m_state_out { } ;
2020-02-08 21:02:54 +00:00
ControlState m_battery_level { } ;
2011-03-14 01:20:11 +00:00
const BYTE m_subtype ;
const u8 m_index ;
2010-04-02 02:48:24 +00:00
} ;
2019-06-17 20:39:24 +00:00
} // namespace ciface::XInput