summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/frontend/applets/controller.cpp35
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp88
-rw-r--r--src/core/hle/service/hid/controllers/npad.h1
3 files changed, 34 insertions, 90 deletions
diff --git a/src/core/frontend/applets/controller.cpp b/src/core/frontend/applets/controller.cpp
index 0fbc7932c..34eacbb45 100644
--- a/src/core/frontend/applets/controller.cpp
+++ b/src/core/frontend/applets/controller.cpp
@@ -27,11 +27,44 @@ void DefaultControllerApplet::ReconfigureControllers(std::function<void()> callb
27 27
28 auto& players = Settings::values.players; 28 auto& players = Settings::values.players;
29 29
30 const auto min_supported_players = parameters.enable_single_mode ? 1 : parameters.min_players;
31
32 // Disconnect Handheld first.
33 npad.DisconnectNPadAtIndex(8);
34
30 // Deduce the best configuration based on the input parameters. 35 // Deduce the best configuration based on the input parameters.
31 for (std::size_t index = 0; index < players.size(); ++index) { 36 for (std::size_t index = 0; index < players.size() - 2; ++index) {
32 // First, disconnect all controllers regardless of the value of keep_controllers_connected. 37 // First, disconnect all controllers regardless of the value of keep_controllers_connected.
33 // This makes it easy to connect the desired controllers. 38 // This makes it easy to connect the desired controllers.
34 npad.DisconnectNPadAtIndex(index); 39 npad.DisconnectNPadAtIndex(index);
40
41 // Only connect the minimum number of required players.
42 if (index >= min_supported_players) {
43 continue;
44 }
45
46 // Connect controllers based on the following priority list from highest to lowest priority:
47 // Pro Controller -> Dual Joycons -> Left Joycon -> Right Joycon -> Handheld
48 if (parameters.allow_pro_controller) {
49 npad.AddNewControllerAt(
50 npad.MapSettingsTypeToNPad(Settings::ControllerType::ProController), index);
51 } else if (parameters.allow_dual_joycons) {
52 npad.AddNewControllerAt(
53 npad.MapSettingsTypeToNPad(Settings::ControllerType::DualJoyconDetached), index);
54 } else if (parameters.allow_left_joycon) {
55 npad.AddNewControllerAt(
56 npad.MapSettingsTypeToNPad(Settings::ControllerType::LeftJoycon), index);
57 } else if (parameters.allow_right_joycon) {
58 npad.AddNewControllerAt(
59 npad.MapSettingsTypeToNPad(Settings::ControllerType::RightJoycon), index);
60 } else if (index == 0 && parameters.enable_single_mode && parameters.allow_handheld &&
61 !Settings::values.use_docked_mode) {
62 // We should *never* reach here under any normal circumstances.
63 npad.AddNewControllerAt(npad.MapSettingsTypeToNPad(Settings::ControllerType::Handheld),
64 index);
65 } else {
66 UNREACHABLE_MSG("Unable to add a new controller based on the given parameters!");
67 }
35 } 68 }
36 69
37 callback(); 70 callback();
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index efb953d93..a92018914 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -720,92 +720,4 @@ bool Controller_NPad::IsControllerSupported(NPadControllerType controller) const
720 return false; 720 return false;
721} 721}
722 722
723Controller_NPad::NPadControllerType Controller_NPad::DecideBestController(
724 NPadControllerType priority) const {
725 if (IsControllerSupported(priority)) {
726 return priority;
727 }
728 const auto is_docked = Settings::values.use_docked_mode;
729 if (is_docked && priority == NPadControllerType::Handheld) {
730 priority = NPadControllerType::JoyDual;
731 if (IsControllerSupported(priority)) {
732 return priority;
733 }
734 }
735 std::vector<NPadControllerType> priority_list;
736 switch (priority) {
737 case NPadControllerType::ProController:
738 priority_list.push_back(NPadControllerType::JoyDual);
739 if (!is_docked) {
740 priority_list.push_back(NPadControllerType::Handheld);
741 }
742 priority_list.push_back(NPadControllerType::JoyLeft);
743 priority_list.push_back(NPadControllerType::JoyRight);
744 priority_list.push_back(NPadControllerType::Pokeball);
745 break;
746 case NPadControllerType::Handheld:
747 priority_list.push_back(NPadControllerType::JoyDual);
748 priority_list.push_back(NPadControllerType::ProController);
749 priority_list.push_back(NPadControllerType::JoyLeft);
750 priority_list.push_back(NPadControllerType::JoyRight);
751 priority_list.push_back(NPadControllerType::Pokeball);
752 break;
753 case NPadControllerType::JoyDual:
754 if (!is_docked) {
755 priority_list.push_back(NPadControllerType::Handheld);
756 }
757 priority_list.push_back(NPadControllerType::ProController);
758 priority_list.push_back(NPadControllerType::JoyLeft);
759 priority_list.push_back(NPadControllerType::JoyRight);
760 priority_list.push_back(NPadControllerType::Pokeball);
761 break;
762 case NPadControllerType::JoyLeft:
763 priority_list.push_back(NPadControllerType::JoyRight);
764 priority_list.push_back(NPadControllerType::JoyDual);
765 if (!is_docked) {
766 priority_list.push_back(NPadControllerType::Handheld);
767 }
768 priority_list.push_back(NPadControllerType::ProController);
769 priority_list.push_back(NPadControllerType::Pokeball);
770 break;
771 case NPadControllerType::JoyRight:
772 priority_list.push_back(NPadControllerType::JoyLeft);
773 priority_list.push_back(NPadControllerType::JoyDual);
774 if (!is_docked) {
775 priority_list.push_back(NPadControllerType::Handheld);
776 }
777 priority_list.push_back(NPadControllerType::ProController);
778 priority_list.push_back(NPadControllerType::Pokeball);
779 break;
780 case NPadControllerType::Pokeball:
781 priority_list.push_back(NPadControllerType::JoyLeft);
782 priority_list.push_back(NPadControllerType::JoyRight);
783 priority_list.push_back(NPadControllerType::JoyDual);
784 if (!is_docked) {
785 priority_list.push_back(NPadControllerType::Handheld);
786 }
787 priority_list.push_back(NPadControllerType::ProController);
788 break;
789 default:
790 priority_list.push_back(NPadControllerType::JoyDual);
791 if (!is_docked) {
792 priority_list.push_back(NPadControllerType::Handheld);
793 }
794 priority_list.push_back(NPadControllerType::ProController);
795 priority_list.push_back(NPadControllerType::JoyLeft);
796 priority_list.push_back(NPadControllerType::JoyRight);
797 priority_list.push_back(NPadControllerType::JoyDual);
798 break;
799 }
800
801 const auto iter = std::find_if(priority_list.begin(), priority_list.end(),
802 [this](auto type) { return IsControllerSupported(type); });
803 if (iter == priority_list.end()) {
804 UNIMPLEMENTED_MSG("Could not find supported controller!");
805 return priority;
806 }
807
808 return *iter;
809}
810
811} // namespace Service::HID 723} // namespace Service::HID
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h
index 40c763376..0f2d33857 100644
--- a/src/core/hle/service/hid/controllers/npad.h
+++ b/src/core/hle/service/hid/controllers/npad.h
@@ -318,7 +318,6 @@ private:
318 318
319 void InitNewlyAddedController(std::size_t controller_idx); 319 void InitNewlyAddedController(std::size_t controller_idx);
320 bool IsControllerSupported(NPadControllerType controller) const; 320 bool IsControllerSupported(NPadControllerType controller) const;
321 NPadControllerType DecideBestController(NPadControllerType priority) const;
322 void RequestPadStateUpdate(u32 npad_id); 321 void RequestPadStateUpdate(u32 npad_id);
323 322
324 u32 press_state{}; 323 u32 press_state{};