Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
4.3 KiB

  1. void
  2. centeredmaster(Monitor *m)
  3. {
  4. unsigned int i, n;
  5. int mx = 0, my = 0, mh = 0, mw = 0;
  6. int lx = 0, ly = 0, lw = 0, lh = 0;
  7. int rx = 0, ry = 0, rw = 0, rh = 0;
  8. float mfacts = 0, lfacts = 0, rfacts = 0;
  9. int mtotal = 0, ltotal = 0, rtotal = 0;
  10. int mrest = 0, lrest = 0, rrest = 0;
  11. Client *c;
  12. #if VANITYGAPS_PATCH
  13. int oh, ov, ih, iv;
  14. getgaps(m, &oh, &ov, &ih, &iv, &n);
  15. #else
  16. for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
  17. #endif // VANITYGAPS_PATCH
  18. if (n == 0)
  19. return;
  20. /* initialize areas */
  21. #if VANITYGAPS_PATCH
  22. mx = m->wx + ov;
  23. my = m->wy + oh;
  24. mh = m->wh - 2*oh - ih * ((!m->nmaster ? n : MIN(n, m->nmaster)) - 1);
  25. mw = m->ww - 2*ov;
  26. lh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - 1);
  27. rh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - ((n - m->nmaster) % 2 ? 0 : 1));
  28. if (m->nmaster && n > m->nmaster) {
  29. /* go mfact box in the center if more than nmaster clients */
  30. if (n - m->nmaster > 1) {
  31. /* ||<-S->|<---M--->|<-S->|| */
  32. mw = (m->ww - 2*ov - 2*iv) * m->mfact;
  33. lw = (m->ww - mw - 2*ov - 2*iv) / 2;
  34. mx += lw + iv;
  35. } else {
  36. /* ||<---M--->|<-S->|| */
  37. mw = (mw - iv) * m->mfact;
  38. lw = m->ww - mw - iv - 2*ov;
  39. }
  40. rw = lw;
  41. lx = m->wx + ov;
  42. ly = m->wy + oh;
  43. rx = mx + mw + iv;
  44. ry = m->wy + oh;
  45. }
  46. #else
  47. mx = m->wx;
  48. my = m->wy;
  49. mh = m->wh;
  50. mw = m->ww;
  51. lh = m->wh;
  52. rh = m->wh;
  53. if (m->nmaster && n > m->nmaster) {
  54. /* go mfact box in the center if more than nmaster clients */
  55. if (n - m->nmaster > 1) {
  56. /* ||<-S->|<---M--->|<-S->|| */
  57. mw = m->ww * m->mfact;
  58. lw = (m->ww - mw) / 2;
  59. mx += lw;
  60. } else {
  61. /* ||<---M--->|<-S->|| */
  62. mw = mw * m->mfact;
  63. lw = m->ww - mw;
  64. }
  65. rw = lw;
  66. lx = m->wx;
  67. ly = m->wy;
  68. rx = mx + mw;
  69. ry = m->wy;
  70. }
  71. #endif // VANITYGAPS_PATCH
  72. /* calculate facts */
  73. #if CFACTS_PATCH
  74. for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
  75. if (!m->nmaster || n < m->nmaster)
  76. mfacts += c->cfact; // total factor of master area
  77. else if ((n - m->nmaster) % 2)
  78. lfacts += c->cfact; // total factor of left hand stack area
  79. else
  80. rfacts += c->cfact; // total factor of right hand stack area
  81. }
  82. for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
  83. if (!m->nmaster || n < m->nmaster)
  84. mtotal += mh / mfacts;
  85. else if ((n - m->nmaster) % 2)
  86. ltotal += lh * (c->cfact / lfacts);
  87. else
  88. rtotal += rh * (c->cfact / rfacts);
  89. #else
  90. for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
  91. if (!m->nmaster || n < m->nmaster)
  92. mfacts += 1;
  93. else if ((n - m->nmaster) % 2)
  94. lfacts += 1; // total factor of left hand stack area
  95. else
  96. rfacts += 1; // total factor of right hand stack area
  97. }
  98. for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
  99. if (!m->nmaster || n < m->nmaster)
  100. mtotal += mh / mfacts;
  101. else if ((n - m->nmaster) % 2)
  102. ltotal += lh / lfacts;
  103. else
  104. rtotal += rh / rfacts;
  105. #endif // CFACTS_PATCH
  106. mrest = mh - mtotal;
  107. lrest = lh - ltotal;
  108. rrest = rh - rtotal;
  109. for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
  110. if (!m->nmaster || i < m->nmaster) {
  111. /* nmaster clients are stacked vertically, in the center of the screen */
  112. #if CFACTS_PATCH
  113. resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) * c->cfact + (i < mrest ? 1 : 0) - (2*c->bw), 0);
  114. #else
  115. resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
  116. #endif // CFACTS_PATCH
  117. #if VANITYGAPS_PATCH
  118. my += HEIGHT(c) + ih;
  119. #else
  120. my += HEIGHT(c);
  121. #endif
  122. } else {
  123. /* stack clients are stacked vertically */
  124. if ((i - m->nmaster) % 2 ) {
  125. #if CFACTS_PATCH
  126. resize(c, lx, ly, lw - (2*c->bw), (lh / lfacts) * c->cfact + ((i - 2*m->nmaster) < 2*lrest ? 1 : 0) - (2*c->bw), 0);
  127. #else
  128. resize(c, lx, ly, lw - (2*c->bw), (lh / lfacts) + ((i - 2*m->nmaster) < 2*lrest ? 1 : 0) - (2*c->bw), 0);
  129. #endif // CFACTS_PATCH
  130. #if VANITYGAPS_PATCH
  131. ly += HEIGHT(c) + ih;
  132. #else
  133. ly += HEIGHT(c);
  134. #endif
  135. } else {
  136. #if CFACTS_PATCH
  137. resize(c, rx, ry, rw - (2*c->bw), (rh / rfacts) * c->cfact + ((i - 2*m->nmaster) < 2*rrest ? 1 : 0) - (2*c->bw), 0);
  138. #else
  139. resize(c, rx, ry, rw - (2*c->bw), (rh / rfacts) + ((i - 2*m->nmaster) < 2*rrest ? 1 : 0) - (2*c->bw), 0);
  140. #endif // CFACTS_PATCH
  141. #if VANITYGAPS_PATCH
  142. ry += HEIGHT(c) + ih;
  143. #else
  144. ry += HEIGHT(c);
  145. #endif
  146. }
  147. }
  148. }
  149. }