sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-fancybar-20200423-ed3ab6b.diff (2017B)


      1 diff --git a/dwm.c b/dwm.c
      2 index fb1e326..941293e 100644
      3 --- a/dwm.c
      4 +++ b/dwm.c
      5 @@ -696,10 +696,10 @@ dirtomon(int dir)
      6  void
      7  drawbar(Monitor *m)
      8  {
      9 -	int x, w, tw = 0;
     10 +	int x, w, tw = 0, mw, ew = 0;
     11  	int boxs = drw->fonts->h / 9;
     12  	int boxw = drw->fonts->h / 6 + 2;
     13 -	unsigned int i, occ = 0, urg = 0;
     14 +	unsigned int i, occ = 0, urg = 0, n = 0;
     15  	Client *c;
     16  
     17  	/* draw status first so it can be overdrawn by tags later */
     18 @@ -710,6 +710,8 @@ drawbar(Monitor *m)
     19  	}
     20  
     21  	for (c = m->clients; c; c = c->next) {
     22 +		if (ISVISIBLE(c))
     23 +			n++;
     24  		occ |= c->tags;
     25  		if (c->isurgent)
     26  			urg |= c->tags;
     27 @@ -730,15 +732,39 @@ drawbar(Monitor *m)
     28  	x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
     29  
     30  	if ((w = m->ww - tw - x) > bh) {
     31 -		if (m->sel) {
     32 -			drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
     33 -			drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
     34 -			if (m->sel->isfloating)
     35 -				drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
     36 -		} else {
     37 -			drw_setscheme(drw, scheme[SchemeNorm]);
     38 -			drw_rect(drw, x, 0, w, bh, 1, 1);
     39 +		if (n > 0) {
     40 +			tw = TEXTW(m->sel->name) + lrpad;
     41 +			mw = (tw >= w || n == 1) ? 0 : (w - tw) / (n - 1);
     42 +
     43 +			i = 0;
     44 +			for (c = m->clients; c; c = c->next) {
     45 +				if (!ISVISIBLE(c) || c == m->sel)
     46 +					continue;
     47 +				tw = TEXTW(c->name);
     48 +				if(tw < mw)
     49 +					ew += (mw - tw);
     50 +				else
     51 +					i++;
     52 +			}
     53 +			if (i > 0)
     54 +				mw += ew / i;
     55 +
     56 +			for (c = m->clients; c; c = c->next) {
     57 +				if (!ISVISIBLE(c))
     58 +					continue;
     59 +				tw = MIN(m->sel == c ? w : mw, TEXTW(c->name));
     60 +
     61 +				drw_setscheme(drw, scheme[m->sel == c ? SchemeSel : SchemeNorm]);
     62 +				if (tw > 0) /* trap special handling of 0 in drw_text */
     63 +					drw_text(drw, x, 0, tw, bh, lrpad / 2, c->name, 0);
     64 +				if (c->isfloating)
     65 +					drw_rect(drw, x + boxs, boxs, boxw, boxw, c->isfixed, 0);
     66 +				x += tw;
     67 +				w -= tw;
     68 +			}
     69  		}
     70 +		drw_setscheme(drw, scheme[SchemeNorm]);
     71 +		drw_rect(drw, x, 0, w, bh, 1, 1);
     72  	}
     73  	drw_map(drw, m->barwin, 0, 0, m->ww, bh);
     74  }