1 /* Conky, a system monitor, based on torsmo
3 * This program is licensed under BSD license, read COPYING
23 #include <X11/Xutil.h>
24 #include <sys/types.h>
27 #define CONFIG_FILE "$HOME/.conkyrc"
28 #define MAIL_FILE "$MAIL"
29 #define MAX_IF_BLOCK_DEPTH 5
43 char name[TEXT_BUFFER_SIZE];
53 static int selected_font = 0;
54 static int font_count = -1;
55 struct font_list *fonts = NULL;
59 #define font_height() use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
60 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
61 #define font_ascent() use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent
62 #define font_descent() use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent
66 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
67 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
68 #define font_descent() fonts[selected_font].font->max_bounds.descent
72 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
76 int addfont(const char *data_in)
78 if (font_count > MAX_FONTS) {
79 CRIT_ERR("you don't need that many fonts, sorry.");
82 if (font_count == 0) {
83 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
87 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
89 CRIT_ERR("realloc in addfont");
91 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
92 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
94 fonts[font_count].font_alpha = 0xffff;
97 CRIT_ERR("Oops...looks like something overflowed in addfont().");
102 void set_first_font(const char *data_in)
104 if (font_count < 0) {
105 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
110 if (strlen(data_in) > 1) {
111 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
113 fonts[0].font_alpha = 0xffff;
124 static void load_fonts()
127 for (i=0;i<=font_count;i++) {
131 if (fonts[i].xftfont != NULL)
132 XftFontClose(display, fonts[i].xftfont);
134 if ((fonts[i].xftfont =
135 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
138 ERR("can't load Xft font '%s'", fonts[i].name);
139 if ((fonts[i].xftfont =
140 XftFontOpenName(display, screen,
141 "courier-12")) != NULL)
144 ERR("can't load Xft font '%s'", "courier-12");
146 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
147 CRIT_ERR("can't load font '%s'", "fixed");
154 /* load normal font */
155 if (fonts[i].font != NULL)
156 XFreeFont(display, fonts[i].font);
158 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
159 ERR("can't load font '%s'", fonts[i].name);
160 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
161 CRIT_ERR("can't load font '%s'", "fixed");
167 /* default config file */
168 static char *current_config;
170 /* set to 1 if you want all text to be in uppercase */
171 static unsigned int stuff_in_upper_case;
173 /* Position on the screen */
174 static int text_alignment;
175 static int gap_x, gap_y;
177 /* Update interval */
178 static double update_interval;
180 /* Run how many times? */
181 static unsigned long total_run_times;
184 static int fork_to_background;
187 static int draw_borders;
188 static int stippled_borders;
190 static int draw_shades, draw_outline;
192 static int border_margin, border_width;
194 static long default_fg_color, default_bg_color, default_out_color;
196 static int cpu_avg_samples, net_avg_samples;
198 /*#ifdef OWN_WINDOW*/
199 /* create own window or draw stuff to root? */
200 static int own_window = 0;
202 /* fixed size/pos is set if wm/user changes them */
203 static int fixed_size = 0, fixed_pos = 0;
206 static int minimum_width, minimum_height;
208 /* no buffers in used memory? */
211 /* pad percentages to decimals? */
212 static int pad_percents = 0;
218 /* Text that is shown */
219 static char original_text[] =
220 "$nodename - $sysname $kernel on $machine\n"
222 "${color grey}Uptime:$color $uptime\n"
223 "${color grey}Frequency (in MHz):$color $freq\n"
224 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
225 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
226 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
227 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
229 "${color grey}File systems:\n"
230 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
231 "${color grey}Networking:\n"
232 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
233 "${color grey}Temperatures:\n"
234 " CPU:$color ${i2c temp 1}°C${color grey} - MB:$color ${i2c temp 2}°C\n"
237 "${color grey}SETI@Home Statistics:\n"
238 "${color grey}Seti Unit Number:$color $seti_credit\n"
239 "${color grey}Seti Progress:$color $seti_prog% $seti_progbar\n"
242 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
243 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
245 "${color grey}Name PID CPU% MEM%\n"
246 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
247 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
248 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
249 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
250 "${tail /var/log/Xorg.0.log 3}";
252 static char *text = original_text;
254 static int total_updates;
257 static int blockdepth = 0;
258 static int if_jumped = 0;
259 static int blockstart[MAX_IF_BLOCK_DEPTH];
261 int check_mount(char *s)
264 FILE *mtab = fopen("/etc/mtab", "r");
266 char buf1[256], buf2[128];
267 while (fgets(buf1, 256, mtab)) {
268 sscanf(buf1, "%*s %128s", buf2);
269 if (!strcmp(s, buf2)) {
276 ERR("Could not open mtab");
283 static inline int calc_text_width(const char *s, unsigned int l)
289 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, s, l, &gi);
291 XftTextExtents8(display, fonts[selected_font].xftfont, s, l, &gi);
297 return XTextWidth(fonts[selected_font].font, s, l);
301 /* formatted text to render on screen, generated in generate_text(),
302 * drawn in draw_stuff() */
304 static char text_buffer[TEXT_BUFFER_SIZE * 4];
306 /* special stuff in text_buffer */
308 #define SPECIAL_CHAR '\x01'
324 static struct special_t {
334 unsigned long first_colour; // for graph gradient
335 unsigned long last_colour;
338 static int special_count;
339 static int special_index; /* used when drawing */
341 #define MAX_GRAPH_DEPTH 256 /* why 256? who knows. */
343 static struct special_t *new_special(char *buf, int t)
345 if (special_count >= 128)
346 CRIT_ERR("too many special things in text");
348 buf[0] = SPECIAL_CHAR;
350 if (t == GRAPH && specials[special_count].graph == NULL) {
351 if (specials[special_count].width > 0
352 && specials[special_count].width < MAX_GRAPH_DEPTH)
353 specials[special_count].graph_width = specials[special_count].width - 3; // subtract 3 for the box
355 specials[special_count].graph_width =
357 specials[special_count].graph =
358 calloc(specials[special_count].graph_width,
360 specials[special_count].graph_scale = 100;
362 specials[special_count].type = t;
363 return &specials[special_count++];
366 typedef struct tailstring_list {
367 char data[TEXT_BUFFER_SIZE];
368 struct tailstring_list *next;
371 void addtail(tailstring ** head, char *data_in)
374 if ((tmp = malloc(sizeof(*tmp))) == NULL) {
377 strncpy(tmp->data, data_in, TEXT_BUFFER_SIZE);
382 void freetail(tailstring * head)
386 while (head != NULL) {
395 static void new_bar(char *buf, int w, int h, int usage)
397 struct special_t *s = new_special(buf, BAR);
398 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
403 static const char *scan_bar(const char *args, int *w, int *h)
405 *w = 0; /* zero width means all space that is available */
407 /* bar's argument is either height or height,width */
410 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
411 sscanf(args, "%d %n", h, &n);
418 static char *scan_font(const char *args)
420 if (args && sizeof(args) < 127) {
424 ERR("font scan failed, lets hope it doesn't mess stuff up");
429 static void new_font(char *buf, char * args) {
430 struct special_t *s = new_special(buf, FONT);
431 if (!s->font_added) {
432 s->font_added = addfont(args);
437 inline void graph_append(struct special_t *graph, double f)
441 graph->graph_scale = 0;
443 graph->graph[graph->graph_width - 1] = f; /* add new data */
444 for (i = 0; i < graph->graph_width - 1; i++) { /* shift all the data by 1 */
445 graph->graph[i] = graph->graph[i + 1];
446 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
447 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
452 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scaled)
454 struct special_t *s = new_special(buf, GRAPH);
457 s->first_colour = first_colour;
458 s->last_colour = second_colour;
461 s->graph_width = s->width - 3; // subtract 3 for rectangle around
466 s->graph_scale = 100;
471 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour)
473 *w = 0; /* zero width means all space that is available */
477 /* graph's argument is either height or height,width */
479 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
480 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
483 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
486 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
489 if (sscanf(args, "%d,%d", h, w) < 2) {
492 sscanf(args, "%*s %d,%d", h, w);
504 static inline void new_hr(char *buf, int a)
506 new_special(buf, HORIZONTAL_LINE)->height = a;
509 static inline void new_stippled_hr(char *buf, int a, int b)
511 struct special_t *s = new_special(buf, STIPPLED_HR);
516 static inline void new_fg(char *buf, long c)
518 new_special(buf, FG)->arg = c;
521 static inline void new_bg(char *buf, long c)
523 new_special(buf, BG)->arg = c;
526 static inline void new_outline(char *buf, long c)
528 new_special(buf, OUTLINE)->arg = c;
531 static inline void new_offset(char *buf, long c)
533 new_special(buf, OFFSET)->arg = c;
536 static inline void new_alignr(char *buf, long c)
538 new_special(buf, ALIGNR)->arg = c;
541 static inline void new_alignc(char *buf, long c)
543 new_special(buf, ALIGNC)->arg = c;
546 /* quite boring functions */
548 static inline void for_each_line(char *b, void (*f) (char *))
552 for (ps = b, pe = b; *pe; pe++) {
565 static void convert_escapes(char *buf)
567 char *p = buf, *s = buf;
583 /* converts from bytes to human readable format (k, M, G) */
584 static void human_readable(long long a, char *buf, int size)
586 if (a >= 1024 * 1024 * 1024)
587 snprintf(buf, size, "%.2fG", (a / 1024 / 1024) / 1024.0);
588 else if (a >= 1024 * 1024) {
589 double m = (a / 1024) / 1024.0;
591 snprintf(buf, size, "%.0fM", m);
593 snprintf(buf, size, "%.1fM", m);
594 } else if (a >= 1024)
595 snprintf(buf, size, "%Ldk", a / (long long) 1024);
597 snprintf(buf, size, "%Ld", a);
602 enum text_object_type {
665 OBJ_ml_upload_counter,
666 OBJ_ml_download_counter,
667 OBJ_ml_nshared_files,
668 OBJ_ml_shared_counter,
669 OBJ_ml_tcp_upload_rate,
670 OBJ_ml_tcp_download_rate,
671 OBJ_ml_udp_upload_rate,
672 OBJ_ml_udp_download_rate,
673 OBJ_ml_ndownloaded_files,
674 OBJ_ml_ndownloading_files,
677 OBJ_running_processes,
686 OBJ_temp1, /* i2c is used instead in these */
738 char *s; /* some string */
739 int i; /* some integer */
740 long l; /* some other integer */
741 struct net_stat *net;
743 unsigned char loadavg[3];
776 char buffer[TEXT_BUFFER_SIZE*4];
792 static unsigned int text_object_count;
793 static struct text_object *text_objects;
795 /* new_text_object() allocates a new zeroed text_object */
796 static struct text_object *new_text_object()
799 text_objects = (struct text_object *) realloc(text_objects,
803 memset(&text_objects[text_object_count - 1], 0,
804 sizeof(struct text_object));
806 return &text_objects[text_object_count - 1];
809 static void free_text_objects()
813 for (i = 0; i < text_object_count; i++) {
814 switch (text_objects[i].type) {
816 close(text_objects[i].data.i);
820 close(text_objects[i].data.i2c.fd);
824 case OBJ_if_existing:
827 free(text_objects[i].data.ifblock.s);
842 free(text_objects[i].data.s);
846 free(text_objects[i].data.execi.cmd);
847 free(text_objects[i].data.execi.buffer);
854 text_object_count = 0;
857 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
862 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
863 *a = mixer_init(buf1);
864 (void) scan_bar(arg + n, w, h);
867 (void) scan_bar(arg, w, h);
871 /* construct_text_object() creates a new text_object */
872 static void construct_text_object(const char *s, const char *arg)
874 struct text_object *obj = new_text_object();
876 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
877 #define END ; } } else
880 obj->type = OBJ_color;
881 obj->data.l = get_x11_color(s);
883 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
884 END OBJ(acpiacadapter, 0)
885 END OBJ(freq, 0) END OBJ(acpifan, 0) END OBJ(battery,
888 sscanf(arg, "%63s", bat);
891 obj->data.s = strdup(bat);
892 END OBJ(buffers, INFO_BUFFERS)
893 END OBJ(cached, INFO_BUFFERS)
894 END OBJ(cpu, INFO_CPU)
895 END OBJ(cpubar, INFO_CPU)
896 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
897 END OBJ(cpugraph, INFO_CPU)
898 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d);
899 END OBJ(color, 0) obj->data.l =
900 arg ? get_x11_color(arg) : default_fg_color;
903 obj->data.s = scan_font(arg);
905 OBJ(downspeed, INFO_NET) obj->data.net = get_net_stat(arg);
906 END OBJ(downspeedf, INFO_NET) obj->data.net = get_net_stat(arg);
907 END OBJ(downspeedgraph, INFO_NET)
908 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d);
910 sscanf(arg, "%63s %*i,%*i %*i", buf);
911 obj->data.net = get_net_stat(buf);
912 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
913 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
922 text_objects[blockstart[blockdepth - 1] -
923 1].data.ifblock.pos = text_object_count;
924 blockstart[blockdepth - 1] = text_object_count;
925 obj->data.ifblock.pos = text_object_count + 2;
927 ERR("$else: no matching $if_*");
932 text_objects[blockstart[blockdepth] - 1].data.ifblock.pos =
935 ERR("$endif: no matching $if_*");
939 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
940 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
941 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
942 END OBJ(execi, 0) unsigned int n;
945 || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
947 ERR("${execi <interval> command}");
948 obj->type = OBJ_text;
949 snprintf(buf, 256, "${%s}", s);
950 obj->data.s = strdup(buf);
952 obj->data.execi.cmd = strdup(arg + n);
953 obj->data.execi.buffer =
954 (char *) calloc(1, TEXT_BUFFER_SIZE);
956 END OBJ(pre_exec, 0) obj->type = OBJ_text;
958 FILE *fp = popen(arg, "r");
962 n = fread(buf, 1, 2048, fp);
965 if (n && buf[n - 1] == '\n')
970 obj->data.s = strdup(buf);
972 obj->data.s = strdup("");
975 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
976 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
978 while (isspace(*arg))
984 obj->data.fsbar.fs = prepare_fs_stat(arg);
985 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
988 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
992 obj->data.fsbar.fs = prepare_fs_stat(arg);
993 END OBJ(fs_free, INFO_FS) if (!arg)
995 obj->data.fs = prepare_fs_stat(arg);
996 END OBJ(fs_used_perc, INFO_FS) if (!arg)
998 obj->data.fs = prepare_fs_stat(arg);
999 END OBJ(fs_free_perc, INFO_FS) if (!arg)
1001 obj->data.fs = prepare_fs_stat(arg);
1002 END OBJ(fs_size, INFO_FS) if (!arg)
1004 obj->data.fs = prepare_fs_stat(arg);
1005 END OBJ(fs_used, INFO_FS) if (!arg)
1007 obj->data.fs = prepare_fs_stat(arg);
1008 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
1009 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
1010 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
1014 ERR("i2c needs arguments");
1015 obj->type = OBJ_text;
1016 obj->data.s = strdup("${i2c}");
1020 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
1021 /* if scanf couldn't read three values, read type and num and use
1023 sscanf(arg, "%63s %d", buf2, &n);
1025 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
1026 obj->data.i2c.devtype);
1027 strcpy(obj->data.i2c.type, buf2);
1030 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
1031 obj->data.i2c.devtype);
1032 strcpy(obj->data.i2c.type, buf2);
1035 END OBJ(top, INFO_TOP)
1039 ERR("top needs arguments");
1040 obj->type = OBJ_text;
1041 obj->data.s = strdup("${top}");
1044 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1045 if (strcmp(buf, "name") == 0) {
1046 obj->data.top.type = TOP_NAME;
1047 } else if (strcmp(buf, "cpu") == 0) {
1048 obj->data.top.type = TOP_CPU;
1049 } else if (strcmp(buf, "pid") == 0) {
1050 obj->data.top.type = TOP_PID;
1051 } else if (strcmp(buf, "mem") == 0) {
1052 obj->data.top.type = TOP_MEM;
1054 ERR("invalid arg for top");
1057 if (n < 1 || n > 10) {
1058 CRIT_ERR("invalid arg for top");
1061 obj->data.top.num = n - 1;
1065 ERR("invalid args given for top");
1068 END OBJ(top_mem, INFO_TOP)
1072 ERR("top_mem needs arguments");
1073 obj->type = OBJ_text;
1074 obj->data.s = strdup("${top_mem}");
1077 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1078 if (strcmp(buf, "name") == 0) {
1079 obj->data.top.type = TOP_NAME;
1080 } else if (strcmp(buf, "cpu") == 0) {
1081 obj->data.top.type = TOP_CPU;
1082 } else if (strcmp(buf, "pid") == 0) {
1083 obj->data.top.type = TOP_PID;
1084 } else if (strcmp(buf, "mem") == 0) {
1085 obj->data.top.type = TOP_MEM;
1087 ERR("invalid arg for top");
1090 if (n < 1 || n > 10) {
1091 CRIT_ERR("invalid arg for top");
1094 obj->data.top.num = n - 1;
1098 ERR("invalid args given for top");
1101 END OBJ(addr, INFO_NET) obj->data.net = get_net_stat(arg);
1102 END OBJ(linkstatus, INFO_WIFI) obj->data.net = get_net_stat(arg);
1107 ERR("tail needs arguments");
1108 obj->type = OBJ_text;
1109 obj->data.s = strdup("${tail}");
1112 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
1113 if (n1 < 1 || n1 > 30) {
1115 ("invalid arg for tail, number of lines must be between 1 and 30");
1119 fp = fopen(buf, "rt");
1121 obj->data.tail.logfile =
1122 malloc(TEXT_BUFFER_SIZE);
1123 strcpy(obj->data.tail.logfile, buf);
1124 obj->data.tail.wantedlines = n1 - 1;
1125 obj->data.tail.interval =
1126 update_interval * 2;
1131 ("tail logfile does not exist, or you do not have correct permissions");
1134 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
1135 if (n1 < 1 || n1 > 30) {
1137 ("invalid arg for tail, number of lines must be between 1 and 30");
1139 } else if (n2 < 1 || n2 < update_interval) {
1141 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
1145 fp = fopen(buf, "rt");
1147 obj->data.tail.logfile =
1148 malloc(TEXT_BUFFER_SIZE);
1149 strcpy(obj->data.tail.logfile, buf);
1150 obj->data.tail.wantedlines = n1 - 1;
1151 obj->data.tail.interval = n2;
1156 ("tail logfile does not exist, or you do not have correct permissions");
1162 ERR("invalid args given for tail");
1165 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
1167 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1168 if (r >= 3 && (c < 1 || c > 3))
1170 if (r >= 2 && (b < 1 || b > 3))
1172 if (r >= 1 && (a < 1 || a > 3))
1175 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1176 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1177 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1178 END OBJ(if_existing, 0)
1179 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1180 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1183 ERR("if_existing needs an argument");
1184 obj->data.ifblock.s = 0;
1186 obj->data.ifblock.s = strdup(arg);
1187 blockstart[blockdepth] = text_object_count;
1188 obj->data.ifblock.pos = text_object_count + 2;
1190 END OBJ(if_mounted, 0)
1191 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1192 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1195 ERR("if_mounted needs an argument");
1196 obj->data.ifblock.s = 0;
1198 obj->data.ifblock.s = strdup(arg);
1199 blockstart[blockdepth] = text_object_count;
1200 obj->data.ifblock.pos = text_object_count + 2;
1202 END OBJ(if_running, 0)
1203 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1204 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1208 snprintf(buf, 256, "pidof %s >/dev/null", arg);
1209 obj->data.ifblock.s = strdup(buf);
1211 ERR("if_running needs an argument");
1212 obj->data.ifblock.s = 0;
1214 blockstart[blockdepth] = text_object_count;
1215 obj->data.ifblock.pos = text_object_count + 2;
1219 END OBJ(mails, INFO_MAIL)
1220 END OBJ(mem, INFO_MEM)
1221 END OBJ(memmax, INFO_MEM)
1222 END OBJ(memperc, INFO_MEM)
1223 END OBJ(membar, INFO_MEM)
1224 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1225 END OBJ(membar, INFO_MEM)
1226 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d);
1227 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
1228 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
1229 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
1230 END OBJ(mixerbar, INFO_MIXER)
1231 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1232 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1233 END OBJ(mixerlbar, INFO_MIXER)
1234 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1235 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1236 END OBJ(mixerrbar, INFO_MIXER)
1237 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1238 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1241 OBJ(ml_upload_counter, INFO_MLDONKEY)
1242 END OBJ(ml_download_counter, INFO_MLDONKEY)
1243 END OBJ(ml_nshared_files, INFO_MLDONKEY)
1244 END OBJ(ml_shared_counter, INFO_MLDONKEY)
1245 END OBJ(ml_tcp_upload_rate, INFO_MLDONKEY)
1246 END OBJ(ml_tcp_download_rate, INFO_MLDONKEY)
1247 END OBJ(ml_udp_upload_rate, INFO_MLDONKEY)
1248 END OBJ(ml_udp_download_rate, INFO_MLDONKEY)
1249 END OBJ(ml_ndownloaded_files, INFO_MLDONKEY)
1250 END OBJ(ml_ndownloading_files, INFO_MLDONKEY) END
1252 OBJ(new_mails, INFO_MAIL)
1253 END OBJ(nodename, 0)
1254 END OBJ(processes, INFO_PROCS)
1255 END OBJ(running_processes, INFO_RUN_PROCS)
1256 END OBJ(shadecolor, 0)
1257 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
1258 END OBJ(outlinecolor, 0)
1259 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
1260 END OBJ(stippled_hr, 0) int a = stippled_borders, b = 1;
1262 if (sscanf(arg, "%d %d", &a, &b) != 2)
1263 sscanf(arg, "%d", &b);
1267 obj->data.pair.a = a;
1268 obj->data.pair.b = b;
1269 END OBJ(swap, INFO_MEM)
1270 END OBJ(swapmax, INFO_MEM)
1271 END OBJ(swapperc, INFO_MEM)
1272 END OBJ(swapbar, INFO_MEM)
1273 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1274 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
1276 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
1277 obj->data.i2c.devtype);
1278 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
1280 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
1281 obj->data.i2c.devtype);
1282 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1283 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1284 END OBJ(totaldown, INFO_NET) obj->data.net = get_net_stat(arg);
1285 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
1287 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 1;
1288 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 1;
1289 END OBJ(upspeed, INFO_NET) obj->data.net = get_net_stat(arg);
1290 END OBJ(upspeedf, INFO_NET) obj->data.net = get_net_stat(arg);
1291 END OBJ(upspeedgraph, INFO_NET)
1292 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d);
1294 sscanf(arg, "%63s %*i,%*i %*i", buf);
1295 obj->data.net = get_net_stat(buf);
1296 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
1297 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
1302 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
1303 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
1305 OBJ(seti_prog, INFO_SETI) END OBJ(seti_progbar, INFO_SETI)
1306 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1307 END OBJ(seti_credit, INFO_SETI) END
1310 OBJ(metar_ob_time, INFO_METAR)
1312 OBJ(metar_temp, INFO_METAR)
1314 OBJ(metar_tempf, INFO_METAR)
1316 OBJ(metar_windchill, INFO_METAR)
1318 OBJ(metar_dew_point, INFO_METAR)
1320 OBJ(metar_rh, INFO_METAR)
1322 OBJ(metar_windspeed, INFO_METAR)
1324 OBJ(metar_winddir, INFO_METAR)
1326 OBJ(metar_swinddir, INFO_METAR)
1327 END OBJ(metar_cloud, INFO_METAR)
1328 END OBJ(metar_u2d_time, INFO_METAR) END
1331 OBJ(mpd_artist, INFO_MPD)
1332 END OBJ(mpd_title, INFO_MPD)
1333 END OBJ(mpd_elapsed, INFO_MPD)
1334 END OBJ(mpd_length, INFO_MPD)
1335 END OBJ(mpd_percent, INFO_MPD)
1336 END OBJ(mpd_album, INFO_MPD) END OBJ(mpd_vol,
1337 INFO_MPD) END OBJ(mpd_bitrate,
1339 END OBJ(mpd_status, INFO_MPD) END OBJ(mpd_bar, INFO_MPD)
1340 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1345 ERR("unknown variable %s", s);
1346 obj->type = OBJ_text;
1347 snprintf(buf, 256, "${%s}", s);
1348 obj->data.s = strdup(buf);
1353 /* append_text() appends text to last text_object if it's text, if it isn't
1354 * it creates a new text_object */
1355 static void append_text(const char *s)
1357 struct text_object *obj;
1359 if (s == NULL || *s == '\0')
1362 obj = text_object_count ? &text_objects[text_object_count - 1] : 0;
1364 /* create a new text object? */
1365 if (!obj || obj->type != OBJ_text) {
1366 obj = new_text_object();
1367 obj->type = OBJ_text;
1368 obj->data.s = strdup(s);
1371 obj->data.s = (char *) realloc(obj->data.s,
1372 strlen(obj->data.s) +
1374 strcat(obj->data.s, s);
1378 static void extract_variable_text(const char *p)
1382 free_text_objects();
1397 /* variable is either $foo or ${foo} */
1401 while (*p && *p != '}')
1407 while (*p && (isalnum((int) *p)
1412 /* copy variable to buffer */
1413 len = (p - s > 255) ? 255 : (p - s);
1414 strncpy(buf, s, len);
1423 /* if variable wasn't found from environment, use some special */
1429 if (strchr(buf, ' ')) {
1430 arg = strchr(buf, ' ');
1433 while (isspace((int) *arg))
1439 /* lowercase variable name */
1446 construct_text_object(buf, arg);
1457 ERR("one or more $endif's are missing");
1460 double current_update_time, last_update_time;
1462 static void generate_text()
1465 struct information *cur = &info;
1472 current_update_time = get_time();
1478 n = TEXT_BUFFER_SIZE * 4 - 2;
1481 for (i = 0; i < text_object_count; i++) {
1482 struct text_object *obj = &text_objects[i];
1484 #define OBJ(a) break; case OBJ_##a:
1486 switch (obj->type) {
1489 ERR("not implemented obj type %d",
1493 /* does anyone have decimals in acpi temperature? */
1495 snprintf(p, n, "%d", (int)
1496 get_acpi_temperature(obj->
1500 snprintf(p, 5, "%d ", (int)
1501 get_acpi_temperature(obj->
1506 snprintf(p, n, "%s", get_freq());
1509 snprintf(p, n, "%s", get_adt746x_cpu());
1512 snprintf(p, n, "%s", get_adt746x_fan());
1515 snprintf(p, n, "%s", get_acpi_fan());
1517 OBJ(acpiacadapter) {
1518 snprintf(p, n, "%s",
1519 get_acpi_ac_adapter());
1522 get_battery_stuff(p, n, obj->data.s);
1525 human_readable(cur->buffers * 1024, p,
1529 human_readable(cur->cached * 1024, p, 255);
1533 snprintf(p, n, "%*d", pad_percents,
1534 (int) (cur->cpu_usage *
1537 snprintf(p, 4, "%*d ",
1539 (int) (cur->cpu_usage *
1543 new_bar(p, obj->data.pair.a,
1545 (int) (cur->cpu_usage * 255.0));
1548 new_graph(p, obj->a,
1549 obj->b, obj->c, obj->d,
1550 (unsigned int) (cur->cpu_usage *
1554 new_fg(p, obj->data.l);
1557 new_font(p, obj->data.s);
1561 snprintf(p, n, "%d",
1562 (int) (obj->data.net->
1566 snprintf(p, 6, "%d ",
1567 (int) (obj->data.net->
1573 snprintf(p, n, "%.1f",
1575 recv_speed / 1024.0);
1577 snprintf(p, 8, "%.1f ",
1579 recv_speed / 1024.0);
1581 OBJ(downspeedgraph) {
1582 if (obj->data.net->recv_speed == 0) // this is just to make the ugliness at start go away
1583 obj->data.net->recv_speed = 0.01;
1584 new_graph(p, obj->a, obj->b, obj->c, obj->d,
1585 (obj->data.net->recv_speed /
1592 i = obj->data.ifblock.pos - 2;
1602 snprintf(p, n, "%u.%u.%u.%u",
1603 obj->data.net->addr.
1605 obj->data.net->addr.
1607 obj->data.net->addr.
1609 obj->data.net->addr.
1614 snprintf(p, n, "%d",
1615 obj->data.net->linkstatus);
1620 FILE *fp = popen(obj->data.s, "r");
1621 int n2 = fread(p, 1, n, fp);
1625 if (n2 && p[n2 - 1] == '\n')
1636 FILE *fp = popen(obj->data.s, "r");
1637 int n2 = fread(p, 1, n, fp);
1641 if (n2 && p[n2 - 1] == '\n')
1650 if (sscanf(p, "%lf", &barnum) == 0) {
1651 ERR("reading execbar value failed (perhaps it's not the correct format?)");
1653 if (barnum > 100 || barnum < 0) {
1654 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
1656 barnum = barnum / 100.0;
1658 4, (int) (barnum * 255.0));
1664 FILE *fp = popen(obj->data.s, "r");
1665 int n2 = fread(p, 1, n, fp);
1669 if (n2 && p[n2 - 1] == '\n')
1678 if (sscanf(p, "%lf", &barnum) == 0) {
1679 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
1681 if (barnum > 100 || barnum < 0) {
1682 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
1685 25, obj->c, obj->d, (int) (barnum), 0);
1690 if (current_update_time -
1691 obj->data.execi.last_update <
1692 obj->data.execi.interval) {
1693 snprintf(p, n, "%s",
1694 obj->data.execi.buffer);
1696 char *p2 = obj->data.execi.buffer;
1698 popen(obj->data.execi.cmd,
1701 fread(p2, 1, TEXT_BUFFER_SIZE,
1706 if (n2 && p2[n2 - 1] == '\n')
1715 snprintf(p, n, "%s",
1716 obj->data.execi.buffer);
1718 obj->data.execi.last_update =
1719 current_update_time;
1724 if (obj->data.fs != NULL) {
1725 if (obj->data.fs->size == 0)
1744 if (obj->data.fs != NULL)
1745 human_readable(obj->data.fs->avail,
1749 if (obj->data.fs != NULL) {
1750 if (obj->data.fs->size)
1751 snprintf(p, n, "%*d",
1760 snprintf(p, n, "0");
1764 if (obj->data.fs != NULL)
1765 human_readable(obj->data.fs->size,
1769 if (obj->data.fs != NULL)
1770 human_readable(obj->data.fs->size -
1771 obj->data.fs->avail,
1775 if (obj->data.fs != NULL) {
1776 if (obj->data.fs->size == 0)
1794 if (obj->data.fs != NULL) {
1795 if (obj->data.fs->size)
1796 snprintf(p, 4, "%d",
1806 snprintf(p, n, "0");
1810 float *v = info.loadavg;
1812 if (obj->data.loadavg[2])
1813 snprintf(p, n, "%.2f %.2f %.2f",
1814 v[obj->data.loadavg[0] -
1816 v[obj->data.loadavg[1] -
1818 v[obj->data.loadavg[2] -
1820 else if (obj->data.loadavg[1])
1821 snprintf(p, n, "%.2f %.2f",
1822 v[obj->data.loadavg[0] -
1824 v[obj->data.loadavg[1] -
1826 else if (obj->data.loadavg[0])
1827 snprintf(p, n, "%.2f",
1828 v[obj->data.loadavg[0] -
1832 new_hr(p, obj->data.i);
1835 new_offset(p, obj->data.i);
1840 r = get_i2c_info(&obj->data.i2c.fd,
1842 obj->data.i2c.devtype,
1843 obj->data.i2c.type);
1845 if (r >= 100.0 || r == 0)
1846 snprintf(p, n, "%d", (int) r);
1848 snprintf(p, n, "%.1f", r);
1851 new_alignr(p, obj->data.i);
1854 new_alignc(p, obj->data.i);
1858 if ((obj->data.ifblock.s)
1859 && (stat(obj->data.ifblock.s, &tmp) ==
1861 i = obj->data.ifblock.pos - 2;
1867 if ((obj->data.ifblock.s)
1868 && (!check_mount(obj->data.ifblock.s))) {
1869 i = obj->data.ifblock.pos - 2;
1875 if ((obj->data.ifblock.s)
1876 && system(obj->data.ifblock.s)) {
1877 i = obj->data.ifblock.pos - 2;
1883 snprintf(p, n, "%s", cur->uname_s.release);
1886 snprintf(p, n, "%s", cur->uname_s.machine);
1891 human_readable(cur->mem * 1024, p, 6);
1894 human_readable(cur->memmax * 1024, p, 255);
1899 snprintf(p, n, "%*d",
1904 snprintf(p, 4, "%*d ",
1911 new_bar(p, obj->data.pair.a,
1913 cur->memmax ? (cur->mem * 255) /
1918 new_graph(p, obj->a,
1919 obj->b, obj->c, obj->d,
1920 cur->memmax ? (cur->mem) /
1921 (cur->memmax) : 0, 0);
1925 snprintf(p, n, "%d",
1926 mixer_get_avg(obj->data.l));
1929 snprintf(p, n, "%d",
1930 mixer_get_left(obj->data.l));
1933 snprintf(p, n, "%d",
1934 mixer_get_right(obj->data.l));
1937 new_bar(p, obj->data.mixerbar.w,
1938 obj->data.mixerbar.h,
1939 mixer_get_avg(obj->data.mixerbar.
1943 new_bar(p, obj->data.mixerbar.w,
1944 obj->data.mixerbar.h,
1945 mixer_get_left(obj->data.mixerbar.
1949 new_bar(p, obj->data.mixerbar.w,
1950 obj->data.mixerbar.h,
1951 mixer_get_right(obj->data.mixerbar.
1957 snprintf(p, n, "%d", cur->mail_count);
1960 snprintf(p, n, "%d", cur->new_mail_count);
1963 OBJ(ml_upload_counter) {
1964 snprintf(p, n, "%lld",
1965 mlinfo.upload_counter / 1048576);
1967 OBJ(ml_download_counter) {
1968 snprintf(p, n, "%lld",
1969 mlinfo.download_counter /
1972 OBJ(ml_nshared_files) {
1973 snprintf(p, n, "%i", mlinfo.nshared_files);
1975 OBJ(ml_shared_counter) {
1976 snprintf(p, n, "%lld",
1977 mlinfo.shared_counter / 1048576);
1979 OBJ(ml_tcp_upload_rate) {
1980 snprintf(p, n, "%.2f",
1981 (float) mlinfo.tcp_upload_rate /
1984 OBJ(ml_tcp_download_rate) {
1985 snprintf(p, n, "%.2f",
1986 (float) mlinfo.tcp_download_rate /
1989 OBJ(ml_udp_upload_rate) {
1990 snprintf(p, n, "%.2f",
1991 (float) mlinfo.udp_upload_rate /
1994 OBJ(ml_udp_download_rate) {
1995 snprintf(p, n, "%.2f",
1996 (float) mlinfo.udp_download_rate /
1999 OBJ(ml_ndownloaded_files) {
2000 snprintf(p, n, "%i",
2001 mlinfo.ndownloaded_files);
2003 OBJ(ml_ndownloading_files) {
2004 snprintf(p, n, "%i",
2005 mlinfo.ndownloading_files);
2010 snprintf(p, n, "%s",
2011 cur->uname_s.nodename);
2014 new_outline(p, obj->data.l);
2018 snprintf(p, n, "%d", cur->procs);
2020 snprintf(p, 5, "%d ",
2023 OBJ(running_processes) {
2025 snprintf(p, n, "%d",
2028 snprintf(p, 3, "%d ",
2032 snprintf(p, n, "%s", obj->data.s);
2035 new_bg(p, obj->data.l);
2038 new_stippled_hr(p, obj->data.pair.a,
2042 human_readable(cur->swap * 1024, p, 255);
2045 human_readable(cur->swapmax * 1024, p,
2049 if (cur->swapmax == 0) {
2050 strncpy(p, "No swap", 255);
2053 snprintf(p, 255, "%*u",
2059 snprintf(p, 4, "%*u ",
2067 new_bar(p, obj->data.pair.a,
2069 cur->swapmax ? (cur->swap * 255) /
2070 (cur->swapmax) : 0);
2073 snprintf(p, n, "%s", cur->uname_s.sysname);
2076 time_t t = time(NULL);
2077 struct tm *tm = localtime(&t);
2078 setlocale(LC_TIME, "");
2079 strftime(p, n, obj->data.s, tm);
2082 time_t t = time(NULL);
2083 struct tm *tm = gmtime(&t);
2084 strftime(p, n, obj->data.s, tm);
2087 human_readable(obj->data.net->recv, p,
2091 human_readable(obj->data.net->trans, p,
2095 snprintf(p, n, "%d", total_updates);
2099 snprintf(p, n, "%d",
2100 (int) (obj->data.net->
2104 snprintf(p, 5, "%d ",
2105 (int) (obj->data.net->
2111 snprintf(p, n, "%.1f",
2113 trans_speed / 1024.0);
2115 snprintf(p, 8, "%.1f ",
2117 trans_speed / 1024.0);
2120 if (obj->data.net->trans_speed == 0) // this is just to make the ugliness at start go away
2121 obj->data.net->trans_speed = 0.01;
2122 new_graph(p, obj->a, obj->b, obj->c, obj->d,
2123 (obj->data.net->trans_speed /
2127 format_seconds_short(p, n,
2131 format_seconds(p, n, (int) cur->uptime);
2136 snprintf(p, n, "%.2f",
2137 cur->seti_prog * 100.0f);
2140 new_bar(p, obj->data.pair.a,
2142 (int) (cur->seti_prog * 255.0f));
2145 snprintf(p, n, "%.0f", cur->seti_credit);
2151 snprintf(p, n, "%s", cur->mpd.title);
2154 snprintf(p, n, "%s", cur->mpd.artist);
2157 snprintf(p, n, "%s", cur->mpd.album);
2160 snprintf(p, n, "%i", cur->mpd.volume);
2163 snprintf(p, n, "%i", cur->mpd.bitrate);
2166 snprintf(p, n, "%s", cur->mpd.status);
2169 int days = 0, hours = 0, minutes =
2171 int tmp = cur->mpd.elapsed;
2172 while (tmp >= 86400) {
2176 while (tmp >= 3600) {
2186 snprintf(p, n, "%i days %i:%i:%2i",
2187 days, hours, minutes,
2190 snprintf(p, n, "%i:%i:%02i", hours,
2193 snprintf(p, n, "%i:%02i", minutes,
2197 int days = 0, hours = 0, minutes =
2199 int tmp = cur->mpd.length;
2200 while (tmp >= 86400) {
2204 while (tmp >= 3600) {
2215 "%i days %i:%i:%02i",
2216 days, hours, minutes,
2219 snprintf(p, n, "%i:%i:%02i", hours,
2222 snprintf(p, n, "%i:%02i", minutes,
2226 snprintf(p, n, "%2.0f",
2227 cur->mpd.progress * 100);
2230 new_bar(p, obj->data.pair.a,
2232 (int) (cur->mpd.progress *
2237 if (obj->data.top.type == TOP_NAME
2238 && obj->data.top.num >= 0
2239 && obj->data.top.num < 10) {
2240 // if we limit the buffer and add a bunch of space after, it stops the thing from
2241 // moving other shit around, which is really fucking annoying
2244 cur->cpu[obj->data.top.
2246 } else if (obj->data.top.type == TOP_CPU
2247 && obj->data.top.num >= 0
2248 && obj->data.top.num < 10) {
2249 snprintf(p, 7, "%3.2f ",
2250 cur->cpu[obj->data.top.
2252 } else if (obj->data.top.type == TOP_PID
2253 && obj->data.top.num >= 0
2254 && obj->data.top.num < 10) {
2255 snprintf(p, 8, "%i ",
2256 cur->cpu[obj->data.top.
2258 } else if (obj->data.top.type == TOP_MEM
2259 && obj->data.top.num >= 0
2260 && obj->data.top.num < 10) {
2261 snprintf(p, 7, "%3.2f ",
2262 cur->cpu[obj->data.top.
2267 if (obj->data.top.type == TOP_NAME
2268 && obj->data.top.num >= 0
2269 && obj->data.top.num < 10) {
2270 // if we limit the buffer and add a bunch of space after, it stops the thing from
2271 // moving other shit around, which is really fucking annoying
2274 cur->memu[obj->data.top.
2276 } else if (obj->data.top.type == TOP_CPU
2277 && obj->data.top.num >= 0
2278 && obj->data.top.num < 10) {
2279 snprintf(p, 7, "%3.2f ",
2280 cur->memu[obj->data.top.
2282 } else if (obj->data.top.type == TOP_PID
2283 && obj->data.top.num >= 0
2284 && obj->data.top.num < 10) {
2285 snprintf(p, 8, "%i ",
2286 cur->memu[obj->data.top.
2288 } else if (obj->data.top.type == TOP_MEM
2289 && obj->data.top.num >= 0
2290 && obj->data.top.num < 10) {
2291 snprintf(p, 7, "%3.2f ",
2292 cur->memu[obj->data.top.
2300 * I'm tired of everything being packed in
2307 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
2308 snprintf(p, n, "%s", obj->data.tail.buffer);
2310 obj->data.tail.last_update = current_update_time;
2313 tailstring *head = NULL;
2314 tailstring *headtmp = NULL;
2315 fp = fopen(obj->data.tail.logfile, "rt");
2317 ERR("tail logfile failed to open");
2319 obj->data.tail.readlines = 0;
2321 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*4, fp) != NULL) {
2322 addtail(&head, obj->data.tail.buffer);
2323 obj->data.tail.readlines++;
2328 if (obj->data.tail.readlines > 0) {
2329 for (i = 0;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
2330 addtail(&headtmp, head->data);
2333 strcpy(obj->data.tail.buffer, headtmp->data);
2334 headtmp = headtmp->next;
2335 for (i = 1;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
2337 strncat(obj->data.tail.buffer, headtmp->data, TEXT_BUFFER_SIZE * 4 / obj->data.tail.wantedlines);
2338 headtmp = headtmp->next;
2342 /* get rid of any ugly newlines at the end */
2343 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
2344 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
2346 snprintf(p, n, "%s", obj->data.tail.buffer);
2351 strcpy(obj->data.tail.buffer, "Logfile Empty");
2352 snprintf(p, n, "Logfile Empty");
2361 // Hmm, it's expensive to calculate this shit every time FIXME
2362 OBJ(metar_ob_time) {
2363 if (data.ob_hour != INT_MAX
2364 && data.ob_minute != INT_MAX
2366 format_seconds(p, n,
2372 format_seconds(p, n, 0);
2375 if (data.temp != INT_MAX && metar_worked)
2376 snprintf(p, n, "%i", data.temp);
2378 snprintf(p, n, "-");
2381 if (data.temp != INT_MAX && metar_worked)
2382 snprintf(p, n, "%3.1f",
2384 40) * 9.0 / 5 - 40);
2386 snprintf(p, n, "-");
2388 OBJ(metar_windchill) {
2389 if (data.temp != INT_MAX
2390 && data.winData.windSpeed != INT_MAX
2392 snprintf(p, n, "%i",
2393 calculateWindChill(data.
2399 snprintf(p, n, "-");
2401 OBJ(metar_dew_point) {
2402 if (data.dew_pt_temp != INT_MAX
2404 snprintf(p, n, "%i",
2407 snprintf(p, n, "-");
2410 if (data.temp != INT_MAX
2411 && data.dew_pt_temp != INT_MAX
2413 snprintf(p, n, "%i",
2414 calculateRelativeHumidity
2418 snprintf(p, n, "-");
2421 OBJ(metar_windspeed) {
2422 if (data.winData.windSpeed != INT_MAX
2424 snprintf(p, n, "%i",
2425 knTokph(data.winData.
2428 snprintf(p, n, "-");
2430 OBJ(metar_winddir) {
2431 if (data.winData.windDir != INT_MAX
2433 snprintf(p, n, "%s",
2434 calculateWindDirectionString
2435 (data.winData.windDir));
2437 snprintf(p, n, "-");
2439 OBJ(metar_swinddir) {
2440 if (data.winData.windDir != INT_MAX
2442 snprintf(p, n, "%s",
2443 calculateShortWindDirectionString
2444 (data.winData.windDir));
2446 snprintf(p, n, "-");
2450 if (data.cldTypHgt[0].cloud_type[0] != '\0'
2453 (&data.cldTypHgt[0].
2454 cloud_type[0], "SKC") == 0)
2458 (&data.cldTypHgt[0].
2464 (&data.cldTypHgt[0].
2470 (&data.cldTypHgt[0].
2474 "Scattered clouds");
2476 (&data.cldTypHgt[0].
2482 (&data.cldTypHgt[0].
2485 snprintf(p, n, "Overcast");
2490 snprintf(p, n, "Checking...");
2492 OBJ(metar_u2d_time) {
2493 format_seconds(p, n,
2494 (int) last_metar_update %
2495 (3600 * 24) + 3600);
2503 unsigned int a = strlen(p);
2509 if (stuff_in_upper_case) {
2519 last_update_time = current_update_time;
2525 static void set_font()
2529 if (window.xftdraw != NULL)
2530 XftDrawDestroy(window.xftdraw);
2531 window.xftdraw = XftDrawCreate(display, window.drawable,
2532 DefaultVisual(display,
2534 DefaultColormap(display,
2540 XSetFont(display, window.gc, fonts[selected_font].font->fid);
2549 static int text_start_x, text_start_y; /* text start position in window */
2550 static int text_width, text_height;
2552 static inline int get_string_width(const char *s)
2554 return *s ? calc_text_width(s, strlen(s)) : 0;
2559 static void text_size_updater(char *s)
2563 int h = font_height();
2564 /* get string widths and skip specials */
2567 if (*p == SPECIAL_CHAR) {
2569 w += get_string_width(s);
2572 if (specials[special_index].type == BAR
2573 || specials[special_index].type == GRAPH) {
2574 w += specials[special_index].width;
2575 if (specials[special_index].height > h) {
2576 h = specials[special_index].height;
2581 else if (specials[special_index].type == OFFSET) {
2582 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
2585 else if (specials[special_index].type == FONT) {
2586 fontchange = specials[special_index].font_added;
2587 selected_font = specials[special_index].font_added;
2597 w += get_string_width(s);
2607 static void update_text_area()
2611 /* update text size if it isn't fixed */
2616 text_width = minimum_width;
2619 for_each_line(text_buffer, text_size_updater);
2621 if (text_height < minimum_height)
2622 text_height = minimum_height;
2625 /* get text position on workarea */
2626 switch (text_alignment) {
2633 x = workarea[2] - text_width - gap_x;
2640 y = workarea[3] - text_height - gap_y;
2644 x = workarea[2] - text_width - gap_x;
2645 y = workarea[3] - text_height - gap_y;
2653 text_start_x = border_margin + 1;
2654 text_start_y = border_margin + 1;
2655 window.x = x - border_margin - 1;
2656 window.y = y - border_margin - 1;
2660 /* If window size doesn't match to workarea's size, then window
2661 * probably includes panels (gnome).
2662 * Blah, doesn't work on KDE. */
2663 if (workarea[2] != window.width
2664 || workarea[3] != window.height) {
2678 static int cur_x, cur_y; /* current x and y for drawing */
2679 static int draw_mode; /* FG, BG or OUTLINE */
2680 static long current_color;
2682 static inline void set_foreground_color(long c)
2685 XSetForeground(display, window.gc, c);
2688 static void draw_string(const char *s)
2692 int i, i2, pos, width_of_s;
2694 width_of_s = get_string_width(s);
2695 if (out_to_console) {
2698 strcpy(tmpstring1, s);
2702 snprintf(space, 2, " ");
2703 max = ((text_width - width_of_s) / get_string_width(space));
2705 * This code looks for tabs in the text and coverts them to spaces.
2706 * The trick is getting the correct number of spaces,
2707 * and not going over the window's size without forcing
2708 * the window larger.
2710 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
2711 if (tmpstring1[i] == '\t') // 9 is ascii tab
2715 i2 < (8 - (1 + pos) % 8) && added <= max;
2717 tmpstring2[pos + i2] = ' ';
2722 if (tmpstring1[i] != 9) {
2723 tmpstring2[pos] = tmpstring1[i];
2733 c.pixel = current_color;
2734 XQueryColor(display, DefaultColormap(display, screen), &c);
2737 c2.color.red = c.red;
2738 c2.color.green = c.green;
2739 c2.color.blue = c.blue;
2740 c2.color.alpha = fonts[selected_font].font_alpha;
2742 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
2743 cur_x, cur_y, (XftChar8 *) s,
2746 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
2747 cur_x, cur_y, (XftChar8 *) s,
2753 XDrawString(display, window.drawable, window.gc,
2754 cur_x, cur_y, s, strlen(s));
2756 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
2757 cur_x += width_of_s;
2762 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 */
2764 int red1, green1, blue1; // first colour
2765 int red2, green2, blue2; // second colour
2766 int red3 = 0, green3 = 0, blue3 = 0; // difference
2767 red1 = (first_colour & 0xff0000) >> 16;
2768 green1 = (first_colour & 0xff00) >> 8;
2769 blue1 = first_colour & 0xff;
2770 red2 = (last_colour & 0xff0000) >> 16;
2771 green2 = (last_colour & 0xff00) >> 8;
2772 blue2 = last_colour & 0xff;
2779 if (green1 > green2) {
2782 if (green1 < green2) {
2785 if (blue1 > blue2) {
2788 if (blue1 < blue2) {
2806 if (green1 > 0xff) {
2812 tmp_color = (red1 << 16) | (green1 << 8) | blue1;
2816 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
2817 int red1, green1, blue1; // first colour
2818 int red2, green2, blue2; // second colour
2819 int red3 = 0, green3 = 0, blue3 = 0; // difference
2820 red1 = (first_colour & 0xff0000) >> 16;
2821 green1 = (first_colour & 0xff00) >> 8;
2822 blue1 = first_colour & 0xff;
2823 red2 = (last_colour & 0xff0000) >> 16;
2824 green2 = (last_colour & 0xff00) >> 8;
2825 blue2 = last_colour & 0xff;
2826 red3 = abs(red1 - red2);
2827 green3 = abs(green1 - green2);
2828 blue3 = abs(blue1 - blue2);
2838 static void draw_line(char *s)
2842 cur_x = text_start_x;
2843 cur_y += font_ascent();
2845 short font_h = font_height();
2847 /* find specials and draw stuff */
2850 if (*p == SPECIAL_CHAR) {
2853 /* draw string before special */
2860 switch (specials[special_index].type) {
2861 case HORIZONTAL_LINE:
2864 specials[special_index].height;
2865 int mid = font_ascent() / 2;
2866 w = text_start_x + text_width -
2869 XSetLineAttributes(display,
2874 XDrawLine(display, window.drawable,
2885 specials[special_index].height;
2887 specials[special_index].arg;
2888 int mid = font_ascent() / 2;
2889 char ss[2] = { s, s };
2890 w = text_start_x + text_width -
2893 XSetLineAttributes(display,
2898 XSetDashes(display, window.gc, 0,
2900 XDrawLine(display, window.drawable,
2911 specials[special_index].height;
2913 specials[special_index].arg;
2915 cur_y - (font_ascent() +
2917 w = specials[special_index].width;
2920 text_width - cur_x - 1;
2924 XSetLineAttributes(display,
2930 XDrawRectangle(display,
2934 XFillRectangle(display,
2938 w * bar_usage / 255,
2940 if (specials[special_index].
2942 && specials[special_index].
2946 [special_index].height;
2954 specials[special_index].height;
2956 cur_y - (font_ascent() +
2958 w = specials[special_index].width;
2961 text_width - cur_x - 1;
2964 XSetLineAttributes(display,
2969 XDrawRectangle(display,
2973 XSetLineAttributes(display,
2980 int gradient_size = 0;
2981 float gradient_factor = 0;
2982 float gradient_update = 0;
2983 unsigned int tmpcolour = current_color;
2984 if (specials[special_index].first_colour != 0 && specials[special_index].last_colour != 0) {
2985 tmpcolour = specials[special_index].first_colour;
2986 gradient_size = gradient_max(specials[special_index].first_colour, specials[special_index].last_colour);
2987 gradient_factor = (float)gradient_size / (w - 3);
2989 for (i = 0; i < w - 3; i++) {
2990 if (specials[special_index].first_colour != 0 && specials[special_index].last_colour != 0) {
2991 XSetForeground(display, window.gc, tmpcolour);
2992 gradient_update += gradient_factor;
2993 while (gradient_update > 0) {
2994 tmpcolour = do_gradient(tmpcolour, specials[special_index].last_colour);
3002 graph_width)) > j) {
3005 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 */
3007 if (specials[special_index].
3009 && specials[special_index].
3013 [special_index].height;
3016 if (draw_mode == BG) {
3017 set_foreground_color(default_bg_color);
3019 else if (draw_mode == OUTLINE) {
3020 set_foreground_color(default_out_color);
3022 set_foreground_color(default_fg_color);
3028 cur_y -= font_ascent();
3029 selected_font = specials[special_index].font_added;
3030 cur_y += font_ascent();
3036 if (draw_mode == FG)
3037 set_foreground_color(specials
3043 if (draw_mode == BG)
3044 set_foreground_color(specials
3050 if (draw_mode == OUTLINE)
3051 set_foreground_color(specials
3058 w = text_start_x + specials[special_index].arg;
3065 text_start_x + text_width -
3067 get_string_width(p);
3069 specials[special_index].arg)
3072 [special_index].arg;
3079 text_start_x + text_width -
3081 get_string_width(p) / 2 -
3084 specials[special_index].arg)
3087 [special_index].arg;
3100 if (cur_y_add > 0) {
3102 cur_y -= font_descent();
3114 font_name = tmpfont;
3120 cur_y += font_descent();
3123 static void draw_text()
3125 cur_y = text_start_y;
3128 if (draw_borders && border_width > 0) {
3129 unsigned int b = (border_width + 1) / 2;
3131 if (stippled_borders) {
3133 { stippled_borders, stippled_borders };
3134 XSetLineAttributes(display, window.gc,
3135 border_width, LineOnOffDash,
3136 CapButt, JoinMiter);
3137 XSetDashes(display, window.gc, 0, ss, 2);
3139 XSetLineAttributes(display, window.gc,
3140 border_width, LineSolid,
3141 CapButt, JoinMiter);
3144 XDrawRectangle(display, window.drawable, window.gc,
3145 text_start_x - border_margin + b,
3146 text_start_y - border_margin + b,
3147 text_width + border_margin * 2 - 1 - b * 2,
3148 text_height + border_margin * 2 - 1 -
3154 for_each_line(text_buffer, draw_line);
3157 static void draw_stuff()
3159 if (draw_shades && !draw_outline) {
3162 set_foreground_color(default_bg_color);
3171 for (i = -1; i < 2; i++)
3172 for (j = -1; j < 2; j++) {
3173 if (i == 0 && j == 0)
3177 set_foreground_color(default_out_color);
3178 draw_mode = OUTLINE;
3185 set_foreground_color(default_fg_color);
3192 swap.swap_window = window.window;
3193 swap.swap_action = XdbeBackground;
3194 XdbeSwapBuffers(display, &swap, 1);
3197 /*#ifdef METAR wtf is this for exactly? aside from trying to cause segfaults?
3198 if (metar_station != NULL) {
3199 free(metar_station);
3200 metar_station = NULL;
3202 if (metar_server != NULL) {
3204 metar_server = NULL;
3206 if (metar_path != NULL) {
3214 static void clear_text(int exposures)
3218 return; /* The swap action is XdbeBackground, which clears */
3220 /* there is some extra space for borders and outlines */
3221 XClearArea(display, window.drawable,
3222 text_start_x - border_margin - 1,
3223 text_start_y - border_margin - 1,
3224 text_width + border_margin * 2 + 2,
3225 text_height + border_margin * 2 + 2,
3226 exposures ? True : 0);
3229 static int need_to_update;
3231 /* update_text() generates new text and clears old text area */
3232 static void update_text()
3239 static void main_loop()
3241 Region region = XCreateRegion();
3243 while (total_run_times == 0 || info.looped < total_run_times - 1) {
3247 /* wait for X event or timeout */
3249 if (!XPending(display)) {
3254 update_interval - (get_time() -
3260 tv.tv_sec = (long) t;
3261 tv.tv_usec = (long) (t * 1000000) % 1000000;
3264 FD_SET(ConnectionNumber(display), &fdsr);
3266 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
3270 ERR("can't select(): %s",
3279 if (need_to_update) {
3281 int wx = window.x, wy = window.y;
3290 /* resize window if it isn't right size */
3292 (text_width + border_margin * 2 !=
3294 || text_height + border_margin * 2 !=
3298 border_margin * 2 + 1;
3301 border_margin * 2 + 1;
3302 XResizeWindow(display,
3308 /* move window if it isn't in right position */
3311 || window.y != wy)) {
3312 XMoveWindow(display, window.window,
3313 window.x, window.y);
3323 r.x = text_start_x - border_margin;
3324 r.y = text_start_y - border_margin;
3325 r.width = text_width + border_margin * 2;
3326 r.height = text_height + border_margin * 2;
3327 XUnionRectWithRegion(&r, region, region);
3332 /* handle X events */
3334 while (XPending(display)) {
3336 XNextEvent(display, &ev);
3344 r.width = ev.xexpose.width;
3345 r.height = ev.xexpose.height;
3346 XUnionRectWithRegion(&r, region,
3352 case ReparentNotify:
3353 /* set background to ParentRelative for all parents */
3355 set_transparent_background(window.
3359 case ConfigureNotify:
3361 /* if window size isn't what expected, set fixed size */
3362 if (ev.xconfigure.width !=
3364 || ev.xconfigure.height !=
3366 if (window.width != 0
3367 && window.height != 0)
3370 /* clear old stuff before screwing up size and pos */
3376 if (XGetWindowAttributes(display, window.window, &attrs)) {
3391 border_margin * 2 - 1;
3394 border_margin * 2 - 1;
3397 /* if position isn't what expected, set fixed pos, total_updates
3398 * avoids setting fixed_pos when window is set to weird locations
3400 if (total_updates >= 2
3402 && (window.x != ev.xconfigure.x
3405 && (ev.xconfigure.x != 0
3406 || ev.xconfigure.y != 0)) {
3418 /* XDBE doesn't seem to provide a way to clear the back buffer without
3419 * interfering with the front buffer, other than passing XdbeBackground
3420 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
3421 * redraw the text even if it wasn't part of the exposed area. OTOH,
3422 * if we're not going to call draw_stuff at all, then no swap happens
3423 * and we can safely do nothing.
3426 if (!XEmptyRegion(region)) {
3430 r.x = text_start_x - border_margin;
3431 r.y = text_start_y - border_margin;
3432 r.width = text_width + border_margin * 2;
3433 r.height = text_height + border_margin * 2;
3434 XUnionRectWithRegion(&r, region, region);
3437 XSetRegion(display, window.gc, region);
3440 XftDrawSetClip(window.xftdraw, region);
3443 XDestroyRegion(region);
3444 region = XCreateRegion();
3449 static void load_config_file(const char *);
3451 /* signal handler that reloads config file */
3452 static void reload_handler(int a)
3454 fprintf(stderr, "Conky: received signal %d, reloading config\n",
3457 if (current_config) {
3459 load_config_file(current_config);
3462 extract_variable_text(text);
3469 static void clean_up()
3473 XdbeDeallocateBackBufferName(display, window.back_buffer);
3477 XDestroyWindow(display, window.window);
3485 XFreeGC(display, window.gc);
3487 /* it is really pointless to free() memory at the end of program but ak|ra
3488 * wants me to do this */
3490 free_text_objects();
3492 if (text != original_text)
3495 free(current_config);
3496 free(current_mail_spool);
3502 static void term_handler(int a)
3504 a = a; /* to get rid of warning */
3509 static int string_to_bool(const char *s)
3513 if (strcasecmp(s, "yes") == 0)
3515 if (strcasecmp(s, "true") == 0)
3517 if (strcasecmp(s, "1") == 0)
3522 static enum alignment string_to_alignment(const char *s)
3524 if (strcasecmp(s, "top_left") == 0)
3526 else if (strcasecmp(s, "top_right") == 0)
3528 else if (strcasecmp(s, "bottom_left") == 0)
3530 else if (strcasecmp(s, "bottom_right") == 0)
3531 return BOTTOM_RIGHT;
3532 else if (strcasecmp(s, "tl") == 0)
3534 else if (strcasecmp(s, "tr") == 0)
3536 else if (strcasecmp(s, "bl") == 0)
3538 else if (strcasecmp(s, "br") == 0)
3539 return BOTTOM_RIGHT;
3544 static void set_default_configurations(void)
3546 text_alignment = BOTTOM_LEFT;
3547 fork_to_background = 0;
3550 total_run_times = 0;
3551 info.cpu_avg_samples = 2;
3552 info.net_avg_samples = 2;
3557 strcpy(info.mpd.host, "localhost");
3558 info.mpd.port = 6600;
3559 info.mpd.status = "Checking status...";
3563 default_fg_color = WhitePixel(display, screen);
3564 default_bg_color = BlackPixel(display, screen);
3565 default_out_color = BlackPixel(display, screen);
3571 set_first_font("courier-12");
3573 set_first_font("6x10");
3578 free(current_mail_spool);
3581 variable_substitute(MAIL_FILE, buf, 256);
3583 current_mail_spool = strdup(buf);
3592 stippled_borders = 0;
3593 update_interval = 10.0;
3594 stuff_in_upper_case = 0;
3596 mlconfig.mldonkey_hostname = "127.0.0.1";
3597 mlconfig.mldonkey_port = 4001;
3598 mlconfig.mldonkey_login = NULL;
3599 mlconfig.mldonkey_password = NULL;
3602 metar_station = NULL;
3603 metar_server = NULL;
3605 last_metar_update = 0;
3609 static void load_config_file(const char *f)
3611 #define CONF_ERR ERR("%s: %d: config file error", f, line)
3615 set_default_configurations();
3617 fp = open_file(f, 0);
3622 char buf[256], *p, *p2, *name, *value;
3624 if (fgets(buf, 256, fp) == NULL)
3629 /* break at comment */
3630 p2 = strchr(p, '#');
3635 while (*p && isspace((int) *p))
3638 continue; /* empty line */
3644 while (*p2 && !isspace((int) *p2))
3647 *p2 = '\0'; /* break at name's end */
3654 while (*p && isspace((int) *p))
3659 p2 = value + strlen(value);
3660 while (isspace((int) *(p2 - 1)))
3666 #define CONF2(a) if (strcasecmp(name, a) == 0)
3667 #define CONF(a) else CONF2(a)
3668 #define CONF3(a,b) \
3669 else if (strcasecmp(name, a) == 0 || strcasecmp(name, a) == 0)
3672 CONF2("alignment") {
3674 int a = string_to_alignment(value);
3682 CONF("background") {
3683 fork_to_background = string_to_bool(value);
3685 CONF("border_margin") {
3687 border_margin = strtol(value, 0, 0);
3691 CONF("border_width") {
3693 border_width = strtol(value, 0, 0);
3697 CONF("default_color") {
3699 default_fg_color = get_x11_color(value);
3703 CONF3("default_shade_color", "default_shadecolor") {
3705 default_bg_color = get_x11_color(value);
3709 CONF3("default_outline_color", "default_outlinecolor") {
3711 default_out_color = get_x11_color(value);
3718 strcpy(info.mpd.host, value);
3724 info.mpd.port = strtol(value, 0, 0);
3725 if (info.mpd.port < 1
3726 || info.mpd.port > 0xffff)
3731 CONF("cpu_avg_samples") {
3733 cpu_avg_samples = strtol(value, 0, 0);
3734 if (cpu_avg_samples < 1
3735 || cpu_avg_samples > 14)
3744 CONF("net_avg_samples") {
3746 net_avg_samples = strtol(value, 0, 0);
3747 if (net_avg_samples < 1
3748 || net_avg_samples > 14)
3763 CONF("override_utf8_locale") {
3764 utf8_mode = string_to_bool(value);
3767 CONF("double_buffer") {
3768 use_xdbe = string_to_bool(value);
3771 CONF("draw_borders") {
3772 draw_borders = string_to_bool(value);
3774 CONF("draw_shades") {
3775 draw_shades = string_to_bool(value);
3777 CONF("draw_outline") {
3778 draw_outline = string_to_bool(value);
3780 CONF("out_to_console") {
3781 out_to_console = string_to_bool(value);
3783 CONF("use_spacer") {
3784 use_spacer = string_to_bool(value);
3788 use_xft = string_to_bool(value);
3791 /* font silently ignored when Xft */
3794 if (value && font_count >= 0)
3795 fonts[0].font_alpha = atof(value)
3803 if (string_to_bool(value))
3804 ERR("Xft not enabled");
3807 /* xftfont silently ignored when no Xft */
3810 /* xftalpha is silently ignored when no Xft */
3815 set_first_font(value);
3822 gap_x = atoi(value);
3828 gap_y = atoi(value);
3832 CONF("mail_spool") {
3835 variable_substitute(value, buf, 256);
3839 if (current_mail_spool)
3840 free(current_mail_spool);
3841 current_mail_spool = strdup(buf);
3846 CONF("minimum_size") {
3849 (value, "%d %d", &minimum_width,
3850 &minimum_height) != 2)
3853 &minimum_width) != 1)
3858 CONF("no_buffers") {
3859 no_buffers = string_to_bool(value);
3862 CONF("mldonkey_hostname") {
3864 mlconfig.mldonkey_hostname = strdup(value);
3868 CONF("mldonkey_port") {
3870 mlconfig.mldonkey_port = atoi(value);
3874 CONF("mldonkey_login") {
3876 mlconfig.mldonkey_login = strdup(value);
3880 CONF("mldonkey_password") {
3882 mlconfig.mldonkey_password = strdup(value);
3888 CONF("own_window") {
3889 own_window = string_to_bool(value);
3892 CONF("pad_percents") {
3893 pad_percents = atoi(value);
3895 CONF("stippled_borders") {
3897 stippled_borders = strtol(value, 0, 0);
3899 stippled_borders = 4;
3902 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
3905 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
3907 CONF("update_interval") {
3909 update_interval = strtod(value, 0);
3913 CONF("total_run_times") {
3915 total_run_times = strtod(value, 0);
3920 stuff_in_upper_case = string_to_bool(value);
3925 malloc(strlen(value)
3927 strcpy(seti_dir, value);
3931 CONF("metar_station") {
3932 metar_station = (char *)
3933 malloc(strlen(value)
3935 strcpy(metar_station, value);
3936 strcat(metar_station, ".TXT");
3938 CONF("metar_server") {
3939 metar_server = (char *)
3940 malloc(strlen(value)
3942 strcpy(metar_server, value);
3944 CONF("metar_path") {
3945 metar_path = (char *)
3946 malloc(strlen(value)
3948 strcpy(metar_path, value);
3953 if (text != original_text)
3963 int l = strlen(text);
3964 if (fgets(buf, 256, fp) == NULL)
3967 realloc(text, l + strlen(buf)
3971 if (strlen(text) > 1024 * 8)
3978 ERR("%s: %d: no such configuration: '%s'", f, line, name);
3988 /* : means that character before that takes an argument */
3992 *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
4002 int main(int argc, char **argv)
4004 /* handle command line parameters that don't change configs */
4007 if (((s = getenv("LC_ALL")) && *s)
4008 || ((s = getenv("LC_CTYPE")) && *s) || ((s = getenv("LANG"))
4010 if (strstr(s, "UTF-8") || strstr(s, "utf-8")
4011 || strstr(s, "UTF8")
4012 || strstr(s, "utf8"))
4015 if (!setlocale(LC_CTYPE, "")) {
4018 "Can't set the specified locale! "
4019 "Check LANG, LC_CTYPE, LC_ALL.\n");
4023 int c = getopt(argc,
4033 ("Conky " VERSION " compiled " __DATE__ "\n");
4037 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
4038 * though free() does the NULL check itself;), then load optarg value */
4040 free(current_config);
4041 current_config = strdup(optarg);
4046 ("Usage: %s [OPTION]...\n"
4047 "Conky is a system monitor that renders text on desktop or to own transparent\n"
4048 "window. Command line options will override configurations defined in config\n"
4051 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
4052 " -c FILE config file to load instead of "
4055 " -d daemonize, fork to background\n"
4056 " -f FONT font to use\n"
4059 " -o create own window to draw\n"
4062 " -b double buffer (prevents flickering)\n"
4064 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
4065 " -u SECS update interval\n"
4066 " -i NUM number of times to update Conky\n"
4067 " -w WIN_ID window id to draw\n"
4068 " -x X x position\n"
4069 " -y Y y position\n", argv[0]);
4073 window.window = strtol(optarg, 0, 0);
4080 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
4083 tmpstring1 = (char *)
4084 malloc(TEXT_BUFFER_SIZE);
4085 tmpstring2 = (char *)
4086 malloc(TEXT_BUFFER_SIZE);
4088 /* load current_config or CONFIG_FILE */
4091 if (current_config == NULL) {
4092 /* load default config file */
4095 variable_substitute(CONFIG_FILE, buf, 256);
4098 current_config = strdup(buf);
4102 if (current_config != NULL)
4103 load_config_file(current_config);
4105 set_default_configurations();
4108 if (current_mail_spool == NULL) {
4110 variable_substitute(MAIL_FILE, buf, 256);
4113 current_mail_spool = strdup(buf);
4117 /* handle other command line arguments */
4122 int c = getopt(argc,
4130 text_alignment = string_to_alignment(optarg);
4134 fork_to_background = 1;
4138 set_first_font(optarg);
4153 if (text != original_text)
4155 text = strdup(optarg);
4156 convert_escapes(text);
4160 update_interval = strtod(optarg, 0);
4164 total_run_times = strtod(optarg, 0);
4168 gap_x = atoi(optarg);
4172 gap_y = atoi(optarg);
4183 /* generate text and get initial size */
4184 extract_variable_text(text);
4185 if (text != original_text)
4192 update_text_area(); /* to get initial size of the window */
4197 + border_margin * 2 + 1, text_height + border_margin * 2 + 1);
4199 update_text_area(); /* to position text/window on screen */
4202 // why the fuck not?
4208 XMoveWindow(display, window.window, window.x, window.y);
4218 if (fork_to_background) {
4222 ERR("can't fork() to background: %s",
4232 "Conky: forked to background, pid is %d\n",
4238 /* set SIGUSR1, SIGINT and SIGTERM handlers */
4243 sa.sa_handler = reload_handler;
4244 sigemptyset(&sa.sa_mask);
4245 sa.sa_flags = SA_RESTART;
4246 if (sigaction(SIGUSR1, &sa, NULL) != 0)
4247 ERR("can't set signal handler for SIGUSR1: %s",
4250 sa.sa_handler = term_handler;
4251 sigemptyset(&sa.sa_mask);
4252 sa.sa_flags = SA_RESTART;
4253 if (sigaction(SIGINT, &sa, NULL) != 0)
4254 ERR("can't set signal handler for SIGINT: %s",
4257 sa.sa_handler = term_handler;
4258 sigemptyset(&sa.sa_mask);
4259 sa.sa_flags = SA_RESTART;
4260 if (sigaction(SIGTERM, &sa, NULL) != 0)
4261 ERR("can't set signal handler for SIGTERM: %s",