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 */
104 #if defined(__linux__)
106 #endif /* __linux__ */
114 static int text_start_x, text_start_y; /* text start position in window */
115 static int text_width, text_height;
130 char name[TEXT_BUFFER_SIZE];
140 static int selected_font = 0;
141 static int font_count = -1;
142 struct font_list *fonts = NULL;
146 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
147 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent))
148 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent)
149 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent)
153 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
154 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
155 #define font_descent() fonts[selected_font].font->max_bounds.descent
159 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
162 static void set_font();
164 int addfont(const char *data_in)
166 if (font_count > MAX_FONTS) {
167 CRIT_ERR("you don't need that many fonts, sorry.");
170 if (font_count == 0) {
174 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
178 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
180 CRIT_ERR("realloc in addfont");
182 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
183 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
185 fonts[font_count].font_alpha = 0xffff;
188 CRIT_ERR("Oops...looks like something overflowed in addfont().");
193 void set_first_font(const char *data_in)
195 if (font_count < 0) {
196 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
201 if (strlen(data_in) > 1) {
202 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
204 fonts[0].font_alpha = 0xffff;
212 for (i=0;i<=font_count;i++) {
215 XftFontClose(display, fonts[i].xftfont);
219 XFreeFont(display, fonts[i].font);
226 set_first_font("6x10");
230 static void load_fonts()
233 for (i=0; i <= font_count; i++) {
237 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
238 XftFontClose(display, fonts[i].xftfont);
240 if ((fonts[i].xftfont =
241 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
244 ERR("can't load Xft font '%s'", fonts[i].name);
245 if ((fonts[i].xftfont =
246 XftFontOpenName(display, screen,
247 "courier-12")) != NULL)
250 ERR("can't load Xft font '%s'", "courier-12");
252 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
253 CRIT_ERR("can't load font '%s'", "fixed");
260 /* load normal font */
261 /* if (fonts[i].font != NULL)
262 XFreeFont(display, fonts[i].font);*/
264 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
265 ERR("can't load font '%s'", fonts[i].name);
266 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
267 CRIT_ERR("can't load font '%s'", "fixed");
268 printf("loaded fixed?\n");
276 /* default config file */
277 static char *current_config;
279 /* set to 1 if you want all text to be in uppercase */
280 static unsigned int stuff_in_upper_case;
282 /* Run how many times? */
283 static unsigned long total_run_times;
286 static int fork_to_background;
288 static int cpu_avg_samples, net_avg_samples;
292 /* Position on the screen */
293 static int text_alignment;
294 static int gap_x, gap_y;
297 static int draw_borders;
298 static int draw_graph_borders;
299 static int stippled_borders;
301 static int draw_shades, draw_outline;
303 static int border_margin, border_width;
305 static long default_fg_color, default_bg_color, default_out_color;
307 /* create own window or draw stuff to root? */
308 static int set_transparent = 0;
312 static int own_window = 0;
313 static int background_colour = 0;
314 /* fixed size/pos is set if wm/user changes them */
315 static int fixed_size = 0, fixed_pos = 0;
318 static int minimum_width, minimum_height;
319 static int maximum_width;
324 static int sensor_device;
327 static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
329 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
330 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
332 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
333 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
335 /* maximum size of individual text buffers, ie $exec buffer size */
336 unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
339 #define CODEPAGE_LENGTH 20
341 long iconv_count = 0;
342 char iconv_converting;
343 static iconv_t **iconv_cd = 0;
345 int register_iconv(iconv_t *new_iconv)
348 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
350 iconv_cd = malloc(sizeof(iconv_t *));
353 CRIT_ERR("Out of memory");
355 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
356 if (!iconv_cd[iconv_count]) {
357 CRIT_ERR("Out of memory");
359 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
364 void free_iconv(void)
368 for (i = 0; i < iconv_count; i++) {
370 iconv_close(*iconv_cd[i]);
385 /* no buffers in used memory? */
388 /* pad percentages to decimals? */
389 static int pad_percents = 0;
391 #ifdef TCP_PORT_MONITOR
392 tcp_port_monitor_args_t tcp_port_monitor_args;
395 /* Text that is shown */
396 static char original_text[] =
397 "$nodename - $sysname $kernel on $machine\n"
399 "${color grey}Uptime:$color $uptime\n"
400 "${color grey}Frequency (in MHz):$color $freq\n"
401 "${color grey}Frequency (in GHz):$color $freq_g\n"
402 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
403 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
404 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
405 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
407 "${color grey}File systems:\n"
408 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
409 "${color grey}Networking:\n"
410 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
413 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
414 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
417 "${color grey}XMMS2: $xmms2_status $xmms2_artist - $xmms2_title from $xmms2_album\n"
418 "Progress: $xmms2_bar\n"
420 "${color grey}Name PID CPU% MEM%\n"
421 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
422 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
423 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
424 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
425 "${tail /var/log/Xorg.0.log 3}";
427 static char *text = original_text;
430 static int total_updates;
433 static int blockdepth = 0;
434 static int if_jumped = 0;
435 static int blockstart[MAX_IF_BLOCK_DEPTH];
437 int check_contains(char *f, char *s)
440 FILE *where = fopen(f, "r");
442 char buf1[256], buf2[256];
443 while (fgets(buf1, 256, where)) {
444 sscanf(buf1, "%255s", buf2);
445 if (strstr(buf2, s)) {
452 ERR("Could not open the file");
459 static inline int calc_text_width(const char *s, int l)
465 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
467 XftTextExtents8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
473 return XTextWidth(fonts[selected_font].font, s, l);
478 /* formatted text to render on screen, generated in generate_text(),
479 * drawn in draw_stuff() */
481 static char text_buffer[TEXT_BUFFER_SIZE * 4];
483 /* special stuff in text_buffer */
485 #define SPECIAL_CHAR '\x01'
514 unsigned long first_colour; // for graph gradient
515 unsigned long last_colour;
518 /* create specials array on heap instead of stack with introduction of max_specials */
519 static struct special_t *specials = NULL;
521 static unsigned int special_count;
523 static unsigned int special_index; /* used when drawing */
526 #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? */
528 static struct special_t *new_special(char *buf, int t)
530 if (special_count >= max_specials)
531 CRIT_ERR("too many special things in text");
533 buf[0] = SPECIAL_CHAR;
535 specials[special_count].type = t;
536 return &specials[special_count++];
539 long fwd_fcharfind(FILE* fp, char val, unsigned int step) {
542 unsigned int count = 0;
543 static char buf[BUFSZ];
544 long orig_pos = ftell(fp);
546 long buf_size = BUFSZ;
547 char* cur_found = NULL;
548 while(count < step) {
549 if(cur_found == NULL) {
550 buf_size = fread(buf, 1, buf_size, fp);
553 cur_found = memchr(buf+buf_pos, val, buf_size-buf_pos);
554 if(cur_found != NULL) {
555 buf_pos = cur_found-buf+1;
564 ret = ftell(fp) - buf_size + buf_pos - 1;
565 fseek(fp, orig_pos, SEEK_SET);
572 memrchr (const void *buffer, int c, size_t n)
574 const unsigned char *p = buffer;
576 for (p += n; n ; n--)
582 long rev_fcharfind(FILE* fp, char val, unsigned int step) {
585 unsigned int count = 0;
586 static char buf[BUFSZ];
587 long orig_pos = ftell(fp);
589 long file_pos = orig_pos;
590 long buf_size = BUFSZ;
592 while(count < step) {
594 if(file_pos > BUFSZ) {
595 fseek(fp, file_pos-BUFSZ, SEEK_SET);
599 fseek(fp, 0, SEEK_SET);
601 file_pos = ftell(fp);
602 buf_pos = fread(buf, 1, buf_size, fp);
609 if(cur_found != NULL) {
610 buf_pos = cur_found-buf;
619 fseek(fp, orig_pos, SEEK_SET);
621 ret = file_pos + buf_pos;
626 static void new_bar(char *buf, int w, int h, int usage)
628 struct special_t *s = new_special(buf, BAR);
629 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
634 static const char *scan_bar(const char *args, int *w, int *h)
636 *w = 0; /* zero width means all space that is available */
638 /* bar's argument is either height or height,width */
641 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
642 sscanf(args, "%d %n", h, &n);
649 static char *scan_font(const char *args)
658 static void new_font(char *buf, char * args) {
660 struct special_t *s = new_special(buf, FONT);
661 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
662 int tmp = selected_font;
663 selected_font = s->font_added = addfont(args);
668 struct special_t *s = new_special(buf, FONT);
669 int tmp = selected_font;
670 selected_font = s->font_added = 0;
677 inline void graph_append(struct special_t *graph, double f)
679 if (!graph->scaled && f > graph->graph_scale) {
680 f = graph->graph_scale;
684 graph->graph_scale = 1;
686 graph->graph[0] = f; /* add new data */
687 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
688 graph->graph[i] = graph->graph[i - 1];
689 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
690 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
695 short colour_depth = 0;
696 void set_up_gradient();
698 /* precalculated: 31/255, and 63/255 */
699 #define CONST_8_TO_5_BITS 0.12156862745098
700 #define CONST_8_TO_6_BITS 0.247058823529412
702 /* adjust color values depending on color depth*/
703 static unsigned int adjust_colors(unsigned int color)
706 if (colour_depth == 0) {
709 if (colour_depth == 16) {
710 r = (color & 0xff0000) >> 16;
711 g = (color & 0xff00) >> 8;
713 color = (int)(r * CONST_8_TO_5_BITS) << 11;
714 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
715 color |= (int)(b * CONST_8_TO_5_BITS);
720 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
722 struct special_t *s = new_special(buf, GRAPH);
724 if (s->graph == NULL) {
725 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
726 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
728 s->graph_width = MAX_GRAPH_DEPTH - 2;
730 s->graph = malloc(s->graph_width * sizeof(double));
731 memset(s->graph, 0, s->graph_width * sizeof(double));
732 s->graph_scale = 100;
735 s->first_colour = adjust_colors(first_colour);
736 s->last_colour = adjust_colors(second_colour);
743 s->graph_width = s->width - 2; // subtract 2 for rectangle around
748 s->graph_scale = scale;
755 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
757 *w = 0; /* zero width means all space that is available */
761 /* graph's argument is either height or height,width */
763 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
764 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
766 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
768 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
771 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
775 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
778 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
782 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
785 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
789 if (sscanf(args, "%d,%d", h, w) < 2) {
792 sscanf(args, "%*s %d,%d", h, w);
798 static inline void new_hr(char *buf, int a)
800 new_special(buf, HORIZONTAL_LINE)->height = a;
803 static inline void new_stippled_hr(char *buf, int a, int b)
805 struct special_t *s = new_special(buf, STIPPLED_HR);
810 static inline void new_fg(char *buf, long c)
812 new_special(buf, FG)->arg = c;
815 static inline void new_bg(char *buf, long c)
817 new_special(buf, BG)->arg = c;
820 static inline void new_outline(char *buf, long c)
822 new_special(buf, OUTLINE)->arg = c;
825 static inline void new_offset(char *buf, long c)
827 new_special(buf, OFFSET)->arg = c;
830 static inline void new_voffset(char *buf, long c)
832 new_special(buf, VOFFSET)->arg = c;
835 static inline void new_alignr(char *buf, long c)
837 new_special(buf, ALIGNR)->arg = c;
840 static inline void new_alignc(char *buf, long c)
842 new_special(buf, ALIGNC)->arg = c;
845 static inline void new_goto(char *buf, long c)
847 new_special(buf, GOTO)->arg = c;
850 static inline void new_tab(char *buf, int a, int b) {
851 struct special_t *s = new_special(buf, TAB);
856 /* quite boring functions */
858 static inline void for_each_line(char *b, void (*f) (char *))
862 for (ps = b, pe = b; *pe; pe++) {
875 static void convert_escapes(char *buf)
877 char *p = buf, *s = buf;
893 /* converts from bytes to human readable format (k, M, G, T) */
894 static void human_readable(long long a, char *buf, int size)
896 // Strange conditional due to possible overflows
897 if(a / 1024 / 1024 / 1024.0 > 1024.0){
898 snprintf(buf, size, "%.2fTiB", (a / 1024 / 1024 / 1024) / 1024.0);
900 else if (a >= 1024 * 1024 * 1024) {
901 snprintf(buf, size, "%.2fGiB", (a / 1024 / 1024) / 1024.0);
903 else if (a >= 1024 * 1024) {
904 double m = (a / 1024) / 1024.0;
906 snprintf(buf, size, "%.0fMiB", m);
908 snprintf(buf, size, "%.1fMiB", m);
909 } else if (a >= 1024)
910 snprintf(buf, size, "%LdKiB", a / (long long) 1024);
912 snprintf(buf, size, "%LdB", a);
917 enum text_object_type {
951 OBJ_diskiograph_read,
952 OBJ_diskiograph_write,
985 #if defined(__linux__)
991 OBJ_i8k_left_fan_status,
992 OBJ_i8k_right_fan_status,
993 OBJ_i8k_left_fan_rpm,
994 OBJ_i8k_right_fan_rpm,
996 OBJ_i8k_buttons_status,
1006 OBJ_wireless_bitrate,
1007 OBJ_wireless_link_qual,
1008 OBJ_wireless_link_qual_max,
1009 OBJ_wireless_link_bar,
1011 #endif /* __linux__ */
1040 OBJ_running_processes,
1049 OBJ_temp1, /* i2c is used instead in these */
1069 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1071 OBJ_apm_battery_time,
1072 OBJ_apm_battery_life,
1073 #endif /* __FreeBSD__ __OpenBSD__ */
1075 OBJ_obsd_sensors_temp,
1076 OBJ_obsd_sensors_fan,
1077 OBJ_obsd_sensors_volt,
1080 #endif /* __OpenBSD__ */
1109 OBJ_xmms2_transport,
1124 OBJ_audacious_status,
1125 OBJ_audacious_title,
1126 OBJ_audacious_length,
1127 OBJ_audacious_length_seconds,
1128 OBJ_audacious_position,
1129 OBJ_audacious_position_seconds,
1130 OBJ_audacious_bitrate,
1131 OBJ_audacious_frequency,
1132 OBJ_audacious_channels,
1133 OBJ_audacious_filename,
1134 OBJ_audacious_playlist_length,
1135 OBJ_audacious_playlist_position,
1149 #ifdef TCP_PORT_MONITOR
1160 OBJ_entropy_poolsize,
1164 struct text_object {
1168 unsigned int c, d, e;
1172 char *s; /* some string */
1173 int i; /* some integer */
1174 long l; /* some other integer */
1175 unsigned int sensor;
1176 struct net_stat *net;
1178 unsigned char loadavg[3];
1179 unsigned int cpu_index;
1180 struct mail_s *mail;
1188 char *tz; /* timezone variable */
1189 char *fmt; /* time display formatting */
1242 timed_thread *p_timed_thread;
1248 #ifdef TCP_PORT_MONITOR
1250 in_port_t port_range_begin; /* starting port to monitor */
1251 in_port_t port_range_end; /* ending port to monitor */
1252 int item; /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1253 int connection_index; /* 0 to n-1 connections. */
1274 struct text_object_list {
1275 unsigned int text_object_count;
1276 struct text_object *text_objects;
1279 static unsigned int text_object_count;
1280 static struct text_object *text_objects;
1281 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1283 #define MAXDATASIZE 1000
1287 struct mail_s* parse_mail_args(char type, const char *arg) {
1288 struct mail_s *mail;
1289 mail = malloc(sizeof(struct mail_s));
1290 memset(mail, 0, sizeof(struct mail_s));
1292 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1294 ERR("Scanning IMAP args failed");
1295 } else if (type == IMAP) {
1296 ERR("Scanning POP3 args failed");
1299 // see if password needs prompting
1300 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1301 int fp = fileno(stdin);
1302 struct termios term;
1303 tcgetattr(fp, &term);
1304 term.c_lflag &= ~ECHO;
1305 tcsetattr(fp, TCSANOW, &term);
1306 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1307 scanf("%128s", mail->pass);
1309 term.c_lflag |= ECHO;
1310 tcsetattr(fp, TCSANOW, &term);
1312 // now we check for optional args
1313 tmp = strstr(arg, "-i ");
1316 sscanf(tmp, "%f", &mail->interval);
1318 mail->interval = 300; // 5 minutes
1320 tmp = strstr(arg, "-p ");
1323 sscanf(tmp, "%lu", &mail->port);
1326 mail->port = 110; // default pop3 port
1327 } else if (type == IMAP) {
1328 mail->port = 143; // default imap port
1332 tmp = strstr(arg, "-f ");
1335 sscanf(tmp, "%s", mail->folder);
1337 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1340 tmp = strstr(arg, "-e ");
1344 if (tmp[0] == '\'') {
1345 len = strstr(tmp+1, "'") - tmp - 1;
1350 strncpy(mail->command, tmp+1, len);
1352 mail->command[0] = '\0';
1354 mail->p_timed_thread = NULL;
1358 void *imap_thread(struct mail_s* mail)
1360 int sockfd, numbytes;
1361 char recvbuf[MAXDATASIZE];
1362 char sendbuf[MAXDATASIZE];
1365 unsigned int old_unseen = UINT_MAX;
1366 unsigned int old_messages = UINT_MAX;
1367 struct stat stat_buf;
1369 struct sockaddr_in their_addr; // connector's address information
1370 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1371 herror("gethostbyname");
1376 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1378 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1381 goto next_iteration;
1384 their_addr.sin_family = AF_INET; // host byte order
1385 their_addr.sin_port = htons(mail->port); // short, network byte order
1386 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1387 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1390 (sockfd, (struct sockaddr *) &their_addr,
1391 sizeof(struct sockaddr)) == -1) {
1394 goto next_iteration;
1396 struct timeval timeout;
1399 timeout.tv_sec = 60; // 60 second timeout i guess
1400 timeout.tv_usec = 0;
1402 FD_SET(sockfd, &fdset);
1403 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1406 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1410 goto next_iteration;
1413 ERR("IMAP connection failed: timeout");
1415 goto next_iteration;
1417 recvbuf[numbytes] = '\0';
1418 if (strstr(recvbuf, "* OK") != recvbuf) {
1419 ERR("IMAP connection failed, probably not an IMAP server");
1421 goto next_iteration;
1423 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1424 strncat(sendbuf, mail->user,
1425 MAXDATASIZE - strlen(sendbuf) - 1);
1426 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1427 strncat(sendbuf, mail->pass,
1428 MAXDATASIZE - strlen(sendbuf) - 1);
1429 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1430 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1433 goto next_iteration;
1435 timeout.tv_sec = 60; // 60 second timeout i guess
1436 timeout.tv_usec = 0;
1438 FD_SET(sockfd, &fdset);
1439 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1442 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1446 goto next_iteration;
1449 recvbuf[numbytes] = '\0';
1450 if (strstr(recvbuf, "a1 OK") == NULL) {
1451 ERR("IMAP server login failed: %s", recvbuf);
1453 goto next_iteration;
1455 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1456 strncat(sendbuf, mail->folder,
1457 MAXDATASIZE - strlen(sendbuf) - 1);
1458 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1459 MAXDATASIZE - strlen(sendbuf) - 1);
1460 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1463 goto next_iteration;
1465 timeout.tv_sec = 60; // 60 second timeout i guess
1466 timeout.tv_usec = 0;
1468 FD_SET(sockfd, &fdset);
1469 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1472 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1476 goto next_iteration;
1479 recvbuf[numbytes] = '\0';
1480 if (strstr(recvbuf, "a2 OK") == NULL) {
1481 ERR("IMAP status failed: %s", recvbuf);
1483 goto next_iteration;
1485 // now we get the data
1486 reply = strstr(recvbuf, " (MESSAGES ");
1488 *strchr(reply, ')') = '\0';
1489 if (reply == NULL) {
1490 ERR("Error parsing IMAP response: %s", recvbuf);
1492 goto next_iteration;
1494 timed_thread_lock (mail->p_timed_thread);
1495 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1498 timed_thread_unlock (mail->p_timed_thread);
1500 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1501 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1504 goto next_iteration;
1506 timeout.tv_sec = 60; // 60 second timeout i guess
1507 timeout.tv_usec = 0;
1509 FD_SET(sockfd, &fdset);
1510 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1513 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1517 goto next_iteration;
1520 recvbuf[numbytes] = '\0';
1521 if (strstr(recvbuf, "a3 OK") == NULL) {
1522 ERR("IMAP logout failed: %s", recvbuf);
1524 goto next_iteration;
1526 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1527 if (system(mail->command) == -1) {
1532 old_unseen = mail->unseen;
1533 old_messages = mail->messages;
1535 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1536 /* if a valid socket, close it */
1538 if (timed_thread_test (mail->p_timed_thread))
1539 timed_thread_exit (mail->p_timed_thread);
1544 void *pop3_thread(struct mail_s *mail)
1546 int sockfd, numbytes;
1547 char recvbuf[MAXDATASIZE];
1548 char sendbuf[MAXDATASIZE];
1551 unsigned int old_unseen = UINT_MAX;
1552 struct stat stat_buf;
1554 struct sockaddr_in their_addr; // connector's address information
1555 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1556 herror("gethostbyname");
1561 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1563 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1566 goto next_iteration;
1569 their_addr.sin_family = AF_INET; // host byte order
1570 their_addr.sin_port = htons(mail->port); // short, network byte order
1571 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1572 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1575 (sockfd, (struct sockaddr *) &their_addr,
1576 sizeof(struct sockaddr)) == -1) {
1579 goto next_iteration;
1581 struct timeval timeout;
1584 timeout.tv_sec = 60; // 60 second timeout i guess
1585 timeout.tv_usec = 0;
1587 FD_SET(sockfd, &fdset);
1588 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1591 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1595 goto next_iteration;
1598 ERR("POP3 connection failed: timeout\n");
1600 goto next_iteration;
1602 recvbuf[numbytes] = '\0';
1603 if (strstr(recvbuf, "+OK ") != recvbuf) {
1604 ERR("POP3 connection failed, probably not a POP3 server");
1606 goto next_iteration;
1608 strncpy(sendbuf, "USER ", MAXDATASIZE);
1609 strncat(sendbuf, mail->user,
1610 MAXDATASIZE - strlen(sendbuf) - 1);
1611 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1612 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1613 perror("send USER");
1615 goto next_iteration;
1617 timeout.tv_sec = 60; // 60 second timeout i guess
1618 timeout.tv_usec = 0;
1620 FD_SET(sockfd, &fdset);
1621 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1624 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1626 perror("recv USER");
1628 goto next_iteration;
1631 recvbuf[numbytes] = '\0';
1632 if (strstr(recvbuf, "+OK ") == NULL) {
1633 ERR("POP3 server login failed: %s", recvbuf);
1635 goto next_iteration;
1637 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1638 strncat(sendbuf, mail->pass,
1639 MAXDATASIZE - strlen(sendbuf) - 1);
1640 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1641 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1642 perror("send PASS");
1644 goto next_iteration;
1646 timeout.tv_sec = 60; // 60 second timeout i guess
1647 timeout.tv_usec = 0;
1649 FD_SET(sockfd, &fdset);
1650 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1653 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1655 perror("recv PASS");
1657 goto next_iteration;
1660 recvbuf[numbytes] = '\0';
1661 if (strstr(recvbuf, "+OK ") == NULL) {
1662 ERR("POP3 server login failed: %s", recvbuf);
1664 goto next_iteration;
1666 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1667 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1668 perror("send STAT");
1670 goto next_iteration;
1672 timeout.tv_sec = 60; // 60 second timeout i guess
1673 timeout.tv_usec = 0;
1675 FD_SET(sockfd, &fdset);
1676 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1679 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1681 perror("recv STAT");
1683 goto next_iteration;
1686 recvbuf[numbytes] = '\0';
1687 if (strstr(recvbuf, "+OK ") == NULL) {
1688 ERR("POP3 status failed: %s", recvbuf);
1690 goto next_iteration;
1692 // now we get the data
1693 reply = recvbuf + 4;
1694 if (reply == NULL) {
1695 ERR("Error parsing POP3 response: %s", recvbuf);
1697 goto next_iteration;
1699 timed_thread_lock (mail->p_timed_thread);
1700 sscanf(reply, "%lu %lu", &mail->unseen,
1702 timed_thread_unlock (mail->p_timed_thread);
1704 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1705 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1706 perror("send QUIT");
1708 goto next_iteration;
1710 timeout.tv_sec = 60; // 60 second timeout i guess
1711 timeout.tv_usec = 0;
1713 FD_SET(sockfd, &fdset);
1714 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1717 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1719 perror("recv QUIT");
1721 goto next_iteration;
1724 recvbuf[numbytes] = '\0';
1725 if (strstr(recvbuf, "+OK") == NULL) {
1726 ERR("POP3 logout failed: %s", recvbuf);
1728 goto next_iteration;
1730 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1731 if (system(mail->command) == -1) {
1736 old_unseen = mail->unseen;
1738 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1739 /* if a valid socket, close it */
1741 if (timed_thread_test (mail->p_timed_thread))
1742 timed_thread_exit (mail->p_timed_thread);
1748 void *threaded_exec(struct text_object *obj) {
1750 char *p2 = obj->data.texeci.buffer;
1751 FILE *fp = popen(obj->data.texeci.cmd,"r");
1752 timed_thread_lock (obj->data.texeci.p_timed_thread);
1753 int n2 = fread(p2, 1, text_buffer_size, fp);
1756 if (n2 && p2[n2 - 1] == '\n') {
1760 if (*p2 == '\001') {
1765 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1766 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1767 timed_thread_exit (obj->data.texeci.p_timed_thread);
1772 static struct text_object *new_text_object_internal()
1774 struct text_object *obj = malloc(sizeof(struct text_object));
1775 memset(obj, 0, sizeof(struct text_object));
1779 static void free_text_objects(unsigned int count, struct text_object *objs)
1782 for (i = 0; i < count; i++) {
1783 switch (objs[i].type) {
1785 close(objs[i].data.i);
1788 close(objs[i].data.i);
1791 close(objs[i].data.i2c.fd);
1794 free(objs[i].data.s);
1797 free(objs[i].data.s);
1800 free(objs[i].data.tztime.tz);
1801 free(objs[i].data.tztime.fmt);
1804 free(objs[i].data.mboxscan.args);
1805 free(objs[i].data.mboxscan.output);
1810 case OBJ_imap_unseen:
1811 if (!objs[i].global_mode) {
1812 free(objs[i].data.mail);
1815 case OBJ_imap_messages:
1816 if (!objs[i].global_mode) {
1817 free(objs[i].data.mail);
1823 case OBJ_pop3_unseen:
1824 if (!objs[i].global_mode) {
1825 free(objs[i].data.mail);
1829 if (!objs[i].global_mode) {
1830 free(objs[i].data.mail);
1834 case OBJ_if_existing:
1835 case OBJ_if_mounted:
1836 case OBJ_if_running:
1837 free(objs[i].data.ifblock.s);
1838 free(objs[i].data.ifblock.str);
1841 free(objs[i].data.tail.logfile);
1842 free(objs[i].data.tail.buffer);
1846 free(objs[i].data.s);
1849 free(objs[i].data.s);
1852 free(objs[i].data.s);
1855 free(objs[i].data.s);
1858 free(objs[i].data.s);
1860 /* case OBJ_execibar:
1861 free(objs[i].data.s);
1863 case OBJ_execigraph:
1864 free(objs[i].data.s);
1867 case OBJ_iconv_start:
1873 if (info.mpd.title) {
1874 free(info.mpd.title);
1878 case OBJ_mpd_artist:
1879 if (info.mpd.artist) {
1880 free(info.mpd.artist);
1881 info.mpd.artist = 0;
1885 if (info.mpd.album) {
1886 free(info.mpd.album);
1890 case OBJ_mpd_random:
1891 if (info.mpd.random) {
1892 free(info.mpd.random);
1893 info.mpd.random = 0;
1896 case OBJ_mpd_repeat:
1897 if (info.mpd.repeat) {
1898 free(info.mpd.repeat);
1899 info.mpd.repeat = 0;
1903 if (info.mpd.track) {
1904 free(info.mpd.track);
1909 if (info.mpd.name) {
1910 free(info.mpd.name);
1915 if (info.mpd.file) {
1916 free(info.mpd.file);
1920 case OBJ_mpd_status:
1921 if (info.mpd.status) {
1922 free(info.mpd.status);
1923 info.mpd.status = 0;
1927 if (info.mpd.artist) {
1928 free(info.mpd.artist);
1929 info.mpd.artist = 0;
1931 if (info.mpd.title) {
1932 free(info.mpd.title);
1935 if (info.mpd.file) {
1936 free(info.mpd.file);
1943 case OBJ_xmms2_artist:
1944 if (info.xmms2.artist) {
1945 free(info.xmms2.artist);
1946 info.xmms2.artist = 0;
1949 case OBJ_xmms2_album:
1950 if (info.xmms2.album) {
1951 free(info.xmms2.album);
1952 info.xmms2.album = 0;
1955 case OBJ_xmms2_title:
1956 if (info.xmms2.title) {
1957 free(info.xmms2.title);
1958 info.xmms2.title = 0;
1961 case OBJ_xmms2_genre:
1962 if (info.xmms2.genre) {
1963 free(info.xmms2.genre);
1964 info.xmms2.genre = 0;
1967 case OBJ_xmms2_comment:
1968 if (info.xmms2.comment) {
1969 free(info.xmms2.comment);
1970 info.xmms2.comment = 0;
1973 case OBJ_xmms2_decoder:
1974 if (info.xmms2.decoder) {
1975 free(info.xmms2.decoder);
1979 case OBJ_xmms2_transport:
1980 if (info.xmms2.transport) {
1981 free(info.xmms2.transport);
1986 if (info.xmms2.url) {
1987 free(info.xmms2.url);
1991 case OBJ_xmms2_date:
1992 if (info.xmms2.date) {
1993 free(info.xmms2.date);
1994 info.xmms2.date = 0;
1997 case OBJ_xmms2_status:
1998 if (info.xmms2.status) {
1999 free(info.xmms2.status);
2000 info.xmms2.status = 0;
2003 case OBJ_xmms2_smart:
2004 if (info.xmms2.artist) {
2005 free(info.xmms2.artist);
2006 info.xmms2.artist = 0;
2008 if (info.xmms2.title) {
2009 free(info.xmms2.title);
2010 info.xmms2.title = 0;
2012 if (info.xmms2.url) {
2013 free(info.xmms2.url);
2019 case OBJ_bmpx_title:
2020 case OBJ_bmpx_artist:
2021 case OBJ_bmpx_album:
2022 case OBJ_bmpx_track:
2024 case OBJ_bmpx_bitrate:
2028 free(objs[i].data.rss.uri);
2029 free(objs[i].data.rss.action);
2034 free(objs[i].data.s);
2036 case OBJ_battery_time:
2037 free(objs[i].data.s);
2040 free(objs[i].data.execi.cmd);
2041 free(objs[i].data.execi.buffer);
2044 free(objs[i].data.texeci.cmd);
2045 free(objs[i].data.texeci.buffer);
2048 if (info.first_process) {
2049 free_all_processes();
2050 info.first_process = NULL;
2054 if (info.first_process) {
2055 free_all_processes();
2056 info.first_process = NULL;
2061 free(objs[i].data.hddtemp.dev);
2062 free(objs[i].data.hddtemp.addr);
2065 case OBJ_entropy_avail:
2066 case OBJ_entropy_poolsize:
2067 case OBJ_entropy_bar:
2072 //text_objects = NULL;
2073 //text_object_count = 0;
2076 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2081 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2082 *a = mixer_init(buf1);
2083 (void) scan_bar(arg + n, w, h);
2086 (void) scan_bar(arg, w, h);
2091 /* construct_text_object() creates a new text_object */
2092 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2094 //struct text_object *obj = new_text_object();
2095 struct text_object *obj = new_text_object_internal();
2098 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2099 #define END ; } } else
2103 obj->type = OBJ_color;
2104 obj->data.l = get_x11_color(s);
2107 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2108 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2109 END OBJ(acpiacadapter, 0)
2110 END OBJ(freq, INFO_FREQ)
2116 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2118 obj->data.cpu_index=1;
2119 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2123 obj->data.cpu_index=atoi(&arg[0]);
2126 END OBJ(freq_g, INFO_FREQ)
2132 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2134 obj->data.cpu_index=1;
2135 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2139 obj->data.cpu_index=atoi(&arg[0]);
2142 #if defined(__linux__)
2143 END OBJ(voltage_mv, 0)
2149 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2151 obj->data.cpu_index=1;
2152 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2156 obj->data.cpu_index=atoi(&arg[0]);
2159 END OBJ(voltage_v, 0)
2165 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2167 obj->data.cpu_index=1;
2168 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2172 obj->data.cpu_index=atoi(&arg[0]);
2177 END OBJ(wireless_essid, INFO_NET)
2179 obj->data.net = get_net_stat(arg);
2181 CRIT_ERR("wireless_essid: needs an argument");
2182 END OBJ(wireless_mode, INFO_NET)
2184 obj->data.net = get_net_stat(arg);
2186 CRIT_ERR("wireless_mode: needs an argument");
2187 END OBJ(wireless_ap, INFO_NET)
2189 obj->data.net = get_net_stat(arg);
2191 CRIT_ERR("wireless_ap: needs an argument");
2192 END OBJ(wireless_bitrate, INFO_NET)
2194 obj->data.net = get_net_stat(arg);
2196 CRIT_ERR("wireless_bitrate: needs an argument");
2197 END OBJ(wireless_link_qual, INFO_NET)
2199 obj->data.net = get_net_stat(arg);
2201 CRIT_ERR("wireless_link_qual: needs an argument");
2202 END OBJ(wireless_link_qual_max, INFO_NET)
2204 obj->data.net = get_net_stat(arg);
2206 CRIT_ERR("wireless_link_qual_max: needs an argument");
2207 END OBJ(wireless_link_bar, INFO_NET)
2209 arg = scan_bar(arg, &obj->a, &obj->b);
2210 obj->data.net = get_net_stat(arg);
2212 CRIT_ERR("wireless_link_bar: needs an argument");
2213 #endif /* HAVE_IWLIB */
2215 #endif /* __linux__ */
2216 END OBJ(freq_dyn, 0);
2217 END OBJ(freq_dyn_g, 0);
2218 END OBJ(acpifan, 0);
2219 END OBJ(battery, 0);
2222 sscanf(arg, "%63s", bat);
2224 strcpy(bat, "BAT0");
2225 obj->data.s = strdup(bat);
2226 END OBJ(battery_time, 0);
2229 sscanf(arg, "%63s", bat);
2231 strcpy(bat, "BAT0");
2232 obj->data.s = strdup(bat);
2233 END OBJ(battery_percent, 0);
2236 sscanf(arg, "%63s", bat);
2238 strcpy(bat, "BAT0");
2239 obj->data.s = strdup(bat);
2240 END OBJ(battery_bar, 0);
2243 arg = scan_bar(arg, &obj->a, &obj->b);
2244 sscanf(arg, "%63s", bat);
2246 strcpy(bat, "BAT0");
2248 obj->data.s = strdup(bat);
2249 #if defined(__linux__)
2250 END OBJ(i8k_version, INFO_I8K)
2251 END OBJ(i8k_bios, INFO_I8K)
2252 END OBJ(i8k_serial, INFO_I8K)
2253 END OBJ(i8k_cpu_temp, INFO_I8K)
2254 END OBJ(i8k_cpu_tempf, INFO_I8K)
2255 END OBJ(i8k_left_fan_status, INFO_I8K)
2256 END OBJ(i8k_right_fan_status, INFO_I8K)
2257 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2258 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2259 END OBJ(i8k_ac_status, INFO_I8K)
2260 END OBJ(i8k_buttons_status, INFO_I8K)
2262 END OBJ(ibm_temps, 0)
2264 CRIT_ERR("ibm_temps: needs an argument");
2266 if (!isdigit(arg[0])
2268 || atoi(&arg[0]) >=8)
2271 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2273 obj->data.sensor = atoi(&arg[0]);
2274 END OBJ(ibm_volume, 0)
2275 END OBJ(ibm_brightness, 0)
2276 END OBJ(pb_battery, 0)
2277 if (arg && strcmp(arg, "status") == 0) {
2278 obj->data.i = PB_BATT_STATUS;
2279 } else if (arg && strcmp(arg, "percent") == 0) {
2280 obj->data.i = PB_BATT_PERCENT;
2281 } else if (arg && strcmp(arg, "time") == 0) {
2282 obj->data.i = PB_BATT_TIME;
2284 ERR("pb_battery: needs one argument: status, percent or time");
2289 #endif /* __linux__ */
2290 #if defined(__OpenBSD__)
2291 END OBJ(obsd_sensors_temp, 0);
2293 CRIT_ERR("obsd_sensors_temp: needs an argument");
2295 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2297 ERR("Invalid temperature sensor number!");
2299 obj->data.sensor = atoi(&arg[0]);
2300 END OBJ(obsd_sensors_fan, 0);
2302 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor number)");
2304 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2306 ERR("Invalid fan sensor number!");
2308 obj->data.sensor = atoi(&arg[0]);
2309 END OBJ(obsd_sensors_volt, 0);
2311 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor number)");
2313 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2315 ERR("Invalid voltage sensor number!");
2317 obj->data.sensor = atoi(&arg[0]);
2318 END OBJ(obsd_vendor, 0);
2319 END OBJ(obsd_product, 0);
2320 #endif /* __OpenBSD__ */
2321 END OBJ(buffers, INFO_BUFFERS)
2322 END OBJ(cached, INFO_BUFFERS)
2323 END OBJ(cpu, INFO_CPU)
2325 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2326 obj->data.cpu_index = atoi(&arg[3]);
2328 } else {obj->data.cpu_index = 0; }
2330 obj->data.cpu_index = 0;
2332 END OBJ(cpubar, INFO_CPU)
2334 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2335 obj->data.cpu_index = atoi(&arg[3]);
2338 else {obj->data.cpu_index = 0;}
2339 (void) scan_bar(arg, &obj->a, &obj->b);
2341 (void) scan_bar(arg, &obj->a, &obj->b);
2342 obj->data.cpu_index = 0;
2344 END OBJ(cpugraph, INFO_CPU)
2346 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2347 obj->data.cpu_index = atoi(&arg[3]);
2350 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2352 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2353 obj->data.cpu_index = 0;
2355 END OBJ(diskio, INFO_DISKIO)
2356 END OBJ(diskio_read, INFO_DISKIO)
2357 END OBJ(diskio_write, INFO_DISKIO)
2358 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2359 END OBJ(diskiograph_read, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2360 END OBJ(diskiograph_write, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2363 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2366 obj->data.l = color0;
2368 obj->data.l = color1;
2370 obj->data.l = color2;
2372 obj->data.l = color3;
2374 obj->data.l = color4;
2376 obj->data.l = color5;
2378 obj->data.l = color6;
2380 obj->data.l = color7;
2382 obj->data.l = color8;
2384 obj->data.l = color9;
2386 obj->data.s = scan_font(arg);
2387 END OBJ(downspeed, INFO_NET)
2389 obj->data.net = get_net_stat(arg);
2392 CRIT_ERR("downspeed needs argument");
2394 END OBJ(downspeedf, INFO_NET)
2396 obj->data.net = get_net_stat(arg);
2399 CRIT_ERR("downspeedf needs argument");
2401 END OBJ(downspeedgraph, INFO_NET)
2402 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2404 sscanf(arg, "%63s %*i,%*i %*i", buf);
2405 obj->data.net = get_net_stat(buf);
2406 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2407 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
2414 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2415 blockstart[blockdepth - 1] = object_count;
2416 obj->data.ifblock.pos = object_count + 2;
2418 ERR("$else: no matching $if_*");
2423 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2425 ERR("$endif: no matching $if_*");
2428 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2431 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2432 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2433 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2434 END OBJ(execibar, 0) unsigned int n;
2435 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2437 ERR("${execibar <interval> command}");
2438 obj->type = OBJ_text;
2439 snprintf(buf, 256, "${%s}", s);
2440 obj->data.s = strdup(buf);
2442 obj->data.execi.cmd = strdup(arg + n);
2444 END OBJ(execigraph, 0) unsigned int n;
2445 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2447 ERR("${execigraph <interval> command}");
2448 obj->type = OBJ_text;
2449 snprintf(buf, 256, "${%s}", s);
2450 obj->data.s = strdup(buf);
2452 obj->data.execi.cmd = strdup(arg + n);
2454 END OBJ(execi, 0) unsigned int n;
2455 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2457 ERR("${execi <interval> command}");
2458 obj->type = OBJ_text;
2459 snprintf(buf, 256, "${%s}", s);
2460 obj->data.s = strdup(buf);
2462 obj->data.execi.cmd = strdup(arg + n);
2463 obj->data.execi.buffer =
2464 (char *) calloc(1, text_buffer_size);
2466 END OBJ(texeci, 0) unsigned int n;
2467 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2469 ERR("${texeci <interval> command}");
2470 obj->type = OBJ_text;
2471 snprintf(buf, 256, "${%s}", s);
2472 obj->data.s = strdup(buf);
2474 obj->data.texeci.cmd = strdup(arg + n);
2475 obj->data.texeci.buffer =
2476 (char *) calloc(1, text_buffer_size);
2478 obj->data.texeci.p_timed_thread = NULL;
2479 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2481 FILE *fp = popen(arg, "r");
2485 n = fread(buf, 1, 2048, fp);
2488 if (n && buf[n - 1] == '\n')
2493 obj->data.s = strdup(buf);
2495 obj->data.s = strdup("");
2498 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2499 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2501 while (isspace(*arg))
2507 obj->data.fsbar.fs = prepare_fs_stat(arg);
2508 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2511 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2515 obj->data.fsbar.fs = prepare_fs_stat(arg);
2516 END OBJ(fs_free, INFO_FS) if (!arg)
2518 obj->data.fs = prepare_fs_stat(arg);
2519 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2521 obj->data.fs = prepare_fs_stat(arg);
2522 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2524 obj->data.fs = prepare_fs_stat(arg);
2525 END OBJ(fs_size, INFO_FS) if (!arg)
2527 obj->data.fs = prepare_fs_stat(arg);
2528 END OBJ(fs_used, INFO_FS) if (!arg)
2530 obj->data.fs = prepare_fs_stat(arg);
2531 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2532 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2533 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2537 ERR("goto needs arguments");
2538 obj->type = OBJ_text;
2539 obj->data.s = strdup("${goto}");
2543 obj->data.i = atoi(arg);
2548 if (sscanf(arg, "%d %d", &a, &b) != 2)
2549 sscanf(arg, "%d", &b);
2553 obj->data.pair.a = a;
2554 obj->data.pair.b = b;
2556 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
2560 ERR("i2c needs arguments");
2561 obj->type = OBJ_text;
2562 //obj->data.s = strdup("${i2c}");
2566 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2567 /* if scanf couldn't read three values, read type and num and use
2569 sscanf(arg, "%63s %d", buf2, &n);
2571 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
2572 obj->data.i2c.devtype);
2573 strncpy(obj->data.i2c.type, buf2, 63);
2576 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
2577 obj->data.i2c.devtype);
2578 strncpy(obj->data.i2c.type, buf2, 63);
2581 END OBJ(top, INFO_TOP)
2585 ERR("top needs arguments");
2586 obj->type = OBJ_text;
2587 //obj->data.s = strdup("${top}");
2590 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2591 if (strcmp(buf, "name") == 0) {
2592 obj->data.top.type = TOP_NAME;
2593 } else if (strcmp(buf, "cpu") == 0) {
2594 obj->data.top.type = TOP_CPU;
2595 } else if (strcmp(buf, "pid") == 0) {
2596 obj->data.top.type = TOP_PID;
2597 } else if (strcmp(buf, "mem") == 0) {
2598 obj->data.top.type = TOP_MEM;
2600 ERR("invalid arg for top");
2603 if (n < 1 || n > 10) {
2604 CRIT_ERR("invalid arg for top");
2607 obj->data.top.num = n - 1;
2611 ERR("invalid args given for top");
2614 END OBJ(top_mem, INFO_TOP)
2618 ERR("top_mem needs arguments");
2619 obj->type = OBJ_text;
2620 obj->data.s = strdup("${top_mem}");
2623 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2624 if (strcmp(buf, "name") == 0) {
2625 obj->data.top.type = TOP_NAME;
2626 } else if (strcmp(buf, "cpu") == 0) {
2627 obj->data.top.type = TOP_CPU;
2628 } else if (strcmp(buf, "pid") == 0) {
2629 obj->data.top.type = TOP_PID;
2630 } else if (strcmp(buf, "mem") == 0) {
2631 obj->data.top.type = TOP_MEM;
2633 ERR("invalid arg for top");
2636 if (n < 1 || n > 10) {
2637 CRIT_ERR("invalid arg for top");
2640 obj->data.top.num = n - 1;
2644 ERR("invalid args given for top");
2647 END OBJ(addr, INFO_NET)
2649 obj->data.net = get_net_stat(arg);
2652 CRIT_ERR("addr needs argument");
2655 END OBJ(linkstatus, INFO_WIFI)
2657 obj->data.net = get_net_stat(arg);
2660 CRIT_ERR("linkstatus needs argument");
2667 ERR("tail needs arguments");
2668 obj->type = OBJ_text;
2669 obj->data.s = strdup("${tail}");
2672 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2673 if (n1 < 1 || n1 > 30) {
2674 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2678 fp = fopen(buf, "r");
2680 obj->data.tail.logfile =
2681 malloc(text_buffer_size);
2682 strcpy(obj->data.tail.logfile, buf);
2683 obj->data.tail.wantedlines = n1;
2684 obj->data.tail.interval =
2685 update_interval * 2;
2689 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2692 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2693 if (n1 < 1 || n1 > 30) {
2695 ("invalid arg for tail, number of lines must be between 1 and 30");
2697 } else if (n2 < 1 || n2 < update_interval) {
2699 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2703 fp = fopen(buf, "r");
2705 obj->data.tail.logfile =
2706 malloc(text_buffer_size);
2707 strcpy(obj->data.tail.logfile, buf);
2708 obj->data.tail.wantedlines = n1;
2709 obj->data.tail.interval = n2;
2713 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2719 ERR("invalid args given for tail");
2722 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2727 ERR("head needs arguments");
2728 obj->type = OBJ_text;
2729 obj->data.s = strdup("${head}");
2732 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2733 if (n1 < 1 || n1 > 30) {
2734 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2738 fp = fopen(buf, "r");
2740 obj->data.tail.logfile =
2741 malloc(text_buffer_size);
2742 strcpy(obj->data.tail.logfile, buf);
2743 obj->data.tail.wantedlines = n1;
2744 obj->data.tail.interval =
2745 update_interval * 2;
2749 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2752 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2753 if (n1 < 1 || n1 > 30) {
2755 ("invalid arg for head, number of lines must be between 1 and 30");
2757 } else if (n2 < 1 || n2 < update_interval) {
2759 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2763 fp = fopen(buf, "r");
2765 obj->data.tail.logfile =
2766 malloc(text_buffer_size);
2767 strcpy(obj->data.tail.logfile, buf);
2768 obj->data.tail.wantedlines = n1;
2769 obj->data.tail.interval = n2;
2773 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2779 ERR("invalid args given for head");
2782 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2783 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2785 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2786 if (r >= 3 && (c < 1 || c > 3))
2788 if (r >= 2 && (b < 1 || b > 3))
2790 if (r >= 1 && (a < 1 || a > 3))
2793 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2794 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2795 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2796 END OBJ(if_empty, 0)
2797 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2798 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2801 ERR("if_empty needs an argument");
2802 obj->data.ifblock.s = 0;
2804 obj->data.ifblock.s = strdup(arg);
2805 blockstart[blockdepth] = object_count;
2806 obj->data.ifblock.pos = object_count + 2;
2808 END OBJ(if_existing, 0)
2809 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2810 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2813 ERR("if_existing needs an argument or two");
2814 obj->data.ifblock.s = NULL;
2815 obj->data.ifblock.str = NULL;
2817 char buf1[256], buf2[256];
2818 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2820 obj->data.ifblock.s = strdup(buf1);
2821 obj->data.ifblock.str = NULL;
2823 obj->data.ifblock.s = strdup(buf1);
2824 obj->data.ifblock.str = strdup(buf2);
2827 blockstart[blockdepth] = object_count;
2828 obj->data.ifblock.pos = object_count + 2;
2830 END OBJ(if_mounted, 0)
2831 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2832 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2835 ERR("if_mounted needs an argument");
2836 obj->data.ifblock.s = 0;
2838 obj->data.ifblock.s = strdup(arg);
2839 blockstart[blockdepth] = object_count;
2840 obj->data.ifblock.pos = object_count + 2;
2842 END OBJ(if_running, 0)
2843 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2844 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2848 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2849 obj->data.ifblock.s = strdup(buf);
2851 ERR("if_running needs an argument");
2852 obj->data.ifblock.s = 0;
2854 blockstart[blockdepth] = object_count;
2855 obj->data.ifblock.pos = object_count + 2;
2859 END OBJ(mails, INFO_MAIL)
2860 END OBJ(mboxscan, 0)
2861 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
2862 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
2863 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2864 obj->data.mboxscan.output[0] = 1;
2865 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
2866 END OBJ(mem, INFO_MEM)
2867 END OBJ(memmax, INFO_MEM)
2868 END OBJ(memperc, INFO_MEM)
2869 END OBJ(membar, INFO_MEM)
2870 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2871 END OBJ(memgraph, INFO_MEM)
2872 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2873 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2874 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2875 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2876 END OBJ(mixerbar, INFO_MIXER)
2877 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2878 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2879 END OBJ(mixerlbar, INFO_MIXER)
2880 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2881 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2882 END OBJ(mixerrbar, INFO_MIXER)
2883 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2884 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2886 OBJ(new_mails, INFO_MAIL)
2887 END OBJ(nodename, 0)
2888 END OBJ(processes, INFO_PROCS)
2889 END OBJ(running_processes, INFO_RUN_PROCS)
2890 END OBJ(shadecolor, 0)
2892 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2894 END OBJ(outlinecolor, 0)
2896 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2898 END OBJ(stippled_hr, 0)
2900 int a = stippled_borders, b = 1;
2902 if (sscanf(arg, "%d %d", &a, &b) != 2)
2903 sscanf(arg, "%d", &b);
2907 obj->data.pair.a = a;
2908 obj->data.pair.b = b;
2910 END OBJ(swap, INFO_MEM)
2911 END OBJ(swapmax, INFO_MEM)
2912 END OBJ(swapperc, INFO_MEM)
2913 END OBJ(swapbar, INFO_MEM)
2914 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2915 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
2917 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
2918 obj->data.i2c.devtype);
2919 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
2921 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
2922 obj->data.i2c.devtype);
2923 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2924 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2926 char buf1[256], buf2[256], *fmt, *tz;
2929 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2938 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
2939 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
2941 END OBJ(iconv_start, 0)
2942 if (iconv_converting) {
2943 CRIT_ERR("You must stop your last iconv conversion before starting another");
2946 char iconv_from[CODEPAGE_LENGTH];
2947 char iconv_to[CODEPAGE_LENGTH];
2948 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2949 CRIT_ERR("Invalid arguments for iconv_start");
2952 new_iconv = iconv_open(iconv_to, iconv_from);
2953 if (new_iconv == (iconv_t)(-1)) {
2954 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2956 obj->a = register_iconv(&new_iconv);
2957 iconv_converting = 1;
2961 CRIT_ERR("Iconv requires arguments");
2963 END OBJ(iconv_stop, 0)
2964 iconv_converting = 0;
2967 END OBJ(totaldown, INFO_NET)
2969 obj->data.net = get_net_stat(arg);
2972 CRIT_ERR("totaldown needs argument");
2974 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
2976 obj->data.net = get_net_stat(arg);
2979 CRIT_ERR("totalup needs argument");
2982 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
2983 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
2984 END OBJ(upspeed, INFO_NET)
2986 obj->data.net = get_net_stat(arg);
2989 CRIT_ERR("upspeed needs argument");
2991 END OBJ(upspeedf, INFO_NET)
2993 obj->data.net = get_net_stat(arg);
2996 CRIT_ERR("upspeedf needs argument");
2999 END OBJ(upspeedgraph, INFO_NET)
3000 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
3002 sscanf(arg, "%63s %*i,%*i %*i", buf);
3003 obj->data.net = get_net_stat(buf);
3004 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
3005 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
3010 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
3011 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
3012 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3013 OBJ(apm_adapter, 0) END
3014 OBJ(apm_battery_life, 0) END
3015 OBJ(apm_battery_time, 0) END
3016 #endif /* __FreeBSD__ */
3020 obj->data.mail = parse_mail_args(IMAP, arg);
3021 obj->global_mode = 0;
3023 obj->global_mode = 1;
3026 OBJ(imap_messages, 0)
3029 obj->data.mail = parse_mail_args(IMAP, arg);
3030 obj->global_mode = 0;
3032 obj->global_mode = 1;
3038 obj->data.mail = parse_mail_args(POP3, arg);
3039 obj->global_mode = 0;
3041 obj->global_mode = 1;
3047 obj->data.mail = parse_mail_args(POP3, arg);
3048 obj->global_mode = 0;
3050 obj->global_mode = 1;
3054 OBJ(mpd_artist, INFO_MPD) END
3055 OBJ(mpd_title, INFO_MPD)
3059 sscanf (arg, "%d", &info.mpd.max_title_len);
3060 if (info.mpd.max_title_len > 0)
3061 info.mpd.max_title_len++;
3063 CRIT_ERR ("mpd_title: invalid length argument");
3066 END OBJ(mpd_random, INFO_MPD)
3067 END OBJ(mpd_repeat, INFO_MPD)
3068 END OBJ(mpd_elapsed, INFO_MPD)
3069 END OBJ(mpd_length, INFO_MPD)
3070 END OBJ(mpd_track, INFO_MPD)
3071 END OBJ(mpd_name, INFO_MPD)
3072 END OBJ(mpd_file, INFO_MPD)
3073 END OBJ(mpd_percent, INFO_MPD)
3074 END OBJ(mpd_album, INFO_MPD)
3075 END OBJ(mpd_vol, INFO_MPD)
3076 END OBJ(mpd_bitrate, INFO_MPD)
3077 END OBJ(mpd_status, INFO_MPD)
3078 END OBJ(mpd_bar, INFO_MPD)
3079 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3080 END OBJ(mpd_smart, INFO_MPD) END
3083 OBJ(xmms2_artist, INFO_XMMS2)
3084 END OBJ(xmms2_album, INFO_XMMS2)
3085 END OBJ(xmms2_title, INFO_XMMS2)
3086 END OBJ(xmms2_genre, INFO_XMMS2)
3087 END OBJ(xmms2_comment, INFO_XMMS2)
3088 END OBJ(xmms2_decoder, INFO_XMMS2)
3089 END OBJ(xmms2_transport, INFO_XMMS2)
3090 END OBJ(xmms2_url, INFO_XMMS2)
3091 END OBJ(xmms2_tracknr, INFO_XMMS2)
3092 END OBJ(xmms2_bitrate, INFO_XMMS2)
3093 END OBJ(xmms2_date, INFO_XMMS2)
3094 END OBJ(xmms2_id, INFO_XMMS2)
3095 END OBJ(xmms2_duration, INFO_XMMS2)
3096 END OBJ(xmms2_elapsed, INFO_XMMS2)
3097 END OBJ(xmms2_size, INFO_XMMS2)
3098 END OBJ(xmms2_status, INFO_XMMS2)
3099 END OBJ(xmms2_percent, INFO_XMMS2)
3100 END OBJ(xmms2_bar, INFO_XMMS2)
3101 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3102 END OBJ(xmms2_smart, INFO_XMMS2)
3106 OBJ(audacious_status, INFO_AUDACIOUS) END
3107 OBJ(audacious_title, INFO_AUDACIOUS)
3111 sscanf (arg, "%d", &info.audacious.max_title_len);
3112 if (info.audacious.max_title_len > 0)
3113 info.audacious.max_title_len++;
3115 CRIT_ERR ("audacious_title: invalid length argument");
3119 OBJ(audacious_length, INFO_AUDACIOUS) END
3120 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3121 OBJ(audacious_position, INFO_AUDACIOUS) END
3122 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3123 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3124 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3125 OBJ(audacious_channels, INFO_AUDACIOUS) END
3126 OBJ(audacious_filename, INFO_AUDACIOUS) END
3127 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3128 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3129 OBJ(audacious_bar, INFO_AUDACIOUS)
3130 (void) scan_bar(arg, &obj->a, &obj->b);
3134 OBJ(bmpx_title, INFO_BMPX)
3135 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3137 OBJ(bmpx_artist, INFO_BMPX)
3138 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3140 OBJ(bmpx_album, INFO_BMPX)
3141 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3143 OBJ(bmpx_track, INFO_BMPX)
3144 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3146 OBJ(bmpx_uri, INFO_BMPX)
3147 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3149 OBJ(bmpx_bitrate, INFO_BMPX)
3150 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3156 int argc, delay, act_par;
3157 char *uri = (char *)malloc(128 * sizeof(char));
3158 char *action = (char *)malloc(64 * sizeof(char));
3160 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par);
3161 obj->data.rss.uri = uri;
3162 obj->data.rss.delay = delay;
3163 obj->data.rss.action = action;
3164 obj->data.rss.act_par = act_par;
3168 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
3174 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3175 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3176 ERR("hddtemp needs arguments");
3177 obj->type = OBJ_text;
3178 obj->data.s = strdup("${hddtemp}");
3183 #ifdef TCP_PORT_MONITOR
3184 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3185 int argc, port_begin, port_end, item, connection_index;
3187 memset(itembuf,0,sizeof(itembuf));
3189 /* massive argument checking */
3191 CRIT_ERR("tcp_portmon: needs arguments");
3193 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3194 if ( (argc != 3) && (argc != 4) )
3196 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3198 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3200 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3202 if ( port_begin > port_end )
3204 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3206 if ( strncmp(itembuf,"count",31) == 0 )
3208 else if ( strncmp(itembuf,"rip",31) == 0 )
3210 else if ( strncmp(itembuf,"rhost",31) == 0 )
3212 else if ( strncmp(itembuf,"rport",31) == 0 )
3214 else if ( strncmp(itembuf,"rservice",31) == 0 )
3216 else if ( strncmp(itembuf,"lip",31) == 0 )
3218 else if ( strncmp(itembuf,"lhost",31) == 0 )
3220 else if ( strncmp(itembuf,"lport",31) == 0 )
3222 else if ( strncmp(itembuf,"lservice",31) == 0 )
3226 CRIT_ERR("tcp_portmon: invalid item specified");
3228 if ( (argc==3) && (item!=COUNT) )
3230 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3232 if ( (argc==4) && (connection_index<0) )
3234 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3236 /* ok, args looks good. save the text object data */
3237 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3238 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3239 obj->data.tcp_port_monitor.item = item;
3240 obj->data.tcp_port_monitor.connection_index = connection_index;
3242 /* if the port monitor collection hasn't been created, we must create it */
3243 if ( !info.p_tcp_port_monitor_collection )
3245 info.p_tcp_port_monitor_collection =
3246 create_tcp_port_monitor_collection ();
3247 if ( !info.p_tcp_port_monitor_collection )
3249 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3253 /* if a port monitor for this port does not exist, create one and add it to the collection */
3254 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3256 tcp_port_monitor_t * p_monitor =
3257 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3260 CRIT_ERR("tcp_portmon: unable to create port monitor");
3262 /* add the newly created monitor to the collection */
3263 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3266 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3271 OBJ(entropy_avail, INFO_ENTROPY) END
3272 OBJ(entropy_poolsize, INFO_ENTROPY) END
3273 OBJ(entropy_bar, INFO_ENTROPY)
3274 (void) scan_bar(arg, &obj->a, &obj->b);
3279 ERR("unknown variable %s", s);
3280 obj->type = OBJ_text;
3281 snprintf(buf, 256, "${%s}", s);
3282 obj->data.s = strdup(buf);
3289 static struct text_object *create_plain_text(const char *s)
3291 struct text_object *obj;
3293 if (s == NULL || *s == '\0') {
3297 obj = new_text_object_internal();
3299 obj->type = OBJ_text;
3300 obj->data.s = strdup(s);
3304 static struct text_object_list *extract_variable_text_internal(const char *p)
3306 struct text_object_list *retval;
3307 struct text_object *obj;
3310 retval = malloc(sizeof(struct text_object_list));
3311 memset(retval, 0, sizeof(struct text_object_list));
3312 retval->text_object_count = 0;
3314 long line = text_lines;
3322 obj = create_plain_text(s);
3324 // allocate memory for the object
3325 retval->text_objects = realloc(retval->text_objects,
3326 sizeof(struct text_object) * (retval->text_object_count+1));
3327 // assign the new object to the end of the list.
3328 memcpy(&retval->text_objects[retval->text_object_count++],
3329 obj, sizeof(struct text_object));
3341 /* variable is either $foo or ${foo} */
3343 unsigned int brl = 1, brr = 0;
3346 while (*p && brl != brr) {
3347 if (*p == '{') brl++;
3348 if (*p == '}') brr++;
3356 while (*p && (isalnum((int) *p)
3361 /* copy variable to buffer */
3362 len = (p - s > 255) ? 255 : (p - s);
3363 strncpy(buf, s, len);
3372 /* if variable wasn't found from environment, use some special */
3378 if (strchr(buf, ' ')) {
3379 arg = strchr(buf, ' ');
3382 while (isspace((int) *arg))
3388 /* lowercase variable name */
3395 // create new object
3396 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3398 // allocate memory for the object
3399 retval->text_objects = realloc(retval->text_objects,
3400 sizeof(struct text_object) * (retval->text_object_count+1));
3401 // assign the new object to the end of the list.
3402 memcpy(&retval->text_objects[retval->text_object_count++],
3403 obj, sizeof(struct text_object));
3409 obj = create_plain_text("$");
3411 // allocate memory for the object
3412 retval->text_objects = realloc(retval->text_objects,
3413 sizeof(struct text_object) * (retval->text_object_count+1));
3414 // assign the new object to the end of the list.
3415 memcpy(&retval->text_objects[retval->text_object_count++],
3416 obj, sizeof(struct text_object));
3423 obj = create_plain_text(s);
3425 // allocate memory for the object
3426 retval->text_objects = realloc(retval->text_objects,
3427 sizeof(struct text_object) * (retval->text_object_count+1));
3428 // assign the new object to the end of the list.
3429 memcpy(&retval->text_objects[retval->text_object_count++],
3430 obj, sizeof(struct text_object));
3435 ERR("one or more $endif's are missing");
3441 static void extract_variable_text(const char *p)
3443 struct text_object_list *list;
3445 free_text_objects(text_object_count, text_objects);
3446 text_object_count = 0;
3447 text_objects = NULL;
3450 list = extract_variable_text_internal(p);
3451 text_objects = list->text_objects;
3452 text_object_count = list->text_object_count;
3459 void parse_conky_vars(char * text, char * p, struct information *cur) {
3460 struct text_object_list *object_list = extract_variable_text_internal(text);
3461 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3465 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3470 char buff_in[P_MAX_SIZE] = {0};
3471 iconv_converting = 0;
3474 for (i = 0; i < object_count; i++) {
3475 struct text_object *obj = &objs[i];
3477 #define OBJ(a) break; case OBJ_##a:
3479 switch (obj->type) {
3482 ERR("not implemented obj type %d",
3486 /* does anyone have decimals in acpi temperature? */
3488 snprintf(p, p_max_size, "%d", (int)
3489 get_acpi_temperature(obj->
3493 snprintf(p, 5, "%d ", (int)
3494 get_acpi_temperature(obj->
3499 /* does anyone have decimals in acpi temperature? */
3501 snprintf(p, p_max_size, "%d", (int)
3502 ((get_acpi_temperature(obj->
3504 i)+ 40) * 9.0 / 5 - 40));
3506 snprintf(p, 5, "%d ", (int)
3507 ((get_acpi_temperature(obj->
3509 i)+ 40) * 9.0 / 5 - 40));
3513 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3518 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3521 #if defined(__linux__)
3524 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3529 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3533 OBJ(wireless_essid) {
3534 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3536 OBJ(wireless_mode) {
3537 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3539 OBJ(wireless_bitrate) {
3540 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3543 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3545 OBJ(wireless_link_qual) {
3546 snprintf(p, p_max_size, "%d", obj->data.net->link_qual);
3548 OBJ(wireless_link_qual_max) {
3549 snprintf(p, p_max_size, "%d", obj->data.net->link_qual_max);
3551 OBJ(wireless_link_bar) {
3552 new_bar(p, obj->a, obj->b, ((double)obj->data.net->link_qual/obj->data.net->link_qual_max)*255.0);
3554 #endif /* HAVE_IWLIB */
3556 #endif /* __linux__ */
3560 get_freq_dynamic(p, 6, "%.0f ", 1 );
3562 get_freq_dynamic(p, p_max_size, "%.0f", 1 );
3567 get_freq_dynamic(p, 6, "%'.2f ", 1000);
3569 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3573 get_adt746x_cpu(p, p_max_size);
3576 get_adt746x_fan(p, p_max_size);
3579 get_acpi_fan(p, p_max_size);
3581 OBJ(acpiacadapter) {
3582 get_acpi_ac_adapter(p, p_max_size);
3585 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3588 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3590 OBJ(battery_percent) {
3591 snprintf(p, p_max_size, "%d",
3592 get_battery_perct(obj->data.s));
3595 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3598 human_readable(cur->buffers * 1024, p, 255);
3601 human_readable(cur->cached * 1024, p, 255);
3604 if (obj->data.cpu_index > info.cpu_count) {
3605 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3606 CRIT_ERR("attempting to use more CPUs then you have!");
3609 snprintf(p, p_max_size, "%*d", pad_percents,
3610 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3613 snprintf(p, 4, "%*d ",
3615 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3621 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3624 new_graph(p, obj->a,
3625 obj->b, obj->c, obj->d,
3626 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3630 new_fg(p, obj->data.l);
3662 #if defined(__linux__)
3664 snprintf(p, p_max_size, "%s", i8k.version);
3667 snprintf(p, p_max_size, "%s", i8k.bios);
3670 snprintf(p, p_max_size, "%s", i8k.serial);
3673 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3675 OBJ(i8k_cpu_tempf) {
3677 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3678 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3680 OBJ(i8k_left_fan_status) {
3681 int left_fan_status;
3682 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3683 if(left_fan_status == 0) {
3684 snprintf(p, p_max_size,"off");
3685 } if(left_fan_status == 1) {
3686 snprintf(p, p_max_size, "low");
3687 } if(left_fan_status == 2) {
3688 snprintf(p, p_max_size, "high");
3692 OBJ(i8k_right_fan_status) {
3693 int right_fan_status;
3694 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3695 if(right_fan_status == 0) {
3696 snprintf(p, p_max_size,"off");
3697 } if(right_fan_status == 1) {
3698 snprintf(p, p_max_size, "low");
3699 } if(right_fan_status == 2) {
3700 snprintf(p, p_max_size, "high");
3703 OBJ(i8k_left_fan_rpm) {
3704 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3706 OBJ(i8k_right_fan_rpm) {
3707 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3709 OBJ(i8k_ac_status) {
3711 sscanf(i8k.ac_status, "%d", &ac_status);
3712 if(ac_status == -1) {
3713 snprintf(p, p_max_size,"disabled (read i8k docs)");
3714 } if(ac_status == 0) {
3715 snprintf(p, p_max_size, "off");
3716 } if(ac_status == 1) {
3717 snprintf(p, p_max_size, "on");
3720 OBJ(i8k_buttons_status) {
3721 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3725 get_ibm_acpi_fan(p, p_max_size);
3728 get_ibm_acpi_temps();
3729 snprintf(p, p_max_size, "%d",
3730 ibm_acpi.temps[obj->data.sensor]);
3733 get_ibm_acpi_volume(p, p_max_size);
3735 OBJ(ibm_brightness) {
3736 get_ibm_acpi_brightness(p, p_max_size);
3739 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3741 #endif /* __linux__ */
3744 OBJ(obsd_sensors_temp) {
3745 obsd_sensors.device = sensor_device;
3746 update_obsd_sensors();
3747 snprintf(p, p_max_size, "%.1f",
3748 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
3751 OBJ(obsd_sensors_fan) {
3752 obsd_sensors.device = sensor_device;
3753 update_obsd_sensors();
3754 snprintf(p, p_max_size, "%d",
3755 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3758 OBJ(obsd_sensors_volt) {
3759 obsd_sensors.device = sensor_device;
3760 update_obsd_sensors();
3761 snprintf(p, p_max_size, "%.2f",
3762 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3766 get_obsd_vendor(p, p_max_size);
3770 get_obsd_product(p, p_max_size);
3772 #endif /* __OpenBSD__ */
3776 new_font(p, obj->data.s);
3779 void format_diskio(unsigned int diskio_value)
3782 if (diskio_value > 1024*1024) {
3783 snprintf(p, p_max_size, "%.1fGiB",
3784 (double)diskio_value/1024/1024);
3785 } else if (diskio_value > 1024) {
3786 snprintf(p, p_max_size, "%.1fMiB",
3787 (double)diskio_value/1024);
3788 } else if (diskio_value > 0) {
3789 snprintf(p, p_max_size, "%dKiB", diskio_value);
3791 snprintf(p, p_max_size, "%dB", diskio_value);
3794 if (diskio_value > 1024*1024) {
3795 snprintf(p, 12, "%.1fGiB ",
3796 (double)diskio_value/1024/1024);
3797 } else if (diskio_value > 1024) {
3798 snprintf(p, 12, "%.1fMiB ",
3799 (double)diskio_value/1024);
3800 } else if (diskio_value > 0) {
3801 snprintf(p, 12, "%dKiB ", diskio_value);
3803 snprintf(p, 12, "%dB ", diskio_value);
3808 format_diskio(diskio_value);
3811 format_diskio(diskio_write_value);
3814 format_diskio(diskio_read_value);
3817 new_graph(p, obj->a,
3818 obj->b, obj->c, obj->d,
3819 diskio_value, obj->e, 1);
3821 OBJ(diskiograph_read) {
3822 new_graph(p, obj->a,
3823 obj->b, obj->c, obj->d,
3824 diskio_read_value, obj->e, 1);
3826 OBJ(diskiograph_write) {
3827 new_graph(p, obj->a,
3828 obj->b, obj->c, obj->d,
3829 diskio_write_value, obj->e, 1);
3833 snprintf(p, p_max_size, "%d",
3834 (int) (obj->data.net->
3838 snprintf(p, 6, "%d ",
3839 (int) (obj->data.net->
3845 snprintf(p, p_max_size, "%.1f",
3847 recv_speed / 1024.0);
3849 snprintf(p, 8, "%.1f ",
3851 recv_speed / 1024.0);
3853 OBJ(downspeedgraph) {
3855 if (obj->data.net->recv_speed == 0)
3856 obj->data.net->recv_speed = 0.01;
3858 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3859 (obj->data.net->recv_speed /
3860 1024.0), obj->e, 1);
3864 i = obj->data.ifblock.pos - 1;
3874 snprintf(p, p_max_size, "%u.%u.%u.%u",
3875 obj->data.net->addr.
3877 obj->data.net->addr.
3879 obj->data.net->addr.
3881 obj->data.net->addr.
3887 snprintf(p, p_max_size, "%d",
3888 obj->data.net->linkstatus);
3891 snprintf(p, 5, "%4d ",
3892 obj->data.net->linkstatus);
3895 #if defined(IMLIB2) && defined(X11)
3900 Imlib_Image image, buffer;
3901 image = imlib_load_image(obj->data.s);
3902 imlib_context_set_image(image);
3905 w = imlib_image_get_width();
3906 h = imlib_image_get_height();
3907 buffer = imlib_create_image(w, h);
3908 imlib_context_set_display(display);
3909 imlib_context_set_drawable(window.drawable);
3910 imlib_context_set_colormap(DefaultColormap(display, screen));
3911 imlib_context_set_visual(DefaultVisual(display, screen));
3912 imlib_context_set_image(buffer);
3913 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
3914 imlib_render_image_on_drawable(text_start_x, text_start_y);
3916 imlib_context_set_image(image);
3923 FILE *fp = popen(obj->data.s, "r");
3924 int length = fread(p, 1, p_max_size, fp);
3927 /*output[length] = '\0';
3928 if (length > 0 && output[length - 1] == '\n') {
3929 output[length - 1] = '\0';
3932 if (length > 0 && p[length - 1] == '\n') {
3933 p[length - 1] = '\0';
3936 //parse_conky_vars(output, p, cur);
3940 FILE *fp = popen(obj->data.s, "r");
3941 int n2 = fread(p, 1, p_max_size, fp);
3945 if (n2 && p[n2 - 1] == '\n')
3954 if (sscanf(p, "%lf", &barnum) == 0) {
3955 ERR("reading execbar value failed (perhaps it's not the correct format?)");
3957 if (barnum > 100 || barnum < 0) {
3958 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
3960 barnum = barnum / 100.0;
3961 new_bar(p, 0, 4, (int) (barnum * 255.0));
3967 FILE *fp = popen(obj->data.s, "r");
3968 int n2 = fread(p, 1, p_max_size, fp);
3972 if (n2 && p[n2 - 1] == '\n')
3981 if (sscanf(p, "%lf", &barnum) == 0) {
3982 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
3984 if (barnum > 100 || barnum < 0) {
3985 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
3987 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
3992 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3993 new_bar(p, 0, 4, (int) obj->f);
3996 FILE *fp = popen(obj->data.execi.cmd, "r");
3997 int n2 = fread(p, 1, p_max_size, fp);
4000 if (n2 && p[n2 - 1] == '\n')
4009 if (sscanf(p, "%f", &barnum) == 0) {
4010 ERR("reading execibar value failed (perhaps it's not the correct format?)");
4012 if (barnum > 100 || barnum < 0) {
4013 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
4015 obj->f = 255 * barnum / 100.0;
4016 new_bar(p, 0, 4, (int) obj->f);
4018 obj->data.execi.last_update =
4019 current_update_time;
4023 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
4024 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
4027 FILE *fp = popen(obj->data.execi.cmd, "r");
4028 int n2 = fread(p, 1, p_max_size, fp);
4031 if (n2 && p[n2 - 1] == '\n')
4040 if (sscanf(p, "%f", &barnum) == 0) {
4041 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
4043 if (barnum > 100 || barnum < 0) {
4044 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
4047 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
4049 obj->data.execi.last_update = current_update_time;
4055 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
4056 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4058 char *output = obj->data.execi.buffer;
4059 FILE *fp = popen(obj->data.execi.cmd, "r");
4060 //int length = fread(output, 1, text_buffer_size, fp);
4061 int length = fread(output, 1, text_buffer_size, fp);
4064 output[length] = '\0';
4065 if (length > 0 && output[length - 1] == '\n') {
4066 output[length - 1] = '\0';
4068 obj->data.execi.last_update = current_update_time;
4069 snprintf(p, p_max_size, "%s", output);
4071 //parse_conky_vars(output, p, cur);
4074 if (!obj->data.texeci.p_timed_thread)
4076 obj->data.texeci.p_timed_thread=
4077 timed_thread_create ((void*)threaded_exec, (void*) obj,
4078 obj->data.texeci.interval * 1000000);
4079 if (!obj->data.texeci.p_timed_thread)
4080 ERR("Error starting texeci thread");
4081 timed_thread_register (obj->data.texeci.p_timed_thread,
4082 &obj->data.texeci.p_timed_thread);
4084 timed_thread_lock (obj->data.texeci.p_timed_thread);
4085 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4086 timed_thread_unlock (obj->data.texeci.p_timed_thread);
4088 #endif /* HAVE_POPEN */
4090 if (obj->global_mode && info.mail) { // this means we use info
4091 if (!info.mail->p_timed_thread)
4093 info.mail->p_timed_thread =
4094 timed_thread_create ((void*)imap_thread,
4096 info.mail->interval * 1000000);
4097 if (!info.mail->p_timed_thread)
4098 ERR("Error starting imap thread");
4099 timed_thread_register (info.mail->p_timed_thread,
4100 &info.mail->p_timed_thread);
4102 timed_thread_lock (info.mail->p_timed_thread);
4103 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4104 timed_thread_unlock (info.mail->p_timed_thread);
4105 } else if (obj->data.mail) { // this means we use obj
4106 if (!obj->data.mail->p_timed_thread)
4108 obj->data.mail->p_timed_thread =
4109 timed_thread_create ((void*)imap_thread,
4110 (void*)obj->data.mail,
4111 obj->data.mail->interval * 1000000);
4112 if (!obj->data.mail->p_timed_thread)
4113 ERR("Error starting imap thread");
4114 timed_thread_register (obj->data.mail->p_timed_thread,
4115 &obj->data.mail->p_timed_thread);
4117 timed_thread_lock (obj->data.mail->p_timed_thread);
4118 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4119 timed_thread_unlock (obj->data.mail->p_timed_thread);
4120 } else if (!obj->a) { // something is wrong, warn once then stop
4121 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4125 OBJ(imap_messages) {
4126 if (obj->global_mode && info.mail) { // this means we use info
4127 if (!info.mail->p_timed_thread)
4129 info.mail->p_timed_thread =
4130 timed_thread_create ((void*)imap_thread,
4132 info.mail->interval * 1000000);
4133 if (!info.mail->p_timed_thread)
4134 ERR("Error starting imap thread");
4135 timed_thread_register (info.mail->p_timed_thread,
4136 &info.mail->p_timed_thread);
4138 timed_thread_lock (info.mail->p_timed_thread);
4139 snprintf(p, p_max_size, "%lu", info.mail->messages);
4140 timed_thread_unlock (info.mail->p_timed_thread);
4141 } else if (obj->data.mail) { // this means we use obj
4142 if (!obj->data.mail->p_timed_thread)
4144 obj->data.mail->p_timed_thread =
4145 timed_thread_create ((void*)imap_thread,
4146 (void*)obj->data.mail,
4147 obj->data.mail->interval * 1000000);
4148 if (!obj->data.mail->p_timed_thread)
4149 ERR("Error starting imap thread");
4150 timed_thread_register (obj->data.mail->p_timed_thread,
4151 &obj->data.mail->p_timed_thread);
4153 timed_thread_lock (obj->data.mail->p_timed_thread);
4154 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4155 timed_thread_lock (obj->data.mail->p_timed_thread);
4156 } else if (!obj->a) { // something is wrong, warn once then stop
4157 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4162 if (obj->global_mode && info.mail) { // this means we use info
4163 if (!info.mail->p_timed_thread)
4165 info.mail->p_timed_thread =
4166 timed_thread_create ((void*)pop3_thread,
4168 info.mail->interval * 1000000);
4169 if (!info.mail->p_timed_thread)
4170 ERR("Error starting pop3 thread");
4171 timed_thread_register (info.mail->p_timed_thread,
4172 &info.mail->p_timed_thread);
4174 timed_thread_lock (info.mail->p_timed_thread);
4175 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4176 timed_thread_unlock (info.mail->p_timed_thread);
4177 } else if (obj->data.mail) { // this means we use obj
4178 if (!obj->data.mail->p_timed_thread)
4180 obj->data.mail->p_timed_thread =
4181 timed_thread_create ((void*)pop3_thread,
4182 (void*)obj->data.mail,
4183 obj->data.mail->interval * 1000000);
4184 if (!obj->data.mail->p_timed_thread)
4185 ERR("Error starting pop3 thread");
4186 timed_thread_register (obj->data.mail->p_timed_thread,
4187 &obj->data.mail->p_timed_thread);
4189 timed_thread_lock (obj->data.mail->p_timed_thread);
4190 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4191 timed_thread_unlock (obj->data.mail->p_timed_thread);
4192 } else if (!obj->a) { // something is wrong, warn once then stop
4193 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4198 if (obj->global_mode && info.mail) { // this means we use info
4199 if (!info.mail->p_timed_thread)
4201 info.mail->p_timed_thread =
4202 timed_thread_create ((void*)pop3_thread,
4204 info.mail->interval * 1000000);
4205 if (!info.mail->p_timed_thread)
4206 ERR("Error starting pop3 thread");
4207 timed_thread_register (info.mail->p_timed_thread,
4208 &info.mail->p_timed_thread);
4210 timed_thread_lock (info.mail->p_timed_thread);
4211 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4212 timed_thread_unlock (info.mail->p_timed_thread);
4213 } else if (obj->data.mail) { // this means we use obj
4214 if (!obj->data.mail->p_timed_thread)
4216 obj->data.mail->p_timed_thread =
4217 timed_thread_create ((void*)pop3_thread,
4218 (void*)obj->data.mail,
4219 obj->data.mail->interval * 1000000);
4220 if (!obj->data.mail->p_timed_thread)
4221 ERR("Error starting pop3 thread");
4222 timed_thread_register (obj->data.mail->p_timed_thread,
4223 &obj->data.mail->p_timed_thread);
4225 timed_thread_lock (obj->data.mail->p_timed_thread);
4226 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4227 timed_thread_unlock (obj->data.mail->p_timed_thread);
4228 } else if (!obj->a) { // something is wrong, warn once then stop
4229 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4234 if (obj->data.fs != NULL) {
4235 if (obj->data.fs->size == 0)
4254 if (obj->data.fs != NULL)
4255 human_readable(obj->data.fs->avail,
4259 if (obj->data.fs != NULL) {
4260 if (obj->data.fs->size)
4261 snprintf(p, p_max_size, "%*d",
4270 snprintf(p, p_max_size, "0");
4274 if (obj->data.fs != NULL)
4275 human_readable(obj->data.fs->size,
4279 if (obj->data.fs != NULL)
4280 human_readable(obj->data.fs->size -
4281 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
4285 if (obj->data.fs != NULL) {
4286 if (obj->data.fs->size == 0)
4304 if (obj->data.fs != NULL) {
4305 if (obj->data.fs->size)
4306 snprintf(p, 4, "%d",
4316 snprintf(p, p_max_size, "0");
4320 float *v = info.loadavg;
4322 if (obj->data.loadavg[2])
4323 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4324 v[obj->data.loadavg[0] -
4326 v[obj->data.loadavg[1] -
4328 v[obj->data.loadavg[2] -
4330 else if (obj->data.loadavg[1])
4331 snprintf(p, p_max_size, "%.2f %.2f",
4332 v[obj->data.loadavg[0] -
4334 v[obj->data.loadavg[1] -
4336 else if (obj->data.loadavg[0])
4337 snprintf(p, p_max_size, "%.2f",
4338 v[obj->data.loadavg[0] -
4342 new_goto(p, obj->data.i);
4345 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4348 new_hr(p, obj->data.i);
4352 PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay);
4355 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4357 if(!strcmp(obj->data.rss.action, "feed_title")) {
4359 if(str[strlen(str)-1] == '\n')
4360 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4361 snprintf(p, p_max_size, "%s", str);
4362 } else if(!strcmp(obj->data.rss.action, "item_title")) {
4363 if(obj->data.rss.act_par < data->item_count) {
4364 str = data->items[obj->data.rss.act_par].title;
4365 if(str[strlen(str)-1] == '\n')
4366 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4367 snprintf(p, p_max_size, "%s", str);
4369 } else if(!strcmp(obj->data.rss.action, "item_desc")) {
4370 if(obj->data.rss.act_par < data->item_count) {
4371 str = data->items[obj->data.rss.act_par].description;
4372 if(str[strlen(str)-1] == '\n')
4373 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4374 snprintf(p, p_max_size, "%s", str);
4376 } else if(!strcmp(obj->data.rss.action, "item_titles")) {
4377 if(data->item_count > 0) {
4381 if(obj->data.rss.act_par > data->item_count)
4382 show = data->item_count;
4383 else show = obj->data.rss.act_par;
4384 for(itmp = 0; itmp < show; itmp++) {
4385 PRSS_Item *item = &data->items[itmp];
4388 if(itmp>0) // don't add new line before first item
4389 strncat(p, "\n", p_max_size);
4390 if(str[strlen(str)-1] == '\n')
4391 str[strlen(str)-1] = 0; // remove trailing new line if one exists, we have our own
4392 strncat(p, str, p_max_size);
4405 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4406 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4408 snprintf(p, p_max_size, "N/A");
4409 } else if (unit == '*') {
4410 snprintf(p, p_max_size, "%s", temp);
4412 snprintf(p, p_max_size, "%s°%c", temp, unit);
4417 new_offset(p, obj->data.i);
4420 new_voffset(p, obj->data.i);
4425 r = get_i2c_info(&obj->data.i2c.fd,
4427 obj->data.i2c.devtype,
4428 obj->data.i2c.type);
4430 if (r >= 100.0 || r == 0)
4431 snprintf(p, p_max_size, "%d", (int) r);
4433 snprintf(p, p_max_size, "%.1f", r);
4436 new_alignr(p, obj->data.i);
4439 new_alignc(p, obj->data.i);
4442 struct information *my_info =
4443 malloc(sizeof(struct information));
4444 memcpy(my_info, cur, sizeof(struct information));
4445 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4446 if (strlen(p) != 0) {
4447 i = obj->data.ifblock.pos;
4457 if ((obj->data.ifblock.s)
4458 && (stat(obj->data.ifblock.s, &tmp) ==
4460 i = obj->data.ifblock.pos;
4463 if (obj->data.ifblock.str) {
4464 if (!check_contains(obj->data.ifblock.s,
4465 obj->data.ifblock.str)) {
4466 i = obj->data.ifblock.pos;
4475 if ((obj->data.ifblock.s)
4476 && (!check_mount(obj->data.ifblock.s))) {
4477 i = obj->data.ifblock.pos;
4484 if ((obj->data.ifblock.s)
4485 && system(obj->data.ifblock.s)) {
4486 i = obj->data.ifblock.pos;
4493 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4496 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4501 human_readable(cur->mem * 1024, p, 255);
4504 human_readable(cur->memmax * 1024, p, 255);
4509 snprintf(p, p_max_size, "%*Lu",
4514 snprintf(p, 4, "%*Lu ",
4521 new_bar(p, obj->data.pair.a,
4523 cur->memmax ? (cur->mem * 255) /
4528 new_graph(p, obj->a,
4529 obj->b, obj->c, obj->d,
4530 cur->memmax ? (cur->mem * 100.0) /
4531 (cur->memmax) : 0.0, 100, 1);
4535 snprintf(p, p_max_size, "%d",
4536 mixer_get_avg(obj->data.l));
4539 snprintf(p, p_max_size, "%d",
4540 mixer_get_left(obj->data.l));
4543 snprintf(p, p_max_size, "%d",
4544 mixer_get_right(obj->data.l));
4547 new_bar(p, obj->data.mixerbar.w,
4548 obj->data.mixerbar.h,
4549 mixer_get_avg(obj->data.mixerbar.
4553 new_bar(p, obj->data.mixerbar.w,
4554 obj->data.mixerbar.h,
4555 mixer_get_left(obj->data.mixerbar.
4559 new_bar(p, obj->data.mixerbar.w,
4560 obj->data.mixerbar.h,
4561 mixer_get_right(obj->data.mixerbar.
4567 snprintf(p, p_max_size, "%d", cur->mail_count);
4570 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4571 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4574 snprintf(p, p_max_size, "%d", cur->new_mail_count);
4578 snprintf(p, p_max_size, "%s",
4579 cur->uname_s.nodename);
4582 new_outline(p, obj->data.l);
4586 snprintf(p, p_max_size, "%hu", cur->procs);
4588 snprintf(p, 5, "%hu ",
4591 OBJ(running_processes) {
4593 snprintf(p, p_max_size, "%hu",
4596 snprintf(p, 3, "%hu ",
4600 snprintf(p, p_max_size, "%s", obj->data.s);
4603 new_bg(p, obj->data.l);
4606 new_stippled_hr(p, obj->data.pair.a,
4610 human_readable(cur->swap * 1024, p, 255);
4613 human_readable(cur->swapmax * 1024, p,
4617 if (cur->swapmax == 0) {
4618 strncpy(p, "No swap", 255);
4621 snprintf(p, 255, "%*Lu",
4627 snprintf(p, 4, "%*Lu ",
4635 new_bar(p, obj->data.pair.a,
4637 cur->swapmax ? (cur->swap * 255) /
4638 (cur->swapmax) : 0);
4641 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4644 time_t t = time(NULL);
4645 struct tm *tm = localtime(&t);
4646 setlocale(LC_TIME, "");
4647 strftime(p, p_max_size, obj->data.s, tm);
4650 time_t t = time(NULL);
4651 struct tm *tm = gmtime(&t);
4652 strftime(p, p_max_size, obj->data.s, tm);
4656 if (obj->data.tztime.tz) {
4657 oldTZ = getenv("TZ");
4658 setenv("TZ", obj->data.tztime.tz, 1);
4661 time_t t = time(NULL);
4662 struct tm *tm = localtime(&t);
4663 setlocale(LC_TIME, "");
4664 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4666 setenv("TZ", oldTZ, 1);
4671 // Needless to free oldTZ since getenv gives ptr to static data
4674 human_readable(obj->data.net->recv, p,
4678 human_readable(obj->data.net->trans, p,
4682 snprintf(p, p_max_size, "%d", total_updates);
4686 snprintf(p, p_max_size, "%d",
4687 (int) (obj->data.net->
4691 snprintf(p, 6, "%d ",
4692 (int) (obj->data.net->
4698 snprintf(p, p_max_size, "%.1f",
4700 trans_speed / 1024.0);
4702 snprintf(p, 8, "%.1f ",
4704 trans_speed / 1024.0);
4708 if (obj->data.net->trans_speed == 0)
4709 obj->data.net->trans_speed = 0.01;
4711 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4712 (obj->data.net->trans_speed /
4713 1024.0), obj->e, 1);
4716 format_seconds_short(p, p_max_size,
4720 format_seconds(p, p_max_size, (int) cur->uptime);
4723 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4726 msg = get_apm_adapter();
4727 snprintf(p, p_max_size, "%s", msg);
4730 OBJ(apm_battery_life) {
4732 msg = get_apm_battery_life();
4733 snprintf(p, p_max_size, "%s", msg);
4736 OBJ(apm_battery_time) {
4738 msg = get_apm_battery_time();
4739 snprintf(p, p_max_size, "%s", msg);
4742 #endif /* __FreeBSD__ __OpenBSD__ */
4746 snprintf(p, cur->mpd.max_title_len > 0 ?
4747 cur->mpd.max_title_len : p_max_size, "%s",
4751 snprintf(p, p_max_size, "%s", cur->mpd.artist);
4754 snprintf(p, p_max_size, "%s", cur->mpd.album);
4757 snprintf(p, p_max_size, "%s", cur->mpd.random);
4760 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
4763 snprintf(p, p_max_size, "%s", cur->mpd.track);
4766 snprintf(p, p_max_size, "%s", cur->mpd.name);
4769 snprintf(p, p_max_size, "%s", cur->mpd.file);
4772 snprintf(p, p_max_size, "%i", cur->mpd.volume);
4775 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
4778 snprintf(p, p_max_size, "%s", cur->mpd.status);
4781 int days = 0, hours = 0, minutes =
4783 int tmp = cur->mpd.elapsed;
4784 while (tmp >= 86400) {
4788 while (tmp >= 3600) {
4798 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
4799 days, hours, minutes,
4802 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4805 snprintf(p, p_max_size, "%i:%02i", minutes,
4809 int days = 0, hours = 0, minutes =
4811 int tmp = cur->mpd.length;
4812 while (tmp >= 86400) {
4816 while (tmp >= 3600) {
4826 snprintf(p, p_max_size,
4827 "%i days %i:%02i:%02i",
4828 days, hours, minutes,
4831 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4834 snprintf(p, p_max_size, "%i:%02i", minutes,
4838 snprintf(p, p_max_size, "%2.0f",
4839 cur->mpd.progress * 100);
4842 new_bar(p, obj->data.pair.a,
4844 (int) (cur->mpd.progress *
4848 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.title) < 2) {
4849 snprintf(p, p_max_size, "%s", cur->mpd.file);
4851 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
4857 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4860 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4863 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4866 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4868 OBJ(xmms2_comment) {
4869 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4871 OBJ(xmms2_decoder) {
4872 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
4874 OBJ(xmms2_transport) {
4875 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
4878 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4881 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4884 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4886 OBJ(xmms2_tracknr) {
4887 if (cur->xmms2.tracknr != -1)
4888 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4890 OBJ(xmms2_bitrate) {
4891 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4894 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4897 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4899 OBJ(xmms2_elapsed) {
4900 int tmp = cur->xmms2.elapsed;
4901 snprintf(p, p_max_size, "%02d:%02d",
4902 tmp / 60000, (tmp / 1000) % 60);
4904 OBJ(xmms2_duration) {
4905 int tmp = cur->xmms2.duration;
4906 snprintf(p, p_max_size, "%02d:%02d",
4907 tmp / 60000, (tmp / 1000) % 60);
4909 OBJ(xmms2_percent) {
4910 snprintf(p, p_max_size, "%2.0f",
4911 cur->xmms2.progress * 100);
4914 new_bar(p, obj->data.pair.a,
4916 (int) (cur->xmms2.progress *
4920 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
4921 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4923 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
4928 OBJ(audacious_status) {
4929 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
4931 OBJ(audacious_title) {
4932 snprintf(p, cur->audacious.max_title_len > 0 ?
4933 cur->audacious.max_title_len : p_max_size, "%s",
4934 cur->audacious.items[AUDACIOUS_TITLE]);
4936 OBJ(audacious_length) {
4937 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
4939 OBJ(audacious_length_seconds) {
4940 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4942 OBJ(audacious_position) {
4943 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
4945 OBJ(audacious_position_seconds) {
4946 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
4948 OBJ(audacious_bitrate) {
4949 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
4951 OBJ(audacious_frequency) {
4952 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
4954 OBJ(audacious_channels) {
4955 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
4957 OBJ(audacious_filename) {
4958 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
4960 OBJ(audacious_playlist_length) {
4961 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
4963 OBJ(audacious_playlist_position) {
4964 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
4966 OBJ(audacious_bar) {
4968 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
4969 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4970 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
4975 snprintf(p, p_max_size, "%s", cur->bmpx.title);
4978 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
4981 snprintf(p, p_max_size, "%s", cur->bmpx.album);
4984 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
4987 snprintf(p, p_max_size, "%i", cur->bmpx.track);
4990 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
4994 if (obj->data.top.type == TOP_NAME
4995 && obj->data.top.num >= 0
4996 && obj->data.top.num < 10) {
4997 snprintf(p, 17, "%-17s", cur->cpu[obj->data.top.num]->name);
4998 } else if (obj->data.top.type == TOP_CPU
4999 && obj->data.top.num >= 0
5000 && obj->data.top.num < 10) {
5001 snprintf(p, 7, "%7.3f",
5002 cur->cpu[obj->data.top.
5004 } else if (obj->data.top.type == TOP_PID
5005 && obj->data.top.num >= 0
5006 && obj->data.top.num < 10) {
5007 snprintf(p, 8, "%7i",
5008 cur->cpu[obj->data.top.
5010 } else if (obj->data.top.type == TOP_MEM
5011 && obj->data.top.num >= 0
5012 && obj->data.top.num < 10) {
5013 snprintf(p, 7, "%7.3f",
5014 cur->cpu[obj->data.top.
5019 if (obj->data.top.type == TOP_NAME
5020 && obj->data.top.num >= 0
5021 && obj->data.top.num < 10) {
5022 snprintf(p, 17, "%-17s",
5023 cur->memu[obj->data.top.
5025 } else if (obj->data.top.type == TOP_CPU
5026 && obj->data.top.num >= 0
5027 && obj->data.top.num < 10) {
5028 snprintf(p, 7, "%7.3f",
5029 cur->memu[obj->data.top.
5031 } else if (obj->data.top.type == TOP_PID
5032 && obj->data.top.num >= 0
5033 && obj->data.top.num < 10) {
5034 snprintf(p, 8, "%7i",
5035 cur->memu[obj->data.top.
5037 } else if (obj->data.top.type == TOP_MEM
5038 && obj->data.top.num >= 0
5039 && obj->data.top.num < 10) {
5040 snprintf(p, 7, "%7.3f",
5041 cur->memu[obj->data.top.
5048 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5049 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5051 obj->data.tail.last_update = current_update_time;
5055 fp = fopen(obj->data.tail.logfile, "rt");
5057 /* Send one message, but do not consistently spam on
5058 * missing logfiles. */
5059 if(obj->data.tail.readlines != 0) {
5060 ERR("tail logfile failed to open");
5061 strcpy(obj->data.tail.buffer, "Logfile Missing");
5063 obj->data.tail.readlines = 0;
5064 snprintf(p, p_max_size, "Logfile Missing");
5067 obj->data.tail.readlines = 0;
5068 /* -1 instead of 0 to avoid counting a trailing newline */
5069 fseek(fp, -1, SEEK_END);
5070 bsize = ftell(fp) + 1;
5071 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5072 nl = rev_fcharfind(fp, '\n', iter);
5076 obj->data.tail.readlines = iter;
5077 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
5078 fseek(fp, 0, SEEK_SET);
5081 fseek(fp, nl+1, SEEK_SET);
5084 /* Make sure bsize is at least 1 byte smaller than
5085 * the buffer max size. */
5086 if(bsize > (long)((text_buffer_size*20) - 1)) {
5087 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
5088 bsize = text_buffer_size*20 - 1;
5090 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5093 /* Clean up trailing newline, make sure the buffer
5094 * is null terminated. */
5095 if(obj->data.tail.buffer[bsize-1] == '\n')
5096 obj->data.tail.buffer[bsize-1] = '\0';
5098 obj->data.tail.buffer[bsize] = '\0';
5099 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5102 strcpy(obj->data.tail.buffer, "Logfile Empty");
5103 snprintf(p, p_max_size, "Logfile Empty");
5106 } /* if cur_upd_time >= */
5108 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5112 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5113 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5115 obj->data.tail.last_update = current_update_time;
5119 fp = fopen(obj->data.tail.logfile, "rt");
5121 /* Send one message, but do not consistently spam on
5122 * missing logfiles. */
5123 if(obj->data.tail.readlines != 0) {
5124 ERR("head logfile failed to open");
5125 strcpy(obj->data.tail.buffer, "Logfile Missing");
5127 obj->data.tail.readlines = 0;
5128 snprintf(p, p_max_size, "Logfile Missing");
5130 obj->data.tail.readlines = 0;
5131 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5132 nl = fwd_fcharfind(fp, '\n', iter);
5136 obj->data.tail.readlines = iter;
5137 /* Make sure nl is at least 1 byte smaller than
5138 * the buffer max size. */
5139 if(nl > (long)((text_buffer_size*20) - 1)) {
5140 nl = text_buffer_size*20 - 1;
5142 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5145 /* Clean up trailing newline, make sure the buffer
5146 * is null terminated. */
5147 if (obj->data.tail.buffer[nl-1] == '\n') {
5148 obj->data.tail.buffer[nl-1] = '\0';
5151 obj->data.tail.buffer[nl] = '\0';
5153 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5156 strcpy(obj->data.tail.buffer, "Logfile Empty");
5157 snprintf(p, p_max_size, "Logfile Empty");
5159 } /* if fp == null */
5160 } /* cur_upd_time >= */
5162 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5165 #ifdef TCP_PORT_MONITOR
5168 /* grab a pointer to this port monitor */
5169 tcp_port_monitor_t * p_monitor =
5170 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
5171 obj->data.tcp_port_monitor.port_range_begin,
5172 obj->data.tcp_port_monitor.port_range_end );
5174 snprintf(p, p_max_size, "monitor not found");
5178 /* now grab the text of interest */
5179 if ( peek_tcp_port_monitor( p_monitor,
5180 obj->data.tcp_port_monitor.item,
5181 obj->data.tcp_port_monitor.connection_index,
5182 p, p_max_size ) != 0 )
5184 snprintf(p, p_max_size, "monitor peek error");
5193 iconv_converting = 1;
5194 iconv_selected = obj->a;
5199 iconv_converting = 0;
5205 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5207 OBJ(entropy_poolsize)
5209 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5213 double entropy_perc;
5214 entropy_perc = (double)cur->entropy.entropy_avail /
5215 (double)cur->entropy.poolsize;
5216 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5224 unsigned int a = strlen(p);
5227 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5229 size_t dummy1, dummy2;
5230 char *ptr = buff_in;
5233 dummy1 = dummy2 = a;
5235 strncpy(buff_in, p, P_MAX_SIZE);
5237 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5238 while (dummy1 > 0) {
5239 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5241 ERR("Iconv codeset conversion failed");
5246 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5257 double current_update_time, last_update_time;
5259 static void generate_text()
5261 struct information *cur = &info;
5269 current_update_time = get_time();
5272 /* fix diskio rates to b/s (use update_interval */
5273 diskio_read_value = diskio_read_value / update_interval;
5274 diskio_write_value = diskio_write_value / update_interval;
5275 diskio_value = diskio_value / update_interval;
5278 /* add things to the buffer */
5284 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5286 if (stuff_in_upper_case) {
5297 last_update_time = current_update_time;
5304 static void set_font()
5308 if (window.xftdraw != NULL) {
5309 XftDrawDestroy(window.xftdraw);
5311 window.xftdraw = XftDrawCreate(display, window.drawable,
5312 DefaultVisual(display,
5314 DefaultColormap(display,
5319 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5325 static inline int get_string_width(const char *s)
5328 return *s ? calc_text_width(s, strlen(s)) : 0;
5334 static inline int get_string_width_special(char *s)
5347 if (*p == SPECIAL_CHAR) {
5348 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5349 for (i = 0; i < strlen(p); i++) {
5350 *(p + i) = *(p + i + 1);
5352 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5353 width += specials[special_index+index].width;
5360 if (strlen(final) > 1) {
5361 width += calc_text_width(final, strlen(final));
5371 static void text_size_updater(char *s);
5373 int last_font_height;
5374 static void update_text_area()
5378 /* update text size if it isn't fixed */
5383 text_width = minimum_width;
5386 last_font_height = font_height();
5387 for_each_line(text_buffer, text_size_updater);
5389 if (text_height < minimum_height)
5390 text_height = minimum_height;
5391 if (text_width > maximum_width && maximum_width > 0)
5392 text_width = maximum_width;
5395 /* get text position on workarea */
5396 switch (text_alignment) {
5403 x = workarea[2] - text_width - gap_x;
5410 y = workarea[3] - text_height - gap_y;
5414 x = workarea[2] - text_width - gap_x;
5415 y = workarea[3] - text_height - gap_y;
5419 case NONE: // Let the WM manage the window
5430 if (own_window && !fixed_pos) {
5433 text_start_x = border_margin + 1;
5434 text_start_y = border_margin + 1;
5435 window.x = x - border_margin - 1;
5436 window.y = y - border_margin - 1;
5440 /* If window size doesn't match to workarea's size, then window
5441 * probably includes panels (gnome).
5442 * Blah, doesn't work on KDE. */
5443 if (workarea[2] != window.width
5444 || workarea[3] != window.height) {
5458 static int cur_x, cur_y; /* current x and y for drawing */
5459 static int draw_mode; /* FG, BG or OUTLINE */
5460 static long current_color;
5463 static void text_size_updater(char *s)
5467 /* get string widths and skip specials */
5470 if (*p == SPECIAL_CHAR) {
5472 w += get_string_width(s);
5475 if (specials[special_index].type == BAR
5476 || specials[special_index].type == GRAPH) {
5477 w += specials[special_index].width;
5478 if (specials[special_index].height > last_font_height) {
5479 last_font_height = specials[special_index].height;
5480 last_font_height += font_ascent();
5482 } else if (specials[special_index].type == OFFSET) {
5483 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
5484 } else if (specials[special_index].type == VOFFSET) {
5485 last_font_height += specials[special_index].arg;
5486 } else if (specials[special_index].type == GOTO) {
5487 if (specials[special_index].arg >= 0)
5488 w += (int)specials[special_index].arg - cur_x;
5489 } else if (specials[special_index].type == TAB) {
5490 int start = specials[special_index].arg;
5491 int step = specials[special_index].width;
5492 if (!step || step < 0)
5494 w += step - (cur_x - text_start_x - start) % step;
5495 } else if (specials[special_index].type == FONT) {
5496 selected_font = specials[special_index].font_added;
5497 if (font_height() > last_font_height) {
5498 last_font_height = font_height();
5507 w += get_string_width(s);
5508 if (w > text_width) {
5511 if (text_width > maximum_width && maximum_width) {
5512 text_width = maximum_width;
5515 text_height += last_font_height;
5516 last_font_height = font_height();
5520 static inline void set_foreground_color(long c)
5523 XSetForeground(display, window.gc, c);
5527 static void draw_string(const char *s)
5531 int i, i2, pos, width_of_s;
5534 width_of_s = get_string_width(s);
5535 if (out_to_console) {
5537 fflush(stdout); /* output immediately, don't buffer */
5539 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5540 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5541 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5545 snprintf(space, 2, " ");
5547 max = ((text_width - width_of_s) / get_string_width(space));
5550 * This code looks for tabs in the text and coverts them to spaces.
5551 * The trick is getting the correct number of spaces,
5552 * and not going over the window's size without forcing
5553 * the window larger.
5555 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5556 if (tmpstring1[i] == '\t') // 9 is ascii tab
5560 i2 < (8 - (1 + pos) % 8) && added <= max;
5563 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5564 fprintf(stderr,"buffer overrun detected\n");
5566 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5571 if (tmpstring1[i] != 9) {
5573 if ( pos > TEXT_BUFFER_SIZE-1 )
5574 fprintf(stderr,"buffer overrun detected\n");
5576 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5582 if (text_width == maximum_width) {
5583 /* this means the text is probably pushing the limit, so we'll chop it */
5584 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5585 tmpstring2[strlen(tmpstring2)-1] = '\0';
5595 c.pixel = current_color;
5596 XQueryColor(display, DefaultColormap(display, screen), &c);
5599 c2.color.red = c.red;
5600 c2.color.green = c.green;
5601 c2.color.blue = c.blue;
5602 c2.color.alpha = fonts[selected_font].font_alpha;
5604 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5605 cur_x, cur_y, (XftChar8 *) s,
5608 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5609 cur_x, cur_y, (XftChar8 *) s,
5615 XDrawString(display, window.drawable, window.gc,
5616 cur_x, cur_y, s, strlen(s));
5618 cur_x += width_of_s;
5620 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5623 long redmask, greenmask, bluemask;
5625 void set_up_gradient()
5628 colour_depth = DisplayPlanes(display, screen);
5632 if (colour_depth != 24 && colour_depth != 16) {
5633 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5639 for(i = (colour_depth / 3)-1; i>=0; i--) {
5641 greenmask |= 1 << i;
5644 if (colour_depth%3 == 1) {
5645 greenmask |= 1 << (colour_depth / 3);
5647 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5648 greenmask = greenmask << (colour_depth / 3);
5651 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 */
5653 int red1, green1, blue1; // first colour
5654 int red2, green2, blue2; // second colour
5655 int red3 = 0, green3 = 0, blue3 = 0; // difference
5656 short redshift = (2*colour_depth / 3 + colour_depth%3);
5657 short greenshift = (colour_depth / 3);
5658 red1 = (first_colour & redmask) >> redshift;
5659 green1 = (first_colour & greenmask) >> greenshift;
5660 blue1 = first_colour & bluemask;
5661 red2 = (last_colour & redmask) >> redshift;
5662 green2 = (last_colour & greenmask) >> greenshift;
5663 blue2 = last_colour & bluemask;
5670 if (green1 > green2) {
5673 if (green1 < green2) {
5676 if (blue1 > blue2) {
5679 if (blue1 < blue2) {
5694 if (red1 > bluemask) {
5697 if (green1 > bluemask) {
5700 if (blue1 > bluemask) {
5703 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
5707 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
5708 if (colour_depth == 0) {
5711 int red1, green1, blue1; // first colour
5712 int red2, green2, blue2; // second colour
5713 long redshift = (2*colour_depth / 3 + colour_depth%3);
5714 long greenshift = (colour_depth / 3);
5715 int red3 = 0, green3 = 0, blue3 = 0; // difference
5716 red1 = (first_colour & redmask) >> redshift;
5717 green1 = (first_colour & greenmask) >> greenshift;
5718 blue1 = first_colour & bluemask;
5719 red2 = (last_colour & redmask) >> redshift;
5720 green2 = (last_colour & greenmask) >> greenshift;
5721 blue2 = last_colour & bluemask;
5722 red3 = abs(red1 - red2);
5723 green3 = abs(green1 - green2);
5724 blue3 = abs(blue1 - blue2);
5733 static void draw_line(char *s)
5737 cur_x = text_start_x;
5738 cur_y += font_ascent();
5740 short font_h = font_height();
5742 /* find specials and draw stuff */
5745 if (*p == SPECIAL_CHAR) {
5748 /* draw string before special */
5755 switch (specials[special_index].type) {
5756 case HORIZONTAL_LINE:
5759 specials[special_index].height;
5760 int mid = font_ascent() / 2;
5761 w = text_start_x + text_width -
5764 XSetLineAttributes(display,
5769 XDrawLine(display, window.drawable,
5780 specials[special_index].height;
5782 specials[special_index].arg;
5783 int mid = font_ascent() / 2;
5784 char ss[2] = { s, s };
5785 w = text_start_x + text_width -
5788 XSetLineAttributes(display,
5793 XSetDashes(display, window.gc, 0,
5795 XDrawLine(display, window.drawable,
5805 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5809 specials[special_index].height;
5811 specials[special_index].arg;
5812 int by = cur_y - (font_ascent() / 2) - 1;
5813 if (h < font_height()) {
5816 w = specials[special_index].width;
5819 text_width - cur_x - 1;
5823 XSetLineAttributes(display,
5829 XDrawRectangle(display,
5833 XFillRectangle(display,
5837 w * bar_usage / 255,
5839 if (specials[special_index].
5841 && specials[special_index].
5845 [special_index].height;
5852 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5856 specials[special_index].height;
5857 unsigned long last_colour = current_color;
5858 int by = cur_y - (font_ascent()/2) - 1;
5859 if (h < font_height()) {
5862 w = specials[special_index].width;
5864 w = text_start_x + text_width - cur_x - 1;
5867 if (draw_graph_borders) {
5868 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
5869 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
5871 XSetLineAttributes(display,
5878 int gradient_size = 0;
5879 float gradient_factor = 0;
5880 float gradient_update = 0;
5881 unsigned long tmpcolour = current_color;
5882 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5883 tmpcolour = specials[special_index].last_colour;
5884 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
5885 gradient_factor = (float)gradient_size / (w - 2);
5887 for (i = w - 2; i > -1; i--) {
5888 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5889 XSetForeground(display, window.gc, tmpcolour);
5890 gradient_update += gradient_factor;
5891 while (gradient_update > 0) {
5892 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
5896 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
5899 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 */
5901 if (specials[special_index].
5903 && specials[special_index].
5907 [special_index].height;
5909 /* if (draw_mode == BG) {
5910 set_foreground_color(default_bg_color);
5912 else if (draw_mode == OUTLINE) {
5913 set_foreground_color(default_out_color);
5915 set_foreground_color(default_fg_color);
5917 set_foreground_color(last_colour);
5923 int old = font_ascent();
5924 cur_y -= font_ascent();
5925 selected_font = specials[special_index].font_added;
5926 if (cur_y + font_ascent() < cur_y + old) {
5929 cur_y += font_ascent();
5935 if (draw_mode == FG)
5936 set_foreground_color(specials
5942 if (draw_mode == BG)
5943 set_foreground_color(specials
5949 if (draw_mode == OUTLINE)
5950 set_foreground_color(specials
5956 w += specials[special_index].arg;
5960 cur_y += specials[special_index].arg;
5964 if (specials[special_index].arg >= 0)
5965 cur_x = (int)specials[special_index].arg;
5970 int start = specials[special_index].arg;
5971 int step = specials[special_index].width;
5972 if (!step || step < 0)
5974 w = step - (cur_x - text_start_x - start) % step;
5980 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
5981 /*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);*/
5982 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
5983 cur_x = pos_x - specials[special_index].arg;
5990 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
5991 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
5992 /*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);*/
5994 specials[special_index].arg)
5997 [special_index].arg;
6014 if (cur_y_add > 0) {
6016 cur_y -= font_descent();
6021 cur_y += font_descent();
6025 static void draw_text()
6028 cur_y = text_start_y;
6031 if (draw_borders && border_width > 0) {
6032 unsigned int b = (border_width + 1) / 2;
6034 if (stippled_borders) {
6036 { stippled_borders, stippled_borders };
6037 XSetLineAttributes(display, window.gc,
6038 border_width, LineOnOffDash,
6039 CapButt, JoinMiter);
6040 XSetDashes(display, window.gc, 0, ss, 2);
6042 XSetLineAttributes(display, window.gc,
6043 border_width, LineSolid,
6044 CapButt, JoinMiter);
6047 XDrawRectangle(display, window.drawable, window.gc,
6048 text_start_x - border_margin + b,
6049 text_start_y - border_margin + b,
6050 text_width + border_margin * 2 - 1 - b * 2,
6051 text_height + border_margin * 2 - 1 -
6058 for_each_line(text_buffer, draw_line);
6061 static void draw_stuff()
6065 if (draw_shades && !draw_outline) {
6068 set_foreground_color(default_bg_color);
6078 for (i = -1; i < 2; i++)
6079 for (j = -1; j < 2; j++) {
6080 if (i == 0 && j == 0)
6084 set_foreground_color(default_out_color);
6085 draw_mode = OUTLINE;
6092 set_foreground_color(default_fg_color);
6100 swap.swap_window = window.window;
6101 swap.swap_action = XdbeBackground;
6102 XdbeSwapBuffers(display, &swap, 1);
6108 static void clear_text(int exposures)
6112 return; /* The swap action is XdbeBackground, which clears */
6116 /* there is some extra space for borders and outlines */
6117 XClearArea(display, window.window,
6118 text_start_x - border_margin - 1,
6119 text_start_y - border_margin - 1,
6120 text_width + border_margin * 2 + 2,
6121 text_height + border_margin * 2 + 2,
6122 exposures ? True : 0);
6127 static int need_to_update;
6129 /* update_text() generates new text and clears old text area */
6130 static void update_text()
6139 static void main_loop()
6141 #ifdef SIGNAL_BLOCKING
6142 sigset_t newmask, oldmask;
6144 sigemptyset(&newmask);
6145 sigaddset(&newmask,SIGINT);
6146 sigaddset(&newmask,SIGTERM);
6147 sigaddset(&newmask,SIGUSR1);
6151 Region region = XCreateRegion();
6153 int event_base, error_base;
6154 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
6155 ERR("Xdamage extension unavailable");
6157 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
6158 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
6159 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
6160 #endif /* HAVE_XDAMAGE */
6164 while (total_run_times == 0 || info.looped < total_run_times) {
6167 #ifdef SIGNAL_BLOCKING
6168 /* block signals. we will inspect for pending signals later */
6169 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
6170 CRIT_ERR("unable to sigprocmask()");
6176 /* wait for X event or timeout */
6178 if (!XPending(display)) {
6183 update_interval - (get_time() -
6189 tv.tv_sec = (long) t;
6190 tv.tv_usec = (long) (t * 1000000) % 1000000;
6192 FD_SET(ConnectionNumber(display), &fdsr);
6195 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
6198 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
6203 ERR("can't select(): %s",
6214 if (need_to_update) {
6216 int wx = window.x, wy = window.y;
6224 /* resize window if it isn't right size */
6226 (text_width + border_margin * 2 + 1 !=
6228 || text_height + border_margin * 2 + 1 !=
6232 border_margin * 2 + 1;
6235 border_margin * 2 + 1;
6236 XResizeWindow(display,
6241 set_transparent_background(window.window);
6245 /* move window if it isn't in right position */
6248 || window.y != wy)) {
6249 XMoveWindow(display, window.window,
6250 window.x, window.y);
6260 r.x = text_start_x - border_margin;
6261 r.y = text_start_y - border_margin;
6262 r.width = text_width + border_margin * 2;
6263 r.height = text_height + border_margin * 2;
6264 XUnionRectWithRegion(&r, region, region);
6269 /* handle X events */
6271 while (XPending(display)) {
6273 XNextEvent(display, &ev);
6280 r.width = ev.xexpose.width;
6281 r.height = ev.xexpose.height;
6282 XUnionRectWithRegion(&r, region,
6288 case ReparentNotify:
6289 /* set background to ParentRelative for all parents */
6291 set_transparent_background(window.
6296 case ConfigureNotify:
6298 /* if window size isn't what expected, set fixed size */
6299 if (ev.xconfigure.width !=
6301 || ev.xconfigure.height !=
6303 if (window.width != 0
6304 && window.height != 0)
6307 /* clear old stuff before screwing up size and pos */
6313 if (XGetWindowAttributes(display, window.window, &attrs)) {
6328 border_margin * 2 - 1;
6331 border_margin * 2 - 1;
6332 if (text_width > maximum_width && maximum_width > 0)
6333 text_width = maximum_width;
6336 /* if position isn't what expected, set fixed pos, total_updates
6337 * avoids setting fixed_pos when window is set to weird locations
6339 /*if (total_updates >= 2 this is broken
6341 && (window.x != ev.xconfigure.x
6344 && (ev.xconfigure.x != 0
6345 || ev.xconfigure.y != 0)) {
6355 /* if an ordinary window with decorations */
6356 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6358 /* allow conky to hold input focus.*/
6363 /* forward the click to the desktop window */
6364 XUngrabPointer(display, ev.xbutton.time);
6365 ev.xbutton.window = window.desktop;
6366 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6367 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6375 /* if an ordinary window with decorations */
6376 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6378 /* allow conky to hold input focus.*/
6383 /* forward the release to the desktop window */
6384 ev.xbutton.window = window.desktop;
6385 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6394 if (ev.type == event_base + XDamageNotify) {
6395 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6396 XFixesSetRegion(display, part, &dev->area, 1);
6397 XFixesUnionRegion(display, region2, region2, part);
6399 #endif /* HAVE_XDAMAGE */
6404 XDamageSubtract(display, damage, region2, None);
6405 XFixesSetRegion(display, region2, 0, 0);
6406 #endif /* HAVE_XDAMAGE */
6408 /* XDBE doesn't seem to provide a way to clear the back buffer without
6409 * interfering with the front buffer, other than passing XdbeBackground
6410 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6411 * redraw the text even if it wasn't part of the exposed area. OTOH,
6412 * if we're not going to call draw_stuff at all, then no swap happens
6413 * and we can safely do nothing.
6416 if (!XEmptyRegion(region)) {
6420 r.x = text_start_x - border_margin;
6421 r.y = text_start_y - border_margin;
6422 r.width = text_width + border_margin * 2;
6423 r.height = text_height + border_margin * 2;
6424 XUnionRectWithRegion(&r, region, region);
6427 XSetRegion(display, window.gc, region);
6430 XftDrawSetClip(window.xftdraw, region);
6436 XDestroyRegion(region);
6437 region = XCreateRegion();
6441 #ifdef SIGNAL_BLOCKING
6442 /* unblock signals of interest and let handler fly */
6443 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6444 CRIT_ERR("unable to sigprocmask()");
6447 switch(g_signal_pending) {
6450 ERR("received SIGUSR1. reloading the config file.");
6457 ERR("received SIGINT or SIGTERM to terminate. bye!");
6460 XDestroyRegion(region);
6463 return; /* return from main_loop */
6468 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6469 * but didn't write any code to deal with it. if you don't want to
6470 * handle a signal, don't set a handler on it in the first place. */
6471 if (g_signal_pending)
6472 ERR("ignoring signal (%d)", g_signal_pending);
6479 #if defined(X11) && defined(HAVE_XDAMAGE)
6480 XDamageDestroy(display, damage);
6481 XFixesDestroyRegion(display, region2);
6482 XFixesDestroyRegion(display, part);
6483 XDestroyRegion(region);
6485 #endif /* X11 && HAVE_XDAMAGE */
6488 static void load_config_file(const char *);
6490 /* reload the config file */
6491 void reload_config(void)
6493 timed_thread_destroy_registered_threads ();
6495 if (info.cpu_usage) {
6496 free(info.cpu_usage);
6497 info.cpu_usage = NULL;
6500 #ifdef TCP_PORT_MONITOR
6501 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6504 if (current_config) {
6506 load_config_file(current_config);
6508 /* re-init specials array */
6509 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6510 ERR("failed to realloc specials array");
6515 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6518 #ifdef TCP_PORT_MONITOR
6519 info.p_tcp_port_monitor_collection = NULL;
6522 if (create_audacious_thread() !=0)
6523 CRIT_ERR("unable to create audacious thread!");
6524 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6526 extract_variable_text(text);
6535 timed_thread_destroy_registered_threads ();
6537 if (info.cpu_usage) {
6538 free(info.cpu_usage);
6539 info.cpu_usage = NULL;
6544 XdbeDeallocateBackBufferName(display, window.back_buffer);
6550 XDestroyWindow(display, window.window);
6551 XClearWindow(display, RootWindow(display, screen));
6557 XClearWindow(display, RootWindow(display, screen));
6562 XFreeGC(display, window.gc);
6565 free_text_objects(text_object_count, text_objects);
6566 text_object_count = 0;
6567 text_objects = NULL;
6569 if (text != original_text)
6572 free(current_config);
6573 free(current_mail_spool);
6575 #ifdef TCP_PORT_MONITOR
6576 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6577 info.p_tcp_port_monitor_collection = NULL;
6585 for(i=0;i<special_count;i++)
6586 if(specials[i].type == GRAPH)
6587 free(specials[i].graph);
6593 static int string_to_bool(const char *s)
6597 if (strcasecmp(s, "yes") == 0)
6599 if (strcasecmp(s, "true") == 0)
6601 if (strcasecmp(s, "1") == 0)
6606 static enum alignment string_to_alignment(const char *s)
6608 if (strcasecmp(s, "top_left") == 0)
6610 else if (strcasecmp(s, "top_right") == 0)
6612 else if (strcasecmp(s, "bottom_left") == 0)
6614 else if (strcasecmp(s, "bottom_right") == 0)
6615 return BOTTOM_RIGHT;
6616 else if (strcasecmp(s, "tl") == 0)
6618 else if (strcasecmp(s, "tr") == 0)
6620 else if (strcasecmp(s, "bl") == 0)
6622 else if (strcasecmp(s, "br") == 0)
6623 return BOTTOM_RIGHT;
6624 else if (strcasecmp(s, "none") == 0)
6631 static void set_default_configurations(void)
6633 fork_to_background = 0;
6634 total_run_times = 0;
6635 info.cpu_avg_samples = 2;
6636 info.net_avg_samples = 2;
6641 strcpy(info.mpd.host, "localhost");
6642 info.mpd.port = 6600;
6643 info.mpd.status = NULL;
6644 info.mpd.artist = NULL;
6645 info.mpd.album = NULL;
6646 info.mpd.title = NULL;
6647 info.mpd.random = NULL;
6648 info.mpd.track = NULL;
6649 info.mpd.name = NULL;
6650 info.mpd.file = NULL;
6653 info.xmms2.artist = NULL;
6654 info.xmms2.album = NULL;
6655 info.xmms2.title = NULL;
6656 info.xmms2.genre = NULL;
6657 info.xmms2.comment = NULL;
6658 info.xmms2.decoder = NULL;
6659 info.xmms2.transport = NULL;
6660 info.xmms2.url = NULL;
6661 info.xmms2.status = NULL;
6664 #if defined(__linux__)
6666 #endif /* __linux__ */
6673 default_fg_color = WhitePixel(display, screen);
6674 default_bg_color = BlackPixel(display, screen);
6675 default_out_color = BlackPixel(display, screen);
6676 color0 = default_fg_color;
6677 color1 = default_fg_color;
6678 color2 = default_fg_color;
6679 color3 = default_fg_color;
6680 color4 = default_fg_color;
6681 color5 = default_fg_color;
6682 color6 = default_fg_color;
6683 color7 = default_fg_color;
6684 color8 = default_fg_color;
6685 color9 = default_fg_color;
6688 draw_graph_borders = 1;
6690 set_first_font("6x10");
6698 window.type=TYPE_NORMAL;
6700 strcpy(window.class_name, "Conky");
6702 sprintf(window.title,"%s - conky",info.uname_s.nodename);
6704 stippled_borders = 0;
6707 text_alignment = BOTTOM_LEFT;
6710 free(current_mail_spool);
6713 variable_substitute(MAIL_FILE, buf, 256);
6715 current_mail_spool = strdup(buf);
6719 update_interval = 10.0;
6720 stuff_in_upper_case = 0;
6722 #ifdef TCP_PORT_MONITOR
6723 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6727 static void load_config_file(const char *f)
6729 #define CONF_ERR ERR("%s: %d: config file error", f, line)
6733 set_default_configurations();
6739 char buf[256], *p, *p2, *name, *value;
6741 if (fgets(buf, 256, fp) == NULL)
6746 /* break at comment */
6747 p2 = strchr(p, '#');
6752 while (*p && isspace((int) *p))
6755 continue; /* empty line */
6761 while (*p2 && !isspace((int) *p2))
6764 *p2 = '\0'; /* break at name's end */
6771 while (*p && isspace((int) *p))
6776 p2 = value + strlen(value);
6777 while (isspace((int) *(p2 - 1)))
6783 #define CONF2(a) if (strcasecmp(name, a) == 0)
6784 #define CONF(a) else CONF2(a)
6785 #define CONF3(a,b) \
6786 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
6790 CONF2("alignment") {
6792 int a = string_to_alignment(value);
6800 CONF("background") {
6801 fork_to_background = string_to_bool(value);
6805 CONF2("background") {
6806 fork_to_background = string_to_bool(value);
6810 CONF("border_margin") {
6812 border_margin = strtol(value, 0, 0);
6816 CONF("border_width") {
6818 border_width = strtol(value, 0, 0);
6824 color0 = get_x11_color(value);
6830 color1 = get_x11_color(value);
6836 color2 = get_x11_color(value);
6842 color3 = get_x11_color(value);
6848 color4 = get_x11_color(value);
6854 color5 = get_x11_color(value);
6860 color6 = get_x11_color(value);
6866 color7 = get_x11_color(value);
6872 color8 = get_x11_color(value);
6878 color9 = get_x11_color(value);
6882 CONF("default_color") {
6884 default_fg_color = get_x11_color(value);
6888 CONF3("default_shade_color", "default_shadecolor") {
6890 default_bg_color = get_x11_color(value);
6894 CONF3("default_outline_color", "default_outlinecolor") {
6896 default_out_color = get_x11_color(value);
6903 info.mail = parse_mail_args(IMAP, value);
6910 info.mail = parse_mail_args(POP3, value);
6918 strncpy(info.mpd.host, value, 127);
6924 info.mpd.port = strtol(value, 0, 0);
6925 if (info.mpd.port < 1
6926 || info.mpd.port > 0xffff)
6930 CONF("mpd_password") {
6932 strncpy(info.mpd.password, value, 127);
6938 CONF("sensor_device") {
6940 sensor_device = strtol(value, 0, 0);
6945 CONF("cpu_avg_samples") {
6947 cpu_avg_samples = strtol(value, 0, 0);
6948 if (cpu_avg_samples < 1
6949 || cpu_avg_samples > 14)
6958 CONF("net_avg_samples") {
6960 net_avg_samples = strtol(value, 0, 0);
6961 if (net_avg_samples < 1
6962 || net_avg_samples > 14)
6978 CONF("double_buffer") {
6979 use_xdbe = string_to_bool(value);
6983 CONF("override_utf8_locale") {
6984 utf8_mode = string_to_bool(value);
6987 CONF("draw_borders") {
6988 draw_borders = string_to_bool(value);
6990 CONF("draw_graph_borders") {
6991 draw_graph_borders = string_to_bool(value);
6993 CONF("draw_shades") {
6994 draw_shades = string_to_bool(value);
6996 CONF("draw_outline") {
6997 draw_outline = string_to_bool(value);
6999 #if defined(__linux__)
7000 CONF("post_21_kernel") {
7001 post_21_kernel = string_to_bool(value);
7003 #endif /* __linux__ */
7005 CONF("out_to_console") {
7006 out_to_console = string_to_bool(value);
7008 CONF("use_spacer") {
7009 use_spacer = string_to_bool(value);
7014 use_xft = string_to_bool(value);
7018 set_first_font(value);
7023 if (value && font_count >= 0)
7024 fonts[0].font_alpha = atof(value)
7033 if (string_to_bool(value))
7034 ERR("Xft not enabled");
7037 /* xftfont silently ignored when no Xft */
7040 /* xftalpha is silently ignored when no Xft */
7045 set_first_font(value);
7054 gap_x = atoi(value);
7060 gap_y = atoi(value);
7065 CONF("mail_spool") {
7068 variable_substitute(value, buf, 256);
7072 if (current_mail_spool)
7073 free(current_mail_spool);
7074 current_mail_spool = strdup(buf);
7080 CONF("minimum_size") {
7083 (value, "%d %d", &minimum_width,
7084 &minimum_height) != 2)
7087 &minimum_width) != 1)
7092 CONF("maximum_width") {
7094 if (sscanf(value, "%d", &maximum_width) != 1)
7100 CONF("no_buffers") {
7101 no_buffers = string_to_bool(value);
7103 CONF("pad_percents") {
7104 pad_percents = atoi(value);
7108 CONF("own_window") {
7110 own_window = string_to_bool(value);
7114 CONF("own_window_class") {
7117 memset(window.class_name,0,sizeof(window.class_name));
7118 strncpy(window.class_name, value, sizeof(window.class_name)-1);
7123 CONF("own_window_title") {
7126 memset(window.title,0,sizeof(window.title));
7127 strncpy(window.title, value, sizeof(window.title)-1);
7132 CONF("own_window_transparent") {
7134 set_transparent = string_to_bool(value);
7138 CONF("own_window_colour") {
7140 background_colour = get_x11_color(value);
7142 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
7145 CONF("own_window_hints") {
7147 char *p_hint, *p_save;
7148 char delim[] = ", ";
7150 /* tokenize the value into individual hints */
7151 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
7153 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
7154 if (strncmp(p_hint,"undecorate",10) == 0)
7155 SET_HINT(window.hints,HINT_UNDECORATED);
7156 else if (strncmp(p_hint,"below",5) == 0)
7157 SET_HINT(window.hints,HINT_BELOW);
7158 else if (strncmp(p_hint,"above",5) == 0)
7159 SET_HINT(window.hints,HINT_ABOVE);
7160 else if (strncmp(p_hint,"sticky",6) == 0)
7161 SET_HINT(window.hints,HINT_STICKY);
7162 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
7163 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
7164 else if (strncmp(p_hint,"skip_pager",10) == 0)
7165 SET_HINT(window.hints,HINT_SKIP_PAGER);
7169 p_hint=strtok_r(NULL, delim, &p_save);
7171 while (p_hint!=NULL);
7176 CONF("own_window_type") {
7178 if (strncmp(value,"normal",6)==0)
7179 window.type = TYPE_NORMAL;
7180 else if (strncmp(value,"desktop",7)==0)
7181 window.type = TYPE_DESKTOP;
7182 else if (strncmp(value,"override",8)==0)
7183 window.type = TYPE_OVERRIDE;
7191 CONF("stippled_borders") {
7193 stippled_borders = strtol(value, 0, 0);
7195 stippled_borders = 4;
7199 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
7202 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
7204 CONF("update_interval") {
7206 update_interval = strtod(value, 0);
7210 CONF("total_run_times") {
7212 total_run_times = strtod(value, 0);
7217 stuff_in_upper_case = string_to_bool(value);
7219 CONF("max_specials") {
7221 max_specials = atoi(value);
7225 CONF("max_user_text") {
7227 max_user_text = atoi(value);
7231 CONF("text_buffer_size") {
7233 text_buffer_size = atoi(value);
7238 if (text != original_text)
7248 int l = strlen(text);
7249 if (fgets(buf, 256, fp) == NULL)
7252 realloc(text, l + strlen(buf)
7256 if (strlen(text) > max_user_text)
7260 text_lines = line + 1;
7263 #ifdef TCP_PORT_MONITOR
7264 CONF("max_port_monitor_connections")
7267 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7268 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
7270 /* an error. use default, warn and continue. */
7271 tcp_port_monitor_args.max_port_monitor_connections =
7272 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7275 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
7277 /* no error, just use default */
7278 tcp_port_monitor_args.max_port_monitor_connections =
7279 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7281 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
7286 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7298 /* : means that character before that takes an argument */
7299 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
7312 int main(int argc, char **argv)
7314 struct sigaction act, oact;
7317 memset(&info, 0, sizeof(info) );
7319 #ifdef TCP_PORT_MONITOR
7320 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7323 /* handle command line parameters that don't change configs */
7328 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7329 *s) || ((s = getenv("LANG")) && *s)) {
7330 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7332 ERR("malloc failed");
7334 for (x = 0; x < strlen(s); x++) {
7335 temp[x] = tolower(s[x]);
7338 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7344 if (!setlocale(LC_CTYPE, "")) {
7345 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7349 int c = getopt(argc,
7360 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
7361 * though free() does the NULL check itself;), then load optarg value */
7363 free(current_config);
7364 current_config = strdup(optarg);
7369 ("Usage: %s [OPTION]...\n"
7370 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7371 "window. Command line options will override configurations defined in config\n"
7374 " -c FILE config file to load instead of "
7377 " -d daemonize, fork to background\n"
7380 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7381 " -f FONT font to use\n"
7383 " -o create own window to draw\n"
7386 " -b double buffer (prevents flickering)\n"
7388 " -w WIN_ID window id to draw\n"
7389 " -x X x position\n"
7390 " -y Y y position\n"
7392 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
7393 " -u SECS update interval\n"
7394 " -i NUM number of times to update Conky\n", argv[0]);
7398 window.window = strtol(optarg, 0, 0);
7407 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7411 /* load current_config or CONFIG_FILE */
7414 if (current_config == NULL) {
7415 /* load default config file */
7418 variable_substitute(CONFIG_FILE, buf, 256);
7421 current_config = strdup(buf);
7425 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
7426 load_config_file(current_config);
7428 set_default_configurations();
7431 /* init specials array */
7432 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7433 ERR("failed to create specials array");
7436 if (current_mail_spool == NULL) {
7438 variable_substitute(MAIL_FILE, buf, 256);
7441 current_mail_spool = strdup(buf);
7445 /* handle other command line arguments */
7447 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
7448 optind = optreset = 1;
7453 #if defined(__FreeBSD__)
7454 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7455 O_RDONLY, "kvm_open")) == NULL)
7456 CRIT_ERR( "cannot read kvm");
7460 int c = getopt(argc,
7468 fork_to_background = 1;
7473 set_first_font(optarg);
7476 text_alignment = string_to_alignment(optarg);
7491 if (text != original_text)
7493 text = strdup(optarg);
7494 convert_escapes(text);
7498 update_interval = strtod(optarg, 0);
7502 total_run_times = strtod(optarg, 0);
7506 gap_x = atoi(optarg);
7510 gap_y = atoi(optarg);
7524 /* generate text and get initial size */
7525 extract_variable_text(text);
7526 if (text != original_text) {
7531 if (fork_to_background) {
7535 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
7541 fprintf(stderr,"\n"); fflush(stderr);
7545 /* parent process */
7546 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
7553 update_text_area(); /* to get initial size of the window */
7557 text_width + border_margin * 2 + 1,
7558 text_height + border_margin * 2 + 1,
7559 set_transparent, background_colour, argv, argc);
7562 update_text_area(); /* to position text/window on screen */
7567 if (own_window && !fixed_pos) {
7568 XMoveWindow(display, window.window, window.x, window.y);
7571 set_transparent_background(window.window);
7582 /* Set signal handlers */
7583 act.sa_handler = signal_handler;
7584 sigemptyset(&act.sa_mask);
7587 act.sa_flags |= SA_RESTART;
7590 if ( sigaction(SIGINT,&act,&oact) < 0 ||
7591 sigaction(SIGUSR1,&act,&oact) < 0 ||
7592 sigaction(SIGTERM,&act,&oact) < 0 )
7594 ERR("error setting signal handler: %s", strerror(errno) );
7598 if (create_audacious_thread() !=0)
7599 CRIT_ERR("unable to create audacious thread!");
7600 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
7611 #if defined(__FreeBSD__)
7618 void signal_handler(int sig)
7620 /* signal handler is light as a feather, as it should be.
7621 * we will poll g_signal_pending with each loop of conky
7622 * and do any signal processing there, NOT here. */
7623 g_signal_pending=sig;