From c61adac77f6907eee8f06e115fdc85020b2f64a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 19 Oct 2026 11:22:44 +0200 Subject: [PATCH 1/3] Game browser: Going up a directory focuses the one you came out of Refresh already focused a game it was asked to. Now it does the same for directories, and keeps the request until a listing that was still loading has arrived. UI::ScrollFocusedViewIntoView scrolls the focused view into sight once it's been laid out, since SetFocus alone doesn't scroll. Co-Authored-By: Claude Opus 5.5 (1M context) --- Common/UI/Root.cpp | 12 ++++++++++++ Common/UI/Root.h | 3 +++ UI/GameBrowser.cpp | 28 +++++++++++++++++++++------- UI/GameBrowser.h | 4 +++- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Common/UI/Root.cpp b/Common/UI/Root.cpp index dabf6fdd7b..de7c963749 100644 --- a/Common/UI/Root.cpp +++ b/Common/UI/Root.cpp @@ -17,6 +17,7 @@ extern bool focusForced; static View *focusedView; static bool focusMovementEnabled; bool focusForced; +static bool scrollFocusedIntoView; static std::function soundCallback; @@ -105,6 +106,10 @@ View *GetFocusedView() { return focusedView; } +void ScrollFocusedViewIntoView() { + scrollFocusedIntoView = true; +} + void SetFocusedView(View *view, FocusFlags cause, bool force) { if (focusedView) { focusedView->FocusChanged(FocusFlags::LOST_FOCUS | cause); @@ -450,6 +455,13 @@ DialogResult UpdateViewHierarchy(ViewGroup *root, bool canEnableFocusMovement) { } focusMoves.clear(); + if (scrollFocusedIntoView) { + scrollFocusedIntoView = false; + if (focusedView) { + root->SubviewFocused(focusedView); + } + } + root->Update(); return DispatchEvents(); } diff --git a/Common/UI/Root.h b/Common/UI/Root.h index d975476f2f..bf1b0ab76f 100644 --- a/Common/UI/Root.h +++ b/Common/UI/Root.h @@ -18,6 +18,9 @@ void EnableFocusMovement(bool enable); bool IsFocusMovementEnabled(); View *GetFocusedView(); void SetFocusedView(View *view, FocusFlags cause, bool force = false); +// Scrolls the focused view into sight at the start of the next update, once it's been laid out. +// For focusing a view that was just created, since SetFocus doesn't scroll by itself. +void ScrollFocusedViewIntoView(); void RemoveQueuedEventsByEvent(Event *e); void RemoveQueuedEventsByView(View * v); diff --git a/UI/GameBrowser.cpp b/UI/GameBrowser.cpp index a32cc1dc92..fec0af9174 100644 --- a/UI/GameBrowser.cpp +++ b/UI/GameBrowser.cpp @@ -762,7 +762,7 @@ void GameBrowser::FocusGame(const Path &gamePath) { } } // Otherwise, Refresh focuses it when it recreates the buttons. - focusGamePath_ = gamePath; + focusPath_ = gamePath; refreshPending_ = true; } @@ -776,9 +776,7 @@ bool GameBrowser::Key(const KeyInput &input) { // Alt+Up goes to the parent directory, as in file managers. if ((input.flags & KeyInputFlags::DOWN) && (input.flags & KeyInputFlags::ModAlt) && input.keyCode == NKCODE_DPAD_UP && input.deviceId == DEVICE_ID_KEYBOARD) { if ((browseFlags_ & BrowseFlags::NAVIGATE) && path_.CanNavigateUp()) { - // Like the ".." button. - path_.Navigate(".."); - PathChanged(); + NavigateUp(); return true; } } @@ -1143,6 +1141,9 @@ void GameBrowser::Refresh() { for (size_t i = 0; i < dirButtons.size(); i++) { gameList_->Add(dirButtons[i])->OnClick.Handle(this, &GameBrowser::NavigateClick); + if (!focusPath_.empty() && dirButtons[i]->GetPath() == focusPath_ && dirButtons[i]->SetFocus(FocusFlags::CAUSE_RESTORE)) { + UI::ScrollFocusedViewIntoView(); + } } for (size_t i = 0; i < gameButtons.size(); i++) { @@ -1151,11 +1152,14 @@ void GameBrowser::Refresh() { b->OnHoldClick.Handle(this, &GameBrowser::GameButtonHoldClick); b->OnHighlight.Handle(this, &GameBrowser::GameButtonHighlight); - if (!focusGamePath_.empty() && b->GamePath() == focusGamePath_) { - b->SetFocus(FocusFlags::CAUSE_RESTORE); + if (!focusPath_.empty() && b->GamePath() == focusPath_ && b->SetFocus(FocusFlags::CAUSE_RESTORE)) { + UI::ScrollFocusedViewIntoView(); } } - focusGamePath_.clear(); + // A listing that's still loading has no buttons to focus yet. + if (!listingPending_) { + focusPath_.clear(); + } // Show a button to toggle pinning at the very end. if ((browseFlags_ & BrowseFlags::PIN) && !path_.GetPath().empty()) { @@ -1247,12 +1251,22 @@ void GameBrowser::NavigateClick(UI::EventParams &e) { Path text = button->GetPath(); if (button->PathAbsolute()) { path_.SetPath(text); + } else if (text.ToString() == "..") { + NavigateUp(); + return; } else { path_.Navigate(text.ToString()); } PathChanged(); } +void GameBrowser::NavigateUp() { + // Focus the directory we came out of, in the parent's listing. + focusPath_ = path_.GetPath(); + path_.Navigate(".."); + PathChanged(); +} + void GameBrowser::PathChanged() { g_Config.currentDirectory = path_.GetPath(); // Clear the search filter. This allow for smooth directory navigation using search diff --git a/UI/GameBrowser.h b/UI/GameBrowser.h index d7c8d4c2a2..c59dccc6b5 100644 --- a/UI/GameBrowser.h +++ b/UI/GameBrowser.h @@ -65,6 +65,7 @@ private: void GameButtonHoldClick(UI::EventParams &e); void GameButtonHighlight(UI::EventParams &e); void NavigateClick(UI::EventParams &e); + void NavigateUp(); void PathChanged(); void LayoutChange(UI::EventParams &e); void LastClick(UI::EventParams &e); @@ -85,7 +86,8 @@ private: ViewSearch search_{}; - Path focusGamePath_; + // A game or directory for Refresh to focus. + Path focusPath_; bool listingPending_ = false; bool refreshPending_ = false; float lastScale_ = 1.0f; From 193dd01c32b32af41e0adeeac170895c13b1f602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 19 Oct 2026 11:25:16 +0200 Subject: [PATCH 2/3] Game browser: Entering a directory focuses its first entry A subdirectory or game rather than "..", which only gets the focus in an empty directory. Co-Authored-By: Claude Opus 5.5 (1M context) --- UI/GameBrowser.cpp | 14 ++++++++++++-- UI/GameBrowser.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/UI/GameBrowser.cpp b/UI/GameBrowser.cpp index fec0af9174..7ea5f65cf1 100644 --- a/UI/GameBrowser.cpp +++ b/UI/GameBrowser.cpp @@ -1120,10 +1120,11 @@ void GameBrowser::Refresh() { } } + DirButton *upButton = nullptr; if (browseFlags_ & BrowseFlags::NAVIGATE) { if (path_.CanNavigateUp()) { - gameList_->Add(new DirButton(Path(".."), lastViewMode_, new UI::LinearLayoutParams(UI::FILL_PARENT, UI::FILL_PARENT)))-> - OnClick.Handle(this, &GameBrowser::NavigateClick); + upButton = gameList_->Add(new DirButton(Path(".."), lastViewMode_, new UI::LinearLayoutParams(UI::FILL_PARENT, UI::FILL_PARENT))); + upButton->OnClick.Handle(this, &GameBrowser::NavigateClick); } // Add any pinned paths before other directories. @@ -1158,6 +1159,14 @@ void GameBrowser::Refresh() { } // A listing that's still loading has no buttons to focus yet. if (!listingPending_) { + if (focusFirstItem_) { + // The folder's own contents rather than "..", which only shows up first if it's empty. + UI::View *first = !dirButtons.empty() ? (UI::View *)dirButtons[0] : !gameButtons.empty() ? (UI::View *)gameButtons[0] : upButton; + if (first && first->SetFocus(FocusFlags::CAUSE_RESTORE)) { + UI::ScrollFocusedViewIntoView(); + } + } + focusFirstItem_ = false; focusPath_.clear(); } @@ -1257,6 +1266,7 @@ void GameBrowser::NavigateClick(UI::EventParams &e) { } else { path_.Navigate(text.ToString()); } + focusFirstItem_ = true; PathChanged(); } diff --git a/UI/GameBrowser.h b/UI/GameBrowser.h index c59dccc6b5..02997a8c83 100644 --- a/UI/GameBrowser.h +++ b/UI/GameBrowser.h @@ -88,6 +88,8 @@ private: // A game or directory for Refresh to focus. Path focusPath_; + // Set when entering a directory, for Refresh to focus its first entry. + bool focusFirstItem_ = false; bool listingPending_ = false; bool refreshPending_ = false; float lastScale_ = 1.0f; From b0382ed91adfef277f665b32c0cd1ba4bea28f09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 19 Oct 2026 11:36:30 +0200 Subject: [PATCH 3/3] Game browser: Backspace goes up a directory, Windows raw input flags key repeats With no type-to-search active, Backspace goes to the parent directory. Never on a repeat, so holding it doesn't climb to the root. Not every platform flags repeats, so the browser also tracks whether it's held. Windows raw input now flags auto-repeated key downs as IS_REPEAT, like Android and UWP, and forgets the held keys it releases on losing focus. The UI drops OS repeats of a key it's already repeating itself, so held arrows don't double up (they were dropped before too, a step later). Co-Authored-By: Claude Opus 5.5 (1M context) --- Common/UI/Root.cpp | 12 ++++++++++++ UI/GameBrowser.cpp | 16 ++++++++++++++++ UI/GameBrowser.h | 1 + UI/MiscViews.cpp | 3 +-- Windows/RawInput.cpp | 7 ++++++- 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Common/UI/Root.cpp b/Common/UI/Root.cpp index de7c963749..24eeb93bd4 100644 --- a/Common/UI/Root.cpp +++ b/Common/UI/Root.cpp @@ -257,6 +257,18 @@ static bool KeyToFocusMove(const KeyInput &key, FocusMove *move) { KeyEventResult KeyEventToFocusMoves(const KeyInput &key) { KeyEventResult retval = KeyEventResult::PASS_THROUGH; + // The OS's own repeats of a key we're already repeating (see ProcessHeldKeys) would double + // up with ours, in a text field for example. + if ((key.flags & KeyInputFlags::DOWN) && (key.flags & KeyInputFlags::IS_REPEAT) && !heldKeys.empty()) { + HeldKey hk; + hk.key = key.keyCode; + hk.deviceId = key.deviceId; + hk.triggerTime = 0.0; // irrelevant + hk.move = FocusMove::NEXT; // irrelevant, not part of the comparison + if (heldKeys.find(hk) != heldKeys.end()) { + return KeyEventResult::IGNORE_KEY; + } + } // Ignore repeats for focus moves. if ((key.flags & KeyInputFlags::DOWN) && !(key.flags & KeyInputFlags::IS_REPEAT)) { FocusMove move; diff --git a/UI/GameBrowser.cpp b/UI/GameBrowser.cpp index 7ea5f65cf1..579518a9c1 100644 --- a/UI/GameBrowser.cpp +++ b/UI/GameBrowser.cpp @@ -781,6 +781,22 @@ bool GameBrowser::Key(const KeyInput &input) { } } + // Backspace with no search going also goes to the parent directory, as in file managers. Never on + // a repeat, or holding it would climb to the root (or carry on up after clearing a search). Not + // every platform flags repeats, so this also tracks whether it's held. + if (input.keyCode == NKCODE_DEL && input.deviceId == DEVICE_ID_KEYBOARD) { + if (input.flags & KeyInputFlags::UP) { + backspaceHeld_ = false; + } else if (input.flags & KeyInputFlags::DOWN) { + const bool repeat = backspaceHeld_ || (input.flags & KeyInputFlags::IS_REPEAT); + backspaceHeld_ = true; + if (!repeat && search_.searchFilter.empty() && (browseFlags_ & BrowseFlags::NAVIGATE) && path_.CanNavigateUp()) { + NavigateUp(); + return true; + } + } + } + bool retval = LinearLayout::Key(input); if (retval) { return true; diff --git a/UI/GameBrowser.h b/UI/GameBrowser.h index 02997a8c83..75ad56a646 100644 --- a/UI/GameBrowser.h +++ b/UI/GameBrowser.h @@ -90,6 +90,7 @@ private: Path focusPath_; // Set when entering a directory, for Refresh to focus its first entry. bool focusFirstItem_ = false; + bool backspaceHeld_ = false; bool listingPending_ = false; bool refreshPending_ = false; float lastScale_ = 1.0f; diff --git a/UI/MiscViews.cpp b/UI/MiscViews.cpp index cb44651871..4267749028 100644 --- a/UI/MiscViews.cpp +++ b/UI/MiscViews.cpp @@ -507,9 +507,8 @@ bool ViewSearch::Key(UI::ViewGroup *viewGroup, const KeyInput &input) { // TODO: Restore focus state here. UI::EnableFocusMovement(false); } - } else { - // Empty search filter. Navigate upwards on backspace? } + // With an empty filter, it's up to the owner (the game browser goes up a directory). } else if (!searchFilter.empty() && input.keyCode == NKCODE_ESCAPE) { searchFilter.clear(); ApplySearchFilter(viewGroup, false); diff --git a/Windows/RawInput.cpp b/Windows/RawInput.cpp index e820ca93a1..47a0392633 100644 --- a/Windows/RawInput.cpp +++ b/Windows/RawInput.cpp @@ -264,8 +264,11 @@ namespace WindowsRawInput { key.keyCode = GetTrueVKey(raw->data.keyboard); if (key.keyCode) { + // Windows auto-repeats a held key as more key downs. Flag them, like other platforms do. + if (!keyboardKeysDown.insert(key.keyCode).second) { + key.flags |= KeyInputFlags::IS_REPEAT; + } NativeKey(key); - keyboardKeysDown.insert(key.keyCode); } } else if (raw->data.keyboard.Message == WM_KEYUP || raw->data.keyboard.Message == WM_SYSKEYUP) { // A key released while Alt is held comes as WM_SYSKEYUP. @@ -434,6 +437,8 @@ namespace WindowsRawInput { key.keyCode = *i; NativeKey(key); } + // Or the next press of one would count as a repeat. + keyboardKeysDown.clear(); focused = false; }