mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-25 22:57:22 +00:00
configure_input: Modify controller connection delay
Increases the controller connection delay to 60ms and refactors it to attempt to disconnect all controllers prior to connecting all controllers in HID.
This commit is contained in:
parent
da07977db0
commit
904ac1daec
4 changed files with 47 additions and 12 deletions
|
@ -535,7 +535,7 @@ void QtControllerSelectorDialog::UpdateControllerState(std::size_t player_index)
|
||||||
// This emulates a delay between disconnecting and reconnecting controllers as some games
|
// This emulates a delay between disconnecting and reconnecting controllers as some games
|
||||||
// do not respond to a change in controller type if it was instantaneous.
|
// do not respond to a change in controller type if it was instantaneous.
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
std::this_thread::sleep_for(20ms);
|
std::this_thread::sleep_for(60ms);
|
||||||
|
|
||||||
UpdateController(controller_type, player_index, player_connected);
|
UpdateController(controller_type, player_index, player_connected);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include <QSignalBlocker>
|
#include <QSignalBlocker>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
@ -181,8 +182,18 @@ QList<QWidget*> ConfigureInput::GetSubTabs() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureInput::ApplyConfiguration() {
|
void ConfigureInput::ApplyConfiguration() {
|
||||||
for (auto controller : player_controllers) {
|
for (auto* controller : player_controllers) {
|
||||||
controller->ApplyConfiguration();
|
controller->ApplyConfiguration();
|
||||||
|
controller->TryDisconnectSelectedController();
|
||||||
|
}
|
||||||
|
|
||||||
|
// This emulates a delay between disconnecting and reconnecting controllers as some games
|
||||||
|
// do not respond to a change in controller type if it was instantaneous.
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
std::this_thread::sleep_for(60ms);
|
||||||
|
|
||||||
|
for (auto* controller : player_controllers) {
|
||||||
|
controller->TryConnectSelectedController();
|
||||||
}
|
}
|
||||||
|
|
||||||
advanced->ApplyConfiguration();
|
advanced->ApplyConfiguration();
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <thread>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
@ -576,6 +575,10 @@ void ConfigureInputPlayer::ApplyConfiguration() {
|
||||||
|
|
||||||
std::transform(motions_param.begin(), motions_param.end(), motions.begin(),
|
std::transform(motions_param.begin(), motions_param.end(), motions.begin(),
|
||||||
[](const Common::ParamPackage& param) { return param.Serialize(); });
|
[](const Common::ParamPackage& param) { return param.Serialize(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureInputPlayer::TryConnectSelectedController() {
|
||||||
|
auto& player = Settings::values.players.GetValue()[player_index];
|
||||||
|
|
||||||
const auto controller_type =
|
const auto controller_type =
|
||||||
GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
|
GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
|
||||||
|
@ -588,15 +591,12 @@ void ConfigureInputPlayer::ApplyConfiguration() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disconnect the controller first.
|
|
||||||
UpdateController(controller_type, player_index, false);
|
|
||||||
|
|
||||||
player.controller_type = controller_type;
|
player.controller_type = controller_type;
|
||||||
player.connected = player_connected;
|
player.connected = player_connected;
|
||||||
|
|
||||||
ConfigureVibration::SetVibrationDevices(player_index);
|
ConfigureVibration::SetVibrationDevices(player_index);
|
||||||
|
|
||||||
// Handheld
|
// Connect/Disconnect Handheld depending on Player 1's controller configuration.
|
||||||
if (player_index == 0) {
|
if (player_index == 0) {
|
||||||
auto& handheld = Settings::values.players.GetValue()[HANDHELD_INDEX];
|
auto& handheld = Settings::values.players.GetValue()[HANDHELD_INDEX];
|
||||||
if (controller_type == Settings::ControllerType::Handheld) {
|
if (controller_type == Settings::ControllerType::Handheld) {
|
||||||
|
@ -611,14 +611,26 @@ void ConfigureInputPlayer::ApplyConfiguration() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This emulates a delay between disconnecting and reconnecting controllers as some games
|
|
||||||
// do not respond to a change in controller type if it was instantaneous.
|
|
||||||
using namespace std::chrono_literals;
|
|
||||||
std::this_thread::sleep_for(20ms);
|
|
||||||
|
|
||||||
UpdateController(controller_type, player_index, player_connected);
|
UpdateController(controller_type, player_index, player_connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigureInputPlayer::TryDisconnectSelectedController() {
|
||||||
|
const auto& player = Settings::values.players.GetValue()[player_index];
|
||||||
|
|
||||||
|
const auto controller_type =
|
||||||
|
GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
|
||||||
|
const auto player_connected = ui->groupConnectedController->isChecked() &&
|
||||||
|
controller_type != Settings::ControllerType::Handheld;
|
||||||
|
|
||||||
|
// Do not do anything if the controller configuration has not changed.
|
||||||
|
if (player.controller_type == controller_type && player.connected == player_connected) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disconnect the controller first.
|
||||||
|
UpdateController(controller_type, player_index, false);
|
||||||
|
}
|
||||||
|
|
||||||
void ConfigureInputPlayer::showEvent(QShowEvent* event) {
|
void ConfigureInputPlayer::showEvent(QShowEvent* event) {
|
||||||
if (bottom_row == nullptr) {
|
if (bottom_row == nullptr) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -54,6 +54,18 @@ public:
|
||||||
/// Save all button configurations to settings file.
|
/// Save all button configurations to settings file.
|
||||||
void ApplyConfiguration();
|
void ApplyConfiguration();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to connect the currently selected controller in the HID backend.
|
||||||
|
* This function will not do anything if it is not connected in the frontend.
|
||||||
|
*/
|
||||||
|
void TryConnectSelectedController();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to disconnect the currently selected controller in the HID backend.
|
||||||
|
* This function will not do anything if the configuration has not changed.
|
||||||
|
*/
|
||||||
|
void TryDisconnectSelectedController();
|
||||||
|
|
||||||
/// Set the connection state checkbox (used to sync state).
|
/// Set the connection state checkbox (used to sync state).
|
||||||
void ConnectPlayer(bool connected);
|
void ConnectPlayer(bool connected);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue