From 11a0d566a9893f0ac754b18403d8bee30b385dac Mon Sep 17 00:00:00 2001 From: yuukibarns Date: Tue, 29 Apr 2025 23:23:52 +0800 Subject: [PATCH 1/6] fix(window): use stored size for new floating window when persistentsize is set. fix hyprwm#9422. --- src/layout/IHyprLayout.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index ac04157b852..d166c289d64 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -888,6 +888,18 @@ void IHyprLayout::requestFocusForWindow(PHLWINDOW pWindow) { Vector2D IHyprLayout::predictSizeForNewWindowFloating(PHLWINDOW pWindow) { // get all rules, see if we have any size overrides. Vector2D sizeOverride = {}; if (g_pCompositor->m_lastMonitor) { + + // If `persistentsize` is set, use the stored size if available. + const bool HASPERSISTENTSIZE = + std::any_of(pWindow->m_matchedRules.begin(), pWindow->m_matchedRules.end(), [](const auto& rule) { return rule->m_ruleType == CWindowRule::RULE_PERSISTENTSIZE; }); + + const auto STOREDSIZE = HASPERSISTENTSIZE ? g_pConfigManager->getStoredFloatingSize(pWindow) : std::nullopt; + + if (STOREDSIZE.has_value()) { + Debug::log(LOG, "using stored size {}x{} for new floating window {}::{}", STOREDSIZE->x, STOREDSIZE->y, pWindow->m_class, pWindow->m_title); + return STOREDSIZE.value(); + } + for (auto const& r : g_pConfigManager->getMatchingRules(pWindow, true, true)) { if (r->m_ruleType != CWindowRule::RULE_SIZE) continue; From 614f2ad5618155e445baf7a9563e8efaddff9522 Mon Sep 17 00:00:00 2001 From: yuukibarns Date: Wed, 30 Apr 2025 13:57:55 +0800 Subject: [PATCH 2/6] fix: replace `std::any_of` with `std::ranges:any_of` --- src/layout/IHyprLayout.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index d166c289d64..ca1b3a6ecd6 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -17,8 +17,7 @@ void IHyprLayout::onWindowCreated(PHLWINDOW pWindow, eDirection direction) { CBox desiredGeometry = g_pXWaylandManager->getGeometryForWindow(pWindow); - const bool HASPERSISTENTSIZE = - std::any_of(pWindow->m_matchedRules.begin(), pWindow->m_matchedRules.end(), [](const auto& rule) { return rule->m_ruleType == CWindowRule::RULE_PERSISTENTSIZE; }); + const bool HASPERSISTENTSIZE = std::ranges::any_of(pWindow->m_matchedRules, [](const auto& rule) { return rule->m_ruleType == CWindowRule::RULE_PERSISTENTSIZE; }); const auto STOREDSIZE = HASPERSISTENTSIZE ? g_pConfigManager->getStoredFloatingSize(pWindow) : std::nullopt; @@ -890,8 +889,7 @@ Vector2D IHyprLayout::predictSizeForNewWindowFloating(PHLWINDOW pWindow) { // ge if (g_pCompositor->m_lastMonitor) { // If `persistentsize` is set, use the stored size if available. - const bool HASPERSISTENTSIZE = - std::any_of(pWindow->m_matchedRules.begin(), pWindow->m_matchedRules.end(), [](const auto& rule) { return rule->m_ruleType == CWindowRule::RULE_PERSISTENTSIZE; }); + const bool HASPERSISTENTSIZE = std::ranges::any_of(pWindow->m_matchedRules, [](const auto& rule) { return rule->m_ruleType == CWindowRule::RULE_PERSISTENTSIZE; }); const auto STOREDSIZE = HASPERSISTENTSIZE ? g_pConfigManager->getStoredFloatingSize(pWindow) : std::nullopt; From b28fd1ac23b7cb0c016caf4a7dd9263d613be074 Mon Sep 17 00:00:00 2001 From: yuukibarns Date: Wed, 30 Apr 2025 14:31:41 +0800 Subject: [PATCH 3/6] fix: use initialClass and initialTitle when storing sizes on close --- src/config/ConfigManager.cpp | 11 ++++++++--- src/config/ConfigManager.hpp | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 26b14dda6dd..652dacc4786 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -3051,13 +3051,18 @@ void CConfigManager::ensurePersistentWorkspacesPresent() { } void CConfigManager::storeFloatingSize(PHLWINDOW window, const Vector2D& size) { - Debug::log(LOG, "storing floating size {}x{} for window {}::{}", size.x, size.y, window->m_class, window->m_title); - SFloatCache id{window}; + Debug::log(LOG, "storing floating size {}x{} for window {}::{}", size.x, size.y, window->m_initialClass, window->m_initialTitle); + // true -> use m_initialClass and m_initialTitle + SFloatCache id{window, true}; m_mStoredFloatingSizes[id] = size; } std::optional CConfigManager::getStoredFloatingSize(PHLWINDOW window) { - SFloatCache id{window}; + // At startup, m_initialClass and m_initialTitle are undefined + // and m_class and m_title are just "initial" ones. + // false -> use m_class and m_title + SFloatCache id{window, false}; + Debug::log(LOG, "Hash for window {}::{} = {}", window->m_class, window->m_title, id.hash); if (m_mStoredFloatingSizes.contains(id)) { Debug::log(LOG, "got stored size {}x{} for window {}::{}", m_mStoredFloatingSizes[id].x, m_mStoredFloatingSizes[id].y, window->m_class, window->m_title); return m_mStoredFloatingSizes[id]; diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index eca2bb2808c..374f6302ea6 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -141,8 +141,11 @@ struct SFirstExecRequest { struct SFloatCache { size_t hash; - SFloatCache(PHLWINDOW window) { - hash = std::hash{}(window->m_class) ^ (std::hash{}(window->m_title) << 1); + SFloatCache(PHLWINDOW window, bool initial) { + if (initial) + hash = std::hash{}(window->m_initialClass) ^ (std::hash{}(window->m_initialTitle) << 1); + else + hash = std::hash{}(window->m_class) ^ (std::hash{}(window->m_title) << 1); } bool operator==(const SFloatCache& other) const { From 4dc30eb60fc94a4f44f82fae018e4295dfc4ac62 Mon Sep 17 00:00:00 2001 From: yuukibarns Date: Thu, 1 May 2025 11:15:19 +0800 Subject: [PATCH 4/6] fix: add `xdgTag` as a new indicator --- src/config/ConfigManager.hpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 374f6302ea6..e5c706b1f85 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -142,10 +142,18 @@ struct SFloatCache { size_t hash; SFloatCache(PHLWINDOW window, bool initial) { - if (initial) - hash = std::hash{}(window->m_initialClass) ^ (std::hash{}(window->m_initialTitle) << 1); - else - hash = std::hash{}(window->m_class) ^ (std::hash{}(window->m_title) << 1); + // Base hash from class/title + size_t baseHash = initial ? (std::hash{}(window->m_initialClass) ^ (std::hash{}(window->m_initialTitle) << 1)) : + (std::hash{}(window->m_class) ^ (std::hash{}(window->m_title) << 1)); + + // Use empty string as default tag value + std::string tagValue = ""; + if (auto xdgTag = window->xdgTag()) { + tagValue = xdgTag.value(); + } + + // Combine hashes + hash = baseHash ^ (std::hash{}(tagValue) << 2); } bool operator==(const SFloatCache& other) const { From f2bbc08c2b77d89b89145db38b1c8e08129a2ff8 Mon Sep 17 00:00:00 2001 From: yuukibarns Date: Fri, 2 May 2025 23:29:51 +0800 Subject: [PATCH 5/6] fix: no {} --- src/config/ConfigManager.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index e5c706b1f85..5cb95bacdde 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -148,9 +148,8 @@ struct SFloatCache { // Use empty string as default tag value std::string tagValue = ""; - if (auto xdgTag = window->xdgTag()) { + if (auto xdgTag = window->xdgTag()) tagValue = xdgTag.value(); - } // Combine hashes hash = baseHash ^ (std::hash{}(tagValue) << 2); From 33eb24824d449ae6751da8f46d01cfc5caa44222 Mon Sep 17 00:00:00 2001 From: yuukibarns Date: Mon, 5 May 2025 10:00:37 +0800 Subject: [PATCH 6/6] fix: format with clang-format --- src/config/ConfigManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 652dacc4786..709f9936987 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -3058,7 +3058,7 @@ void CConfigManager::storeFloatingSize(PHLWINDOW window, const Vector2D& size) { } std::optional CConfigManager::getStoredFloatingSize(PHLWINDOW window) { - // At startup, m_initialClass and m_initialTitle are undefined + // At startup, m_initialClass and m_initialTitle are undefined // and m_class and m_title are just "initial" ones. // false -> use m_class and m_title SFloatCache id{window, false};