diff options
author | vaxerski <[email protected]> | 2023-08-02 13:21:38 +0200 |
---|---|---|
committer | vaxerski <[email protected]> | 2023-08-02 13:21:38 +0200 |
commit | 5c50fac907df3463492a019f01f84d547ab93650 (patch) | |
tree | 0426518b0549a46f9ad1b9d02445f4e513bc77cd | |
parent | 51cda87fe47efec25265b3b9f6bebf9a0882aa08 (diff) | |
download | Hyprland-5c50fac907df3463492a019f01f84d547ab93650.tar.gz Hyprland-5c50fac907df3463492a019f01f84d547ab93650.zip |
windowrules: add workspace param
-rw-r--r-- | src/Window.hpp | 4 | ||||
-rw-r--r-- | src/config/ConfigManager.cpp | 72 |
2 files changed, 48 insertions, 28 deletions
diff --git a/src/Window.hpp b/src/Window.hpp index 3ef33414..bdd079de 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -10,7 +10,8 @@ #include "helpers/Vector2D.hpp" #include "helpers/WLSurface.hpp" -enum eIdleInhibitMode { +enum eIdleInhibitMode +{ IDLEINHIBIT_NONE = 0, IDLEINHIBIT_ALWAYS, IDLEINHIBIT_FULLSCREEN, @@ -135,6 +136,7 @@ struct SWindowRule { int bFloating = -1; int bFullscreen = -1; int bPinned = -1; + std::string szWorkspace = ""; // empty means any }; class CWindow { diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index da34a15b..820e81af 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -964,9 +964,10 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s const auto FLOATPOS = VALUE.find("floating:"); const auto FULLSCREENPOS = VALUE.find("fullscreen:"); const auto PINNEDPOS = VALUE.find("pinned:"); + const auto WORKSPACEPOS = VALUE.find("workspace:"); if (TITLEPOS == std::string::npos && CLASSPOS == std::string::npos && X11POS == std::string::npos && FLOATPOS == std::string::npos && FULLSCREENPOS == std::string::npos && - PINNEDPOS == std::string::npos) { + PINNEDPOS == std::string::npos && WORKSPACEPOS == std::string::npos) { Debug::log(ERR, "Invalid rulev2 syntax: %s", VALUE.c_str()); parseError = "Invalid rulev2 syntax: " + VALUE; return; @@ -989,6 +990,8 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s min = FULLSCREENPOS; if (PINNEDPOS > pos && PINNEDPOS < min) min = PINNEDPOS; + if (WORKSPACEPOS > pos && WORKSPACEPOS < min) + min = PINNEDPOS; result = result.substr(0, min - pos); @@ -1000,58 +1003,52 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s return result; }; - if (CLASSPOS != std::string::npos) { + if (CLASSPOS != std::string::npos) rule.szClass = extract(CLASSPOS + 6); - } - if (TITLEPOS != std::string::npos) { + if (TITLEPOS != std::string::npos) rule.szTitle = extract(TITLEPOS + 6); - } - if (X11POS != std::string::npos) { + if (X11POS != std::string::npos) rule.bX11 = extract(X11POS + 9) == "1" ? 1 : 0; - } - if (FLOATPOS != std::string::npos) { + if (FLOATPOS != std::string::npos) rule.bFloating = extract(FLOATPOS + 9) == "1" ? 1 : 0; - } - if (FULLSCREENPOS != std::string::npos) { + if (FULLSCREENPOS != std::string::npos) rule.bFullscreen = extract(FULLSCREENPOS + 11) == "1" ? 1 : 0; - } - if (PINNEDPOS != std::string::npos) { + if (PINNEDPOS != std::string::npos) rule.bPinned = extract(PINNEDPOS + 7) == "1" ? 1 : 0; - } + + if (WORKSPACEPOS != std::string::npos) + rule.szWorkspace = extract(WORKSPACEPOS + 10); if (RULE == "unset") { std::erase_if(m_dWindowRules, [&](const SWindowRule& other) { if (!other.v2) { return other.szClass == rule.szClass && !rule.szClass.empty(); } else { - if (!rule.szClass.empty() && rule.szClass != other.szClass) { + if (!rule.szClass.empty() && rule.szClass != other.szClass) return false; - } - if (!rule.szTitle.empty() && rule.szTitle != other.szTitle) { + if (!rule.szTitle.empty() && rule.szTitle != other.szTitle) return false; - } - if (rule.bX11 != -1 && rule.bX11 != other.bX11) { + if (rule.bX11 != -1 && rule.bX11 != other.bX11) return false; - } - if (rule.bFloating != -1 && rule.bFloating != other.bFloating) { + if (rule.bFloating != -1 && rule.bFloating != other.bFloating) return false; - } - if (rule.bFullscreen != -1 && rule.bFullscreen != other.bFullscreen) { + if (rule.bFullscreen != -1 && rule.bFullscreen != other.bFullscreen) return false; - } - if (rule.bPinned != -1 && rule.bPinned != other.bPinned) { + if (rule.bPinned != -1 && rule.bPinned != other.bPinned) + return false; + + if (!rule.szWorkspace.empty() && rule.szWorkspace != other.szWorkspace) return false; - } return true; } @@ -1847,8 +1844,29 @@ std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow) { if (pWindow->m_bPinned != rule.bPinned) continue; } - } catch (...) { - Debug::log(ERR, "Regex error at %s", rule.szValue.c_str()); + + if (!rule.szWorkspace.empty()) { + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + + if (!PWORKSPACE) + continue; + + if (rule.szWorkspace.find("name:") == 0) { + if (PWORKSPACE->m_szName != rule.szWorkspace.substr(5)) + continue; + } else { + // number + if (!isNumber(rule.szWorkspace)) + throw std::runtime_error("szWorkspace not name: or number"); + + const int64_t ID = std::stoll(rule.szWorkspace); + + if (PWORKSPACE->m_iID != ID) + continue; + } + } + } catch (std::exception& e) { + Debug::log(ERR, "Regex error at %s (%s)", rule.szValue.c_str(), e.what()); continue; } } |