From 4be4c211dfa5f748c9cfc682805d0b93f923d6f8 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Mon, 17 Feb 2025 11:22:11 +0800 Subject: [PATCH] feat:add sprial and dwindle layout --- config.conf | 2 +- maomao.c | 162 ++++++++++++++++++++++++++++++++++-------------- preset_config.h | 8 ++- 3 files changed, 123 insertions(+), 49 deletions(-) diff --git a/config.conf b/config.conf index 4a04625..b331c8f 100644 --- a/config.conf +++ b/config.conf @@ -51,7 +51,7 @@ scratchpadcolor=0x516c93ff globalcolor=0xb153a7ff # tags rule -# layout support: tile,scroller,grid,monocle +# layout support: tile,scroller,grid,monocle,spiral,dwindle tags=id:1,layout_name:tile tags=id:2,layout_name:tile tags=id:3,layout_name:tile diff --git a/maomao.c b/maomao.c index a7b95c7..0321b40 100644 --- a/maomao.c +++ b/maomao.c @@ -485,7 +485,8 @@ static void tile(Monitor *m, unsigned int gappo, unsigned int uappi); static void overview(Monitor *m, unsigned int gappo, unsigned int gappi); static void grid(Monitor *m, unsigned int gappo, unsigned int uappi); static void scroller(Monitor *m, unsigned int gappo, unsigned int uappi); - +static void dwindle(Monitor *mon, unsigned int gappo, unsigned int gappi); +static void spiral(Monitor *mon, unsigned int gappo, unsigned int gappi); static void unlocksession(struct wl_listener *listener, void *data); static void unmaplayersurfacenotify(struct wl_listener *listener, void *data); static void unmapnotify(struct wl_listener *listener, void *data); @@ -2493,56 +2494,56 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) { focused = focustop(monitor); zdwl_ipc_output_v2_send_active(ipc_output->resource, monitor == selmon); - if ((monitor->tagset[monitor->seltags] & TAGMASK) == TAGMASK) { - state = 0; - state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE; - zdwl_ipc_output_v2_send_tag(ipc_output->resource, 888, state, 1, 1); - } else { - for (tag = 0; tag < LENGTH(tags); tag++) { - numclients = state = focused_client = 0; - tagmask = 1 << tag; - if ((tagmask & monitor->tagset[monitor->seltags]) != 0) - state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE; - - wl_list_for_each(c, &clients, link) { - if (c->iskilling) - continue; - if (c->mon != monitor) - continue; - if (!(c->tags & tagmask)) - continue; - if (c == focused) - focused_client = 1; - if (c->isurgent) - state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT; - - numclients++; - } - zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, numclients, - focused_client); - } - } - - // for ( tag = 0 ; tag < LENGTH(tags); tag++) { + // if ((monitor->tagset[monitor->seltags] & TAGMASK) == TAGMASK) { + // state = 0; + // state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE; + // zdwl_ipc_output_v2_send_tag(ipc_output->resource, 888, state, 1, 1); + // } else { + // for (tag = 0; tag < LENGTH(tags); tag++) { // numclients = state = focused_client = 0; // tagmask = 1 << tag; // if ((tagmask & monitor->tagset[monitor->seltags]) != 0) - // state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE; + // state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE; + // wl_list_for_each(c, &clients, link) { - // if (c->mon != monitor) - // continue; - // if (!(c->tags & tagmask)) - // continue; - // if (c == focused) - // focused_client = 1; - // if (c->isurgent) - // state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT; - // numclients++; + // if (c->iskilling) + // continue; + // if (c->mon != monitor) + // continue; + // if (!(c->tags & tagmask)) + // continue; + // if (c == focused) + // focused_client = 1; + // if (c->isurgent) + // state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT; + + // numclients++; // } - // zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, - // numclients, focused_client); + // zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, numclients, + // focused_client); + // } // } + for ( tag = 0 ; tag < LENGTH(tags); tag++) { + numclients = state = focused_client = 0; + tagmask = 1 << tag; + if ((tagmask & monitor->tagset[monitor->seltags]) != 0) + state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE; + wl_list_for_each(c, &clients, link) { + if (c->mon != monitor) + continue; + if (!(c->tags & tagmask)) + continue; + if (c == focused) + focused_client = 1; + if (c->isurgent) + state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT; + numclients++; + } + zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, + numclients, focused_client); + } + title = focused ? client_get_title(focused) : ""; appid = focused ? client_get_appid(focused) : ""; symbol = @@ -3245,7 +3246,7 @@ monocle(Monitor *m,unsigned int gappo, unsigned int gappi) { int n = 0; wl_list_for_each(c, &clients, link) { - if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen) + if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen || c->ismaxmizescreen || c->iskilling || c->animation.tagouting) continue; resize(c, m->w, 0); n++; @@ -4833,6 +4834,77 @@ void overview(Monitor *m, unsigned int gappo, unsigned int gappi) { grid(m, overviewgappo, overviewgappi); } + +void fibonacci(Monitor *mon, int s) { + unsigned int i=0, n=0, nx, ny, nw, nh; + Client *c; + + wl_list_for_each(c, &clients, link) + if (VISIBLEON(c, mon) && !c->isfloating) + n++; + if(n == 0) + return; + + nx = mon->w.x; + ny = 0; + nw = mon->w.width; + nh = mon->w.height; + + wl_list_for_each(c, &clients, link) + if (VISIBLEON(c, mon) && !c->isfloating){ + if((i % 2 && nh / 2 > 2 * c->bw) + || (!(i % 2) && nw / 2 > 2 * c->bw)) { + if(i < n - 1) { + if(i % 2) + nh /= 2; + else + nw /= 2; + if((i % 4) == 2 && !s) + nx += nw; + else if((i % 4) == 3 && !s) + ny += nh; + } + if((i % 4) == 0) { + if(s) + ny += nh; + else + ny -= nh; + } + else if((i % 4) == 1) + nx += nw; + else if((i % 4) == 2) + ny += nh; + else if((i % 4) == 3) { + if(s) + nx += nw; + else + nx -= nw; + } + if(i == 0) + { + if(n != 1) + nw = mon->w.width * mon->mfact; + ny = mon->w.y; + } + else if(i == 1) + nw = mon->w.width - nw; + i++; + } + resize(c, (struct wlr_box){.x = nx, .y = ny, + .width = nw - 2 * c->bw, .height = nh - 2 * c->bw}, 0); + } +} + +void +dwindle(Monitor *mon,unsigned int gappo, unsigned int gappi) { + fibonacci(mon, 1); +} + +void +spiral(Monitor *mon, unsigned int gappo, unsigned int gappi) { + fibonacci(mon, 0); +} + // 网格布局窗口大小和位置计算 void grid(Monitor *m, unsigned int gappo, unsigned int gappi) { unsigned int i, n; diff --git a/preset_config.h b/preset_config.h index 72d68f2..8cd65ae 100644 --- a/preset_config.h +++ b/preset_config.h @@ -67,10 +67,12 @@ Layout overviewlayout = { "󰃇", overview, "overview" }; Layout layouts[] = { //最少两个,不能删除少于两个 /* symbol arrange function name */ - { "⬌", scroller, "scroller" }, //滚动布局 - { "󱞬", tile, "tile" }, //堆栈布局 - {"󰃇", grid, "grid"}, + { "S", scroller, "scroller" }, //滚动布局 + { "T", tile, "tile" }, //堆栈布局 + {"G", grid, "grid"}, {"M",monocle,"monocle"}, + {"D",dwindle,"dwindle"}, + {"P",spiral,"spiral"}, };