workspacerules: fix workspace rule loops (#5433)

This commit is contained in:
thejch 2024-04-05 08:54:30 -07:00 committed by GitHub
parent 942172d2dc
commit 1e8f57c734
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 68 additions and 91 deletions

View file

@ -1257,13 +1257,8 @@ void CCompositor::sanityCheckWorkspaces() {
auto it = m_vWorkspaces.begin(); auto it = m_vWorkspaces.begin();
while (it != m_vWorkspaces.end()) { while (it != m_vWorkspaces.end()) {
const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(*it); const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(*it);
bool isPersistent = false; if (WORKSPACERULE.isPersistent) {
for (auto& wsRule : WORKSPACERULES) {
if (wsRule.isPersistent)
isPersistent = true;
}
if (isPersistent) {
++it; ++it;
continue; continue;
} }
@ -1291,10 +1286,8 @@ void CCompositor::sanityCheckWorkspaces() {
continue; continue;
} }
if (!WORKSPACE->m_bOnCreatedEmptyExecuted) { if (!WORKSPACE->m_bOnCreatedEmptyExecuted) {
for (auto& wsRule : WORKSPACERULES) { if (auto cmd = WORKSPACERULE.onCreatedEmptyRunCmd)
if (auto cmd = wsRule.onCreatedEmptyRunCmd) g_pKeybindManager->spawn(*cmd);
g_pKeybindManager->spawn(*cmd);
}
WORKSPACE->m_bOnCreatedEmptyExecuted = true; WORKSPACE->m_bOnCreatedEmptyExecuted = true;
} }

View file

@ -965,13 +965,43 @@ SMonitorRule CConfigManager::getMonitorRuleFor(const CMonitor& PMONITOR) {
return SMonitorRule{.name = "", .resolution = Vector2D(0, 0), .offset = Vector2D(-INT32_MAX, -INT32_MAX), .scale = -1}; // 0, 0 is preferred and -1, -1 is auto return SMonitorRule{.name = "", .resolution = Vector2D(0, 0), .offset = Vector2D(-INT32_MAX, -INT32_MAX), .scale = -1}; // 0, 0 is preferred and -1, -1 is auto
} }
std::vector<SWorkspaceRule> CConfigManager::getWorkspaceRulesFor(PHLWORKSPACE pWorkspace) { SWorkspaceRule CConfigManager::getWorkspaceRuleFor(PHLWORKSPACE pWorkspace) {
std::vector<SWorkspaceRule> results; SWorkspaceRule mergedRule{};
for (auto& rule : m_dWorkspaceRules) { for (auto& rule : m_dWorkspaceRules) {
if (pWorkspace->matchesStaticSelector(rule.workspaceString)) if (!pWorkspace->matchesStaticSelector(rule.workspaceString))
results.push_back(rule); 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;
}
}
} }
return results;
return mergedRule;
} }
std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow, bool dynamic, bool shadowExec) { std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow, bool dynamic, bool shadowExec) {

View file

@ -105,7 +105,7 @@ class CConfigManager {
static std::string getMainConfigPath(); static std::string getMainConfigPath();
SMonitorRule getMonitorRuleFor(const CMonitor&); SMonitorRule getMonitorRuleFor(const CMonitor&);
std::vector<SWorkspaceRule> getWorkspaceRulesFor(PHLWORKSPACE workspace); SWorkspaceRule getWorkspaceRuleFor(PHLWORKSPACE workspace);
std::string getDefaultWorkspaceFor(const std::string&); std::string getDefaultWorkspaceFor(const std::string&);
CMonitor* getBoundMonitorForWS(const std::string&); CMonitor* getBoundMonitorForWS(const std::string&);

View file

@ -1088,33 +1088,20 @@ float CWindow::rounding() {
} }
void CWindow::updateSpecialRenderData() { void CWindow::updateSpecialRenderData() {
const auto PWORKSPACE = m_pWorkspace; const auto PWORKSPACE = m_pWorkspace;
const auto WORKSPACERULES = PWORKSPACE ? g_pConfigManager->getWorkspaceRulesFor(PWORKSPACE) : std::vector<SWorkspaceRule>{}; const auto WORKSPACERULE = PWORKSPACE ? g_pConfigManager->getWorkspaceRuleFor(PWORKSPACE) : SWorkspaceRule{};
bool border = true; bool border = true;
static auto PNOBORDERONFLOATING = CConfigValue<Hyprlang::INT>("general:no_border_on_floating"); static auto PNOBORDERONFLOATING = CConfigValue<Hyprlang::INT>("general:no_border_on_floating");
if (m_bIsFloating && *PNOBORDERONFLOATING == 1) if (m_bIsFloating && *PNOBORDERONFLOATING == 1)
border = false; border = false;
m_sSpecialRenderData.border = border; m_sSpecialRenderData.border = WORKSPACERULE.border.value_or(border);
m_sSpecialRenderData.borderSize = -1; m_sSpecialRenderData.borderSize = WORKSPACERULE.borderSize.value_or(-1);
m_sSpecialRenderData.decorate = true; m_sSpecialRenderData.decorate = WORKSPACERULE.decorate.value_or(true);
m_sSpecialRenderData.rounding = true; m_sSpecialRenderData.rounding = WORKSPACERULE.rounding.value_or(true);
m_sSpecialRenderData.shadow = true; m_sSpecialRenderData.shadow = WORKSPACERULE.shadow.value_or(true);
for (auto& wsRule : WORKSPACERULES) {
if (wsRule.border.has_value())
m_sSpecialRenderData.border = wsRule.border.value();
if (wsRule.borderSize.has_value())
m_sSpecialRenderData.borderSize = wsRule.borderSize.value();
if (wsRule.decorate.has_value())
m_sSpecialRenderData.decorate = wsRule.decorate.value();
if (wsRule.rounding.has_value())
m_sSpecialRenderData.rounding = wsRule.rounding.value();
if (wsRule.shadow.has_value())
m_sSpecialRenderData.shadow = wsRule.shadow.value();
}
} }
int CWindow::getRealBorderSize() { int CWindow::getRealBorderSize() {

View file

@ -28,11 +28,9 @@ void CWorkspace::init(PHLWORKSPACE self) {
m_vRenderOffset.registerVar(); m_vRenderOffset.registerVar();
m_fAlpha.registerVar(); m_fAlpha.registerVar();
const auto RULESFORTHIS = g_pConfigManager->getWorkspaceRulesFor(self); const auto RULEFORTHIS = g_pConfigManager->getWorkspaceRuleFor(self);
for (auto& rule : RULESFORTHIS) { if (RULEFORTHIS.defaultName.has_value())
if (rule.defaultName.has_value()) m_szName = RULEFORTHIS.defaultName.value();
m_szName = rule.defaultName.value();
}
m_pFocusedWindowHook = g_pHookSystem->hookDynamic("closeWindow", [this](void* self, SCallbackInfo& info, std::any param) { m_pFocusedWindowHook = g_pHookSystem->hookDynamic("closeWindow", [this](void* self, SCallbackInfo& info, std::any param) {
const auto PWINDOW = std::any_cast<CWindow*>(param); const auto PWINDOW = std::any_cast<CWindow*>(param);

View file

@ -128,7 +128,7 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for
const auto PWINDOW = pNode->pWindow; const auto PWINDOW = pNode->pWindow;
// get specific gaps and rules for this workspace, // get specific gaps and rules for this workspace,
// if user specified them in config // if user specified them in config
const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(g_pCompositor->getWorkspaceByID(pNode->workspaceID)); const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(pNode->workspaceID));
if (!g_pCompositor->windowExists(PWINDOW)) { if (!g_pCompositor->windowExists(PWINDOW)) {
Debug::log(ERR, "Node {} holding invalid {}!!", pNode, PWINDOW); Debug::log(ERR, "Node {} holding invalid {}!!", pNode, PWINDOW);
@ -147,16 +147,9 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for
auto* const PGAPSIN = (CCssGapData*)(PGAPSINDATA.ptr())->getData(); auto* const PGAPSIN = (CCssGapData*)(PGAPSINDATA.ptr())->getData();
auto* const PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData(); auto* const PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData();
auto gapsIn = *PGAPSIN; auto gapsIn = WORKSPACERULE.gapsIn.value_or(*PGAPSIN);
auto gapsOut = *PGAPSOUT; auto gapsOut = WORKSPACERULE.gapsOut.value_or(*PGAPSOUT);
for (auto& wsRule : WORKSPACERULES) { CBox nodeBox = pNode->box;
if (wsRule.gapsIn.has_value())
gapsIn = wsRule.gapsIn.value();
if (wsRule.gapsOut.has_value())
gapsOut = wsRule.gapsOut.value();
}
CBox nodeBox = pNode->box;
nodeBox.round(); nodeBox.round();
PWINDOW->m_vSize = nodeBox.size(); PWINDOW->m_vSize = nodeBox.size();
@ -167,17 +160,10 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for
if (*PNOGAPSWHENONLY && !PWINDOW->onSpecialWorkspace() && if (*PNOGAPSWHENONLY && !PWINDOW->onSpecialWorkspace() &&
(NODESONWORKSPACE == 1 || (PWINDOW->m_bIsFullscreen && PWINDOW->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { (NODESONWORKSPACE == 1 || (PWINDOW->m_bIsFullscreen && PWINDOW->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) {
PWINDOW->m_sSpecialRenderData.border = WORKSPACERULE.border.value_or(*PNOGAPSWHENONLY == 2);
PWINDOW->m_sSpecialRenderData.decorate = WORKSPACERULE.decorate.value_or(true);
PWINDOW->m_sSpecialRenderData.rounding = false; PWINDOW->m_sSpecialRenderData.rounding = false;
PWINDOW->m_sSpecialRenderData.shadow = false; PWINDOW->m_sSpecialRenderData.shadow = false;
PWINDOW->m_sSpecialRenderData.border = (*PNOGAPSWHENONLY == 2);
PWINDOW->m_sSpecialRenderData.decorate = true;
for (auto& wsRule : WORKSPACERULES) {
if (wsRule.border.has_value())
PWINDOW->m_sSpecialRenderData.border = wsRule.border.value();
if (wsRule.decorate.has_value())
PWINDOW->m_sSpecialRenderData.decorate = wsRule.decorate.value();
}
PWINDOW->updateWindowDecos(); PWINDOW->updateWindowDecos();

View file

@ -44,14 +44,12 @@ SMasterWorkspaceData* CHyprMasterLayout::getMasterWorkspaceData(const int& ws) {
const auto PWORKSPACEDATA = &m_lMasterWorkspacesData.emplace_back(); const auto PWORKSPACEDATA = &m_lMasterWorkspacesData.emplace_back();
PWORKSPACEDATA->workspaceID = ws; PWORKSPACEDATA->workspaceID = ws;
static auto PORIENTATION = CConfigValue<std::string>("master:orientation"); static auto PORIENTATION = CConfigValue<std::string>("master:orientation");
const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(g_pCompositor->getWorkspaceByID(ws)); const auto layoutoptsForWs = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(ws)).layoutopts;
std::string orientationForWs = *PORIENTATION; std::string orientationForWs = *PORIENTATION;
for (auto& wsRule : WORKSPACERULES) { if (layoutoptsForWs.contains("orientation"))
if (wsRule.layoutopts.contains("orientation")) orientationForWs = layoutoptsForWs.at("orientation");
orientationForWs = wsRule.layoutopts.at("orientation");
}
if (orientationForWs == "top") if (orientationForWs == "top")
PWORKSPACEDATA->orientation = ORIENTATION_TOP; PWORKSPACEDATA->orientation = ORIENTATION_TOP;
@ -334,13 +332,11 @@ void CHyprMasterLayout::calculateWorkspace(PHLWORKSPACE pWorkspace) {
return; return;
// dynamic workspace rules // dynamic workspace rules
const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(pWorkspace); const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(pWorkspace);
std::string orientationForWs; std::string orientationForWs;
for (auto& wsRule : WORKSPACERULES) { if (WORKSPACERULE.layoutopts.contains("orientation"))
if (wsRule.layoutopts.contains("orientation")) orientationForWs = WORKSPACERULE.layoutopts.at("orientation");
orientationForWs = wsRule.layoutopts.at("orientation");
}
if (orientationForWs == "top") if (orientationForWs == "top")
PWORKSPACEDATA->orientation = ORIENTATION_TOP; PWORKSPACEDATA->orientation = ORIENTATION_TOP;
@ -643,7 +639,7 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) {
const auto PWINDOW = pNode->pWindow; const auto PWINDOW = pNode->pWindow;
// get specific gaps and rules for this workspace, // get specific gaps and rules for this workspace,
// if user specified them in config // if user specified them in config
const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(PWINDOW->m_pWorkspace); const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(PWINDOW->m_pWorkspace);
if (PWINDOW->m_bIsFullscreen && !pNode->ignoreFullscreenChecks) if (PWINDOW->m_bIsFullscreen && !pNode->ignoreFullscreenChecks)
return; return;
@ -657,14 +653,8 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) {
auto* PGAPSIN = (CCssGapData*)(PGAPSINDATA.ptr())->getData(); auto* PGAPSIN = (CCssGapData*)(PGAPSINDATA.ptr())->getData();
auto* PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData(); auto* PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData();
auto gapsIn = *PGAPSIN; auto gapsIn = WORKSPACERULE.gapsIn.value_or(*PGAPSIN);
auto gapsOut = *PGAPSOUT; auto gapsOut = WORKSPACERULE.gapsOut.value_or(*PGAPSOUT);
for (auto& wsRule : WORKSPACERULES) {
if (wsRule.gapsIn.has_value())
gapsIn = wsRule.gapsIn.value();
if (wsRule.gapsOut.has_value())
gapsOut = wsRule.gapsOut.value();
}
if (!g_pCompositor->windowValidMapped(PWINDOW)) { if (!g_pCompositor->windowValidMapped(PWINDOW)) {
Debug::log(ERR, "Node {} holding invalid {}!!", pNode, PWINDOW); Debug::log(ERR, "Node {} holding invalid {}!!", pNode, PWINDOW);
@ -677,17 +667,10 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) {
if (*PNOGAPSWHENONLY && !PWINDOW->onSpecialWorkspace() && if (*PNOGAPSWHENONLY && !PWINDOW->onSpecialWorkspace() &&
(getNodesOnWorkspace(PWINDOW->workspaceID()) == 1 || (PWINDOW->m_bIsFullscreen && PWINDOW->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { (getNodesOnWorkspace(PWINDOW->workspaceID()) == 1 || (PWINDOW->m_bIsFullscreen && PWINDOW->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) {
PWINDOW->m_sSpecialRenderData.border = WORKSPACERULE.border.value_or(*PNOGAPSWHENONLY == 2);
PWINDOW->m_sSpecialRenderData.decorate = WORKSPACERULE.decorate.value_or(true);
PWINDOW->m_sSpecialRenderData.rounding = false; PWINDOW->m_sSpecialRenderData.rounding = false;
PWINDOW->m_sSpecialRenderData.shadow = false; PWINDOW->m_sSpecialRenderData.shadow = false;
PWINDOW->m_sSpecialRenderData.border = (*PNOGAPSWHENONLY == 2);
PWINDOW->m_sSpecialRenderData.decorate = true;
for (auto& wsRule : WORKSPACERULES) {
if (wsRule.border.has_value())
PWINDOW->m_sSpecialRenderData.border = wsRule.border.value();
if (wsRule.decorate.has_value())
PWINDOW->m_sSpecialRenderData.decorate = wsRule.decorate.value();
}
PWINDOW->updateWindowDecos(); PWINDOW->updateWindowDecos();