1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10 * Copyright (c) 2005-2008 Brenden Matthews, Philip Kovacs, et. al.
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
45 #include <X11/Xutil.h>
47 #include <X11/extensions/Xdamage.h>
53 #include <sys/types.h>
55 #include <netinet/in.h>
67 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
70 #define CONFIG_FILE "$HOME/.conkyrc"
71 #define MAIL_FILE "$MAIL"
72 #define MAX_IF_BLOCK_DEPTH 5
73 #define MAX_TAIL_LINES 100
75 /* #define SIGNAL_BLOCKING */
76 #undef SIGNAL_BLOCKING
78 static void print_version(void) __attribute__((noreturn));
80 static void print_version(void)
82 printf("Conky %s compiled %s for %s\n", VERSION, BUILD_DATE, BUILD_ARCH);
84 printf("\nCompiled in features:\n\n"
85 "System config file: %s\n\n"
89 " * Xdamage extension\n"
90 # endif /* HAVE_XDAMAGE */
92 " * Xdbe extension (double buffer)\n"
93 # endif /* HAVE_XDBE */
98 "\n Music detection:\n"
101 #endif /* AUDACIOUS */
111 "\n General features:\n"
115 #ifdef TCP_PORT_MONITOR
117 #endif /* TCP_PORT_MONITOR */
123 #endif /* HAVE_IWLIB */
127 "", SYSTEM_CONFIG_FILE
133 static const char *suffixes[] = { "B", "kiB", "MiB", "GiB", "TiB", "PiB", "" };
139 static int text_start_x, text_start_y; /* text start position in window */
140 static int text_width, text_height;
158 char name[DEFAULT_TEXT_BUFFER_SIZE];
168 static int selected_font = 0;
169 static int font_count = -1;
170 struct font_list *fonts = NULL;
174 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + \
175 fonts[selected_font].xftfont->descent) \
176 : (fonts[selected_font].font->max_bounds.ascent + \
177 fonts[selected_font].font->max_bounds.descent))
178 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent \
179 : fonts[selected_font].font->max_bounds.ascent)
180 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent \
181 : fonts[selected_font].font->max_bounds.descent)
185 #define font_height() (fonts[selected_font].font->max_bounds.ascent + \
186 fonts[selected_font].font->max_bounds.descent)
187 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
188 #define font_descent() fonts[selected_font].font->max_bounds.descent
192 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
194 static void set_font(void);
196 int addfont(const char *data_in)
198 if (font_count > MAX_FONTS) {
199 CRIT_ERR("you don't need that many fonts, sorry.");
202 if (font_count == 0) {
206 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
210 memset(fonts, 0, sizeof(struct font_list));
212 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
213 memset(&fonts[font_count], 0, sizeof(struct font_list));
215 CRIT_ERR("realloc in addfont");
217 // must account for null terminator
218 if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
219 strncpy(fonts[font_count].name, data_in, text_buffer_size);
221 fonts[font_count].font_alpha = 0xffff;
224 CRIT_ERR("Oops...looks like something overflowed in addfont().");
229 void set_first_font(const char *data_in)
231 if (font_count < 0) {
232 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
236 memset(fonts, 0, sizeof(struct font_list));
239 if (strlen(data_in) > 1) {
240 strncpy(fonts[0].name, data_in, text_buffer_size);
242 fonts[0].font_alpha = 0xffff;
247 void free_fonts(void)
251 for (i = 0; i <= font_count; i++) {
254 XftFontClose(display, fonts[i].xftfont);
255 fonts[i].xftfont = 0;
259 XFreeFont(display, fonts[i].font);
269 static void load_fonts(void)
273 for (i = 0; i <= font_count; i++) {
276 if (use_xft && fonts[i].xftfont) {
278 } else if (use_xft) {
279 /* if (fonts[i].xftfont != NULL && selected_font == 0) {
280 XftFontClose(display, fonts[i].xftfont);
282 fonts[i].xftfont = XftFontOpenName(display, screen,
284 if (fonts[i].xftfont != NULL) {
288 ERR("can't load Xft font '%s'", fonts[i].name);
289 if ((fonts[i].xftfont = XftFontOpenName(display, screen,
290 "courier-12")) != NULL) {
294 ERR("can't load Xft font '%s'", "courier-12");
296 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
297 CRIT_ERR("can't load font '%s'", "fixed");
304 /* load normal font */
305 /* if (fonts[i].font != NULL) {
306 XFreeFont(display, fonts[i].font);
309 if (fonts[i].font || (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
310 ERR("can't load font '%s'", fonts[i].name);
311 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
312 CRIT_ERR("can't load font '%s'", "fixed");
313 printf("loaded fixed?\n");
321 /* default config file */
322 static char *current_config;
324 /* set to 1 if you want all text to be in uppercase */
325 static unsigned int stuff_in_upper_case;
327 /* Run how many times? */
328 static unsigned long total_run_times;
331 static int fork_to_background;
333 static int cpu_avg_samples, net_avg_samples;
337 /* Position on the screen */
338 static int text_alignment;
339 static int gap_x, gap_y;
342 static int draw_borders;
343 static int draw_graph_borders;
344 static int stippled_borders;
346 static int draw_shades, draw_outline;
348 static int border_margin, border_width;
350 static long default_fg_color, default_bg_color, default_out_color;
352 /* create own window or draw stuff to root? */
353 static int set_transparent = 0;
356 static int own_window = 0;
357 static int background_colour = 0;
359 /* fixed size/pos is set if wm/user changes them */
360 static int fixed_size = 0, fixed_pos = 0;
363 static int minimum_width, minimum_height;
364 static int maximum_width;
369 static int sensor_device;
372 static long color0, color1, color2, color3, color4, color5, color6, color7,
375 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
376 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
378 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
379 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
381 /* maximum size of individual text buffers, ie $exec buffer size */
382 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
385 #define CODEPAGE_LENGTH 20
387 long iconv_count = 0;
388 char iconv_converting;
389 static iconv_t **iconv_cd = 0;
391 int register_iconv(iconv_t *new_iconv)
393 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
395 CRIT_ERR("Out of memory");
397 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
398 if (!iconv_cd[iconv_count]) {
399 CRIT_ERR("Out of memory");
401 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
406 void free_iconv(void)
411 for (i = 0; i < iconv_count; i++) {
413 iconv_close(*iconv_cd[i]);
427 /* no buffers in used memory? */
430 /* pad percentages to decimals? */
431 static int pad_percents = 0;
433 #ifdef TCP_PORT_MONITOR
434 tcp_port_monitor_args_t tcp_port_monitor_args;
437 static char *text = 0;
440 static int total_updates;
443 static int blockdepth = 0;
444 static int if_jumped = 0;
445 static int blockstart[MAX_IF_BLOCK_DEPTH];
447 int check_contains(char *f, char *s)
450 FILE *where = fopen(f, "r");
453 char buf1[256], buf2[256];
455 while (fgets(buf1, 256, where)) {
456 sscanf(buf1, "%255s", buf2);
457 if (strstr(buf2, s)) {
464 ERR("Could not open the file");
470 static inline int calc_text_width(const char *s, int l)
477 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
478 (const FcChar8 *) s, l, &gi);
480 XftTextExtents8(display, fonts[selected_font].xftfont,
481 (const FcChar8 *) s, l, &gi);
487 return XTextWidth(fonts[selected_font].font, s, l);
492 /* formatted text to render on screen, generated in generate_text(),
493 * drawn in draw_stuff() */
495 static char *text_buffer;
497 /* special stuff in text_buffer */
499 #define SPECIAL_CHAR '\x01'
527 unsigned long first_colour; // for graph gradient
528 unsigned long last_colour;
532 /* create specials array on heap instead of stack with introduction of
534 static struct special_t *specials = NULL;
536 static unsigned int special_count;
539 static unsigned int special_index; /* used when drawing */
542 /* why 256? cause an array of more then 256 doubles seems excessive,
543 * and who needs that kind of precision anyway? */
544 #define MAX_GRAPH_DEPTH 256
546 static struct special_t *new_special(char *buf, enum special_types t)
548 if (special_count >= max_specials) {
549 CRIT_ERR("too many special things in text");
552 buf[0] = SPECIAL_CHAR;
554 specials[special_count].type = t;
555 return &specials[special_count++];
558 long fwd_fcharfind(FILE *fp, char val, unsigned int step)
562 unsigned int count = 0;
563 static char buf[BUFSZ];
564 long orig_pos = ftell(fp);
566 long buf_size = BUFSZ;
567 char *cur_found = NULL;
569 while (count < step) {
570 if (cur_found == NULL) {
571 buf_size = fread(buf, 1, buf_size, fp);
574 cur_found = memchr(buf + buf_pos, val, buf_size - buf_pos);
575 if (cur_found != NULL) {
576 buf_pos = cur_found - buf + 1;
585 ret = ftell(fp) - buf_size + buf_pos - 1;
587 fseek(fp, orig_pos, SEEK_SET);
593 void *memrchr(const void *buffer, char c, size_t n)
595 const unsigned char *p = buffer;
597 for (p += n; n; n--) {
606 long rev_fcharfind(FILE *fp, char val, unsigned int step)
610 unsigned int count = 0;
611 static char buf[BUFSZ];
612 long orig_pos = ftell(fp);
614 long file_pos = orig_pos;
615 long buf_size = BUFSZ;
618 while (count < step) {
620 if (file_pos > BUFSZ) {
621 fseek(fp, file_pos - BUFSZ, SEEK_SET);
624 fseek(fp, 0, SEEK_SET);
626 file_pos = ftell(fp);
627 buf_pos = fread(buf, 1, buf_size, fp);
629 cur_found = memrchr(buf, val, (size_t) buf_pos);
630 if (cur_found != NULL) {
631 buf_pos = cur_found - buf;
640 fseek(fp, orig_pos, SEEK_SET);
642 ret = file_pos + buf_pos;
648 static void new_bar(char *buf, int w, int h, int usage)
650 struct special_t *s = new_special(buf, BAR);
652 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
657 static const char *scan_bar(const char *args, int *w, int *h)
659 /* zero width means all space that is available */
662 /* bar's argument is either height or height,width */
666 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) {
667 sscanf(args, "%d %n", h, &n);
675 static char *scan_font(const char *args)
678 return strndup(args, text_buffer_size);
685 static void new_font(char *buf, char *args)
688 struct special_t *s = new_special(buf, FONT);
690 if (s->font_added > font_count || !s->font_added || strncmp(args, fonts[s->font_added].name, DEFAULT_TEXT_BUFFER_SIZE)) {
691 int tmp = selected_font;
693 selected_font = s->font_added = addfont(args);
698 struct special_t *s = new_special(buf, FONT);
699 int tmp = selected_font;
701 selected_font = s->font_added = 0;
707 inline void graph_append(struct special_t *graph, double f)
711 if (!graph->scaled && f > graph->graph_scale) {
712 f = graph->graph_scale;
716 graph->graph_scale = 1;
718 graph->graph[0] = f; /* add new data */
719 /* shift all the data by 1 */
720 for (i = graph->graph_width - 1; i > 0; i--) {
721 graph->graph[i] = graph->graph[i - 1];
722 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
723 /* check if we need to update the scale */
724 graph->graph_scale = graph->graph[i];
729 short colour_depth = 0;
730 void set_up_gradient(void);
732 /* precalculated: 31/255, and 63/255 */
733 #define CONST_8_TO_5_BITS 0.12156862745098
734 #define CONST_8_TO_6_BITS 0.247058823529412
736 /* adjust color values depending on color depth */
737 static unsigned int adjust_colors(unsigned int color)
741 if (colour_depth == 0) {
744 if (colour_depth == 16) {
745 r = (color & 0xff0000) >> 16;
746 g = (color & 0xff00) >> 8;
748 color = (int) (r * CONST_8_TO_5_BITS) << 11;
749 color |= (int) (g * CONST_8_TO_6_BITS) << 5;
750 color |= (int) (b * CONST_8_TO_5_BITS);
755 static void new_graph(char *buf, int w, int h, unsigned int first_colour,
756 unsigned int second_colour, double i, int scale, int append)
758 struct special_t *s = new_special(buf, GRAPH);
761 if (s->graph == NULL) {
762 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
763 // subtract 2 for the box
764 s->graph_width = s->width /* - 2 */;
766 s->graph_width = MAX_GRAPH_DEPTH - 2;
768 s->graph = malloc(s->graph_width * sizeof(double));
769 memset(s->graph, 0, s->graph_width * sizeof(double));
770 s->graph_scale = 100;
773 s->first_colour = adjust_colors(first_colour);
774 s->last_colour = adjust_colors(second_colour);
781 s->graph_width = s->width - 2; // subtract 2 for rectangle around
786 s->graph_scale = scale;
793 static char *scan_graph(const char *args, int *w, int *h,
794 unsigned int *first_colour, unsigned int *last_colour,
799 /* zero width means all space that is available */
805 /* graph's argument is either height or height,width */
807 if (sscanf(args, "%d,%d %x %x %u", h, w, first_colour, last_colour,
812 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) {
815 if (sscanf(args, "%63s %d,%d %x %x %u", buf, h, w, first_colour,
816 last_colour, scale) == 6) {
817 return strndup(buf, text_buffer_size);
820 if (sscanf(args, "%63s %d,%d %x %x", buf, h, w, first_colour,
822 return strndup(buf, text_buffer_size);
827 if (sscanf(args, "%x %x %u", first_colour, last_colour, scale) == 3) {
831 if (sscanf(args, "%x %x", first_colour, last_colour) == 2) {
834 if (sscanf(args, "%63s %x %x %u", buf, first_colour, last_colour,
836 return strndup(buf, text_buffer_size);
839 if (sscanf(args, "%63s %x %x", buf, first_colour, last_colour) == 3) {
840 return strndup(buf, text_buffer_size);
845 if (sscanf(args, "%d,%d %u", h, w, scale) == 3) {
849 if (sscanf(args, "%d,%d", h, w) == 2) {
852 if (sscanf(args, "%63s %d,%d %u", buf, h, w, scale) < 4) {
854 //TODO: check the return value and throw an error?
855 sscanf(args, "%63s %d,%d", buf, h, w);
858 return strndup(buf, text_buffer_size);
861 if (buf[0] == '\0') {
864 return strndup(buf, text_buffer_size);
868 static inline void new_hr(char *buf, int a)
870 new_special(buf, HORIZONTAL_LINE)->height = a;
873 static inline void new_stippled_hr(char *buf, int a, int b)
875 struct special_t *s = new_special(buf, STIPPLED_HR);
881 static inline void new_fg(char *buf, long c)
883 new_special(buf, FG)->arg = c;
886 static inline void new_bg(char *buf, long c)
888 new_special(buf, BG)->arg = c;
891 static inline void new_outline(char *buf, long c)
893 new_special(buf, OUTLINE)->arg = c;
896 static inline void new_offset(char *buf, long c)
898 new_special(buf, OFFSET)->arg = c;
901 static inline void new_voffset(char *buf, long c)
903 new_special(buf, VOFFSET)->arg = c;
906 static inline void new_alignr(char *buf, long c)
908 new_special(buf, ALIGNR)->arg = c;
911 static inline void new_alignc(char *buf, long c)
913 new_special(buf, ALIGNC)->arg = c;
916 static inline void new_goto(char *buf, long c)
918 new_special(buf, GOTO)->arg = c;
921 static inline void new_tab(char *buf, int a, int b)
923 struct special_t *s = new_special(buf, TAB);
929 /* quite boring functions */
931 static inline void for_each_line(char *b, void f(char *))
935 for (ps = b, pe = b; *pe; pe++) {
949 static void convert_escapes(char *buf)
951 char *p = buf, *s = buf;
958 } else if (*s == '\\') {
969 /* Prints anything normally printed with snprintf according to the current value
970 * of use_spacer. Actually slightly more flexible than snprintf, as you can
971 * safely specify the destination buffer as one of your inputs. */
972 static int spaced_print(char *, int, const char *, int, const char *, ...)
973 __attribute__((format(printf, 3, 6)));
975 static int spaced_print(char *buf, int size, const char *format, int width,
976 const char *func_name, ...) {
984 tempbuf = malloc(size * sizeof(char));
986 // Passes the varargs along to vsnprintf
987 va_start(argp, func_name);
988 vsnprintf(tempbuf, size, format, argp);
991 switch (use_spacer) {
993 len = snprintf(buf, size, "%s", tempbuf);
996 len = snprintf(buf, size, "%*s", width - 1, tempbuf);
999 len = snprintf(buf, size, "%-*s", width - 1, tempbuf);
1002 CRIT_ERR("%s encountered invalid use_spacer value (%d)", func_name,
1011 /* converts from bytes to human readable format (k, M, G, T) */
1012 static void human_readable(long long num, char *buf, int size, const char *func_name)
1014 const char **suffix = suffixes;
1017 static const int WIDTH = 10, SHORT_WIDTH = 8;
1021 spaced_print(buf, size, "%lld%c", SHORT_WIDTH, func_name, num,
1024 spaced_print(buf, size, "%lld%s", WIDTH, func_name, num, *suffix);
1029 while (num / 1024 >= 1000LL && **(suffix + 2)) {
1035 fnum = num / 1024.0;
1040 if (precision < 0) {
1044 len = spaced_print(buf, size, "%.*f%c", SHORT_WIDTH, func_name,
1045 precision, fnum, **suffix);
1047 len = spaced_print(buf, size, "%.*f%s", WIDTH, func_name, precision,
1050 } while (len >= (short_units ? SHORT_WIDTH : WIDTH) || len >= size);
1055 enum text_object_type {
1057 #if defined(__linux__)
1059 #endif /* __linux__ */
1069 OBJ_battery_percent,
1071 #endif /* !__OpenBSD__ */
1086 OBJ_conky_build_date,
1087 OBJ_conky_build_arch,
1096 OBJ_diskiograph_read,
1097 OBJ_diskiograph_write,
1135 #if defined(__linux__)
1142 OBJ_i8k_left_fan_status,
1143 OBJ_i8k_right_fan_status,
1144 OBJ_i8k_left_fan_rpm,
1145 OBJ_i8k_right_fan_rpm,
1147 OBJ_i8k_buttons_status,
1163 OBJ_wireless_bitrate,
1165 OBJ_wireless_link_qual,
1166 OBJ_wireless_link_qual_max,
1167 OBJ_wireless_link_qual_perc,
1168 OBJ_wireless_link_bar,
1169 #endif /* __linux__ */
1201 OBJ_running_processes,
1210 OBJ_temp1, /* i2c is used instead in these */
1234 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
1235 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1237 OBJ_apm_battery_time,
1238 OBJ_apm_battery_life,
1239 #endif /* __FreeBSD__ __OpenBSD__ */
1241 OBJ_obsd_sensors_temp,
1242 OBJ_obsd_sensors_fan,
1243 OBJ_obsd_sensors_volt,
1246 #endif /* __OpenBSD__ */
1268 OBJ_music_player_interval,
1288 OBJ_xmms2_timesplayed,
1291 OBJ_audacious_status,
1292 OBJ_audacious_title,
1293 OBJ_audacious_length,
1294 OBJ_audacious_length_seconds,
1295 OBJ_audacious_position,
1296 OBJ_audacious_position_seconds,
1297 OBJ_audacious_bitrate,
1298 OBJ_audacious_frequency,
1299 OBJ_audacious_channels,
1300 OBJ_audacious_filename,
1301 OBJ_audacious_playlist_length,
1302 OBJ_audacious_playlist_position,
1316 #ifdef TCP_PORT_MONITOR
1330 OBJ_if_smapi_bat_installed,
1333 OBJ_entropy_poolsize,
1337 struct text_object {
1339 char *s; /* some string */
1340 int i; /* some integer */
1341 long l; /* some other integer */
1342 unsigned int sensor;
1343 struct net_stat *net;
1345 struct diskio_stat *diskio;
1346 unsigned char loadavg[3];
1347 unsigned int cpu_index;
1348 struct mail_s *mail;
1356 char *tz; /* timezone variable */
1357 char *fmt; /* time display formatting */
1395 /* If not -1, a file descriptor to read from when
1396 * logfile is a FIFO. */
1413 timed_thread *p_timed_thread;
1419 #ifdef TCP_PORT_MONITOR
1421 /* starting port to monitor */
1422 in_port_t port_range_begin;
1423 /* ending port to monitor */
1424 in_port_t port_range_end;
1425 /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1427 /* 0 to n-1 connections. */
1428 int connection_index;
1446 struct local_mail_s local_mail;
1451 unsigned int c, d, e;
1456 struct text_object_list {
1457 unsigned int text_object_count;
1458 struct text_object *text_objects;
1461 static unsigned int global_text_object_count;
1462 static struct text_object *global_text_objects;
1463 static void generate_text_internal(char *p, int p_max_size,
1464 struct text_object *objs, unsigned int object_count,
1465 struct information *cur);
1467 #define MAXDATASIZE 1000
1471 struct mail_s *parse_mail_args(char type, const char *arg)
1473 struct mail_s *mail;
1476 mail = malloc(sizeof(struct mail_s));
1477 memset(mail, 0, sizeof(struct mail_s));
1479 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass)
1482 ERR("Scanning IMAP args failed");
1483 } else if (type == IMAP) {
1484 ERR("Scanning POP3 args failed");
1487 // see if password needs prompting
1488 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1489 int fp = fileno(stdin);
1490 struct termios term;
1492 tcgetattr(fp, &term);
1493 term.c_lflag &= ~ECHO;
1494 tcsetattr(fp, TCSANOW, &term);
1495 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1496 scanf("%128s", mail->pass);
1498 term.c_lflag |= ECHO;
1499 tcsetattr(fp, TCSANOW, &term);
1501 // now we check for optional args
1502 tmp = strstr(arg, "-i ");
1505 sscanf(tmp, "%f", &mail->interval);
1507 mail->interval = 300; // 5 minutes
1509 tmp = strstr(arg, "-p ");
1512 sscanf(tmp, "%lu", &mail->port);
1515 mail->port = 110; // default pop3 port
1516 } else if (type == IMAP) {
1517 mail->port = 143; // default imap port
1521 tmp = strstr(arg, "-f ");
1524 sscanf(tmp, "%s", mail->folder);
1526 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1529 tmp = strstr(arg, "-e ");
1534 if (tmp[0] == '\'') {
1535 len = strstr(tmp + 1, "'") - tmp - 1;
1540 strncpy(mail->command, tmp + 1, len);
1542 mail->command[0] = '\0';
1544 mail->p_timed_thread = NULL;
1548 void *imap_thread(void *arg)
1550 int sockfd, numbytes;
1551 char recvbuf[MAXDATASIZE];
1552 char sendbuf[MAXDATASIZE];
1555 unsigned int old_unseen = UINT_MAX;
1556 unsigned int old_messages = UINT_MAX;
1557 struct stat stat_buf;
1558 struct hostent he, *he_res = 0;
1560 char hostbuff[2048];
1561 struct sockaddr_in their_addr; // connector's address information
1562 struct mail_s *mail = (struct mail_s *)arg;
1564 #ifdef HAVE_GETHOSTBYNAME_R
1565 if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
1566 ERR("IMAP gethostbyname_r: %s", hstrerror(h_errno));
1569 #else /* HAVE_GETHOSTBYNAME_R */
1570 if ((he_res = gethostbyname(mail->host)) == NULL) { // get the host info
1571 herror("gethostbyname");
1574 #endif /* HAVE_GETHOSTBYNAME_R */
1576 struct timeval timeout;
1581 ERR("Trying IMAP connection again for %s@%s (try %i/5)",
1582 mail->user, mail->host, fail + 1);
1585 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1592 their_addr.sin_family = AF_INET;
1593 // short, network byte order
1594 their_addr.sin_port = htons(mail->port);
1595 their_addr.sin_addr = *((struct in_addr *) he_res->h_addr);
1596 // zero the rest of the struct
1597 memset(&(their_addr.sin_zero), '\0', 8);
1599 if (connect(sockfd, (struct sockaddr *) &their_addr,
1600 sizeof(struct sockaddr)) == -1) {
1606 timeout.tv_sec = 60; // 60 second timeout i guess
1607 timeout.tv_usec = 0;
1609 FD_SET(sockfd, &fdset);
1610 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1612 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1618 ERR("IMAP connection failed: timeout");
1622 recvbuf[numbytes] = '\0';
1623 if (strstr(recvbuf, "* OK") != recvbuf) {
1624 ERR("IMAP connection failed, probably not an IMAP server");
1628 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1629 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1630 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1631 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1632 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1633 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1638 timeout.tv_sec = 60; // 60 second timeout i guess
1639 timeout.tv_usec = 0;
1641 FD_SET(sockfd, &fdset);
1642 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1644 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1650 recvbuf[numbytes] = '\0';
1651 if (strstr(recvbuf, "a1 OK") == NULL) {
1652 ERR("IMAP server login failed: %s", recvbuf);
1656 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1657 strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1);
1658 strncat(sendbuf, " (MESSAGES UNSEEN)\r\n",
1659 MAXDATASIZE - strlen(sendbuf) - 1);
1660 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1665 timeout.tv_sec = 60; // 60 second timeout i guess
1666 timeout.tv_usec = 0;
1668 FD_SET(sockfd, &fdset);
1669 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1671 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1677 recvbuf[numbytes] = '\0';
1678 if (strstr(recvbuf, "a2 OK") == NULL) {
1679 ERR("IMAP status failed: %s", recvbuf);
1683 // now we get the data
1684 reply = strstr(recvbuf, " (MESSAGES ");
1686 *strchr(reply, ')') = '\0';
1687 if (reply == NULL) {
1688 ERR("Error parsing IMAP response: %s", recvbuf);
1692 timed_thread_lock(mail->p_timed_thread);
1693 sscanf(reply, "MESSAGES %lu UNSEEN %lu", &mail->messages,
1695 timed_thread_unlock(mail->p_timed_thread);
1697 strncpy(sendbuf, "a3 logout\r\n", MAXDATASIZE);
1698 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1703 timeout.tv_sec = 60; // 60 second timeout i guess
1704 timeout.tv_usec = 0;
1706 FD_SET(sockfd, &fdset);
1707 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1709 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1715 recvbuf[numbytes] = '\0';
1716 if (strstr(recvbuf, "a3 OK") == NULL) {
1717 ERR("IMAP logout failed: %s", recvbuf);
1721 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen
1722 || (mail->messages > old_messages && mail->unseen > 0))) {
1724 if (system(mail->command) == -1) {
1729 old_unseen = mail->unseen;
1730 old_messages = mail->messages;
1732 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1733 /* if a valid socket, close it */
1736 if (timed_thread_test(mail->p_timed_thread)) {
1737 timed_thread_exit(mail->p_timed_thread);
1745 void *pop3_thread(void *arg)
1747 int sockfd, numbytes;
1748 char recvbuf[MAXDATASIZE];
1749 char sendbuf[MAXDATASIZE];
1752 unsigned int old_unseen = UINT_MAX;
1753 struct stat stat_buf;
1754 struct hostent he, *he_res = 0;
1756 char hostbuff[2048];
1757 struct sockaddr_in their_addr; // connector's address information
1758 struct mail_s *mail = (struct mail_s *)arg;
1760 #ifdef HAVE_GETHOSTBYNAME_R
1761 if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
1762 ERR("POP3 gethostbyname_r: %s", hstrerror(h_errno));
1765 #else /* HAVE_GETHOSTBYNAME_R */
1766 if ((he_res = gethostbyname(mail->host)) == NULL) { // get the host info
1767 herror("gethostbyname");
1770 #endif /* HAVE_GETHOSTBYNAME_R */
1772 struct timeval timeout;
1777 ERR("Trying POP3 connection again for %s@%s (try %i/5)",
1778 mail->user, mail->host, fail + 1);
1781 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1788 their_addr.sin_family = AF_INET;
1789 // short, network byte order
1790 their_addr.sin_port = htons(mail->port);
1791 their_addr.sin_addr = *((struct in_addr *) he_res->h_addr);
1792 // zero the rest of the struct
1793 memset(&(their_addr.sin_zero), '\0', 8);
1795 if (connect(sockfd, (struct sockaddr *) &their_addr,
1796 sizeof(struct sockaddr)) == -1) {
1802 timeout.tv_sec = 60; // 60 second timeout i guess
1803 timeout.tv_usec = 0;
1805 FD_SET(sockfd, &fdset);
1806 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1808 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1814 ERR("POP3 connection failed: timeout\n");
1818 recvbuf[numbytes] = '\0';
1819 if (strstr(recvbuf, "+OK ") != recvbuf) {
1820 ERR("POP3 connection failed, probably not a POP3 server");
1824 strncpy(sendbuf, "USER ", MAXDATASIZE);
1825 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1826 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1827 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1828 perror("send USER");
1832 timeout.tv_sec = 60; // 60 second timeout i guess
1833 timeout.tv_usec = 0;
1835 FD_SET(sockfd, &fdset);
1836 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1838 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1839 perror("recv USER");
1844 recvbuf[numbytes] = '\0';
1845 if (strstr(recvbuf, "+OK ") == NULL) {
1846 ERR("POP3 server login failed: %s", recvbuf);
1850 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1851 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1852 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1853 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1854 perror("send PASS");
1858 timeout.tv_sec = 60; // 60 second timeout i guess
1859 timeout.tv_usec = 0;
1861 FD_SET(sockfd, &fdset);
1862 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1864 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1865 perror("recv PASS");
1870 recvbuf[numbytes] = '\0';
1871 if (strstr(recvbuf, "+OK ") == NULL) {
1872 ERR("POP3 server login failed: %s", recvbuf);
1876 strncpy(sendbuf, "STAT\r\n", MAXDATASIZE);
1877 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1878 perror("send STAT");
1882 timeout.tv_sec = 60; // 60 second timeout i guess
1883 timeout.tv_usec = 0;
1885 FD_SET(sockfd, &fdset);
1886 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1888 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1889 perror("recv STAT");
1894 recvbuf[numbytes] = '\0';
1895 if (strstr(recvbuf, "+OK ") == NULL) {
1896 ERR("POP3 status failed: %s", recvbuf);
1900 // now we get the data
1901 reply = recvbuf + 4;
1902 if (reply == NULL) {
1903 ERR("Error parsing POP3 response: %s", recvbuf);
1907 timed_thread_lock(mail->p_timed_thread);
1908 sscanf(reply, "%lu %lu", &mail->unseen, &mail->used);
1909 timed_thread_unlock(mail->p_timed_thread);
1911 strncpy(sendbuf, "QUIT\r\n", MAXDATASIZE);
1912 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1913 perror("send QUIT");
1917 timeout.tv_sec = 60; // 60 second timeout i guess
1918 timeout.tv_usec = 0;
1920 FD_SET(sockfd, &fdset);
1921 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1923 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1924 perror("recv QUIT");
1929 recvbuf[numbytes] = '\0';
1930 if (strstr(recvbuf, "+OK") == NULL) {
1931 ERR("POP3 logout failed: %s", recvbuf);
1935 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) {
1937 if (system(mail->command) == -1) {
1942 old_unseen = mail->unseen;
1944 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1945 /* if a valid socket, close it */
1948 if (timed_thread_test(mail->p_timed_thread)) {
1949 timed_thread_exit(mail->p_timed_thread);
1957 void *threaded_exec(void *) __attribute__((noreturn));
1959 void *threaded_exec(void *arg)
1964 struct text_object *obj = (struct text_object *)arg;
1966 p2 = obj->data.texeci.buffer;
1967 fp = popen(obj->data.texeci.cmd, "r");
1969 timed_thread_lock(obj->data.texeci.p_timed_thread);
1970 n2 = fread(p2, 1, text_buffer_size, fp);
1974 if (n2 && p2[n2 - 1] == '\n') {
1978 if (*p2 == '\001') {
1983 timed_thread_unlock(obj->data.texeci.p_timed_thread);
1984 if (timed_thread_test(obj->data.texeci.p_timed_thread)) {
1985 timed_thread_exit(obj->data.texeci.p_timed_thread);
1991 static struct text_object *new_text_object_internal(void)
1993 struct text_object *obj = malloc(sizeof(struct text_object));
1994 memset(obj, 0, sizeof(struct text_object));
1998 static void free_text_objects(unsigned int count, struct text_object *objs)
2002 for (i = 0; i < count; i++) {
2003 switch (objs[i].type) {
2007 close(objs[i].data.i);
2012 close(objs[i].data.sysfs.fd);
2014 #endif /* !__OpenBSD__ */
2017 free(objs[i].data.s);
2020 free(objs[i].data.tztime.tz);
2021 free(objs[i].data.tztime.fmt);
2024 free(objs[i].data.mboxscan.args);
2025 free(objs[i].data.mboxscan.output);
2029 free(objs[i].data.local_mail.box);
2034 case OBJ_imap_unseen:
2035 if (!objs[i].global_mode) {
2036 free(objs[i].data.mail);
2039 case OBJ_imap_messages:
2040 if (!objs[i].global_mode) {
2041 free(objs[i].data.mail);
2047 case OBJ_pop3_unseen:
2048 if (!objs[i].global_mode) {
2049 free(objs[i].data.mail);
2053 if (!objs[i].global_mode) {
2054 free(objs[i].data.mail);
2058 case OBJ_if_existing:
2059 case OBJ_if_mounted:
2060 case OBJ_if_running:
2061 free(objs[i].data.ifblock.s);
2062 free(objs[i].data.ifblock.str);
2065 free(objs[i].data.tail.logfile);
2066 free(objs[i].data.tail.buffer);
2075 free(objs[i].data.s);
2078 case OBJ_iconv_start:
2083 case OBJ_disk_protect:
2084 free(objs[i].data.s);
2087 free(objs[i].data.ifblock.s);
2088 free(objs[i].data.ifblock.str);
2091 free(objs[i].data.ifblock.s);
2092 free(objs[i].data.ifblock.str);
2095 if (info.gw_info.iface) {
2096 free(info.gw_info.iface);
2097 info.gw_info.iface = 0;
2099 if (info.gw_info.ip) {
2100 free(info.gw_info.ip);
2101 info.gw_info.ip = 0;
2104 case OBJ_ioscheduler:
2106 free(objs[i].data.s);
2110 case OBJ_xmms2_artist:
2111 if (info.xmms2.artist) {
2112 free(info.xmms2.artist);
2113 info.xmms2.artist = 0;
2116 case OBJ_xmms2_album:
2117 if (info.xmms2.album) {
2118 free(info.xmms2.album);
2119 info.xmms2.album = 0;
2122 case OBJ_xmms2_title:
2123 if (info.xmms2.title) {
2124 free(info.xmms2.title);
2125 info.xmms2.title = 0;
2128 case OBJ_xmms2_genre:
2129 if (info.xmms2.genre) {
2130 free(info.xmms2.genre);
2131 info.xmms2.genre = 0;
2134 case OBJ_xmms2_comment:
2135 if (info.xmms2.comment) {
2136 free(info.xmms2.comment);
2137 info.xmms2.comment = 0;
2141 if (info.xmms2.url) {
2142 free(info.xmms2.url);
2146 case OBJ_xmms2_date:
2147 if (info.xmms2.date) {
2148 free(info.xmms2.date);
2149 info.xmms2.date = 0;
2152 case OBJ_xmms2_status:
2153 if (info.xmms2.status) {
2154 free(info.xmms2.status);
2155 info.xmms2.status = 0;
2158 case OBJ_xmms2_playlist:
2159 if (info.xmms2.playlist) {
2160 free(info.xmms2.playlist);
2161 info.xmms2.playlist = 0;
2164 case OBJ_xmms2_smart:
2165 if (info.xmms2.artist) {
2166 free(info.xmms2.artist);
2167 info.xmms2.artist = 0;
2169 if (info.xmms2.title) {
2170 free(info.xmms2.title);
2171 info.xmms2.title = 0;
2173 if (info.xmms2.url) {
2174 free(info.xmms2.url);
2180 case OBJ_bmpx_title:
2181 case OBJ_bmpx_artist:
2182 case OBJ_bmpx_album:
2183 case OBJ_bmpx_track:
2185 case OBJ_bmpx_bitrate:
2190 free(objs[i].data.rss.uri);
2191 free(objs[i].data.rss.action);
2198 free(objs[i].data.s);
2200 case OBJ_battery_time:
2201 free(objs[i].data.s);
2203 #endif /* !__OpenBSD__ */
2207 case OBJ_execigraph:
2208 free(objs[i].data.execi.cmd);
2209 free(objs[i].data.execi.buffer);
2212 free(objs[i].data.texeci.cmd);
2213 free(objs[i].data.texeci.buffer);
2215 case OBJ_nameserver:
2220 if (info.first_process) {
2221 free_all_processes();
2222 info.first_process = NULL;
2227 free(objs[i].data.hddtemp.dev);
2228 free(objs[i].data.hddtemp.addr);
2231 case OBJ_entropy_avail:
2232 case OBJ_entropy_poolsize:
2233 case OBJ_entropy_bar:
2235 case OBJ_user_names:
2236 if (info.users.names) {
2237 free(info.users.names);
2238 info.users.names = 0;
2241 case OBJ_user_terms:
2242 if (info.users.terms) {
2243 free(info.users.terms);
2244 info.users.terms = 0;
2247 case OBJ_user_times:
2248 if (info.users.times) {
2249 free(info.users.times);
2250 info.users.times = 0;
2255 case OBJ_smapi_bat_perc:
2256 free(objs[i].data.s);
2258 case OBJ_if_smapi_bat_installed:
2259 free(objs[i].data.ifblock.s);
2260 free(objs[i].data.ifblock.str);
2265 case OBJ_mpd_artist:
2267 case OBJ_mpd_random:
2268 case OBJ_mpd_repeat:
2270 case OBJ_mpd_bitrate:
2271 case OBJ_mpd_status:
2274 case OBJ_mpd_password:
2276 case OBJ_mpd_elapsed:
2277 case OBJ_mpd_length:
2281 case OBJ_mpd_percent:
2283 free_mpd_vars(&info);
2289 /* text_objects = NULL;
2290 text_object_count = 0; */
2293 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2298 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2299 *a = mixer_init(buf1);
2300 scan_bar(arg + n, w, h);
2302 *a = mixer_init(NULL);
2303 scan_bar(arg, w, h);
2307 /* strip a leading /dev/ if any */
2308 #define DEV_NAME(x) strncmp(x, "/dev/", 5) ? x : x + 5
2310 /* construct_text_object() creates a new text_object */
2311 static struct text_object *construct_text_object(const char *s,
2312 const char *arg, unsigned int object_count,
2313 struct text_object *text_objects, long line)
2315 // struct text_object *obj = new_text_object();
2316 struct text_object *obj = new_text_object_internal();
2320 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
2321 obj->type = OBJ_##a; need_mask |= (1 << n); {
2322 #define END } } else
2326 obj->type = OBJ_color;
2327 obj->data.l = get_x11_color(s);
2331 OBJ(freq, INFO_FREQ)
2334 obj->data.i = open_acpi_temperature(arg);
2335 END OBJ(acpitempf, 0)
2336 obj->data.i = open_acpi_temperature(arg);
2337 END OBJ(acpiacadapter, 0)
2338 END OBJ(freq, INFO_FREQ)
2339 #endif /* !__OpenBSD__ */
2341 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2342 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2343 obj->data.cpu_index = 1;
2344 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
2345 "Displaying the clock for CPU 1."); */
2347 obj->data.cpu_index = atoi(&arg[0]);
2350 END OBJ(freq_g, INFO_FREQ)
2352 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2353 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2354 obj->data.cpu_index = 1;
2355 /* ERR("freq_g: Invalid CPU number or you don't have that many "
2356 "CPUs! Displaying the clock for CPU 1."); */
2358 obj->data.cpu_index = atoi(&arg[0]);
2361 #if defined(__linux__)
2362 END OBJ(voltage_mv, 0)
2364 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2365 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2366 obj->data.cpu_index = 1;
2367 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
2368 "CPUs! Displaying voltage for CPU 1."); */
2370 obj->data.cpu_index = atoi(&arg[0]);
2373 END OBJ(voltage_v, 0)
2375 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2376 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2377 obj->data.cpu_index = 1;
2378 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
2379 "CPUs! Displaying voltage for CPU 1."); */
2381 obj->data.cpu_index = atoi(&arg[0]);
2386 END OBJ(wireless_essid, INFO_NET)
2388 obj->data.net = get_net_stat(arg);
2390 CRIT_ERR("wireless_essid: needs an argument");
2392 END OBJ(wireless_mode, INFO_NET)
2394 obj->data.net = get_net_stat(arg);
2396 CRIT_ERR("wireless_mode: needs an argument");
2398 END OBJ(wireless_bitrate, INFO_NET)
2400 obj->data.net = get_net_stat(arg);
2402 CRIT_ERR("wireless_bitrate: needs an argument");
2404 END OBJ(wireless_ap, INFO_NET)
2406 obj->data.net = get_net_stat(arg);
2408 CRIT_ERR("wireless_ap: needs an argument");
2410 END OBJ(wireless_link_qual, INFO_NET)
2412 obj->data.net = get_net_stat(arg);
2414 CRIT_ERR("wireless_link_qual: needs an argument");
2416 END OBJ(wireless_link_qual_max, INFO_NET)
2418 obj->data.net = get_net_stat(arg);
2420 CRIT_ERR("wireless_link_qual_max: needs an argument");
2422 END OBJ(wireless_link_qual_perc, INFO_NET)
2424 obj->data.net = get_net_stat(arg);
2426 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2428 END OBJ(wireless_link_bar, INFO_NET)
2430 arg = scan_bar(arg, &obj->a, &obj->b);
2431 obj->data.net = get_net_stat(arg);
2433 CRIT_ERR("wireless_link_bar: needs an argument");
2435 #endif /* HAVE_IWLIB */
2437 #endif /* __linux__ */
2438 END OBJ(freq_dyn, 0)
2439 END OBJ(freq_dyn_g, 0)
2447 sscanf(arg, "%63s", bat);
2449 strcpy(bat, "BAT0");
2451 obj->data.s = strndup(bat, text_buffer_size);
2452 END OBJ(battery_time, 0)
2456 sscanf(arg, "%63s", bat);
2458 strcpy(bat, "BAT0");
2460 obj->data.s = strndup(bat, text_buffer_size);
2461 END OBJ(battery_percent, 0)
2465 sscanf(arg, "%63s", bat);
2467 strcpy(bat, "BAT0");
2469 obj->data.s = strndup(bat, text_buffer_size);
2470 END OBJ(battery_bar, 0)
2474 arg = scan_bar(arg, &obj->a, &obj->b);
2475 sscanf(arg, "%63s", bat);
2477 strcpy(bat, "BAT0");
2479 obj->data.s = strndup(bat, text_buffer_size);
2480 #endif /* !__OpenBSD__ */
2482 #if defined(__linux__)
2483 END OBJ(disk_protect, 0)
2485 obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
2487 CRIT_ERR("disk_protect needs an argument");
2488 END OBJ(i8k_version, INFO_I8K)
2489 END OBJ(i8k_bios, INFO_I8K)
2490 END OBJ(i8k_serial, INFO_I8K)
2491 END OBJ(i8k_cpu_temp, INFO_I8K)
2492 END OBJ(i8k_cpu_tempf, INFO_I8K)
2493 END OBJ(i8k_left_fan_status, INFO_I8K)
2494 END OBJ(i8k_right_fan_status, INFO_I8K)
2495 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2496 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2497 END OBJ(i8k_ac_status, INFO_I8K)
2498 END OBJ(i8k_buttons_status, INFO_I8K)
2500 END OBJ(ibm_temps, 0)
2502 CRIT_ERR("ibm_temps: needs an argument");
2504 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
2505 obj->data.sensor = 0;
2506 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
2507 "Using 0 (CPU temp sensor).");
2509 obj->data.sensor = atoi(&arg[0]);
2510 END OBJ(ibm_volume, 0)
2511 END OBJ(ibm_brightness, 0)
2513 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2514 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2517 ERR("if_up needs an argument");
2518 obj->data.ifblock.s = 0;
2520 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2521 blockstart[blockdepth] = object_count;
2522 obj->data.ifblock.pos = object_count + 2;
2525 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2526 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2528 blockstart[blockdepth] = object_count;
2529 obj->data.ifblock.pos = object_count + 2;
2531 END OBJ(ioscheduler, 0)
2533 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
2536 obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
2537 END OBJ(laptop_mode, 0)
2538 END OBJ(pb_battery, 0)
2539 if (arg && strcmp(arg, "status") == 0) {
2540 obj->data.i = PB_BATT_STATUS;
2541 } else if (arg && strcmp(arg, "percent") == 0) {
2542 obj->data.i = PB_BATT_PERCENT;
2543 } else if (arg && strcmp(arg, "time") == 0) {
2544 obj->data.i = PB_BATT_TIME;
2546 ERR("pb_battery: needs one argument: status, percent or time");
2551 #endif /* __linux__ */
2552 #if defined(__OpenBSD__)
2553 END OBJ(obsd_sensors_temp, 0)
2555 CRIT_ERR("obsd_sensors_temp: needs an argument");
2557 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2558 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2559 obj->data.sensor = 0;
2560 ERR("Invalid temperature sensor number!");
2562 obj->data.sensor = atoi(&arg[0]);
2563 END OBJ(obsd_sensors_fan, 0)
2565 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
2568 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2569 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2570 obj->data.sensor = 0;
2571 ERR("Invalid fan sensor number!");
2573 obj->data.sensor = atoi(&arg[0]);
2574 END OBJ(obsd_sensors_volt, 0)
2576 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
2579 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2580 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2581 obj->data.sensor = 0;
2582 ERR("Invalid voltage sensor number!");
2584 obj->data.sensor = atoi(&arg[0]);
2585 END OBJ(obsd_vendor, 0)
2586 END OBJ(obsd_product, 0)
2587 #endif /* __OpenBSD__ */
2588 END OBJ(buffers, INFO_BUFFERS)
2589 END OBJ(cached, INFO_BUFFERS)
2590 END OBJ(cpu, INFO_CPU)
2592 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2593 obj->data.cpu_index = atoi(&arg[3]);
2596 obj->data.cpu_index = 0;
2599 obj->data.cpu_index = 0;
2601 END OBJ(cpubar, INFO_CPU)
2603 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2604 obj->data.cpu_index = atoi(&arg[3]);
2607 obj->data.cpu_index = 0;
2609 scan_bar(arg, &obj->a, &obj->b);
2611 scan_bar(arg, &obj->a, &obj->b);
2612 obj->data.cpu_index = 0;
2614 END OBJ(cpugraph, INFO_CPU)
2615 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2619 if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
2620 obj->data.cpu_index = atoi(&buf[3]);
2622 obj->data.cpu_index = 0;
2626 END OBJ(diskio, INFO_DISKIO)
2628 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2630 obj->data.diskio = NULL;
2632 END OBJ(diskio_read, INFO_DISKIO)
2634 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2636 obj->data.diskio = NULL;
2638 END OBJ(diskio_write, INFO_DISKIO)
2640 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2642 obj->data.diskio = NULL;
2644 END OBJ(diskiograph, INFO_DISKIO)
2645 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2649 obj->data.diskio = prepare_diskio_stat(buf);
2652 obj->data.diskio = NULL;
2654 END OBJ(diskiograph_read, INFO_DISKIO)
2655 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2659 obj->data.diskio = prepare_diskio_stat(buf);
2662 obj->data.diskio = NULL;
2664 END OBJ(diskiograph_write, INFO_DISKIO)
2665 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2669 obj->data.diskio = prepare_diskio_stat(buf);
2672 obj->data.diskio = NULL;
2676 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2679 obj->data.l = color0;
2681 obj->data.l = color1;
2683 obj->data.l = color2;
2685 obj->data.l = color3;
2687 obj->data.l = color4;
2689 obj->data.l = color5;
2691 obj->data.l = color6;
2693 obj->data.l = color7;
2695 obj->data.l = color8;
2697 obj->data.l = color9;
2699 obj->data.s = scan_font(arg);
2700 END OBJ(conky_version, 0)
2701 END OBJ(conky_build_date, 0)
2702 END OBJ(conky_build_arch, 0)
2703 END OBJ(downspeed, INFO_NET)
2705 obj->data.net = get_net_stat(arg);
2707 CRIT_ERR("downspeed needs argument");
2709 END OBJ(downspeedf, INFO_NET)
2711 obj->data.net = get_net_stat(arg);
2713 CRIT_ERR("downspeedf needs argument");
2715 END OBJ(downspeedgraph, INFO_NET)
2716 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2720 obj->data.net = get_net_stat(buf);
2725 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos =
2727 blockstart[blockdepth - 1] = object_count;
2728 obj->data.ifblock.pos = object_count + 2;
2730 ERR("$else: no matching $if_*");
2735 text_objects[blockstart[blockdepth]].data.ifblock.pos =
2738 ERR("$endif: no matching $if_*");
2741 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2744 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2746 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2748 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2749 END OBJ(execgraph, 0)
2750 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2751 END OBJ(execibar, 0)
2754 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2757 ERR("${execibar <interval> command}");
2758 obj->type = OBJ_text;
2759 snprintf(buf, 256, "${%s}", s);
2760 obj->data.s = strndup(buf, text_buffer_size);
2762 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2764 END OBJ(execigraph, 0)
2767 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2770 ERR("${execigraph <interval> command}");
2771 obj->type = OBJ_text;
2772 snprintf(buf, 256, "${%s}", s);
2773 obj->data.s = strndup(buf, text_buffer_size);
2775 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2780 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2783 ERR("${execi <interval> command}");
2784 obj->type = OBJ_text;
2785 snprintf(buf, 256, "${%s}", s);
2786 obj->data.s = strndup(buf, text_buffer_size);
2788 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2789 obj->data.execi.buffer = malloc(text_buffer_size);
2794 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2797 ERR("${execi <interval> command}");
2798 obj->type = OBJ_text;
2799 snprintf(buf, 256, "${%s}", s);
2800 obj->data.s = strndup(buf, text_buffer_size);
2802 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2803 obj->data.execi.buffer = malloc(text_buffer_size);
2808 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2811 ERR("${texeci <interval> command}");
2812 obj->type = OBJ_text;
2813 snprintf(buf, 256, "${%s}", s);
2814 obj->data.s = strndup(buf, text_buffer_size);
2816 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
2817 obj->data.texeci.buffer = malloc(text_buffer_size);
2819 obj->data.texeci.p_timed_thread = NULL;
2820 END OBJ(pre_exec, 0)
2821 obj->type = OBJ_text;
2823 FILE *fp = popen(arg, "r");
2827 n = fread(buf, 1, 2048, fp);
2830 if (n && buf[n - 1] == '\n') {
2836 obj->data.s = strndup(buf, text_buffer_size);
2838 obj->data.s = strndup("", text_buffer_size);
2841 END OBJ(fs_bar, INFO_FS)
2842 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2844 while (isspace(*arg)) {
2853 obj->data.fsbar.fs = prepare_fs_stat(arg);
2854 END OBJ(fs_bar_free, INFO_FS)
2855 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2857 while (isspace(*arg)) {
2867 obj->data.fsbar.fs = prepare_fs_stat(arg);
2868 END OBJ(fs_free, INFO_FS)
2872 obj->data.fs = prepare_fs_stat(arg);
2873 END OBJ(fs_used_perc, INFO_FS)
2877 obj->data.fs = prepare_fs_stat(arg);
2878 END OBJ(fs_free_perc, INFO_FS)
2882 obj->data.fs = prepare_fs_stat(arg);
2883 END OBJ(fs_size, INFO_FS)
2887 obj->data.fs = prepare_fs_stat(arg);
2888 END OBJ(fs_type, INFO_FS)
2892 obj->data.fs = prepare_fs_stat(arg);
2893 END OBJ(fs_used, INFO_FS)
2897 obj->data.fs = prepare_fs_stat(arg);
2899 obj->data.i = arg ? atoi(arg) : 1;
2900 END OBJ(nameserver, INFO_DNS)
2901 obj->data.i = arg ? atoi(arg) : 0;
2903 obj->data.i = arg ? atoi(arg) : 1;
2905 obj->data.i = arg ? atoi(arg) : 1;
2909 ERR("goto needs arguments");
2910 obj->type = OBJ_text;
2911 obj->data.s = strndup("${goto}", text_buffer_size);
2915 obj->data.i = atoi(arg);
2921 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2922 sscanf(arg, "%d", &b);
2928 obj->data.pair.a = a;
2929 obj->data.pair.b = b;
2932 END OBJ(i2c, INFO_SYSFS)
2933 char buf1[64], buf2[64];
2937 ERR("i2c needs arguments");
2938 obj->type = OBJ_text;
2939 // obj->data.s = strndup("${i2c}", text_buffer_size);
2943 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2944 /* if scanf couldn't read three values, read type and num and use
2946 sscanf(arg, "%63s %d", buf2, &n);
2947 obj->data.sysfs.fd = open_i2c_sensor(0, buf2, n,
2948 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2949 strncpy(obj->data.sysfs.type, buf2, 63);
2951 obj->data.sysfs.fd = open_i2c_sensor(buf1, buf2, n,
2952 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2953 strncpy(obj->data.sysfs.type, buf2, 63);
2956 END OBJ(platform, INFO_SYSFS)
2957 char buf1[64], buf2[64];
2961 ERR("platform needs arguments");
2962 obj->type = OBJ_text;
2966 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2967 /* if scanf couldn't read three values, read type and num and use
2969 sscanf(arg, "%63s %d", buf2, &n);
2970 obj->data.sysfs.fd = open_platform_sensor(0, buf2, n,
2971 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2972 strncpy(obj->data.sysfs.type, buf2, 63);
2974 obj->data.sysfs.fd = open_platform_sensor(buf1, buf2, n,
2975 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2976 strncpy(obj->data.sysfs.type, buf2, 63);
2979 END OBJ(hwmon, INFO_SYSFS)
2980 char buf1[64], buf2[64];
2984 ERR("hwmon needs argumanets");
2985 obj->type = OBJ_text;
2989 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2990 /* if scanf couldn't read three values, read type and num and use
2992 sscanf(arg, "%63s %d", buf2, &n);
2993 obj->data.sysfs.fd = open_hwmon_sensor(0, buf2, n,
2994 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2995 strncpy(obj->data.sysfs.type, buf2, 63);
2997 obj->data.sysfs.fd = open_hwmon_sensor(buf1, buf2, n,
2998 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2999 strncpy(obj->data.sysfs.type, buf2, 63);
3001 #endif /* !__OpenBSD__ */
3003 END OBJ(top, INFO_TOP)
3008 ERR("top needs arguments");
3009 obj->type = OBJ_text;
3010 // obj->data.s = strndup("${top}", text_buffer_size);
3013 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
3014 if (strcmp(buf, "name") == 0) {
3015 obj->data.top.type = TOP_NAME;
3016 } else if (strcmp(buf, "cpu") == 0) {
3017 obj->data.top.type = TOP_CPU;
3018 } else if (strcmp(buf, "pid") == 0) {
3019 obj->data.top.type = TOP_PID;
3020 } else if (strcmp(buf, "mem") == 0) {
3021 obj->data.top.type = TOP_MEM;
3022 } else if (strcmp(buf, "time") == 0) {
3023 obj->data.top.type = TOP_TIME;
3024 } else if (strcmp(buf, "mem_res") == 0) {
3025 obj->data.top.type = TOP_MEM_RES;
3026 } else if (strcmp(buf, "mem_vsize") == 0) {
3027 obj->data.top.type = TOP_MEM_VSIZE;
3029 ERR("invalid arg for top");
3032 if (n < 1 || n > 10) {
3033 CRIT_ERR("invalid arg for top");
3036 obj->data.top.num = n - 1;
3040 ERR("invalid args given for top");
3043 END OBJ(top_mem, INFO_TOP)
3048 ERR("top_mem needs arguments");
3049 obj->type = OBJ_text;
3050 obj->data.s = strndup("${top_mem}", text_buffer_size);
3053 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
3054 if (strcmp(buf, "name") == 0) {
3055 obj->data.top.type = TOP_NAME;
3056 } else if (strcmp(buf, "cpu") == 0) {
3057 obj->data.top.type = TOP_CPU;
3058 } else if (strcmp(buf, "pid") == 0) {
3059 obj->data.top.type = TOP_PID;
3060 } else if (strcmp(buf, "mem") == 0) {
3061 obj->data.top.type = TOP_MEM;
3062 } else if (strcmp(buf, "time") == 0) {
3063 obj->data.top.type = TOP_TIME;
3064 } else if (strcmp(buf, "mem_res") == 0) {
3065 obj->data.top.type = TOP_MEM_RES;
3066 } else if (strcmp(buf, "mem_vsize") == 0) {
3067 obj->data.top.type = TOP_MEM_VSIZE;
3069 ERR("invalid arg for top");
3072 if (n < 1 || n > 10) {
3073 CRIT_ERR("invalid arg for top");
3076 obj->data.top.num = n - 1;
3080 ERR("invalid args given for top");
3083 END OBJ(addr, INFO_NET)
3085 obj->data.net = get_net_stat(arg);
3087 CRIT_ERR("addr needs argument");
3089 #if defined(__linux__)
3090 END OBJ(addrs, INFO_NET)
3092 obj->data.net = get_net_stat(arg);
3094 CRIT_ERR("addrs needs argument");
3096 #endif /* __linux__ */
3103 ERR("tail needs arguments");
3104 obj->type = OBJ_text;
3105 obj->data.s = strndup("${tail}", text_buffer_size);
3108 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3109 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3110 CRIT_ERR("invalid arg for tail, number of lines must be "
3111 "between 1 and %i", MAX_TAIL_LINES);
3117 obj->data.tail.fd = -1;
3119 if (stat(buf, &st) == 0) {
3120 if (S_ISFIFO(st.st_mode)) {
3121 fd = open(buf, O_RDONLY | O_NONBLOCK);
3124 CRIT_ERR("tail logfile does not exist, or you do "
3125 "not have correct permissions");
3128 obj->data.tail.fd = fd;
3130 fp = fopen(buf, "r");
3134 if (fp || obj->data.tail.fd != -1) {
3135 obj->data.tail.logfile = malloc(text_buffer_size);
3136 strcpy(obj->data.tail.logfile, buf);
3137 obj->data.tail.wantedlines = n1;
3138 obj->data.tail.interval = update_interval * 2;
3140 if (obj->data.tail.fd == -1) {
3145 CRIT_ERR("tail logfile does not exist, or you do not have "
3146 "correct permissions");
3149 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3150 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3151 CRIT_ERR("invalid arg for tail, number of lines must be "
3152 "between 1 and %i", MAX_TAIL_LINES);
3154 } else if (n2 < 1 || n2 < update_interval) {
3155 CRIT_ERR("invalid arg for tail, interval must be greater than "
3156 "0 and Conky's interval");
3162 obj->data.tail.fd = -1;
3164 if (stat(buf, &st) == 0) {
3165 if (S_ISFIFO(st.st_mode)) {
3166 fd = open(buf, O_RDONLY | O_NONBLOCK);
3169 CRIT_ERR("tail logfile does not exist, or you do "
3170 "not have correct permissions");
3173 obj->data.tail.fd = fd;
3175 fp = fopen(buf, "r");
3179 if (fp || obj->data.tail.fd != -1) {
3180 obj->data.tail.logfile = malloc(text_buffer_size);
3181 strcpy(obj->data.tail.logfile, buf);
3182 obj->data.tail.wantedlines = n1;
3183 obj->data.tail.interval = n2;
3185 if (obj->data.tail.fd == -1) {
3190 CRIT_ERR("tail logfile does not exist, or you do not have "
3191 "correct permissions");
3195 ERR("invalid args given for tail");
3198 /* asumming all else worked */
3199 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3205 ERR("head needs arguments");
3206 obj->type = OBJ_text;
3207 obj->data.s = strndup("${head}", text_buffer_size);
3210 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3211 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3212 CRIT_ERR("invalid arg for head, number of lines must be "
3213 "between 1 and %i", MAX_TAIL_LINES);
3218 fp = fopen(buf, "r");
3220 obj->data.tail.logfile = malloc(text_buffer_size);
3221 strcpy(obj->data.tail.logfile, buf);
3222 obj->data.tail.wantedlines = n1;
3223 obj->data.tail.interval = update_interval * 2;
3227 CRIT_ERR("head logfile does not exist, or you do not have "
3228 "correct permissions");
3231 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3232 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3233 CRIT_ERR("invalid arg for head, number of lines must be "
3234 "between 1 and %i", MAX_TAIL_LINES);
3236 } else if (n2 < 1 || n2 < update_interval) {
3237 CRIT_ERR("invalid arg for head, interval must be greater than "
3238 "0 and Conky's interval");
3243 fp = fopen(buf, "r");
3245 obj->data.tail.logfile = malloc(text_buffer_size);
3246 strcpy(obj->data.tail.logfile, buf);
3247 obj->data.tail.wantedlines = n1;
3248 obj->data.tail.interval = n2;
3252 CRIT_ERR("head logfile does not exist, or you do not have "
3253 "correct permissions");
3257 ERR("invalid args given for head");
3260 /* asumming all else worked */
3261 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3262 END OBJ(loadavg, INFO_LOADAVG)
3263 int a = 1, b = 2, c = 3, r = 3;
3266 r = sscanf(arg, "%d %d %d", &a, &b, &c);
3267 if (r >= 3 && (c < 1 || c > 3)) {
3270 if (r >= 2 && (b < 1 || b > 3)) {
3273 if (r >= 1 && (a < 1 || a > 3)) {
3277 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
3278 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
3279 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
3280 END OBJ(if_empty, 0)
3281 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3282 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3285 ERR("if_empty needs an argument");
3286 obj->data.ifblock.s = 0;
3288 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3290 blockstart[blockdepth] = object_count;
3291 obj->data.ifblock.pos = object_count + 2;
3293 END OBJ(if_existing, 0)
3294 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3295 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3298 ERR("if_existing needs an argument or two");
3299 obj->data.ifblock.s = NULL;
3300 obj->data.ifblock.str = NULL;
3302 char buf1[256], buf2[256];
3303 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3306 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
3307 obj->data.ifblock.str = NULL;
3309 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
3310 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
3313 blockstart[blockdepth] = object_count;
3314 obj->data.ifblock.pos = object_count + 2;
3316 END OBJ(if_mounted, 0)
3317 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3318 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3321 ERR("if_mounted needs an argument");
3322 obj->data.ifblock.s = 0;
3324 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3326 blockstart[blockdepth] = object_count;
3327 obj->data.ifblock.pos = object_count + 2;
3329 END OBJ(if_running, 0)
3330 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3331 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3336 snprintf(buf, 256, "pidof %s >/dev/null", arg);
3337 obj->data.ifblock.s = strndup(buf, text_buffer_size);
3339 ERR("if_running needs an argument");
3340 obj->data.ifblock.s = 0;
3342 blockstart[blockdepth] = object_count;
3343 obj->data.ifblock.pos = object_count + 2;
3349 char box[256], dst[256];
3353 /* Kapil: Changed from MAIL_FILE to
3354 current_mail_spool since the latter
3355 is a copy of the former if undefined
3356 but the latter should take precedence
3358 strncpy(box, current_mail_spool, sizeof(box));
3360 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3362 strncpy(box, arg, sizeof(box));
3366 variable_substitute(box, dst, sizeof(dst));
3367 obj->data.local_mail.box = strndup(dst, text_buffer_size);
3368 obj->data.local_mail.interval = n1;
3369 END OBJ(mboxscan, 0)
3370 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
3371 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
3372 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
3373 obj->data.mboxscan.output[0] = 1;
3374 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
3375 END OBJ(mem, INFO_MEM)
3376 END OBJ(memmax, INFO_MEM)
3377 END OBJ(memperc, INFO_MEM)
3378 END OBJ(membar, INFO_MEM)
3379 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3380 END OBJ(memgraph, INFO_MEM)
3381 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3387 END OBJ(mixer, INFO_MIXER)
3388 obj->data.l = mixer_init(arg);
3389 END OBJ(mixerl, INFO_MIXER)
3390 obj->data.l = mixer_init(arg);
3391 END OBJ(mixerr, INFO_MIXER)
3392 obj->data.l = mixer_init(arg);
3393 END OBJ(mixerbar, INFO_MIXER)
3394 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3395 &obj->data.mixerbar.h);
3396 END OBJ(mixerlbar, INFO_MIXER)
3397 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3398 &obj->data.mixerbar.h);
3399 END OBJ(mixerrbar, INFO_MIXER)
3400 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3401 &obj->data.mixerbar.h);
3402 END OBJ(new_mails, 0)
3404 char box[256], dst[256];
3408 /* Kapil: Changed from MAIL_FILE to
3409 current_mail_spool since the latter
3410 is a copy of the former if undefined
3411 but the latter should take precedence
3413 strncpy(box, current_mail_spool, sizeof(box));
3415 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3417 strncpy(box, arg, sizeof(box));
3421 variable_substitute(box, dst, sizeof(dst));
3422 obj->data.local_mail.box = strndup(dst, text_buffer_size);
3423 obj->data.local_mail.interval = n1;
3424 END OBJ(nodename, 0)
3425 END OBJ(processes, INFO_PROCS)
3426 END OBJ(running_processes, INFO_RUN_PROCS)
3427 END OBJ(shadecolor, 0)
3429 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
3431 END OBJ(outlinecolor, 0)
3433 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
3435 END OBJ(stippled_hr, 0)
3437 int a = stippled_borders, b = 1;
3440 if (sscanf(arg, "%d %d", &a, &b) != 2) {
3441 sscanf(arg, "%d", &b);
3447 obj->data.pair.a = a;
3448 obj->data.pair.b = b;
3450 END OBJ(swap, INFO_MEM)
3451 END OBJ(swapmax, INFO_MEM)
3452 END OBJ(swapperc, INFO_MEM)
3453 END OBJ(swapbar, INFO_MEM)
3454 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3457 END OBJ(temp1, INFO_SYSFS)
3458 obj->type = OBJ_i2c;
3459 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 1,
3460 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3461 END OBJ(temp2, INFO_SYSFS)
3462 obj->type = OBJ_i2c;
3463 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 2,
3464 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3467 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
3469 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
3471 char buf1[256], buf2[256], *fmt, *tz;
3475 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3485 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
3486 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
3488 END OBJ(iconv_start, 0)
3489 if (iconv_converting) {
3490 CRIT_ERR("You must stop your last iconv conversion before "
3491 "starting another");
3494 char iconv_from[CODEPAGE_LENGTH];
3495 char iconv_to[CODEPAGE_LENGTH];
3497 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3498 CRIT_ERR("Invalid arguments for iconv_start");
3502 new_iconv = iconv_open(iconv_to, iconv_from);
3503 if (new_iconv == (iconv_t) (-1)) {
3504 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3506 obj->a = register_iconv(&new_iconv);
3507 iconv_converting = 1;
3511 CRIT_ERR("Iconv requires arguments");
3513 END OBJ(iconv_stop, 0)
3514 iconv_converting = 0;
3517 END OBJ(totaldown, INFO_NET)
3519 obj->data.net = get_net_stat(arg);
3521 CRIT_ERR("totaldown needs argument");
3523 END OBJ(totalup, INFO_NET)
3524 obj->data.net = get_net_stat(arg);
3526 obj->data.net = get_net_stat(arg);
3528 CRIT_ERR("totalup needs argument");
3532 obj->data.i = arg ? atoi(arg) : 0;
3534 obj->data.i = arg ? atoi(arg) : 0;
3535 END OBJ(upspeed, INFO_NET)
3537 obj->data.net = get_net_stat(arg);
3539 CRIT_ERR("upspeed needs argument");
3541 END OBJ(upspeedf, INFO_NET)
3543 obj->data.net = get_net_stat(arg);
3545 CRIT_ERR("upspeedf needs argument");
3548 END OBJ(upspeedgraph, INFO_NET)
3549 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3553 obj->data.net = get_net_stat(buf);
3556 END OBJ(uptime_short, INFO_UPTIME)
3557 END OBJ(uptime, INFO_UPTIME)
3558 END OBJ(user_names, INFO_USERS)
3559 END OBJ(user_times, INFO_USERS)
3560 END OBJ(user_terms, INFO_USERS)
3561 END OBJ(user_number, INFO_USERS)
3562 END OBJ(gw_iface, INFO_GW)
3563 END OBJ(gw_ip, INFO_GW)
3564 END OBJ(if_gw, INFO_GW)
3566 END OBJ(adt746xcpu, 0)
3567 END OBJ(adt746xfan, 0)
3568 #endif /* !__OpenBSD__ */
3569 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
3570 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3571 END OBJ(apm_adapter, 0)
3572 END OBJ(apm_battery_life, 0)
3573 END OBJ(apm_battery_time, 0)
3574 #endif /* __FreeBSD__ */
3575 END OBJ(imap_unseen, 0)
3578 obj->data.mail = parse_mail_args(IMAP, arg);
3579 obj->global_mode = 0;
3581 obj->global_mode = 1;
3583 END OBJ(imap_messages, 0)
3586 obj->data.mail = parse_mail_args(IMAP, arg);
3587 obj->global_mode = 0;
3589 obj->global_mode = 1;
3591 END OBJ(pop3_unseen, 0)
3594 obj->data.mail = parse_mail_args(POP3, arg);
3595 obj->global_mode = 0;
3597 obj->global_mode = 1;
3599 END OBJ(pop3_used, 0)
3602 obj->data.mail = parse_mail_args(POP3, arg);
3603 obj->global_mode = 0;
3605 obj->global_mode = 1;
3610 obj->data.s = strndup(arg, text_buffer_size);
3612 ERR("smapi needs an argument");
3613 END OBJ(if_smapi_bat_installed, 0)
3614 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3615 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3618 ERR("if_smapi_bat_installed needs an argument");
3619 obj->data.ifblock.s = 0;
3621 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3622 blockstart[blockdepth] = object_count;
3623 obj->data.ifblock.pos = object_count + 2;
3625 END OBJ(smapi_bat_perc, 0)
3627 obj->data.s = strndup(arg, text_buffer_size);
3629 ERR("smapi_bat_perc needs an argument");
3630 END OBJ(smapi_bat_bar, 0)
3633 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
3634 ERR("first argument to smapi_bat_bar must be an integer value");
3638 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
3641 ERR("if_smapi_bat_bar needs an argument");
3644 END OBJ(mpd_artist, INFO_MPD)
3645 END OBJ(mpd_title, INFO_MPD)
3647 sscanf(arg, "%d", &info.mpd.max_title_len);
3648 if (info.mpd.max_title_len > 0) {
3649 info.mpd.max_title_len++;
3651 CRIT_ERR("mpd_title: invalid length argument");
3654 info.mpd.max_title_len = 0;
3656 END OBJ(mpd_random, INFO_MPD)
3657 END OBJ(mpd_repeat, INFO_MPD)
3658 END OBJ(mpd_elapsed, INFO_MPD)
3659 END OBJ(mpd_length, INFO_MPD)
3660 END OBJ(mpd_track, INFO_MPD)
3661 END OBJ(mpd_name, INFO_MPD)
3662 END OBJ(mpd_file, INFO_MPD)
3663 END OBJ(mpd_percent, INFO_MPD)
3664 END OBJ(mpd_album, INFO_MPD)
3665 END OBJ(mpd_vol, INFO_MPD)
3666 END OBJ(mpd_bitrate, INFO_MPD)
3667 END OBJ(mpd_status, INFO_MPD)
3668 END OBJ(mpd_bar, INFO_MPD)
3669 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3670 END OBJ(mpd_smart, INFO_MPD)
3673 END OBJ(xmms2_artist, INFO_XMMS2)
3674 END OBJ(xmms2_album, INFO_XMMS2)
3675 END OBJ(xmms2_title, INFO_XMMS2)
3676 END OBJ(xmms2_genre, INFO_XMMS2)
3677 END OBJ(xmms2_comment, INFO_XMMS2)
3678 END OBJ(xmms2_url, INFO_XMMS2)
3679 END OBJ(xmms2_tracknr, INFO_XMMS2)
3680 END OBJ(xmms2_bitrate, INFO_XMMS2)
3681 END OBJ(xmms2_date, INFO_XMMS2)
3682 END OBJ(xmms2_id, INFO_XMMS2)
3683 END OBJ(xmms2_duration, INFO_XMMS2)
3684 END OBJ(xmms2_elapsed, INFO_XMMS2)
3685 END OBJ(xmms2_size, INFO_XMMS2)
3686 END OBJ(xmms2_status, INFO_XMMS2)
3687 END OBJ(xmms2_percent, INFO_XMMS2)
3688 END OBJ(xmms2_bar, INFO_XMMS2)
3689 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3690 END OBJ(xmms2_smart, INFO_XMMS2)
3691 END OBJ(xmms2_playlist, INFO_XMMS2)
3692 END OBJ(xmms2_timesplayed, INFO_XMMS2)
3695 END OBJ(audacious_status, INFO_AUDACIOUS)
3696 END OBJ(audacious_title, INFO_AUDACIOUS)
3698 sscanf(arg, "%d", &info.audacious.max_title_len);
3699 if (info.audacious.max_title_len > 0) {
3700 info.audacious.max_title_len++;
3702 CRIT_ERR("audacious_title: invalid length argument");
3705 END OBJ(audacious_length, INFO_AUDACIOUS)
3706 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
3707 END OBJ(audacious_position, INFO_AUDACIOUS)
3708 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
3709 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
3710 END OBJ(audacious_frequency, INFO_AUDACIOUS)
3711 END OBJ(audacious_channels, INFO_AUDACIOUS)
3712 END OBJ(audacious_filename, INFO_AUDACIOUS)
3713 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
3714 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
3715 END OBJ(audacious_bar, INFO_AUDACIOUS)
3716 scan_bar(arg, &obj->a, &obj->b);
3719 END OBJ(bmpx_title, INFO_BMPX)
3720 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3721 END OBJ(bmpx_artist, INFO_BMPX)
3722 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3723 END OBJ(bmpx_album, INFO_BMPX)
3724 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3725 END OBJ(bmpx_track, INFO_BMPX)
3726 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3727 END OBJ(bmpx_uri, INFO_BMPX)
3728 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3729 END OBJ(bmpx_bitrate, INFO_BMPX)
3730 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3735 int argc, delay, act_par;
3736 char *uri = (char *) malloc(128 * sizeof(char));
3737 char *action = (char *) malloc(64 * sizeof(char));
3739 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action,
3741 obj->data.rss.uri = uri;
3742 obj->data.rss.delay = delay;
3743 obj->data.rss.action = action;
3744 obj->data.rss.act_par = act_par;
3748 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
3754 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3755 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3756 ERR("hddtemp needs arguments");
3757 obj->type = OBJ_text;
3758 obj->data.s = strndup("${hddtemp}", text_buffer_size);
3762 #ifdef TCP_PORT_MONITOR
3763 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3764 int argc, port_begin, port_end, item, connection_index;
3767 memset(itembuf, 0, sizeof(itembuf));
3768 connection_index = 0;
3769 /* massive argument checking */
3771 CRIT_ERR("tcp_portmon: needs arguments");
3773 argc = sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf,
3775 if ((argc != 3) && (argc != 4)) {
3776 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3778 if ((port_begin < 1) || (port_begin > 65535) || (port_end < 1)
3779 || (port_end > 65535)) {
3780 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3782 if (port_begin > port_end) {
3783 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3785 if (strncmp(itembuf, "count", 31) == 0) {
3787 } else if (strncmp(itembuf, "rip", 31) == 0) {
3789 } else if (strncmp(itembuf, "rhost", 31) == 0) {
3791 } else if (strncmp(itembuf, "rport", 31) == 0) {
3793 } else if (strncmp(itembuf, "rservice", 31) == 0) {
3794 item = REMOTESERVICE;
3795 } else if (strncmp(itembuf, "lip", 31) == 0) {
3797 } else if (strncmp(itembuf, "lhost", 31) == 0) {
3799 } else if (strncmp(itembuf, "lport", 31) == 0) {
3801 } else if (strncmp(itembuf, "lservice", 31) == 0) {
3802 item = LOCALSERVICE;
3804 CRIT_ERR("tcp_portmon: invalid item specified");
3806 if ((argc == 3) && (item != COUNT)) {
3807 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" "
3810 if ((argc == 4) && (connection_index < 0)) {
3811 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3813 /* ok, args looks good. save the text object data */
3814 obj->data.tcp_port_monitor.port_range_begin = (in_port_t) port_begin;
3815 obj->data.tcp_port_monitor.port_range_end = (in_port_t) port_end;
3816 obj->data.tcp_port_monitor.item = item;
3817 obj->data.tcp_port_monitor.connection_index = connection_index;
3819 /* if the port monitor collection hasn't been created,
3820 * we must create it */
3821 if (!info.p_tcp_port_monitor_collection) {
3822 info.p_tcp_port_monitor_collection =
3823 create_tcp_port_monitor_collection();
3824 if (!info.p_tcp_port_monitor_collection) {
3825 CRIT_ERR("tcp_portmon: unable to create port monitor "
3830 /* if a port monitor for this port does not exist,
3831 * create one and add it to the collection */
3832 if (find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
3833 port_begin, port_end) == NULL) {
3834 tcp_port_monitor_t *p_monitor = create_tcp_port_monitor(port_begin,
3835 port_end, &tcp_port_monitor_args);
3838 CRIT_ERR("tcp_portmon: unable to create port monitor");
3840 /* add the newly created monitor to the collection */
3841 if (insert_tcp_port_monitor_into_collection(
3842 info.p_tcp_port_monitor_collection, p_monitor) != 0) {
3843 CRIT_ERR("tcp_portmon: unable to add port monitor to "
3848 END OBJ(entropy_avail, INFO_ENTROPY)
3849 END OBJ(entropy_poolsize, INFO_ENTROPY)
3850 END OBJ(entropy_bar, INFO_ENTROPY)
3851 scan_bar(arg, &obj->a, &obj->b);
3855 ERR("unknown variable %s", s);
3856 obj->type = OBJ_text;
3857 snprintf(buf, 256, "${%s}", s);
3858 obj->data.s = strndup(buf, text_buffer_size);
3865 static struct text_object *create_plain_text(const char *s)
3867 struct text_object *obj;
3869 if (s == NULL || *s == '\0') {
3873 obj = new_text_object_internal();
3875 obj->type = OBJ_text;
3876 obj->data.s = strndup(s, text_buffer_size);
3880 static struct text_object_list *extract_variable_text_internal(const char *const_p)
3882 struct text_object_list *retval;
3883 struct text_object *obj;
3884 char *p, *s, *orig_p;
3887 p = strndup(const_p, max_user_text);
3890 retval = malloc(sizeof(struct text_object_list));
3891 memset(retval, 0, sizeof(struct text_object_list));
3892 retval->text_object_count = 0;
3902 obj = create_plain_text(s);
3904 // allocate memory for the object
3905 retval->text_objects = realloc(retval->text_objects,
3906 sizeof(struct text_object) *
3907 (retval->text_object_count + 1));
3908 // assign the new object to the end of the list.
3909 memcpy(&retval->text_objects[retval->text_object_count++], obj,
3910 sizeof(struct text_object));
3922 /* variable is either $foo or ${foo} */
3924 unsigned int brl = 1, brr = 0;
3928 while (*p && brl != brr) {
3943 while (*p && (isalnum((int) *p) || *p == '_')) {
3948 /* copy variable to buffer */
3949 len = (p - s > 255) ? 255 : (p - s);
3950 strncpy(buf, s, len);
3960 /* if variable wasn't found in environment, use some special */
3966 if (strchr(buf, ' ')) {
3967 arg = strchr(buf, ' ');
3970 while (isspace((int) *arg)) {
3978 /* lowercase variable name */
3981 *tmp_p = tolower(*tmp_p);
3985 // create new object
3986 obj = construct_text_object(buf, arg,
3987 retval->text_object_count, retval->text_objects, line);
3989 // allocate memory for the object
3990 retval->text_objects = realloc(retval->text_objects,
3991 sizeof(struct text_object) *
3992 (retval->text_object_count + 1));
3993 // assign the new object to the end of the list.
3995 &retval->text_objects[retval->text_object_count++],
3996 obj, sizeof(struct text_object));
4002 obj = create_plain_text("$");
4004 // allocate memory for the object
4005 retval->text_objects = realloc(retval->text_objects,
4006 sizeof(struct text_object) *
4007 (retval->text_object_count + 1));
4008 // assign the new object to the end of the list.
4009 memcpy(&retval->text_objects[retval->text_object_count++],
4010 obj, sizeof(struct text_object));
4017 obj = create_plain_text(s);
4019 // allocate memory for the object
4020 retval->text_objects = realloc(retval->text_objects,
4021 sizeof(struct text_object) * (retval->text_object_count + 1));
4022 // assign the new object to the end of the list.
4023 memcpy(&retval->text_objects[retval->text_object_count++], obj,
4024 sizeof(struct text_object));
4029 ERR("one or more $endif's are missing");
4036 static void extract_variable_text(const char *p)
4038 struct text_object_list *list;
4040 free_text_objects(global_text_object_count, global_text_objects);
4053 global_text_object_count = 0;
4054 global_text_objects = NULL;
4056 list = extract_variable_text_internal(p);
4057 global_text_objects = list->text_objects;
4058 global_text_object_count = list->text_object_count;
4063 struct text_object_list *parse_conky_vars(char *txt, char *p, struct information *cur)
4065 struct text_object_list *object_list =
4066 extract_variable_text_internal(txt);
4068 generate_text_internal(p, max_user_text, object_list->text_objects,
4069 object_list->text_object_count, cur);
4073 /* Allows reading from a FIFO (i.e., /dev/xconsole).
4074 * The file descriptor is set to non-blocking which makes this possible.
4076 * FIXME: Since lseek cannot seek a file descriptor long lines will break. */
4077 static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
4079 #define TAIL_PIPE_BUFSIZE 4096
4083 int fd = obj->data.tail.fd;
4086 char buf[TAIL_PIPE_BUFSIZE];
4087 ssize_t len = read(fd, buf, sizeof(buf));
4091 if (errno != EAGAIN) {
4092 strcpy(obj->data.tail.buffer, "Logfile Read Error");
4093 snprintf(dst, dst_size, "Logfile Read Error");
4097 } else if (len == 0) {
4098 strcpy(obj->data.tail.buffer, "Logfile Empty");
4099 snprintf(dst, dst_size, "Logfile Empty");
4103 for (line_len = 0, i = 0; i < len; i++) {
4107 if (buf[i] == '\n') {
4110 if (obj->data.tail.readlines > 0) {
4115 for (n = 0; obj->data.tail.buffer[n]; n++) {
4116 if (obj->data.tail.buffer[n] == '\n') {
4121 if (++olines < obj->data.tail.wantedlines) {
4127 p = obj->data.tail.buffer + first_line;
4128 pos = n - first_line;
4129 memmove(obj->data.tail.buffer,
4130 obj->data.tail.buffer + first_line, strlen(p));
4131 obj->data.tail.buffer[pos] = 0;
4137 p = buf + last_line;
4139 memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
4140 obj->data.tail.buffer[pos + line_len] = 0;
4143 obj->data.tail.readlines = lines;
4151 snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
4154 char *format_time(unsigned long timeval, const int width)
4157 unsigned long nt; // narrow time, for speed on 32-bit
4158 unsigned cc; // centiseconds
4159 unsigned nn; // multi-purpose whatever
4162 cc = nt % 100; // centiseconds past second
4163 nt /= 100; // total seconds
4164 nn = nt % 60; // seconds past the minute
4165 nt /= 60; // total minutes
4166 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
4168 return strndup(buf, text_buffer_size);
4170 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
4171 return strndup(buf, text_buffer_size);
4173 nn = nt % 60; // minutes past the hour
4174 nt /= 60; // total hours
4175 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
4176 return strndup(buf, text_buffer_size);
4178 nn = nt; // now also hours
4179 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
4180 return strndup(buf, text_buffer_size);
4182 nn /= 24; // now days
4183 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
4184 return strndup(buf, text_buffer_size);
4186 nn /= 7; // now weeks
4187 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
4188 return strndup(buf, text_buffer_size);
4190 // well shoot, this outta' fit...
4191 return strndup("<inf>", text_buffer_size);
4194 static void generate_text_internal(char *p, int p_max_size,
4195 struct text_object *objs, unsigned int object_count,
4196 struct information *cur)
4201 char buff_in[p_max_size];
4203 iconv_converting = 0;
4206 for (i = 0; i < object_count; i++) {
4207 struct text_object *obj = &objs[i];
4209 if (p_max_size < 1) {
4213 #define OBJ(a) break; case OBJ_##a:
4215 switch (obj->type) {
4217 ERR("not implemented obj type %d", obj->type);
4220 /* does anyone have decimals in acpi temperature? */
4221 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
4222 round_to_int(get_acpi_temperature(obj->data.i)));
4225 /* does anyone have decimals in acpi temperature? */
4226 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
4227 round_to_int((get_acpi_temperature(obj->data.i) + 40) *
4230 #endif /* !__OpenBSD__ */
4233 obj->a = get_freq(p, p_max_size, "%.0f", 1,
4234 obj->data.cpu_index);
4240 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
4241 obj->data.cpu_index);
4243 /* OpenBSD has no such flag (SUSv2) */
4244 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
4245 obj->data.cpu_index);
4249 #if defined(__linux__)
4252 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
4253 obj->data.cpu_index);
4258 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
4259 obj->data.cpu_index);
4264 OBJ(wireless_essid) {
4265 snprintf(p, p_max_size, "%s", obj->data.net->essid);
4267 OBJ(wireless_mode) {
4268 snprintf(p, p_max_size, "%s", obj->data.net->mode);
4270 OBJ(wireless_bitrate) {
4271 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
4274 snprintf(p, p_max_size, "%s", obj->data.net->ap);
4276 OBJ(wireless_link_qual) {
4277 spaced_print(p, p_max_size, "%d", 4, "wireless_link_qual",
4278 obj->data.net->link_qual);
4280 OBJ(wireless_link_qual_max) {
4281 spaced_print(p, p_max_size, "%d", 4,
4282 "wireless_link_qual_max", obj->data.net->link_qual_max);
4284 OBJ(wireless_link_qual_perc) {
4285 if (obj->data.net->link_qual_max > 0) {
4286 spaced_print(p, p_max_size, "%.0f", 5,
4287 "wireless_link_qual_perc",
4288 (double) obj->data.net->link_qual /
4289 obj->data.net->link_qual_max * 100);
4291 spaced_print(p, p_max_size, "unk", 5,
4292 "wireless_link_qual_perc");
4295 OBJ(wireless_link_bar) {
4296 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
4297 obj->data.net->link_qual_max) * 255.0);
4299 #endif /* HAVE_IWLIB */
4301 #endif /* __linux__ */
4304 get_freq_dynamic(p, p_max_size, "%.0f", 1);
4305 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4309 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
4311 get_freq_dynamic(p, p_max_size, "%.2f", 1000);
4313 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4318 get_adt746x_cpu(p, p_max_size);
4321 get_adt746x_fan(p, p_max_size);
4324 get_acpi_fan(p, p_max_size);
4326 OBJ(acpiacadapter) {
4327 get_acpi_ac_adapter(p, p_max_size);
4330 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
4333 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
4335 OBJ(battery_percent) {
4336 spaced_print(p, p_max_size, "%*d", 4, "battery_percent",
4337 pad_percents, get_battery_perct(obj->data.s));
4340 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
4342 #endif /* __OpenBSD__ */
4345 human_readable(cur->buffers * 1024, p, 255, "buffers");
4348 human_readable(cur->cached * 1024, p, 255, "buffers");
4351 if (obj->data.cpu_index > info.cpu_count) {
4352 printf("obj->data.cpu_index %i info.cpu_count %i",
4353 obj->data.cpu_index, info.cpu_count);
4354 CRIT_ERR("attempting to use more CPUs then you have!");
4356 spaced_print(p, p_max_size, "%*d", 4, "cpu", pad_percents,
4357 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
4360 new_bar(p, obj->a, obj->b,
4361 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
4364 new_graph(p, obj->a, obj->b, obj->c, obj->d, (unsigned int)
4365 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
4369 new_fg(p, obj->data.l);
4401 OBJ(conky_version) {
4402 snprintf(p, p_max_size, "%s", VERSION);
4404 OBJ(conky_build_date) {
4405 snprintf(p, p_max_size, "%s", BUILD_DATE);
4407 OBJ(conky_build_arch) {
4408 snprintf(p, p_max_size, "%s", BUILD_ARCH);
4410 #if defined(__linux__)
4412 snprintf(p, p_max_size, "%s",
4413 get_disk_protect_queue(obj->data.s));
4416 snprintf(p, p_max_size, "%s", i8k.version);
4419 snprintf(p, p_max_size, "%s", i8k.bios);
4422 snprintf(p, p_max_size, "%s", i8k.serial);
4425 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
4427 OBJ(i8k_cpu_tempf) {
4430 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
4431 snprintf(p, p_max_size, "%.1f", cpu_temp * (9.0 / 5.0) + 32.0);
4433 OBJ(i8k_left_fan_status) {
4434 int left_fan_status;
4436 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
4437 if (left_fan_status == 0) {
4438 snprintf(p, p_max_size, "off");
4440 if (left_fan_status == 1) {
4441 snprintf(p, p_max_size, "low");
4443 if (left_fan_status == 2) {
4444 snprintf(p, p_max_size, "high");
4447 OBJ(i8k_right_fan_status) {
4448 int right_fan_status;
4450 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
4451 if (right_fan_status == 0) {
4452 snprintf(p, p_max_size, "off");
4454 if (right_fan_status == 1) {
4455 snprintf(p, p_max_size, "low");
4457 if (right_fan_status == 2) {
4458 snprintf(p, p_max_size, "high");
4461 OBJ(i8k_left_fan_rpm) {
4462 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
4464 OBJ(i8k_right_fan_rpm) {
4465 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
4467 OBJ(i8k_ac_status) {
4470 sscanf(i8k.ac_status, "%d", &ac_status);
4471 if (ac_status == -1) {
4472 snprintf(p, p_max_size, "disabled (read i8k docs)");
4474 if (ac_status == 0) {
4475 snprintf(p, p_max_size, "off");
4477 if (ac_status == 1) {
4478 snprintf(p, p_max_size, "on");
4481 OBJ(i8k_buttons_status) {
4482 snprintf(p, p_max_size, "%s", i8k.buttons_status);
4485 get_ibm_acpi_fan(p, p_max_size);
4488 get_ibm_acpi_temps();
4489 snprintf(p, p_max_size, "%d", ibm_acpi.temps[obj->data.sensor]);
4492 get_ibm_acpi_volume(p, p_max_size);
4494 OBJ(ibm_brightness) {
4495 get_ibm_acpi_brightness(p, p_max_size);
4498 if ((obj->data.ifblock.s)
4499 && (!interface_up(obj->data.ifblock.s))) {
4500 i = obj->data.ifblock.pos;
4507 if (!cur->gw_info.count) {
4508 i = obj->data.ifblock.pos;
4515 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
4518 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
4521 snprintf(p, p_max_size, "%d", get_laptop_mode());
4524 get_powerbook_batt_info(p, p_max_size, obj->data.i);
4526 #endif /* __linux__ */
4529 OBJ(obsd_sensors_temp) {
4530 obsd_sensors.device = sensor_device;
4531 update_obsd_sensors();
4532 snprintf(p, p_max_size, "%.1f",
4533 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
4535 OBJ(obsd_sensors_fan) {
4536 obsd_sensors.device = sensor_device;
4537 update_obsd_sensors();
4538 snprintf(p, p_max_size, "%d",
4539 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
4541 OBJ(obsd_sensors_volt) {
4542 obsd_sensors.device = sensor_device;
4543 update_obsd_sensors();
4544 snprintf(p, p_max_size, "%.2f",
4545 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4548 get_obsd_vendor(p, p_max_size);
4551 get_obsd_product(p, p_max_size);
4553 #endif /* __OpenBSD__ */
4557 new_font(p, obj->data.s);
4560 /* TODO: move this correction from kB to kB/s elsewhere
4561 * (or get rid of it??) */
4563 if (obj->data.diskio) {
4565 (obj->data.diskio->current / update_interval) * 1024LL,
4566 p, p_max_size, "diskio");
4568 human_readable(diskio_value * 1024LL, p, p_max_size,
4573 if (obj->data.diskio) {
4574 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL, p, p_max_size,
4577 human_readable(diskio_write_value * 1024LL, p, p_max_size,
4582 if (obj->data.diskio) {
4583 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL, p, p_max_size,
4586 human_readable(diskio_read_value * 1024LL, p, p_max_size,
4591 if (obj->data.diskio) {
4592 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4593 obj->data.diskio->current, obj->e, 1);
4595 new_graph(p, obj->a, obj->b, obj->c, obj->d, diskio_value,
4599 OBJ(diskiograph_read) {
4600 if (obj->data.diskio) {
4601 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4602 obj->data.diskio->current_read, obj->e, 1);
4604 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4605 diskio_read_value, obj->e, 1);
4608 OBJ(diskiograph_write) {
4609 if (obj->data.diskio) {
4610 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4611 obj->data.diskio->current_write, obj->e, 1);
4613 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4614 diskio_write_value, obj->e, 1);
4618 spaced_print(p, p_max_size, "%d", 6, "downspeed",
4619 round_to_int(obj->data.net->recv_speed / 1024));
4622 spaced_print(p, p_max_size, "%.1f", 8, "downspeedf",
4623 obj->data.net->recv_speed / 1024.0);
4625 OBJ(downspeedgraph) {
4626 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4627 obj->data.net->recv_speed / 1024.0, obj->e, 1);
4631 i = obj->data.ifblock.pos - 1;
4641 snprintf(p, p_max_size, "%u.%u.%u.%u",
4642 obj->data.net->addr.sa_data[2] & 255,
4643 obj->data.net->addr.sa_data[3] & 255,
4644 obj->data.net->addr.sa_data[4] & 255,
4645 obj->data.net->addr.sa_data[5] & 255);
4648 #if defined(__linux__)
4650 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
4652 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
4653 strcpy(p, obj->data.net->addrs);
4656 strcpy(p, "0.0.0.0");
4658 #endif /* __linux__ */
4660 #if defined(IMLIB2) && defined(X11)
4665 Imlib_Image image, buffer;
4667 image = imlib_load_image(obj->data.s);
4668 imlib_context_set_image(image);
4672 w = imlib_image_get_width();
4673 h = imlib_image_get_height();
4674 buffer = imlib_create_image(w, h);
4675 imlib_context_set_display(display);
4676 imlib_context_set_drawable(window.drawable);
4677 imlib_context_set_colormap(DefaultColormap(display,
4679 imlib_context_set_visual(DefaultVisual(display,
4681 imlib_context_set_image(buffer);
4682 imlib_blend_image_onto_image(image, 0, 0, 0, w, h,
4683 text_start_x, text_start_y, w, h);
4684 imlib_render_image_on_drawable(text_start_x,
4687 imlib_context_set_image(image);
4695 FILE *fp = popen(obj->data.s, "r");
4696 int length = fread(p, 1, p_max_size, fp);
4701 if (length > 0 && p[length - 1] == '\n') {
4702 p[length - 1] = '\0';
4707 struct information *my_info;
4708 struct text_object_list *text_objects;
4711 fp = popen(obj->data.s, "r");
4712 fread(p, 1, p_max_size, fp);
4715 my_info = malloc(sizeof(struct information));
4716 memcpy(my_info, cur, sizeof(struct information));
4717 text_objects = parse_conky_vars(p, p, my_info);
4722 if (length > 0 && p[length - 1] == '\n') {
4723 p[length - 1] = '\0';
4726 free_text_objects(text_objects->text_object_count, text_objects->text_objects);
4732 FILE *fp = popen(obj->data.s, "r");
4733 int n2 = fread(p, 1, p_max_size, fp);
4738 if (n2 && p[n2 - 1] == '\n') {
4743 if (*p2 == '\001') {
4749 if (sscanf(p, "%lf", &barnum) == 0) {
4750 ERR("reading execbar value failed (perhaps it's not the "
4751 "correct format?)");
4753 if (barnum > 100 || barnum < 0) {
4754 ERR("your execbar value is not between 0 and 100, "
4755 "therefore it will be ignored");
4757 barnum = barnum / 100.0;
4758 new_bar(p, 0, 4, (int) (barnum * 255.0));
4763 FILE *fp = popen(obj->data.s, "r");
4764 int n2 = fread(p, 1, p_max_size, fp);
4769 if (n2 && p[n2 - 1] == '\n') {
4773 if (*p2 == '\001') {
4779 if (sscanf(p, "%lf", &barnum) == 0) {
4780 ERR("reading execgraph value failed (perhaps it's not the "
4781 "correct format?)");
4783 if (barnum > 100 || barnum < 0) {
4784 ERR("your execgraph value is not between 0 and 100, "
4785 "therefore it will be ignored");
4787 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum),
4792 if (current_update_time - obj->data.execi.last_update
4793 < obj->data.execi.interval) {
4794 new_bar(p, 0, 4, (int) obj->f);
4797 FILE *fp = popen(obj->data.execi.cmd, "r");
4798 int n2 = fread(p, 1, p_max_size, fp);
4803 if (n2 && p[n2 - 1] == '\n') {
4808 if (*p2 == '\001') {
4814 if (sscanf(p, "%f", &barnum) == 0) {
4815 ERR("reading execibar value failed (perhaps it's not "
4816 "the correct format?)");
4818 if (barnum > 100 || barnum < 0) {
4819 ERR("your execibar value is not between 0 and 100, "
4820 "therefore it will be ignored");
4822 obj->f = 255 * barnum / 100.0;
4823 new_bar(p, 0, 4, (int) obj->f);
4825 obj->data.execi.last_update = current_update_time;
4829 if (current_update_time - obj->data.execi.last_update
4830 < obj->data.execi.interval) {
4831 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
4834 FILE *fp = popen(obj->data.execi.cmd, "r");
4835 int n2 = fread(p, 1, p_max_size, fp);
4840 if (n2 && p[n2 - 1] == '\n') {
4845 if (*p2 == '\001') {
4851 if (sscanf(p, "%f", &barnum) == 0) {
4852 ERR("reading execigraph value failed (perhaps it's not "
4853 "the correct format?)");
4855 if (barnum > 100 || barnum < 0) {
4856 ERR("your execigraph value is not between 0 and 100, "
4857 "therefore it will be ignored");
4860 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f),
4863 obj->data.execi.last_update = current_update_time;
4867 if (current_update_time - obj->data.execi.last_update
4868 < obj->data.execi.interval
4869 || obj->data.execi.interval == 0) {
4870 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4872 char *output = obj->data.execi.buffer;
4873 FILE *fp = popen(obj->data.execi.cmd, "r");
4875 int length = fread(output, 1, text_buffer_size, fp);
4878 output[length] = '\0';
4879 if (length > 0 && output[length - 1] == '\n') {
4880 output[length - 1] = '\0';
4882 obj->data.execi.last_update = current_update_time;
4883 snprintf(p, p_max_size, "%s", output);
4885 // parse_conky_vars(output, p, cur);
4888 struct text_object_list *text_objects = 0;
4889 struct information *my_info =
4890 malloc(sizeof(struct information));
4891 memcpy(my_info, cur, sizeof(struct information));
4893 if (current_update_time - obj->data.execi.last_update
4894 < obj->data.execi.interval
4895 || obj->data.execi.interval == 0) {
4896 text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info);
4898 char *output = obj->data.execi.buffer;
4899 FILE *fp = popen(obj->data.execi.cmd, "r");
4900 int length = fread(output, 1, text_buffer_size, fp);
4904 output[length] = '\0';
4905 if (length > 0 && output[length - 1] == '\n') {
4906 output[length - 1] = '\0';
4909 text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info);
4910 obj->data.execi.last_update = current_update_time;
4912 free_text_objects(text_objects->text_object_count, text_objects->text_objects);
4917 if (!obj->data.texeci.p_timed_thread) {
4918 obj->data.texeci.p_timed_thread =
4919 timed_thread_create(&threaded_exec,
4920 (void *) obj, obj->data.texeci.interval * 1000000);
4921 if (!obj->data.texeci.p_timed_thread) {
4922 ERR("Error creating texeci timed thread");
4924 timed_thread_register(obj->data.texeci.p_timed_thread,
4925 &obj->data.texeci.p_timed_thread);
4926 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4927 ERR("Error running texeci timed thread");
4930 timed_thread_lock(obj->data.texeci.p_timed_thread);
4931 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4932 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4934 #endif /* HAVE_POPEN */
4936 if (obj->global_mode && info.mail) {
4937 // this means we use info
4938 if (!info.mail->p_timed_thread) {
4939 info.mail->p_timed_thread =
4940 timed_thread_create(&imap_thread,
4941 (void *) info.mail, info.mail->interval * 1000000);
4942 if (!info.mail->p_timed_thread) {
4943 ERR("Error creating imap timed thread");
4945 timed_thread_register(info.mail->p_timed_thread,
4946 &info.mail->p_timed_thread);
4947 if (timed_thread_run(info.mail->p_timed_thread)) {
4948 ERR("Error running imap timed thread");
4951 timed_thread_lock(info.mail->p_timed_thread);
4952 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4953 timed_thread_unlock(info.mail->p_timed_thread);
4954 } else if (obj->data.mail) {
4955 // this means we use obj
4956 if (!obj->data.mail->p_timed_thread) {
4957 obj->data.mail->p_timed_thread =
4958 timed_thread_create(&imap_thread,
4959 (void *) obj->data.mail,
4960 obj->data.mail->interval * 1000000);
4961 if (!obj->data.mail->p_timed_thread) {
4962 ERR("Error creating imap timed thread");
4964 timed_thread_register(obj->data.mail->p_timed_thread,
4965 &obj->data.mail->p_timed_thread);
4966 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
4967 ERR("Error running imap timed thread");
4970 timed_thread_lock(obj->data.mail->p_timed_thread);
4971 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4972 timed_thread_unlock(obj->data.mail->p_timed_thread);
4973 } else if (!obj->a) {
4974 // something is wrong, warn once then stop
4975 ERR("Theres a problem with your imap_unseen settings. "
4976 "Check that the global IMAP settings are defined "
4977 "properly (line %li).", obj->line);
4981 OBJ(imap_messages) {
4982 if (obj->global_mode && info.mail) {
4983 // this means we use info
4984 if (!info.mail->p_timed_thread) {
4985 info.mail->p_timed_thread =
4986 timed_thread_create(&imap_thread,
4987 (void *) info.mail, info.mail->interval * 1000000);
4988 if (!info.mail->p_timed_thread) {
4989 ERR("Error creating imap timed thread");
4991 timed_thread_register(info.mail->p_timed_thread,
4992 &info.mail->p_timed_thread);
4993 if (timed_thread_run(info.mail->p_timed_thread)) {
4994 ERR("Error running imap timed thread");
4997 timed_thread_lock(info.mail->p_timed_thread);
4998 snprintf(p, p_max_size, "%lu", info.mail->messages);
4999 timed_thread_unlock(info.mail->p_timed_thread);
5000 } else if (obj->data.mail) {
5001 // this means we use obj
5002 if (!obj->data.mail->p_timed_thread) {
5003 obj->data.mail->p_timed_thread =
5004 timed_thread_create(&imap_thread,
5005 (void *) obj->data.mail,
5006 obj->data.mail->interval * 1000000);
5007 if (!obj->data.mail->p_timed_thread) {
5008 ERR("Error creating imap timed thread");
5010 timed_thread_register(obj->data.mail->p_timed_thread,
5011 &obj->data.mail->p_timed_thread);
5012 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
5013 ERR("Error runninging imap timed thread");
5016 timed_thread_lock(obj->data.mail->p_timed_thread);
5017 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
5018 timed_thread_lock(obj->data.mail->p_timed_thread);
5019 } else if (!obj->a) {
5020 // something is wrong, warn once then stop
5021 ERR("Theres a problem with your imap_messages settings. "
5022 "Check that the global IMAP settings are defined "
5023 "properly (line %li).", obj->line);
5028 if (obj->global_mode && info.mail) {
5029 // this means we use info
5030 if (!info.mail->p_timed_thread) {
5031 info.mail->p_timed_thread =
5032 timed_thread_create(&pop3_thread,
5033 (void *) info.mail, info.mail->interval * 1000000);
5034 if (!info.mail->p_timed_thread) {
5035 ERR("Error creating pop3 timed thread");
5037 timed_thread_register(info.mail->p_timed_thread,
5038 &info.mail->p_timed_thread);
5039 if (timed_thread_run(info.mail->p_timed_thread)) {
5040 ERR("Error running pop3 timed thread");
5043 timed_thread_lock(info.mail->p_timed_thread);
5044 snprintf(p, p_max_size, "%lu", info.mail->unseen);
5045 timed_thread_unlock(info.mail->p_timed_thread);
5046 } else if (obj->data.mail) {
5047 // this means we use obj
5048 if (!obj->data.mail->p_timed_thread) {
5049 obj->data.mail->p_timed_thread =
5050 timed_thread_create(&pop3_thread,
5051 (void *) obj->data.mail,
5052 obj->data.mail->interval * 1000000);
5053 if (!obj->data.mail->p_timed_thread) {
5054 ERR("Error creating pop3 timed thread");
5056 timed_thread_register(obj->data.mail->p_timed_thread,
5057 &obj->data.mail->p_timed_thread);
5058 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
5059 ERR("Error running pop3 timed thread");
5062 timed_thread_lock(obj->data.mail->p_timed_thread);
5063 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
5064 timed_thread_unlock(obj->data.mail->p_timed_thread);
5065 } else if (!obj->a) {
5066 // something is wrong, warn once then stop
5067 ERR("Theres a problem with your pop3_unseen settings. "
5068 "Check that the global POP3 settings are defined "
5069 "properly (line %li).", obj->line);
5074 if (obj->global_mode && info.mail) {
5075 // this means we use info
5076 if (!info.mail->p_timed_thread) {
5077 info.mail->p_timed_thread =
5078 timed_thread_create(&pop3_thread,
5079 (void *) info.mail, info.mail->interval * 1000000);
5080 if (!info.mail->p_timed_thread) {
5081 ERR("Error creating pop3 timed thread");
5083 timed_thread_register(info.mail->p_timed_thread,
5084 &info.mail->p_timed_thread);
5085 if (timed_thread_run(info.mail->p_timed_thread)) {
5086 ERR("Error running pop3 timed thread");
5089 timed_thread_lock(info.mail->p_timed_thread);
5090 snprintf(p, p_max_size, "%.1f",
5091 info.mail->used / 1024.0 / 1024.0);
5092 timed_thread_unlock(info.mail->p_timed_thread);
5093 } else if (obj->data.mail) {
5094 // this means we use obj
5095 if (!obj->data.mail->p_timed_thread) {
5096 obj->data.mail->p_timed_thread =
5097 timed_thread_create(&pop3_thread,
5098 (void *) obj->data.mail,
5099 obj->data.mail->interval * 1000000);
5100 if (!obj->data.mail->p_timed_thread) {
5101 ERR("Error creating pop3 timed thread");
5103 timed_thread_register(obj->data.mail->p_timed_thread,
5104 &obj->data.mail->p_timed_thread);
5105 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
5106 ERR("Error running pop3 timed thread");
5109 timed_thread_lock(obj->data.mail->p_timed_thread);
5110 snprintf(p, p_max_size, "%.1f",
5111 obj->data.mail->used / 1024.0 / 1024.0);
5112 timed_thread_unlock(obj->data.mail->p_timed_thread);
5113 } else if (!obj->a) {
5114 // something is wrong, warn once then stop
5115 ERR("Theres a problem with your pop3_used settings. "
5116 "Check that the global POP3 settings are defined "
5117 "properly (line %li).", obj->line);
5122 if (obj->data.fs != NULL) {
5123 if (obj->data.fs->size == 0) {
5124 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5126 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5127 (int) (255 - obj->data.fsbar.fs->avail * 255 /
5128 obj->data.fs->size));
5133 if (obj->data.fs != NULL) {
5134 human_readable(obj->data.fs->avail, p, 255, "fs_free");
5138 if (obj->data.fs != NULL) {
5139 if (obj->data.fs->size) {
5140 spaced_print(p, p_max_size, "%*d", 4, "fs_free_perc",
5141 pad_percents, (int) ((obj->data.fs->avail * 100) /
5142 obj->data.fs->size));
5144 snprintf(p, p_max_size, "0");
5149 if (obj->data.fs != NULL) {
5150 human_readable(obj->data.fs->size, p, 255, "fs_size");
5154 if (obj->data.fs != NULL)
5155 snprintf(p, p_max_size, "%s", obj->data.fs->type);
5158 if (obj->data.fs != NULL) {
5159 human_readable(obj->data.fs->size - (obj->data.fs->free
5160 ? obj->data.fs->free : obj->data.fs->avail), p, 255,
5165 if (obj->data.fs != NULL) {
5166 if (obj->data.fs->size == 0) {
5167 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5169 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5170 (int) (obj->data.fsbar.fs->avail * 255 /
5171 obj->data.fs->size));
5176 if (obj->data.fs != NULL) {
5177 if (obj->data.fs->size) {
5178 spaced_print(p, 4, "%*d", 4, "fs_used_perc",
5179 pad_percents, 100 - ((int) ((obj->data.fs->avail * 100) /
5180 obj->data.fs->size)));
5182 snprintf(p, p_max_size, "0");
5187 float *v = info.loadavg;
5189 if (obj->data.loadavg[2]) {
5190 snprintf(p, p_max_size, "%.2f %.2f %.2f",
5191 v[obj->data.loadavg[0] - 1],
5192 v[obj->data.loadavg[1] - 1],
5193 v[obj->data.loadavg[2] - 1]);
5194 } else if (obj->data.loadavg[1]) {
5195 snprintf(p, p_max_size, "%.2f %.2f",
5196 v[obj->data.loadavg[0] - 1],
5197 v[obj->data.loadavg[1] - 1]);
5198 } else if (obj->data.loadavg[0]) {
5199 snprintf(p, p_max_size, "%.2f",
5200 v[obj->data.loadavg[0] - 1]);
5204 new_goto(p, obj->data.i);
5207 new_tab(p, obj->data.pair.a, obj->data.pair.b);
5210 new_hr(p, obj->data.i);
5213 if (cur->nameserver_info.nscount > obj->data.i)
5214 snprintf(p, p_max_size, "%s",
5215 cur->nameserver_info.ns_list[obj->data.i]);
5219 PRSS *data = get_rss_info(obj->data.rss.uri,
5220 obj->data.rss.delay);
5224 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
5226 if (!strcmp(obj->data.rss.action, "feed_title")) {
5228 // remove trailing new line if one exists
5229 if (str[strlen(str) - 1] == '\n') {
5230 str[strlen(str) - 1] = 0;
5232 snprintf(p, p_max_size, "%s", str);
5233 } else if (!strcmp(obj->data.rss.action, "item_title")) {
5234 if (obj->data.rss.act_par < data->item_count) {
5235 str = data->items[obj->data.rss.act_par].title;
5236 // remove trailing new line if one exists
5237 if (str[strlen(str) - 1] == '\n') {
5238 str[strlen(str) - 1] = 0;
5240 snprintf(p, p_max_size, "%s", str);
5242 } else if (!strcmp(obj->data.rss.action, "item_desc")) {
5243 if (obj->data.rss.act_par < data->item_count) {
5245 data->items[obj->data.rss.act_par].description;
5246 // remove trailing new line if one exists
5247 if (str[strlen(str) - 1] == '\n') {
5248 str[strlen(str) - 1] = 0;
5250 snprintf(p, p_max_size, "%s", str);
5252 } else if (!strcmp(obj->data.rss.action, "item_titles")) {
5253 if (data->item_count > 0) {
5259 if (obj->data.rss.act_par > data->item_count) {
5260 show = data->item_count;
5262 show = obj->data.rss.act_par;
5264 for (itmp = 0; itmp < show; itmp++) {
5265 PRSS_Item *item = &data->items[itmp];
5269 // don't add new line before first item
5271 strncat(p, "\n", p_max_size);
5273 /* remove trailing new line if one exists,
5274 * we have our own */
5275 if (str[strlen(str) - 1] == '\n') {
5276 str[strlen(str) - 1] = 0;
5278 strncat(p, str, p_max_size);
5291 temp = get_hddtemp_info(obj->data.hddtemp.dev,
5292 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
5294 snprintf(p, p_max_size, "N/A");
5295 } else if (unit == '*') {
5296 snprintf(p, p_max_size, "%s", temp);
5298 snprintf(p, p_max_size, "%s%c", temp, unit);
5303 new_offset(p, obj->data.i);
5306 new_voffset(p, obj->data.i);
5312 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5313 obj->data.sysfs.devtype, obj->data.sysfs.type);
5315 if (r >= 100.0 || r == 0) {
5316 snprintf(p, p_max_size, "%d", (int) r);
5318 snprintf(p, p_max_size, "%.1f", r);
5324 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5325 obj->data.sysfs.devtype, obj->data.sysfs.type);
5327 if (r >= 100.0 || r == 0) {
5328 snprintf(p, p_max_size, "%d", (int) r);
5330 snprintf(p, p_max_size, "%.1f", r);
5336 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5337 obj->data.sysfs.devtype, obj->data.sysfs.type);
5339 if (r >= 100.0 || r == 0) {
5340 snprintf(p, p_max_size, "%d", (int) r);
5342 snprintf(p, p_max_size, "%.1f", r);
5345 #endif /* !__OpenBSD__ */
5347 new_alignr(p, obj->data.i);
5350 new_alignc(p, obj->data.i);
5353 struct text_object_list *text_objects;
5354 struct information *my_info =
5355 malloc(sizeof(struct information));
5356 memcpy(my_info, cur, sizeof(struct information));
5357 text_objects = parse_conky_vars(obj->data.ifblock.s, p, my_info);
5359 if (strlen(p) != 0) {
5360 i = obj->data.ifblock.pos;
5366 free_text_objects(text_objects->text_object_count, text_objects->text_objects);
5373 if ((obj->data.ifblock.s)
5374 && (stat(obj->data.ifblock.s, &tmp) == -1)) {
5375 i = obj->data.ifblock.pos;
5378 if (obj->data.ifblock.str) {
5379 if (!check_contains(obj->data.ifblock.s,
5380 obj->data.ifblock.str)) {
5381 i = obj->data.ifblock.pos;
5392 if ((obj->data.ifblock.s)
5393 && (!check_mount(obj->data.ifblock.s))) {
5394 i = obj->data.ifblock.pos;
5401 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
5402 i = obj->data.ifblock.pos;
5409 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
5412 snprintf(p, p_max_size, "%s", cur->uname_s.release);
5415 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
5420 human_readable(cur->mem * 1024, p, 255, "mem");
5423 human_readable(cur->memmax * 1024, p, 255, "memmax");
5427 spaced_print(p, p_max_size, "%*llu", 4, "memperc",
5428 pad_percents, cur->mem * 100 / cur->memmax);
5432 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5433 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
5436 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5437 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
5443 snprintf(p, p_max_size, "%d", mixer_get_avg(obj->data.l));
5446 snprintf(p, p_max_size, "%d", mixer_get_left(obj->data.l));
5449 snprintf(p, p_max_size, "%d", mixer_get_right(obj->data.l));
5452 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5453 mixer_get_avg(obj->data.mixerbar.l) * 255 / 100);
5456 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5457 mixer_get_left(obj->data.mixerbar.l) * 255 / 100);
5460 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5461 mixer_get_right(obj->data.mixerbar.l) * 255 / 100);
5466 update_mail_count(&obj->data.local_mail);
5467 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
5470 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
5472 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
5475 update_mail_count(&obj->data.local_mail);
5476 snprintf(p, p_max_size, "%d",
5477 obj->data.local_mail.new_mail_count);
5480 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
5483 new_outline(p, obj->data.l);
5486 spaced_print(p, p_max_size, "%hu", 5, "processes", cur->procs);
5488 OBJ(running_processes) {
5489 spaced_print(p, p_max_size, "%hu", 3, "running_processes", cur->run_procs);
5492 snprintf(p, p_max_size, "%s", obj->data.s);
5495 new_bg(p, obj->data.l);
5498 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
5501 human_readable(cur->swap * 1024, p, 255, "swap");
5504 human_readable(cur->swapmax * 1024, p, 255, "swapmax");
5507 if (cur->swapmax == 0) {
5508 strncpy(p, "No swap", p_max_size);
5510 spaced_print(p, p_max_size, "%*llu", 4, "swapperc",
5511 pad_percents, cur->swap * 100 / cur->swapmax);
5515 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5516 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
5519 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
5522 time_t t = time(NULL);
5523 struct tm *tm = localtime(&t);
5525 setlocale(LC_TIME, "");
5526 strftime(p, p_max_size, obj->data.s, tm);
5529 time_t t = time(NULL);
5530 struct tm *tm = gmtime(&t);
5532 strftime(p, p_max_size, obj->data.s, tm);
5539 if (obj->data.tztime.tz) {
5540 oldTZ = getenv("TZ");
5541 setenv("TZ", obj->data.tztime.tz, 1);
5547 setlocale(LC_TIME, "");
5548 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
5550 setenv("TZ", oldTZ, 1);
5555 // Needless to free oldTZ since getenv gives ptr to static data
5558 human_readable(obj->data.net->recv, p, 255, "totaldown");
5561 human_readable(obj->data.net->trans, p, 255, "totalup");
5564 snprintf(p, p_max_size, "%d", total_updates);
5567 spaced_print(p, p_max_size, "%d", 6, "upspeed",
5568 round_to_int(obj->data.net->trans_speed / 1024));
5571 spaced_print(p, p_max_size, "%.1f", 8, "upspeedf",
5572 obj->data.net->trans_speed / 1024.0);
5575 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5576 obj->data.net->trans_speed / 1024.0, obj->e, 1);
5579 format_seconds_short(p, p_max_size, (int) cur->uptime);
5582 format_seconds(p, p_max_size, (int) cur->uptime);
5585 snprintf(p, p_max_size, "%s", cur->users.names);
5588 snprintf(p, p_max_size, "%s", cur->users.terms);
5591 snprintf(p, p_max_size, "%s", cur->users.times);
5594 snprintf(p, p_max_size, "%d", cur->users.number);
5596 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
5597 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5601 msg = get_apm_adapter();
5602 snprintf(p, p_max_size, "%s", msg);
5605 OBJ(apm_battery_life) {
5608 msg = get_apm_battery_life();
5609 snprintf(p, p_max_size, "%s", msg);
5612 OBJ(apm_battery_time) {
5615 msg = get_apm_battery_time();
5616 snprintf(p, p_max_size, "%s", msg);
5619 #endif /* __FreeBSD__ __OpenBSD__ */
5623 snprintf(p, cur->mpd.max_title_len > 0
5624 ? cur->mpd.max_title_len : p_max_size, "%s",
5628 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5631 snprintf(p, p_max_size, "%s", cur->mpd.album);
5634 snprintf(p, p_max_size, "%s", cur->mpd.random);
5637 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
5640 snprintf(p, p_max_size, "%s", cur->mpd.track);
5643 snprintf(p, p_max_size, "%s", cur->mpd.name);
5646 snprintf(p, p_max_size, "%s", cur->mpd.file);
5649 snprintf(p, p_max_size, "%i", cur->mpd.volume);
5652 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
5655 snprintf(p, p_max_size, "%s", cur->mpd.status);
5658 int days = 0, hours = 0, minutes = 0, seconds = 0;
5659 int tmp = cur->mpd.elapsed;
5661 while (tmp >= 86400) {
5665 while (tmp >= 3600) {
5675 snprintf(p, p_max_size, "%i days %i:%02i:%02i", days,
5676 hours, minutes, seconds);
5677 } else if (hours > 0) {
5678 snprintf(p, p_max_size, "%i:%02i:%02i", hours, minutes,
5681 snprintf(p, p_max_size, "%i:%02i", minutes, seconds);
5685 int days = 0, hours = 0, minutes = 0, seconds = 0;
5686 int tmp = cur->mpd.length;
5688 while (tmp >= 86400) {
5692 while (tmp >= 3600) {
5702 snprintf(p, p_max_size, "%i days %i:%02i:%02i", days,
5703 hours, minutes, seconds);
5704 } else if (hours > 0) {
5705 snprintf(p, p_max_size, "%i:%02i:%02i", hours, minutes,
5708 snprintf(p, p_max_size, "%i:%02i", minutes, seconds);
5712 spaced_print(p, p_max_size, "%*d", 4, "mpd_percent",
5713 pad_percents, (int) (cur->mpd.progress * 100));
5716 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5717 (int) (cur->mpd.progress * 255.0f));
5720 memset(p, 0, p_max_size);
5721 if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title
5722 && *cur->mpd.title) {
5723 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist,
5725 } else if (cur->mpd.title && *cur->mpd.title) {
5726 snprintf(p, p_max_size, "%s", cur->mpd.title);
5727 } else if (cur->mpd.artist && *cur->mpd.artist) {
5728 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5729 } else if (cur->mpd.file && *cur->mpd.file) {
5730 snprintf(p, p_max_size, "%s", cur->mpd.file);
5739 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5742 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5745 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5748 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5750 OBJ(xmms2_comment) {
5751 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5754 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5757 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5760 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5762 OBJ(xmms2_tracknr) {
5763 if (cur->xmms2.tracknr != -1) {
5764 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5767 OBJ(xmms2_bitrate) {
5768 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5771 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5774 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5776 OBJ(xmms2_elapsed) {
5777 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5778 (cur->xmms2.elapsed / 1000) % 60);
5780 OBJ(xmms2_duration) {
5781 snprintf(p, p_max_size, "%02d:%02d",
5782 cur->xmms2.duration / 60000,
5783 (cur->xmms2.duration / 1000) % 60);
5785 OBJ(xmms2_percent) {
5786 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5789 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5790 (int) (cur->xmms2.progress * 255.0f));
5792 OBJ(xmms2_playlist) {
5793 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5795 OBJ(xmms2_timesplayed) {
5796 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5799 if (strlen(cur->xmms2.title) < 2
5800 && strlen(cur->xmms2.title) < 2) {
5801 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5803 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5809 OBJ(audacious_status) {
5810 snprintf(p, p_max_size, "%s",
5811 cur->audacious.items[AUDACIOUS_STATUS]);
5813 OBJ(audacious_title) {
5814 snprintf(p, cur->audacious.max_title_len > 0
5815 ? cur->audacious.max_title_len : p_max_size, "%s",
5816 cur->audacious.items[AUDACIOUS_TITLE]);
5818 OBJ(audacious_length) {
5819 snprintf(p, p_max_size, "%s",
5820 cur->audacious.items[AUDACIOUS_LENGTH]);
5822 OBJ(audacious_length_seconds) {
5823 snprintf(p, p_max_size, "%s",
5824 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5826 OBJ(audacious_position) {
5827 snprintf(p, p_max_size, "%s",
5828 cur->audacious.items[AUDACIOUS_POSITION]);
5830 OBJ(audacious_position_seconds) {
5831 snprintf(p, p_max_size, "%s",
5832 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5834 OBJ(audacious_bitrate) {
5835 snprintf(p, p_max_size, "%s",
5836 cur->audacious.items[AUDACIOUS_BITRATE]);
5838 OBJ(audacious_frequency) {
5839 snprintf(p, p_max_size, "%s",
5840 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5842 OBJ(audacious_channels) {
5843 snprintf(p, p_max_size, "%s",
5844 cur->audacious.items[AUDACIOUS_CHANNELS]);
5846 OBJ(audacious_filename) {
5847 snprintf(p, p_max_size, "%s",
5848 cur->audacious.items[AUDACIOUS_FILENAME]);
5850 OBJ(audacious_playlist_length) {
5851 snprintf(p, p_max_size, "%s",
5852 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5854 OBJ(audacious_playlist_position) {
5855 snprintf(p, p_max_size, "%s",
5856 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5858 OBJ(audacious_bar) {
5862 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5863 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5864 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5870 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5873 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5876 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5879 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5882 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5885 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5889 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
5892 switch (obj->data.top.type) {
5894 snprintf(p, 16, "%-15s",
5895 cur->cpu[obj->data.top.num]->name);
5898 snprintf(p, 7, "%6.2f",
5899 cur->cpu[obj->data.top.num]->amount);
5902 snprintf(p, 6, "%5i",
5903 cur->cpu[obj->data.top.num]->pid);
5906 snprintf(p, 7, "%6.2f",
5907 cur->cpu[obj->data.top.num]->totalmem);
5910 timeval = format_time(
5911 cur->cpu[obj->data.top.num]->total_cpu_time, 9);
5912 snprintf(p, 10, "%9s", timeval);
5916 human_readable(cur->cpu[obj->data.top.num]->rss,
5920 human_readable(cur->cpu[obj->data.top.num]->vsize,
5924 ERR("Unhandled top data type: %d\n",
5925 obj->data.top.type);
5928 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
5932 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
5935 switch (obj->data.top.type) {
5937 snprintf(p, 16, "%-15s",
5938 cur->memu[obj->data.top.num]->name);
5941 snprintf(p, 7, "%6.2f",
5942 cur->memu[obj->data.top.num]->amount);
5945 snprintf(p, 6, "%5i",
5946 cur->memu[obj->data.top.num]->pid);
5949 snprintf(p, 7, "%6.2f",
5950 cur->memu[obj->data.top.num]->totalmem);
5953 timeval = format_time(
5954 cur->memu[obj->data.top.num]->total_cpu_time,
5956 snprintf(p, 10, "%9s", timeval);
5960 human_readable(cur->cpu[obj->data.top.num]->rss,
5964 human_readable(cur->cpu[obj->data.top.num]->vsize,
5968 ERR("Unhandled top data type: %d\n",
5969 obj->data.top.type);
5972 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
5976 if (current_update_time - obj->data.tail.last_update
5977 < obj->data.tail.interval) {
5978 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5984 obj->data.tail.last_update = current_update_time;
5986 if (obj->data.tail.fd != -1) {
5987 tail_pipe(obj, p, p_max_size);
5991 fp = fopen(obj->data.tail.logfile, "rt");
5994 /* Send one message, but do not consistently spam
5995 * on missing logfiles. */
5996 if (obj->data.tail.readlines != 0) {
5997 ERR("tail logfile failed to open");
5998 strcpy(obj->data.tail.buffer, "Logfile Missing");
6000 obj->data.tail.readlines = 0;
6001 snprintf(p, p_max_size, "Logfile Missing");
6003 obj->data.tail.readlines = 0;
6004 /* -1 instead of 0 to avoid counting a trailing
6006 fseek(fp, -1, SEEK_END);
6007 bsize = ftell(fp) + 1;
6008 for (iter = obj->data.tail.wantedlines; iter > 0;
6010 nl = rev_fcharfind(fp, '\n', iter);
6015 obj->data.tail.readlines = iter;
6016 if (obj->data.tail.readlines
6017 < obj->data.tail.wantedlines) {
6018 fseek(fp, 0, SEEK_SET);
6020 fseek(fp, nl + 1, SEEK_SET);
6023 /* Make sure bsize is at least 1 byte smaller than the
6024 * buffer max size. */
6025 if (bsize > (long) ((text_buffer_size * 20) - 1)) {
6026 fseek(fp, bsize - text_buffer_size * 20 - 1,
6028 bsize = text_buffer_size * 20 - 1;
6030 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
6033 /* Clean up trailing newline, make sure the
6034 * buffer is null terminated. */
6035 if (obj->data.tail.buffer[bsize - 1] == '\n') {
6036 obj->data.tail.buffer[bsize - 1] = '\0';
6038 obj->data.tail.buffer[bsize] = '\0';
6040 snprintf(p, p_max_size, "%s",
6041 obj->data.tail.buffer);
6043 strcpy(obj->data.tail.buffer, "Logfile Empty");
6044 snprintf(p, p_max_size, "Logfile Empty");
6047 } /* if cur_upd_time >= */
6048 // parse_conky_vars(obj->data.tail.buffer, p, cur);
6052 if (current_update_time - obj->data.tail.last_update
6053 < obj->data.tail.interval) {
6054 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
6060 obj->data.tail.last_update = current_update_time;
6062 fp = fopen(obj->data.tail.logfile, "rt");
6064 /* Send one message, but do not consistently spam
6065 * on missing logfiles. */
6066 if (obj->data.tail.readlines != 0) {
6067 ERR("head logfile failed to open");
6068 strcpy(obj->data.tail.buffer, "Logfile Missing");
6070 obj->data.tail.readlines = 0;
6071 snprintf(p, p_max_size, "Logfile Missing");
6073 obj->data.tail.readlines = 0;
6074 for (iter = obj->data.tail.wantedlines; iter > 0;
6076 nl = fwd_fcharfind(fp, '\n', iter);
6081 obj->data.tail.readlines = iter;
6082 /* Make sure nl is at least 1 byte smaller than the
6083 * buffer max size. */
6084 if (nl > (long) ((text_buffer_size * 20) - 1)) {
6085 nl = text_buffer_size * 20 - 1;
6087 nl = fread(obj->data.tail.buffer, 1, nl, fp);
6090 /* Clean up trailing newline, make sure the buffer
6091 * is null terminated. */
6092 if (obj->data.tail.buffer[nl - 1] == '\n') {
6093 obj->data.tail.buffer[nl - 1] = '\0';
6095 obj->data.tail.buffer[nl] = '\0';
6097 snprintf(p, p_max_size, "%s",
6098 obj->data.tail.buffer);
6100 strcpy(obj->data.tail.buffer, "Logfile Empty");
6101 snprintf(p, p_max_size, "Logfile Empty");
6103 } /* if fp == null */
6104 } /* cur_upd_time >= */
6105 // parse_conky_vars(obj->data.tail.buffer, p, cur);
6108 #ifdef TCP_PORT_MONITOR
6110 /* grab a pointer to this port monitor */
6111 tcp_port_monitor_t *p_monitor =
6112 find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
6113 obj->data.tcp_port_monitor.port_range_begin,
6114 obj->data.tcp_port_monitor.port_range_end);
6117 snprintf(p, p_max_size, "monitor not found");
6121 /* now grab the text of interest */
6122 if (peek_tcp_port_monitor(p_monitor,
6123 obj->data.tcp_port_monitor.item,
6124 obj->data.tcp_port_monitor.connection_index, p,
6126 snprintf(p, p_max_size, "monitor peek error");
6134 iconv_converting = 1;
6135 iconv_selected = obj->a;
6138 iconv_converting = 0;
6143 OBJ(entropy_avail) {
6144 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
6146 OBJ(entropy_poolsize) {
6147 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
6150 double entropy_perc;
6152 entropy_perc = (double) cur->entropy.entropy_avail /
6153 (double) cur->entropy.poolsize;
6154 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
6160 s = smapi_get_val(obj->data.s);
6161 snprintf(p, p_max_size, "%s", s);
6165 OBJ(if_smapi_bat_installed) {
6167 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
6168 if(!smapi_bat_installed(idx)) {
6169 i = obj->data.ifblock.pos;
6174 ERR("argument to if_smapi_bat_installed must be an integer");
6176 OBJ(smapi_bat_perc) {
6178 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
6179 val = smapi_bat_installed(idx) ?
6180 smapi_get_bat_int(idx, "remaining_percent") : 0;
6181 spaced_print(p, p_max_size, "%*d", 4, "smapi_bat_perc", pad_percents, val);
6183 ERR("argument to smapi_bat_perc must be an integer");
6185 OBJ(smapi_bat_bar) {
6186 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
6187 new_bar(p, obj->a, obj->b, (int)
6188 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
6190 new_bar(p, obj->a, obj->b, 0);
6198 unsigned int a = strlen(p);
6201 if (a > 0 && iconv_converting && iconv_selected > 0
6202 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
6204 size_t dummy1, dummy2;
6205 char *ptr = buff_in;
6208 dummy1 = dummy2 = a;
6210 strncpy(buff_in, p, p_max_size);
6212 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
6213 while (dummy1 > 0) {
6214 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
6217 ERR("Iconv codeset conversion failed");
6222 /* It is nessecary when we are converting from multibyte to
6223 * singlebyte codepage */
6226 #endif /* HAVE_ICONV */
6233 double current_update_time, last_update_time;
6235 static void generate_text(void)
6237 struct information *cur = &info;
6244 current_update_time = get_time();
6247 /* fix diskio rates to b/s (use update_interval */
6248 diskio_read_value = diskio_read_value / update_interval;
6249 diskio_write_value = diskio_write_value / update_interval;
6250 diskio_value = diskio_value / update_interval;
6252 /* add things to the buffer */
6258 generate_text_internal(p, max_user_text, global_text_objects,
6259 global_text_object_count, cur);
6261 if (stuff_in_upper_case) {
6264 tmp_p = text_buffer;
6266 *tmp_p = toupper(*tmp_p);
6271 last_update_time = current_update_time;
6277 static void set_font(void)
6281 if (window.xftdraw != NULL) {
6282 XftDrawDestroy(window.xftdraw);
6284 window.xftdraw = XftDrawCreate(display, window.drawable,
6285 DefaultVisual(display, screen), DefaultColormap(display, screen));
6289 XSetFont(display, window.gc, fonts[selected_font].font->fid);
6295 static inline int get_string_width(const char *s)
6298 return *s ? calc_text_width(s, strlen(s)) : 0;
6304 static inline int get_string_width_special(char *s)
6316 p = strndup(s, text_buffer_size);
6320 if (*p == SPECIAL_CHAR) {
6321 /* shift everything over by 1 so that the special char
6322 * doesn't mess up the size calculation */
6323 for (i = 0; i < strlen(p); i++) {
6324 *(p + i) = *(p + i + 1);
6326 if (specials[special_index + idx].type == GRAPH
6327 || specials[special_index + idx].type == BAR) {
6328 width += specials[special_index + idx].width;
6335 if (strlen(final) > 1) {
6336 width += calc_text_width(final, strlen(final));
6341 return (s) ? strlen(s) : 0;
6346 static void text_size_updater(char *s);
6348 int last_font_height;
6349 static void update_text_area(void)
6353 /* update text size if it isn't fixed */
6358 text_width = minimum_width;
6361 last_font_height = font_height();
6362 for_each_line(text_buffer, text_size_updater);
6364 if (text_height < minimum_height) {
6365 text_height = minimum_height;
6367 if (text_width > maximum_width && maximum_width > 0) {
6368 text_width = maximum_width;
6372 /* get text position on workarea */
6373 switch (text_alignment) {
6380 x = workarea[2] - text_width - gap_x;
6385 x = workarea[2] / 2 - text_width / 2 - gap_x;
6392 y = workarea[3] - text_height - gap_y;
6396 x = workarea[2] - text_width - gap_x;
6397 y = workarea[3] - text_height - gap_y;
6401 x = workarea[2] / 2 - text_width / 2 - gap_x;
6402 y = workarea[3] - text_height - gap_y;
6407 y = workarea[3] / 2 - text_height / 2 - gap_y;
6411 x = workarea[2] - text_width - gap_x;
6412 y = workarea[3] / 2 - text_height / 2 - gap_y;
6416 case NONE: // Let the WM manage the window
6427 if (own_window && !fixed_pos) {
6430 text_start_x = border_margin + 1;
6431 text_start_y = border_margin + 1;
6432 window.x = x - border_margin - 1;
6433 window.y = y - border_margin - 1;
6437 /* If window size doesn't match to workarea's size,
6438 * then window probably includes panels (gnome).
6439 * Blah, doesn't work on KDE. */
6440 if (workarea[2] != window.width || workarea[3] != window.height) {
6452 static int cur_x, cur_y; /* current x and y for drawing */
6453 static int draw_mode; /* FG, BG or OUTLINE */
6454 static long current_color;
6457 static void text_size_updater(char *s)
6462 /* get string widths and skip specials */
6465 if (*p == SPECIAL_CHAR) {
6467 w += get_string_width(s);
6470 if (specials[special_index].type == BAR
6471 || specials[special_index].type == GRAPH) {
6472 w += specials[special_index].width;
6473 if (specials[special_index].height > last_font_height) {
6474 last_font_height = specials[special_index].height;
6475 last_font_height += font_ascent();
6477 } else if (specials[special_index].type == OFFSET) {
6478 if (specials[special_index].arg > 0) {
6479 w += specials[special_index].arg;
6481 } else if (specials[special_index].type == VOFFSET) {
6482 last_font_height += specials[special_index].arg;
6483 } else if (specials[special_index].type == GOTO) {
6484 if (specials[special_index].arg > cur_x) {
6485 w = (int) specials[special_index].arg;
6487 } else if (specials[special_index].type == TAB) {
6488 int start = specials[special_index].arg;
6489 int step = specials[special_index].width;
6491 if (!step || step < 0) {
6494 w += step - (cur_x - text_start_x - start) % step;
6495 } else if (specials[special_index].type == FONT) {
6496 selected_font = specials[special_index].font_added;
6497 if (font_height() > last_font_height) {
6498 last_font_height = font_height();
6507 w += get_string_width(s);
6508 if (w > text_width) {
6511 if (text_width > maximum_width && maximum_width) {
6512 text_width = maximum_width;
6515 text_height += last_font_height;
6516 last_font_height = font_height();
6520 static inline void set_foreground_color(long c)
6523 XSetForeground(display, window.gc, c);
6527 static void draw_string(const char *s)
6529 int i, i2, pos, width_of_s;
6538 width_of_s = get_string_width(s);
6539 if (out_to_console) {
6541 fflush(stdout); /* output immediately, don't buffer */
6543 memset(tmpstring1, 0, text_buffer_size);
6544 memset(tmpstring2, 0, text_buffer_size);
6545 strncpy(tmpstring1, s, text_buffer_size - 1);
6549 snprintf(space, 2, " ");
6551 max = ((text_width - width_of_s) / get_string_width(space));
6553 /* This code looks for tabs in the text and coverts them to spaces.
6554 * The trick is getting the correct number of spaces, and not going
6555 * over the window's size without forcing the window larger. */
6556 for (i = 0; i < (int)text_buffer_size; i++) {
6557 if (tmpstring1[i] == '\t') { // 9 is ascii tab
6559 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
6560 /* guard against overrun */
6561 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
6566 if (tmpstring1[i] != 9) {
6567 /* guard against overrun */
6568 tmpstring2[MIN(pos, (int)text_buffer_size - 1)] = tmpstring1[i];
6574 if (text_width == maximum_width) {
6575 /* this means the text is probably pushing the limit,
6576 * so we'll chop it */
6577 while (cur_x + get_string_width(tmpstring2) - text_start_x
6578 > maximum_width && strlen(tmpstring2) > 0) {
6579 tmpstring2[strlen(tmpstring2) - 1] = '\0';
6590 c.pixel = current_color;
6591 XQueryColor(display, DefaultColormap(display, screen), &c);
6594 c2.color.red = c.red;
6595 c2.color.green = c.green;
6596 c2.color.blue = c.blue;
6597 c2.color.alpha = fonts[selected_font].font_alpha;
6599 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6600 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6602 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6603 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6608 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
6611 cur_x += width_of_s;
6613 memcpy(tmpstring1, s, text_buffer_size);
6616 long redmask, greenmask, bluemask;
6618 void set_up_gradient(void)
6622 colour_depth = DisplayPlanes(display, screen);
6626 if (colour_depth != 24 && colour_depth != 16) {
6627 ERR("using non-standard colour depth, gradients may look like a "
6634 for (i = (colour_depth / 3) - 1; i >= 0; i--) {
6636 greenmask |= 1 << i;
6639 if (colour_depth % 3 == 1) {
6640 greenmask |= 1 << (colour_depth / 3);
6642 redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
6643 greenmask = greenmask << (colour_depth / 3);
6646 /* this function returns the next colour between two colours for a gradient */
6647 inline unsigned long do_gradient(unsigned long first_colour,
6648 unsigned long last_colour)
6651 int red1, green1, blue1; // first colour
6652 int red2, green2, blue2; // second colour
6653 int red3 = 0, green3 = 0, blue3 = 0; // difference
6654 short redshift = (2 * colour_depth / 3 + colour_depth % 3);
6655 short greenshift = (colour_depth / 3);
6657 red1 = (first_colour & redmask) >> redshift;
6658 green1 = (first_colour & greenmask) >> greenshift;
6659 blue1 = first_colour & bluemask;
6660 red2 = (last_colour & redmask) >> redshift;
6661 green2 = (last_colour & greenmask) >> greenshift;
6662 blue2 = last_colour & bluemask;
6669 if (green1 > green2) {
6672 if (green1 < green2) {
6675 if (blue1 > blue2) {
6678 if (blue1 < blue2) {
6693 if (red1 > bluemask) {
6696 if (green1 > bluemask) {
6699 if (blue1 > bluemask) {
6702 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
6706 /* this function returns the max diff for a gradient */
6707 inline unsigned long gradient_max(unsigned long first_colour,
6708 unsigned long last_colour)
6710 int red1, green1, blue1; // first colour
6711 int red2, green2, blue2; // second colour
6712 int red3 = 0, green3 = 0, blue3 = 0; // difference
6713 long redshift, greenshift;
6716 if (colour_depth == 0) {
6719 redshift = (2 * colour_depth / 3 + colour_depth % 3);
6720 greenshift = (colour_depth / 3);
6722 red1 = (first_colour & redmask) >> redshift;
6723 green1 = (first_colour & greenmask) >> greenshift;
6724 blue1 = first_colour & bluemask;
6725 red2 = (last_colour & redmask) >> redshift;
6726 green2 = (last_colour & greenmask) >> greenshift;
6727 blue2 = last_colour & bluemask;
6728 red3 = abs(red1 - red2);
6729 green3 = abs(green1 - green2);
6730 blue3 = abs(blue1 - blue2);
6742 static void draw_line(char *s)
6749 cur_x = text_start_x;
6750 cur_y += font_ascent();
6751 font_h = font_height();
6753 /* find specials and draw stuff */
6756 if (*p == SPECIAL_CHAR) {
6759 /* draw string before special */
6766 switch (specials[special_index].type) {
6767 case HORIZONTAL_LINE:
6769 int h = specials[special_index].height;
6770 int mid = font_ascent() / 2;
6772 w = text_start_x + text_width - cur_x;
6774 XSetLineAttributes(display, window.gc, h, LineSolid,
6775 CapButt, JoinMiter);
6776 XDrawLine(display, window.drawable, window.gc, cur_x,
6777 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6783 int h = specials[special_index].height;
6784 int tmp_s = specials[special_index].arg;
6785 int mid = font_ascent() / 2;
6786 char ss[2] = { tmp_s, tmp_s };
6788 w = text_start_x + text_width - cur_x - 1;
6789 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6790 CapButt, JoinMiter);
6791 XSetDashes(display, window.gc, 0, ss, 2);
6792 XDrawLine(display, window.drawable, window.gc, cur_x,
6793 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6799 int h, bar_usage, by;
6800 if (cur_x - text_start_x > maximum_width
6801 && maximum_width > 0) {
6804 h = specials[special_index].height;
6805 bar_usage = specials[special_index].arg;
6806 by = cur_y - (font_ascent() / 2) - 1;
6808 if (h < font_height()) {
6811 w = specials[special_index].width;
6813 w = text_start_x + text_width - cur_x - 1;
6819 XSetLineAttributes(display, window.gc, 1, LineSolid,
6820 CapButt, JoinMiter);
6822 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6824 XFillRectangle(display, window.drawable, window.gc, cur_x,
6825 by, w * bar_usage / 255, h);
6826 if (specials[special_index].height > cur_y_add
6827 && specials[special_index].height > font_h) {
6828 cur_y_add = specials[special_index].height;
6835 int h, by, i, j = 0;
6836 int gradient_size = 0;
6837 float gradient_factor = 0;
6838 float gradient_update = 0;
6839 unsigned long last_colour = current_color;
6840 unsigned long tmpcolour = current_color;
6841 if (cur_x - text_start_x > maximum_width
6842 && maximum_width > 0) {
6845 h = specials[special_index].height;
6846 by = cur_y - (font_ascent() / 2) - 1;
6848 if (h < font_height()) {
6851 w = specials[special_index].width;
6853 w = text_start_x + text_width - cur_x - 1;
6858 if (draw_graph_borders) {
6859 XSetLineAttributes(display, window.gc, 1, LineSolid,
6860 CapButt, JoinMiter);
6861 XDrawRectangle(display, window.drawable, window.gc,
6864 XSetLineAttributes(display, window.gc, 1, LineSolid,
6865 CapButt, JoinMiter);
6867 if (specials[special_index].last_colour != 0
6868 || specials[special_index].first_colour != 0) {
6869 tmpcolour = specials[special_index].last_colour;
6871 gradient_max(specials[special_index].last_colour,
6872 specials[special_index].first_colour);
6873 gradient_factor = (float) gradient_size / (w - 2);
6875 for (i = w - 2; i > -1; i--) {
6876 if (specials[special_index].last_colour != 0
6877 || specials[special_index].first_colour != 0) {
6878 XSetForeground(display, window.gc, tmpcolour);
6879 gradient_update += gradient_factor;
6880 while (gradient_update > 0) {
6881 tmpcolour = do_gradient(tmpcolour,
6882 specials[special_index].first_colour);
6886 if ((w - i) / ((float) (w - 2) /
6887 (specials[special_index].graph_width)) > j
6888 && j < MAX_GRAPH_DEPTH - 3) {
6891 /* this is mugfugly, but it works */
6892 XDrawLine(display, window.drawable, window.gc,
6893 cur_x + i + 1, by + h, cur_x + i + 1,
6894 by + h - specials[special_index].graph[j] *
6895 (h - 1) / specials[special_index].graph_scale);
6897 if (specials[special_index].height > cur_y_add
6898 && specials[special_index].height > font_h) {
6899 cur_y_add = specials[special_index].height;
6901 /* if (draw_mode == BG) {
6902 set_foreground_color(default_bg_color);
6903 } else if (draw_mode == OUTLINE) {
6904 set_foreground_color(default_out_color);
6906 set_foreground_color(default_fg_color);
6908 set_foreground_color(last_colour);
6914 int old = font_ascent();
6916 cur_y -= font_ascent();
6917 selected_font = specials[special_index].font_added;
6918 if (cur_y + font_ascent() < cur_y + old) {
6921 cur_y += font_ascent();
6927 if (draw_mode == FG) {
6928 set_foreground_color(specials[special_index].arg);
6933 if (draw_mode == BG) {
6934 set_foreground_color(specials[special_index].arg);
6939 if (draw_mode == OUTLINE) {
6940 set_foreground_color(specials[special_index].arg);
6945 w += specials[special_index].arg;
6949 cur_y += specials[special_index].arg;
6953 if (specials[special_index].arg >= 0) {
6954 cur_x = (int) specials[special_index].arg;
6960 int start = specials[special_index].arg;
6961 int step = specials[special_index].width;
6963 if (!step || step < 0) {
6966 w = step - (cur_x - text_start_x - start) % step;
6972 /* TODO: add back in "+ border_margin" to the end of
6974 int pos_x = text_start_x + text_width -
6975 get_string_width_special(s);
6977 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6978 "get_string_width(p) %i gap_x %i "
6979 "specials[special_index].arg %i border_margin %i "
6980 "border_width %i\n", pos_x, text_start_x, text_width,
6981 cur_x, get_string_width_special(s), gap_x,
6982 specials[special_index].arg, border_margin,
6984 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6985 cur_x = pos_x - specials[special_index].arg;
6992 int pos_x = (text_width) / 2 - get_string_width_special(s) /
6993 2 - (cur_x - text_start_x);
6994 /* int pos_x = text_start_x + text_width / 2 -
6995 get_string_width_special(s) / 2; */
6997 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6998 "get_string_width(p) %i gap_x %i "
6999 "specials[special_index].arg %i\n", pos_x, text_start_x,
7000 text_width, cur_x, get_string_width(s), gap_x,
7001 specials[special_index].arg); */
7002 if (pos_x > specials[special_index].arg) {
7003 w = pos_x - specials[special_index].arg;
7020 if (cur_y_add > 0) {
7022 cur_y -= font_descent();
7027 cur_y += font_descent();
7031 static void draw_text(void)
7034 cur_y = text_start_y;
7037 if (draw_borders && border_width > 0) {
7038 unsigned int b = (border_width + 1) / 2;
7040 if (stippled_borders) {
7041 char ss[2] = { stippled_borders, stippled_borders };
7042 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
7043 CapButt, JoinMiter);
7044 XSetDashes(display, window.gc, 0, ss, 2);
7046 XSetLineAttributes(display, window.gc, border_width, LineSolid,
7047 CapButt, JoinMiter);
7050 XDrawRectangle(display, window.drawable, window.gc,
7051 text_start_x - border_margin + b, text_start_y - border_margin + b,
7052 text_width + border_margin * 2 - 1 - b * 2,
7053 text_height + border_margin * 2 - 1 - b * 2);
7059 for_each_line(text_buffer, draw_line);
7062 static void draw_stuff(void)
7066 if (draw_shades && !draw_outline) {
7069 set_foreground_color(default_bg_color);
7080 for (i = -1; i < 2; i++) {
7081 for (j = -1; j < 2; j++) {
7082 if (i == 0 && j == 0) {
7087 set_foreground_color(default_out_color);
7088 draw_mode = OUTLINE;
7096 set_foreground_color(default_fg_color);
7105 swap.swap_window = window.window;
7106 swap.swap_action = XdbeBackground;
7107 XdbeSwapBuffers(display, &swap, 1);
7114 static void clear_text(int exposures)
7118 /* The swap action is XdbeBackground, which clears */
7123 /* there is some extra space for borders and outlines */
7124 XClearArea(display, window.window, text_start_x - border_margin - 1,
7125 text_start_y - border_margin - 1,
7126 text_width + border_margin * 2 + 2,
7127 text_height + border_margin * 2 + 2, exposures ? True : 0);
7132 static int need_to_update;
7134 /* update_text() generates new text and clears old text area */
7135 static void update_text(void)
7144 static void main_loop(void)
7146 #ifdef SIGNAL_BLOCKING
7147 sigset_t newmask, oldmask;
7150 Region region = XCreateRegion();
7154 XserverRegion region2, part;
7155 int event_base, error_base;
7157 if (!XDamageQueryExtension(display, &event_base, &error_base)) {
7158 ERR("Xdamage extension unavailable");
7160 damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7161 region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7162 part = XFixesCreateRegionFromWindow(display, window.window, 0);
7163 #endif /* HAVE_XDAMAGE */
7166 #ifdef SIGNAL_BLOCKING
7167 sigemptyset(&newmask);
7168 sigaddset(&newmask, SIGINT);
7169 sigaddset(&newmask, SIGTERM);
7170 sigaddset(&newmask, SIGUSR1);
7174 while (total_run_times == 0 || info.looped < total_run_times) {
7177 #ifdef SIGNAL_BLOCKING
7178 /* block signals. we will inspect for pending signals later */
7179 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
7180 CRIT_ERR("unable to sigprocmask()");
7187 /* wait for X event or timeout */
7189 if (!XPending(display)) {
7193 double t = update_interval - (get_time() - last_update_time);
7199 tv.tv_sec = (long) t;
7200 tv.tv_usec = (long) (t * 1000000) % 1000000;
7202 FD_SET(ConnectionNumber(display), &fdsr);
7204 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
7206 if (errno != EINTR) {
7207 ERR("can't select(): %s", strerror(errno));
7213 /* FIXME just sleep for the interval time if no X11 */
7214 usleep(update_interval * 1000000);
7222 if (need_to_update) {
7224 int wx = window.x, wy = window.y;
7232 /* resize window if it isn't right size */
7234 && (text_width + border_margin * 2 + 1 != window.width
7235 || text_height + border_margin * 2 + 1 != window.height)) {
7236 window.width = text_width + border_margin * 2 + 1;
7237 window.height = text_height + border_margin * 2 + 1;
7238 XResizeWindow(display, window.window, window.width,
7241 set_transparent_background(window.window);
7245 /* move window if it isn't in right position */
7246 if (!fixed_pos && (window.x != wx || window.y != wy)) {
7247 XMoveWindow(display, window.window, window.x, window.y);
7258 r.x = text_start_x - border_margin;
7259 r.y = text_start_y - border_margin;
7260 r.width = text_width + border_margin * 2;
7261 r.height = text_height + border_margin * 2;
7262 XUnionRectWithRegion(&r, region, region);
7267 /* handle X events */
7268 while (XPending(display)) {
7271 XNextEvent(display, &ev);
7279 r.width = ev.xexpose.width;
7280 r.height = ev.xexpose.height;
7281 XUnionRectWithRegion(&r, region, region);
7286 case ReparentNotify:
7287 /* set background to ParentRelative for all parents */
7289 set_transparent_background(window.window);
7293 case ConfigureNotify:
7295 /* if window size isn't what expected, set fixed size */
7296 if (ev.xconfigure.width != window.width
7297 || ev.xconfigure.height != window.height) {
7298 if (window.width != 0 && window.height != 0) {
7302 /* clear old stuff before screwing up
7307 XWindowAttributes attrs;
7309 if (XGetWindowAttributes(display,
7310 window.window, &attrs)) {
7311 window.width = attrs.width;
7312 window.height = attrs.height;
7316 text_width = window.width - border_margin * 2 - 1;
7317 text_height = window.height - border_margin * 2 - 1;
7318 if (text_width > maximum_width
7319 && maximum_width > 0) {
7320 text_width = maximum_width;
7324 /* if position isn't what expected, set fixed pos
7325 * total_updates avoids setting fixed_pos when window
7326 * is set to weird locations when started */
7327 /* // this is broken
7328 if (total_updates >= 2 && !fixed_pos
7329 && (window.x != ev.xconfigure.x
7330 || window.y != ev.xconfigure.y)
7331 && (ev.xconfigure.x != 0
7332 || ev.xconfigure.y != 0)) {
7341 /* if an ordinary window with decorations */
7342 if ((window.type == TYPE_NORMAL)
7343 && (!TEST_HINT(window.hints,
7344 HINT_UNDECORATED))) {
7345 /* allow conky to hold input focus. */
7348 /* forward the click to the desktop window */
7349 XUngrabPointer(display, ev.xbutton.time);
7350 ev.xbutton.window = window.desktop;
7351 XSendEvent(display, ev.xbutton.window, False,
7352 ButtonPressMask, &ev);
7353 XSetInputFocus(display, ev.xbutton.window,
7354 RevertToParent, ev.xbutton.time);
7361 /* if an ordinary window with decorations */
7362 if ((window.type == TYPE_NORMAL)
7363 && (!TEST_HINT(window.hints,
7364 HINT_UNDECORATED))) {
7365 /* allow conky to hold input focus. */
7368 /* forward the release to the desktop window */
7369 ev.xbutton.window = window.desktop;
7370 XSendEvent(display, ev.xbutton.window, False,
7371 ButtonReleaseMask, &ev);
7380 if (ev.type == event_base + XDamageNotify) {
7381 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
7383 XFixesSetRegion(display, part, &dev->area, 1);
7384 XFixesUnionRegion(display, region2, region2, part);
7386 #endif /* HAVE_XDAMAGE */
7392 XDamageSubtract(display, damage, region2, None);
7393 XFixesSetRegion(display, region2, 0, 0);
7394 #endif /* HAVE_XDAMAGE */
7396 /* XDBE doesn't seem to provide a way to clear the back buffer without
7397 * interfering with the front buffer, other than passing XdbeBackground
7398 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
7399 * redraw the text even if it wasn't part of the exposed area. OTOH,
7400 * if we're not going to call draw_stuff at all, then no swap happens
7401 * and we can safely do nothing. */
7403 if (!XEmptyRegion(region)) {
7408 r.x = text_start_x - border_margin;
7409 r.y = text_start_y - border_margin;
7410 r.width = text_width + border_margin * 2;
7411 r.height = text_height + border_margin * 2;
7412 XUnionRectWithRegion(&r, region, region);
7415 XSetRegion(display, window.gc, region);
7418 XftDrawSetClip(window.xftdraw, region);
7424 XDestroyRegion(region);
7425 region = XCreateRegion();
7429 #ifdef SIGNAL_BLOCKING
7430 /* unblock signals of interest and let handler fly */
7431 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
7432 CRIT_ERR("unable to sigprocmask()");
7436 switch (g_signal_pending) {
7439 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
7444 ERR("received SIGINT or SIGTERM to terminate. bye!");
7447 XDestroyRegion(region);
7450 XDamageDestroy(display, damage);
7451 XFixesDestroyRegion(display, region2);
7452 XFixesDestroyRegion(display, part);
7453 #endif /* HAVE_XDAMAGE */
7455 return; /* return from main_loop */
7458 /* Reaching here means someone set a signal
7459 * (SIGXXXX, signal_handler), but didn't write any code
7461 * If you don't want to handle a signal, don't set a handler on
7462 * it in the first place. */
7463 if (g_signal_pending) {
7464 ERR("ignoring signal (%d)", g_signal_pending);
7468 g_signal_pending = 0;
7471 #if defined(X11) && defined(HAVE_XDAMAGE)
7472 XDamageDestroy(display, damage);
7473 XFixesDestroyRegion(display, region2);
7474 XFixesDestroyRegion(display, part);
7475 XDestroyRegion(region);
7477 #endif /* X11 && HAVE_XDAMAGE */
7480 static void load_config_file(const char *);
7482 /* reload the config file */
7483 void reload_config(void)
7485 timed_thread_destroy_registered_threads();
7487 if (info.cpu_usage) {
7488 free(info.cpu_usage);
7489 info.cpu_usage = NULL;
7497 if (info.mpd.title) {
7498 free(info.mpd.title);
7499 info.mpd.title = NULL;
7501 if (info.mpd.artist) {
7502 free(info.mpd.artist);
7503 info.mpd.artist = NULL;
7505 if (info.mpd.album) {
7506 free(info.mpd.album);
7507 info.mpd.album = NULL;
7509 if (info.mpd.random) {
7510 free(info.mpd.random);
7511 info.mpd.random = NULL;
7513 if (info.mpd.repeat) {
7514 free(info.mpd.repeat);
7515 info.mpd.repeat = NULL;
7517 if (info.mpd.track) {
7518 free(info.mpd.track);
7519 info.mpd.track = NULL;
7521 if (info.mpd.name) {
7522 free(info.mpd.name);
7523 info.mpd.name = NULL;
7525 if (info.mpd.file) {
7526 free(info.mpd.file);
7527 info.mpd.file = NULL;
7529 if (info.mpd.status) {
7530 free(info.mpd.status);
7531 info.mpd.status = NULL;
7539 #ifdef TCP_PORT_MONITOR
7540 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7543 if (current_config) {
7545 load_config_file(current_config);
7547 /* re-init specials array */
7548 if ((specials = realloc((void *) specials,
7549 sizeof(struct special_t) * max_specials)) == 0) {
7550 ERR("failed to realloc specials array");
7556 // clear the window first
7557 XClearWindow(display, RootWindow(display, screen));
7560 #ifdef TCP_PORT_MONITOR
7561 info.p_tcp_port_monitor_collection = NULL;
7563 extract_variable_text(text);
7569 tmpstring1 = malloc(text_buffer_size);
7570 memset(tmpstring1, 0, text_buffer_size);
7574 tmpstring2 = malloc(text_buffer_size);
7575 memset(tmpstring2, 0, text_buffer_size);
7579 text_buffer = malloc(max_user_text);
7580 memset(text_buffer, 0, max_user_text);
7587 timed_thread_destroy_registered_threads();
7589 if (info.cpu_usage) {
7590 free(info.cpu_usage);
7591 info.cpu_usage = NULL;
7596 XdbeDeallocateBackBufferName(display, window.back_buffer);
7601 XDestroyWindow(display, window.window);
7602 XClearWindow(display, RootWindow(display, screen));
7607 XClearWindow(display, RootWindow(display, screen));
7612 XFreeGC(display, window.gc);
7616 free_text_objects(global_text_object_count, global_text_objects);
7629 global_text_object_count = 0;
7630 global_text_objects = NULL;
7637 free(current_config);
7639 #ifdef TCP_PORT_MONITOR
7640 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7641 info.p_tcp_port_monitor_collection = NULL;
7650 for (i = 0; i < special_count; i++) {
7651 if (specials[i].type == GRAPH) {
7652 free(specials[i].graph);
7659 clear_diskio_stats();
7662 static int string_to_bool(const char *s)
7666 } else if (strcasecmp(s, "yes") == 0) {
7668 } else if (strcasecmp(s, "true") == 0) {
7670 } else if (strcasecmp(s, "1") == 0) {
7677 static enum alignment string_to_alignment(const char *s)
7679 if (strcasecmp(s, "top_left") == 0) {
7681 } else if (strcasecmp(s, "top_right") == 0) {
7683 } else if (strcasecmp(s, "top_middle") == 0) {
7685 } else if (strcasecmp(s, "bottom_left") == 0) {
7687 } else if (strcasecmp(s, "bottom_right") == 0) {
7688 return BOTTOM_RIGHT;
7689 } else if (strcasecmp(s, "bottom_middle") == 0) {
7690 return BOTTOM_MIDDLE;
7691 } else if (strcasecmp(s, "middle_left") == 0) {
7693 } else if (strcasecmp(s, "middle_right") == 0) {
7694 return MIDDLE_RIGHT;
7695 } else if (strcasecmp(s, "tl") == 0) {
7697 } else if (strcasecmp(s, "tr") == 0) {
7699 } else if (strcasecmp(s, "tm") == 0) {
7701 } else if (strcasecmp(s, "bl") == 0) {
7703 } else if (strcasecmp(s, "br") == 0) {
7704 return BOTTOM_RIGHT;
7705 } else if (strcasecmp(s, "bm") == 0) {
7706 return BOTTOM_MIDDLE;
7707 } else if (strcasecmp(s, "ml") == 0) {
7709 } else if (strcasecmp(s, "mr") == 0) {
7710 return MIDDLE_RIGHT;
7711 } else if (strcasecmp(s, "none") == 0) {
7718 static void set_default_configurations(void)
7720 fork_to_background = 0;
7721 total_run_times = 0;
7722 info.cpu_avg_samples = 2;
7723 info.net_avg_samples = 2;
7730 strcpy(info.mpd.host, "localhost");
7731 info.mpd.port = 6600;
7732 info.mpd.status = NULL;
7733 info.mpd.artist = NULL;
7734 info.mpd.album = NULL;
7735 info.mpd.title = NULL;
7736 info.mpd.random = NULL;
7737 info.mpd.track = NULL;
7738 info.mpd.name = NULL;
7739 info.mpd.file = NULL;
7742 info.xmms2.artist = NULL;
7743 info.xmms2.album = NULL;
7744 info.xmms2.title = NULL;
7745 info.xmms2.genre = NULL;
7746 info.xmms2.comment = NULL;
7747 info.xmms2.url = NULL;
7748 info.xmms2.status = NULL;
7749 info.xmms2.playlist = NULL;
7751 use_spacer = NO_SPACER;
7758 default_fg_color = WhitePixel(display, screen);
7759 default_bg_color = BlackPixel(display, screen);
7760 default_out_color = BlackPixel(display, screen);
7761 color0 = default_fg_color;
7762 color1 = default_fg_color;
7763 color2 = default_fg_color;
7764 color3 = default_fg_color;
7765 color4 = default_fg_color;
7766 color5 = default_fg_color;
7767 color6 = default_fg_color;
7768 color7 = default_fg_color;
7769 color8 = default_fg_color;
7770 color9 = default_fg_color;
7773 draw_graph_borders = 1;
7775 set_first_font("6x10");
7783 window.type = TYPE_NORMAL;
7785 strcpy(window.class_name, "Conky");
7787 sprintf(window.title, "Conky (%s)", info.uname_s.nodename);
7789 stippled_borders = 0;
7792 text_alignment = BOTTOM_LEFT;
7795 free(current_mail_spool);
7799 variable_substitute(MAIL_FILE, buf, 256);
7800 if (buf[0] != '\0') {
7801 current_mail_spool = strndup(buf, text_buffer_size);
7806 update_interval = 3.0;
7807 info.music_player_interval = 1.0;
7808 stuff_in_upper_case = 0;
7809 info.users.number = 1;
7811 #ifdef TCP_PORT_MONITOR
7812 tcp_port_monitor_args.max_port_monitor_connections =
7813 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7817 static void load_config_file(const char *f)
7819 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7823 set_default_configurations();
7830 char buf[256], *p, *p2, *name, *value;
7833 if (fgets(buf, 256, fp) == NULL) {
7839 /* break at comment */
7840 p2 = strchr(p, '#');
7846 while (*p && isspace((int) *p)) {
7850 continue; /* empty line */
7857 while (*p2 && !isspace((int) *p2)) {
7861 *p2 = '\0'; /* break at name's end */
7868 while (*p && isspace((int) *p)) {
7874 p2 = value + strlen(value);
7875 while (isspace((int) *(p2 - 1))) {
7882 #define CONF2(a) if (strcasecmp(name, a) == 0)
7883 #define CONF(a) else CONF2(a)
7884 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7885 || strcasecmp(name, b) == 0)
7888 CONF2("alignment") {
7890 int a = string_to_alignment(value);
7901 CONF("background") {
7902 fork_to_background = string_to_bool(value);
7905 CONF2("background") {
7906 fork_to_background = string_to_bool(value);
7910 CONF("border_margin") {
7912 border_margin = strtol(value, 0, 0);
7917 CONF("border_width") {
7919 border_width = strtol(value, 0, 0);
7926 color0 = get_x11_color(value);
7933 color1 = get_x11_color(value);
7940 color2 = get_x11_color(value);
7947 color3 = get_x11_color(value);
7954 color4 = get_x11_color(value);
7961 color5 = get_x11_color(value);
7968 color6 = get_x11_color(value);
7975 color7 = get_x11_color(value);
7982 color8 = get_x11_color(value);
7989 color9 = get_x11_color(value);
7994 CONF("default_color") {
7996 default_fg_color = get_x11_color(value);
8001 CONF3("default_shade_color", "default_shadecolor") {
8003 default_bg_color = get_x11_color(value);
8008 CONF3("default_outline_color", "default_outlinecolor") {
8010 default_out_color = get_x11_color(value);
8018 info.mail = parse_mail_args(IMAP, value);
8025 info.mail = parse_mail_args(POP3, value);
8033 strncpy(info.mpd.host, value, 127);
8040 info.mpd.port = strtol(value, 0, 0);
8041 if (info.mpd.port < 1 || info.mpd.port > 0xffff) {
8046 CONF("mpd_password") {
8048 strncpy(info.mpd.password, value, 127);
8054 CONF("music_player_interval") {
8056 info.music_player_interval = strtod(value, 0);
8062 CONF("sensor_device") {
8064 sensor_device = strtol(value, 0, 0);
8070 CONF("cpu_avg_samples") {
8072 cpu_avg_samples = strtol(value, 0, 0);
8073 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
8076 info.cpu_avg_samples = cpu_avg_samples;
8082 CONF("net_avg_samples") {
8084 net_avg_samples = strtol(value, 0, 0);
8085 if (net_avg_samples < 1 || net_avg_samples > 14) {
8088 info.net_avg_samples = net_avg_samples;
8096 CONF("double_buffer") {
8097 use_xdbe = string_to_bool(value);
8101 CONF("override_utf8_locale") {
8102 utf8_mode = string_to_bool(value);
8104 CONF("draw_borders") {
8105 draw_borders = string_to_bool(value);
8107 CONF("draw_graph_borders") {
8108 draw_graph_borders = string_to_bool(value);
8110 CONF("draw_shades") {
8111 draw_shades = string_to_bool(value);
8113 CONF("draw_outline") {
8114 draw_outline = string_to_bool(value);
8117 CONF("out_to_console") {
8118 out_to_console = string_to_bool(value);
8120 CONF("use_spacer") {
8122 if (strcasecmp(value, "left") == 0) {
8123 use_spacer = LEFT_SPACER;
8124 } else if (strcasecmp(value, "right") == 0) {
8125 use_spacer = RIGHT_SPACER;
8126 } else if (strcasecmp(value, "none") == 0) {
8127 use_spacer = NO_SPACER;
8129 use_spacer = string_to_bool(value);
8130 ERR("use_spacer should have an argument of left, right, or"
8131 " none. '%s' seems to be some form of '%s', so"
8132 " defaulting to %s.", value,
8133 use_spacer ? "true" : "false",
8134 use_spacer ? "right" : "none");
8136 use_spacer = RIGHT_SPACER;
8138 use_spacer = NO_SPACER;
8142 ERR("use_spacer should have an argument. Defaulting to right.");
8143 use_spacer = RIGHT_SPACER;
8149 use_xft = string_to_bool(value);
8153 set_first_font(value);
8159 if (value && font_count >= 0) {
8160 fonts[0].font_alpha = atof(value) * 65535.0;
8169 if (string_to_bool(value)) {
8170 ERR("Xft not enabled");
8174 /* xftfont silently ignored when no Xft */
8177 /* xftalpha is silently ignored when no Xft */
8182 set_first_font(value);
8192 gap_x = atoi(value);
8199 gap_y = atoi(value);
8205 CONF("mail_spool") {
8209 variable_substitute(value, buffer, 256);
8211 if (buffer[0] != '\0') {
8212 if (current_mail_spool) {
8213 free(current_mail_spool);
8215 current_mail_spool = strndup(buffer, text_buffer_size);
8222 CONF("minimum_size") {
8224 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
8226 if (sscanf(value, "%d", &minimum_width) != 1) {
8234 CONF("maximum_width") {
8236 if (sscanf(value, "%d", &maximum_width) != 1) {
8244 CONF("no_buffers") {
8245 no_buffers = string_to_bool(value);
8247 CONF("top_cpu_separate") {
8248 cpu_separate = string_to_bool(value);
8250 CONF("short_units") {
8251 short_units = string_to_bool(value);
8253 CONF("pad_percents") {
8254 pad_percents = atoi(value);
8258 CONF("own_window") {
8260 own_window = string_to_bool(value);
8265 CONF("own_window_class") {
8267 memset(window.class_name, 0, sizeof(window.class_name));
8268 strncpy(window.class_name, value,
8269 sizeof(window.class_name) - 1);
8274 CONF("own_window_title") {
8276 memset(window.title, 0, sizeof(window.title));
8277 strncpy(window.title, value, sizeof(window.title) - 1);
8282 CONF("own_window_transparent") {
8284 set_transparent = string_to_bool(value);
8289 CONF("own_window_colour") {
8291 background_colour = get_x11_color(value);
8293 ERR("Invalid colour for own_window_colour (try omitting the "
8294 "'#' for hex colours");
8297 CONF("own_window_hints") {
8299 char *p_hint, *p_save;
8300 char delim[] = ", ";
8302 /* tokenize the value into individual hints */
8303 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
8305 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
8306 if (strncmp(p_hint, "undecorate", 10) == 0) {
8307 SET_HINT(window.hints, HINT_UNDECORATED);
8308 } else if (strncmp(p_hint, "below", 5) == 0) {
8309 SET_HINT(window.hints, HINT_BELOW);
8310 } else if (strncmp(p_hint, "above", 5) == 0) {
8311 SET_HINT(window.hints, HINT_ABOVE);
8312 } else if (strncmp(p_hint, "sticky", 6) == 0) {
8313 SET_HINT(window.hints, HINT_STICKY);
8314 } else if (strncmp(p_hint, "skip_taskbar", 12) == 0) {
8315 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
8316 } else if (strncmp(p_hint, "skip_pager", 10) == 0) {
8317 SET_HINT(window.hints, HINT_SKIP_PAGER);
8322 p_hint = strtok_r(NULL, delim, &p_save);
8323 } while (p_hint != NULL);
8329 CONF("own_window_type") {
8331 if (strncmp(value, "normal", 6) == 0) {
8332 window.type = TYPE_NORMAL;
8333 } else if (strncmp(value, "desktop", 7) == 0) {
8334 window.type = TYPE_DESKTOP;
8335 } else if (strncmp(value, "override", 8) == 0) {
8336 window.type = TYPE_OVERRIDE;
8345 CONF("stippled_borders") {
8347 stippled_borders = strtol(value, 0, 0);
8349 stippled_borders = 4;
8354 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> "
8358 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> "
8361 CONF("update_interval") {
8363 update_interval = strtod(value, 0);
8367 if (info.music_player_interval == 0) {
8368 // default to update_interval
8369 info.music_player_interval = update_interval;
8372 CONF("total_run_times") {
8374 total_run_times = strtod(value, 0);
8380 stuff_in_upper_case = string_to_bool(value);
8382 CONF("max_specials") {
8384 max_specials = atoi(value);
8389 CONF("max_user_text") {
8391 max_user_text = atoi(value);
8396 CONF("text_buffer_size") {
8398 text_buffer_size = atoi(value);
8399 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
8400 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
8401 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
8413 text = (char *) malloc(1);
8417 unsigned int l = strlen(text);
8419 if (fgets(buf, 256, fp) == NULL) {
8422 text = (char *) realloc(text, l + strlen(buf) + 1);
8425 if (strlen(text) > max_user_text) {
8430 if (strlen(text) < 1) {
8431 CRIT_ERR("no text supplied in configuration; exiting");
8433 text_lines = line + 1;
8436 #ifdef TCP_PORT_MONITOR
8437 CONF("max_port_monitor_connections") {
8438 if (!value || (sscanf(value, "%d",
8439 &tcp_port_monitor_args.max_port_monitor_connections) != 1)
8440 || tcp_port_monitor_args.max_port_monitor_connections < 0) {
8441 /* an error. use default, warn and continue. */
8442 tcp_port_monitor_args.max_port_monitor_connections =
8443 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8445 } else if (tcp_port_monitor_args.max_port_monitor_connections
8447 /* no error, just use default */
8448 tcp_port_monitor_args.max_port_monitor_connections =
8449 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8451 /* else tcp_port_monitor_args.max_port_monitor_connections > 0
8456 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8467 if (info.music_player_interval == 0) {
8468 // default to update_interval
8469 info.music_player_interval = update_interval;
8471 if (!text) { // didn't supply any text
8472 CRIT_ERR("missing text block in configuration; exiting");
8476 /* : means that character before that takes an argument */
8477 static const char *getopt_string = "vVdt:u:i:hc:"
8489 static const struct option longopts[] = {
8490 { "help", 0, NULL, 'h' },
8491 { "version", 0, NULL, 'V' },
8492 { "config", 1, NULL, 'c' },
8493 { "daemonize", 0, NULL, 'd' },
8495 { "alignment", 1, NULL, 'a' },
8496 { "font", 1, NULL, 'f' },
8498 { "own-window", 0, NULL, 'o' },
8501 { "double-buffer", 0, NULL, 'b' },
8503 { "window-id", 1, NULL, 'w' },
8505 { "text", 1, NULL, 't' },
8506 { "interval", 0, NULL, 'u' },
8510 int main(int argc, char **argv)
8516 struct sigaction act, oact;
8518 g_signal_pending = 0;
8519 memset(&info, 0, sizeof(info));
8521 #ifdef TCP_PORT_MONITOR
8522 tcp_port_monitor_args.max_port_monitor_connections =
8523 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8526 /* handle command line parameters that don't change configs */
8528 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8529 || ((s = getenv("LANG")) && *s)) {
8530 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8532 ERR("malloc failed");
8534 for (x = 0; x < strlen(s); x++) {
8535 temp[x] = tolower(s[x]);
8538 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8544 if (!setlocale(LC_CTYPE, "")) {
8545 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8549 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8560 if (current_config) {
8561 free(current_config);
8563 current_config = strndup(optarg, max_user_text);
8567 printf("Usage: %s [OPTION]...\n"
8568 "Conky is a system monitor that renders text on desktop or to own transparent\n"
8569 "window. Command line options will override configurations defined in config\n"
8571 " -v, --version version\n"
8572 " -c, --config=FILE config file to load\n"
8573 " -d, --daemonize daemonize, fork to background\n"
8574 " -h, --help help\n"
8576 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
8577 " -f, --font=FONT font to use\n"
8579 " -o, --own-window create own window to draw\n"
8582 " -b, --double-buffer double buffer (prevents flickering)\n"
8584 " -w, --window-id=WIN_ID window id to draw\n"
8585 " -x X x position\n"
8586 " -y Y y position\n"
8588 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8589 " -u, --interval=SECS update interval\n"
8590 " -i COUNT number of times to update Conky (and quit)\n",
8596 window.window = strtol(optarg, 0, 0);
8605 /* initalize X BEFORE we load config.
8606 * (we need to so that 'screen' is set) */
8610 /* check if specified config file is valid */
8611 if (current_config) {
8613 if (stat(current_config, &sb) ||
8614 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8615 ERR("invalid configuration file '%s'\n", current_config);
8616 free(current_config);
8621 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8623 if (!current_config) {
8624 /* load default config file */
8628 /* Try to use personal config file first */
8629 variable_substitute(CONFIG_FILE, buf, sizeof(buf));
8630 if (buf[0] && (fp = fopen(buf, "r"))) {
8631 current_config = strndup(buf, max_user_text);
8635 /* Try to use system config file if personal config not readable */
8636 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8637 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
8641 /* No readable config found */
8642 if (!current_config) {
8643 CRIT_ERR("no readable personal or system-wide config file found");
8647 load_config_file(current_config);
8649 /* init specials array */
8650 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8651 ERR("failed to create specials array");
8655 if (current_mail_spool == NULL) {
8658 variable_substitute(MAIL_FILE, buf, 256);
8660 if (buf[0] != '\0') {
8661 current_mail_spool = strndup(buf, text_buffer_size);
8666 /* handle other command line arguments */
8668 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8669 || defined(__NetBSD__)
8670 optind = optreset = 1;
8675 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8676 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8677 "kvm_open")) == NULL) {
8678 CRIT_ERR("cannot read kvm");
8683 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8691 fork_to_background = 1;
8696 set_first_font(optarg);
8699 text_alignment = string_to_alignment(optarg);
8718 text = strndup(optarg, max_user_text);
8719 convert_escapes(text);
8723 update_interval = strtod(optarg, 0);
8724 if (info.music_player_interval == 0) {
8725 // default to update_interval
8726 info.music_player_interval = update_interval;
8731 total_run_times = strtod(optarg, 0);
8735 gap_x = atoi(optarg);
8739 gap_y = atoi(optarg);
8753 /* generate text and get initial size */
8754 extract_variable_text(text);
8761 if (fork_to_background) {
8766 ERR("Conky: couldn't fork() to background: %s",
8773 fprintf(stderr, "\n");
8778 /* parent process */
8779 fprintf(stderr, "Conky: forked to background, pid is %d\n",
8786 text_buffer = malloc(max_user_text);
8787 memset(text_buffer, 0, max_user_text);
8788 tmpstring1 = malloc(text_buffer_size);
8789 memset(tmpstring1, 0, text_buffer_size);
8790 tmpstring2 = malloc(text_buffer_size);
8791 memset(tmpstring2, 0, text_buffer_size);
8795 update_text_area(); /* to get initial size of the window */
8798 init_window(own_window, text_width + border_margin * 2 + 1,
8799 text_height + border_margin * 2 + 1, set_transparent, background_colour,
8801 #else /* OWN_WINDOW */
8802 init_window(0, text_width + border_margin * 2 + 1,
8803 text_height + border_margin * 2 + 1, set_transparent, 0,
8805 #endif /* OWN_WINDOW */
8808 update_text_area(); /* to position text/window on screen */
8813 if (own_window && !fixed_pos) {
8814 XMoveWindow(display, window.window, window.x, window.y);
8817 set_transparent_background(window.window);
8827 /* Set signal handlers */
8828 act.sa_handler = signal_handler;
8829 sigemptyset(&act.sa_mask);
8832 act.sa_flags |= SA_RESTART;
8835 if (sigaction(SIGINT, &act, &oact) < 0
8836 || sigaction(SIGUSR1, &act, &oact) < 0
8837 || sigaction(SIGHUP,&act,&oact) < 0
8838 || sigaction(SIGTERM, &act, &oact) < 0) {
8839 ERR("error setting signal handler: %s", strerror(errno));
8842 /* *************** *
8844 * *************** */
8847 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8854 void signal_handler(int sig)
8856 /* signal handler is light as a feather, as it should be.
8857 * we will poll g_signal_pending with each loop of conky
8858 * and do any signal processing there, NOT here. */
8859 g_signal_pending = sig;