去掉奇怪的布局切换机制

This commit is contained in:
DreamMaoMao 2025-02-17 08:34:54 +08:00
parent 8939afab26
commit 2dfc4fda11

106
maomao.c
View file

@ -297,13 +297,11 @@ struct Monitor {
struct wlr_box m; /* monitor area, layout-relative */ struct wlr_box m; /* monitor area, layout-relative */
struct wlr_box w; /* window area, layout-relative */ struct wlr_box w; /* window area, layout-relative */
struct wl_list layers[4]; /* LayerSurface::link */ struct wl_list layers[4]; /* LayerSurface::link */
const Layout *lt[2]; const Layout *lt;
unsigned int seltags; unsigned int seltags;
unsigned int sellt;
uint32_t tagset[2]; uint32_t tagset[2];
double mfact; double mfact;
int nmaster; int nmaster;
char ltsymbol[16];
struct wl_list dwl_ipc_outputs; struct wl_list dwl_ipc_outputs;
int gappih; /* horizontal gap between windows */ int gappih; /* horizontal gap between windows */
@ -656,9 +654,8 @@ struct Pertag {
unsigned int curtag, prevtag; /* current and previous tag */ unsigned int curtag, prevtag; /* current and previous tag */
int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */ int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */ float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
const Layout const Layout
*ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes */ *ltidxs[LENGTH(tags) + 1]; /* matrix of tags and layouts indexes */
}; };
static pid_t *autostart_pids; static pid_t *autostart_pids;
@ -1266,8 +1263,8 @@ arrange(Monitor *m, bool want_animation) {
if (m->isoverview) { if (m->isoverview) {
overviewlayout.arrange(m, 0, 0); overviewlayout.arrange(m, 0, 0);
} else if (m && m->lt[m->sellt]->arrange) { } else if (m && m->pertag->ltidxs[m->pertag->curtag]->arrange) {
m->lt[m->sellt]->arrange(m, gappoh, 0); m->pertag->ltidxs[m->pertag->curtag]->arrange(m, gappoh, 0);
} }
#ifdef IM #ifdef IM
@ -2026,12 +2023,8 @@ createmon(struct wl_listener *listener, void *data) {
m->nmaster = default_nmaster; m->nmaster = default_nmaster;
enum wl_output_transform rr = WL_OUTPUT_TRANSFORM_NORMAL; enum wl_output_transform rr = WL_OUTPUT_TRANSFORM_NORMAL;
if (LENGTH(layouts) > 1) { m->lt = &layouts[0];
m->lt[0] = &layouts[0]; // 默认就有两个布局
m->lt[1] = &layouts[1];
} else {
m->lt[0] = m->lt[1] = &layouts[0];
}
for (ji = 0; ji < config.monitor_rules_count; ji++) { for (ji = 0; ji < config.monitor_rules_count; ji++) {
r = &config.monitor_rules[ji]; r = &config.monitor_rules[ji];
if (!r->name || strstr(wlr_output->name, r->name)) { if (!r->name || strstr(wlr_output->name, r->name)) {
@ -2042,7 +2035,7 @@ createmon(struct wl_listener *listener, void *data) {
if (r->layout) { if (r->layout) {
for (jk = 0; jk < LENGTH(layouts); jk++) { for (jk = 0; jk < LENGTH(layouts); jk++) {
if(strcmp(layouts[jk].name , r->layout) == 0) { if(strcmp(layouts[jk].name , r->layout) == 0) {
m->lt[0] = m->lt[1] = &layouts[jk]; m->lt = &layouts[jk];
} }
} }
} }
@ -2076,7 +2069,6 @@ createmon(struct wl_listener *listener, void *data) {
wlr_output_commit(wlr_output); wlr_output_commit(wlr_output);
wl_list_insert(&mons, &m->link); wl_list_insert(&mons, &m->link);
printstatus();
m->pertag = calloc(1, sizeof(Pertag)); m->pertag = calloc(1, sizeof(Pertag));
m->pertag->curtag = m->pertag->prevtag = 1; m->pertag->curtag = m->pertag->prevtag = 1;
@ -2085,11 +2077,12 @@ createmon(struct wl_listener *listener, void *data) {
m->pertag->nmasters[i] = m->nmaster; m->pertag->nmasters[i] = m->nmaster;
m->pertag->mfacts[i] = m->mfact; m->pertag->mfacts[i] = m->mfact;
m->pertag->ltidxs[i][0] = m->lt[0]; m->pertag->ltidxs[i] = m->lt;
m->pertag->ltidxs[i][1] = m->lt[1];
m->pertag->sellts[i] = m->sellt;
} }
printstatus();
/* The xdg-protocol specifies: /* The xdg-protocol specifies:
* *
* If the fullscreened surface is not opaque, the compositor must make * If the fullscreened surface is not opaque, the compositor must make
@ -2113,7 +2106,6 @@ createmon(struct wl_listener *listener, void *data) {
wlr_output_layout_add_auto(output_layout, wlr_output); wlr_output_layout_add_auto(output_layout, wlr_output);
else else
wlr_output_layout_add(output_layout, wlr_output, m->m.x, m->m.y); wlr_output_layout_add(output_layout, wlr_output, m->m.x, m->m.y);
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
} }
void // fix for 0.5 void // fix for 0.5
@ -2535,10 +2527,10 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
title = focused ? client_get_title(focused) : ""; title = focused ? client_get_title(focused) : "";
appid = focused ? client_get_appid(focused) : ""; appid = focused ? client_get_appid(focused) : "";
symbol = symbol =
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt]->symbol; monitor->pertag->ltidxs[monitor->pertag->curtag]->symbol;
zdwl_ipc_output_v2_send_layout(ipc_output->resource, zdwl_ipc_output_v2_send_layout(ipc_output->resource,
monitor->lt[monitor->sellt] - layouts); monitor->pertag->ltidxs[monitor->pertag->curtag] - layouts);
zdwl_ipc_output_v2_send_title(ipc_output->resource, title ? title : broken); zdwl_ipc_output_v2_send_title(ipc_output->resource, title ? title : broken);
zdwl_ipc_output_v2_send_appid(ipc_output->resource, appid ? appid : broken); zdwl_ipc_output_v2_send_appid(ipc_output->resource, appid ? appid : broken);
zdwl_ipc_output_v2_send_layout_symbol(ipc_output->resource, symbol); zdwl_ipc_output_v2_send_layout_symbol(ipc_output->resource, symbol);
@ -2583,11 +2575,9 @@ void dwl_ipc_output_set_layout(struct wl_client *client,
monitor = ipc_output->monitor; monitor = ipc_output->monitor;
if (index >= LENGTH(layouts)) if (index >= LENGTH(layouts))
return; index = 0;
if (index != monitor->lt[monitor->sellt] - layouts)
monitor->sellt ^= 1; monitor->pertag->ltidxs[monitor->pertag->curtag] = &layouts[index];
monitor->lt[monitor->sellt] = &layouts[index];
arrange(monitor, false); arrange(monitor, false);
printstatus(); printstatus();
} }
@ -2655,7 +2645,7 @@ void focusclient(Client *c, int lift) {
if (selmon) { if (selmon) {
selmon->prevsel = selmon->sel; selmon->prevsel = selmon->sel;
selmon->sel = c; selmon->sel = c;
if (c && selmon->prevsel && selmon->prevsel->istiled && selmon->prevsel->tags == c->tags && c->istiled && !c->isfloating && !c->isfullscreen && strcmp(selmon->lt[selmon->sellt]->name , "scroller") == 0) { if (c && selmon->prevsel && selmon->prevsel->istiled && selmon->prevsel->tags == c->tags && c->istiled && !c->isfloating && !c->isfullscreen && strcmp(selmon->pertag->ltidxs[selmon->pertag->curtag]->name , "scroller") == 0) {
arrange(selmon,false); arrange(selmon,false);
} else if (selmon->prevsel) { } else if (selmon->prevsel) {
selmon->prevsel =NULL; selmon->prevsel =NULL;
@ -3098,10 +3088,10 @@ mapnotify(struct wl_listener *listener, void *data) {
c->scroller_proportion = scroller_default_proportion; c->scroller_proportion = scroller_default_proportion;
c->is_open_animation = true; c->is_open_animation = true;
// nop // nop
if (new_is_master && strcmp(selmon->lt[selmon->sellt]->name , "scroller") != 0) if (new_is_master && strcmp(selmon->pertag->ltidxs[selmon->pertag->curtag]->name , "scroller") != 0)
// tile at the top // tile at the top
wl_list_insert(&clients, &c->link); // 新窗口是master,头部入栈 wl_list_insert(&clients, &c->link); // 新窗口是master,头部入栈
else if (strcmp(selmon->lt[selmon->sellt]->name , "scroller") == 0 && selmon->sel && selmon->sel->istiled) { else if (strcmp(selmon->pertag->ltidxs[selmon->pertag->curtag]->name , "scroller") == 0 && selmon->sel && selmon->sel->istiled) {
selmon->sel->link.next->prev = &c->link; selmon->sel->link.next->prev = &c->link;
c->link.prev = &selmon->sel->link; c->link.prev = &selmon->sel->link;
c->link.next = selmon->sel->link.next; c->link.next = selmon->sel->link.next;
@ -3239,8 +3229,6 @@ monocle(Monitor *m) {
resize(c, m->w, 0); resize(c, m->w, 0);
n++; n++;
} }
if (n)
snprintf(m->ltsymbol, LENGTH(m->ltsymbol), "[%d]", n);
if ((c = focustop(m))) if ((c = focustop(m)))
wlr_scene_node_raise_to_top(&c->scene->node); wlr_scene_node_raise_to_top(&c->scene->node);
} }
@ -3553,7 +3541,7 @@ printstatus(void) {
printf("%s selmon %u\n", m->wlr_output->name, m == selmon); printf("%s selmon %u\n", m->wlr_output->name, m == selmon);
printf("%s tags %u %u %u %u\n", m->wlr_output->name, occ, printf("%s tags %u %u %u %u\n", m->wlr_output->name, occ,
m->tagset[m->seltags], sel, urg); m->tagset[m->seltags], sel, urg);
printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol); printf("%s layout %s\n", m->wlr_output->name, m->pertag->ltidxs[m->pertag->curtag]->symbol);
dwl_ipc_output_printstatus(m); // 更新waybar上tag的状态 这里很关键 dwl_ipc_output_printstatus(m); // 更新waybar上tag的状态 这里很关键
} }
fflush(stdout); fflush(stdout);
@ -3779,7 +3767,7 @@ int is_special_animaiton_rule(Client *c) {
} }
} }
if (strcmp(selmon->lt[selmon->sellt]->name , "scroller") == 0 && !c->isfloating) { if (strcmp(selmon->pertag->ltidxs[selmon->pertag->curtag]->name , "scroller") == 0 && !c->isfloating) {
return DOWN; return DOWN;
} else if (visible_client_number < 2 && !c->isfloating) { } else if (visible_client_number < 2 && !c->isfloating) {
return DOWN; return DOWN;
@ -3872,7 +3860,7 @@ void resize(Client *c, struct wlr_box geo, int interact) {
// oldgeom = c->geom; // oldgeom = c->geom;
bbox = interact ? &sgeom : &c->mon->w; bbox = interact ? &sgeom : &c->mon->w;
if(strcmp(c->mon->lt[c->mon->sellt]->name , "scroller") == 0) { if(strcmp(c->mon->pertag->ltidxs[c->mon->pertag->curtag]->name , "scroller") == 0) {
c->geom = geo; c->geom = geo;
} else { // 这里会限制不允许窗口划出屏幕 } else { // 这里会限制不允许窗口划出屏幕
client_set_bounds( client_set_bounds(
@ -4146,13 +4134,8 @@ setlayout(const Arg *arg) {
int jk; int jk;
for (jk = 0; jk < LENGTH(layouts); jk++) { for (jk = 0; jk < LENGTH(layouts); jk++) {
if(strcmp(layouts[jk].name , arg->v) == 0) { if(strcmp(layouts[jk].name , arg->v) == 0) {
selmon->lt[selmon->sellt] = &layouts[jk]; selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[jk];
selmon->pertag->sellts[selmon->pertag->curtag] = selmon->sellt;
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] =
selmon->lt[selmon->sellt];
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol,
LENGTH(selmon->ltsymbol));
arrange(selmon, false); arrange(selmon, false);
printstatus(); printstatus();
return; return;
@ -4164,9 +4147,8 @@ void switch_layout(const Arg *arg) {
int jk; int jk;
for (jk = 0; jk < LENGTH(layouts); jk++) { for (jk = 0; jk < LENGTH(layouts); jk++) {
if(strcmp(layouts[jk].name , selmon->lt[selmon->sellt]->name)) { if(strcmp(layouts[jk].name , selmon->pertag->ltidxs[selmon->pertag->curtag]->name) == 0) {
selmon->lt[selmon->sellt] = &layouts[jk]; selmon->pertag->ltidxs[selmon->pertag->curtag] = jk == LENGTH(layouts) - 1? &layouts[0] : &layouts[jk+1];
selmon->pertag->sellts[selmon->pertag->curtag] = selmon->sellt;
arrange(selmon, false); arrange(selmon, false);
printstatus(); printstatus();
return; return;
@ -4182,7 +4164,7 @@ void // 17
setmfact(const Arg *arg) { setmfact(const Arg *arg) {
float f; float f;
if (!arg || !selmon || !selmon->lt[selmon->sellt]->arrange) if (!arg || !selmon || !selmon->pertag->ltidxs[selmon->pertag->curtag]->arrange)
return; return;
f = arg->f < 1.0 ? arg->f + selmon->pertag->mfacts[selmon->pertag->curtag] f = arg->f < 1.0 ? arg->f + selmon->pertag->mfacts[selmon->pertag->curtag]
: arg->f - 1.0; : arg->f - 1.0;
@ -5597,12 +5579,6 @@ void view(const Arg *arg, bool want_animation) {
selmon->pertag->curtag = tmptag; selmon->pertag->curtag = tmptag;
} }
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
selmon->lt[selmon->sellt] =
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
selmon->lt[selmon->sellt ^ 1] =
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt ^ 1];
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(selmon, want_animation); arrange(selmon, want_animation);
printstatus(); printstatus();
@ -5635,12 +5611,6 @@ void viewtoleft(const Arg *arg) {
selmon->pertag->curtag = tmptag; selmon->pertag->curtag = tmptag;
} }
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
selmon->lt[selmon->sellt] =
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
selmon->lt[selmon->sellt ^ 1] =
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt ^ 1];
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(selmon, true); arrange(selmon, true);
printstatus(); printstatus();
@ -5686,12 +5656,6 @@ void viewtoright_have_client(const Arg *arg) {
selmon->pertag->curtag = tmptag; selmon->pertag->curtag = tmptag;
} }
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
selmon->lt[selmon->sellt] =
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
selmon->lt[selmon->sellt ^ 1] =
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt ^ 1];
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(selmon, true); arrange(selmon, true);
printstatus(); printstatus();
@ -5721,12 +5685,6 @@ void viewtoright(const Arg *arg) {
selmon->pertag->curtag = tmptag; selmon->pertag->curtag = tmptag;
} }
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
selmon->lt[selmon->sellt] =
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
selmon->lt[selmon->sellt ^ 1] =
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt ^ 1];
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(selmon, true); arrange(selmon, true);
printstatus(); printstatus();
@ -5772,12 +5730,6 @@ void viewtoleft_have_client(const Arg *arg) {
selmon->pertag->curtag = tmptag; selmon->pertag->curtag = tmptag;
} }
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
selmon->lt[selmon->sellt] =
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
selmon->lt[selmon->sellt ^ 1] =
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt ^ 1];
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(selmon, true); arrange(selmon, true);
printstatus(); printstatus();
@ -5885,7 +5837,7 @@ void toggleglobal(const Arg *arg) {
void zoom(const Arg *arg) { void zoom(const Arg *arg) {
Client *c, *sel = focustop(selmon); Client *c, *sel = focustop(selmon);
if (!sel || !selmon || !selmon->lt[selmon->sellt]->arrange || sel->isfloating) if (!sel || !selmon || !selmon->pertag->ltidxs[selmon->pertag->curtag]->arrange || sel->isfloating)
return; return;
/* Search for the first tiled window that is not sel, marking sel as /* Search for the first tiled window that is not sel, marking sel as
@ -5958,7 +5910,7 @@ configurex11(struct wl_listener *listener, void *data) {
event->width, event->height); event->width, event->height);
return; return;
} }
if ((c->isfloating && c != grabc) || !c->mon->lt[c->mon->sellt]->arrange) if ((c->isfloating && c != grabc) || !c->mon->pertag->ltidxs[c->mon->pertag->curtag]->arrange)
resize(c, resize(c,
(struct wlr_box){.x = event->x - c->bw, (struct wlr_box){.x = event->x - c->bw,
.y = event->y - c->bw, .y = event->y - c->bw,