Xbox Cloud Gaming app for PS5 Homebrew
C
fix(mouse): add vector cursor and full mouse navigation on PS5
Rafael Abud Ferreirad1431a2cb24f
diff --git a/src/app/app_core.cpp b/src/app/app_core.cppindex e4ab895..f0bc341 100644--- a/src/app/app_core.cpp+++ b/src/app/app_core.cpp@@ -943,6 +943,32 @@ bool Core::frame() {if (k.pressed) g_ui->captureKey(k.vk), swallowedKeys.push_back(k.vk);for (int b = 0; b < 5; ++b)if ((kbm.buttons & ~mouseButtonsBefore) & (1 << b)) g_ui->captureKey(static_cast<uint8_t>(input::kMouseLeft + b));+ } else if (!inGame || streamScreen->menuOpen()) {+ static float s_mouseCursorX = 960.0f;+ static float s_mouseCursorY = 540.0f;+ if (kbm.dx != 0 || kbm.dy != 0) {+ s_mouseCursorX = std::clamp(s_mouseCursorX + static_cast<float>(kbm.dx), 0.0f, 1920.0f);+ s_mouseCursorY = std::clamp(s_mouseCursorY + static_cast<float>(kbm.dy), 0.0f, 1080.0f);+ ui::UiEvent mev = g_ui->onMouseMove(s_mouseCursorX, s_mouseCursorY);+ if (mev.action != ui::Action::None) dispatchUiAction(mev);+ }+ uint8_t pressedButtons = kbm.buttons & ~mouseButtonsBefore;+ if (pressedButtons & 1) { // Left click+ ui::UiEvent mev = g_ui->onMouseDown(s_mouseCursorX, s_mouseCursorY, 1);+ if (mev.action != ui::Action::None) dispatchUiAction(mev);+ }+ if (pressedButtons & 2) { // Right click+ ui::UiEvent mev = g_ui->onMouseDown(s_mouseCursorX, s_mouseCursorY, 3);+ if (mev.action != ui::Action::None) dispatchUiAction(mev);+ }+ if (pressedButtons & 4) { // Middle click+ ui::UiEvent mev = g_ui->onMouseDown(s_mouseCursorX, s_mouseCursorY, 2);+ if (mev.action != ui::Action::None) dispatchUiAction(mev);+ }+ if (kbm.wheel != 0) {+ ui::UiEvent mev = g_ui->onMouseWheel(0.0f, static_cast<float>(kbm.wheel));+ if (mev.action != ui::Action::None) dispatchUiAction(mev);+ }}mouseButtonsBefore = kbm.buttons;std::erase_if(swallowedKeys, [&](uint8_t vk) { return !std::binary_search(kbm.held.begin(), kbm.held.end(), vk); });diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cppindex 9916d45..77b7d4f 100644--- a/src/app/autoplay.cpp+++ b/src/app/autoplay.cpp@@ -129,6 +129,7 @@ void loadAutoplay() {if (opt == "badca") g_autoplay.badCa = true;if (opt == "consolesempty") g_autoplay.consolesTab = g_autoplay.consolesEmpty = true;if (opt == "librarytest") g_autoplay.libraryTest = true;+ if (opt == "mousetest") g_autoplay.mouseTest = true;if (opt == "block1test") g_autoplay.block1Test = true;if (opt == "block2test") g_autoplay.block2Test = true;if (opt == "block3test") g_autoplay.block3Test = true;@@ -965,6 +966,20 @@ void autoplayScreens(const ui::Canvas& canvas, uint64_t now) {XC_LOGI("AUTOPLAY END: library test");}}+ if (g_autoplay.mouseTest && uiSaved) {+ static uint64_t mouseSince = 0;+ static int saved = 0;+ if (!mouseSince) {+ g_ui->setMouseCursor(700.0f, 450.0f, true);+ g_ui->onMouseMove(700.0f, 450.0f);+ mouseSince = now;+ } else if (saved == 0 && now - mouseSince > 2000) {+ saveCanvas("mouse.ppm");+ saved = 1;+ g_autoplay.mouseTest = false;+ XC_LOGI("AUTOPLAY END: mouse test");+ }+ }if (g_autoplay.vibeTest) {// 10 s to pick the pad up, then each motor alone for 6 s, 3 s apart.static uint64_t since = 0;diff --git a/src/app/autoplay.h b/src/app/autoplay.hindex 7c826c4..84b2154 100644--- a/src/app/autoplay.h+++ b/src/app/autoplay.h@@ -53,6 +53,7 @@ struct Autoplay {bool bitrateTest = false; // "bitratetest": open settings, focus Bitrate row, test slider, save settings_bitrate_caps.ppmbool detailTest = false; // open a game to buy far down the list, save its pagebool libraryTest = false; // open "Your games", save it at 4 s and 25 s+ bool mouseTest = false; // "mousetest": move mouse cursor and save mouse.ppmbool mw4Test = false; // "mw4test": search and open details for Call of Duty MW4bool v150Test = false; // "v150test": verify new settings order and search gratis filterbool claimTest = false; // "claimtest": test free game acquisition, library persistence, and game launchdiff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex e6a52b7..0ee7fcf 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -3270,10 +3270,26 @@ void AppUi::handleGameSettings(const NavInput& in, UiEvent& ev) {}}+void AppUi::setMouseCursor(float x, float y, bool visible) {+ std::lock_guard<std::mutex> lock(mutex_);+ mouseCursorX_ = std::clamp(x, 0.0f, 1919.0f);+ mouseCursorY_ = std::clamp(y, 0.0f, 1079.0f);+ mouseCursorVisible_ = visible;+ if (visible) {+ mouseCursorVisibleUntil_ = platform::nowMs() + 3000;+ }+ dirty_ = true;+}+UiEvent AppUi::onMouseMove(float x, float y) {std::lock_guard<std::mutex> lock(mutex_);UiEvent ev;- if (!caps_.desktopWindow || screen_ == Screen::Streaming || screen_ == Screen::Splash) {+ mouseCursorX_ = std::clamp(x, 0.0f, 1919.0f);+ mouseCursorY_ = std::clamp(y, 0.0f, 1079.0f);+ mouseCursorVisible_ = true;+ mouseCursorVisibleUntil_ = platform::nowMs() + 3000;+ dirty_ = true;+ if (screen_ == Screen::Streaming || screen_ == Screen::Splash) {return ev;}if (screen_ == Screen::Home) {@@ -3396,7 +3412,12 @@ UiEvent AppUi::onMouseMove(float x, float y) {UiEvent AppUi::onMouseDown(float x, float y, int button) {std::lock_guard<std::mutex> lock(mutex_);UiEvent ev;- if (!caps_.desktopWindow || screen_ == Screen::Streaming || screen_ == Screen::Splash) {+ mouseCursorX_ = std::clamp(x, 0.0f, 1919.0f);+ mouseCursorY_ = std::clamp(y, 0.0f, 1079.0f);+ mouseCursorVisible_ = true;+ mouseCursorVisibleUntil_ = platform::nowMs() + 3000;+ dirty_ = true;+ if (screen_ == Screen::Streaming || screen_ == Screen::Splash) {return ev;}if (button == 3) {@@ -3675,7 +3696,10 @@ UiEvent AppUi::onMouseDown(float x, float y, int button) {UiEvent AppUi::onMouseWheel(float dx, float dy) {std::lock_guard<std::mutex> lock(mutex_);UiEvent ev;- if (!caps_.desktopWindow || screen_ == Screen::Streaming || screen_ == Screen::Splash) {+ mouseCursorVisible_ = true;+ mouseCursorVisibleUntil_ = platform::nowMs() + 3000;+ dirty_ = true;+ if (screen_ == Screen::Streaming || screen_ == Screen::Splash) {return ev;}if (screen_ == Screen::Home) {@@ -4157,6 +4181,7 @@ bool AppUi::needsRedraw(uint64_t nowMs) const {std::lock_guard<std::mutex> lock(mutex_);if (screen_ == Screen::Streaming) return false;if (dirty_ || animating_) return true;+ if (mouseCursorVisible_ && nowMs >= mouseCursorVisibleUntil_) return true;// A desktop's toast came or went (the PS5 sends system notifications).if (platform::toastsEnabled() && platform::toasts().version(nowMs) != toastsDrawn_) return true;// Spinners keep moving (about 30 fps is enough).@@ -6994,6 +7019,64 @@ void AppUi::render(Canvas& c, uint64_t nowMs) {toastsDrawn_ = platform::toasts().version(nowMs);drawToasts(c, fonts_, platform::toasts().visible(nowMs), kW - kMargin, 132);}+ if (mouseCursorVisible_ && nowMs >= mouseCursorVisibleUntil_) {+ mouseCursorVisible_ = false;+ }+ if (mouseCursorVisible_ && screen_ != Screen::Streaming && screen_ != Screen::Splash) {+ drawMouseCursor(c, mouseCursorX_, mouseCursorY_);+ }+}++static const char* const kCursorRows[23] = {+ "#...............",+ "##..............",+ "#W#.............",+ "#WW#............",+ "#WWW#...........",+ "#WWWW#..........",+ "#WWWWW#.........",+ "#WWWWWW#........",+ "#WWWWWWW#.......",+ "#WWWWWWWW#......",+ "#WWWWWWWWW#.....",+ "#WWWWWWWWWW#....",+ "#WWWWWWWWWWW#...",+ "#WWWWWW######...",+ "#WWWW##WW#......",+ "#WW##.#WW#......",+ "#W#...#WW#......",+ "##.....#WW#.....",+ "#......#WW#.....",+ "........#WW#....",+ "........#WW#....",+ ".........#WW#...",+ ".........####..."+};++void AppUi::drawMouseCursor(Canvas& c, float cursorX, float cursorY) {+ static bool s_inited = false;+ static uint8_t s_outline[23 * 16];+ static uint8_t s_fill[23 * 16];+ static uint8_t s_shadow[23 * 16];+ if (!s_inited) {+ s_inited = true;+ for (int y = 0; y < 23; ++y) {+ for (int x = 0; x < 16; ++x) {+ char ch = kCursorRows[y][x];+ s_shadow[y * 16 + x] = (ch == '#' || ch == 'W') ? 255 : 0;+ s_outline[y * 16 + x] = (ch == '#') ? 255 : 0;+ s_fill[y * 16 + x] = (ch == 'W') ? 255 : 0;+ }+ }+ }+ int ix = static_cast<int>(std::round(cursorX));+ int iy = static_cast<int>(std::round(cursorY));+ // Sombra sutil+ c.drawMask(s_shadow, 16, 23, 16, ix + 2, iy + 2, rgba(0, 0, 0, 80));+ // Borda preta fina+ c.drawMask(s_outline, 16, 23, 16, ix, iy, rgba(0, 0, 0, 240));+ // Seta branca nítida+ c.drawMask(s_fill, 16, 23, 16, ix, iy, rgba(255, 255, 255, 255));}} // namespace xc::uidiff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex 851fa50..1f84a14 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -475,6 +475,10 @@ public:UiEvent onMouseMove(float x, float y);UiEvent onMouseDown(float x, float y, int button);UiEvent onMouseWheel(float dx, float dy);+ float mouseCursorX() const { return mouseCursorX_; }+ float mouseCursorY() const { return mouseCursorY_; }+ bool mouseCursorVisible() const { return mouseCursorVisible_; }+ void setMouseCursor(float x, float y, bool visible = true);// The keyboard keys' screen waits for a key: the main loop gives it the// next key or mouse button pressed (input::kMouseLeft..) instead of// moving through the screens with it.@@ -789,6 +793,11 @@ private:int achScroll_ = 0;int detailButtonFocus_ = 0; // 0 = Play / Claim, 1 = Achievementsstd::string webUrl_;+ float mouseCursorX_ = 960.0f;+ float mouseCursorY_ = 540.0f;+ bool mouseCursorVisible_ = false;+ uint64_t mouseCursorVisibleUntil_ = 0;+ void drawMouseCursor(Canvas& c, float cursorX, float cursorY);};} // namespace xc::uidiff --git a/tests/test_main.cpp b/tests/test_main.cppindex 0e27d58..738ff0d 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -3977,14 +3977,26 @@ static void testDesktopMouseNav() {uiApp.setRows({row});uiApp.showHome();- // 1. In default PS5 mode (caps_.desktopWindow == false), mouse events must be ignored+ // 1. Mouse cursor state, initial position, and clamping+ CHECK(uiApp.mouseCursorX() == 960.0f);+ CHECK(uiApp.mouseCursorY() == 540.0f);+ CHECK(!uiApp.mouseCursorVisible());+{auto evMove = uiApp.onMouseMove(300.0f, 300.0f);CHECK(evMove.action == ui::Action::None);+ CHECK(uiApp.mouseCursorX() == 300.0f);+ CHECK(uiApp.mouseCursorY() == 300.0f);+ CHECK(uiApp.mouseCursorVisible());+auto evClick = uiApp.onMouseDown(300.0f, 300.0f, 1);CHECK(evClick.action == ui::Action::None);auto evWheel = uiApp.onMouseWheel(0.0f, 1.0f);CHECK(evWheel.action == ui::Action::None);++ uiApp.setMouseCursor(2500.0f, -100.0f);+ CHECK(uiApp.mouseCursorX() == 1919.0f);+ CHECK(uiApp.mouseCursorY() == 0.0f);}// 2. Enable desktopWindow capability (Desktop / Steam Deck mode)diff --git a/tools/ps5/autotest.sh b/tools/ps5/autotest.shindex 99b03f8..b48915f 100755--- a/tools/ps5/autotest.sh+++ b/tools/ps5/autotest.sh@@ -39,7 +39,7 @@ host, port, d, line = sys.argv[1], int(sys.argv[2]), sys.argv[3], sys.argv[4]f = FTP(); f.connect(host, port, timeout=15); f.login()try: f.cwd(d)except error_perm: f.mkd(d); f.cwd(d) # the app makes it on its first start-for name in ("xcloud.log", "frame.ppm", "frame2.ppm", "stream.aus", "ui.ppm", "launch.ppm", "screen.ppm", "detail.ppm", "library.ppm", "library2.ppm", "error.ppm", "consoles.ppm", "settings.ppm"):+for name in ("xcloud.log", "frame.ppm", "frame2.ppm", "stream.aus", "ui.ppm", "mouse.ppm", "launch.ppm", "screen.ppm", "detail.ppm", "library.ppm", "library2.ppm", "error.ppm", "consoles.ppm", "settings.ppm"):try: f.sendcmd(f"DELE {name}")except (error_perm, error_reply): passf.storbinary("STOR autoplay.txt", io.BytesIO(line.encode() + b"\n"))@@ -84,7 +84,7 @@ PYif [[ $status != *"$title_id"* ]]; then result=crashed; break; fifidone-fetch xcloud.log frame.ppm frame2.ppm stream.aus ui.ppm launch.ppm screen.ppm detail.ppm library.ppm library2.ppm error.ppm consoles.ppm settings.ppm || true+fetch xcloud.log frame.ppm frame2.ppm stream.aus ui.ppm mouse.ppm launch.ppm screen.ppm detail.ppm library.ppm library2.ppm error.ppm consoles.ppm settings.ppm || truectl kill "$title_id" >/dev/null 2>&1 || true# Remove the request so a manual launch behaves normally.python3 - "$PS5_HOST" "${FTP_PORT:-2121}" "/data/psbox" <<'PY'