Xbox Cloud Gaming app for PS5 Homebrew
C
Controllers in use: numbered pads on the home screen and in the game menu
Rafael Abud Ferreira5aca22131749
diff --git a/CMakeLists.txt b/CMakeLists.txtindex a516e16..2099914 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -64,6 +64,7 @@ add_library(xcloud_ui STATICsrc/ui/image_cache.cppsrc/ui/app_ui.cppsrc/ui/stream_menu.cpp+ src/ui/pad_icons.cppsrc/ui/brand.cppsrc/app/library.cppsrc/app/settings.cppdiff --git a/src/app/cli_main.cpp b/src/app/cli_main.cppindex 1fa0953..7c8aeec 100644--- a/src/app/cli_main.cpp+++ b/src/app/cli_main.cpp@@ -596,6 +596,12 @@ int main(int argc, char** argv) {ui::Fonts fonts;if (!fonts.load("assets/fonts")) return 1;ui::StreamMenu menu(fonts);+ {+ ui::PadSlots pads{};+ pads[0] = {true, "RafaelNGP"};+ pads[1] = {true, "A very long PS5 user name"};+ menu.setPads(pads);+ }ui::StreamInfo info;info.region = "Brazil South";info.rttMs = 23;@@ -645,6 +651,12 @@ int main(int argc, char** argv) {if (!fonts.load("assets/fonts")) return 1;ui::ImageCache images([] {});ui::AppUi app(fonts, images);+ {+ ui::PadSlots pads{};+ pads[0] = {true, "RafaelNGP"};+ pads[1] = {true, "Player 2"};+ app.setPads(pads);+ }ui::Canvas canvas(1920, 1080);std::vector<ui::GameTile> owned, buy;const char* platforms[] = {"XS", "ONE", "360"};diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex a2e3ac0..c3eba42 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -781,7 +781,8 @@ int main(int argc, char** argv) {static constexpr int kSharpAmount[] = {0, 96, 176, 256};bool padReleased = true;bool padAttached[input::kMaxPads] = {}; // controllers 1..3 announced to the stream- uint64_t padsCheckedAt = 0; // false from the menu/keyboard until the buttons are let go+ uint64_t padsCheckedAt = 0;+ unsigned padChecks = 0; // false from the menu/keyboard until the buttons are let gouint32_t overlaySeq = 0; // g_infoSeq + 1 when drawn; 0 = redrawuint64_t homeSince = 0, launchSince = 0;bool uiSaved = false, launchSaved = false;@@ -790,9 +791,20 @@ int main(int argc, char** argv) {// Autoplay runs unattended: the physical pad must not interfere.if (!g_autoplayTitle.empty()) pad = input::ControllerState{};uint64_t now = platform::nowMs();- if (now - padsCheckedAt >= 1000) { // other players signing in or out+ if (now - padsCheckedAt >= 500) { // other players signing in or outpadsCheckedAt = now;- input::refreshPads();+ if (++padChecks % 2 == 0) input::refreshPads();+ // Off the stream nobody reads pads 1..3: poll them for their state.+ if (g_ui->screen() != ui::Screen::Streaming) {+ input::ControllerState ignored;+ for (int i = 1; i < input::kMaxPads; ++i) input::pollPad(i, ignored);+ }+ ui::PadSlots slots;+ for (int i = 0; i < input::kMaxPads; ++i)+ slots[static_cast<size_t>(i)] = {input::padConnected(i), input::padUserName(i)};+ g_ui->setPads(slots);+ menu.setPads(slots);+ if (menu.isOpen()) overlaySeq = 0;}if (!g_keyboardFor.empty() && g_ui->screen() != ui::Screen::Streaming) updateTextInput(nullptr);@@ -901,6 +913,10 @@ int main(int argc, char** argv) {if (on != padAttached[i]) {padAttached[i] = on;g_player->setPadConnected(i, on);+ std::string who = std::to_string(i + 1);+ std::string name = input::padUserName(i);+ if (!name.empty()) who += " (" + name + ")";+ platform::notify(ui::trf(on ? ui::Str::PadConnected : ui::Str::PadDisconnected, who));}if (on) g_player->sendInput(other, i);}diff --git a/src/input/controller.cpp b/src/input/controller.cppindex 152a6be..b1eca57 100644--- a/src/input/controller.cpp+++ b/src/input/controller.cpp@@ -64,6 +64,7 @@ struct SceUserServiceLoginUserIdList {int sceUserServiceInitialize(const SceUserServiceInitializeParams* param);int sceUserServiceGetInitialUser(int32_t* userId);int sceUserServiceGetLoginUserIdList(SceUserServiceLoginUserIdList* list);+int sceUserServiceGetUserName(int32_t userId, char* name, size_t size);int scePadInit(void);int scePadOpen(int32_t userId, int32_t type, int32_t index, const void* param);int scePadClose(int32_t handle);@@ -134,6 +135,8 @@ struct Rumble {struct Pad {int32_t userId = -1;int32_t handle = -1;+ std::atomic<bool> connected{false}; // the last poll's answer+ char name[32] = {}; // the user's, read when openedRumble motors, triggers;};Pad g_pads[kMaxPads];@@ -163,6 +166,7 @@ bool openPad(Pad& pad, int32_t userId, int slot) {int mode = scePadSetVibrationMode(h, 2);pad.userId = userId;pad.handle = h;+ if (sceUserServiceGetUserName(userId, pad.name, sizeof pad.name) != 0) pad.name[0] = 0;pad.motors.applied = pad.triggers.applied = 0;XC_LOGI("pad %d opened (handle %d, user %d, rumble mode 0x%08x)", slot, h, userId, static_cast<unsigned>(mode));return true;@@ -179,6 +183,8 @@ void closePad(Pad& pad, int slot) {XC_LOGI("pad %d closed (user %d)", slot, pad.userId);pad.handle = -1;pad.userId = -1;+ pad.connected = false;+ pad.name[0] = 0;}void applyRumble(Pad& pad) {@@ -219,6 +225,13 @@ void setTriggerRumble(uint8_t left, uint8_t right, uint32_t durationMs, int pad)void setCircleConfirms(bool on) { g_circleConfirms = on; }+bool padConnected(int index) { return index >= 0 && index < kMaxPads && g_pads[index].connected; }++std::string padUserName(int index) {+ // Main thread, like refreshPads() which changes it.+ return index >= 0 && index < kMaxPads && g_pads[index].handle >= 0 ? g_pads[index].name : "";+}+void setTriggerRumbleEnabled(bool on) {g_triggerRumble = on;if (!on)@@ -288,7 +301,8 @@ bool pollPad(int index, ControllerState& out) {applyRumble(slot);ScePadData pad{};int rc = scePadReadState(slot.handle, &pad);- if (rc != 0 || !pad.connected) return false;+ slot.connected = rc == 0 && pad.connected;+ if (!slot.connected) return false;out.connected = true;uint32_t b = pad.buttons;@@ -346,6 +360,8 @@ void setRumble(uint8_t, uint8_t, uint32_t, int) {}void setTriggerRumble(uint8_t, uint8_t, uint32_t, int) {}void setDeadzone(float) {}void setCircleConfirms(bool) {}+bool padConnected(int index) { return index == 0; }+std::string padUserName(int index) { return index == 0 ? "Player" : ""; }void setTriggerRumbleEnabled(bool) {}} // namespace xc::inputdiff --git a/src/input/controller.h b/src/input/controller.hindex 0952f7f..3b8e2cc 100644--- a/src/input/controller.h+++ b/src/input/controller.h@@ -3,6 +3,7 @@#pragma once#include <cstdint>+#include <string>namespace xc::input {@@ -52,6 +53,10 @@ bool poll(ControllerState& out);bool pollPad(int index, ControllerState& out);// Looks for users who signed in or out since (about once a second).void refreshPads();+// Whether the pad at `index` answered its last poll, and its user's name+// (empty when the slot is free).+bool padConnected(int index);+std::string padUserName(int index);// Rumble, 0..255 per motor (large = low frequency, small = high frequency),// for `durationMs` (0 = until changed). Any thread; polling applies it.void setRumble(uint8_t large, uint8_t small, uint32_t durationMs, int pad = 0);diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex 85da72e..666d8ea 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -631,6 +631,21 @@ void AppUi::setCircleConfirms(bool on) {dirty_ = true;}+void AppUi::setPads(const PadSlots& pads) {+ std::lock_guard<std::mutex> lock(mutex_);+ bool changed = false;+ for (size_t i = 0; i < pads.size(); ++i)+ changed |= pads[i].connected != pads_[i].connected || pads[i].name != pads_[i].name;+ if (!changed) return;+ pads_ = pads;+ dirty_ = true;+}++void AppUi::drawPads(Canvas& c) {+ // Bottom left, on the line of the button hints (which are right-aligned).+ drawPadRow(c, fonts_.bold, kMargin, kH - 70, 54, 14, pads_);+}+void AppUi::setRegions(std::vector<std::string> regions, const std::string& defaultRegion) {std::lock_guard<std::mutex> lock(mutex_);regions_ = std::move(regions);@@ -1451,6 +1466,7 @@ void AppUi::drawLibrary(Canvas& c, uint64_t nowMs) {{kIconR3, tr(Str::SortHint)},{kIconL2R2, tr(Str::Sections)},{kIconOptions, tr(Str::Settings)}});+ drawPads(c);drawToast(c, nowMs);}@@ -1594,6 +1610,7 @@ void AppUi::drawHome(Canvas& c, uint64_t nowMs) {{kIconTriangle, tr(Str::TabSearch)},{kIconOptions, tr(Str::Settings)},{kIconTouchpad, tr(Str::HoldSignOut)}});+ drawPads(c);drawToast(c, nowMs);}diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex b4e4a40..4c5bda2 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -11,6 +11,7 @@#include "ui/canvas.h"#include "ui/font.h"#include "ui/image_cache.h"+#include "ui/pad_icons.h"#include <cstdint>#include <map>@@ -147,6 +148,8 @@ public:// The confirm button in force (the hints show it); Settings may be// showing another choice not saved yet.void setCircleConfirms(bool on);+ // The controllers in use (bottom left of the home screen).+ void setPads(const PadSlots& pads);// Regions offered by the account's xCloud login; `defaultRegion` is the// one "Automatic" picks.void setRegions(std::vector<std::string> regions, const std::string& defaultRegion);@@ -176,6 +179,7 @@ private:void drawHints(Canvas& c, const std::vector<std::pair<int, const char*>>& hints);void drawSpinner(Canvas& c, float cx, float cy, float r, uint64_t nowMs);void drawToast(Canvas& c, uint64_t nowMs);+ void drawPads(Canvas& c);void drawSplash(Canvas& c, uint64_t nowMs);void drawSignIn(Canvas& c, uint64_t nowMs);void drawHome(Canvas& c, uint64_t nowMs);@@ -267,6 +271,7 @@ private:std::string error_;SettingsChoice settings_;bool circleConfirms_ = false;+ PadSlots pads_{};std::vector<std::string> regions_;std::string defaultRegion_;std::map<std::string, int> regionMs_;diff --git a/src/ui/pad_icons.cpp b/src/ui/pad_icons.cppnew file mode 100644index 0000000..0459eb6--- /dev/null+++ b/src/ui/pad_icons.cpp@@ -0,0 +1,37 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+#include "ui/pad_icons.h"++namespace xc::ui {++Color playerColor(int index) {+ switch (index) {+ case 0: return rgba(0, 112, 220);+ case 1: return rgba(220, 50, 50);+ case 2: return rgba(40, 170, 80);+ default: return rgba(225, 90, 175);+ }+}++void drawPadIcon(Canvas& c, const Font& font, int x, int y, int w, int index, bool connected) {+ int h = w * 2 / 3;+ // Opaque even when dim: overlapping translucent parts would show seams.+ Color body = connected ? playerColor(index) : rgba(52, 52, 52);+ // A rounded body with two grips hanging from its lower corners.+ int bodyH = h * 3 / 4;+ float gripR = w * 0.19f;+ c.fillCircle(x + w * 0.22f, y + h - gripR, gripR, body);+ c.fillCircle(x + w * 0.78f, y + h - gripR, gripR, body);+ c.fillRect({x, y, w, bodyH}, body, bodyH / 2);+ std::string n = std::to_string(index + 1);+ int px = bodyH * 9 / 10;+ font.draw(c, n, x + (w - font.measure(n, px)) / 2, font.centeredY(y, bodyH, px), px,+ connected ? rgba(255, 255, 255) : rgba(120, 120, 120));+}++int drawPadRow(Canvas& c, const Font& font, int x, int y, int w, int gap, const PadSlots& pads) {+ for (int i = 0; i < static_cast<int>(pads.size()); ++i) drawPadIcon(c, font, x + i * (w + gap), y, w, i, pads[i].connected);+ return static_cast<int>(pads.size()) * (w + gap) - gap;+}++} // namespace xc::uidiff --git a/src/ui/pad_icons.h b/src/ui/pad_icons.hnew file mode 100644index 0000000..61aebf6--- /dev/null+++ b/src/ui/pad_icons.h@@ -0,0 +1,31 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+// The controllers in use, as numbered pad glyphs (home screen, in-game menu).+#pragma once++#include "ui/canvas.h"+#include "ui/font.h"++#include <array>+#include <string>++namespace xc::ui {++struct PadSlot {+ bool connected = false;+ std::string name; // the PS5 user's+};+using PadSlots = std::array<PadSlot, 4>;++// Each player's colour, as the DualSense light bar shows it: blue, red,+// green, pink.+Color playerColor(int index);++// One pad, `w` wide and w * 2 / 3 high, numbered `index + 1`: in the+// player's colour when connected, dim when not.+void drawPadIcon(Canvas& c, const Font& font, int x, int y, int w, int index, bool connected);++// The four side by side, `gap` apart; returns the width taken.+int drawPadRow(Canvas& c, const Font& font, int x, int y, int w, int gap, const PadSlots& pads);++} // namespace xc::uidiff --git a/src/ui/stream_menu.cpp b/src/ui/stream_menu.cppindex 7f4bfea..9032f93 100644--- a/src/ui/stream_menu.cpp+++ b/src/ui/stream_menu.cpp@@ -136,6 +136,21 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {line(Str::StatLoss, fmt("%.1f %%", info.lossPct));line(Str::StatDecode, info.decodeMs > 0 ? fmt("%.1f ms", info.decodeMs) : none);+ // The controllers: numbered pads, each connected one with its user.+ y += 8;+ fonts_.regular.draw(c, tr(Str::Controllers), kPad, y, 22, kGray);+ y += 38;+ const int slotW = (kMenuW - 2 * kPad) / static_cast<int>(pads_.size());+ for (int i = 0; i < static_cast<int>(pads_.size()); ++i) {+ int sx = kPad + i * slotW;+ constexpr int kIconW = 60;+ drawPadIcon(c, fonts_.bold, sx + (slotW - kIconW) / 2, y, kIconW, i, pads_[i].connected);+ if (!pads_[i].connected || pads_[i].name.empty()) continue;+ auto name = fonts_.regular.wrap(pads_[i].name, 16, slotW - 8, 1);+ if (!name.empty())+ fonts_.regular.draw(c, name[0], sx + (slotW - fonts_.regular.measure(name[0], 16)) / 2, y + 48, 16, kGray);+ }+// Cross selects, Circle goes back to the game (swapped with Circle// confirming).int hy = kMenuH - 56, x = kPad;diff --git a/src/ui/stream_menu.h b/src/ui/stream_menu.hindex 50a3391..b1b12ae 100644--- a/src/ui/stream_menu.h+++ b/src/ui/stream_menu.h@@ -8,6 +8,7 @@#include "ui/app_ui.h"#include "ui/canvas.h"#include "ui/font.h"+#include "ui/pad_icons.h"#include <string>@@ -25,7 +26,7 @@ enum class MenuAction { None, Close, Leave, Refresh, Resolution, Stats, Sharpnesclass StreamMenu {public:- static constexpr int kMenuW = 620, kMenuH = 840;+ static constexpr int kMenuW = 620, kMenuH = 950;static constexpr int kMenuX = 80, kMenuY = (1080 - kMenuH) / 2;static constexpr int kStatsX = 32, kStatsY = 28;@@ -42,6 +43,8 @@ public:int sharpness() const { return sharpness_; }// Circle confirms: the hints swap their buttons.void setCircleConfirms(bool on) { circleConfirms_ = on; }+ // The controllers in use, under the connection.+ void setPads(const PadSlots& pads) { pads_ = pads; }Canvas renderMenu(const StreamInfo& info) const;Canvas renderStats(const StreamInfo& info) const;@@ -56,6 +59,7 @@ private:int sharpness_ = 0;bool resolutionAsked_ = false;bool circleConfirms_ = false;+ PadSlots pads_{};};} // namespace xc::uidiff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex 041ee71..b1ef742 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -142,6 +142,9 @@ constexpr Column kEnglish = {"Cross", // ButtonCross"Circle", // ButtonCircle"PSBox Cloud Gaming %s is out: get it on GitHub (RafaelNGP/xbox-cloud-gaming-ps5)",// UpdateAvailable+ "Controllers", // Controllers+ "Controller %s connected", // PadConnected+ "Controller %s disconnected", // PadDisconnected};constexpr Column kPortugueseBR = {@@ -254,6 +257,9 @@ constexpr Column kPortugueseBR = {"Xis","Círculo","Saiu o PSBox Cloud Gaming %s: baixe no GitHub (RafaelNGP/xbox-cloud-gaming-ps5)",+ "Controles",+ "Controle %s conectado",+ "Controle %s desconectado",};constexpr Column kSpanish = {@@ -366,6 +372,9 @@ constexpr Column kSpanish = {"Equis","Círculo","Ya está disponible PSBox Cloud Gaming %s: descárgalo en GitHub (RafaelNGP/xbox-cloud-gaming-ps5)",+ "Mandos",+ "Mando %s conectado",+ "Mando %s desconectado",};constexpr Column kFrench = {@@ -478,6 +487,9 @@ constexpr Column kFrench = {"Croix","Rond","PSBox Cloud Gaming %s est disponible : téléchargez-le sur GitHub (RafaelNGP/xbox-cloud-gaming-ps5)",+ "Manettes",+ "Manette %s connectée",+ "Manette %s déconnectée",};constexpr Column kGerman = {@@ -590,6 +602,9 @@ constexpr Column kGerman = {"Kreuz","Kreis","PSBox Cloud Gaming %s ist da: auf GitHub herunterladen (RafaelNGP/xbox-cloud-gaming-ps5)",+ "Controller",+ "Controller %s verbunden",+ "Controller %s getrennt",};constexpr Column kItalian = {@@ -702,6 +717,9 @@ constexpr Column kItalian = {"Croce","Cerchio","È disponibile PSBox Cloud Gaming %s: scaricalo da GitHub (RafaelNGP/xbox-cloud-gaming-ps5)",+ "Controller",+ "Controller %s connesso",+ "Controller %s disconnesso",};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex 176ec26..56ecb0b 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -119,6 +119,9 @@ enum class Str {ButtonCross,ButtonCircle,UpdateAvailable, // "%s" = the new version+ Controllers, // in-game menu: the pads in use+ PadConnected, // "%s" = "2 (user name)"+ PadDisconnected, // "%s" = "2 (user name)"Count};