dwm-stairs-20220430-8b48e30.diff (3560B)
1 From a189dd70bd7c0789a11f304ceb75fd2d66fa405d Mon Sep 17 00:00:00 2001 2 From: Ehsan Ghorbannezhad <ehsan@disroot.org> 3 Date: Sat, 30 Apr 2022 01:15:20 +0430 4 Subject: [PATCH] add a new layout called stairs 5 6 --- 7 config.def.h | 5 +++++ 8 dwm.c | 38 ++++++++++++++++++++++++++++++++++++++ 9 2 files changed, 43 insertions(+) 10 11 diff --git a/config.def.h b/config.def.h 12 index a2ac963..7774f1e 100644 13 --- a/config.def.h 14 +++ b/config.def.h 15 @@ -5,6 +5,9 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ 16 static const unsigned int snap = 32; /* snap pixel */ 17 static const int showbar = 1; /* 0 means no bar */ 18 static const int topbar = 1; /* 0 means bottom bar */ 19 +static const unsigned int stairpx = 20; /* depth of the stairs layout */ 20 +static const int stairdirection = 1; /* 0: left-aligned, 1: right-aligned */ 21 +static const int stairsamesize = 1; /* 1 means shrink all the staired windows to the same size */ 22 static const char *fonts[] = { "monospace:size=10" }; 23 static const char dmenufont[] = "monospace:size=10"; 24 static const char col_gray1[] = "#222222"; 25 @@ -42,6 +45,7 @@ static const Layout layouts[] = { 26 { "[]=", tile }, /* first entry is default */ 27 { "><>", NULL }, /* no layout function means floating behavior */ 28 { "[M]", monocle }, 29 + { "[S]", stairs }, 30 }; 31 32 /* key definitions */ 33 @@ -77,6 +81,7 @@ static Key keys[] = { 34 { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, 35 { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, 36 { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, 37 + { MODKEY, XK_s, setlayout, {.v = &layouts[3]} }, 38 { MODKEY, XK_space, setlayout, {0} }, 39 { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, 40 { MODKEY, XK_0, view, {.ui = ~0 } }, 41 diff --git a/dwm.c b/dwm.c 42 index 5646a5c..fcdbb06 100644 43 --- a/dwm.c 44 +++ b/dwm.c 45 @@ -207,6 +207,7 @@ static void seturgent(Client *c, int urg); 46 static void showhide(Client *c); 47 static void sigchld(int unused); 48 static void spawn(const Arg *arg); 49 +static void stairs(Monitor *m); 50 static void tag(const Arg *arg); 51 static void tagmon(const Arg *arg); 52 static void tile(Monitor *); 53 @@ -1659,6 +1660,43 @@ spawn(const Arg *arg) 54 } 55 } 56 57 +void 58 +stairs(Monitor *m) 59 +{ 60 + unsigned int i, n, h, mw, my; 61 + unsigned int ox, oy, ow, oh; /* stair offset values */ 62 + Client *c; 63 + 64 + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); 65 + if (n == 0) 66 + return; 67 + 68 + if (n > m->nmaster) 69 + mw = m->nmaster ? m->ww * m->mfact : 0; 70 + else 71 + mw = m->ww; 72 + 73 + for (i = my = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) { 74 + if (i < m->nmaster) { 75 + h = (m->wh - my) / (MIN(n, m->nmaster) - i); 76 + resize(c, m->wx, m->wy + my, mw - (2 * c->bw), h - (2 * c->bw), 0); 77 + if (my + HEIGHT(c) < m->wh) 78 + my += HEIGHT(c); 79 + } else { 80 + oy = i - m->nmaster; 81 + ox = stairdirection ? n - i - 1 : (stairsamesize ? i - m->nmaster : 0); 82 + ow = stairsamesize ? n - m->nmaster - 1 : n - i - 1; 83 + oh = stairsamesize ? ow : i - m->nmaster; 84 + resize(c, 85 + m->wx + mw + (ox * stairpx), 86 + m->wy + (oy * stairpx), 87 + m->ww - mw - (2 * c->bw) - (ow * stairpx), 88 + m->wh - (2 * c->bw) - (oh * stairpx), 89 + 0); 90 + } 91 + } 92 +} 93 + 94 void 95 tag(const Arg *arg) 96 { 97 -- 98 2.36.0