Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Go round to the top row with Down in side menus

Leonardo Lobatoe3df1eb01cd5
diff --git a/src/homebrew/host.cpp b/src/homebrew/host.cpp
index a718acb..6802ecf 100644
--- a/src/homebrew/host.cpp
+++ b/src/homebrew/host.cpp
@@ -358,10 +358,10 @@ const char* action_name(hui::Action action) {
void apply_input(playden::homebrew::Simulation& simulation, const hui::InputFrame& frame) {
switch (frame.nav) {
- case hui::Direction::up: simulation.action("up"); break;
- case hui::Direction::down: simulation.action("down"); break;
- case hui::Direction::left: simulation.action("left"); break;
- case hui::Direction::right: simulation.action("right"); break;
+ case hui::Direction::up: simulation.action("up", frame.nav_repeat); break;
+ case hui::Direction::down: simulation.action("down", frame.nav_repeat); break;
+ case hui::Direction::left: simulation.action("left", frame.nav_repeat); break;
+ case hui::Direction::right: simulation.action("right", frame.nav_repeat); break;
case hui::Direction::none: break;
}
for (unsigned index = static_cast<unsigned>(hui::Action::confirm);
diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cpp
index a2e618e..5c829a9 100644
--- a/src/homebrew/ps5.cpp
+++ b/src/homebrew/ps5.cpp
@@ -75,10 +75,10 @@ extern "C" void hui_release_splash(void) { playden_release_splash(); }
namespace {
void dispatch(playden::homebrew::Simulation& simulation, const hui::InputFrame& input) {
switch (input.nav) {
- case hui::Direction::up: simulation.action("up"); break;
- case hui::Direction::down: simulation.action("down"); break;
- case hui::Direction::left: simulation.action("left"); break;
- case hui::Direction::right: simulation.action("right"); break;
+ case hui::Direction::up: simulation.action("up", input.nav_repeat); break;
+ case hui::Direction::down: simulation.action("down", input.nav_repeat); break;
+ case hui::Direction::left: simulation.action("left", input.nav_repeat); break;
+ case hui::Direction::right: simulation.action("right", input.nav_repeat); break;
default: break;
}
const std::array<std::pair<hui::Action, const char*>, 10> actions{{
@@ -1015,7 +1015,7 @@ int main() {
// A USB keyboard types into the open text box and also moves around Playden.
for (const auto& command : keyboard_input.Update(keyboard.read(), simulation.state().editor.active, now)) {
if (!command.text.empty()) simulation.text(command.text);
- else simulation.action(command.action);
+ else simulation.action(command.action, command.repeat);
}
}
simulation.controller_sample(playden::homebrew::diagnostic_sample(input));
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index 1f5ca2d..fda0acd 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -8515,7 +8515,7 @@ int route_tab(Route route) {
}
} // namespace
-void Simulation::move(int delta_x, int delta_y) {
+void Simulation::move(int delta_x, int delta_y, bool repeat) {
if (state_.editor.active) {
state_.editor.focus_row = std::clamp(state_.editor.focus_row + delta_y, 0, 4);
// A password's bottom row has a Show key between space and backspace.
@@ -8530,20 +8530,24 @@ void Simulation::move(int delta_x, int delta_y) {
state_.log_offset = std::clamp(state_.log_offset + delta, 0, std::max(0, static_cast<int>(state_.log_lines.size()) - 8));
return;
}
- // Up from a side menu's top row goes round to its last row (a jump stops at the top); a dialog's buttons stay
- // where they are.
- if (delta_y == -1 && !modal.destructive && modal.id != "confirmation" && !modal.action_keys.empty()) {
+ // Up from a side menu's top row goes round to its last row, and Down from its last row to its top row. A held
+ // direction stops at the end first, and a new press goes round; a jump stops at the end. A dialog's buttons
+ // stay where they are.
+ if ((delta_y == -1 || delta_y == 1) && !modal.destructive && modal.id != "confirmation" && !modal.action_keys.empty()) {
const auto passed_over = [&modal](int index) {
const auto& key = modal.action_keys[static_cast<std::size_t>(index)];
return SheetDecoration(key) || (modal.id == "import-games" && key.rfind("import-group-", 0) == 0);
};
- bool above = false;
- for (int index = 0; index < modal.focused_action; ++index) above = above || !passed_over(index);
- if (!above) {
- int bottom = static_cast<int>(modal.action_keys.size()) - 1;
- while (bottom > modal.focused_action && passed_over(bottom)) --bottom;
- modal.focused_action = bottom;
- state_.navigation.focus_key = modal.action_keys[static_cast<std::size_t>(bottom)];
+ const int count = static_cast<int>(modal.action_keys.size());
+ bool beyond = false;
+ for (int index = modal.focused_action + delta_y; index >= 0 && index < count; index += delta_y)
+ beyond = beyond || !passed_over(index);
+ if (!beyond) {
+ if (repeat) return;
+ int other_end = delta_y < 0 ? count - 1 : 0;
+ while (other_end != modal.focused_action && passed_over(other_end)) other_end -= delta_y;
+ modal.focused_action = other_end;
+ state_.navigation.focus_key = modal.action_keys[static_cast<std::size_t>(other_end)];
return;
}
}
@@ -10625,7 +10629,7 @@ void Simulation::activate() {
else if (action_name == "account-switch") { pending_destructive_action_ = "account-switch"; open_modal({"confirmation", "Switch account? Current account cache will be cleared.", state_.navigation.focus_key, {"cancel", "confirm-destructive"}, 0, true}); }
}
-bool Simulation::action(const std::string& logical_action) {
+bool Simulation::action(const std::string& logical_action, bool repeat) {
// Any input settles Details focus where the user put it.
details_primary_pending_ = false;
state_.controller = {};
@@ -10867,8 +10871,8 @@ bool Simulation::action(const std::string& logical_action) {
offset = std::clamp(offset + (logical_action == "l2" ? -1 : 1), 0, last_page);
rebuild_view(); return true;
}
- if (logical_action == "up") move(0, -1);
- else if (logical_action == "down") move(0, 1);
+ if (logical_action == "up") move(0, -1, repeat);
+ else if (logical_action == "down") move(0, 1, repeat);
else if (logical_action == "left") move(-1, 0);
else if (logical_action == "right") move(1, 0);
else if (logical_action == "l2") move(0, -4);
diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hpp
index d744108..860aef5 100644
--- a/src/homebrew/simulation.hpp
+++ b/src/homebrew/simulation.hpp
@@ -971,7 +971,8 @@ public:
ModelMode mode = ModelMode::Simulation);
bool scenario(const std::string& name);
- bool action(const std::string& logical_action);
+ // repeat: the step comes from a held direction, not a new press (a side menu stops at its ends).
+ bool action(const std::string& logical_action, bool repeat = false);
void controller_sample(ControllerState sample);
void text(const std::string& utf8);
// The PS5 system keyboard's accepted text replaces the open editor's value and commits it, as Done does.
@@ -1445,7 +1446,7 @@ private:
void rebuild_view();
void activate();
void cancel();
- void move(int delta_x, int delta_y);
+ void move(int delta_x, int delta_y, bool repeat = false);
void move_content(int delta_x, int delta_y);
[[nodiscard]] bool tab_bar_shown() const;
bool move_settings(int delta_x, int delta_y);
diff --git a/src/homebrew/usb_keyboard.cpp b/src/homebrew/usb_keyboard.cpp
index 49c0939..a5ebfb4 100644
--- a/src/homebrew/usb_keyboard.cpp
+++ b/src/homebrew/usb_keyboard.cpp
@@ -122,8 +122,10 @@ std::vector<KeyboardCommand> KeyboardInput::Update(const KeyboardReport& report,
}
if (repeating_ != 0 && std::find(keys.begin(), keys.end(), repeating_) == keys.end()) repeating_ = 0;
if (repeating_ != 0 && commands.empty() && now_us >= next_repeat_us_) {
- if (auto command = KeyCommand(repeating_, report.modifiers, editing); !command.text.empty() || !command.action.empty())
+ if (auto command = KeyCommand(repeating_, report.modifiers, editing); !command.text.empty() || !command.action.empty()) {
+ command.repeat = true;
commands.push_back(std::move(command));
+ }
next_repeat_us_ = now_us + kRepeatIntervalUs;
}
held_ = keys;
diff --git a/src/homebrew/usb_keyboard.hpp b/src/homebrew/usb_keyboard.hpp
index c1459fa..7f2b9f7 100644
--- a/src/homebrew/usb_keyboard.hpp
+++ b/src/homebrew/usb_keyboard.hpp
@@ -26,6 +26,7 @@ KeyboardReport ParseKeyboardState(const std::uint8_t* state);
struct KeyboardCommand {
std::string text;
std::string action;
+ bool repeat = false; // a held key's repeat, not a new press
};
// Turns successive reports into commands: a key acts when it goes down, and a held key repeats
diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cpp
index 5a9f4bd..ba8f579 100644
--- a/tests/homebrew_library_model_test.cpp
+++ b/tests/homebrew_library_model_test.cpp
@@ -1532,8 +1532,12 @@ void live_filters_sheet_sections() {
check(!model.action("focus:heading-sort") && !model.action("focus:divider") && model.state().navigation.focus_key=="sort-name",
"a heading or the divider can't be focused directly");
// The last action can be reached, past everything else.
- for(int step=0;step<12;++step) model.action("down");
- check(model.state().navigation.focus_key=="cancel","down ends on the last action");
+ // Held, Down stops on the last action; a new press goes round to the first sort, and Up held stops there.
+ for(int step=0;step<12;++step) model.action("down",true);
+ check(model.state().navigation.focus_key=="cancel","held down stops on the last action");
+ check(model.action("down") && model.state().navigation.focus_key=="sort-name","down from the last action goes to the first sort");
+ check(model.action("up",true) && model.state().navigation.focus_key=="sort-name","held up stops on the first sort");
+ check(model.action("down",true) && model.action("focus:cancel"),"back on the last action");
activate(model,"filter-compat-playable");
check(model.action("triangle"),"filter modal opens again");
diff --git a/tests/homebrew_live_model_test.cpp b/tests/homebrew_live_model_test.cpp
index c73a135..1735e94 100644
--- a/tests/homebrew_live_model_test.cpp
+++ b/tests/homebrew_live_model_test.cpp
@@ -854,7 +854,8 @@ void live_runs_setup_program_once(const std::filesystem::path& base) {
model.NotifyLauncherHint(SteamId(35140), "Binaries/BatmanAC.exe");
check(model.state().navigation.modals.empty(), "launcher hint: not offered with the setting on");
- // Up from a side menu's top row goes round to its last row, and carries on from there.
+ // Up from a side menu's top row goes round to its last row, and carries on from there; Down from the last row
+ // goes round to the top. A held direction stops at the end first.
{
activate(model, "details-more");
const auto keys = model.state().navigation.modals.back().action_keys;
@@ -863,9 +864,13 @@ void live_runs_setup_program_once(const std::filesystem::path& base) {
check(model.state().navigation.focus_key == keys.back(), "side menu: Up from the top goes to the last row");
model.action("up");
check(model.state().navigation.focus_key == keys[keys.size() - 2], "side menu: Up carries on from the bottom");
+ model.action("down", true);
+ model.action("down", true);
+ check(model.state().navigation.focus_key == keys.back(), "side menu: a held Down stops on the last row");
model.action("down");
- model.action("down");
- check(model.state().navigation.focus_key == keys.back(), "side menu: Down stops on the last row");
+ check(model.state().navigation.focus_key == keys.front(), "side menu: Down from the last row goes to the top");
+ model.action("up", true);
+ check(model.state().navigation.focus_key == keys.front(), "side menu: a held Up stops on the top row");
while (!model.state().navigation.modals.empty()) model.action("circle");
}
diff --git a/tests/homebrew_usb_keyboard_test.cpp b/tests/homebrew_usb_keyboard_test.cpp
index 6be6050..aad6f83 100644
--- a/tests/homebrew_usb_keyboard_test.cpp
+++ b/tests/homebrew_usb_keyboard_test.cpp
@@ -68,6 +68,15 @@ int main() {
CHECK(Typed(input.Update(Keys({0x06}, 0x01), true, now += 20000)).empty());
CHECK(Typed(input.Update(Keys({}), true, now += 20000)).empty());
+ // A held arrow's repeats say they are repeats, so a side menu stops at its ends.
+ {
+ const auto first = input.Update(Keys({0x51}), false, now += 20000);
+ CHECK(first.size() == 1 && first[0].action == "down" && !first[0].repeat);
+ const auto held = input.Update(Keys({0x51}), false, now += 500000);
+ CHECK(held.size() == 1 && held[0].action == "down" && held[0].repeat);
+ CHECK(input.Update(Keys({}), false, now += 20000).empty());
+ }
+
// A held key repeats after a delay; Enter does not.
CHECK(Typed(input.Update(Keys({0x07}), true, now += 20000)) == "d");
CHECK(Typed(input.Update(Keys({0x07}), true, now += 100000)).empty());