Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Input: report gamepad physicality accurately, suppress touchpad swipes during click (#39)

Rafael Abud Ferreira96b0b8e0c7f9
diff --git a/ROADMAP.md b/ROADMAP.md
index 7b1bd8c..62744e6 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -224,7 +224,8 @@ is rolled back at the next start), then the app restarts itself
| Free play with ads | Microsoft's ad-supported offering (`xgpuwebf2p` login and sessions, its own list): play without a subscription, with the service's limits; the ads are never skipped (as green-nx, Nubix, XStreaming) | small–medium |
| Game Pass trial badge (later) | The store's answer says `isTrial`; a TRIAL mark next to the plan. Not now | small |
| Unreliable input channel (protocol v9) | The official client sends input on an unordered channel, so a lost packet doesn't hold the ones after it; needs a capture of its frames | medium |
-| Controller remapping, touchpad mouse | Per-game: the DualSense's buttons remapped (Edge paddles too), the touchpad as a mouse for MKB games; gyro aiming and the keyboard's keys are done | medium |
+| DualSense button remapping (done), touchpad mouse | Full DualSense button customization in Settings and each game's settings (Edge back buttons/paddles too), with its own remapping screen like keyboard keys (done); touchpad as a mouse for MKB games | medium |
+| Gamepad report physicality & touchpad click robustness (#39) | In `src/stream/input_packet.cpp`: compute accurate `physicalPhysicality` bitmask (0 when idle) and send 0 for `virtualPhysicality` (LE), preventing idle secondary controllers/bridges from continuously reporting active physical input to xCloud. In `src/app/stream_screen.cpp`: suppress touchpad swipe gesture detection while `btnTouchpad` is physically pressed. Add one-time diagnostic log on first `kView` / `kMenu` sent per stream session | small |
| Gyro in Settings | Gyro aiming in Settings and the game settings too (now in the game menu only); an inverted / separate horizontal sensitivity if asked | small |
| Favourites, game language | A favourites row; the game's language apart from the app's | small |
| Lost audio filled | Opus concealment / in-band FEC for lost audio packets: needs libopus (FFmpeg's own Opus decoder has neither) | small–medium |
diff --git a/src/app/stream_screen.cpp b/src/app/stream_screen.cpp
index 6b3afd8..88bfcb1 100644
--- a/src/app/stream_screen.cpp
+++ b/src/app/stream_screen.cpp
@@ -375,7 +375,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
if (!padReleased_ || menuCombo) sent = input::ControllerState{};
// Swiping up or right on the touchpad is the Xbox button (once
// per swipe; the games never see the touchpad's touches).
- if (pad.touching && g_keyboardFor.empty()) {
+ if (pad.touching && !pad.btnTouchpad && g_keyboardFor.empty()) {
if (!swipe_.active) swipe_ = {true, false, pad.touchX, pad.touchY};
float dx = pad.touchX - swipe_.x, dy = swipe_.y - pad.touchY; // dy > 0: up
bool right = dx > 0.30f && std::abs(dy) < 0.30f, up = dy > 0.40f && std::abs(dx) < 0.30f;
@@ -383,14 +383,16 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
if (!swipe_.fired && (right || up) && !menu_.isOpen()) {
swipe_.fired = true;
g_xboxButtonUntil = platform::nowMs() + 250;
- XC_LOGI("touchpad swipe_ %s: Xbox button", right ? "right" : "up");
+ XC_LOGI("touchpad swipe %s: Xbox button", right ? "right" : "up");
} else if (!swipe_.fired && (left || down)) {
swipe_.fired = true;
swipeMenu_ = true; // opened on the next pass, as by OPTIONS + TOUCHPAD
- XC_LOGI("touchpad swipe_ %s: game menu_", left ? "left" : "down");
+ XC_LOGI("touchpad swipe %s: game menu", left ? "left" : "down");
}
} else {
swipe_.active = false;
+ if (!pad.touching) swipe_.fired = false;
+ else if (pad.btnTouchpad) swipe_.fired = true;
}
if (platform::nowMs() < g_xboxButtonUntil) sent.btnNexus = true;
g_player->sendInput(sent);
diff --git a/src/stream/input_packet.cpp b/src/stream/input_packet.cpp
index b564a10..a687bbd 100644
--- a/src/stream/input_packet.cpp
+++ b/src/stream/input_packet.cpp
@@ -73,6 +73,33 @@ std::vector<uint8_t> metadataReport(uint32_t sequence, double timestampMs, const
return b;
}
+uint32_t gamepadPhysicality(const GamepadFrame& f) {
+ uint32_t p = 0;
+ if (f.buttons & kDPadUp) p |= (1 << 0);
+ if (f.buttons & kDPadDown) p |= (1 << 1);
+ if (f.buttons & kDPadLeft) p |= (1 << 2);
+ if (f.buttons & kDPadRight) p |= (1 << 3);
+ if (f.buttons & kMenu) p |= (1 << 4);
+ if (f.buttons & kView) p |= (1 << 5);
+ if (f.buttons & kLeftThumb) p |= (1 << 6);
+ if (f.buttons & kRightThumb) p |= (1 << 7);
+ if (f.buttons & kLeftShoulder) p |= (1 << 8);
+ if (f.buttons & kRightShoulder) p |= (1 << 9);
+ if (f.buttons & kNexus) p |= (1 << 10);
+ // (1 << 11) is Share/Misc
+ if (f.buttons & kA) p |= (1 << 12);
+ if (f.buttons & kB) p |= (1 << 13);
+ if (f.buttons & kX) p |= (1 << 14);
+ if (f.buttons & kY) p |= (1 << 15);
+ if (trigger(f.leftTrigger) != 0) p |= (1 << 16);
+ if (trigger(f.rightTrigger) != 0) p |= (1 << 17);
+ if (axis(f.leftX) != 0) p |= (1 << 18);
+ if (axis(f.leftY) != 0) p |= (1 << 19);
+ if (axis(f.rightX) != 0) p |= (1 << 20);
+ if (axis(f.rightY) != 0) p |= (1 << 21);
+ return p;
+}
+
std::vector<uint8_t> gamepadReport(uint32_t sequence, double timestampMs, const GamepadFrame& f) {
auto b = header(kReportGamepad, sequence, timestampMs, kHeaderSize + 1 + 23);
size_t o = kHeaderSize;
@@ -85,8 +112,8 @@ std::vector<uint8_t> gamepadReport(uint32_t sequence, double timestampMs, const
put16(b, o + 8, static_cast<uint16_t>(axis(f.rightY)));
put16(b, o + 10, trigger(f.leftTrigger));
put16(b, o + 12, trigger(f.rightTrigger));
- put32(b, o + 14, 1); // physical physicality
- put32be(b, o + 18, 1); // virtual physicality (big-endian in the web client too)
+ put32(b, o + 14, gamepadPhysicality(f)); // physical physicality (0 when idle)
+ put32(b, o + 18, 0); // virtual physicality (LE)
return b;
}
diff --git a/src/stream/input_packet.h b/src/stream/input_packet.h
index 5cdeff5..2fb74dd 100644
--- a/src/stream/input_packet.h
+++ b/src/stream/input_packet.h
@@ -86,6 +86,9 @@ std::vector<uint8_t> clientMetadataReport(uint32_t sequence, double timestampMs,
// Frame timings, as the web client sends after each frame it shows (at most
// 30 per report).
std::vector<uint8_t> metadataReport(uint32_t sequence, double timestampMs, const std::vector<FrameMetadata>& frames);
+// Bitmask of active controls for a gamepad frame (0 when idle, bits set for
+// pressed buttons, engaged triggers and deflected sticks).
+uint32_t gamepadPhysicality(const GamepadFrame& frame);
std::vector<uint8_t> gamepadReport(uint32_t sequence, double timestampMs, const GamepadFrame& frame);
// Native mouse and keyboard, for the titles that take them (at most 30
// frames per report).
diff --git a/src/stream/stream_session.cpp b/src/stream/stream_session.cpp
index 23b7933..b5aa65d 100644
--- a/src/stream/stream_session.cpp
+++ b/src/stream/stream_session.cpp
@@ -126,6 +126,8 @@ struct StreamSession::Impl {
// keep receiving the pad and ignore it: the pads are announced again.
std::atomic<uint64_t> lastVideoMs{0};
std::atomic<bool> padsStale{false};
+ bool loggedFirstView = false;
+ bool loggedFirstMenu = false;
Impl(xcloud::GssvClient& g, StreamCallbacks c, StreamOptions o) : gssv(g), cb(std::move(c)), opt(o) {}
@@ -736,6 +738,14 @@ void StreamSession::sendGamepad(const GamepadFrame& frame) {
d.lastPad[frame.index] = frame;
lastMs = now;
}
+ if (!d.loggedFirstView && (frame.buttons & stream::kView)) {
+ d.loggedFirstView = true;
+ XC_LOGI("input: first kView sent (pad %u)", frame.index);
+ }
+ if (!d.loggedFirstMenu && (frame.buttons & stream::kMenu)) {
+ d.loggedFirstMenu = true;
+ XC_LOGI("input: first kMenu sent (pad %u)", frame.index);
+ }
Impl::sendBinary(d.input, gamepadReport(d.inputSequence++, d.nowMs(), frame));
}
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 6a1bb44..60d7617 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -131,8 +131,15 @@ static void testInputPacket() {
CHECK(p[18] == 0xff && p[19] == 0x7f); // left X = 32767
CHECK(p[20] == 0x01 && p[21] == 0x80); // left Y = -32767
CHECK(p[28] == 0xff && p[29] == 0xff); // right trigger
- CHECK(p[30] == 1 && p[33] == 0); // physicality LE
- CHECK(p[34] == 0 && p[37] == 1); // virtual physicality BE
+ CHECK(gamepadPhysicality(f) == 0x000e1001);
+ CHECK(p[30] == 0x01 && p[31] == 0x10 && p[32] == 0x0e && p[33] == 0x00); // physicality LE
+ CHECK(p[34] == 0 && p[35] == 0 && p[36] == 0 && p[37] == 0); // virtual physicality LE = 0
+
+ GamepadFrame idle;
+ CHECK(gamepadPhysicality(idle) == 0);
+ auto pIdle = gamepadReport(8, 2.0, idle);
+ CHECK(pIdle[30] == 0 && pIdle[31] == 0 && pIdle[32] == 0 && pIdle[33] == 0);
+ CHECK(pIdle[34] == 0 && pIdle[35] == 0 && pIdle[36] == 0 && pIdle[37] == 0);
FrameMetadata fm;
fm.serverDataKey = 0x01020304;