dotfiles

My collection of dotfiles
git clone git://git.stellar-nexus.ru/dotfiles
Log | Files | Refs

04-dwm-fancybar-20220527-d3f93c7.diff (1920B)


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