Skip to content

Commit 930eeac

Browse files
authored
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 #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
1 parent ec93f8a commit 930eeac

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

src/config/ConfigManager.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3043,13 +3043,18 @@ void CConfigManager::ensurePersistentWorkspacesPresent() {
30433043
}
30443044

30453045
void CConfigManager::storeFloatingSize(PHLWINDOW window, const Vector2D& size) {
3046-
Debug::log(LOG, "storing floating size {}x{} for window {}::{}", size.x, size.y, window->m_class, window->m_title);
3047-
SFloatCache id{window};
3046+
Debug::log(LOG, "storing floating size {}x{} for window {}::{}", size.x, size.y, window->m_initialClass, window->m_initialTitle);
3047+
// true -> use m_initialClass and m_initialTitle
3048+
SFloatCache id{window, true};
30483049
m_mStoredFloatingSizes[id] = size;
30493050
}
30503051

30513052
std::optional<Vector2D> CConfigManager::getStoredFloatingSize(PHLWINDOW window) {
3052-
SFloatCache id{window};
3053+
// At startup, m_initialClass and m_initialTitle are undefined
3054+
// and m_class and m_title are just "initial" ones.
3055+
// false -> use m_class and m_title
3056+
SFloatCache id{window, false};
3057+
Debug::log(LOG, "Hash for window {}::{} = {}", window->m_class, window->m_title, id.hash);
30533058
if (m_mStoredFloatingSizes.contains(id)) {
30543059
Debug::log(LOG, "got stored size {}x{} for window {}::{}", m_mStoredFloatingSizes[id].x, m_mStoredFloatingSizes[id].y, window->m_class, window->m_title);
30553060
return m_mStoredFloatingSizes[id];

src/config/ConfigManager.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,18 @@ struct SFirstExecRequest {
141141
struct SFloatCache {
142142
size_t hash;
143143

144-
SFloatCache(PHLWINDOW window) {
145-
hash = std::hash<std::string>{}(window->m_class) ^ (std::hash<std::string>{}(window->m_title) << 1);
144+
SFloatCache(PHLWINDOW window, bool initial) {
145+
// Base hash from class/title
146+
size_t baseHash = initial ? (std::hash<std::string>{}(window->m_initialClass) ^ (std::hash<std::string>{}(window->m_initialTitle) << 1)) :
147+
(std::hash<std::string>{}(window->m_class) ^ (std::hash<std::string>{}(window->m_title) << 1));
148+
149+
// Use empty string as default tag value
150+
std::string tagValue = "";
151+
if (auto xdgTag = window->xdgTag())
152+
tagValue = xdgTag.value();
153+
154+
// Combine hashes
155+
hash = baseHash ^ (std::hash<std::string>{}(tagValue) << 2);
146156
}
147157

148158
bool operator==(const SFloatCache& other) const {

src/layout/IHyprLayout.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
void IHyprLayout::onWindowCreated(PHLWINDOW pWindow, eDirection direction) {
1818
CBox desiredGeometry = g_pXWaylandManager->getGeometryForWindow(pWindow);
1919

20-
const bool HASPERSISTENTSIZE =
21-
std::any_of(pWindow->m_matchedRules.begin(), pWindow->m_matchedRules.end(), [](const auto& rule) { return rule->m_ruleType == CWindowRule::RULE_PERSISTENTSIZE; });
20+
const bool HASPERSISTENTSIZE = std::ranges::any_of(pWindow->m_matchedRules, [](const auto& rule) { return rule->m_ruleType == CWindowRule::RULE_PERSISTENTSIZE; });
2221

2322
const auto STOREDSIZE = HASPERSISTENTSIZE ? g_pConfigManager->getStoredFloatingSize(pWindow) : std::nullopt;
2423

@@ -886,6 +885,17 @@ void IHyprLayout::requestFocusForWindow(PHLWINDOW pWindow) {
886885
Vector2D IHyprLayout::predictSizeForNewWindowFloating(PHLWINDOW pWindow) { // get all rules, see if we have any size overrides.
887886
Vector2D sizeOverride = {};
888887
if (g_pCompositor->m_lastMonitor) {
888+
889+
// If `persistentsize` is set, use the stored size if available.
890+
const bool HASPERSISTENTSIZE = std::ranges::any_of(pWindow->m_matchedRules, [](const auto& rule) { return rule->m_ruleType == CWindowRule::RULE_PERSISTENTSIZE; });
891+
892+
const auto STOREDSIZE = HASPERSISTENTSIZE ? g_pConfigManager->getStoredFloatingSize(pWindow) : std::nullopt;
893+
894+
if (STOREDSIZE.has_value()) {
895+
Debug::log(LOG, "using stored size {}x{} for new floating window {}::{}", STOREDSIZE->x, STOREDSIZE->y, pWindow->m_class, pWindow->m_title);
896+
return STOREDSIZE.value();
897+
}
898+
889899
for (auto const& r : g_pConfigManager->getMatchingRules(pWindow, true, true)) {
890900
if (r->m_ruleType != CWindowRule::RULE_SIZE)
891901
continue;

0 commit comments

Comments
 (0)