summaryrefslogtreecommitdiff
path: root/src/managers/KeybindManager.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-04-23 01:28:20 +0100
committerVaxry <vaxry@vaxry.net>2024-04-23 01:49:23 +0100
commit29308b94ca2d95597b3c4e3ac1d3edbcd2f23cdd (patch)
treebc7c9b36fc4941f17c81625964e5110118695b10 /src/managers/KeybindManager.cpp
parent7778f01194d84fae18827fd338299dd7482ef7c5 (diff)
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.
Diffstat (limited to 'src/managers/KeybindManager.cpp')
-rw-r--r--src/managers/KeybindManager.cpp26
1 files changed, 25 insertions, 1 deletions
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 <regex>
+#include <tuple>
#include <sys/ioctl.h>
#include <fcntl.h>
@@ -17,6 +19,23 @@
#include <sys/consio.h>
#endif
+static std::vector<std::pair<std::string, std::string>> getHyprlandLaunchEnv() {
+ static auto PINITIALWSTRACKING = CConfigValue<Hyprlang::INT>("misc:initial_workspace_tracking");
+
+ if (!*PINITIALWSTRACKING)
+ return {};
+
+ const auto PMONITOR = g_pCompositor->m_pLastMonitor;
+ if (!PMONITOR || !PMONITOR->activeWorkspace)
+ return {};
+
+ std::vector<std::pair<std::string, std::string>> 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);