Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply all the workspace rules for the same workspace selector #5656

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading