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 */
107 static int text_start_x, text_start_y; /* text start position in window */
108 static int text_width, text_height;
123 char name[TEXT_BUFFER_SIZE];
133 static int selected_font = 0;
134 static int font_count = -1;
135 struct font_list *fonts = NULL;
139 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
140 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent))
141 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent)
142 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent)
146 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
147 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
148 #define font_descent() fonts[selected_font].font->max_bounds.descent
152 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
155 static void set_font();
157 int addfont(const char *data_in)
159 if (font_count > MAX_FONTS) {
160 CRIT_ERR("you don't need that many fonts, sorry.");
163 if (font_count == 0) {
167 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
171 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
173 CRIT_ERR("realloc in addfont");
175 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
176 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
178 fonts[font_count].font_alpha = 0xffff;
181 CRIT_ERR("Oops...looks like something overflowed in addfont().");
186 void set_first_font(const char *data_in)
188 if (font_count < 0) {
189 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
194 if (strlen(data_in) > 1) {
195 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
197 fonts[0].font_alpha = 0xffff;
205 for (i=0;i<=font_count;i++) {
208 XftFontClose(display, fonts[i].xftfont);
212 XFreeFont(display, fonts[i].font);
219 set_first_font("6x10");
223 static void load_fonts()
226 for (i=0; i <= font_count; i++) {
230 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
231 XftFontClose(display, fonts[i].xftfont);
233 if ((fonts[i].xftfont =
234 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
237 ERR("can't load Xft font '%s'", fonts[i].name);
238 if ((fonts[i].xftfont =
239 XftFontOpenName(display, screen,
240 "courier-12")) != NULL)
243 ERR("can't load Xft font '%s'", "courier-12");
245 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
246 CRIT_ERR("can't load font '%s'", "fixed");
253 /* load normal font */
254 /* if (fonts[i].font != NULL)
255 XFreeFont(display, fonts[i].font);*/
257 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
258 ERR("can't load font '%s'", fonts[i].name);
259 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
260 CRIT_ERR("can't load font '%s'", "fixed");
261 printf("loaded fixed?\n");
269 /* default config file */
270 static char *current_config;
272 /* set to 1 if you want all text to be in uppercase */
273 static unsigned int stuff_in_upper_case;
275 /* Run how many times? */
276 static unsigned long total_run_times;
279 static int fork_to_background;
281 static int cpu_avg_samples, net_avg_samples;
285 /* Position on the screen */
286 static int text_alignment;
287 static int gap_x, gap_y;
290 static int draw_borders;
291 static int draw_graph_borders;
292 static int stippled_borders;
294 static int draw_shades, draw_outline;
296 static int border_margin, border_width;
298 static long default_fg_color, default_bg_color, default_out_color;
300 /* create own window or draw stuff to root? */
301 static int set_transparent = 0;
305 static int own_window = 0;
306 static int background_colour = 0;
307 /* fixed size/pos is set if wm/user changes them */
308 static int fixed_size = 0, fixed_pos = 0;
311 static int minimum_width, minimum_height;
312 static int maximum_width;
317 static int sensor_device;
320 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
321 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
323 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
324 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
326 /* maximum size of individual text buffers, ie $exec buffer size */
327 unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
330 #define CODEPAGE_LENGTH 20
333 char iconv_converting;
334 static iconv_t **iconv_cd = 0;
336 int register_iconv(iconv_t *new_iconv)
339 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
341 iconv_cd = malloc(sizeof(iconv_t *));
344 CRIT_ERR("Out of memory");
346 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
347 if (!iconv_cd[iconv_count]) {
348 CRIT_ERR("Out of memory");
350 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
355 void free_iconv(void)
359 for (i = iconv_count; i < 0; i++) {
375 /* no buffers in used memory? */
378 /* pad percentages to decimals? */
379 static int pad_percents = 0;
381 #ifdef TCP_PORT_MONITOR
382 tcp_port_monitor_args_t tcp_port_monitor_args;
385 /* Text that is shown */
386 static char original_text[] =
387 "$nodename - $sysname $kernel on $machine\n"
389 "${color grey}Uptime:$color $uptime\n"
390 "${color grey}Frequency (in MHz):$color $freq\n"
391 "${color grey}Frequency (in GHz):$color $freq_g\n"
392 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
393 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
394 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
395 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
397 "${color grey}File systems:\n"
398 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
399 "${color grey}Networking:\n"
400 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
403 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
404 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
407 "${color grey}XMMS2: $xmms2_status $xmms2_artist - $xmms2_title from $xmms2_album\n"
408 "Progress: $xmms2_bar\n"
410 "${color grey}Name PID CPU% MEM%\n"
411 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
412 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
413 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
414 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
415 "${tail /var/log/Xorg.0.log 3}";
417 static char *text = original_text;
420 static int total_updates;
423 static int blockdepth = 0;
424 static int if_jumped = 0;
425 static int blockstart[MAX_IF_BLOCK_DEPTH];
427 int check_mount(char *s)
429 #if defined(__linux__)
431 FILE *mtab = fopen("/etc/mtab", "r");
433 char buf1[256], buf2[128];
434 while (fgets(buf1, 256, mtab)) {
435 sscanf(buf1, "%*s %128s", buf2);
436 if (!strcmp(s, buf2)) {
443 ERR("Could not open mtab");
446 #elif defined(__FreeBSD__)
447 struct statfs *mntbuf;
450 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
451 for (i = mntsize - 1; i >= 0; i--)
452 if (strcmp(mntbuf[i].f_mntonname, s) == 0)
460 int check_contains(char *f, char *s)
463 FILE *where = fopen(f, "r");
465 char buf1[256], buf2[256];
466 while (fgets(buf1, 256, where)) {
467 sscanf(buf1, "%255s", buf2);
468 if (strstr(buf2, s)) {
475 ERR("Could not open the file");
482 static inline int calc_text_width(const char *s, int l)
488 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
490 XftTextExtents8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
496 return XTextWidth(fonts[selected_font].font, s, l);
501 /* formatted text to render on screen, generated in generate_text(),
502 * drawn in draw_stuff() */
504 static char text_buffer[TEXT_BUFFER_SIZE * 4];
506 /* special stuff in text_buffer */
508 #define SPECIAL_CHAR '\x01'
537 unsigned long first_colour; // for graph gradient
538 unsigned long last_colour;
541 /* create specials array on heap instead of stack with introduction of max_specials */
542 static struct special_t *specials = NULL;
544 static unsigned int special_count;
546 static unsigned int special_index; /* used when drawing */
549 #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? */
551 static struct special_t *new_special(char *buf, int t)
553 if (special_count >= max_specials)
554 CRIT_ERR("too many special things in text");
556 buf[0] = SPECIAL_CHAR;
558 specials[special_count].type = t;
559 return &specials[special_count++];
562 long fwd_fcharfind(FILE* fp, char val, unsigned int step) {
565 unsigned int count = 0;
566 static char buf[BUFSZ];
567 long orig_pos = ftell(fp);
569 long buf_size = BUFSZ;
570 char* cur_found = NULL;
571 while(count < step) {
572 if(cur_found == NULL) {
573 buf_size = fread(buf, 1, buf_size, fp);
576 cur_found = memchr(buf+buf_pos, val, buf_size-buf_pos);
577 if(cur_found != NULL) {
578 buf_pos = cur_found-buf+1;
587 ret = ftell(fp) - buf_size + buf_pos - 1;
588 fseek(fp, orig_pos, SEEK_SET);
595 memrchr (const void *buffer, int c, size_t n)
597 const unsigned char *p = buffer;
599 for (p += n; n ; n--)
605 long rev_fcharfind(FILE* fp, char val, unsigned int step) {
608 unsigned int count = 0;
609 static char buf[BUFSZ];
610 long orig_pos = ftell(fp);
612 long file_pos = orig_pos;
613 long buf_size = BUFSZ;
615 while(count < step) {
617 if(file_pos > BUFSZ) {
618 fseek(fp, file_pos-BUFSZ, SEEK_SET);
622 fseek(fp, 0, SEEK_SET);
624 file_pos = ftell(fp);
625 buf_pos = fread(buf, 1, buf_size, fp);
632 if(cur_found != NULL) {
633 buf_pos = cur_found-buf;
642 fseek(fp, orig_pos, SEEK_SET);
644 ret = file_pos + buf_pos;
649 static void new_bar(char *buf, int w, int h, int usage)
651 struct special_t *s = new_special(buf, BAR);
652 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
657 static const char *scan_bar(const char *args, int *w, int *h)
659 *w = 0; /* zero width means all space that is available */
661 /* bar's argument is either height or height,width */
664 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
665 sscanf(args, "%d %n", h, &n);
672 static char *scan_font(const char *args)
674 if (args && sizeof(args) < 127) {
681 static void new_font(char *buf, char * args) {
683 struct special_t *s = new_special(buf, FONT);
684 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
685 int tmp = selected_font;
686 selected_font = s->font_added = addfont(args);
691 struct special_t *s = new_special(buf, FONT);
692 int tmp = selected_font;
693 selected_font = s->font_added = 0;
700 inline void graph_append(struct special_t *graph, double f)
702 if (!graph->scaled && f > graph->graph_scale) {
703 f = graph->graph_scale;
707 graph->graph_scale = 1;
709 graph->graph[0] = f; /* add new data */
710 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
711 graph->graph[i] = graph->graph[i - 1];
712 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
713 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
718 short colour_depth = 0;
719 void set_up_gradient();
721 /* precalculated: 31/255, and 63/255 */
722 #define CONST_8_TO_5_BITS 0.12156862745098
723 #define CONST_8_TO_6_BITS 0.247058823529412
725 /* adjust color values depending on color depth*/
726 static unsigned int adjust_colors(unsigned int color)
729 if (colour_depth == 0) {
732 if (colour_depth == 16) {
733 r = (color & 0xff0000) >> 16;
734 g = (color & 0xff00) >> 8;
736 color = (int)(r * CONST_8_TO_5_BITS) << 11;
737 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
738 color |= (int)(b * CONST_8_TO_5_BITS);
743 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
745 struct special_t *s = new_special(buf, GRAPH);
747 if (s->graph == NULL) {
748 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
749 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
751 s->graph_width = MAX_GRAPH_DEPTH - 2;
753 s->graph = malloc(s->graph_width * sizeof(double));
754 memset(s->graph, 0, s->graph_width * sizeof(double));
755 s->graph_scale = 100;
758 s->first_colour = adjust_colors(first_colour);
759 s->last_colour = adjust_colors(second_colour);
766 s->graph_width = s->width - 2; // subtract 2 for rectangle around
771 s->graph_scale = scale;
778 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
780 *w = 0; /* zero width means all space that is available */
784 /* graph's argument is either height or height,width */
786 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
787 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
789 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
791 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
794 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
798 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
801 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
805 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
808 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
812 if (sscanf(args, "%d,%d", h, w) < 2) {
815 sscanf(args, "%*s %d,%d", h, w);
821 static inline void new_hr(char *buf, int a)
823 new_special(buf, HORIZONTAL_LINE)->height = a;
826 static inline void new_stippled_hr(char *buf, int a, int b)
828 struct special_t *s = new_special(buf, STIPPLED_HR);
833 static inline void new_fg(char *buf, long c)
835 new_special(buf, FG)->arg = c;
838 static inline void new_bg(char *buf, long c)
840 new_special(buf, BG)->arg = c;
843 static inline void new_outline(char *buf, long c)
845 new_special(buf, OUTLINE)->arg = c;
848 static inline void new_offset(char *buf, long c)
850 new_special(buf, OFFSET)->arg = c;
853 static inline void new_voffset(char *buf, long c)
855 new_special(buf, VOFFSET)->arg = c;
858 static inline void new_alignr(char *buf, long c)
860 new_special(buf, ALIGNR)->arg = c;
863 static inline void new_alignc(char *buf, long c)
865 new_special(buf, ALIGNC)->arg = c;
868 static inline void new_goto(char *buf, long c)
870 new_special(buf, GOTO)->arg = c;
873 static inline void new_tab(char *buf, int a, int b) {
874 struct special_t *s = new_special(buf, TAB);
879 /* quite boring functions */
881 static inline void for_each_line(char *b, void (*f) (char *))
885 for (ps = b, pe = b; *pe; pe++) {
898 static void convert_escapes(char *buf)
900 char *p = buf, *s = buf;
916 /* converts from bytes to human readable format (k, M, G, T) */
917 static void human_readable(long long a, char *buf, int size)
919 // Strange conditional due to possible overflows
920 if(a / 1024 / 1024 / 1024.0 > 1024.0){
921 snprintf(buf, size, "%.2fTiB", (a / 1024 / 1024 / 1024) / 1024.0);
923 else if (a >= 1024 * 1024 * 1024) {
924 snprintf(buf, size, "%.2fGiB", (a / 1024 / 1024) / 1024.0);
926 else if (a >= 1024 * 1024) {
927 double m = (a / 1024) / 1024.0;
929 snprintf(buf, size, "%.0fMiB", m);
931 snprintf(buf, size, "%.1fMiB", m);
932 } else if (a >= 1024)
933 snprintf(buf, size, "%LdKiB", a / (long long) 1024);
935 snprintf(buf, size, "%LdB", a);
940 enum text_object_type {
964 OBJ_diskiograph_read,
965 OBJ_diskiograph_write,
998 #if defined(__linux__)
1004 OBJ_i8k_left_fan_status,
1005 OBJ_i8k_right_fan_status,
1006 OBJ_i8k_left_fan_rpm,
1007 OBJ_i8k_right_fan_rpm,
1009 OBJ_i8k_buttons_status,
1017 #endif /* __linux__ */
1046 OBJ_running_processes,
1055 OBJ_temp1, /* i2c is used instead in these */
1075 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
1077 OBJ_apm_battery_time,
1078 OBJ_apm_battery_life,
1079 #endif /* __FreeBSD__ */
1081 OBJ_obsd_sensors_temp,
1082 OBJ_obsd_sensors_fan,
1083 OBJ_obsd_sensors_volt,
1086 #endif /* __OpenBSD__ */
1115 OBJ_xmms2_transport,
1130 OBJ_audacious_status,
1131 OBJ_audacious_title,
1132 OBJ_audacious_length,
1133 OBJ_audacious_length_seconds,
1134 OBJ_audacious_position,
1135 OBJ_audacious_position_seconds,
1136 OBJ_audacious_bitrate,
1137 OBJ_audacious_frequency,
1138 OBJ_audacious_channels,
1139 OBJ_audacious_filename,
1140 OBJ_audacious_playlist_length,
1141 OBJ_audacious_playlist_position,
1152 #ifdef TCP_PORT_MONITOR
1163 OBJ_entropy_poolsize,
1167 struct text_object {
1171 unsigned int c, d, e;
1175 char *s; /* some string */
1176 int i; /* some integer */
1177 long l; /* some other integer */
1178 unsigned int sensor;
1179 struct net_stat *net;
1181 unsigned char loadavg[3];
1182 unsigned int cpu_index;
1183 struct mail_s *mail;
1191 char *tz; /* timezone variable */
1192 char *fmt; /* time display formatting */
1245 timed_thread *p_timed_thread;
1251 #ifdef TCP_PORT_MONITOR
1253 in_port_t port_range_begin; /* starting port to monitor */
1254 in_port_t port_range_end; /* ending port to monitor */
1255 int item; /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1256 int connection_index; /* 0 to n-1 connections. */
1269 struct text_object_list {
1270 unsigned int text_object_count;
1271 struct text_object *text_objects;
1274 static unsigned int text_object_count;
1275 static struct text_object *text_objects;
1276 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1278 #define MAXDATASIZE 1000
1282 struct mail_s* parse_mail_args(char type, const char *arg) {
1283 struct mail_s *mail;
1284 mail = malloc(sizeof(struct mail_s));
1285 memset(mail, 0, sizeof(struct mail_s));
1287 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1289 ERR("Scanning IMAP args failed");
1290 } else if (type == IMAP) {
1291 ERR("Scanning POP3 args failed");
1294 // see if password needs prompting
1295 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1296 int fp = fileno(stdin);
1297 struct termios term;
1298 tcgetattr(fp, &term);
1299 term.c_lflag &= ~ECHO;
1300 tcsetattr(fp, TCSANOW, &term);
1301 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1302 scanf("%128s", mail->pass);
1304 term.c_lflag |= ECHO;
1305 tcsetattr(fp, TCSANOW, &term);
1307 // now we check for optional args
1308 tmp = strstr(arg, "-i ");
1311 sscanf(tmp, "%f", &mail->interval);
1313 mail->interval = 300; // 5 minutes
1315 tmp = strstr(arg, "-p ");
1318 sscanf(tmp, "%lu", &mail->port);
1321 mail->port = 110; // default pop3 port
1322 } else if (type == IMAP) {
1323 mail->port = 143; // default imap port
1327 tmp = strstr(arg, "-f ");
1330 sscanf(tmp, "%s", mail->folder);
1332 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1335 tmp = strstr(arg, "-e ");
1339 if (tmp[0] == '\'') {
1340 len = strstr(tmp+1, "'") - tmp - 1;
1345 strncpy(mail->command, tmp+1, len);
1347 mail->command[0] = '\0';
1349 mail->p_timed_thread = NULL;
1353 void *imap_thread(struct mail_s* mail)
1355 int sockfd, numbytes;
1356 char recvbuf[MAXDATASIZE];
1357 char sendbuf[MAXDATASIZE];
1360 unsigned int old_unseen = UINT_MAX;
1361 unsigned int old_messages = UINT_MAX;
1362 struct stat stat_buf;
1364 struct sockaddr_in their_addr; // connector's address information
1365 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1366 herror("gethostbyname");
1371 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1373 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1376 goto next_iteration;
1379 their_addr.sin_family = AF_INET; // host byte order
1380 their_addr.sin_port = htons(mail->port); // short, network byte order
1381 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1382 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1385 (sockfd, (struct sockaddr *) &their_addr,
1386 sizeof(struct sockaddr)) == -1) {
1389 goto next_iteration;
1391 struct timeval timeout;
1394 timeout.tv_sec = 60; // 60 second timeout i guess
1395 timeout.tv_usec = 0;
1397 FD_SET(sockfd, &fdset);
1398 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1401 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1405 goto next_iteration;
1408 ERR("IMAP connection failed: timeout");
1410 goto next_iteration;
1412 recvbuf[numbytes] = '\0';
1413 if (strstr(recvbuf, "* OK") != recvbuf) {
1414 ERR("IMAP connection failed, probably not an IMAP server");
1416 goto next_iteration;
1418 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1419 strncat(sendbuf, mail->user,
1420 MAXDATASIZE - strlen(sendbuf) - 1);
1421 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1422 strncat(sendbuf, mail->pass,
1423 MAXDATASIZE - strlen(sendbuf) - 1);
1424 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1425 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1428 goto next_iteration;
1430 timeout.tv_sec = 60; // 60 second timeout i guess
1431 timeout.tv_usec = 0;
1433 FD_SET(sockfd, &fdset);
1434 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1437 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1441 goto next_iteration;
1444 recvbuf[numbytes] = '\0';
1445 if (strstr(recvbuf, "a1 OK") == NULL) {
1446 ERR("IMAP server login failed: %s", recvbuf);
1448 goto next_iteration;
1450 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1451 strncat(sendbuf, mail->folder,
1452 MAXDATASIZE - strlen(sendbuf) - 1);
1453 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1454 MAXDATASIZE - strlen(sendbuf) - 1);
1455 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1458 goto next_iteration;
1460 timeout.tv_sec = 60; // 60 second timeout i guess
1461 timeout.tv_usec = 0;
1463 FD_SET(sockfd, &fdset);
1464 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1467 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1471 goto next_iteration;
1474 recvbuf[numbytes] = '\0';
1475 if (strstr(recvbuf, "a2 OK") == NULL) {
1476 ERR("IMAP status failed: %s", recvbuf);
1478 goto next_iteration;
1480 // now we get the data
1481 reply = strstr(recvbuf, " (MESSAGES ");
1483 *strchr(reply, ')') = '\0';
1484 if (reply == NULL) {
1485 ERR("Error parsing IMAP response: %s", recvbuf);
1487 goto next_iteration;
1489 timed_thread_lock (mail->p_timed_thread);
1490 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1493 timed_thread_unlock (mail->p_timed_thread);
1495 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1496 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1499 goto next_iteration;
1501 timeout.tv_sec = 60; // 60 second timeout i guess
1502 timeout.tv_usec = 0;
1504 FD_SET(sockfd, &fdset);
1505 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1508 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1512 goto next_iteration;
1515 recvbuf[numbytes] = '\0';
1516 if (strstr(recvbuf, "a3 OK") == NULL) {
1517 ERR("IMAP logout failed: %s", recvbuf);
1519 goto next_iteration;
1521 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1522 if (system(mail->command) == -1) {
1527 old_unseen = mail->unseen;
1528 old_messages = mail->messages;
1530 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1531 /* if a valid socket, close it */
1533 if (timed_thread_test (mail->p_timed_thread))
1534 timed_thread_exit (mail->p_timed_thread);
1539 void *pop3_thread(struct mail_s *mail)
1541 int sockfd, numbytes;
1542 char recvbuf[MAXDATASIZE];
1543 char sendbuf[MAXDATASIZE];
1546 unsigned int old_unseen = UINT_MAX;
1547 struct stat stat_buf;
1549 struct sockaddr_in their_addr; // connector's address information
1550 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1551 herror("gethostbyname");
1556 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1558 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1561 goto next_iteration;
1564 their_addr.sin_family = AF_INET; // host byte order
1565 their_addr.sin_port = htons(mail->port); // short, network byte order
1566 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1567 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1570 (sockfd, (struct sockaddr *) &their_addr,
1571 sizeof(struct sockaddr)) == -1) {
1574 goto next_iteration;
1576 struct timeval timeout;
1579 timeout.tv_sec = 60; // 60 second timeout i guess
1580 timeout.tv_usec = 0;
1582 FD_SET(sockfd, &fdset);
1583 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1586 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1590 goto next_iteration;
1593 ERR("POP3 connection failed: timeout\n");
1595 goto next_iteration;
1597 recvbuf[numbytes] = '\0';
1598 if (strstr(recvbuf, "+OK ") != recvbuf) {
1599 ERR("POP3 connection failed, probably not a POP3 server");
1601 goto next_iteration;
1603 strncpy(sendbuf, "USER ", MAXDATASIZE);
1604 strncat(sendbuf, mail->user,
1605 MAXDATASIZE - strlen(sendbuf) - 1);
1606 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1607 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1608 perror("send USER");
1610 goto next_iteration;
1612 timeout.tv_sec = 60; // 60 second timeout i guess
1613 timeout.tv_usec = 0;
1615 FD_SET(sockfd, &fdset);
1616 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1619 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1621 perror("recv USER");
1623 goto next_iteration;
1626 recvbuf[numbytes] = '\0';
1627 if (strstr(recvbuf, "+OK ") == NULL) {
1628 ERR("POP3 server login failed: %s", recvbuf);
1630 goto next_iteration;
1632 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1633 strncat(sendbuf, mail->pass,
1634 MAXDATASIZE - strlen(sendbuf) - 1);
1635 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1636 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1637 perror("send PASS");
1639 goto next_iteration;
1641 timeout.tv_sec = 60; // 60 second timeout i guess
1642 timeout.tv_usec = 0;
1644 FD_SET(sockfd, &fdset);
1645 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1648 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1650 perror("recv PASS");
1652 goto next_iteration;
1655 recvbuf[numbytes] = '\0';
1656 if (strstr(recvbuf, "+OK ") == NULL) {
1657 ERR("POP3 server login failed: %s", recvbuf);
1659 goto next_iteration;
1661 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1662 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1663 perror("send STAT");
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 STAT");
1678 goto next_iteration;
1681 recvbuf[numbytes] = '\0';
1682 if (strstr(recvbuf, "+OK ") == NULL) {
1683 ERR("POP3 status failed: %s", recvbuf);
1685 goto next_iteration;
1687 // now we get the data
1688 reply = recvbuf + 4;
1689 if (reply == NULL) {
1690 ERR("Error parsing POP3 response: %s", recvbuf);
1692 goto next_iteration;
1694 timed_thread_lock (mail->p_timed_thread);
1695 sscanf(reply, "%lu %lu", &mail->unseen,
1697 timed_thread_unlock (mail->p_timed_thread);
1699 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1700 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1701 perror("send QUIT");
1703 goto next_iteration;
1705 timeout.tv_sec = 60; // 60 second timeout i guess
1706 timeout.tv_usec = 0;
1708 FD_SET(sockfd, &fdset);
1709 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1712 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1714 perror("recv QUIT");
1716 goto next_iteration;
1719 recvbuf[numbytes] = '\0';
1720 if (strstr(recvbuf, "+OK") == NULL) {
1721 ERR("POP3 logout failed: %s", recvbuf);
1723 goto next_iteration;
1725 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1726 if (system(mail->command) == -1) {
1731 old_unseen = mail->unseen;
1733 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1734 /* if a valid socket, close it */
1736 if (timed_thread_test (mail->p_timed_thread))
1737 timed_thread_exit (mail->p_timed_thread);
1743 void *threaded_exec(struct text_object *obj) {
1745 char *p2 = obj->data.texeci.buffer;
1746 FILE *fp = popen(obj->data.texeci.cmd,"r");
1747 timed_thread_lock (obj->data.texeci.p_timed_thread);
1748 int n2 = fread(p2, 1, text_buffer_size, fp);
1751 if (n2 && p2[n2 - 1] == '\n') {
1755 if (*p2 == '\001') {
1760 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1761 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1762 timed_thread_exit (obj->data.texeci.p_timed_thread);
1767 static struct text_object *new_text_object_internal()
1769 struct text_object *obj = malloc(sizeof(struct text_object));
1770 memset(obj, 0, sizeof(struct text_object));
1774 static void free_text_objects(unsigned int count, struct text_object *objs)
1777 for (i = 0; i < count; i++) {
1778 switch (objs[i].type) {
1780 close(objs[i].data.i);
1783 close(objs[i].data.i);
1786 close(objs[i].data.i2c.fd);
1789 free(objs[i].data.s);
1792 free(objs[i].data.s);
1795 free(objs[i].data.tztime.tz);
1796 free(objs[i].data.tztime.fmt);
1799 free(objs[i].data.mboxscan.args);
1800 free(objs[i].data.mboxscan.output);
1805 case OBJ_imap_unseen:
1806 if (!objs[i].global_mode) {
1807 free(objs[i].data.mail);
1810 case OBJ_imap_messages:
1811 if (!objs[i].global_mode) {
1812 free(objs[i].data.mail);
1818 case OBJ_pop3_unseen:
1819 if (!objs[i].global_mode) {
1820 free(objs[i].data.mail);
1824 if (!objs[i].global_mode) {
1825 free(objs[i].data.mail);
1829 case OBJ_if_existing:
1830 case OBJ_if_mounted:
1831 case OBJ_if_running:
1832 free(objs[i].data.ifblock.s);
1833 free(objs[i].data.ifblock.str);
1836 free(objs[i].data.tail.logfile);
1837 free(objs[i].data.tail.buffer);
1839 case OBJ_text: case OBJ_font:
1840 free(objs[i].data.s);
1843 free(objs[i].data.s);
1846 free(objs[i].data.s);
1849 free(objs[i].data.s);
1852 free(objs[i].data.s);
1854 /* case OBJ_execibar:
1855 free(objs[i].data.s);
1857 case OBJ_execigraph:
1858 free(objs[i].data.s);
1861 case OBJ_iconv_start:
1867 if (info.mpd.title) {
1868 free(info.mpd.title);
1872 case OBJ_mpd_artist:
1873 if (info.mpd.artist) {
1874 free(info.mpd.artist);
1875 info.mpd.artist = 0;
1879 if (info.mpd.album) {
1880 free(info.mpd.album);
1884 case OBJ_mpd_random:
1885 if (info.mpd.random) {
1886 free(info.mpd.random);
1887 info.mpd.random = 0;
1890 case OBJ_mpd_repeat:
1891 if (info.mpd.repeat) {
1892 free(info.mpd.repeat);
1893 info.mpd.repeat = 0;
1897 if (info.mpd.track) {
1898 free(info.mpd.track);
1903 if (info.mpd.name) {
1904 free(info.mpd.name);
1909 if (info.mpd.file) {
1910 free(info.mpd.file);
1914 case OBJ_mpd_status:
1915 if (info.mpd.status) {
1916 free(info.mpd.status);
1917 info.mpd.status = 0;
1921 if (info.mpd.artist) {
1922 free(info.mpd.artist);
1923 info.mpd.artist = 0;
1925 if (info.mpd.title) {
1926 free(info.mpd.title);
1929 if (info.mpd.file) {
1930 free(info.mpd.file);
1937 case OBJ_xmms2_artist:
1938 if (info.xmms2.artist) {
1939 free(info.xmms2.artist);
1940 info.xmms2.artist = 0;
1943 case OBJ_xmms2_album:
1944 if (info.xmms2.album) {
1945 free(info.xmms2.album);
1946 info.xmms2.album = 0;
1949 case OBJ_xmms2_title:
1950 if (info.xmms2.title) {
1951 free(info.xmms2.title);
1952 info.xmms2.title = 0;
1955 case OBJ_xmms2_genre:
1956 if (info.xmms2.genre) {
1957 free(info.xmms2.genre);
1958 info.xmms2.genre = 0;
1961 case OBJ_xmms2_comment:
1962 if (info.xmms2.comment) {
1963 free(info.xmms2.comment);
1964 info.xmms2.comment = 0;
1967 case OBJ_xmms2_decoder:
1968 if (info.xmms2.decoder) {
1969 free(info.xmms2.decoder);
1973 case OBJ_xmms2_transport:
1974 if (info.xmms2.transport) {
1975 free(info.xmms2.transport);
1980 if (info.xmms2.url) {
1981 free(info.xmms2.url);
1985 case OBJ_xmms2_date:
1986 if (info.xmms2.date) {
1987 free(info.xmms2.date);
1988 info.xmms2.date = 0;
1991 case OBJ_xmms2_status:
1992 if (info.xmms2.status) {
1993 free(info.xmms2.status);
1994 info.xmms2.status = 0;
1997 case OBJ_xmms2_smart:
1998 if (info.xmms2.artist) {
1999 free(info.xmms2.artist);
2000 info.xmms2.artist = 0;
2002 if (info.xmms2.title) {
2003 free(info.xmms2.title);
2004 info.xmms2.title = 0;
2006 if (info.xmms2.url) {
2007 free(info.xmms2.url);
2013 case OBJ_bmpx_title:
2014 case OBJ_bmpx_artist:
2015 case OBJ_bmpx_album:
2016 case OBJ_bmpx_track:
2018 case OBJ_bmpx_bitrate:
2022 free(objs[i].data.s);
2024 case OBJ_battery_time:
2025 free(objs[i].data.s);
2028 free(objs[i].data.execi.cmd);
2029 free(objs[i].data.execi.buffer);
2032 free(objs[i].data.texeci.cmd);
2033 free(objs[i].data.texeci.buffer);
2036 if (info.first_process) {
2037 free_all_processes();
2038 info.first_process = NULL;
2042 if (info.first_process) {
2043 free_all_processes();
2044 info.first_process = NULL;
2049 free(objs[i].data.hddtemp.dev);
2050 free(objs[i].data.hddtemp.addr);
2053 case OBJ_entropy_avail:
2054 case OBJ_entropy_poolsize:
2055 case OBJ_entropy_bar:
2060 //text_objects = NULL;
2061 //text_object_count = 0;
2064 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2069 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2070 *a = mixer_init(buf1);
2071 (void) scan_bar(arg + n, w, h);
2074 (void) scan_bar(arg, w, h);
2079 /* construct_text_object() creates a new text_object */
2080 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2082 //struct text_object *obj = new_text_object();
2083 struct text_object *obj = new_text_object_internal();
2086 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2087 #define END ; } } else
2091 obj->type = OBJ_color;
2092 obj->data.l = get_x11_color(s);
2095 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2096 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2097 END OBJ(acpiacadapter, 0)
2098 END OBJ(freq, INFO_FREQ)
2104 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2106 obj->data.cpu_index=1;
2107 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2111 obj->data.cpu_index=atoi(&arg[0]);
2114 END OBJ(freq_g, INFO_FREQ)
2120 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2122 obj->data.cpu_index=1;
2123 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2127 obj->data.cpu_index=atoi(&arg[0]);
2130 #if defined(__linux__)
2131 END OBJ(voltage_mv, 0)
2137 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2139 obj->data.cpu_index=1;
2140 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2144 obj->data.cpu_index=atoi(&arg[0]);
2147 END OBJ(voltage_v, 0)
2153 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2155 obj->data.cpu_index=1;
2156 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2160 obj->data.cpu_index=atoi(&arg[0]);
2163 #endif /* __linux__ */
2164 END OBJ(freq_dyn, 0);
2165 END OBJ(freq_dyn_g, 0);
2166 END OBJ(acpifan, 0);
2167 END OBJ(battery, 0);
2170 sscanf(arg, "%63s", bat);
2172 strcpy(bat, "BAT0");
2173 obj->data.s = strdup(bat);
2174 END OBJ(battery_time, 0);
2177 sscanf(arg, "%63s", bat);
2179 strcpy(bat, "BAT0");
2180 obj->data.s = strdup(bat);
2181 END OBJ(battery_percent, 0);
2184 sscanf(arg, "%63s", bat);
2186 strcpy(bat, "BAT0");
2187 obj->data.s = strdup(bat);
2188 END OBJ(battery_bar, 0);
2191 arg = scan_bar(arg, &obj->a, &obj->b);
2192 sscanf(arg, "%63s", bat);
2194 strcpy(bat, "BAT0");
2196 #if defined(__linux__)
2197 END OBJ(i8k_version, INFO_I8K)
2198 END OBJ(i8k_bios, INFO_I8K)
2199 END OBJ(i8k_serial, INFO_I8K)
2200 END OBJ(i8k_cpu_temp, INFO_I8K)
2201 END OBJ(i8k_cpu_tempf, INFO_I8K)
2202 END OBJ(i8k_left_fan_status, INFO_I8K)
2203 END OBJ(i8k_right_fan_status, INFO_I8K)
2204 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2205 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2206 END OBJ(i8k_ac_status, INFO_I8K)
2207 END OBJ(i8k_buttons_status, INFO_I8K)
2209 END OBJ(ibm_temps, 0)
2211 CRIT_ERR("ibm_temps: needs an argument");
2213 if (!isdigit(arg[0])
2215 || atoi(&arg[0]) >=8)
2218 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2220 obj->data.sensor = atoi(&arg[0]);
2221 END OBJ(ibm_volume, 0)
2222 END OBJ(ibm_brightness, 0)
2223 END OBJ(pb_battery, 0)
2224 if (arg && strcmp(arg, "status") == 0) {
2225 obj->data.i = PB_BATT_STATUS;
2226 } else if (arg && strcmp(arg, "percent") == 0) {
2227 obj->data.i = PB_BATT_PERCENT;
2228 } else if (arg && strcmp(arg, "time") == 0) {
2229 obj->data.i = PB_BATT_TIME;
2231 ERR("pb_battery: needs one argument: status, percent or time");
2236 #endif /* __linux__ */
2237 #if defined(__OpenBSD__)
2238 END OBJ(obsd_sensors_temp, 0);
2240 CRIT_ERR("obsd_sensors_temp: needs an argument");
2242 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2244 ERR("Invalid temperature sensor number!");
2246 obj->data.sensor = atoi(&arg[0]);
2247 END OBJ(obsd_sensors_fan, 0);
2249 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor number)");
2251 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2253 ERR("Invalid fan sensor number!");
2255 obj->data.sensor = atoi(&arg[0]);
2256 END OBJ(obsd_sensors_volt, 0);
2258 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor number)");
2260 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2262 ERR("Invalid voltage sensor number!");
2264 obj->data.sensor = atoi(&arg[0]);
2265 END OBJ(obsd_vendor, 0);
2266 END OBJ(obsd_product, 0);
2267 #endif /* __OpenBSD__ */
2268 END OBJ(buffers, INFO_BUFFERS)
2269 END OBJ(cached, INFO_BUFFERS)
2270 END OBJ(cpu, INFO_CPU)
2272 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2273 obj->data.cpu_index = atoi(&arg[3]);
2275 } else {obj->data.cpu_index = 0; }
2277 obj->data.cpu_index = 0;
2279 END OBJ(cpubar, INFO_CPU)
2281 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2282 obj->data.cpu_index = atoi(&arg[3]);
2285 else {obj->data.cpu_index = 0;}
2286 (void) scan_bar(arg, &obj->a, &obj->b);
2288 (void) scan_bar(arg, &obj->a, &obj->b);
2289 obj->data.cpu_index = 0;
2291 END OBJ(cpugraph, INFO_CPU)
2293 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2294 obj->data.cpu_index = atoi(&arg[3]);
2297 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2299 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2300 obj->data.cpu_index = 0;
2302 END OBJ(diskio, INFO_DISKIO)
2303 END OBJ(diskio_read, INFO_DISKIO)
2304 END OBJ(diskio_write, INFO_DISKIO)
2305 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2306 END OBJ(diskiograph_read, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2307 END OBJ(diskiograph_write, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2310 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2314 obj->data.s = scan_font(arg);
2316 OBJ(downspeed, INFO_NET)
2318 obj->data.net = get_net_stat(arg);
2321 CRIT_ERR("downspeed needs argument");
2323 END OBJ(downspeedf, INFO_NET)
2325 obj->data.net = get_net_stat(arg);
2328 CRIT_ERR("downspeedf needs argument");
2330 END OBJ(downspeedgraph, INFO_NET)
2331 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2333 sscanf(arg, "%63s %*i,%*i %*i", buf);
2334 obj->data.net = get_net_stat(buf);
2335 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2336 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
2343 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2344 blockstart[blockdepth - 1] = object_count;
2345 obj->data.ifblock.pos = object_count + 2;
2347 ERR("$else: no matching $if_*");
2352 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2354 ERR("$endif: no matching $if_*");
2357 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2360 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2361 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2362 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2363 END OBJ(execibar, 0) unsigned int n;
2364 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2366 ERR("${execibar <interval> command}");
2367 obj->type = OBJ_text;
2368 snprintf(buf, 256, "${%s}", s);
2369 obj->data.s = strdup(buf);
2371 obj->data.execi.cmd = strdup(arg + n);
2373 END OBJ(execigraph, 0) unsigned int n;
2374 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2376 ERR("${execigraph <interval> command}");
2377 obj->type = OBJ_text;
2378 snprintf(buf, 256, "${%s}", s);
2379 obj->data.s = strdup(buf);
2381 obj->data.execi.cmd = strdup(arg + n);
2383 END OBJ(execi, 0) unsigned int n;
2384 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2386 ERR("${execi <interval> command}");
2387 obj->type = OBJ_text;
2388 snprintf(buf, 256, "${%s}", s);
2389 obj->data.s = strdup(buf);
2391 obj->data.execi.cmd = strdup(arg + n);
2392 obj->data.execi.buffer =
2393 (char *) calloc(1, text_buffer_size);
2395 END OBJ(texeci, 0) unsigned int n;
2396 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2398 ERR("${texeci <interval> command}");
2399 obj->type = OBJ_text;
2400 snprintf(buf, 256, "${%s}", s);
2401 obj->data.s = strdup(buf);
2403 obj->data.texeci.cmd = strdup(arg + n);
2404 obj->data.texeci.buffer =
2405 (char *) calloc(1, text_buffer_size);
2407 obj->data.texeci.p_timed_thread = NULL;
2408 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2410 FILE *fp = popen(arg, "r");
2414 n = fread(buf, 1, 2048, fp);
2417 if (n && buf[n - 1] == '\n')
2422 obj->data.s = strdup(buf);
2424 obj->data.s = strdup("");
2427 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2428 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2430 while (isspace(*arg))
2436 obj->data.fsbar.fs = prepare_fs_stat(arg);
2437 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2440 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2444 obj->data.fsbar.fs = prepare_fs_stat(arg);
2445 END OBJ(fs_free, INFO_FS) if (!arg)
2447 obj->data.fs = prepare_fs_stat(arg);
2448 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2450 obj->data.fs = prepare_fs_stat(arg);
2451 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2453 obj->data.fs = prepare_fs_stat(arg);
2454 END OBJ(fs_size, INFO_FS) if (!arg)
2456 obj->data.fs = prepare_fs_stat(arg);
2457 END OBJ(fs_used, INFO_FS) if (!arg)
2459 obj->data.fs = prepare_fs_stat(arg);
2460 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2461 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2462 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2466 ERR("goto needs arguments");
2467 obj->type = OBJ_text;
2468 obj->data.s = strdup("${goto}");
2472 obj->data.i = atoi(arg);
2477 if (sscanf(arg, "%d %d", &a, &b) != 2)
2478 sscanf(arg, "%d", &b);
2482 obj->data.pair.a = a;
2483 obj->data.pair.b = b;
2485 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
2489 ERR("i2c needs arguments");
2490 obj->type = OBJ_text;
2491 //obj->data.s = strdup("${i2c}");
2495 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2496 /* if scanf couldn't read three values, read type and num and use
2498 sscanf(arg, "%63s %d", buf2, &n);
2500 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
2501 obj->data.i2c.devtype);
2502 strncpy(obj->data.i2c.type, buf2, 63);
2505 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
2506 obj->data.i2c.devtype);
2507 strncpy(obj->data.i2c.type, buf2, 63);
2510 END OBJ(top, INFO_TOP)
2514 ERR("top needs arguments");
2515 obj->type = OBJ_text;
2516 //obj->data.s = strdup("${top}");
2519 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2520 if (strcmp(buf, "name") == 0) {
2521 obj->data.top.type = TOP_NAME;
2522 } else if (strcmp(buf, "cpu") == 0) {
2523 obj->data.top.type = TOP_CPU;
2524 } else if (strcmp(buf, "pid") == 0) {
2525 obj->data.top.type = TOP_PID;
2526 } else if (strcmp(buf, "mem") == 0) {
2527 obj->data.top.type = TOP_MEM;
2529 ERR("invalid arg for top");
2532 if (n < 1 || n > 10) {
2533 CRIT_ERR("invalid arg for top");
2536 obj->data.top.num = n - 1;
2540 ERR("invalid args given for top");
2543 END OBJ(top_mem, INFO_TOP)
2547 ERR("top_mem needs arguments");
2548 obj->type = OBJ_text;
2549 obj->data.s = strdup("${top_mem}");
2552 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2553 if (strcmp(buf, "name") == 0) {
2554 obj->data.top.type = TOP_NAME;
2555 } else if (strcmp(buf, "cpu") == 0) {
2556 obj->data.top.type = TOP_CPU;
2557 } else if (strcmp(buf, "pid") == 0) {
2558 obj->data.top.type = TOP_PID;
2559 } else if (strcmp(buf, "mem") == 0) {
2560 obj->data.top.type = TOP_MEM;
2562 ERR("invalid arg for top");
2565 if (n < 1 || n > 10) {
2566 CRIT_ERR("invalid arg for top");
2569 obj->data.top.num = n - 1;
2573 ERR("invalid args given for top");
2576 END OBJ(addr, INFO_NET)
2578 obj->data.net = get_net_stat(arg);
2581 CRIT_ERR("addr needs argument");
2583 END OBJ(linkstatus, INFO_WIFI)
2585 obj->data.net = get_net_stat(arg);
2588 CRIT_ERR("linkstatus needs argument");
2594 ERR("tail needs arguments");
2595 obj->type = OBJ_text;
2596 obj->data.s = strdup("${tail}");
2599 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2600 if (n1 < 1 || n1 > 30) {
2601 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2605 fp = fopen(buf, "r");
2607 obj->data.tail.logfile =
2608 malloc(text_buffer_size);
2609 strcpy(obj->data.tail.logfile, buf);
2610 obj->data.tail.wantedlines = n1;
2611 obj->data.tail.interval =
2612 update_interval * 2;
2616 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2619 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2620 if (n1 < 1 || n1 > 30) {
2622 ("invalid arg for tail, number of lines must be between 1 and 30");
2624 } else if (n2 < 1 || n2 < update_interval) {
2626 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2630 fp = fopen(buf, "r");
2632 obj->data.tail.logfile =
2633 malloc(text_buffer_size);
2634 strcpy(obj->data.tail.logfile, buf);
2635 obj->data.tail.wantedlines = n1;
2636 obj->data.tail.interval = n2;
2640 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2646 ERR("invalid args given for tail");
2649 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2654 ERR("head needs arguments");
2655 obj->type = OBJ_text;
2656 obj->data.s = strdup("${head}");
2659 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2660 if (n1 < 1 || n1 > 30) {
2661 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2665 fp = fopen(buf, "r");
2667 obj->data.tail.logfile =
2668 malloc(text_buffer_size);
2669 strcpy(obj->data.tail.logfile, buf);
2670 obj->data.tail.wantedlines = n1;
2671 obj->data.tail.interval =
2672 update_interval * 2;
2676 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2679 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2680 if (n1 < 1 || n1 > 30) {
2682 ("invalid arg for head, number of lines must be between 1 and 30");
2684 } else if (n2 < 1 || n2 < update_interval) {
2686 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2690 fp = fopen(buf, "r");
2692 obj->data.tail.logfile =
2693 malloc(text_buffer_size);
2694 strcpy(obj->data.tail.logfile, buf);
2695 obj->data.tail.wantedlines = n1;
2696 obj->data.tail.interval = n2;
2700 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2706 ERR("invalid args given for head");
2709 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2710 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2712 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2713 if (r >= 3 && (c < 1 || c > 3))
2715 if (r >= 2 && (b < 1 || b > 3))
2717 if (r >= 1 && (a < 1 || a > 3))
2720 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2721 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2722 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2723 END OBJ(if_empty, 0)
2724 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2725 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2728 ERR("if_empty needs an argument");
2729 obj->data.ifblock.s = 0;
2731 obj->data.ifblock.s = strdup(arg);
2732 blockstart[blockdepth] = object_count;
2733 obj->data.ifblock.pos = object_count + 2;
2735 END OBJ(if_existing, 0)
2736 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2737 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2740 ERR("if_existing needs an argument or two");
2741 obj->data.ifblock.s = NULL;
2742 obj->data.ifblock.str = NULL;
2744 char buf1[256], buf2[256];
2745 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2747 obj->data.ifblock.s = strdup(buf1);
2748 obj->data.ifblock.str = NULL;
2750 obj->data.ifblock.s = strdup(buf1);
2751 obj->data.ifblock.str = strdup(buf2);
2754 blockstart[blockdepth] = object_count;
2755 obj->data.ifblock.pos = object_count + 2;
2757 END OBJ(if_mounted, 0)
2758 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2759 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2762 ERR("if_mounted needs an argument");
2763 obj->data.ifblock.s = 0;
2765 obj->data.ifblock.s = strdup(arg);
2766 blockstart[blockdepth] = object_count;
2767 obj->data.ifblock.pos = object_count + 2;
2769 END OBJ(if_running, 0)
2770 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2771 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2775 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2776 obj->data.ifblock.s = strdup(buf);
2778 ERR("if_running needs an argument");
2779 obj->data.ifblock.s = 0;
2781 blockstart[blockdepth] = object_count;
2782 obj->data.ifblock.pos = object_count + 2;
2786 END OBJ(mails, INFO_MAIL)
2787 END OBJ(mboxscan, 0)
2788 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
2789 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
2790 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2791 obj->data.mboxscan.output[0] = 1;
2792 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
2793 END OBJ(mem, INFO_MEM)
2794 END OBJ(memmax, INFO_MEM)
2795 END OBJ(memperc, INFO_MEM)
2796 END OBJ(membar, INFO_MEM)
2797 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2798 END OBJ(memgraph, INFO_MEM)
2799 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2800 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2801 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2802 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2803 END OBJ(mixerbar, INFO_MIXER)
2804 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2805 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2806 END OBJ(mixerlbar, INFO_MIXER)
2807 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2808 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2809 END OBJ(mixerrbar, INFO_MIXER)
2810 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2811 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2813 OBJ(new_mails, INFO_MAIL)
2814 END OBJ(nodename, 0)
2815 END OBJ(processes, INFO_PROCS)
2816 END OBJ(running_processes, INFO_RUN_PROCS)
2817 END OBJ(shadecolor, 0)
2819 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2821 END OBJ(outlinecolor, 0)
2823 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2825 END OBJ(stippled_hr, 0)
2827 int a = stippled_borders, b = 1;
2829 if (sscanf(arg, "%d %d", &a, &b) != 2)
2830 sscanf(arg, "%d", &b);
2834 obj->data.pair.a = a;
2835 obj->data.pair.b = b;
2837 END OBJ(swap, INFO_MEM)
2838 END OBJ(swapmax, INFO_MEM)
2839 END OBJ(swapperc, INFO_MEM)
2840 END OBJ(swapbar, INFO_MEM)
2841 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2842 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
2844 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
2845 obj->data.i2c.devtype);
2846 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
2848 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
2849 obj->data.i2c.devtype);
2850 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2851 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2853 char buf1[256], buf2[256], *fmt, *tz;
2856 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2865 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
2866 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
2868 END OBJ(iconv_start, 0)
2869 if (iconv_converting) {
2870 CRIT_ERR("You must stop your last iconv conversion before starting another");
2873 char iconv_from[CODEPAGE_LENGTH];
2874 char iconv_to[CODEPAGE_LENGTH];
2875 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2876 CRIT_ERR("Invalid arguments for iconv_start");
2879 new_iconv = iconv_open(iconv_to, iconv_from);
2880 if (new_iconv == (iconv_t)(-1)) {
2881 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2883 obj->a = register_iconv(&new_iconv);
2884 iconv_converting = 1;
2888 CRIT_ERR("Iconv requires arguments");
2890 END OBJ(iconv_stop, 0)
2891 iconv_converting = 0;
2894 END OBJ(totaldown, INFO_NET)
2896 obj->data.net = get_net_stat(arg);
2899 CRIT_ERR("totaldown needs argument");
2901 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
2903 obj->data.net = get_net_stat(arg);
2906 CRIT_ERR("totalup needs argument");
2909 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
2910 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
2911 END OBJ(upspeed, INFO_NET)
2913 obj->data.net = get_net_stat(arg);
2916 CRIT_ERR("upspeed needs argument");
2918 END OBJ(upspeedf, INFO_NET)
2920 obj->data.net = get_net_stat(arg);
2923 CRIT_ERR("upspeedf needs argument");
2926 END OBJ(upspeedgraph, INFO_NET)
2927 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2929 sscanf(arg, "%63s %*i,%*i %*i", buf);
2930 obj->data.net = get_net_stat(buf);
2931 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2932 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
2937 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
2938 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
2939 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
2940 OBJ(apm_adapter, 0) END
2941 OBJ(apm_battery_life, 0) END
2942 OBJ(apm_battery_time, 0) END
2943 #endif /* __FreeBSD__ */
2947 obj->data.mail = parse_mail_args(IMAP, arg);
2948 obj->global_mode = 0;
2950 obj->global_mode = 1;
2953 OBJ(imap_messages, 0)
2956 obj->data.mail = parse_mail_args(IMAP, arg);
2957 obj->global_mode = 0;
2959 obj->global_mode = 1;
2965 obj->data.mail = parse_mail_args(POP3, arg);
2966 obj->global_mode = 0;
2968 obj->global_mode = 1;
2974 obj->data.mail = parse_mail_args(POP3, arg);
2975 obj->global_mode = 0;
2977 obj->global_mode = 1;
2981 OBJ(mpd_artist, INFO_MPD)
2982 END OBJ(mpd_title, INFO_MPD)
2983 END OBJ(mpd_random, INFO_MPD)
2984 END OBJ(mpd_repeat, INFO_MPD)
2985 END OBJ(mpd_elapsed, INFO_MPD)
2986 END OBJ(mpd_length, INFO_MPD)
2987 END OBJ(mpd_track, INFO_MPD)
2988 END OBJ(mpd_name, INFO_MPD)
2989 END OBJ(mpd_file, INFO_MPD)
2990 END OBJ(mpd_percent, INFO_MPD)
2991 END OBJ(mpd_album, INFO_MPD)
2992 END OBJ(mpd_vol, INFO_MPD)
2993 END OBJ(mpd_bitrate, INFO_MPD)
2994 END OBJ(mpd_status, INFO_MPD)
2995 END OBJ(mpd_bar, INFO_MPD)
2996 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2997 END OBJ(mpd_smart, INFO_MPD) END
3000 OBJ(xmms2_artist, INFO_XMMS2)
3001 END OBJ(xmms2_album, INFO_XMMS2)
3002 END OBJ(xmms2_title, INFO_XMMS2)
3003 END OBJ(xmms2_genre, INFO_XMMS2)
3004 END OBJ(xmms2_comment, INFO_XMMS2)
3005 END OBJ(xmms2_decoder, INFO_XMMS2)
3006 END OBJ(xmms2_transport, INFO_XMMS2)
3007 END OBJ(xmms2_url, INFO_XMMS2)
3008 END OBJ(xmms2_tracknr, INFO_XMMS2)
3009 END OBJ(xmms2_bitrate, INFO_XMMS2)
3010 END OBJ(xmms2_date, INFO_XMMS2)
3011 END OBJ(xmms2_id, INFO_XMMS2)
3012 END OBJ(xmms2_duration, INFO_XMMS2)
3013 END OBJ(xmms2_elapsed, INFO_XMMS2)
3014 END OBJ(xmms2_size, INFO_XMMS2)
3015 END OBJ(xmms2_status, INFO_XMMS2)
3016 END OBJ(xmms2_percent, INFO_XMMS2)
3017 END OBJ(xmms2_bar, INFO_XMMS2)
3018 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3019 END OBJ(xmms2_smart, INFO_XMMS2)
3023 OBJ(audacious_status, INFO_AUDACIOUS) END
3024 OBJ(audacious_title, INFO_AUDACIOUS)
3028 sscanf (arg, "%d", &info.audacious.max_title_len);
3029 if (info.audacious.max_title_len > 0)
3030 info.audacious.max_title_len++;
3032 CRIT_ERR ("audacious_title: invalid length argument");
3036 OBJ(audacious_length, INFO_AUDACIOUS) END
3037 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3038 OBJ(audacious_position, INFO_AUDACIOUS) END
3039 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3040 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3041 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3042 OBJ(audacious_channels, INFO_AUDACIOUS) END
3043 OBJ(audacious_filename, INFO_AUDACIOUS) END
3044 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3045 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3046 OBJ(audacious_bar, INFO_AUDACIOUS)
3047 (void) scan_bar(arg, &obj->a, &obj->b);
3051 OBJ(bmpx_title, INFO_BMPX)
3052 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3054 OBJ(bmpx_artist, INFO_BMPX)
3055 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3057 OBJ(bmpx_album, INFO_BMPX)
3058 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3060 OBJ(bmpx_track, INFO_BMPX)
3061 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3063 OBJ(bmpx_uri, INFO_BMPX)
3064 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3066 OBJ(bmpx_bitrate, INFO_BMPX)
3067 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3072 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3073 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3074 ERR("hddtemp needs arguments");
3075 obj->type = OBJ_text;
3076 obj->data.s = strdup("${hddtemp}");
3081 #ifdef TCP_PORT_MONITOR
3082 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3083 int argc, port_begin, port_end, item, connection_index;
3085 memset(itembuf,0,sizeof(itembuf));
3087 /* massive argument checking */
3089 CRIT_ERR("tcp_portmon: needs arguments");
3091 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3092 if ( (argc != 3) && (argc != 4) )
3094 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3096 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3098 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3100 if ( port_begin > port_end )
3102 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3104 if ( strncmp(itembuf,"count",31) == 0 )
3106 else if ( strncmp(itembuf,"rip",31) == 0 )
3108 else if ( strncmp(itembuf,"rhost",31) == 0 )
3110 else if ( strncmp(itembuf,"rport",31) == 0 )
3112 else if ( strncmp(itembuf,"rservice",31) == 0 )
3114 else if ( strncmp(itembuf,"lip",31) == 0 )
3116 else if ( strncmp(itembuf,"lhost",31) == 0 )
3118 else if ( strncmp(itembuf,"lport",31) == 0 )
3120 else if ( strncmp(itembuf,"lservice",31) == 0 )
3124 CRIT_ERR("tcp_portmon: invalid item specified");
3126 if ( (argc==3) && (item!=COUNT) )
3128 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3130 if ( (argc==4) && (connection_index<0) )
3132 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3134 /* ok, args looks good. save the text object data */
3135 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3136 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3137 obj->data.tcp_port_monitor.item = item;
3138 obj->data.tcp_port_monitor.connection_index = connection_index;
3140 /* if the port monitor collection hasn't been created, we must create it */
3141 if ( !info.p_tcp_port_monitor_collection )
3143 info.p_tcp_port_monitor_collection =
3144 create_tcp_port_monitor_collection ();
3145 if ( !info.p_tcp_port_monitor_collection )
3147 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3151 /* if a port monitor for this port does not exist, create one and add it to the collection */
3152 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3154 tcp_port_monitor_t * p_monitor =
3155 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3158 CRIT_ERR("tcp_portmon: unable to create port monitor");
3160 /* add the newly created monitor to the collection */
3161 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3164 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3169 OBJ(entropy_avail, INFO_ENTROPY) END
3170 OBJ(entropy_poolsize, INFO_ENTROPY) END
3171 OBJ(entropy_bar, INFO_ENTROPY)
3172 (void) scan_bar(arg, &obj->a, &obj->b);
3177 ERR("unknown variable %s", s);
3178 obj->type = OBJ_text;
3179 snprintf(buf, 256, "${%s}", s);
3180 obj->data.s = strdup(buf);
3187 static struct text_object *create_plain_text(const char *s)
3189 struct text_object *obj;
3191 if (s == NULL || *s == '\0') {
3195 obj = new_text_object_internal();
3197 obj->type = OBJ_text;
3198 obj->data.s = strdup(s);
3202 static struct text_object_list *extract_variable_text_internal(const char *p)
3204 struct text_object_list *retval;
3205 struct text_object *obj;
3208 retval = malloc(sizeof(struct text_object_list));
3209 memset(retval, 0, sizeof(struct text_object_list));
3210 retval->text_object_count = 0;
3212 long line = text_lines;
3220 obj = create_plain_text(s);
3222 // allocate memory for the object
3223 retval->text_objects = realloc(retval->text_objects,
3224 sizeof(struct text_object) * (retval->text_object_count+1));
3225 // assign the new object to the end of the list.
3226 memcpy(&retval->text_objects[retval->text_object_count++],
3227 obj, sizeof(struct text_object));
3239 /* variable is either $foo or ${foo} */
3241 unsigned int brl = 1, brr = 0;
3244 while (*p && brl != brr) {
3245 if (*p == '{') brl++;
3246 if (*p == '}') brr++;
3254 while (*p && (isalnum((int) *p)
3259 /* copy variable to buffer */
3260 len = (p - s > 255) ? 255 : (p - s);
3261 strncpy(buf, s, len);
3270 /* if variable wasn't found from environment, use some special */
3276 if (strchr(buf, ' ')) {
3277 arg = strchr(buf, ' ');
3280 while (isspace((int) *arg))
3286 /* lowercase variable name */
3293 // create new object
3294 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3296 // allocate memory for the object
3297 retval->text_objects = realloc(retval->text_objects,
3298 sizeof(struct text_object) * (retval->text_object_count+1));
3299 // assign the new object to the end of the list.
3300 memcpy(&retval->text_objects[retval->text_object_count++],
3301 obj, sizeof(struct text_object));
3307 obj = create_plain_text("$");
3309 // allocate memory for the object
3310 retval->text_objects = realloc(retval->text_objects,
3311 sizeof(struct text_object) * (retval->text_object_count+1));
3312 // assign the new object to the end of the list.
3313 memcpy(&retval->text_objects[retval->text_object_count++],
3314 obj, sizeof(struct text_object));
3321 obj = create_plain_text(s);
3323 // allocate memory for the object
3324 retval->text_objects = realloc(retval->text_objects,
3325 sizeof(struct text_object) * (retval->text_object_count+1));
3326 // assign the new object to the end of the list.
3327 memcpy(&retval->text_objects[retval->text_object_count++],
3328 obj, sizeof(struct text_object));
3333 ERR("one or more $endif's are missing");
3339 static void extract_variable_text(const char *p)
3341 struct text_object_list *list;
3343 free_text_objects(text_object_count, text_objects);
3344 text_object_count = 0;
3345 text_objects = NULL;
3348 list = extract_variable_text_internal(p);
3349 text_objects = list->text_objects;
3350 text_object_count = list->text_object_count;
3357 void parse_conky_vars(char * text, char * p, struct information *cur) {
3358 struct text_object_list *object_list = extract_variable_text_internal(text);
3359 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3363 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3368 char buff_in[P_MAX_SIZE] = {0};
3369 iconv_converting = 0;
3372 for (i = 0; i < object_count; i++) {
3373 struct text_object *obj = &objs[i];
3375 #define OBJ(a) break; case OBJ_##a:
3377 switch (obj->type) {
3380 ERR("not implemented obj type %d",
3384 /* does anyone have decimals in acpi temperature? */
3386 snprintf(p, p_max_size, "%d", (int)
3387 get_acpi_temperature(obj->
3391 snprintf(p, 5, "%d ", (int)
3392 get_acpi_temperature(obj->
3397 /* does anyone have decimals in acpi temperature? */
3399 snprintf(p, p_max_size, "%d", (int)
3400 ((get_acpi_temperature(obj->
3402 i)+ 40) * 9.0 / 5 - 40));
3404 snprintf(p, 5, "%d ", (int)
3405 ((get_acpi_temperature(obj->
3407 i)+ 40) * 9.0 / 5 - 40));
3411 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3416 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3419 #if defined(__linux__)
3422 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3427 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3430 #endif /* __linux__ */
3434 get_freq_dynamic(p, 6, "%.0f ", 1 );
3436 get_freq_dynamic(p, p_max_size, "%.0f", 1 );
3441 get_freq_dynamic(p, 6, "%'.2f ", 1000);
3443 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3447 get_adt746x_cpu(p, p_max_size);
3450 get_adt746x_fan(p, p_max_size);
3453 get_acpi_fan(p, p_max_size);
3455 OBJ(acpiacadapter) {
3456 get_acpi_ac_adapter(p, p_max_size);
3459 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3462 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3464 OBJ(battery_percent) {
3465 snprintf(p, p_max_size, "%d",
3466 get_battery_perct(obj->data.s));
3469 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3472 human_readable(cur->buffers * 1024, p, 255);
3475 human_readable(cur->cached * 1024, p, 255);
3478 if (obj->data.cpu_index > info.cpu_count) {
3479 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3480 CRIT_ERR("attempting to use more CPUs then you have!");
3483 snprintf(p, p_max_size, "%*d", pad_percents,
3484 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3487 snprintf(p, 4, "%*d ",
3489 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3495 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3498 new_graph(p, obj->a,
3499 obj->b, obj->c, obj->d,
3500 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3504 new_fg(p, obj->data.l);
3506 #if defined(__linux__)
3508 snprintf(p, p_max_size, "%s", i8k.version);
3511 snprintf(p, p_max_size, "%s", i8k.bios);
3514 snprintf(p, p_max_size, "%s", i8k.serial);
3517 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3519 OBJ(i8k_cpu_tempf) {
3521 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3522 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3524 OBJ(i8k_left_fan_status) {
3525 int left_fan_status;
3526 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3527 if(left_fan_status == 0) {
3528 snprintf(p, p_max_size,"off");
3529 } if(left_fan_status == 1) {
3530 snprintf(p, p_max_size, "low");
3531 } if(left_fan_status == 2) {
3532 snprintf(p, p_max_size, "high");
3536 OBJ(i8k_right_fan_status) {
3537 int right_fan_status;
3538 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3539 if(right_fan_status == 0) {
3540 snprintf(p, p_max_size,"off");
3541 } if(right_fan_status == 1) {
3542 snprintf(p, p_max_size, "low");
3543 } if(right_fan_status == 2) {
3544 snprintf(p, p_max_size, "high");
3547 OBJ(i8k_left_fan_rpm) {
3548 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3550 OBJ(i8k_right_fan_rpm) {
3551 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3553 OBJ(i8k_ac_status) {
3555 sscanf(i8k.ac_status, "%d", &ac_status);
3556 if(ac_status == -1) {
3557 snprintf(p, p_max_size,"disabled (read i8k docs)");
3558 } if(ac_status == 0) {
3559 snprintf(p, p_max_size, "off");
3560 } if(ac_status == 1) {
3561 snprintf(p, p_max_size, "on");
3564 OBJ(i8k_buttons_status) {
3565 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3569 get_ibm_acpi_fan(p, p_max_size);
3572 get_ibm_acpi_temps();
3573 snprintf(p, p_max_size, "%d",
3574 ibm_acpi.temps[obj->data.sensor]);
3577 get_ibm_acpi_volume(p, p_max_size);
3579 OBJ(ibm_brightness) {
3580 get_ibm_acpi_brightness(p, p_max_size);
3583 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3585 #endif /* __linux__ */
3588 OBJ(obsd_sensors_temp) {
3589 obsd_sensors.device = sensor_device;
3590 update_obsd_sensors();
3591 snprintf(p, p_max_size, "%.1f",
3592 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
3595 OBJ(obsd_sensors_fan) {
3596 obsd_sensors.device = sensor_device;
3597 update_obsd_sensors();
3598 snprintf(p, p_max_size, "%d",
3599 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3602 OBJ(obsd_sensors_volt) {
3603 obsd_sensors.device = sensor_device;
3604 update_obsd_sensors();
3605 snprintf(p, p_max_size, "%.2f",
3606 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3610 get_obsd_vendor(p, p_max_size);
3614 get_obsd_product(p, p_max_size);
3616 #endif /* __OpenBSD__ */
3620 new_font(p, obj->data.s);
3623 void format_diskio(unsigned int diskio_value)
3626 if (diskio_value > 1024*1024) {
3627 snprintf(p, p_max_size, "%.1fGiB",
3628 (double)diskio_value/1024/1024);
3629 } else if (diskio_value > 1024) {
3630 snprintf(p, p_max_size, "%.1fMiB",
3631 (double)diskio_value/1024);
3632 } else if (diskio_value > 0) {
3633 snprintf(p, p_max_size, "%dKiB", diskio_value);
3635 snprintf(p, p_max_size, "%dB", diskio_value);
3638 if (diskio_value > 1024*1024) {
3639 snprintf(p, 12, "%.1fGiB ",
3640 (double)diskio_value/1024/1024);
3641 } else if (diskio_value > 1024) {
3642 snprintf(p, 12, "%.1fMiB ",
3643 (double)diskio_value/1024);
3644 } else if (diskio_value > 0) {
3645 snprintf(p, 12, "%dKiB ", diskio_value);
3647 snprintf(p, 12, "%dB ", diskio_value);
3652 format_diskio(diskio_value);
3655 format_diskio(diskio_write_value);
3658 format_diskio(diskio_read_value);
3661 new_graph(p, obj->a,
3662 obj->b, obj->c, obj->d,
3663 diskio_value, obj->e, 1);
3665 OBJ(diskiograph_read) {
3666 new_graph(p, obj->a,
3667 obj->b, obj->c, obj->d,
3668 diskio_read_value, obj->e, 1);
3670 OBJ(diskiograph_write) {
3671 new_graph(p, obj->a,
3672 obj->b, obj->c, obj->d,
3673 diskio_write_value, obj->e, 1);
3677 snprintf(p, p_max_size, "%d",
3678 (int) (obj->data.net->
3682 snprintf(p, 6, "%d ",
3683 (int) (obj->data.net->
3689 snprintf(p, p_max_size, "%.1f",
3691 recv_speed / 1024.0);
3693 snprintf(p, 8, "%.1f ",
3695 recv_speed / 1024.0);
3697 OBJ(downspeedgraph) {
3699 if (obj->data.net->recv_speed == 0)
3700 obj->data.net->recv_speed = 0.01;
3702 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3703 (obj->data.net->recv_speed /
3704 1024.0), obj->e, 1);
3708 i = obj->data.ifblock.pos - 1;
3718 snprintf(p, p_max_size, "%u.%u.%u.%u",
3719 obj->data.net->addr.
3721 obj->data.net->addr.
3723 obj->data.net->addr.
3725 obj->data.net->addr.
3731 snprintf(p, p_max_size, "%d",
3732 obj->data.net->linkstatus);
3735 snprintf(p, 5, "%4d ",
3736 obj->data.net->linkstatus);
3739 #if defined(IMLIB2) && defined(X11)
3744 Imlib_Image image, buffer;
3745 image = imlib_load_image(obj->data.s);
3746 imlib_context_set_image(image);
3749 w = imlib_image_get_width();
3750 h = imlib_image_get_height();
3751 buffer = imlib_create_image(w, h);
3752 imlib_context_set_display(display);
3753 imlib_context_set_drawable(window.drawable);
3754 imlib_context_set_colormap(DefaultColormap(display, screen));
3755 imlib_context_set_visual(DefaultVisual(display, screen));
3756 imlib_context_set_image(buffer);
3757 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
3758 imlib_render_image_on_drawable(text_start_x, text_start_y);
3760 imlib_context_set_image(image);
3767 FILE *fp = popen(obj->data.s, "r");
3768 int length = fread(p, 1, p_max_size, fp);
3771 /*output[length] = '\0';
3772 if (length > 0 && output[length - 1] == '\n') {
3773 output[length - 1] = '\0';
3776 if (length > 0 && p[length - 1] == '\n') {
3777 p[length - 1] = '\0';
3780 //parse_conky_vars(output, p, cur);
3784 FILE *fp = popen(obj->data.s, "r");
3785 int n2 = fread(p, 1, p_max_size, fp);
3789 if (n2 && p[n2 - 1] == '\n')
3798 if (sscanf(p, "%lf", &barnum) == 0) {
3799 ERR("reading execbar value failed (perhaps it's not the correct format?)");
3801 if (barnum > 100 || barnum < 0) {
3802 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
3804 barnum = barnum / 100.0;
3805 new_bar(p, 0, 4, (int) (barnum * 255.0));
3811 FILE *fp = popen(obj->data.s, "r");
3812 int n2 = fread(p, 1, p_max_size, fp);
3816 if (n2 && p[n2 - 1] == '\n')
3825 if (sscanf(p, "%lf", &barnum) == 0) {
3826 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
3828 if (barnum > 100 || barnum < 0) {
3829 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
3831 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
3836 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3837 new_bar(p, 0, 4, (int) obj->f);
3840 FILE *fp = popen(obj->data.execi.cmd, "r");
3841 int n2 = fread(p, 1, p_max_size, fp);
3844 if (n2 && p[n2 - 1] == '\n')
3853 if (sscanf(p, "%f", &barnum) == 0) {
3854 ERR("reading execibar value failed (perhaps it's not the correct format?)");
3856 if (barnum > 100 || barnum < 0) {
3857 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
3859 obj->f = 255 * barnum / 100.0;
3860 new_bar(p, 0, 4, (int) obj->f);
3862 obj->data.execi.last_update =
3863 current_update_time;
3867 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3868 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
3871 FILE *fp = popen(obj->data.execi.cmd, "r");
3872 int n2 = fread(p, 1, p_max_size, fp);
3875 if (n2 && p[n2 - 1] == '\n')
3884 if (sscanf(p, "%f", &barnum) == 0) {
3885 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
3887 if (barnum > 100 || barnum < 0) {
3888 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
3891 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
3893 obj->data.execi.last_update = current_update_time;
3899 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
3900 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
3902 char *output = obj->data.execi.buffer;
3903 FILE *fp = popen(obj->data.execi.cmd, "r");
3904 //int length = fread(output, 1, text_buffer_size, fp);
3905 int length = fread(output, 1, text_buffer_size, fp);
3908 output[length] = '\0';
3909 if (length > 0 && output[length - 1] == '\n') {
3910 output[length - 1] = '\0';
3912 obj->data.execi.last_update = current_update_time;
3913 snprintf(p, p_max_size, "%s", output);
3915 //parse_conky_vars(output, p, cur);
3918 if (!obj->data.texeci.p_timed_thread)
3920 obj->data.texeci.p_timed_thread=
3921 timed_thread_create ((void*)threaded_exec, (void*) obj,
3922 obj->data.texeci.interval * 1000000);
3923 if (!obj->data.texeci.p_timed_thread)
3924 ERR("Error starting texeci thread");
3925 timed_thread_register (obj->data.texeci.p_timed_thread,
3926 &obj->data.texeci.p_timed_thread);
3928 timed_thread_lock (obj->data.texeci.p_timed_thread);
3929 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
3930 timed_thread_unlock (obj->data.texeci.p_timed_thread);
3932 #endif /* HAVE_POPEN */
3934 if (obj->global_mode && info.mail) { // this means we use info
3935 if (!info.mail->p_timed_thread)
3937 info.mail->p_timed_thread =
3938 timed_thread_create ((void*)imap_thread,
3940 info.mail->interval * 1000000);
3941 if (!info.mail->p_timed_thread)
3942 ERR("Error starting imap thread");
3943 timed_thread_register (info.mail->p_timed_thread,
3944 &info.mail->p_timed_thread);
3946 timed_thread_lock (info.mail->p_timed_thread);
3947 snprintf(p, p_max_size, "%lu", info.mail->unseen);
3948 timed_thread_unlock (info.mail->p_timed_thread);
3949 } else if (obj->data.mail) { // this means we use obj
3950 if (!obj->data.mail->p_timed_thread)
3952 obj->data.mail->p_timed_thread =
3953 timed_thread_create ((void*)imap_thread,
3954 (void*)obj->data.mail,
3955 obj->data.mail->interval * 1000000);
3956 if (!obj->data.mail->p_timed_thread)
3957 ERR("Error starting imap thread");
3958 timed_thread_register (obj->data.mail->p_timed_thread,
3959 &obj->data.mail->p_timed_thread);
3961 timed_thread_lock (obj->data.mail->p_timed_thread);
3962 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
3963 timed_thread_unlock (obj->data.mail->p_timed_thread);
3964 } else if (!obj->a) { // something is wrong, warn once then stop
3965 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
3969 OBJ(imap_messages) {
3970 if (obj->global_mode && info.mail) { // this means we use info
3971 if (!info.mail->p_timed_thread)
3973 info.mail->p_timed_thread =
3974 timed_thread_create ((void*)imap_thread,
3976 info.mail->interval * 1000000);
3977 if (!info.mail->p_timed_thread)
3978 ERR("Error starting imap thread");
3979 timed_thread_register (info.mail->p_timed_thread,
3980 &info.mail->p_timed_thread);
3982 timed_thread_lock (info.mail->p_timed_thread);
3983 snprintf(p, p_max_size, "%lu", info.mail->messages);
3984 timed_thread_unlock (info.mail->p_timed_thread);
3985 } else if (obj->data.mail) { // this means we use obj
3986 if (!obj->data.mail->p_timed_thread)
3988 obj->data.mail->p_timed_thread =
3989 timed_thread_create ((void*)imap_thread,
3990 (void*)obj->data.mail,
3991 obj->data.mail->interval * 1000000);
3992 if (!obj->data.mail->p_timed_thread)
3993 ERR("Error starting imap thread");
3994 timed_thread_register (obj->data.mail->p_timed_thread,
3995 &obj->data.mail->p_timed_thread);
3997 timed_thread_lock (obj->data.mail->p_timed_thread);
3998 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
3999 timed_thread_lock (obj->data.mail->p_timed_thread);
4000 } else if (!obj->a) { // something is wrong, warn once then stop
4001 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4006 if (obj->global_mode && info.mail) { // this means we use info
4007 if (!info.mail->p_timed_thread)
4009 info.mail->p_timed_thread =
4010 timed_thread_create ((void*)pop3_thread,
4012 info.mail->interval * 1000000);
4013 if (!info.mail->p_timed_thread)
4014 ERR("Error starting pop3 thread");
4015 timed_thread_register (info.mail->p_timed_thread,
4016 &info.mail->p_timed_thread);
4018 timed_thread_lock (info.mail->p_timed_thread);
4019 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4020 timed_thread_unlock (info.mail->p_timed_thread);
4021 } else if (obj->data.mail) { // this means we use obj
4022 if (!obj->data.mail->p_timed_thread)
4024 obj->data.mail->p_timed_thread =
4025 timed_thread_create ((void*)pop3_thread,
4026 (void*)obj->data.mail,
4027 obj->data.mail->interval * 1000000);
4028 if (!obj->data.mail->p_timed_thread)
4029 ERR("Error starting pop3 thread");
4030 timed_thread_register (obj->data.mail->p_timed_thread,
4031 &obj->data.mail->p_timed_thread);
4033 timed_thread_lock (obj->data.mail->p_timed_thread);
4034 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4035 timed_thread_unlock (obj->data.mail->p_timed_thread);
4036 } else if (!obj->a) { // something is wrong, warn once then stop
4037 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4042 if (obj->global_mode && info.mail) { // this means we use info
4043 if (!info.mail->p_timed_thread)
4045 info.mail->p_timed_thread =
4046 timed_thread_create ((void*)pop3_thread,
4048 info.mail->interval * 1000000);
4049 if (!info.mail->p_timed_thread)
4050 ERR("Error starting pop3 thread");
4051 timed_thread_register (info.mail->p_timed_thread,
4052 &info.mail->p_timed_thread);
4054 timed_thread_lock (info.mail->p_timed_thread);
4055 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4056 timed_thread_unlock (info.mail->p_timed_thread);
4057 } else if (obj->data.mail) { // this means we use obj
4058 if (!obj->data.mail->p_timed_thread)
4060 obj->data.mail->p_timed_thread =
4061 timed_thread_create ((void*)pop3_thread,
4062 (void*)obj->data.mail,
4063 obj->data.mail->interval * 1000000);
4064 if (!obj->data.mail->p_timed_thread)
4065 ERR("Error starting pop3 thread");
4066 timed_thread_register (obj->data.mail->p_timed_thread,
4067 &obj->data.mail->p_timed_thread);
4069 timed_thread_lock (obj->data.mail->p_timed_thread);
4070 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4071 timed_thread_unlock (obj->data.mail->p_timed_thread);
4072 } else if (!obj->a) { // something is wrong, warn once then stop
4073 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4078 if (obj->data.fs != NULL) {
4079 if (obj->data.fs->size == 0)
4098 if (obj->data.fs != NULL)
4099 human_readable(obj->data.fs->avail,
4103 if (obj->data.fs != NULL) {
4104 if (obj->data.fs->size)
4105 snprintf(p, p_max_size, "%*d",
4114 snprintf(p, p_max_size, "0");
4118 if (obj->data.fs != NULL)
4119 human_readable(obj->data.fs->size,
4123 if (obj->data.fs != NULL)
4124 human_readable(obj->data.fs->size -
4125 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
4129 if (obj->data.fs != NULL) {
4130 if (obj->data.fs->size == 0)
4148 if (obj->data.fs != NULL) {
4149 if (obj->data.fs->size)
4150 snprintf(p, 4, "%d",
4160 snprintf(p, p_max_size, "0");
4164 float *v = info.loadavg;
4166 if (obj->data.loadavg[2])
4167 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4168 v[obj->data.loadavg[0] -
4170 v[obj->data.loadavg[1] -
4172 v[obj->data.loadavg[2] -
4174 else if (obj->data.loadavg[1])
4175 snprintf(p, p_max_size, "%.2f %.2f",
4176 v[obj->data.loadavg[0] -
4178 v[obj->data.loadavg[1] -
4180 else if (obj->data.loadavg[0])
4181 snprintf(p, p_max_size, "%.2f",
4182 v[obj->data.loadavg[0] -
4186 new_goto(p, obj->data.i);
4189 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4192 new_hr(p, obj->data.i);
4199 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4200 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4202 snprintf(p, p_max_size, "N/A");
4203 } else if (unit == '*') {
4204 snprintf(p, p_max_size, "%s", temp);
4206 snprintf(p, p_max_size, "%s°%c", temp, unit);
4211 new_offset(p, obj->data.i);
4214 new_voffset(p, obj->data.i);
4219 r = get_i2c_info(&obj->data.i2c.fd,
4221 obj->data.i2c.devtype,
4222 obj->data.i2c.type);
4224 if (r >= 100.0 || r == 0)
4225 snprintf(p, p_max_size, "%d", (int) r);
4227 snprintf(p, p_max_size, "%.1f", r);
4230 new_alignr(p, obj->data.i);
4233 new_alignc(p, obj->data.i);
4236 struct information *my_info =
4237 malloc(sizeof(struct information));
4238 memcpy(my_info, cur, sizeof(struct information));
4239 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4240 if (strlen(p) != 0) {
4241 i = obj->data.ifblock.pos;
4251 if ((obj->data.ifblock.s)
4252 && (stat(obj->data.ifblock.s, &tmp) ==
4254 i = obj->data.ifblock.pos;
4257 if (obj->data.ifblock.str) {
4258 if (!check_contains(obj->data.ifblock.s,
4259 obj->data.ifblock.str)) {
4260 i = obj->data.ifblock.pos;
4269 if ((obj->data.ifblock.s)
4270 && (!check_mount(obj->data.ifblock.s))) {
4271 i = obj->data.ifblock.pos;
4278 if ((obj->data.ifblock.s)
4279 && system(obj->data.ifblock.s)) {
4280 i = obj->data.ifblock.pos;
4287 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4290 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4295 human_readable(cur->mem * 1024, p, 255);
4298 human_readable(cur->memmax * 1024, p, 255);
4303 snprintf(p, p_max_size, "%*Lu",
4308 snprintf(p, 4, "%*Lu ",
4315 new_bar(p, obj->data.pair.a,
4317 cur->memmax ? (cur->mem * 255) /
4322 new_graph(p, obj->a,
4323 obj->b, obj->c, obj->d,
4324 cur->memmax ? (cur->mem * 100.0) /
4325 (cur->memmax) : 0.0, 100, 1);
4329 snprintf(p, p_max_size, "%d",
4330 mixer_get_avg(obj->data.l));
4333 snprintf(p, p_max_size, "%d",
4334 mixer_get_left(obj->data.l));
4337 snprintf(p, p_max_size, "%d",
4338 mixer_get_right(obj->data.l));
4341 new_bar(p, obj->data.mixerbar.w,
4342 obj->data.mixerbar.h,
4343 mixer_get_avg(obj->data.mixerbar.
4347 new_bar(p, obj->data.mixerbar.w,
4348 obj->data.mixerbar.h,
4349 mixer_get_left(obj->data.mixerbar.
4353 new_bar(p, obj->data.mixerbar.w,
4354 obj->data.mixerbar.h,
4355 mixer_get_right(obj->data.mixerbar.
4361 snprintf(p, p_max_size, "%d", cur->mail_count);
4364 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4365 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4368 snprintf(p, p_max_size, "%d", cur->new_mail_count);
4372 snprintf(p, p_max_size, "%s",
4373 cur->uname_s.nodename);
4376 new_outline(p, obj->data.l);
4380 snprintf(p, p_max_size, "%hu", cur->procs);
4382 snprintf(p, 5, "%hu ",
4385 OBJ(running_processes) {
4387 snprintf(p, p_max_size, "%hu",
4390 snprintf(p, 3, "%hu ",
4394 snprintf(p, p_max_size, "%s", obj->data.s);
4397 new_bg(p, obj->data.l);
4400 new_stippled_hr(p, obj->data.pair.a,
4404 human_readable(cur->swap * 1024, p, 255);
4407 human_readable(cur->swapmax * 1024, p,
4411 if (cur->swapmax == 0) {
4412 strncpy(p, "No swap", 255);
4415 snprintf(p, 255, "%*Lu",
4421 snprintf(p, 4, "%*Lu ",
4429 new_bar(p, obj->data.pair.a,
4431 cur->swapmax ? (cur->swap * 255) /
4432 (cur->swapmax) : 0);
4435 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4438 time_t t = time(NULL);
4439 struct tm *tm = localtime(&t);
4440 setlocale(LC_TIME, "");
4441 strftime(p, p_max_size, obj->data.s, tm);
4444 time_t t = time(NULL);
4445 struct tm *tm = gmtime(&t);
4446 strftime(p, p_max_size, obj->data.s, tm);
4450 if (obj->data.tztime.tz) {
4451 oldTZ = getenv("TZ");
4452 setenv("TZ", obj->data.tztime.tz, 1);
4455 time_t t = time(NULL);
4456 struct tm *tm = localtime(&t);
4457 setlocale(LC_TIME, "");
4458 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4460 setenv("TZ", oldTZ, 1);
4465 // Needless to free oldTZ since getenv gives ptr to static data
4468 human_readable(obj->data.net->recv, p,
4472 human_readable(obj->data.net->trans, p,
4476 snprintf(p, p_max_size, "%d", total_updates);
4480 snprintf(p, p_max_size, "%d",
4481 (int) (obj->data.net->
4485 snprintf(p, 5, "%d ",
4486 (int) (obj->data.net->
4492 snprintf(p, p_max_size, "%.1f",
4494 trans_speed / 1024.0);
4496 snprintf(p, 8, "%.1f ",
4498 trans_speed / 1024.0);
4502 if (obj->data.net->trans_speed == 0)
4503 obj->data.net->trans_speed = 0.01;
4505 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4506 (obj->data.net->trans_speed /
4507 1024.0), obj->e, 1);
4510 format_seconds_short(p, p_max_size,
4514 format_seconds(p, p_max_size, (int) cur->uptime);
4517 #if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
4519 snprintf(p, p_max_size, "%s", get_apm_adapter());
4521 OBJ(apm_battery_life) {
4523 msg = get_apm_battery_life();
4524 snprintf(p, p_max_size, "%s", msg);
4527 OBJ(apm_battery_time) {
4529 msg = get_apm_battery_time();
4530 snprintf(p, p_max_size, "%s", msg);
4533 #endif /* __FreeBSD__ */
4537 snprintf(p, p_max_size, "%s", cur->mpd.title);
4540 snprintf(p, p_max_size, "%s", cur->mpd.artist);
4543 snprintf(p, p_max_size, "%s", cur->mpd.album);
4546 snprintf(p, p_max_size, "%s", cur->mpd.random);
4549 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
4552 snprintf(p, p_max_size, "%s", cur->mpd.track);
4555 snprintf(p, p_max_size, "%s", cur->mpd.name);
4558 snprintf(p, p_max_size, "%s", cur->mpd.file);
4561 snprintf(p, p_max_size, "%i", cur->mpd.volume);
4564 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
4567 snprintf(p, p_max_size, "%s", cur->mpd.status);
4570 int days = 0, hours = 0, minutes =
4572 int tmp = cur->mpd.elapsed;
4573 while (tmp >= 86400) {
4577 while (tmp >= 3600) {
4587 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
4588 days, hours, minutes,
4591 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4594 snprintf(p, p_max_size, "%i:%02i", minutes,
4598 int days = 0, hours = 0, minutes =
4600 int tmp = cur->mpd.length;
4601 while (tmp >= 86400) {
4605 while (tmp >= 3600) {
4615 snprintf(p, p_max_size,
4616 "%i days %i:%02i:%02i",
4617 days, hours, minutes,
4620 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4623 snprintf(p, p_max_size, "%i:%02i", minutes,
4627 snprintf(p, p_max_size, "%2.0f",
4628 cur->mpd.progress * 100);
4631 new_bar(p, obj->data.pair.a,
4633 (int) (cur->mpd.progress *
4637 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.title) < 2) {
4638 snprintf(p, p_max_size, "%s", cur->mpd.file);
4640 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
4646 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4649 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4652 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4655 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4657 OBJ(xmms2_comment) {
4658 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4660 OBJ(xmms2_decoder) {
4661 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
4663 OBJ(xmms2_transport) {
4664 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
4667 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4670 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4673 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4675 OBJ(xmms2_tracknr) {
4676 if (cur->xmms2.tracknr != -1)
4677 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4679 OBJ(xmms2_bitrate) {
4680 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4683 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4686 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4688 OBJ(xmms2_elapsed) {
4689 int tmp = cur->xmms2.elapsed;
4690 snprintf(p, p_max_size, "%02d:%02d",
4691 tmp / 60000, (tmp / 1000) % 60);
4693 OBJ(xmms2_duration) {
4694 int tmp = cur->xmms2.duration;
4695 snprintf(p, p_max_size, "%02d:%02d",
4696 tmp / 60000, (tmp / 1000) % 60);
4698 OBJ(xmms2_percent) {
4699 snprintf(p, p_max_size, "%2.0f",
4700 cur->xmms2.progress * 100);
4703 new_bar(p, obj->data.pair.a,
4705 (int) (cur->xmms2.progress *
4709 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
4710 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4712 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
4717 OBJ(audacious_status) {
4718 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
4720 OBJ(audacious_title) {
4721 snprintf(p, cur->audacious.max_title_len > 0 ?
4722 cur->audacious.max_title_len : p_max_size, "%s",
4723 cur->audacious.items[AUDACIOUS_TITLE]);
4725 OBJ(audacious_length) {
4726 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
4728 OBJ(audacious_length_seconds) {
4729 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4731 OBJ(audacious_position) {
4732 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
4734 OBJ(audacious_position_seconds) {
4735 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
4737 OBJ(audacious_bitrate) {
4738 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
4740 OBJ(audacious_frequency) {
4741 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
4743 OBJ(audacious_channels) {
4744 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
4746 OBJ(audacious_filename) {
4747 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
4749 OBJ(audacious_playlist_length) {
4750 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
4752 OBJ(audacious_playlist_position) {
4753 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
4755 OBJ(audacious_bar) {
4757 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
4758 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4759 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
4764 snprintf(p, p_max_size, "%s", cur->bmpx.title);
4767 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
4770 snprintf(p, p_max_size, "%s", cur->bmpx.album);
4773 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
4776 snprintf(p, p_max_size, "%i", cur->bmpx.track);
4779 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
4783 if (obj->data.top.type == TOP_NAME
4784 && obj->data.top.num >= 0
4785 && obj->data.top.num < 10) {
4786 // if we limit the buffer and add a bunch of space after, it stops the thing from
4787 // moving other shit around, which is really fucking annoying
4788 snprintf(p, 17, "%s ", cur->cpu[obj->data.top.num]->name);
4789 } else if (obj->data.top.type == TOP_CPU
4790 && obj->data.top.num >= 0
4791 && obj->data.top.num < 10) {
4792 snprintf(p, 7, "%3.2f ",
4793 cur->cpu[obj->data.top.
4795 } else if (obj->data.top.type == TOP_PID
4796 && obj->data.top.num >= 0
4797 && obj->data.top.num < 10) {
4798 snprintf(p, 8, "%i ",
4799 cur->cpu[obj->data.top.
4801 } else if (obj->data.top.type == TOP_MEM
4802 && obj->data.top.num >= 0
4803 && obj->data.top.num < 10) {
4804 snprintf(p, 7, "%3.2f ",
4805 cur->cpu[obj->data.top.
4810 if (obj->data.top.type == TOP_NAME
4811 && obj->data.top.num >= 0
4812 && obj->data.top.num < 10) {
4813 // if we limit the buffer and add a bunch of space after, it stops the thing from
4814 // moving other shit around, which is really fucking annoying
4817 cur->memu[obj->data.top.
4819 } else if (obj->data.top.type == TOP_CPU
4820 && obj->data.top.num >= 0
4821 && obj->data.top.num < 10) {
4822 snprintf(p, 7, "%3.2f ",
4823 cur->memu[obj->data.top.
4825 } else if (obj->data.top.type == TOP_PID
4826 && obj->data.top.num >= 0
4827 && obj->data.top.num < 10) {
4828 snprintf(p, 8, "%i ",
4829 cur->memu[obj->data.top.
4831 } else if (obj->data.top.type == TOP_MEM
4832 && obj->data.top.num >= 0
4833 && obj->data.top.num < 10) {
4834 snprintf(p, 7, "%3.2f ",
4835 cur->memu[obj->data.top.
4842 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4843 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4845 obj->data.tail.last_update = current_update_time;
4849 fp = fopen(obj->data.tail.logfile, "rt");
4851 /* Send one message, but do not consistently spam on
4852 * missing logfiles. */
4853 if(obj->data.tail.readlines != 0) {
4854 ERR("tail logfile failed to open");
4855 strcpy(obj->data.tail.buffer, "Logfile Missing");
4857 obj->data.tail.readlines = 0;
4858 snprintf(p, p_max_size, "Logfile Missing");
4861 obj->data.tail.readlines = 0;
4862 /* -1 instead of 0 to avoid counting a trailing newline */
4863 fseek(fp, -1, SEEK_END);
4864 bsize = ftell(fp) + 1;
4865 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
4866 nl = rev_fcharfind(fp, '\n', iter);
4870 obj->data.tail.readlines = iter;
4871 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
4872 fseek(fp, 0, SEEK_SET);
4875 fseek(fp, nl+1, SEEK_SET);
4878 /* Make sure bsize is at least 1 byte smaller than
4879 * the buffer max size. */
4880 if(bsize > (long)((text_buffer_size*20) - 1)) {
4881 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
4882 bsize = text_buffer_size*20 - 1;
4884 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
4887 /* Clean up trailing newline, make sure the buffer
4888 * is null terminated. */
4889 if(obj->data.tail.buffer[bsize-1] == '\n')
4890 obj->data.tail.buffer[bsize-1] = '\0';
4892 obj->data.tail.buffer[bsize] = '\0';
4893 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4896 strcpy(obj->data.tail.buffer, "Logfile Empty");
4897 snprintf(p, p_max_size, "Logfile Empty");
4900 } /* if cur_upd_time >= */
4902 //parse_conky_vars(obj->data.tail.buffer, p, cur);
4906 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4907 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4909 obj->data.tail.last_update = current_update_time;
4913 fp = fopen(obj->data.tail.logfile, "rt");
4915 /* Send one message, but do not consistently spam on
4916 * missing logfiles. */
4917 if(obj->data.tail.readlines != 0) {
4918 ERR("head logfile failed to open");
4919 strcpy(obj->data.tail.buffer, "Logfile Missing");
4921 obj->data.tail.readlines = 0;
4922 snprintf(p, p_max_size, "Logfile Missing");
4924 obj->data.tail.readlines = 0;
4925 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
4926 nl = fwd_fcharfind(fp, '\n', iter);
4930 obj->data.tail.readlines = iter;
4931 /* Make sure nl is at least 1 byte smaller than
4932 * the buffer max size. */
4933 if(nl > (long)((text_buffer_size*20) - 1)) {
4934 nl = text_buffer_size*20 - 1;
4936 nl = fread(obj->data.tail.buffer, 1, nl, fp);
4939 /* Clean up trailing newline, make sure the buffer
4940 * is null terminated. */
4941 if (obj->data.tail.buffer[nl-1] == '\n') {
4942 obj->data.tail.buffer[nl-1] = '\0';
4945 obj->data.tail.buffer[nl] = '\0';
4947 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4950 strcpy(obj->data.tail.buffer, "Logfile Empty");
4951 snprintf(p, p_max_size, "Logfile Empty");
4953 } /* if fp == null */
4954 } /* cur_upd_time >= */
4956 //parse_conky_vars(obj->data.tail.buffer, p, cur);
4959 #ifdef TCP_PORT_MONITOR
4962 /* grab a pointer to this port monitor */
4963 tcp_port_monitor_t * p_monitor =
4964 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
4965 obj->data.tcp_port_monitor.port_range_begin,
4966 obj->data.tcp_port_monitor.port_range_end );
4968 snprintf(p, p_max_size, "monitor not found");
4972 /* now grab the text of interest */
4973 if ( peek_tcp_port_monitor( p_monitor,
4974 obj->data.tcp_port_monitor.item,
4975 obj->data.tcp_port_monitor.connection_index,
4976 p, p_max_size ) != 0 )
4978 snprintf(p, p_max_size, "monitor peek error");
4987 iconv_converting = 1;
4988 iconv_selected = obj->a;
4993 iconv_converting = 0;
4999 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5001 OBJ(entropy_poolsize)
5003 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5007 double entropy_perc;
5008 entropy_perc = (double)cur->entropy.entropy_avail /
5009 (double)cur->entropy.poolsize;
5010 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5018 unsigned int a = strlen(p);
5021 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5023 size_t dummy1, dummy2;
5024 char *ptr = buff_in;
5027 dummy1 = dummy2 = a;
5029 strncpy(buff_in, p, P_MAX_SIZE);
5031 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5032 while (dummy1 > 0) {
5033 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5035 ERR("Iconv codeset conversion failed");
5040 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5051 double current_update_time, last_update_time;
5053 static void generate_text()
5055 struct information *cur = &info;
5063 current_update_time = get_time();
5066 /* fix diskio rates to b/s (use update_interval */
5067 diskio_read_value = diskio_read_value / update_interval;
5068 diskio_write_value = diskio_write_value / update_interval;
5069 diskio_value = diskio_value / update_interval;
5072 /* add things to the buffer */
5078 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5080 if (stuff_in_upper_case) {
5091 last_update_time = current_update_time;
5098 static void set_font()
5102 if (window.xftdraw != NULL) {
5103 XftDrawDestroy(window.xftdraw);
5105 window.xftdraw = XftDrawCreate(display, window.drawable,
5106 DefaultVisual(display,
5108 DefaultColormap(display,
5113 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5119 static inline int get_string_width(const char *s)
5122 return *s ? calc_text_width(s, strlen(s)) : 0;
5128 static inline int get_string_width_special(char *s)
5141 if (*p == SPECIAL_CHAR) {
5142 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5143 for (i = 0; i < strlen(p); i++) {
5144 *(p + i) = *(p + i + 1);
5146 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5147 width += specials[special_index+index].width;
5154 if (strlen(final) > 1) {
5155 width += calc_text_width(final, strlen(final));
5165 static void text_size_updater(char *s);
5167 int last_font_height;
5168 static void update_text_area()
5172 /* update text size if it isn't fixed */
5177 text_width = minimum_width;
5180 last_font_height = font_height();
5181 for_each_line(text_buffer, text_size_updater);
5183 if (text_height < minimum_height)
5184 text_height = minimum_height;
5185 if (text_width > maximum_width && maximum_width > 0)
5186 text_width = maximum_width;
5189 /* get text position on workarea */
5190 switch (text_alignment) {
5197 x = workarea[2] - text_width - gap_x;
5204 y = workarea[3] - text_height - gap_y;
5208 x = workarea[2] - text_width - gap_x;
5209 y = workarea[3] - text_height - gap_y;
5213 case NONE: // Let the WM manage the window
5224 if (own_window && !fixed_pos) {
5227 text_start_x = border_margin + 1;
5228 text_start_y = border_margin + 1;
5229 window.x = x - border_margin - 1;
5230 window.y = y - border_margin - 1;
5234 /* If window size doesn't match to workarea's size, then window
5235 * probably includes panels (gnome).
5236 * Blah, doesn't work on KDE. */
5237 if (workarea[2] != window.width
5238 || workarea[3] != window.height) {
5252 static int cur_x, cur_y; /* current x and y for drawing */
5253 static int draw_mode; /* FG, BG or OUTLINE */
5254 static long current_color;
5257 static void text_size_updater(char *s)
5261 /* get string widths and skip specials */
5264 if (*p == SPECIAL_CHAR) {
5266 w += get_string_width(s);
5269 if (specials[special_index].type == BAR
5270 || specials[special_index].type == GRAPH) {
5271 w += specials[special_index].width;
5272 if (specials[special_index].height > last_font_height) {
5273 last_font_height = specials[special_index].height;
5274 last_font_height += font_ascent();
5276 } else if (specials[special_index].type == OFFSET) {
5277 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
5278 } else if (specials[special_index].type == VOFFSET) {
5279 last_font_height += specials[special_index].arg;
5280 } else if (specials[special_index].type == GOTO) {
5281 if (specials[special_index].arg >= 0)
5282 w += (int)specials[special_index].arg - cur_x;
5283 } else if (specials[special_index].type == TAB) {
5284 int start = specials[special_index].arg;
5285 int step = specials[special_index].width;
5286 if (!step || step < 0)
5288 w += step - (cur_x - text_start_x - start) % step;
5289 } else if (specials[special_index].type == FONT) {
5290 selected_font = specials[special_index].font_added;
5291 if (font_height() > last_font_height) {
5292 last_font_height = font_height();
5301 w += get_string_width(s);
5302 if (w > text_width) {
5305 if (text_width > maximum_width && maximum_width) {
5306 text_width = maximum_width;
5309 text_height += last_font_height;
5310 last_font_height = font_height();
5314 static inline void set_foreground_color(long c)
5317 XSetForeground(display, window.gc, c);
5321 static void draw_string(const char *s)
5325 int i, i2, pos, width_of_s;
5328 width_of_s = get_string_width(s);
5329 if (out_to_console) {
5331 fflush(stdout); /* output immediately, don't buffer */
5333 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5334 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5335 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5339 snprintf(space, 2, " ");
5341 max = ((text_width - width_of_s) / get_string_width(space));
5344 * This code looks for tabs in the text and coverts them to spaces.
5345 * The trick is getting the correct number of spaces,
5346 * and not going over the window's size without forcing
5347 * the window larger.
5349 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5350 if (tmpstring1[i] == '\t') // 9 is ascii tab
5354 i2 < (8 - (1 + pos) % 8) && added <= max;
5357 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5358 fprintf(stderr,"buffer overrun detected\n");
5360 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5365 if (tmpstring1[i] != 9) {
5367 if ( pos > TEXT_BUFFER_SIZE-1 )
5368 fprintf(stderr,"buffer overrun detected\n");
5370 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5376 if (text_width == maximum_width) {
5377 /* this means the text is probably pushing the limit, so we'll chop it */
5378 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5379 tmpstring2[strlen(tmpstring2)-1] = '\0';
5389 c.pixel = current_color;
5390 XQueryColor(display, DefaultColormap(display, screen), &c);
5393 c2.color.red = c.red;
5394 c2.color.green = c.green;
5395 c2.color.blue = c.blue;
5396 c2.color.alpha = fonts[selected_font].font_alpha;
5398 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5399 cur_x, cur_y, (XftChar8 *) s,
5402 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5403 cur_x, cur_y, (XftChar8 *) s,
5409 XDrawString(display, window.drawable, window.gc,
5410 cur_x, cur_y, s, strlen(s));
5412 cur_x += width_of_s;
5414 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5417 long redmask, greenmask, bluemask;
5419 void set_up_gradient()
5422 colour_depth = DisplayPlanes(display, screen);
5426 if (colour_depth != 24 && colour_depth != 16) {
5427 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5433 for(i = (colour_depth / 3)-1; i>=0; i--) {
5435 greenmask |= 1 << i;
5438 if (colour_depth%3 == 1) {
5439 greenmask |= 1 << (colour_depth / 3);
5441 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5442 greenmask = greenmask << (colour_depth / 3);
5445 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 */
5447 int red1, green1, blue1; // first colour
5448 int red2, green2, blue2; // second colour
5449 int red3 = 0, green3 = 0, blue3 = 0; // difference
5450 short redshift = (2*colour_depth / 3 + colour_depth%3);
5451 short greenshift = (colour_depth / 3);
5452 red1 = (first_colour & redmask) >> redshift;
5453 green1 = (first_colour & greenmask) >> greenshift;
5454 blue1 = first_colour & bluemask;
5455 red2 = (last_colour & redmask) >> redshift;
5456 green2 = (last_colour & greenmask) >> greenshift;
5457 blue2 = last_colour & bluemask;
5464 if (green1 > green2) {
5467 if (green1 < green2) {
5470 if (blue1 > blue2) {
5473 if (blue1 < blue2) {
5488 if (red1 > bluemask) {
5491 if (green1 > bluemask) {
5494 if (blue1 > bluemask) {
5497 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
5501 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
5502 if (colour_depth == 0) {
5505 int red1, green1, blue1; // first colour
5506 int red2, green2, blue2; // second colour
5507 long redshift = (2*colour_depth / 3 + colour_depth%3);
5508 long greenshift = (colour_depth / 3);
5509 int red3 = 0, green3 = 0, blue3 = 0; // difference
5510 red1 = (first_colour & redmask) >> redshift;
5511 green1 = (first_colour & greenmask) >> greenshift;
5512 blue1 = first_colour & bluemask;
5513 red2 = (last_colour & redmask) >> redshift;
5514 green2 = (last_colour & greenmask) >> greenshift;
5515 blue2 = last_colour & bluemask;
5516 red3 = abs(red1 - red2);
5517 green3 = abs(green1 - green2);
5518 blue3 = abs(blue1 - blue2);
5527 static void draw_line(char *s)
5531 cur_x = text_start_x;
5532 cur_y += font_ascent();
5534 short font_h = font_height();
5536 /* find specials and draw stuff */
5539 if (*p == SPECIAL_CHAR) {
5542 /* draw string before special */
5549 switch (specials[special_index].type) {
5550 case HORIZONTAL_LINE:
5553 specials[special_index].height;
5554 int mid = font_ascent() / 2;
5555 w = text_start_x + text_width -
5558 XSetLineAttributes(display,
5563 XDrawLine(display, window.drawable,
5574 specials[special_index].height;
5576 specials[special_index].arg;
5577 int mid = font_ascent() / 2;
5578 char ss[2] = { s, s };
5579 w = text_start_x + text_width -
5582 XSetLineAttributes(display,
5587 XSetDashes(display, window.gc, 0,
5589 XDrawLine(display, window.drawable,
5599 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5603 specials[special_index].height;
5605 specials[special_index].arg;
5606 int by = cur_y - (font_ascent() / 2) - 1;
5607 if (h < font_height()) {
5610 w = specials[special_index].width;
5613 text_width - cur_x - 1;
5617 XSetLineAttributes(display,
5623 XDrawRectangle(display,
5627 XFillRectangle(display,
5631 w * bar_usage / 255,
5633 if (specials[special_index].
5635 && specials[special_index].
5639 [special_index].height;
5646 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5650 specials[special_index].height;
5651 unsigned long last_colour = current_color;
5652 int by = cur_y - (font_ascent()/2) - 1;
5653 if (h < font_height()) {
5656 w = specials[special_index].width;
5658 w = text_start_x + text_width - cur_x - 1;
5661 if (draw_graph_borders) {
5662 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
5663 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
5665 XSetLineAttributes(display,
5672 int gradient_size = 0;
5673 float gradient_factor = 0;
5674 float gradient_update = 0;
5675 unsigned long tmpcolour = current_color;
5676 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5677 tmpcolour = specials[special_index].last_colour;
5678 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
5679 gradient_factor = (float)gradient_size / (w - 2);
5681 for (i = w - 2; i > -1; i--) {
5682 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5683 XSetForeground(display, window.gc, tmpcolour);
5684 gradient_update += gradient_factor;
5685 while (gradient_update > 0) {
5686 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
5690 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
5693 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 */
5695 if (specials[special_index].
5697 && specials[special_index].
5701 [special_index].height;
5703 /* if (draw_mode == BG) {
5704 set_foreground_color(default_bg_color);
5706 else if (draw_mode == OUTLINE) {
5707 set_foreground_color(default_out_color);
5709 set_foreground_color(default_fg_color);
5711 set_foreground_color(last_colour);
5717 int old = font_ascent();
5718 cur_y -= font_ascent();
5719 selected_font = specials[special_index].font_added;
5720 if (cur_y + font_ascent() < cur_y + old) {
5723 cur_y += font_ascent();
5729 if (draw_mode == FG)
5730 set_foreground_color(specials
5736 if (draw_mode == BG)
5737 set_foreground_color(specials
5743 if (draw_mode == OUTLINE)
5744 set_foreground_color(specials
5750 w += specials[special_index].arg;
5754 cur_y += specials[special_index].arg;
5758 if (specials[special_index].arg >= 0)
5759 cur_x = (int)specials[special_index].arg;
5764 int start = specials[special_index].arg;
5765 int step = specials[special_index].width;
5766 if (!step || step < 0)
5768 w = step - (cur_x - text_start_x - start) % step;
5774 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
5775 /*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);*/
5776 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
5777 cur_x = pos_x - specials[special_index].arg;
5784 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
5785 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
5786 /*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);*/
5788 specials[special_index].arg)
5791 [special_index].arg;
5808 if (cur_y_add > 0) {
5810 cur_y -= font_descent();
5815 cur_y += font_descent();
5819 static void draw_text()
5822 cur_y = text_start_y;
5825 if (draw_borders && border_width > 0) {
5826 unsigned int b = (border_width + 1) / 2;
5828 if (stippled_borders) {
5830 { stippled_borders, stippled_borders };
5831 XSetLineAttributes(display, window.gc,
5832 border_width, LineOnOffDash,
5833 CapButt, JoinMiter);
5834 XSetDashes(display, window.gc, 0, ss, 2);
5836 XSetLineAttributes(display, window.gc,
5837 border_width, LineSolid,
5838 CapButt, JoinMiter);
5841 XDrawRectangle(display, window.drawable, window.gc,
5842 text_start_x - border_margin + b,
5843 text_start_y - border_margin + b,
5844 text_width + border_margin * 2 - 1 - b * 2,
5845 text_height + border_margin * 2 - 1 -
5852 for_each_line(text_buffer, draw_line);
5855 static void draw_stuff()
5859 if (draw_shades && !draw_outline) {
5862 set_foreground_color(default_bg_color);
5872 for (i = -1; i < 2; i++)
5873 for (j = -1; j < 2; j++) {
5874 if (i == 0 && j == 0)
5878 set_foreground_color(default_out_color);
5879 draw_mode = OUTLINE;
5886 set_foreground_color(default_fg_color);
5894 swap.swap_window = window.window;
5895 swap.swap_action = XdbeBackground;
5896 XdbeSwapBuffers(display, &swap, 1);
5902 static void clear_text(int exposures)
5906 return; /* The swap action is XdbeBackground, which clears */
5910 /* there is some extra space for borders and outlines */
5911 XClearArea(display, window.window,
5912 text_start_x - border_margin - 1,
5913 text_start_y - border_margin - 1,
5914 text_width + border_margin * 2 + 2,
5915 text_height + border_margin * 2 + 2,
5916 exposures ? True : 0);
5921 static int need_to_update;
5923 /* update_text() generates new text and clears old text area */
5924 static void update_text()
5933 static void main_loop()
5935 #ifdef SIGNAL_BLOCKING
5936 sigset_t newmask, oldmask;
5938 sigemptyset(&newmask);
5939 sigaddset(&newmask,SIGINT);
5940 sigaddset(&newmask,SIGTERM);
5941 sigaddset(&newmask,SIGUSR1);
5945 Region region = XCreateRegion();
5947 int event_base, error_base;
5948 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
5949 ERR("Xdamage extension unavailable");
5951 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
5952 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
5953 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
5954 #endif /* HAVE_XDAMAGE */
5958 while (total_run_times == 0 || info.looped < total_run_times) {
5961 #ifdef SIGNAL_BLOCKING
5962 /* block signals. we will inspect for pending signals later */
5963 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
5964 CRIT_ERR("unable to sigprocmask()");
5970 /* wait for X event or timeout */
5972 if (!XPending(display)) {
5977 update_interval - (get_time() -
5983 tv.tv_sec = (long) t;
5984 tv.tv_usec = (long) (t * 1000000) % 1000000;
5986 FD_SET(ConnectionNumber(display), &fdsr);
5989 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
5992 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
5997 ERR("can't select(): %s",
6008 if (need_to_update) {
6010 int wx = window.x, wy = window.y;
6018 /* resize window if it isn't right size */
6020 (text_width + border_margin * 2 + 1 !=
6022 || text_height + border_margin * 2 + 1 !=
6026 border_margin * 2 + 1;
6029 border_margin * 2 + 1;
6030 XResizeWindow(display,
6035 set_transparent_background(window.window);
6039 /* move window if it isn't in right position */
6042 || window.y != wy)) {
6043 XMoveWindow(display, window.window,
6044 window.x, window.y);
6054 r.x = text_start_x - border_margin;
6055 r.y = text_start_y - border_margin;
6056 r.width = text_width + border_margin * 2;
6057 r.height = text_height + border_margin * 2;
6058 XUnionRectWithRegion(&r, region, region);
6063 /* handle X events */
6065 while (XPending(display)) {
6067 XNextEvent(display, &ev);
6074 r.width = ev.xexpose.width;
6075 r.height = ev.xexpose.height;
6076 XUnionRectWithRegion(&r, region,
6082 case ReparentNotify:
6083 /* set background to ParentRelative for all parents */
6085 set_transparent_background(window.
6090 case ConfigureNotify:
6092 /* if window size isn't what expected, set fixed size */
6093 if (ev.xconfigure.width !=
6095 || ev.xconfigure.height !=
6097 if (window.width != 0
6098 && window.height != 0)
6101 /* clear old stuff before screwing up size and pos */
6107 if (XGetWindowAttributes(display, window.window, &attrs)) {
6122 border_margin * 2 - 1;
6125 border_margin * 2 - 1;
6126 if (text_width > maximum_width && maximum_width > 0)
6127 text_width = maximum_width;
6130 /* if position isn't what expected, set fixed pos, total_updates
6131 * avoids setting fixed_pos when window is set to weird locations
6133 /*if (total_updates >= 2 this is broken
6135 && (window.x != ev.xconfigure.x
6138 && (ev.xconfigure.x != 0
6139 || ev.xconfigure.y != 0)) {
6149 /* if an ordinary window with decorations */
6150 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6152 /* allow conky to hold input focus.*/
6157 /* forward the click to the desktop window */
6158 XUngrabPointer(display, ev.xbutton.time);
6159 ev.xbutton.window = window.desktop;
6160 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6161 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6169 /* if an ordinary window with decorations */
6170 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6172 /* allow conky to hold input focus.*/
6177 /* forward the release to the desktop window */
6178 ev.xbutton.window = window.desktop;
6179 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6188 if (ev.type == event_base + XDamageNotify) {
6189 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6190 XFixesSetRegion(display, part, &dev->area, 1);
6191 XFixesUnionRegion(display, region2, region2, part);
6193 #endif /* HAVE_XDAMAGE */
6198 XDamageSubtract(display, damage, region2, None);
6199 XFixesSetRegion(display, region2, 0, 0);
6200 #endif /* HAVE_XDAMAGE */
6202 /* XDBE doesn't seem to provide a way to clear the back buffer without
6203 * interfering with the front buffer, other than passing XdbeBackground
6204 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6205 * redraw the text even if it wasn't part of the exposed area. OTOH,
6206 * if we're not going to call draw_stuff at all, then no swap happens
6207 * and we can safely do nothing.
6210 if (!XEmptyRegion(region)) {
6214 r.x = text_start_x - border_margin;
6215 r.y = text_start_y - border_margin;
6216 r.width = text_width + border_margin * 2;
6217 r.height = text_height + border_margin * 2;
6218 XUnionRectWithRegion(&r, region, region);
6221 XSetRegion(display, window.gc, region);
6224 XftDrawSetClip(window.xftdraw, region);
6230 XDestroyRegion(region);
6231 region = XCreateRegion();
6235 #ifdef SIGNAL_BLOCKING
6236 /* unblock signals of interest and let handler fly */
6237 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6238 CRIT_ERR("unable to sigprocmask()");
6241 switch(g_signal_pending) {
6244 ERR("received SIGUSR1. reloading the config file.");
6251 ERR("received SIGINT or SIGTERM to terminate. bye!");
6254 XDestroyRegion(region);
6257 return; /* return from main_loop */
6262 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6263 * but didn't write any code to deal with it. if you don't want to
6264 * handle a signal, don't set a handler on it in the first place. */
6265 if (g_signal_pending)
6266 ERR("ignoring signal (%d)", g_signal_pending);
6273 #if defined(X11) && defined(HAVE_XDAMAGE)
6274 XDamageDestroy(display, damage);
6275 XFixesDestroyRegion(display, region2);
6276 XFixesDestroyRegion(display, part);
6277 XDestroyRegion(region);
6279 #endif /* X11 && HAVE_XDAMAGE */
6282 static void load_config_file(const char *);
6284 /* reload the config file */
6285 void reload_config(void)
6287 timed_thread_destroy_registered_threads ();
6289 if (info.cpu_usage) {
6290 free(info.cpu_usage);
6291 info.cpu_usage = NULL;
6294 #ifdef TCP_PORT_MONITOR
6295 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6298 if (current_config) {
6300 load_config_file(current_config);
6302 /* re-init specials array */
6303 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6304 ERR("failed to realloc specials array");
6309 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6312 #ifdef TCP_PORT_MONITOR
6313 info.p_tcp_port_monitor_collection = NULL;
6316 if (create_audacious_thread() !=0)
6317 CRIT_ERR("unable to create audacious thread!");
6318 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6320 extract_variable_text(text);
6329 timed_thread_destroy_registered_threads ();
6331 if (info.cpu_usage) {
6332 free(info.cpu_usage);
6333 info.cpu_usage = NULL;
6338 XdbeDeallocateBackBufferName(display, window.back_buffer);
6344 XDestroyWindow(display, window.window);
6345 XClearWindow(display, RootWindow(display, screen));
6351 XClearWindow(display, RootWindow(display, screen));
6356 XFreeGC(display, window.gc);
6359 free_text_objects(text_object_count, text_objects);
6360 text_object_count = 0;
6361 text_objects = NULL;
6363 if (text != original_text)
6366 free(current_config);
6367 free(current_mail_spool);
6369 #ifdef TCP_PORT_MONITOR
6370 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6371 info.p_tcp_port_monitor_collection = NULL;
6380 static int string_to_bool(const char *s)
6384 if (strcasecmp(s, "yes") == 0)
6386 if (strcasecmp(s, "true") == 0)
6388 if (strcasecmp(s, "1") == 0)
6393 static enum alignment string_to_alignment(const char *s)
6395 if (strcasecmp(s, "top_left") == 0)
6397 else if (strcasecmp(s, "top_right") == 0)
6399 else if (strcasecmp(s, "bottom_left") == 0)
6401 else if (strcasecmp(s, "bottom_right") == 0)
6402 return BOTTOM_RIGHT;
6403 else if (strcasecmp(s, "tl") == 0)
6405 else if (strcasecmp(s, "tr") == 0)
6407 else if (strcasecmp(s, "bl") == 0)
6409 else if (strcasecmp(s, "br") == 0)
6410 return BOTTOM_RIGHT;
6411 else if (strcasecmp(s, "none") == 0)
6418 static void set_default_configurations(void)
6420 fork_to_background = 0;
6421 total_run_times = 0;
6422 info.cpu_avg_samples = 2;
6423 info.net_avg_samples = 2;
6428 strcpy(info.mpd.host, "localhost");
6429 info.mpd.port = 6600;
6430 info.mpd.status = NULL;
6431 info.mpd.artist = NULL;
6432 info.mpd.album = NULL;
6433 info.mpd.title = NULL;
6434 info.mpd.random = NULL;
6435 info.mpd.track = NULL;
6436 info.mpd.name = NULL;
6437 info.mpd.file = NULL;
6440 info.xmms2.artist = NULL;
6441 info.xmms2.album = NULL;
6442 info.xmms2.title = NULL;
6443 info.xmms2.genre = NULL;
6444 info.xmms2.comment = NULL;
6445 info.xmms2.decoder = NULL;
6446 info.xmms2.transport = NULL;
6447 info.xmms2.url = NULL;
6448 info.xmms2.status = NULL;
6457 default_fg_color = WhitePixel(display, screen);
6458 default_bg_color = BlackPixel(display, screen);
6459 default_out_color = BlackPixel(display, screen);
6462 draw_graph_borders = 1;
6464 set_first_font("6x10");
6472 window.type=TYPE_NORMAL;
6474 strcpy(window.class_name, "Conky");
6476 sprintf(window.title,"%s - conky",info.uname_s.nodename);
6478 stippled_borders = 0;
6481 text_alignment = BOTTOM_LEFT;
6484 free(current_mail_spool);
6487 variable_substitute(MAIL_FILE, buf, 256);
6489 current_mail_spool = strdup(buf);
6493 update_interval = 10.0;
6494 stuff_in_upper_case = 0;
6496 #ifdef TCP_PORT_MONITOR
6497 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6501 static void load_config_file(const char *f)
6503 #define CONF_ERR ERR("%s: %d: config file error", f, line)
6507 set_default_configurations();
6513 char buf[256], *p, *p2, *name, *value;
6515 if (fgets(buf, 256, fp) == NULL)
6520 /* break at comment */
6521 p2 = strchr(p, '#');
6526 while (*p && isspace((int) *p))
6529 continue; /* empty line */
6535 while (*p2 && !isspace((int) *p2))
6538 *p2 = '\0'; /* break at name's end */
6545 while (*p && isspace((int) *p))
6550 p2 = value + strlen(value);
6551 while (isspace((int) *(p2 - 1)))
6557 #define CONF2(a) if (strcasecmp(name, a) == 0)
6558 #define CONF(a) else CONF2(a)
6559 #define CONF3(a,b) \
6560 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
6564 CONF2("alignment") {
6566 int a = string_to_alignment(value);
6574 CONF("background") {
6575 fork_to_background = string_to_bool(value);
6579 CONF2("background") {
6580 fork_to_background = string_to_bool(value);
6584 CONF("border_margin") {
6586 border_margin = strtol(value, 0, 0);
6590 CONF("border_width") {
6592 border_width = strtol(value, 0, 0);
6596 CONF("default_color") {
6598 default_fg_color = get_x11_color(value);
6602 CONF3("default_shade_color", "default_shadecolor") {
6604 default_bg_color = get_x11_color(value);
6608 CONF3("default_outline_color", "default_outlinecolor") {
6610 default_out_color = get_x11_color(value);
6617 info.mail = parse_mail_args(IMAP, value);
6624 info.mail = parse_mail_args(POP3, value);
6632 strncpy(info.mpd.host, value, 127);
6638 info.mpd.port = strtol(value, 0, 0);
6639 if (info.mpd.port < 1
6640 || info.mpd.port > 0xffff)
6644 CONF("mpd_password") {
6646 strncpy(info.mpd.password, value, 127);
6652 CONF("sensor_device") {
6654 sensor_device = strtol(value, 0, 0);
6659 CONF("cpu_avg_samples") {
6661 cpu_avg_samples = strtol(value, 0, 0);
6662 if (cpu_avg_samples < 1
6663 || cpu_avg_samples > 14)
6672 CONF("net_avg_samples") {
6674 net_avg_samples = strtol(value, 0, 0);
6675 if (net_avg_samples < 1
6676 || net_avg_samples > 14)
6692 CONF("double_buffer") {
6693 use_xdbe = string_to_bool(value);
6697 CONF("override_utf8_locale") {
6698 utf8_mode = string_to_bool(value);
6701 CONF("draw_borders") {
6702 draw_borders = string_to_bool(value);
6704 CONF("draw_graph_borders") {
6705 draw_graph_borders = string_to_bool(value);
6707 CONF("draw_shades") {
6708 draw_shades = string_to_bool(value);
6710 CONF("draw_outline") {
6711 draw_outline = string_to_bool(value);
6714 CONF("out_to_console") {
6715 out_to_console = string_to_bool(value);
6717 CONF("use_spacer") {
6718 use_spacer = string_to_bool(value);
6723 use_xft = string_to_bool(value);
6727 set_first_font(value);
6732 if (value && font_count >= 0)
6733 fonts[0].font_alpha = atof(value)
6742 if (string_to_bool(value))
6743 ERR("Xft not enabled");
6746 /* xftfont silently ignored when no Xft */
6749 /* xftalpha is silently ignored when no Xft */
6754 set_first_font(value);
6763 gap_x = atoi(value);
6769 gap_y = atoi(value);
6774 CONF("mail_spool") {
6777 variable_substitute(value, buf, 256);
6781 if (current_mail_spool)
6782 free(current_mail_spool);
6783 current_mail_spool = strdup(buf);
6789 CONF("minimum_size") {
6792 (value, "%d %d", &minimum_width,
6793 &minimum_height) != 2)
6796 &minimum_width) != 1)
6801 CONF("maximum_width") {
6803 if (sscanf(value, "%d", &maximum_width) != 1)
6809 CONF("no_buffers") {
6810 no_buffers = string_to_bool(value);
6812 CONF("pad_percents") {
6813 pad_percents = atoi(value);
6817 CONF("own_window") {
6819 own_window = string_to_bool(value);
6823 CONF("own_window_class") {
6826 memset(window.class_name,0,sizeof(window.class_name));
6827 strncpy(window.class_name, value, sizeof(window.class_name)-1);
6832 CONF("own_window_title") {
6835 memset(window.title,0,sizeof(window.title));
6836 strncpy(window.title, value, sizeof(window.title)-1);
6841 CONF("own_window_transparent") {
6843 set_transparent = string_to_bool(value);
6847 CONF("own_window_colour") {
6849 background_colour = get_x11_color(value);
6851 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
6854 CONF("own_window_hints") {
6856 char *p_hint, *p_save;
6857 char delim[] = ", ";
6859 /* tokenize the value into individual hints */
6860 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
6862 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
6863 if (strncmp(p_hint,"undecorate",10) == 0)
6864 SET_HINT(window.hints,HINT_UNDECORATED);
6865 else if (strncmp(p_hint,"below",5) == 0)
6866 SET_HINT(window.hints,HINT_BELOW);
6867 else if (strncmp(p_hint,"above",5) == 0)
6868 SET_HINT(window.hints,HINT_ABOVE);
6869 else if (strncmp(p_hint,"sticky",6) == 0)
6870 SET_HINT(window.hints,HINT_STICKY);
6871 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
6872 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
6873 else if (strncmp(p_hint,"skip_pager",10) == 0)
6874 SET_HINT(window.hints,HINT_SKIP_PAGER);
6878 p_hint=strtok_r(NULL, delim, &p_save);
6880 while (p_hint!=NULL);
6885 CONF("own_window_type") {
6887 if (strncmp(value,"normal",6)==0)
6888 window.type = TYPE_NORMAL;
6889 else if (strncmp(value,"desktop",7)==0)
6890 window.type = TYPE_DESKTOP;
6891 else if (strncmp(value,"override",8)==0)
6892 window.type = TYPE_OVERRIDE;
6900 CONF("stippled_borders") {
6902 stippled_borders = strtol(value, 0, 0);
6904 stippled_borders = 4;
6908 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
6911 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
6913 CONF("update_interval") {
6915 update_interval = strtod(value, 0);
6919 CONF("total_run_times") {
6921 total_run_times = strtod(value, 0);
6926 stuff_in_upper_case = string_to_bool(value);
6928 CONF("max_specials") {
6930 max_specials = atoi(value);
6934 CONF("max_user_text") {
6936 max_user_text = atoi(value);
6940 CONF("text_buffer_size") {
6942 text_buffer_size = atoi(value);
6947 if (text != original_text)
6957 int l = strlen(text);
6958 if (fgets(buf, 256, fp) == NULL)
6961 realloc(text, l + strlen(buf)
6965 if (strlen(text) > max_user_text)
6969 text_lines = line + 1;
6972 #ifdef TCP_PORT_MONITOR
6973 CONF("max_port_monitor_connections")
6976 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
6977 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
6979 /* an error. use default, warn and continue. */
6980 tcp_port_monitor_args.max_port_monitor_connections =
6981 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6984 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
6986 /* no error, just use default */
6987 tcp_port_monitor_args.max_port_monitor_connections =
6988 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6990 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
6995 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7007 /* : means that character before that takes an argument */
7008 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
7021 int main(int argc, char **argv)
7023 struct sigaction act, oact;
7026 memset(&info, 0, sizeof(info) );
7028 #ifdef TCP_PORT_MONITOR
7029 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7032 /* handle command line parameters that don't change configs */
7037 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7038 *s) || ((s = getenv("LANG")) && *s)) {
7039 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7041 ERR("malloc failed");
7043 for (x = 0; x < strlen(s); x++) {
7044 temp[x] = tolower(s[x]);
7046 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7052 if (!setlocale(LC_CTYPE, "")) {
7053 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7057 int c = getopt(argc,
7068 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
7069 * though free() does the NULL check itself;), then load optarg value */
7071 free(current_config);
7072 current_config = strdup(optarg);
7077 ("Usage: %s [OPTION]...\n"
7078 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7079 "window. Command line options will override configurations defined in config\n"
7082 " -c FILE config file to load instead of "
7085 " -d daemonize, fork to background\n"
7088 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7089 " -f FONT font to use\n"
7091 " -o create own window to draw\n"
7094 " -b double buffer (prevents flickering)\n"
7096 " -w WIN_ID window id to draw\n"
7097 " -x X x position\n"
7098 " -y Y y position\n"
7100 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
7101 " -u SECS update interval\n"
7102 " -i NUM number of times to update Conky\n", argv[0]);
7106 window.window = strtol(optarg, 0, 0);
7115 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7119 /* load current_config or CONFIG_FILE */
7122 if (current_config == NULL) {
7123 /* load default config file */
7126 variable_substitute(CONFIG_FILE, buf, 256);
7129 current_config = strdup(buf);
7133 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
7134 load_config_file(current_config);
7136 set_default_configurations();
7139 /* init specials array */
7140 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7141 ERR("failed to create specials array");
7144 if (current_mail_spool == NULL) {
7146 variable_substitute(MAIL_FILE, buf, 256);
7149 current_mail_spool = strdup(buf);
7153 /* handle other command line arguments */
7155 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
7156 optind = optreset = 1;
7161 #if defined(__FreeBSD__)
7162 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7163 O_RDONLY, "kvm_open")) == NULL)
7164 CRIT_ERR( "cannot read kvm");
7168 int c = getopt(argc,
7176 fork_to_background = 1;
7181 set_first_font(optarg);
7184 text_alignment = string_to_alignment(optarg);
7199 if (text != original_text)
7201 text = strdup(optarg);
7202 convert_escapes(text);
7206 update_interval = strtod(optarg, 0);
7210 total_run_times = strtod(optarg, 0);
7214 gap_x = atoi(optarg);
7218 gap_y = atoi(optarg);
7232 /* generate text and get initial size */
7233 extract_variable_text(text);
7234 if (text != original_text) {
7239 if (fork_to_background) {
7243 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
7249 fprintf(stderr,"\n"); fflush(stderr);
7253 /* parent process */
7254 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
7261 update_text_area(); /* to get initial size of the window */
7265 text_width + border_margin * 2 + 1,
7266 text_height + border_margin * 2 + 1,
7267 set_transparent, background_colour, argv, argc);
7270 update_text_area(); /* to position text/window on screen */
7275 if (own_window && !fixed_pos) {
7276 XMoveWindow(display, window.window, window.x, window.y);
7279 set_transparent_background(window.window);
7290 /* Set signal handlers */
7291 act.sa_handler = signal_handler;
7292 sigemptyset(&act.sa_mask);
7295 act.sa_flags |= SA_RESTART;
7298 if ( sigaction(SIGINT,&act,&oact) < 0 ||
7299 sigaction(SIGUSR1,&act,&oact) < 0 ||
7300 sigaction(SIGTERM,&act,&oact) < 0 )
7302 ERR("error setting signal handler: %s", strerror(errno) );
7306 if (create_audacious_thread() !=0)
7307 CRIT_ERR("unable to create audacious thread!");
7308 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
7319 #if defined(__FreeBSD__)
7326 void signal_handler(int sig)
7328 /* signal handler is light as a feather, as it should be.
7329 * we will poll g_signal_pending with each loop of conky
7330 * and do any signal processing there, NOT here. */
7331 g_signal_pending=sig;