sites

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

dwm-fancybar-5.6.1.diff (2771B)


      1 diff -r e47a47bd3ed4 dwm.c
      2 --- a/dwm.c	Tue Jul 21 10:57:54 2009 +0100
      3 +++ b/dwm.c	Mon Aug 24 18:28:57 2009 +0200
      4 @@ -169,6 +169,7 @@
      5  static Monitor *dirtomon(int dir);
      6  static void drawbar(Monitor *m);
      7  static void drawbars(void);
      8 +static void drawvline(unsigned long col[ColLast]);
      9  static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
     10  static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
     11  static void enternotify(XEvent *e);
     12 @@ -648,10 +649,11 @@
     13  
     14  void
     15  drawbar(Monitor *m) {
     16 -	int x;
     17 +	int x, ow, mw = 0, extra, tw;
     18  	unsigned int i, n = 0, occ = 0, urg = 0;
     19  	unsigned long *col;
     20 -	Client *c;
     21 +	Client *c, *firstvis, *lastvis = NULL;
     22 +	DC seldc;
     23  
     24  	for(c = m->clients; c; c = c->next) {
     25  		if(ISVISIBLE(c))
     26 @@ -689,16 +691,62 @@
     27  	}
     28  	else
     29  		dc.x = m->ww;
     30 -	if((dc.w = dc.x - x) > bh) {
     31 -		dc.x = x;
     32 -		if(m->sel) {
     33 -			col = m == selmon ? dc.sel : dc.norm;
     34 -			drawtext(m->sel->name, col, False);
     35 -			drawsquare(m->sel->isfixed, m->sel->isfloating, False, col);
     36 +
     37 +	for(c = m->clients; c && !ISVISIBLE(c); c = c->next);
     38 +	firstvis = c;
     39 +
     40 +	col = m == selmon ? dc.sel : dc.norm;
     41 +	dc.w = dc.x - x;
     42 +	dc.x = x;
     43 +
     44 +	if(n > 0) {
     45 +		mw = dc.w / n;
     46 +		extra = 0;
     47 +		seldc = dc;
     48 +		i = 0;
     49 +
     50 +		while(c) {
     51 +			lastvis = c;
     52 +			tw = TEXTW(c->name);
     53 +			if(tw < mw) extra += (mw - tw); else i++;
     54 +			for(c = c->next; c && !ISVISIBLE(c); c = c->next);
     55  		}
     56 -		else
     57 +
     58 +		if(i > 0) mw += extra / i;
     59 +
     60 +		c = firstvis;
     61 +		x = dc.x;
     62 +	}
     63 +
     64 +	while(dc.w > bh) {
     65 +		if(c) {
     66 +			ow = dc.w;
     67 +			tw = TEXTW(c->name);
     68 +			dc.w = MIN(ow, tw);
     69 +
     70 +			if(dc.w > mw) dc.w = mw;
     71 +			if(m->sel == c) seldc = dc;
     72 +			if(c == lastvis) dc.w = ow;
     73 +
     74 +			drawtext(c->name, col, False);
     75 +			if(c != firstvis) drawvline(col);
     76 +			drawsquare(c->isfixed, c->isfloating, False, col);
     77 +
     78 +			dc.x += dc.w;
     79 +			dc.w = ow - dc.w;
     80 +			for(c = c->next; c && !ISVISIBLE(c); c = c->next);
     81 +		} else {
     82  			drawtext(NULL, dc.norm, False);
     83 +			break;
     84 +		}
     85  	}
     86 +
     87 +	if(m == selmon && m->sel && ISVISIBLE(m->sel)) {
     88 +		dc = seldc;
     89 +		drawtext(m->sel->name, col, True);
     90 +		drawsquare(m->sel->isfixed, m->sel->isfloating, True, col);
     91 +	}
     92 +
     93  	XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
     94  	XSync(dpy, False);
     95  }
     96 @@ -709,6 +757,15 @@
     97  
     98  	for(m = mons; m; m = m->next)
     99  		drawbar(m);
    100 +}
    101 +
    102 +void
    103 +drawvline(unsigned long col[ColLast]) {
    104 +	XGCValues gcv;
    105 +
    106 +	gcv.foreground = col[ColFG];
    107 +	XChangeGC(dpy, dc.gc, GCForeground, &gcv);
    108 +	XDrawLine(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.x, dc.y + (dc.font.ascent + dc.font.descent + 2));
    109  }
    110  
    111  void
    112 @@ -1235,8 +1292,7 @@
    113  		}
    114  		if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
    115  			updatetitle(c);
    116 -			if(c == selmon->sel)
    117 -				drawbars();
    118 +			drawbars();
    119  		}
    120  	}
    121  }