1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10 * Copyright (c) 2005-2008 Brenden Matthews, Philip Kovacs, et. al.
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
45 #include <X11/Xutil.h>
47 #include <X11/extensions/Xdamage.h>
53 #include <sys/types.h>
55 #include <netinet/in.h>
67 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
70 #define CONFIG_FILE "$HOME/.conkyrc"
71 #define MAIL_FILE "$MAIL"
72 #define MAX_IF_BLOCK_DEPTH 5
73 #define MAX_TAIL_LINES 100
75 /* #define SIGNAL_BLOCKING */
76 #undef SIGNAL_BLOCKING
78 static void print_version(void) __attribute__((noreturn));
80 static void print_version(void)
82 printf("Conky %s compiled %s for %s\n", VERSION, BUILD_DATE, BUILD_ARCH);
84 printf("\nCompiled in features:\n\n"
85 "System config file: %s\n\n"
89 " * Xdamage extension\n"
90 # endif /* HAVE_XDAMAGE */
92 " * Xdbe extension (double buffer)\n"
93 # endif /* HAVE_XDBE */
98 "\n Music detection:\n"
101 #endif /* AUDACIOUS */
111 "\n General features:\n"
115 #ifdef TCP_PORT_MONITOR
117 #endif /* TCP_PORT_MONITOR */
123 #endif /* HAVE_IWLIB */
127 "", SYSTEM_CONFIG_FILE
133 static const char *suffixes[] = { "B", "kiB", "MiB", "GiB", "TiB", "PiB", "" };
139 static int text_start_x, text_start_y; /* text start position in window */
140 static int text_width, text_height;
158 char name[DEFAULT_TEXT_BUFFER_SIZE];
168 static int selected_font = 0;
169 static int font_count = -1;
170 struct font_list *fonts = NULL;
174 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + \
175 fonts[selected_font].xftfont->descent) \
176 : (fonts[selected_font].font->max_bounds.ascent + \
177 fonts[selected_font].font->max_bounds.descent))
178 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent \
179 : fonts[selected_font].font->max_bounds.ascent)
180 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent \
181 : fonts[selected_font].font->max_bounds.descent)
185 #define font_height() (fonts[selected_font].font->max_bounds.ascent + \
186 fonts[selected_font].font->max_bounds.descent)
187 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
188 #define font_descent() fonts[selected_font].font->max_bounds.descent
192 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
194 static void set_font(void);
196 int addfont(const char *data_in)
198 if (font_count > MAX_FONTS) {
199 CRIT_ERR("you don't need that many fonts, sorry.");
202 if (font_count == 0) {
206 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
210 memset(fonts, 0, sizeof(struct font_list));
212 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
213 memset(&fonts[font_count], 0, sizeof(struct font_list));
215 CRIT_ERR("realloc in addfont");
217 // must account for null terminator
218 if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
219 strncpy(fonts[font_count].name, data_in, text_buffer_size);
221 fonts[font_count].font_alpha = 0xffff;
224 CRIT_ERR("Oops...looks like something overflowed in addfont().");
229 void set_first_font(const char *data_in)
231 if (font_count < 0) {
232 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
236 memset(fonts, 0, sizeof(struct font_list));
239 if (strlen(data_in) > 1) {
240 strncpy(fonts[0].name, data_in, text_buffer_size);
242 fonts[0].font_alpha = 0xffff;
247 void free_fonts(void)
251 for (i = 0; i <= font_count; i++) {
254 XftFontClose(display, fonts[i].xftfont);
255 fonts[i].xftfont = 0;
259 XFreeFont(display, fonts[i].font);
269 static void load_fonts(void)
273 for (i = 0; i <= font_count; i++) {
276 if (use_xft && fonts[i].xftfont) {
278 } else if (use_xft) {
279 /* if (fonts[i].xftfont != NULL && selected_font == 0) {
280 XftFontClose(display, fonts[i].xftfont);
282 fonts[i].xftfont = XftFontOpenName(display, screen,
284 if (fonts[i].xftfont != NULL) {
288 ERR("can't load Xft font '%s'", fonts[i].name);
289 if ((fonts[i].xftfont = XftFontOpenName(display, screen,
290 "courier-12")) != NULL) {
294 ERR("can't load Xft font '%s'", "courier-12");
296 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
297 CRIT_ERR("can't load font '%s'", "fixed");
304 /* load normal font */
305 /* if (fonts[i].font != NULL) {
306 XFreeFont(display, fonts[i].font);
309 if (fonts[i].font || (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
310 ERR("can't load font '%s'", fonts[i].name);
311 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
312 CRIT_ERR("can't load font '%s'", "fixed");
313 printf("loaded fixed?\n");
321 /* default config file */
322 static char *current_config;
324 /* set to 1 if you want all text to be in uppercase */
325 static unsigned int stuff_in_upper_case;
327 /* Run how many times? */
328 static unsigned long total_run_times;
331 static int fork_to_background;
333 static int cpu_avg_samples, net_avg_samples;
337 /* Position on the screen */
338 static int text_alignment;
339 static int gap_x, gap_y;
342 static int draw_borders;
343 static int draw_graph_borders;
344 static int stippled_borders;
346 static int draw_shades, draw_outline;
348 static int border_margin, border_width;
350 static long default_fg_color, default_bg_color, default_out_color;
352 /* create own window or draw stuff to root? */
353 static int set_transparent = 0;
356 static int own_window = 0;
357 static int background_colour = 0;
359 /* fixed size/pos is set if wm/user changes them */
360 static int fixed_size = 0, fixed_pos = 0;
363 static int minimum_width, minimum_height;
364 static int maximum_width;
369 static int sensor_device;
372 static long color0, color1, color2, color3, color4, color5, color6, color7,
375 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
376 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
378 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
379 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
381 /* maximum size of individual text buffers, ie $exec buffer size */
382 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
385 #define CODEPAGE_LENGTH 20
387 long iconv_count = 0;
388 char iconv_converting;
389 static iconv_t **iconv_cd = 0;
391 int register_iconv(iconv_t *new_iconv)
393 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
395 CRIT_ERR("Out of memory");
397 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
398 if (!iconv_cd[iconv_count]) {
399 CRIT_ERR("Out of memory");
401 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
406 void free_iconv(void)
411 for (i = 0; i < iconv_count; i++) {
413 iconv_close(*iconv_cd[i]);
427 /* no buffers in used memory? */
430 /* pad percentages to decimals? */
431 static int pad_percents = 0;
433 #ifdef TCP_PORT_MONITOR
434 tcp_port_monitor_args_t tcp_port_monitor_args;
437 static char *text = 0;
440 static int total_updates;
443 static int blockdepth = 0;
444 static int if_jumped = 0;
445 static int blockstart[MAX_IF_BLOCK_DEPTH];
447 int check_contains(char *f, char *s)
450 FILE *where = fopen(f, "r");
453 char buf1[256], buf2[256];
455 while (fgets(buf1, 256, where)) {
456 sscanf(buf1, "%255s", buf2);
457 if (strstr(buf2, s)) {
464 ERR("Could not open the file");
470 static inline int calc_text_width(const char *s, int l)
477 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
478 (const FcChar8 *) s, l, &gi);
480 XftTextExtents8(display, fonts[selected_font].xftfont,
481 (const FcChar8 *) s, l, &gi);
487 return XTextWidth(fonts[selected_font].font, s, l);
492 /* formatted text to render on screen, generated in generate_text(),
493 * drawn in draw_stuff() */
495 static char *text_buffer;
497 /* special stuff in text_buffer */
499 #define SPECIAL_CHAR '\x01'
527 unsigned long first_colour; // for graph gradient
528 unsigned long last_colour;
532 /* create specials array on heap instead of stack with introduction of
534 static struct special_t *specials = NULL;
536 static unsigned int special_count;
539 static unsigned int special_index; /* used when drawing */
542 /* why 256? cause an array of more then 256 doubles seems excessive,
543 * and who needs that kind of precision anyway? */
544 #define MAX_GRAPH_DEPTH 256
546 static struct special_t *new_special(char *buf, enum special_types t)
548 if (special_count >= max_specials) {
549 CRIT_ERR("too many special things in text");
552 buf[0] = SPECIAL_CHAR;
554 specials[special_count].type = t;
555 return &specials[special_count++];
558 long fwd_fcharfind(FILE *fp, char val, unsigned int step)
562 unsigned int count = 0;
563 static char buf[BUFSZ];
564 long orig_pos = ftell(fp);
566 long buf_size = BUFSZ;
567 char *cur_found = NULL;
569 while (count < step) {
570 if (cur_found == NULL) {
571 buf_size = fread(buf, 1, buf_size, fp);
574 cur_found = memchr(buf + buf_pos, val, buf_size - buf_pos);
575 if (cur_found != NULL) {
576 buf_pos = cur_found - buf + 1;
585 ret = ftell(fp) - buf_size + buf_pos - 1;
587 fseek(fp, orig_pos, SEEK_SET);
593 void *memrchr(const void *buffer, char c, size_t n)
595 const unsigned char *p = buffer;
597 for (p += n; n; n--) {
606 long rev_fcharfind(FILE *fp, char val, unsigned int step)
610 unsigned int count = 0;
611 static char buf[BUFSZ];
612 long orig_pos = ftell(fp);
614 long file_pos = orig_pos;
615 long buf_size = BUFSZ;
618 while (count < step) {
620 if (file_pos > BUFSZ) {
621 fseek(fp, file_pos - BUFSZ, SEEK_SET);
624 fseek(fp, 0, SEEK_SET);
626 file_pos = ftell(fp);
627 buf_pos = fread(buf, 1, buf_size, fp);
629 cur_found = memrchr(buf, val, (size_t) buf_pos);
630 if (cur_found != NULL) {
631 buf_pos = cur_found - buf;
640 fseek(fp, orig_pos, SEEK_SET);
642 ret = file_pos + buf_pos;
648 static void new_bar(char *buf, int w, int h, int usage)
650 struct special_t *s = new_special(buf, BAR);
652 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
657 static const char *scan_bar(const char *args, int *w, int *h)
659 /* zero width means all space that is available */
662 /* bar's argument is either height or height,width */
666 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) {
667 sscanf(args, "%d %n", h, &n);
675 static char *scan_font(const char *args)
678 return strndup(args, text_buffer_size);
685 static void new_font(char *buf, char *args)
688 struct special_t *s = new_special(buf, FONT);
690 if (s->font_added > font_count || !s->font_added || strncmp(args, fonts[s->font_added].name, DEFAULT_TEXT_BUFFER_SIZE)) {
691 int tmp = selected_font;
693 selected_font = s->font_added = addfont(args);
698 struct special_t *s = new_special(buf, FONT);
699 int tmp = selected_font;
701 selected_font = s->font_added = 0;
707 inline void graph_append(struct special_t *graph, double f)
711 if (!graph->scaled && f > graph->graph_scale) {
712 f = graph->graph_scale;
716 graph->graph_scale = 1;
718 graph->graph[0] = f; /* add new data */
719 /* shift all the data by 1 */
720 for (i = graph->graph_width - 1; i > 0; i--) {
721 graph->graph[i] = graph->graph[i - 1];
722 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
723 /* check if we need to update the scale */
724 graph->graph_scale = graph->graph[i];
729 short colour_depth = 0;
730 void set_up_gradient(void);
732 /* precalculated: 31/255, and 63/255 */
733 #define CONST_8_TO_5_BITS 0.12156862745098
734 #define CONST_8_TO_6_BITS 0.247058823529412
736 /* adjust color values depending on color depth */
737 static unsigned int adjust_colors(unsigned int color)
741 if (colour_depth == 0) {
744 if (colour_depth == 16) {
745 r = (color & 0xff0000) >> 16;
746 g = (color & 0xff00) >> 8;
748 color = (int) (r * CONST_8_TO_5_BITS) << 11;
749 color |= (int) (g * CONST_8_TO_6_BITS) << 5;
750 color |= (int) (b * CONST_8_TO_5_BITS);
755 static void new_graph(char *buf, int w, int h, unsigned int first_colour,
756 unsigned int second_colour, double i, int scale, int append)
758 struct special_t *s = new_special(buf, GRAPH);
761 if (s->graph == NULL) {
762 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
763 // subtract 2 for the box
764 s->graph_width = s->width /* - 2 */;
766 s->graph_width = MAX_GRAPH_DEPTH - 2;
768 s->graph = malloc(s->graph_width * sizeof(double));
769 memset(s->graph, 0, s->graph_width * sizeof(double));
770 s->graph_scale = 100;
773 s->first_colour = adjust_colors(first_colour);
774 s->last_colour = adjust_colors(second_colour);
781 s->graph_width = s->width - 2; // subtract 2 for rectangle around
786 s->graph_scale = scale;
793 static char *scan_graph(const char *args, int *w, int *h,
794 unsigned int *first_colour, unsigned int *last_colour,
799 /* zero width means all space that is available */
805 /* graph's argument is either height or height,width */
807 if (sscanf(args, "%d,%d %x %x %u", h, w, first_colour, last_colour,
812 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) {
815 if (sscanf(args, "%63s %d,%d %x %x %u", buf, h, w, first_colour,
816 last_colour, scale) == 6) {
817 return strndup(buf, text_buffer_size);
820 if (sscanf(args, "%63s %d,%d %x %x", buf, h, w, first_colour,
822 return strndup(buf, text_buffer_size);
827 if (sscanf(args, "%x %x %u", first_colour, last_colour, scale) == 3) {
831 if (sscanf(args, "%x %x", first_colour, last_colour) == 2) {
834 if (sscanf(args, "%63s %x %x %u", buf, first_colour, last_colour,
836 return strndup(buf, text_buffer_size);
839 if (sscanf(args, "%63s %x %x", buf, first_colour, last_colour) == 3) {
840 return strndup(buf, text_buffer_size);
845 if (sscanf(args, "%d,%d %u", h, w, scale) == 3) {
849 if (sscanf(args, "%d,%d", h, w) == 2) {
852 if (sscanf(args, "%63s %d,%d %u", buf, h, w, scale) < 4) {
854 //TODO: check the return value and throw an error?
855 sscanf(args, "%63s %d,%d", buf, h, w);
858 return strndup(buf, text_buffer_size);
861 if (buf[0] == '\0') {
864 return strndup(buf, text_buffer_size);
868 static inline void new_hr(char *buf, int a)
870 new_special(buf, HORIZONTAL_LINE)->height = a;
873 static inline void new_stippled_hr(char *buf, int a, int b)
875 struct special_t *s = new_special(buf, STIPPLED_HR);
881 static inline void new_fg(char *buf, long c)
883 new_special(buf, FG)->arg = c;
886 static inline void new_bg(char *buf, long c)
888 new_special(buf, BG)->arg = c;
891 static inline void new_outline(char *buf, long c)
893 new_special(buf, OUTLINE)->arg = c;
896 static inline void new_offset(char *buf, long c)
898 new_special(buf, OFFSET)->arg = c;
901 static inline void new_voffset(char *buf, long c)
903 new_special(buf, VOFFSET)->arg = c;
906 static inline void new_alignr(char *buf, long c)
908 new_special(buf, ALIGNR)->arg = c;
911 static inline void new_alignc(char *buf, long c)
913 new_special(buf, ALIGNC)->arg = c;
916 static inline void new_goto(char *buf, long c)
918 new_special(buf, GOTO)->arg = c;
921 static inline void new_tab(char *buf, int a, int b)
923 struct special_t *s = new_special(buf, TAB);
929 /* quite boring functions */
931 static inline void for_each_line(char *b, void f(char *))
935 for (ps = b, pe = b; *pe; pe++) {
949 static void convert_escapes(char *buf)
951 char *p = buf, *s = buf;
958 } else if (*s == '\\') {
969 /* Prints anything normally printed with snprintf according to the current value
970 * of use_spacer. Actually slightly more flexible than snprintf, as you can
971 * safely specify the destination buffer as one of your inputs. */
972 static int spaced_print(char *, int, const char *, int, const char *, ...)
973 __attribute__((format(printf, 3, 6)));
975 static int spaced_print(char *buf, int size, const char *format, int width,
976 const char *func_name, ...) {
984 tempbuf = malloc(size * sizeof(char));
986 // Passes the varargs along to vsnprintf
987 va_start(argp, func_name);
988 vsnprintf(tempbuf, size, format, argp);
991 switch (use_spacer) {
993 len = snprintf(buf, size, "%s", tempbuf);
996 len = snprintf(buf, size, "%*s", width - 1, tempbuf);
999 len = snprintf(buf, size, "%-*s", width - 1, tempbuf);
1002 CRIT_ERR("%s encountered invalid use_spacer value (%d)", func_name,
1011 /* converts from bytes to human readable format (k, M, G, T) */
1012 static void human_readable(long long num, char *buf, int size, const char *func_name)
1014 const char **suffix = suffixes;
1017 static const int WIDTH = 10, SHORT_WIDTH = 8;
1021 spaced_print(buf, size, "%lld%c", SHORT_WIDTH, func_name, num,
1024 spaced_print(buf, size, "%lld%s", WIDTH, func_name, num, *suffix);
1029 while (num / 1024 >= 1000LL && **(suffix + 2)) {
1035 fnum = num / 1024.0;
1040 if (precision < 0) {
1044 len = spaced_print(buf, size, "%.*f%c", SHORT_WIDTH, func_name,
1045 precision, fnum, **suffix);
1047 len = spaced_print(buf, size, "%.*f%s", WIDTH, func_name, precision,
1050 } while (len >= (short_units ? SHORT_WIDTH : WIDTH) || len >= size);
1055 enum text_object_type {
1057 #if defined(__linux__)
1059 #endif /* __linux__ */
1069 OBJ_battery_percent,
1071 #endif /* !__OpenBSD__ */
1086 OBJ_conky_build_date,
1087 OBJ_conky_build_arch,
1096 OBJ_diskiograph_read,
1097 OBJ_diskiograph_write,
1135 #if defined(__linux__)
1142 OBJ_i8k_left_fan_status,
1143 OBJ_i8k_right_fan_status,
1144 OBJ_i8k_left_fan_rpm,
1145 OBJ_i8k_right_fan_rpm,
1147 OBJ_i8k_buttons_status,
1163 OBJ_wireless_bitrate,
1165 OBJ_wireless_link_qual,
1166 OBJ_wireless_link_qual_max,
1167 OBJ_wireless_link_qual_perc,
1168 OBJ_wireless_link_bar,
1169 #endif /* __linux__ */
1201 OBJ_running_processes,
1210 OBJ_temp1, /* i2c is used instead in these */
1234 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
1235 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1237 OBJ_apm_battery_time,
1238 OBJ_apm_battery_life,
1239 #endif /* __FreeBSD__ __OpenBSD__ */
1241 OBJ_obsd_sensors_temp,
1242 OBJ_obsd_sensors_fan,
1243 OBJ_obsd_sensors_volt,
1246 #endif /* __OpenBSD__ */
1268 OBJ_music_player_interval,
1288 OBJ_xmms2_timesplayed,
1291 OBJ_audacious_status,
1292 OBJ_audacious_title,
1293 OBJ_audacious_length,
1294 OBJ_audacious_length_seconds,
1295 OBJ_audacious_position,
1296 OBJ_audacious_position_seconds,
1297 OBJ_audacious_bitrate,
1298 OBJ_audacious_frequency,
1299 OBJ_audacious_channels,
1300 OBJ_audacious_filename,
1301 OBJ_audacious_playlist_length,
1302 OBJ_audacious_playlist_position,
1316 #ifdef TCP_PORT_MONITOR
1330 OBJ_if_smapi_bat_installed,
1333 OBJ_entropy_poolsize,
1337 struct text_object {
1339 char *s; /* some string */
1340 int i; /* some integer */
1341 long l; /* some other integer */
1342 unsigned int sensor;
1343 struct net_stat *net;
1345 struct diskio_stat *diskio;
1346 unsigned char loadavg[3];
1347 unsigned int cpu_index;
1348 struct mail_s *mail;
1356 char *tz; /* timezone variable */
1357 char *fmt; /* time display formatting */
1395 /* If not -1, a file descriptor to read from when
1396 * logfile is a FIFO. */
1413 timed_thread *p_timed_thread;
1419 #ifdef TCP_PORT_MONITOR
1421 /* starting port to monitor */
1422 in_port_t port_range_begin;
1423 /* ending port to monitor */
1424 in_port_t port_range_end;
1425 /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1427 /* 0 to n-1 connections. */
1428 int connection_index;
1446 struct local_mail_s local_mail;
1451 unsigned int c, d, e;
1456 struct text_object_list {
1457 unsigned int text_object_count;
1458 struct text_object *text_objects;
1461 static unsigned int global_text_object_count;
1462 static struct text_object *global_text_objects;
1463 static void generate_text_internal(char *p, int p_max_size,
1464 struct text_object *objs, unsigned int object_count,
1465 struct information *cur);
1467 #define MAXDATASIZE 1000
1471 struct mail_s *parse_mail_args(char type, const char *arg)
1473 struct mail_s *mail;
1476 mail = malloc(sizeof(struct mail_s));
1477 memset(mail, 0, sizeof(struct mail_s));
1479 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass)
1482 ERR("Scanning IMAP args failed");
1483 } else if (type == IMAP) {
1484 ERR("Scanning POP3 args failed");
1487 // see if password needs prompting
1488 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1489 int fp = fileno(stdin);
1490 struct termios term;
1492 tcgetattr(fp, &term);
1493 term.c_lflag &= ~ECHO;
1494 tcsetattr(fp, TCSANOW, &term);
1495 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1496 scanf("%128s", mail->pass);
1498 term.c_lflag |= ECHO;
1499 tcsetattr(fp, TCSANOW, &term);
1501 // now we check for optional args
1502 tmp = strstr(arg, "-i ");
1505 sscanf(tmp, "%f", &mail->interval);
1507 mail->interval = 300; // 5 minutes
1509 tmp = strstr(arg, "-p ");
1512 sscanf(tmp, "%lu", &mail->port);
1515 mail->port = 110; // default pop3 port
1516 } else if (type == IMAP) {
1517 mail->port = 143; // default imap port
1521 tmp = strstr(arg, "-f ");
1524 sscanf(tmp, "%s", mail->folder);
1526 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1529 tmp = strstr(arg, "-e ");
1534 if (tmp[0] == '\'') {
1535 len = strstr(tmp + 1, "'") - tmp - 1;
1540 strncpy(mail->command, tmp + 1, len);
1542 mail->command[0] = '\0';
1544 mail->p_timed_thread = NULL;
1548 void *imap_thread(void *arg)
1550 int sockfd, numbytes;
1551 char recvbuf[MAXDATASIZE];
1552 char sendbuf[MAXDATASIZE];
1555 unsigned int old_unseen = UINT_MAX;
1556 unsigned int old_messages = UINT_MAX;
1557 struct stat stat_buf;
1559 struct sockaddr_in their_addr; // connector's address information
1560 struct mail_s *mail = (struct mail_s *)arg;
1562 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1563 herror("gethostbyname");
1567 struct timeval timeout;
1572 ERR("Trying IMAP connection again for %s@%s (try %i/5)",
1573 mail->user, mail->host, fail + 1);
1575 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1578 goto next_iteration;
1582 their_addr.sin_family = AF_INET;
1583 // short, network byte order
1584 their_addr.sin_port = htons(mail->port);
1585 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1586 // zero the rest of the struct
1587 memset(&(their_addr.sin_zero), '\0', 8);
1589 if (connect(sockfd, (struct sockaddr *) &their_addr,
1590 sizeof(struct sockaddr)) == -1) {
1593 goto next_iteration;
1596 timeout.tv_sec = 60; // 60 second timeout i guess
1597 timeout.tv_usec = 0;
1599 FD_SET(sockfd, &fdset);
1600 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1602 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1605 goto next_iteration;
1608 ERR("IMAP connection failed: timeout");
1610 goto next_iteration;
1612 recvbuf[numbytes] = '\0';
1613 if (strstr(recvbuf, "* OK") != recvbuf) {
1614 ERR("IMAP connection failed, probably not an IMAP server");
1616 goto next_iteration;
1618 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1619 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1620 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1621 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1622 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1623 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1626 goto next_iteration;
1628 timeout.tv_sec = 60; // 60 second timeout i guess
1629 timeout.tv_usec = 0;
1631 FD_SET(sockfd, &fdset);
1632 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1634 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1637 goto next_iteration;
1640 recvbuf[numbytes] = '\0';
1641 if (strstr(recvbuf, "a1 OK") == NULL) {
1642 ERR("IMAP server login failed: %s", recvbuf);
1644 goto next_iteration;
1646 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1647 strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1);
1648 strncat(sendbuf, " (MESSAGES UNSEEN)\r\n",
1649 MAXDATASIZE - strlen(sendbuf) - 1);
1650 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1653 goto next_iteration;
1655 timeout.tv_sec = 60; // 60 second timeout i guess
1656 timeout.tv_usec = 0;
1658 FD_SET(sockfd, &fdset);
1659 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1661 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1664 goto next_iteration;
1667 recvbuf[numbytes] = '\0';
1668 if (strstr(recvbuf, "a2 OK") == NULL) {
1669 ERR("IMAP status failed: %s", recvbuf);
1671 goto next_iteration;
1673 // now we get the data
1674 reply = strstr(recvbuf, " (MESSAGES ");
1676 *strchr(reply, ')') = '\0';
1677 if (reply == NULL) {
1678 ERR("Error parsing IMAP response: %s", recvbuf);
1680 goto next_iteration;
1682 timed_thread_lock(mail->p_timed_thread);
1683 sscanf(reply, "MESSAGES %lu UNSEEN %lu", &mail->messages,
1685 timed_thread_unlock(mail->p_timed_thread);
1687 strncpy(sendbuf, "a3 logout\r\n", MAXDATASIZE);
1688 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1691 goto next_iteration;
1693 timeout.tv_sec = 60; // 60 second timeout i guess
1694 timeout.tv_usec = 0;
1696 FD_SET(sockfd, &fdset);
1697 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1699 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1702 goto next_iteration;
1705 recvbuf[numbytes] = '\0';
1706 if (strstr(recvbuf, "a3 OK") == NULL) {
1707 ERR("IMAP logout failed: %s", recvbuf);
1709 goto next_iteration;
1711 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen
1712 || (mail->messages > old_messages && mail->unseen > 0))) {
1714 if (system(mail->command) == -1) {
1719 old_unseen = mail->unseen;
1720 old_messages = mail->messages;
1722 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1723 /* if a valid socket, close it */
1726 if (timed_thread_test(mail->p_timed_thread)) {
1727 timed_thread_exit(mail->p_timed_thread);
1735 void *pop3_thread(void *arg)
1737 int sockfd, numbytes;
1738 char recvbuf[MAXDATASIZE];
1739 char sendbuf[MAXDATASIZE];
1742 unsigned int old_unseen = UINT_MAX;
1743 struct stat stat_buf;
1745 struct sockaddr_in their_addr; // connector's address information
1746 struct mail_s *mail = (struct mail_s *)arg;
1748 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1749 herror("gethostbyname");
1753 struct timeval timeout;
1758 ERR("Trying POP3 connection again for %s@%s (try %i/5)",
1759 mail->user, mail->host, fail + 1);
1761 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1764 goto next_iteration;
1768 their_addr.sin_family = AF_INET;
1769 // short, network byte order
1770 their_addr.sin_port = htons(mail->port);
1771 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1772 // zero the rest of the struct
1773 memset(&(their_addr.sin_zero), '\0', 8);
1775 if (connect(sockfd, (struct sockaddr *) &their_addr,
1776 sizeof(struct sockaddr)) == -1) {
1779 goto next_iteration;
1782 timeout.tv_sec = 60; // 60 second timeout i guess
1783 timeout.tv_usec = 0;
1785 FD_SET(sockfd, &fdset);
1786 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1788 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1791 goto next_iteration;
1794 ERR("POP3 connection failed: timeout\n");
1796 goto next_iteration;
1798 recvbuf[numbytes] = '\0';
1799 if (strstr(recvbuf, "+OK ") != recvbuf) {
1800 ERR("POP3 connection failed, probably not a POP3 server");
1802 goto next_iteration;
1804 strncpy(sendbuf, "USER ", MAXDATASIZE);
1805 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1806 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1807 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1808 perror("send USER");
1810 goto next_iteration;
1812 timeout.tv_sec = 60; // 60 second timeout i guess
1813 timeout.tv_usec = 0;
1815 FD_SET(sockfd, &fdset);
1816 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1818 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1819 perror("recv USER");
1821 goto next_iteration;
1824 recvbuf[numbytes] = '\0';
1825 if (strstr(recvbuf, "+OK ") == NULL) {
1826 ERR("POP3 server login failed: %s", recvbuf);
1828 goto next_iteration;
1830 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1831 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1832 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1833 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1834 perror("send PASS");
1836 goto next_iteration;
1838 timeout.tv_sec = 60; // 60 second timeout i guess
1839 timeout.tv_usec = 0;
1841 FD_SET(sockfd, &fdset);
1842 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1844 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1845 perror("recv PASS");
1847 goto next_iteration;
1850 recvbuf[numbytes] = '\0';
1851 if (strstr(recvbuf, "+OK ") == NULL) {
1852 ERR("POP3 server login failed: %s", recvbuf);
1854 goto next_iteration;
1856 strncpy(sendbuf, "STAT\r\n", MAXDATASIZE);
1857 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1858 perror("send STAT");
1860 goto next_iteration;
1862 timeout.tv_sec = 60; // 60 second timeout i guess
1863 timeout.tv_usec = 0;
1865 FD_SET(sockfd, &fdset);
1866 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1868 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1869 perror("recv STAT");
1871 goto next_iteration;
1874 recvbuf[numbytes] = '\0';
1875 if (strstr(recvbuf, "+OK ") == NULL) {
1876 ERR("POP3 status failed: %s", recvbuf);
1878 goto next_iteration;
1880 // now we get the data
1881 reply = recvbuf + 4;
1882 if (reply == NULL) {
1883 ERR("Error parsing POP3 response: %s", recvbuf);
1885 goto next_iteration;
1887 timed_thread_lock(mail->p_timed_thread);
1888 sscanf(reply, "%lu %lu", &mail->unseen, &mail->used);
1889 timed_thread_unlock(mail->p_timed_thread);
1891 strncpy(sendbuf, "QUIT\r\n", MAXDATASIZE);
1892 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1893 perror("send QUIT");
1895 goto next_iteration;
1897 timeout.tv_sec = 60; // 60 second timeout i guess
1898 timeout.tv_usec = 0;
1900 FD_SET(sockfd, &fdset);
1901 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1903 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1904 perror("recv QUIT");
1906 goto next_iteration;
1909 recvbuf[numbytes] = '\0';
1910 if (strstr(recvbuf, "+OK") == NULL) {
1911 ERR("POP3 logout failed: %s", recvbuf);
1913 goto next_iteration;
1915 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) {
1917 if (system(mail->command) == -1) {
1922 old_unseen = mail->unseen;
1924 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1925 /* if a valid socket, close it */
1928 if (timed_thread_test(mail->p_timed_thread)) {
1929 timed_thread_exit(mail->p_timed_thread);
1937 void *threaded_exec(void *) __attribute__((noreturn));
1939 void *threaded_exec(void *arg)
1944 struct text_object *obj = (struct text_object *)arg;
1946 p2 = obj->data.texeci.buffer;
1947 fp = popen(obj->data.texeci.cmd, "r");
1949 timed_thread_lock(obj->data.texeci.p_timed_thread);
1950 n2 = fread(p2, 1, text_buffer_size, fp);
1954 if (n2 && p2[n2 - 1] == '\n') {
1958 if (*p2 == '\001') {
1963 timed_thread_unlock(obj->data.texeci.p_timed_thread);
1964 if (timed_thread_test(obj->data.texeci.p_timed_thread)) {
1965 timed_thread_exit(obj->data.texeci.p_timed_thread);
1971 static struct text_object *new_text_object_internal(void)
1973 struct text_object *obj = malloc(sizeof(struct text_object));
1974 memset(obj, 0, sizeof(struct text_object));
1978 static void free_text_objects(unsigned int count, struct text_object *objs)
1982 for (i = 0; i < count; i++) {
1983 switch (objs[i].type) {
1987 close(objs[i].data.i);
1992 close(objs[i].data.sysfs.fd);
1994 #endif /* !__OpenBSD__ */
1997 free(objs[i].data.s);
2000 free(objs[i].data.tztime.tz);
2001 free(objs[i].data.tztime.fmt);
2004 free(objs[i].data.mboxscan.args);
2005 free(objs[i].data.mboxscan.output);
2009 free(objs[i].data.local_mail.box);
2014 case OBJ_imap_unseen:
2015 if (!objs[i].global_mode) {
2016 free(objs[i].data.mail);
2019 case OBJ_imap_messages:
2020 if (!objs[i].global_mode) {
2021 free(objs[i].data.mail);
2027 case OBJ_pop3_unseen:
2028 if (!objs[i].global_mode) {
2029 free(objs[i].data.mail);
2033 if (!objs[i].global_mode) {
2034 free(objs[i].data.mail);
2038 case OBJ_if_existing:
2039 case OBJ_if_mounted:
2040 case OBJ_if_running:
2041 free(objs[i].data.ifblock.s);
2042 free(objs[i].data.ifblock.str);
2045 free(objs[i].data.tail.logfile);
2046 free(objs[i].data.tail.buffer);
2055 free(objs[i].data.s);
2058 case OBJ_iconv_start:
2063 case OBJ_disk_protect:
2064 free(objs[i].data.s);
2067 free(objs[i].data.ifblock.s);
2068 free(objs[i].data.ifblock.str);
2071 free(objs[i].data.ifblock.s);
2072 free(objs[i].data.ifblock.str);
2075 if (info.gw_info.iface) {
2076 free(info.gw_info.iface);
2077 info.gw_info.iface = 0;
2079 if (info.gw_info.ip) {
2080 free(info.gw_info.ip);
2081 info.gw_info.ip = 0;
2084 case OBJ_ioscheduler:
2086 free(objs[i].data.s);
2090 case OBJ_xmms2_artist:
2091 if (info.xmms2.artist) {
2092 free(info.xmms2.artist);
2093 info.xmms2.artist = 0;
2096 case OBJ_xmms2_album:
2097 if (info.xmms2.album) {
2098 free(info.xmms2.album);
2099 info.xmms2.album = 0;
2102 case OBJ_xmms2_title:
2103 if (info.xmms2.title) {
2104 free(info.xmms2.title);
2105 info.xmms2.title = 0;
2108 case OBJ_xmms2_genre:
2109 if (info.xmms2.genre) {
2110 free(info.xmms2.genre);
2111 info.xmms2.genre = 0;
2114 case OBJ_xmms2_comment:
2115 if (info.xmms2.comment) {
2116 free(info.xmms2.comment);
2117 info.xmms2.comment = 0;
2121 if (info.xmms2.url) {
2122 free(info.xmms2.url);
2126 case OBJ_xmms2_date:
2127 if (info.xmms2.date) {
2128 free(info.xmms2.date);
2129 info.xmms2.date = 0;
2132 case OBJ_xmms2_status:
2133 if (info.xmms2.status) {
2134 free(info.xmms2.status);
2135 info.xmms2.status = 0;
2138 case OBJ_xmms2_playlist:
2139 if (info.xmms2.playlist) {
2140 free(info.xmms2.playlist);
2141 info.xmms2.playlist = 0;
2144 case OBJ_xmms2_smart:
2145 if (info.xmms2.artist) {
2146 free(info.xmms2.artist);
2147 info.xmms2.artist = 0;
2149 if (info.xmms2.title) {
2150 free(info.xmms2.title);
2151 info.xmms2.title = 0;
2153 if (info.xmms2.url) {
2154 free(info.xmms2.url);
2160 case OBJ_bmpx_title:
2161 case OBJ_bmpx_artist:
2162 case OBJ_bmpx_album:
2163 case OBJ_bmpx_track:
2165 case OBJ_bmpx_bitrate:
2170 free(objs[i].data.rss.uri);
2171 free(objs[i].data.rss.action);
2178 free(objs[i].data.s);
2180 case OBJ_battery_time:
2181 free(objs[i].data.s);
2183 #endif /* !__OpenBSD__ */
2187 case OBJ_execigraph:
2188 free(objs[i].data.execi.cmd);
2189 free(objs[i].data.execi.buffer);
2192 free(objs[i].data.texeci.cmd);
2193 free(objs[i].data.texeci.buffer);
2195 case OBJ_nameserver:
2200 if (info.first_process) {
2201 free_all_processes();
2202 info.first_process = NULL;
2207 free(objs[i].data.hddtemp.dev);
2208 free(objs[i].data.hddtemp.addr);
2211 case OBJ_entropy_avail:
2212 case OBJ_entropy_poolsize:
2213 case OBJ_entropy_bar:
2215 case OBJ_user_names:
2216 if (info.users.names) {
2217 free(info.users.names);
2218 info.users.names = 0;
2221 case OBJ_user_terms:
2222 if (info.users.terms) {
2223 free(info.users.terms);
2224 info.users.terms = 0;
2227 case OBJ_user_times:
2228 if (info.users.times) {
2229 free(info.users.times);
2230 info.users.times = 0;
2235 case OBJ_smapi_bat_perc:
2236 free(objs[i].data.s);
2238 case OBJ_if_smapi_bat_installed:
2239 free(objs[i].data.ifblock.s);
2240 free(objs[i].data.ifblock.str);
2245 case OBJ_mpd_artist:
2247 case OBJ_mpd_random:
2248 case OBJ_mpd_repeat:
2250 case OBJ_mpd_bitrate:
2251 case OBJ_mpd_status:
2254 case OBJ_mpd_password:
2256 case OBJ_mpd_elapsed:
2257 case OBJ_mpd_length:
2261 case OBJ_mpd_percent:
2263 free_mpd_vars(&info);
2269 /* text_objects = NULL;
2270 text_object_count = 0; */
2273 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2278 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2279 *a = mixer_init(buf1);
2280 scan_bar(arg + n, w, h);
2282 *a = mixer_init(NULL);
2283 scan_bar(arg, w, h);
2287 /* strip a leading /dev/ if any */
2288 #define DEV_NAME(x) strncmp(x, "/dev/", 5) ? x : x + 5
2290 /* construct_text_object() creates a new text_object */
2291 static struct text_object *construct_text_object(const char *s,
2292 const char *arg, unsigned int object_count,
2293 struct text_object *text_objects, long line)
2295 // struct text_object *obj = new_text_object();
2296 struct text_object *obj = new_text_object_internal();
2300 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
2301 obj->type = OBJ_##a; need_mask |= (1 << n); {
2302 #define END } } else
2306 obj->type = OBJ_color;
2307 obj->data.l = get_x11_color(s);
2311 OBJ(freq, INFO_FREQ)
2314 obj->data.i = open_acpi_temperature(arg);
2315 END OBJ(acpitempf, 0)
2316 obj->data.i = open_acpi_temperature(arg);
2317 END OBJ(acpiacadapter, 0)
2318 END OBJ(freq, INFO_FREQ)
2319 #endif /* !__OpenBSD__ */
2321 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2322 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2323 obj->data.cpu_index = 1;
2324 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
2325 "Displaying the clock for CPU 1."); */
2327 obj->data.cpu_index = atoi(&arg[0]);
2330 END OBJ(freq_g, INFO_FREQ)
2332 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2333 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2334 obj->data.cpu_index = 1;
2335 /* ERR("freq_g: Invalid CPU number or you don't have that many "
2336 "CPUs! Displaying the clock for CPU 1."); */
2338 obj->data.cpu_index = atoi(&arg[0]);
2341 #if defined(__linux__)
2342 END OBJ(voltage_mv, 0)
2344 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2345 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2346 obj->data.cpu_index = 1;
2347 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
2348 "CPUs! Displaying voltage for CPU 1."); */
2350 obj->data.cpu_index = atoi(&arg[0]);
2353 END OBJ(voltage_v, 0)
2355 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2356 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2357 obj->data.cpu_index = 1;
2358 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
2359 "CPUs! Displaying voltage for CPU 1."); */
2361 obj->data.cpu_index = atoi(&arg[0]);
2366 END OBJ(wireless_essid, INFO_NET)
2368 obj->data.net = get_net_stat(arg);
2370 CRIT_ERR("wireless_essid: needs an argument");
2372 END OBJ(wireless_mode, INFO_NET)
2374 obj->data.net = get_net_stat(arg);
2376 CRIT_ERR("wireless_mode: needs an argument");
2378 END OBJ(wireless_bitrate, INFO_NET)
2380 obj->data.net = get_net_stat(arg);
2382 CRIT_ERR("wireless_bitrate: needs an argument");
2384 END OBJ(wireless_ap, INFO_NET)
2386 obj->data.net = get_net_stat(arg);
2388 CRIT_ERR("wireless_ap: needs an argument");
2390 END OBJ(wireless_link_qual, INFO_NET)
2392 obj->data.net = get_net_stat(arg);
2394 CRIT_ERR("wireless_link_qual: needs an argument");
2396 END OBJ(wireless_link_qual_max, INFO_NET)
2398 obj->data.net = get_net_stat(arg);
2400 CRIT_ERR("wireless_link_qual_max: needs an argument");
2402 END OBJ(wireless_link_qual_perc, INFO_NET)
2404 obj->data.net = get_net_stat(arg);
2406 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2408 END OBJ(wireless_link_bar, INFO_NET)
2410 arg = scan_bar(arg, &obj->a, &obj->b);
2411 obj->data.net = get_net_stat(arg);
2413 CRIT_ERR("wireless_link_bar: needs an argument");
2415 #endif /* HAVE_IWLIB */
2417 #endif /* __linux__ */
2418 END OBJ(freq_dyn, 0)
2419 END OBJ(freq_dyn_g, 0)
2427 sscanf(arg, "%63s", bat);
2429 strcpy(bat, "BAT0");
2431 obj->data.s = strndup(bat, text_buffer_size);
2432 END OBJ(battery_time, 0)
2436 sscanf(arg, "%63s", bat);
2438 strcpy(bat, "BAT0");
2440 obj->data.s = strndup(bat, text_buffer_size);
2441 END OBJ(battery_percent, 0)
2445 sscanf(arg, "%63s", bat);
2447 strcpy(bat, "BAT0");
2449 obj->data.s = strndup(bat, text_buffer_size);
2450 END OBJ(battery_bar, 0)
2454 arg = scan_bar(arg, &obj->a, &obj->b);
2455 sscanf(arg, "%63s", bat);
2457 strcpy(bat, "BAT0");
2459 obj->data.s = strndup(bat, text_buffer_size);
2460 #endif /* !__OpenBSD__ */
2462 #if defined(__linux__)
2463 END OBJ(disk_protect, 0)
2465 obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
2467 CRIT_ERR("disk_protect needs an argument");
2468 END OBJ(i8k_version, INFO_I8K)
2469 END OBJ(i8k_bios, INFO_I8K)
2470 END OBJ(i8k_serial, INFO_I8K)
2471 END OBJ(i8k_cpu_temp, INFO_I8K)
2472 END OBJ(i8k_cpu_tempf, INFO_I8K)
2473 END OBJ(i8k_left_fan_status, INFO_I8K)
2474 END OBJ(i8k_right_fan_status, INFO_I8K)
2475 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2476 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2477 END OBJ(i8k_ac_status, INFO_I8K)
2478 END OBJ(i8k_buttons_status, INFO_I8K)
2480 END OBJ(ibm_temps, 0)
2482 CRIT_ERR("ibm_temps: needs an argument");
2484 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
2485 obj->data.sensor = 0;
2486 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
2487 "Using 0 (CPU temp sensor).");
2489 obj->data.sensor = atoi(&arg[0]);
2490 END OBJ(ibm_volume, 0)
2491 END OBJ(ibm_brightness, 0)
2493 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2494 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2497 ERR("if_up needs an argument");
2498 obj->data.ifblock.s = 0;
2500 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2501 blockstart[blockdepth] = object_count;
2502 obj->data.ifblock.pos = object_count + 2;
2505 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2506 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2508 blockstart[blockdepth] = object_count;
2509 obj->data.ifblock.pos = object_count + 2;
2511 END OBJ(ioscheduler, 0)
2513 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
2516 obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
2517 END OBJ(laptop_mode, 0)
2518 END OBJ(pb_battery, 0)
2519 if (arg && strcmp(arg, "status") == 0) {
2520 obj->data.i = PB_BATT_STATUS;
2521 } else if (arg && strcmp(arg, "percent") == 0) {
2522 obj->data.i = PB_BATT_PERCENT;
2523 } else if (arg && strcmp(arg, "time") == 0) {
2524 obj->data.i = PB_BATT_TIME;
2526 ERR("pb_battery: needs one argument: status, percent or time");
2531 #endif /* __linux__ */
2532 #if defined(__OpenBSD__)
2533 END OBJ(obsd_sensors_temp, 0)
2535 CRIT_ERR("obsd_sensors_temp: needs an argument");
2537 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2538 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2539 obj->data.sensor = 0;
2540 ERR("Invalid temperature sensor number!");
2542 obj->data.sensor = atoi(&arg[0]);
2543 END OBJ(obsd_sensors_fan, 0)
2545 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
2548 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2549 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2550 obj->data.sensor = 0;
2551 ERR("Invalid fan sensor number!");
2553 obj->data.sensor = atoi(&arg[0]);
2554 END OBJ(obsd_sensors_volt, 0)
2556 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
2559 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2560 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2561 obj->data.sensor = 0;
2562 ERR("Invalid voltage sensor number!");
2564 obj->data.sensor = atoi(&arg[0]);
2565 END OBJ(obsd_vendor, 0)
2566 END OBJ(obsd_product, 0)
2567 #endif /* __OpenBSD__ */
2568 END OBJ(buffers, INFO_BUFFERS)
2569 END OBJ(cached, INFO_BUFFERS)
2570 END OBJ(cpu, INFO_CPU)
2572 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2573 obj->data.cpu_index = atoi(&arg[3]);
2576 obj->data.cpu_index = 0;
2579 obj->data.cpu_index = 0;
2581 END OBJ(cpubar, INFO_CPU)
2583 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2584 obj->data.cpu_index = atoi(&arg[3]);
2587 obj->data.cpu_index = 0;
2589 scan_bar(arg, &obj->a, &obj->b);
2591 scan_bar(arg, &obj->a, &obj->b);
2592 obj->data.cpu_index = 0;
2594 END OBJ(cpugraph, INFO_CPU)
2595 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2599 if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
2600 obj->data.cpu_index = atoi(&buf[3]);
2602 obj->data.cpu_index = 0;
2606 END OBJ(diskio, INFO_DISKIO)
2608 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2610 obj->data.diskio = NULL;
2612 END OBJ(diskio_read, INFO_DISKIO)
2614 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2616 obj->data.diskio = NULL;
2618 END OBJ(diskio_write, INFO_DISKIO)
2620 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2622 obj->data.diskio = NULL;
2624 END OBJ(diskiograph, INFO_DISKIO)
2625 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2629 obj->data.diskio = prepare_diskio_stat(buf);
2632 obj->data.diskio = NULL;
2634 END OBJ(diskiograph_read, INFO_DISKIO)
2635 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2639 obj->data.diskio = prepare_diskio_stat(buf);
2642 obj->data.diskio = NULL;
2644 END OBJ(diskiograph_write, INFO_DISKIO)
2645 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2649 obj->data.diskio = prepare_diskio_stat(buf);
2652 obj->data.diskio = NULL;
2656 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2659 obj->data.l = color0;
2661 obj->data.l = color1;
2663 obj->data.l = color2;
2665 obj->data.l = color3;
2667 obj->data.l = color4;
2669 obj->data.l = color5;
2671 obj->data.l = color6;
2673 obj->data.l = color7;
2675 obj->data.l = color8;
2677 obj->data.l = color9;
2679 obj->data.s = scan_font(arg);
2680 END OBJ(conky_version, 0)
2681 END OBJ(conky_build_date, 0)
2682 END OBJ(conky_build_arch, 0)
2683 END OBJ(downspeed, INFO_NET)
2685 obj->data.net = get_net_stat(arg);
2687 CRIT_ERR("downspeed needs argument");
2689 END OBJ(downspeedf, INFO_NET)
2691 obj->data.net = get_net_stat(arg);
2693 CRIT_ERR("downspeedf needs argument");
2695 END OBJ(downspeedgraph, INFO_NET)
2696 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2700 obj->data.net = get_net_stat(buf);
2705 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos =
2707 blockstart[blockdepth - 1] = object_count;
2708 obj->data.ifblock.pos = object_count + 2;
2710 ERR("$else: no matching $if_*");
2715 text_objects[blockstart[blockdepth]].data.ifblock.pos =
2718 ERR("$endif: no matching $if_*");
2721 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2724 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2726 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2728 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2729 END OBJ(execgraph, 0)
2730 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2731 END OBJ(execibar, 0)
2734 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2737 ERR("${execibar <interval> command}");
2738 obj->type = OBJ_text;
2739 snprintf(buf, 256, "${%s}", s);
2740 obj->data.s = strndup(buf, text_buffer_size);
2742 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2744 END OBJ(execigraph, 0)
2747 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2750 ERR("${execigraph <interval> command}");
2751 obj->type = OBJ_text;
2752 snprintf(buf, 256, "${%s}", s);
2753 obj->data.s = strndup(buf, text_buffer_size);
2755 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2760 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2763 ERR("${execi <interval> command}");
2764 obj->type = OBJ_text;
2765 snprintf(buf, 256, "${%s}", s);
2766 obj->data.s = strndup(buf, text_buffer_size);
2768 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2769 obj->data.execi.buffer = malloc(text_buffer_size);
2774 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2777 ERR("${execi <interval> command}");
2778 obj->type = OBJ_text;
2779 snprintf(buf, 256, "${%s}", s);
2780 obj->data.s = strndup(buf, text_buffer_size);
2782 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2783 obj->data.execi.buffer = malloc(text_buffer_size);
2788 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2791 ERR("${texeci <interval> command}");
2792 obj->type = OBJ_text;
2793 snprintf(buf, 256, "${%s}", s);
2794 obj->data.s = strndup(buf, text_buffer_size);
2796 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
2797 obj->data.texeci.buffer = malloc(text_buffer_size);
2799 obj->data.texeci.p_timed_thread = NULL;
2800 END OBJ(pre_exec, 0)
2801 obj->type = OBJ_text;
2803 FILE *fp = popen(arg, "r");
2807 n = fread(buf, 1, 2048, fp);
2810 if (n && buf[n - 1] == '\n') {
2816 obj->data.s = strndup(buf, text_buffer_size);
2818 obj->data.s = strndup("", text_buffer_size);
2821 END OBJ(fs_bar, INFO_FS)
2822 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2824 while (isspace(*arg)) {
2833 obj->data.fsbar.fs = prepare_fs_stat(arg);
2834 END OBJ(fs_bar_free, INFO_FS)
2835 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2837 while (isspace(*arg)) {
2847 obj->data.fsbar.fs = prepare_fs_stat(arg);
2848 END OBJ(fs_free, INFO_FS)
2852 obj->data.fs = prepare_fs_stat(arg);
2853 END OBJ(fs_used_perc, INFO_FS)
2857 obj->data.fs = prepare_fs_stat(arg);
2858 END OBJ(fs_free_perc, INFO_FS)
2862 obj->data.fs = prepare_fs_stat(arg);
2863 END OBJ(fs_size, INFO_FS)
2867 obj->data.fs = prepare_fs_stat(arg);
2868 END OBJ(fs_type, INFO_FS)
2872 obj->data.fs = prepare_fs_stat(arg);
2873 END OBJ(fs_used, INFO_FS)
2877 obj->data.fs = prepare_fs_stat(arg);
2879 obj->data.i = arg ? atoi(arg) : 1;
2880 END OBJ(nameserver, INFO_DNS)
2881 obj->data.i = arg ? atoi(arg) : 0;
2883 obj->data.i = arg ? atoi(arg) : 1;
2885 obj->data.i = arg ? atoi(arg) : 1;
2889 ERR("goto needs arguments");
2890 obj->type = OBJ_text;
2891 obj->data.s = strndup("${goto}", text_buffer_size);
2895 obj->data.i = atoi(arg);
2901 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2902 sscanf(arg, "%d", &b);
2908 obj->data.pair.a = a;
2909 obj->data.pair.b = b;
2912 END OBJ(i2c, INFO_SYSFS)
2913 char buf1[64], buf2[64];
2917 ERR("i2c needs arguments");
2918 obj->type = OBJ_text;
2919 // obj->data.s = strndup("${i2c}", text_buffer_size);
2923 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2924 /* if scanf couldn't read three values, read type and num and use
2926 sscanf(arg, "%63s %d", buf2, &n);
2927 obj->data.sysfs.fd = open_i2c_sensor(0, buf2, n,
2928 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2929 strncpy(obj->data.sysfs.type, buf2, 63);
2931 obj->data.sysfs.fd = open_i2c_sensor(buf1, buf2, n,
2932 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2933 strncpy(obj->data.sysfs.type, buf2, 63);
2936 END OBJ(platform, INFO_SYSFS)
2937 char buf1[64], buf2[64];
2941 ERR("platform needs arguments");
2942 obj->type = OBJ_text;
2946 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2947 /* if scanf couldn't read three values, read type and num and use
2949 sscanf(arg, "%63s %d", buf2, &n);
2950 obj->data.sysfs.fd = open_platform_sensor(0, buf2, n,
2951 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2952 strncpy(obj->data.sysfs.type, buf2, 63);
2954 obj->data.sysfs.fd = open_platform_sensor(buf1, buf2, n,
2955 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2956 strncpy(obj->data.sysfs.type, buf2, 63);
2959 END OBJ(hwmon, INFO_SYSFS)
2960 char buf1[64], buf2[64];
2964 ERR("hwmon needs argumanets");
2965 obj->type = OBJ_text;
2969 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2970 /* if scanf couldn't read three values, read type and num and use
2972 sscanf(arg, "%63s %d", buf2, &n);
2973 obj->data.sysfs.fd = open_hwmon_sensor(0, buf2, n,
2974 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2975 strncpy(obj->data.sysfs.type, buf2, 63);
2977 obj->data.sysfs.fd = open_hwmon_sensor(buf1, buf2, n,
2978 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2979 strncpy(obj->data.sysfs.type, buf2, 63);
2981 #endif /* !__OpenBSD__ */
2983 END OBJ(top, INFO_TOP)
2988 ERR("top needs arguments");
2989 obj->type = OBJ_text;
2990 // obj->data.s = strndup("${top}", text_buffer_size);
2993 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2994 if (strcmp(buf, "name") == 0) {
2995 obj->data.top.type = TOP_NAME;
2996 } else if (strcmp(buf, "cpu") == 0) {
2997 obj->data.top.type = TOP_CPU;
2998 } else if (strcmp(buf, "pid") == 0) {
2999 obj->data.top.type = TOP_PID;
3000 } else if (strcmp(buf, "mem") == 0) {
3001 obj->data.top.type = TOP_MEM;
3002 } else if (strcmp(buf, "time") == 0) {
3003 obj->data.top.type = TOP_TIME;
3004 } else if (strcmp(buf, "mem_res") == 0) {
3005 obj->data.top.type = TOP_MEM_RES;
3006 } else if (strcmp(buf, "mem_vsize") == 0) {
3007 obj->data.top.type = TOP_MEM_VSIZE;
3009 ERR("invalid arg for top");
3012 if (n < 1 || n > 10) {
3013 CRIT_ERR("invalid arg for top");
3016 obj->data.top.num = n - 1;
3020 ERR("invalid args given for top");
3023 END OBJ(top_mem, INFO_TOP)
3028 ERR("top_mem needs arguments");
3029 obj->type = OBJ_text;
3030 obj->data.s = strndup("${top_mem}", text_buffer_size);
3033 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
3034 if (strcmp(buf, "name") == 0) {
3035 obj->data.top.type = TOP_NAME;
3036 } else if (strcmp(buf, "cpu") == 0) {
3037 obj->data.top.type = TOP_CPU;
3038 } else if (strcmp(buf, "pid") == 0) {
3039 obj->data.top.type = TOP_PID;
3040 } else if (strcmp(buf, "mem") == 0) {
3041 obj->data.top.type = TOP_MEM;
3042 } else if (strcmp(buf, "time") == 0) {
3043 obj->data.top.type = TOP_TIME;
3044 } else if (strcmp(buf, "mem_res") == 0) {
3045 obj->data.top.type = TOP_MEM_RES;
3046 } else if (strcmp(buf, "mem_vsize") == 0) {
3047 obj->data.top.type = TOP_MEM_VSIZE;
3049 ERR("invalid arg for top");
3052 if (n < 1 || n > 10) {
3053 CRIT_ERR("invalid arg for top");
3056 obj->data.top.num = n - 1;
3060 ERR("invalid args given for top");
3063 END OBJ(addr, INFO_NET)
3065 obj->data.net = get_net_stat(arg);
3067 CRIT_ERR("addr needs argument");
3069 #if defined(__linux__)
3070 END OBJ(addrs, INFO_NET)
3072 obj->data.net = get_net_stat(arg);
3074 CRIT_ERR("addrs needs argument");
3076 #endif /* __linux__ */
3083 ERR("tail needs arguments");
3084 obj->type = OBJ_text;
3085 obj->data.s = strndup("${tail}", text_buffer_size);
3088 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3089 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3090 CRIT_ERR("invalid arg for tail, number of lines must be "
3091 "between 1 and %i", MAX_TAIL_LINES);
3097 obj->data.tail.fd = -1;
3099 if (stat(buf, &st) == 0) {
3100 if (S_ISFIFO(st.st_mode)) {
3101 fd = open(buf, O_RDONLY | O_NONBLOCK);
3104 CRIT_ERR("tail logfile does not exist, or you do "
3105 "not have correct permissions");
3108 obj->data.tail.fd = fd;
3110 fp = fopen(buf, "r");
3114 if (fp || obj->data.tail.fd != -1) {
3115 obj->data.tail.logfile = malloc(text_buffer_size);
3116 strcpy(obj->data.tail.logfile, buf);
3117 obj->data.tail.wantedlines = n1;
3118 obj->data.tail.interval = update_interval * 2;
3120 if (obj->data.tail.fd == -1) {
3125 CRIT_ERR("tail logfile does not exist, or you do not have "
3126 "correct permissions");
3129 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3130 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3131 CRIT_ERR("invalid arg for tail, number of lines must be "
3132 "between 1 and %i", MAX_TAIL_LINES);
3134 } else if (n2 < 1 || n2 < update_interval) {
3135 CRIT_ERR("invalid arg for tail, interval must be greater than "
3136 "0 and Conky's interval");
3142 obj->data.tail.fd = -1;
3144 if (stat(buf, &st) == 0) {
3145 if (S_ISFIFO(st.st_mode)) {
3146 fd = open(buf, O_RDONLY | O_NONBLOCK);
3149 CRIT_ERR("tail logfile does not exist, or you do "
3150 "not have correct permissions");
3153 obj->data.tail.fd = fd;
3155 fp = fopen(buf, "r");
3159 if (fp || obj->data.tail.fd != -1) {
3160 obj->data.tail.logfile = malloc(text_buffer_size);
3161 strcpy(obj->data.tail.logfile, buf);
3162 obj->data.tail.wantedlines = n1;
3163 obj->data.tail.interval = n2;
3165 if (obj->data.tail.fd == -1) {
3170 CRIT_ERR("tail logfile does not exist, or you do not have "
3171 "correct permissions");
3175 ERR("invalid args given for tail");
3178 /* asumming all else worked */
3179 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3185 ERR("head needs arguments");
3186 obj->type = OBJ_text;
3187 obj->data.s = strndup("${head}", text_buffer_size);
3190 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3191 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3192 CRIT_ERR("invalid arg for head, number of lines must be "
3193 "between 1 and %i", MAX_TAIL_LINES);
3198 fp = fopen(buf, "r");
3200 obj->data.tail.logfile = malloc(text_buffer_size);
3201 strcpy(obj->data.tail.logfile, buf);
3202 obj->data.tail.wantedlines = n1;
3203 obj->data.tail.interval = update_interval * 2;
3207 CRIT_ERR("head logfile does not exist, or you do not have "
3208 "correct permissions");
3211 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3212 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3213 CRIT_ERR("invalid arg for head, number of lines must be "
3214 "between 1 and %i", MAX_TAIL_LINES);
3216 } else if (n2 < 1 || n2 < update_interval) {
3217 CRIT_ERR("invalid arg for head, interval must be greater than "
3218 "0 and Conky's interval");
3223 fp = fopen(buf, "r");
3225 obj->data.tail.logfile = malloc(text_buffer_size);
3226 strcpy(obj->data.tail.logfile, buf);
3227 obj->data.tail.wantedlines = n1;
3228 obj->data.tail.interval = n2;
3232 CRIT_ERR("head logfile does not exist, or you do not have "
3233 "correct permissions");
3237 ERR("invalid args given for head");
3240 /* asumming all else worked */
3241 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3242 END OBJ(loadavg, INFO_LOADAVG)
3243 int a = 1, b = 2, c = 3, r = 3;
3246 r = sscanf(arg, "%d %d %d", &a, &b, &c);
3247 if (r >= 3 && (c < 1 || c > 3)) {
3250 if (r >= 2 && (b < 1 || b > 3)) {
3253 if (r >= 1 && (a < 1 || a > 3)) {
3257 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
3258 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
3259 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
3260 END OBJ(if_empty, 0)
3261 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3262 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3265 ERR("if_empty needs an argument");
3266 obj->data.ifblock.s = 0;
3268 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3270 blockstart[blockdepth] = object_count;
3271 obj->data.ifblock.pos = object_count + 2;
3273 END OBJ(if_existing, 0)
3274 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3275 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3278 ERR("if_existing needs an argument or two");
3279 obj->data.ifblock.s = NULL;
3280 obj->data.ifblock.str = NULL;
3282 char buf1[256], buf2[256];
3283 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3286 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
3287 obj->data.ifblock.str = NULL;
3289 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
3290 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
3293 blockstart[blockdepth] = object_count;
3294 obj->data.ifblock.pos = object_count + 2;
3296 END OBJ(if_mounted, 0)
3297 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3298 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3301 ERR("if_mounted needs an argument");
3302 obj->data.ifblock.s = 0;
3304 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3306 blockstart[blockdepth] = object_count;
3307 obj->data.ifblock.pos = object_count + 2;
3309 END OBJ(if_running, 0)
3310 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3311 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3316 snprintf(buf, 256, "pidof %s >/dev/null", arg);
3317 obj->data.ifblock.s = strndup(buf, text_buffer_size);
3319 ERR("if_running needs an argument");
3320 obj->data.ifblock.s = 0;
3322 blockstart[blockdepth] = object_count;
3323 obj->data.ifblock.pos = object_count + 2;
3329 char box[256], dst[256];
3333 /* Kapil: Changed from MAIL_FILE to
3334 current_mail_spool since the latter
3335 is a copy of the former if undefined
3336 but the latter should take precedence
3338 strncpy(box, current_mail_spool, sizeof(box));
3340 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3342 strncpy(box, arg, sizeof(box));
3346 variable_substitute(box, dst, sizeof(dst));
3347 obj->data.local_mail.box = strndup(dst, text_buffer_size);
3348 obj->data.local_mail.interval = n1;
3349 END OBJ(mboxscan, 0)
3350 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
3351 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
3352 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
3353 obj->data.mboxscan.output[0] = 1;
3354 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
3355 END OBJ(mem, INFO_MEM)
3356 END OBJ(memmax, INFO_MEM)
3357 END OBJ(memperc, INFO_MEM)
3358 END OBJ(membar, INFO_MEM)
3359 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3360 END OBJ(memgraph, INFO_MEM)
3361 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3367 END OBJ(mixer, INFO_MIXER)
3368 obj->data.l = mixer_init(arg);
3369 END OBJ(mixerl, INFO_MIXER)
3370 obj->data.l = mixer_init(arg);
3371 END OBJ(mixerr, INFO_MIXER)
3372 obj->data.l = mixer_init(arg);
3373 END OBJ(mixerbar, INFO_MIXER)
3374 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3375 &obj->data.mixerbar.h);
3376 END OBJ(mixerlbar, INFO_MIXER)
3377 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3378 &obj->data.mixerbar.h);
3379 END OBJ(mixerrbar, INFO_MIXER)
3380 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3381 &obj->data.mixerbar.h);
3382 END OBJ(new_mails, 0)
3384 char box[256], dst[256];
3388 /* Kapil: Changed from MAIL_FILE to
3389 current_mail_spool since the latter
3390 is a copy of the former if undefined
3391 but the latter should take precedence
3393 strncpy(box, current_mail_spool, sizeof(box));
3395 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3397 strncpy(box, arg, sizeof(box));
3401 variable_substitute(box, dst, sizeof(dst));
3402 obj->data.local_mail.box = strndup(dst, text_buffer_size);
3403 obj->data.local_mail.interval = n1;
3404 END OBJ(nodename, 0)
3405 END OBJ(processes, INFO_PROCS)
3406 END OBJ(running_processes, INFO_RUN_PROCS)
3407 END OBJ(shadecolor, 0)
3409 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
3411 END OBJ(outlinecolor, 0)
3413 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
3415 END OBJ(stippled_hr, 0)
3417 int a = stippled_borders, b = 1;
3420 if (sscanf(arg, "%d %d", &a, &b) != 2) {
3421 sscanf(arg, "%d", &b);
3427 obj->data.pair.a = a;
3428 obj->data.pair.b = b;
3430 END OBJ(swap, INFO_MEM)
3431 END OBJ(swapmax, INFO_MEM)
3432 END OBJ(swapperc, INFO_MEM)
3433 END OBJ(swapbar, INFO_MEM)
3434 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3437 END OBJ(temp1, INFO_SYSFS)
3438 obj->type = OBJ_i2c;
3439 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 1,
3440 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3441 END OBJ(temp2, INFO_SYSFS)
3442 obj->type = OBJ_i2c;
3443 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 2,
3444 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3447 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
3449 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
3451 char buf1[256], buf2[256], *fmt, *tz;
3455 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3465 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
3466 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
3468 END OBJ(iconv_start, 0)
3469 if (iconv_converting) {
3470 CRIT_ERR("You must stop your last iconv conversion before "
3471 "starting another");
3474 char iconv_from[CODEPAGE_LENGTH];
3475 char iconv_to[CODEPAGE_LENGTH];
3477 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3478 CRIT_ERR("Invalid arguments for iconv_start");
3482 new_iconv = iconv_open(iconv_to, iconv_from);
3483 if (new_iconv == (iconv_t) (-1)) {
3484 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3486 obj->a = register_iconv(&new_iconv);
3487 iconv_converting = 1;
3491 CRIT_ERR("Iconv requires arguments");
3493 END OBJ(iconv_stop, 0)
3494 iconv_converting = 0;
3497 END OBJ(totaldown, INFO_NET)
3499 obj->data.net = get_net_stat(arg);
3501 CRIT_ERR("totaldown needs argument");
3503 END OBJ(totalup, INFO_NET)
3504 obj->data.net = get_net_stat(arg);
3506 obj->data.net = get_net_stat(arg);
3508 CRIT_ERR("totalup needs argument");
3512 obj->data.i = arg ? atoi(arg) : 0;
3514 obj->data.i = arg ? atoi(arg) : 0;
3515 END OBJ(upspeed, INFO_NET)
3517 obj->data.net = get_net_stat(arg);
3519 CRIT_ERR("upspeed needs argument");
3521 END OBJ(upspeedf, INFO_NET)
3523 obj->data.net = get_net_stat(arg);
3525 CRIT_ERR("upspeedf needs argument");
3528 END OBJ(upspeedgraph, INFO_NET)
3529 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3533 obj->data.net = get_net_stat(buf);
3536 END OBJ(uptime_short, INFO_UPTIME)
3537 END OBJ(uptime, INFO_UPTIME)
3538 END OBJ(user_names, INFO_USERS)
3539 END OBJ(user_times, INFO_USERS)
3540 END OBJ(user_terms, INFO_USERS)
3541 END OBJ(user_number, INFO_USERS)
3542 END OBJ(gw_iface, INFO_GW)
3543 END OBJ(gw_ip, INFO_GW)
3544 END OBJ(if_gw, INFO_GW)
3546 END OBJ(adt746xcpu, 0)
3547 END OBJ(adt746xfan, 0)
3548 #endif /* !__OpenBSD__ */
3549 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
3550 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3551 END OBJ(apm_adapter, 0)
3552 END OBJ(apm_battery_life, 0)
3553 END OBJ(apm_battery_time, 0)
3554 #endif /* __FreeBSD__ */
3555 END OBJ(imap_unseen, 0)
3558 obj->data.mail = parse_mail_args(IMAP, arg);
3559 obj->global_mode = 0;
3561 obj->global_mode = 1;
3563 END OBJ(imap_messages, 0)
3566 obj->data.mail = parse_mail_args(IMAP, arg);
3567 obj->global_mode = 0;
3569 obj->global_mode = 1;
3571 END OBJ(pop3_unseen, 0)
3574 obj->data.mail = parse_mail_args(POP3, arg);
3575 obj->global_mode = 0;
3577 obj->global_mode = 1;
3579 END OBJ(pop3_used, 0)
3582 obj->data.mail = parse_mail_args(POP3, arg);
3583 obj->global_mode = 0;
3585 obj->global_mode = 1;
3590 obj->data.s = strndup(arg, text_buffer_size);
3592 ERR("smapi needs an argument");
3593 END OBJ(if_smapi_bat_installed, 0)
3594 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3595 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3598 ERR("if_smapi_bat_installed needs an argument");
3599 obj->data.ifblock.s = 0;
3601 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3602 blockstart[blockdepth] = object_count;
3603 obj->data.ifblock.pos = object_count + 2;
3605 END OBJ(smapi_bat_perc, 0)
3607 obj->data.s = strndup(arg, text_buffer_size);
3609 ERR("smapi_bat_perc needs an argument");
3610 END OBJ(smapi_bat_bar, 0)
3613 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
3614 ERR("first argument to smapi_bat_bar must be an integer value");
3618 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
3621 ERR("if_smapi_bat_bar needs an argument");
3624 END OBJ(mpd_artist, INFO_MPD)
3625 END OBJ(mpd_title, INFO_MPD)
3627 sscanf(arg, "%d", &info.mpd.max_title_len);
3628 if (info.mpd.max_title_len > 0) {
3629 info.mpd.max_title_len++;
3631 CRIT_ERR("mpd_title: invalid length argument");
3634 info.mpd.max_title_len = 0;
3636 END OBJ(mpd_random, INFO_MPD)
3637 END OBJ(mpd_repeat, INFO_MPD)
3638 END OBJ(mpd_elapsed, INFO_MPD)
3639 END OBJ(mpd_length, INFO_MPD)
3640 END OBJ(mpd_track, INFO_MPD)
3641 END OBJ(mpd_name, INFO_MPD)
3642 END OBJ(mpd_file, INFO_MPD)
3643 END OBJ(mpd_percent, INFO_MPD)
3644 END OBJ(mpd_album, INFO_MPD)
3645 END OBJ(mpd_vol, INFO_MPD)
3646 END OBJ(mpd_bitrate, INFO_MPD)
3647 END OBJ(mpd_status, INFO_MPD)
3648 END OBJ(mpd_bar, INFO_MPD)
3649 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3650 END OBJ(mpd_smart, INFO_MPD)
3653 END OBJ(xmms2_artist, INFO_XMMS2)
3654 END OBJ(xmms2_album, INFO_XMMS2)
3655 END OBJ(xmms2_title, INFO_XMMS2)
3656 END OBJ(xmms2_genre, INFO_XMMS2)
3657 END OBJ(xmms2_comment, INFO_XMMS2)
3658 END OBJ(xmms2_url, INFO_XMMS2)
3659 END OBJ(xmms2_tracknr, INFO_XMMS2)
3660 END OBJ(xmms2_bitrate, INFO_XMMS2)
3661 END OBJ(xmms2_date, INFO_XMMS2)
3662 END OBJ(xmms2_id, INFO_XMMS2)
3663 END OBJ(xmms2_duration, INFO_XMMS2)
3664 END OBJ(xmms2_elapsed, INFO_XMMS2)
3665 END OBJ(xmms2_size, INFO_XMMS2)
3666 END OBJ(xmms2_status, INFO_XMMS2)
3667 END OBJ(xmms2_percent, INFO_XMMS2)
3668 END OBJ(xmms2_bar, INFO_XMMS2)
3669 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3670 END OBJ(xmms2_smart, INFO_XMMS2)
3671 END OBJ(xmms2_playlist, INFO_XMMS2)
3672 END OBJ(xmms2_timesplayed, INFO_XMMS2)
3675 END OBJ(audacious_status, INFO_AUDACIOUS)
3676 END OBJ(audacious_title, INFO_AUDACIOUS)
3678 sscanf(arg, "%d", &info.audacious.max_title_len);
3679 if (info.audacious.max_title_len > 0) {
3680 info.audacious.max_title_len++;
3682 CRIT_ERR("audacious_title: invalid length argument");
3685 END OBJ(audacious_length, INFO_AUDACIOUS)
3686 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
3687 END OBJ(audacious_position, INFO_AUDACIOUS)
3688 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
3689 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
3690 END OBJ(audacious_frequency, INFO_AUDACIOUS)
3691 END OBJ(audacious_channels, INFO_AUDACIOUS)
3692 END OBJ(audacious_filename, INFO_AUDACIOUS)
3693 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
3694 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
3695 END OBJ(audacious_bar, INFO_AUDACIOUS)
3696 scan_bar(arg, &obj->a, &obj->b);
3699 END OBJ(bmpx_title, INFO_BMPX)
3700 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3701 END OBJ(bmpx_artist, INFO_BMPX)
3702 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3703 END OBJ(bmpx_album, INFO_BMPX)
3704 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3705 END OBJ(bmpx_track, INFO_BMPX)
3706 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3707 END OBJ(bmpx_uri, INFO_BMPX)
3708 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3709 END OBJ(bmpx_bitrate, INFO_BMPX)
3710 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3715 int argc, delay, act_par;
3716 char *uri = (char *) malloc(128 * sizeof(char));
3717 char *action = (char *) malloc(64 * sizeof(char));
3719 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action,
3721 obj->data.rss.uri = uri;
3722 obj->data.rss.delay = delay;
3723 obj->data.rss.action = action;
3724 obj->data.rss.act_par = act_par;
3728 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
3734 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3735 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3736 ERR("hddtemp needs arguments");
3737 obj->type = OBJ_text;
3738 obj->data.s = strndup("${hddtemp}", text_buffer_size);
3742 #ifdef TCP_PORT_MONITOR
3743 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3744 int argc, port_begin, port_end, item, connection_index;
3747 memset(itembuf, 0, sizeof(itembuf));
3748 connection_index = 0;
3749 /* massive argument checking */
3751 CRIT_ERR("tcp_portmon: needs arguments");
3753 argc = sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf,
3755 if ((argc != 3) && (argc != 4)) {
3756 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3758 if ((port_begin < 1) || (port_begin > 65535) || (port_end < 1)
3759 || (port_end > 65535)) {
3760 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3762 if (port_begin > port_end) {
3763 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3765 if (strncmp(itembuf, "count", 31) == 0) {
3767 } else if (strncmp(itembuf, "rip", 31) == 0) {
3769 } else if (strncmp(itembuf, "rhost", 31) == 0) {
3771 } else if (strncmp(itembuf, "rport", 31) == 0) {
3773 } else if (strncmp(itembuf, "rservice", 31) == 0) {
3774 item = REMOTESERVICE;
3775 } else if (strncmp(itembuf, "lip", 31) == 0) {
3777 } else if (strncmp(itembuf, "lhost", 31) == 0) {
3779 } else if (strncmp(itembuf, "lport", 31) == 0) {
3781 } else if (strncmp(itembuf, "lservice", 31) == 0) {
3782 item = LOCALSERVICE;
3784 CRIT_ERR("tcp_portmon: invalid item specified");
3786 if ((argc == 3) && (item != COUNT)) {
3787 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" "
3790 if ((argc == 4) && (connection_index < 0)) {
3791 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3793 /* ok, args looks good. save the text object data */
3794 obj->data.tcp_port_monitor.port_range_begin = (in_port_t) port_begin;
3795 obj->data.tcp_port_monitor.port_range_end = (in_port_t) port_end;
3796 obj->data.tcp_port_monitor.item = item;
3797 obj->data.tcp_port_monitor.connection_index = connection_index;
3799 /* if the port monitor collection hasn't been created,
3800 * we must create it */
3801 if (!info.p_tcp_port_monitor_collection) {
3802 info.p_tcp_port_monitor_collection =
3803 create_tcp_port_monitor_collection();
3804 if (!info.p_tcp_port_monitor_collection) {
3805 CRIT_ERR("tcp_portmon: unable to create port monitor "
3810 /* if a port monitor for this port does not exist,
3811 * create one and add it to the collection */
3812 if (find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
3813 port_begin, port_end) == NULL) {
3814 tcp_port_monitor_t *p_monitor = create_tcp_port_monitor(port_begin,
3815 port_end, &tcp_port_monitor_args);
3818 CRIT_ERR("tcp_portmon: unable to create port monitor");
3820 /* add the newly created monitor to the collection */
3821 if (insert_tcp_port_monitor_into_collection(
3822 info.p_tcp_port_monitor_collection, p_monitor) != 0) {
3823 CRIT_ERR("tcp_portmon: unable to add port monitor to "
3828 END OBJ(entropy_avail, INFO_ENTROPY)
3829 END OBJ(entropy_poolsize, INFO_ENTROPY)
3830 END OBJ(entropy_bar, INFO_ENTROPY)
3831 scan_bar(arg, &obj->a, &obj->b);
3835 ERR("unknown variable %s", s);
3836 obj->type = OBJ_text;
3837 snprintf(buf, 256, "${%s}", s);
3838 obj->data.s = strndup(buf, text_buffer_size);
3845 static struct text_object *create_plain_text(const char *s)
3847 struct text_object *obj;
3849 if (s == NULL || *s == '\0') {
3853 obj = new_text_object_internal();
3855 obj->type = OBJ_text;
3856 obj->data.s = strndup(s, text_buffer_size);
3860 static struct text_object_list *extract_variable_text_internal(const char *const_p)
3862 struct text_object_list *retval;
3863 struct text_object *obj;
3864 char *p, *s, *orig_p;
3867 p = strndup(const_p, max_user_text);
3870 retval = malloc(sizeof(struct text_object_list));
3871 memset(retval, 0, sizeof(struct text_object_list));
3872 retval->text_object_count = 0;
3882 obj = create_plain_text(s);
3884 // allocate memory for the object
3885 retval->text_objects = realloc(retval->text_objects,
3886 sizeof(struct text_object) *
3887 (retval->text_object_count + 1));
3888 // assign the new object to the end of the list.
3889 memcpy(&retval->text_objects[retval->text_object_count++], obj,
3890 sizeof(struct text_object));
3902 /* variable is either $foo or ${foo} */
3904 unsigned int brl = 1, brr = 0;
3908 while (*p && brl != brr) {
3923 while (*p && (isalnum((int) *p) || *p == '_')) {
3928 /* copy variable to buffer */
3929 len = (p - s > 255) ? 255 : (p - s);
3930 strncpy(buf, s, len);
3940 /* if variable wasn't found in environment, use some special */
3946 if (strchr(buf, ' ')) {
3947 arg = strchr(buf, ' ');
3950 while (isspace((int) *arg)) {
3958 /* lowercase variable name */
3961 *tmp_p = tolower(*tmp_p);
3965 // create new object
3966 obj = construct_text_object(buf, arg,
3967 retval->text_object_count, retval->text_objects, line);
3969 // allocate memory for the object
3970 retval->text_objects = realloc(retval->text_objects,
3971 sizeof(struct text_object) *
3972 (retval->text_object_count + 1));
3973 // assign the new object to the end of the list.
3975 &retval->text_objects[retval->text_object_count++],
3976 obj, sizeof(struct text_object));
3982 obj = create_plain_text("$");
3984 // allocate memory for the object
3985 retval->text_objects = realloc(retval->text_objects,
3986 sizeof(struct text_object) *
3987 (retval->text_object_count + 1));
3988 // assign the new object to the end of the list.
3989 memcpy(&retval->text_objects[retval->text_object_count++],
3990 obj, sizeof(struct text_object));
3997 obj = create_plain_text(s);
3999 // allocate memory for the object
4000 retval->text_objects = realloc(retval->text_objects,
4001 sizeof(struct text_object) * (retval->text_object_count + 1));
4002 // assign the new object to the end of the list.
4003 memcpy(&retval->text_objects[retval->text_object_count++], obj,
4004 sizeof(struct text_object));
4009 ERR("one or more $endif's are missing");
4016 static void extract_variable_text(const char *p)
4018 struct text_object_list *list;
4020 free_text_objects(global_text_object_count, global_text_objects);
4033 global_text_object_count = 0;
4034 global_text_objects = NULL;
4036 list = extract_variable_text_internal(p);
4037 global_text_objects = list->text_objects;
4038 global_text_object_count = list->text_object_count;
4043 struct text_object_list *parse_conky_vars(char *txt, char *p, struct information *cur)
4045 struct text_object_list *object_list =
4046 extract_variable_text_internal(txt);
4048 generate_text_internal(p, max_user_text, object_list->text_objects,
4049 object_list->text_object_count, cur);
4053 /* Allows reading from a FIFO (i.e., /dev/xconsole).
4054 * The file descriptor is set to non-blocking which makes this possible.
4056 * FIXME: Since lseek cannot seek a file descriptor long lines will break. */
4057 static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
4059 #define TAIL_PIPE_BUFSIZE 4096
4063 int fd = obj->data.tail.fd;
4066 char buf[TAIL_PIPE_BUFSIZE];
4067 ssize_t len = read(fd, buf, sizeof(buf));
4071 if (errno != EAGAIN) {
4072 strcpy(obj->data.tail.buffer, "Logfile Read Error");
4073 snprintf(dst, dst_size, "Logfile Read Error");
4077 } else if (len == 0) {
4078 strcpy(obj->data.tail.buffer, "Logfile Empty");
4079 snprintf(dst, dst_size, "Logfile Empty");
4083 for (line_len = 0, i = 0; i < len; i++) {
4087 if (buf[i] == '\n') {
4090 if (obj->data.tail.readlines > 0) {
4095 for (n = 0; obj->data.tail.buffer[n]; n++) {
4096 if (obj->data.tail.buffer[n] == '\n') {
4101 if (++olines < obj->data.tail.wantedlines) {
4107 p = obj->data.tail.buffer + first_line;
4108 pos = n - first_line;
4109 memmove(obj->data.tail.buffer,
4110 obj->data.tail.buffer + first_line, strlen(p));
4111 obj->data.tail.buffer[pos] = 0;
4117 p = buf + last_line;
4119 memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
4120 obj->data.tail.buffer[pos + line_len] = 0;
4123 obj->data.tail.readlines = lines;
4131 snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
4134 char *format_time(unsigned long timeval, const int width)
4137 unsigned long nt; // narrow time, for speed on 32-bit
4138 unsigned cc; // centiseconds
4139 unsigned nn; // multi-purpose whatever
4142 cc = nt % 100; // centiseconds past second
4143 nt /= 100; // total seconds
4144 nn = nt % 60; // seconds past the minute
4145 nt /= 60; // total minutes
4146 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
4148 return strndup(buf, text_buffer_size);
4150 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
4151 return strndup(buf, text_buffer_size);
4153 nn = nt % 60; // minutes past the hour
4154 nt /= 60; // total hours
4155 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
4156 return strndup(buf, text_buffer_size);
4158 nn = nt; // now also hours
4159 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
4160 return strndup(buf, text_buffer_size);
4162 nn /= 24; // now days
4163 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
4164 return strndup(buf, text_buffer_size);
4166 nn /= 7; // now weeks
4167 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
4168 return strndup(buf, text_buffer_size);
4170 // well shoot, this outta' fit...
4171 return strndup("<inf>", text_buffer_size);
4174 static void generate_text_internal(char *p, int p_max_size,
4175 struct text_object *objs, unsigned int object_count,
4176 struct information *cur)
4181 char buff_in[p_max_size];
4183 iconv_converting = 0;
4186 for (i = 0; i < object_count; i++) {
4187 struct text_object *obj = &objs[i];
4189 if (p_max_size < 1) {
4193 #define OBJ(a) break; case OBJ_##a:
4195 switch (obj->type) {
4197 ERR("not implemented obj type %d", obj->type);
4200 /* does anyone have decimals in acpi temperature? */
4201 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
4202 round_to_int(get_acpi_temperature(obj->data.i)));
4205 /* does anyone have decimals in acpi temperature? */
4206 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
4207 round_to_int((get_acpi_temperature(obj->data.i) + 40) *
4210 #endif /* !__OpenBSD__ */
4213 obj->a = get_freq(p, p_max_size, "%.0f", 1,
4214 obj->data.cpu_index);
4220 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
4221 obj->data.cpu_index);
4223 /* OpenBSD has no such flag (SUSv2) */
4224 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
4225 obj->data.cpu_index);
4229 #if defined(__linux__)
4232 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
4233 obj->data.cpu_index);
4238 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
4239 obj->data.cpu_index);
4244 OBJ(wireless_essid) {
4245 snprintf(p, p_max_size, "%s", obj->data.net->essid);
4247 OBJ(wireless_mode) {
4248 snprintf(p, p_max_size, "%s", obj->data.net->mode);
4250 OBJ(wireless_bitrate) {
4251 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
4254 snprintf(p, p_max_size, "%s", obj->data.net->ap);
4256 OBJ(wireless_link_qual) {
4257 spaced_print(p, p_max_size, "%d", 4, "wireless_link_qual",
4258 obj->data.net->link_qual);
4260 OBJ(wireless_link_qual_max) {
4261 spaced_print(p, p_max_size, "%d", 4,
4262 "wireless_link_qual_max", obj->data.net->link_qual_max);
4264 OBJ(wireless_link_qual_perc) {
4265 if (obj->data.net->link_qual_max > 0) {
4266 spaced_print(p, p_max_size, "%.0f", 5,
4267 "wireless_link_qual_perc",
4268 (double) obj->data.net->link_qual /
4269 obj->data.net->link_qual_max * 100);
4271 spaced_print(p, p_max_size, "unk", 5,
4272 "wireless_link_qual_perc");
4275 OBJ(wireless_link_bar) {
4276 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
4277 obj->data.net->link_qual_max) * 255.0);
4279 #endif /* HAVE_IWLIB */
4281 #endif /* __linux__ */
4284 get_freq_dynamic(p, p_max_size, "%.0f", 1);
4285 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4289 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
4291 get_freq_dynamic(p, p_max_size, "%.2f", 1000);
4293 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4298 get_adt746x_cpu(p, p_max_size);
4301 get_adt746x_fan(p, p_max_size);
4304 get_acpi_fan(p, p_max_size);
4306 OBJ(acpiacadapter) {
4307 get_acpi_ac_adapter(p, p_max_size);
4310 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
4313 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
4315 OBJ(battery_percent) {
4316 spaced_print(p, p_max_size, "%*d", 4, "battery_percent",
4317 pad_percents, get_battery_perct(obj->data.s));
4320 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
4322 #endif /* __OpenBSD__ */
4325 human_readable(cur->buffers * 1024, p, 255, "buffers");
4328 human_readable(cur->cached * 1024, p, 255, "buffers");
4331 if (obj->data.cpu_index > info.cpu_count) {
4332 printf("obj->data.cpu_index %i info.cpu_count %i",
4333 obj->data.cpu_index, info.cpu_count);
4334 CRIT_ERR("attempting to use more CPUs then you have!");
4336 spaced_print(p, p_max_size, "%*d", 4, "cpu", pad_percents,
4337 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
4340 new_bar(p, obj->a, obj->b,
4341 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
4344 new_graph(p, obj->a, obj->b, obj->c, obj->d, (unsigned int)
4345 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
4349 new_fg(p, obj->data.l);
4381 OBJ(conky_version) {
4382 snprintf(p, p_max_size, "%s", VERSION);
4384 OBJ(conky_build_date) {
4385 snprintf(p, p_max_size, "%s", BUILD_DATE);
4387 OBJ(conky_build_arch) {
4388 snprintf(p, p_max_size, "%s", BUILD_ARCH);
4390 #if defined(__linux__)
4392 snprintf(p, p_max_size, "%s",
4393 get_disk_protect_queue(obj->data.s));
4396 snprintf(p, p_max_size, "%s", i8k.version);
4399 snprintf(p, p_max_size, "%s", i8k.bios);
4402 snprintf(p, p_max_size, "%s", i8k.serial);
4405 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
4407 OBJ(i8k_cpu_tempf) {
4410 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
4411 snprintf(p, p_max_size, "%.1f", cpu_temp * (9.0 / 5.0) + 32.0);
4413 OBJ(i8k_left_fan_status) {
4414 int left_fan_status;
4416 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
4417 if (left_fan_status == 0) {
4418 snprintf(p, p_max_size, "off");
4420 if (left_fan_status == 1) {
4421 snprintf(p, p_max_size, "low");
4423 if (left_fan_status == 2) {
4424 snprintf(p, p_max_size, "high");
4427 OBJ(i8k_right_fan_status) {
4428 int right_fan_status;
4430 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
4431 if (right_fan_status == 0) {
4432 snprintf(p, p_max_size, "off");
4434 if (right_fan_status == 1) {
4435 snprintf(p, p_max_size, "low");
4437 if (right_fan_status == 2) {
4438 snprintf(p, p_max_size, "high");
4441 OBJ(i8k_left_fan_rpm) {
4442 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
4444 OBJ(i8k_right_fan_rpm) {
4445 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
4447 OBJ(i8k_ac_status) {
4450 sscanf(i8k.ac_status, "%d", &ac_status);
4451 if (ac_status == -1) {
4452 snprintf(p, p_max_size, "disabled (read i8k docs)");
4454 if (ac_status == 0) {
4455 snprintf(p, p_max_size, "off");
4457 if (ac_status == 1) {
4458 snprintf(p, p_max_size, "on");
4461 OBJ(i8k_buttons_status) {
4462 snprintf(p, p_max_size, "%s", i8k.buttons_status);
4465 get_ibm_acpi_fan(p, p_max_size);
4468 get_ibm_acpi_temps();
4469 snprintf(p, p_max_size, "%d", ibm_acpi.temps[obj->data.sensor]);
4472 get_ibm_acpi_volume(p, p_max_size);
4474 OBJ(ibm_brightness) {
4475 get_ibm_acpi_brightness(p, p_max_size);
4478 if ((obj->data.ifblock.s)
4479 && (!interface_up(obj->data.ifblock.s))) {
4480 i = obj->data.ifblock.pos;
4487 if (!cur->gw_info.count) {
4488 i = obj->data.ifblock.pos;
4495 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
4498 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
4501 snprintf(p, p_max_size, "%d", get_laptop_mode());
4504 get_powerbook_batt_info(p, p_max_size, obj->data.i);
4506 #endif /* __linux__ */
4509 OBJ(obsd_sensors_temp) {
4510 obsd_sensors.device = sensor_device;
4511 update_obsd_sensors();
4512 snprintf(p, p_max_size, "%.1f",
4513 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
4515 OBJ(obsd_sensors_fan) {
4516 obsd_sensors.device = sensor_device;
4517 update_obsd_sensors();
4518 snprintf(p, p_max_size, "%d",
4519 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
4521 OBJ(obsd_sensors_volt) {
4522 obsd_sensors.device = sensor_device;
4523 update_obsd_sensors();
4524 snprintf(p, p_max_size, "%.2f",
4525 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4528 get_obsd_vendor(p, p_max_size);
4531 get_obsd_product(p, p_max_size);
4533 #endif /* __OpenBSD__ */
4537 new_font(p, obj->data.s);
4540 /* TODO: move this correction from kB to kB/s elsewhere
4541 * (or get rid of it??) */
4543 if (obj->data.diskio) {
4545 (obj->data.diskio->current / update_interval) * 1024LL,
4546 p, p_max_size, "diskio");
4548 human_readable(diskio_value * 1024LL, p, p_max_size,
4553 if (obj->data.diskio) {
4554 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL, p, p_max_size,
4557 human_readable(diskio_write_value * 1024LL, p, p_max_size,
4562 if (obj->data.diskio) {
4563 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL, p, p_max_size,
4566 human_readable(diskio_read_value * 1024LL, p, p_max_size,
4571 if (obj->data.diskio) {
4572 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4573 obj->data.diskio->current, obj->e, 1);
4575 new_graph(p, obj->a, obj->b, obj->c, obj->d, diskio_value,
4579 OBJ(diskiograph_read) {
4580 if (obj->data.diskio) {
4581 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4582 obj->data.diskio->current_read, obj->e, 1);
4584 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4585 diskio_read_value, obj->e, 1);
4588 OBJ(diskiograph_write) {
4589 if (obj->data.diskio) {
4590 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4591 obj->data.diskio->current_write, obj->e, 1);
4593 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4594 diskio_write_value, obj->e, 1);
4598 spaced_print(p, p_max_size, "%d", 6, "downspeed",
4599 round_to_int(obj->data.net->recv_speed / 1024));
4602 spaced_print(p, p_max_size, "%.1f", 8, "downspeedf",
4603 obj->data.net->recv_speed / 1024.0);
4605 OBJ(downspeedgraph) {
4606 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4607 obj->data.net->recv_speed / 1024.0, obj->e, 1);
4611 i = obj->data.ifblock.pos - 1;
4621 snprintf(p, p_max_size, "%u.%u.%u.%u",
4622 obj->data.net->addr.sa_data[2] & 255,
4623 obj->data.net->addr.sa_data[3] & 255,
4624 obj->data.net->addr.sa_data[4] & 255,
4625 obj->data.net->addr.sa_data[5] & 255);
4628 #if defined(__linux__)
4630 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
4632 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
4633 strcpy(p, obj->data.net->addrs);
4636 strcpy(p, "0.0.0.0");
4638 #endif /* __linux__ */
4640 #if defined(IMLIB2) && defined(X11)
4645 Imlib_Image image, buffer;
4647 image = imlib_load_image(obj->data.s);
4648 imlib_context_set_image(image);
4652 w = imlib_image_get_width();
4653 h = imlib_image_get_height();
4654 buffer = imlib_create_image(w, h);
4655 imlib_context_set_display(display);
4656 imlib_context_set_drawable(window.drawable);
4657 imlib_context_set_colormap(DefaultColormap(display,
4659 imlib_context_set_visual(DefaultVisual(display,
4661 imlib_context_set_image(buffer);
4662 imlib_blend_image_onto_image(image, 0, 0, 0, w, h,
4663 text_start_x, text_start_y, w, h);
4664 imlib_render_image_on_drawable(text_start_x,
4667 imlib_context_set_image(image);
4675 FILE *fp = popen(obj->data.s, "r");
4676 int length = fread(p, 1, p_max_size, fp);
4681 if (length > 0 && p[length - 1] == '\n') {
4682 p[length - 1] = '\0';
4687 struct information *my_info;
4688 struct text_object_list *text_objects;
4691 fp = popen(obj->data.s, "r");
4692 fread(p, 1, p_max_size, fp);
4695 my_info = malloc(sizeof(struct information));
4696 memcpy(my_info, cur, sizeof(struct information));
4697 text_objects = parse_conky_vars(p, p, my_info);
4702 if (length > 0 && p[length - 1] == '\n') {
4703 p[length - 1] = '\0';
4706 free_text_objects(text_objects->text_object_count, text_objects->text_objects);
4712 FILE *fp = popen(obj->data.s, "r");
4713 int n2 = fread(p, 1, p_max_size, fp);
4718 if (n2 && p[n2 - 1] == '\n') {
4723 if (*p2 == '\001') {
4729 if (sscanf(p, "%lf", &barnum) == 0) {
4730 ERR("reading execbar value failed (perhaps it's not the "
4731 "correct format?)");
4733 if (barnum > 100 || barnum < 0) {
4734 ERR("your execbar value is not between 0 and 100, "
4735 "therefore it will be ignored");
4737 barnum = barnum / 100.0;
4738 new_bar(p, 0, 4, (int) (barnum * 255.0));
4743 FILE *fp = popen(obj->data.s, "r");
4744 int n2 = fread(p, 1, p_max_size, fp);
4749 if (n2 && p[n2 - 1] == '\n') {
4753 if (*p2 == '\001') {
4759 if (sscanf(p, "%lf", &barnum) == 0) {
4760 ERR("reading execgraph value failed (perhaps it's not the "
4761 "correct format?)");
4763 if (barnum > 100 || barnum < 0) {
4764 ERR("your execgraph value is not between 0 and 100, "
4765 "therefore it will be ignored");
4767 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum),
4772 if (current_update_time - obj->data.execi.last_update
4773 < obj->data.execi.interval) {
4774 new_bar(p, 0, 4, (int) obj->f);
4777 FILE *fp = popen(obj->data.execi.cmd, "r");
4778 int n2 = fread(p, 1, p_max_size, fp);
4783 if (n2 && p[n2 - 1] == '\n') {
4788 if (*p2 == '\001') {
4794 if (sscanf(p, "%f", &barnum) == 0) {
4795 ERR("reading execibar value failed (perhaps it's not "
4796 "the correct format?)");
4798 if (barnum > 100 || barnum < 0) {
4799 ERR("your execibar value is not between 0 and 100, "
4800 "therefore it will be ignored");
4802 obj->f = 255 * barnum / 100.0;
4803 new_bar(p, 0, 4, (int) obj->f);
4805 obj->data.execi.last_update = current_update_time;
4809 if (current_update_time - obj->data.execi.last_update
4810 < obj->data.execi.interval) {
4811 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
4814 FILE *fp = popen(obj->data.execi.cmd, "r");
4815 int n2 = fread(p, 1, p_max_size, fp);
4820 if (n2 && p[n2 - 1] == '\n') {
4825 if (*p2 == '\001') {
4831 if (sscanf(p, "%f", &barnum) == 0) {
4832 ERR("reading execigraph value failed (perhaps it's not "
4833 "the correct format?)");
4835 if (barnum > 100 || barnum < 0) {
4836 ERR("your execigraph value is not between 0 and 100, "
4837 "therefore it will be ignored");
4840 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f),
4843 obj->data.execi.last_update = current_update_time;
4847 if (current_update_time - obj->data.execi.last_update
4848 < obj->data.execi.interval
4849 || obj->data.execi.interval == 0) {
4850 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4852 char *output = obj->data.execi.buffer;
4853 FILE *fp = popen(obj->data.execi.cmd, "r");
4855 int length = fread(output, 1, text_buffer_size, fp);
4858 output[length] = '\0';
4859 if (length > 0 && output[length - 1] == '\n') {
4860 output[length - 1] = '\0';
4862 obj->data.execi.last_update = current_update_time;
4863 snprintf(p, p_max_size, "%s", output);
4865 // parse_conky_vars(output, p, cur);
4868 struct text_object_list *text_objects = 0;
4869 struct information *my_info =
4870 malloc(sizeof(struct information));
4871 memcpy(my_info, cur, sizeof(struct information));
4873 if (current_update_time - obj->data.execi.last_update
4874 < obj->data.execi.interval
4875 || obj->data.execi.interval == 0) {
4876 text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info);
4878 char *output = obj->data.execi.buffer;
4879 FILE *fp = popen(obj->data.execi.cmd, "r");
4880 int length = fread(output, 1, text_buffer_size, fp);
4884 output[length] = '\0';
4885 if (length > 0 && output[length - 1] == '\n') {
4886 output[length - 1] = '\0';
4889 text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info);
4890 obj->data.execi.last_update = current_update_time;
4892 free_text_objects(text_objects->text_object_count, text_objects->text_objects);
4897 if (!obj->data.texeci.p_timed_thread) {
4898 obj->data.texeci.p_timed_thread =
4899 timed_thread_create(&threaded_exec,
4900 (void *) obj, obj->data.texeci.interval * 1000000);
4901 if (!obj->data.texeci.p_timed_thread) {
4902 ERR("Error creating texeci timed thread");
4904 timed_thread_register(obj->data.texeci.p_timed_thread,
4905 &obj->data.texeci.p_timed_thread);
4906 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4907 ERR("Error running texeci timed thread");
4910 timed_thread_lock(obj->data.texeci.p_timed_thread);
4911 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4912 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4914 #endif /* HAVE_POPEN */
4916 if (obj->global_mode && info.mail) {
4917 // this means we use info
4918 if (!info.mail->p_timed_thread) {
4919 info.mail->p_timed_thread =
4920 timed_thread_create(&imap_thread,
4921 (void *) info.mail, info.mail->interval * 1000000);
4922 if (!info.mail->p_timed_thread) {
4923 ERR("Error creating imap timed thread");
4925 timed_thread_register(info.mail->p_timed_thread,
4926 &info.mail->p_timed_thread);
4927 if (timed_thread_run(info.mail->p_timed_thread)) {
4928 ERR("Error running imap timed thread");
4931 timed_thread_lock(info.mail->p_timed_thread);
4932 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4933 timed_thread_unlock(info.mail->p_timed_thread);
4934 } else if (obj->data.mail) {
4935 // this means we use obj
4936 if (!obj->data.mail->p_timed_thread) {
4937 obj->data.mail->p_timed_thread =
4938 timed_thread_create(&imap_thread,
4939 (void *) obj->data.mail,
4940 obj->data.mail->interval * 1000000);
4941 if (!obj->data.mail->p_timed_thread) {
4942 ERR("Error creating imap timed thread");
4944 timed_thread_register(obj->data.mail->p_timed_thread,
4945 &obj->data.mail->p_timed_thread);
4946 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
4947 ERR("Error running imap timed thread");
4950 timed_thread_lock(obj->data.mail->p_timed_thread);
4951 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4952 timed_thread_unlock(obj->data.mail->p_timed_thread);
4953 } else if (!obj->a) {
4954 // something is wrong, warn once then stop
4955 ERR("Theres a problem with your imap_unseen settings. "
4956 "Check that the global IMAP settings are defined "
4957 "properly (line %li).", obj->line);
4961 OBJ(imap_messages) {
4962 if (obj->global_mode && info.mail) {
4963 // this means we use info
4964 if (!info.mail->p_timed_thread) {
4965 info.mail->p_timed_thread =
4966 timed_thread_create(&imap_thread,
4967 (void *) info.mail, info.mail->interval * 1000000);
4968 if (!info.mail->p_timed_thread) {
4969 ERR("Error creating imap timed thread");
4971 timed_thread_register(info.mail->p_timed_thread,
4972 &info.mail->p_timed_thread);
4973 if (timed_thread_run(info.mail->p_timed_thread)) {
4974 ERR("Error running imap timed thread");
4977 timed_thread_lock(info.mail->p_timed_thread);
4978 snprintf(p, p_max_size, "%lu", info.mail->messages);
4979 timed_thread_unlock(info.mail->p_timed_thread);
4980 } else if (obj->data.mail) {
4981 // this means we use obj
4982 if (!obj->data.mail->p_timed_thread) {
4983 obj->data.mail->p_timed_thread =
4984 timed_thread_create(&imap_thread,
4985 (void *) obj->data.mail,
4986 obj->data.mail->interval * 1000000);
4987 if (!obj->data.mail->p_timed_thread) {
4988 ERR("Error creating imap timed thread");
4990 timed_thread_register(obj->data.mail->p_timed_thread,
4991 &obj->data.mail->p_timed_thread);
4992 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
4993 ERR("Error runninging imap timed thread");
4996 timed_thread_lock(obj->data.mail->p_timed_thread);
4997 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4998 timed_thread_lock(obj->data.mail->p_timed_thread);
4999 } else if (!obj->a) {
5000 // something is wrong, warn once then stop
5001 ERR("Theres a problem with your imap_messages settings. "
5002 "Check that the global IMAP settings are defined "
5003 "properly (line %li).", obj->line);
5008 if (obj->global_mode && info.mail) {
5009 // this means we use info
5010 if (!info.mail->p_timed_thread) {
5011 info.mail->p_timed_thread =
5012 timed_thread_create(&pop3_thread,
5013 (void *) info.mail, info.mail->interval * 1000000);
5014 if (!info.mail->p_timed_thread) {
5015 ERR("Error creating pop3 timed thread");
5017 timed_thread_register(info.mail->p_timed_thread,
5018 &info.mail->p_timed_thread);
5019 if (timed_thread_run(info.mail->p_timed_thread)) {
5020 ERR("Error running pop3 timed thread");
5023 timed_thread_lock(info.mail->p_timed_thread);
5024 snprintf(p, p_max_size, "%lu", info.mail->unseen);
5025 timed_thread_unlock(info.mail->p_timed_thread);
5026 } else if (obj->data.mail) {
5027 // this means we use obj
5028 if (!obj->data.mail->p_timed_thread) {
5029 obj->data.mail->p_timed_thread =
5030 timed_thread_create(&pop3_thread,
5031 (void *) obj->data.mail,
5032 obj->data.mail->interval * 1000000);
5033 if (!obj->data.mail->p_timed_thread) {
5034 ERR("Error creating pop3 timed thread");
5036 timed_thread_register(obj->data.mail->p_timed_thread,
5037 &obj->data.mail->p_timed_thread);
5038 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
5039 ERR("Error running pop3 timed thread");
5042 timed_thread_lock(obj->data.mail->p_timed_thread);
5043 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
5044 timed_thread_unlock(obj->data.mail->p_timed_thread);
5045 } else if (!obj->a) {
5046 // something is wrong, warn once then stop
5047 ERR("Theres a problem with your pop3_unseen settings. "
5048 "Check that the global POP3 settings are defined "
5049 "properly (line %li).", obj->line);
5054 if (obj->global_mode && info.mail) {
5055 // this means we use info
5056 if (!info.mail->p_timed_thread) {
5057 info.mail->p_timed_thread =
5058 timed_thread_create(&pop3_thread,
5059 (void *) info.mail, info.mail->interval * 1000000);
5060 if (!info.mail->p_timed_thread) {
5061 ERR("Error creating pop3 timed thread");
5063 timed_thread_register(info.mail->p_timed_thread,
5064 &info.mail->p_timed_thread);
5065 if (timed_thread_run(info.mail->p_timed_thread)) {
5066 ERR("Error running pop3 timed thread");
5069 timed_thread_lock(info.mail->p_timed_thread);
5070 snprintf(p, p_max_size, "%.1f",
5071 info.mail->used / 1024.0 / 1024.0);
5072 timed_thread_unlock(info.mail->p_timed_thread);
5073 } else if (obj->data.mail) {
5074 // this means we use obj
5075 if (!obj->data.mail->p_timed_thread) {
5076 obj->data.mail->p_timed_thread =
5077 timed_thread_create(&pop3_thread,
5078 (void *) obj->data.mail,
5079 obj->data.mail->interval * 1000000);
5080 if (!obj->data.mail->p_timed_thread) {
5081 ERR("Error creating pop3 timed thread");
5083 timed_thread_register(obj->data.mail->p_timed_thread,
5084 &obj->data.mail->p_timed_thread);
5085 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
5086 ERR("Error running pop3 timed thread");
5089 timed_thread_lock(obj->data.mail->p_timed_thread);
5090 snprintf(p, p_max_size, "%.1f",
5091 obj->data.mail->used / 1024.0 / 1024.0);
5092 timed_thread_unlock(obj->data.mail->p_timed_thread);
5093 } else if (!obj->a) {
5094 // something is wrong, warn once then stop
5095 ERR("Theres a problem with your pop3_used settings. "
5096 "Check that the global POP3 settings are defined "
5097 "properly (line %li).", obj->line);
5102 if (obj->data.fs != NULL) {
5103 if (obj->data.fs->size == 0) {
5104 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5106 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5107 (int) (255 - obj->data.fsbar.fs->avail * 255 /
5108 obj->data.fs->size));
5113 if (obj->data.fs != NULL) {
5114 human_readable(obj->data.fs->avail, p, 255, "fs_free");
5118 if (obj->data.fs != NULL) {
5119 if (obj->data.fs->size) {
5120 spaced_print(p, p_max_size, "%*d", 4, "fs_free_perc",
5121 pad_percents, (int) ((obj->data.fs->avail * 100) /
5122 obj->data.fs->size));
5124 snprintf(p, p_max_size, "0");
5129 if (obj->data.fs != NULL) {
5130 human_readable(obj->data.fs->size, p, 255, "fs_size");
5134 if (obj->data.fs != NULL)
5135 snprintf(p, p_max_size, "%s", obj->data.fs->type);
5138 if (obj->data.fs != NULL) {
5139 human_readable(obj->data.fs->size - (obj->data.fs->free
5140 ? obj->data.fs->free : obj->data.fs->avail), p, 255,
5145 if (obj->data.fs != NULL) {
5146 if (obj->data.fs->size == 0) {
5147 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5149 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5150 (int) (obj->data.fsbar.fs->avail * 255 /
5151 obj->data.fs->size));
5156 if (obj->data.fs != NULL) {
5157 if (obj->data.fs->size) {
5158 spaced_print(p, 4, "%*d", 4, "fs_used_perc",
5159 pad_percents, 100 - ((int) ((obj->data.fs->avail * 100) /
5160 obj->data.fs->size)));
5162 snprintf(p, p_max_size, "0");
5167 float *v = info.loadavg;
5169 if (obj->data.loadavg[2]) {
5170 snprintf(p, p_max_size, "%.2f %.2f %.2f",
5171 v[obj->data.loadavg[0] - 1],
5172 v[obj->data.loadavg[1] - 1],
5173 v[obj->data.loadavg[2] - 1]);
5174 } else if (obj->data.loadavg[1]) {
5175 snprintf(p, p_max_size, "%.2f %.2f",
5176 v[obj->data.loadavg[0] - 1],
5177 v[obj->data.loadavg[1] - 1]);
5178 } else if (obj->data.loadavg[0]) {
5179 snprintf(p, p_max_size, "%.2f",
5180 v[obj->data.loadavg[0] - 1]);
5184 new_goto(p, obj->data.i);
5187 new_tab(p, obj->data.pair.a, obj->data.pair.b);
5190 new_hr(p, obj->data.i);
5193 if (cur->nameserver_info.nscount > obj->data.i)
5194 snprintf(p, p_max_size, "%s",
5195 cur->nameserver_info.ns_list[obj->data.i]);
5199 PRSS *data = get_rss_info(obj->data.rss.uri,
5200 obj->data.rss.delay);
5204 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
5206 if (!strcmp(obj->data.rss.action, "feed_title")) {
5208 // remove trailing new line if one exists
5209 if (str[strlen(str) - 1] == '\n') {
5210 str[strlen(str) - 1] = 0;
5212 snprintf(p, p_max_size, "%s", str);
5213 } else if (!strcmp(obj->data.rss.action, "item_title")) {
5214 if (obj->data.rss.act_par < data->item_count) {
5215 str = data->items[obj->data.rss.act_par].title;
5216 // remove trailing new line if one exists
5217 if (str[strlen(str) - 1] == '\n') {
5218 str[strlen(str) - 1] = 0;
5220 snprintf(p, p_max_size, "%s", str);
5222 } else if (!strcmp(obj->data.rss.action, "item_desc")) {
5223 if (obj->data.rss.act_par < data->item_count) {
5225 data->items[obj->data.rss.act_par].description;
5226 // remove trailing new line if one exists
5227 if (str[strlen(str) - 1] == '\n') {
5228 str[strlen(str) - 1] = 0;
5230 snprintf(p, p_max_size, "%s", str);
5232 } else if (!strcmp(obj->data.rss.action, "item_titles")) {
5233 if (data->item_count > 0) {
5239 if (obj->data.rss.act_par > data->item_count) {
5240 show = data->item_count;
5242 show = obj->data.rss.act_par;
5244 for (itmp = 0; itmp < show; itmp++) {
5245 PRSS_Item *item = &data->items[itmp];
5249 // don't add new line before first item
5251 strncat(p, "\n", p_max_size);
5253 /* remove trailing new line if one exists,
5254 * we have our own */
5255 if (str[strlen(str) - 1] == '\n') {
5256 str[strlen(str) - 1] = 0;
5258 strncat(p, str, p_max_size);
5271 temp = get_hddtemp_info(obj->data.hddtemp.dev,
5272 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
5274 snprintf(p, p_max_size, "N/A");
5275 } else if (unit == '*') {
5276 snprintf(p, p_max_size, "%s", temp);
5278 snprintf(p, p_max_size, "%s%c", temp, unit);
5283 new_offset(p, obj->data.i);
5286 new_voffset(p, obj->data.i);
5292 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5293 obj->data.sysfs.devtype, obj->data.sysfs.type);
5295 if (r >= 100.0 || r == 0) {
5296 snprintf(p, p_max_size, "%d", (int) r);
5298 snprintf(p, p_max_size, "%.1f", r);
5304 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5305 obj->data.sysfs.devtype, obj->data.sysfs.type);
5307 if (r >= 100.0 || r == 0) {
5308 snprintf(p, p_max_size, "%d", (int) r);
5310 snprintf(p, p_max_size, "%.1f", r);
5316 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5317 obj->data.sysfs.devtype, obj->data.sysfs.type);
5319 if (r >= 100.0 || r == 0) {
5320 snprintf(p, p_max_size, "%d", (int) r);
5322 snprintf(p, p_max_size, "%.1f", r);
5325 #endif /* !__OpenBSD__ */
5327 new_alignr(p, obj->data.i);
5330 new_alignc(p, obj->data.i);
5333 struct text_object_list *text_objects;
5334 struct information *my_info =
5335 malloc(sizeof(struct information));
5336 memcpy(my_info, cur, sizeof(struct information));
5337 text_objects = parse_conky_vars(obj->data.ifblock.s, p, my_info);
5339 if (strlen(p) != 0) {
5340 i = obj->data.ifblock.pos;
5346 free_text_objects(text_objects->text_object_count, text_objects->text_objects);
5353 if ((obj->data.ifblock.s)
5354 && (stat(obj->data.ifblock.s, &tmp) == -1)) {
5355 i = obj->data.ifblock.pos;
5358 if (obj->data.ifblock.str) {
5359 if (!check_contains(obj->data.ifblock.s,
5360 obj->data.ifblock.str)) {
5361 i = obj->data.ifblock.pos;
5372 if ((obj->data.ifblock.s)
5373 && (!check_mount(obj->data.ifblock.s))) {
5374 i = obj->data.ifblock.pos;
5381 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
5382 i = obj->data.ifblock.pos;
5389 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
5392 snprintf(p, p_max_size, "%s", cur->uname_s.release);
5395 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
5400 human_readable(cur->mem * 1024, p, 255, "mem");
5403 human_readable(cur->memmax * 1024, p, 255, "memmax");
5407 spaced_print(p, p_max_size, "%*llu", 4, "memperc",
5408 pad_percents, cur->mem * 100 / cur->memmax);
5412 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5413 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
5416 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5417 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
5423 snprintf(p, p_max_size, "%d", mixer_get_avg(obj->data.l));
5426 snprintf(p, p_max_size, "%d", mixer_get_left(obj->data.l));
5429 snprintf(p, p_max_size, "%d", mixer_get_right(obj->data.l));
5432 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5433 mixer_get_avg(obj->data.mixerbar.l) * 255 / 100);
5436 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5437 mixer_get_left(obj->data.mixerbar.l) * 255 / 100);
5440 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5441 mixer_get_right(obj->data.mixerbar.l) * 255 / 100);
5446 update_mail_count(&obj->data.local_mail);
5447 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
5450 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
5452 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
5455 update_mail_count(&obj->data.local_mail);
5456 snprintf(p, p_max_size, "%d",
5457 obj->data.local_mail.new_mail_count);
5460 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
5463 new_outline(p, obj->data.l);
5466 spaced_print(p, p_max_size, "%hu", 5, "processes", cur->procs);
5468 OBJ(running_processes) {
5469 spaced_print(p, p_max_size, "%hu", 3, "running_processes", cur->run_procs);
5472 snprintf(p, p_max_size, "%s", obj->data.s);
5475 new_bg(p, obj->data.l);
5478 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
5481 human_readable(cur->swap * 1024, p, 255, "swap");
5484 human_readable(cur->swapmax * 1024, p, 255, "swapmax");
5487 if (cur->swapmax == 0) {
5488 strncpy(p, "No swap", p_max_size);
5490 spaced_print(p, p_max_size, "%*llu", 4, "swapperc",
5491 pad_percents, cur->swap * 100 / cur->swapmax);
5495 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5496 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
5499 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
5502 time_t t = time(NULL);
5503 struct tm *tm = localtime(&t);
5505 setlocale(LC_TIME, "");
5506 strftime(p, p_max_size, obj->data.s, tm);
5509 time_t t = time(NULL);
5510 struct tm *tm = gmtime(&t);
5512 strftime(p, p_max_size, obj->data.s, tm);
5519 if (obj->data.tztime.tz) {
5520 oldTZ = getenv("TZ");
5521 setenv("TZ", obj->data.tztime.tz, 1);
5527 setlocale(LC_TIME, "");
5528 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
5530 setenv("TZ", oldTZ, 1);
5535 // Needless to free oldTZ since getenv gives ptr to static data
5538 human_readable(obj->data.net->recv, p, 255, "totaldown");
5541 human_readable(obj->data.net->trans, p, 255, "totalup");
5544 snprintf(p, p_max_size, "%d", total_updates);
5547 spaced_print(p, p_max_size, "%d", 6, "upspeed",
5548 round_to_int(obj->data.net->trans_speed / 1024));
5551 spaced_print(p, p_max_size, "%.1f", 8, "upspeedf",
5552 obj->data.net->trans_speed / 1024.0);
5555 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5556 obj->data.net->trans_speed / 1024.0, obj->e, 1);
5559 format_seconds_short(p, p_max_size, (int) cur->uptime);
5562 format_seconds(p, p_max_size, (int) cur->uptime);
5565 snprintf(p, p_max_size, "%s", cur->users.names);
5568 snprintf(p, p_max_size, "%s", cur->users.terms);
5571 snprintf(p, p_max_size, "%s", cur->users.times);
5574 snprintf(p, p_max_size, "%d", cur->users.number);
5576 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
5577 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5581 msg = get_apm_adapter();
5582 snprintf(p, p_max_size, "%s", msg);
5585 OBJ(apm_battery_life) {
5588 msg = get_apm_battery_life();
5589 snprintf(p, p_max_size, "%s", msg);
5592 OBJ(apm_battery_time) {
5595 msg = get_apm_battery_time();
5596 snprintf(p, p_max_size, "%s", msg);
5599 #endif /* __FreeBSD__ __OpenBSD__ */
5603 snprintf(p, cur->mpd.max_title_len > 0
5604 ? cur->mpd.max_title_len : p_max_size, "%s",
5608 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5611 snprintf(p, p_max_size, "%s", cur->mpd.album);
5614 snprintf(p, p_max_size, "%s", cur->mpd.random);
5617 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
5620 snprintf(p, p_max_size, "%s", cur->mpd.track);
5623 snprintf(p, p_max_size, "%s", cur->mpd.name);
5626 snprintf(p, p_max_size, "%s", cur->mpd.file);
5629 snprintf(p, p_max_size, "%i", cur->mpd.volume);
5632 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
5635 snprintf(p, p_max_size, "%s", cur->mpd.status);
5638 int days = 0, hours = 0, minutes = 0, seconds = 0;
5639 int tmp = cur->mpd.elapsed;
5641 while (tmp >= 86400) {
5645 while (tmp >= 3600) {
5655 snprintf(p, p_max_size, "%i days %i:%02i:%02i", days,
5656 hours, minutes, seconds);
5657 } else if (hours > 0) {
5658 snprintf(p, p_max_size, "%i:%02i:%02i", hours, minutes,
5661 snprintf(p, p_max_size, "%i:%02i", minutes, seconds);
5665 int days = 0, hours = 0, minutes = 0, seconds = 0;
5666 int tmp = cur->mpd.length;
5668 while (tmp >= 86400) {
5672 while (tmp >= 3600) {
5682 snprintf(p, p_max_size, "%i days %i:%02i:%02i", days,
5683 hours, minutes, seconds);
5684 } else if (hours > 0) {
5685 snprintf(p, p_max_size, "%i:%02i:%02i", hours, minutes,
5688 snprintf(p, p_max_size, "%i:%02i", minutes, seconds);
5692 spaced_print(p, p_max_size, "%*d", 4, "mpd_percent",
5693 pad_percents, (int) (cur->mpd.progress * 100));
5696 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5697 (int) (cur->mpd.progress * 255.0f));
5700 memset(p, 0, p_max_size);
5701 if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title
5702 && *cur->mpd.title) {
5703 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist,
5705 } else if (cur->mpd.title && *cur->mpd.title) {
5706 snprintf(p, p_max_size, "%s", cur->mpd.title);
5707 } else if (cur->mpd.artist && *cur->mpd.artist) {
5708 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5709 } else if (cur->mpd.file && *cur->mpd.file) {
5710 snprintf(p, p_max_size, "%s", cur->mpd.file);
5719 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5722 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5725 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5728 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5730 OBJ(xmms2_comment) {
5731 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5734 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5737 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5740 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5742 OBJ(xmms2_tracknr) {
5743 if (cur->xmms2.tracknr != -1) {
5744 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5747 OBJ(xmms2_bitrate) {
5748 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5751 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5754 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5756 OBJ(xmms2_elapsed) {
5757 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5758 (cur->xmms2.elapsed / 1000) % 60);
5760 OBJ(xmms2_duration) {
5761 snprintf(p, p_max_size, "%02d:%02d",
5762 cur->xmms2.duration / 60000,
5763 (cur->xmms2.duration / 1000) % 60);
5765 OBJ(xmms2_percent) {
5766 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5769 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5770 (int) (cur->xmms2.progress * 255.0f));
5772 OBJ(xmms2_playlist) {
5773 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5775 OBJ(xmms2_timesplayed) {
5776 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5779 if (strlen(cur->xmms2.title) < 2
5780 && strlen(cur->xmms2.title) < 2) {
5781 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5783 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5789 OBJ(audacious_status) {
5790 snprintf(p, p_max_size, "%s",
5791 cur->audacious.items[AUDACIOUS_STATUS]);
5793 OBJ(audacious_title) {
5794 snprintf(p, cur->audacious.max_title_len > 0
5795 ? cur->audacious.max_title_len : p_max_size, "%s",
5796 cur->audacious.items[AUDACIOUS_TITLE]);
5798 OBJ(audacious_length) {
5799 snprintf(p, p_max_size, "%s",
5800 cur->audacious.items[AUDACIOUS_LENGTH]);
5802 OBJ(audacious_length_seconds) {
5803 snprintf(p, p_max_size, "%s",
5804 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5806 OBJ(audacious_position) {
5807 snprintf(p, p_max_size, "%s",
5808 cur->audacious.items[AUDACIOUS_POSITION]);
5810 OBJ(audacious_position_seconds) {
5811 snprintf(p, p_max_size, "%s",
5812 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5814 OBJ(audacious_bitrate) {
5815 snprintf(p, p_max_size, "%s",
5816 cur->audacious.items[AUDACIOUS_BITRATE]);
5818 OBJ(audacious_frequency) {
5819 snprintf(p, p_max_size, "%s",
5820 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5822 OBJ(audacious_channels) {
5823 snprintf(p, p_max_size, "%s",
5824 cur->audacious.items[AUDACIOUS_CHANNELS]);
5826 OBJ(audacious_filename) {
5827 snprintf(p, p_max_size, "%s",
5828 cur->audacious.items[AUDACIOUS_FILENAME]);
5830 OBJ(audacious_playlist_length) {
5831 snprintf(p, p_max_size, "%s",
5832 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5834 OBJ(audacious_playlist_position) {
5835 snprintf(p, p_max_size, "%s",
5836 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5838 OBJ(audacious_bar) {
5842 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5843 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5844 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5850 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5853 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5856 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5859 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5862 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5865 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5869 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
5872 switch (obj->data.top.type) {
5874 snprintf(p, 16, "%-15s",
5875 cur->cpu[obj->data.top.num]->name);
5878 snprintf(p, 7, "%6.2f",
5879 cur->cpu[obj->data.top.num]->amount);
5882 snprintf(p, 6, "%5i",
5883 cur->cpu[obj->data.top.num]->pid);
5886 snprintf(p, 7, "%6.2f",
5887 cur->cpu[obj->data.top.num]->totalmem);
5890 timeval = format_time(
5891 cur->cpu[obj->data.top.num]->total_cpu_time, 9);
5892 snprintf(p, 10, "%9s", timeval);
5896 human_readable(cur->cpu[obj->data.top.num]->rss,
5900 human_readable(cur->cpu[obj->data.top.num]->vsize,
5904 ERR("Unhandled top data type: %d\n",
5905 obj->data.top.type);
5908 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
5912 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
5915 switch (obj->data.top.type) {
5917 snprintf(p, 16, "%-15s",
5918 cur->memu[obj->data.top.num]->name);
5921 snprintf(p, 7, "%6.2f",
5922 cur->memu[obj->data.top.num]->amount);
5925 snprintf(p, 6, "%5i",
5926 cur->memu[obj->data.top.num]->pid);
5929 snprintf(p, 7, "%6.2f",
5930 cur->memu[obj->data.top.num]->totalmem);
5933 timeval = format_time(
5934 cur->memu[obj->data.top.num]->total_cpu_time,
5936 snprintf(p, 10, "%9s", timeval);
5940 human_readable(cur->cpu[obj->data.top.num]->rss,
5944 human_readable(cur->cpu[obj->data.top.num]->vsize,
5948 ERR("Unhandled top data type: %d\n",
5949 obj->data.top.type);
5952 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
5956 if (current_update_time - obj->data.tail.last_update
5957 < obj->data.tail.interval) {
5958 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5964 obj->data.tail.last_update = current_update_time;
5966 if (obj->data.tail.fd != -1) {
5967 tail_pipe(obj, p, p_max_size);
5971 fp = fopen(obj->data.tail.logfile, "rt");
5974 /* Send one message, but do not consistently spam
5975 * on missing logfiles. */
5976 if (obj->data.tail.readlines != 0) {
5977 ERR("tail logfile failed to open");
5978 strcpy(obj->data.tail.buffer, "Logfile Missing");
5980 obj->data.tail.readlines = 0;
5981 snprintf(p, p_max_size, "Logfile Missing");
5983 obj->data.tail.readlines = 0;
5984 /* -1 instead of 0 to avoid counting a trailing
5986 fseek(fp, -1, SEEK_END);
5987 bsize = ftell(fp) + 1;
5988 for (iter = obj->data.tail.wantedlines; iter > 0;
5990 nl = rev_fcharfind(fp, '\n', iter);
5995 obj->data.tail.readlines = iter;
5996 if (obj->data.tail.readlines
5997 < obj->data.tail.wantedlines) {
5998 fseek(fp, 0, SEEK_SET);
6000 fseek(fp, nl + 1, SEEK_SET);
6003 /* Make sure bsize is at least 1 byte smaller than the
6004 * buffer max size. */
6005 if (bsize > (long) ((text_buffer_size * 20) - 1)) {
6006 fseek(fp, bsize - text_buffer_size * 20 - 1,
6008 bsize = text_buffer_size * 20 - 1;
6010 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
6013 /* Clean up trailing newline, make sure the
6014 * buffer is null terminated. */
6015 if (obj->data.tail.buffer[bsize - 1] == '\n') {
6016 obj->data.tail.buffer[bsize - 1] = '\0';
6018 obj->data.tail.buffer[bsize] = '\0';
6020 snprintf(p, p_max_size, "%s",
6021 obj->data.tail.buffer);
6023 strcpy(obj->data.tail.buffer, "Logfile Empty");
6024 snprintf(p, p_max_size, "Logfile Empty");
6027 } /* if cur_upd_time >= */
6028 // parse_conky_vars(obj->data.tail.buffer, p, cur);
6033 if (current_update_time - obj->data.tail.last_update
6034 < obj->data.tail.interval) {
6035 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
6041 obj->data.tail.last_update = current_update_time;
6043 fp = fopen(obj->data.tail.logfile, "rt");
6045 /* Send one message, but do not consistently spam
6046 * on missing logfiles. */
6047 if (obj->data.tail.readlines != 0) {
6048 ERR("head logfile failed to open");
6049 strcpy(obj->data.tail.buffer, "Logfile Missing");
6051 obj->data.tail.readlines = 0;
6052 snprintf(p, p_max_size, "Logfile Missing");
6054 obj->data.tail.readlines = 0;
6055 for (iter = obj->data.tail.wantedlines; iter > 0;
6057 nl = fwd_fcharfind(fp, '\n', iter);
6062 obj->data.tail.readlines = iter;
6063 /* Make sure nl is at least 1 byte smaller than the
6064 * buffer max size. */
6065 if (nl > (long) ((text_buffer_size * 20) - 1)) {
6066 nl = text_buffer_size * 20 - 1;
6068 nl = fread(obj->data.tail.buffer, 1, nl, fp);
6071 /* Clean up trailing newline, make sure the buffer
6072 * is null terminated. */
6073 if (obj->data.tail.buffer[nl - 1] == '\n') {
6074 obj->data.tail.buffer[nl - 1] = '\0';
6076 obj->data.tail.buffer[nl] = '\0';
6078 snprintf(p, p_max_size, "%s",
6079 obj->data.tail.buffer);
6081 strcpy(obj->data.tail.buffer, "Logfile Empty");
6082 snprintf(p, p_max_size, "Logfile Empty");
6084 } /* if fp == null */
6085 } /* cur_upd_time >= */
6086 // parse_conky_vars(obj->data.tail.buffer, p, cur);
6089 #ifdef TCP_PORT_MONITOR
6091 /* grab a pointer to this port monitor */
6092 tcp_port_monitor_t *p_monitor =
6093 find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
6094 obj->data.tcp_port_monitor.port_range_begin,
6095 obj->data.tcp_port_monitor.port_range_end);
6098 snprintf(p, p_max_size, "monitor not found");
6102 /* now grab the text of interest */
6103 if (peek_tcp_port_monitor(p_monitor,
6104 obj->data.tcp_port_monitor.item,
6105 obj->data.tcp_port_monitor.connection_index, p,
6107 snprintf(p, p_max_size, "monitor peek error");
6115 iconv_converting = 1;
6116 iconv_selected = obj->a;
6119 iconv_converting = 0;
6124 OBJ(entropy_avail) {
6125 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
6127 OBJ(entropy_poolsize) {
6128 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
6131 double entropy_perc;
6133 entropy_perc = (double) cur->entropy.entropy_avail /
6134 (double) cur->entropy.poolsize;
6135 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
6141 s = smapi_get_val(obj->data.s);
6142 snprintf(p, p_max_size, "%s", s);
6146 OBJ(if_smapi_bat_installed) {
6148 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
6149 if(!smapi_bat_installed(idx)) {
6150 i = obj->data.ifblock.pos;
6155 ERR("argument to if_smapi_bat_installed must be an integer");
6157 OBJ(smapi_bat_perc) {
6159 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
6160 val = smapi_bat_installed(idx) ?
6161 smapi_get_bat_int(idx, "remaining_percent") : 0;
6162 spaced_print(p, p_max_size, "%*d", 4, "smapi_bat_perc", pad_percents, val);
6164 ERR("argument to smapi_bat_perc must be an integer");
6166 OBJ(smapi_bat_bar) {
6167 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
6168 new_bar(p, obj->a, obj->b, (int)
6169 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
6171 new_bar(p, obj->a, obj->b, 0);
6179 unsigned int a = strlen(p);
6182 if (a > 0 && iconv_converting && iconv_selected > 0
6183 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
6185 size_t dummy1, dummy2;
6186 char *ptr = buff_in;
6189 dummy1 = dummy2 = a;
6191 strncpy(buff_in, p, p_max_size);
6193 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
6194 while (dummy1 > 0) {
6195 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
6198 ERR("Iconv codeset conversion failed");
6203 /* It is nessecary when we are converting from multibyte to
6204 * singlebyte codepage */
6207 #endif /* HAVE_ICONV */
6214 double current_update_time, last_update_time;
6216 static void generate_text(void)
6218 struct information *cur = &info;
6225 current_update_time = get_time();
6228 /* fix diskio rates to b/s (use update_interval */
6229 diskio_read_value = diskio_read_value / update_interval;
6230 diskio_write_value = diskio_write_value / update_interval;
6231 diskio_value = diskio_value / update_interval;
6233 /* add things to the buffer */
6239 generate_text_internal(p, max_user_text, global_text_objects,
6240 global_text_object_count, cur);
6242 if (stuff_in_upper_case) {
6245 tmp_p = text_buffer;
6247 *tmp_p = toupper(*tmp_p);
6252 last_update_time = current_update_time;
6258 static void set_font(void)
6262 if (window.xftdraw != NULL) {
6263 XftDrawDestroy(window.xftdraw);
6265 window.xftdraw = XftDrawCreate(display, window.drawable,
6266 DefaultVisual(display, screen), DefaultColormap(display, screen));
6270 XSetFont(display, window.gc, fonts[selected_font].font->fid);
6276 static inline int get_string_width(const char *s)
6279 return *s ? calc_text_width(s, strlen(s)) : 0;
6285 static inline int get_string_width_special(char *s)
6297 p = strndup(s, text_buffer_size);
6301 if (*p == SPECIAL_CHAR) {
6302 /* shift everything over by 1 so that the special char
6303 * doesn't mess up the size calculation */
6304 for (i = 0; i < strlen(p); i++) {
6305 *(p + i) = *(p + i + 1);
6307 if (specials[special_index + idx].type == GRAPH
6308 || specials[special_index + idx].type == BAR) {
6309 width += specials[special_index + idx].width;
6316 if (strlen(final) > 1) {
6317 width += calc_text_width(final, strlen(final));
6322 return (s) ? strlen(s) : 0;
6327 static void text_size_updater(char *s);
6329 int last_font_height;
6330 static void update_text_area(void)
6334 /* update text size if it isn't fixed */
6339 text_width = minimum_width;
6342 last_font_height = font_height();
6343 for_each_line(text_buffer, text_size_updater);
6345 if (text_height < minimum_height) {
6346 text_height = minimum_height;
6348 if (text_width > maximum_width && maximum_width > 0) {
6349 text_width = maximum_width;
6353 /* get text position on workarea */
6354 switch (text_alignment) {
6361 x = workarea[2] - text_width - gap_x;
6366 x = workarea[2] / 2 - text_width / 2 - gap_x;
6373 y = workarea[3] - text_height - gap_y;
6377 x = workarea[2] - text_width - gap_x;
6378 y = workarea[3] - text_height - gap_y;
6382 x = workarea[2] / 2 - text_width / 2 - gap_x;
6383 y = workarea[3] - text_height - gap_y;
6388 y = workarea[3] / 2 - text_height / 2 - gap_y;
6392 x = workarea[2] - text_width - gap_x;
6393 y = workarea[3] / 2 - text_height / 2 - gap_y;
6397 case NONE: // Let the WM manage the window
6408 if (own_window && !fixed_pos) {
6411 text_start_x = border_margin + 1;
6412 text_start_y = border_margin + 1;
6413 window.x = x - border_margin - 1;
6414 window.y = y - border_margin - 1;
6418 /* If window size doesn't match to workarea's size,
6419 * then window probably includes panels (gnome).
6420 * Blah, doesn't work on KDE. */
6421 if (workarea[2] != window.width || workarea[3] != window.height) {
6433 static int cur_x, cur_y; /* current x and y for drawing */
6434 static int draw_mode; /* FG, BG or OUTLINE */
6435 static long current_color;
6438 static void text_size_updater(char *s)
6443 /* get string widths and skip specials */
6446 if (*p == SPECIAL_CHAR) {
6448 w += get_string_width(s);
6451 if (specials[special_index].type == BAR
6452 || specials[special_index].type == GRAPH) {
6453 w += specials[special_index].width;
6454 if (specials[special_index].height > last_font_height) {
6455 last_font_height = specials[special_index].height;
6456 last_font_height += font_ascent();
6458 } else if (specials[special_index].type == OFFSET) {
6459 if (specials[special_index].arg > 0) {
6460 w += specials[special_index].arg;
6462 } else if (specials[special_index].type == VOFFSET) {
6463 last_font_height += specials[special_index].arg;
6464 } else if (specials[special_index].type == GOTO) {
6465 if (specials[special_index].arg > cur_x) {
6466 w = (int) specials[special_index].arg;
6468 } else if (specials[special_index].type == TAB) {
6469 int start = specials[special_index].arg;
6470 int step = specials[special_index].width;
6472 if (!step || step < 0) {
6475 w += step - (cur_x - text_start_x - start) % step;
6476 } else if (specials[special_index].type == FONT) {
6477 selected_font = specials[special_index].font_added;
6478 if (font_height() > last_font_height) {
6479 last_font_height = font_height();
6488 w += get_string_width(s);
6489 if (w > text_width) {
6492 if (text_width > maximum_width && maximum_width) {
6493 text_width = maximum_width;
6496 text_height += last_font_height;
6497 last_font_height = font_height();
6501 static inline void set_foreground_color(long c)
6504 XSetForeground(display, window.gc, c);
6508 static void draw_string(const char *s)
6510 int i, i2, pos, width_of_s;
6519 width_of_s = get_string_width(s);
6520 if (out_to_console) {
6522 fflush(stdout); /* output immediately, don't buffer */
6524 memset(tmpstring1, 0, text_buffer_size);
6525 memset(tmpstring2, 0, text_buffer_size);
6526 strncpy(tmpstring1, s, text_buffer_size - 1);
6530 snprintf(space, 2, " ");
6532 max = ((text_width - width_of_s) / get_string_width(space));
6534 /* This code looks for tabs in the text and coverts them to spaces.
6535 * The trick is getting the correct number of spaces, and not going
6536 * over the window's size without forcing the window larger. */
6537 for (i = 0; i < (int)text_buffer_size; i++) {
6538 if (tmpstring1[i] == '\t') { // 9 is ascii tab
6540 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
6541 /* guard against overrun */
6542 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
6547 if (tmpstring1[i] != 9) {
6548 /* guard against overrun */
6549 tmpstring2[MIN(pos, (int)text_buffer_size - 1)] = tmpstring1[i];
6555 if (text_width == maximum_width) {
6556 /* this means the text is probably pushing the limit,
6557 * so we'll chop it */
6558 while (cur_x + get_string_width(tmpstring2) - text_start_x
6559 > maximum_width && strlen(tmpstring2) > 0) {
6560 tmpstring2[strlen(tmpstring2) - 1] = '\0';
6571 c.pixel = current_color;
6572 XQueryColor(display, DefaultColormap(display, screen), &c);
6575 c2.color.red = c.red;
6576 c2.color.green = c.green;
6577 c2.color.blue = c.blue;
6578 c2.color.alpha = fonts[selected_font].font_alpha;
6580 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6581 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6583 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6584 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6589 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
6592 cur_x += width_of_s;
6594 memcpy(tmpstring1, s, text_buffer_size);
6597 long redmask, greenmask, bluemask;
6599 void set_up_gradient(void)
6603 colour_depth = DisplayPlanes(display, screen);
6607 if (colour_depth != 24 && colour_depth != 16) {
6608 ERR("using non-standard colour depth, gradients may look like a "
6615 for (i = (colour_depth / 3) - 1; i >= 0; i--) {
6617 greenmask |= 1 << i;
6620 if (colour_depth % 3 == 1) {
6621 greenmask |= 1 << (colour_depth / 3);
6623 redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
6624 greenmask = greenmask << (colour_depth / 3);
6627 /* this function returns the next colour between two colours for a gradient */
6628 inline unsigned long do_gradient(unsigned long first_colour,
6629 unsigned long last_colour)
6632 int red1, green1, blue1; // first colour
6633 int red2, green2, blue2; // second colour
6634 int red3 = 0, green3 = 0, blue3 = 0; // difference
6635 short redshift = (2 * colour_depth / 3 + colour_depth % 3);
6636 short greenshift = (colour_depth / 3);
6638 red1 = (first_colour & redmask) >> redshift;
6639 green1 = (first_colour & greenmask) >> greenshift;
6640 blue1 = first_colour & bluemask;
6641 red2 = (last_colour & redmask) >> redshift;
6642 green2 = (last_colour & greenmask) >> greenshift;
6643 blue2 = last_colour & bluemask;
6650 if (green1 > green2) {
6653 if (green1 < green2) {
6656 if (blue1 > blue2) {
6659 if (blue1 < blue2) {
6674 if (red1 > bluemask) {
6677 if (green1 > bluemask) {
6680 if (blue1 > bluemask) {
6683 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
6687 /* this function returns the max diff for a gradient */
6688 inline unsigned long gradient_max(unsigned long first_colour,
6689 unsigned long last_colour)
6691 int red1, green1, blue1; // first colour
6692 int red2, green2, blue2; // second colour
6693 int red3 = 0, green3 = 0, blue3 = 0; // difference
6694 long redshift, greenshift;
6697 if (colour_depth == 0) {
6700 redshift = (2 * colour_depth / 3 + colour_depth % 3);
6701 greenshift = (colour_depth / 3);
6703 red1 = (first_colour & redmask) >> redshift;
6704 green1 = (first_colour & greenmask) >> greenshift;
6705 blue1 = first_colour & bluemask;
6706 red2 = (last_colour & redmask) >> redshift;
6707 green2 = (last_colour & greenmask) >> greenshift;
6708 blue2 = last_colour & bluemask;
6709 red3 = abs(red1 - red2);
6710 green3 = abs(green1 - green2);
6711 blue3 = abs(blue1 - blue2);
6723 static void draw_line(char *s)
6730 cur_x = text_start_x;
6731 cur_y += font_ascent();
6732 font_h = font_height();
6734 /* find specials and draw stuff */
6737 if (*p == SPECIAL_CHAR) {
6740 /* draw string before special */
6747 switch (specials[special_index].type) {
6748 case HORIZONTAL_LINE:
6750 int h = specials[special_index].height;
6751 int mid = font_ascent() / 2;
6753 w = text_start_x + text_width - cur_x;
6755 XSetLineAttributes(display, window.gc, h, LineSolid,
6756 CapButt, JoinMiter);
6757 XDrawLine(display, window.drawable, window.gc, cur_x,
6758 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6764 int h = specials[special_index].height;
6765 int tmp_s = specials[special_index].arg;
6766 int mid = font_ascent() / 2;
6767 char ss[2] = { tmp_s, tmp_s };
6769 w = text_start_x + text_width - cur_x - 1;
6770 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6771 CapButt, JoinMiter);
6772 XSetDashes(display, window.gc, 0, ss, 2);
6773 XDrawLine(display, window.drawable, window.gc, cur_x,
6774 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6780 int h, bar_usage, by;
6781 if (cur_x - text_start_x > maximum_width
6782 && maximum_width > 0) {
6785 h = specials[special_index].height;
6786 bar_usage = specials[special_index].arg;
6787 by = cur_y - (font_ascent() / 2) - 1;
6789 if (h < font_height()) {
6792 w = specials[special_index].width;
6794 w = text_start_x + text_width - cur_x - 1;
6800 XSetLineAttributes(display, window.gc, 1, LineSolid,
6801 CapButt, JoinMiter);
6803 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6805 XFillRectangle(display, window.drawable, window.gc, cur_x,
6806 by, w * bar_usage / 255, h);
6807 if (specials[special_index].height > cur_y_add
6808 && specials[special_index].height > font_h) {
6809 cur_y_add = specials[special_index].height;
6816 int h, by, i, j = 0;
6817 int gradient_size = 0;
6818 float gradient_factor = 0;
6819 float gradient_update = 0;
6820 unsigned long last_colour = current_color;
6821 unsigned long tmpcolour = current_color;
6822 if (cur_x - text_start_x > maximum_width
6823 && maximum_width > 0) {
6826 h = specials[special_index].height;
6827 by = cur_y - (font_ascent() / 2) - 1;
6829 if (h < font_height()) {
6832 w = specials[special_index].width;
6834 w = text_start_x + text_width - cur_x - 1;
6839 if (draw_graph_borders) {
6840 XSetLineAttributes(display, window.gc, 1, LineSolid,
6841 CapButt, JoinMiter);
6842 XDrawRectangle(display, window.drawable, window.gc,
6845 XSetLineAttributes(display, window.gc, 1, LineSolid,
6846 CapButt, JoinMiter);
6848 if (specials[special_index].last_colour != 0
6849 || specials[special_index].first_colour != 0) {
6850 tmpcolour = specials[special_index].last_colour;
6852 gradient_max(specials[special_index].last_colour,
6853 specials[special_index].first_colour);
6854 gradient_factor = (float) gradient_size / (w - 2);
6856 for (i = w - 2; i > -1; i--) {
6857 if (specials[special_index].last_colour != 0
6858 || specials[special_index].first_colour != 0) {
6859 XSetForeground(display, window.gc, tmpcolour);
6860 gradient_update += gradient_factor;
6861 while (gradient_update > 0) {
6862 tmpcolour = do_gradient(tmpcolour,
6863 specials[special_index].first_colour);
6867 if ((w - i) / ((float) (w - 2) /
6868 (specials[special_index].graph_width)) > j
6869 && j < MAX_GRAPH_DEPTH - 3) {
6872 /* this is mugfugly, but it works */
6873 XDrawLine(display, window.drawable, window.gc,
6874 cur_x + i + 1, by + h, cur_x + i + 1,
6875 by + h - specials[special_index].graph[j] *
6876 (h - 1) / specials[special_index].graph_scale);
6878 if (specials[special_index].height > cur_y_add
6879 && specials[special_index].height > font_h) {
6880 cur_y_add = specials[special_index].height;
6882 /* if (draw_mode == BG) {
6883 set_foreground_color(default_bg_color);
6884 } else if (draw_mode == OUTLINE) {
6885 set_foreground_color(default_out_color);
6887 set_foreground_color(default_fg_color);
6889 set_foreground_color(last_colour);
6895 int old = font_ascent();
6897 cur_y -= font_ascent();
6898 selected_font = specials[special_index].font_added;
6899 if (cur_y + font_ascent() < cur_y + old) {
6902 cur_y += font_ascent();
6908 if (draw_mode == FG) {
6909 set_foreground_color(specials[special_index].arg);
6914 if (draw_mode == BG) {
6915 set_foreground_color(specials[special_index].arg);
6920 if (draw_mode == OUTLINE) {
6921 set_foreground_color(specials[special_index].arg);
6926 w += specials[special_index].arg;
6930 cur_y += specials[special_index].arg;
6934 if (specials[special_index].arg >= 0) {
6935 cur_x = (int) specials[special_index].arg;
6941 int start = specials[special_index].arg;
6942 int step = specials[special_index].width;
6944 if (!step || step < 0) {
6947 w = step - (cur_x - text_start_x - start) % step;
6953 /* TODO: add back in "+ border_margin" to the end of
6955 int pos_x = text_start_x + text_width -
6956 get_string_width_special(s);
6958 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6959 "get_string_width(p) %i gap_x %i "
6960 "specials[special_index].arg %i border_margin %i "
6961 "border_width %i\n", pos_x, text_start_x, text_width,
6962 cur_x, get_string_width_special(s), gap_x,
6963 specials[special_index].arg, border_margin,
6965 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6966 cur_x = pos_x - specials[special_index].arg;
6973 int pos_x = (text_width) / 2 - get_string_width_special(s) /
6974 2 - (cur_x - text_start_x);
6975 /* int pos_x = text_start_x + text_width / 2 -
6976 get_string_width_special(s) / 2; */
6978 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6979 "get_string_width(p) %i gap_x %i "
6980 "specials[special_index].arg %i\n", pos_x, text_start_x,
6981 text_width, cur_x, get_string_width(s), gap_x,
6982 specials[special_index].arg); */
6983 if (pos_x > specials[special_index].arg) {
6984 w = pos_x - specials[special_index].arg;
7001 if (cur_y_add > 0) {
7003 cur_y -= font_descent();
7008 cur_y += font_descent();
7012 static void draw_text(void)
7015 cur_y = text_start_y;
7018 if (draw_borders && border_width > 0) {
7019 unsigned int b = (border_width + 1) / 2;
7021 if (stippled_borders) {
7022 char ss[2] = { stippled_borders, stippled_borders };
7023 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
7024 CapButt, JoinMiter);
7025 XSetDashes(display, window.gc, 0, ss, 2);
7027 XSetLineAttributes(display, window.gc, border_width, LineSolid,
7028 CapButt, JoinMiter);
7031 XDrawRectangle(display, window.drawable, window.gc,
7032 text_start_x - border_margin + b, text_start_y - border_margin + b,
7033 text_width + border_margin * 2 - 1 - b * 2,
7034 text_height + border_margin * 2 - 1 - b * 2);
7040 for_each_line(text_buffer, draw_line);
7043 static void draw_stuff(void)
7047 if (draw_shades && !draw_outline) {
7050 set_foreground_color(default_bg_color);
7061 for (i = -1; i < 2; i++) {
7062 for (j = -1; j < 2; j++) {
7063 if (i == 0 && j == 0) {
7068 set_foreground_color(default_out_color);
7069 draw_mode = OUTLINE;
7077 set_foreground_color(default_fg_color);
7086 swap.swap_window = window.window;
7087 swap.swap_action = XdbeBackground;
7088 XdbeSwapBuffers(display, &swap, 1);
7095 static void clear_text(int exposures)
7099 /* The swap action is XdbeBackground, which clears */
7104 /* there is some extra space for borders and outlines */
7105 XClearArea(display, window.window, text_start_x - border_margin - 1,
7106 text_start_y - border_margin - 1,
7107 text_width + border_margin * 2 + 2,
7108 text_height + border_margin * 2 + 2, exposures ? True : 0);
7113 static int need_to_update;
7115 /* update_text() generates new text and clears old text area */
7116 static void update_text(void)
7125 static void main_loop(void)
7127 #ifdef SIGNAL_BLOCKING
7128 sigset_t newmask, oldmask;
7131 Region region = XCreateRegion();
7135 XserverRegion region2, part;
7136 int event_base, error_base;
7138 if (!XDamageQueryExtension(display, &event_base, &error_base)) {
7139 ERR("Xdamage extension unavailable");
7141 damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7142 region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7143 part = XFixesCreateRegionFromWindow(display, window.window, 0);
7144 #endif /* HAVE_XDAMAGE */
7147 #ifdef SIGNAL_BLOCKING
7148 sigemptyset(&newmask);
7149 sigaddset(&newmask, SIGINT);
7150 sigaddset(&newmask, SIGTERM);
7151 sigaddset(&newmask, SIGUSR1);
7155 while (total_run_times == 0 || info.looped < total_run_times) {
7158 #ifdef SIGNAL_BLOCKING
7159 /* block signals. we will inspect for pending signals later */
7160 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
7161 CRIT_ERR("unable to sigprocmask()");
7168 /* wait for X event or timeout */
7170 if (!XPending(display)) {
7174 double t = update_interval - (get_time() - last_update_time);
7180 tv.tv_sec = (long) t;
7181 tv.tv_usec = (long) (t * 1000000) % 1000000;
7183 FD_SET(ConnectionNumber(display), &fdsr);
7185 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
7187 if (errno != EINTR) {
7188 ERR("can't select(): %s", strerror(errno));
7194 /* FIXME just sleep for the interval time if no X11 */
7195 usleep(update_interval * 1000000);
7203 if (need_to_update) {
7205 int wx = window.x, wy = window.y;
7213 /* resize window if it isn't right size */
7215 && (text_width + border_margin * 2 + 1 != window.width
7216 || text_height + border_margin * 2 + 1 != window.height)) {
7217 window.width = text_width + border_margin * 2 + 1;
7218 window.height = text_height + border_margin * 2 + 1;
7219 XResizeWindow(display, window.window, window.width,
7222 set_transparent_background(window.window);
7226 /* move window if it isn't in right position */
7227 if (!fixed_pos && (window.x != wx || window.y != wy)) {
7228 XMoveWindow(display, window.window, window.x, window.y);
7239 r.x = text_start_x - border_margin;
7240 r.y = text_start_y - border_margin;
7241 r.width = text_width + border_margin * 2;
7242 r.height = text_height + border_margin * 2;
7243 XUnionRectWithRegion(&r, region, region);
7248 /* handle X events */
7249 while (XPending(display)) {
7252 XNextEvent(display, &ev);
7260 r.width = ev.xexpose.width;
7261 r.height = ev.xexpose.height;
7262 XUnionRectWithRegion(&r, region, region);
7267 case ReparentNotify:
7268 /* set background to ParentRelative for all parents */
7270 set_transparent_background(window.window);
7274 case ConfigureNotify:
7276 /* if window size isn't what expected, set fixed size */
7277 if (ev.xconfigure.width != window.width
7278 || ev.xconfigure.height != window.height) {
7279 if (window.width != 0 && window.height != 0) {
7283 /* clear old stuff before screwing up
7288 XWindowAttributes attrs;
7290 if (XGetWindowAttributes(display,
7291 window.window, &attrs)) {
7292 window.width = attrs.width;
7293 window.height = attrs.height;
7297 text_width = window.width - border_margin * 2 - 1;
7298 text_height = window.height - border_margin * 2 - 1;
7299 if (text_width > maximum_width
7300 && maximum_width > 0) {
7301 text_width = maximum_width;
7305 /* if position isn't what expected, set fixed pos
7306 * total_updates avoids setting fixed_pos when window
7307 * is set to weird locations when started */
7308 /* // this is broken
7309 if (total_updates >= 2 && !fixed_pos
7310 && (window.x != ev.xconfigure.x
7311 || window.y != ev.xconfigure.y)
7312 && (ev.xconfigure.x != 0
7313 || ev.xconfigure.y != 0)) {
7322 /* if an ordinary window with decorations */
7323 if ((window.type == TYPE_NORMAL)
7324 && (!TEST_HINT(window.hints,
7325 HINT_UNDECORATED))) {
7326 /* allow conky to hold input focus. */
7329 /* forward the click to the desktop window */
7330 XUngrabPointer(display, ev.xbutton.time);
7331 ev.xbutton.window = window.desktop;
7332 XSendEvent(display, ev.xbutton.window, False,
7333 ButtonPressMask, &ev);
7334 XSetInputFocus(display, ev.xbutton.window,
7335 RevertToParent, ev.xbutton.time);
7342 /* if an ordinary window with decorations */
7343 if ((window.type == TYPE_NORMAL)
7344 && (!TEST_HINT(window.hints,
7345 HINT_UNDECORATED))) {
7346 /* allow conky to hold input focus. */
7349 /* forward the release to the desktop window */
7350 ev.xbutton.window = window.desktop;
7351 XSendEvent(display, ev.xbutton.window, False,
7352 ButtonReleaseMask, &ev);
7361 if (ev.type == event_base + XDamageNotify) {
7362 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
7364 XFixesSetRegion(display, part, &dev->area, 1);
7365 XFixesUnionRegion(display, region2, region2, part);
7367 #endif /* HAVE_XDAMAGE */
7373 XDamageSubtract(display, damage, region2, None);
7374 XFixesSetRegion(display, region2, 0, 0);
7375 #endif /* HAVE_XDAMAGE */
7377 /* XDBE doesn't seem to provide a way to clear the back buffer without
7378 * interfering with the front buffer, other than passing XdbeBackground
7379 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
7380 * redraw the text even if it wasn't part of the exposed area. OTOH,
7381 * if we're not going to call draw_stuff at all, then no swap happens
7382 * and we can safely do nothing. */
7384 if (!XEmptyRegion(region)) {
7389 r.x = text_start_x - border_margin;
7390 r.y = text_start_y - border_margin;
7391 r.width = text_width + border_margin * 2;
7392 r.height = text_height + border_margin * 2;
7393 XUnionRectWithRegion(&r, region, region);
7396 XSetRegion(display, window.gc, region);
7399 XftDrawSetClip(window.xftdraw, region);
7405 XDestroyRegion(region);
7406 region = XCreateRegion();
7410 #ifdef SIGNAL_BLOCKING
7411 /* unblock signals of interest and let handler fly */
7412 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
7413 CRIT_ERR("unable to sigprocmask()");
7417 switch (g_signal_pending) {
7420 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
7425 ERR("received SIGINT or SIGTERM to terminate. bye!");
7428 XDestroyRegion(region);
7431 XDamageDestroy(display, damage);
7432 XFixesDestroyRegion(display, region2);
7433 XFixesDestroyRegion(display, part);
7434 #endif /* HAVE_XDAMAGE */
7436 return; /* return from main_loop */
7439 /* Reaching here means someone set a signal
7440 * (SIGXXXX, signal_handler), but didn't write any code
7442 * If you don't want to handle a signal, don't set a handler on
7443 * it in the first place. */
7444 if (g_signal_pending) {
7445 ERR("ignoring signal (%d)", g_signal_pending);
7449 g_signal_pending = 0;
7452 #if defined(X11) && defined(HAVE_XDAMAGE)
7453 XDamageDestroy(display, damage);
7454 XFixesDestroyRegion(display, region2);
7455 XFixesDestroyRegion(display, part);
7456 XDestroyRegion(region);
7458 #endif /* X11 && HAVE_XDAMAGE */
7461 static void load_config_file(const char *);
7463 /* reload the config file */
7464 void reload_config(void)
7466 timed_thread_destroy_registered_threads();
7468 if (info.cpu_usage) {
7469 free(info.cpu_usage);
7470 info.cpu_usage = NULL;
7478 if (info.mpd.title) {
7479 free(info.mpd.title);
7480 info.mpd.title = NULL;
7482 if (info.mpd.artist) {
7483 free(info.mpd.artist);
7484 info.mpd.artist = NULL;
7486 if (info.mpd.album) {
7487 free(info.mpd.album);
7488 info.mpd.album = NULL;
7490 if (info.mpd.random) {
7491 free(info.mpd.random);
7492 info.mpd.random = NULL;
7494 if (info.mpd.repeat) {
7495 free(info.mpd.repeat);
7496 info.mpd.repeat = NULL;
7498 if (info.mpd.track) {
7499 free(info.mpd.track);
7500 info.mpd.track = NULL;
7502 if (info.mpd.name) {
7503 free(info.mpd.name);
7504 info.mpd.name = NULL;
7506 if (info.mpd.file) {
7507 free(info.mpd.file);
7508 info.mpd.file = NULL;
7510 if (info.mpd.status) {
7511 free(info.mpd.status);
7512 info.mpd.status = NULL;
7522 #ifdef TCP_PORT_MONITOR
7523 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7526 if (current_config) {
7528 load_config_file(current_config);
7530 /* re-init specials array */
7531 if ((specials = realloc((void *) specials,
7532 sizeof(struct special_t) * max_specials)) == 0) {
7533 ERR("failed to realloc specials array");
7537 // clear the window first
7538 XClearWindow(display, RootWindow(display, screen));
7541 #ifdef TCP_PORT_MONITOR
7542 info.p_tcp_port_monitor_collection = NULL;
7544 extract_variable_text(text);
7550 tmpstring1 = malloc(text_buffer_size);
7551 memset(tmpstring1, 0, text_buffer_size);
7555 tmpstring2 = malloc(text_buffer_size);
7556 memset(tmpstring2, 0, text_buffer_size);
7560 text_buffer = malloc(max_user_text);
7561 memset(text_buffer, 0, max_user_text);
7568 timed_thread_destroy_registered_threads();
7570 if (info.cpu_usage) {
7571 free(info.cpu_usage);
7572 info.cpu_usage = NULL;
7577 XdbeDeallocateBackBufferName(display, window.back_buffer);
7582 XDestroyWindow(display, window.window);
7583 XClearWindow(display, RootWindow(display, screen));
7588 XClearWindow(display, RootWindow(display, screen));
7593 XFreeGC(display, window.gc);
7597 free_text_objects(global_text_object_count, global_text_objects);
7610 global_text_object_count = 0;
7611 global_text_objects = NULL;
7618 free(current_config);
7620 #ifdef TCP_PORT_MONITOR
7621 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7622 info.p_tcp_port_monitor_collection = NULL;
7631 for (i = 0; i < special_count; i++) {
7632 if (specials[i].type == GRAPH) {
7633 free(specials[i].graph);
7640 clear_diskio_stats();
7643 static int string_to_bool(const char *s)
7647 } else if (strcasecmp(s, "yes") == 0) {
7649 } else if (strcasecmp(s, "true") == 0) {
7651 } else if (strcasecmp(s, "1") == 0) {
7658 static enum alignment string_to_alignment(const char *s)
7660 if (strcasecmp(s, "top_left") == 0) {
7662 } else if (strcasecmp(s, "top_right") == 0) {
7664 } else if (strcasecmp(s, "top_middle") == 0) {
7666 } else if (strcasecmp(s, "bottom_left") == 0) {
7668 } else if (strcasecmp(s, "bottom_right") == 0) {
7669 return BOTTOM_RIGHT;
7670 } else if (strcasecmp(s, "bottom_middle") == 0) {
7671 return BOTTOM_MIDDLE;
7672 } else if (strcasecmp(s, "middle_left") == 0) {
7674 } else if (strcasecmp(s, "middle_right") == 0) {
7675 return MIDDLE_RIGHT;
7676 } else if (strcasecmp(s, "tl") == 0) {
7678 } else if (strcasecmp(s, "tr") == 0) {
7680 } else if (strcasecmp(s, "tm") == 0) {
7682 } else if (strcasecmp(s, "bl") == 0) {
7684 } else if (strcasecmp(s, "br") == 0) {
7685 return BOTTOM_RIGHT;
7686 } else if (strcasecmp(s, "bm") == 0) {
7687 return BOTTOM_MIDDLE;
7688 } else if (strcasecmp(s, "ml") == 0) {
7690 } else if (strcasecmp(s, "mr") == 0) {
7691 return MIDDLE_RIGHT;
7692 } else if (strcasecmp(s, "none") == 0) {
7699 static void set_default_configurations(void)
7701 fork_to_background = 0;
7702 total_run_times = 0;
7703 info.cpu_avg_samples = 2;
7704 info.net_avg_samples = 2;
7711 strcpy(info.mpd.host, "localhost");
7712 info.mpd.port = 6600;
7713 info.mpd.status = NULL;
7714 info.mpd.artist = NULL;
7715 info.mpd.album = NULL;
7716 info.mpd.title = NULL;
7717 info.mpd.random = NULL;
7718 info.mpd.track = NULL;
7719 info.mpd.name = NULL;
7720 info.mpd.file = NULL;
7723 info.xmms2.artist = NULL;
7724 info.xmms2.album = NULL;
7725 info.xmms2.title = NULL;
7726 info.xmms2.genre = NULL;
7727 info.xmms2.comment = NULL;
7728 info.xmms2.url = NULL;
7729 info.xmms2.status = NULL;
7730 info.xmms2.playlist = NULL;
7732 use_spacer = NO_SPACER;
7739 default_fg_color = WhitePixel(display, screen);
7740 default_bg_color = BlackPixel(display, screen);
7741 default_out_color = BlackPixel(display, screen);
7742 color0 = default_fg_color;
7743 color1 = default_fg_color;
7744 color2 = default_fg_color;
7745 color3 = default_fg_color;
7746 color4 = default_fg_color;
7747 color5 = default_fg_color;
7748 color6 = default_fg_color;
7749 color7 = default_fg_color;
7750 color8 = default_fg_color;
7751 color9 = default_fg_color;
7754 draw_graph_borders = 1;
7756 set_first_font("6x10");
7764 window.type = TYPE_NORMAL;
7766 strcpy(window.class_name, "Conky");
7768 sprintf(window.title, "Conky (%s)", info.uname_s.nodename);
7770 stippled_borders = 0;
7773 text_alignment = BOTTOM_LEFT;
7776 free(current_mail_spool);
7780 variable_substitute(MAIL_FILE, buf, 256);
7781 if (buf[0] != '\0') {
7782 current_mail_spool = strndup(buf, text_buffer_size);
7787 update_interval = 3.0;
7788 info.music_player_interval = 1.0;
7789 stuff_in_upper_case = 0;
7790 info.users.number = 1;
7792 #ifdef TCP_PORT_MONITOR
7793 tcp_port_monitor_args.max_port_monitor_connections =
7794 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7798 static void load_config_file(const char *f)
7800 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7804 set_default_configurations();
7811 char buf[256], *p, *p2, *name, *value;
7814 if (fgets(buf, 256, fp) == NULL) {
7820 /* break at comment */
7821 p2 = strchr(p, '#');
7827 while (*p && isspace((int) *p)) {
7831 continue; /* empty line */
7838 while (*p2 && !isspace((int) *p2)) {
7842 *p2 = '\0'; /* break at name's end */
7849 while (*p && isspace((int) *p)) {
7855 p2 = value + strlen(value);
7856 while (isspace((int) *(p2 - 1))) {
7863 #define CONF2(a) if (strcasecmp(name, a) == 0)
7864 #define CONF(a) else CONF2(a)
7865 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7866 || strcasecmp(name, b) == 0)
7869 CONF2("alignment") {
7871 int a = string_to_alignment(value);
7882 CONF("background") {
7883 fork_to_background = string_to_bool(value);
7886 CONF2("background") {
7887 fork_to_background = string_to_bool(value);
7891 CONF("border_margin") {
7893 border_margin = strtol(value, 0, 0);
7898 CONF("border_width") {
7900 border_width = strtol(value, 0, 0);
7907 color0 = get_x11_color(value);
7914 color1 = get_x11_color(value);
7921 color2 = get_x11_color(value);
7928 color3 = get_x11_color(value);
7935 color4 = get_x11_color(value);
7942 color5 = get_x11_color(value);
7949 color6 = get_x11_color(value);
7956 color7 = get_x11_color(value);
7963 color8 = get_x11_color(value);
7970 color9 = get_x11_color(value);
7975 CONF("default_color") {
7977 default_fg_color = get_x11_color(value);
7982 CONF3("default_shade_color", "default_shadecolor") {
7984 default_bg_color = get_x11_color(value);
7989 CONF3("default_outline_color", "default_outlinecolor") {
7991 default_out_color = get_x11_color(value);
7999 info.mail = parse_mail_args(IMAP, value);
8006 info.mail = parse_mail_args(POP3, value);
8014 strncpy(info.mpd.host, value, 127);
8021 info.mpd.port = strtol(value, 0, 0);
8022 if (info.mpd.port < 1 || info.mpd.port > 0xffff) {
8027 CONF("mpd_password") {
8029 strncpy(info.mpd.password, value, 127);
8035 CONF("music_player_interval") {
8037 info.music_player_interval = strtod(value, 0);
8043 CONF("sensor_device") {
8045 sensor_device = strtol(value, 0, 0);
8051 CONF("cpu_avg_samples") {
8053 cpu_avg_samples = strtol(value, 0, 0);
8054 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
8057 info.cpu_avg_samples = cpu_avg_samples;
8063 CONF("net_avg_samples") {
8065 net_avg_samples = strtol(value, 0, 0);
8066 if (net_avg_samples < 1 || net_avg_samples > 14) {
8069 info.net_avg_samples = net_avg_samples;
8077 CONF("double_buffer") {
8078 use_xdbe = string_to_bool(value);
8082 CONF("override_utf8_locale") {
8083 utf8_mode = string_to_bool(value);
8085 CONF("draw_borders") {
8086 draw_borders = string_to_bool(value);
8088 CONF("draw_graph_borders") {
8089 draw_graph_borders = string_to_bool(value);
8091 CONF("draw_shades") {
8092 draw_shades = string_to_bool(value);
8094 CONF("draw_outline") {
8095 draw_outline = string_to_bool(value);
8098 CONF("out_to_console") {
8099 out_to_console = string_to_bool(value);
8101 CONF("use_spacer") {
8103 if (strcasecmp(value, "left") == 0) {
8104 use_spacer = LEFT_SPACER;
8105 } else if (strcasecmp(value, "right") == 0) {
8106 use_spacer = RIGHT_SPACER;
8107 } else if (strcasecmp(value, "none") == 0) {
8108 use_spacer = NO_SPACER;
8110 use_spacer = string_to_bool(value);
8111 ERR("use_spacer should have an argument of left, right, or"
8112 " none. '%s' seems to be some form of '%s', so"
8113 " defaulting to %s.", value,
8114 use_spacer ? "true" : "false",
8115 use_spacer ? "right" : "none");
8117 use_spacer = RIGHT_SPACER;
8119 use_spacer = NO_SPACER;
8123 ERR("use_spacer should have an argument. Defaulting to right.");
8124 use_spacer = RIGHT_SPACER;
8130 use_xft = string_to_bool(value);
8134 set_first_font(value);
8140 if (value && font_count >= 0) {
8141 fonts[0].font_alpha = atof(value) * 65535.0;
8150 if (string_to_bool(value)) {
8151 ERR("Xft not enabled");
8155 /* xftfont silently ignored when no Xft */
8158 /* xftalpha is silently ignored when no Xft */
8163 set_first_font(value);
8173 gap_x = atoi(value);
8180 gap_y = atoi(value);
8186 CONF("mail_spool") {
8190 variable_substitute(value, buffer, 256);
8192 if (buffer[0] != '\0') {
8193 if (current_mail_spool) {
8194 free(current_mail_spool);
8196 current_mail_spool = strndup(buffer, text_buffer_size);
8203 CONF("minimum_size") {
8205 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
8207 if (sscanf(value, "%d", &minimum_width) != 1) {
8215 CONF("maximum_width") {
8217 if (sscanf(value, "%d", &maximum_width) != 1) {
8225 CONF("no_buffers") {
8226 no_buffers = string_to_bool(value);
8228 CONF("top_cpu_separate") {
8229 cpu_separate = string_to_bool(value);
8231 CONF("short_units") {
8232 short_units = string_to_bool(value);
8234 CONF("pad_percents") {
8235 pad_percents = atoi(value);
8239 CONF("own_window") {
8241 own_window = string_to_bool(value);
8246 CONF("own_window_class") {
8248 memset(window.class_name, 0, sizeof(window.class_name));
8249 strncpy(window.class_name, value,
8250 sizeof(window.class_name) - 1);
8255 CONF("own_window_title") {
8257 memset(window.title, 0, sizeof(window.title));
8258 strncpy(window.title, value, sizeof(window.title) - 1);
8263 CONF("own_window_transparent") {
8265 set_transparent = string_to_bool(value);
8270 CONF("own_window_colour") {
8272 background_colour = get_x11_color(value);
8274 ERR("Invalid colour for own_window_colour (try omitting the "
8275 "'#' for hex colours");
8278 CONF("own_window_hints") {
8280 char *p_hint, *p_save;
8281 char delim[] = ", ";
8283 /* tokenize the value into individual hints */
8284 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
8286 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
8287 if (strncmp(p_hint, "undecorate", 10) == 0) {
8288 SET_HINT(window.hints, HINT_UNDECORATED);
8289 } else if (strncmp(p_hint, "below", 5) == 0) {
8290 SET_HINT(window.hints, HINT_BELOW);
8291 } else if (strncmp(p_hint, "above", 5) == 0) {
8292 SET_HINT(window.hints, HINT_ABOVE);
8293 } else if (strncmp(p_hint, "sticky", 6) == 0) {
8294 SET_HINT(window.hints, HINT_STICKY);
8295 } else if (strncmp(p_hint, "skip_taskbar", 12) == 0) {
8296 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
8297 } else if (strncmp(p_hint, "skip_pager", 10) == 0) {
8298 SET_HINT(window.hints, HINT_SKIP_PAGER);
8303 p_hint = strtok_r(NULL, delim, &p_save);
8304 } while (p_hint != NULL);
8310 CONF("own_window_type") {
8312 if (strncmp(value, "normal", 6) == 0) {
8313 window.type = TYPE_NORMAL;
8314 } else if (strncmp(value, "desktop", 7) == 0) {
8315 window.type = TYPE_DESKTOP;
8316 } else if (strncmp(value, "override", 8) == 0) {
8317 window.type = TYPE_OVERRIDE;
8326 CONF("stippled_borders") {
8328 stippled_borders = strtol(value, 0, 0);
8330 stippled_borders = 4;
8335 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> "
8339 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> "
8342 CONF("update_interval") {
8344 update_interval = strtod(value, 0);
8348 if (info.music_player_interval == 0) {
8349 // default to update_interval
8350 info.music_player_interval = update_interval;
8353 CONF("total_run_times") {
8355 total_run_times = strtod(value, 0);
8361 stuff_in_upper_case = string_to_bool(value);
8363 CONF("max_specials") {
8365 max_specials = atoi(value);
8370 CONF("max_user_text") {
8372 max_user_text = atoi(value);
8377 CONF("text_buffer_size") {
8379 text_buffer_size = atoi(value);
8380 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
8381 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
8382 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
8394 text = (char *) malloc(1);
8398 unsigned int l = strlen(text);
8400 if (fgets(buf, 256, fp) == NULL) {
8403 text = (char *) realloc(text, l + strlen(buf) + 1);
8406 if (strlen(text) > max_user_text) {
8411 if (strlen(text) < 1) {
8412 CRIT_ERR("no text supplied in configuration; exiting");
8414 text_lines = line + 1;
8417 #ifdef TCP_PORT_MONITOR
8418 CONF("max_port_monitor_connections") {
8419 if (!value || (sscanf(value, "%d",
8420 &tcp_port_monitor_args.max_port_monitor_connections) != 1)
8421 || tcp_port_monitor_args.max_port_monitor_connections < 0) {
8422 /* an error. use default, warn and continue. */
8423 tcp_port_monitor_args.max_port_monitor_connections =
8424 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8426 } else if (tcp_port_monitor_args.max_port_monitor_connections
8428 /* no error, just use default */
8429 tcp_port_monitor_args.max_port_monitor_connections =
8430 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8432 /* else tcp_port_monitor_args.max_port_monitor_connections > 0
8437 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8448 if (info.music_player_interval == 0) {
8449 // default to update_interval
8450 info.music_player_interval = update_interval;
8452 if (!text) { // didn't supply any text
8453 CRIT_ERR("missing text block in configuration; exiting");
8457 /* : means that character before that takes an argument */
8458 static const char *getopt_string = "vVdt:u:i:hc:"
8470 static const struct option longopts[] = {
8471 { "help", 0, NULL, 'h' },
8472 { "version", 0, NULL, 'V' },
8473 { "config", 1, NULL, 'c' },
8474 { "daemonize", 0, NULL, 'd' },
8476 { "alignment", 1, NULL, 'a' },
8477 { "font", 1, NULL, 'f' },
8479 { "own-window", 0, NULL, 'o' },
8482 { "double-buffer", 0, NULL, 'b' },
8484 { "window-id", 1, NULL, 'w' },
8486 { "text", 1, NULL, 't' },
8487 { "interval", 0, NULL, 'u' },
8491 int main(int argc, char **argv)
8497 struct sigaction act, oact;
8499 g_signal_pending = 0;
8500 memset(&info, 0, sizeof(info));
8502 #ifdef TCP_PORT_MONITOR
8503 tcp_port_monitor_args.max_port_monitor_connections =
8504 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8507 /* handle command line parameters that don't change configs */
8509 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8510 || ((s = getenv("LANG")) && *s)) {
8511 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8513 ERR("malloc failed");
8515 for (x = 0; x < strlen(s); x++) {
8516 temp[x] = tolower(s[x]);
8519 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8525 if (!setlocale(LC_CTYPE, "")) {
8526 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8530 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8541 if (current_config) {
8542 free(current_config);
8544 current_config = strndup(optarg, max_user_text);
8548 printf("Usage: %s [OPTION]...\n"
8549 "Conky is a system monitor that renders text on desktop or to own transparent\n"
8550 "window. Command line options will override configurations defined in config\n"
8552 " -v, --version version\n"
8553 " -c, --config=FILE config file to load\n"
8554 " -d, --daemonize daemonize, fork to background\n"
8555 " -h, --help help\n"
8557 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
8558 " -f, --font=FONT font to use\n"
8560 " -o, --own-window create own window to draw\n"
8563 " -b, --double-buffer double buffer (prevents flickering)\n"
8565 " -w, --window-id=WIN_ID window id to draw\n"
8566 " -x X x position\n"
8567 " -y Y y position\n"
8569 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8570 " -u, --interval=SECS update interval\n"
8571 " -i COUNT number of times to update Conky (and quit)\n",
8577 window.window = strtol(optarg, 0, 0);
8586 /* initalize X BEFORE we load config.
8587 * (we need to so that 'screen' is set) */
8591 /* check if specified config file is valid */
8592 if (current_config) {
8594 if (stat(current_config, &sb) ||
8595 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8596 ERR("invalid configuration file '%s'\n", current_config);
8597 free(current_config);
8602 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8604 if (!current_config) {
8605 /* load default config file */
8609 /* Try to use personal config file first */
8610 variable_substitute(CONFIG_FILE, buf, sizeof(buf));
8611 if (buf[0] && (fp = fopen(buf, "r"))) {
8612 current_config = strndup(buf, max_user_text);
8616 /* Try to use system config file if personal config not readable */
8617 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8618 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
8622 /* No readable config found */
8623 if (!current_config) {
8624 CRIT_ERR("no readable personal or system-wide config file found");
8628 load_config_file(current_config);
8630 /* init specials array */
8631 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8632 ERR("failed to create specials array");
8636 if (current_mail_spool == NULL) {
8639 variable_substitute(MAIL_FILE, buf, 256);
8641 if (buf[0] != '\0') {
8642 current_mail_spool = strndup(buf, text_buffer_size);
8647 /* handle other command line arguments */
8649 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8650 || defined(__NetBSD__)
8651 optind = optreset = 1;
8656 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8657 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8658 "kvm_open")) == NULL) {
8659 CRIT_ERR("cannot read kvm");
8664 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8672 fork_to_background = 1;
8677 set_first_font(optarg);
8680 text_alignment = string_to_alignment(optarg);
8699 text = strndup(optarg, max_user_text);
8700 convert_escapes(text);
8704 update_interval = strtod(optarg, 0);
8705 if (info.music_player_interval == 0) {
8706 // default to update_interval
8707 info.music_player_interval = update_interval;
8712 total_run_times = strtod(optarg, 0);
8716 gap_x = atoi(optarg);
8720 gap_y = atoi(optarg);
8734 /* generate text and get initial size */
8735 extract_variable_text(text);
8742 if (fork_to_background) {
8747 ERR("Conky: couldn't fork() to background: %s",
8754 fprintf(stderr, "\n");
8759 /* parent process */
8760 fprintf(stderr, "Conky: forked to background, pid is %d\n",
8767 text_buffer = malloc(max_user_text);
8768 memset(text_buffer, 0, max_user_text);
8769 tmpstring1 = malloc(text_buffer_size);
8770 memset(tmpstring1, 0, text_buffer_size);
8771 tmpstring2 = malloc(text_buffer_size);
8772 memset(tmpstring2, 0, text_buffer_size);
8776 update_text_area(); /* to get initial size of the window */
8779 init_window(own_window, text_width + border_margin * 2 + 1,
8780 text_height + border_margin * 2 + 1, set_transparent, background_colour,
8782 #else /* OWN_WINDOW */
8783 init_window(0, text_width + border_margin * 2 + 1,
8784 text_height + border_margin * 2 + 1, set_transparent, 0,
8786 #endif /* OWN_WINDOW */
8789 update_text_area(); /* to position text/window on screen */
8794 if (own_window && !fixed_pos) {
8795 XMoveWindow(display, window.window, window.x, window.y);
8798 set_transparent_background(window.window);
8808 /* Set signal handlers */
8809 act.sa_handler = signal_handler;
8810 sigemptyset(&act.sa_mask);
8813 act.sa_flags |= SA_RESTART;
8816 if (sigaction(SIGINT, &act, &oact) < 0
8817 || sigaction(SIGUSR1, &act, &oact) < 0
8818 || sigaction(SIGHUP,&act,&oact) < 0
8819 || sigaction(SIGTERM, &act, &oact) < 0) {
8820 ERR("error setting signal handler: %s", strerror(errno));
8823 /* *************** *
8825 * *************** */
8828 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8835 void signal_handler(int sig)
8837 /* signal handler is light as a feather, as it should be.
8838 * we will poll g_signal_pending with each loop of conky
8839 * and do any signal processing there, NOT here. */
8840 g_signal_pending = sig;