Xbox Cloud Gaming app for PS5 Homebrew
C
fix(settings): keep in-game menu changes; one Settings <-> screen mapping
Rafael Abud Ferreira6852b80d8e8c
diff --git a/CMakeLists.txt b/CMakeLists.txtindex d4d90dd..94d8a41 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -86,6 +86,7 @@ add_library(xcloud_ui STATICsrc/ui/font.cppsrc/ui/image_cache.cppsrc/ui/app_ui.cpp+ src/ui/settings_choice.cppsrc/ui/stream_menu.cppsrc/ui/toast_view.cppsrc/ui/pad_icons.cppdiff --git a/src/app/app_core.cpp b/src/app/app_core.cppindex 4827a7b..e2f0fd9 100644--- a/src/app/app_core.cpp+++ b/src/app/app_core.cpp@@ -98,36 +98,13 @@ bool saveSettings(const ui::SettingsChoice& choice) {bool languageChanged, fullscreenChanged;{std::lock_guard<std::mutex> lock(g_settingsMutex);- std::string code = ui::languageCode(static_cast<ui::Language>(choice.language));- languageChanged = code != g_settings.language;- g_settings.language = code;- g_settings.resolution = choice.resolution == 1 ? "720p" : choice.resolution == 2 ? "best" : "1080p";- g_settings.region = choice.region;- g_settings.loginCountry = choice.loginCountry;- g_settings.deadzoneLeft = choice.deadzone[0];- g_settings.deadzoneRight = choice.deadzone[1];- g_settings.triggerStrength = choice.triggerStrength;- g_settings.triggerHz = choice.triggerHz;- g_settings.triggerResistance = choice.triggerResistance;- g_settings.triggerPulses = choice.triggerPulses;- g_settings.circleConfirms = choice.circleConfirms;- g_settings.lightBarMode = choice.lightBarMode;- g_settings.lightBarColour = choice.lightBarColour;- g_settings.sharpness = choice.sharpness;- g_settings.deband = choice.deband;- g_settings.upscaler = choice.upscaler;- g_settings.highRefresh = choice.highRefresh;- g_settings.maxBitrateMbps = choice.maxBitrateMbps;- g_settings.gameVolume = choice.gameVolume;- g_settings.keyMap = choice.keyMap;- if (input::padMapValid(choice.padMap)) g_settings.padMap = choice.padMap; // the screen only lets a complete one out- g_settings.gyroMode = choice.gyroMode;- g_settings.gyroLevel = choice.gyroLevel;- g_settings.touchpadMouse = choice.touchpadMouse;- fullscreenChanged = g_settings.desktopFullscreen != choice.fullscreen;- g_settings.desktopFullscreen = choice.fullscreen;+ std::string language = g_settings.language;+ bool fullscreen = g_settings.desktopFullscreen;+ ui::applyChoice(choice, g_settings);+ languageChanged = g_settings.language != language;+ fullscreenChanged = g_settings.desktopFullscreen != fullscreen;g_settings.save(settingsPath()); // warns itself- XC_LOGI("settings saved: language %s, %s, region %s", code.c_str(), g_settings.resolution.c_str(),+ XC_LOGI("settings saved: language %s, %s, region %s", g_settings.language.c_str(), g_settings.resolution.c_str(),g_settings.region.empty() ? "auto" : g_settings.region.c_str());}applyControllerSettings();@@ -304,35 +281,9 @@ bool coreStartup() {g_ui = std::make_unique<ui::AppUi>(fonts, *g_images);startPriceLoop();{- ui::SettingsChoice choice;- choice.language = static_cast<int>(ui::language());- choice.resolution = g_settings.resolution == "720p" ? 1 : (g_settings.resolution == "1440p" || g_settings.resolution == "best") ? 2 : 0;- choice.region = g_settings.region;- choice.loginCountry = g_settings.loginCountry;- choice.deadzone[0] = std::clamp(g_settings.deadzoneLeft, 0, ui::kMaxDeadzone);- choice.deadzone[1] = std::clamp(g_settings.deadzoneRight, 0, ui::kMaxDeadzone);- choice.triggerStrength = g_settings.triggerStrength;- choice.triggerHz = g_settings.triggerHz;- choice.triggerResistance = g_settings.triggerResistance;- choice.triggerPulses = g_settings.triggerPulses;- choice.circleConfirms = g_settings.circleConfirms;- choice.lightBarMode = g_settings.lightBarMode;- choice.lightBarColour = g_settings.lightBarColour;- choice.sharpness = g_settings.sharpness;- choice.deband = g_settings.deband;- choice.upscaler = g_settings.upscaler;- choice.highRefresh = g_settings.highRefresh;- choice.maxBitrateMbps = g_settings.maxBitrateMbps;- choice.gameVolume = g_settings.gameVolume;- choice.keyMap = g_settings.keyMap;- choice.padMap = g_settings.padMap;- choice.gyroMode = g_settings.gyroMode;- choice.gyroLevel = g_settings.gyroLevel;- choice.fullscreen = g_settings.desktopFullscreen;- choice.touchpadMouse = g_settings.touchpadMouse;g_ui->setAllow1440(allow1440Locked());g_ui->setUpdateState(XC_APP_VERSION, {}, false); // Settings shows this version before any check- g_ui->setSettings(choice);+ g_ui->setSettings(ui::choiceFromSettings(g_settings));g_ui->setPerGameSettings(g_settings.perGame);g_ui->setGyroDefaults(g_settings.gyroMode, g_settings.gyroLevel);applyControllerSettings();diff --git a/src/app/app_state.cpp b/src/app/app_state.cppindex 3e9c2ac..8cb789b 100644--- a/src/app/app_state.cpp+++ b/src/app/app_state.cpp@@ -14,6 +14,9 @@ std::mutex g_settingsMutex;Settings g_settings;std::string settingsPath() { return platform::dataDir() + "/settings.json"; }bool allow1440Locked() { return std::max(g_settings.maxHeightCloud, g_settings.maxHeightHome) >= 1440; }+void refreshSettingsUiLocked() {+ if (g_ui) g_ui->setSettings(ui::choiceFromSettings(g_settings));+}std::atomic<int> g_command{kSignIn};std::atomic<bool> g_cancel{false};std::mutex g_argMutex;diff --git a/src/app/app_state.h b/src/app/app_state.hindex 04b8784..9241a12 100644--- a/src/app/app_state.h+++ b/src/app/app_state.h@@ -29,6 +29,12 @@ extern Settings g_settings;std::string settingsPath();// Caller holds g_settingsMutex. 1440p is offered once a stream delivered it.bool allow1440Locked();+// Settings' screen takes g_settings again (ui::choiceFromSettings) after+// something outside it changed them (the game menu, a test putting them+// back): else leaving Settings would save its older copy over them. Caller+// holds g_settingsMutex (then AppUi's lock is taken: the usual order). Not+// while Settings is open with changes of its own (it would drop them).+void refreshSettingsUiLocked();// --- Worker commands (worker.cpp) ----------------------------------------------enum Command { kNone, kSignIn, kPlay, kSignOut, kReloadLibrary, kConsoles, kUpdate };diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cppindex 86724d6..179c801 100644--- a/src/app/autoplay.cpp+++ b/src/app/autoplay.cpp@@ -297,6 +297,7 @@ void autoplayPad(input::ControllerState& pad) {}g_settings.save(settingsPath());g_ui->setPerGameSettings(g_settings.perGame);+ refreshSettingsUiLocked();}XC_LOGI("autoplay: the game's profile put back as it was");g_autoplay.gameSettingsTest = false;diff --git a/src/app/stream_screen.cpp b/src/app/stream_screen.cppindex 4552aaa..9ac8b14 100644--- a/src/app/stream_screen.cpp+++ b/src/app/stream_screen.cpp@@ -289,6 +289,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bif (hasCustomProfile_) g_settings.perGame[gameKey_].sharpness = sharpness_;else g_settings.sharpness = sharpness_;g_settings.save(settingsPath());+ refreshSettingsUiLocked(); // else leaving Settings later would put the old value backif (g_ui) g_ui->setPerGameSettings(g_settings.perGame);break;}@@ -299,6 +300,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bif (hasCustomProfile_) g_settings.perGame[gameKey_].upscaler = upscaler_;else g_settings.upscaler = upscaler_;g_settings.save(settingsPath());+ refreshSettingsUiLocked();if (g_ui) g_ui->setPerGameSettings(g_settings.perGame);break;}@@ -309,6 +311,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bif (hasCustomProfile_) g_settings.perGame[gameKey_].deband = deband_;else g_settings.deband = deband_;g_settings.save(settingsPath());+ refreshSettingsUiLocked();if (g_ui) g_ui->setPerGameSettings(g_settings.perGame);break;}@@ -319,6 +322,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bif (hasCustomProfile_) g_settings.perGame[gameKey_].triggerStrength = triggerStrength_;else g_settings.triggerStrength = triggerStrength_;g_settings.save(settingsPath());+ refreshSettingsUiLocked();if (g_ui) g_ui->setPerGameSettings(g_settings.perGame);break;}@@ -334,6 +338,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bg_settings.deadzoneRight = deadzone_;}g_settings.save(settingsPath());+ refreshSettingsUiLocked();if (g_ui) g_ui->setPerGameSettings(g_settings.perGame);break;}@@ -348,9 +353,9 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b} else {g_settings.gyroMode = gyroMode_;g_settings.gyroLevel = gyroLevel_;- if (g_ui) g_ui->setGyroDefaults(gyroMode_, gyroLevel_);}g_settings.save(settingsPath());+ refreshSettingsUiLocked(); // the gyro's defaults tooif (g_ui) g_ui->setPerGameSettings(g_settings.perGame);break;}@@ -362,6 +367,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bif (hasCustomProfile_) g_settings.perGame[gameKey_].circleConfirms = circleConfirms_;else g_settings.circleConfirms = circleConfirms_;g_settings.save(settingsPath());+ refreshSettingsUiLocked();if (g_ui) g_ui->setPerGameSettings(g_settings.perGame);break;}diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex f9d6f9e..389ea62 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -133,6 +133,14 @@ struct SettingsChoice {bool touchpadMouse = false;};+// Settings' screen and settings.json, one mapping both ways: what the screen+// shows from the saved settings (at start, and after anything outside+// Settings changed them: the game menu, ...), and the saved settings+// updated with what the screen holds (only the fields it carries; the rest+// stay as they are).+SettingsChoice choiceFromSettings(const app::Settings& settings);+void applyChoice(const SettingsChoice& choice, app::Settings& settings);+// What this system and its pads can do, filled in by the app from the pads'// capabilities (input/input_ext.h), display::caps() and shell::caps(): the// screens hide the options that can't work here and word the rest for thediff --git a/src/ui/settings_choice.cpp b/src/ui/settings_choice.cppnew file mode 100644index 0000000..04fb934--- /dev/null+++ b/src/ui/settings_choice.cpp@@ -0,0 +1,71 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+// Settings' screen <-> settings.json (app_ui.h).+#include "ui/app_ui.h"+#include "ui/strings.h"++#include <algorithm>++namespace xc::ui {++SettingsChoice choiceFromSettings(const app::Settings& s) {+ SettingsChoice c;+ c.language = static_cast<int>(languageFromCode(s.language));+ c.resolution = s.resolution == "720p" ? 1 : (s.resolution == "1440p" || s.resolution == "best") ? 2 : 0;+ c.region = s.region;+ c.loginCountry = s.loginCountry;+ c.deadzone[0] = std::clamp(s.deadzoneLeft, 0, kMaxDeadzone);+ c.deadzone[1] = std::clamp(s.deadzoneRight, 0, kMaxDeadzone);+ c.triggerStrength = s.triggerStrength;+ c.triggerHz = s.triggerHz;+ c.triggerResistance = s.triggerResistance;+ c.triggerPulses = s.triggerPulses;+ c.triggerProfile = s.triggerProfile;+ c.circleConfirms = s.circleConfirms;+ c.lightBarMode = s.lightBarMode;+ c.lightBarColour = s.lightBarColour;+ c.sharpness = s.sharpness;+ c.deband = s.deband;+ c.upscaler = s.upscaler;+ c.highRefresh = s.highRefresh;+ c.maxBitrateMbps = s.maxBitrateMbps;+ c.gameVolume = s.gameVolume;+ c.keyMap = s.keyMap;+ c.padMap = s.padMap;+ c.gyroMode = s.gyroMode;+ c.gyroLevel = s.gyroLevel;+ c.fullscreen = s.desktopFullscreen;+ c.touchpadMouse = s.touchpadMouse;+ return c;+}++void applyChoice(const SettingsChoice& c, app::Settings& s) {+ s.language = languageCode(static_cast<Language>(c.language));+ s.resolution = c.resolution == 1 ? "720p" : c.resolution == 2 ? "best" : "1080p";+ s.region = c.region;+ s.loginCountry = c.loginCountry;+ s.deadzoneLeft = c.deadzone[0];+ s.deadzoneRight = c.deadzone[1];+ s.triggerStrength = c.triggerStrength;+ s.triggerHz = c.triggerHz;+ s.triggerResistance = c.triggerResistance;+ s.triggerPulses = c.triggerPulses;+ s.triggerProfile = c.triggerProfile;+ s.circleConfirms = c.circleConfirms;+ s.lightBarMode = c.lightBarMode;+ s.lightBarColour = c.lightBarColour;+ s.sharpness = c.sharpness;+ s.deband = c.deband;+ s.upscaler = c.upscaler;+ s.highRefresh = c.highRefresh;+ s.maxBitrateMbps = c.maxBitrateMbps;+ s.gameVolume = c.gameVolume;+ s.keyMap = c.keyMap;+ if (input::padMapValid(c.padMap)) s.padMap = c.padMap; // the screen only lets a complete one out+ s.gyroMode = c.gyroMode;+ s.gyroLevel = c.gyroLevel;+ s.desktopFullscreen = c.fullscreen;+ s.touchpadMouse = c.touchpadMouse;+}++} // namespace xc::uidiff --git a/tests/test_main.cpp b/tests/test_main.cppindex a421686..40b7112 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -324,6 +324,78 @@ static void testSettingsMigration() {}// The microphone's gain is stored as a choice (0..2), not as the factor.+// Settings' screen and settings.json share one mapping: every field the+// screen carries comes back as it was (Settings -> choice -> Settings), and+// the fields it doesn't carry are left alone.+static void testSettingsChoiceRoundTrip() {+ using namespace xc::input;+ xc::app::Settings s;+ s.language = "pt-BR";+ s.resolution = "720p";+ s.region = "Brazil South";+ s.loginCountry = "jp";+ s.deadzoneLeft = 7, s.deadzoneRight = 21;+ s.triggerStrength = 4, s.triggerHz = 2, s.triggerResistance = 3, s.triggerPulses = true, s.triggerProfile = 2;+ s.circleConfirms = true;+ s.lightBarMode = 1, s.lightBarColour = 0xFF112233;+ s.sharpness = 3, s.deband = 1, s.upscaler = 0;+ s.highRefresh = true;+ s.maxBitrateMbps = 15, s.gameVolume = 150;+ assignKey(s.keyMap, KeyAction::A, 0, 'E');+ assignPadSource(s.padMap, PadFn::A, static_cast<uint8_t>(PadFn::B));+ CHECK(padMapValid(s.padMap));+ s.gyroMode = 2, s.gyroLevel = 9;+ s.desktopFullscreen = false;+ s.touchpadMouse = true;+ // Not carried by the screen: must survive applyChoice untouched.+ s.keyboardPlayer = 3;+ s.streamStats = true;+ s.favorites = {"P1"};++ ui::SettingsChoice c = ui::choiceFromSettings(s);+ CHECK(c.language == static_cast<int>(ui::Language::PortugueseBR));+ CHECK(c.resolution == 1 && c.triggerProfile == 2 && c.lightBarColour == 0xFF112233u && !c.fullscreen);++ xc::app::Settings back; // defaults, then what the screen carries+ back.keyboardPlayer = 3;+ back.streamStats = true;+ back.favorites = {"P1"};+ ui::applyChoice(c, back);+ CHECK(back.language == s.language);+ CHECK(back.resolution == s.resolution);+ CHECK(back.region == s.region && back.loginCountry == s.loginCountry);+ CHECK(back.deadzoneLeft == s.deadzoneLeft && back.deadzoneRight == s.deadzoneRight);+ CHECK(back.triggerStrength == s.triggerStrength && back.triggerHz == s.triggerHz &&+ back.triggerResistance == s.triggerResistance && back.triggerPulses == s.triggerPulses &&+ back.triggerProfile == s.triggerProfile);+ CHECK(back.circleConfirms == s.circleConfirms);+ CHECK(back.lightBarMode == s.lightBarMode && back.lightBarColour == s.lightBarColour);+ CHECK(back.sharpness == s.sharpness && back.deband == s.deband && back.upscaler == s.upscaler);+ CHECK(back.highRefresh == s.highRefresh);+ CHECK(back.maxBitrateMbps == s.maxBitrateMbps && back.gameVolume == s.gameVolume);+ CHECK(back.keyMap == s.keyMap && back.padMap == s.padMap);+ CHECK(back.gyroMode == s.gyroMode && back.gyroLevel == s.gyroLevel);+ CHECK(back.desktopFullscreen == s.desktopFullscreen && back.touchpadMouse == s.touchpadMouse);+ CHECK(back.keyboardPlayer == 3 && back.streamStats && back.favorites.size() == 1);+ // Every resolution, both ways ("1440p" from older versions reads as the top tier).+ for (const char* res : {"1080p", "720p", "best"}) {+ xc::app::Settings r;+ r.resolution = res;+ xc::app::Settings out;+ ui::applyChoice(ui::choiceFromSettings(r), out);+ CHECK(out.resolution == res);+ }+ xc::app::Settings old;+ old.resolution = "1440p";+ CHECK(ui::choiceFromSettings(old).resolution == 2);+ // An incomplete controller map from the screen never replaces a valid one.+ ui::SettingsChoice broken = c;+ broken.padMap[0] = kPadNone;+ xc::app::Settings kept = s;+ ui::applyChoice(broken, kept);+ CHECK(kept.padMap == s.padMap);+}+static void testMicGain() {app::Settings s;CHECK(s.micGain == 1 && s.micGainFactor() == 1.0f);@@ -2146,6 +2218,7 @@ int main() {testVersions();testStreamMenu();testSettingsMigration();+ testSettingsChoiceRoundTrip();testMicGain();testPerGameSettings();testPlaytimeLimit();