Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

WIP: mouse & keyboard games (badge, page, search filter) from xCloud's supportedInputTypes; keyboard as another player's controller; keyboard icon in the players' row; R key on the sort chip

Rafael Abud Ferreiraad4503cd1eba
diff --git a/src/app/library.cpp b/src/app/library.cpp
index ff7fc5b..e1a68e7 100644
--- a/src/app/library.cpp
+++ b/src/app/library.cpp
@@ -147,6 +147,7 @@ ui::GameTile Library::tile(const std::string& productId, const std::string& titl
!knownGamePass_.count(productId))
t.playable = true;
t.freeInStore = freeInStore_.count(productId) > 0;
+ t.mouseKeyboard = mouseKeyboard_.count(productId) > 0;
// A free-to-play game not on the account yet is got like one bought
// (the store page's QR code), only free.
t.purchasable = !t.playable && (purchasableSet_.count(productId) || t.freeInStore);
@@ -284,6 +285,7 @@ bool Library::loadCache() {
for (const auto& [id, code] : (*j)["platforms"].members()) platform_[id] = code.str();
for (const auto& [pid, xbox] : (*j)["xboxTitles"].members()) xboxTitleOf_[pid] = xbox.str();
for (const auto& id : (*j)["freeInStore"].items()) freeInStore_.insert(id.str());
+ for (const auto& id : (*j)["mouseKeyboard"].items()) mouseKeyboard_.insert(id.str());
for (const auto& t : (*j)["ownedTitles"].items()) ownedTitles_.insert(t.str());
gamePassMember_ = (*j)["gamePassMember"].asBool();
for (const auto& p : (*j)["ownedProducts"].items()) ownedProducts_.insert(p.str());
@@ -346,6 +348,9 @@ void Library::saveCache() const {
json::Value free = json::Value::array();
for (const auto& id : freeInStore_) free.push(id);
root.set("freeInStore", free);
+ json::Value mkb = json::Value::array();
+ for (const auto& id : mouseKeyboard_) mkb.push(id);
+ root.set("mouseKeyboard", mkb);
if (!platform::writeFileAtomic(cachePath_, root.dump())) XC_LOGW("library: could not write %s", cachePath_.c_str());
}
@@ -491,6 +496,7 @@ void Library::loadOwned(xcloud::GssvClient gssv, const Changed& changed, const s
if (xcloud::isNonGameAddon(t.titleId)) continue;
if (!t.productId.empty() && !t.xboxTitleId.empty()) xboxTitleOf_[t.productId] = t.xboxTitleId;
if (t.isFreeInStore && !t.productId.empty()) freeInStore_.insert(t.productId);
+ if (t.mouseKeyboard && !t.productId.empty()) mouseKeyboard_.insert(t.productId);
if (t.hasEntitlement) {
ownedTitles.insert(t.titleId);
if (t.productId.empty()) continue;
diff --git a/src/app/library.h b/src/app/library.h
index 4fc0a33..0f0b110 100644
--- a/src/app/library.h
+++ b/src/app/library.h
@@ -122,6 +122,7 @@ private:
std::vector<Item> purchasable_; // streamable once bought
std::set<std::string> purchasableSet_;
std::set<std::string> freeInStore_; // product ids free in the store
+ std::set<std::string> mouseKeyboard_; // product ids the cloud streams with native mouse and keyboard
// Details from a cache in another language: shown until replaced.
std::set<std::string> otherLanguage_;
Progress progress_;
diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cpp
index 0e8e0de..e437c69 100644
--- a/src/app/ps5_main.cpp
+++ b/src/app/ps5_main.cpp
@@ -127,6 +127,7 @@ 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 itself
XC_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());
@@ -249,6 +250,7 @@ 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 check
g_ui->setSettings(choice);
@@ -276,6 +278,7 @@ 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, homeKeyBefore = false; // F12 / Home held at the last pass
+ bool kbmConnected = false; // a USB keyboard or mouse in use
auto now0 = [] { return platform::nowMs(); };
Repeater up, down, left, right, dpadLeft, dpadRight;
// Smooth scrolling: rows / cards still to move (fractions carry over),
@@ -368,6 +371,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;
streamScreen.setKbm(std::move(kbm));
{
// The triggers' resistance: in a game and in its Settings tester only.
@@ -405,6 +409,10 @@ int main(int argc, char** argv) {
ui::PadSlots slots;
for (int i = 0; i < input::kMaxPads; ++i)
slots[static_cast<size_t>(i)] = {input::padConnected(i), input::padUserName(i)};
+ // The keyboard: in a slot of its own as another player's
+ // controller (Settings), else on player 1's while it's the device in use.
+ if (int kb = keyboardPadSlot(kbmConnected); kb >= 0) slots[static_cast<size_t>(kb)] = {true, "", true};
+ else if (kbmConnected && ui::g_keyboardHints) slots[0].keyboard = slots[0].connected = true;
g_ui->setPads(slots);
streamScreen.setPads(slots);
}
diff --git a/src/app/settings.cpp b/src/app/settings.cpp
index b017ede..49e36f2 100644
--- a/src/app/settings.cpp
+++ b/src/app/settings.cpp
@@ -53,6 +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));
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();
@@ -162,6 +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("micGain", micGain);
v.set("audioRoute", audioRoute);
v.set("skippedUpdate", skippedUpdate);
diff --git a/src/app/settings.h b/src/app/settings.h
index 0fe32e5..875daab 100644
--- a/src/app/settings.h
+++ b/src/app/settings.h
@@ -74,6 +74,7 @@ struct Settings {
bool highRefresh = false; // 119.88 Hz output (VRR where the console turns it on) while streaming
int maxBitrateMbps = 0; // the stream's bitrate cap: 0 automatic (the tier's), else 20, 15, 10 or 5
int 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 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.cpp
index 15e55b2..74af8a7 100644
--- a/src/app/stream_screen.cpp
+++ b/src/app/stream_screen.cpp
@@ -343,9 +343,25 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
}
if (platform::nowMs() < g_xboxButtonUntil) sent.btnNexus = true;
g_player->sendInput(sent);
+ // The keyboard as another player's controller (Settings): its own
+ // slot, announced like a pad; no native mouse and keyboard then.
+ 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;
+ }
+ 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
+ } 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.
- if (!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 || k.vk == 0x24; }),
@@ -434,8 +450,22 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
bool StreamScreen::menuOpen() const { return menu_.isOpen(); }
void StreamScreen::redrawMenu() { overlaySeq_ = 0; }
+int keyboardPadSlot(bool keyboardConnected) {
+ bool asPad;
+ {
+ std::lock_guard<std::mutex> lock(g_settingsMutex);
+ asPad = g_settings.keyboardMode == 1;
+ }
+ if (!asPad || !keyboardConnected) return -1;
+ for (int i = 1; i < input::kMaxPads; ++i)
+ if (!input::padConnected(i)) return i;
+ return -1;
+}
+
void StreamScreen::idle() {
keysInGame_.clear();
+ kbSlotAttached_ = -1;
+ mouseStick_ = {};
if (!g_keyboardFor.empty()) updateTextInput(nullptr);
touchEnabled_ = false; // each stream starts with touch off
if (overlayShown_) {
diff --git a/src/app/stream_screen.h b/src/app/stream_screen.h
index df52862..faa7acc 100644
--- a/src/app/stream_screen.h
+++ b/src/app/stream_screen.h
@@ -10,6 +10,7 @@
#include "app/auto_deband.h"
#include "input/controller.h"
#include "input/kbm.h"
+#include "input/keyboard_nav.h"
#include "ui/app_ui.h"
#include "ui/stream_menu.h"
@@ -19,6 +20,11 @@ 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.
+int keyboardPadSlot(bool keyboardConnected);
+
class StreamScreen {
public:
explicit StreamScreen(const ui::Fonts& fonts) : menu_(fonts) {}
@@ -67,6 +73,8 @@ private:
bool circleConfirms_ = false;
bool highRefresh_ = false; // 120 Hz turned on for this stream
input::KbmInput kbm_;
+ int kbSlotAttached_ = -1; // the keyboard's slot as a controller, announced
+ input::MouseStick mouseStick_;
std::vector<uint8_t> keysInGame_; // keys the game was told are down
bool wasStreaming_ = false;
uint64_t lastMenuRedrawMs_ = 0;
diff --git a/src/input/keyboard_nav.cpp b/src/input/keyboard_nav.cpp
index a9c5f4e..1c643ae 100644
--- a/src/input/keyboard_nav.cpp
+++ b/src/input/keyboard_nav.cpp
@@ -3,9 +3,48 @@
#include "input/keyboard_nav.h"
#include <algorithm>
+#include <cmath>
namespace xc::input {
+void keyboardAsGamepad(const KbmInput& in, MouseStick& stick, ControllerState& out) {
+ out = ControllerState{};
+ out.connected = in.keyboard || in.mouse;
+ auto down = [&](std::initializer_list<uint8_t> vks) {
+ for (uint8_t vk : vks)
+ if (std::binary_search(in.held.begin(), in.held.end(), vk)) return true;
+ return false;
+ };
+ out.leftStickX = (down({'D'}) ? 1.0f : 0.0f) - (down({'A'}) ? 1.0f : 0.0f);
+ out.leftStickY = (down({'S'}) ? 1.0f : 0.0f) - (down({'W'}) ? 1.0f : 0.0f); // pad convention: +down
+ out.dpadUp = down({0x26});
+ out.dpadDown = down({0x28});
+ out.dpadLeft = down({0x25});
+ out.dpadRight = down({0x27});
+ out.btnA = down({0x20});
+ out.btnB = down({'C'});
+ out.btnX = down({'R'});
+ out.btnY = down({'E'});
+ out.btnL1 = down({'Q'});
+ out.btnR1 = down({'F'});
+ out.btnL3 = down({0x10}); // shift
+ out.btnR3 = down({'V'}) || (in.buttons & 4);
+ out.btnTouchpad = down({0x09}); // View
+ out.btnOptions = down({0x1B}); // Menu
+ out.triggerL2 = (in.buttons & 2) ? 1.0f : 0.0f;
+ out.triggerR2 = (in.buttons & 1) ? 1.0f : 0.0f;
+ // The mouse: about 12 counts a pass is the stick all the way; eased so
+ // a still mouse lets the stick come back to the centre.
+ constexpr float kFull = 12.0f, kEase = 0.45f;
+ float tx = std::clamp(in.dx / kFull, -1.0f, 1.0f), ty = std::clamp(in.dy / kFull, -1.0f, 1.0f);
+ stick.x += (tx - stick.x) * kEase;
+ stick.y += (ty - stick.y) * kEase;
+ if (std::abs(stick.x) < 0.02f) stick.x = 0;
+ if (std::abs(stick.y) < 0.02f) stick.y = 0;
+ out.rightStickX = stick.x;
+ out.rightStickY = stick.y;
+}
+
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.h
index 8cc51c1..5caf424 100644
--- a/src/input/keyboard_nav.h
+++ b/src/input/keyboard_nav.h
@@ -15,6 +15,7 @@
#pragma once
#include "input/controller.h"
+#include "input/kbm.h"
#include <cstdint>
#include <vector>
@@ -24,6 +25,16 @@ namespace xc::input {
// The key that opens the app's menu during a game (F12).
constexpr uint8_t kVkAppMenu = 0x7B;
+// The keyboard and mouse as a controller of their own (another player, so
+// a second controller isn't needed): W A S D the left stick, the mouse the
+// right stick, the arrows the D-pad; Space A, C B, R X, E Y, Q LB, F RB, the
+// mouse's right / left buttons LT / RT, Shift and the middle button the
+// sticks' clicks, Tab View, Esc Menu.
+struct MouseStick {
+ float x = 0, y = 0; // the right stick, eased towards the mouse's speed
+};
+void keyboardAsGamepad(const KbmInput& in, MouseStick& stick, ControllerState& out);
+
// 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.cpp
index ef006fb..05889df 100644
--- a/src/ui/app_ui.cpp
+++ b/src/ui/app_ui.cpp
@@ -692,6 +692,7 @@ void AppUi::showFilteredSearch(Tab tab, bool cheapest, int mode, const std::stri
searchOnKeys_ = true;
query_.clear();
filterFree_ = false;
+ filterMouseKeyboard_ = false;
filterCheapest_ = cheapest;
filterConsole_ = 0;
filterMode_ = mode;
@@ -800,6 +801,7 @@ void AppUi::runSearch() {
for (const auto& t : tab_ == Tab::GamePass ? gamePassPool_ : libraryPool_) {
if (hidden_.count(t.productId)) continue;
if (filterConsole_ && t.platform != kConsoleCodes[filterConsole_]) continue;
+ if (filterMouseKeyboard_ && !t.mouseKeyboard) continue;
// Play mode and language need the full details: a game without them
// yet comes in when they arrive.
static constexpr uint32_t kModeBits[] = {0, xcloud::kModeSingle, xcloud::kModeOnlineMulti, xcloud::kModeOnlineCoop,
@@ -1255,6 +1257,8 @@ 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));
@@ -1285,6 +1289,7 @@ 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);
@@ -1323,6 +1328,8 @@ 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 {
@@ -1649,8 +1656,8 @@ std::vector<AppUi::Filter> AppUi::filterRow(int row) const {
// Caller holds mutex_. Prices only matter in "Your games" (Game Pass
// games aren't bought).
if (row == 1) return {Filter::Mode, Filter::Genre, Filter::Publisher, Filter::Language};
- if (tab_ == Tab::GamePass) return {Filter::Console};
- return {Filter::Free, Filter::Cheapest, Filter::Console};
+ if (tab_ == Tab::GamePass) return {Filter::Console, Filter::MouseKeyboard};
+ return {Filter::Free, Filter::Cheapest, Filter::Console, Filter::MouseKeyboard};
}
std::vector<std::string> AppUi::poolGenres() const {
@@ -1739,6 +1746,7 @@ void AppUi::chooseFilterLocked(Filter f, int index) {
std::string AppUi::filterText(Filter f) const {
// Caller holds mutex_. A list shows its name until a choice is made.
if (f == Filter::Free) return tr(Str::FilterFree);
+ if (f == Filter::MouseKeyboard) return tr(Str::FilterMouseKeyboard);
if (f == Filter::Cheapest) return tr(Str::FilterCheapest);
int sel = filterSelected(f);
if (sel > 0 || f == Filter::Console) {
@@ -1752,6 +1760,7 @@ bool AppUi::filterOn(Filter f) const {
// Caller holds mutex_.
if (f == Filter::Free) return filterFree_;
if (f == Filter::Cheapest) return filterCheapest_;
+ if (f == Filter::MouseKeyboard) return filterMouseKeyboard_;
return filterSelected(f) > 0;
}
@@ -1762,7 +1771,7 @@ void AppUi::pressFilter(Filter f) {
filterListIndex_ = filterSelected(f);
filterListTop_ = 0;
} else {
- (f == Filter::Free ? filterFree_ : filterCheapest_) ^= true;
+ (f == Filter::Free ? filterFree_ : f == Filter::MouseKeyboard ? filterMouseKeyboard_ : filterCheapest_) ^= true;
runSearch();
}
dirty_ = true;
@@ -2617,6 +2626,13 @@ void AppUi::drawCard(Canvas& c, const GameTile& t, int x, int y, bool focused, b
}
}
// Bottom-right: the console it was made for; one style and width for all.
+ // Left of it, a small keyboard: the cloud takes mouse and keyboard in it.
+ if (t.mouseKeyboard) {
+ int 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 (const char* p = platformLabel(t.platform)) {
constexpr int kBadgeW = 96;
Rect badge{x + kCard - 10 - kBadgeW, y + kCard - 34, kBadgeW, 24};
@@ -2705,9 +2721,11 @@ void AppUi::drawLibrary(Canvas& c, uint64_t nowMs) {
std::string label = trf(Str::SortLabel, tr(sortName));
int w = fonts_.semibold.measure(label, 22);
int right = left + kGridW;
+ const char* sortKey = g_keyboardHints ? "R" : "R3";
Rect pill{right - 44, 112, 44, 28};
c.fillRect(pill, rgba(255, 255, 255, 40), 8);
- fonts_.bold.draw(c, "R3", pill.x + (pill.w - fonts_.bold.measure("R3", 16)) / 2,
+ if (g_keyboardHints) c.strokeRect(pill, kGray, 2, 8);
+ fonts_.bold.draw(c, sortKey, pill.x + (pill.w - fonts_.bold.measure(sortKey, 16)) / 2,
fonts_.bold.centeredY(pill.y, pill.h, 16), 16, kGray);
fonts_.semibold.draw(c, label, pill.x - 14 - w, fonts_.semibold.centeredY(pill.y, pill.h, 22), 22, kGray);
}
@@ -3084,6 +3102,7 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {
std::string cats;
if (const char* p = platformLabel(g->platform)) cats = p;
for (const auto& cat : g->categories) cats += (cats.empty() ? "" : " \xE2\x80\xA2 ") + cat;
+ if (g->mouseKeyboard) cats += std::string(cats.empty() ? "" : " \xE2\x80\xA2 ") + tr(Str::MouseKeyboardSupport);
if (!cats.empty()) {
fonts_.regular.draw(c, cats, kMargin, y, 24, kDim);
y += 44;
@@ -3238,8 +3257,9 @@ 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)};
- constexpr int kRowW = 1200, kRowH = 50, kGap = 6;
+ tr(Str::HighRefresh), tr(Str::BitrateCap), tr(Str::GameVolume),
+ tr(Str::KeyboardMode)};
+ constexpr int kRowW = 1200, kRowH = 46, 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.h
index 0dc3180..7d4ef4d 100644
--- a/src/ui/app_ui.h
+++ b/src/ui/app_ui.h
@@ -44,6 +44,8 @@ struct GameTile {
bool purchasable = false;
// Free in the store (free-to-play): the "Free" search filter.
bool freeInStore = false;
+ // The cloud takes native mouse and keyboard in it (xCloud's "MKB").
+ bool mouseKeyboard = false;
// Console it was made for: "360", "ONE", "XS" (xcloud/titlehub.h); empty
// while unknown.
std::string platform;
@@ -116,12 +118,13 @@ struct SettingsChoice {
bool highRefresh = false; // 120 Hz output while a game streams
int maxBitrateMbps = 0; // 0 automatic, else 20 / 15 / 10 / 5
int 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 = 12; // language, resolution, region, dead zone, triggers, confirm, light bar, updates,
- // sign-in country, 120 Hz output, bitrate cap, game volume
+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
// The countries "Sign in as another country" offers (xcloud::loginCountryAddress).
constexpr const char* kLoginCountries[] = {"br", "jp", "kr", "pl", "us"};
@@ -291,7 +294,7 @@ public:
// The search keyboard's focus (row, column), for the tests.
std::pair<int, int> searchKeyFocus() const;
std::vector<std::pair<std::string, PriceInfo>> searchResults(size_t max) const;
- enum class Filter { Free, Cheapest, Console, Mode, Genre, Publisher, Language };
+ enum class Filter { Free, Cheapest, Console, Mode, Genre, Publisher, Language, MouseKeyboard };
void chooseFilter(Filter f, int index);
// Autoplay tests: where the focus is ("Game Pass row 2 card 6", ...).
std::string focusDescription() const;
@@ -356,7 +359,7 @@ private:
// only) and Console; then Mode, Genre, Publisher and Language. The lists open a
// drop-down; Free and Lowest price turn on and off.
std::vector<Filter> filterRow(int row) const;
- bool isList(Filter f) const { return f != Filter::Free && f != Filter::Cheapest; }
+ bool isList(Filter f) const { return f != Filter::Free && f != Filter::Cheapest && f != Filter::MouseKeyboard; }
std::string filterText(Filter f) const; // the chip's label: its choice when one is made
bool filterOn(Filter f) const;
std::vector<std::string> filterOptions(Filter f) const;
@@ -431,7 +434,7 @@ private:
void drawLoadingBar(Canvas& c, int x, int y, int w, uint64_t nowMs);
LibrarySort librarySort_ = LibrarySort::Recent;
// Search filters (the row of buttons under the keys).
- bool filterFree_ = false, filterCheapest_ = false;
+ bool filterFree_ = false, filterCheapest_ = false, filterMouseKeyboard_ = false;
int filterConsole_ = 0; // 0 all, 1 Series X|S, 2 Xbox One, 3 Xbox 360
int filterMode_ = 0; // 0 all, single, online multiplayer, online co-op, local
std::string filterGenre_; // empty: all
diff --git a/src/ui/pad_icons.cpp b/src/ui/pad_icons.cpp
index aae8ac4..e45e6f1 100644
--- a/src/ui/pad_icons.cpp
+++ b/src/ui/pad_icons.cpp
@@ -2,6 +2,7 @@
// Copyright (C) 2026 RafaelNGP
#include "ui/pad_icons.h"
+#include <algorithm>
#include <string>
#include <utility>
@@ -16,6 +17,17 @@ Color playerColor(int index) {
}
}
+void drawKeyboardGlyph(Canvas& c, int x, int y, int w, Color color) {
+ int h = w * 10 / 24, t = std::max(2, w / 14), r = std::max(2, w / 10);
+ c.strokeRect({x, y, w, h}, color, t, r);
+ int key = std::max(2, w / 12), gap = (w - 2 * t - 2 * key) / 6;
+ for (int row = 0; row < 2; ++row) // two rows of six keys
+ for (int k = 0; k < 6; ++k)
+ c.fillRect({x + t + key + k * gap, y + t + key / 2 + row * (key + key / 2 + 1), std::max(1, gap - key / 2), key},
+ color, 1);
+ c.fillRect({x + w / 4, y + h - t - key - key / 2, w / 2, key}, color, 1); // the space bar
+}
+
int padIconHeight(int w) { return w * 7 / 10 + 4 + w * 3 / 10; }
void drawPadIcon(Canvas& c, const Font& font, int x, int y, int w, int index, bool connected, Color background) {
@@ -63,8 +75,21 @@ void drawPadIcon(Canvas& c, const Font& font, int x, int y, int w, int index, bo
}
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)
- drawPadIcon(c, font, x + i * (w + gap), y, w, i, pads[i].connected, 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);
+ }
return static_cast<int>(pads.size()) * (w + gap) - gap;
}
diff --git a/src/ui/pad_icons.h b/src/ui/pad_icons.h
index fe806ad..432edb3 100644
--- a/src/ui/pad_icons.h
+++ b/src/ui/pad_icons.h
@@ -13,7 +13,8 @@ namespace xc::ui {
struct PadSlot {
bool connected = false;
- std::string name; // the PS5 user's
+ std::string name; // the PS5 user's
+ bool keyboard = false; // a USB keyboard and mouse plays in this slot
};
using PadSlots = std::array<PadSlot, 4>;
@@ -21,6 +22,10 @@ using PadSlots = std::array<PadSlot, 4>;
// green, pink.
Color playerColor(int index);
+// A keyboard, `w` wide (about w / 2.4 tall), its top-left at (x, y): an
+// outline and three rows of keys, in `color` (cards, the players' row).
+void drawKeyboardGlyph(Canvas& c, int x, int y, int w, Color color);
+
// One pad, a DualSense `w` wide with its number `index + 1` below
// (padIconHeight(w) in all): in the player's colour when connected, dim
// when not. Its buttons are cut out in `background`, the colour behind it.
diff --git a/src/ui/strings.cpp b/src/ui/strings.cpp
index eb3b474..37b607b 100644
--- a/src/ui/strings.cpp
+++ b/src/ui/strings.cpp
@@ -270,6 +270,11 @@ constexpr Column kEnglish = {
"Automatic", // BitrateAuto
"Game volume", // GameVolume
"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
};
constexpr Column kPortugueseBR = {
@@ -510,6 +515,11 @@ constexpr Column kPortugueseBR = {
"Automático", // BitrateAuto
"Volume do jogo", // GameVolume
"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
};
constexpr Column kSpanish = {
@@ -750,6 +760,11 @@ constexpr Column kSpanish = {
"Automático", // BitrateAuto
"Volumen del juego", // GameVolume
"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
};
constexpr Column kFrench = {
@@ -990,6 +1005,11 @@ constexpr Column kFrench = {
"Automatique", // BitrateAuto
"Volume du jeu", // GameVolume
"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
};
constexpr Column kGerman = {
@@ -1230,6 +1250,11 @@ constexpr Column kGerman = {
"Automatisch", // BitrateAuto
"Spiellautstärke", // GameVolume
"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
};
constexpr Column kItalian = {
@@ -1470,6 +1495,11 @@ constexpr Column kItalian = {
"Automatico", // BitrateAuto
"Volume del gioco", // GameVolume
"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
};
constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,
diff --git a/src/ui/strings.h b/src/ui/strings.h
index 1c15ace..6db95df 100644
--- a/src/ui/strings.h
+++ b/src/ui/strings.h
@@ -247,6 +247,11 @@ enum class Str {
BitrateAuto, // ... its default: the resolution's own
GameVolume, // Settings row: the game's sound level
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 keyboard
+ MouseKeyboardSupport, // 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)
Count
};
diff --git a/src/xcloud/gssv.cpp b/src/xcloud/gssv.cpp
index 6f2177e..4f469eb 100644
--- a/src/xcloud/gssv.cpp
+++ b/src/xcloud/gssv.cpp
@@ -311,6 +311,7 @@ bool GssvClient::listTitles(std::vector<Title>& out, std::string& err, bool rece
uint64_t started = platform::nowMs();
std::string continuation;
int pages = 0;
+ std::map<std::string, int> inputTypes; // for the log: how many titles take each
do {
std::string path = recentOnly ? "/v2/titles/mru?mr=25" : "/v2/titles?mr=200";
if (!continuation.empty()) path += "&ct=" + net::urlEncode(continuation);
@@ -331,6 +332,10 @@ bool GssvClient::listTitles(std::vector<Title>& out, std::string& err, bool rece
title.hasEntitlement = t["details"]["hasEntitlement"].asBool();
title.xboxTitleId = t["details"]["xboxTitleId"].str();
title.isFreeInStore = t["details"]["isFreeInStore"].asBool();
+ for (const auto& input : t["details"]["supportedInputTypes"].items()) {
+ ++inputTypes[input.str()];
+ if (input.str() == "MKB") title.mouseKeyboard = true;
+ }
// What lets this account play it: a subscription's program
// (CALLISTO for Game Pass in the cloud) or F2P; none when bought.
for (const auto& program : t["details"]["userPrograms"].items())
@@ -349,6 +354,11 @@ bool GssvClient::listTitles(std::vector<Title>& out, std::string& err, bool rece
} while (!continuation.empty() && out.size() < 5000);
XC_LOGI("title list%s: %zu titles in %llu ms", recentOnly ? " (recent)" : "", out.size(),
static_cast<unsigned long long>(platform::nowMs() - started));
+ if (!inputTypes.empty()) {
+ std::string types;
+ for (const auto& [name, n] : inputTypes) types += (types.empty() ? "" : ", ") + name + " " + std::to_string(n);
+ XC_LOGI("title list: input types: %s", types.c_str());
+ }
return true;
}
diff --git a/src/xcloud/gssv.h b/src/xcloud/gssv.h
index 4148416..ed30aa1 100644
--- a/src/xcloud/gssv.h
+++ b/src/xcloud/gssv.h
@@ -42,6 +42,9 @@ struct Title {
// besides F2P, such as CALLISTO for Game Pass). Entitled but not this:
// the account's own game, bought or free-to-play.
bool viaSubscription = false;
+ // The cloud streams it with native mouse and keyboard (its
+ // supportedInputTypes has "MKB").
+ bool mouseKeyboard = false;
};
// One of the user's own consoles (xhome offering), from /v6/servers/home.
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 5085c65..1dafde7 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -949,6 +949,25 @@ static void testKeyboardNav() {
CHECK(!p3.btnA && !p3.dpadUp && p3.rightStickY == 0.0f);
}
+// The keyboard and mouse as a controller of their own.
+static void testKeyboardAsGamepad() {
+ xc::input::KbmInput in;
+ in.keyboard = true;
+ in.held = {0x20, 'D', 'W'}; // space, d, w (sorted)
+ in.buttons = 1; // left button
+ in.dx = 24; // a fast move right
+ xc::input::MouseStick stick;
+ xc::input::ControllerState out;
+ xc::input::keyboardAsGamepad(in, stick, out);
+ CHECK(out.connected && out.btnA && out.leftStickX == 1.0f && out.leftStickY == -1.0f);
+ CHECK(out.triggerR2 == 1.0f && out.triggerL2 == 0.0f);
+ CHECK(out.rightStickX > 0.4f && out.rightStickY == 0.0f);
+ in = {};
+ in.keyboard = true;
+ for (int i = 0; i < 20; ++i) xc::input::keyboardAsGamepad(in, stick, out); // the mouse still: back to the centre
+ CHECK(out.rightStickX == 0.0f && !out.btnA);
+}
+
int main() {
testReport();
testCrashGuard();
@@ -979,6 +998,7 @@ int main() {
testMouseKeyboardReports();
testHidToVk();
testKeyboardNav();
+ testKeyboardAsGamepad();
testTeredo();
if (g_failures) {
std::fprintf(stderr, "%d failure(s)\n", g_failures);