Xbox Cloud Gaming app for PS5 Homebrew
C
UI: add gyro aiming to Settings and Game Settings modal
Rafael Abud Ferreirad837f0a7fbe5
diff --git a/ROADMAP.md b/ROADMAP.mdindex 0860b1e..1f854b1 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -225,8 +225,8 @@ is rolled back at the next start), then the app restarts itself| Game Pass trial badge (later) | The store's answer says `isTrial`; a TRIAL mark next to the plan. Not now | small || Unreliable input channel (protocol v9) | The official client sends input on an unordered channel, so a lost packet doesn't hold the ones after it; needs a capture of its frames | medium || DualSense button remapping (done), touchpad mouse | Full DualSense button customization in Settings and each game's settings (Edge back buttons/paddles too), with its own remapping screen like keyboard keys (done); touchpad as a mouse for MKB games | medium |-| Gamepad report physicality & touchpad click robustness (#39) | In `src/stream/input_packet.cpp`: compute accurate `physicalPhysicality` bitmask (0 when idle) and send 0 for `virtualPhysicality` (LE), preventing idle secondary controllers/bridges from continuously reporting active physical input to xCloud. In `src/app/stream_screen.cpp`: suppress touchpad swipe gesture detection while `btnTouchpad` is physically pressed. Add one-time diagnostic log on first `kView` / `kMenu` sent per stream session | small |-| Gyro in Settings | Gyro aiming in Settings and the game settings too (now in the game menu only); an inverted / separate horizontal sensitivity if asked | small |+| Gamepad report physicality & touchpad click robustness (#39, done) | In `src/stream/input_packet.cpp`: compute accurate `physicalPhysicality` bitmask (0 when idle) and send 0 for `virtualPhysicality` (LE), preventing idle secondary controllers/bridges from continuously reporting active physical input to xCloud. In `src/app/stream_screen.cpp`: suppress touchpad swipe gesture detection while `btnTouchpad` is physically pressed. Add one-time diagnostic log on first `kView` / `kMenu` sent per stream session | small |+| Gyro in Settings (done) | Gyro aiming in Settings and the game settings too (done); an inverted / separate horizontal sensitivity if asked | small || Desktop Vulkan display (done) | `display/gpu.cpp` shared with the SDL3 desktop window (`SDL_Vulkan_*`): FSR 1, Anime4K x2, Anime4K Restore, CAS sharpening and block smoothing on Linux, with `SDL_Renderer` kept as fallback | medium || Favourites, game language | A favourites row; the game's language apart from the app's | small || Lost audio filled | Opus concealment / in-band FEC for lost audio packets: needs libopus (FFmpeg's own Opus decoder has neither) | small–medium |diff --git a/src/app/app_core.cpp b/src/app/app_core.cppindex fa2dbf9..6961ff2 100644--- a/src/app/app_core.cpp+++ b/src/app/app_core.cpp@@ -112,6 +112,8 @@ bool saveSettings(const ui::SettingsChoice& choice) {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;fullscreenChanged = g_settings.desktopFullscreen != choice.fullscreen;g_settings.desktopFullscreen = choice.fullscreen;g_settings.save(settingsPath()); // warns itself@@ -119,6 +121,7 @@ bool saveSettings(const ui::SettingsChoice& choice) {g_settings.region.empty() ? "auto" : g_settings.region.c_str());}applyControllerSettings();+ if (g_ui) g_ui->setGyroDefaults(choice.gyroMode, choice.gyroLevel);if (fullscreenChanged) shell::setFullscreen(choice.fullscreen); // a desktop's window (main thread)return languageChanged;}@@ -310,6 +313,8 @@ bool coreStartup() {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;g_ui->setAllow1440(allow1440Locked());g_ui->setUpdateState(XC_APP_VERSION, {}, false); // Settings shows this version before any checkdiff --git a/src/app/desktop_selftest.cpp b/src/app/desktop_selftest.cppindex 5215ef1..277f915 100644--- a/src/app/desktop_selftest.cpp+++ b/src/app/desktop_selftest.cpp@@ -200,7 +200,8 @@ int desktopSelftest(const std::string& dir) {auto rows = ui::visibleSettingsRows(caps);bool hidden = std::none_of(rows.begin(), rows.end(), [&](const ui::SettingsRowPos& r) {return (r.row == 6 && !caps.lightBar) || (r.row == 9 && !caps.highRefresh) ||- (r.row == 4 && !caps.triggerRumble && !caps.adaptiveTriggers);+ (r.row == 4 && !caps.triggerRumble && !caps.adaptiveTriggers) ||+ (r.row == 15 && !caps.gyro);});std::printf("selftest: Settings shows %zu of %d rows\n", rows.size(), ui::kSettingRows);check(hidden && rows.size() < static_cast<size_t>(ui::kSettingRows), "Settings hides light bar / 120 Hz rows");diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex 5d0a10a..06f69bb 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -60,15 +60,15 @@ constexpr int kResolutionOrder[3] = {1, 0, 2};// stream (resolution, a desktop's display mode, 120 Hz, bitrate, region);// sound; the controller and keyboard; updates last. A group starts at each// kSettingsGroupStart.-constexpr int kSettingsOrder[kSettingRows] = {0, 8, 1, 13, 9, 10, 2, 11, 3, 4, 5, 6, 14, 12, 7};+constexpr int kSettingsOrder[kSettingRows] = {0, 8, 1, 13, 9, 10, 2, 11, 3, 4, 5, 6, 15, 14, 12, 7};constexpr bool kSettingsGroupStart[kSettingRows] = {false, false, true, false, false, false, false, true,- true, false, false, false, false, false, true};+ true, false, false, false, false, false, false, true};// The game settings' rows on screen (ids: 0 profile, 1 upscaler, 2// sharpness, 3 block smoothing, 4 resolution, 5 dead zone, 6 triggers, 7// confirm, 8 120 Hz, 9 keyboard keys, 10 back to the default, 11 controller-// buttons).-constexpr int kGameRowOrder[12] = {0, 4, 8, 1, 2, 3, 5, 6, 7, 11, 9, 10};-constexpr bool kGameGroupStart[12] = {false, true, false, true, false, false, true, false, false, false, false, true};+// buttons, 12 gyro aiming).+constexpr int kGameRowOrder[13] = {0, 4, 8, 1, 2, 3, 5, 6, 7, 12, 11, 9, 10};+constexpr bool kGameGroupStart[13] = {false, true, false, true, false, false, true, false, false, false, false, false, true};// The keyboard keys' screen: two columns of inputs, then "Reset to default".constexpr int kKeysPerColumn = input::kKeyActions / 2;// Updates on a desktop: the newest release's page (the app doesn't install it there).@@ -244,6 +244,7 @@ std::vector<SettingsRowPos> visibleSettingsRows(const UiCaps& caps) {case 6: return caps.lightBar;case 9: return caps.highRefresh;case 13: return caps.desktopWindow;+ case 15: return caps.gyro;default: return true;}});@@ -258,6 +259,7 @@ std::vector<SettingsRowPos> visibleGameSettingsRows(const UiCaps& caps, bool cuscase 6: return caps.triggerRumble || caps.adaptiveTriggers;case 8: return caps.highRefresh;case 10: return custom;+ case 12: return caps.gyro;default: return true;}});@@ -1318,6 +1320,8 @@ void AppUi::setUpdateStatus(const std::string& status, float fraction) {void AppUi::setSettings(const SettingsChoice& choice) {std::lock_guard<std::mutex> lock(mutex_);settings_ = choice;+ gyroMode_ = choice.gyroMode;+ gyroLevel_ = choice.gyroLevel;dirty_ = true;}@@ -1337,6 +1341,9 @@ void AppUi::setGyroDefaults(int mode, int level) {std::lock_guard<std::mutex> lock(mutex_);gyroMode_ = mode;gyroLevel_ = level;+ settings_.gyroMode = mode;+ settings_.gyroLevel = level;+ dirty_ = true;}void AppUi::setPerGameSettings(const std::map<std::string, app::GameProfile>& perGame) {@@ -1488,6 +1495,8 @@ std::vector<std::string> AppUi::settingOptions(int row) const {} else if (row == 14) {// So do the controller buttons'.out = {tr(settings_.padMap == input::defaultPadMap() ? Str::ProfileDefault : Str::ProfileCustom)};+ } else if (row == 15) {+ out = {tr(Str::Off), tr(Str::GyroAlways), tr(Str::GyroAiming)};} else if (row == 8) {out.push_back(loginCountryOffText());@@ -1515,6 +1524,7 @@ int AppUi::settingSelected(int row) const {if (row == 7) return 0;if (row == 9) return settings_.highRefresh ? 1 : 0;if (row == 13) return settings_.fullscreen ? 1 : 0;+ if (row == 15) return std::clamp(settings_.gyroMode, 0, 2);if (row == 10) {for (size_t i = 0; i < std::size(kBitrateCaps); ++i)if (kBitrateCaps[i] == settings_.maxBitrateMbps) return static_cast<int>(i) + 1;@@ -1558,6 +1568,9 @@ void AppUi::applySetting(int row, int index) {// In force at once (handle() sends the settings): the window follows.if (settings_.fullscreen != (index == 1)) displayModeChanged_ = true;settings_.fullscreen = index == 1;+ } else if (row == 15) {+ settings_.gyroMode = index;+ gyroMode_ = index;} else if (row == 10) {settings_.maxBitrateMbps = index == 0 ? 0 : kBitrateCaps[index - 1];} else if (row == 11) {@@ -2240,6 +2253,11 @@ void AppUi::handleGameSettings(const NavInput& in, UiEvent& ev) {activeGameHasCustom_ = true;dirty_ = true;break;+ case 12: // Gyro aiming (0 off, 1 always, 2 while aiming)+ activeGameProfile_.gyroMode = (activeGameProfile_.gyroMode + 3 + dir) % 3;+ activeGameHasCustom_ = true;+ dirty_ = true;+ break;default: break;}}@@ -2307,6 +2325,11 @@ void AppUi::handleGameSettings(const NavInput& in, UiEvent& ev) {activeGameHasCustom_ = true;dirty_ = true;break;+ case 12:+ activeGameProfile_.gyroMode = (activeGameProfile_.gyroMode + 1) % 3;+ activeGameHasCustom_ = true;+ dirty_ = true;+ break;case 9: // Keyboard keys: their own screen, on this game'sopenTester(Tester::Keys);settings_.keyMap = activeGameProfile_.keyMap;@@ -3641,7 +3664,8 @@ void AppUi::drawSettings(Canvas& c) {tr(Str::Deadzone), tr(Str::TriggerRumble), tr(Str::ConfirmButton),tr(Str::LightBar), tr(Str::Updates), tr(Str::LoginCountry),tr(Str::HighRefresh), tr(Str::BitrateCap), tr(Str::GameVolume),- tr(Str::KeyboardKeys), tr(Str::DisplayMode), tr(Str::ControllerButtons)};+ tr(Str::KeyboardKeys), tr(Str::DisplayMode), tr(Str::ControllerButtons),+ tr(Str::Gyro)};constexpr int kRowW = 1200, kRowH = 46, kGap = 4, kGroupGap = 12;Rect rows[kSettingRows]; // by row idint y = 236;@@ -4271,7 +4295,7 @@ void AppUi::drawGameSettings(Canvas& c) {title = title + " \xE2\x80\xA2 " + cut + "...";}}- constexpr int kModalW = 1140, kModalH = 880;+ constexpr int kModalW = 1140, kModalH = 930;constexpr int kRowH = 50, kGap = 6, kGroupGap = 12;// The rows caps_ allows; the panel loses the height of those it hides// (the same as ever with all of them, "Reset to default" or not).@@ -4361,6 +4385,12 @@ void AppUi::drawGameSettings(Canvas& c) {label = tr(Str::ControllerButtons);value = tr(activeGameProfile_.padMap == input::defaultPadMap() ? Str::ProfileDefault : Str::ProfileCustom);break;+ case 12:+ label = tr(Str::Gyro);+ value = tr(activeGameProfile_.gyroMode == 1 ? Str::GyroAlways+ : activeGameProfile_.gyroMode == 2 ? Str::GyroAiming+ : Str::Off);+ break;default: break;}diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex 1b43c4e..9105328 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -125,6 +125,8 @@ struct SettingsChoice {int gameVolume = 100; // percent: 25 / 50 / 75 / 100 / 150input::KeyMap keyMap = input::defaultKeyMap(); // the keyboard as a player's controllerinput::PadMap padMap = input::defaultPadMap(); // the controller's buttons toward the game (always complete)+ int gyroMode = 0; // gyro aiming (input/gyro.h): 0 off, 1 always, 2 while L2 is held+ int gyroLevel = 5; // intensity, 1..10bool fullscreen = true; // a desktop's window fullscreen (UiCaps::desktopWindow; F11 switches it too)};@@ -167,9 +169,9 @@ std::vector<SettingsRowPos> visibleGameSettingsRows(const UiCaps& caps, bool cus// The largest stick dead zone Settings offers, in percent of the travel.constexpr int kMaxDeadzone = 30;-constexpr int kSettingRows = 15; // language, resolution, region, dead zone, triggers, confirm, light bar, updates,+constexpr int kSettingRows = 16; // language, resolution, region, dead zone, triggers, confirm, light bar, updates,// sign-in country, 120 Hz output, bitrate cap, game volume, keyboard keys,- // display mode (a desktop's window), controller buttons+ // display mode (a desktop's window), controller buttons, gyro aiming// The countries "Sign in as another country" offers (xcloud::loginCountryAddress).constexpr const char* kLoginCountries[] = {"br", "jp", "kr", "pl", "us"};diff --git a/tests/test_main.cpp b/tests/test_main.cppindex 60d7617..5a38603 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -1286,8 +1286,8 @@ static void testVisibleSettingsRows() {};const ui::UiCaps ps5;auto all = ui::visibleSettingsRows(ps5);- CHECK((ids(all) == std::vector<int>{0, 8, 1, 9, 10, 2, 11, 3, 4, 5, 6, 14, 12, 7}));- CHECK((groups(all) == std::vector<bool>{false, false, true, false, false, false, true, true, false, false, false, false, false, true}));+ CHECK((ids(all) == std::vector<int>{0, 8, 1, 9, 10, 2, 11, 3, 4, 5, 6, 15, 14, 12, 7}));+ CHECK((groups(all) == std::vector<bool>{false, false, true, false, false, false, true, true, false, false, false, false, false, false, true}));ui::UiCaps pc;pc.lightBar = pc.triggerRumble = pc.adaptiveTriggers = pc.gyro = pc.touchpad = false;pc.upscalers = pc.sharpen = pc.deband = pc.highRefresh = pc.console = pc.selfUpdate = false;@@ -1306,10 +1306,10 @@ static void testVisibleSettingsRows() {auto x = ids(ui::visibleSettingsRows(xbox));CHECK(std::find(x.begin(), x.end(), 4) != x.end() && std::find(x.begin(), x.end(), 6) == x.end());// A game's settings.- CHECK((ids(ui::visibleGameSettingsRows(ps5, true)) == std::vector<int>{0, 4, 8, 1, 2, 3, 5, 6, 7, 11, 9, 10}));+ CHECK((ids(ui::visibleGameSettingsRows(ps5, true)) == std::vector<int>{0, 4, 8, 1, 2, 3, 5, 6, 7, 12, 11, 9, 10}));CHECK((groups(ui::visibleGameSettingsRows(ps5, true)) ==- std::vector<bool>{false, true, false, true, false, false, true, false, false, false, false, true}));- CHECK((ids(ui::visibleGameSettingsRows(ps5, false)) == std::vector<int>{0, 4, 8, 1, 2, 3, 5, 6, 7, 11, 9}));+ std::vector<bool>{false, true, false, true, false, false, true, false, false, false, false, false, true}));+ CHECK((ids(ui::visibleGameSettingsRows(ps5, false)) == std::vector<int>{0, 4, 8, 1, 2, 3, 5, 6, 7, 12, 11, 9}));auto game = ui::visibleGameSettingsRows(pc, false);CHECK((ids(game) == std::vector<int>{0, 4, 5, 7, 11, 9}));CHECK((groups(game) == std::vector<bool>{false, true, true, false, false, false}));