diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2025-12-27 12:43:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-27 12:43:45 +0100 |
| commit | 42447a50d6840c5e28bd58db1225bae2fd7d5ed0 (patch) | |
| tree | e73584ecd482bf5320a3e35f963a12787ce7cce5 /src/desktop/view/Window.cpp | |
| parent | d7f26038ee2b44f3d02fe2a7556bafb91a02f46e (diff) | |
rules/windowRuleApplicator: fix min/max size effects (#12491)
fixes #12412
Diffstat (limited to 'src/desktop/view/Window.cpp')
| -rw-r--r-- | src/desktop/view/Window.cpp | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/src/desktop/view/Window.cpp b/src/desktop/view/Window.cpp index 32a0086e..695ba81f 100644 --- a/src/desktop/view/Window.cpp +++ b/src/desktop/view/Window.cpp @@ -1574,41 +1574,13 @@ bool CWindow::isModal() { return (m_xwaylandSurface && m_xwaylandSurface->m_modal); } -Vector2D CWindow::requestedMinSize() { - bool hasSizeHints = m_xwaylandSurface ? m_xwaylandSurface->m_sizeHints : false; - bool hasTopLevel = m_xdgSurface ? m_xdgSurface->m_toplevel : false; - if ((m_isX11 && !hasSizeHints) || (!m_isX11 && !hasTopLevel)) - return Vector2D(1, 1); - - Vector2D minSize = m_isX11 ? Vector2D(m_xwaylandSurface->m_sizeHints->min_width, m_xwaylandSurface->m_sizeHints->min_height) : m_xdgSurface->m_toplevel->layoutMinSize(); - - minSize = minSize.clamp({1, 1}); - - return minSize; -} - -Vector2D CWindow::requestedMaxSize() { - constexpr int NO_MAX_SIZE_LIMIT = 99999; - if (((m_isX11 && !m_xwaylandSurface->m_sizeHints) || (!m_isX11 && (!m_xdgSurface || !m_xdgSurface->m_toplevel)) || m_ruleApplicator->noMaxSize().valueOrDefault())) - return Vector2D(NO_MAX_SIZE_LIMIT, NO_MAX_SIZE_LIMIT); - - Vector2D maxSize = m_isX11 ? Vector2D(m_xwaylandSurface->m_sizeHints->max_width, m_xwaylandSurface->m_sizeHints->max_height) : m_xdgSurface->m_toplevel->layoutMaxSize(); - - if (maxSize.x < 5) - maxSize.x = NO_MAX_SIZE_LIMIT; - if (maxSize.y < 5) - maxSize.y = NO_MAX_SIZE_LIMIT; - - return maxSize; -} - Vector2D CWindow::realToReportSize() { if (!m_isX11) - return m_realSize->goal().clamp(Vector2D{0, 0}, Vector2D{std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()}); + return m_realSize->goal().clamp(Vector2D{0, 0}, Math::VECTOR2D_MAX); static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling"); - const auto REPORTSIZE = m_realSize->goal().clamp(Vector2D{1, 1}, Vector2D{std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()}); + const auto REPORTSIZE = m_realSize->goal().clamp(Vector2D{1, 1}, Math::VECTOR2D_MAX); const auto PMONITOR = m_monitor.lock(); if (*PXWLFORCESCALEZERO && PMONITOR) @@ -1628,7 +1600,7 @@ Vector2D CWindow::xwaylandSizeToReal(Vector2D size) { static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling"); const auto PMONITOR = m_monitor.lock(); - const auto SIZE = size.clamp(Vector2D{1, 1}, Vector2D{std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()}); + const auto SIZE = size.clamp(Vector2D{1, 1}, Math::VECTOR2D_MAX); const auto SCALE = *PXWLFORCESCALEZERO ? PMONITOR->m_scale : 1.0f; return SIZE / SCALE; @@ -2718,3 +2690,42 @@ void CWindow::unmanagedSetGeometry() { m_pendingReportedSize = m_realSize->goal(); } } + +std::optional<Vector2D> CWindow::minSize() { + // first check for overrides + if (m_ruleApplicator->minSize().hasValue()) + return m_ruleApplicator->minSize().value(); + + // then check if we have any proto overrides + bool hasSizeHints = m_xwaylandSurface ? m_xwaylandSurface->m_sizeHints : false; + bool hasTopLevel = m_xdgSurface ? m_xdgSurface->m_toplevel : false; + if ((m_isX11 && !hasSizeHints) || (!m_isX11 && !hasTopLevel)) + return std::nullopt; + + Vector2D minSize = m_isX11 ? Vector2D(m_xwaylandSurface->m_sizeHints->min_width, m_xwaylandSurface->m_sizeHints->min_height) : m_xdgSurface->m_toplevel->layoutMinSize(); + + minSize = minSize.clamp({1, 1}); + + return minSize; +} + +std::optional<Vector2D> CWindow::maxSize() { + // first check for overrides + if (m_ruleApplicator->maxSize().hasValue()) + return m_ruleApplicator->maxSize().value(); + + // then check if we have any proto overrides + if (((m_isX11 && !m_xwaylandSurface->m_sizeHints) || (!m_isX11 && (!m_xdgSurface || !m_xdgSurface->m_toplevel)) || m_ruleApplicator->noMaxSize().valueOrDefault())) + return std::nullopt; + + constexpr const double NO_MAX_SIZE_LIMIT = std::numeric_limits<double>::max(); + + Vector2D maxSize = m_isX11 ? Vector2D(m_xwaylandSurface->m_sizeHints->max_width, m_xwaylandSurface->m_sizeHints->max_height) : m_xdgSurface->m_toplevel->layoutMaxSize(); + + if (maxSize.x < 5) + maxSize.x = NO_MAX_SIZE_LIMIT; + if (maxSize.y < 5) + maxSize.y = NO_MAX_SIZE_LIMIT; + + return maxSize; +} |
