2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
26 #include <X11/Xutil.h>
28 #include <X11/extensions/Xdamage.h>
34 #include <sys/types.h>
36 #include <netinet/in.h>
46 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
49 #define CONFIG_FILE "$HOME/.conkyrc"
50 #define MAIL_FILE "$MAIL"
51 #define MAX_IF_BLOCK_DEPTH 5
53 /* #define SIGNAL_BLOCKING */
54 #undef SIGNAL_BLOCKING
56 static void print_version()
58 printf("Conky %s compiled %s for %s\n",
59 VERSION, BUILD_DATE, BUILD_ARCH);
62 "\nCompiled in features:\n\n"
66 " * Xdamage extension\n"
67 # endif /* HAVE_XDAMAGE */
69 " * Xdbe extension (double buffer)\n"
70 # endif /* HAVE_XDBE */
76 "\n Music detection:\n"
79 #endif /* AUDACIOUS */
89 "\n General features:\n"
93 #ifdef TCP_PORT_MONITOR
95 #endif /* TCP_PORT_MONITOR */
110 static int text_start_x, text_start_y; /* text start position in window */
111 static int text_width, text_height;
126 char name[TEXT_BUFFER_SIZE];
136 static int selected_font = 0;
137 static int font_count = -1;
138 struct font_list *fonts = NULL;
142 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
143 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent))
144 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent)
145 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent)
149 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
150 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
151 #define font_descent() fonts[selected_font].font->max_bounds.descent
155 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
158 static void set_font();
160 int addfont(const char *data_in)
162 if (font_count > MAX_FONTS) {
163 CRIT_ERR("you don't need that many fonts, sorry.");
166 if (font_count == 0) {
170 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
174 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
176 CRIT_ERR("realloc in addfont");
178 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
179 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
181 fonts[font_count].font_alpha = 0xffff;
184 CRIT_ERR("Oops...looks like something overflowed in addfont().");
189 void set_first_font(const char *data_in)
191 if (font_count < 0) {
192 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
197 if (strlen(data_in) > 1) {
198 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
200 fonts[0].font_alpha = 0xffff;
208 for (i=0;i<=font_count;i++) {
211 XftFontClose(display, fonts[i].xftfont);
215 XFreeFont(display, fonts[i].font);
222 set_first_font("6x10");
226 static void load_fonts()
229 for (i=0; i <= font_count; i++) {
233 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
234 XftFontClose(display, fonts[i].xftfont);
236 if ((fonts[i].xftfont =
237 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
240 ERR("can't load Xft font '%s'", fonts[i].name);
241 if ((fonts[i].xftfont =
242 XftFontOpenName(display, screen,
243 "courier-12")) != NULL)
246 ERR("can't load Xft font '%s'", "courier-12");
248 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
249 CRIT_ERR("can't load font '%s'", "fixed");
256 /* load normal font */
257 /* if (fonts[i].font != NULL)
258 XFreeFont(display, fonts[i].font);*/
260 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
261 ERR("can't load font '%s'", fonts[i].name);
262 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
263 CRIT_ERR("can't load font '%s'", "fixed");
264 printf("loaded fixed?\n");
272 /* default config file */
273 static char *current_config;
275 /* set to 1 if you want all text to be in uppercase */
276 static unsigned int stuff_in_upper_case;
278 /* Run how many times? */
279 static unsigned long total_run_times;
282 static int fork_to_background;
284 static int cpu_avg_samples, net_avg_samples;
288 /* Position on the screen */
289 static int text_alignment;
290 static int gap_x, gap_y;
293 static int draw_borders;
294 static int draw_graph_borders;
295 static int stippled_borders;
297 static int draw_shades, draw_outline;
299 static int border_margin, border_width;
301 static long default_fg_color, default_bg_color, default_out_color;
303 /* create own window or draw stuff to root? */
304 static int set_transparent = 0;
308 static int own_window = 0;
309 static int background_colour = 0;
310 /* fixed size/pos is set if wm/user changes them */
311 static int fixed_size = 0, fixed_pos = 0;
314 static int minimum_width, minimum_height;
315 static int maximum_width;
319 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
320 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
322 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
323 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
325 /* maximum size of individual text buffers, ie $exec buffer size */
326 unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
329 #define CODEPAGE_LENGTH 20
332 char iconv_converting;
333 static iconv_t **iconv_cd = 0;
335 int register_iconv(iconv_t *new_iconv)
338 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
340 iconv_cd = malloc(sizeof(iconv_t *));
343 CRIT_ERR("Out of memory");
345 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
346 if (!iconv_cd[iconv_count]) {
347 CRIT_ERR("Out of memory");
349 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
354 void free_iconv(void)
358 for (i = iconv_count; i < 0; i++) {
374 /* no buffers in used memory? */
377 /* pad percentages to decimals? */
378 static int pad_percents = 0;
380 #ifdef TCP_PORT_MONITOR
381 tcp_port_monitor_args_t tcp_port_monitor_args;
384 #ifdef HAVE_LIBDEXTER
385 /* private config items for libdexter */
386 static char *dexter_config = NULL;
389 /* Text that is shown */
390 static char original_text[] =
391 "$nodename - $sysname $kernel on $machine\n"
393 "${color grey}Uptime:$color $uptime\n"
394 "${color grey}Frequency (in MHz):$color $freq\n"
395 "${color grey}Frequency (in GHz):$color $freq_g\n"
396 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
397 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
398 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
399 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
401 "${color grey}File systems:\n"
402 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
403 "${color grey}Networking:\n"
404 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
407 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
408 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
411 "${color grey}XMMS2: $xmms2_status $xmms2_artist - $xmms2_title from $xmms2_album\n"
412 "Progress: $xmms2_bar\n"
414 "${color grey}Name PID CPU% MEM%\n"
415 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
416 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
417 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
418 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
419 "${tail /var/log/Xorg.0.log 3}";
421 static char *text = original_text;
424 static int total_updates;
427 static int blockdepth = 0;
428 static int if_jumped = 0;
429 static int blockstart[MAX_IF_BLOCK_DEPTH];
431 int check_mount(char *s)
433 #if defined(__linux__)
435 FILE *mtab = fopen("/etc/mtab", "r");
437 char buf1[256], buf2[128];
438 while (fgets(buf1, 256, mtab)) {
439 sscanf(buf1, "%*s %128s", buf2);
440 if (!strcmp(s, buf2)) {
447 ERR("Could not open mtab");
450 #elif defined(__FreeBSD__)
451 struct statfs *mntbuf;
454 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
455 for (i = mntsize - 1; i >= 0; i--)
456 if (strcmp(mntbuf[i].f_mntonname, s) == 0)
465 static inline int calc_text_width(const char *s, int l)
471 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
473 XftTextExtents8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
479 return XTextWidth(fonts[selected_font].font, s, l);
484 /* formatted text to render on screen, generated in generate_text(),
485 * drawn in draw_stuff() */
487 static char text_buffer[TEXT_BUFFER_SIZE * 4];
489 /* special stuff in text_buffer */
491 #define SPECIAL_CHAR '\x01'
520 unsigned long first_colour; // for graph gradient
521 unsigned long last_colour;
524 /* create specials array on heap instead of stack with introduction of max_specials */
525 static struct special_t *specials = NULL;
527 static unsigned int special_count;
529 static unsigned int special_index; /* used when drawing */
532 #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? */
534 static struct special_t *new_special(char *buf, int t)
536 if (special_count >= max_specials)
537 CRIT_ERR("too many special things in text");
539 buf[0] = SPECIAL_CHAR;
541 specials[special_count].type = t;
542 return &specials[special_count++];
545 long fwd_fcharfind(FILE* fp, char val, unsigned int step) {
548 unsigned int count = 0;
549 static char buf[BUFSZ];
550 long orig_pos = ftell(fp);
552 long buf_size = BUFSZ;
553 char* cur_found = NULL;
554 while(count < step) {
555 if(cur_found == NULL) {
556 buf_size = fread(buf, 1, buf_size, fp);
559 cur_found = memchr(buf+buf_pos, val, buf_size-buf_pos);
560 if(cur_found != NULL) {
561 buf_pos = cur_found-buf+1;
570 ret = ftell(fp) - buf_size + buf_pos - 1;
571 fseek(fp, orig_pos, SEEK_SET);
576 long rev_fcharfind(FILE* fp, char val, unsigned int step) {
579 unsigned int count = 0;
580 static char buf[BUFSZ];
581 long orig_pos = ftell(fp);
583 long file_pos = orig_pos;
584 long buf_size = BUFSZ;
586 while(count < step) {
588 if(file_pos > BUFSZ) {
589 fseek(fp, file_pos-BUFSZ, SEEK_SET);
593 fseek(fp, 0, SEEK_SET);
595 file_pos = ftell(fp);
596 buf_pos = fread(buf, 1, buf_size, fp);
603 if(cur_found != NULL) {
604 buf_pos = cur_found-buf;
613 fseek(fp, orig_pos, SEEK_SET);
615 ret = file_pos + buf_pos;
620 static void new_bar(char *buf, int w, int h, int usage)
622 struct special_t *s = new_special(buf, BAR);
623 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
628 static const char *scan_bar(const char *args, int *w, int *h)
630 *w = 0; /* zero width means all space that is available */
632 /* bar's argument is either height or height,width */
635 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
636 sscanf(args, "%d %n", h, &n);
643 static char *scan_font(const char *args)
645 if (args && sizeof(args) < 127) {
652 static void new_font(char *buf, char * args) {
654 struct special_t *s = new_special(buf, FONT);
655 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
656 int tmp = selected_font;
657 selected_font = s->font_added = addfont(args);
662 struct special_t *s = new_special(buf, FONT);
663 int tmp = selected_font;
664 selected_font = s->font_added = 0;
671 inline void graph_append(struct special_t *graph, double f)
673 if (!graph->scaled && f > graph->graph_scale) {
674 f = graph->graph_scale;
678 graph->graph_scale = 1;
680 graph->graph[0] = f; /* add new data */
681 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
682 graph->graph[i] = graph->graph[i - 1];
683 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
684 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
689 short colour_depth = 0;
690 void set_up_gradient();
692 /* precalculated: 31/255, and 63/255 */
693 #define CONST_8_TO_5_BITS 0.12156862745098
694 #define CONST_8_TO_6_BITS 0.247058823529412
696 /* adjust color values depending on color depth*/
697 static unsigned int adjust_colors(unsigned int color)
700 if (colour_depth == 0) {
703 if (colour_depth == 16) {
704 r = (color & 0xff0000) >> 16;
705 g = (color & 0xff00) >> 8;
707 color = (int)(r * CONST_8_TO_5_BITS) << 11;
708 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
709 color |= (int)(b * CONST_8_TO_5_BITS);
714 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
716 struct special_t *s = new_special(buf, GRAPH);
718 if (s->graph == NULL) {
719 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
720 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
722 s->graph_width = MAX_GRAPH_DEPTH - 2;
724 s->graph = malloc(s->graph_width * sizeof(double));
725 memset(s->graph, 0, s->graph_width * sizeof(double));
726 s->graph_scale = 100;
729 s->first_colour = adjust_colors(first_colour);
730 s->last_colour = adjust_colors(second_colour);
737 s->graph_width = s->width - 2; // subtract 2 for rectangle around
742 s->graph_scale = scale;
749 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
751 *w = 0; /* zero width means all space that is available */
755 /* graph's argument is either height or height,width */
757 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
758 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
760 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
762 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
765 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
769 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
772 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
776 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
779 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
783 if (sscanf(args, "%d,%d", h, w) < 2) {
786 sscanf(args, "%*s %d,%d", h, w);
792 static inline void new_hr(char *buf, int a)
794 new_special(buf, HORIZONTAL_LINE)->height = a;
797 static inline void new_stippled_hr(char *buf, int a, int b)
799 struct special_t *s = new_special(buf, STIPPLED_HR);
804 static inline void new_fg(char *buf, long c)
806 new_special(buf, FG)->arg = c;
809 static inline void new_bg(char *buf, long c)
811 new_special(buf, BG)->arg = c;
814 static inline void new_outline(char *buf, long c)
816 new_special(buf, OUTLINE)->arg = c;
819 static inline void new_offset(char *buf, long c)
821 new_special(buf, OFFSET)->arg = c;
824 static inline void new_voffset(char *buf, long c)
826 new_special(buf, VOFFSET)->arg = c;
829 static inline void new_alignr(char *buf, long c)
831 new_special(buf, ALIGNR)->arg = c;
834 static inline void new_alignc(char *buf, long c)
836 new_special(buf, ALIGNC)->arg = c;
839 static inline void new_goto(char *buf, long c)
841 new_special(buf, GOTO)->arg = c;
844 static inline void new_tab(char *buf, int a, int b) {
845 struct special_t *s = new_special(buf, TAB);
850 /* quite boring functions */
852 static inline void for_each_line(char *b, void (*f) (char *))
856 for (ps = b, pe = b; *pe; pe++) {
869 static void convert_escapes(char *buf)
871 char *p = buf, *s = buf;
887 /* converts from bytes to human readable format (k, M, G, T) */
888 static void human_readable(long long a, char *buf, int size)
890 // Strange conditional due to possible overflows
891 if(a / 1024 / 1024 / 1024.0 > 1024.0){
892 snprintf(buf, size, "%.2fTiB", (a / 1024 / 1024 / 1024) / 1024.0);
894 else if (a >= 1024 * 1024 * 1024) {
895 snprintf(buf, size, "%.2fGiB", (a / 1024 / 1024) / 1024.0);
897 else if (a >= 1024 * 1024) {
898 double m = (a / 1024) / 1024.0;
900 snprintf(buf, size, "%.0fMiB", m);
902 snprintf(buf, size, "%.1fMiB", m);
903 } else if (a >= 1024)
904 snprintf(buf, size, "%LdKiB", a / (long long) 1024);
906 snprintf(buf, size, "%LdB", a);
911 enum text_object_type {
933 OBJ_diskiograph_read,
934 OBJ_diskiograph_write,
967 #if defined(__linux__)
973 OBJ_i8k_left_fan_status,
974 OBJ_i8k_right_fan_status,
975 OBJ_i8k_left_fan_rpm,
976 OBJ_i8k_right_fan_rpm,
978 OBJ_i8k_buttons_status,
986 #endif /* __linux__ */
1014 OBJ_running_processes,
1023 OBJ_temp1, /* i2c is used instead in these */
1043 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
1045 OBJ_apm_battery_time,
1046 OBJ_apm_battery_life,
1047 #endif /* __FreeBSD__ */
1076 OBJ_xmms2_transport,
1091 OBJ_audacious_status,
1092 OBJ_audacious_title,
1093 OBJ_audacious_length,
1094 OBJ_audacious_length_seconds,
1095 OBJ_audacious_position,
1096 OBJ_audacious_position_seconds,
1097 OBJ_audacious_bitrate,
1098 OBJ_audacious_frequency,
1099 OBJ_audacious_channels,
1100 OBJ_audacious_filename,
1101 OBJ_audacious_playlist_length,
1102 OBJ_audacious_playlist_position,
1113 #ifdef TCP_PORT_MONITOR
1124 OBJ_entropy_poolsize,
1128 struct text_object {
1132 unsigned int c, d, e;
1136 char *s; /* some string */
1137 int i; /* some integer */
1138 long l; /* some other integer */
1139 unsigned int sensor;
1140 struct net_stat *net;
1142 unsigned char loadavg[3];
1143 unsigned int cpu_index;
1144 struct mail_s *mail;
1152 char *tz; /* timezone variable */
1153 char *fmt; /* time display formatting */
1203 timed_thread *p_timed_thread;
1209 #ifdef TCP_PORT_MONITOR
1211 in_port_t port_range_begin; /* starting port to monitor */
1212 in_port_t port_range_end; /* ending port to monitor */
1213 int item; /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1214 int connection_index; /* 0 to n-1 connections. */
1227 struct text_object_list {
1228 unsigned int text_object_count;
1229 struct text_object *text_objects;
1232 static unsigned int text_object_count;
1233 static struct text_object *text_objects;
1234 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1236 #define MAXDATASIZE 1000
1240 struct mail_s* parse_mail_args(char type, const char *arg) {
1241 struct mail_s *mail;
1242 mail = malloc(sizeof(struct mail_s));
1243 memset(mail, 0, sizeof(struct mail_s));
1245 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1247 ERR("Scanning IMAP args failed");
1248 } else if (type == IMAP) {
1249 ERR("Scanning POP3 args failed");
1252 // see if password needs prompting
1253 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1254 int fp = fileno(stdin);
1255 struct termios term;
1256 tcgetattr(fp, &term);
1257 term.c_lflag &= ~ECHO;
1258 tcsetattr(fp, TCSANOW, &term);
1259 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1260 scanf("%128s", mail->pass);
1262 term.c_lflag |= ECHO;
1263 tcsetattr(fp, TCSANOW, &term);
1265 // now we check for optional args
1266 tmp = strstr(arg, "-i ");
1269 sscanf(tmp, "%f", &mail->interval);
1271 mail->interval = 300; // 5 minutes
1273 tmp = strstr(arg, "-p ");
1276 sscanf(tmp, "%lu", &mail->port);
1279 mail->port = 110; // default pop3 port
1280 } else if (type == IMAP) {
1281 mail->port = 143; // default imap port
1285 tmp = strstr(arg, "-f ");
1288 sscanf(tmp, "%s", mail->folder);
1290 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1293 tmp = strstr(arg, "-e ");
1297 if (tmp[0] == '\'') {
1298 len = strstr(tmp+1, "'") - tmp - 1;
1303 strncpy(mail->command, tmp+1, len);
1305 mail->command[0] = '\0';
1307 mail->p_timed_thread = NULL;
1311 void *imap_thread(struct mail_s* mail)
1313 int sockfd, numbytes;
1314 char recvbuf[MAXDATASIZE];
1315 char sendbuf[MAXDATASIZE];
1318 unsigned int old_unseen = UINT_MAX;
1319 unsigned int old_messages = UINT_MAX;
1320 struct stat stat_buf;
1322 struct sockaddr_in their_addr; // connector's address information
1323 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1324 herror("gethostbyname");
1329 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1331 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1334 goto next_iteration;
1337 their_addr.sin_family = AF_INET; // host byte order
1338 their_addr.sin_port = htons(mail->port); // short, network byte order
1339 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1340 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1343 (sockfd, (struct sockaddr *) &their_addr,
1344 sizeof(struct sockaddr)) == -1) {
1347 goto next_iteration;
1349 struct timeval timeout;
1352 timeout.tv_sec = 60; // 60 second timeout i guess
1353 timeout.tv_usec = 0;
1355 FD_SET(sockfd, &fdset);
1356 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1359 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1363 goto next_iteration;
1366 ERR("IMAP connection failed: timeout");
1368 goto next_iteration;
1370 recvbuf[numbytes] = '\0';
1371 if (strstr(recvbuf, "* OK") != recvbuf) {
1372 ERR("IMAP connection failed, probably not an IMAP server");
1374 goto next_iteration;
1376 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1377 strncat(sendbuf, mail->user,
1378 MAXDATASIZE - strlen(sendbuf) - 1);
1379 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1380 strncat(sendbuf, mail->pass,
1381 MAXDATASIZE - strlen(sendbuf) - 1);
1382 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1383 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1386 goto next_iteration;
1388 timeout.tv_sec = 60; // 60 second timeout i guess
1389 timeout.tv_usec = 0;
1391 FD_SET(sockfd, &fdset);
1392 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1395 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1399 goto next_iteration;
1402 recvbuf[numbytes] = '\0';
1403 if (strstr(recvbuf, "a1 OK") == NULL) {
1404 ERR("IMAP server login failed: %s", recvbuf);
1406 goto next_iteration;
1408 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1409 strncat(sendbuf, mail->folder,
1410 MAXDATASIZE - strlen(sendbuf) - 1);
1411 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1412 MAXDATASIZE - strlen(sendbuf) - 1);
1413 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1416 goto next_iteration;
1418 timeout.tv_sec = 60; // 60 second timeout i guess
1419 timeout.tv_usec = 0;
1421 FD_SET(sockfd, &fdset);
1422 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1425 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1429 goto next_iteration;
1432 recvbuf[numbytes] = '\0';
1433 if (strstr(recvbuf, "a2 OK") == NULL) {
1434 ERR("IMAP status failed: %s", recvbuf);
1436 goto next_iteration;
1438 // now we get the data
1439 reply = strstr(recvbuf, " (MESSAGES ");
1441 *strchr(reply, ')') = '\0';
1442 if (reply == NULL) {
1443 ERR("Error parsing IMAP response: %s", recvbuf);
1445 goto next_iteration;
1447 timed_thread_lock (mail->p_timed_thread);
1448 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1451 timed_thread_unlock (mail->p_timed_thread);
1453 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1454 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1457 goto next_iteration;
1459 timeout.tv_sec = 60; // 60 second timeout i guess
1460 timeout.tv_usec = 0;
1462 FD_SET(sockfd, &fdset);
1463 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1466 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1470 goto next_iteration;
1473 recvbuf[numbytes] = '\0';
1474 if (strstr(recvbuf, "a3 OK") == NULL) {
1475 ERR("IMAP logout failed: %s", recvbuf);
1477 goto next_iteration;
1479 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1480 if (system(mail->command) == -1) {
1485 old_unseen = mail->unseen;
1486 old_messages = mail->messages;
1488 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1489 /* if a valid socket, close it */
1491 if (timed_thread_test (mail->p_timed_thread))
1492 timed_thread_exit (mail->p_timed_thread);
1497 void *pop3_thread(struct mail_s *mail)
1499 int sockfd, numbytes;
1500 char recvbuf[MAXDATASIZE];
1501 char sendbuf[MAXDATASIZE];
1504 unsigned int old_unseen = UINT_MAX;
1505 struct stat stat_buf;
1507 struct sockaddr_in their_addr; // connector's address information
1508 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1509 herror("gethostbyname");
1514 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1516 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1519 goto next_iteration;
1522 their_addr.sin_family = AF_INET; // host byte order
1523 their_addr.sin_port = htons(mail->port); // short, network byte order
1524 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1525 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1528 (sockfd, (struct sockaddr *) &their_addr,
1529 sizeof(struct sockaddr)) == -1) {
1532 goto next_iteration;
1534 struct timeval timeout;
1537 timeout.tv_sec = 60; // 60 second timeout i guess
1538 timeout.tv_usec = 0;
1540 FD_SET(sockfd, &fdset);
1541 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1544 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1548 goto next_iteration;
1551 ERR("POP3 connection failed: timeout\n");
1553 goto next_iteration;
1555 recvbuf[numbytes] = '\0';
1556 if (strstr(recvbuf, "+OK ") != recvbuf) {
1557 ERR("POP3 connection failed, probably not a POP3 server");
1559 goto next_iteration;
1561 strncpy(sendbuf, "USER ", MAXDATASIZE);
1562 strncat(sendbuf, mail->user,
1563 MAXDATASIZE - strlen(sendbuf) - 1);
1564 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1565 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1566 perror("send USER");
1568 goto next_iteration;
1570 timeout.tv_sec = 60; // 60 second timeout i guess
1571 timeout.tv_usec = 0;
1573 FD_SET(sockfd, &fdset);
1574 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1577 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1579 perror("recv USER");
1581 goto next_iteration;
1584 recvbuf[numbytes] = '\0';
1585 if (strstr(recvbuf, "+OK ") == NULL) {
1586 ERR("POP3 server login failed: %s", recvbuf);
1588 goto next_iteration;
1590 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1591 strncat(sendbuf, mail->pass,
1592 MAXDATASIZE - strlen(sendbuf) - 1);
1593 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1594 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1595 perror("send PASS");
1597 goto next_iteration;
1599 timeout.tv_sec = 60; // 60 second timeout i guess
1600 timeout.tv_usec = 0;
1602 FD_SET(sockfd, &fdset);
1603 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1606 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1608 perror("recv PASS");
1610 goto next_iteration;
1613 recvbuf[numbytes] = '\0';
1614 if (strstr(recvbuf, "+OK ") == NULL) {
1615 ERR("POP3 server login failed: %s", recvbuf);
1617 goto next_iteration;
1619 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1620 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1621 perror("send STAT");
1623 goto next_iteration;
1625 timeout.tv_sec = 60; // 60 second timeout i guess
1626 timeout.tv_usec = 0;
1628 FD_SET(sockfd, &fdset);
1629 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1632 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1634 perror("recv STAT");
1636 goto next_iteration;
1639 recvbuf[numbytes] = '\0';
1640 if (strstr(recvbuf, "+OK ") == NULL) {
1641 ERR("POP3 status failed: %s", recvbuf);
1643 goto next_iteration;
1645 // now we get the data
1646 reply = recvbuf + 4;
1647 if (reply == NULL) {
1648 ERR("Error parsing POP3 response: %s", recvbuf);
1650 goto next_iteration;
1652 timed_thread_lock (mail->p_timed_thread);
1653 sscanf(reply, "%lu %lu", &mail->unseen,
1655 timed_thread_unlock (mail->p_timed_thread);
1657 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1658 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1659 perror("send QUIT");
1661 goto next_iteration;
1663 timeout.tv_sec = 60; // 60 second timeout i guess
1664 timeout.tv_usec = 0;
1666 FD_SET(sockfd, &fdset);
1667 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1670 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1672 perror("recv QUIT");
1674 goto next_iteration;
1677 recvbuf[numbytes] = '\0';
1678 if (strstr(recvbuf, "+OK") == NULL) {
1679 ERR("POP3 logout failed: %s", recvbuf);
1681 goto next_iteration;
1683 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1684 if (system(mail->command) == -1) {
1689 old_unseen = mail->unseen;
1691 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1692 /* if a valid socket, close it */
1694 if (timed_thread_test (mail->p_timed_thread))
1695 timed_thread_exit (mail->p_timed_thread);
1701 void *threaded_exec(struct text_object *obj) {
1703 char *p2 = obj->data.texeci.buffer;
1704 FILE *fp = popen(obj->data.texeci.cmd,"r");
1705 timed_thread_lock (obj->data.texeci.p_timed_thread);
1706 int n2 = fread(p2, 1, text_buffer_size, fp);
1709 if (n2 && p2[n2 - 1] == '\n') {
1713 if (*p2 == '\001') {
1718 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1719 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1720 timed_thread_exit (obj->data.texeci.p_timed_thread);
1725 static struct text_object *new_text_object_internal()
1727 struct text_object *obj = malloc(sizeof(struct text_object));
1728 memset(obj, 0, sizeof(struct text_object));
1732 static void free_text_objects(unsigned int count, struct text_object *objs)
1735 for (i = 0; i < count; i++) {
1736 switch (objs[i].type) {
1738 close(objs[i].data.i);
1741 close(objs[i].data.i);
1744 close(objs[i].data.i2c.fd);
1747 free(objs[i].data.s);
1750 free(objs[i].data.s);
1753 free(objs[i].data.tztime.tz);
1754 free(objs[i].data.tztime.fmt);
1757 free(objs[i].data.mboxscan.args);
1758 free(objs[i].data.mboxscan.output);
1763 case OBJ_imap_unseen:
1764 if (!objs[i].global_mode) {
1765 free(objs[i].data.mail);
1768 case OBJ_imap_messages:
1769 if (!objs[i].global_mode) {
1770 free(objs[i].data.mail);
1776 case OBJ_pop3_unseen:
1777 if (!objs[i].global_mode) {
1778 free(objs[i].data.mail);
1782 if (!objs[i].global_mode) {
1783 free(objs[i].data.mail);
1786 case OBJ_if_existing:
1787 case OBJ_if_mounted:
1788 case OBJ_if_running:
1789 free(objs[i].data.ifblock.s);
1792 free(objs[i].data.tail.logfile);
1793 free(objs[i].data.tail.buffer);
1795 case OBJ_text: case OBJ_font:
1796 free(objs[i].data.s);
1799 free(objs[i].data.s);
1802 free(objs[i].data.s);
1805 free(objs[i].data.s);
1808 free(objs[i].data.s);
1810 /* case OBJ_execibar:
1811 free(objs[i].data.s);
1813 case OBJ_execigraph:
1814 free(objs[i].data.s);
1817 case OBJ_iconv_start:
1823 if (info.mpd.title) {
1824 free(info.mpd.title);
1828 case OBJ_mpd_artist:
1829 if (info.mpd.artist) {
1830 free(info.mpd.artist);
1831 info.mpd.artist = 0;
1835 if (info.mpd.album) {
1836 free(info.mpd.album);
1840 case OBJ_mpd_random:
1841 if (info.mpd.random) {
1842 free(info.mpd.random);
1843 info.mpd.random = 0;
1846 case OBJ_mpd_repeat:
1847 if (info.mpd.repeat) {
1848 free(info.mpd.repeat);
1849 info.mpd.repeat = 0;
1853 if (info.mpd.track) {
1854 free(info.mpd.track);
1859 if (info.mpd.name) {
1860 free(info.mpd.name);
1865 if (info.mpd.file) {
1866 free(info.mpd.file);
1870 case OBJ_mpd_status:
1871 if (info.mpd.status) {
1872 free(info.mpd.status);
1873 info.mpd.status = 0;
1877 if (info.mpd.artist) {
1878 free(info.mpd.artist);
1879 info.mpd.artist = 0;
1881 if (info.mpd.title) {
1882 free(info.mpd.title);
1885 if (info.mpd.file) {
1886 free(info.mpd.file);
1893 case OBJ_xmms2_artist:
1894 if (info.xmms2.artist) {
1895 free(info.xmms2.artist);
1896 info.xmms2.artist = 0;
1899 case OBJ_xmms2_album:
1900 if (info.xmms2.album) {
1901 free(info.xmms2.album);
1902 info.xmms2.album = 0;
1905 case OBJ_xmms2_title:
1906 if (info.xmms2.title) {
1907 free(info.xmms2.title);
1908 info.xmms2.title = 0;
1911 case OBJ_xmms2_genre:
1912 if (info.xmms2.genre) {
1913 free(info.xmms2.genre);
1914 info.xmms2.genre = 0;
1917 case OBJ_xmms2_comment:
1918 if (info.xmms2.comment) {
1919 free(info.xmms2.comment);
1920 info.xmms2.comment = 0;
1923 case OBJ_xmms2_decoder:
1924 if (info.xmms2.decoder) {
1925 free(info.xmms2.decoder);
1929 case OBJ_xmms2_transport:
1930 if (info.xmms2.transport) {
1931 free(info.xmms2.transport);
1936 if (info.xmms2.url) {
1937 free(info.xmms2.url);
1941 case OBJ_xmms2_date:
1942 if (info.xmms2.date) {
1943 free(info.xmms2.date);
1944 info.xmms2.date = 0;
1947 case OBJ_xmms2_status:
1948 if (info.xmms2.status) {
1949 free(info.xmms2.status);
1950 info.xmms2.status = 0;
1953 case OBJ_xmms2_smart:
1954 if (info.xmms2.artist) {
1955 free(info.xmms2.artist);
1956 info.xmms2.artist = 0;
1958 if (info.xmms2.title) {
1959 free(info.xmms2.title);
1960 info.xmms2.title = 0;
1962 if (info.xmms2.url) {
1963 free(info.xmms2.url);
1969 case OBJ_bmpx_title:
1970 case OBJ_bmpx_artist:
1971 case OBJ_bmpx_album:
1972 case OBJ_bmpx_track:
1974 case OBJ_bmpx_bitrate:
1978 free(objs[i].data.s);
1980 case OBJ_battery_time:
1981 free(objs[i].data.s);
1984 free(objs[i].data.execi.cmd);
1985 free(objs[i].data.execi.buffer);
1988 free(objs[i].data.texeci.cmd);
1989 free(objs[i].data.texeci.buffer);
1992 if (info.first_process) {
1993 free_all_processes();
1994 info.first_process = NULL;
1998 if (info.first_process) {
1999 free_all_processes();
2000 info.first_process = NULL;
2005 free(objs[i].data.hddtemp.dev);
2006 free(objs[i].data.hddtemp.addr);
2009 case OBJ_entropy_avail:
2010 case OBJ_entropy_poolsize:
2011 case OBJ_entropy_bar:
2016 //text_objects = NULL;
2017 //text_object_count = 0;
2020 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2025 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2026 *a = mixer_init(buf1);
2027 (void) scan_bar(arg + n, w, h);
2030 (void) scan_bar(arg, w, h);
2035 /* construct_text_object() creates a new text_object */
2036 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2038 //struct text_object *obj = new_text_object();
2039 struct text_object *obj = new_text_object_internal();
2042 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2043 #define END ; } } else
2047 obj->type = OBJ_color;
2048 obj->data.l = get_x11_color(s);
2051 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2052 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2053 END OBJ(acpiacadapter, 0)
2054 END OBJ(freq, INFO_FREQ)
2060 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2062 obj->data.cpu_index=1;
2063 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2067 obj->data.cpu_index=atoi(&arg[0]);
2070 END OBJ(freq_g, INFO_FREQ)
2076 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2078 obj->data.cpu_index=1;
2079 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2083 obj->data.cpu_index=atoi(&arg[0]);
2086 #if defined(__linux__)
2087 END OBJ(voltage_mv, 0)
2093 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2095 obj->data.cpu_index=1;
2096 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2100 obj->data.cpu_index=atoi(&arg[0]);
2103 END OBJ(voltage_v, 0)
2109 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2111 obj->data.cpu_index=1;
2112 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2116 obj->data.cpu_index=atoi(&arg[0]);
2119 #endif /* __linux__ */
2120 END OBJ(freq_dyn, 0);
2121 END OBJ(freq_dyn_g, 0);
2122 END OBJ(acpifan, 0);
2123 END OBJ(battery, 0);
2126 sscanf(arg, "%63s", bat);
2128 strcpy(bat, "BAT0");
2129 obj->data.s = strdup(bat);
2130 END OBJ(battery_time, 0);
2133 sscanf(arg, "%63s", bat);
2135 strcpy(bat, "BAT0");
2136 obj->data.s = strdup(bat);
2137 #if defined(__linux__)
2138 END OBJ(i8k_version, INFO_I8K)
2139 END OBJ(i8k_bios, INFO_I8K)
2140 END OBJ(i8k_serial, INFO_I8K)
2141 END OBJ(i8k_cpu_temp, INFO_I8K)
2142 END OBJ(i8k_cpu_tempf, INFO_I8K)
2143 END OBJ(i8k_left_fan_status, INFO_I8K)
2144 END OBJ(i8k_right_fan_status, INFO_I8K)
2145 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2146 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2147 END OBJ(i8k_ac_status, INFO_I8K)
2148 END OBJ(i8k_buttons_status, INFO_I8K)
2150 END OBJ(ibm_temps, 0)
2152 CRIT_ERR("ibm_temps: needs an argument");
2154 if (!isdigit(arg[0])
2156 || atoi(&arg[0]) >=8)
2159 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2161 obj->data.sensor = atoi(&arg[0]);
2162 END OBJ(ibm_volume, 0)
2163 END OBJ(ibm_brightness, 0)
2164 END OBJ(pb_battery, 0)
2165 if (arg && strcmp(arg, "status") == 0) {
2166 obj->data.i = PB_BATT_STATUS;
2167 } else if (arg && strcmp(arg, "percent") == 0) {
2168 obj->data.i = PB_BATT_PERCENT;
2169 } else if (arg && strcmp(arg, "time") == 0) {
2170 obj->data.i = PB_BATT_TIME;
2172 ERR("pb_battery: needs one argument: status, percent or time");
2177 #endif /* __linux__ */
2178 END OBJ(buffers, INFO_BUFFERS)
2179 END OBJ(cached, INFO_BUFFERS)
2180 END OBJ(cpu, INFO_CPU)
2182 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2183 obj->data.cpu_index = atoi(&arg[3]);
2185 } else {obj->data.cpu_index = 0; }
2187 obj->data.cpu_index = 0;
2189 END OBJ(cpubar, INFO_CPU)
2191 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2192 obj->data.cpu_index = atoi(&arg[3]);
2195 else {obj->data.cpu_index = 0;}
2196 (void) scan_bar(arg, &obj->a, &obj->b);
2198 (void) scan_bar(arg, &obj->a, &obj->b);
2199 obj->data.cpu_index = 0;
2201 END OBJ(cpugraph, INFO_CPU)
2203 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2204 obj->data.cpu_index = atoi(&arg[3]);
2207 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2209 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2210 obj->data.cpu_index = 0;
2212 END OBJ(diskio, INFO_DISKIO)
2213 END OBJ(diskio_read, INFO_DISKIO)
2214 END OBJ(diskio_write, INFO_DISKIO)
2215 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2216 END OBJ(diskiograph_read, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2217 END OBJ(diskiograph_write, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2220 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2224 obj->data.s = scan_font(arg);
2226 OBJ(downspeed, INFO_NET)
2228 obj->data.net = get_net_stat(arg);
2231 CRIT_ERR("downspeed needs argument");
2233 END OBJ(downspeedf, INFO_NET)
2235 obj->data.net = get_net_stat(arg);
2238 CRIT_ERR("downspeedf needs argument");
2240 END OBJ(downspeedgraph, INFO_NET)
2241 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2243 sscanf(arg, "%63s %*i,%*i %*i", buf);
2244 obj->data.net = get_net_stat(buf);
2245 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2246 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
2253 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2254 blockstart[blockdepth - 1] = object_count;
2255 obj->data.ifblock.pos = object_count + 2;
2257 ERR("$else: no matching $if_*");
2262 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2264 ERR("$endif: no matching $if_*");
2267 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2270 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2271 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2272 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2273 END OBJ(execibar, 0) unsigned int n;
2274 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2276 ERR("${execibar <interval> command}");
2277 obj->type = OBJ_text;
2278 snprintf(buf, 256, "${%s}", s);
2279 obj->data.s = strdup(buf);
2281 obj->data.execi.cmd = strdup(arg + n);
2283 END OBJ(execigraph, 0) unsigned int n;
2284 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2286 ERR("${execigraph <interval> command}");
2287 obj->type = OBJ_text;
2288 snprintf(buf, 256, "${%s}", s);
2289 obj->data.s = strdup(buf);
2291 obj->data.execi.cmd = strdup(arg + n);
2293 END OBJ(execi, 0) unsigned int n;
2294 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2296 ERR("${execi <interval> command}");
2297 obj->type = OBJ_text;
2298 snprintf(buf, 256, "${%s}", s);
2299 obj->data.s = strdup(buf);
2301 obj->data.execi.cmd = strdup(arg + n);
2302 obj->data.execi.buffer =
2303 (char *) calloc(1, text_buffer_size);
2305 END OBJ(texeci, 0) unsigned int n;
2306 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2308 ERR("${texeci <interval> command}");
2309 obj->type = OBJ_text;
2310 snprintf(buf, 256, "${%s}", s);
2311 obj->data.s = strdup(buf);
2313 obj->data.texeci.cmd = strdup(arg + n);
2314 obj->data.texeci.buffer =
2315 (char *) calloc(1, text_buffer_size);
2317 obj->data.texeci.p_timed_thread = NULL;
2318 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2320 FILE *fp = popen(arg, "r");
2324 n = fread(buf, 1, 2048, fp);
2327 if (n && buf[n - 1] == '\n')
2332 obj->data.s = strdup(buf);
2334 obj->data.s = strdup("");
2337 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2338 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2340 while (isspace(*arg))
2346 obj->data.fsbar.fs = prepare_fs_stat(arg);
2347 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2350 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2354 obj->data.fsbar.fs = prepare_fs_stat(arg);
2355 END OBJ(fs_free, INFO_FS) if (!arg)
2357 obj->data.fs = prepare_fs_stat(arg);
2358 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2360 obj->data.fs = prepare_fs_stat(arg);
2361 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2363 obj->data.fs = prepare_fs_stat(arg);
2364 END OBJ(fs_size, INFO_FS) if (!arg)
2366 obj->data.fs = prepare_fs_stat(arg);
2367 END OBJ(fs_used, INFO_FS) if (!arg)
2369 obj->data.fs = prepare_fs_stat(arg);
2370 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2371 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2372 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2376 ERR("goto needs arguments");
2377 obj->type = OBJ_text;
2378 obj->data.s = strdup("${goto}");
2382 obj->data.i = atoi(arg);
2387 if (sscanf(arg, "%d %d", &a, &b) != 2)
2388 sscanf(arg, "%d", &b);
2392 obj->data.pair.a = a;
2393 obj->data.pair.b = b;
2395 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
2399 ERR("i2c needs arguments");
2400 obj->type = OBJ_text;
2401 //obj->data.s = strdup("${i2c}");
2405 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2406 /* if scanf couldn't read three values, read type and num and use
2408 sscanf(arg, "%63s %d", buf2, &n);
2410 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
2411 obj->data.i2c.devtype);
2412 strncpy(obj->data.i2c.type, buf2, 63);
2415 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
2416 obj->data.i2c.devtype);
2417 strncpy(obj->data.i2c.type, buf2, 63);
2420 END OBJ(top, INFO_TOP)
2424 ERR("top needs arguments");
2425 obj->type = OBJ_text;
2426 //obj->data.s = strdup("${top}");
2429 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2430 if (strcmp(buf, "name") == 0) {
2431 obj->data.top.type = TOP_NAME;
2432 } else if (strcmp(buf, "cpu") == 0) {
2433 obj->data.top.type = TOP_CPU;
2434 } else if (strcmp(buf, "pid") == 0) {
2435 obj->data.top.type = TOP_PID;
2436 } else if (strcmp(buf, "mem") == 0) {
2437 obj->data.top.type = TOP_MEM;
2439 ERR("invalid arg for top");
2442 if (n < 1 || n > 10) {
2443 CRIT_ERR("invalid arg for top");
2446 obj->data.top.num = n - 1;
2450 ERR("invalid args given for top");
2453 END OBJ(top_mem, INFO_TOP)
2457 ERR("top_mem needs arguments");
2458 obj->type = OBJ_text;
2459 obj->data.s = strdup("${top_mem}");
2462 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2463 if (strcmp(buf, "name") == 0) {
2464 obj->data.top.type = TOP_NAME;
2465 } else if (strcmp(buf, "cpu") == 0) {
2466 obj->data.top.type = TOP_CPU;
2467 } else if (strcmp(buf, "pid") == 0) {
2468 obj->data.top.type = TOP_PID;
2469 } else if (strcmp(buf, "mem") == 0) {
2470 obj->data.top.type = TOP_MEM;
2472 ERR("invalid arg for top");
2475 if (n < 1 || n > 10) {
2476 CRIT_ERR("invalid arg for top");
2479 obj->data.top.num = n - 1;
2483 ERR("invalid args given for top");
2486 END OBJ(addr, INFO_NET)
2488 obj->data.net = get_net_stat(arg);
2491 CRIT_ERR("addr needs argument");
2493 END OBJ(linkstatus, INFO_WIFI)
2495 obj->data.net = get_net_stat(arg);
2498 CRIT_ERR("linkstatus needs argument");
2504 ERR("tail needs arguments");
2505 obj->type = OBJ_text;
2506 obj->data.s = strdup("${tail}");
2509 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2510 if (n1 < 1 || n1 > 30) {
2511 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2515 fp = fopen(buf, "r");
2517 obj->data.tail.logfile =
2518 malloc(text_buffer_size);
2519 strcpy(obj->data.tail.logfile, buf);
2520 obj->data.tail.wantedlines = n1;
2521 obj->data.tail.interval =
2522 update_interval * 2;
2526 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2529 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2530 if (n1 < 1 || n1 > 30) {
2532 ("invalid arg for tail, number of lines must be between 1 and 30");
2534 } else if (n2 < 1 || n2 < update_interval) {
2536 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2540 fp = fopen(buf, "r");
2542 obj->data.tail.logfile =
2543 malloc(text_buffer_size);
2544 strcpy(obj->data.tail.logfile, buf);
2545 obj->data.tail.wantedlines = n1;
2546 obj->data.tail.interval = n2;
2550 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2556 ERR("invalid args given for tail");
2559 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2564 ERR("head needs arguments");
2565 obj->type = OBJ_text;
2566 obj->data.s = strdup("${head}");
2569 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2570 if (n1 < 1 || n1 > 30) {
2571 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2575 fp = fopen(buf, "r");
2577 obj->data.tail.logfile =
2578 malloc(text_buffer_size);
2579 strcpy(obj->data.tail.logfile, buf);
2580 obj->data.tail.wantedlines = n1;
2581 obj->data.tail.interval =
2582 update_interval * 2;
2586 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2589 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2590 if (n1 < 1 || n1 > 30) {
2592 ("invalid arg for head, number of lines must be between 1 and 30");
2594 } else if (n2 < 1 || n2 < update_interval) {
2596 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2600 fp = fopen(buf, "r");
2602 obj->data.tail.logfile =
2603 malloc(text_buffer_size);
2604 strcpy(obj->data.tail.logfile, buf);
2605 obj->data.tail.wantedlines = n1;
2606 obj->data.tail.interval = n2;
2610 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2616 ERR("invalid args given for head");
2619 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2620 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2622 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2623 if (r >= 3 && (c < 1 || c > 3))
2625 if (r >= 2 && (b < 1 || b > 3))
2627 if (r >= 1 && (a < 1 || a > 3))
2630 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2631 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2632 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2633 END OBJ(if_existing, 0)
2634 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2635 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2638 ERR("if_existing needs an argument");
2639 obj->data.ifblock.s = 0;
2641 obj->data.ifblock.s = strdup(arg);
2642 blockstart[blockdepth] = object_count;
2643 obj->data.ifblock.pos = object_count + 2;
2645 END OBJ(if_mounted, 0)
2646 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2647 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2650 ERR("if_mounted needs an argument");
2651 obj->data.ifblock.s = 0;
2653 obj->data.ifblock.s = strdup(arg);
2654 blockstart[blockdepth] = object_count;
2655 obj->data.ifblock.pos = object_count + 2;
2657 END OBJ(if_running, 0)
2658 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2659 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2663 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2664 obj->data.ifblock.s = strdup(buf);
2666 ERR("if_running needs an argument");
2667 obj->data.ifblock.s = 0;
2669 blockstart[blockdepth] = object_count;
2670 obj->data.ifblock.pos = object_count + 2;
2674 END OBJ(mails, INFO_MAIL)
2675 END OBJ(mboxscan, 0)
2676 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
2677 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
2678 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
2679 END OBJ(mem, INFO_MEM)
2680 END OBJ(memmax, INFO_MEM)
2681 END OBJ(memperc, INFO_MEM)
2682 END OBJ(membar, INFO_MEM)
2683 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2684 END OBJ(memgraph, INFO_MEM)
2685 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2686 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2687 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2688 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2689 END OBJ(mixerbar, INFO_MIXER)
2690 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2691 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2692 END OBJ(mixerlbar, INFO_MIXER)
2693 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2694 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2695 END OBJ(mixerrbar, INFO_MIXER)
2696 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2697 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2699 OBJ(new_mails, INFO_MAIL)
2700 END OBJ(nodename, 0)
2701 END OBJ(processes, INFO_PROCS)
2702 END OBJ(running_processes, INFO_RUN_PROCS)
2703 END OBJ(shadecolor, 0)
2705 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2707 END OBJ(outlinecolor, 0)
2709 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2711 END OBJ(stippled_hr, 0)
2713 int a = stippled_borders, b = 1;
2715 if (sscanf(arg, "%d %d", &a, &b) != 2)
2716 sscanf(arg, "%d", &b);
2720 obj->data.pair.a = a;
2721 obj->data.pair.b = b;
2723 END OBJ(swap, INFO_MEM)
2724 END OBJ(swapmax, INFO_MEM)
2725 END OBJ(swapperc, INFO_MEM)
2726 END OBJ(swapbar, INFO_MEM)
2727 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2728 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
2730 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
2731 obj->data.i2c.devtype);
2732 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
2734 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
2735 obj->data.i2c.devtype);
2736 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2737 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2739 char buf1[256], buf2[256], *fmt, *tz;
2742 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2751 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
2752 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
2754 END OBJ(iconv_start, 0)
2755 if (iconv_converting) {
2756 CRIT_ERR("You must stop your last iconv conversion before starting another");
2759 char iconv_from[CODEPAGE_LENGTH];
2760 char iconv_to[CODEPAGE_LENGTH];
2761 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2762 CRIT_ERR("Invalid arguments for iconv_start");
2765 new_iconv = iconv_open(iconv_to, iconv_from);
2766 if (new_iconv == (iconv_t)(-1)) {
2767 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2769 obj->a = register_iconv(&new_iconv);
2770 iconv_converting = 1;
2774 CRIT_ERR("Iconv requires arguments");
2776 END OBJ(iconv_stop, 0)
2777 iconv_converting = 0;
2780 END OBJ(totaldown, INFO_NET)
2782 obj->data.net = get_net_stat(arg);
2785 CRIT_ERR("totaldown needs argument");
2787 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
2789 obj->data.net = get_net_stat(arg);
2792 CRIT_ERR("totalup needs argument");
2795 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
2796 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
2797 END OBJ(upspeed, INFO_NET)
2799 obj->data.net = get_net_stat(arg);
2802 CRIT_ERR("upspeed needs argument");
2804 END OBJ(upspeedf, INFO_NET)
2806 obj->data.net = get_net_stat(arg);
2809 CRIT_ERR("upspeedf needs argument");
2812 END OBJ(upspeedgraph, INFO_NET)
2813 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2815 sscanf(arg, "%63s %*i,%*i %*i", buf);
2816 obj->data.net = get_net_stat(buf);
2817 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2818 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
2823 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
2824 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
2825 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
2826 OBJ(apm_adapter, 0) END
2827 OBJ(apm_battery_life, 0) END
2828 OBJ(apm_battery_time, 0) END
2829 #endif /* __FreeBSD__ */
2833 obj->data.mail = parse_mail_args(IMAP, arg);
2834 obj->global_mode = 0;
2836 obj->global_mode = 1;
2839 OBJ(imap_messages, 0)
2842 obj->data.mail = parse_mail_args(IMAP, arg);
2843 obj->global_mode = 0;
2845 obj->global_mode = 1;
2851 obj->data.mail = parse_mail_args(POP3, arg);
2852 obj->global_mode = 0;
2854 obj->global_mode = 1;
2860 obj->data.mail = parse_mail_args(POP3, arg);
2861 obj->global_mode = 0;
2863 obj->global_mode = 1;
2867 OBJ(mpd_artist, INFO_MPD)
2868 END OBJ(mpd_title, INFO_MPD)
2869 END OBJ(mpd_random, INFO_MPD)
2870 END OBJ(mpd_repeat, INFO_MPD)
2871 END OBJ(mpd_elapsed, INFO_MPD)
2872 END OBJ(mpd_length, INFO_MPD)
2873 END OBJ(mpd_track, INFO_MPD)
2874 END OBJ(mpd_name, INFO_MPD)
2875 END OBJ(mpd_file, INFO_MPD)
2876 END OBJ(mpd_percent, INFO_MPD)
2877 END OBJ(mpd_album, INFO_MPD)
2878 END OBJ(mpd_vol, INFO_MPD)
2879 END OBJ(mpd_bitrate, INFO_MPD)
2880 END OBJ(mpd_status, INFO_MPD)
2881 END OBJ(mpd_bar, INFO_MPD)
2882 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2883 END OBJ(mpd_smart, INFO_MPD) END
2886 OBJ(xmms2_artist, INFO_XMMS2)
2887 END OBJ(xmms2_album, INFO_XMMS2)
2888 END OBJ(xmms2_title, INFO_XMMS2)
2889 END OBJ(xmms2_genre, INFO_XMMS2)
2890 END OBJ(xmms2_comment, INFO_XMMS2)
2891 END OBJ(xmms2_decoder, INFO_XMMS2)
2892 END OBJ(xmms2_transport, INFO_XMMS2)
2893 END OBJ(xmms2_url, INFO_XMMS2)
2894 END OBJ(xmms2_tracknr, INFO_XMMS2)
2895 END OBJ(xmms2_bitrate, INFO_XMMS2)
2896 END OBJ(xmms2_date, INFO_XMMS2)
2897 END OBJ(xmms2_id, INFO_XMMS2)
2898 END OBJ(xmms2_duration, INFO_XMMS2)
2899 END OBJ(xmms2_elapsed, INFO_XMMS2)
2900 END OBJ(xmms2_size, INFO_XMMS2)
2901 END OBJ(xmms2_status, INFO_XMMS2)
2902 END OBJ(xmms2_percent, INFO_XMMS2)
2903 END OBJ(xmms2_bar, INFO_XMMS2)
2904 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2905 END OBJ(xmms2_smart, INFO_XMMS2)
2909 OBJ(audacious_status, INFO_AUDACIOUS) END
2910 OBJ(audacious_title, INFO_AUDACIOUS)
2914 sscanf (arg, "%d", &info.audacious.max_title_len);
2915 if (info.audacious.max_title_len > 0)
2916 info.audacious.max_title_len++;
2918 CRIT_ERR ("audacious_title: invalid length argument");
2922 OBJ(audacious_length, INFO_AUDACIOUS) END
2923 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
2924 OBJ(audacious_position, INFO_AUDACIOUS) END
2925 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
2926 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
2927 OBJ(audacious_frequency, INFO_AUDACIOUS) END
2928 OBJ(audacious_channels, INFO_AUDACIOUS) END
2929 OBJ(audacious_filename, INFO_AUDACIOUS) END
2930 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
2931 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
2932 OBJ(audacious_bar, INFO_AUDACIOUS)
2933 (void) scan_bar(arg, &obj->a, &obj->b);
2937 OBJ(bmpx_title, INFO_BMPX)
2938 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2940 OBJ(bmpx_artist, INFO_BMPX)
2941 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2943 OBJ(bmpx_album, INFO_BMPX)
2944 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2946 OBJ(bmpx_track, INFO_BMPX)
2947 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2949 OBJ(bmpx_uri, INFO_BMPX)
2950 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2952 OBJ(bmpx_bitrate, INFO_BMPX)
2953 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
2958 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
2959 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
2960 ERR("hddtemp needs arguments");
2961 obj->type = OBJ_text;
2962 obj->data.s = strdup("${hddtemp}");
2967 #ifdef TCP_PORT_MONITOR
2968 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
2969 int argc, port_begin, port_end, item, connection_index;
2971 memset(itembuf,0,sizeof(itembuf));
2973 /* massive argument checking */
2975 CRIT_ERR("tcp_portmon: needs arguments");
2977 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
2978 if ( (argc != 3) && (argc != 4) )
2980 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
2982 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
2984 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
2986 if ( port_begin > port_end )
2988 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
2990 if ( strncmp(itembuf,"count",31) == 0 )
2992 else if ( strncmp(itembuf,"rip",31) == 0 )
2994 else if ( strncmp(itembuf,"rhost",31) == 0 )
2996 else if ( strncmp(itembuf,"rport",31) == 0 )
2998 else if ( strncmp(itembuf,"rservice",31) == 0 )
3000 else if ( strncmp(itembuf,"lip",31) == 0 )
3002 else if ( strncmp(itembuf,"lhost",31) == 0 )
3004 else if ( strncmp(itembuf,"lport",31) == 0 )
3006 else if ( strncmp(itembuf,"lservice",31) == 0 )
3010 CRIT_ERR("tcp_portmon: invalid item specified");
3012 if ( (argc==3) && (item!=COUNT) )
3014 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3016 if ( (argc==4) && (connection_index<0) )
3018 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3020 /* ok, args looks good. save the text object data */
3021 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3022 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3023 obj->data.tcp_port_monitor.item = item;
3024 obj->data.tcp_port_monitor.connection_index = connection_index;
3026 /* if the port monitor collection hasn't been created, we must create it */
3027 if ( !info.p_tcp_port_monitor_collection )
3029 info.p_tcp_port_monitor_collection =
3030 create_tcp_port_monitor_collection ();
3031 if ( !info.p_tcp_port_monitor_collection )
3033 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3037 /* if a port monitor for this port does not exist, create one and add it to the collection */
3038 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3040 tcp_port_monitor_t * p_monitor =
3041 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3044 CRIT_ERR("tcp_portmon: unable to create port monitor");
3046 /* add the newly created monitor to the collection */
3047 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3050 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3055 OBJ(entropy_avail, INFO_ENTROPY) END
3056 OBJ(entropy_poolsize, INFO_ENTROPY) END
3057 OBJ(entropy_bar, INFO_ENTROPY)
3058 (void) scan_bar(arg, &obj->a, &obj->b);
3063 ERR("unknown variable %s", s);
3064 obj->type = OBJ_text;
3065 snprintf(buf, 256, "${%s}", s);
3066 obj->data.s = strdup(buf);
3073 static struct text_object *create_plain_text(const char *s)
3075 struct text_object *obj;
3077 if (s == NULL || *s == '\0') {
3081 obj = new_text_object_internal();
3083 obj->type = OBJ_text;
3084 obj->data.s = strdup(s);
3088 static struct text_object_list *extract_variable_text_internal(const char *p)
3090 struct text_object_list *retval;
3091 struct text_object *obj;
3094 retval = malloc(sizeof(struct text_object_list));
3095 memset(retval, 0, sizeof(struct text_object_list));
3096 retval->text_object_count = 0;
3098 long line = text_lines;
3106 obj = create_plain_text(s);
3108 // allocate memory for the object
3109 retval->text_objects = realloc(retval->text_objects,
3110 sizeof(struct text_object) * (retval->text_object_count+1));
3111 // assign the new object to the end of the list.
3112 memcpy(&retval->text_objects[retval->text_object_count++],
3113 obj, sizeof(struct text_object));
3125 /* variable is either $foo or ${foo} */
3129 while (*p && *p != '}')
3135 while (*p && (isalnum((int) *p)
3140 /* copy variable to buffer */
3141 len = (p - s > 255) ? 255 : (p - s);
3142 strncpy(buf, s, len);
3151 /* if variable wasn't found from environment, use some special */
3157 if (strchr(buf, ' ')) {
3158 arg = strchr(buf, ' ');
3161 while (isspace((int) *arg))
3167 /* lowercase variable name */
3174 // create new object
3175 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3177 // allocate memory for the object
3178 retval->text_objects = realloc(retval->text_objects,
3179 sizeof(struct text_object) * (retval->text_object_count+1));
3180 // assign the new object to the end of the list.
3181 memcpy(&retval->text_objects[retval->text_object_count++],
3182 obj, sizeof(struct text_object));
3188 obj = create_plain_text("$");
3190 // allocate memory for the object
3191 retval->text_objects = realloc(retval->text_objects,
3192 sizeof(struct text_object) * (retval->text_object_count+1));
3193 // assign the new object to the end of the list.
3194 memcpy(&retval->text_objects[retval->text_object_count++],
3195 obj, sizeof(struct text_object));
3202 obj = create_plain_text(s);
3204 // allocate memory for the object
3205 retval->text_objects = realloc(retval->text_objects,
3206 sizeof(struct text_object) * (retval->text_object_count+1));
3207 // assign the new object to the end of the list.
3208 memcpy(&retval->text_objects[retval->text_object_count++],
3209 obj, sizeof(struct text_object));
3214 ERR("one or more $endif's are missing");
3220 static void extract_variable_text(const char *p)
3222 struct text_object_list *list;
3224 free_text_objects(text_object_count, text_objects);
3225 text_object_count = 0;
3226 text_objects = NULL;
3229 list = extract_variable_text_internal(p);
3230 text_objects = list->text_objects;
3231 text_object_count = list->text_object_count;
3238 void parse_conky_vars(char * text, char * p, struct information *cur) {
3239 struct text_object_list *object_list = extract_variable_text_internal(text);
3240 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3244 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3249 char buff_in[P_MAX_SIZE] = {0};
3250 iconv_converting = 0;
3253 for (i = 0; i < object_count; i++) {
3254 struct text_object *obj = &objs[i];
3256 #define OBJ(a) break; case OBJ_##a:
3258 switch (obj->type) {
3261 ERR("not implemented obj type %d",
3265 /* does anyone have decimals in acpi temperature? */
3267 snprintf(p, p_max_size, "%d", (int)
3268 get_acpi_temperature(obj->
3272 snprintf(p, 5, "%d ", (int)
3273 get_acpi_temperature(obj->
3278 /* does anyone have decimals in acpi temperature? */
3280 snprintf(p, p_max_size, "%d", (int)
3281 ((get_acpi_temperature(obj->
3283 i)+ 40) * 9.0 / 5 - 40));
3285 snprintf(p, 5, "%d ", (int)
3286 ((get_acpi_temperature(obj->
3288 i)+ 40) * 9.0 / 5 - 40));
3292 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3297 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3300 #if defined(__linux__)
3303 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3308 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3311 #endif /* __linux__ */
3315 get_freq_dynamic(p, 6, "%.0f ", 1 );
3317 get_freq_dynamic(p, p_max_size, "%.0f", 1 );
3322 get_freq_dynamic(p, 6, "%'.2f ", 1000);
3324 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3328 get_adt746x_cpu(p, p_max_size);
3331 get_adt746x_fan(p, p_max_size);
3334 get_acpi_fan(p, p_max_size);
3336 OBJ(acpiacadapter) {
3337 get_acpi_ac_adapter(p, p_max_size);
3340 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3343 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3346 human_readable(cur->buffers * 1024, p, 255);
3349 human_readable(cur->cached * 1024, p, 255);
3352 if (obj->data.cpu_index > info.cpu_count) {
3353 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3354 CRIT_ERR("attempting to use more CPUs then you have!");
3357 snprintf(p, p_max_size, "%*d", pad_percents,
3358 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3361 snprintf(p, 4, "%*d ",
3363 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3369 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3372 new_graph(p, obj->a,
3373 obj->b, obj->c, obj->d,
3374 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3378 new_fg(p, obj->data.l);
3380 #if defined(__linux__)
3382 snprintf(p, p_max_size, "%s", i8k.version);
3385 snprintf(p, p_max_size, "%s", i8k.bios);
3388 snprintf(p, p_max_size, "%s", i8k.serial);
3391 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3393 OBJ(i8k_cpu_tempf) {
3395 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3396 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3398 OBJ(i8k_left_fan_status) {
3399 int left_fan_status;
3400 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3401 if(left_fan_status == 0) {
3402 snprintf(p, p_max_size,"off");
3403 } if(left_fan_status == 1) {
3404 snprintf(p, p_max_size, "low");
3405 } if(left_fan_status == 2) {
3406 snprintf(p, p_max_size, "high");
3410 OBJ(i8k_right_fan_status) {
3411 int right_fan_status;
3412 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3413 if(right_fan_status == 0) {
3414 snprintf(p, p_max_size,"off");
3415 } if(right_fan_status == 1) {
3416 snprintf(p, p_max_size, "low");
3417 } if(right_fan_status == 2) {
3418 snprintf(p, p_max_size, "high");
3421 OBJ(i8k_left_fan_rpm) {
3422 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3424 OBJ(i8k_right_fan_rpm) {
3425 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3427 OBJ(i8k_ac_status) {
3429 sscanf(i8k.ac_status, "%d", &ac_status);
3430 if(ac_status == -1) {
3431 snprintf(p, p_max_size,"disabled (read i8k docs)");
3432 } if(ac_status == 0) {
3433 snprintf(p, p_max_size, "off");
3434 } if(ac_status == 1) {
3435 snprintf(p, p_max_size, "on");
3438 OBJ(i8k_buttons_status) {
3439 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3443 get_ibm_acpi_fan(p, p_max_size);
3446 get_ibm_acpi_temps();
3447 snprintf(p, p_max_size, "%d",
3448 ibm_acpi.temps[obj->data.sensor]);
3451 get_ibm_acpi_volume(p, p_max_size);
3453 OBJ(ibm_brightness) {
3454 get_ibm_acpi_brightness(p, p_max_size);
3457 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3459 #endif /* __linux__ */
3463 new_font(p, obj->data.s);
3466 void format_diskio(unsigned int diskio_value)
3469 if (diskio_value > 1024*1024) {
3470 snprintf(p, p_max_size, "%.1fGiB",
3471 (double)diskio_value/1024/1024);
3472 } else if (diskio_value > 1024) {
3473 snprintf(p, p_max_size, "%.1fMiB",
3474 (double)diskio_value/1024);
3475 } else if (diskio_value > 0) {
3476 snprintf(p, p_max_size, "%dKiB", diskio_value);
3478 snprintf(p, p_max_size, "%dB", diskio_value);
3481 if (diskio_value > 1024*1024) {
3482 snprintf(p, 12, "%.1fGiB ",
3483 (double)diskio_value/1024/1024);
3484 } else if (diskio_value > 1024) {
3485 snprintf(p, 12, "%.1fMiB ",
3486 (double)diskio_value/1024);
3487 } else if (diskio_value > 0) {
3488 snprintf(p, 12, "%dKiB ", diskio_value);
3490 snprintf(p, 12, "%dB ", diskio_value);
3495 format_diskio(diskio_value);
3498 format_diskio(diskio_write_value);
3501 format_diskio(diskio_read_value);
3504 new_graph(p, obj->a,
3505 obj->b, obj->c, obj->d,
3506 diskio_value, obj->e, 1);
3508 OBJ(diskiograph_read) {
3509 new_graph(p, obj->a,
3510 obj->b, obj->c, obj->d,
3511 diskio_read_value, obj->e, 1);
3513 OBJ(diskiograph_write) {
3514 new_graph(p, obj->a,
3515 obj->b, obj->c, obj->d,
3516 diskio_write_value, obj->e, 1);
3520 snprintf(p, p_max_size, "%d",
3521 (int) (obj->data.net->
3525 snprintf(p, 6, "%d ",
3526 (int) (obj->data.net->
3532 snprintf(p, p_max_size, "%.1f",
3534 recv_speed / 1024.0);
3536 snprintf(p, 8, "%.1f ",
3538 recv_speed / 1024.0);
3540 OBJ(downspeedgraph) {
3542 if (obj->data.net->recv_speed == 0)
3543 obj->data.net->recv_speed = 0.01;
3545 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3546 (obj->data.net->recv_speed /
3547 1024.0), obj->e, 1);
3551 i = obj->data.ifblock.pos - 1;
3561 snprintf(p, p_max_size, "%u.%u.%u.%u",
3562 obj->data.net->addr.
3564 obj->data.net->addr.
3566 obj->data.net->addr.
3568 obj->data.net->addr.
3574 snprintf(p, p_max_size, "%d",
3575 obj->data.net->linkstatus);
3578 snprintf(p, 5, "%4d ",
3579 obj->data.net->linkstatus);
3582 #if defined(IMLIB2) && defined(X11)
3587 Imlib_Image image, buffer;
3588 image = imlib_load_image(obj->data.s);
3589 imlib_context_set_image(image);
3592 w = imlib_image_get_width();
3593 h = imlib_image_get_height();
3594 buffer = imlib_create_image(w, h);
3595 imlib_context_set_display(display);
3596 imlib_context_set_drawable(window.drawable);
3597 imlib_context_set_colormap(DefaultColormap(display, screen));
3598 imlib_context_set_visual(DefaultVisual(display, screen));
3599 imlib_context_set_image(buffer);
3600 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
3601 imlib_render_image_on_drawable(text_start_x, text_start_y);
3603 imlib_context_set_image(image);
3610 FILE *fp = popen(obj->data.s, "r");
3611 int length = fread(p, 1, p_max_size, fp);
3614 /*output[length] = '\0';
3615 if (length > 0 && output[length - 1] == '\n') {
3616 output[length - 1] = '\0';
3619 if (length > 0 && p[length - 1] == '\n') {
3620 p[length - 1] = '\0';
3623 //parse_conky_vars(output, p, cur);
3627 FILE *fp = popen(obj->data.s, "r");
3628 int n2 = fread(p, 1, p_max_size, fp);
3632 if (n2 && p[n2 - 1] == '\n')
3641 if (sscanf(p, "%lf", &barnum) == 0) {
3642 ERR("reading execbar value failed (perhaps it's not the correct format?)");
3644 if (barnum > 100 || barnum < 0) {
3645 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
3647 barnum = barnum / 100.0;
3648 new_bar(p, 0, 4, (int) (barnum * 255.0));
3654 FILE *fp = popen(obj->data.s, "r");
3655 int n2 = fread(p, 1, p_max_size, fp);
3659 if (n2 && p[n2 - 1] == '\n')
3668 if (sscanf(p, "%lf", &barnum) == 0) {
3669 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
3671 if (barnum > 100 || barnum < 0) {
3672 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
3674 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
3679 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3680 new_bar(p, 0, 4, (int) obj->f);
3683 FILE *fp = popen(obj->data.execi.cmd, "r");
3684 int n2 = fread(p, 1, p_max_size, fp);
3687 if (n2 && p[n2 - 1] == '\n')
3696 if (sscanf(p, "%f", &barnum) == 0) {
3697 ERR("reading execibar value failed (perhaps it's not the correct format?)");
3699 if (barnum > 100 || barnum < 0) {
3700 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
3702 obj->f = 255 * barnum / 100.0;
3703 new_bar(p, 0, 4, (int) obj->f);
3705 obj->data.execi.last_update =
3706 current_update_time;
3710 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3711 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
3714 FILE *fp = popen(obj->data.execi.cmd, "r");
3715 int n2 = fread(p, 1, p_max_size, fp);
3718 if (n2 && p[n2 - 1] == '\n')
3727 if (sscanf(p, "%f", &barnum) == 0) {
3728 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
3730 if (barnum > 100 || barnum < 0) {
3731 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
3734 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
3736 obj->data.execi.last_update = current_update_time;
3742 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
3743 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
3745 char *output = obj->data.execi.buffer;
3746 FILE *fp = popen(obj->data.execi.cmd, "r");
3747 //int length = fread(output, 1, text_buffer_size, fp);
3748 int length = fread(output, 1, text_buffer_size, fp);
3751 output[length] = '\0';
3752 if (length > 0 && output[length - 1] == '\n') {
3753 output[length - 1] = '\0';
3755 obj->data.execi.last_update = current_update_time;
3756 snprintf(p, p_max_size, "%s", output);
3758 //parse_conky_vars(output, p, cur);
3761 if (!obj->data.texeci.p_timed_thread)
3763 obj->data.texeci.p_timed_thread=
3764 timed_thread_create ((void*)threaded_exec, (void*) obj,
3765 obj->data.texeci.interval * 1000000);
3766 if (!obj->data.texeci.p_timed_thread)
3767 ERR("Error starting texeci thread");
3768 timed_thread_register (obj->data.texeci.p_timed_thread,
3769 &obj->data.texeci.p_timed_thread);
3771 timed_thread_lock (obj->data.texeci.p_timed_thread);
3772 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
3773 timed_thread_unlock (obj->data.texeci.p_timed_thread);
3775 #endif /* HAVE_POPEN */
3777 if (obj->global_mode && info.mail) { // this means we use info
3778 if (!info.mail->p_timed_thread)
3780 info.mail->p_timed_thread =
3781 timed_thread_create ((void*)imap_thread,
3783 info.mail->interval * 1000000);
3784 if (!info.mail->p_timed_thread)
3785 ERR("Error starting imap thread");
3786 timed_thread_register (info.mail->p_timed_thread,
3787 &info.mail->p_timed_thread);
3789 timed_thread_lock (info.mail->p_timed_thread);
3790 snprintf(p, p_max_size, "%lu", info.mail->unseen);
3791 timed_thread_unlock (info.mail->p_timed_thread);
3792 } else if (obj->data.mail) { // this means we use obj
3793 if (!obj->data.mail->p_timed_thread)
3795 obj->data.mail->p_timed_thread =
3796 timed_thread_create ((void*)imap_thread,
3797 (void*)obj->data.mail,
3798 obj->data.mail->interval * 1000000);
3799 if (!obj->data.mail->p_timed_thread)
3800 ERR("Error starting imap thread");
3801 timed_thread_register (obj->data.mail->p_timed_thread,
3802 &obj->data.mail->p_timed_thread);
3804 timed_thread_lock (obj->data.mail->p_timed_thread);
3805 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
3806 timed_thread_unlock (obj->data.mail->p_timed_thread);
3807 } else if (!obj->a) { // something is wrong, warn once then stop
3808 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
3812 OBJ(imap_messages) {
3813 if (obj->global_mode && info.mail) { // this means we use info
3814 if (!info.mail->p_timed_thread)
3816 info.mail->p_timed_thread =
3817 timed_thread_create ((void*)imap_thread,
3819 info.mail->interval * 1000000);
3820 if (!info.mail->p_timed_thread)
3821 ERR("Error starting imap thread");
3822 timed_thread_register (info.mail->p_timed_thread,
3823 &info.mail->p_timed_thread);
3825 timed_thread_lock (info.mail->p_timed_thread);
3826 snprintf(p, p_max_size, "%lu", info.mail->messages);
3827 timed_thread_unlock (info.mail->p_timed_thread);
3828 } else if (obj->data.mail) { // this means we use obj
3829 if (!obj->data.mail->p_timed_thread)
3831 obj->data.mail->p_timed_thread =
3832 timed_thread_create ((void*)imap_thread,
3833 (void*)obj->data.mail,
3834 obj->data.mail->interval * 1000000);
3835 if (!obj->data.mail->p_timed_thread)
3836 ERR("Error starting imap thread");
3837 timed_thread_register (obj->data.mail->p_timed_thread,
3838 &obj->data.mail->p_timed_thread);
3840 timed_thread_lock (obj->data.mail->p_timed_thread);
3841 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
3842 timed_thread_lock (obj->data.mail->p_timed_thread);
3843 } else if (!obj->a) { // something is wrong, warn once then stop
3844 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
3849 if (obj->global_mode && info.mail) { // this means we use info
3850 if (!info.mail->p_timed_thread)
3852 info.mail->p_timed_thread =
3853 timed_thread_create ((void*)pop3_thread,
3855 info.mail->interval * 1000000);
3856 if (!info.mail->p_timed_thread)
3857 ERR("Error starting pop3 thread");
3858 timed_thread_register (info.mail->p_timed_thread,
3859 &info.mail->p_timed_thread);
3861 timed_thread_lock (info.mail->p_timed_thread);
3862 snprintf(p, p_max_size, "%lu", info.mail->unseen);
3863 timed_thread_unlock (info.mail->p_timed_thread);
3864 } else if (obj->data.mail) { // this means we use obj
3865 if (!obj->data.mail->p_timed_thread)
3867 obj->data.mail->p_timed_thread =
3868 timed_thread_create ((void*)pop3_thread,
3870 obj->data.mail->interval * 1000000);
3871 if (!obj->data.mail->p_timed_thread)
3872 ERR("Error starting pop3 thread");
3873 timed_thread_register (obj->data.mail->p_timed_thread,
3874 &obj->data.mail->p_timed_thread);
3876 timed_thread_lock (obj->data.mail->p_timed_thread);
3877 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
3878 timed_thread_unlock (obj->data.mail->p_timed_thread);
3879 } else if (!obj->a) { // something is wrong, warn once then stop
3880 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
3885 if (obj->global_mode && info.mail) { // this means we use info
3886 if (!info.mail->p_timed_thread)
3888 info.mail->p_timed_thread =
3889 timed_thread_create ((void*)pop3_thread,
3891 info.mail->interval * 1000000);
3892 if (!info.mail->p_timed_thread)
3893 ERR("Error starting pop3 thread");
3894 timed_thread_register (info.mail->p_timed_thread,
3895 &info.mail->p_timed_thread);
3897 timed_thread_lock (info.mail->p_timed_thread);
3898 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
3899 timed_thread_unlock (info.mail->p_timed_thread);
3900 } else if (obj->data.mail) { // this means we use obj
3901 if (!obj->data.mail->p_timed_thread)
3903 obj->data.mail->p_timed_thread =
3904 timed_thread_create ((void*)pop3_thread,
3905 (void*)obj->data.mail,
3906 obj->data.mail->interval * 1000000);
3907 if (!obj->data.mail->p_timed_thread)
3908 ERR("Error starting pop3 thread");
3909 timed_thread_register (obj->data.mail->p_timed_thread,
3910 &obj->data.mail->p_timed_thread);
3912 timed_thread_lock (obj->data.mail->p_timed_thread);
3913 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
3914 timed_thread_unlock (obj->data.mail->p_timed_thread);
3915 } else if (!obj->a) { // something is wrong, warn once then stop
3916 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
3921 if (obj->data.fs != NULL) {
3922 if (obj->data.fs->size == 0)
3941 if (obj->data.fs != NULL)
3942 human_readable(obj->data.fs->avail,
3946 if (obj->data.fs != NULL) {
3947 if (obj->data.fs->size)
3948 snprintf(p, p_max_size, "%*d",
3957 snprintf(p, p_max_size, "0");
3961 if (obj->data.fs != NULL)
3962 human_readable(obj->data.fs->size,
3966 if (obj->data.fs != NULL)
3967 human_readable(obj->data.fs->size -
3968 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
3972 if (obj->data.fs != NULL) {
3973 if (obj->data.fs->size == 0)
3991 if (obj->data.fs != NULL) {
3992 if (obj->data.fs->size)
3993 snprintf(p, 4, "%d",
4003 snprintf(p, p_max_size, "0");
4007 float *v = info.loadavg;
4009 if (obj->data.loadavg[2])
4010 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4011 v[obj->data.loadavg[0] -
4013 v[obj->data.loadavg[1] -
4015 v[obj->data.loadavg[2] -
4017 else if (obj->data.loadavg[1])
4018 snprintf(p, p_max_size, "%.2f %.2f",
4019 v[obj->data.loadavg[0] -
4021 v[obj->data.loadavg[1] -
4023 else if (obj->data.loadavg[0])
4024 snprintf(p, p_max_size, "%.2f",
4025 v[obj->data.loadavg[0] -
4029 new_goto(p, obj->data.i);
4032 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4035 new_hr(p, obj->data.i);
4042 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4043 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4045 snprintf(p, p_max_size, "N/A");
4046 } else if (unit == '*') {
4047 snprintf(p, p_max_size, "%s", temp);
4049 snprintf(p, p_max_size, "%s°%c", temp, unit);
4054 new_offset(p, obj->data.i);
4057 new_voffset(p, obj->data.i);
4062 r = get_i2c_info(&obj->data.i2c.fd,
4064 obj->data.i2c.devtype,
4065 obj->data.i2c.type);
4067 if (r >= 100.0 || r == 0)
4068 snprintf(p, p_max_size, "%d", (int) r);
4070 snprintf(p, p_max_size, "%.1f", r);
4073 new_alignr(p, obj->data.i);
4076 new_alignc(p, obj->data.i);
4080 if ((obj->data.ifblock.s)
4081 && (stat(obj->data.ifblock.s, &tmp) ==
4083 i = obj->data.ifblock.pos;
4090 if ((obj->data.ifblock.s)
4091 && (!check_mount(obj->data.ifblock.s))) {
4092 i = obj->data.ifblock.pos;
4099 if ((obj->data.ifblock.s)
4100 && system(obj->data.ifblock.s)) {
4101 i = obj->data.ifblock.pos;
4108 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4111 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4116 human_readable(cur->mem * 1024, p, 255);
4119 human_readable(cur->memmax * 1024, p, 255);
4124 snprintf(p, p_max_size, "%*Lu",
4129 snprintf(p, 4, "%*Lu ",
4136 new_bar(p, obj->data.pair.a,
4138 cur->memmax ? (cur->mem * 255) /
4143 new_graph(p, obj->a,
4144 obj->b, obj->c, obj->d,
4145 cur->memmax ? (cur->mem * 100.0) /
4146 (cur->memmax) : 0.0, 100, 1);
4150 snprintf(p, p_max_size, "%d",
4151 mixer_get_avg(obj->data.l));
4154 snprintf(p, p_max_size, "%d",
4155 mixer_get_left(obj->data.l));
4158 snprintf(p, p_max_size, "%d",
4159 mixer_get_right(obj->data.l));
4162 new_bar(p, obj->data.mixerbar.w,
4163 obj->data.mixerbar.h,
4164 mixer_get_avg(obj->data.mixerbar.
4168 new_bar(p, obj->data.mixerbar.w,
4169 obj->data.mixerbar.h,
4170 mixer_get_left(obj->data.mixerbar.
4174 new_bar(p, obj->data.mixerbar.w,
4175 obj->data.mixerbar.h,
4176 mixer_get_right(obj->data.mixerbar.
4182 snprintf(p, p_max_size, "%d", cur->mail_count);
4185 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, text_buffer_size);
4186 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4189 snprintf(p, p_max_size, "%d", cur->new_mail_count);
4193 snprintf(p, p_max_size, "%s",
4194 cur->uname_s.nodename);
4197 new_outline(p, obj->data.l);
4201 snprintf(p, p_max_size, "%hu", cur->procs);
4203 snprintf(p, 5, "%hu ",
4206 OBJ(running_processes) {
4208 snprintf(p, p_max_size, "%hu",
4211 snprintf(p, 3, "%hu ",
4215 snprintf(p, p_max_size, "%s", obj->data.s);
4218 new_bg(p, obj->data.l);
4221 new_stippled_hr(p, obj->data.pair.a,
4225 human_readable(cur->swap * 1024, p, 255);
4228 human_readable(cur->swapmax * 1024, p,
4232 if (cur->swapmax == 0) {
4233 strncpy(p, "No swap", 255);
4236 snprintf(p, 255, "%*Lu",
4242 snprintf(p, 4, "%*Lu ",
4250 new_bar(p, obj->data.pair.a,
4252 cur->swapmax ? (cur->swap * 255) /
4253 (cur->swapmax) : 0);
4256 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4259 time_t t = time(NULL);
4260 struct tm *tm = localtime(&t);
4261 setlocale(LC_TIME, "");
4262 strftime(p, p_max_size, obj->data.s, tm);
4265 time_t t = time(NULL);
4266 struct tm *tm = gmtime(&t);
4267 strftime(p, p_max_size, obj->data.s, tm);
4271 if (obj->data.tztime.tz) {
4272 oldTZ = getenv("TZ");
4273 setenv("TZ", obj->data.tztime.tz, 1);
4276 time_t t = time(NULL);
4277 struct tm *tm = localtime(&t);
4278 setlocale(LC_TIME, "");
4279 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4281 setenv("TZ", oldTZ, 1);
4286 // Needless to free oldTZ since getenv gives ptr to static data
4289 human_readable(obj->data.net->recv, p,
4293 human_readable(obj->data.net->trans, p,
4297 snprintf(p, p_max_size, "%d", total_updates);
4301 snprintf(p, p_max_size, "%d",
4302 (int) (obj->data.net->
4306 snprintf(p, 5, "%d ",
4307 (int) (obj->data.net->
4313 snprintf(p, p_max_size, "%.1f",
4315 trans_speed / 1024.0);
4317 snprintf(p, 8, "%.1f ",
4319 trans_speed / 1024.0);
4323 if (obj->data.net->trans_speed == 0)
4324 obj->data.net->trans_speed = 0.01;
4326 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4327 (obj->data.net->trans_speed /
4328 1024.0), obj->e, 1);
4331 format_seconds_short(p, p_max_size,
4335 format_seconds(p, p_max_size, (int) cur->uptime);
4338 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
4340 snprintf(p, p_max_size, "%s", get_apm_adapter());
4342 OBJ(apm_battery_life) {
4344 msg = get_apm_battery_life();
4345 snprintf(p, p_max_size, "%s", msg);
4348 OBJ(apm_battery_time) {
4350 msg = get_apm_battery_time();
4351 snprintf(p, p_max_size, "%s", msg);
4354 #endif /* __FreeBSD__ */
4358 snprintf(p, p_max_size, "%s", cur->mpd.title);
4361 snprintf(p, p_max_size, "%s", cur->mpd.artist);
4364 snprintf(p, p_max_size, "%s", cur->mpd.album);
4367 snprintf(p, p_max_size, "%s", cur->mpd.random);
4370 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
4373 snprintf(p, p_max_size, "%s", cur->mpd.track);
4376 snprintf(p, p_max_size, "%s", cur->mpd.name);
4379 snprintf(p, p_max_size, "%s", cur->mpd.file);
4382 snprintf(p, p_max_size, "%i", cur->mpd.volume);
4385 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
4388 snprintf(p, p_max_size, "%s", cur->mpd.status);
4391 int days = 0, hours = 0, minutes =
4393 int tmp = cur->mpd.elapsed;
4394 while (tmp >= 86400) {
4398 while (tmp >= 3600) {
4408 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
4409 days, hours, minutes,
4412 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4415 snprintf(p, p_max_size, "%i:%02i", minutes,
4419 int days = 0, hours = 0, minutes =
4421 int tmp = cur->mpd.length;
4422 while (tmp >= 86400) {
4426 while (tmp >= 3600) {
4436 snprintf(p, p_max_size,
4437 "%i days %i:%02i:%02i",
4438 days, hours, minutes,
4441 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4444 snprintf(p, p_max_size, "%i:%02i", minutes,
4448 snprintf(p, p_max_size, "%2.0f",
4449 cur->mpd.progress * 100);
4452 new_bar(p, obj->data.pair.a,
4454 (int) (cur->mpd.progress *
4458 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.title) < 2) {
4459 snprintf(p, p_max_size, "%s", cur->mpd.file);
4461 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
4467 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4470 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4473 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4476 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4478 OBJ(xmms2_comment) {
4479 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4481 OBJ(xmms2_decoder) {
4482 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
4484 OBJ(xmms2_transport) {
4485 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
4488 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4491 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4494 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4496 OBJ(xmms2_tracknr) {
4497 if (cur->xmms2.tracknr != -1)
4498 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4500 OBJ(xmms2_bitrate) {
4501 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4504 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4507 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4509 OBJ(xmms2_elapsed) {
4510 int tmp = cur->xmms2.elapsed;
4511 snprintf(p, p_max_size, "%02d:%02d",
4512 tmp / 60000, (tmp / 1000) % 60);
4514 OBJ(xmms2_duration) {
4515 int tmp = cur->xmms2.duration;
4516 snprintf(p, p_max_size, "%02d:%02d",
4517 tmp / 60000, (tmp / 1000) % 60);
4519 OBJ(xmms2_percent) {
4520 snprintf(p, p_max_size, "%2.0f",
4521 cur->xmms2.progress * 100);
4524 new_bar(p, obj->data.pair.a,
4526 (int) (cur->xmms2.progress *
4530 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
4531 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4533 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
4538 OBJ(audacious_status) {
4539 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
4541 OBJ(audacious_title) {
4542 snprintf(p, cur->audacious.max_title_len > 0 ?
4543 cur->audacious.max_title_len : p_max_size, "%s",
4544 cur->audacious.items[AUDACIOUS_TITLE]);
4546 OBJ(audacious_length) {
4547 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
4549 OBJ(audacious_length_seconds) {
4550 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4552 OBJ(audacious_position) {
4553 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
4555 OBJ(audacious_position_seconds) {
4556 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
4558 OBJ(audacious_bitrate) {
4559 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
4561 OBJ(audacious_frequency) {
4562 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
4564 OBJ(audacious_channels) {
4565 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
4567 OBJ(audacious_filename) {
4568 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
4570 OBJ(audacious_playlist_length) {
4571 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
4573 OBJ(audacious_playlist_position) {
4574 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
4576 OBJ(audacious_bar) {
4578 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
4579 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4580 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
4585 snprintf(p, p_max_size, "%s", cur->bmpx.title);
4588 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
4591 snprintf(p, p_max_size, "%s", cur->bmpx.album);
4594 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
4597 snprintf(p, p_max_size, "%i", cur->bmpx.track);
4600 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
4604 if (obj->data.top.type == TOP_NAME
4605 && obj->data.top.num >= 0
4606 && obj->data.top.num < 10) {
4607 // if we limit the buffer and add a bunch of space after, it stops the thing from
4608 // moving other shit around, which is really fucking annoying
4609 snprintf(p, 17, "%s ", cur->cpu[obj->data.top.num]->name);
4610 } else if (obj->data.top.type == TOP_CPU
4611 && obj->data.top.num >= 0
4612 && obj->data.top.num < 10) {
4613 snprintf(p, 7, "%3.2f ",
4614 cur->cpu[obj->data.top.
4616 } else if (obj->data.top.type == TOP_PID
4617 && obj->data.top.num >= 0
4618 && obj->data.top.num < 10) {
4619 snprintf(p, 8, "%i ",
4620 cur->cpu[obj->data.top.
4622 } else if (obj->data.top.type == TOP_MEM
4623 && obj->data.top.num >= 0
4624 && obj->data.top.num < 10) {
4625 snprintf(p, 7, "%3.2f ",
4626 cur->cpu[obj->data.top.
4631 if (obj->data.top.type == TOP_NAME
4632 && obj->data.top.num >= 0
4633 && obj->data.top.num < 10) {
4634 // if we limit the buffer and add a bunch of space after, it stops the thing from
4635 // moving other shit around, which is really fucking annoying
4638 cur->memu[obj->data.top.
4640 } else if (obj->data.top.type == TOP_CPU
4641 && obj->data.top.num >= 0
4642 && obj->data.top.num < 10) {
4643 snprintf(p, 7, "%3.2f ",
4644 cur->memu[obj->data.top.
4646 } else if (obj->data.top.type == TOP_PID
4647 && obj->data.top.num >= 0
4648 && obj->data.top.num < 10) {
4649 snprintf(p, 8, "%i ",
4650 cur->memu[obj->data.top.
4652 } else if (obj->data.top.type == TOP_MEM
4653 && obj->data.top.num >= 0
4654 && obj->data.top.num < 10) {
4655 snprintf(p, 7, "%3.2f ",
4656 cur->memu[obj->data.top.
4663 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4664 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4666 obj->data.tail.last_update = current_update_time;
4670 fp = fopen(obj->data.tail.logfile, "rt");
4672 /* Send one message, but do not consistently spam on
4673 * missing logfiles. */
4674 if(obj->data.tail.readlines != 0) {
4675 ERR("tail logfile failed to open");
4676 strcpy(obj->data.tail.buffer, "Logfile Missing");
4678 obj->data.tail.readlines = 0;
4679 snprintf(p, p_max_size, "Logfile Missing");
4682 obj->data.tail.readlines = 0;
4683 /* -1 instead of 0 to avoid counting a trailing newline */
4684 fseek(fp, -1, SEEK_END);
4685 bsize = ftell(fp) + 1;
4686 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
4687 nl = rev_fcharfind(fp, '\n', iter);
4691 obj->data.tail.readlines = iter;
4692 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
4693 fseek(fp, 0, SEEK_SET);
4696 fseek(fp, nl+1, SEEK_SET);
4699 /* Make sure bsize is at least 1 byte smaller than
4700 * the buffer max size. */
4701 if(bsize > text_buffer_size*20 - 1) {
4702 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
4703 bsize = text_buffer_size*20 - 1;
4705 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
4708 /* Clean up trailing newline, make sure the buffer
4709 * is null terminated. */
4710 if(obj->data.tail.buffer[bsize-1] == '\n')
4711 obj->data.tail.buffer[bsize-1] = '\0';
4713 obj->data.tail.buffer[bsize] = '\0';
4714 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4717 strcpy(obj->data.tail.buffer, "Logfile Empty");
4718 snprintf(p, p_max_size, "Logfile Empty");
4721 } /* if cur_upd_time >= */
4723 //parse_conky_vars(obj->data.tail.buffer, p, cur);
4727 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4728 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4730 obj->data.tail.last_update = current_update_time;
4734 fp = fopen(obj->data.tail.logfile, "rt");
4736 /* Send one message, but do not consistently spam on
4737 * missing logfiles. */
4738 if(obj->data.tail.readlines != 0) {
4739 ERR("head logfile failed to open");
4740 strcpy(obj->data.tail.buffer, "Logfile Missing");
4742 obj->data.tail.readlines = 0;
4743 snprintf(p, p_max_size, "Logfile Missing");
4745 obj->data.tail.readlines = 0;
4746 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
4747 nl = fwd_fcharfind(fp, '\n', iter);
4751 obj->data.tail.readlines = iter;
4752 /* Make sure nl is at least 1 byte smaller than
4753 * the buffer max size. */
4754 if(nl > text_buffer_size*20 - 1) {
4755 nl = text_buffer_size*20 - 1;
4757 nl = fread(obj->data.tail.buffer, 1, nl, fp);
4760 /* Clean up trailing newline, make sure the buffer
4761 * is null terminated. */
4762 if (obj->data.tail.buffer[nl-1] == '\n') {
4763 obj->data.tail.buffer[nl-1] = '\0';
4766 obj->data.tail.buffer[nl] = '\0';
4768 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4771 strcpy(obj->data.tail.buffer, "Logfile Empty");
4772 snprintf(p, p_max_size, "Logfile Empty");
4774 } /* if fp == null */
4775 } /* cur_upd_time >= */
4777 //parse_conky_vars(obj->data.tail.buffer, p, cur);
4780 #ifdef TCP_PORT_MONITOR
4783 /* grab a pointer to this port monitor */
4784 tcp_port_monitor_t * p_monitor =
4785 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
4786 obj->data.tcp_port_monitor.port_range_begin,
4787 obj->data.tcp_port_monitor.port_range_end );
4789 snprintf(p, p_max_size, "monitor not found");
4793 /* now grab the text of interest */
4794 if ( peek_tcp_port_monitor( p_monitor,
4795 obj->data.tcp_port_monitor.item,
4796 obj->data.tcp_port_monitor.connection_index,
4797 p, p_max_size ) != 0 )
4799 snprintf(p, p_max_size, "monitor peek error");
4808 iconv_converting = 1;
4809 iconv_selected = obj->a;
4814 iconv_converting = 0;
4820 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
4822 OBJ(entropy_poolsize)
4824 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
4828 double entropy_perc;
4829 entropy_perc = (double)cur->entropy.entropy_avail /
4830 (double)cur->entropy.poolsize;
4831 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
4839 unsigned int a = strlen(p);
4842 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
4844 size_t dummy1, dummy2;
4845 char *ptr = buff_in;
4848 dummy1 = dummy2 = a;
4850 strncpy(buff_in, p, P_MAX_SIZE);
4852 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
4853 while (dummy1 > 0) {
4854 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
4856 ERR("Iconv codeset conversion failed");
4861 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
4872 double current_update_time, last_update_time;
4874 static void generate_text()
4876 struct information *cur = &info;
4884 current_update_time = get_time();
4887 /* fix diskio rates to b/s (use update_interval */
4888 diskio_read_value = diskio_read_value / update_interval;
4889 diskio_write_value = diskio_write_value / update_interval;
4890 diskio_value = diskio_value / update_interval;
4893 /* add things to the buffer */
4899 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
4901 if (stuff_in_upper_case) {
4912 last_update_time = current_update_time;
4919 static void set_font()
4923 if (window.xftdraw != NULL) {
4924 XftDrawDestroy(window.xftdraw);
4926 window.xftdraw = XftDrawCreate(display, window.drawable,
4927 DefaultVisual(display,
4929 DefaultColormap(display,
4934 XSetFont(display, window.gc, fonts[selected_font].font->fid);
4940 static inline int get_string_width(const char *s)
4943 return *s ? calc_text_width(s, strlen(s)) : 0;
4949 static inline int get_string_width_special(char *s)
4962 if (*p == SPECIAL_CHAR) {
4963 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
4964 for (i = 0; i < strlen(p); i++) {
4965 *(p + i) = *(p + i + 1);
4967 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
4968 width += specials[special_index+index].width;
4975 if (strlen(final) > 1) {
4976 width += calc_text_width(final, strlen(final));
4986 static void text_size_updater(char *s);
4988 int last_font_height;
4989 static void update_text_area()
4993 /* update text size if it isn't fixed */
4998 text_width = minimum_width;
5001 last_font_height = font_height();
5002 for_each_line(text_buffer, text_size_updater);
5004 if (text_height < minimum_height)
5005 text_height = minimum_height;
5006 if (text_width > maximum_width && maximum_width > 0)
5007 text_width = maximum_width;
5010 /* get text position on workarea */
5011 switch (text_alignment) {
5018 x = workarea[2] - text_width - gap_x;
5025 y = workarea[3] - text_height - gap_y;
5029 x = workarea[2] - text_width - gap_x;
5030 y = workarea[3] - text_height - gap_y;
5034 case NONE: // Let the WM manage the window
5045 if (own_window && !fixed_pos) {
5048 text_start_x = border_margin + 1;
5049 text_start_y = border_margin + 1;
5050 window.x = x - border_margin - 1;
5051 window.y = y - border_margin - 1;
5055 /* If window size doesn't match to workarea's size, then window
5056 * probably includes panels (gnome).
5057 * Blah, doesn't work on KDE. */
5058 if (workarea[2] != window.width
5059 || workarea[3] != window.height) {
5073 static int cur_x, cur_y; /* current x and y for drawing */
5074 static int draw_mode; /* FG, BG or OUTLINE */
5075 static long current_color;
5078 static void text_size_updater(char *s)
5082 /* get string widths and skip specials */
5085 if (*p == SPECIAL_CHAR) {
5087 w += get_string_width(s);
5090 if (specials[special_index].type == BAR
5091 || specials[special_index].type == GRAPH) {
5092 w += specials[special_index].width;
5093 if (specials[special_index].height > last_font_height) {
5094 last_font_height = specials[special_index].height;
5095 last_font_height += font_ascent();
5097 } else if (specials[special_index].type == OFFSET) {
5098 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
5099 } else if (specials[special_index].type == VOFFSET) {
5100 last_font_height += specials[special_index].arg;
5101 } else if (specials[special_index].type == GOTO) {
5102 if (specials[special_index].arg >= 0)
5103 w += (int)specials[special_index].arg - cur_x;
5104 } else if (specials[special_index].type == TAB) {
5105 int start = specials[special_index].arg;
5106 int step = specials[special_index].width;
5107 if (!step || step < 0)
5109 w += step - (cur_x - text_start_x - start) % step;
5110 } else if (specials[special_index].type == FONT) {
5111 selected_font = specials[special_index].font_added;
5112 if (font_height() > last_font_height) {
5113 last_font_height = font_height();
5122 w += get_string_width(s);
5123 if (w > text_width) {
5126 if (text_width > maximum_width && maximum_width) {
5127 text_width = maximum_width;
5130 text_height += last_font_height;
5131 last_font_height = font_height();
5135 static inline void set_foreground_color(long c)
5138 XSetForeground(display, window.gc, c);
5142 static void draw_string(const char *s)
5146 int i, i2, pos, width_of_s;
5149 width_of_s = get_string_width(s);
5150 if (out_to_console) {
5152 fflush(stdout); /* output immediately, don't buffer */
5154 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5155 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5156 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5160 snprintf(space, 2, " ");
5162 max = ((text_width - width_of_s) / get_string_width(space));
5165 * This code looks for tabs in the text and coverts them to spaces.
5166 * The trick is getting the correct number of spaces,
5167 * and not going over the window's size without forcing
5168 * the window larger.
5170 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5171 if (tmpstring1[i] == '\t') // 9 is ascii tab
5175 i2 < (8 - (1 + pos) % 8) && added <= max;
5178 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5179 fprintf(stderr,"buffer overrun detected\n");
5181 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5186 if (tmpstring1[i] != 9) {
5188 if ( pos > TEXT_BUFFER_SIZE-1 )
5189 fprintf(stderr,"buffer overrun detected\n");
5191 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5197 if (text_width == maximum_width) {
5198 /* this means the text is probably pushing the limit, so we'll chop it */
5199 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5200 tmpstring2[strlen(tmpstring2)-1] = '\0';
5210 c.pixel = current_color;
5211 XQueryColor(display, DefaultColormap(display, screen), &c);
5214 c2.color.red = c.red;
5215 c2.color.green = c.green;
5216 c2.color.blue = c.blue;
5217 c2.color.alpha = fonts[selected_font].font_alpha;
5219 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5220 cur_x, cur_y, (XftChar8 *) s,
5223 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5224 cur_x, cur_y, (XftChar8 *) s,
5230 XDrawString(display, window.drawable, window.gc,
5231 cur_x, cur_y, s, strlen(s));
5233 cur_x += width_of_s;
5235 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5238 long redmask, greenmask, bluemask;
5240 void set_up_gradient()
5243 colour_depth = DisplayPlanes(display, screen);
5247 if (colour_depth != 24 && colour_depth != 16) {
5248 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5254 for(i = (colour_depth / 3)-1; i>=0; i--) {
5256 greenmask |= 1 << i;
5259 if (colour_depth%3 == 1) {
5260 greenmask |= 1 << (colour_depth / 3);
5262 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5263 greenmask = greenmask << (colour_depth / 3);
5266 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 */
5268 int red1, green1, blue1; // first colour
5269 int red2, green2, blue2; // second colour
5270 int red3 = 0, green3 = 0, blue3 = 0; // difference
5271 short redshift = (2*colour_depth / 3 + colour_depth%3);
5272 short greenshift = (colour_depth / 3);
5273 red1 = (first_colour & redmask) >> redshift;
5274 green1 = (first_colour & greenmask) >> greenshift;
5275 blue1 = first_colour & bluemask;
5276 red2 = (last_colour & redmask) >> redshift;
5277 green2 = (last_colour & greenmask) >> greenshift;
5278 blue2 = last_colour & bluemask;
5285 if (green1 > green2) {
5288 if (green1 < green2) {
5291 if (blue1 > blue2) {
5294 if (blue1 < blue2) {
5309 if (red1 > bluemask) {
5312 if (green1 > bluemask) {
5315 if (blue1 > bluemask) {
5318 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
5322 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
5323 if (colour_depth == 0) {
5326 int red1, green1, blue1; // first colour
5327 int red2, green2, blue2; // second colour
5328 long redshift = (2*colour_depth / 3 + colour_depth%3);
5329 long greenshift = (colour_depth / 3);
5330 int red3 = 0, green3 = 0, blue3 = 0; // difference
5331 red1 = (first_colour & redmask) >> redshift;
5332 green1 = (first_colour & greenmask) >> greenshift;
5333 blue1 = first_colour & bluemask;
5334 red2 = (last_colour & redmask) >> redshift;
5335 green2 = (last_colour & greenmask) >> greenshift;
5336 blue2 = last_colour & bluemask;
5337 red3 = abs(red1 - red2);
5338 green3 = abs(green1 - green2);
5339 blue3 = abs(blue1 - blue2);
5348 static void draw_line(char *s)
5352 cur_x = text_start_x;
5353 cur_y += font_ascent();
5355 short font_h = font_height();
5357 /* find specials and draw stuff */
5360 if (*p == SPECIAL_CHAR) {
5363 /* draw string before special */
5370 switch (specials[special_index].type) {
5371 case HORIZONTAL_LINE:
5374 specials[special_index].height;
5375 int mid = font_ascent() / 2;
5376 w = text_start_x + text_width -
5379 XSetLineAttributes(display,
5384 XDrawLine(display, window.drawable,
5395 specials[special_index].height;
5397 specials[special_index].arg;
5398 int mid = font_ascent() / 2;
5399 char ss[2] = { s, s };
5400 w = text_start_x + text_width -
5403 XSetLineAttributes(display,
5408 XSetDashes(display, window.gc, 0,
5410 XDrawLine(display, window.drawable,
5420 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5424 specials[special_index].height;
5426 specials[special_index].arg;
5427 int by = cur_y - (font_ascent() / 2) - 1;
5428 if (h < font_height()) {
5431 w = specials[special_index].width;
5434 text_width - cur_x - 1;
5438 XSetLineAttributes(display,
5444 XDrawRectangle(display,
5448 XFillRectangle(display,
5452 w * bar_usage / 255,
5454 if (specials[special_index].
5456 && specials[special_index].
5460 [special_index].height;
5467 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5471 specials[special_index].height;
5472 unsigned long last_colour = current_color;
5473 int by = cur_y - (font_ascent()/2) - 1;
5474 if (h < font_height()) {
5477 w = specials[special_index].width;
5479 w = text_start_x + text_width - cur_x - 1;
5482 if (draw_graph_borders) {
5483 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
5484 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
5486 XSetLineAttributes(display,
5493 int gradient_size = 0;
5494 float gradient_factor = 0;
5495 float gradient_update = 0;
5496 unsigned long tmpcolour = current_color;
5497 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5498 tmpcolour = specials[special_index].last_colour;
5499 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
5500 gradient_factor = (float)gradient_size / (w - 2);
5502 for (i = w - 2; i > -1; i--) {
5503 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5504 XSetForeground(display, window.gc, tmpcolour);
5505 gradient_update += gradient_factor;
5506 while (gradient_update > 0) {
5507 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
5511 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
5514 XDrawLine(display, window.drawable, window.gc, cur_x + i + 1, by + h, cur_x + i + 1, by + h - specials[special_index].graph[j] * (h - 1) / specials[special_index].graph_scale); /* this is mugfugly, but it works */
5516 if (specials[special_index].
5518 && specials[special_index].
5522 [special_index].height;
5524 /* if (draw_mode == BG) {
5525 set_foreground_color(default_bg_color);
5527 else if (draw_mode == OUTLINE) {
5528 set_foreground_color(default_out_color);
5530 set_foreground_color(default_fg_color);
5532 set_foreground_color(last_colour);
5538 int old = font_ascent();
5539 cur_y -= font_ascent();
5540 selected_font = specials[special_index].font_added;
5541 if (cur_y + font_ascent() < cur_y + old) {
5544 cur_y += font_ascent();
5550 if (draw_mode == FG)
5551 set_foreground_color(specials
5557 if (draw_mode == BG)
5558 set_foreground_color(specials
5564 if (draw_mode == OUTLINE)
5565 set_foreground_color(specials
5571 w += specials[special_index].arg;
5575 cur_y += specials[special_index].arg;
5579 if (specials[special_index].arg >= 0)
5580 cur_x = (int)specials[special_index].arg;
5585 int start = specials[special_index].arg;
5586 int step = specials[special_index].width;
5587 if (!step || step < 0)
5589 w = step - (cur_x - text_start_x - start) % step;
5595 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
5596 /*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);*/
5597 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
5598 cur_x = pos_x - specials[special_index].arg;
5605 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
5606 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
5607 /*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);*/
5609 specials[special_index].arg)
5612 [special_index].arg;
5629 if (cur_y_add > 0) {
5631 cur_y -= font_descent();
5636 cur_y += font_descent();
5640 static void draw_text()
5643 cur_y = text_start_y;
5646 if (draw_borders && border_width > 0) {
5647 unsigned int b = (border_width + 1) / 2;
5649 if (stippled_borders) {
5651 { stippled_borders, stippled_borders };
5652 XSetLineAttributes(display, window.gc,
5653 border_width, LineOnOffDash,
5654 CapButt, JoinMiter);
5655 XSetDashes(display, window.gc, 0, ss, 2);
5657 XSetLineAttributes(display, window.gc,
5658 border_width, LineSolid,
5659 CapButt, JoinMiter);
5662 XDrawRectangle(display, window.drawable, window.gc,
5663 text_start_x - border_margin + b,
5664 text_start_y - border_margin + b,
5665 text_width + border_margin * 2 - 1 - b * 2,
5666 text_height + border_margin * 2 - 1 -
5673 for_each_line(text_buffer, draw_line);
5676 static void draw_stuff()
5680 if (draw_shades && !draw_outline) {
5683 set_foreground_color(default_bg_color);
5693 for (i = -1; i < 2; i++)
5694 for (j = -1; j < 2; j++) {
5695 if (i == 0 && j == 0)
5699 set_foreground_color(default_out_color);
5700 draw_mode = OUTLINE;
5707 set_foreground_color(default_fg_color);
5715 swap.swap_window = window.window;
5716 swap.swap_action = XdbeBackground;
5717 XdbeSwapBuffers(display, &swap, 1);
5723 static void clear_text(int exposures)
5727 return; /* The swap action is XdbeBackground, which clears */
5731 /* there is some extra space for borders and outlines */
5732 XClearArea(display, window.window,
5733 text_start_x - border_margin - 1,
5734 text_start_y - border_margin - 1,
5735 text_width + border_margin * 2 + 2,
5736 text_height + border_margin * 2 + 2,
5737 exposures ? True : 0);
5742 static int need_to_update;
5744 /* update_text() generates new text and clears old text area */
5745 static void update_text()
5754 static void main_loop()
5756 #ifdef SIGNAL_BLOCKING
5757 sigset_t newmask, oldmask;
5759 sigemptyset(&newmask);
5760 sigaddset(&newmask,SIGINT);
5761 sigaddset(&newmask,SIGTERM);
5762 sigaddset(&newmask,SIGUSR1);
5766 Region region = XCreateRegion();
5768 int event_base, error_base;
5769 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
5770 ERR("Xdamage extension unavailable");
5772 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
5773 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
5774 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
5775 #endif /* HAVE_XDAMAGE */
5779 while (total_run_times == 0 || info.looped < total_run_times) {
5782 #ifdef SIGNAL_BLOCKING
5783 /* block signals. we will inspect for pending signals later */
5784 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
5785 CRIT_ERR("unable to sigprocmask()");
5791 /* wait for X event or timeout */
5793 if (!XPending(display)) {
5798 update_interval - (get_time() -
5804 tv.tv_sec = (long) t;
5805 tv.tv_usec = (long) (t * 1000000) % 1000000;
5807 FD_SET(ConnectionNumber(display), &fdsr);
5810 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
5813 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
5818 ERR("can't select(): %s",
5829 if (need_to_update) {
5831 int wx = window.x, wy = window.y;
5839 /* resize window if it isn't right size */
5841 (text_width + border_margin * 2 + 1 !=
5843 || text_height + border_margin * 2 + 1 !=
5847 border_margin * 2 + 1;
5850 border_margin * 2 + 1;
5851 XResizeWindow(display,
5856 set_transparent_background(window.window);
5860 /* move window if it isn't in right position */
5863 || window.y != wy)) {
5864 XMoveWindow(display, window.window,
5865 window.x, window.y);
5875 r.x = text_start_x - border_margin;
5876 r.y = text_start_y - border_margin;
5877 r.width = text_width + border_margin * 2;
5878 r.height = text_height + border_margin * 2;
5879 XUnionRectWithRegion(&r, region, region);
5884 /* handle X events */
5886 while (XPending(display)) {
5888 XNextEvent(display, &ev);
5895 r.width = ev.xexpose.width;
5896 r.height = ev.xexpose.height;
5897 XUnionRectWithRegion(&r, region,
5903 case ReparentNotify:
5904 /* set background to ParentRelative for all parents */
5906 set_transparent_background(window.
5911 case ConfigureNotify:
5913 /* if window size isn't what expected, set fixed size */
5914 if (ev.xconfigure.width !=
5916 || ev.xconfigure.height !=
5918 if (window.width != 0
5919 && window.height != 0)
5922 /* clear old stuff before screwing up size and pos */
5928 if (XGetWindowAttributes(display, window.window, &attrs)) {
5943 border_margin * 2 - 1;
5946 border_margin * 2 - 1;
5947 if (text_width > maximum_width && maximum_width > 0)
5948 text_width = maximum_width;
5951 /* if position isn't what expected, set fixed pos, total_updates
5952 * avoids setting fixed_pos when window is set to weird locations
5954 /*if (total_updates >= 2 this is broken
5956 && (window.x != ev.xconfigure.x
5959 && (ev.xconfigure.x != 0
5960 || ev.xconfigure.y != 0)) {
5970 /* if an ordinary window with decorations */
5971 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
5973 /* allow conky to hold input focus.*/
5978 /* forward the click to the desktop window */
5979 XUngrabPointer(display, ev.xbutton.time);
5980 ev.xbutton.window = window.desktop;
5981 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
5982 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
5990 /* if an ordinary window with decorations */
5991 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
5993 /* allow conky to hold input focus.*/
5998 /* forward the release to the desktop window */
5999 ev.xbutton.window = window.desktop;
6000 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6009 if (ev.type == event_base + XDamageNotify) {
6010 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6011 XFixesSetRegion(display, part, &dev->area, 1);
6012 XFixesUnionRegion(display, region2, region2, part);
6014 #endif /* HAVE_XDAMAGE */
6019 XDamageSubtract(display, damage, region2, None);
6020 XFixesSetRegion(display, region2, 0, 0);
6021 #endif /* HAVE_XDAMAGE */
6023 /* XDBE doesn't seem to provide a way to clear the back buffer without
6024 * interfering with the front buffer, other than passing XdbeBackground
6025 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6026 * redraw the text even if it wasn't part of the exposed area. OTOH,
6027 * if we're not going to call draw_stuff at all, then no swap happens
6028 * and we can safely do nothing.
6031 if (!XEmptyRegion(region)) {
6035 r.x = text_start_x - border_margin;
6036 r.y = text_start_y - border_margin;
6037 r.width = text_width + border_margin * 2;
6038 r.height = text_height + border_margin * 2;
6039 XUnionRectWithRegion(&r, region, region);
6042 XSetRegion(display, window.gc, region);
6045 XftDrawSetClip(window.xftdraw, region);
6051 XDestroyRegion(region);
6052 region = XCreateRegion();
6056 #ifdef SIGNAL_BLOCKING
6057 /* unblock signals of interest and let handler fly */
6058 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6059 CRIT_ERR("unable to sigprocmask()");
6062 switch(g_signal_pending) {
6065 ERR("received SIGUSR1. reloading the config file.");
6072 ERR("received SIGINT or SIGTERM to terminate. bye!");
6075 XDestroyRegion(region);
6078 return; /* return from main_loop */
6083 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6084 * but didn't write any code to deal with it. if you don't want to
6085 * handle a signal, don't set a handler on it in the first place. */
6086 if (g_signal_pending)
6087 ERR("ignoring signal (%d)", g_signal_pending);
6094 #if defined(X11) && defined(HAVE_XDAMAGE)
6095 XDamageDestroy(display, damage);
6096 XFixesDestroyRegion(display, region2);
6097 XFixesDestroyRegion(display, part);
6098 XDestroyRegion(region);
6100 #endif /* X11 && HAVE_XDAMAGE */
6103 static void load_config_file(const char *);
6105 /* reload the config file */
6106 void reload_config(void)
6108 timed_thread_destroy_registered_threads ();
6110 if (info.cpu_usage) {
6111 free(info.cpu_usage);
6112 info.cpu_usage = NULL;
6115 #ifdef TCP_PORT_MONITOR
6116 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6119 if (current_config) {
6121 load_config_file(current_config);
6123 /* re-init specials array */
6124 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6125 ERR("failed to realloc specials array");
6130 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6133 #ifdef TCP_PORT_MONITOR
6134 info.p_tcp_port_monitor_collection = NULL;
6137 if (create_audacious_thread() !=0)
6138 CRIT_ERR("unable to create audacious thread!");
6139 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6141 extract_variable_text(text);
6150 timed_thread_destroy_registered_threads ();
6152 if (info.cpu_usage) {
6153 free(info.cpu_usage);
6154 info.cpu_usage = NULL;
6159 XdbeDeallocateBackBufferName(display, window.back_buffer);
6165 XDestroyWindow(display, window.window);
6166 XClearWindow(display, RootWindow(display, screen));
6172 XClearWindow(display, RootWindow(display, screen));
6177 XFreeGC(display, window.gc);
6180 free_text_objects(text_object_count, text_objects);
6181 text_object_count = 0;
6182 text_objects = NULL;
6184 if (text != original_text)
6187 free(current_config);
6188 free(current_mail_spool);
6190 #ifdef TCP_PORT_MONITOR
6191 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6192 info.p_tcp_port_monitor_collection = NULL;
6200 #ifdef HAVE_LIBDEXTER
6201 dexter_library_exit ();
6203 free (dexter_config);
6207 static int string_to_bool(const char *s)
6211 if (strcasecmp(s, "yes") == 0)
6213 if (strcasecmp(s, "true") == 0)
6215 if (strcasecmp(s, "1") == 0)
6220 static enum alignment string_to_alignment(const char *s)
6222 if (strcasecmp(s, "top_left") == 0)
6224 else if (strcasecmp(s, "top_right") == 0)
6226 else if (strcasecmp(s, "bottom_left") == 0)
6228 else if (strcasecmp(s, "bottom_right") == 0)
6229 return BOTTOM_RIGHT;
6230 else if (strcasecmp(s, "tl") == 0)
6232 else if (strcasecmp(s, "tr") == 0)
6234 else if (strcasecmp(s, "bl") == 0)
6236 else if (strcasecmp(s, "br") == 0)
6237 return BOTTOM_RIGHT;
6238 else if (strcasecmp(s, "none") == 0)
6245 static void set_default_configurations(void)
6247 fork_to_background = 0;
6248 total_run_times = 0;
6249 info.cpu_avg_samples = 2;
6250 info.net_avg_samples = 2;
6255 strcpy(info.mpd.host, "localhost");
6256 info.mpd.port = 6600;
6257 info.mpd.status = NULL;
6258 info.mpd.artist = NULL;
6259 info.mpd.album = NULL;
6260 info.mpd.title = NULL;
6261 info.mpd.random = NULL;
6262 info.mpd.track = NULL;
6263 info.mpd.name = NULL;
6264 info.mpd.file = NULL;
6267 info.xmms2.artist = NULL;
6268 info.xmms2.album = NULL;
6269 info.xmms2.title = NULL;
6270 info.xmms2.genre = NULL;
6271 info.xmms2.comment = NULL;
6272 info.xmms2.decoder = NULL;
6273 info.xmms2.transport = NULL;
6274 info.xmms2.url = NULL;
6275 info.xmms2.status = NULL;
6284 default_fg_color = WhitePixel(display, screen);
6285 default_bg_color = BlackPixel(display, screen);
6286 default_out_color = BlackPixel(display, screen);
6289 draw_graph_borders = 1;
6291 set_first_font("6x10");
6299 window.type=TYPE_NORMAL;
6301 strcpy(window.class_name, "Conky");
6303 sprintf(window.title,"%s - conky",info.uname_s.nodename);
6305 stippled_borders = 0;
6308 text_alignment = BOTTOM_LEFT;
6311 free(current_mail_spool);
6314 variable_substitute(MAIL_FILE, buf, 256);
6316 current_mail_spool = strdup(buf);
6320 update_interval = 10.0;
6321 stuff_in_upper_case = 0;
6323 #ifdef TCP_PORT_MONITOR
6324 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6328 static void load_config_file(const char *f)
6330 #define CONF_ERR ERR("%s: %d: config file error", f, line)
6334 set_default_configurations();
6340 char buf[256], *p, *p2, *name, *value;
6342 if (fgets(buf, 256, fp) == NULL)
6347 /* break at comment */
6348 p2 = strchr(p, '#');
6353 while (*p && isspace((int) *p))
6356 continue; /* empty line */
6362 while (*p2 && !isspace((int) *p2))
6365 *p2 = '\0'; /* break at name's end */
6372 while (*p && isspace((int) *p))
6377 p2 = value + strlen(value);
6378 while (isspace((int) *(p2 - 1)))
6384 #define CONF2(a) if (strcasecmp(name, a) == 0)
6385 #define CONF(a) else CONF2(a)
6386 #define CONF3(a,b) \
6387 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
6391 CONF2("alignment") {
6393 int a = string_to_alignment(value);
6401 CONF("background") {
6402 fork_to_background = string_to_bool(value);
6406 CONF2("background") {
6407 fork_to_background = string_to_bool(value);
6411 CONF("border_margin") {
6413 border_margin = strtol(value, 0, 0);
6417 CONF("border_width") {
6419 border_width = strtol(value, 0, 0);
6423 CONF("default_color") {
6425 default_fg_color = get_x11_color(value);
6429 CONF3("default_shade_color", "default_shadecolor") {
6431 default_bg_color = get_x11_color(value);
6435 CONF3("default_outline_color", "default_outlinecolor") {
6437 default_out_color = get_x11_color(value);
6444 info.mail = parse_mail_args(IMAP, value);
6451 info.mail = parse_mail_args(POP3, value);
6459 strncpy(info.mpd.host, value, 127);
6465 info.mpd.port = strtol(value, 0, 0);
6466 if (info.mpd.port < 1
6467 || info.mpd.port > 0xffff)
6471 CONF("mpd_password") {
6473 strncpy(info.mpd.password, value, 127);
6478 CONF("cpu_avg_samples") {
6480 cpu_avg_samples = strtol(value, 0, 0);
6481 if (cpu_avg_samples < 1
6482 || cpu_avg_samples > 14)
6491 CONF("net_avg_samples") {
6493 net_avg_samples = strtol(value, 0, 0);
6494 if (net_avg_samples < 1
6495 || net_avg_samples > 14)
6511 CONF("double_buffer") {
6512 use_xdbe = string_to_bool(value);
6516 CONF("override_utf8_locale") {
6517 utf8_mode = string_to_bool(value);
6520 CONF("draw_borders") {
6521 draw_borders = string_to_bool(value);
6523 CONF("draw_graph_borders") {
6524 draw_graph_borders = string_to_bool(value);
6526 CONF("draw_shades") {
6527 draw_shades = string_to_bool(value);
6529 CONF("draw_outline") {
6530 draw_outline = string_to_bool(value);
6533 CONF("out_to_console") {
6534 out_to_console = string_to_bool(value);
6536 CONF("use_spacer") {
6537 use_spacer = string_to_bool(value);
6542 use_xft = string_to_bool(value);
6546 set_first_font(value);
6551 if (value && font_count >= 0)
6552 fonts[0].font_alpha = atof(value)
6561 if (string_to_bool(value))
6562 ERR("Xft not enabled");
6565 /* xftfont silently ignored when no Xft */
6568 /* xftalpha is silently ignored when no Xft */
6573 set_first_font(value);
6582 gap_x = atoi(value);
6588 gap_y = atoi(value);
6593 CONF("mail_spool") {
6596 variable_substitute(value, buf, 256);
6600 if (current_mail_spool)
6601 free(current_mail_spool);
6602 current_mail_spool = strdup(buf);
6608 CONF("minimum_size") {
6611 (value, "%d %d", &minimum_width,
6612 &minimum_height) != 2)
6615 &minimum_width) != 1)
6620 CONF("maximum_width") {
6622 if (sscanf(value, "%d", &maximum_width) != 1)
6628 CONF("no_buffers") {
6629 no_buffers = string_to_bool(value);
6631 CONF("pad_percents") {
6632 pad_percents = atoi(value);
6636 CONF("own_window") {
6638 own_window = string_to_bool(value);
6642 CONF("own_window_class") {
6645 memset(window.class_name,0,sizeof(window.class_name));
6646 strncpy(window.class_name, value, sizeof(window.class_name)-1);
6651 CONF("own_window_title") {
6654 memset(window.title,0,sizeof(window.title));
6655 strncpy(window.title, value, sizeof(window.title)-1);
6660 CONF("own_window_transparent") {
6662 set_transparent = string_to_bool(value);
6666 CONF("own_window_colour") {
6668 background_colour = get_x11_color(value);
6670 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
6673 CONF("own_window_hints") {
6675 char *p_hint, *p_save;
6676 char delim[] = ", ";
6678 /* tokenize the value into individual hints */
6679 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
6681 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
6682 if (strncmp(p_hint,"undecorate",10) == 0)
6683 SET_HINT(window.hints,HINT_UNDECORATED);
6684 else if (strncmp(p_hint,"below",5) == 0)
6685 SET_HINT(window.hints,HINT_BELOW);
6686 else if (strncmp(p_hint,"above",5) == 0)
6687 SET_HINT(window.hints,HINT_ABOVE);
6688 else if (strncmp(p_hint,"sticky",6) == 0)
6689 SET_HINT(window.hints,HINT_STICKY);
6690 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
6691 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
6692 else if (strncmp(p_hint,"skip_pager",10) == 0)
6693 SET_HINT(window.hints,HINT_SKIP_PAGER);
6697 p_hint=strtok_r(NULL, delim, &p_save);
6699 while (p_hint!=NULL);
6704 CONF("own_window_type") {
6706 if (strncmp(value,"normal",6)==0)
6707 window.type = TYPE_NORMAL;
6708 else if (strncmp(value,"desktop",7)==0)
6709 window.type = TYPE_DESKTOP;
6710 else if (strncmp(value,"override",8)==0)
6711 window.type = TYPE_OVERRIDE;
6719 CONF("stippled_borders") {
6721 stippled_borders = strtol(value, 0, 0);
6723 stippled_borders = 4;
6727 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
6730 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
6732 CONF("update_interval") {
6734 update_interval = strtod(value, 0);
6738 CONF("total_run_times") {
6740 total_run_times = strtod(value, 0);
6745 stuff_in_upper_case = string_to_bool(value);
6747 CONF("max_specials") {
6749 max_specials = atoi(value);
6753 CONF("max_user_text") {
6755 max_user_text = atoi(value);
6759 CONF("text_buffer_size") {
6761 text_buffer_size = atoi(value);
6766 if (text != original_text)
6776 int l = strlen(text);
6777 if (fgets(buf, 256, fp) == NULL)
6780 realloc(text, l + strlen(buf)
6784 if (strlen(text) > max_user_text)
6788 text_lines = line + 1;
6791 #ifdef TCP_PORT_MONITOR
6792 CONF("max_port_monitor_connections")
6795 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
6796 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
6798 /* an error. use default, warn and continue. */
6799 tcp_port_monitor_args.max_port_monitor_connections =
6800 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6803 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
6805 /* no error, just use default */
6806 tcp_port_monitor_args.max_port_monitor_connections =
6807 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6809 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
6812 #ifdef HAVE_LIBDEXTER
6813 CONF("dexter_client")
6816 dexter_client = string_to_bool (value);
6820 CONF("dexter_server")
6823 dexter_server = string_to_bool (value);
6827 CONF("dexter_config")
6830 dexter_config = strdup (value);
6837 ERR("%s: %d: no such configuration: '%s'", f, line, name);
6849 /* : means that character before that takes an argument */
6850 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
6863 int main(int argc, char **argv)
6865 struct sigaction act, oact;
6868 memset(&info, 0, sizeof(info) );
6870 #ifdef TCP_PORT_MONITOR
6871 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6874 /* handle command line parameters that don't change configs */
6879 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
6880 *s) || ((s = getenv("LANG")) && *s)) {
6881 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
6883 ERR("malloc failed");
6885 for (x = 0; x < strlen(s); x++) {
6886 temp[x] = tolower(s[x]);
6888 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
6894 if (!setlocale(LC_CTYPE, "")) {
6895 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
6899 int c = getopt(argc,
6910 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
6911 * though free() does the NULL check itself;), then load optarg value */
6913 free(current_config);
6914 current_config = strdup(optarg);
6919 ("Usage: %s [OPTION]...\n"
6920 "Conky is a system monitor that renders text on desktop or to own transparent\n"
6921 "window. Command line options will override configurations defined in config\n"
6924 " -c FILE config file to load instead of "
6927 " -d daemonize, fork to background\n"
6930 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
6931 " -f FONT font to use\n"
6933 " -o create own window to draw\n"
6936 " -b double buffer (prevents flickering)\n"
6938 " -w WIN_ID window id to draw\n"
6939 " -x X x position\n"
6940 " -y Y y position\n"
6942 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
6943 " -u SECS update interval\n"
6944 " -i NUM number of times to update Conky\n", argv[0]);
6948 window.window = strtol(optarg, 0, 0);
6957 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
6961 /* load current_config or CONFIG_FILE */
6964 if (current_config == NULL) {
6965 /* load default config file */
6968 variable_substitute(CONFIG_FILE, buf, 256);
6971 current_config = strdup(buf);
6975 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
6976 load_config_file(current_config);
6978 set_default_configurations();
6981 /* init specials array */
6982 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
6983 ERR("failed to create specials array");
6986 if (current_mail_spool == NULL) {
6988 variable_substitute(MAIL_FILE, buf, 256);
6991 current_mail_spool = strdup(buf);
6995 /* handle other command line arguments */
6997 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
6998 optind = optreset = 1;
7003 #if defined(__FreeBSD__)
7004 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7005 O_RDONLY, "kvm_open")) == NULL)
7006 CRIT_ERR( "cannot read kvm");
7010 int c = getopt(argc,
7018 fork_to_background = 1;
7023 set_first_font(optarg);
7026 text_alignment = string_to_alignment(optarg);
7041 if (text != original_text)
7043 text = strdup(optarg);
7044 convert_escapes(text);
7048 update_interval = strtod(optarg, 0);
7052 total_run_times = strtod(optarg, 0);
7056 gap_x = atoi(optarg);
7060 gap_y = atoi(optarg);
7074 /* generate text and get initial size */
7075 extract_variable_text(text);
7076 if (text != original_text) {
7081 if (fork_to_background) {
7085 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
7091 fprintf(stderr,"\n"); fflush(stderr);
7095 /* parent process */
7096 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
7101 #ifdef HAVE_LIBDEXTER
7102 memset (&packet_arrival_time, 0, sizeof (struct timespec));
7103 dexter_library_init ();
7106 /* wait until some data packets arrive, else conky complains
7107 * bittery that /proc filesystems cannot be opened and, worse,
7108 * will likely segfault when it references unchecked pointers
7109 * in get_text_internal() -- those should be cleaned up.
7112 const int max_tries=30;
7113 gboolean got_packet;
7115 fprintf (stderr, "Conky: waiting for data packets to arrive ...\n");
7116 for (try=0;try<max_tries;try++)
7118 /* pause main thread for 1 sec */
7119 g_get_current_time (&timeval);
7120 g_time_val_add (&timeval, G_USEC_PER_SEC);
7121 g_mutex_lock (packet_mutex);
7122 /* mutex released before sleeping; re-acquired after time elapses */
7123 g_cond_timed_wait (packet_cond, packet_mutex, &timeval);
7124 got_packet = packet_arrival_time.tv_sec>0;
7125 g_mutex_unlock (packet_mutex);
7132 fprintf(stderr, "Conky: packets arriving ...\n");
7136 fprintf(stderr, "Conky: no data packets ...\n");
7137 dexter_library_exit ();
7145 update_text_area(); /* to get initial size of the window */
7149 text_width + border_margin * 2 + 1,
7150 text_height + border_margin * 2 + 1,
7151 set_transparent, background_colour, argv, argc);
7154 update_text_area(); /* to position text/window on screen */
7159 if (own_window && !fixed_pos) {
7160 XMoveWindow(display, window.window, window.x, window.y);
7163 set_transparent_background(window.window);
7174 /* Set signal handlers */
7175 act.sa_handler = signal_handler;
7176 sigemptyset(&act.sa_mask);
7179 act.sa_flags |= SA_RESTART;
7182 if ( sigaction(SIGINT,&act,&oact) < 0 ||
7183 sigaction(SIGUSR1,&act,&oact) < 0 ||
7184 sigaction(SIGTERM,&act,&oact) < 0 )
7186 ERR("error setting signal handler: %s", strerror(errno) );
7190 if (create_audacious_thread() !=0)
7191 CRIT_ERR("unable to create audacious thread!");
7192 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
7203 #if defined(__FreeBSD__)
7210 void signal_handler(int sig)
7212 /* signal handler is light as a feather, as it should be.
7213 * we will poll g_signal_pending with each loop of conky
7214 * and do any signal processing there, NOT here. */
7215 g_signal_pending=sig;
7218 #ifdef HAVE_LIBDEXTER
7219 void dexter_library_init (void)
7221 /* start libdexter */
7222 if (dexter_client || dexter_server)
7224 GError *error = NULL;
7225 dexter_init (dexter_config, &error);
7227 CRIT_ERR ("%s", error->message);
7231 if (!(info.dexter.channel = dexter_channel_new (NULL, NULL, NULL, dexter_channel_events)))
7232 CRIT_ERR("unable to create channel to server");
7233 dexter_channel_open (info.dexter.channel, &error);
7235 CRIT_ERR ("%s", error->message);
7236 dexter_channel_greet (info.dexter.channel, &error);
7238 CRIT_ERR ("%s", error->message);
7239 if (dexter_client_init () < 0)
7240 CRIT_ERR ("error initializing dexter client");
7242 packet_mutex = g_mutex_new ();
7243 packet_cond = g_cond_new ();
7248 if (!(info.dexter.server = dexter_server_new (NULL, NULL, NULL)))
7249 CRIT_ERR("unable to create server");
7250 dexter_server_start (info.dexter.server, &error);
7252 CRIT_ERR ("%s", error->message);
7258 void dexter_library_exit (void)
7260 /* shutdown libdexter */
7261 if (dexter_client || dexter_server)
7263 GError *error = NULL;
7267 if (dexter_client_exit () < 0)
7268 ERR ("error de-initializing dexter client");
7269 if (info.dexter.channel)
7271 dexter_channel_part (info.dexter.channel, &error);
7274 ERR("%s", error->message);
7275 g_clear_error (&error);
7277 dexter_channel_close (info.dexter.channel, &error);
7280 ERR("%s", error->message);
7281 g_clear_error (&error);
7283 dexter_channel_free (info.dexter.channel);
7284 info.dexter.channel=NULL;
7289 g_mutex_free (packet_mutex);
7294 g_cond_free (packet_cond);
7301 if (info.dexter.server)
7303 dexter_server_stop (info.dexter.server, &error);
7306 ERR("%s", error->message);
7307 g_clear_error (&error);
7309 dexter_server_free (info.dexter.server);
7310 info.dexter.server=NULL;
7318 void dexter_channel_events (DexterChannel *channel, gint event)
7323 /* if server disconnects we get this event. we also get it normally
7324 * following dexter_channel_part(). */
7325 if (event == DEXTER_CHANNEL_EVENT_NOCONN)
7327 fprintf (stderr, "Conky: channel to server closed\n");
7328 if (dexter_client && (dexter_client_exit () < 0))
7329 ERR ("error de-initializing dexter client");