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-2007 Brenden Matthews, Philip Kovacs, et. al.
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
45 #include <X11/Xutil.h>
47 #include <X11/extensions/Xdamage.h>
53 #include <sys/types.h>
55 #include <netinet/in.h>
67 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
70 #define CONFIG_FILE "$HOME/.conkyrc"
71 #define MAIL_FILE "$MAIL"
72 #define MAX_IF_BLOCK_DEPTH 5
74 /* #define SIGNAL_BLOCKING */
75 #undef SIGNAL_BLOCKING
77 static void print_version(void)
79 printf("Conky %s compiled %s for %s\n", VERSION, BUILD_DATE, BUILD_ARCH);
81 printf("\nCompiled in features:\n\n"
82 "System config file: %s\n\n"
86 " * Xdamage extension\n"
87 # endif /* HAVE_XDAMAGE */
89 " * Xdbe extension (double buffer)\n"
90 # endif /* HAVE_XDBE */
95 "\n Music detection:\n"
98 #endif /* AUDACIOUS */
108 "\n General features:\n"
112 #ifdef TCP_PORT_MONITOR
114 #endif /* TCP_PORT_MONITOR */
120 #endif /* HAVE_IWLIB */
124 "", SYSTEM_CONFIG_FILE
130 static const char *suffixes[] = { "B", "kiB", "MiB", "GiB", "TiB", "PiB", "" };
136 static int text_start_x, text_start_y; /* text start position in window */
137 static int text_width, text_height;
155 char name[DEFAULT_TEXT_BUFFER_SIZE];
165 static int selected_font = 0;
166 static int font_count = -1;
167 struct font_list *fonts = NULL;
171 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + \
172 fonts[selected_font].xftfont->descent) \
173 : (fonts[selected_font].font->max_bounds.ascent + \
174 fonts[selected_font].font->max_bounds.descent))
175 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent \
176 : fonts[selected_font].font->max_bounds.ascent)
177 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent \
178 : fonts[selected_font].font->max_bounds.descent)
182 #define font_height() (fonts[selected_font].font->max_bounds.ascent + \
183 fonts[selected_font].font->max_bounds.descent)
184 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
185 #define font_descent() fonts[selected_font].font->max_bounds.descent
189 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
191 static void set_font(void);
193 int addfont(const char *data_in)
195 if (font_count > MAX_FONTS) {
196 CRIT_ERR("you don't need that many fonts, sorry.");
199 if (font_count == 0) {
203 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
207 memset(fonts, 0, sizeof(struct font_list));
209 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
210 memset(&fonts[font_count], 0, sizeof(struct font_list));
212 CRIT_ERR("realloc in addfont");
214 // must account for null terminator
215 if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
216 strncpy(fonts[font_count].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
218 fonts[font_count].font_alpha = 0xffff;
221 CRIT_ERR("Oops...looks like something overflowed in addfont().");
226 void set_first_font(const char *data_in)
228 if (font_count < 0) {
229 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
233 memset(fonts, 0, sizeof(struct font_list));
236 if (strlen(data_in) > 1) {
237 strncpy(fonts[0].name, data_in, DEFAULT_TEXT_BUFFER_SIZE - 1);
239 fonts[0].font_alpha = 0xffff;
244 void free_fonts(void)
248 for (i = 0; i <= font_count; i++) {
251 XftFontClose(display, fonts[i].xftfont);
252 fonts[i].xftfont = 0;
256 XFreeFont(display, fonts[i].font);
266 static void load_fonts(void)
270 for (i = 0; i <= font_count; i++) {
273 if (use_xft && fonts[i].xftfont) {
275 } else if (use_xft) {
276 /* if (fonts[i].xftfont != NULL && selected_font == 0) {
277 XftFontClose(display, fonts[i].xftfont);
279 fonts[i].xftfont = XftFontOpenName(display, screen,
281 if (fonts[i].xftfont != NULL) {
285 ERR("can't load Xft font '%s'", fonts[i].name);
286 if ((fonts[i].xftfont = XftFontOpenName(display, screen,
287 "courier-12")) != NULL) {
291 ERR("can't load Xft font '%s'", "courier-12");
293 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
294 CRIT_ERR("can't load font '%s'", "fixed");
301 /* load normal font */
302 /* if (fonts[i].font != NULL) {
303 XFreeFont(display, fonts[i].font);
306 if (fonts[i].font || (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
307 ERR("can't load font '%s'", fonts[i].name);
308 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
309 CRIT_ERR("can't load font '%s'", "fixed");
310 printf("loaded fixed?\n");
318 /* default config file */
319 static char *current_config;
321 /* set to 1 if you want all text to be in uppercase */
322 static unsigned int stuff_in_upper_case;
324 /* Run how many times? */
325 static unsigned long total_run_times;
328 static int fork_to_background;
330 static int cpu_avg_samples, net_avg_samples;
334 /* Position on the screen */
335 static int text_alignment;
336 static int gap_x, gap_y;
339 static int draw_borders;
340 static int draw_graph_borders;
341 static int stippled_borders;
343 static int draw_shades, draw_outline;
345 static int border_margin, border_width;
347 static long default_fg_color, default_bg_color, default_out_color;
349 /* create own window or draw stuff to root? */
350 static int set_transparent = 0;
353 static int own_window = 0;
354 static int background_colour = 0;
356 /* fixed size/pos is set if wm/user changes them */
357 static int fixed_size = 0, fixed_pos = 0;
360 static int minimum_width, minimum_height;
361 static int maximum_width;
366 static int sensor_device;
369 static long color0, color1, color2, color3, color4, color5, color6, color7,
372 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
373 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
375 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
376 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
378 /* maximum size of individual text buffers, ie $exec buffer size */
379 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
382 #define CODEPAGE_LENGTH 20
384 long iconv_count = 0;
385 char iconv_converting;
386 static iconv_t **iconv_cd = 0;
388 int register_iconv(iconv_t *new_iconv)
391 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
393 iconv_cd = malloc(sizeof(iconv_t *));
396 CRIT_ERR("Out of memory");
398 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
399 if (!iconv_cd[iconv_count]) {
400 CRIT_ERR("Out of memory");
402 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
407 void free_iconv(void)
412 for (i = 0; i < iconv_count; i++) {
414 iconv_close(*iconv_cd[i]);
428 /* no buffers in used memory? */
431 /* pad percentages to decimals? */
432 static int pad_percents = 0;
434 #ifdef TCP_PORT_MONITOR
435 tcp_port_monitor_args_t tcp_port_monitor_args;
438 static char *text = 0;
441 static int total_updates;
444 static int blockdepth = 0;
445 static int if_jumped = 0;
446 static int blockstart[MAX_IF_BLOCK_DEPTH];
448 int check_contains(char *f, char *s)
451 FILE *where = fopen(f, "r");
454 char buf1[256], buf2[256];
456 while (fgets(buf1, 256, where)) {
457 sscanf(buf1, "%255s", buf2);
458 if (strstr(buf2, s)) {
465 ERR("Could not open the file");
471 static inline int calc_text_width(const char *s, int l)
478 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
479 (const FcChar8 *) s, l, &gi);
481 XftTextExtents8(display, fonts[selected_font].xftfont,
482 (const FcChar8 *) s, l, &gi);
488 return XTextWidth(fonts[selected_font].font, s, l);
493 /* formatted text to render on screen, generated in generate_text(),
494 * drawn in draw_stuff() */
496 static char *text_buffer;
498 /* special stuff in text_buffer */
500 #define SPECIAL_CHAR '\x01'
528 unsigned long first_colour; // for graph gradient
529 unsigned long last_colour;
533 /* create specials array on heap instead of stack with introduction of
535 static struct special_t *specials = NULL;
537 static unsigned int special_count;
540 static unsigned int special_index; /* used when drawing */
543 /* why 256? cause an array of more then 256 doubles seems excessive,
544 * and who needs that kind of precision anyway? */
545 #define MAX_GRAPH_DEPTH 256
547 static struct special_t *new_special(char *buf, enum special_types t)
549 if (special_count >= max_specials) {
550 CRIT_ERR("too many special things in text");
553 buf[0] = SPECIAL_CHAR;
555 specials[special_count].type = t;
556 return &specials[special_count++];
559 long fwd_fcharfind(FILE *fp, char val, unsigned int step)
563 unsigned int count = 0;
564 static char buf[BUFSZ];
565 long orig_pos = ftell(fp);
567 long buf_size = BUFSZ;
568 char *cur_found = NULL;
570 while (count < step) {
571 if (cur_found == NULL) {
572 buf_size = fread(buf, 1, buf_size, fp);
575 cur_found = memchr(buf + buf_pos, val, buf_size - buf_pos);
576 if (cur_found != NULL) {
577 buf_pos = cur_found - buf + 1;
586 ret = ftell(fp) - buf_size + buf_pos - 1;
588 fseek(fp, orig_pos, SEEK_SET);
594 void *memrchr(const void *buffer, char c, size_t n)
596 const unsigned char *p = buffer;
598 for (p += n; n; n--) {
607 long rev_fcharfind(FILE *fp, char val, unsigned int step)
611 unsigned int count = 0;
612 static char buf[BUFSZ];
613 long orig_pos = ftell(fp);
615 long file_pos = orig_pos;
616 long buf_size = BUFSZ;
619 while (count < step) {
621 if (file_pos > BUFSZ) {
622 fseek(fp, file_pos - BUFSZ, SEEK_SET);
625 fseek(fp, 0, SEEK_SET);
627 file_pos = ftell(fp);
628 buf_pos = fread(buf, 1, buf_size, fp);
630 cur_found = memrchr(buf, val, (size_t) buf_pos);
631 if (cur_found != NULL) {
632 buf_pos = cur_found - buf;
641 fseek(fp, orig_pos, SEEK_SET);
643 ret = file_pos + buf_pos;
649 static void new_bar(char *buf, int w, int h, int usage)
651 struct special_t *s = new_special(buf, BAR);
653 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
658 static const char *scan_bar(const char *args, int *w, int *h)
660 /* zero width means all space that is available */
663 /* bar's argument is either height or height,width */
667 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) {
668 sscanf(args, "%d %n", h, &n);
676 static char *scan_font(const char *args)
686 static void new_font(char *buf, char *args)
689 struct special_t *s = new_special(buf, FONT);
691 if (s->font_added > font_count || !s->font_added || strncmp(args, fonts[s->font_added].name, DEFAULT_TEXT_BUFFER_SIZE)) {
692 int tmp = selected_font;
694 selected_font = s->font_added = addfont(args);
699 struct special_t *s = new_special(buf, FONT);
700 int tmp = selected_font;
702 selected_font = s->font_added = 0;
708 inline void graph_append(struct special_t *graph, double f)
712 if (!graph->scaled && f > graph->graph_scale) {
713 f = graph->graph_scale;
717 graph->graph_scale = 1;
719 graph->graph[0] = f; /* add new data */
720 /* shift all the data by 1 */
721 for (i = graph->graph_width - 1; i > 0; i--) {
722 graph->graph[i] = graph->graph[i - 1];
723 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
724 /* check if we need to update the scale */
725 graph->graph_scale = graph->graph[i];
730 short colour_depth = 0;
731 void set_up_gradient(void);
733 /* precalculated: 31/255, and 63/255 */
734 #define CONST_8_TO_5_BITS 0.12156862745098
735 #define CONST_8_TO_6_BITS 0.247058823529412
737 /* adjust color values depending on color depth */
738 static unsigned int adjust_colors(unsigned int color)
742 if (colour_depth == 0) {
745 if (colour_depth == 16) {
746 r = (color & 0xff0000) >> 16;
747 g = (color & 0xff00) >> 8;
749 color = (int) (r * CONST_8_TO_5_BITS) << 11;
750 color |= (int) (g * CONST_8_TO_6_BITS) << 5;
751 color |= (int) (b * CONST_8_TO_5_BITS);
756 static void new_graph(char *buf, int w, int h, unsigned int first_colour,
757 unsigned int second_colour, double i, int scale, int append)
759 struct special_t *s = new_special(buf, GRAPH);
762 if (s->graph == NULL) {
763 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
764 // subtract 2 for the box
765 s->graph_width = s->width /* - 2 */;
767 s->graph_width = MAX_GRAPH_DEPTH - 2;
769 s->graph = malloc(s->graph_width * sizeof(double));
770 memset(s->graph, 0, s->graph_width * sizeof(double));
771 s->graph_scale = 100;
774 s->first_colour = adjust_colors(first_colour);
775 s->last_colour = adjust_colors(second_colour);
782 s->graph_width = s->width - 2; // subtract 2 for rectangle around
787 s->graph_scale = scale;
794 static char *scan_graph(const char *args, int *w, int *h,
795 unsigned int *first_colour, unsigned int *last_colour,
800 /* zero width means all space that is available */
806 /* graph's argument is either height or height,width */
808 if (sscanf(args, "%d,%d %x %x %u", h, w, first_colour, last_colour,
813 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) {
816 if (sscanf(args, "%63s %d,%d %x %x %u", buf, h, w, first_colour,
817 last_colour, scale) == 6) {
821 if (sscanf(args, "%63s %d,%d %x %x", buf, h, w, first_colour,
828 if (sscanf(args, "%x %x %u", first_colour, last_colour, scale) == 3) {
832 if (sscanf(args, "%x %x", first_colour, last_colour) == 2) {
835 if (sscanf(args, "%63s %x %x %u", buf, first_colour, last_colour,
840 if (sscanf(args, "%63s %x %x", buf, first_colour, last_colour) == 3) {
846 if (sscanf(args, "%d,%d %u", h, w, scale) == 3) {
850 if (sscanf(args, "%d,%d", h, w) == 2) {
853 if (sscanf(args, "%63s %d,%d %u", buf, h, w, scale) < 4) {
855 //TODO: check the return value and throw an error?
856 sscanf(args, "%63s %d,%d", buf, h, w);
862 if (buf[0] == '\0') {
869 static inline void new_hr(char *buf, int a)
871 new_special(buf, HORIZONTAL_LINE)->height = a;
874 static inline void new_stippled_hr(char *buf, int a, int b)
876 struct special_t *s = new_special(buf, STIPPLED_HR);
882 static inline void new_fg(char *buf, long c)
884 new_special(buf, FG)->arg = c;
887 static inline void new_bg(char *buf, long c)
889 new_special(buf, BG)->arg = c;
892 static inline void new_outline(char *buf, long c)
894 new_special(buf, OUTLINE)->arg = c;
897 static inline void new_offset(char *buf, long c)
899 new_special(buf, OFFSET)->arg = c;
902 static inline void new_voffset(char *buf, long c)
904 new_special(buf, VOFFSET)->arg = c;
907 static inline void new_alignr(char *buf, long c)
909 new_special(buf, ALIGNR)->arg = c;
912 static inline void new_alignc(char *buf, long c)
914 new_special(buf, ALIGNC)->arg = c;
917 static inline void new_goto(char *buf, long c)
919 new_special(buf, GOTO)->arg = c;
922 static inline void new_tab(char *buf, int a, int b)
924 struct special_t *s = new_special(buf, TAB);
930 /* quite boring functions */
932 static inline void for_each_line(char *b, void f(char *))
936 for (ps = b, pe = b; *pe; pe++) {
950 static void convert_escapes(char *buf)
952 char *p = buf, *s = buf;
959 } else if (*s == '\\') {
970 /* Prints anything normally printed with snprintf according to the current value
971 * of use_spacer. Actually slightly more flexible than snprintf, as you can
972 * safely specify the destination buffer as one of your inputs. */
973 static int spaced_print(char *buf, int size, const char *format, int width,
974 const char *func_name, ...) {
982 tempbuf = malloc(size * sizeof(char));
984 // Passes the varargs along to vsnprintf
985 va_start(argp, func_name);
986 vsnprintf(tempbuf, size, format, argp);
989 switch (use_spacer) {
991 len = snprintf(buf, size, "%s", tempbuf);
994 len = snprintf(buf, size, "%*s", width - 1, tempbuf);
997 len = snprintf(buf, size, "%-*s", width - 1, tempbuf);
1000 CRIT_ERR("%s encountered invalid use_spacer value (%d)", func_name,
1009 /* converts from bytes to human readable format (k, M, G, T) */
1010 static void human_readable(long long num, char *buf, int size, const char *func_name)
1012 const char **suffix = suffixes;
1015 static const int WIDTH = 10, SHORT_WIDTH = 8;
1019 spaced_print(buf, size, "%lld%c", SHORT_WIDTH, func_name, num,
1022 spaced_print(buf, size, "%lld%s", WIDTH, func_name, num, *suffix);
1027 while (num / 1024 >= 1000LL && **(suffix + 2)) {
1033 fnum = num / 1024.0;
1038 if (precision < 0) {
1042 len = spaced_print(buf, size, "%.*f%c", SHORT_WIDTH, func_name,
1043 precision, fnum, **suffix);
1045 len = spaced_print(buf, size, "%.*f%s", WIDTH, func_name, precision,
1048 } while (len >= (short_units ? SHORT_WIDTH : WIDTH) || len >= size);
1053 enum text_object_type {
1055 #if defined(__linux__)
1057 #endif /* __linux__ */
1067 OBJ_battery_percent,
1069 #endif /* !__OpenBSD__ */
1084 OBJ_conky_build_date,
1085 OBJ_conky_build_arch,
1094 OBJ_diskiograph_read,
1095 OBJ_diskiograph_write,
1133 #if defined(__linux__)
1140 OBJ_i8k_left_fan_status,
1141 OBJ_i8k_right_fan_status,
1142 OBJ_i8k_left_fan_rpm,
1143 OBJ_i8k_right_fan_rpm,
1145 OBJ_i8k_buttons_status,
1161 OBJ_wireless_bitrate,
1163 OBJ_wireless_link_qual,
1164 OBJ_wireless_link_qual_max,
1165 OBJ_wireless_link_qual_perc,
1166 OBJ_wireless_link_bar,
1167 #endif /* __linux__ */
1197 OBJ_running_processes,
1206 OBJ_temp1, /* i2c is used instead in these */
1230 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
1231 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1233 OBJ_apm_battery_time,
1234 OBJ_apm_battery_life,
1235 #endif /* __FreeBSD__ __OpenBSD__ */
1237 OBJ_obsd_sensors_temp,
1238 OBJ_obsd_sensors_fan,
1239 OBJ_obsd_sensors_volt,
1242 #endif /* __OpenBSD__ */
1264 OBJ_music_player_interval,
1284 OBJ_xmms2_timesplayed,
1287 OBJ_audacious_status,
1288 OBJ_audacious_title,
1289 OBJ_audacious_length,
1290 OBJ_audacious_length_seconds,
1291 OBJ_audacious_position,
1292 OBJ_audacious_position_seconds,
1293 OBJ_audacious_bitrate,
1294 OBJ_audacious_frequency,
1295 OBJ_audacious_channels,
1296 OBJ_audacious_filename,
1297 OBJ_audacious_playlist_length,
1298 OBJ_audacious_playlist_position,
1312 #ifdef TCP_PORT_MONITOR
1326 OBJ_if_smapi_bat_installed,
1329 OBJ_entropy_poolsize,
1333 struct text_object {
1335 char *s; /* some string */
1336 int i; /* some integer */
1337 long l; /* some other integer */
1338 unsigned int sensor;
1339 struct net_stat *net;
1341 struct diskio_stat *diskio;
1342 unsigned char loadavg[3];
1343 unsigned int cpu_index;
1344 struct mail_s *mail;
1352 char *tz; /* timezone variable */
1353 char *fmt; /* time display formatting */
1391 /* If not -1, a file descriptor to read from when
1392 * logfile is a FIFO. */
1409 timed_thread *p_timed_thread;
1415 #ifdef TCP_PORT_MONITOR
1417 /* starting port to monitor */
1418 in_port_t port_range_begin;
1419 /* ending port to monitor */
1420 in_port_t port_range_end;
1421 /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1423 /* 0 to n-1 connections. */
1424 int connection_index;
1442 struct local_mail_s local_mail;
1447 unsigned int c, d, e;
1452 struct text_object_list {
1453 unsigned int text_object_count;
1454 struct text_object *text_objects;
1457 static unsigned int global_text_object_count;
1458 static struct text_object *global_text_objects;
1459 static void generate_text_internal(char *p, int p_max_size,
1460 struct text_object *objs, unsigned int object_count,
1461 struct information *cur);
1463 #define MAXDATASIZE 1000
1467 struct mail_s *parse_mail_args(char type, const char *arg)
1469 struct mail_s *mail;
1472 mail = malloc(sizeof(struct mail_s));
1473 memset(mail, 0, sizeof(struct mail_s));
1475 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass)
1478 ERR("Scanning IMAP args failed");
1479 } else if (type == IMAP) {
1480 ERR("Scanning POP3 args failed");
1483 // see if password needs prompting
1484 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1485 int fp = fileno(stdin);
1486 struct termios term;
1488 tcgetattr(fp, &term);
1489 term.c_lflag &= ~ECHO;
1490 tcsetattr(fp, TCSANOW, &term);
1491 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1492 scanf("%128s", mail->pass);
1494 term.c_lflag |= ECHO;
1495 tcsetattr(fp, TCSANOW, &term);
1497 // now we check for optional args
1498 tmp = strstr(arg, "-i ");
1501 sscanf(tmp, "%f", &mail->interval);
1503 mail->interval = 300; // 5 minutes
1505 tmp = strstr(arg, "-p ");
1508 sscanf(tmp, "%lu", &mail->port);
1511 mail->port = 110; // default pop3 port
1512 } else if (type == IMAP) {
1513 mail->port = 143; // default imap port
1517 tmp = strstr(arg, "-f ");
1520 sscanf(tmp, "%s", mail->folder);
1522 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1525 tmp = strstr(arg, "-e ");
1530 if (tmp[0] == '\'') {
1531 len = strstr(tmp + 1, "'") - tmp - 1;
1536 strncpy(mail->command, tmp + 1, len);
1538 mail->command[0] = '\0';
1540 mail->p_timed_thread = NULL;
1544 void *imap_thread(void *arg)
1546 int sockfd, numbytes;
1547 char recvbuf[MAXDATASIZE];
1548 char sendbuf[MAXDATASIZE];
1551 unsigned int old_unseen = UINT_MAX;
1552 unsigned int old_messages = UINT_MAX;
1553 struct stat stat_buf;
1555 struct sockaddr_in their_addr; // connector's address information
1556 struct mail_s *mail = (struct mail_s *)arg;
1558 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1559 herror("gethostbyname");
1563 struct timeval timeout;
1568 ERR("Trying IMAP connection again for %s@%s (try %i/5)",
1569 mail->user, mail->host, fail + 1);
1571 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1574 goto next_iteration;
1578 their_addr.sin_family = AF_INET;
1579 // short, network byte order
1580 their_addr.sin_port = htons(mail->port);
1581 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1582 // zero the rest of the struct
1583 memset(&(their_addr.sin_zero), '\0', 8);
1585 if (connect(sockfd, (struct sockaddr *) &their_addr,
1586 sizeof(struct sockaddr)) == -1) {
1589 goto next_iteration;
1592 timeout.tv_sec = 60; // 60 second timeout i guess
1593 timeout.tv_usec = 0;
1595 FD_SET(sockfd, &fdset);
1596 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1598 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1601 goto next_iteration;
1604 ERR("IMAP connection failed: timeout");
1606 goto next_iteration;
1608 recvbuf[numbytes] = '\0';
1609 if (strstr(recvbuf, "* OK") != recvbuf) {
1610 ERR("IMAP connection failed, probably not an IMAP server");
1612 goto next_iteration;
1614 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1615 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1616 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1617 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1618 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1619 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1622 goto next_iteration;
1624 timeout.tv_sec = 60; // 60 second timeout i guess
1625 timeout.tv_usec = 0;
1627 FD_SET(sockfd, &fdset);
1628 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1630 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1633 goto next_iteration;
1636 recvbuf[numbytes] = '\0';
1637 if (strstr(recvbuf, "a1 OK") == NULL) {
1638 ERR("IMAP server login failed: %s", recvbuf);
1640 goto next_iteration;
1642 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1643 strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1);
1644 strncat(sendbuf, " (MESSAGES UNSEEN)\r\n",
1645 MAXDATASIZE - strlen(sendbuf) - 1);
1646 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1649 goto next_iteration;
1651 timeout.tv_sec = 60; // 60 second timeout i guess
1652 timeout.tv_usec = 0;
1654 FD_SET(sockfd, &fdset);
1655 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1657 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1660 goto next_iteration;
1663 recvbuf[numbytes] = '\0';
1664 if (strstr(recvbuf, "a2 OK") == NULL) {
1665 ERR("IMAP status failed: %s", recvbuf);
1667 goto next_iteration;
1669 // now we get the data
1670 reply = strstr(recvbuf, " (MESSAGES ");
1672 *strchr(reply, ')') = '\0';
1673 if (reply == NULL) {
1674 ERR("Error parsing IMAP response: %s", recvbuf);
1676 goto next_iteration;
1678 timed_thread_lock(mail->p_timed_thread);
1679 sscanf(reply, "MESSAGES %lu UNSEEN %lu", &mail->messages,
1681 timed_thread_unlock(mail->p_timed_thread);
1683 strncpy(sendbuf, "a3 logout\r\n", MAXDATASIZE);
1684 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1687 goto next_iteration;
1689 timeout.tv_sec = 60; // 60 second timeout i guess
1690 timeout.tv_usec = 0;
1692 FD_SET(sockfd, &fdset);
1693 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1695 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1698 goto next_iteration;
1701 recvbuf[numbytes] = '\0';
1702 if (strstr(recvbuf, "a3 OK") == NULL) {
1703 ERR("IMAP logout failed: %s", recvbuf);
1705 goto next_iteration;
1707 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen
1708 || (mail->messages > old_messages && mail->unseen > 0))) {
1710 if (system(mail->command) == -1) {
1715 old_unseen = mail->unseen;
1716 old_messages = mail->messages;
1718 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1719 /* if a valid socket, close it */
1722 if (timed_thread_test(mail->p_timed_thread)) {
1723 timed_thread_exit(mail->p_timed_thread);
1731 void *pop3_thread(void *arg)
1733 int sockfd, numbytes;
1734 char recvbuf[MAXDATASIZE];
1735 char sendbuf[MAXDATASIZE];
1738 unsigned int old_unseen = UINT_MAX;
1739 struct stat stat_buf;
1741 struct sockaddr_in their_addr; // connector's address information
1742 struct mail_s *mail = (struct mail_s *)arg;
1744 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1745 herror("gethostbyname");
1749 struct timeval timeout;
1754 ERR("Trying POP3 connection again for %s@%s (try %i/5)",
1755 mail->user, mail->host, fail + 1);
1757 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1760 goto next_iteration;
1764 their_addr.sin_family = AF_INET;
1765 // short, network byte order
1766 their_addr.sin_port = htons(mail->port);
1767 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1768 // zero the rest of the struct
1769 memset(&(their_addr.sin_zero), '\0', 8);
1771 if (connect(sockfd, (struct sockaddr *) &their_addr,
1772 sizeof(struct sockaddr)) == -1) {
1775 goto next_iteration;
1778 timeout.tv_sec = 60; // 60 second timeout i guess
1779 timeout.tv_usec = 0;
1781 FD_SET(sockfd, &fdset);
1782 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1784 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1787 goto next_iteration;
1790 ERR("POP3 connection failed: timeout\n");
1792 goto next_iteration;
1794 recvbuf[numbytes] = '\0';
1795 if (strstr(recvbuf, "+OK ") != recvbuf) {
1796 ERR("POP3 connection failed, probably not a POP3 server");
1798 goto next_iteration;
1800 strncpy(sendbuf, "USER ", MAXDATASIZE);
1801 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1802 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1803 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1804 perror("send USER");
1806 goto next_iteration;
1808 timeout.tv_sec = 60; // 60 second timeout i guess
1809 timeout.tv_usec = 0;
1811 FD_SET(sockfd, &fdset);
1812 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1814 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1815 perror("recv USER");
1817 goto next_iteration;
1820 recvbuf[numbytes] = '\0';
1821 if (strstr(recvbuf, "+OK ") == NULL) {
1822 ERR("POP3 server login failed: %s", recvbuf);
1824 goto next_iteration;
1826 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1827 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1828 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1829 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1830 perror("send PASS");
1832 goto next_iteration;
1834 timeout.tv_sec = 60; // 60 second timeout i guess
1835 timeout.tv_usec = 0;
1837 FD_SET(sockfd, &fdset);
1838 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1840 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1841 perror("recv PASS");
1843 goto next_iteration;
1846 recvbuf[numbytes] = '\0';
1847 if (strstr(recvbuf, "+OK ") == NULL) {
1848 ERR("POP3 server login failed: %s", recvbuf);
1850 goto next_iteration;
1852 strncpy(sendbuf, "STAT\r\n", MAXDATASIZE);
1853 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1854 perror("send STAT");
1856 goto next_iteration;
1858 timeout.tv_sec = 60; // 60 second timeout i guess
1859 timeout.tv_usec = 0;
1861 FD_SET(sockfd, &fdset);
1862 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1864 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1865 perror("recv STAT");
1867 goto next_iteration;
1870 recvbuf[numbytes] = '\0';
1871 if (strstr(recvbuf, "+OK ") == NULL) {
1872 ERR("POP3 status failed: %s", recvbuf);
1874 goto next_iteration;
1876 // now we get the data
1877 reply = recvbuf + 4;
1878 if (reply == NULL) {
1879 ERR("Error parsing POP3 response: %s", recvbuf);
1881 goto next_iteration;
1883 timed_thread_lock(mail->p_timed_thread);
1884 sscanf(reply, "%lu %lu", &mail->unseen, &mail->used);
1885 timed_thread_unlock(mail->p_timed_thread);
1887 strncpy(sendbuf, "QUIT\r\n", MAXDATASIZE);
1888 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1889 perror("send QUIT");
1891 goto next_iteration;
1893 timeout.tv_sec = 60; // 60 second timeout i guess
1894 timeout.tv_usec = 0;
1896 FD_SET(sockfd, &fdset);
1897 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1899 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1900 perror("recv QUIT");
1902 goto next_iteration;
1905 recvbuf[numbytes] = '\0';
1906 if (strstr(recvbuf, "+OK") == NULL) {
1907 ERR("POP3 logout failed: %s", recvbuf);
1909 goto next_iteration;
1911 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) {
1913 if (system(mail->command) == -1) {
1918 old_unseen = mail->unseen;
1920 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1921 /* if a valid socket, close it */
1924 if (timed_thread_test(mail->p_timed_thread)) {
1925 timed_thread_exit(mail->p_timed_thread);
1933 void *threaded_exec(void *arg)
1938 struct text_object *obj = (struct text_object *)arg;
1940 p2 = obj->data.texeci.buffer;
1941 fp = popen(obj->data.texeci.cmd, "r");
1943 timed_thread_lock(obj->data.texeci.p_timed_thread);
1944 n2 = fread(p2, 1, text_buffer_size, fp);
1948 if (n2 && p2[n2 - 1] == '\n') {
1952 if (*p2 == '\001') {
1957 timed_thread_unlock(obj->data.texeci.p_timed_thread);
1958 if (timed_thread_test(obj->data.texeci.p_timed_thread)) {
1959 timed_thread_exit(obj->data.texeci.p_timed_thread);
1965 static struct text_object *new_text_object_internal(void)
1967 struct text_object *obj = malloc(sizeof(struct text_object));
1968 memset(obj, 0, sizeof(struct text_object));
1972 static void free_text_objects(unsigned int count, struct text_object *objs)
1976 for (i = 0; i < count; i++) {
1977 switch (objs[i].type) {
1981 close(objs[i].data.i);
1986 close(objs[i].data.sysfs.fd);
1988 #endif /* !__OpenBSD__ */
1991 free(objs[i].data.s);
1994 free(objs[i].data.tztime.tz);
1995 free(objs[i].data.tztime.fmt);
1998 free(objs[i].data.mboxscan.args);
1999 free(objs[i].data.mboxscan.output);
2003 free(objs[i].data.local_mail.box);
2008 case OBJ_imap_unseen:
2009 if (!objs[i].global_mode) {
2010 free(objs[i].data.mail);
2013 case OBJ_imap_messages:
2014 if (!objs[i].global_mode) {
2015 free(objs[i].data.mail);
2021 case OBJ_pop3_unseen:
2022 if (!objs[i].global_mode) {
2023 free(objs[i].data.mail);
2027 if (!objs[i].global_mode) {
2028 free(objs[i].data.mail);
2032 case OBJ_if_existing:
2033 case OBJ_if_mounted:
2034 case OBJ_if_running:
2035 free(objs[i].data.ifblock.s);
2036 free(objs[i].data.ifblock.str);
2039 free(objs[i].data.tail.logfile);
2040 free(objs[i].data.tail.buffer);
2049 free(objs[i].data.s);
2052 case OBJ_iconv_start:
2057 case OBJ_disk_protect:
2058 free(objs[i].data.s);
2061 free(objs[i].data.ifblock.s);
2062 free(objs[i].data.ifblock.str);
2065 free(objs[i].data.ifblock.s);
2066 free(objs[i].data.ifblock.str);
2069 if (info.gw_info.iface) {
2070 free(info.gw_info.iface);
2071 info.gw_info.iface = 0;
2073 if (info.gw_info.ip) {
2074 free(info.gw_info.ip);
2075 info.gw_info.ip = 0;
2078 case OBJ_ioscheduler:
2080 free(objs[i].data.s);
2084 case OBJ_xmms2_artist:
2085 if (info.xmms2.artist) {
2086 free(info.xmms2.artist);
2087 info.xmms2.artist = 0;
2090 case OBJ_xmms2_album:
2091 if (info.xmms2.album) {
2092 free(info.xmms2.album);
2093 info.xmms2.album = 0;
2096 case OBJ_xmms2_title:
2097 if (info.xmms2.title) {
2098 free(info.xmms2.title);
2099 info.xmms2.title = 0;
2102 case OBJ_xmms2_genre:
2103 if (info.xmms2.genre) {
2104 free(info.xmms2.genre);
2105 info.xmms2.genre = 0;
2108 case OBJ_xmms2_comment:
2109 if (info.xmms2.comment) {
2110 free(info.xmms2.comment);
2111 info.xmms2.comment = 0;
2115 if (info.xmms2.url) {
2116 free(info.xmms2.url);
2120 case OBJ_xmms2_date:
2121 if (info.xmms2.date) {
2122 free(info.xmms2.date);
2123 info.xmms2.date = 0;
2126 case OBJ_xmms2_status:
2127 if (info.xmms2.status) {
2128 free(info.xmms2.status);
2129 info.xmms2.status = 0;
2132 case OBJ_xmms2_playlist:
2133 if (info.xmms2.playlist) {
2134 free(info.xmms2.playlist);
2135 info.xmms2.playlist = 0;
2138 case OBJ_xmms2_smart:
2139 if (info.xmms2.artist) {
2140 free(info.xmms2.artist);
2141 info.xmms2.artist = 0;
2143 if (info.xmms2.title) {
2144 free(info.xmms2.title);
2145 info.xmms2.title = 0;
2147 if (info.xmms2.url) {
2148 free(info.xmms2.url);
2154 case OBJ_bmpx_title:
2155 case OBJ_bmpx_artist:
2156 case OBJ_bmpx_album:
2157 case OBJ_bmpx_track:
2159 case OBJ_bmpx_bitrate:
2164 free(objs[i].data.rss.uri);
2165 free(objs[i].data.rss.action);
2172 free(objs[i].data.s);
2174 case OBJ_battery_time:
2175 free(objs[i].data.s);
2177 #endif /* !__OpenBSD__ */
2181 case OBJ_execigraph:
2182 free(objs[i].data.execi.cmd);
2183 free(objs[i].data.execi.buffer);
2186 free(objs[i].data.texeci.cmd);
2187 free(objs[i].data.texeci.buffer);
2189 case OBJ_nameserver:
2194 if (info.first_process) {
2195 free_all_processes();
2196 info.first_process = NULL;
2201 free(objs[i].data.hddtemp.dev);
2202 free(objs[i].data.hddtemp.addr);
2205 case OBJ_entropy_avail:
2206 case OBJ_entropy_poolsize:
2207 case OBJ_entropy_bar:
2209 case OBJ_user_names:
2210 if (info.users.names) {
2211 free(info.users.names);
2212 info.users.names = 0;
2215 case OBJ_user_terms:
2216 if (info.users.terms) {
2217 free(info.users.terms);
2218 info.users.terms = 0;
2221 case OBJ_user_times:
2222 if (info.users.times) {
2223 free(info.users.times);
2224 info.users.times = 0;
2229 case OBJ_smapi_bat_perc:
2230 free(objs[i].data.s);
2232 case OBJ_if_smapi_bat_installed:
2233 free(objs[i].data.ifblock.s);
2234 free(objs[i].data.ifblock.str);
2239 case OBJ_mpd_artist:
2241 case OBJ_mpd_random:
2242 case OBJ_mpd_repeat:
2244 case OBJ_mpd_bitrate:
2245 case OBJ_mpd_status:
2248 case OBJ_mpd_password:
2250 case OBJ_mpd_elapsed:
2251 case OBJ_mpd_length:
2255 case OBJ_mpd_percent:
2257 free_mpd_vars(&info);
2263 /* text_objects = NULL;
2264 text_object_count = 0; */
2267 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2272 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2273 *a = mixer_init(buf1);
2274 scan_bar(arg + n, w, h);
2276 *a = mixer_init(NULL);
2277 scan_bar(arg, w, h);
2281 /* construct_text_object() creates a new text_object */
2282 static struct text_object *construct_text_object(const char *s,
2283 const char *arg, unsigned int object_count,
2284 struct text_object *text_objects, long line)
2286 // struct text_object *obj = new_text_object();
2287 struct text_object *obj = new_text_object_internal();
2291 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
2292 obj->type = OBJ_##a; need_mask |= (1 << n); {
2293 #define END } } else
2297 obj->type = OBJ_color;
2298 obj->data.l = get_x11_color(s);
2302 OBJ(freq, INFO_FREQ)
2305 obj->data.i = open_acpi_temperature(arg);
2306 END OBJ(acpitempf, 0)
2307 obj->data.i = open_acpi_temperature(arg);
2308 END OBJ(acpiacadapter, 0)
2309 END OBJ(freq, INFO_FREQ)
2310 #endif /* !__OpenBSD__ */
2312 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2313 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2314 obj->data.cpu_index = 1;
2315 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
2316 "Displaying the clock for CPU 1."); */
2318 obj->data.cpu_index = atoi(&arg[0]);
2321 END OBJ(freq_g, INFO_FREQ)
2323 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2324 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2325 obj->data.cpu_index = 1;
2326 /* ERR("freq_g: Invalid CPU number or you don't have that many "
2327 "CPUs! Displaying the clock for CPU 1."); */
2329 obj->data.cpu_index = atoi(&arg[0]);
2332 #if defined(__linux__)
2333 END OBJ(voltage_mv, 0)
2335 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2336 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2337 obj->data.cpu_index = 1;
2338 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
2339 "CPUs! Displaying voltage for CPU 1."); */
2341 obj->data.cpu_index = atoi(&arg[0]);
2344 END OBJ(voltage_v, 0)
2346 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2347 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2348 obj->data.cpu_index = 1;
2349 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
2350 "CPUs! Displaying voltage for CPU 1."); */
2352 obj->data.cpu_index = atoi(&arg[0]);
2357 END OBJ(wireless_essid, INFO_NET)
2359 obj->data.net = get_net_stat(arg);
2361 CRIT_ERR("wireless_essid: needs an argument");
2363 END OBJ(wireless_mode, INFO_NET)
2365 obj->data.net = get_net_stat(arg);
2367 CRIT_ERR("wireless_mode: needs an argument");
2369 END OBJ(wireless_bitrate, INFO_NET)
2371 obj->data.net = get_net_stat(arg);
2373 CRIT_ERR("wireless_bitrate: needs an argument");
2375 END OBJ(wireless_ap, INFO_NET)
2377 obj->data.net = get_net_stat(arg);
2379 CRIT_ERR("wireless_ap: needs an argument");
2381 END OBJ(wireless_link_qual, INFO_NET)
2383 obj->data.net = get_net_stat(arg);
2385 CRIT_ERR("wireless_link_qual: needs an argument");
2387 END OBJ(wireless_link_qual_max, INFO_NET)
2389 obj->data.net = get_net_stat(arg);
2391 CRIT_ERR("wireless_link_qual_max: needs an argument");
2393 END OBJ(wireless_link_qual_perc, INFO_NET)
2395 obj->data.net = get_net_stat(arg);
2397 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2399 END OBJ(wireless_link_bar, INFO_NET)
2401 arg = scan_bar(arg, &obj->a, &obj->b);
2402 obj->data.net = get_net_stat(arg);
2404 CRIT_ERR("wireless_link_bar: needs an argument");
2406 #endif /* HAVE_IWLIB */
2408 #endif /* __linux__ */
2409 END OBJ(freq_dyn, 0)
2410 END OBJ(freq_dyn_g, 0)
2418 sscanf(arg, "%63s", bat);
2420 strcpy(bat, "BAT0");
2422 obj->data.s = strdup(bat);
2423 END OBJ(battery_time, 0)
2427 sscanf(arg, "%63s", bat);
2429 strcpy(bat, "BAT0");
2431 obj->data.s = strdup(bat);
2432 END OBJ(battery_percent, 0)
2436 sscanf(arg, "%63s", bat);
2438 strcpy(bat, "BAT0");
2440 obj->data.s = strdup(bat);
2441 END OBJ(battery_bar, 0)
2445 arg = scan_bar(arg, &obj->a, &obj->b);
2446 sscanf(arg, "%63s", bat);
2448 strcpy(bat, "BAT0");
2450 obj->data.s = strdup(bat);
2451 #endif /* !__OpenBSD__ */
2453 #if defined(__linux__)
2454 END OBJ(disk_protect, 0)
2456 obj->data.s = strdup(arg);
2458 CRIT_ERR("disk_protect needs an argument");
2459 END OBJ(i8k_version, INFO_I8K)
2460 END OBJ(i8k_bios, INFO_I8K)
2461 END OBJ(i8k_serial, INFO_I8K)
2462 END OBJ(i8k_cpu_temp, INFO_I8K)
2463 END OBJ(i8k_cpu_tempf, INFO_I8K)
2464 END OBJ(i8k_left_fan_status, INFO_I8K)
2465 END OBJ(i8k_right_fan_status, INFO_I8K)
2466 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2467 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2468 END OBJ(i8k_ac_status, INFO_I8K)
2469 END OBJ(i8k_buttons_status, INFO_I8K)
2471 END OBJ(ibm_temps, 0)
2473 CRIT_ERR("ibm_temps: needs an argument");
2475 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
2476 obj->data.sensor = 0;
2477 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
2478 "Using 0 (CPU temp sensor).");
2480 obj->data.sensor = atoi(&arg[0]);
2481 END OBJ(ibm_volume, 0)
2482 END OBJ(ibm_brightness, 0)
2484 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2485 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2488 ERR("if_up needs an argument");
2489 obj->data.ifblock.s = 0;
2491 obj->data.ifblock.s = strdup(arg);
2492 blockstart[blockdepth] = object_count;
2493 obj->data.ifblock.pos = object_count + 2;
2496 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2497 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2499 blockstart[blockdepth] = object_count;
2500 obj->data.ifblock.pos = object_count + 2;
2502 END OBJ(ioscheduler, 0)
2504 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
2507 obj->data.s = strdup(arg);
2508 END OBJ(laptop_mode, 0)
2509 END OBJ(pb_battery, 0)
2510 if (arg && strcmp(arg, "status") == 0) {
2511 obj->data.i = PB_BATT_STATUS;
2512 } else if (arg && strcmp(arg, "percent") == 0) {
2513 obj->data.i = PB_BATT_PERCENT;
2514 } else if (arg && strcmp(arg, "time") == 0) {
2515 obj->data.i = PB_BATT_TIME;
2517 ERR("pb_battery: needs one argument: status, percent or time");
2522 #endif /* __linux__ */
2523 #if defined(__OpenBSD__)
2524 END OBJ(obsd_sensors_temp, 0)
2526 CRIT_ERR("obsd_sensors_temp: needs an argument");
2528 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2529 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2530 obj->data.sensor = 0;
2531 ERR("Invalid temperature sensor number!");
2533 obj->data.sensor = atoi(&arg[0]);
2534 END OBJ(obsd_sensors_fan, 0)
2536 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
2539 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2540 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2541 obj->data.sensor = 0;
2542 ERR("Invalid fan sensor number!");
2544 obj->data.sensor = atoi(&arg[0]);
2545 END OBJ(obsd_sensors_volt, 0)
2547 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
2550 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2551 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2552 obj->data.sensor = 0;
2553 ERR("Invalid voltage sensor number!");
2555 obj->data.sensor = atoi(&arg[0]);
2556 END OBJ(obsd_vendor, 0)
2557 END OBJ(obsd_product, 0)
2558 #endif /* __OpenBSD__ */
2559 END OBJ(buffers, INFO_BUFFERS)
2560 END OBJ(cached, INFO_BUFFERS)
2561 END OBJ(cpu, INFO_CPU)
2563 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2564 obj->data.cpu_index = atoi(&arg[3]);
2567 obj->data.cpu_index = 0;
2570 obj->data.cpu_index = 0;
2572 END OBJ(cpubar, INFO_CPU)
2574 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2575 obj->data.cpu_index = atoi(&arg[3]);
2578 obj->data.cpu_index = 0;
2580 scan_bar(arg, &obj->a, &obj->b);
2582 scan_bar(arg, &obj->a, &obj->b);
2583 obj->data.cpu_index = 0;
2585 END OBJ(cpugraph, INFO_CPU)
2586 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2590 if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
2591 obj->data.cpu_index = atoi(&buf[3]);
2593 obj->data.cpu_index = 0;
2597 END OBJ(diskio, INFO_DISKIO)
2599 obj->data.diskio = prepare_diskio_stat(arg);
2601 obj->data.diskio = NULL;
2603 END OBJ(diskio_read, INFO_DISKIO)
2605 obj->data.diskio = prepare_diskio_stat(arg);
2607 obj->data.diskio = NULL;
2609 END OBJ(diskio_write, INFO_DISKIO)
2611 obj->data.diskio = prepare_diskio_stat(arg);
2613 obj->data.diskio = NULL;
2615 END OBJ(diskiograph, INFO_DISKIO)
2616 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2620 obj->data.diskio = prepare_diskio_stat(buf);
2623 obj->data.diskio = NULL;
2625 END OBJ(diskiograph_read, INFO_DISKIO)
2626 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2630 obj->data.diskio = prepare_diskio_stat(buf);
2633 obj->data.diskio = NULL;
2635 END OBJ(diskiograph_write, INFO_DISKIO)
2636 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2640 obj->data.diskio = prepare_diskio_stat(buf);
2643 obj->data.diskio = NULL;
2647 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2650 obj->data.l = color0;
2652 obj->data.l = color1;
2654 obj->data.l = color2;
2656 obj->data.l = color3;
2658 obj->data.l = color4;
2660 obj->data.l = color5;
2662 obj->data.l = color6;
2664 obj->data.l = color7;
2666 obj->data.l = color8;
2668 obj->data.l = color9;
2670 obj->data.s = scan_font(arg);
2671 END OBJ(conky_version, 0)
2672 END OBJ(conky_build_date, 0)
2673 END OBJ(conky_build_arch, 0)
2674 END OBJ(downspeed, INFO_NET)
2676 obj->data.net = get_net_stat(arg);
2678 CRIT_ERR("downspeed needs argument");
2680 END OBJ(downspeedf, INFO_NET)
2682 obj->data.net = get_net_stat(arg);
2684 CRIT_ERR("downspeedf needs argument");
2686 END OBJ(downspeedgraph, INFO_NET)
2687 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2691 obj->data.net = get_net_stat(buf);
2696 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos =
2698 blockstart[blockdepth - 1] = object_count;
2699 obj->data.ifblock.pos = object_count + 2;
2701 ERR("$else: no matching $if_*");
2706 text_objects[blockstart[blockdepth]].data.ifblock.pos =
2709 ERR("$endif: no matching $if_*");
2712 obj->data.s = strdup(arg ? arg : "");
2715 obj->data.s = strdup(arg ? arg : "");
2717 obj->data.s = strdup(arg ? arg : "");
2719 obj->data.s = strdup(arg ? arg : "");
2720 END OBJ(execgraph, 0)
2721 obj->data.s = strdup(arg ? arg : "");
2722 END OBJ(execibar, 0)
2725 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2728 ERR("${execibar <interval> command}");
2729 obj->type = OBJ_text;
2730 snprintf(buf, 256, "${%s}", s);
2731 obj->data.s = strdup(buf);
2733 obj->data.execi.cmd = strdup(arg + n);
2735 END OBJ(execigraph, 0)
2738 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2741 ERR("${execigraph <interval> command}");
2742 obj->type = OBJ_text;
2743 snprintf(buf, 256, "${%s}", s);
2744 obj->data.s = strdup(buf);
2746 obj->data.execi.cmd = strdup(arg + n);
2751 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2754 ERR("${execi <interval> command}");
2755 obj->type = OBJ_text;
2756 snprintf(buf, 256, "${%s}", s);
2757 obj->data.s = strdup(buf);
2759 obj->data.execi.cmd = strdup(arg + n);
2760 obj->data.execi.buffer = malloc(text_buffer_size);
2765 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2768 ERR("${execi <interval> command}");
2769 obj->type = OBJ_text;
2770 snprintf(buf, 256, "${%s}", s);
2771 obj->data.s = strdup(buf);
2773 obj->data.execi.cmd = strdup(arg + n);
2774 obj->data.execi.buffer = malloc(text_buffer_size);
2779 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2782 ERR("${texeci <interval> command}");
2783 obj->type = OBJ_text;
2784 snprintf(buf, 256, "${%s}", s);
2785 obj->data.s = strdup(buf);
2787 obj->data.texeci.cmd = strdup(arg + n);
2788 obj->data.texeci.buffer = malloc(text_buffer_size);
2790 obj->data.texeci.p_timed_thread = NULL;
2791 END OBJ(pre_exec, 0)
2792 obj->type = OBJ_text;
2794 FILE *fp = popen(arg, "r");
2798 n = fread(buf, 1, 2048, fp);
2801 if (n && buf[n - 1] == '\n') {
2807 obj->data.s = strdup(buf);
2809 obj->data.s = strdup("");
2812 END OBJ(fs_bar, INFO_FS)
2813 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2815 while (isspace(*arg)) {
2824 obj->data.fsbar.fs = prepare_fs_stat(arg);
2825 END OBJ(fs_bar_free, INFO_FS)
2826 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2828 while (isspace(*arg)) {
2838 obj->data.fsbar.fs = prepare_fs_stat(arg);
2839 END OBJ(fs_free, INFO_FS)
2843 obj->data.fs = prepare_fs_stat(arg);
2844 END OBJ(fs_used_perc, INFO_FS)
2848 obj->data.fs = prepare_fs_stat(arg);
2849 END OBJ(fs_free_perc, INFO_FS)
2853 obj->data.fs = prepare_fs_stat(arg);
2854 END OBJ(fs_size, INFO_FS)
2858 obj->data.fs = prepare_fs_stat(arg);
2859 END OBJ(fs_type, INFO_FS)
2863 obj->data.fs = prepare_fs_stat(arg);
2864 END OBJ(fs_used, INFO_FS)
2868 obj->data.fs = prepare_fs_stat(arg);
2870 obj->data.i = arg ? atoi(arg) : 1;
2871 END OBJ(nameserver, INFO_DNS)
2872 obj->data.i = arg ? atoi(arg) : 0;
2874 obj->data.i = arg ? atoi(arg) : 1;
2876 obj->data.i = arg ? atoi(arg) : 1;
2880 ERR("goto needs arguments");
2881 obj->type = OBJ_text;
2882 obj->data.s = strdup("${goto}");
2886 obj->data.i = atoi(arg);
2892 if (sscanf(arg, "%d %d", &a, &b) != 2) {
2893 sscanf(arg, "%d", &b);
2899 obj->data.pair.a = a;
2900 obj->data.pair.b = b;
2903 END OBJ(i2c, INFO_SYSFS)
2904 char buf1[64], buf2[64];
2908 ERR("i2c needs arguments");
2909 obj->type = OBJ_text;
2910 // obj->data.s = strdup("${i2c}");
2914 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2915 /* if scanf couldn't read three values, read type and num and use
2917 sscanf(arg, "%63s %d", buf2, &n);
2918 obj->data.sysfs.fd = open_i2c_sensor(0, buf2, n,
2919 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2920 strncpy(obj->data.sysfs.type, buf2, 63);
2922 obj->data.sysfs.fd = open_i2c_sensor(buf1, buf2, n,
2923 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2924 strncpy(obj->data.sysfs.type, buf2, 63);
2927 END OBJ(platform, INFO_SYSFS)
2928 char buf1[64], buf2[64];
2932 ERR("platform needs arguments");
2933 obj->type = OBJ_text;
2937 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2938 /* if scanf couldn't read three values, read type and num and use
2940 sscanf(arg, "%63s %d", buf2, &n);
2941 obj->data.sysfs.fd = open_platform_sensor(0, buf2, n,
2942 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2943 strncpy(obj->data.sysfs.type, buf2, 63);
2945 obj->data.sysfs.fd = open_platform_sensor(buf1, buf2, n,
2946 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2947 strncpy(obj->data.sysfs.type, buf2, 63);
2950 END OBJ(hwmon, INFO_SYSFS)
2951 char buf1[64], buf2[64];
2955 ERR("hwmon needs argumanets");
2956 obj->type = OBJ_text;
2960 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2961 /* if scanf couldn't read three values, read type and num and use
2963 sscanf(arg, "%63s %d", buf2, &n);
2964 obj->data.sysfs.fd = open_hwmon_sensor(0, buf2, n,
2965 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2966 strncpy(obj->data.sysfs.type, buf2, 63);
2968 obj->data.sysfs.fd = open_hwmon_sensor(buf1, buf2, n,
2969 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2970 strncpy(obj->data.sysfs.type, buf2, 63);
2972 #endif /* !__OpenBSD__ */
2974 END OBJ(top, INFO_TOP)
2979 ERR("top needs arguments");
2980 obj->type = OBJ_text;
2981 // obj->data.s = strdup("${top}");
2984 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2985 if (strcmp(buf, "name") == 0) {
2986 obj->data.top.type = TOP_NAME;
2987 } else if (strcmp(buf, "cpu") == 0) {
2988 obj->data.top.type = TOP_CPU;
2989 } else if (strcmp(buf, "pid") == 0) {
2990 obj->data.top.type = TOP_PID;
2991 } else if (strcmp(buf, "mem") == 0) {
2992 obj->data.top.type = TOP_MEM;
2993 } else if (strcmp(buf, "time") == 0) {
2994 obj->data.top.type = TOP_TIME;
2996 ERR("invalid arg for top");
2999 if (n < 1 || n > 10) {
3000 CRIT_ERR("invalid arg for top");
3003 obj->data.top.num = n - 1;
3007 ERR("invalid args given for top");
3010 END OBJ(top_mem, INFO_TOP)
3015 ERR("top_mem needs arguments");
3016 obj->type = OBJ_text;
3017 obj->data.s = strdup("${top_mem}");
3020 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
3021 if (strcmp(buf, "name") == 0) {
3022 obj->data.top.type = TOP_NAME;
3023 } else if (strcmp(buf, "cpu") == 0) {
3024 obj->data.top.type = TOP_CPU;
3025 } else if (strcmp(buf, "pid") == 0) {
3026 obj->data.top.type = TOP_PID;
3027 } else if (strcmp(buf, "mem") == 0) {
3028 obj->data.top.type = TOP_MEM;
3029 } else if (strcmp(buf, "time") == 0) {
3030 obj->data.top.type = TOP_TIME;
3032 ERR("invalid arg for top");
3035 if (n < 1 || n > 10) {
3036 CRIT_ERR("invalid arg for top");
3039 obj->data.top.num = n - 1;
3043 ERR("invalid args given for top");
3046 END OBJ(addr, INFO_NET)
3048 obj->data.net = get_net_stat(arg);
3050 CRIT_ERR("addr needs argument");
3052 #if defined(__linux__)
3053 END OBJ(addrs, INFO_NET)
3055 obj->data.net = get_net_stat(arg);
3057 CRIT_ERR("addrs needs argument");
3059 #endif /* __linux__ */
3066 ERR("tail needs arguments");
3067 obj->type = OBJ_text;
3068 obj->data.s = strdup("${tail}");
3071 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3072 if (n1 < 1 || n1 > 30) {
3073 CRIT_ERR("invalid arg for tail, number of lines must be "
3074 "between 1 and 30");
3080 obj->data.tail.fd = -1;
3082 if (stat(buf, &st) == 0) {
3083 if (S_ISFIFO(st.st_mode)) {
3084 fd = open(buf, O_RDONLY | O_NONBLOCK);
3087 CRIT_ERR("tail logfile does not exist, or you do "
3088 "not have correct permissions");
3091 obj->data.tail.fd = fd;
3093 fp = fopen(buf, "r");
3097 if (fp || obj->data.tail.fd != -1) {
3098 obj->data.tail.logfile = malloc(text_buffer_size);
3099 strcpy(obj->data.tail.logfile, buf);
3100 obj->data.tail.wantedlines = n1;
3101 obj->data.tail.interval = update_interval * 2;
3103 if (obj->data.tail.fd == -1) {
3108 CRIT_ERR("tail logfile does not exist, or you do not have "
3109 "correct permissions");
3112 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3113 if (n1 < 1 || n1 > 30) {
3114 CRIT_ERR("invalid arg for tail, number of lines must be "
3115 "between 1 and 30");
3117 } else if (n2 < 1 || n2 < update_interval) {
3118 CRIT_ERR("invalid arg for tail, interval must be greater than "
3119 "0 and Conky's interval");
3125 obj->data.tail.fd = -1;
3127 if (stat(buf, &st) == 0) {
3128 if (S_ISFIFO(st.st_mode)) {
3129 fd = open(buf, O_RDONLY | O_NONBLOCK);
3132 CRIT_ERR("tail logfile does not exist, or you do "
3133 "not have correct permissions");
3136 obj->data.tail.fd = fd;
3138 fp = fopen(buf, "r");
3142 if (fp || obj->data.tail.fd != -1) {
3143 obj->data.tail.logfile = malloc(text_buffer_size);
3144 strcpy(obj->data.tail.logfile, buf);
3145 obj->data.tail.wantedlines = n1;
3146 obj->data.tail.interval = n2;
3148 if (obj->data.tail.fd == -1) {
3153 CRIT_ERR("tail logfile does not exist, or you do not have "
3154 "correct permissions");
3158 ERR("invalid args given for tail");
3161 /* asumming all else worked */
3162 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3168 ERR("head needs arguments");
3169 obj->type = OBJ_text;
3170 obj->data.s = strdup("${head}");
3173 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3174 if (n1 < 1 || n1 > 30) {
3175 CRIT_ERR("invalid arg for head, number of lines must be "
3176 "between 1 and 30");
3181 fp = fopen(buf, "r");
3183 obj->data.tail.logfile = malloc(text_buffer_size);
3184 strcpy(obj->data.tail.logfile, buf);
3185 obj->data.tail.wantedlines = n1;
3186 obj->data.tail.interval = update_interval * 2;
3190 CRIT_ERR("head logfile does not exist, or you do not have "
3191 "correct permissions");
3194 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3195 if (n1 < 1 || n1 > 30) {
3196 CRIT_ERR("invalid arg for head, number of lines must be "
3197 "between 1 and 30");
3199 } else if (n2 < 1 || n2 < update_interval) {
3200 CRIT_ERR("invalid arg for head, interval must be greater than "
3201 "0 and Conky's interval");
3206 fp = fopen(buf, "r");
3208 obj->data.tail.logfile = malloc(text_buffer_size);
3209 strcpy(obj->data.tail.logfile, buf);
3210 obj->data.tail.wantedlines = n1;
3211 obj->data.tail.interval = n2;
3215 CRIT_ERR("head logfile does not exist, or you do not have "
3216 "correct permissions");
3220 ERR("invalid args given for head");
3223 /* asumming all else worked */
3224 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3225 END OBJ(loadavg, INFO_LOADAVG)
3226 int a = 1, b = 2, c = 3, r = 3;
3229 r = sscanf(arg, "%d %d %d", &a, &b, &c);
3230 if (r >= 3 && (c < 1 || c > 3)) {
3233 if (r >= 2 && (b < 1 || b > 3)) {
3236 if (r >= 1 && (a < 1 || a > 3)) {
3240 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
3241 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
3242 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
3243 END OBJ(if_empty, 0)
3244 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3245 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3248 ERR("if_empty needs an argument");
3249 obj->data.ifblock.s = 0;
3251 obj->data.ifblock.s = strdup(arg);
3253 blockstart[blockdepth] = object_count;
3254 obj->data.ifblock.pos = object_count + 2;
3256 END OBJ(if_existing, 0)
3257 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3258 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3261 ERR("if_existing needs an argument or two");
3262 obj->data.ifblock.s = NULL;
3263 obj->data.ifblock.str = NULL;
3265 char buf1[256], buf2[256];
3266 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3269 obj->data.ifblock.s = strdup(buf1);
3270 obj->data.ifblock.str = NULL;
3272 obj->data.ifblock.s = strdup(buf1);
3273 obj->data.ifblock.str = strdup(buf2);
3276 blockstart[blockdepth] = object_count;
3277 obj->data.ifblock.pos = object_count + 2;
3279 END OBJ(if_mounted, 0)
3280 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3281 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3284 ERR("if_mounted needs an argument");
3285 obj->data.ifblock.s = 0;
3287 obj->data.ifblock.s = strdup(arg);
3289 blockstart[blockdepth] = object_count;
3290 obj->data.ifblock.pos = object_count + 2;
3292 END OBJ(if_running, 0)
3293 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3294 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3299 snprintf(buf, 256, "pidof %s >/dev/null", arg);
3300 obj->data.ifblock.s = strdup(buf);
3302 ERR("if_running needs an argument");
3303 obj->data.ifblock.s = 0;
3305 blockstart[blockdepth] = object_count;
3306 obj->data.ifblock.pos = object_count + 2;
3312 char box[256], dst[256];
3316 strncpy(box, MAIL_FILE, sizeof(box));
3318 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3320 strncpy(box, arg, sizeof(box));
3324 variable_substitute(box, dst, sizeof(dst));
3325 obj->data.local_mail.box = strdup(dst);
3326 obj->data.local_mail.interval = n1;
3327 END OBJ(mboxscan, 0)
3328 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
3329 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
3330 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
3331 obj->data.mboxscan.output[0] = 1;
3332 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
3333 END OBJ(mem, INFO_MEM)
3334 END OBJ(memmax, INFO_MEM)
3335 END OBJ(memperc, INFO_MEM)
3336 END OBJ(membar, INFO_MEM)
3337 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3338 END OBJ(memgraph, INFO_MEM)
3339 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3345 END OBJ(mixer, INFO_MIXER)
3346 obj->data.l = mixer_init(arg);
3347 END OBJ(mixerl, INFO_MIXER)
3348 obj->data.l = mixer_init(arg);
3349 END OBJ(mixerr, INFO_MIXER)
3350 obj->data.l = mixer_init(arg);
3351 END OBJ(mixerbar, INFO_MIXER)
3352 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3353 &obj->data.mixerbar.h);
3354 END OBJ(mixerlbar, INFO_MIXER)
3355 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3356 &obj->data.mixerbar.h);
3357 END OBJ(mixerrbar, INFO_MIXER)
3358 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3359 &obj->data.mixerbar.h);
3360 END OBJ(new_mails, 0)
3362 char box[256], dst[256];
3366 strncpy(box, MAIL_FILE, sizeof(box));
3368 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3370 strncpy(box, arg, sizeof(box));
3374 variable_substitute(box, dst, sizeof(dst));
3375 obj->data.local_mail.box = strdup(dst);
3376 obj->data.local_mail.interval = n1;
3377 END OBJ(nodename, 0)
3378 END OBJ(processes, INFO_PROCS)
3379 END OBJ(running_processes, INFO_RUN_PROCS)
3380 END OBJ(shadecolor, 0)
3382 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
3384 END OBJ(outlinecolor, 0)
3386 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
3388 END OBJ(stippled_hr, 0)
3390 int a = stippled_borders, b = 1;
3393 if (sscanf(arg, "%d %d", &a, &b) != 2) {
3394 sscanf(arg, "%d", &b);
3400 obj->data.pair.a = a;
3401 obj->data.pair.b = b;
3403 END OBJ(swap, INFO_MEM)
3404 END OBJ(swapmax, INFO_MEM)
3405 END OBJ(swapperc, INFO_MEM)
3406 END OBJ(swapbar, INFO_MEM)
3407 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3410 END OBJ(temp1, INFO_SYSFS)
3411 obj->type = OBJ_i2c;
3412 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 1,
3413 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3414 END OBJ(temp2, INFO_SYSFS)
3415 obj->type = OBJ_i2c;
3416 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 2,
3417 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3420 obj->data.s = strdup(arg ? arg : "%F %T");
3422 obj->data.s = strdup(arg ? arg : "%F %T");
3424 char buf1[256], buf2[256], *fmt, *tz;
3428 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3438 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
3439 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
3441 END OBJ(iconv_start, 0)
3442 if (iconv_converting) {
3443 CRIT_ERR("You must stop your last iconv conversion before "
3444 "starting another");
3447 char iconv_from[CODEPAGE_LENGTH];
3448 char iconv_to[CODEPAGE_LENGTH];
3450 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3451 CRIT_ERR("Invalid arguments for iconv_start");
3455 new_iconv = iconv_open(iconv_to, iconv_from);
3456 if (new_iconv == (iconv_t) (-1)) {
3457 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3459 obj->a = register_iconv(&new_iconv);
3460 iconv_converting = 1;
3464 CRIT_ERR("Iconv requires arguments");
3466 END OBJ(iconv_stop, 0)
3467 iconv_converting = 0;
3470 END OBJ(totaldown, INFO_NET)
3472 obj->data.net = get_net_stat(arg);
3474 CRIT_ERR("totaldown needs argument");
3476 END OBJ(totalup, INFO_NET)
3477 obj->data.net = get_net_stat(arg);
3479 obj->data.net = get_net_stat(arg);
3481 CRIT_ERR("totalup needs argument");
3485 obj->data.i = arg ? atoi(arg) : 0;
3487 obj->data.i = arg ? atoi(arg) : 0;
3488 END OBJ(upspeed, INFO_NET)
3490 obj->data.net = get_net_stat(arg);
3492 CRIT_ERR("upspeed needs argument");
3494 END OBJ(upspeedf, INFO_NET)
3496 obj->data.net = get_net_stat(arg);
3498 CRIT_ERR("upspeedf needs argument");
3501 END OBJ(upspeedgraph, INFO_NET)
3502 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3506 obj->data.net = get_net_stat(buf);
3509 END OBJ(uptime_short, INFO_UPTIME)
3510 END OBJ(uptime, INFO_UPTIME)
3511 END OBJ(user_names, INFO_USERS)
3512 END OBJ(user_times, INFO_USERS)
3513 END OBJ(user_terms, INFO_USERS)
3514 END OBJ(user_number, INFO_USERS)
3515 END OBJ(gw_iface, INFO_GW)
3516 END OBJ(gw_ip, INFO_GW)
3517 END OBJ(if_gw, INFO_GW)
3519 END OBJ(adt746xcpu, 0)
3520 END OBJ(adt746xfan, 0)
3521 #endif /* !__OpenBSD__ */
3522 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
3523 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3524 END OBJ(apm_adapter, 0)
3525 END OBJ(apm_battery_life, 0)
3526 END OBJ(apm_battery_time, 0)
3527 #endif /* __FreeBSD__ */
3528 END OBJ(imap_unseen, 0)
3531 obj->data.mail = parse_mail_args(IMAP, arg);
3532 obj->global_mode = 0;
3534 obj->global_mode = 1;
3536 END OBJ(imap_messages, 0)
3539 obj->data.mail = parse_mail_args(IMAP, arg);
3540 obj->global_mode = 0;
3542 obj->global_mode = 1;
3544 END OBJ(pop3_unseen, 0)
3547 obj->data.mail = parse_mail_args(POP3, arg);
3548 obj->global_mode = 0;
3550 obj->global_mode = 1;
3552 END OBJ(pop3_used, 0)
3555 obj->data.mail = parse_mail_args(POP3, arg);
3556 obj->global_mode = 0;
3558 obj->global_mode = 1;
3563 obj->data.s = strdup(arg);
3565 ERR("smapi needs an argument");
3566 END OBJ(if_smapi_bat_installed, 0)
3567 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3568 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3571 ERR("if_smapi_bat_installed needs an argument");
3572 obj->data.ifblock.s = 0;
3574 obj->data.ifblock.s = strdup(arg);
3575 blockstart[blockdepth] = object_count;
3576 obj->data.ifblock.pos = object_count + 2;
3578 END OBJ(smapi_bat_perc, 0)
3580 obj->data.s = strdup(arg);
3582 ERR("smapi_bat_perc needs an argument");
3583 END OBJ(smapi_bat_bar, 0)
3586 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
3587 ERR("first argument to smapi_bat_bar must be an integer value");
3591 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
3594 ERR("if_smapi_bat_bar needs an argument");
3597 END OBJ(mpd_artist, INFO_MPD)
3598 END OBJ(mpd_title, INFO_MPD)
3600 sscanf(arg, "%d", &info.mpd.max_title_len);
3601 if (info.mpd.max_title_len > 0) {
3602 info.mpd.max_title_len++;
3604 CRIT_ERR("mpd_title: invalid length argument");
3607 info.mpd.max_title_len = 0;
3609 END OBJ(mpd_random, INFO_MPD)
3610 END OBJ(mpd_repeat, INFO_MPD)
3611 END OBJ(mpd_elapsed, INFO_MPD)
3612 END OBJ(mpd_length, INFO_MPD)
3613 END OBJ(mpd_track, INFO_MPD)
3614 END OBJ(mpd_name, INFO_MPD)
3615 END OBJ(mpd_file, INFO_MPD)
3616 END OBJ(mpd_percent, INFO_MPD)
3617 END OBJ(mpd_album, INFO_MPD)
3618 END OBJ(mpd_vol, INFO_MPD)
3619 END OBJ(mpd_bitrate, INFO_MPD)
3620 END OBJ(mpd_status, INFO_MPD)
3621 END OBJ(mpd_bar, INFO_MPD)
3622 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3623 END OBJ(mpd_smart, INFO_MPD)
3626 END OBJ(xmms2_artist, INFO_XMMS2)
3627 END OBJ(xmms2_album, INFO_XMMS2)
3628 END OBJ(xmms2_title, INFO_XMMS2)
3629 END OBJ(xmms2_genre, INFO_XMMS2)
3630 END OBJ(xmms2_comment, INFO_XMMS2)
3631 END OBJ(xmms2_url, INFO_XMMS2)
3632 END OBJ(xmms2_tracknr, INFO_XMMS2)
3633 END OBJ(xmms2_bitrate, INFO_XMMS2)
3634 END OBJ(xmms2_date, INFO_XMMS2)
3635 END OBJ(xmms2_id, INFO_XMMS2)
3636 END OBJ(xmms2_duration, INFO_XMMS2)
3637 END OBJ(xmms2_elapsed, INFO_XMMS2)
3638 END OBJ(xmms2_size, INFO_XMMS2)
3639 END OBJ(xmms2_status, INFO_XMMS2)
3640 END OBJ(xmms2_percent, INFO_XMMS2)
3641 END OBJ(xmms2_bar, INFO_XMMS2)
3642 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3643 END OBJ(xmms2_smart, INFO_XMMS2)
3644 END OBJ(xmms2_playlist, INFO_XMMS2)
3645 END OBJ(xmms2_timesplayed, INFO_XMMS2)
3648 END OBJ(audacious_status, INFO_AUDACIOUS)
3649 END OBJ(audacious_title, INFO_AUDACIOUS)
3651 sscanf(arg, "%d", &info.audacious.max_title_len);
3652 if (info.audacious.max_title_len > 0) {
3653 info.audacious.max_title_len++;
3655 CRIT_ERR("audacious_title: invalid length argument");
3658 END OBJ(audacious_length, INFO_AUDACIOUS)
3659 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
3660 END OBJ(audacious_position, INFO_AUDACIOUS)
3661 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
3662 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
3663 END OBJ(audacious_frequency, INFO_AUDACIOUS)
3664 END OBJ(audacious_channels, INFO_AUDACIOUS)
3665 END OBJ(audacious_filename, INFO_AUDACIOUS)
3666 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
3667 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
3668 END OBJ(audacious_bar, INFO_AUDACIOUS)
3669 scan_bar(arg, &obj->a, &obj->b);
3672 END OBJ(bmpx_title, INFO_BMPX)
3673 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3674 END OBJ(bmpx_artist, INFO_BMPX)
3675 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3676 END OBJ(bmpx_album, INFO_BMPX)
3677 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3678 END OBJ(bmpx_track, INFO_BMPX)
3679 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3680 END OBJ(bmpx_uri, INFO_BMPX)
3681 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3682 END OBJ(bmpx_bitrate, INFO_BMPX)
3683 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3688 int argc, delay, act_par;
3689 char *uri = (char *) malloc(128 * sizeof(char));
3690 char *action = (char *) malloc(64 * sizeof(char));
3692 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action,
3694 obj->data.rss.uri = uri;
3695 obj->data.rss.delay = delay;
3696 obj->data.rss.action = action;
3697 obj->data.rss.act_par = act_par;
3701 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
3707 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3708 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3709 ERR("hddtemp needs arguments");
3710 obj->type = OBJ_text;
3711 obj->data.s = strdup("${hddtemp}");
3715 #ifdef TCP_PORT_MONITOR
3716 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3717 int argc, port_begin, port_end, item, connection_index;
3720 memset(itembuf, 0, sizeof(itembuf));
3721 connection_index = 0;
3722 /* massive argument checking */
3724 CRIT_ERR("tcp_portmon: needs arguments");
3726 argc = sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf,
3728 if ((argc != 3) && (argc != 4)) {
3729 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3731 if ((port_begin < 1) || (port_begin > 65535) || (port_end < 1)
3732 || (port_end > 65535)) {
3733 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3735 if (port_begin > port_end) {
3736 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3738 if (strncmp(itembuf, "count", 31) == 0) {
3740 } else if (strncmp(itembuf, "rip", 31) == 0) {
3742 } else if (strncmp(itembuf, "rhost", 31) == 0) {
3744 } else if (strncmp(itembuf, "rport", 31) == 0) {
3746 } else if (strncmp(itembuf, "rservice", 31) == 0) {
3747 item = REMOTESERVICE;
3748 } else if (strncmp(itembuf, "lip", 31) == 0) {
3750 } else if (strncmp(itembuf, "lhost", 31) == 0) {
3752 } else if (strncmp(itembuf, "lport", 31) == 0) {
3754 } else if (strncmp(itembuf, "lservice", 31) == 0) {
3755 item = LOCALSERVICE;
3757 CRIT_ERR("tcp_portmon: invalid item specified");
3759 if ((argc == 3) && (item != COUNT)) {
3760 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" "
3763 if ((argc == 4) && (connection_index < 0)) {
3764 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3766 /* ok, args looks good. save the text object data */
3767 obj->data.tcp_port_monitor.port_range_begin = (in_port_t) port_begin;
3768 obj->data.tcp_port_monitor.port_range_end = (in_port_t) port_end;
3769 obj->data.tcp_port_monitor.item = item;
3770 obj->data.tcp_port_monitor.connection_index = connection_index;
3772 /* if the port monitor collection hasn't been created,
3773 * we must create it */
3774 if (!info.p_tcp_port_monitor_collection) {
3775 info.p_tcp_port_monitor_collection =
3776 create_tcp_port_monitor_collection();
3777 if (!info.p_tcp_port_monitor_collection) {
3778 CRIT_ERR("tcp_portmon: unable to create port monitor "
3783 /* if a port monitor for this port does not exist,
3784 * create one and add it to the collection */
3785 if (find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
3786 port_begin, port_end) == NULL) {
3787 tcp_port_monitor_t *p_monitor = create_tcp_port_monitor(port_begin,
3788 port_end, &tcp_port_monitor_args);
3791 CRIT_ERR("tcp_portmon: unable to create port monitor");
3793 /* add the newly created monitor to the collection */
3794 if (insert_tcp_port_monitor_into_collection(
3795 info.p_tcp_port_monitor_collection, p_monitor) != 0) {
3796 CRIT_ERR("tcp_portmon: unable to add port monitor to "
3801 END OBJ(entropy_avail, INFO_ENTROPY)
3802 END OBJ(entropy_poolsize, INFO_ENTROPY)
3803 END OBJ(entropy_bar, INFO_ENTROPY)
3804 scan_bar(arg, &obj->a, &obj->b);
3808 ERR("unknown variable %s", s);
3809 obj->type = OBJ_text;
3810 snprintf(buf, 256, "${%s}", s);
3811 obj->data.s = strdup(buf);
3818 static struct text_object *create_plain_text(const char *s)
3820 struct text_object *obj;
3822 if (s == NULL || *s == '\0') {
3826 obj = new_text_object_internal();
3828 obj->type = OBJ_text;
3829 obj->data.s = strdup(s);
3833 static struct text_object_list *extract_variable_text_internal(const char *const_p)
3835 struct text_object_list *retval;
3836 struct text_object *obj;
3837 char *p, *s, *orig_p;
3840 p = strdup(const_p);
3843 retval = malloc(sizeof(struct text_object_list));
3844 memset(retval, 0, sizeof(struct text_object_list));
3845 retval->text_object_count = 0;
3855 obj = create_plain_text(s);
3857 // allocate memory for the object
3858 retval->text_objects = realloc(retval->text_objects,
3859 sizeof(struct text_object) *
3860 (retval->text_object_count + 1));
3861 // assign the new object to the end of the list.
3862 memcpy(&retval->text_objects[retval->text_object_count++], obj,
3863 sizeof(struct text_object));
3875 /* variable is either $foo or ${foo} */
3877 unsigned int brl = 1, brr = 0;
3881 while (*p && brl != brr) {
3896 while (*p && (isalnum((int) *p) || *p == '_')) {
3901 /* copy variable to buffer */
3902 len = (p - s > 255) ? 255 : (p - s);
3903 strncpy(buf, s, len);
3913 /* if variable wasn't found in environment, use some special */
3919 if (strchr(buf, ' ')) {
3920 arg = strchr(buf, ' ');
3923 while (isspace((int) *arg)) {
3931 /* lowercase variable name */
3934 *tmp_p = tolower(*tmp_p);
3938 // create new object
3939 obj = construct_text_object(buf, arg,
3940 retval->text_object_count, retval->text_objects, line);
3942 // allocate memory for the object
3943 retval->text_objects = realloc(retval->text_objects,
3944 sizeof(struct text_object) *
3945 (retval->text_object_count + 1));
3946 // assign the new object to the end of the list.
3948 &retval->text_objects[retval->text_object_count++],
3949 obj, sizeof(struct text_object));
3955 obj = create_plain_text("$");
3957 // allocate memory for the object
3958 retval->text_objects = realloc(retval->text_objects,
3959 sizeof(struct text_object) *
3960 (retval->text_object_count + 1));
3961 // assign the new object to the end of the list.
3962 memcpy(&retval->text_objects[retval->text_object_count++],
3963 obj, sizeof(struct text_object));
3970 obj = create_plain_text(s);
3972 // allocate memory for the object
3973 retval->text_objects = realloc(retval->text_objects,
3974 sizeof(struct text_object) * (retval->text_object_count + 1));
3975 // assign the new object to the end of the list.
3976 memcpy(&retval->text_objects[retval->text_object_count++], obj,
3977 sizeof(struct text_object));
3982 ERR("one or more $endif's are missing");
3989 static void extract_variable_text(const char *p)
3991 struct text_object_list *list;
3993 free_text_objects(global_text_object_count, global_text_objects);
4006 global_text_object_count = 0;
4007 global_text_objects = NULL;
4009 list = extract_variable_text_internal(p);
4010 global_text_objects = list->text_objects;
4011 global_text_object_count = list->text_object_count;
4016 struct text_object_list *parse_conky_vars(char *text, char *p, struct information *cur)
4018 struct text_object_list *object_list =
4019 extract_variable_text_internal(text);
4021 generate_text_internal(p, max_user_text, object_list->text_objects,
4022 object_list->text_object_count, cur);
4026 /* Allows reading from a FIFO (i.e., /dev/xconsole).
4027 * The file descriptor is set to non-blocking which makes this possible.
4029 * FIXME: Since lseek cannot seek a file descriptor long lines will break. */
4030 static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
4032 #define TAIL_PIPE_BUFSIZE 4096
4036 int fd = obj->data.tail.fd;
4039 char buf[TAIL_PIPE_BUFSIZE];
4040 ssize_t len = read(fd, buf, sizeof(buf));
4044 if (errno != EAGAIN) {
4045 strcpy(obj->data.tail.buffer, "Logfile Read Error");
4046 snprintf(dst, dst_size, "Logfile Read Error");
4050 } else if (len == 0) {
4051 strcpy(obj->data.tail.buffer, "Logfile Empty");
4052 snprintf(dst, dst_size, "Logfile Empty");
4056 for (line_len = 0, i = 0; i < len; i++) {
4060 if (buf[i] == '\n') {
4063 if (obj->data.tail.readlines > 0) {
4068 for (n = 0; obj->data.tail.buffer[n]; n++) {
4069 if (obj->data.tail.buffer[n] == '\n') {
4074 if (++olines < obj->data.tail.wantedlines) {
4080 p = obj->data.tail.buffer + first_line;
4081 pos = n - first_line;
4082 memmove(obj->data.tail.buffer,
4083 obj->data.tail.buffer + first_line, strlen(p));
4084 obj->data.tail.buffer[pos] = 0;
4090 p = buf + last_line;
4092 memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
4093 obj->data.tail.buffer[pos + line_len] = 0;
4096 obj->data.tail.readlines = lines;
4104 snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
4107 char *format_time(unsigned long time, const int width)
4110 unsigned long nt; // narrow time, for speed on 32-bit
4111 unsigned cc; // centiseconds
4112 unsigned nn; // multi-purpose whatever
4115 cc = nt % 100; // centiseconds past second
4116 nt /= 100; // total seconds
4117 nn = nt % 60; // seconds past the minute
4118 nt /= 60; // total minutes
4119 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
4123 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
4126 nn = nt % 60; // minutes past the hour
4127 nt /= 60; // total hours
4128 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
4131 nn = nt; // now also hours
4132 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
4135 nn /= 24; // now days
4136 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
4139 nn /= 7; // now weeks
4140 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
4143 // well shoot, this outta' fit...
4144 return strdup("<inf>");
4147 static void generate_text_internal(char *p, int p_max_size,
4148 struct text_object *objs, unsigned int object_count,
4149 struct information *cur)
4154 char buff_in[p_max_size];
4156 iconv_converting = 0;
4159 for (i = 0; i < object_count; i++) {
4160 struct text_object *obj = &objs[i];
4162 if (p_max_size < 1) {
4166 #define OBJ(a) break; case OBJ_##a:
4168 switch (obj->type) {
4170 ERR("not implemented obj type %d", obj->type);
4173 /* does anyone have decimals in acpi temperature? */
4174 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
4175 round_to_int(get_acpi_temperature(obj->data.i)));
4178 /* does anyone have decimals in acpi temperature? */
4179 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
4180 round_to_int((get_acpi_temperature(obj->data.i) + 40) *
4183 #endif /* !__OpenBSD__ */
4186 obj->a = get_freq(p, p_max_size, "%.0f", 1,
4187 obj->data.cpu_index);
4193 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
4194 obj->data.cpu_index);
4196 /* OpenBSD has no such flag (SUSv2) */
4197 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
4198 obj->data.cpu_index);
4202 #if defined(__linux__)
4205 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
4206 obj->data.cpu_index);
4211 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
4212 obj->data.cpu_index);
4217 OBJ(wireless_essid) {
4218 snprintf(p, p_max_size, "%s", obj->data.net->essid);
4220 OBJ(wireless_mode) {
4221 snprintf(p, p_max_size, "%s", obj->data.net->mode);
4223 OBJ(wireless_bitrate) {
4224 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
4227 snprintf(p, p_max_size, "%s", obj->data.net->ap);
4229 OBJ(wireless_link_qual) {
4230 spaced_print(p, p_max_size, "%d", 4, "wireless_link_qual",
4231 obj->data.net->link_qual);
4233 OBJ(wireless_link_qual_max) {
4234 spaced_print(p, p_max_size, "%d", 4,
4235 "wireless_link_qual_max", obj->data.net->link_qual_max);
4237 OBJ(wireless_link_qual_perc) {
4238 if (obj->data.net->link_qual_max > 0) {
4239 spaced_print(p, p_max_size, "%.0f", 5,
4240 "wireless_link_qual_perc",
4241 (double) obj->data.net->link_qual /
4242 obj->data.net->link_qual_max * 100);
4244 spaced_print(p, p_max_size, "unk", 5,
4245 "wireless_link_qual_perc");
4248 OBJ(wireless_link_bar) {
4249 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
4250 obj->data.net->link_qual_max) * 255.0);
4252 #endif /* HAVE_IWLIB */
4254 #endif /* __linux__ */
4257 get_freq_dynamic(p, p_max_size, "%.0f", 1);
4258 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4262 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
4264 get_freq_dynamic(p, p_max_size, "%.2f", 1000);
4266 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4271 get_adt746x_cpu(p, p_max_size);
4274 get_adt746x_fan(p, p_max_size);
4277 get_acpi_fan(p, p_max_size);
4279 OBJ(acpiacadapter) {
4280 get_acpi_ac_adapter(p, p_max_size);
4283 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
4286 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
4288 OBJ(battery_percent) {
4289 spaced_print(p, p_max_size, "%*d", 4, "battery_percent",
4290 pad_percents, get_battery_perct(obj->data.s));
4293 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
4295 #endif /* __OpenBSD__ */
4298 human_readable(cur->buffers * 1024, p, 255, "buffers");
4301 human_readable(cur->cached * 1024, p, 255, "buffers");
4304 if (obj->data.cpu_index > info.cpu_count) {
4305 printf("obj->data.cpu_index %i info.cpu_count %i",
4306 obj->data.cpu_index, info.cpu_count);
4307 CRIT_ERR("attempting to use more CPUs then you have!");
4309 spaced_print(p, p_max_size, "%*d", 4, "cpu", pad_percents,
4310 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
4313 new_bar(p, obj->a, obj->b,
4314 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
4317 new_graph(p, obj->a, obj->b, obj->c, obj->d, (unsigned int)
4318 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
4322 new_fg(p, obj->data.l);
4354 OBJ(conky_version) {
4355 snprintf(p, p_max_size, "%s", VERSION);
4357 OBJ(conky_build_date) {
4358 snprintf(p, p_max_size, "%s", BUILD_DATE);
4360 OBJ(conky_build_arch) {
4361 snprintf(p, p_max_size, "%s", BUILD_ARCH);
4363 #if defined(__linux__)
4365 snprintf(p, p_max_size, "%s",
4366 get_disk_protect_queue(obj->data.s));
4369 snprintf(p, p_max_size, "%s", i8k.version);
4372 snprintf(p, p_max_size, "%s", i8k.bios);
4375 snprintf(p, p_max_size, "%s", i8k.serial);
4378 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
4380 OBJ(i8k_cpu_tempf) {
4383 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
4384 snprintf(p, p_max_size, "%.1f", cpu_temp * (9.0 / 5.0) + 32.0);
4386 OBJ(i8k_left_fan_status) {
4387 int left_fan_status;
4389 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
4390 if (left_fan_status == 0) {
4391 snprintf(p, p_max_size, "off");
4393 if (left_fan_status == 1) {
4394 snprintf(p, p_max_size, "low");
4396 if (left_fan_status == 2) {
4397 snprintf(p, p_max_size, "high");
4400 OBJ(i8k_right_fan_status) {
4401 int right_fan_status;
4403 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
4404 if (right_fan_status == 0) {
4405 snprintf(p, p_max_size, "off");
4407 if (right_fan_status == 1) {
4408 snprintf(p, p_max_size, "low");
4410 if (right_fan_status == 2) {
4411 snprintf(p, p_max_size, "high");
4414 OBJ(i8k_left_fan_rpm) {
4415 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
4417 OBJ(i8k_right_fan_rpm) {
4418 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
4420 OBJ(i8k_ac_status) {
4423 sscanf(i8k.ac_status, "%d", &ac_status);
4424 if (ac_status == -1) {
4425 snprintf(p, p_max_size, "disabled (read i8k docs)");
4427 if (ac_status == 0) {
4428 snprintf(p, p_max_size, "off");
4430 if (ac_status == 1) {
4431 snprintf(p, p_max_size, "on");
4434 OBJ(i8k_buttons_status) {
4435 snprintf(p, p_max_size, "%s", i8k.buttons_status);
4438 get_ibm_acpi_fan(p, p_max_size);
4441 get_ibm_acpi_temps();
4442 snprintf(p, p_max_size, "%d", ibm_acpi.temps[obj->data.sensor]);
4445 get_ibm_acpi_volume(p, p_max_size);
4447 OBJ(ibm_brightness) {
4448 get_ibm_acpi_brightness(p, p_max_size);
4451 if ((obj->data.ifblock.s)
4452 && (!interface_up(obj->data.ifblock.s))) {
4453 i = obj->data.ifblock.pos;
4460 if (!cur->gw_info.count) {
4461 i = obj->data.ifblock.pos;
4468 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
4471 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
4474 snprintf(p, p_max_size, "%d", get_laptop_mode());
4477 get_powerbook_batt_info(p, p_max_size, obj->data.i);
4479 #endif /* __linux__ */
4482 OBJ(obsd_sensors_temp) {
4483 obsd_sensors.device = sensor_device;
4484 update_obsd_sensors();
4485 snprintf(p, p_max_size, "%.1f",
4486 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
4488 OBJ(obsd_sensors_fan) {
4489 obsd_sensors.device = sensor_device;
4490 update_obsd_sensors();
4491 snprintf(p, p_max_size, "%d",
4492 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
4494 OBJ(obsd_sensors_volt) {
4495 obsd_sensors.device = sensor_device;
4496 update_obsd_sensors();
4497 snprintf(p, p_max_size, "%.2f",
4498 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4501 get_obsd_vendor(p, p_max_size);
4504 get_obsd_product(p, p_max_size);
4506 #endif /* __OpenBSD__ */
4510 new_font(p, obj->data.s);
4513 /* TODO: move this correction from kB to kB/s elsewhere
4514 * (or get rid of it??) */
4516 if (obj->data.diskio) {
4518 (obj->data.diskio->current / update_interval) * 1024LL,
4519 p, p_max_size, "diskio");
4521 human_readable(diskio_value * 1024LL, p, p_max_size,
4526 if (obj->data.diskio) {
4527 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL, p, p_max_size,
4530 human_readable(diskio_write_value * 1024LL, p, p_max_size,
4535 if (obj->data.diskio) {
4536 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL, p, p_max_size,
4539 human_readable(diskio_read_value * 1024LL, p, p_max_size,
4544 if (obj->data.diskio) {
4545 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4546 obj->data.diskio->current, obj->e, 1);
4548 new_graph(p, obj->a, obj->b, obj->c, obj->d, diskio_value,
4552 OBJ(diskiograph_read) {
4553 if (obj->data.diskio) {
4554 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4555 obj->data.diskio->current_read, obj->e, 1);
4557 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4558 diskio_read_value, obj->e, 1);
4561 OBJ(diskiograph_write) {
4562 if (obj->data.diskio) {
4563 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4564 obj->data.diskio->current_write, obj->e, 1);
4566 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4567 diskio_write_value, obj->e, 1);
4571 spaced_print(p, p_max_size, "%d", 6, "downspeed",
4572 round_to_int(obj->data.net->recv_speed / 1024));
4575 spaced_print(p, p_max_size, "%.1f", 8, "downspeedf",
4576 obj->data.net->recv_speed / 1024.0);
4578 OBJ(downspeedgraph) {
4579 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4580 obj->data.net->recv_speed / 1024.0, obj->e, 1);
4584 i = obj->data.ifblock.pos - 1;
4594 snprintf(p, p_max_size, "%u.%u.%u.%u",
4595 obj->data.net->addr.sa_data[2] & 255,
4596 obj->data.net->addr.sa_data[3] & 255,
4597 obj->data.net->addr.sa_data[4] & 255,
4598 obj->data.net->addr.sa_data[5] & 255);
4601 #if defined(__linux__)
4603 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
4605 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
4606 strcpy(p, obj->data.net->addrs);
4609 strcpy(p, "0.0.0.0");
4611 #endif /* __linux__ */
4613 #if defined(IMLIB2) && defined(X11)
4618 Imlib_Image image, buffer;
4620 image = imlib_load_image(obj->data.s);
4621 imlib_context_set_image(image);
4625 w = imlib_image_get_width();
4626 h = imlib_image_get_height();
4627 buffer = imlib_create_image(w, h);
4628 imlib_context_set_display(display);
4629 imlib_context_set_drawable(window.drawable);
4630 imlib_context_set_colormap(DefaultColormap(display,
4632 imlib_context_set_visual(DefaultVisual(display,
4634 imlib_context_set_image(buffer);
4635 imlib_blend_image_onto_image(image, 0, 0, 0, w, h,
4636 text_start_x, text_start_y, w, h);
4637 imlib_render_image_on_drawable(text_start_x,
4640 imlib_context_set_image(image);
4648 FILE *fp = popen(obj->data.s, "r");
4649 int length = fread(p, 1, p_max_size, fp);
4654 if (length > 0 && p[length - 1] == '\n') {
4655 p[length - 1] = '\0';
4660 struct information *my_info;
4661 struct text_object_list *text_objects;
4664 fp = popen(obj->data.s, "r");
4665 fread(p, 1, p_max_size, fp);
4668 my_info = malloc(sizeof(struct information));
4669 memcpy(my_info, cur, sizeof(struct information));
4670 text_objects = parse_conky_vars(p, p, my_info);
4675 if (length > 0 && p[length - 1] == '\n') {
4676 p[length - 1] = '\0';
4679 free_text_objects(text_objects->text_object_count, text_objects->text_objects);
4685 FILE *fp = popen(obj->data.s, "r");
4686 int n2 = fread(p, 1, p_max_size, fp);
4691 if (n2 && p[n2 - 1] == '\n') {
4696 if (*p2 == '\001') {
4702 if (sscanf(p, "%lf", &barnum) == 0) {
4703 ERR("reading execbar value failed (perhaps it's not the "
4704 "correct format?)");
4706 if (barnum > 100 || barnum < 0) {
4707 ERR("your execbar value is not between 0 and 100, "
4708 "therefore it will be ignored");
4710 barnum = barnum / 100.0;
4711 new_bar(p, 0, 4, (int) (barnum * 255.0));
4716 FILE *fp = popen(obj->data.s, "r");
4717 int n2 = fread(p, 1, p_max_size, fp);
4722 if (n2 && p[n2 - 1] == '\n') {
4726 if (*p2 == '\001') {
4732 if (sscanf(p, "%lf", &barnum) == 0) {
4733 ERR("reading execgraph value failed (perhaps it's not the "
4734 "correct format?)");
4736 if (barnum > 100 || barnum < 0) {
4737 ERR("your execgraph value is not between 0 and 100, "
4738 "therefore it will be ignored");
4740 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum),
4745 if (current_update_time - obj->data.execi.last_update
4746 < obj->data.execi.interval) {
4747 new_bar(p, 0, 4, (int) obj->f);
4750 FILE *fp = popen(obj->data.execi.cmd, "r");
4751 int n2 = fread(p, 1, p_max_size, fp);
4756 if (n2 && p[n2 - 1] == '\n') {
4761 if (*p2 == '\001') {
4767 if (sscanf(p, "%f", &barnum) == 0) {
4768 ERR("reading execibar value failed (perhaps it's not "
4769 "the correct format?)");
4771 if (barnum > 100 || barnum < 0) {
4772 ERR("your execibar value is not between 0 and 100, "
4773 "therefore it will be ignored");
4775 obj->f = 255 * barnum / 100.0;
4776 new_bar(p, 0, 4, (int) obj->f);
4778 obj->data.execi.last_update = current_update_time;
4782 if (current_update_time - obj->data.execi.last_update
4783 < obj->data.execi.interval) {
4784 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
4787 FILE *fp = popen(obj->data.execi.cmd, "r");
4788 int n2 = fread(p, 1, p_max_size, fp);
4793 if (n2 && p[n2 - 1] == '\n') {
4798 if (*p2 == '\001') {
4804 if (sscanf(p, "%f", &barnum) == 0) {
4805 ERR("reading execigraph value failed (perhaps it's not "
4806 "the correct format?)");
4808 if (barnum > 100 || barnum < 0) {
4809 ERR("your execigraph value is not between 0 and 100, "
4810 "therefore it will be ignored");
4813 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f),
4816 obj->data.execi.last_update = current_update_time;
4820 if (current_update_time - obj->data.execi.last_update
4821 < obj->data.execi.interval
4822 || obj->data.execi.interval == 0) {
4823 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4825 char *output = obj->data.execi.buffer;
4826 FILE *fp = popen(obj->data.execi.cmd, "r");
4828 int length = fread(output, 1, text_buffer_size, fp);
4831 output[length] = '\0';
4832 if (length > 0 && output[length - 1] == '\n') {
4833 output[length - 1] = '\0';
4835 obj->data.execi.last_update = current_update_time;
4836 snprintf(p, p_max_size, "%s", output);
4838 // parse_conky_vars(output, p, cur);
4841 struct text_object_list *text_objects = 0;
4842 struct information *my_info =
4843 malloc(sizeof(struct information));
4844 memcpy(my_info, cur, sizeof(struct information));
4846 if (current_update_time - obj->data.execi.last_update
4847 < obj->data.execi.interval
4848 || obj->data.execi.interval == 0) {
4849 text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info);
4851 char *output = obj->data.execi.buffer;
4852 FILE *fp = popen(obj->data.execi.cmd, "r");
4853 int length = fread(output, 1, text_buffer_size, fp);
4857 output[length] = '\0';
4858 if (length > 0 && output[length - 1] == '\n') {
4859 output[length - 1] = '\0';
4862 text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info);
4863 obj->data.execi.last_update = current_update_time;
4865 free_text_objects(text_objects->text_object_count, text_objects->text_objects);
4870 if (!obj->data.texeci.p_timed_thread) {
4871 obj->data.texeci.p_timed_thread =
4872 timed_thread_create(&threaded_exec,
4873 (void *) obj, obj->data.texeci.interval * 1000000);
4874 if (!obj->data.texeci.p_timed_thread) {
4875 ERR("Error creating texeci timed thread");
4877 timed_thread_register(obj->data.texeci.p_timed_thread,
4878 &obj->data.texeci.p_timed_thread);
4879 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
4880 ERR("Error running texeci timed thread");
4883 timed_thread_lock(obj->data.texeci.p_timed_thread);
4884 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4885 timed_thread_unlock(obj->data.texeci.p_timed_thread);
4887 #endif /* HAVE_POPEN */
4889 if (obj->global_mode && info.mail) {
4890 // this means we use info
4891 if (!info.mail->p_timed_thread) {
4892 info.mail->p_timed_thread =
4893 timed_thread_create(&imap_thread,
4894 (void *) info.mail, info.mail->interval * 1000000);
4895 if (!info.mail->p_timed_thread) {
4896 ERR("Error creating imap timed thread");
4898 timed_thread_register(info.mail->p_timed_thread,
4899 &info.mail->p_timed_thread);
4900 if (timed_thread_run(info.mail->p_timed_thread)) {
4901 ERR("Error running imap timed thread");
4904 timed_thread_lock(info.mail->p_timed_thread);
4905 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4906 timed_thread_unlock(info.mail->p_timed_thread);
4907 } else if (obj->data.mail) {
4908 // this means we use obj
4909 if (!obj->data.mail->p_timed_thread) {
4910 obj->data.mail->p_timed_thread =
4911 timed_thread_create(&imap_thread,
4912 (void *) obj->data.mail,
4913 obj->data.mail->interval * 1000000);
4914 if (!obj->data.mail->p_timed_thread) {
4915 ERR("Error creating imap timed thread");
4917 timed_thread_register(obj->data.mail->p_timed_thread,
4918 &obj->data.mail->p_timed_thread);
4919 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
4920 ERR("Error running imap timed thread");
4923 timed_thread_lock(obj->data.mail->p_timed_thread);
4924 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4925 timed_thread_unlock(obj->data.mail->p_timed_thread);
4926 } else if (!obj->a) {
4927 // something is wrong, warn once then stop
4928 ERR("Theres a problem with your imap_unseen settings. "
4929 "Check that the global IMAP settings are defined "
4930 "properly (line %li).", obj->line);
4934 OBJ(imap_messages) {
4935 if (obj->global_mode && info.mail) {
4936 // this means we use info
4937 if (!info.mail->p_timed_thread) {
4938 info.mail->p_timed_thread =
4939 timed_thread_create(&imap_thread,
4940 (void *) info.mail, info.mail->interval * 1000000);
4941 if (!info.mail->p_timed_thread) {
4942 ERR("Error creating imap timed thread");
4944 timed_thread_register(info.mail->p_timed_thread,
4945 &info.mail->p_timed_thread);
4946 if (timed_thread_run(info.mail->p_timed_thread)) {
4947 ERR("Error running imap timed thread");
4950 timed_thread_lock(info.mail->p_timed_thread);
4951 snprintf(p, p_max_size, "%lu", info.mail->messages);
4952 timed_thread_unlock(info.mail->p_timed_thread);
4953 } else if (obj->data.mail) {
4954 // this means we use obj
4955 if (!obj->data.mail->p_timed_thread) {
4956 obj->data.mail->p_timed_thread =
4957 timed_thread_create(&imap_thread,
4958 (void *) obj->data.mail,
4959 obj->data.mail->interval * 1000000);
4960 if (!obj->data.mail->p_timed_thread) {
4961 ERR("Error creating imap timed thread");
4963 timed_thread_register(obj->data.mail->p_timed_thread,
4964 &obj->data.mail->p_timed_thread);
4965 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
4966 ERR("Error runninging imap timed thread");
4969 timed_thread_lock(obj->data.mail->p_timed_thread);
4970 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4971 timed_thread_lock(obj->data.mail->p_timed_thread);
4972 } else if (!obj->a) {
4973 // something is wrong, warn once then stop
4974 ERR("Theres a problem with your imap_messages settings. "
4975 "Check that the global IMAP settings are defined "
4976 "properly (line %li).", obj->line);
4981 if (obj->global_mode && info.mail) {
4982 // this means we use info
4983 if (!info.mail->p_timed_thread) {
4984 info.mail->p_timed_thread =
4985 timed_thread_create(&pop3_thread,
4986 (void *) info.mail, info.mail->interval * 1000000);
4987 if (!info.mail->p_timed_thread) {
4988 ERR("Error creating pop3 timed thread");
4990 timed_thread_register(info.mail->p_timed_thread,
4991 &info.mail->p_timed_thread);
4992 if (timed_thread_run(info.mail->p_timed_thread)) {
4993 ERR("Error running pop3 timed thread");
4996 timed_thread_lock(info.mail->p_timed_thread);
4997 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4998 timed_thread_unlock(info.mail->p_timed_thread);
4999 } else if (obj->data.mail) {
5000 // this means we use obj
5001 if (!obj->data.mail->p_timed_thread) {
5002 obj->data.mail->p_timed_thread =
5003 timed_thread_create(&pop3_thread,
5004 (void *) obj->data.mail,
5005 obj->data.mail->interval * 1000000);
5006 if (!obj->data.mail->p_timed_thread) {
5007 ERR("Error creating pop3 timed thread");
5009 timed_thread_register(obj->data.mail->p_timed_thread,
5010 &obj->data.mail->p_timed_thread);
5011 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
5012 ERR("Error running pop3 timed thread");
5015 timed_thread_lock(obj->data.mail->p_timed_thread);
5016 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
5017 timed_thread_unlock(obj->data.mail->p_timed_thread);
5018 } else if (!obj->a) {
5019 // something is wrong, warn once then stop
5020 ERR("Theres a problem with your pop3_unseen settings. "
5021 "Check that the global POP3 settings are defined "
5022 "properly (line %li).", obj->line);
5027 if (obj->global_mode && info.mail) {
5028 // this means we use info
5029 if (!info.mail->p_timed_thread) {
5030 info.mail->p_timed_thread =
5031 timed_thread_create(&pop3_thread,
5032 (void *) info.mail, info.mail->interval * 1000000);
5033 if (!info.mail->p_timed_thread) {
5034 ERR("Error creating pop3 timed thread");
5036 timed_thread_register(info.mail->p_timed_thread,
5037 &info.mail->p_timed_thread);
5038 if (timed_thread_run(info.mail->p_timed_thread)) {
5039 ERR("Error running pop3 timed thread");
5042 timed_thread_lock(info.mail->p_timed_thread);
5043 snprintf(p, p_max_size, "%.1f",
5044 info.mail->used / 1024.0 / 1024.0);
5045 timed_thread_unlock(info.mail->p_timed_thread);
5046 } else if (obj->data.mail) {
5047 // this means we use obj
5048 if (!obj->data.mail->p_timed_thread) {
5049 obj->data.mail->p_timed_thread =
5050 timed_thread_create(&pop3_thread,
5051 (void *) obj->data.mail,
5052 obj->data.mail->interval * 1000000);
5053 if (!obj->data.mail->p_timed_thread) {
5054 ERR("Error creating pop3 timed thread");
5056 timed_thread_register(obj->data.mail->p_timed_thread,
5057 &obj->data.mail->p_timed_thread);
5058 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
5059 ERR("Error running pop3 timed thread");
5062 timed_thread_lock(obj->data.mail->p_timed_thread);
5063 snprintf(p, p_max_size, "%.1f",
5064 obj->data.mail->used / 1024.0 / 1024.0);
5065 timed_thread_unlock(obj->data.mail->p_timed_thread);
5066 } else if (!obj->a) {
5067 // something is wrong, warn once then stop
5068 ERR("Theres a problem with your pop3_used settings. "
5069 "Check that the global POP3 settings are defined "
5070 "properly (line %li).", obj->line);
5075 if (obj->data.fs != NULL) {
5076 if (obj->data.fs->size == 0) {
5077 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5079 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5080 (int) (255 - obj->data.fsbar.fs->avail * 255 /
5081 obj->data.fs->size));
5086 if (obj->data.fs != NULL) {
5087 human_readable(obj->data.fs->avail, p, 255, "fs_free");
5091 if (obj->data.fs != NULL) {
5092 if (obj->data.fs->size) {
5093 spaced_print(p, p_max_size, "%*d", 4, "fs_free_perc",
5094 pad_percents, (int) ((obj->data.fs->avail * 100) /
5095 obj->data.fs->size));
5097 snprintf(p, p_max_size, "0");
5102 if (obj->data.fs != NULL) {
5103 human_readable(obj->data.fs->size, p, 255, "fs_size");
5107 if (obj->data.fs != NULL)
5108 snprintf(p, p_max_size, "%s", obj->data.fs->type);
5111 if (obj->data.fs != NULL) {
5112 human_readable(obj->data.fs->size - (obj->data.fs->free
5113 ? obj->data.fs->free : obj->data.fs->avail), p, 255,
5118 if (obj->data.fs != NULL) {
5119 if (obj->data.fs->size == 0) {
5120 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5122 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5123 (int) (obj->data.fsbar.fs->avail * 255 /
5124 obj->data.fs->size));
5129 if (obj->data.fs != NULL) {
5130 if (obj->data.fs->size) {
5131 spaced_print(p, 4, "%*d", 4, "fs_used_perc",
5132 pad_percents, 100 - ((int) ((obj->data.fs->avail * 100) /
5133 obj->data.fs->size)));
5135 snprintf(p, p_max_size, "0");
5140 float *v = info.loadavg;
5142 if (obj->data.loadavg[2]) {
5143 snprintf(p, p_max_size, "%.2f %.2f %.2f",
5144 v[obj->data.loadavg[0] - 1],
5145 v[obj->data.loadavg[1] - 1],
5146 v[obj->data.loadavg[2] - 1]);
5147 } else if (obj->data.loadavg[1]) {
5148 snprintf(p, p_max_size, "%.2f %.2f",
5149 v[obj->data.loadavg[0] - 1],
5150 v[obj->data.loadavg[1] - 1]);
5151 } else if (obj->data.loadavg[0]) {
5152 snprintf(p, p_max_size, "%.2f",
5153 v[obj->data.loadavg[0] - 1]);
5157 new_goto(p, obj->data.i);
5160 new_tab(p, obj->data.pair.a, obj->data.pair.b);
5163 new_hr(p, obj->data.i);
5166 if (cur->nameserver_info.nscount > obj->data.i)
5167 snprintf(p, p_max_size, "%s",
5168 cur->nameserver_info.ns_list[obj->data.i]);
5172 PRSS *data = get_rss_info(obj->data.rss.uri,
5173 obj->data.rss.delay);
5177 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
5179 if (!strcmp(obj->data.rss.action, "feed_title")) {
5181 // remove trailing new line if one exists
5182 if (str[strlen(str) - 1] == '\n') {
5183 str[strlen(str) - 1] = 0;
5185 snprintf(p, p_max_size, "%s", str);
5186 } else if (!strcmp(obj->data.rss.action, "item_title")) {
5187 if (obj->data.rss.act_par < data->item_count) {
5188 str = data->items[obj->data.rss.act_par].title;
5189 // remove trailing new line if one exists
5190 if (str[strlen(str) - 1] == '\n') {
5191 str[strlen(str) - 1] = 0;
5193 snprintf(p, p_max_size, "%s", str);
5195 } else if (!strcmp(obj->data.rss.action, "item_desc")) {
5196 if (obj->data.rss.act_par < data->item_count) {
5198 data->items[obj->data.rss.act_par].description;
5199 // remove trailing new line if one exists
5200 if (str[strlen(str) - 1] == '\n') {
5201 str[strlen(str) - 1] = 0;
5203 snprintf(p, p_max_size, "%s", str);
5205 } else if (!strcmp(obj->data.rss.action, "item_titles")) {
5206 if (data->item_count > 0) {
5212 if (obj->data.rss.act_par > data->item_count) {
5213 show = data->item_count;
5215 show = obj->data.rss.act_par;
5217 for (itmp = 0; itmp < show; itmp++) {
5218 PRSS_Item *item = &data->items[itmp];
5222 // don't add new line before first item
5224 strncat(p, "\n", p_max_size);
5226 /* remove trailing new line if one exists,
5227 * we have our own */
5228 if (str[strlen(str) - 1] == '\n') {
5229 str[strlen(str) - 1] = 0;
5231 strncat(p, str, p_max_size);
5244 temp = get_hddtemp_info(obj->data.hddtemp.dev,
5245 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
5247 snprintf(p, p_max_size, "N/A");
5248 } else if (unit == '*') {
5249 snprintf(p, p_max_size, "%s", temp);
5251 snprintf(p, p_max_size, "%s°%c", temp, unit);
5256 new_offset(p, obj->data.i);
5259 new_voffset(p, obj->data.i);
5265 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5266 obj->data.sysfs.devtype, obj->data.sysfs.type);
5268 if (r >= 100.0 || r == 0) {
5269 snprintf(p, p_max_size, "%d", (int) r);
5271 snprintf(p, p_max_size, "%.1f", r);
5277 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5278 obj->data.sysfs.devtype, obj->data.sysfs.type);
5280 if (r >= 100.0 || r == 0) {
5281 snprintf(p, p_max_size, "%d", (int) r);
5283 snprintf(p, p_max_size, "%.1f", r);
5289 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5290 obj->data.sysfs.devtype, obj->data.sysfs.type);
5292 if (r >= 100.0 || r == 0) {
5293 snprintf(p, p_max_size, "%d", (int) r);
5295 snprintf(p, p_max_size, "%.1f", r);
5298 #endif /* !__OpenBSD__ */
5300 new_alignr(p, obj->data.i);
5303 new_alignc(p, obj->data.i);
5306 struct text_object_list *text_objects;
5307 struct information *my_info =
5308 malloc(sizeof(struct information));
5309 memcpy(my_info, cur, sizeof(struct information));
5310 text_objects = parse_conky_vars(obj->data.ifblock.s, p, my_info);
5312 if (strlen(p) != 0) {
5313 i = obj->data.ifblock.pos;
5319 free_text_objects(text_objects->text_object_count, text_objects->text_objects);
5326 if ((obj->data.ifblock.s)
5327 && (stat(obj->data.ifblock.s, &tmp) == -1)) {
5328 i = obj->data.ifblock.pos;
5331 if (obj->data.ifblock.str) {
5332 if (!check_contains(obj->data.ifblock.s,
5333 obj->data.ifblock.str)) {
5334 i = obj->data.ifblock.pos;
5345 if ((obj->data.ifblock.s)
5346 && (!check_mount(obj->data.ifblock.s))) {
5347 i = obj->data.ifblock.pos;
5354 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
5355 i = obj->data.ifblock.pos;
5362 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
5365 snprintf(p, p_max_size, "%s", cur->uname_s.release);
5368 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
5373 human_readable(cur->mem * 1024, p, 255, "mem");
5376 human_readable(cur->memmax * 1024, p, 255, "memmax");
5380 spaced_print(p, p_max_size, "%*llu", 4, "memperc",
5381 pad_percents, cur->mem * 100 / cur->memmax);
5385 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5386 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
5389 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5390 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
5396 snprintf(p, p_max_size, "%d", mixer_get_avg(obj->data.l));
5399 snprintf(p, p_max_size, "%d", mixer_get_left(obj->data.l));
5402 snprintf(p, p_max_size, "%d", mixer_get_right(obj->data.l));
5405 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5406 mixer_get_avg(obj->data.mixerbar.l) * 255 / 100);
5409 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5410 mixer_get_left(obj->data.mixerbar.l) * 255 / 100);
5413 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5414 mixer_get_right(obj->data.mixerbar.l) * 255 / 100);
5419 update_mail_count(&obj->data.local_mail);
5420 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
5423 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
5425 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
5428 update_mail_count(&obj->data.local_mail);
5429 snprintf(p, p_max_size, "%d",
5430 obj->data.local_mail.new_mail_count);
5433 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
5436 new_outline(p, obj->data.l);
5439 spaced_print(p, p_max_size, "%hu", 5, "processes", cur->procs);
5441 OBJ(running_processes) {
5442 spaced_print(p, p_max_size, "%hu", 3, "running_processes", cur->run_procs);
5445 snprintf(p, p_max_size, "%s", obj->data.s);
5448 new_bg(p, obj->data.l);
5451 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
5454 human_readable(cur->swap * 1024, p, 255, "swap");
5457 human_readable(cur->swapmax * 1024, p, 255, "swapmax");
5460 if (cur->swapmax == 0) {
5461 strncpy(p, "No swap", p_max_size);
5463 spaced_print(p, p_max_size, "%*llu", 4, "swapperc",
5464 pad_percents, cur->swap * 100 / cur->swapmax);
5468 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5469 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
5472 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
5475 time_t t = time(NULL);
5476 struct tm *tm = localtime(&t);
5478 setlocale(LC_TIME, "");
5479 strftime(p, p_max_size, obj->data.s, tm);
5482 time_t t = time(NULL);
5483 struct tm *tm = gmtime(&t);
5485 strftime(p, p_max_size, obj->data.s, tm);
5492 if (obj->data.tztime.tz) {
5493 oldTZ = getenv("TZ");
5494 setenv("TZ", obj->data.tztime.tz, 1);
5500 setlocale(LC_TIME, "");
5501 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
5503 setenv("TZ", oldTZ, 1);
5508 // Needless to free oldTZ since getenv gives ptr to static data
5511 human_readable(obj->data.net->recv, p, 255, "totaldown");
5514 human_readable(obj->data.net->trans, p, 255, "totalup");
5517 snprintf(p, p_max_size, "%d", total_updates);
5520 spaced_print(p, p_max_size, "%d", 6, "upspeed",
5521 round_to_int(obj->data.net->trans_speed / 1024));
5524 spaced_print(p, p_max_size, "%.1f", 8, "upspeedf",
5525 obj->data.net->trans_speed / 1024.0);
5528 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5529 obj->data.net->trans_speed / 1024.0, obj->e, 1);
5532 format_seconds_short(p, p_max_size, (int) cur->uptime);
5535 format_seconds(p, p_max_size, (int) cur->uptime);
5538 snprintf(p, p_max_size, "%s", cur->users.names);
5541 snprintf(p, p_max_size, "%s", cur->users.terms);
5544 snprintf(p, p_max_size, "%s", cur->users.times);
5547 snprintf(p, p_max_size, "%d", cur->users.number);
5549 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
5550 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5554 msg = get_apm_adapter();
5555 snprintf(p, p_max_size, "%s", msg);
5558 OBJ(apm_battery_life) {
5561 msg = get_apm_battery_life();
5562 snprintf(p, p_max_size, "%s", msg);
5565 OBJ(apm_battery_time) {
5568 msg = get_apm_battery_time();
5569 snprintf(p, p_max_size, "%s", msg);
5572 #endif /* __FreeBSD__ __OpenBSD__ */
5576 snprintf(p, cur->mpd.max_title_len > 0
5577 ? cur->mpd.max_title_len : p_max_size, "%s",
5581 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5584 snprintf(p, p_max_size, "%s", cur->mpd.album);
5587 snprintf(p, p_max_size, "%s", cur->mpd.random);
5590 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
5593 snprintf(p, p_max_size, "%s", cur->mpd.track);
5596 snprintf(p, p_max_size, "%s", cur->mpd.name);
5599 snprintf(p, p_max_size, "%s", cur->mpd.file);
5602 snprintf(p, p_max_size, "%i", cur->mpd.volume);
5605 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
5608 snprintf(p, p_max_size, "%s", cur->mpd.status);
5611 int days = 0, hours = 0, minutes = 0, seconds = 0;
5612 int tmp = cur->mpd.elapsed;
5614 while (tmp >= 86400) {
5618 while (tmp >= 3600) {
5628 snprintf(p, p_max_size, "%i days %i:%02i:%02i", days,
5629 hours, minutes, seconds);
5630 } else if (hours > 0) {
5631 snprintf(p, p_max_size, "%i:%02i:%02i", hours, minutes,
5634 snprintf(p, p_max_size, "%i:%02i", minutes, seconds);
5638 int days = 0, hours = 0, minutes = 0, seconds = 0;
5639 int tmp = cur->mpd.length;
5641 while (tmp >= 86400) {
5645 while (tmp >= 3600) {
5655 snprintf(p, p_max_size, "%i days %i:%02i:%02i", days,
5656 hours, minutes, seconds);
5657 } else if (hours > 0) {
5658 snprintf(p, p_max_size, "%i:%02i:%02i", hours, minutes,
5661 snprintf(p, p_max_size, "%i:%02i", minutes, seconds);
5665 spaced_print(p, p_max_size, "%*d", 4, "mpd_percent",
5666 pad_percents, (int) (cur->mpd.progress * 100));
5669 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5670 (int) (cur->mpd.progress * 255.0f));
5673 memset(p, 0, p_max_size);
5674 if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title
5675 && *cur->mpd.title) {
5676 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist,
5678 } else if (cur->mpd.title && *cur->mpd.title) {
5679 snprintf(p, p_max_size, "%s", cur->mpd.title);
5680 } else if (cur->mpd.artist && *cur->mpd.artist) {
5681 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5682 } else if (cur->mpd.file && *cur->mpd.file) {
5683 snprintf(p, p_max_size, "%s", cur->mpd.file);
5692 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5695 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5698 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5701 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5703 OBJ(xmms2_comment) {
5704 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5707 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5710 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5713 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5715 OBJ(xmms2_tracknr) {
5716 if (cur->xmms2.tracknr != -1) {
5717 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5720 OBJ(xmms2_bitrate) {
5721 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5724 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5727 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5729 OBJ(xmms2_elapsed) {
5730 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5731 (cur->xmms2.elapsed / 1000) % 60);
5733 OBJ(xmms2_duration) {
5734 snprintf(p, p_max_size, "%02d:%02d",
5735 cur->xmms2.duration / 60000,
5736 (cur->xmms2.duration / 1000) % 60);
5738 OBJ(xmms2_percent) {
5739 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5742 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5743 (int) (cur->xmms2.progress * 255.0f));
5745 OBJ(xmms2_playlist) {
5746 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5748 OBJ(xmms2_timesplayed) {
5749 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5752 if (strlen(cur->xmms2.title) < 2
5753 && strlen(cur->xmms2.title) < 2) {
5754 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5756 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5762 OBJ(audacious_status) {
5763 snprintf(p, p_max_size, "%s",
5764 cur->audacious.items[AUDACIOUS_STATUS]);
5766 OBJ(audacious_title) {
5767 snprintf(p, cur->audacious.max_title_len > 0
5768 ? cur->audacious.max_title_len : p_max_size, "%s",
5769 cur->audacious.items[AUDACIOUS_TITLE]);
5771 OBJ(audacious_length) {
5772 snprintf(p, p_max_size, "%s",
5773 cur->audacious.items[AUDACIOUS_LENGTH]);
5775 OBJ(audacious_length_seconds) {
5776 snprintf(p, p_max_size, "%s",
5777 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5779 OBJ(audacious_position) {
5780 snprintf(p, p_max_size, "%s",
5781 cur->audacious.items[AUDACIOUS_POSITION]);
5783 OBJ(audacious_position_seconds) {
5784 snprintf(p, p_max_size, "%s",
5785 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5787 OBJ(audacious_bitrate) {
5788 snprintf(p, p_max_size, "%s",
5789 cur->audacious.items[AUDACIOUS_BITRATE]);
5791 OBJ(audacious_frequency) {
5792 snprintf(p, p_max_size, "%s",
5793 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5795 OBJ(audacious_channels) {
5796 snprintf(p, p_max_size, "%s",
5797 cur->audacious.items[AUDACIOUS_CHANNELS]);
5799 OBJ(audacious_filename) {
5800 snprintf(p, p_max_size, "%s",
5801 cur->audacious.items[AUDACIOUS_FILENAME]);
5803 OBJ(audacious_playlist_length) {
5804 snprintf(p, p_max_size, "%s",
5805 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5807 OBJ(audacious_playlist_position) {
5808 snprintf(p, p_max_size, "%s",
5809 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5811 OBJ(audacious_bar) {
5815 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5816 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5817 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5823 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5826 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5829 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5832 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5835 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5838 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5842 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
5845 switch (obj->data.top.type) {
5847 snprintf(p, 16, "%-15s",
5848 cur->cpu[obj->data.top.num]->name);
5851 snprintf(p, 7, "%6.2f",
5852 cur->cpu[obj->data.top.num]->amount);
5855 snprintf(p, 6, "%5i",
5856 cur->cpu[obj->data.top.num]->pid);
5859 snprintf(p, 7, "%6.2f",
5860 cur->cpu[obj->data.top.num]->totalmem);
5864 cur->cpu[obj->data.top.num]->total_cpu_time, 9);
5865 snprintf(p, 10, "%9s", time);
5869 ERR("Unhandled top data type: %d\n",
5870 obj->data.top.type);
5873 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
5877 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
5880 switch (obj->data.top.type) {
5882 snprintf(p, 16, "%-15s",
5883 cur->memu[obj->data.top.num]->name);
5886 snprintf(p, 7, "%6.2f",
5887 cur->memu[obj->data.top.num]->amount);
5890 snprintf(p, 6, "%5i",
5891 cur->memu[obj->data.top.num]->pid);
5894 snprintf(p, 7, "%6.2f",
5895 cur->memu[obj->data.top.num]->totalmem);
5899 cur->memu[obj->data.top.num]->total_cpu_time,
5901 snprintf(p, 10, "%9s", time);
5905 ERR("Unhandled top data type: %d\n",
5906 obj->data.top.type);
5909 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
5913 if (current_update_time - obj->data.tail.last_update
5914 < obj->data.tail.interval) {
5915 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5921 obj->data.tail.last_update = current_update_time;
5923 if (obj->data.tail.fd != -1) {
5924 tail_pipe(obj, p, p_max_size);
5928 fp = fopen(obj->data.tail.logfile, "rt");
5931 /* Send one message, but do not consistently spam
5932 * on missing logfiles. */
5933 if (obj->data.tail.readlines != 0) {
5934 ERR("tail logfile failed to open");
5935 strcpy(obj->data.tail.buffer, "Logfile Missing");
5937 obj->data.tail.readlines = 0;
5938 snprintf(p, p_max_size, "Logfile Missing");
5940 obj->data.tail.readlines = 0;
5941 /* -1 instead of 0 to avoid counting a trailing
5943 fseek(fp, -1, SEEK_END);
5944 bsize = ftell(fp) + 1;
5945 for (iter = obj->data.tail.wantedlines; iter > 0;
5947 nl = rev_fcharfind(fp, '\n', iter);
5952 obj->data.tail.readlines = iter;
5953 if (obj->data.tail.readlines
5954 < obj->data.tail.wantedlines) {
5955 fseek(fp, 0, SEEK_SET);
5957 fseek(fp, nl + 1, SEEK_SET);
5960 /* Make sure bsize is at least 1 byte smaller than the
5961 * buffer max size. */
5962 if (bsize > (long) ((text_buffer_size * 20) - 1)) {
5963 fseek(fp, bsize - text_buffer_size * 20 - 1,
5965 bsize = text_buffer_size * 20 - 1;
5967 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5970 /* Clean up trailing newline, make sure the
5971 * buffer is null terminated. */
5972 if (obj->data.tail.buffer[bsize - 1] == '\n') {
5973 obj->data.tail.buffer[bsize - 1] = '\0';
5975 obj->data.tail.buffer[bsize] = '\0';
5977 snprintf(p, p_max_size, "%s",
5978 obj->data.tail.buffer);
5980 strcpy(obj->data.tail.buffer, "Logfile Empty");
5981 snprintf(p, p_max_size, "Logfile Empty");
5984 } /* if cur_upd_time >= */
5985 // parse_conky_vars(obj->data.tail.buffer, p, cur);
5990 if (current_update_time - obj->data.tail.last_update
5991 < obj->data.tail.interval) {
5992 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5998 obj->data.tail.last_update = current_update_time;
6000 fp = fopen(obj->data.tail.logfile, "rt");
6002 /* Send one message, but do not consistently spam
6003 * on missing logfiles. */
6004 if (obj->data.tail.readlines != 0) {
6005 ERR("head logfile failed to open");
6006 strcpy(obj->data.tail.buffer, "Logfile Missing");
6008 obj->data.tail.readlines = 0;
6009 snprintf(p, p_max_size, "Logfile Missing");
6011 obj->data.tail.readlines = 0;
6012 for (iter = obj->data.tail.wantedlines; iter > 0;
6014 nl = fwd_fcharfind(fp, '\n', iter);
6019 obj->data.tail.readlines = iter;
6020 /* Make sure nl is at least 1 byte smaller than the
6021 * buffer max size. */
6022 if (nl > (long) ((text_buffer_size * 20) - 1)) {
6023 nl = text_buffer_size * 20 - 1;
6025 nl = fread(obj->data.tail.buffer, 1, nl, fp);
6028 /* Clean up trailing newline, make sure the buffer
6029 * is null terminated. */
6030 if (obj->data.tail.buffer[nl - 1] == '\n') {
6031 obj->data.tail.buffer[nl - 1] = '\0';
6033 obj->data.tail.buffer[nl] = '\0';
6035 snprintf(p, p_max_size, "%s",
6036 obj->data.tail.buffer);
6038 strcpy(obj->data.tail.buffer, "Logfile Empty");
6039 snprintf(p, p_max_size, "Logfile Empty");
6041 } /* if fp == null */
6042 } /* cur_upd_time >= */
6043 // parse_conky_vars(obj->data.tail.buffer, p, cur);
6046 #ifdef TCP_PORT_MONITOR
6048 /* grab a pointer to this port monitor */
6049 tcp_port_monitor_t *p_monitor =
6050 find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
6051 obj->data.tcp_port_monitor.port_range_begin,
6052 obj->data.tcp_port_monitor.port_range_end);
6055 snprintf(p, p_max_size, "monitor not found");
6059 /* now grab the text of interest */
6060 if (peek_tcp_port_monitor(p_monitor,
6061 obj->data.tcp_port_monitor.item,
6062 obj->data.tcp_port_monitor.connection_index, p,
6064 snprintf(p, p_max_size, "monitor peek error");
6072 iconv_converting = 1;
6073 iconv_selected = obj->a;
6076 iconv_converting = 0;
6081 OBJ(entropy_avail) {
6082 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
6084 OBJ(entropy_poolsize) {
6085 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
6088 double entropy_perc;
6090 entropy_perc = (double) cur->entropy.entropy_avail /
6091 (double) cur->entropy.poolsize;
6092 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
6098 s = smapi_get_val(obj->data.s);
6099 snprintf(p, p_max_size, "%s", s);
6103 OBJ(if_smapi_bat_installed) {
6105 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
6106 if(!smapi_bat_installed(idx)) {
6107 i = obj->data.ifblock.pos;
6112 ERR("argument to if_smapi_bat_installed must be an integer");
6114 OBJ(smapi_bat_perc) {
6116 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
6117 val = smapi_bat_installed(idx) ?
6118 smapi_get_bat_int(idx, "remaining_percent") : 0;
6119 spaced_print(p, p_max_size, "%*d", 4, "smapi_bat_perc", pad_percents, val);
6121 ERR("argument to smapi_bat_perc must be an integer");
6123 OBJ(smapi_bat_bar) {
6124 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
6125 new_bar(p, obj->a, obj->b, (int)
6126 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
6128 new_bar(p, obj->a, obj->b, 0);
6136 unsigned int a = strlen(p);
6139 if (a > 0 && iconv_converting && iconv_selected > 0
6140 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
6142 size_t dummy1, dummy2;
6143 char *ptr = buff_in;
6146 dummy1 = dummy2 = a;
6148 strncpy(buff_in, p, p_max_size);
6150 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
6151 while (dummy1 > 0) {
6152 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
6155 ERR("Iconv codeset conversion failed");
6160 /* It is nessecary when we are converting from multibyte to
6161 * singlebyte codepage */
6164 #endif /* HAVE_ICONV */
6171 double current_update_time, last_update_time;
6173 static void generate_text(void)
6175 struct information *cur = &info;
6182 current_update_time = get_time();
6185 /* fix diskio rates to b/s (use update_interval */
6186 diskio_read_value = diskio_read_value / update_interval;
6187 diskio_write_value = diskio_write_value / update_interval;
6188 diskio_value = diskio_value / update_interval;
6190 /* add things to the buffer */
6196 generate_text_internal(p, max_user_text, global_text_objects,
6197 global_text_object_count, cur);
6199 if (stuff_in_upper_case) {
6209 last_update_time = current_update_time;
6215 static void set_font(void)
6219 if (window.xftdraw != NULL) {
6220 XftDrawDestroy(window.xftdraw);
6222 window.xftdraw = XftDrawCreate(display, window.drawable,
6223 DefaultVisual(display, screen), DefaultColormap(display, screen));
6227 XSetFont(display, window.gc, fonts[selected_font].font->fid);
6233 static inline int get_string_width(const char *s)
6236 return *s ? calc_text_width(s, strlen(s)) : 0;
6242 static inline int get_string_width_special(char *s)
6258 if (*p == SPECIAL_CHAR) {
6259 /* shift everything over by 1 so that the special char
6260 * doesn't mess up the size calculation */
6261 for (i = 0; i < strlen(p); i++) {
6262 *(p + i) = *(p + i + 1);
6264 if (specials[special_index + index].type == GRAPH
6265 || specials[special_index + index].type == BAR) {
6266 width += specials[special_index + index].width;
6273 if (strlen(final) > 1) {
6274 width += calc_text_width(final, strlen(final));
6279 return (s) ? strlen(s) : 0;
6284 static void text_size_updater(char *s);
6286 int last_font_height;
6287 static void update_text_area(void)
6291 /* update text size if it isn't fixed */
6296 text_width = minimum_width;
6299 last_font_height = font_height();
6300 for_each_line(text_buffer, text_size_updater);
6302 if (text_height < minimum_height) {
6303 text_height = minimum_height;
6305 if (text_width > maximum_width && maximum_width > 0) {
6306 text_width = maximum_width;
6310 /* get text position on workarea */
6311 switch (text_alignment) {
6318 x = workarea[2] - text_width - gap_x;
6323 x = workarea[2] / 2 - text_width / 2 - gap_x;
6330 y = workarea[3] - text_height - gap_y;
6334 x = workarea[2] - text_width - gap_x;
6335 y = workarea[3] - text_height - gap_y;
6339 x = workarea[2] / 2 - text_width / 2 - gap_x;
6340 y = workarea[3] - text_height - gap_y;
6345 y = workarea[3] / 2 - text_height / 2 - gap_y;
6349 x = workarea[2] - text_width - gap_x;
6350 y = workarea[3] / 2 - text_height / 2 - gap_y;
6354 case NONE: // Let the WM manage the window
6365 if (own_window && !fixed_pos) {
6368 text_start_x = border_margin + 1;
6369 text_start_y = border_margin + 1;
6370 window.x = x - border_margin - 1;
6371 window.y = y - border_margin - 1;
6375 /* If window size doesn't match to workarea's size,
6376 * then window probably includes panels (gnome).
6377 * Blah, doesn't work on KDE. */
6378 if (workarea[2] != window.width || workarea[3] != window.height) {
6390 static int cur_x, cur_y; /* current x and y for drawing */
6391 static int draw_mode; /* FG, BG or OUTLINE */
6392 static long current_color;
6395 static void text_size_updater(char *s)
6400 /* get string widths and skip specials */
6403 if (*p == SPECIAL_CHAR) {
6405 w += get_string_width(s);
6408 if (specials[special_index].type == BAR
6409 || specials[special_index].type == GRAPH) {
6410 w += specials[special_index].width;
6411 if (specials[special_index].height > last_font_height) {
6412 last_font_height = specials[special_index].height;
6413 last_font_height += font_ascent();
6415 } else if (specials[special_index].type == OFFSET) {
6416 if (specials[special_index].arg > 0) {
6417 w += specials[special_index].arg;
6419 } else if (specials[special_index].type == VOFFSET) {
6420 last_font_height += specials[special_index].arg;
6421 } else if (specials[special_index].type == GOTO) {
6422 if (specials[special_index].arg > cur_x) {
6423 w = (int) specials[special_index].arg;
6425 } else if (specials[special_index].type == TAB) {
6426 int start = specials[special_index].arg;
6427 int step = specials[special_index].width;
6429 if (!step || step < 0) {
6432 w += step - (cur_x - text_start_x - start) % step;
6433 } else if (specials[special_index].type == FONT) {
6434 selected_font = specials[special_index].font_added;
6435 if (font_height() > last_font_height) {
6436 last_font_height = font_height();
6445 w += get_string_width(s);
6446 if (w > text_width) {
6449 if (text_width > maximum_width && maximum_width) {
6450 text_width = maximum_width;
6453 text_height += last_font_height;
6454 last_font_height = font_height();
6458 static inline void set_foreground_color(long c)
6461 XSetForeground(display, window.gc, c);
6465 static void draw_string(const char *s)
6467 int i, i2, pos, width_of_s;
6476 width_of_s = get_string_width(s);
6477 if (out_to_console) {
6479 fflush(stdout); /* output immediately, don't buffer */
6481 memset(tmpstring1, 0, text_buffer_size);
6482 memset(tmpstring2, 0, text_buffer_size);
6483 strncpy(tmpstring1, s, text_buffer_size - 1);
6487 snprintf(space, 2, " ");
6489 max = ((text_width - width_of_s) / get_string_width(space));
6491 /* This code looks for tabs in the text and coverts them to spaces.
6492 * The trick is getting the correct number of spaces, and not going
6493 * over the window's size without forcing the window larger. */
6494 for (i = 0; i < (int)text_buffer_size; i++) {
6495 if (tmpstring1[i] == '\t') { // 9 is ascii tab
6497 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
6498 /* guard against overrun */
6499 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
6504 if (tmpstring1[i] != 9) {
6505 /* guard against overrun */
6506 tmpstring2[MIN(pos, (int)text_buffer_size - 1)] = tmpstring1[i];
6512 if (text_width == maximum_width) {
6513 /* this means the text is probably pushing the limit,
6514 * so we'll chop it */
6515 while (cur_x + get_string_width(tmpstring2) - text_start_x
6516 > maximum_width && strlen(tmpstring2) > 0) {
6517 tmpstring2[strlen(tmpstring2) - 1] = '\0';
6528 c.pixel = current_color;
6529 XQueryColor(display, DefaultColormap(display, screen), &c);
6532 c2.color.red = c.red;
6533 c2.color.green = c.green;
6534 c2.color.blue = c.blue;
6535 c2.color.alpha = fonts[selected_font].font_alpha;
6537 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6538 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6540 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6541 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6546 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
6549 cur_x += width_of_s;
6551 memcpy(tmpstring1, s, text_buffer_size);
6554 long redmask, greenmask, bluemask;
6556 void set_up_gradient(void)
6560 colour_depth = DisplayPlanes(display, screen);
6564 if (colour_depth != 24 && colour_depth != 16) {
6565 ERR("using non-standard colour depth, gradients may look like a "
6572 for (i = (colour_depth / 3) - 1; i >= 0; i--) {
6574 greenmask |= 1 << i;
6577 if (colour_depth % 3 == 1) {
6578 greenmask |= 1 << (colour_depth / 3);
6580 redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
6581 greenmask = greenmask << (colour_depth / 3);
6584 /* this function returns the next colour between two colours for a gradient */
6585 inline unsigned long do_gradient(unsigned long first_colour,
6586 unsigned long last_colour)
6589 int red1, green1, blue1; // first colour
6590 int red2, green2, blue2; // second colour
6591 int red3 = 0, green3 = 0, blue3 = 0; // difference
6592 short redshift = (2 * colour_depth / 3 + colour_depth % 3);
6593 short greenshift = (colour_depth / 3);
6595 red1 = (first_colour & redmask) >> redshift;
6596 green1 = (first_colour & greenmask) >> greenshift;
6597 blue1 = first_colour & bluemask;
6598 red2 = (last_colour & redmask) >> redshift;
6599 green2 = (last_colour & greenmask) >> greenshift;
6600 blue2 = last_colour & bluemask;
6607 if (green1 > green2) {
6610 if (green1 < green2) {
6613 if (blue1 > blue2) {
6616 if (blue1 < blue2) {
6631 if (red1 > bluemask) {
6634 if (green1 > bluemask) {
6637 if (blue1 > bluemask) {
6640 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
6644 /* this function returns the max diff for a gradient */
6645 inline unsigned long gradient_max(unsigned long first_colour,
6646 unsigned long last_colour)
6648 int red1, green1, blue1; // first colour
6649 int red2, green2, blue2; // second colour
6650 int red3 = 0, green3 = 0, blue3 = 0; // difference
6651 long redshift, greenshift;
6654 if (colour_depth == 0) {
6657 redshift = (2 * colour_depth / 3 + colour_depth % 3);
6658 greenshift = (colour_depth / 3);
6660 red1 = (first_colour & redmask) >> redshift;
6661 green1 = (first_colour & greenmask) >> greenshift;
6662 blue1 = first_colour & bluemask;
6663 red2 = (last_colour & redmask) >> redshift;
6664 green2 = (last_colour & greenmask) >> greenshift;
6665 blue2 = last_colour & bluemask;
6666 red3 = abs(red1 - red2);
6667 green3 = abs(green1 - green2);
6668 blue3 = abs(blue1 - blue2);
6680 static void draw_line(char *s)
6687 cur_x = text_start_x;
6688 cur_y += font_ascent();
6689 font_h = font_height();
6691 /* find specials and draw stuff */
6694 if (*p == SPECIAL_CHAR) {
6697 /* draw string before special */
6704 switch (specials[special_index].type) {
6705 case HORIZONTAL_LINE:
6707 int h = specials[special_index].height;
6708 int mid = font_ascent() / 2;
6710 w = text_start_x + text_width - cur_x;
6712 XSetLineAttributes(display, window.gc, h, LineSolid,
6713 CapButt, JoinMiter);
6714 XDrawLine(display, window.drawable, window.gc, cur_x,
6715 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6721 int h = specials[special_index].height;
6722 int s = specials[special_index].arg;
6723 int mid = font_ascent() / 2;
6724 char ss[2] = { s, s };
6726 w = text_start_x + text_width - cur_x - 1;
6727 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6728 CapButt, JoinMiter);
6729 XSetDashes(display, window.gc, 0, ss, 2);
6730 XDrawLine(display, window.drawable, window.gc, cur_x,
6731 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6737 int h, bar_usage, by;
6738 if (cur_x - text_start_x > maximum_width
6739 && maximum_width > 0) {
6742 h = specials[special_index].height;
6743 bar_usage = specials[special_index].arg;
6744 by = cur_y - (font_ascent() / 2) - 1;
6746 if (h < font_height()) {
6749 w = specials[special_index].width;
6751 w = text_start_x + text_width - cur_x - 1;
6757 XSetLineAttributes(display, window.gc, 1, LineSolid,
6758 CapButt, JoinMiter);
6760 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6762 XFillRectangle(display, window.drawable, window.gc, cur_x,
6763 by, w * bar_usage / 255, h);
6764 if (specials[special_index].height > cur_y_add
6765 && specials[special_index].height > font_h) {
6766 cur_y_add = specials[special_index].height;
6773 int h, by, i, j = 0;
6774 int gradient_size = 0;
6775 float gradient_factor = 0;
6776 float gradient_update = 0;
6777 unsigned long last_colour = current_color;
6778 unsigned long tmpcolour = current_color;
6779 if (cur_x - text_start_x > maximum_width
6780 && maximum_width > 0) {
6783 h = specials[special_index].height;
6784 by = cur_y - (font_ascent() / 2) - 1;
6786 if (h < font_height()) {
6789 w = specials[special_index].width;
6791 w = text_start_x + text_width - cur_x - 1;
6796 if (draw_graph_borders) {
6797 XSetLineAttributes(display, window.gc, 1, LineSolid,
6798 CapButt, JoinMiter);
6799 XDrawRectangle(display, window.drawable, window.gc,
6802 XSetLineAttributes(display, window.gc, 1, LineSolid,
6803 CapButt, JoinMiter);
6805 if (specials[special_index].last_colour != 0
6806 || specials[special_index].first_colour != 0) {
6807 tmpcolour = specials[special_index].last_colour;
6809 gradient_max(specials[special_index].last_colour,
6810 specials[special_index].first_colour);
6811 gradient_factor = (float) gradient_size / (w - 2);
6813 for (i = w - 2; i > -1; i--) {
6814 if (specials[special_index].last_colour != 0
6815 || specials[special_index].first_colour != 0) {
6816 XSetForeground(display, window.gc, tmpcolour);
6817 gradient_update += gradient_factor;
6818 while (gradient_update > 0) {
6819 tmpcolour = do_gradient(tmpcolour,
6820 specials[special_index].first_colour);
6824 if ((w - i) / ((float) (w - 2) /
6825 (specials[special_index].graph_width)) > j
6826 && j < MAX_GRAPH_DEPTH - 3) {
6829 /* this is mugfugly, but it works */
6830 XDrawLine(display, window.drawable, window.gc,
6831 cur_x + i + 1, by + h, cur_x + i + 1,
6832 by + h - specials[special_index].graph[j] *
6833 (h - 1) / specials[special_index].graph_scale);
6835 if (specials[special_index].height > cur_y_add
6836 && specials[special_index].height > font_h) {
6837 cur_y_add = specials[special_index].height;
6839 /* if (draw_mode == BG) {
6840 set_foreground_color(default_bg_color);
6841 } else if (draw_mode == OUTLINE) {
6842 set_foreground_color(default_out_color);
6844 set_foreground_color(default_fg_color);
6846 set_foreground_color(last_colour);
6852 int old = font_ascent();
6854 cur_y -= font_ascent();
6855 selected_font = specials[special_index].font_added;
6856 if (cur_y + font_ascent() < cur_y + old) {
6859 cur_y += font_ascent();
6865 if (draw_mode == FG) {
6866 set_foreground_color(specials[special_index].arg);
6871 if (draw_mode == BG) {
6872 set_foreground_color(specials[special_index].arg);
6877 if (draw_mode == OUTLINE) {
6878 set_foreground_color(specials[special_index].arg);
6883 w += specials[special_index].arg;
6887 cur_y += specials[special_index].arg;
6891 if (specials[special_index].arg >= 0) {
6892 cur_x = (int) specials[special_index].arg;
6898 int start = specials[special_index].arg;
6899 int step = specials[special_index].width;
6901 if (!step || step < 0) {
6904 w = step - (cur_x - text_start_x - start) % step;
6910 /* TODO: add back in "+ border_margin" to the end of
6912 int pos_x = text_start_x + text_width -
6913 get_string_width_special(s);
6915 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6916 "get_string_width(p) %i gap_x %i "
6917 "specials[special_index].arg %i border_margin %i "
6918 "border_width %i\n", pos_x, text_start_x, text_width,
6919 cur_x, get_string_width_special(s), gap_x,
6920 specials[special_index].arg, border_margin,
6922 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6923 cur_x = pos_x - specials[special_index].arg;
6930 int pos_x = (text_width) / 2 - get_string_width_special(s) /
6931 2 - (cur_x - text_start_x);
6932 /* int pos_x = text_start_x + text_width / 2 -
6933 get_string_width_special(s) / 2; */
6935 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
6936 "get_string_width(p) %i gap_x %i "
6937 "specials[special_index].arg %i\n", pos_x, text_start_x,
6938 text_width, cur_x, get_string_width(s), gap_x,
6939 specials[special_index].arg); */
6940 if (pos_x > specials[special_index].arg) {
6941 w = pos_x - specials[special_index].arg;
6958 if (cur_y_add > 0) {
6960 cur_y -= font_descent();
6965 cur_y += font_descent();
6969 static void draw_text(void)
6972 cur_y = text_start_y;
6975 if (draw_borders && border_width > 0) {
6976 unsigned int b = (border_width + 1) / 2;
6978 if (stippled_borders) {
6979 char ss[2] = { stippled_borders, stippled_borders };
6980 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
6981 CapButt, JoinMiter);
6982 XSetDashes(display, window.gc, 0, ss, 2);
6984 XSetLineAttributes(display, window.gc, border_width, LineSolid,
6985 CapButt, JoinMiter);
6988 XDrawRectangle(display, window.drawable, window.gc,
6989 text_start_x - border_margin + b, text_start_y - border_margin + b,
6990 text_width + border_margin * 2 - 1 - b * 2,
6991 text_height + border_margin * 2 - 1 - b * 2);
6997 for_each_line(text_buffer, draw_line);
7000 static void draw_stuff(void)
7004 if (draw_shades && !draw_outline) {
7007 set_foreground_color(default_bg_color);
7018 for (i = -1; i < 2; i++) {
7019 for (j = -1; j < 2; j++) {
7020 if (i == 0 && j == 0) {
7025 set_foreground_color(default_out_color);
7026 draw_mode = OUTLINE;
7034 set_foreground_color(default_fg_color);
7043 swap.swap_window = window.window;
7044 swap.swap_action = XdbeBackground;
7045 XdbeSwapBuffers(display, &swap, 1);
7052 static void clear_text(int exposures)
7056 /* The swap action is XdbeBackground, which clears */
7061 /* there is some extra space for borders and outlines */
7062 XClearArea(display, window.window, text_start_x - border_margin - 1,
7063 text_start_y - border_margin - 1,
7064 text_width + border_margin * 2 + 2,
7065 text_height + border_margin * 2 + 2, exposures ? True : 0);
7070 static int need_to_update;
7072 /* update_text() generates new text and clears old text area */
7073 static void update_text(void)
7082 static void main_loop(void)
7084 #ifdef SIGNAL_BLOCKING
7085 sigset_t newmask, oldmask;
7088 Region region = XCreateRegion();
7092 XserverRegion region2, part;
7093 int event_base, error_base;
7095 if (!XDamageQueryExtension(display, &event_base, &error_base)) {
7096 ERR("Xdamage extension unavailable");
7098 damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7099 region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7100 part = XFixesCreateRegionFromWindow(display, window.window, 0);
7101 #endif /* HAVE_XDAMAGE */
7104 #ifdef SIGNAL_BLOCKING
7105 sigemptyset(&newmask);
7106 sigaddset(&newmask, SIGINT);
7107 sigaddset(&newmask, SIGTERM);
7108 sigaddset(&newmask, SIGUSR1);
7112 while (total_run_times == 0 || info.looped < total_run_times) {
7115 #ifdef SIGNAL_BLOCKING
7116 /* block signals. we will inspect for pending signals later */
7117 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
7118 CRIT_ERR("unable to sigprocmask()");
7125 /* wait for X event or timeout */
7127 if (!XPending(display)) {
7131 double t = update_interval - (get_time() - last_update_time);
7137 tv.tv_sec = (long) t;
7138 tv.tv_usec = (long) (t * 1000000) % 1000000;
7140 FD_SET(ConnectionNumber(display), &fdsr);
7142 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
7144 if (errno != EINTR) {
7145 ERR("can't select(): %s", strerror(errno));
7151 /* FIXME just sleep for the interval time if no X11 */
7152 usleep(update_interval * 1000000);
7160 if (need_to_update) {
7162 int wx = window.x, wy = window.y;
7170 /* resize window if it isn't right size */
7172 && (text_width + border_margin * 2 + 1 != window.width
7173 || text_height + border_margin * 2 + 1 != window.height)) {
7174 window.width = text_width + border_margin * 2 + 1;
7175 window.height = text_height + border_margin * 2 + 1;
7176 XResizeWindow(display, window.window, window.width,
7179 set_transparent_background(window.window);
7183 /* move window if it isn't in right position */
7184 if (!fixed_pos && (window.x != wx || window.y != wy)) {
7185 XMoveWindow(display, window.window, window.x, window.y);
7196 r.x = text_start_x - border_margin;
7197 r.y = text_start_y - border_margin;
7198 r.width = text_width + border_margin * 2;
7199 r.height = text_height + border_margin * 2;
7200 XUnionRectWithRegion(&r, region, region);
7205 /* handle X events */
7206 while (XPending(display)) {
7209 XNextEvent(display, &ev);
7217 r.width = ev.xexpose.width;
7218 r.height = ev.xexpose.height;
7219 XUnionRectWithRegion(&r, region, region);
7224 case ReparentNotify:
7225 /* set background to ParentRelative for all parents */
7227 set_transparent_background(window.window);
7231 case ConfigureNotify:
7233 /* if window size isn't what expected, set fixed size */
7234 if (ev.xconfigure.width != window.width
7235 || ev.xconfigure.height != window.height) {
7236 if (window.width != 0 && window.height != 0) {
7240 /* clear old stuff before screwing up
7245 XWindowAttributes attrs;
7247 if (XGetWindowAttributes(display,
7248 window.window, &attrs)) {
7249 window.width = attrs.width;
7250 window.height = attrs.height;
7254 text_width = window.width - border_margin * 2 - 1;
7255 text_height = window.height - border_margin * 2 - 1;
7256 if (text_width > maximum_width
7257 && maximum_width > 0) {
7258 text_width = maximum_width;
7262 /* if position isn't what expected, set fixed pos
7263 * total_updates avoids setting fixed_pos when window
7264 * is set to weird locations when started */
7265 /* // this is broken
7266 if (total_updates >= 2 && !fixed_pos
7267 && (window.x != ev.xconfigure.x
7268 || window.y != ev.xconfigure.y)
7269 && (ev.xconfigure.x != 0
7270 || ev.xconfigure.y != 0)) {
7279 /* if an ordinary window with decorations */
7280 if ((window.type == TYPE_NORMAL)
7281 && (!TEST_HINT(window.hints,
7282 HINT_UNDECORATED))) {
7283 /* allow conky to hold input focus. */
7286 /* forward the click to the desktop window */
7287 XUngrabPointer(display, ev.xbutton.time);
7288 ev.xbutton.window = window.desktop;
7289 XSendEvent(display, ev.xbutton.window, False,
7290 ButtonPressMask, &ev);
7291 XSetInputFocus(display, ev.xbutton.window,
7292 RevertToParent, ev.xbutton.time);
7299 /* if an ordinary window with decorations */
7300 if ((window.type == TYPE_NORMAL)
7301 && (!TEST_HINT(window.hints,
7302 HINT_UNDECORATED))) {
7303 /* allow conky to hold input focus. */
7306 /* forward the release to the desktop window */
7307 ev.xbutton.window = window.desktop;
7308 XSendEvent(display, ev.xbutton.window, False,
7309 ButtonReleaseMask, &ev);
7318 if (ev.type == event_base + XDamageNotify) {
7319 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
7321 XFixesSetRegion(display, part, &dev->area, 1);
7322 XFixesUnionRegion(display, region2, region2, part);
7324 #endif /* HAVE_XDAMAGE */
7330 XDamageSubtract(display, damage, region2, None);
7331 XFixesSetRegion(display, region2, 0, 0);
7332 #endif /* HAVE_XDAMAGE */
7334 /* XDBE doesn't seem to provide a way to clear the back buffer without
7335 * interfering with the front buffer, other than passing XdbeBackground
7336 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
7337 * redraw the text even if it wasn't part of the exposed area. OTOH,
7338 * if we're not going to call draw_stuff at all, then no swap happens
7339 * and we can safely do nothing. */
7341 if (!XEmptyRegion(region)) {
7346 r.x = text_start_x - border_margin;
7347 r.y = text_start_y - border_margin;
7348 r.width = text_width + border_margin * 2;
7349 r.height = text_height + border_margin * 2;
7350 XUnionRectWithRegion(&r, region, region);
7353 XSetRegion(display, window.gc, region);
7356 XftDrawSetClip(window.xftdraw, region);
7362 XDestroyRegion(region);
7363 region = XCreateRegion();
7367 #ifdef SIGNAL_BLOCKING
7368 /* unblock signals of interest and let handler fly */
7369 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
7370 CRIT_ERR("unable to sigprocmask()");
7374 switch (g_signal_pending) {
7377 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
7382 ERR("received SIGINT or SIGTERM to terminate. bye!");
7385 XDestroyRegion(region);
7388 XDamageDestroy(display, damage);
7389 XFixesDestroyRegion(display, region2);
7390 XFixesDestroyRegion(display, part);
7391 #endif /* HAVE_XDAMAGE */
7393 return; /* return from main_loop */
7396 /* Reaching here means someone set a signal
7397 * (SIGXXXX, signal_handler), but didn't write any code
7399 * If you don't want to handle a signal, don't set a handler on
7400 * it in the first place. */
7401 if (g_signal_pending) {
7402 ERR("ignoring signal (%d)", g_signal_pending);
7406 g_signal_pending = 0;
7409 #if defined(X11) && defined(HAVE_XDAMAGE)
7410 XDamageDestroy(display, damage);
7411 XFixesDestroyRegion(display, region2);
7412 XFixesDestroyRegion(display, part);
7413 XDestroyRegion(region);
7415 #endif /* X11 && HAVE_XDAMAGE */
7418 static void load_config_file(const char *);
7420 /* reload the config file */
7421 void reload_config(void)
7423 timed_thread_destroy_registered_threads();
7425 if (info.cpu_usage) {
7426 free(info.cpu_usage);
7427 info.cpu_usage = NULL;
7435 if (info.mpd.title) {
7436 free(info.mpd.title);
7437 info.mpd.title = NULL;
7439 if (info.mpd.artist) {
7440 free(info.mpd.artist);
7441 info.mpd.artist = NULL;
7443 if (info.mpd.album) {
7444 free(info.mpd.album);
7445 info.mpd.album = NULL;
7447 if (info.mpd.random) {
7448 free(info.mpd.random);
7449 info.mpd.random = NULL;
7451 if (info.mpd.repeat) {
7452 free(info.mpd.repeat);
7453 info.mpd.repeat = NULL;
7455 if (info.mpd.track) {
7456 free(info.mpd.track);
7457 info.mpd.track = NULL;
7459 if (info.mpd.name) {
7460 free(info.mpd.name);
7461 info.mpd.name = NULL;
7463 if (info.mpd.file) {
7464 free(info.mpd.file);
7465 info.mpd.file = NULL;
7467 if (info.mpd.status) {
7468 free(info.mpd.status);
7469 info.mpd.status = NULL;
7479 #ifdef TCP_PORT_MONITOR
7480 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7483 if (current_config) {
7485 load_config_file(current_config);
7487 /* re-init specials array */
7488 if ((specials = realloc((void *) specials,
7489 sizeof(struct special_t) * max_specials)) == 0) {
7490 ERR("failed to realloc specials array");
7494 // clear the window first
7495 XClearWindow(display, RootWindow(display, screen));
7498 #ifdef TCP_PORT_MONITOR
7499 info.p_tcp_port_monitor_collection = NULL;
7501 extract_variable_text(text);
7507 tmpstring1 = malloc(text_buffer_size);
7508 memset(tmpstring1, 0, text_buffer_size);
7512 tmpstring2 = malloc(text_buffer_size);
7513 memset(tmpstring2, 0, text_buffer_size);
7517 text_buffer = malloc(max_user_text);
7518 memset(text_buffer, 0, max_user_text);
7525 timed_thread_destroy_registered_threads();
7527 if (info.cpu_usage) {
7528 free(info.cpu_usage);
7529 info.cpu_usage = NULL;
7534 XdbeDeallocateBackBufferName(display, window.back_buffer);
7539 XDestroyWindow(display, window.window);
7540 XClearWindow(display, RootWindow(display, screen));
7545 XClearWindow(display, RootWindow(display, screen));
7550 XFreeGC(display, window.gc);
7554 free_text_objects(global_text_object_count, global_text_objects);
7567 global_text_object_count = 0;
7568 global_text_objects = NULL;
7575 free(current_config);
7577 #ifdef TCP_PORT_MONITOR
7578 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7579 info.p_tcp_port_monitor_collection = NULL;
7588 for (i = 0; i < special_count; i++) {
7589 if (specials[i].type == GRAPH) {
7590 free(specials[i].graph);
7597 clear_diskio_stats();
7600 static int string_to_bool(const char *s)
7604 } else if (strcasecmp(s, "yes") == 0) {
7606 } else if (strcasecmp(s, "true") == 0) {
7608 } else if (strcasecmp(s, "1") == 0) {
7615 static enum alignment string_to_alignment(const char *s)
7617 if (strcasecmp(s, "top_left") == 0) {
7619 } else if (strcasecmp(s, "top_right") == 0) {
7621 } else if (strcasecmp(s, "top_middle") == 0) {
7623 } else if (strcasecmp(s, "bottom_left") == 0) {
7625 } else if (strcasecmp(s, "bottom_right") == 0) {
7626 return BOTTOM_RIGHT;
7627 } else if (strcasecmp(s, "bottom_middle") == 0) {
7628 return BOTTOM_MIDDLE;
7629 } else if (strcasecmp(s, "middle_left") == 0) {
7631 } else if (strcasecmp(s, "middle_right") == 0) {
7632 return MIDDLE_RIGHT;
7633 } else if (strcasecmp(s, "tl") == 0) {
7635 } else if (strcasecmp(s, "tr") == 0) {
7637 } else if (strcasecmp(s, "tm") == 0) {
7639 } else if (strcasecmp(s, "bl") == 0) {
7641 } else if (strcasecmp(s, "br") == 0) {
7642 return BOTTOM_RIGHT;
7643 } else if (strcasecmp(s, "bm") == 0) {
7644 return BOTTOM_MIDDLE;
7645 } else if (strcasecmp(s, "ml") == 0) {
7647 } else if (strcasecmp(s, "mr") == 0) {
7648 return MIDDLE_RIGHT;
7649 } else if (strcasecmp(s, "none") == 0) {
7656 static void set_default_configurations(void)
7658 fork_to_background = 0;
7659 total_run_times = 0;
7660 info.cpu_avg_samples = 2;
7661 info.net_avg_samples = 2;
7668 strcpy(info.mpd.host, "localhost");
7669 info.mpd.port = 6600;
7670 info.mpd.status = NULL;
7671 info.mpd.artist = NULL;
7672 info.mpd.album = NULL;
7673 info.mpd.title = NULL;
7674 info.mpd.random = NULL;
7675 info.mpd.track = NULL;
7676 info.mpd.name = NULL;
7677 info.mpd.file = NULL;
7680 info.xmms2.artist = NULL;
7681 info.xmms2.album = NULL;
7682 info.xmms2.title = NULL;
7683 info.xmms2.genre = NULL;
7684 info.xmms2.comment = NULL;
7685 info.xmms2.url = NULL;
7686 info.xmms2.status = NULL;
7687 info.xmms2.playlist = NULL;
7689 use_spacer = NO_SPACER;
7696 default_fg_color = WhitePixel(display, screen);
7697 default_bg_color = BlackPixel(display, screen);
7698 default_out_color = BlackPixel(display, screen);
7699 color0 = default_fg_color;
7700 color1 = default_fg_color;
7701 color2 = default_fg_color;
7702 color3 = default_fg_color;
7703 color4 = default_fg_color;
7704 color5 = default_fg_color;
7705 color6 = default_fg_color;
7706 color7 = default_fg_color;
7707 color8 = default_fg_color;
7708 color9 = default_fg_color;
7711 draw_graph_borders = 1;
7713 set_first_font("6x10");
7721 window.type = TYPE_NORMAL;
7723 strcpy(window.class_name, "Conky");
7725 sprintf(window.title, "Conky (%s)", info.uname_s.nodename);
7727 stippled_borders = 0;
7730 text_alignment = BOTTOM_LEFT;
7733 free(current_mail_spool);
7737 variable_substitute(MAIL_FILE, buf, 256);
7738 if (buf[0] != '\0') {
7739 current_mail_spool = strdup(buf);
7744 update_interval = 3.0;
7745 info.music_player_interval = 1.0;
7746 stuff_in_upper_case = 0;
7747 info.users.number = 1;
7749 #ifdef TCP_PORT_MONITOR
7750 tcp_port_monitor_args.max_port_monitor_connections =
7751 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7755 static void load_config_file(const char *f)
7757 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7761 set_default_configurations();
7768 char buf[256], *p, *p2, *name, *value;
7771 if (fgets(buf, 256, fp) == NULL) {
7777 /* break at comment */
7778 p2 = strchr(p, '#');
7784 while (*p && isspace((int) *p)) {
7788 continue; /* empty line */
7795 while (*p2 && !isspace((int) *p2)) {
7799 *p2 = '\0'; /* break at name's end */
7806 while (*p && isspace((int) *p)) {
7812 p2 = value + strlen(value);
7813 while (isspace((int) *(p2 - 1))) {
7820 #define CONF2(a) if (strcasecmp(name, a) == 0)
7821 #define CONF(a) else CONF2(a)
7822 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
7823 || strcasecmp(name, b) == 0)
7826 CONF2("alignment") {
7828 int a = string_to_alignment(value);
7839 CONF("background") {
7840 fork_to_background = string_to_bool(value);
7843 CONF2("background") {
7844 fork_to_background = string_to_bool(value);
7848 CONF("border_margin") {
7850 border_margin = strtol(value, 0, 0);
7855 CONF("border_width") {
7857 border_width = strtol(value, 0, 0);
7864 color0 = get_x11_color(value);
7871 color1 = get_x11_color(value);
7878 color2 = get_x11_color(value);
7885 color3 = get_x11_color(value);
7892 color4 = get_x11_color(value);
7899 color5 = get_x11_color(value);
7906 color6 = get_x11_color(value);
7913 color7 = get_x11_color(value);
7920 color8 = get_x11_color(value);
7927 color9 = get_x11_color(value);
7932 CONF("default_color") {
7934 default_fg_color = get_x11_color(value);
7939 CONF3("default_shade_color", "default_shadecolor") {
7941 default_bg_color = get_x11_color(value);
7946 CONF3("default_outline_color", "default_outlinecolor") {
7948 default_out_color = get_x11_color(value);
7956 info.mail = parse_mail_args(IMAP, value);
7963 info.mail = parse_mail_args(POP3, value);
7971 strncpy(info.mpd.host, value, 127);
7978 info.mpd.port = strtol(value, 0, 0);
7979 if (info.mpd.port < 1 || info.mpd.port > 0xffff) {
7984 CONF("mpd_password") {
7986 strncpy(info.mpd.password, value, 127);
7992 CONF("music_player_interval") {
7994 info.music_player_interval = strtod(value, 0);
8000 CONF("sensor_device") {
8002 sensor_device = strtol(value, 0, 0);
8008 CONF("cpu_avg_samples") {
8010 cpu_avg_samples = strtol(value, 0, 0);
8011 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
8014 info.cpu_avg_samples = cpu_avg_samples;
8020 CONF("net_avg_samples") {
8022 net_avg_samples = strtol(value, 0, 0);
8023 if (net_avg_samples < 1 || net_avg_samples > 14) {
8026 info.net_avg_samples = net_avg_samples;
8034 CONF("double_buffer") {
8035 use_xdbe = string_to_bool(value);
8039 CONF("override_utf8_locale") {
8040 utf8_mode = string_to_bool(value);
8042 CONF("draw_borders") {
8043 draw_borders = string_to_bool(value);
8045 CONF("draw_graph_borders") {
8046 draw_graph_borders = string_to_bool(value);
8048 CONF("draw_shades") {
8049 draw_shades = string_to_bool(value);
8051 CONF("draw_outline") {
8052 draw_outline = string_to_bool(value);
8055 CONF("out_to_console") {
8056 out_to_console = string_to_bool(value);
8058 CONF("use_spacer") {
8060 if (strcasecmp(value, "left") == 0) {
8061 use_spacer = LEFT_SPACER;
8062 } else if (strcasecmp(value, "right") == 0) {
8063 use_spacer = RIGHT_SPACER;
8064 } else if (strcasecmp(value, "none") == 0) {
8065 use_spacer = NO_SPACER;
8067 use_spacer = string_to_bool(value);
8068 ERR("use_spacer should have an argument of left, right, or"
8069 " none. '%s' seems to be some form of '%s', so"
8070 " defaulting to %s.", value,
8071 use_spacer ? "true" : "false",
8072 use_spacer ? "right" : "none");
8074 use_spacer = RIGHT_SPACER;
8076 use_spacer = NO_SPACER;
8080 ERR("use_spacer should have an argument. Defaulting to right.");
8081 use_spacer = RIGHT_SPACER;
8087 use_xft = string_to_bool(value);
8091 set_first_font(value);
8097 if (value && font_count >= 0) {
8098 fonts[0].font_alpha = atof(value) * 65535.0;
8107 if (string_to_bool(value)) {
8108 ERR("Xft not enabled");
8112 /* xftfont silently ignored when no Xft */
8115 /* xftalpha is silently ignored when no Xft */
8120 set_first_font(value);
8130 gap_x = atoi(value);
8137 gap_y = atoi(value);
8143 CONF("mail_spool") {
8147 variable_substitute(value, buf, 256);
8149 if (buf[0] != '\0') {
8150 if (current_mail_spool) {
8151 free(current_mail_spool);
8153 current_mail_spool = strdup(buf);
8160 CONF("minimum_size") {
8162 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
8164 if (sscanf(value, "%d", &minimum_width) != 1) {
8172 CONF("maximum_width") {
8174 if (sscanf(value, "%d", &maximum_width) != 1) {
8182 CONF("no_buffers") {
8183 no_buffers = string_to_bool(value);
8185 CONF("top_cpu_separate") {
8186 cpu_separate = string_to_bool(value);
8188 CONF("short_units") {
8189 short_units = string_to_bool(value);
8191 CONF("pad_percents") {
8192 pad_percents = atoi(value);
8196 CONF("own_window") {
8198 own_window = string_to_bool(value);
8203 CONF("own_window_class") {
8205 memset(window.class_name, 0, sizeof(window.class_name));
8206 strncpy(window.class_name, value,
8207 sizeof(window.class_name) - 1);
8212 CONF("own_window_title") {
8214 memset(window.title, 0, sizeof(window.title));
8215 strncpy(window.title, value, sizeof(window.title) - 1);
8220 CONF("own_window_transparent") {
8222 set_transparent = string_to_bool(value);
8227 CONF("own_window_colour") {
8229 background_colour = get_x11_color(value);
8231 ERR("Invalid colour for own_window_colour (try omitting the "
8232 "'#' for hex colours");
8235 CONF("own_window_hints") {
8237 char *p_hint, *p_save;
8238 char delim[] = ", ";
8240 /* tokenize the value into individual hints */
8241 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
8243 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
8244 if (strncmp(p_hint, "undecorate", 10) == 0) {
8245 SET_HINT(window.hints, HINT_UNDECORATED);
8246 } else if (strncmp(p_hint, "below", 5) == 0) {
8247 SET_HINT(window.hints, HINT_BELOW);
8248 } else if (strncmp(p_hint, "above", 5) == 0) {
8249 SET_HINT(window.hints, HINT_ABOVE);
8250 } else if (strncmp(p_hint, "sticky", 6) == 0) {
8251 SET_HINT(window.hints, HINT_STICKY);
8252 } else if (strncmp(p_hint, "skip_taskbar", 12) == 0) {
8253 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
8254 } else if (strncmp(p_hint, "skip_pager", 10) == 0) {
8255 SET_HINT(window.hints, HINT_SKIP_PAGER);
8260 p_hint = strtok_r(NULL, delim, &p_save);
8261 } while (p_hint != NULL);
8267 CONF("own_window_type") {
8269 if (strncmp(value, "normal", 6) == 0) {
8270 window.type = TYPE_NORMAL;
8271 } else if (strncmp(value, "desktop", 7) == 0) {
8272 window.type = TYPE_DESKTOP;
8273 } else if (strncmp(value, "override", 8) == 0) {
8274 window.type = TYPE_OVERRIDE;
8283 CONF("stippled_borders") {
8285 stippled_borders = strtol(value, 0, 0);
8287 stippled_borders = 4;
8292 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> "
8296 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> "
8299 CONF("update_interval") {
8301 update_interval = strtod(value, 0);
8305 if (info.music_player_interval == 0) {
8306 // default to update_interval
8307 info.music_player_interval = update_interval;
8310 CONF("total_run_times") {
8312 total_run_times = strtod(value, 0);
8318 stuff_in_upper_case = string_to_bool(value);
8320 CONF("max_specials") {
8322 max_specials = atoi(value);
8327 CONF("max_user_text") {
8329 max_user_text = atoi(value);
8334 CONF("text_buffer_size") {
8336 text_buffer_size = atoi(value);
8337 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
8338 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
8339 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
8351 text = (char *) malloc(1);
8355 unsigned int l = strlen(text);
8357 if (fgets(buf, 256, fp) == NULL) {
8360 text = (char *) realloc(text, l + strlen(buf) + 1);
8363 if (strlen(text) > max_user_text) {
8368 text_lines = line + 1;
8371 #ifdef TCP_PORT_MONITOR
8372 CONF("max_port_monitor_connections") {
8373 if (!value || (sscanf(value, "%d",
8374 &tcp_port_monitor_args.max_port_monitor_connections) != 1)
8375 || tcp_port_monitor_args.max_port_monitor_connections < 0) {
8376 /* an error. use default, warn and continue. */
8377 tcp_port_monitor_args.max_port_monitor_connections =
8378 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8380 } else if (tcp_port_monitor_args.max_port_monitor_connections
8382 /* no error, just use default */
8383 tcp_port_monitor_args.max_port_monitor_connections =
8384 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8386 /* else tcp_port_monitor_args.max_port_monitor_connections > 0
8391 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8402 if (info.music_player_interval == 0) {
8403 // default to update_interval
8404 info.music_player_interval = update_interval;
8408 /* : means that character before that takes an argument */
8409 static const char *getopt_string = "vVdt:u:i:hc:"
8421 static const struct option longopts[] = {
8422 { "help", 0, NULL, 'h' },
8423 { "version", 0, NULL, 'V' },
8424 { "config", 1, NULL, 'c' },
8425 { "daemonize", 0, NULL, 'd' },
8427 { "alignment", 1, NULL, 'a' },
8428 { "font", 1, NULL, 'f' },
8430 { "own-window", 0, NULL, 'o' },
8433 { "double-buffer", 0, NULL, 'b' },
8435 { "window-id", 1, NULL, 'w' },
8437 { "text", 1, NULL, 't' },
8438 { "interval", 0, NULL, 'u' },
8442 int main(int argc, char **argv)
8448 struct sigaction act, oact;
8450 g_signal_pending = 0;
8451 memset(&info, 0, sizeof(info));
8453 #ifdef TCP_PORT_MONITOR
8454 tcp_port_monitor_args.max_port_monitor_connections =
8455 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8458 /* handle command line parameters that don't change configs */
8460 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8461 || ((s = getenv("LANG")) && *s)) {
8462 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8464 ERR("malloc failed");
8466 for (x = 0; x < strlen(s); x++) {
8467 temp[x] = tolower(s[x]);
8470 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8476 if (!setlocale(LC_CTYPE, "")) {
8477 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8481 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8492 if (current_config) {
8493 free(current_config);
8495 current_config = strdup(optarg);
8499 printf("Usage: %s [OPTION]...\n"
8500 "Conky is a system monitor that renders text on desktop or to own transparent\n"
8501 "window. Command line options will override configurations defined in config\n"
8503 " -V, --version version\n"
8504 " -c, --config=FILE config file to load\n"
8505 " -d, --daemonize daemonize, fork to background\n"
8506 " -h, --help help\n"
8508 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
8509 " -f, --font=FONT font to use\n"
8511 " -o, --own-window create own window to draw\n"
8514 " -b, --double-buffer double buffer (prevents flickering)\n"
8516 " -w, --window-id=WIN_ID window id to draw\n"
8517 " -x X x position\n"
8518 " -y Y y position\n"
8520 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8521 " -u, --interval=SECS update interval\n"
8522 " -i NUM number of times to update Conky\n",
8528 window.window = strtol(optarg, 0, 0);
8537 /* initalize X BEFORE we load config.
8538 * (we need to so that 'screen' is set) */
8542 /* check if specified config file is valid */
8543 if (current_config) {
8545 if (stat(current_config, &sb) ||
8546 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8547 ERR("invalid configuration file '%s'\n", current_config);
8548 free(current_config);
8553 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8555 if (!current_config) {
8556 /* load default config file */
8560 /* Try to use personal config file first */
8561 variable_substitute(CONFIG_FILE, buf, sizeof(buf));
8562 if (buf[0] && (fp = fopen(buf, "r"))) {
8563 current_config = strdup(buf);
8567 /* Try to use system config file if personal config not readable */
8568 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8569 current_config = strdup(SYSTEM_CONFIG_FILE);
8573 /* No readable config found */
8574 if (!current_config) {
8575 CRIT_ERR("no readable personal or system-wide config file found");
8579 load_config_file(current_config);
8581 /* init specials array */
8582 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8583 ERR("failed to create specials array");
8587 if (current_mail_spool == NULL) {
8590 variable_substitute(MAIL_FILE, buf, 256);
8592 if (buf[0] != '\0') {
8593 current_mail_spool = strdup(buf);
8598 /* handle other command line arguments */
8600 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8601 || defined(__NetBSD__)
8602 optind = optreset = 1;
8607 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8608 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8609 "kvm_open")) == NULL) {
8610 CRIT_ERR("cannot read kvm");
8615 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8623 fork_to_background = 1;
8628 set_first_font(optarg);
8631 text_alignment = string_to_alignment(optarg);
8650 text = strdup(optarg);
8651 convert_escapes(text);
8655 update_interval = strtod(optarg, 0);
8656 if (info.music_player_interval == 0) {
8657 // default to update_interval
8658 info.music_player_interval = update_interval;
8663 total_run_times = strtod(optarg, 0);
8667 gap_x = atoi(optarg);
8671 gap_y = atoi(optarg);
8685 /* generate text and get initial size */
8686 extract_variable_text(text);
8693 if (fork_to_background) {
8698 ERR("Conky: couldn't fork() to background: %s",
8705 fprintf(stderr, "\n");
8710 /* parent process */
8711 fprintf(stderr, "Conky: forked to background, pid is %d\n",
8718 text_buffer = malloc(max_user_text);
8719 memset(text_buffer, 0, max_user_text);
8720 tmpstring1 = malloc(text_buffer_size);
8721 memset(tmpstring1, 0, text_buffer_size);
8722 tmpstring2 = malloc(text_buffer_size);
8723 memset(tmpstring2, 0, text_buffer_size);
8727 update_text_area(); /* to get initial size of the window */
8730 init_window(own_window, text_width + border_margin * 2 + 1,
8731 text_height + border_margin * 2 + 1, set_transparent, background_colour,
8733 #else /* OWN_WINDOW */
8734 init_window(0, text_width + border_margin * 2 + 1,
8735 text_height + border_margin * 2 + 1, set_transparent, 0,
8737 #endif /* OWN_WINDOW */
8740 update_text_area(); /* to position text/window on screen */
8745 if (own_window && !fixed_pos) {
8746 XMoveWindow(display, window.window, window.x, window.y);
8749 set_transparent_background(window.window);
8759 /* Set signal handlers */
8760 act.sa_handler = signal_handler;
8761 sigemptyset(&act.sa_mask);
8764 act.sa_flags |= SA_RESTART;
8767 if (sigaction(SIGINT, &act, &oact) < 0
8768 || sigaction(SIGUSR1, &act, &oact) < 0
8769 || sigaction(SIGHUP,&act,&oact) < 0
8770 || sigaction(SIGTERM, &act, &oact) < 0) {
8771 ERR("error setting signal handler: %s", strerror(errno));
8774 /* *************** *
8776 * *************** */
8779 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8786 void signal_handler(int sig)
8788 /* signal handler is light as a feather, as it should be.
8789 * we will poll g_signal_pending with each loop of conky
8790 * and do any signal processing there, NOT here. */
8791 g_signal_pending = sig;