2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
28 #include <X11/Xutil.h>
30 #include <sys/types.h>
33 #define CONFIG_FILE "$HOME/.conkyrc"
34 #define MAIL_FILE "$MAIL"
35 #define MAX_IF_BLOCK_DEPTH 5
37 /* #define SIGNAL_BLOCKING */
38 #undef SIGNAL_BLOCKING
55 char name[TEXT_BUFFER_SIZE];
65 static int selected_font = 0;
66 static int font_count = -1;
67 struct font_list *fonts = NULL;
71 #define font_height() use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
72 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
73 #define font_ascent() use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent
74 #define font_descent() use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent
78 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
79 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
80 #define font_descent() fonts[selected_font].font->max_bounds.descent
84 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
87 static void set_font();
89 int addfont(const char *data_in)
91 if (font_count > MAX_FONTS) {
92 CRIT_ERR("you don't need that many fonts, sorry.");
95 if (font_count == 0) {
99 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
103 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
105 CRIT_ERR("realloc in addfont");
107 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
108 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
110 fonts[font_count].font_alpha = 0xffff;
113 CRIT_ERR("Oops...looks like something overflowed in addfont().");
118 void set_first_font(const char *data_in)
120 if (font_count < 0) {
121 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
126 if (strlen(data_in) > 1) {
127 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
129 fonts[0].font_alpha = 0xffff;
137 for (i=0;i<=font_count;i++) {
140 XftFontClose(display, fonts[i].xftfont);
144 XFreeFont(display, fonts[i].font);
151 set_first_font("6x10");
155 static void load_fonts()
158 for (i=0;i<=font_count;i++) {
162 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
163 XftFontClose(display, fonts[i].xftfont);
165 if ((fonts[i].xftfont =
166 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
169 ERR("can't load Xft font '%s'", fonts[i].name);
170 if ((fonts[i].xftfont =
171 XftFontOpenName(display, screen,
172 "courier-12")) != NULL)
175 ERR("can't load Xft font '%s'", "courier-12");
177 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
178 CRIT_ERR("can't load font '%s'", "fixed");
185 /* load normal font */
186 /* if (fonts[i].font != NULL)
187 XFreeFont(display, fonts[i].font);*/
189 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
190 ERR("can't load font '%s'", fonts[i].name);
191 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
192 CRIT_ERR("can't load font '%s'", "fixed");
193 printf("loaded fixed?\n");
201 /* default config file */
202 static char *current_config;
204 /* set to 1 if you want all text to be in uppercase */
205 static unsigned int stuff_in_upper_case;
207 /* Update interval */
208 static double update_interval;
210 /* Run how many times? */
211 static unsigned long total_run_times;
214 static int fork_to_background;
216 static int cpu_avg_samples, net_avg_samples;
220 /* Always on bottom */
221 static int on_bottom;
223 /* Position on the screen */
224 static int text_alignment;
225 static int gap_x, gap_y;
228 static int draw_borders;
229 static int draw_graph_borders;
230 static int stippled_borders;
232 static int draw_shades, draw_outline;
234 static int border_margin, border_width;
236 static long default_fg_color, default_bg_color, default_out_color;
238 /* create own window or draw stuff to root? */
239 static int set_transparent = 0;
243 static int own_window = 0;
244 static int background_colour = 0;
245 static char wm_class_name[256];
246 /* fixed size/pos is set if wm/user changes them */
247 static int fixed_size = 0, fixed_pos = 0;
250 static int minimum_width, minimum_height;
251 static int maximum_width;
258 /* no buffers in used memory? */
261 /* pad percentages to decimals? */
262 static int pad_percents = 0;
264 #ifdef TCP_PORT_MONITOR
265 tcp_port_monitor_collection_args_t tcp_port_monitor_collection_args;
266 tcp_port_monitor_args_t tcp_port_monitor_args;
269 /* Text that is shown */
270 static char original_text[] =
271 "$nodename - $sysname $kernel on $machine\n"
273 "${color grey}Uptime:$color $uptime\n"
274 "${color grey}Frequency (in MHz):$color $freq\n"
275 "${color grey}Frequency (in GHz):$color $freq_g\n"
276 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
277 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
278 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
279 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
281 "${color grey}File systems:\n"
282 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
283 "${color grey}Networking:\n"
284 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
285 "${color grey}Temperatures:\n"
286 " CPU:$color ${i2c temp 1}°C${color grey} - MB:$color ${i2c temp 2}°C\n"
289 "${color grey}SETI@Home Statistics:\n"
290 "${color grey}Seti Unit Number:$color $seti_credit\n"
291 "${color grey}Seti Progress:$color $seti_prog% $seti_progbar\n"
294 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
295 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_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 >= 128)
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[graph->graph_width - 1] = f; /* add new data */
528 for (i = 0; i < graph->graph_width - 1; 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,
807 #endif /* __linux__ */
834 OBJ_ml_upload_counter,
835 OBJ_ml_download_counter,
836 OBJ_ml_nshared_files,
837 OBJ_ml_shared_counter,
838 OBJ_ml_tcp_upload_rate,
839 OBJ_ml_tcp_download_rate,
840 OBJ_ml_udp_upload_rate,
841 OBJ_ml_udp_download_rate,
842 OBJ_ml_ndownloaded_files,
843 OBJ_ml_ndownloading_files,
846 OBJ_running_processes,
855 OBJ_temp1, /* i2c is used instead in these */
868 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
870 OBJ_apm_battery_time,
871 OBJ_apm_battery_life,
872 #endif /* __FreeBSD__ */
896 OBJ_audacious_status,
898 OBJ_audacious_song_length,
899 OBJ_audacious_song_length_seconds,
900 OBJ_audacious_song_length_frames,
901 OBJ_audacious_song_output_length,
902 OBJ_audacious_song_output_length_seconds,
903 OBJ_audacious_song_output_length_frames,
904 OBJ_audacious_song_bitrate,
905 OBJ_audacious_song_frequency,
906 OBJ_audacious_song_channels,
918 OBJ_infopipe_protocol,
919 OBJ_infopipe_version,
921 OBJ_infopipe_playlist_tunes,
922 OBJ_infopipe_playlist_currtune,
923 OBJ_infopipe_usec_position,
924 OBJ_infopipe_position,
925 OBJ_infopipe_usec_time,
927 OBJ_infopipe_bitrate,
928 OBJ_infopipe_frequency,
929 OBJ_infopipe_channels,
934 #ifdef TCP_PORT_MONITOR
942 unsigned int c, d, e;
945 char *s; /* some string */
946 int i; /* some integer */
947 long l; /* some other integer */
948 struct net_stat *net;
950 unsigned char loadavg[3];
951 //unsigned int diskio;
952 unsigned int cpu_index;
998 #ifdef TCP_PORT_MONITOR
1000 in_port_t port_range_begin; /* starting port to monitor */
1001 in_port_t port_range_end; /* ending port to monitor */
1002 int item; /* enum value from libtcp-portmon.h, e.g. COUNT, REMOTEIP, etc. */
1003 int connection_index; /* 0 to n-1 connections. */
1009 struct text_object_list {
1010 unsigned int text_object_count;
1011 struct text_object *text_objects;
1014 static unsigned int text_object_count;
1015 static struct text_object *text_objects;
1016 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1018 pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
1020 void *threaded_exec( struct text_object *obj ) {
1021 char *p2 = obj->data.execi.buffer;
1022 FILE *fp = popen(obj->data.execi.cmd,"r");
1023 pthread_mutex_lock( &mutex1 );
1024 int n2 = fread(p2, 1, TEXT_BUFFER_SIZE, fp);
1027 if (n2 && p2[n2 - 1] == '\n')
1035 pthread_mutex_unlock( &mutex1 );
1039 static struct text_object *new_text_object_internal()
1041 struct text_object *obj = malloc(sizeof(struct text_object));
1042 memset(obj, 0, sizeof(struct text_object));
1049 if (mlconfig.mldonkey_hostname) {
1050 free(mlconfig.mldonkey_hostname);
1051 mlconfig.mldonkey_hostname = NULL;
1056 static void free_text_objects(unsigned int count, struct text_object *objs)
1059 for (i = 0; i < count; i++) {
1060 switch (objs[i].type) {
1062 close(objs[i].data.i);
1065 close(objs[i].data.i);
1068 close(objs[i].data.i2c.fd);
1071 free(objs[i].data.s);
1074 case OBJ_if_existing:
1075 case OBJ_if_mounted:
1076 case OBJ_if_running:
1077 free(objs[i].data.ifblock.s);
1080 free(objs[i].data.tail.logfile);
1081 free(objs[i].data.tail.buffer);
1083 case OBJ_text: case OBJ_font:
1084 free(objs[i].data.s);
1087 free(objs[i].data.s);
1090 free(objs[i].data.s);
1093 free(objs[i].data.s);
1095 /* case OBJ_execibar:
1096 free(objs[i].data.s);
1098 case OBJ_execigraph:
1099 free(objs[i].data.s);
1103 case OBJ_mpd_artist:
1105 case OBJ_mpd_random:
1106 case OBJ_mpd_repeat:
1108 case OBJ_mpd_status:
1112 case OBJ_bmpx_title:
1113 case OBJ_bmpx_artist:
1114 case OBJ_bmpx_album:
1115 case OBJ_bmpx_track:
1117 case OBJ_bmpx_bitrate:
1121 free(objs[i].data.s);
1125 free(objs[i].data.execi.cmd);
1126 free(objs[i].data.execi.buffer);
1129 free(objs[i].data.execi.cmd);
1130 free(objs[i].data.execi.buffer);
1133 if (info.first_process) {
1134 free_all_processes();
1135 info.first_process = NULL;
1139 if (info.first_process) {
1140 free_all_processes();
1141 info.first_process = NULL;
1147 //text_objects = NULL;
1148 //text_object_count = 0;
1151 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1156 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1157 *a = mixer_init(buf1);
1158 (void) scan_bar(arg + n, w, h);
1161 (void) scan_bar(arg, w, h);
1166 /* construct_text_object() creates a new text_object */
1167 static struct text_object *construct_text_object(const char *s, const char *arg)
1169 //struct text_object *obj = new_text_object();
1170 struct text_object *obj = new_text_object_internal();
1172 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
1173 #define END ; } } else
1177 obj->type = OBJ_color;
1178 obj->data.l = get_x11_color(s);
1181 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
1182 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
1183 END OBJ(acpiacadapter, 0)
1186 END OBJ(freq_dyn, 0);
1187 END OBJ(freq_dyn_g, 0);
1188 END OBJ(acpifan, 0);
1189 END OBJ(battery, 0);
1192 sscanf(arg, "%63s", bat);
1194 strcpy(bat, "BAT0");
1195 obj->data.s = strdup(bat);
1196 #if defined(__linux__)
1197 END OBJ(i8k_version, INFO_I8K)
1198 END OBJ(i8k_bios, INFO_I8K)
1199 END OBJ(i8k_serial, INFO_I8K)
1200 END OBJ(i8k_cpu_temp, INFO_I8K)
1201 END OBJ(i8k_cpu_tempf, INFO_I8K)
1202 END OBJ(i8k_left_fan_status, INFO_I8K)
1203 END OBJ(i8k_right_fan_status, INFO_I8K)
1204 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1205 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1206 END OBJ(i8k_ac_status, INFO_I8K)
1207 END OBJ(i8k_buttons_status, INFO_I8K)
1208 #endif /* __linux__ */
1209 END OBJ(buffers, INFO_BUFFERS)
1210 END OBJ(cached, INFO_BUFFERS)
1211 END OBJ(cpu, INFO_CPU)
1213 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1214 obj->data.cpu_index = atoi(&arg[3]);
1216 } else {obj->data.cpu_index = 0; }
1218 obj->data.cpu_index = 0;
1220 END OBJ(cpubar, INFO_CPU)
1222 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1223 obj->data.cpu_index = atoi(&arg[3]);
1226 else {obj->data.cpu_index = 0;}
1227 (void) scan_bar(arg, &obj->a, &obj->b);
1229 (void) scan_bar(arg, &obj->a, &obj->b);
1230 obj->data.cpu_index = 0;
1232 END OBJ(cpugraph, INFO_CPU)
1234 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1235 obj->data.cpu_index = atoi(&arg[3]);
1238 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1240 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1241 obj->data.cpu_index = 0;
1243 END OBJ(diskio, INFO_DISKIO)
1244 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1247 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1251 obj->data.s = scan_font(arg);
1253 OBJ(downspeed, INFO_NET)
1255 obj->data.net = get_net_stat(arg);
1258 CRIT_ERR("downspeed needs argument");
1260 END OBJ(downspeedf, INFO_NET)
1262 obj->data.net = get_net_stat(arg);
1265 CRIT_ERR("downspeedf needs argument");
1267 END OBJ(downspeedgraph, INFO_NET)
1268 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1270 sscanf(arg, "%63s %*i,%*i %*i", buf);
1271 obj->data.net = get_net_stat(buf);
1272 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
1273 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
1282 text_objects[blockstart[blockdepth - 1] -
1283 1].data.ifblock.pos = text_object_count;
1284 blockstart[blockdepth - 1] = text_object_count;
1285 obj->data.ifblock.pos = text_object_count + 2;
1287 ERR("$else: no matching $if_*");
1292 text_objects[blockstart[blockdepth] - 1].data.ifblock.pos =
1295 ERR("$endif: no matching $if_*");
1299 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
1300 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
1301 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
1302 END OBJ(execibar, 0) unsigned int n;
1303 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1305 ERR("${execibar <interval> command}");
1306 obj->type = OBJ_text;
1307 snprintf(buf, 256, "${%s}", s);
1308 obj->data.s = strdup(buf);
1310 obj->data.execi.cmd = strdup(arg + n);
1312 END OBJ(execigraph, 0) unsigned int n;
1313 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1315 ERR("${execigraph <interval> command}");
1316 obj->type = OBJ_text;
1317 snprintf(buf, 256, "${%s}", s);
1318 obj->data.s = strdup(buf);
1320 obj->data.execi.cmd = strdup(arg + n);
1322 END OBJ(execi, 0) unsigned int n;
1325 || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1327 ERR("${execi <interval> command}");
1328 obj->type = OBJ_text;
1329 snprintf(buf, 256, "${%s}", s);
1330 obj->data.s = strdup(buf);
1332 obj->data.execi.cmd = strdup(arg + n);
1333 obj->data.execi.buffer =
1334 (char *) calloc(1, TEXT_BUFFER_SIZE);
1336 END OBJ(texeci, 0) unsigned int n;
1339 || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1341 ERR("${texeci <interval> command}");
1342 obj->type = OBJ_text;
1343 snprintf(buf, 256, "${%s}", s);
1344 obj->data.s = strdup(buf);
1346 obj->data.execi.cmd = strdup(arg + n);
1347 obj->data.execi.buffer =
1348 (char *) calloc(1, TEXT_BUFFER_SIZE);
1350 END OBJ(pre_exec, 0) obj->type = OBJ_text;
1352 FILE *fp = popen(arg, "r");
1356 n = fread(buf, 1, 2048, fp);
1359 if (n && buf[n - 1] == '\n')
1364 obj->data.s = strdup(buf);
1366 obj->data.s = strdup("");
1369 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
1370 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1372 while (isspace(*arg))
1378 obj->data.fsbar.fs = prepare_fs_stat(arg);
1379 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
1382 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
1386 obj->data.fsbar.fs = prepare_fs_stat(arg);
1387 END OBJ(fs_free, INFO_FS) if (!arg)
1389 obj->data.fs = prepare_fs_stat(arg);
1390 END OBJ(fs_used_perc, INFO_FS) if (!arg)
1392 obj->data.fs = prepare_fs_stat(arg);
1393 END OBJ(fs_free_perc, INFO_FS) if (!arg)
1395 obj->data.fs = prepare_fs_stat(arg);
1396 END OBJ(fs_size, INFO_FS) if (!arg)
1398 obj->data.fs = prepare_fs_stat(arg);
1399 END OBJ(fs_used, INFO_FS) if (!arg)
1401 obj->data.fs = prepare_fs_stat(arg);
1402 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
1403 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
1404 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
1405 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
1409 ERR("i2c needs arguments");
1410 obj->type = OBJ_text;
1411 //obj->data.s = strdup("${i2c}");
1415 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
1416 /* if scanf couldn't read three values, read type and num and use
1418 sscanf(arg, "%63s %d", buf2, &n);
1420 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
1421 obj->data.i2c.devtype);
1422 strncpy(obj->data.i2c.type, buf2, 63);
1425 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
1426 obj->data.i2c.devtype);
1427 strncpy(obj->data.i2c.type, buf2, 63);
1430 END OBJ(top, INFO_TOP)
1434 ERR("top needs arguments");
1435 obj->type = OBJ_text;
1436 //obj->data.s = strdup("${top}");
1439 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1440 if (strcmp(buf, "name") == 0) {
1441 obj->data.top.type = TOP_NAME;
1442 } else if (strcmp(buf, "cpu") == 0) {
1443 obj->data.top.type = TOP_CPU;
1444 } else if (strcmp(buf, "pid") == 0) {
1445 obj->data.top.type = TOP_PID;
1446 } else if (strcmp(buf, "mem") == 0) {
1447 obj->data.top.type = TOP_MEM;
1449 ERR("invalid arg for top");
1452 if (n < 1 || n > 10) {
1453 CRIT_ERR("invalid arg for top");
1456 obj->data.top.num = n - 1;
1460 ERR("invalid args given for top");
1463 END OBJ(top_mem, INFO_TOP)
1467 ERR("top_mem needs arguments");
1468 obj->type = OBJ_text;
1469 obj->data.s = strdup("${top_mem}");
1472 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1473 if (strcmp(buf, "name") == 0) {
1474 obj->data.top.type = TOP_NAME;
1475 } else if (strcmp(buf, "cpu") == 0) {
1476 obj->data.top.type = TOP_CPU;
1477 } else if (strcmp(buf, "pid") == 0) {
1478 obj->data.top.type = TOP_PID;
1479 } else if (strcmp(buf, "mem") == 0) {
1480 obj->data.top.type = TOP_MEM;
1482 ERR("invalid arg for top");
1485 if (n < 1 || n > 10) {
1486 CRIT_ERR("invalid arg for top");
1489 obj->data.top.num = n - 1;
1493 ERR("invalid args given for top");
1496 END OBJ(addr, INFO_NET)
1498 obj->data.net = get_net_stat(arg);
1501 CRIT_ERR("addr needs argument");
1503 END OBJ(linkstatus, INFO_WIFI)
1505 obj->data.net = get_net_stat(arg);
1508 CRIT_ERR("linkstatus needs argument");
1514 ERR("tail needs arguments");
1515 obj->type = OBJ_text;
1516 obj->data.s = strdup("${tail}");
1519 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
1520 if (n1 < 1 || n1 > 30) {
1521 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
1525 fp = fopen(buf, "r");
1527 obj->data.tail.logfile =
1528 malloc(TEXT_BUFFER_SIZE);
1529 strcpy(obj->data.tail.logfile, buf);
1530 obj->data.tail.wantedlines = n1 - 1;
1531 obj->data.tail.interval =
1532 update_interval * 2;
1536 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
1539 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
1540 if (n1 < 1 || n1 > 30) {
1542 ("invalid arg for tail, number of lines must be between 1 and 30");
1544 } else if (n2 < 1 || n2 < update_interval) {
1546 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
1550 fp = fopen(buf, "r");
1552 obj->data.tail.logfile =
1553 malloc(TEXT_BUFFER_SIZE);
1554 strcpy(obj->data.tail.logfile, buf);
1555 obj->data.tail.wantedlines = n1 - 1;
1556 obj->data.tail.interval = n2;
1560 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
1566 ERR("invalid args given for tail");
1569 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
1574 ERR("head needs arguments");
1575 obj->type = OBJ_text;
1576 obj->data.s = strdup("${head}");
1579 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
1580 if (n1 < 1 || n1 > 30) {
1581 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
1585 fp = fopen(buf, "r");
1587 obj->data.tail.logfile =
1588 malloc(TEXT_BUFFER_SIZE);
1589 strcpy(obj->data.tail.logfile, buf);
1590 obj->data.tail.wantedlines = n1 - 1;
1591 obj->data.tail.interval =
1592 update_interval * 2;
1596 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
1599 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
1600 if (n1 < 1 || n1 > 30) {
1602 ("invalid arg for head, number of lines must be between 1 and 30");
1604 } else if (n2 < 1 || n2 < update_interval) {
1606 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
1610 fp = fopen(buf, "r");
1612 obj->data.tail.logfile =
1613 malloc(TEXT_BUFFER_SIZE);
1614 strcpy(obj->data.tail.logfile, buf);
1615 obj->data.tail.wantedlines = n1 - 1;
1616 obj->data.tail.interval = n2;
1620 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
1626 ERR("invalid args given for head");
1629 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
1630 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
1632 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1633 if (r >= 3 && (c < 1 || c > 3))
1635 if (r >= 2 && (b < 1 || b > 3))
1637 if (r >= 1 && (a < 1 || a > 3))
1640 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1641 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1642 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1643 END OBJ(if_existing, 0)
1644 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1645 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1648 ERR("if_existing needs an argument");
1649 obj->data.ifblock.s = 0;
1651 obj->data.ifblock.s = strdup(arg);
1652 blockstart[blockdepth] = text_object_count;
1653 obj->data.ifblock.pos = text_object_count + 2;
1655 END OBJ(if_mounted, 0)
1656 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1657 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1660 ERR("if_mounted needs an argument");
1661 obj->data.ifblock.s = 0;
1663 obj->data.ifblock.s = strdup(arg);
1664 blockstart[blockdepth] = text_object_count;
1665 obj->data.ifblock.pos = text_object_count + 2;
1667 END OBJ(if_running, 0)
1668 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1669 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1673 snprintf(buf, 256, "pidof %s >/dev/null", arg);
1674 obj->data.ifblock.s = strdup(buf);
1676 ERR("if_running needs an argument");
1677 obj->data.ifblock.s = 0;
1679 blockstart[blockdepth] = text_object_count;
1680 obj->data.ifblock.pos = text_object_count + 2;
1684 END OBJ(mails, INFO_MAIL)
1685 END OBJ(mem, INFO_MEM)
1686 END OBJ(memmax, INFO_MEM)
1687 END OBJ(memperc, INFO_MEM)
1688 END OBJ(membar, INFO_MEM)
1689 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1690 END OBJ(memgraph, INFO_MEM)
1691 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1692 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
1693 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
1694 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
1695 END OBJ(mixerbar, INFO_MIXER)
1696 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1697 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1698 END OBJ(mixerlbar, INFO_MIXER)
1699 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1700 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1701 END OBJ(mixerrbar, INFO_MIXER)
1702 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1703 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1706 OBJ(ml_upload_counter, INFO_MLDONKEY)
1707 END OBJ(ml_download_counter, INFO_MLDONKEY)
1708 END OBJ(ml_nshared_files, INFO_MLDONKEY)
1709 END OBJ(ml_shared_counter, INFO_MLDONKEY)
1710 END OBJ(ml_tcp_upload_rate, INFO_MLDONKEY)
1711 END OBJ(ml_tcp_download_rate, INFO_MLDONKEY)
1712 END OBJ(ml_udp_upload_rate, INFO_MLDONKEY)
1713 END OBJ(ml_udp_download_rate, INFO_MLDONKEY)
1714 END OBJ(ml_ndownloaded_files, INFO_MLDONKEY)
1715 END OBJ(ml_ndownloading_files, INFO_MLDONKEY) END
1717 OBJ(new_mails, INFO_MAIL)
1718 END OBJ(nodename, 0)
1719 END OBJ(processes, INFO_PROCS)
1720 END OBJ(running_processes, INFO_RUN_PROCS)
1721 END OBJ(shadecolor, 0)
1723 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
1725 END OBJ(outlinecolor, 0)
1727 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
1729 END OBJ(stippled_hr, 0)
1731 int a = stippled_borders, b = 1;
1733 if (sscanf(arg, "%d %d", &a, &b) != 2)
1734 sscanf(arg, "%d", &b);
1738 obj->data.pair.a = a;
1739 obj->data.pair.b = b;
1741 END OBJ(swap, INFO_MEM)
1742 END OBJ(swapmax, INFO_MEM)
1743 END OBJ(swapperc, INFO_MEM)
1744 END OBJ(swapbar, INFO_MEM)
1745 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1746 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
1748 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
1749 obj->data.i2c.devtype);
1750 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
1752 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
1753 obj->data.i2c.devtype);
1754 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1755 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1756 END OBJ(totaldown, INFO_NET)
1758 obj->data.net = get_net_stat(arg);
1761 CRIT_ERR("totaldown needs argument");
1763 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
1765 obj->data.net = get_net_stat(arg);
1768 CRIT_ERR("totalup needs argument");
1771 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
1772 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
1773 END OBJ(upspeed, INFO_NET)
1775 obj->data.net = get_net_stat(arg);
1778 CRIT_ERR("upspeed needs argument");
1780 END OBJ(upspeedf, INFO_NET)
1782 obj->data.net = get_net_stat(arg);
1785 CRIT_ERR("upspeedf needs argument");
1788 END OBJ(upspeedgraph, INFO_NET)
1789 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1791 sscanf(arg, "%63s %*i,%*i %*i", buf);
1792 obj->data.net = get_net_stat(buf);
1793 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
1794 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
1799 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
1800 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
1801 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
1802 OBJ(apm_adapter, 0) END
1803 OBJ(apm_battery_life, 0) END
1804 OBJ(apm_battery_time, 0) END
1805 #endif /* __FreeBSD__ */
1807 OBJ(seti_prog, INFO_SETI) END OBJ(seti_progbar, INFO_SETI)
1808 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1809 END OBJ(seti_credit, INFO_SETI) END
1812 OBJ(mpd_artist, INFO_MPD)
1813 END OBJ(mpd_title, INFO_MPD)
1814 END OBJ(mpd_random, INFO_MPD)
1815 END OBJ(mpd_repeat, INFO_MPD)
1816 END OBJ(mpd_elapsed, INFO_MPD)
1817 END OBJ(mpd_length, INFO_MPD)
1818 END OBJ(mpd_track, INFO_MPD)
1819 END OBJ(mpd_percent, INFO_MPD)
1820 END OBJ(mpd_album, INFO_MPD) END OBJ(mpd_vol,
1821 INFO_MPD) END OBJ(mpd_bitrate,
1823 END OBJ(mpd_status, INFO_MPD)
1824 END OBJ(mpd_bar, INFO_MPD)
1825 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1829 OBJ(audacious_status, INFO_AUDACIOUS) END
1830 OBJ(audacious_song, INFO_AUDACIOUS) END
1831 OBJ(audacious_song_length, INFO_AUDACIOUS) END
1832 OBJ(audacious_song_length_seconds, INFO_AUDACIOUS) END
1833 OBJ(audacious_song_length_frames, INFO_AUDACIOUS) END
1834 OBJ(audacious_song_output_length, INFO_AUDACIOUS) END
1835 OBJ(audacious_song_output_length_seconds, INFO_AUDACIOUS) END
1836 OBJ(audacious_song_output_length_frames, INFO_AUDACIOUS) END
1837 OBJ(audacious_song_bitrate, INFO_AUDACIOUS) END
1838 OBJ(audacious_song_frequency, INFO_AUDACIOUS) END
1839 OBJ(audacious_song_channels, INFO_AUDACIOUS) END
1840 OBJ(audacious_bar, INFO_AUDACIOUS)
1841 (void) scan_bar(arg, &obj->a, &obj->b);
1845 OBJ(bmpx_title, INFO_BMPX)
1846 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1848 OBJ(bmpx_artist, INFO_BMPX)
1849 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1851 OBJ(bmpx_album, INFO_BMPX)
1852 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1854 OBJ(bmpx_track, INFO_BMPX)
1855 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1857 OBJ(bmpx_uri, INFO_BMPX)
1858 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1860 OBJ(bmpx_bitrate, INFO_BMPX)
1861 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1865 OBJ(infopipe_protocol, INFO_INFOPIPE) END
1866 OBJ(infopipe_version, INFO_INFOPIPE) END
1867 OBJ(infopipe_status, INFO_INFOPIPE) END
1868 OBJ(infopipe_playlist_tunes, INFO_INFOPIPE) END
1869 OBJ(infopipe_playlist_currtune, INFO_INFOPIPE) END
1870 OBJ(infopipe_usec_position, INFO_INFOPIPE) END
1871 OBJ(infopipe_position, INFO_INFOPIPE) END
1872 OBJ(infopipe_usec_time, INFO_INFOPIPE) END
1873 OBJ(infopipe_time, INFO_INFOPIPE) END
1874 OBJ(infopipe_bitrate, INFO_INFOPIPE) END
1875 OBJ(infopipe_frequency, INFO_INFOPIPE) END
1876 OBJ(infopipe_channels, INFO_INFOPIPE) END
1877 OBJ(infopipe_title, INFO_INFOPIPE) END
1878 OBJ(infopipe_file, INFO_INFOPIPE) END
1879 OBJ(infopipe_bar, INFO_INFOPIPE)
1880 (void) scan_bar(arg, &obj->a, &obj->b);
1883 #ifdef TCP_PORT_MONITOR
1884 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
1885 int argc, port_begin, port_end, item, connection_index;
1887 memset(itembuf,0,sizeof(itembuf));
1889 /* massive argument checking */
1891 CRIT_ERR("tcp_portmon: needs arguments");
1893 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
1894 if ( (argc != 3) && (argc != 4) )
1896 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
1898 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
1900 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
1902 if ( port_begin > port_end )
1904 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
1906 if ( strncmp(itembuf,"count",31) == 0 )
1908 else if ( strncmp(itembuf,"rip",31) == 0 )
1910 else if ( strncmp(itembuf,"rhost",31) == 0 )
1912 else if ( strncmp(itembuf,"rport",31) == 0 )
1914 else if ( strncmp(itembuf,"lip",31) == 0 )
1916 else if ( strncmp(itembuf,"lhost",31) == 0 )
1918 else if ( strncmp(itembuf,"lport",31) == 0 )
1920 else if ( strncmp(itembuf,"lservice",31) == 0 )
1924 CRIT_ERR("tcp_portmon: invalid item specified");
1926 if ( (argc==3) && (item!=COUNT) )
1928 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
1930 if ( (argc==4) && (connection_index<0) )
1932 CRIT_ERR("tcp_portmon: connection index must be non-negative");
1934 /* ok, args looks good. save the text object data */
1935 obj->data.tcp_port_monitor.port_range_begin = (in_addr_t)port_begin;
1936 obj->data.tcp_port_monitor.port_range_end = (in_addr_t)port_end;
1937 obj->data.tcp_port_monitor.item = item;
1938 obj->data.tcp_port_monitor.connection_index = connection_index;
1940 /* if the port monitor collection hasn't been created, we must create it */
1941 if ( !info.p_tcp_port_monitor_collection )
1943 info.p_tcp_port_monitor_collection =
1944 create_tcp_port_monitor_collection( &tcp_port_monitor_collection_args );
1945 if ( !info.p_tcp_port_monitor_collection )
1947 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
1951 /* if a port monitor for this port does not exist, create one and add it to the collection */
1952 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
1954 tcp_port_monitor_t * p_monitor =
1955 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
1958 CRIT_ERR("tcp_portmon: unable to create port monitor");
1960 /* add the newly created monitor to the collection */
1961 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
1964 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
1971 ERR("unknown variable %s", s);
1972 obj->type = OBJ_text;
1973 snprintf(buf, 256, "${%s}", s);
1974 obj->data.s = strdup(buf);
1981 static struct text_object *create_plain_text(const char *s)
1983 struct text_object *obj;
1985 if (s == NULL || *s == '\0') {
1989 obj = new_text_object_internal();
1991 obj->type = OBJ_text;
1992 obj->data.s = strdup(s);
1996 static struct text_object_list *extract_variable_text_internal(const char *p)
1998 struct text_object_list *retval;
1999 struct text_object *obj;
2002 retval = malloc(sizeof(struct text_object_list));
2003 memset(retval, 0, sizeof(struct text_object_list));
2004 retval->text_object_count = 0;
2009 obj = create_plain_text(s);
2011 // allocate memory for the object
2012 retval->text_objects = realloc(retval->text_objects,
2013 sizeof(struct text_object) * (retval->text_object_count+1));
2014 // assign the new object to the end of the list.
2015 memcpy(&retval->text_objects[retval->text_object_count++],
2016 obj, sizeof(struct text_object));
2028 /* variable is either $foo or ${foo} */
2032 while (*p && *p != '}')
2038 while (*p && (isalnum((int) *p)
2043 /* copy variable to buffer */
2044 len = (p - s > 255) ? 255 : (p - s);
2045 strncpy(buf, s, len);
2054 /* if variable wasn't found from environment, use some special */
2060 if (strchr(buf, ' ')) {
2061 arg = strchr(buf, ' ');
2064 while (isspace((int) *arg))
2070 /* lowercase variable name */
2077 // create new object
2078 obj = construct_text_object(buf, arg);
2080 // allocate memory for the object
2081 retval->text_objects = realloc(retval->text_objects,
2082 sizeof(struct text_object) * (retval->text_object_count+1));
2083 // assign the new object to the end of the list.
2084 memcpy(&retval->text_objects[retval->text_object_count++],
2085 obj, sizeof(struct text_object));
2091 obj = create_plain_text("$");
2093 // allocate memory for the object
2094 retval->text_objects = realloc(retval->text_objects,
2095 sizeof(struct text_object) * (retval->text_object_count+1));
2096 // assign the new object to the end of the list.
2097 memcpy(&retval->text_objects[retval->text_object_count++],
2098 obj, sizeof(struct text_object));
2105 obj = create_plain_text(s);
2107 // allocate memory for the object
2108 retval->text_objects = realloc(retval->text_objects,
2109 sizeof(struct text_object) * (retval->text_object_count+1));
2110 // assign the new object to the end of the list.
2111 memcpy(&retval->text_objects[retval->text_object_count++],
2112 obj, sizeof(struct text_object));
2117 ERR("one or more $endif's are missing");
2123 static void extract_variable_text(const char *p)
2125 struct text_object_list *list;
2127 free_text_objects(text_object_count, text_objects);
2128 text_object_count = 0;
2129 text_objects = NULL;
2133 #endif /* MLDONKEY */
2135 list = extract_variable_text_internal(p);
2136 text_objects = list->text_objects;
2137 text_object_count = list->text_object_count;
2144 void parse_conky_vars(char * text, char * p, struct information *cur) {
2145 struct text_object_list *object_list = extract_variable_text_internal(text);
2146 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
2150 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
2154 for (i = 0; i < object_count; i++) {
2155 struct text_object *obj = &objs[i];
2157 #define OBJ(a) break; case OBJ_##a:
2159 switch (obj->type) {
2162 ERR("not implemented obj type %d",
2166 /* does anyone have decimals in acpi temperature? */
2168 snprintf(p, p_max_size, "%d", (int)
2169 get_acpi_temperature(obj->
2173 snprintf(p, 5, "%d ", (int)
2174 get_acpi_temperature(obj->
2179 /* does anyone have decimals in acpi temperature? */
2181 snprintf(p, p_max_size, "%d", (int)
2182 ((get_acpi_temperature(obj->
2184 i)+ 40) * 9.0 / 5 - 40));
2186 snprintf(p, 5, "%d ", (int)
2187 ((get_acpi_temperature(obj->
2189 i)+ 40) * 9.0 / 5 - 40));
2192 get_freq(p, p_max_size, "%.0f", 1); /* pk */
2195 get_freq(p, p_max_size, "%'.2f", 1000); /* pk */
2199 get_freq_dynamic(p, 6, "%.0f ", 1 ); /* pk */
2201 get_freq_dynamic(p, p_max_size, "%.0f", 1 ); /* pk */
2206 get_freq_dynamic(p, 6, "%'.2f ", 1000); /* pk */
2208 get_freq_dynamic(p, p_max_size, "%'.2f", 1000); /* pk */
2212 get_adt746x_cpu(p, p_max_size); /* pk */
2215 get_adt746x_fan(p, p_max_size); /* pk */
2218 get_acpi_fan(p, p_max_size); /* pk */
2220 OBJ(acpiacadapter) {
2221 get_acpi_ac_adapter(p, p_max_size); /* pk */
2224 get_battery_stuff(p, p_max_size, obj->data.s);
2227 human_readable(cur->buffers * 1024, p, 255);
2230 human_readable(cur->cached * 1024, p, 255);
2233 if (obj->data.cpu_index > info.cpu_count) {
2234 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
2235 CRIT_ERR("attempting to use more CPUs then you have!");
2238 snprintf(p, p_max_size, "%*d", pad_percents,
2239 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
2242 snprintf(p, 4, "%*d ",
2244 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
2250 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
2253 new_graph(p, obj->a,
2254 obj->b, obj->c, obj->d,
2255 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
2259 new_fg(p, obj->data.l);
2261 #if defined(__linux__)
2263 snprintf(p, p_max_size, "%s", i8k.version);
2266 snprintf(p, p_max_size, "%s", i8k.bios);
2269 snprintf(p, p_max_size, "%s", i8k.serial);
2272 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
2274 OBJ(i8k_cpu_tempf) {
2276 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
2277 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
2279 OBJ(i8k_left_fan_status) {
2280 int left_fan_status;
2281 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
2282 if(left_fan_status == 0) {
2283 snprintf(p, p_max_size,"off");
2284 } if(left_fan_status == 1) {
2285 snprintf(p, p_max_size, "low");
2286 } if(left_fan_status == 2) {
2287 snprintf(p, p_max_size, "high");
2291 OBJ(i8k_right_fan_status) {
2292 int right_fan_status;
2293 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
2294 if(right_fan_status == 0) {
2295 snprintf(p, p_max_size,"off");
2296 } if(right_fan_status == 1) {
2297 snprintf(p, p_max_size, "low");
2298 } if(right_fan_status == 2) {
2299 snprintf(p, p_max_size, "high");
2302 OBJ(i8k_left_fan_rpm) {
2303 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
2305 OBJ(i8k_right_fan_rpm) {
2306 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
2308 OBJ(i8k_ac_status) {
2310 sscanf(i8k.ac_status, "%d", &ac_status);
2311 if(ac_status == -1) {
2312 snprintf(p, p_max_size,"disabled (read i8k docs)");
2313 } if(ac_status == 0) {
2314 snprintf(p, p_max_size, "off");
2315 } if(ac_status == 1) {
2316 snprintf(p, p_max_size, "on");
2319 OBJ(i8k_buttons_status) {
2320 snprintf(p, p_max_size, "%s", i8k.buttons_status);
2323 #endif /* __linux__ */
2327 new_font(p, obj->data.s);
2332 if (diskio_value > 1024*1024) {
2333 snprintf(p, p_max_size, "%.1fG",
2334 (double)diskio_value/1024/1024);
2335 } else if (diskio_value > 1024) {
2336 snprintf(p, p_max_size, "%.1fM",
2337 (double)diskio_value/1024);
2338 } else if (diskio_value > 0) {
2339 snprintf(p, p_max_size, "%dK", diskio_value);
2341 snprintf(p, p_max_size, "%d", diskio_value);
2344 if (diskio_value > 1024*1024) {
2345 snprintf(p, 6, "%.1fG ",
2346 (double)diskio_value/1024/1024);
2347 } else if (diskio_value > 1024) {
2348 snprintf(p, 6, "%.1fM ",
2349 (double)diskio_value/1024);
2350 } else if (diskio_value > 0) {
2351 snprintf(p, 6, "%dK ", diskio_value);
2353 snprintf(p, 6, "%d ", diskio_value);
2358 new_graph(p, obj->a,
2359 obj->b, obj->c, obj->d,
2360 diskio_value, obj->e, 1);
2365 snprintf(p, p_max_size, "%d",
2366 (int) (obj->data.net->
2370 snprintf(p, 6, "%d ",
2371 (int) (obj->data.net->
2377 snprintf(p, p_max_size, "%.1f",
2379 recv_speed / 1024.0);
2381 snprintf(p, 8, "%.1f ",
2383 recv_speed / 1024.0);
2385 OBJ(downspeedgraph) {
2386 if (obj->data.net->recv_speed == 0) // this is just to make the ugliness at start go away
2387 obj->data.net->recv_speed = 0.01;
2388 new_graph(p, obj->a, obj->b, obj->c, obj->d,
2389 (obj->data.net->recv_speed /
2390 1024.0), obj->e, 1);
2396 i = obj->data.ifblock.pos - 2;
2406 snprintf(p, p_max_size, "%u.%u.%u.%u",
2407 obj->data.net->addr.
2409 obj->data.net->addr.
2411 obj->data.net->addr.
2413 obj->data.net->addr.
2418 snprintf(p, p_max_size, "%d",
2419 obj->data.net->linkstatus);
2423 FILE *fp = popen(obj->data.s, "r");
2424 int length = fread(p, 1, p_max_size, fp);
2427 /*output[length] = '\0';
2428 if (length > 0 && output[length - 1] == '\n') {
2429 output[length - 1] = '\0';
2432 if (length > 0 && p[length - 1] == '\n') {
2433 p[length - 1] = '\0';
2436 //parse_conky_vars(output, p, cur);
2440 FILE *fp = popen(obj->data.s, "r");
2441 int n2 = fread(p, 1, p_max_size, fp);
2445 if (n2 && p[n2 - 1] == '\n')
2454 if (sscanf(p, "%lf", &barnum) == 0) {
2455 ERR("reading execbar value failed (perhaps it's not the correct format?)");
2457 if (barnum > 100 || barnum < 0) {
2458 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
2460 barnum = barnum / 100.0;
2461 new_bar(p, 0, 4, (int) (barnum * 255.0));
2467 FILE *fp = popen(obj->data.s, "r");
2468 int n2 = fread(p, 1, p_max_size, fp);
2472 if (n2 && p[n2 - 1] == '\n')
2481 if (sscanf(p, "%lf", &barnum) == 0) {
2482 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
2484 if (barnum > 100 || barnum < 0) {
2485 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
2488 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
2493 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2494 new_bar(p, 0, 4, (int) obj->f);
2497 FILE *fp = popen(obj->data.execi.cmd, "r");
2498 int n2 = fread(p, 1, p_max_size, fp);
2501 if (n2 && p[n2 - 1] == '\n')
2510 if (sscanf(p, "%f", &barnum) == 0) {
2511 ERR("reading execibar value failed (perhaps it's not the correct format?)");
2513 if (barnum > 100 || barnum < 0) {
2514 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
2516 obj->f = 255 * barnum / 100.0;
2517 new_bar(p, 0, 4, (int) obj->f);
2519 obj->data.execi.last_update =
2520 current_update_time;
2524 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2525 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
2528 FILE *fp = popen(obj->data.execi.cmd, "r");
2529 int n2 = fread(p, 1, p_max_size, fp);
2532 if (n2 && p[n2 - 1] == '\n')
2541 if (sscanf(p, "%f", &barnum) == 0) {
2542 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
2544 if (barnum > 100 || barnum < 0) {
2545 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
2548 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
2550 obj->data.execi.last_update = current_update_time;
2556 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
2557 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
2559 char *output = obj->data.execi.buffer;
2560 FILE *fp = popen(obj->data.execi.cmd, "r");
2561 //int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
2562 int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
2565 output[length] = '\0';
2566 if (length > 0 && output[length - 1] == '\n') {
2567 output[length - 1] = '\0';
2569 obj->data.execi.last_update = current_update_time;
2570 snprintf(p, p_max_size, "%s", output);
2572 //parse_conky_vars(output, p, cur);
2575 static int running = 0;
2576 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2577 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
2579 static pthread_t execthread;
2581 pthread_join( execthread, NULL);
2586 pthread_create( &execthread, NULL, (void*)threaded_exec, (void*) obj);
2587 pthread_mutex_lock( &mutex1 );
2588 obj->data.execi.last_update = current_update_time;
2589 pthread_mutex_unlock( &mutex1 );
2591 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
2593 //parse_conky_vars(obj->data.execi.buffer, p, cur);
2597 if (obj->data.fs != NULL) {
2598 if (obj->data.fs->size == 0)
2617 if (obj->data.fs != NULL)
2618 human_readable(obj->data.fs->avail,
2622 if (obj->data.fs != NULL) {
2623 if (obj->data.fs->size)
2624 snprintf(p, p_max_size, "%*d",
2633 snprintf(p, p_max_size, "0");
2637 if (obj->data.fs != NULL)
2638 human_readable(obj->data.fs->size,
2642 if (obj->data.fs != NULL)
2643 human_readable(obj->data.fs->size -
2644 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
2648 if (obj->data.fs != NULL) {
2649 if (obj->data.fs->size == 0)
2667 if (obj->data.fs != NULL) {
2668 if (obj->data.fs->size)
2669 snprintf(p, 4, "%d",
2679 snprintf(p, p_max_size, "0");
2683 float *v = info.loadavg;
2685 if (obj->data.loadavg[2])
2686 snprintf(p, p_max_size, "%.2f %.2f %.2f",
2687 v[obj->data.loadavg[0] -
2689 v[obj->data.loadavg[1] -
2691 v[obj->data.loadavg[2] -
2693 else if (obj->data.loadavg[1])
2694 snprintf(p, p_max_size, "%.2f %.2f",
2695 v[obj->data.loadavg[0] -
2697 v[obj->data.loadavg[1] -
2699 else if (obj->data.loadavg[0])
2700 snprintf(p, p_max_size, "%.2f",
2701 v[obj->data.loadavg[0] -
2705 new_hr(p, obj->data.i);
2708 new_offset(p, obj->data.i);
2711 new_voffset(p, obj->data.i);
2716 r = get_i2c_info(&obj->data.i2c.fd,
2718 obj->data.i2c.devtype,
2719 obj->data.i2c.type);
2721 if (r >= 100.0 || r == 0)
2722 snprintf(p, p_max_size, "%d", (int) r);
2724 snprintf(p, p_max_size, "%.1f", r);
2727 new_alignr(p, obj->data.i);
2730 new_alignc(p, obj->data.i);
2734 if ((obj->data.ifblock.s)
2735 && (stat(obj->data.ifblock.s, &tmp) ==
2737 i = obj->data.ifblock.pos - 2;
2743 if ((obj->data.ifblock.s)
2744 && (!check_mount(obj->data.ifblock.s))) {
2745 i = obj->data.ifblock.pos - 2;
2751 if ((obj->data.ifblock.s)
2752 && system(obj->data.ifblock.s)) {
2753 i = obj->data.ifblock.pos - 2;
2759 snprintf(p, p_max_size, "%s", cur->uname_s.release);
2762 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
2767 human_readable(cur->mem * 1024, p, 6);
2770 human_readable(cur->memmax * 1024, p, 255);
2775 snprintf(p, p_max_size, "%*lu",
2780 snprintf(p, 4, "%*lu ",
2787 new_bar(p, obj->data.pair.a,
2789 cur->memmax ? (cur->mem * 255) /
2794 new_graph(p, obj->a,
2795 obj->b, obj->c, obj->d,
2796 cur->memmax ? (cur->mem * 100.0) /
2797 (cur->memmax) : 0.0, 100, 1);
2801 snprintf(p, p_max_size, "%d",
2802 mixer_get_avg(obj->data.l));
2805 snprintf(p, p_max_size, "%d",
2806 mixer_get_left(obj->data.l));
2809 snprintf(p, p_max_size, "%d",
2810 mixer_get_right(obj->data.l));
2813 new_bar(p, obj->data.mixerbar.w,
2814 obj->data.mixerbar.h,
2815 mixer_get_avg(obj->data.mixerbar.
2819 new_bar(p, obj->data.mixerbar.w,
2820 obj->data.mixerbar.h,
2821 mixer_get_left(obj->data.mixerbar.
2825 new_bar(p, obj->data.mixerbar.w,
2826 obj->data.mixerbar.h,
2827 mixer_get_right(obj->data.mixerbar.
2833 snprintf(p, p_max_size, "%d", cur->mail_count);
2836 snprintf(p, p_max_size, "%d", cur->new_mail_count);
2839 OBJ(ml_upload_counter) {
2840 snprintf(p, p_max_size, "%lld",
2841 mlinfo.upload_counter / 1048576);
2843 OBJ(ml_download_counter) {
2844 snprintf(p, p_max_size, "%lld",
2845 mlinfo.download_counter /
2848 OBJ(ml_nshared_files) {
2849 snprintf(p, p_max_size, "%i", mlinfo.nshared_files);
2851 OBJ(ml_shared_counter) {
2852 snprintf(p, p_max_size, "%lld",
2853 mlinfo.shared_counter / 1048576);
2855 OBJ(ml_tcp_upload_rate) {
2856 snprintf(p, p_max_size, "%.2f",
2857 (float) mlinfo.tcp_upload_rate /
2860 OBJ(ml_tcp_download_rate) {
2861 snprintf(p, p_max_size, "%.2f",
2862 (float) mlinfo.tcp_download_rate /
2865 OBJ(ml_udp_upload_rate) {
2866 snprintf(p, p_max_size, "%.2f",
2867 (float) mlinfo.udp_upload_rate /
2870 OBJ(ml_udp_download_rate) {
2871 snprintf(p, p_max_size, "%.2f",
2872 (float) mlinfo.udp_download_rate /
2875 OBJ(ml_ndownloaded_files) {
2876 snprintf(p, p_max_size, "%i",
2877 mlinfo.ndownloaded_files);
2879 OBJ(ml_ndownloading_files) {
2880 snprintf(p, p_max_size, "%i",
2881 mlinfo.ndownloading_files);
2886 snprintf(p, p_max_size, "%s",
2887 cur->uname_s.nodename);
2890 new_outline(p, obj->data.l);
2894 snprintf(p, p_max_size, "%hu", cur->procs);
2896 snprintf(p, 5, "%hu ",
2899 OBJ(running_processes) {
2901 snprintf(p, p_max_size, "%hu",
2904 snprintf(p, 3, "%hu ",
2908 snprintf(p, p_max_size, "%s", obj->data.s);
2911 new_bg(p, obj->data.l);
2914 new_stippled_hr(p, obj->data.pair.a,
2918 human_readable(cur->swap * 1024, p, 255);
2921 human_readable(cur->swapmax * 1024, p,
2925 if (cur->swapmax == 0) {
2926 strncpy(p, "No swap", 255);
2929 snprintf(p, 255, "%*lu",
2935 snprintf(p, 4, "%*lu ",
2943 new_bar(p, obj->data.pair.a,
2945 cur->swapmax ? (cur->swap * 255) /
2946 (cur->swapmax) : 0);
2949 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
2952 time_t t = time(NULL);
2953 struct tm *tm = localtime(&t);
2954 setlocale(LC_TIME, "");
2955 strftime(p, p_max_size, obj->data.s, tm);
2958 time_t t = time(NULL);
2959 struct tm *tm = gmtime(&t);
2960 strftime(p, p_max_size, obj->data.s, tm);
2963 human_readable(obj->data.net->recv, p,
2967 human_readable(obj->data.net->trans, p,
2971 snprintf(p, p_max_size, "%d", total_updates);
2975 snprintf(p, p_max_size, "%d",
2976 (int) (obj->data.net->
2980 snprintf(p, 5, "%d ",
2981 (int) (obj->data.net->
2987 snprintf(p, p_max_size, "%.1f",
2989 trans_speed / 1024.0);
2991 snprintf(p, 8, "%.1f ",
2993 trans_speed / 1024.0);
2996 if (obj->data.net->trans_speed == 0) // this is just to make the ugliness at start go away
2997 obj->data.net->trans_speed = 0.01;
2998 new_graph(p, obj->a, obj->b, obj->c, obj->d,
2999 (obj->data.net->trans_speed /
3000 1024.0), obj->e, 1);
3003 format_seconds_short(p, p_max_size,
3007 format_seconds(p, p_max_size, (int) cur->uptime);
3010 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
3012 snprintf(p, p_max_size, "%s", get_apm_adapter());
3014 OBJ(apm_battery_life) {
3016 msg = get_apm_battery_life();
3017 snprintf(p, p_max_size, "%s", msg);
3020 OBJ(apm_battery_time) {
3022 msg = get_apm_battery_time();
3023 snprintf(p, p_max_size, "%s", msg);
3026 #endif /* __FreeBSD__ */
3029 snprintf(p, p_max_size, "%.2f",
3030 cur->seti_prog * 100.0f);
3033 new_bar(p, obj->data.pair.a,
3035 (int) (cur->seti_prog * 255.0f));
3038 snprintf(p, p_max_size, "%.0f", cur->seti_credit);
3044 snprintf(p, p_max_size, "%s", cur->mpd.title);
3047 snprintf(p, p_max_size, "%s", cur->mpd.artist);
3050 snprintf(p, p_max_size, "%s", cur->mpd.album);
3053 snprintf(p, p_max_size, "%s", cur->mpd.random);
3056 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
3059 snprintf(p, p_max_size, "%s", cur->mpd.track);
3062 snprintf(p, p_max_size, "%i", cur->mpd.volume);
3065 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
3068 snprintf(p, p_max_size, "%s", cur->mpd.status);
3071 int days = 0, hours = 0, minutes =
3073 int tmp = cur->mpd.elapsed;
3074 while (tmp >= 86400) {
3078 while (tmp >= 3600) {
3088 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
3089 days, hours, minutes,
3092 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
3095 snprintf(p, p_max_size, "%i:%02i", minutes,
3099 int days = 0, hours = 0, minutes =
3101 int tmp = cur->mpd.length;
3102 while (tmp >= 86400) {
3106 while (tmp >= 3600) {
3116 snprintf(p, p_max_size,
3117 "%i days %i:%02i:%02i",
3118 days, hours, minutes,
3121 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
3124 snprintf(p, p_max_size, "%i:%02i", minutes,
3128 snprintf(p, p_max_size, "%2.0f",
3129 cur->mpd.progress * 100);
3132 new_bar(p, obj->data.pair.a,
3134 (int) (cur->mpd.progress *
3139 OBJ(audacious_status) {
3140 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
3142 OBJ(audacious_song) {
3143 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG]);
3145 OBJ(audacious_song_length) {
3146 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_LENGTH]);
3148 OBJ(audacious_song_length_seconds) {
3149 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_LENGTH_SECONDS]);
3151 OBJ(audacious_song_length_frames) {
3152 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_LENGTH_FRAMES]);
3154 OBJ(audacious_song_output_length) {
3155 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH]);
3157 OBJ(audacious_song_output_length_seconds) {
3158 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH_SECONDS]);
3160 OBJ(audacious_song_output_length_frames) {
3161 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH_FRAMES]);
3163 OBJ(audacious_song_bitrate) {
3164 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_BITRATE]);
3166 OBJ(audacious_song_frequency) {
3167 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_FREQUENCY]);
3169 OBJ(audacious_song_channels) {
3170 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
3172 OBJ(audacious_bar) {
3174 progress= atof(cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH_SECONDS]) /
3175 atof(cur->audacious.items[AUDACIOUS_SONG_LENGTH_SECONDS]);
3176 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
3182 snprintf(p, p_max_size, "%s", cur->bmpx.title);
3185 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
3188 snprintf(p, p_max_size, "%s", cur->bmpx.album);
3191 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
3194 snprintf(p, p_max_size, "%i", cur->bmpx.track);
3197 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
3201 OBJ(infopipe_protocol) {
3202 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_PROTOCOL]);
3204 OBJ(infopipe_version) {
3205 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_VERSION]);
3207 OBJ(infopipe_status) {
3208 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_STATUS]);
3210 OBJ(infopipe_playlist_tunes) {
3211 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_PLAYLIST_TUNES]);
3213 OBJ(infopipe_playlist_currtune) {
3214 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_PLAYLIST_CURRTUNE]);
3216 OBJ(infopipe_usec_position) {
3217 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_USEC_POSITION]);
3219 OBJ(infopipe_position) {
3220 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_POSITION]);
3222 OBJ(infopipe_usec_time) {
3223 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_USEC_TIME]);
3225 OBJ(infopipe_time) {
3226 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_TIME]);
3228 OBJ(infopipe_bitrate) {
3229 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_BITRATE]);
3231 OBJ(infopipe_frequency) {
3232 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_FREQUENCY]);
3234 OBJ(infopipe_channels) {
3235 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_CHANNELS]);
3237 OBJ(infopipe_title) {
3238 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_TITLE]);
3240 OBJ(infopipe_file) {
3241 snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_FILE]);
3245 progress= atof(cur->infopipe.items[INFOPIPE_USEC_POSITION]) /
3246 atof(cur->infopipe.items[INFOPIPE_USEC_TIME]);
3247 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
3251 if (obj->data.top.type == TOP_NAME
3252 && obj->data.top.num >= 0
3253 && obj->data.top.num < 10) {
3254 // if we limit the buffer and add a bunch of space after, it stops the thing from
3255 // moving other shit around, which is really fucking annoying
3256 snprintf(p, 17, "%s ", cur->cpu[obj->data.top.num]->name);
3257 } else if (obj->data.top.type == TOP_CPU
3258 && obj->data.top.num >= 0
3259 && obj->data.top.num < 10) {
3260 snprintf(p, 7, "%3.2f ",
3261 cur->cpu[obj->data.top.
3263 } else if (obj->data.top.type == TOP_PID
3264 && obj->data.top.num >= 0
3265 && obj->data.top.num < 10) {
3266 snprintf(p, 8, "%i ",
3267 cur->cpu[obj->data.top.
3269 } else if (obj->data.top.type == TOP_MEM
3270 && obj->data.top.num >= 0
3271 && obj->data.top.num < 10) {
3272 snprintf(p, 7, "%3.2f ",
3273 cur->cpu[obj->data.top.
3278 if (obj->data.top.type == TOP_NAME
3279 && obj->data.top.num >= 0
3280 && obj->data.top.num < 10) {
3281 // if we limit the buffer and add a bunch of space after, it stops the thing from
3282 // moving other shit around, which is really fucking annoying
3285 cur->memu[obj->data.top.
3287 } else if (obj->data.top.type == TOP_CPU
3288 && obj->data.top.num >= 0
3289 && obj->data.top.num < 10) {
3290 snprintf(p, 7, "%3.2f ",
3291 cur->memu[obj->data.top.
3293 } else if (obj->data.top.type == TOP_PID
3294 && obj->data.top.num >= 0
3295 && obj->data.top.num < 10) {
3296 snprintf(p, 8, "%i ",
3297 cur->memu[obj->data.top.
3299 } else if (obj->data.top.type == TOP_MEM
3300 && obj->data.top.num >= 0
3301 && obj->data.top.num < 10) {
3302 snprintf(p, 7, "%3.2f ",
3303 cur->memu[obj->data.top.
3310 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
3311 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
3313 obj->data.tail.last_update = current_update_time;
3317 tailstring *head = NULL;
3318 tailstring *headtmp = NULL;
3319 tailstring *freetmp = NULL;
3320 fp = fopen(obj->data.tail.logfile, "rt");
3322 ERR("tail logfile failed to open");
3325 obj->data.tail.readlines = 0;
3327 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL) {
3334 addtail(&head, obj->data.tail.buffer);
3335 obj->data.tail.readlines++;
3341 if (obj->data.tail.readlines > 0) {
3342 for (i = 0;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
3343 addtail(&headtmp, head->data);
3348 strcpy(obj->data.tail.buffer, headtmp->data);
3349 headtmp = headtmp->next;
3350 for (i = 1;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
3352 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 */
3353 headtmp = headtmp->next;
3357 /* get rid of any ugly newlines at the end */
3358 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
3359 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
3361 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
3365 strcpy(obj->data.tail.buffer, "Logfile Empty");
3366 snprintf(p, p_max_size, "Logfile Empty");
3367 } /* if readlines */
3369 } /* if cur_upd_time >= */
3371 //parse_conky_vars(obj->data.tail.buffer, p, cur);
3375 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
3376 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
3378 obj->data.tail.last_update = current_update_time;
3380 tailstring *head = NULL;
3381 tailstring *headtmp = NULL;
3382 tailstring *freetmp = NULL;
3383 fp = fopen(obj->data.tail.logfile, "rt");
3385 ERR("head logfile failed to open");
3387 obj->data.tail.readlines = 0;
3388 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL && obj->data.tail.readlines <= obj->data.tail.wantedlines) {
3389 addtail(&head, obj->data.tail.buffer);
3390 obj->data.tail.readlines++;
3394 if (obj->data.tail.readlines > 0) {
3396 addtail(&headtmp, head->data);
3401 strcpy(obj->data.tail.buffer, headtmp->data);
3402 headtmp = headtmp->next;
3404 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 */
3405 headtmp = headtmp->next;
3408 /* get rid of any ugly newlines at the end */
3409 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
3410 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
3412 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
3414 strcpy(obj->data.tail.buffer, "Logfile Empty");
3415 snprintf(p, p_max_size, "Logfile Empty");
3416 } /* if readlines > 0 */
3417 } /* if fp == null */
3418 } /* cur_upd_time >= */
3420 //parse_conky_vars(obj->data.tail.buffer, p, cur);
3423 #ifdef TCP_PORT_MONITOR
3426 /* grab a pointer to this port monitor */
3427 tcp_port_monitor_t * p_monitor =
3428 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
3429 obj->data.tcp_port_monitor.port_range_begin,
3430 obj->data.tcp_port_monitor.port_range_end );
3432 snprintf(p, p_max_size, "monitor not found");
3436 /* now grab the text of interest */
3437 if ( peek_tcp_port_monitor( p_monitor,
3438 obj->data.tcp_port_monitor.item,
3439 obj->data.tcp_port_monitor.connection_index,
3440 p, p_max_size ) != 0 )
3442 snprintf(p, p_max_size, "monitor peek error");
3452 unsigned int a = strlen(p);
3460 double current_update_time, last_update_time;
3462 static void generate_text()
3464 struct information *cur = &info;
3471 current_update_time = get_time();
3475 /* add things to the buffer */
3481 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
3483 if (stuff_in_upper_case) {
3493 last_update_time = current_update_time;
3500 static void set_font()
3504 if (window.xftdraw != NULL) {
3505 XftDrawDestroy(window.xftdraw);
3507 window.xftdraw = XftDrawCreate(display, window.drawable,
3508 DefaultVisual(display,
3510 DefaultColormap(display,
3515 XSetFont(display, window.gc, fonts[selected_font].font->fid);
3524 static int text_start_x, text_start_y; /* text start position in window */
3525 static int text_width, text_height;
3529 static inline int get_string_width(const char *s)
3532 return *s ? calc_text_width(s, strlen(s)) : 0;
3538 static inline int get_string_width_special(char *s)
3551 if (*p == SPECIAL_CHAR) {
3552 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
3553 for (i = 0; i < strlen(p); i++) {
3554 *(p + i) = *(p + i + 1);
3556 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
3557 width += specials[special_index+index].width;
3564 if (strlen(final) > 1) {
3565 width += calc_text_width(final, strlen(final));
3577 static void text_size_updater(char *s)
3581 int h = font_height();
3582 /* get string widths and skip specials */
3585 if (*p == SPECIAL_CHAR) {
3587 w += get_string_width(s);
3590 if (specials[special_index].type == BAR
3591 || specials[special_index].type == GRAPH) {
3592 w += specials[special_index].width;
3593 if (specials[special_index].height > h) {
3594 h = specials[special_index].height;
3599 else if (specials[special_index].type == OFFSET) {
3600 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
3602 else if (specials[special_index].type == VOFFSET) {
3603 h += specials[special_index].arg;
3605 else if (specials[special_index].type == FONT) {
3606 fontchange = specials[special_index].font_added;
3607 selected_font = specials[special_index].font_added;
3617 w += get_string_width(s);
3620 if (text_width > maximum_width && maximum_width)
3621 text_width = maximum_width;
3632 static void update_text_area()
3636 /* update text size if it isn't fixed */
3641 text_width = minimum_width;
3644 for_each_line(text_buffer, text_size_updater);
3646 if (text_height < minimum_height)
3647 text_height = minimum_height;
3648 if (text_width > maximum_width && maximum_width > 0)
3649 text_width = maximum_width;
3652 /* get text position on workarea */
3653 switch (text_alignment) {
3660 x = workarea[2] - text_width - gap_x;
3667 y = workarea[3] - text_height - gap_y;
3671 x = workarea[2] - text_width - gap_x;
3672 y = workarea[3] - text_height - gap_y;
3676 case NONE: // Let the WM manage the window
3687 if (own_window && !fixed_pos) {
3690 text_start_x = border_margin + 1;
3691 text_start_y = border_margin + 1;
3692 window.x = x - border_margin - 1;
3693 window.y = y - border_margin - 1;
3697 /* If window size doesn't match to workarea's size, then window
3698 * probably includes panels (gnome).
3699 * Blah, doesn't work on KDE. */
3700 if (workarea[2] != window.width
3701 || workarea[3] != window.height) {
3715 static int cur_x, cur_y; /* current x and y for drawing */
3716 static int draw_mode; /* FG, BG or OUTLINE */
3717 static long current_color;
3719 static inline void set_foreground_color(long c)
3722 XSetForeground(display, window.gc, c);
3726 static void draw_string(const char *s)
3730 int i, i2, pos, width_of_s;
3733 width_of_s = get_string_width(s);
3734 if (out_to_console) {
3736 fflush(stdout); /* output immediately, don't buffer */
3738 /* 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 */
3739 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
3740 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
3741 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
3745 snprintf(space, 2, " ");
3747 max = ((text_width - width_of_s) / get_string_width(space));
3750 * This code looks for tabs in the text and coverts them to spaces.
3751 * The trick is getting the correct number of spaces,
3752 * and not going over the window's size without forcing
3753 * the window larger.
3755 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
3756 if (tmpstring1[i] == '\t') // 9 is ascii tab
3760 i2 < (8 - (1 + pos) % 8) && added <= max;
3763 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
3764 fprintf(stderr,"buffer overrun detected\n");
3766 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
3771 if (tmpstring1[i] != 9) {
3773 if ( pos > TEXT_BUFFER_SIZE-1 )
3774 fprintf(stderr,"buffer overrun detected\n");
3776 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
3782 if (text_width == maximum_width) {
3783 /* this means the text is probably pushing the limit, so we'll chop it */
3784 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
3785 tmpstring2[strlen(tmpstring2)-1] = '\0';
3795 c.pixel = current_color;
3796 XQueryColor(display, DefaultColormap(display, screen), &c);
3799 c2.color.red = c.red;
3800 c2.color.green = c.green;
3801 c2.color.blue = c.blue;
3802 c2.color.alpha = fonts[selected_font].font_alpha;
3804 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
3805 cur_x, cur_y, (XftChar8 *) s,
3808 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
3809 cur_x, cur_y, (XftChar8 *) s,
3815 XDrawString(display, window.drawable, window.gc,
3816 cur_x, cur_y, s, strlen(s));
3818 cur_x += width_of_s;
3820 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
3823 long redmask, greenmask, bluemask;
3825 void set_up_gradient()
3828 colour_depth = DisplayPlanes(display, screen);
3832 if (colour_depth != 24 && colour_depth != 16) {
3833 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
3839 for(i = (colour_depth / 3)-1; i>=0; i--) {
3841 greenmask |= 1 << i;
3844 if (colour_depth%3 == 1) {
3845 greenmask |= 1 << (colour_depth / 3);
3847 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
3848 greenmask = greenmask << (colour_depth / 3);
3851 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 */
3853 int red1, green1, blue1; // first colour
3854 int red2, green2, blue2; // second colour
3855 int red3 = 0, green3 = 0, blue3 = 0; // difference
3856 short redshift = (2*colour_depth / 3 + colour_depth%3);
3857 short greenshift = (colour_depth / 3);
3858 red1 = (first_colour & redmask) >> redshift;
3859 green1 = (first_colour & greenmask) >> greenshift;
3860 blue1 = first_colour & bluemask;
3861 red2 = (last_colour & redmask) >> redshift;
3862 green2 = (last_colour & greenmask) >> greenshift;
3863 blue2 = last_colour & bluemask;
3870 if (green1 > green2) {
3873 if (green1 < green2) {
3876 if (blue1 > blue2) {
3879 if (blue1 < blue2) {
3894 if (red1 > bluemask) {
3897 if (green1 > bluemask) {
3900 if (blue1 > bluemask) {
3903 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
3907 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
3908 if (colour_depth == 0) {
3911 int red1, green1, blue1; // first colour
3912 int red2, green2, blue2; // second colour
3913 long redshift = (2*colour_depth / 3 + colour_depth%3);
3914 long greenshift = (colour_depth / 3);
3915 int red3 = 0, green3 = 0, blue3 = 0; // difference
3916 red1 = (first_colour & redmask) >> redshift;
3917 green1 = (first_colour & greenmask) >> greenshift;
3918 blue1 = first_colour & bluemask;
3919 red2 = (last_colour & redmask) >> redshift;
3920 green2 = (last_colour & greenmask) >> greenshift;
3921 blue2 = last_colour & bluemask;
3922 red3 = abs(red1 - red2);
3923 green3 = abs(green1 - green2);
3924 blue3 = abs(blue1 - blue2);
3933 static void draw_line(char *s)
3937 cur_x = text_start_x;
3938 cur_y += font_ascent();
3940 short font_h = font_height();
3942 /* find specials and draw stuff */
3945 if (*p == SPECIAL_CHAR) {
3948 /* draw string before special */
3955 switch (specials[special_index].type) {
3956 case HORIZONTAL_LINE:
3959 specials[special_index].height;
3960 int mid = font_ascent() / 2;
3961 w = text_start_x + text_width -
3964 XSetLineAttributes(display,
3969 XDrawLine(display, window.drawable,
3980 specials[special_index].height;
3982 specials[special_index].arg;
3983 int mid = font_ascent() / 2;
3984 char ss[2] = { s, s };
3985 w = text_start_x + text_width -
3988 XSetLineAttributes(display,
3993 XSetDashes(display, window.gc, 0,
3995 XDrawLine(display, window.drawable,
4005 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
4009 specials[special_index].height;
4011 specials[special_index].arg;
4016 by = cur_y - (font_ascent() + h) / 2 - 1;
4020 by = cur_y - (font_ascent()/2) - 1;
4022 if (h < (font_height())) {
4025 w = specials[special_index].width;
4028 text_width - cur_x - 1;
4032 XSetLineAttributes(display,
4038 XDrawRectangle(display,
4042 XFillRectangle(display,
4046 w * bar_usage / 255,
4048 if (specials[special_index].
4050 && specials[special_index].
4054 [special_index].height;
4061 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
4065 specials[special_index].height;
4069 by = cur_y - (font_ascent() + h) / 2 - 1;
4073 by = cur_y - (font_ascent()/2) - 1;
4075 if (h < (font_height())) {
4078 w = specials[special_index].width;
4080 w = text_start_x + text_width - cur_x - 1;
4083 if (draw_graph_borders) {
4084 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
4085 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
4087 XSetLineAttributes(display,
4094 int gradient_size = 0;
4095 float gradient_factor = 0;
4096 float gradient_update = 0;
4097 unsigned long tmpcolour = current_color;
4098 if (specials[special_index].first_colour != specials[special_index].last_colour) {
4099 tmpcolour = specials[special_index].first_colour;
4100 gradient_size = gradient_max(specials[special_index].first_colour, specials[special_index].last_colour);
4101 gradient_factor = (float)gradient_size / (w - 3);
4103 for (i = 0; i < w - 3; i++) {
4104 if (specials[special_index].first_colour != specials[special_index].last_colour) {
4105 XSetForeground(display, window.gc, tmpcolour);
4106 gradient_update += gradient_factor;
4107 while (gradient_update > 0) {
4108 tmpcolour = do_gradient(tmpcolour, specials[special_index].last_colour);
4112 if (i / ((float) (w - 3) / (specials[special_index].graph_width)) > j) {
4115 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 */
4117 if (specials[special_index].
4119 && specials[special_index].
4123 [special_index].height;
4126 if (draw_mode == BG) {
4127 set_foreground_color(default_bg_color);
4129 else if (draw_mode == OUTLINE) {
4130 set_foreground_color(default_out_color);
4132 set_foreground_color(default_fg_color);
4138 cur_y -= font_ascent();
4139 selected_font = specials[special_index].font_added;
4140 cur_y += font_ascent();
4142 if (!use_xft || use_xdbe)
4150 if (draw_mode == FG)
4151 set_foreground_color(specials
4157 if (draw_mode == BG)
4158 set_foreground_color(specials
4164 if (draw_mode == OUTLINE)
4165 set_foreground_color(specials
4172 w += specials[special_index].arg;
4177 cur_y += specials[special_index].arg;
4183 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
4184 /*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);*/
4185 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
4186 cur_x = pos_x - specials[special_index].arg;
4193 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
4194 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
4195 /*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);*/
4197 specials[special_index].arg)
4200 [special_index].arg;
4217 if (cur_y_add > 0) {
4219 cur_y -= font_descent();
4224 cur_y += font_descent();
4231 static void draw_text()
4234 cur_y = text_start_y;
4237 if (draw_borders && border_width > 0) {
4238 unsigned int b = (border_width + 1) / 2;
4240 if (stippled_borders) {
4242 { stippled_borders, stippled_borders };
4243 XSetLineAttributes(display, window.gc,
4244 border_width, LineOnOffDash,
4245 CapButt, JoinMiter);
4246 XSetDashes(display, window.gc, 0, ss, 2);
4248 XSetLineAttributes(display, window.gc,
4249 border_width, LineSolid,
4250 CapButt, JoinMiter);
4253 XDrawRectangle(display, window.drawable, window.gc,
4254 text_start_x - border_margin + b,
4255 text_start_y - border_margin + b,
4256 text_width + border_margin * 2 - 1 - b * 2,
4257 text_height + border_margin * 2 - 1 -
4264 for_each_line(text_buffer, draw_line);
4267 static void draw_stuff()
4270 if (draw_shades && !draw_outline) {
4273 set_foreground_color(default_bg_color);
4282 for (i = -1; i < 2; i++)
4283 for (j = -1; j < 2; j++) {
4284 if (i == 0 && j == 0)
4288 set_foreground_color(default_out_color);
4289 draw_mode = OUTLINE;
4296 set_foreground_color(default_fg_color);
4304 swap.swap_window = window.window;
4305 swap.swap_action = XdbeBackground;
4306 XdbeSwapBuffers(display, &swap, 1);
4312 static void clear_text(int exposures)
4316 return; /* The swap action is XdbeBackground, which clears */
4320 /* there is some extra space for borders and outlines */
4321 XClearArea(display, window.drawable,
4322 text_start_x - border_margin - 1,
4323 text_start_y - border_margin - 1,
4324 text_width + border_margin * 2 + 2,
4325 text_height + border_margin * 2 + 2,
4326 exposures ? True : 0);
4331 static int need_to_update;
4333 /* update_text() generates new text and clears old text area */
4334 static void update_text()
4343 static void main_loop()
4345 #ifdef SIGNAL_BLOCKING
4346 sigset_t newmask, oldmask;
4348 sigemptyset(&newmask);
4349 sigaddset(&newmask,SIGINT);
4350 sigaddset(&newmask,SIGTERM);
4351 sigaddset(&newmask,SIGUSR1);
4355 Region region = XCreateRegion();
4359 while (total_run_times == 0 || info.looped < total_run_times - 1) {
4362 #ifdef SIGNAL_BLOCKING
4363 /* block signals. we will inspect for pending signals later */
4364 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
4365 CRIT_ERR("unable to sigprocmask()");
4371 /* wait for X event or timeout */
4373 if (!XPending(display)) {
4378 update_interval - (get_time() -
4384 tv.tv_sec = (long) t;
4385 tv.tv_usec = (long) (t * 1000000) % 1000000;
4387 FD_SET(ConnectionNumber(display), &fdsr);
4390 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
4393 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
4398 ERR("can't select(): %s",
4409 set_transparent_background(window.window);
4414 if (need_to_update) {
4416 int wx = window.x, wy = window.y;
4424 /* resize window if it isn't right size */
4426 (text_width + border_margin * 2 !=
4428 || text_height + border_margin * 2 !=
4432 border_margin * 2 + 1;
4435 border_margin * 2 + 1;
4436 XResizeWindow(display,
4442 /* move window if it isn't in right position */
4445 || window.y != wy)) {
4446 XMoveWindow(display, window.window,
4447 window.x, window.y);
4457 r.x = text_start_x - border_margin;
4458 r.y = text_start_y - border_margin;
4459 r.width = text_width + border_margin * 2;
4460 r.height = text_height + border_margin * 2;
4461 XUnionRectWithRegion(&r, region, region);
4466 /* handle X events */
4468 while (XPending(display)) {
4470 XNextEvent(display, &ev);
4477 r.width = ev.xexpose.width;
4478 r.height = ev.xexpose.height;
4479 XUnionRectWithRegion(&r, region,
4485 case ReparentNotify:
4486 /* set background to ParentRelative for all parents */
4488 set_transparent_background(window.
4493 case ConfigureNotify:
4495 /* if window size isn't what expected, set fixed size */
4496 if (ev.xconfigure.width !=
4498 || ev.xconfigure.height !=
4500 if (window.width != 0
4501 && window.height != 0)
4504 /* clear old stuff before screwing up size and pos */
4510 if (XGetWindowAttributes(display, window.window, &attrs)) {
4525 border_margin * 2 - 1;
4528 border_margin * 2 - 1;
4529 if (text_width > maximum_width && maximum_width > 0)
4530 text_width = maximum_width;
4533 /* if position isn't what expected, set fixed pos, total_updates
4534 * avoids setting fixed_pos when window is set to weird locations
4536 /*if (total_updates >= 2 this is broken
4538 && (window.x != ev.xconfigure.x
4541 && (ev.xconfigure.x != 0
4542 || ev.xconfigure.y != 0)) {
4555 /* XDBE doesn't seem to provide a way to clear the back buffer without
4556 * interfering with the front buffer, other than passing XdbeBackground
4557 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
4558 * redraw the text even if it wasn't part of the exposed area. OTOH,
4559 * if we're not going to call draw_stuff at all, then no swap happens
4560 * and we can safely do nothing.
4563 if (!XEmptyRegion(region)) {
4567 r.x = text_start_x - border_margin;
4568 r.y = text_start_y - border_margin;
4569 r.width = text_width + border_margin * 2;
4570 r.height = text_height + border_margin * 2;
4571 XUnionRectWithRegion(&r, region, region);
4574 XSetRegion(display, window.gc, region);
4577 XftDrawSetClip(window.xftdraw, region);
4583 XDestroyRegion(region);
4584 region = XCreateRegion();
4588 #ifdef SIGNAL_BLOCKING
4589 /* unblock signals of interest and let handler fly */
4590 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
4591 CRIT_ERR("unable to sigprocmask()");
4594 switch(g_signal_pending) {
4597 ERR("received SIGUSR1. reloading the config file.");
4604 ERR("received SIGINT or SIGTERM to terminate. bye!");
4607 XDestroyRegion(region);
4610 return; /* return from main_loop */
4615 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
4616 * but didn't write any code to deal with it. if you don't want to
4617 * handle a signal, don't set a handler on it in the first place. */
4618 if (g_signal_pending)
4619 ERR("ignoring signal (%d)", g_signal_pending);
4627 XDestroyRegion(region);
4632 static void load_config_file(const char *);
4634 /* reload the config file */
4635 void reload_config(void)
4637 if (current_config) {
4639 load_config_file(current_config);
4643 XClearWindow(display, RootWindow(display, screen)); // clear the window first
4646 #ifdef TCP_PORT_MONITOR
4647 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
4648 info.p_tcp_port_monitor_collection = NULL;
4650 extract_variable_text(text);
4662 XdbeDeallocateBackBufferName(display, window.back_buffer);
4667 XDestroyWindow(display, window.window);
4671 XClearWindow(display, RootWindow(display, screen));
4676 XFreeGC(display, window.gc);
4680 /* it is really pointless to free() memory at the end of program but ak|ra
4681 * wants me to do this */
4683 free_text_objects(text_object_count, text_objects);
4684 text_object_count = 0;
4685 text_objects = NULL;
4689 #endif /* MLDONKEY */
4691 if (text != original_text)
4694 free(current_config);
4695 free(current_mail_spool);
4699 #ifdef TCP_PORT_MONITOR
4700 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
4701 info.p_tcp_port_monitor_collection = NULL;
4705 static int string_to_bool(const char *s)
4709 if (strcasecmp(s, "yes") == 0)
4711 if (strcasecmp(s, "true") == 0)
4713 if (strcasecmp(s, "1") == 0)
4718 static enum alignment string_to_alignment(const char *s)
4720 if (strcasecmp(s, "top_left") == 0)
4722 else if (strcasecmp(s, "top_right") == 0)
4724 else if (strcasecmp(s, "bottom_left") == 0)
4726 else if (strcasecmp(s, "bottom_right") == 0)
4727 return BOTTOM_RIGHT;
4728 else if (strcasecmp(s, "tl") == 0)
4730 else if (strcasecmp(s, "tr") == 0)
4732 else if (strcasecmp(s, "bl") == 0)
4734 else if (strcasecmp(s, "br") == 0)
4735 return BOTTOM_RIGHT;
4736 else if (strcasecmp(s, "none") == 0)
4743 static void set_default_configurations(void)
4745 fork_to_background = 0;
4746 total_run_times = 0;
4747 info.cpu_avg_samples = 2;
4748 info.net_avg_samples = 2;
4753 strcpy(info.mpd.host, "localhost");
4754 info.mpd.port = 6600;
4755 info.mpd.status = "Checking status...";
4764 default_fg_color = WhitePixel(display, screen);
4765 default_bg_color = BlackPixel(display, screen);
4766 default_out_color = BlackPixel(display, screen);
4769 draw_graph_borders = 1;
4771 set_first_font("6x10");
4779 strcpy(wm_class_name, "conky");
4781 stippled_borders = 0;
4784 text_alignment = BOTTOM_LEFT;
4788 free(current_mail_spool);
4791 variable_substitute(MAIL_FILE, buf, 256);
4793 current_mail_spool = strdup(buf);
4797 update_interval = 10.0;
4798 stuff_in_upper_case = 0;
4800 mlconfig.mldonkey_hostname = strdup("127.0.0.1");
4801 mlconfig.mldonkey_port = 4001;
4802 mlconfig.mldonkey_login = NULL;
4803 mlconfig.mldonkey_password = NULL;
4806 #ifdef TCP_PORT_MONITOR
4807 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
4808 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
4812 static void load_config_file(const char *f)
4814 #define CONF_ERR ERR("%s: %d: config file error", f, line)
4818 set_default_configurations();
4824 char buf[256], *p, *p2, *name, *value;
4826 if (fgets(buf, 256, fp) == NULL)
4831 /* break at comment */
4832 p2 = strchr(p, '#');
4837 while (*p && isspace((int) *p))
4840 continue; /* empty line */
4846 while (*p2 && !isspace((int) *p2))
4849 *p2 = '\0'; /* break at name's end */
4856 while (*p && isspace((int) *p))
4861 p2 = value + strlen(value);
4862 while (isspace((int) *(p2 - 1)))
4868 #define CONF2(a) if (strcasecmp(name, a) == 0)
4869 #define CONF(a) else CONF2(a)
4870 #define CONF3(a,b) \
4871 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
4875 CONF2("alignment") {
4877 int a = string_to_alignment(value);
4887 on_bottom = string_to_bool(value);
4891 CONF("background") {
4892 fork_to_background = string_to_bool(value);
4896 CONF2("background") {
4897 fork_to_background = string_to_bool(value);
4901 CONF("border_margin") {
4903 border_margin = strtol(value, 0, 0);
4907 CONF("border_width") {
4909 border_width = strtol(value, 0, 0);
4913 CONF("default_color") {
4915 default_fg_color = get_x11_color(value);
4919 CONF3("default_shade_color", "default_shadecolor") {
4921 default_bg_color = get_x11_color(value);
4925 CONF3("default_outline_color", "default_outlinecolor") {
4927 default_out_color = get_x11_color(value);
4935 strcpy(info.mpd.host, value);
4941 info.mpd.port = strtol(value, 0, 0);
4942 if (info.mpd.port < 1
4943 || info.mpd.port > 0xffff)
4948 CONF("cpu_avg_samples") {
4950 cpu_avg_samples = strtol(value, 0, 0);
4951 if (cpu_avg_samples < 1
4952 || cpu_avg_samples > 14)
4961 CONF("net_avg_samples") {
4963 net_avg_samples = strtol(value, 0, 0);
4964 if (net_avg_samples < 1
4965 || net_avg_samples > 14)
4981 CONF("double_buffer") {
4982 use_xdbe = string_to_bool(value);
4986 CONF("override_utf8_locale") {
4987 utf8_mode = string_to_bool(value);
4990 CONF("draw_borders") {
4991 draw_borders = string_to_bool(value);
4993 CONF("draw_graph_borders") {
4994 draw_graph_borders = string_to_bool(value);
4996 CONF("draw_shades") {
4997 draw_shades = string_to_bool(value);
4999 CONF("draw_outline") {
5000 draw_outline = string_to_bool(value);
5003 CONF("out_to_console") {
5004 out_to_console = string_to_bool(value);
5006 CONF("use_spacer") {
5007 use_spacer = string_to_bool(value);
5012 use_xft = string_to_bool(value);
5016 set_first_font(value);
5021 if (value && font_count >= 0)
5022 fonts[0].font_alpha = atof(value)
5030 if (string_to_bool(value))
5031 ERR("Xft not enabled");
5034 /* xftfont silently ignored when no Xft */
5037 /* xftalpha is silently ignored when no Xft */
5043 set_first_font(value);
5050 gap_x = atoi(value);
5056 gap_y = atoi(value);
5061 CONF("mail_spool") {
5064 variable_substitute(value, buf, 256);
5068 if (current_mail_spool)
5069 free(current_mail_spool);
5070 current_mail_spool = strdup(buf);
5076 CONF("minimum_size") {
5079 (value, "%d %d", &minimum_width,
5080 &minimum_height) != 2)
5083 &minimum_width) != 1)
5088 CONF("maximum_width") {
5090 if (sscanf(value, "%d", &maximum_width) != 1)
5096 CONF("no_buffers") {
5097 no_buffers = string_to_bool(value);
5100 CONF("mldonkey_hostname") {
5102 if (mlconfig.mldonkey_hostname != NULL) {
5103 free(mlconfig.mldonkey_hostname);
5105 mlconfig.mldonkey_hostname = strdup(value);
5110 CONF("mldonkey_port") {
5112 mlconfig.mldonkey_port = atoi(value);
5116 CONF("mldonkey_login") {
5118 if (mlconfig.mldonkey_login != NULL) {
5119 free(mlconfig.mldonkey_login);
5121 mlconfig.mldonkey_login = strdup(value);
5126 CONF("mldonkey_password") {
5128 if (mlconfig.mldonkey_password != NULL) {
5129 free(mlconfig.mldonkey_password);
5131 mlconfig.mldonkey_password = strdup(value);
5137 CONF("pad_percents") {
5138 pad_percents = atoi(value);
5142 CONF("own_window") {
5143 own_window = string_to_bool(value);
5145 CONF("wm_class_name") {
5146 strncpy(wm_class_name, value, sizeof(wm_class_name)-1);
5147 wm_class_name[sizeof(wm_class_name)-1] = 0;
5149 CONF("own_window_transparent") {
5150 set_transparent = string_to_bool(value);
5152 CONF("own_window_colour") {
5153 background_colour = get_x11_color(value);
5156 CONF("stippled_borders") {
5158 stippled_borders = strtol(value, 0, 0);
5160 stippled_borders = 4;
5164 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
5167 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
5169 CONF("update_interval") {
5171 update_interval = strtod(value, 0);
5175 CONF("total_run_times") {
5177 total_run_times = strtod(value, 0);
5182 stuff_in_upper_case = string_to_bool(value);
5187 malloc(strlen(value)
5189 strcpy(seti_dir, value);
5193 if (text != original_text)
5203 int l = strlen(text);
5204 if (fgets(buf, 256, fp) == NULL)
5207 realloc(text, l + strlen(buf)
5211 if (strlen(text) > 1024 * 8)
5217 #ifdef TCP_PORT_MONITOR
5218 CONF("min_port_monitors")
5221 (sscanf(value, "%d", &tcp_port_monitor_collection_args.min_port_monitors) != 1) ||
5222 tcp_port_monitor_collection_args.min_port_monitors < 0 )
5224 /* an error. use default, warn and continue. */
5225 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
5228 else if ( tcp_port_monitor_collection_args.min_port_monitors == 0 )
5230 /* no error, just use default */
5231 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
5233 /* else tcp_port_monitor_collection_args.min_port_monitors > 0 as per config */
5235 CONF("min_port_monitor_connections")
5238 (sscanf(value, "%d", &tcp_port_monitor_args.min_port_monitor_connections) != 1)
5239 || tcp_port_monitor_args.min_port_monitor_connections < 0 )
5241 /* an error. use default, warni and continue. */
5242 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
5245 else if ( tcp_port_monitor_args.min_port_monitor_connections == 0 )
5247 /* no error, just use default */
5248 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
5250 /* else tcp_port_monitor_args.min_port_monitor_connections > 0 as per config */
5254 ERR("%s: %d: no such configuration: '%s'", f, line, name);
5264 /* : means that character before that takes an argument */
5265 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
5278 int main(int argc, char **argv)
5280 struct sigaction act, oact;
5283 memset(&info, 0, sizeof(info) );
5285 #ifdef TCP_PORT_MONITOR
5286 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
5287 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
5290 /* handle command line parameters that don't change configs */
5296 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
5297 *s) || ((s = getenv("LANG")) && *s)) {
5299 for(x = 0; x < strlen(s) ; x++) {
5300 temp[x] = tolower(s[x]);
5302 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
5306 if (!setlocale(LC_CTYPE, "")) {
5307 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
5311 int c = getopt(argc,
5321 ("Conky " VERSION " compiled " __DATE__ "\n");
5325 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
5326 * though free() does the NULL check itself;), then load optarg value */
5328 free(current_config);
5329 current_config = strdup(optarg);
5334 ("Usage: %s [OPTION]...\n"
5335 "Conky is a system monitor that renders text on desktop or to own transparent\n"
5336 "window. Command line options will override configurations defined in config\n"
5339 " -c FILE config file to load instead of "
5342 " -d daemonize, fork to background\n"
5345 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
5346 " -f FONT font to use\n"
5348 " -o create own window to draw\n"
5351 " -b double buffer (prevents flickering)\n"
5353 " -w WIN_ID window id to draw\n"
5354 " -x X x position\n"
5355 " -y Y y position\n"
5357 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
5358 " -u SECS update interval\n"
5359 " -i NUM number of times to update Conky\n", argv[0]);
5363 window.window = strtol(optarg, 0, 0);
5372 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
5376 /* load current_config or CONFIG_FILE */
5379 if (current_config == NULL) {
5380 /* load default config file */
5383 variable_substitute(CONFIG_FILE, buf, 256);
5386 current_config = strdup(buf);
5390 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
5391 load_config_file(current_config);
5393 set_default_configurations();
5397 if (current_mail_spool == NULL) {
5399 variable_substitute(MAIL_FILE, buf, 256);
5402 current_mail_spool = strdup(buf);
5406 /* handle other command line arguments */
5408 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
5409 optind = optreset = 1;
5415 int c = getopt(argc,
5423 fork_to_background = 1;
5428 set_first_font(optarg);
5431 text_alignment = string_to_alignment(optarg);
5446 if (text != original_text)
5448 text = strdup(optarg);
5449 convert_escapes(text);
5453 update_interval = strtod(optarg, 0);
5457 total_run_times = strtod(optarg, 0);
5461 gap_x = atoi(optarg);
5465 gap_y = atoi(optarg);
5479 /* generate text and get initial size */
5480 extract_variable_text(text);
5481 if (text != original_text) {
5490 update_text_area(); /* to get initial size of the window */
5492 #if defined OWN_WINDOW
5496 text_width + border_margin * 2 + 1,
5497 text_height + border_margin * 2 + 1,
5498 on_bottom, fixed_pos, set_transparent, background_colour, info.uname_s.nodename);
5502 text_width + border_margin * 2 + 1,
5503 text_height + border_margin * 2 + 1,
5504 on_bottom, set_transparent, background_colour, info.uname_s.nodename);
5508 update_text_area(); /* to position text/window on screen */
5512 // why the fuck not?
5518 if (own_window && !fixed_pos) {
5519 XMoveWindow(display, window.window, window.x, window.y);
5522 set_transparent_background(window.window);
5533 if (fork_to_background) {
5537 ERR("can't fork() to background: %s",
5547 "Conky: forked to background, pid is %d\n",
5553 /* Set signal handlers */
5554 act.sa_handler = signal_handler;
5555 sigemptyset(&act.sa_mask);
5558 act.sa_flags |= SA_RESTART;
5561 if ( sigaction(SIGINT,&act,&oact) < 0 ||
5562 sigaction(SIGUSR1,&act,&oact) < 0 ||
5563 sigaction(SIGTERM,&act,&oact) < 0 )
5565 ERR("error setting signal handler: %s", strerror(errno) );
5569 /* joinable thread for audacious activity */
5570 pthread_attr_init(&info.audacious.thread_attr);
5571 pthread_attr_setdetachstate(&info.audacious.thread_attr, PTHREAD_CREATE_JOINABLE);
5573 pthread_mutex_init(&info.audacious.item_mutex, NULL);
5574 pthread_mutex_init(&info.audacious.runnable_mutex, NULL);
5575 /* init runnable condition for worker thread */
5576 pthread_mutex_lock(&info.audacious.runnable_mutex);
5577 info.audacious.runnable=1;
5578 pthread_mutex_unlock(&info.audacious.runnable_mutex);
5579 if (pthread_create(&info.audacious.thread, &info.audacious.thread_attr, audacious_thread_func, NULL))
5581 CRIT_ERR("unable to create audacious thread!");
5585 /* joinable thread for infopipe activity */
5586 pthread_attr_init(&info.infopipe.thread_attr);
5587 pthread_attr_setdetachstate(&info.infopipe.thread_attr, PTHREAD_CREATE_JOINABLE);
5589 pthread_mutex_init(&info.infopipe.item_mutex, NULL);
5590 pthread_mutex_init(&info.infopipe.runnable_mutex, NULL);
5591 /* init runnable condition for worker thread */
5592 pthread_mutex_lock(&info.infopipe.runnable_mutex);
5593 info.infopipe.runnable=1;
5594 pthread_mutex_unlock(&info.infopipe.runnable_mutex);
5595 if (pthread_create(&info.infopipe.thread, &info.infopipe.thread_attr, infopipe_thread_func, NULL))
5597 CRIT_ERR("unable to create infopipe thread!");
5604 /* signal audacious worker thread to terminate */
5605 pthread_mutex_lock(&info.audacious.runnable_mutex);
5606 info.audacious.runnable=0;
5607 pthread_mutex_unlock(&info.audacious.runnable_mutex);
5608 /* destroy thread attribute and wait for thread */
5609 pthread_attr_destroy(&info.audacious.thread_attr);
5610 if (pthread_join(info.audacious.thread, NULL))
5612 ERR("error joining audacious thread");
5614 /* destroy mutexes */
5615 pthread_mutex_destroy(&info.audacious.item_mutex);
5616 pthread_mutex_destroy(&info.audacious.runnable_mutex);
5619 /* signal infopipe worker thread to terminate */
5620 pthread_mutex_lock(&info.infopipe.runnable_mutex);
5621 info.infopipe.runnable=0;
5622 pthread_mutex_unlock(&info.infopipe.runnable_mutex);
5623 /* destroy thread attribute and wait for thread */
5624 pthread_attr_destroy(&info.infopipe.thread_attr);
5625 if (pthread_join(info.infopipe.thread, NULL))
5627 ERR("error joining infopipe thread");
5629 /* destroy mutexes */
5630 pthread_mutex_destroy(&info.infopipe.item_mutex);
5631 pthread_mutex_destroy(&info.infopipe.runnable_mutex);
5637 void signal_handler(int sig)
5639 /* signal handler is light as a feather, as it should be.
5640 * we will poll g_signal_pending with each loop of conky
5641 * and do any signal processing there, NOT here. pkovacs. */
5642 g_signal_pending=sig;