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.

219 lines
6.1 KiB

  1. /* Bartabgroups properties, you can override these in your config.h if you want. */
  2. #ifndef BARTAB_BORDERS
  3. #define BARTAB_BORDERS 1 // 0 = off, 1 = on
  4. #endif
  5. #ifndef BARTAB_SHOWFLOATING
  6. #define BARTAB_SHOWFLOATING 0 // whether to show titles for floating windows, hidden clients are always shown
  7. #endif
  8. #ifndef BARTAB_STACKWEIGHT
  9. #define BARTAB_STACKWEIGHT 1 // stack weight compared to hidden and floating window titles
  10. #endif
  11. #ifndef BARTAB_HIDDENWEIGHT
  12. #define BARTAB_HIDDENWEIGHT 1 // hidden window title weight
  13. #endif
  14. #ifndef BARTAB_FLOATWEIGHT
  15. #define BARTAB_FLOATWEIGHT 1 // floating window title weight, set to 0 to not show floating windows
  16. #endif
  17. int
  18. width_bartabgroups(Bar *bar, BarArg *a)
  19. {
  20. return a->w;
  21. }
  22. int
  23. draw_bartabgroups(Bar *bar, BarArg *a)
  24. {
  25. drw_rect(drw, a->x, a->y, a->w, a->h, 1, 1);
  26. return bartabcalculate(bar->mon, a->x, a->w, -1, bartabdraw, NULL, a);
  27. }
  28. int
  29. click_bartabgroups(Bar *bar, Arg *arg, BarArg *a)
  30. {
  31. bartabcalculate(bar->mon, 0, a->w, a->x, bartabclick, arg, a);
  32. return ClkWinTitle;
  33. }
  34. void
  35. bartabdraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive, Arg *arg, BarArg *barg)
  36. {
  37. if (!c)
  38. return;
  39. int i, nclienttags = 0, nviewtags = 0, pad = lrpad / 2;
  40. drw_setscheme(drw, scheme[
  41. m->sel == c
  42. ? SchemeSel
  43. #ifdef HIDDEN
  44. : HIDDEN(c)
  45. ? SchemeHid
  46. #endif
  47. : groupactive
  48. ? SchemeTitleSel
  49. : SchemeTitleNorm
  50. ]);
  51. if (w <= TEXTW("A") - lrpad + pad) // reduce text padding if wintitle is too small
  52. pad = (w - TEXTW("A") + lrpad < 0 ? 0 : (w - TEXTW("A") + lrpad) / 2);
  53. #if BAR_CENTEREDWINDOWNAME_PATCH
  54. else if (TEXTW(c->name) < w)
  55. pad = (w - TEXTW(c->name) + lrpad) / 2;
  56. #endif // BAR_CENTEREDWINDOWNAME_PATCH
  57. drw_text(drw, x, barg->y, w, barg->h, pad, c->name, 0, False);
  58. drawstateindicator(m, c, 1, x, barg->y, w, barg->h, 0, 0, c->isfixed);
  59. if (BARTAB_BORDERS) {
  60. XSetForeground(drw->dpy, drw->gc, scheme[SchemeSel][ColBorder].pixel);
  61. XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, barg->y, 1, barg->h);
  62. XFillRectangle(drw->dpy, drw->drawable, drw->gc, x + w - (x + w >= barg->w ? 1 : 0), barg->y, 1, barg->h);
  63. }
  64. /* Optional tags icons */
  65. for (i = 0; i < NUMTAGS; i++) {
  66. if ((m->tagset[m->seltags] >> i) & 1)
  67. nviewtags++;
  68. if ((c->tags >> i) & 1)
  69. nclienttags++;
  70. }
  71. if (TAGSINDICATOR == 2 || nclienttags > 1 || nviewtags > 1)
  72. drawindicator(m, c, 1, x, barg->y, w, barg->h, 0, 0, 0, INDICATOR_RIGHT_TAGS);
  73. }
  74. #ifndef HIDDEN
  75. #define HIDDEN(C) 0
  76. #endif
  77. void
  78. bartabclick(Monitor *m, Client *c, int passx, int x, int w, int unused, Arg *arg, BarArg *barg)
  79. {
  80. if (passx >= x && passx <= x + w)
  81. arg->v = c;
  82. }
  83. int
  84. bartabcalculate(
  85. Monitor *m, int offx, int tabw, int passx,
  86. void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg, BarArg *barg),
  87. Arg *arg, BarArg *barg
  88. ) {
  89. Client *c;
  90. int
  91. i, clientsnmaster = 0, clientsnstack = 0, clientsnfloating = 0, clientsnhidden = 0,
  92. masteractive = 0, fulllayout = 0,
  93. x = offx, w, r, num = 0, den, tgactive;
  94. for (i = 0; i < LENGTH(bartabmonfns); i++)
  95. if (m ->lt[m->sellt]->arrange == bartabmonfns[i]) {
  96. fulllayout = 1;
  97. break;
  98. }
  99. for (i = 0, c = m->clients; c; c = c->next) {
  100. if (!ISVISIBLE(c))
  101. continue;
  102. if (HIDDEN(c)) {
  103. clientsnhidden++;
  104. continue;
  105. }
  106. if (c->isfloating) {
  107. clientsnfloating++;
  108. continue;
  109. }
  110. if (m->sel == c)
  111. masteractive = i < m->nmaster;
  112. if (i < m->nmaster)
  113. clientsnmaster++;
  114. else
  115. clientsnstack++;
  116. i++;
  117. }
  118. if (clientsnmaster + clientsnstack + clientsnfloating + clientsnhidden == 0)
  119. return 0;
  120. tgactive = 1;
  121. num = tabw;
  122. /* floating mode */
  123. if ((fulllayout && BARTAB_FLOATWEIGHT) || clientsnmaster + clientsnstack == 0 || !m->lt[m->sellt]->arrange) {
  124. den = clientsnmaster + clientsnstack + clientsnfloating + clientsnhidden;
  125. r = num % den;
  126. w = num / den;
  127. for (c = m->clients, i = 0; c; c = c->next) {
  128. if (!ISVISIBLE(c))
  129. continue;
  130. tabfn(m, c, passx, x, w + (i < r ? 1 : 0), tgactive, arg, barg);
  131. x += w + (i < r ? 1 : 0);
  132. i++;
  133. }
  134. /* no master and stack mode, e.g. monocole, grid layouts, fibonacci */
  135. } else if (fulllayout) {
  136. den = clientsnmaster + clientsnstack + clientsnhidden;
  137. r = num % den;
  138. w = num / den;
  139. for (c = m->clients, i = 0; c; c = c->next) {
  140. if (!ISVISIBLE(c) || (c->isfloating && !HIDDEN(c)))
  141. continue;
  142. tabfn(m, c, passx, x, w + (i < r ? 1 : 0), tgactive, arg, barg);
  143. x += w + (i < r ? 1 : 0);
  144. i++;
  145. }
  146. /* tiled mode */
  147. } else {
  148. den = clientsnmaster;
  149. c = m->clients;
  150. i = 0;
  151. if (den) {
  152. if (clientsnstack + clientsnfloating * BARTAB_FLOATWEIGHT + clientsnhidden) {
  153. tgactive = masteractive;
  154. num = tabw * m->mfact;
  155. }
  156. r = num % den;
  157. w = num / den;
  158. for (; c && i < m->nmaster; c = c->next) { // tiled master
  159. if (!ISVISIBLE(c) || c->isfloating || HIDDEN(c))
  160. continue;
  161. tabfn(m, c, passx, x, w + (i < r ? 1 : 0), tgactive, arg, barg);
  162. x += w + (i < r ? 1 : 0);
  163. i++;
  164. }
  165. tgactive = !tgactive;
  166. num = tabw - num;
  167. }
  168. den = clientsnstack * BARTAB_STACKWEIGHT + clientsnfloating * BARTAB_FLOATWEIGHT + clientsnhidden * BARTAB_HIDDENWEIGHT;
  169. if (!den)
  170. return 1;
  171. r = num % den;
  172. w = num / den;
  173. #if BARTAB_STACKWEIGHT
  174. for (; c; c = c->next) { // tiled stack
  175. if (!ISVISIBLE(c) || HIDDEN(c) || c->isfloating)
  176. continue;
  177. tabfn(m, c, passx, x, w * BARTAB_STACKWEIGHT + (i - m->nmaster < r ? 1 : 0), tgactive, arg, barg);
  178. x += w * BARTAB_STACKWEIGHT + (i - m->nmaster < r ? 1 : 0);
  179. i++;
  180. }
  181. #endif // BARTAB_STACKWEIGHT
  182. #if BARTAB_HIDDENWEIGHT
  183. for (c = m->clients; c; c = c->next) { // hidden windows
  184. if (!ISVISIBLE(c) || !HIDDEN(c))
  185. continue;
  186. tabfn(m, c, passx, x, w * BARTAB_HIDDENWEIGHT + (i - m->nmaster < r ? 1 : 0), tgactive, arg, barg);
  187. x += w * BARTAB_HIDDENWEIGHT + (i - m->nmaster < r ? 1 : 0);
  188. i++;
  189. }
  190. #endif // BARTAB_HIDDENWEIGHT
  191. #if BARTAB_FLOATWEIGHT
  192. for (c = m->clients; c; c = c->next) { // floating windows
  193. if (!ISVISIBLE(c) || HIDDEN(c) || !c->isfloating)
  194. continue;
  195. tabfn(m, c, passx, x, w * BARTAB_FLOATWEIGHT + (i - m->nmaster < r ? 1 : 0), tgactive, arg, barg);
  196. x += w * BARTAB_FLOATWEIGHT + (i - m->nmaster < r ? 1 : 0);
  197. i++;
  198. }
  199. #endif // BARTAB_FLOATWEIGHT
  200. }
  201. return 1;
  202. }