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;
320 static int sensor_device;
323 static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
325 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
326 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
328 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
329 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
331 /* maximum size of individual text buffers, ie $exec buffer size */
332 unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
335 #define CODEPAGE_LENGTH 20
337 long iconv_count = 0;
338 char iconv_converting;
339 static iconv_t **iconv_cd = 0;
341 int register_iconv(iconv_t *new_iconv)
344 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
346 iconv_cd = malloc(sizeof(iconv_t *));
349 CRIT_ERR("Out of memory");
351 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
352 if (!iconv_cd[iconv_count]) {
353 CRIT_ERR("Out of memory");
355 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
360 void free_iconv(void)
364 for (i = 0; i < iconv_count; i++) {
366 iconv_close(*iconv_cd[i]);
381 /* no buffers in used memory? */
384 /* pad percentages to decimals? */
385 static int pad_percents = 0;
387 #ifdef TCP_PORT_MONITOR
388 tcp_port_monitor_args_t tcp_port_monitor_args;
391 /* Text that is shown */
392 static char original_text[] =
393 "$nodename - $sysname $kernel on $machine\n"
395 "${color grey}Uptime:$color $uptime\n"
396 "${color grey}Frequency (in MHz):$color $freq\n"
397 "${color grey}Frequency (in GHz):$color $freq_g\n"
398 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
399 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
400 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
401 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
403 "${color grey}File systems:\n"
404 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
405 "${color grey}Networking:\n"
406 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
409 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
410 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
413 "${color grey}XMMS2: $xmms2_status $xmms2_artist - $xmms2_title from $xmms2_album\n"
414 "Progress: $xmms2_bar\n"
416 "${color grey}Name PID CPU% MEM%\n"
417 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
418 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
419 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
420 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
421 "${tail /var/log/Xorg.0.log 3}";
423 static char *text = original_text;
426 static int total_updates;
429 static int blockdepth = 0;
430 static int if_jumped = 0;
431 static int blockstart[MAX_IF_BLOCK_DEPTH];
433 int check_contains(char *f, char *s)
436 FILE *where = fopen(f, "r");
438 char buf1[256], buf2[256];
439 while (fgets(buf1, 256, where)) {
440 sscanf(buf1, "%255s", buf2);
441 if (strstr(buf2, s)) {
448 ERR("Could not open the file");
455 static inline int calc_text_width(const char *s, int l)
461 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
463 XftTextExtents8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
469 return XTextWidth(fonts[selected_font].font, s, l);
474 /* formatted text to render on screen, generated in generate_text(),
475 * drawn in draw_stuff() */
477 static char text_buffer[TEXT_BUFFER_SIZE * 4];
479 /* special stuff in text_buffer */
481 #define SPECIAL_CHAR '\x01'
510 unsigned long first_colour; // for graph gradient
511 unsigned long last_colour;
514 /* create specials array on heap instead of stack with introduction of max_specials */
515 static struct special_t *specials = NULL;
517 static unsigned int special_count;
519 static unsigned int special_index; /* used when drawing */
522 #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? */
524 static struct special_t *new_special(char *buf, int t)
526 if (special_count >= max_specials)
527 CRIT_ERR("too many special things in text");
529 buf[0] = SPECIAL_CHAR;
531 specials[special_count].type = t;
532 return &specials[special_count++];
535 long fwd_fcharfind(FILE* fp, char val, unsigned int step) {
538 unsigned int count = 0;
539 static char buf[BUFSZ];
540 long orig_pos = ftell(fp);
542 long buf_size = BUFSZ;
543 char* cur_found = NULL;
544 while(count < step) {
545 if(cur_found == NULL) {
546 buf_size = fread(buf, 1, buf_size, fp);
549 cur_found = memchr(buf+buf_pos, val, buf_size-buf_pos);
550 if(cur_found != NULL) {
551 buf_pos = cur_found-buf+1;
560 ret = ftell(fp) - buf_size + buf_pos - 1;
561 fseek(fp, orig_pos, SEEK_SET);
568 memrchr (const void *buffer, int c, size_t n)
570 const unsigned char *p = buffer;
572 for (p += n; n ; n--)
578 long rev_fcharfind(FILE* fp, char val, unsigned int step) {
581 unsigned int count = 0;
582 static char buf[BUFSZ];
583 long orig_pos = ftell(fp);
585 long file_pos = orig_pos;
586 long buf_size = BUFSZ;
588 while(count < step) {
590 if(file_pos > BUFSZ) {
591 fseek(fp, file_pos-BUFSZ, SEEK_SET);
595 fseek(fp, 0, SEEK_SET);
597 file_pos = ftell(fp);
598 buf_pos = fread(buf, 1, buf_size, fp);
605 if(cur_found != NULL) {
606 buf_pos = cur_found-buf;
615 fseek(fp, orig_pos, SEEK_SET);
617 ret = file_pos + buf_pos;
622 static void new_bar(char *buf, int w, int h, int usage)
624 struct special_t *s = new_special(buf, BAR);
625 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
630 static const char *scan_bar(const char *args, int *w, int *h)
632 *w = 0; /* zero width means all space that is available */
634 /* bar's argument is either height or height,width */
637 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
638 sscanf(args, "%d %n", h, &n);
645 static char *scan_font(const char *args)
654 static void new_font(char *buf, char * args) {
656 struct special_t *s = new_special(buf, FONT);
657 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
658 int tmp = selected_font;
659 selected_font = s->font_added = addfont(args);
664 struct special_t *s = new_special(buf, FONT);
665 int tmp = selected_font;
666 selected_font = s->font_added = 0;
673 inline void graph_append(struct special_t *graph, double f)
675 if (!graph->scaled && f > graph->graph_scale) {
676 f = graph->graph_scale;
680 graph->graph_scale = 1;
682 graph->graph[0] = f; /* add new data */
683 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
684 graph->graph[i] = graph->graph[i - 1];
685 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
686 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
691 short colour_depth = 0;
692 void set_up_gradient();
694 /* precalculated: 31/255, and 63/255 */
695 #define CONST_8_TO_5_BITS 0.12156862745098
696 #define CONST_8_TO_6_BITS 0.247058823529412
698 /* adjust color values depending on color depth*/
699 static unsigned int adjust_colors(unsigned int color)
702 if (colour_depth == 0) {
705 if (colour_depth == 16) {
706 r = (color & 0xff0000) >> 16;
707 g = (color & 0xff00) >> 8;
709 color = (int)(r * CONST_8_TO_5_BITS) << 11;
710 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
711 color |= (int)(b * CONST_8_TO_5_BITS);
716 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
718 struct special_t *s = new_special(buf, GRAPH);
720 if (s->graph == NULL) {
721 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
722 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
724 s->graph_width = MAX_GRAPH_DEPTH - 2;
726 s->graph = malloc(s->graph_width * sizeof(double));
727 memset(s->graph, 0, s->graph_width * sizeof(double));
728 s->graph_scale = 100;
731 s->first_colour = adjust_colors(first_colour);
732 s->last_colour = adjust_colors(second_colour);
739 s->graph_width = s->width - 2; // subtract 2 for rectangle around
744 s->graph_scale = scale;
751 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
753 *w = 0; /* zero width means all space that is available */
757 /* graph's argument is either height or height,width */
759 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
760 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
762 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
764 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
767 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
771 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
774 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
778 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
781 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
785 if (sscanf(args, "%d,%d", h, w) < 2) {
788 sscanf(args, "%*s %d,%d", h, w);
794 static inline void new_hr(char *buf, int a)
796 new_special(buf, HORIZONTAL_LINE)->height = a;
799 static inline void new_stippled_hr(char *buf, int a, int b)
801 struct special_t *s = new_special(buf, STIPPLED_HR);
806 static inline void new_fg(char *buf, long c)
808 new_special(buf, FG)->arg = c;
811 static inline void new_bg(char *buf, long c)
813 new_special(buf, BG)->arg = c;
816 static inline void new_outline(char *buf, long c)
818 new_special(buf, OUTLINE)->arg = c;
821 static inline void new_offset(char *buf, long c)
823 new_special(buf, OFFSET)->arg = c;
826 static inline void new_voffset(char *buf, long c)
828 new_special(buf, VOFFSET)->arg = c;
831 static inline void new_alignr(char *buf, long c)
833 new_special(buf, ALIGNR)->arg = c;
836 static inline void new_alignc(char *buf, long c)
838 new_special(buf, ALIGNC)->arg = c;
841 static inline void new_goto(char *buf, long c)
843 new_special(buf, GOTO)->arg = c;
846 static inline void new_tab(char *buf, int a, int b) {
847 struct special_t *s = new_special(buf, TAB);
852 /* quite boring functions */
854 static inline void for_each_line(char *b, void (*f) (char *))
858 for (ps = b, pe = b; *pe; pe++) {
871 static void convert_escapes(char *buf)
873 char *p = buf, *s = buf;
889 /* converts from bytes to human readable format (k, M, G, T) */
890 static void human_readable(long long a, char *buf, int size)
892 // Strange conditional due to possible overflows
893 if(a / 1024 / 1024 / 1024.0 > 1024.0){
894 snprintf(buf, size, "%.2fTiB", (a / 1024 / 1024 / 1024) / 1024.0);
896 else if (a >= 1024 * 1024 * 1024) {
897 snprintf(buf, size, "%.2fGiB", (a / 1024 / 1024) / 1024.0);
899 else if (a >= 1024 * 1024) {
900 double m = (a / 1024) / 1024.0;
902 snprintf(buf, size, "%.0fMiB", m);
904 snprintf(buf, size, "%.1fMiB", m);
905 } else if (a >= 1024)
906 snprintf(buf, size, "%LdKiB", a / (long long) 1024);
908 snprintf(buf, size, "%LdB", a);
913 enum text_object_type {
947 OBJ_diskiograph_read,
948 OBJ_diskiograph_write,
981 #if defined(__linux__)
987 OBJ_i8k_left_fan_status,
988 OBJ_i8k_right_fan_status,
989 OBJ_i8k_left_fan_rpm,
990 OBJ_i8k_right_fan_rpm,
992 OBJ_i8k_buttons_status,
1000 #endif /* __linux__ */
1029 OBJ_running_processes,
1038 OBJ_temp1, /* i2c is used instead in these */
1058 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1060 OBJ_apm_battery_time,
1061 OBJ_apm_battery_life,
1062 #endif /* __FreeBSD__ __OpenBSD__ */
1064 OBJ_obsd_sensors_temp,
1065 OBJ_obsd_sensors_fan,
1066 OBJ_obsd_sensors_volt,
1069 #endif /* __OpenBSD__ */
1098 OBJ_xmms2_transport,
1113 OBJ_audacious_status,
1114 OBJ_audacious_title,
1115 OBJ_audacious_length,
1116 OBJ_audacious_length_seconds,
1117 OBJ_audacious_position,
1118 OBJ_audacious_position_seconds,
1119 OBJ_audacious_bitrate,
1120 OBJ_audacious_frequency,
1121 OBJ_audacious_channels,
1122 OBJ_audacious_filename,
1123 OBJ_audacious_playlist_length,
1124 OBJ_audacious_playlist_position,
1138 #ifdef TCP_PORT_MONITOR
1149 OBJ_entropy_poolsize,
1153 struct text_object {
1157 unsigned int c, d, e;
1161 char *s; /* some string */
1162 int i; /* some integer */
1163 long l; /* some other integer */
1164 unsigned int sensor;
1165 struct net_stat *net;
1167 unsigned char loadavg[3];
1168 unsigned int cpu_index;
1169 struct mail_s *mail;
1177 char *tz; /* timezone variable */
1178 char *fmt; /* time display formatting */
1231 timed_thread *p_timed_thread;
1237 #ifdef TCP_PORT_MONITOR
1239 in_port_t port_range_begin; /* starting port to monitor */
1240 in_port_t port_range_end; /* ending port to monitor */
1241 int item; /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1242 int connection_index; /* 0 to n-1 connections. */
1263 struct text_object_list {
1264 unsigned int text_object_count;
1265 struct text_object *text_objects;
1268 static unsigned int text_object_count;
1269 static struct text_object *text_objects;
1270 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1272 #define MAXDATASIZE 1000
1276 struct mail_s* parse_mail_args(char type, const char *arg) {
1277 struct mail_s *mail;
1278 mail = malloc(sizeof(struct mail_s));
1279 memset(mail, 0, sizeof(struct mail_s));
1281 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1283 ERR("Scanning IMAP args failed");
1284 } else if (type == IMAP) {
1285 ERR("Scanning POP3 args failed");
1288 // see if password needs prompting
1289 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1290 int fp = fileno(stdin);
1291 struct termios term;
1292 tcgetattr(fp, &term);
1293 term.c_lflag &= ~ECHO;
1294 tcsetattr(fp, TCSANOW, &term);
1295 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1296 scanf("%128s", mail->pass);
1298 term.c_lflag |= ECHO;
1299 tcsetattr(fp, TCSANOW, &term);
1301 // now we check for optional args
1302 tmp = strstr(arg, "-i ");
1305 sscanf(tmp, "%f", &mail->interval);
1307 mail->interval = 300; // 5 minutes
1309 tmp = strstr(arg, "-p ");
1312 sscanf(tmp, "%lu", &mail->port);
1315 mail->port = 110; // default pop3 port
1316 } else if (type == IMAP) {
1317 mail->port = 143; // default imap port
1321 tmp = strstr(arg, "-f ");
1324 sscanf(tmp, "%s", mail->folder);
1326 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1329 tmp = strstr(arg, "-e ");
1333 if (tmp[0] == '\'') {
1334 len = strstr(tmp+1, "'") - tmp - 1;
1339 strncpy(mail->command, tmp+1, len);
1341 mail->command[0] = '\0';
1343 mail->p_timed_thread = NULL;
1347 void *imap_thread(struct mail_s* mail)
1349 int sockfd, numbytes;
1350 char recvbuf[MAXDATASIZE];
1351 char sendbuf[MAXDATASIZE];
1354 unsigned int old_unseen = UINT_MAX;
1355 unsigned int old_messages = UINT_MAX;
1356 struct stat stat_buf;
1358 struct sockaddr_in their_addr; // connector's address information
1359 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1360 herror("gethostbyname");
1365 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1367 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1370 goto next_iteration;
1373 their_addr.sin_family = AF_INET; // host byte order
1374 their_addr.sin_port = htons(mail->port); // short, network byte order
1375 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1376 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1379 (sockfd, (struct sockaddr *) &their_addr,
1380 sizeof(struct sockaddr)) == -1) {
1383 goto next_iteration;
1385 struct timeval timeout;
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 ERR("IMAP connection failed: timeout");
1404 goto next_iteration;
1406 recvbuf[numbytes] = '\0';
1407 if (strstr(recvbuf, "* OK") != recvbuf) {
1408 ERR("IMAP connection failed, probably not an IMAP server");
1410 goto next_iteration;
1412 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1413 strncat(sendbuf, mail->user,
1414 MAXDATASIZE - strlen(sendbuf) - 1);
1415 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1416 strncat(sendbuf, mail->pass,
1417 MAXDATASIZE - strlen(sendbuf) - 1);
1418 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1419 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1422 goto next_iteration;
1424 timeout.tv_sec = 60; // 60 second timeout i guess
1425 timeout.tv_usec = 0;
1427 FD_SET(sockfd, &fdset);
1428 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1431 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1435 goto next_iteration;
1438 recvbuf[numbytes] = '\0';
1439 if (strstr(recvbuf, "a1 OK") == NULL) {
1440 ERR("IMAP server login failed: %s", recvbuf);
1442 goto next_iteration;
1444 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1445 strncat(sendbuf, mail->folder,
1446 MAXDATASIZE - strlen(sendbuf) - 1);
1447 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1448 MAXDATASIZE - strlen(sendbuf) - 1);
1449 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1452 goto next_iteration;
1454 timeout.tv_sec = 60; // 60 second timeout i guess
1455 timeout.tv_usec = 0;
1457 FD_SET(sockfd, &fdset);
1458 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1461 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1465 goto next_iteration;
1468 recvbuf[numbytes] = '\0';
1469 if (strstr(recvbuf, "a2 OK") == NULL) {
1470 ERR("IMAP status failed: %s", recvbuf);
1472 goto next_iteration;
1474 // now we get the data
1475 reply = strstr(recvbuf, " (MESSAGES ");
1477 *strchr(reply, ')') = '\0';
1478 if (reply == NULL) {
1479 ERR("Error parsing IMAP response: %s", recvbuf);
1481 goto next_iteration;
1483 timed_thread_lock (mail->p_timed_thread);
1484 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1487 timed_thread_unlock (mail->p_timed_thread);
1489 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1490 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1493 goto next_iteration;
1495 timeout.tv_sec = 60; // 60 second timeout i guess
1496 timeout.tv_usec = 0;
1498 FD_SET(sockfd, &fdset);
1499 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1502 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1506 goto next_iteration;
1509 recvbuf[numbytes] = '\0';
1510 if (strstr(recvbuf, "a3 OK") == NULL) {
1511 ERR("IMAP logout failed: %s", recvbuf);
1513 goto next_iteration;
1515 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1516 if (system(mail->command) == -1) {
1521 old_unseen = mail->unseen;
1522 old_messages = mail->messages;
1524 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1525 /* if a valid socket, close it */
1527 if (timed_thread_test (mail->p_timed_thread))
1528 timed_thread_exit (mail->p_timed_thread);
1533 void *pop3_thread(struct mail_s *mail)
1535 int sockfd, numbytes;
1536 char recvbuf[MAXDATASIZE];
1537 char sendbuf[MAXDATASIZE];
1540 unsigned int old_unseen = UINT_MAX;
1541 struct stat stat_buf;
1543 struct sockaddr_in their_addr; // connector's address information
1544 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1545 herror("gethostbyname");
1550 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1552 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1555 goto next_iteration;
1558 their_addr.sin_family = AF_INET; // host byte order
1559 their_addr.sin_port = htons(mail->port); // short, network byte order
1560 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1561 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1564 (sockfd, (struct sockaddr *) &their_addr,
1565 sizeof(struct sockaddr)) == -1) {
1568 goto next_iteration;
1570 struct timeval timeout;
1573 timeout.tv_sec = 60; // 60 second timeout i guess
1574 timeout.tv_usec = 0;
1576 FD_SET(sockfd, &fdset);
1577 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1580 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1584 goto next_iteration;
1587 ERR("POP3 connection failed: timeout\n");
1589 goto next_iteration;
1591 recvbuf[numbytes] = '\0';
1592 if (strstr(recvbuf, "+OK ") != recvbuf) {
1593 ERR("POP3 connection failed, probably not a POP3 server");
1595 goto next_iteration;
1597 strncpy(sendbuf, "USER ", MAXDATASIZE);
1598 strncat(sendbuf, mail->user,
1599 MAXDATASIZE - strlen(sendbuf) - 1);
1600 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1601 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1602 perror("send USER");
1604 goto next_iteration;
1606 timeout.tv_sec = 60; // 60 second timeout i guess
1607 timeout.tv_usec = 0;
1609 FD_SET(sockfd, &fdset);
1610 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1613 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1615 perror("recv USER");
1617 goto next_iteration;
1620 recvbuf[numbytes] = '\0';
1621 if (strstr(recvbuf, "+OK ") == NULL) {
1622 ERR("POP3 server login failed: %s", recvbuf);
1624 goto next_iteration;
1626 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1627 strncat(sendbuf, mail->pass,
1628 MAXDATASIZE - strlen(sendbuf) - 1);
1629 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1630 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1631 perror("send PASS");
1633 goto next_iteration;
1635 timeout.tv_sec = 60; // 60 second timeout i guess
1636 timeout.tv_usec = 0;
1638 FD_SET(sockfd, &fdset);
1639 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1642 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1644 perror("recv PASS");
1646 goto next_iteration;
1649 recvbuf[numbytes] = '\0';
1650 if (strstr(recvbuf, "+OK ") == NULL) {
1651 ERR("POP3 server login failed: %s", recvbuf);
1653 goto next_iteration;
1655 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1656 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1657 perror("send STAT");
1659 goto next_iteration;
1661 timeout.tv_sec = 60; // 60 second timeout i guess
1662 timeout.tv_usec = 0;
1664 FD_SET(sockfd, &fdset);
1665 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1668 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1670 perror("recv STAT");
1672 goto next_iteration;
1675 recvbuf[numbytes] = '\0';
1676 if (strstr(recvbuf, "+OK ") == NULL) {
1677 ERR("POP3 status failed: %s", recvbuf);
1679 goto next_iteration;
1681 // now we get the data
1682 reply = recvbuf + 4;
1683 if (reply == NULL) {
1684 ERR("Error parsing POP3 response: %s", recvbuf);
1686 goto next_iteration;
1688 timed_thread_lock (mail->p_timed_thread);
1689 sscanf(reply, "%lu %lu", &mail->unseen,
1691 timed_thread_unlock (mail->p_timed_thread);
1693 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1694 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1695 perror("send QUIT");
1697 goto next_iteration;
1699 timeout.tv_sec = 60; // 60 second timeout i guess
1700 timeout.tv_usec = 0;
1702 FD_SET(sockfd, &fdset);
1703 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1706 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1708 perror("recv QUIT");
1710 goto next_iteration;
1713 recvbuf[numbytes] = '\0';
1714 if (strstr(recvbuf, "+OK") == NULL) {
1715 ERR("POP3 logout failed: %s", recvbuf);
1717 goto next_iteration;
1719 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1720 if (system(mail->command) == -1) {
1725 old_unseen = mail->unseen;
1727 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1728 /* if a valid socket, close it */
1730 if (timed_thread_test (mail->p_timed_thread))
1731 timed_thread_exit (mail->p_timed_thread);
1737 void *threaded_exec(struct text_object *obj) {
1739 char *p2 = obj->data.texeci.buffer;
1740 FILE *fp = popen(obj->data.texeci.cmd,"r");
1741 timed_thread_lock (obj->data.texeci.p_timed_thread);
1742 int n2 = fread(p2, 1, text_buffer_size, fp);
1745 if (n2 && p2[n2 - 1] == '\n') {
1749 if (*p2 == '\001') {
1754 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1755 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1756 timed_thread_exit (obj->data.texeci.p_timed_thread);
1761 static struct text_object *new_text_object_internal()
1763 struct text_object *obj = malloc(sizeof(struct text_object));
1764 memset(obj, 0, sizeof(struct text_object));
1768 static void free_text_objects(unsigned int count, struct text_object *objs)
1771 for (i = 0; i < count; i++) {
1772 switch (objs[i].type) {
1774 close(objs[i].data.i);
1777 close(objs[i].data.i);
1780 close(objs[i].data.i2c.fd);
1783 free(objs[i].data.s);
1786 free(objs[i].data.s);
1789 free(objs[i].data.tztime.tz);
1790 free(objs[i].data.tztime.fmt);
1793 free(objs[i].data.mboxscan.args);
1794 free(objs[i].data.mboxscan.output);
1799 case OBJ_imap_unseen:
1800 if (!objs[i].global_mode) {
1801 free(objs[i].data.mail);
1804 case OBJ_imap_messages:
1805 if (!objs[i].global_mode) {
1806 free(objs[i].data.mail);
1812 case OBJ_pop3_unseen:
1813 if (!objs[i].global_mode) {
1814 free(objs[i].data.mail);
1818 if (!objs[i].global_mode) {
1819 free(objs[i].data.mail);
1823 case OBJ_if_existing:
1824 case OBJ_if_mounted:
1825 case OBJ_if_running:
1826 free(objs[i].data.ifblock.s);
1827 free(objs[i].data.ifblock.str);
1830 free(objs[i].data.tail.logfile);
1831 free(objs[i].data.tail.buffer);
1835 free(objs[i].data.s);
1838 free(objs[i].data.s);
1841 free(objs[i].data.s);
1844 free(objs[i].data.s);
1847 free(objs[i].data.s);
1849 /* case OBJ_execibar:
1850 free(objs[i].data.s);
1852 case OBJ_execigraph:
1853 free(objs[i].data.s);
1856 case OBJ_iconv_start:
1862 if (info.mpd.title) {
1863 free(info.mpd.title);
1867 case OBJ_mpd_artist:
1868 if (info.mpd.artist) {
1869 free(info.mpd.artist);
1870 info.mpd.artist = 0;
1874 if (info.mpd.album) {
1875 free(info.mpd.album);
1879 case OBJ_mpd_random:
1880 if (info.mpd.random) {
1881 free(info.mpd.random);
1882 info.mpd.random = 0;
1885 case OBJ_mpd_repeat:
1886 if (info.mpd.repeat) {
1887 free(info.mpd.repeat);
1888 info.mpd.repeat = 0;
1892 if (info.mpd.track) {
1893 free(info.mpd.track);
1898 if (info.mpd.name) {
1899 free(info.mpd.name);
1904 if (info.mpd.file) {
1905 free(info.mpd.file);
1909 case OBJ_mpd_status:
1910 if (info.mpd.status) {
1911 free(info.mpd.status);
1912 info.mpd.status = 0;
1916 if (info.mpd.artist) {
1917 free(info.mpd.artist);
1918 info.mpd.artist = 0;
1920 if (info.mpd.title) {
1921 free(info.mpd.title);
1924 if (info.mpd.file) {
1925 free(info.mpd.file);
1932 case OBJ_xmms2_artist:
1933 if (info.xmms2.artist) {
1934 free(info.xmms2.artist);
1935 info.xmms2.artist = 0;
1938 case OBJ_xmms2_album:
1939 if (info.xmms2.album) {
1940 free(info.xmms2.album);
1941 info.xmms2.album = 0;
1944 case OBJ_xmms2_title:
1945 if (info.xmms2.title) {
1946 free(info.xmms2.title);
1947 info.xmms2.title = 0;
1950 case OBJ_xmms2_genre:
1951 if (info.xmms2.genre) {
1952 free(info.xmms2.genre);
1953 info.xmms2.genre = 0;
1956 case OBJ_xmms2_comment:
1957 if (info.xmms2.comment) {
1958 free(info.xmms2.comment);
1959 info.xmms2.comment = 0;
1962 case OBJ_xmms2_decoder:
1963 if (info.xmms2.decoder) {
1964 free(info.xmms2.decoder);
1968 case OBJ_xmms2_transport:
1969 if (info.xmms2.transport) {
1970 free(info.xmms2.transport);
1975 if (info.xmms2.url) {
1976 free(info.xmms2.url);
1980 case OBJ_xmms2_date:
1981 if (info.xmms2.date) {
1982 free(info.xmms2.date);
1983 info.xmms2.date = 0;
1986 case OBJ_xmms2_status:
1987 if (info.xmms2.status) {
1988 free(info.xmms2.status);
1989 info.xmms2.status = 0;
1992 case OBJ_xmms2_smart:
1993 if (info.xmms2.artist) {
1994 free(info.xmms2.artist);
1995 info.xmms2.artist = 0;
1997 if (info.xmms2.title) {
1998 free(info.xmms2.title);
1999 info.xmms2.title = 0;
2001 if (info.xmms2.url) {
2002 free(info.xmms2.url);
2008 case OBJ_bmpx_title:
2009 case OBJ_bmpx_artist:
2010 case OBJ_bmpx_album:
2011 case OBJ_bmpx_track:
2013 case OBJ_bmpx_bitrate:
2017 free(objs[i].data.rss.uri);
2018 free(objs[i].data.rss.action);
2023 free(objs[i].data.s);
2025 case OBJ_battery_time:
2026 free(objs[i].data.s);
2029 free(objs[i].data.execi.cmd);
2030 free(objs[i].data.execi.buffer);
2033 free(objs[i].data.texeci.cmd);
2034 free(objs[i].data.texeci.buffer);
2037 if (info.first_process) {
2038 free_all_processes();
2039 info.first_process = NULL;
2043 if (info.first_process) {
2044 free_all_processes();
2045 info.first_process = NULL;
2050 free(objs[i].data.hddtemp.dev);
2051 free(objs[i].data.hddtemp.addr);
2054 case OBJ_entropy_avail:
2055 case OBJ_entropy_poolsize:
2056 case OBJ_entropy_bar:
2061 //text_objects = NULL;
2062 //text_object_count = 0;
2065 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2070 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2071 *a = mixer_init(buf1);
2072 (void) scan_bar(arg + n, w, h);
2075 (void) scan_bar(arg, w, h);
2080 /* construct_text_object() creates a new text_object */
2081 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2083 //struct text_object *obj = new_text_object();
2084 struct text_object *obj = new_text_object_internal();
2087 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2088 #define END ; } } else
2092 obj->type = OBJ_color;
2093 obj->data.l = get_x11_color(s);
2096 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2097 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2098 END OBJ(acpiacadapter, 0)
2099 END OBJ(freq, INFO_FREQ)
2105 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2107 obj->data.cpu_index=1;
2108 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2112 obj->data.cpu_index=atoi(&arg[0]);
2115 END OBJ(freq_g, INFO_FREQ)
2121 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2123 obj->data.cpu_index=1;
2124 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2128 obj->data.cpu_index=atoi(&arg[0]);
2131 #if defined(__linux__)
2132 END OBJ(voltage_mv, 0)
2138 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2140 obj->data.cpu_index=1;
2141 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2145 obj->data.cpu_index=atoi(&arg[0]);
2148 END OBJ(voltage_v, 0)
2154 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2156 obj->data.cpu_index=1;
2157 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2161 obj->data.cpu_index=atoi(&arg[0]);
2164 #endif /* __linux__ */
2165 END OBJ(freq_dyn, 0);
2166 END OBJ(freq_dyn_g, 0);
2167 END OBJ(acpifan, 0);
2168 END OBJ(battery, 0);
2171 sscanf(arg, "%63s", bat);
2173 strcpy(bat, "BAT0");
2174 obj->data.s = strdup(bat);
2175 END OBJ(battery_time, 0);
2178 sscanf(arg, "%63s", bat);
2180 strcpy(bat, "BAT0");
2181 obj->data.s = strdup(bat);
2182 END OBJ(battery_percent, 0);
2185 sscanf(arg, "%63s", bat);
2187 strcpy(bat, "BAT0");
2188 obj->data.s = strdup(bat);
2189 END OBJ(battery_bar, 0);
2192 arg = scan_bar(arg, &obj->a, &obj->b);
2193 sscanf(arg, "%63s", bat);
2195 strcpy(bat, "BAT0");
2197 #if defined(__linux__)
2198 END OBJ(i8k_version, INFO_I8K)
2199 END OBJ(i8k_bios, INFO_I8K)
2200 END OBJ(i8k_serial, INFO_I8K)
2201 END OBJ(i8k_cpu_temp, INFO_I8K)
2202 END OBJ(i8k_cpu_tempf, INFO_I8K)
2203 END OBJ(i8k_left_fan_status, INFO_I8K)
2204 END OBJ(i8k_right_fan_status, INFO_I8K)
2205 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2206 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2207 END OBJ(i8k_ac_status, INFO_I8K)
2208 END OBJ(i8k_buttons_status, INFO_I8K)
2210 END OBJ(ibm_temps, 0)
2212 CRIT_ERR("ibm_temps: needs an argument");
2214 if (!isdigit(arg[0])
2216 || atoi(&arg[0]) >=8)
2219 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2221 obj->data.sensor = atoi(&arg[0]);
2222 END OBJ(ibm_volume, 0)
2223 END OBJ(ibm_brightness, 0)
2224 END OBJ(pb_battery, 0)
2225 if (arg && strcmp(arg, "status") == 0) {
2226 obj->data.i = PB_BATT_STATUS;
2227 } else if (arg && strcmp(arg, "percent") == 0) {
2228 obj->data.i = PB_BATT_PERCENT;
2229 } else if (arg && strcmp(arg, "time") == 0) {
2230 obj->data.i = PB_BATT_TIME;
2232 ERR("pb_battery: needs one argument: status, percent or time");
2237 #endif /* __linux__ */
2238 #if defined(__OpenBSD__)
2239 END OBJ(obsd_sensors_temp, 0);
2241 CRIT_ERR("obsd_sensors_temp: needs an argument");
2243 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2245 ERR("Invalid temperature sensor number!");
2247 obj->data.sensor = atoi(&arg[0]);
2248 END OBJ(obsd_sensors_fan, 0);
2250 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor number)");
2252 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2254 ERR("Invalid fan sensor number!");
2256 obj->data.sensor = atoi(&arg[0]);
2257 END OBJ(obsd_sensors_volt, 0);
2259 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor number)");
2261 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2263 ERR("Invalid voltage sensor number!");
2265 obj->data.sensor = atoi(&arg[0]);
2266 END OBJ(obsd_vendor, 0);
2267 END OBJ(obsd_product, 0);
2268 #endif /* __OpenBSD__ */
2269 END OBJ(buffers, INFO_BUFFERS)
2270 END OBJ(cached, INFO_BUFFERS)
2271 END OBJ(cpu, INFO_CPU)
2273 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2274 obj->data.cpu_index = atoi(&arg[3]);
2276 } else {obj->data.cpu_index = 0; }
2278 obj->data.cpu_index = 0;
2280 END OBJ(cpubar, INFO_CPU)
2282 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2283 obj->data.cpu_index = atoi(&arg[3]);
2286 else {obj->data.cpu_index = 0;}
2287 (void) scan_bar(arg, &obj->a, &obj->b);
2289 (void) scan_bar(arg, &obj->a, &obj->b);
2290 obj->data.cpu_index = 0;
2292 END OBJ(cpugraph, INFO_CPU)
2294 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2295 obj->data.cpu_index = atoi(&arg[3]);
2298 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2300 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2301 obj->data.cpu_index = 0;
2303 END OBJ(diskio, INFO_DISKIO)
2304 END OBJ(diskio_read, INFO_DISKIO)
2305 END OBJ(diskio_write, INFO_DISKIO)
2306 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2307 END OBJ(diskiograph_read, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2308 END OBJ(diskiograph_write, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2311 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2314 obj->data.l = color0;
2316 obj->data.l = color1;
2318 obj->data.l = color2;
2320 obj->data.l = color3;
2322 obj->data.l = color4;
2324 obj->data.l = color5;
2326 obj->data.l = color6;
2328 obj->data.l = color7;
2330 obj->data.l = color8;
2332 obj->data.l = color9;
2334 obj->data.s = scan_font(arg);
2335 END OBJ(downspeed, INFO_NET)
2337 obj->data.net = get_net_stat(arg);
2340 CRIT_ERR("downspeed needs argument");
2342 END OBJ(downspeedf, INFO_NET)
2344 obj->data.net = get_net_stat(arg);
2347 CRIT_ERR("downspeedf needs argument");
2349 END OBJ(downspeedgraph, INFO_NET)
2350 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2352 sscanf(arg, "%63s %*i,%*i %*i", buf);
2353 obj->data.net = get_net_stat(buf);
2354 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2355 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
2362 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2363 blockstart[blockdepth - 1] = object_count;
2364 obj->data.ifblock.pos = object_count + 2;
2366 ERR("$else: no matching $if_*");
2371 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2373 ERR("$endif: no matching $if_*");
2376 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2379 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2380 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2381 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2382 END OBJ(execibar, 0) unsigned int n;
2383 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2385 ERR("${execibar <interval> command}");
2386 obj->type = OBJ_text;
2387 snprintf(buf, 256, "${%s}", s);
2388 obj->data.s = strdup(buf);
2390 obj->data.execi.cmd = strdup(arg + n);
2392 END OBJ(execigraph, 0) unsigned int n;
2393 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2395 ERR("${execigraph <interval> command}");
2396 obj->type = OBJ_text;
2397 snprintf(buf, 256, "${%s}", s);
2398 obj->data.s = strdup(buf);
2400 obj->data.execi.cmd = strdup(arg + n);
2402 END OBJ(execi, 0) unsigned int n;
2403 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2405 ERR("${execi <interval> command}");
2406 obj->type = OBJ_text;
2407 snprintf(buf, 256, "${%s}", s);
2408 obj->data.s = strdup(buf);
2410 obj->data.execi.cmd = strdup(arg + n);
2411 obj->data.execi.buffer =
2412 (char *) calloc(1, text_buffer_size);
2414 END OBJ(texeci, 0) unsigned int n;
2415 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2417 ERR("${texeci <interval> command}");
2418 obj->type = OBJ_text;
2419 snprintf(buf, 256, "${%s}", s);
2420 obj->data.s = strdup(buf);
2422 obj->data.texeci.cmd = strdup(arg + n);
2423 obj->data.texeci.buffer =
2424 (char *) calloc(1, text_buffer_size);
2426 obj->data.texeci.p_timed_thread = NULL;
2427 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2429 FILE *fp = popen(arg, "r");
2433 n = fread(buf, 1, 2048, fp);
2436 if (n && buf[n - 1] == '\n')
2441 obj->data.s = strdup(buf);
2443 obj->data.s = strdup("");
2446 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2447 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2449 while (isspace(*arg))
2455 obj->data.fsbar.fs = prepare_fs_stat(arg);
2456 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2459 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2463 obj->data.fsbar.fs = prepare_fs_stat(arg);
2464 END OBJ(fs_free, INFO_FS) if (!arg)
2466 obj->data.fs = prepare_fs_stat(arg);
2467 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2469 obj->data.fs = prepare_fs_stat(arg);
2470 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2472 obj->data.fs = prepare_fs_stat(arg);
2473 END OBJ(fs_size, INFO_FS) if (!arg)
2475 obj->data.fs = prepare_fs_stat(arg);
2476 END OBJ(fs_used, INFO_FS) if (!arg)
2478 obj->data.fs = prepare_fs_stat(arg);
2479 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2480 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2481 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2485 ERR("goto needs arguments");
2486 obj->type = OBJ_text;
2487 obj->data.s = strdup("${goto}");
2491 obj->data.i = atoi(arg);
2496 if (sscanf(arg, "%d %d", &a, &b) != 2)
2497 sscanf(arg, "%d", &b);
2501 obj->data.pair.a = a;
2502 obj->data.pair.b = b;
2504 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
2508 ERR("i2c needs arguments");
2509 obj->type = OBJ_text;
2510 //obj->data.s = strdup("${i2c}");
2514 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2515 /* if scanf couldn't read three values, read type and num and use
2517 sscanf(arg, "%63s %d", buf2, &n);
2519 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
2520 obj->data.i2c.devtype);
2521 strncpy(obj->data.i2c.type, buf2, 63);
2524 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
2525 obj->data.i2c.devtype);
2526 strncpy(obj->data.i2c.type, buf2, 63);
2529 END OBJ(top, INFO_TOP)
2533 ERR("top needs arguments");
2534 obj->type = OBJ_text;
2535 //obj->data.s = strdup("${top}");
2538 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2539 if (strcmp(buf, "name") == 0) {
2540 obj->data.top.type = TOP_NAME;
2541 } else if (strcmp(buf, "cpu") == 0) {
2542 obj->data.top.type = TOP_CPU;
2543 } else if (strcmp(buf, "pid") == 0) {
2544 obj->data.top.type = TOP_PID;
2545 } else if (strcmp(buf, "mem") == 0) {
2546 obj->data.top.type = TOP_MEM;
2548 ERR("invalid arg for top");
2551 if (n < 1 || n > 10) {
2552 CRIT_ERR("invalid arg for top");
2555 obj->data.top.num = n - 1;
2559 ERR("invalid args given for top");
2562 END OBJ(top_mem, INFO_TOP)
2566 ERR("top_mem needs arguments");
2567 obj->type = OBJ_text;
2568 obj->data.s = strdup("${top_mem}");
2571 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2572 if (strcmp(buf, "name") == 0) {
2573 obj->data.top.type = TOP_NAME;
2574 } else if (strcmp(buf, "cpu") == 0) {
2575 obj->data.top.type = TOP_CPU;
2576 } else if (strcmp(buf, "pid") == 0) {
2577 obj->data.top.type = TOP_PID;
2578 } else if (strcmp(buf, "mem") == 0) {
2579 obj->data.top.type = TOP_MEM;
2581 ERR("invalid arg for top");
2584 if (n < 1 || n > 10) {
2585 CRIT_ERR("invalid arg for top");
2588 obj->data.top.num = n - 1;
2592 ERR("invalid args given for top");
2595 END OBJ(addr, INFO_NET)
2597 obj->data.net = get_net_stat(arg);
2600 CRIT_ERR("addr needs argument");
2602 END OBJ(linkstatus, INFO_WIFI)
2604 obj->data.net = get_net_stat(arg);
2607 CRIT_ERR("linkstatus needs argument");
2613 ERR("tail needs arguments");
2614 obj->type = OBJ_text;
2615 obj->data.s = strdup("${tail}");
2618 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2619 if (n1 < 1 || n1 > 30) {
2620 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2624 fp = fopen(buf, "r");
2626 obj->data.tail.logfile =
2627 malloc(text_buffer_size);
2628 strcpy(obj->data.tail.logfile, buf);
2629 obj->data.tail.wantedlines = n1;
2630 obj->data.tail.interval =
2631 update_interval * 2;
2635 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2638 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2639 if (n1 < 1 || n1 > 30) {
2641 ("invalid arg for tail, number of lines must be between 1 and 30");
2643 } else if (n2 < 1 || n2 < update_interval) {
2645 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2649 fp = fopen(buf, "r");
2651 obj->data.tail.logfile =
2652 malloc(text_buffer_size);
2653 strcpy(obj->data.tail.logfile, buf);
2654 obj->data.tail.wantedlines = n1;
2655 obj->data.tail.interval = n2;
2659 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2665 ERR("invalid args given for tail");
2668 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2673 ERR("head needs arguments");
2674 obj->type = OBJ_text;
2675 obj->data.s = strdup("${head}");
2678 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2679 if (n1 < 1 || n1 > 30) {
2680 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2684 fp = fopen(buf, "r");
2686 obj->data.tail.logfile =
2687 malloc(text_buffer_size);
2688 strcpy(obj->data.tail.logfile, buf);
2689 obj->data.tail.wantedlines = n1;
2690 obj->data.tail.interval =
2691 update_interval * 2;
2695 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2698 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2699 if (n1 < 1 || n1 > 30) {
2701 ("invalid arg for head, number of lines must be between 1 and 30");
2703 } else if (n2 < 1 || n2 < update_interval) {
2705 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2709 fp = fopen(buf, "r");
2711 obj->data.tail.logfile =
2712 malloc(text_buffer_size);
2713 strcpy(obj->data.tail.logfile, buf);
2714 obj->data.tail.wantedlines = n1;
2715 obj->data.tail.interval = n2;
2719 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2725 ERR("invalid args given for head");
2728 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2729 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2731 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2732 if (r >= 3 && (c < 1 || c > 3))
2734 if (r >= 2 && (b < 1 || b > 3))
2736 if (r >= 1 && (a < 1 || a > 3))
2739 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2740 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2741 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2742 END OBJ(if_empty, 0)
2743 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2744 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2747 ERR("if_empty needs an argument");
2748 obj->data.ifblock.s = 0;
2750 obj->data.ifblock.s = strdup(arg);
2751 blockstart[blockdepth] = object_count;
2752 obj->data.ifblock.pos = object_count + 2;
2754 END OBJ(if_existing, 0)
2755 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2756 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2759 ERR("if_existing needs an argument or two");
2760 obj->data.ifblock.s = NULL;
2761 obj->data.ifblock.str = NULL;
2763 char buf1[256], buf2[256];
2764 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2766 obj->data.ifblock.s = strdup(buf1);
2767 obj->data.ifblock.str = NULL;
2769 obj->data.ifblock.s = strdup(buf1);
2770 obj->data.ifblock.str = strdup(buf2);
2773 blockstart[blockdepth] = object_count;
2774 obj->data.ifblock.pos = object_count + 2;
2776 END OBJ(if_mounted, 0)
2777 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2778 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2781 ERR("if_mounted needs an argument");
2782 obj->data.ifblock.s = 0;
2784 obj->data.ifblock.s = strdup(arg);
2785 blockstart[blockdepth] = object_count;
2786 obj->data.ifblock.pos = object_count + 2;
2788 END OBJ(if_running, 0)
2789 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2790 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2794 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2795 obj->data.ifblock.s = strdup(buf);
2797 ERR("if_running needs an argument");
2798 obj->data.ifblock.s = 0;
2800 blockstart[blockdepth] = object_count;
2801 obj->data.ifblock.pos = object_count + 2;
2805 END OBJ(mails, INFO_MAIL)
2806 END OBJ(mboxscan, 0)
2807 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
2808 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
2809 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2810 obj->data.mboxscan.output[0] = 1;
2811 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
2812 END OBJ(mem, INFO_MEM)
2813 END OBJ(memmax, INFO_MEM)
2814 END OBJ(memperc, INFO_MEM)
2815 END OBJ(membar, INFO_MEM)
2816 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2817 END OBJ(memgraph, INFO_MEM)
2818 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2819 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2820 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2821 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2822 END OBJ(mixerbar, INFO_MIXER)
2823 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2824 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2825 END OBJ(mixerlbar, INFO_MIXER)
2826 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2827 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2828 END OBJ(mixerrbar, INFO_MIXER)
2829 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2830 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2832 OBJ(new_mails, INFO_MAIL)
2833 END OBJ(nodename, 0)
2834 END OBJ(processes, INFO_PROCS)
2835 END OBJ(running_processes, INFO_RUN_PROCS)
2836 END OBJ(shadecolor, 0)
2838 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2840 END OBJ(outlinecolor, 0)
2842 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2844 END OBJ(stippled_hr, 0)
2846 int a = stippled_borders, b = 1;
2848 if (sscanf(arg, "%d %d", &a, &b) != 2)
2849 sscanf(arg, "%d", &b);
2853 obj->data.pair.a = a;
2854 obj->data.pair.b = b;
2856 END OBJ(swap, INFO_MEM)
2857 END OBJ(swapmax, INFO_MEM)
2858 END OBJ(swapperc, INFO_MEM)
2859 END OBJ(swapbar, INFO_MEM)
2860 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2861 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
2863 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
2864 obj->data.i2c.devtype);
2865 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
2867 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
2868 obj->data.i2c.devtype);
2869 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2870 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2872 char buf1[256], buf2[256], *fmt, *tz;
2875 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2884 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
2885 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
2887 END OBJ(iconv_start, 0)
2888 if (iconv_converting) {
2889 CRIT_ERR("You must stop your last iconv conversion before starting another");
2892 char iconv_from[CODEPAGE_LENGTH];
2893 char iconv_to[CODEPAGE_LENGTH];
2894 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2895 CRIT_ERR("Invalid arguments for iconv_start");
2898 new_iconv = iconv_open(iconv_to, iconv_from);
2899 if (new_iconv == (iconv_t)(-1)) {
2900 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2902 obj->a = register_iconv(&new_iconv);
2903 iconv_converting = 1;
2907 CRIT_ERR("Iconv requires arguments");
2909 END OBJ(iconv_stop, 0)
2910 iconv_converting = 0;
2913 END OBJ(totaldown, INFO_NET)
2915 obj->data.net = get_net_stat(arg);
2918 CRIT_ERR("totaldown needs argument");
2920 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
2922 obj->data.net = get_net_stat(arg);
2925 CRIT_ERR("totalup needs argument");
2928 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
2929 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
2930 END OBJ(upspeed, INFO_NET)
2932 obj->data.net = get_net_stat(arg);
2935 CRIT_ERR("upspeed needs argument");
2937 END OBJ(upspeedf, INFO_NET)
2939 obj->data.net = get_net_stat(arg);
2942 CRIT_ERR("upspeedf needs argument");
2945 END OBJ(upspeedgraph, INFO_NET)
2946 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2948 sscanf(arg, "%63s %*i,%*i %*i", buf);
2949 obj->data.net = get_net_stat(buf);
2950 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2951 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
2956 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
2957 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
2958 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2959 OBJ(apm_adapter, 0) END
2960 OBJ(apm_battery_life, 0) END
2961 OBJ(apm_battery_time, 0) END
2962 #endif /* __FreeBSD__ */
2966 obj->data.mail = parse_mail_args(IMAP, arg);
2967 obj->global_mode = 0;
2969 obj->global_mode = 1;
2972 OBJ(imap_messages, 0)
2975 obj->data.mail = parse_mail_args(IMAP, arg);
2976 obj->global_mode = 0;
2978 obj->global_mode = 1;
2984 obj->data.mail = parse_mail_args(POP3, arg);
2985 obj->global_mode = 0;
2987 obj->global_mode = 1;
2993 obj->data.mail = parse_mail_args(POP3, arg);
2994 obj->global_mode = 0;
2996 obj->global_mode = 1;
3000 OBJ(mpd_artist, INFO_MPD) END
3001 OBJ(mpd_title, INFO_MPD)
3005 sscanf (arg, "%d", &info.mpd.max_title_len);
3006 if (info.mpd.max_title_len > 0)
3007 info.mpd.max_title_len++;
3009 CRIT_ERR ("mpd_title: invalid length argument");
3012 END OBJ(mpd_random, INFO_MPD)
3013 END OBJ(mpd_repeat, INFO_MPD)
3014 END OBJ(mpd_elapsed, INFO_MPD)
3015 END OBJ(mpd_length, INFO_MPD)
3016 END OBJ(mpd_track, INFO_MPD)
3017 END OBJ(mpd_name, INFO_MPD)
3018 END OBJ(mpd_file, INFO_MPD)
3019 END OBJ(mpd_percent, INFO_MPD)
3020 END OBJ(mpd_album, INFO_MPD)
3021 END OBJ(mpd_vol, INFO_MPD)
3022 END OBJ(mpd_bitrate, INFO_MPD)
3023 END OBJ(mpd_status, INFO_MPD)
3024 END OBJ(mpd_bar, INFO_MPD)
3025 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3026 END OBJ(mpd_smart, INFO_MPD) END
3029 OBJ(xmms2_artist, INFO_XMMS2)
3030 END OBJ(xmms2_album, INFO_XMMS2)
3031 END OBJ(xmms2_title, INFO_XMMS2)
3032 END OBJ(xmms2_genre, INFO_XMMS2)
3033 END OBJ(xmms2_comment, INFO_XMMS2)
3034 END OBJ(xmms2_decoder, INFO_XMMS2)
3035 END OBJ(xmms2_transport, INFO_XMMS2)
3036 END OBJ(xmms2_url, INFO_XMMS2)
3037 END OBJ(xmms2_tracknr, INFO_XMMS2)
3038 END OBJ(xmms2_bitrate, INFO_XMMS2)
3039 END OBJ(xmms2_date, INFO_XMMS2)
3040 END OBJ(xmms2_id, INFO_XMMS2)
3041 END OBJ(xmms2_duration, INFO_XMMS2)
3042 END OBJ(xmms2_elapsed, INFO_XMMS2)
3043 END OBJ(xmms2_size, INFO_XMMS2)
3044 END OBJ(xmms2_status, INFO_XMMS2)
3045 END OBJ(xmms2_percent, INFO_XMMS2)
3046 END OBJ(xmms2_bar, INFO_XMMS2)
3047 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3048 END OBJ(xmms2_smart, INFO_XMMS2)
3052 OBJ(audacious_status, INFO_AUDACIOUS) END
3053 OBJ(audacious_title, INFO_AUDACIOUS)
3057 sscanf (arg, "%d", &info.audacious.max_title_len);
3058 if (info.audacious.max_title_len > 0)
3059 info.audacious.max_title_len++;
3061 CRIT_ERR ("audacious_title: invalid length argument");
3065 OBJ(audacious_length, INFO_AUDACIOUS) END
3066 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3067 OBJ(audacious_position, INFO_AUDACIOUS) END
3068 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3069 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3070 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3071 OBJ(audacious_channels, INFO_AUDACIOUS) END
3072 OBJ(audacious_filename, INFO_AUDACIOUS) END
3073 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3074 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3075 OBJ(audacious_bar, INFO_AUDACIOUS)
3076 (void) scan_bar(arg, &obj->a, &obj->b);
3080 OBJ(bmpx_title, INFO_BMPX)
3081 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3083 OBJ(bmpx_artist, INFO_BMPX)
3084 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3086 OBJ(bmpx_album, INFO_BMPX)
3087 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3089 OBJ(bmpx_track, INFO_BMPX)
3090 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3092 OBJ(bmpx_uri, INFO_BMPX)
3093 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3095 OBJ(bmpx_bitrate, INFO_BMPX)
3096 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3102 int argc, delay, act_par;
3103 char *uri = (char *)malloc(128 * sizeof(char));
3104 char *action = (char *)malloc(64 * sizeof(char));
3106 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par);
3107 obj->data.rss.uri = uri;
3108 obj->data.rss.delay = delay;
3109 obj->data.rss.action = action;
3110 obj->data.rss.act_par = act_par;
3114 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
3120 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3121 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3122 ERR("hddtemp needs arguments");
3123 obj->type = OBJ_text;
3124 obj->data.s = strdup("${hddtemp}");
3129 #ifdef TCP_PORT_MONITOR
3130 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3131 int argc, port_begin, port_end, item, connection_index;
3133 memset(itembuf,0,sizeof(itembuf));
3135 /* massive argument checking */
3137 CRIT_ERR("tcp_portmon: needs arguments");
3139 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3140 if ( (argc != 3) && (argc != 4) )
3142 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3144 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3146 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3148 if ( port_begin > port_end )
3150 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3152 if ( strncmp(itembuf,"count",31) == 0 )
3154 else if ( strncmp(itembuf,"rip",31) == 0 )
3156 else if ( strncmp(itembuf,"rhost",31) == 0 )
3158 else if ( strncmp(itembuf,"rport",31) == 0 )
3160 else if ( strncmp(itembuf,"rservice",31) == 0 )
3162 else if ( strncmp(itembuf,"lip",31) == 0 )
3164 else if ( strncmp(itembuf,"lhost",31) == 0 )
3166 else if ( strncmp(itembuf,"lport",31) == 0 )
3168 else if ( strncmp(itembuf,"lservice",31) == 0 )
3172 CRIT_ERR("tcp_portmon: invalid item specified");
3174 if ( (argc==3) && (item!=COUNT) )
3176 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3178 if ( (argc==4) && (connection_index<0) )
3180 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3182 /* ok, args looks good. save the text object data */
3183 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3184 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3185 obj->data.tcp_port_monitor.item = item;
3186 obj->data.tcp_port_monitor.connection_index = connection_index;
3188 /* if the port monitor collection hasn't been created, we must create it */
3189 if ( !info.p_tcp_port_monitor_collection )
3191 info.p_tcp_port_monitor_collection =
3192 create_tcp_port_monitor_collection ();
3193 if ( !info.p_tcp_port_monitor_collection )
3195 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3199 /* if a port monitor for this port does not exist, create one and add it to the collection */
3200 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3202 tcp_port_monitor_t * p_monitor =
3203 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3206 CRIT_ERR("tcp_portmon: unable to create port monitor");
3208 /* add the newly created monitor to the collection */
3209 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3212 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3217 OBJ(entropy_avail, INFO_ENTROPY) END
3218 OBJ(entropy_poolsize, INFO_ENTROPY) END
3219 OBJ(entropy_bar, INFO_ENTROPY)
3220 (void) scan_bar(arg, &obj->a, &obj->b);
3225 ERR("unknown variable %s", s);
3226 obj->type = OBJ_text;
3227 snprintf(buf, 256, "${%s}", s);
3228 obj->data.s = strdup(buf);
3235 static struct text_object *create_plain_text(const char *s)
3237 struct text_object *obj;
3239 if (s == NULL || *s == '\0') {
3243 obj = new_text_object_internal();
3245 obj->type = OBJ_text;
3246 obj->data.s = strdup(s);
3250 static struct text_object_list *extract_variable_text_internal(const char *p)
3252 struct text_object_list *retval;
3253 struct text_object *obj;
3256 retval = malloc(sizeof(struct text_object_list));
3257 memset(retval, 0, sizeof(struct text_object_list));
3258 retval->text_object_count = 0;
3260 long line = text_lines;
3268 obj = create_plain_text(s);
3270 // allocate memory for the object
3271 retval->text_objects = realloc(retval->text_objects,
3272 sizeof(struct text_object) * (retval->text_object_count+1));
3273 // assign the new object to the end of the list.
3274 memcpy(&retval->text_objects[retval->text_object_count++],
3275 obj, sizeof(struct text_object));
3287 /* variable is either $foo or ${foo} */
3289 unsigned int brl = 1, brr = 0;
3292 while (*p && brl != brr) {
3293 if (*p == '{') brl++;
3294 if (*p == '}') brr++;
3302 while (*p && (isalnum((int) *p)
3307 /* copy variable to buffer */
3308 len = (p - s > 255) ? 255 : (p - s);
3309 strncpy(buf, s, len);
3318 /* if variable wasn't found from environment, use some special */
3324 if (strchr(buf, ' ')) {
3325 arg = strchr(buf, ' ');
3328 while (isspace((int) *arg))
3334 /* lowercase variable name */
3341 // create new object
3342 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3344 // allocate memory for the object
3345 retval->text_objects = realloc(retval->text_objects,
3346 sizeof(struct text_object) * (retval->text_object_count+1));
3347 // assign the new object to the end of the list.
3348 memcpy(&retval->text_objects[retval->text_object_count++],
3349 obj, sizeof(struct text_object));
3355 obj = create_plain_text("$");
3357 // allocate memory for the object
3358 retval->text_objects = realloc(retval->text_objects,
3359 sizeof(struct text_object) * (retval->text_object_count+1));
3360 // assign the new object to the end of the list.
3361 memcpy(&retval->text_objects[retval->text_object_count++],
3362 obj, sizeof(struct text_object));
3369 obj = create_plain_text(s);
3371 // allocate memory for the object
3372 retval->text_objects = realloc(retval->text_objects,
3373 sizeof(struct text_object) * (retval->text_object_count+1));
3374 // assign the new object to the end of the list.
3375 memcpy(&retval->text_objects[retval->text_object_count++],
3376 obj, sizeof(struct text_object));
3381 ERR("one or more $endif's are missing");
3387 static void extract_variable_text(const char *p)
3389 struct text_object_list *list;
3391 free_text_objects(text_object_count, text_objects);
3392 text_object_count = 0;
3393 text_objects = NULL;
3396 list = extract_variable_text_internal(p);
3397 text_objects = list->text_objects;
3398 text_object_count = list->text_object_count;
3405 void parse_conky_vars(char * text, char * p, struct information *cur) {
3406 struct text_object_list *object_list = extract_variable_text_internal(text);
3407 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3411 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3416 char buff_in[P_MAX_SIZE] = {0};
3417 iconv_converting = 0;
3420 for (i = 0; i < object_count; i++) {
3421 struct text_object *obj = &objs[i];
3423 #define OBJ(a) break; case OBJ_##a:
3425 switch (obj->type) {
3428 ERR("not implemented obj type %d",
3432 /* does anyone have decimals in acpi temperature? */
3434 snprintf(p, p_max_size, "%d", (int)
3435 get_acpi_temperature(obj->
3439 snprintf(p, 5, "%d ", (int)
3440 get_acpi_temperature(obj->
3445 /* does anyone have decimals in acpi temperature? */
3447 snprintf(p, p_max_size, "%d", (int)
3448 ((get_acpi_temperature(obj->
3450 i)+ 40) * 9.0 / 5 - 40));
3452 snprintf(p, 5, "%d ", (int)
3453 ((get_acpi_temperature(obj->
3455 i)+ 40) * 9.0 / 5 - 40));
3459 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3464 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3467 #if defined(__linux__)
3470 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3475 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3478 #endif /* __linux__ */
3482 get_freq_dynamic(p, 6, "%.0f ", 1 );
3484 get_freq_dynamic(p, p_max_size, "%.0f", 1 );
3489 get_freq_dynamic(p, 6, "%'.2f ", 1000);
3491 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3495 get_adt746x_cpu(p, p_max_size);
3498 get_adt746x_fan(p, p_max_size);
3501 get_acpi_fan(p, p_max_size);
3503 OBJ(acpiacadapter) {
3504 get_acpi_ac_adapter(p, p_max_size);
3507 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3510 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3512 OBJ(battery_percent) {
3513 snprintf(p, p_max_size, "%d",
3514 get_battery_perct(obj->data.s));
3517 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3520 human_readable(cur->buffers * 1024, p, 255);
3523 human_readable(cur->cached * 1024, p, 255);
3526 if (obj->data.cpu_index > info.cpu_count) {
3527 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3528 CRIT_ERR("attempting to use more CPUs then you have!");
3531 snprintf(p, p_max_size, "%*d", pad_percents,
3532 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3535 snprintf(p, 4, "%*d ",
3537 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3543 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3546 new_graph(p, obj->a,
3547 obj->b, obj->c, obj->d,
3548 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3552 new_fg(p, obj->data.l);
3584 #if defined(__linux__)
3586 snprintf(p, p_max_size, "%s", i8k.version);
3589 snprintf(p, p_max_size, "%s", i8k.bios);
3592 snprintf(p, p_max_size, "%s", i8k.serial);
3595 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3597 OBJ(i8k_cpu_tempf) {
3599 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3600 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3602 OBJ(i8k_left_fan_status) {
3603 int left_fan_status;
3604 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3605 if(left_fan_status == 0) {
3606 snprintf(p, p_max_size,"off");
3607 } if(left_fan_status == 1) {
3608 snprintf(p, p_max_size, "low");
3609 } if(left_fan_status == 2) {
3610 snprintf(p, p_max_size, "high");
3614 OBJ(i8k_right_fan_status) {
3615 int right_fan_status;
3616 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3617 if(right_fan_status == 0) {
3618 snprintf(p, p_max_size,"off");
3619 } if(right_fan_status == 1) {
3620 snprintf(p, p_max_size, "low");
3621 } if(right_fan_status == 2) {
3622 snprintf(p, p_max_size, "high");
3625 OBJ(i8k_left_fan_rpm) {
3626 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3628 OBJ(i8k_right_fan_rpm) {
3629 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3631 OBJ(i8k_ac_status) {
3633 sscanf(i8k.ac_status, "%d", &ac_status);
3634 if(ac_status == -1) {
3635 snprintf(p, p_max_size,"disabled (read i8k docs)");
3636 } if(ac_status == 0) {
3637 snprintf(p, p_max_size, "off");
3638 } if(ac_status == 1) {
3639 snprintf(p, p_max_size, "on");
3642 OBJ(i8k_buttons_status) {
3643 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3647 get_ibm_acpi_fan(p, p_max_size);
3650 get_ibm_acpi_temps();
3651 snprintf(p, p_max_size, "%d",
3652 ibm_acpi.temps[obj->data.sensor]);
3655 get_ibm_acpi_volume(p, p_max_size);
3657 OBJ(ibm_brightness) {
3658 get_ibm_acpi_brightness(p, p_max_size);
3661 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3663 #endif /* __linux__ */
3666 OBJ(obsd_sensors_temp) {
3667 obsd_sensors.device = sensor_device;
3668 update_obsd_sensors();
3669 snprintf(p, p_max_size, "%.1f",
3670 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
3673 OBJ(obsd_sensors_fan) {
3674 obsd_sensors.device = sensor_device;
3675 update_obsd_sensors();
3676 snprintf(p, p_max_size, "%d",
3677 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3680 OBJ(obsd_sensors_volt) {
3681 obsd_sensors.device = sensor_device;
3682 update_obsd_sensors();
3683 snprintf(p, p_max_size, "%.2f",
3684 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3688 get_obsd_vendor(p, p_max_size);
3692 get_obsd_product(p, p_max_size);
3694 #endif /* __OpenBSD__ */
3698 new_font(p, obj->data.s);
3701 void format_diskio(unsigned int diskio_value)
3704 if (diskio_value > 1024*1024) {
3705 snprintf(p, p_max_size, "%.1fGiB",
3706 (double)diskio_value/1024/1024);
3707 } else if (diskio_value > 1024) {
3708 snprintf(p, p_max_size, "%.1fMiB",
3709 (double)diskio_value/1024);
3710 } else if (diskio_value > 0) {
3711 snprintf(p, p_max_size, "%dKiB", diskio_value);
3713 snprintf(p, p_max_size, "%dB", diskio_value);
3716 if (diskio_value > 1024*1024) {
3717 snprintf(p, 12, "%.1fGiB ",
3718 (double)diskio_value/1024/1024);
3719 } else if (diskio_value > 1024) {
3720 snprintf(p, 12, "%.1fMiB ",
3721 (double)diskio_value/1024);
3722 } else if (diskio_value > 0) {
3723 snprintf(p, 12, "%dKiB ", diskio_value);
3725 snprintf(p, 12, "%dB ", diskio_value);
3730 format_diskio(diskio_value);
3733 format_diskio(diskio_write_value);
3736 format_diskio(diskio_read_value);
3739 new_graph(p, obj->a,
3740 obj->b, obj->c, obj->d,
3741 diskio_value, obj->e, 1);
3743 OBJ(diskiograph_read) {
3744 new_graph(p, obj->a,
3745 obj->b, obj->c, obj->d,
3746 diskio_read_value, obj->e, 1);
3748 OBJ(diskiograph_write) {
3749 new_graph(p, obj->a,
3750 obj->b, obj->c, obj->d,
3751 diskio_write_value, obj->e, 1);
3755 snprintf(p, p_max_size, "%d",
3756 (int) (obj->data.net->
3760 snprintf(p, 6, "%d ",
3761 (int) (obj->data.net->
3767 snprintf(p, p_max_size, "%.1f",
3769 recv_speed / 1024.0);
3771 snprintf(p, 8, "%.1f ",
3773 recv_speed / 1024.0);
3775 OBJ(downspeedgraph) {
3777 if (obj->data.net->recv_speed == 0)
3778 obj->data.net->recv_speed = 0.01;
3780 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3781 (obj->data.net->recv_speed /
3782 1024.0), obj->e, 1);
3786 i = obj->data.ifblock.pos - 1;
3796 snprintf(p, p_max_size, "%u.%u.%u.%u",
3797 obj->data.net->addr.
3799 obj->data.net->addr.
3801 obj->data.net->addr.
3803 obj->data.net->addr.
3809 snprintf(p, p_max_size, "%d",
3810 obj->data.net->linkstatus);
3813 snprintf(p, 5, "%4d ",
3814 obj->data.net->linkstatus);
3817 #if defined(IMLIB2) && defined(X11)
3822 Imlib_Image image, buffer;
3823 image = imlib_load_image(obj->data.s);
3824 imlib_context_set_image(image);
3827 w = imlib_image_get_width();
3828 h = imlib_image_get_height();
3829 buffer = imlib_create_image(w, h);
3830 imlib_context_set_display(display);
3831 imlib_context_set_drawable(window.drawable);
3832 imlib_context_set_colormap(DefaultColormap(display, screen));
3833 imlib_context_set_visual(DefaultVisual(display, screen));
3834 imlib_context_set_image(buffer);
3835 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
3836 imlib_render_image_on_drawable(text_start_x, text_start_y);
3838 imlib_context_set_image(image);
3845 FILE *fp = popen(obj->data.s, "r");
3846 int length = fread(p, 1, p_max_size, fp);
3849 /*output[length] = '\0';
3850 if (length > 0 && output[length - 1] == '\n') {
3851 output[length - 1] = '\0';
3854 if (length > 0 && p[length - 1] == '\n') {
3855 p[length - 1] = '\0';
3858 //parse_conky_vars(output, p, cur);
3862 FILE *fp = popen(obj->data.s, "r");
3863 int n2 = fread(p, 1, p_max_size, fp);
3867 if (n2 && p[n2 - 1] == '\n')
3876 if (sscanf(p, "%lf", &barnum) == 0) {
3877 ERR("reading execbar value failed (perhaps it's not the correct format?)");
3879 if (barnum > 100 || barnum < 0) {
3880 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
3882 barnum = barnum / 100.0;
3883 new_bar(p, 0, 4, (int) (barnum * 255.0));
3889 FILE *fp = popen(obj->data.s, "r");
3890 int n2 = fread(p, 1, p_max_size, fp);
3894 if (n2 && p[n2 - 1] == '\n')
3903 if (sscanf(p, "%lf", &barnum) == 0) {
3904 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
3906 if (barnum > 100 || barnum < 0) {
3907 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
3909 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
3914 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3915 new_bar(p, 0, 4, (int) obj->f);
3918 FILE *fp = popen(obj->data.execi.cmd, "r");
3919 int n2 = fread(p, 1, p_max_size, fp);
3922 if (n2 && p[n2 - 1] == '\n')
3931 if (sscanf(p, "%f", &barnum) == 0) {
3932 ERR("reading execibar value failed (perhaps it's not the correct format?)");
3934 if (barnum > 100 || barnum < 0) {
3935 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
3937 obj->f = 255 * barnum / 100.0;
3938 new_bar(p, 0, 4, (int) obj->f);
3940 obj->data.execi.last_update =
3941 current_update_time;
3945 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3946 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
3949 FILE *fp = popen(obj->data.execi.cmd, "r");
3950 int n2 = fread(p, 1, p_max_size, fp);
3953 if (n2 && p[n2 - 1] == '\n')
3962 if (sscanf(p, "%f", &barnum) == 0) {
3963 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
3965 if (barnum > 100 || barnum < 0) {
3966 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
3969 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
3971 obj->data.execi.last_update = current_update_time;
3977 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
3978 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
3980 char *output = obj->data.execi.buffer;
3981 FILE *fp = popen(obj->data.execi.cmd, "r");
3982 //int length = fread(output, 1, text_buffer_size, fp);
3983 int length = fread(output, 1, text_buffer_size, fp);
3986 output[length] = '\0';
3987 if (length > 0 && output[length - 1] == '\n') {
3988 output[length - 1] = '\0';
3990 obj->data.execi.last_update = current_update_time;
3991 snprintf(p, p_max_size, "%s", output);
3993 //parse_conky_vars(output, p, cur);
3996 if (!obj->data.texeci.p_timed_thread)
3998 obj->data.texeci.p_timed_thread=
3999 timed_thread_create ((void*)threaded_exec, (void*) obj,
4000 obj->data.texeci.interval * 1000000);
4001 if (!obj->data.texeci.p_timed_thread)
4002 ERR("Error starting texeci thread");
4003 timed_thread_register (obj->data.texeci.p_timed_thread,
4004 &obj->data.texeci.p_timed_thread);
4006 timed_thread_lock (obj->data.texeci.p_timed_thread);
4007 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4008 timed_thread_unlock (obj->data.texeci.p_timed_thread);
4010 #endif /* HAVE_POPEN */
4012 if (obj->global_mode && info.mail) { // this means we use info
4013 if (!info.mail->p_timed_thread)
4015 info.mail->p_timed_thread =
4016 timed_thread_create ((void*)imap_thread,
4018 info.mail->interval * 1000000);
4019 if (!info.mail->p_timed_thread)
4020 ERR("Error starting imap thread");
4021 timed_thread_register (info.mail->p_timed_thread,
4022 &info.mail->p_timed_thread);
4024 timed_thread_lock (info.mail->p_timed_thread);
4025 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4026 timed_thread_unlock (info.mail->p_timed_thread);
4027 } else if (obj->data.mail) { // this means we use obj
4028 if (!obj->data.mail->p_timed_thread)
4030 obj->data.mail->p_timed_thread =
4031 timed_thread_create ((void*)imap_thread,
4032 (void*)obj->data.mail,
4033 obj->data.mail->interval * 1000000);
4034 if (!obj->data.mail->p_timed_thread)
4035 ERR("Error starting imap thread");
4036 timed_thread_register (obj->data.mail->p_timed_thread,
4037 &obj->data.mail->p_timed_thread);
4039 timed_thread_lock (obj->data.mail->p_timed_thread);
4040 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4041 timed_thread_unlock (obj->data.mail->p_timed_thread);
4042 } else if (!obj->a) { // something is wrong, warn once then stop
4043 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4047 OBJ(imap_messages) {
4048 if (obj->global_mode && info.mail) { // this means we use info
4049 if (!info.mail->p_timed_thread)
4051 info.mail->p_timed_thread =
4052 timed_thread_create ((void*)imap_thread,
4054 info.mail->interval * 1000000);
4055 if (!info.mail->p_timed_thread)
4056 ERR("Error starting imap thread");
4057 timed_thread_register (info.mail->p_timed_thread,
4058 &info.mail->p_timed_thread);
4060 timed_thread_lock (info.mail->p_timed_thread);
4061 snprintf(p, p_max_size, "%lu", info.mail->messages);
4062 timed_thread_unlock (info.mail->p_timed_thread);
4063 } else if (obj->data.mail) { // this means we use obj
4064 if (!obj->data.mail->p_timed_thread)
4066 obj->data.mail->p_timed_thread =
4067 timed_thread_create ((void*)imap_thread,
4068 (void*)obj->data.mail,
4069 obj->data.mail->interval * 1000000);
4070 if (!obj->data.mail->p_timed_thread)
4071 ERR("Error starting imap thread");
4072 timed_thread_register (obj->data.mail->p_timed_thread,
4073 &obj->data.mail->p_timed_thread);
4075 timed_thread_lock (obj->data.mail->p_timed_thread);
4076 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4077 timed_thread_lock (obj->data.mail->p_timed_thread);
4078 } else if (!obj->a) { // something is wrong, warn once then stop
4079 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4084 if (obj->global_mode && info.mail) { // this means we use info
4085 if (!info.mail->p_timed_thread)
4087 info.mail->p_timed_thread =
4088 timed_thread_create ((void*)pop3_thread,
4090 info.mail->interval * 1000000);
4091 if (!info.mail->p_timed_thread)
4092 ERR("Error starting pop3 thread");
4093 timed_thread_register (info.mail->p_timed_thread,
4094 &info.mail->p_timed_thread);
4096 timed_thread_lock (info.mail->p_timed_thread);
4097 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4098 timed_thread_unlock (info.mail->p_timed_thread);
4099 } else if (obj->data.mail) { // this means we use obj
4100 if (!obj->data.mail->p_timed_thread)
4102 obj->data.mail->p_timed_thread =
4103 timed_thread_create ((void*)pop3_thread,
4104 (void*)obj->data.mail,
4105 obj->data.mail->interval * 1000000);
4106 if (!obj->data.mail->p_timed_thread)
4107 ERR("Error starting pop3 thread");
4108 timed_thread_register (obj->data.mail->p_timed_thread,
4109 &obj->data.mail->p_timed_thread);
4111 timed_thread_lock (obj->data.mail->p_timed_thread);
4112 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4113 timed_thread_unlock (obj->data.mail->p_timed_thread);
4114 } else if (!obj->a) { // something is wrong, warn once then stop
4115 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4120 if (obj->global_mode && info.mail) { // this means we use info
4121 if (!info.mail->p_timed_thread)
4123 info.mail->p_timed_thread =
4124 timed_thread_create ((void*)pop3_thread,
4126 info.mail->interval * 1000000);
4127 if (!info.mail->p_timed_thread)
4128 ERR("Error starting pop3 thread");
4129 timed_thread_register (info.mail->p_timed_thread,
4130 &info.mail->p_timed_thread);
4132 timed_thread_lock (info.mail->p_timed_thread);
4133 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4134 timed_thread_unlock (info.mail->p_timed_thread);
4135 } else if (obj->data.mail) { // this means we use obj
4136 if (!obj->data.mail->p_timed_thread)
4138 obj->data.mail->p_timed_thread =
4139 timed_thread_create ((void*)pop3_thread,
4140 (void*)obj->data.mail,
4141 obj->data.mail->interval * 1000000);
4142 if (!obj->data.mail->p_timed_thread)
4143 ERR("Error starting pop3 thread");
4144 timed_thread_register (obj->data.mail->p_timed_thread,
4145 &obj->data.mail->p_timed_thread);
4147 timed_thread_lock (obj->data.mail->p_timed_thread);
4148 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4149 timed_thread_unlock (obj->data.mail->p_timed_thread);
4150 } else if (!obj->a) { // something is wrong, warn once then stop
4151 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4156 if (obj->data.fs != NULL) {
4157 if (obj->data.fs->size == 0)
4176 if (obj->data.fs != NULL)
4177 human_readable(obj->data.fs->avail,
4181 if (obj->data.fs != NULL) {
4182 if (obj->data.fs->size)
4183 snprintf(p, p_max_size, "%*d",
4192 snprintf(p, p_max_size, "0");
4196 if (obj->data.fs != NULL)
4197 human_readable(obj->data.fs->size,
4201 if (obj->data.fs != NULL)
4202 human_readable(obj->data.fs->size -
4203 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
4207 if (obj->data.fs != NULL) {
4208 if (obj->data.fs->size == 0)
4226 if (obj->data.fs != NULL) {
4227 if (obj->data.fs->size)
4228 snprintf(p, 4, "%d",
4238 snprintf(p, p_max_size, "0");
4242 float *v = info.loadavg;
4244 if (obj->data.loadavg[2])
4245 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4246 v[obj->data.loadavg[0] -
4248 v[obj->data.loadavg[1] -
4250 v[obj->data.loadavg[2] -
4252 else if (obj->data.loadavg[1])
4253 snprintf(p, p_max_size, "%.2f %.2f",
4254 v[obj->data.loadavg[0] -
4256 v[obj->data.loadavg[1] -
4258 else if (obj->data.loadavg[0])
4259 snprintf(p, p_max_size, "%.2f",
4260 v[obj->data.loadavg[0] -
4264 new_goto(p, obj->data.i);
4267 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4270 new_hr(p, obj->data.i);
4274 PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay);
4277 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4279 if(!strcmp(obj->data.rss.action, "feed_title")) {
4281 if(str[strlen(str)-1] == '\n')
4282 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4283 snprintf(p, p_max_size, "%s", str);
4284 } else if(!strcmp(obj->data.rss.action, "item_title")) {
4285 if(obj->data.rss.act_par < data->item_count) {
4286 str = data->items[obj->data.rss.act_par].title;
4287 if(str[strlen(str)-1] == '\n')
4288 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4289 snprintf(p, p_max_size, "%s", str);
4291 } else if(!strcmp(obj->data.rss.action, "item_desc")) {
4292 if(obj->data.rss.act_par < data->item_count) {
4293 str = data->items[obj->data.rss.act_par].description;
4294 if(str[strlen(str)-1] == '\n')
4295 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4296 snprintf(p, p_max_size, "%s", str);
4298 } else if(!strcmp(obj->data.rss.action, "item_titles")) {
4299 if(data->item_count > 0) {
4303 if(obj->data.rss.act_par > data->item_count)
4304 show = data->item_count;
4305 else show = obj->data.rss.act_par;
4306 for(itmp = 0; itmp < show; itmp++) {
4307 PRSS_Item *item = &data->items[itmp];
4310 if(itmp>0) // don't add new line before first item
4311 strncat(p, "\n", p_max_size);
4312 if(str[strlen(str)-1] == '\n')
4313 str[strlen(str)-1] = 0; // remove trailing new line if one exists, we have our own
4314 strncat(p, str, p_max_size);
4327 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4328 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4330 snprintf(p, p_max_size, "N/A");
4331 } else if (unit == '*') {
4332 snprintf(p, p_max_size, "%s", temp);
4334 snprintf(p, p_max_size, "%s°%c", temp, unit);
4339 new_offset(p, obj->data.i);
4342 new_voffset(p, obj->data.i);
4347 r = get_i2c_info(&obj->data.i2c.fd,
4349 obj->data.i2c.devtype,
4350 obj->data.i2c.type);
4352 if (r >= 100.0 || r == 0)
4353 snprintf(p, p_max_size, "%d", (int) r);
4355 snprintf(p, p_max_size, "%.1f", r);
4358 new_alignr(p, obj->data.i);
4361 new_alignc(p, obj->data.i);
4364 struct information *my_info =
4365 malloc(sizeof(struct information));
4366 memcpy(my_info, cur, sizeof(struct information));
4367 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4368 if (strlen(p) != 0) {
4369 i = obj->data.ifblock.pos;
4379 if ((obj->data.ifblock.s)
4380 && (stat(obj->data.ifblock.s, &tmp) ==
4382 i = obj->data.ifblock.pos;
4385 if (obj->data.ifblock.str) {
4386 if (!check_contains(obj->data.ifblock.s,
4387 obj->data.ifblock.str)) {
4388 i = obj->data.ifblock.pos;
4397 if ((obj->data.ifblock.s)
4398 && (!check_mount(obj->data.ifblock.s))) {
4399 i = obj->data.ifblock.pos;
4406 if ((obj->data.ifblock.s)
4407 && system(obj->data.ifblock.s)) {
4408 i = obj->data.ifblock.pos;
4415 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4418 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4423 human_readable(cur->mem * 1024, p, 255);
4426 human_readable(cur->memmax * 1024, p, 255);
4431 snprintf(p, p_max_size, "%*Lu",
4436 snprintf(p, 4, "%*Lu ",
4443 new_bar(p, obj->data.pair.a,
4445 cur->memmax ? (cur->mem * 255) /
4450 new_graph(p, obj->a,
4451 obj->b, obj->c, obj->d,
4452 cur->memmax ? (cur->mem * 100.0) /
4453 (cur->memmax) : 0.0, 100, 1);
4457 snprintf(p, p_max_size, "%d",
4458 mixer_get_avg(obj->data.l));
4461 snprintf(p, p_max_size, "%d",
4462 mixer_get_left(obj->data.l));
4465 snprintf(p, p_max_size, "%d",
4466 mixer_get_right(obj->data.l));
4469 new_bar(p, obj->data.mixerbar.w,
4470 obj->data.mixerbar.h,
4471 mixer_get_avg(obj->data.mixerbar.
4475 new_bar(p, obj->data.mixerbar.w,
4476 obj->data.mixerbar.h,
4477 mixer_get_left(obj->data.mixerbar.
4481 new_bar(p, obj->data.mixerbar.w,
4482 obj->data.mixerbar.h,
4483 mixer_get_right(obj->data.mixerbar.
4489 snprintf(p, p_max_size, "%d", cur->mail_count);
4492 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4493 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4496 snprintf(p, p_max_size, "%d", cur->new_mail_count);
4500 snprintf(p, p_max_size, "%s",
4501 cur->uname_s.nodename);
4504 new_outline(p, obj->data.l);
4508 snprintf(p, p_max_size, "%hu", cur->procs);
4510 snprintf(p, 5, "%hu ",
4513 OBJ(running_processes) {
4515 snprintf(p, p_max_size, "%hu",
4518 snprintf(p, 3, "%hu ",
4522 snprintf(p, p_max_size, "%s", obj->data.s);
4525 new_bg(p, obj->data.l);
4528 new_stippled_hr(p, obj->data.pair.a,
4532 human_readable(cur->swap * 1024, p, 255);
4535 human_readable(cur->swapmax * 1024, p,
4539 if (cur->swapmax == 0) {
4540 strncpy(p, "No swap", 255);
4543 snprintf(p, 255, "%*Lu",
4549 snprintf(p, 4, "%*Lu ",
4557 new_bar(p, obj->data.pair.a,
4559 cur->swapmax ? (cur->swap * 255) /
4560 (cur->swapmax) : 0);
4563 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4566 time_t t = time(NULL);
4567 struct tm *tm = localtime(&t);
4568 setlocale(LC_TIME, "");
4569 strftime(p, p_max_size, obj->data.s, tm);
4572 time_t t = time(NULL);
4573 struct tm *tm = gmtime(&t);
4574 strftime(p, p_max_size, obj->data.s, tm);
4578 if (obj->data.tztime.tz) {
4579 oldTZ = getenv("TZ");
4580 setenv("TZ", obj->data.tztime.tz, 1);
4583 time_t t = time(NULL);
4584 struct tm *tm = localtime(&t);
4585 setlocale(LC_TIME, "");
4586 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4588 setenv("TZ", oldTZ, 1);
4593 // Needless to free oldTZ since getenv gives ptr to static data
4596 human_readable(obj->data.net->recv, p,
4600 human_readable(obj->data.net->trans, p,
4604 snprintf(p, p_max_size, "%d", total_updates);
4608 snprintf(p, p_max_size, "%d",
4609 (int) (obj->data.net->
4613 snprintf(p, 6, "%d ",
4614 (int) (obj->data.net->
4620 snprintf(p, p_max_size, "%.1f",
4622 trans_speed / 1024.0);
4624 snprintf(p, 8, "%.1f ",
4626 trans_speed / 1024.0);
4630 if (obj->data.net->trans_speed == 0)
4631 obj->data.net->trans_speed = 0.01;
4633 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4634 (obj->data.net->trans_speed /
4635 1024.0), obj->e, 1);
4638 format_seconds_short(p, p_max_size,
4642 format_seconds(p, p_max_size, (int) cur->uptime);
4645 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4648 msg = get_apm_adapter();
4649 snprintf(p, p_max_size, "%s", msg);
4652 OBJ(apm_battery_life) {
4654 msg = get_apm_battery_life();
4655 snprintf(p, p_max_size, "%s", msg);
4658 OBJ(apm_battery_time) {
4660 msg = get_apm_battery_time();
4661 snprintf(p, p_max_size, "%s", msg);
4664 #endif /* __FreeBSD__ __OpenBSD__ */
4668 snprintf(p, cur->mpd.max_title_len > 0 ?
4669 cur->mpd.max_title_len : p_max_size, "%s",
4673 snprintf(p, p_max_size, "%s", cur->mpd.artist);
4676 snprintf(p, p_max_size, "%s", cur->mpd.album);
4679 snprintf(p, p_max_size, "%s", cur->mpd.random);
4682 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
4685 snprintf(p, p_max_size, "%s", cur->mpd.track);
4688 snprintf(p, p_max_size, "%s", cur->mpd.name);
4691 snprintf(p, p_max_size, "%s", cur->mpd.file);
4694 snprintf(p, p_max_size, "%i", cur->mpd.volume);
4697 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
4700 snprintf(p, p_max_size, "%s", cur->mpd.status);
4703 int days = 0, hours = 0, minutes =
4705 int tmp = cur->mpd.elapsed;
4706 while (tmp >= 86400) {
4710 while (tmp >= 3600) {
4720 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
4721 days, hours, minutes,
4724 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4727 snprintf(p, p_max_size, "%i:%02i", minutes,
4731 int days = 0, hours = 0, minutes =
4733 int tmp = cur->mpd.length;
4734 while (tmp >= 86400) {
4738 while (tmp >= 3600) {
4748 snprintf(p, p_max_size,
4749 "%i days %i:%02i:%02i",
4750 days, hours, minutes,
4753 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4756 snprintf(p, p_max_size, "%i:%02i", minutes,
4760 snprintf(p, p_max_size, "%2.0f",
4761 cur->mpd.progress * 100);
4764 new_bar(p, obj->data.pair.a,
4766 (int) (cur->mpd.progress *
4770 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.title) < 2) {
4771 snprintf(p, p_max_size, "%s", cur->mpd.file);
4773 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
4779 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4782 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4785 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4788 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4790 OBJ(xmms2_comment) {
4791 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4793 OBJ(xmms2_decoder) {
4794 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
4796 OBJ(xmms2_transport) {
4797 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
4800 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4803 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4806 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4808 OBJ(xmms2_tracknr) {
4809 if (cur->xmms2.tracknr != -1)
4810 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4812 OBJ(xmms2_bitrate) {
4813 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4816 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4819 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4821 OBJ(xmms2_elapsed) {
4822 int tmp = cur->xmms2.elapsed;
4823 snprintf(p, p_max_size, "%02d:%02d",
4824 tmp / 60000, (tmp / 1000) % 60);
4826 OBJ(xmms2_duration) {
4827 int tmp = cur->xmms2.duration;
4828 snprintf(p, p_max_size, "%02d:%02d",
4829 tmp / 60000, (tmp / 1000) % 60);
4831 OBJ(xmms2_percent) {
4832 snprintf(p, p_max_size, "%2.0f",
4833 cur->xmms2.progress * 100);
4836 new_bar(p, obj->data.pair.a,
4838 (int) (cur->xmms2.progress *
4842 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
4843 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4845 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
4850 OBJ(audacious_status) {
4851 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
4853 OBJ(audacious_title) {
4854 snprintf(p, cur->audacious.max_title_len > 0 ?
4855 cur->audacious.max_title_len : p_max_size, "%s",
4856 cur->audacious.items[AUDACIOUS_TITLE]);
4858 OBJ(audacious_length) {
4859 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
4861 OBJ(audacious_length_seconds) {
4862 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4864 OBJ(audacious_position) {
4865 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
4867 OBJ(audacious_position_seconds) {
4868 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
4870 OBJ(audacious_bitrate) {
4871 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
4873 OBJ(audacious_frequency) {
4874 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
4876 OBJ(audacious_channels) {
4877 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
4879 OBJ(audacious_filename) {
4880 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
4882 OBJ(audacious_playlist_length) {
4883 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
4885 OBJ(audacious_playlist_position) {
4886 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
4888 OBJ(audacious_bar) {
4890 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
4891 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4892 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
4897 snprintf(p, p_max_size, "%s", cur->bmpx.title);
4900 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
4903 snprintf(p, p_max_size, "%s", cur->bmpx.album);
4906 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
4909 snprintf(p, p_max_size, "%i", cur->bmpx.track);
4912 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
4916 if (obj->data.top.type == TOP_NAME
4917 && obj->data.top.num >= 0
4918 && obj->data.top.num < 10) {
4919 snprintf(p, 17, "%-17s", cur->cpu[obj->data.top.num]->name);
4920 } else if (obj->data.top.type == TOP_CPU
4921 && obj->data.top.num >= 0
4922 && obj->data.top.num < 10) {
4923 snprintf(p, 7, "%7.3f",
4924 cur->cpu[obj->data.top.
4926 } else if (obj->data.top.type == TOP_PID
4927 && obj->data.top.num >= 0
4928 && obj->data.top.num < 10) {
4929 snprintf(p, 8, "%7i",
4930 cur->cpu[obj->data.top.
4932 } else if (obj->data.top.type == TOP_MEM
4933 && obj->data.top.num >= 0
4934 && obj->data.top.num < 10) {
4935 snprintf(p, 7, "%7.3f",
4936 cur->cpu[obj->data.top.
4941 if (obj->data.top.type == TOP_NAME
4942 && obj->data.top.num >= 0
4943 && obj->data.top.num < 10) {
4944 snprintf(p, 17, "%-17s",
4945 cur->memu[obj->data.top.
4947 } else if (obj->data.top.type == TOP_CPU
4948 && obj->data.top.num >= 0
4949 && obj->data.top.num < 10) {
4950 snprintf(p, 7, "%7.3f",
4951 cur->memu[obj->data.top.
4953 } else if (obj->data.top.type == TOP_PID
4954 && obj->data.top.num >= 0
4955 && obj->data.top.num < 10) {
4956 snprintf(p, 8, "%7i",
4957 cur->memu[obj->data.top.
4959 } else if (obj->data.top.type == TOP_MEM
4960 && obj->data.top.num >= 0
4961 && obj->data.top.num < 10) {
4962 snprintf(p, 7, "%7.3f",
4963 cur->memu[obj->data.top.
4970 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4971 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4973 obj->data.tail.last_update = current_update_time;
4977 fp = fopen(obj->data.tail.logfile, "rt");
4979 /* Send one message, but do not consistently spam on
4980 * missing logfiles. */
4981 if(obj->data.tail.readlines != 0) {
4982 ERR("tail logfile failed to open");
4983 strcpy(obj->data.tail.buffer, "Logfile Missing");
4985 obj->data.tail.readlines = 0;
4986 snprintf(p, p_max_size, "Logfile Missing");
4989 obj->data.tail.readlines = 0;
4990 /* -1 instead of 0 to avoid counting a trailing newline */
4991 fseek(fp, -1, SEEK_END);
4992 bsize = ftell(fp) + 1;
4993 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
4994 nl = rev_fcharfind(fp, '\n', iter);
4998 obj->data.tail.readlines = iter;
4999 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
5000 fseek(fp, 0, SEEK_SET);
5003 fseek(fp, nl+1, SEEK_SET);
5006 /* Make sure bsize is at least 1 byte smaller than
5007 * the buffer max size. */
5008 if(bsize > (long)((text_buffer_size*20) - 1)) {
5009 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
5010 bsize = text_buffer_size*20 - 1;
5012 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5015 /* Clean up trailing newline, make sure the buffer
5016 * is null terminated. */
5017 if(obj->data.tail.buffer[bsize-1] == '\n')
5018 obj->data.tail.buffer[bsize-1] = '\0';
5020 obj->data.tail.buffer[bsize] = '\0';
5021 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5024 strcpy(obj->data.tail.buffer, "Logfile Empty");
5025 snprintf(p, p_max_size, "Logfile Empty");
5028 } /* if cur_upd_time >= */
5030 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5034 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5035 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5037 obj->data.tail.last_update = current_update_time;
5041 fp = fopen(obj->data.tail.logfile, "rt");
5043 /* Send one message, but do not consistently spam on
5044 * missing logfiles. */
5045 if(obj->data.tail.readlines != 0) {
5046 ERR("head logfile failed to open");
5047 strcpy(obj->data.tail.buffer, "Logfile Missing");
5049 obj->data.tail.readlines = 0;
5050 snprintf(p, p_max_size, "Logfile Missing");
5052 obj->data.tail.readlines = 0;
5053 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5054 nl = fwd_fcharfind(fp, '\n', iter);
5058 obj->data.tail.readlines = iter;
5059 /* Make sure nl is at least 1 byte smaller than
5060 * the buffer max size. */
5061 if(nl > (long)((text_buffer_size*20) - 1)) {
5062 nl = text_buffer_size*20 - 1;
5064 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5067 /* Clean up trailing newline, make sure the buffer
5068 * is null terminated. */
5069 if (obj->data.tail.buffer[nl-1] == '\n') {
5070 obj->data.tail.buffer[nl-1] = '\0';
5073 obj->data.tail.buffer[nl] = '\0';
5075 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5078 strcpy(obj->data.tail.buffer, "Logfile Empty");
5079 snprintf(p, p_max_size, "Logfile Empty");
5081 } /* if fp == null */
5082 } /* cur_upd_time >= */
5084 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5087 #ifdef TCP_PORT_MONITOR
5090 /* grab a pointer to this port monitor */
5091 tcp_port_monitor_t * p_monitor =
5092 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
5093 obj->data.tcp_port_monitor.port_range_begin,
5094 obj->data.tcp_port_monitor.port_range_end );
5096 snprintf(p, p_max_size, "monitor not found");
5100 /* now grab the text of interest */
5101 if ( peek_tcp_port_monitor( p_monitor,
5102 obj->data.tcp_port_monitor.item,
5103 obj->data.tcp_port_monitor.connection_index,
5104 p, p_max_size ) != 0 )
5106 snprintf(p, p_max_size, "monitor peek error");
5115 iconv_converting = 1;
5116 iconv_selected = obj->a;
5121 iconv_converting = 0;
5127 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5129 OBJ(entropy_poolsize)
5131 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5135 double entropy_perc;
5136 entropy_perc = (double)cur->entropy.entropy_avail /
5137 (double)cur->entropy.poolsize;
5138 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5146 unsigned int a = strlen(p);
5149 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5151 size_t dummy1, dummy2;
5152 char *ptr = buff_in;
5155 dummy1 = dummy2 = a;
5157 strncpy(buff_in, p, P_MAX_SIZE);
5159 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5160 while (dummy1 > 0) {
5161 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5163 ERR("Iconv codeset conversion failed");
5168 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5179 double current_update_time, last_update_time;
5181 static void generate_text()
5183 struct information *cur = &info;
5191 current_update_time = get_time();
5194 /* fix diskio rates to b/s (use update_interval */
5195 diskio_read_value = diskio_read_value / update_interval;
5196 diskio_write_value = diskio_write_value / update_interval;
5197 diskio_value = diskio_value / update_interval;
5200 /* add things to the buffer */
5206 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5208 if (stuff_in_upper_case) {
5219 last_update_time = current_update_time;
5226 static void set_font()
5230 if (window.xftdraw != NULL) {
5231 XftDrawDestroy(window.xftdraw);
5233 window.xftdraw = XftDrawCreate(display, window.drawable,
5234 DefaultVisual(display,
5236 DefaultColormap(display,
5241 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5247 static inline int get_string_width(const char *s)
5250 return *s ? calc_text_width(s, strlen(s)) : 0;
5256 static inline int get_string_width_special(char *s)
5269 if (*p == SPECIAL_CHAR) {
5270 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5271 for (i = 0; i < strlen(p); i++) {
5272 *(p + i) = *(p + i + 1);
5274 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5275 width += specials[special_index+index].width;
5282 if (strlen(final) > 1) {
5283 width += calc_text_width(final, strlen(final));
5293 static void text_size_updater(char *s);
5295 int last_font_height;
5296 static void update_text_area()
5300 /* update text size if it isn't fixed */
5305 text_width = minimum_width;
5308 last_font_height = font_height();
5309 for_each_line(text_buffer, text_size_updater);
5311 if (text_height < minimum_height)
5312 text_height = minimum_height;
5313 if (text_width > maximum_width && maximum_width > 0)
5314 text_width = maximum_width;
5317 /* get text position on workarea */
5318 switch (text_alignment) {
5325 x = workarea[2] - text_width - gap_x;
5332 y = workarea[3] - text_height - gap_y;
5336 x = workarea[2] - text_width - gap_x;
5337 y = workarea[3] - text_height - gap_y;
5341 case NONE: // Let the WM manage the window
5352 if (own_window && !fixed_pos) {
5355 text_start_x = border_margin + 1;
5356 text_start_y = border_margin + 1;
5357 window.x = x - border_margin - 1;
5358 window.y = y - border_margin - 1;
5362 /* If window size doesn't match to workarea's size, then window
5363 * probably includes panels (gnome).
5364 * Blah, doesn't work on KDE. */
5365 if (workarea[2] != window.width
5366 || workarea[3] != window.height) {
5380 static int cur_x, cur_y; /* current x and y for drawing */
5381 static int draw_mode; /* FG, BG or OUTLINE */
5382 static long current_color;
5385 static void text_size_updater(char *s)
5389 /* get string widths and skip specials */
5392 if (*p == SPECIAL_CHAR) {
5394 w += get_string_width(s);
5397 if (specials[special_index].type == BAR
5398 || specials[special_index].type == GRAPH) {
5399 w += specials[special_index].width;
5400 if (specials[special_index].height > last_font_height) {
5401 last_font_height = specials[special_index].height;
5402 last_font_height += font_ascent();
5404 } else if (specials[special_index].type == OFFSET) {
5405 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
5406 } else if (specials[special_index].type == VOFFSET) {
5407 last_font_height += specials[special_index].arg;
5408 } else if (specials[special_index].type == GOTO) {
5409 if (specials[special_index].arg >= 0)
5410 w += (int)specials[special_index].arg - cur_x;
5411 } else if (specials[special_index].type == TAB) {
5412 int start = specials[special_index].arg;
5413 int step = specials[special_index].width;
5414 if (!step || step < 0)
5416 w += step - (cur_x - text_start_x - start) % step;
5417 } else if (specials[special_index].type == FONT) {
5418 selected_font = specials[special_index].font_added;
5419 if (font_height() > last_font_height) {
5420 last_font_height = font_height();
5429 w += get_string_width(s);
5430 if (w > text_width) {
5433 if (text_width > maximum_width && maximum_width) {
5434 text_width = maximum_width;
5437 text_height += last_font_height;
5438 last_font_height = font_height();
5442 static inline void set_foreground_color(long c)
5445 XSetForeground(display, window.gc, c);
5449 static void draw_string(const char *s)
5453 int i, i2, pos, width_of_s;
5456 width_of_s = get_string_width(s);
5457 if (out_to_console) {
5459 fflush(stdout); /* output immediately, don't buffer */
5461 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5462 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5463 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5467 snprintf(space, 2, " ");
5469 max = ((text_width - width_of_s) / get_string_width(space));
5472 * This code looks for tabs in the text and coverts them to spaces.
5473 * The trick is getting the correct number of spaces,
5474 * and not going over the window's size without forcing
5475 * the window larger.
5477 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5478 if (tmpstring1[i] == '\t') // 9 is ascii tab
5482 i2 < (8 - (1 + pos) % 8) && added <= max;
5485 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5486 fprintf(stderr,"buffer overrun detected\n");
5488 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5493 if (tmpstring1[i] != 9) {
5495 if ( pos > TEXT_BUFFER_SIZE-1 )
5496 fprintf(stderr,"buffer overrun detected\n");
5498 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5504 if (text_width == maximum_width) {
5505 /* this means the text is probably pushing the limit, so we'll chop it */
5506 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5507 tmpstring2[strlen(tmpstring2)-1] = '\0';
5517 c.pixel = current_color;
5518 XQueryColor(display, DefaultColormap(display, screen), &c);
5521 c2.color.red = c.red;
5522 c2.color.green = c.green;
5523 c2.color.blue = c.blue;
5524 c2.color.alpha = fonts[selected_font].font_alpha;
5526 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5527 cur_x, cur_y, (XftChar8 *) s,
5530 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5531 cur_x, cur_y, (XftChar8 *) s,
5537 XDrawString(display, window.drawable, window.gc,
5538 cur_x, cur_y, s, strlen(s));
5540 cur_x += width_of_s;
5542 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5545 long redmask, greenmask, bluemask;
5547 void set_up_gradient()
5550 colour_depth = DisplayPlanes(display, screen);
5554 if (colour_depth != 24 && colour_depth != 16) {
5555 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5561 for(i = (colour_depth / 3)-1; i>=0; i--) {
5563 greenmask |= 1 << i;
5566 if (colour_depth%3 == 1) {
5567 greenmask |= 1 << (colour_depth / 3);
5569 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5570 greenmask = greenmask << (colour_depth / 3);
5573 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 */
5575 int red1, green1, blue1; // first colour
5576 int red2, green2, blue2; // second colour
5577 int red3 = 0, green3 = 0, blue3 = 0; // difference
5578 short redshift = (2*colour_depth / 3 + colour_depth%3);
5579 short greenshift = (colour_depth / 3);
5580 red1 = (first_colour & redmask) >> redshift;
5581 green1 = (first_colour & greenmask) >> greenshift;
5582 blue1 = first_colour & bluemask;
5583 red2 = (last_colour & redmask) >> redshift;
5584 green2 = (last_colour & greenmask) >> greenshift;
5585 blue2 = last_colour & bluemask;
5592 if (green1 > green2) {
5595 if (green1 < green2) {
5598 if (blue1 > blue2) {
5601 if (blue1 < blue2) {
5616 if (red1 > bluemask) {
5619 if (green1 > bluemask) {
5622 if (blue1 > bluemask) {
5625 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
5629 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
5630 if (colour_depth == 0) {
5633 int red1, green1, blue1; // first colour
5634 int red2, green2, blue2; // second colour
5635 long redshift = (2*colour_depth / 3 + colour_depth%3);
5636 long greenshift = (colour_depth / 3);
5637 int red3 = 0, green3 = 0, blue3 = 0; // difference
5638 red1 = (first_colour & redmask) >> redshift;
5639 green1 = (first_colour & greenmask) >> greenshift;
5640 blue1 = first_colour & bluemask;
5641 red2 = (last_colour & redmask) >> redshift;
5642 green2 = (last_colour & greenmask) >> greenshift;
5643 blue2 = last_colour & bluemask;
5644 red3 = abs(red1 - red2);
5645 green3 = abs(green1 - green2);
5646 blue3 = abs(blue1 - blue2);
5655 static void draw_line(char *s)
5659 cur_x = text_start_x;
5660 cur_y += font_ascent();
5662 short font_h = font_height();
5664 /* find specials and draw stuff */
5667 if (*p == SPECIAL_CHAR) {
5670 /* draw string before special */
5677 switch (specials[special_index].type) {
5678 case HORIZONTAL_LINE:
5681 specials[special_index].height;
5682 int mid = font_ascent() / 2;
5683 w = text_start_x + text_width -
5686 XSetLineAttributes(display,
5691 XDrawLine(display, window.drawable,
5702 specials[special_index].height;
5704 specials[special_index].arg;
5705 int mid = font_ascent() / 2;
5706 char ss[2] = { s, s };
5707 w = text_start_x + text_width -
5710 XSetLineAttributes(display,
5715 XSetDashes(display, window.gc, 0,
5717 XDrawLine(display, window.drawable,
5727 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5731 specials[special_index].height;
5733 specials[special_index].arg;
5734 int by = cur_y - (font_ascent() / 2) - 1;
5735 if (h < font_height()) {
5738 w = specials[special_index].width;
5741 text_width - cur_x - 1;
5745 XSetLineAttributes(display,
5751 XDrawRectangle(display,
5755 XFillRectangle(display,
5759 w * bar_usage / 255,
5761 if (specials[special_index].
5763 && specials[special_index].
5767 [special_index].height;
5774 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5778 specials[special_index].height;
5779 unsigned long last_colour = current_color;
5780 int by = cur_y - (font_ascent()/2) - 1;
5781 if (h < font_height()) {
5784 w = specials[special_index].width;
5786 w = text_start_x + text_width - cur_x - 1;
5789 if (draw_graph_borders) {
5790 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
5791 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
5793 XSetLineAttributes(display,
5800 int gradient_size = 0;
5801 float gradient_factor = 0;
5802 float gradient_update = 0;
5803 unsigned long tmpcolour = current_color;
5804 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5805 tmpcolour = specials[special_index].last_colour;
5806 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
5807 gradient_factor = (float)gradient_size / (w - 2);
5809 for (i = w - 2; i > -1; i--) {
5810 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5811 XSetForeground(display, window.gc, tmpcolour);
5812 gradient_update += gradient_factor;
5813 while (gradient_update > 0) {
5814 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
5818 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
5821 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 */
5823 if (specials[special_index].
5825 && specials[special_index].
5829 [special_index].height;
5831 /* if (draw_mode == BG) {
5832 set_foreground_color(default_bg_color);
5834 else if (draw_mode == OUTLINE) {
5835 set_foreground_color(default_out_color);
5837 set_foreground_color(default_fg_color);
5839 set_foreground_color(last_colour);
5845 int old = font_ascent();
5846 cur_y -= font_ascent();
5847 selected_font = specials[special_index].font_added;
5848 if (cur_y + font_ascent() < cur_y + old) {
5851 cur_y += font_ascent();
5857 if (draw_mode == FG)
5858 set_foreground_color(specials
5864 if (draw_mode == BG)
5865 set_foreground_color(specials
5871 if (draw_mode == OUTLINE)
5872 set_foreground_color(specials
5878 w += specials[special_index].arg;
5882 cur_y += specials[special_index].arg;
5886 if (specials[special_index].arg >= 0)
5887 cur_x = (int)specials[special_index].arg;
5892 int start = specials[special_index].arg;
5893 int step = specials[special_index].width;
5894 if (!step || step < 0)
5896 w = step - (cur_x - text_start_x - start) % step;
5902 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
5903 /*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);*/
5904 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
5905 cur_x = pos_x - specials[special_index].arg;
5912 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
5913 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
5914 /*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);*/
5916 specials[special_index].arg)
5919 [special_index].arg;
5936 if (cur_y_add > 0) {
5938 cur_y -= font_descent();
5943 cur_y += font_descent();
5947 static void draw_text()
5950 cur_y = text_start_y;
5953 if (draw_borders && border_width > 0) {
5954 unsigned int b = (border_width + 1) / 2;
5956 if (stippled_borders) {
5958 { stippled_borders, stippled_borders };
5959 XSetLineAttributes(display, window.gc,
5960 border_width, LineOnOffDash,
5961 CapButt, JoinMiter);
5962 XSetDashes(display, window.gc, 0, ss, 2);
5964 XSetLineAttributes(display, window.gc,
5965 border_width, LineSolid,
5966 CapButt, JoinMiter);
5969 XDrawRectangle(display, window.drawable, window.gc,
5970 text_start_x - border_margin + b,
5971 text_start_y - border_margin + b,
5972 text_width + border_margin * 2 - 1 - b * 2,
5973 text_height + border_margin * 2 - 1 -
5980 for_each_line(text_buffer, draw_line);
5983 static void draw_stuff()
5987 if (draw_shades && !draw_outline) {
5990 set_foreground_color(default_bg_color);
6000 for (i = -1; i < 2; i++)
6001 for (j = -1; j < 2; j++) {
6002 if (i == 0 && j == 0)
6006 set_foreground_color(default_out_color);
6007 draw_mode = OUTLINE;
6014 set_foreground_color(default_fg_color);
6022 swap.swap_window = window.window;
6023 swap.swap_action = XdbeBackground;
6024 XdbeSwapBuffers(display, &swap, 1);
6030 static void clear_text(int exposures)
6034 return; /* The swap action is XdbeBackground, which clears */
6038 /* there is some extra space for borders and outlines */
6039 XClearArea(display, window.window,
6040 text_start_x - border_margin - 1,
6041 text_start_y - border_margin - 1,
6042 text_width + border_margin * 2 + 2,
6043 text_height + border_margin * 2 + 2,
6044 exposures ? True : 0);
6049 static int need_to_update;
6051 /* update_text() generates new text and clears old text area */
6052 static void update_text()
6061 static void main_loop()
6063 #ifdef SIGNAL_BLOCKING
6064 sigset_t newmask, oldmask;
6066 sigemptyset(&newmask);
6067 sigaddset(&newmask,SIGINT);
6068 sigaddset(&newmask,SIGTERM);
6069 sigaddset(&newmask,SIGUSR1);
6073 Region region = XCreateRegion();
6075 int event_base, error_base;
6076 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
6077 ERR("Xdamage extension unavailable");
6079 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
6080 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
6081 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
6082 #endif /* HAVE_XDAMAGE */
6086 while (total_run_times == 0 || info.looped < total_run_times) {
6089 #ifdef SIGNAL_BLOCKING
6090 /* block signals. we will inspect for pending signals later */
6091 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
6092 CRIT_ERR("unable to sigprocmask()");
6098 /* wait for X event or timeout */
6100 if (!XPending(display)) {
6105 update_interval - (get_time() -
6111 tv.tv_sec = (long) t;
6112 tv.tv_usec = (long) (t * 1000000) % 1000000;
6114 FD_SET(ConnectionNumber(display), &fdsr);
6117 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
6120 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
6125 ERR("can't select(): %s",
6136 if (need_to_update) {
6138 int wx = window.x, wy = window.y;
6146 /* resize window if it isn't right size */
6148 (text_width + border_margin * 2 + 1 !=
6150 || text_height + border_margin * 2 + 1 !=
6154 border_margin * 2 + 1;
6157 border_margin * 2 + 1;
6158 XResizeWindow(display,
6163 set_transparent_background(window.window);
6167 /* move window if it isn't in right position */
6170 || window.y != wy)) {
6171 XMoveWindow(display, window.window,
6172 window.x, window.y);
6182 r.x = text_start_x - border_margin;
6183 r.y = text_start_y - border_margin;
6184 r.width = text_width + border_margin * 2;
6185 r.height = text_height + border_margin * 2;
6186 XUnionRectWithRegion(&r, region, region);
6191 /* handle X events */
6193 while (XPending(display)) {
6195 XNextEvent(display, &ev);
6202 r.width = ev.xexpose.width;
6203 r.height = ev.xexpose.height;
6204 XUnionRectWithRegion(&r, region,
6210 case ReparentNotify:
6211 /* set background to ParentRelative for all parents */
6213 set_transparent_background(window.
6218 case ConfigureNotify:
6220 /* if window size isn't what expected, set fixed size */
6221 if (ev.xconfigure.width !=
6223 || ev.xconfigure.height !=
6225 if (window.width != 0
6226 && window.height != 0)
6229 /* clear old stuff before screwing up size and pos */
6235 if (XGetWindowAttributes(display, window.window, &attrs)) {
6250 border_margin * 2 - 1;
6253 border_margin * 2 - 1;
6254 if (text_width > maximum_width && maximum_width > 0)
6255 text_width = maximum_width;
6258 /* if position isn't what expected, set fixed pos, total_updates
6259 * avoids setting fixed_pos when window is set to weird locations
6261 /*if (total_updates >= 2 this is broken
6263 && (window.x != ev.xconfigure.x
6266 && (ev.xconfigure.x != 0
6267 || ev.xconfigure.y != 0)) {
6277 /* if an ordinary window with decorations */
6278 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6280 /* allow conky to hold input focus.*/
6285 /* forward the click to the desktop window */
6286 XUngrabPointer(display, ev.xbutton.time);
6287 ev.xbutton.window = window.desktop;
6288 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6289 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6297 /* if an ordinary window with decorations */
6298 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6300 /* allow conky to hold input focus.*/
6305 /* forward the release to the desktop window */
6306 ev.xbutton.window = window.desktop;
6307 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6316 if (ev.type == event_base + XDamageNotify) {
6317 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6318 XFixesSetRegion(display, part, &dev->area, 1);
6319 XFixesUnionRegion(display, region2, region2, part);
6321 #endif /* HAVE_XDAMAGE */
6326 XDamageSubtract(display, damage, region2, None);
6327 XFixesSetRegion(display, region2, 0, 0);
6328 #endif /* HAVE_XDAMAGE */
6330 /* XDBE doesn't seem to provide a way to clear the back buffer without
6331 * interfering with the front buffer, other than passing XdbeBackground
6332 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6333 * redraw the text even if it wasn't part of the exposed area. OTOH,
6334 * if we're not going to call draw_stuff at all, then no swap happens
6335 * and we can safely do nothing.
6338 if (!XEmptyRegion(region)) {
6342 r.x = text_start_x - border_margin;
6343 r.y = text_start_y - border_margin;
6344 r.width = text_width + border_margin * 2;
6345 r.height = text_height + border_margin * 2;
6346 XUnionRectWithRegion(&r, region, region);
6349 XSetRegion(display, window.gc, region);
6352 XftDrawSetClip(window.xftdraw, region);
6358 XDestroyRegion(region);
6359 region = XCreateRegion();
6363 #ifdef SIGNAL_BLOCKING
6364 /* unblock signals of interest and let handler fly */
6365 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6366 CRIT_ERR("unable to sigprocmask()");
6369 switch(g_signal_pending) {
6372 ERR("received SIGUSR1. reloading the config file.");
6379 ERR("received SIGINT or SIGTERM to terminate. bye!");
6382 XDestroyRegion(region);
6385 return; /* return from main_loop */
6390 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6391 * but didn't write any code to deal with it. if you don't want to
6392 * handle a signal, don't set a handler on it in the first place. */
6393 if (g_signal_pending)
6394 ERR("ignoring signal (%d)", g_signal_pending);
6401 #if defined(X11) && defined(HAVE_XDAMAGE)
6402 XDamageDestroy(display, damage);
6403 XFixesDestroyRegion(display, region2);
6404 XFixesDestroyRegion(display, part);
6405 XDestroyRegion(region);
6407 #endif /* X11 && HAVE_XDAMAGE */
6410 static void load_config_file(const char *);
6412 /* reload the config file */
6413 void reload_config(void)
6415 timed_thread_destroy_registered_threads ();
6417 if (info.cpu_usage) {
6418 free(info.cpu_usage);
6419 info.cpu_usage = NULL;
6422 #ifdef TCP_PORT_MONITOR
6423 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6426 if (current_config) {
6428 load_config_file(current_config);
6430 /* re-init specials array */
6431 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6432 ERR("failed to realloc specials array");
6437 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6440 #ifdef TCP_PORT_MONITOR
6441 info.p_tcp_port_monitor_collection = NULL;
6444 if (create_audacious_thread() !=0)
6445 CRIT_ERR("unable to create audacious thread!");
6446 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6448 extract_variable_text(text);
6457 timed_thread_destroy_registered_threads ();
6459 if (info.cpu_usage) {
6460 free(info.cpu_usage);
6461 info.cpu_usage = NULL;
6466 XdbeDeallocateBackBufferName(display, window.back_buffer);
6472 XDestroyWindow(display, window.window);
6473 XClearWindow(display, RootWindow(display, screen));
6479 XClearWindow(display, RootWindow(display, screen));
6484 XFreeGC(display, window.gc);
6487 free_text_objects(text_object_count, text_objects);
6488 text_object_count = 0;
6489 text_objects = NULL;
6491 if (text != original_text)
6494 free(current_config);
6495 free(current_mail_spool);
6497 #ifdef TCP_PORT_MONITOR
6498 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6499 info.p_tcp_port_monitor_collection = NULL;
6507 for(i=0;i<special_count;i++)
6508 if(specials[i].type == GRAPH)
6509 free(specials[i].graph);
6515 static int string_to_bool(const char *s)
6519 if (strcasecmp(s, "yes") == 0)
6521 if (strcasecmp(s, "true") == 0)
6523 if (strcasecmp(s, "1") == 0)
6528 static enum alignment string_to_alignment(const char *s)
6530 if (strcasecmp(s, "top_left") == 0)
6532 else if (strcasecmp(s, "top_right") == 0)
6534 else if (strcasecmp(s, "bottom_left") == 0)
6536 else if (strcasecmp(s, "bottom_right") == 0)
6537 return BOTTOM_RIGHT;
6538 else if (strcasecmp(s, "tl") == 0)
6540 else if (strcasecmp(s, "tr") == 0)
6542 else if (strcasecmp(s, "bl") == 0)
6544 else if (strcasecmp(s, "br") == 0)
6545 return BOTTOM_RIGHT;
6546 else if (strcasecmp(s, "none") == 0)
6553 static void set_default_configurations(void)
6555 fork_to_background = 0;
6556 total_run_times = 0;
6557 info.cpu_avg_samples = 2;
6558 info.net_avg_samples = 2;
6563 strcpy(info.mpd.host, "localhost");
6564 info.mpd.port = 6600;
6565 info.mpd.status = NULL;
6566 info.mpd.artist = NULL;
6567 info.mpd.album = NULL;
6568 info.mpd.title = NULL;
6569 info.mpd.random = NULL;
6570 info.mpd.track = NULL;
6571 info.mpd.name = NULL;
6572 info.mpd.file = NULL;
6575 info.xmms2.artist = NULL;
6576 info.xmms2.album = NULL;
6577 info.xmms2.title = NULL;
6578 info.xmms2.genre = NULL;
6579 info.xmms2.comment = NULL;
6580 info.xmms2.decoder = NULL;
6581 info.xmms2.transport = NULL;
6582 info.xmms2.url = NULL;
6583 info.xmms2.status = NULL;
6592 default_fg_color = WhitePixel(display, screen);
6593 default_bg_color = BlackPixel(display, screen);
6594 default_out_color = BlackPixel(display, screen);
6595 color0 = default_fg_color;
6596 color1 = default_fg_color;
6597 color2 = default_fg_color;
6598 color3 = default_fg_color;
6599 color4 = default_fg_color;
6600 color5 = default_fg_color;
6601 color6 = default_fg_color;
6602 color7 = default_fg_color;
6603 color8 = default_fg_color;
6604 color9 = default_fg_color;
6607 draw_graph_borders = 1;
6609 set_first_font("6x10");
6617 window.type=TYPE_NORMAL;
6619 strcpy(window.class_name, "Conky");
6621 sprintf(window.title,"%s - conky",info.uname_s.nodename);
6623 stippled_borders = 0;
6626 text_alignment = BOTTOM_LEFT;
6629 free(current_mail_spool);
6632 variable_substitute(MAIL_FILE, buf, 256);
6634 current_mail_spool = strdup(buf);
6638 update_interval = 10.0;
6639 stuff_in_upper_case = 0;
6641 #ifdef TCP_PORT_MONITOR
6642 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6646 static void load_config_file(const char *f)
6648 #define CONF_ERR ERR("%s: %d: config file error", f, line)
6652 set_default_configurations();
6658 char buf[256], *p, *p2, *name, *value;
6660 if (fgets(buf, 256, fp) == NULL)
6665 /* break at comment */
6666 p2 = strchr(p, '#');
6671 while (*p && isspace((int) *p))
6674 continue; /* empty line */
6680 while (*p2 && !isspace((int) *p2))
6683 *p2 = '\0'; /* break at name's end */
6690 while (*p && isspace((int) *p))
6695 p2 = value + strlen(value);
6696 while (isspace((int) *(p2 - 1)))
6702 #define CONF2(a) if (strcasecmp(name, a) == 0)
6703 #define CONF(a) else CONF2(a)
6704 #define CONF3(a,b) \
6705 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
6709 CONF2("alignment") {
6711 int a = string_to_alignment(value);
6719 CONF("background") {
6720 fork_to_background = string_to_bool(value);
6724 CONF2("background") {
6725 fork_to_background = string_to_bool(value);
6729 CONF("border_margin") {
6731 border_margin = strtol(value, 0, 0);
6735 CONF("border_width") {
6737 border_width = strtol(value, 0, 0);
6743 color0 = get_x11_color(value);
6749 color1 = get_x11_color(value);
6755 color2 = get_x11_color(value);
6761 color3 = get_x11_color(value);
6767 color4 = get_x11_color(value);
6773 color5 = get_x11_color(value);
6779 color6 = get_x11_color(value);
6785 color7 = get_x11_color(value);
6791 color8 = get_x11_color(value);
6797 color9 = get_x11_color(value);
6801 CONF("default_color") {
6803 default_fg_color = get_x11_color(value);
6807 CONF3("default_shade_color", "default_shadecolor") {
6809 default_bg_color = get_x11_color(value);
6813 CONF3("default_outline_color", "default_outlinecolor") {
6815 default_out_color = get_x11_color(value);
6822 info.mail = parse_mail_args(IMAP, value);
6829 info.mail = parse_mail_args(POP3, value);
6837 strncpy(info.mpd.host, value, 127);
6843 info.mpd.port = strtol(value, 0, 0);
6844 if (info.mpd.port < 1
6845 || info.mpd.port > 0xffff)
6849 CONF("mpd_password") {
6851 strncpy(info.mpd.password, value, 127);
6857 CONF("sensor_device") {
6859 sensor_device = strtol(value, 0, 0);
6864 CONF("cpu_avg_samples") {
6866 cpu_avg_samples = strtol(value, 0, 0);
6867 if (cpu_avg_samples < 1
6868 || cpu_avg_samples > 14)
6877 CONF("net_avg_samples") {
6879 net_avg_samples = strtol(value, 0, 0);
6880 if (net_avg_samples < 1
6881 || net_avg_samples > 14)
6897 CONF("double_buffer") {
6898 use_xdbe = string_to_bool(value);
6902 CONF("override_utf8_locale") {
6903 utf8_mode = string_to_bool(value);
6906 CONF("draw_borders") {
6907 draw_borders = string_to_bool(value);
6909 CONF("draw_graph_borders") {
6910 draw_graph_borders = string_to_bool(value);
6912 CONF("draw_shades") {
6913 draw_shades = string_to_bool(value);
6915 CONF("draw_outline") {
6916 draw_outline = string_to_bool(value);
6919 CONF("out_to_console") {
6920 out_to_console = string_to_bool(value);
6922 CONF("use_spacer") {
6923 use_spacer = string_to_bool(value);
6928 use_xft = string_to_bool(value);
6932 set_first_font(value);
6937 if (value && font_count >= 0)
6938 fonts[0].font_alpha = atof(value)
6947 if (string_to_bool(value))
6948 ERR("Xft not enabled");
6951 /* xftfont silently ignored when no Xft */
6954 /* xftalpha is silently ignored when no Xft */
6959 set_first_font(value);
6968 gap_x = atoi(value);
6974 gap_y = atoi(value);
6979 CONF("mail_spool") {
6982 variable_substitute(value, buf, 256);
6986 if (current_mail_spool)
6987 free(current_mail_spool);
6988 current_mail_spool = strdup(buf);
6994 CONF("minimum_size") {
6997 (value, "%d %d", &minimum_width,
6998 &minimum_height) != 2)
7001 &minimum_width) != 1)
7006 CONF("maximum_width") {
7008 if (sscanf(value, "%d", &maximum_width) != 1)
7014 CONF("no_buffers") {
7015 no_buffers = string_to_bool(value);
7017 CONF("pad_percents") {
7018 pad_percents = atoi(value);
7022 CONF("own_window") {
7024 own_window = string_to_bool(value);
7028 CONF("own_window_class") {
7031 memset(window.class_name,0,sizeof(window.class_name));
7032 strncpy(window.class_name, value, sizeof(window.class_name)-1);
7037 CONF("own_window_title") {
7040 memset(window.title,0,sizeof(window.title));
7041 strncpy(window.title, value, sizeof(window.title)-1);
7046 CONF("own_window_transparent") {
7048 set_transparent = string_to_bool(value);
7052 CONF("own_window_colour") {
7054 background_colour = get_x11_color(value);
7056 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
7059 CONF("own_window_hints") {
7061 char *p_hint, *p_save;
7062 char delim[] = ", ";
7064 /* tokenize the value into individual hints */
7065 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
7067 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
7068 if (strncmp(p_hint,"undecorate",10) == 0)
7069 SET_HINT(window.hints,HINT_UNDECORATED);
7070 else if (strncmp(p_hint,"below",5) == 0)
7071 SET_HINT(window.hints,HINT_BELOW);
7072 else if (strncmp(p_hint,"above",5) == 0)
7073 SET_HINT(window.hints,HINT_ABOVE);
7074 else if (strncmp(p_hint,"sticky",6) == 0)
7075 SET_HINT(window.hints,HINT_STICKY);
7076 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
7077 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
7078 else if (strncmp(p_hint,"skip_pager",10) == 0)
7079 SET_HINT(window.hints,HINT_SKIP_PAGER);
7083 p_hint=strtok_r(NULL, delim, &p_save);
7085 while (p_hint!=NULL);
7090 CONF("own_window_type") {
7092 if (strncmp(value,"normal",6)==0)
7093 window.type = TYPE_NORMAL;
7094 else if (strncmp(value,"desktop",7)==0)
7095 window.type = TYPE_DESKTOP;
7096 else if (strncmp(value,"override",8)==0)
7097 window.type = TYPE_OVERRIDE;
7105 CONF("stippled_borders") {
7107 stippled_borders = strtol(value, 0, 0);
7109 stippled_borders = 4;
7113 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
7116 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
7118 CONF("update_interval") {
7120 update_interval = strtod(value, 0);
7124 CONF("total_run_times") {
7126 total_run_times = strtod(value, 0);
7131 stuff_in_upper_case = string_to_bool(value);
7133 CONF("max_specials") {
7135 max_specials = atoi(value);
7139 CONF("max_user_text") {
7141 max_user_text = atoi(value);
7145 CONF("text_buffer_size") {
7147 text_buffer_size = atoi(value);
7152 if (text != original_text)
7162 int l = strlen(text);
7163 if (fgets(buf, 256, fp) == NULL)
7166 realloc(text, l + strlen(buf)
7170 if (strlen(text) > max_user_text)
7174 text_lines = line + 1;
7177 #ifdef TCP_PORT_MONITOR
7178 CONF("max_port_monitor_connections")
7181 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7182 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
7184 /* an error. use default, warn and continue. */
7185 tcp_port_monitor_args.max_port_monitor_connections =
7186 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7189 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
7191 /* no error, just use default */
7192 tcp_port_monitor_args.max_port_monitor_connections =
7193 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7195 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
7200 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7212 /* : means that character before that takes an argument */
7213 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
7226 int main(int argc, char **argv)
7228 struct sigaction act, oact;
7231 memset(&info, 0, sizeof(info) );
7233 #ifdef TCP_PORT_MONITOR
7234 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7237 /* handle command line parameters that don't change configs */
7242 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7243 *s) || ((s = getenv("LANG")) && *s)) {
7244 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7246 ERR("malloc failed");
7248 for (x = 0; x < strlen(s); x++) {
7249 temp[x] = tolower(s[x]);
7252 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7258 if (!setlocale(LC_CTYPE, "")) {
7259 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7263 int c = getopt(argc,
7274 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
7275 * though free() does the NULL check itself;), then load optarg value */
7277 free(current_config);
7278 current_config = strdup(optarg);
7283 ("Usage: %s [OPTION]...\n"
7284 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7285 "window. Command line options will override configurations defined in config\n"
7288 " -c FILE config file to load instead of "
7291 " -d daemonize, fork to background\n"
7294 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7295 " -f FONT font to use\n"
7297 " -o create own window to draw\n"
7300 " -b double buffer (prevents flickering)\n"
7302 " -w WIN_ID window id to draw\n"
7303 " -x X x position\n"
7304 " -y Y y position\n"
7306 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
7307 " -u SECS update interval\n"
7308 " -i NUM number of times to update Conky\n", argv[0]);
7312 window.window = strtol(optarg, 0, 0);
7321 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7325 /* load current_config or CONFIG_FILE */
7328 if (current_config == NULL) {
7329 /* load default config file */
7332 variable_substitute(CONFIG_FILE, buf, 256);
7335 current_config = strdup(buf);
7339 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
7340 load_config_file(current_config);
7342 set_default_configurations();
7345 /* init specials array */
7346 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7347 ERR("failed to create specials array");
7350 if (current_mail_spool == NULL) {
7352 variable_substitute(MAIL_FILE, buf, 256);
7355 current_mail_spool = strdup(buf);
7359 /* handle other command line arguments */
7361 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
7362 optind = optreset = 1;
7367 #if defined(__FreeBSD__)
7368 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7369 O_RDONLY, "kvm_open")) == NULL)
7370 CRIT_ERR( "cannot read kvm");
7374 int c = getopt(argc,
7382 fork_to_background = 1;
7387 set_first_font(optarg);
7390 text_alignment = string_to_alignment(optarg);
7405 if (text != original_text)
7407 text = strdup(optarg);
7408 convert_escapes(text);
7412 update_interval = strtod(optarg, 0);
7416 total_run_times = strtod(optarg, 0);
7420 gap_x = atoi(optarg);
7424 gap_y = atoi(optarg);
7438 /* generate text and get initial size */
7439 extract_variable_text(text);
7440 if (text != original_text) {
7445 if (fork_to_background) {
7449 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
7455 fprintf(stderr,"\n"); fflush(stderr);
7459 /* parent process */
7460 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
7467 update_text_area(); /* to get initial size of the window */
7471 text_width + border_margin * 2 + 1,
7472 text_height + border_margin * 2 + 1,
7473 set_transparent, background_colour, argv, argc);
7476 update_text_area(); /* to position text/window on screen */
7481 if (own_window && !fixed_pos) {
7482 XMoveWindow(display, window.window, window.x, window.y);
7485 set_transparent_background(window.window);
7496 /* Set signal handlers */
7497 act.sa_handler = signal_handler;
7498 sigemptyset(&act.sa_mask);
7501 act.sa_flags |= SA_RESTART;
7504 if ( sigaction(SIGINT,&act,&oact) < 0 ||
7505 sigaction(SIGUSR1,&act,&oact) < 0 ||
7506 sigaction(SIGTERM,&act,&oact) < 0 )
7508 ERR("error setting signal handler: %s", strerror(errno) );
7512 if (create_audacious_thread() !=0)
7513 CRIT_ERR("unable to create audacious thread!");
7514 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
7525 #if defined(__FreeBSD__)
7532 void signal_handler(int sig)
7534 /* signal handler is light as a feather, as it should be.
7535 * we will poll g_signal_pending with each loop of conky
7536 * and do any signal processing there, NOT here. */
7537 g_signal_pending=sig;