From 6ade4d58cab67e18aa758ef664e36421cab4d8b2 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Wed, 29 Oct 2025 23:21:28 +0000 Subject: layout: fit floating window on toggle to float (#12139) --- src/layout/IHyprLayout.cpp | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'src/layout/IHyprLayout.cpp') diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index e21cd886..4ae41d57 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -790,17 +790,16 @@ void IHyprLayout::changeWindowFloatingMode(PHLWINDOW pWindow) { CBox wb = {pWindow->m_realPosition->goal() + (pWindow->m_realSize->goal() - pWindow->m_lastFloatingSize) / 2.f, pWindow->m_lastFloatingSize}; wb.round(); - if (!(pWindow->m_isFloating && pWindow->m_isPseudotiled) && DELTALESSTHAN(pWindow->m_realSize->value().x, pWindow->m_lastFloatingSize.x, 10) && - DELTALESSTHAN(pWindow->m_realSize->value().y, pWindow->m_lastFloatingSize.y, 10)) { + if (!(pWindow->m_isFloating && pWindow->m_isPseudotiled) && DELTALESSTHAN(pWindow->m_realSize->goal().x, pWindow->m_lastFloatingSize.x, 10) && + DELTALESSTHAN(pWindow->m_realSize->goal().y, pWindow->m_lastFloatingSize.y, 10)) { wb = {wb.pos() + Vector2D{10, 10}, wb.size() - Vector2D{20, 20}}; } - *pWindow->m_realPosition = wb.pos(); - *pWindow->m_realSize = wb.size(); - pWindow->m_size = wb.size(); pWindow->m_position = wb.pos(); + fitFloatingWindowOnMonitor(pWindow, wb); + g_pHyprRenderer->damageMonitor(pWindow->m_monitor.lock()); pWindow->unsetWindowData(PRIORITY_LAYOUT); @@ -815,6 +814,36 @@ void IHyprLayout::changeWindowFloatingMode(PHLWINDOW pWindow) { g_pHyprRenderer->damageWindow(pWindow); } +void IHyprLayout::fitFloatingWindowOnMonitor(PHLWINDOW w, std::optional tb) { + if (!w->m_isFloating) + return; + + const auto PMONITOR = w->m_monitor.lock(); + + if (!PMONITOR) + return; + + const auto EXTENTS = w->getWindowExtentsUnified(RESERVED_EXTENTS | INPUT_EXTENTS); + CBox targetBoxMonLocal = tb.value_or(w->getWindowMainSurfaceBox()).translate(-PMONITOR->m_position).addExtents(EXTENTS); + + if (targetBoxMonLocal.w < PMONITOR->m_size.x) { + if (targetBoxMonLocal.x < 0) + targetBoxMonLocal.x = 0; + else if (targetBoxMonLocal.x + targetBoxMonLocal.w > PMONITOR->m_size.x) + targetBoxMonLocal.x = PMONITOR->m_size.x - targetBoxMonLocal.w; + } + + if (targetBoxMonLocal.h < PMONITOR->m_size.y) { + if (targetBoxMonLocal.y < 0) + targetBoxMonLocal.y = 0; + else if (targetBoxMonLocal.y + targetBoxMonLocal.h > PMONITOR->m_size.y) + targetBoxMonLocal.y = PMONITOR->m_size.y - targetBoxMonLocal.h; + } + + *w->m_realPosition = (targetBoxMonLocal.pos() + PMONITOR->m_position + EXTENTS.topLeft).round(); + *w->m_realSize = (targetBoxMonLocal.size() - EXTENTS.topLeft - EXTENTS.bottomRight).round(); +} + void IHyprLayout::moveActiveWindow(const Vector2D& delta, PHLWINDOW pWindow) { const auto PWINDOW = pWindow ? pWindow : g_pCompositor->m_lastWindow.lock(); -- cgit v1.2.3