dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

bar_status2d.c (6856B)


      1 #if BAR_STATUS2D_XRDB_TERMCOLORS_PATCH
      2 static char termcol0[]  = "#000000"; /* black   */
      3 static char termcol1[]  = "#ff0000"; /* red     */
      4 static char termcol2[]  = "#33ff00"; /* green   */
      5 static char termcol3[]  = "#ff0099"; /* yellow  */
      6 static char termcol4[]  = "#0066ff"; /* blue    */
      7 static char termcol5[]  = "#cc00ff"; /* magenta */
      8 static char termcol6[]  = "#00ffff"; /* cyan    */
      9 static char termcol7[]  = "#d0d0d0"; /* white   */
     10 static char termcol8[]  = "#808080"; /* black   */
     11 static char termcol9[]  = "#ff0000"; /* red     */
     12 static char termcol10[] = "#33ff00"; /* green   */
     13 static char termcol11[] = "#ff0099"; /* yellow  */
     14 static char termcol12[] = "#0066ff"; /* blue    */
     15 static char termcol13[] = "#cc00ff"; /* magenta */
     16 static char termcol14[] = "#00ffff"; /* cyan    */
     17 static char termcol15[] = "#ffffff"; /* white   */
     18 static char *termcolor[] = {
     19 	termcol0, termcol1, termcol2, termcol3, termcol4, termcol5, termcol6, termcol7,
     20 	termcol8, termcol9, termcol10, termcol11, termcol12, termcol13, termcol14, termcol15,
     21 };
     22 #endif // BAR_STATUS2D_XRDB_TERMCOLORS_PATCH
     23 
     24 int
     25 width_status2d(Bar *bar, BarArg *a)
     26 {
     27 	#if BAR_EXTRASTATUS_PATCH || BAR_STATUSCMD_PATCH
     28 	return status2dtextlength(rawstext);
     29 	#else
     30 	return status2dtextlength(stext);
     31 	#endif // #if BAR_EXTRASTATUS_PATCH | BAR_STATUSCMD_PATCH
     32 }
     33 
     34 #if BAR_EXTRASTATUS_PATCH
     35 int
     36 width_status2d_es(Bar *bar, BarArg *a)
     37 {
     38 	#if BAR_STATUSCMD_PATCH
     39 	return status2dtextlength(rawestext);
     40 	#else
     41 	return status2dtextlength(estext);
     42 	#endif // BAR_STATUSCMD_PATCH
     43 }
     44 #endif // BAR_EXTRASTATUS_PATCH
     45 
     46 int
     47 draw_status2d(Bar *bar, BarArg *a)
     48 {
     49 	#if BAR_EXTRASTATUS_PATCH || BAR_STATUSCMD_PATCH
     50 	return drawstatusbar(a, rawstext);
     51 	#else
     52 	return drawstatusbar(a, stext);
     53 	#endif // #if BAR_EXTRASTATUS_PATCH | BAR_STATUSCMD_PATCH
     54 }
     55 
     56 #if BAR_EXTRASTATUS_PATCH
     57 int
     58 draw_status2d_es(Bar *bar, BarArg *a)
     59 {
     60 	#if BAR_STATUSCMD_PATCH
     61 	return drawstatusbar(a, rawestext);
     62 	#else
     63 	return drawstatusbar(a, estext);
     64 	#endif // BAR_STATUSCMD_PATCH
     65 }
     66 #endif // BAR_EXTRASTATUS_PATCH
     67 
     68 #if !BAR_STATUSCMD_PATCH
     69 int
     70 click_status2d(Bar *bar, Arg *arg, BarArg *a)
     71 {
     72 	return ClkStatusText;
     73 }
     74 #endif // BAR_STATUSCMD_PATCH
     75 
     76 int
     77 drawstatusbar(BarArg *a, char* stext)
     78 {
     79 	int i, w, len;
     80 	int x = a->x;
     81 	int y = a->y;
     82 	short isCode = 0;
     83 	char *text;
     84 	char *p;
     85 	Clr oldbg, oldfg;
     86 	len = strlen(stext);
     87 	if (!(text = (char*) malloc(sizeof(char)*(len + 1))))
     88 		die("malloc");
     89 	p = text;
     90 	#if BAR_STATUSCMD_PATCH
     91 	copyvalidchars(text, stext);
     92 	#else
     93 	memcpy(text, stext, len);
     94 	#endif // BAR_STATUSCMD_PATCH
     95 	text[len] = '\0';
     96 
     97 	drw_setscheme(drw, scheme[LENGTH(colors)]);
     98 	drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
     99 	drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
    100 
    101 	/* process status text */
    102 	i = -1;
    103 	while (text[++i]) {
    104 		if (text[i] == '^' && !isCode) {
    105 			isCode = 1;
    106 
    107 			text[i] = '\0';
    108 			w = TEXTWM(text) - lrpad;
    109 			drw_text(drw, x, y, w, bh, 0, text, 0, True);
    110 
    111 			x += w;
    112 
    113 			/* process code */
    114 			while (text[++i] != '^') {
    115 				if (text[i] == 'c') {
    116 					char buf[8];
    117 					if (i + 7 >= len) {
    118 						i += 7;
    119 						len = 0;
    120 						break;
    121 					}
    122 					memcpy(buf, (char*)text+i+1, 7);
    123 					buf[7] = '\0';
    124 					#if BAR_ALPHA_PATCH && BAR_STATUS2D_NO_ALPHA_PATCH
    125 					drw_clr_create(drw, &drw->scheme[ColFg], buf, 0xff);
    126 					#elif BAR_ALPHA_PATCH
    127 					drw_clr_create(drw, &drw->scheme[ColFg], buf, alphas[SchemeNorm][ColFg]);
    128 					#else
    129 					drw_clr_create(drw, &drw->scheme[ColFg], buf);
    130 					#endif // BAR_ALPHA_PATCH
    131 					i += 7;
    132 				} else if (text[i] == 'b') {
    133 					char buf[8];
    134 					if (i + 7 >= len) {
    135 						i += 7;
    136 						len = 0;
    137 						break;
    138 					}
    139 					memcpy(buf, (char*)text+i+1, 7);
    140 					buf[7] = '\0';
    141 					#if BAR_ALPHA_PATCH && BAR_STATUS2D_NO_ALPHA_PATCH
    142 					drw_clr_create(drw, &drw->scheme[ColBg], buf, 0xff);
    143 					#elif BAR_ALPHA_PATCH
    144 					drw_clr_create(drw, &drw->scheme[ColBg], buf, alphas[SchemeNorm][ColBg]);
    145 					#else
    146 					drw_clr_create(drw, &drw->scheme[ColBg], buf);
    147 					#endif // BAR_ALPHA_PATCH
    148 					i += 7;
    149 				#if BAR_STATUS2D_XRDB_TERMCOLORS_PATCH
    150 				} else if (text[i] == 'C') {
    151 					int c = atoi(text + ++i) % 16;
    152 					#if BAR_ALPHA_PATCH && BAR_STATUS2D_NO_ALPHA_PATCH
    153 					drw_clr_create(drw, &drw->scheme[ColFg], termcolor[c], 0xff);
    154 					#elif BAR_ALPHA_PATCH
    155 					drw_clr_create(drw, &drw->scheme[ColFg], termcolor[c], alphas[SchemeNorm][ColBg]);
    156 					#else
    157 					drw_clr_create(drw, &drw->scheme[ColFg], termcolor[c]);
    158 					#endif // BAR_ALPHA_PATCH
    159 				} else if (text[i] == 'B') {
    160 					int c = atoi(text + ++i) % 16;
    161 					#if BAR_ALPHA_PATCH && BAR_STATUS2D_NO_ALPHA_PATCH
    162 					drw_clr_create(drw, &drw->scheme[ColBg], termcolor[c], 0xff);
    163 					#elif BAR_ALPHA_PATCH
    164 					drw_clr_create(drw, &drw->scheme[ColBg], termcolor[c], alphas[SchemeNorm][ColBg]);
    165 					#else
    166 					drw_clr_create(drw, &drw->scheme[ColBg], termcolor[c]);
    167 					#endif // BAR_ALPHA_PATCH
    168 				#endif // BAR_STATUS2D_XRDB_TERMCOLORS_PATCH
    169 				} else if (text[i] == 'd') {
    170 					drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
    171 					drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
    172 				} else if (text[i] == 'w') {
    173 					Clr swp;
    174 					swp = drw->scheme[ColFg];
    175 					drw->scheme[ColFg] = drw->scheme[ColBg];
    176 					drw->scheme[ColBg] = swp;
    177 				} else if (text[i] == 'v') {
    178 					oldfg = drw->scheme[ColFg];
    179 					oldbg = drw->scheme[ColBg];
    180 				} else if (text[i] == 't') {
    181 					drw->scheme[ColFg] = oldfg;
    182 					drw->scheme[ColBg] = oldbg;
    183 				} else if (text[i] == 'r') {
    184 					int rx = atoi(text + ++i);
    185 					while (text[++i] != ',');
    186 					int ry = atoi(text + ++i);
    187 					while (text[++i] != ',');
    188 					int rw = atoi(text + ++i);
    189 					while (text[++i] != ',');
    190 					int rh = atoi(text + ++i);
    191 
    192 					if (ry < 0)
    193 						ry = 0;
    194 					if (rx < 0)
    195 						rx = 0;
    196 
    197 					drw_rect(drw, rx + x, y + ry, rw, rh, 1, 0);
    198 				} else if (text[i] == 'f') {
    199 					x += atoi(text + ++i);
    200 				}
    201 			}
    202 
    203 			text = text + i + 1;
    204 			len -= i + 1;
    205 			i = -1;
    206 			isCode = 0;
    207 			if (len <= 0)
    208 				break;
    209 		}
    210 	}
    211 	if (!isCode && len > 0) {
    212 		w = TEXTWM(text) - lrpad;
    213 		drw_text(drw, x, y, w, bh, 0, text, 0, True);
    214 		x += w;
    215 	}
    216 	free(p);
    217 
    218 	drw_setscheme(drw, scheme[SchemeNorm]);
    219 	return 1;
    220 }
    221 
    222 int
    223 status2dtextlength(char* stext)
    224 {
    225 	int i, w, len;
    226 	short isCode = 0;
    227 	char *text;
    228 	char *p;
    229 
    230 	len = strlen(stext) + 1;
    231 	if (!(text = (char*) malloc(sizeof(char)*len)))
    232 		die("malloc");
    233 	p = text;
    234 	#if BAR_STATUSCMD_PATCH
    235 	copyvalidchars(text, stext);
    236 	#else
    237 	memcpy(text, stext, len);
    238 	#endif // BAR_STATUSCMD_PATCH
    239 
    240 	/* compute width of the status text */
    241 	w = 0;
    242 	i = -1;
    243 	while (text[++i]) {
    244 		if (text[i] == '^') {
    245 			if (!isCode) {
    246 				isCode = 1;
    247 				text[i] = '\0';
    248 				w += TEXTWM(text) - lrpad;
    249 				text[i] = '^';
    250 				if (text[++i] == 'f')
    251 					w += atoi(text + ++i);
    252 			} else {
    253 				isCode = 0;
    254 				text = text + i + 1;
    255 				i = -1;
    256 			}
    257 		}
    258 	}
    259 	if (!isCode)
    260 		w += TEXTWM(text) - lrpad;
    261 	free(p);
    262 	return w;
    263 }