Skip to content

Commit

Permalink
config: merge all rules set for the same workspace selection (#5656)
Browse files Browse the repository at this point in the history
  • Loading branch information
thejch authored Apr 20, 2024
1 parent 1ebc32f commit 10caa03
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
64 changes: 35 additions & 29 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,39 +970,45 @@ SWorkspaceRule CConfigManager::getWorkspaceRuleFor(PHLWORKSPACE pWorkspace) {
if (!pWorkspace->matchesStaticSelector(rule.workspaceString))
continue;

if (rule.isDefault)
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()) {
for (const auto& layoutopt : rule.layoutopts) {
mergedRule.layoutopts[layoutopt.first] = layoutopt.second;
}
}
mergedRule = mergeWorkspaceRules(mergedRule, rule);
}

return mergedRule;
}

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;
}
}
return mergedRule;
}

std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow, bool dynamic, bool shadowExec) {
if (!g_pCompositor->windowExists(pWindow))
return std::vector<SWindowRule>();
Expand Down Expand Up @@ -2307,7 +2313,7 @@ std::optional<std::string> CConfigManager::handleWorkspaceRules(const std::strin
if (IT == m_dWorkspaceRules.end())
m_dWorkspaceRules.emplace_back(wsRule);
else
*IT = wsRule;
*IT = mergeWorkspaceRules(*IT, wsRule);

return {};
}
Expand Down
1 change: 1 addition & 0 deletions src/config/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class CConfigManager {
std::optional<std::string> verifyConfigExists();
void postConfigReload(const Hyprlang::CParseResult& result);
void reload();
SWorkspaceRule mergeWorkspaceRules(const SWorkspaceRule&, const SWorkspaceRule&);
};

inline std::unique_ptr<CConfigManager> g_pConfigManager;

0 comments on commit 10caa03

Please sign in to comment.