summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2021-12-30 16:54:35 -0800
committerGravatar GitHub2021-12-30 16:54:35 -0800
commit667a8ae163681f68d90010bc7dd05eb7398524d6 (patch)
treedea803db312fc0e36c5ed2c9000cacf3bd4df7c3
parentMerge pull request #7635 from bunnei/set-heap-size (diff)
parentcore/hid: Fix controller type validation (diff)
downloadyuzu-667a8ae163681f68d90010bc7dd05eb7398524d6.tar.gz
yuzu-667a8ae163681f68d90010bc7dd05eb7398524d6.tar.xz
yuzu-667a8ae163681f68d90010bc7dd05eb7398524d6.zip
Merge pull request #7647 from german77/toad
core/hid: Fix controller type validation
Diffstat (limited to '')
-rw-r--r--src/core/frontend/applets/controller.cpp10
-rw-r--r--src/core/hid/emulated_controller.cpp12
-rw-r--r--src/core/hid/emulated_controller.h10
-rw-r--r--src/yuzu/applets/qt_controller.cpp2
-rw-r--r--src/yuzu/configuration/configure_input_player.cpp6
5 files changed, 23 insertions, 17 deletions
diff --git a/src/core/frontend/applets/controller.cpp b/src/core/frontend/applets/controller.cpp
index 6dbd38ffa..e1033b634 100644
--- a/src/core/frontend/applets/controller.cpp
+++ b/src/core/frontend/applets/controller.cpp
@@ -45,26 +45,26 @@ void DefaultControllerApplet::ReconfigureControllers(std::function<void()> callb
45 // Pro Controller -> Dual Joycons -> Left Joycon/Right Joycon -> Handheld 45 // Pro Controller -> Dual Joycons -> Left Joycon/Right Joycon -> Handheld
46 if (parameters.allow_pro_controller) { 46 if (parameters.allow_pro_controller) {
47 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::ProController); 47 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::ProController);
48 controller->Connect(); 48 controller->Connect(true);
49 } else if (parameters.allow_dual_joycons) { 49 } else if (parameters.allow_dual_joycons) {
50 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::JoyconDual); 50 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::JoyconDual);
51 controller->Connect(); 51 controller->Connect(true);
52 } else if (parameters.allow_left_joycon && parameters.allow_right_joycon) { 52 } else if (parameters.allow_left_joycon && parameters.allow_right_joycon) {
53 // Assign left joycons to even player indices and right joycons to odd player indices. 53 // Assign left joycons to even player indices and right joycons to odd player indices.
54 // We do this since Captain Toad Treasure Tracker expects a left joycon for Player 1 and 54 // We do this since Captain Toad Treasure Tracker expects a left joycon for Player 1 and
55 // a right Joycon for Player 2 in 2 Player Assist mode. 55 // a right Joycon for Player 2 in 2 Player Assist mode.
56 if (index % 2 == 0) { 56 if (index % 2 == 0) {
57 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::JoyconLeft); 57 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::JoyconLeft);
58 controller->Connect(); 58 controller->Connect(true);
59 } else { 59 } else {
60 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::JoyconRight); 60 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::JoyconRight);
61 controller->Connect(); 61 controller->Connect(true);
62 } 62 }
63 } else if (index == 0 && parameters.enable_single_mode && parameters.allow_handheld && 63 } else if (index == 0 && parameters.enable_single_mode && parameters.allow_handheld &&
64 !Settings::values.use_docked_mode.GetValue()) { 64 !Settings::values.use_docked_mode.GetValue()) {
65 // We should *never* reach here under any normal circumstances. 65 // We should *never* reach here under any normal circumstances.
66 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::Handheld); 66 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::Handheld);
67 controller->Connect(); 67 controller->Connect(true);
68 } else { 68 } else {
69 UNREACHABLE_MSG("Unable to add a new controller based on the given parameters!"); 69 UNREACHABLE_MSG("Unable to add a new controller based on the given parameters!");
70 } 70 }
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index ff9d7a7e3..2d3fce276 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -886,8 +886,9 @@ void EmulatedController::SetSupportedNpadStyleTag(NpadStyleTag supported_styles)
886 } 886 }
887} 887}
888 888
889bool EmulatedController::IsControllerSupported() const { 889bool EmulatedController::IsControllerSupported(bool use_temporary_value) const {
890 switch (npad_type) { 890 const auto type = is_configuring && use_temporary_value ? tmp_npad_type : npad_type;
891 switch (type) {
891 case NpadStyleIndex::ProController: 892 case NpadStyleIndex::ProController:
892 return supported_style_tag.fullkey; 893 return supported_style_tag.fullkey;
893 case NpadStyleIndex::Handheld: 894 case NpadStyleIndex::Handheld:
@@ -915,9 +916,10 @@ bool EmulatedController::IsControllerSupported() const {
915 } 916 }
916} 917}
917 918
918void EmulatedController::Connect() { 919void EmulatedController::Connect(bool use_temporary_value) {
919 if (!IsControllerSupported()) { 920 if (!IsControllerSupported(use_temporary_value)) {
920 LOG_ERROR(Service_HID, "Controller type {} is not supported", npad_type); 921 const auto type = is_configuring && use_temporary_value ? tmp_npad_type : npad_type;
922 LOG_ERROR(Service_HID, "Controller type {} is not supported", type);
921 return; 923 return;
922 } 924 }
923 { 925 {
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index e42aafebc..d887eca87 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -167,8 +167,11 @@ public:
167 */ 167 */
168 void SetSupportedNpadStyleTag(NpadStyleTag supported_styles); 168 void SetSupportedNpadStyleTag(NpadStyleTag supported_styles);
169 169
170 /// Sets the connected status to true 170 /**
171 void Connect(); 171 * Sets the connected status to true
172 * @param use_temporary_value If true tmp_npad_type will be used
173 */
174 void Connect(bool use_temporary_value = false);
172 175
173 /// Sets the connected status to false 176 /// Sets the connected status to false
174 void Disconnect(); 177 void Disconnect();
@@ -319,9 +322,10 @@ private:
319 322
320 /** 323 /**
321 * Checks the current controller type against the supported_style_tag 324 * Checks the current controller type against the supported_style_tag
325 * @param use_temporary_value If true tmp_npad_type will be used
322 * @return true if the controller is supported 326 * @return true if the controller is supported
323 */ 327 */
324 bool IsControllerSupported() const; 328 bool IsControllerSupported(bool use_temporary_value = false) const;
325 329
326 /** 330 /**
327 * Updates the button status of the controller 331 * Updates the button status of the controller
diff --git a/src/yuzu/applets/qt_controller.cpp b/src/yuzu/applets/qt_controller.cpp
index c6222b571..d63193131 100644
--- a/src/yuzu/applets/qt_controller.cpp
+++ b/src/yuzu/applets/qt_controller.cpp
@@ -33,7 +33,7 @@ void UpdateController(Core::HID::EmulatedController* controller,
33 } 33 }
34 controller->SetNpadStyleIndex(controller_type); 34 controller->SetNpadStyleIndex(controller_type);
35 if (connected) { 35 if (connected) {
36 controller->Connect(); 36 controller->Connect(true);
37 } 37 }
38} 38}
39 39
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index 8a8be8e40..cb6163702 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -599,11 +599,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
599 if (is_connected) { 599 if (is_connected) {
600 if (type == Core::HID::NpadStyleIndex::Handheld) { 600 if (type == Core::HID::NpadStyleIndex::Handheld) {
601 emulated_controller_p1->Disconnect(); 601 emulated_controller_p1->Disconnect();
602 emulated_controller_handheld->Connect(); 602 emulated_controller_handheld->Connect(true);
603 emulated_controller = emulated_controller_handheld; 603 emulated_controller = emulated_controller_handheld;
604 } else { 604 } else {
605 emulated_controller_handheld->Disconnect(); 605 emulated_controller_handheld->Disconnect();
606 emulated_controller_p1->Connect(); 606 emulated_controller_p1->Connect(true);
607 emulated_controller = emulated_controller_p1; 607 emulated_controller = emulated_controller_p1;
608 } 608 }
609 } 609 }
@@ -718,7 +718,7 @@ void ConfigureInputPlayer::LoadConfiguration() {
718void ConfigureInputPlayer::ConnectPlayer(bool connected) { 718void ConfigureInputPlayer::ConnectPlayer(bool connected) {
719 ui->groupConnectedController->setChecked(connected); 719 ui->groupConnectedController->setChecked(connected);
720 if (connected) { 720 if (connected) {
721 emulated_controller->Connect(); 721 emulated_controller->Connect(true);
722 } else { 722 } else {
723 emulated_controller->Disconnect(); 723 emulated_controller->Disconnect();
724 } 724 }