diff options
-rw-r--r-- | draw.c | 53 | ||||
-rw-r--r-- | gadgets/gcpubar.c | 23 | ||||
-rw-r--r-- | gadgets/gdbar.c | 4 |
3 files changed, 51 insertions, 29 deletions
@@ -211,25 +211,38 @@ setcolor(Drawable *pm, int x, int width, long tfg, long tbg, int reverse, int no } static void -get_rect_vals(char *s, int *w, int *h) { - int i; +get_rect_vals(char *s, int *w, int *h, int *x, int *y) { + int i, j; char buf[128]; - *w = 0; *h = 0; + *w = 0; *h = 0; *x=~0; *y=~0; for(i=0; (s[i] != 'x') && i<128; i++) { buf[i] = s[i]; } - buf[++i] = '\0'; + buf[i] = '\0'; *w = atoi(buf); - *h = atoi(s+i); + + for(j=0, i++; s[i] != '+' && s[i] != '-' && j<128; j++, i++) + buf[j] = s[i]; + buf[j] = '\0'; + *h = atoi(buf); + + for(j=0, i++; s[i] != '+' && s[i] != '-' && j<128; j++, i++) + buf[j] = s[i]; + if(j<2) { + buf[j] = '\0'; + *x = atoi(buf); + *y = atoi(s+i); + } + } char * parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { unsigned int bm_w, bm_h; int bm_xh, bm_yh; - int rectw, recth, n_pos, recty; + int rectw, recth, n_pos, rectx, recty; int i, next_pos=0, j=0, px=0, py=0, xorig, h=0, tw, ow; char lbuf[MAX_LINE_LEN], *rbuf = NULL; int t=-1, nobg=0; @@ -352,27 +365,29 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { break; case rect: - get_rect_vals(tval, &rectw, &recth); + get_rect_vals(tval, &rectw, &recth, &rectx, &recty); rectw = rectw+px > dzen.w ? dzen.w-px : rectw; recth = recth > dzen.line_height ? dzen.line_height : recth; - recty = (dzen.line_height - recth)/2; + recty = recty == ~0 ? (dzen.line_height - recth)/2 : recty; + px = (rectx == ~0) ? px : rectx+px; setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg); - XFillRectangle(dzen.dpy, pm, dzen.tgc, px, (int)recty, rectw, recth); + XFillRectangle(dzen.dpy, pm, dzen.tgc, (int)px, (int)recty<0 ? dzen.line_height + recty : recty, rectw, recth); px += rectw; break; case recto: - get_rect_vals(tval, &rectw, &recth); + get_rect_vals(tval, &rectw, &recth, &rectx, &recty); if (!rectw) break; rectw = rectw+px > dzen.w ? dzen.w-px : rectw; recth = recth > dzen.line_height ? dzen.line_height-2 : recth-1; - recty = (dzen.line_height - recth)/2; + recty = recty == ~0 ? (dzen.line_height - recth)/2 : recty; + px = (rectx == ~0) ? px : rectx+px; /* prevent from stairs effect when rounding recty */ if (!((dzen.line_height - recth) % 2)) recty--; setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg); - XDrawRectangle(dzen.dpy, pm, dzen.tgc, px, (int)recty, rectw-1, recth); + XDrawRectangle(dzen.dpy, pm, dzen.tgc, (int)px, (int)recty<0 ? dzen.line_height + recty : recty, rectw-1, recth); px += rectw; break; @@ -494,27 +509,29 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { break; case rect: - get_rect_vals(tval, &rectw, &recth); + get_rect_vals(tval, &rectw, &recth, &rectx, &recty); rectw = rectw+px > dzen.w ? dzen.w-px : rectw; recth = recth > dzen.line_height ? dzen.line_height : recth; - recty = (dzen.line_height - recth)/2; + recty = (recty == ~0) ? (dzen.line_height - recth)/2 : recty; + px = (rectx == ~0) ? px : rectx+px; setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg); - XFillRectangle(dzen.dpy, pm, dzen.tgc, px, (int)recty, rectw, recth); + XFillRectangle(dzen.dpy, pm, dzen.tgc, (int)px, (int)recty<0 ? dzen.line_height + recty : recty, rectw, recth); px += rectw; break; case recto: - get_rect_vals(tval, &rectw, &recth); + get_rect_vals(tval, &rectw, &recth, &rectx, &recty); if (!rectw) break; rectw = rectw+px > dzen.w ? dzen.w-px : rectw; recth = recth > dzen.line_height ? dzen.line_height-2 : recth-1; - recty = (dzen.line_height - recth)/2; + recty = recty == ~0 ? (dzen.line_height - recth)/2 : recty; + px = (rectx == ~0) ? px : rectx+px; /* prevent from stairs effect when rounding recty */ if (!((dzen.line_height - recth) % 2)) recty--; setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg); - XDrawRectangle(dzen.dpy, pm, dzen.tgc, px, (int)recty, rectw-1, recth); + XDrawRectangle(dzen.dpy, pm, dzen.tgc, px, (int)recty<0 ? dzen.line_height + recty : recty, rectw-1, recth); px += rectw; break; diff --git a/gadgets/gcpubar.c b/gadgets/gcpubar.c index a55b781..4349cbf 100644 --- a/gadgets/gcpubar.c +++ b/gadgets/gcpubar.c @@ -32,7 +32,7 @@ THE SOFTWARE. /* bar color for critical values */ #define CRITCOL "red" -static void pbar (double, int, int, int, int); +static void pbar (const char *, double, int, int, int, int); struct cpu_info { unsigned long long user; @@ -44,7 +44,7 @@ struct cpu_info { char *bg, *fg; static void -pbar(double perc, int maxc, int height, int print_nl, int mode) { +pbar(const char *label, double perc, int maxc, int height, int print_nl, int mode) { int i, rp; double l; @@ -58,13 +58,13 @@ pbar(double perc, int maxc, int height, int print_nl, int mode) { rp = (int)perc; if(mode) - printf("CPU: %3d%% ^ib(1)^fg(%s)^ro(%dx%d)^p(%d)^fg(%s)^r(%dx%d)^p(%d)^ib(0)^fg()%s", - rp, bg, maxc, height, -1*(maxc-1), + printf("%s %3d%% ^ib(1)^fg(%s)^ro(%dx%d)^p(%d)^fg(%s)^r(%dx%d)^p(%d)^ib(0)^fg()%s", + label ? label : "", rp, bg, maxc, height, -1*(maxc-1), (rp>=CPUCRIT) ? CRITCOL : fg, (int)l, height-2, (maxc-1)-(int)l, print_nl ? "\n" : ""); else - printf("CPU: %3d%% ^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d)^fg()%s", - rp, (rp>=CPUCRIT) ? CRITCOL : fg, (int)l, height, - bg, maxc-(int)l, height, print_nl ? "\n" : ""); + printf("%s %3d%% ^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d)^fg()%s", + label ? label : "", rp, (rp>=CPUCRIT) ? CRITCOL : fg, (int)l, + height, bg, maxc-(int)l, height, print_nl ? "\n" : ""); fflush(stdout); } @@ -81,6 +81,7 @@ main(int argc, char *argv[]) struct cpu_info mcpu; FILE *statfp; char buf[256], *ep; + const char *label = NULL; /* defaults */ int mode = 0; @@ -133,11 +134,15 @@ main(int argc, char *argv[]) strcpy(bg, "darkgrey"); } } + else if(!strncmp(argv[i], "-l", 3)) { + if(++i < argc) + label = argv[i]; + } else if(!strncmp(argv[i], "-nonl", 6)) { print_nl = 0; } else { - printf("usage: %s [-i <interval>] [-c <count>] [-fg <color>] [-bg <color>] [-w <pixel>] [-h <pixel>] [-o] [-nonl]\n", argv[0]); + printf("usage: %s [-l <label>] [-i <interval>] [-c <count>] [-fg <color>] [-bg <color>] [-w <pixel>] [-h <pixel>] [-o] [-nonl]\n", argv[0]); return EXIT_FAILURE; } } @@ -179,7 +184,7 @@ main(int argc, char *argv[]) total = (mcpu.user + mcpu.sys + mcpu.idle + mcpu.iowait) / 100.0; myload = (mcpu.user + mcpu.sys + mcpu.iowait) / total; - pbar(myload, barwidth, barheight, print_nl, mode); + pbar(label, myload, barwidth, barheight, print_nl, mode); ocpu = ncpu; } } diff --git a/gadgets/gdbar.c b/gadgets/gdbar.c index f905542..89cd7ec 100644 --- a/gadgets/gdbar.c +++ b/gadgets/gdbar.c @@ -52,13 +52,13 @@ pbar(const char* label, double perc, int maxc, int height, int pnl, int mode) { rp = (int)perc; if(mode) - printf("%s %3d%% ^ib(1)^fg(%s)^ro(%dx%d)^p(%d)^fg(%s)^r(%dx%d)^p(%d)^ib(0)^fg()%s", + printf("%s%3d%% ^ib(1)^fg(%s)^ro(%dx%d)^p(%d)^fg(%s)^r(%dx%d)^p(%d)^ib(0)^fg()%s", label ? label : "", rp, bg, (int)maxc, height, -1*(maxc-1), fg, (int)l, height-2, maxc-(int)l-1, pnl ? "\n" : ""); else - printf("%s %3d%% ^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d)^fg()%s", + printf("%s%3d%% ^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d)^fg()%s", label ? label : "", rp, fg, (int)l, height, bg, maxc-(int)l, height, |