fibonacci.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. void
  2. fibonacci(Monitor *mon, int s) {
  3. unsigned int i, n, nx, ny, nw, nh;
  4. Client *c;
  5. for(n = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next), n++);
  6. if(n == 0)
  7. return;
  8. nx = mon->wx;
  9. ny = 0;
  10. nw = mon->ww;
  11. nh = mon->wh;
  12. for(i = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next)) {
  13. if((i % 2 && nh / 2 > 2 * c->bw)
  14. || (!(i % 2) && nw / 2 > 2 * c->bw)) {
  15. if(i < n - 1) {
  16. if(i % 2)
  17. nh /= 2;
  18. else
  19. nw /= 2;
  20. if((i % 4) == 2 && !s)
  21. nx += nw;
  22. else if((i % 4) == 3 && !s)
  23. ny += nh;
  24. }
  25. if((i % 4) == 0) {
  26. if(s)
  27. ny += nh;
  28. else
  29. ny -= nh;
  30. }
  31. else if((i % 4) == 1)
  32. nx += nw;
  33. else if((i % 4) == 2)
  34. ny += nh;
  35. else if((i % 4) == 3) {
  36. if(s)
  37. nx += nw;
  38. else
  39. nx -= nw;
  40. }
  41. if(i == 0)
  42. {
  43. if(n != 1)
  44. nw = mon->ww * mon->mfact;
  45. ny = mon->wy;
  46. }
  47. else if(i == 1)
  48. nw = mon->ww - nw;
  49. i++;
  50. }
  51. resize(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw, False);
  52. }
  53. }
  54. void
  55. dwindle(Monitor *mon) {
  56. fibonacci(mon, 1);
  57. }
  58. void
  59. spiral(Monitor *mon) {
  60. fibonacci(mon, 0);
  61. }