config/workspace-rules: support modifying persistent and monitor (#14217)

* workspace rules: support modifying persistent and monitor

* support modifying isDefault
This commit is contained in:
shezdy 2026-04-30 13:10:03 -06:00 committed by GitHub
parent bac49db9a1
commit 546cc71565
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 17 additions and 17 deletions

View file

@ -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<Config::CW
std::vector<PHLWORKSPACE> persistentFound;
for (const auto& rule : rules) {
if (!rule.m_isPersistent)
if (!rule.m_isPersistent.value_or(false))
continue;
PHLWORKSPACE PWORKSPACE = nullptr;

View file

@ -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())

View file

@ -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<bool> m_isDefault;
std::optional<bool> m_isPersistent;
std::optional<CCssGapData> m_gapsIn;
std::optional<CCssGapData> m_gapsOut;
std::optional<CCssGapData> m_floatGaps = m_gapsOut;

View file

@ -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:")) {

View file

@ -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<bool>(r.m_isDefault) ? std::format(",\n \"default\": {}", boolToString(r.m_isDefault)) : "";
const std::string persistent = sc<bool>(r.m_isPersistent) ? std::format(",\n \"persistent\": {}", boolToString(r.m_isPersistent)) : "";
const std::string default_ = sc<bool>(r.m_isDefault) ? std::format(",\n \"default\": {}", boolToString(r.m_isDefault.value())) : "";
const std::string persistent = sc<bool>(r.m_isPersistent) ? std::format(",\n \"persistent\": {}", boolToString(r.m_isPersistent.value())) : "";
const std::string gapsIn = sc<bool>(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() ? "<unset>" : escapeJSONStrings(r.m_monitor));
const std::string default_ = std::format("\tdefault: {}\n", sc<bool>(r.m_isDefault) ? boolToString(r.m_isDefault) : "<unset>");
const std::string persistent = std::format("\tpersistent: {}\n", sc<bool>(r.m_isPersistent) ? boolToString(r.m_isPersistent) : "<unset>");
const std::string default_ = std::format("\tdefault: {}\n", sc<bool>(r.m_isDefault) ? boolToString(r.m_isDefault.value()) : "<unset>");
const std::string persistent = std::format("\tpersistent: {}\n", sc<bool>(r.m_isPersistent) ? boolToString(r.m_isPersistent.value()) : "<unset>");
const std::string gapsIn = sc<bool>(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)) :

View file

@ -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<Config::CWorkspaceRule>{WORKSPACERULE}, m_self.lock());
g_pEventManager->postEvent({.event = "renameworkspace", .data = std::to_string(m_id) + "," + m_name});