Fix audio focus issue by tracking the cause of lost focus.

Fixes #21643
This commit is contained in:
Henrik Rydgård committed 2026-05-06 00:06:32 +02:00
1 parent d4bd7c604c
commit 3a599c4714
16 files changed
+95 -70

No files matched your search

+9 -4
View File
@@ -665,12 +665,14 @@ void MainScreen::OnGameHighlight(UI::EventParams &e) {
Path path(e.s);
if (path == highlightedGamePath_ && e.a == FF_GOTFOCUS) {
const FocusFlags focusFlags = (FocusFlags)e.a;
if (path == highlightedGamePath_ && (focusFlags & FocusFlags::GOT_FOCUS)) {
// Already highlighted, nothing to do.
return;
}
if (e.a == FF_LOSTFOCUS) {
if (focusFlags & FocusFlags::LOST_FOCUS) {
// Lost focus, so we want to fade out the background.
// Trigger fadeouts on any active highlights.
@@ -680,7 +682,10 @@ void MainScreen::OnGameHighlight(UI::EventParams &e) {
}
}
highlightedGamePath_.clear();
g_BackgroundAudio.SetGame(Path());
if ((focusFlags & FocusFlags::CAUSE_FOCUS_MOVE) || (focusFlags & FocusFlags::CAUSE_KB_FOCUS_DISABLED)) {
// Focus moved to another game, so we want to fade out so we can fade in the new one.
g_BackgroundAudio.SetGame(Path());
}
return;
}
@@ -695,7 +700,7 @@ void MainScreen::OnGameHighlight(UI::EventParams &e) {
// Add a new entry to the highlight list.
highlightedBackgrounds_.push_back({path, time_now_d(), -1.0});
if ((!highlightedGamePath_.empty() || e.a == FF_LOSTFOCUS) && !lockBackgroundAudio_) {
if ((!highlightedGamePath_.empty() || (focusFlags & FocusFlags::LOST_FOCUS)) && !lockBackgroundAudio_) {
g_BackgroundAudio.SetGame(highlightedGamePath_);
}