1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10 * Copyright (c) 2005-2008 Brenden Matthews, Philip Kovacs, et. al.
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
44 #include <X11/Xutil.h>
46 #include <X11/extensions/Xdamage.h>
52 #include <sys/types.h>
54 #include <netinet/in.h>
66 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
69 #define CONFIG_FILE "$HOME/.conkyrc"
70 #define MAIL_FILE "$MAIL"
71 #define MAX_IF_BLOCK_DEPTH 5
72 #define MAX_TAIL_LINES 100
74 /* #define SIGNAL_BLOCKING */
75 #undef SIGNAL_BLOCKING
77 static void print_version(void) __attribute__((noreturn));
79 static void print_version(void)
81 printf("Conky %s compiled %s for %s\n", VERSION, BUILD_DATE, BUILD_ARCH);
83 printf("\nCompiled in features:\n\n"
84 "System config file: %s\n\n"
88 " * Xdamage extension\n"
89 # endif /* HAVE_XDAMAGE */
91 " * Xdbe extension (double buffer)\n"
92 # endif /* HAVE_XDBE */
97 "\n Music detection:\n"
100 #endif /* AUDACIOUS */
110 "\n General features:\n"
114 #ifdef TCP_PORT_MONITOR
116 #endif /* TCP_PORT_MONITOR */
122 #endif /* HAVE_IWLIB */
129 "", SYSTEM_CONFIG_FILE
135 static const char *suffixes[] = { "B", "kiB", "MiB", "GiB", "TiB", "PiB", "" };
141 static int text_start_x, text_start_y; /* text start position in window */
142 static int text_width, text_height;
160 char name[DEFAULT_TEXT_BUFFER_SIZE];
170 static int selected_font = 0;
171 static int font_count = -1;
172 struct font_list *fonts = NULL;
176 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + \
177 fonts[selected_font].xftfont->descent) \
178 : (fonts[selected_font].font->max_bounds.ascent + \
179 fonts[selected_font].font->max_bounds.descent))
180 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent \
181 : fonts[selected_font].font->max_bounds.ascent)
182 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent \
183 : fonts[selected_font].font->max_bounds.descent)
187 #define font_height() (fonts[selected_font].font->max_bounds.ascent + \
188 fonts[selected_font].font->max_bounds.descent)
189 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
190 #define font_descent() fonts[selected_font].font->max_bounds.descent
194 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
196 static void set_font(void);
198 int addfont(const char *data_in)
200 if (font_count > MAX_FONTS) {
201 CRIT_ERR("you don't need that many fonts, sorry.");
204 if (font_count == 0) {
208 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
212 memset(fonts, 0, sizeof(struct font_list));
214 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
215 memset(&fonts[font_count], 0, sizeof(struct font_list));
217 CRIT_ERR("realloc in addfont");
219 // must account for null terminator
220 if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
221 strncpy(fonts[font_count].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
223 fonts[font_count].font_alpha = 0xffff;
226 CRIT_ERR("Oops...looks like something overflowed in addfont().");
231 void set_first_font(const char *data_in)
233 if (font_count < 0) {
234 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
238 memset(fonts, 0, sizeof(struct font_list));
241 if (strlen(data_in) > 1) {
242 strncpy(fonts[0].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
244 fonts[0].font_alpha = 0xffff;
249 void free_fonts(void)
253 for (i = 0; i <= font_count; i++) {
256 XftFontClose(display, fonts[i].xftfont);
257 fonts[i].xftfont = 0;
261 XFreeFont(display, fonts[i].font);
271 static void load_fonts(void)
275 for (i = 0; i <= font_count; i++) {
278 if (use_xft && fonts[i].xftfont) {
280 } else if (use_xft) {
281 /* if (fonts[i].xftfont != NULL && selected_font == 0) {
282 XftFontClose(display, fonts[i].xftfont);
284 fonts[i].xftfont = XftFontOpenName(display, screen,
286 if (fonts[i].xftfont != NULL) {
290 ERR("can't load Xft font '%s'", fonts[i].name);
291 if ((fonts[i].xftfont = XftFontOpenName(display, screen,
292 "courier-12")) != NULL) {
296 ERR("can't load Xft font '%s'", "courier-12");
298 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
299 CRIT_ERR("can't load font '%s'", "fixed");
306 /* load normal font */
307 /* if (fonts[i].font != NULL) {
308 XFreeFont(display, fonts[i].font);
311 if (fonts[i].font || (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
312 ERR("can't load font '%s'", fonts[i].name);
313 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
314 CRIT_ERR("can't load font '%s'", "fixed");
315 printf("loaded fixed?\n");
323 /* default config file */
324 static char *current_config;
326 /* set to 1 if you want all text to be in uppercase */
327 static unsigned int stuff_in_upper_case;
329 /* Run how many times? */
330 static unsigned long total_run_times;
333 static int fork_to_background;
335 static int cpu_avg_samples, net_avg_samples;
339 static int show_graph_scale;
341 /* Position on the screen */
342 static int text_alignment;
343 static int gap_x, gap_y;
346 static int draw_borders;
347 static int draw_graph_borders;
348 static int stippled_borders;
350 static int draw_shades, draw_outline;
352 static int border_margin, border_width;
354 static long default_fg_color, default_bg_color, default_out_color;
356 /* create own window or draw stuff to root? */
357 static int set_transparent = 0;
360 static int own_window = 0;
361 static int background_colour = 0;
363 /* fixed size/pos is set if wm/user changes them */
364 static int fixed_size = 0, fixed_pos = 0;
367 static int minimum_width, minimum_height;
368 static int maximum_width;
373 static int sensor_device;
376 static long color0, color1, color2, color3, color4, color5, color6, color7,
379 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
380 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
382 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
383 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
385 /* maximum size of individual text buffers, ie $exec buffer size */
386 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
389 #define CODEPAGE_LENGTH 20
391 long iconv_count = 0;
392 char iconv_converting;
393 static iconv_t **iconv_cd = 0;
395 int register_iconv(iconv_t *new_iconv)
397 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
399 CRIT_ERR("Out of memory");
401 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
402 if (!iconv_cd[iconv_count]) {
403 CRIT_ERR("Out of memory");
405 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
410 void free_iconv(void)
415 for (i = 0; i < iconv_count; i++) {
417 iconv_close(*iconv_cd[i]);
431 /* no buffers in used memory? */
434 /* pad percentages to decimals? */
435 static int pad_percents = 0;
437 #ifdef TCP_PORT_MONITOR
438 tcp_port_monitor_args_t tcp_port_monitor_args;
441 static char *text = 0;
444 static int total_updates;
447 static int blockdepth = 0;
448 static int if_jumped = 0;
449 static int blockstart[MAX_IF_BLOCK_DEPTH];
451 int check_contains(char *f, char *s)
454 FILE *where = fopen(f, "r");
457 char buf1[256], buf2[256];
459 while (fgets(buf1, 256, where)) {
460 sscanf(buf1, "%255s", buf2);
461 if (strstr(buf2, s)) {
468 ERR("Could not open the file");
474 static inline int calc_text_width(const char *s, int l)
481 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
482 (const FcChar8 *) s, l, &gi);
484 XftTextExtents8(display, fonts[selected_font].xftfont,
485 (const FcChar8 *) s, l, &gi);
491 return XTextWidth(fonts[selected_font].font, s, l);
496 /* formatted text to render on screen, generated in generate_text(),
497 * drawn in draw_stuff() */
499 static char *text_buffer;
501 /* special stuff in text_buffer */
503 #define SPECIAL_CHAR '\x01'
532 unsigned long first_colour; // for graph gradient
533 unsigned long last_colour;
537 /* create specials array on heap instead of stack with introduction of
539 static struct special_t *specials = NULL;
541 static unsigned int special_count;
544 static unsigned int special_index; /* used when drawing */
547 /* why 256? cause an array of more then 256 doubles seems excessive,
548 * and who needs that kind of precision anyway? */
549 #define MAX_GRAPH_DEPTH 256
551 static struct special_t *new_special(char *buf, enum special_types t)
553 if (special_count >= max_specials) {
554 CRIT_ERR("too many special things in text");
557 buf[0] = SPECIAL_CHAR;
559 specials[special_count].type = t;
560 return &specials[special_count++];
563 long fwd_fcharfind(FILE *fp, char val, unsigned int step)
567 unsigned int count = 0;
568 static char buf[BUFSZ];
569 long orig_pos = ftell(fp);
571 long buf_size = BUFSZ;
572 char *cur_found = NULL;
574 while (count < step) {
575 if (cur_found == NULL) {
576 buf_size = fread(buf, 1, buf_size, fp);
579 cur_found = memchr(buf + buf_pos, val, buf_size - buf_pos);
580 if (cur_found != NULL) {
581 buf_pos = cur_found - buf + 1;
590 ret = ftell(fp) - buf_size + buf_pos - 1;
592 fseek(fp, orig_pos, SEEK_SET);
598 void *memrchr(const void *buffer, char c, size_t n)
600 const unsigned char *p = buffer;
602 for (p += n; n; n--) {
611 long rev_fcharfind(FILE *fp, char val, unsigned int step)
615 unsigned int count = 0;
616 static char buf[BUFSZ];
617 long orig_pos = ftell(fp);
619 long file_pos = orig_pos;
620 long buf_size = BUFSZ;
623 while (count < step) {
625 if (file_pos > BUFSZ) {
626 fseek(fp, file_pos - BUFSZ, SEEK_SET);
629 fseek(fp, 0, SEEK_SET);
631 file_pos = ftell(fp);
632 buf_pos = fread(buf, 1, buf_size, fp);
634 cur_found = memrchr(buf, val, (size_t) buf_pos);
635 if (cur_found != NULL) {
636 buf_pos = cur_found - buf;
645 fseek(fp, orig_pos, SEEK_SET);
647 ret = file_pos + buf_pos;
653 static void new_bar(char *buf, int w, int h, int usage)
655 struct special_t *s = new_special(buf, BAR);
657 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
662 static const char *scan_bar(const char *args, int *w, int *h)
664 /* zero width means all space that is available */
667 /* bar's argument is either height or height,width */
671 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) {
672 sscanf(args, "%d %n", h, &n);
680 static char *scan_font(const char *args)
683 return strndup(args, DEFAULT_TEXT_BUFFER_SIZE);
690 static void new_font(char *buf, char *args)
693 struct special_t *s = new_special(buf, FONT);
695 if (s->font_added > font_count || !s->font_added || strncmp(args, fonts[s->font_added].name, DEFAULT_TEXT_BUFFER_SIZE)) {
696 int tmp = selected_font;
698 selected_font = s->font_added = addfont(args);
703 struct special_t *s = new_special(buf, FONT);
704 int tmp = selected_font;
706 selected_font = s->font_added = 0;
711 inline void graph_append(struct special_t *graph, double f)
715 if (!graph->scaled && f > graph->graph_scale) {
716 f = graph->graph_scale;
720 graph->graph_scale = 1;
722 graph->graph[0] = f; /* add new data */
723 /* shift all the data by 1 */
724 for (i = graph->graph_width - 1; i > 0; i--) {
725 graph->graph[i] = graph->graph[i - 1];
726 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
727 /* check if we need to update the scale */
728 graph->graph_scale = graph->graph[i];
733 short colour_depth = 0;
734 void set_up_gradient(void);
736 /* precalculated: 31/255, and 63/255 */
737 #define CONST_8_TO_5_BITS 0.12156862745098
738 #define CONST_8_TO_6_BITS 0.247058823529412
740 /* adjust color values depending on color depth */
741 static unsigned int adjust_colors(unsigned int color)
745 if (colour_depth == 0) {
748 if (colour_depth == 16) {
749 r = (color & 0xff0000) >> 16;
750 g = (color & 0xff00) >> 8;
752 color = (int) (r * CONST_8_TO_5_BITS) << 11;
753 color |= (int) (g * CONST_8_TO_6_BITS) << 5;
754 color |= (int) (b * CONST_8_TO_5_BITS);
759 static void new_graph(char *buf, int w, int h, unsigned int first_colour,
760 unsigned int second_colour, double i, int scale, int append)
762 struct special_t *s = new_special(buf, GRAPH);
765 if (s->graph == NULL) {
766 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
767 // subtract 2 for the box
768 s->graph_width = s->width /* - 2 */;
770 s->graph_width = MAX_GRAPH_DEPTH - 2;
772 s->graph = malloc(s->graph_width * sizeof(double));
773 memset(s->graph, 0, s->graph_width * sizeof(double));
774 s->graph_scale = 100;
777 s->first_colour = adjust_colors(first_colour);
778 s->last_colour = adjust_colors(second_colour);
785 s->graph_width = s->width - 2; // subtract 2 for rectangle around
791 s->graph_scale = scale;
799 static char *scan_graph(const char *args, int *w, int *h,
800 unsigned int *first_colour, unsigned int *last_colour,
806 /* zero width means all space that is available */
812 /* graph's argument is either height or height,width */
814 if (sscanf(args, "%d,%d %x %x %u", h, w, first_colour, last_colour,
819 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) {
822 if (sscanf(args, "%63s %d,%d %x %x %u", buf, h, w, first_colour,
823 last_colour, scale) == 6) {
824 return strndup(buf, text_buffer_size);
827 if (sscanf(args, "%63s %d,%d %x %x", buf, h, w, first_colour,
829 return strndup(buf, text_buffer_size);
834 if (sscanf(args, "%x %x %u", first_colour, last_colour, scale) == 3) {
838 if (sscanf(args, "%x %x", first_colour, last_colour) == 2) {
841 if (sscanf(args, "%63s %x %x %u", buf, first_colour, last_colour,
843 return strndup(buf, text_buffer_size);
846 if (sscanf(args, "%63s %x %x", buf, first_colour, last_colour) == 3) {
847 return strndup(buf, text_buffer_size);
852 if (sscanf(args, "%d,%d %u", h, w, scale) == 3) {
856 if (sscanf(args, "%d,%d", h, w) == 2) {
859 if (sscanf(args, "%63s %d,%d %u", buf, h, w, scale) < 4) {
861 //TODO: check the return value and throw an error?
862 sscanf(args, "%63s %d,%d", buf, h, w);
865 return strndup(buf, text_buffer_size);
868 if (buf[0] == '\0') {
871 return strndup(buf, text_buffer_size);
875 static inline void new_hr(char *buf, int a)
877 new_special(buf, HORIZONTAL_LINE)->height = a;
880 static inline void new_stippled_hr(char *buf, int a, int b)
882 struct special_t *s = new_special(buf, STIPPLED_HR);
888 static inline void new_fg(char *buf, long c)
890 new_special(buf, FG)->arg = c;
893 static inline void new_bg(char *buf, long c)
895 new_special(buf, BG)->arg = c;
898 static inline void new_outline(char *buf, long c)
900 new_special(buf, OUTLINE)->arg = c;
903 static inline void new_offset(char *buf, long c)
905 new_special(buf, OFFSET)->arg = c;
908 static inline void new_voffset(char *buf, long c)
910 new_special(buf, VOFFSET)->arg = c;
913 static inline void new_alignr(char *buf, long c)
915 new_special(buf, ALIGNR)->arg = c;
918 static inline void new_alignc(char *buf, long c)
920 new_special(buf, ALIGNC)->arg = c;
923 static inline void new_goto(char *buf, long c)
925 new_special(buf, GOTO)->arg = c;
928 static inline void new_tab(char *buf, int a, int b)
930 struct special_t *s = new_special(buf, TAB);
936 /* quite boring functions */
938 static inline void for_each_line(char *b, void f(char *))
942 for (ps = b, pe = b; *pe; pe++) {
956 static void convert_escapes(char *buf)
958 char *p = buf, *s = buf;
965 } else if (*s == '\\') {
976 /* Prints anything normally printed with snprintf according to the current value
977 * of use_spacer. Actually slightly more flexible than snprintf, as you can
978 * safely specify the destination buffer as one of your inputs. */
979 static int spaced_print(char *, int, const char *, int, const char *, ...)
980 __attribute__((format(printf, 3, 6)));
982 static int spaced_print(char *buf, int size, const char *format, int width,
983 const char *func_name, ...) {
991 tempbuf = malloc(size * sizeof(char));
993 // Passes the varargs along to vsnprintf
994 va_start(argp, func_name);
995 vsnprintf(tempbuf, size, format, argp);
998 switch (use_spacer) {
1000 len = snprintf(buf, size, "%s", tempbuf);
1003 len = snprintf(buf, size, "%*s", width - 1, tempbuf);
1006 len = snprintf(buf, size, "%-*s", width - 1, tempbuf);
1009 CRIT_ERR("%s encountered invalid use_spacer value (%d)", func_name,
1018 /* converts from bytes to human readable format (k, M, G, T) */
1019 static void human_readable(long long num, char *buf, int size, const char *func_name)
1021 const char **suffix = suffixes;
1024 static const int WIDTH = 10, SHORT_WIDTH = 8;
1028 spaced_print(buf, size, "%lld%c", SHORT_WIDTH, func_name, num,
1031 spaced_print(buf, size, "%lld%s", WIDTH, func_name, num, *suffix);
1036 while (num / 1024 >= 1000LL && **(suffix + 2)) {
1042 fnum = num / 1024.0;
1047 if (precision < 0) {
1051 len = spaced_print(buf, size, "%.*f%c", SHORT_WIDTH, func_name,
1052 precision, fnum, **suffix);
1054 len = spaced_print(buf, size, "%.*f%s", WIDTH, func_name, precision,
1057 } while (len >= (short_units ? SHORT_WIDTH : WIDTH) || len >= size);
1062 enum text_object_type {
1064 #if defined(__linux__)
1066 #endif /* __linux__ */
1076 OBJ_battery_percent,
1078 #endif /* !__OpenBSD__ */
1093 OBJ_conky_build_date,
1094 OBJ_conky_build_arch,
1104 OBJ_diskiograph_read,
1105 OBJ_diskiograph_write,
1143 #if defined(__linux__)
1150 OBJ_i8k_left_fan_status,
1151 OBJ_i8k_right_fan_status,
1152 OBJ_i8k_left_fan_rpm,
1153 OBJ_i8k_right_fan_rpm,
1155 OBJ_i8k_buttons_status,
1171 OBJ_wireless_bitrate,
1173 OBJ_wireless_link_qual,
1174 OBJ_wireless_link_qual_max,
1175 OBJ_wireless_link_qual_perc,
1176 OBJ_wireless_link_bar,
1177 #endif /* __linux__ */
1210 OBJ_running_processes,
1219 OBJ_temp1, /* i2c is used instead in these */
1243 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
1244 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1246 OBJ_apm_battery_time,
1247 OBJ_apm_battery_life,
1248 #endif /* __FreeBSD__ __OpenBSD__ */
1250 OBJ_obsd_sensors_temp,
1251 OBJ_obsd_sensors_fan,
1252 OBJ_obsd_sensors_volt,
1255 #endif /* __OpenBSD__ */
1277 OBJ_music_player_interval,
1297 OBJ_xmms2_timesplayed,
1300 OBJ_audacious_status,
1301 OBJ_audacious_title,
1302 OBJ_audacious_length,
1303 OBJ_audacious_length_seconds,
1304 OBJ_audacious_position,
1305 OBJ_audacious_position_seconds,
1306 OBJ_audacious_bitrate,
1307 OBJ_audacious_frequency,
1308 OBJ_audacious_channels,
1309 OBJ_audacious_filename,
1310 OBJ_audacious_playlist_length,
1311 OBJ_audacious_playlist_position,
1325 #ifdef TCP_PORT_MONITOR
1339 OBJ_if_smapi_bat_installed,
1342 OBJ_entropy_poolsize,
1346 struct text_object {
1348 char *s; /* some string */
1349 int i; /* some integer */
1350 long l; /* some other integer */
1351 unsigned int sensor;
1352 struct net_stat *net;
1354 struct diskio_stat *diskio;
1355 unsigned char loadavg[3];
1356 unsigned int cpu_index;
1357 struct mail_s *mail;
1365 char *tz; /* timezone variable */
1366 char *fmt; /* time display formatting */
1404 /* If not -1, a file descriptor to read from when
1405 * logfile is a FIFO. */
1422 timed_thread *p_timed_thread;
1428 #ifdef TCP_PORT_MONITOR
1430 /* starting port to monitor */
1431 in_port_t port_range_begin;
1432 /* ending port to monitor */
1433 in_port_t port_range_end;
1434 /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1436 /* 0 to n-1 connections. */
1437 int connection_index;
1458 struct local_mail_s local_mail;
1460 struct nvidia_s nvidia;
1467 unsigned int c, d, e;
1472 struct text_object_list {
1473 unsigned int text_object_count;
1474 struct text_object *text_objects;
1477 static unsigned int global_text_object_count;
1478 static struct text_object *global_text_objects;
1479 static void generate_text_internal(char *p, int p_max_size,
1480 struct text_object *objs, unsigned int object_count,
1481 struct information *cur);
1483 #define MAXDATASIZE 1000
1487 struct mail_s *parse_mail_args(char type, const char *arg)
1489 struct mail_s *mail;
1492 mail = malloc(sizeof(struct mail_s));
1493 memset(mail, 0, sizeof(struct mail_s));
1495 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass)
1498 ERR("Scanning IMAP args failed");
1499 } else if (type == IMAP) {
1500 ERR("Scanning POP3 args failed");
1503 // see if password needs prompting
1504 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1505 int fp = fileno(stdin);
1506 struct termios term;
1508 tcgetattr(fp, &term);
1509 term.c_lflag &= ~ECHO;
1510 tcsetattr(fp, TCSANOW, &term);
1511 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1512 scanf("%128s", mail->pass);
1514 term.c_lflag |= ECHO;
1515 tcsetattr(fp, TCSANOW, &term);
1517 // now we check for optional args
1518 tmp = strstr(arg, "-i ");
1521 sscanf(tmp, "%f", &mail->interval);
1523 mail->interval = 300; // 5 minutes
1525 tmp = strstr(arg, "-p ");
1528 sscanf(tmp, "%lu", &mail->port);
1531 mail->port = 110; // default pop3 port
1532 } else if (type == IMAP) {
1533 mail->port = 143; // default imap port
1537 tmp = strstr(arg, "-f ");
1540 sscanf(tmp, "%s", mail->folder);
1542 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1545 tmp = strstr(arg, "-e ");
1550 if (tmp[0] == '\'') {
1551 len = strstr(tmp + 1, "'") - tmp - 1;
1556 strncpy(mail->command, tmp + 1, len);
1558 mail->command[0] = '\0';
1560 mail->p_timed_thread = NULL;
1564 void *imap_thread(void *arg)
1566 int sockfd, numbytes;
1567 char recvbuf[MAXDATASIZE];
1568 char sendbuf[MAXDATASIZE];
1571 unsigned int old_unseen = UINT_MAX;
1572 unsigned int old_messages = UINT_MAX;
1573 struct stat stat_buf;
1574 struct hostent he, *he_res = 0;
1576 char hostbuff[2048];
1577 struct sockaddr_in their_addr; // connector's address information
1578 struct mail_s *mail = (struct mail_s *)arg;
1580 #ifdef HAVE_GETHOSTBYNAME_R
1581 if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
1582 ERR("IMAP gethostbyname_r: %s", hstrerror(h_errno));
1585 #else /* HAVE_GETHOSTBYNAME_R */
1586 if ((he_res = gethostbyname(mail->host)) == NULL) { // get the host info
1587 herror("gethostbyname");
1590 #endif /* HAVE_GETHOSTBYNAME_R */
1592 struct timeval timeout;
1597 ERR("Trying IMAP connection again for %s@%s (try %i/5)",
1598 mail->user, mail->host, fail + 1);
1601 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1608 their_addr.sin_family = AF_INET;
1609 // short, network byte order
1610 their_addr.sin_port = htons(mail->port);
1611 their_addr.sin_addr = *((struct in_addr *) he_res->h_addr);
1612 // zero the rest of the struct
1613 memset(&(their_addr.sin_zero), '\0', 8);
1615 if (connect(sockfd, (struct sockaddr *) &their_addr,
1616 sizeof(struct sockaddr)) == -1) {
1622 timeout.tv_sec = 60; // 60 second timeout i guess
1623 timeout.tv_usec = 0;
1625 FD_SET(sockfd, &fdset);
1626 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1628 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1634 ERR("IMAP connection failed: timeout");
1638 recvbuf[numbytes] = '\0';
1639 if (strstr(recvbuf, "* OK") != recvbuf) {
1640 ERR("IMAP connection failed, probably not an IMAP server");
1644 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1645 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1646 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1647 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1648 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1649 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1654 timeout.tv_sec = 60; // 60 second timeout i guess
1655 timeout.tv_usec = 0;
1657 FD_SET(sockfd, &fdset);
1658 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1660 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1666 recvbuf[numbytes] = '\0';
1667 if (strstr(recvbuf, "a1 OK") == NULL) {
1668 ERR("IMAP server login failed: %s", recvbuf);
1672 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1673 strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1);
1674 strncat(sendbuf, " (MESSAGES UNSEEN)\r\n",
1675 MAXDATASIZE - strlen(sendbuf) - 1);
1676 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1681 timeout.tv_sec = 60; // 60 second timeout i guess
1682 timeout.tv_usec = 0;
1684 FD_SET(sockfd, &fdset);
1685 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1687 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1693 recvbuf[numbytes] = '\0';
1694 if (strstr(recvbuf, "a2 OK") == NULL) {
1695 ERR("IMAP status failed: %s", recvbuf);
1699 // now we get the data
1700 reply = strstr(recvbuf, " (MESSAGES ");
1702 *strchr(reply, ')') = '\0';
1703 if (reply == NULL) {
1704 ERR("Error parsing IMAP response: %s", recvbuf);
1708 timed_thread_lock(mail->p_timed_thread);
1709 sscanf(reply, "MESSAGES %lu UNSEEN %lu", &mail->messages,
1711 timed_thread_unlock(mail->p_timed_thread);
1713 strncpy(sendbuf, "a3 logout\r\n", MAXDATASIZE);
1714 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1719 timeout.tv_sec = 60; // 60 second timeout i guess
1720 timeout.tv_usec = 0;
1722 FD_SET(sockfd, &fdset);
1723 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1725 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1731 recvbuf[numbytes] = '\0';
1732 if (strstr(recvbuf, "a3 OK") == NULL) {
1733 ERR("IMAP logout failed: %s", recvbuf);
1737 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen
1738 || (mail->messages > old_messages && mail->unseen > 0))) {
1740 if (system(mail->command) == -1) {
1745 old_unseen = mail->unseen;
1746 old_messages = mail->messages;
1748 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1749 /* if a valid socket, close it */
1752 if (timed_thread_test(mail->p_timed_thread)) {
1753 timed_thread_exit(mail->p_timed_thread);
1761 void *pop3_thread(void *arg)
1763 int sockfd, numbytes;
1764 char recvbuf[MAXDATASIZE];
1765 char sendbuf[MAXDATASIZE];
1768 unsigned int old_unseen = UINT_MAX;
1769 struct stat stat_buf;
1770 struct hostent he, *he_res = 0;
1772 char hostbuff[2048];
1773 struct sockaddr_in their_addr; // connector's address information
1774 struct mail_s *mail = (struct mail_s *)arg;
1776 #ifdef HAVE_GETHOSTBYNAME_R
1777 if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
1778 ERR("POP3 gethostbyname_r: %s", hstrerror(h_errno));
1781 #else /* HAVE_GETHOSTBYNAME_R */
1782 if ((he_res = gethostbyname(mail->host)) == NULL) { // get the host info
1783 herror("gethostbyname");
1786 #endif /* HAVE_GETHOSTBYNAME_R */
1788 struct timeval timeout;
1793 ERR("Trying POP3 connection again for %s@%s (try %i/5)",
1794 mail->user, mail->host, fail + 1);
1797 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1804 their_addr.sin_family = AF_INET;
1805 // short, network byte order
1806 their_addr.sin_port = htons(mail->port);
1807 their_addr.sin_addr = *((struct in_addr *) he_res->h_addr);
1808 // zero the rest of the struct
1809 memset(&(their_addr.sin_zero), '\0', 8);
1811 if (connect(sockfd, (struct sockaddr *) &their_addr,
1812 sizeof(struct sockaddr)) == -1) {
1818 timeout.tv_sec = 60; // 60 second timeout i guess
1819 timeout.tv_usec = 0;
1821 FD_SET(sockfd, &fdset);
1822 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1824 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1830 ERR("POP3 connection failed: timeout\n");
1834 recvbuf[numbytes] = '\0';
1835 if (strstr(recvbuf, "+OK ") != recvbuf) {
1836 ERR("POP3 connection failed, probably not a POP3 server");
1840 strncpy(sendbuf, "USER ", MAXDATASIZE);
1841 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1842 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1843 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1844 perror("send USER");
1848 timeout.tv_sec = 60; // 60 second timeout i guess
1849 timeout.tv_usec = 0;
1851 FD_SET(sockfd, &fdset);
1852 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1854 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1855 perror("recv USER");
1860 recvbuf[numbytes] = '\0';
1861 if (strstr(recvbuf, "+OK ") == NULL) {
1862 ERR("POP3 server login failed: %s", recvbuf);
1866 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1867 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1868 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1869 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1870 perror("send PASS");
1874 timeout.tv_sec = 60; // 60 second timeout i guess
1875 timeout.tv_usec = 0;
1877 FD_SET(sockfd, &fdset);
1878 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1880 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1881 perror("recv PASS");
1886 recvbuf[numbytes] = '\0';
1887 if (strstr(recvbuf, "+OK ") == NULL) {
1888 ERR("POP3 server login failed: %s", recvbuf);
1892 strncpy(sendbuf, "STAT\r\n", MAXDATASIZE);
1893 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1894 perror("send STAT");
1898 timeout.tv_sec = 60; // 60 second timeout i guess
1899 timeout.tv_usec = 0;
1901 FD_SET(sockfd, &fdset);
1902 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1904 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1905 perror("recv STAT");
1910 recvbuf[numbytes] = '\0';
1911 if (strstr(recvbuf, "+OK ") == NULL) {
1912 ERR("POP3 status failed: %s", recvbuf);
1916 // now we get the data
1917 reply = recvbuf + 4;
1918 if (reply == NULL) {
1919 ERR("Error parsing POP3 response: %s", recvbuf);
1923 timed_thread_lock(mail->p_timed_thread);
1924 sscanf(reply, "%lu %lu", &mail->unseen, &mail->used);
1925 timed_thread_unlock(mail->p_timed_thread);
1927 strncpy(sendbuf, "QUIT\r\n", MAXDATASIZE);
1928 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1929 perror("send QUIT");
1933 timeout.tv_sec = 60; // 60 second timeout i guess
1934 timeout.tv_usec = 0;
1936 FD_SET(sockfd, &fdset);
1937 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1939 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1940 perror("recv QUIT");
1945 recvbuf[numbytes] = '\0';
1946 if (strstr(recvbuf, "+OK") == NULL) {
1947 ERR("POP3 logout failed: %s", recvbuf);
1951 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) {
1953 if (system(mail->command) == -1) {
1958 old_unseen = mail->unseen;
1960 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1961 /* if a valid socket, close it */
1964 if (timed_thread_test(mail->p_timed_thread)) {
1965 timed_thread_exit(mail->p_timed_thread);
1973 void *threaded_exec(void *) __attribute__((noreturn));
1975 void *threaded_exec(void *arg)
1980 struct text_object *obj = (struct text_object *)arg;
1982 p2 = obj->data.texeci.buffer;
1983 fp = popen(obj->data.texeci.cmd, "r");
1985 timed_thread_lock(obj->data.texeci.p_timed_thread);
1986 n2 = fread(p2, 1, text_buffer_size, fp);
1990 if (n2 && p2[n2 - 1] == '\n') {
1994 if (*p2 == '\001') {
1999 timed_thread_unlock(obj->data.texeci.p_timed_thread);
2000 if (timed_thread_test(obj->data.texeci.p_timed_thread)) {
2001 timed_thread_exit(obj->data.texeci.p_timed_thread);
2007 static struct text_object *new_text_object_internal(void)
2009 struct text_object *obj = malloc(sizeof(struct text_object));
2010 memset(obj, 0, sizeof(struct text_object));
2014 static void free_text_objects(unsigned int count, struct text_object *objs)
2018 for (i = 0; i < count; i++) {
2019 switch (objs[i].type) {
2023 close(objs[i].data.i);
2028 close(objs[i].data.sysfs.fd);
2030 #endif /* !__OpenBSD__ */
2033 free(objs[i].data.s);
2036 free(objs[i].data.tztime.tz);
2037 free(objs[i].data.tztime.fmt);
2040 free(objs[i].data.mboxscan.args);
2041 free(objs[i].data.mboxscan.output);
2045 free(objs[i].data.local_mail.box);
2050 case OBJ_imap_unseen:
2051 if (!objs[i].global_mode) {
2052 free(objs[i].data.mail);
2055 case OBJ_imap_messages:
2056 if (!objs[i].global_mode) {
2057 free(objs[i].data.mail);
2063 case OBJ_pop3_unseen:
2064 if (!objs[i].global_mode) {
2065 free(objs[i].data.mail);
2069 if (!objs[i].global_mode) {
2070 free(objs[i].data.mail);
2074 case OBJ_if_existing:
2075 case OBJ_if_mounted:
2076 case OBJ_if_running:
2077 free(objs[i].data.ifblock.s);
2078 free(objs[i].data.ifblock.str);
2081 free(objs[i].data.tail.logfile);
2082 free(objs[i].data.tail.buffer);
2091 free(objs[i].data.s);
2094 case OBJ_iconv_start:
2099 case OBJ_disk_protect:
2100 free(objs[i].data.s);
2103 free(objs[i].data.ifblock.s);
2104 free(objs[i].data.ifblock.str);
2107 free(objs[i].data.ifblock.s);
2108 free(objs[i].data.ifblock.str);
2111 if (info.gw_info.iface) {
2112 free(info.gw_info.iface);
2113 info.gw_info.iface = 0;
2115 if (info.gw_info.ip) {
2116 free(info.gw_info.ip);
2117 info.gw_info.ip = 0;
2120 case OBJ_ioscheduler:
2122 free(objs[i].data.s);
2126 case OBJ_xmms2_artist:
2127 if (info.xmms2.artist) {
2128 free(info.xmms2.artist);
2129 info.xmms2.artist = 0;
2132 case OBJ_xmms2_album:
2133 if (info.xmms2.album) {
2134 free(info.xmms2.album);
2135 info.xmms2.album = 0;
2138 case OBJ_xmms2_title:
2139 if (info.xmms2.title) {
2140 free(info.xmms2.title);
2141 info.xmms2.title = 0;
2144 case OBJ_xmms2_genre:
2145 if (info.xmms2.genre) {
2146 free(info.xmms2.genre);
2147 info.xmms2.genre = 0;
2150 case OBJ_xmms2_comment:
2151 if (info.xmms2.comment) {
2152 free(info.xmms2.comment);
2153 info.xmms2.comment = 0;
2157 if (info.xmms2.url) {
2158 free(info.xmms2.url);
2162 case OBJ_xmms2_date:
2163 if (info.xmms2.date) {
2164 free(info.xmms2.date);
2165 info.xmms2.date = 0;
2168 case OBJ_xmms2_status:
2169 if (info.xmms2.status) {
2170 free(info.xmms2.status);
2171 info.xmms2.status = 0;
2174 case OBJ_xmms2_playlist:
2175 if (info.xmms2.playlist) {
2176 free(info.xmms2.playlist);
2177 info.xmms2.playlist = 0;
2180 case OBJ_xmms2_smart:
2181 if (info.xmms2.artist) {
2182 free(info.xmms2.artist);
2183 info.xmms2.artist = 0;
2185 if (info.xmms2.title) {
2186 free(info.xmms2.title);
2187 info.xmms2.title = 0;
2189 if (info.xmms2.url) {
2190 free(info.xmms2.url);
2196 case OBJ_bmpx_title:
2197 case OBJ_bmpx_artist:
2198 case OBJ_bmpx_album:
2199 case OBJ_bmpx_track:
2201 case OBJ_bmpx_bitrate:
2206 free(objs[i].data.rss.uri);
2207 free(objs[i].data.rss.action);
2214 free(objs[i].data.s);
2216 case OBJ_battery_time:
2217 free(objs[i].data.s);
2219 #endif /* !__OpenBSD__ */
2223 case OBJ_execigraph:
2224 free(objs[i].data.execi.cmd);
2225 free(objs[i].data.execi.buffer);
2228 free(objs[i].data.texeci.cmd);
2229 free(objs[i].data.texeci.buffer);
2231 case OBJ_nameserver:
2236 if (info.first_process) {
2237 free_all_processes();
2238 info.first_process = NULL;
2243 free(objs[i].data.hddtemp.dev);
2244 free(objs[i].data.hddtemp.addr);
2245 free(objs[i].data.hddtemp.temp);
2248 case OBJ_entropy_avail:
2249 case OBJ_entropy_poolsize:
2250 case OBJ_entropy_bar:
2252 case OBJ_user_names:
2253 if (info.users.names) {
2254 free(info.users.names);
2255 info.users.names = 0;
2258 case OBJ_user_terms:
2259 if (info.users.terms) {
2260 free(info.users.terms);
2261 info.users.terms = 0;
2264 case OBJ_user_times:
2265 if (info.users.times) {
2266 free(info.users.times);
2267 info.users.times = 0;
2272 case OBJ_smapi_bat_perc:
2273 free(objs[i].data.s);
2275 case OBJ_if_smapi_bat_installed:
2276 free(objs[i].data.ifblock.s);
2277 free(objs[i].data.ifblock.str);
2286 case OBJ_mpd_artist:
2288 case OBJ_mpd_random:
2289 case OBJ_mpd_repeat:
2291 case OBJ_mpd_bitrate:
2292 case OBJ_mpd_status:
2295 case OBJ_mpd_password:
2297 case OBJ_mpd_elapsed:
2298 case OBJ_mpd_length:
2302 case OBJ_mpd_percent:
2304 free_mpd_vars(&info.mpd);
2310 /* text_objects = NULL;
2311 text_object_count = 0; */
2314 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2319 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2320 *a = mixer_init(buf1);
2321 scan_bar(arg + n, w, h);
2323 *a = mixer_init(NULL);
2324 scan_bar(arg, w, h);
2328 /* strip a leading /dev/ if any */
2329 #define DEV_NAME(x) x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 \
2332 /* construct_text_object() creates a new text_object */
2333 static struct text_object *construct_text_object(const char *s,
2334 const char *arg, unsigned int object_count,
2335 struct text_object *text_objects, long line)
2337 // struct text_object *obj = new_text_object();
2338 struct text_object *obj = new_text_object_internal();
2342 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
2343 obj->type = OBJ_##a; need_mask |= (1 << n); {
2344 #define END } } else
2348 obj->type = OBJ_color;
2349 obj->data.l = get_x11_color(s);
2353 OBJ(freq, INFO_FREQ)
2356 obj->data.i = open_acpi_temperature(arg);
2357 END OBJ(acpitempf, 0)
2358 obj->data.i = open_acpi_temperature(arg);
2359 END OBJ(acpiacadapter, 0)
2360 END OBJ(freq, INFO_FREQ)
2361 #endif /* !__OpenBSD__ */
2363 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2364 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2365 obj->data.cpu_index = 1;
2366 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
2367 "Displaying the clock for CPU 1."); */
2369 obj->data.cpu_index = atoi(&arg[0]);
2372 END OBJ(freq_g, INFO_FREQ)
2374 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2375 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2376 obj->data.cpu_index = 1;
2377 /* ERR("freq_g: Invalid CPU number or you don't have that many "
2378 "CPUs! Displaying the clock for CPU 1."); */
2380 obj->data.cpu_index = atoi(&arg[0]);
2383 #if defined(__linux__)
2384 END OBJ(voltage_mv, 0)
2386 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2387 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2388 obj->data.cpu_index = 1;
2389 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
2390 "CPUs! Displaying voltage for CPU 1."); */
2392 obj->data.cpu_index = atoi(&arg[0]);
2395 END OBJ(voltage_v, 0)
2397 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2398 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2399 obj->data.cpu_index = 1;
2400 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
2401 "CPUs! Displaying voltage for CPU 1."); */
2403 obj->data.cpu_index = atoi(&arg[0]);
2408 END OBJ(wireless_essid, INFO_NET)
2410 obj->data.net = get_net_stat(arg);
2412 CRIT_ERR("wireless_essid: needs an argument");
2414 END OBJ(wireless_mode, INFO_NET)
2416 obj->data.net = get_net_stat(arg);
2418 CRIT_ERR("wireless_mode: needs an argument");
2420 END OBJ(wireless_bitrate, INFO_NET)
2422 obj->data.net = get_net_stat(arg);
2424 CRIT_ERR("wireless_bitrate: needs an argument");
2426 END OBJ(wireless_ap, INFO_NET)
2428 obj->data.net = get_net_stat(arg);
2430 CRIT_ERR("wireless_ap: needs an argument");
2432 END OBJ(wireless_link_qual, INFO_NET)
2434 obj->data.net = get_net_stat(arg);
2436 CRIT_ERR("wireless_link_qual: needs an argument");
2438 END OBJ(wireless_link_qual_max, INFO_NET)
2440 obj->data.net = get_net_stat(arg);
2442 CRIT_ERR("wireless_link_qual_max: needs an argument");
2444 END OBJ(wireless_link_qual_perc, INFO_NET)
2446 obj->data.net = get_net_stat(arg);
2448 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2450 END OBJ(wireless_link_bar, INFO_NET)
2452 arg = scan_bar(arg, &obj->a, &obj->b);
2453 obj->data.net = get_net_stat(arg);
2455 CRIT_ERR("wireless_link_bar: needs an argument");
2457 #endif /* HAVE_IWLIB */
2459 #endif /* __linux__ */
2460 END OBJ(freq_dyn, 0)
2461 END OBJ(freq_dyn_g, 0)
2469 sscanf(arg, "%63s", bat);
2471 strcpy(bat, "BAT0");
2473 obj->data.s = strndup(bat, text_buffer_size);
2474 END OBJ(battery_time, 0)
2478 sscanf(arg, "%63s", bat);
2480 strcpy(bat, "BAT0");
2482 obj->data.s = strndup(bat, text_buffer_size);
2483 END OBJ(battery_percent, 0)
2487 sscanf(arg, "%63s", bat);
2489 strcpy(bat, "BAT0");
2491 obj->data.s = strndup(bat, text_buffer_size);
2492 END OBJ(battery_bar, 0)
2496 arg = scan_bar(arg, &obj->a, &obj->b);
2497 sscanf(arg, "%63s", bat);
2499 strcpy(bat, "BAT0");
2501 obj->data.s = strndup(bat, text_buffer_size);
2502 #endif /* !__OpenBSD__ */
2504 #if defined(__linux__)
2505 END OBJ(disk_protect, 0)
2507 obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
2509 CRIT_ERR("disk_protect needs an argument");
2510 END OBJ(i8k_version, INFO_I8K)
2511 END OBJ(i8k_bios, INFO_I8K)
2512 END OBJ(i8k_serial, INFO_I8K)
2513 END OBJ(i8k_cpu_temp, INFO_I8K)
2514 END OBJ(i8k_cpu_tempf, INFO_I8K)
2515 END OBJ(i8k_left_fan_status, INFO_I8K)
2516 END OBJ(i8k_right_fan_status, INFO_I8K)
2517 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2518 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2519 END OBJ(i8k_ac_status, INFO_I8K)
2520 END OBJ(i8k_buttons_status, INFO_I8K)
2522 END OBJ(ibm_temps, 0)
2524 CRIT_ERR("ibm_temps: needs an argument");
2526 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
2527 obj->data.sensor = 0;
2528 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
2529 "Using 0 (CPU temp sensor).");
2531 obj->data.sensor = atoi(&arg[0]);
2532 END OBJ(ibm_volume, 0)
2533 END OBJ(ibm_brightness, 0)
2535 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2536 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2539 ERR("if_up needs an argument");
2540 obj->data.ifblock.s = 0;
2542 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2543 blockstart[blockdepth] = object_count;
2544 obj->data.ifblock.pos = object_count + 2;
2547 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2548 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2550 blockstart[blockdepth] = object_count;
2551 obj->data.ifblock.pos = object_count + 2;
2553 END OBJ(ioscheduler, 0)
2555 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
2558 obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
2559 END OBJ(laptop_mode, 0)
2560 END OBJ(pb_battery, 0)
2561 if (arg && strcmp(arg, "status") == 0) {
2562 obj->data.i = PB_BATT_STATUS;
2563 } else if (arg && strcmp(arg, "percent") == 0) {
2564 obj->data.i = PB_BATT_PERCENT;
2565 } else if (arg && strcmp(arg, "time") == 0) {
2566 obj->data.i = PB_BATT_TIME;
2568 ERR("pb_battery: needs one argument: status, percent or time");
2573 #endif /* __linux__ */
2574 #if defined(__OpenBSD__)
2575 END OBJ(obsd_sensors_temp, 0)
2577 CRIT_ERR("obsd_sensors_temp: needs an argument");
2579 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2580 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2581 obj->data.sensor = 0;
2582 ERR("Invalid temperature sensor number!");
2584 obj->data.sensor = atoi(&arg[0]);
2585 END OBJ(obsd_sensors_fan, 0)
2587 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
2590 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2591 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2592 obj->data.sensor = 0;
2593 ERR("Invalid fan sensor number!");
2595 obj->data.sensor = atoi(&arg[0]);
2596 END OBJ(obsd_sensors_volt, 0)
2598 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
2601 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2602 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2603 obj->data.sensor = 0;
2604 ERR("Invalid voltage sensor number!");
2606 obj->data.sensor = atoi(&arg[0]);
2607 END OBJ(obsd_vendor, 0)
2608 END OBJ(obsd_product, 0)
2609 #endif /* __OpenBSD__ */
2610 END OBJ(buffers, INFO_BUFFERS)
2611 END OBJ(cached, INFO_BUFFERS)
2612 END OBJ(cpu, INFO_CPU)
2614 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2615 obj->data.cpu_index = atoi(&arg[3]);
2618 obj->data.cpu_index = 0;
2621 obj->data.cpu_index = 0;
2623 END OBJ(cpubar, INFO_CPU)
2625 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2626 obj->data.cpu_index = atoi(&arg[3]);
2629 obj->data.cpu_index = 0;
2631 scan_bar(arg, &obj->a, &obj->b);
2633 scan_bar(arg, &obj->a, &obj->b);
2634 obj->data.cpu_index = 0;
2636 END OBJ(cpugraph, INFO_CPU)
2637 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2641 if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
2642 obj->data.cpu_index = atoi(&buf[3]);
2644 obj->data.cpu_index = 0;
2648 END OBJ(loadgraph, INFO_LOADAVG)
2649 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2654 r = sscanf(arg, "%d", &a);
2656 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2659 #if defined(__linux__)
2660 END OBJ(diskio, INFO_DISKIO)
2662 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2664 obj->data.diskio = NULL;
2666 END OBJ(diskio_read, INFO_DISKIO)
2668 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2670 obj->data.diskio = NULL;
2672 END OBJ(diskio_write, INFO_DISKIO)
2674 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2676 obj->data.diskio = NULL;
2678 END OBJ(diskiograph, INFO_DISKIO)
2679 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2683 obj->data.diskio = prepare_diskio_stat(buf);
2686 obj->data.diskio = NULL;
2688 END OBJ(diskiograph_read, INFO_DISKIO)
2689 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2693 obj->data.diskio = prepare_diskio_stat(buf);
2696 obj->data.diskio = NULL;
2698 END OBJ(diskiograph_write, INFO_DISKIO)
2699 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2703 obj->data.diskio = prepare_diskio_stat(buf);
2706 obj->data.diskio = NULL;
2711 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2714 obj->data.l = color0;
2716 obj->data.l = color1;
2718 obj->data.l = color2;
2720 obj->data.l = color3;
2722 obj->data.l = color4;
2724 obj->data.l = color5;
2726 obj->data.l = color6;
2728 obj->data.l = color7;
2730 obj->data.l = color8;
2732 obj->data.l = color9;
2734 obj->data.s = scan_font(arg);
2735 END OBJ(conky_version, 0)
2736 END OBJ(conky_build_date, 0)
2737 END OBJ(conky_build_arch, 0)
2738 END OBJ(downspeed, INFO_NET)
2740 obj->data.net = get_net_stat(arg);
2742 CRIT_ERR("downspeed needs argument");
2744 END OBJ(downspeedf, INFO_NET)
2746 obj->data.net = get_net_stat(arg);
2748 CRIT_ERR("downspeedf needs argument");
2750 END OBJ(downspeedgraph, INFO_NET)
2751 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2755 obj->data.net = get_net_stat(buf);
2760 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos =
2762 blockstart[blockdepth - 1] = object_count;
2763 obj->data.ifblock.pos = object_count + 2;
2765 ERR("$else: no matching $if_*");
2770 text_objects[blockstart[blockdepth]].data.ifblock.pos =
2773 ERR("$endif: no matching $if_*");
2776 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2779 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2781 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2783 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2784 END OBJ(execgraph, 0)
2785 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2786 END OBJ(execibar, 0)
2789 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2792 ERR("${execibar <interval> command}");
2793 obj->type = OBJ_text;
2794 snprintf(buf, 256, "${%s}", s);
2795 obj->data.s = strndup(buf, text_buffer_size);
2797 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2799 END OBJ(execigraph, 0)
2802 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2805 ERR("${execigraph <interval> command}");
2806 obj->type = OBJ_text;
2807 snprintf(buf, 256, "${%s}", s);
2808 obj->data.s = strndup(buf, text_buffer_size);
2810 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2815 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2818 ERR("${execi <interval> command}");
2819 obj->type = OBJ_text;
2820 snprintf(buf, 256, "${%s}", s);
2821 obj->data.s = strndup(buf, text_buffer_size);
2823 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2824 obj->data.execi.buffer = malloc(text_buffer_size);
2829 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2832 ERR("${execi <interval> command}");
2833 obj->type = OBJ_text;
2834 snprintf(buf, 256, "${%s}", s);
2835 obj->data.s = strndup(buf, text_buffer_size);
2837 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2838 obj->data.execi.buffer = malloc(text_buffer_size);
2843 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2846 ERR("${texeci <interval> command}");
2847 obj->type = OBJ_text;
2848 snprintf(buf, 256, "${%s}", s);
2849 obj->data.s = strndup(buf, text_buffer_size);
2851 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
2852 obj->data.texeci.buffer = malloc(text_buffer_size);
2854 obj->data.texeci.p_timed_thread = NULL;
2855 END OBJ(pre_exec, 0)
2856 obj->type = OBJ_text;
2858 FILE *fp = popen(arg, "r");
2862 n = fread(buf, 1, 2048, fp);
2865 if (n && buf[n - 1] == '\n') {
2871 obj->data.s = strndup(buf, text_buffer_size);
2873 obj->data.s = strndup("", text_buffer_size);
2876 END OBJ(fs_bar, INFO_FS)
2877 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2879 while (isspace(*arg)) {
2888 obj->data.fsbar.fs = prepare_fs_stat(arg);
2889 END OBJ(fs_bar_free, INFO_FS)
2890 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2892 while (isspace(*arg)) {
2902 obj->data.fsbar.fs = prepare_fs_stat(arg);
2903 END OBJ(fs_free, INFO_FS)
2907 obj->data.fs = prepare_fs_stat(arg);
2908 END OBJ(fs_used_perc, INFO_FS)
2912 obj->data.fs = prepare_fs_stat(arg);
2913 END OBJ(fs_free_perc, INFO_FS)
2917 obj->data.fs = prepare_fs_stat(arg);
2918 END OBJ(fs_size, INFO_FS)
2922 obj->data.fs = prepare_fs_stat(arg);
2923 END OBJ(fs_type, INFO_FS)
2927 obj->data.fs = prepare_fs_stat(arg);
2928 END OBJ(fs_used, INFO_FS)
2932 obj->data.fs = prepare_fs_stat(arg);
2934 obj->data.i = arg ? atoi(arg) : 1;
2935 END OBJ(nameserver, INFO_DNS)
2936 obj->data.i = arg ? atoi(arg) : 0;
2938 obj->data.i = arg ? atoi(arg) : 1;
2940 obj->data.i = arg ? atoi(arg) : 1;
2944 ERR("goto needs arguments");
2945 obj->type = OBJ_text;
2946 obj->data.s = strndup("${goto}", text_buffer_size);
2950 obj->data.i = atoi(arg);
2956 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2957 sscanf(arg, "%d", &b);
2963 obj->data.pair.a = a;
2964 obj->data.pair.b = b;
2967 END OBJ(i2c, INFO_SYSFS)
2968 char buf1[64], buf2[64];
2972 ERR("i2c needs arguments");
2973 obj->type = OBJ_text;
2974 // obj->data.s = strndup("${i2c}", text_buffer_size);
2978 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2979 /* if scanf couldn't read three values, read type and num and use
2981 sscanf(arg, "%63s %d", buf2, &n);
2982 obj->data.sysfs.fd = open_i2c_sensor(0, buf2, n,
2983 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2984 strncpy(obj->data.sysfs.type, buf2, 63);
2986 obj->data.sysfs.fd = open_i2c_sensor(buf1, buf2, n,
2987 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2988 strncpy(obj->data.sysfs.type, buf2, 63);
2991 END OBJ(platform, INFO_SYSFS)
2992 char buf1[64], buf2[64];
2996 ERR("platform needs arguments");
2997 obj->type = OBJ_text;
3001 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
3002 /* if scanf couldn't read three values, read type and num and use
3004 sscanf(arg, "%63s %d", buf2, &n);
3005 obj->data.sysfs.fd = open_platform_sensor(0, buf2, n,
3006 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3007 strncpy(obj->data.sysfs.type, buf2, 63);
3009 obj->data.sysfs.fd = open_platform_sensor(buf1, buf2, n,
3010 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3011 strncpy(obj->data.sysfs.type, buf2, 63);
3014 END OBJ(hwmon, INFO_SYSFS)
3015 char buf1[64], buf2[64];
3019 ERR("hwmon needs argumanets");
3020 obj->type = OBJ_text;
3024 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
3025 /* if scanf couldn't read three values, read type and num and use
3027 sscanf(arg, "%63s %d", buf2, &n);
3028 obj->data.sysfs.fd = open_hwmon_sensor(0, buf2, n,
3029 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3030 strncpy(obj->data.sysfs.type, buf2, 63);
3032 obj->data.sysfs.fd = open_hwmon_sensor(buf1, buf2, n,
3033 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3034 strncpy(obj->data.sysfs.type, buf2, 63);
3036 #endif /* !__OpenBSD__ */
3038 END OBJ(top, INFO_TOP)
3043 ERR("top needs arguments");
3044 obj->type = OBJ_text;
3045 // obj->data.s = strndup("${top}", text_buffer_size);
3048 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
3049 if (strcmp(buf, "name") == 0) {
3050 obj->data.top.type = TOP_NAME;
3051 } else if (strcmp(buf, "cpu") == 0) {
3052 obj->data.top.type = TOP_CPU;
3053 } else if (strcmp(buf, "pid") == 0) {
3054 obj->data.top.type = TOP_PID;
3055 } else if (strcmp(buf, "mem") == 0) {
3056 obj->data.top.type = TOP_MEM;
3057 } else if (strcmp(buf, "time") == 0) {
3058 obj->data.top.type = TOP_TIME;
3059 } else if (strcmp(buf, "mem_res") == 0) {
3060 obj->data.top.type = TOP_MEM_RES;
3061 } else if (strcmp(buf, "mem_vsize") == 0) {
3062 obj->data.top.type = TOP_MEM_VSIZE;
3064 ERR("invalid arg for top");
3067 if (n < 1 || n > 10) {
3068 CRIT_ERR("invalid arg for top");
3071 obj->data.top.num = n - 1;
3075 ERR("invalid args given for top");
3078 END OBJ(top_mem, INFO_TOP)
3083 ERR("top_mem needs arguments");
3084 obj->type = OBJ_text;
3085 obj->data.s = strndup("${top_mem}", text_buffer_size);
3088 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
3089 if (strcmp(buf, "name") == 0) {
3090 obj->data.top.type = TOP_NAME;
3091 } else if (strcmp(buf, "cpu") == 0) {
3092 obj->data.top.type = TOP_CPU;
3093 } else if (strcmp(buf, "pid") == 0) {
3094 obj->data.top.type = TOP_PID;
3095 } else if (strcmp(buf, "mem") == 0) {
3096 obj->data.top.type = TOP_MEM;
3097 } else if (strcmp(buf, "time") == 0) {
3098 obj->data.top.type = TOP_TIME;
3099 } else if (strcmp(buf, "mem_res") == 0) {
3100 obj->data.top.type = TOP_MEM_RES;
3101 } else if (strcmp(buf, "mem_vsize") == 0) {
3102 obj->data.top.type = TOP_MEM_VSIZE;
3104 ERR("invalid arg for top");
3107 if (n < 1 || n > 10) {
3108 CRIT_ERR("invalid arg for top");
3111 obj->data.top.num = n - 1;
3115 ERR("invalid args given for top");
3118 END OBJ(addr, INFO_NET)
3120 obj->data.net = get_net_stat(arg);
3122 CRIT_ERR("addr needs argument");
3124 #if defined(__linux__)
3125 END OBJ(addrs, INFO_NET)
3127 obj->data.net = get_net_stat(arg);
3129 CRIT_ERR("addrs needs argument");
3131 #endif /* __linux__ */
3138 ERR("tail needs arguments");
3139 obj->type = OBJ_text;
3140 obj->data.s = strndup("${tail}", text_buffer_size);
3143 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3144 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3145 CRIT_ERR("invalid arg for tail, number of lines must be "
3146 "between 1 and %i", MAX_TAIL_LINES);
3152 obj->data.tail.fd = -1;
3154 if (stat(buf, &st) == 0) {
3155 if (S_ISFIFO(st.st_mode)) {
3156 fd = open(buf, O_RDONLY | O_NONBLOCK);
3159 CRIT_ERR("tail logfile does not exist, or you do "
3160 "not have correct permissions");
3163 obj->data.tail.fd = fd;
3165 fp = fopen(buf, "r");
3169 if (fp || obj->data.tail.fd != -1) {
3170 obj->data.tail.logfile = malloc(text_buffer_size);
3171 strcpy(obj->data.tail.logfile, buf);
3172 obj->data.tail.wantedlines = n1;
3173 obj->data.tail.interval = update_interval * 2;
3175 if (obj->data.tail.fd == -1) {
3180 CRIT_ERR("tail logfile does not exist, or you do not have "
3181 "correct permissions");
3184 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3185 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3186 CRIT_ERR("invalid arg for tail, number of lines must be "
3187 "between 1 and %i", MAX_TAIL_LINES);
3189 } else if (n2 < 1 || n2 < update_interval) {
3190 CRIT_ERR("invalid arg for tail, interval must be greater than "
3191 "0 and Conky's interval");
3197 obj->data.tail.fd = -1;
3199 if (stat(buf, &st) == 0) {
3200 if (S_ISFIFO(st.st_mode)) {
3201 fd = open(buf, O_RDONLY | O_NONBLOCK);
3204 CRIT_ERR("tail logfile does not exist, or you do "
3205 "not have correct permissions");
3208 obj->data.tail.fd = fd;
3210 fp = fopen(buf, "r");
3214 if (fp || obj->data.tail.fd != -1) {
3215 obj->data.tail.logfile = malloc(text_buffer_size);
3216 strcpy(obj->data.tail.logfile, buf);
3217 obj->data.tail.wantedlines = n1;
3218 obj->data.tail.interval = n2;
3220 if (obj->data.tail.fd == -1) {
3225 CRIT_ERR("tail logfile does not exist, or you do not have "
3226 "correct permissions");
3230 ERR("invalid args given for tail");
3233 /* asumming all else worked */
3234 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3240 ERR("head needs arguments");
3241 obj->type = OBJ_text;
3242 obj->data.s = strndup("${head}", text_buffer_size);
3245 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3246 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3247 CRIT_ERR("invalid arg for head, number of lines must be "
3248 "between 1 and %i", MAX_TAIL_LINES);
3253 fp = fopen(buf, "r");
3255 obj->data.tail.logfile = malloc(text_buffer_size);
3256 strcpy(obj->data.tail.logfile, buf);
3257 obj->data.tail.wantedlines = n1;
3258 obj->data.tail.interval = update_interval * 2;
3262 CRIT_ERR("head logfile does not exist, or you do not have "
3263 "correct permissions");
3266 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3267 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3268 CRIT_ERR("invalid arg for head, number of lines must be "
3269 "between 1 and %i", MAX_TAIL_LINES);
3271 } else if (n2 < 1 || n2 < update_interval) {
3272 CRIT_ERR("invalid arg for head, interval must be greater than "
3273 "0 and Conky's interval");
3278 fp = fopen(buf, "r");
3280 obj->data.tail.logfile = malloc(text_buffer_size);
3281 strcpy(obj->data.tail.logfile, buf);
3282 obj->data.tail.wantedlines = n1;
3283 obj->data.tail.interval = n2;
3287 CRIT_ERR("head logfile does not exist, or you do not have "
3288 "correct permissions");
3292 ERR("invalid args given for head");
3295 /* asumming all else worked */
3296 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3297 END OBJ(loadavg, INFO_LOADAVG)
3298 int a = 1, b = 2, c = 3, r = 3;
3301 r = sscanf(arg, "%d %d %d", &a, &b, &c);
3302 if (r >= 3 && (c < 1 || c > 3)) {
3305 if (r >= 2 && (b < 1 || b > 3)) {
3308 if (r >= 1 && (a < 1 || a > 3)) {
3312 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
3313 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
3314 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
3315 END OBJ(if_empty, 0)
3316 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3317 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3320 ERR("if_empty needs an argument");
3321 obj->data.ifblock.s = 0;
3323 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3325 blockstart[blockdepth] = object_count;
3326 obj->data.ifblock.pos = object_count + 2;
3328 END OBJ(if_existing, 0)
3329 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3330 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3333 ERR("if_existing needs an argument or two");
3334 obj->data.ifblock.s = NULL;
3335 obj->data.ifblock.str = NULL;
3337 char buf1[256], buf2[256];
3338 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3341 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
3342 obj->data.ifblock.str = NULL;
3344 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
3345 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
3348 blockstart[blockdepth] = object_count;
3349 obj->data.ifblock.pos = object_count + 2;
3351 END OBJ(if_mounted, 0)
3352 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3353 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3356 ERR("if_mounted needs an argument");
3357 obj->data.ifblock.s = 0;
3359 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3361 blockstart[blockdepth] = object_count;
3362 obj->data.ifblock.pos = object_count + 2;
3364 END OBJ(if_running, 0)
3365 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3366 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3371 snprintf(buf, 256, "pidof %s >/dev/null", arg);
3372 obj->data.ifblock.s = strndup(buf, text_buffer_size);
3374 ERR("if_running needs an argument");
3375 obj->data.ifblock.s = 0;
3377 blockstart[blockdepth] = object_count;
3378 obj->data.ifblock.pos = object_count + 2;
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(mboxscan, 0)
3405 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
3406 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
3407 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
3408 obj->data.mboxscan.output[0] = 1;
3409 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
3410 END OBJ(mem, INFO_MEM)
3411 END OBJ(memmax, INFO_MEM)
3412 END OBJ(memperc, INFO_MEM)
3413 END OBJ(membar, INFO_MEM)
3414 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3415 END OBJ(memgraph, INFO_MEM)
3416 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3422 END OBJ(mixer, INFO_MIXER)
3423 obj->data.l = mixer_init(arg);
3424 END OBJ(mixerl, INFO_MIXER)
3425 obj->data.l = mixer_init(arg);
3426 END OBJ(mixerr, INFO_MIXER)
3427 obj->data.l = mixer_init(arg);
3428 END OBJ(mixerbar, INFO_MIXER)
3429 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3430 &obj->data.mixerbar.h);
3431 END OBJ(mixerlbar, INFO_MIXER)
3432 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3433 &obj->data.mixerbar.h);
3434 END OBJ(mixerrbar, INFO_MIXER)
3435 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3436 &obj->data.mixerbar.h);
3437 END OBJ(new_mails, 0)
3439 char box[256], dst[256];
3443 /* Kapil: Changed from MAIL_FILE to
3444 current_mail_spool since the latter
3445 is a copy of the former if undefined
3446 but the latter should take precedence
3448 strncpy(box, current_mail_spool, sizeof(box));
3450 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3452 strncpy(box, arg, sizeof(box));
3456 variable_substitute(box, dst, sizeof(dst));
3457 obj->data.local_mail.box = strndup(dst, text_buffer_size);
3458 obj->data.local_mail.interval = n1;
3459 END OBJ(nodename, 0)
3460 END OBJ(processes, INFO_PROCS)
3461 END OBJ(running_processes, INFO_RUN_PROCS)
3462 END OBJ(shadecolor, 0)
3464 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
3466 END OBJ(outlinecolor, 0)
3468 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
3470 END OBJ(stippled_hr, 0)
3472 int a = stippled_borders, b = 1;
3475 if (sscanf(arg, "%d %d", &a, &b) != 2) {
3476 sscanf(arg, "%d", &b);
3482 obj->data.pair.a = a;
3483 obj->data.pair.b = b;
3485 END OBJ(swap, INFO_MEM)
3486 END OBJ(swapmax, INFO_MEM)
3487 END OBJ(swapperc, INFO_MEM)
3488 END OBJ(swapbar, INFO_MEM)
3489 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3492 END OBJ(temp1, INFO_SYSFS)
3493 obj->type = OBJ_i2c;
3494 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 1,
3495 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3496 END OBJ(temp2, INFO_SYSFS)
3497 obj->type = OBJ_i2c;
3498 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 2,
3499 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3502 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
3504 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
3506 char buf1[256], buf2[256], *fmt, *tz;
3510 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3520 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
3521 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
3523 END OBJ(iconv_start, 0)
3524 if (iconv_converting) {
3525 CRIT_ERR("You must stop your last iconv conversion before "
3526 "starting another");
3529 char iconv_from[CODEPAGE_LENGTH];
3530 char iconv_to[CODEPAGE_LENGTH];
3532 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3533 CRIT_ERR("Invalid arguments for iconv_start");
3537 new_iconv = iconv_open(iconv_to, iconv_from);
3538 if (new_iconv == (iconv_t) (-1)) {
3539 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3541 obj->a = register_iconv(&new_iconv);
3542 iconv_converting = 1;
3546 CRIT_ERR("Iconv requires arguments");
3548 END OBJ(iconv_stop, 0)
3549 iconv_converting = 0;
3552 END OBJ(totaldown, INFO_NET)
3554 obj->data.net = get_net_stat(arg);
3556 CRIT_ERR("totaldown needs argument");
3558 END OBJ(totalup, INFO_NET)
3559 obj->data.net = get_net_stat(arg);
3561 obj->data.net = get_net_stat(arg);
3563 CRIT_ERR("totalup needs argument");
3567 obj->data.i = arg ? atoi(arg) : 0;
3569 obj->data.i = arg ? atoi(arg) : 0;
3570 END OBJ(upspeed, INFO_NET)
3572 obj->data.net = get_net_stat(arg);
3574 CRIT_ERR("upspeed needs argument");
3576 END OBJ(upspeedf, INFO_NET)
3578 obj->data.net = get_net_stat(arg);
3580 CRIT_ERR("upspeedf needs argument");
3583 END OBJ(upspeedgraph, INFO_NET)
3584 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3588 obj->data.net = get_net_stat(buf);
3591 END OBJ(uptime_short, INFO_UPTIME)
3592 END OBJ(uptime, INFO_UPTIME)
3593 END OBJ(user_names, INFO_USERS)
3594 END OBJ(user_times, INFO_USERS)
3595 END OBJ(user_terms, INFO_USERS)
3596 END OBJ(user_number, INFO_USERS)
3597 #if defined(__linux__)
3598 END OBJ(gw_iface, INFO_GW)
3599 END OBJ(gw_ip, INFO_GW)
3600 END OBJ(if_gw, INFO_GW)
3601 #endif /* !__linux__ */
3603 END OBJ(adt746xcpu, 0)
3604 END OBJ(adt746xfan, 0)
3605 #endif /* !__OpenBSD__ */
3606 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
3607 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3608 END OBJ(apm_adapter, 0)
3609 END OBJ(apm_battery_life, 0)
3610 END OBJ(apm_battery_time, 0)
3611 #endif /* __FreeBSD__ */
3612 END OBJ(imap_unseen, 0)
3615 obj->data.mail = parse_mail_args(IMAP, arg);
3616 obj->global_mode = 0;
3618 obj->global_mode = 1;
3620 END OBJ(imap_messages, 0)
3623 obj->data.mail = parse_mail_args(IMAP, arg);
3624 obj->global_mode = 0;
3626 obj->global_mode = 1;
3628 END OBJ(pop3_unseen, 0)
3631 obj->data.mail = parse_mail_args(POP3, arg);
3632 obj->global_mode = 0;
3634 obj->global_mode = 1;
3636 END OBJ(pop3_used, 0)
3639 obj->data.mail = parse_mail_args(POP3, arg);
3640 obj->global_mode = 0;
3642 obj->global_mode = 1;
3647 obj->data.s = strndup(arg, text_buffer_size);
3649 ERR("smapi needs an argument");
3650 END OBJ(if_smapi_bat_installed, 0)
3651 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3652 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3655 ERR("if_smapi_bat_installed needs an argument");
3656 obj->data.ifblock.s = 0;
3658 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3659 blockstart[blockdepth] = object_count;
3660 obj->data.ifblock.pos = object_count + 2;
3662 END OBJ(smapi_bat_perc, 0)
3664 obj->data.s = strndup(arg, text_buffer_size);
3666 ERR("smapi_bat_perc needs an argument");
3667 END OBJ(smapi_bat_bar, 0)
3670 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
3671 ERR("first argument to smapi_bat_bar must be an integer value");
3675 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
3678 ERR("if_smapi_bat_bar needs an argument");
3681 END OBJ(mpd_artist, INFO_MPD)
3682 END OBJ(mpd_title, INFO_MPD)
3684 sscanf(arg, "%d", &info.mpd.max_title_len);
3685 if (info.mpd.max_title_len > 0) {
3686 info.mpd.max_title_len++;
3688 CRIT_ERR("mpd_title: invalid length argument");
3691 info.mpd.max_title_len = 0;
3693 END OBJ(mpd_random, INFO_MPD)
3694 END OBJ(mpd_repeat, INFO_MPD)
3695 END OBJ(mpd_elapsed, INFO_MPD)
3696 END OBJ(mpd_length, INFO_MPD)
3697 END OBJ(mpd_track, INFO_MPD)
3698 END OBJ(mpd_name, INFO_MPD)
3699 END OBJ(mpd_file, INFO_MPD)
3700 END OBJ(mpd_percent, INFO_MPD)
3701 END OBJ(mpd_album, INFO_MPD)
3702 END OBJ(mpd_vol, INFO_MPD)
3703 END OBJ(mpd_bitrate, INFO_MPD)
3704 END OBJ(mpd_status, INFO_MPD)
3705 END OBJ(mpd_bar, INFO_MPD)
3706 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3707 END OBJ(mpd_smart, INFO_MPD)
3710 END OBJ(xmms2_artist, INFO_XMMS2)
3711 END OBJ(xmms2_album, INFO_XMMS2)
3712 END OBJ(xmms2_title, INFO_XMMS2)
3713 END OBJ(xmms2_genre, INFO_XMMS2)
3714 END OBJ(xmms2_comment, INFO_XMMS2)
3715 END OBJ(xmms2_url, INFO_XMMS2)
3716 END OBJ(xmms2_tracknr, INFO_XMMS2)
3717 END OBJ(xmms2_bitrate, INFO_XMMS2)
3718 END OBJ(xmms2_date, INFO_XMMS2)
3719 END OBJ(xmms2_id, INFO_XMMS2)
3720 END OBJ(xmms2_duration, INFO_XMMS2)
3721 END OBJ(xmms2_elapsed, INFO_XMMS2)
3722 END OBJ(xmms2_size, INFO_XMMS2)
3723 END OBJ(xmms2_status, INFO_XMMS2)
3724 END OBJ(xmms2_percent, INFO_XMMS2)
3725 END OBJ(xmms2_bar, INFO_XMMS2)
3726 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3727 END OBJ(xmms2_smart, INFO_XMMS2)
3728 END OBJ(xmms2_playlist, INFO_XMMS2)
3729 END OBJ(xmms2_timesplayed, INFO_XMMS2)
3732 END OBJ(audacious_status, INFO_AUDACIOUS)
3733 END OBJ(audacious_title, INFO_AUDACIOUS)
3735 sscanf(arg, "%d", &info.audacious.max_title_len);
3736 if (info.audacious.max_title_len > 0) {
3737 info.audacious.max_title_len++;
3739 CRIT_ERR("audacious_title: invalid length argument");
3742 END OBJ(audacious_length, INFO_AUDACIOUS)
3743 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
3744 END OBJ(audacious_position, INFO_AUDACIOUS)
3745 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
3746 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
3747 END OBJ(audacious_frequency, INFO_AUDACIOUS)
3748 END OBJ(audacious_channels, INFO_AUDACIOUS)
3749 END OBJ(audacious_filename, INFO_AUDACIOUS)
3750 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
3751 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
3752 END OBJ(audacious_bar, INFO_AUDACIOUS)
3753 scan_bar(arg, &obj->a, &obj->b);
3756 END OBJ(bmpx_title, INFO_BMPX)
3757 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3758 END OBJ(bmpx_artist, INFO_BMPX)
3759 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3760 END OBJ(bmpx_album, INFO_BMPX)
3761 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3762 END OBJ(bmpx_track, INFO_BMPX)
3763 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3764 END OBJ(bmpx_uri, INFO_BMPX)
3765 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3766 END OBJ(bmpx_bitrate, INFO_BMPX)
3767 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3772 int argc, delay, act_par;
3773 char *uri = (char *) malloc(128 * sizeof(char));
3774 char *action = (char *) malloc(64 * sizeof(char));
3776 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action,
3778 obj->data.rss.uri = uri;
3779 obj->data.rss.delay = delay;
3780 obj->data.rss.action = action;
3781 obj->data.rss.act_par = act_par;
3785 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
3791 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3792 &obj->data.hddtemp.addr, &obj->data.hddtemp.port, &obj->data.hddtemp.temp)) {
3793 ERR("hddtemp needs arguments");
3794 obj->type = OBJ_text;
3795 obj->data.s = strndup("${hddtemp}", text_buffer_size);
3796 obj->data.hddtemp.update_time = 0;
3800 #ifdef TCP_PORT_MONITOR
3801 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3802 int argc, port_begin, port_end, item, connection_index;
3805 memset(itembuf, 0, sizeof(itembuf));
3806 connection_index = 0;
3807 /* massive argument checking */
3809 CRIT_ERR("tcp_portmon: needs arguments");
3811 argc = sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf,
3813 if ((argc != 3) && (argc != 4)) {
3814 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3816 if ((port_begin < 1) || (port_begin > 65535) || (port_end < 1)
3817 || (port_end > 65535)) {
3818 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3820 if (port_begin > port_end) {
3821 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3823 if (strncmp(itembuf, "count", 31) == 0) {
3825 } else if (strncmp(itembuf, "rip", 31) == 0) {
3827 } else if (strncmp(itembuf, "rhost", 31) == 0) {
3829 } else if (strncmp(itembuf, "rport", 31) == 0) {
3831 } else if (strncmp(itembuf, "rservice", 31) == 0) {
3832 item = REMOTESERVICE;
3833 } else if (strncmp(itembuf, "lip", 31) == 0) {
3835 } else if (strncmp(itembuf, "lhost", 31) == 0) {
3837 } else if (strncmp(itembuf, "lport", 31) == 0) {
3839 } else if (strncmp(itembuf, "lservice", 31) == 0) {
3840 item = LOCALSERVICE;
3842 CRIT_ERR("tcp_portmon: invalid item specified");
3844 if ((argc == 3) && (item != COUNT)) {
3845 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" "
3848 if ((argc == 4) && (connection_index < 0)) {
3849 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3851 /* ok, args looks good. save the text object data */
3852 obj->data.tcp_port_monitor.port_range_begin = (in_port_t) port_begin;
3853 obj->data.tcp_port_monitor.port_range_end = (in_port_t) port_end;
3854 obj->data.tcp_port_monitor.item = item;
3855 obj->data.tcp_port_monitor.connection_index = connection_index;
3857 /* if the port monitor collection hasn't been created,
3858 * we must create it */
3859 if (!info.p_tcp_port_monitor_collection) {
3860 info.p_tcp_port_monitor_collection =
3861 create_tcp_port_monitor_collection();
3862 if (!info.p_tcp_port_monitor_collection) {
3863 CRIT_ERR("tcp_portmon: unable to create port monitor "
3868 /* if a port monitor for this port does not exist,
3869 * create one and add it to the collection */
3870 if (find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
3871 port_begin, port_end) == NULL) {
3872 tcp_port_monitor_t *p_monitor = create_tcp_port_monitor(port_begin,
3873 port_end, &tcp_port_monitor_args);
3876 CRIT_ERR("tcp_portmon: unable to create port monitor");
3878 /* add the newly created monitor to the collection */
3879 if (insert_tcp_port_monitor_into_collection(
3880 info.p_tcp_port_monitor_collection, p_monitor) != 0) {
3881 CRIT_ERR("tcp_portmon: unable to add port monitor to "
3886 END OBJ(entropy_avail, INFO_ENTROPY)
3887 END OBJ(entropy_poolsize, INFO_ENTROPY)
3888 END OBJ(entropy_bar, INFO_ENTROPY)
3889 scan_bar(arg, &obj->a, &obj->b);
3893 CRIT_ERR("nvidia needs one argument "
3894 "[temp,threshold,gpufreq,memfreq,imagequality]");
3896 if (strcmp(arg, "temp") == 0)
3897 obj->data.nvidia.type = NV_TEMP;
3898 else if (strcmp(arg, "threshold") == 0)
3899 obj->data.nvidia.type = NV_TEMP_THRESHOLD;
3900 else if (strcmp(arg, "gpufreq") == 0)
3901 obj->data.nvidia.type = NV_GPU_FREQ;
3902 else if (strcmp(arg, "memfreq") == 0)
3903 obj->data.nvidia.type = NV_MEM_FREQ;
3904 else if (strcmp(arg, "imagequality") == 0)
3905 obj->data.nvidia.type = NV_IMAGE_QUALITY;
3907 CRIT_ERR("you have to give one of these arguments "
3908 "[temp,threshold,gpufreq,memfreq,imagequality");
3909 strncpy((char*)&obj->data.nvidia.arg, arg, 20);
3915 ERR("unknown variable %s", s);
3916 obj->type = OBJ_text;
3917 snprintf(buf, 256, "${%s}", s);
3918 obj->data.s = strndup(buf, text_buffer_size);
3925 static struct text_object *create_plain_text(const char *s)
3927 struct text_object *obj;
3929 if (s == NULL || *s == '\0') {
3933 obj = new_text_object_internal();
3935 obj->type = OBJ_text;
3936 obj->data.s = strndup(s, text_buffer_size);
3940 static struct text_object_list *extract_variable_text_internal(const char *const_p)
3942 struct text_object_list *retval;
3943 struct text_object *obj;
3944 char *p, *s, *orig_p;
3947 p = strndup(const_p, max_user_text);
3950 retval = malloc(sizeof(struct text_object_list));
3951 memset(retval, 0, sizeof(struct text_object_list));
3952 retval->text_object_count = 0;
3962 obj = create_plain_text(s);
3964 // allocate memory for the object
3965 retval->text_objects = realloc(retval->text_objects,
3966 sizeof(struct text_object) *
3967 (retval->text_object_count + 1));
3968 // assign the new object to the end of the list.
3969 memcpy(&retval->text_objects[retval->text_object_count++], obj,
3970 sizeof(struct text_object));
3982 /* variable is either $foo or ${foo} */
3984 unsigned int brl = 1, brr = 0;
3988 while (*p && brl != brr) {
4003 while (*p && (isalnum((int) *p) || *p == '_')) {
4008 /* copy variable to buffer */
4009 len = (p - s > 255) ? 255 : (p - s);
4010 strncpy(buf, s, len);
4020 /* if variable wasn't found in environment, use some special */
4026 if (strchr(buf, ' ')) {
4027 arg = strchr(buf, ' ');
4030 while (isspace((int) *arg)) {
4038 /* lowercase variable name */
4041 *tmp_p = tolower(*tmp_p);
4045 // create new object
4046 obj = construct_text_object(buf, arg,
4047 retval->text_object_count, retval->text_objects, line);
4049 // allocate memory for the object
4050 retval->text_objects = realloc(retval->text_objects,
4051 sizeof(struct text_object) *
4052 (retval->text_object_count + 1));
4053 // assign the new object to the end of the list.
4055 &retval->text_objects[retval->text_object_count++],
4056 obj, sizeof(struct text_object));
4062 obj = create_plain_text("$");
4064 // allocate memory for the object
4065 retval->text_objects = realloc(retval->text_objects,
4066 sizeof(struct text_object) *
4067 (retval->text_object_count + 1));
4068 // assign the new object to the end of the list.
4069 memcpy(&retval->text_objects[retval->text_object_count++],
4070 obj, sizeof(struct text_object));
4077 obj = create_plain_text(s);
4079 // allocate memory for the object
4080 retval->text_objects = realloc(retval->text_objects,
4081 sizeof(struct text_object) * (retval->text_object_count + 1));
4082 // assign the new object to the end of the list.
4083 memcpy(&retval->text_objects[retval->text_object_count++], obj,
4084 sizeof(struct text_object));
4089 ERR("one or more $endif's are missing");
4096 static void extract_variable_text(const char *p)
4098 struct text_object_list *list;
4100 free_text_objects(global_text_object_count, global_text_objects);
4113 global_text_object_count = 0;
4114 global_text_objects = NULL;
4116 list = extract_variable_text_internal(p);
4117 global_text_objects = list->text_objects;
4118 global_text_object_count = list->text_object_count;
4123 struct text_object_list *parse_conky_vars(char *txt, char *p, struct information *cur)
4125 struct text_object_list *object_list =
4126 extract_variable_text_internal(txt);
4128 generate_text_internal(p, max_user_text, object_list->text_objects,
4129 object_list->text_object_count, cur);
4133 /* Allows reading from a FIFO (i.e., /dev/xconsole).
4134 * The file descriptor is set to non-blocking which makes this possible.
4136 * FIXME: Since lseek cannot seek a file descriptor long lines will break. */
4137 static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
4139 #define TAIL_PIPE_BUFSIZE 4096
4143 int fd = obj->data.tail.fd;
4146 char buf[TAIL_PIPE_BUFSIZE];
4147 ssize_t len = read(fd, buf, sizeof(buf));
4151 if (errno != EAGAIN) {
4152 strcpy(obj->data.tail.buffer, "Logfile Read Error");
4153 snprintf(dst, dst_size, "Logfile Read Error");
4157 } else if (len == 0) {
4158 strcpy(obj->data.tail.buffer, "Logfile Empty");
4159 snprintf(dst, dst_size, "Logfile Empty");
4163 for (line_len = 0, i = 0; i < len; i++) {
4167 if (buf[i] == '\n') {
4170 if (obj->data.tail.readlines > 0) {
4175 for (n = 0; obj->data.tail.buffer[n]; n++) {
4176 if (obj->data.tail.buffer[n] == '\n') {
4181 if (++olines < obj->data.tail.wantedlines) {
4187 p = obj->data.tail.buffer + first_line;
4188 pos = n - first_line;
4189 memmove(obj->data.tail.buffer,
4190 obj->data.tail.buffer + first_line, strlen(p));
4191 obj->data.tail.buffer[pos] = 0;
4197 p = buf + last_line;
4199 memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
4200 obj->data.tail.buffer[pos + line_len] = 0;
4203 obj->data.tail.readlines = lines;
4211 snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
4214 char *format_time(unsigned long timeval, const int width)
4217 unsigned long nt; // narrow time, for speed on 32-bit
4218 unsigned cc; // centiseconds
4219 unsigned nn; // multi-purpose whatever
4222 cc = nt % 100; // centiseconds past second
4223 nt /= 100; // total seconds
4224 nn = nt % 60; // seconds past the minute
4225 nt /= 60; // total minutes
4226 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
4228 return strndup(buf, text_buffer_size);
4230 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
4231 return strndup(buf, text_buffer_size);
4233 nn = nt % 60; // minutes past the hour
4234 nt /= 60; // total hours
4235 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
4236 return strndup(buf, text_buffer_size);
4238 nn = nt; // now also hours
4239 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
4240 return strndup(buf, text_buffer_size);
4242 nn /= 24; // now days
4243 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
4244 return strndup(buf, text_buffer_size);
4246 nn /= 7; // now weeks
4247 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
4248 return strndup(buf, text_buffer_size);
4250 // well shoot, this outta' fit...
4251 return strndup("<inf>", text_buffer_size);
4254 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
4255 //string has to end with \0 and it's length should fit in a int
4257 void remove_deleted_chars(char *string){
4259 while(string[i] != 0){
4260 if(string[i] == BACKSPACE){
4262 strcpy( &(string[i-1]), &(string[i+1]) );
4264 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
4269 static inline void format_media_player_time(char *buf, const int size,
4272 int days, hours, minutes;
4274 days = seconds / (24 * 60 * 60);
4275 seconds %= (24 * 60 * 60);
4276 hours = seconds / (60 * 60);
4277 seconds %= (60 * 60);
4278 minutes = seconds / 60;
4282 snprintf(buf, size, "%i days %i:%02i:%02i", days,
4283 hours, minutes, seconds);
4284 } else if (hours > 0) {
4285 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
4288 snprintf(buf, size, "%i:%02i", minutes, seconds);
4292 static void generate_text_internal(char *p, int p_max_size,
4293 struct text_object *objs, unsigned int object_count,
4294 struct information *cur)
4299 char buff_in[p_max_size];
4301 iconv_converting = 0;
4305 for (i = 0; i < object_count; i++) {
4306 struct text_object *obj = &objs[i];
4308 if (p_max_size < 1) {
4312 #define OBJ(a) break; case OBJ_##a:
4314 switch (obj->type) {
4316 ERR("not implemented obj type %d", obj->type);
4319 /* does anyone have decimals in acpi temperature? */
4320 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
4321 round_to_int(get_acpi_temperature(obj->data.i)));
4324 /* does anyone have decimals in acpi temperature? */
4325 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
4326 round_to_int((get_acpi_temperature(obj->data.i) + 40) *
4329 #endif /* !__OpenBSD__ */
4332 obj->a = get_freq(p, p_max_size, "%.0f", 1,
4333 obj->data.cpu_index);
4339 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
4340 obj->data.cpu_index);
4342 /* OpenBSD has no such flag (SUSv2) */
4343 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
4344 obj->data.cpu_index);
4348 #if defined(__linux__)
4351 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
4352 obj->data.cpu_index);
4357 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
4358 obj->data.cpu_index);
4363 OBJ(wireless_essid) {
4364 snprintf(p, p_max_size, "%s", obj->data.net->essid);
4366 OBJ(wireless_mode) {
4367 snprintf(p, p_max_size, "%s", obj->data.net->mode);
4369 OBJ(wireless_bitrate) {
4370 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
4373 snprintf(p, p_max_size, "%s", obj->data.net->ap);
4375 OBJ(wireless_link_qual) {
4376 spaced_print(p, p_max_size, "%d", 4, "wireless_link_qual",
4377 obj->data.net->link_qual);
4379 OBJ(wireless_link_qual_max) {
4380 spaced_print(p, p_max_size, "%d", 4,
4381 "wireless_link_qual_max", obj->data.net->link_qual_max);
4383 OBJ(wireless_link_qual_perc) {
4384 if (obj->data.net->link_qual_max > 0) {
4385 spaced_print(p, p_max_size, "%.0f", 5,
4386 "wireless_link_qual_perc",
4387 (double) obj->data.net->link_qual /
4388 obj->data.net->link_qual_max * 100);
4390 spaced_print(p, p_max_size, "unk", 5,
4391 "wireless_link_qual_perc");
4394 OBJ(wireless_link_bar) {
4395 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
4396 obj->data.net->link_qual_max) * 255.0);
4398 #endif /* HAVE_IWLIB */
4400 #endif /* __linux__ */
4403 get_freq_dynamic(p, p_max_size, "%.0f", 1);
4404 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4408 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
4410 get_freq_dynamic(p, p_max_size, "%.2f", 1000);
4412 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4417 get_adt746x_cpu(p, p_max_size);
4420 get_adt746x_fan(p, p_max_size);
4423 get_acpi_fan(p, p_max_size);
4425 OBJ(acpiacadapter) {
4426 get_acpi_ac_adapter(p, p_max_size);
4429 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
4432 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
4434 OBJ(battery_percent) {
4435 spaced_print(p, p_max_size, "%*d", 4, "battery_percent",
4436 pad_percents, get_battery_perct(obj->data.s));
4439 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
4441 #endif /* __OpenBSD__ */
4444 human_readable(cur->buffers * 1024, p, 255, "buffers");
4447 human_readable(cur->cached * 1024, p, 255, "buffers");
4450 if (obj->data.cpu_index > info.cpu_count) {
4451 printf("obj->data.cpu_index %i info.cpu_count %i",
4452 obj->data.cpu_index, info.cpu_count);
4453 CRIT_ERR("attempting to use more CPUs than you have!");
4455 spaced_print(p, p_max_size, "%*d", 4, "cpu", pad_percents,
4456 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
4459 new_bar(p, obj->a, obj->b,
4460 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
4463 new_graph(p, obj->a, obj->b, obj->c, obj->d, (unsigned int)
4464 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
4468 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
4472 new_fg(p, obj->data.l);
4504 OBJ(conky_version) {
4505 snprintf(p, p_max_size, "%s", VERSION);
4507 OBJ(conky_build_date) {
4508 snprintf(p, p_max_size, "%s", BUILD_DATE);
4510 OBJ(conky_build_arch) {
4511 snprintf(p, p_max_size, "%s", BUILD_ARCH);
4513 #if defined(__linux__)
4515 snprintf(p, p_max_size, "%s",
4516 get_disk_protect_queue(obj->data.s));
4519 snprintf(p, p_max_size, "%s", i8k.version);
4522 snprintf(p, p_max_size, "%s", i8k.bios);
4525 snprintf(p, p_max_size, "%s", i8k.serial);
4528 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
4530 OBJ(i8k_cpu_tempf) {
4533 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
4534 snprintf(p, p_max_size, "%.1f", cpu_temp * (9.0 / 5.0) + 32.0);
4536 OBJ(i8k_left_fan_status) {
4537 int left_fan_status;
4539 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
4540 if (left_fan_status == 0) {
4541 snprintf(p, p_max_size, "off");
4543 if (left_fan_status == 1) {
4544 snprintf(p, p_max_size, "low");
4546 if (left_fan_status == 2) {
4547 snprintf(p, p_max_size, "high");
4550 OBJ(i8k_right_fan_status) {
4551 int right_fan_status;
4553 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
4554 if (right_fan_status == 0) {
4555 snprintf(p, p_max_size, "off");
4557 if (right_fan_status == 1) {
4558 snprintf(p, p_max_size, "low");
4560 if (right_fan_status == 2) {
4561 snprintf(p, p_max_size, "high");
4564 OBJ(i8k_left_fan_rpm) {
4565 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
4567 OBJ(i8k_right_fan_rpm) {
4568 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
4570 OBJ(i8k_ac_status) {
4573 sscanf(i8k.ac_status, "%d", &ac_status);
4574 if (ac_status == -1) {
4575 snprintf(p, p_max_size, "disabled (read i8k docs)");
4577 if (ac_status == 0) {
4578 snprintf(p, p_max_size, "off");
4580 if (ac_status == 1) {
4581 snprintf(p, p_max_size, "on");
4584 OBJ(i8k_buttons_status) {
4585 snprintf(p, p_max_size, "%s", i8k.buttons_status);
4588 get_ibm_acpi_fan(p, p_max_size);
4591 get_ibm_acpi_temps();
4592 snprintf(p, p_max_size, "%d", ibm_acpi.temps[obj->data.sensor]);
4595 get_ibm_acpi_volume(p, p_max_size);
4597 OBJ(ibm_brightness) {
4598 get_ibm_acpi_brightness(p, p_max_size);
4601 if ((obj->data.ifblock.s)
4602 && (!interface_up(obj->data.ifblock.s))) {
4603 i = obj->data.ifblock.pos;
4610 if (!cur->gw_info.count) {
4611 i = obj->data.ifblock.pos;
4618 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
4621 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
4624 snprintf(p, p_max_size, "%d", get_laptop_mode());
4627 get_powerbook_batt_info(p, p_max_size, obj->data.i);
4629 #endif /* __linux__ */
4632 OBJ(obsd_sensors_temp) {
4633 obsd_sensors.device = sensor_device;
4634 update_obsd_sensors();
4635 snprintf(p, p_max_size, "%.1f",
4636 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
4638 OBJ(obsd_sensors_fan) {
4639 obsd_sensors.device = sensor_device;
4640 update_obsd_sensors();
4641 snprintf(p, p_max_size, "%d",
4642 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
4644 OBJ(obsd_sensors_volt) {
4645 obsd_sensors.device = sensor_device;
4646 update_obsd_sensors();
4647 snprintf(p, p_max_size, "%.2f",
4648 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4651 get_obsd_vendor(p, p_max_size);
4654 get_obsd_product(p, p_max_size);
4656 #endif /* __OpenBSD__ */
4660 new_font(p, obj->data.s);
4663 /* TODO: move this correction from kB to kB/s elsewhere
4664 * (or get rid of it??) */
4666 if (obj->data.diskio) {
4668 (obj->data.diskio->current / update_interval) * 1024LL,
4669 p, p_max_size, "diskio");
4671 human_readable(info.diskio_value * 1024LL, p, p_max_size,
4676 if (obj->data.diskio) {
4677 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL, p, p_max_size,
4680 human_readable(info.diskio_write_value * 1024LL, p, p_max_size,
4685 if (obj->data.diskio) {
4686 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL, p, p_max_size,
4689 human_readable(info.diskio_read_value * 1024LL, p, p_max_size,
4694 if (obj->data.diskio) {
4695 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4696 obj->data.diskio->current, obj->e, 1);
4698 new_graph(p, obj->a, obj->b, obj->c, obj->d, info.diskio_value,
4702 OBJ(diskiograph_read) {
4703 if (obj->data.diskio) {
4704 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4705 obj->data.diskio->current_read, obj->e, 1);
4707 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4708 info.diskio_read_value, obj->e, 1);
4711 OBJ(diskiograph_write) {
4712 if (obj->data.diskio) {
4713 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4714 obj->data.diskio->current_write, obj->e, 1);
4716 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4717 info.diskio_write_value, obj->e, 1);
4721 spaced_print(p, p_max_size, "%d", 6, "downspeed",
4722 round_to_int(obj->data.net->recv_speed / 1024));
4725 spaced_print(p, p_max_size, "%.1f", 8, "downspeedf",
4726 obj->data.net->recv_speed / 1024.0);
4728 OBJ(downspeedgraph) {
4729 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4730 obj->data.net->recv_speed / 1024.0, obj->e, 1);
4734 i = obj->data.ifblock.pos - 1;
4744 if ((obj->data.net->addr.sa_data[2] & 255) == 0
4745 && (obj->data.net->addr.sa_data[3] & 255) == 0
4746 && (obj->data.net->addr.sa_data[4] & 255) == 0
4747 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
4748 snprintf(p, p_max_size, "No Address");
4750 snprintf(p, p_max_size, "%u.%u.%u.%u",
4751 obj->data.net->addr.sa_data[2] & 255,
4752 obj->data.net->addr.sa_data[3] & 255,
4753 obj->data.net->addr.sa_data[4] & 255,
4754 obj->data.net->addr.sa_data[5] & 255);
4757 #if defined(__linux__)
4759 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
4761 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
4762 strcpy(p, obj->data.net->addrs);
4765 strcpy(p, "0.0.0.0");
4767 #endif /* __linux__ */
4769 #if defined(IMLIB2) && defined(X11)
4774 Imlib_Image image, buffer;
4776 image = imlib_load_image(obj->data.s);
4777 imlib_context_set_image(image);
4781 w = imlib_image_get_width();
4782 h = imlib_image_get_height();
4783 buffer = imlib_create_image(w, h);
4784 imlib_context_set_display(display);
4785 imlib_context_set_drawable(window.drawable);
4786 imlib_context_set_colormap(DefaultColormap(display,
4788 imlib_context_set_visual(DefaultVisual(display,
4790 imlib_context_set_image(buffer);
4791 imlib_blend_image_onto_image(image, 0, 0, 0, w, h,
4792 text_start_x, text_start_y, w, h);
4793 imlib_render_image_on_drawable(text_start_x,
4796 imlib_context_set_image(image);
4804 FILE *fp = popen(obj->data.s, "r");
4805 int length = fread(p, 1, p_max_size, fp);
4810 remove_deleted_chars(p);
4811 if (length > 0 && p[length - 1] == '\n') {
4812 p[length - 1] = '\0';
4817 struct information *my_info;
4818 struct text_object_list *text_objects;
4821 fp = popen(obj->data.s, "r");
4822 fread(p, 1, p_max_size, fp);
4825 my_info = malloc(sizeof(struct information));
4826 memcpy(my_info, cur, sizeof(struct information));
4827 text_objects = parse_conky_vars(p, p, my_info);
4832 if (length > 0 && p[length - 1] == '\n') {
4833 p[length - 1] = '\0';
4836 free_text_objects(text_objects->text_object_count, text_objects->text_objects);
4842 FILE *fp = popen(obj->data.s, "r");
4843 int n2 = fread(p, 1, p_max_size, fp);
4848 if (n2 && p[n2 - 1] == '\n') {
4853 if (*p2 == '\001') {
4859 if (sscanf(p, "%lf", &barnum) == 0) {
4860 ERR("reading execbar value failed (perhaps it's not the "
4861 "correct format?)");
4863 if (barnum > 100 || barnum < 0) {
4864 ERR("your execbar value is not between 0 and 100, "
4865 "therefore it will be ignored");
4867 barnum = barnum / 100.0;
4868 new_bar(p, 0, 4, (int) (barnum * 255.0));
4873 FILE *fp = popen(obj->data.s, "r");
4874 int n2 = fread(p, 1, p_max_size, fp);
4879 if (n2 && p[n2 - 1] == '\n') {
4883 if (*p2 == '\001') {
4889 if (sscanf(p, "%lf", &barnum) == 0) {
4890 ERR("reading execgraph value failed (perhaps it's not the "
4891 "correct format?)");
4893 if (barnum > 100 || barnum < 0) {
4894 ERR("your execgraph value is not between 0 and 100, "
4895 "therefore it will be ignored");
4897 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), 100, 1);
4901 if (current_update_time - obj->data.execi.last_update
4902 < obj->data.execi.interval) {
4903 new_bar(p, 0, 4, (int) obj->f);
4906 FILE *fp = popen(obj->data.execi.cmd, "r");
4907 int n2 = fread(p, 1, p_max_size, fp);
4912 if (n2 && p[n2 - 1] == '\n') {
4917 if (*p2 == '\001') {
4923 if (sscanf(p, "%f", &barnum) == 0) {
4924 ERR("reading execibar value failed (perhaps it's not "
4925 "the correct format?)");
4927 if (barnum > 100 || barnum < 0) {
4928 ERR("your execibar value is not between 0 and 100, "
4929 "therefore it will be ignored");
4931 obj->f = 255 * barnum / 100.0;
4932 new_bar(p, 0, 4, (int) obj->f);
4934 obj->data.execi.last_update = current_update_time;
4938 if (current_update_time - obj->data.execi.last_update
4939 < obj->data.execi.interval) {
4940 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
4943 FILE *fp = popen(obj->data.execi.cmd, "r");
4944 int n2 = fread(p, 1, p_max_size, fp);
4949 if (n2 && p[n2 - 1] == '\n') {
4954 if (*p2 == '\001') {
4960 if (sscanf(p, "%f", &barnum) == 0) {
4961 ERR("reading execigraph value failed (perhaps it's not "
4962 "the correct format?)");
4964 if (barnum > 100 || barnum < 0) {
4965 ERR("your execigraph value is not between 0 and 100, "
4966 "therefore it will be ignored");
4969 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f),
4972 obj->data.execi.last_update = current_update_time;
4976 if (current_update_time - obj->data.execi.last_update
4977 < obj->data.execi.interval
4978 || obj->data.execi.interval == 0) {
4979 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4981 char *output = obj->data.execi.buffer;
4982 FILE *fp = popen(obj->data.execi.cmd, "r");
4984 int length = fread(output, 1, text_buffer_size, fp);
4987 output[length] = '\0';
4988 if (length > 0 && output[length - 1] == '\n') {
4989 output[length - 1] = '\0';
4991 obj->data.execi.last_update = current_update_time;
4992 snprintf(p, p_max_size, "%s", output);
4994 // parse_conky_vars(output, p, cur);
4997 struct text_object_list *text_objects = 0;
4998 struct information *my_info =
4999 malloc(sizeof(struct information));
5000 memcpy(my_info, cur, sizeof(struct information));
5002 if (current_update_time - obj->data.execi.last_update
5003 < obj->data.execi.interval
5004 || obj->data.execi.interval == 0) {
5005 text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info);
5007 char *output = obj->data.execi.buffer;
5008 FILE *fp = popen(obj->data.execi.cmd, "r");
5009 int length = fread(output, 1, text_buffer_size, fp);
5013 output[length] = '\0';
5014 if (length > 0 && output[length - 1] == '\n') {
5015 output[length - 1] = '\0';
5018 text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info);
5019 obj->data.execi.last_update = current_update_time;
5021 free_text_objects(text_objects->text_object_count, text_objects->text_objects);
5026 if (!obj->data.texeci.p_timed_thread) {
5027 obj->data.texeci.p_timed_thread =
5028 timed_thread_create(&threaded_exec,
5029 (void *) obj, obj->data.texeci.interval * 1000000);
5030 if (!obj->data.texeci.p_timed_thread) {
5031 ERR("Error creating texeci timed thread");
5033 timed_thread_register(obj->data.texeci.p_timed_thread,
5034 &obj->data.texeci.p_timed_thread);
5035 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
5036 ERR("Error running texeci timed thread");
5039 timed_thread_lock(obj->data.texeci.p_timed_thread);
5040 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
5041 timed_thread_unlock(obj->data.texeci.p_timed_thread);
5043 #endif /* HAVE_POPEN */
5045 if (obj->global_mode && info.mail) {
5046 // this means we use info
5047 if (!info.mail->p_timed_thread) {
5048 info.mail->p_timed_thread =
5049 timed_thread_create(&imap_thread,
5050 (void *) info.mail, info.mail->interval * 1000000);
5051 if (!info.mail->p_timed_thread) {
5052 ERR("Error creating imap timed thread");
5054 timed_thread_register(info.mail->p_timed_thread,
5055 &info.mail->p_timed_thread);
5056 if (timed_thread_run(info.mail->p_timed_thread)) {
5057 ERR("Error running imap timed thread");
5060 timed_thread_lock(info.mail->p_timed_thread);
5061 snprintf(p, p_max_size, "%lu", info.mail->unseen);
5062 timed_thread_unlock(info.mail->p_timed_thread);
5063 } else if (obj->data.mail) {
5064 // this means we use obj
5065 if (!obj->data.mail->p_timed_thread) {
5066 obj->data.mail->p_timed_thread =
5067 timed_thread_create(&imap_thread,
5068 (void *) obj->data.mail,
5069 obj->data.mail->interval * 1000000);
5070 if (!obj->data.mail->p_timed_thread) {
5071 ERR("Error creating imap timed thread");
5073 timed_thread_register(obj->data.mail->p_timed_thread,
5074 &obj->data.mail->p_timed_thread);
5075 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
5076 ERR("Error running imap timed thread");
5079 timed_thread_lock(obj->data.mail->p_timed_thread);
5080 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
5081 timed_thread_unlock(obj->data.mail->p_timed_thread);
5082 } else if (!obj->a) {
5083 // something is wrong, warn once then stop
5084 ERR("Theres a problem with your imap_unseen settings. "
5085 "Check that the global IMAP settings are defined "
5086 "properly (line %li).", obj->line);
5090 OBJ(imap_messages) {
5091 if (obj->global_mode && info.mail) {
5092 // this means we use info
5093 if (!info.mail->p_timed_thread) {
5094 info.mail->p_timed_thread =
5095 timed_thread_create(&imap_thread,
5096 (void *) info.mail, info.mail->interval * 1000000);
5097 if (!info.mail->p_timed_thread) {
5098 ERR("Error creating imap timed thread");
5100 timed_thread_register(info.mail->p_timed_thread,
5101 &info.mail->p_timed_thread);
5102 if (timed_thread_run(info.mail->p_timed_thread)) {
5103 ERR("Error running imap timed thread");
5106 timed_thread_lock(info.mail->p_timed_thread);
5107 snprintf(p, p_max_size, "%lu", info.mail->messages);
5108 timed_thread_unlock(info.mail->p_timed_thread);
5109 } else if (obj->data.mail) {
5110 // this means we use obj
5111 if (!obj->data.mail->p_timed_thread) {
5112 obj->data.mail->p_timed_thread =
5113 timed_thread_create(&imap_thread,
5114 (void *) obj->data.mail,
5115 obj->data.mail->interval * 1000000);
5116 if (!obj->data.mail->p_timed_thread) {
5117 ERR("Error creating imap timed thread");
5119 timed_thread_register(obj->data.mail->p_timed_thread,
5120 &obj->data.mail->p_timed_thread);
5121 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
5122 ERR("Error runninging imap timed thread");
5125 timed_thread_lock(obj->data.mail->p_timed_thread);
5126 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
5127 timed_thread_lock(obj->data.mail->p_timed_thread);
5128 } else if (!obj->a) {
5129 // something is wrong, warn once then stop
5130 ERR("Theres a problem with your imap_messages settings. "
5131 "Check that the global IMAP settings are defined "
5132 "properly (line %li).", obj->line);
5137 if (obj->global_mode && info.mail) {
5138 // this means we use info
5139 if (!info.mail->p_timed_thread) {
5140 info.mail->p_timed_thread =
5141 timed_thread_create(&pop3_thread,
5142 (void *) info.mail, info.mail->interval * 1000000);
5143 if (!info.mail->p_timed_thread) {
5144 ERR("Error creating pop3 timed thread");
5146 timed_thread_register(info.mail->p_timed_thread,
5147 &info.mail->p_timed_thread);
5148 if (timed_thread_run(info.mail->p_timed_thread)) {
5149 ERR("Error running pop3 timed thread");
5152 timed_thread_lock(info.mail->p_timed_thread);
5153 snprintf(p, p_max_size, "%lu", info.mail->unseen);
5154 timed_thread_unlock(info.mail->p_timed_thread);
5155 } else if (obj->data.mail) {
5156 // this means we use obj
5157 if (!obj->data.mail->p_timed_thread) {
5158 obj->data.mail->p_timed_thread =
5159 timed_thread_create(&pop3_thread,
5160 (void *) obj->data.mail,
5161 obj->data.mail->interval * 1000000);
5162 if (!obj->data.mail->p_timed_thread) {
5163 ERR("Error creating pop3 timed thread");
5165 timed_thread_register(obj->data.mail->p_timed_thread,
5166 &obj->data.mail->p_timed_thread);
5167 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
5168 ERR("Error running pop3 timed thread");
5171 timed_thread_lock(obj->data.mail->p_timed_thread);
5172 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
5173 timed_thread_unlock(obj->data.mail->p_timed_thread);
5174 } else if (!obj->a) {
5175 // something is wrong, warn once then stop
5176 ERR("Theres a problem with your pop3_unseen settings. "
5177 "Check that the global POP3 settings are defined "
5178 "properly (line %li).", obj->line);
5183 if (obj->global_mode && info.mail) {
5184 // this means we use info
5185 if (!info.mail->p_timed_thread) {
5186 info.mail->p_timed_thread =
5187 timed_thread_create(&pop3_thread,
5188 (void *) info.mail, info.mail->interval * 1000000);
5189 if (!info.mail->p_timed_thread) {
5190 ERR("Error creating pop3 timed thread");
5192 timed_thread_register(info.mail->p_timed_thread,
5193 &info.mail->p_timed_thread);
5194 if (timed_thread_run(info.mail->p_timed_thread)) {
5195 ERR("Error running pop3 timed thread");
5198 timed_thread_lock(info.mail->p_timed_thread);
5199 snprintf(p, p_max_size, "%.1f",
5200 info.mail->used / 1024.0 / 1024.0);
5201 timed_thread_unlock(info.mail->p_timed_thread);
5202 } else if (obj->data.mail) {
5203 // this means we use obj
5204 if (!obj->data.mail->p_timed_thread) {
5205 obj->data.mail->p_timed_thread =
5206 timed_thread_create(&pop3_thread,
5207 (void *) obj->data.mail,
5208 obj->data.mail->interval * 1000000);
5209 if (!obj->data.mail->p_timed_thread) {
5210 ERR("Error creating pop3 timed thread");
5212 timed_thread_register(obj->data.mail->p_timed_thread,
5213 &obj->data.mail->p_timed_thread);
5214 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
5215 ERR("Error running pop3 timed thread");
5218 timed_thread_lock(obj->data.mail->p_timed_thread);
5219 snprintf(p, p_max_size, "%.1f",
5220 obj->data.mail->used / 1024.0 / 1024.0);
5221 timed_thread_unlock(obj->data.mail->p_timed_thread);
5222 } else if (!obj->a) {
5223 // something is wrong, warn once then stop
5224 ERR("Theres a problem with your pop3_used settings. "
5225 "Check that the global POP3 settings are defined "
5226 "properly (line %li).", obj->line);
5231 if (obj->data.fs != NULL) {
5232 if (obj->data.fs->size == 0) {
5233 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5235 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5236 (int) (255 - obj->data.fsbar.fs->avail * 255 /
5237 obj->data.fs->size));
5242 if (obj->data.fs != NULL) {
5243 human_readable(obj->data.fs->avail, p, 255, "fs_free");
5247 if (obj->data.fs != NULL) {
5248 if (obj->data.fs->size) {
5249 spaced_print(p, p_max_size, "%*d", 4, "fs_free_perc",
5250 pad_percents, (int) ((obj->data.fs->avail * 100) /
5251 obj->data.fs->size));
5253 snprintf(p, p_max_size, "0");
5258 if (obj->data.fs != NULL) {
5259 human_readable(obj->data.fs->size, p, 255, "fs_size");
5263 if (obj->data.fs != NULL)
5264 snprintf(p, p_max_size, "%s", obj->data.fs->type);
5267 if (obj->data.fs != NULL) {
5268 human_readable(obj->data.fs->size - (obj->data.fs->free
5269 ? obj->data.fs->free : obj->data.fs->avail), p, 255,
5274 if (obj->data.fs != NULL) {
5275 if (obj->data.fs->size == 0) {
5276 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5278 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5279 (int) (obj->data.fsbar.fs->avail * 255 /
5280 obj->data.fs->size));
5285 if (obj->data.fs != NULL) {
5286 if (obj->data.fs->size) {
5287 spaced_print(p, 4, "%*d", 4, "fs_used_perc",
5288 pad_percents, 100 - ((int) ((obj->data.fs->avail * 100) /
5289 obj->data.fs->size)));
5291 snprintf(p, p_max_size, "0");
5296 float *v = info.loadavg;
5298 if (obj->data.loadavg[2]) {
5299 snprintf(p, p_max_size, "%.2f %.2f %.2f",
5300 v[obj->data.loadavg[0] - 1],
5301 v[obj->data.loadavg[1] - 1],
5302 v[obj->data.loadavg[2] - 1]);
5303 } else if (obj->data.loadavg[1]) {
5304 snprintf(p, p_max_size, "%.2f %.2f",
5305 v[obj->data.loadavg[0] - 1],
5306 v[obj->data.loadavg[1] - 1]);
5307 } else if (obj->data.loadavg[0]) {
5308 snprintf(p, p_max_size, "%.2f",
5309 v[obj->data.loadavg[0] - 1]);
5313 new_goto(p, obj->data.i);
5316 new_tab(p, obj->data.pair.a, obj->data.pair.b);
5319 new_hr(p, obj->data.i);
5322 if (cur->nameserver_info.nscount > obj->data.i)
5323 snprintf(p, p_max_size, "%s",
5324 cur->nameserver_info.ns_list[obj->data.i]);
5328 PRSS *data = get_rss_info(obj->data.rss.uri,
5329 obj->data.rss.delay);
5333 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
5335 if (!strcmp(obj->data.rss.action, "feed_title")) {
5337 // remove trailing new line if one exists
5338 if (str[strlen(str) - 1] == '\n') {
5339 str[strlen(str) - 1] = 0;
5341 snprintf(p, p_max_size, "%s", str);
5342 } else if (!strcmp(obj->data.rss.action, "item_title")) {
5343 if (obj->data.rss.act_par < data->item_count) {
5344 str = data->items[obj->data.rss.act_par].title;
5345 // remove trailing new line if one exists
5346 if (str[strlen(str) - 1] == '\n') {
5347 str[strlen(str) - 1] = 0;
5349 snprintf(p, p_max_size, "%s", str);
5351 } else if (!strcmp(obj->data.rss.action, "item_desc")) {
5352 if (obj->data.rss.act_par < data->item_count) {
5354 data->items[obj->data.rss.act_par].description;
5355 // remove trailing new line if one exists
5356 if (str[strlen(str) - 1] == '\n') {
5357 str[strlen(str) - 1] = 0;
5359 snprintf(p, p_max_size, "%s", str);
5361 } else if (!strcmp(obj->data.rss.action, "item_titles")) {
5362 if (data->item_count > 0) {
5368 if (obj->data.rss.act_par > data->item_count) {
5369 show = data->item_count;
5371 show = obj->data.rss.act_par;
5373 for (itmp = 0; itmp < show; itmp++) {
5374 PRSS_Item *item = &data->items[itmp];
5378 // don't add new line before first item
5380 strncat(p, "\n", p_max_size);
5382 /* remove trailing new line if one exists,
5383 * we have our own */
5384 if (str[strlen(str) - 1] == '\n') {
5385 str[strlen(str) - 1] = 0;
5387 strncat(p, str, p_max_size);
5397 if (obj->data.hddtemp.update_time < current_update_time - 30) {
5398 char *str = get_hddtemp_info(obj->data.hddtemp.dev,
5399 obj->data.hddtemp.addr, obj->data.hddtemp.port, &obj->data.hddtemp.unit);
5401 strncpy(obj->data.hddtemp.temp, str, text_buffer_size);
5403 obj->data.hddtemp.temp[0] = 0;
5405 obj->data.hddtemp.update_time = current_update_time;
5407 if (!obj->data.hddtemp.temp) {
5408 snprintf(p, p_max_size, "N/A");
5409 } else if (obj->data.hddtemp.unit == '*') {
5410 snprintf(p, p_max_size, "%s", obj->data.hddtemp.temp);
5412 snprintf(p, p_max_size, "%s%c", obj->data.hddtemp.temp, obj->data.hddtemp.unit);
5417 new_offset(p, obj->data.i);
5420 new_voffset(p, obj->data.i);
5426 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5427 obj->data.sysfs.devtype, obj->data.sysfs.type);
5429 if (r >= 100.0 || r == 0) {
5430 snprintf(p, p_max_size, "%d", (int) r);
5432 snprintf(p, p_max_size, "%.1f", r);
5438 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5439 obj->data.sysfs.devtype, obj->data.sysfs.type);
5441 if (r >= 100.0 || r == 0) {
5442 snprintf(p, p_max_size, "%d", (int) r);
5444 snprintf(p, p_max_size, "%.1f", r);
5450 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5451 obj->data.sysfs.devtype, obj->data.sysfs.type);
5453 if (r >= 100.0 || r == 0) {
5454 snprintf(p, p_max_size, "%d", (int) r);
5456 snprintf(p, p_max_size, "%.1f", r);
5459 #endif /* !__OpenBSD__ */
5461 new_alignr(p, obj->data.i);
5464 new_alignc(p, obj->data.i);
5467 struct text_object_list *text_objects;
5468 struct information *my_info =
5469 malloc(sizeof(struct information));
5470 memcpy(my_info, cur, sizeof(struct information));
5471 text_objects = parse_conky_vars(obj->data.ifblock.s, p, my_info);
5473 if (strlen(p) != 0) {
5474 i = obj->data.ifblock.pos;
5480 free_text_objects(text_objects->text_object_count, text_objects->text_objects);
5487 if ((obj->data.ifblock.s)
5488 && (stat(obj->data.ifblock.s, &tmp) == -1)) {
5489 i = obj->data.ifblock.pos;
5492 if (obj->data.ifblock.str) {
5493 if (!check_contains(obj->data.ifblock.s,
5494 obj->data.ifblock.str)) {
5495 i = obj->data.ifblock.pos;
5506 if ((obj->data.ifblock.s)
5507 && (!check_mount(obj->data.ifblock.s))) {
5508 i = obj->data.ifblock.pos;
5515 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
5516 i = obj->data.ifblock.pos;
5522 #if defined(__linux__)
5524 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
5528 snprintf(p, p_max_size, "%s", cur->uname_s.release);
5531 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
5536 human_readable(cur->mem * 1024, p, 255, "mem");
5539 human_readable(cur->memmax * 1024, p, 255, "memmax");
5543 spaced_print(p, p_max_size, "%*llu", 4, "memperc",
5544 pad_percents, cur->mem * 100 / cur->memmax);
5548 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5549 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
5552 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5553 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
5559 snprintf(p, p_max_size, "%d", mixer_get_avg(obj->data.l));
5562 snprintf(p, p_max_size, "%d", mixer_get_left(obj->data.l));
5565 snprintf(p, p_max_size, "%d", mixer_get_right(obj->data.l));
5568 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5569 mixer_get_avg(obj->data.mixerbar.l) * 255 / 100);
5572 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5573 mixer_get_left(obj->data.mixerbar.l) * 255 / 100);
5576 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5577 mixer_get_right(obj->data.mixerbar.l) * 255 / 100);
5582 update_mail_count(&obj->data.local_mail);
5583 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
5586 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
5588 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
5591 update_mail_count(&obj->data.local_mail);
5592 snprintf(p, p_max_size, "%d",
5593 obj->data.local_mail.new_mail_count);
5596 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
5599 new_outline(p, obj->data.l);
5602 spaced_print(p, p_max_size, "%hu", 5, "processes", cur->procs);
5604 OBJ(running_processes) {
5605 spaced_print(p, p_max_size, "%hu", 3, "running_processes", cur->run_procs);
5608 snprintf(p, p_max_size, "%s", obj->data.s);
5611 new_bg(p, obj->data.l);
5614 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
5617 human_readable(cur->swap * 1024, p, 255, "swap");
5620 human_readable(cur->swapmax * 1024, p, 255, "swapmax");
5623 if (cur->swapmax == 0) {
5624 strncpy(p, "No swap", p_max_size);
5626 spaced_print(p, p_max_size, "%*llu", 4, "swapperc",
5627 pad_percents, cur->swap * 100 / cur->swapmax);
5631 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5632 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
5635 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
5638 time_t t = time(NULL);
5639 struct tm *tm = localtime(&t);
5641 setlocale(LC_TIME, "");
5642 strftime(p, p_max_size, obj->data.s, tm);
5645 time_t t = time(NULL);
5646 struct tm *tm = gmtime(&t);
5648 strftime(p, p_max_size, obj->data.s, tm);
5655 if (obj->data.tztime.tz) {
5656 oldTZ = getenv("TZ");
5657 setenv("TZ", obj->data.tztime.tz, 1);
5663 setlocale(LC_TIME, "");
5664 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
5666 setenv("TZ", oldTZ, 1);
5671 // Needless to free oldTZ since getenv gives ptr to static data
5674 human_readable(obj->data.net->recv, p, 255, "totaldown");
5677 human_readable(obj->data.net->trans, p, 255, "totalup");
5680 snprintf(p, p_max_size, "%d", total_updates);
5683 spaced_print(p, p_max_size, "%d", 6, "upspeed",
5684 round_to_int(obj->data.net->trans_speed / 1024));
5687 spaced_print(p, p_max_size, "%.1f", 8, "upspeedf",
5688 obj->data.net->trans_speed / 1024.0);
5691 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5692 obj->data.net->trans_speed / 1024.0, obj->e, 1);
5695 format_seconds_short(p, p_max_size, (int) cur->uptime);
5698 format_seconds(p, p_max_size, (int) cur->uptime);
5701 snprintf(p, p_max_size, "%s", cur->users.names);
5704 snprintf(p, p_max_size, "%s", cur->users.terms);
5707 snprintf(p, p_max_size, "%s", cur->users.times);
5710 snprintf(p, p_max_size, "%d", cur->users.number);
5712 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
5713 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5717 msg = get_apm_adapter();
5718 snprintf(p, p_max_size, "%s", msg);
5721 OBJ(apm_battery_life) {
5724 msg = get_apm_battery_life();
5725 snprintf(p, p_max_size, "%s", msg);
5728 OBJ(apm_battery_time) {
5731 msg = get_apm_battery_time();
5732 snprintf(p, p_max_size, "%s", msg);
5735 #endif /* __FreeBSD__ __OpenBSD__ */
5739 snprintf(p, cur->mpd.max_title_len > 0
5740 ? cur->mpd.max_title_len : p_max_size, "%s",
5744 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5747 snprintf(p, p_max_size, "%s", cur->mpd.album);
5750 snprintf(p, p_max_size, "%s", cur->mpd.random);
5753 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
5756 snprintf(p, p_max_size, "%s", cur->mpd.track);
5759 snprintf(p, p_max_size, "%s", cur->mpd.name);
5762 snprintf(p, p_max_size, "%s", cur->mpd.file);
5765 snprintf(p, p_max_size, "%i", cur->mpd.volume);
5768 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
5771 snprintf(p, p_max_size, "%s", cur->mpd.status);
5774 format_media_player_time(p, p_max_size, cur->mpd.elapsed);
5777 format_media_player_time(p, p_max_size, cur->mpd.length);
5780 spaced_print(p, p_max_size, "%*d", 4, "mpd_percent",
5781 pad_percents, (int) (cur->mpd.progress * 100));
5784 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5785 (int) (cur->mpd.progress * 255.0f));
5788 memset(p, 0, p_max_size);
5789 if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title
5790 && *cur->mpd.title) {
5791 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist,
5793 } else if (cur->mpd.title && *cur->mpd.title) {
5794 snprintf(p, p_max_size, "%s", cur->mpd.title);
5795 } else if (cur->mpd.artist && *cur->mpd.artist) {
5796 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5797 } else if (cur->mpd.file && *cur->mpd.file) {
5798 snprintf(p, p_max_size, "%s", cur->mpd.file);
5807 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5810 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5813 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5816 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5818 OBJ(xmms2_comment) {
5819 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5822 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5825 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5828 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5830 OBJ(xmms2_tracknr) {
5831 if (cur->xmms2.tracknr != -1) {
5832 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5835 OBJ(xmms2_bitrate) {
5836 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5839 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5842 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5844 OBJ(xmms2_elapsed) {
5845 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5846 (cur->xmms2.elapsed / 1000) % 60);
5848 OBJ(xmms2_duration) {
5849 snprintf(p, p_max_size, "%02d:%02d",
5850 cur->xmms2.duration / 60000,
5851 (cur->xmms2.duration / 1000) % 60);
5853 OBJ(xmms2_percent) {
5854 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5857 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5858 (int) (cur->xmms2.progress * 255.0f));
5860 OBJ(xmms2_playlist) {
5861 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5863 OBJ(xmms2_timesplayed) {
5864 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5867 if (strlen(cur->xmms2.title) < 2
5868 && strlen(cur->xmms2.title) < 2) {
5869 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5871 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5877 OBJ(audacious_status) {
5878 snprintf(p, p_max_size, "%s",
5879 cur->audacious.items[AUDACIOUS_STATUS]);
5881 OBJ(audacious_title) {
5882 snprintf(p, cur->audacious.max_title_len > 0
5883 ? cur->audacious.max_title_len : p_max_size, "%s",
5884 cur->audacious.items[AUDACIOUS_TITLE]);
5886 OBJ(audacious_length) {
5887 snprintf(p, p_max_size, "%s",
5888 cur->audacious.items[AUDACIOUS_LENGTH]);
5890 OBJ(audacious_length_seconds) {
5891 snprintf(p, p_max_size, "%s",
5892 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5894 OBJ(audacious_position) {
5895 snprintf(p, p_max_size, "%s",
5896 cur->audacious.items[AUDACIOUS_POSITION]);
5898 OBJ(audacious_position_seconds) {
5899 snprintf(p, p_max_size, "%s",
5900 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5902 OBJ(audacious_bitrate) {
5903 snprintf(p, p_max_size, "%s",
5904 cur->audacious.items[AUDACIOUS_BITRATE]);
5906 OBJ(audacious_frequency) {
5907 snprintf(p, p_max_size, "%s",
5908 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5910 OBJ(audacious_channels) {
5911 snprintf(p, p_max_size, "%s",
5912 cur->audacious.items[AUDACIOUS_CHANNELS]);
5914 OBJ(audacious_filename) {
5915 snprintf(p, p_max_size, "%s",
5916 cur->audacious.items[AUDACIOUS_FILENAME]);
5918 OBJ(audacious_playlist_length) {
5919 snprintf(p, p_max_size, "%s",
5920 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5922 OBJ(audacious_playlist_position) {
5923 snprintf(p, p_max_size, "%s",
5924 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5926 OBJ(audacious_bar) {
5930 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5931 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5932 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5938 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5941 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5944 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5947 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5950 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5953 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5957 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
5960 switch (obj->data.top.type) {
5962 snprintf(p, 16, "%-15s",
5963 cur->cpu[obj->data.top.num]->name);
5966 snprintf(p, 7, "%6.2f",
5967 cur->cpu[obj->data.top.num]->amount);
5970 snprintf(p, 6, "%5i",
5971 cur->cpu[obj->data.top.num]->pid);
5974 snprintf(p, 7, "%6.2f",
5975 cur->cpu[obj->data.top.num]->totalmem);
5978 timeval = format_time(
5979 cur->cpu[obj->data.top.num]->total_cpu_time, 9);
5980 snprintf(p, 10, "%9s", timeval);
5984 human_readable(cur->cpu[obj->data.top.num]->rss,
5988 human_readable(cur->cpu[obj->data.top.num]->vsize,
5992 ERR("Unhandled top data type: %d\n",
5993 obj->data.top.type);
5996 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
6000 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
6003 switch (obj->data.top.type) {
6005 snprintf(p, 16, "%-15s",
6006 cur->memu[obj->data.top.num]->name);
6009 snprintf(p, 7, "%6.2f",
6010 cur->memu[obj->data.top.num]->amount);
6013 snprintf(p, 6, "%5i",
6014 cur->memu[obj->data.top.num]->pid);
6017 snprintf(p, 7, "%6.2f",
6018 cur->memu[obj->data.top.num]->totalmem);
6021 timeval = format_time(
6022 cur->memu[obj->data.top.num]->total_cpu_time,
6024 snprintf(p, 10, "%9s", timeval);
6028 human_readable(cur->cpu[obj->data.top.num]->rss,
6032 human_readable(cur->cpu[obj->data.top.num]->vsize,
6036 ERR("Unhandled top data type: %d\n",
6037 obj->data.top.type);
6040 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
6044 if (current_update_time - obj->data.tail.last_update
6045 < obj->data.tail.interval) {
6046 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
6052 obj->data.tail.last_update = current_update_time;
6054 if (obj->data.tail.fd != -1) {
6055 tail_pipe(obj, p, p_max_size);
6059 fp = fopen(obj->data.tail.logfile, "rt");
6062 /* Send one message, but do not consistently spam
6063 * on missing logfiles. */
6064 if (obj->data.tail.readlines != 0) {
6065 ERR("tail logfile failed to open");
6066 strcpy(obj->data.tail.buffer, "Logfile Missing");
6068 obj->data.tail.readlines = 0;
6069 snprintf(p, p_max_size, "Logfile Missing");
6071 obj->data.tail.readlines = 0;
6072 /* -1 instead of 0 to avoid counting a trailing
6074 fseek(fp, -1, SEEK_END);
6075 bsize = ftell(fp) + 1;
6076 for (iter = obj->data.tail.wantedlines; iter > 0;
6078 nl = rev_fcharfind(fp, '\n', iter);
6083 obj->data.tail.readlines = iter;
6084 if (obj->data.tail.readlines
6085 < obj->data.tail.wantedlines) {
6086 fseek(fp, 0, SEEK_SET);
6088 fseek(fp, nl + 1, SEEK_SET);
6091 /* Make sure bsize is at least 1 byte smaller than the
6092 * buffer max size. */
6093 if (bsize > (long) ((text_buffer_size * 20) - 1)) {
6094 fseek(fp, bsize - text_buffer_size * 20 - 1,
6096 bsize = text_buffer_size * 20 - 1;
6098 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
6101 /* Clean up trailing newline, make sure the
6102 * buffer is null terminated. */
6103 if (obj->data.tail.buffer[bsize - 1] == '\n') {
6104 obj->data.tail.buffer[bsize - 1] = '\0';
6106 obj->data.tail.buffer[bsize] = '\0';
6108 snprintf(p, p_max_size, "%s",
6109 obj->data.tail.buffer);
6111 strcpy(obj->data.tail.buffer, "Logfile Empty");
6112 snprintf(p, p_max_size, "Logfile Empty");
6115 } /* if cur_upd_time >= */
6116 // parse_conky_vars(obj->data.tail.buffer, p, cur);
6120 if (current_update_time - obj->data.tail.last_update
6121 < obj->data.tail.interval) {
6122 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
6128 obj->data.tail.last_update = current_update_time;
6130 fp = fopen(obj->data.tail.logfile, "rt");
6132 /* Send one message, but do not consistently spam
6133 * on missing logfiles. */
6134 if (obj->data.tail.readlines != 0) {
6135 ERR("head logfile failed to open");
6136 strcpy(obj->data.tail.buffer, "Logfile Missing");
6138 obj->data.tail.readlines = 0;
6139 snprintf(p, p_max_size, "Logfile Missing");
6141 obj->data.tail.readlines = 0;
6142 for (iter = obj->data.tail.wantedlines; iter > 0;
6144 nl = fwd_fcharfind(fp, '\n', iter);
6149 obj->data.tail.readlines = iter;
6150 /* Make sure nl is at least 1 byte smaller than the
6151 * buffer max size. */
6152 if (nl > (long) ((text_buffer_size * 20) - 1)) {
6153 nl = text_buffer_size * 20 - 1;
6155 nl = fread(obj->data.tail.buffer, 1, nl, fp);
6158 /* Clean up trailing newline, make sure the buffer
6159 * is null terminated. */
6160 if (obj->data.tail.buffer[nl - 1] == '\n') {
6161 obj->data.tail.buffer[nl - 1] = '\0';
6163 obj->data.tail.buffer[nl] = '\0';
6165 snprintf(p, p_max_size, "%s",
6166 obj->data.tail.buffer);
6168 strcpy(obj->data.tail.buffer, "Logfile Empty");
6169 snprintf(p, p_max_size, "Logfile Empty");
6171 } /* if fp == null */
6172 } /* cur_upd_time >= */
6173 // parse_conky_vars(obj->data.tail.buffer, p, cur);
6176 #ifdef TCP_PORT_MONITOR
6178 /* grab a pointer to this port monitor */
6179 tcp_port_monitor_t *p_monitor =
6180 find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
6181 obj->data.tcp_port_monitor.port_range_begin,
6182 obj->data.tcp_port_monitor.port_range_end);
6185 snprintf(p, p_max_size, "monitor not found");
6189 /* now grab the text of interest */
6190 if (peek_tcp_port_monitor(p_monitor,
6191 obj->data.tcp_port_monitor.item,
6192 obj->data.tcp_port_monitor.connection_index, p,
6194 snprintf(p, p_max_size, "monitor peek error");
6202 iconv_converting = 1;
6203 iconv_selected = obj->a;
6206 iconv_converting = 0;
6211 OBJ(entropy_avail) {
6212 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
6214 OBJ(entropy_poolsize) {
6215 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
6218 double entropy_perc;
6220 entropy_perc = (double) cur->entropy.entropy_avail /
6221 (double) cur->entropy.poolsize;
6222 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
6228 s = smapi_get_val(obj->data.s);
6229 snprintf(p, p_max_size, "%s", s);
6233 OBJ(if_smapi_bat_installed) {
6235 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
6236 if(!smapi_bat_installed(idx)) {
6237 i = obj->data.ifblock.pos;
6242 ERR("argument to if_smapi_bat_installed must be an integer");
6244 OBJ(smapi_bat_perc) {
6246 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
6247 val = smapi_bat_installed(idx) ?
6248 smapi_get_bat_int(idx, "remaining_percent") : 0;
6249 spaced_print(p, p_max_size, "%*d", 4, "smapi_bat_perc", pad_percents, val);
6251 ERR("argument to smapi_bat_perc must be an integer");
6253 OBJ(smapi_bat_bar) {
6254 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
6255 new_bar(p, obj->a, obj->b, (int)
6256 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
6258 new_bar(p, obj->a, obj->b, 0);
6263 int hol = (strcmp((char*)&obj->data.nvidia.arg, "gpufreq")) ? 1 : 0;
6264 if(!(obj->data.nvidia.value = get_nvidia_value(obj->data.nvidia.type, display, hol)))
6265 snprintf(p, p_max_size, "value unavailible");
6267 spaced_print(p, p_max_size, "%*d", 4, "nvidia",
6268 4, obj->data.nvidia.value);
6277 unsigned int a = strlen(p);
6280 if (a > 0 && iconv_converting && iconv_selected > 0
6281 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
6283 size_t dummy1, dummy2;
6284 char *ptr = buff_in;
6287 dummy1 = dummy2 = a;
6289 strncpy(buff_in, p, p_max_size);
6291 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
6292 while (dummy1 > 0) {
6293 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
6296 ERR("Iconv codeset conversion failed");
6301 /* It is nessecary when we are converting from multibyte to
6302 * singlebyte codepage */
6305 #endif /* HAVE_ICONV */
6312 double current_update_time, last_update_time;
6314 static void generate_text(void)
6316 struct information *cur = &info;
6323 current_update_time = get_time();
6326 /* fix diskio rates to b/s (use update_interval */
6327 info.diskio_read_value /= update_interval;
6328 info.diskio_write_value /= update_interval;
6329 info.diskio_value /= update_interval;
6331 /* add things to the buffer */
6337 generate_text_internal(p, max_user_text, global_text_objects,
6338 global_text_object_count, cur);
6340 if (stuff_in_upper_case) {
6343 tmp_p = text_buffer;
6345 *tmp_p = toupper(*tmp_p);
6350 last_update_time = current_update_time;
6356 static void set_font(void)
6360 if (window.xftdraw != NULL) {
6361 XftDrawDestroy(window.xftdraw);
6363 window.xftdraw = XftDrawCreate(display, window.drawable,
6364 DefaultVisual(display, screen), DefaultColormap(display, screen));
6368 XSetFont(display, window.gc, fonts[selected_font].font->fid);
6374 static inline int get_string_width(const char *s)
6377 return *s ? calc_text_width(s, strlen(s)) : 0;
6383 static inline int get_string_width_special(char *s)
6395 p = strndup(s, text_buffer_size);
6399 if (*p == SPECIAL_CHAR) {
6400 /* shift everything over by 1 so that the special char
6401 * doesn't mess up the size calculation */
6402 for (i = 0; i < strlen(p); i++) {
6403 *(p + i) = *(p + i + 1);
6405 if (specials[special_index + idx].type == GRAPH
6406 || specials[special_index + idx].type == BAR) {
6407 width += specials[special_index + idx].width;
6414 if (strlen(final) > 1) {
6415 width += calc_text_width(final, strlen(final));
6420 return (s) ? strlen(s) : 0;
6425 static void text_size_updater(char *s);
6427 int last_font_height;
6428 static void update_text_area(void)
6432 /* update text size if it isn't fixed */
6437 text_width = minimum_width;
6440 last_font_height = font_height();
6441 for_each_line(text_buffer, text_size_updater);
6443 if (text_height < minimum_height) {
6444 text_height = minimum_height;
6446 if (text_width > maximum_width && maximum_width > 0) {
6447 text_width = maximum_width;
6451 /* get text position on workarea */
6452 switch (text_alignment) {
6459 x = workarea[2] - text_width - gap_x;
6464 x = workarea[2] / 2 - text_width / 2 - gap_x;
6471 y = workarea[3] - text_height - gap_y;
6475 x = workarea[2] - text_width - gap_x;
6476 y = workarea[3] - text_height - gap_y;
6480 x = workarea[2] / 2 - text_width / 2 - gap_x;
6481 y = workarea[3] - text_height - gap_y;
6486 y = workarea[3] / 2 - text_height / 2 - gap_y;
6490 x = workarea[2] - text_width - gap_x;
6491 y = workarea[3] / 2 - text_height / 2 - gap_y;
6495 case NONE: // Let the WM manage the window
6506 if (own_window && !fixed_pos) {
6509 text_start_x = border_margin + 1;
6510 text_start_y = border_margin + 1;
6511 window.x = x - border_margin - 1;
6512 window.y = y - border_margin - 1;
6516 /* If window size doesn't match to workarea's size,
6517 * then window probably includes panels (gnome).
6518 * Blah, doesn't work on KDE. */
6519 if (workarea[2] != window.width || workarea[3] != window.height) {
6531 static int cur_x, cur_y; /* current x and y for drawing */
6533 //draw_mode also without X11 because we only need to print to stdout with FG
6534 static int draw_mode; /* FG, BG or OUTLINE */
6536 static long current_color;
6539 static void text_size_updater(char *s)
6544 /* get string widths and skip specials */
6547 if (*p == SPECIAL_CHAR) {
6549 w += get_string_width(s);
6552 if (specials[special_index].type == BAR
6553 || specials[special_index].type == GRAPH) {
6554 w += specials[special_index].width;
6555 if (specials[special_index].height > last_font_height) {
6556 last_font_height = specials[special_index].height;
6557 last_font_height += font_ascent();
6559 } else if (specials[special_index].type == OFFSET) {
6560 if (specials[special_index].arg > 0) {
6561 w += specials[special_index].arg;
6563 } else if (specials[special_index].type == VOFFSET) {
6564 last_font_height += specials[special_index].arg;
6565 } else if (specials[special_index].type == GOTO) {
6566 if (specials[special_index].arg > cur_x) {
6567 w = (int) specials[special_index].arg;
6569 } else if (specials[special_index].type == TAB) {
6570 int start = specials[special_index].arg;
6571 int step = specials[special_index].width;
6573 if (!step || step < 0) {
6576 w += step - (cur_x - text_start_x - start) % step;
6577 } else if (specials[special_index].type == FONT) {
6578 selected_font = specials[special_index].font_added;
6579 if (font_height() > last_font_height) {
6580 last_font_height = font_height();
6589 w += get_string_width(s);
6590 if (w > text_width) {
6593 if (text_width > maximum_width && maximum_width) {
6594 text_width = maximum_width;
6597 text_height += last_font_height;
6598 last_font_height = font_height();
6602 static inline void set_foreground_color(long c)
6605 XSetForeground(display, window.gc, c);
6609 static void draw_string(const char *s)
6611 int i, i2, pos, width_of_s;
6619 width_of_s = get_string_width(s);
6620 if (out_to_console && draw_mode == FG) {
6622 fflush(stdout); /* output immediately, don't buffer */
6624 memset(tmpstring1, 0, text_buffer_size);
6625 memset(tmpstring2, 0, text_buffer_size);
6626 strncpy(tmpstring1, s, text_buffer_size - 1);
6631 max = ((text_width - width_of_s) / get_string_width(" "));
6633 /* This code looks for tabs in the text and coverts them to spaces.
6634 * The trick is getting the correct number of spaces, and not going
6635 * over the window's size without forcing the window larger. */
6636 for (i = 0; i < (int) text_buffer_size; i++) {
6637 if (tmpstring1[i] == '\t') {
6639 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
6640 /* guard against overrun */
6641 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
6646 /* guard against overrun */
6647 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
6652 if (text_width == maximum_width) {
6653 /* this means the text is probably pushing the limit,
6654 * so we'll chop it */
6655 while (cur_x + get_string_width(tmpstring2) - text_start_x
6656 > maximum_width && strlen(tmpstring2) > 0) {
6657 tmpstring2[strlen(tmpstring2) - 1] = '\0';
6668 c.pixel = current_color;
6669 XQueryColor(display, DefaultColormap(display, screen), &c);
6672 c2.color.red = c.red;
6673 c2.color.green = c.green;
6674 c2.color.blue = c.blue;
6675 c2.color.alpha = fonts[selected_font].font_alpha;
6677 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6678 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6680 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6681 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6686 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
6689 cur_x += width_of_s;
6691 memcpy(tmpstring1, s, text_buffer_size);
6694 long redmask, greenmask, bluemask;
6696 void set_up_gradient(void)
6700 colour_depth = DisplayPlanes(display, screen);
6704 if (colour_depth != 24 && colour_depth != 16) {
6705 ERR("using non-standard colour depth, gradients may look like a "
6712 for (i = (colour_depth / 3) - 1; i >= 0; i--) {
6714 greenmask |= 1 << i;
6717 if (colour_depth % 3 == 1) {
6718 greenmask |= 1 << (colour_depth / 3);
6720 redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
6721 greenmask = greenmask << (colour_depth / 3);
6724 /* this function returns the next colour between two colours for a gradient */
6725 inline unsigned long do_gradient(unsigned long first_colour,
6726 unsigned long last_colour)
6729 int red1, green1, blue1; // first colour
6730 int red2, green2, blue2; // second colour
6731 int red3 = 0, green3 = 0, blue3 = 0; // difference
6732 short redshift = (2 * colour_depth / 3 + colour_depth % 3);
6733 short greenshift = (colour_depth / 3);
6735 red1 = (first_colour & redmask) >> redshift;
6736 green1 = (first_colour & greenmask) >> greenshift;
6737 blue1 = first_colour & bluemask;
6738 red2 = (last_colour & redmask) >> redshift;
6739 green2 = (last_colour & greenmask) >> greenshift;
6740 blue2 = last_colour & bluemask;
6747 if (green1 > green2) {
6750 if (green1 < green2) {
6753 if (blue1 > blue2) {
6756 if (blue1 < blue2) {
6771 if (red1 > bluemask) {
6774 if (green1 > bluemask) {
6777 if (blue1 > bluemask) {
6780 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
6784 /* this function returns the max diff for a gradient */
6785 inline unsigned long gradient_max(unsigned long first_colour,
6786 unsigned long last_colour)
6788 int red1, green1, blue1; // first colour
6789 int red2, green2, blue2; // second colour
6790 int red3 = 0, green3 = 0, blue3 = 0; // difference
6791 long redshift, greenshift;
6794 if (colour_depth == 0) {
6797 redshift = (2 * colour_depth / 3 + colour_depth % 3);
6798 greenshift = (colour_depth / 3);
6800 red1 = (first_colour & redmask) >> redshift;
6801 green1 = (first_colour & greenmask) >> greenshift;
6802 blue1 = first_colour & bluemask;
6803 red2 = (last_colour & redmask) >> redshift;
6804 green2 = (last_colour & greenmask) >> greenshift;
6805 blue2 = last_colour & bluemask;
6806 red3 = abs(red1 - red2);
6807 green3 = abs(green1 - green2);
6808 blue3 = abs(blue1 - blue2);
6820 static void draw_line(char *s)
6828 cur_x = text_start_x;
6829 cur_y += font_ascent();
6830 font_h = font_height();
6832 /* find specials and draw stuff */
6835 if (*p == SPECIAL_CHAR) {
6838 /* draw string before special */
6845 switch (specials[special_index].type) {
6846 case HORIZONTAL_LINE:
6848 int h = specials[special_index].height;
6849 int mid = font_ascent() / 2;
6851 w = text_start_x + text_width - cur_x;
6853 XSetLineAttributes(display, window.gc, h, LineSolid,
6854 CapButt, JoinMiter);
6855 XDrawLine(display, window.drawable, window.gc, cur_x,
6856 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6862 int h = specials[special_index].height;
6863 int tmp_s = specials[special_index].arg;
6864 int mid = font_ascent() / 2;
6865 char ss[2] = { tmp_s, tmp_s };
6867 w = text_start_x + text_width - cur_x - 1;
6868 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6869 CapButt, JoinMiter);
6870 XSetDashes(display, window.gc, 0, ss, 2);
6871 XDrawLine(display, window.drawable, window.gc, cur_x,
6872 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6878 int h, bar_usage, by;
6879 if (cur_x - text_start_x > maximum_width
6880 && maximum_width > 0) {
6883 h = specials[special_index].height;
6884 bar_usage = specials[special_index].arg;
6885 by = cur_y - (font_ascent() / 2) - 1;
6887 if (h < font_height()) {
6890 w = specials[special_index].width;
6892 w = text_start_x + text_width - cur_x - 1;
6898 XSetLineAttributes(display, window.gc, 1, LineSolid,
6899 CapButt, JoinMiter);
6901 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6903 XFillRectangle(display, window.drawable, window.gc, cur_x,
6904 by, w * bar_usage / 255, h);
6905 if (specials[special_index].height > cur_y_add
6906 && specials[special_index].height > font_h) {
6907 cur_y_add = specials[special_index].height;
6914 int h, by, i, j = 0;
6915 int gradient_size = 0;
6916 float gradient_factor = 0;
6917 float gradient_update = 0;
6918 unsigned long last_colour = current_color;
6919 unsigned long tmpcolour = current_color;
6920 int show_scale_x = cur_x + font_ascent() / 2;
6921 int show_scale_y = cur_y + font_height() / 2;
6922 if (cur_x - text_start_x > maximum_width
6923 && maximum_width > 0) {
6926 h = specials[special_index].height;
6927 by = cur_y - (font_ascent() / 2) - 1;
6929 if (h < font_height()) {
6932 w = specials[special_index].width;
6934 w = text_start_x + text_width - cur_x - 1;
6939 if (draw_graph_borders) {
6940 XSetLineAttributes(display, window.gc, 1, LineSolid,
6941 CapButt, JoinMiter);
6942 XDrawRectangle(display, window.drawable, window.gc,
6945 XSetLineAttributes(display, window.gc, 1, LineSolid,
6946 CapButt, JoinMiter);
6948 if (specials[special_index].last_colour != 0
6949 || specials[special_index].first_colour != 0) {
6950 tmpcolour = specials[special_index].last_colour;
6952 gradient_max(specials[special_index].last_colour,
6953 specials[special_index].first_colour);
6954 gradient_factor = (float) gradient_size / (w - 2);
6956 for (i = w - 2; i > -1; i--) {
6957 if (specials[special_index].last_colour != 0
6958 || specials[special_index].first_colour != 0) {
6959 XSetForeground(display, window.gc, tmpcolour);
6960 gradient_update += gradient_factor;
6961 while (gradient_update > 0) {
6962 tmpcolour = do_gradient(tmpcolour,
6963 specials[special_index].first_colour);
6967 if ((w - i) / ((float) (w - 2) /
6968 (specials[special_index].graph_width)) > j
6969 && j < MAX_GRAPH_DEPTH - 3) {
6972 /* this is mugfugly, but it works */
6973 XDrawLine(display, window.drawable, window.gc,
6974 cur_x + i + 1, by + h, cur_x + i + 1,
6975 by + h - specials[special_index].graph[j] *
6976 (h - 1) / specials[special_index].graph_scale);
6978 if (specials[special_index].height > cur_y_add
6979 && specials[special_index].height > font_h) {
6980 cur_y_add = specials[special_index].height;
6982 /* if (draw_mode == BG) {
6983 set_foreground_color(default_bg_color);
6984 } else if (draw_mode == OUTLINE) {
6985 set_foreground_color(default_out_color);
6987 set_foreground_color(default_fg_color);
6989 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
6992 cur_x = show_scale_x;
6993 cur_y = show_scale_y;
6995 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
6997 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
6998 draw_string(tmp_str);
7003 set_foreground_color(last_colour);
7009 int old = font_ascent();
7011 cur_y -= font_ascent();
7012 selected_font = specials[special_index].font_added;
7013 if (cur_y + font_ascent() < cur_y + old) {
7016 cur_y += font_ascent();
7022 if (draw_mode == FG) {
7023 set_foreground_color(specials[special_index].arg);
7028 if (draw_mode == BG) {
7029 set_foreground_color(specials[special_index].arg);
7034 if (draw_mode == OUTLINE) {
7035 set_foreground_color(specials[special_index].arg);
7040 w += specials[special_index].arg;
7044 cur_y += specials[special_index].arg;
7048 if (specials[special_index].arg >= 0) {
7049 cur_x = (int) specials[special_index].arg;
7055 int start = specials[special_index].arg;
7056 int step = specials[special_index].width;
7058 if (!step || step < 0) {
7061 w = step - (cur_x - text_start_x - start) % step;
7067 /* TODO: add back in "+ border_margin" to the end of
7069 int pos_x = text_start_x + text_width -
7070 get_string_width_special(s);
7072 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
7073 "get_string_width(p) %i gap_x %i "
7074 "specials[special_index].arg %i border_margin %i "
7075 "border_width %i\n", pos_x, text_start_x, text_width,
7076 cur_x, get_string_width_special(s), gap_x,
7077 specials[special_index].arg, border_margin,
7079 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
7080 cur_x = pos_x - specials[special_index].arg;
7087 int pos_x = (text_width) / 2 - get_string_width_special(s) /
7088 2 - (cur_x - text_start_x);
7089 /* int pos_x = text_start_x + text_width / 2 -
7090 get_string_width_special(s) / 2; */
7092 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
7093 "get_string_width(p) %i gap_x %i "
7094 "specials[special_index].arg %i\n", pos_x, text_start_x,
7095 text_width, cur_x, get_string_width(s), gap_x,
7096 specials[special_index].arg); */
7097 if (pos_x > specials[special_index].arg) {
7098 w = pos_x - specials[special_index].arg;
7115 if (cur_y_add > 0) {
7117 cur_y -= font_descent();
7122 cur_y += font_descent();
7126 static void draw_text(void)
7129 cur_y = text_start_y;
7132 if (draw_borders && border_width > 0) {
7133 unsigned int b = (border_width + 1) / 2;
7135 if (stippled_borders) {
7136 char ss[2] = { stippled_borders, stippled_borders };
7137 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
7138 CapButt, JoinMiter);
7139 XSetDashes(display, window.gc, 0, ss, 2);
7141 XSetLineAttributes(display, window.gc, border_width, LineSolid,
7142 CapButt, JoinMiter);
7145 XDrawRectangle(display, window.drawable, window.gc,
7146 text_start_x - border_margin + b, text_start_y - border_margin + b,
7147 text_width + border_margin * 2 - 1 - b * 2,
7148 text_height + border_margin * 2 - 1 - b * 2);
7154 for_each_line(text_buffer, draw_line);
7157 static void draw_stuff(void)
7161 if (draw_shades && !draw_outline) {
7164 set_foreground_color(default_bg_color);
7175 for (i = -1; i < 2; i++) {
7176 for (j = -1; j < 2; j++) {
7177 if (i == 0 && j == 0) {
7182 set_foreground_color(default_out_color);
7183 draw_mode = OUTLINE;
7191 set_foreground_color(default_fg_color);
7200 swap.swap_window = window.window;
7201 swap.swap_action = XdbeBackground;
7202 XdbeSwapBuffers(display, &swap, 1);
7209 static void clear_text(int exposures)
7213 /* The swap action is XdbeBackground, which clears */
7218 /* there is some extra space for borders and outlines */
7219 XClearArea(display, window.window, text_start_x - border_margin - 1,
7220 text_start_y - border_margin - 1,
7221 text_width + border_margin * 2 + 2,
7222 text_height + border_margin * 2 + 2, exposures ? True : 0);
7227 static int need_to_update;
7229 /* update_text() generates new text and clears old text area */
7230 static void update_text(void)
7239 static void main_loop(void)
7241 #ifdef SIGNAL_BLOCKING
7242 sigset_t newmask, oldmask;
7245 Region region = XCreateRegion();
7249 XserverRegion region2, part;
7250 int event_base, error_base;
7252 if (!XDamageQueryExtension(display, &event_base, &error_base)) {
7253 ERR("Xdamage extension unavailable");
7255 damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7256 region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7257 part = XFixesCreateRegionFromWindow(display, window.window, 0);
7258 #endif /* HAVE_XDAMAGE */
7261 #ifdef SIGNAL_BLOCKING
7262 sigemptyset(&newmask);
7263 sigaddset(&newmask, SIGINT);
7264 sigaddset(&newmask, SIGTERM);
7265 sigaddset(&newmask, SIGUSR1);
7269 while (total_run_times == 0 || info.looped < total_run_times) {
7272 #ifdef SIGNAL_BLOCKING
7273 /* block signals. we will inspect for pending signals later */
7274 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
7275 CRIT_ERR("unable to sigprocmask()");
7282 /* wait for X event or timeout */
7284 if (!XPending(display)) {
7288 double t = update_interval - (get_time() - last_update_time);
7294 tv.tv_sec = (long) t;
7295 tv.tv_usec = (long) (t * 1000000) % 1000000;
7297 FD_SET(ConnectionNumber(display), &fdsr);
7299 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
7301 if (errno != EINTR) {
7302 ERR("can't select(): %s", strerror(errno));
7308 /* FIXME just sleep for the interval time if no X11 */
7309 usleep(update_interval * 1000000);
7317 if (need_to_update) {
7319 int wx = window.x, wy = window.y;
7327 /* resize window if it isn't right size */
7329 && (text_width + border_margin * 2 + 1 != window.width
7330 || text_height + border_margin * 2 + 1 != window.height)) {
7331 window.width = text_width + border_margin * 2 + 1;
7332 window.height = text_height + border_margin * 2 + 1;
7333 XResizeWindow(display, window.window, window.width,
7336 set_transparent_background(window.window);
7340 /* move window if it isn't in right position */
7341 if (!fixed_pos && (window.x != wx || window.y != wy)) {
7342 XMoveWindow(display, window.window, window.x, window.y);
7353 r.x = text_start_x - border_margin;
7354 r.y = text_start_y - border_margin;
7355 r.width = text_width + border_margin * 2;
7356 r.height = text_height + border_margin * 2;
7357 XUnionRectWithRegion(&r, region, region);
7362 /* handle X events */
7363 while (XPending(display)) {
7366 XNextEvent(display, &ev);
7374 r.width = ev.xexpose.width;
7375 r.height = ev.xexpose.height;
7376 XUnionRectWithRegion(&r, region, region);
7381 case ReparentNotify:
7382 /* set background to ParentRelative for all parents */
7384 set_transparent_background(window.window);
7388 case ConfigureNotify:
7390 /* if window size isn't what expected, set fixed size */
7391 if (ev.xconfigure.width != window.width
7392 || ev.xconfigure.height != window.height) {
7393 if (window.width != 0 && window.height != 0) {
7397 /* clear old stuff before screwing up
7402 XWindowAttributes attrs;
7404 if (XGetWindowAttributes(display,
7405 window.window, &attrs)) {
7406 window.width = attrs.width;
7407 window.height = attrs.height;
7411 text_width = window.width - border_margin * 2 - 1;
7412 text_height = window.height - border_margin * 2 - 1;
7413 if (text_width > maximum_width
7414 && maximum_width > 0) {
7415 text_width = maximum_width;
7419 /* if position isn't what expected, set fixed pos
7420 * total_updates avoids setting fixed_pos when window
7421 * is set to weird locations when started */
7422 /* // this is broken
7423 if (total_updates >= 2 && !fixed_pos
7424 && (window.x != ev.xconfigure.x
7425 || window.y != ev.xconfigure.y)
7426 && (ev.xconfigure.x != 0
7427 || ev.xconfigure.y != 0)) {
7436 /* if an ordinary window with decorations */
7437 if ((window.type == TYPE_NORMAL)
7438 && (!TEST_HINT(window.hints,
7439 HINT_UNDECORATED))) {
7440 /* allow conky to hold input focus. */
7443 /* forward the click to the desktop window */
7444 XUngrabPointer(display, ev.xbutton.time);
7445 ev.xbutton.window = window.desktop;
7446 XSendEvent(display, ev.xbutton.window, False,
7447 ButtonPressMask, &ev);
7448 XSetInputFocus(display, ev.xbutton.window,
7449 RevertToParent, ev.xbutton.time);
7456 /* if an ordinary window with decorations */
7457 if ((window.type == TYPE_NORMAL)
7458 && (!TEST_HINT(window.hints,
7459 HINT_UNDECORATED))) {
7460 /* allow conky to hold input focus. */
7463 /* forward the release to the desktop window */
7464 ev.xbutton.window = window.desktop;
7465 XSendEvent(display, ev.xbutton.window, False,
7466 ButtonReleaseMask, &ev);
7475 if (ev.type == event_base + XDamageNotify) {
7476 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
7478 XFixesSetRegion(display, part, &dev->area, 1);
7479 XFixesUnionRegion(display, region2, region2, part);
7481 #endif /* HAVE_XDAMAGE */
7487 XDamageSubtract(display, damage, region2, None);
7488 XFixesSetRegion(display, region2, 0, 0);
7489 #endif /* HAVE_XDAMAGE */
7491 /* XDBE doesn't seem to provide a way to clear the back buffer without
7492 * interfering with the front buffer, other than passing XdbeBackground
7493 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
7494 * redraw the text even if it wasn't part of the exposed area. OTOH,
7495 * if we're not going to call draw_stuff at all, then no swap happens
7496 * and we can safely do nothing. */
7498 if (!XEmptyRegion(region)) {
7503 r.x = text_start_x - border_margin;
7504 r.y = text_start_y - border_margin;
7505 r.width = text_width + border_margin * 2;
7506 r.height = text_height + border_margin * 2;
7507 XUnionRectWithRegion(&r, region, region);
7510 XSetRegion(display, window.gc, region);
7513 XftDrawSetClip(window.xftdraw, region);
7519 XDestroyRegion(region);
7520 region = XCreateRegion();
7524 #ifdef SIGNAL_BLOCKING
7525 /* unblock signals of interest and let handler fly */
7526 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
7527 CRIT_ERR("unable to sigprocmask()");
7531 switch (g_signal_pending) {
7534 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
7539 ERR("received SIGINT or SIGTERM to terminate. bye!");
7542 XDestroyRegion(region);
7545 XDamageDestroy(display, damage);
7546 XFixesDestroyRegion(display, region2);
7547 XFixesDestroyRegion(display, part);
7548 #endif /* HAVE_XDAMAGE */
7550 return; /* return from main_loop */
7553 /* Reaching here means someone set a signal
7554 * (SIGXXXX, signal_handler), but didn't write any code
7556 * If you don't want to handle a signal, don't set a handler on
7557 * it in the first place. */
7558 if (g_signal_pending) {
7559 ERR("ignoring signal (%d)", g_signal_pending);
7563 g_signal_pending = 0;
7566 #if defined(X11) && defined(HAVE_XDAMAGE)
7567 XDamageDestroy(display, damage);
7568 XFixesDestroyRegion(display, region2);
7569 XFixesDestroyRegion(display, part);
7570 XDestroyRegion(region);
7572 #endif /* X11 && HAVE_XDAMAGE */
7575 static void load_config_file(const char *);
7577 /* reload the config file */
7578 void reload_config(void)
7580 timed_thread_destroy_registered_threads();
7582 if (info.cpu_usage) {
7583 free(info.cpu_usage);
7584 info.cpu_usage = NULL;
7592 if (info.mpd.title) {
7593 free(info.mpd.title);
7594 info.mpd.title = NULL;
7596 if (info.mpd.artist) {
7597 free(info.mpd.artist);
7598 info.mpd.artist = NULL;
7600 if (info.mpd.album) {
7601 free(info.mpd.album);
7602 info.mpd.album = NULL;
7604 if (info.mpd.random) {
7605 free(info.mpd.random);
7606 info.mpd.random = NULL;
7608 if (info.mpd.repeat) {
7609 free(info.mpd.repeat);
7610 info.mpd.repeat = NULL;
7612 if (info.mpd.track) {
7613 free(info.mpd.track);
7614 info.mpd.track = NULL;
7616 if (info.mpd.name) {
7617 free(info.mpd.name);
7618 info.mpd.name = NULL;
7620 if (info.mpd.file) {
7621 free(info.mpd.file);
7622 info.mpd.file = NULL;
7624 if (info.mpd.status) {
7625 free(info.mpd.status);
7626 info.mpd.status = NULL;
7634 #ifdef TCP_PORT_MONITOR
7635 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7638 if (current_config) {
7640 load_config_file(current_config);
7642 /* re-init specials array */
7643 if ((specials = realloc((void *) specials,
7644 sizeof(struct special_t) * max_specials)) == 0) {
7645 ERR("failed to realloc specials array");
7651 // clear the window first
7652 XClearWindow(display, RootWindow(display, screen));
7655 #ifdef TCP_PORT_MONITOR
7656 info.p_tcp_port_monitor_collection = NULL;
7658 extract_variable_text(text);
7664 tmpstring1 = malloc(text_buffer_size);
7665 memset(tmpstring1, 0, text_buffer_size);
7669 tmpstring2 = malloc(text_buffer_size);
7670 memset(tmpstring2, 0, text_buffer_size);
7674 text_buffer = malloc(max_user_text);
7675 memset(text_buffer, 0, max_user_text);
7682 timed_thread_destroy_registered_threads();
7684 if (info.cpu_usage) {
7685 free(info.cpu_usage);
7686 info.cpu_usage = NULL;
7691 XdbeDeallocateBackBufferName(display, window.back_buffer);
7696 XDestroyWindow(display, window.window);
7697 XClearWindow(display, RootWindow(display, screen));
7702 XClearWindow(display, RootWindow(display, screen));
7707 XFreeGC(display, window.gc);
7711 free_text_objects(global_text_object_count, global_text_objects);
7724 global_text_object_count = 0;
7725 global_text_objects = NULL;
7732 free(current_config);
7734 #ifdef TCP_PORT_MONITOR
7735 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7736 info.p_tcp_port_monitor_collection = NULL;
7745 for (i = 0; i < special_count; i++) {
7746 if (specials[i].type == GRAPH) {
7747 free(specials[i].graph);
7754 clear_diskio_stats();
7757 static int string_to_bool(const char *s)
7761 } else if (strcasecmp(s, "yes") == 0) {
7763 } else if (strcasecmp(s, "true") == 0) {
7765 } else if (strcasecmp(s, "1") == 0) {
7772 static enum alignment string_to_alignment(const char *s)
7774 if (strcasecmp(s, "top_left") == 0) {
7776 } else if (strcasecmp(s, "top_right") == 0) {
7778 } else if (strcasecmp(s, "top_middle") == 0) {
7780 } else if (strcasecmp(s, "bottom_left") == 0) {
7782 } else if (strcasecmp(s, "bottom_right") == 0) {
7783 return BOTTOM_RIGHT;
7784 } else if (strcasecmp(s, "bottom_middle") == 0) {
7785 return BOTTOM_MIDDLE;
7786 } else if (strcasecmp(s, "middle_left") == 0) {
7788 } else if (strcasecmp(s, "middle_right") == 0) {
7789 return MIDDLE_RIGHT;
7790 } else if (strcasecmp(s, "tl") == 0) {
7792 } else if (strcasecmp(s, "tr") == 0) {
7794 } else if (strcasecmp(s, "tm") == 0) {
7796 } else if (strcasecmp(s, "bl") == 0) {
7798 } else if (strcasecmp(s, "br") == 0) {
7799 return BOTTOM_RIGHT;
7800 } else if (strcasecmp(s, "bm") == 0) {
7801 return BOTTOM_MIDDLE;
7802 } else if (strcasecmp(s, "ml") == 0) {
7804 } else if (strcasecmp(s, "mr") == 0) {
7805 return MIDDLE_RIGHT;
7806 } else if (strcasecmp(s, "none") == 0) {
7813 static void set_default_configurations(void)
7815 fork_to_background = 0;
7816 total_run_times = 0;
7817 info.cpu_avg_samples = 2;
7818 info.net_avg_samples = 2;
7825 strcpy(info.mpd.host, "localhost");
7826 info.mpd.port = 6600;
7827 info.mpd.status = NULL;
7828 info.mpd.artist = NULL;
7829 info.mpd.album = NULL;
7830 info.mpd.title = NULL;
7831 info.mpd.random = NULL;
7832 info.mpd.track = NULL;
7833 info.mpd.name = NULL;
7834 info.mpd.file = NULL;
7837 info.xmms2.artist = NULL;
7838 info.xmms2.album = NULL;
7839 info.xmms2.title = NULL;
7840 info.xmms2.genre = NULL;
7841 info.xmms2.comment = NULL;
7842 info.xmms2.url = NULL;
7843 info.xmms2.status = NULL;
7844 info.xmms2.playlist = NULL;
7846 use_spacer = NO_SPACER;
7853 show_graph_scale = 0;
7854 default_fg_color = WhitePixel(display, screen);
7855 default_bg_color = BlackPixel(display, screen);
7856 default_out_color = BlackPixel(display, screen);
7857 color0 = default_fg_color;
7858 color1 = default_fg_color;
7859 color2 = default_fg_color;
7860 color3 = default_fg_color;
7861 color4 = default_fg_color;
7862 color5 = default_fg_color;
7863 color6 = default_fg_color;
7864 color7 = default_fg_color;
7865 color8 = default_fg_color;
7866 color9 = default_fg_color;
7869 draw_graph_borders = 1;
7871 set_first_font("6x10");
7879 window.type = TYPE_NORMAL;
7881 strcpy(window.class_name, "Conky");
7883 sprintf(window.title, "Conky (%s)", info.uname_s.nodename);
7885 stippled_borders = 0;
7888 text_alignment = BOTTOM_LEFT;
7891 free(current_mail_spool);
7895 variable_substitute(MAIL_FILE, buf, 256);
7896 if (buf[0] != '\0') {
7897 current_mail_spool = strndup(buf, text_buffer_size);
7902 update_interval = 3.0;
7903 info.music_player_interval = 1.0;
7904 stuff_in_upper_case = 0;
7905 info.users.number = 1;
7907 #ifdef TCP_PORT_MONITOR
7908 tcp_port_monitor_args.max_port_monitor_connections =
7909 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7913 static void load_config_file(const char *f)
7915 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7919 set_default_configurations();
7926 char buf[256], *p, *p2, *name, *value;
7929 if (fgets(buf, 256, fp) == NULL) {
7935 /* break at comment */
7936 p2 = strchr(p, '#');
7942 while (*p && isspace((int) *p)) {
7946 continue; /* empty line */
7953 while (*p2 && !isspace((int) *p2)) {
7957 *p2 = '\0'; /* break at name's end */
7964 while (*p && isspace((int) *p)) {
7970 p2 = value + strlen(value);
7971 while (isspace((int) *(p2 - 1))) {
7978 #define CONF2(a) if (strcasecmp(name, a) == 0)
7979 #define CONF(a) else CONF2(a)
7980 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7981 || strcasecmp(name, b) == 0)
7984 CONF2("alignment") {
7986 int a = string_to_alignment(value);
7997 CONF("background") {
7998 fork_to_background = string_to_bool(value);
8001 CONF2("background") {
8002 fork_to_background = string_to_bool(value);
8006 CONF("show_graph_scale") {
8007 show_graph_scale = string_to_bool(value);
8009 CONF("border_margin") {
8011 border_margin = strtol(value, 0, 0);
8016 CONF("border_width") {
8018 border_width = strtol(value, 0, 0);
8025 color0 = get_x11_color(value);
8032 color1 = get_x11_color(value);
8039 color2 = get_x11_color(value);
8046 color3 = get_x11_color(value);
8053 color4 = get_x11_color(value);
8060 color5 = get_x11_color(value);
8067 color6 = get_x11_color(value);
8074 color7 = get_x11_color(value);
8081 color8 = get_x11_color(value);
8088 color9 = get_x11_color(value);
8093 CONF("default_color") {
8095 default_fg_color = get_x11_color(value);
8100 CONF3("default_shade_color", "default_shadecolor") {
8102 default_bg_color = get_x11_color(value);
8107 CONF3("default_outline_color", "default_outlinecolor") {
8109 default_out_color = get_x11_color(value);
8117 info.mail = parse_mail_args(IMAP, value);
8124 info.mail = parse_mail_args(POP3, value);
8132 strncpy(info.mpd.host, value, 127);
8139 info.mpd.port = strtol(value, 0, 0);
8140 if (info.mpd.port < 1 || info.mpd.port > 0xffff) {
8145 CONF("mpd_password") {
8147 strncpy(info.mpd.password, value, 127);
8153 CONF("music_player_interval") {
8155 info.music_player_interval = strtod(value, 0);
8161 CONF("sensor_device") {
8163 sensor_device = strtol(value, 0, 0);
8169 CONF("cpu_avg_samples") {
8171 cpu_avg_samples = strtol(value, 0, 0);
8172 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
8175 info.cpu_avg_samples = cpu_avg_samples;
8181 CONF("net_avg_samples") {
8183 net_avg_samples = strtol(value, 0, 0);
8184 if (net_avg_samples < 1 || net_avg_samples > 14) {
8187 info.net_avg_samples = net_avg_samples;
8195 CONF("double_buffer") {
8196 use_xdbe = string_to_bool(value);
8200 CONF("override_utf8_locale") {
8201 utf8_mode = string_to_bool(value);
8203 CONF("draw_borders") {
8204 draw_borders = string_to_bool(value);
8206 CONF("draw_graph_borders") {
8207 draw_graph_borders = string_to_bool(value);
8209 CONF("draw_shades") {
8210 draw_shades = string_to_bool(value);
8212 CONF("draw_outline") {
8213 draw_outline = string_to_bool(value);
8216 CONF("out_to_console") {
8217 out_to_console = string_to_bool(value);
8219 CONF("use_spacer") {
8221 if (strcasecmp(value, "left") == 0) {
8222 use_spacer = LEFT_SPACER;
8223 } else if (strcasecmp(value, "right") == 0) {
8224 use_spacer = RIGHT_SPACER;
8225 } else if (strcasecmp(value, "none") == 0) {
8226 use_spacer = NO_SPACER;
8228 use_spacer = string_to_bool(value);
8229 ERR("use_spacer should have an argument of left, right, or"
8230 " none. '%s' seems to be some form of '%s', so"
8231 " defaulting to %s.", value,
8232 use_spacer ? "true" : "false",
8233 use_spacer ? "right" : "none");
8235 use_spacer = RIGHT_SPACER;
8237 use_spacer = NO_SPACER;
8241 ERR("use_spacer should have an argument. Defaulting to right.");
8242 use_spacer = RIGHT_SPACER;
8248 use_xft = string_to_bool(value);
8252 set_first_font(value);
8258 if (value && font_count >= 0) {
8259 fonts[0].font_alpha = atof(value) * 65535.0;
8268 if (string_to_bool(value)) {
8269 ERR("Xft not enabled");
8273 /* xftfont silently ignored when no Xft */
8276 /* xftalpha is silently ignored when no Xft */
8281 set_first_font(value);
8291 gap_x = atoi(value);
8298 gap_y = atoi(value);
8304 CONF("mail_spool") {
8308 variable_substitute(value, buffer, 256);
8310 if (buffer[0] != '\0') {
8311 if (current_mail_spool) {
8312 free(current_mail_spool);
8314 current_mail_spool = strndup(buffer, text_buffer_size);
8321 CONF("minimum_size") {
8323 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
8325 if (sscanf(value, "%d", &minimum_width) != 1) {
8333 CONF("maximum_width") {
8335 if (sscanf(value, "%d", &maximum_width) != 1) {
8343 CONF("no_buffers") {
8344 no_buffers = string_to_bool(value);
8346 CONF("top_cpu_separate") {
8347 cpu_separate = string_to_bool(value);
8349 CONF("short_units") {
8350 short_units = string_to_bool(value);
8352 CONF("pad_percents") {
8353 pad_percents = atoi(value);
8357 CONF("own_window") {
8359 own_window = string_to_bool(value);
8364 CONF("own_window_class") {
8366 memset(window.class_name, 0, sizeof(window.class_name));
8367 strncpy(window.class_name, value,
8368 sizeof(window.class_name) - 1);
8373 CONF("own_window_title") {
8375 memset(window.title, 0, sizeof(window.title));
8376 strncpy(window.title, value, sizeof(window.title) - 1);
8381 CONF("own_window_transparent") {
8383 set_transparent = string_to_bool(value);
8388 CONF("own_window_colour") {
8390 background_colour = get_x11_color(value);
8392 ERR("Invalid colour for own_window_colour (try omitting the "
8393 "'#' for hex colours");
8396 CONF("own_window_hints") {
8398 char *p_hint, *p_save;
8399 char delim[] = ", ";
8401 /* tokenize the value into individual hints */
8402 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
8404 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
8405 if (strncmp(p_hint, "undecorate", 10) == 0) {
8406 SET_HINT(window.hints, HINT_UNDECORATED);
8407 } else if (strncmp(p_hint, "below", 5) == 0) {
8408 SET_HINT(window.hints, HINT_BELOW);
8409 } else if (strncmp(p_hint, "above", 5) == 0) {
8410 SET_HINT(window.hints, HINT_ABOVE);
8411 } else if (strncmp(p_hint, "sticky", 6) == 0) {
8412 SET_HINT(window.hints, HINT_STICKY);
8413 } else if (strncmp(p_hint, "skip_taskbar", 12) == 0) {
8414 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
8415 } else if (strncmp(p_hint, "skip_pager", 10) == 0) {
8416 SET_HINT(window.hints, HINT_SKIP_PAGER);
8421 p_hint = strtok_r(NULL, delim, &p_save);
8422 } while (p_hint != NULL);
8428 CONF("own_window_type") {
8430 if (strncmp(value, "normal", 6) == 0) {
8431 window.type = TYPE_NORMAL;
8432 } else if (strncmp(value, "desktop", 7) == 0) {
8433 window.type = TYPE_DESKTOP;
8434 } else if (strncmp(value, "dock", 7) == 0) {
8435 window.type = TYPE_DOCK;
8436 } else if (strncmp(value, "override", 8) == 0) {
8437 window.type = TYPE_OVERRIDE;
8446 CONF("stippled_borders") {
8448 stippled_borders = strtol(value, 0, 0);
8450 stippled_borders = 4;
8455 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> "
8459 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> "
8462 CONF("update_interval") {
8464 update_interval = strtod(value, 0);
8468 if (info.music_player_interval == 0) {
8469 // default to update_interval
8470 info.music_player_interval = update_interval;
8473 CONF("total_run_times") {
8475 total_run_times = strtod(value, 0);
8481 stuff_in_upper_case = string_to_bool(value);
8483 CONF("max_specials") {
8485 max_specials = atoi(value);
8490 CONF("max_user_text") {
8492 max_user_text = atoi(value);
8497 CONF("text_buffer_size") {
8499 text_buffer_size = atoi(value);
8500 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
8501 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
8502 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
8514 text = (char *) malloc(1);
8518 unsigned int l = strlen(text);
8520 if (fgets(buf, 256, fp) == NULL) {
8523 text = (char *) realloc(text, l + strlen(buf) + 1);
8526 if (strlen(text) > max_user_text) {
8531 if (strlen(text) < 1) {
8532 CRIT_ERR("no text supplied in configuration; exiting");
8534 text_lines = line + 1;
8537 #ifdef TCP_PORT_MONITOR
8538 CONF("max_port_monitor_connections") {
8539 if (!value || (sscanf(value, "%d",
8540 &tcp_port_monitor_args.max_port_monitor_connections) != 1)
8541 || tcp_port_monitor_args.max_port_monitor_connections < 0) {
8542 /* an error. use default, warn and continue. */
8543 tcp_port_monitor_args.max_port_monitor_connections =
8544 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8546 } else if (tcp_port_monitor_args.max_port_monitor_connections
8548 /* no error, just use default */
8549 tcp_port_monitor_args.max_port_monitor_connections =
8550 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8552 /* else tcp_port_monitor_args.max_port_monitor_connections > 0
8556 CONF("if_up_strictness") {
8558 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8559 ifup_strictness = IFUP_UP;
8560 } else if (!strcmp(value, "up")) {
8561 ifup_strictness = IFUP_UP;
8562 } else if (!strcmp(value, "link")) {
8563 ifup_strictness = IFUP_LINK;
8564 } else if (!strcmp(value, "address")) {
8565 ifup_strictness = IFUP_ADDR;
8567 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8568 ifup_strictness = IFUP_UP;
8572 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8583 if (info.music_player_interval == 0) {
8584 // default to update_interval
8585 info.music_player_interval = update_interval;
8587 if (!text) { // didn't supply any text
8588 CRIT_ERR("missing text block in configuration; exiting");
8592 static void print_help(const char *prog_name) {
8593 printf("Usage: %s [OPTION]...\n"
8594 "Conky is a system monitor that renders text on desktop or to own transparent\n"
8595 "window. Command line options will override configurations defined in config\n"
8597 " -v, --version version\n"
8598 " -q, --quiet quiet mode\n"
8599 " -c, --config=FILE config file to load\n"
8600 " -d, --daemonize daemonize, fork to background\n"
8601 " -h, --help help\n"
8603 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
8604 " -f, --font=FONT font to use\n"
8606 " -o, --own-window create own window to draw\n"
8609 " -b, --double-buffer double buffer (prevents flickering)\n"
8611 " -w, --window-id=WIN_ID window id to draw\n"
8612 " -x X x position\n"
8613 " -y Y y position\n"
8615 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8616 " -u, --interval=SECS update interval\n"
8617 " -i COUNT number of times to update Conky (and quit)\n",
8622 /* : means that character before that takes an argument */
8623 static const char *getopt_string = "vVqdt:u:i:hc:"
8635 static const struct option longopts[] = {
8636 { "help", 0, NULL, 'h' },
8637 { "version", 0, NULL, 'V' },
8638 { "config", 1, NULL, 'c' },
8639 { "daemonize", 0, NULL, 'd' },
8641 { "alignment", 1, NULL, 'a' },
8642 { "font", 1, NULL, 'f' },
8644 { "own-window", 0, NULL, 'o' },
8647 { "double-buffer", 0, NULL, 'b' },
8649 { "window-id", 1, NULL, 'w' },
8651 { "text", 1, NULL, 't' },
8652 { "interval", 0, NULL, 'u' },
8656 int main(int argc, char **argv)
8662 struct sigaction act, oact;
8664 g_signal_pending = 0;
8665 memset(&info, 0, sizeof(info));
8667 #ifdef TCP_PORT_MONITOR
8668 tcp_port_monitor_args.max_port_monitor_connections =
8669 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8672 /* handle command line parameters that don't change configs */
8674 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8675 || ((s = getenv("LANG")) && *s)) {
8676 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8678 ERR("malloc failed");
8680 for (x = 0; x < strlen(s); x++) {
8681 temp[x] = tolower(s[x]);
8684 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8690 if (!setlocale(LC_CTYPE, "")) {
8691 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8695 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8706 if (current_config) {
8707 free(current_config);
8709 current_config = strndup(optarg, max_user_text);
8712 freopen("/dev/null", "w", stderr);
8715 print_help(argv[0]);
8719 window.window = strtol(optarg, 0, 0);
8728 /* initalize X BEFORE we load config.
8729 * (we need to so that 'screen' is set) */
8733 /* check if specified config file is valid */
8734 if (current_config) {
8736 if (stat(current_config, &sb) ||
8737 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8738 ERR("invalid configuration file '%s'\n", current_config);
8739 free(current_config);
8744 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8746 if (!current_config) {
8747 /* load default config file */
8751 /* Try to use personal config file first */
8752 variable_substitute(CONFIG_FILE, buf, sizeof(buf));
8753 if (buf[0] && (fp = fopen(buf, "r"))) {
8754 current_config = strndup(buf, max_user_text);
8758 /* Try to use system config file if personal config not readable */
8759 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8760 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
8764 /* No readable config found */
8765 if (!current_config) {
8766 CRIT_ERR("no readable personal or system-wide config file found");
8770 load_config_file(current_config);
8772 /* init specials array */
8773 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8774 ERR("failed to create specials array");
8778 if (current_mail_spool == NULL) {
8781 variable_substitute(MAIL_FILE, buf, 256);
8783 if (buf[0] != '\0') {
8784 current_mail_spool = strndup(buf, text_buffer_size);
8789 /* handle other command line arguments */
8791 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8792 || defined(__NetBSD__)
8793 optind = optreset = 1;
8798 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8799 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8800 "kvm_open")) == NULL) {
8801 CRIT_ERR("cannot read kvm");
8806 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8814 fork_to_background = 1;
8819 set_first_font(optarg);
8822 text_alignment = string_to_alignment(optarg);
8841 text = strndup(optarg, max_user_text);
8842 convert_escapes(text);
8846 update_interval = strtod(optarg, 0);
8847 if (info.music_player_interval == 0) {
8848 // default to update_interval
8849 info.music_player_interval = update_interval;
8854 total_run_times = strtod(optarg, 0);
8858 gap_x = atoi(optarg);
8862 gap_y = atoi(optarg);
8876 /* generate text and get initial size */
8877 extract_variable_text(text);
8884 if (fork_to_background) {
8889 ERR("Conky: couldn't fork() to background: %s",
8896 fprintf(stderr, "\n");
8901 /* parent process */
8902 fprintf(stderr, "Conky: forked to background, pid is %d\n",
8909 text_buffer = malloc(max_user_text);
8910 memset(text_buffer, 0, max_user_text);
8911 tmpstring1 = malloc(text_buffer_size);
8912 memset(tmpstring1, 0, text_buffer_size);
8913 tmpstring2 = malloc(text_buffer_size);
8914 memset(tmpstring2, 0, text_buffer_size);
8918 update_text_area(); /* to get initial size of the window */
8921 init_window(own_window, text_width + border_margin * 2 + 1,
8922 text_height + border_margin * 2 + 1, set_transparent, background_colour,
8924 #else /* OWN_WINDOW */
8925 init_window(0, text_width + border_margin * 2 + 1,
8926 text_height + border_margin * 2 + 1, set_transparent, 0,
8928 #endif /* OWN_WINDOW */
8931 update_text_area(); /* to position text/window on screen */
8936 if (own_window && !fixed_pos) {
8937 XMoveWindow(display, window.window, window.x, window.y);
8940 set_transparent_background(window.window);
8950 /* Set signal handlers */
8951 act.sa_handler = signal_handler;
8952 sigemptyset(&act.sa_mask);
8955 act.sa_flags |= SA_RESTART;
8958 if (sigaction(SIGINT, &act, &oact) < 0
8959 || sigaction(SIGUSR1, &act, &oact) < 0
8960 || sigaction(SIGHUP,&act,&oact) < 0
8961 || sigaction(SIGTERM, &act, &oact) < 0) {
8962 ERR("error setting signal handler: %s", strerror(errno));
8965 /* *************** *
8967 * *************** */
8970 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8977 void signal_handler(int sig)
8979 /* signal handler is light as a feather, as it should be.
8980 * we will poll g_signal_pending with each loop of conky
8981 * and do any signal processing there, NOT here. */
8982 g_signal_pending = sig;