2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
27 #include <X11/Xutil.h>
29 #include <sys/types.h>
32 #define CONFIG_FILE "$HOME/.conkyrc"
33 #define MAIL_FILE "$MAIL"
34 #define MAX_IF_BLOCK_DEPTH 5
51 char name[TEXT_BUFFER_SIZE];
61 static int selected_font = 0;
62 static int font_count = -1;
63 struct font_list *fonts = NULL;
67 #define font_height() use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
68 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
69 #define font_ascent() use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent
70 #define font_descent() use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent
74 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
75 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
76 #define font_descent() fonts[selected_font].font->max_bounds.descent
80 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
83 static void set_font();
86 int addfont(const char *data_in)
88 if (font_count > MAX_FONTS) {
89 CRIT_ERR("you don't need that many fonts, sorry.");
92 if (font_count == 0) {
96 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
100 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
102 CRIT_ERR("realloc in addfont");
104 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
105 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
107 fonts[font_count].font_alpha = 0xffff;
110 CRIT_ERR("Oops...looks like something overflowed in addfont().");
115 void set_first_font(const char *data_in)
117 if (font_count < 0) {
118 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
123 if (strlen(data_in) > 1) {
124 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
126 fonts[0].font_alpha = 0xffff;
134 for (i=0;i<=font_count;i++) {
137 XftFontClose(display, fonts[i].xftfont);
141 XFreeFont(display, fonts[i].font);
148 set_first_font("6x10");
152 static void load_fonts()
155 for (i=0;i<=font_count;i++) {
159 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
160 XftFontClose(display, fonts[i].xftfont);
162 if ((fonts[i].xftfont =
163 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
166 ERR("can't load Xft font '%s'", fonts[i].name);
167 if ((fonts[i].xftfont =
168 XftFontOpenName(display, screen,
169 "courier-12")) != NULL)
172 ERR("can't load Xft font '%s'", "courier-12");
174 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
175 CRIT_ERR("can't load font '%s'", "fixed");
182 /* load normal font */
183 /* if (fonts[i].font != NULL)
184 XFreeFont(display, fonts[i].font);*/
186 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
187 ERR("can't load font '%s'", fonts[i].name);
188 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
189 CRIT_ERR("can't load font '%s'", "fixed");
197 /* default config file */
198 static char *current_config;
200 /* set to 1 if you want all text to be in uppercase */
201 static unsigned int stuff_in_upper_case;
203 /* Update interval */
204 static double update_interval;
206 /* Run how many times? */
207 static unsigned long total_run_times;
210 static int fork_to_background;
212 static int cpu_avg_samples, net_avg_samples;
216 /* Always on bottom */
217 static int on_bottom;
219 /* Position on the screen */
220 static int text_alignment;
221 static int gap_x, gap_y;
224 static int draw_borders;
225 static int stippled_borders;
227 static int draw_shades, draw_outline;
229 static int border_margin, border_width;
231 static long default_fg_color, default_bg_color, default_out_color;
233 /* create own window or draw stuff to root? */
234 static int own_window = 0;
237 /* fixed size/pos is set if wm/user changes them */
238 static int fixed_size = 0, fixed_pos = 0;
241 static int minimum_width, minimum_height;
248 /* no buffers in used memory? */
251 /* pad percentages to decimals? */
252 static int pad_percents = 0;
254 /* Text that is shown */
255 static char original_text[] =
256 "$nodename - $sysname $kernel on $machine\n"
258 "${color grey}Uptime:$color $uptime\n"
259 "${color grey}Frequency (in MHz):$color $freq\n"
260 "${color grey}Frequency (in Ghz):$color $freq_g\n"
261 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
262 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
263 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
264 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
266 "${color grey}File systems:\n"
267 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
268 "${color grey}Networking:\n"
269 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
270 "${color grey}Temperatures:\n"
271 " CPU:$color ${i2c temp 1}°C${color grey} - MB:$color ${i2c temp 2}°C\n"
274 "${color grey}SETI@Home Statistics:\n"
275 "${color grey}Seti Unit Number:$color $seti_credit\n"
276 "${color grey}Seti Progress:$color $seti_prog% $seti_progbar\n"
279 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
280 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
282 "${color grey}Name PID CPU% MEM%\n"
283 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
284 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
285 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
286 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
287 "${tail /var/log/Xorg.0.log 3}";
289 static char *text = original_text;
291 static int total_updates;
294 static int blockdepth = 0;
295 static int if_jumped = 0;
296 static int blockstart[MAX_IF_BLOCK_DEPTH];
298 int check_mount(char *s)
301 FILE *mtab = fopen("/etc/mtab", "r");
303 char buf1[256], buf2[128];
304 while (fgets(buf1, 256, mtab)) {
305 sscanf(buf1, "%*s %128s", buf2);
306 if (!strcmp(s, buf2)) {
313 ERR("Could not open mtab");
320 static inline int calc_text_width(const char *s, unsigned int l)
326 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, s, l, &gi);
328 XftTextExtents8(display, fonts[selected_font].xftfont, s, l, &gi);
334 return XTextWidth(fonts[selected_font].font, s, l);
339 /* formatted text to render on screen, generated in generate_text(),
340 * drawn in draw_stuff() */
342 static char text_buffer[TEXT_BUFFER_SIZE * 4];
344 /* special stuff in text_buffer */
346 #define SPECIAL_CHAR '\x01'
363 static struct special_t {
373 unsigned long first_colour; // for graph gradient
374 unsigned long last_colour;
377 static int special_count;
379 static int special_index; /* used when drawing */
382 #define MAX_GRAPH_DEPTH 256 /* why 256? who knows. */
384 static struct special_t *new_special(char *buf, int t)
386 if (special_count >= 128)
387 CRIT_ERR("too many special things in text");
389 buf[0] = SPECIAL_CHAR;
391 if (t == GRAPH && specials[special_count].graph == NULL) {
392 if (specials[special_count].width > 0
393 && specials[special_count].width < MAX_GRAPH_DEPTH)
394 specials[special_count].graph_width = specials[special_count].width - 3; // subtract 3 for the box
396 specials[special_count].graph_width =
398 specials[special_count].graph =
399 calloc(specials[special_count].graph_width,
401 specials[special_count].graph_scale = 100;
403 specials[special_count].type = t;
404 return &specials[special_count++];
407 typedef struct tailstring_list {
408 char data[TEXT_BUFFER_SIZE];
409 struct tailstring_list *next;
410 struct tailstring_list *first;
413 void addtail(tailstring ** head, char *data_in)
416 if ((tmp = malloc(sizeof(*tmp))) == NULL) {
422 tmp->first = (*head)->first;
424 strncpy(tmp->data, data_in, TEXT_BUFFER_SIZE);
429 void freetail(tailstring * head)
432 while (head != NULL) {
439 void freelasttail(tailstring * head)
441 tailstring * tmp = head;
443 if (tmp->next == head->first) {
450 while(head != NULL && tmp != NULL) {
456 static void new_bar(char *buf, int w, int h, int usage)
458 struct special_t *s = new_special(buf, BAR);
459 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
464 static const char *scan_bar(const char *args, int *w, int *h)
466 *w = 0; /* zero width means all space that is available */
468 /* bar's argument is either height or height,width */
471 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
472 sscanf(args, "%d %n", h, &n);
479 static char *scan_font(const char *args)
481 if (args && sizeof(args) < 127) {
485 ERR("font scan failed, lets hope it doesn't mess stuff up");
491 static void new_font(char *buf, char * args) {
492 struct special_t *s = new_special(buf, FONT);
493 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
494 int tmp = selected_font;
495 selected_font = s->font_added = addfont(args);
503 inline void graph_append(struct special_t *graph, double f)
507 graph->graph_scale = 0;
509 graph->graph[graph->graph_width - 1] = f; /* add new data */
510 for (i = 0; i < graph->graph_width - 1; i++) { /* shift all the data by 1 */
511 graph->graph[i] = graph->graph[i + 1];
512 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
513 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
518 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scaled)
520 struct special_t *s = new_special(buf, GRAPH);
523 s->first_colour = first_colour;
524 s->last_colour = second_colour;
527 s->graph_width = s->width - 3; // subtract 3 for rectangle around
532 s->graph_scale = 100;
537 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour)
539 *w = 0; /* zero width means all space that is available */
543 /* graph's argument is either height or height,width */
545 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
546 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
549 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 3) {
552 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
555 if (sscanf(args, "%d,%d", h, w) < 2) {
558 sscanf(args, "%*s %d,%d", h, w);
570 static inline void new_hr(char *buf, int a)
572 new_special(buf, HORIZONTAL_LINE)->height = a;
575 static inline void new_stippled_hr(char *buf, int a, int b)
577 struct special_t *s = new_special(buf, STIPPLED_HR);
582 static inline void new_fg(char *buf, long c)
584 new_special(buf, FG)->arg = c;
587 static inline void new_bg(char *buf, long c)
589 new_special(buf, BG)->arg = c;
592 static inline void new_outline(char *buf, long c)
594 new_special(buf, OUTLINE)->arg = c;
597 static inline void new_offset(char *buf, long c)
599 new_special(buf, OFFSET)->arg = c;
602 static inline void new_voffset(char *buf, long c)
604 new_special(buf, VOFFSET)->arg = c;
607 static inline void new_alignr(char *buf, long c)
609 new_special(buf, ALIGNR)->arg = c;
612 static inline void new_alignc(char *buf, long c)
614 new_special(buf, ALIGNC)->arg = c;
617 /* quite boring functions */
619 static inline void for_each_line(char *b, void (*f) (char *))
623 for (ps = b, pe = b; *pe; pe++) {
636 static void convert_escapes(char *buf)
638 char *p = buf, *s = buf;
654 /* converts from bytes to human readable format (k, M, G, T) */
655 static void human_readable(long long a, char *buf, int size)
657 //Strange conditional due to possible overflows
658 if(a / 1024 / 1024 / 1024.0 > 1024.0){
659 snprintf(buf, size, "%.2fT", (a / 1024 / 1024) / 1024 / 1024.0);
661 else if (a >= 1024 * 1024 * 1024) {
662 snprintf(buf, size, "%.2fG", (a / 1024 / 1024) / 1024.0);
664 else if (a >= 1024 * 1024) {
665 double m = (a / 1024) / 1024.0;
667 snprintf(buf, size, "%.0fM", m);
669 snprintf(buf, size, "%.1fM", m);
670 } else if (a >= 1024)
671 snprintf(buf, size, "%Ldk", a / (long long) 1024);
673 snprintf(buf, size, "%Ld", a);
678 enum text_object_type {
744 OBJ_ml_upload_counter,
745 OBJ_ml_download_counter,
746 OBJ_ml_nshared_files,
747 OBJ_ml_shared_counter,
748 OBJ_ml_tcp_upload_rate,
749 OBJ_ml_tcp_download_rate,
750 OBJ_ml_udp_upload_rate,
751 OBJ_ml_udp_download_rate,
752 OBJ_ml_ndownloaded_files,
753 OBJ_ml_ndownloading_files,
756 OBJ_running_processes,
765 OBJ_temp1, /* i2c is used instead in these */
804 char *s; /* some string */
805 int i; /* some integer */
806 long l; /* some other integer */
807 struct net_stat *net;
809 unsigned char loadavg[3];
858 static unsigned int text_object_count;
859 static struct text_object *text_objects;
861 /* new_text_object() allocates a new zeroed text_object */
862 static struct text_object *new_text_object()
865 text_objects = (struct text_object *) realloc(text_objects,
869 memset(&text_objects[text_object_count - 1], 0,
870 sizeof(struct text_object));
872 return &text_objects[text_object_count - 1];
875 static void free_text_objects()
879 for (i = 0; i < text_object_count; i++) {
880 switch (text_objects[i].type) {
882 close(text_objects[i].data.i);
885 close(text_objects[i].data.i);
888 close(text_objects[i].data.i2c.fd);
892 case OBJ_if_existing:
895 free(text_objects[i].data.ifblock.s);
910 free(text_objects[i].data.s);
914 free(text_objects[i].data.execi.cmd);
915 free(text_objects[i].data.execi.buffer);
922 text_object_count = 0;
925 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
930 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
931 *a = mixer_init(buf1);
932 (void) scan_bar(arg + n, w, h);
935 (void) scan_bar(arg, w, h);
939 /* construct_text_object() creates a new text_object */
940 static void construct_text_object(const char *s, const char *arg)
942 struct text_object *obj = new_text_object();
944 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
945 #define END ; } } else
949 obj->type = OBJ_color;
950 obj->data.l = get_x11_color(s);
953 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
954 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
955 END OBJ(acpiacadapter, 0)
962 sscanf(arg, "%63s", bat);
965 obj->data.s = strdup(bat);
966 END OBJ(buffers, INFO_BUFFERS)
967 END OBJ(cached, INFO_BUFFERS)
968 END OBJ(cpu, INFO_CPU)
969 END OBJ(cpubar, INFO_CPU)
970 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
971 END OBJ(cpugraph, INFO_CPU)
972 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d);
975 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
979 obj->data.s = scan_font(arg);
981 OBJ(downspeed, INFO_NET) obj->data.net = get_net_stat(arg);
982 END OBJ(downspeedf, INFO_NET) obj->data.net = get_net_stat(arg);
983 END OBJ(downspeedgraph, INFO_NET)
984 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d);
986 sscanf(arg, "%63s %*i,%*i %*i", buf);
987 obj->data.net = get_net_stat(buf);
988 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
989 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
998 text_objects[blockstart[blockdepth - 1] -
999 1].data.ifblock.pos = text_object_count;
1000 blockstart[blockdepth - 1] = text_object_count;
1001 obj->data.ifblock.pos = text_object_count + 2;
1003 ERR("$else: no matching $if_*");
1008 text_objects[blockstart[blockdepth] - 1].data.ifblock.pos =
1011 ERR("$endif: no matching $if_*");
1015 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
1016 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
1017 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
1018 END OBJ(execi, 0) unsigned int n;
1021 || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1023 ERR("${execi <interval> command}");
1024 obj->type = OBJ_text;
1025 snprintf(buf, 256, "${%s}", s);
1026 obj->data.s = strdup(buf);
1028 obj->data.execi.cmd = strdup(arg + n);
1029 obj->data.execi.buffer =
1030 (char *) calloc(1, TEXT_BUFFER_SIZE);
1032 END OBJ(pre_exec, 0) obj->type = OBJ_text;
1034 FILE *fp = popen(arg, "r");
1038 n = fread(buf, 1, 2048, fp);
1041 if (n && buf[n - 1] == '\n')
1046 obj->data.s = strdup(buf);
1048 obj->data.s = strdup("");
1051 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
1052 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1054 while (isspace(*arg))
1060 obj->data.fsbar.fs = prepare_fs_stat(arg);
1061 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
1064 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
1068 obj->data.fsbar.fs = prepare_fs_stat(arg);
1069 END OBJ(fs_free, INFO_FS) if (!arg)
1071 obj->data.fs = prepare_fs_stat(arg);
1072 END OBJ(fs_used_perc, INFO_FS) if (!arg)
1074 obj->data.fs = prepare_fs_stat(arg);
1075 END OBJ(fs_free_perc, INFO_FS) if (!arg)
1077 obj->data.fs = prepare_fs_stat(arg);
1078 END OBJ(fs_size, INFO_FS) if (!arg)
1080 obj->data.fs = prepare_fs_stat(arg);
1081 END OBJ(fs_used, INFO_FS) if (!arg)
1083 obj->data.fs = prepare_fs_stat(arg);
1084 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
1085 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
1086 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
1087 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
1091 ERR("i2c needs arguments");
1092 obj->type = OBJ_text;
1093 obj->data.s = strdup("${i2c}");
1097 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
1098 /* if scanf couldn't read three values, read type and num and use
1100 sscanf(arg, "%63s %d", buf2, &n);
1102 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
1103 obj->data.i2c.devtype);
1104 strcpy(obj->data.i2c.type, buf2);
1107 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
1108 obj->data.i2c.devtype);
1109 strcpy(obj->data.i2c.type, buf2);
1112 END OBJ(top, INFO_TOP)
1116 ERR("top needs arguments");
1117 obj->type = OBJ_text;
1118 obj->data.s = strdup("${top}");
1121 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1122 if (strcmp(buf, "name") == 0) {
1123 obj->data.top.type = TOP_NAME;
1124 } else if (strcmp(buf, "cpu") == 0) {
1125 obj->data.top.type = TOP_CPU;
1126 } else if (strcmp(buf, "pid") == 0) {
1127 obj->data.top.type = TOP_PID;
1128 } else if (strcmp(buf, "mem") == 0) {
1129 obj->data.top.type = TOP_MEM;
1131 ERR("invalid arg for top");
1134 if (n < 1 || n > 10) {
1135 CRIT_ERR("invalid arg for top");
1138 obj->data.top.num = n - 1;
1142 ERR("invalid args given for top");
1145 END OBJ(top_mem, INFO_TOP)
1149 ERR("top_mem needs arguments");
1150 obj->type = OBJ_text;
1151 obj->data.s = strdup("${top_mem}");
1154 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1155 if (strcmp(buf, "name") == 0) {
1156 obj->data.top.type = TOP_NAME;
1157 } else if (strcmp(buf, "cpu") == 0) {
1158 obj->data.top.type = TOP_CPU;
1159 } else if (strcmp(buf, "pid") == 0) {
1160 obj->data.top.type = TOP_PID;
1161 } else if (strcmp(buf, "mem") == 0) {
1162 obj->data.top.type = TOP_MEM;
1164 ERR("invalid arg for top");
1167 if (n < 1 || n > 10) {
1168 CRIT_ERR("invalid arg for top");
1171 obj->data.top.num = n - 1;
1175 ERR("invalid args given for top");
1178 END OBJ(addr, INFO_NET) obj->data.net = get_net_stat(arg);
1179 END OBJ(linkstatus, INFO_WIFI) obj->data.net = get_net_stat(arg);
1184 ERR("tail needs arguments");
1185 obj->type = OBJ_text;
1186 obj->data.s = strdup("${tail}");
1189 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
1190 if (n1 < 1 || n1 > 30) {
1191 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
1195 fp = fopen(buf, "rt");
1197 obj->data.tail.logfile =
1198 malloc(TEXT_BUFFER_SIZE);
1199 strcpy(obj->data.tail.logfile, buf);
1200 obj->data.tail.wantedlines = n1 - 1;
1201 obj->data.tail.interval =
1202 update_interval * 2;
1206 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
1209 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
1210 if (n1 < 1 || n1 > 30) {
1212 ("invalid arg for tail, number of lines must be between 1 and 30");
1214 } else if (n2 < 1 || n2 < update_interval) {
1216 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
1220 fp = fopen(buf, "rt");
1222 obj->data.tail.logfile =
1223 malloc(TEXT_BUFFER_SIZE);
1224 strcpy(obj->data.tail.logfile, buf);
1225 obj->data.tail.wantedlines = n1 - 1;
1226 obj->data.tail.interval = n2;
1230 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
1236 ERR("invalid args given for tail");
1239 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 6); /* asumming all else worked */
1240 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
1242 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1243 if (r >= 3 && (c < 1 || c > 3))
1245 if (r >= 2 && (b < 1 || b > 3))
1247 if (r >= 1 && (a < 1 || a > 3))
1250 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1251 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1252 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1253 END OBJ(if_existing, 0)
1254 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1255 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1258 ERR("if_existing needs an argument");
1259 obj->data.ifblock.s = 0;
1261 obj->data.ifblock.s = strdup(arg);
1262 blockstart[blockdepth] = text_object_count;
1263 obj->data.ifblock.pos = text_object_count + 2;
1265 END OBJ(if_mounted, 0)
1266 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1267 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1270 ERR("if_mounted needs an argument");
1271 obj->data.ifblock.s = 0;
1273 obj->data.ifblock.s = strdup(arg);
1274 blockstart[blockdepth] = text_object_count;
1275 obj->data.ifblock.pos = text_object_count + 2;
1277 END OBJ(if_running, 0)
1278 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1279 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1283 snprintf(buf, 256, "pidof %s >/dev/null", arg);
1284 obj->data.ifblock.s = strdup(buf);
1286 ERR("if_running needs an argument");
1287 obj->data.ifblock.s = 0;
1289 blockstart[blockdepth] = text_object_count;
1290 obj->data.ifblock.pos = text_object_count + 2;
1294 END OBJ(mails, INFO_MAIL)
1295 END OBJ(mem, INFO_MEM)
1296 END OBJ(memmax, INFO_MEM)
1297 END OBJ(memperc, INFO_MEM)
1298 END OBJ(membar, INFO_MEM)
1299 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1300 END OBJ(memgraph, INFO_MEM)
1301 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d);
1302 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
1303 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
1304 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
1305 END OBJ(mixerbar, INFO_MIXER)
1306 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1307 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1308 END OBJ(mixerlbar, INFO_MIXER)
1309 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1310 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1311 END OBJ(mixerrbar, INFO_MIXER)
1312 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1313 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1316 OBJ(ml_upload_counter, INFO_MLDONKEY)
1317 END OBJ(ml_download_counter, INFO_MLDONKEY)
1318 END OBJ(ml_nshared_files, INFO_MLDONKEY)
1319 END OBJ(ml_shared_counter, INFO_MLDONKEY)
1320 END OBJ(ml_tcp_upload_rate, INFO_MLDONKEY)
1321 END OBJ(ml_tcp_download_rate, INFO_MLDONKEY)
1322 END OBJ(ml_udp_upload_rate, INFO_MLDONKEY)
1323 END OBJ(ml_udp_download_rate, INFO_MLDONKEY)
1324 END OBJ(ml_ndownloaded_files, INFO_MLDONKEY)
1325 END OBJ(ml_ndownloading_files, INFO_MLDONKEY) END
1327 OBJ(new_mails, INFO_MAIL)
1328 END OBJ(nodename, 0)
1329 END OBJ(processes, INFO_PROCS)
1330 END OBJ(running_processes, INFO_RUN_PROCS)
1331 END OBJ(shadecolor, 0)
1333 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
1335 END OBJ(outlinecolor, 0)
1337 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
1339 END OBJ(stippled_hr, 0)
1341 int a = stippled_borders, b = 1;
1343 if (sscanf(arg, "%d %d", &a, &b) != 2)
1344 sscanf(arg, "%d", &b);
1348 obj->data.pair.a = a;
1349 obj->data.pair.b = b;
1351 END OBJ(swap, INFO_MEM)
1352 END OBJ(swapmax, INFO_MEM)
1353 END OBJ(swapperc, INFO_MEM)
1354 END OBJ(swapbar, INFO_MEM)
1355 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1356 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
1358 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
1359 obj->data.i2c.devtype);
1360 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
1362 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
1363 obj->data.i2c.devtype);
1364 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1365 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1366 END OBJ(totaldown, INFO_NET) obj->data.net = get_net_stat(arg);
1367 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
1369 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
1370 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
1371 END OBJ(upspeed, INFO_NET) obj->data.net = get_net_stat(arg);
1372 END OBJ(upspeedf, INFO_NET) obj->data.net = get_net_stat(arg);
1373 END OBJ(upspeedgraph, INFO_NET)
1374 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d);
1376 sscanf(arg, "%63s %*i,%*i %*i", buf);
1377 obj->data.net = get_net_stat(buf);
1378 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
1379 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
1384 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
1385 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
1387 OBJ(seti_prog, INFO_SETI) END OBJ(seti_progbar, INFO_SETI)
1388 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1389 END OBJ(seti_credit, INFO_SETI) END
1392 OBJ(mpd_artist, INFO_MPD)
1393 END OBJ(mpd_title, INFO_MPD)
1394 END OBJ(mpd_elapsed, INFO_MPD)
1395 END OBJ(mpd_length, INFO_MPD)
1396 END OBJ(mpd_percent, INFO_MPD)
1397 END OBJ(mpd_album, INFO_MPD) END OBJ(mpd_vol,
1398 INFO_MPD) END OBJ(mpd_bitrate,
1400 END OBJ(mpd_status, INFO_MPD) END OBJ(mpd_bar, INFO_MPD)
1401 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1406 ERR("unknown variable %s", s);
1407 obj->type = OBJ_text;
1408 snprintf(buf, 256, "${%s}", s);
1409 obj->data.s = strdup(buf);
1414 /* append_text() appends text to last text_object if it's text, if it isn't
1415 * it creates a new text_object */
1416 static void append_text(const char *s)
1418 struct text_object *obj;
1420 if (s == NULL || *s == '\0')
1423 obj = text_object_count ? &text_objects[text_object_count - 1] : 0;
1425 /* create a new text object? */
1426 if (!obj || obj->type != OBJ_text) {
1427 obj = new_text_object();
1428 obj->type = OBJ_text;
1429 obj->data.s = strdup(s);
1432 obj->data.s = (char *) realloc(obj->data.s,
1433 strlen(obj->data.s) +
1435 strcat(obj->data.s, s);
1439 static void extract_variable_text(const char *p)
1443 free_text_objects();
1458 /* variable is either $foo or ${foo} */
1462 while (*p && *p != '}')
1468 while (*p && (isalnum((int) *p)
1473 /* copy variable to buffer */
1474 len = (p - s > 255) ? 255 : (p - s);
1475 strncpy(buf, s, len);
1484 /* if variable wasn't found from environment, use some special */
1490 if (strchr(buf, ' ')) {
1491 arg = strchr(buf, ' ');
1494 while (isspace((int) *arg))
1500 /* lowercase variable name */
1507 construct_text_object(buf, arg);
1518 ERR("one or more $endif's are missing");
1522 double current_update_time, last_update_time;
1524 static void generate_text()
1527 struct information *cur = &info;
1534 current_update_time = get_time();
1540 n = TEXT_BUFFER_SIZE * 4 - 2;
1543 for (i = 0; i < text_object_count; i++) {
1544 struct text_object *obj = &text_objects[i];
1546 #define OBJ(a) break; case OBJ_##a:
1548 switch (obj->type) {
1551 ERR("not implemented obj type %d",
1555 /* does anyone have decimals in acpi temperature? */
1557 snprintf(p, n, "%d", (int)
1558 get_acpi_temperature(obj->
1562 snprintf(p, 5, "%d ", (int)
1563 get_acpi_temperature(obj->
1568 /* does anyone have decimals in acpi temperature? */
1570 snprintf(p, n, "%d", (int)
1571 ((get_acpi_temperature(obj->
1573 i)+ 40) * 9.0 / 5 - 40));
1575 snprintf(p, 5, "%d ", (int)
1576 ((get_acpi_temperature(obj->
1578 i)+ 40) * 9.0 / 5 - 40));
1581 snprintf(p, n, "%sMhz", get_freq());
1584 float ghz = (float)(atof(get_freq())/1000);
1585 //printf("%f\n", ghz);
1586 snprintf(p, n, "%'.2fGhz", ghz);
1589 snprintf(p, n, "%s", get_adt746x_cpu());
1592 snprintf(p, n, "%s", get_adt746x_fan());
1595 snprintf(p, n, "%s", get_acpi_fan());
1597 OBJ(acpiacadapter) {
1598 snprintf(p, n, "%s",
1599 get_acpi_ac_adapter());
1602 get_battery_stuff(p, n, obj->data.s);
1605 human_readable(cur->buffers * 1024, p,
1609 human_readable(cur->cached * 1024, p, 255);
1613 snprintf(p, n, "%*d", pad_percents,
1614 (int) (cur->cpu_usage *
1617 snprintf(p, 4, "%*d ",
1619 (int) (cur->cpu_usage *
1623 new_bar(p, obj->data.pair.a,
1625 (int) (cur->cpu_usage * 255.0));
1628 new_graph(p, obj->a,
1629 obj->b, obj->c, obj->d,
1630 (unsigned int) (cur->cpu_usage *
1634 new_fg(p, obj->data.l);
1638 new_font(p, obj->data.s);
1643 snprintf(p, n, "%d",
1644 (int) (obj->data.net->
1648 snprintf(p, 6, "%d ",
1649 (int) (obj->data.net->
1655 snprintf(p, n, "%.1f",
1657 recv_speed / 1024.0);
1659 snprintf(p, 8, "%.1f ",
1661 recv_speed / 1024.0);
1663 OBJ(downspeedgraph) {
1664 if (obj->data.net->recv_speed == 0) // this is just to make the ugliness at start go away
1665 obj->data.net->recv_speed = 0.01;
1666 new_graph(p, obj->a, obj->b, obj->c, obj->d,
1667 (obj->data.net->recv_speed /
1674 i = obj->data.ifblock.pos - 2;
1684 snprintf(p, n, "%u.%u.%u.%u",
1685 obj->data.net->addr.
1687 obj->data.net->addr.
1689 obj->data.net->addr.
1691 obj->data.net->addr.
1696 snprintf(p, n, "%d",
1697 obj->data.net->linkstatus);
1702 FILE *fp = popen(obj->data.s, "r");
1703 int n2 = fread(p, 1, n, fp);
1707 if (n2 && p[n2 - 1] == '\n')
1718 FILE *fp = popen(obj->data.s, "r");
1719 int n2 = fread(p, 1, n, fp);
1723 if (n2 && p[n2 - 1] == '\n')
1732 if (sscanf(p, "%lf", &barnum) == 0) {
1733 ERR("reading execbar value failed (perhaps it's not the correct format?)");
1735 if (barnum > 100 || barnum < 0) {
1736 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
1738 barnum = barnum / 100.0;
1740 4, (int) (barnum * 255.0));
1746 FILE *fp = popen(obj->data.s, "r");
1747 int n2 = fread(p, 1, n, fp);
1751 if (n2 && p[n2 - 1] == '\n')
1760 if (sscanf(p, "%lf", &barnum) == 0) {
1761 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
1763 if (barnum > 100 || barnum < 0) {
1764 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
1767 25, obj->c, obj->d, (int) (barnum), 0);
1772 if (current_update_time -
1773 obj->data.execi.last_update <
1774 obj->data.execi.interval) {
1775 snprintf(p, n, "%s",
1776 obj->data.execi.buffer);
1778 char *p2 = obj->data.execi.buffer;
1780 popen(obj->data.execi.cmd,
1783 fread(p2, 1, TEXT_BUFFER_SIZE,
1788 if (n2 && p2[n2 - 1] == '\n')
1797 snprintf(p, n, "%s",
1798 obj->data.execi.buffer);
1800 obj->data.execi.last_update =
1801 current_update_time;
1806 if (obj->data.fs != NULL) {
1807 if (obj->data.fs->size == 0)
1826 if (obj->data.fs != NULL)
1827 human_readable(obj->data.fs->avail,
1831 if (obj->data.fs != NULL) {
1832 if (obj->data.fs->size)
1833 snprintf(p, n, "%*d",
1842 snprintf(p, n, "0");
1846 if (obj->data.fs != NULL)
1847 human_readable(obj->data.fs->size,
1851 if (obj->data.fs != NULL)
1852 human_readable(obj->data.fs->size -
1853 obj->data.fs->avail,
1857 if (obj->data.fs != NULL) {
1858 if (obj->data.fs->size == 0)
1876 if (obj->data.fs != NULL) {
1877 if (obj->data.fs->size)
1878 snprintf(p, 4, "%d",
1888 snprintf(p, n, "0");
1892 float *v = info.loadavg;
1894 if (obj->data.loadavg[2])
1895 snprintf(p, n, "%.2f %.2f %.2f",
1896 v[obj->data.loadavg[0] -
1898 v[obj->data.loadavg[1] -
1900 v[obj->data.loadavg[2] -
1902 else if (obj->data.loadavg[1])
1903 snprintf(p, n, "%.2f %.2f",
1904 v[obj->data.loadavg[0] -
1906 v[obj->data.loadavg[1] -
1908 else if (obj->data.loadavg[0])
1909 snprintf(p, n, "%.2f",
1910 v[obj->data.loadavg[0] -
1914 new_hr(p, obj->data.i);
1917 new_offset(p, obj->data.i);
1920 new_voffset(p, obj->data.i);
1925 r = get_i2c_info(&obj->data.i2c.fd,
1927 obj->data.i2c.devtype,
1928 obj->data.i2c.type);
1930 if (r >= 100.0 || r == 0)
1931 snprintf(p, n, "%d", (int) r);
1933 snprintf(p, n, "%.1f", r);
1936 new_alignr(p, obj->data.i);
1939 new_alignc(p, obj->data.i);
1943 if ((obj->data.ifblock.s)
1944 && (stat(obj->data.ifblock.s, &tmp) ==
1946 i = obj->data.ifblock.pos - 2;
1952 if ((obj->data.ifblock.s)
1953 && (!check_mount(obj->data.ifblock.s))) {
1954 i = obj->data.ifblock.pos - 2;
1960 if ((obj->data.ifblock.s)
1961 && system(obj->data.ifblock.s)) {
1962 i = obj->data.ifblock.pos - 2;
1968 snprintf(p, n, "%s", cur->uname_s.release);
1971 snprintf(p, n, "%s", cur->uname_s.machine);
1976 human_readable(cur->mem * 1024, p, 6);
1979 human_readable(cur->memmax * 1024, p, 255);
1984 snprintf(p, n, "%*d",
1989 snprintf(p, 4, "%*d ",
1996 new_bar(p, obj->data.pair.a,
1998 cur->memmax ? (cur->mem * 255) /
2003 new_graph(p, obj->a,
2004 obj->b, obj->c, obj->d,
2005 cur->memmax ? (cur->mem * 100.0) /
2006 (cur->memmax) : 0.0, 0);
2010 snprintf(p, n, "%d",
2011 mixer_get_avg(obj->data.l));
2014 snprintf(p, n, "%d",
2015 mixer_get_left(obj->data.l));
2018 snprintf(p, n, "%d",
2019 mixer_get_right(obj->data.l));
2022 new_bar(p, obj->data.mixerbar.w,
2023 obj->data.mixerbar.h,
2024 mixer_get_avg(obj->data.mixerbar.
2028 new_bar(p, obj->data.mixerbar.w,
2029 obj->data.mixerbar.h,
2030 mixer_get_left(obj->data.mixerbar.
2034 new_bar(p, obj->data.mixerbar.w,
2035 obj->data.mixerbar.h,
2036 mixer_get_right(obj->data.mixerbar.
2042 snprintf(p, n, "%d", cur->mail_count);
2045 snprintf(p, n, "%d", cur->new_mail_count);
2048 OBJ(ml_upload_counter) {
2049 snprintf(p, n, "%lld",
2050 mlinfo.upload_counter / 1048576);
2052 OBJ(ml_download_counter) {
2053 snprintf(p, n, "%lld",
2054 mlinfo.download_counter /
2057 OBJ(ml_nshared_files) {
2058 snprintf(p, n, "%i", mlinfo.nshared_files);
2060 OBJ(ml_shared_counter) {
2061 snprintf(p, n, "%lld",
2062 mlinfo.shared_counter / 1048576);
2064 OBJ(ml_tcp_upload_rate) {
2065 snprintf(p, n, "%.2f",
2066 (float) mlinfo.tcp_upload_rate /
2069 OBJ(ml_tcp_download_rate) {
2070 snprintf(p, n, "%.2f",
2071 (float) mlinfo.tcp_download_rate /
2074 OBJ(ml_udp_upload_rate) {
2075 snprintf(p, n, "%.2f",
2076 (float) mlinfo.udp_upload_rate /
2079 OBJ(ml_udp_download_rate) {
2080 snprintf(p, n, "%.2f",
2081 (float) mlinfo.udp_download_rate /
2084 OBJ(ml_ndownloaded_files) {
2085 snprintf(p, n, "%i",
2086 mlinfo.ndownloaded_files);
2088 OBJ(ml_ndownloading_files) {
2089 snprintf(p, n, "%i",
2090 mlinfo.ndownloading_files);
2095 snprintf(p, n, "%s",
2096 cur->uname_s.nodename);
2099 new_outline(p, obj->data.l);
2103 snprintf(p, n, "%d", cur->procs);
2105 snprintf(p, 5, "%d ",
2108 OBJ(running_processes) {
2110 snprintf(p, n, "%d",
2113 snprintf(p, 3, "%d ",
2117 snprintf(p, n, "%s", obj->data.s);
2120 new_bg(p, obj->data.l);
2123 new_stippled_hr(p, obj->data.pair.a,
2127 human_readable(cur->swap * 1024, p, 255);
2130 human_readable(cur->swapmax * 1024, p,
2134 if (cur->swapmax == 0) {
2135 strncpy(p, "No swap", 255);
2138 snprintf(p, 255, "%*u",
2144 snprintf(p, 4, "%*u ",
2152 new_bar(p, obj->data.pair.a,
2154 cur->swapmax ? (cur->swap * 255) /
2155 (cur->swapmax) : 0);
2158 snprintf(p, n, "%s", cur->uname_s.sysname);
2161 time_t t = time(NULL);
2162 struct tm *tm = localtime(&t);
2163 setlocale(LC_TIME, "");
2164 strftime(p, n, obj->data.s, tm);
2167 time_t t = time(NULL);
2168 struct tm *tm = gmtime(&t);
2169 strftime(p, n, obj->data.s, tm);
2172 human_readable(obj->data.net->recv, p,
2176 human_readable(obj->data.net->trans, p,
2180 snprintf(p, n, "%d", total_updates);
2184 snprintf(p, n, "%d",
2185 (int) (obj->data.net->
2189 snprintf(p, 5, "%d ",
2190 (int) (obj->data.net->
2196 snprintf(p, n, "%.1f",
2198 trans_speed / 1024.0);
2200 snprintf(p, 8, "%.1f ",
2202 trans_speed / 1024.0);
2205 if (obj->data.net->trans_speed == 0) // this is just to make the ugliness at start go away
2206 obj->data.net->trans_speed = 0.01;
2207 new_graph(p, obj->a, obj->b, obj->c, obj->d,
2208 (obj->data.net->trans_speed /
2212 format_seconds_short(p, n,
2216 format_seconds(p, n, (int) cur->uptime);
2221 snprintf(p, n, "%.2f",
2222 cur->seti_prog * 100.0f);
2225 new_bar(p, obj->data.pair.a,
2227 (int) (cur->seti_prog * 255.0f));
2230 snprintf(p, n, "%.0f", cur->seti_credit);
2236 snprintf(p, n, "%s", cur->mpd.title);
2239 snprintf(p, n, "%s", cur->mpd.artist);
2242 snprintf(p, n, "%s", cur->mpd.album);
2245 snprintf(p, n, "%i", cur->mpd.volume);
2248 snprintf(p, n, "%i", cur->mpd.bitrate);
2251 snprintf(p, n, "%s", cur->mpd.status);
2254 int days = 0, hours = 0, minutes =
2256 int tmp = cur->mpd.elapsed;
2257 while (tmp >= 86400) {
2261 while (tmp >= 3600) {
2271 snprintf(p, n, "%i days %i:%i:%2i",
2272 days, hours, minutes,
2275 snprintf(p, n, "%i:%i:%02i", hours,
2278 snprintf(p, n, "%i:%02i", minutes,
2282 int days = 0, hours = 0, minutes =
2284 int tmp = cur->mpd.length;
2285 while (tmp >= 86400) {
2289 while (tmp >= 3600) {
2300 "%i days %i:%i:%02i",
2301 days, hours, minutes,
2304 snprintf(p, n, "%i:%i:%02i", hours,
2307 snprintf(p, n, "%i:%02i", minutes,
2311 snprintf(p, n, "%2.0f",
2312 cur->mpd.progress * 100);
2315 new_bar(p, obj->data.pair.a,
2317 (int) (cur->mpd.progress *
2322 if (obj->data.top.type == TOP_NAME
2323 && obj->data.top.num >= 0
2324 && obj->data.top.num < 10) {
2325 // if we limit the buffer and add a bunch of space after, it stops the thing from
2326 // moving other shit around, which is really fucking annoying
2329 cur->cpu[obj->data.top.
2331 } else if (obj->data.top.type == TOP_CPU
2332 && obj->data.top.num >= 0
2333 && obj->data.top.num < 10) {
2334 snprintf(p, 7, "%3.2f ",
2335 cur->cpu[obj->data.top.
2337 } else if (obj->data.top.type == TOP_PID
2338 && obj->data.top.num >= 0
2339 && obj->data.top.num < 10) {
2340 snprintf(p, 8, "%i ",
2341 cur->cpu[obj->data.top.
2343 } else if (obj->data.top.type == TOP_MEM
2344 && obj->data.top.num >= 0
2345 && obj->data.top.num < 10) {
2346 snprintf(p, 7, "%3.2f ",
2347 cur->cpu[obj->data.top.
2352 if (obj->data.top.type == TOP_NAME
2353 && obj->data.top.num >= 0
2354 && obj->data.top.num < 10) {
2355 // if we limit the buffer and add a bunch of space after, it stops the thing from
2356 // moving other shit around, which is really fucking annoying
2359 cur->memu[obj->data.top.
2361 } else if (obj->data.top.type == TOP_CPU
2362 && obj->data.top.num >= 0
2363 && obj->data.top.num < 10) {
2364 snprintf(p, 7, "%3.2f ",
2365 cur->memu[obj->data.top.
2367 } else if (obj->data.top.type == TOP_PID
2368 && obj->data.top.num >= 0
2369 && obj->data.top.num < 10) {
2370 snprintf(p, 8, "%i ",
2371 cur->memu[obj->data.top.
2373 } else if (obj->data.top.type == TOP_MEM
2374 && obj->data.top.num >= 0
2375 && obj->data.top.num < 10) {
2376 snprintf(p, 7, "%3.2f ",
2377 cur->memu[obj->data.top.
2385 * I'm tired of everything being packed in
2392 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
2393 snprintf(p, n, "%s", obj->data.tail.buffer);
2395 obj->data.tail.last_update = current_update_time;
2399 tailstring *head = NULL;
2400 tailstring *headtmp = NULL;
2401 fp = fopen(obj->data.tail.logfile, "rt");
2403 ERR("tail logfile failed to open");
2406 obj->data.tail.readlines = 0;
2408 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*4, fp) != NULL) {
2415 addtail(&head, obj->data.tail.buffer);
2416 obj->data.tail.readlines++;
2421 if (obj->data.tail.readlines > 0) {
2422 for (i = 0;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
2423 addtail(&headtmp, head->data);
2426 strcpy(obj->data.tail.buffer, headtmp->data);
2427 headtmp = headtmp->next;
2428 for (i = 1;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
2430 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 */
2431 headtmp = headtmp->next;
2435 /* get rid of any ugly newlines at the end */
2436 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
2437 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
2439 snprintf(p, n, "%s", obj->data.tail.buffer);
2444 strcpy(obj->data.tail.buffer, "Logfile Empty");
2445 snprintf(p, n, "Logfile Empty");
2458 unsigned int a = strlen(p);
2464 if (stuff_in_upper_case) {
2474 last_update_time = current_update_time;
2480 static void set_font()
2484 if (window.xftdraw != NULL)
2485 XftDrawDestroy(window.xftdraw);
2486 window.xftdraw = XftDrawCreate(display, window.drawable,
2487 DefaultVisual(display,
2489 DefaultColormap(display,
2494 XSetFont(display, window.gc, fonts[selected_font].font->fid);
2503 static int text_start_x, text_start_y; /* text start position in window */
2504 static int text_width, text_height;
2508 static inline int get_string_width(const char *s)
2511 return *s ? calc_text_width(s, strlen(s)) : 0;
2520 static void text_size_updater(char *s)
2524 int h = font_height();
2525 /* get string widths and skip specials */
2528 if (*p == SPECIAL_CHAR) {
2530 w += get_string_width(s);
2533 if (specials[special_index].type == BAR
2534 || specials[special_index].type == GRAPH) {
2535 w += specials[special_index].width;
2536 if (specials[special_index].height > h) {
2537 h = specials[special_index].height;
2542 else if (specials[special_index].type == OFFSET) {
2543 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
2545 else if (specials[special_index].type == VOFFSET) {
2546 h += specials[special_index].arg;
2548 else if (specials[special_index].type == FONT) {
2549 fontchange = specials[special_index].font_added;
2550 selected_font = specials[special_index].font_added;
2560 w += get_string_width(s);
2573 static void update_text_area()
2577 /* update text size if it isn't fixed */
2582 text_width = minimum_width;
2585 for_each_line(text_buffer, text_size_updater);
2587 if (text_height < minimum_height)
2588 text_height = minimum_height;
2591 /* get text position on workarea */
2592 switch (text_alignment) {
2599 x = workarea[2] - text_width - gap_x;
2606 y = workarea[3] - text_height - gap_y;
2610 x = workarea[2] - text_width - gap_x;
2611 y = workarea[3] - text_height - gap_y;
2615 case NONE: // Let the WM manage the window
2626 if (own_window && !fixed_pos) {
2629 text_start_x = border_margin + 1;
2630 text_start_y = border_margin + 1;
2631 window.x = x - border_margin - 1;
2632 window.y = y - border_margin - 1;
2636 /* If window size doesn't match to workarea's size, then window
2637 * probably includes panels (gnome).
2638 * Blah, doesn't work on KDE. */
2639 if (workarea[2] != window.width
2640 || workarea[3] != window.height) {
2654 static int cur_x, cur_y; /* current x and y for drawing */
2655 static int draw_mode; /* FG, BG or OUTLINE */
2656 static long current_color;
2658 static inline void set_foreground_color(long c)
2661 XSetForeground(display, window.gc, c);
2665 static void draw_string(const char *s)
2669 int i, i2, pos, width_of_s;
2672 width_of_s = get_string_width(s);
2673 if (out_to_console) {
2676 /* daemon_run(s); the daemon can be called here, but we need to have a buffer in daemon_run() and we need to tell it when everything is ready to be sent */
2677 strcpy(tmpstring1, s);
2681 snprintf(space, 2, " ");
2683 max = ((text_width - width_of_s) / get_string_width(space));
2686 * This code looks for tabs in the text and coverts them to spaces.
2687 * The trick is getting the correct number of spaces,
2688 * and not going over the window's size without forcing
2689 * the window larger.
2691 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
2692 if (tmpstring1[i] == '\t') // 9 is ascii tab
2696 i2 < (8 - (1 + pos) % 8) && added <= max;
2698 tmpstring2[pos + i2] = ' ';
2703 if (tmpstring1[i] != 9) {
2704 tmpstring2[pos] = tmpstring1[i];
2715 c.pixel = current_color;
2716 XQueryColor(display, DefaultColormap(display, screen), &c);
2719 c2.color.red = c.red;
2720 c2.color.green = c.green;
2721 c2.color.blue = c.blue;
2722 c2.color.alpha = fonts[selected_font].font_alpha;
2724 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
2725 cur_x, cur_y, (XftChar8 *) s,
2728 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
2729 cur_x, cur_y, (XftChar8 *) s,
2735 XDrawString(display, window.drawable, window.gc,
2736 cur_x, cur_y, s, strlen(s));
2738 cur_x += width_of_s;
2740 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
2743 long redmask, greenmask, bluemask;
2744 short colour_depth = 0;
2746 void set_up_gradient()
2749 colour_depth = DisplayPlanes(display, screen);
2753 if (colour_depth != 24 && colour_depth != 16) {
2754 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
2760 for(i = (colour_depth / 3)-1; i>=0; i--) {
2762 greenmask |= 1 << i;
2765 if (colour_depth%3 == 1) {
2766 greenmask |= 1 << (colour_depth / 3);
2768 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
2769 greenmask = greenmask << (colour_depth / 3);
2772 inline unsigned long do_gradient(unsigned long first_colour, unsigned long last_colour) { /* this function returns the next colour between two colours for a gradient */
2774 int red1, green1, blue1; // first colour
2775 int red2, green2, blue2; // second colour
2776 int red3 = 0, green3 = 0, blue3 = 0; // difference
2777 short redshift = (2*colour_depth / 3 + colour_depth%3);
2778 short greenshift = (colour_depth / 3);
2779 red1 = (first_colour & redmask) >> redshift;
2780 green1 = (first_colour & greenmask) >> greenshift;
2781 blue1 = first_colour & bluemask;
2782 red2 = (last_colour & redmask) >> redshift;
2783 green2 = (last_colour & greenmask) >> greenshift;
2784 blue2 = last_colour & bluemask;
2791 if (green1 > green2) {
2794 if (green1 < green2) {
2797 if (blue1 > blue2) {
2800 if (blue1 < blue2) {
2815 if (red1 > bluemask) {
2818 if (green1 > bluemask) {
2821 if (blue1 > bluemask) {
2824 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
2828 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
2829 if (colour_depth == 0) {
2832 int red1, green1, blue1; // first colour
2833 int red2, green2, blue2; // second colour
2834 long redshift = (2*colour_depth / 3 + colour_depth%3);
2835 long greenshift = (colour_depth / 3);
2836 int red3 = 0, green3 = 0, blue3 = 0; // difference
2837 red1 = (first_colour & redmask) >> redshift;
2838 green1 = (first_colour & greenmask) >> greenshift;
2839 blue1 = first_colour & bluemask;
2840 red2 = (last_colour & redmask) >> redshift;
2841 green2 = (last_colour & greenmask) >> greenshift;
2842 blue2 = last_colour & bluemask;
2843 red3 = abs(red1 - red2);
2844 green3 = abs(green1 - green2);
2845 blue3 = abs(blue1 - blue2);
2854 static void draw_line(char *s)
2858 cur_x = text_start_x;
2859 cur_y += font_ascent();
2861 short font_h = font_height();
2863 /* find specials and draw stuff */
2866 if (*p == SPECIAL_CHAR) {
2869 /* draw string before special */
2876 switch (specials[special_index].type) {
2877 case HORIZONTAL_LINE:
2880 specials[special_index].height;
2881 int mid = font_ascent() / 2;
2882 w = text_start_x + text_width -
2885 XSetLineAttributes(display,
2890 XDrawLine(display, window.drawable,
2901 specials[special_index].height;
2903 specials[special_index].arg;
2904 int mid = font_ascent() / 2;
2905 char ss[2] = { s, s };
2906 w = text_start_x + text_width -
2909 XSetLineAttributes(display,
2914 XSetDashes(display, window.gc, 0,
2916 XDrawLine(display, window.drawable,
2927 specials[special_index].height;
2929 specials[special_index].arg;
2931 cur_y - (font_ascent() +
2933 w = specials[special_index].width;
2936 text_width - cur_x - 1;
2940 XSetLineAttributes(display,
2946 XDrawRectangle(display,
2950 XFillRectangle(display,
2954 w * bar_usage / 255,
2956 if (specials[special_index].
2958 && specials[special_index].
2962 [special_index].height;
2970 specials[special_index].height;
2974 by = cur_y - (font_ascent() +
2979 by = cur_y - (font_ascent()/2);
2981 w = specials[special_index].width;
2983 w = text_start_x + text_width - cur_x - 1;
2986 XSetLineAttributes(display,
2991 XDrawRectangle(display,
2995 XSetLineAttributes(display,
3002 int gradient_size = 0;
3003 float gradient_factor = 0;
3004 float gradient_update = 0;
3005 unsigned long tmpcolour = current_color;
3006 if (specials[special_index].first_colour != specials[special_index].last_colour) {
3007 tmpcolour = specials[special_index].first_colour;
3008 gradient_size = gradient_max(specials[special_index].first_colour, specials[special_index].last_colour);
3009 gradient_factor = (float)gradient_size / (w - 3);
3011 for (i = 0; i < w - 3; i++) {
3012 if (specials[special_index].first_colour != specials[special_index].last_colour) {
3013 XSetForeground(display, window.gc, tmpcolour);
3014 gradient_update += gradient_factor;
3015 while (gradient_update > 0) {
3016 tmpcolour = do_gradient(tmpcolour, specials[special_index].last_colour);
3020 if (i / ((float) (w - 3) / (specials[special_index].graph_width)) > j) {
3023 XDrawLine(display, window.drawable, window.gc, cur_x + i + 2, by + h, cur_x + i + 2, by + h - specials[special_index].graph[j] * (h - 1) / specials[special_index].graph_scale); /* this is mugfugly, but it works */
3025 if (specials[special_index].
3027 && specials[special_index].
3031 [special_index].height;
3034 if (draw_mode == BG) {
3035 set_foreground_color(default_bg_color);
3037 else if (draw_mode == OUTLINE) {
3038 set_foreground_color(default_out_color);
3040 set_foreground_color(default_fg_color);
3046 cur_y -= font_ascent();
3047 selected_font = specials[special_index].font_added;
3048 cur_y += font_ascent();
3058 if (draw_mode == FG)
3059 set_foreground_color(specials
3065 if (draw_mode == BG)
3066 set_foreground_color(specials
3072 if (draw_mode == OUTLINE)
3073 set_foreground_color(specials
3080 w += specials[special_index].arg;
3085 cur_y += specials[special_index].arg;
3091 int pos_x = text_width + gap_x - get_string_width(p) /*- border_margin*2 - 1*/;
3092 /*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);*/
3093 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
3094 cur_x = pos_x - specials[special_index].arg;
3101 int pos_x = (text_width)/2 - get_string_width(p)/2 - (cur_x - text_start_x);
3102 /*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);*/
3104 specials[special_index].arg)
3107 [special_index].arg;
3124 if (cur_y_add > 0) {
3126 cur_y -= font_descent();
3131 cur_y += font_descent();
3138 static void draw_text()
3141 cur_y = text_start_y;
3144 if (draw_borders && border_width > 0) {
3145 unsigned int b = (border_width + 1) / 2;
3147 if (stippled_borders) {
3149 { stippled_borders, stippled_borders };
3150 XSetLineAttributes(display, window.gc,
3151 border_width, LineOnOffDash,
3152 CapButt, JoinMiter);
3153 XSetDashes(display, window.gc, 0, ss, 2);
3155 XSetLineAttributes(display, window.gc,
3156 border_width, LineSolid,
3157 CapButt, JoinMiter);
3160 XDrawRectangle(display, window.drawable, window.gc,
3161 text_start_x - border_margin + b,
3162 text_start_y - border_margin + b,
3163 text_width + border_margin * 2 - 1 - b * 2,
3164 text_height + border_margin * 2 - 1 -
3171 for_each_line(text_buffer, draw_line);
3174 static void draw_stuff()
3177 if (draw_shades && !draw_outline) {
3180 set_foreground_color(default_bg_color);
3189 for (i = -1; i < 2; i++)
3190 for (j = -1; j < 2; j++) {
3191 if (i == 0 && j == 0)
3195 set_foreground_color(default_out_color);
3196 draw_mode = OUTLINE;
3203 set_foreground_color(default_fg_color);
3211 swap.swap_window = window.window;
3212 swap.swap_action = XdbeBackground;
3213 XdbeSwapBuffers(display, &swap, 1);
3219 static void clear_text(int exposures)
3223 return; /* The swap action is XdbeBackground, which clears */
3225 /* there is some extra space for borders and outlines */
3226 XClearArea(display, window.drawable,
3227 text_start_x - border_margin - 1,
3228 text_start_y - border_margin - 1,
3229 text_width + border_margin * 2 + 2,
3230 text_height + border_margin * 2 + 2,
3231 exposures ? True : 0);
3235 static int need_to_update;
3237 /* update_text() generates new text and clears old text area */
3238 static void update_text()
3247 static void main_loop()
3250 Region region = XCreateRegion();
3254 while (total_run_times == 0 || info.looped < total_run_times - 1) {
3259 /* wait for X event or timeout */
3261 if (!XPending(display)) {
3266 update_interval - (get_time() -
3272 tv.tv_sec = (long) t;
3273 tv.tv_usec = (long) (t * 1000000) % 1000000;
3275 FD_SET(ConnectionNumber(display), &fdsr);
3278 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
3281 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
3286 ERR("can't select(): %s",
3297 if (need_to_update) {
3299 int wx = window.x, wy = window.y;
3308 /* resize window if it isn't right size */
3310 (text_width + border_margin * 2 !=
3312 || text_height + border_margin * 2 !=
3316 border_margin * 2 + 1;
3319 border_margin * 2 + 1;
3320 XResizeWindow(display,
3326 /* move window if it isn't in right position */
3329 || window.y != wy)) {
3330 XMoveWindow(display, window.window,
3331 window.x, window.y);
3341 r.x = text_start_x - border_margin;
3342 r.y = text_start_y - border_margin;
3343 r.width = text_width + border_margin * 2;
3344 r.height = text_height + border_margin * 2;
3345 XUnionRectWithRegion(&r, region, region);
3350 /* handle X events */
3352 while (XPending(display)) {
3354 XNextEvent(display, &ev);
3362 r.width = ev.xexpose.width;
3363 r.height = ev.xexpose.height;
3364 XUnionRectWithRegion(&r, region,
3370 case ReparentNotify:
3371 /* set background to ParentRelative for all parents */
3373 set_transparent_background(window.
3377 case ConfigureNotify:
3379 /* if window size isn't what expected, set fixed size */
3380 if (ev.xconfigure.width !=
3382 || ev.xconfigure.height !=
3384 if (window.width != 0
3385 && window.height != 0)
3388 /* clear old stuff before screwing up size and pos */
3394 if (XGetWindowAttributes(display, window.window, &attrs)) {
3409 border_margin * 2 - 1;
3412 border_margin * 2 - 1;
3415 /* if position isn't what expected, set fixed pos, total_updates
3416 * avoids setting fixed_pos when window is set to weird locations
3418 if (total_updates >= 2
3420 && (window.x != ev.xconfigure.x
3423 && (ev.xconfigure.x != 0
3424 || ev.xconfigure.y != 0)) {
3436 /* XDBE doesn't seem to provide a way to clear the back buffer without
3437 * interfering with the front buffer, other than passing XdbeBackground
3438 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
3439 * redraw the text even if it wasn't part of the exposed area. OTOH,
3440 * if we're not going to call draw_stuff at all, then no swap happens
3441 * and we can safely do nothing.
3444 if (!XEmptyRegion(region)) {
3448 r.x = text_start_x - border_margin;
3449 r.y = text_start_y - border_margin;
3450 r.width = text_width + border_margin * 2;
3451 r.height = text_height + border_margin * 2;
3452 XUnionRectWithRegion(&r, region, region);
3455 XSetRegion(display, window.gc, region);
3458 XftDrawSetClip(window.xftdraw, region);
3463 XDestroyRegion(region);
3464 region = XCreateRegion();
3471 static void load_config_file(const char *);
3473 /* signal handler that reloads config file */
3474 static void reload_handler(int a)
3476 ERR("Conky: received signal %d, reloading config\n", a);
3478 if (current_config) {
3480 load_config_file(current_config);
3485 extract_variable_text(text);
3492 static void clean_up()
3497 XdbeDeallocateBackBufferName(display, window.back_buffer);
3501 XDestroyWindow(display, window.window);
3505 XClearWindow(display, RootWindow(display, screen));
3510 XFreeGC(display, window.gc);
3514 /* it is really pointless to free() memory at the end of program but ak|ra
3515 * wants me to do this */
3517 free_text_objects();
3519 if (text != original_text)
3522 free(current_config);
3523 free(current_mail_spool);
3529 static void term_handler(int a)
3531 a = a; /* to get rid of warning */
3536 static int string_to_bool(const char *s)
3540 if (strcasecmp(s, "yes") == 0)
3542 if (strcasecmp(s, "true") == 0)
3544 if (strcasecmp(s, "1") == 0)
3549 static enum alignment string_to_alignment(const char *s)
3551 if (strcasecmp(s, "top_left") == 0)
3553 else if (strcasecmp(s, "top_right") == 0)
3555 else if (strcasecmp(s, "bottom_left") == 0)
3557 else if (strcasecmp(s, "bottom_right") == 0)
3558 return BOTTOM_RIGHT;
3559 else if (strcasecmp(s, "tl") == 0)
3561 else if (strcasecmp(s, "tr") == 0)
3563 else if (strcasecmp(s, "bl") == 0)
3565 else if (strcasecmp(s, "br") == 0)
3566 return BOTTOM_RIGHT;
3567 else if (strcasecmp(s, "none") == 0)
3574 static void set_default_configurations(void)
3576 fork_to_background = 0;
3577 total_run_times = 0;
3578 info.cpu_avg_samples = 2;
3579 info.net_avg_samples = 2;
3584 strcpy(info.mpd.host, "localhost");
3585 info.mpd.port = 6600;
3586 info.mpd.status = "Checking status...";
3595 default_fg_color = WhitePixel(display, screen);
3596 default_bg_color = BlackPixel(display, screen);
3597 default_out_color = BlackPixel(display, screen);
3601 set_first_font("6x10");
3609 stippled_borders = 0;
3612 text_alignment = BOTTOM_LEFT;
3616 free(current_mail_spool);
3619 variable_substitute(MAIL_FILE, buf, 256);
3621 current_mail_spool = strdup(buf);
3625 update_interval = 10.0;
3626 stuff_in_upper_case = 0;
3628 mlconfig.mldonkey_hostname = "127.0.0.1";
3629 mlconfig.mldonkey_port = 4001;
3630 mlconfig.mldonkey_login = NULL;
3631 mlconfig.mldonkey_password = NULL;
3635 static void load_config_file(const char *f)
3637 #define CONF_ERR ERR("%s: %d: config file error", f, line)
3641 set_default_configurations();
3643 fp = open_file(f, 0);
3648 char buf[256], *p, *p2, *name, *value;
3650 if (fgets(buf, 256, fp) == NULL)
3655 /* break at comment */
3656 p2 = strchr(p, '#');
3661 while (*p && isspace((int) *p))
3664 continue; /* empty line */
3670 while (*p2 && !isspace((int) *p2))
3673 *p2 = '\0'; /* break at name's end */
3680 while (*p && isspace((int) *p))
3685 p2 = value + strlen(value);
3686 while (isspace((int) *(p2 - 1)))
3692 #define CONF2(a) if (strcasecmp(name, a) == 0)
3693 #define CONF(a) else CONF2(a)
3694 #define CONF3(a,b) \
3695 else if (strcasecmp(name, a) == 0 || strcasecmp(name, a) == 0)
3699 CONF2("alignment") {
3701 int a = string_to_alignment(value);
3711 on_bottom = string_to_bool(value);
3715 CONF("background") {
3716 fork_to_background = string_to_bool(value);
3720 CONF2("background") {
3721 fork_to_background = string_to_bool(value);
3725 CONF("border_margin") {
3727 border_margin = strtol(value, 0, 0);
3731 CONF("border_width") {
3733 border_width = strtol(value, 0, 0);
3737 CONF("default_color") {
3739 default_fg_color = get_x11_color(value);
3743 CONF3("default_shade_color", "default_shadecolor") {
3745 default_bg_color = get_x11_color(value);
3749 CONF3("default_outline_color", "default_outlinecolor") {
3751 default_out_color = get_x11_color(value);
3759 strcpy(info.mpd.host, value);
3765 info.mpd.port = strtol(value, 0, 0);
3766 if (info.mpd.port < 1
3767 || info.mpd.port > 0xffff)
3772 CONF("cpu_avg_samples") {
3774 cpu_avg_samples = strtol(value, 0, 0);
3775 if (cpu_avg_samples < 1
3776 || cpu_avg_samples > 14)
3785 CONF("net_avg_samples") {
3787 net_avg_samples = strtol(value, 0, 0);
3788 if (net_avg_samples < 1
3789 || net_avg_samples > 14)
3805 CONF("double_buffer") {
3807 use_xdbe = string_to_bool(value);
3812 CONF("override_utf8_locale") {
3813 utf8_mode = string_to_bool(value);
3816 CONF("draw_borders") {
3817 draw_borders = string_to_bool(value);
3819 CONF("draw_shades") {
3820 draw_shades = string_to_bool(value);
3822 CONF("draw_outline") {
3823 draw_outline = string_to_bool(value);
3826 CONF("out_to_console") {
3827 out_to_console = string_to_bool(value);
3829 CONF("use_spacer") {
3830 use_spacer = string_to_bool(value);
3835 use_xft = string_to_bool(value);
3840 set_first_font(value);
3846 if (value && font_count >= 0)
3847 fonts[0].font_alpha = atof(value)
3855 if (string_to_bool(value))
3856 ERR("Xft not enabled");
3859 /* xftfont silently ignored when no Xft */
3862 /* xftalpha is silently ignored when no Xft */
3867 set_first_font(value);
3873 gap_x = atoi(value);
3879 gap_y = atoi(value);
3884 CONF("mail_spool") {
3887 variable_substitute(value, buf, 256);
3891 if (current_mail_spool)
3892 free(current_mail_spool);
3893 current_mail_spool = strdup(buf);
3899 CONF("minimum_size") {
3902 (value, "%d %d", &minimum_width,
3903 &minimum_height) != 2)
3906 &minimum_width) != 1)
3912 CONF("no_buffers") {
3913 no_buffers = string_to_bool(value);
3916 CONF("mldonkey_hostname") {
3918 if (mlconfig.mldonkey_hostname != NULL) {
3919 free(mlconfig.mldonkey_hostname);
3921 mlconfig.mldonkey_hostname = strdup(value);
3926 CONF("mldonkey_port") {
3928 mlconfig.mldonkey_port = atoi(value);
3932 CONF("mldonkey_login") {
3934 if (mlconfig.mldonkey_login != NULL) {
3935 free(mlconfig.mldonkey_login);
3937 mlconfig.mldonkey_login = strdup(value);
3942 CONF("mldonkey_password") {
3944 if (mlconfig.mldonkey_password != NULL) {
3945 free(mlconfig.mldonkey_password);
3947 mlconfig.mldonkey_password = strdup(value);
3953 CONF("pad_percents") {
3954 pad_percents = atoi(value);
3958 CONF("own_window") {
3959 own_window = string_to_bool(value);
3965 CONF("stippled_borders") {
3967 stippled_borders = strtol(value, 0, 0);
3969 stippled_borders = 4;
3973 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
3976 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
3978 CONF("update_interval") {
3980 update_interval = strtod(value, 0);
3984 CONF("total_run_times") {
3986 total_run_times = strtod(value, 0);
3991 stuff_in_upper_case = string_to_bool(value);
3996 malloc(strlen(value)
3998 strcpy(seti_dir, value);
4002 if (text != original_text)
4012 int l = strlen(text);
4013 if (fgets(buf, 256, fp) == NULL)
4016 realloc(text, l + strlen(buf)
4020 if (strlen(text) > 1024 * 8)
4027 ERR("%s: %d: no such configuration: '%s'", f, line, name);
4037 /* : means that character before that takes an argument */
4038 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
4051 int main(int argc, char **argv)
4053 /* handle command line parameters that don't change configs */
4059 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
4060 *s) || ((s = getenv("LANG")) && *s)) {
4062 for(x = 0; x < strlen(s) ; x++) {
4063 temp[x] = tolower(s[x]);
4065 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
4069 if (!setlocale(LC_CTYPE, "")) {
4070 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
4075 int c = getopt(argc,
4085 ("Conky " VERSION " compiled " __DATE__ "\n");
4089 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
4090 * though free() does the NULL check itself;), then load optarg value */
4092 free(current_config);
4093 current_config = strdup(optarg);
4098 ("Usage: %s [OPTION]...\n"
4099 "Conky is a system monitor that renders text on desktop or to own transparent\n"
4100 "window. Command line options will override configurations defined in config\n"
4103 " -c FILE config file to load instead of "
4106 " -d daemonize, fork to background\n"
4109 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
4110 " -f FONT font to use\n"
4112 " -o create own window to draw\n"
4115 " -b double buffer (prevents flickering)\n"
4117 " -w WIN_ID window id to draw\n"
4118 " -x X x position\n"
4119 " -y Y y position\n"
4121 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
4122 " -u SECS update interval\n"
4123 " -i NUM number of times to update Conky\n", argv[0]);
4127 window.window = strtol(optarg, 0, 0);
4136 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
4140 tmpstring1 = (char *)
4141 malloc(TEXT_BUFFER_SIZE);
4142 tmpstring2 = (char *)
4143 malloc(TEXT_BUFFER_SIZE);
4145 /* load current_config or CONFIG_FILE */
4148 if (current_config == NULL) {
4149 /* load default config file */
4152 variable_substitute(CONFIG_FILE, buf, 256);
4155 current_config = strdup(buf);
4159 if (current_config != NULL)
4160 load_config_file(current_config);
4162 set_default_configurations();
4165 if (current_mail_spool == NULL) {
4167 variable_substitute(MAIL_FILE, buf, 256);
4170 current_mail_spool = strdup(buf);
4174 /* handle other command line arguments */
4179 int c = getopt(argc,
4187 fork_to_background = 1;
4192 set_first_font(optarg);
4195 text_alignment = string_to_alignment(optarg);
4213 if (text != original_text)
4215 text = strdup(optarg);
4216 convert_escapes(text);
4220 update_interval = strtod(optarg, 0);
4224 total_run_times = strtod(optarg, 0);
4228 gap_x = atoi(optarg);
4232 gap_y = atoi(optarg);
4246 /* generate text and get initial size */
4247 extract_variable_text(text);
4248 if (text != original_text) {
4257 update_text_area(); /* to get initial size of the window */
4259 #if defined OWN_WINDOW
4262 text_width + border_margin * 2 + 1,
4263 text_height + border_margin * 2 + 1,
4264 on_bottom, fixed_pos);
4268 text_width + border_margin * 2 + 1,
4269 text_height + border_margin * 2 + 1,
4274 update_text_area(); /* to position text/window on screen */
4278 // why the fuck not?
4284 if (own_window && !fixed_pos)
4285 XMoveWindow(display, window.window, window.x, window.y);
4295 if (fork_to_background) {
4299 ERR("can't fork() to background: %s",
4309 "Conky: forked to background, pid is %d\n",
4315 /* set SIGUSR1, SIGINT and SIGTERM handlers */
4320 sa.sa_handler = reload_handler;
4321 sigemptyset(&sa.sa_mask);
4322 sa.sa_flags = SA_RESTART;
4323 if (sigaction(SIGUSR1, &sa, NULL) != 0)
4324 ERR("can't set signal handler for SIGUSR1: %s",
4327 sa.sa_handler = term_handler;
4328 sigemptyset(&sa.sa_mask);
4329 sa.sa_flags = SA_RESTART;
4330 if (sigaction(SIGINT, &sa, NULL) != 0)
4331 ERR("can't set signal handler for SIGINT: %s",
4334 sa.sa_handler = term_handler;
4335 sigemptyset(&sa.sa_mask);
4336 sa.sa_flags = SA_RESTART;
4337 if (sigaction(SIGTERM, &sa, NULL) != 0)
4338 ERR("can't set signal handler for SIGTERM: %s",