From 1df3cc4b1f8c08e3655777a6d09ee7892fd1a455 Mon Sep 17 00:00:00 2001 From: Street Pea Date: Thu, 3 Oct 2024 16:54:11 -0700 Subject: [PATCH] Fix controller mappings in stream session --- gui/include/qmlbackend.h | 2 +- gui/include/streamsession.h | 5 ++++- gui/src/qmlbackend.cpp | 18 +++++++++++------- gui/src/streamsession.cpp | 38 +++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/gui/include/qmlbackend.h b/gui/include/qmlbackend.h index 12be4d21c..203d93e43 100644 --- a/gui/include/qmlbackend.h +++ b/gui/include/qmlbackend.h @@ -234,7 +234,7 @@ class QmlBackend : public QObject bool controller_mapping_altered = false; bool disable_zero_copy = false; Controller *controller_mapping_controller = {}; - QList current_controller_guids = {}; + QList controller_guids_to_update = {}; int controller_mapping_id = -1; QString controller_mapping_controller_guid = ""; QString controller_mapping_controller_type = ""; diff --git a/gui/include/streamsession.h b/gui/include/streamsession.h index e5e1f4330..1d6a38c3a 100755 --- a/gui/include/streamsession.h +++ b/gui/include/streamsession.h @@ -88,6 +88,7 @@ struct StreamSessionConnectInfo RumbleHapticsIntensity rumble_haptics_intensity; bool buttons_by_pos; bool start_mic_unmuted; + QMap controller_mappings; #if CHIAKI_GUI_ENABLE_STEAMDECK_NATIVE bool vertical_sdeck; bool enable_steamdeck_haptics; @@ -153,7 +154,8 @@ class StreamSession : public QObject QList packet_loss_history; bool cant_display = false; int haptics_handheld; - + QList controller_guids_to_update; + QMap controller_mappings; QHash controllers; #if CHIAKI_GUI_ENABLE_SETSU Setsu *setsu; @@ -222,6 +224,7 @@ class StreamSession : public QObject void PushHapticsFrame(uint8_t *buf, size_t buf_size); void CantDisplayMessage(bool cant_display); ChiakiErrorCode InitiatePsnConnection(QString psn_token); + void updateControllerMappings(); #ifdef Q_OS_MACOS void SetMicAuthorization(Authorization authorization); #endif diff --git a/gui/src/qmlbackend.cpp b/gui/src/qmlbackend.cpp index 842c629cf..763c7c56e 100644 --- a/gui/src/qmlbackend.cpp +++ b/gui/src/qmlbackend.cpp @@ -1128,8 +1128,8 @@ void QmlBackend::updateControllers() controllerMappingQuit(); } QString guid = it.value()->GetGUID(); - if(current_controller_guids.contains(guid)) - current_controller_guids.removeOne(guid); + if(controller_guids_to_update.contains(guid)) + controller_guids_to_update.removeOne(guid); it.value()->deleteLater(); it = controllers.erase(it); changed = true; @@ -1142,8 +1142,7 @@ void QmlBackend::updateControllers() continue; controllers[id] = new QmlController(controller, window, this); QString guid = controller->GetGUIDString(); - if(!current_controller_guids.contains(guid)) - current_controller_guids.append(guid); + controller_guids_to_update.append(guid); connect(controller, &Controller::UpdatingControllerMapping, this, &QmlBackend::controllerMappingUpdate); connect(controller, &Controller::NewButtonMapping, this, &QmlBackend::controllerMappingChangeButton); changed = true; @@ -1241,7 +1240,7 @@ void QmlBackend::updateControllerMappings() for(int i=0; ibuttons_by_pos = settings->GetButtonsByPosition(); this->start_mic_unmuted = settings->GetStartMicUnmuted(); this->packet_loss_max = settings->GetPacketLossMax(); + this->controller_mappings = settings->GetControllerMappings(); #if CHIAKI_GUI_ENABLE_STEAMDECK_NATIVE this->enable_steamdeck_haptics = settings->GetSteamDeckHapticsEnabled(); this->vertical_sdeck = settings->GetVerticalDeckEnabled(); @@ -224,6 +225,7 @@ StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObje host = connect_info.host; QByteArray host_str = connect_info.host.toUtf8(); + controller_mappings = connect_info.controller_mappings; ChiakiConnectInfo chiaki_connect_info = {}; chiaki_connect_info.ps5 = chiaki_target_is_ps5(connect_info.target); @@ -738,6 +740,9 @@ void StreamSession::UpdateGamepads() if(!controller->IsConnected()) { CHIAKI_LOGI(log.GetChiakiLog(), "Controller %d disconnected", controller->GetDeviceID()); + QString guid = controller->GetGUIDString(); + if(controller_guids_to_update.contains(guid)) + controller_guids_to_update.removeOne(guid); controllers.remove(controller_id); if (controller->IsDualSense() || controller->IsDualSenseEdge()) { @@ -757,15 +762,18 @@ void StreamSession::UpdateGamepads() if(!controllers.contains(controller_id)) { auto controller = ControllerManager::GetInstance()->OpenController(controller_id); + QString guid = controller->GetGUIDString(); if(!controller) { CHIAKI_LOGE(log.GetChiakiLog(), "Failed to open controller %d", controller_id); continue; } + controller_guids_to_update.append(guid); CHIAKI_LOGI(log.GetChiakiLog(), "Controller %d opened: \"%s\"", controller_id, controller->GetName().toLocal8Bit().constData()); connect(controller, &Controller::StateChanged, this, &StreamSession::SendFeedbackState); connect(controller, &Controller::MicButtonPush, this, &StreamSession::ToggleMute); controllers[controller_id] = controller; + updateControllerMappings(); if(controller->IsHandheld()) { #if CHIAKI_GUI_ENABLE_STEAMDECK_NATIVE @@ -803,6 +811,36 @@ void StreamSession::UpdateGamepads() #endif } +void StreamSession::updateControllerMappings() +{ + if(SDL_WasInit(SDL_INIT_GAMECONTROLLER)==0) + return; + QStringList mapping_guids = controller_mappings.keys(); + for(int i=0; i