From 27183b8d491135575e1a29a5439b83f49b066f8c Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sat, 11 Oct 2025 16:27:54 +0800 Subject: [PATCH] opt: add back vertical grid layout --- README.md | 1 + src/layout/layout.h | 2 + src/layout/vertical.h | 116 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) diff --git a/README.md b/README.md index f955544..2e8d3a5 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ https://github.com/user-attachments/assets/c9bf9415-fad1-4400-bcdc-3ad2d76de85a - deck - center_tile - vertical_tile +- vertical_grid - vertical_scroller # Installation diff --git a/src/layout/layout.h b/src/layout/layout.h index a0c9bd2..de65aa9 100644 --- a/src/layout/layout.h +++ b/src/layout/layout.h @@ -23,6 +23,7 @@ enum { CENTER_TILE, VERTICAL_SCROLLER, VERTICAL_TILE, + VERTICAL_GRID, }; Layout layouts[] = { @@ -37,4 +38,5 @@ Layout layouts[] = { {"VS", vertical_scroller, "vertical_scroller", VERTICAL_SCROLLER}, // 垂直滚动布局 {"VT", vertical_tile, "vertical_tile", VERTICAL_TILE}, // 垂直平铺布局 + {"VG", vertical_grid, "vertical_grid", VERTICAL_GRID}, // 垂直格子布局 }; \ No newline at end of file diff --git a/src/layout/vertical.h b/src/layout/vertical.h index 17e48a7..bae3c11 100644 --- a/src/layout/vertical.h +++ b/src/layout/vertical.h @@ -217,3 +217,119 @@ void vertical_scroller(Monitor *m) { free(tempClients); } + +void vertical_grid(Monitor *m) { + unsigned int i, n; + unsigned int cx, cy, cw, ch; + unsigned int dy; + unsigned int rows, cols, overrows; + Client *c = NULL; + + n = m->isoverview ? m->visible_clients : m->visible_tiling_clients; + + if (n == 0) { + return; + } + + if (n == 1) { + wl_list_for_each(c, &clients, link) { + + if (c->mon != m) + continue; + + c->bw = m->visible_tiling_clients == 1 && no_border_when_single && + smartgaps + ? 0 + : borderpx; + if (VISIBLEON(c, m) && !c->isunglobal && + ((m->isoverview && !client_should_ignore_focus(c)) || + ISTILED(c))) { + ch = (m->w.height - 2 * overviewgappo) * 0.7; + cw = (m->w.width - 2 * overviewgappo) * 0.8; + c->geom.x = m->w.x + (m->w.width - cw) / 2; + c->geom.y = m->w.y + (m->w.height - ch) / 2; + c->geom.width = cw - 2 * c->bw; + c->geom.height = ch - 2 * c->bw; + resize(c, c->geom, 0); + return; + } + } + } + + if (n == 2) { + ch = (m->w.height - 2 * overviewgappo - overviewgappi) / 2; + cw = (m->w.width - 2 * overviewgappo) * 0.65; + i = 0; + wl_list_for_each(c, &clients, link) { + + if (c->mon != m) + continue; + + c->bw = m->visible_tiling_clients == 1 && no_border_when_single && + smartgaps + ? 0 + : borderpx; + if (VISIBLEON(c, m) && !c->isunglobal && + ((m->isoverview && !client_should_ignore_focus(c)) || + ISTILED(c))) { + if (i == 0) { + c->geom.x = m->w.x + (m->w.width - cw) / 2 + overviewgappo; + c->geom.y = m->w.y + overviewgappo; + c->geom.width = cw - 2 * c->bw; + c->geom.height = ch - 2 * c->bw; + resize(c, c->geom, 0); + } else if (i == 1) { + c->geom.x = m->w.x + (m->w.width - cw) / 2 + overviewgappo; + c->geom.y = m->w.y + ch + overviewgappo + overviewgappi; + c->geom.width = cw - 2 * c->bw; + c->geom.height = ch - 2 * c->bw; + resize(c, c->geom, 0); + } + i++; + } + } + return; + } + + for (rows = 0; rows <= n / 2; rows++) { + if (rows * rows >= n) { + break; + } + } + cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows; + + cw = (m->w.width - 2 * overviewgappo - (cols - 1) * overviewgappi) / cols; + ch = (m->w.height - 2 * overviewgappo - (rows - 1) * overviewgappi) / rows; + + overrows = n % rows; + if (overrows) { + dy = + (m->w.height - overrows * ch - (overrows - 1) * overviewgappi) / 2 - + overviewgappo; + } + + i = 0; + wl_list_for_each(c, &clients, link) { + if (c->mon != m) + continue; + + c->bw = + m->visible_tiling_clients == 1 && no_border_when_single && smartgaps + ? 0 + : borderpx; + if (VISIBLEON(c, m) && !c->isunglobal && + ((m->isoverview && !client_should_ignore_focus(c)) || ISTILED(c))) { + cx = m->w.x + (i / rows) * (cw + overviewgappi); + cy = m->w.y + (i % rows) * (ch + overviewgappi); + if (overrows && i >= n - overrows) { + cy += dy; + } + c->geom.x = cx + overviewgappo; + c->geom.y = cy + overviewgappo; + c->geom.width = cw - 2 * c->bw; + c->geom.height = ch - 2 * c->bw; + resize(c, c->geom, 0); + i++; + } + } +} \ No newline at end of file