diff --git a/src/Compositor.cpp b/src/Compositor.cpp index e55504615..9c806fdd5 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1455,7 +1455,7 @@ PHLWINDOW CCompositor::getWindowInDirection(const CBox& box, PHLWORKSPACE pWorks // get idx int windowIDX = -1; const auto& HISTORY = Desktop::History::windowTracker()->fullHistory(); - for (int64_t i = HISTORY.size() - 1; i > 0; --i) { + for (int64_t i = HISTORY.size() - 1; i >= 0; --i) { if (HISTORY[i] == w) { windowIDX = i; break; diff --git a/src/desktop/history/WindowHistoryTracker.cpp b/src/desktop/history/WindowHistoryTracker.cpp index 4ef5323f1..5dc0742f8 100644 --- a/src/desktop/history/WindowHistoryTracker.cpp +++ b/src/desktop/history/WindowHistoryTracker.cpp @@ -12,7 +12,14 @@ SP History::windowTracker() { } CWindowHistoryTracker::CWindowHistoryTracker() { - static auto P = g_pHookSystem->hookDynamic("activeWindow", [this](void* self, SCallbackInfo& info, std::any data) { + static auto P = g_pHookSystem->hookDynamic("openWindowEarly", [this](void* self, SCallbackInfo& info, std::any data) { + auto window = std::any_cast(data); + + // add a last track + m_history.insert(m_history.begin(), window); + }); + + static auto P1 = g_pHookSystem->hookDynamic("activeWindow", [this](void* self, SCallbackInfo& info, std::any data) { auto window = std::any_cast(data); track(window);