From 2dfc4fda11c8988666c2e2f29b0daf7b7b8169f3 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Mon, 17 Feb 2025 08:34:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=A5=87=E6=80=AA=E7=9A=84?= =?UTF-8?q?=E5=B8=83=E5=B1=80=E5=88=87=E6=8D=A2=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maomao.c | 106 +++++++++++++++---------------------------------------- 1 file changed, 29 insertions(+), 77 deletions(-) diff --git a/maomao.c b/maomao.c index 9be94157..f5ffed28 100644 --- a/maomao.c +++ b/maomao.c @@ -297,13 +297,11 @@ struct Monitor { struct wlr_box m; /* monitor area, layout-relative */ struct wlr_box w; /* window area, layout-relative */ struct wl_list layers[4]; /* LayerSurface::link */ - const Layout *lt[2]; + const Layout *lt; unsigned int seltags; - unsigned int sellt; uint32_t tagset[2]; double mfact; int nmaster; - char ltsymbol[16]; struct wl_list dwl_ipc_outputs; int gappih; /* horizontal gap between windows */ @@ -656,9 +654,8 @@ struct Pertag { unsigned int curtag, prevtag; /* current and previous tag */ int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */ float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */ - unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */ 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; @@ -1266,8 +1263,8 @@ arrange(Monitor *m, bool want_animation) { if (m->isoverview) { overviewlayout.arrange(m, 0, 0); - } else if (m && m->lt[m->sellt]->arrange) { - m->lt[m->sellt]->arrange(m, gappoh, 0); + } else if (m && m->pertag->ltidxs[m->pertag->curtag]->arrange) { + m->pertag->ltidxs[m->pertag->curtag]->arrange(m, gappoh, 0); } #ifdef IM @@ -2026,12 +2023,8 @@ createmon(struct wl_listener *listener, void *data) { m->nmaster = default_nmaster; enum wl_output_transform rr = WL_OUTPUT_TRANSFORM_NORMAL; - if (LENGTH(layouts) > 1) { - m->lt[0] = &layouts[0]; // 默认就有两个布局 - m->lt[1] = &layouts[1]; - } else { - m->lt[0] = m->lt[1] = &layouts[0]; - } + m->lt = &layouts[0]; + for (ji = 0; ji < config.monitor_rules_count; ji++) { r = &config.monitor_rules[ji]; if (!r->name || strstr(wlr_output->name, r->name)) { @@ -2042,7 +2035,7 @@ createmon(struct wl_listener *listener, void *data) { if (r->layout) { for (jk = 0; jk < LENGTH(layouts); jk++) { 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); wl_list_insert(&mons, &m->link); - printstatus(); m->pertag = calloc(1, sizeof(Pertag)); 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->mfacts[i] = m->mfact; - m->pertag->ltidxs[i][0] = m->lt[0]; - m->pertag->ltidxs[i][1] = m->lt[1]; - m->pertag->sellts[i] = m->sellt; + m->pertag->ltidxs[i] = m->lt; } + printstatus(); + + /* The xdg-protocol specifies: * * 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); else 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 @@ -2535,10 +2527,10 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) { title = focused ? client_get_title(focused) : ""; appid = focused ? client_get_appid(focused) : ""; 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, - 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_appid(ipc_output->resource, appid ? appid : broken); 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; if (index >= LENGTH(layouts)) - return; - if (index != monitor->lt[monitor->sellt] - layouts) - monitor->sellt ^= 1; - - monitor->lt[monitor->sellt] = &layouts[index]; + index = 0; + + monitor->pertag->ltidxs[monitor->pertag->curtag] = &layouts[index]; arrange(monitor, false); printstatus(); } @@ -2655,7 +2645,7 @@ void focusclient(Client *c, int lift) { if (selmon) { selmon->prevsel = selmon->sel; 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); } else if (selmon->prevsel) { selmon->prevsel =NULL; @@ -3098,10 +3088,10 @@ mapnotify(struct wl_listener *listener, void *data) { c->scroller_proportion = scroller_default_proportion; c->is_open_animation = true; // 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 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; c->link.prev = &selmon->sel->link; c->link.next = selmon->sel->link.next; @@ -3239,8 +3229,6 @@ monocle(Monitor *m) { resize(c, m->w, 0); n++; } - if (n) - snprintf(m->ltsymbol, LENGTH(m->ltsymbol), "[%d]", n); if ((c = focustop(m))) 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 tags %u %u %u %u\n", m->wlr_output->name, occ, 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的状态 这里很关键 } 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; } else if (visible_client_number < 2 && !c->isfloating) { return DOWN; @@ -3872,7 +3860,7 @@ void resize(Client *c, struct wlr_box geo, int interact) { // oldgeom = c->geom; 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; } else { // 这里会限制不允许窗口划出屏幕 client_set_bounds( @@ -4146,13 +4134,8 @@ setlayout(const Arg *arg) { int jk; for (jk = 0; jk < LENGTH(layouts); jk++) { if(strcmp(layouts[jk].name , arg->v) == 0) { - selmon->lt[selmon->sellt] = &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)); + selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[jk]; + arrange(selmon, false); printstatus(); return; @@ -4164,9 +4147,8 @@ void switch_layout(const Arg *arg) { int jk; for (jk = 0; jk < LENGTH(layouts); jk++) { - if(strcmp(layouts[jk].name , selmon->lt[selmon->sellt]->name)) { - selmon->lt[selmon->sellt] = &layouts[jk]; - selmon->pertag->sellts[selmon->pertag->curtag] = selmon->sellt; + if(strcmp(layouts[jk].name , selmon->pertag->ltidxs[selmon->pertag->curtag]->name) == 0) { + selmon->pertag->ltidxs[selmon->pertag->curtag] = jk == LENGTH(layouts) - 1? &layouts[0] : &layouts[jk+1]; arrange(selmon, false); printstatus(); return; @@ -4182,7 +4164,7 @@ void // 17 setmfact(const Arg *arg) { float f; - if (!arg || !selmon || !selmon->lt[selmon->sellt]->arrange) + if (!arg || !selmon || !selmon->pertag->ltidxs[selmon->pertag->curtag]->arrange) return; f = arg->f < 1.0 ? arg->f + selmon->pertag->mfacts[selmon->pertag->curtag] : arg->f - 1.0; @@ -5597,12 +5579,6 @@ void view(const Arg *arg, bool want_animation) { 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); arrange(selmon, want_animation); printstatus(); @@ -5635,12 +5611,6 @@ void viewtoleft(const Arg *arg) { 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); arrange(selmon, true); printstatus(); @@ -5686,12 +5656,6 @@ void viewtoright_have_client(const Arg *arg) { 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); arrange(selmon, true); printstatus(); @@ -5721,12 +5685,6 @@ void viewtoright(const Arg *arg) { 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); arrange(selmon, true); printstatus(); @@ -5772,12 +5730,6 @@ void viewtoleft_have_client(const Arg *arg) { 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); arrange(selmon, true); printstatus(); @@ -5885,7 +5837,7 @@ void toggleglobal(const Arg *arg) { void zoom(const Arg *arg) { 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; /* 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); 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, (struct wlr_box){.x = event->x - c->bw, .y = event->y - c->bw,