From 546cc71565cd2ccd9277febb14dcebf513ace623 Mon Sep 17 00:00:00 2001 From: shezdy <77217897+shezdy@users.noreply.github.com> Date: Thu, 30 Apr 2026 13:10:03 -0600 Subject: [PATCH] config/workspace-rules: support modifying persistent and monitor (#14217) * workspace rules: support modifying persistent and monitor * support modifying isDefault --- src/Compositor.cpp | 4 ++-- src/config/shared/workspace/WorkspaceRule.cpp | 10 +++++----- src/config/shared/workspace/WorkspaceRule.hpp | 4 ++-- src/config/shared/workspace/WorkspaceRuleManager.cpp | 2 +- src/debug/HyprCtl.cpp | 8 ++++---- src/desktop/Workspace.cpp | 6 +++--- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 14a7843ec..c64300279 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1699,7 +1699,7 @@ WORKSPACEID CCompositor::getNextAvailableNamedWorkspace() { // Give priority to persistent workspaces to avoid any conflicts between them. for (auto const& rule : Config::workspaceRuleMgr()->getAllWorkspaceRules()) { - if (!rule.m_isPersistent) + if (!rule.m_isPersistent.value_or(false)) continue; if (rule.m_workspaceId < -1 && rule.m_workspaceId < lowest) lowest = rule.m_workspaceId; @@ -3096,7 +3096,7 @@ void CCompositor::ensurePersistentWorkspacesPresent(const std::vector persistentFound; for (const auto& rule : rules) { - if (!rule.m_isPersistent) + if (!rule.m_isPersistent.value_or(false)) continue; PHLWORKSPACE PWORKSPACE = nullptr; diff --git a/src/config/shared/workspace/WorkspaceRule.cpp b/src/config/shared/workspace/WorkspaceRule.cpp index 28d5fcab7..dfd77d429 100644 --- a/src/config/shared/workspace/WorkspaceRule.cpp +++ b/src/config/shared/workspace/WorkspaceRule.cpp @@ -3,7 +3,7 @@ using namespace Config; void CWorkspaceRule::mergeLeft(const CWorkspaceRule& other) { - if (m_monitor.empty()) + if (!other.m_monitor.empty()) m_monitor = other.m_monitor; if (m_workspaceString.empty()) m_workspaceString = other.m_workspaceString; @@ -12,10 +12,10 @@ void CWorkspaceRule::mergeLeft(const CWorkspaceRule& other) { if (m_workspaceId == WORKSPACE_INVALID) m_workspaceId = other.m_workspaceId; - if (other.m_isDefault) - m_isDefault = true; - if (other.m_isPersistent) - m_isPersistent = true; + if (other.m_isDefault.has_value()) + m_isDefault = other.m_isDefault; + if (other.m_isPersistent.has_value()) + m_isPersistent = other.m_isPersistent; if (other.m_gapsIn.has_value()) m_gapsIn = other.m_gapsIn; if (other.m_gapsOut.has_value()) diff --git a/src/config/shared/workspace/WorkspaceRule.hpp b/src/config/shared/workspace/WorkspaceRule.hpp index 5d63e4349..e56a13663 100644 --- a/src/config/shared/workspace/WorkspaceRule.hpp +++ b/src/config/shared/workspace/WorkspaceRule.hpp @@ -27,8 +27,8 @@ namespace Config { std::string m_workspaceString = ""; std::string m_workspaceName = ""; WORKSPACEID m_workspaceId = -1; - bool m_isDefault = false; - bool m_isPersistent = false; + std::optional m_isDefault; + std::optional m_isPersistent; std::optional m_gapsIn; std::optional m_gapsOut; std::optional m_floatGaps = m_gapsOut; diff --git a/src/config/shared/workspace/WorkspaceRuleManager.cpp b/src/config/shared/workspace/WorkspaceRuleManager.cpp index 4c2c2b909..04b94a533 100644 --- a/src/config/shared/workspace/WorkspaceRuleManager.cpp +++ b/src/config/shared/workspace/WorkspaceRuleManager.cpp @@ -55,7 +55,7 @@ std::string CWorkspaceRuleManager::getDefaultWorkspaceFor(const std::string& nam if (!other->m_enabled) continue; - if (other->m_isDefault) { + if (other->m_isDefault.value_or(false)) { if (other->m_monitor == name) return other->m_workspaceString; if (other->m_monitor.starts_with("desc:")) { diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index b334a26e3..111714723 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -507,8 +507,8 @@ static std::string getWorkspaceRuleData(const Config::CWorkspaceRule& r, eHyprCt const auto boolToString = [](const bool b) -> std::string { return b ? "true" : "false"; }; if (format == eHyprCtlOutputFormat::FORMAT_JSON) { const std::string monitor = r.m_monitor.empty() ? "" : std::format(",\n \"monitor\": \"{}\"", escapeJSONStrings(r.m_monitor)); - const std::string default_ = sc(r.m_isDefault) ? std::format(",\n \"default\": {}", boolToString(r.m_isDefault)) : ""; - const std::string persistent = sc(r.m_isPersistent) ? std::format(",\n \"persistent\": {}", boolToString(r.m_isPersistent)) : ""; + const std::string default_ = sc(r.m_isDefault) ? std::format(",\n \"default\": {}", boolToString(r.m_isDefault.value())) : ""; + const std::string persistent = sc(r.m_isPersistent) ? std::format(",\n \"persistent\": {}", boolToString(r.m_isPersistent.value())) : ""; const std::string gapsIn = sc(r.m_gapsIn) ? std::format(",\n \"gapsIn\": [{}, {}, {}, {}]", r.m_gapsIn.value().m_top, r.m_gapsIn.value().m_right, r.m_gapsIn.value().m_bottom, r.m_gapsIn.value().m_left) : ""; @@ -531,8 +531,8 @@ static std::string getWorkspaceRuleData(const Config::CWorkspaceRule& r, eHyprCt return result; } else { const std::string monitor = std::format("\tmonitor: {}\n", r.m_monitor.empty() ? "" : escapeJSONStrings(r.m_monitor)); - const std::string default_ = std::format("\tdefault: {}\n", sc(r.m_isDefault) ? boolToString(r.m_isDefault) : ""); - const std::string persistent = std::format("\tpersistent: {}\n", sc(r.m_isPersistent) ? boolToString(r.m_isPersistent) : ""); + const std::string default_ = std::format("\tdefault: {}\n", sc(r.m_isDefault) ? boolToString(r.m_isDefault.value()) : ""); + const std::string persistent = std::format("\tpersistent: {}\n", sc(r.m_isPersistent) ? boolToString(r.m_isPersistent.value()) : ""); const std::string gapsIn = sc(r.m_gapsIn) ? std::format("\tgapsIn: {} {} {} {}\n", std::to_string(r.m_gapsIn.value().m_top), std::to_string(r.m_gapsIn.value().m_right), std::to_string(r.m_gapsIn.value().m_bottom), std::to_string(r.m_gapsIn.value().m_left)) : diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index 6d8e6cb49..60d8d9853 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -52,7 +52,7 @@ void CWorkspace::init(PHLWORKSPACE self) { m_inert = false; const auto WORKSPACERULE = Config::workspaceRuleMgr()->getWorkspaceRuleFor(self).value_or(Config::CWorkspaceRule{}); - setPersistent(WORKSPACERULE.m_isPersistent); + setPersistent(WORKSPACERULE.m_isPersistent.value_or(false)); if (self->m_wasCreatedEmpty) if (auto cmd = WORKSPACERULE.m_onCreatedEmptyRunCmd) @@ -517,9 +517,9 @@ void CWorkspace::rename(const std::string& name) { m_name = name; const auto WORKSPACERULE = Config::workspaceRuleMgr()->getWorkspaceRuleFor(m_self.lock()).value_or(Config::CWorkspaceRule{}); - setPersistent(WORKSPACERULE.m_isPersistent); + setPersistent(WORKSPACERULE.m_isPersistent.value_or(false)); - if (WORKSPACERULE.m_isPersistent) + if (WORKSPACERULE.m_isPersistent.value_or(false)) g_pCompositor->ensurePersistentWorkspacesPresent(std::vector{WORKSPACERULE}, m_self.lock()); g_pEventManager->postEvent({.event = "renameworkspace", .data = std::to_string(m_id) + "," + m_name});