From c681f948fd620d79c44ac1e3a7e466eb6b4f8eb0 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Fri, 26 Sep 2025 21:30:45 +0800 Subject: [PATCH] feat: add layout center_tile --- README.md | 2 +- config.conf | 4 +- src/layout/horizontal.h | 117 ++++++++++++++++++++++++++++++++++++++++ src/layout/layout.h | 4 +- src/layout/vertical.h | 12 ----- 5 files changed, 122 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 53d7aeb..5851584 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ https://github.com/user-attachments/assets/c9bf9415-fad1-4400-bcdc-3ad2d76de85a - dwindle - spiral - deck +- center_tile ## Vertical Layouts - vertical_tile @@ -54,7 +55,6 @@ https://github.com/user-attachments/assets/c9bf9415-fad1-4400-bcdc-3ad2d76de85a - vertical_grid - vertical_dwindle - vertical_spiral -- vertical_deck # Installation diff --git a/config.conf b/config.conf index 6295794..3a94d2f 100644 --- a/config.conf +++ b/config.conf @@ -102,8 +102,8 @@ globalcolor=0xb153a7ff overlaycolor=0x14a57cff # layout support: -# horizontal:tile,scroller,grid,monocle,spiral,dwindle -# vertical:vertical_tile,vertical_scroller,vertical_grid,vertical_monocle,vertical_spiral,vertical_dwindle +# horizontal:tile,scroller,grid,monocle,spiral,dwindle,center_tile +# vertical:vertical_tile,vertical_scroller,vertical_grid,vertical_spiral,vertical_dwindle tagrule=id:1,layout_name:tile tagrule=id:2,layout_name:tile tagrule=id:3,layout_name:tile diff --git a/src/layout/horizontal.h b/src/layout/horizontal.h index 0334c48..491f45e 100644 --- a/src/layout/horizontal.h +++ b/src/layout/horizontal.h @@ -432,6 +432,123 @@ void scroller(Monitor *m) { free(tempClients); // 最后释放内存 } +void center_tile(Monitor *m) { + unsigned int i, n = 0, h, mw, mx, my, oty, ety, tw; + Client *c; + + n = m->visible_tiling_clients; + if (n == 0) + return; + + // 间隙参数处理 + unsigned int gappiv = enablegaps ? m->gappiv : 0; // 内部垂直间隙 + unsigned int gappih = enablegaps ? m->gappih : 0; // 内部水平间隙 + unsigned int gappov = enablegaps ? m->gappov : 0; // 外部垂直间隙 + unsigned int gappoh = enablegaps ? m->gappoh : 0; // 外部水平间隙 + + // 智能间隙处理 + if (smartgaps && n == 1) { + gappiv = gappih = gappov = gappoh = 0; + } + + unsigned int nmasters = m->pertag->nmasters[m->pertag->curtag]; + float mfact = m->pertag->mfacts[m->pertag->curtag]; + + // 初始化区域 + mw = m->w.width; + mx = gappoh; + my = gappov; + tw = mw; + + if (n > nmasters) { + // 计算主区域宽度 + mw = nmasters ? (m->w.width - 2 * gappoh - gappih) * mfact : 0; + + if (n - nmasters > 1) { + // 多个堆叠窗口:主区域居中,左右两侧各有一个堆叠区域 + tw = (m->w.width - mw - 2 * gappoh - gappih) / 2; + mx = gappoh + tw + gappih; + } else { + // 单个堆叠窗口:主区域居中,堆叠窗口在左,右边空着 + tw = (m->w.width - mw - 2 * gappoh - gappih) / 2; + mx = gappoh + tw + gappih; + } + } else { + // 所有窗口都在主区域 + mw = m->w.width - 2 * gappoh; + mx = gappoh; + } + + oty = gappov; + ety = gappov; + + i = 0; + wl_list_for_each(c, &clients, link) { + if (!VISIBLEON(c, m) || !ISTILED(c)) + continue; + + if (i < nmasters) { + // 主区域窗口 + unsigned int r = MIN(n, nmasters) - i; + h = (m->w.height - my - gappov - gappiv * (r - 1)) / r; + + resize(c, + (struct wlr_box){.x = m->w.x + mx, + .y = m->w.y + my, + .width = mw, + .height = h}, + 0); + my += c->geom.height + gappiv; + } else { + // 堆叠区域窗口 + unsigned int stack_index = i - nmasters; + + if (n - nmasters == 1) { + // 单个堆叠窗口:放在左侧 + unsigned int r = n - i; + h = (m->w.height - ety - gappov - gappiv * (r - 1)) / r; + + int stack_x = m->w.x + gappoh; // 左侧位置 + resize(c, + (struct wlr_box){.x = stack_x, + .y = m->w.y + ety, + .width = tw, + .height = h}, + 0); + ety += c->geom.height + gappiv; + } else { + // 多个堆叠窗口:交替放在左右两侧 + unsigned int r = (n - i + 1) / 2; + + if (stack_index % 2) { + // 右侧堆叠窗口 + h = (m->w.height - ety - gappov - gappiv * (r - 1)) / r; + int stack_x = m->w.x + mx + mw + gappih; + resize(c, + (struct wlr_box){.x = stack_x, + .y = m->w.y + ety, + .width = tw, + .height = h}, + 0); + ety += c->geom.height + gappiv; + } else { + // 左侧堆叠窗口 + h = (m->w.height - oty - gappov - gappiv * (r - 1)) / r; + int stack_x = m->w.x + gappoh; + resize(c, + (struct wlr_box){.x = stack_x, + .y = m->w.y + oty, + .width = tw, + .height = h}, + 0); + oty += c->geom.height + gappiv; + } + } + } + i++; + } +} + void tile(Monitor *m) { unsigned int i, n = 0, h, r, ie = enablegaps, mw, my, ty; Client *c; diff --git a/src/layout/layout.h b/src/layout/layout.h index 05190cf..f140e7b 100644 --- a/src/layout/layout.h +++ b/src/layout/layout.h @@ -1,4 +1,5 @@ static void tile(Monitor *m); +static void center_tile(Monitor *m); static void overview(Monitor *m); static void grid(Monitor *m); static void scroller(Monitor *m); @@ -13,7 +14,6 @@ static void vertical_scroller(Monitor *m); static void vertical_deck(Monitor *mon); static void vertical_dwindle(Monitor *mon); static void vertical_spiral(Monitor *mon); -static void vertical_monocle(Monitor *m); /* layout(s) */ Layout overviewlayout = {"󰃇", overview, "overview"}; @@ -28,9 +28,9 @@ Layout layouts[] = { {"D", dwindle, "dwindle"}, {"P", spiral, "spiral"}, {"K", deck, "deck"}, + {"CT", center_tile, "center_tile"}, {"VS", vertical_scroller, "vertical_scroller"}, {"VT", vertical_tile, "vertical_tile"}, - {"VM", vertical_monocle, "vertical_monocle"}, {"VD", vertical_dwindle, "vertical_dwindle"}, {"VP", vertical_spiral, "vertical_spiral"}, {"VG", vertical_grid, "vertical_grid"}, diff --git a/src/layout/vertical.h b/src/layout/vertical.h index 96d0005..c6d7226 100644 --- a/src/layout/vertical.h +++ b/src/layout/vertical.h @@ -474,16 +474,4 @@ void vertical_tile(Monitor *m) { } i++; } -} - -void vertical_monocle(Monitor *m) { - Client *c; - - wl_list_for_each(c, &clients, link) { - if (!VISIBLEON(c, m) || !ISTILED(c)) - continue; - resize(c, m->w, 0); - } - if ((c = focustop(m))) - wlr_scene_node_raise_to_top(&c->scene->node); } \ No newline at end of file