diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2026-03-03 11:55:57 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-03 11:55:57 +0000 |
| commit | 3faddf40d08fe00738cfe7b85dc48953c27012bb (patch) | |
| tree | 1e57d080959e55396fe112c3a9956f4aa0757438 /src/layout/algorithm/tiled | |
| parent | a6e3a2478cdb01f6e4f2e0821aecda311e1c75a5 (diff) | |
algo/dwindle: don't crash on empty swapsplit (#13533)
ref https://github.com/hyprwm/Hyprland/discussions/13530
Diffstat (limited to 'src/layout/algorithm/tiled')
| -rw-r--r-- | src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp | 41 | ||||
| -rw-r--r-- | src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.hpp | 6 |
2 files changed, 29 insertions, 18 deletions
diff --git a/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp b/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp index 17ddfe8a..716097ba 100644 --- a/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp +++ b/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp @@ -657,11 +657,15 @@ std::expected<void, std::string> CDwindleAlgorithm::layoutMsg(const std::string_ const auto CURRENT_NODE = getNodeFromWindow(Desktop::focusState()->window()); if (ARGS[0] == "togglesplit") { - if (CURRENT_NODE) - toggleSplit(CURRENT_NODE); + if (CURRENT_NODE) { + if (!toggleSplit(CURRENT_NODE)) + return std::unexpected("can't togglesplit in the current workspace"); + } } else if (ARGS[0] == "swapsplit") { - if (CURRENT_NODE) - swapSplit(CURRENT_NODE); + if (CURRENT_NODE) { + if (!swapSplit(CURRENT_NODE)) + return std::unexpected("can't swapsplit in the current workspace"); + } } else if (ARGS[0] == "movetoroot") { auto node = CURRENT_NODE; if (!ARGS[1].empty()) { @@ -671,7 +675,8 @@ std::expected<void, std::string> CDwindleAlgorithm::layoutMsg(const std::string_ } const auto STABLE = ARGS[2].empty() || ARGS[2] != "unstable"; - moveToRoot(node, STABLE); + if (!moveToRoot(node, STABLE)) + return std::unexpected("can't movetoroot in the current workspace"); } else if (ARGS[0] == "preselect") { auto direction = ARGS[1]; @@ -730,37 +735,41 @@ std::expected<void, std::string> CDwindleAlgorithm::layoutMsg(const std::string_ return {}; } -void CDwindleAlgorithm::toggleSplit(SP<SDwindleNodeData> x) { +bool CDwindleAlgorithm::toggleSplit(SP<SDwindleNodeData> x) { if (!x || !x->pParent) - return; + return false; if (x->pTarget->fullscreenMode() != FSMODE_NONE) - return; + return false; x->pParent->splitTop = !x->pParent->splitTop; x->pParent->recalcSizePosRecursive(); + + return true; } -void CDwindleAlgorithm::swapSplit(SP<SDwindleNodeData> x) { - if (x->pTarget->fullscreenMode() != FSMODE_NONE) - return; +bool CDwindleAlgorithm::swapSplit(SP<SDwindleNodeData> x) { + if (x->pTarget->fullscreenMode() != FSMODE_NONE || !x->pParent) + return false; std::swap(x->pParent->children[0], x->pParent->children[1]); x->pParent->recalcSizePosRecursive(); + + return true; } -void CDwindleAlgorithm::moveToRoot(SP<SDwindleNodeData> x, bool stable) { +bool CDwindleAlgorithm::moveToRoot(SP<SDwindleNodeData> x, bool stable) { if (!x || !x->pParent) - return; + return false; if (x->pTarget->fullscreenMode() != FSMODE_NONE) - return; + return false; // already at root if (!x->pParent->pParent) - return; + return false; auto& pNode = x->pParent->children[0] == x ? x->pParent->children[0] : x->pParent->children[1]; @@ -781,4 +790,6 @@ void CDwindleAlgorithm::moveToRoot(SP<SDwindleNodeData> x, bool stable) { std::swap(pRoot->children[0], pRoot->children[1]); pRoot->recalcSizePosRecursive(); + + return true; } diff --git a/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.hpp b/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.hpp index 594b033b..97ea2908 100644 --- a/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.hpp +++ b/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.hpp @@ -48,9 +48,9 @@ namespace Layout::Tiled { SP<SDwindleNodeData> getClosestNode(const Vector2D&, SP<ITarget> skip = nullptr); SP<SDwindleNodeData> getMasterNode(); - void toggleSplit(SP<SDwindleNodeData>); - void swapSplit(SP<SDwindleNodeData>); - void moveToRoot(SP<SDwindleNodeData>, bool stable = true); + bool toggleSplit(SP<SDwindleNodeData>); + bool swapSplit(SP<SDwindleNodeData>); + bool moveToRoot(SP<SDwindleNodeData>, bool stable = true); Math::eDirection m_overrideDirection = Math::DIRECTION_DEFAULT; }; |
