From 901236a5356a3f249af7d55e5db69889e50256b8 Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Fri, 11 Aug 2023 14:54:16 +0000 Subject: [PATCH] rules: center window improvements (#2935) * center window improvements modified: src/config/ConfigManager.cpp modified: src/events/Windows.cpp modified: src/managers/KeybindManager.cpp * remove redundant line modified: src/events/Windows.cpp * simplify code modified: src/events/Windows.cpp modified: src/managers/KeybindManager.cpp --- src/config/ConfigManager.cpp | 20 +++++++++++++------- src/events/Windows.cpp | 9 +++++++-- src/managers/KeybindManager.cpp | 6 +++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 0723ad24..cf2f8ed6 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -885,11 +885,11 @@ void CConfigManager::handleUnbind(const std::string& command, const std::string& bool windowRuleValid(const std::string& RULE) { return !(RULE != "float" && RULE != "tile" && RULE.find("opacity") != 0 && RULE.find("move") != 0 && RULE.find("size") != 0 && RULE.find("minsize") != 0 && RULE.find("maxsize") != 0 && RULE.find("pseudo") != 0 && RULE.find("monitor") != 0 && RULE.find("idleinhibit") != 0 && RULE != "nofocus" && RULE != "noblur" && - RULE != "noshadow" && RULE != "nodim" && RULE != "noborder" && RULE != "center" && RULE != "opaque" && RULE != "forceinput" && RULE != "fullscreen" && - RULE != "nofullscreenrequest" && RULE != "nomaximizerequest" && RULE != "fakefullscreen" && RULE != "nomaxsize" && RULE != "pin" && RULE != "noanim" && - RULE != "dimaround" && RULE != "windowdance" && RULE != "maximize" && RULE != "keepaspectratio" && RULE.find("animation") != 0 && RULE.find("rounding") != 0 && - RULE.find("workspace") != 0 && RULE.find("bordercolor") != 0 && RULE != "forcergbx" && RULE != "noinitialfocus" && RULE != "stayfocused" && - RULE.find("bordersize") != 0 && RULE.find("xray") != 0); + RULE != "noshadow" && RULE != "nodim" && RULE != "noborder" && RULE != "opaque" && RULE != "forceinput" && RULE != "fullscreen" && RULE != "nofullscreenrequest" && + RULE != "nomaximizerequest" && RULE != "fakefullscreen" && RULE != "nomaxsize" && RULE != "pin" && RULE != "noanim" && RULE != "dimaround" && RULE != "windowdance" && + RULE != "maximize" && RULE != "keepaspectratio" && RULE.find("animation") != 0 && RULE.find("rounding") != 0 && RULE.find("workspace") != 0 && + RULE.find("bordercolor") != 0 && RULE != "forcergbx" && RULE != "noinitialfocus" && RULE != "stayfocused" && RULE.find("bordersize") != 0 && RULE.find("xray") != 0 && + RULE.find("center") != 0); } bool layerRuleValid(const std::string& RULE) { @@ -917,7 +917,10 @@ void CConfigManager::handleWindowRule(const std::string& command, const std::str return; } - m_dWindowRules.push_back({RULE, VALUE}); + if (RULE.find("size") == 0 || RULE.find("maxsize") == 0 || RULE.find("minsize") == 0) + m_dWindowRules.push_front({RULE, VALUE}); + else + m_dWindowRules.push_back({RULE, VALUE}); } void CConfigManager::handleLayerRule(const std::string& command, const std::string& value) { @@ -1061,7 +1064,10 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s return; } - m_dWindowRules.push_back(rule); + if (RULE.find("size") == 0 || RULE.find("maxsize") == 0 || RULE.find("minsize") == 0) + m_dWindowRules.push_front(rule); + else + m_dWindowRules.push_back(rule); } void CConfigManager::updateBlurredLS(const std::string& name, const bool forceBlur) { diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index e79f1e74..a45aa91e 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -412,8 +412,13 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->setHidden(false); } catch (...) { Debug::log(LOG, "Rule move failed, rule: %s -> %s", r.szRule.c_str(), r.szValue.c_str()); } - } else if (r.szRule == "center") { - PWINDOW->m_vRealPosition = PMONITOR->vecPosition + PMONITOR->vecSize / 2.f - PWINDOW->m_vRealSize.goalv() / 2.f; + } else if (r.szRule.find("center") == 0) { + auto RESERVEDOFFSET = Vector2D(); + const auto ARGS = CVarList(r.szRule, 2, ' '); + if (ARGS[1] == "1") + RESERVEDOFFSET = (PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight) / 2.f; + + PWINDOW->m_vRealPosition = PMONITOR->vecPosition + PMONITOR->vecSize / 2.f - PWINDOW->m_vRealSize.goalv() / 2.f + RESERVEDOFFSET; } } diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 9cdf05d0..f54e1e5f 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -720,7 +720,11 @@ void CKeybindManager::centerWindow(std::string args) { const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); - PWINDOW->m_vRealPosition = PMONITOR->vecPosition + PMONITOR->vecSize / 2.f - PWINDOW->m_vRealSize.goalv() / 2.f; + auto RESERVEDOFFSET = Vector2D(); + if (args == "1") + RESERVEDOFFSET = (PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight) / 2.f; + + PWINDOW->m_vRealPosition = PMONITOR->vecPosition + PMONITOR->vecSize / 2.f - PWINDOW->m_vRealSize.goalv() / 2.f + RESERVEDOFFSET; PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.goalv(); }