summaryrefslogtreecommitdiff
path: root/src/yuzu
diff options
context:
space:
mode:
authorgerman77 <juangerman-13@hotmail.com>2021-10-18 23:15:46 -0500
committerNarr the Reg <juangerman-13@hotmail.com>2021-11-24 20:30:24 -0600
commit4d308fd0b4fc8f14754c47811e751bf068b330b8 (patch)
tree3ea29a0c024fdc9ad7681aaf6160e46511ceb2a6 /src/yuzu
parent72e5920240381cbe775dc38fcdff88cf46b55101 (diff)
hid: Fix controller connection/disconnection
Diffstat (limited to 'src/yuzu')
-rw-r--r--src/yuzu/configuration/configure_input.cpp1
-rw-r--r--src/yuzu/configuration/configure_input_player.cpp81
-rw-r--r--src/yuzu/configuration/configure_input_player_widget.cpp2
3 files changed, 75 insertions, 9 deletions
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp
index a8611f77f..67faa8be8 100644
--- a/src/yuzu/configuration/configure_input.cpp
+++ b/src/yuzu/configuration/configure_input.cpp
@@ -114,6 +114,7 @@ void ConfigureInput::Initialize(InputCommon::InputSubsystem* input_subsystem, Co
player_tabs[i]->setLayout(new QHBoxLayout(player_tabs[i]));
player_tabs[i]->layout()->addWidget(player_controllers[i]);
connect(player_controllers[i], &ConfigureInputPlayer::Connected, [&, i](bool is_connected) {
+ // Ensures that the controllers are always connected in sequential order
if (is_connected) {
for (std::size_t index = 0; index <= i; ++index) {
player_connected[index]->setChecked(is_connected);
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index ed9c3facf..81310a5b3 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -143,8 +143,26 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()),
bottom_row(bottom_row), system{system_} {
- emulated_controller = system_.HIDCore().GetEmulatedControllerByIndex(player_index);
- emulated_controller->EnableConfiguration();
+ if (player_index == 0) {
+ auto* emulated_controller_p1 =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);
+ auto* emulated_controller_hanheld =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
+ emulated_controller_p1->SaveCurrentConfig();
+ emulated_controller_p1->EnableConfiguration();
+ emulated_controller_hanheld->SaveCurrentConfig();
+ emulated_controller_hanheld->EnableConfiguration();
+ if (emulated_controller_hanheld->IsConnected(true)) {
+ emulated_controller_p1->Disconnect();
+ emulated_controller = emulated_controller_hanheld;
+ } else {
+ emulated_controller = emulated_controller_p1;
+ }
+ } else {
+ emulated_controller = system_.HIDCore().GetEmulatedControllerByIndex(player_index);
+ emulated_controller->SaveCurrentConfig();
+ emulated_controller->EnableConfiguration();
+ }
ui->setupUi(this);
setFocusPolicy(Qt::ClickFocus);
@@ -460,13 +478,36 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
UpdateControllerEnabledButtons();
UpdateControllerButtonNames();
UpdateMotionButtons();
- connect(ui->comboControllerType, qOverload<int>(&QComboBox::currentIndexChanged), [this](int) {
+ connect(ui->comboControllerType, qOverload<int>(&QComboBox::currentIndexChanged), [this, player_index](int) {
UpdateControllerAvailableButtons();
UpdateControllerEnabledButtons();
UpdateControllerButtonNames();
UpdateMotionButtons();
- emulated_controller->SetNpadType(
- GetControllerTypeFromIndex(ui->comboControllerType->currentIndex()));
+ const Core::HID::NpadType type = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
+
+ if (player_index == 0) {
+ auto* emulated_controller_p1 =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);
+ auto* emulated_controller_hanheld =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
+ bool is_connected = emulated_controller->IsConnected(true);
+
+ emulated_controller_p1->SetNpadType(type);
+ emulated_controller_hanheld->SetNpadType(type);
+ if (is_connected) {
+ if (type == Core::HID::NpadType::Handheld) {
+ emulated_controller_p1->Disconnect();
+ emulated_controller_hanheld->Connect();
+ emulated_controller = emulated_controller_hanheld;
+ } else {
+ emulated_controller_hanheld->Disconnect();
+ emulated_controller_p1->Connect();
+ emulated_controller = emulated_controller_p1;
+ }
+ }
+ ui->controllerFrame->SetController(emulated_controller);
+ }
+ emulated_controller->SetNpadType(type);
});
connect(ui->comboDevices, qOverload<int>(&QComboBox::activated), this,
@@ -504,11 +545,35 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
}
ConfigureInputPlayer::~ConfigureInputPlayer() {
- emulated_controller->DisableConfiguration();
+ if (player_index == 0) {
+ auto* emulated_controller_p1 =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);
+ auto* emulated_controller_hanheld =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
+ emulated_controller_p1->DisableConfiguration();
+ emulated_controller_hanheld->DisableConfiguration();
+ } else {
+ emulated_controller->DisableConfiguration();
+ }
};
void ConfigureInputPlayer::ApplyConfiguration() {
+ if (player_index == 0) {
+ auto* emulated_controller_p1 =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);
+ auto* emulated_controller_hanheld =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
+ emulated_controller_p1->DisableConfiguration();
+ emulated_controller_p1->SaveCurrentConfig();
+ emulated_controller_p1->EnableConfiguration();
+ emulated_controller_hanheld->DisableConfiguration();
+ emulated_controller_hanheld->SaveCurrentConfig();
+ emulated_controller_hanheld->EnableConfiguration();
+ return;
+ }
+ emulated_controller->DisableConfiguration();
emulated_controller->SaveCurrentConfig();
+ emulated_controller->EnableConfiguration();
}
void ConfigureInputPlayer::showEvent(QShowEvent* event) {
@@ -535,9 +600,9 @@ void ConfigureInputPlayer::RetranslateUI() {
void ConfigureInputPlayer::LoadConfiguration() {
UpdateUI();
UpdateInputDeviceCombobox();
- const int comboBoxIndex = GetIndexFromControllerType(emulated_controller->GetNpadType());
+ const int comboBoxIndex = GetIndexFromControllerType(emulated_controller->GetNpadType(true));
ui->comboControllerType->setCurrentIndex(comboBoxIndex);
- ui->groupConnectedController->setChecked(emulated_controller->IsConnected());
+ ui->groupConnectedController->setChecked(emulated_controller->IsConnected(true));
}
void ConfigureInputPlayer::ConnectPlayer(bool connected) {
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp
index 446b72e55..3b79b6076 100644
--- a/src/yuzu/configuration/configure_input_player_widget.cpp
+++ b/src/yuzu/configuration/configure_input_player_widget.cpp
@@ -145,7 +145,7 @@ void PlayerControlPreview::ControllerUpdate(Core::HID::ControllerTriggerType typ
needs_redraw = true;
break;
case Core::HID::ControllerTriggerType::Type:
- controller_type = controller->GetNpadType();
+ controller_type = controller->GetNpadType(true);
needs_redraw = true;
break;
case Core::HID::ControllerTriggerType::Color: