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.

84 lines
2.4 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. int oh, ov, ih, iv;
  13. getgaps(m, &oh, &ov, &ih, &iv, &n);
  14. if (n == 0)
  15. return;
  16. /* initialize areas */
  17. mx = m->wx + ov;
  18. my = m->wy + oh;
  19. mh = m->wh - 2*oh - ih * ((!m->nmaster ? n : MIN(n, m->nmaster)) - 1);
  20. mw = m->ww - 2*ov;
  21. lh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - 1);
  22. rh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - ((n - m->nmaster) % 2 ? 0 : 1));
  23. if (m->nmaster && n > m->nmaster) {
  24. /* go mfact box in the center if more than nmaster clients */
  25. if (n - m->nmaster > 1) {
  26. /* ||<-S->|<---M--->|<-S->|| */
  27. mw = (m->ww - 2*ov - 2*iv) * m->mfact;
  28. lw = (m->ww - mw - 2*ov - 2*iv) / 2;
  29. mx += lw + iv;
  30. } else {
  31. /* ||<---M--->|<-S->|| */
  32. mw = (mw - iv) * m->mfact;
  33. lw = m->ww - mw - iv - 2*ov;
  34. }
  35. rw = lw;
  36. lx = m->wx + ov;
  37. ly = m->wy + oh;
  38. rx = mx + mw + iv;
  39. ry = m->wy + oh;
  40. }
  41. /* calculate facts */
  42. for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
  43. if (!m->nmaster || n < m->nmaster)
  44. mfacts += 1;
  45. else if ((n - m->nmaster) % 2)
  46. lfacts += 1; // total factor of left hand stack area
  47. else
  48. rfacts += 1; // total factor of right hand stack area
  49. }
  50. for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
  51. if (!m->nmaster || n < m->nmaster)
  52. mtotal += mh / mfacts;
  53. else if ((n - m->nmaster) % 2)
  54. ltotal += lh / lfacts;
  55. else
  56. rtotal += rh / rfacts;
  57. mrest = mh - mtotal;
  58. lrest = lh - ltotal;
  59. rrest = rh - rtotal;
  60. for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
  61. if (!m->nmaster || i < m->nmaster) {
  62. /* nmaster clients are stacked vertically, in the center of the screen */
  63. resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
  64. my += HEIGHT(c) + ih;
  65. } else {
  66. /* stack clients are stacked vertically */
  67. if ((i - m->nmaster) % 2 ) {
  68. resize(c, lx, ly, lw - (2*c->bw), (lh / lfacts) + ((i - 2*m->nmaster) < 2*lrest ? 1 : 0) - (2*c->bw), 0);
  69. ly += HEIGHT(c) + ih;
  70. } else {
  71. resize(c, rx, ry, rw - (2*c->bw), (rh / rfacts) + ((i - 2*m->nmaster) < 2*rrest ? 1 : 0) - (2*c->bw), 0);
  72. ry += HEIGHT(c) + ih;
  73. }
  74. }
  75. }
  76. }