From cff77258937400618ef17aa588a25aca20e8fc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 17 Oct 2026 14:14:14 +0200 Subject: [PATCH] Main screen: Come back to the same tab after exiting a game Leaving a game creates a new MainScreen, which picked the default tab (Recent unless changed) whenever there were recent files. Remember the tab for the rest of the session, so the default tab only applies to the first main screen after startup. Co-Authored-By: Claude Opus 5.5 (1M context) --- UI/MainScreen.cpp | 17 ++++++++++++++++- UI/MainScreen.h | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index ba46909733..145876b40d 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -189,12 +189,23 @@ static bool IsTempPath(const Path &str) { return false; } +// Leaving a game creates a new MainScreen, which should come back on the tab the game was +// launched from. The default tab setting is only for the first one after startup. +static int g_lastMainScreenTab = -1; +// Tab indices shift when the Recent tab isn't shown, so the saved tab only applies if this matches. +static bool g_lastMainScreenHadRecent = false; + MainScreen::MainScreen() { g_BackgroundAudio.SetGame(Path()); packGeneration_ = GamePacker::Generation(); } MainScreen::~MainScreen() { + // RemoteISOBrowseScreen derives from us, but with tabs of its own. + if (tabHolder_ && createdMainTabs_) { + g_lastMainScreenTab = tabHolder_->GetCurrentTab(); + g_lastMainScreenHadRecent = recentTabShown_; + } g_BackgroundAudio.SetGame(Path()); } @@ -445,6 +456,8 @@ void MainScreen::CreateViews() { if (showRecent) { CreateRecentTab(); } + recentTabShown_ = showRecent; + createdMainTabs_ = true; Button *focusButton = nullptr; if (hasStorageAccess) { @@ -457,7 +470,9 @@ void MainScreen::CreateViews() { remoteBrowser->SetHomePath(remotePath); } - if (g_recentFiles.HasAny()) { + if (g_lastMainScreenTab >= 0 && g_lastMainScreenHadRecent == showRecent) { + tabHolder_->SetCurrentTab(g_lastMainScreenTab, true); + } else if (g_recentFiles.HasAny()) { tabHolder_->SetCurrentTab(std::clamp(g_Config.iDefaultTab, 0, g_Config.bRemoteTab ? 3 : 2), true); } else if (g_Config.iMaxRecent > 0) { tabHolder_->SetCurrentTab(1, true); diff --git a/UI/MainScreen.h b/UI/MainScreen.h index 18e132917a..2a21b9e6f9 100644 --- a/UI/MainScreen.h +++ b/UI/MainScreen.h @@ -94,6 +94,8 @@ protected: bool lastVertical_ = false; bool confirmedTemporary_ = false; bool searchChanged_ = false; + bool recentTabShown_ = false; + bool createdMainTabs_ = false; std::string searchFilter_; friend class RemoteISOBrowseScreen;