algo/dwindle: add back splitratio (#13498)
This commit is contained in:
parent
5cb1281035
commit
9f98f7440b
3 changed files with 87 additions and 0 deletions
|
|
@ -39,6 +39,16 @@ namespace Colors {
|
||||||
TESTS_PASSED++; \
|
TESTS_PASSED++; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define EXPECT_NOT(expr, val) \
|
||||||
|
if (const auto RESULT = expr; RESULT == (val)) { \
|
||||||
|
NLog::log("{}Failed: {}{}, expected not {}, got {}. Source: {}@{}.", Colors::RED, Colors::RESET, #expr, val, RESULT, __FILE__, __LINE__); \
|
||||||
|
ret = 1; \
|
||||||
|
TESTS_FAILED++; \
|
||||||
|
} else { \
|
||||||
|
NLog::log("{}Passed: {}{}. Got {}", Colors::GREEN, Colors::RESET, #expr, val); \
|
||||||
|
TESTS_PASSED++; \
|
||||||
|
}
|
||||||
|
|
||||||
#define EXPECT_VECTOR2D(expr, val) \
|
#define EXPECT_VECTOR2D(expr, val) \
|
||||||
do { \
|
do { \
|
||||||
const auto& RESULT = expr; \
|
const auto& RESULT = expr; \
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,61 @@ static void test13349() {
|
||||||
Tests::killAllWindows();
|
Tests::killAllWindows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OK(getFromSocket("/dispatch focuswindow class:a"));
|
||||||
|
OK(getFromSocket("/dispatch layoutmsg splitratio -0.2"));
|
||||||
|
|
||||||
|
{
|
||||||
|
auto str = getFromSocket("/activewindow");
|
||||||
|
EXPECT_CONTAINS(str, "at: 22,22");
|
||||||
|
EXPECT_CONTAINS(str, "size: 743,1036");
|
||||||
|
}
|
||||||
|
|
||||||
|
OK(getFromSocket("/dispatch layoutmsg splitratio 1.6 exact"));
|
||||||
|
|
||||||
|
{
|
||||||
|
auto str = getFromSocket("/activewindow");
|
||||||
|
EXPECT_CONTAINS(str, "at: 22,22");
|
||||||
|
EXPECT_CONTAINS(str, "size: 1495,1036");
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_NOT(getFromSocket("/dispatch layoutmsg splitratio fhne exact"), "ok");
|
||||||
|
EXPECT_NOT(getFromSocket("/dispatch layoutmsg splitratio exact"), "ok");
|
||||||
|
EXPECT_NOT(getFromSocket("/dispatch layoutmsg splitratio -....9"), "ok");
|
||||||
|
EXPECT_NOT(getFromSocket("/dispatch layoutmsg splitratio ..9"), "ok");
|
||||||
|
EXPECT_NOT(getFromSocket("/dispatch layoutmsg splitratio"), "ok");
|
||||||
|
|
||||||
|
OK(getFromSocket("/dispatch layoutmsg togglesplit"));
|
||||||
|
|
||||||
|
{
|
||||||
|
auto str = getFromSocket("/activewindow");
|
||||||
|
EXPECT_CONTAINS(str, "at: 22,22");
|
||||||
|
EXPECT_CONTAINS(str, "size: 1876,823");
|
||||||
|
}
|
||||||
|
|
||||||
|
OK(getFromSocket("/dispatch layoutmsg swapsplit"));
|
||||||
|
|
||||||
|
{
|
||||||
|
auto str = getFromSocket("/activewindow");
|
||||||
|
EXPECT_CONTAINS(str, "at: 22,859");
|
||||||
|
EXPECT_CONTAINS(str, "size: 1876,199");
|
||||||
|
}
|
||||||
|
|
||||||
|
NLog::log("{}Killing all windows", Colors::YELLOW);
|
||||||
|
Tests::killAllWindows();
|
||||||
|
}
|
||||||
|
|
||||||
static bool test() {
|
static bool test() {
|
||||||
NLog::log("{}Testing Dwindle layout", Colors::GREEN);
|
NLog::log("{}Testing Dwindle layout", Colors::GREEN);
|
||||||
|
|
||||||
|
|
@ -91,6 +146,9 @@ static bool test() {
|
||||||
NLog::log("{}Testing #13349", Colors::GREEN);
|
NLog::log("{}Testing #13349", Colors::GREEN);
|
||||||
test13349();
|
test13349();
|
||||||
|
|
||||||
|
NLog::log("{}Testing splits", Colors::GREEN);
|
||||||
|
testSplit();
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
NLog::log("Cleaning up", Colors::YELLOW);
|
NLog::log("Cleaning up", Colors::YELLOW);
|
||||||
getFromSocket("/dispatch workspace 1");
|
getFromSocket("/dispatch workspace 1");
|
||||||
|
|
|
||||||
|
|
@ -714,6 +714,25 @@ std::expected<void, std::string> CDwindleAlgorithm::layoutMsg(const std::string_
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (ARGS[0] == "splitratio") {
|
||||||
|
auto ratio = ARGS[1];
|
||||||
|
bool exact = ARGS[2].starts_with("exact");
|
||||||
|
|
||||||
|
if (ratio.empty())
|
||||||
|
return std::unexpected("splitratio requires an arg");
|
||||||
|
|
||||||
|
auto delta = getPlusMinusKeywordResult(std::string{ratio}, 0.F);
|
||||||
|
|
||||||
|
if (!CURRENT_NODE || !CURRENT_NODE->pParent)
|
||||||
|
return std::unexpected("cannot alter split ratio on no / single node");
|
||||||
|
|
||||||
|
if (!delta)
|
||||||
|
return std::unexpected(std::format("failed to parse \"{}\" as a delta", ratio));
|
||||||
|
|
||||||
|
const float newRatio = exact ? *delta : CURRENT_NODE->pParent->splitRatio + *delta;
|
||||||
|
CURRENT_NODE->pParent->splitRatio = std::clamp(newRatio, 0.1F, 1.9F);
|
||||||
|
|
||||||
|
CURRENT_NODE->pParent->recalcSizePosRecursive();
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue