config: merge all rules set for the same workspace selection (#5656)

This commit is contained in:
thejch 2024-04-19 18:20:16 -07:00 committed by GitHub
parent 1ebc32f5f4
commit 10caa03ce5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 29 deletions

View file

@ -970,36 +970,42 @@ SWorkspaceRule CConfigManager::getWorkspaceRuleFor(PHLWORKSPACE pWorkspace) {
if (!pWorkspace->matchesStaticSelector(rule.workspaceString)) if (!pWorkspace->matchesStaticSelector(rule.workspaceString))
continue; continue;
if (rule.isDefault) mergedRule = mergeWorkspaceRules(mergedRule, rule);
mergedRule.isDefault = true; }
if (rule.isPersistent)
mergedRule.isPersistent = true;
if (rule.gapsIn.has_value())
mergedRule.gapsIn = rule.gapsIn;
if (rule.gapsOut.has_value())
mergedRule.gapsOut = rule.gapsOut;
if (rule.borderSize.has_value())
mergedRule.borderSize = rule.borderSize;
if (rule.border.has_value())
mergedRule.border = rule.border;
if (rule.rounding.has_value())
mergedRule.rounding = rule.rounding;
if (rule.decorate.has_value())
mergedRule.decorate = rule.decorate;
if (rule.shadow.has_value())
mergedRule.shadow = rule.shadow;
if (rule.onCreatedEmptyRunCmd.has_value())
mergedRule.onCreatedEmptyRunCmd = rule.onCreatedEmptyRunCmd;
if (rule.defaultName.has_value())
mergedRule.defaultName = rule.defaultName;
if (!rule.layoutopts.empty()) { return mergedRule;
for (const auto& layoutopt : rule.layoutopts) { }
SWorkspaceRule CConfigManager::mergeWorkspaceRules(const SWorkspaceRule& rule1, const SWorkspaceRule& rule2) {
SWorkspaceRule mergedRule = rule1;
if (rule2.isDefault)
mergedRule.isDefault = true;
if (rule2.isPersistent)
mergedRule.isPersistent = true;
if (rule2.gapsIn.has_value())
mergedRule.gapsIn = rule2.gapsIn;
if (rule2.gapsOut.has_value())
mergedRule.gapsOut = rule2.gapsOut;
if (rule2.borderSize.has_value())
mergedRule.borderSize = rule2.borderSize;
if (rule2.border.has_value())
mergedRule.border = rule2.border;
if (rule2.rounding.has_value())
mergedRule.rounding = rule2.rounding;
if (rule2.decorate.has_value())
mergedRule.decorate = rule2.decorate;
if (rule2.shadow.has_value())
mergedRule.shadow = rule2.shadow;
if (rule2.onCreatedEmptyRunCmd.has_value())
mergedRule.onCreatedEmptyRunCmd = rule2.onCreatedEmptyRunCmd;
if (rule2.defaultName.has_value())
mergedRule.defaultName = rule2.defaultName;
if (!rule2.layoutopts.empty()) {
for (const auto& layoutopt : rule2.layoutopts) {
mergedRule.layoutopts[layoutopt.first] = layoutopt.second; mergedRule.layoutopts[layoutopt.first] = layoutopt.second;
} }
} }
}
return mergedRule; return mergedRule;
} }
@ -2307,7 +2313,7 @@ std::optional<std::string> CConfigManager::handleWorkspaceRules(const std::strin
if (IT == m_dWorkspaceRules.end()) if (IT == m_dWorkspaceRules.end())
m_dWorkspaceRules.emplace_back(wsRule); m_dWorkspaceRules.emplace_back(wsRule);
else else
*IT = wsRule; *IT = mergeWorkspaceRules(*IT, wsRule);
return {}; return {};
} }

View file

@ -205,6 +205,7 @@ class CConfigManager {
std::optional<std::string> verifyConfigExists(); std::optional<std::string> verifyConfigExists();
void postConfigReload(const Hyprlang::CParseResult& result); void postConfigReload(const Hyprlang::CParseResult& result);
void reload(); void reload();
SWorkspaceRule mergeWorkspaceRules(const SWorkspaceRule&, const SWorkspaceRule&);
}; };
inline std::unique_ptr<CConfigManager> g_pConfigManager; inline std::unique_ptr<CConfigManager> g_pConfigManager;