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/>.
44 #include <X11/Xutil.h>
46 #include <X11/extensions/Xdamage.h>
52 #include <sys/types.h>
54 #include <netinet/in.h>
66 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
69 #define CONFIG_FILE "$HOME/.conkyrc"
70 #define MAIL_FILE "$MAIL"
71 #define MAX_IF_BLOCK_DEPTH 5
72 #define MAX_TAIL_LINES 100
74 /* #define SIGNAL_BLOCKING */
75 #undef SIGNAL_BLOCKING
77 static void print_version(void) __attribute__((noreturn));
79 static void print_version(void)
81 printf("Conky %s compiled %s for %s\n", VERSION, BUILD_DATE, BUILD_ARCH);
83 printf("\nCompiled in features:\n\n"
84 "System config file: %s\n\n"
88 " * Xdamage extension\n"
89 # endif /* HAVE_XDAMAGE */
91 " * Xdbe extension (double buffer)\n"
92 # endif /* HAVE_XDBE */
97 "\n Music detection:\n"
100 #endif /* AUDACIOUS */
110 "\n General features:\n"
114 #ifdef TCP_PORT_MONITOR
116 #endif /* TCP_PORT_MONITOR */
122 #endif /* HAVE_IWLIB */
129 "", SYSTEM_CONFIG_FILE
135 static const char *suffixes[] = { "B", "kiB", "MiB", "GiB", "TiB", "PiB", "" };
141 static int text_start_x, text_start_y; /* text start position in window */
142 static int text_width, text_height;
160 char name[DEFAULT_TEXT_BUFFER_SIZE];
170 static int selected_font = 0;
171 static int font_count = -1;
172 struct font_list *fonts = NULL;
176 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + \
177 fonts[selected_font].xftfont->descent) \
178 : (fonts[selected_font].font->max_bounds.ascent + \
179 fonts[selected_font].font->max_bounds.descent))
180 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent \
181 : fonts[selected_font].font->max_bounds.ascent)
182 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent \
183 : fonts[selected_font].font->max_bounds.descent)
187 #define font_height() (fonts[selected_font].font->max_bounds.ascent + \
188 fonts[selected_font].font->max_bounds.descent)
189 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
190 #define font_descent() fonts[selected_font].font->max_bounds.descent
194 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
196 static void set_font(void);
198 int addfont(const char *data_in)
200 if (font_count > MAX_FONTS) {
201 CRIT_ERR("you don't need that many fonts, sorry.");
204 if (font_count == 0) {
208 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
212 memset(fonts, 0, sizeof(struct font_list));
214 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
215 memset(&fonts[font_count], 0, sizeof(struct font_list));
217 CRIT_ERR("realloc in addfont");
219 // must account for null terminator
220 if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
221 strncpy(fonts[font_count].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
223 fonts[font_count].font_alpha = 0xffff;
226 CRIT_ERR("Oops...looks like something overflowed in addfont().");
231 void set_first_font(const char *data_in)
233 if (font_count < 0) {
234 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
238 memset(fonts, 0, sizeof(struct font_list));
241 if (strlen(data_in) > 1) {
242 strncpy(fonts[0].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
244 fonts[0].font_alpha = 0xffff;
249 void free_fonts(void)
253 for (i = 0; i <= font_count; i++) {
256 XftFontClose(display, fonts[i].xftfont);
257 fonts[i].xftfont = 0;
261 XFreeFont(display, fonts[i].font);
271 static void load_fonts(void)
275 for (i = 0; i <= font_count; i++) {
278 if (use_xft && fonts[i].xftfont) {
280 } else if (use_xft) {
281 /* if (fonts[i].xftfont != NULL && selected_font == 0) {
282 XftFontClose(display, fonts[i].xftfont);
284 fonts[i].xftfont = XftFontOpenName(display, screen,
286 if (fonts[i].xftfont != NULL) {
290 ERR("can't load Xft font '%s'", fonts[i].name);
291 if ((fonts[i].xftfont = XftFontOpenName(display, screen,
292 "courier-12")) != NULL) {
296 ERR("can't load Xft font '%s'", "courier-12");
298 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
299 CRIT_ERR("can't load font '%s'", "fixed");
306 /* load normal font */
307 /* if (fonts[i].font != NULL) {
308 XFreeFont(display, fonts[i].font);
311 if (fonts[i].font || (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
312 ERR("can't load font '%s'", fonts[i].name);
313 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
314 CRIT_ERR("can't load font '%s'", "fixed");
315 printf("loaded fixed?\n");
323 /* default config file */
324 static char *current_config;
326 /* set to 1 if you want all text to be in uppercase */
327 static unsigned int stuff_in_upper_case;
329 /* Run how many times? */
330 static unsigned long total_run_times;
333 static int fork_to_background;
335 static int cpu_avg_samples, net_avg_samples;
339 static int show_graph_scale;
341 /* Position on the screen */
342 static int text_alignment;
343 static int gap_x, gap_y;
346 static int draw_borders;
347 static int draw_graph_borders;
348 static int stippled_borders;
350 static int draw_shades, draw_outline;
352 static int border_margin, border_width;
354 static long default_fg_color, default_bg_color, default_out_color;
356 /* create own window or draw stuff to root? */
357 static int set_transparent = 0;
360 static int own_window = 0;
361 static int background_colour = 0;
363 /* fixed size/pos is set if wm/user changes them */
364 static int fixed_size = 0, fixed_pos = 0;
367 static int minimum_width, minimum_height;
368 static int maximum_width;
373 static int sensor_device;
376 static long color0, color1, color2, color3, color4, color5, color6, color7,
379 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
380 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
382 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
383 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
385 /* maximum size of individual text buffers, ie $exec buffer size */
386 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
389 #define CODEPAGE_LENGTH 20
391 long iconv_count = 0;
392 char iconv_converting;
393 static iconv_t **iconv_cd = 0;
395 int register_iconv(iconv_t *new_iconv)
397 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
399 CRIT_ERR("Out of memory");
401 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
402 if (!iconv_cd[iconv_count]) {
403 CRIT_ERR("Out of memory");
405 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
410 void free_iconv(void)
415 for (i = 0; i < iconv_count; i++) {
417 iconv_close(*iconv_cd[i]);
431 /* no buffers in used memory? */
434 /* pad percentages to decimals? */
435 static int pad_percents = 0;
437 #ifdef TCP_PORT_MONITOR
438 tcp_port_monitor_args_t tcp_port_monitor_args;
441 static char *global_text = 0;
442 long global_text_lines;
444 static int total_updates;
447 static int blockdepth = 0;
448 static int if_jumped = 0;
449 static int blockstart[MAX_IF_BLOCK_DEPTH];
451 int check_contains(char *f, char *s)
454 FILE *where = fopen(f, "r");
457 char buf1[256], buf2[256];
459 while (fgets(buf1, 256, where)) {
460 sscanf(buf1, "%255s", buf2);
461 if (strstr(buf2, s)) {
468 ERR("Could not open the file");
474 static inline int calc_text_width(const char *s, int l)
481 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
482 (const FcChar8 *) s, l, &gi);
484 XftTextExtents8(display, fonts[selected_font].xftfont,
485 (const FcChar8 *) s, l, &gi);
491 return XTextWidth(fonts[selected_font].font, s, l);
496 /* formatted text to render on screen, generated in generate_text(),
497 * drawn in draw_stuff() */
499 static char *text_buffer;
501 /* special stuff in text_buffer */
503 #define SPECIAL_CHAR '\x01'
532 unsigned long first_colour; // for graph gradient
533 unsigned long last_colour;
537 /* create specials array on heap instead of stack with introduction of
539 static struct special_t *specials = NULL;
541 static unsigned int special_count;
544 static unsigned int special_index; /* used when drawing */
547 /* why 256? cause an array of more then 256 doubles seems excessive,
548 * and who needs that kind of precision anyway? */
549 #define MAX_GRAPH_DEPTH 256
551 static struct special_t *new_special(char *buf, enum special_types t)
553 if (special_count >= max_specials) {
554 CRIT_ERR("too many special things in text");
557 buf[0] = SPECIAL_CHAR;
559 specials[special_count].type = t;
560 return &specials[special_count++];
563 long fwd_fcharfind(FILE *fp, char val, unsigned int step)
567 unsigned int count = 0;
568 static char buf[BUFSZ];
569 long orig_pos = ftell(fp);
571 long buf_size = BUFSZ;
572 char *cur_found = NULL;
574 while (count < step) {
575 if (cur_found == NULL) {
576 buf_size = fread(buf, 1, buf_size, fp);
579 cur_found = memchr(buf + buf_pos, val, buf_size - buf_pos);
580 if (cur_found != NULL) {
581 buf_pos = cur_found - buf + 1;
590 ret = ftell(fp) - buf_size + buf_pos - 1;
592 fseek(fp, orig_pos, SEEK_SET);
598 void *memrchr(const void *buffer, char c, size_t n)
600 const unsigned char *p = buffer;
602 for (p += n; n; n--) {
611 long rev_fcharfind(FILE *fp, char val, unsigned int step)
615 unsigned int count = 0;
616 static char buf[BUFSZ];
617 long orig_pos = ftell(fp);
619 long file_pos = orig_pos;
620 long buf_size = BUFSZ;
623 while (count < step) {
625 if (file_pos > BUFSZ) {
626 fseek(fp, file_pos - BUFSZ, SEEK_SET);
629 fseek(fp, 0, SEEK_SET);
631 file_pos = ftell(fp);
632 buf_pos = fread(buf, 1, buf_size, fp);
634 cur_found = memrchr(buf, val, (size_t) buf_pos);
635 if (cur_found != NULL) {
636 buf_pos = cur_found - buf;
645 fseek(fp, orig_pos, SEEK_SET);
647 ret = file_pos + buf_pos;
653 static void new_bar(char *buf, int w, int h, int usage)
655 struct special_t *s = new_special(buf, BAR);
657 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
662 static const char *scan_bar(const char *args, int *w, int *h)
664 /* zero width means all space that is available */
667 /* bar's argument is either height or height,width */
671 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) {
672 sscanf(args, "%d %n", h, &n);
680 static char *scan_font(const char *args)
683 return strndup(args, DEFAULT_TEXT_BUFFER_SIZE);
690 static void new_font(char *buf, char *args)
693 struct special_t *s = new_special(buf, FONT);
695 if (s->font_added > font_count || !s->font_added || strncmp(args, fonts[s->font_added].name, DEFAULT_TEXT_BUFFER_SIZE)) {
696 int tmp = selected_font;
698 selected_font = s->font_added = addfont(args);
703 struct special_t *s = new_special(buf, FONT);
704 int tmp = selected_font;
706 selected_font = s->font_added = 0;
711 inline void graph_append(struct special_t *graph, double f)
715 if (!graph->scaled && f > graph->graph_scale) {
716 f = graph->graph_scale;
720 graph->graph_scale = 1;
722 graph->graph[0] = f; /* add new data */
723 /* shift all the data by 1 */
724 for (i = graph->graph_width - 1; i > 0; i--) {
725 graph->graph[i] = graph->graph[i - 1];
726 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
727 /* check if we need to update the scale */
728 graph->graph_scale = graph->graph[i];
733 short colour_depth = 0;
734 void set_up_gradient(void);
736 /* precalculated: 31/255, and 63/255 */
737 #define CONST_8_TO_5_BITS 0.12156862745098
738 #define CONST_8_TO_6_BITS 0.247058823529412
740 /* adjust color values depending on color depth */
741 static unsigned int adjust_colors(unsigned int color)
745 if (colour_depth == 0) {
748 if (colour_depth == 16) {
749 r = (color & 0xff0000) >> 16;
750 g = (color & 0xff00) >> 8;
752 color = (int) (r * CONST_8_TO_5_BITS) << 11;
753 color |= (int) (g * CONST_8_TO_6_BITS) << 5;
754 color |= (int) (b * CONST_8_TO_5_BITS);
759 static void new_graph(char *buf, int w, int h, unsigned int first_colour,
760 unsigned int second_colour, double i, int scale, int append)
762 struct special_t *s = new_special(buf, GRAPH);
765 if (s->graph == NULL) {
766 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
767 // subtract 2 for the box
768 s->graph_width = s->width /* - 2 */;
770 s->graph_width = MAX_GRAPH_DEPTH - 2;
772 s->graph = malloc(s->graph_width * sizeof(double));
773 memset(s->graph, 0, s->graph_width * sizeof(double));
774 s->graph_scale = 100;
777 s->first_colour = adjust_colors(first_colour);
778 s->last_colour = adjust_colors(second_colour);
785 s->graph_width = s->width - 2; // subtract 2 for rectangle around
791 s->graph_scale = scale;
799 static char *scan_graph(const char *args, int *w, int *h,
800 unsigned int *first_colour, unsigned int *last_colour,
806 /* zero width means all space that is available */
812 /* graph's argument is either height or height,width */
814 if (sscanf(args, "%d,%d %x %x %u", h, w, first_colour, last_colour,
819 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) {
822 if (sscanf(args, "%63s %d,%d %x %x %u", buf, h, w, first_colour,
823 last_colour, scale) == 6) {
824 return strndup(buf, text_buffer_size);
827 if (sscanf(args, "%63s %d,%d %x %x", buf, h, w, first_colour,
829 return strndup(buf, text_buffer_size);
834 if (sscanf(args, "%x %x %u", first_colour, last_colour, scale) == 3) {
838 if (sscanf(args, "%x %x", first_colour, last_colour) == 2) {
841 if (sscanf(args, "%63s %x %x %u", buf, first_colour, last_colour,
843 return strndup(buf, text_buffer_size);
846 if (sscanf(args, "%63s %x %x", buf, first_colour, last_colour) == 3) {
847 return strndup(buf, text_buffer_size);
852 if (sscanf(args, "%d,%d %u", h, w, scale) == 3) {
856 if (sscanf(args, "%d,%d", h, w) == 2) {
859 if (sscanf(args, "%63s %d,%d %u", buf, h, w, scale) < 4) {
861 //TODO: check the return value and throw an error?
862 sscanf(args, "%63s %d,%d", buf, h, w);
865 return strndup(buf, text_buffer_size);
868 if (buf[0] == '\0') {
871 return strndup(buf, text_buffer_size);
875 static inline void new_hr(char *buf, int a)
877 new_special(buf, HORIZONTAL_LINE)->height = a;
880 static inline void new_stippled_hr(char *buf, int a, int b)
882 struct special_t *s = new_special(buf, STIPPLED_HR);
888 static inline void new_fg(char *buf, long c)
890 new_special(buf, FG)->arg = c;
893 static inline void new_bg(char *buf, long c)
895 new_special(buf, BG)->arg = c;
898 static inline void new_outline(char *buf, long c)
900 new_special(buf, OUTLINE)->arg = c;
903 static inline void new_offset(char *buf, long c)
905 new_special(buf, OFFSET)->arg = c;
908 static inline void new_voffset(char *buf, long c)
910 new_special(buf, VOFFSET)->arg = c;
913 static inline void new_alignr(char *buf, long c)
915 new_special(buf, ALIGNR)->arg = c;
918 // A postive offset pushes the text further left
919 static inline void new_alignc(char *buf, long c)
921 new_special(buf, ALIGNC)->arg = c;
924 static inline void new_goto(char *buf, long c)
926 new_special(buf, GOTO)->arg = c;
929 static inline void new_tab(char *buf, int a, int b)
931 struct special_t *s = new_special(buf, TAB);
937 /* quite boring functions */
939 static inline void for_each_line(char *b, void f(char *))
943 for (ps = b, pe = b; *pe; pe++) {
957 static void convert_escapes(char *buf)
959 char *p = buf, *s = buf;
966 } else if (*s == '\\') {
977 /* Prints anything normally printed with snprintf according to the current value
978 * of use_spacer. Actually slightly more flexible than snprintf, as you can
979 * safely specify the destination buffer as one of your inputs. */
980 static int spaced_print(char *, int, const char *, int, const char *, ...)
981 __attribute__((format(printf, 3, 6)));
983 static int spaced_print(char *buf, int size, const char *format, int width,
984 const char *func_name, ...) {
992 tempbuf = malloc(size * sizeof(char));
994 // Passes the varargs along to vsnprintf
995 va_start(argp, func_name);
996 vsnprintf(tempbuf, size, format, argp);
999 switch (use_spacer) {
1001 len = snprintf(buf, size, "%s", tempbuf);
1004 len = snprintf(buf, size, "%*s", width - 1, tempbuf);
1007 len = snprintf(buf, size, "%-*s", width - 1, tempbuf);
1010 CRIT_ERR("%s encountered invalid use_spacer value (%d)", func_name,
1019 /* converts from bytes to human readable format (k, M, G, T) */
1020 static void human_readable(long long num, char *buf, int size, const char *func_name)
1022 const char **suffix = suffixes;
1025 static const int WIDTH = 10, SHORT_WIDTH = 8;
1029 spaced_print(buf, size, "%lld%c", SHORT_WIDTH, func_name, num,
1032 spaced_print(buf, size, "%lld%s", WIDTH, func_name, num, *suffix);
1037 while (num / 1024 >= 1000LL && **(suffix + 2)) {
1043 fnum = num / 1024.0;
1048 if (precision < 0) {
1052 len = spaced_print(buf, size, "%.*f%c", SHORT_WIDTH, func_name,
1053 precision, fnum, **suffix);
1055 len = spaced_print(buf, size, "%.*f%s", WIDTH, func_name, precision,
1058 } while (len >= (short_units ? SHORT_WIDTH : WIDTH) || len >= size);
1063 enum text_object_type {
1065 #if defined(__linux__)
1067 #endif /* __linux__ */
1077 OBJ_battery_percent,
1079 #endif /* !__OpenBSD__ */
1094 OBJ_conky_build_date,
1095 OBJ_conky_build_arch,
1105 OBJ_diskiograph_read,
1106 OBJ_diskiograph_write,
1144 #if defined(__linux__)
1151 OBJ_i8k_left_fan_status,
1152 OBJ_i8k_right_fan_status,
1153 OBJ_i8k_left_fan_rpm,
1154 OBJ_i8k_right_fan_rpm,
1156 OBJ_i8k_buttons_status,
1172 OBJ_wireless_bitrate,
1174 OBJ_wireless_link_qual,
1175 OBJ_wireless_link_qual_max,
1176 OBJ_wireless_link_qual_perc,
1177 OBJ_wireless_link_bar,
1178 #endif /* __linux__ */
1211 OBJ_running_processes,
1220 OBJ_temp1, /* i2c is used instead in these */
1244 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
1245 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1247 OBJ_apm_battery_time,
1248 OBJ_apm_battery_life,
1249 #endif /* __FreeBSD__ __OpenBSD__ */
1251 OBJ_obsd_sensors_temp,
1252 OBJ_obsd_sensors_fan,
1253 OBJ_obsd_sensors_volt,
1256 #endif /* __OpenBSD__ */
1278 OBJ_music_player_interval,
1298 OBJ_xmms2_timesplayed,
1301 OBJ_audacious_status,
1302 OBJ_audacious_title,
1303 OBJ_audacious_length,
1304 OBJ_audacious_length_seconds,
1305 OBJ_audacious_position,
1306 OBJ_audacious_position_seconds,
1307 OBJ_audacious_bitrate,
1308 OBJ_audacious_frequency,
1309 OBJ_audacious_channels,
1310 OBJ_audacious_filename,
1311 OBJ_audacious_playlist_length,
1312 OBJ_audacious_playlist_position,
1326 #ifdef TCP_PORT_MONITOR
1340 OBJ_if_smapi_bat_installed,
1343 OBJ_entropy_poolsize,
1347 struct text_object {
1349 char *s; /* some string */
1350 int i; /* some integer */
1351 long l; /* some other integer */
1352 unsigned int sensor;
1353 struct net_stat *net;
1355 struct diskio_stat *diskio;
1356 unsigned char loadavg[3];
1357 unsigned int cpu_index;
1358 struct mail_s *mail;
1366 char *tz; /* timezone variable */
1367 char *fmt; /* time display formatting */
1405 /* If not -1, a file descriptor to read from when
1406 * logfile is a FIFO. */
1423 timed_thread *p_timed_thread;
1429 #ifdef TCP_PORT_MONITOR
1431 /* starting port to monitor */
1432 in_port_t port_range_begin;
1433 /* ending port to monitor */
1434 in_port_t port_range_end;
1435 /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1437 /* 0 to n-1 connections. */
1438 int connection_index;
1459 struct local_mail_s local_mail;
1461 struct nvidia_s nvidia;
1468 unsigned int c, d, e;
1473 struct text_object_list {
1474 unsigned int text_object_count;
1475 struct text_object *text_objects;
1478 static struct text_object_list *global_text_object_list;
1480 static void generate_text_internal(char *p, int p_max_size,
1481 struct text_object_list *text_object_list,
1482 struct information *cur);
1484 #define MAXDATASIZE 1000
1488 struct mail_s *parse_mail_args(char type, const char *arg)
1490 struct mail_s *mail;
1493 mail = malloc(sizeof(struct mail_s));
1494 memset(mail, 0, sizeof(struct mail_s));
1496 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass)
1499 ERR("Scanning IMAP args failed");
1500 } else if (type == IMAP) {
1501 ERR("Scanning POP3 args failed");
1504 // see if password needs prompting
1505 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1506 int fp = fileno(stdin);
1507 struct termios term;
1509 tcgetattr(fp, &term);
1510 term.c_lflag &= ~ECHO;
1511 tcsetattr(fp, TCSANOW, &term);
1512 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1513 scanf("%128s", mail->pass);
1515 term.c_lflag |= ECHO;
1516 tcsetattr(fp, TCSANOW, &term);
1518 // now we check for optional args
1519 tmp = strstr(arg, "-i ");
1522 sscanf(tmp, "%f", &mail->interval);
1524 mail->interval = 300; // 5 minutes
1526 tmp = strstr(arg, "-p ");
1529 sscanf(tmp, "%lu", &mail->port);
1532 mail->port = 110; // default pop3 port
1533 } else if (type == IMAP) {
1534 mail->port = 143; // default imap port
1538 tmp = strstr(arg, "-f ");
1541 sscanf(tmp, "%s", mail->folder);
1543 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1546 tmp = strstr(arg, "-e ");
1551 if (tmp[0] == '\'') {
1552 len = strstr(tmp + 1, "'") - tmp - 1;
1557 strncpy(mail->command, tmp + 1, len);
1559 mail->command[0] = '\0';
1561 mail->p_timed_thread = NULL;
1565 void *imap_thread(void *arg)
1567 int sockfd, numbytes;
1568 char recvbuf[MAXDATASIZE];
1569 char sendbuf[MAXDATASIZE];
1572 unsigned int old_unseen = UINT_MAX;
1573 unsigned int old_messages = UINT_MAX;
1574 struct stat stat_buf;
1575 struct hostent he, *he_res = 0;
1577 char hostbuff[2048];
1578 struct sockaddr_in their_addr; // connector's address information
1579 struct mail_s *mail = (struct mail_s *)arg;
1581 #ifdef HAVE_GETHOSTBYNAME_R
1582 if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
1583 ERR("IMAP gethostbyname_r: %s", hstrerror(h_errno));
1586 #else /* HAVE_GETHOSTBYNAME_R */
1587 if ((he_res = gethostbyname(mail->host)) == NULL) { // get the host info
1588 herror("gethostbyname");
1591 #endif /* HAVE_GETHOSTBYNAME_R */
1593 struct timeval timeout;
1598 ERR("Trying IMAP connection again for %s@%s (try %i/5)",
1599 mail->user, mail->host, fail + 1);
1602 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1609 their_addr.sin_family = AF_INET;
1610 // short, network byte order
1611 their_addr.sin_port = htons(mail->port);
1612 their_addr.sin_addr = *((struct in_addr *) he_res->h_addr);
1613 // zero the rest of the struct
1614 memset(&(their_addr.sin_zero), '\0', 8);
1616 if (connect(sockfd, (struct sockaddr *) &their_addr,
1617 sizeof(struct sockaddr)) == -1) {
1623 timeout.tv_sec = 60; // 60 second timeout i guess
1624 timeout.tv_usec = 0;
1626 FD_SET(sockfd, &fdset);
1627 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1629 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1635 ERR("IMAP connection failed: timeout");
1639 recvbuf[numbytes] = '\0';
1640 if (strstr(recvbuf, "* OK") != recvbuf) {
1641 ERR("IMAP connection failed, probably not an IMAP server");
1645 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1646 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1647 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1648 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1649 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1650 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1655 timeout.tv_sec = 60; // 60 second timeout i guess
1656 timeout.tv_usec = 0;
1658 FD_SET(sockfd, &fdset);
1659 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1661 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1667 recvbuf[numbytes] = '\0';
1668 if (strstr(recvbuf, "a1 OK") == NULL) {
1669 ERR("IMAP server login failed: %s", recvbuf);
1673 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1674 strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1);
1675 strncat(sendbuf, " (MESSAGES UNSEEN)\r\n",
1676 MAXDATASIZE - strlen(sendbuf) - 1);
1677 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1682 timeout.tv_sec = 60; // 60 second timeout i guess
1683 timeout.tv_usec = 0;
1685 FD_SET(sockfd, &fdset);
1686 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1688 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1694 recvbuf[numbytes] = '\0';
1695 if (strstr(recvbuf, "a2 OK") == NULL) {
1696 ERR("IMAP status failed: %s", recvbuf);
1700 // now we get the data
1701 reply = strstr(recvbuf, " (MESSAGES ");
1703 *strchr(reply, ')') = '\0';
1704 if (reply == NULL) {
1705 ERR("Error parsing IMAP response: %s", recvbuf);
1709 timed_thread_lock(mail->p_timed_thread);
1710 sscanf(reply, "MESSAGES %lu UNSEEN %lu", &mail->messages,
1712 timed_thread_unlock(mail->p_timed_thread);
1714 strncpy(sendbuf, "a3 logout\r\n", MAXDATASIZE);
1715 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1720 timeout.tv_sec = 60; // 60 second timeout i guess
1721 timeout.tv_usec = 0;
1723 FD_SET(sockfd, &fdset);
1724 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1726 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1732 recvbuf[numbytes] = '\0';
1733 if (strstr(recvbuf, "a3 OK") == NULL) {
1734 ERR("IMAP logout failed: %s", recvbuf);
1738 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen
1739 || (mail->messages > old_messages && mail->unseen > 0))) {
1741 if (system(mail->command) == -1) {
1746 old_unseen = mail->unseen;
1747 old_messages = mail->messages;
1749 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1750 /* if a valid socket, close it */
1753 if (timed_thread_test(mail->p_timed_thread)) {
1754 timed_thread_exit(mail->p_timed_thread);
1762 void *pop3_thread(void *arg)
1764 int sockfd, numbytes;
1765 char recvbuf[MAXDATASIZE];
1766 char sendbuf[MAXDATASIZE];
1769 unsigned int old_unseen = UINT_MAX;
1770 struct stat stat_buf;
1771 struct hostent he, *he_res = 0;
1773 char hostbuff[2048];
1774 struct sockaddr_in their_addr; // connector's address information
1775 struct mail_s *mail = (struct mail_s *)arg;
1777 #ifdef HAVE_GETHOSTBYNAME_R
1778 if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
1779 ERR("POP3 gethostbyname_r: %s", hstrerror(h_errno));
1782 #else /* HAVE_GETHOSTBYNAME_R */
1783 if ((he_res = gethostbyname(mail->host)) == NULL) { // get the host info
1784 herror("gethostbyname");
1787 #endif /* HAVE_GETHOSTBYNAME_R */
1789 struct timeval timeout;
1794 ERR("Trying POP3 connection again for %s@%s (try %i/5)",
1795 mail->user, mail->host, fail + 1);
1798 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1805 their_addr.sin_family = AF_INET;
1806 // short, network byte order
1807 their_addr.sin_port = htons(mail->port);
1808 their_addr.sin_addr = *((struct in_addr *) he_res->h_addr);
1809 // zero the rest of the struct
1810 memset(&(their_addr.sin_zero), '\0', 8);
1812 if (connect(sockfd, (struct sockaddr *) &their_addr,
1813 sizeof(struct sockaddr)) == -1) {
1819 timeout.tv_sec = 60; // 60 second timeout i guess
1820 timeout.tv_usec = 0;
1822 FD_SET(sockfd, &fdset);
1823 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1825 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1831 ERR("POP3 connection failed: timeout\n");
1835 recvbuf[numbytes] = '\0';
1836 if (strstr(recvbuf, "+OK ") != recvbuf) {
1837 ERR("POP3 connection failed, probably not a POP3 server");
1841 strncpy(sendbuf, "USER ", MAXDATASIZE);
1842 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1843 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1844 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1845 perror("send USER");
1849 timeout.tv_sec = 60; // 60 second timeout i guess
1850 timeout.tv_usec = 0;
1852 FD_SET(sockfd, &fdset);
1853 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1855 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1856 perror("recv USER");
1861 recvbuf[numbytes] = '\0';
1862 if (strstr(recvbuf, "+OK ") == NULL) {
1863 ERR("POP3 server login failed: %s", recvbuf);
1867 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1868 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1869 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1870 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1871 perror("send PASS");
1875 timeout.tv_sec = 60; // 60 second timeout i guess
1876 timeout.tv_usec = 0;
1878 FD_SET(sockfd, &fdset);
1879 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1881 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1882 perror("recv PASS");
1887 recvbuf[numbytes] = '\0';
1888 if (strstr(recvbuf, "+OK ") == NULL) {
1889 ERR("POP3 server login failed: %s", recvbuf);
1893 strncpy(sendbuf, "STAT\r\n", MAXDATASIZE);
1894 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1895 perror("send STAT");
1899 timeout.tv_sec = 60; // 60 second timeout i guess
1900 timeout.tv_usec = 0;
1902 FD_SET(sockfd, &fdset);
1903 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1905 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1906 perror("recv STAT");
1911 recvbuf[numbytes] = '\0';
1912 if (strstr(recvbuf, "+OK ") == NULL) {
1913 ERR("POP3 status failed: %s", recvbuf);
1917 // now we get the data
1918 reply = recvbuf + 4;
1919 if (reply == NULL) {
1920 ERR("Error parsing POP3 response: %s", recvbuf);
1924 timed_thread_lock(mail->p_timed_thread);
1925 sscanf(reply, "%lu %lu", &mail->unseen, &mail->used);
1926 timed_thread_unlock(mail->p_timed_thread);
1928 strncpy(sendbuf, "QUIT\r\n", MAXDATASIZE);
1929 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1930 perror("send QUIT");
1934 timeout.tv_sec = 60; // 60 second timeout i guess
1935 timeout.tv_usec = 0;
1937 FD_SET(sockfd, &fdset);
1938 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1940 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1941 perror("recv QUIT");
1946 recvbuf[numbytes] = '\0';
1947 if (strstr(recvbuf, "+OK") == NULL) {
1948 ERR("POP3 logout failed: %s", recvbuf);
1952 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) {
1954 if (system(mail->command) == -1) {
1959 old_unseen = mail->unseen;
1961 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1962 /* if a valid socket, close it */
1965 if (timed_thread_test(mail->p_timed_thread)) {
1966 timed_thread_exit(mail->p_timed_thread);
1974 static inline void read_exec(const char *data, char *buf, const int size)
1976 FILE *fp = popen(data, "r");
1977 int length = fread(buf, 1, size, fp);
1981 if (length > 0 && buf[length - 1] == '\n') {
1982 buf[length - 1] = '\0';
1986 void *threaded_exec(void *) __attribute__((noreturn));
1988 void *threaded_exec(void *arg)
1991 struct text_object *obj = (struct text_object *)arg;
1994 p2 = obj->data.texeci.buffer;
1995 timed_thread_lock(obj->data.texeci.p_timed_thread);
1996 read_exec(obj->data.texeci.cmd, obj->data.texeci.buffer,
1999 if (*p2 == '\001') {
2004 timed_thread_unlock(obj->data.texeci.p_timed_thread);
2005 if (timed_thread_test(obj->data.texeci.p_timed_thread)) {
2006 timed_thread_exit(obj->data.texeci.p_timed_thread);
2012 static struct text_object *new_text_object_internal(void)
2014 struct text_object *obj = malloc(sizeof(struct text_object));
2015 memset(obj, 0, sizeof(struct text_object));
2019 static void free_text_objects(struct text_object_list *text_object_list)
2022 struct text_object *obj;
2024 if (text_object_list == NULL) {
2028 for (i = 0; i < text_object_list->text_object_count; i++) {
2029 obj = &text_object_list->text_objects[i];
2030 switch (obj->type) {
2039 close(obj->data.sysfs.fd);
2041 #endif /* !__OpenBSD__ */
2047 free(obj->data.tztime.tz);
2048 free(obj->data.tztime.fmt);
2051 free(obj->data.mboxscan.args);
2052 free(obj->data.mboxscan.output);
2056 free(obj->data.local_mail.box);
2061 case OBJ_imap_unseen:
2062 if (!obj->global_mode) {
2063 free(obj->data.mail);
2066 case OBJ_imap_messages:
2067 if (!obj->global_mode) {
2068 free(obj->data.mail);
2074 case OBJ_pop3_unseen:
2075 if (!obj->global_mode) {
2076 free(obj->data.mail);
2080 if (!obj->global_mode) {
2081 free(obj->data.mail);
2085 case OBJ_if_existing:
2086 case OBJ_if_mounted:
2087 case OBJ_if_running:
2088 free(obj->data.ifblock.s);
2089 free(obj->data.ifblock.str);
2092 free(obj->data.tail.logfile);
2093 free(obj->data.tail.buffer);
2105 case OBJ_iconv_start:
2110 case OBJ_disk_protect:
2111 free(objs[i].data.s);
2114 free(objs[i].data.ifblock.s);
2115 free(objs[i].data.ifblock.str);
2118 free(objs[i].data.ifblock.s);
2119 free(objs[i].data.ifblock.str);
2122 if (info.gw_info.iface) {
2123 free(info.gw_info.iface);
2124 info.gw_info.iface = 0;
2126 if (info.gw_info.ip) {
2127 free(info.gw_info.ip);
2128 info.gw_info.ip = 0;
2131 case OBJ_ioscheduler:
2133 free(objs[i].data.s);
2137 case OBJ_xmms2_artist:
2138 if (info.xmms2.artist) {
2139 free(info.xmms2.artist);
2140 info.xmms2.artist = 0;
2143 case OBJ_xmms2_album:
2144 if (info.xmms2.album) {
2145 free(info.xmms2.album);
2146 info.xmms2.album = 0;
2149 case OBJ_xmms2_title:
2150 if (info.xmms2.title) {
2151 free(info.xmms2.title);
2152 info.xmms2.title = 0;
2155 case OBJ_xmms2_genre:
2156 if (info.xmms2.genre) {
2157 free(info.xmms2.genre);
2158 info.xmms2.genre = 0;
2161 case OBJ_xmms2_comment:
2162 if (info.xmms2.comment) {
2163 free(info.xmms2.comment);
2164 info.xmms2.comment = 0;
2168 if (info.xmms2.url) {
2169 free(info.xmms2.url);
2173 case OBJ_xmms2_date:
2174 if (info.xmms2.date) {
2175 free(info.xmms2.date);
2176 info.xmms2.date = 0;
2179 case OBJ_xmms2_status:
2180 if (info.xmms2.status) {
2181 free(info.xmms2.status);
2182 info.xmms2.status = 0;
2185 case OBJ_xmms2_playlist:
2186 if (info.xmms2.playlist) {
2187 free(info.xmms2.playlist);
2188 info.xmms2.playlist = 0;
2191 case OBJ_xmms2_smart:
2192 if (info.xmms2.artist) {
2193 free(info.xmms2.artist);
2194 info.xmms2.artist = 0;
2196 if (info.xmms2.title) {
2197 free(info.xmms2.title);
2198 info.xmms2.title = 0;
2200 if (info.xmms2.url) {
2201 free(info.xmms2.url);
2207 case OBJ_bmpx_title:
2208 case OBJ_bmpx_artist:
2209 case OBJ_bmpx_album:
2210 case OBJ_bmpx_track:
2212 case OBJ_bmpx_bitrate:
2217 free(obj->data.rss.uri);
2218 free(obj->data.rss.action);
2227 case OBJ_battery_time:
2230 #endif /* !__OpenBSD__ */
2234 case OBJ_execigraph:
2235 free(obj->data.execi.cmd);
2236 free(obj->data.execi.buffer);
2239 free(obj->data.texeci.cmd);
2240 free(obj->data.texeci.buffer);
2242 case OBJ_nameserver:
2247 if (info.first_process) {
2248 free_all_processes();
2249 info.first_process = NULL;
2254 free(obj->data.hddtemp.dev);
2255 free(obj->data.hddtemp.addr);
2256 free(obj->data.hddtemp.temp);
2259 case OBJ_entropy_avail:
2260 case OBJ_entropy_poolsize:
2261 case OBJ_entropy_bar:
2263 case OBJ_user_names:
2264 if (info.users.names) {
2265 free(info.users.names);
2266 info.users.names = 0;
2269 case OBJ_user_terms:
2270 if (info.users.terms) {
2271 free(info.users.terms);
2272 info.users.terms = 0;
2275 case OBJ_user_times:
2276 if (info.users.times) {
2277 free(info.users.times);
2278 info.users.times = 0;
2283 case OBJ_smapi_bat_perc:
2286 case OBJ_if_smapi_bat_installed:
2287 free(obj->data.ifblock.s);
2288 free(obj->data.ifblock.str);
2297 case OBJ_mpd_artist:
2299 case OBJ_mpd_random:
2300 case OBJ_mpd_repeat:
2302 case OBJ_mpd_bitrate:
2303 case OBJ_mpd_status:
2306 case OBJ_mpd_password:
2308 case OBJ_mpd_elapsed:
2309 case OBJ_mpd_length:
2313 case OBJ_mpd_percent:
2315 free_mpd_vars(&info.mpd);
2320 free(text_object_list->text_objects);
2321 text_object_list->text_objects = NULL;
2322 text_object_list->text_object_count = 0;
2325 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2330 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2331 *a = mixer_init(buf1);
2332 scan_bar(arg + n, w, h);
2334 *a = mixer_init(NULL);
2335 scan_bar(arg, w, h);
2339 /* strip a leading /dev/ if any */
2340 #define DEV_NAME(x) x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 \
2343 /* construct_text_object() creates a new text_object */
2344 static struct text_object *construct_text_object(const char *s,
2345 const char *arg, unsigned int object_count,
2346 struct text_object *text_objects, long line)
2348 // struct text_object *obj = new_text_object();
2349 struct text_object *obj = new_text_object_internal();
2353 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
2354 obj->type = OBJ_##a; need_mask |= (1 << n); {
2355 #define END } } else
2359 obj->type = OBJ_color;
2360 obj->data.l = get_x11_color(s);
2364 OBJ(freq, INFO_FREQ)
2367 obj->data.i = open_acpi_temperature(arg);
2368 END OBJ(acpitempf, 0)
2369 obj->data.i = open_acpi_temperature(arg);
2370 END OBJ(acpiacadapter, 0)
2371 END OBJ(freq, INFO_FREQ)
2372 #endif /* !__OpenBSD__ */
2374 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2375 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2376 obj->data.cpu_index = 1;
2377 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
2378 "Displaying the clock for CPU 1."); */
2380 obj->data.cpu_index = atoi(&arg[0]);
2383 END OBJ(freq_g, INFO_FREQ)
2385 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2386 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2387 obj->data.cpu_index = 1;
2388 /* ERR("freq_g: Invalid CPU number or you don't have that many "
2389 "CPUs! Displaying the clock for CPU 1."); */
2391 obj->data.cpu_index = atoi(&arg[0]);
2394 #if defined(__linux__)
2395 END OBJ(voltage_mv, 0)
2397 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2398 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2399 obj->data.cpu_index = 1;
2400 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
2401 "CPUs! Displaying voltage for CPU 1."); */
2403 obj->data.cpu_index = atoi(&arg[0]);
2406 END OBJ(voltage_v, 0)
2408 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2409 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2410 obj->data.cpu_index = 1;
2411 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
2412 "CPUs! Displaying voltage for CPU 1."); */
2414 obj->data.cpu_index = atoi(&arg[0]);
2419 END OBJ(wireless_essid, INFO_NET)
2421 obj->data.net = get_net_stat(arg);
2423 CRIT_ERR("wireless_essid: needs an argument");
2425 END OBJ(wireless_mode, INFO_NET)
2427 obj->data.net = get_net_stat(arg);
2429 CRIT_ERR("wireless_mode: needs an argument");
2431 END OBJ(wireless_bitrate, INFO_NET)
2433 obj->data.net = get_net_stat(arg);
2435 CRIT_ERR("wireless_bitrate: needs an argument");
2437 END OBJ(wireless_ap, INFO_NET)
2439 obj->data.net = get_net_stat(arg);
2441 CRIT_ERR("wireless_ap: needs an argument");
2443 END OBJ(wireless_link_qual, INFO_NET)
2445 obj->data.net = get_net_stat(arg);
2447 CRIT_ERR("wireless_link_qual: needs an argument");
2449 END OBJ(wireless_link_qual_max, INFO_NET)
2451 obj->data.net = get_net_stat(arg);
2453 CRIT_ERR("wireless_link_qual_max: needs an argument");
2455 END OBJ(wireless_link_qual_perc, INFO_NET)
2457 obj->data.net = get_net_stat(arg);
2459 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2461 END OBJ(wireless_link_bar, INFO_NET)
2463 arg = scan_bar(arg, &obj->a, &obj->b);
2464 obj->data.net = get_net_stat(arg);
2466 CRIT_ERR("wireless_link_bar: needs an argument");
2468 #endif /* HAVE_IWLIB */
2470 #endif /* __linux__ */
2471 END OBJ(freq_dyn, 0)
2472 END OBJ(freq_dyn_g, 0)
2480 sscanf(arg, "%63s", bat);
2482 strcpy(bat, "BAT0");
2484 obj->data.s = strndup(bat, text_buffer_size);
2485 END OBJ(battery_time, 0)
2489 sscanf(arg, "%63s", bat);
2491 strcpy(bat, "BAT0");
2493 obj->data.s = strndup(bat, text_buffer_size);
2494 END OBJ(battery_percent, 0)
2498 sscanf(arg, "%63s", bat);
2500 strcpy(bat, "BAT0");
2502 obj->data.s = strndup(bat, text_buffer_size);
2503 END OBJ(battery_bar, 0)
2507 arg = scan_bar(arg, &obj->a, &obj->b);
2508 sscanf(arg, "%63s", bat);
2510 strcpy(bat, "BAT0");
2512 obj->data.s = strndup(bat, text_buffer_size);
2513 #endif /* !__OpenBSD__ */
2515 #if defined(__linux__)
2516 END OBJ(disk_protect, 0)
2518 obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
2520 CRIT_ERR("disk_protect needs an argument");
2521 END OBJ(i8k_version, INFO_I8K)
2522 END OBJ(i8k_bios, INFO_I8K)
2523 END OBJ(i8k_serial, INFO_I8K)
2524 END OBJ(i8k_cpu_temp, INFO_I8K)
2525 END OBJ(i8k_cpu_tempf, INFO_I8K)
2526 END OBJ(i8k_left_fan_status, INFO_I8K)
2527 END OBJ(i8k_right_fan_status, INFO_I8K)
2528 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2529 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2530 END OBJ(i8k_ac_status, INFO_I8K)
2531 END OBJ(i8k_buttons_status, INFO_I8K)
2533 END OBJ(ibm_temps, 0)
2535 CRIT_ERR("ibm_temps: needs an argument");
2537 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
2538 obj->data.sensor = 0;
2539 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
2540 "Using 0 (CPU temp sensor).");
2542 obj->data.sensor = atoi(&arg[0]);
2543 END OBJ(ibm_volume, 0)
2544 END OBJ(ibm_brightness, 0)
2546 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2547 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2550 ERR("if_up needs an argument");
2551 obj->data.ifblock.s = 0;
2553 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2554 blockstart[blockdepth] = object_count;
2555 obj->data.ifblock.pos = object_count + 2;
2558 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2559 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2561 blockstart[blockdepth] = object_count;
2562 obj->data.ifblock.pos = object_count + 2;
2564 END OBJ(ioscheduler, 0)
2566 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
2569 obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
2570 END OBJ(laptop_mode, 0)
2571 END OBJ(pb_battery, 0)
2572 if (arg && strcmp(arg, "status") == 0) {
2573 obj->data.i = PB_BATT_STATUS;
2574 } else if (arg && strcmp(arg, "percent") == 0) {
2575 obj->data.i = PB_BATT_PERCENT;
2576 } else if (arg && strcmp(arg, "time") == 0) {
2577 obj->data.i = PB_BATT_TIME;
2579 ERR("pb_battery: needs one argument: status, percent or time");
2584 #endif /* __linux__ */
2585 #if defined(__OpenBSD__)
2586 END OBJ(obsd_sensors_temp, 0)
2588 CRIT_ERR("obsd_sensors_temp: needs an argument");
2590 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2591 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2592 obj->data.sensor = 0;
2593 ERR("Invalid temperature sensor number!");
2595 obj->data.sensor = atoi(&arg[0]);
2596 END OBJ(obsd_sensors_fan, 0)
2598 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
2601 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2602 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2603 obj->data.sensor = 0;
2604 ERR("Invalid fan sensor number!");
2606 obj->data.sensor = atoi(&arg[0]);
2607 END OBJ(obsd_sensors_volt, 0)
2609 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
2612 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2613 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2614 obj->data.sensor = 0;
2615 ERR("Invalid voltage sensor number!");
2617 obj->data.sensor = atoi(&arg[0]);
2618 END OBJ(obsd_vendor, 0)
2619 END OBJ(obsd_product, 0)
2620 #endif /* __OpenBSD__ */
2621 END OBJ(buffers, INFO_BUFFERS)
2622 END OBJ(cached, INFO_BUFFERS)
2623 END OBJ(cpu, INFO_CPU)
2625 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2626 obj->data.cpu_index = atoi(&arg[3]);
2629 obj->data.cpu_index = 0;
2632 obj->data.cpu_index = 0;
2634 END OBJ(cpubar, INFO_CPU)
2636 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2637 obj->data.cpu_index = atoi(&arg[3]);
2640 obj->data.cpu_index = 0;
2642 scan_bar(arg, &obj->a, &obj->b);
2644 scan_bar(arg, &obj->a, &obj->b);
2645 obj->data.cpu_index = 0;
2647 END OBJ(cpugraph, INFO_CPU)
2648 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2652 if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
2653 obj->data.cpu_index = atoi(&buf[3]);
2655 obj->data.cpu_index = 0;
2659 END OBJ(loadgraph, INFO_LOADAVG)
2660 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2665 r = sscanf(arg, "%d", &a);
2667 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2670 #if defined(__linux__)
2671 END OBJ(diskio, INFO_DISKIO)
2673 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2675 obj->data.diskio = NULL;
2677 END OBJ(diskio_read, INFO_DISKIO)
2679 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2681 obj->data.diskio = NULL;
2683 END OBJ(diskio_write, INFO_DISKIO)
2685 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2687 obj->data.diskio = NULL;
2689 END OBJ(diskiograph, INFO_DISKIO)
2690 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2694 obj->data.diskio = prepare_diskio_stat(buf);
2697 obj->data.diskio = NULL;
2699 END OBJ(diskiograph_read, INFO_DISKIO)
2700 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2704 obj->data.diskio = prepare_diskio_stat(buf);
2707 obj->data.diskio = NULL;
2709 END OBJ(diskiograph_write, INFO_DISKIO)
2710 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2714 obj->data.diskio = prepare_diskio_stat(buf);
2717 obj->data.diskio = NULL;
2722 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2725 obj->data.l = color0;
2727 obj->data.l = color1;
2729 obj->data.l = color2;
2731 obj->data.l = color3;
2733 obj->data.l = color4;
2735 obj->data.l = color5;
2737 obj->data.l = color6;
2739 obj->data.l = color7;
2741 obj->data.l = color8;
2743 obj->data.l = color9;
2745 obj->data.s = scan_font(arg);
2746 END OBJ(conky_version, 0)
2747 END OBJ(conky_build_date, 0)
2748 END OBJ(conky_build_arch, 0)
2749 END OBJ(downspeed, INFO_NET)
2751 obj->data.net = get_net_stat(arg);
2753 CRIT_ERR("downspeed needs argument");
2755 END OBJ(downspeedf, INFO_NET)
2757 obj->data.net = get_net_stat(arg);
2759 CRIT_ERR("downspeedf needs argument");
2761 END OBJ(downspeedgraph, INFO_NET)
2762 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2766 obj->data.net = get_net_stat(buf);
2771 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos =
2773 blockstart[blockdepth - 1] = object_count;
2774 obj->data.ifblock.pos = object_count + 2;
2776 ERR("$else: no matching $if_*");
2781 text_objects[blockstart[blockdepth]].data.ifblock.pos =
2784 ERR("$endif: no matching $if_*");
2787 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2790 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2792 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2794 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2795 END OBJ(execgraph, 0)
2796 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2797 END OBJ(execibar, 0)
2800 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2803 ERR("${execibar <interval> command}");
2804 obj->type = OBJ_text;
2805 snprintf(buf, 256, "${%s}", s);
2806 obj->data.s = strndup(buf, text_buffer_size);
2808 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2810 END OBJ(execigraph, 0)
2813 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2816 ERR("${execigraph <interval> command}");
2817 obj->type = OBJ_text;
2818 snprintf(buf, 256, "${%s}", s);
2819 obj->data.s = strndup(buf, text_buffer_size);
2821 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2826 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2829 ERR("${execi <interval> command}");
2830 obj->type = OBJ_text;
2831 snprintf(buf, 256, "${%s}", s);
2832 obj->data.s = strndup(buf, text_buffer_size);
2834 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2835 obj->data.execi.buffer = malloc(text_buffer_size);
2840 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2843 ERR("${execi <interval> command}");
2844 obj->type = OBJ_text;
2845 snprintf(buf, 256, "${%s}", s);
2846 obj->data.s = strndup(buf, text_buffer_size);
2848 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2849 obj->data.execi.buffer = malloc(text_buffer_size);
2854 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2857 ERR("${texeci <interval> command}");
2858 obj->type = OBJ_text;
2859 snprintf(buf, 256, "${%s}", s);
2860 obj->data.s = strndup(buf, text_buffer_size);
2862 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
2863 obj->data.texeci.buffer = malloc(text_buffer_size);
2865 obj->data.texeci.p_timed_thread = NULL;
2866 END OBJ(pre_exec, 0)
2867 obj->type = OBJ_text;
2871 read_exec(arg, buf, sizeof(buf));
2872 obj->data.s = strndup(buf, text_buffer_size);
2874 obj->data.s = strndup("", text_buffer_size);
2877 END OBJ(fs_bar, INFO_FS)
2878 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2880 while (isspace(*arg)) {
2889 obj->data.fsbar.fs = prepare_fs_stat(arg);
2890 END OBJ(fs_bar_free, INFO_FS)
2891 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2893 while (isspace(*arg)) {
2903 obj->data.fsbar.fs = prepare_fs_stat(arg);
2904 END OBJ(fs_free, INFO_FS)
2908 obj->data.fs = prepare_fs_stat(arg);
2909 END OBJ(fs_used_perc, INFO_FS)
2913 obj->data.fs = prepare_fs_stat(arg);
2914 END OBJ(fs_free_perc, INFO_FS)
2918 obj->data.fs = prepare_fs_stat(arg);
2919 END OBJ(fs_size, INFO_FS)
2923 obj->data.fs = prepare_fs_stat(arg);
2924 END OBJ(fs_type, INFO_FS)
2928 obj->data.fs = prepare_fs_stat(arg);
2929 END OBJ(fs_used, INFO_FS)
2933 obj->data.fs = prepare_fs_stat(arg);
2935 obj->data.i = arg ? atoi(arg) : 1;
2936 END OBJ(nameserver, INFO_DNS)
2937 obj->data.i = arg ? atoi(arg) : 0;
2939 obj->data.i = arg ? atoi(arg) : 1;
2941 obj->data.i = arg ? atoi(arg) : 1;
2945 ERR("goto needs arguments");
2946 obj->type = OBJ_text;
2947 obj->data.s = strndup("${goto}", text_buffer_size);
2951 obj->data.i = atoi(arg);
2957 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2958 sscanf(arg, "%d", &b);
2964 obj->data.pair.a = a;
2965 obj->data.pair.b = b;
2968 END OBJ(i2c, INFO_SYSFS)
2969 char buf1[64], buf2[64];
2973 ERR("i2c needs arguments");
2974 obj->type = OBJ_text;
2975 // obj->data.s = strndup("${i2c}", text_buffer_size);
2979 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2980 /* if scanf couldn't read three values, read type and num and use
2982 sscanf(arg, "%63s %d", buf2, &n);
2983 obj->data.sysfs.fd = open_i2c_sensor(0, buf2, n,
2984 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2985 strncpy(obj->data.sysfs.type, buf2, 63);
2987 obj->data.sysfs.fd = open_i2c_sensor(buf1, buf2, n,
2988 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2989 strncpy(obj->data.sysfs.type, buf2, 63);
2992 END OBJ(platform, INFO_SYSFS)
2993 char buf1[64], buf2[64];
2997 ERR("platform needs arguments");
2998 obj->type = OBJ_text;
3002 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
3003 /* if scanf couldn't read three values, read type and num and use
3005 sscanf(arg, "%63s %d", buf2, &n);
3006 obj->data.sysfs.fd = open_platform_sensor(0, buf2, n,
3007 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3008 strncpy(obj->data.sysfs.type, buf2, 63);
3010 obj->data.sysfs.fd = open_platform_sensor(buf1, buf2, n,
3011 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3012 strncpy(obj->data.sysfs.type, buf2, 63);
3015 END OBJ(hwmon, INFO_SYSFS)
3016 char buf1[64], buf2[64];
3020 ERR("hwmon needs argumanets");
3021 obj->type = OBJ_text;
3025 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
3026 /* if scanf couldn't read three values, read type and num and use
3028 sscanf(arg, "%63s %d", buf2, &n);
3029 obj->data.sysfs.fd = open_hwmon_sensor(0, buf2, n,
3030 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3031 strncpy(obj->data.sysfs.type, buf2, 63);
3033 obj->data.sysfs.fd = open_hwmon_sensor(buf1, buf2, n,
3034 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3035 strncpy(obj->data.sysfs.type, buf2, 63);
3037 #endif /* !__OpenBSD__ */
3039 END OBJ(top, INFO_TOP)
3044 ERR("top needs arguments");
3045 obj->type = OBJ_text;
3046 // obj->data.s = strndup("${top}", text_buffer_size);
3049 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
3050 if (strcmp(buf, "name") == 0) {
3051 obj->data.top.type = TOP_NAME;
3052 } else if (strcmp(buf, "cpu") == 0) {
3053 obj->data.top.type = TOP_CPU;
3054 } else if (strcmp(buf, "pid") == 0) {
3055 obj->data.top.type = TOP_PID;
3056 } else if (strcmp(buf, "mem") == 0) {
3057 obj->data.top.type = TOP_MEM;
3058 } else if (strcmp(buf, "time") == 0) {
3059 obj->data.top.type = TOP_TIME;
3060 } else if (strcmp(buf, "mem_res") == 0) {
3061 obj->data.top.type = TOP_MEM_RES;
3062 } else if (strcmp(buf, "mem_vsize") == 0) {
3063 obj->data.top.type = TOP_MEM_VSIZE;
3065 ERR("invalid arg for top");
3068 if (n < 1 || n > 10) {
3069 CRIT_ERR("invalid arg for top");
3072 obj->data.top.num = n - 1;
3076 ERR("invalid args given for top");
3079 END OBJ(top_mem, INFO_TOP)
3084 ERR("top_mem needs arguments");
3085 obj->type = OBJ_text;
3086 obj->data.s = strndup("${top_mem}", text_buffer_size);
3089 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
3090 if (strcmp(buf, "name") == 0) {
3091 obj->data.top.type = TOP_NAME;
3092 } else if (strcmp(buf, "cpu") == 0) {
3093 obj->data.top.type = TOP_CPU;
3094 } else if (strcmp(buf, "pid") == 0) {
3095 obj->data.top.type = TOP_PID;
3096 } else if (strcmp(buf, "mem") == 0) {
3097 obj->data.top.type = TOP_MEM;
3098 } else if (strcmp(buf, "time") == 0) {
3099 obj->data.top.type = TOP_TIME;
3100 } else if (strcmp(buf, "mem_res") == 0) {
3101 obj->data.top.type = TOP_MEM_RES;
3102 } else if (strcmp(buf, "mem_vsize") == 0) {
3103 obj->data.top.type = TOP_MEM_VSIZE;
3105 ERR("invalid arg for top");
3108 if (n < 1 || n > 10) {
3109 CRIT_ERR("invalid arg for top");
3112 obj->data.top.num = n - 1;
3116 ERR("invalid args given for top");
3119 END OBJ(addr, INFO_NET)
3121 obj->data.net = get_net_stat(arg);
3123 CRIT_ERR("addr needs argument");
3125 #if defined(__linux__)
3126 END OBJ(addrs, INFO_NET)
3128 obj->data.net = get_net_stat(arg);
3130 CRIT_ERR("addrs needs argument");
3132 #endif /* __linux__ */
3139 ERR("tail needs arguments");
3140 obj->type = OBJ_text;
3141 obj->data.s = strndup("${tail}", text_buffer_size);
3144 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3145 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3146 CRIT_ERR("invalid arg for tail, number of lines must be "
3147 "between 1 and %i", MAX_TAIL_LINES);
3153 obj->data.tail.fd = -1;
3155 if (stat(buf, &st) == 0) {
3156 if (S_ISFIFO(st.st_mode)) {
3157 fd = open(buf, O_RDONLY | O_NONBLOCK);
3160 CRIT_ERR("tail logfile does not exist, or you do "
3161 "not have correct permissions");
3164 obj->data.tail.fd = fd;
3166 fp = fopen(buf, "r");
3170 if (fp || obj->data.tail.fd != -1) {
3171 obj->data.tail.logfile = malloc(text_buffer_size);
3172 strcpy(obj->data.tail.logfile, buf);
3173 obj->data.tail.wantedlines = n1;
3174 obj->data.tail.interval = update_interval * 2;
3176 if (obj->data.tail.fd == -1) {
3181 CRIT_ERR("tail logfile does not exist, or you do not have "
3182 "correct permissions");
3185 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3186 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3187 CRIT_ERR("invalid arg for tail, number of lines must be "
3188 "between 1 and %i", MAX_TAIL_LINES);
3190 } else if (n2 < 1 || n2 < update_interval) {
3191 CRIT_ERR("invalid arg for tail, interval must be greater than "
3192 "0 and Conky's interval");
3198 obj->data.tail.fd = -1;
3200 if (stat(buf, &st) == 0) {
3201 if (S_ISFIFO(st.st_mode)) {
3202 fd = open(buf, O_RDONLY | O_NONBLOCK);
3205 CRIT_ERR("tail logfile does not exist, or you do "
3206 "not have correct permissions");
3209 obj->data.tail.fd = fd;
3211 fp = fopen(buf, "r");
3215 if (fp || obj->data.tail.fd != -1) {
3216 obj->data.tail.logfile = malloc(text_buffer_size);
3217 strcpy(obj->data.tail.logfile, buf);
3218 obj->data.tail.wantedlines = n1;
3219 obj->data.tail.interval = n2;
3221 if (obj->data.tail.fd == -1) {
3226 CRIT_ERR("tail logfile does not exist, or you do not have "
3227 "correct permissions");
3231 ERR("invalid args given for tail");
3234 /* asumming all else worked */
3235 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3241 ERR("head needs arguments");
3242 obj->type = OBJ_text;
3243 obj->data.s = strndup("${head}", text_buffer_size);
3246 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3247 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3248 CRIT_ERR("invalid arg for head, number of lines must be "
3249 "between 1 and %i", MAX_TAIL_LINES);
3254 fp = fopen(buf, "r");
3256 obj->data.tail.logfile = malloc(text_buffer_size);
3257 strcpy(obj->data.tail.logfile, buf);
3258 obj->data.tail.wantedlines = n1;
3259 obj->data.tail.interval = update_interval * 2;
3263 CRIT_ERR("head logfile does not exist, or you do not have "
3264 "correct permissions");
3267 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3268 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3269 CRIT_ERR("invalid arg for head, number of lines must be "
3270 "between 1 and %i", MAX_TAIL_LINES);
3272 } else if (n2 < 1 || n2 < update_interval) {
3273 CRIT_ERR("invalid arg for head, interval must be greater than "
3274 "0 and Conky's interval");
3279 fp = fopen(buf, "r");
3281 obj->data.tail.logfile = malloc(text_buffer_size);
3282 strcpy(obj->data.tail.logfile, buf);
3283 obj->data.tail.wantedlines = n1;
3284 obj->data.tail.interval = n2;
3288 CRIT_ERR("head logfile does not exist, or you do not have "
3289 "correct permissions");
3293 ERR("invalid args given for head");
3296 /* asumming all else worked */
3297 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3298 END OBJ(loadavg, INFO_LOADAVG)
3299 int a = 1, b = 2, c = 3, r = 3;
3302 r = sscanf(arg, "%d %d %d", &a, &b, &c);
3303 if (r >= 3 && (c < 1 || c > 3)) {
3306 if (r >= 2 && (b < 1 || b > 3)) {
3309 if (r >= 1 && (a < 1 || a > 3)) {
3313 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
3314 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
3315 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
3316 END OBJ(if_empty, 0)
3317 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3318 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3321 ERR("if_empty 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_existing, 0)
3330 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3331 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3334 ERR("if_existing needs an argument or two");
3335 obj->data.ifblock.s = NULL;
3336 obj->data.ifblock.str = NULL;
3338 char buf1[256], buf2[256];
3339 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3342 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
3343 obj->data.ifblock.str = NULL;
3345 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
3346 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
3349 blockstart[blockdepth] = object_count;
3350 obj->data.ifblock.pos = object_count + 2;
3352 END OBJ(if_mounted, 0)
3353 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3354 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3357 ERR("if_mounted needs an argument");
3358 obj->data.ifblock.s = 0;
3360 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3362 blockstart[blockdepth] = object_count;
3363 obj->data.ifblock.pos = object_count + 2;
3365 END OBJ(if_running, 0)
3366 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3367 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3372 snprintf(buf, 256, "pidof %s >/dev/null", arg);
3373 obj->data.ifblock.s = strndup(buf, text_buffer_size);
3375 ERR("if_running needs an argument");
3376 obj->data.ifblock.s = 0;
3378 blockstart[blockdepth] = object_count;
3379 obj->data.ifblock.pos = object_count + 2;
3385 char box[256], dst[256];
3389 /* Kapil: Changed from MAIL_FILE to
3390 current_mail_spool since the latter
3391 is a copy of the former if undefined
3392 but the latter should take precedence
3394 strncpy(box, current_mail_spool, sizeof(box));
3396 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3398 strncpy(box, arg, sizeof(box));
3402 variable_substitute(box, dst, sizeof(dst));
3403 obj->data.local_mail.box = strndup(dst, text_buffer_size);
3404 obj->data.local_mail.interval = n1;
3405 END OBJ(mboxscan, 0)
3406 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
3407 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
3408 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
3409 obj->data.mboxscan.output[0] = 1;
3410 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
3411 END OBJ(mem, INFO_MEM)
3412 END OBJ(memmax, INFO_MEM)
3413 END OBJ(memperc, INFO_MEM)
3414 END OBJ(membar, INFO_MEM)
3415 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3416 END OBJ(memgraph, INFO_MEM)
3417 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3423 END OBJ(mixer, INFO_MIXER)
3424 obj->data.l = mixer_init(arg);
3425 END OBJ(mixerl, INFO_MIXER)
3426 obj->data.l = mixer_init(arg);
3427 END OBJ(mixerr, INFO_MIXER)
3428 obj->data.l = mixer_init(arg);
3429 END OBJ(mixerbar, INFO_MIXER)
3430 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3431 &obj->data.mixerbar.h);
3432 END OBJ(mixerlbar, INFO_MIXER)
3433 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3434 &obj->data.mixerbar.h);
3435 END OBJ(mixerrbar, INFO_MIXER)
3436 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3437 &obj->data.mixerbar.h);
3438 END OBJ(new_mails, 0)
3440 char box[256], dst[256];
3444 /* Kapil: Changed from MAIL_FILE to
3445 current_mail_spool since the latter
3446 is a copy of the former if undefined
3447 but the latter should take precedence
3449 strncpy(box, current_mail_spool, sizeof(box));
3451 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3453 strncpy(box, arg, sizeof(box));
3457 variable_substitute(box, dst, sizeof(dst));
3458 obj->data.local_mail.box = strndup(dst, text_buffer_size);
3459 obj->data.local_mail.interval = n1;
3460 END OBJ(nodename, 0)
3461 END OBJ(processes, INFO_PROCS)
3462 END OBJ(running_processes, INFO_RUN_PROCS)
3463 END OBJ(shadecolor, 0)
3465 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
3467 END OBJ(outlinecolor, 0)
3469 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
3471 END OBJ(stippled_hr, 0)
3473 int a = stippled_borders, b = 1;
3476 if (sscanf(arg, "%d %d", &a, &b) != 2) {
3477 sscanf(arg, "%d", &b);
3483 obj->data.pair.a = a;
3484 obj->data.pair.b = b;
3486 END OBJ(swap, INFO_MEM)
3487 END OBJ(swapmax, INFO_MEM)
3488 END OBJ(swapperc, INFO_MEM)
3489 END OBJ(swapbar, INFO_MEM)
3490 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3493 END OBJ(temp1, INFO_SYSFS)
3494 obj->type = OBJ_i2c;
3495 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 1,
3496 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3497 END OBJ(temp2, INFO_SYSFS)
3498 obj->type = OBJ_i2c;
3499 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 2,
3500 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3503 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
3505 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
3507 char buf1[256], buf2[256], *fmt, *tz;
3511 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3521 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
3522 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
3524 END OBJ(iconv_start, 0)
3525 if (iconv_converting) {
3526 CRIT_ERR("You must stop your last iconv conversion before "
3527 "starting another");
3530 char iconv_from[CODEPAGE_LENGTH];
3531 char iconv_to[CODEPAGE_LENGTH];
3533 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3534 CRIT_ERR("Invalid arguments for iconv_start");
3538 new_iconv = iconv_open(iconv_to, iconv_from);
3539 if (new_iconv == (iconv_t) (-1)) {
3540 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3542 obj->a = register_iconv(&new_iconv);
3543 iconv_converting = 1;
3547 CRIT_ERR("Iconv requires arguments");
3549 END OBJ(iconv_stop, 0)
3550 iconv_converting = 0;
3553 END OBJ(totaldown, INFO_NET)
3555 obj->data.net = get_net_stat(arg);
3557 CRIT_ERR("totaldown needs argument");
3559 END OBJ(totalup, INFO_NET)
3560 obj->data.net = get_net_stat(arg);
3562 obj->data.net = get_net_stat(arg);
3564 CRIT_ERR("totalup needs argument");
3568 obj->data.i = arg ? atoi(arg) : 0;
3570 obj->data.i = arg ? atoi(arg) : 0;
3571 END OBJ(upspeed, INFO_NET)
3573 obj->data.net = get_net_stat(arg);
3575 CRIT_ERR("upspeed needs argument");
3577 END OBJ(upspeedf, INFO_NET)
3579 obj->data.net = get_net_stat(arg);
3581 CRIT_ERR("upspeedf needs argument");
3584 END OBJ(upspeedgraph, INFO_NET)
3585 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3589 obj->data.net = get_net_stat(buf);
3592 END OBJ(uptime_short, INFO_UPTIME)
3593 END OBJ(uptime, INFO_UPTIME)
3594 END OBJ(user_names, INFO_USERS)
3595 END OBJ(user_times, INFO_USERS)
3596 END OBJ(user_terms, INFO_USERS)
3597 END OBJ(user_number, INFO_USERS)
3598 #if defined(__linux__)
3599 END OBJ(gw_iface, INFO_GW)
3600 END OBJ(gw_ip, INFO_GW)
3601 END OBJ(if_gw, INFO_GW)
3602 #endif /* !__linux__ */
3604 END OBJ(adt746xcpu, 0)
3605 END OBJ(adt746xfan, 0)
3606 #endif /* !__OpenBSD__ */
3607 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
3608 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3609 END OBJ(apm_adapter, 0)
3610 END OBJ(apm_battery_life, 0)
3611 END OBJ(apm_battery_time, 0)
3612 #endif /* __FreeBSD__ */
3613 END OBJ(imap_unseen, 0)
3616 obj->data.mail = parse_mail_args(IMAP, arg);
3617 obj->global_mode = 0;
3619 obj->global_mode = 1;
3621 END OBJ(imap_messages, 0)
3624 obj->data.mail = parse_mail_args(IMAP, arg);
3625 obj->global_mode = 0;
3627 obj->global_mode = 1;
3629 END OBJ(pop3_unseen, 0)
3632 obj->data.mail = parse_mail_args(POP3, arg);
3633 obj->global_mode = 0;
3635 obj->global_mode = 1;
3637 END OBJ(pop3_used, 0)
3640 obj->data.mail = parse_mail_args(POP3, arg);
3641 obj->global_mode = 0;
3643 obj->global_mode = 1;
3648 obj->data.s = strndup(arg, text_buffer_size);
3650 ERR("smapi needs an argument");
3651 END OBJ(if_smapi_bat_installed, 0)
3652 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3653 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3656 ERR("if_smapi_bat_installed needs an argument");
3657 obj->data.ifblock.s = 0;
3659 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3660 blockstart[blockdepth] = object_count;
3661 obj->data.ifblock.pos = object_count + 2;
3663 END OBJ(smapi_bat_perc, 0)
3665 obj->data.s = strndup(arg, text_buffer_size);
3667 ERR("smapi_bat_perc needs an argument");
3668 END OBJ(smapi_bat_bar, 0)
3671 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
3672 ERR("first argument to smapi_bat_bar must be an integer value");
3676 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
3679 ERR("if_smapi_bat_bar needs an argument");
3682 END OBJ(mpd_artist, INFO_MPD)
3683 END OBJ(mpd_title, INFO_MPD)
3685 sscanf(arg, "%d", &info.mpd.max_title_len);
3686 if (info.mpd.max_title_len > 0) {
3687 info.mpd.max_title_len++;
3689 CRIT_ERR("mpd_title: invalid length argument");
3692 info.mpd.max_title_len = 0;
3694 END OBJ(mpd_random, INFO_MPD)
3695 END OBJ(mpd_repeat, INFO_MPD)
3696 END OBJ(mpd_elapsed, INFO_MPD)
3697 END OBJ(mpd_length, INFO_MPD)
3698 END OBJ(mpd_track, INFO_MPD)
3699 END OBJ(mpd_name, INFO_MPD)
3700 END OBJ(mpd_file, INFO_MPD)
3701 END OBJ(mpd_percent, INFO_MPD)
3702 END OBJ(mpd_album, INFO_MPD)
3703 END OBJ(mpd_vol, INFO_MPD)
3704 END OBJ(mpd_bitrate, INFO_MPD)
3705 END OBJ(mpd_status, INFO_MPD)
3706 END OBJ(mpd_bar, INFO_MPD)
3707 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3708 END OBJ(mpd_smart, INFO_MPD)
3711 END OBJ(xmms2_artist, INFO_XMMS2)
3712 END OBJ(xmms2_album, INFO_XMMS2)
3713 END OBJ(xmms2_title, INFO_XMMS2)
3714 END OBJ(xmms2_genre, INFO_XMMS2)
3715 END OBJ(xmms2_comment, INFO_XMMS2)
3716 END OBJ(xmms2_url, INFO_XMMS2)
3717 END OBJ(xmms2_tracknr, INFO_XMMS2)
3718 END OBJ(xmms2_bitrate, INFO_XMMS2)
3719 END OBJ(xmms2_date, INFO_XMMS2)
3720 END OBJ(xmms2_id, INFO_XMMS2)
3721 END OBJ(xmms2_duration, INFO_XMMS2)
3722 END OBJ(xmms2_elapsed, INFO_XMMS2)
3723 END OBJ(xmms2_size, INFO_XMMS2)
3724 END OBJ(xmms2_status, INFO_XMMS2)
3725 END OBJ(xmms2_percent, INFO_XMMS2)
3726 END OBJ(xmms2_bar, INFO_XMMS2)
3727 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3728 END OBJ(xmms2_smart, INFO_XMMS2)
3729 END OBJ(xmms2_playlist, INFO_XMMS2)
3730 END OBJ(xmms2_timesplayed, INFO_XMMS2)
3733 END OBJ(audacious_status, INFO_AUDACIOUS)
3734 END OBJ(audacious_title, INFO_AUDACIOUS)
3736 sscanf(arg, "%d", &info.audacious.max_title_len);
3737 if (info.audacious.max_title_len > 0) {
3738 info.audacious.max_title_len++;
3740 CRIT_ERR("audacious_title: invalid length argument");
3743 END OBJ(audacious_length, INFO_AUDACIOUS)
3744 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
3745 END OBJ(audacious_position, INFO_AUDACIOUS)
3746 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
3747 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
3748 END OBJ(audacious_frequency, INFO_AUDACIOUS)
3749 END OBJ(audacious_channels, INFO_AUDACIOUS)
3750 END OBJ(audacious_filename, INFO_AUDACIOUS)
3751 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
3752 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
3753 END OBJ(audacious_bar, INFO_AUDACIOUS)
3754 scan_bar(arg, &obj->a, &obj->b);
3757 END OBJ(bmpx_title, INFO_BMPX)
3758 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3759 END OBJ(bmpx_artist, INFO_BMPX)
3760 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3761 END OBJ(bmpx_album, INFO_BMPX)
3762 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3763 END OBJ(bmpx_track, INFO_BMPX)
3764 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3765 END OBJ(bmpx_uri, INFO_BMPX)
3766 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3767 END OBJ(bmpx_bitrate, INFO_BMPX)
3768 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3773 int argc, delay, act_par;
3774 char *uri = (char *) malloc(128 * sizeof(char));
3775 char *action = (char *) malloc(64 * sizeof(char));
3777 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action,
3779 obj->data.rss.uri = uri;
3780 obj->data.rss.delay = delay;
3781 obj->data.rss.action = action;
3782 obj->data.rss.act_par = act_par;
3786 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
3792 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3793 &obj->data.hddtemp.addr, &obj->data.hddtemp.port, &obj->data.hddtemp.temp)) {
3794 ERR("hddtemp needs arguments");
3795 obj->type = OBJ_text;
3796 obj->data.s = strndup("${hddtemp}", text_buffer_size);
3797 obj->data.hddtemp.update_time = 0;
3801 #ifdef TCP_PORT_MONITOR
3802 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3803 int argc, port_begin, port_end, item, connection_index;
3806 memset(itembuf, 0, sizeof(itembuf));
3807 connection_index = 0;
3808 /* massive argument checking */
3810 CRIT_ERR("tcp_portmon: needs arguments");
3812 argc = sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf,
3814 if ((argc != 3) && (argc != 4)) {
3815 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3817 if ((port_begin < 1) || (port_begin > 65535) || (port_end < 1)
3818 || (port_end > 65535)) {
3819 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3821 if (port_begin > port_end) {
3822 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3824 if (strncmp(itembuf, "count", 31) == 0) {
3826 } else if (strncmp(itembuf, "rip", 31) == 0) {
3828 } else if (strncmp(itembuf, "rhost", 31) == 0) {
3830 } else if (strncmp(itembuf, "rport", 31) == 0) {
3832 } else if (strncmp(itembuf, "rservice", 31) == 0) {
3833 item = REMOTESERVICE;
3834 } else if (strncmp(itembuf, "lip", 31) == 0) {
3836 } else if (strncmp(itembuf, "lhost", 31) == 0) {
3838 } else if (strncmp(itembuf, "lport", 31) == 0) {
3840 } else if (strncmp(itembuf, "lservice", 31) == 0) {
3841 item = LOCALSERVICE;
3843 CRIT_ERR("tcp_portmon: invalid item specified");
3845 if ((argc == 3) && (item != COUNT)) {
3846 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" "
3849 if ((argc == 4) && (connection_index < 0)) {
3850 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3852 /* ok, args looks good. save the text object data */
3853 obj->data.tcp_port_monitor.port_range_begin = (in_port_t) port_begin;
3854 obj->data.tcp_port_monitor.port_range_end = (in_port_t) port_end;
3855 obj->data.tcp_port_monitor.item = item;
3856 obj->data.tcp_port_monitor.connection_index = connection_index;
3858 /* if the port monitor collection hasn't been created,
3859 * we must create it */
3860 if (!info.p_tcp_port_monitor_collection) {
3861 info.p_tcp_port_monitor_collection =
3862 create_tcp_port_monitor_collection();
3863 if (!info.p_tcp_port_monitor_collection) {
3864 CRIT_ERR("tcp_portmon: unable to create port monitor "
3869 /* if a port monitor for this port does not exist,
3870 * create one and add it to the collection */
3871 if (find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
3872 port_begin, port_end) == NULL) {
3873 tcp_port_monitor_t *p_monitor = create_tcp_port_monitor(port_begin,
3874 port_end, &tcp_port_monitor_args);
3877 CRIT_ERR("tcp_portmon: unable to create port monitor");
3879 /* add the newly created monitor to the collection */
3880 if (insert_tcp_port_monitor_into_collection(
3881 info.p_tcp_port_monitor_collection, p_monitor) != 0) {
3882 CRIT_ERR("tcp_portmon: unable to add port monitor to "
3887 END OBJ(entropy_avail, INFO_ENTROPY)
3888 END OBJ(entropy_poolsize, INFO_ENTROPY)
3889 END OBJ(entropy_bar, INFO_ENTROPY)
3890 scan_bar(arg, &obj->a, &obj->b);
3894 CRIT_ERR("nvidia needs one argument "
3895 "[temp,threshold,gpufreq,memfreq,imagequality]");
3897 if (strcmp(arg, "temp") == 0)
3898 obj->data.nvidia.type = NV_TEMP;
3899 else if (strcmp(arg, "threshold") == 0)
3900 obj->data.nvidia.type = NV_TEMP_THRESHOLD;
3901 else if (strcmp(arg, "gpufreq") == 0)
3902 obj->data.nvidia.type = NV_GPU_FREQ;
3903 else if (strcmp(arg, "memfreq") == 0)
3904 obj->data.nvidia.type = NV_MEM_FREQ;
3905 else if (strcmp(arg, "imagequality") == 0)
3906 obj->data.nvidia.type = NV_IMAGE_QUALITY;
3908 CRIT_ERR("you have to give one of these arguments "
3909 "[temp,threshold,gpufreq,memfreq,imagequality");
3910 strncpy((char*)&obj->data.nvidia.arg, arg, 20);
3916 ERR("unknown variable %s", s);
3917 obj->type = OBJ_text;
3918 snprintf(buf, 256, "${%s}", s);
3919 obj->data.s = strndup(buf, text_buffer_size);
3926 static struct text_object *create_plain_text(const char *s)
3928 struct text_object *obj;
3930 if (s == NULL || *s == '\0') {
3934 obj = new_text_object_internal();
3936 obj->type = OBJ_text;
3937 obj->data.s = strndup(s, text_buffer_size);
3941 static struct text_object_list *extract_variable_text_internal(const char *const_p)
3943 struct text_object_list *retval;
3944 struct text_object *obj;
3945 char *p, *s, *orig_p;
3948 p = strndup(const_p, max_user_text);
3951 retval = malloc(sizeof(struct text_object_list));
3952 memset(retval, 0, sizeof(struct text_object_list));
3953 retval->text_object_count = 0;
3955 line = global_text_lines;
3963 obj = create_plain_text(s);
3965 // allocate memory for the object
3966 retval->text_objects = realloc(retval->text_objects,
3967 sizeof(struct text_object) *
3968 (retval->text_object_count + 1));
3969 // assign the new object to the end of the list.
3970 memcpy(&retval->text_objects[retval->text_object_count++], obj,
3971 sizeof(struct text_object));
3983 /* variable is either $foo or ${foo} */
3985 unsigned int brl = 1, brr = 0;
3989 while (*p && brl != brr) {
4004 while (*p && (isalnum((int) *p) || *p == '_')) {
4009 /* copy variable to buffer */
4010 len = (p - s > 255) ? 255 : (p - s);
4011 strncpy(buf, s, len);
4021 /* if variable wasn't found in environment, use some special */
4027 if (strchr(buf, ' ')) {
4028 arg = strchr(buf, ' ');
4031 while (isspace((int) *arg)) {
4039 /* lowercase variable name */
4042 *tmp_p = tolower(*tmp_p);
4046 // create new object
4047 obj = construct_text_object(buf, arg,
4048 retval->text_object_count, retval->text_objects, line);
4050 // allocate memory for the object
4051 retval->text_objects = realloc(retval->text_objects,
4052 sizeof(struct text_object) *
4053 (retval->text_object_count + 1));
4054 // assign the new object to the end of the list.
4056 &retval->text_objects[retval->text_object_count++],
4057 obj, sizeof(struct text_object));
4063 obj = create_plain_text("$");
4065 // allocate memory for the object
4066 retval->text_objects = realloc(retval->text_objects,
4067 sizeof(struct text_object) *
4068 (retval->text_object_count + 1));
4069 // assign the new object to the end of the list.
4070 memcpy(&retval->text_objects[retval->text_object_count++],
4071 obj, sizeof(struct text_object));
4078 obj = create_plain_text(s);
4080 // allocate memory for the object
4081 retval->text_objects = realloc(retval->text_objects,
4082 sizeof(struct text_object) * (retval->text_object_count + 1));
4083 // assign the new object to the end of the list.
4084 memcpy(&retval->text_objects[retval->text_object_count++], obj,
4085 sizeof(struct text_object));
4090 ERR("one or more $endif's are missing");
4097 static void extract_variable_text(const char *p)
4099 free_text_objects(global_text_object_list);
4100 free(global_text_object_list);
4114 global_text_object_list = extract_variable_text_internal(p);
4117 struct text_object_list *parse_conky_vars(char *txt, char *p, struct information *cur)
4119 struct text_object_list *object_list =
4120 extract_variable_text_internal(txt);
4122 generate_text_internal(p, max_user_text, object_list, cur);
4126 /* Allows reading from a FIFO (i.e., /dev/xconsole).
4127 * The file descriptor is set to non-blocking which makes this possible.
4129 * FIXME: Since lseek cannot seek a file descriptor long lines will break. */
4130 static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
4132 #define TAIL_PIPE_BUFSIZE 4096
4136 int fd = obj->data.tail.fd;
4139 char buf[TAIL_PIPE_BUFSIZE];
4140 ssize_t len = read(fd, buf, sizeof(buf));
4144 if (errno != EAGAIN) {
4145 strcpy(obj->data.tail.buffer, "Logfile Read Error");
4146 snprintf(dst, dst_size, "Logfile Read Error");
4150 } else if (len == 0) {
4151 strcpy(obj->data.tail.buffer, "Logfile Empty");
4152 snprintf(dst, dst_size, "Logfile Empty");
4156 for (line_len = 0, i = 0; i < len; i++) {
4160 if (buf[i] == '\n') {
4163 if (obj->data.tail.readlines > 0) {
4168 for (n = 0; obj->data.tail.buffer[n]; n++) {
4169 if (obj->data.tail.buffer[n] == '\n') {
4174 if (++olines < obj->data.tail.wantedlines) {
4180 p = obj->data.tail.buffer + first_line;
4181 pos = n - first_line;
4182 memmove(obj->data.tail.buffer,
4183 obj->data.tail.buffer + first_line, strlen(p));
4184 obj->data.tail.buffer[pos] = 0;
4190 p = buf + last_line;
4192 memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
4193 obj->data.tail.buffer[pos + line_len] = 0;
4196 obj->data.tail.readlines = lines;
4204 snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
4207 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
4208 void *thread(void *), const char *text)
4210 if (obj->global_mode && info.mail) {
4211 // this means we use info
4212 if (!info.mail->p_timed_thread) {
4213 info.mail->p_timed_thread =
4214 timed_thread_create(thread,
4215 (void *) info.mail, info.mail->interval * 1000000);
4216 if (!info.mail->p_timed_thread) {
4217 ERR("Error creating %s timed thread", text);
4219 timed_thread_register(info.mail->p_timed_thread,
4220 &info.mail->p_timed_thread);
4221 if (timed_thread_run(info.mail->p_timed_thread)) {
4222 ERR("Error running %s timed thread", text);
4226 } else if (obj->data.mail) {
4227 // this means we use obj
4228 if (!obj->data.mail->p_timed_thread) {
4229 obj->data.mail->p_timed_thread =
4230 timed_thread_create(thread,
4231 (void *) obj->data.mail,
4232 obj->data.mail->interval * 1000000);
4233 if (!obj->data.mail->p_timed_thread) {
4234 ERR("Error creating %s timed thread", text);
4236 timed_thread_register(obj->data.mail->p_timed_thread,
4237 &obj->data.mail->p_timed_thread);
4238 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
4239 ERR("Error running %s timed thread", text);
4242 return obj->data.mail;
4243 } else if (!obj->a) {
4244 // something is wrong, warn once then stop
4245 ERR("Theres a problem with your %s_unseen settings. "
4246 "Check that the global %s settings are defined "
4247 "properly (line %li).", global_text, global_text, obj->line);
4253 char *format_time(unsigned long timeval, const int width)
4256 unsigned long nt; // narrow time, for speed on 32-bit
4257 unsigned cc; // centiseconds
4258 unsigned nn; // multi-purpose whatever
4261 cc = nt % 100; // centiseconds past second
4262 nt /= 100; // total seconds
4263 nn = nt % 60; // seconds past the minute
4264 nt /= 60; // total minutes
4265 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
4267 return strndup(buf, text_buffer_size);
4269 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
4270 return strndup(buf, text_buffer_size);
4272 nn = nt % 60; // minutes past the hour
4273 nt /= 60; // total hours
4274 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
4275 return strndup(buf, text_buffer_size);
4277 nn = nt; // now also hours
4278 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
4279 return strndup(buf, text_buffer_size);
4281 nn /= 24; // now days
4282 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
4283 return strndup(buf, text_buffer_size);
4285 nn /= 7; // now weeks
4286 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
4287 return strndup(buf, text_buffer_size);
4289 // well shoot, this outta' fit...
4290 return strndup("<inf>", text_buffer_size);
4293 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
4294 //string has to end with \0 and it's length should fit in a int
4296 void remove_deleted_chars(char *string){
4298 while(string[i] != 0){
4299 if(string[i] == BACKSPACE){
4301 strcpy( &(string[i-1]), &(string[i+1]) );
4303 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
4308 static inline void format_media_player_time(char *buf, const int size,
4311 int days, hours, minutes;
4313 days = seconds / (24 * 60 * 60);
4314 seconds %= (24 * 60 * 60);
4315 hours = seconds / (60 * 60);
4316 seconds %= (60 * 60);
4317 minutes = seconds / 60;
4321 snprintf(buf, size, "%i days %i:%02i:%02i", days,
4322 hours, minutes, seconds);
4323 } else if (hours > 0) {
4324 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
4327 snprintf(buf, size, "%i:%02i", minutes, seconds);
4331 static inline double get_barnum(char *buf)
4343 if (sscanf(buf, "%lf", &barnum) == 0) {
4344 ERR("reading execbar value failed (perhaps it's not the "
4345 "correct format?)");
4348 if (barnum > 100.0 || barnum < 0.0) {
4349 ERR("your execbar value is not between 0 and 100, "
4350 "therefore it will be ignored");
4356 static void generate_text_internal(char *p, int p_max_size,
4357 struct text_object_list *text_object_list,
4358 struct information *cur)
4363 char buff_in[p_max_size];
4365 iconv_converting = 0;
4369 for (i = 0; i < text_object_list->text_object_count; i++) {
4370 struct text_object *obj = &(text_object_list->text_objects[i]);
4372 if (p_max_size < 1) {
4376 #define OBJ(a) break; case OBJ_##a:
4378 switch (obj->type) {
4380 ERR("not implemented obj type %d", obj->type);
4383 /* does anyone have decimals in acpi temperature? */
4384 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
4385 round_to_int(get_acpi_temperature(obj->data.i)));
4388 /* does anyone have decimals in acpi temperature? */
4389 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
4390 round_to_int((get_acpi_temperature(obj->data.i) + 40) *
4393 #endif /* !__OpenBSD__ */
4396 obj->a = get_freq(p, p_max_size, "%.0f", 1,
4397 obj->data.cpu_index);
4403 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
4404 obj->data.cpu_index);
4406 /* OpenBSD has no such flag (SUSv2) */
4407 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
4408 obj->data.cpu_index);
4412 #if defined(__linux__)
4415 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
4416 obj->data.cpu_index);
4421 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
4422 obj->data.cpu_index);
4427 OBJ(wireless_essid) {
4428 snprintf(p, p_max_size, "%s", obj->data.net->essid);
4430 OBJ(wireless_mode) {
4431 snprintf(p, p_max_size, "%s", obj->data.net->mode);
4433 OBJ(wireless_bitrate) {
4434 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
4437 snprintf(p, p_max_size, "%s", obj->data.net->ap);
4439 OBJ(wireless_link_qual) {
4440 spaced_print(p, p_max_size, "%d", 4, "wireless_link_qual",
4441 obj->data.net->link_qual);
4443 OBJ(wireless_link_qual_max) {
4444 spaced_print(p, p_max_size, "%d", 4,
4445 "wireless_link_qual_max", obj->data.net->link_qual_max);
4447 OBJ(wireless_link_qual_perc) {
4448 if (obj->data.net->link_qual_max > 0) {
4449 spaced_print(p, p_max_size, "%.0f", 5,
4450 "wireless_link_qual_perc",
4451 (double) obj->data.net->link_qual /
4452 obj->data.net->link_qual_max * 100);
4454 spaced_print(p, p_max_size, "unk", 5,
4455 "wireless_link_qual_perc");
4458 OBJ(wireless_link_bar) {
4459 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
4460 obj->data.net->link_qual_max) * 255.0);
4462 #endif /* HAVE_IWLIB */
4464 #endif /* __linux__ */
4467 get_freq_dynamic(p, p_max_size, "%.0f", 1);
4468 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4472 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
4474 get_freq_dynamic(p, p_max_size, "%.2f", 1000);
4476 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4481 get_adt746x_cpu(p, p_max_size);
4484 get_adt746x_fan(p, p_max_size);
4487 get_acpi_fan(p, p_max_size);
4489 OBJ(acpiacadapter) {
4490 get_acpi_ac_adapter(p, p_max_size);
4493 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
4496 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
4498 OBJ(battery_percent) {
4499 spaced_print(p, p_max_size, "%*d", 4, "battery_percent",
4500 pad_percents, get_battery_perct(obj->data.s));
4503 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
4505 #endif /* __OpenBSD__ */
4508 human_readable(cur->buffers * 1024, p, 255, "buffers");
4511 human_readable(cur->cached * 1024, p, 255, "buffers");
4514 if (obj->data.cpu_index > info.cpu_count) {
4515 printf("obj->data.cpu_index %i info.cpu_count %i",
4516 obj->data.cpu_index, info.cpu_count);
4517 CRIT_ERR("attempting to use more CPUs than you have!");
4519 spaced_print(p, p_max_size, "%*d", 4, "cpu", pad_percents,
4520 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
4523 new_bar(p, obj->a, obj->b,
4524 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
4527 new_graph(p, obj->a, obj->b, obj->c, obj->d, (unsigned int)
4528 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
4532 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
4536 new_fg(p, obj->data.l);
4568 OBJ(conky_version) {
4569 snprintf(p, p_max_size, "%s", VERSION);
4571 OBJ(conky_build_date) {
4572 snprintf(p, p_max_size, "%s", BUILD_DATE);
4574 OBJ(conky_build_arch) {
4575 snprintf(p, p_max_size, "%s", BUILD_ARCH);
4577 #if defined(__linux__)
4579 snprintf(p, p_max_size, "%s",
4580 get_disk_protect_queue(obj->data.s));
4583 snprintf(p, p_max_size, "%s", i8k.version);
4586 snprintf(p, p_max_size, "%s", i8k.bios);
4589 snprintf(p, p_max_size, "%s", i8k.serial);
4592 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
4594 OBJ(i8k_cpu_tempf) {
4597 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
4598 snprintf(p, p_max_size, "%.1f", cpu_temp * (9.0 / 5.0) + 32.0);
4600 OBJ(i8k_left_fan_status) {
4601 int left_fan_status;
4603 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
4604 if (left_fan_status == 0) {
4605 snprintf(p, p_max_size, "off");
4607 if (left_fan_status == 1) {
4608 snprintf(p, p_max_size, "low");
4610 if (left_fan_status == 2) {
4611 snprintf(p, p_max_size, "high");
4614 OBJ(i8k_right_fan_status) {
4615 int right_fan_status;
4617 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
4618 if (right_fan_status == 0) {
4619 snprintf(p, p_max_size, "off");
4621 if (right_fan_status == 1) {
4622 snprintf(p, p_max_size, "low");
4624 if (right_fan_status == 2) {
4625 snprintf(p, p_max_size, "high");
4628 OBJ(i8k_left_fan_rpm) {
4629 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
4631 OBJ(i8k_right_fan_rpm) {
4632 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
4634 OBJ(i8k_ac_status) {
4637 sscanf(i8k.ac_status, "%d", &ac_status);
4638 if (ac_status == -1) {
4639 snprintf(p, p_max_size, "disabled (read i8k docs)");
4641 if (ac_status == 0) {
4642 snprintf(p, p_max_size, "off");
4644 if (ac_status == 1) {
4645 snprintf(p, p_max_size, "on");
4648 OBJ(i8k_buttons_status) {
4649 snprintf(p, p_max_size, "%s", i8k.buttons_status);
4652 get_ibm_acpi_fan(p, p_max_size);
4655 get_ibm_acpi_temps();
4656 snprintf(p, p_max_size, "%d", ibm_acpi.temps[obj->data.sensor]);
4659 get_ibm_acpi_volume(p, p_max_size);
4661 OBJ(ibm_brightness) {
4662 get_ibm_acpi_brightness(p, p_max_size);
4665 if ((obj->data.ifblock.s)
4666 && (!interface_up(obj->data.ifblock.s))) {
4667 i = obj->data.ifblock.pos;
4674 if (!cur->gw_info.count) {
4675 i = obj->data.ifblock.pos;
4682 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
4685 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
4688 snprintf(p, p_max_size, "%d", get_laptop_mode());
4691 get_powerbook_batt_info(p, p_max_size, obj->data.i);
4693 #endif /* __linux__ */
4696 OBJ(obsd_sensors_temp) {
4697 obsd_sensors.device = sensor_device;
4698 update_obsd_sensors();
4699 snprintf(p, p_max_size, "%.1f",
4700 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
4702 OBJ(obsd_sensors_fan) {
4703 obsd_sensors.device = sensor_device;
4704 update_obsd_sensors();
4705 snprintf(p, p_max_size, "%d",
4706 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
4708 OBJ(obsd_sensors_volt) {
4709 obsd_sensors.device = sensor_device;
4710 update_obsd_sensors();
4711 snprintf(p, p_max_size, "%.2f",
4712 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4715 get_obsd_vendor(p, p_max_size);
4718 get_obsd_product(p, p_max_size);
4720 #endif /* __OpenBSD__ */
4724 new_font(p, obj->data.s);
4727 /* TODO: move this correction from kB to kB/s elsewhere
4728 * (or get rid of it??) */
4730 if (obj->data.diskio) {
4732 (obj->data.diskio->current / update_interval) * 1024LL,
4733 p, p_max_size, "diskio");
4735 human_readable(info.diskio_value * 1024LL, p, p_max_size,
4740 if (obj->data.diskio) {
4741 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL, p, p_max_size,
4744 human_readable(info.diskio_write_value * 1024LL, p, p_max_size,
4749 if (obj->data.diskio) {
4750 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL, p, p_max_size,
4753 human_readable(info.diskio_read_value * 1024LL, p, p_max_size,
4758 if (obj->data.diskio) {
4759 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4760 obj->data.diskio->current, obj->e, 1);
4762 new_graph(p, obj->a, obj->b, obj->c, obj->d, info.diskio_value,
4766 OBJ(diskiograph_read) {
4767 if (obj->data.diskio) {
4768 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4769 obj->data.diskio->current_read, obj->e, 1);
4771 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4772 info.diskio_read_value, obj->e, 1);
4775 OBJ(diskiograph_write) {
4776 if (obj->data.diskio) {
4777 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4778 obj->data.diskio->current_write, obj->e, 1);
4780 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4781 info.diskio_write_value, obj->e, 1);
4785 spaced_print(p, p_max_size, "%d", 6, "downspeed",
4786 round_to_int(obj->data.net->recv_speed / 1024));
4789 spaced_print(p, p_max_size, "%.1f", 8, "downspeedf",
4790 obj->data.net->recv_speed / 1024.0);
4792 OBJ(downspeedgraph) {
4793 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4794 obj->data.net->recv_speed / 1024.0, obj->e, 1);
4798 i = obj->data.ifblock.pos - 1;
4808 if ((obj->data.net->addr.sa_data[2] & 255) == 0
4809 && (obj->data.net->addr.sa_data[3] & 255) == 0
4810 && (obj->data.net->addr.sa_data[4] & 255) == 0
4811 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
4812 snprintf(p, p_max_size, "No Address");
4814 snprintf(p, p_max_size, "%u.%u.%u.%u",
4815 obj->data.net->addr.sa_data[2] & 255,
4816 obj->data.net->addr.sa_data[3] & 255,
4817 obj->data.net->addr.sa_data[4] & 255,
4818 obj->data.net->addr.sa_data[5] & 255);
4821 #if defined(__linux__)
4823 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
4825 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
4826 strcpy(p, obj->data.net->addrs);
4829 strcpy(p, "0.0.0.0");
4831 #endif /* __linux__ */
4833 #if defined(IMLIB2) && defined(X11)
4838 Imlib_Image image, buffer;
4840 image = imlib_load_image(obj->data.s);
4841 imlib_context_set_image(image);
4845 w = imlib_image_get_width();
4846 h = imlib_image_get_height();
4847 buffer = imlib_create_image(w, h);
4848 imlib_context_set_display(display);
4849 imlib_context_set_drawable(window.drawable);
4850 imlib_context_set_colormap(DefaultColormap(display,
4852 imlib_context_set_visual(DefaultVisual(display,
4854 imlib_context_set_image(buffer);
4855 imlib_blend_image_onto_image(image, 0, 0, 0, w, h,
4856 text_start_x, text_start_y, w, h);
4857 imlib_render_image_on_drawable(text_start_x,
4860 imlib_context_set_image(image);
4868 read_exec(obj->data.s, p, p_max_size);
4869 remove_deleted_chars(p);
4872 struct information *tmp_info;
4873 struct text_object_list *text_objects;
4875 read_exec(obj->data.s, p, p_max_size);
4877 tmp_info = malloc(sizeof(struct information));
4878 memcpy(tmp_info, cur, sizeof(struct information));
4879 text_objects = parse_conky_vars(p, p, tmp_info);
4881 free_text_objects(text_objects);
4888 read_exec(obj->data.s, p, p_max_size);
4889 barnum = get_barnum(p);
4891 if (barnum >= 0.0) {
4892 new_bar(p, 0, 4, round_to_int(barnum * 255.0));
4898 read_exec(obj->data.s, p, p_max_size);
4899 barnum = get_barnum(p);
4901 if (barnum >= 0.0) {
4902 new_graph(p, 0, 25, obj->c, obj->d, round_to_int(barnum),
4907 if (current_update_time - obj->data.execi.last_update
4908 < obj->data.execi.interval) {
4909 new_bar(p, 0, 4, (int) obj->f);
4913 read_exec(obj->data.execi.cmd, p, p_max_size);
4914 barnum = get_barnum(p);
4916 if (barnum >= 0.0) {
4917 obj->f = 255 * barnum / 100.0;
4918 new_bar(p, 0, 4, round_to_int(obj->f));
4920 obj->data.execi.last_update = current_update_time;
4924 if (current_update_time - obj->data.execi.last_update
4925 < obj->data.execi.interval) {
4926 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
4930 read_exec(obj->data.execi.cmd, p, p_max_size);
4931 barnum = get_barnum(p);
4933 if (barnum >= 0.0) {
4935 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f),
4938 obj->data.execi.last_update = current_update_time;
4942 if (current_update_time - obj->data.execi.last_update
4943 < obj->data.execi.interval
4944 || obj->data.execi.interval == 0) {
4945 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4947 read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
4949 obj->data.execi.last_update = current_update_time;
4950 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4952 // parse_conky_vars(output, p, cur);
4955 struct text_object_list *text_objects = 0;
4956 struct information *tmp_info =
4957 malloc(sizeof(struct information));
4958 memcpy(tmp_info, cur, sizeof(struct information));
4960 if (current_update_time - obj->data.execi.last_update
4961 < obj->data.execi.interval
4962 || obj->data.execi.interval == 0) {
4963 text_objects = parse_conky_vars(obj->data.execi.buffer, p, tmp_info);
4965 char *output = obj->data.execi.buffer;
4966 FILE *fp = popen(obj->data.execi.cmd, "r");
4967 int length = fread(output, 1, text_buffer_size, fp);
4971 output[length] = '\0';
4972 if (length > 0 && output[length - 1] == '\n') {
4973 output[length - 1] = '\0';
4976 text_objects = parse_conky_vars(obj->data.execi.buffer, p, tmp_info);
4977 obj->data.execi.last_update = current_update_time;
4979 free_text_objects(text_objects);
4984 if (!obj->data.texeci.p_timed_thread) {
4985 obj->data.texeci.p_timed_thread =
4986 timed_thread_create(&threaded_exec,
4987 (void *) obj, obj->data.texeci.interval * 1000000);
4988 if (!obj->data.texeci.p_timed_thread) {
4989 ERR("Error creating texeci timed thread");
4991 timed_thread_register(obj->data.texeci.p_timed_thread,
4992 &obj->data.texeci.p_timed_thread);
4993 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4994 ERR("Error running texeci timed thread");
4997 timed_thread_lock(obj->data.texeci.p_timed_thread);
4998 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4999 timed_thread_unlock(obj->data.texeci.p_timed_thread);
5001 #endif /* HAVE_POPEN */
5003 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
5005 if (mail && mail->p_timed_thread) {
5006 timed_thread_lock(mail->p_timed_thread);
5007 snprintf(p, p_max_size, "%lu", mail->unseen);
5008 timed_thread_unlock(mail->p_timed_thread);
5011 OBJ(imap_messages) {
5012 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
5014 if (mail && mail->p_timed_thread) {
5015 timed_thread_lock(mail->p_timed_thread);
5016 snprintf(p, p_max_size, "%lu", mail->messages);
5017 timed_thread_unlock(mail->p_timed_thread);
5021 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
5023 if (mail && mail->p_timed_thread) {
5024 timed_thread_lock(mail->p_timed_thread);
5025 snprintf(p, p_max_size, "%lu", mail->unseen);
5026 timed_thread_unlock(mail->p_timed_thread);
5030 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
5032 if (mail && mail->p_timed_thread) {
5033 timed_thread_lock(mail->p_timed_thread);
5034 snprintf(p, p_max_size, "%.1f",
5035 mail->used / 1024.0 / 1024.0);
5036 timed_thread_unlock(mail->p_timed_thread);
5040 if (obj->data.fs != NULL) {
5041 if (obj->data.fs->size == 0) {
5042 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5044 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5045 (int) (255 - obj->data.fsbar.fs->avail * 255 /
5046 obj->data.fs->size));
5051 if (obj->data.fs != NULL) {
5052 human_readable(obj->data.fs->avail, p, 255, "fs_free");
5056 if (obj->data.fs != NULL) {
5057 if (obj->data.fs->size) {
5058 spaced_print(p, p_max_size, "%*d", 4, "fs_free_perc",
5059 pad_percents, (int) ((obj->data.fs->avail * 100) /
5060 obj->data.fs->size));
5062 snprintf(p, p_max_size, "0");
5067 if (obj->data.fs != NULL) {
5068 human_readable(obj->data.fs->size, p, 255, "fs_size");
5072 if (obj->data.fs != NULL)
5073 snprintf(p, p_max_size, "%s", obj->data.fs->type);
5076 if (obj->data.fs != NULL) {
5077 human_readable(obj->data.fs->size - (obj->data.fs->free
5078 ? obj->data.fs->free : obj->data.fs->avail), p, 255,
5083 if (obj->data.fs != NULL) {
5084 if (obj->data.fs->size == 0) {
5085 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5087 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5088 (int) (obj->data.fsbar.fs->avail * 255 /
5089 obj->data.fs->size));
5094 if (obj->data.fs != NULL) {
5095 if (obj->data.fs->size) {
5096 spaced_print(p, 4, "%*d", 4, "fs_used_perc",
5097 pad_percents, 100 - ((int) ((obj->data.fs->avail * 100) /
5098 obj->data.fs->size)));
5100 snprintf(p, p_max_size, "0");
5105 float *v = info.loadavg;
5107 if (obj->data.loadavg[2]) {
5108 snprintf(p, p_max_size, "%.2f %.2f %.2f",
5109 v[obj->data.loadavg[0] - 1],
5110 v[obj->data.loadavg[1] - 1],
5111 v[obj->data.loadavg[2] - 1]);
5112 } else if (obj->data.loadavg[1]) {
5113 snprintf(p, p_max_size, "%.2f %.2f",
5114 v[obj->data.loadavg[0] - 1],
5115 v[obj->data.loadavg[1] - 1]);
5116 } else if (obj->data.loadavg[0]) {
5117 snprintf(p, p_max_size, "%.2f",
5118 v[obj->data.loadavg[0] - 1]);
5122 new_goto(p, obj->data.i);
5125 new_tab(p, obj->data.pair.a, obj->data.pair.b);
5128 new_hr(p, obj->data.i);
5131 if (cur->nameserver_info.nscount > obj->data.i)
5132 snprintf(p, p_max_size, "%s",
5133 cur->nameserver_info.ns_list[obj->data.i]);
5137 PRSS *data = get_rss_info(obj->data.rss.uri,
5138 obj->data.rss.delay);
5142 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
5144 if (!strcmp(obj->data.rss.action, "feed_title")) {
5146 // remove trailing new line if one exists
5147 if (str[strlen(str) - 1] == '\n') {
5148 str[strlen(str) - 1] = 0;
5150 snprintf(p, p_max_size, "%s", str);
5151 } else if (!strcmp(obj->data.rss.action, "item_title")) {
5152 if (obj->data.rss.act_par < data->item_count) {
5153 str = data->items[obj->data.rss.act_par].title;
5154 // remove trailing new line if one exists
5155 if (str[strlen(str) - 1] == '\n') {
5156 str[strlen(str) - 1] = 0;
5158 snprintf(p, p_max_size, "%s", str);
5160 } else if (!strcmp(obj->data.rss.action, "item_desc")) {
5161 if (obj->data.rss.act_par < data->item_count) {
5163 data->items[obj->data.rss.act_par].description;
5164 // remove trailing new line if one exists
5165 if (str[strlen(str) - 1] == '\n') {
5166 str[strlen(str) - 1] = 0;
5168 snprintf(p, p_max_size, "%s", str);
5170 } else if (!strcmp(obj->data.rss.action, "item_titles")) {
5171 if (data->item_count > 0) {
5177 if (obj->data.rss.act_par > data->item_count) {
5178 show = data->item_count;
5180 show = obj->data.rss.act_par;
5182 for (itmp = 0; itmp < show; itmp++) {
5183 PRSS_Item *item = &data->items[itmp];
5187 // don't add new line before first item
5189 strncat(p, "\n", p_max_size);
5191 /* remove trailing new line if one exists,
5192 * we have our own */
5193 if (str[strlen(str) - 1] == '\n') {
5194 str[strlen(str) - 1] = 0;
5196 strncat(p, str, p_max_size);
5206 if (obj->data.hddtemp.update_time < current_update_time - 30) {
5207 char *str = get_hddtemp_info(obj->data.hddtemp.dev,
5208 obj->data.hddtemp.addr, obj->data.hddtemp.port, &obj->data.hddtemp.unit);
5210 strncpy(obj->data.hddtemp.temp, str, text_buffer_size);
5212 obj->data.hddtemp.temp[0] = 0;
5214 obj->data.hddtemp.update_time = current_update_time;
5216 if (!obj->data.hddtemp.temp) {
5217 snprintf(p, p_max_size, "N/A");
5218 } else if (obj->data.hddtemp.unit == '*') {
5219 snprintf(p, p_max_size, "%s", obj->data.hddtemp.temp);
5221 snprintf(p, p_max_size, "%s%c", obj->data.hddtemp.temp, obj->data.hddtemp.unit);
5226 new_offset(p, obj->data.i);
5229 new_voffset(p, obj->data.i);
5235 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5236 obj->data.sysfs.devtype, obj->data.sysfs.type);
5238 if (r >= 100.0 || r == 0) {
5239 snprintf(p, p_max_size, "%d", (int) r);
5241 snprintf(p, p_max_size, "%.1f", r);
5247 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5248 obj->data.sysfs.devtype, obj->data.sysfs.type);
5250 if (r >= 100.0 || r == 0) {
5251 snprintf(p, p_max_size, "%d", (int) r);
5253 snprintf(p, p_max_size, "%.1f", r);
5259 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5260 obj->data.sysfs.devtype, obj->data.sysfs.type);
5262 if (r >= 100.0 || r == 0) {
5263 snprintf(p, p_max_size, "%d", (int) r);
5265 snprintf(p, p_max_size, "%.1f", r);
5268 #endif /* !__OpenBSD__ */
5270 new_alignr(p, obj->data.i);
5273 new_alignc(p, obj->data.i);
5276 struct text_object_list *text_objects;
5277 struct information *tmp_info =
5278 malloc(sizeof(struct information));
5279 memcpy(tmp_info, cur, sizeof(struct information));
5280 text_objects = parse_conky_vars(obj->data.ifblock.s, p, tmp_info);
5282 if (strlen(p) != 0) {
5283 i = obj->data.ifblock.pos;
5289 free_text_objects(text_objects);
5296 if ((obj->data.ifblock.s)
5297 && (stat(obj->data.ifblock.s, &tmp) == -1)) {
5298 i = obj->data.ifblock.pos;
5301 if (obj->data.ifblock.str) {
5302 if (!check_contains(obj->data.ifblock.s,
5303 obj->data.ifblock.str)) {
5304 i = obj->data.ifblock.pos;
5315 if ((obj->data.ifblock.s)
5316 && (!check_mount(obj->data.ifblock.s))) {
5317 i = obj->data.ifblock.pos;
5324 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
5325 i = obj->data.ifblock.pos;
5331 #if defined(__linux__)
5333 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
5337 snprintf(p, p_max_size, "%s", cur->uname_s.release);
5340 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
5345 human_readable(cur->mem * 1024, p, 255, "mem");
5348 human_readable(cur->memmax * 1024, p, 255, "memmax");
5352 spaced_print(p, p_max_size, "%*llu", 4, "memperc",
5353 pad_percents, cur->mem * 100 / cur->memmax);
5357 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5358 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
5361 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5362 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
5368 snprintf(p, p_max_size, "%d", mixer_get_avg(obj->data.l));
5371 snprintf(p, p_max_size, "%d", mixer_get_left(obj->data.l));
5374 snprintf(p, p_max_size, "%d", mixer_get_right(obj->data.l));
5377 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5378 mixer_get_avg(obj->data.mixerbar.l) * 255 / 100);
5381 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5382 mixer_get_left(obj->data.mixerbar.l) * 255 / 100);
5385 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5386 mixer_get_right(obj->data.mixerbar.l) * 255 / 100);
5391 update_mail_count(&obj->data.local_mail);
5392 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
5395 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
5397 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
5400 update_mail_count(&obj->data.local_mail);
5401 snprintf(p, p_max_size, "%d",
5402 obj->data.local_mail.new_mail_count);
5405 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
5408 new_outline(p, obj->data.l);
5411 spaced_print(p, p_max_size, "%hu", 5, "processes", cur->procs);
5413 OBJ(running_processes) {
5414 spaced_print(p, p_max_size, "%hu", 3, "running_processes", cur->run_procs);
5417 snprintf(p, p_max_size, "%s", obj->data.s);
5420 new_bg(p, obj->data.l);
5423 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
5426 human_readable(cur->swap * 1024, p, 255, "swap");
5429 human_readable(cur->swapmax * 1024, p, 255, "swapmax");
5432 if (cur->swapmax == 0) {
5433 strncpy(p, "No swap", p_max_size);
5435 spaced_print(p, p_max_size, "%*llu", 4, "swapperc",
5436 pad_percents, cur->swap * 100 / cur->swapmax);
5440 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5441 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
5444 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
5447 time_t t = time(NULL);
5448 struct tm *tm = localtime(&t);
5450 setlocale(LC_TIME, "");
5451 strftime(p, p_max_size, obj->data.s, tm);
5454 time_t t = time(NULL);
5455 struct tm *tm = gmtime(&t);
5457 strftime(p, p_max_size, obj->data.s, tm);
5464 if (obj->data.tztime.tz) {
5465 oldTZ = getenv("TZ");
5466 setenv("TZ", obj->data.tztime.tz, 1);
5472 setlocale(LC_TIME, "");
5473 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
5475 setenv("TZ", oldTZ, 1);
5480 // Needless to free oldTZ since getenv gives ptr to static data
5483 human_readable(obj->data.net->recv, p, 255, "totaldown");
5486 human_readable(obj->data.net->trans, p, 255, "totalup");
5489 snprintf(p, p_max_size, "%d", total_updates);
5492 spaced_print(p, p_max_size, "%d", 6, "upspeed",
5493 round_to_int(obj->data.net->trans_speed / 1024));
5496 spaced_print(p, p_max_size, "%.1f", 8, "upspeedf",
5497 obj->data.net->trans_speed / 1024.0);
5500 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5501 obj->data.net->trans_speed / 1024.0, obj->e, 1);
5504 format_seconds_short(p, p_max_size, (int) cur->uptime);
5507 format_seconds(p, p_max_size, (int) cur->uptime);
5510 snprintf(p, p_max_size, "%s", cur->users.names);
5513 snprintf(p, p_max_size, "%s", cur->users.terms);
5516 snprintf(p, p_max_size, "%s", cur->users.times);
5519 snprintf(p, p_max_size, "%d", cur->users.number);
5521 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
5522 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5526 msg = get_apm_adapter();
5527 snprintf(p, p_max_size, "%s", msg);
5530 OBJ(apm_battery_life) {
5533 msg = get_apm_battery_life();
5534 snprintf(p, p_max_size, "%s", msg);
5537 OBJ(apm_battery_time) {
5540 msg = get_apm_battery_time();
5541 snprintf(p, p_max_size, "%s", msg);
5544 #endif /* __FreeBSD__ __OpenBSD__ */
5548 snprintf(p, cur->mpd.max_title_len > 0
5549 ? cur->mpd.max_title_len : p_max_size, "%s",
5553 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5556 snprintf(p, p_max_size, "%s", cur->mpd.album);
5559 snprintf(p, p_max_size, "%s", cur->mpd.random);
5562 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
5565 snprintf(p, p_max_size, "%s", cur->mpd.track);
5568 snprintf(p, p_max_size, "%s", cur->mpd.name);
5571 snprintf(p, p_max_size, "%s", cur->mpd.file);
5574 snprintf(p, p_max_size, "%i", cur->mpd.volume);
5577 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
5580 snprintf(p, p_max_size, "%s", cur->mpd.status);
5583 format_media_player_time(p, p_max_size, cur->mpd.elapsed);
5586 format_media_player_time(p, p_max_size, cur->mpd.length);
5589 spaced_print(p, p_max_size, "%*d", 4, "mpd_percent",
5590 pad_percents, (int) (cur->mpd.progress * 100));
5593 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5594 (int) (cur->mpd.progress * 255.0f));
5597 memset(p, 0, p_max_size);
5598 if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title
5599 && *cur->mpd.title) {
5600 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist,
5602 } else if (cur->mpd.title && *cur->mpd.title) {
5603 snprintf(p, p_max_size, "%s", cur->mpd.title);
5604 } else if (cur->mpd.artist && *cur->mpd.artist) {
5605 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5606 } else if (cur->mpd.file && *cur->mpd.file) {
5607 snprintf(p, p_max_size, "%s", cur->mpd.file);
5616 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5619 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5622 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5625 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5627 OBJ(xmms2_comment) {
5628 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5631 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5634 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5637 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5639 OBJ(xmms2_tracknr) {
5640 if (cur->xmms2.tracknr != -1) {
5641 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5644 OBJ(xmms2_bitrate) {
5645 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5648 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5651 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5653 OBJ(xmms2_elapsed) {
5654 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5655 (cur->xmms2.elapsed / 1000) % 60);
5657 OBJ(xmms2_duration) {
5658 snprintf(p, p_max_size, "%02d:%02d",
5659 cur->xmms2.duration / 60000,
5660 (cur->xmms2.duration / 1000) % 60);
5662 OBJ(xmms2_percent) {
5663 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5666 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5667 (int) (cur->xmms2.progress * 255.0f));
5669 OBJ(xmms2_playlist) {
5670 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5672 OBJ(xmms2_timesplayed) {
5673 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5676 if (strlen(cur->xmms2.title) < 2
5677 && strlen(cur->xmms2.title) < 2) {
5678 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5680 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5686 OBJ(audacious_status) {
5687 snprintf(p, p_max_size, "%s",
5688 cur->audacious.items[AUDACIOUS_STATUS]);
5690 OBJ(audacious_title) {
5691 snprintf(p, cur->audacious.max_title_len > 0
5692 ? cur->audacious.max_title_len : p_max_size, "%s",
5693 cur->audacious.items[AUDACIOUS_TITLE]);
5695 OBJ(audacious_length) {
5696 snprintf(p, p_max_size, "%s",
5697 cur->audacious.items[AUDACIOUS_LENGTH]);
5699 OBJ(audacious_length_seconds) {
5700 snprintf(p, p_max_size, "%s",
5701 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5703 OBJ(audacious_position) {
5704 snprintf(p, p_max_size, "%s",
5705 cur->audacious.items[AUDACIOUS_POSITION]);
5707 OBJ(audacious_position_seconds) {
5708 snprintf(p, p_max_size, "%s",
5709 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5711 OBJ(audacious_bitrate) {
5712 snprintf(p, p_max_size, "%s",
5713 cur->audacious.items[AUDACIOUS_BITRATE]);
5715 OBJ(audacious_frequency) {
5716 snprintf(p, p_max_size, "%s",
5717 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5719 OBJ(audacious_channels) {
5720 snprintf(p, p_max_size, "%s",
5721 cur->audacious.items[AUDACIOUS_CHANNELS]);
5723 OBJ(audacious_filename) {
5724 snprintf(p, p_max_size, "%s",
5725 cur->audacious.items[AUDACIOUS_FILENAME]);
5727 OBJ(audacious_playlist_length) {
5728 snprintf(p, p_max_size, "%s",
5729 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5731 OBJ(audacious_playlist_position) {
5732 snprintf(p, p_max_size, "%s",
5733 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5735 OBJ(audacious_bar) {
5739 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5740 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5741 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5747 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5750 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5753 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5756 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5759 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5762 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5766 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
5769 switch (obj->data.top.type) {
5771 snprintf(p, 16, "%-15s",
5772 cur->cpu[obj->data.top.num]->name);
5775 snprintf(p, 7, "%6.2f",
5776 cur->cpu[obj->data.top.num]->amount);
5779 snprintf(p, 6, "%5i",
5780 cur->cpu[obj->data.top.num]->pid);
5783 snprintf(p, 7, "%6.2f",
5784 cur->cpu[obj->data.top.num]->totalmem);
5787 timeval = format_time(
5788 cur->cpu[obj->data.top.num]->total_cpu_time, 9);
5789 snprintf(p, 10, "%9s", timeval);
5793 human_readable(cur->cpu[obj->data.top.num]->rss,
5797 human_readable(cur->cpu[obj->data.top.num]->vsize,
5801 ERR("Unhandled top data type: %d\n",
5802 obj->data.top.type);
5805 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
5809 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
5812 switch (obj->data.top.type) {
5814 snprintf(p, 16, "%-15s",
5815 cur->memu[obj->data.top.num]->name);
5818 snprintf(p, 7, "%6.2f",
5819 cur->memu[obj->data.top.num]->amount);
5822 snprintf(p, 6, "%5i",
5823 cur->memu[obj->data.top.num]->pid);
5826 snprintf(p, 7, "%6.2f",
5827 cur->memu[obj->data.top.num]->totalmem);
5830 timeval = format_time(
5831 cur->memu[obj->data.top.num]->total_cpu_time,
5833 snprintf(p, 10, "%9s", timeval);
5837 human_readable(cur->cpu[obj->data.top.num]->rss,
5841 human_readable(cur->cpu[obj->data.top.num]->vsize,
5845 ERR("Unhandled top data type: %d\n",
5846 obj->data.top.type);
5849 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
5853 if (current_update_time - obj->data.tail.last_update
5854 < obj->data.tail.interval) {
5855 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5861 obj->data.tail.last_update = current_update_time;
5863 if (obj->data.tail.fd != -1) {
5864 tail_pipe(obj, p, p_max_size);
5868 fp = fopen(obj->data.tail.logfile, "rt");
5871 /* Send one message, but do not consistently spam
5872 * on missing logfiles. */
5873 if (obj->data.tail.readlines != 0) {
5874 ERR("tail logfile failed to open");
5875 strcpy(obj->data.tail.buffer, "Logfile Missing");
5877 obj->data.tail.readlines = 0;
5878 snprintf(p, p_max_size, "Logfile Missing");
5880 obj->data.tail.readlines = 0;
5881 /* -1 instead of 0 to avoid counting a trailing
5883 fseek(fp, -1, SEEK_END);
5884 bsize = ftell(fp) + 1;
5885 for (iter = obj->data.tail.wantedlines; iter > 0;
5887 nl = rev_fcharfind(fp, '\n', iter);
5892 obj->data.tail.readlines = iter;
5893 if (obj->data.tail.readlines
5894 < obj->data.tail.wantedlines) {
5895 fseek(fp, 0, SEEK_SET);
5897 fseek(fp, nl + 1, SEEK_SET);
5900 /* Make sure bsize is at least 1 byte smaller than the
5901 * buffer max size. */
5902 if (bsize > (long) ((text_buffer_size * 20) - 1)) {
5903 fseek(fp, bsize - text_buffer_size * 20 - 1,
5905 bsize = text_buffer_size * 20 - 1;
5907 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5910 /* Clean up trailing newline, make sure the
5911 * buffer is null terminated. */
5912 if (obj->data.tail.buffer[bsize - 1] == '\n') {
5913 obj->data.tail.buffer[bsize - 1] = '\0';
5915 obj->data.tail.buffer[bsize] = '\0';
5917 snprintf(p, p_max_size, "%s",
5918 obj->data.tail.buffer);
5920 strcpy(obj->data.tail.buffer, "Logfile Empty");
5921 snprintf(p, p_max_size, "Logfile Empty");
5924 } /* if cur_upd_time >= */
5925 // parse_conky_vars(obj->data.tail.buffer, p, cur);
5929 if (current_update_time - obj->data.tail.last_update
5930 < obj->data.tail.interval) {
5931 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5937 obj->data.tail.last_update = current_update_time;
5939 fp = fopen(obj->data.tail.logfile, "rt");
5941 /* Send one message, but do not consistently spam
5942 * on missing logfiles. */
5943 if (obj->data.tail.readlines != 0) {
5944 ERR("head logfile failed to open");
5945 strcpy(obj->data.tail.buffer, "Logfile Missing");
5947 obj->data.tail.readlines = 0;
5948 snprintf(p, p_max_size, "Logfile Missing");
5950 obj->data.tail.readlines = 0;
5951 for (iter = obj->data.tail.wantedlines; iter > 0;
5953 nl = fwd_fcharfind(fp, '\n', iter);
5958 obj->data.tail.readlines = iter;
5959 /* Make sure nl is at least 1 byte smaller than the
5960 * buffer max size. */
5961 if (nl > (long) ((text_buffer_size * 20) - 1)) {
5962 nl = text_buffer_size * 20 - 1;
5964 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5967 /* Clean up trailing newline, make sure the buffer
5968 * is null terminated. */
5969 if (obj->data.tail.buffer[nl - 1] == '\n') {
5970 obj->data.tail.buffer[nl - 1] = '\0';
5972 obj->data.tail.buffer[nl] = '\0';
5974 snprintf(p, p_max_size, "%s",
5975 obj->data.tail.buffer);
5977 strcpy(obj->data.tail.buffer, "Logfile Empty");
5978 snprintf(p, p_max_size, "Logfile Empty");
5980 } /* if fp == null */
5981 } /* cur_upd_time >= */
5982 // parse_conky_vars(obj->data.tail.buffer, p, cur);
5985 #ifdef TCP_PORT_MONITOR
5987 /* grab a pointer to this port monitor */
5988 tcp_port_monitor_t *p_monitor =
5989 find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
5990 obj->data.tcp_port_monitor.port_range_begin,
5991 obj->data.tcp_port_monitor.port_range_end);
5994 snprintf(p, p_max_size, "monitor not found");
5998 /* now grab the text of interest */
5999 if (peek_tcp_port_monitor(p_monitor,
6000 obj->data.tcp_port_monitor.item,
6001 obj->data.tcp_port_monitor.connection_index, p,
6003 snprintf(p, p_max_size, "monitor peek error");
6011 iconv_converting = 1;
6012 iconv_selected = obj->a;
6015 iconv_converting = 0;
6020 OBJ(entropy_avail) {
6021 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
6023 OBJ(entropy_poolsize) {
6024 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
6027 double entropy_perc;
6029 entropy_perc = (double) cur->entropy.entropy_avail /
6030 (double) cur->entropy.poolsize;
6031 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
6037 s = smapi_get_val(obj->data.s);
6038 snprintf(p, p_max_size, "%s", s);
6042 OBJ(if_smapi_bat_installed) {
6044 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
6045 if(!smapi_bat_installed(idx)) {
6046 i = obj->data.ifblock.pos;
6051 ERR("argument to if_smapi_bat_installed must be an integer");
6053 OBJ(smapi_bat_perc) {
6055 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
6056 val = smapi_bat_installed(idx) ?
6057 smapi_get_bat_int(idx, "remaining_percent") : 0;
6058 spaced_print(p, p_max_size, "%*d", 4, "smapi_bat_perc", pad_percents, val);
6060 ERR("argument to smapi_bat_perc must be an integer");
6062 OBJ(smapi_bat_bar) {
6063 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
6064 new_bar(p, obj->a, obj->b, (int)
6065 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
6067 new_bar(p, obj->a, obj->b, 0);
6072 int hol = (strcmp((char*)&obj->data.nvidia.arg, "gpufreq")) ? 1 : 0;
6073 if(!(obj->data.nvidia.value = get_nvidia_value(obj->data.nvidia.type, display, hol)))
6074 snprintf(p, p_max_size, "value unavailible");
6076 spaced_print(p, p_max_size, "%*d", 4, "nvidia",
6077 4, obj->data.nvidia.value);
6086 unsigned int a = strlen(p);
6089 if (a > 0 && iconv_converting && iconv_selected > 0
6090 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
6092 size_t dummy1, dummy2;
6093 char *ptr = buff_in;
6096 dummy1 = dummy2 = a;
6098 strncpy(buff_in, p, p_max_size);
6100 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
6101 while (dummy1 > 0) {
6102 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
6105 ERR("Iconv codeset conversion failed");
6110 /* It is nessecary when we are converting from multibyte to
6111 * singlebyte codepage */
6114 #endif /* HAVE_ICONV */
6121 double current_update_time, last_update_time;
6123 static void generate_text(void)
6125 struct information *cur = &info;
6132 current_update_time = get_time();
6135 /* fix diskio rates to b/s (use update_interval */
6136 info.diskio_read_value /= update_interval;
6137 info.diskio_write_value /= update_interval;
6138 info.diskio_value /= update_interval;
6140 /* add things to the buffer */
6146 generate_text_internal(p, max_user_text, global_text_object_list, cur);
6148 if (stuff_in_upper_case) {
6151 tmp_p = text_buffer;
6153 *tmp_p = toupper(*tmp_p);
6158 last_update_time = current_update_time;
6164 static void set_font(void)
6168 if (window.xftdraw != NULL) {
6169 XftDrawDestroy(window.xftdraw);
6171 window.xftdraw = XftDrawCreate(display, window.drawable,
6172 DefaultVisual(display, screen), DefaultColormap(display, screen));
6176 XSetFont(display, window.gc, fonts[selected_font].font->fid);
6182 static inline int get_string_width(const char *s)
6185 return *s ? calc_text_width(s, strlen(s)) : 0;
6191 static inline int get_string_width_special(char *s)
6203 p = strndup(s, text_buffer_size);
6207 if (*p == SPECIAL_CHAR) {
6208 /* shift everything over by 1 so that the special char
6209 * doesn't mess up the size calculation */
6210 for (i = 0; i < strlen(p); i++) {
6211 *(p + i) = *(p + i + 1);
6213 if (specials[special_index + idx].type == GRAPH
6214 || specials[special_index + idx].type == BAR) {
6215 width += specials[special_index + idx].width;
6222 if (strlen(final) > 1) {
6223 width += calc_text_width(final, strlen(final));
6228 return (s) ? strlen(s) : 0;
6233 static void text_size_updater(char *s);
6235 int last_font_height;
6236 static void update_text_area(void)
6240 /* update text size if it isn't fixed */
6245 text_width = minimum_width;
6248 last_font_height = font_height();
6249 for_each_line(text_buffer, text_size_updater);
6251 if (text_height < minimum_height) {
6252 text_height = minimum_height;
6254 if (text_width > maximum_width && maximum_width > 0) {
6255 text_width = maximum_width;
6259 /* get text position on workarea */
6260 switch (text_alignment) {
6267 x = workarea[2] - text_width - gap_x;
6272 x = workarea[2] / 2 - text_width / 2 - gap_x;
6279 y = workarea[3] - text_height - gap_y;
6283 x = workarea[2] - text_width - gap_x;
6284 y = workarea[3] - text_height - gap_y;
6288 x = workarea[2] / 2 - text_width / 2 - gap_x;
6289 y = workarea[3] - text_height - gap_y;
6294 y = workarea[3] / 2 - text_height / 2 - gap_y;
6298 x = workarea[2] - text_width - gap_x;
6299 y = workarea[3] / 2 - text_height / 2 - gap_y;
6303 case NONE: // Let the WM manage the window
6314 if (own_window && !fixed_pos) {
6317 text_start_x = border_margin + 1;
6318 text_start_y = border_margin + 1;
6319 window.x = x - border_margin - 1;
6320 window.y = y - border_margin - 1;
6324 /* If window size doesn't match to workarea's size,
6325 * then window probably includes panels (gnome).
6326 * Blah, doesn't work on KDE. */
6327 if (workarea[2] != window.width || workarea[3] != window.height) {
6339 static int cur_x, cur_y; /* current x and y for drawing */
6341 //draw_mode also without X11 because we only need to print to stdout with FG
6342 static int draw_mode; /* FG, BG or OUTLINE */
6344 static long current_color;
6347 static void text_size_updater(char *s)
6352 /* get string widths and skip specials */
6355 if (*p == SPECIAL_CHAR) {
6357 w += get_string_width(s);
6360 if (specials[special_index].type == BAR
6361 || specials[special_index].type == GRAPH) {
6362 w += specials[special_index].width;
6363 if (specials[special_index].height > last_font_height) {
6364 last_font_height = specials[special_index].height;
6365 last_font_height += font_ascent();
6367 } else if (specials[special_index].type == OFFSET) {
6368 if (specials[special_index].arg > 0) {
6369 w += specials[special_index].arg;
6371 } else if (specials[special_index].type == VOFFSET) {
6372 last_font_height += specials[special_index].arg;
6373 } else if (specials[special_index].type == GOTO) {
6374 if (specials[special_index].arg > cur_x) {
6375 w = (int) specials[special_index].arg;
6377 } else if (specials[special_index].type == TAB) {
6378 int start = specials[special_index].arg;
6379 int step = specials[special_index].width;
6381 if (!step || step < 0) {
6384 w += step - (cur_x - text_start_x - start) % step;
6385 } else if (specials[special_index].type == FONT) {
6386 selected_font = specials[special_index].font_added;
6387 if (font_height() > last_font_height) {
6388 last_font_height = font_height();
6397 w += get_string_width(s);
6398 if (w > text_width) {
6401 if (text_width > maximum_width && maximum_width) {
6402 text_width = maximum_width;
6405 text_height += last_font_height;
6406 last_font_height = font_height();
6410 static inline void set_foreground_color(long c)
6413 XSetForeground(display, window.gc, c);
6417 static void draw_string(const char *s)
6419 int i, i2, pos, width_of_s;
6427 width_of_s = get_string_width(s);
6428 if (out_to_console && draw_mode == FG) {
6430 fflush(stdout); /* output immediately, don't buffer */
6432 memset(tmpstring1, 0, text_buffer_size);
6433 memset(tmpstring2, 0, text_buffer_size);
6434 strncpy(tmpstring1, s, text_buffer_size - 1);
6439 max = ((text_width - width_of_s) / get_string_width(" "));
6441 /* This code looks for tabs in the text and coverts them to spaces.
6442 * The trick is getting the correct number of spaces, and not going
6443 * over the window's size without forcing the window larger. */
6444 for (i = 0; i < (int) text_buffer_size; i++) {
6445 if (tmpstring1[i] == '\t') {
6447 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
6448 /* guard against overrun */
6449 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
6454 /* guard against overrun */
6455 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
6460 if (text_width == maximum_width) {
6461 /* this means the text is probably pushing the limit,
6462 * so we'll chop it */
6463 while (cur_x + get_string_width(tmpstring2) - text_start_x
6464 > maximum_width && strlen(tmpstring2) > 0) {
6465 tmpstring2[strlen(tmpstring2) - 1] = '\0';
6476 c.pixel = current_color;
6477 XQueryColor(display, DefaultColormap(display, screen), &c);
6480 c2.color.red = c.red;
6481 c2.color.green = c.green;
6482 c2.color.blue = c.blue;
6483 c2.color.alpha = fonts[selected_font].font_alpha;
6485 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6486 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6488 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6489 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6494 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
6497 cur_x += width_of_s;
6499 memcpy(tmpstring1, s, text_buffer_size);
6502 long redmask, greenmask, bluemask;
6504 void set_up_gradient(void)
6508 colour_depth = DisplayPlanes(display, screen);
6512 if (colour_depth != 24 && colour_depth != 16) {
6513 ERR("using non-standard colour depth, gradients may look like a "
6520 for (i = (colour_depth / 3) - 1; i >= 0; i--) {
6522 greenmask |= 1 << i;
6525 if (colour_depth % 3 == 1) {
6526 greenmask |= 1 << (colour_depth / 3);
6528 redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
6529 greenmask = greenmask << (colour_depth / 3);
6532 /* this function returns the next colour between two colours for a gradient */
6533 inline unsigned long do_gradient(unsigned long first_colour,
6534 unsigned long last_colour)
6537 int red1, green1, blue1; // first colour
6538 int red2, green2, blue2; // second colour
6539 int red3 = 0, green3 = 0, blue3 = 0; // difference
6540 short redshift = (2 * colour_depth / 3 + colour_depth % 3);
6541 short greenshift = (colour_depth / 3);
6543 red1 = (first_colour & redmask) >> redshift;
6544 green1 = (first_colour & greenmask) >> greenshift;
6545 blue1 = first_colour & bluemask;
6546 red2 = (last_colour & redmask) >> redshift;
6547 green2 = (last_colour & greenmask) >> greenshift;
6548 blue2 = last_colour & bluemask;
6555 if (green1 > green2) {
6558 if (green1 < green2) {
6561 if (blue1 > blue2) {
6564 if (blue1 < blue2) {
6579 if (red1 > bluemask) {
6582 if (green1 > bluemask) {
6585 if (blue1 > bluemask) {
6588 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
6592 /* this function returns the max diff for a gradient */
6593 inline unsigned long gradient_max(unsigned long first_colour,
6594 unsigned long last_colour)
6596 int red1, green1, blue1; // first colour
6597 int red2, green2, blue2; // second colour
6598 int red3 = 0, green3 = 0, blue3 = 0; // difference
6599 long redshift, greenshift;
6602 if (colour_depth == 0) {
6605 redshift = (2 * colour_depth / 3 + colour_depth % 3);
6606 greenshift = (colour_depth / 3);
6608 red1 = (first_colour & redmask) >> redshift;
6609 green1 = (first_colour & greenmask) >> greenshift;
6610 blue1 = first_colour & bluemask;
6611 red2 = (last_colour & redmask) >> redshift;
6612 green2 = (last_colour & greenmask) >> greenshift;
6613 blue2 = last_colour & bluemask;
6614 red3 = abs(red1 - red2);
6615 green3 = abs(green1 - green2);
6616 blue3 = abs(blue1 - blue2);
6628 static void draw_line(char *s)
6636 cur_x = text_start_x;
6637 cur_y += font_ascent();
6638 font_h = font_height();
6640 /* find specials and draw stuff */
6643 if (*p == SPECIAL_CHAR) {
6646 /* draw string before special */
6653 switch (specials[special_index].type) {
6654 case HORIZONTAL_LINE:
6656 int h = specials[special_index].height;
6657 int mid = font_ascent() / 2;
6659 w = text_start_x + text_width - cur_x;
6661 XSetLineAttributes(display, window.gc, h, LineSolid,
6662 CapButt, JoinMiter);
6663 XDrawLine(display, window.drawable, window.gc, cur_x,
6664 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6670 int h = specials[special_index].height;
6671 int tmp_s = specials[special_index].arg;
6672 int mid = font_ascent() / 2;
6673 char ss[2] = { tmp_s, tmp_s };
6675 w = text_start_x + text_width - cur_x - 1;
6676 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6677 CapButt, JoinMiter);
6678 XSetDashes(display, window.gc, 0, ss, 2);
6679 XDrawLine(display, window.drawable, window.gc, cur_x,
6680 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6686 int h, bar_usage, by;
6687 if (cur_x - text_start_x > maximum_width
6688 && maximum_width > 0) {
6691 h = specials[special_index].height;
6692 bar_usage = specials[special_index].arg;
6693 by = cur_y - (font_ascent() / 2) - 1;
6695 if (h < font_height()) {
6698 w = specials[special_index].width;
6700 w = text_start_x + text_width - cur_x - 1;
6706 XSetLineAttributes(display, window.gc, 1, LineSolid,
6707 CapButt, JoinMiter);
6709 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6711 XFillRectangle(display, window.drawable, window.gc, cur_x,
6712 by, w * bar_usage / 255, h);
6713 if (specials[special_index].height > cur_y_add
6714 && specials[special_index].height > font_h) {
6715 cur_y_add = specials[special_index].height;
6722 int h, by, i, j = 0;
6723 int gradient_size = 0;
6724 float gradient_factor = 0;
6725 float gradient_update = 0;
6726 unsigned long last_colour = current_color;
6727 unsigned long tmpcolour = current_color;
6728 int show_scale_x = cur_x + font_ascent() / 2;
6729 int show_scale_y = cur_y + font_height() / 2;
6730 if (cur_x - text_start_x > maximum_width
6731 && maximum_width > 0) {
6734 h = specials[special_index].height;
6735 by = cur_y - (font_ascent() / 2) - 1;
6737 if (h < font_height()) {
6740 w = specials[special_index].width;
6742 w = text_start_x + text_width - cur_x - 1;
6747 if (draw_graph_borders) {
6748 XSetLineAttributes(display, window.gc, 1, LineSolid,
6749 CapButt, JoinMiter);
6750 XDrawRectangle(display, window.drawable, window.gc,
6753 XSetLineAttributes(display, window.gc, 1, LineSolid,
6754 CapButt, JoinMiter);
6756 if (specials[special_index].last_colour != 0
6757 || specials[special_index].first_colour != 0) {
6758 tmpcolour = specials[special_index].last_colour;
6760 gradient_max(specials[special_index].last_colour,
6761 specials[special_index].first_colour);
6762 gradient_factor = (float) gradient_size / (w - 2);
6764 for (i = w - 2; i > -1; i--) {
6765 if (specials[special_index].last_colour != 0
6766 || specials[special_index].first_colour != 0) {
6767 XSetForeground(display, window.gc, tmpcolour);
6768 gradient_update += gradient_factor;
6769 while (gradient_update > 0) {
6770 tmpcolour = do_gradient(tmpcolour,
6771 specials[special_index].first_colour);
6775 if ((w - i) / ((float) (w - 2) /
6776 (specials[special_index].graph_width)) > j
6777 && j < MAX_GRAPH_DEPTH - 3) {
6780 /* this is mugfugly, but it works */
6781 XDrawLine(display, window.drawable, window.gc,
6782 cur_x + i + 1, by + h, cur_x + i + 1,
6783 by + h - specials[special_index].graph[j] *
6784 (h - 1) / specials[special_index].graph_scale);
6786 if (specials[special_index].height > cur_y_add
6787 && specials[special_index].height > font_h) {
6788 cur_y_add = specials[special_index].height;
6790 /* if (draw_mode == BG) {
6791 set_foreground_color(default_bg_color);
6792 } else if (draw_mode == OUTLINE) {
6793 set_foreground_color(default_out_color);
6795 set_foreground_color(default_fg_color);
6797 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
6800 cur_x = show_scale_x;
6801 cur_y = show_scale_y;
6803 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
6805 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
6806 draw_string(tmp_str);
6811 set_foreground_color(last_colour);
6817 int old = font_ascent();
6819 cur_y -= font_ascent();
6820 selected_font = specials[special_index].font_added;
6821 if (cur_y + font_ascent() < cur_y + old) {
6824 cur_y += font_ascent();
6830 if (draw_mode == FG) {
6831 set_foreground_color(specials[special_index].arg);
6836 if (draw_mode == BG) {
6837 set_foreground_color(specials[special_index].arg);
6842 if (draw_mode == OUTLINE) {
6843 set_foreground_color(specials[special_index].arg);
6848 w += specials[special_index].arg;
6852 cur_y += specials[special_index].arg;
6856 if (specials[special_index].arg >= 0) {
6857 cur_x = (int) specials[special_index].arg;
6863 int start = specials[special_index].arg;
6864 int step = specials[special_index].width;
6866 if (!step || step < 0) {
6869 w = step - (cur_x - text_start_x - start) % step;
6875 /* TODO: add back in "+ border_margin" to the end of
6877 int pos_x = text_start_x + text_width -
6878 get_string_width_special(s);
6880 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6881 "get_string_width(p) %i gap_x %i "
6882 "specials[special_index].arg %i border_margin %i "
6883 "border_width %i\n", pos_x, text_start_x, text_width,
6884 cur_x, get_string_width_special(s), gap_x,
6885 specials[special_index].arg, border_margin,
6887 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6888 cur_x = pos_x - specials[special_index].arg;
6895 int pos_x = (text_width) / 2 - get_string_width_special(s) /
6896 2 - (cur_x - text_start_x);
6897 /* int pos_x = text_start_x + text_width / 2 -
6898 get_string_width_special(s) / 2; */
6900 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6901 "get_string_width(p) %i gap_x %i "
6902 "specials[special_index].arg %i\n", pos_x, text_start_x,
6903 text_width, cur_x, get_string_width(s), gap_x,
6904 specials[special_index].arg); */
6905 if (pos_x > specials[special_index].arg) {
6906 w = pos_x - specials[special_index].arg;
6923 if (cur_y_add > 0) {
6925 cur_y -= font_descent();
6930 cur_y += font_descent();
6934 static void draw_text(void)
6937 cur_y = text_start_y;
6940 if (draw_borders && border_width > 0) {
6941 unsigned int b = (border_width + 1) / 2;
6943 if (stippled_borders) {
6944 char ss[2] = { stippled_borders, stippled_borders };
6945 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
6946 CapButt, JoinMiter);
6947 XSetDashes(display, window.gc, 0, ss, 2);
6949 XSetLineAttributes(display, window.gc, border_width, LineSolid,
6950 CapButt, JoinMiter);
6953 XDrawRectangle(display, window.drawable, window.gc,
6954 text_start_x - border_margin + b, text_start_y - border_margin + b,
6955 text_width + border_margin * 2 - 1 - b * 2,
6956 text_height + border_margin * 2 - 1 - b * 2);
6962 for_each_line(text_buffer, draw_line);
6965 static void draw_stuff(void)
6969 if (draw_shades && !draw_outline) {
6972 set_foreground_color(default_bg_color);
6983 for (i = -1; i < 2; i++) {
6984 for (j = -1; j < 2; j++) {
6985 if (i == 0 && j == 0) {
6990 set_foreground_color(default_out_color);
6991 draw_mode = OUTLINE;
6999 set_foreground_color(default_fg_color);
7008 swap.swap_window = window.window;
7009 swap.swap_action = XdbeBackground;
7010 XdbeSwapBuffers(display, &swap, 1);
7017 static void clear_text(int exposures)
7021 /* The swap action is XdbeBackground, which clears */
7026 /* there is some extra space for borders and outlines */
7027 XClearArea(display, window.window, text_start_x - border_margin - 1,
7028 text_start_y - border_margin - 1,
7029 text_width + border_margin * 2 + 2,
7030 text_height + border_margin * 2 + 2, exposures ? True : 0);
7035 static int need_to_update;
7037 /* update_text() generates new text and clears old text area */
7038 static void update_text(void)
7047 static void main_loop(void)
7049 #ifdef SIGNAL_BLOCKING
7050 sigset_t newmask, oldmask;
7053 Region region = XCreateRegion();
7057 XserverRegion region2, part;
7058 int event_base, error_base;
7060 if (!XDamageQueryExtension(display, &event_base, &error_base)) {
7061 ERR("Xdamage extension unavailable");
7063 damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7064 region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7065 part = XFixesCreateRegionFromWindow(display, window.window, 0);
7066 #endif /* HAVE_XDAMAGE */
7069 #ifdef SIGNAL_BLOCKING
7070 sigemptyset(&newmask);
7071 sigaddset(&newmask, SIGINT);
7072 sigaddset(&newmask, SIGTERM);
7073 sigaddset(&newmask, SIGUSR1);
7077 while (total_run_times == 0 || info.looped < total_run_times) {
7080 #ifdef SIGNAL_BLOCKING
7081 /* block signals. we will inspect for pending signals later */
7082 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
7083 CRIT_ERR("unable to sigprocmask()");
7090 /* wait for X event or timeout */
7092 if (!XPending(display)) {
7096 double t = update_interval - (get_time() - last_update_time);
7102 tv.tv_sec = (long) t;
7103 tv.tv_usec = (long) (t * 1000000) % 1000000;
7105 FD_SET(ConnectionNumber(display), &fdsr);
7107 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
7109 if (errno != EINTR) {
7110 ERR("can't select(): %s", strerror(errno));
7116 /* FIXME just sleep for the interval time if no X11 */
7117 usleep(update_interval * 1000000);
7125 if (need_to_update) {
7127 int wx = window.x, wy = window.y;
7135 /* resize window if it isn't right size */
7137 && (text_width + border_margin * 2 + 1 != window.width
7138 || text_height + border_margin * 2 + 1 != window.height)) {
7139 window.width = text_width + border_margin * 2 + 1;
7140 window.height = text_height + border_margin * 2 + 1;
7141 XResizeWindow(display, window.window, window.width,
7144 set_transparent_background(window.window);
7148 /* move window if it isn't in right position */
7149 if (!fixed_pos && (window.x != wx || window.y != wy)) {
7150 XMoveWindow(display, window.window, window.x, window.y);
7161 r.x = text_start_x - border_margin;
7162 r.y = text_start_y - border_margin;
7163 r.width = text_width + border_margin * 2;
7164 r.height = text_height + border_margin * 2;
7165 XUnionRectWithRegion(&r, region, region);
7170 /* handle X events */
7171 while (XPending(display)) {
7174 XNextEvent(display, &ev);
7182 r.width = ev.xexpose.width;
7183 r.height = ev.xexpose.height;
7184 XUnionRectWithRegion(&r, region, region);
7189 case ReparentNotify:
7190 /* set background to ParentRelative for all parents */
7192 set_transparent_background(window.window);
7196 case ConfigureNotify:
7198 /* if window size isn't what expected, set fixed size */
7199 if (ev.xconfigure.width != window.width
7200 || ev.xconfigure.height != window.height) {
7201 if (window.width != 0 && window.height != 0) {
7205 /* clear old stuff before screwing up
7210 XWindowAttributes attrs;
7212 if (XGetWindowAttributes(display,
7213 window.window, &attrs)) {
7214 window.width = attrs.width;
7215 window.height = attrs.height;
7219 text_width = window.width - border_margin * 2 - 1;
7220 text_height = window.height - border_margin * 2 - 1;
7221 if (text_width > maximum_width
7222 && maximum_width > 0) {
7223 text_width = maximum_width;
7227 /* if position isn't what expected, set fixed pos
7228 * total_updates avoids setting fixed_pos when window
7229 * is set to weird locations when started */
7230 /* // this is broken
7231 if (total_updates >= 2 && !fixed_pos
7232 && (window.x != ev.xconfigure.x
7233 || window.y != ev.xconfigure.y)
7234 && (ev.xconfigure.x != 0
7235 || ev.xconfigure.y != 0)) {
7244 /* if an ordinary window with decorations */
7245 if ((window.type == TYPE_NORMAL)
7246 && (!TEST_HINT(window.hints,
7247 HINT_UNDECORATED))) {
7248 /* allow conky to hold input focus. */
7251 /* forward the click to the desktop window */
7252 XUngrabPointer(display, ev.xbutton.time);
7253 ev.xbutton.window = window.desktop;
7254 XSendEvent(display, ev.xbutton.window, False,
7255 ButtonPressMask, &ev);
7256 XSetInputFocus(display, ev.xbutton.window,
7257 RevertToParent, ev.xbutton.time);
7264 /* if an ordinary window with decorations */
7265 if ((window.type == TYPE_NORMAL)
7266 && (!TEST_HINT(window.hints,
7267 HINT_UNDECORATED))) {
7268 /* allow conky to hold input focus. */
7271 /* forward the release to the desktop window */
7272 ev.xbutton.window = window.desktop;
7273 XSendEvent(display, ev.xbutton.window, False,
7274 ButtonReleaseMask, &ev);
7283 if (ev.type == event_base + XDamageNotify) {
7284 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
7286 XFixesSetRegion(display, part, &dev->area, 1);
7287 XFixesUnionRegion(display, region2, region2, part);
7289 #endif /* HAVE_XDAMAGE */
7295 XDamageSubtract(display, damage, region2, None);
7296 XFixesSetRegion(display, region2, 0, 0);
7297 #endif /* HAVE_XDAMAGE */
7299 /* XDBE doesn't seem to provide a way to clear the back buffer without
7300 * interfering with the front buffer, other than passing XdbeBackground
7301 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
7302 * redraw the text even if it wasn't part of the exposed area. OTOH,
7303 * if we're not going to call draw_stuff at all, then no swap happens
7304 * and we can safely do nothing. */
7306 if (!XEmptyRegion(region)) {
7311 r.x = text_start_x - border_margin;
7312 r.y = text_start_y - border_margin;
7313 r.width = text_width + border_margin * 2;
7314 r.height = text_height + border_margin * 2;
7315 XUnionRectWithRegion(&r, region, region);
7318 XSetRegion(display, window.gc, region);
7321 XftDrawSetClip(window.xftdraw, region);
7327 XDestroyRegion(region);
7328 region = XCreateRegion();
7332 #ifdef SIGNAL_BLOCKING
7333 /* unblock signals of interest and let handler fly */
7334 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
7335 CRIT_ERR("unable to sigprocmask()");
7339 switch (g_signal_pending) {
7342 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
7347 ERR("received SIGINT or SIGTERM to terminate. bye!");
7350 XDestroyRegion(region);
7353 XDamageDestroy(display, damage);
7354 XFixesDestroyRegion(display, region2);
7355 XFixesDestroyRegion(display, part);
7356 #endif /* HAVE_XDAMAGE */
7358 return; /* return from main_loop */
7361 /* Reaching here means someone set a signal
7362 * (SIGXXXX, signal_handler), but didn't write any code
7364 * If you don't want to handle a signal, don't set a handler on
7365 * it in the first place. */
7366 if (g_signal_pending) {
7367 ERR("ignoring signal (%d)", g_signal_pending);
7371 g_signal_pending = 0;
7374 #if defined(X11) && defined(HAVE_XDAMAGE)
7375 XDamageDestroy(display, damage);
7376 XFixesDestroyRegion(display, region2);
7377 XFixesDestroyRegion(display, part);
7378 XDestroyRegion(region);
7380 #endif /* X11 && HAVE_XDAMAGE */
7383 static void load_config_file(const char *);
7385 /* reload the config file */
7386 void reload_config(void)
7388 timed_thread_destroy_registered_threads();
7390 if (info.cpu_usage) {
7391 free(info.cpu_usage);
7392 info.cpu_usage = NULL;
7400 if (info.mpd.title) {
7401 free(info.mpd.title);
7402 info.mpd.title = NULL;
7404 if (info.mpd.artist) {
7405 free(info.mpd.artist);
7406 info.mpd.artist = NULL;
7408 if (info.mpd.album) {
7409 free(info.mpd.album);
7410 info.mpd.album = NULL;
7412 if (info.mpd.random) {
7413 free(info.mpd.random);
7414 info.mpd.random = NULL;
7416 if (info.mpd.repeat) {
7417 free(info.mpd.repeat);
7418 info.mpd.repeat = NULL;
7420 if (info.mpd.track) {
7421 free(info.mpd.track);
7422 info.mpd.track = NULL;
7424 if (info.mpd.name) {
7425 free(info.mpd.name);
7426 info.mpd.name = NULL;
7428 if (info.mpd.file) {
7429 free(info.mpd.file);
7430 info.mpd.file = NULL;
7432 if (info.mpd.status) {
7433 free(info.mpd.status);
7434 info.mpd.status = NULL;
7442 #ifdef TCP_PORT_MONITOR
7443 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7446 if (current_config) {
7448 load_config_file(current_config);
7450 /* re-init specials array */
7451 if ((specials = realloc((void *) specials,
7452 sizeof(struct special_t) * max_specials)) == 0) {
7453 ERR("failed to realloc specials array");
7459 // clear the window first
7460 XClearWindow(display, RootWindow(display, screen));
7463 #ifdef TCP_PORT_MONITOR
7464 info.p_tcp_port_monitor_collection = NULL;
7466 extract_variable_text(global_text);
7472 tmpstring1 = malloc(text_buffer_size);
7473 memset(tmpstring1, 0, text_buffer_size);
7477 tmpstring2 = malloc(text_buffer_size);
7478 memset(tmpstring2, 0, text_buffer_size);
7482 text_buffer = malloc(max_user_text);
7483 memset(text_buffer, 0, max_user_text);
7490 timed_thread_destroy_registered_threads();
7492 if (info.cpu_usage) {
7493 free(info.cpu_usage);
7494 info.cpu_usage = NULL;
7499 XdbeDeallocateBackBufferName(display, window.back_buffer);
7504 XDestroyWindow(display, window.window);
7505 XClearWindow(display, RootWindow(display, screen));
7510 XClearWindow(display, RootWindow(display, screen));
7515 XFreeGC(display, window.gc);
7519 free_text_objects(global_text_object_list);
7520 free(global_text_object_list);
7521 global_text_object_list = NULL;
7540 free(current_config);
7542 #ifdef TCP_PORT_MONITOR
7543 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7544 info.p_tcp_port_monitor_collection = NULL;
7553 for (i = 0; i < special_count; i++) {
7554 if (specials[i].type == GRAPH) {
7555 free(specials[i].graph);
7562 clear_diskio_stats();
7565 static int string_to_bool(const char *s)
7568 // Assumes an option without a true/false means true
7570 } else if (strcasecmp(s, "yes") == 0) {
7572 } else if (strcasecmp(s, "true") == 0) {
7574 } else if (strcasecmp(s, "1") == 0) {
7581 static enum alignment string_to_alignment(const char *s)
7583 if (strcasecmp(s, "top_left") == 0) {
7585 } else if (strcasecmp(s, "top_right") == 0) {
7587 } else if (strcasecmp(s, "top_middle") == 0) {
7589 } else if (strcasecmp(s, "bottom_left") == 0) {
7591 } else if (strcasecmp(s, "bottom_right") == 0) {
7592 return BOTTOM_RIGHT;
7593 } else if (strcasecmp(s, "bottom_middle") == 0) {
7594 return BOTTOM_MIDDLE;
7595 } else if (strcasecmp(s, "middle_left") == 0) {
7597 } else if (strcasecmp(s, "middle_right") == 0) {
7598 return MIDDLE_RIGHT;
7599 } else if (strcasecmp(s, "tl") == 0) {
7601 } else if (strcasecmp(s, "tr") == 0) {
7603 } else if (strcasecmp(s, "tm") == 0) {
7605 } else if (strcasecmp(s, "bl") == 0) {
7607 } else if (strcasecmp(s, "br") == 0) {
7608 return BOTTOM_RIGHT;
7609 } else if (strcasecmp(s, "bm") == 0) {
7610 return BOTTOM_MIDDLE;
7611 } else if (strcasecmp(s, "ml") == 0) {
7613 } else if (strcasecmp(s, "mr") == 0) {
7614 return MIDDLE_RIGHT;
7615 } else if (strcasecmp(s, "none") == 0) {
7622 static void set_default_configurations(void)
7624 fork_to_background = 0;
7625 total_run_times = 0;
7626 info.cpu_avg_samples = 2;
7627 info.net_avg_samples = 2;
7634 strcpy(info.mpd.host, "localhost");
7635 info.mpd.port = 6600;
7636 info.mpd.status = NULL;
7637 info.mpd.artist = NULL;
7638 info.mpd.album = NULL;
7639 info.mpd.title = NULL;
7640 info.mpd.random = NULL;
7641 info.mpd.track = NULL;
7642 info.mpd.name = NULL;
7643 info.mpd.file = NULL;
7646 info.xmms2.artist = NULL;
7647 info.xmms2.album = NULL;
7648 info.xmms2.title = NULL;
7649 info.xmms2.genre = NULL;
7650 info.xmms2.comment = NULL;
7651 info.xmms2.url = NULL;
7652 info.xmms2.status = NULL;
7653 info.xmms2.playlist = NULL;
7655 use_spacer = NO_SPACER;
7662 show_graph_scale = 0;
7663 default_fg_color = WhitePixel(display, screen);
7664 default_bg_color = BlackPixel(display, screen);
7665 default_out_color = BlackPixel(display, screen);
7666 color0 = default_fg_color;
7667 color1 = default_fg_color;
7668 color2 = default_fg_color;
7669 color3 = default_fg_color;
7670 color4 = default_fg_color;
7671 color5 = default_fg_color;
7672 color6 = default_fg_color;
7673 color7 = default_fg_color;
7674 color8 = default_fg_color;
7675 color9 = default_fg_color;
7678 draw_graph_borders = 1;
7680 set_first_font("6x10");
7688 window.type = TYPE_NORMAL;
7690 strcpy(window.class_name, "Conky");
7692 sprintf(window.title, "Conky (%s)", info.uname_s.nodename);
7694 stippled_borders = 0;
7697 text_alignment = BOTTOM_LEFT;
7700 free(current_mail_spool);
7704 variable_substitute(MAIL_FILE, buf, 256);
7705 if (buf[0] != '\0') {
7706 current_mail_spool = strndup(buf, text_buffer_size);
7711 update_interval = 3.0;
7712 info.music_player_interval = 1.0;
7713 stuff_in_upper_case = 0;
7714 info.users.number = 1;
7716 #ifdef TCP_PORT_MONITOR
7717 tcp_port_monitor_args.max_port_monitor_connections =
7718 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7722 static void load_config_file(const char *f)
7724 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7728 set_default_configurations();
7735 char buf[256], *p, *p2, *name, *value;
7738 if (fgets(buf, 256, fp) == NULL) {
7744 /* break at comment */
7745 p2 = strchr(p, '#');
7751 while (*p && isspace((int) *p)) {
7755 continue; /* empty line */
7762 while (*p2 && !isspace((int) *p2)) {
7766 *p2 = '\0'; /* break at name's end */
7773 while (*p && isspace((int) *p)) {
7779 p2 = value + strlen(value);
7780 while (isspace((int) *(p2 - 1))) {
7787 #define CONF2(a) if (strcasecmp(name, a) == 0)
7788 #define CONF(a) else CONF2(a)
7789 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7790 || strcasecmp(name, b) == 0)
7793 CONF2("alignment") {
7795 int a = string_to_alignment(value);
7806 CONF("background") {
7807 fork_to_background = string_to_bool(value);
7810 CONF2("background") {
7811 fork_to_background = string_to_bool(value);
7815 CONF("show_graph_scale") {
7816 show_graph_scale = string_to_bool(value);
7818 CONF("border_margin") {
7820 border_margin = strtol(value, 0, 0);
7825 CONF("border_width") {
7827 border_width = strtol(value, 0, 0);
7834 color0 = get_x11_color(value);
7841 color1 = get_x11_color(value);
7848 color2 = get_x11_color(value);
7855 color3 = get_x11_color(value);
7862 color4 = get_x11_color(value);
7869 color5 = get_x11_color(value);
7876 color6 = get_x11_color(value);
7883 color7 = get_x11_color(value);
7890 color8 = get_x11_color(value);
7897 color9 = get_x11_color(value);
7902 CONF("default_color") {
7904 default_fg_color = get_x11_color(value);
7909 CONF3("default_shade_color", "default_shadecolor") {
7911 default_bg_color = get_x11_color(value);
7916 CONF3("default_outline_color", "default_outlinecolor") {
7918 default_out_color = get_x11_color(value);
7926 info.mail = parse_mail_args(IMAP, value);
7933 info.mail = parse_mail_args(POP3, value);
7941 strncpy(info.mpd.host, value, 127);
7948 info.mpd.port = strtol(value, 0, 0);
7949 if (info.mpd.port < 1 || info.mpd.port > 0xffff) {
7954 CONF("mpd_password") {
7956 strncpy(info.mpd.password, value, 127);
7962 CONF("music_player_interval") {
7964 info.music_player_interval = strtod(value, 0);
7970 CONF("sensor_device") {
7972 sensor_device = strtol(value, 0, 0);
7978 CONF("cpu_avg_samples") {
7980 cpu_avg_samples = strtol(value, 0, 0);
7981 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
7984 info.cpu_avg_samples = cpu_avg_samples;
7990 CONF("net_avg_samples") {
7992 net_avg_samples = strtol(value, 0, 0);
7993 if (net_avg_samples < 1 || net_avg_samples > 14) {
7996 info.net_avg_samples = net_avg_samples;
8004 CONF("double_buffer") {
8005 use_xdbe = string_to_bool(value);
8009 CONF("override_utf8_locale") {
8010 utf8_mode = string_to_bool(value);
8012 CONF("draw_borders") {
8013 draw_borders = string_to_bool(value);
8015 CONF("draw_graph_borders") {
8016 draw_graph_borders = string_to_bool(value);
8018 CONF("draw_shades") {
8019 draw_shades = string_to_bool(value);
8021 CONF("draw_outline") {
8022 draw_outline = string_to_bool(value);
8025 CONF("out_to_console") {
8026 out_to_console = string_to_bool(value);
8028 CONF("use_spacer") {
8030 if (strcasecmp(value, "left") == 0) {
8031 use_spacer = LEFT_SPACER;
8032 } else if (strcasecmp(value, "right") == 0) {
8033 use_spacer = RIGHT_SPACER;
8034 } else if (strcasecmp(value, "none") == 0) {
8035 use_spacer = NO_SPACER;
8037 use_spacer = string_to_bool(value);
8038 ERR("use_spacer should have an argument of left, right, or"
8039 " none. '%s' seems to be some form of '%s', so"
8040 " defaulting to %s.", value,
8041 use_spacer ? "true" : "false",
8042 use_spacer ? "right" : "none");
8044 use_spacer = RIGHT_SPACER;
8046 use_spacer = NO_SPACER;
8050 ERR("use_spacer should have an argument. Defaulting to right.");
8051 use_spacer = RIGHT_SPACER;
8057 use_xft = string_to_bool(value);
8061 set_first_font(value);
8067 if (value && font_count >= 0) {
8068 fonts[0].font_alpha = atof(value) * 65535.0;
8077 if (string_to_bool(value)) {
8078 ERR("Xft not enabled");
8082 /* xftfont silently ignored when no Xft */
8085 /* xftalpha is silently ignored when no Xft */
8090 set_first_font(value);
8100 gap_x = atoi(value);
8107 gap_y = atoi(value);
8113 CONF("mail_spool") {
8117 variable_substitute(value, buffer, 256);
8119 if (buffer[0] != '\0') {
8120 if (current_mail_spool) {
8121 free(current_mail_spool);
8123 current_mail_spool = strndup(buffer, text_buffer_size);
8130 CONF("minimum_size") {
8132 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
8134 if (sscanf(value, "%d", &minimum_width) != 1) {
8142 CONF("maximum_width") {
8144 if (sscanf(value, "%d", &maximum_width) != 1) {
8152 CONF("no_buffers") {
8153 no_buffers = string_to_bool(value);
8155 CONF("top_cpu_separate") {
8156 cpu_separate = string_to_bool(value);
8158 CONF("short_units") {
8159 short_units = string_to_bool(value);
8161 CONF("pad_percents") {
8162 pad_percents = atoi(value);
8166 CONF("own_window") {
8168 own_window = string_to_bool(value);
8173 CONF("own_window_class") {
8175 memset(window.class_name, 0, sizeof(window.class_name));
8176 strncpy(window.class_name, value,
8177 sizeof(window.class_name) - 1);
8182 CONF("own_window_title") {
8184 memset(window.title, 0, sizeof(window.title));
8185 strncpy(window.title, value, sizeof(window.title) - 1);
8190 CONF("own_window_transparent") {
8192 set_transparent = string_to_bool(value);
8197 CONF("own_window_colour") {
8199 background_colour = get_x11_color(value);
8201 ERR("Invalid colour for own_window_colour (try omitting the "
8202 "'#' for hex colours");
8205 CONF("own_window_hints") {
8207 char *p_hint, *p_save;
8208 char delim[] = ", ";
8210 /* tokenize the value into individual hints */
8211 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
8213 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
8214 if (strncmp(p_hint, "undecorate", 10) == 0) {
8215 SET_HINT(window.hints, HINT_UNDECORATED);
8216 } else if (strncmp(p_hint, "below", 5) == 0) {
8217 SET_HINT(window.hints, HINT_BELOW);
8218 } else if (strncmp(p_hint, "above", 5) == 0) {
8219 SET_HINT(window.hints, HINT_ABOVE);
8220 } else if (strncmp(p_hint, "sticky", 6) == 0) {
8221 SET_HINT(window.hints, HINT_STICKY);
8222 } else if (strncmp(p_hint, "skip_taskbar", 12) == 0) {
8223 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
8224 } else if (strncmp(p_hint, "skip_pager", 10) == 0) {
8225 SET_HINT(window.hints, HINT_SKIP_PAGER);
8230 p_hint = strtok_r(NULL, delim, &p_save);
8231 } while (p_hint != NULL);
8237 CONF("own_window_type") {
8239 if (strncmp(value, "normal", 6) == 0) {
8240 window.type = TYPE_NORMAL;
8241 } else if (strncmp(value, "desktop", 7) == 0) {
8242 window.type = TYPE_DESKTOP;
8243 } else if (strncmp(value, "dock", 7) == 0) {
8244 window.type = TYPE_DOCK;
8245 } else if (strncmp(value, "override", 8) == 0) {
8246 window.type = TYPE_OVERRIDE;
8255 CONF("stippled_borders") {
8257 stippled_borders = strtol(value, 0, 0);
8259 stippled_borders = 4;
8264 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> "
8268 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> "
8271 CONF("update_interval") {
8273 update_interval = strtod(value, 0);
8277 if (info.music_player_interval == 0) {
8278 // default to update_interval
8279 info.music_player_interval = update_interval;
8282 CONF("total_run_times") {
8284 total_run_times = strtod(value, 0);
8290 stuff_in_upper_case = string_to_bool(value);
8292 CONF("max_specials") {
8294 max_specials = atoi(value);
8299 CONF("max_user_text") {
8301 max_user_text = atoi(value);
8306 CONF("text_buffer_size") {
8308 text_buffer_size = atoi(value);
8309 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
8310 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
8311 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
8323 global_text = (char *) malloc(1);
8324 global_text[0] = '\0';
8327 unsigned int l = strlen(global_text);
8329 if (fgets(buf, 256, fp) == NULL) {
8332 global_text = (char *) realloc(global_text, l + strlen(buf) + 1);
8333 strcat(global_text, buf);
8335 if (strlen(global_text) > max_user_text) {
8340 if (strlen(global_text) < 1) {
8341 CRIT_ERR("no text supplied in configuration; exiting");
8343 global_text_lines = line + 1;
8346 #ifdef TCP_PORT_MONITOR
8347 CONF("max_port_monitor_connections") {
8348 if (!value || (sscanf(value, "%d",
8349 &tcp_port_monitor_args.max_port_monitor_connections) != 1)
8350 || tcp_port_monitor_args.max_port_monitor_connections < 0) {
8351 /* an error. use default, warn and continue. */
8352 tcp_port_monitor_args.max_port_monitor_connections =
8353 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8355 } else if (tcp_port_monitor_args.max_port_monitor_connections
8357 /* no error, just use default */
8358 tcp_port_monitor_args.max_port_monitor_connections =
8359 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8361 /* else tcp_port_monitor_args.max_port_monitor_connections > 0
8365 CONF("if_up_strictness") {
8367 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8368 ifup_strictness = IFUP_UP;
8369 } else if (!strcmp(value, "up")) {
8370 ifup_strictness = IFUP_UP;
8371 } else if (!strcmp(value, "link")) {
8372 ifup_strictness = IFUP_LINK;
8373 } else if (!strcmp(value, "address")) {
8374 ifup_strictness = IFUP_ADDR;
8376 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8377 ifup_strictness = IFUP_UP;
8381 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8392 if (info.music_player_interval == 0) {
8393 // default to update_interval
8394 info.music_player_interval = update_interval;
8396 if (!global_text) { // didn't supply any text
8397 CRIT_ERR("missing text block in configuration; exiting");
8401 static void print_help(const char *prog_name) {
8402 printf("Usage: %s [OPTION]...\n"
8403 "Conky is a system monitor that renders text on desktop or to own transparent\n"
8404 "window. Command line options will override configurations defined in config\n"
8406 " -v, --version version\n"
8407 " -q, --quiet quiet mode\n"
8408 " -c, --config=FILE config file to load\n"
8409 " -d, --daemonize daemonize, fork to background\n"
8410 " -h, --help help\n"
8412 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
8413 " -f, --font=FONT font to use\n"
8415 " -o, --own-window create own window to draw\n"
8418 " -b, --double-buffer double buffer (prevents flickering)\n"
8420 " -w, --window-id=WIN_ID window id to draw\n"
8421 " -x X x position\n"
8422 " -y Y y position\n"
8424 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8425 " -u, --interval=SECS update interval\n"
8426 " -i COUNT number of times to update Conky (and quit)\n",
8431 /* : means that character before that takes an argument */
8432 static const char *getopt_string = "vVqdt:u:i:hc:"
8444 static const struct option longopts[] = {
8445 { "help", 0, NULL, 'h' },
8446 { "version", 0, NULL, 'V' },
8447 { "config", 1, NULL, 'c' },
8448 { "daemonize", 0, NULL, 'd' },
8450 { "alignment", 1, NULL, 'a' },
8451 { "font", 1, NULL, 'f' },
8453 { "own-window", 0, NULL, 'o' },
8456 { "double-buffer", 0, NULL, 'b' },
8458 { "window-id", 1, NULL, 'w' },
8460 { "text", 1, NULL, 't' },
8461 { "interval", 0, NULL, 'u' },
8465 int main(int argc, char **argv)
8471 struct sigaction act, oact;
8473 g_signal_pending = 0;
8474 memset(&info, 0, sizeof(info));
8476 #ifdef TCP_PORT_MONITOR
8477 tcp_port_monitor_args.max_port_monitor_connections =
8478 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8481 /* handle command line parameters that don't change configs */
8483 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8484 || ((s = getenv("LANG")) && *s)) {
8485 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8487 ERR("malloc failed");
8489 for (x = 0; x < strlen(s); x++) {
8490 temp[x] = tolower(s[x]);
8493 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8499 if (!setlocale(LC_CTYPE, "")) {
8500 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8504 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8515 if (current_config) {
8516 free(current_config);
8518 current_config = strndup(optarg, max_user_text);
8521 freopen("/dev/null", "w", stderr);
8524 print_help(argv[0]);
8528 window.window = strtol(optarg, 0, 0);
8537 /* initalize X BEFORE we load config.
8538 * (we need to so that 'screen' is set) */
8542 /* check if specified config file is valid */
8543 if (current_config) {
8545 if (stat(current_config, &sb) ||
8546 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8547 ERR("invalid configuration file '%s'\n", current_config);
8548 free(current_config);
8553 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8555 if (!current_config) {
8556 /* load default config file */
8560 /* Try to use personal config file first */
8561 variable_substitute(CONFIG_FILE, buf, sizeof(buf));
8562 if (buf[0] && (fp = fopen(buf, "r"))) {
8563 current_config = strndup(buf, max_user_text);
8567 /* Try to use system config file if personal config not readable */
8568 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8569 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
8573 /* No readable config found */
8574 if (!current_config) {
8575 CRIT_ERR("no readable personal or system-wide config file found");
8579 load_config_file(current_config);
8581 /* init specials array */
8582 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8583 ERR("failed to create specials array");
8587 if (current_mail_spool == NULL) {
8590 variable_substitute(MAIL_FILE, buf, 256);
8592 if (buf[0] != '\0') {
8593 current_mail_spool = strndup(buf, text_buffer_size);
8598 /* handle other command line arguments */
8600 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8601 || defined(__NetBSD__)
8602 optind = optreset = 1;
8607 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8608 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8609 "kvm_open")) == NULL) {
8610 CRIT_ERR("cannot read kvm");
8615 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8623 fork_to_background = 1;
8628 set_first_font(optarg);
8631 text_alignment = string_to_alignment(optarg);
8650 global_text = strndup(optarg, max_user_text);
8651 convert_escapes(global_text);
8655 update_interval = strtod(optarg, 0);
8656 if (info.music_player_interval == 0) {
8657 // default to update_interval
8658 info.music_player_interval = update_interval;
8663 total_run_times = strtod(optarg, 0);
8667 gap_x = atoi(optarg);
8671 gap_y = atoi(optarg);
8685 /* generate text and get initial size */
8686 extract_variable_text(global_text);
8693 if (fork_to_background) {
8698 ERR("Conky: couldn't fork() to background: %s",
8705 fprintf(stderr, "\n");
8710 /* parent process */
8711 fprintf(stderr, "Conky: forked to background, pid is %d\n",
8718 text_buffer = malloc(max_user_text);
8719 memset(text_buffer, 0, max_user_text);
8720 tmpstring1 = malloc(text_buffer_size);
8721 memset(tmpstring1, 0, text_buffer_size);
8722 tmpstring2 = malloc(text_buffer_size);
8723 memset(tmpstring2, 0, text_buffer_size);
8727 update_text_area(); /* to get initial size of the window */
8730 init_window(own_window, text_width + border_margin * 2 + 1,
8731 text_height + border_margin * 2 + 1, set_transparent, background_colour,
8733 #else /* OWN_WINDOW */
8734 init_window(0, text_width + border_margin * 2 + 1,
8735 text_height + border_margin * 2 + 1, set_transparent, 0,
8737 #endif /* OWN_WINDOW */
8740 update_text_area(); /* to position text/window on screen */
8745 if (own_window && !fixed_pos) {
8746 XMoveWindow(display, window.window, window.x, window.y);
8749 set_transparent_background(window.window);
8759 /* Set signal handlers */
8760 act.sa_handler = signal_handler;
8761 sigemptyset(&act.sa_mask);
8764 act.sa_flags |= SA_RESTART;
8767 if (sigaction(SIGINT, &act, &oact) < 0
8768 || sigaction(SIGUSR1, &act, &oact) < 0
8769 || sigaction(SIGHUP,&act,&oact) < 0
8770 || sigaction(SIGTERM, &act, &oact) < 0) {
8771 ERR("error setting signal handler: %s", strerror(errno));
8774 /* *************** *
8776 * *************** */
8779 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8786 void signal_handler(int sig)
8788 /* signal handler is light as a feather, as it should be.
8789 * we will poll g_signal_pending with each loop of conky
8790 * and do any signal processing there, NOT here. */
8791 g_signal_pending = sig;