summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/applets/controller.cpp2
-rw-r--r--src/yuzu/configuration/configure_input.cpp13
-rw-r--r--src/yuzu/configuration/configure_input_player.cpp32
-rw-r--r--src/yuzu/configuration/configure_input_player.h12
4 files changed, 47 insertions, 12 deletions
diff --git a/src/yuzu/applets/controller.cpp b/src/yuzu/applets/controller.cpp
index a15e8ca2a..c680fd2c2 100644
--- a/src/yuzu/applets/controller.cpp
+++ b/src/yuzu/applets/controller.cpp
@@ -535,7 +535,7 @@ void QtControllerSelectorDialog::UpdateControllerState(std::size_t player_index)
535 // This emulates a delay between disconnecting and reconnecting controllers as some games 535 // This emulates a delay between disconnecting and reconnecting controllers as some games
536 // do not respond to a change in controller type if it was instantaneous. 536 // do not respond to a change in controller type if it was instantaneous.
537 using namespace std::chrono_literals; 537 using namespace std::chrono_literals;
538 std::this_thread::sleep_for(20ms); 538 std::this_thread::sleep_for(60ms);
539 539
540 UpdateController(controller_type, player_index, player_connected); 540 UpdateController(controller_type, player_index, player_connected);
541} 541}
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp
index d9009091b..567a36d9b 100644
--- a/src/yuzu/configuration/configure_input.cpp
+++ b/src/yuzu/configuration/configure_input.cpp
@@ -4,6 +4,7 @@
4 4
5#include <algorithm> 5#include <algorithm>
6#include <memory> 6#include <memory>
7#include <thread>
7 8
8#include <QSignalBlocker> 9#include <QSignalBlocker>
9#include <QTimer> 10#include <QTimer>
@@ -181,8 +182,18 @@ QList<QWidget*> ConfigureInput::GetSubTabs() const {
181} 182}
182 183
183void ConfigureInput::ApplyConfiguration() { 184void ConfigureInput::ApplyConfiguration() {
184 for (auto controller : player_controllers) { 185 for (auto* controller : player_controllers) {
185 controller->ApplyConfiguration(); 186 controller->ApplyConfiguration();
187 controller->TryDisconnectSelectedController();
188 }
189
190 // This emulates a delay between disconnecting and reconnecting controllers as some games
191 // do not respond to a change in controller type if it was instantaneous.
192 using namespace std::chrono_literals;
193 std::this_thread::sleep_for(60ms);
194
195 for (auto* controller : player_controllers) {
196 controller->TryConnectSelectedController();
186 } 197 }
187 198
188 advanced->ApplyConfiguration(); 199 advanced->ApplyConfiguration();
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index 3c7500ee3..46ea026e4 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -4,7 +4,6 @@
4 4
5#include <algorithm> 5#include <algorithm>
6#include <memory> 6#include <memory>
7#include <thread>
8#include <utility> 7#include <utility>
9#include <QGridLayout> 8#include <QGridLayout>
10#include <QInputDialog> 9#include <QInputDialog>
@@ -576,6 +575,10 @@ void ConfigureInputPlayer::ApplyConfiguration() {
576 575
577 std::transform(motions_param.begin(), motions_param.end(), motions.begin(), 576 std::transform(motions_param.begin(), motions_param.end(), motions.begin(),
578 [](const Common::ParamPackage& param) { return param.Serialize(); }); 577 [](const Common::ParamPackage& param) { return param.Serialize(); });
578}
579
580void ConfigureInputPlayer::TryConnectSelectedController() {
581 auto& player = Settings::values.players.GetValue()[player_index];
579 582
580 const auto controller_type = 583 const auto controller_type =
581 GetControllerTypeFromIndex(ui->comboControllerType->currentIndex()); 584 GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
@@ -588,15 +591,12 @@ void ConfigureInputPlayer::ApplyConfiguration() {
588 return; 591 return;
589 } 592 }
590 593
591 // Disconnect the controller first.
592 UpdateController(controller_type, player_index, false);
593
594 player.controller_type = controller_type; 594 player.controller_type = controller_type;
595 player.connected = player_connected; 595 player.connected = player_connected;
596 596
597 ConfigureVibration::SetVibrationDevices(player_index); 597 ConfigureVibration::SetVibrationDevices(player_index);
598 598
599 // Handheld 599 // Connect/Disconnect Handheld depending on Player 1's controller configuration.
600 if (player_index == 0) { 600 if (player_index == 0) {
601 auto& handheld = Settings::values.players.GetValue()[HANDHELD_INDEX]; 601 auto& handheld = Settings::values.players.GetValue()[HANDHELD_INDEX];
602 if (controller_type == Settings::ControllerType::Handheld) { 602 if (controller_type == Settings::ControllerType::Handheld) {
@@ -611,14 +611,26 @@ void ConfigureInputPlayer::ApplyConfiguration() {
611 return; 611 return;
612 } 612 }
613 613
614 // This emulates a delay between disconnecting and reconnecting controllers as some games
615 // do not respond to a change in controller type if it was instantaneous.
616 using namespace std::chrono_literals;
617 std::this_thread::sleep_for(20ms);
618
619 UpdateController(controller_type, player_index, player_connected); 614 UpdateController(controller_type, player_index, player_connected);
620} 615}
621 616
617void ConfigureInputPlayer::TryDisconnectSelectedController() {
618 const auto& player = Settings::values.players.GetValue()[player_index];
619
620 const auto controller_type =
621 GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
622 const auto player_connected = ui->groupConnectedController->isChecked() &&
623 controller_type != Settings::ControllerType::Handheld;
624
625 // Do not do anything if the controller configuration has not changed.
626 if (player.controller_type == controller_type && player.connected == player_connected) {
627 return;
628 }
629
630 // Disconnect the controller first.
631 UpdateController(controller_type, player_index, false);
632}
633
622void ConfigureInputPlayer::showEvent(QShowEvent* event) { 634void ConfigureInputPlayer::showEvent(QShowEvent* event) {
623 if (bottom_row == nullptr) { 635 if (bottom_row == nullptr) {
624 return; 636 return;
diff --git a/src/yuzu/configuration/configure_input_player.h b/src/yuzu/configuration/configure_input_player.h
index 9c30879a2..c4ae50de7 100644
--- a/src/yuzu/configuration/configure_input_player.h
+++ b/src/yuzu/configuration/configure_input_player.h
@@ -54,6 +54,18 @@ public:
54 /// Save all button configurations to settings file. 54 /// Save all button configurations to settings file.
55 void ApplyConfiguration(); 55 void ApplyConfiguration();
56 56
57 /**
58 * Attempts to connect the currently selected controller in the HID backend.
59 * This function will not do anything if it is not connected in the frontend.
60 */
61 void TryConnectSelectedController();
62
63 /**
64 * Attempts to disconnect the currently selected controller in the HID backend.
65 * This function will not do anything if the configuration has not changed.
66 */
67 void TryDisconnectSelectedController();
68
57 /// Set the connection state checkbox (used to sync state). 69 /// Set the connection state checkbox (used to sync state).
58 void ConnectPlayer(bool connected); 70 void ConnectPlayer(bool connected);
59 71