From 7601b86450f8ed18512547b98675f930d20a1b88 Mon Sep 17 00:00:00 2001 From: speckitor Date: Sat, 4 Apr 2026 16:59:31 +0700 Subject: [PATCH] add variable main stack size --- include/config.h | 3 ++- src/layout.c | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/include/config.h b/include/config.h index 28c133e..6cb7403 100644 --- a/include/config.h +++ b/include/config.h @@ -9,7 +9,8 @@ static const float focused_border_color[4] = {0.88, 0.18, 0.18, 1.0}; static const float unfocused_border_color[4] = {0.18, 0.18, 0.18, 1.0}; -#define ABSINTHE_MAIN_TOPLEVEL_WIDTH 0.5 +#define ABSINTHE_MAIN_STACK_WIDTH 0.5 +#define ABSINTHE_MAIN_STACK_SIZE 2 #define ABSINTHE_OUTPUT_GAP 10 #define ABSINTHE_LAYOUT_GAP 10 diff --git a/src/layout.c b/src/layout.c index fba31c6..51dfae7 100644 --- a/src/layout.c +++ b/src/layout.c @@ -12,7 +12,6 @@ void layout_arrange(struct absinthe_output *output) toplevels_count++; } - if (toplevels_count < 1) return; @@ -34,24 +33,47 @@ void layout_arrange(struct absinthe_output *output) } int32_t layout_gap = ABSINTHE_LAYOUT_GAP; - int32_t main_toplevel_width = ABSINTHE_MAIN_TOPLEVEL_WIDTH * (output->geometry.width - 2 * output_gap); - int32_t width, height; - width = output->geometry.width - main_toplevel_width - borders_width - layout_gap - 2 * output_gap; + int32_t main_stack_width = (toplevels_count <= ABSINTHE_MAIN_STACK_SIZE) + ? output->geometry.width - borders_width - 2 * output_gap + : ABSINTHE_MAIN_STACK_WIDTH * (output->geometry.width - 2 * output_gap); + int32_t width = output->geometry.width - main_stack_width - borders_width - layout_gap - 2 * output_gap; + int32_t height; int32_t dy = output_gap; size_t i = 0; + + if (toplevels_count <= ABSINTHE_MAIN_STACK_SIZE) { + wl_list_for_each(toplevel, &output->server->toplevels, link) { + if (toplevel->output != output) + continue; + + height = (output->geometry.height - dy - output_gap) / (ABSINTHE_MAIN_STACK_SIZE - i) - borders_width; + wlr_xdg_toplevel_set_size(toplevel->toplevel.xdg, main_stack_width, height); + toplevel->geometry.x = output->geometry.x + output_gap; + toplevel->geometry.y = output->geometry.y + dy; + dy += height + borders_width + layout_gap; + + i++; + } + return; + } + wl_list_for_each(toplevel, &output->server->toplevels, link) { if (toplevel->output != output) continue; - if (i == 0) { - height = output->geometry.height - borders_width - 2 * output_gap; - wlr_xdg_toplevel_set_size(toplevel->toplevel.xdg, main_toplevel_width, height); + + if (i < ABSINTHE_MAIN_STACK_SIZE) { + height = (output->geometry.height - dy - output_gap) / (ABSINTHE_MAIN_STACK_SIZE - i) - borders_width; + wlr_xdg_toplevel_set_size(toplevel->toplevel.xdg, main_stack_width, height); toplevel->geometry.x = output->geometry.x + output_gap; - toplevel->geometry.y = output->geometry.y + output_gap; + toplevel->geometry.y = output->geometry.y + dy; + dy += height + borders_width + layout_gap; } else { + if (i == ABSINTHE_MAIN_STACK_SIZE) + dy = output_gap; height = (output->geometry.height - dy - output_gap) / (toplevels_count - i) - borders_width; wlr_xdg_toplevel_set_size(toplevel->toplevel.xdg, width, height); - toplevel->geometry.x = output->geometry.x + main_toplevel_width + layout_gap + output_gap; + toplevel->geometry.x = output->geometry.x + main_stack_width + layout_gap + output_gap; toplevel->geometry.y = output->geometry.y + dy; dy += height + borders_width + layout_gap; }