|
|
-
- int
- width_status2d(Bar *bar, BarArg *a)
- {
- int width;
- width = status2dtextlength(rawstext);
- return width ? width + lrpad : 0;
- }
-
-
- int
- draw_status2d(Bar *bar, BarArg *a)
- {
- return drawstatusbar(a, rawstext);
- }
-
-
-
- int
- drawstatusbar(BarArg *a, char* stext)
- {
- int i, w, len;
- int x = a->x;
- int y = a->y;
- short isCode = 0;
- char *text;
- char *p;
- Clr oldbg, oldfg;
- len = strlen(stext) + 1;
- if (!(text = (char*) malloc(sizeof(char)*len)))
- die("malloc");
- p = text;
- copyvalidchars(text, stext);
-
- x += lrpad / 2;
- drw_setscheme(drw, scheme[LENGTH(colors)]);
- drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
- drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
-
- /* process status text */
- i = -1;
- while (text[++i]) {
- if (text[i] == '^' && !isCode) {
- isCode = 1;
-
- text[i] = '\0';
- w = TEXTWM(text) - lrpad;
- drw_text(drw, x, y, w, bh, 0, text, 0, True);
-
- x += w;
-
- /* process code */
- while (text[++i] != '^') {
- if (text[i] == 'c') {
- char buf[8];
- if (i + 7 > len) {
- i += 7;
- break;
- }
- memcpy(buf, (char*)text+i+1, 7);
- buf[7] = '\0';
- drw_clr_create(drw, &drw->scheme[ColFg], buf);
- i += 7;
- } else if (text[i] == 'b') {
- char buf[8];
- if (i + 7 > len) {
- i += 7;
- break;
- }
- memcpy(buf, (char*)text+i+1, 7);
- buf[7] = '\0';
- drw_clr_create(drw, &drw->scheme[ColBg], buf);
- i += 7;
- } else if (text[i] == 'd') {
- drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
- drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
- } else if (text[i] == 'w') {
- Clr swp;
- swp = drw->scheme[ColFg];
- drw->scheme[ColFg] = drw->scheme[ColBg];
- drw->scheme[ColBg] = swp;
- } else if (text[i] == 'v') {
- oldfg = drw->scheme[ColFg];
- oldbg = drw->scheme[ColBg];
- } else if (text[i] == 't') {
- drw->scheme[ColFg] = oldfg;
- drw->scheme[ColBg] = oldbg;
- } else if (text[i] == 'r') {
- int rx = atoi(text + ++i);
- while (text[++i] != ',');
- int ry = atoi(text + ++i);
- while (text[++i] != ',');
- int rw = atoi(text + ++i);
- while (text[++i] != ',');
- int rh = atoi(text + ++i);
-
- if (ry < 0)
- ry = 0;
- if (rx < 0)
- rx = 0;
-
- drw_rect(drw, rx + x, y + ry, rw, rh, 1, 0);
- } else if (text[i] == 'f') {
- x += atoi(text + ++i);
- }
- }
-
- text = text + i + 1;
- i=-1;
- isCode = 0;
- }
- }
- if (!isCode) {
- w = TEXTWM(text) - lrpad;
- drw_text(drw, x, y, w, bh, 0, text, 0, True);
- x += w;
- }
- free(p);
-
- drw_setscheme(drw, scheme[SchemeNorm]);
- return len - 1;
- }
-
- int
- status2dtextlength(char* stext)
- {
- int i, w, len;
- short isCode = 0;
- char *text;
- char *p;
-
- len = strlen(stext) + 1;
- if (!(text = (char*) malloc(sizeof(char)*len)))
- die("malloc");
- p = text;
- copyvalidchars(text, stext);
-
- /* compute width of the status text */
- w = 0;
- i = -1;
- while (text[++i]) {
- if (text[i] == '^') {
- if (!isCode) {
- isCode = 1;
- text[i] = '\0';
- w += TEXTWM(text) - lrpad;
- text[i] = '^';
- if (text[++i] == 'f')
- w += atoi(text + ++i);
- } else {
- isCode = 0;
- text = text + i + 1;
- i = -1;
- }
- }
- }
- if (!isCode)
- w += TEXTWM(text) - lrpad;
- free(p);
- return w;
- }
|