Skip to content

Commit

Permalink
internal: use clampWindowSize to unify min/maxsize handling (#8014)
Browse files Browse the repository at this point in the history
modified:   src/desktop/Window.cpp
modified:   src/desktop/Window.hpp
modified:   src/events/Windows.cpp
  • Loading branch information
MightyPlaza authored Oct 7, 2024
1 parent 46d990f commit a364df4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
20 changes: 14 additions & 6 deletions src/desktop/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()); }
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/desktop/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 2 additions & 20 deletions src/events/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,26 +751,8 @@ void Events::listener_commitWindow(void* owner, void* data) {
const auto MINSIZE = PWINDOW->m_pXDGSurface->toplevel->current.minSize;
const auto MAXSIZE = PWINDOW->m_pXDGSurface->toplevel->current.maxSize;

if (MAXSIZE > Vector2D{1, 1}) {
const auto REALSIZE = PWINDOW->m_vRealSize.goal();
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);
}
PWINDOW->clampWindowSize(MINSIZE, MAXSIZE > Vector2D{1, 1} ? std::optional<Vector2D>{MAXSIZE} : std::nullopt);
g_pHyprRenderer->damageWindow(PWINDOW);
}

if (!PWINDOW->m_pWorkspace->m_bVisible)
Expand Down

0 comments on commit a364df4

Please sign in to comment.