diff --git a/hyprtester/src/tests/main/dwindle.cpp b/hyprtester/src/tests/main/dwindle.cpp index 664a8d73..ef270a62 100644 --- a/hyprtester/src/tests/main/dwindle.cpp +++ b/hyprtester/src/tests/main/dwindle.cpp @@ -84,14 +84,13 @@ static void test13349() { static void testSplit() { // Test various split methods - for (auto const& win : {"a", "b"}) { - if (!Tests::spawnKitty(win)) { - NLog::log("{}Failed to spawn kitty with win class `{}`", Colors::RED, win); - ++TESTS_FAILED; - ret = 1; - return; - } - } + Tests::spawnKitty("a"); + + // these must not crash + EXPECT_NOT(getFromSocket("/dispatch layoutmsg swapsplit"), "ok"); + EXPECT_NOT(getFromSocket("/dispatch layoutmsg splitratio 1 exact"), "ok"); + + Tests::spawnKitty("b"); OK(getFromSocket("/dispatch focuswindow class:a")); OK(getFromSocket("/dispatch layoutmsg splitratio -0.2")); 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 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 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 CDwindleAlgorithm::layoutMsg(const std::string_ return {}; } -void CDwindleAlgorithm::toggleSplit(SP x) { +bool CDwindleAlgorithm::toggleSplit(SP 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 x) { - if (x->pTarget->fullscreenMode() != FSMODE_NONE) - return; +bool CDwindleAlgorithm::swapSplit(SP 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 x, bool stable) { +bool CDwindleAlgorithm::moveToRoot(SP 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 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 getClosestNode(const Vector2D&, SP skip = nullptr); SP getMasterNode(); - void toggleSplit(SP); - void swapSplit(SP); - void moveToRoot(SP, bool stable = true); + bool toggleSplit(SP); + bool swapSplit(SP); + bool moveToRoot(SP, bool stable = true); Math::eDirection m_overrideDirection = Math::DIRECTION_DEFAULT; };