feat: add layout center_tile

This commit is contained in:
DreamMaoMao 2025-09-26 21:30:45 +08:00
parent 698498ddf0
commit 5f380e2379
5 changed files with 122 additions and 17 deletions

View file

@ -51,6 +51,7 @@ https://github.com/user-attachments/assets/014c893f-115c-4ae9-8342-f9ae3e9a0df0
- dwindle
- spiral
- deck
- center_tile
## Vertical Layouts
- vertical_tile
@ -59,7 +60,6 @@ https://github.com/user-attachments/assets/014c893f-115c-4ae9-8342-f9ae3e9a0df0
- vertical_grid
- vertical_dwindle
- vertical_spiral
- vertical_deck
# Installation

View file

@ -123,8 +123,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

View file

@ -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;

View file

@ -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"},

View file

@ -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);
}