diff options
| author | Vaxry <vaxry@vaxry.net> | 2024-04-23 01:28:20 +0100 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2024-04-23 01:49:23 +0100 |
| commit | 29308b94ca2d95597b3c4e3ac1d3edbcd2f23cdd (patch) | |
| tree | bc7c9b36fc4941f17c81625964e5110118695b10 /src/desktop/Window.cpp | |
| parent | 7778f01194d84fae18827fd338299dd7482ef7c5 (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/desktop/Window.cpp')
| -rw-r--r-- | src/desktop/Window.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 5310ecae..29a41976 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -5,6 +5,7 @@ #include "../render/decorations/CHyprBorderDecoration.hpp" #include "../config/ConfigValue.hpp" #include <any> +#include "../managers/TokenManager.hpp" CWindow::CWindow() { m_vRealPosition.create(g_pConfigManager->getAnimationPropertyConfig("windowsIn"), this, AVARDAMAGE_ENTIRE); @@ -384,6 +385,11 @@ void CWindow::moveToWorkspace(PHLWORKSPACE pWorkspace) { if (m_pWorkspace == pWorkspace) return; + if (!m_szInitialWorkspaceToken.empty()) { + g_pTokenManager->removeToken(g_pTokenManager->getToken(m_szInitialWorkspaceToken)); + m_szInitialWorkspaceToken = ""; + } + static auto PCLOSEONLASTSPECIAL = CConfigValue<Hyprlang::INT>("misc:close_special_on_empty"); const auto OLDWORKSPACE = m_pWorkspace; @@ -1241,3 +1247,42 @@ int CWindow::workspaceID() { bool CWindow::onSpecialWorkspace() { return m_pWorkspace ? m_pWorkspace->m_bIsSpecialWorkspace : g_pCompositor->isWorkspaceSpecial(m_iLastWorkspace); } + +std::unordered_map<std::string, std::string> CWindow::getEnv() { + + const auto PID = getPID(); + + if (PID <= 1) + return {}; + + std::unordered_map<std::string, std::string> results; + + // + std::string environFile = "/proc/" + std::to_string(PID) + "/environ"; + std::ifstream ifs(environFile, std::ios::binary); + + if (!ifs.good()) + return {}; + + std::vector<char> buffer; + size_t needle = 0; + buffer.resize(512, '\0'); + while (ifs.read(buffer.data() + needle, 512)) { + buffer.resize(buffer.size() + 512, '\0'); + needle += 512; + } + + std::replace(buffer.begin(), buffer.end() - 1, '\0', '\n'); + + CVarList envs(std::string{buffer.data(), needle - 1}, 0, '\n', true); + + for (auto& e : envs) { + if (!e.contains('=')) + continue; + + const auto EQ = e.find_first_of('='); + results[e.substr(0, EQ)] = e.substr(EQ + 1); + } + + return results; +} |
