summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hid/emulated_controller.cpp43
-rw-r--r--src/core/hid/emulated_controller.h14
-rw-r--r--src/core/hid/hid_core.cpp10
-rw-r--r--src/core/hid/hid_core.h2
-rw-r--r--src/core/hid/hid_types.h2
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp30
-rw-r--r--src/yuzu/configuration/configure_input_player.cpp131
-rw-r--r--src/yuzu/main.cpp3
8 files changed, 147 insertions, 88 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 466ff5542..720706794 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -866,7 +866,50 @@ void EmulatedController::SetLedPattern() {
866 } 866 }
867} 867}
868 868
869void EmulatedController::SetSupportedNpadStyleTag(NpadStyleTag supported_styles) {
870 supported_style_tag = supported_styles;
871 if (!is_connected) {
872 return;
873 }
874 if (!IsControllerSupported()) {
875 LOG_ERROR(Service_HID, "Controller type {} is not supported. Disconnecting controller",
876 npad_type);
877 Disconnect();
878 }
879}
880
881bool EmulatedController::IsControllerSupported() const {
882 switch (npad_type) {
883 case NpadStyleIndex::ProController:
884 return supported_style_tag.fullkey;
885 case NpadStyleIndex::JoyconDual:
886 return supported_style_tag.joycon_dual;
887 case NpadStyleIndex::JoyconLeft:
888 return supported_style_tag.joycon_left;
889 case NpadStyleIndex::JoyconRight:
890 return supported_style_tag.joycon_right;
891 case NpadStyleIndex::GameCube:
892 return supported_style_tag.gamecube;
893 case NpadStyleIndex::Pokeball:
894 return supported_style_tag.palma;
895 case NpadStyleIndex::NES:
896 return supported_style_tag.lark;
897 case NpadStyleIndex::SNES:
898 return supported_style_tag.lucia;
899 case NpadStyleIndex::N64:
900 return supported_style_tag.lagoon;
901 case NpadStyleIndex::SegaGenesis:
902 return supported_style_tag.lager;
903 default:
904 return false;
905 }
906}
907
869void EmulatedController::Connect() { 908void EmulatedController::Connect() {
909 if (!IsControllerSupported()) {
910 LOG_ERROR(Service_HID, "Controller type {} is not supported", npad_type);
911 return;
912 }
870 { 913 {
871 std::lock_guard lock{mutex}; 914 std::lock_guard lock{mutex};
872 if (is_configuring) { 915 if (is_configuring) {
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index 5887e3e38..425b3e7c4 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -160,6 +160,13 @@ public:
160 */ 160 */
161 NpadStyleIndex GetNpadStyleIndex(bool get_temporary_value = false) const; 161 NpadStyleIndex GetNpadStyleIndex(bool get_temporary_value = false) const;
162 162
163 /**
164 * Sets the supported controller types. Disconnects the controller if current type is not
165 * supported
166 * @param supported_styles bitflag with supported types
167 */
168 void SetSupportedNpadStyleTag(NpadStyleTag supported_styles);
169
163 /// Sets the connected status to true 170 /// Sets the connected status to true
164 void Connect(); 171 void Connect();
165 172
@@ -311,6 +318,12 @@ private:
311 void LoadTASParams(); 318 void LoadTASParams();
312 319
313 /** 320 /**
321 * Checks the current controller type against the supported_style_tag
322 * @return true if the controller is supported
323 */
324 bool IsControllerSupported() const;
325
326 /**
314 * Updates the button status of the controller 327 * Updates the button status of the controller
315 * @param callback A CallbackStatus containing the button status 328 * @param callback A CallbackStatus containing the button status
316 * @param index Button ID of the to be updated 329 * @param index Button ID of the to be updated
@@ -354,6 +367,7 @@ private:
354 367
355 NpadIdType npad_id_type; 368 NpadIdType npad_id_type;
356 NpadStyleIndex npad_type{NpadStyleIndex::None}; 369 NpadStyleIndex npad_type{NpadStyleIndex::None};
370 NpadStyleTag supported_style_tag{NpadStyleSet::All};
357 bool is_connected{false}; 371 bool is_connected{false};
358 bool is_configuring{false}; 372 bool is_configuring{false};
359 f32 motion_sensitivity{0.01f}; 373 f32 motion_sensitivity{0.01f};
diff --git a/src/core/hid/hid_core.cpp b/src/core/hid/hid_core.cpp
index 946adde00..0c3eb5a62 100644
--- a/src/core/hid/hid_core.cpp
+++ b/src/core/hid/hid_core.cpp
@@ -108,6 +108,16 @@ const EmulatedController* HIDCore::GetEmulatedControllerByIndex(std::size_t inde
108 108
109void HIDCore::SetSupportedStyleTag(NpadStyleTag style_tag) { 109void HIDCore::SetSupportedStyleTag(NpadStyleTag style_tag) {
110 supported_style_tag.raw = style_tag.raw; 110 supported_style_tag.raw = style_tag.raw;
111 player_1->SetSupportedNpadStyleTag(supported_style_tag);
112 player_2->SetSupportedNpadStyleTag(supported_style_tag);
113 player_3->SetSupportedNpadStyleTag(supported_style_tag);
114 player_4->SetSupportedNpadStyleTag(supported_style_tag);
115 player_5->SetSupportedNpadStyleTag(supported_style_tag);
116 player_6->SetSupportedNpadStyleTag(supported_style_tag);
117 player_7->SetSupportedNpadStyleTag(supported_style_tag);
118 player_8->SetSupportedNpadStyleTag(supported_style_tag);
119 other->SetSupportedNpadStyleTag(supported_style_tag);
120 handheld->SetSupportedNpadStyleTag(supported_style_tag);
111} 121}
112 122
113NpadStyleTag HIDCore::GetSupportedStyleTag() const { 123NpadStyleTag HIDCore::GetSupportedStyleTag() const {
diff --git a/src/core/hid/hid_core.h b/src/core/hid/hid_core.h
index 140a0e962..2fb0f7e19 100644
--- a/src/core/hid/hid_core.h
+++ b/src/core/hid/hid_core.h
@@ -73,7 +73,7 @@ private:
73 std::unique_ptr<EmulatedController> handheld; 73 std::unique_ptr<EmulatedController> handheld;
74 std::unique_ptr<EmulatedConsole> console; 74 std::unique_ptr<EmulatedConsole> console;
75 std::unique_ptr<EmulatedDevices> devices; 75 std::unique_ptr<EmulatedDevices> devices;
76 NpadStyleTag supported_style_tag; 76 NpadStyleTag supported_style_tag{NpadStyleSet::All};
77}; 77};
78 78
79} // namespace Core::HID 79} // namespace Core::HID
diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h
index 780659b86..7c12f01fc 100644
--- a/src/core/hid/hid_types.h
+++ b/src/core/hid/hid_types.h
@@ -256,6 +256,8 @@ enum class NpadStyleSet : u32 {
256 Lager = 1U << 11, 256 Lager = 1U << 11,
257 SystemExt = 1U << 29, 257 SystemExt = 1U << 29,
258 System = 1U << 30, 258 System = 1U << 30,
259
260 All = 0xFFFFFFFFU,
259}; 261};
260static_assert(sizeof(NpadStyleSet) == 4, "NpadStyleSet is an invalid size"); 262static_assert(sizeof(NpadStyleSet) == 4, "NpadStyleSet is an invalid size");
261 263
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index 6916930f7..ae56f10cf 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -126,8 +126,11 @@ void Controller_NPad::ControllerUpdate(Core::HID::ControllerTriggerType type,
126} 126}
127 127
128void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { 128void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
129 LOG_DEBUG(Service_HID, "Npad connected {}", npad_id);
130 auto& controller = GetControllerFromNpadIdType(npad_id); 129 auto& controller = GetControllerFromNpadIdType(npad_id);
130 if (!IsControllerSupported(controller.device->GetNpadStyleIndex())) {
131 return;
132 }
133 LOG_DEBUG(Service_HID, "Npad connected {}", npad_id);
131 const auto controller_type = controller.device->GetNpadStyleIndex(); 134 const auto controller_type = controller.device->GetNpadStyleIndex();
132 auto& shared_memory = controller.shared_memory_entry; 135 auto& shared_memory = controller.shared_memory_entry;
133 if (controller_type == Core::HID::NpadStyleIndex::None) { 136 if (controller_type == Core::HID::NpadStyleIndex::None) {
@@ -255,19 +258,7 @@ void Controller_NPad::OnInit() {
255 258
256 if (hid_core.GetSupportedStyleTag().raw == Core::HID::NpadStyleSet::None) { 259 if (hid_core.GetSupportedStyleTag().raw == Core::HID::NpadStyleSet::None) {
257 // We want to support all controllers 260 // We want to support all controllers
258 Core::HID::NpadStyleTag style{}; 261 hid_core.SetSupportedStyleTag({Core::HID::NpadStyleSet::All});
259 style.handheld.Assign(1);
260 style.joycon_left.Assign(1);
261 style.joycon_right.Assign(1);
262 style.joycon_dual.Assign(1);
263 style.fullkey.Assign(1);
264 style.gamecube.Assign(1);
265 style.palma.Assign(1);
266 style.lark.Assign(1);
267 style.lucia.Assign(1);
268 style.lagoon.Assign(1);
269 style.lager.Assign(1);
270 hid_core.SetSupportedStyleTag(style);
271 } 262 }
272 263
273 supported_npad_id_types.resize(npad_id_list.size()); 264 supported_npad_id_types.resize(npad_id_list.size());
@@ -1072,13 +1063,18 @@ bool Controller_NPad::SwapNpadAssignment(Core::HID::NpadIdType npad_id_1,
1072 const auto& controller_2 = GetControllerFromNpadIdType(npad_id_2).device; 1063 const auto& controller_2 = GetControllerFromNpadIdType(npad_id_2).device;
1073 const auto type_index_1 = controller_1->GetNpadStyleIndex(); 1064 const auto type_index_1 = controller_1->GetNpadStyleIndex();
1074 const auto type_index_2 = controller_2->GetNpadStyleIndex(); 1065 const auto type_index_2 = controller_2->GetNpadStyleIndex();
1066 const auto is_connected_1 = controller_1->IsConnected();
1067 const auto is_connected_2 = controller_2->IsConnected();
1075 1068
1076 if (!IsControllerSupported(type_index_1) || !IsControllerSupported(type_index_2)) { 1069 if (!IsControllerSupported(type_index_1) && is_connected_1) {
1070 return false;
1071 }
1072 if (!IsControllerSupported(type_index_2) && is_connected_2) {
1077 return false; 1073 return false;
1078 } 1074 }
1079 1075
1080 AddNewControllerAt(type_index_2, npad_id_1); 1076 UpdateControllerAt(type_index_2, npad_id_1, is_connected_2);
1081 AddNewControllerAt(type_index_1, npad_id_2); 1077 UpdateControllerAt(type_index_1, npad_id_2, is_connected_1);
1082 1078
1083 return true; 1079 return true;
1084} 1080}
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index 34099bc83..8a8be8e40 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -907,88 +907,79 @@ void ConfigureInputPlayer::UpdateUI() {
907} 907}
908 908
909void ConfigureInputPlayer::SetConnectableControllers() { 909void ConfigureInputPlayer::SetConnectableControllers() {
910 const auto add_controllers = [this](bool enable_all, 910 Core::HID::NpadStyleTag npad_style_set = hid_core.GetSupportedStyleTag();
911 Core::HID::NpadStyleTag npad_style_set = {}) { 911 index_controller_type_pairs.clear();
912 index_controller_type_pairs.clear(); 912 ui->comboControllerType->clear();
913 ui->comboControllerType->clear();
914
915 if (enable_all || npad_style_set.fullkey == 1) {
916 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
917 Core::HID::NpadStyleIndex::ProController);
918 ui->comboControllerType->addItem(tr("Pro Controller"));
919 }
920
921 if (enable_all || npad_style_set.joycon_dual == 1) {
922 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
923 Core::HID::NpadStyleIndex::JoyconDual);
924 ui->comboControllerType->addItem(tr("Dual Joycons"));
925 }
926 913
927 if (enable_all || npad_style_set.joycon_left == 1) { 914 if (npad_style_set.fullkey == 1) {
928 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), 915 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
929 Core::HID::NpadStyleIndex::JoyconLeft); 916 Core::HID::NpadStyleIndex::ProController);
930 ui->comboControllerType->addItem(tr("Left Joycon")); 917 ui->comboControllerType->addItem(tr("Pro Controller"));
931 } 918 }
932 919
933 if (enable_all || npad_style_set.joycon_right == 1) { 920 if (npad_style_set.joycon_dual == 1) {
934 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), 921 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
935 Core::HID::NpadStyleIndex::JoyconRight); 922 Core::HID::NpadStyleIndex::JoyconDual);
936 ui->comboControllerType->addItem(tr("Right Joycon")); 923 ui->comboControllerType->addItem(tr("Dual Joycons"));
937 } 924 }
938 925
939 if (player_index == 0 && (enable_all || npad_style_set.handheld == 1)) { 926 if (npad_style_set.joycon_left == 1) {
940 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), 927 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
941 Core::HID::NpadStyleIndex::Handheld); 928 Core::HID::NpadStyleIndex::JoyconLeft);
942 ui->comboControllerType->addItem(tr("Handheld")); 929 ui->comboControllerType->addItem(tr("Left Joycon"));
943 } 930 }
944 931
945 if (enable_all || npad_style_set.gamecube == 1) { 932 if (npad_style_set.joycon_right == 1) {
946 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), 933 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
947 Core::HID::NpadStyleIndex::GameCube); 934 Core::HID::NpadStyleIndex::JoyconRight);
948 ui->comboControllerType->addItem(tr("GameCube Controller")); 935 ui->comboControllerType->addItem(tr("Right Joycon"));
949 } 936 }
950 937
951 // Disable all unsupported controllers 938 if (player_index == 0 && npad_style_set.handheld == 1) {
952 if (!Settings::values.enable_all_controllers) { 939 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
953 return; 940 Core::HID::NpadStyleIndex::Handheld);
954 } 941 ui->comboControllerType->addItem(tr("Handheld"));
955 if (enable_all || npad_style_set.palma == 1) { 942 }
956 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
957 Core::HID::NpadStyleIndex::Pokeball);
958 ui->comboControllerType->addItem(tr("Poke Ball Plus"));
959 }
960 943
961 if (enable_all || npad_style_set.lark == 1) { 944 if (npad_style_set.gamecube == 1) {
962 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), 945 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
963 Core::HID::NpadStyleIndex::NES); 946 Core::HID::NpadStyleIndex::GameCube);
964 ui->comboControllerType->addItem(tr("NES Controller")); 947 ui->comboControllerType->addItem(tr("GameCube Controller"));
965 } 948 }
966 949
967 if (enable_all || npad_style_set.lucia == 1) { 950 // Disable all unsupported controllers
968 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), 951 if (!Settings::values.enable_all_controllers) {
969 Core::HID::NpadStyleIndex::SNES); 952 return;
970 ui->comboControllerType->addItem(tr("SNES Controller")); 953 }
971 } 954 if (npad_style_set.palma == 1) {
955 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
956 Core::HID::NpadStyleIndex::Pokeball);
957 ui->comboControllerType->addItem(tr("Poke Ball Plus"));
958 }
972 959
973 if (enable_all || npad_style_set.lagoon == 1) { 960 if (npad_style_set.lark == 1) {
974 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), 961 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
975 Core::HID::NpadStyleIndex::N64); 962 Core::HID::NpadStyleIndex::NES);
976 ui->comboControllerType->addItem(tr("N64 Controller")); 963 ui->comboControllerType->addItem(tr("NES Controller"));
977 } 964 }
978 965
979 if (enable_all || npad_style_set.lager == 1) { 966 if (npad_style_set.lucia == 1) {
980 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), 967 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
981 Core::HID::NpadStyleIndex::SegaGenesis); 968 Core::HID::NpadStyleIndex::SNES);
982 ui->comboControllerType->addItem(tr("Sega Genesis")); 969 ui->comboControllerType->addItem(tr("SNES Controller"));
983 } 970 }
984 };
985 971
986 if (!is_powered_on) { 972 if (npad_style_set.lagoon == 1) {
987 add_controllers(true); 973 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
988 return; 974 Core::HID::NpadStyleIndex::N64);
975 ui->comboControllerType->addItem(tr("N64 Controller"));
989 } 976 }
990 977
991 add_controllers(false, hid_core.GetSupportedStyleTag()); 978 if (npad_style_set.lager == 1) {
979 index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
980 Core::HID::NpadStyleIndex::SegaGenesis);
981 ui->comboControllerType->addItem(tr("Sega Genesis"));
982 }
992} 983}
993 984
994Core::HID::NpadStyleIndex ConfigureInputPlayer::GetControllerTypeFromIndex(int index) const { 985Core::HID::NpadStyleIndex ConfigureInputPlayer::GetControllerTypeFromIndex(int index) const {
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index f266fd963..5a9dec8f3 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -1516,6 +1516,9 @@ void GMainWindow::ShutdownGame() {
1516 input_subsystem->GetTas()->Stop(); 1516 input_subsystem->GetTas()->Stop();
1517 OnTasStateChanged(); 1517 OnTasStateChanged();
1518 1518
1519 // Enable all controllers
1520 system->HIDCore().SetSupportedStyleTag({Core::HID::NpadStyleSet::All});
1521
1519 render_window->removeEventFilter(render_window); 1522 render_window->removeEventFilter(render_window);
1520 render_window->setAttribute(Qt::WA_Hover, false); 1523 render_window->setAttribute(Qt::WA_Hover, false);
1521 1524