window: use stored size for new floating window when persistentsize is set (#10212)

* fix(window): use stored size for new floating window when persistentsize is set. fix hyprwm#9422.

* fix: replace `std::any_of` with `std::ranges:any_of`

* fix: use initialClass and initialTitle when storing sizes on close

* fix: add `xdgTag` as a new indicator

* fix: no {}

* fix: format with clang-format
This commit is contained in:
Jack Barnes 2025-05-06 09:53:43 +08:00 committed by GitHub
parent ec93f8a1cd
commit 930eeac900
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 7 deletions

View File

@ -3043,13 +3043,18 @@ void CConfigManager::ensurePersistentWorkspacesPresent() {
} }
void CConfigManager::storeFloatingSize(PHLWINDOW window, const Vector2D& size) { 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); Debug::log(LOG, "storing floating size {}x{} for window {}::{}", size.x, size.y, window->m_initialClass, window->m_initialTitle);
SFloatCache id{window}; // true -> use m_initialClass and m_initialTitle
SFloatCache id{window, true};
m_mStoredFloatingSizes[id] = size; m_mStoredFloatingSizes[id] = size;
} }
std::optional<Vector2D> CConfigManager::getStoredFloatingSize(PHLWINDOW window) { std::optional<Vector2D> 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)) { 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); 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]; return m_mStoredFloatingSizes[id];

View File

@ -141,8 +141,18 @@ struct SFirstExecRequest {
struct SFloatCache { struct SFloatCache {
size_t hash; size_t hash;
SFloatCache(PHLWINDOW window) { SFloatCache(PHLWINDOW window, bool initial) {
hash = std::hash<std::string>{}(window->m_class) ^ (std::hash<std::string>{}(window->m_title) << 1); // Base hash from class/title
size_t baseHash = initial ? (std::hash<std::string>{}(window->m_initialClass) ^ (std::hash<std::string>{}(window->m_initialTitle) << 1)) :
(std::hash<std::string>{}(window->m_class) ^ (std::hash<std::string>{}(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<std::string>{}(tagValue) << 2);
} }
bool operator==(const SFloatCache& other) const { bool operator==(const SFloatCache& other) const {

View File

@ -17,8 +17,7 @@
void IHyprLayout::onWindowCreated(PHLWINDOW pWindow, eDirection direction) { void IHyprLayout::onWindowCreated(PHLWINDOW pWindow, eDirection direction) {
CBox desiredGeometry = g_pXWaylandManager->getGeometryForWindow(pWindow); CBox desiredGeometry = g_pXWaylandManager->getGeometryForWindow(pWindow);
const bool HASPERSISTENTSIZE = const bool HASPERSISTENTSIZE = std::ranges::any_of(pWindow->m_matchedRules, [](const auto& rule) { return rule->m_ruleType == CWindowRule::RULE_PERSISTENTSIZE; });
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; const auto STOREDSIZE = HASPERSISTENTSIZE ? g_pConfigManager->getStoredFloatingSize(pWindow) : std::nullopt;
@ -886,6 +885,17 @@ void IHyprLayout::requestFocusForWindow(PHLWINDOW pWindow) {
Vector2D IHyprLayout::predictSizeForNewWindowFloating(PHLWINDOW pWindow) { // get all rules, see if we have any size overrides. Vector2D IHyprLayout::predictSizeForNewWindowFloating(PHLWINDOW pWindow) { // get all rules, see if we have any size overrides.
Vector2D sizeOverride = {}; Vector2D sizeOverride = {};
if (g_pCompositor->m_lastMonitor) { if (g_pCompositor->m_lastMonitor) {
// If `persistentsize` is set, use the stored size if available.
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;
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)) { for (auto const& r : g_pConfigManager->getMatchingRules(pWindow, true, true)) {
if (r->m_ruleType != CWindowRule::RULE_SIZE) if (r->m_ruleType != CWindowRule::RULE_SIZE)
continue; continue;