From f4f3aa2e505ca1b22688fb4a32f31c4bfb851dd0 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Wed, 28 Feb 2024 11:45:43 +0000 Subject: layout: add size prediction for initial xdg commits fixes #4022 --- src/layout/MasterLayout.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/layout/MasterLayout.cpp') diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 6a3cd492..1a488b0d 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -1459,6 +1459,33 @@ void CHyprMasterLayout::replaceWindowDataWith(CWindow* from, CWindow* to) { applyNodeDataToWindow(PNODE); } +Vector2D CHyprMasterLayout::predictSizeForNewWindow() { + static auto* const PNEWISMASTER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:new_is_master"); + + if (!g_pCompositor->m_pLastMonitor) + return {}; + + const int NODES = getNodesOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + + if (NODES <= 0) + return g_pCompositor->m_pLastMonitor->vecSize; + + const auto MASTER = getMasterNodeOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + if (!MASTER) // wtf + return {}; + + if (*PNEWISMASTER) { + return MASTER->size; + } else { + const auto SLAVES = NODES - getMastersOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + + // TODO: make this better + return {g_pCompositor->m_pLastMonitor->vecSize.x - MASTER->size.x, g_pCompositor->m_pLastMonitor->vecSize.y / (SLAVES + 1)}; + } + + return {}; +} + void CHyprMasterLayout::onEnable() { for (auto& w : g_pCompositor->m_vWindows) { if (w->m_bIsFloating || !w->m_bIsMapped || w->isHidden()) -- cgit v1.2.3