dwm-status2d-20161231-bb3bd6f.diff (3985B)
1 diff --git a/dwm.c b/dwm.c 2 index d27cb67..464c9d6 100644 3 --- a/dwm.c 4 +++ b/dwm.c 5 @@ -163,6 +163,7 @@ static void detach(Client *c); 6 static void detachstack(Client *c); 7 static Monitor *dirtomon(int dir); 8 static void drawbar(Monitor *m); 9 +static int drawstatusbar(Monitor *m, int bh, char* text); 10 static void drawbars(void); 11 static void enternotify(XEvent *e); 12 static void expose(XEvent *e); 13 @@ -237,7 +238,7 @@ static void zoom(const Arg *arg); 14 15 /* variables */ 16 static const char broken[] = "broken"; 17 -static char stext[256]; 18 +static char stext[1024]; 19 static int screen; 20 static int sw, sh; /* X display screen geometry width, height */ 21 static int bh, blw = 0; /* bar geometry */ 22 @@ -483,7 +484,7 @@ cleanup(void) 23 cleanupmon(mons); 24 for (i = 0; i < CurLast; i++) 25 drw_cur_free(drw, cursor[i]); 26 - for (i = 0; i < LENGTH(colors); i++) 27 + for (i = 0; i < LENGTH(colors) + 1; i++) 28 free(scheme[i]); 29 XDestroyWindow(dpy, wmcheckwin); 30 drw_free(drw); 31 @@ -690,6 +691,106 @@ dirtomon(int dir) 32 return m; 33 } 34 35 +int 36 +drawstatusbar(Monitor *m, int bh, char* stext) { 37 + int ret, i, w, x, len; 38 + short isCode = 0; 39 + char *text; 40 + char *p; 41 + 42 + len = strlen(stext) + 1 ; 43 + if (!(text = (char*) malloc(sizeof(char)*len))) 44 + die("malloc"); 45 + p = text; 46 + memcpy(text, stext, len); 47 + 48 + /* compute width of the status text */ 49 + w = 0; 50 + i = -1; 51 + while (text[++i]) { 52 + if (text[i] == '^') { 53 + if (!isCode) { 54 + isCode = 1; 55 + text[i] = '\0'; 56 + w += TEXTW(text) - lrpad; 57 + text[i] = '^'; 58 + if (text[++i] == 'f') 59 + w += atoi(text + ++i); 60 + } else { 61 + isCode = 0; 62 + text = text + i + 1; 63 + i = -1; 64 + } 65 + } 66 + } 67 + if (!isCode) 68 + w += TEXTW(text) - lrpad; 69 + else 70 + isCode = 0; 71 + text = p; 72 + 73 + w += 2; /* 1px padding on both sides */ 74 + ret = x = m->ww - w; 75 + 76 + drw_setscheme(drw, scheme[LENGTH(colors)]); 77 + drw->scheme[ColFg] = scheme[SchemeNorm][ColFg]; 78 + drw_rect(drw, x, 0, w, bh, 1, 1); 79 + x++; 80 + 81 + /* process status text */ 82 + i = -1; 83 + while (text[++i]) { 84 + if (text[i] == '^' && !isCode) { 85 + isCode = 1; 86 + 87 + text[i] = '\0'; 88 + w = TEXTW(text) - lrpad; 89 + drw_text(drw, x, 0, w, bh, 0, text, 0); 90 + 91 + x += w; 92 + 93 + /* process code */ 94 + while (text[++i] != '^') { 95 + if (text[i] == 'c') { 96 + char buf[8]; 97 + memcpy(buf, (char*)text+i+1, 7); 98 + buf[7] = '\0'; 99 + drw_clr_create(drw, &drw->scheme[ColFg], buf); 100 + i += 7; 101 + } else if (text[i] == 'd') { 102 + drw->scheme[ColFg] = scheme[SchemeNorm][ColFg]; 103 + } else if (text[i] == 'r') { 104 + int rx = atoi(text + ++i); 105 + while (text[++i] != ','); 106 + int ry = atoi(text + ++i); 107 + while (text[++i] != ','); 108 + int rw = atoi(text + ++i); 109 + while (text[++i] != ','); 110 + int rh = atoi(text + ++i); 111 + 112 + drw_rect(drw, rx + x, ry, rw, rh, 1, 0); 113 + } else if (text[i] == 'f') { 114 + x += atoi(text + ++i); 115 + } 116 + } 117 + 118 + text = text + i + 1; 119 + i=-1; 120 + isCode = 0; 121 + } 122 + } 123 + 124 + if (!isCode) { 125 + w = TEXTW(text) - lrpad; 126 + drw_text(drw, x, 0, w, bh, 0, text, 0); 127 + } 128 + 129 + drw_setscheme(drw, scheme[SchemeNorm]); 130 + free(p); 131 + 132 + return ret; 133 +} 134 + 135 void 136 drawbar(Monitor *m) 137 { 138 @@ -701,9 +802,7 @@ drawbar(Monitor *m) 139 140 /* draw status first so it can be overdrawn by tags later */ 141 if (m == selmon) { /* status is only drawn on selected monitor */ 142 - drw_setscheme(drw, scheme[SchemeNorm]); 143 - sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ 144 - drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0); 145 + sw = m->ww - drawstatusbar(m, bh, stext); 146 } 147 148 for (c = m->clients; c; c = c->next) { 149 @@ -1572,7 +1671,8 @@ setup(void) 150 cursor[CurResize] = drw_cur_create(drw, XC_sizing); 151 cursor[CurMove] = drw_cur_create(drw, XC_fleur); 152 /* init appearance */ 153 - scheme = ecalloc(LENGTH(colors), sizeof(Scm)); 154 + scheme = ecalloc(LENGTH(colors) + 1, sizeof(Scm)); 155 + scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], 3); 156 for (i = 0; i < LENGTH(colors); i++) 157 scheme[i] = drw_scm_create(drw, colors[i], 3); 158 /* init bars */