From 2e5b146e57364795aabeb2dea6fd2257db8b2c3a Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 2 Apr 2024 12:10:03 +0100 Subject: [PATCH] workspace: remove lastFocusedWindow on unmap --- src/desktop/Workspace.cpp | 9 +++++++++ src/desktop/Workspace.hpp | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index a0c14bba..9200b4d7 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -30,6 +30,13 @@ CWorkspace::CWorkspace(int id, int monitorID, std::string name, bool special) { m_szName = rule.defaultName.value(); } + m_pFocusedWindowHook = g_pHookSystem->hookDynamic("closeWindow", [this](void* self, SCallbackInfo& info, std::any param) { + const auto PWINDOW = std::any_cast(param); + + if (PWINDOW == m_pLastFocusedWindow) + m_pLastFocusedWindow = nullptr; + }); + g_pEventManager->postEvent({"createworkspace", m_szName}); g_pEventManager->postEvent({"createworkspacev2", std::format("{},{}", m_iID, m_szName)}); EMIT_HOOK_EVENT("createWorkspace", this); @@ -40,6 +47,8 @@ CWorkspace::~CWorkspace() { Debug::log(LOG, "Destroying workspace ID {}", m_iID); + g_pHookSystem->unhook(m_pFocusedWindowHook); + g_pEventManager->postEvent({"destroyworkspace", m_szName}); g_pEventManager->postEvent({"destroyworkspacev2", std::format("{},{}", m_iID, m_szName)}); EMIT_HOOK_EVENT("destroyWorkspace", this); diff --git a/src/desktop/Workspace.hpp b/src/desktop/Workspace.hpp index f1bdb333..0cae1859 100644 --- a/src/desktop/Workspace.hpp +++ b/src/desktop/Workspace.hpp @@ -66,4 +66,7 @@ class CWorkspace { std::string getConfigName(); bool matchesStaticSelector(const std::string& selector); + + private: + HOOK_CALLBACK_FN* m_pFocusedWindowHook = nullptr; };