aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/desktop
diff options
context:
space:
mode:
authorMightyPlaza <[email protected]>2024-10-07 18:52:49 +0000
committerGitHub <[email protected]>2024-10-07 19:52:49 +0100
commita364df4c9e9a73f0460665463028539e3abe4a8b (patch)
tree47b1d81390c78adb04c744c19c41d6a483c76c07 /src/desktop
parent46d990f1b632dc52a667d876a32cffb24ef72bd8 (diff)
downloadHyprland-a364df4c9e9a73f0460665463028539e3abe4a8b.tar.gz
Hyprland-a364df4c9e9a73f0460665463028539e3abe4a8b.zip
internal: use clampWindowSize to unify min/maxsize handling (#8014)
modified: src/desktop/Window.cpp modified: src/desktop/Window.hpp modified: src/events/Windows.cpp
Diffstat (limited to 'src/desktop')
-rw-r--r--src/desktop/Window.cpp20
-rw-r--r--src/desktop/Window.hpp1
2 files changed, 15 insertions, 6 deletions
diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp
index feced807..fa85dc07 100644
--- a/src/desktop/Window.cpp
+++ b/src/desktop/Window.cpp
@@ -736,9 +736,8 @@ void CWindow::applyDynamicRule(const SWindowRule& r) {
}
m_sWindowData.maxSize = CWindowOverridableVar(VEC, priority);
- m_vRealSize =
- Vector2D(std::min((double)m_sWindowData.maxSize.value().x, m_vRealSize.goal().x), std::min((double)m_sWindowData.maxSize.value().y, m_vRealSize.goal().y));
- g_pXWaylandManager->setWindowSize(m_pSelf.lock(), m_vRealSize.goal());
+ clampWindowSize(std::nullopt, m_sWindowData.maxSize.value());
+
} catch (std::exception& e) { Debug::log(ERR, "maxsize rule \"{}\" failed with: {}", r.szRule, e.what()); }
} else if (r.szRule.starts_with("minsize")) {
try {
@@ -751,9 +750,8 @@ void CWindow::applyDynamicRule(const SWindowRule& r) {
}
m_sWindowData.minSize = CWindowOverridableVar(VEC, priority);
- m_vRealSize =
- Vector2D(std::max((double)m_sWindowData.minSize.value().x, m_vRealSize.goal().x), std::max((double)m_sWindowData.minSize.value().y, m_vRealSize.goal().y));
- g_pXWaylandManager->setWindowSize(m_pSelf.lock(), m_vRealSize.goal());
+ clampWindowSize(m_sWindowData.minSize.value(), std::nullopt);
+
if (m_sGroupData.pNextWindow.expired())
setHidden(false);
} catch (std::exception& e) { Debug::log(ERR, "minsize rule \"{}\" failed with: {}", r.szRule, e.what()); }
@@ -1253,6 +1251,16 @@ int CWindow::surfacesCount() {
return no;
}
+void CWindow::clampWindowSize(const std::optional<Vector2D> minSize, const std::optional<Vector2D> maxSize) {
+ const Vector2D REALSIZE = m_vRealSize.goal();
+ const Vector2D NEWSIZE = REALSIZE.clamp(minSize.value_or(Vector2D{0.f, 0.f}), maxSize.value_or(Vector2D{INFINITY, INFINITY}));
+ const Vector2D DELTA = REALSIZE - NEWSIZE;
+
+ m_vRealPosition = m_vRealPosition.goal() + DELTA / 2.0;
+ m_vRealSize = NEWSIZE;
+ g_pXWaylandManager->setWindowSize(m_pSelf.lock(), NEWSIZE);
+}
+
bool CWindow::isFullscreen() {
return m_sFullscreenState.internal != FSMODE_NONE;
}
diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp
index d14248c5..9baf57c4 100644
--- a/src/desktop/Window.hpp
+++ b/src/desktop/Window.hpp
@@ -429,6 +429,7 @@ class CWindow {
bool onSpecialWorkspace();
void activate(bool force = false);
int surfacesCount();
+ void clampWindowSize(const std::optional<Vector2D> minSize, const std::optional<Vector2D> maxSize);
bool isFullscreen();
bool isEffectiveInternalFSMode(const eFullscreenMode);