From 2653237be8f78c3bb52ec33a66883ae0ca1051d3 Mon Sep 17 00:00:00 2001 From: speckitor Date: Tue, 12 May 2026 13:19:16 +0700 Subject: [PATCH] tileleft --- include/config.h | 1 + include/types.h | 2 +- src/layout.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 1 deletion(-) diff --git a/include/config.h b/include/config.h index 9cc8414..ad3582f 100644 --- a/include/config.h +++ b/include/config.h @@ -58,6 +58,7 @@ static const absn_keybind keybinds[] = { { ALT | SHIFT, XKB_KEY_l, increase_master_width, { .f = +0.05 } }, { ALT, XKB_KEY_t, set_layout, { .i = LAYOUT_TILE } }, + { ALT, XKB_KEY_r, set_layout, { .i = LAYOUT_TILELEFT } }, { ALT, XKB_KEY_m, set_layout, { .i = LAYOUT_MONOCLE } }, { ALT, XKB_KEY_1, switch_workspace, { .v = "1" } }, diff --git a/include/types.h b/include/types.h index afa8e4e..ccad1ef 100644 --- a/include/types.h +++ b/include/types.h @@ -79,10 +79,10 @@ static const int layermap[] = { enum { LAYOUT_TILE, - LAYOUT_MONOCLE, LAYOUT_TILELEFT, LAYOUT_TILETOP, LAYOUT_TILEBOTTOM, + LAYOUT_MONOCLE, LAYOUT_SPIRAL, LAYOUT_DWINDLE, LAYOUT_VGRID, diff --git a/src/layout.c b/src/layout.c index 11b63c5..630161a 100644 --- a/src/layout.c +++ b/src/layout.c @@ -151,6 +151,129 @@ tile(struct absn_output *output) } } +static void +tile_left(struct absn_output *output) +{ + int toplevels_count = prepare_output(output); + + if (toplevels_count < 1) + return; + + int32_t og = OUTPUT_GAP; + struct wlr_box new_geom; + + absn_toplevel *toplevel; + if (toplevels_count == 1) { + wl_list_for_each(toplevel, &output->server->toplevels, link) + { + if (toplevel->workspace == output->workspace && + !toplevel->floating && !toplevel->fullscreen) + break; + } + new_geom.x = output->geom.x + og, + new_geom.y = output->geom.y + og, + new_geom.width = output->geom.width - 2 * og, + new_geom.height = output->geom.height - 2 * og, + + toplevel_set_geom(toplevel, &new_geom); + return; + } + + int32_t lg = LAYOUT_GAP; + int32_t total_lg; + + int mcount = output->workspace->count; + float msize = output->workspace->size; + + int32_t main_stack_width = (toplevels_count <= mcount) ? + output->geom.width - 2 * og : + msize * (output->geom.width - 2 * og); + int32_t w = output->geom.width - main_stack_width - 2 * og - lg; + + int32_t pure_h; + int32_t h; + int32_t cur_h; + int32_t r; + + int32_t dy = og; + int i = 0; + + if (toplevels_count <= mcount) { + total_lg = (toplevels_count - 1) * lg; + pure_h = output->geom.height - 2 * og - total_lg; + h = pure_h / toplevels_count; + r = pure_h % toplevels_count; + + wl_list_for_each(toplevel, &output->server->toplevels, link) + { + if (toplevel->workspace != output->workspace || + toplevel->floating || toplevel->fullscreen) + continue; + + cur_h = h + (i < r ? 1 : 0); + + new_geom.x = output->geom.x + og; + new_geom.y = output->geom.y + dy; + new_geom.width = main_stack_width; + new_geom.height = cur_h; + + toplevel_set_geom(toplevel, &new_geom); + + dy += cur_h + lg; + + i++; + } + return; + } + + wl_list_for_each(toplevel, &output->server->toplevels, link) + { + if (toplevel->workspace != output->workspace || + toplevel->floating || toplevel->fullscreen) + continue; + + if (i < mcount) { + total_lg = (mcount - 1) * lg; + pure_h = output->geom.height - 2 * og - total_lg; + h = pure_h / mcount; + r = pure_h % mcount; + + cur_h = h + (i < r ? 1 : 0); + + new_geom.x = output->geom.width - og - main_stack_width; + new_geom.y = output->geom.y + dy; + new_geom.width = main_stack_width; + new_geom.height = cur_h; + + toplevel_set_geom(toplevel, &new_geom); + + dy += cur_h + lg; + } else { + if (i == mcount) + dy = og; + + int32_t stack_count = toplevels_count - mcount; + total_lg = (stack_count - 1) * lg; + pure_h = output->geom.height - 2 * og - total_lg; + h = pure_h / stack_count; + r = pure_h % stack_count; + + cur_h = h + (i - mcount < r ? 1 : 0); + + new_geom.x = output->geom.x + og; + new_geom.y = output->geom.y + dy; + new_geom.width = w; + new_geom.height = cur_h; + + toplevel_set_geom(toplevel, &new_geom); + + dy += cur_h + lg; + } + + i++; + } +} + static void monocle(struct absn_output *output) { @@ -189,6 +312,9 @@ layout_arrange(struct absn_output *output) case LAYOUT_TILE: tile(output); break; + case LAYOUT_TILELEFT: + tile_left(output); + break; case LAYOUT_MONOCLE: monocle(output); break;