Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Gyro aiming: the DualSense's turning moves the right stick (off / always / while L2 aims, intensity 1-10) from the in-game menu, saved in general or the game's profile

Rafael Abud Ferreirac983de9fb0fd
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 98a4bc3..6bc82d9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,6 +40,7 @@ add_library(xcloud_core STATIC
src/input/keyboard_nav.cpp
src/xcloud/social.cpp
src/platform/posix_common.cpp
+ src/input/gyro.cpp
)
target_include_directories(xcloud_core PUBLIC src)
if(NOT MSVC)
diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cpp
index 30dd8ff..d18aac3 100644
--- a/src/app/autoplay.cpp
+++ b/src/app/autoplay.cpp
@@ -752,6 +752,12 @@ void autoplayScreens(const ui::Canvas& canvas, uint64_t now) {
ui::StreamMenu menu(g_ui->fonts());
menu.open(0, false, 1, 1, 0, false, true, false, 2, 15, false, 0.65f, false);
+ menu.setGyro(2, 7); // gyro aiming while aiming, intensity 7, its row selected
+ for (int i = 0; i < 10; ++i) {
+ ui::NavInput down;
+ down.down = true;
+ menu.handle(down);
+ }
ui::StreamInfo info;
info.region = "East US";
info.rttMs = 18;
diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cpp
index e43dacd..9e22a51 100644
--- a/src/app/ps5_main.cpp
+++ b/src/app/ps5_main.cpp
@@ -265,6 +265,7 @@ int main(int argc, char** argv) {
g_ui->setUpdateState(XC_APP_VERSION, {}, false); // Settings shows this version before any check
g_ui->setSettings(choice);
g_ui->setPerGameSettings(g_settings.perGame);
+ g_ui->setGyroDefaults(g_settings.gyroMode, g_settings.gyroLevel);
applyControllerSettings();
g_ui->setRegionLatency(g_settings.regionRtt);
g_ui->setPrefs(g_settings.hidden, g_settings.librarySort == "az" ? ui::LibrarySort::AZ
@@ -367,6 +368,8 @@ int main(int argc, char** argv) {
// The log is already on disk (flushed by line).
_exit(0);
}
+ // Gyro aiming moves the aim in a game, not the app's menu.
+ input::setGyroActive(g_ui->screen() == ui::Screen::Streaming && !streamScreen.menuOpen());
input::poll(pad);
autoplayPad(pad);
// USB keyboard: the app's screens (and its menu in a game) as with the
diff --git a/src/app/settings.cpp b/src/app/settings.cpp
index 60aadfc..1085695 100644
--- a/src/app/settings.cpp
+++ b/src/app/settings.cpp
@@ -77,6 +77,8 @@ bool Settings::load(const std::string& path) {
gameVolume = static_cast<int>(std::clamp<int64_t>((*j)["gameVolume"].asInt(gameVolume), 0, 200));
keyMap = readKeyMap((*j)["keyMap"], input::defaultKeyMap());
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));
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();
@@ -112,6 +114,8 @@ 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.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;
}
return true;
@@ -132,6 +136,8 @@ GameProfile Settings::defaultProfile() const {
p.circleConfirms = circleConfirms;
p.highRefresh = highRefresh;
p.keyMap = keyMap;
+ p.gyroMode = gyroMode;
+ p.gyroLevel = gyroLevel;
return p;
}
@@ -190,6 +196,8 @@ bool Settings::save(const std::string& path) const {
v.set("gameVolume", gameVolume);
v.set("keyMap", keyMapJson(keyMap));
v.set("keyboardPlayer", keyboardPlayer);
+ v.set("gyroMode", gyroMode);
+ v.set("gyroLevel", gyroLevel);
v.set("micGain", micGain);
v.set("audioRoute", audioRoute);
v.set("skippedUpdate", skippedUpdate);
@@ -213,6 +221,8 @@ 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("gyroMode", p.gyroMode);
+ obj.set("gyroLevel", p.gyroLevel);
pg.set(id, obj);
}
v.set("perGame", pg);
diff --git a/src/app/settings.h b/src/app/settings.h
index 02f74bf..5bd8a5a 100644
--- a/src/app/settings.h
+++ b/src/app/settings.h
@@ -29,6 +29,9 @@ struct GameProfile {
bool highRefresh = false; // 120 Hz output (VRR) while streaming
// Keyboard and mouse as a controller: which keys play what
input::KeyMap keyMap = input::defaultKeyMap();
+ // Gyro aiming: 0 off, 1 always, 2 while L2 is held; intensity 1..10
+ int gyroMode = 0;
+ int gyroLevel = 5;
};
// Key to identify a game profile: productId first, else titleId.
@@ -80,6 +83,8 @@ struct Settings {
int gameVolume = 100; // percent: 25, 50, 75, 100 or 150
input::KeyMap keyMap = input::defaultKeyMap(); // the keys when the keyboard is a player's controller
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 controller
+ int gyroMode = 0; // gyro aiming (input/gyro.h): 0 off, 1 always, 2 while L2 is held
+ int gyroLevel = 5; // its intensity, 1..10
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 8945b72..6f1ad89 100644
--- a/src/app/stream_screen.cpp
+++ b/src/app/stream_screen.cpp
@@ -122,6 +122,9 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
deadzone_ = prof.deadzoneLeft;
circleConfirms_ = prof.circleConfirms;
keyMap_ = prof.keyMap;
+ gyroMode_ = prof.gyroMode;
+ gyroLevel_ = prof.gyroLevel;
+ input::setGyro(gyroMode_, gyroLevel_);
input::setDeadzone(prof.deadzoneLeft / 100.0f, prof.deadzoneRight / 100.0f);
input::setTriggerFeel(prof.triggerStrength, prof.triggerHz, prof.triggerResistance, prof.triggerPulses);
input::setCircleConfirms(prof.circleConfirms);
@@ -152,6 +155,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
float micLvl = g_player ? g_player->micLevel() : 0.0f;
bool micMuted = g_player ? (g_player->micMuted() || g_player->isMicHardwareMuted()) : false;
menu_.setDebandInUse(autoDeband_.level());
+ menu_.setGyro(gyroMode_, gyroLevel_);
menu_.open(streamResolution_, showStats_, sharpness_, deband_, upscaler_, g_playingHome, allow1440,
hasCustomProfile_, triggerStrength_, deadzone_, circleConfirms_, micLvl, micMuted);
overlaySeq_ = 0;
@@ -205,6 +209,8 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
auto had = g_settings.perGame.find(gameKey_); // not set from this menu: kept
p.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.gyroMode = gyroMode_;
+ p.gyroLevel = gyroLevel_;
g_settings.perGame[gameKey_] = p;
} else {
g_settings.perGame.erase(gameKey_);
@@ -217,6 +223,10 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
triggerStrength_ = def.triggerStrength;
keyMap_ = def.keyMap;
circleConfirms_ = def.circleConfirms;
+ gyroMode_ = def.gyroMode;
+ gyroLevel_ = def.gyroLevel;
+ input::setGyro(gyroMode_, gyroLevel_);
+ menu_.setGyro(gyroMode_, gyroLevel_);
display::setSharpness(kSharpAmount[sharpness_]);
applyDeband_();
applyUpscaler(upscaler_);
@@ -285,6 +295,23 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
if (g_ui) g_ui->setPerGameSettings(g_settings.perGame);
break;
}
+ case ui::MenuAction::Gyro: {
+ gyroMode_ = menu_.gyroMode();
+ gyroLevel_ = menu_.gyroLevel();
+ input::setGyro(gyroMode_, gyroLevel_);
+ std::lock_guard<std::mutex> settingsLock(g_settingsMutex);
+ if (hasCustomProfile_) {
+ g_settings.perGame[gameKey_].gyroMode = gyroMode_;
+ g_settings.perGame[gameKey_].gyroLevel = gyroLevel_;
+ } else {
+ g_settings.gyroMode = gyroMode_;
+ g_settings.gyroLevel = gyroLevel_;
+ if (g_ui) g_ui->setGyroDefaults(gyroMode_, gyroLevel_);
+ }
+ g_settings.save(settingsPath());
+ if (g_ui) g_ui->setPerGameSettings(g_settings.perGame);
+ break;
+ }
case ui::MenuAction::ConfirmButton: {
circleConfirms_ = menu_.circleConfirms();
input::setCircleConfirms(circleConfirms_);
diff --git a/src/app/stream_screen.h b/src/app/stream_screen.h
index 43ed1b6..78e49d6 100644
--- a/src/app/stream_screen.h
+++ b/src/app/stream_screen.h
@@ -71,6 +71,7 @@ private:
int deadzone_ = 15;
bool circleConfirms_ = false;
input::KeyMap keyMap_ = input::defaultKeyMap(); // this game's keys (the keyboard as a controller)
+ int gyroMode_ = 0, gyroLevel_ = 5; // gyro aiming (input/gyro.h), this game's
bool highRefresh_ = false; // 120 Hz turned on for this stream
input::KbmInput kbm_;
int kbSlotAttached_ = -1; // the keyboard's slot as a controller, announced
diff --git a/src/input/controller.cpp b/src/input/controller.cpp
index 3df0f14..94e1f3c 100644
--- a/src/input/controller.cpp
+++ b/src/input/controller.cpp
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 RafaelNGP
#include "input/controller.h"
+#include "input/gyro.h"
#include "input/tuning.h"
#include "util/log.h"
@@ -79,6 +80,7 @@ int scePadInit(void);
int scePadOpen(int32_t userId, int32_t type, int32_t index, const void* param);
int scePadClose(int32_t handle);
int scePadReadState(int32_t handle, ScePadData* data);
+int scePadSetMotionSensorState(int32_t handle, bool enable);
struct ScePadVibrationParam {
uint8_t largeMotor;
@@ -162,6 +164,7 @@ struct Pad {
float light[3] = {0, 0, 0};
bool lightStarted = false;
std::atomic<uint64_t> activeAt{0}; // the last poll with a button or stick in use (ms)
+ GyroState gyro; // gyro aiming's eased push
};
Pad g_pads[kMaxPads];
std::atomic<float> g_deadzone[2] = {0.15f, 0.15f};
@@ -169,6 +172,9 @@ std::atomic<bool> g_circleConfirms{false};
std::atomic<int> g_triggerStrength{kTriggerMedium}, g_triggerHz{1}, g_triggerResistance{0};
std::atomic<bool> g_triggerPulses{false}, g_triggerLogging{false}, g_resistanceActive{false};
bool g_rumbleLogged = false;
+std::atomic<int> g_gyroMode{kGyroOff}, g_gyroLevel{5};
+std::atomic<bool> g_gyroActive{false};
+int g_gyroLogged = 0; // the first turns, to check the axes' signs
inline float normStick(uint8_t val) {
// 0..255 -> -1.0 .. 1.0
@@ -188,6 +194,9 @@ bool openPad(Pad& pad, int32_t userId, int slot) {
// The DualSense starts in haptics mode, where scePadSetVibration succeeds
// and does nothing; mode 2 is classic two-motor rumble (as ProsperoEden).
int mode = scePadSetVibrationMode(h, 2);
+ // The motion sensors (gyro aiming) report only once turned on.
+ if (int rc = scePadSetMotionSensorState(h, true); rc < 0)
+ XC_LOGW("scePadSetMotionSensorState: 0x%08x", static_cast<unsigned>(rc));
pad.userId = userId;
pad.handle = h;
if (sceUserServiceGetUserName(userId, pad.name, sizeof pad.name) != 0) pad.name[0] = 0;
@@ -444,6 +453,23 @@ bool pollPad(int index, ControllerState& out) {
out.triggerL2 = normTrigger(pad.l2);
out.triggerR2 = normTrigger(pad.r2);
+ // Gyro aiming: in a game (menu closed), always or while L2 aims.
+ int gyroMode = g_gyroMode.load(std::memory_order_relaxed);
+ bool gyroOn = g_gyroActive && (gyroMode == kGyroAlways || (gyroMode == kGyroAiming && out.triggerL2 > 0.3f));
+ if (gyroOn) {
+ float gx, gy;
+ gyroToStick(pad.angularVelocity, g_gyroLevel.load(std::memory_order_relaxed), slot.gyro, gx, gy);
+ float x = out.rightStickX + gx, y = out.rightStickY + gy, m = std::hypot(x, y);
+ if (m > 1.0f) x /= m, y /= m;
+ out.rightStickX = x;
+ out.rightStickY = y;
+ if (g_gyroLogged < 6 && std::abs(pad.angularVelocity[1]) + std::abs(pad.angularVelocity[0]) > 1.0f)
+ XC_LOGI("gyro: pitch %.2f yaw %.2f roll %.2f rad/s -> stick %.2f,%.2f (%d)", pad.angularVelocity[0],
+ pad.angularVelocity[1], pad.angularVelocity[2], gx, gy, ++g_gyroLogged);
+ } else {
+ slot.gyro = {};
+ }
+
// The DualSense touchpad reports 0..1919 x 0..1079.
if (pad.touchData.touchNum > 0) {
out.touching = true;
@@ -456,6 +482,12 @@ bool pollPad(int index, ControllerState& out) {
}
uint64_t padActiveAt(int index) { return index >= 0 && index < kMaxPads ? g_pads[index].activeAt.load() : 0; }
+void setGyro(int mode, int level) {
+ g_gyroMode = std::clamp(mode, 0, 2);
+ g_gyroLevel = std::clamp(level, 1, kGyroLevels);
+}
+
+void setGyroActive(bool on) { g_gyroActive = on; }
void setEmbeddedMicActive(bool active, int pad) {
if (pad < 0 || pad >= kMaxPads) return;
@@ -500,6 +532,8 @@ void setTriggerFeel(int, int, int, bool) {}
void setTriggerLogging(bool) {}
void setTriggerResistanceActive(bool) {}
void setEmbeddedMicActive(bool, int) {}
+void setGyro(int, int) {}
+void setGyroActive(bool) {}
} // namespace xc::input
#endif
diff --git a/src/input/controller.h b/src/input/controller.h
index f04e18d..2c013c2 100644
--- a/src/input/controller.h
+++ b/src/input/controller.h
@@ -96,6 +96,11 @@ void setTriggerResistanceActive(bool on);
// system (the player's colour). Any thread; polling applies it.
void setLightBar(uint8_t r, uint8_t g, uint8_t b, int pad = 0);
void resetLightBar(int pad = 0);
+// Gyro aiming (input/gyro.h): the mode (off, always, while L2 is held)
+// and the intensity 1..kGyroLevels; it only moves the right stick while
+// active (in a game with its menu closed).
+void setGyro(int mode, int level);
+void setGyroActive(bool on);
// DualSense: suppresses vibration and trigger effect bleed while embedded mic is active
void setEmbeddedMicActive(bool active, int pad = 0);
diff --git a/src/input/gyro.cpp b/src/input/gyro.cpp
new file mode 100644
index 0000000..2dfd09c
--- /dev/null
+++ b/src/input/gyro.cpp
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 RafaelNGP
+#include "input/gyro.h"
+
+#include <algorithm>
+#include <cmath>
+
+namespace xc::input {
+
+void gyroToStick(const float w[3], int level, GyroState& s, float& x, float& y) {
+ // Below ~1 degree a second it is the hand shaking or the sensor's noise.
+ constexpr float kNoise = 0.015f;
+ auto still = [](float v) { return std::abs(v) < kNoise ? 0.0f : v - std::copysign(kNoise, v); };
+ // Intensity 5: half a turn a second (~0.5 rad/s, a quick aim) is ~40 %.
+ const float scale = 0.16f * std::clamp(level, 1, kGyroLevels);
+ // Turning left (yaw +) aims left; tilting the top up (pitch +) aims up.
+ float tx = -still(w[1]) * scale, ty = -still(w[0]) * scale;
+ s.x += (tx - s.x) * 0.5f;
+ s.y += (ty - s.y) * 0.5f;
+ float m = std::hypot(s.x, s.y);
+ if (m < 0.005f) {
+ x = y = 0;
+ return;
+ }
+ // The games ignore about the first 10-20 % of the stick: start past it.
+ constexpr float kLift = 0.12f;
+ float lifted = std::min(1.0f, kLift + (1.0f - kLift) * m);
+ x = s.x / m * lifted;
+ y = s.y / m * lifted;
+}
+
+} // namespace xc::input
diff --git a/src/input/gyro.h b/src/input/gyro.h
new file mode 100644
index 0000000..2cd9996
--- /dev/null
+++ b/src/input/gyro.h
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 RafaelNGP
+// Gyro aiming: turning the DualSense moves the right stick, for the cloud
+// games that only know sticks. The turn speed (the pad's yaw and pitch) is
+// eased a little and lifted past the games' own stick dead zone, so small
+// turns still move the aim.
+#pragma once
+
+namespace xc::input {
+
+constexpr int kGyroLevels = 10; // intensity 1..kGyroLevels
+enum GyroMode { kGyroOff, kGyroAlways, kGyroAiming }; // kGyroAiming: while L2 is held
+
+struct GyroState {
+ float x = 0, y = 0; // the push given, eased
+};
+
+// `w`: the pad's angular velocity (rad/s; x pitch, y yaw, z roll) -> the
+// push to add to the right stick (pad convention: +x right, +y down).
+void gyroToStick(const float w[3], int level, GyroState& s, float& x, float& y);
+
+} // namespace xc::input
diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cpp
index 5f4950b..9596643 100644
--- a/src/ui/app_ui.cpp
+++ b/src/ui/app_ui.cpp
@@ -1201,6 +1201,12 @@ void AppUi::setSettings(const SettingsChoice& choice) {
dirty_ = true;
}
+void AppUi::setGyroDefaults(int mode, int level) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ gyroMode_ = mode;
+ gyroLevel_ = level;
+}
+
void AppUi::setPerGameSettings(const std::map<std::string, app::GameProfile>& perGame) {
std::lock_guard<std::mutex> lock(mutex_);
perGameSettings_ = perGame;
@@ -1230,6 +1236,8 @@ void AppUi::openGameSettings() {
activeGameProfile_.circleConfirms = settings_.circleConfirms;
activeGameProfile_.highRefresh = settings_.highRefresh;
activeGameProfile_.keyMap = settings_.keyMap;
+ activeGameProfile_.gyroMode = gyroMode_;
+ activeGameProfile_.gyroLevel = gyroLevel_;
}
}
@@ -2099,6 +2107,8 @@ void AppUi::handleGameSettings(const NavInput& in, UiEvent& ev) {
activeGameProfile_.triggerPulses = settings_.triggerPulses;
activeGameProfile_.circleConfirms = settings_.circleConfirms;
activeGameProfile_.highRefresh = settings_.highRefresh;
+ activeGameProfile_.gyroMode = gyroMode_;
+ activeGameProfile_.gyroLevel = gyroLevel_;
gameSettingsRow_ = 0;
dirty_ = true;
break;
diff --git a/src/ui/app_ui.h b/src/ui/app_ui.h
index 88daa06..57a067f 100644
--- a/src/ui/app_ui.h
+++ b/src/ui/app_ui.h
@@ -247,6 +247,9 @@ public:
void setSettings(const SettingsChoice& choice);
// Per-game settings
void setPerGameSettings(const std::map<std::string, app::GameProfile>& perGame);
+ // The general gyro aiming (set from the in-game menu): what a game
+ // without its own profile starts its game settings with.
+ void setGyroDefaults(int mode, int level);
bool gameSettingsOpen() const { return gameSettingsOpen_; }
void openGameSettings();
void closeGameSettings();
@@ -531,6 +534,7 @@ private:
bool gameSettingsOpen_ = false;
int gameSettingsRow_ = 0;
app::GameProfile activeGameProfile_;
+ int gyroMode_ = 0, gyroLevel_ = 5; // setGyroDefaults
bool activeGameHasCustom_ = false;
void handleGameSettings(const NavInput& in, UiEvent& ev);
void drawGameSettings(Canvas& c);
diff --git a/src/ui/stream_menu.cpp b/src/ui/stream_menu.cpp
index 5ba4f91..cf608b1 100644
--- a/src/ui/stream_menu.cpp
+++ b/src/ui/stream_menu.cpp
@@ -117,6 +117,16 @@ MenuAction StreamMenu::handle(const NavInput& in) {
circleConfirms_ = !circleConfirms_;
return MenuAction::ConfirmButton;
}
+ if (selected_ == GyroItem && (in.left || in.right || in.accept)) {
+ gyroMode_ = in.left ? (gyroMode_ + 2) % 3 : (gyroMode_ + 1) % 3; // off, always, while aiming
+ return MenuAction::Gyro;
+ }
+ if (selected_ == GyroLevelItem && (in.left || in.right)) {
+ int level = std::clamp(gyroLevel_ + (in.right ? 1 : -1), 1, 10);
+ if (level == gyroLevel_) return MenuAction::None;
+ gyroLevel_ = level;
+ return MenuAction::Gyro;
+ }
if (selected_ == Stats && (in.left || in.right)) {
stats_ = !stats_;
return MenuAction::Stats;
@@ -159,6 +169,8 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {
: i == Triggers ? tr(Str::TriggerRumble)
: i == DeadzoneItem ? tr(Str::Deadzone)
: i == ConfirmItem ? tr(Str::ConfirmButton)
+ : i == GyroItem ? tr(Str::Gyro)
+ : i == GyroLevelItem ? tr(Str::GyroIntensity)
: homeConsole_ ? tr(Str::MenuEndStream)
: tr(Str::MenuLeave);
fonts_.semibold.draw(c, label, row.x + 16, ty, kPx, fg);
@@ -200,6 +212,14 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {
value = std::to_string(deadzone_) + " %";
if (sel) value = "< " + value + " >";
}
+ if (i == GyroItem) {
+ value = tr(gyroMode_ == 1 ? Str::GyroAlways : gyroMode_ == 2 ? Str::GyroAiming : Str::Off);
+ if (sel) value = "< " + value + " >";
+ }
+ if (i == GyroLevelItem) {
+ value = std::to_string(gyroLevel_) + " / 10";
+ if (sel) value = "< " + value + " >";
+ }
if (i == ConfirmItem) {
value = circleConfirms_ ? "○" : "×";
if (sel) value = "< " + value + " >";
diff --git a/src/ui/stream_menu.h b/src/ui/stream_menu.h
index 75980aa..a430f0b 100644
--- a/src/ui/stream_menu.h
+++ b/src/ui/stream_menu.h
@@ -28,7 +28,7 @@ struct StreamInfo {
// Close: the menu went away (Circle, OPTIONS, or the Xbox button): a fresh key frame is asked for.
enum class MenuAction {
None, Close, Leave, Resolution, Stats, Sharpness, Deband, Upscaler, XboxButton,
- ProfileToggle, Triggers, Deadzone, ConfirmButton, MicToggle
+ ProfileToggle, Triggers, Deadzone, ConfirmButton, MicToggle, Gyro
};
class StreamMenu {
@@ -66,6 +66,10 @@ public:
void setDeadzone(int deadzone) { deadzone_ = deadzone; }
bool circleConfirms() const { return circleConfirms_; }
void setCircleConfirms(bool cc) { circleConfirms_ = cc; }
+ // Gyro aiming: mode (input::GyroMode) and intensity 1..input::kGyroLevels.
+ int gyroMode() const { return gyroMode_; }
+ int gyroLevel() const { return gyroLevel_; }
+ void setGyro(int mode, int level) { gyroMode_ = mode, gyroLevel_ = level; }
bool micMuted() const { return micMuted_; }
void setMicMuted(bool muted) { micMuted_ = muted; }
float micLevel() const { return micLevel_; }
@@ -97,6 +101,8 @@ private:
Triggers,
DeadzoneItem,
ConfirmItem,
+ GyroItem,
+ GyroLevelItem,
Leave,
ItemCount
};
@@ -112,6 +118,7 @@ private:
bool hasCustomProfile_ = false;
int triggerStrength_ = 2;
int deadzone_ = 15;
+ int gyroMode_ = 0, gyroLevel_ = 5;
bool micMuted_ = false;
float micLevel_ = 0.0f;
PadSlots pads_{};
diff --git a/src/ui/strings.cpp b/src/ui/strings.cpp
index fd84d2b..aab6e31 100644
--- a/src/ui/strings.cpp
+++ b/src/ui/strings.cpp
@@ -281,6 +281,10 @@ constexpr Column kEnglish = {
"Change", // ChangeKey
"Clear", // ClearKey
"The mouse moves the right stick and a wheel notch presses Triangle. F12 (menu), Home (Xbox button) and 1-4 (player) are kept by the app.", // KeysHelp
+ "Gyro aiming", // Gyro
+ "Always", // GyroAlways
+ "While aiming (L2)", // GyroAiming
+ "Gyro intensity", // GyroIntensity
};
constexpr Column kPortugueseBR = {
@@ -532,6 +536,10 @@ constexpr Column kPortugueseBR = {
"Alterar", // ChangeKey
"Limpar", // ClearKey
"O mouse move o analógico direito e cada clique da roda aperta Triângulo. F12 (menu), Home (botão Xbox) e 1-4 (jogador) são reservadas pelo app.", // KeysHelp
+ "Mira por giroscópio", // Gyro
+ "Sempre", // GyroAlways
+ "Ao mirar (L2)", // GyroAiming
+ "Intensidade do giroscópio", // GyroIntensity
};
constexpr Column kSpanish = {
@@ -783,6 +791,10 @@ constexpr Column kSpanish = {
"Cambiar", // ChangeKey
"Borrar", // ClearKey
"El ratón mueve el stick derecho y cada paso de la rueda pulsa Triángulo. F12 (menú), Inicio (botón Xbox) y 1-4 (jugador) las reserva la app.", // KeysHelp
+ "Apuntado con giroscopio", // Gyro
+ "Siempre", // GyroAlways
+ "Al apuntar (L2)", // GyroAiming
+ "Intensidad del giroscopio", // GyroIntensity
};
constexpr Column kFrench = {
@@ -1034,6 +1046,10 @@ constexpr Column kFrench = {
"Modifier", // ChangeKey
"Effacer", // ClearKey
"La souris déplace le joystick droit et chaque cran de la molette appuie sur Triangle. F12 (menu), Origine (bouton Xbox) et 1-4 (joueur) sont réservées par l'app.", // KeysHelp
+ "Visée gyroscopique", // Gyro
+ "Toujours", // GyroAlways
+ "En visant (L2)", // GyroAiming
+ "Intensité du gyroscope", // GyroIntensity
};
constexpr Column kGerman = {
@@ -1285,6 +1301,10 @@ constexpr Column kGerman = {
"Ändern", // ChangeKey
"Löschen", // ClearKey
"Die Maus bewegt den rechten Stick, jede Rasterstufe des Mausrads drückt Dreieck. F12 (Menü), Pos1 (Xbox-Taste) und 1-4 (Spieler) sind für die App reserviert.", // KeysHelp
+ "Gyro-Zielen", // Gyro
+ "Immer", // GyroAlways
+ "Beim Zielen (L2)", // GyroAiming
+ "Gyro-Stärke", // GyroIntensity
};
constexpr Column kItalian = {
@@ -1536,6 +1556,10 @@ constexpr Column kItalian = {
"Cambia", // ChangeKey
"Cancella", // ClearKey
"Il mouse muove la levetta destra e ogni scatto della rotella preme Triangolo. F12 (menu), Home (tasto Xbox) e 1-4 (giocatore) sono riservati all'app.", // KeysHelp
+ "Mira giroscopica", // Gyro
+ "Sempre", // GyroAlways
+ "Mirando (L2)", // GyroAiming
+ "Intensità giroscopio", // GyroIntensity
};
constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,
diff --git a/src/ui/strings.h b/src/ui/strings.h
index f1e3cf9..273ff94 100644
--- a/src/ui/strings.h
+++ b/src/ui/strings.h
@@ -258,6 +258,10 @@ enum class Str {
ChangeKey, // keyboard keys hint: Cross changes the key
ClearKey, // keyboard keys hint: Square takes it off
KeysHelp, // keyboard keys: the mouse and the keys the app keeps
+ Gyro, // in-game menu: gyro aiming (turning the DualSense moves the aim)
+ GyroAlways, // ... on all the time
+ GyroAiming, // ... only while L2 is held
+ GyroIntensity, // in-game menu: how far a turn moves the aim
Count
};
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 68e2bbe..916afa7 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -9,6 +9,7 @@
#include "app/report.h"
#include "media/audio_encoder.h"
#include "media/decoder.h"
+#include "input/gyro.h"
#include "input/tuning.h"
#include "net/http.h"
#include "platform/platform.h"
@@ -423,6 +424,11 @@ static void testStreamMenu() {
CHECK(press([](xc::ui::NavInput& n) { n.right = true; }) == MenuAction::Deadzone);
press([](xc::ui::NavInput& n) { n.down = true; });
CHECK(press([](xc::ui::NavInput& n) { n.right = true; }) == MenuAction::ConfirmButton);
+ press([](xc::ui::NavInput& n) { n.down = true; }); // gyro aiming: off -> always -> while aiming
+ CHECK(press([](xc::ui::NavInput& n) { n.right = true; }) == MenuAction::Gyro && menu.gyroMode() == 1);
+ CHECK(press([](xc::ui::NavInput& n) { n.right = true; }) == MenuAction::Gyro && menu.gyroMode() == 2);
+ press([](xc::ui::NavInput& n) { n.down = true; }); // its intensity, 1..10
+ CHECK(press([](xc::ui::NavInput& n) { n.left = true; }) == MenuAction::Gyro && menu.gyroLevel() == 4);
press([](xc::ui::NavInput& n) { n.down = true; }); // "Leave game", last
CHECK(press([](xc::ui::NavInput& n) { n.accept = true; }) == MenuAction::Leave);
CHECK(!menu.isOpen());
@@ -1047,8 +1053,37 @@ static void testLoginRetry() {
net::setTestTransport({});
}
+// Gyro aiming: still is nothing, a turn left aims left (past the games'
+// dead zone), more intensity aims further, the push eases back to nothing.
+static void testGyro() {
+ using namespace xc::input;
+ GyroState s;
+ float x = 1, y = 1;
+ const float still[3] = {0.01f, -0.01f, 0.0f};
+ gyroToStick(still, 5, s, x, y);
+ CHECK(x == 0 && y == 0);
+ const float left[3] = {0.0f, 0.5f, 0.0f}; // yaw +: turning left
+ for (int i = 0; i < 8; ++i) gyroToStick(left, 5, s, x, y);
+ CHECK(x < -0.3f && x > -0.6f && std::abs(y) < 1e-6f);
+ GyroState s2;
+ float x2 = 0, y2 = 0;
+ for (int i = 0; i < 8; ++i) gyroToStick(left, 10, s2, x2, y2);
+ CHECK(x2 < x);
+ const float up[3] = {0.3f, 0.0f, 0.0f}; // pitch +: the top tilted up
+ GyroState s3;
+ for (int i = 0; i < 8; ++i) gyroToStick(up, 5, s3, x, y);
+ CHECK(y < -0.12f && x == 0);
+ const float tiny[3] = {0.0f, 0.03f, 0.0f}; // a slow turn: still past the dead zone
+ GyroState s4;
+ for (int i = 0; i < 8; ++i) gyroToStick(tiny, 5, s4, x, y);
+ CHECK(x <= -0.12f);
+ for (int i = 0; i < 20; ++i) gyroToStick(still, 5, s4, x, y);
+ CHECK(x == 0);
+}
+
int main() {
testLoginRetry();
+ testGyro();
testReport();
testCrashGuard();
testBuiltinCa();