diff --git a/src/conky.c b/src/conky.c index eb0a1d00..9bc08e4c 100644 --- a/src/conky.c +++ b/src/conky.c @@ -699,6 +699,7 @@ static void free_text_objects(struct text_object *root) case OBJ_font: case OBJ_image: case OBJ_exec: + case OBJ_execgauge: case OBJ_execbar: case OBJ_execgraph: case OBJ_execp: @@ -1283,6 +1284,9 @@ static struct text_object *construct_text_object(const char *s, } else { obj->data.cpu_index = 0; } + END OBJ(cpugauge, INFO_CPU) + scan_gauge(arg, &obj->a, &obj->b); + DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index); END OBJ(cpubar, INFO_CPU) if (arg) { if (strncmp(arg, "cpu", 3) == EQUAL && isdigit(arg[3])) { @@ -1410,6 +1414,8 @@ static struct text_object *construct_text_object(const char *s, obj->data.s = strndup(arg ? arg : "", text_buffer_size); END OBJ(execp, 0) obj->data.s = strndup(arg ? arg : "", text_buffer_size); + END OBJ(execgauge, 0) + obj->data.s = strndup(arg ? arg : "", text_buffer_size); END OBJ(execbar, 0) obj->data.s = strndup(arg ? arg : "", text_buffer_size); END OBJ(execgraph, 0) @@ -2046,6 +2052,8 @@ static struct text_object *construct_text_object(const char *s, END OBJ(memfree, INFO_MEM) END OBJ(memmax, INFO_MEM) END OBJ(memperc, INFO_MEM) + END OBJ(memgauge, INFO_MEM) + scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b); END OBJ(membar, INFO_MEM) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b); END OBJ(memgraph, INFO_MEM) @@ -2795,39 +2803,38 @@ static int extract_variable_text_internal(struct text_object *retval, const char s = p; var = getenv(buf); - if (var) { - strncpy(buf, var, 255); - } - arg = 0; + /* if variable wasn't found in environment, use some special */ + if (!var) { + arg = 0; - /* split arg */ - if (strchr(buf, ' ')) { - arg = strchr(buf, ' '); - *arg = '\0'; - arg++; - while (isspace((int) *arg)) { + /* split arg */ + if (strchr(buf, ' ')) { + arg = strchr(buf, ' '); + *arg = '\0'; arg++; + while (isspace((int) *arg)) { + arg++; + } + if (!*arg) { + arg = 0; + } } - if (!*arg) { - arg = 0; + + /* lowercase variable name */ + tmp_p = buf; + while (*tmp_p) { + *tmp_p = tolower(*tmp_p); + tmp_p++; + } + + obj = construct_text_object(buf, arg, + line, allow_threaded, + &ifblock_opaque); + if (obj != NULL) { + append_object(retval, obj); } } - - /* lowercase variable name */ - tmp_p = buf; - while (*tmp_p) { - *tmp_p = tolower(*tmp_p); - tmp_p++; - } - - obj = construct_text_object(buf, arg, - line, allow_threaded, - &ifblock_opaque); - if (obj != NULL) { - append_object(retval, obj); - } - continue; } else { obj = create_plain_text("$"); @@ -3193,6 +3200,9 @@ static void generate_text_internal(char *p, int p_max_size, percent_print(p, p_max_size, round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0)); } + OBJ(cpugauge) + new_gauge(p, obj->a, obj->b, + round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0)); OBJ(cpubar) { new_bar(p, obj->a, obj->b, round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0)); @@ -3517,6 +3527,17 @@ static void generate_text_internal(char *p, int p_max_size, free_text_objects(&subroot); free(tmp_info); } + OBJ(execgauge) { + double barnum; + + read_exec(obj->data.s, p, text_buffer_size); + barnum = get_barnum(p); /*using the same function*/ + + if (barnum >= 0.0) { + barnum /= 100; + new_bar(p, 0, 6, round_to_int(barnum * 255.0)); + } + } OBJ(execbar) { double barnum; @@ -4006,6 +4027,10 @@ static void generate_text_internal(char *p, int p_max_size, if (cur->memmax) percent_print(p, p_max_size, cur->mem * 100 / cur->memmax); } + OBJ(memgauge){ + new_gauge(p, obj->data.pair.a, obj->data.pair.b, + cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0); + } OBJ(membar) { new_bar(p, obj->data.pair.a, obj->data.pair.b, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0); @@ -5298,6 +5323,59 @@ static void draw_line(char *s) break; } + case GAUGE: /* new GAUGE */ + { + int h, by = 0; + unsigned long last_colour = current_color; + float angle, px,py; + int usage; + + if (cur_x - text_start_x > maximum_width + && maximum_width > 0) { + break; + } + + h = specials[special_index].height; + by = cur_y - (font_ascent() / 2) - 1; + + if (h < font_height()) { + by -= h / 2 - 1; + } + w = specials[special_index].width; + if (w == 0) { + w = text_start_x + text_width - cur_x - 1; + } + if (w < 0) { + w = 0; + } + + XSetLineAttributes(display, window.gc, 1, LineSolid, + CapButt, JoinMiter); + + XDrawArc(display, window.drawable, window.gc, + cur_x, by, w, h*2, 0, 180*64); + +#ifdef MATH + usage =specials[special_index].arg; + angle = (3.14)*(float)(usage)/255.; + px = (float)(cur_x+w/2.)-(float)(w)/2.*0.9*cos(angle); + py = (float)(by+h)-(float)(h)*0.9*sin(angle); + + XDrawLine(display, window.drawable, window.gc, + cur_x+ w/2, by+h, (int)(px), (int)(py)); +#endif + + if (specials[special_index].height > cur_y_add + && specials[special_index].height > font_h) { + cur_y_add = specials[special_index].height; + } + + set_foreground_color(last_colour); + + break; + + } + case GRAPH: { int h, by, i, j = 0; diff --git a/src/specials.c b/src/specials.c index 031f089e..23b55ef3 100644 --- a/src/specials.c +++ b/src/specials.c @@ -43,6 +43,27 @@ unsigned int special_count; /* * Scanning arguments to various special text objects */ + +const char *scan_gauge(const char *args, int *w, int *h) +{ + /*width and height*/ + *w = 25; + *h = 25; + + /* gauge's argument is either height or height,width */ + if (args) { + int n = 0; + + if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) { + sscanf(args, "%d %n", h, &n); + *w = *h; /*square gauge*/ + } + args += n; + } + + return args; +} + const char *scan_bar(const char *args, int *w, int *h) { /* zero width means all space that is available */ @@ -177,6 +198,15 @@ static struct special_t *new_special(char *buf, enum special_types t) return &specials[special_count++]; } +void new_gauge(char *buf, int w, int h, int usage) +{ + struct special_t *s = new_special(buf, GAUGE); + + s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage); + s->width = w; + s->height = h; +} + void new_bar(char *buf, int w, int h, int usage) { struct special_t *s = new_special(buf, BAR); diff --git a/src/specials.h b/src/specials.h index 8a82cbbd..ef74138f 100644 --- a/src/specials.h +++ b/src/specials.h @@ -48,6 +48,7 @@ enum special_types { OUTLINE, ALIGNR, ALIGNC, + GAUGE, GRAPH, OFFSET, VOFFSET, @@ -79,12 +80,14 @@ extern unsigned int special_count; extern unsigned int max_specials; /* scanning special arguments */ +const char *scan_gauge(const char *, int *, int *); const char *scan_bar(const char *, int *, int *); char *scan_font(const char *); char *scan_graph(const char *, int *, int *, unsigned int *, unsigned int *, unsigned int *, char *); /* printing specials */ +void new_gauge(char *, int, int, int); void new_bar(char *, int, int, int); void new_font(char *, char *); void new_graph(char *, int, int, unsigned int, diff --git a/src/text_object.h b/src/text_object.h index 9d1975df..ad18bf05 100644 --- a/src/text_object.h +++ b/src/text_object.h @@ -76,6 +76,7 @@ enum text_object_type { OBJ_conky_build_arch, OBJ_font, OBJ_cpu, + OBJ_cpugauge, OBJ_cpubar, OBJ_cpugraph, OBJ_loadgraph, @@ -94,6 +95,7 @@ enum text_object_type { OBJ_exec, OBJ_execi, OBJ_texeci, + OBJ_execgauge, OBJ_execbar, OBJ_execgraph, OBJ_execibar, @@ -194,6 +196,7 @@ enum text_object_type { OBJ_mem, OBJ_memeasyfree, OBJ_memfree, + OBJ_memgauge, OBJ_membar, OBJ_memgraph, OBJ_memmax,