dwm-fibonacci-6.2.diff 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. From ec9f55b6005cfa3b025b3d700c61af3ce539d057 Mon Sep 17 00:00:00 2001
  2. From: Niki Yoshiuchi <nyoshiuchi@gmail.com>
  3. Date: Sat, 18 Apr 2020 09:55:26 -0700
  4. Subject: [PATCH] Adding the fibonacci layout patch
  5. ---
  6. config.def.h | 5 ++++
  7. fibonacci.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  8. 2 files changed, 71 insertions(+)
  9. create mode 100644 fibonacci.c
  10. diff --git a/config.def.h b/config.def.h
  11. index 1c0b587..5708487 100644
  12. --- a/config.def.h
  13. +++ b/config.def.h
  14. @@ -36,11 +36,14 @@ static const float mfact = 0.55; /* factor of master area size [0.05..0.95]
  15. static const int nmaster = 1; /* number of clients in master area */
  16. static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
  17. +#include "fibonacci.c"
  18. static const Layout layouts[] = {
  19. /* symbol arrange function */
  20. { "[]=", tile }, /* first entry is default */
  21. { "><>", NULL }, /* no layout function means floating behavior */
  22. { "[M]", monocle },
  23. + { "[@]", spiral },
  24. + { "[\\]", dwindle },
  25. };
  26. /* key definitions */
  27. @@ -76,6 +79,8 @@ static Key keys[] = {
  28. { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
  29. { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
  30. { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
  31. + { MODKEY, XK_r, setlayout, {.v = &layouts[3]} },
  32. + { MODKEY|ShiftMask, XK_r, setlayout, {.v = &layouts[4]} },
  33. { MODKEY, XK_space, setlayout, {0} },
  34. { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
  35. { MODKEY, XK_0, view, {.ui = ~0 } },
  36. diff --git a/fibonacci.c b/fibonacci.c
  37. new file mode 100644
  38. index 0000000..fce0a57
  39. --- /dev/null
  40. +++ b/fibonacci.c
  41. @@ -0,0 +1,66 @@
  42. +void
  43. +fibonacci(Monitor *mon, int s) {
  44. + unsigned int i, n, nx, ny, nw, nh;
  45. + Client *c;
  46. +
  47. + for(n = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next), n++);
  48. + if(n == 0)
  49. + return;
  50. +
  51. + nx = mon->wx;
  52. + ny = 0;
  53. + nw = mon->ww;
  54. + nh = mon->wh;
  55. +
  56. + for(i = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next)) {
  57. + if((i % 2 && nh / 2 > 2 * c->bw)
  58. + || (!(i % 2) && nw / 2 > 2 * c->bw)) {
  59. + if(i < n - 1) {
  60. + if(i % 2)
  61. + nh /= 2;
  62. + else
  63. + nw /= 2;
  64. + if((i % 4) == 2 && !s)
  65. + nx += nw;
  66. + else if((i % 4) == 3 && !s)
  67. + ny += nh;
  68. + }
  69. + if((i % 4) == 0) {
  70. + if(s)
  71. + ny += nh;
  72. + else
  73. + ny -= nh;
  74. + }
  75. + else if((i % 4) == 1)
  76. + nx += nw;
  77. + else if((i % 4) == 2)
  78. + ny += nh;
  79. + else if((i % 4) == 3) {
  80. + if(s)
  81. + nx += nw;
  82. + else
  83. + nx -= nw;
  84. + }
  85. + if(i == 0)
  86. + {
  87. + if(n != 1)
  88. + nw = mon->ww * mon->mfact;
  89. + ny = mon->wy;
  90. + }
  91. + else if(i == 1)
  92. + nw = mon->ww - nw;
  93. + i++;
  94. + }
  95. + resize(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw, False);
  96. + }
  97. +}
  98. +
  99. +void
  100. +dwindle(Monitor *mon) {
  101. + fibonacci(mon, 1);
  102. +}
  103. +
  104. +void
  105. +spiral(Monitor *mon) {
  106. + fibonacci(mon, 0);
  107. +}
  108. --
  109. 2.20.1