From 151b5f69783b111831e8c5dc062904a221799d7b Mon Sep 17 00:00:00 2001 From: crossatko <3613973+crossatko@users.noreply.github.com> Date: Fri, 24 Oct 2025 20:01:05 +0200 Subject: dwindle: rework split logic to be fully gap-aware (#12047) --- hyprtester/src/tests/main/window.cpp | 44 +++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'hyprtester/src/tests/main/window.cpp') diff --git a/hyprtester/src/tests/main/window.cpp b/hyprtester/src/tests/main/window.cpp index 12e01563..6cfa061c 100644 --- a/hyprtester/src/tests/main/window.cpp +++ b/hyprtester/src/tests/main/window.cpp @@ -152,22 +152,40 @@ static bool test() { NLog::log("{}Testing window split ratios", Colors::YELLOW); { - const double RATIO = 1.25; - const double PERCENT = RATIO / 2.0 * 100.0; - const int GAPSIN = 5; - const int GAPSOUT = 20; - const int BORDERS = 2 * 2; - const int WTRIM = BORDERS + GAPSIN + GAPSOUT; - const int HEIGHT = 1080 - (BORDERS + (GAPSOUT * 2)); - const int WIDTH1 = std::round(1920.0 / 2.0 * (2 - RATIO)) - WTRIM; - const int WIDTH2 = std::round(1920.0 / 2.0 * RATIO) - WTRIM; + const double INITIAL_RATIO = 1.25; + const int GAPSIN = 5; + const int GAPSOUT = 20; + const int BORDERSIZE = 2; + const int BORDERS = BORDERSIZE * 2; + const int MONITOR_W = 1920; + const int MONITOR_H = 1080; + + const float totalAvailableHeight = MONITOR_H - (GAPSOUT * 2); + const int HEIGHT = std::round(totalAvailableHeight) - BORDERS; + const float availableWidthForSplit = MONITOR_W - (GAPSOUT * 2) - GAPSIN; + + auto calculateFinalWidth = [&](double boxWidth, bool isLeftWindow) { + double gapLeft = isLeftWindow ? GAPSOUT : GAPSIN; + double gapRight = isLeftWindow ? GAPSIN : GAPSOUT; + return std::round(boxWidth - gapLeft - gapRight - BORDERS); + }; + + double geomBoxWidthA_R1 = (availableWidthForSplit * INITIAL_RATIO / 2.0) + GAPSOUT + (GAPSIN / 2.0); + double geomBoxWidthB_R1 = MONITOR_W - geomBoxWidthA_R1; + const int WIDTH1 = calculateFinalWidth(geomBoxWidthB_R1, false); + + const double INVERTED_RATIO = 0.75; + double geomBoxWidthA_R2 = (availableWidthForSplit * INVERTED_RATIO / 2.0) + GAPSOUT + (GAPSIN / 2.0); + double geomBoxWidthB_R2 = MONITOR_W - geomBoxWidthA_R2; + const int WIDTH2 = calculateFinalWidth(geomBoxWidthB_R2, false); + const int WIDTH_A_FINAL = calculateFinalWidth(geomBoxWidthA_R2, true); OK(getFromSocket("/keyword dwindle:default_split_ratio 1.25")); if (!spawnKitty("kitty_B")) return false; - NLog::log("{}Expecting kitty_B to take up roughly {}% of screen width", Colors::YELLOW, 100 - PERCENT); + NLog::log("{}Expecting kitty_B size: {},{}", Colors::YELLOW, WIDTH1, HEIGHT); EXPECT_CONTAINS(getFromSocket("/activewindow"), std::format("size: {},{}", WIDTH1, HEIGHT)); OK(getFromSocket("/dispatch killwindow activewindow")); @@ -179,12 +197,12 @@ static bool test() { if (!spawnKitty("kitty_B")) return false; - NLog::log("{}Expecting kitty_B to take up roughly {}% of screen width", Colors::YELLOW, PERCENT); + NLog::log("{}Expecting kitty_B size: {},{}", Colors::YELLOW, WIDTH2, HEIGHT); EXPECT_CONTAINS(getFromSocket("/activewindow"), std::format("size: {},{}", WIDTH2, HEIGHT)); OK(getFromSocket("/dispatch focuswindow class:kitty_A")); - NLog::log("{}Expecting kitty_A to have the same width as the previous kitty_B", Colors::YELLOW); - EXPECT_CONTAINS(getFromSocket("/activewindow"), std::format("size: {},{}", WIDTH1, HEIGHT)); + NLog::log("{}Expecting kitty_A size: {},{}", Colors::YELLOW, WIDTH_A_FINAL, HEIGHT); + EXPECT_CONTAINS(getFromSocket("/activewindow"), std::format("size: {},{}", WIDTH_A_FINAL, HEIGHT)); OK(getFromSocket("/keyword dwindle:default_split_ratio 1")); } -- cgit v1.2.3