From b80b64cd6c913f8c8ac820a1e4ca615a62ff958f Mon Sep 17 00:00:00 2001 From: nyx Date: Fri, 7 Mar 2025 20:12:02 -0500 Subject: windowrules: add option to allow size persistence between app launches (#9422) --- src/desktop/Window.cpp | 9 +++++++++ src/desktop/Window.hpp | 2 ++ src/desktop/WindowRule.cpp | 4 +++- src/desktop/WindowRule.hpp | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src/desktop') diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index ceb5eb18..b7a3f8f6 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -791,6 +791,10 @@ void CWindow::applyDynamicRule(const SP& r) { } break; } + case CWindowRule::RULE_PERSISTENTSIZE: { + m_sWindowData.persistentSize = CWindowOverridableVar(true, PRIORITY_WINDOW_RULE); + break; + } default: break; } } @@ -1323,6 +1327,11 @@ void CWindow::clampWindowSize(const std::optional minSize, const std:: *m_vRealPosition = m_vRealPosition->goal() + DELTA / 2.0; *m_vRealSize = NEWSIZE; + + if (m_bIsFloating && !m_bIsX11 && std::any_of(m_vMatchedRules.begin(), m_vMatchedRules.end(), [](const auto& r) { return r->ruleType == CWindowRule::RULE_PERSISTENTSIZE; })) { + Debug::log(LOG, "clamped window {}::{} to {}x{} (persistentsize)", m_szClass, m_szTitle, m_vRealSize->value().x, m_vRealSize->value().y); + g_pConfigManager->storeFloatingSize(m_pSelf.lock(), m_vRealSize->value()); + } } bool CWindow::isFullscreen() { diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp index ec3c0b21..3ed4ce75 100644 --- a/src/desktop/Window.hpp +++ b/src/desktop/Window.hpp @@ -198,6 +198,8 @@ struct SWindowData { CWindowOverridableVar activeBorderColor; CWindowOverridableVar inactiveBorderColor; + + CWindowOverridableVar persistentSize; }; struct SInitialWorkspaceToken { diff --git a/src/desktop/WindowRule.cpp b/src/desktop/WindowRule.cpp index cf3004b0..23269085 100644 --- a/src/desktop/WindowRule.cpp +++ b/src/desktop/WindowRule.cpp @@ -5,7 +5,7 @@ #include "../config/ConfigManager.hpp" static const auto RULES = std::unordered_set{ - "float", "fullscreen", "maximize", "noinitialfocus", "pin", "stayfocused", "tile", "renderunfocused", + "float", "fullscreen", "maximize", "noinitialfocus", "pin", "stayfocused", "tile", "renderunfocused", "persistentsize", }; static const auto RULES_PREFIX = std::unordered_set{ "animation", "bordercolor", "bordersize", "center", "content", "fullscreenstate", "group", "idleinhibit", "maxsize", "minsize", @@ -39,6 +39,8 @@ CWindowRule::CWindowRule(const std::string& rule, const std::string& value, bool ruleType = RULE_TILE; else if (rule == "renderunfocused") ruleType = RULE_RENDERUNFOCUSED; + else if (rule == "persistentsize") + ruleType = RULE_PERSISTENTSIZE; else if (rule.starts_with("animation")) ruleType = RULE_ANIMATION; else if (rule.starts_with("bordercolor")) diff --git a/src/desktop/WindowRule.hpp b/src/desktop/WindowRule.hpp index 50e221f3..192d8aa7 100644 --- a/src/desktop/WindowRule.hpp +++ b/src/desktop/WindowRule.hpp @@ -37,6 +37,7 @@ class CWindowRule { RULE_WORKSPACE, RULE_PROP, RULE_CONTENT, + RULE_PERSISTENTSIZE, }; eRuleType ruleType = RULE_INVALID; -- cgit v1.2.3