mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-23 03:05:59 +01:00
internal: use clampWindowSize to unify min/maxsize handling (#8014)
modified: src/desktop/Window.cpp modified: src/desktop/Window.hpp modified: src/events/Windows.cpp
This commit is contained in:
parent
46d990f1b6
commit
a364df4c9e
3 changed files with 17 additions and 26 deletions
|
@ -736,9 +736,8 @@ void CWindow::applyDynamicRule(const SWindowRule& r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sWindowData.maxSize = CWindowOverridableVar(VEC, priority);
|
m_sWindowData.maxSize = CWindowOverridableVar(VEC, priority);
|
||||||
m_vRealSize =
|
clampWindowSize(std::nullopt, m_sWindowData.maxSize.value());
|
||||||
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());
|
|
||||||
} catch (std::exception& e) { Debug::log(ERR, "maxsize rule \"{}\" failed with: {}", r.szRule, e.what()); }
|
} catch (std::exception& e) { Debug::log(ERR, "maxsize rule \"{}\" failed with: {}", r.szRule, e.what()); }
|
||||||
} else if (r.szRule.starts_with("minsize")) {
|
} else if (r.szRule.starts_with("minsize")) {
|
||||||
try {
|
try {
|
||||||
|
@ -751,9 +750,8 @@ void CWindow::applyDynamicRule(const SWindowRule& r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sWindowData.minSize = CWindowOverridableVar(VEC, priority);
|
m_sWindowData.minSize = CWindowOverridableVar(VEC, priority);
|
||||||
m_vRealSize =
|
clampWindowSize(m_sWindowData.minSize.value(), std::nullopt);
|
||||||
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());
|
|
||||||
if (m_sGroupData.pNextWindow.expired())
|
if (m_sGroupData.pNextWindow.expired())
|
||||||
setHidden(false);
|
setHidden(false);
|
||||||
} catch (std::exception& e) { Debug::log(ERR, "minsize rule \"{}\" failed with: {}", r.szRule, e.what()); }
|
} catch (std::exception& e) { Debug::log(ERR, "minsize rule \"{}\" failed with: {}", r.szRule, e.what()); }
|
||||||
|
@ -1253,6 +1251,16 @@ int CWindow::surfacesCount() {
|
||||||
return no;
|
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() {
|
bool CWindow::isFullscreen() {
|
||||||
return m_sFullscreenState.internal != FSMODE_NONE;
|
return m_sFullscreenState.internal != FSMODE_NONE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -429,6 +429,7 @@ class CWindow {
|
||||||
bool onSpecialWorkspace();
|
bool onSpecialWorkspace();
|
||||||
void activate(bool force = false);
|
void activate(bool force = false);
|
||||||
int surfacesCount();
|
int surfacesCount();
|
||||||
|
void clampWindowSize(const std::optional<Vector2D> minSize, const std::optional<Vector2D> maxSize);
|
||||||
|
|
||||||
bool isFullscreen();
|
bool isFullscreen();
|
||||||
bool isEffectiveInternalFSMode(const eFullscreenMode);
|
bool isEffectiveInternalFSMode(const eFullscreenMode);
|
||||||
|
|
|
@ -751,26 +751,8 @@ void Events::listener_commitWindow(void* owner, void* data) {
|
||||||
const auto MINSIZE = PWINDOW->m_pXDGSurface->toplevel->current.minSize;
|
const auto MINSIZE = PWINDOW->m_pXDGSurface->toplevel->current.minSize;
|
||||||
const auto MAXSIZE = PWINDOW->m_pXDGSurface->toplevel->current.maxSize;
|
const auto MAXSIZE = PWINDOW->m_pXDGSurface->toplevel->current.maxSize;
|
||||||
|
|
||||||
if (MAXSIZE > Vector2D{1, 1}) {
|
PWINDOW->clampWindowSize(MINSIZE, MAXSIZE > Vector2D{1, 1} ? std::optional<Vector2D>{MAXSIZE} : std::nullopt);
|
||||||
const auto REALSIZE = PWINDOW->m_vRealSize.goal();
|
g_pHyprRenderer->damageWindow(PWINDOW);
|
||||||
Vector2D newSize = REALSIZE;
|
|
||||||
|
|
||||||
if (MAXSIZE.x < newSize.x)
|
|
||||||
newSize.x = MAXSIZE.x;
|
|
||||||
if (MAXSIZE.y < newSize.y)
|
|
||||||
newSize.y = MAXSIZE.y;
|
|
||||||
if (MINSIZE.x > newSize.x)
|
|
||||||
newSize.x = MINSIZE.x;
|
|
||||||
if (MINSIZE.y > newSize.y)
|
|
||||||
newSize.y = MINSIZE.y;
|
|
||||||
|
|
||||||
const Vector2D DELTA = REALSIZE - newSize;
|
|
||||||
|
|
||||||
PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition.goal() + DELTA / 2.0;
|
|
||||||
PWINDOW->m_vRealSize = newSize;
|
|
||||||
g_pXWaylandManager->setWindowSize(PWINDOW, newSize);
|
|
||||||
g_pHyprRenderer->damageWindow(PWINDOW);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PWINDOW->m_pWorkspace->m_bVisible)
|
if (!PWINDOW->m_pWorkspace->m_bVisible)
|
||||||
|
|
Loading…
Reference in a new issue