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;
299 static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
301 /* create own window or draw stuff to root? */
302 static int set_transparent = 0;
306 static int own_window = 0;
307 static int background_colour = 0;
308 /* fixed size/pos is set if wm/user changes them */
309 static int fixed_size = 0, fixed_pos = 0;
312 static int minimum_width, minimum_height;
313 static int maximum_width;
318 static int sensor_device;
321 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
322 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
324 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
325 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
327 /* maximum size of individual text buffers, ie $exec buffer size */
328 unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
331 #define CODEPAGE_LENGTH 20
334 char iconv_converting;
335 static iconv_t **iconv_cd = 0;
337 int register_iconv(iconv_t *new_iconv)
340 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
342 iconv_cd = malloc(sizeof(iconv_t *));
345 CRIT_ERR("Out of memory");
347 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
348 if (!iconv_cd[iconv_count]) {
349 CRIT_ERR("Out of memory");
351 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
356 void free_iconv(void)
360 for (i = iconv_count; i < 0; i++) {
376 /* no buffers in used memory? */
379 /* pad percentages to decimals? */
380 static int pad_percents = 0;
382 #ifdef TCP_PORT_MONITOR
383 tcp_port_monitor_args_t tcp_port_monitor_args;
386 /* Text that is shown */
387 static char original_text[] =
388 "$nodename - $sysname $kernel on $machine\n"
390 "${color grey}Uptime:$color $uptime\n"
391 "${color grey}Frequency (in MHz):$color $freq\n"
392 "${color grey}Frequency (in GHz):$color $freq_g\n"
393 "${color grey}RAM Usage:$color $mem/$memmax - $memperc% ${membar 4}\n"
394 "${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4}\n"
395 "${color grey}CPU Usage:$color $cpu% ${cpubar 4}\n"
396 "${color grey}Processes:$color $processes ${color grey}Running:$color $running_processes\n"
398 "${color grey}File systems:\n"
399 " / $color${fs_free /}/${fs_size /} ${fs_bar 6 /}\n"
400 "${color grey}Networking:\n"
401 " Up:$color ${upspeed eth0} k/s${color grey} - Down:$color ${downspeed eth0} k/s\n"
404 "${color grey}MPD: $mpd_status $mpd_artist - $mpd_title from $mpd_album at $mpd_vol\n"
405 "Bitrate: $mpd_bitrate\n" "Progress: $mpd_bar\n"
408 "${color grey}XMMS2: $xmms2_status $xmms2_artist - $xmms2_title from $xmms2_album\n"
409 "Progress: $xmms2_bar\n"
411 "${color grey}Name PID CPU% MEM%\n"
412 " ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}\n"
413 " ${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}\n"
414 " ${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}\n"
415 " ${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}\n"
416 "${tail /var/log/Xorg.0.log 3}";
418 static char *text = original_text;
421 static int total_updates;
424 static int blockdepth = 0;
425 static int if_jumped = 0;
426 static int blockstart[MAX_IF_BLOCK_DEPTH];
428 int check_mount(char *s)
430 #if defined(__linux__)
432 FILE *mtab = fopen("/etc/mtab", "r");
434 char buf1[256], buf2[128];
435 while (fgets(buf1, 256, mtab)) {
436 sscanf(buf1, "%*s %128s", buf2);
437 if (!strcmp(s, buf2)) {
444 ERR("Could not open mtab");
447 #elif defined(__FreeBSD__)
448 struct statfs *mntbuf;
451 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
452 for (i = mntsize - 1; i >= 0; i--)
453 if (strcmp(mntbuf[i].f_mntonname, s) == 0)
457 #elif defined(__OpenBSD__)
464 int check_contains(char *f, char *s)
467 FILE *where = fopen(f, "r");
469 char buf1[256], buf2[256];
470 while (fgets(buf1, 256, where)) {
471 sscanf(buf1, "%255s", buf2);
472 if (strstr(buf2, s)) {
479 ERR("Could not open the file");
486 static inline int calc_text_width(const char *s, int l)
492 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
494 XftTextExtents8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
500 return XTextWidth(fonts[selected_font].font, s, l);
505 /* formatted text to render on screen, generated in generate_text(),
506 * drawn in draw_stuff() */
508 static char text_buffer[TEXT_BUFFER_SIZE * 4];
510 /* special stuff in text_buffer */
512 #define SPECIAL_CHAR '\x01'
541 unsigned long first_colour; // for graph gradient
542 unsigned long last_colour;
545 /* create specials array on heap instead of stack with introduction of max_specials */
546 static struct special_t *specials = NULL;
548 static unsigned int special_count;
550 static unsigned int special_index; /* used when drawing */
553 #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? */
555 static struct special_t *new_special(char *buf, int t)
557 if (special_count >= max_specials)
558 CRIT_ERR("too many special things in text");
560 buf[0] = SPECIAL_CHAR;
562 specials[special_count].type = t;
563 return &specials[special_count++];
566 long fwd_fcharfind(FILE* fp, char val, unsigned int step) {
569 unsigned int count = 0;
570 static char buf[BUFSZ];
571 long orig_pos = ftell(fp);
573 long buf_size = BUFSZ;
574 char* cur_found = NULL;
575 while(count < step) {
576 if(cur_found == NULL) {
577 buf_size = fread(buf, 1, buf_size, fp);
580 cur_found = memchr(buf+buf_pos, val, buf_size-buf_pos);
581 if(cur_found != NULL) {
582 buf_pos = cur_found-buf+1;
591 ret = ftell(fp) - buf_size + buf_pos - 1;
592 fseek(fp, orig_pos, SEEK_SET);
599 memrchr (const void *buffer, int c, size_t n)
601 const unsigned char *p = buffer;
603 for (p += n; n ; n--)
609 long rev_fcharfind(FILE* fp, char val, unsigned int step) {
612 unsigned int count = 0;
613 static char buf[BUFSZ];
614 long orig_pos = ftell(fp);
616 long file_pos = orig_pos;
617 long buf_size = BUFSZ;
619 while(count < step) {
621 if(file_pos > BUFSZ) {
622 fseek(fp, file_pos-BUFSZ, SEEK_SET);
626 fseek(fp, 0, SEEK_SET);
628 file_pos = ftell(fp);
629 buf_pos = fread(buf, 1, buf_size, fp);
636 if(cur_found != NULL) {
637 buf_pos = cur_found-buf;
646 fseek(fp, orig_pos, SEEK_SET);
648 ret = file_pos + buf_pos;
653 static void new_bar(char *buf, int w, int h, int usage)
655 struct special_t *s = new_special(buf, BAR);
656 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
661 static const char *scan_bar(const char *args, int *w, int *h)
663 *w = 0; /* zero width means all space that is available */
665 /* bar's argument is either height or height,width */
668 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
669 sscanf(args, "%d %n", h, &n);
676 static char *scan_font(const char *args)
678 if (args && sizeof(args) < 127) {
685 static void new_font(char *buf, char * args) {
687 struct special_t *s = new_special(buf, FONT);
688 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
689 int tmp = selected_font;
690 selected_font = s->font_added = addfont(args);
695 struct special_t *s = new_special(buf, FONT);
696 int tmp = selected_font;
697 selected_font = s->font_added = 0;
704 inline void graph_append(struct special_t *graph, double f)
706 if (!graph->scaled && f > graph->graph_scale) {
707 f = graph->graph_scale;
711 graph->graph_scale = 1;
713 graph->graph[0] = f; /* add new data */
714 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
715 graph->graph[i] = graph->graph[i - 1];
716 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
717 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
722 short colour_depth = 0;
723 void set_up_gradient();
725 /* precalculated: 31/255, and 63/255 */
726 #define CONST_8_TO_5_BITS 0.12156862745098
727 #define CONST_8_TO_6_BITS 0.247058823529412
729 /* adjust color values depending on color depth*/
730 static unsigned int adjust_colors(unsigned int color)
733 if (colour_depth == 0) {
736 if (colour_depth == 16) {
737 r = (color & 0xff0000) >> 16;
738 g = (color & 0xff00) >> 8;
740 color = (int)(r * CONST_8_TO_5_BITS) << 11;
741 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
742 color |= (int)(b * CONST_8_TO_5_BITS);
747 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
749 struct special_t *s = new_special(buf, GRAPH);
751 if (s->graph == NULL) {
752 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
753 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
755 s->graph_width = MAX_GRAPH_DEPTH - 2;
757 s->graph = malloc(s->graph_width * sizeof(double));
758 memset(s->graph, 0, s->graph_width * sizeof(double));
759 s->graph_scale = 100;
762 s->first_colour = adjust_colors(first_colour);
763 s->last_colour = adjust_colors(second_colour);
770 s->graph_width = s->width - 2; // subtract 2 for rectangle around
775 s->graph_scale = scale;
782 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
784 *w = 0; /* zero width means all space that is available */
788 /* graph's argument is either height or height,width */
790 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
791 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
793 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
795 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
798 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
802 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
805 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
809 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
812 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
816 if (sscanf(args, "%d,%d", h, w) < 2) {
819 sscanf(args, "%*s %d,%d", h, w);
825 static inline void new_hr(char *buf, int a)
827 new_special(buf, HORIZONTAL_LINE)->height = a;
830 static inline void new_stippled_hr(char *buf, int a, int b)
832 struct special_t *s = new_special(buf, STIPPLED_HR);
837 static inline void new_fg(char *buf, long c)
839 new_special(buf, FG)->arg = c;
842 static inline void new_bg(char *buf, long c)
844 new_special(buf, BG)->arg = c;
847 static inline void new_outline(char *buf, long c)
849 new_special(buf, OUTLINE)->arg = c;
852 static inline void new_offset(char *buf, long c)
854 new_special(buf, OFFSET)->arg = c;
857 static inline void new_voffset(char *buf, long c)
859 new_special(buf, VOFFSET)->arg = c;
862 static inline void new_alignr(char *buf, long c)
864 new_special(buf, ALIGNR)->arg = c;
867 static inline void new_alignc(char *buf, long c)
869 new_special(buf, ALIGNC)->arg = c;
872 static inline void new_goto(char *buf, long c)
874 new_special(buf, GOTO)->arg = c;
877 static inline void new_tab(char *buf, int a, int b) {
878 struct special_t *s = new_special(buf, TAB);
883 /* quite boring functions */
885 static inline void for_each_line(char *b, void (*f) (char *))
889 for (ps = b, pe = b; *pe; pe++) {
902 static void convert_escapes(char *buf)
904 char *p = buf, *s = buf;
920 /* converts from bytes to human readable format (k, M, G, T) */
921 static void human_readable(long long a, char *buf, int size)
923 // Strange conditional due to possible overflows
924 if(a / 1024 / 1024 / 1024.0 > 1024.0){
925 snprintf(buf, size, "%.2fTiB", (a / 1024 / 1024 / 1024) / 1024.0);
927 else if (a >= 1024 * 1024 * 1024) {
928 snprintf(buf, size, "%.2fGiB", (a / 1024 / 1024) / 1024.0);
930 else if (a >= 1024 * 1024) {
931 double m = (a / 1024) / 1024.0;
933 snprintf(buf, size, "%.0fMiB", m);
935 snprintf(buf, size, "%.1fMiB", m);
936 } else if (a >= 1024)
937 snprintf(buf, size, "%LdKiB", a / (long long) 1024);
939 snprintf(buf, size, "%LdB", a);
944 enum text_object_type {
978 OBJ_diskiograph_read,
979 OBJ_diskiograph_write,
1012 #if defined(__linux__)
1018 OBJ_i8k_left_fan_status,
1019 OBJ_i8k_right_fan_status,
1020 OBJ_i8k_left_fan_rpm,
1021 OBJ_i8k_right_fan_rpm,
1023 OBJ_i8k_buttons_status,
1031 #endif /* __linux__ */
1060 OBJ_running_processes,
1069 OBJ_temp1, /* i2c is used instead in these */
1089 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1091 OBJ_apm_battery_time,
1092 OBJ_apm_battery_life,
1093 #endif /* __FreeBSD__ __OpenBSD__ */
1095 OBJ_obsd_sensors_temp,
1096 OBJ_obsd_sensors_fan,
1097 OBJ_obsd_sensors_volt,
1100 #endif /* __OpenBSD__ */
1129 OBJ_xmms2_transport,
1144 OBJ_audacious_status,
1145 OBJ_audacious_title,
1146 OBJ_audacious_length,
1147 OBJ_audacious_length_seconds,
1148 OBJ_audacious_position,
1149 OBJ_audacious_position_seconds,
1150 OBJ_audacious_bitrate,
1151 OBJ_audacious_frequency,
1152 OBJ_audacious_channels,
1153 OBJ_audacious_filename,
1154 OBJ_audacious_playlist_length,
1155 OBJ_audacious_playlist_position,
1166 #ifdef TCP_PORT_MONITOR
1177 OBJ_entropy_poolsize,
1181 struct text_object {
1185 unsigned int c, d, e;
1189 char *s; /* some string */
1190 int i; /* some integer */
1191 long l; /* some other integer */
1192 unsigned int sensor;
1193 struct net_stat *net;
1195 unsigned char loadavg[3];
1196 unsigned int cpu_index;
1197 struct mail_s *mail;
1205 char *tz; /* timezone variable */
1206 char *fmt; /* time display formatting */
1259 timed_thread *p_timed_thread;
1265 #ifdef TCP_PORT_MONITOR
1267 in_port_t port_range_begin; /* starting port to monitor */
1268 in_port_t port_range_end; /* ending port to monitor */
1269 int item; /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1270 int connection_index; /* 0 to n-1 connections. */
1283 struct text_object_list {
1284 unsigned int text_object_count;
1285 struct text_object *text_objects;
1288 static unsigned int text_object_count;
1289 static struct text_object *text_objects;
1290 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1292 #define MAXDATASIZE 1000
1296 struct mail_s* parse_mail_args(char type, const char *arg) {
1297 struct mail_s *mail;
1298 mail = malloc(sizeof(struct mail_s));
1299 memset(mail, 0, sizeof(struct mail_s));
1301 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1303 ERR("Scanning IMAP args failed");
1304 } else if (type == IMAP) {
1305 ERR("Scanning POP3 args failed");
1308 // see if password needs prompting
1309 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1310 int fp = fileno(stdin);
1311 struct termios term;
1312 tcgetattr(fp, &term);
1313 term.c_lflag &= ~ECHO;
1314 tcsetattr(fp, TCSANOW, &term);
1315 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1316 scanf("%128s", mail->pass);
1318 term.c_lflag |= ECHO;
1319 tcsetattr(fp, TCSANOW, &term);
1321 // now we check for optional args
1322 tmp = strstr(arg, "-i ");
1325 sscanf(tmp, "%f", &mail->interval);
1327 mail->interval = 300; // 5 minutes
1329 tmp = strstr(arg, "-p ");
1332 sscanf(tmp, "%lu", &mail->port);
1335 mail->port = 110; // default pop3 port
1336 } else if (type == IMAP) {
1337 mail->port = 143; // default imap port
1341 tmp = strstr(arg, "-f ");
1344 sscanf(tmp, "%s", mail->folder);
1346 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1349 tmp = strstr(arg, "-e ");
1353 if (tmp[0] == '\'') {
1354 len = strstr(tmp+1, "'") - tmp - 1;
1359 strncpy(mail->command, tmp+1, len);
1361 mail->command[0] = '\0';
1363 mail->p_timed_thread = NULL;
1367 void *imap_thread(struct mail_s* mail)
1369 int sockfd, numbytes;
1370 char recvbuf[MAXDATASIZE];
1371 char sendbuf[MAXDATASIZE];
1374 unsigned int old_unseen = UINT_MAX;
1375 unsigned int old_messages = UINT_MAX;
1376 struct stat stat_buf;
1378 struct sockaddr_in their_addr; // connector's address information
1379 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1380 herror("gethostbyname");
1385 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1387 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1390 goto next_iteration;
1393 their_addr.sin_family = AF_INET; // host byte order
1394 their_addr.sin_port = htons(mail->port); // short, network byte order
1395 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1396 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1399 (sockfd, (struct sockaddr *) &their_addr,
1400 sizeof(struct sockaddr)) == -1) {
1403 goto next_iteration;
1405 struct timeval timeout;
1408 timeout.tv_sec = 60; // 60 second timeout i guess
1409 timeout.tv_usec = 0;
1411 FD_SET(sockfd, &fdset);
1412 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1415 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1419 goto next_iteration;
1422 ERR("IMAP connection failed: timeout");
1424 goto next_iteration;
1426 recvbuf[numbytes] = '\0';
1427 if (strstr(recvbuf, "* OK") != recvbuf) {
1428 ERR("IMAP connection failed, probably not an IMAP server");
1430 goto next_iteration;
1432 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1433 strncat(sendbuf, mail->user,
1434 MAXDATASIZE - strlen(sendbuf) - 1);
1435 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1436 strncat(sendbuf, mail->pass,
1437 MAXDATASIZE - strlen(sendbuf) - 1);
1438 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1439 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1442 goto next_iteration;
1444 timeout.tv_sec = 60; // 60 second timeout i guess
1445 timeout.tv_usec = 0;
1447 FD_SET(sockfd, &fdset);
1448 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1451 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1455 goto next_iteration;
1458 recvbuf[numbytes] = '\0';
1459 if (strstr(recvbuf, "a1 OK") == NULL) {
1460 ERR("IMAP server login failed: %s", recvbuf);
1462 goto next_iteration;
1464 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1465 strncat(sendbuf, mail->folder,
1466 MAXDATASIZE - strlen(sendbuf) - 1);
1467 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1468 MAXDATASIZE - strlen(sendbuf) - 1);
1469 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1472 goto next_iteration;
1474 timeout.tv_sec = 60; // 60 second timeout i guess
1475 timeout.tv_usec = 0;
1477 FD_SET(sockfd, &fdset);
1478 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1481 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1485 goto next_iteration;
1488 recvbuf[numbytes] = '\0';
1489 if (strstr(recvbuf, "a2 OK") == NULL) {
1490 ERR("IMAP status failed: %s", recvbuf);
1492 goto next_iteration;
1494 // now we get the data
1495 reply = strstr(recvbuf, " (MESSAGES ");
1497 *strchr(reply, ')') = '\0';
1498 if (reply == NULL) {
1499 ERR("Error parsing IMAP response: %s", recvbuf);
1501 goto next_iteration;
1503 timed_thread_lock (mail->p_timed_thread);
1504 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1507 timed_thread_unlock (mail->p_timed_thread);
1509 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1510 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1513 goto next_iteration;
1515 timeout.tv_sec = 60; // 60 second timeout i guess
1516 timeout.tv_usec = 0;
1518 FD_SET(sockfd, &fdset);
1519 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1522 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1526 goto next_iteration;
1529 recvbuf[numbytes] = '\0';
1530 if (strstr(recvbuf, "a3 OK") == NULL) {
1531 ERR("IMAP logout failed: %s", recvbuf);
1533 goto next_iteration;
1535 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1536 if (system(mail->command) == -1) {
1541 old_unseen = mail->unseen;
1542 old_messages = mail->messages;
1544 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1545 /* if a valid socket, close it */
1547 if (timed_thread_test (mail->p_timed_thread))
1548 timed_thread_exit (mail->p_timed_thread);
1553 void *pop3_thread(struct mail_s *mail)
1555 int sockfd, numbytes;
1556 char recvbuf[MAXDATASIZE];
1557 char sendbuf[MAXDATASIZE];
1560 unsigned int old_unseen = UINT_MAX;
1561 struct stat stat_buf;
1563 struct sockaddr_in their_addr; // connector's address information
1564 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1565 herror("gethostbyname");
1570 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1572 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1575 goto next_iteration;
1578 their_addr.sin_family = AF_INET; // host byte order
1579 their_addr.sin_port = htons(mail->port); // short, network byte order
1580 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1581 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1584 (sockfd, (struct sockaddr *) &their_addr,
1585 sizeof(struct sockaddr)) == -1) {
1588 goto next_iteration;
1590 struct timeval timeout;
1593 timeout.tv_sec = 60; // 60 second timeout i guess
1594 timeout.tv_usec = 0;
1596 FD_SET(sockfd, &fdset);
1597 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1600 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1604 goto next_iteration;
1607 ERR("POP3 connection failed: timeout\n");
1609 goto next_iteration;
1611 recvbuf[numbytes] = '\0';
1612 if (strstr(recvbuf, "+OK ") != recvbuf) {
1613 ERR("POP3 connection failed, probably not a POP3 server");
1615 goto next_iteration;
1617 strncpy(sendbuf, "USER ", MAXDATASIZE);
1618 strncat(sendbuf, mail->user,
1619 MAXDATASIZE - strlen(sendbuf) - 1);
1620 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1621 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1622 perror("send USER");
1624 goto next_iteration;
1626 timeout.tv_sec = 60; // 60 second timeout i guess
1627 timeout.tv_usec = 0;
1629 FD_SET(sockfd, &fdset);
1630 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1633 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1635 perror("recv USER");
1637 goto next_iteration;
1640 recvbuf[numbytes] = '\0';
1641 if (strstr(recvbuf, "+OK ") == NULL) {
1642 ERR("POP3 server login failed: %s", recvbuf);
1644 goto next_iteration;
1646 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1647 strncat(sendbuf, mail->pass,
1648 MAXDATASIZE - strlen(sendbuf) - 1);
1649 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1650 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1651 perror("send PASS");
1653 goto next_iteration;
1655 timeout.tv_sec = 60; // 60 second timeout i guess
1656 timeout.tv_usec = 0;
1658 FD_SET(sockfd, &fdset);
1659 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1662 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1664 perror("recv PASS");
1666 goto next_iteration;
1669 recvbuf[numbytes] = '\0';
1670 if (strstr(recvbuf, "+OK ") == NULL) {
1671 ERR("POP3 server login failed: %s", recvbuf);
1673 goto next_iteration;
1675 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1676 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1677 perror("send STAT");
1679 goto next_iteration;
1681 timeout.tv_sec = 60; // 60 second timeout i guess
1682 timeout.tv_usec = 0;
1684 FD_SET(sockfd, &fdset);
1685 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1688 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1690 perror("recv STAT");
1692 goto next_iteration;
1695 recvbuf[numbytes] = '\0';
1696 if (strstr(recvbuf, "+OK ") == NULL) {
1697 ERR("POP3 status failed: %s", recvbuf);
1699 goto next_iteration;
1701 // now we get the data
1702 reply = recvbuf + 4;
1703 if (reply == NULL) {
1704 ERR("Error parsing POP3 response: %s", recvbuf);
1706 goto next_iteration;
1708 timed_thread_lock (mail->p_timed_thread);
1709 sscanf(reply, "%lu %lu", &mail->unseen,
1711 timed_thread_unlock (mail->p_timed_thread);
1713 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1714 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1715 perror("send QUIT");
1717 goto next_iteration;
1719 timeout.tv_sec = 60; // 60 second timeout i guess
1720 timeout.tv_usec = 0;
1722 FD_SET(sockfd, &fdset);
1723 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1726 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1728 perror("recv QUIT");
1730 goto next_iteration;
1733 recvbuf[numbytes] = '\0';
1734 if (strstr(recvbuf, "+OK") == NULL) {
1735 ERR("POP3 logout failed: %s", recvbuf);
1737 goto next_iteration;
1739 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1740 if (system(mail->command) == -1) {
1745 old_unseen = mail->unseen;
1747 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1748 /* if a valid socket, close it */
1750 if (timed_thread_test (mail->p_timed_thread))
1751 timed_thread_exit (mail->p_timed_thread);
1757 void *threaded_exec(struct text_object *obj) {
1759 char *p2 = obj->data.texeci.buffer;
1760 FILE *fp = popen(obj->data.texeci.cmd,"r");
1761 timed_thread_lock (obj->data.texeci.p_timed_thread);
1762 int n2 = fread(p2, 1, text_buffer_size, fp);
1765 if (n2 && p2[n2 - 1] == '\n') {
1769 if (*p2 == '\001') {
1774 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1775 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1776 timed_thread_exit (obj->data.texeci.p_timed_thread);
1781 static struct text_object *new_text_object_internal()
1783 struct text_object *obj = malloc(sizeof(struct text_object));
1784 memset(obj, 0, sizeof(struct text_object));
1788 static void free_text_objects(unsigned int count, struct text_object *objs)
1791 for (i = 0; i < count; i++) {
1792 switch (objs[i].type) {
1794 close(objs[i].data.i);
1797 close(objs[i].data.i);
1800 close(objs[i].data.i2c.fd);
1803 free(objs[i].data.s);
1806 free(objs[i].data.s);
1809 free(objs[i].data.tztime.tz);
1810 free(objs[i].data.tztime.fmt);
1813 free(objs[i].data.mboxscan.args);
1814 free(objs[i].data.mboxscan.output);
1819 case OBJ_imap_unseen:
1820 if (!objs[i].global_mode) {
1821 free(objs[i].data.mail);
1824 case OBJ_imap_messages:
1825 if (!objs[i].global_mode) {
1826 free(objs[i].data.mail);
1832 case OBJ_pop3_unseen:
1833 if (!objs[i].global_mode) {
1834 free(objs[i].data.mail);
1838 if (!objs[i].global_mode) {
1839 free(objs[i].data.mail);
1843 case OBJ_if_existing:
1844 case OBJ_if_mounted:
1845 case OBJ_if_running:
1846 free(objs[i].data.ifblock.s);
1847 free(objs[i].data.ifblock.str);
1850 free(objs[i].data.tail.logfile);
1851 free(objs[i].data.tail.buffer);
1853 case OBJ_text: case OBJ_font:
1854 free(objs[i].data.s);
1857 free(objs[i].data.s);
1860 free(objs[i].data.s);
1863 free(objs[i].data.s);
1866 free(objs[i].data.s);
1868 /* case OBJ_execibar:
1869 free(objs[i].data.s);
1871 case OBJ_execigraph:
1872 free(objs[i].data.s);
1875 case OBJ_iconv_start:
1881 if (info.mpd.title) {
1882 free(info.mpd.title);
1886 case OBJ_mpd_artist:
1887 if (info.mpd.artist) {
1888 free(info.mpd.artist);
1889 info.mpd.artist = 0;
1893 if (info.mpd.album) {
1894 free(info.mpd.album);
1898 case OBJ_mpd_random:
1899 if (info.mpd.random) {
1900 free(info.mpd.random);
1901 info.mpd.random = 0;
1904 case OBJ_mpd_repeat:
1905 if (info.mpd.repeat) {
1906 free(info.mpd.repeat);
1907 info.mpd.repeat = 0;
1911 if (info.mpd.track) {
1912 free(info.mpd.track);
1917 if (info.mpd.name) {
1918 free(info.mpd.name);
1923 if (info.mpd.file) {
1924 free(info.mpd.file);
1928 case OBJ_mpd_status:
1929 if (info.mpd.status) {
1930 free(info.mpd.status);
1931 info.mpd.status = 0;
1935 if (info.mpd.artist) {
1936 free(info.mpd.artist);
1937 info.mpd.artist = 0;
1939 if (info.mpd.title) {
1940 free(info.mpd.title);
1943 if (info.mpd.file) {
1944 free(info.mpd.file);
1951 case OBJ_xmms2_artist:
1952 if (info.xmms2.artist) {
1953 free(info.xmms2.artist);
1954 info.xmms2.artist = 0;
1957 case OBJ_xmms2_album:
1958 if (info.xmms2.album) {
1959 free(info.xmms2.album);
1960 info.xmms2.album = 0;
1963 case OBJ_xmms2_title:
1964 if (info.xmms2.title) {
1965 free(info.xmms2.title);
1966 info.xmms2.title = 0;
1969 case OBJ_xmms2_genre:
1970 if (info.xmms2.genre) {
1971 free(info.xmms2.genre);
1972 info.xmms2.genre = 0;
1975 case OBJ_xmms2_comment:
1976 if (info.xmms2.comment) {
1977 free(info.xmms2.comment);
1978 info.xmms2.comment = 0;
1981 case OBJ_xmms2_decoder:
1982 if (info.xmms2.decoder) {
1983 free(info.xmms2.decoder);
1987 case OBJ_xmms2_transport:
1988 if (info.xmms2.transport) {
1989 free(info.xmms2.transport);
1994 if (info.xmms2.url) {
1995 free(info.xmms2.url);
1999 case OBJ_xmms2_date:
2000 if (info.xmms2.date) {
2001 free(info.xmms2.date);
2002 info.xmms2.date = 0;
2005 case OBJ_xmms2_status:
2006 if (info.xmms2.status) {
2007 free(info.xmms2.status);
2008 info.xmms2.status = 0;
2011 case OBJ_xmms2_smart:
2012 if (info.xmms2.artist) {
2013 free(info.xmms2.artist);
2014 info.xmms2.artist = 0;
2016 if (info.xmms2.title) {
2017 free(info.xmms2.title);
2018 info.xmms2.title = 0;
2020 if (info.xmms2.url) {
2021 free(info.xmms2.url);
2027 case OBJ_bmpx_title:
2028 case OBJ_bmpx_artist:
2029 case OBJ_bmpx_album:
2030 case OBJ_bmpx_track:
2032 case OBJ_bmpx_bitrate:
2036 free(objs[i].data.s);
2038 case OBJ_battery_time:
2039 free(objs[i].data.s);
2042 free(objs[i].data.execi.cmd);
2043 free(objs[i].data.execi.buffer);
2046 free(objs[i].data.texeci.cmd);
2047 free(objs[i].data.texeci.buffer);
2050 if (info.first_process) {
2051 free_all_processes();
2052 info.first_process = NULL;
2056 if (info.first_process) {
2057 free_all_processes();
2058 info.first_process = NULL;
2063 free(objs[i].data.hddtemp.dev);
2064 free(objs[i].data.hddtemp.addr);
2067 case OBJ_entropy_avail:
2068 case OBJ_entropy_poolsize:
2069 case OBJ_entropy_bar:
2074 //text_objects = NULL;
2075 //text_object_count = 0;
2078 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2083 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2084 *a = mixer_init(buf1);
2085 (void) scan_bar(arg + n, w, h);
2088 (void) scan_bar(arg, w, h);
2093 /* construct_text_object() creates a new text_object */
2094 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2096 //struct text_object *obj = new_text_object();
2097 struct text_object *obj = new_text_object_internal();
2100 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2101 #define END ; } } else
2105 obj->type = OBJ_color;
2106 obj->data.l = get_x11_color(s);
2109 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2110 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2111 END OBJ(acpiacadapter, 0)
2112 END OBJ(freq, INFO_FREQ)
2118 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2120 obj->data.cpu_index=1;
2121 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2125 obj->data.cpu_index=atoi(&arg[0]);
2128 END OBJ(freq_g, INFO_FREQ)
2134 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2136 obj->data.cpu_index=1;
2137 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2141 obj->data.cpu_index=atoi(&arg[0]);
2144 #if defined(__linux__)
2145 END OBJ(voltage_mv, 0)
2151 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2153 obj->data.cpu_index=1;
2154 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2158 obj->data.cpu_index=atoi(&arg[0]);
2161 END OBJ(voltage_v, 0)
2167 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2169 obj->data.cpu_index=1;
2170 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2174 obj->data.cpu_index=atoi(&arg[0]);
2177 #endif /* __linux__ */
2178 END OBJ(freq_dyn, 0);
2179 END OBJ(freq_dyn_g, 0);
2180 END OBJ(acpifan, 0);
2181 END OBJ(battery, 0);
2184 sscanf(arg, "%63s", bat);
2186 strcpy(bat, "BAT0");
2187 obj->data.s = strdup(bat);
2188 END OBJ(battery_time, 0);
2191 sscanf(arg, "%63s", bat);
2193 strcpy(bat, "BAT0");
2194 obj->data.s = strdup(bat);
2195 END OBJ(battery_percent, 0);
2198 sscanf(arg, "%63s", bat);
2200 strcpy(bat, "BAT0");
2201 obj->data.s = strdup(bat);
2202 END OBJ(battery_bar, 0);
2205 arg = scan_bar(arg, &obj->a, &obj->b);
2206 sscanf(arg, "%63s", bat);
2208 strcpy(bat, "BAT0");
2210 #if defined(__linux__)
2211 END OBJ(i8k_version, INFO_I8K)
2212 END OBJ(i8k_bios, INFO_I8K)
2213 END OBJ(i8k_serial, INFO_I8K)
2214 END OBJ(i8k_cpu_temp, INFO_I8K)
2215 END OBJ(i8k_cpu_tempf, INFO_I8K)
2216 END OBJ(i8k_left_fan_status, INFO_I8K)
2217 END OBJ(i8k_right_fan_status, INFO_I8K)
2218 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2219 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2220 END OBJ(i8k_ac_status, INFO_I8K)
2221 END OBJ(i8k_buttons_status, INFO_I8K)
2223 END OBJ(ibm_temps, 0)
2225 CRIT_ERR("ibm_temps: needs an argument");
2227 if (!isdigit(arg[0])
2229 || atoi(&arg[0]) >=8)
2232 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2234 obj->data.sensor = atoi(&arg[0]);
2235 END OBJ(ibm_volume, 0)
2236 END OBJ(ibm_brightness, 0)
2237 END OBJ(pb_battery, 0)
2238 if (arg && strcmp(arg, "status") == 0) {
2239 obj->data.i = PB_BATT_STATUS;
2240 } else if (arg && strcmp(arg, "percent") == 0) {
2241 obj->data.i = PB_BATT_PERCENT;
2242 } else if (arg && strcmp(arg, "time") == 0) {
2243 obj->data.i = PB_BATT_TIME;
2245 ERR("pb_battery: needs one argument: status, percent or time");
2250 #endif /* __linux__ */
2251 #if defined(__OpenBSD__)
2252 END OBJ(obsd_sensors_temp, 0);
2254 CRIT_ERR("obsd_sensors_temp: needs an argument");
2256 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2258 ERR("Invalid temperature sensor number!");
2260 obj->data.sensor = atoi(&arg[0]);
2261 END OBJ(obsd_sensors_fan, 0);
2263 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor number)");
2265 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2267 ERR("Invalid fan sensor number!");
2269 obj->data.sensor = atoi(&arg[0]);
2270 END OBJ(obsd_sensors_volt, 0);
2272 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor number)");
2274 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2276 ERR("Invalid voltage sensor number!");
2278 obj->data.sensor = atoi(&arg[0]);
2279 END OBJ(obsd_vendor, 0);
2280 END OBJ(obsd_product, 0);
2281 #endif /* __OpenBSD__ */
2282 END OBJ(buffers, INFO_BUFFERS)
2283 END OBJ(cached, INFO_BUFFERS)
2284 END OBJ(cpu, INFO_CPU)
2286 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2287 obj->data.cpu_index = atoi(&arg[3]);
2289 } else {obj->data.cpu_index = 0; }
2291 obj->data.cpu_index = 0;
2293 END OBJ(cpubar, INFO_CPU)
2295 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2296 obj->data.cpu_index = atoi(&arg[3]);
2299 else {obj->data.cpu_index = 0;}
2300 (void) scan_bar(arg, &obj->a, &obj->b);
2302 (void) scan_bar(arg, &obj->a, &obj->b);
2303 obj->data.cpu_index = 0;
2305 END OBJ(cpugraph, INFO_CPU)
2307 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2308 obj->data.cpu_index = atoi(&arg[3]);
2311 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2313 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2314 obj->data.cpu_index = 0;
2316 END OBJ(diskio, INFO_DISKIO)
2317 END OBJ(diskio_read, INFO_DISKIO)
2318 END OBJ(diskio_write, INFO_DISKIO)
2319 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2320 END OBJ(diskiograph_read, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2321 END OBJ(diskiograph_write, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2324 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2327 obj->data.l = color0;
2329 obj->data.l = color1;
2331 obj->data.l = color2;
2333 obj->data.l = color3;
2335 obj->data.l = color4;
2337 obj->data.l = color5;
2339 obj->data.l = color6;
2341 obj->data.l = color7;
2343 obj->data.l = color8;
2345 obj->data.l = color9;
2347 obj->data.s = scan_font(arg);
2349 OBJ(downspeed, INFO_NET)
2351 obj->data.net = get_net_stat(arg);
2354 CRIT_ERR("downspeed needs argument");
2356 END OBJ(downspeedf, INFO_NET)
2358 obj->data.net = get_net_stat(arg);
2361 CRIT_ERR("downspeedf needs argument");
2363 END OBJ(downspeedgraph, INFO_NET)
2364 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2366 sscanf(arg, "%63s %*i,%*i %*i", buf);
2367 obj->data.net = get_net_stat(buf);
2368 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2369 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
2376 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2377 blockstart[blockdepth - 1] = object_count;
2378 obj->data.ifblock.pos = object_count + 2;
2380 ERR("$else: no matching $if_*");
2385 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2387 ERR("$endif: no matching $if_*");
2390 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2393 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2394 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2395 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2396 END OBJ(execibar, 0) unsigned int n;
2397 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2399 ERR("${execibar <interval> command}");
2400 obj->type = OBJ_text;
2401 snprintf(buf, 256, "${%s}", s);
2402 obj->data.s = strdup(buf);
2404 obj->data.execi.cmd = strdup(arg + n);
2406 END OBJ(execigraph, 0) unsigned int n;
2407 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2409 ERR("${execigraph <interval> command}");
2410 obj->type = OBJ_text;
2411 snprintf(buf, 256, "${%s}", s);
2412 obj->data.s = strdup(buf);
2414 obj->data.execi.cmd = strdup(arg + n);
2416 END OBJ(execi, 0) unsigned int n;
2417 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2419 ERR("${execi <interval> command}");
2420 obj->type = OBJ_text;
2421 snprintf(buf, 256, "${%s}", s);
2422 obj->data.s = strdup(buf);
2424 obj->data.execi.cmd = strdup(arg + n);
2425 obj->data.execi.buffer =
2426 (char *) calloc(1, text_buffer_size);
2428 END OBJ(texeci, 0) unsigned int n;
2429 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2431 ERR("${texeci <interval> command}");
2432 obj->type = OBJ_text;
2433 snprintf(buf, 256, "${%s}", s);
2434 obj->data.s = strdup(buf);
2436 obj->data.texeci.cmd = strdup(arg + n);
2437 obj->data.texeci.buffer =
2438 (char *) calloc(1, text_buffer_size);
2440 obj->data.texeci.p_timed_thread = NULL;
2441 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2443 FILE *fp = popen(arg, "r");
2447 n = fread(buf, 1, 2048, fp);
2450 if (n && buf[n - 1] == '\n')
2455 obj->data.s = strdup(buf);
2457 obj->data.s = strdup("");
2460 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2461 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2463 while (isspace(*arg))
2469 obj->data.fsbar.fs = prepare_fs_stat(arg);
2470 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2473 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2477 obj->data.fsbar.fs = prepare_fs_stat(arg);
2478 END OBJ(fs_free, INFO_FS) if (!arg)
2480 obj->data.fs = prepare_fs_stat(arg);
2481 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2483 obj->data.fs = prepare_fs_stat(arg);
2484 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2486 obj->data.fs = prepare_fs_stat(arg);
2487 END OBJ(fs_size, INFO_FS) if (!arg)
2489 obj->data.fs = prepare_fs_stat(arg);
2490 END OBJ(fs_used, INFO_FS) if (!arg)
2492 obj->data.fs = prepare_fs_stat(arg);
2493 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2494 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2495 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2499 ERR("goto needs arguments");
2500 obj->type = OBJ_text;
2501 obj->data.s = strdup("${goto}");
2505 obj->data.i = atoi(arg);
2510 if (sscanf(arg, "%d %d", &a, &b) != 2)
2511 sscanf(arg, "%d", &b);
2515 obj->data.pair.a = a;
2516 obj->data.pair.b = b;
2518 END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
2522 ERR("i2c needs arguments");
2523 obj->type = OBJ_text;
2524 //obj->data.s = strdup("${i2c}");
2528 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2529 /* if scanf couldn't read three values, read type and num and use
2531 sscanf(arg, "%63s %d", buf2, &n);
2533 open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
2534 obj->data.i2c.devtype);
2535 strncpy(obj->data.i2c.type, buf2, 63);
2538 open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
2539 obj->data.i2c.devtype);
2540 strncpy(obj->data.i2c.type, buf2, 63);
2543 END OBJ(top, INFO_TOP)
2547 ERR("top needs arguments");
2548 obj->type = OBJ_text;
2549 //obj->data.s = strdup("${top}");
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(top_mem, INFO_TOP)
2580 ERR("top_mem needs arguments");
2581 obj->type = OBJ_text;
2582 obj->data.s = strdup("${top_mem}");
2585 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2586 if (strcmp(buf, "name") == 0) {
2587 obj->data.top.type = TOP_NAME;
2588 } else if (strcmp(buf, "cpu") == 0) {
2589 obj->data.top.type = TOP_CPU;
2590 } else if (strcmp(buf, "pid") == 0) {
2591 obj->data.top.type = TOP_PID;
2592 } else if (strcmp(buf, "mem") == 0) {
2593 obj->data.top.type = TOP_MEM;
2595 ERR("invalid arg for top");
2598 if (n < 1 || n > 10) {
2599 CRIT_ERR("invalid arg for top");
2602 obj->data.top.num = n - 1;
2606 ERR("invalid args given for top");
2609 END OBJ(addr, INFO_NET)
2611 obj->data.net = get_net_stat(arg);
2614 CRIT_ERR("addr needs argument");
2616 END OBJ(linkstatus, INFO_WIFI)
2618 obj->data.net = get_net_stat(arg);
2621 CRIT_ERR("linkstatus needs argument");
2627 ERR("tail needs arguments");
2628 obj->type = OBJ_text;
2629 obj->data.s = strdup("${tail}");
2632 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2633 if (n1 < 1 || n1 > 30) {
2634 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2638 fp = fopen(buf, "r");
2640 obj->data.tail.logfile =
2641 malloc(text_buffer_size);
2642 strcpy(obj->data.tail.logfile, buf);
2643 obj->data.tail.wantedlines = n1;
2644 obj->data.tail.interval =
2645 update_interval * 2;
2649 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2652 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2653 if (n1 < 1 || n1 > 30) {
2655 ("invalid arg for tail, number of lines must be between 1 and 30");
2657 } else if (n2 < 1 || n2 < update_interval) {
2659 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2663 fp = fopen(buf, "r");
2665 obj->data.tail.logfile =
2666 malloc(text_buffer_size);
2667 strcpy(obj->data.tail.logfile, buf);
2668 obj->data.tail.wantedlines = n1;
2669 obj->data.tail.interval = n2;
2673 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2679 ERR("invalid args given for tail");
2682 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2687 ERR("head needs arguments");
2688 obj->type = OBJ_text;
2689 obj->data.s = strdup("${head}");
2692 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2693 if (n1 < 1 || n1 > 30) {
2694 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2698 fp = fopen(buf, "r");
2700 obj->data.tail.logfile =
2701 malloc(text_buffer_size);
2702 strcpy(obj->data.tail.logfile, buf);
2703 obj->data.tail.wantedlines = n1;
2704 obj->data.tail.interval =
2705 update_interval * 2;
2709 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2712 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2713 if (n1 < 1 || n1 > 30) {
2715 ("invalid arg for head, number of lines must be between 1 and 30");
2717 } else if (n2 < 1 || n2 < update_interval) {
2719 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2723 fp = fopen(buf, "r");
2725 obj->data.tail.logfile =
2726 malloc(text_buffer_size);
2727 strcpy(obj->data.tail.logfile, buf);
2728 obj->data.tail.wantedlines = n1;
2729 obj->data.tail.interval = n2;
2733 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2739 ERR("invalid args given for head");
2742 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2743 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2745 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2746 if (r >= 3 && (c < 1 || c > 3))
2748 if (r >= 2 && (b < 1 || b > 3))
2750 if (r >= 1 && (a < 1 || a > 3))
2753 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2754 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2755 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2756 END OBJ(if_empty, 0)
2757 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2758 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2761 ERR("if_empty needs an argument");
2762 obj->data.ifblock.s = 0;
2764 obj->data.ifblock.s = strdup(arg);
2765 blockstart[blockdepth] = object_count;
2766 obj->data.ifblock.pos = object_count + 2;
2768 END OBJ(if_existing, 0)
2769 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2770 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2773 ERR("if_existing needs an argument or two");
2774 obj->data.ifblock.s = NULL;
2775 obj->data.ifblock.str = NULL;
2777 char buf1[256], buf2[256];
2778 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2780 obj->data.ifblock.s = strdup(buf1);
2781 obj->data.ifblock.str = NULL;
2783 obj->data.ifblock.s = strdup(buf1);
2784 obj->data.ifblock.str = strdup(buf2);
2787 blockstart[blockdepth] = object_count;
2788 obj->data.ifblock.pos = object_count + 2;
2790 END OBJ(if_mounted, 0)
2791 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2792 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2795 ERR("if_mounted needs an argument");
2796 obj->data.ifblock.s = 0;
2798 obj->data.ifblock.s = strdup(arg);
2799 blockstart[blockdepth] = object_count;
2800 obj->data.ifblock.pos = object_count + 2;
2802 END OBJ(if_running, 0)
2803 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2804 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2808 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2809 obj->data.ifblock.s = strdup(buf);
2811 ERR("if_running needs an argument");
2812 obj->data.ifblock.s = 0;
2814 blockstart[blockdepth] = object_count;
2815 obj->data.ifblock.pos = object_count + 2;
2819 END OBJ(mails, INFO_MAIL)
2820 END OBJ(mboxscan, 0)
2821 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
2822 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
2823 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2824 obj->data.mboxscan.output[0] = 1;
2825 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
2826 END OBJ(mem, INFO_MEM)
2827 END OBJ(memmax, INFO_MEM)
2828 END OBJ(memperc, INFO_MEM)
2829 END OBJ(membar, INFO_MEM)
2830 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2831 END OBJ(memgraph, INFO_MEM)
2832 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2833 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2834 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2835 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2836 END OBJ(mixerbar, INFO_MIXER)
2837 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2838 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2839 END OBJ(mixerlbar, INFO_MIXER)
2840 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2841 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2842 END OBJ(mixerrbar, INFO_MIXER)
2843 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2844 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2846 OBJ(new_mails, INFO_MAIL)
2847 END OBJ(nodename, 0)
2848 END OBJ(processes, INFO_PROCS)
2849 END OBJ(running_processes, INFO_RUN_PROCS)
2850 END OBJ(shadecolor, 0)
2852 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
2854 END OBJ(outlinecolor, 0)
2856 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
2858 END OBJ(stippled_hr, 0)
2860 int a = stippled_borders, b = 1;
2862 if (sscanf(arg, "%d %d", &a, &b) != 2)
2863 sscanf(arg, "%d", &b);
2867 obj->data.pair.a = a;
2868 obj->data.pair.b = b;
2870 END OBJ(swap, INFO_MEM)
2871 END OBJ(swapmax, INFO_MEM)
2872 END OBJ(swapperc, INFO_MEM)
2873 END OBJ(swapbar, INFO_MEM)
2874 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2875 END OBJ(sysname, 0) END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c;
2877 open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg,
2878 obj->data.i2c.devtype);
2879 END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c;
2881 open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg,
2882 obj->data.i2c.devtype);
2883 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2884 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
2886 char buf1[256], buf2[256], *fmt, *tz;
2889 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2898 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
2899 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
2901 END OBJ(iconv_start, 0)
2902 if (iconv_converting) {
2903 CRIT_ERR("You must stop your last iconv conversion before starting another");
2906 char iconv_from[CODEPAGE_LENGTH];
2907 char iconv_to[CODEPAGE_LENGTH];
2908 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
2909 CRIT_ERR("Invalid arguments for iconv_start");
2912 new_iconv = iconv_open(iconv_to, iconv_from);
2913 if (new_iconv == (iconv_t)(-1)) {
2914 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
2916 obj->a = register_iconv(&new_iconv);
2917 iconv_converting = 1;
2921 CRIT_ERR("Iconv requires arguments");
2923 END OBJ(iconv_stop, 0)
2924 iconv_converting = 0;
2927 END OBJ(totaldown, INFO_NET)
2929 obj->data.net = get_net_stat(arg);
2932 CRIT_ERR("totaldown needs argument");
2934 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
2936 obj->data.net = get_net_stat(arg);
2939 CRIT_ERR("totalup needs argument");
2942 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
2943 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
2944 END OBJ(upspeed, INFO_NET)
2946 obj->data.net = get_net_stat(arg);
2949 CRIT_ERR("upspeed needs argument");
2951 END OBJ(upspeedf, INFO_NET)
2953 obj->data.net = get_net_stat(arg);
2956 CRIT_ERR("upspeedf needs argument");
2959 END OBJ(upspeedgraph, INFO_NET)
2960 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2962 sscanf(arg, "%63s %*i,%*i %*i", buf);
2963 obj->data.net = get_net_stat(buf);
2964 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2965 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
2970 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
2971 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
2972 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
2973 OBJ(apm_adapter, 0) END
2974 OBJ(apm_battery_life, 0) END
2975 OBJ(apm_battery_time, 0) END
2976 #endif /* __FreeBSD__ */
2980 obj->data.mail = parse_mail_args(IMAP, arg);
2981 obj->global_mode = 0;
2983 obj->global_mode = 1;
2986 OBJ(imap_messages, 0)
2989 obj->data.mail = parse_mail_args(IMAP, arg);
2990 obj->global_mode = 0;
2992 obj->global_mode = 1;
2998 obj->data.mail = parse_mail_args(POP3, arg);
2999 obj->global_mode = 0;
3001 obj->global_mode = 1;
3007 obj->data.mail = parse_mail_args(POP3, arg);
3008 obj->global_mode = 0;
3010 obj->global_mode = 1;
3014 OBJ(mpd_artist, INFO_MPD)
3015 END OBJ(mpd_title, INFO_MPD)
3016 END OBJ(mpd_random, INFO_MPD)
3017 END OBJ(mpd_repeat, INFO_MPD)
3018 END OBJ(mpd_elapsed, INFO_MPD)
3019 END OBJ(mpd_length, INFO_MPD)
3020 END OBJ(mpd_track, INFO_MPD)
3021 END OBJ(mpd_name, INFO_MPD)
3022 END OBJ(mpd_file, INFO_MPD)
3023 END OBJ(mpd_percent, INFO_MPD)
3024 END OBJ(mpd_album, INFO_MPD)
3025 END OBJ(mpd_vol, INFO_MPD)
3026 END OBJ(mpd_bitrate, INFO_MPD)
3027 END OBJ(mpd_status, INFO_MPD)
3028 END OBJ(mpd_bar, INFO_MPD)
3029 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3030 END OBJ(mpd_smart, INFO_MPD) END
3033 OBJ(xmms2_artist, INFO_XMMS2)
3034 END OBJ(xmms2_album, INFO_XMMS2)
3035 END OBJ(xmms2_title, INFO_XMMS2)
3036 END OBJ(xmms2_genre, INFO_XMMS2)
3037 END OBJ(xmms2_comment, INFO_XMMS2)
3038 END OBJ(xmms2_decoder, INFO_XMMS2)
3039 END OBJ(xmms2_transport, INFO_XMMS2)
3040 END OBJ(xmms2_url, INFO_XMMS2)
3041 END OBJ(xmms2_tracknr, INFO_XMMS2)
3042 END OBJ(xmms2_bitrate, INFO_XMMS2)
3043 END OBJ(xmms2_date, INFO_XMMS2)
3044 END OBJ(xmms2_id, INFO_XMMS2)
3045 END OBJ(xmms2_duration, INFO_XMMS2)
3046 END OBJ(xmms2_elapsed, INFO_XMMS2)
3047 END OBJ(xmms2_size, INFO_XMMS2)
3048 END OBJ(xmms2_status, INFO_XMMS2)
3049 END OBJ(xmms2_percent, INFO_XMMS2)
3050 END OBJ(xmms2_bar, INFO_XMMS2)
3051 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3052 END OBJ(xmms2_smart, INFO_XMMS2)
3056 OBJ(audacious_status, INFO_AUDACIOUS) END
3057 OBJ(audacious_title, INFO_AUDACIOUS)
3061 sscanf (arg, "%d", &info.audacious.max_title_len);
3062 if (info.audacious.max_title_len > 0)
3063 info.audacious.max_title_len++;
3065 CRIT_ERR ("audacious_title: invalid length argument");
3069 OBJ(audacious_length, INFO_AUDACIOUS) END
3070 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3071 OBJ(audacious_position, INFO_AUDACIOUS) END
3072 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3073 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3074 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3075 OBJ(audacious_channels, INFO_AUDACIOUS) END
3076 OBJ(audacious_filename, INFO_AUDACIOUS) END
3077 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3078 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3079 OBJ(audacious_bar, INFO_AUDACIOUS)
3080 (void) scan_bar(arg, &obj->a, &obj->b);
3084 OBJ(bmpx_title, INFO_BMPX)
3085 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3087 OBJ(bmpx_artist, INFO_BMPX)
3088 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3090 OBJ(bmpx_album, INFO_BMPX)
3091 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3093 OBJ(bmpx_track, INFO_BMPX)
3094 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3096 OBJ(bmpx_uri, INFO_BMPX)
3097 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3099 OBJ(bmpx_bitrate, INFO_BMPX)
3100 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3105 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3106 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3107 ERR("hddtemp needs arguments");
3108 obj->type = OBJ_text;
3109 obj->data.s = strdup("${hddtemp}");
3114 #ifdef TCP_PORT_MONITOR
3115 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3116 int argc, port_begin, port_end, item, connection_index;
3118 memset(itembuf,0,sizeof(itembuf));
3120 /* massive argument checking */
3122 CRIT_ERR("tcp_portmon: needs arguments");
3124 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3125 if ( (argc != 3) && (argc != 4) )
3127 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3129 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3131 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3133 if ( port_begin > port_end )
3135 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3137 if ( strncmp(itembuf,"count",31) == 0 )
3139 else if ( strncmp(itembuf,"rip",31) == 0 )
3141 else if ( strncmp(itembuf,"rhost",31) == 0 )
3143 else if ( strncmp(itembuf,"rport",31) == 0 )
3145 else if ( strncmp(itembuf,"rservice",31) == 0 )
3147 else if ( strncmp(itembuf,"lip",31) == 0 )
3149 else if ( strncmp(itembuf,"lhost",31) == 0 )
3151 else if ( strncmp(itembuf,"lport",31) == 0 )
3153 else if ( strncmp(itembuf,"lservice",31) == 0 )
3157 CRIT_ERR("tcp_portmon: invalid item specified");
3159 if ( (argc==3) && (item!=COUNT) )
3161 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3163 if ( (argc==4) && (connection_index<0) )
3165 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3167 /* ok, args looks good. save the text object data */
3168 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3169 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3170 obj->data.tcp_port_monitor.item = item;
3171 obj->data.tcp_port_monitor.connection_index = connection_index;
3173 /* if the port monitor collection hasn't been created, we must create it */
3174 if ( !info.p_tcp_port_monitor_collection )
3176 info.p_tcp_port_monitor_collection =
3177 create_tcp_port_monitor_collection ();
3178 if ( !info.p_tcp_port_monitor_collection )
3180 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3184 /* if a port monitor for this port does not exist, create one and add it to the collection */
3185 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3187 tcp_port_monitor_t * p_monitor =
3188 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3191 CRIT_ERR("tcp_portmon: unable to create port monitor");
3193 /* add the newly created monitor to the collection */
3194 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3197 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3202 OBJ(entropy_avail, INFO_ENTROPY) END
3203 OBJ(entropy_poolsize, INFO_ENTROPY) END
3204 OBJ(entropy_bar, INFO_ENTROPY)
3205 (void) scan_bar(arg, &obj->a, &obj->b);
3210 ERR("unknown variable %s", s);
3211 obj->type = OBJ_text;
3212 snprintf(buf, 256, "${%s}", s);
3213 obj->data.s = strdup(buf);
3220 static struct text_object *create_plain_text(const char *s)
3222 struct text_object *obj;
3224 if (s == NULL || *s == '\0') {
3228 obj = new_text_object_internal();
3230 obj->type = OBJ_text;
3231 obj->data.s = strdup(s);
3235 static struct text_object_list *extract_variable_text_internal(const char *p)
3237 struct text_object_list *retval;
3238 struct text_object *obj;
3241 retval = malloc(sizeof(struct text_object_list));
3242 memset(retval, 0, sizeof(struct text_object_list));
3243 retval->text_object_count = 0;
3245 long line = text_lines;
3253 obj = create_plain_text(s);
3255 // allocate memory for the object
3256 retval->text_objects = realloc(retval->text_objects,
3257 sizeof(struct text_object) * (retval->text_object_count+1));
3258 // assign the new object to the end of the list.
3259 memcpy(&retval->text_objects[retval->text_object_count++],
3260 obj, sizeof(struct text_object));
3272 /* variable is either $foo or ${foo} */
3274 unsigned int brl = 1, brr = 0;
3277 while (*p && brl != brr) {
3278 if (*p == '{') brl++;
3279 if (*p == '}') brr++;
3287 while (*p && (isalnum((int) *p)
3292 /* copy variable to buffer */
3293 len = (p - s > 255) ? 255 : (p - s);
3294 strncpy(buf, s, len);
3303 /* if variable wasn't found from environment, use some special */
3309 if (strchr(buf, ' ')) {
3310 arg = strchr(buf, ' ');
3313 while (isspace((int) *arg))
3319 /* lowercase variable name */
3326 // create new object
3327 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3329 // allocate memory for the object
3330 retval->text_objects = realloc(retval->text_objects,
3331 sizeof(struct text_object) * (retval->text_object_count+1));
3332 // assign the new object to the end of the list.
3333 memcpy(&retval->text_objects[retval->text_object_count++],
3334 obj, sizeof(struct text_object));
3340 obj = create_plain_text("$");
3342 // allocate memory for the object
3343 retval->text_objects = realloc(retval->text_objects,
3344 sizeof(struct text_object) * (retval->text_object_count+1));
3345 // assign the new object to the end of the list.
3346 memcpy(&retval->text_objects[retval->text_object_count++],
3347 obj, sizeof(struct text_object));
3354 obj = create_plain_text(s);
3356 // allocate memory for the object
3357 retval->text_objects = realloc(retval->text_objects,
3358 sizeof(struct text_object) * (retval->text_object_count+1));
3359 // assign the new object to the end of the list.
3360 memcpy(&retval->text_objects[retval->text_object_count++],
3361 obj, sizeof(struct text_object));
3366 ERR("one or more $endif's are missing");
3372 static void extract_variable_text(const char *p)
3374 struct text_object_list *list;
3376 free_text_objects(text_object_count, text_objects);
3377 text_object_count = 0;
3378 text_objects = NULL;
3381 list = extract_variable_text_internal(p);
3382 text_objects = list->text_objects;
3383 text_object_count = list->text_object_count;
3390 void parse_conky_vars(char * text, char * p, struct information *cur) {
3391 struct text_object_list *object_list = extract_variable_text_internal(text);
3392 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3396 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3401 char buff_in[P_MAX_SIZE] = {0};
3402 iconv_converting = 0;
3405 for (i = 0; i < object_count; i++) {
3406 struct text_object *obj = &objs[i];
3408 #define OBJ(a) break; case OBJ_##a:
3410 switch (obj->type) {
3413 ERR("not implemented obj type %d",
3417 /* does anyone have decimals in acpi temperature? */
3419 snprintf(p, p_max_size, "%d", (int)
3420 get_acpi_temperature(obj->
3424 snprintf(p, 5, "%d ", (int)
3425 get_acpi_temperature(obj->
3430 /* does anyone have decimals in acpi temperature? */
3432 snprintf(p, p_max_size, "%d", (int)
3433 ((get_acpi_temperature(obj->
3435 i)+ 40) * 9.0 / 5 - 40));
3437 snprintf(p, 5, "%d ", (int)
3438 ((get_acpi_temperature(obj->
3440 i)+ 40) * 9.0 / 5 - 40));
3444 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3449 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3452 #if defined(__linux__)
3455 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3460 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3463 #endif /* __linux__ */
3467 get_freq_dynamic(p, 6, "%.0f ", 1 );
3469 get_freq_dynamic(p, p_max_size, "%.0f", 1 );
3474 get_freq_dynamic(p, 6, "%'.2f ", 1000);
3476 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3480 get_adt746x_cpu(p, p_max_size);
3483 get_adt746x_fan(p, p_max_size);
3486 get_acpi_fan(p, p_max_size);
3488 OBJ(acpiacadapter) {
3489 get_acpi_ac_adapter(p, p_max_size);
3492 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3495 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3497 OBJ(battery_percent) {
3498 snprintf(p, p_max_size, "%d",
3499 get_battery_perct(obj->data.s));
3502 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3505 human_readable(cur->buffers * 1024, p, 255);
3508 human_readable(cur->cached * 1024, p, 255);
3511 if (obj->data.cpu_index > info.cpu_count) {
3512 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3513 CRIT_ERR("attempting to use more CPUs then you have!");
3516 snprintf(p, p_max_size, "%*d", pad_percents,
3517 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3520 snprintf(p, 4, "%*d ",
3522 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3528 (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3531 new_graph(p, obj->a,
3532 obj->b, obj->c, obj->d,
3533 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3537 new_fg(p, obj->data.l);
3569 #if defined(__linux__)
3571 snprintf(p, p_max_size, "%s", i8k.version);
3574 snprintf(p, p_max_size, "%s", i8k.bios);
3577 snprintf(p, p_max_size, "%s", i8k.serial);
3580 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3582 OBJ(i8k_cpu_tempf) {
3584 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3585 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3587 OBJ(i8k_left_fan_status) {
3588 int left_fan_status;
3589 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3590 if(left_fan_status == 0) {
3591 snprintf(p, p_max_size,"off");
3592 } if(left_fan_status == 1) {
3593 snprintf(p, p_max_size, "low");
3594 } if(left_fan_status == 2) {
3595 snprintf(p, p_max_size, "high");
3599 OBJ(i8k_right_fan_status) {
3600 int right_fan_status;
3601 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3602 if(right_fan_status == 0) {
3603 snprintf(p, p_max_size,"off");
3604 } if(right_fan_status == 1) {
3605 snprintf(p, p_max_size, "low");
3606 } if(right_fan_status == 2) {
3607 snprintf(p, p_max_size, "high");
3610 OBJ(i8k_left_fan_rpm) {
3611 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3613 OBJ(i8k_right_fan_rpm) {
3614 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3616 OBJ(i8k_ac_status) {
3618 sscanf(i8k.ac_status, "%d", &ac_status);
3619 if(ac_status == -1) {
3620 snprintf(p, p_max_size,"disabled (read i8k docs)");
3621 } if(ac_status == 0) {
3622 snprintf(p, p_max_size, "off");
3623 } if(ac_status == 1) {
3624 snprintf(p, p_max_size, "on");
3627 OBJ(i8k_buttons_status) {
3628 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3632 get_ibm_acpi_fan(p, p_max_size);
3635 get_ibm_acpi_temps();
3636 snprintf(p, p_max_size, "%d",
3637 ibm_acpi.temps[obj->data.sensor]);
3640 get_ibm_acpi_volume(p, p_max_size);
3642 OBJ(ibm_brightness) {
3643 get_ibm_acpi_brightness(p, p_max_size);
3646 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3648 #endif /* __linux__ */
3651 OBJ(obsd_sensors_temp) {
3652 obsd_sensors.device = sensor_device;
3653 update_obsd_sensors();
3654 snprintf(p, p_max_size, "%.1f",
3655 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
3658 OBJ(obsd_sensors_fan) {
3659 obsd_sensors.device = sensor_device;
3660 update_obsd_sensors();
3661 snprintf(p, p_max_size, "%d",
3662 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3665 OBJ(obsd_sensors_volt) {
3666 obsd_sensors.device = sensor_device;
3667 update_obsd_sensors();
3668 snprintf(p, p_max_size, "%.2f",
3669 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
3673 get_obsd_vendor(p, p_max_size);
3677 get_obsd_product(p, p_max_size);
3679 #endif /* __OpenBSD__ */
3683 new_font(p, obj->data.s);
3686 void format_diskio(unsigned int diskio_value)
3689 if (diskio_value > 1024*1024) {
3690 snprintf(p, p_max_size, "%.1fGiB",
3691 (double)diskio_value/1024/1024);
3692 } else if (diskio_value > 1024) {
3693 snprintf(p, p_max_size, "%.1fMiB",
3694 (double)diskio_value/1024);
3695 } else if (diskio_value > 0) {
3696 snprintf(p, p_max_size, "%dKiB", diskio_value);
3698 snprintf(p, p_max_size, "%dB", diskio_value);
3701 if (diskio_value > 1024*1024) {
3702 snprintf(p, 12, "%.1fGiB ",
3703 (double)diskio_value/1024/1024);
3704 } else if (diskio_value > 1024) {
3705 snprintf(p, 12, "%.1fMiB ",
3706 (double)diskio_value/1024);
3707 } else if (diskio_value > 0) {
3708 snprintf(p, 12, "%dKiB ", diskio_value);
3710 snprintf(p, 12, "%dB ", diskio_value);
3715 format_diskio(diskio_value);
3718 format_diskio(diskio_write_value);
3721 format_diskio(diskio_read_value);
3724 new_graph(p, obj->a,
3725 obj->b, obj->c, obj->d,
3726 diskio_value, obj->e, 1);
3728 OBJ(diskiograph_read) {
3729 new_graph(p, obj->a,
3730 obj->b, obj->c, obj->d,
3731 diskio_read_value, obj->e, 1);
3733 OBJ(diskiograph_write) {
3734 new_graph(p, obj->a,
3735 obj->b, obj->c, obj->d,
3736 diskio_write_value, obj->e, 1);
3740 snprintf(p, p_max_size, "%d",
3741 (int) (obj->data.net->
3745 snprintf(p, 6, "%d ",
3746 (int) (obj->data.net->
3752 snprintf(p, p_max_size, "%.1f",
3754 recv_speed / 1024.0);
3756 snprintf(p, 8, "%.1f ",
3758 recv_speed / 1024.0);
3760 OBJ(downspeedgraph) {
3762 if (obj->data.net->recv_speed == 0)
3763 obj->data.net->recv_speed = 0.01;
3765 new_graph(p, obj->a, obj->b, obj->c, obj->d,
3766 (obj->data.net->recv_speed /
3767 1024.0), obj->e, 1);
3771 i = obj->data.ifblock.pos - 1;
3781 snprintf(p, p_max_size, "%u.%u.%u.%u",
3782 obj->data.net->addr.
3784 obj->data.net->addr.
3786 obj->data.net->addr.
3788 obj->data.net->addr.
3794 snprintf(p, p_max_size, "%d",
3795 obj->data.net->linkstatus);
3798 snprintf(p, 5, "%4d ",
3799 obj->data.net->linkstatus);
3802 #if defined(IMLIB2) && defined(X11)
3807 Imlib_Image image, buffer;
3808 image = imlib_load_image(obj->data.s);
3809 imlib_context_set_image(image);
3812 w = imlib_image_get_width();
3813 h = imlib_image_get_height();
3814 buffer = imlib_create_image(w, h);
3815 imlib_context_set_display(display);
3816 imlib_context_set_drawable(window.drawable);
3817 imlib_context_set_colormap(DefaultColormap(display, screen));
3818 imlib_context_set_visual(DefaultVisual(display, screen));
3819 imlib_context_set_image(buffer);
3820 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
3821 imlib_render_image_on_drawable(text_start_x, text_start_y);
3823 imlib_context_set_image(image);
3830 FILE *fp = popen(obj->data.s, "r");
3831 int length = fread(p, 1, p_max_size, fp);
3834 /*output[length] = '\0';
3835 if (length > 0 && output[length - 1] == '\n') {
3836 output[length - 1] = '\0';
3839 if (length > 0 && p[length - 1] == '\n') {
3840 p[length - 1] = '\0';
3843 //parse_conky_vars(output, p, cur);
3847 FILE *fp = popen(obj->data.s, "r");
3848 int n2 = fread(p, 1, p_max_size, fp);
3852 if (n2 && p[n2 - 1] == '\n')
3861 if (sscanf(p, "%lf", &barnum) == 0) {
3862 ERR("reading execbar value failed (perhaps it's not the correct format?)");
3864 if (barnum > 100 || barnum < 0) {
3865 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
3867 barnum = barnum / 100.0;
3868 new_bar(p, 0, 4, (int) (barnum * 255.0));
3874 FILE *fp = popen(obj->data.s, "r");
3875 int n2 = fread(p, 1, p_max_size, fp);
3879 if (n2 && p[n2 - 1] == '\n')
3888 if (sscanf(p, "%lf", &barnum) == 0) {
3889 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
3891 if (barnum > 100 || barnum < 0) {
3892 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
3894 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
3899 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3900 new_bar(p, 0, 4, (int) obj->f);
3903 FILE *fp = popen(obj->data.execi.cmd, "r");
3904 int n2 = fread(p, 1, p_max_size, fp);
3907 if (n2 && p[n2 - 1] == '\n')
3916 if (sscanf(p, "%f", &barnum) == 0) {
3917 ERR("reading execibar value failed (perhaps it's not the correct format?)");
3919 if (barnum > 100 || barnum < 0) {
3920 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
3922 obj->f = 255 * barnum / 100.0;
3923 new_bar(p, 0, 4, (int) obj->f);
3925 obj->data.execi.last_update =
3926 current_update_time;
3930 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
3931 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
3934 FILE *fp = popen(obj->data.execi.cmd, "r");
3935 int n2 = fread(p, 1, p_max_size, fp);
3938 if (n2 && p[n2 - 1] == '\n')
3947 if (sscanf(p, "%f", &barnum) == 0) {
3948 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
3950 if (barnum > 100 || barnum < 0) {
3951 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
3954 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
3956 obj->data.execi.last_update = current_update_time;
3962 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
3963 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
3965 char *output = obj->data.execi.buffer;
3966 FILE *fp = popen(obj->data.execi.cmd, "r");
3967 //int length = fread(output, 1, text_buffer_size, fp);
3968 int length = fread(output, 1, text_buffer_size, fp);
3971 output[length] = '\0';
3972 if (length > 0 && output[length - 1] == '\n') {
3973 output[length - 1] = '\0';
3975 obj->data.execi.last_update = current_update_time;
3976 snprintf(p, p_max_size, "%s", output);
3978 //parse_conky_vars(output, p, cur);
3981 if (!obj->data.texeci.p_timed_thread)
3983 obj->data.texeci.p_timed_thread=
3984 timed_thread_create ((void*)threaded_exec, (void*) obj,
3985 obj->data.texeci.interval * 1000000);
3986 if (!obj->data.texeci.p_timed_thread)
3987 ERR("Error starting texeci thread");
3988 timed_thread_register (obj->data.texeci.p_timed_thread,
3989 &obj->data.texeci.p_timed_thread);
3991 timed_thread_lock (obj->data.texeci.p_timed_thread);
3992 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
3993 timed_thread_unlock (obj->data.texeci.p_timed_thread);
3995 #endif /* HAVE_POPEN */
3997 if (obj->global_mode && info.mail) { // this means we use info
3998 if (!info.mail->p_timed_thread)
4000 info.mail->p_timed_thread =
4001 timed_thread_create ((void*)imap_thread,
4003 info.mail->interval * 1000000);
4004 if (!info.mail->p_timed_thread)
4005 ERR("Error starting imap thread");
4006 timed_thread_register (info.mail->p_timed_thread,
4007 &info.mail->p_timed_thread);
4009 timed_thread_lock (info.mail->p_timed_thread);
4010 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4011 timed_thread_unlock (info.mail->p_timed_thread);
4012 } else if (obj->data.mail) { // this means we use obj
4013 if (!obj->data.mail->p_timed_thread)
4015 obj->data.mail->p_timed_thread =
4016 timed_thread_create ((void*)imap_thread,
4017 (void*)obj->data.mail,
4018 obj->data.mail->interval * 1000000);
4019 if (!obj->data.mail->p_timed_thread)
4020 ERR("Error starting imap thread");
4021 timed_thread_register (obj->data.mail->p_timed_thread,
4022 &obj->data.mail->p_timed_thread);
4024 timed_thread_lock (obj->data.mail->p_timed_thread);
4025 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4026 timed_thread_unlock (obj->data.mail->p_timed_thread);
4027 } else if (!obj->a) { // something is wrong, warn once then stop
4028 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4032 OBJ(imap_messages) {
4033 if (obj->global_mode && info.mail) { // this means we use info
4034 if (!info.mail->p_timed_thread)
4036 info.mail->p_timed_thread =
4037 timed_thread_create ((void*)imap_thread,
4039 info.mail->interval * 1000000);
4040 if (!info.mail->p_timed_thread)
4041 ERR("Error starting imap thread");
4042 timed_thread_register (info.mail->p_timed_thread,
4043 &info.mail->p_timed_thread);
4045 timed_thread_lock (info.mail->p_timed_thread);
4046 snprintf(p, p_max_size, "%lu", info.mail->messages);
4047 timed_thread_unlock (info.mail->p_timed_thread);
4048 } else if (obj->data.mail) { // this means we use obj
4049 if (!obj->data.mail->p_timed_thread)
4051 obj->data.mail->p_timed_thread =
4052 timed_thread_create ((void*)imap_thread,
4053 (void*)obj->data.mail,
4054 obj->data.mail->interval * 1000000);
4055 if (!obj->data.mail->p_timed_thread)
4056 ERR("Error starting imap thread");
4057 timed_thread_register (obj->data.mail->p_timed_thread,
4058 &obj->data.mail->p_timed_thread);
4060 timed_thread_lock (obj->data.mail->p_timed_thread);
4061 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4062 timed_thread_lock (obj->data.mail->p_timed_thread);
4063 } else if (!obj->a) { // something is wrong, warn once then stop
4064 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4069 if (obj->global_mode && info.mail) { // this means we use info
4070 if (!info.mail->p_timed_thread)
4072 info.mail->p_timed_thread =
4073 timed_thread_create ((void*)pop3_thread,
4075 info.mail->interval * 1000000);
4076 if (!info.mail->p_timed_thread)
4077 ERR("Error starting pop3 thread");
4078 timed_thread_register (info.mail->p_timed_thread,
4079 &info.mail->p_timed_thread);
4081 timed_thread_lock (info.mail->p_timed_thread);
4082 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4083 timed_thread_unlock (info.mail->p_timed_thread);
4084 } else if (obj->data.mail) { // this means we use obj
4085 if (!obj->data.mail->p_timed_thread)
4087 obj->data.mail->p_timed_thread =
4088 timed_thread_create ((void*)pop3_thread,
4089 (void*)obj->data.mail,
4090 obj->data.mail->interval * 1000000);
4091 if (!obj->data.mail->p_timed_thread)
4092 ERR("Error starting pop3 thread");
4093 timed_thread_register (obj->data.mail->p_timed_thread,
4094 &obj->data.mail->p_timed_thread);
4096 timed_thread_lock (obj->data.mail->p_timed_thread);
4097 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4098 timed_thread_unlock (obj->data.mail->p_timed_thread);
4099 } else if (!obj->a) { // something is wrong, warn once then stop
4100 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4105 if (obj->global_mode && info.mail) { // this means we use info
4106 if (!info.mail->p_timed_thread)
4108 info.mail->p_timed_thread =
4109 timed_thread_create ((void*)pop3_thread,
4111 info.mail->interval * 1000000);
4112 if (!info.mail->p_timed_thread)
4113 ERR("Error starting pop3 thread");
4114 timed_thread_register (info.mail->p_timed_thread,
4115 &info.mail->p_timed_thread);
4117 timed_thread_lock (info.mail->p_timed_thread);
4118 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4119 timed_thread_unlock (info.mail->p_timed_thread);
4120 } else if (obj->data.mail) { // this means we use obj
4121 if (!obj->data.mail->p_timed_thread)
4123 obj->data.mail->p_timed_thread =
4124 timed_thread_create ((void*)pop3_thread,
4125 (void*)obj->data.mail,
4126 obj->data.mail->interval * 1000000);
4127 if (!obj->data.mail->p_timed_thread)
4128 ERR("Error starting pop3 thread");
4129 timed_thread_register (obj->data.mail->p_timed_thread,
4130 &obj->data.mail->p_timed_thread);
4132 timed_thread_lock (obj->data.mail->p_timed_thread);
4133 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4134 timed_thread_unlock (obj->data.mail->p_timed_thread);
4135 } else if (!obj->a) { // something is wrong, warn once then stop
4136 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4141 if (obj->data.fs != NULL) {
4142 if (obj->data.fs->size == 0)
4161 if (obj->data.fs != NULL)
4162 human_readable(obj->data.fs->avail,
4166 if (obj->data.fs != NULL) {
4167 if (obj->data.fs->size)
4168 snprintf(p, p_max_size, "%*d",
4177 snprintf(p, p_max_size, "0");
4181 if (obj->data.fs != NULL)
4182 human_readable(obj->data.fs->size,
4186 if (obj->data.fs != NULL)
4187 human_readable(obj->data.fs->size -
4188 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
4192 if (obj->data.fs != NULL) {
4193 if (obj->data.fs->size == 0)
4211 if (obj->data.fs != NULL) {
4212 if (obj->data.fs->size)
4213 snprintf(p, 4, "%d",
4223 snprintf(p, p_max_size, "0");
4227 float *v = info.loadavg;
4229 if (obj->data.loadavg[2])
4230 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4231 v[obj->data.loadavg[0] -
4233 v[obj->data.loadavg[1] -
4235 v[obj->data.loadavg[2] -
4237 else if (obj->data.loadavg[1])
4238 snprintf(p, p_max_size, "%.2f %.2f",
4239 v[obj->data.loadavg[0] -
4241 v[obj->data.loadavg[1] -
4243 else if (obj->data.loadavg[0])
4244 snprintf(p, p_max_size, "%.2f",
4245 v[obj->data.loadavg[0] -
4249 new_goto(p, obj->data.i);
4252 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4255 new_hr(p, obj->data.i);
4262 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4263 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4265 snprintf(p, p_max_size, "N/A");
4266 } else if (unit == '*') {
4267 snprintf(p, p_max_size, "%s", temp);
4269 snprintf(p, p_max_size, "%s°%c", temp, unit);
4274 new_offset(p, obj->data.i);
4277 new_voffset(p, obj->data.i);
4282 r = get_i2c_info(&obj->data.i2c.fd,
4284 obj->data.i2c.devtype,
4285 obj->data.i2c.type);
4287 if (r >= 100.0 || r == 0)
4288 snprintf(p, p_max_size, "%d", (int) r);
4290 snprintf(p, p_max_size, "%.1f", r);
4293 new_alignr(p, obj->data.i);
4296 new_alignc(p, obj->data.i);
4299 struct information *my_info =
4300 malloc(sizeof(struct information));
4301 memcpy(my_info, cur, sizeof(struct information));
4302 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4303 if (strlen(p) != 0) {
4304 i = obj->data.ifblock.pos;
4314 if ((obj->data.ifblock.s)
4315 && (stat(obj->data.ifblock.s, &tmp) ==
4317 i = obj->data.ifblock.pos;
4320 if (obj->data.ifblock.str) {
4321 if (!check_contains(obj->data.ifblock.s,
4322 obj->data.ifblock.str)) {
4323 i = obj->data.ifblock.pos;
4332 if ((obj->data.ifblock.s)
4333 && (!check_mount(obj->data.ifblock.s))) {
4334 i = obj->data.ifblock.pos;
4341 if ((obj->data.ifblock.s)
4342 && system(obj->data.ifblock.s)) {
4343 i = obj->data.ifblock.pos;
4350 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4353 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4358 human_readable(cur->mem * 1024, p, 255);
4361 human_readable(cur->memmax * 1024, p, 255);
4366 snprintf(p, p_max_size, "%*Lu",
4371 snprintf(p, 4, "%*Lu ",
4378 new_bar(p, obj->data.pair.a,
4380 cur->memmax ? (cur->mem * 255) /
4385 new_graph(p, obj->a,
4386 obj->b, obj->c, obj->d,
4387 cur->memmax ? (cur->mem * 100.0) /
4388 (cur->memmax) : 0.0, 100, 1);
4392 snprintf(p, p_max_size, "%d",
4393 mixer_get_avg(obj->data.l));
4396 snprintf(p, p_max_size, "%d",
4397 mixer_get_left(obj->data.l));
4400 snprintf(p, p_max_size, "%d",
4401 mixer_get_right(obj->data.l));
4404 new_bar(p, obj->data.mixerbar.w,
4405 obj->data.mixerbar.h,
4406 mixer_get_avg(obj->data.mixerbar.
4410 new_bar(p, obj->data.mixerbar.w,
4411 obj->data.mixerbar.h,
4412 mixer_get_left(obj->data.mixerbar.
4416 new_bar(p, obj->data.mixerbar.w,
4417 obj->data.mixerbar.h,
4418 mixer_get_right(obj->data.mixerbar.
4424 snprintf(p, p_max_size, "%d", cur->mail_count);
4427 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4428 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4431 snprintf(p, p_max_size, "%d", cur->new_mail_count);
4435 snprintf(p, p_max_size, "%s",
4436 cur->uname_s.nodename);
4439 new_outline(p, obj->data.l);
4443 snprintf(p, p_max_size, "%hu", cur->procs);
4445 snprintf(p, 5, "%hu ",
4448 OBJ(running_processes) {
4450 snprintf(p, p_max_size, "%hu",
4453 snprintf(p, 3, "%hu ",
4457 snprintf(p, p_max_size, "%s", obj->data.s);
4460 new_bg(p, obj->data.l);
4463 new_stippled_hr(p, obj->data.pair.a,
4467 human_readable(cur->swap * 1024, p, 255);
4470 human_readable(cur->swapmax * 1024, p,
4474 if (cur->swapmax == 0) {
4475 strncpy(p, "No swap", 255);
4478 snprintf(p, 255, "%*Lu",
4484 snprintf(p, 4, "%*Lu ",
4492 new_bar(p, obj->data.pair.a,
4494 cur->swapmax ? (cur->swap * 255) /
4495 (cur->swapmax) : 0);
4498 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4501 time_t t = time(NULL);
4502 struct tm *tm = localtime(&t);
4503 setlocale(LC_TIME, "");
4504 strftime(p, p_max_size, obj->data.s, tm);
4507 time_t t = time(NULL);
4508 struct tm *tm = gmtime(&t);
4509 strftime(p, p_max_size, obj->data.s, tm);
4513 if (obj->data.tztime.tz) {
4514 oldTZ = getenv("TZ");
4515 setenv("TZ", obj->data.tztime.tz, 1);
4518 time_t t = time(NULL);
4519 struct tm *tm = localtime(&t);
4520 setlocale(LC_TIME, "");
4521 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4523 setenv("TZ", oldTZ, 1);
4528 // Needless to free oldTZ since getenv gives ptr to static data
4531 human_readable(obj->data.net->recv, p,
4535 human_readable(obj->data.net->trans, p,
4539 snprintf(p, p_max_size, "%d", total_updates);
4543 snprintf(p, p_max_size, "%d",
4544 (int) (obj->data.net->
4548 snprintf(p, 5, "%d ",
4549 (int) (obj->data.net->
4555 snprintf(p, p_max_size, "%.1f",
4557 trans_speed / 1024.0);
4559 snprintf(p, 8, "%.1f ",
4561 trans_speed / 1024.0);
4565 if (obj->data.net->trans_speed == 0)
4566 obj->data.net->trans_speed = 0.01;
4568 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4569 (obj->data.net->trans_speed /
4570 1024.0), obj->e, 1);
4573 format_seconds_short(p, p_max_size,
4577 format_seconds(p, p_max_size, (int) cur->uptime);
4580 #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4583 msg = get_apm_adapter();
4584 snprintf(p, p_max_size, "%s", msg);
4587 OBJ(apm_battery_life) {
4589 msg = get_apm_battery_life();
4590 snprintf(p, p_max_size, "%s", msg);
4593 OBJ(apm_battery_time) {
4595 msg = get_apm_battery_time();
4596 snprintf(p, p_max_size, "%s", msg);
4599 #endif /* __FreeBSD__ __OpenBSD__ */
4603 snprintf(p, p_max_size, "%s", cur->mpd.title);
4606 snprintf(p, p_max_size, "%s", cur->mpd.artist);
4609 snprintf(p, p_max_size, "%s", cur->mpd.album);
4612 snprintf(p, p_max_size, "%s", cur->mpd.random);
4615 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
4618 snprintf(p, p_max_size, "%s", cur->mpd.track);
4621 snprintf(p, p_max_size, "%s", cur->mpd.name);
4624 snprintf(p, p_max_size, "%s", cur->mpd.file);
4627 snprintf(p, p_max_size, "%i", cur->mpd.volume);
4630 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
4633 snprintf(p, p_max_size, "%s", cur->mpd.status);
4636 int days = 0, hours = 0, minutes =
4638 int tmp = cur->mpd.elapsed;
4639 while (tmp >= 86400) {
4643 while (tmp >= 3600) {
4653 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
4654 days, hours, minutes,
4657 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4660 snprintf(p, p_max_size, "%i:%02i", minutes,
4664 int days = 0, hours = 0, minutes =
4666 int tmp = cur->mpd.length;
4667 while (tmp >= 86400) {
4671 while (tmp >= 3600) {
4681 snprintf(p, p_max_size,
4682 "%i days %i:%02i:%02i",
4683 days, hours, minutes,
4686 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
4689 snprintf(p, p_max_size, "%i:%02i", minutes,
4693 snprintf(p, p_max_size, "%2.0f",
4694 cur->mpd.progress * 100);
4697 new_bar(p, obj->data.pair.a,
4699 (int) (cur->mpd.progress *
4703 if (strlen(cur->mpd.title) < 2 && strlen(cur->mpd.title) < 2) {
4704 snprintf(p, p_max_size, "%s", cur->mpd.file);
4706 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
4712 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
4715 snprintf(p, p_max_size, "%s", cur->xmms2.album);
4718 snprintf(p, p_max_size, "%s", cur->xmms2.title);
4721 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
4723 OBJ(xmms2_comment) {
4724 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
4726 OBJ(xmms2_decoder) {
4727 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
4729 OBJ(xmms2_transport) {
4730 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
4733 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4736 snprintf(p, p_max_size, "%s", cur->xmms2.status);
4739 snprintf(p, p_max_size, "%s", cur->xmms2.date);
4741 OBJ(xmms2_tracknr) {
4742 if (cur->xmms2.tracknr != -1)
4743 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
4745 OBJ(xmms2_bitrate) {
4746 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
4749 snprintf(p, p_max_size, "%u", cur->xmms2.id);
4752 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
4754 OBJ(xmms2_elapsed) {
4755 int tmp = cur->xmms2.elapsed;
4756 snprintf(p, p_max_size, "%02d:%02d",
4757 tmp / 60000, (tmp / 1000) % 60);
4759 OBJ(xmms2_duration) {
4760 int tmp = cur->xmms2.duration;
4761 snprintf(p, p_max_size, "%02d:%02d",
4762 tmp / 60000, (tmp / 1000) % 60);
4764 OBJ(xmms2_percent) {
4765 snprintf(p, p_max_size, "%2.0f",
4766 cur->xmms2.progress * 100);
4769 new_bar(p, obj->data.pair.a,
4771 (int) (cur->xmms2.progress *
4775 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
4776 snprintf(p, p_max_size, "%s", cur->xmms2.url);
4778 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
4783 OBJ(audacious_status) {
4784 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
4786 OBJ(audacious_title) {
4787 snprintf(p, cur->audacious.max_title_len > 0 ?
4788 cur->audacious.max_title_len : p_max_size, "%s",
4789 cur->audacious.items[AUDACIOUS_TITLE]);
4791 OBJ(audacious_length) {
4792 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
4794 OBJ(audacious_length_seconds) {
4795 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4797 OBJ(audacious_position) {
4798 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
4800 OBJ(audacious_position_seconds) {
4801 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
4803 OBJ(audacious_bitrate) {
4804 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
4806 OBJ(audacious_frequency) {
4807 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
4809 OBJ(audacious_channels) {
4810 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
4812 OBJ(audacious_filename) {
4813 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
4815 OBJ(audacious_playlist_length) {
4816 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
4818 OBJ(audacious_playlist_position) {
4819 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
4821 OBJ(audacious_bar) {
4823 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
4824 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
4825 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
4830 snprintf(p, p_max_size, "%s", cur->bmpx.title);
4833 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
4836 snprintf(p, p_max_size, "%s", cur->bmpx.album);
4839 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
4842 snprintf(p, p_max_size, "%i", cur->bmpx.track);
4845 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
4849 if (obj->data.top.type == TOP_NAME
4850 && obj->data.top.num >= 0
4851 && obj->data.top.num < 10) {
4852 // if we limit the buffer and add a bunch of space after, it stops the thing from
4853 // moving other shit around, which is really fucking annoying
4854 snprintf(p, 17, "%s ", cur->cpu[obj->data.top.num]->name);
4855 } else if (obj->data.top.type == TOP_CPU
4856 && obj->data.top.num >= 0
4857 && obj->data.top.num < 10) {
4858 snprintf(p, 7, "%3.2f ",
4859 cur->cpu[obj->data.top.
4861 } else if (obj->data.top.type == TOP_PID
4862 && obj->data.top.num >= 0
4863 && obj->data.top.num < 10) {
4864 snprintf(p, 8, "%i ",
4865 cur->cpu[obj->data.top.
4867 } else if (obj->data.top.type == TOP_MEM
4868 && obj->data.top.num >= 0
4869 && obj->data.top.num < 10) {
4870 snprintf(p, 7, "%3.2f ",
4871 cur->cpu[obj->data.top.
4876 if (obj->data.top.type == TOP_NAME
4877 && obj->data.top.num >= 0
4878 && obj->data.top.num < 10) {
4879 // if we limit the buffer and add a bunch of space after, it stops the thing from
4880 // moving other shit around, which is really fucking annoying
4883 cur->memu[obj->data.top.
4885 } else if (obj->data.top.type == TOP_CPU
4886 && obj->data.top.num >= 0
4887 && obj->data.top.num < 10) {
4888 snprintf(p, 7, "%3.2f ",
4889 cur->memu[obj->data.top.
4891 } else if (obj->data.top.type == TOP_PID
4892 && obj->data.top.num >= 0
4893 && obj->data.top.num < 10) {
4894 snprintf(p, 8, "%i ",
4895 cur->memu[obj->data.top.
4897 } else if (obj->data.top.type == TOP_MEM
4898 && obj->data.top.num >= 0
4899 && obj->data.top.num < 10) {
4900 snprintf(p, 7, "%3.2f ",
4901 cur->memu[obj->data.top.
4908 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4909 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4911 obj->data.tail.last_update = current_update_time;
4915 fp = fopen(obj->data.tail.logfile, "rt");
4917 /* Send one message, but do not consistently spam on
4918 * missing logfiles. */
4919 if(obj->data.tail.readlines != 0) {
4920 ERR("tail logfile failed to open");
4921 strcpy(obj->data.tail.buffer, "Logfile Missing");
4923 obj->data.tail.readlines = 0;
4924 snprintf(p, p_max_size, "Logfile Missing");
4927 obj->data.tail.readlines = 0;
4928 /* -1 instead of 0 to avoid counting a trailing newline */
4929 fseek(fp, -1, SEEK_END);
4930 bsize = ftell(fp) + 1;
4931 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
4932 nl = rev_fcharfind(fp, '\n', iter);
4936 obj->data.tail.readlines = iter;
4937 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
4938 fseek(fp, 0, SEEK_SET);
4941 fseek(fp, nl+1, SEEK_SET);
4944 /* Make sure bsize is at least 1 byte smaller than
4945 * the buffer max size. */
4946 if(bsize > (long)((text_buffer_size*20) - 1)) {
4947 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
4948 bsize = text_buffer_size*20 - 1;
4950 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
4953 /* Clean up trailing newline, make sure the buffer
4954 * is null terminated. */
4955 if(obj->data.tail.buffer[bsize-1] == '\n')
4956 obj->data.tail.buffer[bsize-1] = '\0';
4958 obj->data.tail.buffer[bsize] = '\0';
4959 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4962 strcpy(obj->data.tail.buffer, "Logfile Empty");
4963 snprintf(p, p_max_size, "Logfile Empty");
4966 } /* if cur_upd_time >= */
4968 //parse_conky_vars(obj->data.tail.buffer, p, cur);
4972 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
4973 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
4975 obj->data.tail.last_update = current_update_time;
4979 fp = fopen(obj->data.tail.logfile, "rt");
4981 /* Send one message, but do not consistently spam on
4982 * missing logfiles. */
4983 if(obj->data.tail.readlines != 0) {
4984 ERR("head logfile failed to open");
4985 strcpy(obj->data.tail.buffer, "Logfile Missing");
4987 obj->data.tail.readlines = 0;
4988 snprintf(p, p_max_size, "Logfile Missing");
4990 obj->data.tail.readlines = 0;
4991 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
4992 nl = fwd_fcharfind(fp, '\n', iter);
4996 obj->data.tail.readlines = iter;
4997 /* Make sure nl is at least 1 byte smaller than
4998 * the buffer max size. */
4999 if(nl > (long)((text_buffer_size*20) - 1)) {
5000 nl = text_buffer_size*20 - 1;
5002 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5005 /* Clean up trailing newline, make sure the buffer
5006 * is null terminated. */
5007 if (obj->data.tail.buffer[nl-1] == '\n') {
5008 obj->data.tail.buffer[nl-1] = '\0';
5011 obj->data.tail.buffer[nl] = '\0';
5013 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5016 strcpy(obj->data.tail.buffer, "Logfile Empty");
5017 snprintf(p, p_max_size, "Logfile Empty");
5019 } /* if fp == null */
5020 } /* cur_upd_time >= */
5022 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5025 #ifdef TCP_PORT_MONITOR
5028 /* grab a pointer to this port monitor */
5029 tcp_port_monitor_t * p_monitor =
5030 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
5031 obj->data.tcp_port_monitor.port_range_begin,
5032 obj->data.tcp_port_monitor.port_range_end );
5034 snprintf(p, p_max_size, "monitor not found");
5038 /* now grab the text of interest */
5039 if ( peek_tcp_port_monitor( p_monitor,
5040 obj->data.tcp_port_monitor.item,
5041 obj->data.tcp_port_monitor.connection_index,
5042 p, p_max_size ) != 0 )
5044 snprintf(p, p_max_size, "monitor peek error");
5053 iconv_converting = 1;
5054 iconv_selected = obj->a;
5059 iconv_converting = 0;
5065 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5067 OBJ(entropy_poolsize)
5069 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5073 double entropy_perc;
5074 entropy_perc = (double)cur->entropy.entropy_avail /
5075 (double)cur->entropy.poolsize;
5076 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5084 unsigned int a = strlen(p);
5087 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5089 size_t dummy1, dummy2;
5090 char *ptr = buff_in;
5093 dummy1 = dummy2 = a;
5095 strncpy(buff_in, p, P_MAX_SIZE);
5097 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5098 while (dummy1 > 0) {
5099 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5101 ERR("Iconv codeset conversion failed");
5106 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5117 double current_update_time, last_update_time;
5119 static void generate_text()
5121 struct information *cur = &info;
5129 current_update_time = get_time();
5132 /* fix diskio rates to b/s (use update_interval */
5133 diskio_read_value = diskio_read_value / update_interval;
5134 diskio_write_value = diskio_write_value / update_interval;
5135 diskio_value = diskio_value / update_interval;
5138 /* add things to the buffer */
5144 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5146 if (stuff_in_upper_case) {
5157 last_update_time = current_update_time;
5164 static void set_font()
5168 if (window.xftdraw != NULL) {
5169 XftDrawDestroy(window.xftdraw);
5171 window.xftdraw = XftDrawCreate(display, window.drawable,
5172 DefaultVisual(display,
5174 DefaultColormap(display,
5179 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5185 static inline int get_string_width(const char *s)
5188 return *s ? calc_text_width(s, strlen(s)) : 0;
5194 static inline int get_string_width_special(char *s)
5207 if (*p == SPECIAL_CHAR) {
5208 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5209 for (i = 0; i < strlen(p); i++) {
5210 *(p + i) = *(p + i + 1);
5212 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5213 width += specials[special_index+index].width;
5220 if (strlen(final) > 1) {
5221 width += calc_text_width(final, strlen(final));
5231 static void text_size_updater(char *s);
5233 int last_font_height;
5234 static void update_text_area()
5238 /* update text size if it isn't fixed */
5243 text_width = minimum_width;
5246 last_font_height = font_height();
5247 for_each_line(text_buffer, text_size_updater);
5249 if (text_height < minimum_height)
5250 text_height = minimum_height;
5251 if (text_width > maximum_width && maximum_width > 0)
5252 text_width = maximum_width;
5255 /* get text position on workarea */
5256 switch (text_alignment) {
5263 x = workarea[2] - text_width - gap_x;
5270 y = workarea[3] - text_height - gap_y;
5274 x = workarea[2] - text_width - gap_x;
5275 y = workarea[3] - text_height - gap_y;
5279 case NONE: // Let the WM manage the window
5290 if (own_window && !fixed_pos) {
5293 text_start_x = border_margin + 1;
5294 text_start_y = border_margin + 1;
5295 window.x = x - border_margin - 1;
5296 window.y = y - border_margin - 1;
5300 /* If window size doesn't match to workarea's size, then window
5301 * probably includes panels (gnome).
5302 * Blah, doesn't work on KDE. */
5303 if (workarea[2] != window.width
5304 || workarea[3] != window.height) {
5318 static int cur_x, cur_y; /* current x and y for drawing */
5319 static int draw_mode; /* FG, BG or OUTLINE */
5320 static long current_color;
5323 static void text_size_updater(char *s)
5327 /* get string widths and skip specials */
5330 if (*p == SPECIAL_CHAR) {
5332 w += get_string_width(s);
5335 if (specials[special_index].type == BAR
5336 || specials[special_index].type == GRAPH) {
5337 w += specials[special_index].width;
5338 if (specials[special_index].height > last_font_height) {
5339 last_font_height = specials[special_index].height;
5340 last_font_height += font_ascent();
5342 } else if (specials[special_index].type == OFFSET) {
5343 w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
5344 } else if (specials[special_index].type == VOFFSET) {
5345 last_font_height += specials[special_index].arg;
5346 } else if (specials[special_index].type == GOTO) {
5347 if (specials[special_index].arg >= 0)
5348 w += (int)specials[special_index].arg - cur_x;
5349 } else if (specials[special_index].type == TAB) {
5350 int start = specials[special_index].arg;
5351 int step = specials[special_index].width;
5352 if (!step || step < 0)
5354 w += step - (cur_x - text_start_x - start) % step;
5355 } else if (specials[special_index].type == FONT) {
5356 selected_font = specials[special_index].font_added;
5357 if (font_height() > last_font_height) {
5358 last_font_height = font_height();
5367 w += get_string_width(s);
5368 if (w > text_width) {
5371 if (text_width > maximum_width && maximum_width) {
5372 text_width = maximum_width;
5375 text_height += last_font_height;
5376 last_font_height = font_height();
5380 static inline void set_foreground_color(long c)
5383 XSetForeground(display, window.gc, c);
5387 static void draw_string(const char *s)
5391 int i, i2, pos, width_of_s;
5394 width_of_s = get_string_width(s);
5395 if (out_to_console) {
5397 fflush(stdout); /* output immediately, don't buffer */
5399 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5400 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5401 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5405 snprintf(space, 2, " ");
5407 max = ((text_width - width_of_s) / get_string_width(space));
5410 * This code looks for tabs in the text and coverts them to spaces.
5411 * The trick is getting the correct number of spaces,
5412 * and not going over the window's size without forcing
5413 * the window larger.
5415 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5416 if (tmpstring1[i] == '\t') // 9 is ascii tab
5420 i2 < (8 - (1 + pos) % 8) && added <= max;
5423 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5424 fprintf(stderr,"buffer overrun detected\n");
5426 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5431 if (tmpstring1[i] != 9) {
5433 if ( pos > TEXT_BUFFER_SIZE-1 )
5434 fprintf(stderr,"buffer overrun detected\n");
5436 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5442 if (text_width == maximum_width) {
5443 /* this means the text is probably pushing the limit, so we'll chop it */
5444 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5445 tmpstring2[strlen(tmpstring2)-1] = '\0';
5455 c.pixel = current_color;
5456 XQueryColor(display, DefaultColormap(display, screen), &c);
5459 c2.color.red = c.red;
5460 c2.color.green = c.green;
5461 c2.color.blue = c.blue;
5462 c2.color.alpha = fonts[selected_font].font_alpha;
5464 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5465 cur_x, cur_y, (XftChar8 *) s,
5468 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5469 cur_x, cur_y, (XftChar8 *) s,
5475 XDrawString(display, window.drawable, window.gc,
5476 cur_x, cur_y, s, strlen(s));
5478 cur_x += width_of_s;
5480 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5483 long redmask, greenmask, bluemask;
5485 void set_up_gradient()
5488 colour_depth = DisplayPlanes(display, screen);
5492 if (colour_depth != 24 && colour_depth != 16) {
5493 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5499 for(i = (colour_depth / 3)-1; i>=0; i--) {
5501 greenmask |= 1 << i;
5504 if (colour_depth%3 == 1) {
5505 greenmask |= 1 << (colour_depth / 3);
5507 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5508 greenmask = greenmask << (colour_depth / 3);
5511 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 */
5513 int red1, green1, blue1; // first colour
5514 int red2, green2, blue2; // second colour
5515 int red3 = 0, green3 = 0, blue3 = 0; // difference
5516 short redshift = (2*colour_depth / 3 + colour_depth%3);
5517 short greenshift = (colour_depth / 3);
5518 red1 = (first_colour & redmask) >> redshift;
5519 green1 = (first_colour & greenmask) >> greenshift;
5520 blue1 = first_colour & bluemask;
5521 red2 = (last_colour & redmask) >> redshift;
5522 green2 = (last_colour & greenmask) >> greenshift;
5523 blue2 = last_colour & bluemask;
5530 if (green1 > green2) {
5533 if (green1 < green2) {
5536 if (blue1 > blue2) {
5539 if (blue1 < blue2) {
5554 if (red1 > bluemask) {
5557 if (green1 > bluemask) {
5560 if (blue1 > bluemask) {
5563 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
5567 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
5568 if (colour_depth == 0) {
5571 int red1, green1, blue1; // first colour
5572 int red2, green2, blue2; // second colour
5573 long redshift = (2*colour_depth / 3 + colour_depth%3);
5574 long greenshift = (colour_depth / 3);
5575 int red3 = 0, green3 = 0, blue3 = 0; // difference
5576 red1 = (first_colour & redmask) >> redshift;
5577 green1 = (first_colour & greenmask) >> greenshift;
5578 blue1 = first_colour & bluemask;
5579 red2 = (last_colour & redmask) >> redshift;
5580 green2 = (last_colour & greenmask) >> greenshift;
5581 blue2 = last_colour & bluemask;
5582 red3 = abs(red1 - red2);
5583 green3 = abs(green1 - green2);
5584 blue3 = abs(blue1 - blue2);
5593 static void draw_line(char *s)
5597 cur_x = text_start_x;
5598 cur_y += font_ascent();
5600 short font_h = font_height();
5602 /* find specials and draw stuff */
5605 if (*p == SPECIAL_CHAR) {
5608 /* draw string before special */
5615 switch (specials[special_index].type) {
5616 case HORIZONTAL_LINE:
5619 specials[special_index].height;
5620 int mid = font_ascent() / 2;
5621 w = text_start_x + text_width -
5624 XSetLineAttributes(display,
5629 XDrawLine(display, window.drawable,
5640 specials[special_index].height;
5642 specials[special_index].arg;
5643 int mid = font_ascent() / 2;
5644 char ss[2] = { s, s };
5645 w = text_start_x + text_width -
5648 XSetLineAttributes(display,
5653 XSetDashes(display, window.gc, 0,
5655 XDrawLine(display, window.drawable,
5665 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5669 specials[special_index].height;
5671 specials[special_index].arg;
5672 int by = cur_y - (font_ascent() / 2) - 1;
5673 if (h < font_height()) {
5676 w = specials[special_index].width;
5679 text_width - cur_x - 1;
5683 XSetLineAttributes(display,
5689 XDrawRectangle(display,
5693 XFillRectangle(display,
5697 w * bar_usage / 255,
5699 if (specials[special_index].
5701 && specials[special_index].
5705 [special_index].height;
5712 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
5716 specials[special_index].height;
5717 unsigned long last_colour = current_color;
5718 int by = cur_y - (font_ascent()/2) - 1;
5719 if (h < font_height()) {
5722 w = specials[special_index].width;
5724 w = text_start_x + text_width - cur_x - 1;
5727 if (draw_graph_borders) {
5728 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
5729 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
5731 XSetLineAttributes(display,
5738 int gradient_size = 0;
5739 float gradient_factor = 0;
5740 float gradient_update = 0;
5741 unsigned long tmpcolour = current_color;
5742 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5743 tmpcolour = specials[special_index].last_colour;
5744 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
5745 gradient_factor = (float)gradient_size / (w - 2);
5747 for (i = w - 2; i > -1; i--) {
5748 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
5749 XSetForeground(display, window.gc, tmpcolour);
5750 gradient_update += gradient_factor;
5751 while (gradient_update > 0) {
5752 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
5756 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
5759 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 */
5761 if (specials[special_index].
5763 && specials[special_index].
5767 [special_index].height;
5769 /* if (draw_mode == BG) {
5770 set_foreground_color(default_bg_color);
5772 else if (draw_mode == OUTLINE) {
5773 set_foreground_color(default_out_color);
5775 set_foreground_color(default_fg_color);
5777 set_foreground_color(last_colour);
5783 int old = font_ascent();
5784 cur_y -= font_ascent();
5785 selected_font = specials[special_index].font_added;
5786 if (cur_y + font_ascent() < cur_y + old) {
5789 cur_y += font_ascent();
5795 if (draw_mode == FG)
5796 set_foreground_color(specials
5802 if (draw_mode == BG)
5803 set_foreground_color(specials
5809 if (draw_mode == OUTLINE)
5810 set_foreground_color(specials
5816 w += specials[special_index].arg;
5820 cur_y += specials[special_index].arg;
5824 if (specials[special_index].arg >= 0)
5825 cur_x = (int)specials[special_index].arg;
5830 int start = specials[special_index].arg;
5831 int step = specials[special_index].width;
5832 if (!step || step < 0)
5834 w = step - (cur_x - text_start_x - start) % step;
5840 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
5841 /*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);*/
5842 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
5843 cur_x = pos_x - specials[special_index].arg;
5850 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
5851 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
5852 /*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);*/
5854 specials[special_index].arg)
5857 [special_index].arg;
5874 if (cur_y_add > 0) {
5876 cur_y -= font_descent();
5881 cur_y += font_descent();
5885 static void draw_text()
5888 cur_y = text_start_y;
5891 if (draw_borders && border_width > 0) {
5892 unsigned int b = (border_width + 1) / 2;
5894 if (stippled_borders) {
5896 { stippled_borders, stippled_borders };
5897 XSetLineAttributes(display, window.gc,
5898 border_width, LineOnOffDash,
5899 CapButt, JoinMiter);
5900 XSetDashes(display, window.gc, 0, ss, 2);
5902 XSetLineAttributes(display, window.gc,
5903 border_width, LineSolid,
5904 CapButt, JoinMiter);
5907 XDrawRectangle(display, window.drawable, window.gc,
5908 text_start_x - border_margin + b,
5909 text_start_y - border_margin + b,
5910 text_width + border_margin * 2 - 1 - b * 2,
5911 text_height + border_margin * 2 - 1 -
5918 for_each_line(text_buffer, draw_line);
5921 static void draw_stuff()
5925 if (draw_shades && !draw_outline) {
5928 set_foreground_color(default_bg_color);
5938 for (i = -1; i < 2; i++)
5939 for (j = -1; j < 2; j++) {
5940 if (i == 0 && j == 0)
5944 set_foreground_color(default_out_color);
5945 draw_mode = OUTLINE;
5952 set_foreground_color(default_fg_color);
5960 swap.swap_window = window.window;
5961 swap.swap_action = XdbeBackground;
5962 XdbeSwapBuffers(display, &swap, 1);
5968 static void clear_text(int exposures)
5972 return; /* The swap action is XdbeBackground, which clears */
5976 /* there is some extra space for borders and outlines */
5977 XClearArea(display, window.window,
5978 text_start_x - border_margin - 1,
5979 text_start_y - border_margin - 1,
5980 text_width + border_margin * 2 + 2,
5981 text_height + border_margin * 2 + 2,
5982 exposures ? True : 0);
5987 static int need_to_update;
5989 /* update_text() generates new text and clears old text area */
5990 static void update_text()
5999 static void main_loop()
6001 #ifdef SIGNAL_BLOCKING
6002 sigset_t newmask, oldmask;
6004 sigemptyset(&newmask);
6005 sigaddset(&newmask,SIGINT);
6006 sigaddset(&newmask,SIGTERM);
6007 sigaddset(&newmask,SIGUSR1);
6011 Region region = XCreateRegion();
6013 int event_base, error_base;
6014 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
6015 ERR("Xdamage extension unavailable");
6017 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
6018 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
6019 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
6020 #endif /* HAVE_XDAMAGE */
6024 while (total_run_times == 0 || info.looped < total_run_times) {
6027 #ifdef SIGNAL_BLOCKING
6028 /* block signals. we will inspect for pending signals later */
6029 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
6030 CRIT_ERR("unable to sigprocmask()");
6036 /* wait for X event or timeout */
6038 if (!XPending(display)) {
6043 update_interval - (get_time() -
6049 tv.tv_sec = (long) t;
6050 tv.tv_usec = (long) (t * 1000000) % 1000000;
6052 FD_SET(ConnectionNumber(display), &fdsr);
6055 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
6058 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
6063 ERR("can't select(): %s",
6074 if (need_to_update) {
6076 int wx = window.x, wy = window.y;
6084 /* resize window if it isn't right size */
6086 (text_width + border_margin * 2 + 1 !=
6088 || text_height + border_margin * 2 + 1 !=
6092 border_margin * 2 + 1;
6095 border_margin * 2 + 1;
6096 XResizeWindow(display,
6101 set_transparent_background(window.window);
6105 /* move window if it isn't in right position */
6108 || window.y != wy)) {
6109 XMoveWindow(display, window.window,
6110 window.x, window.y);
6120 r.x = text_start_x - border_margin;
6121 r.y = text_start_y - border_margin;
6122 r.width = text_width + border_margin * 2;
6123 r.height = text_height + border_margin * 2;
6124 XUnionRectWithRegion(&r, region, region);
6129 /* handle X events */
6131 while (XPending(display)) {
6133 XNextEvent(display, &ev);
6140 r.width = ev.xexpose.width;
6141 r.height = ev.xexpose.height;
6142 XUnionRectWithRegion(&r, region,
6148 case ReparentNotify:
6149 /* set background to ParentRelative for all parents */
6151 set_transparent_background(window.
6156 case ConfigureNotify:
6158 /* if window size isn't what expected, set fixed size */
6159 if (ev.xconfigure.width !=
6161 || ev.xconfigure.height !=
6163 if (window.width != 0
6164 && window.height != 0)
6167 /* clear old stuff before screwing up size and pos */
6173 if (XGetWindowAttributes(display, window.window, &attrs)) {
6188 border_margin * 2 - 1;
6191 border_margin * 2 - 1;
6192 if (text_width > maximum_width && maximum_width > 0)
6193 text_width = maximum_width;
6196 /* if position isn't what expected, set fixed pos, total_updates
6197 * avoids setting fixed_pos when window is set to weird locations
6199 /*if (total_updates >= 2 this is broken
6201 && (window.x != ev.xconfigure.x
6204 && (ev.xconfigure.x != 0
6205 || ev.xconfigure.y != 0)) {
6215 /* if an ordinary window with decorations */
6216 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6218 /* allow conky to hold input focus.*/
6223 /* forward the click to the desktop window */
6224 XUngrabPointer(display, ev.xbutton.time);
6225 ev.xbutton.window = window.desktop;
6226 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6227 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6235 /* if an ordinary window with decorations */
6236 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6238 /* allow conky to hold input focus.*/
6243 /* forward the release to the desktop window */
6244 ev.xbutton.window = window.desktop;
6245 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6254 if (ev.type == event_base + XDamageNotify) {
6255 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6256 XFixesSetRegion(display, part, &dev->area, 1);
6257 XFixesUnionRegion(display, region2, region2, part);
6259 #endif /* HAVE_XDAMAGE */
6264 XDamageSubtract(display, damage, region2, None);
6265 XFixesSetRegion(display, region2, 0, 0);
6266 #endif /* HAVE_XDAMAGE */
6268 /* XDBE doesn't seem to provide a way to clear the back buffer without
6269 * interfering with the front buffer, other than passing XdbeBackground
6270 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6271 * redraw the text even if it wasn't part of the exposed area. OTOH,
6272 * if we're not going to call draw_stuff at all, then no swap happens
6273 * and we can safely do nothing.
6276 if (!XEmptyRegion(region)) {
6280 r.x = text_start_x - border_margin;
6281 r.y = text_start_y - border_margin;
6282 r.width = text_width + border_margin * 2;
6283 r.height = text_height + border_margin * 2;
6284 XUnionRectWithRegion(&r, region, region);
6287 XSetRegion(display, window.gc, region);
6290 XftDrawSetClip(window.xftdraw, region);
6296 XDestroyRegion(region);
6297 region = XCreateRegion();
6301 #ifdef SIGNAL_BLOCKING
6302 /* unblock signals of interest and let handler fly */
6303 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6304 CRIT_ERR("unable to sigprocmask()");
6307 switch(g_signal_pending) {
6310 ERR("received SIGUSR1. reloading the config file.");
6317 ERR("received SIGINT or SIGTERM to terminate. bye!");
6320 XDestroyRegion(region);
6323 return; /* return from main_loop */
6328 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6329 * but didn't write any code to deal with it. if you don't want to
6330 * handle a signal, don't set a handler on it in the first place. */
6331 if (g_signal_pending)
6332 ERR("ignoring signal (%d)", g_signal_pending);
6339 #if defined(X11) && defined(HAVE_XDAMAGE)
6340 XDamageDestroy(display, damage);
6341 XFixesDestroyRegion(display, region2);
6342 XFixesDestroyRegion(display, part);
6343 XDestroyRegion(region);
6345 #endif /* X11 && HAVE_XDAMAGE */
6348 static void load_config_file(const char *);
6350 /* reload the config file */
6351 void reload_config(void)
6353 timed_thread_destroy_registered_threads ();
6355 if (info.cpu_usage) {
6356 free(info.cpu_usage);
6357 info.cpu_usage = NULL;
6360 #ifdef TCP_PORT_MONITOR
6361 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6364 if (current_config) {
6366 load_config_file(current_config);
6368 /* re-init specials array */
6369 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6370 ERR("failed to realloc specials array");
6375 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6378 #ifdef TCP_PORT_MONITOR
6379 info.p_tcp_port_monitor_collection = NULL;
6382 if (create_audacious_thread() !=0)
6383 CRIT_ERR("unable to create audacious thread!");
6384 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6386 extract_variable_text(text);
6395 timed_thread_destroy_registered_threads ();
6397 if (info.cpu_usage) {
6398 free(info.cpu_usage);
6399 info.cpu_usage = NULL;
6404 XdbeDeallocateBackBufferName(display, window.back_buffer);
6410 XDestroyWindow(display, window.window);
6411 XClearWindow(display, RootWindow(display, screen));
6417 XClearWindow(display, RootWindow(display, screen));
6422 XFreeGC(display, window.gc);
6425 free_text_objects(text_object_count, text_objects);
6426 text_object_count = 0;
6427 text_objects = NULL;
6429 if (text != original_text)
6432 free(current_config);
6433 free(current_mail_spool);
6435 #ifdef TCP_PORT_MONITOR
6436 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6437 info.p_tcp_port_monitor_collection = NULL;
6446 static int string_to_bool(const char *s)
6450 if (strcasecmp(s, "yes") == 0)
6452 if (strcasecmp(s, "true") == 0)
6454 if (strcasecmp(s, "1") == 0)
6459 static enum alignment string_to_alignment(const char *s)
6461 if (strcasecmp(s, "top_left") == 0)
6463 else if (strcasecmp(s, "top_right") == 0)
6465 else if (strcasecmp(s, "bottom_left") == 0)
6467 else if (strcasecmp(s, "bottom_right") == 0)
6468 return BOTTOM_RIGHT;
6469 else if (strcasecmp(s, "tl") == 0)
6471 else if (strcasecmp(s, "tr") == 0)
6473 else if (strcasecmp(s, "bl") == 0)
6475 else if (strcasecmp(s, "br") == 0)
6476 return BOTTOM_RIGHT;
6477 else if (strcasecmp(s, "none") == 0)
6484 static void set_default_configurations(void)
6486 fork_to_background = 0;
6487 total_run_times = 0;
6488 info.cpu_avg_samples = 2;
6489 info.net_avg_samples = 2;
6494 strcpy(info.mpd.host, "localhost");
6495 info.mpd.port = 6600;
6496 info.mpd.status = NULL;
6497 info.mpd.artist = NULL;
6498 info.mpd.album = NULL;
6499 info.mpd.title = NULL;
6500 info.mpd.random = NULL;
6501 info.mpd.track = NULL;
6502 info.mpd.name = NULL;
6503 info.mpd.file = NULL;
6506 info.xmms2.artist = NULL;
6507 info.xmms2.album = NULL;
6508 info.xmms2.title = NULL;
6509 info.xmms2.genre = NULL;
6510 info.xmms2.comment = NULL;
6511 info.xmms2.decoder = NULL;
6512 info.xmms2.transport = NULL;
6513 info.xmms2.url = NULL;
6514 info.xmms2.status = NULL;
6523 default_fg_color = WhitePixel(display, screen);
6524 default_bg_color = BlackPixel(display, screen);
6525 default_out_color = BlackPixel(display, screen);
6526 color0 = default_fg_color;
6527 color1 = default_fg_color;
6528 color2 = default_fg_color;
6529 color3 = default_fg_color;
6530 color4 = default_fg_color;
6531 color5 = default_fg_color;
6532 color6 = default_fg_color;
6533 color7 = default_fg_color;
6534 color8 = default_fg_color;
6535 color9 = default_fg_color;
6538 draw_graph_borders = 1;
6540 set_first_font("6x10");
6548 window.type=TYPE_NORMAL;
6550 strcpy(window.class_name, "Conky");
6552 sprintf(window.title,"%s - conky",info.uname_s.nodename);
6554 stippled_borders = 0;
6557 text_alignment = BOTTOM_LEFT;
6560 free(current_mail_spool);
6563 variable_substitute(MAIL_FILE, buf, 256);
6565 current_mail_spool = strdup(buf);
6569 update_interval = 10.0;
6570 stuff_in_upper_case = 0;
6572 #ifdef TCP_PORT_MONITOR
6573 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
6577 static void load_config_file(const char *f)
6579 #define CONF_ERR ERR("%s: %d: config file error", f, line)
6583 set_default_configurations();
6589 char buf[256], *p, *p2, *name, *value;
6591 if (fgets(buf, 256, fp) == NULL)
6596 /* break at comment */
6597 p2 = strchr(p, '#');
6602 while (*p && isspace((int) *p))
6605 continue; /* empty line */
6611 while (*p2 && !isspace((int) *p2))
6614 *p2 = '\0'; /* break at name's end */
6621 while (*p && isspace((int) *p))
6626 p2 = value + strlen(value);
6627 while (isspace((int) *(p2 - 1)))
6633 #define CONF2(a) if (strcasecmp(name, a) == 0)
6634 #define CONF(a) else CONF2(a)
6635 #define CONF3(a,b) \
6636 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
6640 CONF2("alignment") {
6642 int a = string_to_alignment(value);
6650 CONF("background") {
6651 fork_to_background = string_to_bool(value);
6655 CONF2("background") {
6656 fork_to_background = string_to_bool(value);
6660 CONF("border_margin") {
6662 border_margin = strtol(value, 0, 0);
6666 CONF("border_width") {
6668 border_width = strtol(value, 0, 0);
6674 color0 = get_x11_color(value);
6680 color1 = get_x11_color(value);
6686 color2 = get_x11_color(value);
6692 color3 = get_x11_color(value);
6698 color4 = get_x11_color(value);
6704 color5 = get_x11_color(value);
6710 color6 = get_x11_color(value);
6716 color7 = get_x11_color(value);
6722 color8 = get_x11_color(value);
6728 color9 = get_x11_color(value);
6732 CONF("default_color") {
6734 default_fg_color = get_x11_color(value);
6738 CONF3("default_shade_color", "default_shadecolor") {
6740 default_bg_color = get_x11_color(value);
6744 CONF3("default_outline_color", "default_outlinecolor") {
6746 default_out_color = get_x11_color(value);
6753 info.mail = parse_mail_args(IMAP, value);
6760 info.mail = parse_mail_args(POP3, value);
6768 strncpy(info.mpd.host, value, 127);
6774 info.mpd.port = strtol(value, 0, 0);
6775 if (info.mpd.port < 1
6776 || info.mpd.port > 0xffff)
6780 CONF("mpd_password") {
6782 strncpy(info.mpd.password, value, 127);
6788 CONF("sensor_device") {
6790 sensor_device = strtol(value, 0, 0);
6795 CONF("cpu_avg_samples") {
6797 cpu_avg_samples = strtol(value, 0, 0);
6798 if (cpu_avg_samples < 1
6799 || cpu_avg_samples > 14)
6808 CONF("net_avg_samples") {
6810 net_avg_samples = strtol(value, 0, 0);
6811 if (net_avg_samples < 1
6812 || net_avg_samples > 14)
6828 CONF("double_buffer") {
6829 use_xdbe = string_to_bool(value);
6833 CONF("override_utf8_locale") {
6834 utf8_mode = string_to_bool(value);
6837 CONF("draw_borders") {
6838 draw_borders = string_to_bool(value);
6840 CONF("draw_graph_borders") {
6841 draw_graph_borders = string_to_bool(value);
6843 CONF("draw_shades") {
6844 draw_shades = string_to_bool(value);
6846 CONF("draw_outline") {
6847 draw_outline = string_to_bool(value);
6850 CONF("out_to_console") {
6851 out_to_console = string_to_bool(value);
6853 CONF("use_spacer") {
6854 use_spacer = string_to_bool(value);
6859 use_xft = string_to_bool(value);
6863 set_first_font(value);
6868 if (value && font_count >= 0)
6869 fonts[0].font_alpha = atof(value)
6878 if (string_to_bool(value))
6879 ERR("Xft not enabled");
6882 /* xftfont silently ignored when no Xft */
6885 /* xftalpha is silently ignored when no Xft */
6890 set_first_font(value);
6899 gap_x = atoi(value);
6905 gap_y = atoi(value);
6910 CONF("mail_spool") {
6913 variable_substitute(value, buf, 256);
6917 if (current_mail_spool)
6918 free(current_mail_spool);
6919 current_mail_spool = strdup(buf);
6925 CONF("minimum_size") {
6928 (value, "%d %d", &minimum_width,
6929 &minimum_height) != 2)
6932 &minimum_width) != 1)
6937 CONF("maximum_width") {
6939 if (sscanf(value, "%d", &maximum_width) != 1)
6945 CONF("no_buffers") {
6946 no_buffers = string_to_bool(value);
6948 CONF("pad_percents") {
6949 pad_percents = atoi(value);
6953 CONF("own_window") {
6955 own_window = string_to_bool(value);
6959 CONF("own_window_class") {
6962 memset(window.class_name,0,sizeof(window.class_name));
6963 strncpy(window.class_name, value, sizeof(window.class_name)-1);
6968 CONF("own_window_title") {
6971 memset(window.title,0,sizeof(window.title));
6972 strncpy(window.title, value, sizeof(window.title)-1);
6977 CONF("own_window_transparent") {
6979 set_transparent = string_to_bool(value);
6983 CONF("own_window_colour") {
6985 background_colour = get_x11_color(value);
6987 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
6990 CONF("own_window_hints") {
6992 char *p_hint, *p_save;
6993 char delim[] = ", ";
6995 /* tokenize the value into individual hints */
6996 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
6998 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
6999 if (strncmp(p_hint,"undecorate",10) == 0)
7000 SET_HINT(window.hints,HINT_UNDECORATED);
7001 else if (strncmp(p_hint,"below",5) == 0)
7002 SET_HINT(window.hints,HINT_BELOW);
7003 else if (strncmp(p_hint,"above",5) == 0)
7004 SET_HINT(window.hints,HINT_ABOVE);
7005 else if (strncmp(p_hint,"sticky",6) == 0)
7006 SET_HINT(window.hints,HINT_STICKY);
7007 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
7008 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
7009 else if (strncmp(p_hint,"skip_pager",10) == 0)
7010 SET_HINT(window.hints,HINT_SKIP_PAGER);
7014 p_hint=strtok_r(NULL, delim, &p_save);
7016 while (p_hint!=NULL);
7021 CONF("own_window_type") {
7023 if (strncmp(value,"normal",6)==0)
7024 window.type = TYPE_NORMAL;
7025 else if (strncmp(value,"desktop",7)==0)
7026 window.type = TYPE_DESKTOP;
7027 else if (strncmp(value,"override",8)==0)
7028 window.type = TYPE_OVERRIDE;
7036 CONF("stippled_borders") {
7038 stippled_borders = strtol(value, 0, 0);
7040 stippled_borders = 4;
7044 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
7047 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
7049 CONF("update_interval") {
7051 update_interval = strtod(value, 0);
7055 CONF("total_run_times") {
7057 total_run_times = strtod(value, 0);
7062 stuff_in_upper_case = string_to_bool(value);
7064 CONF("max_specials") {
7066 max_specials = atoi(value);
7070 CONF("max_user_text") {
7072 max_user_text = atoi(value);
7076 CONF("text_buffer_size") {
7078 text_buffer_size = atoi(value);
7083 if (text != original_text)
7093 int l = strlen(text);
7094 if (fgets(buf, 256, fp) == NULL)
7097 realloc(text, l + strlen(buf)
7101 if (strlen(text) > max_user_text)
7105 text_lines = line + 1;
7108 #ifdef TCP_PORT_MONITOR
7109 CONF("max_port_monitor_connections")
7112 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7113 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
7115 /* an error. use default, warn and continue. */
7116 tcp_port_monitor_args.max_port_monitor_connections =
7117 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7120 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
7122 /* no error, just use default */
7123 tcp_port_monitor_args.max_port_monitor_connections =
7124 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7126 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
7131 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7143 /* : means that character before that takes an argument */
7144 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
7157 int main(int argc, char **argv)
7159 struct sigaction act, oact;
7162 memset(&info, 0, sizeof(info) );
7164 #ifdef TCP_PORT_MONITOR
7165 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7168 /* handle command line parameters that don't change configs */
7173 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7174 *s) || ((s = getenv("LANG")) && *s)) {
7175 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7177 ERR("malloc failed");
7179 for (x = 0; x < strlen(s); x++) {
7180 temp[x] = tolower(s[x]);
7182 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7188 if (!setlocale(LC_CTYPE, "")) {
7189 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7193 int c = getopt(argc,
7204 /* if current_config is set to a strdup of CONFIG_FILE, free it (even
7205 * though free() does the NULL check itself;), then load optarg value */
7207 free(current_config);
7208 current_config = strdup(optarg);
7213 ("Usage: %s [OPTION]...\n"
7214 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7215 "window. Command line options will override configurations defined in config\n"
7218 " -c FILE config file to load instead of "
7221 " -d daemonize, fork to background\n"
7224 " -a ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7225 " -f FONT font to use\n"
7227 " -o create own window to draw\n"
7230 " -b double buffer (prevents flickering)\n"
7232 " -w WIN_ID window id to draw\n"
7233 " -x X x position\n"
7234 " -y Y y position\n"
7236 " -t TEXT text to render, remember single quotes, like -t '$uptime'\n"
7237 " -u SECS update interval\n"
7238 " -i NUM number of times to update Conky\n", argv[0]);
7242 window.window = strtol(optarg, 0, 0);
7251 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7255 /* load current_config or CONFIG_FILE */
7258 if (current_config == NULL) {
7259 /* load default config file */
7262 variable_substitute(CONFIG_FILE, buf, 256);
7265 current_config = strdup(buf);
7269 if (current_config != NULL && fopen((const char *)current_config, (const char *)"r"))
7270 load_config_file(current_config);
7272 set_default_configurations();
7275 /* init specials array */
7276 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7277 ERR("failed to create specials array");
7280 if (current_mail_spool == NULL) {
7282 variable_substitute(MAIL_FILE, buf, 256);
7285 current_mail_spool = strdup(buf);
7289 /* handle other command line arguments */
7291 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
7292 optind = optreset = 1;
7297 #if defined(__FreeBSD__)
7298 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7299 O_RDONLY, "kvm_open")) == NULL)
7300 CRIT_ERR( "cannot read kvm");
7304 int c = getopt(argc,
7312 fork_to_background = 1;
7317 set_first_font(optarg);
7320 text_alignment = string_to_alignment(optarg);
7335 if (text != original_text)
7337 text = strdup(optarg);
7338 convert_escapes(text);
7342 update_interval = strtod(optarg, 0);
7346 total_run_times = strtod(optarg, 0);
7350 gap_x = atoi(optarg);
7354 gap_y = atoi(optarg);
7368 /* generate text and get initial size */
7369 extract_variable_text(text);
7370 if (text != original_text) {
7375 if (fork_to_background) {
7379 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
7385 fprintf(stderr,"\n"); fflush(stderr);
7389 /* parent process */
7390 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
7397 update_text_area(); /* to get initial size of the window */
7401 text_width + border_margin * 2 + 1,
7402 text_height + border_margin * 2 + 1,
7403 set_transparent, background_colour, argv, argc);
7406 update_text_area(); /* to position text/window on screen */
7411 if (own_window && !fixed_pos) {
7412 XMoveWindow(display, window.window, window.x, window.y);
7415 set_transparent_background(window.window);
7426 /* Set signal handlers */
7427 act.sa_handler = signal_handler;
7428 sigemptyset(&act.sa_mask);
7431 act.sa_flags |= SA_RESTART;
7434 if ( sigaction(SIGINT,&act,&oact) < 0 ||
7435 sigaction(SIGUSR1,&act,&oact) < 0 ||
7436 sigaction(SIGTERM,&act,&oact) < 0 )
7438 ERR("error setting signal handler: %s", strerror(errno) );
7442 if (create_audacious_thread() !=0)
7443 CRIT_ERR("unable to create audacious thread!");
7444 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
7455 #if defined(__FreeBSD__)
7462 void signal_handler(int sig)
7464 /* signal handler is light as a feather, as it should be.
7465 * we will poll g_signal_pending with each loop of conky
7466 * and do any signal processing there, NOT here. */
7467 g_signal_pending=sig;