My dwm build
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.
 
 
 
 
 

143 lines
4.3 KiB

  1. diff --git a/config.def.h b/config.def.h
  2. index 7054c06..527b214 100644
  3. --- a/config.def.h
  4. +++ b/config.def.h
  5. @@ -39,6 +39,8 @@ static const Layout layouts[] = {
  6. { "[]=", tile }, /* first entry is default */
  7. { "><>", NULL }, /* no layout function means floating behavior */
  8. { "[M]", monocle },
  9. + { "|M|", centeredmaster },
  10. + { ">M>", centeredfloatingmaster },
  11. };
  12. /* key definitions */
  13. @@ -74,6 +76,8 @@ static Key keys[] = {
  14. { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
  15. { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
  16. { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
  17. + { MODKEY, XK_u, setlayout, {.v = &layouts[3]} },
  18. + { MODKEY, XK_o, setlayout, {.v = &layouts[4]} },
  19. { MODKEY, XK_space, setlayout, {0} },
  20. { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
  21. { MODKEY, XK_0, view, {.ui = ~0 } },
  22. diff --git a/dwm.c b/dwm.c
  23. index 0362114..1e81412 100644
  24. --- a/dwm.c
  25. +++ b/dwm.c
  26. @@ -233,6 +233,8 @@ static int xerror(Display *dpy, XErrorEvent *ee);
  27. static int xerrordummy(Display *dpy, XErrorEvent *ee);
  28. static int xerrorstart(Display *dpy, XErrorEvent *ee);
  29. static void zoom(const Arg *arg);
  30. +static void centeredmaster(Monitor *m);
  31. +static void centeredfloatingmaster(Monitor *m);
  32. /* variables */
  33. static const char broken[] = "broken";
  34. @@ -2139,3 +2141,106 @@ main(int argc, char *argv[])
  35. XCloseDisplay(dpy);
  36. return EXIT_SUCCESS;
  37. }
  38. +
  39. +void
  40. +centeredmaster(Monitor *m)
  41. +{
  42. + unsigned int i, n, h, mw, mx, my, oty, ety, tw;
  43. + Client *c;
  44. +
  45. + /* count number of clients in the selected monitor */
  46. + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
  47. + if (n == 0)
  48. + return;
  49. +
  50. + /* initialize areas */
  51. + mw = m->ww;
  52. + mx = 0;
  53. + my = 0;
  54. + tw = mw;
  55. +
  56. + if (n > m->nmaster) {
  57. + /* go mfact box in the center if more than nmaster clients */
  58. + mw = m->nmaster ? m->ww * m->mfact : 0;
  59. + tw = m->ww - mw;
  60. +
  61. + if (n - m->nmaster > 1) {
  62. + /* only one client */
  63. + mx = (m->ww - mw) / 2;
  64. + tw = (m->ww - mw) / 2;
  65. + }
  66. + }
  67. +
  68. + oty = 0;
  69. + ety = 0;
  70. + for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
  71. + if (i < m->nmaster) {
  72. + /* nmaster clients are stacked vertically, in the center
  73. + * of the screen */
  74. + h = (m->wh - my) / (MIN(n, m->nmaster) - i);
  75. + resize(c, m->wx + mx, m->wy + my, mw - (2*c->bw),
  76. + h - (2*c->bw), 0);
  77. + my += HEIGHT(c);
  78. + } else {
  79. + /* stack clients are stacked vertically */
  80. + if ((i - m->nmaster) % 2 ) {
  81. + h = (m->wh - ety) / ( (1 + n - i) / 2);
  82. + resize(c, m->wx, m->wy + ety, tw - (2*c->bw),
  83. + h - (2*c->bw), 0);
  84. + ety += HEIGHT(c);
  85. + } else {
  86. + h = (m->wh - oty) / ((1 + n - i) / 2);
  87. + resize(c, m->wx + mx + mw, m->wy + oty,
  88. + tw - (2*c->bw), h - (2*c->bw), 0);
  89. + oty += HEIGHT(c);
  90. + }
  91. + }
  92. +}
  93. +
  94. +void
  95. +centeredfloatingmaster(Monitor *m)
  96. +{
  97. + unsigned int i, n, w, mh, mw, mx, mxo, my, myo, tx;
  98. + Client *c;
  99. +
  100. + /* count number of clients in the selected monitor */
  101. + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
  102. + if (n == 0)
  103. + return;
  104. +
  105. + /* initialize nmaster area */
  106. + if (n > m->nmaster) {
  107. + /* go mfact box in the center if more than nmaster clients */
  108. + if (m->ww > m->wh) {
  109. + mw = m->nmaster ? m->ww * m->mfact : 0;
  110. + mh = m->nmaster ? m->wh * 0.9 : 0;
  111. + } else {
  112. + mh = m->nmaster ? m->wh * m->mfact : 0;
  113. + mw = m->nmaster ? m->ww * 0.9 : 0;
  114. + }
  115. + mx = mxo = (m->ww - mw) / 2;
  116. + my = myo = (m->wh - mh) / 2;
  117. + } else {
  118. + /* go fullscreen if all clients are in the master area */
  119. + mh = m->wh;
  120. + mw = m->ww;
  121. + mx = mxo = 0;
  122. + my = myo = 0;
  123. + }
  124. +
  125. + for(i = tx = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
  126. + if (i < m->nmaster) {
  127. + /* nmaster clients are stacked horizontally, in the center
  128. + * of the screen */
  129. + w = (mw + mxo - mx) / (MIN(n, m->nmaster) - i);
  130. + resize(c, m->wx + mx, m->wy + my, w - (2*c->bw),
  131. + mh - (2*c->bw), 0);
  132. + mx += WIDTH(c);
  133. + } else {
  134. + /* stack clients are stacked horizontally */
  135. + w = (m->ww - tx) / (n - i);
  136. + resize(c, m->wx + tx, m->wy, w - (2*c->bw),
  137. + m->wh - (2*c->bw), 0);
  138. + tx += WIDTH(c);
  139. + }
  140. +}