dwm-vanitygaps-20200610-f09418b.diff (8300B)
1 From c35fd03ec002e1f4476a75203ff9b5cbcc630177 Mon Sep 17 00:00:00 2001 2 From: Michel Boaventura <michel.boaventura@protonmail.com> 3 Date: Wed, 10 Jun 2020 10:46:51 -0300 4 Subject: [PATCH] Update Vanity Gaps to master 5 6 --- 7 config.def.h | 21 +++++++ 8 dwm.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++---- 9 2 files changed, 163 insertions(+), 12 deletions(-) 10 11 diff --git a/config.def.h b/config.def.h 12 index 1c0b587..0927c2d 100644 13 --- a/config.def.h 14 +++ b/config.def.h 15 @@ -3,6 +3,11 @@ 16 /* appearance */ 17 static const unsigned int borderpx = 1; /* border pixel of windows */ 18 static const unsigned int snap = 32; /* snap pixel */ 19 +static const unsigned int gappih = 10; /* horiz inner gap between windows */ 20 +static const unsigned int gappiv = 10; /* vert inner gap between windows */ 21 +static const unsigned int gappoh = 10; /* horiz outer gap between windows and screen edge */ 22 +static const unsigned int gappov = 10; /* vert outer gap between windows and screen edge */ 23 +static const int smartgaps = 0; /* 1 means no outer gap when there is only one window */ 24 static const int showbar = 1; /* 0 means no bar */ 25 static const int topbar = 1; /* 0 means bottom bar */ 26 static const char *fonts[] = { "monospace:size=10" }; 27 @@ -70,6 +75,22 @@ static Key keys[] = { 28 { MODKEY, XK_d, incnmaster, {.i = -1 } }, 29 { MODKEY, XK_h, setmfact, {.f = -0.05} }, 30 { MODKEY, XK_l, setmfact, {.f = +0.05} }, 31 + { MODKEY|Mod4Mask, XK_h, incrgaps, {.i = +1 } }, 32 + { MODKEY|Mod4Mask, XK_l, incrgaps, {.i = -1 } }, 33 + { MODKEY|Mod4Mask|ShiftMask, XK_h, incrogaps, {.i = +1 } }, 34 + { MODKEY|Mod4Mask|ShiftMask, XK_l, incrogaps, {.i = -1 } }, 35 + { MODKEY|Mod4Mask|ControlMask, XK_h, incrigaps, {.i = +1 } }, 36 + { MODKEY|Mod4Mask|ControlMask, XK_l, incrigaps, {.i = -1 } }, 37 + { MODKEY|Mod4Mask, XK_0, togglegaps, {0} }, 38 + { MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} }, 39 + { MODKEY, XK_y, incrihgaps, {.i = +1 } }, 40 + { MODKEY, XK_o, incrihgaps, {.i = -1 } }, 41 + { MODKEY|ControlMask, XK_y, incrivgaps, {.i = +1 } }, 42 + { MODKEY|ControlMask, XK_o, incrivgaps, {.i = -1 } }, 43 + { MODKEY|Mod4Mask, XK_y, incrohgaps, {.i = +1 } }, 44 + { MODKEY|Mod4Mask, XK_o, incrohgaps, {.i = -1 } }, 45 + { MODKEY|ShiftMask, XK_y, incrovgaps, {.i = +1 } }, 46 + { MODKEY|ShiftMask, XK_o, incrovgaps, {.i = -1 } }, 47 { MODKEY, XK_Return, zoom, {0} }, 48 { MODKEY, XK_Tab, view, {0} }, 49 { MODKEY|ShiftMask, XK_c, killclient, {0} }, 50 diff --git a/dwm.c b/dwm.c 51 index 9fd0286..50dbbaf 100644 52 --- a/dwm.c 53 +++ b/dwm.c 54 @@ -119,6 +119,10 @@ struct Monitor { 55 int by; /* bar geometry */ 56 int mx, my, mw, mh; /* screen size */ 57 int wx, wy, ww, wh; /* window area */ 58 + int gappih; /* horizontal gap between windows */ 59 + int gappiv; /* vertical gap between windows */ 60 + int gappoh; /* horizontal outer gaps */ 61 + int gappov; /* vertical outer gaps */ 62 unsigned int seltags; 63 unsigned int sellt; 64 unsigned int tagset[2]; 65 @@ -200,6 +204,16 @@ static void sendmon(Client *c, Monitor *m); 66 static void setclientstate(Client *c, long state); 67 static void setfocus(Client *c); 68 static void setfullscreen(Client *c, int fullscreen); 69 +static void setgaps(int oh, int ov, int ih, int iv); 70 +static void incrgaps(const Arg *arg); 71 +static void incrigaps(const Arg *arg); 72 +static void incrogaps(const Arg *arg); 73 +static void incrohgaps(const Arg *arg); 74 +static void incrovgaps(const Arg *arg); 75 +static void incrihgaps(const Arg *arg); 76 +static void incrivgaps(const Arg *arg); 77 +static void togglegaps(const Arg *arg); 78 +static void defaultgaps(const Arg *arg); 79 static void setlayout(const Arg *arg); 80 static void setmfact(const Arg *arg); 81 static void setup(void); 82 @@ -241,6 +255,7 @@ static char stext[256]; 83 static int screen; 84 static int sw, sh; /* X display screen geometry width, height */ 85 static int bh, blw = 0; /* bar geometry */ 86 +static int enablegaps = 1; /* enables gaps, used by togglegaps */ 87 static int lrpad; /* sum of left and right padding for text */ 88 static int (*xerrorxlib)(Display *, XErrorEvent *); 89 static unsigned int numlockmask = 0; 90 @@ -639,6 +654,10 @@ createmon(void) 91 m->nmaster = nmaster; 92 m->showbar = showbar; 93 m->topbar = topbar; 94 + m->gappih = gappih; 95 + m->gappiv = gappiv; 96 + m->gappoh = gappoh; 97 + m->gappov = gappov; 98 m->lt[0] = &layouts[0]; 99 m->lt[1] = &layouts[1 % LENGTH(layouts)]; 100 strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); 101 @@ -1498,6 +1517,111 @@ setfullscreen(Client *c, int fullscreen) 102 } 103 } 104 105 +void 106 +setgaps(int oh, int ov, int ih, int iv) 107 +{ 108 + if (oh < 0) oh = 0; 109 + if (ov < 0) ov = 0; 110 + if (ih < 0) ih = 0; 111 + if (iv < 0) iv = 0; 112 + 113 + selmon->gappoh = oh; 114 + selmon->gappov = ov; 115 + selmon->gappih = ih; 116 + selmon->gappiv = iv; 117 + arrange(selmon); 118 +} 119 + 120 +void 121 +togglegaps(const Arg *arg) 122 +{ 123 + enablegaps = !enablegaps; 124 + arrange(selmon); 125 +} 126 + 127 +void 128 +defaultgaps(const Arg *arg) 129 +{ 130 + setgaps(gappoh, gappov, gappih, gappiv); 131 +} 132 + 133 +void 134 +incrgaps(const Arg *arg) 135 +{ 136 + setgaps( 137 + selmon->gappoh + arg->i, 138 + selmon->gappov + arg->i, 139 + selmon->gappih + arg->i, 140 + selmon->gappiv + arg->i 141 + ); 142 +} 143 + 144 +void 145 +incrigaps(const Arg *arg) 146 +{ 147 + setgaps( 148 + selmon->gappoh, 149 + selmon->gappov, 150 + selmon->gappih + arg->i, 151 + selmon->gappiv + arg->i 152 + ); 153 +} 154 + 155 +void 156 +incrogaps(const Arg *arg) 157 +{ 158 + setgaps( 159 + selmon->gappoh + arg->i, 160 + selmon->gappov + arg->i, 161 + selmon->gappih, 162 + selmon->gappiv 163 + ); 164 +} 165 + 166 +void 167 +incrohgaps(const Arg *arg) 168 +{ 169 + setgaps( 170 + selmon->gappoh + arg->i, 171 + selmon->gappov, 172 + selmon->gappih, 173 + selmon->gappiv 174 + ); 175 +} 176 + 177 +void 178 +incrovgaps(const Arg *arg) 179 +{ 180 + setgaps( 181 + selmon->gappoh, 182 + selmon->gappov + arg->i, 183 + selmon->gappih, 184 + selmon->gappiv 185 + ); 186 +} 187 + 188 +void 189 +incrihgaps(const Arg *arg) 190 +{ 191 + setgaps( 192 + selmon->gappoh, 193 + selmon->gappov, 194 + selmon->gappih + arg->i, 195 + selmon->gappiv 196 + ); 197 +} 198 + 199 +void 200 +incrivgaps(const Arg *arg) 201 +{ 202 + setgaps( 203 + selmon->gappoh, 204 + selmon->gappov, 205 + selmon->gappih, 206 + selmon->gappiv + arg->i 207 + ); 208 +} 209 + 210 void 211 setlayout(const Arg *arg) 212 { 213 @@ -1674,28 +1798,34 @@ tagmon(const Arg *arg) 214 void 215 tile(Monitor *m) 216 { 217 - unsigned int i, n, h, mw, my, ty; 218 + unsigned int i, n, h, r, oe = enablegaps, ie = enablegaps, mw, my, ty; 219 Client *c; 220 221 for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); 222 if (n == 0) 223 return; 224 225 + if (smartgaps == n) { 226 + oe = 0; // outer gaps disabled 227 + } 228 + 229 if (n > m->nmaster) 230 - mw = m->nmaster ? m->ww * m->mfact : 0; 231 + mw = m->nmaster ? (m->ww + m->gappiv*ie) * m->mfact : 0; 232 else 233 - mw = m->ww; 234 - for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) 235 + mw = m->ww - 2*m->gappov*oe + m->gappiv*ie; 236 + for (i = 0, my = ty = m->gappoh*oe, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) 237 if (i < m->nmaster) { 238 - h = (m->wh - my) / (MIN(n, m->nmaster) - i); 239 - resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0); 240 - if (my + HEIGHT(c) < m->wh) 241 - my += HEIGHT(c); 242 + r = MIN(n, m->nmaster) - i; 243 + h = (m->wh - my - m->gappoh*oe - m->gappih*ie * (r - 1)) / r; 244 + resize(c, m->wx + m->gappov*oe, m->wy + my, mw - (2*c->bw) - m->gappiv*ie, h - (2*c->bw), 0); 245 + if (my + HEIGHT(c) + m->gappih*ie < m->wh) 246 + my += HEIGHT(c) + m->gappih*ie; 247 } else { 248 - h = (m->wh - ty) / (n - i); 249 - resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0); 250 - if (ty + HEIGHT(c) < m->wh) 251 - ty += HEIGHT(c); 252 + r = n - i; 253 + h = (m->wh - ty - m->gappoh*oe - m->gappih*ie * (r - 1)) / r; 254 + resize(c, m->wx + mw + m->gappov*oe, m->wy + ty, m->ww - mw - (2*c->bw) - 2*m->gappov*oe, h - (2*c->bw), 0); 255 + if (ty + HEIGHT(c) + m->gappih*ie < m->wh) 256 + ty += HEIGHT(c) + m->gappih*ie; 257 } 258 } 259 260 -- 261 2.27.0 262