diff --git a/rpcs3/Emu/Io/PadHandler.cpp b/rpcs3/Emu/Io/PadHandler.cpp index d444eb8cf8..43998b5be8 100644 --- a/rpcs3/Emu/Io/PadHandler.cpp +++ b/rpcs3/Emu/Io/PadHandler.cpp @@ -474,7 +474,7 @@ bool PadHandlerBase::bindPadToDevice(std::shared_ptr pad, const std::string u32 pclass_profile = 0x0; - for (const auto product : input::get_products_by_class(profile->device_class_type)) + for (const auto& product : input::get_products_by_class(profile->device_class_type)) { if (product.vendor_id == profile->vendor_id && product.product_id == profile->product_id) { diff --git a/rpcs3/Input/ds3_pad_handler.cpp b/rpcs3/Input/ds3_pad_handler.cpp index 2e031dcf08..c2c27c8d4b 100644 --- a/rpcs3/Input/ds3_pad_handler.cpp +++ b/rpcs3/Input/ds3_pad_handler.cpp @@ -49,6 +49,7 @@ ds3_pad_handler::ds3_pad_handler() { button_list = { + { DS3KeyCodes::None, "" }, { DS3KeyCodes::Triangle, "Triangle" }, { DS3KeyCodes::Circle, "Circle" }, { DS3KeyCodes::Cross, "Cross" }, @@ -229,7 +230,7 @@ void ds3_pad_handler::init_config(pad_config* cfg, const std::string& name) cfg->l2.def = button_list.at(DS3KeyCodes::L2); cfg->l3.def = button_list.at(DS3KeyCodes::L3); - cfg->pressure_intensity_button.def = ""; + cfg->pressure_intensity_button.def = button_list.at(DS3KeyCodes::None); // Set default misc variables cfg->lstickdeadzone.def = 40; // between 0 and 255 diff --git a/rpcs3/Input/ds3_pad_handler.h b/rpcs3/Input/ds3_pad_handler.h index 59dd34a61f..6245f871dd 100644 --- a/rpcs3/Input/ds3_pad_handler.h +++ b/rpcs3/Input/ds3_pad_handler.h @@ -16,7 +16,9 @@ class ds3_pad_handler final : public hid_pad_handler { enum DS3KeyCodes { - Triangle = 0, + None = 0, + + Triangle, Circle, Cross, Square, @@ -42,9 +44,7 @@ class ds3_pad_handler final : public hid_pad_handler RSXNeg, RSXPos, RSYNeg, - RSYPos, - - KeyCodeCount + RSYPos }; enum HidRequest diff --git a/rpcs3/Input/ds4_pad_handler.cpp b/rpcs3/Input/ds4_pad_handler.cpp index b7d18ac268..38a5bfd02c 100644 --- a/rpcs3/Input/ds4_pad_handler.cpp +++ b/rpcs3/Input/ds4_pad_handler.cpp @@ -76,6 +76,7 @@ ds4_pad_handler::ds4_pad_handler() // Unique names for the config files and our pad settings dialog button_list = { + { DS4KeyCodes::None, "" }, { DS4KeyCodes::Triangle, "Triangle" }, { DS4KeyCodes::Circle, "Circle" }, { DS4KeyCodes::Cross, "Cross" }, @@ -162,7 +163,7 @@ void ds4_pad_handler::init_config(pad_config* cfg, const std::string& name) cfg->l2.def = button_list.at(DS4KeyCodes::L2); cfg->l3.def = button_list.at(DS4KeyCodes::L3); - cfg->pressure_intensity_button.def = ""; + cfg->pressure_intensity_button.def = button_list.at(DS4KeyCodes::None); // Set default misc variables cfg->lstickdeadzone.def = 40; // between 0 and 255 diff --git a/rpcs3/Input/ds4_pad_handler.h b/rpcs3/Input/ds4_pad_handler.h index 0c2d2681cb..ccefd4f0bc 100644 --- a/rpcs3/Input/ds4_pad_handler.h +++ b/rpcs3/Input/ds4_pad_handler.h @@ -18,7 +18,9 @@ class ds4_pad_handler final : public hid_pad_handler // The touchpad is restricted to its button for now (or forever?) enum DS4KeyCodes { - Triangle = 0, + None = 0, + + Triangle, Circle, Cross, Square, @@ -47,9 +49,7 @@ class ds4_pad_handler final : public hid_pad_handler RSXNeg, RSXPos, RSYNeg, - RSYPos, - - KeyCodeCount + RSYPos }; public: diff --git a/rpcs3/Input/dualsense_pad_handler.cpp b/rpcs3/Input/dualsense_pad_handler.cpp index e1b18b607a..76fcb14e61 100644 --- a/rpcs3/Input/dualsense_pad_handler.cpp +++ b/rpcs3/Input/dualsense_pad_handler.cpp @@ -95,6 +95,7 @@ dualsense_pad_handler::dualsense_pad_handler() // Unique names for the config files and our pad settings dialog button_list = { + { DualSenseKeyCodes::None, "" }, { DualSenseKeyCodes::Triangle, "Triangle" }, { DualSenseKeyCodes::Circle, "Circle" }, { DualSenseKeyCodes::Cross, "Cross" }, @@ -273,7 +274,7 @@ void dualsense_pad_handler::init_config(pad_config* cfg, const std::string& name cfg->l2.def = button_list.at(DualSenseKeyCodes::L2); cfg->l3.def = button_list.at(DualSenseKeyCodes::L3); - cfg->pressure_intensity_button.def = ""; + cfg->pressure_intensity_button.def = button_list.at(DualSenseKeyCodes::None); // Set default misc variables cfg->lstickdeadzone.def = 40; // between 0 and 255 diff --git a/rpcs3/Input/dualsense_pad_handler.h b/rpcs3/Input/dualsense_pad_handler.h index b19eac0edb..2019524920 100644 --- a/rpcs3/Input/dualsense_pad_handler.h +++ b/rpcs3/Input/dualsense_pad_handler.h @@ -32,7 +32,9 @@ class dualsense_pad_handler final : public hid_pad_handler { enum DualSenseKeyCodes { - Triangle = 0, + None = 0, + + Triangle, Circle, Cross, Square, @@ -60,9 +62,7 @@ class dualsense_pad_handler final : public hid_pad_handler RSXNeg, RSXPos, RSYNeg, - RSYPos, - - KeyCodeCount + RSYPos }; public: diff --git a/rpcs3/Input/evdev_joystick_handler.cpp b/rpcs3/Input/evdev_joystick_handler.cpp index e549647a9b..bf6a069e10 100644 --- a/rpcs3/Input/evdev_joystick_handler.cpp +++ b/rpcs3/Input/evdev_joystick_handler.cpp @@ -81,7 +81,7 @@ void evdev_joystick_handler::init_config(pad_config* cfg, const std::string& nam cfg->l2.def = axis_list.at(ABS_Z); cfg->l3.def = button_list.at(BTN_THUMBL); - cfg->pressure_intensity_button.def = ""; + cfg->pressure_intensity_button.def = button_list.at(NO_BUTTON); // Set default misc variables cfg->lstickdeadzone.def = 30; // between 0 and 255 @@ -225,7 +225,11 @@ std::unordered_map> evdev_joystick_handler::GetButtonV for (const auto& entry : button_list) { const auto code = entry.first; - int val = 0; + + if (code == NO_BUTTON) + continue; + + int val = 0; if (libevdev_fetch_event_value(dev, EV_KEY, code, &val) == 0) continue; @@ -340,6 +344,8 @@ void evdev_joystick_handler::get_next_button_press(const std::string& padId, con for (const auto& [code, name] : button_list) { // Handle annoying useless buttons + if (code == NO_BUTTON) + continue; if (padId.find("Xbox 360") != umax && code >= BTN_TRIGGER_HAPPY) continue; if (padId.find("Sony") != umax && (code == BTN_TL2 || code == BTN_TR2)) @@ -522,9 +528,9 @@ void evdev_joystick_handler::SetPadData(const std::string& padId, u32 largeMotor SetRumble(static_cast(dev.get()), largeMotor, smallMotor); } -int evdev_joystick_handler::GetButtonInfo(const input_event& evt, const std::shared_ptr& device, int& value) +u32 evdev_joystick_handler::GetButtonInfo(const input_event& evt, const std::shared_ptr& device, int& value) { - const int code = evt.code; + const u32 code = evt.code; const int val = evt.value; m_is_button_or_trigger = false; @@ -744,8 +750,8 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr& devic m_dev->cur_type = evt.type; int value; - const int button_code = GetButtonInfo(evt, m_dev, value); - if (button_code < 0 || value < 0) + const u32 button_code = GetButtonInfo(evt, m_dev, value); + if (button_code == NO_BUTTON || value < 0) return; auto axis_orientations = m_dev->axis_orientations; @@ -753,7 +759,9 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr& devic // Translate any corresponding keycodes to our normal DS3 buttons and triggers for (int i = 0; i < static_cast(pad->m_buttons.size()); i++) { - if (pad->m_buttons[i].m_keyCode != button_code + 0u) + auto& button = pad->m_buttons[i]; + + if (button.m_keyCode != button_code) continue; // Be careful to handle mapped axis specially @@ -771,14 +779,14 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr& devic } else if (direction != (m_is_negative ? 1 : 0)) { - pad->m_buttons[i].m_value = 0; - pad->m_buttons[i].m_pressed = 0; + button.m_value = 0; + button.m_pressed = 0; continue; } } - pad->m_buttons[i].m_value = static_cast(value); - TranslateButtonPress(m_dev, button_code, pad->m_buttons[i].m_pressed, pad->m_buttons[i].m_value); + button.m_value = static_cast(value); + TranslateButtonPress(m_dev, button_code, button.m_pressed, button.m_value); } // Translate any corresponding keycodes to our two sticks. (ignoring thresholds for now) @@ -788,7 +796,7 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr& devic bool pressed_max = false; // m_keyCodeMin is the mapped key for left or down - if (pad->m_sticks[idx].m_keyCodeMin == button_code + 0u) + if (pad->m_sticks[idx].m_keyCodeMin == button_code) { bool is_direction_min = false; @@ -814,7 +822,7 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr& devic } // m_keyCodeMax is the mapped key for right or up - if (pad->m_sticks[idx].m_keyCodeMax == button_code + 0u) + if (pad->m_sticks[idx].m_keyCodeMax == button_code) { bool is_direction_max = false; diff --git a/rpcs3/Input/evdev_joystick_handler.h b/rpcs3/Input/evdev_joystick_handler.h index 0e92177239..eddd6ee80c 100644 --- a/rpcs3/Input/evdev_joystick_handler.h +++ b/rpcs3/Input/evdev_joystick_handler.h @@ -80,9 +80,12 @@ struct positive_axis : cfg::node class evdev_joystick_handler final : public PadHandlerBase { + static constexpr u32 NO_BUTTON = u32{umax}; // Some event code that doesn't exist in evdev (code type is U16) + // Unique button names for the config files and our pad settings dialog const std::unordered_map button_list = { + { NO_BUTTON , "" }, // Xbox One S Controller returns some buttons as key when connected through bluetooth { KEY_BACK , "Back Key" }, { KEY_HOMEPAGE , "Homepage Key"}, @@ -372,7 +375,7 @@ private: bool update_device(const std::shared_ptr& device); void update_devs(); int add_device(const std::string& device, const std::shared_ptr& pad, bool in_settings = false); - int GetButtonInfo(const input_event& evt, const std::shared_ptr& device, int& button_code); + u32 GetButtonInfo(const input_event& evt, const std::shared_ptr& device, int& button_code); std::unordered_map> GetButtonValues(const std::shared_ptr& device); void SetRumble(EvdevDevice* device, u16 large, u16 small); diff --git a/rpcs3/Input/keyboard_pad_handler.cpp b/rpcs3/Input/keyboard_pad_handler.cpp index a588aa30dd..d6de73262f 100644 --- a/rpcs3/Input/keyboard_pad_handler.cpp +++ b/rpcs3/Input/keyboard_pad_handler.cpp @@ -65,7 +65,7 @@ void keyboard_pad_handler::init_config(pad_config* cfg, const std::string& name) cfg->l2.def = GetKeyName(Qt::Key_R); cfg->l3.def = GetKeyName(Qt::Key_F); - cfg->pressure_intensity_button.def = ""; + cfg->pressure_intensity_button.def = GetKeyName(Qt::NoButton); // apply defaults cfg->from_default(); diff --git a/rpcs3/Input/mm_joystick_handler.cpp b/rpcs3/Input/mm_joystick_handler.cpp index 4f3568ac74..fa982dff91 100644 --- a/rpcs3/Input/mm_joystick_handler.cpp +++ b/rpcs3/Input/mm_joystick_handler.cpp @@ -60,7 +60,7 @@ void mm_joystick_handler::init_config(pad_config* cfg, const std::string& name) cfg->l2.def = button_list.at(JOY_BUTTON5); cfg->l3.def = button_list.at(JOY_BUTTON11); - cfg->pressure_intensity_button.def = ""; + cfg->pressure_intensity_button.def = button_list.at(NO_BUTTON); // Set default misc variables cfg->lstickdeadzone.def = 0; // between 0 and 255 @@ -119,6 +119,16 @@ std::vector mm_joystick_handler::ListDevices() return devices; } +u64 mm_joystick_handler::find_key(const std::string& name) const +{ + long key = FindKeyCodeByString(axis_list, name, false); + if (key < 0) + key = FindKeyCodeByString(pov_list, name, false); + if (key < 0) + key = FindKeyCodeByString(button_list, name); + return static_cast(key); +} + std::array mm_joystick_handler::get_mapped_key_codes(const std::shared_ptr& device, const pad_config* profile) { std::array mapping{ 0 }; @@ -127,16 +137,6 @@ std::array mm_joystick_handler::get_m if (!joy_device) return mapping; - auto find_key = [this](const cfg::string& name) - { - long key = FindKeyCode(button_list, name, false); - if (key < 0) - key = FindKeyCode(pov_list, name, false); - if (key < 0) - key = FindKeyCode(axis_list, name); - return static_cast(key); - }; - joy_device->trigger_left = find_key(profile->l2); joy_device->trigger_right = find_key(profile->r2); joy_device->axis_left[0] = find_key(profile->ls_left); @@ -174,6 +174,8 @@ std::array mm_joystick_handler::get_m mapping[button::rs_down] = static_cast(joy_device->axis_right[2]); mapping[button::rs_up] = static_cast(joy_device->axis_right[3]); + mapping[button::pressure_intensity_button] = static_cast(find_key(profile->pressure_intensity_button)); + return mapping; } @@ -272,12 +274,16 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const for (const auto& button : button_list) { - u64 keycode = button.first; - u16 value = data[keycode]; + const u64 keycode = button.first; + + if (keycode == NO_BUTTON) + continue; if (!get_blacklist && std::find(blacklist.begin(), blacklist.end(), keycode) != blacklist.end()) continue; + const u16 value = data[keycode]; + if (value > 0) { if (get_blacklist) @@ -297,16 +303,6 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const return; } - auto find_key = [this](const std::string& name) - { - long key = FindKeyCodeByString(axis_list, name, false); - if (key < 0) - key = FindKeyCodeByString(pov_list, name, false); - if (key < 0) - key = FindKeyCodeByString(button_list, name); - return static_cast(key); - }; - pad_preview_values preview_values = { 0, 0, 0, 0, 0, 0 }; if (buttons.size() == 10) { @@ -339,6 +335,9 @@ std::unordered_map mm_joystick_handler::GetButtonValues(const JOYINFOE for (const auto& entry : button_list) { + if (entry.first == NO_BUTTON) + continue; + button_values.emplace(entry.first, js_info.dwButtons & entry.first ? 255 : 0); } diff --git a/rpcs3/Input/mm_joystick_handler.h b/rpcs3/Input/mm_joystick_handler.h index caa6786893..36e8846f76 100644 --- a/rpcs3/Input/mm_joystick_handler.h +++ b/rpcs3/Input/mm_joystick_handler.h @@ -16,9 +16,12 @@ class mm_joystick_handler final : public PadHandlerBase { + static constexpr u64 NO_BUTTON = 0; + // Unique names for the config files and our pad settings dialog const std::unordered_map button_list = { + { NO_BUTTON , "" }, { JOY_BUTTON1 , "Button 1" }, { JOY_BUTTON2 , "Button 2" }, { JOY_BUTTON3 , "Button 3" }, @@ -128,6 +131,8 @@ private: std::shared_ptr m_dev; std::unordered_map m_devices; + u64 find_key(const std::string& name) const; + std::array get_mapped_key_codes(const std::shared_ptr& device, const pad_config* profile) override; std::shared_ptr get_device(const std::string& device) override; bool get_is_left_trigger(u64 keyCode) override; diff --git a/rpcs3/Input/xinput_pad_handler.cpp b/rpcs3/Input/xinput_pad_handler.cpp index c141b2bc1f..fd6bd26a5a 100644 --- a/rpcs3/Input/xinput_pad_handler.cpp +++ b/rpcs3/Input/xinput_pad_handler.cpp @@ -19,6 +19,7 @@ xinput_pad_handler::xinput_pad_handler() : PadHandlerBase(pad_handler::xinput) // Unique names for the config files and our pad settings dialog button_list = { + { XInputKeyCodes::None, "" }, { XInputKeyCodes::A, "A" }, { XInputKeyCodes::B, "B" }, { XInputKeyCodes::X, "X" }, @@ -116,6 +117,8 @@ void xinput_pad_handler::init_config(pad_config* cfg, const std::string& name) cfg->l2.def = button_list.at(XInputKeyCodes::LT); cfg->l3.def = button_list.at(XInputKeyCodes::LS); + cfg->pressure_intensity_button.def = button_list.at(XInputKeyCodes::None); + // Set default misc variables cfg->lstickdeadzone.def = XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE; // between 0 and 32767 cfg->rstickdeadzone.def = XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE; // between 0 and 32767 diff --git a/rpcs3/Input/xinput_pad_handler.h b/rpcs3/Input/xinput_pad_handler.h index 0b71d32142..ae7a098195 100644 --- a/rpcs3/Input/xinput_pad_handler.h +++ b/rpcs3/Input/xinput_pad_handler.h @@ -57,6 +57,8 @@ class xinput_pad_handler final : public PadHandlerBase // These are all the possible buttons on a standard xbox 360 or xbox one controller enum XInputKeyCodes { + None = 0, + A, B, X, @@ -83,9 +85,7 @@ class xinput_pad_handler final : public PadHandlerBase RSXNeg, RSXPos, RSYNeg, - RSYPos, - - KeyCodeCount + RSYPos }; using PadButtonValues = std::unordered_map;