From 3d0b2de319e2193e095089fda30c8954a461de6a Mon Sep 17 00:00:00 2001 From: casey langen Date: Mon, 12 Oct 2020 10:55:39 -0700 Subject: [PATCH] Fix re-focus behavior to ensure SOMETHING always gets focused when switching screens. --- src/musikcube/cursespp/AppLayout.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/musikcube/cursespp/AppLayout.cpp b/src/musikcube/cursespp/AppLayout.cpp index f06011fbc..0ccc4ea49 100644 --- a/src/musikcube/cursespp/AppLayout.cpp +++ b/src/musikcube/cursespp/AppLayout.cpp @@ -41,6 +41,8 @@ using namespace cursespp; +/* TODO: this seems to be busted in many cases; either fix the +implementation or get rid of this. */ static std::map lastFocusMap; #define ENABLE_DEMO_MODE 0 @@ -155,8 +157,8 @@ IWindowPtr AppLayout::FocusPrev() { void AppLayout::SetLayout(std::shared_ptr layout) { if (layout != this->layout) { if (this->layout) { - this->RemoveWindow(this->layout); last(this->layout.get(), this->layout->GetFocusIndex()); + this->RemoveWindow(this->layout); this->layout->Hide(); } @@ -180,7 +182,7 @@ void AppLayout::SetLayout(std::shared_ptr layout) { this->Layout(); if (!this->shortcuts->IsFocused()) { - auto lastFocusIndex = last(this->layout.get()); + auto lastFocusIndex = std::max(0, last(this->layout.get())); this->layout->SetFocusIndex(lastFocusIndex); } }