From 608eff600d31879519aa64b795b45709ebfac267 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 24 Apr 2024 16:16:46 +0100 Subject: [PATCH] tokens: add more modes to initial_workspace_tracking 1 is single-shot, 2 is persistent fixes #5732 --- src/desktop/Window.cpp | 29 +++++++++++++++++++++++++++-- src/desktop/Window.hpp | 7 +++++++ src/events/Windows.cpp | 19 +++++++++++++++---- src/managers/KeybindManager.cpp | 5 +++-- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 8dcfc397..cebdad49 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -385,9 +385,20 @@ void CWindow::moveToWorkspace(PHLWORKSPACE pWorkspace) { if (m_pWorkspace == pWorkspace) return; + static auto PINITIALWSTRACKING = CConfigValue("misc:initial_workspace_tracking"); + if (!m_szInitialWorkspaceToken.empty()) { - g_pTokenManager->removeToken(g_pTokenManager->getToken(m_szInitialWorkspaceToken)); - m_szInitialWorkspaceToken = ""; + const auto TOKEN = g_pTokenManager->getToken(m_szInitialWorkspaceToken); + if (TOKEN) { + if (*PINITIALWSTRACKING == 2) { + // persistent + SInitialWorkspaceToken token = std::any_cast(TOKEN->data); + if (token.primaryOwner == this) { + token.workspace = pWorkspace->getConfigName(); + TOKEN->data = token; + } + } + } } static auto PCLOSEONLASTSPECIAL = CConfigValue("misc:close_special_on_empty"); @@ -468,6 +479,20 @@ void CWindow::onUnmap() { if (g_pInputManager->currentlyDraggedWindow == this) g_pInputManager->currentlyDraggedWindow = nullptr; + static auto PINITIALWSTRACKING = CConfigValue("misc:initial_workspace_tracking"); + + if (!m_szInitialWorkspaceToken.empty()) { + const auto TOKEN = g_pTokenManager->getToken(m_szInitialWorkspaceToken); + if (TOKEN) { + if (*PINITIALWSTRACKING == 2) { + // persistent token, but the first window got removed so the token is gone + SInitialWorkspaceToken token = std::any_cast(TOKEN->data); + if (token.primaryOwner == this) + g_pTokenManager->removeToken(TOKEN); + } + } + } + m_iLastWorkspace = m_pWorkspace->m_iID; m_vRealPosition.setCallbackOnEnd(unregisterVar); diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp index cc4d1757..7b298552 100644 --- a/src/desktop/Window.hpp +++ b/src/desktop/Window.hpp @@ -14,6 +14,8 @@ #include "DesktopTypes.hpp" #include "../helpers/signal/Signal.hpp" +class CWindow; + enum eIdleInhibitMode { IDLEINHIBIT_NONE = 0, IDLEINHIBIT_ALWAYS, @@ -188,6 +190,11 @@ struct SWindowRule { std::string szWorkspace = ""; // empty means any }; +struct SInitialWorkspaceToken { + CWindow* primaryOwner = nullptr; + std::string workspace; +}; + class CWindow { public: CWindow(); diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index b02d63a7..2d1e1384 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -81,14 +81,25 @@ void Events::listener_mapWindow(void* owner, void* data) { const auto TOKEN = g_pTokenManager->getToken(SZTOKEN); if (TOKEN) { // find workspace and use it - std::string WS = std::any_cast(TOKEN->data); + SInitialWorkspaceToken WS = std::any_cast(TOKEN->data); - Debug::log(LOG, "HL_INITIAL_WORKSPACE_TOKEN {} -> {}", SZTOKEN, WS); + Debug::log(LOG, "HL_INITIAL_WORKSPACE_TOKEN {} -> {}", SZTOKEN, WS.workspace); - if (g_pCompositor->getWorkspaceByString(WS) != PWINDOW->m_pWorkspace) { - requestedWorkspace = WS; + if (g_pCompositor->getWorkspaceByString(WS.workspace) != PWINDOW->m_pWorkspace) { + requestedWorkspace = WS.workspace; workspaceSilent = true; } + + if (*PINITIALWSTRACKING == 1) // one-shot token + g_pTokenManager->removeToken(TOKEN); + else if (*PINITIALWSTRACKING == 2) { // persistent + if (!WS.primaryOwner) { + WS.primaryOwner = PWINDOW; + TOKEN->data = WS; + } + + PWINDOW->m_szInitialWorkspaceToken = SZTOKEN; + } } } } diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 5a9fef8b..ad863274 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -33,8 +33,9 @@ static std::vector> getHyprlandLaunchEnv() { result.push_back(std::make_pair<>( "HL_INITIAL_WORKSPACE_TOKEN", - g_pTokenManager->registerNewToken(PMONITOR->activeSpecialWorkspace ? PMONITOR->activeSpecialWorkspace->getConfigName() : PMONITOR->activeWorkspace->getConfigName(), - std::chrono::minutes(2)))); + g_pTokenManager->registerNewToken( + SInitialWorkspaceToken{nullptr, PMONITOR->activeSpecialWorkspace ? PMONITOR->activeSpecialWorkspace->getConfigName() : PMONITOR->activeWorkspace->getConfigName()}, + std::chrono::months(1337)))); return result; }