2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
26 #include <X11/Xutil.h>
28 #include <X11/extensions/Xdamage.h>
34 #include <sys/types.h>
36 #include <netinet/in.h>
46 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
49 #define CONFIG_FILE "$HOME/.conkyrc"
50 #define MAIL_FILE "$MAIL"
51 #define MAX_IF_BLOCK_DEPTH 5
53 /* #define SIGNAL_BLOCKING */
54 #undef SIGNAL_BLOCKING
56 static void print_version()
58 printf("Conky %s compiled %s for %s\n",
59 VERSION, BUILD_DATE, BUILD_ARCH);
62 "\nCompiled in features:\n\n"
66 " * Xdamage extension\n"
67 # endif /* HAVE_XDAMAGE */
69 " * Xdbe extension (double buffer)\n"
70 # endif /* HAVE_XDBE */
76 "\n Music detection:\n"
79 #endif /* AUDACIOUS */
89 "\n General features:\n"
93 #ifdef TCP_PORT_MONITOR
95 #endif /* TCP_PORT_MONITOR */
110 static int text_start_x, text_start_y; /* text start position in window */
111 static int text_width, text_height;
126 char name[TEXT_BUFFER_SIZE];
136 static int selected_font = 0;
137 static int font_count = -1;
138 struct font_list *fonts = NULL;
142 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
143 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent))
144 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent)
145 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent)
149 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
150 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
151 #define font_descent() fonts[selected_font].font->max_bounds.descent
155 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
158 static void set_font();
160 int addfont(const char *data_in)
162 if (font_count > MAX_FONTS) {
163 CRIT_ERR("you don't need that many fonts, sorry.");
166 if (font_count == 0) {
170 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
174 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
176 CRIT_ERR("realloc in addfont");
178 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
179 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
181 fonts[font_count].font_alpha = 0xffff;
184 CRIT_ERR("Oops...looks like something overflowed in addfont().");
189 void set_first_font(const char *data_in)
191 if (font_count < 0) {
192 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
197 if (strlen(data_in) > 1) {
198 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
200 fonts[0].font_alpha = 0xffff;
208 for (i=0;i<=font_count;i++) {
211 XftFontClose(display, fonts[i].xftfont);
215 XFreeFont(display, fonts[i].font);
222 set_first_font("6x10");
226 static void load_fonts()
229 for (i=0; i <= font_count; i++) {
233 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
234 XftFontClose(display, fonts[i].xftfont);
236 if ((fonts[i].xftfont =
237 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
240 ERR("can't load Xft font '%s'", fonts[i].name);
241 if ((fonts[i].xftfont =
242 XftFontOpenName(display, screen,
243 "courier-12")) != NULL)
246 ERR("can't load Xft font '%s'", "courier-12");
248 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
249 CRIT_ERR("can't load font '%s'", "fixed");
256 /* load normal font */
257 /* if (fonts[i].font != NULL)
258 XFreeFont(display, fonts[i].font);*/
260 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
261 ERR("can't load font '%s'", fonts[i].name);
262 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
263 CRIT_ERR("can't load font '%s'", "fixed");
264 printf("loaded fixed?\n");
272 /* default config file */
273 static char *current_config;
275 /* set to 1 if you want all text to be in uppercase */
276 static unsigned int stuff_in_upper_case;
278 /* Run how many times? */
279 static unsigned long total_run_times;
282 static int fork_to_background;
284 static int cpu_avg_samples, net_avg_samples;
288 /* Position on the screen */
289 static int text_alignment;
290 static int gap_x, gap_y;
293 static int draw_borders;
294 static int draw_graph_borders;
295 static int stippled_borders;
297 static int draw_shades, draw_outline;
299 static int border_margin, border_width;
301 static long default_fg_color, default_bg_color, default_out_color;
302 static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
304 /* create own window or draw stuff to root? */
305 static int set_transparent = 0;
309 static int own_window = 0;
310 static int background_colour = 0;
311 /* fixed size/pos is set if wm/user changes them */
312 static int fixed_size = 0, fixed_pos = 0;
315 static int minimum_width, minimum_height;
316 static int maximum_width;
321 static int sensor_device;
324 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
325 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
327 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
328 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
330 /* maximum size of individual text buffers, ie $exec buffer size */
331 unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
334 #define CODEPAGE_LENGTH 20
337 char iconv_converting;
338 static iconv_t **iconv_cd = 0;
340 int register_iconv(iconv_t *new_iconv)
343 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
345 iconv_cd = malloc(sizeof(iconv_t *));
348 CRIT_ERR("Out of memory");
350 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
351 if (!iconv_cd[iconv_count]) {
352 CRIT_ERR("Out of memory");
354 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
359 void free_iconv(void)
363 for (i = iconv_count; i < 0; i++) {
379 /* no buffers in used memory? */
382 /* pad percentages to decimals? */
383 static int pad_percents = 0;
385 #ifdef TCP_PORT_MONITOR
386 tcp_port_monitor_args_t tcp_port_monitor_args;
389 /* Text that is shown */
390 static char original_text[] =
391 "$nodename - $sysname $kernel on $machine\n"
393 "${color grey}Uptime:$color $uptime\n"
394 "${color grey}Frequency (in MHz):$color $freq\n"
395 "${color grey}Frequency (in GHz):$color $freq_g\n"
396 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
397 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
398 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
399 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
401 "${color grey}File systems:\n"
402 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
403 "${color grey}Networking:\n"
404 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
407 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
408 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
411 "${color grey}XMMS2: $xmms2_status $xmms2_artist - $xmms2_title from $xmms2_album\n"
412 "Progress: $xmms2_bar\n"
414 "${color grey}Name PID CPU% MEM%\n"
415 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
416 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
417 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
418 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
419 "${tail /var/log/Xorg.0.log 3}";
421 static char *text = original_text;
424 static int total_updates;
427 static int blockdepth = 0;
428 static int if_jumped = 0;
429 static int blockstart[MAX_IF_BLOCK_DEPTH];
431 int check_mount(char *s)
433 #if defined(__linux__)
435 FILE *mtab = fopen("/etc/mtab", "r");
437 char buf1[256], buf2[128];
438 while (fgets(buf1, 256, mtab)) {
439 sscanf(buf1, "%*s %128s", buf2);
440 if (!strcmp(s, buf2)) {
447 ERR("Could not open mtab");
450 #elif defined(__FreeBSD__)
451 struct statfs *mntbuf;
454 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
455 for (i = mntsize - 1; i >= 0; i--)
456 if (strcmp(mntbuf[i].f_mntonname, s) == 0)
460 #elif defined(__OpenBSD__)
467 int check_contains(char *f, char *s)
470 FILE *where = fopen(f, "r");
472 char buf1[256], buf2[256];
473 while (fgets(buf1, 256, where)) {
474 sscanf(buf1, "%255s", buf2);
475 if (strstr(buf2, s)) {
482 ERR("Could not open the file");
489 static inline int calc_text_width(const char *s, int l)
495 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
497 XftTextExtents8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
503 return XTextWidth(fonts[selected_font].font, s, l);
508 /* formatted text to render on screen, generated in generate_text(),
509 * drawn in draw_stuff() */
511 static char text_buffer[TEXT_BUFFER_SIZE * 4];
513 /* special stuff in text_buffer */
515 #define SPECIAL_CHAR '\x01'
544 unsigned long first_colour; // for graph gradient
545 unsigned long last_colour;
548 /* create specials array on heap instead of stack with introduction of max_specials */
549 static struct special_t *specials = NULL;
551 static unsigned int special_count;
553 static unsigned int special_index; /* used when drawing */
556 #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? */
558 static struct special_t *new_special(char *buf, int t)
560 if (special_count >= max_specials)
561 CRIT_ERR("too many special things in text");
563 buf[0] = SPECIAL_CHAR;
565 specials[special_count].type = t;
566 return &specials[special_count++];
569 long fwd_fcharfind(FILE* fp, char val, unsigned int step) {
572 unsigned int count = 0;
573 static char buf[BUFSZ];
574 long orig_pos = ftell(fp);
576 long buf_size = BUFSZ;
577 char* cur_found = NULL;
578 while(count < step) {
579 if(cur_found == NULL) {
580 buf_size = fread(buf, 1, buf_size, fp);
583 cur_found = memchr(buf+buf_pos, val, buf_size-buf_pos);
584 if(cur_found != NULL) {
585 buf_pos = cur_found-buf+1;
594 ret = ftell(fp) - buf_size + buf_pos - 1;
595 fseek(fp, orig_pos, SEEK_SET);
602 memrchr (const void *buffer, int c, size_t n)
604 const unsigned char *p = buffer;
606 for (p += n; n ; n--)
612 long rev_fcharfind(FILE* fp, char val, unsigned int step) {
615 unsigned int count = 0;
616 static char buf[BUFSZ];
617 long orig_pos = ftell(fp);
619 long file_pos = orig_pos;
620 long buf_size = BUFSZ;
622 while(count < step) {
624 if(file_pos > BUFSZ) {
625 fseek(fp, file_pos-BUFSZ, SEEK_SET);
629 fseek(fp, 0, SEEK_SET);
631 file_pos = ftell(fp);
632 buf_pos = fread(buf, 1, buf_size, fp);
639 if(cur_found != NULL) {
640 buf_pos = cur_found-buf;
649 fseek(fp, orig_pos, SEEK_SET);
651 ret = file_pos + buf_pos;
656 static void new_bar(char *buf, int w, int h, int usage)
658 struct special_t *s = new_special(buf, BAR);
659 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
664 static const char *scan_bar(const char *args, int *w, int *h)
666 *w = 0; /* zero width means all space that is available */
668 /* bar's argument is either height or height,width */
671 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
672 sscanf(args, "%d %n", h, &n);
679 static char *scan_font(const char *args)
681 if (args && sizeof(args) < 127) {
688 static void new_font(char *buf, char * args) {
690 struct special_t *s = new_special(buf, FONT);
691 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
692 int tmp = selected_font;
693 selected_font = s->font_added = addfont(args);
698 struct special_t *s = new_special(buf, FONT);
699 int tmp = selected_font;
700 selected_font = s->font_added = 0;
707 inline void graph_append(struct special_t *graph, double f)
709 if (!graph->scaled && f > graph->graph_scale) {
710 f = graph->graph_scale;
714 graph->graph_scale = 1;
716 graph->graph[0] = f; /* add new data */
717 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
718 graph->graph[i] = graph->graph[i - 1];
719 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
720 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
725 short colour_depth = 0;
726 void set_up_gradient();
728 /* precalculated: 31/255, and 63/255 */
729 #define CONST_8_TO_5_BITS 0.12156862745098
730 #define CONST_8_TO_6_BITS 0.247058823529412
732 /* adjust color values depending on color depth*/
733 static unsigned int adjust_colors(unsigned int color)
736 if (colour_depth == 0) {
739 if (colour_depth == 16) {
740 r = (color & 0xff0000) >> 16;
741 g = (color & 0xff00) >> 8;
743 color = (int)(r * CONST_8_TO_5_BITS) << 11;
744 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
745 color |= (int)(b * CONST_8_TO_5_BITS);
750 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
752 struct special_t *s = new_special(buf, GRAPH);
754 if (s->graph == NULL) {
755 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
756 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
758 s->graph_width = MAX_GRAPH_DEPTH - 2;
760 s->graph = malloc(s->graph_width * sizeof(double));
761 memset(s->graph, 0, s->graph_width * sizeof(double));
762 s->graph_scale = 100;
765 s->first_colour = adjust_colors(first_colour);
766 s->last_colour = adjust_colors(second_colour);
773 s->graph_width = s->width - 2; // subtract 2 for rectangle around
778 s->graph_scale = scale;
785 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
787 *w = 0; /* zero width means all space that is available */
791 /* graph's argument is either height or height,width */
793 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
794 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
796 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
798 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
801 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
805 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
808 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
812 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
815 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
819 if (sscanf(args, "%d,%d", h, w) < 2) {
822 sscanf(args, "%*s %d,%d", h, w);
828 static inline void new_hr(char *buf, int a)
830 new_special(buf, HORIZONTAL_LINE)->height = a;
833 static inline void new_stippled_hr(char *buf, int a, int b)
835 struct special_t *s = new_special(buf, STIPPLED_HR);
840 static inline void new_fg(char *buf, long c)
842 new_special(buf, FG)->arg = c;
845 static inline void new_bg(char *buf, long c)
847 new_special(buf, BG)->arg = c;
850 static inline void new_outline(char *buf, long c)
852 new_special(buf, OUTLINE)->arg = c;
855 static inline void new_offset(char *buf, long c)
857 new_special(buf, OFFSET)->arg = c;
860 static inline void new_voffset(char *buf, long c)
862 new_special(buf, VOFFSET)->arg = c;
865 static inline void new_alignr(char *buf, long c)
867 new_special(buf, ALIGNR)->arg = c;
870 static inline void new_alignc(char *buf, long c)
872 new_special(buf, ALIGNC)->arg = c;
875 static inline void new_goto(char *buf, long c)
877 new_special(buf, GOTO)->arg = c;
880 static inline void new_tab(char *buf, int a, int b) {
881 struct special_t *s = new_special(buf, TAB);
886 /* quite boring functions */
888 static inline void for_each_line(char *b, void (*f) (char *))
892 for (ps = b, pe = b; *pe; pe++) {
905 static void convert_escapes(char *buf)
907 char *p = buf, *s = buf;
923 /* converts from bytes to human readable format (k, M, G, T) */
924 static void human_readable(long long a, char *buf, int size)
926 // Strange conditional due to possible overflows
927 if(a / 1024 / 1024 / 1024.0 > 1024.0){
928 snprintf(buf, size, "%.2fTiB", (a / 1024 / 1024 / 1024) / 1024.0);
930 else if (a >= 1024 * 1024 * 1024) {
931 snprintf(buf, size, "%.2fGiB", (a / 1024 / 1024) / 1024.0);
933 else if (a >= 1024 * 1024) {
934 double m = (a / 1024) / 1024.0;
936 snprintf(buf, size, "%.0fMiB", m);
938 snprintf(buf, size, "%.1fMiB", m);
939 } else if (a >= 1024)
940 snprintf(buf, size, "%LdKiB", a / (long long) 1024);
942 snprintf(buf, size, "%LdB", a);
947 enum text_object_type {
981 OBJ_diskiograph_read,
982 OBJ_diskiograph_write,
1015 #if defined(__linux__)
1021 OBJ_i8k_left_fan_status,
1022 OBJ_i8k_right_fan_status,
1023 OBJ_i8k_left_fan_rpm,
1024 OBJ_i8k_right_fan_rpm,
1026 OBJ_i8k_buttons_status,
1034 #endif /* __linux__ */
1063 OBJ_running_processes,
1072 OBJ_temp1, /* i2c is used instead in these */
1092 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1094 OBJ_apm_battery_time,
1095 OBJ_apm_battery_life,
1096 #endif /* __FreeBSD__ __OpenBSD__ */
1098 OBJ_obsd_sensors_temp,
1099 OBJ_obsd_sensors_fan,
1100 OBJ_obsd_sensors_volt,
1103 #endif /* __OpenBSD__ */
1132 OBJ_xmms2_transport,
1147 OBJ_audacious_status,
1148 OBJ_audacious_title,
1149 OBJ_audacious_length,
1150 OBJ_audacious_length_seconds,
1151 OBJ_audacious_position,
1152 OBJ_audacious_position_seconds,
1153 OBJ_audacious_bitrate,
1154 OBJ_audacious_frequency,
1155 OBJ_audacious_channels,
1156 OBJ_audacious_filename,
1157 OBJ_audacious_playlist_length,
1158 OBJ_audacious_playlist_position,
1172 #ifdef TCP_PORT_MONITOR
1183 OBJ_entropy_poolsize,
1187 struct text_object {
1191 unsigned int c, d, e;
1195 char *s; /* some string */
1196 int i; /* some integer */
1197 long l; /* some other integer */
1198 unsigned int sensor;
1199 struct net_stat *net;
1201 unsigned char loadavg[3];
1202 unsigned int cpu_index;
1203 struct mail_s *mail;
1211 char *tz; /* timezone variable */
1212 char *fmt; /* time display formatting */
1265 timed_thread *p_timed_thread;
1271 #ifdef TCP_PORT_MONITOR
1273 in_port_t port_range_begin; /* starting port to monitor */
1274 in_port_t port_range_end; /* ending port to monitor */
1275 int item; /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1276 int connection_index; /* 0 to n-1 connections. */
1295 struct text_object_list {
1296 unsigned int text_object_count;
1297 struct text_object *text_objects;
1300 static unsigned int text_object_count;
1301 static struct text_object *text_objects;
1302 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1304 #define MAXDATASIZE 1000
1308 struct mail_s* parse_mail_args(char type, const char *arg) {
1309 struct mail_s *mail;
1310 mail = malloc(sizeof(struct mail_s));
1311 memset(mail, 0, sizeof(struct mail_s));
1313 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1315 ERR("Scanning IMAP args failed");
1316 } else if (type == IMAP) {
1317 ERR("Scanning POP3 args failed");
1320 // see if password needs prompting
1321 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1322 int fp = fileno(stdin);
1323 struct termios term;
1324 tcgetattr(fp, &term);
1325 term.c_lflag &= ~ECHO;
1326 tcsetattr(fp, TCSANOW, &term);
1327 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1328 scanf("%128s", mail->pass);
1330 term.c_lflag |= ECHO;
1331 tcsetattr(fp, TCSANOW, &term);
1333 // now we check for optional args
1334 tmp = strstr(arg, "-i ");
1337 sscanf(tmp, "%f", &mail->interval);
1339 mail->interval = 300; // 5 minutes
1341 tmp = strstr(arg, "-p ");
1344 sscanf(tmp, "%lu", &mail->port);
1347 mail->port = 110; // default pop3 port
1348 } else if (type == IMAP) {
1349 mail->port = 143; // default imap port
1353 tmp = strstr(arg, "-f ");
1356 sscanf(tmp, "%s", mail->folder);
1358 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1361 tmp = strstr(arg, "-e ");
1365 if (tmp[0] == '\'') {
1366 len = strstr(tmp+1, "'") - tmp - 1;
1371 strncpy(mail->command, tmp+1, len);
1373 mail->command[0] = '\0';
1375 mail->p_timed_thread = NULL;
1379 void *imap_thread(struct mail_s* mail)
1381 int sockfd, numbytes;
1382 char recvbuf[MAXDATASIZE];
1383 char sendbuf[MAXDATASIZE];
1386 unsigned int old_unseen = UINT_MAX;
1387 unsigned int old_messages = UINT_MAX;
1388 struct stat stat_buf;
1390 struct sockaddr_in their_addr; // connector's address information
1391 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1392 herror("gethostbyname");
1397 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1399 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1402 goto next_iteration;
1405 their_addr.sin_family = AF_INET; // host byte order
1406 their_addr.sin_port = htons(mail->port); // short, network byte order
1407 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1408 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1411 (sockfd, (struct sockaddr *) &their_addr,
1412 sizeof(struct sockaddr)) == -1) {
1415 goto next_iteration;
1417 struct timeval timeout;
1420 timeout.tv_sec = 60; // 60 second timeout i guess
1421 timeout.tv_usec = 0;
1423 FD_SET(sockfd, &fdset);
1424 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1427 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1431 goto next_iteration;
1434 ERR("IMAP connection failed: timeout");
1436 goto next_iteration;
1438 recvbuf[numbytes] = '\0';
1439 if (strstr(recvbuf, "* OK") != recvbuf) {
1440 ERR("IMAP connection failed, probably not an IMAP server");
1442 goto next_iteration;
1444 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1445 strncat(sendbuf, mail->user,
1446 MAXDATASIZE - strlen(sendbuf) - 1);
1447 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1448 strncat(sendbuf, mail->pass,
1449 MAXDATASIZE - strlen(sendbuf) - 1);
1450 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1451 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1454 goto next_iteration;
1456 timeout.tv_sec = 60; // 60 second timeout i guess
1457 timeout.tv_usec = 0;
1459 FD_SET(sockfd, &fdset);
1460 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1463 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1467 goto next_iteration;
1470 recvbuf[numbytes] = '\0';
1471 if (strstr(recvbuf, "a1 OK") == NULL) {
1472 ERR("IMAP server login failed: %s", recvbuf);
1474 goto next_iteration;
1476 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1477 strncat(sendbuf, mail->folder,
1478 MAXDATASIZE - strlen(sendbuf) - 1);
1479 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1480 MAXDATASIZE - strlen(sendbuf) - 1);
1481 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1484 goto next_iteration;
1486 timeout.tv_sec = 60; // 60 second timeout i guess
1487 timeout.tv_usec = 0;
1489 FD_SET(sockfd, &fdset);
1490 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1493 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1497 goto next_iteration;
1500 recvbuf[numbytes] = '\0';
1501 if (strstr(recvbuf, "a2 OK") == NULL) {
1502 ERR("IMAP status failed: %s", recvbuf);
1504 goto next_iteration;
1506 // now we get the data
1507 reply = strstr(recvbuf, " (MESSAGES ");
1509 *strchr(reply, ')') = '\0';
1510 if (reply == NULL) {
1511 ERR("Error parsing IMAP response: %s", recvbuf);
1513 goto next_iteration;
1515 timed_thread_lock (mail->p_timed_thread);
1516 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1519 timed_thread_unlock (mail->p_timed_thread);
1521 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1522 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1525 goto next_iteration;
1527 timeout.tv_sec = 60; // 60 second timeout i guess
1528 timeout.tv_usec = 0;
1530 FD_SET(sockfd, &fdset);
1531 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1534 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1538 goto next_iteration;
1541 recvbuf[numbytes] = '\0';
1542 if (strstr(recvbuf, "a3 OK") == NULL) {
1543 ERR("IMAP logout failed: %s", recvbuf);
1545 goto next_iteration;
1547 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1548 if (system(mail->command) == -1) {
1553 old_unseen = mail->unseen;
1554 old_messages = mail->messages;
1556 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1557 /* if a valid socket, close it */
1559 if (timed_thread_test (mail->p_timed_thread))
1560 timed_thread_exit (mail->p_timed_thread);
1565 void *pop3_thread(struct mail_s *mail)
1567 int sockfd, numbytes;
1568 char recvbuf[MAXDATASIZE];
1569 char sendbuf[MAXDATASIZE];
1572 unsigned int old_unseen = UINT_MAX;
1573 struct stat stat_buf;
1575 struct sockaddr_in their_addr; // connector's address information
1576 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1577 herror("gethostbyname");
1582 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1584 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1587 goto next_iteration;
1590 their_addr.sin_family = AF_INET; // host byte order
1591 their_addr.sin_port = htons(mail->port); // short, network byte order
1592 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1593 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1596 (sockfd, (struct sockaddr *) &their_addr,
1597 sizeof(struct sockaddr)) == -1) {
1600 goto next_iteration;
1602 struct timeval timeout;
1605 timeout.tv_sec = 60; // 60 second timeout i guess
1606 timeout.tv_usec = 0;
1608 FD_SET(sockfd, &fdset);
1609 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1612 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1616 goto next_iteration;
1619 ERR("POP3 connection failed: timeout\n");
1621 goto next_iteration;
1623 recvbuf[numbytes] = '\0';
1624 if (strstr(recvbuf, "+OK ") != recvbuf) {
1625 ERR("POP3 connection failed, probably not a POP3 server");
1627 goto next_iteration;
1629 strncpy(sendbuf, "USER ", MAXDATASIZE);
1630 strncat(sendbuf, mail->user,
1631 MAXDATASIZE - strlen(sendbuf) - 1);
1632 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1633 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1634 perror("send USER");
1636 goto next_iteration;
1638 timeout.tv_sec = 60; // 60 second timeout i guess
1639 timeout.tv_usec = 0;
1641 FD_SET(sockfd, &fdset);
1642 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1645 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1647 perror("recv USER");
1649 goto next_iteration;
1652 recvbuf[numbytes] = '\0';
1653 if (strstr(recvbuf, "+OK ") == NULL) {
1654 ERR("POP3 server login failed: %s", recvbuf);
1656 goto next_iteration;
1658 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1659 strncat(sendbuf, mail->pass,
1660 MAXDATASIZE - strlen(sendbuf) - 1);
1661 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1662 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1663 perror("send PASS");
1665 goto next_iteration;
1667 timeout.tv_sec = 60; // 60 second timeout i guess
1668 timeout.tv_usec = 0;
1670 FD_SET(sockfd, &fdset);
1671 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1674 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1676 perror("recv PASS");
1678 goto next_iteration;
1681 recvbuf[numbytes] = '\0';
1682 if (strstr(recvbuf, "+OK ") == NULL) {
1683 ERR("POP3 server login failed: %s", recvbuf);
1685 goto next_iteration;
1687 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1688 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1689 perror("send STAT");
1691 goto next_iteration;
1693 timeout.tv_sec = 60; // 60 second timeout i guess
1694 timeout.tv_usec = 0;
1696 FD_SET(sockfd, &fdset);
1697 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1700 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1702 perror("recv STAT");
1704 goto next_iteration;
1707 recvbuf[numbytes] = '\0';
1708 if (strstr(recvbuf, "+OK ") == NULL) {
1709 ERR("POP3 status failed: %s", recvbuf);
1711 goto next_iteration;
1713 // now we get the data
1714 reply = recvbuf + 4;
1715 if (reply == NULL) {
1716 ERR("Error parsing POP3 response: %s", recvbuf);
1718 goto next_iteration;
1720 timed_thread_lock (mail->p_timed_thread);
1721 sscanf(reply, "%lu %lu", &mail->unseen,
1723 timed_thread_unlock (mail->p_timed_thread);
1725 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1726 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1727 perror("send QUIT");
1729 goto next_iteration;
1731 timeout.tv_sec = 60; // 60 second timeout i guess
1732 timeout.tv_usec = 0;
1734 FD_SET(sockfd, &fdset);
1735 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1738 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1740 perror("recv QUIT");
1742 goto next_iteration;
1745 recvbuf[numbytes] = '\0';
1746 if (strstr(recvbuf, "+OK") == NULL) {
1747 ERR("POP3 logout failed: %s", recvbuf);
1749 goto next_iteration;
1751 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1752 if (system(mail->command) == -1) {
1757 old_unseen = mail->unseen;
1759 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1760 /* if a valid socket, close it */
1762 if (timed_thread_test (mail->p_timed_thread))
1763 timed_thread_exit (mail->p_timed_thread);
1769 void *threaded_exec(struct text_object *obj) {
1771 char *p2 = obj->data.texeci.buffer;
1772 FILE *fp = popen(obj->data.texeci.cmd,"r");
1773 timed_thread_lock (obj->data.texeci.p_timed_thread);
1774 int n2 = fread(p2, 1, text_buffer_size, fp);
1777 if (n2 && p2[n2 - 1] == '\n') {
1781 if (*p2 == '\001') {
1786 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1787 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1788 timed_thread_exit (obj->data.texeci.p_timed_thread);
1793 static struct text_object *new_text_object_internal()
1795 struct text_object *obj = malloc(sizeof(struct text_object));
1796 memset(obj, 0, sizeof(struct text_object));
1800 static void free_text_objects(unsigned int count, struct text_object *objs)
1803 for (i = 0; i < count; i++) {
1804 switch (objs[i].type) {
1806 close(objs[i].data.i);
1809 close(objs[i].data.i);
1812 close(objs[i].data.i2c.fd);
1815 free(objs[i].data.s);
1818 free(objs[i].data.s);
1821 free(objs[i].data.tztime.tz);
1822 free(objs[i].data.tztime.fmt);
1825 free(objs[i].data.mboxscan.args);
1826 free(objs[i].data.mboxscan.output);
1831 case OBJ_imap_unseen:
1832 if (!objs[i].global_mode) {
1833 free(objs[i].data.mail);
1836 case OBJ_imap_messages:
1837 if (!objs[i].global_mode) {
1838 free(objs[i].data.mail);
1844 case OBJ_pop3_unseen:
1845 if (!objs[i].global_mode) {
1846 free(objs[i].data.mail);
1850 if (!objs[i].global_mode) {
1851 free(objs[i].data.mail);
1855 case OBJ_if_existing:
1856 case OBJ_if_mounted:
1857 case OBJ_if_running:
1858 free(objs[i].data.ifblock.s);
1859 free(objs[i].data.ifblock.str);
1862 free(objs[i].data.tail.logfile);
1863 free(objs[i].data.tail.buffer);
1865 case OBJ_text: case OBJ_font:
1866 free(objs[i].data.s);
1869 free(objs[i].data.s);
1872 free(objs[i].data.s);
1875 free(objs[i].data.s);
1878 free(objs[i].data.s);
1880 /* case OBJ_execibar:
1881 free(objs[i].data.s);
1883 case OBJ_execigraph:
1884 free(objs[i].data.s);
1887 case OBJ_iconv_start:
1893 if (info.mpd.title) {
1894 free(info.mpd.title);
1898 case OBJ_mpd_artist:
1899 if (info.mpd.artist) {
1900 free(info.mpd.artist);
1901 info.mpd.artist = 0;
1905 if (info.mpd.album) {
1906 free(info.mpd.album);
1910 case OBJ_mpd_random:
1911 if (info.mpd.random) {
1912 free(info.mpd.random);
1913 info.mpd.random = 0;
1916 case OBJ_mpd_repeat:
1917 if (info.mpd.repeat) {
1918 free(info.mpd.repeat);
1919 info.mpd.repeat = 0;
1923 if (info.mpd.track) {
1924 free(info.mpd.track);
1929 if (info.mpd.name) {
1930 free(info.mpd.name);
1935 if (info.mpd.file) {
1936 free(info.mpd.file);
1940 case OBJ_mpd_status:
1941 if (info.mpd.status) {
1942 free(info.mpd.status);
1943 info.mpd.status = 0;
1947 if (info.mpd.artist) {
1948 free(info.mpd.artist);
1949 info.mpd.artist = 0;
1951 if (info.mpd.title) {
1952 free(info.mpd.title);
1955 if (info.mpd.file) {
1956 free(info.mpd.file);
1963 case OBJ_xmms2_artist:
1964 if (info.xmms2.artist) {
1965 free(info.xmms2.artist);
1966 info.xmms2.artist = 0;
1969 case OBJ_xmms2_album:
1970 if (info.xmms2.album) {
1971 free(info.xmms2.album);
1972 info.xmms2.album = 0;
1975 case OBJ_xmms2_title:
1976 if (info.xmms2.title) {
1977 free(info.xmms2.title);
1978 info.xmms2.title = 0;
1981 case OBJ_xmms2_genre:
1982 if (info.xmms2.genre) {
1983 free(info.xmms2.genre);
1984 info.xmms2.genre = 0;
1987 case OBJ_xmms2_comment:
1988 if (info.xmms2.comment) {
1989 free(info.xmms2.comment);
1990 info.xmms2.comment = 0;
1993 case OBJ_xmms2_decoder:
1994 if (info.xmms2.decoder) {
1995 free(info.xmms2.decoder);
1999 case OBJ_xmms2_transport:
2000 if (info.xmms2.transport) {
2001 free(info.xmms2.transport);
2006 if (info.xmms2.url) {
2007 free(info.xmms2.url);
2011 case OBJ_xmms2_date:
2012 if (info.xmms2.date) {
2013 free(info.xmms2.date);
2014 info.xmms2.date = 0;
2017 case OBJ_xmms2_status:
2018 if (info.xmms2.status) {
2019 free(info.xmms2.status);
2020 info.xmms2.status = 0;
2023 case OBJ_xmms2_smart:
2024 if (info.xmms2.artist) {
2025 free(info.xmms2.artist);
2026 info.xmms2.artist = 0;
2028 if (info.xmms2.title) {
2029 free(info.xmms2.title);
2030 info.xmms2.title = 0;
2032 if (info.xmms2.url) {
2033 free(info.xmms2.url);
2039 case OBJ_bmpx_title:
2040 case OBJ_bmpx_artist:
2041 case OBJ_bmpx_album:
2042 case OBJ_bmpx_track:
2044 case OBJ_bmpx_bitrate:
2048 free(objs[i].data.rss.uri);
2052 free(objs[i].data.s);
2054 case OBJ_battery_time:
2055 free(objs[i].data.s);
2058 free(objs[i].data.execi.cmd);
2059 free(objs[i].data.execi.buffer);
2062 free(objs[i].data.texeci.cmd);
2063 free(objs[i].data.texeci.buffer);
2066 if (info.first_process) {
2067 free_all_processes();
2068 info.first_process = NULL;
2072 if (info.first_process) {
2073 free_all_processes();
2074 info.first_process = NULL;
2079 free(objs[i].data.hddtemp.dev);
2080 free(objs[i].data.hddtemp.addr);
2083 case OBJ_entropy_avail:
2084 case OBJ_entropy_poolsize:
2085 case OBJ_entropy_bar:
2090 //text_objects = NULL;
2091 //text_object_count = 0;
2094 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2099 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2100 *a = mixer_init(buf1);
2101 (void) scan_bar(arg + n, w, h);
2104 (void) scan_bar(arg, w, h);
2109 /* construct_text_object() creates a new text_object */
2110 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2112 //struct text_object *obj = new_text_object();
2113 struct text_object *obj = new_text_object_internal();
2116 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2117 #define END ; } } else
2121 obj->type = OBJ_color;
2122 obj->data.l = get_x11_color(s);
2125 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2126 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2127 END OBJ(acpiacadapter, 0)
2128 END OBJ(freq, INFO_FREQ)
2134 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2136 obj->data.cpu_index=1;
2137 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2141 obj->data.cpu_index=atoi(&arg[0]);
2144 END OBJ(freq_g, INFO_FREQ)
2150 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2152 obj->data.cpu_index=1;
2153 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2157 obj->data.cpu_index=atoi(&arg[0]);
2160 #if defined(__linux__)
2161 END OBJ(voltage_mv, 0)
2167 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2169 obj->data.cpu_index=1;
2170 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2174 obj->data.cpu_index=atoi(&arg[0]);
2177 END OBJ(voltage_v, 0)
2183 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2185 obj->data.cpu_index=1;
2186 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2190 obj->data.cpu_index=atoi(&arg[0]);
2193 #endif /* __linux__ */
2194 END OBJ(freq_dyn, 0);
2195 END OBJ(freq_dyn_g, 0);
2196 END OBJ(acpifan, 0);
2197 END OBJ(battery, 0);
2200 sscanf(arg, "%63s", bat);
2202 strcpy(bat, "BAT0");
2203 obj->data.s = strdup(bat);
2204 END OBJ(battery_time, 0);
2207 sscanf(arg, "%63s", bat);
2209 strcpy(bat, "BAT0");
2210 obj->data.s = strdup(bat);
2211 END OBJ(battery_percent, 0);
2214 sscanf(arg, "%63s", bat);
2216 strcpy(bat, "BAT0");
2217 obj->data.s = strdup(bat);
2218 END OBJ(battery_bar, 0);
2221 arg = scan_bar(arg, &obj->a, &obj->b);
2222 sscanf(arg, "%63s", bat);
2224 strcpy(bat, "BAT0");
2226 #if defined(__linux__)
2227 END OBJ(i8k_version, INFO_I8K)
2228 END OBJ(i8k_bios, INFO_I8K)
2229 END OBJ(i8k_serial, INFO_I8K)
2230 END OBJ(i8k_cpu_temp, INFO_I8K)
2231 END OBJ(i8k_cpu_tempf, INFO_I8K)
2232 END OBJ(i8k_left_fan_status, INFO_I8K)
2233 END OBJ(i8k_right_fan_status, INFO_I8K)
2234 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2235 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2236 END OBJ(i8k_ac_status, INFO_I8K)
2237 END OBJ(i8k_buttons_status, INFO_I8K)
2239 END OBJ(ibm_temps, 0)
2241 CRIT_ERR("ibm_temps: needs an argument");
2243 if (!isdigit(arg[0])
2245 || atoi(&arg[0]) >=8)
2248 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2250 obj->data.sensor = atoi(&arg[0]);
2251 END OBJ(ibm_volume, 0)
2252 END OBJ(ibm_brightness, 0)
2253 END OBJ(pb_battery, 0)
2254 if (arg && strcmp(arg, "status") == 0) {
2255 obj->data.i = PB_BATT_STATUS;
2256 } else if (arg && strcmp(arg, "percent") == 0) {
2257 obj->data.i = PB_BATT_PERCENT;
2258 } else if (arg && strcmp(arg, "time") == 0) {
2259 obj->data.i = PB_BATT_TIME;
2261 ERR("pb_battery: needs one argument: status, percent or time");
2266 #endif /* __linux__ */
2267 #if defined(__OpenBSD__)
2268 END OBJ(obsd_sensors_temp, 0);
2270 CRIT_ERR("obsd_sensors_temp: needs an argument");
2272 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2274 ERR("Invalid temperature sensor number!");
2276 obj->data.sensor = atoi(&arg[0]);
2277 END OBJ(obsd_sensors_fan, 0);
2279 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor number)");
2281 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2283 ERR("Invalid fan sensor number!");
2285 obj->data.sensor = atoi(&arg[0]);
2286 END OBJ(obsd_sensors_volt, 0);
2288 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor number)");
2290 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2292 ERR("Invalid voltage sensor number!");
2294 obj->data.sensor = atoi(&arg[0]);
2295 END OBJ(obsd_vendor, 0);
2296 END OBJ(obsd_product, 0);
2297 #endif /* __OpenBSD__ */
2298 END OBJ(buffers, INFO_BUFFERS)
2299 END OBJ(cached, INFO_BUFFERS)
2300 END OBJ(cpu, INFO_CPU)
2302 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2303 obj->data.cpu_index = atoi(&arg[3]);
2305 } else {obj->data.cpu_index = 0; }
2307 obj->data.cpu_index = 0;
2309 END OBJ(cpubar, INFO_CPU)
2311 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2312 obj->data.cpu_index = atoi(&arg[3]);
2315 else {obj->data.cpu_index = 0;}
2316 (void) scan_bar(arg, &obj->a, &obj->b);
2318 (void) scan_bar(arg, &obj->a, &obj->b);
2319 obj->data.cpu_index = 0;
2321 END OBJ(cpugraph, INFO_CPU)
2323 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2324 obj->data.cpu_index = atoi(&arg[3]);
2327 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2329 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2330 obj->data.cpu_index = 0;
2332 END OBJ(diskio, INFO_DISKIO)
2333 END OBJ(diskio_read, INFO_DISKIO)
2334 END OBJ(diskio_write, INFO_DISKIO)
2335 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2336 END OBJ(diskiograph_read, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2337 END OBJ(diskiograph_write, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2340 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2343 obj->data.l = color0;
2345 obj->data.l = color1;
2347 obj->data.l = color2;
2349 obj->data.l = color3;
2351 obj->data.l = color4;
2353 obj->data.l = color5;
2355 obj->data.l = color6;
2357 obj->data.l = color7;
2359 obj->data.l = color8;
2361 obj->data.l = color9;
2363 obj->data.s = scan_font(arg);
2365 OBJ(downspeed, INFO_NET)
2367 obj->data.net = get_net_stat(arg);
2370 CRIT_ERR("downspeed needs argument");
2372 END OBJ(downspeedf, INFO_NET)
2374 obj->data.net = get_net_stat(arg);
2377 CRIT_ERR("downspeedf needs argument");
2379 END OBJ(downspeedgraph, INFO_NET)
2380 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2382 sscanf(arg, "%63s %*i,%*i %*i", buf);
2383 obj->data.net = get_net_stat(buf);
2384 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2385 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
2392 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2393 blockstart[blockdepth - 1] = object_count;
2394 obj->data.ifblock.pos = object_count + 2;
2396 ERR("$else: no matching $if_*");
2401 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2403 ERR("$endif: no matching $if_*");
2406 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2409 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2410 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2411 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2412 END OBJ(execibar, 0) unsigned int n;
2413 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2415 ERR("${execibar <interval> command}");
2416 obj->type = OBJ_text;
2417 snprintf(buf, 256, "${%s}", s);
2418 obj->data.s = strdup(buf);
2420 obj->data.execi.cmd = strdup(arg + n);
2422 END OBJ(execigraph, 0) unsigned int n;
2423 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2425 ERR("${execigraph <interval> command}");
2426 obj->type = OBJ_text;
2427 snprintf(buf, 256, "${%s}", s);
2428 obj->data.s = strdup(buf);
2430 obj->data.execi.cmd = strdup(arg + n);
2432 END OBJ(execi, 0) unsigned int n;
2433 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2435 ERR("${execi <interval> command}");
2436 obj->type = OBJ_text;
2437 snprintf(buf, 256, "${%s}", s);
2438 obj->data.s = strdup(buf);
2440 obj->data.execi.cmd = strdup(arg + n);
2441 obj->data.execi.buffer =
2442 (char *) calloc(1, text_buffer_size);
2444 END OBJ(texeci, 0) unsigned int n;
2445 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2447 ERR("${texeci <interval> command}");
2448 obj->type = OBJ_text;
2449 snprintf(buf, 256, "${%s}", s);
2450 obj->data.s = strdup(buf);
2452 obj->data.texeci.cmd = strdup(arg + n);
2453 obj->data.texeci.buffer =
2454 (char *) calloc(1, text_buffer_size);
2456 obj->data.texeci.p_timed_thread = NULL;
2457 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2459 FILE *fp = popen(arg, "r");
2463 n = fread(buf, 1, 2048, fp);
2466 if (n && buf[n - 1] == '\n')
2471 obj->data.s = strdup(buf);
2473 obj->data.s = strdup("");
2476 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2477 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2479 while (isspace(*arg))
2485 obj->data.fsbar.fs = prepare_fs_stat(arg);
2486 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2489 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2493 obj->data.fsbar.fs = prepare_fs_stat(arg);
2494 END OBJ(fs_free, INFO_FS) if (!arg)
2496 obj->data.fs = prepare_fs_stat(arg);
2497 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2499 obj->data.fs = prepare_fs_stat(arg);
2500 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2502 obj->data.fs = prepare_fs_stat(arg);
2503 END OBJ(fs_size, INFO_FS) if (!arg)
2505 obj->data.fs = prepare_fs_stat(arg);
2506 END OBJ(fs_used, INFO_FS) if (!arg)
2508 obj->data.fs = prepare_fs_stat(arg);
2509 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2510 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2511 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2515 ERR("goto needs arguments");
2516 obj->type = OBJ_text;
2517 obj->data.s = strdup("${goto}");
2521 obj->data.i = atoi(arg);
2526 if (sscanf(arg, "%d %d", &a, &b) != 2)
2527 sscanf(arg, "%d", &b);
2531 obj->data.pair.a = a;
2532 obj->data.pair.b = b;
2534 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
2538 ERR("i2c needs arguments");
2539 obj->type = OBJ_text;
2540 //obj->data.s = strdup("${i2c}");
2544 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2545 /* if scanf couldn't read three values, read type and num and use
2547 sscanf(arg, "%63s %d", buf2, &n);
2549 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
2550 obj->data.i2c.devtype);
2551 strncpy(obj->data.i2c.type, buf2, 63);
2554 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
2555 obj->data.i2c.devtype);
2556 strncpy(obj->data.i2c.type, buf2, 63);
2559 END OBJ(top, INFO_TOP)
2563 ERR("top needs arguments");
2564 obj->type = OBJ_text;
2565 //obj->data.s = strdup("${top}");
2568 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2569 if (strcmp(buf, "name") == 0) {
2570 obj->data.top.type = TOP_NAME;
2571 } else if (strcmp(buf, "cpu") == 0) {
2572 obj->data.top.type = TOP_CPU;
2573 } else if (strcmp(buf, "pid") == 0) {
2574 obj->data.top.type = TOP_PID;
2575 } else if (strcmp(buf, "mem") == 0) {
2576 obj->data.top.type = TOP_MEM;
2578 ERR("invalid arg for top");
2581 if (n < 1 || n > 10) {
2582 CRIT_ERR("invalid arg for top");
2585 obj->data.top.num = n - 1;
2589 ERR("invalid args given for top");
2592 END OBJ(top_mem, INFO_TOP)
2596 ERR("top_mem needs arguments");
2597 obj->type = OBJ_text;
2598 obj->data.s = strdup("${top_mem}");
2601 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2602 if (strcmp(buf, "name") == 0) {
2603 obj->data.top.type = TOP_NAME;
2604 } else if (strcmp(buf, "cpu") == 0) {
2605 obj->data.top.type = TOP_CPU;
2606 } else if (strcmp(buf, "pid") == 0) {
2607 obj->data.top.type = TOP_PID;
2608 } else if (strcmp(buf, "mem") == 0) {
2609 obj->data.top.type = TOP_MEM;
2611 ERR("invalid arg for top");
2614 if (n < 1 || n > 10) {
2615 CRIT_ERR("invalid arg for top");
2618 obj->data.top.num = n - 1;
2622 ERR("invalid args given for top");
2625 END OBJ(addr, INFO_NET)
2627 obj->data.net = get_net_stat(arg);
2630 CRIT_ERR("addr needs argument");
2632 END OBJ(linkstatus, INFO_WIFI)
2634 obj->data.net = get_net_stat(arg);
2637 CRIT_ERR("linkstatus needs argument");
2643 ERR("tail needs arguments");
2644 obj->type = OBJ_text;
2645 obj->data.s = strdup("${tail}");
2648 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2649 if (n1 < 1 || n1 > 30) {
2650 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2654 fp = fopen(buf, "r");
2656 obj->data.tail.logfile =
2657 malloc(text_buffer_size);
2658 strcpy(obj->data.tail.logfile, buf);
2659 obj->data.tail.wantedlines = n1;
2660 obj->data.tail.interval =
2661 update_interval * 2;
2665 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2668 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2669 if (n1 < 1 || n1 > 30) {
2671 ("invalid arg for tail, number of lines must be between 1 and 30");
2673 } else if (n2 < 1 || n2 < update_interval) {
2675 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2679 fp = fopen(buf, "r");
2681 obj->data.tail.logfile =
2682 malloc(text_buffer_size);
2683 strcpy(obj->data.tail.logfile, buf);
2684 obj->data.tail.wantedlines = n1;
2685 obj->data.tail.interval = n2;
2689 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2695 ERR("invalid args given for tail");
2698 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2703 ERR("head needs arguments");
2704 obj->type = OBJ_text;
2705 obj->data.s = strdup("${head}");
2708 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2709 if (n1 < 1 || n1 > 30) {
2710 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2714 fp = fopen(buf, "r");
2716 obj->data.tail.logfile =
2717 malloc(text_buffer_size);
2718 strcpy(obj->data.tail.logfile, buf);
2719 obj->data.tail.wantedlines = n1;
2720 obj->data.tail.interval =
2721 update_interval * 2;
2725 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2728 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2729 if (n1 < 1 || n1 > 30) {
2731 ("invalid arg for head, number of lines must be between 1 and 30");
2733 } else if (n2 < 1 || n2 < update_interval) {
2735 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2739 fp = fopen(buf, "r");
2741 obj->data.tail.logfile =
2742 malloc(text_buffer_size);
2743 strcpy(obj->data.tail.logfile, buf);
2744 obj->data.tail.wantedlines = n1;
2745 obj->data.tail.interval = n2;
2749 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2755 ERR("invalid args given for head");
2758 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2759 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2761 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2762 if (r >= 3 && (c < 1 || c > 3))
2764 if (r >= 2 && (b < 1 || b > 3))
2766 if (r >= 1 && (a < 1 || a > 3))
2769 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2770 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2771 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2772 END OBJ(if_empty, 0)
2773 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2774 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2777 ERR("if_empty needs an argument");
2778 obj->data.ifblock.s = 0;
2780 obj->data.ifblock.s = strdup(arg);
2781 blockstart[blockdepth] = object_count;
2782 obj->data.ifblock.pos = object_count + 2;
2784 END OBJ(if_existing, 0)
2785 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2786 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2789 ERR("if_existing needs an argument or two");
2790 obj->data.ifblock.s = NULL;
2791 obj->data.ifblock.str = NULL;
2793 char buf1[256], buf2[256];
2794 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2796 obj->data.ifblock.s = strdup(buf1);
2797 obj->data.ifblock.str = NULL;
2799 obj->data.ifblock.s = strdup(buf1);
2800 obj->data.ifblock.str = strdup(buf2);
2803 blockstart[blockdepth] = object_count;
2804 obj->data.ifblock.pos = object_count + 2;
2806 END OBJ(if_mounted, 0)
2807 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2808 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2811 ERR("if_mounted needs an argument");
2812 obj->data.ifblock.s = 0;
2814 obj->data.ifblock.s = strdup(arg);
2815 blockstart[blockdepth] = object_count;
2816 obj->data.ifblock.pos = object_count + 2;
2818 END OBJ(if_running, 0)
2819 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2820 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2824 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2825 obj->data.ifblock.s = strdup(buf);
2827 ERR("if_running needs an argument");
2828 obj->data.ifblock.s = 0;
2830 blockstart[blockdepth] = object_count;
2831 obj->data.ifblock.pos = object_count + 2;
2835 END OBJ(mails, INFO_MAIL)
2836 END OBJ(mboxscan, 0)
2837 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
2838 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
2839 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2840 obj->data.mboxscan.output[0] = 1;
2841 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
2842 END OBJ(mem, INFO_MEM)
2843 END OBJ(memmax, INFO_MEM)
2844 END OBJ(memperc, INFO_MEM)
2845 END OBJ(membar, INFO_MEM)
2846 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2847 END OBJ(memgraph, INFO_MEM)
2848 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2849 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2850 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2851 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2852 END OBJ(mixerbar, INFO_MIXER)
2853 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2854 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2855 END OBJ(mixerlbar, INFO_MIXER)
2856 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2857 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2858 END OBJ(mixerrbar, INFO_MIXER)
2859 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2860 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2862 OBJ(new_mails, INFO_MAIL)
2863 END OBJ(nodename, 0)
2864 END OBJ(processes, INFO_PROCS)
2865 END OBJ(running_processes, INFO_RUN_PROCS)
2866 END OBJ(shadecolor, 0)
2868 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2870 END OBJ(outlinecolor, 0)
2872 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2874 END OBJ(stippled_hr, 0)
2876 int a = stippled_borders, b = 1;
2878 if (sscanf(arg, "%d %d", &a, &b) != 2)
2879 sscanf(arg, "%d", &b);
2883 obj->data.pair.a = a;
2884 obj->data.pair.b = b;
2886 END OBJ(swap, INFO_MEM)
2887 END OBJ(swapmax, INFO_MEM)
2888 END OBJ(swapperc, INFO_MEM)
2889 END OBJ(swapbar, INFO_MEM)
2890 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2891 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
2893 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
2894 obj->data.i2c.devtype);
2895 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
2897 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
2898 obj->data.i2c.devtype);
2899 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2900 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2902 char buf1[256], buf2[256], *fmt, *tz;
2905 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2914 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
2915 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
2917 END OBJ(iconv_start, 0)
2918 if (iconv_converting) {
2919 CRIT_ERR("You must stop your last iconv conversion before starting another");
2922 char iconv_from[CODEPAGE_LENGTH];
2923 char iconv_to[CODEPAGE_LENGTH];
2924 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2925 CRIT_ERR("Invalid arguments for iconv_start");
2928 new_iconv = iconv_open(iconv_to, iconv_from);
2929 if (new_iconv == (iconv_t)(-1)) {
2930 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2932 obj->a = register_iconv(&new_iconv);
2933 iconv_converting = 1;
2937 CRIT_ERR("Iconv requires arguments");
2939 END OBJ(iconv_stop, 0)
2940 iconv_converting = 0;
2943 END OBJ(totaldown, INFO_NET)
2945 obj->data.net = get_net_stat(arg);
2948 CRIT_ERR("totaldown needs argument");
2950 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
2952 obj->data.net = get_net_stat(arg);
2955 CRIT_ERR("totalup needs argument");
2958 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
2959 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
2960 END OBJ(upspeed, INFO_NET)
2962 obj->data.net = get_net_stat(arg);
2965 CRIT_ERR("upspeed needs argument");
2967 END OBJ(upspeedf, INFO_NET)
2969 obj->data.net = get_net_stat(arg);
2972 CRIT_ERR("upspeedf needs argument");
2975 END OBJ(upspeedgraph, INFO_NET)
2976 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2978 sscanf(arg, "%63s %*i,%*i %*i", buf);
2979 obj->data.net = get_net_stat(buf);
2980 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2981 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
2986 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
2987 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
2988 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2989 OBJ(apm_adapter, 0) END
2990 OBJ(apm_battery_life, 0) END
2991 OBJ(apm_battery_time, 0) END
2992 #endif /* __FreeBSD__ */
2996 obj->data.mail = parse_mail_args(IMAP, arg);
2997 obj->global_mode = 0;
2999 obj->global_mode = 1;
3002 OBJ(imap_messages, 0)
3005 obj->data.mail = parse_mail_args(IMAP, arg);
3006 obj->global_mode = 0;
3008 obj->global_mode = 1;
3014 obj->data.mail = parse_mail_args(POP3, arg);
3015 obj->global_mode = 0;
3017 obj->global_mode = 1;
3023 obj->data.mail = parse_mail_args(POP3, arg);
3024 obj->global_mode = 0;
3026 obj->global_mode = 1;
3030 OBJ(mpd_artist, INFO_MPD)
3031 END OBJ(mpd_title, INFO_MPD)
3032 END OBJ(mpd_random, INFO_MPD)
3033 END OBJ(mpd_repeat, INFO_MPD)
3034 END OBJ(mpd_elapsed, INFO_MPD)
3035 END OBJ(mpd_length, INFO_MPD)
3036 END OBJ(mpd_track, INFO_MPD)
3037 END OBJ(mpd_name, INFO_MPD)
3038 END OBJ(mpd_file, INFO_MPD)
3039 END OBJ(mpd_percent, INFO_MPD)
3040 END OBJ(mpd_album, INFO_MPD)
3041 END OBJ(mpd_vol, INFO_MPD)
3042 END OBJ(mpd_bitrate, INFO_MPD)
3043 END OBJ(mpd_status, INFO_MPD)
3044 END OBJ(mpd_bar, INFO_MPD)
3045 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3046 END OBJ(mpd_smart, INFO_MPD) END
3049 OBJ(xmms2_artist, INFO_XMMS2)
3050 END OBJ(xmms2_album, INFO_XMMS2)
3051 END OBJ(xmms2_title, INFO_XMMS2)
3052 END OBJ(xmms2_genre, INFO_XMMS2)
3053 END OBJ(xmms2_comment, INFO_XMMS2)
3054 END OBJ(xmms2_decoder, INFO_XMMS2)
3055 END OBJ(xmms2_transport, INFO_XMMS2)
3056 END OBJ(xmms2_url, INFO_XMMS2)
3057 END OBJ(xmms2_tracknr, INFO_XMMS2)
3058 END OBJ(xmms2_bitrate, INFO_XMMS2)
3059 END OBJ(xmms2_date, INFO_XMMS2)
3060 END OBJ(xmms2_id, INFO_XMMS2)
3061 END OBJ(xmms2_duration, INFO_XMMS2)
3062 END OBJ(xmms2_elapsed, INFO_XMMS2)
3063 END OBJ(xmms2_size, INFO_XMMS2)
3064 END OBJ(xmms2_status, INFO_XMMS2)
3065 END OBJ(xmms2_percent, INFO_XMMS2)
3066 END OBJ(xmms2_bar, INFO_XMMS2)
3067 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3068 END OBJ(xmms2_smart, INFO_XMMS2)
3072 OBJ(audacious_status, INFO_AUDACIOUS) END
3073 OBJ(audacious_title, INFO_AUDACIOUS)
3077 sscanf (arg, "%d", &info.audacious.max_title_len);
3078 if (info.audacious.max_title_len > 0)
3079 info.audacious.max_title_len++;
3081 CRIT_ERR ("audacious_title: invalid length argument");
3085 OBJ(audacious_length, INFO_AUDACIOUS) END
3086 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3087 OBJ(audacious_position, INFO_AUDACIOUS) END
3088 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3089 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3090 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3091 OBJ(audacious_channels, INFO_AUDACIOUS) END
3092 OBJ(audacious_filename, INFO_AUDACIOUS) END
3093 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3094 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3095 OBJ(audacious_bar, INFO_AUDACIOUS)
3096 (void) scan_bar(arg, &obj->a, &obj->b);
3100 OBJ(bmpx_title, INFO_BMPX)
3101 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3103 OBJ(bmpx_artist, INFO_BMPX)
3104 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3106 OBJ(bmpx_album, INFO_BMPX)
3107 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3109 OBJ(bmpx_track, INFO_BMPX)
3110 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3112 OBJ(bmpx_uri, INFO_BMPX)
3113 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3115 OBJ(bmpx_bitrate, INFO_BMPX)
3116 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3123 char *uri = (char *)malloc(64 * sizeof(char *));
3125 argc = sscanf(arg, "%63s %d", uri, &count);
3126 printf("argc: %d, uri: %s, count: %d\n", argc, uri, count);
3127 obj->data.rss.uri = uri;
3128 obj->data.rss.count = count;
3130 CRIT_ERR("rss: needs arguments");
3136 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3137 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3138 ERR("hddtemp needs arguments");
3139 obj->type = OBJ_text;
3140 obj->data.s = strdup("${hddtemp}");
3145 #ifdef TCP_PORT_MONITOR
3146 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3147 int argc, port_begin, port_end, item, connection_index;
3149 memset(itembuf,0,sizeof(itembuf));
3151 /* massive argument checking */
3153 CRIT_ERR("tcp_portmon: needs arguments");
3155 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3156 if ( (argc != 3) && (argc != 4) )
3158 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3160 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3162 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3164 if ( port_begin > port_end )
3166 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3168 if ( strncmp(itembuf,"count",31) == 0 )
3170 else if ( strncmp(itembuf,"rip",31) == 0 )
3172 else if ( strncmp(itembuf,"rhost",31) == 0 )
3174 else if ( strncmp(itembuf,"rport",31) == 0 )
3176 else if ( strncmp(itembuf,"rservice",31) == 0 )
3178 else if ( strncmp(itembuf,"lip",31) == 0 )
3180 else if ( strncmp(itembuf,"lhost",31) == 0 )
3182 else if ( strncmp(itembuf,"lport",31) == 0 )
3184 else if ( strncmp(itembuf,"lservice",31) == 0 )
3188 CRIT_ERR("tcp_portmon: invalid item specified");
3190 if ( (argc==3) && (item!=COUNT) )
3192 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3194 if ( (argc==4) && (connection_index<0) )
3196 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3198 /* ok, args looks good. save the text object data */
3199 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3200 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3201 obj->data.tcp_port_monitor.item = item;
3202 obj->data.tcp_port_monitor.connection_index = connection_index;
3204 /* if the port monitor collection hasn't been created, we must create it */
3205 if ( !info.p_tcp_port_monitor_collection )
3207 info.p_tcp_port_monitor_collection =
3208 create_tcp_port_monitor_collection ();
3209 if ( !info.p_tcp_port_monitor_collection )
3211 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3215 /* if a port monitor for this port does not exist, create one and add it to the collection */
3216 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3218 tcp_port_monitor_t * p_monitor =
3219 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3222 CRIT_ERR("tcp_portmon: unable to create port monitor");
3224 /* add the newly created monitor to the collection */
3225 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3228 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3233 OBJ(entropy_avail, INFO_ENTROPY) END
3234 OBJ(entropy_poolsize, INFO_ENTROPY) END
3235 OBJ(entropy_bar, INFO_ENTROPY)
3236 (void) scan_bar(arg, &obj->a, &obj->b);
3241 ERR("unknown variable %s", s);
3242 obj->type = OBJ_text;
3243 snprintf(buf, 256, "${%s}", s);
3244 obj->data.s = strdup(buf);
3251 static struct text_object *create_plain_text(const char *s)
3253 struct text_object *obj;
3255 if (s == NULL || *s == '\0') {
3259 obj = new_text_object_internal();
3261 obj->type = OBJ_text;
3262 obj->data.s = strdup(s);
3266 static struct text_object_list *extract_variable_text_internal(const char *p)
3268 struct text_object_list *retval;
3269 struct text_object *obj;
3272 retval = malloc(sizeof(struct text_object_list));
3273 memset(retval, 0, sizeof(struct text_object_list));
3274 retval->text_object_count = 0;
3276 long line = text_lines;
3284 obj = create_plain_text(s);
3286 // allocate memory for the object
3287 retval->text_objects = realloc(retval->text_objects,
3288 sizeof(struct text_object) * (retval->text_object_count+1));
3289 // assign the new object to the end of the list.
3290 memcpy(&retval->text_objects[retval->text_object_count++],
3291 obj, sizeof(struct text_object));
3303 /* variable is either $foo or ${foo} */
3305 unsigned int brl = 1, brr = 0;
3308 while (*p && brl != brr) {
3309 if (*p == '{') brl++;
3310 if (*p == '}') brr++;
3318 while (*p && (isalnum((int) *p)
3323 /* copy variable to buffer */
3324 len = (p - s > 255) ? 255 : (p - s);
3325 strncpy(buf, s, len);
3334 /* if variable wasn't found from environment, use some special */
3340 if (strchr(buf, ' ')) {
3341 arg = strchr(buf, ' ');
3344 while (isspace((int) *arg))
3350 /* lowercase variable name */
3357 // create new object
3358 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3360 // allocate memory for the object
3361 retval->text_objects = realloc(retval->text_objects,
3362 sizeof(struct text_object) * (retval->text_object_count+1));
3363 // assign the new object to the end of the list.
3364 memcpy(&retval->text_objects[retval->text_object_count++],
3365 obj, sizeof(struct text_object));
3371 obj = create_plain_text("$");
3373 // allocate memory for the object
3374 retval->text_objects = realloc(retval->text_objects,
3375 sizeof(struct text_object) * (retval->text_object_count+1));
3376 // assign the new object to the end of the list.
3377 memcpy(&retval->text_objects[retval->text_object_count++],
3378 obj, sizeof(struct text_object));
3385 obj = create_plain_text(s);
3387 // allocate memory for the object
3388 retval->text_objects = realloc(retval->text_objects,
3389 sizeof(struct text_object) * (retval->text_object_count+1));
3390 // assign the new object to the end of the list.
3391 memcpy(&retval->text_objects[retval->text_object_count++],
3392 obj, sizeof(struct text_object));
3397 ERR("one or more $endif's are missing");
3403 static void extract_variable_text(const char *p)
3405 struct text_object_list *list;
3407 free_text_objects(text_object_count, text_objects);
3408 text_object_count = 0;
3409 text_objects = NULL;
3412 list = extract_variable_text_internal(p);
3413 text_objects = list->text_objects;
3414 text_object_count = list->text_object_count;
3421 void parse_conky_vars(char * text, char * p, struct information *cur) {
3422 struct text_object_list *object_list = extract_variable_text_internal(text);
3423 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3427 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3432 char buff_in[P_MAX_SIZE] = {0};
3433 iconv_converting = 0;
3436 for (i = 0; i < object_count; i++) {
3437 struct text_object *obj = &objs[i];
3439 #define OBJ(a) break; case OBJ_##a:
3441 switch (obj->type) {
3444 ERR("not implemented obj type %d",
3448 /* does anyone have decimals in acpi temperature? */
3450 snprintf(p, p_max_size, "%d", (int)
3451 get_acpi_temperature(obj->
3455 snprintf(p, 5, "%d ", (int)
3456 get_acpi_temperature(obj->
3461 /* does anyone have decimals in acpi temperature? */
3463 snprintf(p, p_max_size, "%d", (int)
3464 ((get_acpi_temperature(obj->
3466 i)+ 40) * 9.0 / 5 - 40));
3468 snprintf(p, 5, "%d ", (int)
3469 ((get_acpi_temperature(obj->
3471 i)+ 40) * 9.0 / 5 - 40));
3475 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3480 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3483 #if defined(__linux__)
3486 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3491 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3494 #endif /* __linux__ */
3498 get_freq_dynamic(p, 6, "%.0f ", 1 );
3500 get_freq_dynamic(p, p_max_size, "%.0f", 1 );
3505 get_freq_dynamic(p, 6, "%'.2f ", 1000);
3507 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3511 get_adt746x_cpu(p, p_max_size);
3514 get_adt746x_fan(p, p_max_size);
3517 get_acpi_fan(p, p_max_size);
3519 OBJ(acpiacadapter) {
3520 get_acpi_ac_adapter(p, p_max_size);
3523 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3526 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3528 OBJ(battery_percent) {
3529 snprintf(p, p_max_size, "%d",
3530 get_battery_perct(obj->data.s));
3533 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3536 human_readable(cur->buffers * 1024, p, 255);
3539 human_readable(cur->cached * 1024, p, 255);
3542 if (obj->data.cpu_index > info.cpu_count) {
3543 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3544 CRIT_ERR("attempting to use more CPUs then you have!");
3547 snprintf(p, p_max_size, "%*d", pad_percents,
3548 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3551 snprintf(p, 4, "%*d ",
3553 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3559 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3562 new_graph(p, obj->a,
3563 obj->b, obj->c, obj->d,
3564 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3568 new_fg(p, obj->data.l);
3600 #if defined(__linux__)
3602 snprintf(p, p_max_size, "%s", i8k.version);
3605 snprintf(p, p_max_size, "%s", i8k.bios);
3608 snprintf(p, p_max_size, "%s", i8k.serial);
3611 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3613 OBJ(i8k_cpu_tempf) {
3615 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3616 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3618 OBJ(i8k_left_fan_status) {
3619 int left_fan_status;
3620 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3621 if(left_fan_status == 0) {
3622 snprintf(p, p_max_size,"off");
3623 } if(left_fan_status == 1) {
3624 snprintf(p, p_max_size, "low");
3625 } if(left_fan_status == 2) {
3626 snprintf(p, p_max_size, "high");
3630 OBJ(i8k_right_fan_status) {
3631 int right_fan_status;
3632 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3633 if(right_fan_status == 0) {
3634 snprintf(p, p_max_size,"off");
3635 } if(right_fan_status == 1) {
3636 snprintf(p, p_max_size, "low");
3637 } if(right_fan_status == 2) {
3638 snprintf(p, p_max_size, "high");
3641 OBJ(i8k_left_fan_rpm) {
3642 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3644 OBJ(i8k_right_fan_rpm) {
3645 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3647 OBJ(i8k_ac_status) {
3649 sscanf(i8k.ac_status, "%d", &ac_status);
3650 if(ac_status == -1) {
3651 snprintf(p, p_max_size,"disabled (read i8k docs)");
3652 } if(ac_status == 0) {
3653 snprintf(p, p_max_size, "off");
3654 } if(ac_status == 1) {
3655 snprintf(p, p_max_size, "on");
3658 OBJ(i8k_buttons_status) {
3659 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3663 get_ibm_acpi_fan(p, p_max_size);
3666 get_ibm_acpi_temps();
3667 snprintf(p, p_max_size, "%d",
3668 ibm_acpi.temps[obj->data.sensor]);
3671 get_ibm_acpi_volume(p, p_max_size);
3673 OBJ(ibm_brightness) {
3674 get_ibm_acpi_brightness(p, p_max_size);
3677 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3679 #endif /* __linux__ */
3682 OBJ(obsd_sensors_temp) {
3683 obsd_sensors.device = sensor_device;
3684 update_obsd_sensors();
3685 snprintf(p, p_max_size, "%.1f",
3686 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
3689 OBJ(obsd_sensors_fan) {
3690 obsd_sensors.device = sensor_device;
3691 update_obsd_sensors();
3692 snprintf(p, p_max_size, "%d",
3693 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3696 OBJ(obsd_sensors_volt) {
3697 obsd_sensors.device = sensor_device;
3698 update_obsd_sensors();
3699 snprintf(p, p_max_size, "%.2f",
3700 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3704 get_obsd_vendor(p, p_max_size);
3708 get_obsd_product(p, p_max_size);
3710 #endif /* __OpenBSD__ */
3714 new_font(p, obj->data.s);
3717 void format_diskio(unsigned int diskio_value)
3720 if (diskio_value > 1024*1024) {
3721 snprintf(p, p_max_size, "%.1fGiB",
3722 (double)diskio_value/1024/1024);
3723 } else if (diskio_value > 1024) {
3724 snprintf(p, p_max_size, "%.1fMiB",
3725 (double)diskio_value/1024);
3726 } else if (diskio_value > 0) {
3727 snprintf(p, p_max_size, "%dKiB", diskio_value);
3729 snprintf(p, p_max_size, "%dB", diskio_value);
3732 if (diskio_value > 1024*1024) {
3733 snprintf(p, 12, "%.1fGiB ",
3734 (double)diskio_value/1024/1024);
3735 } else if (diskio_value > 1024) {
3736 snprintf(p, 12, "%.1fMiB ",
3737 (double)diskio_value/1024);
3738 } else if (diskio_value > 0) {
3739 snprintf(p, 12, "%dKiB ", diskio_value);
3741 snprintf(p, 12, "%dB ", diskio_value);
3746 format_diskio(diskio_value);
3749 format_diskio(diskio_write_value);
3752 format_diskio(diskio_read_value);
3755 new_graph(p, obj->a,
3756 obj->b, obj->c, obj->d,
3757 diskio_value, obj->e, 1);
3759 OBJ(diskiograph_read) {
3760 new_graph(p, obj->a,
3761 obj->b, obj->c, obj->d,
3762 diskio_read_value, obj->e, 1);
3764 OBJ(diskiograph_write) {
3765 new_graph(p, obj->a,
3766 obj->b, obj->c, obj->d,
3767 diskio_write_value, obj->e, 1);
3771 snprintf(p, p_max_size, "%d",
3772 (int) (obj->data.net->
3776 snprintf(p, 6, "%d ",
3777 (int) (obj->data.net->
3783 snprintf(p, p_max_size, "%.1f",
3785 recv_speed / 1024.0);
3787 snprintf(p, 8, "%.1f ",
3789 recv_speed / 1024.0);
3791 OBJ(downspeedgraph) {
3793 if (obj->data.net->recv_speed == 0)
3794 obj->data.net->recv_speed = 0.01;
3796 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3797 (obj->data.net->recv_speed /
3798 1024.0), obj->e, 1);
3802 i = obj->data.ifblock.pos - 1;
3812 snprintf(p, p_max_size, "%u.%u.%u.%u",
3813 obj->data.net->addr.
3815 obj->data.net->addr.
3817 obj->data.net->addr.
3819 obj->data.net->addr.
3825 snprintf(p, p_max_size, "%d",
3826 obj->data.net->linkstatus);
3829 snprintf(p, 5, "%4d ",
3830 obj->data.net->linkstatus);
3833 #if defined(IMLIB2) && defined(X11)
3838 Imlib_Image image, buffer;
3839 image = imlib_load_image(obj->data.s);
3840 imlib_context_set_image(image);
3843 w = imlib_image_get_width();
3844 h = imlib_image_get_height();
3845 buffer = imlib_create_image(w, h);
3846 imlib_context_set_display(display);
3847 imlib_context_set_drawable(window.drawable);
3848 imlib_context_set_colormap(DefaultColormap(display, screen));
3849 imlib_context_set_visual(DefaultVisual(display, screen));
3850 imlib_context_set_image(buffer);
3851 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
3852 imlib_render_image_on_drawable(text_start_x, text_start_y);
3854 imlib_context_set_image(image);
3861 FILE *fp = popen(obj->data.s, "r");
3862 int length = fread(p, 1, p_max_size, fp);
3865 /*output[length] = '\0';
3866 if (length > 0 && output[length - 1] == '\n') {
3867 output[length - 1] = '\0';
3870 if (length > 0 && p[length - 1] == '\n') {
3871 p[length - 1] = '\0';
3874 //parse_conky_vars(output, p, cur);
3878 FILE *fp = popen(obj->data.s, "r");
3879 int n2 = fread(p, 1, p_max_size, fp);
3883 if (n2 && p[n2 - 1] == '\n')
3892 if (sscanf(p, "%lf", &barnum) == 0) {
3893 ERR("reading execbar value failed (perhaps it's not the correct format?)");
3895 if (barnum > 100 || barnum < 0) {
3896 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
3898 barnum = barnum / 100.0;
3899 new_bar(p, 0, 4, (int) (barnum * 255.0));
3905 FILE *fp = popen(obj->data.s, "r");
3906 int n2 = fread(p, 1, p_max_size, fp);
3910 if (n2 && p[n2 - 1] == '\n')
3919 if (sscanf(p, "%lf", &barnum) == 0) {
3920 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
3922 if (barnum > 100 || barnum < 0) {
3923 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
3925 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
3930 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3931 new_bar(p, 0, 4, (int) obj->f);
3934 FILE *fp = popen(obj->data.execi.cmd, "r");
3935 int n2 = fread(p, 1, p_max_size, fp);
3938 if (n2 && p[n2 - 1] == '\n')
3947 if (sscanf(p, "%f", &barnum) == 0) {
3948 ERR("reading execibar value failed (perhaps it's not the correct format?)");
3950 if (barnum > 100 || barnum < 0) {
3951 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
3953 obj->f = 255 * barnum / 100.0;
3954 new_bar(p, 0, 4, (int) obj->f);
3956 obj->data.execi.last_update =
3957 current_update_time;
3961 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3962 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
3965 FILE *fp = popen(obj->data.execi.cmd, "r");
3966 int n2 = fread(p, 1, p_max_size, fp);
3969 if (n2 && p[n2 - 1] == '\n')
3978 if (sscanf(p, "%f", &barnum) == 0) {
3979 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
3981 if (barnum > 100 || barnum < 0) {
3982 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
3985 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
3987 obj->data.execi.last_update = current_update_time;
3993 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
3994 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
3996 char *output = obj->data.execi.buffer;
3997 FILE *fp = popen(obj->data.execi.cmd, "r");
3998 //int length = fread(output, 1, text_buffer_size, fp);
3999 int length = fread(output, 1, text_buffer_size, fp);
4002 output[length] = '\0';
4003 if (length > 0 && output[length - 1] == '\n') {
4004 output[length - 1] = '\0';
4006 obj->data.execi.last_update = current_update_time;
4007 snprintf(p, p_max_size, "%s", output);
4009 //parse_conky_vars(output, p, cur);
4012 if (!obj->data.texeci.p_timed_thread)
4014 obj->data.texeci.p_timed_thread=
4015 timed_thread_create ((void*)threaded_exec, (void*) obj,
4016 obj->data.texeci.interval * 1000000);
4017 if (!obj->data.texeci.p_timed_thread)
4018 ERR("Error starting texeci thread");
4019 timed_thread_register (obj->data.texeci.p_timed_thread,
4020 &obj->data.texeci.p_timed_thread);
4022 timed_thread_lock (obj->data.texeci.p_timed_thread);
4023 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4024 timed_thread_unlock (obj->data.texeci.p_timed_thread);
4026 #endif /* HAVE_POPEN */
4028 if (obj->global_mode && info.mail) { // this means we use info
4029 if (!info.mail->p_timed_thread)
4031 info.mail->p_timed_thread =
4032 timed_thread_create ((void*)imap_thread,
4034 info.mail->interval * 1000000);
4035 if (!info.mail->p_timed_thread)
4036 ERR("Error starting imap thread");
4037 timed_thread_register (info.mail->p_timed_thread,
4038 &info.mail->p_timed_thread);
4040 timed_thread_lock (info.mail->p_timed_thread);
4041 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4042 timed_thread_unlock (info.mail->p_timed_thread);
4043 } else if (obj->data.mail) { // this means we use obj
4044 if (!obj->data.mail->p_timed_thread)
4046 obj->data.mail->p_timed_thread =
4047 timed_thread_create ((void*)imap_thread,
4048 (void*)obj->data.mail,
4049 obj->data.mail->interval * 1000000);
4050 if (!obj->data.mail->p_timed_thread)
4051 ERR("Error starting imap thread");
4052 timed_thread_register (obj->data.mail->p_timed_thread,
4053 &obj->data.mail->p_timed_thread);
4055 timed_thread_lock (obj->data.mail->p_timed_thread);
4056 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4057 timed_thread_unlock (obj->data.mail->p_timed_thread);
4058 } else if (!obj->a) { // something is wrong, warn once then stop
4059 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4063 OBJ(imap_messages) {
4064 if (obj->global_mode && info.mail) { // this means we use info
4065 if (!info.mail->p_timed_thread)
4067 info.mail->p_timed_thread =
4068 timed_thread_create ((void*)imap_thread,
4070 info.mail->interval * 1000000);
4071 if (!info.mail->p_timed_thread)
4072 ERR("Error starting imap thread");
4073 timed_thread_register (info.mail->p_timed_thread,
4074 &info.mail->p_timed_thread);
4076 timed_thread_lock (info.mail->p_timed_thread);
4077 snprintf(p, p_max_size, "%lu", info.mail->messages);
4078 timed_thread_unlock (info.mail->p_timed_thread);
4079 } else if (obj->data.mail) { // this means we use obj
4080 if (!obj->data.mail->p_timed_thread)
4082 obj->data.mail->p_timed_thread =
4083 timed_thread_create ((void*)imap_thread,
4084 (void*)obj->data.mail,
4085 obj->data.mail->interval * 1000000);
4086 if (!obj->data.mail->p_timed_thread)
4087 ERR("Error starting imap thread");
4088 timed_thread_register (obj->data.mail->p_timed_thread,
4089 &obj->data.mail->p_timed_thread);
4091 timed_thread_lock (obj->data.mail->p_timed_thread);
4092 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4093 timed_thread_lock (obj->data.mail->p_timed_thread);
4094 } else if (!obj->a) { // something is wrong, warn once then stop
4095 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4100 if (obj->global_mode && info.mail) { // this means we use info
4101 if (!info.mail->p_timed_thread)
4103 info.mail->p_timed_thread =
4104 timed_thread_create ((void*)pop3_thread,
4106 info.mail->interval * 1000000);
4107 if (!info.mail->p_timed_thread)
4108 ERR("Error starting pop3 thread");
4109 timed_thread_register (info.mail->p_timed_thread,
4110 &info.mail->p_timed_thread);
4112 timed_thread_lock (info.mail->p_timed_thread);
4113 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4114 timed_thread_unlock (info.mail->p_timed_thread);
4115 } else if (obj->data.mail) { // this means we use obj
4116 if (!obj->data.mail->p_timed_thread)
4118 obj->data.mail->p_timed_thread =
4119 timed_thread_create ((void*)pop3_thread,
4120 (void*)obj->data.mail,
4121 obj->data.mail->interval * 1000000);
4122 if (!obj->data.mail->p_timed_thread)
4123 ERR("Error starting pop3 thread");
4124 timed_thread_register (obj->data.mail->p_timed_thread,
4125 &obj->data.mail->p_timed_thread);
4127 timed_thread_lock (obj->data.mail->p_timed_thread);
4128 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4129 timed_thread_unlock (obj->data.mail->p_timed_thread);
4130 } else if (!obj->a) { // something is wrong, warn once then stop
4131 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4136 if (obj->global_mode && info.mail) { // this means we use info
4137 if (!info.mail->p_timed_thread)
4139 info.mail->p_timed_thread =
4140 timed_thread_create ((void*)pop3_thread,
4142 info.mail->interval * 1000000);
4143 if (!info.mail->p_timed_thread)
4144 ERR("Error starting pop3 thread");
4145 timed_thread_register (info.mail->p_timed_thread,
4146 &info.mail->p_timed_thread);
4148 timed_thread_lock (info.mail->p_timed_thread);
4149 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4150 timed_thread_unlock (info.mail->p_timed_thread);
4151 } else if (obj->data.mail) { // this means we use obj
4152 if (!obj->data.mail->p_timed_thread)
4154 obj->data.mail->p_timed_thread =
4155 timed_thread_create ((void*)pop3_thread,
4156 (void*)obj->data.mail,
4157 obj->data.mail->interval * 1000000);
4158 if (!obj->data.mail->p_timed_thread)
4159 ERR("Error starting pop3 thread");
4160 timed_thread_register (obj->data.mail->p_timed_thread,
4161 &obj->data.mail->p_timed_thread);
4163 timed_thread_lock (obj->data.mail->p_timed_thread);
4164 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4165 timed_thread_unlock (obj->data.mail->p_timed_thread);
4166 } else if (!obj->a) { // something is wrong, warn once then stop
4167 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4172 if (obj->data.fs != NULL) {
4173 if (obj->data.fs->size == 0)
4192 if (obj->data.fs != NULL)
4193 human_readable(obj->data.fs->avail,
4197 if (obj->data.fs != NULL) {
4198 if (obj->data.fs->size)
4199 snprintf(p, p_max_size, "%*d",
4208 snprintf(p, p_max_size, "0");
4212 if (obj->data.fs != NULL)
4213 human_readable(obj->data.fs->size,
4217 if (obj->data.fs != NULL)
4218 human_readable(obj->data.fs->size -
4219 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
4223 if (obj->data.fs != NULL) {
4224 if (obj->data.fs->size == 0)
4242 if (obj->data.fs != NULL) {
4243 if (obj->data.fs->size)
4244 snprintf(p, 4, "%d",
4254 snprintf(p, p_max_size, "0");
4258 float *v = info.loadavg;
4260 if (obj->data.loadavg[2])
4261 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4262 v[obj->data.loadavg[0] -
4264 v[obj->data.loadavg[1] -
4266 v[obj->data.loadavg[2] -
4268 else if (obj->data.loadavg[1])
4269 snprintf(p, p_max_size, "%.2f %.2f",
4270 v[obj->data.loadavg[0] -
4272 v[obj->data.loadavg[1] -
4274 else if (obj->data.loadavg[0])
4275 snprintf(p, p_max_size, "%.2f",
4276 v[obj->data.loadavg[0] -
4280 new_goto(p, obj->data.i);
4283 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4286 new_hr(p, obj->data.i);
4292 char *titles = malloc(1024*sizeof(char *));
4294 memset(titles, 0, sizeof(titles));
4295 list = get_rss_info(obj->data.rss.uri, obj->data.rss.count);
4297 for (walk = g_list_first(list); walk != NULL; walk = g_list_next(walk)) {
4298 snprintf(titles, 1023, "%s%s\n", titles, (char *)walk->data);
4302 /* we don't need last \n */
4303 titles[strlen(titles)-2] = '\0';
4305 snprintf(p, p_max_size, "%s", titles);
4317 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4318 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4320 snprintf(p, p_max_size, "N/A");
4321 } else if (unit == '*') {
4322 snprintf(p, p_max_size, "%s", temp);
4324 snprintf(p, p_max_size, "%s°%c", temp, unit);
4329 new_offset(p, obj->data.i);
4332 new_voffset(p, obj->data.i);
4337 r = get_i2c_info(&obj->data.i2c.fd,
4339 obj->data.i2c.devtype,
4340 obj->data.i2c.type);
4342 if (r >= 100.0 || r == 0)
4343 snprintf(p, p_max_size, "%d", (int) r);
4345 snprintf(p, p_max_size, "%.1f", r);
4348 new_alignr(p, obj->data.i);
4351 new_alignc(p, obj->data.i);
4354 struct information *my_info =
4355 malloc(sizeof(struct information));
4356 memcpy(my_info, cur, sizeof(struct information));
4357 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4358 if (strlen(p) != 0) {
4359 i = obj->data.ifblock.pos;
4369 if ((obj->data.ifblock.s)
4370 && (stat(obj->data.ifblock.s, &tmp) ==
4372 i = obj->data.ifblock.pos;
4375 if (obj->data.ifblock.str) {
4376 if (!check_contains(obj->data.ifblock.s,
4377 obj->data.ifblock.str)) {
4378 i = obj->data.ifblock.pos;
4387 if ((obj->data.ifblock.s)
4388 && (!check_mount(obj->data.ifblock.s))) {
4389 i = obj->data.ifblock.pos;
4396 if ((obj->data.ifblock.s)
4397 && system(obj->data.ifblock.s)) {
4398 i = obj->data.ifblock.pos;
4405 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4408 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4413 human_readable(cur->mem * 1024, p, 255);
4416 human_readable(cur->memmax * 1024, p, 255);
4421 snprintf(p, p_max_size, "%*Lu",
4426 snprintf(p, 4, "%*Lu ",
4433 new_bar(p, obj->data.pair.a,
4435 cur->memmax ? (cur->mem * 255) /
4440 new_graph(p, obj->a,
4441 obj->b, obj->c, obj->d,
4442 cur->memmax ? (cur->mem * 100.0) /
4443 (cur->memmax) : 0.0, 100, 1);
4447 snprintf(p, p_max_size, "%d",
4448 mixer_get_avg(obj->data.l));
4451 snprintf(p, p_max_size, "%d",
4452 mixer_get_left(obj->data.l));
4455 snprintf(p, p_max_size, "%d",
4456 mixer_get_right(obj->data.l));
4459 new_bar(p, obj->data.mixerbar.w,
4460 obj->data.mixerbar.h,
4461 mixer_get_avg(obj->data.mixerbar.
4465 new_bar(p, obj->data.mixerbar.w,
4466 obj->data.mixerbar.h,
4467 mixer_get_left(obj->data.mixerbar.
4471 new_bar(p, obj->data.mixerbar.w,
4472 obj->data.mixerbar.h,
4473 mixer_get_right(obj->data.mixerbar.
4479 snprintf(p, p_max_size, "%d", cur->mail_count);
4482 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4483 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4486 snprintf(p, p_max_size, "%d", cur->new_mail_count);
4490 snprintf(p, p_max_size, "%s",
4491 cur->uname_s.nodename);
4494 new_outline(p, obj->data.l);
4498 snprintf(p, p_max_size, "%hu", cur->procs);
4500 snprintf(p, 5, "%hu ",
4503 OBJ(running_processes) {
4505 snprintf(p, p_max_size, "%hu",
4508 snprintf(p, 3, "%hu ",
4512 snprintf(p, p_max_size, "%s", obj->data.s);
4515 new_bg(p, obj->data.l);
4518 new_stippled_hr(p, obj->data.pair.a,
4522 human_readable(cur->swap * 1024, p, 255);
4525 human_readable(cur->swapmax * 1024, p,
4529 if (cur->swapmax == 0) {
4530 strncpy(p, "No swap", 255);
4533 snprintf(p, 255, "%*Lu",
4539 snprintf(p, 4, "%*Lu ",
4547 new_bar(p, obj->data.pair.a,
4549 cur->swapmax ? (cur->swap * 255) /
4550 (cur->swapmax) : 0);
4553 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4556 time_t t = time(NULL);
4557 struct tm *tm = localtime(&t);
4558 setlocale(LC_TIME, "");
4559 strftime(p, p_max_size, obj->data.s, tm);
4562 time_t t = time(NULL);
4563 struct tm *tm = gmtime(&t);
4564 strftime(p, p_max_size, obj->data.s, tm);
4568 if (obj->data.tztime.tz) {
4569 oldTZ = getenv("TZ");
4570 setenv("TZ", obj->data.tztime.tz, 1);
4573 time_t t = time(NULL);
4574 struct tm *tm = localtime(&t);
4575 setlocale(LC_TIME, "");
4576 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4578 setenv("TZ", oldTZ, 1);
4583 // Needless to free oldTZ since getenv gives ptr to static data
4586 human_readable(obj->data.net->recv, p,
4590 human_readable(obj->data.net->trans, p,
4594 snprintf(p, p_max_size, "%d", total_updates);
4598 snprintf(p, p_max_size, "%d",
4599 (int) (obj->data.net->
4603 snprintf(p, 5, "%d ",
4604 (int) (obj->data.net->
4610 snprintf(p, p_max_size, "%.1f",
4612 trans_speed / 1024.0);
4614 snprintf(p, 8, "%.1f ",
4616 trans_speed / 1024.0);
4620 if (obj->data.net->trans_speed == 0)
4621 obj->data.net->trans_speed = 0.01;
4623 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4624 (obj->data.net->trans_speed /
4625 1024.0), obj->e, 1);
4628 format_seconds_short(p, p_max_size,
4632 format_seconds(p, p_max_size, (int) cur->uptime);
4635 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4638 msg = get_apm_adapter();
4639 snprintf(p, p_max_size, "%s", msg);
4642 OBJ(apm_battery_life) {
4644 msg = get_apm_battery_life();
4645 snprintf(p, p_max_size, "%s", msg);
4648 OBJ(apm_battery_time) {
4650 msg = get_apm_battery_time();
4651 snprintf(p, p_max_size, "%s", msg);
4654 #endif /* __FreeBSD__ __OpenBSD__ */
4658 snprintf(p, p_max_size, "%s", cur->mpd.title);
4661 snprintf(p, p_max_size, "%s", cur->mpd.artist);
4664 snprintf(p, p_max_size, "%s", cur->mpd.album);
4667 snprintf(p, p_max_size, "%s", cur->mpd.random);
4670 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
4673 snprintf(p, p_max_size, "%s", cur->mpd.track);
4676 snprintf(p, p_max_size, "%s", cur->mpd.name);
4679 snprintf(p, p_max_size, "%s", cur->mpd.file);
4682 snprintf(p, p_max_size, "%i", cur->mpd.volume);
4685 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
4688 snprintf(p, p_max_size, "%s", cur->mpd.status);
4691 int days = 0, hours = 0, minutes =
4693 int tmp = cur->mpd.elapsed;
4694 while (tmp >= 86400) {
4698 while (tmp >= 3600) {
4708 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
4709 days, hours, minutes,
4712 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4715 snprintf(p, p_max_size, "%i:%02i", minutes,
4719 int days = 0, hours = 0, minutes =
4721 int tmp = cur->mpd.length;
4722 while (tmp >= 86400) {
4726 while (tmp >= 3600) {
4736 snprintf(p, p_max_size,
4737 "%i days %i:%02i:%02i",
4738 days, hours, minutes,
4741 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4744 snprintf(p, p_max_size, "%i:%02i", minutes,
4748 snprintf(p, p_max_size, "%2.0f",
4749 cur->mpd.progress * 100);
4752 new_bar(p, obj->data.pair.a,
4754 (int) (cur->mpd.progress *
4758 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.title) < 2) {
4759 snprintf(p, p_max_size, "%s", cur->mpd.file);
4761 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
4767 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4770 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4773 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4776 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4778 OBJ(xmms2_comment) {
4779 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4781 OBJ(xmms2_decoder) {
4782 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
4784 OBJ(xmms2_transport) {
4785 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
4788 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4791 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4794 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4796 OBJ(xmms2_tracknr) {
4797 if (cur->xmms2.tracknr != -1)
4798 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4800 OBJ(xmms2_bitrate) {
4801 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4804 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4807 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4809 OBJ(xmms2_elapsed) {
4810 int tmp = cur->xmms2.elapsed;
4811 snprintf(p, p_max_size, "%02d:%02d",
4812 tmp / 60000, (tmp / 1000) % 60);
4814 OBJ(xmms2_duration) {
4815 int tmp = cur->xmms2.duration;
4816 snprintf(p, p_max_size, "%02d:%02d",
4817 tmp / 60000, (tmp / 1000) % 60);
4819 OBJ(xmms2_percent) {
4820 snprintf(p, p_max_size, "%2.0f",
4821 cur->xmms2.progress * 100);
4824 new_bar(p, obj->data.pair.a,
4826 (int) (cur->xmms2.progress *
4830 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
4831 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4833 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
4838 OBJ(audacious_status) {
4839 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
4841 OBJ(audacious_title) {
4842 snprintf(p, cur->audacious.max_title_len > 0 ?
4843 cur->audacious.max_title_len : p_max_size, "%s",
4844 cur->audacious.items[AUDACIOUS_TITLE]);
4846 OBJ(audacious_length) {
4847 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
4849 OBJ(audacious_length_seconds) {
4850 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4852 OBJ(audacious_position) {
4853 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
4855 OBJ(audacious_position_seconds) {
4856 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
4858 OBJ(audacious_bitrate) {
4859 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
4861 OBJ(audacious_frequency) {
4862 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
4864 OBJ(audacious_channels) {
4865 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
4867 OBJ(audacious_filename) {
4868 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
4870 OBJ(audacious_playlist_length) {
4871 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
4873 OBJ(audacious_playlist_position) {
4874 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
4876 OBJ(audacious_bar) {
4878 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
4879 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4880 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
4885 snprintf(p, p_max_size, "%s", cur->bmpx.title);
4888 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
4891 snprintf(p, p_max_size, "%s", cur->bmpx.album);
4894 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
4897 snprintf(p, p_max_size, "%i", cur->bmpx.track);
4900 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
4904 if (obj->data.top.type == TOP_NAME
4905 && obj->data.top.num >= 0
4906 && obj->data.top.num < 10) {
4907 // if we limit the buffer and add a bunch of space after, it stops the thing from
4908 // moving other shit around, which is really fucking annoying
4909 snprintf(p, 17, "%s ", cur->cpu[obj->data.top.num]->name);
4910 } else if (obj->data.top.type == TOP_CPU
4911 && obj->data.top.num >= 0
4912 && obj->data.top.num < 10) {
4913 snprintf(p, 7, "%3.2f ",
4914 cur->cpu[obj->data.top.
4916 } else if (obj->data.top.type == TOP_PID
4917 && obj->data.top.num >= 0
4918 && obj->data.top.num < 10) {
4919 snprintf(p, 8, "%i ",
4920 cur->cpu[obj->data.top.
4922 } else if (obj->data.top.type == TOP_MEM
4923 && obj->data.top.num >= 0
4924 && obj->data.top.num < 10) {
4925 snprintf(p, 7, "%3.2f ",
4926 cur->cpu[obj->data.top.
4931 if (obj->data.top.type == TOP_NAME
4932 && obj->data.top.num >= 0
4933 && obj->data.top.num < 10) {
4934 // if we limit the buffer and add a bunch of space after, it stops the thing from
4935 // moving other shit around, which is really fucking annoying
4938 cur->memu[obj->data.top.
4940 } else if (obj->data.top.type == TOP_CPU
4941 && obj->data.top.num >= 0
4942 && obj->data.top.num < 10) {
4943 snprintf(p, 7, "%3.2f ",
4944 cur->memu[obj->data.top.
4946 } else if (obj->data.top.type == TOP_PID
4947 && obj->data.top.num >= 0
4948 && obj->data.top.num < 10) {
4949 snprintf(p, 8, "%i ",
4950 cur->memu[obj->data.top.
4952 } else if (obj->data.top.type == TOP_MEM
4953 && obj->data.top.num >= 0
4954 && obj->data.top.num < 10) {
4955 snprintf(p, 7, "%3.2f ",
4956 cur->memu[obj->data.top.
4963 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4964 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4966 obj->data.tail.last_update = current_update_time;
4970 fp = fopen(obj->data.tail.logfile, "rt");
4972 /* Send one message, but do not consistently spam on
4973 * missing logfiles. */
4974 if(obj->data.tail.readlines != 0) {
4975 ERR("tail logfile failed to open");
4976 strcpy(obj->data.tail.buffer, "Logfile Missing");
4978 obj->data.tail.readlines = 0;
4979 snprintf(p, p_max_size, "Logfile Missing");
4982 obj->data.tail.readlines = 0;
4983 /* -1 instead of 0 to avoid counting a trailing newline */
4984 fseek(fp, -1, SEEK_END);
4985 bsize = ftell(fp) + 1;
4986 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
4987 nl = rev_fcharfind(fp, '\n', iter);
4991 obj->data.tail.readlines = iter;
4992 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
4993 fseek(fp, 0, SEEK_SET);
4996 fseek(fp, nl+1, SEEK_SET);
4999 /* Make sure bsize is at least 1 byte smaller than
5000 * the buffer max size. */
5001 if(bsize > (long)((text_buffer_size*20) - 1)) {
5002 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
5003 bsize = text_buffer_size*20 - 1;
5005 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5008 /* Clean up trailing newline, make sure the buffer
5009 * is null terminated. */
5010 if(obj->data.tail.buffer[bsize-1] == '\n')
5011 obj->data.tail.buffer[bsize-1] = '\0';
5013 obj->data.tail.buffer[bsize] = '\0';
5014 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5017 strcpy(obj->data.tail.buffer, "Logfile Empty");
5018 snprintf(p, p_max_size, "Logfile Empty");
5021 } /* if cur_upd_time >= */
5023 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5027 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5028 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5030 obj->data.tail.last_update = current_update_time;
5034 fp = fopen(obj->data.tail.logfile, "rt");
5036 /* Send one message, but do not consistently spam on
5037 * missing logfiles. */
5038 if(obj->data.tail.readlines != 0) {
5039 ERR("head logfile failed to open");
5040 strcpy(obj->data.tail.buffer, "Logfile Missing");
5042 obj->data.tail.readlines = 0;
5043 snprintf(p, p_max_size, "Logfile Missing");
5045 obj->data.tail.readlines = 0;
5046 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5047 nl = fwd_fcharfind(fp, '\n', iter);
5051 obj->data.tail.readlines = iter;
5052 /* Make sure nl is at least 1 byte smaller than
5053 * the buffer max size. */
5054 if(nl > (long)((text_buffer_size*20) - 1)) {
5055 nl = text_buffer_size*20 - 1;
5057 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5060 /* Clean up trailing newline, make sure the buffer
5061 * is null terminated. */
5062 if (obj->data.tail.buffer[nl-1] == '\n') {
5063 obj->data.tail.buffer[nl-1] = '\0';
5066 obj->data.tail.buffer[nl] = '\0';
5068 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5071 strcpy(obj->data.tail.buffer, "Logfile Empty");
5072 snprintf(p, p_max_size, "Logfile Empty");
5074 } /* if fp == null */
5075 } /* cur_upd_time >= */
5077 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5080 #ifdef TCP_PORT_MONITOR
5083 /* grab a pointer to this port monitor */
5084 tcp_port_monitor_t * p_monitor =
5085 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
5086 obj->data.tcp_port_monitor.port_range_begin,
5087 obj->data.tcp_port_monitor.port_range_end );
5089 snprintf(p, p_max_size, "monitor not found");
5093 /* now grab the text of interest */
5094 if ( peek_tcp_port_monitor( p_monitor,
5095 obj->data.tcp_port_monitor.item,
5096 obj->data.tcp_port_monitor.connection_index,
5097 p, p_max_size ) != 0 )
5099 snprintf(p, p_max_size, "monitor peek error");
5108 iconv_converting = 1;
5109 iconv_selected = obj->a;
5114 iconv_converting = 0;
5120 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5122 OBJ(entropy_poolsize)
5124 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5128 double entropy_perc;
5129 entropy_perc = (double)cur->entropy.entropy_avail /
5130 (double)cur->entropy.poolsize;
5131 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5139 unsigned int a = strlen(p);
5142 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5144 size_t dummy1, dummy2;
5145 char *ptr = buff_in;
5148 dummy1 = dummy2 = a;
5150 strncpy(buff_in, p, P_MAX_SIZE);
5152 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5153 while (dummy1 > 0) {
5154 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5156 ERR("Iconv codeset conversion failed");
5161 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5172 double current_update_time, last_update_time;
5174 static void generate_text()
5176 struct information *cur = &info;
5184 current_update_time = get_time();
5187 /* fix diskio rates to b/s (use update_interval */
5188 diskio_read_value = diskio_read_value / update_interval;
5189 diskio_write_value = diskio_write_value / update_interval;
5190 diskio_value = diskio_value / update_interval;
5193 /* add things to the buffer */
5199 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5201 if (stuff_in_upper_case) {
5212 last_update_time = current_update_time;
5219 static void set_font()
5223 if (window.xftdraw != NULL) {
5224 XftDrawDestroy(window.xftdraw);
5226 window.xftdraw = XftDrawCreate(display, window.drawable,
5227 DefaultVisual(display,
5229 DefaultColormap(display,
5234 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5240 static inline int get_string_width(const char *s)
5243 return *s ? calc_text_width(s, strlen(s)) : 0;
5249 static inline int get_string_width_special(char *s)
5262 if (*p == SPECIAL_CHAR) {
5263 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5264 for (i = 0; i < strlen(p); i++) {
5265 *(p + i) = *(p + i + 1);
5267 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5268 width += specials[special_index+index].width;
5275 if (strlen(final) > 1) {
5276 width += calc_text_width(final, strlen(final));
5286 static void text_size_updater(char *s);
5288 int last_font_height;
5289 static void update_text_area()
5293 /* update text size if it isn't fixed */
5298 text_width = minimum_width;
5301 last_font_height = font_height();
5302 for_each_line(text_buffer, text_size_updater);
5304 if (text_height < minimum_height)
5305 text_height = minimum_height;
5306 if (text_width > maximum_width && maximum_width > 0)
5307 text_width = maximum_width;
5310 /* get text position on workarea */
5311 switch (text_alignment) {
5318 x = workarea[2] - text_width - gap_x;
5325 y = workarea[3] - text_height - gap_y;
5329 x = workarea[2] - text_width - gap_x;
5330 y = workarea[3] - text_height - gap_y;
5334 case NONE: // Let the WM manage the window
5345 if (own_window && !fixed_pos) {
5348 text_start_x = border_margin + 1;
5349 text_start_y = border_margin + 1;
5350 window.x = x - border_margin - 1;
5351 window.y = y - border_margin - 1;
5355 /* If window size doesn't match to workarea's size, then window
5356 * probably includes panels (gnome).
5357 * Blah, doesn't work on KDE. */
5358 if (workarea[2] != window.width
5359 || workarea[3] != window.height) {
5373 static int cur_x, cur_y; /* current x and y for drawing */
5374 static int draw_mode; /* FG, BG or OUTLINE */
5375 static long current_color;
5378 static void text_size_updater(char *s)
5382 /* get string widths and skip specials */
5385 if (*p == SPECIAL_CHAR) {
5387 w += get_string_width(s);
5390 if (specials[special_index].type == BAR
5391 || specials[special_index].type == GRAPH) {
5392 w += specials[special_index].width;
5393 if (specials[special_index].height > last_font_height) {
5394 last_font_height = specials[special_index].height;
5395 last_font_height += font_ascent();
5397 } else if (specials[special_index].type == OFFSET) {
5398 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
5399 } else if (specials[special_index].type == VOFFSET) {
5400 last_font_height += specials[special_index].arg;
5401 } else if (specials[special_index].type == GOTO) {
5402 if (specials[special_index].arg >= 0)
5403 w += (int)specials[special_index].arg - cur_x;
5404 } else if (specials[special_index].type == TAB) {
5405 int start = specials[special_index].arg;
5406 int step = specials[special_index].width;
5407 if (!step || step < 0)
5409 w += step - (cur_x - text_start_x - start) % step;
5410 } else if (specials[special_index].type == FONT) {
5411 selected_font = specials[special_index].font_added;
5412 if (font_height() > last_font_height) {
5413 last_font_height = font_height();
5422 w += get_string_width(s);
5423 if (w > text_width) {
5426 if (text_width > maximum_width && maximum_width) {
5427 text_width = maximum_width;
5430 text_height += last_font_height;
5431 last_font_height = font_height();
5435 static inline void set_foreground_color(long c)
5438 XSetForeground(display, window.gc, c);
5442 static void draw_string(const char *s)
5446 int i, i2, pos, width_of_s;
5449 width_of_s = get_string_width(s);
5450 if (out_to_console) {
5452 fflush(stdout); /* output immediately, don't buffer */
5454 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5455 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5456 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5460 snprintf(space, 2, " ");
5462 max = ((text_width - width_of_s) / get_string_width(space));
5465 * This code looks for tabs in the text and coverts them to spaces.
5466 * The trick is getting the correct number of spaces,
5467 * and not going over the window's size without forcing
5468 * the window larger.
5470 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5471 if (tmpstring1[i] == '\t') // 9 is ascii tab
5475 i2 < (8 - (1 + pos) % 8) && added <= max;
5478 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5479 fprintf(stderr,"buffer overrun detected\n");
5481 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5486 if (tmpstring1[i] != 9) {
5488 if ( pos > TEXT_BUFFER_SIZE-1 )
5489 fprintf(stderr,"buffer overrun detected\n");
5491 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5497 if (text_width == maximum_width) {
5498 /* this means the text is probably pushing the limit, so we'll chop it */
5499 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5500 tmpstring2[strlen(tmpstring2)-1] = '\0';
5510 c.pixel = current_color;
5511 XQueryColor(display, DefaultColormap(display, screen), &c);
5514 c2.color.red = c.red;
5515 c2.color.green = c.green;
5516 c2.color.blue = c.blue;
5517 c2.color.alpha = fonts[selected_font].font_alpha;
5519 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5520 cur_x, cur_y, (XftChar8 *) s,
5523 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5524 cur_x, cur_y, (XftChar8 *) s,
5530 XDrawString(display, window.drawable, window.gc,
5531 cur_x, cur_y, s, strlen(s));
5533 cur_x += width_of_s;
5535 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5538 long redmask, greenmask, bluemask;
5540 void set_up_gradient()
5543 colour_depth = DisplayPlanes(display, screen);
5547 if (colour_depth != 24 && colour_depth != 16) {
5548 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5554 for(i = (colour_depth / 3)-1; i>=0; i--) {
5556 greenmask |= 1 << i;
5559 if (colour_depth%3 == 1) {
5560 greenmask |= 1 << (colour_depth / 3);
5562 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5563 greenmask = greenmask << (colour_depth / 3);
5566 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 */
5568 int red1, green1, blue1; // first colour
5569 int red2, green2, blue2; // second colour
5570 int red3 = 0, green3 = 0, blue3 = 0; // difference
5571 short redshift = (2*colour_depth / 3 + colour_depth%3);
5572 short greenshift = (colour_depth / 3);
5573 red1 = (first_colour & redmask) >> redshift;
5574 green1 = (first_colour & greenmask) >> greenshift;
5575 blue1 = first_colour & bluemask;
5576 red2 = (last_colour & redmask) >> redshift;
5577 green2 = (last_colour & greenmask) >> greenshift;
5578 blue2 = last_colour & bluemask;
5585 if (green1 > green2) {
5588 if (green1 < green2) {
5591 if (blue1 > blue2) {
5594 if (blue1 < blue2) {
5609 if (red1 > bluemask) {
5612 if (green1 > bluemask) {
5615 if (blue1 > bluemask) {
5618 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
5622 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
5623 if (colour_depth == 0) {
5626 int red1, green1, blue1; // first colour
5627 int red2, green2, blue2; // second colour
5628 long redshift = (2*colour_depth / 3 + colour_depth%3);
5629 long greenshift = (colour_depth / 3);
5630 int red3 = 0, green3 = 0, blue3 = 0; // difference
5631 red1 = (first_colour & redmask) >> redshift;
5632 green1 = (first_colour & greenmask) >> greenshift;
5633 blue1 = first_colour & bluemask;
5634 red2 = (last_colour & redmask) >> redshift;
5635 green2 = (last_colour & greenmask) >> greenshift;
5636 blue2 = last_colour & bluemask;
5637 red3 = abs(red1 - red2);
5638 green3 = abs(green1 - green2);
5639 blue3 = abs(blue1 - blue2);
5648 static void draw_line(char *s)
5652 cur_x = text_start_x;
5653 cur_y += font_ascent();
5655 short font_h = font_height();
5657 /* find specials and draw stuff */
5660 if (*p == SPECIAL_CHAR) {
5663 /* draw string before special */
5670 switch (specials[special_index].type) {
5671 case HORIZONTAL_LINE:
5674 specials[special_index].height;
5675 int mid = font_ascent() / 2;
5676 w = text_start_x + text_width -
5679 XSetLineAttributes(display,
5684 XDrawLine(display, window.drawable,
5695 specials[special_index].height;
5697 specials[special_index].arg;
5698 int mid = font_ascent() / 2;
5699 char ss[2] = { s, s };
5700 w = text_start_x + text_width -
5703 XSetLineAttributes(display,
5708 XSetDashes(display, window.gc, 0,
5710 XDrawLine(display, window.drawable,
5720 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5724 specials[special_index].height;
5726 specials[special_index].arg;
5727 int by = cur_y - (font_ascent() / 2) - 1;
5728 if (h < font_height()) {
5731 w = specials[special_index].width;
5734 text_width - cur_x - 1;
5738 XSetLineAttributes(display,
5744 XDrawRectangle(display,
5748 XFillRectangle(display,
5752 w * bar_usage / 255,
5754 if (specials[special_index].
5756 && specials[special_index].
5760 [special_index].height;
5767 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5771 specials[special_index].height;
5772 unsigned long last_colour = current_color;
5773 int by = cur_y - (font_ascent()/2) - 1;
5774 if (h < font_height()) {
5777 w = specials[special_index].width;
5779 w = text_start_x + text_width - cur_x - 1;
5782 if (draw_graph_borders) {
5783 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
5784 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
5786 XSetLineAttributes(display,
5793 int gradient_size = 0;
5794 float gradient_factor = 0;
5795 float gradient_update = 0;
5796 unsigned long tmpcolour = current_color;
5797 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5798 tmpcolour = specials[special_index].last_colour;
5799 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
5800 gradient_factor = (float)gradient_size / (w - 2);
5802 for (i = w - 2; i > -1; i--) {
5803 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5804 XSetForeground(display, window.gc, tmpcolour);
5805 gradient_update += gradient_factor;
5806 while (gradient_update > 0) {
5807 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
5811 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
5814 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 */
5816 if (specials[special_index].
5818 && specials[special_index].
5822 [special_index].height;
5824 /* if (draw_mode == BG) {
5825 set_foreground_color(default_bg_color);
5827 else if (draw_mode == OUTLINE) {
5828 set_foreground_color(default_out_color);
5830 set_foreground_color(default_fg_color);
5832 set_foreground_color(last_colour);
5838 int old = font_ascent();
5839 cur_y -= font_ascent();
5840 selected_font = specials[special_index].font_added;
5841 if (cur_y + font_ascent() < cur_y + old) {
5844 cur_y += font_ascent();
5850 if (draw_mode == FG)
5851 set_foreground_color(specials
5857 if (draw_mode == BG)
5858 set_foreground_color(specials
5864 if (draw_mode == OUTLINE)
5865 set_foreground_color(specials
5871 w += specials[special_index].arg;
5875 cur_y += specials[special_index].arg;
5879 if (specials[special_index].arg >= 0)
5880 cur_x = (int)specials[special_index].arg;
5885 int start = specials[special_index].arg;
5886 int step = specials[special_index].width;
5887 if (!step || step < 0)
5889 w = step - (cur_x - text_start_x - start) % step;
5895 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
5896 /*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);*/
5897 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
5898 cur_x = pos_x - specials[special_index].arg;
5905 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
5906 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
5907 /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width(s), gap_x, specials[special_index].arg);*/
5909 specials[special_index].arg)
5912 [special_index].arg;
5929 if (cur_y_add > 0) {
5931 cur_y -= font_descent();
5936 cur_y += font_descent();
5940 static void draw_text()
5943 cur_y = text_start_y;
5946 if (draw_borders && border_width > 0) {
5947 unsigned int b = (border_width + 1) / 2;
5949 if (stippled_borders) {
5951 { stippled_borders, stippled_borders };
5952 XSetLineAttributes(display, window.gc,
5953 border_width, LineOnOffDash,
5954 CapButt, JoinMiter);
5955 XSetDashes(display, window.gc, 0, ss, 2);
5957 XSetLineAttributes(display, window.gc,
5958 border_width, LineSolid,
5959 CapButt, JoinMiter);
5962 XDrawRectangle(display, window.drawable, window.gc,
5963 text_start_x - border_margin + b,
5964 text_start_y - border_margin + b,
5965 text_width + border_margin * 2 - 1 - b * 2,
5966 text_height + border_margin * 2 - 1 -
5973 for_each_line(text_buffer, draw_line);
5976 static void draw_stuff()
5980 if (draw_shades && !draw_outline) {
5983 set_foreground_color(default_bg_color);
5993 for (i = -1; i < 2; i++)
5994 for (j = -1; j < 2; j++) {
5995 if (i == 0 && j == 0)
5999 set_foreground_color(default_out_color);
6000 draw_mode = OUTLINE;
6007 set_foreground_color(default_fg_color);
6015 swap.swap_window = window.window;
6016 swap.swap_action = XdbeBackground;
6017 XdbeSwapBuffers(display, &swap, 1);
6023 static void clear_text(int exposures)
6027 return; /* The swap action is XdbeBackground, which clears */
6031 /* there is some extra space for borders and outlines */
6032 XClearArea(display, window.window,
6033 text_start_x - border_margin - 1,
6034 text_start_y - border_margin - 1,
6035 text_width + border_margin * 2 + 2,
6036 text_height + border_margin * 2 + 2,
6037 exposures ? True : 0);
6042 static int need_to_update;
6044 /* update_text() generates new text and clears old text area */
6045 static void update_text()
6054 static void main_loop()
6056 #ifdef SIGNAL_BLOCKING
6057 sigset_t newmask, oldmask;
6059 sigemptyset(&newmask);
6060 sigaddset(&newmask,SIGINT);
6061 sigaddset(&newmask,SIGTERM);
6062 sigaddset(&newmask,SIGUSR1);
6066 Region region = XCreateRegion();
6068 int event_base, error_base;
6069 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
6070 ERR("Xdamage extension unavailable");
6072 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
6073 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
6074 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
6075 #endif /* HAVE_XDAMAGE */
6079 while (total_run_times == 0 || info.looped < total_run_times) {
6082 #ifdef SIGNAL_BLOCKING
6083 /* block signals. we will inspect for pending signals later */
6084 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
6085 CRIT_ERR("unable to sigprocmask()");
6091 /* wait for X event or timeout */
6093 if (!XPending(display)) {
6098 update_interval - (get_time() -
6104 tv.tv_sec = (long) t;
6105 tv.tv_usec = (long) (t * 1000000) % 1000000;
6107 FD_SET(ConnectionNumber(display), &fdsr);
6110 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
6113 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
6118 ERR("can't select(): %s",
6129 if (need_to_update) {
6131 int wx = window.x, wy = window.y;
6139 /* resize window if it isn't right size */
6141 (text_width + border_margin * 2 + 1 !=
6143 || text_height + border_margin * 2 + 1 !=
6147 border_margin * 2 + 1;
6150 border_margin * 2 + 1;
6151 XResizeWindow(display,
6156 set_transparent_background(window.window);
6160 /* move window if it isn't in right position */
6163 || window.y != wy)) {
6164 XMoveWindow(display, window.window,
6165 window.x, window.y);
6175 r.x = text_start_x - border_margin;
6176 r.y = text_start_y - border_margin;
6177 r.width = text_width + border_margin * 2;
6178 r.height = text_height + border_margin * 2;
6179 XUnionRectWithRegion(&r, region, region);
6184 /* handle X events */
6186 while (XPending(display)) {
6188 XNextEvent(display, &ev);
6195 r.width = ev.xexpose.width;
6196 r.height = ev.xexpose.height;
6197 XUnionRectWithRegion(&r, region,
6203 case ReparentNotify:
6204 /* set background to ParentRelative for all parents */
6206 set_transparent_background(window.
6211 case ConfigureNotify:
6213 /* if window size isn't what expected, set fixed size */
6214 if (ev.xconfigure.width !=
6216 || ev.xconfigure.height !=
6218 if (window.width != 0
6219 && window.height != 0)
6222 /* clear old stuff before screwing up size and pos */
6228 if (XGetWindowAttributes(display, window.window, &attrs)) {
6243 border_margin * 2 - 1;
6246 border_margin * 2 - 1;
6247 if (text_width > maximum_width && maximum_width > 0)
6248 text_width = maximum_width;
6251 /* if position isn't what expected, set fixed pos, total_updates
6252 * avoids setting fixed_pos when window is set to weird locations
6254 /*if (total_updates >= 2 this is broken
6256 && (window.x != ev.xconfigure.x
6259 && (ev.xconfigure.x != 0
6260 || ev.xconfigure.y != 0)) {
6270 /* if an ordinary window with decorations */
6271 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6273 /* allow conky to hold input focus.*/
6278 /* forward the click to the desktop window */
6279 XUngrabPointer(display, ev.xbutton.time);
6280 ev.xbutton.window = window.desktop;
6281 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6282 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6290 /* if an ordinary window with decorations */
6291 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6293 /* allow conky to hold input focus.*/
6298 /* forward the release to the desktop window */
6299 ev.xbutton.window = window.desktop;
6300 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6309 if (ev.type == event_base + XDamageNotify) {
6310 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6311 XFixesSetRegion(display, part, &dev->area, 1);
6312 XFixesUnionRegion(display, region2, region2, part);
6314 #endif /* HAVE_XDAMAGE */
6319 XDamageSubtract(display, damage, region2, None);
6320 XFixesSetRegion(display, region2, 0, 0);
6321 #endif /* HAVE_XDAMAGE */
6323 /* XDBE doesn't seem to provide a way to clear the back buffer without
6324 * interfering with the front buffer, other than passing XdbeBackground
6325 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6326 * redraw the text even if it wasn't part of the exposed area. OTOH,
6327 * if we're not going to call draw_stuff at all, then no swap happens
6328 * and we can safely do nothing.
6331 if (!XEmptyRegion(region)) {
6335 r.x = text_start_x - border_margin;
6336 r.y = text_start_y - border_margin;
6337 r.width = text_width + border_margin * 2;
6338 r.height = text_height + border_margin * 2;
6339 XUnionRectWithRegion(&r, region, region);
6342 XSetRegion(display, window.gc, region);
6345 XftDrawSetClip(window.xftdraw, region);
6351 XDestroyRegion(region);
6352 region = XCreateRegion();
6356 #ifdef SIGNAL_BLOCKING
6357 /* unblock signals of interest and let handler fly */
6358 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6359 CRIT_ERR("unable to sigprocmask()");
6362 switch(g_signal_pending) {
6365 ERR("received SIGUSR1. reloading the config file.");
6372 ERR("received SIGINT or SIGTERM to terminate. bye!");
6375 XDestroyRegion(region);
6378 return; /* return from main_loop */
6383 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6384 * but didn't write any code to deal with it. if you don't want to
6385 * handle a signal, don't set a handler on it in the first place. */
6386 if (g_signal_pending)
6387 ERR("ignoring signal (%d)", g_signal_pending);
6394 #if defined(X11) && defined(HAVE_XDAMAGE)
6395 XDamageDestroy(display, damage);
6396 XFixesDestroyRegion(display, region2);
6397 XFixesDestroyRegion(display, part);
6398 XDestroyRegion(region);
6400 #endif /* X11 && HAVE_XDAMAGE */
6403 static void load_config_file(const char *);
6405 /* reload the config file */
6406 void reload_config(void)
6408 timed_thread_destroy_registered_threads ();
6410 if (info.cpu_usage) {
6411 free(info.cpu_usage);
6412 info.cpu_usage = NULL;
6415 #ifdef TCP_PORT_MONITOR
6416 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6419 if (current_config) {
6421 load_config_file(current_config);
6423 /* re-init specials array */
6424 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6425 ERR("failed to realloc specials array");
6430 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6433 #ifdef TCP_PORT_MONITOR
6434 info.p_tcp_port_monitor_collection = NULL;
6437 if (create_audacious_thread() !=0)
6438 CRIT_ERR("unable to create audacious thread!");
6439 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6441 extract_variable_text(text);
6450 timed_thread_destroy_registered_threads ();
6452 if (info.cpu_usage) {
6453 free(info.cpu_usage);
6454 info.cpu_usage = NULL;
6459 XdbeDeallocateBackBufferName(display, window.back_buffer);
6465 XDestroyWindow(display, window.window);
6466 XClearWindow(display, RootWindow(display, screen));
6472 XClearWindow(display, RootWindow(display, screen));
6477 XFreeGC(display, window.gc);
6480 free_text_objects(text_object_count, text_objects);
6481 text_object_count = 0;
6482 text_objects = NULL;
6484 if (text != original_text)
6487 free(current_config);
6488 free(current_mail_spool);
6490 #ifdef TCP_PORT_MONITOR
6491 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6492 info.p_tcp_port_monitor_collection = NULL;
6501 static int string_to_bool(const char *s)
6505 if (strcasecmp(s, "yes") == 0)
6507 if (strcasecmp(s, "true") == 0)
6509 if (strcasecmp(s, "1") == 0)
6514 static enum alignment string_to_alignment(const char *s)
6516 if (strcasecmp(s, "top_left") == 0)
6518 else if (strcasecmp(s, "top_right") == 0)
6520 else if (strcasecmp(s, "bottom_left") == 0)
6522 else if (strcasecmp(s, "bottom_right") == 0)
6523 return BOTTOM_RIGHT;
6524 else if (strcasecmp(s, "tl") == 0)
6526 else if (strcasecmp(s, "tr") == 0)
6528 else if (strcasecmp(s, "bl") == 0)
6530 else if (strcasecmp(s, "br") == 0)
6531 return BOTTOM_RIGHT;
6532 else if (strcasecmp(s, "none") == 0)
6539 static void set_default_configurations(void)
6541 fork_to_background = 0;
6542 total_run_times = 0;
6543 info.cpu_avg_samples = 2;
6544 info.net_avg_samples = 2;
6549 strcpy(info.mpd.host, "localhost");
6550 info.mpd.port = 6600;
6551 info.mpd.status = NULL;
6552 info.mpd.artist = NULL;
6553 info.mpd.album = NULL;
6554 info.mpd.title = NULL;
6555 info.mpd.random = NULL;
6556 info.mpd.track = NULL;
6557 info.mpd.name = NULL;
6558 info.mpd.file = NULL;
6561 info.xmms2.artist = NULL;
6562 info.xmms2.album = NULL;
6563 info.xmms2.title = NULL;
6564 info.xmms2.genre = NULL;
6565 info.xmms2.comment = NULL;
6566 info.xmms2.decoder = NULL;
6567 info.xmms2.transport = NULL;
6568 info.xmms2.url = NULL;
6569 info.xmms2.status = NULL;
6578 default_fg_color = WhitePixel(display, screen);
6579 default_bg_color = BlackPixel(display, screen);
6580 default_out_color = BlackPixel(display, screen);
6581 color0 = default_fg_color;
6582 color1 = default_fg_color;
6583 color2 = default_fg_color;
6584 color3 = default_fg_color;
6585 color4 = default_fg_color;
6586 color5 = default_fg_color;
6587 color6 = default_fg_color;
6588 color7 = default_fg_color;
6589 color8 = default_fg_color;
6590 color9 = default_fg_color;
6593 draw_graph_borders = 1;
6595 set_first_font("6x10");
6603 window.type=TYPE_NORMAL;
6605 strcpy(window.class_name, "Conky");
6607 sprintf(window.title,"%s - conky",info.uname_s.nodename);
6609 stippled_borders = 0;
6612 text_alignment = BOTTOM_LEFT;
6615 free(current_mail_spool);
6618 variable_substitute(MAIL_FILE, buf, 256);
6620 current_mail_spool = strdup(buf);
6624 update_interval = 10.0;
6625 stuff_in_upper_case = 0;
6627 #ifdef TCP_PORT_MONITOR
6628 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6632 static void load_config_file(const char *f)
6634 #define CONF_ERR ERR("%s: %d: config file error", f, line)
6638 set_default_configurations();
6644 char buf[256], *p, *p2, *name, *value;
6646 if (fgets(buf, 256, fp) == NULL)
6651 /* break at comment */
6652 p2 = strchr(p, '#');
6657 while (*p && isspace((int) *p))
6660 continue; /* empty line */
6666 while (*p2 && !isspace((int) *p2))
6669 *p2 = '\0'; /* break at name's end */
6676 while (*p && isspace((int) *p))
6681 p2 = value + strlen(value);
6682 while (isspace((int) *(p2 - 1)))
6688 #define CONF2(a) if (strcasecmp(name, a) == 0)
6689 #define CONF(a) else CONF2(a)
6690 #define CONF3(a,b) \
6691 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
6695 CONF2("alignment") {
6697 int a = string_to_alignment(value);
6705 CONF("background") {
6706 fork_to_background = string_to_bool(value);
6710 CONF2("background") {
6711 fork_to_background = string_to_bool(value);
6715 CONF("border_margin") {
6717 border_margin = strtol(value, 0, 0);
6721 CONF("border_width") {
6723 border_width = strtol(value, 0, 0);
6729 color0 = get_x11_color(value);
6735 color1 = get_x11_color(value);
6741 color2 = get_x11_color(value);
6747 color3 = get_x11_color(value);
6753 color4 = get_x11_color(value);
6759 color5 = get_x11_color(value);
6765 color6 = get_x11_color(value);
6771 color7 = get_x11_color(value);
6777 color8 = get_x11_color(value);
6783 color9 = get_x11_color(value);
6787 CONF("default_color") {
6789 default_fg_color = get_x11_color(value);
6793 CONF3("default_shade_color", "default_shadecolor") {
6795 default_bg_color = get_x11_color(value);
6799 CONF3("default_outline_color", "default_outlinecolor") {
6801 default_out_color = get_x11_color(value);
6808 info.mail = parse_mail_args(IMAP, value);
6815 info.mail = parse_mail_args(POP3, value);
6823 strncpy(info.mpd.host, value, 127);
6829 info.mpd.port = strtol(value, 0, 0);
6830 if (info.mpd.port < 1
6831 || info.mpd.port > 0xffff)
6835 CONF("mpd_password") {
6837 strncpy(info.mpd.password, value, 127);
6843 CONF("sensor_device") {
6845 sensor_device = strtol(value, 0, 0);
6850 CONF("cpu_avg_samples") {
6852 cpu_avg_samples = strtol(value, 0, 0);
6853 if (cpu_avg_samples < 1
6854 || cpu_avg_samples > 14)
6863 CONF("net_avg_samples") {
6865 net_avg_samples = strtol(value, 0, 0);
6866 if (net_avg_samples < 1
6867 || net_avg_samples > 14)
6883 CONF("double_buffer") {
6884 use_xdbe = string_to_bool(value);
6888 CONF("override_utf8_locale") {
6889 utf8_mode = string_to_bool(value);
6892 CONF("draw_borders") {
6893 draw_borders = string_to_bool(value);
6895 CONF("draw_graph_borders") {
6896 draw_graph_borders = string_to_bool(value);
6898 CONF("draw_shades") {
6899 draw_shades = string_to_bool(value);
6901 CONF("draw_outline") {
6902 draw_outline = string_to_bool(value);
6905 CONF("out_to_console") {
6906 out_to_console = string_to_bool(value);
6908 CONF("use_spacer") {
6909 use_spacer = string_to_bool(value);
6914 use_xft = string_to_bool(value);
6918 set_first_font(value);
6923 if (value && font_count >= 0)
6924 fonts[0].font_alpha = atof(value)
6933 if (string_to_bool(value))
6934 ERR("Xft not enabled");
6937 /* xftfont silently ignored when no Xft */
6940 /* xftalpha is silently ignored when no Xft */
6945 set_first_font(value);
6954 gap_x = atoi(value);
6960 gap_y = atoi(value);
6965 CONF("mail_spool") {
6968 variable_substitute(value, buf, 256);
6972 if (current_mail_spool)
6973 free(current_mail_spool);
6974 current_mail_spool = strdup(buf);
6980 CONF("minimum_size") {
6983 (value, "%d %d", &minimum_width,
6984 &minimum_height) != 2)
6987 &minimum_width) != 1)
6992 CONF("maximum_width") {
6994 if (sscanf(value, "%d", &maximum_width) != 1)
7000 CONF("no_buffers") {
7001 no_buffers = string_to_bool(value);
7003 CONF("pad_percents") {
7004 pad_percents = atoi(value);
7008 CONF("own_window") {
7010 own_window = string_to_bool(value);
7014 CONF("own_window_class") {
7017 memset(window.class_name,0,sizeof(window.class_name));
7018 strncpy(window.class_name, value, sizeof(window.class_name)-1);
7023 CONF("own_window_title") {
7026 memset(window.title,0,sizeof(window.title));
7027 strncpy(window.title, value, sizeof(window.title)-1);
7032 CONF("own_window_transparent") {
7034 set_transparent = string_to_bool(value);
7038 CONF("own_window_colour") {
7040 background_colour = get_x11_color(value);
7042 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
7045 CONF("own_window_hints") {
7047 char *p_hint, *p_save;
7048 char delim[] = ", ";
7050 /* tokenize the value into individual hints */
7051 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
7053 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
7054 if (strncmp(p_hint,"undecorate",10) == 0)
7055 SET_HINT(window.hints,HINT_UNDECORATED);
7056 else if (strncmp(p_hint,"below",5) == 0)
7057 SET_HINT(window.hints,HINT_BELOW);
7058 else if (strncmp(p_hint,"above",5) == 0)
7059 SET_HINT(window.hints,HINT_ABOVE);
7060 else if (strncmp(p_hint,"sticky",6) == 0)
7061 SET_HINT(window.hints,HINT_STICKY);
7062 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
7063 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
7064 else if (strncmp(p_hint,"skip_pager",10) == 0)
7065 SET_HINT(window.hints,HINT_SKIP_PAGER);
7069 p_hint=strtok_r(NULL, delim, &p_save);
7071 while (p_hint!=NULL);
7076 CONF("own_window_type") {
7078 if (strncmp(value,"normal",6)==0)
7079 window.type = TYPE_NORMAL;
7080 else if (strncmp(value,"desktop",7)==0)
7081 window.type = TYPE_DESKTOP;
7082 else if (strncmp(value,"override",8)==0)
7083 window.type = TYPE_OVERRIDE;
7091 CONF("stippled_borders") {
7093 stippled_borders = strtol(value, 0, 0);
7095 stippled_borders = 4;
7099 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
7102 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
7104 CONF("update_interval") {
7106 update_interval = strtod(value, 0);
7110 CONF("total_run_times") {
7112 total_run_times = strtod(value, 0);
7117 stuff_in_upper_case = string_to_bool(value);
7119 CONF("max_specials") {
7121 max_specials = atoi(value);
7125 CONF("max_user_text") {
7127 max_user_text = atoi(value);
7131 CONF("text_buffer_size") {
7133 text_buffer_size = atoi(value);
7138 if (text != original_text)
7148 int l = strlen(text);
7149 if (fgets(buf, 256, fp) == NULL)
7152 realloc(text, l + strlen(buf)
7156 if (strlen(text) > max_user_text)
7160 text_lines = line + 1;
7163 #ifdef TCP_PORT_MONITOR
7164 CONF("max_port_monitor_connections")
7167 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7168 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
7170 /* an error. use default, warn and continue. */
7171 tcp_port_monitor_args.max_port_monitor_connections =
7172 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7175 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
7177 /* no error, just use default */
7178 tcp_port_monitor_args.max_port_monitor_connections =
7179 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7181 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
7186 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7198 /* : means that character before that takes an argument */
7199 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
7212 int main(int argc, char **argv)
7214 struct sigaction act, oact;
7217 memset(&info, 0, sizeof(info) );
7219 #ifdef TCP_PORT_MONITOR
7220 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7223 /* handle command line parameters that don't change configs */
7228 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7229 *s) || ((s = getenv("LANG")) && *s)) {
7230 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7232 ERR("malloc failed");
7234 for (x = 0; x < strlen(s); x++) {
7235 temp[x] = tolower(s[x]);
7237 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7243 if (!setlocale(LC_CTYPE, "")) {
7244 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7248 int c = getopt(argc,
7259 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
7260 * though free() does the NULL check itself;), then load optarg value */
7262 free(current_config);
7263 current_config = strdup(optarg);
7268 ("Usage: %s [OPTION]...\n"
7269 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7270 "window. Command line options will override configurations defined in config\n"
7273 " -c FILE config file to load instead of "
7276 " -d daemonize, fork to background\n"
7279 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7280 " -f FONT font to use\n"
7282 " -o create own window to draw\n"
7285 " -b double buffer (prevents flickering)\n"
7287 " -w WIN_ID window id to draw\n"
7288 " -x X x position\n"
7289 " -y Y y position\n"
7291 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
7292 " -u SECS update interval\n"
7293 " -i NUM number of times to update Conky\n", argv[0]);
7297 window.window = strtol(optarg, 0, 0);
7306 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7310 /* load current_config or CONFIG_FILE */
7313 if (current_config == NULL) {
7314 /* load default config file */
7317 variable_substitute(CONFIG_FILE, buf, 256);
7320 current_config = strdup(buf);
7324 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
7325 load_config_file(current_config);
7327 set_default_configurations();
7330 /* init specials array */
7331 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7332 ERR("failed to create specials array");
7335 if (current_mail_spool == NULL) {
7337 variable_substitute(MAIL_FILE, buf, 256);
7340 current_mail_spool = strdup(buf);
7344 /* handle other command line arguments */
7346 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
7347 optind = optreset = 1;
7352 #if defined(__FreeBSD__)
7353 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7354 O_RDONLY, "kvm_open")) == NULL)
7355 CRIT_ERR( "cannot read kvm");
7359 int c = getopt(argc,
7367 fork_to_background = 1;
7372 set_first_font(optarg);
7375 text_alignment = string_to_alignment(optarg);
7390 if (text != original_text)
7392 text = strdup(optarg);
7393 convert_escapes(text);
7397 update_interval = strtod(optarg, 0);
7401 total_run_times = strtod(optarg, 0);
7405 gap_x = atoi(optarg);
7409 gap_y = atoi(optarg);
7423 /* generate text and get initial size */
7424 extract_variable_text(text);
7425 if (text != original_text) {
7430 if (fork_to_background) {
7434 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
7440 fprintf(stderr,"\n"); fflush(stderr);
7444 /* parent process */
7445 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
7452 update_text_area(); /* to get initial size of the window */
7456 text_width + border_margin * 2 + 1,
7457 text_height + border_margin * 2 + 1,
7458 set_transparent, background_colour, argv, argc);
7461 update_text_area(); /* to position text/window on screen */
7466 if (own_window && !fixed_pos) {
7467 XMoveWindow(display, window.window, window.x, window.y);
7470 set_transparent_background(window.window);
7481 /* Set signal handlers */
7482 act.sa_handler = signal_handler;
7483 sigemptyset(&act.sa_mask);
7486 act.sa_flags |= SA_RESTART;
7489 if ( sigaction(SIGINT,&act,&oact) < 0 ||
7490 sigaction(SIGUSR1,&act,&oact) < 0 ||
7491 sigaction(SIGTERM,&act,&oact) < 0 )
7493 ERR("error setting signal handler: %s", strerror(errno) );
7497 if (create_audacious_thread() !=0)
7498 CRIT_ERR("unable to create audacious thread!");
7499 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
7510 #if defined(__FreeBSD__)
7517 void signal_handler(int sig)
7519 /* signal handler is light as a feather, as it should be.
7520 * we will poll g_signal_pending with each loop of conky
7521 * and do any signal processing there, NOT here. */
7522 g_signal_pending=sig;