dwm-gaplessgridleftright-20211216-76d72e24.diff (4902B)
1 From 76d72e24117a5626827cfb0ef49515ec7f7dd4fe Mon Sep 17 00:00:00 2001 2 From: shlomi-aknin <shlomi.aknin@gmail.com> 3 Date: Thu, 16 Dec 2021 14:53:02 +0200 4 Subject: [PATCH] This patch incorporates gaplessgrid patch. This patch adds 5 the ability to focus on left or right window of the current window (works in 6 gaplessgrid layout only) 7 8 --- 9 config.def.h | 5 +++- 10 dwm.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++- 11 2 files changed, 77 insertions(+), 2 deletions(-) 12 13 diff --git a/config.def.h b/config.def.h 14 index a2ac963..c63a640 100644 15 --- a/config.def.h 16 +++ b/config.def.h 17 @@ -42,6 +42,7 @@ static const Layout layouts[] = { 18 { "[]=", tile }, /* first entry is default */ 19 { "><>", NULL }, /* no layout function means floating behavior */ 20 { "[M]", monocle }, 21 + { "###", gaplessgrid }, 22 }; 23 24 /* key definitions */ 25 @@ -77,6 +78,7 @@ static Key keys[] = { 26 { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, 27 { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, 28 { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, 29 + { MODKEY, XK_g, setlayout, {.v = &layouts[3]} }, 30 { MODKEY, XK_space, setlayout, {0} }, 31 { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, 32 { MODKEY, XK_0, view, {.ui = ~0 } }, 33 @@ -85,6 +87,8 @@ static Key keys[] = { 34 { MODKEY, XK_period, focusmon, {.i = +1 } }, 35 { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, 36 { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, 37 + { MODKEY|ControlMask, XK_l, gaplessgridleftright, {.i = +1 } }, 38 + { MODKEY|ControlMask, XK_h, gaplessgridleftright, {.i = -1 } }, 39 TAGKEYS( XK_1, 0) 40 TAGKEYS( XK_2, 1) 41 TAGKEYS( XK_3, 2) 42 @@ -113,4 +117,3 @@ static Button buttons[] = { 43 { ClkTagBar, MODKEY, Button1, tag, {0} }, 44 { ClkTagBar, MODKEY, Button3, toggletag, {0} }, 45 }; 46 - 47 diff --git a/dwm.c b/dwm.c 48 index 5e4d494..a7fb265 100644 49 --- a/dwm.c 50 +++ b/dwm.c 51 @@ -91,6 +91,7 @@ struct Client { 52 int oldx, oldy, oldw, oldh; 53 int basew, baseh, incw, inch, maxw, maxh, minw, minh; 54 int bw, oldbw; 55 + int gridrow, gridcol; 56 unsigned int tags; 57 int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; 58 Client *next; 59 @@ -169,6 +170,8 @@ static void focus(Client *c); 60 static void focusin(XEvent *e); 61 static void focusmon(const Arg *arg); 62 static void focusstack(const Arg *arg); 63 +static void gaplessgrid(Monitor *m); 64 +static void gaplessgridleftright(const Arg *arg); 65 static Atom getatomprop(Client *c, Atom prop); 66 static int getrootptr(int *x, int *y); 67 static long getstate(Window w); 68 @@ -856,6 +859,76 @@ focusstack(const Arg *arg) 69 } 70 } 71 72 +void 73 +gaplessgrid(Monitor *m) 74 +{ 75 + unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch; 76 + Client *c; 77 + 78 + for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ; 79 + if(n == 0) 80 + return; 81 + 82 + /* grid dimensions */ 83 + for(cols = 0; cols <= n/2; cols++) 84 + if(cols*cols >= n) 85 + break; 86 + if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */ 87 + cols = 2; 88 + rows = n/cols; 89 + 90 + /* window geometries */ 91 + cw = cols ? m->ww / cols : m->ww; 92 + cn = 0; /* current column number */ 93 + rn = 0; /* current row number */ 94 + for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) { 95 + if(i/rows + 1 > cols - n%cols) 96 + rows = n/cols + 1; 97 + ch = rows ? m->wh / rows : m->wh; 98 + cx = m->wx + cn*cw; 99 + cy = m->wy + rn*ch; 100 + c->gridrow = rn; 101 + c->gridcol = cn; 102 + resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False); 103 + rn++; 104 + if(rn >= rows) { 105 + rn = 0; 106 + cn++; 107 + } 108 + } 109 +} 110 + 111 +void 112 +gaplessgridleftright(const Arg *arg) 113 +{ 114 + Client *c = selmon->sel; 115 + Client *t = NULL; 116 + int found = 0; 117 + if(selmon->lt[selmon->sellt]->arrange != gaplessgrid || !ISVISIBLE(c)) return; 118 + 119 + if (arg->i > 0) { 120 + for(t = selmon->sel->next; t; t = t->next) { 121 + if (t->gridcol == c->gridcol + 1 && t->gridrow == c->gridrow) break; 122 + } 123 + } else { 124 + for(t = selmon->clients; t; t = t->next) { 125 + if (t->gridcol == c->gridcol - 1 && t->gridrow == c->gridrow) { 126 + found = 1; 127 + break; 128 + } 129 + } 130 + 131 + if (found == 0) { 132 + for(t = selmon->clients; t; t = t->next) { 133 + if (t->gridcol == c->gridcol - 1 && t->gridrow == c->gridrow - 1) break; 134 + } 135 + } 136 + } 137 + 138 + focus(t); 139 + arrange(selmon); 140 +} 141 + 142 Atom 143 getatomprop(Client *c, Atom prop) 144 { 145 @@ -1597,7 +1670,6 @@ setup(void) 146 focus(NULL); 147 } 148 149 - 150 void 151 seturgent(Client *c, int urg) 152 { 153 -- 154 2.34.1