summaryrefslogtreecommitdiff
path: root/src/layout/DwindleLayout.cpp
diff options
context:
space:
mode:
authorvaxerski <vaxry@vaxry.net>2024-02-28 11:45:43 +0000
committervaxerski <vaxry@vaxry.net>2024-02-28 11:45:43 +0000
commitf4f3aa2e505ca1b22688fb4a32f31c4bfb851dd0 (patch)
tree98c8547e45a04445b24b2aa90b0a3e0d302a0cd6 /src/layout/DwindleLayout.cpp
parentc198d744b77f272c2fc187eb6d431580a99ab6c3 (diff)
layout: add size prediction for initial xdg commits
fixes #4022
Diffstat (limited to 'src/layout/DwindleLayout.cpp')
-rw-r--r--src/layout/DwindleLayout.cpp66
1 files changed, 58 insertions, 8 deletions
diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp
index 0f4a5f87..2bb6e4c3 100644
--- a/src/layout/DwindleLayout.cpp
+++ b/src/layout/DwindleLayout.cpp
@@ -127,7 +127,13 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for
const auto PWINDOW = pNode->pWindow;
// get specific gaps and rules for this workspace,
// if user specified them in config
- const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID));
+ const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(pNode->workspaceID));
+
+ if (!g_pCompositor->windowExists(PWINDOW)) {
+ Debug::log(ERR, "Node {} holding invalid {}!!", pNode, PWINDOW);
+ onWindowRemovedTiling(PWINDOW);
+ return;
+ }
if (PWINDOW->m_bIsFullscreen && !pNode->ignoreFullscreenChecks)
return;
@@ -143,13 +149,7 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for
auto gapsIn = WORKSPACERULE.gapsIn.value_or(*PGAPSIN);
auto gapsOut = WORKSPACERULE.gapsOut.value_or(*PGAPSOUT);
- if (!g_pCompositor->windowExists(PWINDOW) || !PWINDOW->m_bIsMapped) {
- Debug::log(ERR, "Node {} holding invalid {}!!", pNode, PWINDOW);
- onWindowRemovedTiling(PWINDOW);
- return;
- }
-
- CBox nodeBox = pNode->box;
+ CBox nodeBox = pNode->box;
nodeBox.round();
PWINDOW->m_vSize = nodeBox.size();
@@ -1093,3 +1093,53 @@ void CHyprDwindleLayout::onEnable() {
void CHyprDwindleLayout::onDisable() {
m_lDwindleNodesData.clear();
}
+
+Vector2D CHyprDwindleLayout::predictSizeForNewWindow() {
+ if (!g_pCompositor->m_pLastMonitor)
+ return {};
+
+ // get window candidate
+ CWindow* candidate = g_pCompositor->m_pLastWindow;
+
+ if (!candidate)
+ candidate = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace);
+
+ // create a fake node
+ SDwindleNodeData node;
+
+ if (!candidate)
+ return g_pCompositor->m_pLastMonitor->vecSize;
+ else {
+ const auto PNODE = getNodeFromWindow(candidate);
+
+ if (!PNODE)
+ return {};
+
+ node = *PNODE;
+ node.pWindow = nullptr;
+
+ CBox box = PNODE->box;
+
+ static auto* const PSMARTSPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:smart_split");
+ static auto* const PPRESERVESPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:preserve_split");
+ static auto* const PFLMULT = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("dwindle:split_width_multiplier");
+
+ bool splitTop = false;
+
+ if (**PPRESERVESPLIT == 0 && **PSMARTSPLIT == 0)
+ splitTop = box.h * **PFLMULT > box.w;
+
+ const auto SPLITSIDE = !splitTop;
+
+ if (SPLITSIDE)
+ node.box = {{}, {box.w / 2.0, box.h}};
+ else
+ node.box = {{}, {box.w, box.h / 2.0}};
+
+ // TODO: make this better and more accurate
+
+ return node.box.size();
+ }
+
+ return {};
+}