bar_fancybar.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. int
  2. width_fancybar(Bar *bar, BarArg *a)
  3. {
  4. return a->w;
  5. }
  6. int
  7. draw_fancybar(Bar *bar, BarArg *a)
  8. {
  9. int tabw, mw, ew = 0, n = 0, tx, tw;
  10. unsigned int i;
  11. Client *c;
  12. Monitor *m = bar->mon;
  13. int x = a->x + lrpad / 2, w = a->w - lrpad;
  14. for (c = m->clients; c; c = c->next) {
  15. if (ISVISIBLE(c))
  16. n++;
  17. }
  18. if (n > 0) {
  19. tabw = TEXTW(m->sel->name);
  20. mw = (tabw >= w || n == 1) ? 0 : (w - tabw) / (n - 1);
  21. i = 0;
  22. for (c = m->clients; c; c = c->next) {
  23. if (!ISVISIBLE(c) || c == m->sel)
  24. continue;
  25. tabw = TEXTW(c->name);
  26. if (tabw < mw)
  27. ew += (mw - tabw);
  28. else
  29. i++;
  30. }
  31. if (i > 0)
  32. mw += ew / i;
  33. for (c = m->clients; c; c = c->next) {
  34. if (!ISVISIBLE(c))
  35. continue;
  36. tabw = MIN(m->sel == c ? w : mw, TEXTW(c->name));
  37. tx = x;
  38. tw = tabw;
  39. drw_setscheme(drw, scheme[m->sel == c ? SchemeTitleSel : SchemeTitleNorm]);
  40. XSetForeground(drw->dpy, drw->gc, drw->scheme[ColBg].pixel);
  41. XFillRectangle(drw->dpy, drw->drawable, drw->gc, tx, a->y, tw, a->h);
  42. if (tabw <= 0) /* trap special handling of 0 in drw_text */
  43. continue;
  44. tx += lrpad / 2;
  45. tw -= lrpad;
  46. drw_text(drw, tx, a->y, tw, a->h, 0, c->name, 0, False);
  47. drawstateindicator(c->mon, c, 1, x, a->y, tabw, a->h, 0, 0, c->isfixed);
  48. x += tabw;
  49. w -= tabw;
  50. }
  51. }
  52. return n;
  53. }
  54. int
  55. click_fancybar(Bar *bar, Arg *arg, BarArg *a)
  56. {
  57. return ClkWinTitle;
  58. }