From 2e1ea995cfaed64ccf6d488ae3e9e6803a88634d Mon Sep 17 00:00:00 2001 From: casey langen Date: Tue, 5 Mar 2019 22:46:29 -0800 Subject: [PATCH] Revert "Scary experimental changes to the way focus is tracked to reduce" This reverts commit 22900b2c837080059b28560a1ce5d60a0033f991. --- src/musikcube/app/layout/LibraryLayout.cpp | 4 ++++ src/musikcube/app/window/TransportWindow.cpp | 1 + src/musikcube/cursespp/App.cpp | 4 ++++ src/musikcube/cursespp/AppLayout.cpp | 5 +++++ src/musikcube/cursespp/LayoutBase.cpp | 5 +++++ src/musikcube/cursespp/Window.cpp | 14 -------------- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/musikcube/app/layout/LibraryLayout.cpp b/src/musikcube/app/layout/LibraryLayout.cpp index f04042308..e0b501bd0 100755 --- a/src/musikcube/app/layout/LibraryLayout.cpp +++ b/src/musikcube/app/layout/LibraryLayout.cpp @@ -306,6 +306,7 @@ IWindowPtr LibraryLayout::FocusNext() { return this->transportView; } + this->transportView->Blur(); return this->visibleLayout->FocusFirst(); } @@ -318,6 +319,7 @@ IWindowPtr LibraryLayout::FocusPrev() { return this->transportView; } + this->transportView->Blur(); return this->visibleLayout->FocusLast(); } @@ -450,10 +452,12 @@ bool LibraryLayout::KeyPress(const std::string& key) { return true; } else if (this->GetFocus() == this->transportView && Hotkeys::Is(Hotkeys::Up, key)) { + this->transportView->Blur(); this->visibleLayout->FocusLast(); return true; } else if (this->GetFocus() == this->transportView && Hotkeys::Is(Hotkeys::Down, key)) { + this->transportView->Blur(); this->visibleLayout->FocusFirst(); return true; } diff --git a/src/musikcube/app/window/TransportWindow.cpp b/src/musikcube/app/window/TransportWindow.cpp index 69da63e08..0f5c2b627 100755 --- a/src/musikcube/app/window/TransportWindow.cpp +++ b/src/musikcube/app/window/TransportWindow.cpp @@ -360,6 +360,7 @@ void TransportWindow::SetFocus(FocusTarget target) { if (this->focus == FocusNone) { this->lastFocus = last; + this->Blur(); } else { this->Focus(); diff --git a/src/musikcube/cursespp/App.cpp b/src/musikcube/cursespp/App.cpp index a2990c54d..3ba8e25ff 100755 --- a/src/musikcube/cursespp/App.cpp +++ b/src/musikcube/cursespp/App.cpp @@ -449,6 +449,10 @@ process: void App::UpdateFocusedWindow(IWindowPtr window) { if (this->state.focused != window) { + if (this->state.focused) { + this->state.focused->Blur(); + } + this->state.focused = window; this->state.input = dynamic_cast(window.get()); this->state.keyHandler = dynamic_cast(window.get()); diff --git a/src/musikcube/cursespp/AppLayout.cpp b/src/musikcube/cursespp/AppLayout.cpp index 20743be28..20e2e10ec 100644 --- a/src/musikcube/cursespp/AppLayout.cpp +++ b/src/musikcube/cursespp/AppLayout.cpp @@ -203,6 +203,11 @@ void AppLayout::FocusShortcuts() { if (this->layout) { this->lastFocus = this->layout->GetFocus(); + + if (this->lastFocus) { + this->lastFocus->Blur(); + } + this->layout->SetFocus(IWindowPtr()); } diff --git a/src/musikcube/cursespp/LayoutBase.cpp b/src/musikcube/cursespp/LayoutBase.cpp index e767b840f..cc3c0fc56 100755 --- a/src/musikcube/cursespp/LayoutBase.cpp +++ b/src/musikcube/cursespp/LayoutBase.cpp @@ -67,9 +67,14 @@ bool sortByFocusOrder(IWindowPtr a, IWindowPtr b) { } static inline IWindowPtr adjustFocus(IWindowPtr oldFocus, IWindowPtr newFocus) { + if (oldFocus) { + oldFocus->Blur(); + } + if (newFocus) { newFocus->Focus(); } + return newFocus; } diff --git a/src/musikcube/cursespp/Window.cpp b/src/musikcube/cursespp/Window.cpp index 10c2e2461..7561a10a0 100755 --- a/src/musikcube/cursespp/Window.cpp +++ b/src/musikcube/cursespp/Window.cpp @@ -52,7 +52,6 @@ static int NEXT_ID = 0; static bool drawPending = false; static bool freeze = false; static Window* top = nullptr; -static Window* focused = nullptr; static MessageQueue messageQueue; static std::shared_ptr keys; @@ -148,12 +147,6 @@ Window::Window(IWindow *parent) { Window::~Window() { messageQueue.Remove(this); - if (::top == this) { - ::top = nullptr; - } - if (::focused == this) { - ::focused = nullptr; - } this->Destroy(); } @@ -814,10 +807,6 @@ bool Window::IsParentVisible() { void Window::Focus() { if (!this->isFocused) { - if (::focused && ::focused != this) { - ::focused->Blur(); - } - ::focused = this; this->isFocused = true; this->isDirty = true; this->OnFocusChanged(true); @@ -828,9 +817,6 @@ void Window::Focus() { void Window::Blur() { if (this->isFocused) { - if (::focused == this) { - ::focused = nullptr; - } this->isFocused = false; this->isDirty = true; this->OnFocusChanged(false);