From b71d5768de895b652a0b93cb07878e34d01126b9 Mon Sep 17 00:00:00 2001 From: casey langen Date: Mon, 11 Sep 2017 01:00:40 -0700 Subject: [PATCH] Fixed a bug that could cause focus to get completely lost if the transport is focused while switching between main views. --- src/musikcube/app/layout/LibraryLayout.cpp | 9 ++++++++- src/musikcube/app/layout/MainLayout.cpp | 15 +++++++++++++++ src/musikcube/app/layout/NowPlayingLayout.cpp | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/musikcube/app/layout/LibraryLayout.cpp b/src/musikcube/app/layout/LibraryLayout.cpp index 0c181391f..4a690d6bb 100755 --- a/src/musikcube/app/layout/LibraryLayout.cpp +++ b/src/musikcube/app/layout/LibraryLayout.cpp @@ -277,7 +277,14 @@ IWindowPtr LibraryLayout::GetFocus() { return this->transportView; } - return this->visibleLayout->GetFocus(); + auto result = this->visibleLayout->GetFocus(); + + if (!result) { + this->visibleLayout->SetFocusIndex(0); + result = this->visibleLayout->GetFocus(); + } + + return result; } bool LibraryLayout::SetFocus(cursespp::IWindowPtr window) { diff --git a/src/musikcube/app/layout/MainLayout.cpp b/src/musikcube/app/layout/MainLayout.cpp index 7662f5727..eca83d066 100755 --- a/src/musikcube/app/layout/MainLayout.cpp +++ b/src/musikcube/app/layout/MainLayout.cpp @@ -47,6 +47,8 @@ #include #include +#include + #include "SettingsLayout.h" #include "MainLayout.h" @@ -57,6 +59,7 @@ using namespace musik::core::runtime; using namespace cursespp; static UpdateCheck updateCheck; +static std::map lastFocusMap; #define ENABLE_DEMO_MODE 0 @@ -65,6 +68,15 @@ static std::string lastKey; static int lastKeyRepeat = 0; #endif +static int last(ILayout* layout) { + auto it = lastFocusMap.find(layout); + return (it == lastFocusMap.end()) ? 0 : it->second; +} + +static void last(ILayout* layout, int last) { + lastFocusMap[layout] = last; +} + static void updateSyncingText(TextLabel* label, int updates) { try { if (updates <= 0) { @@ -206,6 +218,8 @@ void MainLayout::SetMainLayout(std::shared_ptr layout) { } this->RemoveWindow(this->layout); + last(this->layout.get(), this->layout->GetFocusIndex()); + this->layout->SetFocusIndex(-1); this->layout->Hide(); } @@ -226,6 +240,7 @@ void MainLayout::SetMainLayout(std::shared_ptr layout) { this->AddWindow(this->layout); this->layout->SetFocusOrder(0); + this->layout->SetFocusIndex(last(this->layout.get())); this->Layout(); } } diff --git a/src/musikcube/app/layout/NowPlayingLayout.cpp b/src/musikcube/app/layout/NowPlayingLayout.cpp index a0017a81d..20e367616 100755 --- a/src/musikcube/app/layout/NowPlayingLayout.cpp +++ b/src/musikcube/app/layout/NowPlayingLayout.cpp @@ -120,7 +120,7 @@ void NowPlayingLayout::OnLayout() { this->GetWidth(), this->GetHeight()); - this->trackListView->SetFocusOrder(1); + this->trackListView->SetFocusOrder(0); } void NowPlayingLayout::InitializeWindows() {