mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-16 11:48:36 +12:00
[Qt/Input] Improve pad_settings_dialog a bit (#3611)
* Input: further work on remapping Xinput and begin work on remapping DS4 * Input: Improve pad_settings_dialog a bit and begin Remapping for XInput * Input: begin evdev remapping and change all handlers to use cfg::string * Input: finish work on remapping evdev and some more crap * Input: finish work on remapping Xinput and DS4 * Input: add DS4 Colors to DS4 config * Input: Improve DS4 deadzone scaling Jarves made some mistakes, so I'll fix them in the follow up commit * Input: fix Jarves fixes on DS4 deadzone and remove unnecessary usage of toUtf8 * Input: add primitive batterychecks to XInput and DS4 * Input: add mmjoystick remapping * Input: Fix evdev and some Vibration issues * Input: adjust capabilities to fix stick input for games like LoS 2 also fix threshold slider minimum also add ps button to all the handlers * Input: Further evdev work based on danilaml code review and own debugging: Fixed path issue, <= 0 issue, some captures, const, axis with same codes. Adds a map to each device that differentiates negative and positive axis mappings. adjusted rest of the file to tabs (ListDevices and beginning of threadProc) * Input: use 20ms vibration update time for xbox one elite controllers. * Input: Fix return type of Clamp() * Input: Evdev Fix * Input: Evdev Optional GetNextButtonPress presumably better than the other * Input: review changes * Input: evdev: fix wrong index in axis handling move bindpadtodevice down to keep consistency between handlers and not get crazy * Input: evdev: fix expensive add_device in GetNextButtonPress * cleanup * Input: mmjoy: fix type * Input: evdev: final fixes * Input: evdev: exclude unnecessary buttons while mapping Xbox 360 or DS4 * Input: add deadzone preview by passing necessary values in callback use 0.5 of max value for threshold in pad dialog * Input: get rid of all-uppercase variables
This commit is contained in:
parent
695b4c1f06
commit
662fe8cc95
33 changed files with 3573 additions and 1796 deletions
|
@ -1,43 +1,102 @@
|
|||
#ifndef X_INPUT_PAD_HANDLER
|
||||
#define X_INPUT_PAD_HANDLER
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Utilities/Config.h"
|
||||
#include "Emu/Io/PadHandler.h"
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
#include <Xinput.h>
|
||||
#include <ctime>
|
||||
|
||||
struct xinput_config final : cfg::node
|
||||
namespace XINPUT_INFO
|
||||
{
|
||||
const std::string cfg_name = fs::get_config_dir() + "/config_xinput.yml";
|
||||
|
||||
cfg::_int<0, 1000000> lstickdeadzone{ this, "Left Stick Deadzone", 7849 };
|
||||
cfg::_int<0, 1000000> rstickdeadzone{ this, "Right Stick Deadzone", 8689 };
|
||||
cfg::_int<0, 1000000> padsquircling{ this, "Pad Squircling Factor", 8000 };
|
||||
|
||||
bool load()
|
||||
{
|
||||
if (fs::file cfg_file{ cfg_name, fs::read })
|
||||
{
|
||||
return from_string(cfg_file.to_string());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void save()
|
||||
{
|
||||
fs::file(cfg_name, fs::rewrite).write(to_string());
|
||||
}
|
||||
|
||||
bool exist()
|
||||
{
|
||||
return fs::is_file(cfg_name);
|
||||
}
|
||||
};
|
||||
const DWORD THREAD_TIMEOUT = 1000;
|
||||
const DWORD THREAD_SLEEP = 10;
|
||||
const DWORD THREAD_SLEEP_INACTIVE = 100;
|
||||
const DWORD GUIDE_BUTTON = 0x0400;
|
||||
const LPCWSTR LIBRARY_FILENAMES[] = {
|
||||
L"xinput1_4.dll",
|
||||
L"xinput1_3.dll",
|
||||
L"xinput1_2.dll",
|
||||
L"xinput9_1_0.dll"
|
||||
};
|
||||
}
|
||||
|
||||
class xinput_pad_handler final : public PadHandlerBase
|
||||
{
|
||||
// These are all the possible buttons on a standard xbox 360 or xbox one controller
|
||||
enum XInputKeyCodes
|
||||
{
|
||||
A,
|
||||
B,
|
||||
X,
|
||||
Y,
|
||||
Left,
|
||||
Right,
|
||||
Up,
|
||||
Down,
|
||||
LB,
|
||||
RB,
|
||||
LS,
|
||||
RS,
|
||||
Start,
|
||||
Back,
|
||||
Guide,
|
||||
|
||||
LT,
|
||||
RT,
|
||||
|
||||
LSXNeg,
|
||||
LSXPos,
|
||||
LSYNeg,
|
||||
LSYPos,
|
||||
RSXNeg,
|
||||
RSXPos,
|
||||
RSYNeg,
|
||||
RSYPos,
|
||||
|
||||
KeyCodeCount
|
||||
};
|
||||
|
||||
// Unique names for the config files and our pad settings dialog
|
||||
const std::unordered_map<u32, std::string> button_list =
|
||||
{
|
||||
{ XInputKeyCodes::A, "A" },
|
||||
{ XInputKeyCodes::B, "B" },
|
||||
{ XInputKeyCodes::X, "X" },
|
||||
{ XInputKeyCodes::Y, "Y" },
|
||||
{ XInputKeyCodes::Left, "Left" },
|
||||
{ XInputKeyCodes::Right, "Right" },
|
||||
{ XInputKeyCodes::Up, "Up" },
|
||||
{ XInputKeyCodes::Down, "Down" },
|
||||
{ XInputKeyCodes::LB, "LB" },
|
||||
{ XInputKeyCodes::RB, "RB" },
|
||||
{ XInputKeyCodes::Back, "Back" },
|
||||
{ XInputKeyCodes::Start, "Start" },
|
||||
{ XInputKeyCodes::LS, "LS" },
|
||||
{ XInputKeyCodes::RS, "RS" },
|
||||
{ XInputKeyCodes::Guide, "Guide" },
|
||||
{ XInputKeyCodes::LT, "LT" },
|
||||
{ XInputKeyCodes::RT, "RT" },
|
||||
{ XInputKeyCodes::LSXNeg, "LS X-" },
|
||||
{ XInputKeyCodes::LSXPos, "LS X+" },
|
||||
{ XInputKeyCodes::LSYPos, "LS Y+" },
|
||||
{ XInputKeyCodes::LSYNeg, "LS Y-" },
|
||||
{ XInputKeyCodes::RSXNeg, "RS X-" },
|
||||
{ XInputKeyCodes::RSXPos, "RS X+" },
|
||||
{ XInputKeyCodes::RSYPos, "RS Y+" },
|
||||
{ XInputKeyCodes::RSYNeg, "RS Y-" }
|
||||
};
|
||||
|
||||
struct XInputDevice
|
||||
{
|
||||
u32 deviceNumber{ 0 };
|
||||
bool newVibrateData{ true };
|
||||
u8 largeVibrate{ 0 };
|
||||
u8 smallVibrate{ 0 };
|
||||
clock_t last_vibration{ 0 };
|
||||
};
|
||||
|
||||
public:
|
||||
xinput_pad_handler();
|
||||
~xinput_pad_handler();
|
||||
|
@ -48,25 +107,27 @@ public:
|
|||
std::vector<std::string> ListDevices() override;
|
||||
bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override;
|
||||
void ThreadProc() override;
|
||||
void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback) override;
|
||||
void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override;
|
||||
|
||||
private:
|
||||
typedef void (WINAPI * PFN_XINPUTENABLE)(BOOL);
|
||||
typedef DWORD (WINAPI * PFN_XINPUTGETSTATE)(DWORD, XINPUT_STATE *);
|
||||
typedef DWORD (WINAPI * PFN_XINPUTSETSTATE)(DWORD, XINPUT_VIBRATION *);
|
||||
typedef DWORD (WINAPI * PFN_XINPUTGETBATTERYINFORMATION)(DWORD, BYTE, XINPUT_BATTERY_INFORMATION *);
|
||||
|
||||
private:
|
||||
std::tuple<u16, u16> ConvertToSquirclePoint(u16 inX, u16 inY);
|
||||
std::array<u16, XInputKeyCodes::KeyCodeCount> GetButtonValues(const XINPUT_STATE& state);
|
||||
void TranslateButtonPress(u64 keyCode, bool& pressed, u16& val, bool ignore_threshold = false) override;
|
||||
|
||||
private:
|
||||
bool is_init;
|
||||
float squircle_factor;
|
||||
u32 left_stick_deadzone, right_stick_deadzone;
|
||||
HMODULE library;
|
||||
PFN_XINPUTGETSTATE xinputGetState;
|
||||
PFN_XINPUTSETSTATE xinputSetState;
|
||||
PFN_XINPUTENABLE xinputEnable;
|
||||
PFN_XINPUTGETBATTERYINFORMATION xinputGetBatteryInformation;
|
||||
|
||||
std::vector<std::pair<u32, std::shared_ptr<Pad>>> bindings;
|
||||
std::vector<std::pair<std::shared_ptr<XInputDevice>, std::shared_ptr<Pad>>> bindings;
|
||||
std::array<bool, 7> last_connection_status = {};
|
||||
|
||||
// holds internal controller state change
|
||||
|
@ -74,7 +135,3 @@ private:
|
|||
DWORD result;
|
||||
DWORD online = 0;
|
||||
};
|
||||
|
||||
extern xinput_config xinput_cfg;
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue