My build of dwm
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

260 行
8.1 KiB

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