dwm-vanitygaps-20190508-6.2.diff (8260B)
1 From 20967685d6879bd611a856ade154df19da9ddc7b Mon Sep 17 00:00:00 2001 2 From: Stein Gunnar Bakkeby <bakkeby@gmail.com> 3 Date: Wed, 8 May 2019 08:07:14 +0200 4 Subject: [PATCH] Vanity gaps - allows control of both inner and outer gaps 5 between windows and screen edge 6 7 --- 8 config.def.h | 21 +++++++++ 9 dwm.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 10 2 files changed, 161 insertions(+), 10 deletions(-) 11 12 diff --git a/config.def.h b/config.def.h 13 index 1c0b587..0927c2d 100644 14 --- a/config.def.h 15 +++ b/config.def.h 16 @@ -3,6 +3,11 @@ 17 /* appearance */ 18 static const unsigned int borderpx = 1; /* border pixel of windows */ 19 static const unsigned int snap = 32; /* snap pixel */ 20 +static const unsigned int gappih = 10; /* horiz inner gap between windows */ 21 +static const unsigned int gappiv = 10; /* vert inner gap between windows */ 22 +static const unsigned int gappoh = 10; /* horiz outer gap between windows and screen edge */ 23 +static const unsigned int gappov = 10; /* vert outer gap between windows and screen edge */ 24 +static const int smartgaps = 0; /* 1 means no outer gap when there is only one window */ 25 static const int showbar = 1; /* 0 means no bar */ 26 static const int topbar = 1; /* 0 means bottom bar */ 27 static const char *fonts[] = { "monospace:size=10" }; 28 @@ -70,6 +75,22 @@ static Key keys[] = { 29 { MODKEY, XK_d, incnmaster, {.i = -1 } }, 30 { MODKEY, XK_h, setmfact, {.f = -0.05} }, 31 { MODKEY, XK_l, setmfact, {.f = +0.05} }, 32 + { MODKEY|Mod4Mask, XK_h, incrgaps, {.i = +1 } }, 33 + { MODKEY|Mod4Mask, XK_l, incrgaps, {.i = -1 } }, 34 + { MODKEY|Mod4Mask|ShiftMask, XK_h, incrogaps, {.i = +1 } }, 35 + { MODKEY|Mod4Mask|ShiftMask, XK_l, incrogaps, {.i = -1 } }, 36 + { MODKEY|Mod4Mask|ControlMask, XK_h, incrigaps, {.i = +1 } }, 37 + { MODKEY|Mod4Mask|ControlMask, XK_l, incrigaps, {.i = -1 } }, 38 + { MODKEY|Mod4Mask, XK_0, togglegaps, {0} }, 39 + { MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} }, 40 + { MODKEY, XK_y, incrihgaps, {.i = +1 } }, 41 + { MODKEY, XK_o, incrihgaps, {.i = -1 } }, 42 + { MODKEY|ControlMask, XK_y, incrivgaps, {.i = +1 } }, 43 + { MODKEY|ControlMask, XK_o, incrivgaps, {.i = -1 } }, 44 + { MODKEY|Mod4Mask, XK_y, incrohgaps, {.i = +1 } }, 45 + { MODKEY|Mod4Mask, XK_o, incrohgaps, {.i = -1 } }, 46 + { MODKEY|ShiftMask, XK_y, incrovgaps, {.i = +1 } }, 47 + { MODKEY|ShiftMask, XK_o, incrovgaps, {.i = -1 } }, 48 { MODKEY, XK_Return, zoom, {0} }, 49 { MODKEY, XK_Tab, view, {0} }, 50 { MODKEY|ShiftMask, XK_c, killclient, {0} }, 51 diff --git a/dwm.c b/dwm.c 52 index 4465af1..88f3e04 100644 53 --- a/dwm.c 54 +++ b/dwm.c 55 @@ -119,6 +119,10 @@ struct Monitor { 56 int by; /* bar geometry */ 57 int mx, my, mw, mh; /* screen size */ 58 int wx, wy, ww, wh; /* window area */ 59 + int gappih; /* horizontal gap between windows */ 60 + int gappiv; /* vertical gap between windows */ 61 + int gappoh; /* horizontal outer gaps */ 62 + int gappov; /* vertical outer gaps */ 63 unsigned int seltags; 64 unsigned int sellt; 65 unsigned int tagset[2]; 66 @@ -199,6 +203,16 @@ static void sendmon(Client *c, Monitor *m); 67 static void setclientstate(Client *c, long state); 68 static void setfocus(Client *c); 69 static void setfullscreen(Client *c, int fullscreen); 70 +static void setgaps(int oh, int ov, int ih, int iv); 71 +static void incrgaps(const Arg *arg); 72 +static void incrigaps(const Arg *arg); 73 +static void incrogaps(const Arg *arg); 74 +static void incrohgaps(const Arg *arg); 75 +static void incrovgaps(const Arg *arg); 76 +static void incrihgaps(const Arg *arg); 77 +static void incrivgaps(const Arg *arg); 78 +static void togglegaps(const Arg *arg); 79 +static void defaultgaps(const Arg *arg); 80 static void setlayout(const Arg *arg); 81 static void setmfact(const Arg *arg); 82 static void setup(void); 83 @@ -240,6 +254,7 @@ static char stext[256]; 84 static int screen; 85 static int sw, sh; /* X display screen geometry width, height */ 86 static int bh, blw = 0; /* bar geometry */ 87 +static int enablegaps = 1; /* enables gaps, used by togglegaps */ 88 static int lrpad; /* sum of left and right padding for text */ 89 static int (*xerrorxlib)(Display *, XErrorEvent *); 90 static unsigned int numlockmask = 0; 91 @@ -638,6 +653,10 @@ createmon(void) 92 m->nmaster = nmaster; 93 m->showbar = showbar; 94 m->topbar = topbar; 95 + m->gappih = gappih; 96 + m->gappiv = gappiv; 97 + m->gappoh = gappoh; 98 + m->gappov = gappov; 99 m->lt[0] = &layouts[0]; 100 m->lt[1] = &layouts[1 % LENGTH(layouts)]; 101 strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); 102 @@ -1498,6 +1517,111 @@ setfullscreen(Client *c, int fullscreen) 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 if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) 214 @@ -1673,26 +1797,32 @@ tagmon(const Arg *arg) 215 void 216 tile(Monitor *m) 217 { 218 - unsigned int i, n, h, mw, my, ty; 219 + unsigned int i, n, h, r, oe = enablegaps, ie = enablegaps, mw, my, ty; 220 Client *c; 221 222 for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); 223 if (n == 0) 224 return; 225 226 + if (smartgaps == n) { 227 + oe = 0; // outer gaps disabled 228 + } 229 + 230 if (n > m->nmaster) 231 - mw = m->nmaster ? m->ww * m->mfact : 0; 232 + mw = m->nmaster ? (m->ww + m->gappiv*ie) * m->mfact : 0; 233 else 234 - mw = m->ww; 235 - for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) 236 + mw = m->ww - 2*m->gappov*oe + m->gappiv*ie; 237 + for (i = 0, my = ty = m->gappoh*oe, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) 238 if (i < m->nmaster) { 239 - h = (m->wh - my) / (MIN(n, m->nmaster) - i); 240 - resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0); 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 + my += HEIGHT(c) + m->gappih*ie; 246 } else { 247 - h = (m->wh - ty) / (n - i); 248 - resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0); 249 - ty += HEIGHT(c); 250 + r = n - i; 251 + h = (m->wh - ty - m->gappoh*oe - m->gappih*ie * (r - 1)) / r; 252 + 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); 253 + ty += HEIGHT(c) + m->gappih*ie; 254 } 255 } 256 257 -- 258 2.7.4 259