2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
28 #include <X11/Xutil.h>
30 #include <sys/types.h>
33 #define CONFIG_FILE "$HOME/.conkyrc"
34 #define MAIL_FILE "$MAIL"
35 #define MAX_IF_BLOCK_DEPTH 5
52 char name[TEXT_BUFFER_SIZE];
62 static int selected_font = 0;
63 static int font_count = -1;
64 struct font_list *fonts = NULL;
68 #define font_height() use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
69 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
70 #define font_ascent() use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent
71 #define font_descent() use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent
75 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
76 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
77 #define font_descent() fonts[selected_font].font->max_bounds.descent
81 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
84 static void set_font();
87 int addfont(const char *data_in)
89 if (font_count > MAX_FONTS) {
90 CRIT_ERR("you don't need that many fonts, sorry.");
93 if (font_count == 0) {
97 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
101 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
103 CRIT_ERR("realloc in addfont");
105 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
106 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
108 fonts[font_count].font_alpha = 0xffff;
111 CRIT_ERR("Oops...looks like something overflowed in addfont().");
116 void set_first_font(const char *data_in)
118 if (font_count < 0) {
119 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
124 if (strlen(data_in) > 1) {
125 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
127 fonts[0].font_alpha = 0xffff;
135 for (i=0;i<=font_count;i++) {
138 XftFontClose(display, fonts[i].xftfont);
142 XFreeFont(display, fonts[i].font);
149 set_first_font("6x10");
153 static void load_fonts()
156 for (i=0;i<=font_count;i++) {
160 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
161 XftFontClose(display, fonts[i].xftfont);
163 if ((fonts[i].xftfont =
164 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
167 ERR("can't load Xft font '%s'", fonts[i].name);
168 if ((fonts[i].xftfont =
169 XftFontOpenName(display, screen,
170 "courier-12")) != NULL)
173 ERR("can't load Xft font '%s'", "courier-12");
175 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
176 CRIT_ERR("can't load font '%s'", "fixed");
183 /* load normal font */
184 /* if (fonts[i].font != NULL)
185 XFreeFont(display, fonts[i].font);*/
187 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
188 ERR("can't load font '%s'", fonts[i].name);
189 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
190 CRIT_ERR("can't load font '%s'", "fixed");
191 printf("loaded fixed?\n");
199 /* default config file */
200 static char *current_config;
202 /* set to 1 if you want all text to be in uppercase */
203 static unsigned int stuff_in_upper_case;
205 /* Update interval */
206 static double update_interval;
208 /* Run how many times? */
209 static unsigned long total_run_times;
212 static int fork_to_background;
214 static int cpu_avg_samples, net_avg_samples;
218 /* Always on bottom */
219 static int on_bottom;
221 /* Position on the screen */
222 static int text_alignment;
223 static int gap_x, gap_y;
226 static int draw_borders;
227 static int stippled_borders;
229 static int draw_shades, draw_outline;
231 static int border_margin, border_width;
233 static long default_fg_color, default_bg_color, default_out_color;
235 /* create own window or draw stuff to root? */
236 static int set_transparent = 0;
240 static int own_window = 0;
241 static int background_colour = 0;
242 static char wm_class_name[256];
243 /* fixed size/pos is set if wm/user changes them */
244 static int fixed_size = 0, fixed_pos = 0;
247 static int minimum_width, minimum_height;
248 static int maximum_width;
255 /* no buffers in used memory? */
258 /* pad percentages to decimals? */
259 static int pad_percents = 0;
261 /* Text that is shown */
262 static char original_text[] =
263 "$nodename - $sysname $kernel on $machine\n"
265 "${color grey}Uptime:$color $uptime\n"
266 "${color grey}Frequency (in MHz):$color $freq\n"
267 "${color grey}Frequency (in GHz):$color $freq_g\n"
268 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
269 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
270 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
271 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
273 "${color grey}File systems:\n"
274 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
275 "${color grey}Networking:\n"
276 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
277 "${color grey}Temperatures:\n"
278 " CPU:$color ${i2c temp 1}°C${color grey} - MB:$color ${i2c temp 2}°C\n"
281 "${color grey}SETI@Home Statistics:\n"
282 "${color grey}Seti Unit Number:$color $seti_credit\n"
283 "${color grey}Seti Progress:$color $seti_prog% $seti_progbar\n"
286 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
287 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
289 "${color grey}Name PID CPU% MEM%\n"
290 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
291 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
292 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
293 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
294 "${tail /var/log/Xorg.0.log 3}";
296 static char *text = original_text;
298 static int total_updates;
301 static int blockdepth = 0;
302 static int if_jumped = 0;
303 static int blockstart[MAX_IF_BLOCK_DEPTH];
305 int check_mount(char *s)
307 #if defined(__linux__)
309 FILE *mtab = fopen("/etc/mtab", "r");
311 char buf1[256], buf2[128];
312 while (fgets(buf1, 256, mtab)) {
313 sscanf(buf1, "%*s %128s", buf2);
314 if (!strcmp(s, buf2)) {
321 ERR("Could not open mtab");
324 #elif defined(__FreeBSD__)
325 struct statfs *mntbuf;
328 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
329 for (i = mntsize - 1; i >= 0; i--)
330 if (strcmp(mntbuf[i].f_mntonname, s) == 0)
339 static inline int calc_text_width(const char *s, unsigned int l)
345 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, s, l, &gi);
347 XftTextExtents8(display, fonts[selected_font].xftfont, s, l, &gi);
353 return XTextWidth(fonts[selected_font].font, s, l);
358 /* formatted text to render on screen, generated in generate_text(),
359 * drawn in draw_stuff() */
361 static char text_buffer[TEXT_BUFFER_SIZE * 4];
363 /* special stuff in text_buffer */
365 #define SPECIAL_CHAR '\x01'
382 static struct special_t {
392 unsigned long first_colour; // for graph gradient
393 unsigned long last_colour;
396 static int special_count;
398 static int special_index; /* used when drawing */
401 #define MAX_GRAPH_DEPTH 256 /* why 256? cause an array of more then 256 doubles seems excessive, and who needs that kind of precision anyway? */
403 static struct special_t *new_special(char *buf, int t)
405 if (special_count >= 128)
406 CRIT_ERR("too many special things in text");
408 buf[0] = SPECIAL_CHAR;
410 specials[special_count].type = t;
411 return &specials[special_count++];
414 typedef struct tailstring_list {
415 char data[TEXT_BUFFER_SIZE];
416 struct tailstring_list *next;
417 struct tailstring_list *first;
420 void addtail(tailstring ** head, char *data_in)
423 if ((tmp = malloc(sizeof(*tmp))) == NULL) {
429 tmp->first = (*head)->first;
431 strncpy(tmp->data, data_in, TEXT_BUFFER_SIZE);
436 void freetail(tailstring * head)
439 while (head != NULL) {
446 void freelasttail(tailstring * head)
448 tailstring * tmp = head;
450 if (tmp->next == head->first) {
457 while(head != NULL && tmp != NULL) {
463 static void new_bar(char *buf, int w, int h, int usage)
465 struct special_t *s = new_special(buf, BAR);
466 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
471 static const char *scan_bar(const char *args, int *w, int *h)
473 *w = 0; /* zero width means all space that is available */
475 /* bar's argument is either height or height,width */
478 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
479 sscanf(args, "%d %n", h, &n);
486 static char *scan_font(const char *args)
488 if (args && sizeof(args) < 127) {
492 ERR("font scan failed, lets hope it doesn't mess stuff up");
498 static void new_font(char *buf, char * args) {
499 struct special_t *s = new_special(buf, FONT);
500 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
501 int tmp = selected_font;
502 selected_font = s->font_added = addfont(args);
510 inline void graph_append(struct special_t *graph, double f)
512 if (!graph->scaled && f > graph->graph_scale) {
513 f = graph->graph_scale;
517 graph->graph_scale = 1;
519 graph->graph[graph->graph_width - 1] = f; /* add new data */
520 for (i = 0; i < graph->graph_width - 1; i++) { /* shift all the data by 1 */
521 graph->graph[i] = graph->graph[i + 1];
522 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
523 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
528 short colour_depth = 0;
529 void set_up_gradient();
531 /* precalculated: 31/255, and 63/255 */
532 #define CONST_8_TO_5_BITS 0.12156862745098
533 #define CONST_8_TO_6_BITS 0.247058823529412
535 /* adjust color values depending on color depth*/
536 static unsigned int adjust_colors(unsigned int color)
539 if (colour_depth == 0) {
542 if (colour_depth == 16) {
543 r = (color & 0xff0000) >> 16;
544 g = (color & 0xff00) >> 8;
546 color = (int)(r * CONST_8_TO_5_BITS) << 11;
547 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
548 color |= (int)(b * CONST_8_TO_5_BITS);
553 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
555 struct special_t *s = new_special(buf, GRAPH);
557 if (s->graph == NULL) {
558 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
559 s->graph_width = s->width - 3; // subtract 3 for the box
561 s->graph_width = MAX_GRAPH_DEPTH - 3;
563 s->graph = malloc(s->graph_width * sizeof(double));
564 memset(s->graph, 0, s->graph_width * sizeof(double));
565 s->graph_scale = 100;
568 s->first_colour = adjust_colors(first_colour);
569 s->last_colour = adjust_colors(second_colour);
576 s->graph_width = s->width - 3; // subtract 3 for rectangle around
581 s->graph_scale = scale;
588 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
590 *w = 0; /* zero width means all space that is available */
594 /* graph's argument is either height or height,width */
596 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
597 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
599 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
601 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
604 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
608 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
611 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
615 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
618 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
622 if (sscanf(args, "%d,%d", h, w) < 2) {
625 sscanf(args, "%*s %d,%d", h, w);
631 static inline void new_hr(char *buf, int a)
633 new_special(buf, HORIZONTAL_LINE)->height = a;
636 static inline void new_stippled_hr(char *buf, int a, int b)
638 struct special_t *s = new_special(buf, STIPPLED_HR);
643 static inline void new_fg(char *buf, long c)
645 new_special(buf, FG)->arg = c;
648 static inline void new_bg(char *buf, long c)
650 new_special(buf, BG)->arg = c;
653 static inline void new_outline(char *buf, long c)
655 new_special(buf, OUTLINE)->arg = c;
658 static inline void new_offset(char *buf, long c)
660 new_special(buf, OFFSET)->arg = c;
663 static inline void new_voffset(char *buf, long c)
665 new_special(buf, VOFFSET)->arg = c;
668 static inline void new_alignr(char *buf, long c)
670 new_special(buf, ALIGNR)->arg = c;
673 static inline void new_alignc(char *buf, long c)
675 new_special(buf, ALIGNC)->arg = c;
678 /* quite boring functions */
680 static inline void for_each_line(char *b, void (*f) (char *))
684 for (ps = b, pe = b; *pe; pe++) {
697 static void convert_escapes(char *buf)
699 char *p = buf, *s = buf;
715 /* converts from bytes to human readable format (k, M, G, T) */
716 static void human_readable(long long a, char *buf, int size)
718 // Strange conditional due to possible overflows
719 if(a / 1024 / 1024 / 1024.0 > 1024.0){
720 snprintf(buf, size, "%.2fT", (a / 1024 / 1024 / 1024) / 1024.0);
722 else if (a >= 1024 * 1024 * 1024) {
723 snprintf(buf, size, "%.2fG", (a / 1024 / 1024) / 1024.0);
725 else if (a >= 1024 * 1024) {
726 double m = (a / 1024) / 1024.0;
728 snprintf(buf, size, "%.0fM", m);
730 snprintf(buf, size, "%.1fM", m);
731 } else if (a >= 1024)
732 snprintf(buf, size, "%Ldk", a / (long long) 1024);
734 snprintf(buf, size, "%Ld", a);
739 enum text_object_type {
787 #if defined(__linux__)
793 OBJ_i8k_left_fan_status,
794 OBJ_i8k_right_fan_status,
795 OBJ_i8k_left_fan_rpm,
796 OBJ_i8k_right_fan_rpm,
798 OBJ_i8k_buttons_status,
799 #endif /* __linux__ */
826 OBJ_ml_upload_counter,
827 OBJ_ml_download_counter,
828 OBJ_ml_nshared_files,
829 OBJ_ml_shared_counter,
830 OBJ_ml_tcp_upload_rate,
831 OBJ_ml_tcp_download_rate,
832 OBJ_ml_udp_upload_rate,
833 OBJ_ml_udp_download_rate,
834 OBJ_ml_ndownloaded_files,
835 OBJ_ml_ndownloading_files,
838 OBJ_running_processes,
847 OBJ_temp1, /* i2c is used instead in these */
860 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
862 OBJ_apm_battery_time,
863 OBJ_apm_battery_life,
864 #endif /* __FreeBSD__ */
887 #ifdef TCP_PORT_MONITOR
895 unsigned int c, d, e;
898 char *s; /* some string */
899 int i; /* some integer */
900 long l; /* some other integer */
901 struct net_stat *net;
903 unsigned char loadavg[3];
904 //unsigned int diskio;
905 unsigned int cpu_index;
951 #ifdef TCP_PORT_MONITOR
953 in_port_t port_range_begin; /* starting port to monitor */
954 in_port_t port_range_end; /* ending port to monitor */
955 int item; /* enum value from libtcp-portmon.h, e.g. COUNT, REMOTEIP, etc. */
956 int connection_index; /* 0 to n-1 connections. */
962 static unsigned int text_object_count;
963 static struct text_object *text_objects;
965 pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
967 void *threaded_exec( struct text_object *obj ) {
968 char *p2 = obj->data.execi.buffer;
969 FILE *fp = popen(obj->data.execi.cmd,"r");
970 pthread_mutex_lock( &mutex1 );
971 int n2 = fread(p2, 1, TEXT_BUFFER_SIZE, fp);
974 if (n2 && p2[n2 - 1] == '\n')
982 pthread_mutex_unlock( &mutex1 );
986 /* new_text_object() allocates a new zeroed text_object */
987 static struct text_object *new_text_object()
990 text_objects = (struct text_object *) realloc(text_objects,
994 memset(&text_objects[text_object_count - 1], 0,
995 sizeof(struct text_object));
997 return &text_objects[text_object_count - 1];
1000 static void free_text_objects()
1003 for (i = 0; i < text_object_count; i++) {
1004 switch (text_objects[i].type) {
1006 close(text_objects[i].data.i);
1009 close(text_objects[i].data.i);
1012 close(text_objects[i].data.i2c.fd);
1015 free(text_objects[i].data.s);
1018 case OBJ_if_existing:
1019 case OBJ_if_mounted:
1020 case OBJ_if_running:
1021 free(text_objects[i].data.ifblock.s);
1024 free(text_objects[i].data.tail.logfile);
1025 free(text_objects[i].data.tail.buffer);
1029 free(text_objects[i].data.s);
1032 free(text_objects[i].data.s);
1035 free(text_objects[i].data.s);
1038 free(text_objects[i].data.s);
1040 /* case OBJ_execibar:
1041 free(text_objects[i].data.s);
1043 case OBJ_execigraph:
1044 free(text_objects[i].data.s);
1048 case OBJ_mpd_artist:
1050 case OBJ_mpd_random:
1051 case OBJ_mpd_repeat:
1053 case OBJ_mpd_status:
1058 free(text_objects[i].data.s);
1062 free(text_objects[i].data.execi.cmd);
1063 free(text_objects[i].data.execi.buffer);
1066 free(text_objects[i].data.execi.cmd);
1067 free(text_objects[i].data.execi.buffer);
1070 if (info.first_process) {
1071 free_all_processes(info.first_process);
1072 info.first_process = NULL;
1076 if (info.first_process) {
1077 free_all_processes(info.first_process);
1078 info.first_process = NULL;
1085 text_objects = NULL;
1086 text_object_count = 0;
1089 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1094 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1095 *a = mixer_init(buf1);
1096 (void) scan_bar(arg + n, w, h);
1099 (void) scan_bar(arg, w, h);
1103 /* construct_text_object() creates a new text_object */
1104 static void construct_text_object(const char *s, const char *arg)
1106 struct text_object *obj = new_text_object();
1108 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
1109 #define END ; } } else
1113 obj->type = OBJ_color;
1114 obj->data.l = get_x11_color(s);
1117 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
1118 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
1119 END OBJ(acpiacadapter, 0)
1122 END OBJ(freq_dyn, 0);
1123 END OBJ(freq_dyn_g, 0);
1124 END OBJ(acpifan, 0);
1125 END OBJ(battery, 0);
1128 sscanf(arg, "%63s", bat);
1130 strcpy(bat, "BAT0");
1131 obj->data.s = strdup(bat);
1132 #if defined(__linux__)
1133 END OBJ(i8k_version, INFO_I8K)
1134 END OBJ(i8k_bios, INFO_I8K)
1135 END OBJ(i8k_serial, INFO_I8K)
1136 END OBJ(i8k_cpu_temp, INFO_I8K)
1137 END OBJ(i8k_cpu_tempf, INFO_I8K)
1138 END OBJ(i8k_left_fan_status, INFO_I8K)
1139 END OBJ(i8k_right_fan_status, INFO_I8K)
1140 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1141 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1142 END OBJ(i8k_ac_status, INFO_I8K)
1143 END OBJ(i8k_buttons_status, INFO_I8K)
1144 #endif /* __linux__ */
1145 END OBJ(buffers, INFO_BUFFERS)
1146 END OBJ(cached, INFO_BUFFERS)
1147 END OBJ(cpu, INFO_CPU)
1149 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1150 obj->data.cpu_index = atoi(&arg[3]);
1152 } else {obj->data.cpu_index = 0; }
1154 obj->data.cpu_index = 0;
1156 END OBJ(cpubar, INFO_CPU)
1158 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1159 obj->data.cpu_index = atoi(&arg[3]);
1162 else {obj->data.cpu_index = 0;}
1163 (void) scan_bar(arg, &obj->a, &obj->b);
1165 (void) scan_bar(arg, &obj->a, &obj->b);
1166 obj->data.cpu_index = 0;
1168 END OBJ(cpugraph, INFO_CPU)
1170 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1171 obj->data.cpu_index = atoi(&arg[3]);
1174 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1176 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1177 obj->data.cpu_index = 0;
1179 END OBJ(diskio, INFO_DISKIO)
1180 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1183 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1187 obj->data.s = scan_font(arg);
1189 OBJ(downspeed, INFO_NET)
1191 obj->data.net = get_net_stat(arg);
1194 CRIT_ERR("downspeed needs argument");
1196 END OBJ(downspeedf, INFO_NET)
1198 obj->data.net = get_net_stat(arg);
1201 CRIT_ERR("downspeedf needs argument");
1203 END OBJ(downspeedgraph, INFO_NET)
1204 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1206 sscanf(arg, "%63s %*i,%*i %*i", buf);
1207 obj->data.net = get_net_stat(buf);
1208 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
1209 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
1218 text_objects[blockstart[blockdepth - 1] -
1219 1].data.ifblock.pos = text_object_count;
1220 blockstart[blockdepth - 1] = text_object_count;
1221 obj->data.ifblock.pos = text_object_count + 2;
1223 ERR("$else: no matching $if_*");
1228 text_objects[blockstart[blockdepth] - 1].data.ifblock.pos =
1231 ERR("$endif: no matching $if_*");
1235 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
1236 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
1237 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
1238 END OBJ(execibar, 0) unsigned int n;
1239 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1241 ERR("${execibar <interval> command}");
1242 obj->type = OBJ_text;
1243 snprintf(buf, 256, "${%s}", s);
1244 obj->data.s = strdup(buf);
1246 obj->data.execi.cmd = strdup(arg + n);
1248 END OBJ(execigraph, 0) unsigned int n;
1249 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1251 ERR("${execigraph <interval> command}");
1252 obj->type = OBJ_text;
1253 snprintf(buf, 256, "${%s}", s);
1254 obj->data.s = strdup(buf);
1256 obj->data.execi.cmd = strdup(arg + n);
1258 END OBJ(execi, 0) unsigned int n;
1261 || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1263 ERR("${execi <interval> command}");
1264 obj->type = OBJ_text;
1265 snprintf(buf, 256, "${%s}", s);
1266 obj->data.s = strdup(buf);
1268 obj->data.execi.cmd = strdup(arg + n);
1269 obj->data.execi.buffer =
1270 (char *) calloc(1, TEXT_BUFFER_SIZE);
1272 END OBJ(texeci, 0) unsigned int n;
1275 || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1277 ERR("${texeci <interval> command}");
1278 obj->type = OBJ_text;
1279 snprintf(buf, 256, "${%s}", s);
1280 obj->data.s = strdup(buf);
1282 obj->data.execi.cmd = strdup(arg + n);
1283 obj->data.execi.buffer =
1284 (char *) calloc(1, TEXT_BUFFER_SIZE);
1286 END OBJ(pre_exec, 0) obj->type = OBJ_text;
1288 FILE *fp = popen(arg, "r");
1292 n = fread(buf, 1, 2048, fp);
1295 if (n && buf[n - 1] == '\n')
1300 obj->data.s = strdup(buf);
1302 obj->data.s = strdup("");
1305 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
1306 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1308 while (isspace(*arg))
1314 obj->data.fsbar.fs = prepare_fs_stat(arg);
1315 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
1318 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
1322 obj->data.fsbar.fs = prepare_fs_stat(arg);
1323 END OBJ(fs_free, INFO_FS) if (!arg)
1325 obj->data.fs = prepare_fs_stat(arg);
1326 END OBJ(fs_used_perc, INFO_FS) if (!arg)
1328 obj->data.fs = prepare_fs_stat(arg);
1329 END OBJ(fs_free_perc, INFO_FS) if (!arg)
1331 obj->data.fs = prepare_fs_stat(arg);
1332 END OBJ(fs_size, INFO_FS) if (!arg)
1334 obj->data.fs = prepare_fs_stat(arg);
1335 END OBJ(fs_used, INFO_FS) if (!arg)
1337 obj->data.fs = prepare_fs_stat(arg);
1338 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
1339 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
1340 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
1341 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
1345 ERR("i2c needs arguments");
1346 obj->type = OBJ_text;
1347 //obj->data.s = strdup("${i2c}");
1351 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
1352 /* if scanf couldn't read three values, read type and num and use
1354 sscanf(arg, "%63s %d", buf2, &n);
1356 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
1357 obj->data.i2c.devtype);
1358 strncpy(obj->data.i2c.type, buf2, 63);
1361 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
1362 obj->data.i2c.devtype);
1363 strncpy(obj->data.i2c.type, buf2, 63);
1366 END OBJ(top, INFO_TOP)
1370 ERR("top needs arguments");
1371 obj->type = OBJ_text;
1372 //obj->data.s = strdup("${top}");
1375 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1376 if (strcmp(buf, "name") == 0) {
1377 obj->data.top.type = TOP_NAME;
1378 } else if (strcmp(buf, "cpu") == 0) {
1379 obj->data.top.type = TOP_CPU;
1380 } else if (strcmp(buf, "pid") == 0) {
1381 obj->data.top.type = TOP_PID;
1382 } else if (strcmp(buf, "mem") == 0) {
1383 obj->data.top.type = TOP_MEM;
1385 ERR("invalid arg for top");
1388 if (n < 1 || n > 10) {
1389 CRIT_ERR("invalid arg for top");
1392 obj->data.top.num = n - 1;
1396 ERR("invalid args given for top");
1399 END OBJ(top_mem, INFO_TOP)
1403 ERR("top_mem needs arguments");
1404 obj->type = OBJ_text;
1405 obj->data.s = strdup("${top_mem}");
1408 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1409 if (strcmp(buf, "name") == 0) {
1410 obj->data.top.type = TOP_NAME;
1411 } else if (strcmp(buf, "cpu") == 0) {
1412 obj->data.top.type = TOP_CPU;
1413 } else if (strcmp(buf, "pid") == 0) {
1414 obj->data.top.type = TOP_PID;
1415 } else if (strcmp(buf, "mem") == 0) {
1416 obj->data.top.type = TOP_MEM;
1418 ERR("invalid arg for top");
1421 if (n < 1 || n > 10) {
1422 CRIT_ERR("invalid arg for top");
1425 obj->data.top.num = n - 1;
1429 ERR("invalid args given for top");
1432 END OBJ(addr, INFO_NET)
1434 obj->data.net = get_net_stat(arg);
1437 CRIT_ERR("addr needs argument");
1439 END OBJ(linkstatus, INFO_WIFI)
1441 obj->data.net = get_net_stat(arg);
1444 CRIT_ERR("linkstatus needs argument");
1450 ERR("tail needs arguments");
1451 obj->type = OBJ_text;
1452 obj->data.s = strdup("${tail}");
1455 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
1456 if (n1 < 1 || n1 > 30) {
1457 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
1461 fp = fopen(buf, "rt");
1463 obj->data.tail.logfile =
1464 malloc(TEXT_BUFFER_SIZE);
1465 strcpy(obj->data.tail.logfile, buf);
1466 obj->data.tail.wantedlines = n1 - 1;
1467 obj->data.tail.interval =
1468 update_interval * 2;
1472 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
1475 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
1476 if (n1 < 1 || n1 > 30) {
1478 ("invalid arg for tail, number of lines must be between 1 and 30");
1480 } else if (n2 < 1 || n2 < update_interval) {
1482 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
1486 fp = fopen(buf, "rt");
1488 obj->data.tail.logfile =
1489 malloc(TEXT_BUFFER_SIZE);
1490 strcpy(obj->data.tail.logfile, buf);
1491 obj->data.tail.wantedlines = n1 - 1;
1492 obj->data.tail.interval = n2;
1496 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
1502 ERR("invalid args given for tail");
1505 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
1510 ERR("head needs arguments");
1511 obj->type = OBJ_text;
1512 obj->data.s = strdup("${head}");
1515 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
1516 if (n1 < 1 || n1 > 30) {
1517 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
1521 fp = fopen(buf, "rt");
1523 obj->data.tail.logfile =
1524 malloc(TEXT_BUFFER_SIZE);
1525 strcpy(obj->data.tail.logfile, buf);
1526 obj->data.tail.wantedlines = n1 - 1;
1527 obj->data.tail.interval =
1528 update_interval * 2;
1532 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
1535 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
1536 if (n1 < 1 || n1 > 30) {
1538 ("invalid arg for head, number of lines must be between 1 and 30");
1540 } else if (n2 < 1 || n2 < update_interval) {
1542 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
1546 fp = fopen(buf, "rt");
1548 obj->data.tail.logfile =
1549 malloc(TEXT_BUFFER_SIZE);
1550 strcpy(obj->data.tail.logfile, buf);
1551 obj->data.tail.wantedlines = n1 - 1;
1552 obj->data.tail.interval = n2;
1556 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
1562 ERR("invalid args given for head");
1565 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
1566 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
1568 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1569 if (r >= 3 && (c < 1 || c > 3))
1571 if (r >= 2 && (b < 1 || b > 3))
1573 if (r >= 1 && (a < 1 || a > 3))
1576 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1577 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1578 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1579 END OBJ(if_existing, 0)
1580 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1581 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1584 ERR("if_existing needs an argument");
1585 obj->data.ifblock.s = 0;
1587 obj->data.ifblock.s = strdup(arg);
1588 blockstart[blockdepth] = text_object_count;
1589 obj->data.ifblock.pos = text_object_count + 2;
1591 END OBJ(if_mounted, 0)
1592 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1593 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1596 ERR("if_mounted needs an argument");
1597 obj->data.ifblock.s = 0;
1599 obj->data.ifblock.s = strdup(arg);
1600 blockstart[blockdepth] = text_object_count;
1601 obj->data.ifblock.pos = text_object_count + 2;
1603 END OBJ(if_running, 0)
1604 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1605 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1609 snprintf(buf, 256, "pidof %s >/dev/null", arg);
1610 obj->data.ifblock.s = strdup(buf);
1612 ERR("if_running needs an argument");
1613 obj->data.ifblock.s = 0;
1615 blockstart[blockdepth] = text_object_count;
1616 obj->data.ifblock.pos = text_object_count + 2;
1620 END OBJ(mails, INFO_MAIL)
1621 END OBJ(mem, INFO_MEM)
1622 END OBJ(memmax, INFO_MEM)
1623 END OBJ(memperc, INFO_MEM)
1624 END OBJ(membar, INFO_MEM)
1625 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1626 END OBJ(memgraph, INFO_MEM)
1627 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1628 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
1629 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
1630 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
1631 END OBJ(mixerbar, INFO_MIXER)
1632 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1633 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1634 END OBJ(mixerlbar, INFO_MIXER)
1635 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1636 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1637 END OBJ(mixerrbar, INFO_MIXER)
1638 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1639 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1642 OBJ(ml_upload_counter, INFO_MLDONKEY)
1643 END OBJ(ml_download_counter, INFO_MLDONKEY)
1644 END OBJ(ml_nshared_files, INFO_MLDONKEY)
1645 END OBJ(ml_shared_counter, INFO_MLDONKEY)
1646 END OBJ(ml_tcp_upload_rate, INFO_MLDONKEY)
1647 END OBJ(ml_tcp_download_rate, INFO_MLDONKEY)
1648 END OBJ(ml_udp_upload_rate, INFO_MLDONKEY)
1649 END OBJ(ml_udp_download_rate, INFO_MLDONKEY)
1650 END OBJ(ml_ndownloaded_files, INFO_MLDONKEY)
1651 END OBJ(ml_ndownloading_files, INFO_MLDONKEY) END
1653 OBJ(new_mails, INFO_MAIL)
1654 END OBJ(nodename, 0)
1655 END OBJ(processes, INFO_PROCS)
1656 END OBJ(running_processes, INFO_RUN_PROCS)
1657 END OBJ(shadecolor, 0)
1659 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
1661 END OBJ(outlinecolor, 0)
1663 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
1665 END OBJ(stippled_hr, 0)
1667 int a = stippled_borders, b = 1;
1669 if (sscanf(arg, "%d %d", &a, &b) != 2)
1670 sscanf(arg, "%d", &b);
1674 obj->data.pair.a = a;
1675 obj->data.pair.b = b;
1677 END OBJ(swap, INFO_MEM)
1678 END OBJ(swapmax, INFO_MEM)
1679 END OBJ(swapperc, INFO_MEM)
1680 END OBJ(swapbar, INFO_MEM)
1681 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1682 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
1684 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
1685 obj->data.i2c.devtype);
1686 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
1688 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
1689 obj->data.i2c.devtype);
1690 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1691 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1692 END OBJ(totaldown, INFO_NET)
1694 obj->data.net = get_net_stat(arg);
1697 CRIT_ERR("totaldown needs argument");
1699 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
1701 obj->data.net = get_net_stat(arg);
1704 CRIT_ERR("totalup needs argument");
1707 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
1708 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
1709 END OBJ(upspeed, INFO_NET)
1711 obj->data.net = get_net_stat(arg);
1714 CRIT_ERR("upspeed needs argument");
1716 END OBJ(upspeedf, INFO_NET)
1718 obj->data.net = get_net_stat(arg);
1721 CRIT_ERR("upspeedf needs argument");
1724 END OBJ(upspeedgraph, INFO_NET)
1725 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1727 sscanf(arg, "%63s %*i,%*i %*i", buf);
1728 obj->data.net = get_net_stat(buf);
1729 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
1730 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
1735 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
1736 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
1737 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
1738 OBJ(apm_adapter, 0) END
1739 OBJ(apm_battery_life, 0) END
1740 OBJ(apm_battery_time, 0) END
1741 #endif /* __FreeBSD__ */
1743 OBJ(seti_prog, INFO_SETI) END OBJ(seti_progbar, INFO_SETI)
1744 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1745 END OBJ(seti_credit, INFO_SETI) END
1748 OBJ(mpd_artist, INFO_MPD)
1749 END OBJ(mpd_title, INFO_MPD)
1750 END OBJ(mpd_random, INFO_MPD)
1751 END OBJ(mpd_repeat, INFO_MPD)
1752 END OBJ(mpd_elapsed, INFO_MPD)
1753 END OBJ(mpd_length, INFO_MPD)
1754 END OBJ(mpd_track, INFO_MPD)
1755 END OBJ(mpd_percent, INFO_MPD)
1756 END OBJ(mpd_album, INFO_MPD) END OBJ(mpd_vol,
1757 INFO_MPD) END OBJ(mpd_bitrate,
1759 END OBJ(mpd_status, INFO_MPD)
1760 END OBJ(mpd_bar, INFO_MPD)
1761 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1764 #ifdef TCP_PORT_MONITOR
1765 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
1766 int argc, port_begin, port_end, item, connection_index;
1768 memset(itembuf,0,sizeof(itembuf));
1770 /* massive argument checking */
1772 CRIT_ERR("tcp_portmon: needs arguments");
1774 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
1775 if ( (argc != 3) && (argc != 4) )
1777 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
1779 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
1781 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
1783 if ( port_begin > port_end )
1785 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
1787 if ( strncmp(itembuf,"count",31) == 0 )
1789 else if ( strncmp(itembuf,"rip",31) == 0 )
1791 else if ( strncmp(itembuf,"rhost",31) == 0 )
1793 else if ( strncmp(itembuf,"rport",31) == 0 )
1795 else if ( strncmp(itembuf,"lip",31) == 0 )
1797 else if ( strncmp(itembuf,"lhost",31) == 0 )
1799 else if ( strncmp(itembuf,"lport",31) == 0 )
1801 else if ( strncmp(itembuf,"lservice",31) == 0 )
1805 CRIT_ERR("tcp_portmon: invalid item specified");
1807 if ( (argc==3) && (item!=COUNT) )
1809 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
1811 if ( (argc==4) && (connection_index<0) )
1813 CRIT_ERR("tcp_portmon: connection index must be non-negative");
1815 /* ok, args looks good. save the text object data */
1816 obj->data.tcp_port_monitor.port_range_begin = (in_addr_t)port_begin;
1817 obj->data.tcp_port_monitor.port_range_end = (in_addr_t)port_end;
1818 obj->data.tcp_port_monitor.item = item;
1819 obj->data.tcp_port_monitor.connection_index = connection_index;
1821 /* if the port monitor collection hasn't been created, we must create it */
1822 if ( !info.p_tcp_port_monitor_collection )
1824 info.p_tcp_port_monitor_collection = create_tcp_port_monitor_collection();
1825 if ( !info.p_tcp_port_monitor_collection )
1827 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
1831 /* if a port monitor for this port does not exist, create one and add it to the collection */
1832 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
1834 tcp_port_monitor_t * p_monitor = create_tcp_port_monitor( port_begin, port_end );
1837 CRIT_ERR("tcp_portmon: unable to create port monitor");
1839 /* add the newly created monitor to the collection */
1840 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
1843 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
1850 ERR("unknown variable %s", s);
1851 obj->type = OBJ_text;
1852 snprintf(buf, 256, "${%s}", s);
1853 obj->data.s = strdup(buf);
1858 /* append_text() appends text to last text_object if it's text, if it isn't
1859 * it creates a new text_object */
1860 static void append_text(const char *s)
1862 struct text_object *obj;
1864 if (s == NULL || *s == '\0')
1867 obj = text_object_count ? &text_objects[text_object_count - 1] : 0;
1869 /* create a new text object? */
1870 if (!obj || obj->type != OBJ_text) {
1871 obj = new_text_object();
1872 obj->type = OBJ_text;
1873 obj->data.s = strdup(s);
1876 obj->data.s = (char *) realloc(obj->data.s,
1877 strlen(obj->data.s) +
1879 strcat(obj->data.s, s);
1883 static void extract_variable_text(const char *p)
1887 free_text_objects();
1902 /* variable is either $foo or ${foo} */
1906 while (*p && *p != '}')
1912 while (*p && (isalnum((int) *p)
1917 /* copy variable to buffer */
1918 len = (p - s > 255) ? 255 : (p - s);
1919 strncpy(buf, s, len);
1928 /* if variable wasn't found from environment, use some special */
1934 if (strchr(buf, ' ')) {
1935 arg = strchr(buf, ' ');
1938 while (isspace((int) *arg))
1944 /* lowercase variable name */
1951 construct_text_object(buf, arg);
1962 ERR("one or more $endif's are missing");
1966 double current_update_time, last_update_time;
1968 static void generate_text()
1971 struct information *cur = &info;
1978 current_update_time = get_time();
1984 n = TEXT_BUFFER_SIZE * 4 - 2;
1987 for (i = 0; i < text_object_count; i++) {
1988 struct text_object *obj = &text_objects[i];
1990 #define OBJ(a) break; case OBJ_##a:
1992 switch (obj->type) {
1995 ERR("not implemented obj type %d",
1999 /* does anyone have decimals in acpi temperature? */
2001 snprintf(p, n, "%d", (int)
2002 get_acpi_temperature(obj->
2006 snprintf(p, 5, "%d ", (int)
2007 get_acpi_temperature(obj->
2012 /* does anyone have decimals in acpi temperature? */
2014 snprintf(p, n, "%d", (int)
2015 ((get_acpi_temperature(obj->
2017 i)+ 40) * 9.0 / 5 - 40));
2019 snprintf(p, 5, "%d ", (int)
2020 ((get_acpi_temperature(obj->
2022 i)+ 40) * 9.0 / 5 - 40));
2025 snprintf(p, n, "%.0f", get_freq());
2028 float ghz = (float)(get_freq()/1000);
2029 //printf("%f\n", ghz);
2030 snprintf(p, n, "%'.2f", ghz);
2033 snprintf(p, n, "%.0f", get_freq_dynamic());
2036 float ghz = (float)(get_freq_dynamic()/1000);
2037 snprintf(p, n, "%'.2f", ghz);
2040 snprintf(p, n, "%s", get_adt746x_cpu());
2043 snprintf(p, n, "%s", get_adt746x_fan());
2046 snprintf(p, n, "%s", get_acpi_fan());
2048 OBJ(acpiacadapter) {
2049 snprintf(p, n, "%s",
2050 get_acpi_ac_adapter());
2053 get_battery_stuff(p, n, obj->data.s);
2056 human_readable(cur->buffers * 1024, p,
2060 human_readable(cur->cached * 1024, p, 255);
2063 if (obj->data.cpu_index > info.cpu_count) {
2064 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
2065 CRIT_ERR("attempting to use more CPUs then you have!");
2068 snprintf(p, n, "%*d", pad_percents,
2069 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
2072 snprintf(p, 4, "%*d ",
2074 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
2080 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
2083 new_graph(p, obj->a,
2084 obj->b, obj->c, obj->d,
2085 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
2089 new_fg(p, obj->data.l);
2091 #if defined(__linux__)
2093 snprintf(p, n, "%s", i8k.version);
2096 snprintf(p, n, "%s", i8k.bios);
2099 snprintf(p, n, "%s", i8k.serial);
2102 snprintf(p, n, "%s", i8k.cpu_temp);
2104 OBJ(i8k_cpu_tempf) {
2106 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
2107 snprintf(p, n, "%.1f", cpu_temp*(9.0/5.0)+32.0);
2109 OBJ(i8k_left_fan_status) {
2110 int left_fan_status;
2111 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
2112 if(left_fan_status == 0) {
2113 snprintf(p, n,"off");
2114 } if(left_fan_status == 1) {
2115 snprintf(p, n, "low");
2116 } if(left_fan_status == 2) {
2117 snprintf(p, n, "high");
2121 OBJ(i8k_right_fan_status) {
2122 int right_fan_status;
2123 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
2124 if(right_fan_status == 0) {
2125 snprintf(p, n,"off");
2126 } if(right_fan_status == 1) {
2127 snprintf(p, n, "low");
2128 } if(right_fan_status == 2) {
2129 snprintf(p, n, "high");
2132 OBJ(i8k_left_fan_rpm) {
2133 snprintf(p, n, "%s", i8k.left_fan_rpm);
2135 OBJ(i8k_right_fan_rpm) {
2136 snprintf(p, n, "%s", i8k.right_fan_rpm);
2138 OBJ(i8k_ac_status) {
2140 sscanf(i8k.ac_status, "%d", &ac_status);
2141 if(ac_status == -1) {
2142 snprintf(p, n,"disabled (read i8k docs)");
2143 } if(ac_status == 0) {
2144 snprintf(p, n, "off");
2145 } if(ac_status == 1) {
2146 snprintf(p, n, "on");
2149 OBJ(i8k_buttons_status) {
2150 snprintf(p, n, "%s", i8k.buttons_status);
2153 #endif /* __linux__ */
2157 new_font(p, obj->data.s);
2162 if (diskio_value > 1024*1024) {
2163 snprintf(p, n, "%.1fG",
2164 (double)diskio_value/1024/1024);
2165 } else if (diskio_value > 1024) {
2166 snprintf(p, n, "%.1fM",
2167 (double)diskio_value/1024);
2168 } else if (diskio_value > 0) {
2169 snprintf(p, n, "%dK", diskio_value);
2171 snprintf(p, n, "%d", diskio_value);
2174 if (diskio_value > 1024*1024) {
2175 snprintf(p, 6, "%.1fG ",
2176 (double)diskio_value/1024/1024);
2177 } else if (diskio_value > 1024) {
2178 snprintf(p, 6, "%.1fM ",
2179 (double)diskio_value/1024);
2180 } else if (diskio_value > 0) {
2181 snprintf(p, 6, "%dK ", diskio_value);
2183 snprintf(p, 6, "%d ", diskio_value);
2188 new_graph(p, obj->a,
2189 obj->b, obj->c, obj->d,
2190 diskio_value, obj->e, 1);
2195 snprintf(p, n, "%d",
2196 (int) (obj->data.net->
2200 snprintf(p, 6, "%d ",
2201 (int) (obj->data.net->
2207 snprintf(p, n, "%.1f",
2209 recv_speed / 1024.0);
2211 snprintf(p, 8, "%.1f ",
2213 recv_speed / 1024.0);
2215 OBJ(downspeedgraph) {
2216 if (obj->data.net->recv_speed == 0) // this is just to make the ugliness at start go away
2217 obj->data.net->recv_speed = 0.01;
2218 new_graph(p, obj->a, obj->b, obj->c, obj->d,
2219 (obj->data.net->recv_speed /
2220 1024.0), obj->e, 1);
2226 i = obj->data.ifblock.pos - 2;
2236 snprintf(p, n, "%u.%u.%u.%u",
2237 obj->data.net->addr.
2239 obj->data.net->addr.
2241 obj->data.net->addr.
2243 obj->data.net->addr.
2248 snprintf(p, n, "%d",
2249 obj->data.net->linkstatus);
2254 FILE *fp = popen(obj->data.s, "r");
2255 int n2 = fread(p, 1, n, fp);
2259 if (n2 && p[n2 - 1] == '\n')
2270 FILE *fp = popen(obj->data.s, "r");
2271 int n2 = fread(p, 1, n, fp);
2275 if (n2 && p[n2 - 1] == '\n')
2284 if (sscanf(p, "%lf", &barnum) == 0) {
2285 ERR("reading execbar value failed (perhaps it's not the correct format?)");
2287 if (barnum > 100 || barnum < 0) {
2288 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
2290 barnum = barnum / 100.0;
2291 new_bar(p, 0, 4, (int) (barnum * 255.0));
2297 FILE *fp = popen(obj->data.s, "r");
2298 int n2 = fread(p, 1, n, fp);
2302 if (n2 && p[n2 - 1] == '\n')
2311 if (sscanf(p, "%lf", &barnum) == 0) {
2312 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
2314 if (barnum > 100 || barnum < 0) {
2315 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
2318 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
2323 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2324 new_bar(p, 0, 4, (int) obj->f);
2327 FILE *fp = popen(obj->data.execi.cmd, "r");
2328 int n2 = fread(p, 1, n, fp);
2331 if (n2 && p[n2 - 1] == '\n')
2340 if (sscanf(p, "%f", &barnum) == 0) {
2341 ERR("reading execibar value failed (perhaps it's not the correct format?)");
2343 if (barnum > 100 || barnum < 0) {
2344 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
2346 obj->f = 255 * barnum / 100.0;
2347 new_bar(p, 0, 4, (int) obj->f);
2349 obj->data.execi.last_update =
2350 current_update_time;
2354 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2355 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
2358 FILE *fp = popen(obj->data.execi.cmd, "r");
2359 int n2 = fread(p, 1, n, fp);
2362 if (n2 && p[n2 - 1] == '\n')
2371 if (sscanf(p, "%f", &barnum) == 0) {
2372 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
2374 if (barnum > 100 || barnum < 0) {
2375 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
2378 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
2380 obj->data.execi.last_update = current_update_time;
2386 if (current_update_time -
2387 obj->data.execi.last_update <
2388 obj->data.execi.interval) {
2389 snprintf(p, n, "%s",
2390 obj->data.execi.buffer);
2392 char *p2 = obj->data.execi.buffer;
2394 popen(obj->data.execi.cmd,
2397 fread(p2, 1, TEXT_BUFFER_SIZE,
2402 if (n2 && p2[n2 - 1] == '\n')
2411 snprintf(p, n, "%s",
2412 obj->data.execi.buffer);
2414 obj->data.execi.last_update =
2415 current_update_time;
2419 static int running = 0;
2420 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2421 snprintf(p, n, "%s", obj->data.execi.buffer);
2423 static pthread_t execthread;
2426 pthread_create( &execthread, NULL, (void*)threaded_exec, (void*) obj);
2427 pthread_mutex_lock( &mutex1 );
2428 obj->data.execi.last_update = current_update_time;
2429 pthread_mutex_unlock( &mutex1 );
2431 pthread_join( execthread, NULL);
2434 snprintf(p, n, "%s", obj->data.execi.buffer);
2439 if (obj->data.fs != NULL) {
2440 if (obj->data.fs->size == 0)
2459 if (obj->data.fs != NULL)
2460 human_readable(obj->data.fs->avail,
2464 if (obj->data.fs != NULL) {
2465 if (obj->data.fs->size)
2466 snprintf(p, n, "%*d",
2475 snprintf(p, n, "0");
2479 if (obj->data.fs != NULL)
2480 human_readable(obj->data.fs->size,
2484 if (obj->data.fs != NULL)
2485 human_readable(obj->data.fs->size -
2486 obj->data.fs->avail,
2490 if (obj->data.fs != NULL) {
2491 if (obj->data.fs->size == 0)
2509 if (obj->data.fs != NULL) {
2510 if (obj->data.fs->size)
2511 snprintf(p, 4, "%d",
2521 snprintf(p, n, "0");
2525 float *v = info.loadavg;
2527 if (obj->data.loadavg[2])
2528 snprintf(p, n, "%.2f %.2f %.2f",
2529 v[obj->data.loadavg[0] -
2531 v[obj->data.loadavg[1] -
2533 v[obj->data.loadavg[2] -
2535 else if (obj->data.loadavg[1])
2536 snprintf(p, n, "%.2f %.2f",
2537 v[obj->data.loadavg[0] -
2539 v[obj->data.loadavg[1] -
2541 else if (obj->data.loadavg[0])
2542 snprintf(p, n, "%.2f",
2543 v[obj->data.loadavg[0] -
2547 new_hr(p, obj->data.i);
2550 new_offset(p, obj->data.i);
2553 new_voffset(p, obj->data.i);
2558 r = get_i2c_info(&obj->data.i2c.fd,
2560 obj->data.i2c.devtype,
2561 obj->data.i2c.type);
2563 if (r >= 100.0 || r == 0)
2564 snprintf(p, n, "%d", (int) r);
2566 snprintf(p, n, "%.1f", r);
2569 new_alignr(p, obj->data.i);
2572 new_alignc(p, obj->data.i);
2576 if ((obj->data.ifblock.s)
2577 && (stat(obj->data.ifblock.s, &tmp) ==
2579 i = obj->data.ifblock.pos - 2;
2585 if ((obj->data.ifblock.s)
2586 && (!check_mount(obj->data.ifblock.s))) {
2587 i = obj->data.ifblock.pos - 2;
2593 if ((obj->data.ifblock.s)
2594 && system(obj->data.ifblock.s)) {
2595 i = obj->data.ifblock.pos - 2;
2601 snprintf(p, n, "%s", cur->uname_s.release);
2604 snprintf(p, n, "%s", cur->uname_s.machine);
2609 human_readable(cur->mem * 1024, p, 6);
2612 human_readable(cur->memmax * 1024, p, 255);
2617 snprintf(p, n, "%*lu",
2622 snprintf(p, 4, "%*lu ",
2629 new_bar(p, obj->data.pair.a,
2631 cur->memmax ? (cur->mem * 255) /
2636 new_graph(p, obj->a,
2637 obj->b, obj->c, obj->d,
2638 cur->memmax ? (cur->mem * 100.0) /
2639 (cur->memmax) : 0.0, 100, 1);
2643 snprintf(p, n, "%d",
2644 mixer_get_avg(obj->data.l));
2647 snprintf(p, n, "%d",
2648 mixer_get_left(obj->data.l));
2651 snprintf(p, n, "%d",
2652 mixer_get_right(obj->data.l));
2655 new_bar(p, obj->data.mixerbar.w,
2656 obj->data.mixerbar.h,
2657 mixer_get_avg(obj->data.mixerbar.
2661 new_bar(p, obj->data.mixerbar.w,
2662 obj->data.mixerbar.h,
2663 mixer_get_left(obj->data.mixerbar.
2667 new_bar(p, obj->data.mixerbar.w,
2668 obj->data.mixerbar.h,
2669 mixer_get_right(obj->data.mixerbar.
2675 snprintf(p, n, "%d", cur->mail_count);
2678 snprintf(p, n, "%d", cur->new_mail_count);
2681 OBJ(ml_upload_counter) {
2682 snprintf(p, n, "%lld",
2683 mlinfo.upload_counter / 1048576);
2685 OBJ(ml_download_counter) {
2686 snprintf(p, n, "%lld",
2687 mlinfo.download_counter /
2690 OBJ(ml_nshared_files) {
2691 snprintf(p, n, "%i", mlinfo.nshared_files);
2693 OBJ(ml_shared_counter) {
2694 snprintf(p, n, "%lld",
2695 mlinfo.shared_counter / 1048576);
2697 OBJ(ml_tcp_upload_rate) {
2698 snprintf(p, n, "%.2f",
2699 (float) mlinfo.tcp_upload_rate /
2702 OBJ(ml_tcp_download_rate) {
2703 snprintf(p, n, "%.2f",
2704 (float) mlinfo.tcp_download_rate /
2707 OBJ(ml_udp_upload_rate) {
2708 snprintf(p, n, "%.2f",
2709 (float) mlinfo.udp_upload_rate /
2712 OBJ(ml_udp_download_rate) {
2713 snprintf(p, n, "%.2f",
2714 (float) mlinfo.udp_download_rate /
2717 OBJ(ml_ndownloaded_files) {
2718 snprintf(p, n, "%i",
2719 mlinfo.ndownloaded_files);
2721 OBJ(ml_ndownloading_files) {
2722 snprintf(p, n, "%i",
2723 mlinfo.ndownloading_files);
2728 snprintf(p, n, "%s",
2729 cur->uname_s.nodename);
2732 new_outline(p, obj->data.l);
2736 snprintf(p, n, "%d", cur->procs);
2738 snprintf(p, 5, "%d ",
2741 OBJ(running_processes) {
2743 snprintf(p, n, "%d",
2746 snprintf(p, 3, "%d ",
2750 snprintf(p, n, "%s", obj->data.s);
2753 new_bg(p, obj->data.l);
2756 new_stippled_hr(p, obj->data.pair.a,
2760 human_readable(cur->swap * 1024, p, 255);
2763 human_readable(cur->swapmax * 1024, p,
2767 if (cur->swapmax == 0) {
2768 strncpy(p, "No swap", 255);
2771 snprintf(p, 255, "%*lu",
2777 snprintf(p, 4, "%*lu ",
2785 new_bar(p, obj->data.pair.a,
2787 cur->swapmax ? (cur->swap * 255) /
2788 (cur->swapmax) : 0);
2791 snprintf(p, n, "%s", cur->uname_s.sysname);
2794 time_t t = time(NULL);
2795 struct tm *tm = localtime(&t);
2796 setlocale(LC_TIME, "");
2797 strftime(p, n, obj->data.s, tm);
2800 time_t t = time(NULL);
2801 struct tm *tm = gmtime(&t);
2802 strftime(p, n, obj->data.s, tm);
2805 human_readable(obj->data.net->recv, p,
2809 human_readable(obj->data.net->trans, p,
2813 snprintf(p, n, "%d", total_updates);
2817 snprintf(p, n, "%d",
2818 (int) (obj->data.net->
2822 snprintf(p, 5, "%d ",
2823 (int) (obj->data.net->
2829 snprintf(p, n, "%.1f",
2831 trans_speed / 1024.0);
2833 snprintf(p, 8, "%.1f ",
2835 trans_speed / 1024.0);
2838 if (obj->data.net->trans_speed == 0) // this is just to make the ugliness at start go away
2839 obj->data.net->trans_speed = 0.01;
2840 new_graph(p, obj->a, obj->b, obj->c, obj->d,
2841 (obj->data.net->trans_speed /
2842 1024.0), obj->e, 1);
2845 format_seconds_short(p, n,
2849 format_seconds(p, n, (int) cur->uptime);
2852 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
2854 snprintf(p, n, "%s", get_apm_adapter());
2856 OBJ(apm_battery_life) {
2858 msg = get_apm_battery_life();
2859 snprintf(p, n, "%s", msg);
2862 OBJ(apm_battery_time) {
2864 msg = get_apm_battery_time();
2865 snprintf(p, n, "%s", msg);
2868 #endif /* __FreeBSD__ */
2871 snprintf(p, n, "%.2f",
2872 cur->seti_prog * 100.0f);
2875 new_bar(p, obj->data.pair.a,
2877 (int) (cur->seti_prog * 255.0f));
2880 snprintf(p, n, "%.0f", cur->seti_credit);
2886 snprintf(p, n, "%s", cur->mpd.title);
2889 snprintf(p, n, "%s", cur->mpd.artist);
2892 snprintf(p, n, "%s", cur->mpd.album);
2895 snprintf(p, n, "%s", cur->mpd.random);
2898 snprintf(p, n, "%s", cur->mpd.repeat);
2901 snprintf(p, n, "%s", cur->mpd.track);
2904 snprintf(p, n, "%i", cur->mpd.volume);
2907 snprintf(p, n, "%i", cur->mpd.bitrate);
2910 snprintf(p, n, "%s", cur->mpd.status);
2913 int days = 0, hours = 0, minutes =
2915 int tmp = cur->mpd.elapsed;
2916 while (tmp >= 86400) {
2920 while (tmp >= 3600) {
2930 snprintf(p, n, "%i days %i:%02i:%02i",
2931 days, hours, minutes,
2934 snprintf(p, n, "%i:%02i:%02i", hours,
2937 snprintf(p, n, "%i:%02i", minutes,
2941 int days = 0, hours = 0, minutes =
2943 int tmp = cur->mpd.length;
2944 while (tmp >= 86400) {
2948 while (tmp >= 3600) {
2959 "%i days %i:%02i:%02i",
2960 days, hours, minutes,
2963 snprintf(p, n, "%i:%02i:%02i", hours,
2966 snprintf(p, n, "%i:%02i", minutes,
2970 snprintf(p, n, "%2.0f",
2971 cur->mpd.progress * 100);
2974 new_bar(p, obj->data.pair.a,
2976 (int) (cur->mpd.progress *
2981 if (obj->data.top.type == TOP_NAME
2982 && obj->data.top.num >= 0
2983 && obj->data.top.num < 10) {
2984 // if we limit the buffer and add a bunch of space after, it stops the thing from
2985 // moving other shit around, which is really fucking annoying
2986 snprintf(p, 17, "%s ", cur->cpu[obj->data.top.num]->name);
2987 } else if (obj->data.top.type == TOP_CPU
2988 && obj->data.top.num >= 0
2989 && obj->data.top.num < 10) {
2990 snprintf(p, 7, "%3.2f ",
2991 cur->cpu[obj->data.top.
2993 } else if (obj->data.top.type == TOP_PID
2994 && obj->data.top.num >= 0
2995 && obj->data.top.num < 10) {
2996 snprintf(p, 8, "%i ",
2997 cur->cpu[obj->data.top.
2999 } else if (obj->data.top.type == TOP_MEM
3000 && obj->data.top.num >= 0
3001 && obj->data.top.num < 10) {
3002 snprintf(p, 7, "%3.2f ",
3003 cur->cpu[obj->data.top.
3008 if (obj->data.top.type == TOP_NAME
3009 && obj->data.top.num >= 0
3010 && obj->data.top.num < 10) {
3011 // if we limit the buffer and add a bunch of space after, it stops the thing from
3012 // moving other shit around, which is really fucking annoying
3015 cur->memu[obj->data.top.
3017 } else if (obj->data.top.type == TOP_CPU
3018 && obj->data.top.num >= 0
3019 && obj->data.top.num < 10) {
3020 snprintf(p, 7, "%3.2f ",
3021 cur->memu[obj->data.top.
3023 } else if (obj->data.top.type == TOP_PID
3024 && obj->data.top.num >= 0
3025 && obj->data.top.num < 10) {
3026 snprintf(p, 8, "%i ",
3027 cur->memu[obj->data.top.
3029 } else if (obj->data.top.type == TOP_MEM
3030 && obj->data.top.num >= 0
3031 && obj->data.top.num < 10) {
3032 snprintf(p, 7, "%3.2f ",
3033 cur->memu[obj->data.top.
3041 * I'm tired of everything being packed in
3048 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
3049 snprintf(p, n, "%s", obj->data.tail.buffer);
3051 obj->data.tail.last_update = current_update_time;
3055 tailstring *head = NULL;
3056 tailstring *headtmp = NULL;
3057 tailstring *freetmp = NULL;
3058 fp = fopen(obj->data.tail.logfile, "rt");
3060 ERR("tail logfile failed to open");
3063 obj->data.tail.readlines = 0;
3065 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL) {
3072 addtail(&head, obj->data.tail.buffer);
3073 obj->data.tail.readlines++;
3079 if (obj->data.tail.readlines > 0) {
3080 for (i = 0;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
3081 addtail(&headtmp, head->data);
3086 strcpy(obj->data.tail.buffer, headtmp->data);
3087 headtmp = headtmp->next;
3088 for (i = 1;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
3090 strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
3091 headtmp = headtmp->next;
3095 /* get rid of any ugly newlines at the end */
3096 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
3097 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
3099 snprintf(p, n, "%s", obj->data.tail.buffer);
3104 strcpy(obj->data.tail.buffer, "Logfile Empty");
3105 snprintf(p, n, "Logfile Empty");
3111 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
3112 snprintf(p, n, "%s", obj->data.tail.buffer);
3114 obj->data.tail.last_update = current_update_time;
3116 tailstring *head = NULL;
3117 tailstring *headtmp = NULL;
3118 tailstring *freetmp = NULL;
3119 fp = fopen(obj->data.tail.logfile, "rt");
3121 ERR("head logfile failed to open");
3124 obj->data.tail.readlines = 0;
3125 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL && obj->data.tail.readlines <= obj->data.tail.wantedlines) {
3126 addtail(&head, obj->data.tail.buffer);
3127 obj->data.tail.readlines++;
3131 if (obj->data.tail.readlines > 0) {
3133 addtail(&headtmp, head->data);
3138 strcpy(obj->data.tail.buffer, headtmp->data);
3139 headtmp = headtmp->next;
3141 strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
3142 headtmp = headtmp->next;
3145 /* get rid of any ugly newlines at the end */
3146 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
3147 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
3149 snprintf(p, n, "%s", obj->data.tail.buffer);
3152 strcpy(obj->data.tail.buffer, "Logfile Empty");
3153 snprintf(p, n, "Logfile Empty");
3158 #ifdef TCP_PORT_MONITOR
3161 /* grab a pointer to this port monitor */
3162 tcp_port_monitor_t * p_monitor =
3163 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
3164 obj->data.tcp_port_monitor.port_range_begin,
3165 obj->data.tcp_port_monitor.port_range_end );
3167 snprintf(p, n, "monitor not found");
3171 /* now grab the text of interest */
3172 if ( peek_tcp_port_monitor( p_monitor,
3173 obj->data.tcp_port_monitor.item,
3174 obj->data.tcp_port_monitor.connection_index,
3177 snprintf(p, n, "monitor peek error");
3187 unsigned int a = strlen(p);
3193 if (stuff_in_upper_case) {
3203 last_update_time = current_update_time;
3209 static void set_font()
3213 if (window.xftdraw != NULL) {
3214 XftDrawDestroy(window.xftdraw);
3216 window.xftdraw = XftDrawCreate(display, window.drawable,
3217 DefaultVisual(display,
3219 DefaultColormap(display,
3224 XSetFont(display, window.gc, fonts[selected_font].font->fid);
3233 static int text_start_x, text_start_y; /* text start position in window */
3234 static int text_width, text_height;
3238 static inline int get_string_width(const char *s)
3241 return *s ? calc_text_width(s, strlen(s)) : 0;
3247 static inline int get_string_width_special(char *s)
3260 if (*p == SPECIAL_CHAR) {
3261 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
3262 for (i = 0; i < strlen(p); i++) {
3263 *(p + i) = *(p + i + 1);
3265 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
3266 width += specials[special_index+index].width;
3273 if (strlen(final) > 1) {
3274 width += calc_text_width(final, strlen(final));
3286 static void text_size_updater(char *s)
3290 int h = font_height();
3291 /* get string widths and skip specials */
3294 if (*p == SPECIAL_CHAR) {
3296 w += get_string_width(s);
3299 if (specials[special_index].type == BAR
3300 || specials[special_index].type == GRAPH) {
3301 w += specials[special_index].width;
3302 if (specials[special_index].height > h) {
3303 h = specials[special_index].height;
3308 else if (specials[special_index].type == OFFSET) {
3309 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
3311 else if (specials[special_index].type == VOFFSET) {
3312 h += specials[special_index].arg;
3314 else if (specials[special_index].type == FONT) {
3315 fontchange = specials[special_index].font_added;
3316 selected_font = specials[special_index].font_added;
3326 w += get_string_width(s);
3329 if (text_width > maximum_width && maximum_width)
3330 text_width = maximum_width;
3341 static void update_text_area()
3345 /* update text size if it isn't fixed */
3350 text_width = minimum_width;
3353 for_each_line(text_buffer, text_size_updater);
3355 if (text_height < minimum_height)
3356 text_height = minimum_height;
3357 if (text_width > maximum_width && maximum_width > 0)
3358 text_width = maximum_width;
3361 /* get text position on workarea */
3362 switch (text_alignment) {
3369 x = workarea[2] - text_width - gap_x;
3376 y = workarea[3] - text_height - gap_y;
3380 x = workarea[2] - text_width - gap_x;
3381 y = workarea[3] - text_height - gap_y;
3385 case NONE: // Let the WM manage the window
3396 if (own_window && !fixed_pos) {
3399 text_start_x = border_margin + 1;
3400 text_start_y = border_margin + 1;
3401 window.x = x - border_margin - 1;
3402 window.y = y - border_margin - 1;
3406 /* If window size doesn't match to workarea's size, then window
3407 * probably includes panels (gnome).
3408 * Blah, doesn't work on KDE. */
3409 if (workarea[2] != window.width
3410 || workarea[3] != window.height) {
3424 static int cur_x, cur_y; /* current x and y for drawing */
3425 static int draw_mode; /* FG, BG or OUTLINE */
3426 static long current_color;
3428 static inline void set_foreground_color(long c)
3431 XSetForeground(display, window.gc, c);
3435 static void draw_string(const char *s)
3439 int i, i2, pos, width_of_s;
3442 width_of_s = get_string_width(s);
3443 if (out_to_console) {
3446 /* 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 */
3447 strcpy(tmpstring1, s);
3451 snprintf(space, 2, " ");
3453 max = ((text_width - width_of_s) / get_string_width(space));
3456 * This code looks for tabs in the text and coverts them to spaces.
3457 * The trick is getting the correct number of spaces,
3458 * and not going over the window's size without forcing
3459 * the window larger.
3461 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
3462 if (tmpstring1[i] == '\t') // 9 is ascii tab
3466 i2 < (8 - (1 + pos) % 8) && added <= max;
3468 tmpstring2[pos + i2] = ' ';
3473 if (tmpstring1[i] != 9) {
3474 tmpstring2[pos] = tmpstring1[i];
3480 if (text_width == maximum_width) {
3481 /* this means the text is probably pushing the limit, so we'll chop it */
3482 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
3483 tmpstring2[strlen(tmpstring2)-1] = '\0';
3493 c.pixel = current_color;
3494 XQueryColor(display, DefaultColormap(display, screen), &c);
3497 c2.color.red = c.red;
3498 c2.color.green = c.green;
3499 c2.color.blue = c.blue;
3500 c2.color.alpha = fonts[selected_font].font_alpha;
3502 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
3503 cur_x, cur_y, (XftChar8 *) s,
3506 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
3507 cur_x, cur_y, (XftChar8 *) s,
3513 XDrawString(display, window.drawable, window.gc,
3514 cur_x, cur_y, s, strlen(s));
3516 cur_x += width_of_s;
3518 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
3521 long redmask, greenmask, bluemask;
3523 void set_up_gradient()
3526 colour_depth = DisplayPlanes(display, screen);
3530 if (colour_depth != 24 && colour_depth != 16) {
3531 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
3537 for(i = (colour_depth / 3)-1; i>=0; i--) {
3539 greenmask |= 1 << i;
3542 if (colour_depth%3 == 1) {
3543 greenmask |= 1 << (colour_depth / 3);
3545 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
3546 greenmask = greenmask << (colour_depth / 3);
3549 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 */
3551 int red1, green1, blue1; // first colour
3552 int red2, green2, blue2; // second colour
3553 int red3 = 0, green3 = 0, blue3 = 0; // difference
3554 short redshift = (2*colour_depth / 3 + colour_depth%3);
3555 short greenshift = (colour_depth / 3);
3556 red1 = (first_colour & redmask) >> redshift;
3557 green1 = (first_colour & greenmask) >> greenshift;
3558 blue1 = first_colour & bluemask;
3559 red2 = (last_colour & redmask) >> redshift;
3560 green2 = (last_colour & greenmask) >> greenshift;
3561 blue2 = last_colour & bluemask;
3568 if (green1 > green2) {
3571 if (green1 < green2) {
3574 if (blue1 > blue2) {
3577 if (blue1 < blue2) {
3592 if (red1 > bluemask) {
3595 if (green1 > bluemask) {
3598 if (blue1 > bluemask) {
3601 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
3605 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
3606 if (colour_depth == 0) {
3609 int red1, green1, blue1; // first colour
3610 int red2, green2, blue2; // second colour
3611 long redshift = (2*colour_depth / 3 + colour_depth%3);
3612 long greenshift = (colour_depth / 3);
3613 int red3 = 0, green3 = 0, blue3 = 0; // difference
3614 red1 = (first_colour & redmask) >> redshift;
3615 green1 = (first_colour & greenmask) >> greenshift;
3616 blue1 = first_colour & bluemask;
3617 red2 = (last_colour & redmask) >> redshift;
3618 green2 = (last_colour & greenmask) >> greenshift;
3619 blue2 = last_colour & bluemask;
3620 red3 = abs(red1 - red2);
3621 green3 = abs(green1 - green2);
3622 blue3 = abs(blue1 - blue2);
3631 static void draw_line(char *s)
3635 cur_x = text_start_x;
3636 cur_y += font_ascent();
3638 short font_h = font_height();
3640 /* find specials and draw stuff */
3643 if (*p == SPECIAL_CHAR) {
3646 /* draw string before special */
3653 switch (specials[special_index].type) {
3654 case HORIZONTAL_LINE:
3657 specials[special_index].height;
3658 int mid = font_ascent() / 2;
3659 w = text_start_x + text_width -
3662 XSetLineAttributes(display,
3667 XDrawLine(display, window.drawable,
3678 specials[special_index].height;
3680 specials[special_index].arg;
3681 int mid = font_ascent() / 2;
3682 char ss[2] = { s, s };
3683 w = text_start_x + text_width -
3686 XSetLineAttributes(display,
3691 XSetDashes(display, window.gc, 0,
3693 XDrawLine(display, window.drawable,
3703 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
3707 specials[special_index].height;
3709 specials[special_index].arg;
3714 by = cur_y - (font_ascent() + h) / 2 - 1;
3718 by = cur_y - (font_ascent()/2) - 1;
3720 if (h < (font_height())) {
3723 w = specials[special_index].width;
3726 text_width - cur_x - 1;
3730 XSetLineAttributes(display,
3736 XDrawRectangle(display,
3740 XFillRectangle(display,
3744 w * bar_usage / 255,
3746 if (specials[special_index].
3748 && specials[special_index].
3752 [special_index].height;
3759 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
3763 specials[special_index].height;
3767 by = cur_y - (font_ascent() + h) / 2 - 1;
3771 by = cur_y - (font_ascent()/2) - 1;
3773 if (h < (font_height())) {
3776 w = specials[special_index].width;
3778 w = text_start_x + text_width - cur_x - 1;
3781 XSetLineAttributes(display,
3786 XDrawRectangle(display,
3790 XSetLineAttributes(display,
3797 int gradient_size = 0;
3798 float gradient_factor = 0;
3799 float gradient_update = 0;
3800 unsigned long tmpcolour = current_color;
3801 if (specials[special_index].first_colour != specials[special_index].last_colour) {
3802 tmpcolour = specials[special_index].first_colour;
3803 gradient_size = gradient_max(specials[special_index].first_colour, specials[special_index].last_colour);
3804 gradient_factor = (float)gradient_size / (w - 3);
3806 for (i = 0; i < w - 3; i++) {
3807 if (specials[special_index].first_colour != specials[special_index].last_colour) {
3808 XSetForeground(display, window.gc, tmpcolour);
3809 gradient_update += gradient_factor;
3810 while (gradient_update > 0) {
3811 tmpcolour = do_gradient(tmpcolour, specials[special_index].last_colour);
3815 if (i / ((float) (w - 3) / (specials[special_index].graph_width)) > j) {
3818 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 */
3820 if (specials[special_index].
3822 && specials[special_index].
3826 [special_index].height;
3829 if (draw_mode == BG) {
3830 set_foreground_color(default_bg_color);
3832 else if (draw_mode == OUTLINE) {
3833 set_foreground_color(default_out_color);
3835 set_foreground_color(default_fg_color);
3841 cur_y -= font_ascent();
3842 selected_font = specials[special_index].font_added;
3843 cur_y += font_ascent();
3845 if (!use_xft || use_xdbe)
3853 if (draw_mode == FG)
3854 set_foreground_color(specials
3860 if (draw_mode == BG)
3861 set_foreground_color(specials
3867 if (draw_mode == OUTLINE)
3868 set_foreground_color(specials
3875 w += specials[special_index].arg;
3880 cur_y += specials[special_index].arg;
3886 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
3887 /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i border_margin %i border_width %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width_special(s), gap_x, specials[special_index].arg, border_margin, border_width);*/
3888 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
3889 cur_x = pos_x - specials[special_index].arg;
3896 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
3897 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
3898 /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width(s), gap_x, specials[special_index].arg);*/
3900 specials[special_index].arg)
3903 [special_index].arg;
3920 if (cur_y_add > 0) {
3922 cur_y -= font_descent();
3927 cur_y += font_descent();
3934 static void draw_text()
3937 cur_y = text_start_y;
3940 if (draw_borders && border_width > 0) {
3941 unsigned int b = (border_width + 1) / 2;
3943 if (stippled_borders) {
3945 { stippled_borders, stippled_borders };
3946 XSetLineAttributes(display, window.gc,
3947 border_width, LineOnOffDash,
3948 CapButt, JoinMiter);
3949 XSetDashes(display, window.gc, 0, ss, 2);
3951 XSetLineAttributes(display, window.gc,
3952 border_width, LineSolid,
3953 CapButt, JoinMiter);
3956 XDrawRectangle(display, window.drawable, window.gc,
3957 text_start_x - border_margin + b,
3958 text_start_y - border_margin + b,
3959 text_width + border_margin * 2 - 1 - b * 2,
3960 text_height + border_margin * 2 - 1 -
3967 for_each_line(text_buffer, draw_line);
3970 static void draw_stuff()
3973 if (draw_shades && !draw_outline) {
3976 set_foreground_color(default_bg_color);
3985 for (i = -1; i < 2; i++)
3986 for (j = -1; j < 2; j++) {
3987 if (i == 0 && j == 0)
3991 set_foreground_color(default_out_color);
3992 draw_mode = OUTLINE;
3999 set_foreground_color(default_fg_color);
4007 swap.swap_window = window.window;
4008 swap.swap_action = XdbeBackground;
4009 XdbeSwapBuffers(display, &swap, 1);
4015 static void clear_text(int exposures)
4019 return; /* The swap action is XdbeBackground, which clears */
4023 /* there is some extra space for borders and outlines */
4024 XClearArea(display, window.drawable,
4025 text_start_x - border_margin - 1,
4026 text_start_y - border_margin - 1,
4027 text_width + border_margin * 2 + 2,
4028 text_height + border_margin * 2 + 2,
4029 exposures ? True : 0);
4034 static int need_to_update;
4036 /* update_text() generates new text and clears old text area */
4037 static void update_text()
4046 static void main_loop()
4049 Region region = XCreateRegion();
4053 while (total_run_times == 0 || info.looped < total_run_times - 1) {
4058 /* wait for X event or timeout */
4060 if (!XPending(display)) {
4065 update_interval - (get_time() -
4071 tv.tv_sec = (long) t;
4072 tv.tv_usec = (long) (t * 1000000) % 1000000;
4074 FD_SET(ConnectionNumber(display), &fdsr);
4077 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
4080 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
4085 ERR("can't select(): %s",
4096 set_transparent_background(window.window);
4101 if (need_to_update) {
4103 int wx = window.x, wy = window.y;
4111 /* resize window if it isn't right size */
4113 (text_width + border_margin * 2 !=
4115 || text_height + border_margin * 2 !=
4119 border_margin * 2 + 1;
4122 border_margin * 2 + 1;
4123 XResizeWindow(display,
4129 /* move window if it isn't in right position */
4132 || window.y != wy)) {
4133 XMoveWindow(display, window.window,
4134 window.x, window.y);
4144 r.x = text_start_x - border_margin;
4145 r.y = text_start_y - border_margin;
4146 r.width = text_width + border_margin * 2;
4147 r.height = text_height + border_margin * 2;
4148 XUnionRectWithRegion(&r, region, region);
4153 /* handle X events */
4155 while (XPending(display)) {
4157 XNextEvent(display, &ev);
4164 r.width = ev.xexpose.width;
4165 r.height = ev.xexpose.height;
4166 XUnionRectWithRegion(&r, region,
4172 case ReparentNotify:
4173 /* set background to ParentRelative for all parents */
4175 set_transparent_background(window.
4180 case ConfigureNotify:
4182 /* if window size isn't what expected, set fixed size */
4183 if (ev.xconfigure.width !=
4185 || ev.xconfigure.height !=
4187 if (window.width != 0
4188 && window.height != 0)
4191 /* clear old stuff before screwing up size and pos */
4197 if (XGetWindowAttributes(display, window.window, &attrs)) {
4212 border_margin * 2 - 1;
4215 border_margin * 2 - 1;
4216 if (text_width > maximum_width && maximum_width > 0)
4217 text_width = maximum_width;
4220 /* if position isn't what expected, set fixed pos, total_updates
4221 * avoids setting fixed_pos when window is set to weird locations
4223 /*if (total_updates >= 2 this is broken
4225 && (window.x != ev.xconfigure.x
4228 && (ev.xconfigure.x != 0
4229 || ev.xconfigure.y != 0)) {
4242 /* XDBE doesn't seem to provide a way to clear the back buffer without
4243 * interfering with the front buffer, other than passing XdbeBackground
4244 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
4245 * redraw the text even if it wasn't part of the exposed area. OTOH,
4246 * if we're not going to call draw_stuff at all, then no swap happens
4247 * and we can safely do nothing.
4250 if (!XEmptyRegion(region)) {
4254 r.x = text_start_x - border_margin;
4255 r.y = text_start_y - border_margin;
4256 r.width = text_width + border_margin * 2;
4257 r.height = text_height + border_margin * 2;
4258 XUnionRectWithRegion(&r, region, region);
4261 XSetRegion(display, window.gc, region);
4264 XftDrawSetClip(window.xftdraw, region);
4270 XDestroyRegion(region);
4271 region = XCreateRegion();
4275 /* inspect pending signal prior to entering next loop */
4276 switch(g_signal_pending) {
4279 ERR("received SIGUSR1. reloading the config file.");
4286 ERR("received SIGINT or SIGTERM to terminate. bye!");
4289 XDestroyRegion(region);
4292 return; /* return from main_loop */
4297 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
4298 * but didn't write any code to deal with it. if you don't want to
4299 * handle a signal, don't set a handler on it in the first place. */
4300 if (g_signal_pending)
4301 ERR("ignoring signal (%d)", g_signal_pending);
4309 XDestroyRegion(region);
4314 static void load_config_file(const char *);
4316 /* reload the config file */
4317 void reload_config(void)
4319 if (current_config) {
4321 load_config_file(current_config);
4325 XClearWindow(display, RootWindow(display, screen)); // clear the window first
4328 #ifdef TCP_PORT_MONITOR
4329 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
4330 info.p_tcp_port_monitor_collection = NULL;
4332 extract_variable_text(text);
4344 XdbeDeallocateBackBufferName(display, window.back_buffer);
4349 XDestroyWindow(display, window.window);
4353 XClearWindow(display, RootWindow(display, screen));
4358 XFreeGC(display, window.gc);
4362 /* it is really pointless to free() memory at the end of program but ak|ra
4363 * wants me to do this */
4365 free_text_objects();
4367 if (text != original_text)
4370 free(current_config);
4371 free(current_mail_spool);
4375 #ifdef TCP_PORT_MONITOR
4376 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
4377 info.p_tcp_port_monitor_collection = NULL;
4381 static int string_to_bool(const char *s)
4385 if (strcasecmp(s, "yes") == 0)
4387 if (strcasecmp(s, "true") == 0)
4389 if (strcasecmp(s, "1") == 0)
4394 static enum alignment string_to_alignment(const char *s)
4396 if (strcasecmp(s, "top_left") == 0)
4398 else if (strcasecmp(s, "top_right") == 0)
4400 else if (strcasecmp(s, "bottom_left") == 0)
4402 else if (strcasecmp(s, "bottom_right") == 0)
4403 return BOTTOM_RIGHT;
4404 else if (strcasecmp(s, "tl") == 0)
4406 else if (strcasecmp(s, "tr") == 0)
4408 else if (strcasecmp(s, "bl") == 0)
4410 else if (strcasecmp(s, "br") == 0)
4411 return BOTTOM_RIGHT;
4412 else if (strcasecmp(s, "none") == 0)
4419 static void set_default_configurations(void)
4421 fork_to_background = 0;
4422 total_run_times = 0;
4423 info.cpu_avg_samples = 2;
4424 info.net_avg_samples = 2;
4429 strcpy(info.mpd.host, "localhost");
4430 info.mpd.port = 6600;
4431 info.mpd.status = "Checking status...";
4440 default_fg_color = WhitePixel(display, screen);
4441 default_bg_color = BlackPixel(display, screen);
4442 default_out_color = BlackPixel(display, screen);
4446 set_first_font("6x10");
4454 strcpy(wm_class_name, "conky");
4456 stippled_borders = 0;
4459 text_alignment = BOTTOM_LEFT;
4463 free(current_mail_spool);
4466 variable_substitute(MAIL_FILE, buf, 256);
4468 current_mail_spool = strdup(buf);
4472 update_interval = 10.0;
4473 stuff_in_upper_case = 0;
4475 mlconfig.mldonkey_hostname = strdup("127.0.0.1");
4476 mlconfig.mldonkey_port = 4001;
4477 mlconfig.mldonkey_login = NULL;
4478 mlconfig.mldonkey_password = NULL;
4482 static void load_config_file(const char *f)
4484 #define CONF_ERR ERR("%s: %d: config file error", f, line)
4488 set_default_configurations();
4490 fp = open_file(f, 0);
4495 char buf[256], *p, *p2, *name, *value;
4497 if (fgets(buf, 256, fp) == NULL)
4502 /* break at comment */
4503 p2 = strchr(p, '#');
4508 while (*p && isspace((int) *p))
4511 continue; /* empty line */
4517 while (*p2 && !isspace((int) *p2))
4520 *p2 = '\0'; /* break at name's end */
4527 while (*p && isspace((int) *p))
4532 p2 = value + strlen(value);
4533 while (isspace((int) *(p2 - 1)))
4539 #define CONF2(a) if (strcasecmp(name, a) == 0)
4540 #define CONF(a) else CONF2(a)
4541 #define CONF3(a,b) \
4542 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
4546 CONF2("alignment") {
4548 int a = string_to_alignment(value);
4558 on_bottom = string_to_bool(value);
4562 CONF("background") {
4563 fork_to_background = string_to_bool(value);
4567 CONF2("background") {
4568 fork_to_background = string_to_bool(value);
4572 CONF("border_margin") {
4574 border_margin = strtol(value, 0, 0);
4578 CONF("border_width") {
4580 border_width = strtol(value, 0, 0);
4584 CONF("default_color") {
4586 default_fg_color = get_x11_color(value);
4590 CONF3("default_shade_color", "default_shadecolor") {
4592 default_bg_color = get_x11_color(value);
4596 CONF3("default_outline_color", "default_outlinecolor") {
4598 default_out_color = get_x11_color(value);
4606 strcpy(info.mpd.host, value);
4612 info.mpd.port = strtol(value, 0, 0);
4613 if (info.mpd.port < 1
4614 || info.mpd.port > 0xffff)
4619 CONF("cpu_avg_samples") {
4621 cpu_avg_samples = strtol(value, 0, 0);
4622 if (cpu_avg_samples < 1
4623 || cpu_avg_samples > 14)
4632 CONF("net_avg_samples") {
4634 net_avg_samples = strtol(value, 0, 0);
4635 if (net_avg_samples < 1
4636 || net_avg_samples > 14)
4652 CONF("double_buffer") {
4653 use_xdbe = string_to_bool(value);
4657 CONF("override_utf8_locale") {
4658 utf8_mode = string_to_bool(value);
4661 CONF("draw_borders") {
4662 draw_borders = string_to_bool(value);
4664 CONF("draw_shades") {
4665 draw_shades = string_to_bool(value);
4667 CONF("draw_outline") {
4668 draw_outline = string_to_bool(value);
4671 CONF("out_to_console") {
4672 out_to_console = string_to_bool(value);
4674 CONF("use_spacer") {
4675 use_spacer = string_to_bool(value);
4680 use_xft = string_to_bool(value);
4685 set_first_font(value);
4691 if (value && font_count >= 0)
4692 fonts[0].font_alpha = atof(value)
4700 if (string_to_bool(value))
4701 ERR("Xft not enabled");
4704 /* xftfont silently ignored when no Xft */
4707 /* xftalpha is silently ignored when no Xft */
4712 set_first_font(value);
4718 gap_x = atoi(value);
4724 gap_y = atoi(value);
4729 CONF("mail_spool") {
4732 variable_substitute(value, buf, 256);
4736 if (current_mail_spool)
4737 free(current_mail_spool);
4738 current_mail_spool = strdup(buf);
4744 CONF("minimum_size") {
4747 (value, "%d %d", &minimum_width,
4748 &minimum_height) != 2)
4751 &minimum_width) != 1)
4756 CONF("maximum_width") {
4758 if (sscanf(value, "%d", &maximum_width) != 1)
4764 CONF("no_buffers") {
4765 no_buffers = string_to_bool(value);
4768 CONF("mldonkey_hostname") {
4770 if (mlconfig.mldonkey_hostname != NULL) {
4771 free(mlconfig.mldonkey_hostname);
4773 mlconfig.mldonkey_hostname = strdup(value);
4778 CONF("mldonkey_port") {
4780 mlconfig.mldonkey_port = atoi(value);
4784 CONF("mldonkey_login") {
4786 if (mlconfig.mldonkey_login != NULL) {
4787 free(mlconfig.mldonkey_login);
4789 mlconfig.mldonkey_login = strdup(value);
4794 CONF("mldonkey_password") {
4796 if (mlconfig.mldonkey_password != NULL) {
4797 free(mlconfig.mldonkey_password);
4799 mlconfig.mldonkey_password = strdup(value);
4805 CONF("pad_percents") {
4806 pad_percents = atoi(value);
4810 CONF("own_window") {
4811 own_window = string_to_bool(value);
4813 CONF("wm_class_name") {
4814 strncpy(wm_class_name, value, sizeof(wm_class_name)-1);
4815 wm_class_name[sizeof(wm_class_name)-1] = 0;
4817 CONF("own_window_transparent") {
4818 set_transparent = string_to_bool(value);
4820 CONF("own_window_colour") {
4821 background_colour = get_x11_color(value);
4824 CONF("stippled_borders") {
4826 stippled_borders = strtol(value, 0, 0);
4828 stippled_borders = 4;
4832 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
4835 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
4837 CONF("update_interval") {
4839 update_interval = strtod(value, 0);
4843 CONF("total_run_times") {
4845 total_run_times = strtod(value, 0);
4850 stuff_in_upper_case = string_to_bool(value);
4855 malloc(strlen(value)
4857 strcpy(seti_dir, value);
4861 if (text != original_text)
4871 int l = strlen(text);
4872 if (fgets(buf, 256, fp) == NULL)
4875 realloc(text, l + strlen(buf)
4879 if (strlen(text) > 1024 * 8)
4886 ERR("%s: %d: no such configuration: '%s'", f, line, name);
4896 /* : means that character before that takes an argument */
4897 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
4910 int main(int argc, char **argv)
4913 memset(&info, 0, sizeof(info) );
4915 /* handle command line parameters that don't change configs */
4921 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
4922 *s) || ((s = getenv("LANG")) && *s)) {
4924 for(x = 0; x < strlen(s) ; x++) {
4925 temp[x] = tolower(s[x]);
4927 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
4931 if (!setlocale(LC_CTYPE, "")) {
4932 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
4936 int c = getopt(argc,
4946 ("Conky " VERSION " compiled " __DATE__ "\n");
4950 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
4951 * though free() does the NULL check itself;), then load optarg value */
4953 free(current_config);
4954 current_config = strdup(optarg);
4959 ("Usage: %s [OPTION]...\n"
4960 "Conky is a system monitor that renders text on desktop or to own transparent\n"
4961 "window. Command line options will override configurations defined in config\n"
4964 " -c FILE config file to load instead of "
4967 " -d daemonize, fork to background\n"
4970 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
4971 " -f FONT font to use\n"
4973 " -o create own window to draw\n"
4976 " -b double buffer (prevents flickering)\n"
4978 " -w WIN_ID window id to draw\n"
4979 " -x X x position\n"
4980 " -y Y y position\n"
4982 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
4983 " -u SECS update interval\n"
4984 " -i NUM number of times to update Conky\n", argv[0]);
4988 window.window = strtol(optarg, 0, 0);
4997 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
5001 tmpstring1 = (char *)
5002 malloc(TEXT_BUFFER_SIZE);
5003 tmpstring2 = (char *)
5004 malloc(TEXT_BUFFER_SIZE);
5006 /* load current_config or CONFIG_FILE */
5009 if (current_config == NULL) {
5010 /* load default config file */
5013 variable_substitute(CONFIG_FILE, buf, 256);
5016 current_config = strdup(buf);
5020 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
5021 load_config_file(current_config);
5023 set_default_configurations();
5027 if (current_mail_spool == NULL) {
5029 variable_substitute(MAIL_FILE, buf, 256);
5032 current_mail_spool = strdup(buf);
5036 /* handle other command line arguments */
5038 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
5039 optind = optreset = 1;
5045 int c = getopt(argc,
5053 fork_to_background = 1;
5058 set_first_font(optarg);
5061 text_alignment = string_to_alignment(optarg);
5076 if (text != original_text)
5078 text = strdup(optarg);
5079 convert_escapes(text);
5083 update_interval = strtod(optarg, 0);
5087 total_run_times = strtod(optarg, 0);
5091 gap_x = atoi(optarg);
5095 gap_y = atoi(optarg);
5109 /* generate text and get initial size */
5110 extract_variable_text(text);
5111 if (text != original_text) {
5120 update_text_area(); /* to get initial size of the window */
5122 #if defined OWN_WINDOW
5126 text_width + border_margin * 2 + 1,
5127 text_height + border_margin * 2 + 1,
5128 on_bottom, fixed_pos, set_transparent, background_colour);
5132 text_width + border_margin * 2 + 1,
5133 text_height + border_margin * 2 + 1,
5134 on_bottom, set_transparent, background_colour);
5138 update_text_area(); /* to position text/window on screen */
5142 // why the fuck not?
5148 if (own_window && !fixed_pos) {
5149 XMoveWindow(display, window.window, window.x, window.y);
5152 set_transparent_background(window.window);
5163 if (fork_to_background) {
5167 ERR("can't fork() to background: %s",
5177 "Conky: forked to background, pid is %d\n",
5183 /* Set signal handlers */
5184 if ( signal(SIGINT,signal_handler) == SIG_ERR ||
5185 signal(SIGUSR1,signal_handler) == SIG_ERR ||
5186 signal(SIGTERM,signal_handler) == SIG_ERR )
5188 ERR("error setting signal handler: %s", strerror(errno) );
5197 void signal_handler(int sig)
5199 /* signal handler is light as a feather, as it should be.
5200 * we will poll g_signal_pending with each loop of conky
5201 * and do any signal processing there, NOT here. pkovacs. */
5202 g_signal_pending=sig;