Xbox Cloud Gaming app for PS5 Homebrew
C
WIP: hints follow the device last used (keys for the keyboard); F12 / swipe down toggle the in-game menu; Home the Xbox button
Rafael Abud Ferreira46f3a7279896
diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cppindex 2729fb1..18f1276 100644--- a/src/app/autoplay.cpp+++ b/src/app/autoplay.cpp@@ -2,6 +2,7 @@// Copyright (C) 2026 RafaelNGP// Unattended test mode (tools/ps5/autotest.sh); see autoplay.h.#include "app/autoplay.h"+#include "ui/input_mode.h"#include "app/ps5_app.h"#include "display/display.h"@@ -63,6 +64,7 @@ void loadAutoplay() {if (opt == "cpudisplay") g_autoplay.cpuDisplay = true;if (opt == "hwdecode") g_autoplay.hwDecode = true;if (opt == "droptest") g_autoplay.dropTest = true;+ if (opt == "kbhints") ui::g_keyboardHints = true; // the hints as with a keyboard (screenshots)if (opt.rfind("loss=", 0) == 0) g_autoplay.videoLoss = std::atoi(opt.c_str() + 5);if (opt == "ai") g_autoplay.upscaler = 1;if (opt == "restore") g_autoplay.restore = true;diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex b1d42e3..0e8e0de 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -17,6 +17,7 @@#include "input/controller.h"#include "input/kbm.h"#include "input/keyboard_nav.h"+#include "ui/input_mode.h"#include "input/tuning.h"#include "net/http.h"#include "platform/platform.h"@@ -274,7 +275,8 @@ int main(int argc, char** argv) {// Never return from main: the app is closed from the home screen.input::ControllerState prev{}, pad{};- bool appMenuKeyBefore = false; // F12 held at the last pass+ bool appMenuKeyBefore = false, homeKeyBefore = false; // F12 / Home held at the last pass+ auto now0 = [] { return platform::nowMs(); };Repeater up, down, left, right, dpadLeft, dpadRight;// Smooth scrolling: rows / cards still to move (fractions carry over),// the touchpad's last point, and its speed for the glide after release.@@ -341,6 +343,27 @@ int main(int argc, char** argv) {// controller; in a game otherwise, its keys and the mouse go to the game.input::KbmInput kbm = input::kbmPoll();bool inGame = g_ui->screen() == ui::Screen::Streaming;+ {+ // The hints follow the device last used: a key or the mouse+ // switches them to the keyboard's keys, the controller back.+ bool keyPressed = std::any_of(kbm.keys.begin(), kbm.keys.end(), [](const input::KeyEvent& k) { return k.pressed; });+ bool padUsed = pad.btnA || pad.btnB || pad.btnX || pad.btnY || pad.dpadUp || pad.dpadDown || pad.dpadLeft ||+ pad.dpadRight || pad.btnL1 || pad.btnR1 || pad.btnOptions || pad.btnTouchpad ||+ std::abs(pad.leftStickX) > 0.5f || std::abs(pad.leftStickY) > 0.5f ||+ std::abs(pad.rightStickX) > 0.5f || std::abs(pad.rightStickY) > 0.5f;+ bool keyboard = ui::g_keyboardHints;+ if (keyPressed || kbm.moved) keyboard = true;+ else if (padUsed) keyboard = false;+ if (keyboard != ui::g_keyboardHints) {+ ui::g_keyboardHints = keyboard;+ g_ui->invalidate();+ streamScreen.redrawMenu();+ }+ }+ // Home: the Xbox button in a game (as the touchpad swiped up).+ bool homeKey = std::binary_search(kbm.held.begin(), kbm.held.end(), uint8_t{0x24});+ if (inGame && homeKey && !homeKeyBefore && !streamScreen.menuOpen()) g_xboxButtonUntil = now0() + 250;+ homeKeyBefore = homeKey;bool appMenuKey = std::binary_search(kbm.held.begin(), kbm.held.end(), input::kVkAppMenu);bool appMenuPressed = appMenuKey && !appMenuKeyBefore;appMenuKeyBefore = appMenuKey;diff --git a/src/app/stream_screen.cpp b/src/app/stream_screen.cppindex 7649da1..15e55b2 100644--- a/src/app/stream_screen.cpp+++ b/src/app/stream_screen.cpp@@ -154,6 +154,12 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bmenu_.open(streamResolution_, showStats_, sharpness_, deband_, upscaler_, g_playingHome, allow1440,hasCustomProfile_, triggerStrength_, deadzone_, circleConfirms_, micLvl, micMuted);overlaySeq_ = 0;+ } else if (wasOpen && (menuCombo || swipeMenu_)) {+ // The same gesture or key closes it again.+ swipeMenu_ = false;+ menu_.close();+ overlaySeq_ = 0;+ g_player->requestKeyframe();} else if (wasOpen) {switch (menu_.handle(nav)) {case ui::MenuAction::Leave: g_cancel = true; break;@@ -318,12 +324,12 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bif (!padReleased_ || menuCombo) sent = input::ControllerState{};// Swiping up or right on the touchpad is the Xbox button (once// per swipe; the games never see the touchpad's touches).- if (pad.touching && !menu_.isOpen() && g_keyboardFor.empty()) {+ if (pad.touching && g_keyboardFor.empty()) {if (!swipe_.active) swipe_ = {true, false, pad.touchX, pad.touchY};float dx = pad.touchX - swipe_.x, dy = swipe_.y - pad.touchY; // dy > 0: upbool right = dx > 0.30f && std::abs(dy) < 0.30f, up = dy > 0.40f && std::abs(dx) < 0.30f;bool left = dx < -0.30f && std::abs(dy) < 0.30f, down = dy < -0.40f && std::abs(dx) < 0.30f;- if (!swipe_.fired && (right || up)) {+ if (!swipe_.fired && (right || up) && !menu_.isOpen()) {swipe_.fired = true;g_xboxButtonUntil = platform::nowMs() + 250;XC_LOGI("touchpad swipe_ %s: Xbox button", right ? "right" : "up");@@ -342,7 +348,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bif (!menu_.isOpen()) {input::KbmInput toGame = kbm_;toGame.keys.erase(std::remove_if(toGame.keys.begin(), toGame.keys.end(),- [](const input::KeyEvent& k) { return k.vk == input::kVkAppMenu; }),+ [](const input::KeyEvent& k) { return k.vk == input::kVkAppMenu || k.vk == 0x24; }),toGame.keys.end());for (const auto& k : toGame.keys) {auto at = std::find(keysInGame_.begin(), keysInGame_.end(), k.vk);@@ -426,6 +432,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b}bool StreamScreen::menuOpen() const { return menu_.isOpen(); }+void StreamScreen::redrawMenu() { overlaySeq_ = 0; }void StreamScreen::idle() {keysInGame_.clear();diff --git a/src/app/stream_screen.h b/src/app/stream_screen.hindex b21d53d..df52862 100644--- a/src/app/stream_screen.h+++ b/src/app/stream_screen.h@@ -32,6 +32,8 @@ public:// is closed (update() sends them).void setKbm(input::KbmInput kbm) { kbm_ = std::move(kbm); }bool menuOpen() const;+ // The hints changed device (keyboard / controller): the overlay again.+ void redrawMenu();// Each pass on any other screen: what the stream left is cleared, and a// console keyboard still up is closed.void idle();diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex 4e2f8d1..ef006fb 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-3.0-or-later// Copyright (C) 2026 RafaelNGP#include "ui/app_ui.h"+#include "ui/input_mode.h"#include "input/tuning.h"#include "xcloud/catalog.h"@@ -2302,11 +2303,21 @@ void AppUi::drawHints(Canvas& c, const std::vector<std::pair<int, const char*>>&// With Circle confirming, the pad reports it as Cross (and the// other way round): the hints show the button to press.int icon = it->first;- if (circleConfirms_ && (icon == kIconCross || icon == kIconCircle))- icon = icon == kIconCross ? kIconCircle : kIconCross;int w = fonts_.semibold.measure(it->second, kPx);x -= w;fonts_.semibold.draw(c, it->second, x, y, kPx, kGray);+ if (g_keyboardHints) { // the keyboard's key, as a key cap+ const char* key = keyLabel(icon);+ int kw = fonts_.bold.measure(key, 15) + 18;+ Rect cap{x - 10 - kw, y + 1, kw, 26};+ c.fillRect(cap, rgba(255, 255, 255, 30), 6);+ c.strokeRect(cap, kGray, 2, 6);+ fonts_.bold.draw(c, key, cap.x + 9, fonts_.bold.centeredY(cap.y, cap.h, 15), 15, kWhite);+ x = cap.x - kGap;+ continue;+ }+ if (circleConfirms_ && (icon == kIconCross || icon == kIconCircle))+ icon = icon == kIconCross ? kIconCircle : kIconCross;x -= 10 + 2 * kR;float cx = x + kR, cy = y + 13;if (icon == kIconL2R2) {@@ -2462,7 +2473,7 @@ void AppUi::drawTabs(Canvas& c) {c.fillRect(r, rgba(255, 255, 255, 40), 8);fonts_.bold.draw(c, name, cx - fonts_.bold.measure(name, 16) / 2, fonts_.bold.centeredY(r.y, r.h, 16), 16, kGray);};- shoulder("L1", x - 40);+ shoulder(g_keyboardHints ? "Q" : "L1", x - 40);for (int i = 0; i < 3; ++i) {bool on = static_cast<int>(tab_) == i;Rect r{x, kY, widths[i], kH};@@ -2470,7 +2481,7 @@ void AppUi::drawTabs(Canvas& c) {fonts_.semibold.draw(c, labels[i], x + kPad, fonts_.semibold.centeredY(kY, kH, kPx), kPx, on ? kBg : kGray);x += widths[i] + kGap;}- shoulder("R1", x - kGap + 40);+ shoulder(g_keyboardHints ? "E" : "R1", x - kGap + 40);}namespace {diff --git a/src/ui/input_mode.h b/src/ui/input_mode.hnew file mode 100644index 0000000..6dab755--- /dev/null+++ b/src/ui/input_mode.h@@ -0,0 +1,21 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+// Which device the button hints show: the controller's glyphs, or the+// keyboard's keys once a keyboard (or mouse) is used, until the controller+// is used again.+#pragma once++#include <atomic>++namespace xc::ui {++inline std::atomic<bool> g_keyboardHints{false};++// The key each controller glyph stands for, as the hints show it.+inline const char* keyLabel(int icon) {+ // As app_ui.cpp's Icon: Cross, Circle, Options, Triangle, Touchpad, Square, R3, L2 R2.+ static const char* const kLabels[] = {"Enter", "Esc", "Tab", "F", "Del", "H", "R", "Z C"};+ return icon >= 0 && icon < 8 ? kLabels[icon] : "";+}++} // namespace xc::uidiff --git a/src/ui/stream_menu.cpp b/src/ui/stream_menu.cppindex 5279053..dce69b0 100644--- a/src/ui/stream_menu.cpp+++ b/src/ui/stream_menu.cpp@@ -3,6 +3,7 @@#include "ui/stream_menu.h"#include "ui/strings.h"+#include "ui/input_mode.h"#include <algorithm>#include <cstdio>@@ -299,7 +300,7 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {int hy = kMenuH - 50, x = kPad;{// The touchpad's gestures, small, above the button hints.- auto lines = fonts_.regular.wrap(tr(Str::MenuGestureHint), 16, kMenuW - 2 * kPad, 2);+ auto lines = fonts_.regular.wrap(tr(g_keyboardHints ? Str::MenuKeyHint : Str::MenuGestureHint), 16, kMenuW - 2 * kPad, 2);int gy = hy - 14 - static_cast<int>(lines.size()) * 22;for (const auto& l : lines) {fonts_.regular.draw(c, l, kPad, gy, 16, kDim);@@ -315,6 +316,20 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {c.strokeArc(x + 13, hy + 12, 6.0f, 2.5f, 0, 6.2832f, rgba(255, 102, 102));}};+ if (g_keyboardHints) { // Enter / Esc as key caps+ auto cap = [&](const char* key) {+ int kw = fonts_.bold.measure(key, 15) + 18;+ c.fillRect({x, hy, kw, 26}, rgba(255, 255, 255, 30), 6);+ c.strokeRect({x, hy, kw, 26}, kGray, 2, 6);+ fonts_.bold.draw(c, key, x + 9, fonts_.bold.centeredY(hy, 26, 15), 15, kWhite);+ return kw;+ };+ int kw = cap("Enter");+ x = fonts_.semibold.draw(c, tr(Str::Select), x + kw + 8, hy, 20, kGray) + 32;+ kw = cap("Esc");+ fonts_.semibold.draw(c, tr(Str::Back), x + kw + 8, hy, 20, kGray);+ return c;+ }icon(!circleConfirms_);x = fonts_.semibold.draw(c, tr(Str::Select), x + 34, hy, 20, kGray) + 32;icon(circleConfirms_);diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex cd512c6..eb3b474 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -269,6 +269,7 @@ constexpr Column kEnglish = {"Maximum bitrate", // BitrateCap"Automatic", // BitrateAuto"Game volume", // GameVolume+ "Keyboard: F12 this menu · Home Xbox button", // MenuKeyHint};constexpr Column kPortugueseBR = {@@ -508,6 +509,7 @@ constexpr Column kPortugueseBR = {"Bitrate máximo", // BitrateCap"Automático", // BitrateAuto"Volume do jogo", // GameVolume+ "Teclado: F12 este menu · Home botão Xbox", // MenuKeyHint};constexpr Column kSpanish = {@@ -747,6 +749,7 @@ constexpr Column kSpanish = {"Bitrate máximo", // BitrateCap"Automático", // BitrateAuto"Volumen del juego", // GameVolume+ "Teclado: F12 este menú · Inicio botón Xbox", // MenuKeyHint};constexpr Column kFrench = {@@ -986,6 +989,7 @@ constexpr Column kFrench = {"Débit maximal", // BitrateCap"Automatique", // BitrateAuto"Volume du jeu", // GameVolume+ "Clavier : F12 ce menu · Origine bouton Xbox", // MenuKeyHint};constexpr Column kGerman = {@@ -1225,6 +1229,7 @@ constexpr Column kGerman = {"Maximale Bitrate", // BitrateCap"Automatisch", // BitrateAuto"Spiellautstärke", // GameVolume+ "Tastatur: F12 dieses Menü · Pos1 Xbox-Taste", // MenuKeyHint};constexpr Column kItalian = {@@ -1464,6 +1469,7 @@ constexpr Column kItalian = {"Bitrate massimo", // BitrateCap"Automatico", // BitrateAuto"Volume del gioco", // GameVolume+ "Tastiera: F12 questo menu · Home pulsante Xbox", // MenuKeyHint};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex 862d352..1c15ace 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -246,6 +246,7 @@ enum class Str {BitrateCap, // Settings row: the stream's bitrate cap (for Wi-Fi)BitrateAuto, // ... its default: the resolution's ownGameVolume, // Settings row: the game's sound level+ MenuKeyHint, // in-game menu, keyboard in use: its keys (F12 the menu, Home the Xbox button)Count};