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,
1004 #endif /* __linux__ */
1033 OBJ_running_processes,
1042 OBJ_temp1, /* i2c is used instead in these */
1062 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1064 OBJ_apm_battery_time,
1065 OBJ_apm_battery_life,
1066 #endif /* __FreeBSD__ __OpenBSD__ */
1068 OBJ_obsd_sensors_temp,
1069 OBJ_obsd_sensors_fan,
1070 OBJ_obsd_sensors_volt,
1073 #endif /* __OpenBSD__ */
1102 OBJ_xmms2_transport,
1117 OBJ_audacious_status,
1118 OBJ_audacious_title,
1119 OBJ_audacious_length,
1120 OBJ_audacious_length_seconds,
1121 OBJ_audacious_position,
1122 OBJ_audacious_position_seconds,
1123 OBJ_audacious_bitrate,
1124 OBJ_audacious_frequency,
1125 OBJ_audacious_channels,
1126 OBJ_audacious_filename,
1127 OBJ_audacious_playlist_length,
1128 OBJ_audacious_playlist_position,
1142 #ifdef TCP_PORT_MONITOR
1153 OBJ_entropy_poolsize,
1157 struct text_object {
1161 unsigned int c, d, e;
1165 char *s; /* some string */
1166 int i; /* some integer */
1167 long l; /* some other integer */
1168 unsigned int sensor;
1169 struct net_stat *net;
1171 unsigned char loadavg[3];
1172 unsigned int cpu_index;
1173 struct mail_s *mail;
1181 char *tz; /* timezone variable */
1182 char *fmt; /* time display formatting */
1235 timed_thread *p_timed_thread;
1241 #ifdef TCP_PORT_MONITOR
1243 in_port_t port_range_begin; /* starting port to monitor */
1244 in_port_t port_range_end; /* ending port to monitor */
1245 int item; /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1246 int connection_index; /* 0 to n-1 connections. */
1267 struct text_object_list {
1268 unsigned int text_object_count;
1269 struct text_object *text_objects;
1272 static unsigned int text_object_count;
1273 static struct text_object *text_objects;
1274 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1276 #define MAXDATASIZE 1000
1280 struct mail_s* parse_mail_args(char type, const char *arg) {
1281 struct mail_s *mail;
1282 mail = malloc(sizeof(struct mail_s));
1283 memset(mail, 0, sizeof(struct mail_s));
1285 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1287 ERR("Scanning IMAP args failed");
1288 } else if (type == IMAP) {
1289 ERR("Scanning POP3 args failed");
1292 // see if password needs prompting
1293 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1294 int fp = fileno(stdin);
1295 struct termios term;
1296 tcgetattr(fp, &term);
1297 term.c_lflag &= ~ECHO;
1298 tcsetattr(fp, TCSANOW, &term);
1299 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1300 scanf("%128s", mail->pass);
1302 term.c_lflag |= ECHO;
1303 tcsetattr(fp, TCSANOW, &term);
1305 // now we check for optional args
1306 tmp = strstr(arg, "-i ");
1309 sscanf(tmp, "%f", &mail->interval);
1311 mail->interval = 300; // 5 minutes
1313 tmp = strstr(arg, "-p ");
1316 sscanf(tmp, "%lu", &mail->port);
1319 mail->port = 110; // default pop3 port
1320 } else if (type == IMAP) {
1321 mail->port = 143; // default imap port
1325 tmp = strstr(arg, "-f ");
1328 sscanf(tmp, "%s", mail->folder);
1330 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1333 tmp = strstr(arg, "-e ");
1337 if (tmp[0] == '\'') {
1338 len = strstr(tmp+1, "'") - tmp - 1;
1343 strncpy(mail->command, tmp+1, len);
1345 mail->command[0] = '\0';
1347 mail->p_timed_thread = NULL;
1351 void *imap_thread(struct mail_s* mail)
1353 int sockfd, numbytes;
1354 char recvbuf[MAXDATASIZE];
1355 char sendbuf[MAXDATASIZE];
1358 unsigned int old_unseen = UINT_MAX;
1359 unsigned int old_messages = UINT_MAX;
1360 struct stat stat_buf;
1362 struct sockaddr_in their_addr; // connector's address information
1363 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1364 herror("gethostbyname");
1369 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1371 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1374 goto next_iteration;
1377 their_addr.sin_family = AF_INET; // host byte order
1378 their_addr.sin_port = htons(mail->port); // short, network byte order
1379 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1380 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1383 (sockfd, (struct sockaddr *) &their_addr,
1384 sizeof(struct sockaddr)) == -1) {
1387 goto next_iteration;
1389 struct timeval timeout;
1392 timeout.tv_sec = 60; // 60 second timeout i guess
1393 timeout.tv_usec = 0;
1395 FD_SET(sockfd, &fdset);
1396 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1399 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1403 goto next_iteration;
1406 ERR("IMAP connection failed: timeout");
1408 goto next_iteration;
1410 recvbuf[numbytes] = '\0';
1411 if (strstr(recvbuf, "* OK") != recvbuf) {
1412 ERR("IMAP connection failed, probably not an IMAP server");
1414 goto next_iteration;
1416 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1417 strncat(sendbuf, mail->user,
1418 MAXDATASIZE - strlen(sendbuf) - 1);
1419 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1420 strncat(sendbuf, mail->pass,
1421 MAXDATASIZE - strlen(sendbuf) - 1);
1422 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1423 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1426 goto next_iteration;
1428 timeout.tv_sec = 60; // 60 second timeout i guess
1429 timeout.tv_usec = 0;
1431 FD_SET(sockfd, &fdset);
1432 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1435 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1439 goto next_iteration;
1442 recvbuf[numbytes] = '\0';
1443 if (strstr(recvbuf, "a1 OK") == NULL) {
1444 ERR("IMAP server login failed: %s", recvbuf);
1446 goto next_iteration;
1448 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1449 strncat(sendbuf, mail->folder,
1450 MAXDATASIZE - strlen(sendbuf) - 1);
1451 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1452 MAXDATASIZE - strlen(sendbuf) - 1);
1453 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1456 goto next_iteration;
1458 timeout.tv_sec = 60; // 60 second timeout i guess
1459 timeout.tv_usec = 0;
1461 FD_SET(sockfd, &fdset);
1462 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1465 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1469 goto next_iteration;
1472 recvbuf[numbytes] = '\0';
1473 if (strstr(recvbuf, "a2 OK") == NULL) {
1474 ERR("IMAP status failed: %s", recvbuf);
1476 goto next_iteration;
1478 // now we get the data
1479 reply = strstr(recvbuf, " (MESSAGES ");
1481 *strchr(reply, ')') = '\0';
1482 if (reply == NULL) {
1483 ERR("Error parsing IMAP response: %s", recvbuf);
1485 goto next_iteration;
1487 timed_thread_lock (mail->p_timed_thread);
1488 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1491 timed_thread_unlock (mail->p_timed_thread);
1493 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1494 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1497 goto next_iteration;
1499 timeout.tv_sec = 60; // 60 second timeout i guess
1500 timeout.tv_usec = 0;
1502 FD_SET(sockfd, &fdset);
1503 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1506 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1510 goto next_iteration;
1513 recvbuf[numbytes] = '\0';
1514 if (strstr(recvbuf, "a3 OK") == NULL) {
1515 ERR("IMAP logout failed: %s", recvbuf);
1517 goto next_iteration;
1519 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1520 if (system(mail->command) == -1) {
1525 old_unseen = mail->unseen;
1526 old_messages = mail->messages;
1528 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1529 /* if a valid socket, close it */
1531 if (timed_thread_test (mail->p_timed_thread))
1532 timed_thread_exit (mail->p_timed_thread);
1537 void *pop3_thread(struct mail_s *mail)
1539 int sockfd, numbytes;
1540 char recvbuf[MAXDATASIZE];
1541 char sendbuf[MAXDATASIZE];
1544 unsigned int old_unseen = UINT_MAX;
1545 struct stat stat_buf;
1547 struct sockaddr_in their_addr; // connector's address information
1548 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1549 herror("gethostbyname");
1554 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1556 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1559 goto next_iteration;
1562 their_addr.sin_family = AF_INET; // host byte order
1563 their_addr.sin_port = htons(mail->port); // short, network byte order
1564 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1565 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1568 (sockfd, (struct sockaddr *) &their_addr,
1569 sizeof(struct sockaddr)) == -1) {
1572 goto next_iteration;
1574 struct timeval timeout;
1577 timeout.tv_sec = 60; // 60 second timeout i guess
1578 timeout.tv_usec = 0;
1580 FD_SET(sockfd, &fdset);
1581 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1584 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1588 goto next_iteration;
1591 ERR("POP3 connection failed: timeout\n");
1593 goto next_iteration;
1595 recvbuf[numbytes] = '\0';
1596 if (strstr(recvbuf, "+OK ") != recvbuf) {
1597 ERR("POP3 connection failed, probably not a POP3 server");
1599 goto next_iteration;
1601 strncpy(sendbuf, "USER ", MAXDATASIZE);
1602 strncat(sendbuf, mail->user,
1603 MAXDATASIZE - strlen(sendbuf) - 1);
1604 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1605 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1606 perror("send USER");
1608 goto next_iteration;
1610 timeout.tv_sec = 60; // 60 second timeout i guess
1611 timeout.tv_usec = 0;
1613 FD_SET(sockfd, &fdset);
1614 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1617 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1619 perror("recv USER");
1621 goto next_iteration;
1624 recvbuf[numbytes] = '\0';
1625 if (strstr(recvbuf, "+OK ") == NULL) {
1626 ERR("POP3 server login failed: %s", recvbuf);
1628 goto next_iteration;
1630 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1631 strncat(sendbuf, mail->pass,
1632 MAXDATASIZE - strlen(sendbuf) - 1);
1633 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1634 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1635 perror("send PASS");
1637 goto next_iteration;
1639 timeout.tv_sec = 60; // 60 second timeout i guess
1640 timeout.tv_usec = 0;
1642 FD_SET(sockfd, &fdset);
1643 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1646 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1648 perror("recv PASS");
1650 goto next_iteration;
1653 recvbuf[numbytes] = '\0';
1654 if (strstr(recvbuf, "+OK ") == NULL) {
1655 ERR("POP3 server login failed: %s", recvbuf);
1657 goto next_iteration;
1659 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1660 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1661 perror("send STAT");
1663 goto next_iteration;
1665 timeout.tv_sec = 60; // 60 second timeout i guess
1666 timeout.tv_usec = 0;
1668 FD_SET(sockfd, &fdset);
1669 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1672 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1674 perror("recv STAT");
1676 goto next_iteration;
1679 recvbuf[numbytes] = '\0';
1680 if (strstr(recvbuf, "+OK ") == NULL) {
1681 ERR("POP3 status failed: %s", recvbuf);
1683 goto next_iteration;
1685 // now we get the data
1686 reply = recvbuf + 4;
1687 if (reply == NULL) {
1688 ERR("Error parsing POP3 response: %s", recvbuf);
1690 goto next_iteration;
1692 timed_thread_lock (mail->p_timed_thread);
1693 sscanf(reply, "%lu %lu", &mail->unseen,
1695 timed_thread_unlock (mail->p_timed_thread);
1697 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1698 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1699 perror("send QUIT");
1701 goto next_iteration;
1703 timeout.tv_sec = 60; // 60 second timeout i guess
1704 timeout.tv_usec = 0;
1706 FD_SET(sockfd, &fdset);
1707 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1710 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1712 perror("recv QUIT");
1714 goto next_iteration;
1717 recvbuf[numbytes] = '\0';
1718 if (strstr(recvbuf, "+OK") == NULL) {
1719 ERR("POP3 logout failed: %s", recvbuf);
1721 goto next_iteration;
1723 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1724 if (system(mail->command) == -1) {
1729 old_unseen = mail->unseen;
1731 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1732 /* if a valid socket, close it */
1734 if (timed_thread_test (mail->p_timed_thread))
1735 timed_thread_exit (mail->p_timed_thread);
1741 void *threaded_exec(struct text_object *obj) {
1743 char *p2 = obj->data.texeci.buffer;
1744 FILE *fp = popen(obj->data.texeci.cmd,"r");
1745 timed_thread_lock (obj->data.texeci.p_timed_thread);
1746 int n2 = fread(p2, 1, text_buffer_size, fp);
1749 if (n2 && p2[n2 - 1] == '\n') {
1753 if (*p2 == '\001') {
1758 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1759 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1760 timed_thread_exit (obj->data.texeci.p_timed_thread);
1765 static struct text_object *new_text_object_internal()
1767 struct text_object *obj = malloc(sizeof(struct text_object));
1768 memset(obj, 0, sizeof(struct text_object));
1772 static void free_text_objects(unsigned int count, struct text_object *objs)
1775 for (i = 0; i < count; i++) {
1776 switch (objs[i].type) {
1778 close(objs[i].data.i);
1781 close(objs[i].data.i);
1784 close(objs[i].data.i2c.fd);
1787 free(objs[i].data.s);
1790 free(objs[i].data.s);
1793 free(objs[i].data.tztime.tz);
1794 free(objs[i].data.tztime.fmt);
1797 free(objs[i].data.mboxscan.args);
1798 free(objs[i].data.mboxscan.output);
1803 case OBJ_imap_unseen:
1804 if (!objs[i].global_mode) {
1805 free(objs[i].data.mail);
1808 case OBJ_imap_messages:
1809 if (!objs[i].global_mode) {
1810 free(objs[i].data.mail);
1816 case OBJ_pop3_unseen:
1817 if (!objs[i].global_mode) {
1818 free(objs[i].data.mail);
1822 if (!objs[i].global_mode) {
1823 free(objs[i].data.mail);
1827 case OBJ_if_existing:
1828 case OBJ_if_mounted:
1829 case OBJ_if_running:
1830 free(objs[i].data.ifblock.s);
1831 free(objs[i].data.ifblock.str);
1834 free(objs[i].data.tail.logfile);
1835 free(objs[i].data.tail.buffer);
1839 free(objs[i].data.s);
1842 free(objs[i].data.s);
1845 free(objs[i].data.s);
1848 free(objs[i].data.s);
1851 free(objs[i].data.s);
1853 /* case OBJ_execibar:
1854 free(objs[i].data.s);
1856 case OBJ_execigraph:
1857 free(objs[i].data.s);
1860 case OBJ_iconv_start:
1866 if (info.mpd.title) {
1867 free(info.mpd.title);
1871 case OBJ_mpd_artist:
1872 if (info.mpd.artist) {
1873 free(info.mpd.artist);
1874 info.mpd.artist = 0;
1878 if (info.mpd.album) {
1879 free(info.mpd.album);
1883 case OBJ_mpd_random:
1884 if (info.mpd.random) {
1885 free(info.mpd.random);
1886 info.mpd.random = 0;
1889 case OBJ_mpd_repeat:
1890 if (info.mpd.repeat) {
1891 free(info.mpd.repeat);
1892 info.mpd.repeat = 0;
1896 if (info.mpd.track) {
1897 free(info.mpd.track);
1902 if (info.mpd.name) {
1903 free(info.mpd.name);
1908 if (info.mpd.file) {
1909 free(info.mpd.file);
1913 case OBJ_mpd_status:
1914 if (info.mpd.status) {
1915 free(info.mpd.status);
1916 info.mpd.status = 0;
1920 if (info.mpd.artist) {
1921 free(info.mpd.artist);
1922 info.mpd.artist = 0;
1924 if (info.mpd.title) {
1925 free(info.mpd.title);
1928 if (info.mpd.file) {
1929 free(info.mpd.file);
1936 case OBJ_xmms2_artist:
1937 if (info.xmms2.artist) {
1938 free(info.xmms2.artist);
1939 info.xmms2.artist = 0;
1942 case OBJ_xmms2_album:
1943 if (info.xmms2.album) {
1944 free(info.xmms2.album);
1945 info.xmms2.album = 0;
1948 case OBJ_xmms2_title:
1949 if (info.xmms2.title) {
1950 free(info.xmms2.title);
1951 info.xmms2.title = 0;
1954 case OBJ_xmms2_genre:
1955 if (info.xmms2.genre) {
1956 free(info.xmms2.genre);
1957 info.xmms2.genre = 0;
1960 case OBJ_xmms2_comment:
1961 if (info.xmms2.comment) {
1962 free(info.xmms2.comment);
1963 info.xmms2.comment = 0;
1966 case OBJ_xmms2_decoder:
1967 if (info.xmms2.decoder) {
1968 free(info.xmms2.decoder);
1972 case OBJ_xmms2_transport:
1973 if (info.xmms2.transport) {
1974 free(info.xmms2.transport);
1979 if (info.xmms2.url) {
1980 free(info.xmms2.url);
1984 case OBJ_xmms2_date:
1985 if (info.xmms2.date) {
1986 free(info.xmms2.date);
1987 info.xmms2.date = 0;
1990 case OBJ_xmms2_status:
1991 if (info.xmms2.status) {
1992 free(info.xmms2.status);
1993 info.xmms2.status = 0;
1996 case OBJ_xmms2_smart:
1997 if (info.xmms2.artist) {
1998 free(info.xmms2.artist);
1999 info.xmms2.artist = 0;
2001 if (info.xmms2.title) {
2002 free(info.xmms2.title);
2003 info.xmms2.title = 0;
2005 if (info.xmms2.url) {
2006 free(info.xmms2.url);
2012 case OBJ_bmpx_title:
2013 case OBJ_bmpx_artist:
2014 case OBJ_bmpx_album:
2015 case OBJ_bmpx_track:
2017 case OBJ_bmpx_bitrate:
2021 free(objs[i].data.rss.uri);
2022 free(objs[i].data.rss.action);
2027 free(objs[i].data.s);
2029 case OBJ_battery_time:
2030 free(objs[i].data.s);
2033 free(objs[i].data.execi.cmd);
2034 free(objs[i].data.execi.buffer);
2037 free(objs[i].data.texeci.cmd);
2038 free(objs[i].data.texeci.buffer);
2041 if (info.first_process) {
2042 free_all_processes();
2043 info.first_process = NULL;
2047 if (info.first_process) {
2048 free_all_processes();
2049 info.first_process = NULL;
2054 free(objs[i].data.hddtemp.dev);
2055 free(objs[i].data.hddtemp.addr);
2058 case OBJ_entropy_avail:
2059 case OBJ_entropy_poolsize:
2060 case OBJ_entropy_bar:
2065 //text_objects = NULL;
2066 //text_object_count = 0;
2069 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2074 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2075 *a = mixer_init(buf1);
2076 (void) scan_bar(arg + n, w, h);
2079 (void) scan_bar(arg, w, h);
2084 /* construct_text_object() creates a new text_object */
2085 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2087 //struct text_object *obj = new_text_object();
2088 struct text_object *obj = new_text_object_internal();
2091 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2092 #define END ; } } else
2096 obj->type = OBJ_color;
2097 obj->data.l = get_x11_color(s);
2100 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2101 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2102 END OBJ(acpiacadapter, 0)
2103 END OBJ(freq, INFO_FREQ)
2109 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2111 obj->data.cpu_index=1;
2112 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2116 obj->data.cpu_index=atoi(&arg[0]);
2119 END OBJ(freq_g, INFO_FREQ)
2125 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2127 obj->data.cpu_index=1;
2128 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2132 obj->data.cpu_index=atoi(&arg[0]);
2135 #if defined(__linux__)
2136 END OBJ(voltage_mv, 0)
2142 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2144 obj->data.cpu_index=1;
2145 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2149 obj->data.cpu_index=atoi(&arg[0]);
2152 END OBJ(voltage_v, 0)
2158 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2160 obj->data.cpu_index=1;
2161 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2165 obj->data.cpu_index=atoi(&arg[0]);
2168 #endif /* __linux__ */
2169 END OBJ(freq_dyn, 0);
2170 END OBJ(freq_dyn_g, 0);
2171 END OBJ(acpifan, 0);
2172 END OBJ(battery, 0);
2175 sscanf(arg, "%63s", bat);
2177 strcpy(bat, "BAT0");
2178 obj->data.s = strdup(bat);
2179 END OBJ(battery_time, 0);
2182 sscanf(arg, "%63s", bat);
2184 strcpy(bat, "BAT0");
2185 obj->data.s = strdup(bat);
2186 END OBJ(battery_percent, 0);
2189 sscanf(arg, "%63s", bat);
2191 strcpy(bat, "BAT0");
2192 obj->data.s = strdup(bat);
2193 END OBJ(battery_bar, 0);
2196 arg = scan_bar(arg, &obj->a, &obj->b);
2197 sscanf(arg, "%63s", bat);
2199 strcpy(bat, "BAT0");
2201 #if defined(__linux__)
2202 END OBJ(i8k_version, INFO_I8K)
2203 END OBJ(i8k_bios, INFO_I8K)
2204 END OBJ(i8k_serial, INFO_I8K)
2205 END OBJ(i8k_cpu_temp, INFO_I8K)
2206 END OBJ(i8k_cpu_tempf, INFO_I8K)
2207 END OBJ(i8k_left_fan_status, INFO_I8K)
2208 END OBJ(i8k_right_fan_status, INFO_I8K)
2209 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2210 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2211 END OBJ(i8k_ac_status, INFO_I8K)
2212 END OBJ(i8k_buttons_status, INFO_I8K)
2214 END OBJ(ibm_temps, 0)
2216 CRIT_ERR("ibm_temps: needs an argument");
2218 if (!isdigit(arg[0])
2220 || atoi(&arg[0]) >=8)
2223 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2225 obj->data.sensor = atoi(&arg[0]);
2226 END OBJ(ibm_volume, 0)
2227 END OBJ(ibm_brightness, 0)
2228 END OBJ(pb_battery, 0)
2229 if (arg && strcmp(arg, "status") == 0) {
2230 obj->data.i = PB_BATT_STATUS;
2231 } else if (arg && strcmp(arg, "percent") == 0) {
2232 obj->data.i = PB_BATT_PERCENT;
2233 } else if (arg && strcmp(arg, "time") == 0) {
2234 obj->data.i = PB_BATT_TIME;
2236 ERR("pb_battery: needs one argument: status, percent or time");
2241 #endif /* __linux__ */
2242 #if defined(__OpenBSD__)
2243 END OBJ(obsd_sensors_temp, 0);
2245 CRIT_ERR("obsd_sensors_temp: needs an argument");
2247 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2249 ERR("Invalid temperature sensor number!");
2251 obj->data.sensor = atoi(&arg[0]);
2252 END OBJ(obsd_sensors_fan, 0);
2254 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor number)");
2256 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2258 ERR("Invalid fan sensor number!");
2260 obj->data.sensor = atoi(&arg[0]);
2261 END OBJ(obsd_sensors_volt, 0);
2263 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor number)");
2265 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2267 ERR("Invalid voltage sensor number!");
2269 obj->data.sensor = atoi(&arg[0]);
2270 END OBJ(obsd_vendor, 0);
2271 END OBJ(obsd_product, 0);
2272 #endif /* __OpenBSD__ */
2273 END OBJ(buffers, INFO_BUFFERS)
2274 END OBJ(cached, INFO_BUFFERS)
2275 END OBJ(cpu, INFO_CPU)
2277 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2278 obj->data.cpu_index = atoi(&arg[3]);
2280 } else {obj->data.cpu_index = 0; }
2282 obj->data.cpu_index = 0;
2284 END OBJ(cpubar, INFO_CPU)
2286 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2287 obj->data.cpu_index = atoi(&arg[3]);
2290 else {obj->data.cpu_index = 0;}
2291 (void) scan_bar(arg, &obj->a, &obj->b);
2293 (void) scan_bar(arg, &obj->a, &obj->b);
2294 obj->data.cpu_index = 0;
2296 END OBJ(cpugraph, INFO_CPU)
2298 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2299 obj->data.cpu_index = atoi(&arg[3]);
2302 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2304 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2305 obj->data.cpu_index = 0;
2307 END OBJ(diskio, INFO_DISKIO)
2308 END OBJ(diskio_read, INFO_DISKIO)
2309 END OBJ(diskio_write, INFO_DISKIO)
2310 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2311 END OBJ(diskiograph_read, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2312 END OBJ(diskiograph_write, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2315 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2318 obj->data.l = color0;
2320 obj->data.l = color1;
2322 obj->data.l = color2;
2324 obj->data.l = color3;
2326 obj->data.l = color4;
2328 obj->data.l = color5;
2330 obj->data.l = color6;
2332 obj->data.l = color7;
2334 obj->data.l = color8;
2336 obj->data.l = color9;
2338 obj->data.s = scan_font(arg);
2339 END OBJ(downspeed, INFO_NET)
2341 obj->data.net = get_net_stat(arg);
2344 CRIT_ERR("downspeed needs argument");
2346 END OBJ(downspeedf, INFO_NET)
2348 obj->data.net = get_net_stat(arg);
2351 CRIT_ERR("downspeedf needs argument");
2353 END OBJ(downspeedgraph, INFO_NET)
2354 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2356 sscanf(arg, "%63s %*i,%*i %*i", buf);
2357 obj->data.net = get_net_stat(buf);
2358 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2359 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
2366 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2367 blockstart[blockdepth - 1] = object_count;
2368 obj->data.ifblock.pos = object_count + 2;
2370 ERR("$else: no matching $if_*");
2375 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2377 ERR("$endif: no matching $if_*");
2380 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2383 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2384 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2385 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2386 END OBJ(execibar, 0) unsigned int n;
2387 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2389 ERR("${execibar <interval> command}");
2390 obj->type = OBJ_text;
2391 snprintf(buf, 256, "${%s}", s);
2392 obj->data.s = strdup(buf);
2394 obj->data.execi.cmd = strdup(arg + n);
2396 END OBJ(execigraph, 0) unsigned int n;
2397 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2399 ERR("${execigraph <interval> command}");
2400 obj->type = OBJ_text;
2401 snprintf(buf, 256, "${%s}", s);
2402 obj->data.s = strdup(buf);
2404 obj->data.execi.cmd = strdup(arg + n);
2406 END OBJ(execi, 0) unsigned int n;
2407 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2409 ERR("${execi <interval> command}");
2410 obj->type = OBJ_text;
2411 snprintf(buf, 256, "${%s}", s);
2412 obj->data.s = strdup(buf);
2414 obj->data.execi.cmd = strdup(arg + n);
2415 obj->data.execi.buffer =
2416 (char *) calloc(1, text_buffer_size);
2418 END OBJ(texeci, 0) unsigned int n;
2419 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2421 ERR("${texeci <interval> command}");
2422 obj->type = OBJ_text;
2423 snprintf(buf, 256, "${%s}", s);
2424 obj->data.s = strdup(buf);
2426 obj->data.texeci.cmd = strdup(arg + n);
2427 obj->data.texeci.buffer =
2428 (char *) calloc(1, text_buffer_size);
2430 obj->data.texeci.p_timed_thread = NULL;
2431 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2433 FILE *fp = popen(arg, "r");
2437 n = fread(buf, 1, 2048, fp);
2440 if (n && buf[n - 1] == '\n')
2445 obj->data.s = strdup(buf);
2447 obj->data.s = strdup("");
2450 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2451 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2453 while (isspace(*arg))
2459 obj->data.fsbar.fs = prepare_fs_stat(arg);
2460 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2463 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2467 obj->data.fsbar.fs = prepare_fs_stat(arg);
2468 END OBJ(fs_free, INFO_FS) if (!arg)
2470 obj->data.fs = prepare_fs_stat(arg);
2471 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2473 obj->data.fs = prepare_fs_stat(arg);
2474 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2476 obj->data.fs = prepare_fs_stat(arg);
2477 END OBJ(fs_size, INFO_FS) if (!arg)
2479 obj->data.fs = prepare_fs_stat(arg);
2480 END OBJ(fs_used, INFO_FS) if (!arg)
2482 obj->data.fs = prepare_fs_stat(arg);
2483 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2484 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2485 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2489 ERR("goto needs arguments");
2490 obj->type = OBJ_text;
2491 obj->data.s = strdup("${goto}");
2495 obj->data.i = atoi(arg);
2500 if (sscanf(arg, "%d %d", &a, &b) != 2)
2501 sscanf(arg, "%d", &b);
2505 obj->data.pair.a = a;
2506 obj->data.pair.b = b;
2508 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
2512 ERR("i2c needs arguments");
2513 obj->type = OBJ_text;
2514 //obj->data.s = strdup("${i2c}");
2518 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2519 /* if scanf couldn't read three values, read type and num and use
2521 sscanf(arg, "%63s %d", buf2, &n);
2523 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
2524 obj->data.i2c.devtype);
2525 strncpy(obj->data.i2c.type, buf2, 63);
2528 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
2529 obj->data.i2c.devtype);
2530 strncpy(obj->data.i2c.type, buf2, 63);
2533 END OBJ(top, INFO_TOP)
2537 ERR("top needs arguments");
2538 obj->type = OBJ_text;
2539 //obj->data.s = strdup("${top}");
2542 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2543 if (strcmp(buf, "name") == 0) {
2544 obj->data.top.type = TOP_NAME;
2545 } else if (strcmp(buf, "cpu") == 0) {
2546 obj->data.top.type = TOP_CPU;
2547 } else if (strcmp(buf, "pid") == 0) {
2548 obj->data.top.type = TOP_PID;
2549 } else if (strcmp(buf, "mem") == 0) {
2550 obj->data.top.type = TOP_MEM;
2552 ERR("invalid arg for top");
2555 if (n < 1 || n > 10) {
2556 CRIT_ERR("invalid arg for top");
2559 obj->data.top.num = n - 1;
2563 ERR("invalid args given for top");
2566 END OBJ(top_mem, INFO_TOP)
2570 ERR("top_mem needs arguments");
2571 obj->type = OBJ_text;
2572 obj->data.s = strdup("${top_mem}");
2575 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2576 if (strcmp(buf, "name") == 0) {
2577 obj->data.top.type = TOP_NAME;
2578 } else if (strcmp(buf, "cpu") == 0) {
2579 obj->data.top.type = TOP_CPU;
2580 } else if (strcmp(buf, "pid") == 0) {
2581 obj->data.top.type = TOP_PID;
2582 } else if (strcmp(buf, "mem") == 0) {
2583 obj->data.top.type = TOP_MEM;
2585 ERR("invalid arg for top");
2588 if (n < 1 || n > 10) {
2589 CRIT_ERR("invalid arg for top");
2592 obj->data.top.num = n - 1;
2596 ERR("invalid args given for top");
2599 END OBJ(addr, INFO_NET)
2601 obj->data.net = get_net_stat(arg);
2604 CRIT_ERR("addr needs argument");
2606 END OBJ(linkstatus, INFO_WIFI)
2608 obj->data.net = get_net_stat(arg);
2611 CRIT_ERR("linkstatus needs argument");
2617 ERR("tail needs arguments");
2618 obj->type = OBJ_text;
2619 obj->data.s = strdup("${tail}");
2622 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2623 if (n1 < 1 || n1 > 30) {
2624 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2628 fp = fopen(buf, "r");
2630 obj->data.tail.logfile =
2631 malloc(text_buffer_size);
2632 strcpy(obj->data.tail.logfile, buf);
2633 obj->data.tail.wantedlines = n1;
2634 obj->data.tail.interval =
2635 update_interval * 2;
2639 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2642 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2643 if (n1 < 1 || n1 > 30) {
2645 ("invalid arg for tail, number of lines must be between 1 and 30");
2647 } else if (n2 < 1 || n2 < update_interval) {
2649 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2653 fp = fopen(buf, "r");
2655 obj->data.tail.logfile =
2656 malloc(text_buffer_size);
2657 strcpy(obj->data.tail.logfile, buf);
2658 obj->data.tail.wantedlines = n1;
2659 obj->data.tail.interval = n2;
2663 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2669 ERR("invalid args given for tail");
2672 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2677 ERR("head needs arguments");
2678 obj->type = OBJ_text;
2679 obj->data.s = strdup("${head}");
2682 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2683 if (n1 < 1 || n1 > 30) {
2684 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2688 fp = fopen(buf, "r");
2690 obj->data.tail.logfile =
2691 malloc(text_buffer_size);
2692 strcpy(obj->data.tail.logfile, buf);
2693 obj->data.tail.wantedlines = n1;
2694 obj->data.tail.interval =
2695 update_interval * 2;
2699 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2702 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2703 if (n1 < 1 || n1 > 30) {
2705 ("invalid arg for head, number of lines must be between 1 and 30");
2707 } else if (n2 < 1 || n2 < update_interval) {
2709 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2713 fp = fopen(buf, "r");
2715 obj->data.tail.logfile =
2716 malloc(text_buffer_size);
2717 strcpy(obj->data.tail.logfile, buf);
2718 obj->data.tail.wantedlines = n1;
2719 obj->data.tail.interval = n2;
2723 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2729 ERR("invalid args given for head");
2732 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2733 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2735 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2736 if (r >= 3 && (c < 1 || c > 3))
2738 if (r >= 2 && (b < 1 || b > 3))
2740 if (r >= 1 && (a < 1 || a > 3))
2743 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2744 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2745 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2746 END OBJ(if_empty, 0)
2747 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2748 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2751 ERR("if_empty needs an argument");
2752 obj->data.ifblock.s = 0;
2754 obj->data.ifblock.s = strdup(arg);
2755 blockstart[blockdepth] = object_count;
2756 obj->data.ifblock.pos = object_count + 2;
2758 END OBJ(if_existing, 0)
2759 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2760 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2763 ERR("if_existing needs an argument or two");
2764 obj->data.ifblock.s = NULL;
2765 obj->data.ifblock.str = NULL;
2767 char buf1[256], buf2[256];
2768 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2770 obj->data.ifblock.s = strdup(buf1);
2771 obj->data.ifblock.str = NULL;
2773 obj->data.ifblock.s = strdup(buf1);
2774 obj->data.ifblock.str = strdup(buf2);
2777 blockstart[blockdepth] = object_count;
2778 obj->data.ifblock.pos = object_count + 2;
2780 END OBJ(if_mounted, 0)
2781 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2782 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2785 ERR("if_mounted needs an argument");
2786 obj->data.ifblock.s = 0;
2788 obj->data.ifblock.s = strdup(arg);
2789 blockstart[blockdepth] = object_count;
2790 obj->data.ifblock.pos = object_count + 2;
2792 END OBJ(if_running, 0)
2793 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2794 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2798 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2799 obj->data.ifblock.s = strdup(buf);
2801 ERR("if_running needs an argument");
2802 obj->data.ifblock.s = 0;
2804 blockstart[blockdepth] = object_count;
2805 obj->data.ifblock.pos = object_count + 2;
2809 END OBJ(mails, INFO_MAIL)
2810 END OBJ(mboxscan, 0)
2811 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
2812 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
2813 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2814 obj->data.mboxscan.output[0] = 1;
2815 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
2816 END OBJ(mem, INFO_MEM)
2817 END OBJ(memmax, INFO_MEM)
2818 END OBJ(memperc, INFO_MEM)
2819 END OBJ(membar, INFO_MEM)
2820 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2821 END OBJ(memgraph, INFO_MEM)
2822 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2823 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2824 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2825 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2826 END OBJ(mixerbar, INFO_MIXER)
2827 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2828 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2829 END OBJ(mixerlbar, INFO_MIXER)
2830 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2831 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2832 END OBJ(mixerrbar, INFO_MIXER)
2833 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2834 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2836 OBJ(new_mails, INFO_MAIL)
2837 END OBJ(nodename, 0)
2838 END OBJ(processes, INFO_PROCS)
2839 END OBJ(running_processes, INFO_RUN_PROCS)
2840 END OBJ(shadecolor, 0)
2842 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2844 END OBJ(outlinecolor, 0)
2846 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2848 END OBJ(stippled_hr, 0)
2850 int a = stippled_borders, b = 1;
2852 if (sscanf(arg, "%d %d", &a, &b) != 2)
2853 sscanf(arg, "%d", &b);
2857 obj->data.pair.a = a;
2858 obj->data.pair.b = b;
2860 END OBJ(swap, INFO_MEM)
2861 END OBJ(swapmax, INFO_MEM)
2862 END OBJ(swapperc, INFO_MEM)
2863 END OBJ(swapbar, INFO_MEM)
2864 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2865 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
2867 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
2868 obj->data.i2c.devtype);
2869 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
2871 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
2872 obj->data.i2c.devtype);
2873 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2874 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2876 char buf1[256], buf2[256], *fmt, *tz;
2879 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2888 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
2889 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
2891 END OBJ(iconv_start, 0)
2892 if (iconv_converting) {
2893 CRIT_ERR("You must stop your last iconv conversion before starting another");
2896 char iconv_from[CODEPAGE_LENGTH];
2897 char iconv_to[CODEPAGE_LENGTH];
2898 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2899 CRIT_ERR("Invalid arguments for iconv_start");
2902 new_iconv = iconv_open(iconv_to, iconv_from);
2903 if (new_iconv == (iconv_t)(-1)) {
2904 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2906 obj->a = register_iconv(&new_iconv);
2907 iconv_converting = 1;
2911 CRIT_ERR("Iconv requires arguments");
2913 END OBJ(iconv_stop, 0)
2914 iconv_converting = 0;
2917 END OBJ(totaldown, INFO_NET)
2919 obj->data.net = get_net_stat(arg);
2922 CRIT_ERR("totaldown needs argument");
2924 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
2926 obj->data.net = get_net_stat(arg);
2929 CRIT_ERR("totalup needs argument");
2932 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
2933 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
2934 END OBJ(upspeed, INFO_NET)
2936 obj->data.net = get_net_stat(arg);
2939 CRIT_ERR("upspeed needs argument");
2941 END OBJ(upspeedf, INFO_NET)
2943 obj->data.net = get_net_stat(arg);
2946 CRIT_ERR("upspeedf needs argument");
2949 END OBJ(upspeedgraph, INFO_NET)
2950 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2952 sscanf(arg, "%63s %*i,%*i %*i", buf);
2953 obj->data.net = get_net_stat(buf);
2954 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2955 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
2960 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
2961 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
2962 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2963 OBJ(apm_adapter, 0) END
2964 OBJ(apm_battery_life, 0) END
2965 OBJ(apm_battery_time, 0) END
2966 #endif /* __FreeBSD__ */
2970 obj->data.mail = parse_mail_args(IMAP, arg);
2971 obj->global_mode = 0;
2973 obj->global_mode = 1;
2976 OBJ(imap_messages, 0)
2979 obj->data.mail = parse_mail_args(IMAP, arg);
2980 obj->global_mode = 0;
2982 obj->global_mode = 1;
2988 obj->data.mail = parse_mail_args(POP3, arg);
2989 obj->global_mode = 0;
2991 obj->global_mode = 1;
2997 obj->data.mail = parse_mail_args(POP3, arg);
2998 obj->global_mode = 0;
3000 obj->global_mode = 1;
3004 OBJ(mpd_artist, INFO_MPD) END
3005 OBJ(mpd_title, INFO_MPD)
3009 sscanf (arg, "%d", &info.mpd.max_title_len);
3010 if (info.mpd.max_title_len > 0)
3011 info.mpd.max_title_len++;
3013 CRIT_ERR ("mpd_title: invalid length argument");
3016 END OBJ(mpd_random, INFO_MPD)
3017 END OBJ(mpd_repeat, INFO_MPD)
3018 END OBJ(mpd_elapsed, INFO_MPD)
3019 END OBJ(mpd_length, INFO_MPD)
3020 END OBJ(mpd_track, INFO_MPD)
3021 END OBJ(mpd_name, INFO_MPD)
3022 END OBJ(mpd_file, INFO_MPD)
3023 END OBJ(mpd_percent, INFO_MPD)
3024 END OBJ(mpd_album, INFO_MPD)
3025 END OBJ(mpd_vol, INFO_MPD)
3026 END OBJ(mpd_bitrate, INFO_MPD)
3027 END OBJ(mpd_status, INFO_MPD)
3028 END OBJ(mpd_bar, INFO_MPD)
3029 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3030 END OBJ(mpd_smart, INFO_MPD) END
3033 OBJ(xmms2_artist, INFO_XMMS2)
3034 END OBJ(xmms2_album, INFO_XMMS2)
3035 END OBJ(xmms2_title, INFO_XMMS2)
3036 END OBJ(xmms2_genre, INFO_XMMS2)
3037 END OBJ(xmms2_comment, INFO_XMMS2)
3038 END OBJ(xmms2_decoder, INFO_XMMS2)
3039 END OBJ(xmms2_transport, INFO_XMMS2)
3040 END OBJ(xmms2_url, INFO_XMMS2)
3041 END OBJ(xmms2_tracknr, INFO_XMMS2)
3042 END OBJ(xmms2_bitrate, INFO_XMMS2)
3043 END OBJ(xmms2_date, INFO_XMMS2)
3044 END OBJ(xmms2_id, INFO_XMMS2)
3045 END OBJ(xmms2_duration, INFO_XMMS2)
3046 END OBJ(xmms2_elapsed, INFO_XMMS2)
3047 END OBJ(xmms2_size, INFO_XMMS2)
3048 END OBJ(xmms2_status, INFO_XMMS2)
3049 END OBJ(xmms2_percent, INFO_XMMS2)
3050 END OBJ(xmms2_bar, INFO_XMMS2)
3051 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3052 END OBJ(xmms2_smart, INFO_XMMS2)
3056 OBJ(audacious_status, INFO_AUDACIOUS) END
3057 OBJ(audacious_title, INFO_AUDACIOUS)
3061 sscanf (arg, "%d", &info.audacious.max_title_len);
3062 if (info.audacious.max_title_len > 0)
3063 info.audacious.max_title_len++;
3065 CRIT_ERR ("audacious_title: invalid length argument");
3069 OBJ(audacious_length, INFO_AUDACIOUS) END
3070 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3071 OBJ(audacious_position, INFO_AUDACIOUS) END
3072 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3073 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3074 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3075 OBJ(audacious_channels, INFO_AUDACIOUS) END
3076 OBJ(audacious_filename, INFO_AUDACIOUS) END
3077 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3078 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3079 OBJ(audacious_bar, INFO_AUDACIOUS)
3080 (void) scan_bar(arg, &obj->a, &obj->b);
3084 OBJ(bmpx_title, INFO_BMPX)
3085 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3087 OBJ(bmpx_artist, INFO_BMPX)
3088 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3090 OBJ(bmpx_album, INFO_BMPX)
3091 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3093 OBJ(bmpx_track, INFO_BMPX)
3094 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3096 OBJ(bmpx_uri, INFO_BMPX)
3097 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3099 OBJ(bmpx_bitrate, INFO_BMPX)
3100 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3106 int argc, delay, act_par;
3107 char *uri = (char *)malloc(128 * sizeof(char));
3108 char *action = (char *)malloc(64 * sizeof(char));
3110 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par);
3111 obj->data.rss.uri = uri;
3112 obj->data.rss.delay = delay;
3113 obj->data.rss.action = action;
3114 obj->data.rss.act_par = act_par;
3118 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
3124 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3125 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3126 ERR("hddtemp needs arguments");
3127 obj->type = OBJ_text;
3128 obj->data.s = strdup("${hddtemp}");
3133 #ifdef TCP_PORT_MONITOR
3134 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3135 int argc, port_begin, port_end, item, connection_index;
3137 memset(itembuf,0,sizeof(itembuf));
3139 /* massive argument checking */
3141 CRIT_ERR("tcp_portmon: needs arguments");
3143 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3144 if ( (argc != 3) && (argc != 4) )
3146 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3148 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3150 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3152 if ( port_begin > port_end )
3154 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3156 if ( strncmp(itembuf,"count",31) == 0 )
3158 else if ( strncmp(itembuf,"rip",31) == 0 )
3160 else if ( strncmp(itembuf,"rhost",31) == 0 )
3162 else if ( strncmp(itembuf,"rport",31) == 0 )
3164 else if ( strncmp(itembuf,"rservice",31) == 0 )
3166 else if ( strncmp(itembuf,"lip",31) == 0 )
3168 else if ( strncmp(itembuf,"lhost",31) == 0 )
3170 else if ( strncmp(itembuf,"lport",31) == 0 )
3172 else if ( strncmp(itembuf,"lservice",31) == 0 )
3176 CRIT_ERR("tcp_portmon: invalid item specified");
3178 if ( (argc==3) && (item!=COUNT) )
3180 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3182 if ( (argc==4) && (connection_index<0) )
3184 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3186 /* ok, args looks good. save the text object data */
3187 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3188 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3189 obj->data.tcp_port_monitor.item = item;
3190 obj->data.tcp_port_monitor.connection_index = connection_index;
3192 /* if the port monitor collection hasn't been created, we must create it */
3193 if ( !info.p_tcp_port_monitor_collection )
3195 info.p_tcp_port_monitor_collection =
3196 create_tcp_port_monitor_collection ();
3197 if ( !info.p_tcp_port_monitor_collection )
3199 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3203 /* if a port monitor for this port does not exist, create one and add it to the collection */
3204 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3206 tcp_port_monitor_t * p_monitor =
3207 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3210 CRIT_ERR("tcp_portmon: unable to create port monitor");
3212 /* add the newly created monitor to the collection */
3213 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3216 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3221 OBJ(entropy_avail, INFO_ENTROPY) END
3222 OBJ(entropy_poolsize, INFO_ENTROPY) END
3223 OBJ(entropy_bar, INFO_ENTROPY)
3224 (void) scan_bar(arg, &obj->a, &obj->b);
3229 ERR("unknown variable %s", s);
3230 obj->type = OBJ_text;
3231 snprintf(buf, 256, "${%s}", s);
3232 obj->data.s = strdup(buf);
3239 static struct text_object *create_plain_text(const char *s)
3241 struct text_object *obj;
3243 if (s == NULL || *s == '\0') {
3247 obj = new_text_object_internal();
3249 obj->type = OBJ_text;
3250 obj->data.s = strdup(s);
3254 static struct text_object_list *extract_variable_text_internal(const char *p)
3256 struct text_object_list *retval;
3257 struct text_object *obj;
3260 retval = malloc(sizeof(struct text_object_list));
3261 memset(retval, 0, sizeof(struct text_object_list));
3262 retval->text_object_count = 0;
3264 long line = text_lines;
3272 obj = create_plain_text(s);
3274 // allocate memory for the object
3275 retval->text_objects = realloc(retval->text_objects,
3276 sizeof(struct text_object) * (retval->text_object_count+1));
3277 // assign the new object to the end of the list.
3278 memcpy(&retval->text_objects[retval->text_object_count++],
3279 obj, sizeof(struct text_object));
3291 /* variable is either $foo or ${foo} */
3293 unsigned int brl = 1, brr = 0;
3296 while (*p && brl != brr) {
3297 if (*p == '{') brl++;
3298 if (*p == '}') brr++;
3306 while (*p && (isalnum((int) *p)
3311 /* copy variable to buffer */
3312 len = (p - s > 255) ? 255 : (p - s);
3313 strncpy(buf, s, len);
3322 /* if variable wasn't found from environment, use some special */
3328 if (strchr(buf, ' ')) {
3329 arg = strchr(buf, ' ');
3332 while (isspace((int) *arg))
3338 /* lowercase variable name */
3345 // create new object
3346 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3348 // allocate memory for the object
3349 retval->text_objects = realloc(retval->text_objects,
3350 sizeof(struct text_object) * (retval->text_object_count+1));
3351 // assign the new object to the end of the list.
3352 memcpy(&retval->text_objects[retval->text_object_count++],
3353 obj, sizeof(struct text_object));
3359 obj = create_plain_text("$");
3361 // allocate memory for the object
3362 retval->text_objects = realloc(retval->text_objects,
3363 sizeof(struct text_object) * (retval->text_object_count+1));
3364 // assign the new object to the end of the list.
3365 memcpy(&retval->text_objects[retval->text_object_count++],
3366 obj, sizeof(struct text_object));
3373 obj = create_plain_text(s);
3375 // allocate memory for the object
3376 retval->text_objects = realloc(retval->text_objects,
3377 sizeof(struct text_object) * (retval->text_object_count+1));
3378 // assign the new object to the end of the list.
3379 memcpy(&retval->text_objects[retval->text_object_count++],
3380 obj, sizeof(struct text_object));
3385 ERR("one or more $endif's are missing");
3391 static void extract_variable_text(const char *p)
3393 struct text_object_list *list;
3395 free_text_objects(text_object_count, text_objects);
3396 text_object_count = 0;
3397 text_objects = NULL;
3400 list = extract_variable_text_internal(p);
3401 text_objects = list->text_objects;
3402 text_object_count = list->text_object_count;
3409 void parse_conky_vars(char * text, char * p, struct information *cur) {
3410 struct text_object_list *object_list = extract_variable_text_internal(text);
3411 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3415 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3420 char buff_in[P_MAX_SIZE] = {0};
3421 iconv_converting = 0;
3424 for (i = 0; i < object_count; i++) {
3425 struct text_object *obj = &objs[i];
3427 #define OBJ(a) break; case OBJ_##a:
3429 switch (obj->type) {
3432 ERR("not implemented obj type %d",
3436 /* does anyone have decimals in acpi temperature? */
3438 snprintf(p, p_max_size, "%d", (int)
3439 get_acpi_temperature(obj->
3443 snprintf(p, 5, "%d ", (int)
3444 get_acpi_temperature(obj->
3449 /* does anyone have decimals in acpi temperature? */
3451 snprintf(p, p_max_size, "%d", (int)
3452 ((get_acpi_temperature(obj->
3454 i)+ 40) * 9.0 / 5 - 40));
3456 snprintf(p, 5, "%d ", (int)
3457 ((get_acpi_temperature(obj->
3459 i)+ 40) * 9.0 / 5 - 40));
3463 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3468 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3471 #if defined(__linux__)
3474 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3479 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3482 #endif /* __linux__ */
3486 get_freq_dynamic(p, 6, "%.0f ", 1 );
3488 get_freq_dynamic(p, p_max_size, "%.0f", 1 );
3493 get_freq_dynamic(p, 6, "%'.2f ", 1000);
3495 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3499 get_adt746x_cpu(p, p_max_size);
3502 get_adt746x_fan(p, p_max_size);
3505 get_acpi_fan(p, p_max_size);
3507 OBJ(acpiacadapter) {
3508 get_acpi_ac_adapter(p, p_max_size);
3511 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3514 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3516 OBJ(battery_percent) {
3517 snprintf(p, p_max_size, "%d",
3518 get_battery_perct(obj->data.s));
3521 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3524 human_readable(cur->buffers * 1024, p, 255);
3527 human_readable(cur->cached * 1024, p, 255);
3530 if (obj->data.cpu_index > info.cpu_count) {
3531 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3532 CRIT_ERR("attempting to use more CPUs then you have!");
3535 snprintf(p, p_max_size, "%*d", pad_percents,
3536 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3539 snprintf(p, 4, "%*d ",
3541 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3547 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3550 new_graph(p, obj->a,
3551 obj->b, obj->c, obj->d,
3552 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3556 new_fg(p, obj->data.l);
3588 #if defined(__linux__)
3590 snprintf(p, p_max_size, "%s", i8k.version);
3593 snprintf(p, p_max_size, "%s", i8k.bios);
3596 snprintf(p, p_max_size, "%s", i8k.serial);
3599 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3601 OBJ(i8k_cpu_tempf) {
3603 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3604 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3606 OBJ(i8k_left_fan_status) {
3607 int left_fan_status;
3608 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3609 if(left_fan_status == 0) {
3610 snprintf(p, p_max_size,"off");
3611 } if(left_fan_status == 1) {
3612 snprintf(p, p_max_size, "low");
3613 } if(left_fan_status == 2) {
3614 snprintf(p, p_max_size, "high");
3618 OBJ(i8k_right_fan_status) {
3619 int right_fan_status;
3620 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3621 if(right_fan_status == 0) {
3622 snprintf(p, p_max_size,"off");
3623 } if(right_fan_status == 1) {
3624 snprintf(p, p_max_size, "low");
3625 } if(right_fan_status == 2) {
3626 snprintf(p, p_max_size, "high");
3629 OBJ(i8k_left_fan_rpm) {
3630 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3632 OBJ(i8k_right_fan_rpm) {
3633 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3635 OBJ(i8k_ac_status) {
3637 sscanf(i8k.ac_status, "%d", &ac_status);
3638 if(ac_status == -1) {
3639 snprintf(p, p_max_size,"disabled (read i8k docs)");
3640 } if(ac_status == 0) {
3641 snprintf(p, p_max_size, "off");
3642 } if(ac_status == 1) {
3643 snprintf(p, p_max_size, "on");
3646 OBJ(i8k_buttons_status) {
3647 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3651 get_ibm_acpi_fan(p, p_max_size);
3654 get_ibm_acpi_temps();
3655 snprintf(p, p_max_size, "%d",
3656 ibm_acpi.temps[obj->data.sensor]);
3659 get_ibm_acpi_volume(p, p_max_size);
3661 OBJ(ibm_brightness) {
3662 get_ibm_acpi_brightness(p, p_max_size);
3665 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3667 #endif /* __linux__ */
3670 OBJ(obsd_sensors_temp) {
3671 obsd_sensors.device = sensor_device;
3672 update_obsd_sensors();
3673 snprintf(p, p_max_size, "%.1f",
3674 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
3677 OBJ(obsd_sensors_fan) {
3678 obsd_sensors.device = sensor_device;
3679 update_obsd_sensors();
3680 snprintf(p, p_max_size, "%d",
3681 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3684 OBJ(obsd_sensors_volt) {
3685 obsd_sensors.device = sensor_device;
3686 update_obsd_sensors();
3687 snprintf(p, p_max_size, "%.2f",
3688 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3692 get_obsd_vendor(p, p_max_size);
3696 get_obsd_product(p, p_max_size);
3698 #endif /* __OpenBSD__ */
3702 new_font(p, obj->data.s);
3705 void format_diskio(unsigned int diskio_value)
3708 if (diskio_value > 1024*1024) {
3709 snprintf(p, p_max_size, "%.1fGiB",
3710 (double)diskio_value/1024/1024);
3711 } else if (diskio_value > 1024) {
3712 snprintf(p, p_max_size, "%.1fMiB",
3713 (double)diskio_value/1024);
3714 } else if (diskio_value > 0) {
3715 snprintf(p, p_max_size, "%dKiB", diskio_value);
3717 snprintf(p, p_max_size, "%dB", diskio_value);
3720 if (diskio_value > 1024*1024) {
3721 snprintf(p, 12, "%.1fGiB ",
3722 (double)diskio_value/1024/1024);
3723 } else if (diskio_value > 1024) {
3724 snprintf(p, 12, "%.1fMiB ",
3725 (double)diskio_value/1024);
3726 } else if (diskio_value > 0) {
3727 snprintf(p, 12, "%dKiB ", diskio_value);
3729 snprintf(p, 12, "%dB ", diskio_value);
3734 format_diskio(diskio_value);
3737 format_diskio(diskio_write_value);
3740 format_diskio(diskio_read_value);
3743 new_graph(p, obj->a,
3744 obj->b, obj->c, obj->d,
3745 diskio_value, obj->e, 1);
3747 OBJ(diskiograph_read) {
3748 new_graph(p, obj->a,
3749 obj->b, obj->c, obj->d,
3750 diskio_read_value, obj->e, 1);
3752 OBJ(diskiograph_write) {
3753 new_graph(p, obj->a,
3754 obj->b, obj->c, obj->d,
3755 diskio_write_value, obj->e, 1);
3759 snprintf(p, p_max_size, "%d",
3760 (int) (obj->data.net->
3764 snprintf(p, 6, "%d ",
3765 (int) (obj->data.net->
3771 snprintf(p, p_max_size, "%.1f",
3773 recv_speed / 1024.0);
3775 snprintf(p, 8, "%.1f ",
3777 recv_speed / 1024.0);
3779 OBJ(downspeedgraph) {
3781 if (obj->data.net->recv_speed == 0)
3782 obj->data.net->recv_speed = 0.01;
3784 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3785 (obj->data.net->recv_speed /
3786 1024.0), obj->e, 1);
3790 i = obj->data.ifblock.pos - 1;
3800 snprintf(p, p_max_size, "%u.%u.%u.%u",
3801 obj->data.net->addr.
3803 obj->data.net->addr.
3805 obj->data.net->addr.
3807 obj->data.net->addr.
3813 snprintf(p, p_max_size, "%d",
3814 obj->data.net->linkstatus);
3817 snprintf(p, 5, "%4d ",
3818 obj->data.net->linkstatus);
3821 #if defined(IMLIB2) && defined(X11)
3826 Imlib_Image image, buffer;
3827 image = imlib_load_image(obj->data.s);
3828 imlib_context_set_image(image);
3831 w = imlib_image_get_width();
3832 h = imlib_image_get_height();
3833 buffer = imlib_create_image(w, h);
3834 imlib_context_set_display(display);
3835 imlib_context_set_drawable(window.drawable);
3836 imlib_context_set_colormap(DefaultColormap(display, screen));
3837 imlib_context_set_visual(DefaultVisual(display, screen));
3838 imlib_context_set_image(buffer);
3839 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
3840 imlib_render_image_on_drawable(text_start_x, text_start_y);
3842 imlib_context_set_image(image);
3849 FILE *fp = popen(obj->data.s, "r");
3850 int length = fread(p, 1, p_max_size, fp);
3853 /*output[length] = '\0';
3854 if (length > 0 && output[length - 1] == '\n') {
3855 output[length - 1] = '\0';
3858 if (length > 0 && p[length - 1] == '\n') {
3859 p[length - 1] = '\0';
3862 //parse_conky_vars(output, p, cur);
3866 FILE *fp = popen(obj->data.s, "r");
3867 int n2 = fread(p, 1, p_max_size, fp);
3871 if (n2 && p[n2 - 1] == '\n')
3880 if (sscanf(p, "%lf", &barnum) == 0) {
3881 ERR("reading execbar value failed (perhaps it's not the correct format?)");
3883 if (barnum > 100 || barnum < 0) {
3884 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
3886 barnum = barnum / 100.0;
3887 new_bar(p, 0, 4, (int) (barnum * 255.0));
3893 FILE *fp = popen(obj->data.s, "r");
3894 int n2 = fread(p, 1, p_max_size, fp);
3898 if (n2 && p[n2 - 1] == '\n')
3907 if (sscanf(p, "%lf", &barnum) == 0) {
3908 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
3910 if (barnum > 100 || barnum < 0) {
3911 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
3913 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
3918 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3919 new_bar(p, 0, 4, (int) obj->f);
3922 FILE *fp = popen(obj->data.execi.cmd, "r");
3923 int n2 = fread(p, 1, p_max_size, fp);
3926 if (n2 && p[n2 - 1] == '\n')
3935 if (sscanf(p, "%f", &barnum) == 0) {
3936 ERR("reading execibar value failed (perhaps it's not the correct format?)");
3938 if (barnum > 100 || barnum < 0) {
3939 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
3941 obj->f = 255 * barnum / 100.0;
3942 new_bar(p, 0, 4, (int) obj->f);
3944 obj->data.execi.last_update =
3945 current_update_time;
3949 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3950 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
3953 FILE *fp = popen(obj->data.execi.cmd, "r");
3954 int n2 = fread(p, 1, p_max_size, fp);
3957 if (n2 && p[n2 - 1] == '\n')
3966 if (sscanf(p, "%f", &barnum) == 0) {
3967 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
3969 if (barnum > 100 || barnum < 0) {
3970 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
3973 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
3975 obj->data.execi.last_update = current_update_time;
3981 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
3982 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
3984 char *output = obj->data.execi.buffer;
3985 FILE *fp = popen(obj->data.execi.cmd, "r");
3986 //int length = fread(output, 1, text_buffer_size, fp);
3987 int length = fread(output, 1, text_buffer_size, fp);
3990 output[length] = '\0';
3991 if (length > 0 && output[length - 1] == '\n') {
3992 output[length - 1] = '\0';
3994 obj->data.execi.last_update = current_update_time;
3995 snprintf(p, p_max_size, "%s", output);
3997 //parse_conky_vars(output, p, cur);
4000 if (!obj->data.texeci.p_timed_thread)
4002 obj->data.texeci.p_timed_thread=
4003 timed_thread_create ((void*)threaded_exec, (void*) obj,
4004 obj->data.texeci.interval * 1000000);
4005 if (!obj->data.texeci.p_timed_thread)
4006 ERR("Error starting texeci thread");
4007 timed_thread_register (obj->data.texeci.p_timed_thread,
4008 &obj->data.texeci.p_timed_thread);
4010 timed_thread_lock (obj->data.texeci.p_timed_thread);
4011 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4012 timed_thread_unlock (obj->data.texeci.p_timed_thread);
4014 #endif /* HAVE_POPEN */
4016 if (obj->global_mode && info.mail) { // this means we use info
4017 if (!info.mail->p_timed_thread)
4019 info.mail->p_timed_thread =
4020 timed_thread_create ((void*)imap_thread,
4022 info.mail->interval * 1000000);
4023 if (!info.mail->p_timed_thread)
4024 ERR("Error starting imap thread");
4025 timed_thread_register (info.mail->p_timed_thread,
4026 &info.mail->p_timed_thread);
4028 timed_thread_lock (info.mail->p_timed_thread);
4029 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4030 timed_thread_unlock (info.mail->p_timed_thread);
4031 } else if (obj->data.mail) { // this means we use obj
4032 if (!obj->data.mail->p_timed_thread)
4034 obj->data.mail->p_timed_thread =
4035 timed_thread_create ((void*)imap_thread,
4036 (void*)obj->data.mail,
4037 obj->data.mail->interval * 1000000);
4038 if (!obj->data.mail->p_timed_thread)
4039 ERR("Error starting imap thread");
4040 timed_thread_register (obj->data.mail->p_timed_thread,
4041 &obj->data.mail->p_timed_thread);
4043 timed_thread_lock (obj->data.mail->p_timed_thread);
4044 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4045 timed_thread_unlock (obj->data.mail->p_timed_thread);
4046 } else if (!obj->a) { // something is wrong, warn once then stop
4047 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4051 OBJ(imap_messages) {
4052 if (obj->global_mode && info.mail) { // this means we use info
4053 if (!info.mail->p_timed_thread)
4055 info.mail->p_timed_thread =
4056 timed_thread_create ((void*)imap_thread,
4058 info.mail->interval * 1000000);
4059 if (!info.mail->p_timed_thread)
4060 ERR("Error starting imap thread");
4061 timed_thread_register (info.mail->p_timed_thread,
4062 &info.mail->p_timed_thread);
4064 timed_thread_lock (info.mail->p_timed_thread);
4065 snprintf(p, p_max_size, "%lu", info.mail->messages);
4066 timed_thread_unlock (info.mail->p_timed_thread);
4067 } else if (obj->data.mail) { // this means we use obj
4068 if (!obj->data.mail->p_timed_thread)
4070 obj->data.mail->p_timed_thread =
4071 timed_thread_create ((void*)imap_thread,
4072 (void*)obj->data.mail,
4073 obj->data.mail->interval * 1000000);
4074 if (!obj->data.mail->p_timed_thread)
4075 ERR("Error starting imap thread");
4076 timed_thread_register (obj->data.mail->p_timed_thread,
4077 &obj->data.mail->p_timed_thread);
4079 timed_thread_lock (obj->data.mail->p_timed_thread);
4080 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4081 timed_thread_lock (obj->data.mail->p_timed_thread);
4082 } else if (!obj->a) { // something is wrong, warn once then stop
4083 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4088 if (obj->global_mode && info.mail) { // this means we use info
4089 if (!info.mail->p_timed_thread)
4091 info.mail->p_timed_thread =
4092 timed_thread_create ((void*)pop3_thread,
4094 info.mail->interval * 1000000);
4095 if (!info.mail->p_timed_thread)
4096 ERR("Error starting pop3 thread");
4097 timed_thread_register (info.mail->p_timed_thread,
4098 &info.mail->p_timed_thread);
4100 timed_thread_lock (info.mail->p_timed_thread);
4101 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4102 timed_thread_unlock (info.mail->p_timed_thread);
4103 } else if (obj->data.mail) { // this means we use obj
4104 if (!obj->data.mail->p_timed_thread)
4106 obj->data.mail->p_timed_thread =
4107 timed_thread_create ((void*)pop3_thread,
4108 (void*)obj->data.mail,
4109 obj->data.mail->interval * 1000000);
4110 if (!obj->data.mail->p_timed_thread)
4111 ERR("Error starting pop3 thread");
4112 timed_thread_register (obj->data.mail->p_timed_thread,
4113 &obj->data.mail->p_timed_thread);
4115 timed_thread_lock (obj->data.mail->p_timed_thread);
4116 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4117 timed_thread_unlock (obj->data.mail->p_timed_thread);
4118 } else if (!obj->a) { // something is wrong, warn once then stop
4119 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4124 if (obj->global_mode && info.mail) { // this means we use info
4125 if (!info.mail->p_timed_thread)
4127 info.mail->p_timed_thread =
4128 timed_thread_create ((void*)pop3_thread,
4130 info.mail->interval * 1000000);
4131 if (!info.mail->p_timed_thread)
4132 ERR("Error starting pop3 thread");
4133 timed_thread_register (info.mail->p_timed_thread,
4134 &info.mail->p_timed_thread);
4136 timed_thread_lock (info.mail->p_timed_thread);
4137 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4138 timed_thread_unlock (info.mail->p_timed_thread);
4139 } else if (obj->data.mail) { // this means we use obj
4140 if (!obj->data.mail->p_timed_thread)
4142 obj->data.mail->p_timed_thread =
4143 timed_thread_create ((void*)pop3_thread,
4144 (void*)obj->data.mail,
4145 obj->data.mail->interval * 1000000);
4146 if (!obj->data.mail->p_timed_thread)
4147 ERR("Error starting pop3 thread");
4148 timed_thread_register (obj->data.mail->p_timed_thread,
4149 &obj->data.mail->p_timed_thread);
4151 timed_thread_lock (obj->data.mail->p_timed_thread);
4152 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4153 timed_thread_unlock (obj->data.mail->p_timed_thread);
4154 } else if (!obj->a) { // something is wrong, warn once then stop
4155 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4160 if (obj->data.fs != NULL) {
4161 if (obj->data.fs->size == 0)
4180 if (obj->data.fs != NULL)
4181 human_readable(obj->data.fs->avail,
4185 if (obj->data.fs != NULL) {
4186 if (obj->data.fs->size)
4187 snprintf(p, p_max_size, "%*d",
4196 snprintf(p, p_max_size, "0");
4200 if (obj->data.fs != NULL)
4201 human_readable(obj->data.fs->size,
4205 if (obj->data.fs != NULL)
4206 human_readable(obj->data.fs->size -
4207 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
4211 if (obj->data.fs != NULL) {
4212 if (obj->data.fs->size == 0)
4230 if (obj->data.fs != NULL) {
4231 if (obj->data.fs->size)
4232 snprintf(p, 4, "%d",
4242 snprintf(p, p_max_size, "0");
4246 float *v = info.loadavg;
4248 if (obj->data.loadavg[2])
4249 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4250 v[obj->data.loadavg[0] -
4252 v[obj->data.loadavg[1] -
4254 v[obj->data.loadavg[2] -
4256 else if (obj->data.loadavg[1])
4257 snprintf(p, p_max_size, "%.2f %.2f",
4258 v[obj->data.loadavg[0] -
4260 v[obj->data.loadavg[1] -
4262 else if (obj->data.loadavg[0])
4263 snprintf(p, p_max_size, "%.2f",
4264 v[obj->data.loadavg[0] -
4268 new_goto(p, obj->data.i);
4271 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4274 new_hr(p, obj->data.i);
4278 PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay);
4281 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4283 if(!strcmp(obj->data.rss.action, "feed_title")) {
4285 if(str[strlen(str)-1] == '\n')
4286 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4287 snprintf(p, p_max_size, "%s", str);
4288 } else if(!strcmp(obj->data.rss.action, "item_title")) {
4289 if(obj->data.rss.act_par < data->item_count) {
4290 str = data->items[obj->data.rss.act_par].title;
4291 if(str[strlen(str)-1] == '\n')
4292 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4293 snprintf(p, p_max_size, "%s", str);
4295 } else if(!strcmp(obj->data.rss.action, "item_desc")) {
4296 if(obj->data.rss.act_par < data->item_count) {
4297 str = data->items[obj->data.rss.act_par].description;
4298 if(str[strlen(str)-1] == '\n')
4299 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4300 snprintf(p, p_max_size, "%s", str);
4302 } else if(!strcmp(obj->data.rss.action, "item_titles")) {
4303 if(data->item_count > 0) {
4307 if(obj->data.rss.act_par > data->item_count)
4308 show = data->item_count;
4309 else show = obj->data.rss.act_par;
4310 for(itmp = 0; itmp < show; itmp++) {
4311 PRSS_Item *item = &data->items[itmp];
4314 if(itmp>0) // don't add new line before first item
4315 strncat(p, "\n", p_max_size);
4316 if(str[strlen(str)-1] == '\n')
4317 str[strlen(str)-1] = 0; // remove trailing new line if one exists, we have our own
4318 strncat(p, str, p_max_size);
4331 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4332 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4334 snprintf(p, p_max_size, "N/A");
4335 } else if (unit == '*') {
4336 snprintf(p, p_max_size, "%s", temp);
4338 snprintf(p, p_max_size, "%s°%c", temp, unit);
4343 new_offset(p, obj->data.i);
4346 new_voffset(p, obj->data.i);
4351 r = get_i2c_info(&obj->data.i2c.fd,
4353 obj->data.i2c.devtype,
4354 obj->data.i2c.type);
4356 if (r >= 100.0 || r == 0)
4357 snprintf(p, p_max_size, "%d", (int) r);
4359 snprintf(p, p_max_size, "%.1f", r);
4362 new_alignr(p, obj->data.i);
4365 new_alignc(p, obj->data.i);
4368 struct information *my_info =
4369 malloc(sizeof(struct information));
4370 memcpy(my_info, cur, sizeof(struct information));
4371 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4372 if (strlen(p) != 0) {
4373 i = obj->data.ifblock.pos;
4383 if ((obj->data.ifblock.s)
4384 && (stat(obj->data.ifblock.s, &tmp) ==
4386 i = obj->data.ifblock.pos;
4389 if (obj->data.ifblock.str) {
4390 if (!check_contains(obj->data.ifblock.s,
4391 obj->data.ifblock.str)) {
4392 i = obj->data.ifblock.pos;
4401 if ((obj->data.ifblock.s)
4402 && (!check_mount(obj->data.ifblock.s))) {
4403 i = obj->data.ifblock.pos;
4410 if ((obj->data.ifblock.s)
4411 && system(obj->data.ifblock.s)) {
4412 i = obj->data.ifblock.pos;
4419 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4422 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4427 human_readable(cur->mem * 1024, p, 255);
4430 human_readable(cur->memmax * 1024, p, 255);
4435 snprintf(p, p_max_size, "%*Lu",
4440 snprintf(p, 4, "%*Lu ",
4447 new_bar(p, obj->data.pair.a,
4449 cur->memmax ? (cur->mem * 255) /
4454 new_graph(p, obj->a,
4455 obj->b, obj->c, obj->d,
4456 cur->memmax ? (cur->mem * 100.0) /
4457 (cur->memmax) : 0.0, 100, 1);
4461 snprintf(p, p_max_size, "%d",
4462 mixer_get_avg(obj->data.l));
4465 snprintf(p, p_max_size, "%d",
4466 mixer_get_left(obj->data.l));
4469 snprintf(p, p_max_size, "%d",
4470 mixer_get_right(obj->data.l));
4473 new_bar(p, obj->data.mixerbar.w,
4474 obj->data.mixerbar.h,
4475 mixer_get_avg(obj->data.mixerbar.
4479 new_bar(p, obj->data.mixerbar.w,
4480 obj->data.mixerbar.h,
4481 mixer_get_left(obj->data.mixerbar.
4485 new_bar(p, obj->data.mixerbar.w,
4486 obj->data.mixerbar.h,
4487 mixer_get_right(obj->data.mixerbar.
4493 snprintf(p, p_max_size, "%d", cur->mail_count);
4496 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4497 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4500 snprintf(p, p_max_size, "%d", cur->new_mail_count);
4504 snprintf(p, p_max_size, "%s",
4505 cur->uname_s.nodename);
4508 new_outline(p, obj->data.l);
4512 snprintf(p, p_max_size, "%hu", cur->procs);
4514 snprintf(p, 5, "%hu ",
4517 OBJ(running_processes) {
4519 snprintf(p, p_max_size, "%hu",
4522 snprintf(p, 3, "%hu ",
4526 snprintf(p, p_max_size, "%s", obj->data.s);
4529 new_bg(p, obj->data.l);
4532 new_stippled_hr(p, obj->data.pair.a,
4536 human_readable(cur->swap * 1024, p, 255);
4539 human_readable(cur->swapmax * 1024, p,
4543 if (cur->swapmax == 0) {
4544 strncpy(p, "No swap", 255);
4547 snprintf(p, 255, "%*Lu",
4553 snprintf(p, 4, "%*Lu ",
4561 new_bar(p, obj->data.pair.a,
4563 cur->swapmax ? (cur->swap * 255) /
4564 (cur->swapmax) : 0);
4567 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4570 time_t t = time(NULL);
4571 struct tm *tm = localtime(&t);
4572 setlocale(LC_TIME, "");
4573 strftime(p, p_max_size, obj->data.s, tm);
4576 time_t t = time(NULL);
4577 struct tm *tm = gmtime(&t);
4578 strftime(p, p_max_size, obj->data.s, tm);
4582 if (obj->data.tztime.tz) {
4583 oldTZ = getenv("TZ");
4584 setenv("TZ", obj->data.tztime.tz, 1);
4587 time_t t = time(NULL);
4588 struct tm *tm = localtime(&t);
4589 setlocale(LC_TIME, "");
4590 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4592 setenv("TZ", oldTZ, 1);
4597 // Needless to free oldTZ since getenv gives ptr to static data
4600 human_readable(obj->data.net->recv, p,
4604 human_readable(obj->data.net->trans, p,
4608 snprintf(p, p_max_size, "%d", total_updates);
4612 snprintf(p, p_max_size, "%d",
4613 (int) (obj->data.net->
4617 snprintf(p, 6, "%d ",
4618 (int) (obj->data.net->
4624 snprintf(p, p_max_size, "%.1f",
4626 trans_speed / 1024.0);
4628 snprintf(p, 8, "%.1f ",
4630 trans_speed / 1024.0);
4634 if (obj->data.net->trans_speed == 0)
4635 obj->data.net->trans_speed = 0.01;
4637 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4638 (obj->data.net->trans_speed /
4639 1024.0), obj->e, 1);
4642 format_seconds_short(p, p_max_size,
4646 format_seconds(p, p_max_size, (int) cur->uptime);
4649 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4652 msg = get_apm_adapter();
4653 snprintf(p, p_max_size, "%s", msg);
4656 OBJ(apm_battery_life) {
4658 msg = get_apm_battery_life();
4659 snprintf(p, p_max_size, "%s", msg);
4662 OBJ(apm_battery_time) {
4664 msg = get_apm_battery_time();
4665 snprintf(p, p_max_size, "%s", msg);
4668 #endif /* __FreeBSD__ __OpenBSD__ */
4672 snprintf(p, cur->mpd.max_title_len > 0 ?
4673 cur->mpd.max_title_len : p_max_size, "%s",
4677 snprintf(p, p_max_size, "%s", cur->mpd.artist);
4680 snprintf(p, p_max_size, "%s", cur->mpd.album);
4683 snprintf(p, p_max_size, "%s", cur->mpd.random);
4686 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
4689 snprintf(p, p_max_size, "%s", cur->mpd.track);
4692 snprintf(p, p_max_size, "%s", cur->mpd.name);
4695 snprintf(p, p_max_size, "%s", cur->mpd.file);
4698 snprintf(p, p_max_size, "%i", cur->mpd.volume);
4701 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
4704 snprintf(p, p_max_size, "%s", cur->mpd.status);
4707 int days = 0, hours = 0, minutes =
4709 int tmp = cur->mpd.elapsed;
4710 while (tmp >= 86400) {
4714 while (tmp >= 3600) {
4724 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
4725 days, hours, minutes,
4728 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4731 snprintf(p, p_max_size, "%i:%02i", minutes,
4735 int days = 0, hours = 0, minutes =
4737 int tmp = cur->mpd.length;
4738 while (tmp >= 86400) {
4742 while (tmp >= 3600) {
4752 snprintf(p, p_max_size,
4753 "%i days %i:%02i:%02i",
4754 days, hours, minutes,
4757 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4760 snprintf(p, p_max_size, "%i:%02i", minutes,
4764 snprintf(p, p_max_size, "%2.0f",
4765 cur->mpd.progress * 100);
4768 new_bar(p, obj->data.pair.a,
4770 (int) (cur->mpd.progress *
4774 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.title) < 2) {
4775 snprintf(p, p_max_size, "%s", cur->mpd.file);
4777 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
4783 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4786 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4789 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4792 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4794 OBJ(xmms2_comment) {
4795 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4797 OBJ(xmms2_decoder) {
4798 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
4800 OBJ(xmms2_transport) {
4801 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
4804 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4807 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4810 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4812 OBJ(xmms2_tracknr) {
4813 if (cur->xmms2.tracknr != -1)
4814 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4816 OBJ(xmms2_bitrate) {
4817 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4820 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4823 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4825 OBJ(xmms2_elapsed) {
4826 int tmp = cur->xmms2.elapsed;
4827 snprintf(p, p_max_size, "%02d:%02d",
4828 tmp / 60000, (tmp / 1000) % 60);
4830 OBJ(xmms2_duration) {
4831 int tmp = cur->xmms2.duration;
4832 snprintf(p, p_max_size, "%02d:%02d",
4833 tmp / 60000, (tmp / 1000) % 60);
4835 OBJ(xmms2_percent) {
4836 snprintf(p, p_max_size, "%2.0f",
4837 cur->xmms2.progress * 100);
4840 new_bar(p, obj->data.pair.a,
4842 (int) (cur->xmms2.progress *
4846 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
4847 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4849 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
4854 OBJ(audacious_status) {
4855 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
4857 OBJ(audacious_title) {
4858 snprintf(p, cur->audacious.max_title_len > 0 ?
4859 cur->audacious.max_title_len : p_max_size, "%s",
4860 cur->audacious.items[AUDACIOUS_TITLE]);
4862 OBJ(audacious_length) {
4863 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
4865 OBJ(audacious_length_seconds) {
4866 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4868 OBJ(audacious_position) {
4869 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
4871 OBJ(audacious_position_seconds) {
4872 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
4874 OBJ(audacious_bitrate) {
4875 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
4877 OBJ(audacious_frequency) {
4878 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
4880 OBJ(audacious_channels) {
4881 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
4883 OBJ(audacious_filename) {
4884 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
4886 OBJ(audacious_playlist_length) {
4887 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
4889 OBJ(audacious_playlist_position) {
4890 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
4892 OBJ(audacious_bar) {
4894 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
4895 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4896 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
4901 snprintf(p, p_max_size, "%s", cur->bmpx.title);
4904 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
4907 snprintf(p, p_max_size, "%s", cur->bmpx.album);
4910 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
4913 snprintf(p, p_max_size, "%i", cur->bmpx.track);
4916 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
4920 if (obj->data.top.type == TOP_NAME
4921 && obj->data.top.num >= 0
4922 && obj->data.top.num < 10) {
4923 snprintf(p, 17, "%-17s", cur->cpu[obj->data.top.num]->name);
4924 } else if (obj->data.top.type == TOP_CPU
4925 && obj->data.top.num >= 0
4926 && obj->data.top.num < 10) {
4927 snprintf(p, 7, "%7.3f",
4928 cur->cpu[obj->data.top.
4930 } else if (obj->data.top.type == TOP_PID
4931 && obj->data.top.num >= 0
4932 && obj->data.top.num < 10) {
4933 snprintf(p, 8, "%7i",
4934 cur->cpu[obj->data.top.
4936 } else if (obj->data.top.type == TOP_MEM
4937 && obj->data.top.num >= 0
4938 && obj->data.top.num < 10) {
4939 snprintf(p, 7, "%7.3f",
4940 cur->cpu[obj->data.top.
4945 if (obj->data.top.type == TOP_NAME
4946 && obj->data.top.num >= 0
4947 && obj->data.top.num < 10) {
4948 snprintf(p, 17, "%-17s",
4949 cur->memu[obj->data.top.
4951 } else if (obj->data.top.type == TOP_CPU
4952 && obj->data.top.num >= 0
4953 && obj->data.top.num < 10) {
4954 snprintf(p, 7, "%7.3f",
4955 cur->memu[obj->data.top.
4957 } else if (obj->data.top.type == TOP_PID
4958 && obj->data.top.num >= 0
4959 && obj->data.top.num < 10) {
4960 snprintf(p, 8, "%7i",
4961 cur->memu[obj->data.top.
4963 } else if (obj->data.top.type == TOP_MEM
4964 && obj->data.top.num >= 0
4965 && obj->data.top.num < 10) {
4966 snprintf(p, 7, "%7.3f",
4967 cur->memu[obj->data.top.
4974 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4975 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4977 obj->data.tail.last_update = current_update_time;
4981 fp = fopen(obj->data.tail.logfile, "rt");
4983 /* Send one message, but do not consistently spam on
4984 * missing logfiles. */
4985 if(obj->data.tail.readlines != 0) {
4986 ERR("tail logfile failed to open");
4987 strcpy(obj->data.tail.buffer, "Logfile Missing");
4989 obj->data.tail.readlines = 0;
4990 snprintf(p, p_max_size, "Logfile Missing");
4993 obj->data.tail.readlines = 0;
4994 /* -1 instead of 0 to avoid counting a trailing newline */
4995 fseek(fp, -1, SEEK_END);
4996 bsize = ftell(fp) + 1;
4997 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
4998 nl = rev_fcharfind(fp, '\n', iter);
5002 obj->data.tail.readlines = iter;
5003 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
5004 fseek(fp, 0, SEEK_SET);
5007 fseek(fp, nl+1, SEEK_SET);
5010 /* Make sure bsize is at least 1 byte smaller than
5011 * the buffer max size. */
5012 if(bsize > (long)((text_buffer_size*20) - 1)) {
5013 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
5014 bsize = text_buffer_size*20 - 1;
5016 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5019 /* Clean up trailing newline, make sure the buffer
5020 * is null terminated. */
5021 if(obj->data.tail.buffer[bsize-1] == '\n')
5022 obj->data.tail.buffer[bsize-1] = '\0';
5024 obj->data.tail.buffer[bsize] = '\0';
5025 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5028 strcpy(obj->data.tail.buffer, "Logfile Empty");
5029 snprintf(p, p_max_size, "Logfile Empty");
5032 } /* if cur_upd_time >= */
5034 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5038 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5039 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5041 obj->data.tail.last_update = current_update_time;
5045 fp = fopen(obj->data.tail.logfile, "rt");
5047 /* Send one message, but do not consistently spam on
5048 * missing logfiles. */
5049 if(obj->data.tail.readlines != 0) {
5050 ERR("head logfile failed to open");
5051 strcpy(obj->data.tail.buffer, "Logfile Missing");
5053 obj->data.tail.readlines = 0;
5054 snprintf(p, p_max_size, "Logfile Missing");
5056 obj->data.tail.readlines = 0;
5057 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5058 nl = fwd_fcharfind(fp, '\n', iter);
5062 obj->data.tail.readlines = iter;
5063 /* Make sure nl is at least 1 byte smaller than
5064 * the buffer max size. */
5065 if(nl > (long)((text_buffer_size*20) - 1)) {
5066 nl = text_buffer_size*20 - 1;
5068 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5071 /* Clean up trailing newline, make sure the buffer
5072 * is null terminated. */
5073 if (obj->data.tail.buffer[nl-1] == '\n') {
5074 obj->data.tail.buffer[nl-1] = '\0';
5077 obj->data.tail.buffer[nl] = '\0';
5079 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5082 strcpy(obj->data.tail.buffer, "Logfile Empty");
5083 snprintf(p, p_max_size, "Logfile Empty");
5085 } /* if fp == null */
5086 } /* cur_upd_time >= */
5088 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5091 #ifdef TCP_PORT_MONITOR
5094 /* grab a pointer to this port monitor */
5095 tcp_port_monitor_t * p_monitor =
5096 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
5097 obj->data.tcp_port_monitor.port_range_begin,
5098 obj->data.tcp_port_monitor.port_range_end );
5100 snprintf(p, p_max_size, "monitor not found");
5104 /* now grab the text of interest */
5105 if ( peek_tcp_port_monitor( p_monitor,
5106 obj->data.tcp_port_monitor.item,
5107 obj->data.tcp_port_monitor.connection_index,
5108 p, p_max_size ) != 0 )
5110 snprintf(p, p_max_size, "monitor peek error");
5119 iconv_converting = 1;
5120 iconv_selected = obj->a;
5125 iconv_converting = 0;
5131 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5133 OBJ(entropy_poolsize)
5135 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5139 double entropy_perc;
5140 entropy_perc = (double)cur->entropy.entropy_avail /
5141 (double)cur->entropy.poolsize;
5142 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5150 unsigned int a = strlen(p);
5153 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5155 size_t dummy1, dummy2;
5156 char *ptr = buff_in;
5159 dummy1 = dummy2 = a;
5161 strncpy(buff_in, p, P_MAX_SIZE);
5163 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5164 while (dummy1 > 0) {
5165 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5167 ERR("Iconv codeset conversion failed");
5172 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5183 double current_update_time, last_update_time;
5185 static void generate_text()
5187 struct information *cur = &info;
5195 current_update_time = get_time();
5198 /* fix diskio rates to b/s (use update_interval */
5199 diskio_read_value = diskio_read_value / update_interval;
5200 diskio_write_value = diskio_write_value / update_interval;
5201 diskio_value = diskio_value / update_interval;
5204 /* add things to the buffer */
5210 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5212 if (stuff_in_upper_case) {
5223 last_update_time = current_update_time;
5230 static void set_font()
5234 if (window.xftdraw != NULL) {
5235 XftDrawDestroy(window.xftdraw);
5237 window.xftdraw = XftDrawCreate(display, window.drawable,
5238 DefaultVisual(display,
5240 DefaultColormap(display,
5245 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5251 static inline int get_string_width(const char *s)
5254 return *s ? calc_text_width(s, strlen(s)) : 0;
5260 static inline int get_string_width_special(char *s)
5273 if (*p == SPECIAL_CHAR) {
5274 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5275 for (i = 0; i < strlen(p); i++) {
5276 *(p + i) = *(p + i + 1);
5278 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5279 width += specials[special_index+index].width;
5286 if (strlen(final) > 1) {
5287 width += calc_text_width(final, strlen(final));
5297 static void text_size_updater(char *s);
5299 int last_font_height;
5300 static void update_text_area()
5304 /* update text size if it isn't fixed */
5309 text_width = minimum_width;
5312 last_font_height = font_height();
5313 for_each_line(text_buffer, text_size_updater);
5315 if (text_height < minimum_height)
5316 text_height = minimum_height;
5317 if (text_width > maximum_width && maximum_width > 0)
5318 text_width = maximum_width;
5321 /* get text position on workarea */
5322 switch (text_alignment) {
5329 x = workarea[2] - text_width - gap_x;
5336 y = workarea[3] - text_height - gap_y;
5340 x = workarea[2] - text_width - gap_x;
5341 y = workarea[3] - text_height - gap_y;
5345 case NONE: // Let the WM manage the window
5356 if (own_window && !fixed_pos) {
5359 text_start_x = border_margin + 1;
5360 text_start_y = border_margin + 1;
5361 window.x = x - border_margin - 1;
5362 window.y = y - border_margin - 1;
5366 /* If window size doesn't match to workarea's size, then window
5367 * probably includes panels (gnome).
5368 * Blah, doesn't work on KDE. */
5369 if (workarea[2] != window.width
5370 || workarea[3] != window.height) {
5384 static int cur_x, cur_y; /* current x and y for drawing */
5385 static int draw_mode; /* FG, BG or OUTLINE */
5386 static long current_color;
5389 static void text_size_updater(char *s)
5393 /* get string widths and skip specials */
5396 if (*p == SPECIAL_CHAR) {
5398 w += get_string_width(s);
5401 if (specials[special_index].type == BAR
5402 || specials[special_index].type == GRAPH) {
5403 w += specials[special_index].width;
5404 if (specials[special_index].height > last_font_height) {
5405 last_font_height = specials[special_index].height;
5406 last_font_height += font_ascent();
5408 } else if (specials[special_index].type == OFFSET) {
5409 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
5410 } else if (specials[special_index].type == VOFFSET) {
5411 last_font_height += specials[special_index].arg;
5412 } else if (specials[special_index].type == GOTO) {
5413 if (specials[special_index].arg >= 0)
5414 w += (int)specials[special_index].arg - cur_x;
5415 } else if (specials[special_index].type == TAB) {
5416 int start = specials[special_index].arg;
5417 int step = specials[special_index].width;
5418 if (!step || step < 0)
5420 w += step - (cur_x - text_start_x - start) % step;
5421 } else if (specials[special_index].type == FONT) {
5422 selected_font = specials[special_index].font_added;
5423 if (font_height() > last_font_height) {
5424 last_font_height = font_height();
5433 w += get_string_width(s);
5434 if (w > text_width) {
5437 if (text_width > maximum_width && maximum_width) {
5438 text_width = maximum_width;
5441 text_height += last_font_height;
5442 last_font_height = font_height();
5446 static inline void set_foreground_color(long c)
5449 XSetForeground(display, window.gc, c);
5453 static void draw_string(const char *s)
5457 int i, i2, pos, width_of_s;
5460 width_of_s = get_string_width(s);
5461 if (out_to_console) {
5463 fflush(stdout); /* output immediately, don't buffer */
5465 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5466 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5467 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5471 snprintf(space, 2, " ");
5473 max = ((text_width - width_of_s) / get_string_width(space));
5476 * This code looks for tabs in the text and coverts them to spaces.
5477 * The trick is getting the correct number of spaces,
5478 * and not going over the window's size without forcing
5479 * the window larger.
5481 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5482 if (tmpstring1[i] == '\t') // 9 is ascii tab
5486 i2 < (8 - (1 + pos) % 8) && added <= max;
5489 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5490 fprintf(stderr,"buffer overrun detected\n");
5492 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5497 if (tmpstring1[i] != 9) {
5499 if ( pos > TEXT_BUFFER_SIZE-1 )
5500 fprintf(stderr,"buffer overrun detected\n");
5502 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5508 if (text_width == maximum_width) {
5509 /* this means the text is probably pushing the limit, so we'll chop it */
5510 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5511 tmpstring2[strlen(tmpstring2)-1] = '\0';
5521 c.pixel = current_color;
5522 XQueryColor(display, DefaultColormap(display, screen), &c);
5525 c2.color.red = c.red;
5526 c2.color.green = c.green;
5527 c2.color.blue = c.blue;
5528 c2.color.alpha = fonts[selected_font].font_alpha;
5530 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5531 cur_x, cur_y, (XftChar8 *) s,
5534 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5535 cur_x, cur_y, (XftChar8 *) s,
5541 XDrawString(display, window.drawable, window.gc,
5542 cur_x, cur_y, s, strlen(s));
5544 cur_x += width_of_s;
5546 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5549 long redmask, greenmask, bluemask;
5551 void set_up_gradient()
5554 colour_depth = DisplayPlanes(display, screen);
5558 if (colour_depth != 24 && colour_depth != 16) {
5559 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5565 for(i = (colour_depth / 3)-1; i>=0; i--) {
5567 greenmask |= 1 << i;
5570 if (colour_depth%3 == 1) {
5571 greenmask |= 1 << (colour_depth / 3);
5573 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5574 greenmask = greenmask << (colour_depth / 3);
5577 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 */
5579 int red1, green1, blue1; // first colour
5580 int red2, green2, blue2; // second colour
5581 int red3 = 0, green3 = 0, blue3 = 0; // difference
5582 short redshift = (2*colour_depth / 3 + colour_depth%3);
5583 short greenshift = (colour_depth / 3);
5584 red1 = (first_colour & redmask) >> redshift;
5585 green1 = (first_colour & greenmask) >> greenshift;
5586 blue1 = first_colour & bluemask;
5587 red2 = (last_colour & redmask) >> redshift;
5588 green2 = (last_colour & greenmask) >> greenshift;
5589 blue2 = last_colour & bluemask;
5596 if (green1 > green2) {
5599 if (green1 < green2) {
5602 if (blue1 > blue2) {
5605 if (blue1 < blue2) {
5620 if (red1 > bluemask) {
5623 if (green1 > bluemask) {
5626 if (blue1 > bluemask) {
5629 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
5633 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
5634 if (colour_depth == 0) {
5637 int red1, green1, blue1; // first colour
5638 int red2, green2, blue2; // second colour
5639 long redshift = (2*colour_depth / 3 + colour_depth%3);
5640 long greenshift = (colour_depth / 3);
5641 int red3 = 0, green3 = 0, blue3 = 0; // difference
5642 red1 = (first_colour & redmask) >> redshift;
5643 green1 = (first_colour & greenmask) >> greenshift;
5644 blue1 = first_colour & bluemask;
5645 red2 = (last_colour & redmask) >> redshift;
5646 green2 = (last_colour & greenmask) >> greenshift;
5647 blue2 = last_colour & bluemask;
5648 red3 = abs(red1 - red2);
5649 green3 = abs(green1 - green2);
5650 blue3 = abs(blue1 - blue2);
5659 static void draw_line(char *s)
5663 cur_x = text_start_x;
5664 cur_y += font_ascent();
5666 short font_h = font_height();
5668 /* find specials and draw stuff */
5671 if (*p == SPECIAL_CHAR) {
5674 /* draw string before special */
5681 switch (specials[special_index].type) {
5682 case HORIZONTAL_LINE:
5685 specials[special_index].height;
5686 int mid = font_ascent() / 2;
5687 w = text_start_x + text_width -
5690 XSetLineAttributes(display,
5695 XDrawLine(display, window.drawable,
5706 specials[special_index].height;
5708 specials[special_index].arg;
5709 int mid = font_ascent() / 2;
5710 char ss[2] = { s, s };
5711 w = text_start_x + text_width -
5714 XSetLineAttributes(display,
5719 XSetDashes(display, window.gc, 0,
5721 XDrawLine(display, window.drawable,
5731 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5735 specials[special_index].height;
5737 specials[special_index].arg;
5738 int by = cur_y - (font_ascent() / 2) - 1;
5739 if (h < font_height()) {
5742 w = specials[special_index].width;
5745 text_width - cur_x - 1;
5749 XSetLineAttributes(display,
5755 XDrawRectangle(display,
5759 XFillRectangle(display,
5763 w * bar_usage / 255,
5765 if (specials[special_index].
5767 && specials[special_index].
5771 [special_index].height;
5778 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5782 specials[special_index].height;
5783 unsigned long last_colour = current_color;
5784 int by = cur_y - (font_ascent()/2) - 1;
5785 if (h < font_height()) {
5788 w = specials[special_index].width;
5790 w = text_start_x + text_width - cur_x - 1;
5793 if (draw_graph_borders) {
5794 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
5795 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
5797 XSetLineAttributes(display,
5804 int gradient_size = 0;
5805 float gradient_factor = 0;
5806 float gradient_update = 0;
5807 unsigned long tmpcolour = current_color;
5808 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5809 tmpcolour = specials[special_index].last_colour;
5810 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
5811 gradient_factor = (float)gradient_size / (w - 2);
5813 for (i = w - 2; i > -1; i--) {
5814 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5815 XSetForeground(display, window.gc, tmpcolour);
5816 gradient_update += gradient_factor;
5817 while (gradient_update > 0) {
5818 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
5822 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
5825 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 */
5827 if (specials[special_index].
5829 && specials[special_index].
5833 [special_index].height;
5835 /* if (draw_mode == BG) {
5836 set_foreground_color(default_bg_color);
5838 else if (draw_mode == OUTLINE) {
5839 set_foreground_color(default_out_color);
5841 set_foreground_color(default_fg_color);
5843 set_foreground_color(last_colour);
5849 int old = font_ascent();
5850 cur_y -= font_ascent();
5851 selected_font = specials[special_index].font_added;
5852 if (cur_y + font_ascent() < cur_y + old) {
5855 cur_y += font_ascent();
5861 if (draw_mode == FG)
5862 set_foreground_color(specials
5868 if (draw_mode == BG)
5869 set_foreground_color(specials
5875 if (draw_mode == OUTLINE)
5876 set_foreground_color(specials
5882 w += specials[special_index].arg;
5886 cur_y += specials[special_index].arg;
5890 if (specials[special_index].arg >= 0)
5891 cur_x = (int)specials[special_index].arg;
5896 int start = specials[special_index].arg;
5897 int step = specials[special_index].width;
5898 if (!step || step < 0)
5900 w = step - (cur_x - text_start_x - start) % step;
5906 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
5907 /*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);*/
5908 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
5909 cur_x = pos_x - specials[special_index].arg;
5916 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
5917 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
5918 /*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);*/
5920 specials[special_index].arg)
5923 [special_index].arg;
5940 if (cur_y_add > 0) {
5942 cur_y -= font_descent();
5947 cur_y += font_descent();
5951 static void draw_text()
5954 cur_y = text_start_y;
5957 if (draw_borders && border_width > 0) {
5958 unsigned int b = (border_width + 1) / 2;
5960 if (stippled_borders) {
5962 { stippled_borders, stippled_borders };
5963 XSetLineAttributes(display, window.gc,
5964 border_width, LineOnOffDash,
5965 CapButt, JoinMiter);
5966 XSetDashes(display, window.gc, 0, ss, 2);
5968 XSetLineAttributes(display, window.gc,
5969 border_width, LineSolid,
5970 CapButt, JoinMiter);
5973 XDrawRectangle(display, window.drawable, window.gc,
5974 text_start_x - border_margin + b,
5975 text_start_y - border_margin + b,
5976 text_width + border_margin * 2 - 1 - b * 2,
5977 text_height + border_margin * 2 - 1 -
5984 for_each_line(text_buffer, draw_line);
5987 static void draw_stuff()
5991 if (draw_shades && !draw_outline) {
5994 set_foreground_color(default_bg_color);
6004 for (i = -1; i < 2; i++)
6005 for (j = -1; j < 2; j++) {
6006 if (i == 0 && j == 0)
6010 set_foreground_color(default_out_color);
6011 draw_mode = OUTLINE;
6018 set_foreground_color(default_fg_color);
6026 swap.swap_window = window.window;
6027 swap.swap_action = XdbeBackground;
6028 XdbeSwapBuffers(display, &swap, 1);
6034 static void clear_text(int exposures)
6038 return; /* The swap action is XdbeBackground, which clears */
6042 /* there is some extra space for borders and outlines */
6043 XClearArea(display, window.window,
6044 text_start_x - border_margin - 1,
6045 text_start_y - border_margin - 1,
6046 text_width + border_margin * 2 + 2,
6047 text_height + border_margin * 2 + 2,
6048 exposures ? True : 0);
6053 static int need_to_update;
6055 /* update_text() generates new text and clears old text area */
6056 static void update_text()
6065 static void main_loop()
6067 #ifdef SIGNAL_BLOCKING
6068 sigset_t newmask, oldmask;
6070 sigemptyset(&newmask);
6071 sigaddset(&newmask,SIGINT);
6072 sigaddset(&newmask,SIGTERM);
6073 sigaddset(&newmask,SIGUSR1);
6077 Region region = XCreateRegion();
6079 int event_base, error_base;
6080 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
6081 ERR("Xdamage extension unavailable");
6083 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
6084 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
6085 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
6086 #endif /* HAVE_XDAMAGE */
6090 while (total_run_times == 0 || info.looped < total_run_times) {
6093 #ifdef SIGNAL_BLOCKING
6094 /* block signals. we will inspect for pending signals later */
6095 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
6096 CRIT_ERR("unable to sigprocmask()");
6102 /* wait for X event or timeout */
6104 if (!XPending(display)) {
6109 update_interval - (get_time() -
6115 tv.tv_sec = (long) t;
6116 tv.tv_usec = (long) (t * 1000000) % 1000000;
6118 FD_SET(ConnectionNumber(display), &fdsr);
6121 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
6124 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
6129 ERR("can't select(): %s",
6140 if (need_to_update) {
6142 int wx = window.x, wy = window.y;
6150 /* resize window if it isn't right size */
6152 (text_width + border_margin * 2 + 1 !=
6154 || text_height + border_margin * 2 + 1 !=
6158 border_margin * 2 + 1;
6161 border_margin * 2 + 1;
6162 XResizeWindow(display,
6167 set_transparent_background(window.window);
6171 /* move window if it isn't in right position */
6174 || window.y != wy)) {
6175 XMoveWindow(display, window.window,
6176 window.x, window.y);
6186 r.x = text_start_x - border_margin;
6187 r.y = text_start_y - border_margin;
6188 r.width = text_width + border_margin * 2;
6189 r.height = text_height + border_margin * 2;
6190 XUnionRectWithRegion(&r, region, region);
6195 /* handle X events */
6197 while (XPending(display)) {
6199 XNextEvent(display, &ev);
6206 r.width = ev.xexpose.width;
6207 r.height = ev.xexpose.height;
6208 XUnionRectWithRegion(&r, region,
6214 case ReparentNotify:
6215 /* set background to ParentRelative for all parents */
6217 set_transparent_background(window.
6222 case ConfigureNotify:
6224 /* if window size isn't what expected, set fixed size */
6225 if (ev.xconfigure.width !=
6227 || ev.xconfigure.height !=
6229 if (window.width != 0
6230 && window.height != 0)
6233 /* clear old stuff before screwing up size and pos */
6239 if (XGetWindowAttributes(display, window.window, &attrs)) {
6254 border_margin * 2 - 1;
6257 border_margin * 2 - 1;
6258 if (text_width > maximum_width && maximum_width > 0)
6259 text_width = maximum_width;
6262 /* if position isn't what expected, set fixed pos, total_updates
6263 * avoids setting fixed_pos when window is set to weird locations
6265 /*if (total_updates >= 2 this is broken
6267 && (window.x != ev.xconfigure.x
6270 && (ev.xconfigure.x != 0
6271 || ev.xconfigure.y != 0)) {
6281 /* if an ordinary window with decorations */
6282 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6284 /* allow conky to hold input focus.*/
6289 /* forward the click to the desktop window */
6290 XUngrabPointer(display, ev.xbutton.time);
6291 ev.xbutton.window = window.desktop;
6292 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6293 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6301 /* if an ordinary window with decorations */
6302 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6304 /* allow conky to hold input focus.*/
6309 /* forward the release to the desktop window */
6310 ev.xbutton.window = window.desktop;
6311 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6320 if (ev.type == event_base + XDamageNotify) {
6321 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6322 XFixesSetRegion(display, part, &dev->area, 1);
6323 XFixesUnionRegion(display, region2, region2, part);
6325 #endif /* HAVE_XDAMAGE */
6330 XDamageSubtract(display, damage, region2, None);
6331 XFixesSetRegion(display, region2, 0, 0);
6332 #endif /* HAVE_XDAMAGE */
6334 /* XDBE doesn't seem to provide a way to clear the back buffer without
6335 * interfering with the front buffer, other than passing XdbeBackground
6336 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6337 * redraw the text even if it wasn't part of the exposed area. OTOH,
6338 * if we're not going to call draw_stuff at all, then no swap happens
6339 * and we can safely do nothing.
6342 if (!XEmptyRegion(region)) {
6346 r.x = text_start_x - border_margin;
6347 r.y = text_start_y - border_margin;
6348 r.width = text_width + border_margin * 2;
6349 r.height = text_height + border_margin * 2;
6350 XUnionRectWithRegion(&r, region, region);
6353 XSetRegion(display, window.gc, region);
6356 XftDrawSetClip(window.xftdraw, region);
6362 XDestroyRegion(region);
6363 region = XCreateRegion();
6367 #ifdef SIGNAL_BLOCKING
6368 /* unblock signals of interest and let handler fly */
6369 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6370 CRIT_ERR("unable to sigprocmask()");
6373 switch(g_signal_pending) {
6376 ERR("received SIGUSR1. reloading the config file.");
6383 ERR("received SIGINT or SIGTERM to terminate. bye!");
6386 XDestroyRegion(region);
6389 return; /* return from main_loop */
6394 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6395 * but didn't write any code to deal with it. if you don't want to
6396 * handle a signal, don't set a handler on it in the first place. */
6397 if (g_signal_pending)
6398 ERR("ignoring signal (%d)", g_signal_pending);
6405 #if defined(X11) && defined(HAVE_XDAMAGE)
6406 XDamageDestroy(display, damage);
6407 XFixesDestroyRegion(display, region2);
6408 XFixesDestroyRegion(display, part);
6409 XDestroyRegion(region);
6411 #endif /* X11 && HAVE_XDAMAGE */
6414 static void load_config_file(const char *);
6416 /* reload the config file */
6417 void reload_config(void)
6419 timed_thread_destroy_registered_threads ();
6421 if (info.cpu_usage) {
6422 free(info.cpu_usage);
6423 info.cpu_usage = NULL;
6426 #ifdef TCP_PORT_MONITOR
6427 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6430 if (current_config) {
6432 load_config_file(current_config);
6434 /* re-init specials array */
6435 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6436 ERR("failed to realloc specials array");
6441 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6444 #ifdef TCP_PORT_MONITOR
6445 info.p_tcp_port_monitor_collection = NULL;
6448 if (create_audacious_thread() !=0)
6449 CRIT_ERR("unable to create audacious thread!");
6450 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6452 extract_variable_text(text);
6461 timed_thread_destroy_registered_threads ();
6463 if (info.cpu_usage) {
6464 free(info.cpu_usage);
6465 info.cpu_usage = NULL;
6470 XdbeDeallocateBackBufferName(display, window.back_buffer);
6476 XDestroyWindow(display, window.window);
6477 XClearWindow(display, RootWindow(display, screen));
6483 XClearWindow(display, RootWindow(display, screen));
6488 XFreeGC(display, window.gc);
6491 free_text_objects(text_object_count, text_objects);
6492 text_object_count = 0;
6493 text_objects = NULL;
6495 if (text != original_text)
6498 free(current_config);
6499 free(current_mail_spool);
6501 #ifdef TCP_PORT_MONITOR
6502 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6503 info.p_tcp_port_monitor_collection = NULL;
6511 for(i=0;i<special_count;i++)
6512 if(specials[i].type == GRAPH)
6513 free(specials[i].graph);
6519 static int string_to_bool(const char *s)
6523 if (strcasecmp(s, "yes") == 0)
6525 if (strcasecmp(s, "true") == 0)
6527 if (strcasecmp(s, "1") == 0)
6532 static enum alignment string_to_alignment(const char *s)
6534 if (strcasecmp(s, "top_left") == 0)
6536 else if (strcasecmp(s, "top_right") == 0)
6538 else if (strcasecmp(s, "bottom_left") == 0)
6540 else if (strcasecmp(s, "bottom_right") == 0)
6541 return BOTTOM_RIGHT;
6542 else if (strcasecmp(s, "tl") == 0)
6544 else if (strcasecmp(s, "tr") == 0)
6546 else if (strcasecmp(s, "bl") == 0)
6548 else if (strcasecmp(s, "br") == 0)
6549 return BOTTOM_RIGHT;
6550 else if (strcasecmp(s, "none") == 0)
6557 static void set_default_configurations(void)
6559 fork_to_background = 0;
6560 total_run_times = 0;
6561 info.cpu_avg_samples = 2;
6562 info.net_avg_samples = 2;
6567 strcpy(info.mpd.host, "localhost");
6568 info.mpd.port = 6600;
6569 info.mpd.status = NULL;
6570 info.mpd.artist = NULL;
6571 info.mpd.album = NULL;
6572 info.mpd.title = NULL;
6573 info.mpd.random = NULL;
6574 info.mpd.track = NULL;
6575 info.mpd.name = NULL;
6576 info.mpd.file = NULL;
6579 info.xmms2.artist = NULL;
6580 info.xmms2.album = NULL;
6581 info.xmms2.title = NULL;
6582 info.xmms2.genre = NULL;
6583 info.xmms2.comment = NULL;
6584 info.xmms2.decoder = NULL;
6585 info.xmms2.transport = NULL;
6586 info.xmms2.url = NULL;
6587 info.xmms2.status = NULL;
6590 #if defined(__linux__)
6592 #endif /* __linux__ */
6599 default_fg_color = WhitePixel(display, screen);
6600 default_bg_color = BlackPixel(display, screen);
6601 default_out_color = BlackPixel(display, screen);
6602 color0 = default_fg_color;
6603 color1 = default_fg_color;
6604 color2 = default_fg_color;
6605 color3 = default_fg_color;
6606 color4 = default_fg_color;
6607 color5 = default_fg_color;
6608 color6 = default_fg_color;
6609 color7 = default_fg_color;
6610 color8 = default_fg_color;
6611 color9 = default_fg_color;
6614 draw_graph_borders = 1;
6616 set_first_font("6x10");
6624 window.type=TYPE_NORMAL;
6626 strcpy(window.class_name, "Conky");
6628 sprintf(window.title,"%s - conky",info.uname_s.nodename);
6630 stippled_borders = 0;
6633 text_alignment = BOTTOM_LEFT;
6636 free(current_mail_spool);
6639 variable_substitute(MAIL_FILE, buf, 256);
6641 current_mail_spool = strdup(buf);
6645 update_interval = 10.0;
6646 stuff_in_upper_case = 0;
6648 #ifdef TCP_PORT_MONITOR
6649 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6653 static void load_config_file(const char *f)
6655 #define CONF_ERR ERR("%s: %d: config file error", f, line)
6659 set_default_configurations();
6665 char buf[256], *p, *p2, *name, *value;
6667 if (fgets(buf, 256, fp) == NULL)
6672 /* break at comment */
6673 p2 = strchr(p, '#');
6678 while (*p && isspace((int) *p))
6681 continue; /* empty line */
6687 while (*p2 && !isspace((int) *p2))
6690 *p2 = '\0'; /* break at name's end */
6697 while (*p && isspace((int) *p))
6702 p2 = value + strlen(value);
6703 while (isspace((int) *(p2 - 1)))
6709 #define CONF2(a) if (strcasecmp(name, a) == 0)
6710 #define CONF(a) else CONF2(a)
6711 #define CONF3(a,b) \
6712 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
6716 CONF2("alignment") {
6718 int a = string_to_alignment(value);
6726 CONF("background") {
6727 fork_to_background = string_to_bool(value);
6731 CONF2("background") {
6732 fork_to_background = string_to_bool(value);
6736 CONF("border_margin") {
6738 border_margin = strtol(value, 0, 0);
6742 CONF("border_width") {
6744 border_width = strtol(value, 0, 0);
6750 color0 = get_x11_color(value);
6756 color1 = get_x11_color(value);
6762 color2 = get_x11_color(value);
6768 color3 = get_x11_color(value);
6774 color4 = get_x11_color(value);
6780 color5 = get_x11_color(value);
6786 color6 = get_x11_color(value);
6792 color7 = get_x11_color(value);
6798 color8 = get_x11_color(value);
6804 color9 = get_x11_color(value);
6808 CONF("default_color") {
6810 default_fg_color = get_x11_color(value);
6814 CONF3("default_shade_color", "default_shadecolor") {
6816 default_bg_color = get_x11_color(value);
6820 CONF3("default_outline_color", "default_outlinecolor") {
6822 default_out_color = get_x11_color(value);
6829 info.mail = parse_mail_args(IMAP, value);
6836 info.mail = parse_mail_args(POP3, value);
6844 strncpy(info.mpd.host, value, 127);
6850 info.mpd.port = strtol(value, 0, 0);
6851 if (info.mpd.port < 1
6852 || info.mpd.port > 0xffff)
6856 CONF("mpd_password") {
6858 strncpy(info.mpd.password, value, 127);
6864 CONF("sensor_device") {
6866 sensor_device = strtol(value, 0, 0);
6871 CONF("cpu_avg_samples") {
6873 cpu_avg_samples = strtol(value, 0, 0);
6874 if (cpu_avg_samples < 1
6875 || cpu_avg_samples > 14)
6884 CONF("net_avg_samples") {
6886 net_avg_samples = strtol(value, 0, 0);
6887 if (net_avg_samples < 1
6888 || net_avg_samples > 14)
6904 CONF("double_buffer") {
6905 use_xdbe = string_to_bool(value);
6909 CONF("override_utf8_locale") {
6910 utf8_mode = string_to_bool(value);
6913 CONF("draw_borders") {
6914 draw_borders = string_to_bool(value);
6916 CONF("draw_graph_borders") {
6917 draw_graph_borders = string_to_bool(value);
6919 CONF("draw_shades") {
6920 draw_shades = string_to_bool(value);
6922 CONF("draw_outline") {
6923 draw_outline = string_to_bool(value);
6925 #if defined(__linux__)
6926 CONF("post_21_kernel") {
6927 post_21_kernel = string_to_bool(value);
6929 #endif /* __linux__ */
6931 CONF("out_to_console") {
6932 out_to_console = string_to_bool(value);
6934 CONF("use_spacer") {
6935 use_spacer = string_to_bool(value);
6940 use_xft = string_to_bool(value);
6944 set_first_font(value);
6949 if (value && font_count >= 0)
6950 fonts[0].font_alpha = atof(value)
6959 if (string_to_bool(value))
6960 ERR("Xft not enabled");
6963 /* xftfont silently ignored when no Xft */
6966 /* xftalpha is silently ignored when no Xft */
6971 set_first_font(value);
6980 gap_x = atoi(value);
6986 gap_y = atoi(value);
6991 CONF("mail_spool") {
6994 variable_substitute(value, buf, 256);
6998 if (current_mail_spool)
6999 free(current_mail_spool);
7000 current_mail_spool = strdup(buf);
7006 CONF("minimum_size") {
7009 (value, "%d %d", &minimum_width,
7010 &minimum_height) != 2)
7013 &minimum_width) != 1)
7018 CONF("maximum_width") {
7020 if (sscanf(value, "%d", &maximum_width) != 1)
7026 CONF("no_buffers") {
7027 no_buffers = string_to_bool(value);
7029 CONF("pad_percents") {
7030 pad_percents = atoi(value);
7034 CONF("own_window") {
7036 own_window = string_to_bool(value);
7040 CONF("own_window_class") {
7043 memset(window.class_name,0,sizeof(window.class_name));
7044 strncpy(window.class_name, value, sizeof(window.class_name)-1);
7049 CONF("own_window_title") {
7052 memset(window.title,0,sizeof(window.title));
7053 strncpy(window.title, value, sizeof(window.title)-1);
7058 CONF("own_window_transparent") {
7060 set_transparent = string_to_bool(value);
7064 CONF("own_window_colour") {
7066 background_colour = get_x11_color(value);
7068 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
7071 CONF("own_window_hints") {
7073 char *p_hint, *p_save;
7074 char delim[] = ", ";
7076 /* tokenize the value into individual hints */
7077 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
7079 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
7080 if (strncmp(p_hint,"undecorate",10) == 0)
7081 SET_HINT(window.hints,HINT_UNDECORATED);
7082 else if (strncmp(p_hint,"below",5) == 0)
7083 SET_HINT(window.hints,HINT_BELOW);
7084 else if (strncmp(p_hint,"above",5) == 0)
7085 SET_HINT(window.hints,HINT_ABOVE);
7086 else if (strncmp(p_hint,"sticky",6) == 0)
7087 SET_HINT(window.hints,HINT_STICKY);
7088 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
7089 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
7090 else if (strncmp(p_hint,"skip_pager",10) == 0)
7091 SET_HINT(window.hints,HINT_SKIP_PAGER);
7095 p_hint=strtok_r(NULL, delim, &p_save);
7097 while (p_hint!=NULL);
7102 CONF("own_window_type") {
7104 if (strncmp(value,"normal",6)==0)
7105 window.type = TYPE_NORMAL;
7106 else if (strncmp(value,"desktop",7)==0)
7107 window.type = TYPE_DESKTOP;
7108 else if (strncmp(value,"override",8)==0)
7109 window.type = TYPE_OVERRIDE;
7117 CONF("stippled_borders") {
7119 stippled_borders = strtol(value, 0, 0);
7121 stippled_borders = 4;
7125 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
7128 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
7130 CONF("update_interval") {
7132 update_interval = strtod(value, 0);
7136 CONF("total_run_times") {
7138 total_run_times = strtod(value, 0);
7143 stuff_in_upper_case = string_to_bool(value);
7145 CONF("max_specials") {
7147 max_specials = atoi(value);
7151 CONF("max_user_text") {
7153 max_user_text = atoi(value);
7157 CONF("text_buffer_size") {
7159 text_buffer_size = atoi(value);
7164 if (text != original_text)
7174 int l = strlen(text);
7175 if (fgets(buf, 256, fp) == NULL)
7178 realloc(text, l + strlen(buf)
7182 if (strlen(text) > max_user_text)
7186 text_lines = line + 1;
7189 #ifdef TCP_PORT_MONITOR
7190 CONF("max_port_monitor_connections")
7193 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7194 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
7196 /* an error. use default, warn and continue. */
7197 tcp_port_monitor_args.max_port_monitor_connections =
7198 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7201 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
7203 /* no error, just use default */
7204 tcp_port_monitor_args.max_port_monitor_connections =
7205 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7207 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
7212 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7224 /* : means that character before that takes an argument */
7225 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
7238 int main(int argc, char **argv)
7240 struct sigaction act, oact;
7243 memset(&info, 0, sizeof(info) );
7245 #ifdef TCP_PORT_MONITOR
7246 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7249 /* handle command line parameters that don't change configs */
7254 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7255 *s) || ((s = getenv("LANG")) && *s)) {
7256 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7258 ERR("malloc failed");
7260 for (x = 0; x < strlen(s); x++) {
7261 temp[x] = tolower(s[x]);
7264 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7270 if (!setlocale(LC_CTYPE, "")) {
7271 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7275 int c = getopt(argc,
7286 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
7287 * though free() does the NULL check itself;), then load optarg value */
7289 free(current_config);
7290 current_config = strdup(optarg);
7295 ("Usage: %s [OPTION]...\n"
7296 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7297 "window. Command line options will override configurations defined in config\n"
7300 " -c FILE config file to load instead of "
7303 " -d daemonize, fork to background\n"
7306 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7307 " -f FONT font to use\n"
7309 " -o create own window to draw\n"
7312 " -b double buffer (prevents flickering)\n"
7314 " -w WIN_ID window id to draw\n"
7315 " -x X x position\n"
7316 " -y Y y position\n"
7318 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
7319 " -u SECS update interval\n"
7320 " -i NUM number of times to update Conky\n", argv[0]);
7324 window.window = strtol(optarg, 0, 0);
7333 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7337 /* load current_config or CONFIG_FILE */
7340 if (current_config == NULL) {
7341 /* load default config file */
7344 variable_substitute(CONFIG_FILE, buf, 256);
7347 current_config = strdup(buf);
7351 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
7352 load_config_file(current_config);
7354 set_default_configurations();
7357 /* init specials array */
7358 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7359 ERR("failed to create specials array");
7362 if (current_mail_spool == NULL) {
7364 variable_substitute(MAIL_FILE, buf, 256);
7367 current_mail_spool = strdup(buf);
7371 /* handle other command line arguments */
7373 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
7374 optind = optreset = 1;
7379 #if defined(__FreeBSD__)
7380 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7381 O_RDONLY, "kvm_open")) == NULL)
7382 CRIT_ERR( "cannot read kvm");
7386 int c = getopt(argc,
7394 fork_to_background = 1;
7399 set_first_font(optarg);
7402 text_alignment = string_to_alignment(optarg);
7417 if (text != original_text)
7419 text = strdup(optarg);
7420 convert_escapes(text);
7424 update_interval = strtod(optarg, 0);
7428 total_run_times = strtod(optarg, 0);
7432 gap_x = atoi(optarg);
7436 gap_y = atoi(optarg);
7450 /* generate text and get initial size */
7451 extract_variable_text(text);
7452 if (text != original_text) {
7457 if (fork_to_background) {
7461 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
7467 fprintf(stderr,"\n"); fflush(stderr);
7471 /* parent process */
7472 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
7479 update_text_area(); /* to get initial size of the window */
7483 text_width + border_margin * 2 + 1,
7484 text_height + border_margin * 2 + 1,
7485 set_transparent, background_colour, argv, argc);
7488 update_text_area(); /* to position text/window on screen */
7493 if (own_window && !fixed_pos) {
7494 XMoveWindow(display, window.window, window.x, window.y);
7497 set_transparent_background(window.window);
7508 /* Set signal handlers */
7509 act.sa_handler = signal_handler;
7510 sigemptyset(&act.sa_mask);
7513 act.sa_flags |= SA_RESTART;
7516 if ( sigaction(SIGINT,&act,&oact) < 0 ||
7517 sigaction(SIGUSR1,&act,&oact) < 0 ||
7518 sigaction(SIGTERM,&act,&oact) < 0 )
7520 ERR("error setting signal handler: %s", strerror(errno) );
7524 if (create_audacious_thread() !=0)
7525 CRIT_ERR("unable to create audacious thread!");
7526 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
7537 #if defined(__FreeBSD__)
7544 void signal_handler(int sig)
7546 /* signal handler is light as a feather, as it should be.
7547 * we will poll g_signal_pending with each loop of conky
7548 * and do any signal processing there, NOT here. */
7549 g_signal_pending=sig;