diff --git a/rpcs3/Emu/Io/PadHandler.cpp b/rpcs3/Emu/Io/PadHandler.cpp index 4111ee2827..81d30c1a2f 100644 --- a/rpcs3/Emu/Io/PadHandler.cpp +++ b/rpcs3/Emu/Io/PadHandler.cpp @@ -655,13 +655,13 @@ void PadHandlerBase::get_mapping(const pad_ensemble& binding) if (!device || !pad) return; - auto cfg = device->config; + const auto cfg = device->config; auto button_values = get_button_values(device); // Find out if special buttons are pressed (introduced by RPCS3). // These buttons will have a delay of one cycle, but whatever. - const bool adjust_pressure = pad->m_pressure_intensity_button_index >= 0 && pad->m_buttons[pad->m_pressure_intensity_button_index].m_pressed; + const bool adjust_pressure = pad->get_pressure_intensity_enabled(cfg->pressure_intensity_toggle_mode.get()); // Translate any corresponding keycodes to our normal DS3 buttons and triggers for (auto& btn : pad->m_buttons) diff --git a/rpcs3/Emu/Io/pad_config.h b/rpcs3/Emu/Io/pad_config.h index 08ef967208..7e4f4baaaa 100644 --- a/rpcs3/Emu/Io/pad_config.h +++ b/rpcs3/Emu/Io/pad_config.h @@ -58,6 +58,7 @@ struct cfg_pad final : cfg::node cfg::string pressure_intensity_button{ this, "Pressure Intensity Button", "" }; cfg::uint<0, 100> pressure_intensity{ this, "Pressure Intensity Percent", 50 }; + cfg::_bool pressure_intensity_toggle_mode{ this, "Pressure Intensity Toggle Mode", false }; cfg::uint<0, 200> lstickmultiplier{ this, "Left Stick Multiplier", 100 }; cfg::uint<0, 200> rstickmultiplier{ this, "Right Stick Multiplier", 100 }; diff --git a/rpcs3/Emu/Io/pad_types.cpp b/rpcs3/Emu/Io/pad_types.cpp index e6d7b9d17d..b62fee2f57 100644 --- a/rpcs3/Emu/Io/pad_types.cpp +++ b/rpcs3/Emu/Io/pad_types.cpp @@ -131,3 +131,30 @@ u32 get_axis_keycode(u32 offset, u16 value) default: return static_cast(axis_direction::both); } } + +bool Pad::get_pressure_intensity_enabled(bool is_toggle_mode) +{ + if (m_pressure_intensity_button_index < 0) + { + return false; + } + + const Button& pressure_intensity_button = m_buttons[m_pressure_intensity_button_index]; + + if (is_toggle_mode) + { + const bool pressed = pressure_intensity_button.m_pressed; + + if (std::exchange(m_pressure_intensity_button_pressed, pressed) != pressed) + { + if (pressed) + { + m_pressure_intensity_toggled = !m_pressure_intensity_toggled; + } + } + + return m_pressure_intensity_toggled; + } + + return pressure_intensity_button.m_pressed; +} diff --git a/rpcs3/Emu/Io/pad_types.h b/rpcs3/Emu/Io/pad_types.h index b49941d365..7c59caf531 100644 --- a/rpcs3/Emu/Io/pad_types.h +++ b/rpcs3/Emu/Io/pad_types.h @@ -334,7 +334,10 @@ struct Pad u16 m_product_id{0}; s32 m_pressure_intensity_button_index{-1}; // Special button index. -1 if not set. + bool m_pressure_intensity_button_pressed{}; // Last sensitivity button press state, used for toggle. + bool m_pressure_intensity_toggled{}; // Whether the sensitivity is toggled on or off. u8 m_pressure_intensity{127}; // 0-255 + bool get_pressure_intensity_enabled(bool is_toggle_mode); // Cable State: 0 - 1 plugged in ? u8 m_cable_state{0}; diff --git a/rpcs3/Input/evdev_joystick_handler.cpp b/rpcs3/Input/evdev_joystick_handler.cpp index ee1ed4e4d9..c872167be1 100644 --- a/rpcs3/Input/evdev_joystick_handler.cpp +++ b/rpcs3/Input/evdev_joystick_handler.cpp @@ -1011,11 +1011,15 @@ void evdev_joystick_handler::handle_input_event(const input_event& evt, const st if (button_code == NO_BUTTON || value < 0) return; + const auto cfg = m_dev->config; + if (!cfg) + return; + auto axis_orientations = m_dev->axis_orientations; // Find out if special buttons are pressed (introduced by RPCS3). // These buttons will have a delay of one cycle, but whatever. - const bool adjust_pressure = pad->m_pressure_intensity_button_index >= 0 && pad->m_buttons[pad->m_pressure_intensity_button_index].m_pressed; + const bool adjust_pressure = pad->get_pressure_intensity_enabled(cfg->pressure_intensity_toggle_mode.get()); // Translate any corresponding keycodes to our normal DS3 buttons and triggers for (int i = 0; i < static_cast(pad->m_buttons.size()); i++) @@ -1128,10 +1132,6 @@ void evdev_joystick_handler::handle_input_event(const input_event& evt, const st m_dev->stick_val[idx] = m_dev->val_max[idx] - m_dev->val_min[idx]; } - const auto cfg = m_dev->config; - if (!cfg) - return; - u16 lx, ly, rx, ry; // Normalize and apply pad squircling diff --git a/rpcs3/Input/keyboard_pad_handler.cpp b/rpcs3/Input/keyboard_pad_handler.cpp index 57682654be..0bf0c92270 100644 --- a/rpcs3/Input/keyboard_pad_handler.cpp +++ b/rpcs3/Input/keyboard_pad_handler.cpp @@ -81,8 +81,6 @@ void keyboard_pad_handler::Key(const u32 code, bool pressed, u16 value) { // Find out if special buttons are pressed (introduced by RPCS3). // Activate the buttons here if possible since keys don't auto-repeat. This ensures that they are already pressed in the following loop. - bool adjust_pressure = false; - if (pad.m_pressure_intensity_button_index >= 0) { Button& pressure_intensity_button = pad.m_buttons[pad.m_pressure_intensity_button_index]; @@ -92,10 +90,10 @@ void keyboard_pad_handler::Key(const u32 code, bool pressed, u16 value) pressure_intensity_button.m_pressed = pressed; pressure_intensity_button.m_value = value; } - - adjust_pressure = pressure_intensity_button.m_pressed; } + const bool adjust_pressure = pad.get_pressure_intensity_enabled(m_pressure_intensity_toggle_mode); + // Handle buttons for (Button& button : pad.m_buttons) { @@ -795,7 +793,7 @@ bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr pad, u8 player_i return false; m_pad_configs[player_id].from_string(player_config->config.to_string()); - cfg_pad* cfg = &m_pad_configs[player_id]; + const cfg_pad* cfg = &m_pad_configs[player_id]; if (cfg == nullptr) return false; @@ -812,6 +810,7 @@ bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr pad, u8 player_i m_trigger_lerp_factor = cfg->trigger_lerp_factor / 100.0f; m_l_stick_multiplier = cfg->lstickmultiplier; m_r_stick_multiplier = cfg->rstickmultiplier; + m_pressure_intensity_toggle_mode = cfg->pressure_intensity_toggle_mode.get(); const auto find_key = [this](const cfg::string& name) { diff --git a/rpcs3/Input/keyboard_pad_handler.h b/rpcs3/Input/keyboard_pad_handler.h index e8dbd0814a..98926d150d 100644 --- a/rpcs3/Input/keyboard_pad_handler.h +++ b/rpcs3/Input/keyboard_pad_handler.h @@ -116,6 +116,7 @@ private: steady_clock::time_point m_button_time; f32 m_analog_lerp_factor = 1.0f; f32 m_trigger_lerp_factor = 1.0f; + bool m_pressure_intensity_toggle_mode{}; // Stick Movements steady_clock::time_point m_stick_time; diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.cpp b/rpcs3/rpcs3qt/pad_settings_dialog.cpp index 6c325f4a3f..7b2f7281d5 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/pad_settings_dialog.cpp @@ -1076,9 +1076,9 @@ void pad_settings_dialog::UpdateLabels(bool is_reset) } } - ui->chb_vibration_large->setChecked(static_cast(cfg.enable_vibration_motor_large)); - ui->chb_vibration_small->setChecked(static_cast(cfg.enable_vibration_motor_small)); - ui->chb_vibration_switch->setChecked(static_cast(cfg.switch_vibration_motors)); + ui->chb_vibration_large->setChecked(cfg.enable_vibration_motor_large.get()); + ui->chb_vibration_small->setChecked(cfg.enable_vibration_motor_small.get()); + ui->chb_vibration_switch->setChecked(cfg.switch_vibration_motors.get()); // Update Trigger Thresholds ui->preview_trigger_left->setRange(0, m_handler->trigger_max); @@ -1160,6 +1160,9 @@ void pad_settings_dialog::UpdateLabels(bool is_reset) ui->sb_pressure_intensity->setRange(std::stoi(range.front()), std::stoi(range.back())); ui->sb_pressure_intensity->setValue(cfg.pressure_intensity); + // Update pressure sensitivity toggle mode + ui->cb_pressure_intensity_toggle_mode->setChecked(cfg.pressure_intensity_toggle_mode.get()); + // Apply stored/default LED settings to the device m_enable_led = m_handler->has_led(); SetPadData(0, 0); @@ -1778,6 +1781,7 @@ void pad_settings_dialog::ApplyCurrentPlayerConfig(int new_player_id) if (m_handler->has_pressure_intensity_button()) { cfg.pressure_intensity.set(ui->sb_pressure_intensity->value()); + cfg.pressure_intensity_toggle_mode.set(ui->cb_pressure_intensity_toggle_mode->isChecked()); } if (m_handler->m_type == pad_handler::keyboard) diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.ui b/rpcs3/rpcs3qt/pad_settings_dialog.ui index 2030e62531..6000014044 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.ui +++ b/rpcs3/rpcs3qt/pad_settings_dialog.ui @@ -674,7 +674,7 @@ Pressure Sensitivity Mode - + 5 @@ -707,6 +707,13 @@ + + + + Toggle + + + diff --git a/rpcs3/rpcs3qt/tooltips.h b/rpcs3/rpcs3qt/tooltips.h index 7f2e2576b6..13b99cd41c 100644 --- a/rpcs3/rpcs3qt/tooltips.h +++ b/rpcs3/rpcs3qt/tooltips.h @@ -265,7 +265,7 @@ public: const QString mmjoy = tr("The MMJoystick handler should work with almost any controller recognized by Windows. However, it is recommended that you use the more specific handlers if you have a controller that supports them."); const QString sdl = tr("The SDL handler supports a variety of controllers across different platforms."); - const QString pressure_intensity = tr("Controls the intensity of pressure sensitive buttons while this special button is pressed.
Use the percentage to change how hard you want to press a button."); + const QString pressure_intensity = tr("Controls the intensity of pressure sensitive buttons while this special button is pressed.
Enable \"Toggle\" if you want to toggle the intensity on button press instead.
Use the percentage to change how hard you want to press a button."); const QString squircle_factor = tr("The actual DualShock 3's stick range is not circular but formed like a rounded square (or squircle) which represents the maximum range of the emulated sticks. You can use the squircle values to modify the stick input if your sticks can't reach the corners of that range. A value of 0 does not apply any so called squircling. A value of 8000 is usually recommended."); const QString stick_multiplier = tr("The stick multipliers can be used to change the sensitivity of your stick movements.
The default setting is 1 and represents normal input."); const QString stick_deadzones = tr("A stick's deadzone determines how far the stick has to be moved until it is fully recognized by the game. The resulting range will be projected onto the full input range in order to give you a smooth experience. Movement inside the deadzone is actually simulated as a real DualShock 3's deadzone of ~13%, so don't worry if there is still movement shown in the emulated stick preview.");