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"
287 "${color grey}SETI@Home Statistics:\n"
288 "${color grey}Seti Unit Number:$color $seti_credit\n"
289 "${color grey}Seti Progress:$color $seti_prog% $seti_progbar\n"
292 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
293 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
295 "${color grey}Name PID CPU% MEM%\n"
296 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
297 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
298 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
299 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
300 "${tail /var/log/Xorg.0.log 3}";
302 static char *text = original_text;
304 static int total_updates;
307 static int blockdepth = 0;
308 static int if_jumped = 0;
309 static int blockstart[MAX_IF_BLOCK_DEPTH];
311 int check_mount(char *s)
313 #if defined(__linux__)
315 FILE *mtab = fopen("/etc/mtab", "r");
317 char buf1[256], buf2[128];
318 while (fgets(buf1, 256, mtab)) {
319 sscanf(buf1, "%*s %128s", buf2);
320 if (!strcmp(s, buf2)) {
327 ERR("Could not open mtab");
330 #elif defined(__FreeBSD__)
331 struct statfs *mntbuf;
334 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
335 for (i = mntsize - 1; i >= 0; i--)
336 if (strcmp(mntbuf[i].f_mntonname, s) == 0)
345 static inline int calc_text_width(const char *s, int l)
351 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, s, l, &gi);
353 XftTextExtents8(display, fonts[selected_font].xftfont, s, l, &gi);
359 return XTextWidth(fonts[selected_font].font, s, l);
364 /* formatted text to render on screen, generated in generate_text(),
365 * drawn in draw_stuff() */
367 static char text_buffer[TEXT_BUFFER_SIZE * 4];
369 /* special stuff in text_buffer */
371 #define SPECIAL_CHAR '\x01'
388 static struct special_t {
398 unsigned long first_colour; // for graph gradient
399 unsigned long last_colour;
402 static int special_count;
404 static int special_index; /* used when drawing */
407 #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? */
409 static struct special_t *new_special(char *buf, int t)
411 if (special_count >= 128)
412 CRIT_ERR("too many special things in text");
414 buf[0] = SPECIAL_CHAR;
416 specials[special_count].type = t;
417 return &specials[special_count++];
420 typedef struct tailstring_list {
421 char data[TEXT_BUFFER_SIZE];
422 struct tailstring_list *next;
423 struct tailstring_list *first;
426 void addtail(tailstring ** head, char *data_in)
429 if ((tmp = malloc(sizeof(*tmp))) == NULL) {
435 tmp->first = (*head)->first;
437 strncpy(tmp->data, data_in, TEXT_BUFFER_SIZE);
442 void freetail(tailstring * head)
445 while (head != NULL) {
452 void freelasttail(tailstring * head)
454 tailstring * tmp = head;
456 if (tmp->next == head->first) {
463 while(head != NULL && tmp != NULL) {
469 static void new_bar(char *buf, int w, int h, int usage)
471 struct special_t *s = new_special(buf, BAR);
472 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
477 static const char *scan_bar(const char *args, int *w, int *h)
479 *w = 0; /* zero width means all space that is available */
481 /* bar's argument is either height or height,width */
484 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
485 sscanf(args, "%d %n", h, &n);
492 static char *scan_font(const char *args)
494 if (args && sizeof(args) < 127) {
498 ERR("font scan failed, lets hope it doesn't mess stuff up");
504 static void new_font(char *buf, char * args) {
505 struct special_t *s = new_special(buf, FONT);
506 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
507 int tmp = selected_font;
508 selected_font = s->font_added = addfont(args);
516 inline void graph_append(struct special_t *graph, double f)
518 if (!graph->scaled && f > graph->graph_scale) {
519 f = graph->graph_scale;
523 graph->graph_scale = 1;
525 graph->graph[0] = f; /* add new data */
526 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
527 graph->graph[i] = graph->graph[i - 1];
528 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
529 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
534 short colour_depth = 0;
535 void set_up_gradient();
537 /* precalculated: 31/255, and 63/255 */
538 #define CONST_8_TO_5_BITS 0.12156862745098
539 #define CONST_8_TO_6_BITS 0.247058823529412
541 /* adjust color values depending on color depth*/
542 static unsigned int adjust_colors(unsigned int color)
545 if (colour_depth == 0) {
548 if (colour_depth == 16) {
549 r = (color & 0xff0000) >> 16;
550 g = (color & 0xff00) >> 8;
552 color = (int)(r * CONST_8_TO_5_BITS) << 11;
553 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
554 color |= (int)(b * CONST_8_TO_5_BITS);
559 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
561 struct special_t *s = new_special(buf, GRAPH);
563 if (s->graph == NULL) {
564 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
565 s->graph_width = s->width - 3; // subtract 3 for the box
567 s->graph_width = MAX_GRAPH_DEPTH - 3;
569 s->graph = malloc(s->graph_width * sizeof(double));
570 memset(s->graph, 0, s->graph_width * sizeof(double));
571 s->graph_scale = 100;
574 s->first_colour = adjust_colors(first_colour);
575 s->last_colour = adjust_colors(second_colour);
582 s->graph_width = s->width - 3; // subtract 3 for rectangle around
587 s->graph_scale = scale;
594 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
596 *w = 0; /* zero width means all space that is available */
600 /* graph's argument is either height or height,width */
602 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
603 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
605 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
607 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
610 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
614 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
617 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
621 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
624 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
628 if (sscanf(args, "%d,%d", h, w) < 2) {
631 sscanf(args, "%*s %d,%d", h, w);
637 static inline void new_hr(char *buf, int a)
639 new_special(buf, HORIZONTAL_LINE)->height = a;
642 static inline void new_stippled_hr(char *buf, int a, int b)
644 struct special_t *s = new_special(buf, STIPPLED_HR);
649 static inline void new_fg(char *buf, long c)
651 new_special(buf, FG)->arg = c;
654 static inline void new_bg(char *buf, long c)
656 new_special(buf, BG)->arg = c;
659 static inline void new_outline(char *buf, long c)
661 new_special(buf, OUTLINE)->arg = c;
664 static inline void new_offset(char *buf, long c)
666 new_special(buf, OFFSET)->arg = c;
669 static inline void new_voffset(char *buf, long c)
671 new_special(buf, VOFFSET)->arg = c;
674 static inline void new_alignr(char *buf, long c)
676 new_special(buf, ALIGNR)->arg = c;
679 static inline void new_alignc(char *buf, long c)
681 new_special(buf, ALIGNC)->arg = c;
684 /* quite boring functions */
686 static inline void for_each_line(char *b, void (*f) (char *))
690 for (ps = b, pe = b; *pe; pe++) {
703 static void convert_escapes(char *buf)
705 char *p = buf, *s = buf;
721 /* converts from bytes to human readable format (k, M, G, T) */
722 static void human_readable(long long a, char *buf, int size)
724 // Strange conditional due to possible overflows
725 if(a / 1024 / 1024 / 1024.0 > 1024.0){
726 snprintf(buf, size, "%.2fT", (a / 1024 / 1024 / 1024) / 1024.0);
728 else if (a >= 1024 * 1024 * 1024) {
729 snprintf(buf, size, "%.2fG", (a / 1024 / 1024) / 1024.0);
731 else if (a >= 1024 * 1024) {
732 double m = (a / 1024) / 1024.0;
734 snprintf(buf, size, "%.0fM", m);
736 snprintf(buf, size, "%.1fM", m);
737 } else if (a >= 1024)
738 snprintf(buf, size, "%Ldk", a / (long long) 1024);
740 snprintf(buf, size, "%Ld", a);
745 enum text_object_type {
793 #if defined(__linux__)
799 OBJ_i8k_left_fan_status,
800 OBJ_i8k_right_fan_status,
801 OBJ_i8k_left_fan_rpm,
802 OBJ_i8k_right_fan_rpm,
804 OBJ_i8k_buttons_status,
805 #endif /* __linux__ */
832 OBJ_ml_upload_counter,
833 OBJ_ml_download_counter,
834 OBJ_ml_nshared_files,
835 OBJ_ml_shared_counter,
836 OBJ_ml_tcp_upload_rate,
837 OBJ_ml_tcp_download_rate,
838 OBJ_ml_udp_upload_rate,
839 OBJ_ml_udp_download_rate,
840 OBJ_ml_ndownloaded_files,
841 OBJ_ml_ndownloading_files,
844 OBJ_running_processes,
853 OBJ_temp1, /* i2c is used instead in these */
866 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
868 OBJ_apm_battery_time,
869 OBJ_apm_battery_life,
870 #endif /* __FreeBSD__ */
893 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
897 OBJ_xmms_length_seconds,
899 OBJ_xmms_position_seconds,
904 OBJ_xmms_playlist_length,
905 OBJ_xmms_playlist_position,
916 #ifdef TCP_PORT_MONITOR
924 unsigned int c, d, e;
927 char *s; /* some string */
928 int i; /* some integer */
929 long l; /* some other integer */
930 struct net_stat *net;
932 unsigned char loadavg[3];
933 unsigned int cpu_index;
979 #ifdef TCP_PORT_MONITOR
981 in_port_t port_range_begin; /* starting port to monitor */
982 in_port_t port_range_end; /* ending port to monitor */
983 int item; /* enum value from libtcp-portmon.h, e.g. COUNT, REMOTEIP, etc. */
984 int connection_index; /* 0 to n-1 connections. */
990 struct text_object_list {
991 unsigned int text_object_count;
992 struct text_object *text_objects;
995 static unsigned int text_object_count;
996 static struct text_object *text_objects;
997 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
999 pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
1001 void *threaded_exec( struct text_object *obj ) {
1002 char *p2 = obj->data.execi.buffer;
1003 FILE *fp = popen(obj->data.execi.cmd,"r");
1004 pthread_mutex_lock( &mutex1 );
1005 int n2 = fread(p2, 1, TEXT_BUFFER_SIZE, fp);
1008 if (n2 && p2[n2 - 1] == '\n')
1016 pthread_mutex_unlock( &mutex1 );
1020 static struct text_object *new_text_object_internal()
1022 struct text_object *obj = malloc(sizeof(struct text_object));
1023 memset(obj, 0, sizeof(struct text_object));
1030 if (mlconfig.mldonkey_hostname) {
1031 free(mlconfig.mldonkey_hostname);
1032 mlconfig.mldonkey_hostname = NULL;
1037 static void free_text_objects(unsigned int count, struct text_object *objs)
1040 for (i = 0; i < count; i++) {
1041 switch (objs[i].type) {
1043 close(objs[i].data.i);
1046 close(objs[i].data.i);
1049 close(objs[i].data.i2c.fd);
1052 free(objs[i].data.s);
1055 case OBJ_if_existing:
1056 case OBJ_if_mounted:
1057 case OBJ_if_running:
1058 free(objs[i].data.ifblock.s);
1061 free(objs[i].data.tail.logfile);
1062 free(objs[i].data.tail.buffer);
1064 case OBJ_text: case OBJ_font:
1065 free(objs[i].data.s);
1068 free(objs[i].data.s);
1071 free(objs[i].data.s);
1074 free(objs[i].data.s);
1076 /* case OBJ_execibar:
1077 free(objs[i].data.s);
1079 case OBJ_execigraph:
1080 free(objs[i].data.s);
1084 case OBJ_mpd_artist:
1086 case OBJ_mpd_random:
1087 case OBJ_mpd_repeat:
1089 case OBJ_mpd_status:
1093 case OBJ_bmpx_title:
1094 case OBJ_bmpx_artist:
1095 case OBJ_bmpx_album:
1096 case OBJ_bmpx_track:
1098 case OBJ_bmpx_bitrate:
1102 free(objs[i].data.s);
1106 free(objs[i].data.execi.cmd);
1107 free(objs[i].data.execi.buffer);
1110 free(objs[i].data.execi.cmd);
1111 free(objs[i].data.execi.buffer);
1114 if (info.first_process) {
1115 free_all_processes();
1116 info.first_process = NULL;
1120 if (info.first_process) {
1121 free_all_processes();
1122 info.first_process = NULL;
1128 //text_objects = NULL;
1129 //text_object_count = 0;
1132 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
1137 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
1138 *a = mixer_init(buf1);
1139 (void) scan_bar(arg + n, w, h);
1142 (void) scan_bar(arg, w, h);
1147 /* construct_text_object() creates a new text_object */
1148 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects)
1150 //struct text_object *obj = new_text_object();
1151 struct text_object *obj = new_text_object_internal();
1153 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
1154 #define END ; } } else
1158 obj->type = OBJ_color;
1159 obj->data.l = get_x11_color(s);
1162 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
1163 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
1164 END OBJ(acpiacadapter, 0)
1167 END OBJ(freq_dyn, 0);
1168 END OBJ(freq_dyn_g, 0);
1169 END OBJ(acpifan, 0);
1170 END OBJ(battery, 0);
1173 sscanf(arg, "%63s", bat);
1175 strcpy(bat, "BAT0");
1176 obj->data.s = strdup(bat);
1177 #if defined(__linux__)
1178 END OBJ(i8k_version, INFO_I8K)
1179 END OBJ(i8k_bios, INFO_I8K)
1180 END OBJ(i8k_serial, INFO_I8K)
1181 END OBJ(i8k_cpu_temp, INFO_I8K)
1182 END OBJ(i8k_cpu_tempf, INFO_I8K)
1183 END OBJ(i8k_left_fan_status, INFO_I8K)
1184 END OBJ(i8k_right_fan_status, INFO_I8K)
1185 END OBJ(i8k_left_fan_rpm, INFO_I8K)
1186 END OBJ(i8k_right_fan_rpm, INFO_I8K)
1187 END OBJ(i8k_ac_status, INFO_I8K)
1188 END OBJ(i8k_buttons_status, INFO_I8K)
1189 #endif /* __linux__ */
1190 END OBJ(buffers, INFO_BUFFERS)
1191 END OBJ(cached, INFO_BUFFERS)
1192 END OBJ(cpu, INFO_CPU)
1194 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1195 obj->data.cpu_index = atoi(&arg[3]);
1197 } else {obj->data.cpu_index = 0; }
1199 obj->data.cpu_index = 0;
1201 END OBJ(cpubar, INFO_CPU)
1203 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1204 obj->data.cpu_index = atoi(&arg[3]);
1207 else {obj->data.cpu_index = 0;}
1208 (void) scan_bar(arg, &obj->a, &obj->b);
1210 (void) scan_bar(arg, &obj->a, &obj->b);
1211 obj->data.cpu_index = 0;
1213 END OBJ(cpugraph, INFO_CPU)
1215 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
1216 obj->data.cpu_index = atoi(&arg[3]);
1219 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1221 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1222 obj->data.cpu_index = 0;
1224 END OBJ(diskio, INFO_DISKIO)
1225 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1228 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
1232 obj->data.s = scan_font(arg);
1234 OBJ(downspeed, INFO_NET)
1236 obj->data.net = get_net_stat(arg);
1239 CRIT_ERR("downspeed needs argument");
1241 END OBJ(downspeedf, INFO_NET)
1243 obj->data.net = get_net_stat(arg);
1246 CRIT_ERR("downspeedf needs argument");
1248 END OBJ(downspeedgraph, INFO_NET)
1249 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1251 sscanf(arg, "%63s %*i,%*i %*i", buf);
1252 obj->data.net = get_net_stat(buf);
1253 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
1254 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
1261 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
1262 blockstart[blockdepth - 1] = object_count;
1263 obj->data.ifblock.pos = object_count + 2;
1265 ERR("$else: no matching $if_*");
1269 printf("blockdepth is %i and blockstart[blockdepth] is %i and object_count is %i\n", blockdepth, blockstart[blockdepth - 1], object_count);
1271 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
1273 ERR("$endif: no matching $if_*");
1277 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
1278 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
1279 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
1280 END OBJ(execibar, 0) unsigned int n;
1281 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1283 ERR("${execibar <interval> command}");
1284 obj->type = OBJ_text;
1285 snprintf(buf, 256, "${%s}", s);
1286 obj->data.s = strdup(buf);
1288 obj->data.execi.cmd = strdup(arg + n);
1290 END OBJ(execigraph, 0) unsigned int n;
1291 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1293 ERR("${execigraph <interval> command}");
1294 obj->type = OBJ_text;
1295 snprintf(buf, 256, "${%s}", s);
1296 obj->data.s = strdup(buf);
1298 obj->data.execi.cmd = strdup(arg + n);
1300 END OBJ(execi, 0) unsigned int n;
1303 || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1305 ERR("${execi <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);
1311 obj->data.execi.buffer =
1312 (char *) calloc(1, TEXT_BUFFER_SIZE);
1314 END OBJ(texeci, 0) unsigned int n;
1317 || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
1319 ERR("${texeci <interval> command}");
1320 obj->type = OBJ_text;
1321 snprintf(buf, 256, "${%s}", s);
1322 obj->data.s = strdup(buf);
1324 obj->data.execi.cmd = strdup(arg + n);
1325 obj->data.execi.buffer =
1326 (char *) calloc(1, TEXT_BUFFER_SIZE);
1328 END OBJ(pre_exec, 0) obj->type = OBJ_text;
1330 FILE *fp = popen(arg, "r");
1334 n = fread(buf, 1, 2048, fp);
1337 if (n && buf[n - 1] == '\n')
1342 obj->data.s = strdup(buf);
1344 obj->data.s = strdup("");
1347 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
1348 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
1350 while (isspace(*arg))
1356 obj->data.fsbar.fs = prepare_fs_stat(arg);
1357 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
1360 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
1364 obj->data.fsbar.fs = prepare_fs_stat(arg);
1365 END OBJ(fs_free, INFO_FS) if (!arg)
1367 obj->data.fs = prepare_fs_stat(arg);
1368 END OBJ(fs_used_perc, INFO_FS) if (!arg)
1370 obj->data.fs = prepare_fs_stat(arg);
1371 END OBJ(fs_free_perc, INFO_FS) if (!arg)
1373 obj->data.fs = prepare_fs_stat(arg);
1374 END OBJ(fs_size, INFO_FS) if (!arg)
1376 obj->data.fs = prepare_fs_stat(arg);
1377 END OBJ(fs_used, INFO_FS) if (!arg)
1379 obj->data.fs = prepare_fs_stat(arg);
1380 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
1381 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
1382 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
1383 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
1387 ERR("i2c needs arguments");
1388 obj->type = OBJ_text;
1389 //obj->data.s = strdup("${i2c}");
1393 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
1394 /* if scanf couldn't read three values, read type and num and use
1396 sscanf(arg, "%63s %d", buf2, &n);
1398 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
1399 obj->data.i2c.devtype);
1400 strncpy(obj->data.i2c.type, buf2, 63);
1403 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
1404 obj->data.i2c.devtype);
1405 strncpy(obj->data.i2c.type, buf2, 63);
1408 END OBJ(top, INFO_TOP)
1412 ERR("top needs arguments");
1413 obj->type = OBJ_text;
1414 //obj->data.s = strdup("${top}");
1417 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1418 if (strcmp(buf, "name") == 0) {
1419 obj->data.top.type = TOP_NAME;
1420 } else if (strcmp(buf, "cpu") == 0) {
1421 obj->data.top.type = TOP_CPU;
1422 } else if (strcmp(buf, "pid") == 0) {
1423 obj->data.top.type = TOP_PID;
1424 } else if (strcmp(buf, "mem") == 0) {
1425 obj->data.top.type = TOP_MEM;
1427 ERR("invalid arg for top");
1430 if (n < 1 || n > 10) {
1431 CRIT_ERR("invalid arg for top");
1434 obj->data.top.num = n - 1;
1438 ERR("invalid args given for top");
1441 END OBJ(top_mem, INFO_TOP)
1445 ERR("top_mem needs arguments");
1446 obj->type = OBJ_text;
1447 obj->data.s = strdup("${top_mem}");
1450 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
1451 if (strcmp(buf, "name") == 0) {
1452 obj->data.top.type = TOP_NAME;
1453 } else if (strcmp(buf, "cpu") == 0) {
1454 obj->data.top.type = TOP_CPU;
1455 } else if (strcmp(buf, "pid") == 0) {
1456 obj->data.top.type = TOP_PID;
1457 } else if (strcmp(buf, "mem") == 0) {
1458 obj->data.top.type = TOP_MEM;
1460 ERR("invalid arg for top");
1463 if (n < 1 || n > 10) {
1464 CRIT_ERR("invalid arg for top");
1467 obj->data.top.num = n - 1;
1471 ERR("invalid args given for top");
1474 END OBJ(addr, INFO_NET)
1476 obj->data.net = get_net_stat(arg);
1479 CRIT_ERR("addr needs argument");
1481 END OBJ(linkstatus, INFO_WIFI)
1483 obj->data.net = get_net_stat(arg);
1486 CRIT_ERR("linkstatus needs argument");
1492 ERR("tail needs arguments");
1493 obj->type = OBJ_text;
1494 obj->data.s = strdup("${tail}");
1497 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
1498 if (n1 < 1 || n1 > 30) {
1499 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
1503 fp = fopen(buf, "r");
1505 obj->data.tail.logfile =
1506 malloc(TEXT_BUFFER_SIZE);
1507 strcpy(obj->data.tail.logfile, buf);
1508 obj->data.tail.wantedlines = n1 - 1;
1509 obj->data.tail.interval =
1510 update_interval * 2;
1514 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
1517 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
1518 if (n1 < 1 || n1 > 30) {
1520 ("invalid arg for tail, number of lines must be between 1 and 30");
1522 } else if (n2 < 1 || n2 < update_interval) {
1524 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
1528 fp = fopen(buf, "r");
1530 obj->data.tail.logfile =
1531 malloc(TEXT_BUFFER_SIZE);
1532 strcpy(obj->data.tail.logfile, buf);
1533 obj->data.tail.wantedlines = n1 - 1;
1534 obj->data.tail.interval = n2;
1538 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
1544 ERR("invalid args given for tail");
1547 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
1552 ERR("head needs arguments");
1553 obj->type = OBJ_text;
1554 obj->data.s = strdup("${head}");
1557 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
1558 if (n1 < 1 || n1 > 30) {
1559 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
1563 fp = fopen(buf, "r");
1565 obj->data.tail.logfile =
1566 malloc(TEXT_BUFFER_SIZE);
1567 strcpy(obj->data.tail.logfile, buf);
1568 obj->data.tail.wantedlines = n1 - 1;
1569 obj->data.tail.interval =
1570 update_interval * 2;
1574 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
1577 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
1578 if (n1 < 1 || n1 > 30) {
1580 ("invalid arg for head, number of lines must be between 1 and 30");
1582 } else if (n2 < 1 || n2 < update_interval) {
1584 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
1588 fp = fopen(buf, "r");
1590 obj->data.tail.logfile =
1591 malloc(TEXT_BUFFER_SIZE);
1592 strcpy(obj->data.tail.logfile, buf);
1593 obj->data.tail.wantedlines = n1 - 1;
1594 obj->data.tail.interval = n2;
1598 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
1604 ERR("invalid args given for head");
1607 obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
1608 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
1610 r = sscanf(arg, "%d %d %d", &a, &b, &c);
1611 if (r >= 3 && (c < 1 || c > 3))
1613 if (r >= 2 && (b < 1 || b > 3))
1615 if (r >= 1 && (a < 1 || a > 3))
1618 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
1619 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
1620 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
1621 END OBJ(if_existing, 0)
1622 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1623 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1626 ERR("if_existing needs an argument");
1627 obj->data.ifblock.s = 0;
1629 obj->data.ifblock.s = strdup(arg);
1630 blockstart[blockdepth] = object_count;
1631 obj->data.ifblock.pos = object_count + 2;
1633 END OBJ(if_mounted, 0)
1634 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1635 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1638 ERR("if_mounted needs an argument");
1639 obj->data.ifblock.s = 0;
1641 obj->data.ifblock.s = strdup(arg);
1642 blockstart[blockdepth] = object_count;
1643 obj->data.ifblock.pos = object_count + 2;
1645 printf("blockdepth is %i and blockstart[blockdepth] is %i and object_count is %i\n", blockdepth, blockstart[blockdepth - 1], object_count);
1646 END OBJ(if_running, 0)
1647 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
1648 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
1652 snprintf(buf, 256, "pidof %s >/dev/null", arg);
1653 obj->data.ifblock.s = strdup(buf);
1655 ERR("if_running needs an argument");
1656 obj->data.ifblock.s = 0;
1658 blockstart[blockdepth] = object_count;
1659 obj->data.ifblock.pos = object_count + 2;
1663 END OBJ(mails, INFO_MAIL)
1664 END OBJ(mem, INFO_MEM)
1665 END OBJ(memmax, INFO_MEM)
1666 END OBJ(memperc, INFO_MEM)
1667 END OBJ(membar, INFO_MEM)
1668 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1669 END OBJ(memgraph, INFO_MEM)
1670 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1671 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
1672 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
1673 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
1674 END OBJ(mixerbar, INFO_MIXER)
1675 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1676 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1677 END OBJ(mixerlbar, INFO_MIXER)
1678 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1679 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1680 END OBJ(mixerrbar, INFO_MIXER)
1681 scan_mixer_bar(arg, &obj->data.mixerbar.l,
1682 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
1685 OBJ(ml_upload_counter, INFO_MLDONKEY)
1686 END OBJ(ml_download_counter, INFO_MLDONKEY)
1687 END OBJ(ml_nshared_files, INFO_MLDONKEY)
1688 END OBJ(ml_shared_counter, INFO_MLDONKEY)
1689 END OBJ(ml_tcp_upload_rate, INFO_MLDONKEY)
1690 END OBJ(ml_tcp_download_rate, INFO_MLDONKEY)
1691 END OBJ(ml_udp_upload_rate, INFO_MLDONKEY)
1692 END OBJ(ml_udp_download_rate, INFO_MLDONKEY)
1693 END OBJ(ml_ndownloaded_files, INFO_MLDONKEY)
1694 END OBJ(ml_ndownloading_files, INFO_MLDONKEY) END
1696 OBJ(new_mails, INFO_MAIL)
1697 END OBJ(nodename, 0)
1698 END OBJ(processes, INFO_PROCS)
1699 END OBJ(running_processes, INFO_RUN_PROCS)
1700 END OBJ(shadecolor, 0)
1702 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
1704 END OBJ(outlinecolor, 0)
1706 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
1708 END OBJ(stippled_hr, 0)
1710 int a = stippled_borders, b = 1;
1712 if (sscanf(arg, "%d %d", &a, &b) != 2)
1713 sscanf(arg, "%d", &b);
1717 obj->data.pair.a = a;
1718 obj->data.pair.b = b;
1720 END OBJ(swap, INFO_MEM)
1721 END OBJ(swapmax, INFO_MEM)
1722 END OBJ(swapperc, INFO_MEM)
1723 END OBJ(swapbar, INFO_MEM)
1724 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1725 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
1727 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
1728 obj->data.i2c.devtype);
1729 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
1731 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
1732 obj->data.i2c.devtype);
1733 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1734 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
1735 END OBJ(totaldown, INFO_NET)
1737 obj->data.net = get_net_stat(arg);
1740 CRIT_ERR("totaldown needs argument");
1742 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
1744 obj->data.net = get_net_stat(arg);
1747 CRIT_ERR("totalup needs argument");
1750 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
1751 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
1752 END OBJ(upspeed, INFO_NET)
1754 obj->data.net = get_net_stat(arg);
1757 CRIT_ERR("upspeed needs argument");
1759 END OBJ(upspeedf, INFO_NET)
1761 obj->data.net = get_net_stat(arg);
1764 CRIT_ERR("upspeedf needs argument");
1767 END OBJ(upspeedgraph, INFO_NET)
1768 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
1770 sscanf(arg, "%63s %*i,%*i %*i", buf);
1771 obj->data.net = get_net_stat(buf);
1772 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
1773 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
1778 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
1779 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
1780 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
1781 OBJ(apm_adapter, 0) END
1782 OBJ(apm_battery_life, 0) END
1783 OBJ(apm_battery_time, 0) END
1784 #endif /* __FreeBSD__ */
1786 OBJ(seti_prog, INFO_SETI) END OBJ(seti_progbar, INFO_SETI)
1787 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1788 END OBJ(seti_credit, INFO_SETI) END
1791 OBJ(mpd_artist, INFO_MPD)
1792 END OBJ(mpd_title, INFO_MPD)
1793 END OBJ(mpd_random, INFO_MPD)
1794 END OBJ(mpd_repeat, INFO_MPD)
1795 END OBJ(mpd_elapsed, INFO_MPD)
1796 END OBJ(mpd_length, INFO_MPD)
1797 END OBJ(mpd_track, INFO_MPD)
1798 END OBJ(mpd_percent, INFO_MPD)
1799 END OBJ(mpd_album, INFO_MPD) END OBJ(mpd_vol,
1800 INFO_MPD) END OBJ(mpd_bitrate,
1802 END OBJ(mpd_status, INFO_MPD)
1803 END OBJ(mpd_bar, INFO_MPD)
1804 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
1807 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
1808 OBJ(xmms_status, INFO_XMMS) END
1809 OBJ(xmms_title, INFO_XMMS) END
1810 OBJ(xmms_length, INFO_XMMS) END
1811 OBJ(xmms_length_seconds, INFO_XMMS) END
1812 OBJ(xmms_position, INFO_XMMS) END
1813 OBJ(xmms_position_seconds, INFO_XMMS) END
1814 OBJ(xmms_bitrate, INFO_XMMS) END
1815 OBJ(xmms_frequency, INFO_XMMS) END
1816 OBJ(xmms_channels, INFO_XMMS) END
1817 OBJ(xmms_filename, INFO_XMMS) END
1818 OBJ(xmms_playlist_length, INFO_XMMS) END
1819 OBJ(xmms_playlist_position, INFO_XMMS) END
1820 OBJ(xmms_bar, INFO_XMMS)
1821 (void) scan_bar(arg, &obj->a, &obj->b);
1825 OBJ(bmpx_title, INFO_BMPX)
1826 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1828 OBJ(bmpx_artist, INFO_BMPX)
1829 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1831 OBJ(bmpx_album, INFO_BMPX)
1832 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1834 OBJ(bmpx_track, INFO_BMPX)
1835 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1837 OBJ(bmpx_uri, INFO_BMPX)
1838 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1840 OBJ(bmpx_bitrate, INFO_BMPX)
1841 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1844 #ifdef TCP_PORT_MONITOR
1845 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
1846 int argc, port_begin, port_end, item, connection_index;
1848 memset(itembuf,0,sizeof(itembuf));
1850 /* massive argument checking */
1852 CRIT_ERR("tcp_portmon: needs arguments");
1854 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
1855 if ( (argc != 3) && (argc != 4) )
1857 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
1859 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
1861 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
1863 if ( port_begin > port_end )
1865 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
1867 if ( strncmp(itembuf,"count",31) == 0 )
1869 else if ( strncmp(itembuf,"rip",31) == 0 )
1871 else if ( strncmp(itembuf,"rhost",31) == 0 )
1873 else if ( strncmp(itembuf,"rport",31) == 0 )
1875 else if ( strncmp(itembuf,"lip",31) == 0 )
1877 else if ( strncmp(itembuf,"lhost",31) == 0 )
1879 else if ( strncmp(itembuf,"lport",31) == 0 )
1881 else if ( strncmp(itembuf,"lservice",31) == 0 )
1885 CRIT_ERR("tcp_portmon: invalid item specified");
1887 if ( (argc==3) && (item!=COUNT) )
1889 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
1891 if ( (argc==4) && (connection_index<0) )
1893 CRIT_ERR("tcp_portmon: connection index must be non-negative");
1895 /* ok, args looks good. save the text object data */
1896 obj->data.tcp_port_monitor.port_range_begin = (in_addr_t)port_begin;
1897 obj->data.tcp_port_monitor.port_range_end = (in_addr_t)port_end;
1898 obj->data.tcp_port_monitor.item = item;
1899 obj->data.tcp_port_monitor.connection_index = connection_index;
1901 /* if the port monitor collection hasn't been created, we must create it */
1902 if ( !info.p_tcp_port_monitor_collection )
1904 info.p_tcp_port_monitor_collection =
1905 create_tcp_port_monitor_collection( &tcp_port_monitor_collection_args );
1906 if ( !info.p_tcp_port_monitor_collection )
1908 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
1912 /* if a port monitor for this port does not exist, create one and add it to the collection */
1913 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
1915 tcp_port_monitor_t * p_monitor =
1916 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
1919 CRIT_ERR("tcp_portmon: unable to create port monitor");
1921 /* add the newly created monitor to the collection */
1922 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
1925 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
1932 ERR("unknown variable %s", s);
1933 obj->type = OBJ_text;
1934 snprintf(buf, 256, "${%s}", s);
1935 obj->data.s = strdup(buf);
1942 static struct text_object *create_plain_text(const char *s)
1944 struct text_object *obj;
1946 if (s == NULL || *s == '\0') {
1950 obj = new_text_object_internal();
1952 obj->type = OBJ_text;
1953 obj->data.s = strdup(s);
1957 static struct text_object_list *extract_variable_text_internal(const char *p)
1959 struct text_object_list *retval;
1960 struct text_object *obj;
1963 retval = malloc(sizeof(struct text_object_list));
1964 memset(retval, 0, sizeof(struct text_object_list));
1965 retval->text_object_count = 0;
1970 obj = create_plain_text(s);
1972 // allocate memory for the object
1973 retval->text_objects = realloc(retval->text_objects,
1974 sizeof(struct text_object) * (retval->text_object_count+1));
1975 // assign the new object to the end of the list.
1976 memcpy(&retval->text_objects[retval->text_object_count++],
1977 obj, sizeof(struct text_object));
1989 /* variable is either $foo or ${foo} */
1993 while (*p && *p != '}')
1999 while (*p && (isalnum((int) *p)
2004 /* copy variable to buffer */
2005 len = (p - s > 255) ? 255 : (p - s);
2006 strncpy(buf, s, len);
2015 /* if variable wasn't found from environment, use some special */
2021 if (strchr(buf, ' ')) {
2022 arg = strchr(buf, ' ');
2025 while (isspace((int) *arg))
2031 /* lowercase variable name */
2038 // create new object
2039 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects);
2041 // allocate memory for the object
2042 retval->text_objects = realloc(retval->text_objects,
2043 sizeof(struct text_object) * (retval->text_object_count+1));
2044 // assign the new object to the end of the list.
2045 memcpy(&retval->text_objects[retval->text_object_count++],
2046 obj, sizeof(struct text_object));
2052 obj = create_plain_text("$");
2054 // allocate memory for the object
2055 retval->text_objects = realloc(retval->text_objects,
2056 sizeof(struct text_object) * (retval->text_object_count+1));
2057 // assign the new object to the end of the list.
2058 memcpy(&retval->text_objects[retval->text_object_count++],
2059 obj, sizeof(struct text_object));
2066 obj = create_plain_text(s);
2068 // allocate memory for the object
2069 retval->text_objects = realloc(retval->text_objects,
2070 sizeof(struct text_object) * (retval->text_object_count+1));
2071 // assign the new object to the end of the list.
2072 memcpy(&retval->text_objects[retval->text_object_count++],
2073 obj, sizeof(struct text_object));
2078 ERR("one or more $endif's are missing");
2084 static void extract_variable_text(const char *p)
2086 struct text_object_list *list;
2088 free_text_objects(text_object_count, text_objects);
2089 text_object_count = 0;
2090 text_objects = NULL;
2094 #endif /* MLDONKEY */
2096 list = extract_variable_text_internal(p);
2097 text_objects = list->text_objects;
2098 text_object_count = list->text_object_count;
2105 void parse_conky_vars(char * text, char * p, struct information *cur) {
2106 struct text_object_list *object_list = extract_variable_text_internal(text);
2107 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
2111 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
2115 for (i = 0; i < object_count; i++) {
2116 struct text_object *obj = &objs[i];
2118 #define OBJ(a) break; case OBJ_##a:
2120 switch (obj->type) {
2123 ERR("not implemented obj type %d",
2127 /* does anyone have decimals in acpi temperature? */
2129 snprintf(p, p_max_size, "%d", (int)
2130 get_acpi_temperature(obj->
2134 snprintf(p, 5, "%d ", (int)
2135 get_acpi_temperature(obj->
2140 /* does anyone have decimals in acpi temperature? */
2142 snprintf(p, p_max_size, "%d", (int)
2143 ((get_acpi_temperature(obj->
2145 i)+ 40) * 9.0 / 5 - 40));
2147 snprintf(p, 5, "%d ", (int)
2148 ((get_acpi_temperature(obj->
2150 i)+ 40) * 9.0 / 5 - 40));
2153 get_freq(p, p_max_size, "%.0f", 1); /* pk */
2156 get_freq(p, p_max_size, "%'.2f", 1000); /* pk */
2160 get_freq_dynamic(p, 6, "%.0f ", 1 ); /* pk */
2162 get_freq_dynamic(p, p_max_size, "%.0f", 1 ); /* pk */
2167 get_freq_dynamic(p, 6, "%'.2f ", 1000); /* pk */
2169 get_freq_dynamic(p, p_max_size, "%'.2f", 1000); /* pk */
2173 get_adt746x_cpu(p, p_max_size); /* pk */
2176 get_adt746x_fan(p, p_max_size); /* pk */
2179 get_acpi_fan(p, p_max_size); /* pk */
2181 OBJ(acpiacadapter) {
2182 get_acpi_ac_adapter(p, p_max_size); /* pk */
2185 get_battery_stuff(p, p_max_size, obj->data.s);
2188 human_readable(cur->buffers * 1024, p, 255);
2191 human_readable(cur->cached * 1024, p, 255);
2194 if (obj->data.cpu_index > info.cpu_count) {
2195 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
2196 CRIT_ERR("attempting to use more CPUs then you have!");
2199 snprintf(p, p_max_size, "%*d", pad_percents,
2200 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
2203 snprintf(p, 4, "%*d ",
2205 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
2211 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
2214 new_graph(p, obj->a,
2215 obj->b, obj->c, obj->d,
2216 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
2220 new_fg(p, obj->data.l);
2222 #if defined(__linux__)
2224 snprintf(p, p_max_size, "%s", i8k.version);
2227 snprintf(p, p_max_size, "%s", i8k.bios);
2230 snprintf(p, p_max_size, "%s", i8k.serial);
2233 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
2235 OBJ(i8k_cpu_tempf) {
2237 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
2238 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
2240 OBJ(i8k_left_fan_status) {
2241 int left_fan_status;
2242 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
2243 if(left_fan_status == 0) {
2244 snprintf(p, p_max_size,"off");
2245 } if(left_fan_status == 1) {
2246 snprintf(p, p_max_size, "low");
2247 } if(left_fan_status == 2) {
2248 snprintf(p, p_max_size, "high");
2252 OBJ(i8k_right_fan_status) {
2253 int right_fan_status;
2254 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
2255 if(right_fan_status == 0) {
2256 snprintf(p, p_max_size,"off");
2257 } if(right_fan_status == 1) {
2258 snprintf(p, p_max_size, "low");
2259 } if(right_fan_status == 2) {
2260 snprintf(p, p_max_size, "high");
2263 OBJ(i8k_left_fan_rpm) {
2264 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
2266 OBJ(i8k_right_fan_rpm) {
2267 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
2269 OBJ(i8k_ac_status) {
2271 sscanf(i8k.ac_status, "%d", &ac_status);
2272 if(ac_status == -1) {
2273 snprintf(p, p_max_size,"disabled (read i8k docs)");
2274 } if(ac_status == 0) {
2275 snprintf(p, p_max_size, "off");
2276 } if(ac_status == 1) {
2277 snprintf(p, p_max_size, "on");
2280 OBJ(i8k_buttons_status) {
2281 snprintf(p, p_max_size, "%s", i8k.buttons_status);
2284 #endif /* __linux__ */
2288 new_font(p, obj->data.s);
2293 if (diskio_value > 1024*1024) {
2294 snprintf(p, p_max_size, "%.1fG",
2295 (double)diskio_value/1024/1024);
2296 } else if (diskio_value > 1024) {
2297 snprintf(p, p_max_size, "%.1fM",
2298 (double)diskio_value/1024);
2299 } else if (diskio_value > 0) {
2300 snprintf(p, p_max_size, "%dK", diskio_value);
2302 snprintf(p, p_max_size, "%d", diskio_value);
2305 if (diskio_value > 1024*1024) {
2306 snprintf(p, 6, "%.1fG ",
2307 (double)diskio_value/1024/1024);
2308 } else if (diskio_value > 1024) {
2309 snprintf(p, 6, "%.1fM ",
2310 (double)diskio_value/1024);
2311 } else if (diskio_value > 0) {
2312 snprintf(p, 6, "%dK ", diskio_value);
2314 snprintf(p, 6, "%d ", diskio_value);
2319 new_graph(p, obj->a,
2320 obj->b, obj->c, obj->d,
2321 diskio_value, obj->e, 1);
2326 snprintf(p, p_max_size, "%d",
2327 (int) (obj->data.net->
2331 snprintf(p, 6, "%d ",
2332 (int) (obj->data.net->
2338 snprintf(p, p_max_size, "%.1f",
2340 recv_speed / 1024.0);
2342 snprintf(p, 8, "%.1f ",
2344 recv_speed / 1024.0);
2346 OBJ(downspeedgraph) {
2347 if (obj->data.net->recv_speed == 0) // this is just to make the ugliness at start go away
2348 obj->data.net->recv_speed = 0.01;
2349 new_graph(p, obj->a, obj->b, obj->c, obj->d,
2350 (obj->data.net->recv_speed /
2351 1024.0), obj->e, 1);
2357 i = obj->data.ifblock.pos - 2;
2367 snprintf(p, p_max_size, "%u.%u.%u.%u",
2368 obj->data.net->addr.
2370 obj->data.net->addr.
2372 obj->data.net->addr.
2374 obj->data.net->addr.
2379 snprintf(p, p_max_size, "%d",
2380 obj->data.net->linkstatus);
2384 FILE *fp = popen(obj->data.s, "r");
2385 int length = fread(p, 1, p_max_size, fp);
2388 /*output[length] = '\0';
2389 if (length > 0 && output[length - 1] == '\n') {
2390 output[length - 1] = '\0';
2393 if (length > 0 && p[length - 1] == '\n') {
2394 p[length - 1] = '\0';
2397 //parse_conky_vars(output, p, cur);
2401 FILE *fp = popen(obj->data.s, "r");
2402 int n2 = fread(p, 1, p_max_size, fp);
2406 if (n2 && p[n2 - 1] == '\n')
2415 if (sscanf(p, "%lf", &barnum) == 0) {
2416 ERR("reading execbar value failed (perhaps it's not the correct format?)");
2418 if (barnum > 100 || barnum < 0) {
2419 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
2421 barnum = barnum / 100.0;
2422 new_bar(p, 0, 4, (int) (barnum * 255.0));
2428 FILE *fp = popen(obj->data.s, "r");
2429 int n2 = fread(p, 1, p_max_size, fp);
2433 if (n2 && p[n2 - 1] == '\n')
2442 if (sscanf(p, "%lf", &barnum) == 0) {
2443 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
2445 if (barnum > 100 || barnum < 0) {
2446 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
2448 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
2453 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2454 new_bar(p, 0, 4, (int) obj->f);
2457 FILE *fp = popen(obj->data.execi.cmd, "r");
2458 int n2 = fread(p, 1, p_max_size, fp);
2461 if (n2 && p[n2 - 1] == '\n')
2470 if (sscanf(p, "%f", &barnum) == 0) {
2471 ERR("reading execibar value failed (perhaps it's not the correct format?)");
2473 if (barnum > 100 || barnum < 0) {
2474 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
2476 obj->f = 255 * barnum / 100.0;
2477 new_bar(p, 0, 4, (int) obj->f);
2479 obj->data.execi.last_update =
2480 current_update_time;
2484 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2485 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
2488 FILE *fp = popen(obj->data.execi.cmd, "r");
2489 int n2 = fread(p, 1, p_max_size, fp);
2492 if (n2 && p[n2 - 1] == '\n')
2501 if (sscanf(p, "%f", &barnum) == 0) {
2502 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
2504 if (barnum > 100 || barnum < 0) {
2505 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
2508 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
2510 obj->data.execi.last_update = current_update_time;
2516 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
2517 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
2519 char *output = obj->data.execi.buffer;
2520 FILE *fp = popen(obj->data.execi.cmd, "r");
2521 //int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
2522 int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
2525 output[length] = '\0';
2526 if (length > 0 && output[length - 1] == '\n') {
2527 output[length - 1] = '\0';
2529 obj->data.execi.last_update = current_update_time;
2530 snprintf(p, p_max_size, "%s", output);
2532 //parse_conky_vars(output, p, cur);
2535 static int running = 0;
2536 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
2537 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
2539 static pthread_t execthread;
2541 pthread_join( execthread, NULL);
2546 pthread_create( &execthread, NULL, (void*)threaded_exec, (void*) obj);
2547 pthread_mutex_lock( &mutex1 );
2548 obj->data.execi.last_update = current_update_time;
2549 pthread_mutex_unlock( &mutex1 );
2551 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
2553 //parse_conky_vars(obj->data.execi.buffer, p, cur);
2557 if (obj->data.fs != NULL) {
2558 if (obj->data.fs->size == 0)
2577 if (obj->data.fs != NULL)
2578 human_readable(obj->data.fs->avail,
2582 if (obj->data.fs != NULL) {
2583 if (obj->data.fs->size)
2584 snprintf(p, p_max_size, "%*d",
2593 snprintf(p, p_max_size, "0");
2597 if (obj->data.fs != NULL)
2598 human_readable(obj->data.fs->size,
2602 if (obj->data.fs != NULL)
2603 human_readable(obj->data.fs->size -
2604 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
2608 if (obj->data.fs != NULL) {
2609 if (obj->data.fs->size == 0)
2627 if (obj->data.fs != NULL) {
2628 if (obj->data.fs->size)
2629 snprintf(p, 4, "%d",
2639 snprintf(p, p_max_size, "0");
2643 float *v = info.loadavg;
2645 if (obj->data.loadavg[2])
2646 snprintf(p, p_max_size, "%.2f %.2f %.2f",
2647 v[obj->data.loadavg[0] -
2649 v[obj->data.loadavg[1] -
2651 v[obj->data.loadavg[2] -
2653 else if (obj->data.loadavg[1])
2654 snprintf(p, p_max_size, "%.2f %.2f",
2655 v[obj->data.loadavg[0] -
2657 v[obj->data.loadavg[1] -
2659 else if (obj->data.loadavg[0])
2660 snprintf(p, p_max_size, "%.2f",
2661 v[obj->data.loadavg[0] -
2665 new_hr(p, obj->data.i);
2668 new_offset(p, obj->data.i);
2671 new_voffset(p, obj->data.i);
2676 r = get_i2c_info(&obj->data.i2c.fd,
2678 obj->data.i2c.devtype,
2679 obj->data.i2c.type);
2681 if (r >= 100.0 || r == 0)
2682 snprintf(p, p_max_size, "%d", (int) r);
2684 snprintf(p, p_max_size, "%.1f", r);
2687 new_alignr(p, obj->data.i);
2690 new_alignc(p, obj->data.i);
2694 if ((obj->data.ifblock.s)
2695 && (stat(obj->data.ifblock.s, &tmp) ==
2697 i = obj->data.ifblock.pos;
2704 if ((obj->data.ifblock.s)
2705 && (!check_mount(obj->data.ifblock.s))) {
2706 i = obj->data.ifblock.pos;
2713 if ((obj->data.ifblock.s)
2714 && system(obj->data.ifblock.s)) {
2715 i = obj->data.ifblock.pos;
2722 snprintf(p, p_max_size, "%s", cur->uname_s.release);
2725 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
2730 human_readable(cur->mem * 1024, p, 6);
2733 human_readable(cur->memmax * 1024, p, 255);
2738 snprintf(p, p_max_size, "%*lu",
2743 snprintf(p, 4, "%*lu ",
2750 new_bar(p, obj->data.pair.a,
2752 cur->memmax ? (cur->mem * 255) /
2757 new_graph(p, obj->a,
2758 obj->b, obj->c, obj->d,
2759 cur->memmax ? (cur->mem * 100.0) /
2760 (cur->memmax) : 0.0, 100, 1);
2764 snprintf(p, p_max_size, "%d",
2765 mixer_get_avg(obj->data.l));
2768 snprintf(p, p_max_size, "%d",
2769 mixer_get_left(obj->data.l));
2772 snprintf(p, p_max_size, "%d",
2773 mixer_get_right(obj->data.l));
2776 new_bar(p, obj->data.mixerbar.w,
2777 obj->data.mixerbar.h,
2778 mixer_get_avg(obj->data.mixerbar.
2782 new_bar(p, obj->data.mixerbar.w,
2783 obj->data.mixerbar.h,
2784 mixer_get_left(obj->data.mixerbar.
2788 new_bar(p, obj->data.mixerbar.w,
2789 obj->data.mixerbar.h,
2790 mixer_get_right(obj->data.mixerbar.
2796 snprintf(p, p_max_size, "%d", cur->mail_count);
2799 snprintf(p, p_max_size, "%d", cur->new_mail_count);
2802 OBJ(ml_upload_counter) {
2803 snprintf(p, p_max_size, "%lld",
2804 mlinfo.upload_counter / 1048576);
2806 OBJ(ml_download_counter) {
2807 snprintf(p, p_max_size, "%lld",
2808 mlinfo.download_counter /
2811 OBJ(ml_nshared_files) {
2812 snprintf(p, p_max_size, "%i", mlinfo.nshared_files);
2814 OBJ(ml_shared_counter) {
2815 snprintf(p, p_max_size, "%lld",
2816 mlinfo.shared_counter / 1048576);
2818 OBJ(ml_tcp_upload_rate) {
2819 snprintf(p, p_max_size, "%.2f",
2820 (float) mlinfo.tcp_upload_rate /
2823 OBJ(ml_tcp_download_rate) {
2824 snprintf(p, p_max_size, "%.2f",
2825 (float) mlinfo.tcp_download_rate /
2828 OBJ(ml_udp_upload_rate) {
2829 snprintf(p, p_max_size, "%.2f",
2830 (float) mlinfo.udp_upload_rate /
2833 OBJ(ml_udp_download_rate) {
2834 snprintf(p, p_max_size, "%.2f",
2835 (float) mlinfo.udp_download_rate /
2838 OBJ(ml_ndownloaded_files) {
2839 snprintf(p, p_max_size, "%i",
2840 mlinfo.ndownloaded_files);
2842 OBJ(ml_ndownloading_files) {
2843 snprintf(p, p_max_size, "%i",
2844 mlinfo.ndownloading_files);
2849 snprintf(p, p_max_size, "%s",
2850 cur->uname_s.nodename);
2853 new_outline(p, obj->data.l);
2857 snprintf(p, p_max_size, "%hu", cur->procs);
2859 snprintf(p, 5, "%hu ",
2862 OBJ(running_processes) {
2864 snprintf(p, p_max_size, "%hu",
2867 snprintf(p, 3, "%hu ",
2871 snprintf(p, p_max_size, "%s", obj->data.s);
2874 new_bg(p, obj->data.l);
2877 new_stippled_hr(p, obj->data.pair.a,
2881 human_readable(cur->swap * 1024, p, 255);
2884 human_readable(cur->swapmax * 1024, p,
2888 if (cur->swapmax == 0) {
2889 strncpy(p, "No swap", 255);
2892 snprintf(p, 255, "%*lu",
2898 snprintf(p, 4, "%*lu ",
2906 new_bar(p, obj->data.pair.a,
2908 cur->swapmax ? (cur->swap * 255) /
2909 (cur->swapmax) : 0);
2912 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
2915 time_t t = time(NULL);
2916 struct tm *tm = localtime(&t);
2917 setlocale(LC_TIME, "");
2918 strftime(p, p_max_size, obj->data.s, tm);
2921 time_t t = time(NULL);
2922 struct tm *tm = gmtime(&t);
2923 strftime(p, p_max_size, obj->data.s, tm);
2926 human_readable(obj->data.net->recv, p,
2930 human_readable(obj->data.net->trans, p,
2934 snprintf(p, p_max_size, "%d", total_updates);
2938 snprintf(p, p_max_size, "%d",
2939 (int) (obj->data.net->
2943 snprintf(p, 5, "%d ",
2944 (int) (obj->data.net->
2950 snprintf(p, p_max_size, "%.1f",
2952 trans_speed / 1024.0);
2954 snprintf(p, 8, "%.1f ",
2956 trans_speed / 1024.0);
2959 if (obj->data.net->trans_speed == 0) // this is just to make the ugliness at start go away
2960 obj->data.net->trans_speed = 0.01;
2961 new_graph(p, obj->a, obj->b, obj->c, obj->d,
2962 (obj->data.net->trans_speed /
2963 1024.0), obj->e, 1);
2966 format_seconds_short(p, p_max_size,
2970 format_seconds(p, p_max_size, (int) cur->uptime);
2973 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
2975 snprintf(p, p_max_size, "%s", get_apm_adapter());
2977 OBJ(apm_battery_life) {
2979 msg = get_apm_battery_life();
2980 snprintf(p, p_max_size, "%s", msg);
2983 OBJ(apm_battery_time) {
2985 msg = get_apm_battery_time();
2986 snprintf(p, p_max_size, "%s", msg);
2989 #endif /* __FreeBSD__ */
2992 snprintf(p, p_max_size, "%.2f",
2993 cur->seti_prog * 100.0f);
2996 new_bar(p, obj->data.pair.a,
2998 (int) (cur->seti_prog * 255.0f));
3001 snprintf(p, p_max_size, "%.0f", cur->seti_credit);
3007 snprintf(p, p_max_size, "%s", cur->mpd.title);
3010 snprintf(p, p_max_size, "%s", cur->mpd.artist);
3013 snprintf(p, p_max_size, "%s", cur->mpd.album);
3016 snprintf(p, p_max_size, "%s", cur->mpd.random);
3019 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
3022 snprintf(p, p_max_size, "%s", cur->mpd.track);
3025 snprintf(p, p_max_size, "%i", cur->mpd.volume);
3028 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
3031 snprintf(p, p_max_size, "%s", cur->mpd.status);
3034 int days = 0, hours = 0, minutes =
3036 int tmp = cur->mpd.elapsed;
3037 while (tmp >= 86400) {
3041 while (tmp >= 3600) {
3051 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
3052 days, hours, minutes,
3055 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
3058 snprintf(p, p_max_size, "%i:%02i", minutes,
3062 int days = 0, hours = 0, minutes =
3064 int tmp = cur->mpd.length;
3065 while (tmp >= 86400) {
3069 while (tmp >= 3600) {
3079 snprintf(p, p_max_size,
3080 "%i days %i:%02i:%02i",
3081 days, hours, minutes,
3084 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
3087 snprintf(p, p_max_size, "%i:%02i", minutes,
3091 snprintf(p, p_max_size, "%2.0f",
3092 cur->mpd.progress * 100);
3095 new_bar(p, obj->data.pair.a,
3097 (int) (cur->mpd.progress *
3101 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
3103 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_STATUS]);
3106 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_TITLE]);
3109 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_LENGTH]);
3111 OBJ(xmms_length_seconds) {
3112 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_LENGTH_SECONDS]);
3114 OBJ(xmms_position) {
3115 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_POSITION]);
3117 OBJ(xmms_position_seconds) {
3118 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_POSITION_SECONDS]);
3121 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_BITRATE]);
3123 OBJ(xmms_frequency) {
3124 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_FREQUENCY]);
3126 OBJ(xmms_channels) {
3127 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_CHANNELS]);
3129 OBJ(xmms_filename) {
3130 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_FILENAME]);
3132 OBJ(xmms_playlist_length) {
3133 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_PLAYLIST_LENGTH]);
3135 OBJ(xmms_playlist_position) {
3136 snprintf(p, p_max_size, "%s", cur->xmms.items[XMMS_PLAYLIST_POSITION]);
3140 progress= atof(cur->xmms.items[XMMS_POSITION_SECONDS]) /
3141 atof(cur->xmms.items[XMMS_LENGTH_SECONDS]);
3142 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
3147 snprintf(p, p_max_size, "%s", cur->bmpx.title);
3150 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
3153 snprintf(p, p_max_size, "%s", cur->bmpx.album);
3156 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
3159 snprintf(p, p_max_size, "%i", cur->bmpx.track);
3162 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
3166 if (obj->data.top.type == TOP_NAME
3167 && obj->data.top.num >= 0
3168 && obj->data.top.num < 10) {
3169 // if we limit the buffer and add a bunch of space after, it stops the thing from
3170 // moving other shit around, which is really fucking annoying
3171 snprintf(p, 17, "%s ", cur->cpu[obj->data.top.num]->name);
3172 } else if (obj->data.top.type == TOP_CPU
3173 && obj->data.top.num >= 0
3174 && obj->data.top.num < 10) {
3175 snprintf(p, 7, "%3.2f ",
3176 cur->cpu[obj->data.top.
3178 } else if (obj->data.top.type == TOP_PID
3179 && obj->data.top.num >= 0
3180 && obj->data.top.num < 10) {
3181 snprintf(p, 8, "%i ",
3182 cur->cpu[obj->data.top.
3184 } else if (obj->data.top.type == TOP_MEM
3185 && obj->data.top.num >= 0
3186 && obj->data.top.num < 10) {
3187 snprintf(p, 7, "%3.2f ",
3188 cur->cpu[obj->data.top.
3193 if (obj->data.top.type == TOP_NAME
3194 && obj->data.top.num >= 0
3195 && obj->data.top.num < 10) {
3196 // if we limit the buffer and add a bunch of space after, it stops the thing from
3197 // moving other shit around, which is really fucking annoying
3200 cur->memu[obj->data.top.
3202 } else if (obj->data.top.type == TOP_CPU
3203 && obj->data.top.num >= 0
3204 && obj->data.top.num < 10) {
3205 snprintf(p, 7, "%3.2f ",
3206 cur->memu[obj->data.top.
3208 } else if (obj->data.top.type == TOP_PID
3209 && obj->data.top.num >= 0
3210 && obj->data.top.num < 10) {
3211 snprintf(p, 8, "%i ",
3212 cur->memu[obj->data.top.
3214 } else if (obj->data.top.type == TOP_MEM
3215 && obj->data.top.num >= 0
3216 && obj->data.top.num < 10) {
3217 snprintf(p, 7, "%3.2f ",
3218 cur->memu[obj->data.top.
3225 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
3226 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
3228 obj->data.tail.last_update = current_update_time;
3232 tailstring *head = NULL;
3233 tailstring *headtmp = NULL;
3234 tailstring *freetmp = NULL;
3235 fp = fopen(obj->data.tail.logfile, "rt");
3237 ERR("tail logfile failed to open");
3240 obj->data.tail.readlines = 0;
3242 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL) {
3249 addtail(&head, obj->data.tail.buffer);
3250 obj->data.tail.readlines++;
3256 if (obj->data.tail.readlines > 0) {
3257 for (i = 0;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
3258 addtail(&headtmp, head->data);
3263 strcpy(obj->data.tail.buffer, headtmp->data);
3264 headtmp = headtmp->next;
3265 for (i = 1;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
3267 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 */
3268 headtmp = headtmp->next;
3272 /* get rid of any ugly newlines at the end */
3273 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
3274 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
3276 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
3280 strcpy(obj->data.tail.buffer, "Logfile Empty");
3281 snprintf(p, p_max_size, "Logfile Empty");
3282 } /* if readlines */
3284 } /* if cur_upd_time >= */
3286 //parse_conky_vars(obj->data.tail.buffer, p, cur);
3290 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
3291 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
3293 obj->data.tail.last_update = current_update_time;
3295 tailstring *head = NULL;
3296 tailstring *headtmp = NULL;
3297 tailstring *freetmp = NULL;
3298 fp = fopen(obj->data.tail.logfile, "rt");
3300 ERR("head logfile failed to open");
3302 obj->data.tail.readlines = 0;
3303 while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL && obj->data.tail.readlines <= obj->data.tail.wantedlines) {
3304 addtail(&head, obj->data.tail.buffer);
3305 obj->data.tail.readlines++;
3309 if (obj->data.tail.readlines > 0) {
3311 addtail(&headtmp, head->data);
3316 strcpy(obj->data.tail.buffer, headtmp->data);
3317 headtmp = headtmp->next;
3319 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 */
3320 headtmp = headtmp->next;
3323 /* get rid of any ugly newlines at the end */
3324 if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
3325 obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
3327 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
3329 strcpy(obj->data.tail.buffer, "Logfile Empty");
3330 snprintf(p, p_max_size, "Logfile Empty");
3331 } /* if readlines > 0 */
3332 } /* if fp == null */
3333 } /* cur_upd_time >= */
3335 //parse_conky_vars(obj->data.tail.buffer, p, cur);
3338 #ifdef TCP_PORT_MONITOR
3341 /* grab a pointer to this port monitor */
3342 tcp_port_monitor_t * p_monitor =
3343 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
3344 obj->data.tcp_port_monitor.port_range_begin,
3345 obj->data.tcp_port_monitor.port_range_end );
3347 snprintf(p, p_max_size, "monitor not found");
3351 /* now grab the text of interest */
3352 if ( peek_tcp_port_monitor( p_monitor,
3353 obj->data.tcp_port_monitor.item,
3354 obj->data.tcp_port_monitor.connection_index,
3355 p, p_max_size ) != 0 )
3357 snprintf(p, p_max_size, "monitor peek error");
3367 unsigned int a = strlen(p);
3375 double current_update_time, last_update_time;
3377 static void generate_text()
3379 struct information *cur = &info;
3386 current_update_time = get_time();
3390 /* add things to the buffer */
3396 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
3398 if (stuff_in_upper_case) {
3408 last_update_time = current_update_time;
3415 static void set_font()
3419 if (window.xftdraw != NULL) {
3420 XftDrawDestroy(window.xftdraw);
3422 window.xftdraw = XftDrawCreate(display, window.drawable,
3423 DefaultVisual(display,
3425 DefaultColormap(display,
3430 XSetFont(display, window.gc, fonts[selected_font].font->fid);
3439 static int text_start_x, text_start_y; /* text start position in window */
3440 static int text_width, text_height;
3444 static inline int get_string_width(const char *s)
3447 return *s ? calc_text_width(s, strlen(s)) : 0;
3453 static inline int get_string_width_special(char *s)
3466 if (*p == SPECIAL_CHAR) {
3467 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
3468 for (i = 0; i < strlen(p); i++) {
3469 *(p + i) = *(p + i + 1);
3471 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
3472 width += specials[special_index+index].width;
3479 if (strlen(final) > 1) {
3480 width += calc_text_width(final, strlen(final));
3492 static void text_size_updater(char *s)
3496 int h = font_height();
3497 /* get string widths and skip specials */
3500 if (*p == SPECIAL_CHAR) {
3502 w += get_string_width(s);
3505 if (specials[special_index].type == BAR
3506 || specials[special_index].type == GRAPH) {
3507 w += specials[special_index].width;
3508 if (specials[special_index].height > h) {
3509 h = specials[special_index].height;
3514 else if (specials[special_index].type == OFFSET) {
3515 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
3517 else if (specials[special_index].type == VOFFSET) {
3518 h += specials[special_index].arg;
3520 else if (specials[special_index].type == FONT) {
3521 fontchange = specials[special_index].font_added;
3522 selected_font = specials[special_index].font_added;
3532 w += get_string_width(s);
3535 if (text_width > maximum_width && maximum_width)
3536 text_width = maximum_width;
3547 static void update_text_area()
3551 /* update text size if it isn't fixed */
3556 text_width = minimum_width;
3559 for_each_line(text_buffer, text_size_updater);
3561 if (text_height < minimum_height)
3562 text_height = minimum_height;
3563 if (text_width > maximum_width && maximum_width > 0)
3564 text_width = maximum_width;
3567 /* get text position on workarea */
3568 switch (text_alignment) {
3575 x = workarea[2] - text_width - gap_x;
3582 y = workarea[3] - text_height - gap_y;
3586 x = workarea[2] - text_width - gap_x;
3587 y = workarea[3] - text_height - gap_y;
3591 case NONE: // Let the WM manage the window
3602 if (own_window && !fixed_pos) {
3605 text_start_x = border_margin + 1;
3606 text_start_y = border_margin + 1;
3607 window.x = x - border_margin - 1;
3608 window.y = y - border_margin - 1;
3612 /* If window size doesn't match to workarea's size, then window
3613 * probably includes panels (gnome).
3614 * Blah, doesn't work on KDE. */
3615 if (workarea[2] != window.width
3616 || workarea[3] != window.height) {
3630 static int cur_x, cur_y; /* current x and y for drawing */
3631 static int draw_mode; /* FG, BG or OUTLINE */
3632 static long current_color;
3634 static inline void set_foreground_color(long c)
3637 XSetForeground(display, window.gc, c);
3641 static void draw_string(const char *s)
3645 int i, i2, pos, width_of_s;
3648 width_of_s = get_string_width(s);
3649 if (out_to_console) {
3651 fflush(stdout); /* output immediately, don't buffer */
3653 /* 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 */
3654 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
3655 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
3656 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
3660 snprintf(space, 2, " ");
3662 max = ((text_width - width_of_s) / get_string_width(space));
3665 * This code looks for tabs in the text and coverts them to spaces.
3666 * The trick is getting the correct number of spaces,
3667 * and not going over the window's size without forcing
3668 * the window larger.
3670 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
3671 if (tmpstring1[i] == '\t') // 9 is ascii tab
3675 i2 < (8 - (1 + pos) % 8) && added <= max;
3678 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
3679 fprintf(stderr,"buffer overrun detected\n");
3681 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
3686 if (tmpstring1[i] != 9) {
3688 if ( pos > TEXT_BUFFER_SIZE-1 )
3689 fprintf(stderr,"buffer overrun detected\n");
3691 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
3697 if (text_width == maximum_width) {
3698 /* this means the text is probably pushing the limit, so we'll chop it */
3699 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
3700 tmpstring2[strlen(tmpstring2)-1] = '\0';
3710 c.pixel = current_color;
3711 XQueryColor(display, DefaultColormap(display, screen), &c);
3714 c2.color.red = c.red;
3715 c2.color.green = c.green;
3716 c2.color.blue = c.blue;
3717 c2.color.alpha = fonts[selected_font].font_alpha;
3719 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
3720 cur_x, cur_y, (XftChar8 *) s,
3723 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
3724 cur_x, cur_y, (XftChar8 *) s,
3730 XDrawString(display, window.drawable, window.gc,
3731 cur_x, cur_y, s, strlen(s));
3733 cur_x += width_of_s;
3735 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
3738 long redmask, greenmask, bluemask;
3740 void set_up_gradient()
3743 colour_depth = DisplayPlanes(display, screen);
3747 if (colour_depth != 24 && colour_depth != 16) {
3748 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
3754 for(i = (colour_depth / 3)-1; i>=0; i--) {
3756 greenmask |= 1 << i;
3759 if (colour_depth%3 == 1) {
3760 greenmask |= 1 << (colour_depth / 3);
3762 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
3763 greenmask = greenmask << (colour_depth / 3);
3766 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 */
3768 int red1, green1, blue1; // first colour
3769 int red2, green2, blue2; // second colour
3770 int red3 = 0, green3 = 0, blue3 = 0; // difference
3771 short redshift = (2*colour_depth / 3 + colour_depth%3);
3772 short greenshift = (colour_depth / 3);
3773 red1 = (first_colour & redmask) >> redshift;
3774 green1 = (first_colour & greenmask) >> greenshift;
3775 blue1 = first_colour & bluemask;
3776 red2 = (last_colour & redmask) >> redshift;
3777 green2 = (last_colour & greenmask) >> greenshift;
3778 blue2 = last_colour & bluemask;
3785 if (green1 > green2) {
3788 if (green1 < green2) {
3791 if (blue1 > blue2) {
3794 if (blue1 < blue2) {
3809 if (red1 > bluemask) {
3812 if (green1 > bluemask) {
3815 if (blue1 > bluemask) {
3818 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
3822 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
3823 if (colour_depth == 0) {
3826 int red1, green1, blue1; // first colour
3827 int red2, green2, blue2; // second colour
3828 long redshift = (2*colour_depth / 3 + colour_depth%3);
3829 long greenshift = (colour_depth / 3);
3830 int red3 = 0, green3 = 0, blue3 = 0; // difference
3831 red1 = (first_colour & redmask) >> redshift;
3832 green1 = (first_colour & greenmask) >> greenshift;
3833 blue1 = first_colour & bluemask;
3834 red2 = (last_colour & redmask) >> redshift;
3835 green2 = (last_colour & greenmask) >> greenshift;
3836 blue2 = last_colour & bluemask;
3837 red3 = abs(red1 - red2);
3838 green3 = abs(green1 - green2);
3839 blue3 = abs(blue1 - blue2);
3848 static void draw_line(char *s)
3852 cur_x = text_start_x;
3853 cur_y += font_ascent();
3855 short font_h = font_height();
3857 /* find specials and draw stuff */
3860 if (*p == SPECIAL_CHAR) {
3863 /* draw string before special */
3870 switch (specials[special_index].type) {
3871 case HORIZONTAL_LINE:
3874 specials[special_index].height;
3875 int mid = font_ascent() / 2;
3876 w = text_start_x + text_width -
3879 XSetLineAttributes(display,
3884 XDrawLine(display, window.drawable,
3895 specials[special_index].height;
3897 specials[special_index].arg;
3898 int mid = font_ascent() / 2;
3899 char ss[2] = { s, s };
3900 w = text_start_x + text_width -
3903 XSetLineAttributes(display,
3908 XSetDashes(display, window.gc, 0,
3910 XDrawLine(display, window.drawable,
3920 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
3924 specials[special_index].height;
3926 specials[special_index].arg;
3931 by = cur_y - (font_ascent() + h) / 2 - 1;
3935 by = cur_y - (font_ascent()/2) - 1;
3937 if (h < (font_height())) {
3940 w = specials[special_index].width;
3943 text_width - cur_x - 1;
3947 XSetLineAttributes(display,
3953 XDrawRectangle(display,
3957 XFillRectangle(display,
3961 w * bar_usage / 255,
3963 if (specials[special_index].
3965 && specials[special_index].
3969 [special_index].height;
3976 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
3980 specials[special_index].height;
3984 by = cur_y - (font_ascent() + h) / 2 - 1;
3988 by = cur_y - (font_ascent()/2) - 1;
3990 if (h < (font_height())) {
3993 w = specials[special_index].width;
3995 w = text_start_x + text_width - cur_x - 1;
3998 if (draw_graph_borders) {
3999 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
4000 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
4002 XSetLineAttributes(display,
4009 int gradient_size = 0;
4010 float gradient_factor = 0;
4011 float gradient_update = 0;
4012 unsigned long tmpcolour = current_color;
4013 if (specials[special_index].last_colour != specials[special_index].first_colour) {
4014 tmpcolour = specials[special_index].last_colour;
4015 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
4016 gradient_factor = (float)gradient_size / (w - 3);
4018 for (i = w - 3; i > 0; i--) {
4019 if (specials[special_index].last_colour != specials[special_index].first_colour) {
4020 XSetForeground(display, window.gc, tmpcolour);
4021 gradient_update += gradient_factor;
4022 while (gradient_update > 0) {
4023 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
4027 if ((w - 3 - i) / ((float) (w - 3) / (specials[special_index].graph_width)) > j) {
4030 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 */
4032 if (specials[special_index].
4034 && specials[special_index].
4038 [special_index].height;
4041 if (draw_mode == BG) {
4042 set_foreground_color(default_bg_color);
4044 else if (draw_mode == OUTLINE) {
4045 set_foreground_color(default_out_color);
4047 set_foreground_color(default_fg_color);
4053 cur_y -= font_ascent();
4054 selected_font = specials[special_index].font_added;
4055 cur_y += font_ascent();
4057 if (!use_xft || use_xdbe)
4065 if (draw_mode == FG)
4066 set_foreground_color(specials
4072 if (draw_mode == BG)
4073 set_foreground_color(specials
4079 if (draw_mode == OUTLINE)
4080 set_foreground_color(specials
4087 w += specials[special_index].arg;
4092 cur_y += specials[special_index].arg;
4098 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
4099 /*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);*/
4100 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
4101 cur_x = pos_x - specials[special_index].arg;
4108 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
4109 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
4110 /*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);*/
4112 specials[special_index].arg)
4115 [special_index].arg;
4132 if (cur_y_add > 0) {
4134 cur_y -= font_descent();
4139 cur_y += font_descent();
4146 static void draw_text()
4149 cur_y = text_start_y;
4152 if (draw_borders && border_width > 0) {
4153 unsigned int b = (border_width + 1) / 2;
4155 if (stippled_borders) {
4157 { stippled_borders, stippled_borders };
4158 XSetLineAttributes(display, window.gc,
4159 border_width, LineOnOffDash,
4160 CapButt, JoinMiter);
4161 XSetDashes(display, window.gc, 0, ss, 2);
4163 XSetLineAttributes(display, window.gc,
4164 border_width, LineSolid,
4165 CapButt, JoinMiter);
4168 XDrawRectangle(display, window.drawable, window.gc,
4169 text_start_x - border_margin + b,
4170 text_start_y - border_margin + b,
4171 text_width + border_margin * 2 - 1 - b * 2,
4172 text_height + border_margin * 2 - 1 -
4179 for_each_line(text_buffer, draw_line);
4182 static void draw_stuff()
4185 if (draw_shades && !draw_outline) {
4188 set_foreground_color(default_bg_color);
4197 for (i = -1; i < 2; i++)
4198 for (j = -1; j < 2; j++) {
4199 if (i == 0 && j == 0)
4203 set_foreground_color(default_out_color);
4204 draw_mode = OUTLINE;
4211 set_foreground_color(default_fg_color);
4219 swap.swap_window = window.window;
4220 swap.swap_action = XdbeBackground;
4221 XdbeSwapBuffers(display, &swap, 1);
4227 static void clear_text(int exposures)
4231 return; /* The swap action is XdbeBackground, which clears */
4235 /* there is some extra space for borders and outlines */
4236 XClearArea(display, window.drawable,
4237 text_start_x - border_margin - 1,
4238 text_start_y - border_margin - 1,
4239 text_width + border_margin * 2 + 2,
4240 text_height + border_margin * 2 + 2,
4241 exposures ? True : 0);
4246 static int need_to_update;
4248 /* update_text() generates new text and clears old text area */
4249 static void update_text()
4258 static void main_loop()
4260 #ifdef SIGNAL_BLOCKING
4261 sigset_t newmask, oldmask;
4263 sigemptyset(&newmask);
4264 sigaddset(&newmask,SIGINT);
4265 sigaddset(&newmask,SIGTERM);
4266 sigaddset(&newmask,SIGUSR1);
4270 Region region = XCreateRegion();
4274 while (total_run_times == 0 || info.looped < total_run_times - 1) {
4277 #ifdef SIGNAL_BLOCKING
4278 /* block signals. we will inspect for pending signals later */
4279 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
4280 CRIT_ERR("unable to sigprocmask()");
4286 /* wait for X event or timeout */
4288 if (!XPending(display)) {
4293 update_interval - (get_time() -
4299 tv.tv_sec = (long) t;
4300 tv.tv_usec = (long) (t * 1000000) % 1000000;
4302 FD_SET(ConnectionNumber(display), &fdsr);
4305 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
4308 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
4313 ERR("can't select(): %s",
4324 set_transparent_background(window.window);
4329 if (need_to_update) {
4331 int wx = window.x, wy = window.y;
4339 /* resize window if it isn't right size */
4341 (text_width + border_margin * 2 !=
4343 || text_height + border_margin * 2 !=
4347 border_margin * 2 + 1;
4350 border_margin * 2 + 1;
4351 XResizeWindow(display,
4357 /* move window if it isn't in right position */
4360 || window.y != wy)) {
4361 XMoveWindow(display, window.window,
4362 window.x, window.y);
4372 r.x = text_start_x - border_margin;
4373 r.y = text_start_y - border_margin;
4374 r.width = text_width + border_margin * 2;
4375 r.height = text_height + border_margin * 2;
4376 XUnionRectWithRegion(&r, region, region);
4381 /* handle X events */
4383 while (XPending(display)) {
4385 XNextEvent(display, &ev);
4392 r.width = ev.xexpose.width;
4393 r.height = ev.xexpose.height;
4394 XUnionRectWithRegion(&r, region,
4400 case ReparentNotify:
4401 /* set background to ParentRelative for all parents */
4403 set_transparent_background(window.
4408 case ConfigureNotify:
4410 /* if window size isn't what expected, set fixed size */
4411 if (ev.xconfigure.width !=
4413 || ev.xconfigure.height !=
4415 if (window.width != 0
4416 && window.height != 0)
4419 /* clear old stuff before screwing up size and pos */
4425 if (XGetWindowAttributes(display, window.window, &attrs)) {
4440 border_margin * 2 - 1;
4443 border_margin * 2 - 1;
4444 if (text_width > maximum_width && maximum_width > 0)
4445 text_width = maximum_width;
4448 /* if position isn't what expected, set fixed pos, total_updates
4449 * avoids setting fixed_pos when window is set to weird locations
4451 /*if (total_updates >= 2 this is broken
4453 && (window.x != ev.xconfigure.x
4456 && (ev.xconfigure.x != 0
4457 || ev.xconfigure.y != 0)) {
4470 /* XDBE doesn't seem to provide a way to clear the back buffer without
4471 * interfering with the front buffer, other than passing XdbeBackground
4472 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
4473 * redraw the text even if it wasn't part of the exposed area. OTOH,
4474 * if we're not going to call draw_stuff at all, then no swap happens
4475 * and we can safely do nothing.
4478 if (!XEmptyRegion(region)) {
4482 r.x = text_start_x - border_margin;
4483 r.y = text_start_y - border_margin;
4484 r.width = text_width + border_margin * 2;
4485 r.height = text_height + border_margin * 2;
4486 XUnionRectWithRegion(&r, region, region);
4489 XSetRegion(display, window.gc, region);
4492 XftDrawSetClip(window.xftdraw, region);
4498 XDestroyRegion(region);
4499 region = XCreateRegion();
4503 #ifdef SIGNAL_BLOCKING
4504 /* unblock signals of interest and let handler fly */
4505 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
4506 CRIT_ERR("unable to sigprocmask()");
4509 switch(g_signal_pending) {
4512 ERR("received SIGUSR1. reloading the config file.");
4519 ERR("received SIGINT or SIGTERM to terminate. bye!");
4522 XDestroyRegion(region);
4525 return; /* return from main_loop */
4530 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
4531 * but didn't write any code to deal with it. if you don't want to
4532 * handle a signal, don't set a handler on it in the first place. */
4533 if (g_signal_pending)
4534 ERR("ignoring signal (%d)", g_signal_pending);
4542 XDestroyRegion(region);
4547 static void load_config_file(const char *);
4549 /* reload the config file */
4550 void reload_config(void)
4552 if (current_config) {
4554 load_config_file(current_config);
4558 XClearWindow(display, RootWindow(display, screen)); // clear the window first
4561 #ifdef TCP_PORT_MONITOR
4562 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
4563 info.p_tcp_port_monitor_collection = NULL;
4565 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
4566 if (info.xmms.thread) {
4567 if (destroy_xmms_thread()!=0)
4569 ERR("error destroying xmms_player thread");
4572 if ( (!info.xmms.thread) && (info.xmms.current_project > PROJECT_NONE) &&
4573 (create_xmms_thread() !=0) )
4575 CRIT_ERR("unable to create xmms_player thread!");
4578 extract_variable_text(text);
4590 XdbeDeallocateBackBufferName(display, window.back_buffer);
4595 XDestroyWindow(display, window.window);
4599 XClearWindow(display, RootWindow(display, screen));
4604 XFreeGC(display, window.gc);
4608 /* it is really pointless to free() memory at the end of program but ak|ra
4609 * wants me to do this */
4611 free_text_objects(text_object_count, text_objects);
4612 text_object_count = 0;
4613 text_objects = NULL;
4617 #endif /* MLDONKEY */
4619 if (text != original_text)
4622 free(current_config);
4623 free(current_mail_spool);
4627 #ifdef TCP_PORT_MONITOR
4628 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
4629 info.p_tcp_port_monitor_collection = NULL;
4631 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
4632 if ( info.xmms.thread && (destroy_xmms_thread()!=0) )
4634 ERR("error destroying xmms_player thread");
4639 static int string_to_bool(const char *s)
4643 if (strcasecmp(s, "yes") == 0)
4645 if (strcasecmp(s, "true") == 0)
4647 if (strcasecmp(s, "1") == 0)
4652 static enum alignment string_to_alignment(const char *s)
4654 if (strcasecmp(s, "top_left") == 0)
4656 else if (strcasecmp(s, "top_right") == 0)
4658 else if (strcasecmp(s, "bottom_left") == 0)
4660 else if (strcasecmp(s, "bottom_right") == 0)
4661 return BOTTOM_RIGHT;
4662 else if (strcasecmp(s, "tl") == 0)
4664 else if (strcasecmp(s, "tr") == 0)
4666 else if (strcasecmp(s, "bl") == 0)
4668 else if (strcasecmp(s, "br") == 0)
4669 return BOTTOM_RIGHT;
4670 else if (strcasecmp(s, "none") == 0)
4677 static void set_default_configurations(void)
4679 fork_to_background = 0;
4680 total_run_times = 0;
4681 info.cpu_avg_samples = 2;
4682 info.net_avg_samples = 2;
4687 strcpy(info.mpd.host, "localhost");
4688 info.mpd.port = 6600;
4689 info.mpd.status = "Checking status...";
4698 default_fg_color = WhitePixel(display, screen);
4699 default_bg_color = BlackPixel(display, screen);
4700 default_out_color = BlackPixel(display, screen);
4703 draw_graph_borders = 1;
4705 set_first_font("6x10");
4713 strcpy(wm_class_name, "conky");
4715 stippled_borders = 0;
4718 text_alignment = BOTTOM_LEFT;
4722 free(current_mail_spool);
4725 variable_substitute(MAIL_FILE, buf, 256);
4727 current_mail_spool = strdup(buf);
4731 update_interval = 10.0;
4732 stuff_in_upper_case = 0;
4734 mlconfig.mldonkey_hostname = strdup("127.0.0.1");
4735 mlconfig.mldonkey_port = 4001;
4736 mlconfig.mldonkey_login = NULL;
4737 mlconfig.mldonkey_password = NULL;
4740 #ifdef TCP_PORT_MONITOR
4741 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
4742 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
4745 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
4746 info.xmms.current_project=PROJECT_NONE;
4750 static void load_config_file(const char *f)
4752 #define CONF_ERR ERR("%s: %d: config file error", f, line)
4756 set_default_configurations();
4762 char buf[256], *p, *p2, *name, *value;
4764 if (fgets(buf, 256, fp) == NULL)
4769 /* break at comment */
4770 p2 = strchr(p, '#');
4775 while (*p && isspace((int) *p))
4778 continue; /* empty line */
4784 while (*p2 && !isspace((int) *p2))
4787 *p2 = '\0'; /* break at name's end */
4794 while (*p && isspace((int) *p))
4799 p2 = value + strlen(value);
4800 while (isspace((int) *(p2 - 1)))
4806 #define CONF2(a) if (strcasecmp(name, a) == 0)
4807 #define CONF(a) else CONF2(a)
4808 #define CONF3(a,b) \
4809 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
4813 CONF2("alignment") {
4815 int a = string_to_alignment(value);
4825 on_bottom = string_to_bool(value);
4829 CONF("background") {
4830 fork_to_background = string_to_bool(value);
4834 CONF2("background") {
4835 fork_to_background = string_to_bool(value);
4839 CONF("border_margin") {
4841 border_margin = strtol(value, 0, 0);
4845 CONF("border_width") {
4847 border_width = strtol(value, 0, 0);
4851 CONF("default_color") {
4853 default_fg_color = get_x11_color(value);
4857 CONF3("default_shade_color", "default_shadecolor") {
4859 default_bg_color = get_x11_color(value);
4863 CONF3("default_outline_color", "default_outlinecolor") {
4865 default_out_color = get_x11_color(value);
4870 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
4871 CONF("xmms_player") {
4873 if (strncmp(value,"none",4)==0)
4874 info.xmms.current_project=PROJECT_NONE;
4875 else if (strncmp(value,"xmms",4)==0)
4876 info.xmms.current_project=PROJECT_XMMS;
4877 else if (strncmp(value,"bmp",3)==0)
4878 info.xmms.current_project=PROJECT_BMP;
4879 else if (strncmp(value,"audacious",9)==0)
4880 info.xmms.current_project=PROJECT_AUDACIOUS;
4881 else if (strncmp(value,"infopipe",8)==0)
4882 info.xmms.current_project=PROJECT_INFOPIPE;
4893 strcpy(info.mpd.host, value);
4899 info.mpd.port = strtol(value, 0, 0);
4900 if (info.mpd.port < 1
4901 || info.mpd.port > 0xffff)
4906 CONF("cpu_avg_samples") {
4908 cpu_avg_samples = strtol(value, 0, 0);
4909 if (cpu_avg_samples < 1
4910 || cpu_avg_samples > 14)
4919 CONF("net_avg_samples") {
4921 net_avg_samples = strtol(value, 0, 0);
4922 if (net_avg_samples < 1
4923 || net_avg_samples > 14)
4939 CONF("double_buffer") {
4940 use_xdbe = string_to_bool(value);
4944 CONF("override_utf8_locale") {
4945 utf8_mode = string_to_bool(value);
4948 CONF("draw_borders") {
4949 draw_borders = string_to_bool(value);
4951 CONF("draw_graph_borders") {
4952 draw_graph_borders = string_to_bool(value);
4954 CONF("draw_shades") {
4955 draw_shades = string_to_bool(value);
4957 CONF("draw_outline") {
4958 draw_outline = string_to_bool(value);
4961 CONF("out_to_console") {
4962 out_to_console = string_to_bool(value);
4964 CONF("use_spacer") {
4965 use_spacer = string_to_bool(value);
4970 use_xft = string_to_bool(value);
4974 set_first_font(value);
4979 if (value && font_count >= 0)
4980 fonts[0].font_alpha = atof(value)
4989 if (string_to_bool(value))
4990 ERR("Xft not enabled");
4993 /* xftfont silently ignored when no Xft */
4996 /* xftalpha is silently ignored when no Xft */
5001 set_first_font(value);
5010 gap_x = atoi(value);
5016 gap_y = atoi(value);
5021 CONF("mail_spool") {
5024 variable_substitute(value, buf, 256);
5028 if (current_mail_spool)
5029 free(current_mail_spool);
5030 current_mail_spool = strdup(buf);
5036 CONF("minimum_size") {
5039 (value, "%d %d", &minimum_width,
5040 &minimum_height) != 2)
5043 &minimum_width) != 1)
5048 CONF("maximum_width") {
5050 if (sscanf(value, "%d", &maximum_width) != 1)
5056 CONF("no_buffers") {
5057 no_buffers = string_to_bool(value);
5060 CONF("mldonkey_hostname") {
5062 if (mlconfig.mldonkey_hostname != NULL) {
5063 free(mlconfig.mldonkey_hostname);
5065 mlconfig.mldonkey_hostname = strdup(value);
5070 CONF("mldonkey_port") {
5072 mlconfig.mldonkey_port = atoi(value);
5076 CONF("mldonkey_login") {
5078 if (mlconfig.mldonkey_login != NULL) {
5079 free(mlconfig.mldonkey_login);
5081 mlconfig.mldonkey_login = strdup(value);
5086 CONF("mldonkey_password") {
5088 if (mlconfig.mldonkey_password != NULL) {
5089 free(mlconfig.mldonkey_password);
5091 mlconfig.mldonkey_password = strdup(value);
5097 CONF("pad_percents") {
5098 pad_percents = atoi(value);
5102 CONF("own_window") {
5103 own_window = string_to_bool(value);
5105 CONF("wm_class_name") {
5106 strncpy(wm_class_name, value, sizeof(wm_class_name)-1);
5107 wm_class_name[sizeof(wm_class_name)-1] = 0;
5109 CONF("own_window_transparent") {
5110 set_transparent = string_to_bool(value);
5112 CONF("own_window_colour") {
5113 background_colour = get_x11_color(value);
5116 CONF("stippled_borders") {
5118 stippled_borders = strtol(value, 0, 0);
5120 stippled_borders = 4;
5124 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
5127 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
5129 CONF("update_interval") {
5131 update_interval = strtod(value, 0);
5135 CONF("total_run_times") {
5137 total_run_times = strtod(value, 0);
5142 stuff_in_upper_case = string_to_bool(value);
5147 malloc(strlen(value)
5149 strcpy(seti_dir, value);
5153 if (text != original_text)
5163 int l = strlen(text);
5164 if (fgets(buf, 256, fp) == NULL)
5167 realloc(text, l + strlen(buf)
5171 if (strlen(text) > 1024 * 8)
5177 #ifdef TCP_PORT_MONITOR
5178 CONF("min_port_monitors")
5181 (sscanf(value, "%d", &tcp_port_monitor_collection_args.min_port_monitors) != 1) ||
5182 tcp_port_monitor_collection_args.min_port_monitors < 0 )
5184 /* an error. use default, warn and continue. */
5185 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
5188 else if ( tcp_port_monitor_collection_args.min_port_monitors == 0 )
5190 /* no error, just use default */
5191 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
5193 /* else tcp_port_monitor_collection_args.min_port_monitors > 0 as per config */
5195 CONF("min_port_monitor_connections")
5198 (sscanf(value, "%d", &tcp_port_monitor_args.min_port_monitor_connections) != 1)
5199 || tcp_port_monitor_args.min_port_monitor_connections < 0 )
5201 /* an error. use default, warni and continue. */
5202 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
5205 else if ( tcp_port_monitor_args.min_port_monitor_connections == 0 )
5207 /* no error, just use default */
5208 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
5210 /* else tcp_port_monitor_args.min_port_monitor_connections > 0 as per config */
5214 ERR("%s: %d: no such configuration: '%s'", f, line, name);
5224 /* : means that character before that takes an argument */
5225 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
5238 int main(int argc, char **argv)
5240 struct sigaction act, oact;
5243 memset(&info, 0, sizeof(info) );
5245 #ifdef TCP_PORT_MONITOR
5246 tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
5247 tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
5251 SET_XMMS_PROJECT_AVAILABLE(info.xmms.project_mask, PROJECT_XMMS);
5254 SET_XMMS_PROJECT_AVAILABLE(info.xmms.project_mask, PROJECT_BMP);
5256 #if defined(AUDACIOUS)
5257 SET_XMMS_PROJECT_AVAILABLE(info.xmms.project_mask, PROJECT_AUDACIOUS);
5259 #if defined(INFOPIPE)
5260 SET_XMMS_PROJECT_AVAILABLE(info.xmms.project_mask, PROJECT_INFOPIPE);
5263 /* handle command line parameters that don't change configs */
5269 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
5270 *s) || ((s = getenv("LANG")) && *s)) {
5272 for(x = 0; x < strlen(s) ; x++) {
5273 temp[x] = tolower(s[x]);
5275 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
5279 if (!setlocale(LC_CTYPE, "")) {
5280 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
5284 int c = getopt(argc,
5294 ("Conky " VERSION " compiled " __DATE__ "\n");
5298 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
5299 * though free() does the NULL check itself;), then load optarg value */
5301 free(current_config);
5302 current_config = strdup(optarg);
5307 ("Usage: %s [OPTION]...\n"
5308 "Conky is a system monitor that renders text on desktop or to own transparent\n"
5309 "window. Command line options will override configurations defined in config\n"
5312 " -c FILE config file to load instead of "
5315 " -d daemonize, fork to background\n"
5318 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
5319 " -f FONT font to use\n"
5321 " -o create own window to draw\n"
5324 " -b double buffer (prevents flickering)\n"
5326 " -w WIN_ID window id to draw\n"
5327 " -x X x position\n"
5328 " -y Y y position\n"
5330 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
5331 " -u SECS update interval\n"
5332 " -i NUM number of times to update Conky\n", argv[0]);
5336 window.window = strtol(optarg, 0, 0);
5345 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
5349 /* load current_config or CONFIG_FILE */
5352 if (current_config == NULL) {
5353 /* load default config file */
5356 variable_substitute(CONFIG_FILE, buf, 256);
5359 current_config = strdup(buf);
5363 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
5364 load_config_file(current_config);
5366 set_default_configurations();
5370 if (current_mail_spool == NULL) {
5372 variable_substitute(MAIL_FILE, buf, 256);
5375 current_mail_spool = strdup(buf);
5379 /* handle other command line arguments */
5381 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
5382 optind = optreset = 1;
5388 int c = getopt(argc,
5396 fork_to_background = 1;
5401 set_first_font(optarg);
5404 text_alignment = string_to_alignment(optarg);
5419 if (text != original_text)
5421 text = strdup(optarg);
5422 convert_escapes(text);
5426 update_interval = strtod(optarg, 0);
5430 total_run_times = strtod(optarg, 0);
5434 gap_x = atoi(optarg);
5438 gap_y = atoi(optarg);
5452 /* generate text and get initial size */
5453 extract_variable_text(text);
5454 if (text != original_text) {
5463 update_text_area(); /* to get initial size of the window */
5465 #if defined OWN_WINDOW
5469 text_width + border_margin * 2 + 1,
5470 text_height + border_margin * 2 + 1,
5471 on_bottom, fixed_pos, set_transparent, background_colour, info.uname_s.nodename);
5475 text_width + border_margin * 2 + 1,
5476 text_height + border_margin * 2 + 1,
5477 on_bottom, set_transparent, background_colour, info.uname_s.nodename);
5481 update_text_area(); /* to position text/window on screen */
5485 // why the fuck not?
5491 if (own_window && !fixed_pos) {
5492 XMoveWindow(display, window.window, window.x, window.y);
5495 set_transparent_background(window.window);
5506 if (fork_to_background) {
5510 ERR("can't fork() to background: %s",
5520 "Conky: forked to background, pid is %d\n",
5526 /* Set signal handlers */
5527 act.sa_handler = signal_handler;
5528 sigemptyset(&act.sa_mask);
5531 act.sa_flags |= SA_RESTART;
5534 if ( sigaction(SIGINT,&act,&oact) < 0 ||
5535 sigaction(SIGUSR1,&act,&oact) < 0 ||
5536 sigaction(SIGTERM,&act,&oact) < 0 )
5538 ERR("error setting signal handler: %s", strerror(errno) );
5541 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
5542 if ( (info.xmms.current_project > PROJECT_NONE) && (create_xmms_thread() !=0) )
5544 CRIT_ERR("unable to create xmms_player thread!");
5550 #if defined(XMMS) || defined(BMP) || defined(AUDACIOUS) || defined(INFOPIPE)
5551 if ( info.xmms.thread && (destroy_xmms_thread()!=0) )
5553 ERR("error destroying xmms_player thread");
5560 void signal_handler(int sig)
5562 /* signal handler is light as a feather, as it should be.
5563 * we will poll g_signal_pending with each loop of conky
5564 * and do any signal processing there, NOT here. pkovacs. */
5565 g_signal_pending=sig;