sites

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

dwm-5.8.2-statuscolors.diff (8515B)


      1 --- a/config.def.h      2010-10-16 15:49:03.000000000 +0200
      2 +++ b/config.def.h      2010-10-16 15:51:35.000000000 +0200
      3 @@ -1,13 +1,16 @@
      4  /* See LICENSE file for copyright and license details. */
      5  
      6  /* appearance */
      7 +#define NUMCOLORS         4             // need at least 3
      8 +static const char colors[NUMCOLORS][ColLast][8] = {
      9 +   // border   foreground  background
     10 +   { "#cccccc", "#000000", "#cccccc" },  // 0 = normal
     11 +   { "#0066ff", "#ffffff", "#0066ff" },  // 1 = selected
     12 +   { "#0066ff", "#0066ff", "#ffffff" },  // 2 = urgent/warning
     13 +   { "#ff0000", "#ffffff", "#ff0000" },  // 3 = error
     14 +   // add more here
     15 +};
     16  static const char font[]            = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
     17 -static const char normbordercolor[] = "#cccccc";
     18 -static const char normbgcolor[]     = "#cccccc";
     19 -static const char normfgcolor[]     = "#000000";
     20 -static const char selbordercolor[]  = "#0066ff";
     21 -static const char selbgcolor[]      = "#0066ff";
     22 -static const char selfgcolor[]      = "#ffffff";
     23  static const unsigned int borderpx  = 1;        /* border pixel of windows */
     24  static const unsigned int snap      = 32;       /* snap pixel */
     25  static const Bool showbar           = True;     /* False means no bar */
     26 @@ -45,7 +48,7 @@
     27  #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
     28  
     29  /* commands */
     30 -static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
     31 +static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", colors[0][ColBG], "-nf", colors[0][ColFG],"-sb", colors[1][ColBG], "-sf", colors[1][ColFG], NULL };
     32  static const char *termcmd[]  = { "uxterm", NULL };
     33  
     34  static Key keys[] = {
     35 --- a//dwm.c	2010-06-04 12:39:15.000000000 +0200
     36 +++ b/dwm.c	2010-11-03 20:36:50.000000000 +0100
     37 @@ -48,6 +48,7 @@
     38  #define LENGTH(X)               (sizeof X / sizeof X[0])
     39  #define MAX(A, B)               ((A) > (B) ? (A) : (B))
     40  #define MIN(A, B)               ((A) < (B) ? (A) : (B))
     41 +#define MAXCOLORS               8
     42  #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
     43  #define WIDTH(X)                ((X)->w + 2 * (X)->bw)
     44  #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
     45 @@ -97,8 +98,7 @@
     46  
     47  typedef struct {
     48  	int x, y, w, h;
     49 -	unsigned long norm[ColLast];
     50 -	unsigned long sel[ColLast];
     51 +	unsigned long colors[MAXCOLORS][ColLast];
     52  	Drawable drawable;
     53  	GC gc;
     54  	struct {
     55 @@ -175,8 +175,9 @@
     56  static Monitor *dirtomon(int dir);
     57  static void drawbar(Monitor *m);
     58  static void drawbars(void);
     59 -static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
     60 -static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
     61 +static void drawcoloredtext(char *text);
     62 +static void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]);
     63 +static void drawtext(const char *text, unsigned long col[ColLast], Bool pad);
     64  static void enternotify(XEvent *e);
     65  static void expose(XEvent *e);
     66  static void focus(Client *c);
     67 @@ -696,14 +697,13 @@
     68  	dc.x = 0;
     69  	for(i = 0; i < LENGTH(tags); i++) {
     70  		dc.w = TEXTW(tags[i]);
     71 -		col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm;
     72 -		drawtext(tags[i], col, urg & 1 << i);
     73 -		drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
     74 -		           occ & 1 << i, urg & 1 << i, col);
     75 +		col = dc.colors[ (m->tagset[m->seltags] & 1 << i ? 1:(urg & 1 << i ? 2:0))];
     76 +		drawtext(tags[i], col, True);
     77 +		drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i, occ & 1 << i, col);
     78  		dc.x += dc.w;
     79  	}
     80  	dc.w = blw = TEXTW(m->ltsymbol);
     81 -	drawtext(m->ltsymbol, dc.norm, False);
     82 +	drawtext(m->ltsymbol, dc.colors[0], True);
     83  	dc.x += dc.w;
     84  	x = dc.x;
     85  	if(m == selmon) { /* status is only drawn on selected monitor */
     86 @@ -713,19 +713,19 @@
     87  			dc.x = x;
     88  			dc.w = m->ww - x;
     89  		}
     90 -		drawtext(stext, dc.norm, False);
     91 +		drawcoloredtext(stext);
     92  	}
     93  	else
     94  		dc.x = m->ww;
     95  	if((dc.w = dc.x - x) > bh) {
     96  		dc.x = x;
     97  		if(m->sel) {
     98 -			col = m == selmon ? dc.sel : dc.norm;
     99 -			drawtext(m->sel->name, col, False);
    100 -			drawsquare(m->sel->isfixed, m->sel->isfloating, False, col);
    101 +			col = m == selmon ? dc.colors[1] : dc.colors[0];
    102 +			drawtext(m->sel->name, col, True);
    103 +			drawsquare(m->sel->isfixed, m->sel->isfloating, col);
    104  		}
    105  		else
    106 -			drawtext(NULL, dc.norm, False);
    107 +			drawtext(NULL, dc.colors[0], False);
    108  	}
    109  	XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
    110  	XSync(dpy, False);
    111 @@ -740,12 +740,42 @@
    112  }
    113  
    114  void
    115 -drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
    116 +drawcoloredtext(char *text) {
    117 +	Bool first=True;
    118 +	char *buf = text, *ptr = buf, c = 1;
    119 +	unsigned long *col = dc.colors[0];
    120 +	int i, ox = dc.x;
    121 +
    122 +	while( *ptr ) {
    123 +		for( i = 0; *ptr < 0 || *ptr > NUMCOLORS; i++, ptr++);
    124 +		if( !*ptr ) break;
    125 +		c=*ptr;
    126 +		*ptr=0;
    127 +		if( i ) {
    128 +			dc.w = selmon->ww - dc.x;
    129 +			drawtext(buf, col, first);
    130 +			dc.x += textnw(buf, i) + textnw(&c,1);
    131 +			if( first ) dc.x += ( dc.font.ascent + dc.font.descent ) / 2;
    132 +			first = False;
    133 +		} else if( first ) {
    134 +			ox = dc.x += textnw(&c,1);
    135 +		}
    136 +		*ptr = c;
    137 +		col = dc.colors[ c-1 ];
    138 +		buf = ++ptr;
    139 +	}
    140 +	if( !first ) dc.x-=(dc.font.ascent+dc.font.descent)/2;
    141 +	drawtext(buf, col, True);
    142 +	dc.x = ox;
    143 +}
    144 +
    145 +void
    146 +drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
    147  	int x;
    148  	XGCValues gcv;
    149  	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
    150  
    151 -	gcv.foreground = col[invert ? ColBG : ColFG];
    152 +	gcv.foreground = col[ ColFG ];
    153  	XChangeGC(dpy, dc.gc, GCForeground, &gcv);
    154  	x = (dc.font.ascent + dc.font.descent + 2) / 4;
    155  	r.x = dc.x + 1;
    156 @@ -761,18 +791,18 @@
    157  }
    158  
    159  void
    160 -drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
    161 +drawtext(const char *text, unsigned long col[ColLast], Bool pad) {
    162  	char buf[256];
    163  	int i, x, y, h, len, olen;
    164  	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
    165  
    166 -	XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
    167 +	XSetForeground(dpy, dc.gc, col[ ColBG ]);
    168  	XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
    169  	if(!text)
    170  		return;
    171  	olen = strlen(text);
    172 -	h = dc.font.ascent + dc.font.descent;
    173 -	y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
    174 +	h = pad ? (dc.font.ascent + dc.font.descent) : 0;
    175 +	y = dc.y + ((dc.h + dc.font.ascent - dc.font.descent) / 2);
    176  	x = dc.x + (h / 2);
    177  	/* shorten text if necessary */
    178  	for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--);
    179 @@ -781,7 +811,7 @@
    180  	memcpy(buf, text, len);
    181  	if(len < olen)
    182  		for(i = len; i && i > len - 3; buf[--i] = '.');
    183 -	XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
    184 +	XSetForeground(dpy, dc.gc, col[ ColFG ]);
    185  	if(dc.font.set)
    186  		XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
    187  	else
    188 @@ -830,7 +860,7 @@
    189  		detachstack(c);
    190  		attachstack(c);
    191  		grabbuttons(c, True);
    192 -		XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
    193 +		XSetWindowBorder(dpy, c->win, dc.colors[1][ColBorder]);
    194  		XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
    195  	}
    196  	else
    197 @@ -1139,7 +1169,7 @@
    198  	}
    199  	wc.border_width = c->bw;
    200  	XConfigureWindow(dpy, w, CWBorderWidth, &wc);
    201 -	XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
    202 +	XSetWindowBorder(dpy, w, dc.colors[0][ColBorder]);
    203  	configure(c); /* propagates border_width, if size doesn't change */
    204  	updatesizehints(c);
    205  	XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
    206 @@ -1544,12 +1574,11 @@
    207  	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
    208  	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
    209  	/* init appearance */
    210 -	dc.norm[ColBorder] = getcolor(normbordercolor);
    211 -	dc.norm[ColBG] = getcolor(normbgcolor);
    212 -	dc.norm[ColFG] = getcolor(normfgcolor);
    213 -	dc.sel[ColBorder] = getcolor(selbordercolor);
    214 -	dc.sel[ColBG] = getcolor(selbgcolor);
    215 -	dc.sel[ColFG] = getcolor(selfgcolor);
    216 +	for(int i=0; i<NUMCOLORS; i++) {
    217 +		dc.colors[i][ColBorder] = getcolor( colors[i][ColBorder] );
    218 +		dc.colors[i][ColFG] = getcolor( colors[i][ColFG] );
    219 +		dc.colors[i][ColBG] = getcolor( colors[i][ColBG] );
    220 +	}
    221  	dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
    222  	dc.gc = XCreateGC(dpy, root, 0, NULL);
    223  	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
    224 @@ -1711,7 +1740,7 @@
    225  	if(!c)
    226  		return;
    227  	grabbuttons(c, False);
    228 -	XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
    229 +	XSetWindowBorder(dpy, c->win, dc.colors[0][ColBorder]);
    230  	if(setfocus)
    231  		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
    232  }