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 /* fixed size/pos is set if wm/user changes them */
243 static int fixed_size = 0, fixed_pos = 0;
246 static int minimum_width, minimum_height;
247 static int maximum_width;
254 /* no buffers in used memory? */
257 /* pad percentages to decimals? */
258 static int pad_percents = 0;
260 /* Text that is shown */
261 static char original_text[] =
262 "$nodename - $sysname $kernel on $machine\n"
264 "${color grey}Uptime:$color $uptime\n"
265 "${color grey}Frequency (in MHz):$color $freq\n"
266 "${color grey}Frequency (in GHz):$color $freq_g\n"
267 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
268 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
269 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
270 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
272 "${color grey}File systems:\n"
273 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
274 "${color grey}Networking:\n"
275 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
276 "${color grey}Temperatures:\n"
277 " CPU:$color ${i2c temp 1}°C${color grey} - MB:$color ${i2c temp 2}°C\n"
280 "${color grey}SETI@Home Statistics:\n"
281 "${color grey}Seti Unit Number:$color $seti_credit\n"
282 "${color grey}Seti Progress:$color $seti_prog% $seti_progbar\n"
285 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
286 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
288 "${color grey}Name PID CPU% MEM%\n"
289 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
290 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
291 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
292 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
293 "${tail /var/log/Xorg.0.log 3}";
295 static char *text = original_text;
297 static int total_updates;
300 static int blockdepth = 0;
301 static int if_jumped = 0;
302 static int blockstart[MAX_IF_BLOCK_DEPTH];
304 int check_mount(char *s)
306 #if defined(__linux__)
308 FILE *mtab = fopen("/etc/mtab", "r");
310 char buf1[256], buf2[128];
311 while (fgets(buf1, 256, mtab)) {
312 sscanf(buf1, "%*s %128s", buf2);
313 if (!strcmp(s, buf2)) {
320 ERR("Could not open mtab");
323 #elif defined(__FreeBSD__)
324 struct statfs *mntbuf;
327 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
328 for (i = mntsize - 1; i >= 0; i--)
329 if (strcmp(mntbuf[i].f_mntonname, s) == 0)
338 static inline int calc_text_width(const char *s, unsigned int l)
344 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, s, l, &gi);
346 XftTextExtents8(display, fonts[selected_font].xftfont, s, l, &gi);
352 return XTextWidth(fonts[selected_font].font, s, l);
357 /* formatted text to render on screen, generated in generate_text(),
358 * drawn in draw_stuff() */
360 static char text_buffer[TEXT_BUFFER_SIZE * 4];
362 /* special stuff in text_buffer */
364 #define SPECIAL_CHAR '\x01'
381 static struct special_t {
391 unsigned long first_colour; // for graph gradient
392 unsigned long last_colour;
395 static int special_count;
397 static int special_index; /* used when drawing */
400 #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? */
402 static struct special_t *new_special(char *buf, int t)
404 if (special_count >= 128)
405 CRIT_ERR("too many special things in text");
407 buf[0] = SPECIAL_CHAR;
409 specials[special_count].type = t;
410 return &specials[special_count++];
413 typedef struct tailstring_list {
414 char data[TEXT_BUFFER_SIZE];
415 struct tailstring_list *next;
416 struct tailstring_list *first;
419 void addtail(tailstring ** head, char *data_in)
422 if ((tmp = malloc(sizeof(*tmp))) == NULL) {
428 tmp->first = (*head)->first;
430 strncpy(tmp->data, data_in, TEXT_BUFFER_SIZE);
435 void freetail(tailstring * head)
438 while (head != NULL) {
445 void freelasttail(tailstring * head)
447 tailstring * tmp = head;
449 if (tmp->next == head->first) {
456 while(head != NULL && tmp != NULL) {
462 static void new_bar(char *buf, int w, int h, int usage)
464 struct special_t *s = new_special(buf, BAR);
465 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
470 static const char *scan_bar(const char *args, int *w, int *h)
472 *w = 0; /* zero width means all space that is available */
474 /* bar's argument is either height or height,width */
477 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
478 sscanf(args, "%d %n", h, &n);
485 static char *scan_font(const char *args)
487 if (args && sizeof(args) < 127) {
491 ERR("font scan failed, lets hope it doesn't mess stuff up");
497 static void new_font(char *buf, char * args) {
498 struct special_t *s = new_special(buf, FONT);
499 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
500 int tmp = selected_font;
501 selected_font = s->font_added = addfont(args);
509 inline void graph_append(struct special_t *graph, double f)
511 if (!graph->scaled && f > graph->graph_scale) {
512 f = graph->graph_scale;
516 graph->graph_scale = 1;
518 graph->graph[graph->graph_width - 1] = f; /* add new data */
519 for (i = 0; i < graph->graph_width - 1; i++) { /* shift all the data by 1 */
520 graph->graph[i] = graph->graph[i + 1];
521 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
522 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
527 short colour_depth = 0;
528 void set_up_gradient();
530 /* precalculated: 31/255, and 63/255 */
531 #define CONST_8_TO_5_BITS 0.12156862745098
532 #define CONST_8_TO_6_BITS 0.247058823529412
534 /* adjust color values depending on color depth*/
535 static unsigned int adjust_colors(unsigned int color)
538 if (colour_depth == 0) {
541 if (colour_depth == 16) {
542 r = (color & 0xff0000) >> 16;
543 g = (color & 0xff00) >> 8;
545 color = (int)(r * CONST_8_TO_5_BITS) << 11;
546 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
547 color |= (int)(b * CONST_8_TO_5_BITS);
552 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
554 struct special_t *s = new_special(buf, GRAPH);
556 if (s->graph == NULL) {
557 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
558 s->graph_width = s->width - 3; // subtract 3 for the box
560 s->graph_width = MAX_GRAPH_DEPTH - 3;
562 s->graph = malloc(s->graph_width * sizeof(double));
563 memset(s->graph, 0, s->graph_width * sizeof(double));
564 s->graph_scale = 100;
567 s->first_colour = adjust_colors(first_colour);
568 s->last_colour = adjust_colors(second_colour);
575 s->graph_width = s->width - 3; // subtract 3 for rectangle around
580 s->graph_scale = scale;
587 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
589 *w = 0; /* zero width means all space that is available */
593 /* graph's argument is either height or height,width */
595 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
596 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
598 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
600 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
603 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
607 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
610 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
614 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
617 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
621 if (sscanf(args, "%d,%d", h, w) < 2) {
624 sscanf(args, "%*s %d,%d", h, w);
630 static inline void new_hr(char *buf, int a)
632 new_special(buf, HORIZONTAL_LINE)->height = a;
635 static inline void new_stippled_hr(char *buf, int a, int b)
637 struct special_t *s = new_special(buf, STIPPLED_HR);
642 static inline void new_fg(char *buf, long c)
644 new_special(buf, FG)->arg = c;
647 static inline void new_bg(char *buf, long c)
649 new_special(buf, BG)->arg = c;
652 static inline void new_outline(char *buf, long c)
654 new_special(buf, OUTLINE)->arg = c;
657 static inline void new_offset(char *buf, long c)
659 new_special(buf, OFFSET)->arg = c;
662 static inline void new_voffset(char *buf, long c)
664 new_special(buf, VOFFSET)->arg = c;
667 static inline void new_alignr(char *buf, long c)
669 new_special(buf, ALIGNR)->arg = c;
672 static inline void new_alignc(char *buf, long c)
674 new_special(buf, ALIGNC)->arg = c;
677 /* quite boring functions */
679 static inline void for_each_line(char *b, void (*f) (char *))
683 for (ps = b, pe = b; *pe; pe++) {
696 static void convert_escapes(char *buf)
698 char *p = buf, *s = buf;
714 /* converts from bytes to human readable format (k, M, G, T) */
715 static void human_readable(long long a, char *buf, int size)
717 // Strange conditional due to possible overflows
718 if(a / 1024 / 1024 / 1024.0 > 1024.0){
719 snprintf(buf, size, "%.2fT", (a / 1024 / 1024 / 1024) / 1024.0);
721 else if (a >= 1024 * 1024 * 1024) {
722 snprintf(buf, size, "%.2fG", (a / 1024 / 1024) / 1024.0);
724 else if (a >= 1024 * 1024) {
725 double m = (a / 1024) / 1024.0;
727 snprintf(buf, size, "%.0fM", m);
729 snprintf(buf, size, "%.1fM", m);
730 } else if (a >= 1024)
731 snprintf(buf, size, "%Ldk", a / (long long) 1024);
733 snprintf(buf, size, "%Ld", a);
738 enum text_object_type {
786 #if defined(__linux__)
792 OBJ_i8k_left_fan_status,
793 OBJ_i8k_right_fan_status,
794 OBJ_i8k_left_fan_rpm,
795 OBJ_i8k_right_fan_rpm,
797 OBJ_i8k_buttons_status,
798 #endif /* __linux__ */
825 OBJ_ml_upload_counter,
826 OBJ_ml_download_counter,
827 OBJ_ml_nshared_files,
828 OBJ_ml_shared_counter,
829 OBJ_ml_tcp_upload_rate,
830 OBJ_ml_tcp_download_rate,
831 OBJ_ml_udp_upload_rate,
832 OBJ_ml_udp_download_rate,
833 OBJ_ml_ndownloaded_files,
834 OBJ_ml_ndownloading_files,
837 OBJ_running_processes,
846 OBJ_temp1, /* i2c is used instead in these */
859 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
861 OBJ_apm_battery_time,
862 OBJ_apm_battery_life,
863 #endif /* __FreeBSD__ */
891 unsigned int c, d, e;
894 char *s; /* some string */
895 int i; /* some integer */
896 long l; /* some other integer */
897 struct net_stat *net;
899 unsigned char loadavg[3];
900 //unsigned int diskio;
901 unsigned int cpu_index;
950 static unsigned int text_object_count;
951 static struct text_object *text_objects;
953 pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
955 void *threaded_exec( struct text_object *obj ) {
956 char *p2 = obj->data.execi.buffer;
957 FILE *fp = popen(obj->data.execi.cmd,"r");
958 pthread_mutex_lock( &mutex1 );
959 int n2 = fread(p2, 1, TEXT_BUFFER_SIZE, fp);
962 if (n2 && p2[n2 - 1] == '\n')
970 pthread_mutex_unlock( &mutex1 );
974 /* new_text_object() allocates a new zeroed text_object */
975 static struct text_object *new_text_object()
978 text_objects = (struct text_object *) realloc(text_objects,
982 memset(&text_objects[text_object_count - 1], 0,
983 sizeof(struct text_object));
985 return &text_objects[text_object_count - 1];
988 static void free_text_objects()
991 for (i = 0; i < text_object_count; i++) {
992 switch (text_objects[i].type) {
994 close(text_objects[i].data.i);
997 close(text_objects[i].data.i);
1000 close(text_objects[i].data.i2c.fd);
1004 case OBJ_if_existing:
1005 case OBJ_if_mounted:
1006 case OBJ_if_running:
1007 free(text_objects[i].data.ifblock.s);
1010 free(text_objects[i].data.tail.logfile);
1011 free(text_objects[i].data.tail.buffer);
1015 free(text_objects[i].data.s);
1018 free(text_objects[i].data.s);
1021 free(text_objects[i].data.s);
1024 free(text_objects[i].data.s);
1026 /* case OBJ_execibar:
1027 free(text_objects[i].data.s);
1029 case OBJ_execigraph:
1030 free(text_objects[i].data.s);
1034 case OBJ_mpd_artist:
1036 case OBJ_mpd_random:
1037 case OBJ_mpd_repeat:
1039 case OBJ_mpd_status:
1044 free(text_objects[i].data.s);
1048 free(text_objects[i].data.execi.cmd);
1049 free(text_objects[i].data.execi.buffer);
1052 free(text_objects[i].data.execi.cmd);
1053 free(text_objects[i].data.execi.buffer);
1059 text_objects = NULL;
1060 text_object_count = 0;
1063 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1068 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1069 *a = mixer_init(buf1);
1070 (void) scan_bar(arg + n, w, h);
1073 (void) scan_bar(arg, w, h);
1077 /* construct_text_object() creates a new text_object */
1078 static void construct_text_object(const char *s, const char *arg)
1080 struct text_object *obj = new_text_object();
1082 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
1083 #define END ; } } else
1087 obj->type = OBJ_color;
1088 obj->data.l = get_x11_color(s);
1091 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
1092 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
1093 END OBJ(acpiacadapter, 0)
1096 END OBJ(freq_dyn, 0);
1097 END OBJ(freq_dyn_g, 0);
1098 END OBJ(acpifan, 0);
1099 END OBJ(battery, 0);
1102 sscanf(arg, "%63s", bat);
1104 strcpy(bat, "BAT0");
1105 obj->data.s = strdup(bat);
1106 #if defined(__linux__)
1107 END OBJ(i8k_version, INFO_I8K)
1108 END OBJ(i8k_bios, INFO_I8K)
1109 END OBJ(i8k_serial, INFO_I8K)
1110 END OBJ(i8k_cpu_temp, INFO_I8K)
1111 END OBJ(i8k_cpu_tempf, INFO_I8K)
1112 END OBJ(i8k_left_fan_status, INFO_I8K)
1113 END OBJ(i8k_right_fan_status, INFO_I8K)
1114 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1115 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1116 END OBJ(i8k_ac_status, INFO_I8K)
1117 END OBJ(i8k_buttons_status, INFO_I8K)
1118 #endif /* __linux__ */
1119 END OBJ(buffers, INFO_BUFFERS)
1120 END OBJ(cached, INFO_BUFFERS)
1121 END OBJ(cpu, INFO_CPU)
1123 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1124 obj->data.cpu_index = atoi(&arg[3]);
1126 } else {obj->data.cpu_index = 0; }
1128 obj->data.cpu_index = 0;
1130 END OBJ(cpubar, INFO_CPU)
1132 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1133 obj->data.cpu_index = atoi(&arg[3]);
1136 else {obj->data.cpu_index = 0;}
1137 (void) scan_bar(arg, &obj->a, &obj->b);
1139 (void) scan_bar(arg, &obj->a, &obj->b);
1140 obj->data.cpu_index = 0;
1142 END OBJ(cpugraph, INFO_CPU)
1144 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1145 obj->data.cpu_index = atoi(&arg[3]);
1148 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1150 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1151 obj->data.cpu_index = 0;
1153 END OBJ(diskio, INFO_DISKIO)
1154 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1157 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1161 obj->data.s = scan_font(arg);
1163 OBJ(downspeed, INFO_NET)
1165 obj->data.net = get_net_stat(arg);
1168 CRIT_ERR("downspeed needs argument");
1170 END OBJ(downspeedf, INFO_NET)
1172 obj->data.net = get_net_stat(arg);
1175 CRIT_ERR("downspeedf needs argument");
1177 END OBJ(downspeedgraph, INFO_NET)
1178 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1180 sscanf(arg, "%63s %*i,%*i %*i", buf);
1181 obj->data.net = get_net_stat(buf);
1182 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
1183 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
1192 text_objects[blockstart[blockdepth - 1] -
1193 1].data.ifblock.pos = text_object_count;
1194 blockstart[blockdepth - 1] = text_object_count;
1195 obj->data.ifblock.pos = text_object_count + 2;
1197 ERR("$else: no matching $if_*");
1202 text_objects[blockstart[blockdepth] - 1].data.ifblock.pos =
1205 ERR("$endif: no matching $if_*");
1209 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
1210 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
1211 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
1212 END OBJ(execibar, 0) unsigned int n;
1213 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1215 ERR("${execibar <interval> command}");
1216 obj->type = OBJ_text;
1217 snprintf(buf, 256, "${%s}", s);
1218 obj->data.s = strdup(buf);
1220 obj->data.execi.cmd = strdup(arg + n);
1222 END OBJ(execigraph, 0) unsigned int n;
1223 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1225 ERR("${execigraph <interval> command}");
1226 obj->type = OBJ_text;
1227 snprintf(buf, 256, "${%s}", s);
1228 obj->data.s = strdup(buf);
1230 obj->data.execi.cmd = strdup(arg + n);
1232 END OBJ(execi, 0) unsigned int n;
1235 || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1237 ERR("${execi <interval> command}");
1238 obj->type = OBJ_text;
1239 snprintf(buf, 256, "${%s}", s);
1240 obj->data.s = strdup(buf);
1242 obj->data.execi.cmd = strdup(arg + n);
1243 obj->data.execi.buffer =
1244 (char *) calloc(1, TEXT_BUFFER_SIZE);
1246 END OBJ(texeci, 0) unsigned int n;
1249 || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1251 ERR("${texeci <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);
1257 obj->data.execi.buffer =
1258 (char *) calloc(1, TEXT_BUFFER_SIZE);
1260 END OBJ(pre_exec, 0) obj->type = OBJ_text;
1262 FILE *fp = popen(arg, "r");
1266 n = fread(buf, 1, 2048, fp);
1269 if (n && buf[n - 1] == '\n')
1274 obj->data.s = strdup(buf);
1276 obj->data.s = strdup("");
1279 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
1280 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1282 while (isspace(*arg))
1288 obj->data.fsbar.fs = prepare_fs_stat(arg);
1289 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
1292 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
1296 obj->data.fsbar.fs = prepare_fs_stat(arg);
1297 END OBJ(fs_free, INFO_FS) if (!arg)
1299 obj->data.fs = prepare_fs_stat(arg);
1300 END OBJ(fs_used_perc, INFO_FS) if (!arg)
1302 obj->data.fs = prepare_fs_stat(arg);
1303 END OBJ(fs_free_perc, INFO_FS) if (!arg)
1305 obj->data.fs = prepare_fs_stat(arg);
1306 END OBJ(fs_size, INFO_FS) if (!arg)
1308 obj->data.fs = prepare_fs_stat(arg);
1309 END OBJ(fs_used, INFO_FS) if (!arg)
1311 obj->data.fs = prepare_fs_stat(arg);
1312 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
1313 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
1314 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
1315 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
1319 ERR("i2c needs arguments");
1320 obj->type = OBJ_text;
1321 //obj->data.s = strdup("${i2c}");
1325 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
1326 /* if scanf couldn't read three values, read type and num and use
1328 sscanf(arg, "%63s %d", buf2, &n);
1330 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
1331 obj->data.i2c.devtype);
1332 strncpy(obj->data.i2c.type, buf2, 63);
1335 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
1336 obj->data.i2c.devtype);
1337 strncpy(obj->data.i2c.type, buf2, 63);
1340 END OBJ(top, INFO_TOP)
1344 ERR("top needs arguments");
1345 obj->type = OBJ_text;
1346 //obj->data.s = strdup("${top}");
1349 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1350 if (strcmp(buf, "name") == 0) {
1351 obj->data.top.type = TOP_NAME;
1352 } else if (strcmp(buf, "cpu") == 0) {
1353 obj->data.top.type = TOP_CPU;
1354 } else if (strcmp(buf, "pid") == 0) {
1355 obj->data.top.type = TOP_PID;
1356 } else if (strcmp(buf, "mem") == 0) {
1357 obj->data.top.type = TOP_MEM;
1359 ERR("invalid arg for top");
1362 if (n < 1 || n > 10) {
1363 CRIT_ERR("invalid arg for top");
1366 obj->data.top.num = n - 1;
1370 ERR("invalid args given for top");
1373 END OBJ(top_mem, INFO_TOP)
1377 ERR("top_mem needs arguments");
1378 obj->type = OBJ_text;
1379 obj->data.s = strdup("${top_mem}");
1382 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1383 if (strcmp(buf, "name") == 0) {
1384 obj->data.top.type = TOP_NAME;
1385 } else if (strcmp(buf, "cpu") == 0) {
1386 obj->data.top.type = TOP_CPU;
1387 } else if (strcmp(buf, "pid") == 0) {
1388 obj->data.top.type = TOP_PID;
1389 } else if (strcmp(buf, "mem") == 0) {
1390 obj->data.top.type = TOP_MEM;
1392 ERR("invalid arg for top");
1395 if (n < 1 || n > 10) {
1396 CRIT_ERR("invalid arg for top");
1399 obj->data.top.num = n - 1;
1403 ERR("invalid args given for top");
1406 END OBJ(addr, INFO_NET)
1408 obj->data.net = get_net_stat(arg);
1411 CRIT_ERR("addr needs argument");
1413 END OBJ(linkstatus, INFO_WIFI)
1415 obj->data.net = get_net_stat(arg);
1418 CRIT_ERR("linkstatus needs argument");
1424 ERR("tail needs arguments");
1425 obj->type = OBJ_text;
1426 obj->data.s = strdup("${tail}");
1429 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
1430 if (n1 < 1 || n1 > 30) {
1431 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
1435 fp = fopen(buf, "rt");
1437 obj->data.tail.logfile =
1438 malloc(TEXT_BUFFER_SIZE);
1439 strcpy(obj->data.tail.logfile, buf);
1440 obj->data.tail.wantedlines = n1 - 1;
1441 obj->data.tail.interval =
1442 update_interval * 2;
1446 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
1449 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
1450 if (n1 < 1 || n1 > 30) {
1452 ("invalid arg for tail, number of lines must be between 1 and 30");
1454 } else if (n2 < 1 || n2 < update_interval) {
1456 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
1460 fp = fopen(buf, "rt");
1462 obj->data.tail.logfile =
1463 malloc(TEXT_BUFFER_SIZE);
1464 strcpy(obj->data.tail.logfile, buf);
1465 obj->data.tail.wantedlines = n1 - 1;
1466 obj->data.tail.interval = n2;
1470 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
1476 ERR("invalid args given for tail");
1479 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
1484 ERR("head needs arguments");
1485 obj->type = OBJ_text;
1486 obj->data.s = strdup("${head}");
1489 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
1490 if (n1 < 1 || n1 > 30) {
1491 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
1495 fp = fopen(buf, "rt");
1497 obj->data.tail.logfile =
1498 malloc(TEXT_BUFFER_SIZE);
1499 strcpy(obj->data.tail.logfile, buf);
1500 obj->data.tail.wantedlines = n1 - 1;
1501 obj->data.tail.interval =
1502 update_interval * 2;
1506 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
1509 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
1510 if (n1 < 1 || n1 > 30) {
1512 ("invalid arg for head, number of lines must be between 1 and 30");
1514 } else if (n2 < 1 || n2 < update_interval) {
1516 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
1520 fp = fopen(buf, "rt");
1522 obj->data.tail.logfile =
1523 malloc(TEXT_BUFFER_SIZE);
1524 strcpy(obj->data.tail.logfile, buf);
1525 obj->data.tail.wantedlines = n1 - 1;
1526 obj->data.tail.interval = n2;
1530 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
1536 ERR("invalid args given for head");
1539 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
1540 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
1542 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1543 if (r >= 3 && (c < 1 || c > 3))
1545 if (r >= 2 && (b < 1 || b > 3))
1547 if (r >= 1 && (a < 1 || a > 3))
1550 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1551 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1552 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1553 END OBJ(if_existing, 0)
1554 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1555 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1558 ERR("if_existing needs an argument");
1559 obj->data.ifblock.s = 0;
1561 obj->data.ifblock.s = strdup(arg);
1562 blockstart[blockdepth] = text_object_count;
1563 obj->data.ifblock.pos = text_object_count + 2;
1565 END OBJ(if_mounted, 0)
1566 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1567 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1570 ERR("if_mounted needs an argument");
1571 obj->data.ifblock.s = 0;
1573 obj->data.ifblock.s = strdup(arg);
1574 blockstart[blockdepth] = text_object_count;
1575 obj->data.ifblock.pos = text_object_count + 2;
1577 END OBJ(if_running, 0)
1578 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1579 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1583 snprintf(buf, 256, "pidof %s >/dev/null", arg);
1584 obj->data.ifblock.s = strdup(buf);
1586 ERR("if_running needs an argument");
1587 obj->data.ifblock.s = 0;
1589 blockstart[blockdepth] = text_object_count;
1590 obj->data.ifblock.pos = text_object_count + 2;
1594 END OBJ(mails, INFO_MAIL)
1595 END OBJ(mem, INFO_MEM)
1596 END OBJ(memmax, INFO_MEM)
1597 END OBJ(memperc, INFO_MEM)
1598 END OBJ(membar, INFO_MEM)
1599 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1600 END OBJ(memgraph, INFO_MEM)
1601 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1602 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
1603 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
1604 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
1605 END OBJ(mixerbar, INFO_MIXER)
1606 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1607 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1608 END OBJ(mixerlbar, INFO_MIXER)
1609 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1610 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1611 END OBJ(mixerrbar, INFO_MIXER)
1612 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1613 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1616 OBJ(ml_upload_counter, INFO_MLDONKEY)
1617 END OBJ(ml_download_counter, INFO_MLDONKEY)
1618 END OBJ(ml_nshared_files, INFO_MLDONKEY)
1619 END OBJ(ml_shared_counter, INFO_MLDONKEY)
1620 END OBJ(ml_tcp_upload_rate, INFO_MLDONKEY)
1621 END OBJ(ml_tcp_download_rate, INFO_MLDONKEY)
1622 END OBJ(ml_udp_upload_rate, INFO_MLDONKEY)
1623 END OBJ(ml_udp_download_rate, INFO_MLDONKEY)
1624 END OBJ(ml_ndownloaded_files, INFO_MLDONKEY)
1625 END OBJ(ml_ndownloading_files, INFO_MLDONKEY) END
1627 OBJ(new_mails, INFO_MAIL)
1628 END OBJ(nodename, 0)
1629 END OBJ(processes, INFO_PROCS)
1630 END OBJ(running_processes, INFO_RUN_PROCS)
1631 END OBJ(shadecolor, 0)
1633 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
1635 END OBJ(outlinecolor, 0)
1637 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
1639 END OBJ(stippled_hr, 0)
1641 int a = stippled_borders, b = 1;
1643 if (sscanf(arg, "%d %d", &a, &b) != 2)
1644 sscanf(arg, "%d", &b);
1648 obj->data.pair.a = a;
1649 obj->data.pair.b = b;
1651 END OBJ(swap, INFO_MEM)
1652 END OBJ(swapmax, INFO_MEM)
1653 END OBJ(swapperc, INFO_MEM)
1654 END OBJ(swapbar, INFO_MEM)
1655 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1656 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
1658 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
1659 obj->data.i2c.devtype);
1660 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
1662 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
1663 obj->data.i2c.devtype);
1664 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1665 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1666 END OBJ(totaldown, INFO_NET)
1668 obj->data.net = get_net_stat(arg);
1671 CRIT_ERR("totaldown needs argument");
1673 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
1675 obj->data.net = get_net_stat(arg);
1678 CRIT_ERR("totalup needs argument");
1681 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
1682 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
1683 END OBJ(upspeed, INFO_NET)
1685 obj->data.net = get_net_stat(arg);
1688 CRIT_ERR("upspeed needs argument");
1690 END OBJ(upspeedf, INFO_NET)
1692 obj->data.net = get_net_stat(arg);
1695 CRIT_ERR("upspeedf needs argument");
1698 END OBJ(upspeedgraph, INFO_NET)
1699 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1701 sscanf(arg, "%63s %*i,%*i %*i", buf);
1702 obj->data.net = get_net_stat(buf);
1703 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
1704 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
1709 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
1710 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
1711 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
1712 OBJ(apm_adapter, 0) END
1713 OBJ(apm_battery_life, 0) END
1714 OBJ(apm_battery_time, 0) END
1715 #endif /* __FreeBSD__ */
1717 OBJ(seti_prog, INFO_SETI) END OBJ(seti_progbar, INFO_SETI)
1718 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1719 END OBJ(seti_credit, INFO_SETI) END
1722 OBJ(mpd_artist, INFO_MPD)
1723 END OBJ(mpd_title, INFO_MPD)
1724 END OBJ(mpd_random, INFO_MPD)
1725 END OBJ(mpd_repeat, INFO_MPD)
1726 END OBJ(mpd_elapsed, INFO_MPD)
1727 END OBJ(mpd_length, INFO_MPD)
1728 END OBJ(mpd_track, INFO_MPD)
1729 END OBJ(mpd_percent, INFO_MPD)
1730 END OBJ(mpd_album, INFO_MPD) END OBJ(mpd_vol,
1731 INFO_MPD) END OBJ(mpd_bitrate,
1733 END OBJ(mpd_status, INFO_MPD)
1734 END OBJ(mpd_bar, INFO_MPD)
1735 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1740 ERR("unknown variable %s", s);
1741 obj->type = OBJ_text;
1742 snprintf(buf, 256, "${%s}", s);
1743 obj->data.s = strdup(buf);
1748 /* append_text() appends text to last text_object if it's text, if it isn't
1749 * it creates a new text_object */
1750 static void append_text(const char *s)
1752 struct text_object *obj;
1754 if (s == NULL || *s == '\0')
1757 obj = text_object_count ? &text_objects[text_object_count - 1] : 0;
1759 /* create a new text object? */
1760 if (!obj || obj->type != OBJ_text) {
1761 obj = new_text_object();
1762 obj->type = OBJ_text;
1763 obj->data.s = strdup(s);
1766 obj->data.s = (char *) realloc(obj->data.s,
1767 strlen(obj->data.s) +
1769 strcat(obj->data.s, s);
1773 static void extract_variable_text(const char *p)
1777 free_text_objects();
1792 /* variable is either $foo or ${foo} */
1796 while (*p && *p != '}')
1802 while (*p && (isalnum((int) *p)
1807 /* copy variable to buffer */
1808 len = (p - s > 255) ? 255 : (p - s);
1809 strncpy(buf, s, len);
1818 /* if variable wasn't found from environment, use some special */
1824 if (strchr(buf, ' ')) {
1825 arg = strchr(buf, ' ');
1828 while (isspace((int) *arg))
1834 /* lowercase variable name */
1841 construct_text_object(buf, arg);
1852 ERR("one or more $endif's are missing");
1856 double current_update_time, last_update_time;
1858 static void generate_text()
1861 struct information *cur = &info;
1868 current_update_time = get_time();
1874 n = TEXT_BUFFER_SIZE * 4 - 2;
1877 for (i = 0; i < text_object_count; i++) {
1878 struct text_object *obj = &text_objects[i];
1880 #define OBJ(a) break; case OBJ_##a:
1882 switch (obj->type) {
1885 ERR("not implemented obj type %d",
1889 /* does anyone have decimals in acpi temperature? */
1891 snprintf(p, n, "%d", (int)
1892 get_acpi_temperature(obj->
1896 snprintf(p, 5, "%d ", (int)
1897 get_acpi_temperature(obj->
1902 /* does anyone have decimals in acpi temperature? */
1904 snprintf(p, n, "%d", (int)
1905 ((get_acpi_temperature(obj->
1907 i)+ 40) * 9.0 / 5 - 40));
1909 snprintf(p, 5, "%d ", (int)
1910 ((get_acpi_temperature(obj->
1912 i)+ 40) * 9.0 / 5 - 40));
1915 snprintf(p, n, "%.0f", get_freq());
1918 float ghz = (float)(get_freq()/1000);
1919 //printf("%f\n", ghz);
1920 snprintf(p, n, "%'.2f", ghz);
1923 snprintf(p, n, "%.0f", get_freq_dynamic());
1926 float ghz = (float)(get_freq_dynamic()/1000);
1927 snprintf(p, n, "%'.2f", ghz);
1930 snprintf(p, n, "%s", get_adt746x_cpu());
1933 snprintf(p, n, "%s", get_adt746x_fan());
1936 snprintf(p, n, "%s", get_acpi_fan());
1938 OBJ(acpiacadapter) {
1939 snprintf(p, n, "%s",
1940 get_acpi_ac_adapter());
1943 get_battery_stuff(p, n, obj->data.s);
1946 human_readable(cur->buffers * 1024, p,
1950 human_readable(cur->cached * 1024, p, 255);
1953 if (obj->data.cpu_index > info.cpu_count) {
1954 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
1955 CRIT_ERR("attempting to use more CPUs then you have!");
1958 snprintf(p, n, "%*d", pad_percents,
1959 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
1962 snprintf(p, 4, "%*d ",
1964 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
1970 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
1973 new_graph(p, obj->a,
1974 obj->b, obj->c, obj->d,
1975 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
1979 new_fg(p, obj->data.l);
1981 #if defined(__linux__)
1983 snprintf(p, n, "%s", i8k.version);
1986 snprintf(p, n, "%s", i8k.bios);
1989 snprintf(p, n, "%s", i8k.serial);
1992 snprintf(p, n, "%s", i8k.cpu_temp);
1994 OBJ(i8k_cpu_tempf) {
1996 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
1997 snprintf(p, n, "%.1f", cpu_temp*(9.0/5.0)+32.0);
1999 OBJ(i8k_left_fan_status) {
2000 int left_fan_status;
2001 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
2002 if(left_fan_status == 0) {
2003 snprintf(p, n,"off");
2004 } if(left_fan_status == 1) {
2005 snprintf(p, n, "low");
2006 } if(left_fan_status == 2) {
2007 snprintf(p, n, "high");
2011 OBJ(i8k_right_fan_status) {
2012 int right_fan_status;
2013 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
2014 if(right_fan_status == 0) {
2015 snprintf(p, n,"off");
2016 } if(right_fan_status == 1) {
2017 snprintf(p, n, "low");
2018 } if(right_fan_status == 2) {
2019 snprintf(p, n, "high");
2022 OBJ(i8k_left_fan_rpm) {
2023 snprintf(p, n, "%s", i8k.left_fan_rpm);
2025 OBJ(i8k_right_fan_rpm) {
2026 snprintf(p, n, "%s", i8k.right_fan_rpm);
2028 OBJ(i8k_ac_status) {
2030 sscanf(i8k.ac_status, "%d", &ac_status);
2031 if(ac_status == -1) {
2032 snprintf(p, n,"disabled (read i8k docs)");
2033 } if(ac_status == 0) {
2034 snprintf(p, n, "off");
2035 } if(ac_status == 1) {
2036 snprintf(p, n, "on");
2039 OBJ(i8k_buttons_status) {
2040 snprintf(p, n, "%s", i8k.buttons_status);
2043 #endif /* __linux__ */
2047 new_font(p, obj->data.s);
2052 if (diskio_value > 1024*1024) {
2053 snprintf(p, n, "%.1fG",
2054 (double)diskio_value/1024/1024);
2055 } else if (diskio_value > 1024) {
2056 snprintf(p, n, "%.1fM",
2057 (double)diskio_value/1024);
2058 } else if (diskio_value > 0) {
2059 snprintf(p, n, "%dK", diskio_value);
2061 snprintf(p, n, "%d", diskio_value);
2064 if (diskio_value > 1024*1024) {
2065 snprintf(p, 6, "%.1fG ",
2066 (double)diskio_value/1024/1024);
2067 } else if (diskio_value > 1024) {
2068 snprintf(p, 6, "%.1fM ",
2069 (double)diskio_value/1024);
2070 } else if (diskio_value > 0) {
2071 snprintf(p, 6, "%dK ", diskio_value);
2073 snprintf(p, 6, "%d ", diskio_value);
2078 new_graph(p, obj->a,
2079 obj->b, obj->c, obj->d,
2080 diskio_value, obj->e, 1);
2085 snprintf(p, n, "%d",
2086 (int) (obj->data.net->
2090 snprintf(p, 6, "%d ",
2091 (int) (obj->data.net->
2097 snprintf(p, n, "%.1f",
2099 recv_speed / 1024.0);
2101 snprintf(p, 8, "%.1f ",
2103 recv_speed / 1024.0);
2105 OBJ(downspeedgraph) {
2106 if (obj->data.net->recv_speed == 0) // this is just to make the ugliness at start go away
2107 obj->data.net->recv_speed = 0.01;
2108 new_graph(p, obj->a, obj->b, obj->c, obj->d,
2109 (obj->data.net->recv_speed /
2110 1024.0), obj->e, 1);
2116 i = obj->data.ifblock.pos - 2;
2126 snprintf(p, n, "%u.%u.%u.%u",
2127 obj->data.net->addr.
2129 obj->data.net->addr.
2131 obj->data.net->addr.
2133 obj->data.net->addr.
2138 snprintf(p, n, "%d",
2139 obj->data.net->linkstatus);
2144 FILE *fp = popen(obj->data.s, "r");
2145 int n2 = fread(p, 1, n, fp);
2149 if (n2 && p[n2 - 1] == '\n')
2160 FILE *fp = popen(obj->data.s, "r");
2161 int n2 = fread(p, 1, n, fp);
2165 if (n2 && p[n2 - 1] == '\n')
2174 if (sscanf(p, "%lf", &barnum) == 0) {
2175 ERR("reading execbar value failed (perhaps it's not the correct format?)");
2177 if (barnum > 100 || barnum < 0) {
2178 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
2180 barnum = barnum / 100.0;
2181 new_bar(p, 0, 4, (int) (barnum * 255.0));
2187 FILE *fp = popen(obj->data.s, "r");
2188 int n2 = fread(p, 1, n, fp);
2192 if (n2 && p[n2 - 1] == '\n')
2201 if (sscanf(p, "%lf", &barnum) == 0) {
2202 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
2204 if (barnum > 100 || barnum < 0) {
2205 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
2208 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
2213 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2214 new_bar(p, 0, 4, (int) obj->f);
2217 FILE *fp = popen(obj->data.execi.cmd, "r");
2218 int n2 = fread(p, 1, n, fp);
2221 if (n2 && p[n2 - 1] == '\n')
2230 if (sscanf(p, "%f", &barnum) == 0) {
2231 ERR("reading execibar value failed (perhaps it's not the correct format?)");
2233 if (barnum > 100 || barnum < 0) {
2234 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
2236 obj->f = 255 * barnum / 100.0;
2237 new_bar(p, 0, 4, (int) obj->f);
2239 obj->data.execi.last_update =
2240 current_update_time;
2244 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2245 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
2248 FILE *fp = popen(obj->data.execi.cmd, "r");
2249 int n2 = fread(p, 1, n, fp);
2252 if (n2 && p[n2 - 1] == '\n')
2261 if (sscanf(p, "%f", &barnum) == 0) {
2262 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
2264 if (barnum > 100 || barnum < 0) {
2265 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
2268 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
2270 obj->data.execi.last_update = current_update_time;
2276 if (current_update_time -
2277 obj->data.execi.last_update <
2278 obj->data.execi.interval) {
2279 snprintf(p, n, "%s",
2280 obj->data.execi.buffer);
2282 char *p2 = obj->data.execi.buffer;
2284 popen(obj->data.execi.cmd,
2287 fread(p2, 1, TEXT_BUFFER_SIZE,
2292 if (n2 && p2[n2 - 1] == '\n')
2301 snprintf(p, n, "%s",
2302 obj->data.execi.buffer);
2304 obj->data.execi.last_update =
2305 current_update_time;
2309 static int running = 0;
2310 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2311 snprintf(p, n, "%s", obj->data.execi.buffer);
2313 static pthread_t execthread;
2316 pthread_create( &execthread, NULL, (void*)threaded_exec, (void*) obj);
2317 pthread_mutex_lock( &mutex1 );
2318 obj->data.execi.last_update = current_update_time;
2319 pthread_mutex_unlock( &mutex1 );
2321 pthread_join( execthread, NULL);
2324 snprintf(p, n, "%s", obj->data.execi.buffer);
2329 if (obj->data.fs != NULL) {
2330 if (obj->data.fs->size == 0)
2349 if (obj->data.fs != NULL)
2350 human_readable(obj->data.fs->avail,
2354 if (obj->data.fs != NULL) {
2355 if (obj->data.fs->size)
2356 snprintf(p, n, "%*d",
2365 snprintf(p, n, "0");
2369 if (obj->data.fs != NULL)
2370 human_readable(obj->data.fs->size,
2374 if (obj->data.fs != NULL)
2375 human_readable(obj->data.fs->size -
2376 obj->data.fs->avail,
2380 if (obj->data.fs != NULL) {
2381 if (obj->data.fs->size == 0)
2399 if (obj->data.fs != NULL) {
2400 if (obj->data.fs->size)
2401 snprintf(p, 4, "%d",
2411 snprintf(p, n, "0");
2415 float *v = info.loadavg;
2417 if (obj->data.loadavg[2])
2418 snprintf(p, n, "%.2f %.2f %.2f",
2419 v[obj->data.loadavg[0] -
2421 v[obj->data.loadavg[1] -
2423 v[obj->data.loadavg[2] -
2425 else if (obj->data.loadavg[1])
2426 snprintf(p, n, "%.2f %.2f",
2427 v[obj->data.loadavg[0] -
2429 v[obj->data.loadavg[1] -
2431 else if (obj->data.loadavg[0])
2432 snprintf(p, n, "%.2f",
2433 v[obj->data.loadavg[0] -
2437 new_hr(p, obj->data.i);
2440 new_offset(p, obj->data.i);
2443 new_voffset(p, obj->data.i);
2448 r = get_i2c_info(&obj->data.i2c.fd,
2450 obj->data.i2c.devtype,
2451 obj->data.i2c.type);
2453 if (r >= 100.0 || r == 0)
2454 snprintf(p, n, "%d", (int) r);
2456 snprintf(p, n, "%.1f", r);
2459 new_alignr(p, obj->data.i);
2462 new_alignc(p, obj->data.i);
2466 if ((obj->data.ifblock.s)
2467 && (stat(obj->data.ifblock.s, &tmp) ==
2469 i = obj->data.ifblock.pos - 2;
2475 if ((obj->data.ifblock.s)
2476 && (!check_mount(obj->data.ifblock.s))) {
2477 i = obj->data.ifblock.pos - 2;
2483 if ((obj->data.ifblock.s)
2484 && system(obj->data.ifblock.s)) {
2485 i = obj->data.ifblock.pos - 2;
2491 snprintf(p, n, "%s", cur->uname_s.release);
2494 snprintf(p, n, "%s", cur->uname_s.machine);
2499 human_readable(cur->mem * 1024, p, 6);
2502 human_readable(cur->memmax * 1024, p, 255);
2507 snprintf(p, n, "%*d",
2512 snprintf(p, 4, "%*d ",
2519 new_bar(p, obj->data.pair.a,
2521 cur->memmax ? (cur->mem * 255) /
2526 new_graph(p, obj->a,
2527 obj->b, obj->c, obj->d,
2528 cur->memmax ? (cur->mem * 100.0) /
2529 (cur->memmax) : 0.0, 100, 1);
2533 snprintf(p, n, "%d",
2534 mixer_get_avg(obj->data.l));
2537 snprintf(p, n, "%d",
2538 mixer_get_left(obj->data.l));
2541 snprintf(p, n, "%d",
2542 mixer_get_right(obj->data.l));
2545 new_bar(p, obj->data.mixerbar.w,
2546 obj->data.mixerbar.h,
2547 mixer_get_avg(obj->data.mixerbar.
2551 new_bar(p, obj->data.mixerbar.w,
2552 obj->data.mixerbar.h,
2553 mixer_get_left(obj->data.mixerbar.
2557 new_bar(p, obj->data.mixerbar.w,
2558 obj->data.mixerbar.h,
2559 mixer_get_right(obj->data.mixerbar.
2565 snprintf(p, n, "%d", cur->mail_count);
2568 snprintf(p, n, "%d", cur->new_mail_count);
2571 OBJ(ml_upload_counter) {
2572 snprintf(p, n, "%lld",
2573 mlinfo.upload_counter / 1048576);
2575 OBJ(ml_download_counter) {
2576 snprintf(p, n, "%lld",
2577 mlinfo.download_counter /
2580 OBJ(ml_nshared_files) {
2581 snprintf(p, n, "%i", mlinfo.nshared_files);
2583 OBJ(ml_shared_counter) {
2584 snprintf(p, n, "%lld",
2585 mlinfo.shared_counter / 1048576);
2587 OBJ(ml_tcp_upload_rate) {
2588 snprintf(p, n, "%.2f",
2589 (float) mlinfo.tcp_upload_rate /
2592 OBJ(ml_tcp_download_rate) {
2593 snprintf(p, n, "%.2f",
2594 (float) mlinfo.tcp_download_rate /
2597 OBJ(ml_udp_upload_rate) {
2598 snprintf(p, n, "%.2f",
2599 (float) mlinfo.udp_upload_rate /
2602 OBJ(ml_udp_download_rate) {
2603 snprintf(p, n, "%.2f",
2604 (float) mlinfo.udp_download_rate /
2607 OBJ(ml_ndownloaded_files) {
2608 snprintf(p, n, "%i",
2609 mlinfo.ndownloaded_files);
2611 OBJ(ml_ndownloading_files) {
2612 snprintf(p, n, "%i",
2613 mlinfo.ndownloading_files);
2618 snprintf(p, n, "%s",
2619 cur->uname_s.nodename);
2622 new_outline(p, obj->data.l);
2626 snprintf(p, n, "%d", cur->procs);
2628 snprintf(p, 5, "%d ",
2631 OBJ(running_processes) {
2633 snprintf(p, n, "%d",
2636 snprintf(p, 3, "%d ",
2640 snprintf(p, n, "%s", obj->data.s);
2643 new_bg(p, obj->data.l);
2646 new_stippled_hr(p, obj->data.pair.a,
2650 human_readable(cur->swap * 1024, p, 255);
2653 human_readable(cur->swapmax * 1024, p,
2657 if (cur->swapmax == 0) {
2658 strncpy(p, "No swap", 255);
2661 snprintf(p, 255, "%*u",
2667 snprintf(p, 4, "%*u ",
2675 new_bar(p, obj->data.pair.a,
2677 cur->swapmax ? (cur->swap * 255) /
2678 (cur->swapmax) : 0);
2681 snprintf(p, n, "%s", cur->uname_s.sysname);
2684 time_t t = time(NULL);
2685 struct tm *tm = localtime(&t);
2686 setlocale(LC_TIME, "");
2687 strftime(p, n, obj->data.s, tm);
2690 time_t t = time(NULL);
2691 struct tm *tm = gmtime(&t);
2692 strftime(p, n, obj->data.s, tm);
2695 human_readable(obj->data.net->recv, p,
2699 human_readable(obj->data.net->trans, p,
2703 snprintf(p, n, "%d", total_updates);
2707 snprintf(p, n, "%d",
2708 (int) (obj->data.net->
2712 snprintf(p, 5, "%d ",
2713 (int) (obj->data.net->
2719 snprintf(p, n, "%.1f",
2721 trans_speed / 1024.0);
2723 snprintf(p, 8, "%.1f ",
2725 trans_speed / 1024.0);
2728 if (obj->data.net->trans_speed == 0) // this is just to make the ugliness at start go away
2729 obj->data.net->trans_speed = 0.01;
2730 new_graph(p, obj->a, obj->b, obj->c, obj->d,
2731 (obj->data.net->trans_speed /
2732 1024.0), obj->e, 1);
2735 format_seconds_short(p, n,
2739 format_seconds(p, n, (int) cur->uptime);
2742 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
2744 snprintf(p, n, "%s", get_apm_adapter());
2746 OBJ(apm_battery_life) {
2748 msg = get_apm_battery_life();
2749 snprintf(p, n, "%s", msg);
2752 OBJ(apm_battery_time) {
2754 msg = get_apm_battery_time();
2755 snprintf(p, n, "%s", msg);
2758 #endif /* __FreeBSD__ */
2761 snprintf(p, n, "%.2f",
2762 cur->seti_prog * 100.0f);
2765 new_bar(p, obj->data.pair.a,
2767 (int) (cur->seti_prog * 255.0f));
2770 snprintf(p, n, "%.0f", cur->seti_credit);
2776 snprintf(p, n, "%s", cur->mpd.title);
2779 snprintf(p, n, "%s", cur->mpd.artist);
2782 snprintf(p, n, "%s", cur->mpd.album);
2785 snprintf(p, n, "%s", cur->mpd.random);
2788 snprintf(p, n, "%s", cur->mpd.repeat);
2791 snprintf(p, n, "%s", cur->mpd.track);
2794 snprintf(p, n, "%i", cur->mpd.volume);
2797 snprintf(p, n, "%i", cur->mpd.bitrate);
2800 snprintf(p, n, "%s", cur->mpd.status);
2803 int days = 0, hours = 0, minutes =
2805 int tmp = cur->mpd.elapsed;
2806 while (tmp >= 86400) {
2810 while (tmp >= 3600) {
2820 snprintf(p, n, "%i days %i:%02i:%02i",
2821 days, hours, minutes,
2824 snprintf(p, n, "%i:%02i:%02i", hours,
2827 snprintf(p, n, "%i:%02i", minutes,
2831 int days = 0, hours = 0, minutes =
2833 int tmp = cur->mpd.length;
2834 while (tmp >= 86400) {
2838 while (tmp >= 3600) {
2849 "%i days %i:%02i:%02i",
2850 days, hours, minutes,
2853 snprintf(p, n, "%i:%02i:%02i", hours,
2856 snprintf(p, n, "%i:%02i", minutes,
2860 snprintf(p, n, "%2.0f",
2861 cur->mpd.progress * 100);
2864 new_bar(p, obj->data.pair.a,
2866 (int) (cur->mpd.progress *
2871 if (obj->data.top.type == TOP_NAME
2872 && obj->data.top.num >= 0
2873 && obj->data.top.num < 10) {
2874 // if we limit the buffer and add a bunch of space after, it stops the thing from
2875 // moving other shit around, which is really fucking annoying
2876 snprintf(p, 17, "%s ", cur->cpu[obj->data.top.num]->name);
2877 } else if (obj->data.top.type == TOP_CPU
2878 && obj->data.top.num >= 0
2879 && obj->data.top.num < 10) {
2880 snprintf(p, 7, "%3.2f ",
2881 cur->cpu[obj->data.top.
2883 } else if (obj->data.top.type == TOP_PID
2884 && obj->data.top.num >= 0
2885 && obj->data.top.num < 10) {
2886 snprintf(p, 8, "%i ",
2887 cur->cpu[obj->data.top.
2889 } else if (obj->data.top.type == TOP_MEM
2890 && obj->data.top.num >= 0
2891 && obj->data.top.num < 10) {
2892 snprintf(p, 7, "%3.2f ",
2893 cur->cpu[obj->data.top.
2898 if (obj->data.top.type == TOP_NAME
2899 && obj->data.top.num >= 0
2900 && obj->data.top.num < 10) {
2901 // if we limit the buffer and add a bunch of space after, it stops the thing from
2902 // moving other shit around, which is really fucking annoying
2905 cur->memu[obj->data.top.
2907 } else if (obj->data.top.type == TOP_CPU
2908 && obj->data.top.num >= 0
2909 && obj->data.top.num < 10) {
2910 snprintf(p, 7, "%3.2f ",
2911 cur->memu[obj->data.top.
2913 } else if (obj->data.top.type == TOP_PID
2914 && obj->data.top.num >= 0
2915 && obj->data.top.num < 10) {
2916 snprintf(p, 8, "%i ",
2917 cur->memu[obj->data.top.
2919 } else if (obj->data.top.type == TOP_MEM
2920 && obj->data.top.num >= 0
2921 && obj->data.top.num < 10) {
2922 snprintf(p, 7, "%3.2f ",
2923 cur->memu[obj->data.top.
2931 * I'm tired of everything being packed in
2938 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
2939 snprintf(p, n, "%s", obj->data.tail.buffer);
2941 obj->data.tail.last_update = current_update_time;
2945 tailstring *head = NULL;
2946 tailstring *headtmp = NULL;
2947 tailstring *freetmp = NULL;
2948 fp = fopen(obj->data.tail.logfile, "rt");
2950 ERR("tail logfile failed to open");
2953 obj->data.tail.readlines = 0;
2955 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL) {
2962 addtail(&head, obj->data.tail.buffer);
2963 obj->data.tail.readlines++;
2969 if (obj->data.tail.readlines > 0) {
2970 for (i = 0;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
2971 addtail(&headtmp, head->data);
2976 strcpy(obj->data.tail.buffer, headtmp->data);
2977 headtmp = headtmp->next;
2978 for (i = 1;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
2980 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 */
2981 headtmp = headtmp->next;
2985 /* get rid of any ugly newlines at the end */
2986 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
2987 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
2989 snprintf(p, n, "%s", obj->data.tail.buffer);
2994 strcpy(obj->data.tail.buffer, "Logfile Empty");
2995 snprintf(p, n, "Logfile Empty");
3001 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
3002 snprintf(p, n, "%s", obj->data.tail.buffer);
3004 obj->data.tail.last_update = current_update_time;
3006 tailstring *head = NULL;
3007 tailstring *headtmp = NULL;
3008 tailstring *freetmp = NULL;
3009 fp = fopen(obj->data.tail.logfile, "rt");
3011 ERR("head logfile failed to open");
3014 obj->data.tail.readlines = 0;
3015 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL && obj->data.tail.readlines <= obj->data.tail.wantedlines) {
3016 addtail(&head, obj->data.tail.buffer);
3017 obj->data.tail.readlines++;
3021 if (obj->data.tail.readlines > 0) {
3023 addtail(&headtmp, head->data);
3028 strcpy(obj->data.tail.buffer, headtmp->data);
3029 headtmp = headtmp->next;
3031 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 */
3032 headtmp = headtmp->next;
3035 /* get rid of any ugly newlines at the end */
3036 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
3037 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
3039 snprintf(p, n, "%s", obj->data.tail.buffer);
3042 strcpy(obj->data.tail.buffer, "Logfile Empty");
3043 snprintf(p, n, "Logfile Empty");
3053 unsigned int a = strlen(p);
3059 if (stuff_in_upper_case) {
3069 last_update_time = current_update_time;
3075 static void set_font()
3079 if (window.xftdraw != NULL) {
3080 XftDrawDestroy(window.xftdraw);
3082 window.xftdraw = XftDrawCreate(display, window.drawable,
3083 DefaultVisual(display,
3085 DefaultColormap(display,
3090 XSetFont(display, window.gc, fonts[selected_font].font->fid);
3099 static int text_start_x, text_start_y; /* text start position in window */
3100 static int text_width, text_height;
3104 static inline int get_string_width(const char *s)
3107 return *s ? calc_text_width(s, strlen(s)) : 0;
3113 static inline int get_string_width_special(char *s)
3126 if (*p == SPECIAL_CHAR) {
3127 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
3128 for (i = 0; i < strlen(p); i++) {
3129 *(p + i) = *(p + i + 1);
3131 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
3132 width += specials[special_index+index].width;
3139 if (strlen(final) > 1) {
3140 width += calc_text_width(final, strlen(final));
3152 static void text_size_updater(char *s)
3156 int h = font_height();
3157 /* get string widths and skip specials */
3160 if (*p == SPECIAL_CHAR) {
3162 w += get_string_width(s);
3165 if (specials[special_index].type == BAR
3166 || specials[special_index].type == GRAPH) {
3167 w += specials[special_index].width;
3168 if (specials[special_index].height > h) {
3169 h = specials[special_index].height;
3174 else if (specials[special_index].type == OFFSET) {
3175 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
3177 else if (specials[special_index].type == VOFFSET) {
3178 h += specials[special_index].arg;
3180 else if (specials[special_index].type == FONT) {
3181 fontchange = specials[special_index].font_added;
3182 selected_font = specials[special_index].font_added;
3192 w += get_string_width(s);
3195 if (text_width > maximum_width && maximum_width)
3196 text_width = maximum_width;
3207 static void update_text_area()
3211 /* update text size if it isn't fixed */
3216 text_width = minimum_width;
3219 for_each_line(text_buffer, text_size_updater);
3221 if (text_height < minimum_height)
3222 text_height = minimum_height;
3223 if (text_width > maximum_width && maximum_width > 0)
3224 text_width = maximum_width;
3227 /* get text position on workarea */
3228 switch (text_alignment) {
3235 x = workarea[2] - text_width - gap_x;
3242 y = workarea[3] - text_height - gap_y;
3246 x = workarea[2] - text_width - gap_x;
3247 y = workarea[3] - text_height - gap_y;
3251 case NONE: // Let the WM manage the window
3262 if (own_window && !fixed_pos) {
3265 text_start_x = border_margin + 1;
3266 text_start_y = border_margin + 1;
3267 window.x = x - border_margin - 1;
3268 window.y = y - border_margin - 1;
3272 /* If window size doesn't match to workarea's size, then window
3273 * probably includes panels (gnome).
3274 * Blah, doesn't work on KDE. */
3275 if (workarea[2] != window.width
3276 || workarea[3] != window.height) {
3290 static int cur_x, cur_y; /* current x and y for drawing */
3291 static int draw_mode; /* FG, BG or OUTLINE */
3292 static long current_color;
3294 static inline void set_foreground_color(long c)
3297 XSetForeground(display, window.gc, c);
3301 static void draw_string(const char *s)
3305 int i, i2, pos, width_of_s;
3308 width_of_s = get_string_width(s);
3309 if (out_to_console) {
3312 /* 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 */
3313 strcpy(tmpstring1, s);
3317 snprintf(space, 2, " ");
3319 max = ((text_width - width_of_s) / get_string_width(space));
3322 * This code looks for tabs in the text and coverts them to spaces.
3323 * The trick is getting the correct number of spaces,
3324 * and not going over the window's size without forcing
3325 * the window larger.
3327 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
3328 if (tmpstring1[i] == '\t') // 9 is ascii tab
3332 i2 < (8 - (1 + pos) % 8) && added <= max;
3334 tmpstring2[pos + i2] = ' ';
3339 if (tmpstring1[i] != 9) {
3340 tmpstring2[pos] = tmpstring1[i];
3346 if (text_width == maximum_width) {
3347 /* this means the text is probably pushing the limit, so we'll chop it */
3348 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
3349 tmpstring2[strlen(tmpstring2)-1] = '\0';
3359 c.pixel = current_color;
3360 XQueryColor(display, DefaultColormap(display, screen), &c);
3363 c2.color.red = c.red;
3364 c2.color.green = c.green;
3365 c2.color.blue = c.blue;
3366 c2.color.alpha = fonts[selected_font].font_alpha;
3368 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
3369 cur_x, cur_y, (XftChar8 *) s,
3372 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
3373 cur_x, cur_y, (XftChar8 *) s,
3379 XDrawString(display, window.drawable, window.gc,
3380 cur_x, cur_y, s, strlen(s));
3382 cur_x += width_of_s;
3384 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
3387 long redmask, greenmask, bluemask;
3389 void set_up_gradient()
3392 colour_depth = DisplayPlanes(display, screen);
3396 if (colour_depth != 24 && colour_depth != 16) {
3397 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
3403 for(i = (colour_depth / 3)-1; i>=0; i--) {
3405 greenmask |= 1 << i;
3408 if (colour_depth%3 == 1) {
3409 greenmask |= 1 << (colour_depth / 3);
3411 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
3412 greenmask = greenmask << (colour_depth / 3);
3415 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 */
3417 int red1, green1, blue1; // first colour
3418 int red2, green2, blue2; // second colour
3419 int red3 = 0, green3 = 0, blue3 = 0; // difference
3420 short redshift = (2*colour_depth / 3 + colour_depth%3);
3421 short greenshift = (colour_depth / 3);
3422 red1 = (first_colour & redmask) >> redshift;
3423 green1 = (first_colour & greenmask) >> greenshift;
3424 blue1 = first_colour & bluemask;
3425 red2 = (last_colour & redmask) >> redshift;
3426 green2 = (last_colour & greenmask) >> greenshift;
3427 blue2 = last_colour & bluemask;
3434 if (green1 > green2) {
3437 if (green1 < green2) {
3440 if (blue1 > blue2) {
3443 if (blue1 < blue2) {
3458 if (red1 > bluemask) {
3461 if (green1 > bluemask) {
3464 if (blue1 > bluemask) {
3467 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
3471 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
3472 if (colour_depth == 0) {
3475 int red1, green1, blue1; // first colour
3476 int red2, green2, blue2; // second colour
3477 long redshift = (2*colour_depth / 3 + colour_depth%3);
3478 long greenshift = (colour_depth / 3);
3479 int red3 = 0, green3 = 0, blue3 = 0; // difference
3480 red1 = (first_colour & redmask) >> redshift;
3481 green1 = (first_colour & greenmask) >> greenshift;
3482 blue1 = first_colour & bluemask;
3483 red2 = (last_colour & redmask) >> redshift;
3484 green2 = (last_colour & greenmask) >> greenshift;
3485 blue2 = last_colour & bluemask;
3486 red3 = abs(red1 - red2);
3487 green3 = abs(green1 - green2);
3488 blue3 = abs(blue1 - blue2);
3497 static void draw_line(char *s)
3501 cur_x = text_start_x;
3502 cur_y += font_ascent();
3504 short font_h = font_height();
3506 /* find specials and draw stuff */
3509 if (*p == SPECIAL_CHAR) {
3512 /* draw string before special */
3519 switch (specials[special_index].type) {
3520 case HORIZONTAL_LINE:
3523 specials[special_index].height;
3524 int mid = font_ascent() / 2;
3525 w = text_start_x + text_width -
3528 XSetLineAttributes(display,
3533 XDrawLine(display, window.drawable,
3544 specials[special_index].height;
3546 specials[special_index].arg;
3547 int mid = font_ascent() / 2;
3548 char ss[2] = { s, s };
3549 w = text_start_x + text_width -
3552 XSetLineAttributes(display,
3557 XSetDashes(display, window.gc, 0,
3559 XDrawLine(display, window.drawable,
3569 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
3573 specials[special_index].height;
3575 specials[special_index].arg;
3580 by = cur_y - (font_ascent() + h) / 2 - 1;
3584 by = cur_y - (font_ascent()/2) - 1;
3586 if (h < (font_height())) {
3589 w = specials[special_index].width;
3592 text_width - cur_x - 1;
3596 XSetLineAttributes(display,
3602 XDrawRectangle(display,
3606 XFillRectangle(display,
3610 w * bar_usage / 255,
3612 if (specials[special_index].
3614 && specials[special_index].
3618 [special_index].height;
3625 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
3629 specials[special_index].height;
3633 by = cur_y - (font_ascent() + h) / 2 - 1;
3637 by = cur_y - (font_ascent()/2) - 1;
3639 if (h < (font_height())) {
3642 w = specials[special_index].width;
3644 w = text_start_x + text_width - cur_x - 1;
3647 XSetLineAttributes(display,
3652 XDrawRectangle(display,
3656 XSetLineAttributes(display,
3663 int gradient_size = 0;
3664 float gradient_factor = 0;
3665 float gradient_update = 0;
3666 unsigned long tmpcolour = current_color;
3667 if (specials[special_index].first_colour != specials[special_index].last_colour) {
3668 tmpcolour = specials[special_index].first_colour;
3669 gradient_size = gradient_max(specials[special_index].first_colour, specials[special_index].last_colour);
3670 gradient_factor = (float)gradient_size / (w - 3);
3672 for (i = 0; i < w - 3; i++) {
3673 if (specials[special_index].first_colour != specials[special_index].last_colour) {
3674 XSetForeground(display, window.gc, tmpcolour);
3675 gradient_update += gradient_factor;
3676 while (gradient_update > 0) {
3677 tmpcolour = do_gradient(tmpcolour, specials[special_index].last_colour);
3681 if (i / ((float) (w - 3) / (specials[special_index].graph_width)) > j) {
3684 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 */
3686 if (specials[special_index].
3688 && specials[special_index].
3692 [special_index].height;
3695 if (draw_mode == BG) {
3696 set_foreground_color(default_bg_color);
3698 else if (draw_mode == OUTLINE) {
3699 set_foreground_color(default_out_color);
3701 set_foreground_color(default_fg_color);
3707 cur_y -= font_ascent();
3708 selected_font = specials[special_index].font_added;
3709 cur_y += font_ascent();
3711 if (!use_xft || use_xdbe)
3719 if (draw_mode == FG)
3720 set_foreground_color(specials
3726 if (draw_mode == BG)
3727 set_foreground_color(specials
3733 if (draw_mode == OUTLINE)
3734 set_foreground_color(specials
3741 w += specials[special_index].arg;
3746 cur_y += specials[special_index].arg;
3752 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
3753 /*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);*/
3754 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
3755 cur_x = pos_x - specials[special_index].arg;
3762 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
3763 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
3764 /*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);*/
3766 specials[special_index].arg)
3769 [special_index].arg;
3786 if (cur_y_add > 0) {
3788 cur_y -= font_descent();
3793 cur_y += font_descent();
3800 static void draw_text()
3803 cur_y = text_start_y;
3806 if (draw_borders && border_width > 0) {
3807 unsigned int b = (border_width + 1) / 2;
3809 if (stippled_borders) {
3811 { stippled_borders, stippled_borders };
3812 XSetLineAttributes(display, window.gc,
3813 border_width, LineOnOffDash,
3814 CapButt, JoinMiter);
3815 XSetDashes(display, window.gc, 0, ss, 2);
3817 XSetLineAttributes(display, window.gc,
3818 border_width, LineSolid,
3819 CapButt, JoinMiter);
3822 XDrawRectangle(display, window.drawable, window.gc,
3823 text_start_x - border_margin + b,
3824 text_start_y - border_margin + b,
3825 text_width + border_margin * 2 - 1 - b * 2,
3826 text_height + border_margin * 2 - 1 -
3833 for_each_line(text_buffer, draw_line);
3836 static void draw_stuff()
3839 if (draw_shades && !draw_outline) {
3842 set_foreground_color(default_bg_color);
3851 for (i = -1; i < 2; i++)
3852 for (j = -1; j < 2; j++) {
3853 if (i == 0 && j == 0)
3857 set_foreground_color(default_out_color);
3858 draw_mode = OUTLINE;
3865 set_foreground_color(default_fg_color);
3873 swap.swap_window = window.window;
3874 swap.swap_action = XdbeBackground;
3875 XdbeSwapBuffers(display, &swap, 1);
3881 static void clear_text(int exposures)
3885 return; /* The swap action is XdbeBackground, which clears */
3889 /* there is some extra space for borders and outlines */
3890 XClearArea(display, window.drawable,
3891 text_start_x - border_margin - 1,
3892 text_start_y - border_margin - 1,
3893 text_width + border_margin * 2 + 2,
3894 text_height + border_margin * 2 + 2,
3895 exposures ? True : 0);
3900 static int need_to_update;
3902 /* update_text() generates new text and clears old text area */
3903 static void update_text()
3912 static void main_loop()
3915 Region region = XCreateRegion();
3919 while (total_run_times == 0 || info.looped < total_run_times - 1) {
3924 /* wait for X event or timeout */
3926 if (!XPending(display)) {
3931 update_interval - (get_time() -
3937 tv.tv_sec = (long) t;
3938 tv.tv_usec = (long) (t * 1000000) % 1000000;
3940 FD_SET(ConnectionNumber(display), &fdsr);
3943 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
3946 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
3951 ERR("can't select(): %s",
3962 set_transparent_background(window.window);
3967 if (need_to_update) {
3969 int wx = window.x, wy = window.y;
3977 /* resize window if it isn't right size */
3979 (text_width + border_margin * 2 !=
3981 || text_height + border_margin * 2 !=
3985 border_margin * 2 + 1;
3988 border_margin * 2 + 1;
3989 XResizeWindow(display,
3995 /* move window if it isn't in right position */
3998 || window.y != wy)) {
3999 XMoveWindow(display, window.window,
4000 window.x, window.y);
4010 r.x = text_start_x - border_margin;
4011 r.y = text_start_y - border_margin;
4012 r.width = text_width + border_margin * 2;
4013 r.height = text_height + border_margin * 2;
4014 XUnionRectWithRegion(&r, region, region);
4019 /* handle X events */
4021 while (XPending(display)) {
4023 XNextEvent(display, &ev);
4030 r.width = ev.xexpose.width;
4031 r.height = ev.xexpose.height;
4032 XUnionRectWithRegion(&r, region,
4038 case ReparentNotify:
4039 /* set background to ParentRelative for all parents */
4041 set_transparent_background(window.
4046 case ConfigureNotify:
4048 /* if window size isn't what expected, set fixed size */
4049 if (ev.xconfigure.width !=
4051 || ev.xconfigure.height !=
4053 if (window.width != 0
4054 && window.height != 0)
4057 /* clear old stuff before screwing up size and pos */
4063 if (XGetWindowAttributes(display, window.window, &attrs)) {
4078 border_margin * 2 - 1;
4081 border_margin * 2 - 1;
4082 if (text_width > maximum_width && maximum_width > 0)
4083 text_width = maximum_width;
4086 /* if position isn't what expected, set fixed pos, total_updates
4087 * avoids setting fixed_pos when window is set to weird locations
4089 /*if (total_updates >= 2 this is broken
4091 && (window.x != ev.xconfigure.x
4094 && (ev.xconfigure.x != 0
4095 || ev.xconfigure.y != 0)) {
4108 /* XDBE doesn't seem to provide a way to clear the back buffer without
4109 * interfering with the front buffer, other than passing XdbeBackground
4110 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
4111 * redraw the text even if it wasn't part of the exposed area. OTOH,
4112 * if we're not going to call draw_stuff at all, then no swap happens
4113 * and we can safely do nothing.
4116 if (!XEmptyRegion(region)) {
4120 r.x = text_start_x - border_margin;
4121 r.y = text_start_y - border_margin;
4122 r.width = text_width + border_margin * 2;
4123 r.height = text_height + border_margin * 2;
4124 XUnionRectWithRegion(&r, region, region);
4127 XSetRegion(display, window.gc, region);
4130 XftDrawSetClip(window.xftdraw, region);
4136 XDestroyRegion(region);
4137 region = XCreateRegion();
4144 static void load_config_file(const char *);
4146 /* signal handler that reloads config file */
4147 static void reload_handler(int a)
4149 ERR("Conky: received signal %d, reloading config\n", a);
4151 if (current_config) {
4153 load_config_file(current_config);
4158 extract_variable_text(text);
4165 static void clean_up()
4170 XdbeDeallocateBackBufferName(display, window.back_buffer);
4175 XDestroyWindow(display, window.window);
4179 XClearWindow(display, RootWindow(display, screen));
4184 XFreeGC(display, window.gc);
4188 /* it is really pointless to free() memory at the end of program but ak|ra
4189 * wants me to do this */
4191 free_text_objects();
4193 if (text != original_text)
4196 free(current_config);
4197 free(current_mail_spool);
4203 static void term_handler(int a)
4205 a = a; /* to get rid of warning */
4210 static int string_to_bool(const char *s)
4214 if (strcasecmp(s, "yes") == 0)
4216 if (strcasecmp(s, "true") == 0)
4218 if (strcasecmp(s, "1") == 0)
4223 static enum alignment string_to_alignment(const char *s)
4225 if (strcasecmp(s, "top_left") == 0)
4227 else if (strcasecmp(s, "top_right") == 0)
4229 else if (strcasecmp(s, "bottom_left") == 0)
4231 else if (strcasecmp(s, "bottom_right") == 0)
4232 return BOTTOM_RIGHT;
4233 else if (strcasecmp(s, "tl") == 0)
4235 else if (strcasecmp(s, "tr") == 0)
4237 else if (strcasecmp(s, "bl") == 0)
4239 else if (strcasecmp(s, "br") == 0)
4240 return BOTTOM_RIGHT;
4241 else if (strcasecmp(s, "none") == 0)
4248 static void set_default_configurations(void)
4250 fork_to_background = 0;
4251 total_run_times = 0;
4252 info.cpu_avg_samples = 2;
4253 info.net_avg_samples = 2;
4258 strcpy(info.mpd.host, "localhost");
4259 info.mpd.port = 6600;
4260 info.mpd.status = "Checking status...";
4269 default_fg_color = WhitePixel(display, screen);
4270 default_bg_color = BlackPixel(display, screen);
4271 default_out_color = BlackPixel(display, screen);
4275 set_first_font("6x10");
4284 stippled_borders = 0;
4287 text_alignment = BOTTOM_LEFT;
4291 free(current_mail_spool);
4294 variable_substitute(MAIL_FILE, buf, 256);
4296 current_mail_spool = strdup(buf);
4300 update_interval = 10.0;
4301 stuff_in_upper_case = 0;
4303 mlconfig.mldonkey_hostname = strdup("127.0.0.1");
4304 mlconfig.mldonkey_port = 4001;
4305 mlconfig.mldonkey_login = NULL;
4306 mlconfig.mldonkey_password = NULL;
4310 static void load_config_file(const char *f)
4312 #define CONF_ERR ERR("%s: %d: config file error", f, line)
4316 set_default_configurations();
4318 fp = open_file(f, 0);
4323 char buf[256], *p, *p2, *name, *value;
4325 if (fgets(buf, 256, fp) == NULL)
4330 /* break at comment */
4331 p2 = strchr(p, '#');
4336 while (*p && isspace((int) *p))
4339 continue; /* empty line */
4345 while (*p2 && !isspace((int) *p2))
4348 *p2 = '\0'; /* break at name's end */
4355 while (*p && isspace((int) *p))
4360 p2 = value + strlen(value);
4361 while (isspace((int) *(p2 - 1)))
4367 #define CONF2(a) if (strcasecmp(name, a) == 0)
4368 #define CONF(a) else CONF2(a)
4369 #define CONF3(a,b) \
4370 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
4374 CONF2("alignment") {
4376 int a = string_to_alignment(value);
4386 on_bottom = string_to_bool(value);
4390 CONF("background") {
4391 fork_to_background = string_to_bool(value);
4395 CONF2("background") {
4396 fork_to_background = string_to_bool(value);
4400 CONF("border_margin") {
4402 border_margin = strtol(value, 0, 0);
4406 CONF("border_width") {
4408 border_width = strtol(value, 0, 0);
4412 CONF("default_color") {
4414 default_fg_color = get_x11_color(value);
4418 CONF3("default_shade_color", "default_shadecolor") {
4420 default_bg_color = get_x11_color(value);
4424 CONF3("default_outline_color", "default_outlinecolor") {
4426 default_out_color = get_x11_color(value);
4434 strcpy(info.mpd.host, value);
4440 info.mpd.port = strtol(value, 0, 0);
4441 if (info.mpd.port < 1
4442 || info.mpd.port > 0xffff)
4447 CONF("cpu_avg_samples") {
4449 cpu_avg_samples = strtol(value, 0, 0);
4450 if (cpu_avg_samples < 1
4451 || cpu_avg_samples > 14)
4460 CONF("net_avg_samples") {
4462 net_avg_samples = strtol(value, 0, 0);
4463 if (net_avg_samples < 1
4464 || net_avg_samples > 14)
4480 CONF("double_buffer") {
4481 use_xdbe = string_to_bool(value);
4485 CONF("override_utf8_locale") {
4486 utf8_mode = string_to_bool(value);
4489 CONF("draw_borders") {
4490 draw_borders = string_to_bool(value);
4492 CONF("draw_shades") {
4493 draw_shades = string_to_bool(value);
4495 CONF("draw_outline") {
4496 draw_outline = string_to_bool(value);
4499 CONF("out_to_console") {
4500 out_to_console = string_to_bool(value);
4502 CONF("use_spacer") {
4503 use_spacer = string_to_bool(value);
4508 use_xft = string_to_bool(value);
4513 set_first_font(value);
4519 if (value && font_count >= 0)
4520 fonts[0].font_alpha = atof(value)
4528 if (string_to_bool(value))
4529 ERR("Xft not enabled");
4532 /* xftfont silently ignored when no Xft */
4535 /* xftalpha is silently ignored when no Xft */
4540 set_first_font(value);
4546 gap_x = atoi(value);
4552 gap_y = atoi(value);
4557 CONF("mail_spool") {
4560 variable_substitute(value, buf, 256);
4564 if (current_mail_spool)
4565 free(current_mail_spool);
4566 current_mail_spool = strdup(buf);
4572 CONF("minimum_size") {
4575 (value, "%d %d", &minimum_width,
4576 &minimum_height) != 2)
4579 &minimum_width) != 1)
4584 CONF("maximum_width") {
4586 if (sscanf(value, "%d", &maximum_width) != 1)
4592 CONF("no_buffers") {
4593 no_buffers = string_to_bool(value);
4596 CONF("mldonkey_hostname") {
4598 if (mlconfig.mldonkey_hostname != NULL) {
4599 free(mlconfig.mldonkey_hostname);
4601 mlconfig.mldonkey_hostname = strdup(value);
4606 CONF("mldonkey_port") {
4608 mlconfig.mldonkey_port = atoi(value);
4612 CONF("mldonkey_login") {
4614 if (mlconfig.mldonkey_login != NULL) {
4615 free(mlconfig.mldonkey_login);
4617 mlconfig.mldonkey_login = strdup(value);
4622 CONF("mldonkey_password") {
4624 if (mlconfig.mldonkey_password != NULL) {
4625 free(mlconfig.mldonkey_password);
4627 mlconfig.mldonkey_password = strdup(value);
4633 CONF("pad_percents") {
4634 pad_percents = atoi(value);
4638 CONF("own_window") {
4639 own_window = string_to_bool(value);
4641 CONF("own_window_transparent") {
4642 set_transparent = string_to_bool(value);
4644 CONF("own_window_colour") {
4645 background_colour = get_x11_color(value);
4648 CONF("stippled_borders") {
4650 stippled_borders = strtol(value, 0, 0);
4652 stippled_borders = 4;
4656 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
4659 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
4661 CONF("update_interval") {
4663 update_interval = strtod(value, 0);
4667 CONF("total_run_times") {
4669 total_run_times = strtod(value, 0);
4674 stuff_in_upper_case = string_to_bool(value);
4679 malloc(strlen(value)
4681 strcpy(seti_dir, value);
4685 if (text != original_text)
4695 int l = strlen(text);
4696 if (fgets(buf, 256, fp) == NULL)
4699 realloc(text, l + strlen(buf)
4703 if (strlen(text) > 1024 * 8)
4710 ERR("%s: %d: no such configuration: '%s'", f, line, name);
4720 /* : means that character before that takes an argument */
4721 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
4734 int main(int argc, char **argv)
4736 /* handle command line parameters that don't change configs */
4742 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
4743 *s) || ((s = getenv("LANG")) && *s)) {
4745 for(x = 0; x < strlen(s) ; x++) {
4746 temp[x] = tolower(s[x]);
4748 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
4752 if (!setlocale(LC_CTYPE, "")) {
4753 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
4757 int c = getopt(argc,
4767 ("Conky " VERSION " compiled " __DATE__ "\n");
4771 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
4772 * though free() does the NULL check itself;), then load optarg value */
4774 free(current_config);
4775 current_config = strdup(optarg);
4780 ("Usage: %s [OPTION]...\n"
4781 "Conky is a system monitor that renders text on desktop or to own transparent\n"
4782 "window. Command line options will override configurations defined in config\n"
4785 " -c FILE config file to load instead of "
4788 " -d daemonize, fork to background\n"
4791 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
4792 " -f FONT font to use\n"
4794 " -o create own window to draw\n"
4797 " -b double buffer (prevents flickering)\n"
4799 " -w WIN_ID window id to draw\n"
4800 " -x X x position\n"
4801 " -y Y y position\n"
4803 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
4804 " -u SECS update interval\n"
4805 " -i NUM number of times to update Conky\n", argv[0]);
4809 window.window = strtol(optarg, 0, 0);
4818 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
4822 tmpstring1 = (char *)
4823 malloc(TEXT_BUFFER_SIZE);
4824 tmpstring2 = (char *)
4825 malloc(TEXT_BUFFER_SIZE);
4827 /* load current_config or CONFIG_FILE */
4830 if (current_config == NULL) {
4831 /* load default config file */
4834 variable_substitute(CONFIG_FILE, buf, 256);
4837 current_config = strdup(buf);
4841 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
4842 load_config_file(current_config);
4844 set_default_configurations();
4848 if (current_mail_spool == NULL) {
4850 variable_substitute(MAIL_FILE, buf, 256);
4853 current_mail_spool = strdup(buf);
4857 /* handle other command line arguments */
4859 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
4860 optind = optreset = 1;
4866 int c = getopt(argc,
4874 fork_to_background = 1;
4879 set_first_font(optarg);
4882 text_alignment = string_to_alignment(optarg);
4897 if (text != original_text)
4899 text = strdup(optarg);
4900 convert_escapes(text);
4904 update_interval = strtod(optarg, 0);
4908 total_run_times = strtod(optarg, 0);
4912 gap_x = atoi(optarg);
4916 gap_y = atoi(optarg);
4930 /* generate text and get initial size */
4931 extract_variable_text(text);
4932 if (text != original_text) {
4941 update_text_area(); /* to get initial size of the window */
4943 #if defined OWN_WINDOW
4946 text_width + border_margin * 2 + 1,
4947 text_height + border_margin * 2 + 1,
4948 on_bottom, fixed_pos, set_transparent, background_colour);
4952 text_width + border_margin * 2 + 1,
4953 text_height + border_margin * 2 + 1,
4954 on_bottom, set_transparent, background_colour);
4958 update_text_area(); /* to position text/window on screen */
4962 // why the fuck not?
4968 if (own_window && !fixed_pos) {
4969 XMoveWindow(display, window.window, window.x, window.y);
4972 set_transparent_background(window.window);
4983 if (fork_to_background) {
4987 ERR("can't fork() to background: %s",
4997 "Conky: forked to background, pid is %d\n",
5003 /* set SIGUSR1, SIGINT and SIGTERM handlers */
5008 sa.sa_handler = reload_handler;
5009 sigemptyset(&sa.sa_mask);
5010 sa.sa_flags = SA_RESTART;
5011 if (sigaction(SIGUSR1, &sa, NULL) != 0)
5012 ERR("can't set signal handler for SIGUSR1: %s",
5015 sa.sa_handler = term_handler;
5016 sigemptyset(&sa.sa_mask);
5017 sa.sa_flags = SA_RESTART;
5018 if (sigaction(SIGINT, &sa, NULL) != 0)
5019 ERR("can't set signal handler for SIGINT: %s",
5022 sa.sa_handler = term_handler;
5023 sigemptyset(&sa.sa_mask);
5024 sa.sa_flags = SA_RESTART;
5025 if (sigaction(SIGTERM, &sa, NULL) != 0)
5026 ERR("can't set signal handler for SIGTERM: %s",