Xbox Cloud Gaming app for PS5 Homebrew
C
WIP: keys 1-4 choose the keyboard's player (1 native, 2-4 that player's controller, added to their pad); the console's own keyboard-and-mouse icon (system icon font, read at run time)
Rafael Abud Ferreira1655ba731d78
diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cppindex 18f1276..4e91964 100644--- a/src/app/autoplay.cpp+++ b/src/app/autoplay.cpp@@ -64,7 +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 == "kbhints") ui::g_keyboardHints = g_autoplay.kbHints = true; // the hints and slots 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/autoplay.h b/src/app/autoplay.hindex bb58cac..53de437 100644--- a/src/app/autoplay.h+++ b/src/app/autoplay.h@@ -53,7 +53,8 @@ struct Autoplay {bool imeTest = false; // open the system keyboard on the home screenbool menuTest = false; // in the game: open the menu, switch to 720pint decodeThreads = 1;- int videoLoss = 0; // loss=N: N% of the video packets held back, delivered when NACKed+ int videoLoss = 0;+ bool kbHints = false; // kbhints: as if a keyboard were plugged in and used // loss=N: N% of the video packets held back, delivered when NACKedint deband = -1; // deband=0..3: instead of the settingint sharpness = -1; // sharp=0..3: instead of the settingstd::string resolution; // res=720p|1080p|1440p: instead of the settingdiff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex e437c69..99539b2 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -38,6 +38,7 @@#include <utility>extern "C" int sceSystemServiceHideSplashScreen(void);+extern "C" const char* sceKernelGetFsSandboxRandomWord(void);namespace xc::app {@@ -127,7 +128,6 @@ bool saveSettings(const ui::SettingsChoice& choice) {g_settings.highRefresh = choice.highRefresh;g_settings.maxBitrateMbps = choice.maxBitrateMbps;g_settings.gameVolume = choice.gameVolume;- g_settings.keyboardMode = choice.keyboardMode;g_settings.save(settingsPath()); // warns itselfXC_LOGI("settings saved: language %s, %s, region %s", code.c_str(), g_settings.resolution.c_str(),g_settings.region.empty() ? "auto" : g_settings.region.c_str());@@ -222,6 +222,15 @@ int main(int argc, char** argv) {ui::Fonts fonts;if (!fonts.load(platform::assetDir() + "/fonts")) XC_LOGE("fonts missing in %s", platform::assetDir().c_str());+ {+ // The console's icon font (keyboard and mouse...): read where the+ // system keeps it, not shipped with the app.+ const char* word = sceKernelGetFsSandboxRandomWord();+ std::string sandbox = std::string("/") + (word ? word : "");+ bool ok = fonts.loadIcons({"/system_ex/common_ex/font2/PS4Icon.ttf", sandbox + "/common_ex/font2/PS4Icon.ttf",+ sandbox + "_ex/common_ex/font2/PS4Icon.ttf"});+ XC_LOGI("system icon font: %s", ok ? "loaded" : "not found (drawn icons)");+ }g_images = std::make_unique<ui::ImageCache>([] {if (g_ui) g_ui->invalidate();@@ -250,7 +259,6 @@ int main(int argc, char** argv) {choice.highRefresh = g_settings.highRefresh;choice.maxBitrateMbps = g_settings.maxBitrateMbps;choice.gameVolume = g_settings.gameVolume;- choice.keyboardMode = g_settings.keyboardMode;g_ui->setAllow1440(allow1440Locked());g_ui->setUpdateState(XC_APP_VERSION, {}, false); // Settings shows this version before any checkg_ui->setSettings(choice);@@ -363,6 +371,23 @@ int main(int argc, char** argv) {streamScreen.redrawMenu();}}+ // Keys 1-4 (off a game, or with the app's menu open in one): the+ // player the keyboard and mouse play as. 1 native with player 1;+ // 2-4 that player's controller (3 or 4 with two players: just its slot).+ if (!inGame || streamScreen.menuOpen()) {+ for (const auto& k : kbm.keys) {+ if (!k.pressed || k.vk < '1' || k.vk > '4') continue;+ int player = k.vk - '1';+ {+ std::lock_guard<std::mutex> lock(g_settingsMutex);+ g_settings.keyboardPlayer = player;+ g_settings.save(settingsPath());+ }+ platform::notify(ui::trf(ui::Str::KeyboardPlayer, std::to_string(player + 1)),+ "keyboard: player " + std::to_string(player + 1));+ padsCheckedAt = 0; // the players' row at once+ }+ }// 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;@@ -371,7 +396,7 @@ int main(int argc, char** argv) {bool appMenuPressed = appMenuKey && !appMenuKeyBefore;appMenuKeyBefore = appMenuKey;if (!inGame || streamScreen.menuOpen()) input::keyboardToPad(kbm.held, pad);- kbmConnected = kbm.keyboard || kbm.mouse;+ kbmConnected = kbm.keyboard || kbm.mouse || g_autoplay.kbHints;streamScreen.setKbm(std::move(kbm));{// The triggers' resistance: in a game and in its Settings tester only.diff --git a/src/app/settings.cpp b/src/app/settings.cppindex 49e36f2..dca0469 100644--- a/src/app/settings.cpp+++ b/src/app/settings.cpp@@ -53,7 +53,7 @@ bool Settings::load(const std::string& path) {highRefresh = (*j)["highRefresh"].asBool(highRefresh);maxBitrateMbps = static_cast<int>(std::clamp<int64_t>((*j)["maxBitrateMbps"].asInt(maxBitrateMbps), 0, 40));gameVolume = static_cast<int>(std::clamp<int64_t>((*j)["gameVolume"].asInt(gameVolume), 0, 200));- keyboardMode = static_cast<int>(std::clamp<int64_t>((*j)["keyboardMode"].asInt(keyboardMode), 0, 1));+ keyboardPlayer = static_cast<int>(std::clamp<int64_t>((*j)["keyboardPlayer"].asInt(keyboardPlayer), 0, 3));micGain = static_cast<int>(std::clamp<int64_t>((*j)["micGain"].asInt(micGain), 0, 2));audioRoute = static_cast<int>(std::clamp<int64_t>((*j)["audioRoute"].asInt(audioRoute), 0, 1));skippedUpdate = (*j)["skippedUpdate"].str();@@ -163,7 +163,7 @@ bool Settings::save(const std::string& path) const {v.set("highRefresh", highRefresh);v.set("maxBitrateMbps", maxBitrateMbps);v.set("gameVolume", gameVolume);- v.set("keyboardMode", keyboardMode);+ v.set("keyboardPlayer", keyboardPlayer);v.set("micGain", micGain);v.set("audioRoute", audioRoute);v.set("skippedUpdate", skippedUpdate);diff --git a/src/app/settings.h b/src/app/settings.hindex 875daab..ad7263b 100644--- a/src/app/settings.h+++ b/src/app/settings.h@@ -74,7 +74,7 @@ struct Settings {bool highRefresh = false; // 119.88 Hz output (VRR where the console turns it on) while streamingint maxBitrateMbps = 0; // the stream's bitrate cap: 0 automatic (the tier's), else 20, 15, 10 or 5int gameVolume = 100; // percent: 25, 50, 75, 100 or 150- int keyboardMode = 0; // USB keyboard and mouse: 0 native, with player 1; 1 a controller of their own (another player)+ int keyboardPlayer = 0; // the player a USB keyboard and mouse play as (0..3; keys 1-4): 0 native with player 1, else that player's controllerint micGain = 1; // 0: 50%, 1: 100%, 2: 150%int audioRoute = 0; // 0: TV/HDMI (Main), 1: DualSense Speaker / Headset (Pad)// The release the user said "Not now" to: not offered again on start.diff --git a/src/app/stream_screen.cpp b/src/app/stream_screen.cppindex 74af8a7..cf131c0 100644--- a/src/app/stream_screen.cpp+++ b/src/app/stream_screen.cpp@@ -345,20 +345,22 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bg_player->sendInput(sent);// The keyboard as another player's controller (Settings): its own// slot, announced like a pad; no native mouse and keyboard then.+ // Keys 2-4: that player's controller. With that player's own pad+ // connected the two add up (below); alone, the keyboard is announced+ // in the slot by itself.int kbSlot = keyboardPadSlot(kbm_.keyboard || kbm_.mouse);- if (kbSlot != kbSlotAttached_) {- if (kbSlotAttached_ >= 0) g_player->setPadConnected(kbSlotAttached_, false);- if (kbSlot >= 0) {- g_player->setPadConnected(kbSlot, true);- platform::notify(ui::trf(ui::Str::PadConnected, std::to_string(kbSlot + 1)),- "keyboard as controller " + std::to_string(kbSlot + 1));- }- kbSlotAttached_ = kbSlot;+ kbPad_ = input::ControllerState{};+ if (kbSlot >= 0 && !menu_.isOpen()) input::keyboardAsGamepad(kbm_, mouseStick_, kbPad_);+ int alone = kbSlot >= 0 && !input::padConnected(kbSlot) ? kbSlot : -1;+ if (alone != kbSlotAttached_) {+ if (kbSlotAttached_ >= 0 && !input::padConnected(kbSlotAttached_)) g_player->setPadConnected(kbSlotAttached_, false);+ if (alone >= 0) g_player->setPadConnected(alone, true);+ kbSlotAttached_ = alone;}- if (kbSlot >= 0) {- input::ControllerState kbPad;- if (!menu_.isOpen()) input::keyboardAsGamepad(kbm_, mouseStick_, kbPad);- g_player->sendInput(kbPad, kbSlot); // all released while the app's menu is open+ if (alone >= 0) {+ g_player->sendInput(kbPad_, alone); // all released while the app's menu is open+ } else if (kbSlot >= 0) {+ // Added to that player's pad in the loop below.} else if (!menu_.isOpen()) {// USB keyboard and mouse: straight to the game (those that take// them) while the app's menu is closed; F12 is the app's.@@ -383,6 +385,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bfor (int i = 1; i < input::kMaxPads; ++i) {input::ControllerState other;bool on = input::pollPad(i, other);+ if (on && i == kbSlot) input::mergePads(other, kbPad_); // the keyboard plays with this player's padif (on != padAttached_[i]) {padAttached_[i] = on;g_player->setPadConnected(i, on);@@ -451,15 +454,12 @@ bool StreamScreen::menuOpen() const { return menu_.isOpen(); }void StreamScreen::redrawMenu() { overlaySeq_ = 0; }int keyboardPadSlot(bool keyboardConnected) {- bool asPad;+ int player;{std::lock_guard<std::mutex> lock(g_settingsMutex);- asPad = g_settings.keyboardMode == 1;+ player = g_settings.keyboardPlayer;}- if (!asPad || !keyboardConnected) return -1;- for (int i = 1; i < input::kMaxPads; ++i)- if (!input::padConnected(i)) return i;- return -1;+ return keyboardConnected && player > 0 && player < input::kMaxPads ? player : -1;}void StreamScreen::idle() {diff --git a/src/app/stream_screen.h b/src/app/stream_screen.hindex faa7acc..77af067 100644--- a/src/app/stream_screen.h+++ b/src/app/stream_screen.h@@ -20,9 +20,8 @@ namespace xc::app {class StreamPlayer;-// The slot the keyboard and mouse play in as a controller of their own-// (Settings: as another player): the first without a controller; -1 when-// that's off or nothing is plugged in.+// The slot the keyboard and mouse play in as that player's controller+// (keys 2-4); -1 for player 1 (native mouse and keyboard) or nothing plugged in.int keyboardPadSlot(bool keyboardConnected);class StreamScreen {@@ -75,6 +74,7 @@ private:input::KbmInput kbm_;int kbSlotAttached_ = -1; // the keyboard's slot as a controller, announcedinput::MouseStick mouseStick_;+ input::ControllerState kbPad_; // the keyboard as a controller, this passstd::vector<uint8_t> keysInGame_; // keys the game was told are downbool wasStreaming_ = false;uint64_t lastMenuRedrawMs_ = 0;diff --git a/src/input/keyboard_nav.cpp b/src/input/keyboard_nav.cppindex 1c643ae..b014803 100644--- a/src/input/keyboard_nav.cpp+++ b/src/input/keyboard_nav.cpp@@ -45,6 +45,32 @@ void keyboardAsGamepad(const KbmInput& in, MouseStick& stick, ControllerState& oout.rightStickY = stick.y;}+void mergePads(ControllerState& pad, const ControllerState& e) {+ pad.dpadUp |= e.dpadUp;+ pad.dpadDown |= e.dpadDown;+ pad.dpadLeft |= e.dpadLeft;+ pad.dpadRight |= e.dpadRight;+ pad.btnA |= e.btnA;+ pad.btnB |= e.btnB;+ pad.btnX |= e.btnX;+ pad.btnY |= e.btnY;+ pad.btnL1 |= e.btnL1;+ pad.btnR1 |= e.btnR1;+ pad.btnL3 |= e.btnL3;+ pad.btnR3 |= e.btnR3;+ pad.btnOptions |= e.btnOptions;+ pad.btnTouchpad |= e.btnTouchpad;+ auto further = [](float& a, float b) {+ if (std::abs(b) > std::abs(a)) a = b;+ };+ further(pad.leftStickX, e.leftStickX);+ further(pad.leftStickY, e.leftStickY);+ further(pad.rightStickX, e.rightStickX);+ further(pad.rightStickY, e.rightStickY);+ pad.triggerL2 = std::max(pad.triggerL2, e.triggerL2);+ pad.triggerR2 = std::max(pad.triggerR2, e.triggerR2);+}+void keyboardToPad(const std::vector<uint8_t>& held, ControllerState& pad) {auto down = [&](std::initializer_list<uint8_t> vks) {for (uint8_t vk : vks)diff --git a/src/input/keyboard_nav.h b/src/input/keyboard_nav.hindex 5caf424..7353306 100644--- a/src/input/keyboard_nav.h+++ b/src/input/keyboard_nav.h@@ -35,6 +35,10 @@ struct MouseStick {};void keyboardAsGamepad(const KbmInput& in, MouseStick& stick, ControllerState& out);+// Adds `extra` (the keyboard as a controller) to `pad`: buttons pressed on+// either, the stick or trigger pushed further.+void mergePads(ControllerState& pad, const ControllerState& extra);+// Adds what the keys held press to `pad` (buttons on, sticks pushed); the// controller's own input stays.void keyboardToPad(const std::vector<uint8_t>& held, ControllerState& pad);diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex 05889df..ea71c4c 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -1212,7 +1212,8 @@ bool AppUi::accentColor(Color& out) {void AppUi::drawPads(Canvas& c) {// Bottom left, on the line of the button hints (which are right-aligned).- drawPadRow(c, fonts_.bold, kMargin, kH - 26 - padIconHeight(48), 48, 16, pads_, kBg);+ drawPadRow(c, fonts_.bold, kMargin, kH - 26 - padIconHeight(48), 48, 16, pads_, kBg,+ fonts_.hasIcons ? &fonts_.icons : nullptr);}void AppUi::setRegions(std::vector<std::string> regions, const std::string& defaultRegion) {@@ -1257,8 +1258,7 @@ std::vector<std::string> AppUi::settingOptions(int row) const {for (int mbps : kBitrateCaps) out.push_back(std::to_string(mbps) + " Mbps");} else if (row == 11) {for (int v : kVolumes) out.push_back(std::to_string(v) + " %");- } else if (row == 12) {- out = {tr(Str::KeyboardNative), tr(Str::KeyboardAsPad)};+} else if (row == 8) {out.push_back(tr(Str::LoginCountryOff));for (const char* country : kLoginCountries) out.push_back(loginCountryName(country));@@ -1289,7 +1289,6 @@ int AppUi::settingSelected(int row) const {if (kBitrateCaps[i] == settings_.maxBitrateMbps) return static_cast<int>(i) + 1;return 0;}- if (row == 12) return settings_.keyboardMode;if (row == 11) {for (size_t i = 0; i < std::size(kVolumes); ++i)if (kVolumes[i] == settings_.gameVolume) return static_cast<int>(i);@@ -1328,8 +1327,7 @@ void AppUi::applySetting(int row, int index) {settings_.maxBitrateMbps = index == 0 ? 0 : kBitrateCaps[index - 1];} else if (row == 11) {settings_.gameVolume = kVolumes[index];- } else if (row == 12) {- settings_.keyboardMode = index;+} else if (row == 8) {settings_.loginCountry = index == 0 ? std::string() : kLoginCountries[index - 1];} else {@@ -2631,7 +2629,10 @@ void AppUi::drawCard(Canvas& c, const GameTile& t, int x, int y, bool focused, bint right = x + kCard - 10 - (platformLabel(t.platform) ? 96 + 6 : 0);Rect k{right - 34, y + kCard - 34, 34, 24};c.fillRect(k, rgba(0, 0, 0, 220), 4);- drawKeyboardGlyph(c, k.x + 6, k.y + 6, 22, kWhite);+ if (fonts_.hasIcons) // the console's own keyboard-and-mouse icon+ fonts_.icons.draw(c, kIconKeyboardMouse, k.x + (k.w - fonts_.icons.measure(kIconKeyboardMouse, 18)) / 2, k.y + 3, 18, kWhite);+ else+ drawKeyboardGlyph(c, k.x + 6, k.y + 6, 22, kWhite);}if (const char* p = platformLabel(t.platform)) {constexpr int kBadgeW = 96;@@ -3257,9 +3258,8 @@ void AppUi::drawSettings(Canvas& c) {const char* labels[kSettingRows] = {tr(Str::Language), tr(Str::Resolution), tr(Str::Region),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::KeyboardMode)};- constexpr int kRowW = 1200, kRowH = 46, kGap = 6;+ tr(Str::HighRefresh), tr(Str::BitrateCap), tr(Str::GameVolume)};+ constexpr int kRowW = 1200, kRowH = 50, kGap = 6;Rect rows[kSettingRows];int y = 262;for (int i = 0; i < kSettingRows; ++i) {diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex 7d4ef4d..0a092a5 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -118,13 +118,12 @@ struct SettingsChoice {bool highRefresh = false; // 120 Hz output while a game streamsint maxBitrateMbps = 0; // 0 automatic, else 20 / 15 / 10 / 5int gameVolume = 100; // percent: 25 / 50 / 75 / 100 / 150- int keyboardMode = 0; // 0 native (player 1), 1 a controller of its own};// The largest stick dead zone Settings offers, in percent of the travel.constexpr int kMaxDeadzone = 30;-constexpr int kSettingRows = 13; // language, resolution, region, dead zone, triggers, confirm, light bar, updates,- // sign-in country, 120 Hz output, bitrate cap, game volume, keyboard+constexpr int kSettingRows = 12; // language, resolution, region, dead zone, triggers, confirm, light bar, updates,+ // sign-in country, 120 Hz output, bitrate cap, game volume// The countries "Sign in as another country" offers (xcloud::loginCountryAddress).constexpr const char* kLoginCountries[] = {"br", "jp", "kr", "pl", "us"};diff --git a/src/ui/font.cpp b/src/ui/font.cppindex 42529aa..62b2df1 100644--- a/src/ui/font.cpp+++ b/src/ui/font.cpp@@ -168,4 +168,10 @@ bool Fonts::load(const std::string& dir) {bold.load(dir + "/Inter-Bold.ttf");}+bool Fonts::loadIcons(const std::vector<std::string>& paths) {+ for (const auto& p : paths)+ if (icons.load(p)) return hasIcons = true;+ return false;+}+} // namespace xc::uidiff --git a/src/ui/font.h b/src/ui/font.hindex 0e72d25..b027a2b 100644--- a/src/ui/font.h+++ b/src/ui/font.h@@ -55,9 +55,18 @@ private:// The three weights the UI uses.struct Fonts {Font regular, semibold, bold;+ // The console's own icon font (keyboard and mouse, controller...), read+ // from the system at run time, never shipped; hasIcons false without it.+ Font icons;+ bool hasIcons = false;bool load(const std::string& dir);+ // The first of `paths` that loads; false when none does.+ bool loadIcons(const std::vector<std::string>& paths);};+// Code points of the console's icon font.+constexpr const char* kIconKeyboardMouse = "\xEF\xA3\xBE"; // U+F8FE+// Next UTF-8 code point from `s` at `i` (advances `i`); U+FFFD on bad input.uint32_t nextCodepoint(std::string_view s, size_t& i);diff --git a/src/ui/pad_icons.cpp b/src/ui/pad_icons.cppindex e45e6f1..28d49ac 100644--- a/src/ui/pad_icons.cpp+++ b/src/ui/pad_icons.cpp@@ -74,22 +74,32 @@ void drawPadIcon(Canvas& c, const Font& font, int x, int y, int w, int index, boconnected ? rgba(255, 255, 255) : rgba(110, 110, 110));}-int drawPadRow(Canvas& c, const Font& font, int x, int y, int w, int gap, const PadSlots& pads, Color background) {- for (int i = 0; i < static_cast<int>(pads.size()); ++i) {- int px = x + i * (w + gap);- if (pads[i].keyboard) { // a keyboard (and mouse) in the player's colour, numbered like a pad- Color col = playerColor(i);- int kh = w * 10 / 24;- int top = y + (w * 7 / 10 - kh) / 2;- drawKeyboardGlyph(c, px, top, w * 3 / 4, col);- c.fillRect({px + w * 3 / 4 + w / 16, top + kh / 6, w / 6, kh * 5 / 6}, col, w / 12); // the mouse- std::string n = std::to_string(i + 1);- int npx = w * 3 / 10;- font.draw(c, n, px + (w - font.measure(n, npx)) / 2, y + w * 7 / 10 + 4, npx, rgba(255, 255, 255));- continue;- }- drawPadIcon(c, font, px, y, w, i, pads[i].connected, background);+void drawSlotIcon(Canvas& c, const Font& font, int x, int y, int w, int index, const PadSlot& slot, Color background,+ const Font* icons) {+ if (!slot.keyboard) {+ drawPadIcon(c, font, x, y, w, index, slot.connected, background);+ return;+ }+ // A keyboard (and mouse) in the player's colour, numbered like a pad.+ Color col = playerColor(index);+ if (icons) { // the console's own keyboard-and-mouse icon+ int px2 = w * 9 / 10; // as wide as a pad, centred on its height+ icons->draw(c, kIconKeyboardMouse, x + (w - icons->measure(kIconKeyboardMouse, px2)) / 2, y - w / 10, px2, col);+ } else {+ int kh = w * 10 / 24;+ int top = y + (w * 7 / 10 - kh) / 2;+ drawKeyboardGlyph(c, x, top, w * 3 / 4, col);+ c.fillRect({x + w * 3 / 4 + w / 16, top + kh / 6, w / 6, kh * 5 / 6}, col, w / 12); // the mouse}+ std::string n = std::to_string(index + 1);+ int npx = w * 3 / 10;+ font.draw(c, n, x + (w - font.measure(n, npx)) / 2, y + w * 7 / 10 + 4, npx, rgba(255, 255, 255));+}++int drawPadRow(Canvas& c, const Font& font, int x, int y, int w, int gap, const PadSlots& pads, Color background,+ const Font* icons) {+ for (int i = 0; i < static_cast<int>(pads.size()); ++i)+ drawSlotIcon(c, font, x + i * (w + gap), y, w, i, pads[i], background, icons);return static_cast<int>(pads.size()) * (w + gap) - gap;}diff --git a/src/ui/pad_icons.h b/src/ui/pad_icons.hindex 432edb3..b719014 100644--- a/src/ui/pad_icons.h+++ b/src/ui/pad_icons.h@@ -33,6 +33,12 @@ void drawPadIcon(Canvas& c, const Font& font, int x, int y, int w, int index, boint padIconHeight(int w);// 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, Color background);+// One slot: its pad, or the keyboard and mouse playing in it.+void drawSlotIcon(Canvas& c, const Font& font, int x, int y, int w, int index, const PadSlot& slot, Color background,+ const Font* icons = nullptr);++// `icons`: the console's icon font, for the keyboard (nullptr: drawn).+int drawPadRow(Canvas& c, const Font& font, int x, int y, int w, int gap, const PadSlots& pads, Color background,+ const Font* icons = nullptr);} // namespace xc::uidiff --git a/src/ui/stream_menu.cpp b/src/ui/stream_menu.cppindex dce69b0..dd4fa25 100644--- a/src/ui/stream_menu.cpp+++ b/src/ui/stream_menu.cpp@@ -279,7 +279,8 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {for (int i = 0; i < static_cast<int>(pads_.size()); ++i) {int sx = kPad + i * slotW;constexpr int kIconW = 56;- drawPadIcon(c, fonts_.bold, sx + (slotW - kIconW) / 2, y, kIconW, i, pads_[i].connected, kPanel);+ drawSlotIcon(c, fonts_.bold, sx + (slotW - kIconW) / 2, y, kIconW, i, pads_[i], kPanel,+ fonts_.hasIcons ? &fonts_.icons : nullptr);if (!pads_[i].connected || pads_[i].name.empty()) continue;auto name = fonts_.regular.wrap(pads_[i].name, 15, slotW - 8, 1);if (!name.empty())diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex 37b607b..b341d17 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -272,9 +272,7 @@ constexpr Column kEnglish = {"Keyboard: F12 this menu · Home Xbox button", // MenuKeyHint"Mouse & keyboard", // FilterMouseKeyboard"Mouse and keyboard", // MouseKeyboardSupport- "Keyboard & mouse", // KeyboardMode- "Native (player 1)", // KeyboardNative- "As a controller (another player)", // KeyboardAsPad+ "Keyboard and mouse: player %s", // KeyboardPlayer};constexpr Column kPortugueseBR = {@@ -517,9 +515,7 @@ constexpr Column kPortugueseBR = {"Teclado: F12 este menu · Home botão Xbox", // MenuKeyHint"Teclado e mouse", // FilterMouseKeyboard"Teclado e mouse", // MouseKeyboardSupport- "Teclado e mouse", // KeyboardMode- "Nativo (jogador 1)", // KeyboardNative- "Como controle (outro jogador)", // KeyboardAsPad+ "Teclado e mouse: jogador %s", // KeyboardPlayer};constexpr Column kSpanish = {@@ -762,9 +758,7 @@ constexpr Column kSpanish = {"Teclado: F12 este menú · Inicio botón Xbox", // MenuKeyHint"Teclado y ratón", // FilterMouseKeyboard"Teclado y ratón", // MouseKeyboardSupport- "Teclado y ratón", // KeyboardMode- "Nativo (jugador 1)", // KeyboardNative- "Como mando (otro jugador)", // KeyboardAsPad+ "Teclado y ratón: jugador %s", // KeyboardPlayer};constexpr Column kFrench = {@@ -1007,9 +1001,7 @@ constexpr Column kFrench = {"Clavier : F12 ce menu · Origine bouton Xbox", // MenuKeyHint"Clavier et souris", // FilterMouseKeyboard"Clavier et souris", // MouseKeyboardSupport- "Clavier et souris", // KeyboardMode- "Natif (joueur 1)", // KeyboardNative- "Comme manette (autre joueur)", // KeyboardAsPad+ "Clavier et souris : joueur %s", // KeyboardPlayer};constexpr Column kGerman = {@@ -1252,9 +1244,7 @@ constexpr Column kGerman = {"Tastatur: F12 dieses Menü · Pos1 Xbox-Taste", // MenuKeyHint"Maus & Tastatur", // FilterMouseKeyboard"Maus und Tastatur", // MouseKeyboardSupport- "Tastatur & Maus", // KeyboardMode- "Nativ (Spieler 1)", // KeyboardNative- "Als Controller (weiterer Spieler)", // KeyboardAsPad+ "Tastatur und Maus: Spieler %s", // KeyboardPlayer};constexpr Column kItalian = {@@ -1497,9 +1487,7 @@ constexpr Column kItalian = {"Tastiera: F12 questo menu · Home pulsante Xbox", // MenuKeyHint"Tastiera e mouse", // FilterMouseKeyboard"Tastiera e mouse", // MouseKeyboardSupport- "Tastiera e mouse", // KeyboardMode- "Nativo (giocatore 1)", // KeyboardNative- "Come controller (altro giocatore)", // KeyboardAsPad+ "Tastiera e mouse: giocatore %s", // KeyboardPlayer};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex 6db95df..1564d7b 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -249,9 +249,7 @@ enum class Str {MenuKeyHint, // in-game menu, keyboard in use: its keys (F12 the menu, Home the Xbox button)FilterMouseKeyboard, // search filter: games the cloud plays with native mouse and keyboardMouseKeyboardSupport, // game page, beside the console and genres- KeyboardMode, // Settings row: what a USB keyboard and mouse are- KeyboardNative, // ... native mouse and keyboard, with player 1- KeyboardAsPad, // ... a controller of their own (another player)+ KeyboardPlayer, // notification: keys 1-4 chose the player the keyboard plays as (%s: 1..4)Count};diff --git a/tests/test_main.cpp b/tests/test_main.cppindex 1dafde7..446a2f8 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -966,6 +966,14 @@ static void testKeyboardAsGamepad() {in.keyboard = true;for (int i = 0; i < 20; ++i) xc::input::keyboardAsGamepad(in, stick, out); // the mouse still: back to the centreCHECK(out.rightStickX == 0.0f && !out.btnA);+ xc::input::ControllerState pad, kb;+ pad.btnB = true;+ pad.leftStickX = 0.3f;+ kb.btnA = true;+ kb.leftStickX = -1.0f;+ kb.triggerR2 = 1.0f;+ xc::input::mergePads(pad, kb);+ CHECK(pad.btnA && pad.btnB && pad.leftStickX == -1.0f && pad.triggerR2 == 1.0f);}int main() {