mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-11 09:18:40 +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
|
@ -8,91 +8,259 @@
|
|||
#include <vector>
|
||||
#include <thread>
|
||||
|
||||
enum { EVDEV_DPAD_HAT_AXIS_X = -1, EVDEV_DPAD_HAT_AXIS_Y = -2 };
|
||||
|
||||
struct evdev_joystick_config final : cfg::node
|
||||
{
|
||||
const std::string cfg_name = fs::get_config_dir() + "/config_linuxjoystick.yml";
|
||||
|
||||
cfg::int32 select{this, "Select", 6};
|
||||
cfg::int32 start{this, "Start", 7};
|
||||
cfg::int32 cross{this, "Cross", 0};
|
||||
cfg::int32 circle{this, "Circle", 1};
|
||||
cfg::int32 square{this, "Square", 2};
|
||||
cfg::int32 triangle{this, "Triangle", 3};
|
||||
|
||||
cfg::int32 r1{this, "R1", 5};
|
||||
cfg::int32 r2{this, "R2", 11};
|
||||
cfg::int32 r3{this, "R3", 10};
|
||||
cfg::int32 l1{this, "L1", 4};
|
||||
cfg::int32 l2{this, "L2", 12};
|
||||
cfg::int32 l3{this, "L3", 9};
|
||||
|
||||
cfg::int32 up{this, "Up", EVDEV_DPAD_HAT_AXIS_Y};
|
||||
cfg::int32 down{this, "Down", EVDEV_DPAD_HAT_AXIS_Y};
|
||||
cfg::int32 left{this, "Left", EVDEV_DPAD_HAT_AXIS_X};
|
||||
cfg::int32 right{this, "Right", EVDEV_DPAD_HAT_AXIS_X};
|
||||
|
||||
cfg::int32 rxstick{this, "Right stick X axis", 0};
|
||||
cfg::int32 rystick{this, "Right stick Y axis", 1};
|
||||
cfg::int32 lxstick{this, "Left stick X axis", 2};
|
||||
cfg::int32 lystick{this, "Left stick Y axis", 3};
|
||||
|
||||
cfg::_bool rxreverse{this, "Reverse right stick X axis", false};
|
||||
cfg::_bool ryreverse{this, "Reverse right stick Y axis", false};
|
||||
cfg::_bool lxreverse{this, "Reverse left stick X axis", false};
|
||||
cfg::_bool lyreverse{this, "Reverse left stick Y axis", false};
|
||||
|
||||
cfg::_bool axistrigger{this, "Z axis triggers", true};
|
||||
cfg::_bool squirclejoysticks{this, "Squircle Joysticks", true};
|
||||
cfg::int32 squirclefactor{this, "Squircle Factor", 5000};
|
||||
cfg::int32 deadzone{this, "Deadzone", 10};
|
||||
cfg::_bool left_analog_to_dpad{this, "Left Analog to Dpad", false};
|
||||
|
||||
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());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class evdev_joystick_handler final : public PadHandlerBase
|
||||
{
|
||||
public:
|
||||
evdev_joystick_handler();
|
||||
~evdev_joystick_handler();
|
||||
// Unique button names for the config files and our pad settings dialog
|
||||
const std::unordered_map<u32, std::string> button_list =
|
||||
{
|
||||
//{ BTN_MISC , "Misc" }, same as BTN_0
|
||||
{ BTN_0 , "0" },
|
||||
{ BTN_1 , "1" },
|
||||
{ BTN_2 , "2" },
|
||||
{ BTN_3 , "3" },
|
||||
{ BTN_4 , "4" },
|
||||
{ BTN_5 , "5" },
|
||||
{ BTN_6 , "6" },
|
||||
{ BTN_7 , "7" },
|
||||
{ BTN_8 , "8" },
|
||||
{ BTN_9 , "9" },
|
||||
//{ BTN_MOUSE , "Mouse" }, same as BTN_LEFT
|
||||
{ BTN_LEFT , "Left" },
|
||||
{ BTN_RIGHT , "Right" },
|
||||
{ BTN_MIDDLE , "Middle" },
|
||||
{ BTN_SIDE , "Side" },
|
||||
{ BTN_EXTRA , "Extra" },
|
||||
{ BTN_FORWARD , "Forward" },
|
||||
{ BTN_BACK , "Back" },
|
||||
{ BTN_TASK , "Task" },
|
||||
{ BTN_JOYSTICK , "Joystick" },
|
||||
{ BTN_TRIGGER , "Trigger" },
|
||||
{ BTN_THUMB , "Thumb" },
|
||||
{ BTN_THUMB2 , "Thumb 2" },
|
||||
{ BTN_TOP , "Top" },
|
||||
{ BTN_TOP2 , "Top 2" },
|
||||
{ BTN_PINKIE , "Pinkie" },
|
||||
{ BTN_BASE , "Base" },
|
||||
{ BTN_BASE2 , "Base 2" },
|
||||
{ BTN_BASE3 , "Base 3" },
|
||||
{ BTN_BASE4 , "Base 4" },
|
||||
{ BTN_BASE5 , "Base 5" },
|
||||
{ BTN_BASE6 , "Base 6" },
|
||||
{ BTN_DEAD , "Dead" },
|
||||
//{ BTN_GAMEPAD , "Gamepad" }, same as BTN_A
|
||||
//{ BTN_SOUTH , "South" }, same as BTN_A
|
||||
{ BTN_A , "A" },
|
||||
//{ BTN_EAST , "South" }, same as BTN_B
|
||||
{ BTN_B , "B" },
|
||||
{ BTN_C , "C" },
|
||||
//{ BTN_NORTH , "North" }, same as BTN_X
|
||||
{ BTN_X , "X" },
|
||||
//{ BTN_WEST , "West" }, same as BTN_Y
|
||||
{ BTN_Y , "Y" },
|
||||
{ BTN_Z , "Z" },
|
||||
{ BTN_TL , "TL" },
|
||||
{ BTN_TR , "TR" },
|
||||
{ BTN_TL2 , "TL 2" },
|
||||
{ BTN_TR2 , "TR 2" },
|
||||
{ BTN_SELECT , "Select" },
|
||||
{ BTN_START , "Start" },
|
||||
{ BTN_MODE , "Mode" },
|
||||
{ BTN_THUMBL , "Thumb L" },
|
||||
{ BTN_THUMBR , "Thumb R" },
|
||||
//{ BTN_DIGI , "Digi" }, same as BTN_TOOL_PEN
|
||||
{ BTN_TOOL_PEN , "Pen" },
|
||||
{ BTN_TOOL_RUBBER , "Rubber" },
|
||||
{ BTN_TOOL_BRUSH , "Brush" },
|
||||
{ BTN_TOOL_PENCIL , "Pencil" },
|
||||
{ BTN_TOOL_AIRBRUSH , "Airbrush" },
|
||||
{ BTN_TOOL_FINGER , "Finger" },
|
||||
{ BTN_TOOL_MOUSE , "Mouse" },
|
||||
{ BTN_TOOL_LENS , "Lense" },
|
||||
{ BTN_TOOL_QUINTTAP , "Quinttap" },
|
||||
{ BTN_TOUCH , "Touch" },
|
||||
{ BTN_STYLUS , "Stylus" },
|
||||
{ BTN_STYLUS2 , "Stylus 2" },
|
||||
{ BTN_TOOL_DOUBLETAP , "Doubletap" },
|
||||
{ BTN_TOOL_TRIPLETAP , "Tripletap" },
|
||||
{ BTN_TOOL_QUADTAP , "Quadtap" },
|
||||
//{ BTN_WHEEL , "Wheel" }, same as BTN_GEAR_DOWN
|
||||
{ BTN_GEAR_DOWN , "Gear Up" },
|
||||
{ BTN_GEAR_UP , "Gear Down" },
|
||||
{ BTN_DPAD_UP , "D-Pad Up" },
|
||||
{ BTN_DPAD_DOWN , "D-Pad Down" },
|
||||
{ BTN_DPAD_LEFT , "D-Pad Left" },
|
||||
{ BTN_DPAD_RIGHT , "D-Pad Right" },
|
||||
{ BTN_TRIGGER_HAPPY , "Happy" },
|
||||
{ BTN_TRIGGER_HAPPY1 , "Happy 1" },
|
||||
{ BTN_TRIGGER_HAPPY2 , "Happy 2" },
|
||||
{ BTN_TRIGGER_HAPPY3 , "Happy 3" },
|
||||
{ BTN_TRIGGER_HAPPY4 , "Happy 4" },
|
||||
{ BTN_TRIGGER_HAPPY5 , "Happy 5" },
|
||||
{ BTN_TRIGGER_HAPPY6 , "Happy 6" },
|
||||
{ BTN_TRIGGER_HAPPY7 , "Happy 7" },
|
||||
{ BTN_TRIGGER_HAPPY8 , "Happy 8" },
|
||||
{ BTN_TRIGGER_HAPPY9 , "Happy 9" },
|
||||
{ BTN_TRIGGER_HAPPY10 , "Happy 10" },
|
||||
{ BTN_TRIGGER_HAPPY11 , "Happy 11" },
|
||||
{ BTN_TRIGGER_HAPPY12 , "Happy 12" },
|
||||
{ BTN_TRIGGER_HAPPY13 , "Happy 13" },
|
||||
{ BTN_TRIGGER_HAPPY14 , "Happy 14" },
|
||||
{ BTN_TRIGGER_HAPPY15 , "Happy 15" },
|
||||
{ BTN_TRIGGER_HAPPY16 , "Happy 16" },
|
||||
{ BTN_TRIGGER_HAPPY17 , "Happy 17" },
|
||||
{ BTN_TRIGGER_HAPPY18 , "Happy 18" },
|
||||
{ BTN_TRIGGER_HAPPY19 , "Happy 19" },
|
||||
{ BTN_TRIGGER_HAPPY20 , "Happy 20" },
|
||||
{ BTN_TRIGGER_HAPPY21 , "Happy 21" },
|
||||
{ BTN_TRIGGER_HAPPY22 , "Happy 22" },
|
||||
{ BTN_TRIGGER_HAPPY23 , "Happy 23" },
|
||||
{ BTN_TRIGGER_HAPPY24 , "Happy 24" },
|
||||
{ BTN_TRIGGER_HAPPY25 , "Happy 25" },
|
||||
{ BTN_TRIGGER_HAPPY26 , "Happy 26" },
|
||||
{ BTN_TRIGGER_HAPPY27 , "Happy 27" },
|
||||
{ BTN_TRIGGER_HAPPY28 , "Happy 28" },
|
||||
{ BTN_TRIGGER_HAPPY29 , "Happy 29" },
|
||||
{ BTN_TRIGGER_HAPPY30 , "Happy 30" },
|
||||
{ BTN_TRIGGER_HAPPY31 , "Happy 31" },
|
||||
{ BTN_TRIGGER_HAPPY32 , "Happy 32" },
|
||||
{ BTN_TRIGGER_HAPPY33 , "Happy 33" },
|
||||
{ BTN_TRIGGER_HAPPY34 , "Happy 34" },
|
||||
{ BTN_TRIGGER_HAPPY35 , "Happy 35" },
|
||||
{ BTN_TRIGGER_HAPPY36 , "Happy 36" },
|
||||
{ BTN_TRIGGER_HAPPY37 , "Happy 37" },
|
||||
{ BTN_TRIGGER_HAPPY38 , "Happy 38" },
|
||||
{ BTN_TRIGGER_HAPPY39 , "Happy 39" },
|
||||
{ BTN_TRIGGER_HAPPY40 , "Happy 40" },
|
||||
};
|
||||
|
||||
bool Init() override;
|
||||
std::vector<std::string> ListDevices() override;
|
||||
bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override;
|
||||
void ThreadProc() override;
|
||||
void Close();
|
||||
// Unique positive axis names for the config files and our pad settings dialog
|
||||
const std::unordered_map<u32, std::string> axis_list =
|
||||
{
|
||||
{ ABS_X , "LX+" },
|
||||
{ ABS_Y , "LY+" },
|
||||
{ ABS_Z , "LZ+" },
|
||||
{ ABS_RX , "RX+" },
|
||||
{ ABS_RY , "RY+" },
|
||||
{ ABS_RZ , "RZ+" },
|
||||
{ ABS_THROTTLE , "Throttle+" },
|
||||
{ ABS_RUDDER , "Rudder+" },
|
||||
{ ABS_WHEEL , "Wheel+" },
|
||||
{ ABS_GAS , "Gas+" },
|
||||
{ ABS_BRAKE , "Brake+" },
|
||||
{ ABS_HAT0X , "Hat0 X+" },
|
||||
{ ABS_HAT0Y , "Hat0 Y+" },
|
||||
{ ABS_HAT1X , "Hat1 X+" },
|
||||
{ ABS_HAT1Y , "Hat1 Y+" },
|
||||
{ ABS_HAT2X , "Hat2 X+" },
|
||||
{ ABS_HAT2Y , "Hat2 Y+" },
|
||||
{ ABS_HAT3X , "Hat3 X+" },
|
||||
{ ABS_HAT3Y , "Hat3 Y+" },
|
||||
{ ABS_PRESSURE , "Pressure+" },
|
||||
{ ABS_DISTANCE , "Distance+" },
|
||||
{ ABS_TILT_X , "Tilt X+" },
|
||||
{ ABS_TILT_Y , "Tilt Y+" },
|
||||
{ ABS_TOOL_WIDTH , "Width+" },
|
||||
{ ABS_VOLUME , "Volume+" },
|
||||
{ ABS_MISC , "Misc+" },
|
||||
{ ABS_MT_SLOT , "Slot+" },
|
||||
{ ABS_MT_TOUCH_MAJOR , "MT TMaj+" },
|
||||
{ ABS_MT_TOUCH_MINOR , "MT TMin+" },
|
||||
{ ABS_MT_WIDTH_MAJOR , "MT WMaj+" },
|
||||
{ ABS_MT_WIDTH_MINOR , "MT WMin+" },
|
||||
{ ABS_MT_ORIENTATION , "MT Orient+" },
|
||||
{ ABS_MT_POSITION_X , "MT PosX+" },
|
||||
{ ABS_MT_POSITION_Y , "MT PosY+" },
|
||||
{ ABS_MT_TOOL_TYPE , "MT TType+" },
|
||||
{ ABS_MT_BLOB_ID , "MT Blob ID+" },
|
||||
{ ABS_MT_TRACKING_ID , "MT Track ID+" },
|
||||
{ ABS_MT_PRESSURE , "MT Pressure+" },
|
||||
{ ABS_MT_DISTANCE , "MT Distance+" },
|
||||
{ ABS_MT_TOOL_X , "MT Tool X+" },
|
||||
{ ABS_MT_TOOL_Y , "MT Tool Y+" },
|
||||
};
|
||||
|
||||
// Unique negative axis names for the config files and our pad settings dialog
|
||||
const std::unordered_map<u32, std::string> rev_axis_list =
|
||||
{
|
||||
{ ABS_X , "LX-" },
|
||||
{ ABS_Y , "LY-" },
|
||||
{ ABS_Z , "LZ-" },
|
||||
{ ABS_RX , "RX-" },
|
||||
{ ABS_RY , "RY-" },
|
||||
{ ABS_RZ , "RZ-" },
|
||||
{ ABS_THROTTLE , "Throttle-" },
|
||||
{ ABS_RUDDER , "Rudder-" },
|
||||
{ ABS_WHEEL , "Wheel-" },
|
||||
{ ABS_GAS , "Gas-" },
|
||||
{ ABS_BRAKE , "Brake-" },
|
||||
{ ABS_HAT0X , "Hat0 X-" },
|
||||
{ ABS_HAT0Y , "Hat0 Y-" },
|
||||
{ ABS_HAT1X , "Hat1 X-" },
|
||||
{ ABS_HAT1Y , "Hat1 Y-" },
|
||||
{ ABS_HAT2X , "Hat2 X-" },
|
||||
{ ABS_HAT2Y , "Hat2 Y-" },
|
||||
{ ABS_HAT3X , "Hat3 X-" },
|
||||
{ ABS_HAT3Y , "Hat3 Y-" },
|
||||
{ ABS_PRESSURE , "Pressure-" },
|
||||
{ ABS_DISTANCE , "Distance-" },
|
||||
{ ABS_TILT_X , "Tilt X-" },
|
||||
{ ABS_TILT_Y , "Tilt Y-" },
|
||||
{ ABS_TOOL_WIDTH , "Width-" },
|
||||
{ ABS_VOLUME , "Volume-" },
|
||||
{ ABS_MISC , "Misc-" },
|
||||
{ ABS_MT_SLOT , "Slot-" },
|
||||
{ ABS_MT_TOUCH_MAJOR , "MT TMaj-" },
|
||||
{ ABS_MT_TOUCH_MINOR , "MT TMin-" },
|
||||
{ ABS_MT_WIDTH_MAJOR , "MT WMaj-" },
|
||||
{ ABS_MT_WIDTH_MINOR , "MT WMin-" },
|
||||
{ ABS_MT_ORIENTATION , "MT Orient-" },
|
||||
{ ABS_MT_POSITION_X , "MT PosX-" },
|
||||
{ ABS_MT_POSITION_Y , "MT PosY-" },
|
||||
{ ABS_MT_TOOL_TYPE , "MT TType-" },
|
||||
{ ABS_MT_BLOB_ID , "MT Blob ID-" },
|
||||
{ ABS_MT_TRACKING_ID , "MT Track ID-" },
|
||||
{ ABS_MT_PRESSURE , "MT Pressure-" },
|
||||
{ ABS_MT_DISTANCE , "MT Distance-" },
|
||||
{ ABS_MT_TOOL_X , "MT Tool X-" },
|
||||
{ ABS_MT_TOOL_Y , "MT Tool Y-" },
|
||||
};
|
||||
|
||||
struct EvdevDevice
|
||||
{
|
||||
libevdev* device;
|
||||
std::string path;
|
||||
std::shared_ptr<Pad> pad;
|
||||
std::unordered_map<int, bool> axis_orientations; // value is true if key was found in rev_axis_list
|
||||
float stick_val[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
u16 val_min[4] = { 0, 0, 0, 0 };
|
||||
u16 val_max[4] = { 0, 0, 0, 0 };
|
||||
};
|
||||
|
||||
const int BUTTON_COUNT = 17;
|
||||
|
||||
public:
|
||||
evdev_joystick_handler();
|
||||
~evdev_joystick_handler();
|
||||
|
||||
bool Init() override;
|
||||
std::vector<std::string> ListDevices() override;
|
||||
bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override;
|
||||
void ThreadProc() override;
|
||||
void Close();
|
||||
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:
|
||||
void update_devs();
|
||||
std::tuple<u16, u16> ConvertToSquirclePoint(u16 inX, u16 inY);
|
||||
bool try_open_dev(u32 index);
|
||||
int scale_axis(int axis, int value);
|
||||
void TranslateButtonPress(u64 keyCode, bool& pressed, u16& value, bool ignore_threshold = false) override;
|
||||
bool update_device(EvdevDevice& device, bool use_cell = true);
|
||||
void update_devs(bool use_cell = true);
|
||||
int add_device(const std::string& device, bool in_settings = false, std::shared_ptr<Pad> pad = nullptr, const std::unordered_map<int, bool>& axis_map = std::unordered_map<int, bool>());
|
||||
int GetButtonInfo(const input_event& evt, libevdev* dev, int& button_code, bool& is_negative);
|
||||
std::unordered_map<u64, std::pair<u16, bool>> GetButtonValues(libevdev* dev);
|
||||
|
||||
std::vector<std::string> joy_paths;
|
||||
std::vector<std::shared_ptr<Pad>> pads;
|
||||
std::vector<libevdev*> joy_devs;
|
||||
std::vector<std::vector<int>> joy_button_maps;
|
||||
std::vector<std::vector<int>> joy_axis_maps;
|
||||
// joy_axis is only used for squircling
|
||||
std::vector<std::vector<int>> joy_axis;
|
||||
std::vector<int> joy_hat_ids;
|
||||
bool axistrigger;
|
||||
std::map<int, std::pair<int, int>> axis_ranges;
|
||||
std::vector<bool> revaxis;
|
||||
// Search axis_orientations map for the direction by index, returns -1 if not found, 0 for positive and 1 for negative
|
||||
int FindAxisDirection(const std::unordered_map<int, bool>& map, int index);
|
||||
|
||||
std::vector<EvdevDevice> devices;
|
||||
int m_pad_index = -1;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue