From 29308b94ca2d95597b3c4e3ac1d3edbcd2f23cdd Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 23 Apr 2024 01:28:20 +0100 Subject: windows: add misc:initial_workspace_tracking By default enabled, will track the initial opened workspace of a window spawned for 2 minutes or until it's moved to a different workspace. For example: you run a launcher and open an app on workspace 1, but quickly switch to workspace 2. The app will now open on workspace 1 regardless of your switch. --- src/managers/KeybindManager.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 34e2f85b..040ae245 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -3,8 +3,10 @@ #include "debug/Log.hpp" #include "helpers/VarList.hpp" #include "../config/ConfigValue.hpp" +#include "TokenManager.hpp" #include +#include #include #include @@ -17,6 +19,23 @@ #include #endif +static std::vector> getHyprlandLaunchEnv() { + static auto PINITIALWSTRACKING = CConfigValue("misc:initial_workspace_tracking"); + + if (!*PINITIALWSTRACKING) + return {}; + + const auto PMONITOR = g_pCompositor->m_pLastMonitor; + if (!PMONITOR || !PMONITOR->activeWorkspace) + return {}; + + std::vector> result; + + result.push_back(std::make_pair<>("HL_INITIAL_WORKSPACE_TOKEN", g_pTokenManager->registerNewToken(PMONITOR->activeWorkspace->getConfigName(), std::chrono::minutes(2)))); + + return result; +} + CKeybindManager::CKeybindManager() { // initialize all dispatchers @@ -774,7 +793,9 @@ void CKeybindManager::spawn(std::string args) { uint64_t CKeybindManager::spawnRaw(std::string args) { Debug::log(LOG, "Executing {}", args); - int socket[2]; + const auto HLENV = getHyprlandLaunchEnv(); + + int socket[2]; if (pipe(socket) != 0) { Debug::log(LOG, "Unable to create pipe for fork"); } @@ -797,6 +818,9 @@ uint64_t CKeybindManager::spawnRaw(std::string args) { grandchild = fork(); if (grandchild == 0) { // run in grandchild + for (auto& e : HLENV) { + setenv(e.first.c_str(), e.second.c_str(), 1); + } close(socket[0]); close(socket[1]); execl("/bin/sh", "/bin/sh", "-c", args.c_str(), nullptr); -- cgit v1.2.3