2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
27 #include <X11/Xutil.h>
29 #include <sys/types.h>
32 #define CONFIG_FILE "$HOME/.conkyrc"
33 #define MAIL_FILE "$MAIL"
34 #define MAX_IF_BLOCK_DEPTH 5
36 /* #define SIGNAL_BLOCKING */
37 #undef SIGNAL_BLOCKING
54 char name[TEXT_BUFFER_SIZE];
64 static int selected_font = 0;
65 static int font_count = -1;
66 struct font_list *fonts = NULL;
70 #define font_height() use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
71 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
72 #define font_ascent() use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent
73 #define font_descent() use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent
77 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
78 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
79 #define font_descent() fonts[selected_font].font->max_bounds.descent
83 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
86 static void set_font();
88 int addfont(const char *data_in)
90 if (font_count > MAX_FONTS) {
91 CRIT_ERR("you don't need that many fonts, sorry.");
94 if (font_count == 0) {
98 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
102 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
104 CRIT_ERR("realloc in addfont");
106 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
107 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
109 fonts[font_count].font_alpha = 0xffff;
112 CRIT_ERR("Oops...looks like something overflowed in addfont().");
117 void set_first_font(const char *data_in)
119 if (font_count < 0) {
120 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
125 if (strlen(data_in) > 1) {
126 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
128 fonts[0].font_alpha = 0xffff;
136 for (i=0;i<=font_count;i++) {
139 XftFontClose(display, fonts[i].xftfont);
143 XFreeFont(display, fonts[i].font);
150 set_first_font("6x10");
154 static void load_fonts()
157 for (i=0;i<=font_count;i++) {
161 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
162 XftFontClose(display, fonts[i].xftfont);
164 if ((fonts[i].xftfont =
165 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
168 ERR("can't load Xft font '%s'", fonts[i].name);
169 if ((fonts[i].xftfont =
170 XftFontOpenName(display, screen,
171 "courier-12")) != NULL)
174 ERR("can't load Xft font '%s'", "courier-12");
176 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
177 CRIT_ERR("can't load font '%s'", "fixed");
184 /* load normal font */
185 /* if (fonts[i].font != NULL)
186 XFreeFont(display, fonts[i].font);*/
188 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
189 ERR("can't load font '%s'", fonts[i].name);
190 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
191 CRIT_ERR("can't load font '%s'", "fixed");
192 printf("loaded fixed?\n");
200 /* default config file */
201 static char *current_config;
203 /* set to 1 if you want all text to be in uppercase */
204 static unsigned int stuff_in_upper_case;
206 /* Update interval */
207 static double update_interval;
209 /* Run how many times? */
210 static unsigned long total_run_times;
213 static int fork_to_background;
215 static int cpu_avg_samples, net_avg_samples;
219 /* Always on bottom */
220 static int on_bottom;
222 /* Position on the screen */
223 static int text_alignment;
224 static int gap_x, gap_y;
227 static int draw_borders;
228 static int draw_graph_borders;
229 static int stippled_borders;
231 static int draw_shades, draw_outline;
233 static int border_margin, border_width;
235 static long default_fg_color, default_bg_color, default_out_color;
237 /* create own window or draw stuff to root? */
238 static int set_transparent = 0;
242 static int own_window = 0;
243 static int background_colour = 0;
244 /* fixed size/pos is set if wm/user changes them */
245 static int fixed_size = 0, fixed_pos = 0;
248 static int minimum_width, minimum_height;
249 static int maximum_width;
256 /* no buffers in used memory? */
259 /* pad percentages to decimals? */
260 static int pad_percents = 0;
262 #ifdef TCP_PORT_MONITOR
263 tcp_port_monitor_collection_args_t tcp_port_monitor_collection_args;
264 tcp_port_monitor_args_t tcp_port_monitor_args;
267 /* Text that is shown */
268 static char original_text[] =
269 "$nodename - $sysname $kernel on $machine\n"
271 "${color grey}Uptime:$color $uptime\n"
272 "${color grey}Frequency (in MHz):$color $freq\n"
273 "${color grey}Frequency (in GHz):$color $freq_g\n"
274 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
275 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
276 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
277 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
279 "${color grey}File systems:\n"
280 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
281 "${color grey}Networking:\n"
282 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
285 "${color grey}SETI@Home Statistics:\n"
286 "${color grey}Seti Unit Number:$color $seti_credit\n"
287 "${color grey}Seti Progress:$color $seti_prog% $seti_progbar\n"
290 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
291 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
294 "${color grey}XMMS2: $xmms2_status $xmms2_artist - $xmms2_title from $xmms2_album\n"
295 "Progress: $xmms2_bar\n"
297 "${color grey}Name PID CPU% MEM%\n"
298 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
299 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
300 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
301 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
302 "${tail /var/log/Xorg.0.log 3}";
304 static char *text = original_text;
306 static int total_updates;
309 static int blockdepth = 0;
310 static int if_jumped = 0;
311 static int blockstart[MAX_IF_BLOCK_DEPTH];
313 int check_mount(char *s)
315 #if defined(__linux__)
317 FILE *mtab = fopen("/etc/mtab", "r");
319 char buf1[256], buf2[128];
320 while (fgets(buf1, 256, mtab)) {
321 sscanf(buf1, "%*s %128s", buf2);
322 if (!strcmp(s, buf2)) {
329 ERR("Could not open mtab");
332 #elif defined(__FreeBSD__)
333 struct statfs *mntbuf;
336 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
337 for (i = mntsize - 1; i >= 0; i--)
338 if (strcmp(mntbuf[i].f_mntonname, s) == 0)
347 static inline int calc_text_width(const char *s, int l)
353 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, s, l, &gi);
355 XftTextExtents8(display, fonts[selected_font].xftfont, s, l, &gi);
361 return XTextWidth(fonts[selected_font].font, s, l);
366 /* formatted text to render on screen, generated in generate_text(),
367 * drawn in draw_stuff() */
369 static char text_buffer[TEXT_BUFFER_SIZE * 4];
371 /* special stuff in text_buffer */
373 #define SPECIAL_CHAR '\x01'
390 static struct special_t {
400 unsigned long first_colour; // for graph gradient
401 unsigned long last_colour;
404 static int special_count;
406 static int special_index; /* used when drawing */
409 #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? */
411 static struct special_t *new_special(char *buf, int t)
413 if (special_count >= 512)
414 CRIT_ERR("too many special things in text");
416 buf[0] = SPECIAL_CHAR;
418 specials[special_count].type = t;
419 return &specials[special_count++];
422 typedef struct tailstring_list {
423 char data[TEXT_BUFFER_SIZE];
424 struct tailstring_list *next;
425 struct tailstring_list *first;
428 void addtail(tailstring ** head, char *data_in)
431 if ((tmp = malloc(sizeof(*tmp))) == NULL) {
437 tmp->first = (*head)->first;
439 strncpy(tmp->data, data_in, TEXT_BUFFER_SIZE);
444 void freetail(tailstring * head)
447 while (head != NULL) {
454 void freelasttail(tailstring * head)
456 tailstring * tmp = head;
458 if (tmp->next == head->first) {
465 while(head != NULL && tmp != NULL) {
471 static void new_bar(char *buf, int w, int h, int usage)
473 struct special_t *s = new_special(buf, BAR);
474 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
479 static const char *scan_bar(const char *args, int *w, int *h)
481 *w = 0; /* zero width means all space that is available */
483 /* bar's argument is either height or height,width */
486 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
487 sscanf(args, "%d %n", h, &n);
494 static char *scan_font(const char *args)
496 if (args && sizeof(args) < 127) {
500 ERR("font scan failed, lets hope it doesn't mess stuff up");
506 static void new_font(char *buf, char * args) {
507 struct special_t *s = new_special(buf, FONT);
508 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
509 int tmp = selected_font;
510 selected_font = s->font_added = addfont(args);
518 inline void graph_append(struct special_t *graph, double f)
520 if (!graph->scaled && f > graph->graph_scale) {
521 f = graph->graph_scale;
525 graph->graph_scale = 1;
527 graph->graph[0] = f; /* add new data */
528 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
529 graph->graph[i] = graph->graph[i - 1];
530 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
531 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
536 short colour_depth = 0;
537 void set_up_gradient();
539 /* precalculated: 31/255, and 63/255 */
540 #define CONST_8_TO_5_BITS 0.12156862745098
541 #define CONST_8_TO_6_BITS 0.247058823529412
543 /* adjust color values depending on color depth*/
544 static unsigned int adjust_colors(unsigned int color)
547 if (colour_depth == 0) {
550 if (colour_depth == 16) {
551 r = (color & 0xff0000) >> 16;
552 g = (color & 0xff00) >> 8;
554 color = (int)(r * CONST_8_TO_5_BITS) << 11;
555 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
556 color |= (int)(b * CONST_8_TO_5_BITS);
561 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
563 struct special_t *s = new_special(buf, GRAPH);
565 if (s->graph == NULL) {
566 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
567 s->graph_width = s->width - 3; // subtract 3 for the box
569 s->graph_width = MAX_GRAPH_DEPTH - 3;
571 s->graph = malloc(s->graph_width * sizeof(double));
572 memset(s->graph, 0, s->graph_width * sizeof(double));
573 s->graph_scale = 100;
576 s->first_colour = adjust_colors(first_colour);
577 s->last_colour = adjust_colors(second_colour);
584 s->graph_width = s->width - 3; // subtract 3 for rectangle around
589 s->graph_scale = scale;
596 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
598 *w = 0; /* zero width means all space that is available */
602 /* graph's argument is either height or height,width */
604 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
605 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
607 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
609 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
612 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
616 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
619 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
623 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
626 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
630 if (sscanf(args, "%d,%d", h, w) < 2) {
633 sscanf(args, "%*s %d,%d", h, w);
639 static inline void new_hr(char *buf, int a)
641 new_special(buf, HORIZONTAL_LINE)->height = a;
644 static inline void new_stippled_hr(char *buf, int a, int b)
646 struct special_t *s = new_special(buf, STIPPLED_HR);
651 static inline void new_fg(char *buf, long c)
653 new_special(buf, FG)->arg = c;
656 static inline void new_bg(char *buf, long c)
658 new_special(buf, BG)->arg = c;
661 static inline void new_outline(char *buf, long c)
663 new_special(buf, OUTLINE)->arg = c;
666 static inline void new_offset(char *buf, long c)
668 new_special(buf, OFFSET)->arg = c;
671 static inline void new_voffset(char *buf, long c)
673 new_special(buf, VOFFSET)->arg = c;
676 static inline void new_alignr(char *buf, long c)
678 new_special(buf, ALIGNR)->arg = c;
681 static inline void new_alignc(char *buf, long c)
683 new_special(buf, ALIGNC)->arg = c;
686 /* quite boring functions */
688 static inline void for_each_line(char *b, void (*f) (char *))
692 for (ps = b, pe = b; *pe; pe++) {
705 static void convert_escapes(char *buf)
707 char *p = buf, *s = buf;
723 /* converts from bytes to human readable format (k, M, G, T) */
724 static void human_readable(long long a, char *buf, int size)
726 // Strange conditional due to possible overflows
727 if(a / 1024 / 1024 / 1024.0 > 1024.0){
728 snprintf(buf, size, "%.2fT", (a / 1024 / 1024 / 1024) / 1024.0);
730 else if (a >= 1024 * 1024 * 1024) {
731 snprintf(buf, size, "%.2fG", (a / 1024 / 1024) / 1024.0);
733 else if (a >= 1024 * 1024) {
734 double m = (a / 1024) / 1024.0;
736 snprintf(buf, size, "%.0fM", m);
738 snprintf(buf, size, "%.1fM", m);
739 } else if (a >= 1024)
740 snprintf(buf, size, "%Ldk", a / (long long) 1024);
742 snprintf(buf, size, "%Ld", a);
747 enum text_object_type {
795 #if defined(__linux__)
801 OBJ_i8k_left_fan_status,
802 OBJ_i8k_right_fan_status,
803 OBJ_i8k_left_fan_rpm,
804 OBJ_i8k_right_fan_rpm,
806 OBJ_i8k_buttons_status,
811 #endif /* __linux__ */
838 OBJ_ml_upload_counter,
839 OBJ_ml_download_counter,
840 OBJ_ml_nshared_files,
841 OBJ_ml_shared_counter,
842 OBJ_ml_tcp_upload_rate,
843 OBJ_ml_tcp_download_rate,
844 OBJ_ml_udp_upload_rate,
845 OBJ_ml_udp_download_rate,
846 OBJ_ml_ndownloaded_files,
847 OBJ_ml_ndownloading_files,
850 OBJ_running_processes,
859 OBJ_temp1, /* i2c is used instead in these */
872 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
874 OBJ_apm_battery_time,
875 OBJ_apm_battery_life,
876 #endif /* __FreeBSD__ */
910 // OBJ_xmms2_bitrate,
921 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
925 OBJ_xmms_length_seconds,
927 OBJ_xmms_position_seconds,
932 OBJ_xmms_playlist_length,
933 OBJ_xmms_playlist_position,
944 #ifdef TCP_PORT_MONITOR
949 struct thread_info_s {
956 unsigned int c, d, e;
959 char *s; /* some string */
960 int i; /* some integer */
961 long l; /* some other integer */
963 struct net_stat *net;
965 unsigned char loadavg[3];
966 unsigned int cpu_index;
1008 struct thread_info_s thread_info;
1014 #ifdef TCP_PORT_MONITOR
1016 in_port_t port_range_begin; /* starting port to monitor */
1017 in_port_t port_range_end; /* ending port to monitor */
1018 int item; /* enum value from libtcp-portmon.h, e.g. COUNT, REMOTEIP, etc. */
1019 int connection_index; /* 0 to n-1 connections. */
1025 struct text_object_list {
1026 unsigned int text_object_count;
1027 struct text_object *text_objects;
1030 static unsigned int text_object_count;
1031 static struct text_object *text_objects;
1032 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1034 #define MAX_THREADS 512 // sure whatever
1035 typedef struct thread_info_s *thread_info;
1036 static thread_info thread_list[MAX_THREADS];
1037 static int thread_count = 0;
1038 static int threads_runnable = 1;
1040 int register_thread(struct thread_info_s *new_thread)
1042 if (thread_count >= MAX_THREADS) {
1043 CRIT_ERR("Uh oh, tried to register too many threads");
1045 thread_list[thread_count] = new_thread;
1048 return thread_count - 1;
1051 void replace_thread(struct thread_info_s *new_thread, int pos) // this isn't even used anymore; oh wells
1053 if (pos >= 0 && pos < MAX_THREADS) {
1054 thread_list[pos] = new_thread;
1056 ERR("thread position out of bounds");
1060 void *threaded_exec(struct text_object *obj) { // pthreads are really beginning to piss me off
1062 int run_code = threads_runnable;
1063 while (threads_runnable == run_code) {
1064 update_time = get_time();
1065 char *p2 = obj->data.execi.buffer;
1066 FILE *fp = popen(obj->data.execi.cmd,"r");
1067 int n2 = fread(p2, 1, TEXT_BUFFER_SIZE, fp);
1070 if (n2 && p2[n2 - 1] == '\n') {
1074 if (*p2 == '\001') {
1079 obj->data.execi.last_update = update_time;
1080 usleep(100); // prevent race condition
1081 if (get_time() - obj->data.execi.last_update > obj->data.execi.interval) {
1084 unsigned int delay = 1000000.0 * (obj->data.execi.interval -(get_time() - obj->data.execi.last_update));
1085 if (delay < update_interval * 500000) {
1086 delay = update_interval * 1000000;
1091 ERR("exiting thread");
1096 static struct text_object *new_text_object_internal()
1098 struct text_object *obj = malloc(sizeof(struct text_object));
1099 memset(obj, 0, sizeof(struct text_object));
1106 if (mlconfig.mldonkey_hostname) {
1107 free(mlconfig.mldonkey_hostname);
1108 mlconfig.mldonkey_hostname = NULL;
1113 static void free_text_objects(unsigned int count, struct text_object *objs)
1116 for (i = 0; i < count; i++) {
1117 switch (objs[i].type) {
1119 close(objs[i].data.i);
1122 close(objs[i].data.i);
1125 close(objs[i].data.i2c.fd);
1128 free(objs[i].data.s);
1131 case OBJ_if_existing:
1132 case OBJ_if_mounted:
1133 case OBJ_if_running:
1134 free(objs[i].data.ifblock.s);
1137 free(objs[i].data.tail.logfile);
1138 free(objs[i].data.tail.buffer);
1140 case OBJ_text: case OBJ_font:
1141 free(objs[i].data.s);
1144 free(objs[i].data.s);
1147 free(objs[i].data.s);
1150 free(objs[i].data.s);
1152 /* case OBJ_execibar:
1153 free(objs[i].data.s);
1155 case OBJ_execigraph:
1156 free(objs[i].data.s);
1160 if (info.mpd.title) {
1161 free(info.mpd.title);
1165 case OBJ_mpd_artist:
1166 if (info.mpd.artist) {
1167 free(info.mpd.artist);
1168 info.mpd.artist = 0;
1172 if (info.mpd.album) {
1173 free(info.mpd.album);
1177 case OBJ_mpd_random:
1178 if (info.mpd.random) {
1179 free(info.mpd.random);
1180 info.mpd.random = 0;
1183 case OBJ_mpd_repeat:
1184 if (info.mpd.repeat) {
1185 free(info.mpd.repeat);
1186 info.mpd.repeat = 0;
1190 if (info.mpd.track) {
1191 free(info.mpd.track);
1196 if (info.mpd.name) {
1197 free(info.mpd.name);
1202 if (info.mpd.file) {
1203 free(info.mpd.file);
1207 case OBJ_mpd_status:
1208 if (info.mpd.status) {
1209 free(info.mpd.status);
1210 info.mpd.status = 0;
1214 if (info.mpd.artist) {
1215 free(info.mpd.artist);
1216 info.mpd.artist = 0;
1218 if (info.mpd.title) {
1219 free(info.mpd.title);
1222 if (info.mpd.file) {
1223 free(info.mpd.file);
1230 case OBJ_xmms2_title:
1231 if (info.xmms2.title) {
1232 free(info.xmms2.title);
1233 info.xmms2.title = 0;
1236 case OBJ_xmms2_artist:
1237 if (info.xmms2.artist) {
1238 free(info.xmms2.artist);
1239 info.xmms2.artist = 0;
1242 case OBJ_xmms2_album:
1243 if (info.xmms2.album) {
1244 free(info.xmms2.album);
1245 info.xmms2.album = 0;
1248 case OBJ_xmms2_track:
1249 if (info.xmms2.track) {
1250 free(info.xmms2.track);
1251 info.xmms2.track = 0;
1254 case OBJ_xmms2_file:
1255 if (info.xmms2.file) {
1256 free(info.xmms2.file);
1257 info.xmms2.file = 0;
1260 case OBJ_xmms2_status:
1261 if (info.xmms2.status) {
1262 free(info.xmms2.status);
1263 info.xmms2.status = 0;
1266 /* case OBJ_xmms2_smart:
1267 if (info.xmms2.artist) {
1268 free(info.xmms2.artist);
1269 info.xmms2.artist = 0;
1271 if (info.xmms2.title) {
1272 free(info.xmms2.title);
1273 info.xmms2.title = 0;
1275 if (info.xmms2.file) {
1276 free(info.xmms2.file);
1277 info.xmms2.file = 0;
1282 case OBJ_bmpx_title:
1283 case OBJ_bmpx_artist:
1284 case OBJ_bmpx_album:
1285 case OBJ_bmpx_track:
1287 case OBJ_bmpx_bitrate:
1291 free(objs[i].data.s);
1295 free(objs[i].data.execi.cmd);
1296 free(objs[i].data.execi.buffer);
1299 free(objs[i].data.execi.cmd);
1300 free(objs[i].data.execi.buffer);
1303 if (info.first_process) {
1304 free_all_processes();
1305 info.first_process = NULL;
1309 if (info.first_process) {
1310 free_all_processes();
1311 info.first_process = NULL;
1317 //text_objects = NULL;
1318 //text_object_count = 0;
1321 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1326 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1327 *a = mixer_init(buf1);
1328 (void) scan_bar(arg + n, w, h);
1331 (void) scan_bar(arg, w, h);
1336 /* construct_text_object() creates a new text_object */
1337 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects)
1339 //struct text_object *obj = new_text_object();
1340 struct text_object *obj = new_text_object_internal();
1342 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
1343 #define END ; } } else
1347 obj->type = OBJ_color;
1348 obj->data.l = get_x11_color(s);
1351 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
1352 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
1353 END OBJ(acpiacadapter, 0)
1356 END OBJ(freq_dyn, 0);
1357 END OBJ(freq_dyn_g, 0);
1358 END OBJ(acpifan, 0);
1359 END OBJ(battery, 0);
1362 sscanf(arg, "%63s", bat);
1364 strcpy(bat, "BAT0");
1365 obj->data.s = strdup(bat);
1366 #if defined(__linux__)
1367 END OBJ(i8k_version, INFO_I8K)
1368 END OBJ(i8k_bios, INFO_I8K)
1369 END OBJ(i8k_serial, INFO_I8K)
1370 END OBJ(i8k_cpu_temp, INFO_I8K)
1371 END OBJ(i8k_cpu_tempf, INFO_I8K)
1372 END OBJ(i8k_left_fan_status, INFO_I8K)
1373 END OBJ(i8k_right_fan_status, INFO_I8K)
1374 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1375 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1376 END OBJ(i8k_ac_status, INFO_I8K)
1377 END OBJ(i8k_buttons_status, INFO_I8K)
1379 END OBJ(ibm_temps, 0)
1380 if (!isdigit(arg[0])
1382 || atoi(&arg[0]) >=8)
1385 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
1387 obj->data.sensor = atoi(&arg[0]);
1388 END OBJ(ibm_volume, 0)
1389 END OBJ(ibm_brightness, 0)
1391 #endif /* __linux__ */
1392 END OBJ(buffers, INFO_BUFFERS)
1393 END OBJ(cached, INFO_BUFFERS)
1394 END OBJ(cpu, INFO_CPU)
1396 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1397 obj->data.cpu_index = atoi(&arg[3]);
1399 } else {obj->data.cpu_index = 0; }
1401 obj->data.cpu_index = 0;
1403 END OBJ(cpubar, INFO_CPU)
1405 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1406 obj->data.cpu_index = atoi(&arg[3]);
1409 else {obj->data.cpu_index = 0;}
1410 (void) scan_bar(arg, &obj->a, &obj->b);
1412 (void) scan_bar(arg, &obj->a, &obj->b);
1413 obj->data.cpu_index = 0;
1415 END OBJ(cpugraph, INFO_CPU)
1417 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1418 obj->data.cpu_index = atoi(&arg[3]);
1421 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1423 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1424 obj->data.cpu_index = 0;
1426 END OBJ(diskio, INFO_DISKIO)
1427 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1430 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1434 obj->data.s = scan_font(arg);
1436 OBJ(downspeed, INFO_NET)
1438 obj->data.net = get_net_stat(arg);
1441 CRIT_ERR("downspeed needs argument");
1443 END OBJ(downspeedf, INFO_NET)
1445 obj->data.net = get_net_stat(arg);
1448 CRIT_ERR("downspeedf needs argument");
1450 END OBJ(downspeedgraph, INFO_NET)
1451 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1453 sscanf(arg, "%63s %*i,%*i %*i", buf);
1454 obj->data.net = get_net_stat(buf);
1455 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
1456 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
1463 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
1464 blockstart[blockdepth - 1] = object_count;
1465 obj->data.ifblock.pos = object_count + 2;
1467 ERR("$else: no matching $if_*");
1472 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
1474 ERR("$endif: no matching $if_*");
1478 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
1479 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
1480 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
1481 END OBJ(execibar, 0) unsigned int n;
1482 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1484 ERR("${execibar <interval> command}");
1485 obj->type = OBJ_text;
1486 snprintf(buf, 256, "${%s}", s);
1487 obj->data.s = strdup(buf);
1489 obj->data.execi.cmd = strdup(arg + n);
1491 END OBJ(execigraph, 0) unsigned int n;
1492 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1494 ERR("${execigraph <interval> command}");
1495 obj->type = OBJ_text;
1496 snprintf(buf, 256, "${%s}", s);
1497 obj->data.s = strdup(buf);
1499 obj->data.execi.cmd = strdup(arg + n);
1501 END OBJ(execi, 0) unsigned int n;
1504 || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1506 ERR("${execi <interval> command}");
1507 obj->type = OBJ_text;
1508 snprintf(buf, 256, "${%s}", s);
1509 obj->data.s = strdup(buf);
1511 obj->data.execi.cmd = strdup(arg + n);
1512 obj->data.execi.buffer =
1513 (char *) calloc(1, TEXT_BUFFER_SIZE);
1515 END OBJ(texeci, 0) unsigned int n;
1517 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1519 ERR("${texeci <interval> command}");
1520 obj->type = OBJ_text;
1521 snprintf(buf, 256, "${%s}", s);
1522 obj->data.s = strdup(buf);
1524 obj->data.execi.cmd = strdup(arg + n);
1525 obj->data.execi.buffer =
1526 (char *) calloc(1, TEXT_BUFFER_SIZE);
1528 obj->data.execi.pos = -1;
1529 END OBJ(pre_exec, 0) obj->type = OBJ_text;
1531 FILE *fp = popen(arg, "r");
1535 n = fread(buf, 1, 2048, fp);
1538 if (n && buf[n - 1] == '\n')
1543 obj->data.s = strdup(buf);
1545 obj->data.s = strdup("");
1548 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
1549 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1551 while (isspace(*arg))
1557 obj->data.fsbar.fs = prepare_fs_stat(arg);
1558 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
1561 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
1565 obj->data.fsbar.fs = prepare_fs_stat(arg);
1566 END OBJ(fs_free, INFO_FS) if (!arg)
1568 obj->data.fs = prepare_fs_stat(arg);
1569 END OBJ(fs_used_perc, INFO_FS) if (!arg)
1571 obj->data.fs = prepare_fs_stat(arg);
1572 END OBJ(fs_free_perc, INFO_FS) if (!arg)
1574 obj->data.fs = prepare_fs_stat(arg);
1575 END OBJ(fs_size, INFO_FS) if (!arg)
1577 obj->data.fs = prepare_fs_stat(arg);
1578 END OBJ(fs_used, INFO_FS) if (!arg)
1580 obj->data.fs = prepare_fs_stat(arg);
1581 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
1582 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
1583 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
1584 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
1588 ERR("i2c needs arguments");
1589 obj->type = OBJ_text;
1590 //obj->data.s = strdup("${i2c}");
1594 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
1595 /* if scanf couldn't read three values, read type and num and use
1597 sscanf(arg, "%63s %d", buf2, &n);
1599 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
1600 obj->data.i2c.devtype);
1601 strncpy(obj->data.i2c.type, buf2, 63);
1604 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
1605 obj->data.i2c.devtype);
1606 strncpy(obj->data.i2c.type, buf2, 63);
1609 END OBJ(top, INFO_TOP)
1613 ERR("top needs arguments");
1614 obj->type = OBJ_text;
1615 //obj->data.s = strdup("${top}");
1618 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1619 if (strcmp(buf, "name") == 0) {
1620 obj->data.top.type = TOP_NAME;
1621 } else if (strcmp(buf, "cpu") == 0) {
1622 obj->data.top.type = TOP_CPU;
1623 } else if (strcmp(buf, "pid") == 0) {
1624 obj->data.top.type = TOP_PID;
1625 } else if (strcmp(buf, "mem") == 0) {
1626 obj->data.top.type = TOP_MEM;
1628 ERR("invalid arg for top");
1631 if (n < 1 || n > 10) {
1632 CRIT_ERR("invalid arg for top");
1635 obj->data.top.num = n - 1;
1639 ERR("invalid args given for top");
1642 END OBJ(top_mem, INFO_TOP)
1646 ERR("top_mem needs arguments");
1647 obj->type = OBJ_text;
1648 obj->data.s = strdup("${top_mem}");
1651 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1652 if (strcmp(buf, "name") == 0) {
1653 obj->data.top.type = TOP_NAME;
1654 } else if (strcmp(buf, "cpu") == 0) {
1655 obj->data.top.type = TOP_CPU;
1656 } else if (strcmp(buf, "pid") == 0) {
1657 obj->data.top.type = TOP_PID;
1658 } else if (strcmp(buf, "mem") == 0) {
1659 obj->data.top.type = TOP_MEM;
1661 ERR("invalid arg for top");
1664 if (n < 1 || n > 10) {
1665 CRIT_ERR("invalid arg for top");
1668 obj->data.top.num = n - 1;
1672 ERR("invalid args given for top");
1675 END OBJ(addr, INFO_NET)
1677 obj->data.net = get_net_stat(arg);
1680 CRIT_ERR("addr needs argument");
1682 END OBJ(linkstatus, INFO_WIFI)
1684 obj->data.net = get_net_stat(arg);
1687 CRIT_ERR("linkstatus needs argument");
1693 ERR("tail needs arguments");
1694 obj->type = OBJ_text;
1695 obj->data.s = strdup("${tail}");
1698 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
1699 if (n1 < 1 || n1 > 30) {
1700 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
1704 fp = fopen(buf, "r");
1706 obj->data.tail.logfile =
1707 malloc(TEXT_BUFFER_SIZE);
1708 strcpy(obj->data.tail.logfile, buf);
1709 obj->data.tail.wantedlines = n1 - 1;
1710 obj->data.tail.interval =
1711 update_interval * 2;
1715 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
1718 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
1719 if (n1 < 1 || n1 > 30) {
1721 ("invalid arg for tail, number of lines must be between 1 and 30");
1723 } else if (n2 < 1 || n2 < update_interval) {
1725 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
1729 fp = fopen(buf, "r");
1731 obj->data.tail.logfile =
1732 malloc(TEXT_BUFFER_SIZE);
1733 strcpy(obj->data.tail.logfile, buf);
1734 obj->data.tail.wantedlines = n1 - 1;
1735 obj->data.tail.interval = n2;
1739 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
1745 ERR("invalid args given for tail");
1748 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
1753 ERR("head needs arguments");
1754 obj->type = OBJ_text;
1755 obj->data.s = strdup("${head}");
1758 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
1759 if (n1 < 1 || n1 > 30) {
1760 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
1764 fp = fopen(buf, "r");
1766 obj->data.tail.logfile =
1767 malloc(TEXT_BUFFER_SIZE);
1768 strcpy(obj->data.tail.logfile, buf);
1769 obj->data.tail.wantedlines = n1 - 1;
1770 obj->data.tail.interval =
1771 update_interval * 2;
1775 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
1778 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
1779 if (n1 < 1 || n1 > 30) {
1781 ("invalid arg for head, number of lines must be between 1 and 30");
1783 } else if (n2 < 1 || n2 < update_interval) {
1785 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
1789 fp = fopen(buf, "r");
1791 obj->data.tail.logfile =
1792 malloc(TEXT_BUFFER_SIZE);
1793 strcpy(obj->data.tail.logfile, buf);
1794 obj->data.tail.wantedlines = n1 - 1;
1795 obj->data.tail.interval = n2;
1799 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
1805 ERR("invalid args given for head");
1808 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
1809 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
1811 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1812 if (r >= 3 && (c < 1 || c > 3))
1814 if (r >= 2 && (b < 1 || b > 3))
1816 if (r >= 1 && (a < 1 || a > 3))
1819 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1820 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1821 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1822 END OBJ(if_existing, 0)
1823 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1824 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1827 ERR("if_existing needs an argument");
1828 obj->data.ifblock.s = 0;
1830 obj->data.ifblock.s = strdup(arg);
1831 blockstart[blockdepth] = object_count;
1832 obj->data.ifblock.pos = object_count + 2;
1834 END OBJ(if_mounted, 0)
1835 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1836 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1839 ERR("if_mounted needs an argument");
1840 obj->data.ifblock.s = 0;
1842 obj->data.ifblock.s = strdup(arg);
1843 blockstart[blockdepth] = object_count;
1844 obj->data.ifblock.pos = object_count + 2;
1846 END OBJ(if_running, 0)
1847 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1848 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1852 snprintf(buf, 256, "pidof %s >/dev/null", arg);
1853 obj->data.ifblock.s = strdup(buf);
1855 ERR("if_running needs an argument");
1856 obj->data.ifblock.s = 0;
1858 blockstart[blockdepth] = object_count;
1859 obj->data.ifblock.pos = object_count + 2;
1863 END OBJ(mails, INFO_MAIL)
1864 END OBJ(mem, INFO_MEM)
1865 END OBJ(memmax, INFO_MEM)
1866 END OBJ(memperc, INFO_MEM)
1867 END OBJ(membar, INFO_MEM)
1868 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1869 END OBJ(memgraph, INFO_MEM)
1870 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1871 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
1872 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
1873 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
1874 END OBJ(mixerbar, INFO_MIXER)
1875 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1876 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1877 END OBJ(mixerlbar, INFO_MIXER)
1878 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1879 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1880 END OBJ(mixerrbar, INFO_MIXER)
1881 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1882 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1885 OBJ(ml_upload_counter, INFO_MLDONKEY)
1886 END OBJ(ml_download_counter, INFO_MLDONKEY)
1887 END OBJ(ml_nshared_files, INFO_MLDONKEY)
1888 END OBJ(ml_shared_counter, INFO_MLDONKEY)
1889 END OBJ(ml_tcp_upload_rate, INFO_MLDONKEY)
1890 END OBJ(ml_tcp_download_rate, INFO_MLDONKEY)
1891 END OBJ(ml_udp_upload_rate, INFO_MLDONKEY)
1892 END OBJ(ml_udp_download_rate, INFO_MLDONKEY)
1893 END OBJ(ml_ndownloaded_files, INFO_MLDONKEY)
1894 END OBJ(ml_ndownloading_files, INFO_MLDONKEY) END
1896 OBJ(new_mails, INFO_MAIL)
1897 END OBJ(nodename, 0)
1898 END OBJ(processes, INFO_PROCS)
1899 END OBJ(running_processes, INFO_RUN_PROCS)
1900 END OBJ(shadecolor, 0)
1902 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
1904 END OBJ(outlinecolor, 0)
1906 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
1908 END OBJ(stippled_hr, 0)
1910 int a = stippled_borders, b = 1;
1912 if (sscanf(arg, "%d %d", &a, &b) != 2)
1913 sscanf(arg, "%d", &b);
1917 obj->data.pair.a = a;
1918 obj->data.pair.b = b;
1920 END OBJ(swap, INFO_MEM)
1921 END OBJ(swapmax, INFO_MEM)
1922 END OBJ(swapperc, INFO_MEM)
1923 END OBJ(swapbar, INFO_MEM)
1924 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1925 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
1927 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
1928 obj->data.i2c.devtype);
1929 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
1931 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
1932 obj->data.i2c.devtype);
1933 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1934 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1935 END OBJ(totaldown, INFO_NET)
1937 obj->data.net = get_net_stat(arg);
1940 CRIT_ERR("totaldown needs argument");
1942 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
1944 obj->data.net = get_net_stat(arg);
1947 CRIT_ERR("totalup needs argument");
1950 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
1951 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
1952 END OBJ(upspeed, INFO_NET)
1954 obj->data.net = get_net_stat(arg);
1957 CRIT_ERR("upspeed needs argument");
1959 END OBJ(upspeedf, INFO_NET)
1961 obj->data.net = get_net_stat(arg);
1964 CRIT_ERR("upspeedf needs argument");
1967 END OBJ(upspeedgraph, INFO_NET)
1968 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1970 sscanf(arg, "%63s %*i,%*i %*i", buf);
1971 obj->data.net = get_net_stat(buf);
1972 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
1973 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
1978 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
1979 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
1980 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
1981 OBJ(apm_adapter, 0) END
1982 OBJ(apm_battery_life, 0) END
1983 OBJ(apm_battery_time, 0) END
1984 #endif /* __FreeBSD__ */
1986 OBJ(seti_prog, INFO_SETI) END OBJ(seti_progbar, INFO_SETI)
1987 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1988 END OBJ(seti_credit, INFO_SETI) END
1991 OBJ(mpd_artist, INFO_MPD)
1992 END OBJ(mpd_title, INFO_MPD)
1993 END OBJ(mpd_random, INFO_MPD)
1994 END OBJ(mpd_repeat, INFO_MPD)
1995 END OBJ(mpd_elapsed, INFO_MPD)
1996 END OBJ(mpd_length, INFO_MPD)
1997 END OBJ(mpd_track, INFO_MPD)
1998 END OBJ(mpd_name, INFO_MPD)
1999 END OBJ(mpd_file, INFO_MPD)
2000 END OBJ(mpd_percent, INFO_MPD)
2001 END OBJ(mpd_album, INFO_MPD)
2002 END OBJ(mpd_vol, INFO_MPD)
2003 END OBJ(mpd_bitrate, INFO_MPD)
2004 END OBJ(mpd_status, INFO_MPD)
2005 END OBJ(mpd_bar, INFO_MPD)
2006 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2007 END OBJ(mpd_smart, INFO_MPD) END
2010 OBJ(xmms2_artist, INFO_XMMS2)
2011 END OBJ(xmms2_title, INFO_XMMS2)
2012 END OBJ(xmms2_length, INFO_XMMS2)
2013 END OBJ(xmms2_track, INFO_XMMS2)
2014 END OBJ(xmms2_file, INFO_XMMS2)
2015 END OBJ(xmms2_album, INFO_XMMS2)
2016 END OBJ(xmms2_status, INFO_XMMS2)
2017 END OBJ(xmms2_elapsed, INFO_XMMS2)
2018 END OBJ(xmms2_length, INFO_XMMS2)
2019 END OBJ(xmms2_percent, INFO_XMMS2)
2020 END OBJ(xmms2_bar, INFO_XMMS2)
2021 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2024 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
2025 OBJ(xmms_status, INFO_XMMS) END
2026 OBJ(xmms_title, INFO_XMMS) END
2027 OBJ(xmms_length, INFO_XMMS) END
2028 OBJ(xmms_length_seconds, INFO_XMMS) END
2029 OBJ(xmms_position, INFO_XMMS) END
2030 OBJ(xmms_position_seconds, INFO_XMMS) END
2031 OBJ(xmms_bitrate, INFO_XMMS) END
2032 OBJ(xmms_frequency, INFO_XMMS) END
2033 OBJ(xmms_channels, INFO_XMMS) END
2034 OBJ(xmms_filename, INFO_XMMS) END
2035 OBJ(xmms_playlist_length, INFO_XMMS) END
2036 OBJ(xmms_playlist_position, INFO_XMMS) END
2037 OBJ(xmms_bar, INFO_XMMS)
2038 (void) scan_bar(arg, &obj->a, &obj->b);
2042 OBJ(bmpx_title, INFO_BMPX)
2043 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2045 OBJ(bmpx_artist, INFO_BMPX)
2046 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2048 OBJ(bmpx_album, INFO_BMPX)
2049 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2051 OBJ(bmpx_track, INFO_BMPX)
2052 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2054 OBJ(bmpx_uri, INFO_BMPX)
2055 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2057 OBJ(bmpx_bitrate, INFO_BMPX)
2058 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2061 #ifdef TCP_PORT_MONITOR
2062 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
2063 int argc, port_begin, port_end, item, connection_index;
2065 memset(itembuf,0,sizeof(itembuf));
2067 /* massive argument checking */
2069 CRIT_ERR("tcp_portmon: needs arguments");
2071 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
2072 if ( (argc != 3) && (argc != 4) )
2074 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
2076 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
2078 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
2080 if ( port_begin > port_end )
2082 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
2084 if ( strncmp(itembuf,"count",31) == 0 )
2086 else if ( strncmp(itembuf,"rip",31) == 0 )
2088 else if ( strncmp(itembuf,"rhost",31) == 0 )
2090 else if ( strncmp(itembuf,"rport",31) == 0 )
2092 else if ( strncmp(itembuf,"rservice",31) == 0 )
2094 else if ( strncmp(itembuf,"lip",31) == 0 )
2096 else if ( strncmp(itembuf,"lhost",31) == 0 )
2098 else if ( strncmp(itembuf,"lport",31) == 0 )
2100 else if ( strncmp(itembuf,"lservice",31) == 0 )
2104 CRIT_ERR("tcp_portmon: invalid item specified");
2106 if ( (argc==3) && (item!=COUNT) )
2108 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
2110 if ( (argc==4) && (connection_index<0) )
2112 CRIT_ERR("tcp_portmon: connection index must be non-negative");
2114 /* ok, args looks good. save the text object data */
2115 obj->data.tcp_port_monitor.port_range_begin = (in_addr_t)port_begin;
2116 obj->data.tcp_port_monitor.port_range_end = (in_addr_t)port_end;
2117 obj->data.tcp_port_monitor.item = item;
2118 obj->data.tcp_port_monitor.connection_index = connection_index;
2120 /* if the port monitor collection hasn't been created, we must create it */
2121 if ( !info.p_tcp_port_monitor_collection )
2123 info.p_tcp_port_monitor_collection =
2124 create_tcp_port_monitor_collection( &tcp_port_monitor_collection_args );
2125 if ( !info.p_tcp_port_monitor_collection )
2127 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
2131 /* if a port monitor for this port does not exist, create one and add it to the collection */
2132 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
2134 tcp_port_monitor_t * p_monitor =
2135 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
2138 CRIT_ERR("tcp_portmon: unable to create port monitor");
2140 /* add the newly created monitor to the collection */
2141 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
2144 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
2151 ERR("unknown variable %s", s);
2152 obj->type = OBJ_text;
2153 snprintf(buf, 256, "${%s}", s);
2154 obj->data.s = strdup(buf);
2161 static struct text_object *create_plain_text(const char *s)
2163 struct text_object *obj;
2165 if (s == NULL || *s == '\0') {
2169 obj = new_text_object_internal();
2171 obj->type = OBJ_text;
2172 obj->data.s = strdup(s);
2176 static struct text_object_list *extract_variable_text_internal(const char *p)
2178 struct text_object_list *retval;
2179 struct text_object *obj;
2182 retval = malloc(sizeof(struct text_object_list));
2183 memset(retval, 0, sizeof(struct text_object_list));
2184 retval->text_object_count = 0;
2189 obj = create_plain_text(s);
2191 // allocate memory for the object
2192 retval->text_objects = realloc(retval->text_objects,
2193 sizeof(struct text_object) * (retval->text_object_count+1));
2194 // assign the new object to the end of the list.
2195 memcpy(&retval->text_objects[retval->text_object_count++],
2196 obj, sizeof(struct text_object));
2208 /* variable is either $foo or ${foo} */
2212 while (*p && *p != '}')
2218 while (*p && (isalnum((int) *p)
2223 /* copy variable to buffer */
2224 len = (p - s > 255) ? 255 : (p - s);
2225 strncpy(buf, s, len);
2234 /* if variable wasn't found from environment, use some special */
2240 if (strchr(buf, ' ')) {
2241 arg = strchr(buf, ' ');
2244 while (isspace((int) *arg))
2250 /* lowercase variable name */
2257 // create new object
2258 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects);
2260 // allocate memory for the object
2261 retval->text_objects = realloc(retval->text_objects,
2262 sizeof(struct text_object) * (retval->text_object_count+1));
2263 // assign the new object to the end of the list.
2264 memcpy(&retval->text_objects[retval->text_object_count++],
2265 obj, sizeof(struct text_object));
2271 obj = create_plain_text("$");
2273 // allocate memory for the object
2274 retval->text_objects = realloc(retval->text_objects,
2275 sizeof(struct text_object) * (retval->text_object_count+1));
2276 // assign the new object to the end of the list.
2277 memcpy(&retval->text_objects[retval->text_object_count++],
2278 obj, sizeof(struct text_object));
2285 obj = create_plain_text(s);
2287 // allocate memory for the object
2288 retval->text_objects = realloc(retval->text_objects,
2289 sizeof(struct text_object) * (retval->text_object_count+1));
2290 // assign the new object to the end of the list.
2291 memcpy(&retval->text_objects[retval->text_object_count++],
2292 obj, sizeof(struct text_object));
2297 ERR("one or more $endif's are missing");
2303 static void extract_variable_text(const char *p)
2305 struct text_object_list *list;
2307 free_text_objects(text_object_count, text_objects);
2308 text_object_count = 0;
2309 text_objects = NULL;
2313 #endif /* MLDONKEY */
2315 list = extract_variable_text_internal(p);
2316 text_objects = list->text_objects;
2317 text_object_count = list->text_object_count;
2324 void parse_conky_vars(char * text, char * p, struct information *cur) {
2325 struct text_object_list *object_list = extract_variable_text_internal(text);
2326 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
2330 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
2333 for (i = 0; i < object_count; i++) {
2334 struct text_object *obj = &objs[i];
2336 #define OBJ(a) break; case OBJ_##a:
2338 switch (obj->type) {
2341 ERR("not implemented obj type %d",
2345 /* does anyone have decimals in acpi temperature? */
2347 snprintf(p, p_max_size, "%d", (int)
2348 get_acpi_temperature(obj->
2352 snprintf(p, 5, "%d ", (int)
2353 get_acpi_temperature(obj->
2358 /* does anyone have decimals in acpi temperature? */
2360 snprintf(p, p_max_size, "%d", (int)
2361 ((get_acpi_temperature(obj->
2363 i)+ 40) * 9.0 / 5 - 40));
2365 snprintf(p, 5, "%d ", (int)
2366 ((get_acpi_temperature(obj->
2368 i)+ 40) * 9.0 / 5 - 40));
2371 get_freq(p, p_max_size, "%.0f", 1); /* pk */
2374 get_freq(p, p_max_size, "%'.2f", 1000); /* pk */
2378 get_freq_dynamic(p, 6, "%.0f ", 1 ); /* pk */
2380 get_freq_dynamic(p, p_max_size, "%.0f", 1 ); /* pk */
2385 get_freq_dynamic(p, 6, "%'.2f ", 1000); /* pk */
2387 get_freq_dynamic(p, p_max_size, "%'.2f", 1000); /* pk */
2391 get_adt746x_cpu(p, p_max_size); /* pk */
2394 get_adt746x_fan(p, p_max_size); /* pk */
2397 get_acpi_fan(p, p_max_size); /* pk */
2399 OBJ(acpiacadapter) {
2400 get_acpi_ac_adapter(p, p_max_size); /* pk */
2403 get_battery_stuff(p, p_max_size, obj->data.s);
2406 human_readable(cur->buffers * 1024, p, 255);
2409 human_readable(cur->cached * 1024, p, 255);
2412 if (obj->data.cpu_index > info.cpu_count) {
2413 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
2414 CRIT_ERR("attempting to use more CPUs then you have!");
2417 snprintf(p, p_max_size, "%*d", pad_percents,
2418 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
2421 snprintf(p, 4, "%*d ",
2423 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
2429 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
2432 new_graph(p, obj->a,
2433 obj->b, obj->c, obj->d,
2434 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
2438 new_fg(p, obj->data.l);
2440 #if defined(__linux__)
2442 snprintf(p, p_max_size, "%s", i8k.version);
2445 snprintf(p, p_max_size, "%s", i8k.bios);
2448 snprintf(p, p_max_size, "%s", i8k.serial);
2451 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
2453 OBJ(i8k_cpu_tempf) {
2455 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
2456 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
2458 OBJ(i8k_left_fan_status) {
2459 int left_fan_status;
2460 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
2461 if(left_fan_status == 0) {
2462 snprintf(p, p_max_size,"off");
2463 } if(left_fan_status == 1) {
2464 snprintf(p, p_max_size, "low");
2465 } if(left_fan_status == 2) {
2466 snprintf(p, p_max_size, "high");
2470 OBJ(i8k_right_fan_status) {
2471 int right_fan_status;
2472 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
2473 if(right_fan_status == 0) {
2474 snprintf(p, p_max_size,"off");
2475 } if(right_fan_status == 1) {
2476 snprintf(p, p_max_size, "low");
2477 } if(right_fan_status == 2) {
2478 snprintf(p, p_max_size, "high");
2481 OBJ(i8k_left_fan_rpm) {
2482 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
2484 OBJ(i8k_right_fan_rpm) {
2485 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
2487 OBJ(i8k_ac_status) {
2489 sscanf(i8k.ac_status, "%d", &ac_status);
2490 if(ac_status == -1) {
2491 snprintf(p, p_max_size,"disabled (read i8k docs)");
2492 } if(ac_status == 0) {
2493 snprintf(p, p_max_size, "off");
2494 } if(ac_status == 1) {
2495 snprintf(p, p_max_size, "on");
2498 OBJ(i8k_buttons_status) {
2499 snprintf(p, p_max_size, "%s", i8k.buttons_status);
2503 get_ibm_acpi_fan(p, p_max_size);
2506 get_ibm_acpi_temps();
2507 snprintf(p, p_max_size, "%d",
2508 ibm_acpi.temps[obj->data.sensor]);
2511 get_ibm_acpi_volume(p, p_max_size);
2513 OBJ(ibm_brightness) {
2514 get_ibm_acpi_brightness(p, p_max_size);
2516 #endif /* __linux__ */
2520 new_font(p, obj->data.s);
2525 if (diskio_value > 1024*1024) {
2526 snprintf(p, p_max_size, "%.1fG",
2527 (double)diskio_value/1024/1024);
2528 } else if (diskio_value > 1024) {
2529 snprintf(p, p_max_size, "%.1fM",
2530 (double)diskio_value/1024);
2531 } else if (diskio_value > 0) {
2532 snprintf(p, p_max_size, "%dK", diskio_value);
2534 snprintf(p, p_max_size, "%d", diskio_value);
2537 if (diskio_value > 1024*1024) {
2538 snprintf(p, 6, "%.1fG ",
2539 (double)diskio_value/1024/1024);
2540 } else if (diskio_value > 1024) {
2541 snprintf(p, 6, "%.1fM ",
2542 (double)diskio_value/1024);
2543 } else if (diskio_value > 0) {
2544 snprintf(p, 6, "%dK ", diskio_value);
2546 snprintf(p, 6, "%d ", diskio_value);
2551 new_graph(p, obj->a,
2552 obj->b, obj->c, obj->d,
2553 diskio_value, obj->e, 1);
2558 snprintf(p, p_max_size, "%d",
2559 (int) (obj->data.net->
2563 snprintf(p, 6, "%d ",
2564 (int) (obj->data.net->
2570 snprintf(p, p_max_size, "%.1f",
2572 recv_speed / 1024.0);
2574 snprintf(p, 8, "%.1f ",
2576 recv_speed / 1024.0);
2578 OBJ(downspeedgraph) {
2579 if (obj->data.net->recv_speed == 0) // this is just to make the ugliness at start go away
2580 obj->data.net->recv_speed = 0.01;
2581 new_graph(p, obj->a, obj->b, obj->c, obj->d,
2582 (obj->data.net->recv_speed /
2583 1024.0), obj->e, 1);
2589 i = obj->data.ifblock.pos - 2;
2599 snprintf(p, p_max_size, "%u.%u.%u.%u",
2600 obj->data.net->addr.
2602 obj->data.net->addr.
2604 obj->data.net->addr.
2606 obj->data.net->addr.
2611 snprintf(p, p_max_size, "%d",
2612 obj->data.net->linkstatus);
2616 FILE *fp = popen(obj->data.s, "r");
2617 int length = fread(p, 1, p_max_size, fp);
2620 /*output[length] = '\0';
2621 if (length > 0 && output[length - 1] == '\n') {
2622 output[length - 1] = '\0';
2625 if (length > 0 && p[length - 1] == '\n') {
2626 p[length - 1] = '\0';
2629 //parse_conky_vars(output, p, cur);
2633 FILE *fp = popen(obj->data.s, "r");
2634 int n2 = fread(p, 1, p_max_size, fp);
2638 if (n2 && p[n2 - 1] == '\n')
2647 if (sscanf(p, "%lf", &barnum) == 0) {
2648 ERR("reading execbar value failed (perhaps it's not the correct format?)");
2650 if (barnum > 100 || barnum < 0) {
2651 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
2653 barnum = barnum / 100.0;
2654 new_bar(p, 0, 4, (int) (barnum * 255.0));
2660 FILE *fp = popen(obj->data.s, "r");
2661 int n2 = fread(p, 1, p_max_size, fp);
2665 if (n2 && p[n2 - 1] == '\n')
2674 if (sscanf(p, "%lf", &barnum) == 0) {
2675 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
2677 if (barnum > 100 || barnum < 0) {
2678 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
2680 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
2685 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2686 new_bar(p, 0, 4, (int) obj->f);
2689 FILE *fp = popen(obj->data.execi.cmd, "r");
2690 int n2 = fread(p, 1, p_max_size, fp);
2693 if (n2 && p[n2 - 1] == '\n')
2702 if (sscanf(p, "%f", &barnum) == 0) {
2703 ERR("reading execibar value failed (perhaps it's not the correct format?)");
2705 if (barnum > 100 || barnum < 0) {
2706 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
2708 obj->f = 255 * barnum / 100.0;
2709 new_bar(p, 0, 4, (int) obj->f);
2711 obj->data.execi.last_update =
2712 current_update_time;
2716 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2717 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
2720 FILE *fp = popen(obj->data.execi.cmd, "r");
2721 int n2 = fread(p, 1, p_max_size, fp);
2724 if (n2 && p[n2 - 1] == '\n')
2733 if (sscanf(p, "%f", &barnum) == 0) {
2734 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
2736 if (barnum > 100 || barnum < 0) {
2737 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
2740 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
2742 obj->data.execi.last_update = current_update_time;
2748 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
2749 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
2751 char *output = obj->data.execi.buffer;
2752 FILE *fp = popen(obj->data.execi.cmd, "r");
2753 //int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
2754 int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
2757 output[length] = '\0';
2758 if (length > 0 && output[length - 1] == '\n') {
2759 output[length - 1] = '\0';
2761 obj->data.execi.last_update = current_update_time;
2762 snprintf(p, p_max_size, "%s", output);
2764 //parse_conky_vars(output, p, cur);
2767 if (obj->data.execi.pos < 0) {
2768 obj->data.execi.last_update = current_update_time;
2769 if (pthread_create(&(obj->data.execi.thread_info.thread), NULL, (void*)threaded_exec, (void*) obj)) {
2770 ERR("Error starting thread");
2772 obj->data.execi.pos = register_thread(&(obj->data.execi.thread_info));
2774 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
2778 if (obj->data.fs != NULL) {
2779 if (obj->data.fs->size == 0)
2798 if (obj->data.fs != NULL)
2799 human_readable(obj->data.fs->avail,
2803 if (obj->data.fs != NULL) {
2804 if (obj->data.fs->size)
2805 snprintf(p, p_max_size, "%*d",
2814 snprintf(p, p_max_size, "0");
2818 if (obj->data.fs != NULL)
2819 human_readable(obj->data.fs->size,
2823 if (obj->data.fs != NULL)
2824 human_readable(obj->data.fs->size -
2825 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
2829 if (obj->data.fs != NULL) {
2830 if (obj->data.fs->size == 0)
2848 if (obj->data.fs != NULL) {
2849 if (obj->data.fs->size)
2850 snprintf(p, 4, "%d",
2860 snprintf(p, p_max_size, "0");
2864 float *v = info.loadavg;
2866 if (obj->data.loadavg[2])
2867 snprintf(p, p_max_size, "%.2f %.2f %.2f",
2868 v[obj->data.loadavg[0] -
2870 v[obj->data.loadavg[1] -
2872 v[obj->data.loadavg[2] -
2874 else if (obj->data.loadavg[1])
2875 snprintf(p, p_max_size, "%.2f %.2f",
2876 v[obj->data.loadavg[0] -
2878 v[obj->data.loadavg[1] -
2880 else if (obj->data.loadavg[0])
2881 snprintf(p, p_max_size, "%.2f",
2882 v[obj->data.loadavg[0] -
2886 new_hr(p, obj->data.i);
2889 new_offset(p, obj->data.i);
2892 new_voffset(p, obj->data.i);
2897 r = get_i2c_info(&obj->data.i2c.fd,
2899 obj->data.i2c.devtype,
2900 obj->data.i2c.type);
2902 if (r >= 100.0 || r == 0)
2903 snprintf(p, p_max_size, "%d", (int) r);
2905 snprintf(p, p_max_size, "%.1f", r);
2908 new_alignr(p, obj->data.i);
2911 new_alignc(p, obj->data.i);
2915 if ((obj->data.ifblock.s)
2916 && (stat(obj->data.ifblock.s, &tmp) ==
2918 i = obj->data.ifblock.pos;
2925 if ((obj->data.ifblock.s)
2926 && (!check_mount(obj->data.ifblock.s))) {
2927 i = obj->data.ifblock.pos;
2934 if ((obj->data.ifblock.s)
2935 && system(obj->data.ifblock.s)) {
2936 i = obj->data.ifblock.pos;
2943 snprintf(p, p_max_size, "%s", cur->uname_s.release);
2946 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
2951 human_readable(cur->mem * 1024, p, 6);
2954 human_readable(cur->memmax * 1024, p, 255);
2959 snprintf(p, p_max_size, "%*lu",
2964 snprintf(p, 4, "%*lu ",
2971 new_bar(p, obj->data.pair.a,
2973 cur->memmax ? (cur->mem * 255) /
2978 new_graph(p, obj->a,
2979 obj->b, obj->c, obj->d,
2980 cur->memmax ? (cur->mem * 100.0) /
2981 (cur->memmax) : 0.0, 100, 1);
2985 snprintf(p, p_max_size, "%d",
2986 mixer_get_avg(obj->data.l));
2989 snprintf(p, p_max_size, "%d",
2990 mixer_get_left(obj->data.l));
2993 snprintf(p, p_max_size, "%d",
2994 mixer_get_right(obj->data.l));
2997 new_bar(p, obj->data.mixerbar.w,
2998 obj->data.mixerbar.h,
2999 mixer_get_avg(obj->data.mixerbar.
3003 new_bar(p, obj->data.mixerbar.w,
3004 obj->data.mixerbar.h,
3005 mixer_get_left(obj->data.mixerbar.
3009 new_bar(p, obj->data.mixerbar.w,
3010 obj->data.mixerbar.h,
3011 mixer_get_right(obj->data.mixerbar.
3017 snprintf(p, p_max_size, "%d", cur->mail_count);
3020 snprintf(p, p_max_size, "%d", cur->new_mail_count);
3023 OBJ(ml_upload_counter) {
3024 snprintf(p, p_max_size, "%lld",
3025 mlinfo.upload_counter / 1048576);
3027 OBJ(ml_download_counter) {
3028 snprintf(p, p_max_size, "%lld",
3029 mlinfo.download_counter /
3032 OBJ(ml_nshared_files) {
3033 snprintf(p, p_max_size, "%i", mlinfo.nshared_files);
3035 OBJ(ml_shared_counter) {
3036 snprintf(p, p_max_size, "%lld",
3037 mlinfo.shared_counter / 1048576);
3039 OBJ(ml_tcp_upload_rate) {
3040 snprintf(p, p_max_size, "%.2f",
3041 (float) mlinfo.tcp_upload_rate /
3044 OBJ(ml_tcp_download_rate) {
3045 snprintf(p, p_max_size, "%.2f",
3046 (float) mlinfo.tcp_download_rate /
3049 OBJ(ml_udp_upload_rate) {
3050 snprintf(p, p_max_size, "%.2f",
3051 (float) mlinfo.udp_upload_rate /
3054 OBJ(ml_udp_download_rate) {
3055 snprintf(p, p_max_size, "%.2f",
3056 (float) mlinfo.udp_download_rate /
3059 OBJ(ml_ndownloaded_files) {
3060 snprintf(p, p_max_size, "%i",
3061 mlinfo.ndownloaded_files);
3063 OBJ(ml_ndownloading_files) {
3064 snprintf(p, p_max_size, "%i",
3065 mlinfo.ndownloading_files);
3070 snprintf(p, p_max_size, "%s",
3071 cur->uname_s.nodename);
3074 new_outline(p, obj->data.l);
3078 snprintf(p, p_max_size, "%hu", cur->procs);
3080 snprintf(p, 5, "%hu ",
3083 OBJ(running_processes) {
3085 snprintf(p, p_max_size, "%hu",
3088 snprintf(p, 3, "%hu ",
3092 snprintf(p, p_max_size, "%s", obj->data.s);
3095 new_bg(p, obj->data.l);
3098 new_stippled_hr(p, obj->data.pair.a,
3102 human_readable(cur->swap * 1024, p, 255);
3105 human_readable(cur->swapmax * 1024, p,
3109 if (cur->swapmax == 0) {
3110 strncpy(p, "No swap", 255);
3113 snprintf(p, 255, "%*lu",
3119 snprintf(p, 4, "%*lu ",
3127 new_bar(p, obj->data.pair.a,
3129 cur->swapmax ? (cur->swap * 255) /
3130 (cur->swapmax) : 0);
3133 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
3136 time_t t = time(NULL);
3137 struct tm *tm = localtime(&t);
3138 setlocale(LC_TIME, "");
3139 strftime(p, p_max_size, obj->data.s, tm);
3142 time_t t = time(NULL);
3143 struct tm *tm = gmtime(&t);
3144 strftime(p, p_max_size, obj->data.s, tm);
3147 human_readable(obj->data.net->recv, p,
3151 human_readable(obj->data.net->trans, p,
3155 snprintf(p, p_max_size, "%d", total_updates);
3159 snprintf(p, p_max_size, "%d",
3160 (int) (obj->data.net->
3164 snprintf(p, 5, "%d ",
3165 (int) (obj->data.net->
3171 snprintf(p, p_max_size, "%.1f",
3173 trans_speed / 1024.0);
3175 snprintf(p, 8, "%.1f ",
3177 trans_speed / 1024.0);
3180 if (obj->data.net->trans_speed == 0) // this is just to make the ugliness at start go away
3181 obj->data.net->trans_speed = 0.01;
3182 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3183 (obj->data.net->trans_speed /
3184 1024.0), obj->e, 1);
3187 format_seconds_short(p, p_max_size,
3191 format_seconds(p, p_max_size, (int) cur->uptime);
3194 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
3196 snprintf(p, p_max_size, "%s", get_apm_adapter());
3198 OBJ(apm_battery_life) {
3200 msg = get_apm_battery_life();
3201 snprintf(p, p_max_size, "%s", msg);
3204 OBJ(apm_battery_time) {
3206 msg = get_apm_battery_time();
3207 snprintf(p, p_max_size, "%s", msg);
3210 #endif /* __FreeBSD__ */
3213 snprintf(p, p_max_size, "%.2f",
3214 cur->seti_prog * 100.0f);
3217 new_bar(p, obj->data.pair.a,
3219 (int) (cur->seti_prog * 255.0f));
3222 snprintf(p, p_max_size, "%.0f", cur->seti_credit);
3228 snprintf(p, p_max_size, "%s", cur->mpd.title);
3231 snprintf(p, p_max_size, "%s", cur->mpd.artist);
3234 snprintf(p, p_max_size, "%s", cur->mpd.album);
3237 snprintf(p, p_max_size, "%s", cur->mpd.random);
3240 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
3243 snprintf(p, p_max_size, "%s", cur->mpd.track);
3246 snprintf(p, p_max_size, "%s", cur->mpd.name);
3249 snprintf(p, p_max_size, "%s", cur->mpd.file);
3252 snprintf(p, p_max_size, "%i", cur->mpd.volume);
3255 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
3258 snprintf(p, p_max_size, "%s", cur->mpd.status);
3261 int days = 0, hours = 0, minutes =
3263 int tmp = cur->mpd.elapsed;
3264 while (tmp >= 86400) {
3268 while (tmp >= 3600) {
3278 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
3279 days, hours, minutes,
3282 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
3285 snprintf(p, p_max_size, "%i:%02i", minutes,
3289 int days = 0, hours = 0, minutes =
3291 int tmp = cur->mpd.length;
3292 while (tmp >= 86400) {
3296 while (tmp >= 3600) {
3306 snprintf(p, p_max_size,
3307 "%i days %i:%02i:%02i",
3308 days, hours, minutes,
3311 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
3314 snprintf(p, p_max_size, "%i:%02i", minutes,
3318 snprintf(p, p_max_size, "%2.0f",
3319 cur->mpd.progress * 100);
3322 new_bar(p, obj->data.pair.a,
3324 (int) (cur->mpd.progress *
3328 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.title) < 2) {
3329 snprintf(p, p_max_size, "%s", cur->mpd.file);
3331 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
3337 snprintf(p, p_max_size, "%s", cur->xmms2.title);
3340 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
3343 snprintf(p, p_max_size, "%s", cur->xmms2.album);
3346 snprintf(p, p_max_size, "%i", cur->xmms2.track);
3349 snprintf(p, p_max_size, "%s", cur->xmms2.file);
3352 snprintf(p, p_max_size, "%s", cur->xmms2.status);
3354 OBJ(xmms2_elapsed) {
3355 int tmp = cur->xmms2.elapsed;
3356 snprintf(p, p_max_size, "%02d:%02d",
3357 tmp / 60000, (tmp / 1000) % 60);
3360 int tmp = cur->xmms2.length;
3361 snprintf(p, p_max_size, "%02d:%02d",
3362 tmp / 60000, (tmp / 1000) % 60);
3364 OBJ(xmms2_percent) {
3365 snprintf(p, p_max_size, "%2.0f",
3366 cur->xmms2.progress * 100);
3369 new_bar(p, obj->data.pair.a,
3371 (int) (cur->xmms2.progress *
3376 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
3378 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_STATUS]);
3381 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_TITLE]);
3384 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_LENGTH]);
3386 OBJ(xmms_length_seconds) {
3387 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_LENGTH_SECONDS]);
3389 OBJ(xmms_position) {
3390 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_POSITION]);
3392 OBJ(xmms_position_seconds) {
3393 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_POSITION_SECONDS]);
3396 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_BITRATE]);
3398 OBJ(xmms_frequency) {
3399 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_FREQUENCY]);
3401 OBJ(xmms_channels) {
3402 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_CHANNELS]);
3404 OBJ(xmms_filename) {
3405 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_FILENAME]);
3407 OBJ(xmms_playlist_length) {
3408 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_PLAYLIST_LENGTH]);
3410 OBJ(xmms_playlist_position) {
3411 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_PLAYLIST_POSITION]);
3415 progress= atof(cur->xmms.items[XMMS_POSITION_SECONDS]) /
3416 atof(cur->xmms.items[XMMS_LENGTH_SECONDS]);
3417 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
3422 snprintf(p, p_max_size, "%s", cur->bmpx.title);
3425 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
3428 snprintf(p, p_max_size, "%s", cur->bmpx.album);
3431 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
3434 snprintf(p, p_max_size, "%i", cur->bmpx.track);
3437 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
3441 if (obj->data.top.type == TOP_NAME
3442 && obj->data.top.num >= 0
3443 && obj->data.top.num < 10) {
3444 // if we limit the buffer and add a bunch of space after, it stops the thing from
3445 // moving other shit around, which is really fucking annoying
3446 snprintf(p, 17, "%s ", cur->cpu[obj->data.top.num]->name);
3447 } else if (obj->data.top.type == TOP_CPU
3448 && obj->data.top.num >= 0
3449 && obj->data.top.num < 10) {
3450 snprintf(p, 7, "%3.2f ",
3451 cur->cpu[obj->data.top.
3453 } else if (obj->data.top.type == TOP_PID
3454 && obj->data.top.num >= 0
3455 && obj->data.top.num < 10) {
3456 snprintf(p, 8, "%i ",
3457 cur->cpu[obj->data.top.
3459 } else if (obj->data.top.type == TOP_MEM
3460 && obj->data.top.num >= 0
3461 && obj->data.top.num < 10) {
3462 snprintf(p, 7, "%3.2f ",
3463 cur->cpu[obj->data.top.
3468 if (obj->data.top.type == TOP_NAME
3469 && obj->data.top.num >= 0
3470 && obj->data.top.num < 10) {
3471 // if we limit the buffer and add a bunch of space after, it stops the thing from
3472 // moving other shit around, which is really fucking annoying
3475 cur->memu[obj->data.top.
3477 } else if (obj->data.top.type == TOP_CPU
3478 && obj->data.top.num >= 0
3479 && obj->data.top.num < 10) {
3480 snprintf(p, 7, "%3.2f ",
3481 cur->memu[obj->data.top.
3483 } else if (obj->data.top.type == TOP_PID
3484 && obj->data.top.num >= 0
3485 && obj->data.top.num < 10) {
3486 snprintf(p, 8, "%i ",
3487 cur->memu[obj->data.top.
3489 } else if (obj->data.top.type == TOP_MEM
3490 && obj->data.top.num >= 0
3491 && obj->data.top.num < 10) {
3492 snprintf(p, 7, "%3.2f ",
3493 cur->memu[obj->data.top.
3500 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
3501 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
3503 obj->data.tail.last_update = current_update_time;
3507 tailstring *head = NULL;
3508 tailstring *headtmp = NULL;
3509 tailstring *freetmp = NULL;
3510 fp = fopen(obj->data.tail.logfile, "rt");
3512 ERR("tail logfile failed to open");
3515 obj->data.tail.readlines = 0;
3517 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL) {
3524 addtail(&head, obj->data.tail.buffer);
3525 obj->data.tail.readlines++;
3531 if (obj->data.tail.readlines > 0) {
3532 for (i = 0;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
3533 addtail(&headtmp, head->data);
3538 strcpy(obj->data.tail.buffer, headtmp->data);
3539 headtmp = headtmp->next;
3540 for (i = 1;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
3542 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 */
3543 headtmp = headtmp->next;
3547 /* get rid of any ugly newlines at the end */
3548 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
3549 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
3551 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
3555 strcpy(obj->data.tail.buffer, "Logfile Empty");
3556 snprintf(p, p_max_size, "Logfile Empty");
3557 } /* if readlines */
3559 } /* if cur_upd_time >= */
3561 //parse_conky_vars(obj->data.tail.buffer, p, cur);
3565 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
3566 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
3568 obj->data.tail.last_update = current_update_time;
3570 tailstring *head = NULL;
3571 tailstring *headtmp = NULL;
3572 tailstring *freetmp = NULL;
3573 fp = fopen(obj->data.tail.logfile, "rt");
3575 ERR("head logfile failed to open");
3577 obj->data.tail.readlines = 0;
3578 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL && obj->data.tail.readlines <= obj->data.tail.wantedlines) {
3579 addtail(&head, obj->data.tail.buffer);
3580 obj->data.tail.readlines++;
3584 if (obj->data.tail.readlines > 0) {
3586 addtail(&headtmp, head->data);
3591 strcpy(obj->data.tail.buffer, headtmp->data);
3592 headtmp = headtmp->next;
3594 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 */
3595 headtmp = headtmp->next;
3598 /* get rid of any ugly newlines at the end */
3599 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
3600 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
3602 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
3604 strcpy(obj->data.tail.buffer, "Logfile Empty");
3605 snprintf(p, p_max_size, "Logfile Empty");
3606 } /* if readlines > 0 */
3607 } /* if fp == null */
3608 } /* cur_upd_time >= */
3610 //parse_conky_vars(obj->data.tail.buffer, p, cur);
3613 #ifdef TCP_PORT_MONITOR
3616 /* grab a pointer to this port monitor */
3617 tcp_port_monitor_t * p_monitor =
3618 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
3619 obj->data.tcp_port_monitor.port_range_begin,
3620 obj->data.tcp_port_monitor.port_range_end );
3622 snprintf(p, p_max_size, "monitor not found");
3626 /* now grab the text of interest */
3627 if ( peek_tcp_port_monitor( p_monitor,
3628 obj->data.tcp_port_monitor.item,
3629 obj->data.tcp_port_monitor.connection_index,
3630 p, p_max_size ) != 0 )
3632 snprintf(p, p_max_size, "monitor peek error");
3642 unsigned int a = strlen(p);
3650 double current_update_time, last_update_time;
3652 static void generate_text()
3654 struct information *cur = &info;
3661 current_update_time = get_time();
3665 /* add things to the buffer */
3671 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
3673 if (stuff_in_upper_case) {
3683 last_update_time = current_update_time;
3690 static void set_font()
3694 if (window.xftdraw != NULL) {
3695 XftDrawDestroy(window.xftdraw);
3697 window.xftdraw = XftDrawCreate(display, window.drawable,
3698 DefaultVisual(display,
3700 DefaultColormap(display,
3705 XSetFont(display, window.gc, fonts[selected_font].font->fid);
3714 static int text_start_x, text_start_y; /* text start position in window */
3715 static int text_width, text_height;
3719 static inline int get_string_width(const char *s)
3722 return *s ? calc_text_width(s, strlen(s)) : 0;
3728 static inline int get_string_width_special(char *s)
3741 if (*p == SPECIAL_CHAR) {
3742 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
3743 for (i = 0; i < strlen(p); i++) {
3744 *(p + i) = *(p + i + 1);
3746 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
3747 width += specials[special_index+index].width;
3754 if (strlen(final) > 1) {
3755 width += calc_text_width(final, strlen(final));
3767 static void text_size_updater(char *s)
3771 int h = font_height();
3772 /* get string widths and skip specials */
3775 if (*p == SPECIAL_CHAR) {
3777 w += get_string_width(s);
3780 if (specials[special_index].type == BAR
3781 || specials[special_index].type == GRAPH) {
3782 w += specials[special_index].width;
3783 if (specials[special_index].height > h) {
3784 h = specials[special_index].height;
3789 else if (specials[special_index].type == OFFSET) {
3790 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
3792 else if (specials[special_index].type == VOFFSET) {
3793 h += specials[special_index].arg;
3795 else if (specials[special_index].type == FONT) {
3796 fontchange = specials[special_index].font_added;
3797 selected_font = specials[special_index].font_added;
3807 w += get_string_width(s);
3810 if (text_width > maximum_width && maximum_width)
3811 text_width = maximum_width;
3822 static void update_text_area()
3826 /* update text size if it isn't fixed */
3831 text_width = minimum_width;
3834 for_each_line(text_buffer, text_size_updater);
3836 if (text_height < minimum_height)
3837 text_height = minimum_height;
3838 if (text_width > maximum_width && maximum_width > 0)
3839 text_width = maximum_width;
3842 /* get text position on workarea */
3843 switch (text_alignment) {
3850 x = workarea[2] - text_width - gap_x;
3857 y = workarea[3] - text_height - gap_y;
3861 x = workarea[2] - text_width - gap_x;
3862 y = workarea[3] - text_height - gap_y;
3866 case NONE: // Let the WM manage the window
3877 if (own_window && !fixed_pos) {
3880 text_start_x = border_margin + 1;
3881 text_start_y = border_margin + 1;
3882 window.x = x - border_margin - 1;
3883 window.y = y - border_margin - 1;
3887 /* If window size doesn't match to workarea's size, then window
3888 * probably includes panels (gnome).
3889 * Blah, doesn't work on KDE. */
3890 if (workarea[2] != window.width
3891 || workarea[3] != window.height) {
3905 static int cur_x, cur_y; /* current x and y for drawing */
3906 static int draw_mode; /* FG, BG or OUTLINE */
3907 static long current_color;
3909 static inline void set_foreground_color(long c)
3912 XSetForeground(display, window.gc, c);
3916 static void draw_string(const char *s)
3920 int i, i2, pos, width_of_s;
3923 width_of_s = get_string_width(s);
3924 if (out_to_console) {
3926 fflush(stdout); /* output immediately, don't buffer */
3928 /* 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 */
3929 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
3930 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
3931 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
3935 snprintf(space, 2, " ");
3937 max = ((text_width - width_of_s) / get_string_width(space));
3940 * This code looks for tabs in the text and coverts them to spaces.
3941 * The trick is getting the correct number of spaces,
3942 * and not going over the window's size without forcing
3943 * the window larger.
3945 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
3946 if (tmpstring1[i] == '\t') // 9 is ascii tab
3950 i2 < (8 - (1 + pos) % 8) && added <= max;
3953 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
3954 fprintf(stderr,"buffer overrun detected\n");
3956 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
3961 if (tmpstring1[i] != 9) {
3963 if ( pos > TEXT_BUFFER_SIZE-1 )
3964 fprintf(stderr,"buffer overrun detected\n");
3966 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
3972 if (text_width == maximum_width) {
3973 /* this means the text is probably pushing the limit, so we'll chop it */
3974 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
3975 tmpstring2[strlen(tmpstring2)-1] = '\0';
3985 c.pixel = current_color;
3986 XQueryColor(display, DefaultColormap(display, screen), &c);
3989 c2.color.red = c.red;
3990 c2.color.green = c.green;
3991 c2.color.blue = c.blue;
3992 c2.color.alpha = fonts[selected_font].font_alpha;
3994 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
3995 cur_x, cur_y, (XftChar8 *) s,
3998 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
3999 cur_x, cur_y, (XftChar8 *) s,
4005 XDrawString(display, window.drawable, window.gc,
4006 cur_x, cur_y, s, strlen(s));
4008 cur_x += width_of_s;
4010 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
4013 long redmask, greenmask, bluemask;
4015 void set_up_gradient()
4018 colour_depth = DisplayPlanes(display, screen);
4022 if (colour_depth != 24 && colour_depth != 16) {
4023 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
4029 for(i = (colour_depth / 3)-1; i>=0; i--) {
4031 greenmask |= 1 << i;
4034 if (colour_depth%3 == 1) {
4035 greenmask |= 1 << (colour_depth / 3);
4037 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
4038 greenmask = greenmask << (colour_depth / 3);
4041 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 */
4043 int red1, green1, blue1; // first colour
4044 int red2, green2, blue2; // second colour
4045 int red3 = 0, green3 = 0, blue3 = 0; // difference
4046 short redshift = (2*colour_depth / 3 + colour_depth%3);
4047 short greenshift = (colour_depth / 3);
4048 red1 = (first_colour & redmask) >> redshift;
4049 green1 = (first_colour & greenmask) >> greenshift;
4050 blue1 = first_colour & bluemask;
4051 red2 = (last_colour & redmask) >> redshift;
4052 green2 = (last_colour & greenmask) >> greenshift;
4053 blue2 = last_colour & bluemask;
4060 if (green1 > green2) {
4063 if (green1 < green2) {
4066 if (blue1 > blue2) {
4069 if (blue1 < blue2) {
4084 if (red1 > bluemask) {
4087 if (green1 > bluemask) {
4090 if (blue1 > bluemask) {
4093 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
4097 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
4098 if (colour_depth == 0) {
4101 int red1, green1, blue1; // first colour
4102 int red2, green2, blue2; // second colour
4103 long redshift = (2*colour_depth / 3 + colour_depth%3);
4104 long greenshift = (colour_depth / 3);
4105 int red3 = 0, green3 = 0, blue3 = 0; // difference
4106 red1 = (first_colour & redmask) >> redshift;
4107 green1 = (first_colour & greenmask) >> greenshift;
4108 blue1 = first_colour & bluemask;
4109 red2 = (last_colour & redmask) >> redshift;
4110 green2 = (last_colour & greenmask) >> greenshift;
4111 blue2 = last_colour & bluemask;
4112 red3 = abs(red1 - red2);
4113 green3 = abs(green1 - green2);
4114 blue3 = abs(blue1 - blue2);
4123 static void draw_line(char *s)
4127 cur_x = text_start_x;
4128 cur_y += font_ascent();
4130 short font_h = font_height();
4132 /* find specials and draw stuff */
4135 if (*p == SPECIAL_CHAR) {
4138 /* draw string before special */
4145 switch (specials[special_index].type) {
4146 case HORIZONTAL_LINE:
4149 specials[special_index].height;
4150 int mid = font_ascent() / 2;
4151 w = text_start_x + text_width -
4154 XSetLineAttributes(display,
4159 XDrawLine(display, window.drawable,
4170 specials[special_index].height;
4172 specials[special_index].arg;
4173 int mid = font_ascent() / 2;
4174 char ss[2] = { s, s };
4175 w = text_start_x + text_width -
4178 XSetLineAttributes(display,
4183 XSetDashes(display, window.gc, 0,
4185 XDrawLine(display, window.drawable,
4195 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
4199 specials[special_index].height;
4201 specials[special_index].arg;
4206 by = cur_y - (font_ascent() + h) / 2 - 1;
4210 by = cur_y - (font_ascent()/2) - 1;
4212 if (h < (font_height())) {
4215 w = specials[special_index].width;
4218 text_width - cur_x - 1;
4222 XSetLineAttributes(display,
4228 XDrawRectangle(display,
4232 XFillRectangle(display,
4236 w * bar_usage / 255,
4238 if (specials[special_index].
4240 && specials[special_index].
4244 [special_index].height;
4251 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
4255 specials[special_index].height;
4257 unsigned long last_colour = current_color;
4260 by = cur_y - (font_ascent() + h) / 2 - 1;
4264 by = cur_y - (font_ascent()/2) - 1;
4266 if (h < (font_height())) {
4269 w = specials[special_index].width;
4271 w = text_start_x + text_width - cur_x - 1;
4274 if (draw_graph_borders) {
4275 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
4276 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
4278 XSetLineAttributes(display,
4285 int gradient_size = 0;
4286 float gradient_factor = 0;
4287 float gradient_update = 0;
4288 unsigned long tmpcolour = current_color;
4289 if (specials[special_index].last_colour != specials[special_index].first_colour) {
4290 tmpcolour = specials[special_index].last_colour;
4291 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
4292 gradient_factor = (float)gradient_size / (w - 3);
4294 for (i = w - 3; i > 0; i--) {
4295 if (specials[special_index].last_colour != specials[special_index].first_colour) {
4296 XSetForeground(display, window.gc, tmpcolour);
4297 gradient_update += gradient_factor;
4298 while (gradient_update > 0) {
4299 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
4303 if ((w - 3 - i) / ((float) (w - 3) / (specials[special_index].graph_width)) > j) {
4306 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 */
4308 if (specials[special_index].
4310 && specials[special_index].
4314 [special_index].height;
4316 /* if (draw_mode == BG) {
4317 set_foreground_color(default_bg_color);
4319 else if (draw_mode == OUTLINE) {
4320 set_foreground_color(default_out_color);
4322 set_foreground_color(default_fg_color);
4324 set_foreground_color(last_colour);
4330 cur_y -= font_ascent();
4331 selected_font = specials[special_index].font_added;
4332 cur_y += font_ascent();
4334 if (!use_xft || use_xdbe)
4342 if (draw_mode == FG)
4343 set_foreground_color(specials
4349 if (draw_mode == BG)
4350 set_foreground_color(specials
4356 if (draw_mode == OUTLINE)
4357 set_foreground_color(specials
4364 w += specials[special_index].arg;
4369 cur_y += specials[special_index].arg;
4375 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
4376 /*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);*/
4377 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
4378 cur_x = pos_x - specials[special_index].arg;
4385 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
4386 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
4387 /*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);*/
4389 specials[special_index].arg)
4392 [special_index].arg;
4409 if (cur_y_add > 0) {
4411 cur_y -= font_descent();
4416 cur_y += font_descent();
4423 static void draw_text()
4426 cur_y = text_start_y;
4429 if (draw_borders && border_width > 0) {
4430 unsigned int b = (border_width + 1) / 2;
4432 if (stippled_borders) {
4434 { stippled_borders, stippled_borders };
4435 XSetLineAttributes(display, window.gc,
4436 border_width, LineOnOffDash,
4437 CapButt, JoinMiter);
4438 XSetDashes(display, window.gc, 0, ss, 2);
4440 XSetLineAttributes(display, window.gc,
4441 border_width, LineSolid,
4442 CapButt, JoinMiter);
4445 XDrawRectangle(display, window.drawable, window.gc,
4446 text_start_x - border_margin + b,
4447 text_start_y - border_margin + b,
4448 text_width + border_margin * 2 - 1 - b * 2,
4449 text_height + border_margin * 2 - 1 -
4456 for_each_line(text_buffer, draw_line);
4459 static void draw_stuff()
4462 if (draw_shades && !draw_outline) {
4465 set_foreground_color(default_bg_color);
4474 for (i = -1; i < 2; i++)
4475 for (j = -1; j < 2; j++) {
4476 if (i == 0 && j == 0)
4480 set_foreground_color(default_out_color);
4481 draw_mode = OUTLINE;
4488 set_foreground_color(default_fg_color);
4496 swap.swap_window = window.window;
4497 swap.swap_action = XdbeBackground;
4498 XdbeSwapBuffers(display, &swap, 1);
4504 static void clear_text(int exposures)
4508 return; /* The swap action is XdbeBackground, which clears */
4512 /* there is some extra space for borders and outlines */
4513 XClearArea(display, window.drawable,
4514 text_start_x - border_margin - 1,
4515 text_start_y - border_margin - 1,
4516 text_width + border_margin * 2 + 2,
4517 text_height + border_margin * 2 + 2,
4518 exposures ? True : 0);
4523 static int need_to_update;
4525 /* update_text() generates new text and clears old text area */
4526 static void update_text()
4535 static void main_loop()
4537 #ifdef SIGNAL_BLOCKING
4538 sigset_t newmask, oldmask;
4540 sigemptyset(&newmask);
4541 sigaddset(&newmask,SIGINT);
4542 sigaddset(&newmask,SIGTERM);
4543 sigaddset(&newmask,SIGUSR1);
4547 Region region = XCreateRegion();
4551 while (total_run_times == 0 || info.looped < total_run_times - 1) {
4554 #ifdef SIGNAL_BLOCKING
4555 /* block signals. we will inspect for pending signals later */
4556 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
4557 CRIT_ERR("unable to sigprocmask()");
4563 /* wait for X event or timeout */
4565 if (!XPending(display)) {
4570 update_interval - (get_time() -
4576 tv.tv_sec = (long) t;
4577 tv.tv_usec = (long) (t * 1000000) % 1000000;
4579 FD_SET(ConnectionNumber(display), &fdsr);
4582 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
4585 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
4590 ERR("can't select(): %s",
4601 if (need_to_update) {
4603 int wx = window.x, wy = window.y;
4611 /* resize window if it isn't right size */
4613 (text_width + border_margin * 2 + 1 !=
4615 || text_height + border_margin * 2 + 1 !=
4619 border_margin * 2 + 1;
4622 border_margin * 2 + 1;
4623 XResizeWindow(display,
4628 set_transparent_background(window.window);
4632 /* move window if it isn't in right position */
4635 || window.y != wy)) {
4636 XMoveWindow(display, window.window,
4637 window.x, window.y);
4647 r.x = text_start_x - border_margin;
4648 r.y = text_start_y - border_margin;
4649 r.width = text_width + border_margin * 2;
4650 r.height = text_height + border_margin * 2;
4651 XUnionRectWithRegion(&r, region, region);
4656 /* handle X events */
4658 while (XPending(display)) {
4660 XNextEvent(display, &ev);
4667 r.width = ev.xexpose.width;
4668 r.height = ev.xexpose.height;
4669 XUnionRectWithRegion(&r, region,
4675 case ReparentNotify:
4676 /* set background to ParentRelative for all parents */
4678 set_transparent_background(window.
4683 case ConfigureNotify:
4685 /* if window size isn't what expected, set fixed size */
4686 if (ev.xconfigure.width !=
4688 || ev.xconfigure.height !=
4690 if (window.width != 0
4691 && window.height != 0)
4694 /* clear old stuff before screwing up size and pos */
4700 if (XGetWindowAttributes(display, window.window, &attrs)) {
4715 border_margin * 2 - 1;
4718 border_margin * 2 - 1;
4719 if (text_width > maximum_width && maximum_width > 0)
4720 text_width = maximum_width;
4723 /* if position isn't what expected, set fixed pos, total_updates
4724 * avoids setting fixed_pos when window is set to weird locations
4726 /*if (total_updates >= 2 this is broken
4728 && (window.x != ev.xconfigure.x
4731 && (ev.xconfigure.x != 0
4732 || ev.xconfigure.y != 0)) {
4742 /* forward the click to the desktop window */
4743 XUngrabPointer(display, ev.xbutton.time);
4744 ev.xbutton.window = window.desktop;
4745 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
4752 /* forward the release to the desktop window */
4753 ev.xbutton.window = window.desktop;
4754 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
4765 /* XDBE doesn't seem to provide a way to clear the back buffer without
4766 * interfering with the front buffer, other than passing XdbeBackground
4767 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
4768 * redraw the text even if it wasn't part of the exposed area. OTOH,
4769 * if we're not going to call draw_stuff at all, then no swap happens
4770 * and we can safely do nothing.
4773 if (!XEmptyRegion(region)) {
4777 r.x = text_start_x - border_margin;
4778 r.y = text_start_y - border_margin;
4779 r.width = text_width + border_margin * 2;
4780 r.height = text_height + border_margin * 2;
4781 XUnionRectWithRegion(&r, region, region);
4784 XSetRegion(display, window.gc, region);
4787 XftDrawSetClip(window.xftdraw, region);
4793 XDestroyRegion(region);
4794 region = XCreateRegion();
4798 #ifdef SIGNAL_BLOCKING
4799 /* unblock signals of interest and let handler fly */
4800 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
4801 CRIT_ERR("unable to sigprocmask()");
4804 switch(g_signal_pending) {
4807 ERR("received SIGUSR1. reloading the config file.");
4814 ERR("received SIGINT or SIGTERM to terminate. bye!");
4817 XDestroyRegion(region);
4820 return; /* return from main_loop */
4825 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
4826 * but didn't write any code to deal with it. if you don't want to
4827 * handle a signal, don't set a handler on it in the first place. */
4828 if (g_signal_pending)
4829 ERR("ignoring signal (%d)", g_signal_pending);
4837 XDestroyRegion(region);
4842 static void load_config_file(const char *);
4844 /* reload the config file */
4845 void reload_config(void)
4847 //lock_all_threads();
4849 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
4850 if (info.xmms.thread) {
4851 if (destroy_xmms_thread()!=0)
4853 ERR("error destroying xmms_player thread");
4857 #ifdef TCP_PORT_MONITOR
4858 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
4861 if (current_config) {
4863 load_config_file(current_config);
4867 XClearWindow(display, RootWindow(display, screen)); // clear the window first
4870 #ifdef TCP_PORT_MONITOR
4871 info.p_tcp_port_monitor_collection = NULL;
4873 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
4874 if ( (!info.xmms.thread) && (info.xmms.current_project > PROJECT_NONE) &&
4875 (create_xmms_thread() !=0) )
4877 CRIT_ERR("unable to create xmms_player thread!");
4880 extract_variable_text(text);
4890 //lock_all_threads();
4895 XdbeDeallocateBackBufferName(display, window.back_buffer);
4901 XDestroyWindow(display, window.window);
4902 XClearWindow(display, RootWindow(display, screen));
4908 XClearWindow(display, RootWindow(display, screen));
4913 XFreeGC(display, window.gc);
4917 /* it is really pointless to free() memory at the end of program but ak|ra
4918 * wants me to do this */
4920 free_text_objects(text_object_count, text_objects);
4921 text_object_count = 0;
4922 text_objects = NULL;
4926 #endif /* MLDONKEY */
4928 if (text != original_text)
4931 free(current_config);
4932 free(current_mail_spool);
4936 #ifdef TCP_PORT_MONITOR
4937 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
4938 info.p_tcp_port_monitor_collection = NULL;
4940 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
4941 if ( info.xmms.thread && (destroy_xmms_thread()!=0) )
4943 ERR("error destroying xmms_player thread");
4948 static int string_to_bool(const char *s)
4952 if (strcasecmp(s, "yes") == 0)
4954 if (strcasecmp(s, "true") == 0)
4956 if (strcasecmp(s, "1") == 0)
4961 static enum alignment string_to_alignment(const char *s)
4963 if (strcasecmp(s, "top_left") == 0)
4965 else if (strcasecmp(s, "top_right") == 0)
4967 else if (strcasecmp(s, "bottom_left") == 0)
4969 else if (strcasecmp(s, "bottom_right") == 0)
4970 return BOTTOM_RIGHT;
4971 else if (strcasecmp(s, "tl") == 0)
4973 else if (strcasecmp(s, "tr") == 0)
4975 else if (strcasecmp(s, "bl") == 0)
4977 else if (strcasecmp(s, "br") == 0)
4978 return BOTTOM_RIGHT;
4979 else if (strcasecmp(s, "none") == 0)
4986 static void set_default_configurations(void)
4988 fork_to_background = 0;
4989 total_run_times = 0;
4990 info.cpu_avg_samples = 2;
4991 info.net_avg_samples = 2;
4996 strcpy(info.mpd.host, "localhost");
4997 info.mpd.port = 6600;
4998 info.mpd.status = NULL;
4999 info.mpd.artist = NULL;
5000 info.mpd.album = NULL;
5001 info.mpd.title = NULL;
5002 info.mpd.random = NULL;
5003 info.mpd.track = NULL;
5004 info.mpd.name = NULL;
5005 info.mpd.file = NULL;
5008 info.xmms2.status = NULL;
5009 info.xmms2.artist = NULL;
5010 info.xmms2.album = NULL;
5011 info.xmms2.title = NULL;
5012 // info.xmms2.random = NULL;
5013 // info.xmms2.track = NULL;
5014 // info.xmms2.name = NULL;
5015 info.xmms2.file = NULL;
5016 // info.xmms2.connection = NULL;
5025 default_fg_color = WhitePixel(display, screen);
5026 default_bg_color = BlackPixel(display, screen);
5027 default_out_color = BlackPixel(display, screen);
5030 draw_graph_borders = 1;
5032 set_first_font("6x10");
5040 window.type=TYPE_NORMAL;
5042 strcpy(window.wm_class_name, "conky");
5044 stippled_borders = 0;
5047 text_alignment = BOTTOM_LEFT;
5051 free(current_mail_spool);
5054 variable_substitute(MAIL_FILE, buf, 256);
5056 current_mail_spool = strdup(buf);
5060 update_interval = 10.0;
5061 stuff_in_upper_case = 0;
5063 mlconfig.mldonkey_hostname = strdup("127.0.0.1");
5064 mlconfig.mldonkey_port = 4001;
5065 mlconfig.mldonkey_login = NULL;
5066 mlconfig.mldonkey_password = NULL;
5069 #ifdef TCP_PORT_MONITOR
5070 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
5071 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
5074 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
5075 info.xmms.current_project=PROJECT_NONE;
5079 static void load_config_file(const char *f)
5081 #define CONF_ERR ERR("%s: %d: config file error", f, line)
5085 set_default_configurations();
5091 char buf[256], *p, *p2, *name, *value;
5093 if (fgets(buf, 256, fp) == NULL)
5098 /* break at comment */
5099 p2 = strchr(p, '#');
5104 while (*p && isspace((int) *p))
5107 continue; /* empty line */
5113 while (*p2 && !isspace((int) *p2))
5116 *p2 = '\0'; /* break at name's end */
5123 while (*p && isspace((int) *p))
5128 p2 = value + strlen(value);
5129 while (isspace((int) *(p2 - 1)))
5135 #define CONF2(a) if (strcasecmp(name, a) == 0)
5136 #define CONF(a) else CONF2(a)
5137 #define CONF3(a,b) \
5138 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
5142 CONF2("alignment") {
5144 int a = string_to_alignment(value);
5154 ERR("on_bottom is deprecated. use own_window_hints below");
5155 on_bottom = string_to_bool(value);
5157 SET_HINT(window.hints,HINT_BELOW);
5162 CONF("background") {
5163 fork_to_background = string_to_bool(value);
5167 CONF2("background") {
5168 fork_to_background = string_to_bool(value);
5172 CONF("border_margin") {
5174 border_margin = strtol(value, 0, 0);
5178 CONF("border_width") {
5180 border_width = strtol(value, 0, 0);
5184 CONF("default_color") {
5186 default_fg_color = get_x11_color(value);
5190 CONF3("default_shade_color", "default_shadecolor") {
5192 default_bg_color = get_x11_color(value);
5196 CONF3("default_outline_color", "default_outlinecolor") {
5198 default_out_color = get_x11_color(value);
5203 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
5204 CONF("xmms_player") {
5206 if (strncmp(value,"none",4)==0)
5207 info.xmms.current_project=PROJECT_NONE;
5208 else if (strncmp(value,"xmms",4)==0)
5209 info.xmms.current_project=PROJECT_XMMS;
5210 else if (strncmp(value,"bmp",3)==0)
5211 info.xmms.current_project=PROJECT_BMP;
5212 else if (strncmp(value,"audacious",9)==0)
5213 info.xmms.current_project=PROJECT_AUDACIOUS;
5214 else if (strncmp(value,"infopipe",8)==0)
5215 info.xmms.current_project=PROJECT_INFOPIPE;
5226 strncpy(info.mpd.host, value, 127);
5232 info.mpd.port = strtol(value, 0, 0);
5233 if (info.mpd.port < 1
5234 || info.mpd.port > 0xffff)
5238 CONF("mpd_password") {
5240 strncpy(info.mpd.password, value, 127);
5245 CONF("cpu_avg_samples") {
5247 cpu_avg_samples = strtol(value, 0, 0);
5248 if (cpu_avg_samples < 1
5249 || cpu_avg_samples > 14)
5258 CONF("net_avg_samples") {
5260 net_avg_samples = strtol(value, 0, 0);
5261 if (net_avg_samples < 1
5262 || net_avg_samples > 14)
5278 CONF("double_buffer") {
5279 use_xdbe = string_to_bool(value);
5283 CONF("override_utf8_locale") {
5284 utf8_mode = string_to_bool(value);
5287 CONF("draw_borders") {
5288 draw_borders = string_to_bool(value);
5290 CONF("draw_graph_borders") {
5291 draw_graph_borders = string_to_bool(value);
5293 CONF("draw_shades") {
5294 draw_shades = string_to_bool(value);
5296 CONF("draw_outline") {
5297 draw_outline = string_to_bool(value);
5300 CONF("out_to_console") {
5301 out_to_console = string_to_bool(value);
5303 CONF("use_spacer") {
5304 use_spacer = string_to_bool(value);
5309 use_xft = string_to_bool(value);
5313 set_first_font(value);
5318 if (value && font_count >= 0)
5319 fonts[0].font_alpha = atof(value)
5328 if (string_to_bool(value))
5329 ERR("Xft not enabled");
5332 /* xftfont silently ignored when no Xft */
5335 /* xftalpha is silently ignored when no Xft */
5340 set_first_font(value);
5349 gap_x = atoi(value);
5355 gap_y = atoi(value);
5360 CONF("mail_spool") {
5363 variable_substitute(value, buf, 256);
5367 if (current_mail_spool)
5368 free(current_mail_spool);
5369 current_mail_spool = strdup(buf);
5375 CONF("minimum_size") {
5378 (value, "%d %d", &minimum_width,
5379 &minimum_height) != 2)
5382 &minimum_width) != 1)
5387 CONF("maximum_width") {
5389 if (sscanf(value, "%d", &maximum_width) != 1)
5395 CONF("no_buffers") {
5396 no_buffers = string_to_bool(value);
5399 CONF("mldonkey_hostname") {
5401 if (mlconfig.mldonkey_hostname != NULL) {
5402 free(mlconfig.mldonkey_hostname);
5404 mlconfig.mldonkey_hostname = strdup(value);
5409 CONF("mldonkey_port") {
5411 mlconfig.mldonkey_port = atoi(value);
5415 CONF("mldonkey_login") {
5417 if (mlconfig.mldonkey_login != NULL) {
5418 free(mlconfig.mldonkey_login);
5420 mlconfig.mldonkey_login = strdup(value);
5425 CONF("mldonkey_password") {
5427 if (mlconfig.mldonkey_password != NULL) {
5428 free(mlconfig.mldonkey_password);
5430 mlconfig.mldonkey_password = strdup(value);
5436 CONF("pad_percents") {
5437 pad_percents = atoi(value);
5441 CONF("own_window") {
5442 own_window = string_to_bool(value);
5444 CONF("wm_class_name") {
5445 memset(window.wm_class_name,0,sizeof(window.wm_class_name));
5446 strncpy(window.wm_class_name, value, sizeof(window.wm_class_name)-1);
5448 CONF("own_window_transparent") {
5449 set_transparent = string_to_bool(value);
5451 CONF("own_window_colour") {
5453 background_colour = get_x11_color(value);
5455 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
5458 CONF("own_window_hints") {
5460 char *p_hint, *p_save;
5461 char delim[] = ", ";
5463 /* tokenize the value into individual hints */
5464 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
5466 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
5467 if (strncmp(p_hint,"undecorate",10) == 0)
5468 SET_HINT(window.hints,HINT_UNDECORATED);
5469 else if (strncmp(p_hint,"below",5) == 0)
5470 SET_HINT(window.hints,HINT_BELOW);
5471 else if (strncmp(p_hint,"above",5) == 0)
5472 SET_HINT(window.hints,HINT_ABOVE);
5473 else if (strncmp(p_hint,"sticky",6) == 0)
5474 SET_HINT(window.hints,HINT_STICKY);
5475 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
5476 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
5477 else if (strncmp(p_hint,"skip_pager",10) == 0)
5478 SET_HINT(window.hints,HINT_SKIP_PAGER);
5482 p_hint=strtok_r(NULL, delim, &p_save);
5484 while (p_hint!=NULL);
5487 CONF("own_window_type") {
5489 if (strncmp(value,"normal",6)==0)
5490 window.type = TYPE_NORMAL;
5491 else if (strncmp(value,"desktop",7)==0)
5492 window.type = TYPE_DESKTOP;
5493 else if (strncmp(value,"override",8)==0)
5494 window.type = TYPE_OVERRIDE;
5500 CONF("stippled_borders") {
5502 stippled_borders = strtol(value, 0, 0);
5504 stippled_borders = 4;
5508 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
5511 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
5513 CONF("update_interval") {
5515 update_interval = strtod(value, 0);
5519 CONF("total_run_times") {
5521 total_run_times = strtod(value, 0);
5526 stuff_in_upper_case = string_to_bool(value);
5531 malloc(strlen(value)
5533 strcpy(seti_dir, value);
5537 if (text != original_text)
5547 int l = strlen(text);
5548 if (fgets(buf, 256, fp) == NULL)
5551 realloc(text, l + strlen(buf)
5555 if (strlen(text) > 1024 * 8)
5561 #ifdef TCP_PORT_MONITOR
5562 CONF("min_port_monitors")
5565 (sscanf(value, "%d", &tcp_port_monitor_collection_args.min_port_monitors) != 1) ||
5566 tcp_port_monitor_collection_args.min_port_monitors < 0 )
5568 /* an error. use default, warn and continue. */
5569 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
5572 else if ( tcp_port_monitor_collection_args.min_port_monitors == 0 )
5574 /* no error, just use default */
5575 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
5577 /* else tcp_port_monitor_collection_args.min_port_monitors > 0 as per config */
5579 CONF("min_port_monitor_connections")
5582 (sscanf(value, "%d", &tcp_port_monitor_args.min_port_monitor_connections) != 1)
5583 || tcp_port_monitor_args.min_port_monitor_connections < 0 )
5585 /* an error. use default, warni and continue. */
5586 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
5589 else if ( tcp_port_monitor_args.min_port_monitor_connections == 0 )
5591 /* no error, just use default */
5592 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
5594 /* else tcp_port_monitor_args.min_port_monitor_connections > 0 as per config */
5598 ERR("%s: %d: no such configuration: '%s'", f, line, name);
5608 /* : means that character before that takes an argument */
5609 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
5622 int main(int argc, char **argv)
5624 struct sigaction act, oact;
5627 memset(&info, 0, sizeof(info) );
5629 #ifdef TCP_PORT_MONITOR
5630 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
5631 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
5635 SET_XMMS_PROJECT_AVAILABLE(info.xmms.project_mask, PROJECT_XMMS);
5638 SET_XMMS_PROJECT_AVAILABLE(info.xmms.project_mask, PROJECT_BMP);
5640 #if defined(AUDACIOUS)
5641 SET_XMMS_PROJECT_AVAILABLE(info.xmms.project_mask, PROJECT_AUDACIOUS);
5643 #if defined(INFOPIPE)
5644 SET_XMMS_PROJECT_AVAILABLE(info.xmms.project_mask, PROJECT_INFOPIPE);
5647 /* handle command line parameters that don't change configs */
5653 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
5654 *s) || ((s = getenv("LANG")) && *s)) {
5656 for(x = 0; x < strlen(s) ; x++) {
5657 temp[x] = tolower(s[x]);
5659 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
5663 if (!setlocale(LC_CTYPE, "")) {
5664 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
5668 int c = getopt(argc,
5678 ("Conky " VERSION " compiled " __DATE__ "\n");
5682 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
5683 * though free() does the NULL check itself;), then load optarg value */
5685 free(current_config);
5686 current_config = strdup(optarg);
5691 ("Usage: %s [OPTION]...\n"
5692 "Conky is a system monitor that renders text on desktop or to own transparent\n"
5693 "window. Command line options will override configurations defined in config\n"
5696 " -c FILE config file to load instead of "
5699 " -d daemonize, fork to background\n"
5702 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
5703 " -f FONT font to use\n"
5705 " -o create own window to draw\n"
5708 " -b double buffer (prevents flickering)\n"
5710 " -w WIN_ID window id to draw\n"
5711 " -x X x position\n"
5712 " -y Y y position\n"
5714 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
5715 " -u SECS update interval\n"
5716 " -i NUM number of times to update Conky\n", argv[0]);
5720 window.window = strtol(optarg, 0, 0);
5729 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
5733 /* load current_config or CONFIG_FILE */
5736 if (current_config == NULL) {
5737 /* load default config file */
5740 variable_substitute(CONFIG_FILE, buf, 256);
5743 current_config = strdup(buf);
5747 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
5748 load_config_file(current_config);
5750 set_default_configurations();
5754 if (current_mail_spool == NULL) {
5756 variable_substitute(MAIL_FILE, buf, 256);
5759 current_mail_spool = strdup(buf);
5763 /* handle other command line arguments */
5765 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
5766 optind = optreset = 1;
5771 #if defined(__FreeBSD__)
5772 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
5773 O_RDONLY, "kvm_open")) == NULL)
5774 CRIT_ERR( "cannot read kvm");
5778 int c = getopt(argc,
5786 fork_to_background = 1;
5791 set_first_font(optarg);
5794 text_alignment = string_to_alignment(optarg);
5809 if (text != original_text)
5811 text = strdup(optarg);
5812 convert_escapes(text);
5816 update_interval = strtod(optarg, 0);
5820 total_run_times = strtod(optarg, 0);
5824 gap_x = atoi(optarg);
5828 gap_y = atoi(optarg);
5842 /* generate text and get initial size */
5843 extract_variable_text(text);
5844 if (text != original_text) {
5849 if (fork_to_background) {
5853 ERR("can't fork() to background: %s",
5860 fprintf(stderr,"\n");fflush(stderr);
5864 /* parent process */
5865 fprintf(stderr,"Conky: forked to background, pid is %d\n",pid);
5875 update_text_area(); /* to get initial size of the window */
5879 text_width + border_margin * 2 + 1,
5880 text_height + border_margin * 2 + 1,
5881 set_transparent, background_colour, info.uname_s.nodename, argv, argc);
5883 update_text_area(); /* to position text/window on screen */
5887 // why the fuck not?
5893 if (own_window && !fixed_pos) {
5894 XMoveWindow(display, window.window, window.x, window.y);
5897 set_transparent_background(window.window);
5908 /* Set signal handlers */
5909 act.sa_handler = signal_handler;
5910 sigemptyset(&act.sa_mask);
5913 act.sa_flags |= SA_RESTART;
5916 if ( sigaction(SIGINT,&act,&oact) < 0 ||
5917 sigaction(SIGUSR1,&act,&oact) < 0 ||
5918 sigaction(SIGTERM,&act,&oact) < 0 )
5920 ERR("error setting signal handler: %s", strerror(errno) );
5923 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
5924 if ( (info.xmms.current_project > PROJECT_NONE) && (create_xmms_thread() !=0) )
5926 CRIT_ERR("unable to create xmms_player thread!");
5932 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
5933 if ( info.xmms.thread && (destroy_xmms_thread()!=0) )
5935 ERR("error destroying xmms_player thread");
5939 #if defined(__FreeBSD__)
5946 void signal_handler(int sig)
5948 /* signal handler is light as a feather, as it should be.
5949 * we will poll g_signal_pending with each loop of conky
5950 * and do any signal processing there, NOT here. pkovacs. */
5951 g_signal_pending=sig;