Xbox Cloud Gaming app for PS5 Homebrew
C
Controller buttons: remap the pad toward the game, never the menus
Rafael Abud Ferreira87509eea4ede
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 05eeb3f..d1cd19c 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -38,6 +38,7 @@ add_library(xcloud_core STATICsrc/input/controller_common.cppsrc/input/kbm_map.cppsrc/input/key_map.cpp+ src/input/pad_map.cppsrc/input/keyboard_nav.cppsrc/input/sdl_mapping.cppsrc/xcloud/social.cppdiff --git a/src/app/app_core.cpp b/src/app/app_core.cppindex 9db4d45..fa2dbf9 100644--- a/src/app/app_core.cpp+++ b/src/app/app_core.cpp@@ -21,6 +21,7 @@#include "input/input_ext.h"#include "input/kbm.h"#include "input/keyboard_nav.h"+#include "input/pad_map.h"#include "ui/input_mode.h"#include "ui/pad_glyphs.h"#include "input/tuning.h"@@ -110,6 +111,7 @@ bool saveSettings(const ui::SettingsChoice& choice) {g_settings.maxBitrateMbps = choice.maxBitrateMbps;g_settings.gameVolume = choice.gameVolume;g_settings.keyMap = choice.keyMap;+ if (input::padMapValid(choice.padMap)) g_settings.padMap = choice.padMap; // the screen only lets a complete one outfullscreenChanged = g_settings.desktopFullscreen != choice.fullscreen;g_settings.desktopFullscreen = choice.fullscreen;g_settings.save(settingsPath()); // warns itself@@ -307,6 +309,7 @@ bool coreStartup() {choice.maxBitrateMbps = g_settings.maxBitrateMbps;choice.gameVolume = g_settings.gameVolume;choice.keyMap = g_settings.keyMap;+ choice.padMap = g_settings.padMap;choice.fullscreen = g_settings.desktopFullscreen;g_ui->setAllow1440(allow1440Locked());g_ui->setUpdateState(XC_APP_VERSION, {}, false); // Settings shows this version before any check@@ -557,6 +560,7 @@ bool Core::frame() {nav.dpadRight = dpadRight.update(pad.dpadRight, now);nav.rawLX = pad.rawLeftX, nav.rawLY = pad.rawLeftY, nav.rawRX = pad.rawRightX, nav.rawRY = pad.rawRightY;nav.l2Analog = pad.triggerL2, nav.r2Analog = pad.triggerR2;+ nav.padPressed = input::padButtons(pad) & ~input::padButtons(prev); // the pad as it is: never through the game's map// Smooth scrolling. The right stick: a speed that follows how far it// is pushed (up to ~12 rows / 16 cards a second). The touchpad,// touched (not pressed): the list follows the finger (its height ~6diff --git a/src/app/desktop_selftest.cpp b/src/app/desktop_selftest.cppindex 7691c69..2197d92 100644--- a/src/app/desktop_selftest.cpp+++ b/src/app/desktop_selftest.cpp@@ -12,6 +12,7 @@#include "display/display_sdl.h"#include "input/controller.h"#include "input/input_ext.h"+#include "input/pad_map.h"#include "media/audio_in.h"#include "media/audio_out.h"#include "platform/platform.h"@@ -206,6 +207,12 @@ int desktopSelftest(const std::string& dir) {ui.render(canvas, platform::nowMs());drawCanvas(canvas);check(screenshot(dir, "2-settings.png", shot) && varied(shot), "Settings screen (2-settings.png)");+ // The PS5's Settings, every row shown (the console's own capabilities).+ ui.setCaps(ui::UiCaps{});+ ui.render(canvas, platform::nowMs());+ drawCanvas(canvas);+ check(screenshot(dir, "2e-settings-all-rows.png", shot) && varied(shot), "Settings with every row (2e-settings-all-rows.png)");+ ui.setCaps(caps);// The same with an Xbox pad's glyphs (A / B, Menu, View...).{const std::vector<uint8_t> ps = shot.rgb;@@ -226,6 +233,77 @@ int desktopSelftest(const std::string& dir) {ui::g_glyphStyle = ui::GlyphStyle::PlayStation;ui.invalidate();}+ // Settings > Controller buttons: the map as it is, a row cleared (Circle+ // then stays, naming it), a press captured, and a complete map kept on+ // the way out (A and B swapped).+ {+ auto step = [&](auto set) {+ ui::NavInput in;+ set(in);+ in.nowMs = platform::nowMs();+ ui.handle(in);+ ui.render(canvas, platform::nowMs());+ drawCanvas(canvas);+ };+ auto bit = [](input::PadFn f) { return 1u << static_cast<int>(f); };+ step([](ui::NavInput& in) { in.options = true; });+ const int downs = [&] {+ auto shown = ui::visibleSettingsRows(caps);+ for (size_t i = 0; i < shown.size(); ++i)+ if (shown[i].row == 14) return static_cast<int>(i);+ return -1;+ }();+ check(downs > 0, "Settings has the Controller buttons row");+ for (int i = 0; i < downs; ++i) step([](ui::NavInput& in) { in.down = true; });+ step([](ui::NavInput& in) { in.accept = true; });+ check(screenshot(dir, "5-padmap.png", shot) && varied(shot), "Controller buttons screen (5-padmap.png)");+ step([](ui::NavInput& in) { in.square = true; }); // A cleared+ step([](ui::NavInput& in) { in.back = true; }); // refused: A has no button+ check(ui.screen() == ui::Screen::Settings && ui.settings().padMap == input::defaultPadMap() &&+ screenshot(dir, "5b-padmap-incomplete.png", shot) && varied(shot),+ "an incomplete map stays on its screen, unsaved (5b-padmap-incomplete.png)");+ step([](ui::NavInput& in) { in.accept = true; }); // A: waiting for a press+ check(screenshot(dir, "5c-padmap-capture.png", shot) && varied(shot), "waiting for a press (5c-padmap-capture.png)");+ step([&](ui::NavInput& in) { in.padPressed = bit(input::PadFn::B); }); // Circle -> A (B now has none)+ step([](ui::NavInput& in) { in.down = true; });+ step([](ui::NavInput& in) { in.accept = true; });+ step([&](ui::NavInput& in) { in.padPressed = bit(input::PadFn::A); }); // Cross -> B+ check(screenshot(dir, "5d-padmap-swapped.png", shot) && varied(shot), "A and B swapped (5d-padmap-swapped.png)");+ step([](ui::NavInput& in) { in.back = true; }); // complete: kept+ input::PadMap swapped = input::defaultPadMap();+ input::assignPadSource(swapped, input::PadFn::A, static_cast<uint8_t>(input::PadFn::B));+ check(ui.settings().padMap == swapped, "a complete map is kept on the way out");+ // Back to the default for the rest (Reset to default, then out).+ step([](ui::NavInput& in) { in.accept = true; });+ for (int i = 0; i < 8; ++i) step([](ui::NavInput& in) { in.down = true; });+ step([](ui::NavInput& in) { in.accept = true; });+ step([](ui::NavInput& in) { in.back = true; });+ check(ui.settings().padMap == input::defaultPadMap(), "Reset to default");+ step([](ui::NavInput& in) { in.back = true; }); // the home screen+ // A game's settings with every row (the PS5's), its Controller+ // buttons row opening the screen on the game's map; Discard leaves.+ ui.setCaps(ui::UiCaps{});+ ui::GameTile game;+ game.productId = "SELFTEST";+ game.titleId = "selftest";+ game.name = "Self-test game";+ ui.showDetails(game);+ step([](ui::NavInput& in) { in.options = true; });+ check(screenshot(dir, "5e-game-settings.png", shot) && varied(shot), "a game's settings (5e-game-settings.png)");+ const auto gameRows = ui::visibleGameSettingsRows(ui::UiCaps{}, false);+ for (size_t i = 0; i < gameRows.size() && gameRows[i].row != 11; ++i) step([](ui::NavInput& in) { in.down = true; });+ step([](ui::NavInput& in) { in.accept = true; });+ step([](ui::NavInput& in) { in.square = true; });+ check(screenshot(dir, "5f-game-padmap.png", shot) && varied(shot), "the game's controller buttons (5f-game-padmap.png)");+ step([](ui::NavInput& in) { in.up = true; }); // Reset / Discard+ step([](ui::NavInput& in) { in.right = true; }); // Discard changes+ step([](ui::NavInput& in) { in.accept = true; });+ check(screenshot(dir, "5g-game-settings-after.png", shot) && varied(shot), "discarded: still Default (5g-game-settings-after.png)");+ step([](ui::NavInput& in) { in.back = true; });+ step([](ui::NavInput& in) { in.back = true; });+ ui.setCaps(caps);+ ui.showHome();+ }// The search typed on the keyboard: the shell's text input, the text// through AppUi::typeText().{diff --git a/src/app/settings.cpp b/src/app/settings.cppindex 4befa9d..d5bec06 100644--- a/src/app/settings.cpp+++ b/src/app/settings.cpp@@ -32,6 +32,15 @@ json::Value keyMapJson(const input::KeyMap& m) {return v;}+// "padMap": absent keeps `fallback`; present but not a complete map of+// this version (an edited or damaged file) gives the default map.+input::PadMap readPadMapOr(const json::Value& v, const input::PadMap& fallback, const char* where) {+ if (v.isNull()) return fallback;+ input::PadMap m;+ if (!input::readPadMap(v, m)) XC_LOGW("settings: controller buttons of %s not valid; back to the default", where);+ return m;+}+} // namespacebool Settings::load(const std::string& path) {@@ -77,6 +86,7 @@ bool Settings::load(const std::string& path) {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));keyMap = readKeyMap((*j)["keyMap"], input::defaultKeyMap());+ padMap = readPadMapOr((*j)["padMap"], input::defaultPadMap(), "the settings");keyboardPlayer = static_cast<int>(std::clamp<int64_t>((*j)["keyboardPlayer"].asInt(keyboardPlayer), 0, 3));gyroMode = static_cast<int>(std::clamp<int64_t>((*j)["gyroMode"].asInt(gyroMode), 0, 2));gyroLevel = static_cast<int>(std::clamp<int64_t>((*j)["gyroLevel"].asInt(gyroLevel), 1, 10));@@ -115,6 +125,7 @@ bool Settings::load(const std::string& path) {p.circleConfirms = obj["circleConfirms"].asBool(circleConfirms);p.highRefresh = obj["highRefresh"].asBool(highRefresh);p.keyMap = readKeyMap(obj["keyMap"], keyMap);+ p.padMap = readPadMapOr(obj["padMap"], padMap, id.c_str());p.gyroMode = static_cast<int>(std::clamp<int64_t>(obj["gyroMode"].asInt(gyroMode), 0, 2));p.gyroLevel = static_cast<int>(std::clamp<int64_t>(obj["gyroLevel"].asInt(gyroLevel), 1, 10));perGame[id] = p;@@ -142,6 +153,7 @@ GameProfile Settings::defaultProfile() const {p.circleConfirms = circleConfirms;p.highRefresh = highRefresh;p.keyMap = keyMap;+ p.padMap = padMap;p.gyroMode = gyroMode;p.gyroLevel = gyroLevel;return p;@@ -202,6 +214,7 @@ bool Settings::save(const std::string& path) const {v.set("maxBitrateMbps", maxBitrateMbps);v.set("gameVolume", gameVolume);v.set("keyMap", keyMapJson(keyMap));+ v.set("padMap", input::padMapJson(padMap));v.set("keyboardPlayer", keyboardPlayer);v.set("gyroMode", gyroMode);v.set("gyroLevel", gyroLevel);@@ -228,6 +241,7 @@ bool Settings::save(const std::string& path) const {obj.set("circleConfirms", p.circleConfirms);obj.set("highRefresh", p.highRefresh);obj.set("keyMap", keyMapJson(p.keyMap));+ obj.set("padMap", input::padMapJson(p.padMap));obj.set("gyroMode", p.gyroMode);obj.set("gyroLevel", p.gyroLevel);pg.set(id, obj);diff --git a/src/app/settings.h b/src/app/settings.hindex 6373fde..6031453 100644--- a/src/app/settings.h+++ b/src/app/settings.h@@ -4,6 +4,7 @@#pragma once#include "input/key_map.h"+#include "input/pad_map.h"#include <cstdint>#include <map>@@ -29,6 +30,8 @@ struct GameProfile {bool highRefresh = false; // 120 Hz output (VRR) while streaming// Keyboard and mouse as a controller: which keys play whatinput::KeyMap keyMap = input::defaultKeyMap();+ // The controller's buttons toward the game (input/pad_map.h)+ input::PadMap padMap = input::defaultPadMap();// Gyro aiming: 0 off, 1 always, 2 while L2 is held; intensity 1..10int gyroMode = 0;int gyroLevel = 5;@@ -82,6 +85,9 @@ struct Settings {int 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 150input::KeyMap keyMap = input::defaultKeyMap(); // the keys when the keyboard is a player's controller+ // Which pad button plays which Xbox button in a game (input/pad_map.h;+ // the menus always read the buttons as they are). Always complete.+ input::PadMap padMap = input::defaultPadMap();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 gyroMode = 0; // gyro aiming (input/gyro.h): 0 off, 1 always, 2 while L2 is heldint gyroLevel = 5; // its intensity, 1..10diff --git a/src/app/stream_screen.cpp b/src/app/stream_screen.cppindex ff9f146..6b3afd8 100644--- a/src/app/stream_screen.cpp+++ b/src/app/stream_screen.cpp@@ -137,6 +137,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bdeadzone_ = prof.deadzoneLeft;circleConfirms_ = prof.circleConfirms;keyMap_ = prof.keyMap;+ padMap_ = prof.padMap;gyroMode_ = prof.gyroMode;gyroLevel_ = prof.gyroLevel;input::setGyro(gyroMode_, gyroLevel_);@@ -224,6 +225,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bauto had = g_settings.perGame.find(gameKey_); // not set from this menu: keptp.highRefresh = had != g_settings.perGame.end() ? had->second.highRefresh : g_settings.highRefresh;p.keyMap = had != g_settings.perGame.end() ? had->second.keyMap : g_settings.keyMap;+ p.padMap = had != g_settings.perGame.end() ? had->second.padMap : g_settings.padMap;p.gyroMode = gyroMode_;p.gyroLevel = gyroLevel_;g_settings.perGame[gameKey_] = p;@@ -237,6 +239,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bdeadzone_ = def.deadzoneLeft;triggerStrength_ = def.triggerStrength;keyMap_ = def.keyMap;+ padMap_ = def.padMap;circleConfirms_ = def.circleConfirms;gyroMode_ = def.gyroMode;gyroLevel_ = def.gyroLevel;@@ -349,7 +352,10 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b}overlaySeq_ = 0;}- input::ControllerState sent = pad;+ // The game gets the buttons through this game's map (Settings >+ // Controller buttons); everything above (the menu's combo, the+ // menu itself) read them as they are.+ input::ControllerState sent = input::applyPadMap(pad, padMap_);if (g_syntheticA) sent.btnA = true;// While another window has the focus on the cloud console (a// publisher's page such as NetEase's terms in Marvel Rivals,@@ -430,6 +436,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) other = input::applyPadMap(other, padMap_); // the same map as player 1's (the keys keep theirs)if (on && i == kbSlot) input::mergePads(other, kbPad_); // the keyboard plays with this player's padif (on != padAttached_[i]) {padAttached_[i] = on;diff --git a/src/app/stream_screen.h b/src/app/stream_screen.hindex 0fb144c..34ba70e 100644--- a/src/app/stream_screen.h+++ b/src/app/stream_screen.h@@ -11,6 +11,7 @@#include "input/controller.h"#include "input/kbm.h"#include "input/keyboard_nav.h"+#include "input/pad_map.h"#include "ui/app_ui.h"#include "ui/stream_menu.h"@@ -77,6 +78,7 @@ private:int deadzone_ = 15;bool circleConfirms_ = false;input::KeyMap keyMap_ = input::defaultKeyMap(); // this game's keys (the keyboard as a controller)+ input::PadMap padMap_ = input::defaultPadMap(); // this game's controller buttons, toward the game onlyint gyroMode_ = 0, gyroLevel_ = 5; // gyro aiming (input/gyro.h), this game'sbool highRefresh_ = false; // 120 Hz turned on for this streaminput::KbmInput kbm_;diff --git a/src/input/pad_map.cpp b/src/input/pad_map.cppnew file mode 100644index 0000000..4383e33--- /dev/null+++ b/src/input/pad_map.cpp@@ -0,0 +1,138 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+#include "input/pad_map.h"++#include "util/json.h"++#include <utility>++namespace xc::input {++namespace {++constexpr int kPadMapVersion = 1;+constexpr float kHalf = 0.5f;++// The button behind a PadFn in a state (const or not); null for the triggers.+template <class State>+auto buttonOf(State& s, int fn) -> decltype(&s.btnA) {+ switch (static_cast<PadFn>(fn)) {+ case PadFn::A: return &s.btnA;+ case PadFn::B: return &s.btnB;+ case PadFn::X: return &s.btnX;+ case PadFn::Y: return &s.btnY;+ case PadFn::LB: return &s.btnL1;+ case PadFn::RB: return &s.btnR1;+ case PadFn::LS: return &s.btnL3;+ case PadFn::RS: return &s.btnR3;+ case PadFn::View: return &s.btnTouchpad;+ case PadFn::Menu: return &s.btnOptions;+ case PadFn::Up: return &s.dpadUp;+ case PadFn::Down: return &s.dpadDown;+ case PadFn::Left: return &s.dpadLeft;+ case PadFn::Right: return &s.dpadRight;+ default: return nullptr; // the triggers+ }+}++// How far a source is pressed, 0..1 (a button: 0 or 1).+float amountOf(const ControllerState& s, uint8_t src) {+ if (src == static_cast<uint8_t>(PadFn::LT)) return s.triggerL2;+ if (src == static_cast<uint8_t>(PadFn::RT)) return s.triggerR2;+ if (src >= kPadFns) return 0.0f;+ const bool* b = buttonOf(s, src);+ return b && *b ? 1.0f : 0.0f;+}++} // namespace++PadMap defaultPadMap() {+ PadMap m{};+ for (int i = 0; i < kPadFns; ++i) m[static_cast<size_t>(i)] = static_cast<uint8_t>(i);+ return m;+}++ControllerState applyPadMap(const ControllerState& in, const PadMap& map) {+ ControllerState out = in; // sticks, touch, the Xbox button+ for (int fn = 0; fn < kPadFns; ++fn) {+ float v = amountOf(in, map[static_cast<size_t>(fn)]);+ if (fn == static_cast<int>(PadFn::LT)) out.triggerL2 = v;+ else if (fn == static_cast<int>(PadFn::RT)) out.triggerR2 = v;+ else *buttonOf(out, fn) = v > kHalf;+ }+ return out;+}++uint32_t padButtons(const ControllerState& s) {+ uint32_t bits = 0;+ for (int i = 0; i < kPadFns; ++i)+ if (amountOf(s, static_cast<uint8_t>(i)) > kHalf) bits |= 1u << i;+ return bits;+}++void assignPadSource(PadMap& map, PadFn fn, uint8_t source) {+ const auto f = static_cast<size_t>(fn);+ if (f >= map.size()) return;+ if (source != kPadNone)+ for (auto& s : map)+ if (s == source) s = map[f]; // the other button takes fn's old source+ map[f] = source;+}++uint32_t padMapMissing(const PadMap& map) {+ uint32_t bits = 0;+ for (int i = 0; i < kPadFns; ++i)+ if (map[static_cast<size_t>(i)] >= kPadFns) bits |= 1u << i;+ return bits;+}++bool padMapValid(const PadMap& map) {+ uint32_t seen = 0;+ for (uint8_t s : map) {+ if (s >= kPadFns || (seen & (1u << s))) return false;+ seen |= 1u << s;+ }+ return true;+}++uint8_t physicalSource(uint8_t source, bool circleConfirms) {+ if (!circleConfirms) return source;+ if (source == static_cast<uint8_t>(PadFn::A)) return static_cast<uint8_t>(PadFn::B);+ if (source == static_cast<uint8_t>(PadFn::B)) return static_cast<uint8_t>(PadFn::A);+ return source;+}++const char* padFnName(PadFn fn) {+ static constexpr const char* kNames[kPadFns] = {"A", "B", "X", "Y", "LB", "RB", "LT", "RT",+ "LS", "RS", "View", "Menu", "D-pad up", "D-pad down", "D-pad left", "D-pad right"};+ auto i = static_cast<size_t>(fn);+ return i < static_cast<size_t>(kPadFns) ? kNames[i] : "?";+}++json::Value padMapJson(const PadMap& map) {+ json::Value v = json::Value::object();+ v.set("version", kPadMapVersion);+ json::Value items = json::Value::array();+ for (uint8_t s : map) items.push(static_cast<int>(s));+ v.set("map", std::move(items));+ return v;+}++bool readPadMap(const json::Value& v, PadMap& out) {+ out = defaultPadMap();+ if (!v.isObject() || v["version"].asInt(0) != kPadMapVersion) return false;+ const json::Value& items = v["map"];+ if (!items.isArray() || items.size() != static_cast<size_t>(kPadFns)) return false;+ PadMap m{};+ for (int i = 0; i < kPadFns; ++i) {+ const json::Value& s = items[i];+ int64_t n = s.asInt(-1);+ if (!s.isNumber() || n < 0 || n >= kPadFns) return false;+ m[static_cast<size_t>(i)] = static_cast<uint8_t>(n);+ }+ if (!padMapValid(m)) return false;+ out = m;+ return true;+}++} // namespace xc::inputdiff --git a/src/input/pad_map.h b/src/input/pad_map.hnew file mode 100644index 0000000..97ed1d9--- /dev/null+++ b/src/input/pad_map.h@@ -0,0 +1,73 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+// Which of the controller's buttons plays which Xbox button in a game,+// chosen in Settings (and per game) on the "Controller buttons" screen.+//+// The map only changes what the game is sent (applyPadMap(), in the+// stream's input report): the app's menus, its Settings and the in-game+// menu's combo always read the buttons as they are, so a bad map can never+// keep anyone from going back to fix it.+//+// Order with "Circle confirms" (input::setCircleConfirms): that swap of+// Cross and Circle happens first, in input::pollPad(), for the menus and+// the game alike; this map is applied after it, to the game's copy only.+// A map's sources are therefore the ControllerState's slots as the menus+// see them (with the swap on, slot A is the physical Circle);+// physicalSource() turns one back into the button on the pad.+#pragma once++#include "input/controller.h"++#include <array>+#include <cstdint>+#include <string>++namespace xc::json {+class Value;+}++namespace xc::input {++// The Xbox buttons a game is sent, and (the same indices) the pad's+// buttons that can feed them: A B X Y are the south, east, west and north+// face buttons (Cross, Circle, Square, Triangle), LB RB L1 R1, LT RT the+// triggers L2 R2, LS RS the stick clicks, View the touchpad (Create on an+// Xbox-like pad: Back/View), Menu Options. The sticks aren't remapped.+enum class PadFn : uint8_t { A, B, X, Y, LB, RB, LT, RT, LS, RS, View, Menu, Up, Down, Left, Right, Count };+constexpr int kPadFns = static_cast<int>(PadFn::Count);+// No button (a row cleared on the screen; never valid to keep).+constexpr uint8_t kPadNone = 0xFF;++// map[fn]: the source (a PadFn index) that feeds fn, or kPadNone.+using PadMap = std::array<uint8_t, kPadFns>;++// Every button plays itself.+PadMap defaultPadMap();+// The game's copy of `in`: each Xbox button pressed while its source is.+// A trigger fed by a trigger keeps how far it is pressed; fed by a button,+// it is fully pressed with it. A button fed by a trigger is pressed past+// halfway. Sticks, touch and the Xbox button pass as they are.+ControllerState applyPadMap(const ControllerState& in, const PadMap& map);+// The sources pressed now, a bit per PadFn index (triggers past halfway).+uint32_t padButtons(const ControllerState& s);+// Puts `source` on `fn`. A source already feeding another button swaps+// with it (that one gets fn's old source), so a complete map stays complete.+void assignPadSource(PadMap& map, PadFn fn, uint8_t source);+// The Xbox buttons with no source, a bit per PadFn (0: none missing).+uint32_t padMapMissing(const PadMap& map);+// Every Xbox button has exactly one source and no source feeds two.+bool padMapValid(const PadMap& map);+// The button on the pad behind a source, with "Circle confirms" on or off+// (A and B swapped back).+uint8_t physicalSource(uint8_t source, bool circleConfirms);+// "A", "LB", "View", "D-pad up"... (log and test names).+const char* padFnName(PadFn fn);++// {"version":1,"map":[16 sources]} in PadFn order.+json::Value padMapJson(const PadMap& map);+// Reads it back into `out`. Anything else (another version, size, a+// source out of range, an incomplete or duplicated map) gives false and+// `out` the default map.+bool readPadMap(const json::Value& v, PadMap& out);++} // namespace xc::inputdiff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex c7b4485..5d0a10a 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -60,14 +60,15 @@ constexpr int kResolutionOrder[3] = {1, 0, 2};// stream (resolution, a desktop's display mode, 120 Hz, bitrate, region);// sound; the controller and keyboard; updates last. A group starts at each// kSettingsGroupStart.-constexpr int kSettingsOrder[kSettingRows] = {0, 8, 1, 13, 9, 10, 2, 11, 3, 4, 5, 6, 12, 7};-constexpr bool kSettingsGroupStart[kSettingRows] = {false, false, true, false, false, false, false,- true, true, false, false, false, false, true};+constexpr int kSettingsOrder[kSettingRows] = {0, 8, 1, 13, 9, 10, 2, 11, 3, 4, 5, 6, 14, 12, 7};+constexpr bool kSettingsGroupStart[kSettingRows] = {false, false, true, false, false, false, false, true,+ true, false, false, false, false, false, true};// The game settings' rows on screen (ids: 0 profile, 1 upscaler, 2// sharpness, 3 block smoothing, 4 resolution, 5 dead zone, 6 triggers, 7-// confirm, 8 120 Hz, 9 keyboard keys, 10 back to the default).-constexpr int kGameRowOrder[11] = {0, 4, 8, 1, 2, 3, 5, 6, 7, 9, 10};-constexpr bool kGameGroupStart[11] = {false, true, false, true, false, false, true, false, false, false, true};+// confirm, 8 120 Hz, 9 keyboard keys, 10 back to the default, 11 controller+// buttons).+constexpr int kGameRowOrder[12] = {0, 4, 8, 1, 2, 3, 5, 6, 7, 11, 9, 10};+constexpr bool kGameGroupStart[12] = {false, true, false, true, false, false, true, false, false, false, false, true};// The keyboard keys' screen: two columns of inputs, then "Reset to default".constexpr int kKeysPerColumn = input::kKeyActions / 2;// Updates on a desktop: the newest release's page (the app doesn't install it there).@@ -1109,10 +1110,79 @@ void AppUi::handleKeysTester(const NavInput& in) {}}+void AppUi::openPadTester() {+ // Caller holds mutex_. A copy of the map in force (Settings', or the+ // game's with its settings open) is what the screen edits.+ tester_ = Tester::Pad;+ padWork_ = gameSettingsOpen_ ? activeGameProfile_.padMap : settings_.padMap;+ if (!input::padMapValid(padWork_)) padWork_ = input::defaultPadMap();+ padRow_ = padCol_ = 0;+ padCaptureSince_ = 0;+ dirty_ = true;+}++void AppUi::handlePadTester(const NavInput& in) {+ // Caller holds mutex_. The screen reads the pad as it is (the map only+ // changes what a game is sent), so it always answers. Edits stay in+ // padWork_: Circle keeps them only when every Xbox button has one+ // button (else the screen stays, naming what's missing); "Reset to+ // default" and "Discard changes" are always there below.+ //+ // The map's sources are the pad's slots after "Circle confirms"+ // (input/pad_map.h): a press comes in with the menus' swap (circleConfirms_)+ // and is stored with the one the map plays under (the game's own with+ // its settings open).+ const bool mapSwap = gameSettingsOpen_ ? activeGameProfile_.circleConfirms : settings_.circleConfirms;+ constexpr int kPerColumn = input::kPadFns / 2, kButtonsRow = kPerColumn;+ const auto fn = static_cast<input::PadFn>(padCol_ * kPerColumn + std::min(padRow_, kPerColumn - 1));+ if (padCaptureSince_) {+ // Waiting for a press: the next button pressed (Circle too; the PS+ // / Home button isn't one) is the one; 5 s without one give up.+ if (in.padPressed) {+ uint8_t slot = 0;+ while (!(in.padPressed & (1u << slot))) ++slot;+ const uint8_t onPad = input::physicalSource(slot, circleConfirms_);+ input::assignPadSource(padWork_, fn, input::physicalSource(onPad, mapSwap));+ padCaptureSince_ = 0;+ dirty_ = true;+ } else if (in.nowMs > padCaptureSince_ && in.nowMs - padCaptureSince_ > 5000) {+ padCaptureSince_ = 0;+ dirty_ = true;+ }+ return;+ }+ if (in.up) padRow_ = (padRow_ + kButtonsRow) % (kButtonsRow + 1), dirty_ = true;+ if (in.down) padRow_ = (padRow_ + 1) % (kButtonsRow + 1), dirty_ = true;+ if (in.left || in.right) padCol_ = 1 - padCol_, dirty_ = true;+ if (in.accept) {+ dirty_ = true;+ if (padRow_ < kButtonsRow) {+ padCaptureSince_ = in.nowMs ? in.nowMs : 1;+ } else if (padCol_ == 0) {+ padWork_ = input::defaultPadMap(); // Reset to default (kept on the way out)+ } else {+ tester_ = Tester::None; // Discard changes: what was saved stays+ return;+ }+ }+ if (in.square && padRow_ < kButtonsRow) input::assignPadSource(padWork_, fn, input::kPadNone), dirty_ = true;+ if (in.back) {+ dirty_ = true;+ if (!input::padMapValid(padWork_)) return; // incomplete: the warning says what's missing+ if (gameSettingsOpen_) {+ if (padWork_ != activeGameProfile_.padMap) activeGameProfile_.padMap = padWork_, activeGameHasCustom_ = true;+ } else {+ settings_.padMap = padWork_; // saved with Settings, as the other choices+ }+ tester_ = Tester::None;+ }+}+void AppUi::handleTester(const NavInput& in) {// Caller holds mutex_. Changes apply as they are made (the pad follows);// Cross keeps them, Circle puts the old ones back.if (tester_ == Tester::Keys) return handleKeysTester(in);+ if (tester_ == Tester::Pad) return handlePadTester(in);if (tester_ == Tester::Sticks) {// L1 / R1 pick the stick, the D-pad (only: the sticks are what is// being tried) changes its dead zone.@@ -1298,6 +1368,7 @@ void AppUi::openGameSettings() {activeGameProfile_.circleConfirms = settings_.circleConfirms;activeGameProfile_.highRefresh = settings_.highRefresh;activeGameProfile_.keyMap = settings_.keyMap;+ activeGameProfile_.padMap = settings_.padMap;activeGameProfile_.gyroMode = gyroMode_;activeGameProfile_.gyroLevel = gyroLevel_;}@@ -1414,6 +1485,9 @@ std::vector<std::string> AppUi::settingOptions(int row) const {} else if (row == 12) {// The keys' own screen changes them.out = {tr(settings_.keyMap == input::defaultKeyMap() ? Str::ProfileDefault : Str::ProfileCustom)};+ } else if (row == 14) {+ // So do the controller buttons'.+ out = {tr(settings_.padMap == input::defaultPadMap() ? Str::ProfileDefault : Str::ProfileCustom)};} else if (row == 8) {out.push_back(loginCountryOffText());@@ -1434,7 +1508,7 @@ int AppUi::settingSelected(int row) const {for (int i = 0; i < 3; ++i)if (kResolutionOrder[i] == settings_.resolution) return i;}- if (row == 3 || row == 12) return 0;+ if (row == 3 || row == 12 || row == 14) return 0;if (row == 4) return settings_.triggerStrength;if (row == 5) return settings_.circleConfirms ? 1 : 0;if (row == 6) return settings_.lightBarMode;@@ -1468,8 +1542,8 @@ void AppUi::applySetting(int row, int index) {setLanguage(static_cast<Language>(index)); // the UI switches right away} else if (row == 1) {settings_.resolution = kResolutionOrder[index];- } else if (row == 3 || row == 12) {- (void)index; // the tester sets each stick's, the keys' screen the keys+ } else if (row == 3 || row == 12 || row == 14) {+ (void)index; // the tester sets each stick's, the keys' and buttons' screens theirs} else if (row == 4) {settings_.triggerStrength = index;} else if (row == 5) {@@ -2237,9 +2311,13 @@ void AppUi::handleGameSettings(const NavInput& in, UiEvent& ev) {openTester(Tester::Keys);settings_.keyMap = activeGameProfile_.keyMap;break;+ case 11: // Controller buttons: their own screen, on this game's+ openPadTester();+ break;case 10: // Reset to defaultactiveGameHasCustom_ = false;activeGameProfile_.keyMap = settings_.keyMap;+ activeGameProfile_.padMap = settings_.padMap;activeGameProfile_.sharpness = settings_.sharpness;activeGameProfile_.deband = settings_.deband;activeGameProfile_.upscaler = settings_.upscaler;@@ -2369,7 +2447,9 @@ UiEvent AppUi::handle(const NavInput& in) {}if (in.right) changeSetting(+1);if (in.left) changeSetting(-1);- if (in.accept && (settingsRow_ == 3 || settingsRow_ == 4 || settingsRow_ == 12)) {+ if (in.accept && settingsRow_ == 14) {+ openPadTester(); // controller buttons: their own screen+ } else if (in.accept && (settingsRow_ == 3 || settingsRow_ == 4 || settingsRow_ == 12)) {// Dead zone, trigger vibration, keyboard keys: their own screens instead of a list.openTester(settingsRow_ == 3 ? Tester::Sticks : settingsRow_ == 4 ? Tester::Triggers : Tester::Keys);} else if (in.accept && settingsRow_ == 7) {@@ -3561,8 +3641,8 @@ void AppUi::drawSettings(Canvas& c) {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::KeyboardKeys), tr(Str::DisplayMode)};- constexpr int kRowW = 1200, kRowH = 46, kGap = 5, kGroupGap = 16;+ tr(Str::KeyboardKeys), tr(Str::DisplayMode), tr(Str::ControllerButtons)};+ constexpr int kRowW = 1200, kRowH = 46, kGap = 4, kGroupGap = 12;Rect rows[kSettingRows]; // by row idint y = 236;for (const auto& [i, groupStart] : visibleSettingsRows(caps_)) { // what caps_ rules out is hidden@@ -3619,6 +3699,7 @@ void AppUi::drawSettings(Canvas& c) {if (tester_ == Tester::Sticks) return drawStickTester(c);if (tester_ == Tester::Triggers) return drawTriggerTester(c);if (tester_ == Tester::Keys) return drawKeysTester(c);+ if (tester_ == Tester::Pad) return drawPadTester(c);if (dropdownOpen_) {// The list under (or, near the bottom, over) the row, right-aligned// with it; scrolls past kVisible choices.@@ -3880,6 +3961,98 @@ void AppUi::drawTriggerTester(Canvas& c) {fonts_.regular.draw(c, help[i], panel.x + 56, panel.y + panel.h - 70 + static_cast<int>(i) * 30, 22, kDim);}+void AppUi::drawPadTester(Canvas& c) {+ Rect panel = drawModal(c, 1500, 860, tr(Str::ControllerButtons));+ // Each Xbox button the game gets (as an Xbox pad shows it), then the+ // button on this pad that plays it (in the pad's own glyphs). Left+ // column the face buttons, shoulders and triggers; right the rest.+ constexpr int kPerColumn = input::kPadFns / 2;+ constexpr int kRowH = 52, kGap = 8, kChipW = 300, kColGap = 40;+ constexpr const char* kArrows[4] = {" \xE2\x86\x91", " \xE2\x86\x93", " \xE2\x86\x90", " \xE2\x86\x92"};+ static constexpr PadButton kButtons[12] = {PadButton::Cross, PadButton::Circle, PadButton::Square, PadButton::Triangle,+ PadButton::L1, PadButton::R1, PadButton::L2, PadButton::R2,+ PadButton::L3, PadButton::R3, PadButton::Touchpad, PadButton::Options};+ const GlyphStyle style = g_glyphStyle;+ const bool mapSwap = gameSettingsOpen_ ? activeGameProfile_.circleConfirms : settings_.circleConfirms;+ const bool capturing = padCaptureSince_ != 0;+ const std::string dpad = tr(Str::DPad);+ // A button (a PadFn index) drawn at (x, cy), left-aligned, in `s`'s glyphs.+ auto drawButton = [&](int i, GlyphStyle s, int x, int cy, Color color) {+ const int ty = fonts_.semibold.centeredY(cy - kRowH / 2, kRowH, 24);+ if (i >= 12) {+ fonts_.semibold.draw(c, dpad + kArrows[i - 12], x, ty, 24, color);+ } else if (i < 4) {+ ui::drawFaceButton(c, fonts_.bold, s, kButtons[i], x + 16.0f, static_cast<float>(cy), 16);+ if (s == GlyphStyle::PlayStation)+ fonts_.semibold.draw(c, buttonName(s, kButtons[i]), x + 44, ty, 24, color);+ } else {+ fonts_.semibold.draw(c, buttonName(s, kButtons[i]), x, ty, 24, color);+ }+ };+ const int colW = (panel.w - 112 - kColGap) / 2;+ for (int f = 0; f < input::kPadFns; ++f) {+ const int col = f / kPerColumn, row = f % kPerColumn;+ Rect r{panel.x + 56 + col * (colW + kColGap), panel.y + 106 + row * (kRowH + kGap), colW, kRowH};+ const bool on = row == padRow_ && col == padCol_;+ const int cy = r.y + r.h / 2;+ c.fillRect(r, on ? rgba(255, 255, 255, 30) : rgba(255, 255, 255, 12), 14);+ if (on && !capturing) c.strokeRect({r.x - 4, r.y - 4, r.w + 8, r.h + 8}, kWhite, 2, 18);+ drawButton(f, GlyphStyle::Xbox, r.x + 22, cy, kWhite);+ Rect chip{r.x + r.w - 10 - kChipW, r.y + 7, kChipW, r.h - 14};+ fonts_.regular.draw(c, "\xE2\x86\x90", chip.x - 44, fonts_.regular.centeredY(r.y, r.h, 24), 24, kDim);+ const uint8_t src = padWork_[static_cast<size_t>(f)];+ const bool none = src >= input::kPadFns, changed = src != f;+ c.fillRect(chip, none ? rgba(240, 100, 100, 40) : changed ? rgba(90, 170, 255, 60) : rgba(255, 255, 255, 26), 10);+ if (on && capturing) {+ c.strokeRect({chip.x - 4, chip.y - 4, chip.w + 8, chip.h + 8}, rgba(90, 220, 110), 3, 13);+ fonts_.semibold.draw(c, "...", chip.x + 20, fonts_.semibold.centeredY(chip.y, chip.h, 24), 24, kWhite);+ } else if (none) {+ fonts_.semibold.draw(c, "\xE2\x80\x94", chip.x + 20, fonts_.semibold.centeredY(chip.y, chip.h, 24), 24,+ rgba(240, 100, 100));+ } else {+ drawButton(input::physicalSource(src, mapSwap), style, chip.x + 16, cy, kWhite);+ }+ }+ // Reset to default and Discard changes, side by side under the columns.+ const int by = panel.y + 106 + kPerColumn * (kRowH + kGap) + 8;+ for (int col = 0; col < 2; ++col) {+ Rect b{panel.x + 56 + col * (colW + kColGap), by, colW, kRowH};+ const bool on = padRow_ == kPerColumn && padCol_ == col;+ c.fillRect(b, on ? rgba(255, 255, 255, 36) : rgba(255, 255, 255, 14), 14);+ if (on) c.strokeRect({b.x - 4, b.y - 4, b.w + 8, b.h + 8}, kWhite, 2, 18);+ const char* label = tr(col == 0 ? Str::ResetToDefault : Str::DiscardChanges);+ fonts_.semibold.draw(c, label, b.x + (b.w - fonts_.semibold.measure(label, 24)) / 2,+ fonts_.semibold.centeredY(b.y, b.h, 24), 24, on ? kWhite : rgba(240, 100, 100));+ }+ // Waiting for a press: say for what. Else what's missing (Circle won't+ // leave then), or the help.+ int hy = by + kRowH + 34;+ const uint32_t missing = input::padMapMissing(padWork_);+ if (capturing) {+ const auto fn = static_cast<input::PadFn>(padCol_ * kPerColumn + std::min(padRow_, kPerColumn - 1));+ std::string ask = trf(Str::PadPressButton, input::padFnName(fn));+ fonts_.bold.draw(c, ask, panel.x + (panel.w - fonts_.bold.measure(ask, 28)) / 2, hy, 28, kWhite);+ } else if (missing || !input::padMapValid(padWork_)) {+ std::string names;+ for (int f = 0; f < input::kPadFns; ++f)+ if (missing & (1u << f)) names += (names.empty() ? "" : ", ") + std::string(input::padFnName(static_cast<input::PadFn>(f)));+ auto lines = fonts_.semibold.wrap(trf(Str::PadMissing, names), 24, panel.w - 112, 2);+ for (size_t i = 0; i < lines.size(); ++i)+ fonts_.semibold.draw(c, lines[i], panel.x + 56, hy + static_cast<int>(i) * 32, 24, rgba(240, 100, 100));+ } else {+ auto help = fonts_.regular.wrap(tr(Str::PadHelp), 22, panel.w - 112, 2);+ for (size_t i = 0; i < help.size(); ++i)+ fonts_.regular.draw(c, help[i], panel.x + 56, hy + static_cast<int>(i) * 30, 22, kDim);+ }+ c.fillRect({0, kH - 80, kW, 80}, kBg); // its own hints over drawModal's+ if (capturing)+ return;+ if (padRow_ == kPerColumn)+ drawHints(c, {{kIconCross, tr(Str::Select)}, {kIconCircle, tr(Str::Back)}});+ else+ drawHints(c, {{kIconCross, tr(Str::ChangeKey)}, {kIconSquare, tr(Str::ClearKey)}, {kIconCircle, tr(Str::Back)}});+}+void AppUi::drawKeysTester(Canvas& c) {Rect panel = drawModal(c, 1500, 860, tr(Str::KeyboardKeys));// Each input: its name (the PlayStation button, the Xbox one beside),@@ -4079,6 +4252,10 @@ void AppUi::drawGameSettings(Canvas& c) {drawKeysTester(c);return;}+ if (tester_ == Tester::Pad) {+ drawPadTester(c);+ return;+ }std::string title = tr(Str::GameSettings);if (!detail_.name.empty()) {std::string full = title + " \xE2\x80\xA2 " + detail_.name;@@ -4094,8 +4271,8 @@ void AppUi::drawGameSettings(Canvas& c) {title = title + " \xE2\x80\xA2 " + cut + "...";}}- constexpr int kModalW = 1140, kModalH = 860;- constexpr int kRowH = 52, kGap = 7, kGroupGap = 12;+ constexpr int kModalW = 1140, kModalH = 880;+ constexpr int kRowH = 50, kGap = 6, kGroupGap = 12;// The rows caps_ allows; the panel loses the height of those it hides// (the same as ever with all of them, "Reset to default" or not).const auto rows = visibleGameSettingsRows(caps_, activeGameHasCustom_);@@ -4180,6 +4357,10 @@ void AppUi::drawGameSettings(Canvas& c) {label = tr(Str::KeyboardKeys);value = tr(activeGameProfile_.keyMap == input::defaultKeyMap() ? Str::ProfileDefault : Str::ProfileCustom);break;+ case 11:+ label = tr(Str::ControllerButtons);+ value = tr(activeGameProfile_.padMap == input::defaultPadMap() ? Str::ProfileDefault : Str::ProfileCustom);+ break;default: break;}diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex c6a816c..1b43c4e 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -93,6 +93,10 @@ struct NavInput {bool dpadLeft = false, dpadRight = false;float rawLX = 0, rawLY = 0, rawRX = 0, rawRY = 0;float l2Analog = 0, r2Analog = 0;+ // The pad's buttons pressed since the last pass, a bit per input::PadFn+ // index (input::padButtons(), the menus' own reading of the pad): the+ // Controller buttons screen waiting for a press.+ uint32_t padPressed = 0;// Smooth scrolling (the right stick, or the touchpad with inertia):// rows down (+) / up (-) and cards right (+) / left (-) to move now.int scrollRows = 0, scrollCards = 0;@@ -120,6 +124,7 @@ struct SettingsChoice {int maxBitrateMbps = 0; // 0 automatic, else 20 / 15 / 10 / 5int gameVolume = 100; // percent: 25 / 50 / 75 / 100 / 150input::KeyMap keyMap = input::defaultKeyMap(); // the keyboard as a player's controller+ input::PadMap padMap = input::defaultPadMap(); // the controller's buttons toward the game (always complete)bool fullscreen = true; // a desktop's window fullscreen (UiCaps::desktopWindow; F11 switches it too)};@@ -162,9 +167,9 @@ std::vector<SettingsRowPos> visibleGameSettingsRows(const UiCaps& caps, bool cus// The largest stick dead zone Settings offers, in percent of the travel.constexpr int kMaxDeadzone = 30;-constexpr int kSettingRows = 14; // language, resolution, region, dead zone, triggers, confirm, light bar, updates,+constexpr int kSettingRows = 15; // language, resolution, region, dead zone, triggers, confirm, light bar, updates,// sign-in country, 120 Hz output, bitrate cap, game volume, keyboard keys,- // display mode (a desktop's window)+ // display mode (a desktop's window), controller buttons// The countries "Sign in as another country" offers (xcloud::loginCountryAddress).constexpr const char* kLoginCountries[] = {"br", "jp", "kr", "pl", "us"};@@ -456,13 +461,18 @@ private:Color pickerColour() const;void drawColourPicker(Canvas& c);// The testers that Dead zone and Trigger vibration open in Settings.- enum class Tester { None, Sticks, Triggers, Keys };+ enum class Tester { None, Sticks, Triggers, Keys, Pad };void openTester(Tester t);void handleTester(const NavInput& in);void drawStickTester(Canvas& c);void drawTriggerTester(Canvas& c);void handleKeysTester(const NavInput& in);void drawKeysTester(Canvas& c);+ // The controller buttons' screen (Tester::Pad), on Settings' map or+ // (game settings open) the game's.+ void openPadTester();+ void handlePadTester(const NavInput& in);+ void drawPadTester(Canvas& c);// A modal panel over Settings with its title; returns its rectangle.Rect drawModal(Canvas& c, int w, int h, const std::string& title);void drawUpdating(Canvas& c, uint64_t nowMs);@@ -575,6 +585,13 @@ private:uint64_t captureSince_ = 0;uint8_t keyRefused_ = 0;uint64_t keyRefusedUntil_ = 0;+ // The controller buttons' screen: the copy being edited (Settings or the+ // game's profile only get it on a valid way out), the row (0..7 each+ // column, 8 the Reset / Discard buttons) and column, and waiting for a+ // press since (ms; 0 not).+ input::PadMap padWork_ = input::defaultPadMap();+ int padRow_ = 0, padCol_ = 0;+ uint64_t padCaptureSince_ = 0;int testerStick_ = 0; // the stick tester: the one being adjusted (L1 / R1)float testSticks_[4] = {0, 0, 0, 0}, testL2_ = 0, testR2_ = 0;bool pickerOpen_ = false;diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex c352c5f..62c677c 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -297,6 +297,11 @@ constexpr Column kEnglish = {"Fullscreen", // DisplayFullscreen"Quit PSBox?", // QuitTitle"Quit", // QuitConfirm+ "Controller buttons", // ControllerButtons+ "Press the button for %s", // PadPressButton+ "Missing a button: %s. Give each one a button, or reset or discard the changes.", // PadMissing+ "Discard changes", // DiscardChanges+ "Only the game sees this: the app's menus keep the buttons as they are. Picking a button used by another swaps the two.", // PadHelp};constexpr Column kPortugueseBR = {@@ -564,6 +569,11 @@ constexpr Column kPortugueseBR = {"Tela cheia", // DisplayFullscreen"Sair do PSBox?", // QuitTitle"Sair", // QuitConfirm+ "Botões do controle", // ControllerButtons+ "Aperte o botão para %s", // PadPressButton+ "Falta botão para: %s. Dê um botão a cada um, ou restaure o padrão ou descarte as alterações.", // PadMissing+ "Descartar alterações", // DiscardChanges+ "Só o jogo vê isto: os menus do app usam os botões como são. Escolher um botão já usado troca os dois.", // PadHelp};constexpr Column kSpanish = {@@ -831,6 +841,11 @@ constexpr Column kSpanish = {"Pantalla completa", // DisplayFullscreen"¿Salir de PSBox?", // QuitTitle"Salir", // QuitConfirm+ "Botones del mando", // ControllerButtons+ "Pulsa el botón para %s", // PadPressButton+ "Falta botón para: %s. Asigna uno a cada función, o restablece o descarta los cambios.", // PadMissing+ "Descartar cambios", // DiscardChanges+ "Solo el juego lo ve: los menús de la app usan los botones tal cual. Elegir un botón ya usado intercambia los dos.", // PadHelp};constexpr Column kFrench = {@@ -1098,6 +1113,11 @@ constexpr Column kFrench = {"Plein écran", // DisplayFullscreen"Quitter PSBox ?", // QuitTitle"Quitter", // QuitConfirm+ "Boutons de la manette", // ControllerButtons+ "Appuyez sur le bouton pour %s", // PadPressButton+ "Bouton manquant pour : %s. Attribuez-en un à chaque fonction, ou réinitialisez ou annulez les modifications.", // PadMissing+ "Annuler les modifications", // DiscardChanges+ "Seul le jeu est concerné : les menus de l'app gardent les boutons tels quels. Choisir un bouton déjà utilisé échange les deux.", // PadHelp};constexpr Column kGerman = {@@ -1365,6 +1385,11 @@ constexpr Column kGerman = {"Vollbild", // DisplayFullscreen"PSBox beenden?", // QuitTitle"Beenden", // QuitConfirm+ "Controller-Tasten", // ControllerButtons+ "Drücke die Taste für %s", // PadPressButton+ "Ohne Taste: %s. Weise jeder Funktion eine zu, oder setze zurück bzw. verwirf die Änderungen.", // PadMissing+ "Änderungen verwerfen", // DiscardChanges+ "Gilt nur im Spiel: Die Menüs der App nutzen die Tasten, wie sie sind. Eine schon belegte Taste zu wählen tauscht die beiden.", // PadHelp};constexpr Column kItalian = {@@ -1632,6 +1657,11 @@ constexpr Column kItalian = {"Schermo intero", // DisplayFullscreen"Uscire da PSBox?", // QuitTitle"Esci", // QuitConfirm+ "Pulsanti del controller", // ControllerButtons+ "Premi il pulsante per %s", // PadPressButton+ "Manca un pulsante per: %s. Assegnane uno a ogni funzione, oppure ripristina o annulla le modifiche.", // PadMissing+ "Annulla modifiche", // DiscardChanges+ "Vale solo nel gioco: i menu dell'app usano i pulsanti così come sono. Scegliere un pulsante già usato scambia i due.", // PadHelp};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex 2fc29cf..7c6fe7a 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -274,6 +274,11 @@ enum class Str {DisplayFullscreen, // ... fullscreenQuitTitle, // desktop: Circle / Esc on the home screen asks before closing the appQuitConfirm, // ... the hint that closes it+ ControllerButtons, // Settings / game settings row and its screen: which pad button plays which Xbox button in a game+ PadPressButton, // controller buttons: waiting for a press (%s: the Xbox button, e.g. "LB")+ PadMissing, // controller buttons: can't leave yet (%s: the Xbox buttons without one, "A, LB")+ DiscardChanges, // controller buttons: leave without keeping the changes+ PadHelp, // controller buttons: only the game sees the map; a button already used swapsCount};diff --git a/tests/test_main.cpp b/tests/test_main.cppindex bd91899..6a1bb44 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -33,6 +33,7 @@#include "stream/h264_receiver.h"#include "input/kbm.h"#include "input/keyboard_nav.h"+#include "input/pad_map.h"#include "input/sdl_mapping.h"#include "platform/platform.h"#include "auth/msa.h"@@ -1080,6 +1081,103 @@ static void testKeyMap() {std::remove(path.c_str());}+// The controller's buttons toward the game (input/pad_map.h).+static void testPadMap() {+ using namespace xc::input;+ auto at = [](const PadMap& m, PadFn f) { return m[static_cast<size_t>(f)]; };+ auto src = [](PadFn f) { return static_cast<uint8_t>(f); };+ const PadMap def = defaultPadMap();+ CHECK(padMapValid(def) && padMapMissing(def) == 0);+ // The default map passes everything through.+ ControllerState in;+ in.btnA = in.dpadLeft = in.btnTouchpad = true;+ in.triggerL2 = 0.3f;+ in.leftStickX = 0.7f;+ in.btnNexus = true;+ ControllerState same = applyPadMap(in, def);+ CHECK(same.btnA && same.dpadLeft && same.btnTouchpad && !same.btnB && same.triggerL2 == 0.3f &&+ same.leftStickX == 0.7f && same.btnNexus);+ // Assigning a source used elsewhere swaps the two: still complete.+ PadMap m = def;+ assignPadSource(m, PadFn::A, src(PadFn::B)); // A <- Circle, so B <- Cross+ CHECK(at(m, PadFn::A) == src(PadFn::B) && at(m, PadFn::B) == src(PadFn::A) && padMapValid(m));+ ControllerState cross;+ cross.btnA = true;+ ControllerState out = applyPadMap(cross, m);+ CHECK(!out.btnA && out.btnB);+ // A trigger fed by a button is fully pressed; a button fed by a trigger past halfway.+ assignPadSource(m, PadFn::RT, src(PadFn::RB)); // RT <- R1, RB <- R2+ ControllerState r1;+ r1.btnR1 = true;+ out = applyPadMap(r1, m);+ CHECK(out.triggerR2 == 1.0f && !out.btnR1);+ ControllerState r2;+ r2.triggerR2 = 0.4f;+ CHECK(!applyPadMap(r2, m).btnR1 && applyPadMap(r2, m).triggerR2 == 0.0f);+ r2.triggerR2 = 0.8f;+ CHECK(applyPadMap(r2, m).btnR1);+ // A trigger fed by the other trigger keeps how far it is pressed.+ PadMap t = def;+ assignPadSource(t, PadFn::LT, src(PadFn::RT));+ ControllerState lr;+ lr.triggerR2 = 0.25f;+ CHECK(applyPadMap(lr, t).triggerL2 == 0.25f && applyPadMap(lr, t).triggerR2 == 0.0f);+ // A cleared row: incomplete, named in the missing bits; a source fed twice is not valid.+ PadMap hole = def;+ assignPadSource(hole, PadFn::Y, kPadNone);+ CHECK(!padMapValid(hole) && padMapMissing(hole) == (1u << static_cast<int>(PadFn::Y)));+ CHECK(!applyPadMap(ControllerState{}, hole).btnY);+ PadMap twice = def;+ twice[static_cast<size_t>(PadFn::X)] = src(PadFn::A);+ CHECK(!padMapValid(twice) && padMapMissing(twice) == 0);+ // Filling the hole with a button used elsewhere moves the hole there.+ assignPadSource(hole, PadFn::Y, src(PadFn::X));+ CHECK(at(hole, PadFn::Y) == src(PadFn::X) && at(hole, PadFn::X) == kPadNone);+ // The buttons pressed, by source; Circle confirms swaps A / B back to the pad's.+ ControllerState held;+ held.btnB = true;+ held.triggerL2 = 0.9f;+ CHECK(padButtons(held) == ((1u << static_cast<int>(PadFn::B)) | (1u << static_cast<int>(PadFn::LT))));+ CHECK(physicalSource(src(PadFn::A), true) == src(PadFn::B) && physicalSource(src(PadFn::A), false) == src(PadFn::A) &&+ physicalSource(src(PadFn::Y), true) == src(PadFn::Y));+ CHECK(std::string(padFnName(PadFn::Right)) == "D-pad right");+ // JSON: round trip; anything else is refused and gives the default.+ PadMap back;+ CHECK(readPadMap(padMapJson(m), back) && back == m);+ auto reads = [&](const char* text) {+ auto v = json::parse(text);+ PadMap r = m;+ bool ok = v && readPadMap(*v, r);+ CHECK(r == (ok ? r : def));+ return ok;+ };+ CHECK(reads(R"({"version":1,"map":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]})"));+ CHECK(!reads(R"({"version":2,"map":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]})"));+ CHECK(!reads(R"({"version":1,"map":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]})"));+ CHECK(!reads(R"({"version":1,"map":[0,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15]})"));+ CHECK(!reads(R"({"version":1,"map":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,255]})"));+ CHECK(!reads(R"({"version":1,"map":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,"x"]})"));+ CHECK(!reads(R"([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])"));+ // In the settings and a game's profile: saved and read back; a broken+ // one falls back to the default; an older file (none) keeps the general one.+ xc::app::Settings st;+ st.padMap = m;+ st.perGame["g"] = st.defaultProfile();+ CHECK(st.perGame["g"].padMap == m);+ st.perGame["g"].padMap = t;+ std::string path = std::string(std::getenv("TMPDIR") ? std::getenv("TMPDIR") : "/tmp") + "/xc_padmap_test.json";+ CHECK(st.save(path));+ xc::app::Settings loaded;+ CHECK(loaded.load(path) && loaded.padMap == m && loaded.perGame["g"].padMap == t);+ xc::platform::writeFileAtomic(path, R"({"padMap":{"version":1,"map":[1,1]},"perGame":{"h":{},"k":{"padMap":7}}})");+ xc::app::Settings broken;+ CHECK(broken.load(path) && broken.padMap == def && broken.perGame["h"].padMap == def && broken.perGame["k"].padMap == def);+ xc::platform::writeFileAtomic(path, R"({"padMap":)" + padMapJson(m).dump() + R"(,"perGame":{"h":{}}})");+ xc::app::Settings older;+ CHECK(older.load(path) && older.perGame["h"].padMap == m);+ std::remove(path.c_str());+}+// The xCloud login: a 5xx is tried again, a refusal is not.static void testLoginRetry() {using namespace xc;@@ -1181,33 +1279,33 @@ static void testVisibleSettingsRows() {};const ui::UiCaps ps5;auto all = ui::visibleSettingsRows(ps5);- CHECK((ids(all) == std::vector<int>{0, 8, 1, 9, 10, 2, 11, 3, 4, 5, 6, 12, 7}));- CHECK((groups(all) == std::vector<bool>{false, false, true, false, false, false, true, true, false, false, false, false, true}));+ CHECK((ids(all) == std::vector<int>{0, 8, 1, 9, 10, 2, 11, 3, 4, 5, 6, 14, 12, 7}));+ CHECK((groups(all) == std::vector<bool>{false, false, true, false, false, false, true, true, false, false, false, false, false, true}));ui::UiCaps pc;pc.lightBar = pc.triggerRumble = pc.adaptiveTriggers = pc.gyro = pc.touchpad = false;pc.upscalers = pc.sharpen = pc.deband = pc.highRefresh = pc.console = pc.selfUpdate = false;pc.openUrl = true;auto desk = ui::visibleSettingsRows(pc);- CHECK((ids(desk) == std::vector<int>{0, 8, 1, 10, 2, 11, 3, 5, 12, 7}));- CHECK((groups(desk) == std::vector<bool>{false, false, true, false, false, true, true, false, false, true}));+ CHECK((ids(desk) == std::vector<int>{0, 8, 1, 10, 2, 11, 3, 5, 14, 12, 7}));+ CHECK((groups(desk) == std::vector<bool>{false, false, true, false, false, true, true, false, false, false, true}));// The desktop app's window: Display mode after the resolution, in the stream's group.ui::UiCaps win = pc;win.desktopWindow = true;auto w = ui::visibleSettingsRows(win);- CHECK((ids(w) == std::vector<int>{0, 8, 1, 13, 10, 2, 11, 3, 5, 12, 7}));- CHECK((groups(w) == std::vector<bool>{false, false, true, false, false, false, true, true, false, false, true}));+ CHECK((ids(w) == std::vector<int>{0, 8, 1, 13, 10, 2, 11, 3, 5, 14, 12, 7}));+ CHECK((groups(w) == std::vector<bool>{false, false, true, false, false, false, true, true, false, false, false, true}));ui::UiCaps xbox = pc; // an Xbox pad: impulse triggers, no light barxbox.triggerRumble = true;auto x = ids(ui::visibleSettingsRows(xbox));CHECK(std::find(x.begin(), x.end(), 4) != x.end() && std::find(x.begin(), x.end(), 6) == x.end());// A game's settings.- CHECK((ids(ui::visibleGameSettingsRows(ps5, true)) == std::vector<int>{0, 4, 8, 1, 2, 3, 5, 6, 7, 9, 10}));+ CHECK((ids(ui::visibleGameSettingsRows(ps5, true)) == std::vector<int>{0, 4, 8, 1, 2, 3, 5, 6, 7, 11, 9, 10}));CHECK((groups(ui::visibleGameSettingsRows(ps5, true)) ==- std::vector<bool>{false, true, false, true, false, false, true, false, false, false, true}));- CHECK((ids(ui::visibleGameSettingsRows(ps5, false)) == std::vector<int>{0, 4, 8, 1, 2, 3, 5, 6, 7, 9}));+ std::vector<bool>{false, true, false, true, false, false, true, false, false, false, false, true}));+ CHECK((ids(ui::visibleGameSettingsRows(ps5, false)) == std::vector<int>{0, 4, 8, 1, 2, 3, 5, 6, 7, 11, 9}));auto game = ui::visibleGameSettingsRows(pc, false);- CHECK((ids(game) == std::vector<int>{0, 4, 5, 7, 9}));- CHECK((groups(game) == std::vector<bool>{false, true, true, false, false}));+ CHECK((ids(game) == std::vector<int>{0, 4, 5, 7, 11, 9}));+ CHECK((groups(game) == std::vector<bool>{false, true, true, false, false, false}));}// The controller's glyphs by pad kind (ui/pad_glyphs.h).@@ -1555,6 +1653,7 @@ int main() {testKeyboardNav();testKeyboardAsGamepad();testKeyMap();+ testPadMap();testTeredo();if (g_failures) {std::fprintf(stderr, "%d failure(s)\n", g_failures);