From d56f732d3b5bba4ea0bdf56a91d0992b0cb25bfb Mon Sep 17 00:00:00 2001 From: anabasis Date: Fri, 10 May 2024 13:45:33 -0400 Subject: [PATCH] add deck layout --- config.def.h | 2 ++ dwl.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/config.def.h b/config.def.h index 8f498d2..9238da0 100644 --- a/config.def.h +++ b/config.def.h @@ -33,6 +33,7 @@ static const Layout layouts[] = { { "[]=", tile }, { "><>", NULL }, /* no layout function means floating behavior */ { "[M]", monocle }, + { "[D]", deck }, }; /* monitors */ @@ -134,6 +135,7 @@ static const Key keys[] = { { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} }, { MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} }, { MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} }, + { MODKEY, XKB_KEY_r, setlayout, {.v = &layouts[3]} }, { MODKEY, XKB_KEY_space, setlayout, {0} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} }, { MODKEY, XKB_KEY_e, togglefullscreen, {0} }, diff --git a/dwl.c b/dwl.c index bf763df..1a7ce8e 100644 --- a/dwl.c +++ b/dwl.c @@ -267,6 +267,7 @@ static void createpointerconstraint(struct wl_listener *listener, void *data); static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint); static void cursorframe(struct wl_listener *listener, void *data); static void cursorwarptohint(void); +static void deck(Monitor *m); static void destroydecoration(struct wl_listener *listener, void *data); static void destroydragicon(struct wl_listener *listener, void *data); static void destroyidleinhibitor(struct wl_listener *listener, void *data); @@ -1080,6 +1081,41 @@ cursorwarptohint(void) } } +void +deck(Monitor *m) +{ + unsigned int mw, my; + int i, n = 0; + Client *c; + + wl_list_for_each(c, &clients, link) + if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen) + n++; + if (n == 0) + return; + + if (n > m->nmaster) + mw = m->nmaster ? ROUND(m->w.width * m->mfact) : 0; + else + mw = m->w.width; + i = my = 0; + wl_list_for_each(c, &clients, link) { + if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen) + continue; + if (i < m->nmaster) { + resize(c, (struct wlr_box){.x = m->w.x, .y = m->w.y + my, .width = mw, + .height = (m->w.height - my) / (MIN(n, m->nmaster) - i)}, 0); + my += c->geom.height; + } else { + resize(c, (struct wlr_box){.x = m->w.x + mw, .y = m->w.y, + .width = m->w.width - mw, .height = m->w.height}, 0); + if (c == focustop(m)) + wlr_scene_node_raise_to_top(&c->scene->node); + } + i++; + } +} + void destroydecoration(struct wl_listener *listener, void *data) { -- 2.45.0