sites

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

dwm-5.2-colorstatus.diff (4202B)


      1 diff -up dwm-5.2-original/colorstatus.c dwm-5.2-modified/colorstatus.c
      2 --- /dev/null	2008-11-17 18:12:14.000000000 +0100
      3 +++ dwm-5.2-modified/colorstatus.c	2008-11-17 18:09:29.000000000 +0100
      4 @@ -0,0 +1,144 @@
      5 +int
      6 +drawstatustext(int x) {
      7 +	char cd[] = "[c]", id[] = "[i]";
      8 +	char buf1[256] = {0};
      9 +	Bool parse = True;
     10 +	Bool cs = False, is = False;
     11 +	int stextw = 0;
     12 +	
     13 +	strcpy(buf1, stext);
     14 +	while(parse) {
     15 +		char *cp = 0, *ip = 0;
     16 +		
     17 +		cp = strstr(buf1, cd);
     18 +		ip = strstr(buf1, id);
     19 +		if(cp != NULL || ip != NULL) {
     20 +			char buf2[256] = {0}, buf3[256] = {0};
     21 +			size_t clen2 = -1, ilen2 = -1, len2 = 0, dlen = 0, offset3 = 0, len3 = 0;
     22 +			
     23 +			if(cp != NULL)
     24 +				clen2 = cp - buf1;
     25 +			if(ip != NULL)
     26 +				ilen2 = ip - buf1;
     27 +			if(clen2 < 0) {
     28 +				len2 = ilen2;
     29 +				dlen = strlen(id);
     30 +			}
     31 +			else if(ilen2 < 0) {
     32 +				len2 = clen2;
     33 +				dlen = strlen(cd);
     34 +			}
     35 +			else if(clen2 < ilen2) {
     36 +				len2 = clen2;
     37 +				dlen = strlen(cd);
     38 +			}
     39 +			else {
     40 +				len2 = ilen2;
     41 +				dlen = strlen(id);
     42 +			}
     43 +			strncpy(buf2, buf1, len2);
     44 +			offset3 = len2 + dlen;
     45 +			len3 = strlen(buf1) - offset3;
     46 +			strncpy(buf3, buf1 + offset3, len3);
     47 +			if(buf2 != NULL && strlen(buf2) > 0)
     48 +				stextw = stextw + TEXTW(buf2);
     49 +			
     50 +			memset(buf1, '\0', sizeof(buf1));
     51 +			strcpy(buf1, buf3);
     52 +		}
     53 +		else {
     54 +			stextw = stextw + TEXTW(buf1);
     55 +			parse = False;
     56 +		}
     57 +	}
     58 +	dc.x = ww - stextw;
     59 +	
     60 +	memset(buf1, '\0', sizeof(buf1));
     61 +	strcpy(buf1, stext);
     62 +	parse = True;
     63 +	while(parse) {
     64 +		char *cp = 0, *ip = 0;
     65 +		
     66 +		cp = strstr(buf1, cd);
     67 +		ip = strstr(buf1, id);
     68 +		if(cp != NULL || ip != NULL) {
     69 +			char buf2[256] = {0}, buf3[256] = {0};
     70 +			size_t clen2 = -1, ilen2 = -1, len2 = 0, dlen = 0, offset3 = 0, len3 = 0;
     71 +			Bool cs3 = cs, is3 = is;
     72 +			
     73 +			if(cp != NULL)
     74 +				clen2 = cp - buf1;
     75 +			if(ip != NULL)
     76 +				ilen2 = ip - buf1;
     77 +			if(clen2 < 0) {
     78 +				len2 = ilen2;
     79 +				dlen = strlen(id);
     80 +				is3 = !is;
     81 +			}
     82 +			else if(ilen2 < 0) {
     83 +				len2 = clen2;
     84 +				dlen = strlen(cd);
     85 +				cs3 = !cs;
     86 +			}
     87 +			else if(clen2 < ilen2) {
     88 +				len2 = clen2;
     89 +				dlen = strlen(cd);
     90 +				cs3 = !cs;
     91 +			}
     92 +			else {
     93 +				len2 = ilen2;
     94 +				dlen = strlen(id);
     95 +				is3 = !is;
     96 +			}
     97 +			
     98 +			strncpy(buf2, buf1, len2);
     99 +			offset3 = len2 + dlen;
    100 +			len3 = strlen(buf1) - offset3;
    101 +			strncpy(buf3, buf1 + offset3, len3);
    102 +			if(buf2 != NULL && strlen(buf2) > 0) {
    103 +				dc.w = TEXTW(buf2);
    104 +				if(cs) {
    105 +					if(is)
    106 +						drawtext(buf2, dc.sel, True);
    107 +					else
    108 +						drawtext(buf2, dc.sel, False);
    109 +				}
    110 +				else {
    111 +					if(is)
    112 +						drawtext(buf2, dc.norm, True);
    113 +					else
    114 +						drawtext(buf2, dc.norm, False);
    115 +				}
    116 +				dc.x = dc.x + dc.w;
    117 +			}
    118 +			
    119 +			cs = cs3;
    120 +			is = is3;
    121 +			memset(buf1, '\0', sizeof(buf1));
    122 +			strcpy(buf1, buf3);
    123 +		}
    124 +		else {
    125 +			dc.w = TEXTW(buf1);
    126 +			dc.x = ww - dc.w;
    127 +			if(dc.x < x) {
    128 +				dc.x = x;
    129 +				dc.w = ww - x;
    130 +			}
    131 +			if(cs) {
    132 +				if(is)
    133 +					drawtext(buf1, dc.sel, True);
    134 +				else
    135 +					drawtext(buf1, dc.sel, False);
    136 +			}
    137 +			else {
    138 +				if(is)
    139 +					drawtext(buf1, dc.norm, True);
    140 +				else
    141 +					drawtext(buf1, dc.norm, False);
    142 +			}
    143 +			parse = False;
    144 +		}
    145 +	}
    146 +	
    147 +	return(stextw);
    148 +}
    149 diff -up dwm-5.2-original/dwm.c dwm-5.2-modified/dwm.c
    150 --- dwm-5.2-original/dwm.c	2008-09-09 21:46:17.000000000 +0200
    151 +++ dwm-5.2-modified/dwm.c	2008-11-17 18:09:29.000000000 +0100
    152 @@ -239,6 +239,7 @@ static Layout *lt[] = { NULL, NULL };
    153  static Window root, barwin;
    154  /* configuration, allows nested code to access above variables */
    155  #include "config.h"
    156 +#include "colorstatus.c"
    157  
    158  /* compile-time check if all tags fit into an unsigned int bit array. */
    159  struct NumTags { char limitexceeded[sizeof(unsigned int) * 8 < LENGTH(tags) ? -1 : 1]; };
    160 @@ -495,6 +496,7 @@ drawbar(void) {
    161  	unsigned int i, occ = 0, urg = 0;
    162  	unsigned long *col;
    163  	Client *c;
    164 +	int stextw = 0;
    165  
    166  	for(c = clients; c; c = c->next) {
    167  		occ |= c->tags;
    168 @@ -517,13 +519,8 @@ drawbar(void) {
    169  	}
    170  	else
    171  		x = dc.x;
    172 -	dc.w = TEXTW(stext);
    173 -	dc.x = ww - dc.w;
    174 -	if(dc.x < x) {
    175 -		dc.x = x;
    176 -		dc.w = ww - x;
    177 -	}
    178 -	drawtext(stext, dc.norm, False);
    179 +	stextw = drawstatustext(x);
    180 +	dc.x = ww - stextw;
    181  	if((dc.w = dc.x - x) > bh) {
    182  		dc.x = x;
    183  		if(sel) {