/* converts from bytes to human readable format (k, M, G, T) */
static void human_readable(long long a, char *buf, int size)
{
- //Strange conditional due to possible overflows
+ // Strange conditional due to possible overflows
if(a / 1024 / 1024 / 1024.0 > 1024.0){
- snprintf(buf, size, "%.2fT", (a / 1024 / 1024) / 1024 / 1024.0);
+ snprintf(buf, size, "%.2fT", (a / 1024 / 1024 / 1024) / 1024.0);
}
else if (a >= 1024 * 1024 * 1024) {
snprintf(buf, size, "%.2fG", (a / 1024 / 1024) / 1024.0);
OBJ_alignr,
OBJ_alignc,
OBJ_i2c,
+#if defined(__linux__)
+ OBJ_i8k_version,
+ OBJ_i8k_bios,
+ OBJ_i8k_serial,
+ OBJ_i8k_cpu_temp,
+ OBJ_i8k_cpu_tempf,
+ OBJ_i8k_left_fan_status,
+ OBJ_i8k_right_fan_status,
+ OBJ_i8k_left_fan_rpm,
+ OBJ_i8k_right_fan_rpm,
+ OBJ_i8k_ac_status,
+ OBJ_i8k_buttons_status,
+#endif /* __linux__ */
OBJ_if_existing,
OBJ_if_mounted,
OBJ_if_running,
OBJ_top,
OBJ_top_mem,
OBJ_tail,
+ OBJ_head,
OBJ_kernel,
OBJ_loadavg,
OBJ_machine,
struct net_stat *net;
struct fs_stat *fs;
unsigned char loadavg[3];
- unsigned int diskio;
-
+ //unsigned int diskio;
+ unsigned int cpu_index;
struct {
struct fs_stat *fs;
int w, h;
free(text_objects[i].data.ifblock.s);
break;
case OBJ_text:
+ case OBJ_font:
+ free(text_objects[i].data.s);
+ break;
case OBJ_exec:
free(text_objects[i].data.s);
break;
else
strcpy(bat, "BAT0");
obj->data.s = strdup(bat);
+#if defined(__linux__)
+ END OBJ(i8k_version, INFO_I8K)
+ END OBJ(i8k_bios, INFO_I8K)
+ END OBJ(i8k_serial, INFO_I8K)
+ END OBJ(i8k_cpu_temp, INFO_I8K)
+ END OBJ(i8k_cpu_tempf, INFO_I8K)
+ END OBJ(i8k_left_fan_status, INFO_I8K)
+ END OBJ(i8k_right_fan_status, INFO_I8K)
+ END OBJ(i8k_left_fan_rpm, INFO_I8K)
+ END OBJ(i8k_right_fan_rpm, INFO_I8K)
+ END OBJ(i8k_ac_status, INFO_I8K)
+ END OBJ(i8k_buttons_status, INFO_I8K)
+#endif /* __linux__ */
END OBJ(buffers, INFO_BUFFERS)
END OBJ(cached, INFO_BUFFERS)
END OBJ(cpu, INFO_CPU)
+ if (arg) {
+ if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
+ obj->data.cpu_index = atoi(&arg[3]);
+ arg += 4;
+ } else {obj->data.cpu_index = 0; }
+ } else {
+ obj->data.cpu_index = 0;
+ }
END OBJ(cpubar, INFO_CPU)
- (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
+ if (arg) {
+ if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
+ obj->data.cpu_index = atoi(&arg[3]);
+ arg += 4;
+ }
+ else {obj->data.cpu_index = 0;}
+ (void) scan_bar(arg, &obj->a, &obj->b);
+ } else {
+ (void) scan_bar(arg, &obj->a, &obj->b);
+ obj->data.cpu_index = 0;
+ }
END OBJ(cpugraph, INFO_CPU)
- (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
+ if (arg) {
+ if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
+ obj->data.cpu_index = atoi(&arg[3]);
+ arg += 4;
+ }
+ (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
+} else {
+ (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
+ obj->data.cpu_index = 0;
+ }
END OBJ(diskio, INFO_DISKIO)
END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
END OBJ(color, 0)
obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
#endif /* X11 */
END
- OBJ(font, 0)
+ OBJ(font, 0)
obj->data.s = scan_font(arg);
- END
+ END
OBJ(downspeed, INFO_NET) obj->data.net = get_net_stat(arg);
END OBJ(downspeedf, INFO_NET) obj->data.net = get_net_stat(arg);
END OBJ(downspeedgraph, INFO_NET)
ERR("invalid args given for tail");
return;
}
- obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 6); /* asumming all else worked */
+ obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
+ END OBJ(head, 0)
+ char buf[64];
+ int n1, n2;
+ if (!arg) {
+ ERR("head needs arguments");
+ obj->type = OBJ_text;
+ obj->data.s = strdup("${head}");
+ return;
+ }
+ if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
+ if (n1 < 1 || n1 > 30) {
+ CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
+ return;
+ } else {
+ FILE *fp;
+ fp = fopen(buf, "rt");
+ if (fp != NULL) {
+ obj->data.tail.logfile =
+ malloc(TEXT_BUFFER_SIZE);
+ strcpy(obj->data.tail.logfile, buf);
+ obj->data.tail.wantedlines = n1 - 1;
+ obj->data.tail.interval =
+ update_interval * 2;
+ fclose(fp);
+ } else {
+ //fclose (fp);
+ CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
+ }
+ }
+ } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
+ if (n1 < 1 || n1 > 30) {
+ CRIT_ERR
+ ("invalid arg for head, number of lines must be between 1 and 30");
+ return;
+ } else if (n2 < 1 || n2 < update_interval) {
+ CRIT_ERR
+ ("invalid arg for head, interval must be greater than 0 and Conky's interval");
+ return;
+ } else {
+ FILE *fp;
+ fp = fopen(buf, "rt");
+ if (fp != NULL) {
+ obj->data.tail.logfile =
+ malloc(TEXT_BUFFER_SIZE);
+ strcpy(obj->data.tail.logfile, buf);
+ obj->data.tail.wantedlines = n1 - 1;
+ obj->data.tail.interval = n2;
+ fclose(fp);
+ } else {
+ //fclose (fp);
+ CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
+ }
+ }
+ }
+
+ else {
+ ERR("invalid args given for head");
+ return;
+ }
+ obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
if (arg) {
r = sscanf(arg, "%d %d %d", &a, &b, &c);
human_readable(cur->cached * 1024, p, 255);
}
OBJ(cpu) {
+ if (obj->data.cpu_index > info.cpu_count) {
+ printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
+ CRIT_ERR("attempting to use more CPUs then you have!");
+ }
if (!use_spacer)
snprintf(p, n, "%*d", pad_percents,
- (int) (cur->cpu_usage *
+ (int) (cur->cpu_usage[obj->data.cpu_index] *
100.0));
else
snprintf(p, 4, "%*d ",
pad_percents,
- (int) (cur->cpu_usage *
+ (int) (cur->cpu_usage[obj->data.cpu_index] *
100.0));
}
OBJ(cpubar) {
- new_bar(p, obj->data.pair.a,
- obj->data.pair.b,
- (int) (cur->cpu_usage * 255.0));
+ new_bar(p, obj->a,
+ obj->b,
+ (int) (cur->cpu_usage[obj->data.cpu_index] * 255.0));
}
OBJ(cpugraph) {
new_graph(p, obj->a,
obj->b, obj->c, obj->d,
- (unsigned int) (cur->cpu_usage *
+ (unsigned int) (cur->cpu_usage[obj->data.cpu_index] *
100), 100, 1);
}
OBJ(color) {
new_fg(p, obj->data.l);
}
+#if defined(__linux__)
+ OBJ(i8k_version) {
+ snprintf(p, n, "%s", i8k.version);
+ }
+ OBJ(i8k_bios) {
+ snprintf(p, n, "%s", i8k.bios);
+ }
+ OBJ(i8k_serial) {
+ snprintf(p, n, "%s", i8k.serial);
+ }
+ OBJ(i8k_cpu_temp) {
+ snprintf(p, n, "%s", i8k.cpu_temp);
+ }
+ OBJ(i8k_cpu_tempf) {
+ int cpu_temp;
+ sscanf(i8k.cpu_temp, "%d", &cpu_temp);
+ snprintf(p, n, "%.1f", cpu_temp*(9.0/5.0)+32.0);
+ }
+ OBJ(i8k_left_fan_status) {
+ int left_fan_status;
+ sscanf(i8k.left_fan_status, "%d", &left_fan_status);
+ if(left_fan_status == 0) {
+ snprintf(p, n,"off");
+ } if(left_fan_status == 1) {
+ snprintf(p, n, "low");
+ } if(left_fan_status == 2) {
+ snprintf(p, n, "high");
+ }
+
+ }
+ OBJ(i8k_right_fan_status) {
+ int right_fan_status;
+ sscanf(i8k.right_fan_status, "%d", &right_fan_status);
+ if(right_fan_status == 0) {
+ snprintf(p, n,"off");
+ } if(right_fan_status == 1) {
+ snprintf(p, n, "low");
+ } if(right_fan_status == 2) {
+ snprintf(p, n, "high");
+ }
+ }
+ OBJ(i8k_left_fan_rpm) {
+ snprintf(p, n, "%s", i8k.left_fan_rpm);
+ }
+ OBJ(i8k_right_fan_rpm) {
+ snprintf(p, n, "%s", i8k.right_fan_rpm);
+ }
+ OBJ(i8k_ac_status) {
+ int ac_status;
+ sscanf(i8k.ac_status, "%d", &ac_status);
+ if(ac_status == -1) {
+ snprintf(p, n,"disabled (read i8k docs)");
+ } if(ac_status == 0) {
+ snprintf(p, n, "off");
+ } if(ac_status == 1) {
+ snprintf(p, n, "on");
+ }
+ }
+ OBJ(i8k_buttons_status) {
+ snprintf(p, n, "%s", i8k.buttons_status);
+
+ }
+#endif /* __linux__ */
+
#ifdef X11
OBJ(font) {
new_font(p, obj->data.s);
}
#endif /* X11 */
OBJ(diskio) {
- if (diskio_value > 1024) {
- snprintf(p, n, "%.1fM",
- (double)diskio_value/1024);
- } else if (diskio_value > 0) {
- snprintf(p, n, "%dK", diskio_value);
+ if (!use_spacer) {
+ if (diskio_value > 1024*1024) {
+ snprintf(p, n, "%.1fG",
+ (double)diskio_value/1024/1024);
+ } else if (diskio_value > 1024) {
+ snprintf(p, n, "%.1fM",
+ (double)diskio_value/1024);
+ } else if (diskio_value > 0) {
+ snprintf(p, n, "%dK", diskio_value);
+ } else {
+ snprintf(p, n, "%d", diskio_value);
+ }
} else {
- snprintf(p, n, "%d", diskio_value);
+ if (diskio_value > 1024*1024) {
+ snprintf(p, 6, "%.1fG ",
+ (double)diskio_value/1024/1024);
+ } else if (diskio_value > 1024) {
+ snprintf(p, 6, "%.1fM ",
+ (double)diskio_value/1024);
+ } else if (diskio_value > 0) {
+ snprintf(p, 6, "%dK ", diskio_value);
+ } else {
+ snprintf(p, 6, "%d ", diskio_value);
+ }
}
}
OBJ(diskiograph) {
int added = 0;
tailstring *head = NULL;
tailstring *headtmp = NULL;
+ tailstring *freetmp = NULL;
fp = fopen(obj->data.tail.logfile, "rt");
if (fp == NULL) {
ERR("tail logfile failed to open");
}
fclose(fp);
+ freetmp = head;
if (obj->data.tail.readlines > 0) {
for (i = 0;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
addtail(&headtmp, head->data);
head = head->next;
}
+ freetail(freetmp);
+ freetmp = headtmp;
strcpy(obj->data.tail.buffer, headtmp->data);
headtmp = headtmp->next;
for (i = 1;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
if (headtmp) {
- strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 6 / obj->data.tail.wantedlines) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
+ strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20 / obj->data.tail.wantedlines) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
headtmp = headtmp->next;
}
}
}
snprintf(p, n, "%s", obj->data.tail.buffer);
- freetail(headtmp);
+ freetail(freetmp);
+ }
+ else {
+ strcpy(obj->data.tail.buffer, "Logfile Empty");
+ snprintf(p, n, "Logfile Empty");
+ }
+ }
+ }
+ }
+ OBJ(head) {
+ if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
+ snprintf(p, n, "%s", obj->data.tail.buffer);
+ } else {
+ obj->data.tail.last_update = current_update_time;
+ FILE *fp;
+ tailstring *head = NULL;
+ tailstring *headtmp = NULL;
+ tailstring *freetmp = NULL;
+ fp = fopen(obj->data.tail.logfile, "rt");
+ if (fp == NULL) {
+ ERR("head logfile failed to open");
+ }
+ else {
+ obj->data.tail.readlines = 0;
+ while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*4, fp) != NULL && obj->data.tail.readlines <= obj->data.tail.wantedlines) {
+ addtail(&head, obj->data.tail.buffer);
+ obj->data.tail.readlines++;
+ }
+ fclose(fp);
+ freetmp = head;
+ if (obj->data.tail.readlines > 0) {
+ while (head) {
+ addtail(&headtmp, head->data);
+ head = head->next;
+ }
+ freetail(freetmp);
+ freetmp = headtmp;
+ strcpy(obj->data.tail.buffer, headtmp->data);
+ headtmp = headtmp->next;
+ while (headtmp) {
+ strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20 / obj->data.tail.wantedlines) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
+ headtmp = headtmp->next;
+ }
+ freetail(freetmp);
+ /* get rid of any ugly newlines at the end */
+ if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
+ obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
+ }
+ snprintf(p, n, "%s", obj->data.tail.buffer);
}
else {
strcpy(obj->data.tail.buffer, "Logfile Empty");
snprintf(p, n, "Logfile Empty");
}
- freetail(head);
}
}
}
-
-
break;
}
#endif /* X11 */
}
+static inline int get_string_width_special(char *s)
+{
+ if (!s) {
+ return 0;
+ }
+#ifdef X11
+ char *p, *final;
+ p = strdup(s);
+ final = p;
+ int index = 1;
+ int width = 0;
+ unsigned int i;
+ while (*p) {
+ if (*p == SPECIAL_CHAR) {
+ /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
+ for (i = 0; i < strlen(p); i++) {
+ *(p + i) = *(p + i + 1);
+ }
+ if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
+ width += specials[special_index+index].width;
+ }
+ index++;
+ } else {
+ p++;
+ }
+ }
+ if (strlen(final) > 1) {
+ width += calc_text_width(final, strlen(final));
+ }
+ free(final);
+ return width;
+#else
+ return strlen(s);
+#endif /* X11 */
+}
+
int fontchange = 0;
#ifdef X11
specials[special_index].height;
int bar_usage =
specials[special_index].arg;
- int by =
- cur_y - (font_ascent() +
- h) / 2 - 1;
+ int by;
+
+#ifdef XFT
+ if (use_xft) {
+ by = cur_y - (font_ascent() + h) / 2 - 1;
+ } else
+#endif
+ {
+ 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 +
break;
case GRAPH:
- {
+ {
if (cur_x > maximum_width - text_start_x && maximum_width > 0) {
break;
}
int by;
#ifdef XFT
if (use_xft) {
- by = cur_y - (font_ascent() + h) / 2 + 1;
+ by = cur_y - (font_ascent() + h) / 2 - 1;
} else
#endif
{
- by = cur_y - (font_ascent()/2) + 1;
+ by = cur_y - (font_ascent()/2) - 1;
+ }
+ if (h < (font_height())) {
+ by -= h / 2 - 1;
}
w = specials[special_index].width;
if (w == 0)
case ALIGNR:
{
- int pos_x = text_width + gap_x - get_string_width(p) /*- border_margin*2 - 1*/;
- /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i border_margin %i border_width %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width(p), gap_x, specials[special_index].arg, border_margin, border_width);*/
+ int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
+ /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i border_margin %i border_width %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width_special(s), gap_x, specials[special_index].arg, border_margin, border_width);*/
if (pos_x > specials[special_index].arg && pos_x > cur_x) {
- cur_x = pos_x - specials[special_index].arg;
+ cur_x = pos_x - specials[special_index].arg;
}
}
break;
case ALIGNC:
{
- int pos_x = (text_width)/2 - get_string_width(p)/2 - (cur_x - text_start_x);
- /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width(p), gap_x, specials[special_index].arg);*/
+ int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
+ /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
+ /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width(s), gap_x, specials[special_index].arg);*/
if (pos_x >
specials[special_index].arg)
w = pos_x -
#endif /* X11 */
}
+#ifdef X11
+ XDestroyRegion(region);
+#endif /* X11 */
}
static void load_config_file(const char *);