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");
2607 END OBJ(linkstatus, INFO_WIFI)
2609 obj->data.net = get_net_stat(arg);
2612 CRIT_ERR("linkstatus needs argument");
2619 ERR("tail needs arguments");
2620 obj->type = OBJ_text;
2621 obj->data.s = strdup("${tail}");
2624 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2625 if (n1 < 1 || n1 > 30) {
2626 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2630 fp = fopen(buf, "r");
2632 obj->data.tail.logfile =
2633 malloc(text_buffer_size);
2634 strcpy(obj->data.tail.logfile, buf);
2635 obj->data.tail.wantedlines = n1;
2636 obj->data.tail.interval =
2637 update_interval * 2;
2641 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2644 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2645 if (n1 < 1 || n1 > 30) {
2647 ("invalid arg for tail, number of lines must be between 1 and 30");
2649 } else if (n2 < 1 || n2 < update_interval) {
2651 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2655 fp = fopen(buf, "r");
2657 obj->data.tail.logfile =
2658 malloc(text_buffer_size);
2659 strcpy(obj->data.tail.logfile, buf);
2660 obj->data.tail.wantedlines = n1;
2661 obj->data.tail.interval = n2;
2665 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2671 ERR("invalid args given for tail");
2674 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2679 ERR("head needs arguments");
2680 obj->type = OBJ_text;
2681 obj->data.s = strdup("${head}");
2684 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2685 if (n1 < 1 || n1 > 30) {
2686 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2690 fp = fopen(buf, "r");
2692 obj->data.tail.logfile =
2693 malloc(text_buffer_size);
2694 strcpy(obj->data.tail.logfile, buf);
2695 obj->data.tail.wantedlines = n1;
2696 obj->data.tail.interval =
2697 update_interval * 2;
2701 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2704 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2705 if (n1 < 1 || n1 > 30) {
2707 ("invalid arg for head, number of lines must be between 1 and 30");
2709 } else if (n2 < 1 || n2 < update_interval) {
2711 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2715 fp = fopen(buf, "r");
2717 obj->data.tail.logfile =
2718 malloc(text_buffer_size);
2719 strcpy(obj->data.tail.logfile, buf);
2720 obj->data.tail.wantedlines = n1;
2721 obj->data.tail.interval = n2;
2725 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2731 ERR("invalid args given for head");
2734 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2735 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2737 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2738 if (r >= 3 && (c < 1 || c > 3))
2740 if (r >= 2 && (b < 1 || b > 3))
2742 if (r >= 1 && (a < 1 || a > 3))
2745 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2746 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2747 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2748 END OBJ(if_empty, 0)
2749 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2750 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2753 ERR("if_empty needs an argument");
2754 obj->data.ifblock.s = 0;
2756 obj->data.ifblock.s = strdup(arg);
2757 blockstart[blockdepth] = object_count;
2758 obj->data.ifblock.pos = object_count + 2;
2760 END OBJ(if_existing, 0)
2761 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2762 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2765 ERR("if_existing needs an argument or two");
2766 obj->data.ifblock.s = NULL;
2767 obj->data.ifblock.str = NULL;
2769 char buf1[256], buf2[256];
2770 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2772 obj->data.ifblock.s = strdup(buf1);
2773 obj->data.ifblock.str = NULL;
2775 obj->data.ifblock.s = strdup(buf1);
2776 obj->data.ifblock.str = strdup(buf2);
2779 blockstart[blockdepth] = object_count;
2780 obj->data.ifblock.pos = object_count + 2;
2782 END OBJ(if_mounted, 0)
2783 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2784 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2787 ERR("if_mounted needs an argument");
2788 obj->data.ifblock.s = 0;
2790 obj->data.ifblock.s = strdup(arg);
2791 blockstart[blockdepth] = object_count;
2792 obj->data.ifblock.pos = object_count + 2;
2794 END OBJ(if_running, 0)
2795 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2796 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2800 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2801 obj->data.ifblock.s = strdup(buf);
2803 ERR("if_running needs an argument");
2804 obj->data.ifblock.s = 0;
2806 blockstart[blockdepth] = object_count;
2807 obj->data.ifblock.pos = object_count + 2;
2811 END OBJ(mails, INFO_MAIL)
2812 END OBJ(mboxscan, 0)
2813 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
2814 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
2815 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2816 obj->data.mboxscan.output[0] = 1;
2817 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
2818 END OBJ(mem, INFO_MEM)
2819 END OBJ(memmax, INFO_MEM)
2820 END OBJ(memperc, INFO_MEM)
2821 END OBJ(membar, INFO_MEM)
2822 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2823 END OBJ(memgraph, INFO_MEM)
2824 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2825 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2826 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2827 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2828 END OBJ(mixerbar, INFO_MIXER)
2829 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2830 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2831 END OBJ(mixerlbar, INFO_MIXER)
2832 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2833 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2834 END OBJ(mixerrbar, INFO_MIXER)
2835 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2836 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2838 OBJ(new_mails, INFO_MAIL)
2839 END OBJ(nodename, 0)
2840 END OBJ(processes, INFO_PROCS)
2841 END OBJ(running_processes, INFO_RUN_PROCS)
2842 END OBJ(shadecolor, 0)
2844 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2846 END OBJ(outlinecolor, 0)
2848 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2850 END OBJ(stippled_hr, 0)
2852 int a = stippled_borders, b = 1;
2854 if (sscanf(arg, "%d %d", &a, &b) != 2)
2855 sscanf(arg, "%d", &b);
2859 obj->data.pair.a = a;
2860 obj->data.pair.b = b;
2862 END OBJ(swap, INFO_MEM)
2863 END OBJ(swapmax, INFO_MEM)
2864 END OBJ(swapperc, INFO_MEM)
2865 END OBJ(swapbar, INFO_MEM)
2866 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2867 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
2869 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
2870 obj->data.i2c.devtype);
2871 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
2873 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
2874 obj->data.i2c.devtype);
2875 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2876 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2878 char buf1[256], buf2[256], *fmt, *tz;
2881 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2890 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
2891 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
2893 END OBJ(iconv_start, 0)
2894 if (iconv_converting) {
2895 CRIT_ERR("You must stop your last iconv conversion before starting another");
2898 char iconv_from[CODEPAGE_LENGTH];
2899 char iconv_to[CODEPAGE_LENGTH];
2900 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2901 CRIT_ERR("Invalid arguments for iconv_start");
2904 new_iconv = iconv_open(iconv_to, iconv_from);
2905 if (new_iconv == (iconv_t)(-1)) {
2906 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2908 obj->a = register_iconv(&new_iconv);
2909 iconv_converting = 1;
2913 CRIT_ERR("Iconv requires arguments");
2915 END OBJ(iconv_stop, 0)
2916 iconv_converting = 0;
2919 END OBJ(totaldown, INFO_NET)
2921 obj->data.net = get_net_stat(arg);
2924 CRIT_ERR("totaldown needs argument");
2926 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
2928 obj->data.net = get_net_stat(arg);
2931 CRIT_ERR("totalup needs argument");
2934 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
2935 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
2936 END OBJ(upspeed, INFO_NET)
2938 obj->data.net = get_net_stat(arg);
2941 CRIT_ERR("upspeed needs argument");
2943 END OBJ(upspeedf, INFO_NET)
2945 obj->data.net = get_net_stat(arg);
2948 CRIT_ERR("upspeedf needs argument");
2951 END OBJ(upspeedgraph, INFO_NET)
2952 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2954 sscanf(arg, "%63s %*i,%*i %*i", buf);
2955 obj->data.net = get_net_stat(buf);
2956 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2957 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
2962 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
2963 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
2964 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2965 OBJ(apm_adapter, 0) END
2966 OBJ(apm_battery_life, 0) END
2967 OBJ(apm_battery_time, 0) END
2968 #endif /* __FreeBSD__ */
2972 obj->data.mail = parse_mail_args(IMAP, arg);
2973 obj->global_mode = 0;
2975 obj->global_mode = 1;
2978 OBJ(imap_messages, 0)
2981 obj->data.mail = parse_mail_args(IMAP, arg);
2982 obj->global_mode = 0;
2984 obj->global_mode = 1;
2990 obj->data.mail = parse_mail_args(POP3, arg);
2991 obj->global_mode = 0;
2993 obj->global_mode = 1;
2999 obj->data.mail = parse_mail_args(POP3, arg);
3000 obj->global_mode = 0;
3002 obj->global_mode = 1;
3006 OBJ(mpd_artist, INFO_MPD) END
3007 OBJ(mpd_title, INFO_MPD)
3011 sscanf (arg, "%d", &info.mpd.max_title_len);
3012 if (info.mpd.max_title_len > 0)
3013 info.mpd.max_title_len++;
3015 CRIT_ERR ("mpd_title: invalid length argument");
3018 END OBJ(mpd_random, INFO_MPD)
3019 END OBJ(mpd_repeat, INFO_MPD)
3020 END OBJ(mpd_elapsed, INFO_MPD)
3021 END OBJ(mpd_length, INFO_MPD)
3022 END OBJ(mpd_track, INFO_MPD)
3023 END OBJ(mpd_name, INFO_MPD)
3024 END OBJ(mpd_file, INFO_MPD)
3025 END OBJ(mpd_percent, INFO_MPD)
3026 END OBJ(mpd_album, INFO_MPD)
3027 END OBJ(mpd_vol, INFO_MPD)
3028 END OBJ(mpd_bitrate, INFO_MPD)
3029 END OBJ(mpd_status, INFO_MPD)
3030 END OBJ(mpd_bar, INFO_MPD)
3031 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3032 END OBJ(mpd_smart, INFO_MPD) END
3035 OBJ(xmms2_artist, INFO_XMMS2)
3036 END OBJ(xmms2_album, INFO_XMMS2)
3037 END OBJ(xmms2_title, INFO_XMMS2)
3038 END OBJ(xmms2_genre, INFO_XMMS2)
3039 END OBJ(xmms2_comment, INFO_XMMS2)
3040 END OBJ(xmms2_decoder, INFO_XMMS2)
3041 END OBJ(xmms2_transport, INFO_XMMS2)
3042 END OBJ(xmms2_url, INFO_XMMS2)
3043 END OBJ(xmms2_tracknr, INFO_XMMS2)
3044 END OBJ(xmms2_bitrate, INFO_XMMS2)
3045 END OBJ(xmms2_date, INFO_XMMS2)
3046 END OBJ(xmms2_id, INFO_XMMS2)
3047 END OBJ(xmms2_duration, INFO_XMMS2)
3048 END OBJ(xmms2_elapsed, INFO_XMMS2)
3049 END OBJ(xmms2_size, INFO_XMMS2)
3050 END OBJ(xmms2_status, INFO_XMMS2)
3051 END OBJ(xmms2_percent, INFO_XMMS2)
3052 END OBJ(xmms2_bar, INFO_XMMS2)
3053 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3054 END OBJ(xmms2_smart, INFO_XMMS2)
3058 OBJ(audacious_status, INFO_AUDACIOUS) END
3059 OBJ(audacious_title, INFO_AUDACIOUS)
3063 sscanf (arg, "%d", &info.audacious.max_title_len);
3064 if (info.audacious.max_title_len > 0)
3065 info.audacious.max_title_len++;
3067 CRIT_ERR ("audacious_title: invalid length argument");
3071 OBJ(audacious_length, INFO_AUDACIOUS) END
3072 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3073 OBJ(audacious_position, INFO_AUDACIOUS) END
3074 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3075 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3076 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3077 OBJ(audacious_channels, INFO_AUDACIOUS) END
3078 OBJ(audacious_filename, INFO_AUDACIOUS) END
3079 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3080 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3081 OBJ(audacious_bar, INFO_AUDACIOUS)
3082 (void) scan_bar(arg, &obj->a, &obj->b);
3086 OBJ(bmpx_title, INFO_BMPX)
3087 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3089 OBJ(bmpx_artist, INFO_BMPX)
3090 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3092 OBJ(bmpx_album, INFO_BMPX)
3093 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3095 OBJ(bmpx_track, INFO_BMPX)
3096 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3098 OBJ(bmpx_uri, INFO_BMPX)
3099 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3101 OBJ(bmpx_bitrate, INFO_BMPX)
3102 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3108 int argc, delay, act_par;
3109 char *uri = (char *)malloc(128 * sizeof(char));
3110 char *action = (char *)malloc(64 * sizeof(char));
3112 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par);
3113 obj->data.rss.uri = uri;
3114 obj->data.rss.delay = delay;
3115 obj->data.rss.action = action;
3116 obj->data.rss.act_par = act_par;
3120 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
3126 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3127 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3128 ERR("hddtemp needs arguments");
3129 obj->type = OBJ_text;
3130 obj->data.s = strdup("${hddtemp}");
3135 #ifdef TCP_PORT_MONITOR
3136 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3137 int argc, port_begin, port_end, item, connection_index;
3139 memset(itembuf,0,sizeof(itembuf));
3141 /* massive argument checking */
3143 CRIT_ERR("tcp_portmon: needs arguments");
3145 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3146 if ( (argc != 3) && (argc != 4) )
3148 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3150 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3152 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3154 if ( port_begin > port_end )
3156 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3158 if ( strncmp(itembuf,"count",31) == 0 )
3160 else if ( strncmp(itembuf,"rip",31) == 0 )
3162 else if ( strncmp(itembuf,"rhost",31) == 0 )
3164 else if ( strncmp(itembuf,"rport",31) == 0 )
3166 else if ( strncmp(itembuf,"rservice",31) == 0 )
3168 else if ( strncmp(itembuf,"lip",31) == 0 )
3170 else if ( strncmp(itembuf,"lhost",31) == 0 )
3172 else if ( strncmp(itembuf,"lport",31) == 0 )
3174 else if ( strncmp(itembuf,"lservice",31) == 0 )
3178 CRIT_ERR("tcp_portmon: invalid item specified");
3180 if ( (argc==3) && (item!=COUNT) )
3182 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3184 if ( (argc==4) && (connection_index<0) )
3186 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3188 /* ok, args looks good. save the text object data */
3189 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3190 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3191 obj->data.tcp_port_monitor.item = item;
3192 obj->data.tcp_port_monitor.connection_index = connection_index;
3194 /* if the port monitor collection hasn't been created, we must create it */
3195 if ( !info.p_tcp_port_monitor_collection )
3197 info.p_tcp_port_monitor_collection =
3198 create_tcp_port_monitor_collection ();
3199 if ( !info.p_tcp_port_monitor_collection )
3201 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3205 /* if a port monitor for this port does not exist, create one and add it to the collection */
3206 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3208 tcp_port_monitor_t * p_monitor =
3209 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3212 CRIT_ERR("tcp_portmon: unable to create port monitor");
3214 /* add the newly created monitor to the collection */
3215 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3218 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3223 OBJ(entropy_avail, INFO_ENTROPY) END
3224 OBJ(entropy_poolsize, INFO_ENTROPY) END
3225 OBJ(entropy_bar, INFO_ENTROPY)
3226 (void) scan_bar(arg, &obj->a, &obj->b);
3231 ERR("unknown variable %s", s);
3232 obj->type = OBJ_text;
3233 snprintf(buf, 256, "${%s}", s);
3234 obj->data.s = strdup(buf);
3241 static struct text_object *create_plain_text(const char *s)
3243 struct text_object *obj;
3245 if (s == NULL || *s == '\0') {
3249 obj = new_text_object_internal();
3251 obj->type = OBJ_text;
3252 obj->data.s = strdup(s);
3256 static struct text_object_list *extract_variable_text_internal(const char *p)
3258 struct text_object_list *retval;
3259 struct text_object *obj;
3262 retval = malloc(sizeof(struct text_object_list));
3263 memset(retval, 0, sizeof(struct text_object_list));
3264 retval->text_object_count = 0;
3266 long line = text_lines;
3274 obj = create_plain_text(s);
3276 // allocate memory for the object
3277 retval->text_objects = realloc(retval->text_objects,
3278 sizeof(struct text_object) * (retval->text_object_count+1));
3279 // assign the new object to the end of the list.
3280 memcpy(&retval->text_objects[retval->text_object_count++],
3281 obj, sizeof(struct text_object));
3293 /* variable is either $foo or ${foo} */
3295 unsigned int brl = 1, brr = 0;
3298 while (*p && brl != brr) {
3299 if (*p == '{') brl++;
3300 if (*p == '}') brr++;
3308 while (*p && (isalnum((int) *p)
3313 /* copy variable to buffer */
3314 len = (p - s > 255) ? 255 : (p - s);
3315 strncpy(buf, s, len);
3324 /* if variable wasn't found from environment, use some special */
3330 if (strchr(buf, ' ')) {
3331 arg = strchr(buf, ' ');
3334 while (isspace((int) *arg))
3340 /* lowercase variable name */
3347 // create new object
3348 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3350 // allocate memory for the object
3351 retval->text_objects = realloc(retval->text_objects,
3352 sizeof(struct text_object) * (retval->text_object_count+1));
3353 // assign the new object to the end of the list.
3354 memcpy(&retval->text_objects[retval->text_object_count++],
3355 obj, sizeof(struct text_object));
3361 obj = create_plain_text("$");
3363 // allocate memory for the object
3364 retval->text_objects = realloc(retval->text_objects,
3365 sizeof(struct text_object) * (retval->text_object_count+1));
3366 // assign the new object to the end of the list.
3367 memcpy(&retval->text_objects[retval->text_object_count++],
3368 obj, sizeof(struct text_object));
3375 obj = create_plain_text(s);
3377 // allocate memory for the object
3378 retval->text_objects = realloc(retval->text_objects,
3379 sizeof(struct text_object) * (retval->text_object_count+1));
3380 // assign the new object to the end of the list.
3381 memcpy(&retval->text_objects[retval->text_object_count++],
3382 obj, sizeof(struct text_object));
3387 ERR("one or more $endif's are missing");
3393 static void extract_variable_text(const char *p)
3395 struct text_object_list *list;
3397 free_text_objects(text_object_count, text_objects);
3398 text_object_count = 0;
3399 text_objects = NULL;
3402 list = extract_variable_text_internal(p);
3403 text_objects = list->text_objects;
3404 text_object_count = list->text_object_count;
3411 void parse_conky_vars(char * text, char * p, struct information *cur) {
3412 struct text_object_list *object_list = extract_variable_text_internal(text);
3413 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3417 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3422 char buff_in[P_MAX_SIZE] = {0};
3423 iconv_converting = 0;
3426 for (i = 0; i < object_count; i++) {
3427 struct text_object *obj = &objs[i];
3429 #define OBJ(a) break; case OBJ_##a:
3431 switch (obj->type) {
3434 ERR("not implemented obj type %d",
3438 /* does anyone have decimals in acpi temperature? */
3440 snprintf(p, p_max_size, "%d", (int)
3441 get_acpi_temperature(obj->
3445 snprintf(p, 5, "%d ", (int)
3446 get_acpi_temperature(obj->
3451 /* does anyone have decimals in acpi temperature? */
3453 snprintf(p, p_max_size, "%d", (int)
3454 ((get_acpi_temperature(obj->
3456 i)+ 40) * 9.0 / 5 - 40));
3458 snprintf(p, 5, "%d ", (int)
3459 ((get_acpi_temperature(obj->
3461 i)+ 40) * 9.0 / 5 - 40));
3465 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3470 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3473 #if defined(__linux__)
3476 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3481 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3484 #endif /* __linux__ */
3488 get_freq_dynamic(p, 6, "%.0f ", 1 );
3490 get_freq_dynamic(p, p_max_size, "%.0f", 1 );
3495 get_freq_dynamic(p, 6, "%'.2f ", 1000);
3497 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3501 get_adt746x_cpu(p, p_max_size);
3504 get_adt746x_fan(p, p_max_size);
3507 get_acpi_fan(p, p_max_size);
3509 OBJ(acpiacadapter) {
3510 get_acpi_ac_adapter(p, p_max_size);
3513 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3516 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3518 OBJ(battery_percent) {
3519 snprintf(p, p_max_size, "%d",
3520 get_battery_perct(obj->data.s));
3523 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3526 human_readable(cur->buffers * 1024, p, 255);
3529 human_readable(cur->cached * 1024, p, 255);
3532 if (obj->data.cpu_index > info.cpu_count) {
3533 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3534 CRIT_ERR("attempting to use more CPUs then you have!");
3537 snprintf(p, p_max_size, "%*d", pad_percents,
3538 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3541 snprintf(p, 4, "%*d ",
3543 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3549 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3552 new_graph(p, obj->a,
3553 obj->b, obj->c, obj->d,
3554 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3558 new_fg(p, obj->data.l);
3590 #if defined(__linux__)
3592 snprintf(p, p_max_size, "%s", i8k.version);
3595 snprintf(p, p_max_size, "%s", i8k.bios);
3598 snprintf(p, p_max_size, "%s", i8k.serial);
3601 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3603 OBJ(i8k_cpu_tempf) {
3605 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3606 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3608 OBJ(i8k_left_fan_status) {
3609 int left_fan_status;
3610 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3611 if(left_fan_status == 0) {
3612 snprintf(p, p_max_size,"off");
3613 } if(left_fan_status == 1) {
3614 snprintf(p, p_max_size, "low");
3615 } if(left_fan_status == 2) {
3616 snprintf(p, p_max_size, "high");
3620 OBJ(i8k_right_fan_status) {
3621 int right_fan_status;
3622 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3623 if(right_fan_status == 0) {
3624 snprintf(p, p_max_size,"off");
3625 } if(right_fan_status == 1) {
3626 snprintf(p, p_max_size, "low");
3627 } if(right_fan_status == 2) {
3628 snprintf(p, p_max_size, "high");
3631 OBJ(i8k_left_fan_rpm) {
3632 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3634 OBJ(i8k_right_fan_rpm) {
3635 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3637 OBJ(i8k_ac_status) {
3639 sscanf(i8k.ac_status, "%d", &ac_status);
3640 if(ac_status == -1) {
3641 snprintf(p, p_max_size,"disabled (read i8k docs)");
3642 } if(ac_status == 0) {
3643 snprintf(p, p_max_size, "off");
3644 } if(ac_status == 1) {
3645 snprintf(p, p_max_size, "on");
3648 OBJ(i8k_buttons_status) {
3649 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3653 get_ibm_acpi_fan(p, p_max_size);
3656 get_ibm_acpi_temps();
3657 snprintf(p, p_max_size, "%d",
3658 ibm_acpi.temps[obj->data.sensor]);
3661 get_ibm_acpi_volume(p, p_max_size);
3663 OBJ(ibm_brightness) {
3664 get_ibm_acpi_brightness(p, p_max_size);
3667 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3669 #endif /* __linux__ */
3672 OBJ(obsd_sensors_temp) {
3673 obsd_sensors.device = sensor_device;
3674 update_obsd_sensors();
3675 snprintf(p, p_max_size, "%.1f",
3676 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
3679 OBJ(obsd_sensors_fan) {
3680 obsd_sensors.device = sensor_device;
3681 update_obsd_sensors();
3682 snprintf(p, p_max_size, "%d",
3683 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3686 OBJ(obsd_sensors_volt) {
3687 obsd_sensors.device = sensor_device;
3688 update_obsd_sensors();
3689 snprintf(p, p_max_size, "%.2f",
3690 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3694 get_obsd_vendor(p, p_max_size);
3698 get_obsd_product(p, p_max_size);
3700 #endif /* __OpenBSD__ */
3704 new_font(p, obj->data.s);
3707 void format_diskio(unsigned int diskio_value)
3710 if (diskio_value > 1024*1024) {
3711 snprintf(p, p_max_size, "%.1fGiB",
3712 (double)diskio_value/1024/1024);
3713 } else if (diskio_value > 1024) {
3714 snprintf(p, p_max_size, "%.1fMiB",
3715 (double)diskio_value/1024);
3716 } else if (diskio_value > 0) {
3717 snprintf(p, p_max_size, "%dKiB", diskio_value);
3719 snprintf(p, p_max_size, "%dB", diskio_value);
3722 if (diskio_value > 1024*1024) {
3723 snprintf(p, 12, "%.1fGiB ",
3724 (double)diskio_value/1024/1024);
3725 } else if (diskio_value > 1024) {
3726 snprintf(p, 12, "%.1fMiB ",
3727 (double)diskio_value/1024);
3728 } else if (diskio_value > 0) {
3729 snprintf(p, 12, "%dKiB ", diskio_value);
3731 snprintf(p, 12, "%dB ", diskio_value);
3736 format_diskio(diskio_value);
3739 format_diskio(diskio_write_value);
3742 format_diskio(diskio_read_value);
3745 new_graph(p, obj->a,
3746 obj->b, obj->c, obj->d,
3747 diskio_value, obj->e, 1);
3749 OBJ(diskiograph_read) {
3750 new_graph(p, obj->a,
3751 obj->b, obj->c, obj->d,
3752 diskio_read_value, obj->e, 1);
3754 OBJ(diskiograph_write) {
3755 new_graph(p, obj->a,
3756 obj->b, obj->c, obj->d,
3757 diskio_write_value, obj->e, 1);
3761 snprintf(p, p_max_size, "%d",
3762 (int) (obj->data.net->
3766 snprintf(p, 6, "%d ",
3767 (int) (obj->data.net->
3773 snprintf(p, p_max_size, "%.1f",
3775 recv_speed / 1024.0);
3777 snprintf(p, 8, "%.1f ",
3779 recv_speed / 1024.0);
3781 OBJ(downspeedgraph) {
3783 if (obj->data.net->recv_speed == 0)
3784 obj->data.net->recv_speed = 0.01;
3786 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3787 (obj->data.net->recv_speed /
3788 1024.0), obj->e, 1);
3792 i = obj->data.ifblock.pos - 1;
3802 snprintf(p, p_max_size, "%u.%u.%u.%u",
3803 obj->data.net->addr.
3805 obj->data.net->addr.
3807 obj->data.net->addr.
3809 obj->data.net->addr.
3815 snprintf(p, p_max_size, "%d",
3816 obj->data.net->linkstatus);
3819 snprintf(p, 5, "%4d ",
3820 obj->data.net->linkstatus);
3823 #if defined(IMLIB2) && defined(X11)
3828 Imlib_Image image, buffer;
3829 image = imlib_load_image(obj->data.s);
3830 imlib_context_set_image(image);
3833 w = imlib_image_get_width();
3834 h = imlib_image_get_height();
3835 buffer = imlib_create_image(w, h);
3836 imlib_context_set_display(display);
3837 imlib_context_set_drawable(window.drawable);
3838 imlib_context_set_colormap(DefaultColormap(display, screen));
3839 imlib_context_set_visual(DefaultVisual(display, screen));
3840 imlib_context_set_image(buffer);
3841 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
3842 imlib_render_image_on_drawable(text_start_x, text_start_y);
3844 imlib_context_set_image(image);
3851 FILE *fp = popen(obj->data.s, "r");
3852 int length = fread(p, 1, p_max_size, fp);
3855 /*output[length] = '\0';
3856 if (length > 0 && output[length - 1] == '\n') {
3857 output[length - 1] = '\0';
3860 if (length > 0 && p[length - 1] == '\n') {
3861 p[length - 1] = '\0';
3864 //parse_conky_vars(output, p, cur);
3868 FILE *fp = popen(obj->data.s, "r");
3869 int n2 = fread(p, 1, p_max_size, fp);
3873 if (n2 && p[n2 - 1] == '\n')
3882 if (sscanf(p, "%lf", &barnum) == 0) {
3883 ERR("reading execbar value failed (perhaps it's not the correct format?)");
3885 if (barnum > 100 || barnum < 0) {
3886 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
3888 barnum = barnum / 100.0;
3889 new_bar(p, 0, 4, (int) (barnum * 255.0));
3895 FILE *fp = popen(obj->data.s, "r");
3896 int n2 = fread(p, 1, p_max_size, fp);
3900 if (n2 && p[n2 - 1] == '\n')
3909 if (sscanf(p, "%lf", &barnum) == 0) {
3910 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
3912 if (barnum > 100 || barnum < 0) {
3913 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
3915 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
3920 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3921 new_bar(p, 0, 4, (int) obj->f);
3924 FILE *fp = popen(obj->data.execi.cmd, "r");
3925 int n2 = fread(p, 1, p_max_size, fp);
3928 if (n2 && p[n2 - 1] == '\n')
3937 if (sscanf(p, "%f", &barnum) == 0) {
3938 ERR("reading execibar value failed (perhaps it's not the correct format?)");
3940 if (barnum > 100 || barnum < 0) {
3941 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
3943 obj->f = 255 * barnum / 100.0;
3944 new_bar(p, 0, 4, (int) obj->f);
3946 obj->data.execi.last_update =
3947 current_update_time;
3951 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3952 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
3955 FILE *fp = popen(obj->data.execi.cmd, "r");
3956 int n2 = fread(p, 1, p_max_size, fp);
3959 if (n2 && p[n2 - 1] == '\n')
3968 if (sscanf(p, "%f", &barnum) == 0) {
3969 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
3971 if (barnum > 100 || barnum < 0) {
3972 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
3975 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
3977 obj->data.execi.last_update = current_update_time;
3983 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
3984 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
3986 char *output = obj->data.execi.buffer;
3987 FILE *fp = popen(obj->data.execi.cmd, "r");
3988 //int length = fread(output, 1, text_buffer_size, fp);
3989 int length = fread(output, 1, text_buffer_size, fp);
3992 output[length] = '\0';
3993 if (length > 0 && output[length - 1] == '\n') {
3994 output[length - 1] = '\0';
3996 obj->data.execi.last_update = current_update_time;
3997 snprintf(p, p_max_size, "%s", output);
3999 //parse_conky_vars(output, p, cur);
4002 if (!obj->data.texeci.p_timed_thread)
4004 obj->data.texeci.p_timed_thread=
4005 timed_thread_create ((void*)threaded_exec, (void*) obj,
4006 obj->data.texeci.interval * 1000000);
4007 if (!obj->data.texeci.p_timed_thread)
4008 ERR("Error starting texeci thread");
4009 timed_thread_register (obj->data.texeci.p_timed_thread,
4010 &obj->data.texeci.p_timed_thread);
4012 timed_thread_lock (obj->data.texeci.p_timed_thread);
4013 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4014 timed_thread_unlock (obj->data.texeci.p_timed_thread);
4016 #endif /* HAVE_POPEN */
4018 if (obj->global_mode && info.mail) { // this means we use info
4019 if (!info.mail->p_timed_thread)
4021 info.mail->p_timed_thread =
4022 timed_thread_create ((void*)imap_thread,
4024 info.mail->interval * 1000000);
4025 if (!info.mail->p_timed_thread)
4026 ERR("Error starting imap thread");
4027 timed_thread_register (info.mail->p_timed_thread,
4028 &info.mail->p_timed_thread);
4030 timed_thread_lock (info.mail->p_timed_thread);
4031 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4032 timed_thread_unlock (info.mail->p_timed_thread);
4033 } else if (obj->data.mail) { // this means we use obj
4034 if (!obj->data.mail->p_timed_thread)
4036 obj->data.mail->p_timed_thread =
4037 timed_thread_create ((void*)imap_thread,
4038 (void*)obj->data.mail,
4039 obj->data.mail->interval * 1000000);
4040 if (!obj->data.mail->p_timed_thread)
4041 ERR("Error starting imap thread");
4042 timed_thread_register (obj->data.mail->p_timed_thread,
4043 &obj->data.mail->p_timed_thread);
4045 timed_thread_lock (obj->data.mail->p_timed_thread);
4046 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4047 timed_thread_unlock (obj->data.mail->p_timed_thread);
4048 } else if (!obj->a) { // something is wrong, warn once then stop
4049 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4053 OBJ(imap_messages) {
4054 if (obj->global_mode && info.mail) { // this means we use info
4055 if (!info.mail->p_timed_thread)
4057 info.mail->p_timed_thread =
4058 timed_thread_create ((void*)imap_thread,
4060 info.mail->interval * 1000000);
4061 if (!info.mail->p_timed_thread)
4062 ERR("Error starting imap thread");
4063 timed_thread_register (info.mail->p_timed_thread,
4064 &info.mail->p_timed_thread);
4066 timed_thread_lock (info.mail->p_timed_thread);
4067 snprintf(p, p_max_size, "%lu", info.mail->messages);
4068 timed_thread_unlock (info.mail->p_timed_thread);
4069 } else if (obj->data.mail) { // this means we use obj
4070 if (!obj->data.mail->p_timed_thread)
4072 obj->data.mail->p_timed_thread =
4073 timed_thread_create ((void*)imap_thread,
4074 (void*)obj->data.mail,
4075 obj->data.mail->interval * 1000000);
4076 if (!obj->data.mail->p_timed_thread)
4077 ERR("Error starting imap thread");
4078 timed_thread_register (obj->data.mail->p_timed_thread,
4079 &obj->data.mail->p_timed_thread);
4081 timed_thread_lock (obj->data.mail->p_timed_thread);
4082 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4083 timed_thread_lock (obj->data.mail->p_timed_thread);
4084 } else if (!obj->a) { // something is wrong, warn once then stop
4085 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4090 if (obj->global_mode && info.mail) { // this means we use info
4091 if (!info.mail->p_timed_thread)
4093 info.mail->p_timed_thread =
4094 timed_thread_create ((void*)pop3_thread,
4096 info.mail->interval * 1000000);
4097 if (!info.mail->p_timed_thread)
4098 ERR("Error starting pop3 thread");
4099 timed_thread_register (info.mail->p_timed_thread,
4100 &info.mail->p_timed_thread);
4102 timed_thread_lock (info.mail->p_timed_thread);
4103 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4104 timed_thread_unlock (info.mail->p_timed_thread);
4105 } else if (obj->data.mail) { // this means we use obj
4106 if (!obj->data.mail->p_timed_thread)
4108 obj->data.mail->p_timed_thread =
4109 timed_thread_create ((void*)pop3_thread,
4110 (void*)obj->data.mail,
4111 obj->data.mail->interval * 1000000);
4112 if (!obj->data.mail->p_timed_thread)
4113 ERR("Error starting pop3 thread");
4114 timed_thread_register (obj->data.mail->p_timed_thread,
4115 &obj->data.mail->p_timed_thread);
4117 timed_thread_lock (obj->data.mail->p_timed_thread);
4118 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4119 timed_thread_unlock (obj->data.mail->p_timed_thread);
4120 } else if (!obj->a) { // something is wrong, warn once then stop
4121 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4126 if (obj->global_mode && info.mail) { // this means we use info
4127 if (!info.mail->p_timed_thread)
4129 info.mail->p_timed_thread =
4130 timed_thread_create ((void*)pop3_thread,
4132 info.mail->interval * 1000000);
4133 if (!info.mail->p_timed_thread)
4134 ERR("Error starting pop3 thread");
4135 timed_thread_register (info.mail->p_timed_thread,
4136 &info.mail->p_timed_thread);
4138 timed_thread_lock (info.mail->p_timed_thread);
4139 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4140 timed_thread_unlock (info.mail->p_timed_thread);
4141 } else if (obj->data.mail) { // this means we use obj
4142 if (!obj->data.mail->p_timed_thread)
4144 obj->data.mail->p_timed_thread =
4145 timed_thread_create ((void*)pop3_thread,
4146 (void*)obj->data.mail,
4147 obj->data.mail->interval * 1000000);
4148 if (!obj->data.mail->p_timed_thread)
4149 ERR("Error starting pop3 thread");
4150 timed_thread_register (obj->data.mail->p_timed_thread,
4151 &obj->data.mail->p_timed_thread);
4153 timed_thread_lock (obj->data.mail->p_timed_thread);
4154 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4155 timed_thread_unlock (obj->data.mail->p_timed_thread);
4156 } else if (!obj->a) { // something is wrong, warn once then stop
4157 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4162 if (obj->data.fs != NULL) {
4163 if (obj->data.fs->size == 0)
4182 if (obj->data.fs != NULL)
4183 human_readable(obj->data.fs->avail,
4187 if (obj->data.fs != NULL) {
4188 if (obj->data.fs->size)
4189 snprintf(p, p_max_size, "%*d",
4198 snprintf(p, p_max_size, "0");
4202 if (obj->data.fs != NULL)
4203 human_readable(obj->data.fs->size,
4207 if (obj->data.fs != NULL)
4208 human_readable(obj->data.fs->size -
4209 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
4213 if (obj->data.fs != NULL) {
4214 if (obj->data.fs->size == 0)
4232 if (obj->data.fs != NULL) {
4233 if (obj->data.fs->size)
4234 snprintf(p, 4, "%d",
4244 snprintf(p, p_max_size, "0");
4248 float *v = info.loadavg;
4250 if (obj->data.loadavg[2])
4251 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4252 v[obj->data.loadavg[0] -
4254 v[obj->data.loadavg[1] -
4256 v[obj->data.loadavg[2] -
4258 else if (obj->data.loadavg[1])
4259 snprintf(p, p_max_size, "%.2f %.2f",
4260 v[obj->data.loadavg[0] -
4262 v[obj->data.loadavg[1] -
4264 else if (obj->data.loadavg[0])
4265 snprintf(p, p_max_size, "%.2f",
4266 v[obj->data.loadavg[0] -
4270 new_goto(p, obj->data.i);
4273 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4276 new_hr(p, obj->data.i);
4280 PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay);
4283 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4285 if(!strcmp(obj->data.rss.action, "feed_title")) {
4287 if(str[strlen(str)-1] == '\n')
4288 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4289 snprintf(p, p_max_size, "%s", str);
4290 } else if(!strcmp(obj->data.rss.action, "item_title")) {
4291 if(obj->data.rss.act_par < data->item_count) {
4292 str = data->items[obj->data.rss.act_par].title;
4293 if(str[strlen(str)-1] == '\n')
4294 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4295 snprintf(p, p_max_size, "%s", str);
4297 } else if(!strcmp(obj->data.rss.action, "item_desc")) {
4298 if(obj->data.rss.act_par < data->item_count) {
4299 str = data->items[obj->data.rss.act_par].description;
4300 if(str[strlen(str)-1] == '\n')
4301 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4302 snprintf(p, p_max_size, "%s", str);
4304 } else if(!strcmp(obj->data.rss.action, "item_titles")) {
4305 if(data->item_count > 0) {
4309 if(obj->data.rss.act_par > data->item_count)
4310 show = data->item_count;
4311 else show = obj->data.rss.act_par;
4312 for(itmp = 0; itmp < show; itmp++) {
4313 PRSS_Item *item = &data->items[itmp];
4316 if(itmp>0) // don't add new line before first item
4317 strncat(p, "\n", p_max_size);
4318 if(str[strlen(str)-1] == '\n')
4319 str[strlen(str)-1] = 0; // remove trailing new line if one exists, we have our own
4320 strncat(p, str, p_max_size);
4333 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4334 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4336 snprintf(p, p_max_size, "N/A");
4337 } else if (unit == '*') {
4338 snprintf(p, p_max_size, "%s", temp);
4340 snprintf(p, p_max_size, "%s°%c", temp, unit);
4345 new_offset(p, obj->data.i);
4348 new_voffset(p, obj->data.i);
4353 r = get_i2c_info(&obj->data.i2c.fd,
4355 obj->data.i2c.devtype,
4356 obj->data.i2c.type);
4358 if (r >= 100.0 || r == 0)
4359 snprintf(p, p_max_size, "%d", (int) r);
4361 snprintf(p, p_max_size, "%.1f", r);
4364 new_alignr(p, obj->data.i);
4367 new_alignc(p, obj->data.i);
4370 struct information *my_info =
4371 malloc(sizeof(struct information));
4372 memcpy(my_info, cur, sizeof(struct information));
4373 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4374 if (strlen(p) != 0) {
4375 i = obj->data.ifblock.pos;
4385 if ((obj->data.ifblock.s)
4386 && (stat(obj->data.ifblock.s, &tmp) ==
4388 i = obj->data.ifblock.pos;
4391 if (obj->data.ifblock.str) {
4392 if (!check_contains(obj->data.ifblock.s,
4393 obj->data.ifblock.str)) {
4394 i = obj->data.ifblock.pos;
4403 if ((obj->data.ifblock.s)
4404 && (!check_mount(obj->data.ifblock.s))) {
4405 i = obj->data.ifblock.pos;
4412 if ((obj->data.ifblock.s)
4413 && system(obj->data.ifblock.s)) {
4414 i = obj->data.ifblock.pos;
4421 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4424 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4429 human_readable(cur->mem * 1024, p, 255);
4432 human_readable(cur->memmax * 1024, p, 255);
4437 snprintf(p, p_max_size, "%*Lu",
4442 snprintf(p, 4, "%*Lu ",
4449 new_bar(p, obj->data.pair.a,
4451 cur->memmax ? (cur->mem * 255) /
4456 new_graph(p, obj->a,
4457 obj->b, obj->c, obj->d,
4458 cur->memmax ? (cur->mem * 100.0) /
4459 (cur->memmax) : 0.0, 100, 1);
4463 snprintf(p, p_max_size, "%d",
4464 mixer_get_avg(obj->data.l));
4467 snprintf(p, p_max_size, "%d",
4468 mixer_get_left(obj->data.l));
4471 snprintf(p, p_max_size, "%d",
4472 mixer_get_right(obj->data.l));
4475 new_bar(p, obj->data.mixerbar.w,
4476 obj->data.mixerbar.h,
4477 mixer_get_avg(obj->data.mixerbar.
4481 new_bar(p, obj->data.mixerbar.w,
4482 obj->data.mixerbar.h,
4483 mixer_get_left(obj->data.mixerbar.
4487 new_bar(p, obj->data.mixerbar.w,
4488 obj->data.mixerbar.h,
4489 mixer_get_right(obj->data.mixerbar.
4495 snprintf(p, p_max_size, "%d", cur->mail_count);
4498 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4499 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4502 snprintf(p, p_max_size, "%d", cur->new_mail_count);
4506 snprintf(p, p_max_size, "%s",
4507 cur->uname_s.nodename);
4510 new_outline(p, obj->data.l);
4514 snprintf(p, p_max_size, "%hu", cur->procs);
4516 snprintf(p, 5, "%hu ",
4519 OBJ(running_processes) {
4521 snprintf(p, p_max_size, "%hu",
4524 snprintf(p, 3, "%hu ",
4528 snprintf(p, p_max_size, "%s", obj->data.s);
4531 new_bg(p, obj->data.l);
4534 new_stippled_hr(p, obj->data.pair.a,
4538 human_readable(cur->swap * 1024, p, 255);
4541 human_readable(cur->swapmax * 1024, p,
4545 if (cur->swapmax == 0) {
4546 strncpy(p, "No swap", 255);
4549 snprintf(p, 255, "%*Lu",
4555 snprintf(p, 4, "%*Lu ",
4563 new_bar(p, obj->data.pair.a,
4565 cur->swapmax ? (cur->swap * 255) /
4566 (cur->swapmax) : 0);
4569 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4572 time_t t = time(NULL);
4573 struct tm *tm = localtime(&t);
4574 setlocale(LC_TIME, "");
4575 strftime(p, p_max_size, obj->data.s, tm);
4578 time_t t = time(NULL);
4579 struct tm *tm = gmtime(&t);
4580 strftime(p, p_max_size, obj->data.s, tm);
4584 if (obj->data.tztime.tz) {
4585 oldTZ = getenv("TZ");
4586 setenv("TZ", obj->data.tztime.tz, 1);
4589 time_t t = time(NULL);
4590 struct tm *tm = localtime(&t);
4591 setlocale(LC_TIME, "");
4592 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4594 setenv("TZ", oldTZ, 1);
4599 // Needless to free oldTZ since getenv gives ptr to static data
4602 human_readable(obj->data.net->recv, p,
4606 human_readable(obj->data.net->trans, p,
4610 snprintf(p, p_max_size, "%d", total_updates);
4614 snprintf(p, p_max_size, "%d",
4615 (int) (obj->data.net->
4619 snprintf(p, 6, "%d ",
4620 (int) (obj->data.net->
4626 snprintf(p, p_max_size, "%.1f",
4628 trans_speed / 1024.0);
4630 snprintf(p, 8, "%.1f ",
4632 trans_speed / 1024.0);
4636 if (obj->data.net->trans_speed == 0)
4637 obj->data.net->trans_speed = 0.01;
4639 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4640 (obj->data.net->trans_speed /
4641 1024.0), obj->e, 1);
4644 format_seconds_short(p, p_max_size,
4648 format_seconds(p, p_max_size, (int) cur->uptime);
4651 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4654 msg = get_apm_adapter();
4655 snprintf(p, p_max_size, "%s", msg);
4658 OBJ(apm_battery_life) {
4660 msg = get_apm_battery_life();
4661 snprintf(p, p_max_size, "%s", msg);
4664 OBJ(apm_battery_time) {
4666 msg = get_apm_battery_time();
4667 snprintf(p, p_max_size, "%s", msg);
4670 #endif /* __FreeBSD__ __OpenBSD__ */
4674 snprintf(p, cur->mpd.max_title_len > 0 ?
4675 cur->mpd.max_title_len : p_max_size, "%s",
4679 snprintf(p, p_max_size, "%s", cur->mpd.artist);
4682 snprintf(p, p_max_size, "%s", cur->mpd.album);
4685 snprintf(p, p_max_size, "%s", cur->mpd.random);
4688 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
4691 snprintf(p, p_max_size, "%s", cur->mpd.track);
4694 snprintf(p, p_max_size, "%s", cur->mpd.name);
4697 snprintf(p, p_max_size, "%s", cur->mpd.file);
4700 snprintf(p, p_max_size, "%i", cur->mpd.volume);
4703 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
4706 snprintf(p, p_max_size, "%s", cur->mpd.status);
4709 int days = 0, hours = 0, minutes =
4711 int tmp = cur->mpd.elapsed;
4712 while (tmp >= 86400) {
4716 while (tmp >= 3600) {
4726 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
4727 days, hours, minutes,
4730 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4733 snprintf(p, p_max_size, "%i:%02i", minutes,
4737 int days = 0, hours = 0, minutes =
4739 int tmp = cur->mpd.length;
4740 while (tmp >= 86400) {
4744 while (tmp >= 3600) {
4754 snprintf(p, p_max_size,
4755 "%i days %i:%02i:%02i",
4756 days, hours, minutes,
4759 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4762 snprintf(p, p_max_size, "%i:%02i", minutes,
4766 snprintf(p, p_max_size, "%2.0f",
4767 cur->mpd.progress * 100);
4770 new_bar(p, obj->data.pair.a,
4772 (int) (cur->mpd.progress *
4776 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.title) < 2) {
4777 snprintf(p, p_max_size, "%s", cur->mpd.file);
4779 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
4785 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4788 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4791 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4794 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4796 OBJ(xmms2_comment) {
4797 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4799 OBJ(xmms2_decoder) {
4800 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
4802 OBJ(xmms2_transport) {
4803 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
4806 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4809 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4812 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4814 OBJ(xmms2_tracknr) {
4815 if (cur->xmms2.tracknr != -1)
4816 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4818 OBJ(xmms2_bitrate) {
4819 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4822 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4825 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4827 OBJ(xmms2_elapsed) {
4828 int tmp = cur->xmms2.elapsed;
4829 snprintf(p, p_max_size, "%02d:%02d",
4830 tmp / 60000, (tmp / 1000) % 60);
4832 OBJ(xmms2_duration) {
4833 int tmp = cur->xmms2.duration;
4834 snprintf(p, p_max_size, "%02d:%02d",
4835 tmp / 60000, (tmp / 1000) % 60);
4837 OBJ(xmms2_percent) {
4838 snprintf(p, p_max_size, "%2.0f",
4839 cur->xmms2.progress * 100);
4842 new_bar(p, obj->data.pair.a,
4844 (int) (cur->xmms2.progress *
4848 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
4849 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4851 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
4856 OBJ(audacious_status) {
4857 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
4859 OBJ(audacious_title) {
4860 snprintf(p, cur->audacious.max_title_len > 0 ?
4861 cur->audacious.max_title_len : p_max_size, "%s",
4862 cur->audacious.items[AUDACIOUS_TITLE]);
4864 OBJ(audacious_length) {
4865 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
4867 OBJ(audacious_length_seconds) {
4868 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4870 OBJ(audacious_position) {
4871 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
4873 OBJ(audacious_position_seconds) {
4874 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
4876 OBJ(audacious_bitrate) {
4877 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
4879 OBJ(audacious_frequency) {
4880 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
4882 OBJ(audacious_channels) {
4883 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
4885 OBJ(audacious_filename) {
4886 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
4888 OBJ(audacious_playlist_length) {
4889 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
4891 OBJ(audacious_playlist_position) {
4892 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
4894 OBJ(audacious_bar) {
4896 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
4897 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4898 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
4903 snprintf(p, p_max_size, "%s", cur->bmpx.title);
4906 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
4909 snprintf(p, p_max_size, "%s", cur->bmpx.album);
4912 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
4915 snprintf(p, p_max_size, "%i", cur->bmpx.track);
4918 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
4922 if (obj->data.top.type == TOP_NAME
4923 && obj->data.top.num >= 0
4924 && obj->data.top.num < 10) {
4925 snprintf(p, 17, "%-17s", cur->cpu[obj->data.top.num]->name);
4926 } else if (obj->data.top.type == TOP_CPU
4927 && obj->data.top.num >= 0
4928 && obj->data.top.num < 10) {
4929 snprintf(p, 7, "%7.3f",
4930 cur->cpu[obj->data.top.
4932 } else if (obj->data.top.type == TOP_PID
4933 && obj->data.top.num >= 0
4934 && obj->data.top.num < 10) {
4935 snprintf(p, 8, "%7i",
4936 cur->cpu[obj->data.top.
4938 } else if (obj->data.top.type == TOP_MEM
4939 && obj->data.top.num >= 0
4940 && obj->data.top.num < 10) {
4941 snprintf(p, 7, "%7.3f",
4942 cur->cpu[obj->data.top.
4947 if (obj->data.top.type == TOP_NAME
4948 && obj->data.top.num >= 0
4949 && obj->data.top.num < 10) {
4950 snprintf(p, 17, "%-17s",
4951 cur->memu[obj->data.top.
4953 } else if (obj->data.top.type == TOP_CPU
4954 && obj->data.top.num >= 0
4955 && obj->data.top.num < 10) {
4956 snprintf(p, 7, "%7.3f",
4957 cur->memu[obj->data.top.
4959 } else if (obj->data.top.type == TOP_PID
4960 && obj->data.top.num >= 0
4961 && obj->data.top.num < 10) {
4962 snprintf(p, 8, "%7i",
4963 cur->memu[obj->data.top.
4965 } else if (obj->data.top.type == TOP_MEM
4966 && obj->data.top.num >= 0
4967 && obj->data.top.num < 10) {
4968 snprintf(p, 7, "%7.3f",
4969 cur->memu[obj->data.top.
4976 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4977 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4979 obj->data.tail.last_update = current_update_time;
4983 fp = fopen(obj->data.tail.logfile, "rt");
4985 /* Send one message, but do not consistently spam on
4986 * missing logfiles. */
4987 if(obj->data.tail.readlines != 0) {
4988 ERR("tail logfile failed to open");
4989 strcpy(obj->data.tail.buffer, "Logfile Missing");
4991 obj->data.tail.readlines = 0;
4992 snprintf(p, p_max_size, "Logfile Missing");
4995 obj->data.tail.readlines = 0;
4996 /* -1 instead of 0 to avoid counting a trailing newline */
4997 fseek(fp, -1, SEEK_END);
4998 bsize = ftell(fp) + 1;
4999 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5000 nl = rev_fcharfind(fp, '\n', iter);
5004 obj->data.tail.readlines = iter;
5005 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
5006 fseek(fp, 0, SEEK_SET);
5009 fseek(fp, nl+1, SEEK_SET);
5012 /* Make sure bsize is at least 1 byte smaller than
5013 * the buffer max size. */
5014 if(bsize > (long)((text_buffer_size*20) - 1)) {
5015 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
5016 bsize = text_buffer_size*20 - 1;
5018 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5021 /* Clean up trailing newline, make sure the buffer
5022 * is null terminated. */
5023 if(obj->data.tail.buffer[bsize-1] == '\n')
5024 obj->data.tail.buffer[bsize-1] = '\0';
5026 obj->data.tail.buffer[bsize] = '\0';
5027 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5030 strcpy(obj->data.tail.buffer, "Logfile Empty");
5031 snprintf(p, p_max_size, "Logfile Empty");
5034 } /* if cur_upd_time >= */
5036 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5040 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5041 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5043 obj->data.tail.last_update = current_update_time;
5047 fp = fopen(obj->data.tail.logfile, "rt");
5049 /* Send one message, but do not consistently spam on
5050 * missing logfiles. */
5051 if(obj->data.tail.readlines != 0) {
5052 ERR("head logfile failed to open");
5053 strcpy(obj->data.tail.buffer, "Logfile Missing");
5055 obj->data.tail.readlines = 0;
5056 snprintf(p, p_max_size, "Logfile Missing");
5058 obj->data.tail.readlines = 0;
5059 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5060 nl = fwd_fcharfind(fp, '\n', iter);
5064 obj->data.tail.readlines = iter;
5065 /* Make sure nl is at least 1 byte smaller than
5066 * the buffer max size. */
5067 if(nl > (long)((text_buffer_size*20) - 1)) {
5068 nl = text_buffer_size*20 - 1;
5070 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5073 /* Clean up trailing newline, make sure the buffer
5074 * is null terminated. */
5075 if (obj->data.tail.buffer[nl-1] == '\n') {
5076 obj->data.tail.buffer[nl-1] = '\0';
5079 obj->data.tail.buffer[nl] = '\0';
5081 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5084 strcpy(obj->data.tail.buffer, "Logfile Empty");
5085 snprintf(p, p_max_size, "Logfile Empty");
5087 } /* if fp == null */
5088 } /* cur_upd_time >= */
5090 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5093 #ifdef TCP_PORT_MONITOR
5096 /* grab a pointer to this port monitor */
5097 tcp_port_monitor_t * p_monitor =
5098 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
5099 obj->data.tcp_port_monitor.port_range_begin,
5100 obj->data.tcp_port_monitor.port_range_end );
5102 snprintf(p, p_max_size, "monitor not found");
5106 /* now grab the text of interest */
5107 if ( peek_tcp_port_monitor( p_monitor,
5108 obj->data.tcp_port_monitor.item,
5109 obj->data.tcp_port_monitor.connection_index,
5110 p, p_max_size ) != 0 )
5112 snprintf(p, p_max_size, "monitor peek error");
5121 iconv_converting = 1;
5122 iconv_selected = obj->a;
5127 iconv_converting = 0;
5133 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5135 OBJ(entropy_poolsize)
5137 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5141 double entropy_perc;
5142 entropy_perc = (double)cur->entropy.entropy_avail /
5143 (double)cur->entropy.poolsize;
5144 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5152 unsigned int a = strlen(p);
5155 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5157 size_t dummy1, dummy2;
5158 char *ptr = buff_in;
5161 dummy1 = dummy2 = a;
5163 strncpy(buff_in, p, P_MAX_SIZE);
5165 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5166 while (dummy1 > 0) {
5167 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5169 ERR("Iconv codeset conversion failed");
5174 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5185 double current_update_time, last_update_time;
5187 static void generate_text()
5189 struct information *cur = &info;
5197 current_update_time = get_time();
5200 /* fix diskio rates to b/s (use update_interval */
5201 diskio_read_value = diskio_read_value / update_interval;
5202 diskio_write_value = diskio_write_value / update_interval;
5203 diskio_value = diskio_value / update_interval;
5206 /* add things to the buffer */
5212 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5214 if (stuff_in_upper_case) {
5225 last_update_time = current_update_time;
5232 static void set_font()
5236 if (window.xftdraw != NULL) {
5237 XftDrawDestroy(window.xftdraw);
5239 window.xftdraw = XftDrawCreate(display, window.drawable,
5240 DefaultVisual(display,
5242 DefaultColormap(display,
5247 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5253 static inline int get_string_width(const char *s)
5256 return *s ? calc_text_width(s, strlen(s)) : 0;
5262 static inline int get_string_width_special(char *s)
5275 if (*p == SPECIAL_CHAR) {
5276 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5277 for (i = 0; i < strlen(p); i++) {
5278 *(p + i) = *(p + i + 1);
5280 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5281 width += specials[special_index+index].width;
5288 if (strlen(final) > 1) {
5289 width += calc_text_width(final, strlen(final));
5299 static void text_size_updater(char *s);
5301 int last_font_height;
5302 static void update_text_area()
5306 /* update text size if it isn't fixed */
5311 text_width = minimum_width;
5314 last_font_height = font_height();
5315 for_each_line(text_buffer, text_size_updater);
5317 if (text_height < minimum_height)
5318 text_height = minimum_height;
5319 if (text_width > maximum_width && maximum_width > 0)
5320 text_width = maximum_width;
5323 /* get text position on workarea */
5324 switch (text_alignment) {
5331 x = workarea[2] - text_width - gap_x;
5338 y = workarea[3] - text_height - gap_y;
5342 x = workarea[2] - text_width - gap_x;
5343 y = workarea[3] - text_height - gap_y;
5347 case NONE: // Let the WM manage the window
5358 if (own_window && !fixed_pos) {
5361 text_start_x = border_margin + 1;
5362 text_start_y = border_margin + 1;
5363 window.x = x - border_margin - 1;
5364 window.y = y - border_margin - 1;
5368 /* If window size doesn't match to workarea's size, then window
5369 * probably includes panels (gnome).
5370 * Blah, doesn't work on KDE. */
5371 if (workarea[2] != window.width
5372 || workarea[3] != window.height) {
5386 static int cur_x, cur_y; /* current x and y for drawing */
5387 static int draw_mode; /* FG, BG or OUTLINE */
5388 static long current_color;
5391 static void text_size_updater(char *s)
5395 /* get string widths and skip specials */
5398 if (*p == SPECIAL_CHAR) {
5400 w += get_string_width(s);
5403 if (specials[special_index].type == BAR
5404 || specials[special_index].type == GRAPH) {
5405 w += specials[special_index].width;
5406 if (specials[special_index].height > last_font_height) {
5407 last_font_height = specials[special_index].height;
5408 last_font_height += font_ascent();
5410 } else if (specials[special_index].type == OFFSET) {
5411 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
5412 } else if (specials[special_index].type == VOFFSET) {
5413 last_font_height += specials[special_index].arg;
5414 } else if (specials[special_index].type == GOTO) {
5415 if (specials[special_index].arg >= 0)
5416 w += (int)specials[special_index].arg - cur_x;
5417 } else if (specials[special_index].type == TAB) {
5418 int start = specials[special_index].arg;
5419 int step = specials[special_index].width;
5420 if (!step || step < 0)
5422 w += step - (cur_x - text_start_x - start) % step;
5423 } else if (specials[special_index].type == FONT) {
5424 selected_font = specials[special_index].font_added;
5425 if (font_height() > last_font_height) {
5426 last_font_height = font_height();
5435 w += get_string_width(s);
5436 if (w > text_width) {
5439 if (text_width > maximum_width && maximum_width) {
5440 text_width = maximum_width;
5443 text_height += last_font_height;
5444 last_font_height = font_height();
5448 static inline void set_foreground_color(long c)
5451 XSetForeground(display, window.gc, c);
5455 static void draw_string(const char *s)
5459 int i, i2, pos, width_of_s;
5462 width_of_s = get_string_width(s);
5463 if (out_to_console) {
5465 fflush(stdout); /* output immediately, don't buffer */
5467 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5468 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5469 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5473 snprintf(space, 2, " ");
5475 max = ((text_width - width_of_s) / get_string_width(space));
5478 * This code looks for tabs in the text and coverts them to spaces.
5479 * The trick is getting the correct number of spaces,
5480 * and not going over the window's size without forcing
5481 * the window larger.
5483 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5484 if (tmpstring1[i] == '\t') // 9 is ascii tab
5488 i2 < (8 - (1 + pos) % 8) && added <= max;
5491 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5492 fprintf(stderr,"buffer overrun detected\n");
5494 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5499 if (tmpstring1[i] != 9) {
5501 if ( pos > TEXT_BUFFER_SIZE-1 )
5502 fprintf(stderr,"buffer overrun detected\n");
5504 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5510 if (text_width == maximum_width) {
5511 /* this means the text is probably pushing the limit, so we'll chop it */
5512 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5513 tmpstring2[strlen(tmpstring2)-1] = '\0';
5523 c.pixel = current_color;
5524 XQueryColor(display, DefaultColormap(display, screen), &c);
5527 c2.color.red = c.red;
5528 c2.color.green = c.green;
5529 c2.color.blue = c.blue;
5530 c2.color.alpha = fonts[selected_font].font_alpha;
5532 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5533 cur_x, cur_y, (XftChar8 *) s,
5536 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5537 cur_x, cur_y, (XftChar8 *) s,
5543 XDrawString(display, window.drawable, window.gc,
5544 cur_x, cur_y, s, strlen(s));
5546 cur_x += width_of_s;
5548 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5551 long redmask, greenmask, bluemask;
5553 void set_up_gradient()
5556 colour_depth = DisplayPlanes(display, screen);
5560 if (colour_depth != 24 && colour_depth != 16) {
5561 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5567 for(i = (colour_depth / 3)-1; i>=0; i--) {
5569 greenmask |= 1 << i;
5572 if (colour_depth%3 == 1) {
5573 greenmask |= 1 << (colour_depth / 3);
5575 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5576 greenmask = greenmask << (colour_depth / 3);
5579 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 */
5581 int red1, green1, blue1; // first colour
5582 int red2, green2, blue2; // second colour
5583 int red3 = 0, green3 = 0, blue3 = 0; // difference
5584 short redshift = (2*colour_depth / 3 + colour_depth%3);
5585 short greenshift = (colour_depth / 3);
5586 red1 = (first_colour & redmask) >> redshift;
5587 green1 = (first_colour & greenmask) >> greenshift;
5588 blue1 = first_colour & bluemask;
5589 red2 = (last_colour & redmask) >> redshift;
5590 green2 = (last_colour & greenmask) >> greenshift;
5591 blue2 = last_colour & bluemask;
5598 if (green1 > green2) {
5601 if (green1 < green2) {
5604 if (blue1 > blue2) {
5607 if (blue1 < blue2) {
5622 if (red1 > bluemask) {
5625 if (green1 > bluemask) {
5628 if (blue1 > bluemask) {
5631 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
5635 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
5636 if (colour_depth == 0) {
5639 int red1, green1, blue1; // first colour
5640 int red2, green2, blue2; // second colour
5641 long redshift = (2*colour_depth / 3 + colour_depth%3);
5642 long greenshift = (colour_depth / 3);
5643 int red3 = 0, green3 = 0, blue3 = 0; // difference
5644 red1 = (first_colour & redmask) >> redshift;
5645 green1 = (first_colour & greenmask) >> greenshift;
5646 blue1 = first_colour & bluemask;
5647 red2 = (last_colour & redmask) >> redshift;
5648 green2 = (last_colour & greenmask) >> greenshift;
5649 blue2 = last_colour & bluemask;
5650 red3 = abs(red1 - red2);
5651 green3 = abs(green1 - green2);
5652 blue3 = abs(blue1 - blue2);
5661 static void draw_line(char *s)
5665 cur_x = text_start_x;
5666 cur_y += font_ascent();
5668 short font_h = font_height();
5670 /* find specials and draw stuff */
5673 if (*p == SPECIAL_CHAR) {
5676 /* draw string before special */
5683 switch (specials[special_index].type) {
5684 case HORIZONTAL_LINE:
5687 specials[special_index].height;
5688 int mid = font_ascent() / 2;
5689 w = text_start_x + text_width -
5692 XSetLineAttributes(display,
5697 XDrawLine(display, window.drawable,
5708 specials[special_index].height;
5710 specials[special_index].arg;
5711 int mid = font_ascent() / 2;
5712 char ss[2] = { s, s };
5713 w = text_start_x + text_width -
5716 XSetLineAttributes(display,
5721 XSetDashes(display, window.gc, 0,
5723 XDrawLine(display, window.drawable,
5733 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5737 specials[special_index].height;
5739 specials[special_index].arg;
5740 int by = cur_y - (font_ascent() / 2) - 1;
5741 if (h < font_height()) {
5744 w = specials[special_index].width;
5747 text_width - cur_x - 1;
5751 XSetLineAttributes(display,
5757 XDrawRectangle(display,
5761 XFillRectangle(display,
5765 w * bar_usage / 255,
5767 if (specials[special_index].
5769 && specials[special_index].
5773 [special_index].height;
5780 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5784 specials[special_index].height;
5785 unsigned long last_colour = current_color;
5786 int by = cur_y - (font_ascent()/2) - 1;
5787 if (h < font_height()) {
5790 w = specials[special_index].width;
5792 w = text_start_x + text_width - cur_x - 1;
5795 if (draw_graph_borders) {
5796 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
5797 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
5799 XSetLineAttributes(display,
5806 int gradient_size = 0;
5807 float gradient_factor = 0;
5808 float gradient_update = 0;
5809 unsigned long tmpcolour = current_color;
5810 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5811 tmpcolour = specials[special_index].last_colour;
5812 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
5813 gradient_factor = (float)gradient_size / (w - 2);
5815 for (i = w - 2; i > -1; i--) {
5816 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5817 XSetForeground(display, window.gc, tmpcolour);
5818 gradient_update += gradient_factor;
5819 while (gradient_update > 0) {
5820 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
5824 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
5827 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 */
5829 if (specials[special_index].
5831 && specials[special_index].
5835 [special_index].height;
5837 /* if (draw_mode == BG) {
5838 set_foreground_color(default_bg_color);
5840 else if (draw_mode == OUTLINE) {
5841 set_foreground_color(default_out_color);
5843 set_foreground_color(default_fg_color);
5845 set_foreground_color(last_colour);
5851 int old = font_ascent();
5852 cur_y -= font_ascent();
5853 selected_font = specials[special_index].font_added;
5854 if (cur_y + font_ascent() < cur_y + old) {
5857 cur_y += font_ascent();
5863 if (draw_mode == FG)
5864 set_foreground_color(specials
5870 if (draw_mode == BG)
5871 set_foreground_color(specials
5877 if (draw_mode == OUTLINE)
5878 set_foreground_color(specials
5884 w += specials[special_index].arg;
5888 cur_y += specials[special_index].arg;
5892 if (specials[special_index].arg >= 0)
5893 cur_x = (int)specials[special_index].arg;
5898 int start = specials[special_index].arg;
5899 int step = specials[special_index].width;
5900 if (!step || step < 0)
5902 w = step - (cur_x - text_start_x - start) % step;
5908 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
5909 /*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);*/
5910 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
5911 cur_x = pos_x - specials[special_index].arg;
5918 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
5919 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
5920 /*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);*/
5922 specials[special_index].arg)
5925 [special_index].arg;
5942 if (cur_y_add > 0) {
5944 cur_y -= font_descent();
5949 cur_y += font_descent();
5953 static void draw_text()
5956 cur_y = text_start_y;
5959 if (draw_borders && border_width > 0) {
5960 unsigned int b = (border_width + 1) / 2;
5962 if (stippled_borders) {
5964 { stippled_borders, stippled_borders };
5965 XSetLineAttributes(display, window.gc,
5966 border_width, LineOnOffDash,
5967 CapButt, JoinMiter);
5968 XSetDashes(display, window.gc, 0, ss, 2);
5970 XSetLineAttributes(display, window.gc,
5971 border_width, LineSolid,
5972 CapButt, JoinMiter);
5975 XDrawRectangle(display, window.drawable, window.gc,
5976 text_start_x - border_margin + b,
5977 text_start_y - border_margin + b,
5978 text_width + border_margin * 2 - 1 - b * 2,
5979 text_height + border_margin * 2 - 1 -
5986 for_each_line(text_buffer, draw_line);
5989 static void draw_stuff()
5993 if (draw_shades && !draw_outline) {
5996 set_foreground_color(default_bg_color);
6006 for (i = -1; i < 2; i++)
6007 for (j = -1; j < 2; j++) {
6008 if (i == 0 && j == 0)
6012 set_foreground_color(default_out_color);
6013 draw_mode = OUTLINE;
6020 set_foreground_color(default_fg_color);
6028 swap.swap_window = window.window;
6029 swap.swap_action = XdbeBackground;
6030 XdbeSwapBuffers(display, &swap, 1);
6036 static void clear_text(int exposures)
6040 return; /* The swap action is XdbeBackground, which clears */
6044 /* there is some extra space for borders and outlines */
6045 XClearArea(display, window.window,
6046 text_start_x - border_margin - 1,
6047 text_start_y - border_margin - 1,
6048 text_width + border_margin * 2 + 2,
6049 text_height + border_margin * 2 + 2,
6050 exposures ? True : 0);
6055 static int need_to_update;
6057 /* update_text() generates new text and clears old text area */
6058 static void update_text()
6067 static void main_loop()
6069 #ifdef SIGNAL_BLOCKING
6070 sigset_t newmask, oldmask;
6072 sigemptyset(&newmask);
6073 sigaddset(&newmask,SIGINT);
6074 sigaddset(&newmask,SIGTERM);
6075 sigaddset(&newmask,SIGUSR1);
6079 Region region = XCreateRegion();
6081 int event_base, error_base;
6082 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
6083 ERR("Xdamage extension unavailable");
6085 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
6086 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
6087 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
6088 #endif /* HAVE_XDAMAGE */
6092 while (total_run_times == 0 || info.looped < total_run_times) {
6095 #ifdef SIGNAL_BLOCKING
6096 /* block signals. we will inspect for pending signals later */
6097 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
6098 CRIT_ERR("unable to sigprocmask()");
6104 /* wait for X event or timeout */
6106 if (!XPending(display)) {
6111 update_interval - (get_time() -
6117 tv.tv_sec = (long) t;
6118 tv.tv_usec = (long) (t * 1000000) % 1000000;
6120 FD_SET(ConnectionNumber(display), &fdsr);
6123 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
6126 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
6131 ERR("can't select(): %s",
6142 if (need_to_update) {
6144 int wx = window.x, wy = window.y;
6152 /* resize window if it isn't right size */
6154 (text_width + border_margin * 2 + 1 !=
6156 || text_height + border_margin * 2 + 1 !=
6160 border_margin * 2 + 1;
6163 border_margin * 2 + 1;
6164 XResizeWindow(display,
6169 set_transparent_background(window.window);
6173 /* move window if it isn't in right position */
6176 || window.y != wy)) {
6177 XMoveWindow(display, window.window,
6178 window.x, window.y);
6188 r.x = text_start_x - border_margin;
6189 r.y = text_start_y - border_margin;
6190 r.width = text_width + border_margin * 2;
6191 r.height = text_height + border_margin * 2;
6192 XUnionRectWithRegion(&r, region, region);
6197 /* handle X events */
6199 while (XPending(display)) {
6201 XNextEvent(display, &ev);
6208 r.width = ev.xexpose.width;
6209 r.height = ev.xexpose.height;
6210 XUnionRectWithRegion(&r, region,
6216 case ReparentNotify:
6217 /* set background to ParentRelative for all parents */
6219 set_transparent_background(window.
6224 case ConfigureNotify:
6226 /* if window size isn't what expected, set fixed size */
6227 if (ev.xconfigure.width !=
6229 || ev.xconfigure.height !=
6231 if (window.width != 0
6232 && window.height != 0)
6235 /* clear old stuff before screwing up size and pos */
6241 if (XGetWindowAttributes(display, window.window, &attrs)) {
6256 border_margin * 2 - 1;
6259 border_margin * 2 - 1;
6260 if (text_width > maximum_width && maximum_width > 0)
6261 text_width = maximum_width;
6264 /* if position isn't what expected, set fixed pos, total_updates
6265 * avoids setting fixed_pos when window is set to weird locations
6267 /*if (total_updates >= 2 this is broken
6269 && (window.x != ev.xconfigure.x
6272 && (ev.xconfigure.x != 0
6273 || ev.xconfigure.y != 0)) {
6283 /* if an ordinary window with decorations */
6284 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6286 /* allow conky to hold input focus.*/
6291 /* forward the click to the desktop window */
6292 XUngrabPointer(display, ev.xbutton.time);
6293 ev.xbutton.window = window.desktop;
6294 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6295 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6303 /* if an ordinary window with decorations */
6304 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6306 /* allow conky to hold input focus.*/
6311 /* forward the release to the desktop window */
6312 ev.xbutton.window = window.desktop;
6313 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6322 if (ev.type == event_base + XDamageNotify) {
6323 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6324 XFixesSetRegion(display, part, &dev->area, 1);
6325 XFixesUnionRegion(display, region2, region2, part);
6327 #endif /* HAVE_XDAMAGE */
6332 XDamageSubtract(display, damage, region2, None);
6333 XFixesSetRegion(display, region2, 0, 0);
6334 #endif /* HAVE_XDAMAGE */
6336 /* XDBE doesn't seem to provide a way to clear the back buffer without
6337 * interfering with the front buffer, other than passing XdbeBackground
6338 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6339 * redraw the text even if it wasn't part of the exposed area. OTOH,
6340 * if we're not going to call draw_stuff at all, then no swap happens
6341 * and we can safely do nothing.
6344 if (!XEmptyRegion(region)) {
6348 r.x = text_start_x - border_margin;
6349 r.y = text_start_y - border_margin;
6350 r.width = text_width + border_margin * 2;
6351 r.height = text_height + border_margin * 2;
6352 XUnionRectWithRegion(&r, region, region);
6355 XSetRegion(display, window.gc, region);
6358 XftDrawSetClip(window.xftdraw, region);
6364 XDestroyRegion(region);
6365 region = XCreateRegion();
6369 #ifdef SIGNAL_BLOCKING
6370 /* unblock signals of interest and let handler fly */
6371 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6372 CRIT_ERR("unable to sigprocmask()");
6375 switch(g_signal_pending) {
6378 ERR("received SIGUSR1. reloading the config file.");
6385 ERR("received SIGINT or SIGTERM to terminate. bye!");
6388 XDestroyRegion(region);
6391 return; /* return from main_loop */
6396 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6397 * but didn't write any code to deal with it. if you don't want to
6398 * handle a signal, don't set a handler on it in the first place. */
6399 if (g_signal_pending)
6400 ERR("ignoring signal (%d)", g_signal_pending);
6407 #if defined(X11) && defined(HAVE_XDAMAGE)
6408 XDamageDestroy(display, damage);
6409 XFixesDestroyRegion(display, region2);
6410 XFixesDestroyRegion(display, part);
6411 XDestroyRegion(region);
6413 #endif /* X11 && HAVE_XDAMAGE */
6416 static void load_config_file(const char *);
6418 /* reload the config file */
6419 void reload_config(void)
6421 timed_thread_destroy_registered_threads ();
6423 if (info.cpu_usage) {
6424 free(info.cpu_usage);
6425 info.cpu_usage = NULL;
6428 #ifdef TCP_PORT_MONITOR
6429 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6432 if (current_config) {
6434 load_config_file(current_config);
6436 /* re-init specials array */
6437 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6438 ERR("failed to realloc specials array");
6443 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6446 #ifdef TCP_PORT_MONITOR
6447 info.p_tcp_port_monitor_collection = NULL;
6450 if (create_audacious_thread() !=0)
6451 CRIT_ERR("unable to create audacious thread!");
6452 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6454 extract_variable_text(text);
6463 timed_thread_destroy_registered_threads ();
6465 if (info.cpu_usage) {
6466 free(info.cpu_usage);
6467 info.cpu_usage = NULL;
6472 XdbeDeallocateBackBufferName(display, window.back_buffer);
6478 XDestroyWindow(display, window.window);
6479 XClearWindow(display, RootWindow(display, screen));
6485 XClearWindow(display, RootWindow(display, screen));
6490 XFreeGC(display, window.gc);
6493 free_text_objects(text_object_count, text_objects);
6494 text_object_count = 0;
6495 text_objects = NULL;
6497 if (text != original_text)
6500 free(current_config);
6501 free(current_mail_spool);
6503 #ifdef TCP_PORT_MONITOR
6504 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6505 info.p_tcp_port_monitor_collection = NULL;
6513 for(i=0;i<special_count;i++)
6514 if(specials[i].type == GRAPH)
6515 free(specials[i].graph);
6521 static int string_to_bool(const char *s)
6525 if (strcasecmp(s, "yes") == 0)
6527 if (strcasecmp(s, "true") == 0)
6529 if (strcasecmp(s, "1") == 0)
6534 static enum alignment string_to_alignment(const char *s)
6536 if (strcasecmp(s, "top_left") == 0)
6538 else if (strcasecmp(s, "top_right") == 0)
6540 else if (strcasecmp(s, "bottom_left") == 0)
6542 else if (strcasecmp(s, "bottom_right") == 0)
6543 return BOTTOM_RIGHT;
6544 else if (strcasecmp(s, "tl") == 0)
6546 else if (strcasecmp(s, "tr") == 0)
6548 else if (strcasecmp(s, "bl") == 0)
6550 else if (strcasecmp(s, "br") == 0)
6551 return BOTTOM_RIGHT;
6552 else if (strcasecmp(s, "none") == 0)
6559 static void set_default_configurations(void)
6561 fork_to_background = 0;
6562 total_run_times = 0;
6563 info.cpu_avg_samples = 2;
6564 info.net_avg_samples = 2;
6569 strcpy(info.mpd.host, "localhost");
6570 info.mpd.port = 6600;
6571 info.mpd.status = NULL;
6572 info.mpd.artist = NULL;
6573 info.mpd.album = NULL;
6574 info.mpd.title = NULL;
6575 info.mpd.random = NULL;
6576 info.mpd.track = NULL;
6577 info.mpd.name = NULL;
6578 info.mpd.file = NULL;
6581 info.xmms2.artist = NULL;
6582 info.xmms2.album = NULL;
6583 info.xmms2.title = NULL;
6584 info.xmms2.genre = NULL;
6585 info.xmms2.comment = NULL;
6586 info.xmms2.decoder = NULL;
6587 info.xmms2.transport = NULL;
6588 info.xmms2.url = NULL;
6589 info.xmms2.status = NULL;
6592 #if defined(__linux__)
6594 #endif /* __linux__ */
6601 default_fg_color = WhitePixel(display, screen);
6602 default_bg_color = BlackPixel(display, screen);
6603 default_out_color = BlackPixel(display, screen);
6604 color0 = default_fg_color;
6605 color1 = default_fg_color;
6606 color2 = default_fg_color;
6607 color3 = default_fg_color;
6608 color4 = default_fg_color;
6609 color5 = default_fg_color;
6610 color6 = default_fg_color;
6611 color7 = default_fg_color;
6612 color8 = default_fg_color;
6613 color9 = default_fg_color;
6616 draw_graph_borders = 1;
6618 set_first_font("6x10");
6626 window.type=TYPE_NORMAL;
6628 strcpy(window.class_name, "Conky");
6630 sprintf(window.title,"%s - conky",info.uname_s.nodename);
6632 stippled_borders = 0;
6635 text_alignment = BOTTOM_LEFT;
6638 free(current_mail_spool);
6641 variable_substitute(MAIL_FILE, buf, 256);
6643 current_mail_spool = strdup(buf);
6647 update_interval = 10.0;
6648 stuff_in_upper_case = 0;
6650 #ifdef TCP_PORT_MONITOR
6651 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6655 static void load_config_file(const char *f)
6657 #define CONF_ERR ERR("%s: %d: config file error", f, line)
6661 set_default_configurations();
6667 char buf[256], *p, *p2, *name, *value;
6669 if (fgets(buf, 256, fp) == NULL)
6674 /* break at comment */
6675 p2 = strchr(p, '#');
6680 while (*p && isspace((int) *p))
6683 continue; /* empty line */
6689 while (*p2 && !isspace((int) *p2))
6692 *p2 = '\0'; /* break at name's end */
6699 while (*p && isspace((int) *p))
6704 p2 = value + strlen(value);
6705 while (isspace((int) *(p2 - 1)))
6711 #define CONF2(a) if (strcasecmp(name, a) == 0)
6712 #define CONF(a) else CONF2(a)
6713 #define CONF3(a,b) \
6714 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
6718 CONF2("alignment") {
6720 int a = string_to_alignment(value);
6728 CONF("background") {
6729 fork_to_background = string_to_bool(value);
6733 CONF2("background") {
6734 fork_to_background = string_to_bool(value);
6738 CONF("border_margin") {
6740 border_margin = strtol(value, 0, 0);
6744 CONF("border_width") {
6746 border_width = strtol(value, 0, 0);
6752 color0 = get_x11_color(value);
6758 color1 = get_x11_color(value);
6764 color2 = get_x11_color(value);
6770 color3 = get_x11_color(value);
6776 color4 = get_x11_color(value);
6782 color5 = get_x11_color(value);
6788 color6 = get_x11_color(value);
6794 color7 = get_x11_color(value);
6800 color8 = get_x11_color(value);
6806 color9 = get_x11_color(value);
6810 CONF("default_color") {
6812 default_fg_color = get_x11_color(value);
6816 CONF3("default_shade_color", "default_shadecolor") {
6818 default_bg_color = get_x11_color(value);
6822 CONF3("default_outline_color", "default_outlinecolor") {
6824 default_out_color = get_x11_color(value);
6831 info.mail = parse_mail_args(IMAP, value);
6838 info.mail = parse_mail_args(POP3, value);
6846 strncpy(info.mpd.host, value, 127);
6852 info.mpd.port = strtol(value, 0, 0);
6853 if (info.mpd.port < 1
6854 || info.mpd.port > 0xffff)
6858 CONF("mpd_password") {
6860 strncpy(info.mpd.password, value, 127);
6866 CONF("sensor_device") {
6868 sensor_device = strtol(value, 0, 0);
6873 CONF("cpu_avg_samples") {
6875 cpu_avg_samples = strtol(value, 0, 0);
6876 if (cpu_avg_samples < 1
6877 || cpu_avg_samples > 14)
6886 CONF("net_avg_samples") {
6888 net_avg_samples = strtol(value, 0, 0);
6889 if (net_avg_samples < 1
6890 || net_avg_samples > 14)
6906 CONF("double_buffer") {
6907 use_xdbe = string_to_bool(value);
6911 CONF("override_utf8_locale") {
6912 utf8_mode = string_to_bool(value);
6915 CONF("draw_borders") {
6916 draw_borders = string_to_bool(value);
6918 CONF("draw_graph_borders") {
6919 draw_graph_borders = string_to_bool(value);
6921 CONF("draw_shades") {
6922 draw_shades = string_to_bool(value);
6924 CONF("draw_outline") {
6925 draw_outline = string_to_bool(value);
6927 #if defined(__linux__)
6928 CONF("post_21_kernel") {
6929 post_21_kernel = string_to_bool(value);
6931 #endif /* __linux__ */
6933 CONF("out_to_console") {
6934 out_to_console = string_to_bool(value);
6936 CONF("use_spacer") {
6937 use_spacer = string_to_bool(value);
6942 use_xft = string_to_bool(value);
6946 set_first_font(value);
6951 if (value && font_count >= 0)
6952 fonts[0].font_alpha = atof(value)
6961 if (string_to_bool(value))
6962 ERR("Xft not enabled");
6965 /* xftfont silently ignored when no Xft */
6968 /* xftalpha is silently ignored when no Xft */
6973 set_first_font(value);
6982 gap_x = atoi(value);
6988 gap_y = atoi(value);
6993 CONF("mail_spool") {
6996 variable_substitute(value, buf, 256);
7000 if (current_mail_spool)
7001 free(current_mail_spool);
7002 current_mail_spool = strdup(buf);
7008 CONF("minimum_size") {
7011 (value, "%d %d", &minimum_width,
7012 &minimum_height) != 2)
7015 &minimum_width) != 1)
7020 CONF("maximum_width") {
7022 if (sscanf(value, "%d", &maximum_width) != 1)
7028 CONF("no_buffers") {
7029 no_buffers = string_to_bool(value);
7031 CONF("pad_percents") {
7032 pad_percents = atoi(value);
7036 CONF("own_window") {
7038 own_window = string_to_bool(value);
7042 CONF("own_window_class") {
7045 memset(window.class_name,0,sizeof(window.class_name));
7046 strncpy(window.class_name, value, sizeof(window.class_name)-1);
7051 CONF("own_window_title") {
7054 memset(window.title,0,sizeof(window.title));
7055 strncpy(window.title, value, sizeof(window.title)-1);
7060 CONF("own_window_transparent") {
7062 set_transparent = string_to_bool(value);
7066 CONF("own_window_colour") {
7068 background_colour = get_x11_color(value);
7070 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
7073 CONF("own_window_hints") {
7075 char *p_hint, *p_save;
7076 char delim[] = ", ";
7078 /* tokenize the value into individual hints */
7079 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
7081 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
7082 if (strncmp(p_hint,"undecorate",10) == 0)
7083 SET_HINT(window.hints,HINT_UNDECORATED);
7084 else if (strncmp(p_hint,"below",5) == 0)
7085 SET_HINT(window.hints,HINT_BELOW);
7086 else if (strncmp(p_hint,"above",5) == 0)
7087 SET_HINT(window.hints,HINT_ABOVE);
7088 else if (strncmp(p_hint,"sticky",6) == 0)
7089 SET_HINT(window.hints,HINT_STICKY);
7090 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
7091 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
7092 else if (strncmp(p_hint,"skip_pager",10) == 0)
7093 SET_HINT(window.hints,HINT_SKIP_PAGER);
7097 p_hint=strtok_r(NULL, delim, &p_save);
7099 while (p_hint!=NULL);
7104 CONF("own_window_type") {
7106 if (strncmp(value,"normal",6)==0)
7107 window.type = TYPE_NORMAL;
7108 else if (strncmp(value,"desktop",7)==0)
7109 window.type = TYPE_DESKTOP;
7110 else if (strncmp(value,"override",8)==0)
7111 window.type = TYPE_OVERRIDE;
7119 CONF("stippled_borders") {
7121 stippled_borders = strtol(value, 0, 0);
7123 stippled_borders = 4;
7127 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
7130 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
7132 CONF("update_interval") {
7134 update_interval = strtod(value, 0);
7138 CONF("total_run_times") {
7140 total_run_times = strtod(value, 0);
7145 stuff_in_upper_case = string_to_bool(value);
7147 CONF("max_specials") {
7149 max_specials = atoi(value);
7153 CONF("max_user_text") {
7155 max_user_text = atoi(value);
7159 CONF("text_buffer_size") {
7161 text_buffer_size = atoi(value);
7166 if (text != original_text)
7176 int l = strlen(text);
7177 if (fgets(buf, 256, fp) == NULL)
7180 realloc(text, l + strlen(buf)
7184 if (strlen(text) > max_user_text)
7188 text_lines = line + 1;
7191 #ifdef TCP_PORT_MONITOR
7192 CONF("max_port_monitor_connections")
7195 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7196 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
7198 /* an error. use default, warn and continue. */
7199 tcp_port_monitor_args.max_port_monitor_connections =
7200 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7203 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
7205 /* no error, just use default */
7206 tcp_port_monitor_args.max_port_monitor_connections =
7207 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7209 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
7214 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7226 /* : means that character before that takes an argument */
7227 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
7240 int main(int argc, char **argv)
7242 struct sigaction act, oact;
7245 memset(&info, 0, sizeof(info) );
7247 #ifdef TCP_PORT_MONITOR
7248 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7251 /* handle command line parameters that don't change configs */
7256 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7257 *s) || ((s = getenv("LANG")) && *s)) {
7258 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7260 ERR("malloc failed");
7262 for (x = 0; x < strlen(s); x++) {
7263 temp[x] = tolower(s[x]);
7266 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7272 if (!setlocale(LC_CTYPE, "")) {
7273 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7277 int c = getopt(argc,
7288 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
7289 * though free() does the NULL check itself;), then load optarg value */
7291 free(current_config);
7292 current_config = strdup(optarg);
7297 ("Usage: %s [OPTION]...\n"
7298 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7299 "window. Command line options will override configurations defined in config\n"
7302 " -c FILE config file to load instead of "
7305 " -d daemonize, fork to background\n"
7308 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7309 " -f FONT font to use\n"
7311 " -o create own window to draw\n"
7314 " -b double buffer (prevents flickering)\n"
7316 " -w WIN_ID window id to draw\n"
7317 " -x X x position\n"
7318 " -y Y y position\n"
7320 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
7321 " -u SECS update interval\n"
7322 " -i NUM number of times to update Conky\n", argv[0]);
7326 window.window = strtol(optarg, 0, 0);
7335 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7339 /* load current_config or CONFIG_FILE */
7342 if (current_config == NULL) {
7343 /* load default config file */
7346 variable_substitute(CONFIG_FILE, buf, 256);
7349 current_config = strdup(buf);
7353 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
7354 load_config_file(current_config);
7356 set_default_configurations();
7359 /* init specials array */
7360 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7361 ERR("failed to create specials array");
7364 if (current_mail_spool == NULL) {
7366 variable_substitute(MAIL_FILE, buf, 256);
7369 current_mail_spool = strdup(buf);
7373 /* handle other command line arguments */
7375 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
7376 optind = optreset = 1;
7381 #if defined(__FreeBSD__)
7382 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7383 O_RDONLY, "kvm_open")) == NULL)
7384 CRIT_ERR( "cannot read kvm");
7388 int c = getopt(argc,
7396 fork_to_background = 1;
7401 set_first_font(optarg);
7404 text_alignment = string_to_alignment(optarg);
7419 if (text != original_text)
7421 text = strdup(optarg);
7422 convert_escapes(text);
7426 update_interval = strtod(optarg, 0);
7430 total_run_times = strtod(optarg, 0);
7434 gap_x = atoi(optarg);
7438 gap_y = atoi(optarg);
7452 /* generate text and get initial size */
7453 extract_variable_text(text);
7454 if (text != original_text) {
7459 if (fork_to_background) {
7463 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
7469 fprintf(stderr,"\n"); fflush(stderr);
7473 /* parent process */
7474 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
7481 update_text_area(); /* to get initial size of the window */
7485 text_width + border_margin * 2 + 1,
7486 text_height + border_margin * 2 + 1,
7487 set_transparent, background_colour, argv, argc);
7490 update_text_area(); /* to position text/window on screen */
7495 if (own_window && !fixed_pos) {
7496 XMoveWindow(display, window.window, window.x, window.y);
7499 set_transparent_background(window.window);
7510 /* Set signal handlers */
7511 act.sa_handler = signal_handler;
7512 sigemptyset(&act.sa_mask);
7515 act.sa_flags |= SA_RESTART;
7518 if ( sigaction(SIGINT,&act,&oact) < 0 ||
7519 sigaction(SIGUSR1,&act,&oact) < 0 ||
7520 sigaction(SIGTERM,&act,&oact) < 0 )
7522 ERR("error setting signal handler: %s", strerror(errno) );
7526 if (create_audacious_thread() !=0)
7527 CRIT_ERR("unable to create audacious thread!");
7528 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
7539 #if defined(__FreeBSD__)
7546 void signal_handler(int sig)
7548 /* signal handler is light as a feather, as it should be.
7549 * we will poll g_signal_pending with each loop of conky
7550 * and do any signal processing there, NOT here. */
7551 g_signal_pending=sig;