2 * Conky, a system monitor, based on torsmo
4 * Any original torsmo code is licensed under the BSD license
6 * All code written since the fork of torsmo is licensed under the GPL
8 * Please see COPYING for details
10 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
11 * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
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/>.
46 #include <X11/Xutil.h>
48 #include <X11/extensions/Xdamage.h>
54 #include <sys/types.h>
56 #include <netinet/in.h>
68 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
71 #define CONFIG_FILE "$HOME/.conkyrc"
72 #define MAIL_FILE "$MAIL"
73 #define MAX_IF_BLOCK_DEPTH 5
75 /* #define SIGNAL_BLOCKING */
76 #undef SIGNAL_BLOCKING
78 static void print_version()
80 printf("Conky %s compiled %s for %s\n",
81 VERSION, BUILD_DATE, BUILD_ARCH);
84 "\nCompiled in features:\n\n"
85 "system config file: %s\n\n"
89 " * Xdamage extension\n"
90 # endif /* HAVE_XDAMAGE */
92 " * Xdbe extension (double buffer)\n"
93 # endif /* HAVE_XDBE */
99 "\n Music detection:\n"
102 #endif /* AUDACIOUS */
112 "\n General features:\n"
116 #ifdef TCP_PORT_MONITOR
118 #endif /* TCP_PORT_MONITOR */
125 "",SYSTEM_CONFIG_FILE
137 static int text_start_x, text_start_y; /* text start position in window */
138 static int text_width, text_height;
153 char name[TEXT_BUFFER_SIZE];
163 static int selected_font = 0;
164 static int font_count = -1;
165 struct font_list *fonts = NULL;
167 static char *suffixes[] = { "B", "kiB", "MiB", "GiB", "TiB", "PiB", "" };
171 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
172 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent))
173 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent)
174 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent)
178 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
179 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
180 #define font_descent() fonts[selected_font].font->max_bounds.descent
184 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
187 static void set_font();
189 int addfont(const char *data_in)
191 if (font_count > MAX_FONTS) {
192 CRIT_ERR("you don't need that many fonts, sorry.");
195 if (font_count == 0) {
199 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
203 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
205 CRIT_ERR("realloc in addfont");
207 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
208 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
210 fonts[font_count].font_alpha = 0xffff;
213 CRIT_ERR("Oops...looks like something overflowed in addfont().");
218 void set_first_font(const char *data_in)
220 if (font_count < 0) {
221 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
226 if (strlen(data_in) > 1) {
227 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
229 fonts[0].font_alpha = 0xffff;
237 for (i = 0; i <= font_count; i++) {
240 XftFontClose(display, fonts[i].xftfont);
244 XFreeFont(display, fonts[i].font);
254 static void load_fonts()
257 for (i=0; i <= font_count; i++) {
261 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
262 XftFontClose(display, fonts[i].xftfont);
264 if ((fonts[i].xftfont =
265 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
268 ERR("can't load Xft font '%s'", fonts[i].name);
269 if ((fonts[i].xftfont =
270 XftFontOpenName(display, screen,
271 "courier-12")) != NULL)
274 ERR("can't load Xft font '%s'", "courier-12");
276 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
277 CRIT_ERR("can't load font '%s'", "fixed");
284 /* load normal font */
285 /* if (fonts[i].font != NULL)
286 XFreeFont(display, fonts[i].font);*/
288 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
289 ERR("can't load font '%s'", fonts[i].name);
290 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
291 CRIT_ERR("can't load font '%s'", "fixed");
292 printf("loaded fixed?\n");
300 /* default config file */
301 static char *current_config;
303 /* set to 1 if you want all text to be in uppercase */
304 static unsigned int stuff_in_upper_case;
306 /* Run how many times? */
307 static unsigned long total_run_times;
310 static int fork_to_background;
312 static int cpu_avg_samples, net_avg_samples;
316 /* Position on the screen */
317 static int text_alignment;
318 static int gap_x, gap_y;
321 static int draw_borders;
322 static int draw_graph_borders;
323 static int stippled_borders;
325 static int draw_shades, draw_outline;
327 static int border_margin, border_width;
329 static long default_fg_color, default_bg_color, default_out_color;
331 /* create own window or draw stuff to root? */
332 static int set_transparent = 0;
336 static int own_window = 0;
337 static int background_colour = 0;
338 /* fixed size/pos is set if wm/user changes them */
339 static int fixed_size = 0, fixed_pos = 0;
342 static int minimum_width, minimum_height;
343 static int maximum_width;
348 static int sensor_device;
351 static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
353 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
354 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
356 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
357 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
359 /* maximum size of individual text buffers, ie $exec buffer size */
360 unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
363 #define CODEPAGE_LENGTH 20
365 long iconv_count = 0;
366 char iconv_converting;
367 static iconv_t **iconv_cd = 0;
369 int register_iconv(iconv_t *new_iconv)
372 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
374 iconv_cd = malloc(sizeof(iconv_t *));
377 CRIT_ERR("Out of memory");
379 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
380 if (!iconv_cd[iconv_count]) {
381 CRIT_ERR("Out of memory");
383 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
388 void free_iconv(void)
392 for (i = 0; i < iconv_count; i++) {
394 iconv_close(*iconv_cd[i]);
409 /* no buffers in used memory? */
412 /* pad percentages to decimals? */
413 static int pad_percents = 0;
415 #ifdef TCP_PORT_MONITOR
416 tcp_port_monitor_args_t tcp_port_monitor_args;
419 static char *text = 0;
422 static int total_updates;
425 static int blockdepth = 0;
426 static int if_jumped = 0;
427 static int blockstart[MAX_IF_BLOCK_DEPTH];
429 int check_contains(char *f, char *s)
432 FILE *where = fopen(f, "r");
434 char buf1[256], buf2[256];
435 while (fgets(buf1, 256, where)) {
436 sscanf(buf1, "%255s", buf2);
437 if (strstr(buf2, s)) {
444 ERR("Could not open the file");
451 static inline int calc_text_width(const char *s, int l)
457 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
459 XftTextExtents8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
465 return XTextWidth(fonts[selected_font].font, s, l);
470 /* formatted text to render on screen, generated in generate_text(),
471 * drawn in draw_stuff() */
473 static char text_buffer[TEXT_BUFFER_SIZE * 4];
475 /* special stuff in text_buffer */
477 #define SPECIAL_CHAR '\x01'
505 unsigned long first_colour; // for graph gradient
506 unsigned long last_colour;
510 /* create specials array on heap instead of stack with introduction of max_specials */
511 static struct special_t *specials = NULL;
513 static unsigned int special_count;
515 static unsigned int special_index; /* used when drawing */
518 #define MAX_GRAPH_DEPTH 256 /* why 256? cause an array of more then 256 doubles seems excessive, and who needs that kind of precision anyway? */
520 static struct special_t *new_special(char *buf, int t)
522 if (special_count >= max_specials)
523 CRIT_ERR("too many special things in text");
525 buf[0] = SPECIAL_CHAR;
527 specials[special_count].type = t;
528 return &specials[special_count++];
531 long fwd_fcharfind(FILE* fp, char val, unsigned int step) {
534 unsigned int count = 0;
535 static char buf[BUFSZ];
536 long orig_pos = ftell(fp);
538 long buf_size = BUFSZ;
539 char* cur_found = NULL;
540 while(count < step) {
541 if(cur_found == NULL) {
542 buf_size = fread(buf, 1, buf_size, fp);
545 cur_found = memchr(buf+buf_pos, val, buf_size-buf_pos);
546 if(cur_found != NULL) {
547 buf_pos = cur_found-buf+1;
556 ret = ftell(fp) - buf_size + buf_pos - 1;
557 fseek(fp, orig_pos, SEEK_SET);
564 memrchr (const void *buffer, int c, size_t n)
566 const unsigned char *p = buffer;
568 for (p += n; n ; n--)
574 long rev_fcharfind(FILE* fp, char val, unsigned int step) {
577 unsigned int count = 0;
578 static char buf[BUFSZ];
579 long orig_pos = ftell(fp);
581 long file_pos = orig_pos;
582 long buf_size = BUFSZ;
584 while(count < step) {
586 if(file_pos > BUFSZ) {
587 fseek(fp, file_pos-BUFSZ, SEEK_SET);
591 fseek(fp, 0, SEEK_SET);
593 file_pos = ftell(fp);
594 buf_pos = fread(buf, 1, buf_size, fp);
601 if(cur_found != NULL) {
602 buf_pos = cur_found-buf;
611 fseek(fp, orig_pos, SEEK_SET);
613 ret = file_pos + buf_pos;
618 static void new_bar(char *buf, int w, int h, int usage)
620 struct special_t *s = new_special(buf, BAR);
621 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
626 static const char *scan_bar(const char *args, int *w, int *h)
628 *w = 0; /* zero width means all space that is available */
630 /* bar's argument is either height or height,width */
633 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
634 sscanf(args, "%d %n", h, &n);
641 static char *scan_font(const char *args)
650 static void new_font(char *buf, char * args) {
652 struct special_t *s = new_special(buf, FONT);
653 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
654 int tmp = selected_font;
655 selected_font = s->font_added = addfont(args);
660 struct special_t *s = new_special(buf, FONT);
661 int tmp = selected_font;
662 selected_font = s->font_added = 0;
668 inline void graph_append(struct special_t *graph, double f)
670 if (!graph->scaled && f > graph->graph_scale) {
671 f = graph->graph_scale;
675 graph->graph_scale = 1;
677 graph->graph[0] = f; /* add new data */
678 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
679 graph->graph[i] = graph->graph[i - 1];
680 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
681 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
686 short colour_depth = 0;
687 void set_up_gradient();
689 /* precalculated: 31/255, and 63/255 */
690 #define CONST_8_TO_5_BITS 0.12156862745098
691 #define CONST_8_TO_6_BITS 0.247058823529412
693 /* adjust color values depending on color depth*/
694 static unsigned int adjust_colors(unsigned int color)
697 if (colour_depth == 0) {
700 if (colour_depth == 16) {
701 r = (color & 0xff0000) >> 16;
702 g = (color & 0xff00) >> 8;
704 color = (int)(r * CONST_8_TO_5_BITS) << 11;
705 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
706 color |= (int)(b * CONST_8_TO_5_BITS);
711 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
713 struct special_t *s = new_special(buf, GRAPH);
715 if (s->graph == NULL) {
716 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
717 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
719 s->graph_width = MAX_GRAPH_DEPTH - 2;
721 s->graph = malloc(s->graph_width * sizeof(double));
722 memset(s->graph, 0, s->graph_width * sizeof(double));
723 s->graph_scale = 100;
726 s->first_colour = adjust_colors(first_colour);
727 s->last_colour = adjust_colors(second_colour);
734 s->graph_width = s->width - 2; // subtract 2 for rectangle around
739 s->graph_scale = scale;
746 static char *scan_graph(const char *args, int *w, int *h,
747 unsigned int *first_colour, unsigned int *last_colour,
752 /* zero width means all space that is available */
758 /* graph's argument is either height or height,width */
760 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour,
765 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) {
768 if (sscanf(args, "%63s %d,%d %x %x %i", buf, h, w, first_colour,
769 last_colour, scale) == 6) {
773 if (sscanf(args, "%63s %d,%d %x %x", buf, h, w, first_colour,
780 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) == 3) {
784 if (sscanf(args, "%x %x", first_colour, last_colour) == 2) {
787 if (sscanf(args, "%63s %x %x %i", buf, first_colour, last_colour,
792 if (sscanf(args, "%63s %x %x", buf, first_colour, last_colour) == 3) {
798 if (sscanf(args, "%d,%d %i", h, w, scale) == 3) {
802 if (sscanf(args, "%d,%d", h, w) == 2) {
805 if (sscanf(args, "%63s %d,%d %i", buf, h, w, scale) < 4) {
807 //TODO: check the return value and throw an error?
808 sscanf(args, "%63s %d,%d", buf, h, w);
814 if (buf[0] == '\0') {
822 static inline void new_hr(char *buf, int a)
824 new_special(buf, HORIZONTAL_LINE)->height = a;
827 static inline void new_stippled_hr(char *buf, int a, int b)
829 struct special_t *s = new_special(buf, STIPPLED_HR);
834 static inline void new_fg(char *buf, long c)
836 new_special(buf, FG)->arg = c;
839 static inline void new_bg(char *buf, long c)
841 new_special(buf, BG)->arg = c;
844 static inline void new_outline(char *buf, long c)
846 new_special(buf, OUTLINE)->arg = c;
849 static inline void new_offset(char *buf, long c)
851 new_special(buf, OFFSET)->arg = c;
854 static inline void new_voffset(char *buf, long c)
856 new_special(buf, VOFFSET)->arg = c;
859 static inline void new_alignr(char *buf, long c)
861 new_special(buf, ALIGNR)->arg = c;
864 static inline void new_alignc(char *buf, long c)
866 new_special(buf, ALIGNC)->arg = c;
869 static inline void new_goto(char *buf, long c)
871 new_special(buf, GOTO)->arg = c;
874 static inline void new_tab(char *buf, int a, int b) {
875 struct special_t *s = new_special(buf, TAB);
880 /* quite boring functions */
882 static inline void for_each_line(char *b, void (*f) (char *))
886 for (ps = b, pe = b; *pe; pe++) {
899 static void convert_escapes(char *buf)
901 char *p = buf, *s = buf;
917 /* Prints anything normally printed with snprintf according to the current value
918 * of use_spacer. Actually slightly more flexible than snprintf, as you can
919 * safely specify the destination buffer as one of your inputs. */
920 static int spaced_print(char *buf, int size, char *format, int width,
921 char *func_name, ...) {
924 char *tempbuf = malloc(size * sizeof(char));
926 // Passes the varargs along to vsnprintf
927 va_start(argp, func_name);
928 vsnprintf(tempbuf, size, format, argp);
931 switch (use_spacer) {
933 len = snprintf(buf, size, "%s", tempbuf);
936 len = snprintf(buf, width, "%*s", width - 1, tempbuf);
939 len = snprintf(buf, width, "%-*s", width - 1, tempbuf);
942 CRIT_ERR("%s encountered invalid use_spacer value (%d)", func_name,
951 /* converts from bytes to human readable format (k, M, G, T) */
952 static void human_readable(long long num, char *buf, int size, char *func_name)
954 char ** suffix = suffixes;
957 static const int WIDTH = 10, SHORT_WIDTH = 8;
961 spaced_print(buf, size, "%lld%c", SHORT_WIDTH, func_name, num,
964 spaced_print(buf, size, "%lld%s", WIDTH, func_name, num, *suffix);
969 while (num / 1024 >= 1000LL && **(suffix + 2)) {
984 len = spaced_print(buf, size, "%.*f%c", SHORT_WIDTH, func_name,
985 precision, fnum, **suffix);
987 len = spaced_print(buf, size, "%.*f%s", WIDTH, func_name, precision,
990 } while (len >= (short_units ? SHORT_WIDTH : WIDTH) || len >= size);
995 enum text_object_type {
1006 OBJ_battery_percent,
1008 #endif /* !__OpenBSD__ */
1030 OBJ_diskiograph_read,
1031 OBJ_diskiograph_write,
1066 #if defined(__linux__)
1072 OBJ_i8k_left_fan_status,
1073 OBJ_i8k_right_fan_status,
1074 OBJ_i8k_left_fan_rpm,
1075 OBJ_i8k_right_fan_rpm,
1077 OBJ_i8k_buttons_status,
1087 OBJ_wireless_bitrate,
1089 OBJ_wireless_link_qual,
1090 OBJ_wireless_link_qual_max,
1091 OBJ_wireless_link_qual_perc,
1092 OBJ_wireless_link_bar,
1093 #endif /* __linux__ */
1122 OBJ_running_processes,
1131 OBJ_temp1, /* i2c is used instead in these */
1151 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1153 OBJ_apm_battery_time,
1154 OBJ_apm_battery_life,
1155 #endif /* __FreeBSD__ __OpenBSD__ */
1157 OBJ_obsd_sensors_temp,
1158 OBJ_obsd_sensors_fan,
1159 OBJ_obsd_sensors_volt,
1162 #endif /* __OpenBSD__ */
1184 OBJ_music_player_interval,
1192 OBJ_xmms2_transport,
1207 OBJ_audacious_status,
1208 OBJ_audacious_title,
1209 OBJ_audacious_length,
1210 OBJ_audacious_length_seconds,
1211 OBJ_audacious_position,
1212 OBJ_audacious_position_seconds,
1213 OBJ_audacious_bitrate,
1214 OBJ_audacious_frequency,
1215 OBJ_audacious_channels,
1216 OBJ_audacious_filename,
1217 OBJ_audacious_playlist_length,
1218 OBJ_audacious_playlist_position,
1232 #ifdef TCP_PORT_MONITOR
1243 OBJ_entropy_poolsize,
1247 struct text_object {
1249 char *s; /* some string */
1250 int i; /* some integer */
1251 long l; /* some other integer */
1252 unsigned int sensor;
1253 struct net_stat *net;
1255 struct diskio_stat *diskio;
1256 unsigned char loadavg[3];
1257 unsigned int cpu_index;
1258 struct mail_s *mail;
1266 char *tz; /* timezone variable */
1267 char *fmt; /* time display formatting */
1305 /* If not -1, a file descriptor to read from when
1306 * logfile is a FIFO. */
1323 timed_thread *p_timed_thread;
1329 #ifdef TCP_PORT_MONITOR
1331 in_port_t port_range_begin; /* starting port to monitor */
1332 in_port_t port_range_end; /* ending port to monitor */
1333 int item; /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1334 int connection_index; /* 0 to n-1 connections. */
1352 struct local_mail_s local_mail;
1357 unsigned int c, d, e;
1362 struct text_object_list {
1363 unsigned int text_object_count;
1364 struct text_object *text_objects;
1367 static unsigned int text_object_count;
1368 static struct text_object *text_objects;
1369 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1371 #define MAXDATASIZE 1000
1375 struct mail_s* parse_mail_args(char type, const char *arg) {
1376 struct mail_s *mail;
1377 mail = malloc(sizeof(struct mail_s));
1378 memset(mail, 0, sizeof(struct mail_s));
1380 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1382 ERR("Scanning IMAP args failed");
1383 } else if (type == IMAP) {
1384 ERR("Scanning POP3 args failed");
1387 // see if password needs prompting
1388 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1389 int fp = fileno(stdin);
1390 struct termios term;
1391 tcgetattr(fp, &term);
1392 term.c_lflag &= ~ECHO;
1393 tcsetattr(fp, TCSANOW, &term);
1394 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1395 scanf("%128s", mail->pass);
1397 term.c_lflag |= ECHO;
1398 tcsetattr(fp, TCSANOW, &term);
1400 // now we check for optional args
1401 tmp = strstr(arg, "-i ");
1404 sscanf(tmp, "%f", &mail->interval);
1406 mail->interval = 300; // 5 minutes
1408 tmp = strstr(arg, "-p ");
1411 sscanf(tmp, "%lu", &mail->port);
1414 mail->port = 110; // default pop3 port
1415 } else if (type == IMAP) {
1416 mail->port = 143; // default imap port
1420 tmp = strstr(arg, "-f ");
1423 sscanf(tmp, "%s", mail->folder);
1425 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1428 tmp = strstr(arg, "-e ");
1432 if (tmp[0] == '\'') {
1433 len = strstr(tmp+1, "'") - tmp - 1;
1438 strncpy(mail->command, tmp+1, len);
1440 mail->command[0] = '\0';
1442 mail->p_timed_thread = NULL;
1446 void *imap_thread(struct mail_s* mail)
1448 int sockfd, numbytes;
1449 char recvbuf[MAXDATASIZE];
1450 char sendbuf[MAXDATASIZE];
1453 unsigned int old_unseen = UINT_MAX;
1454 unsigned int old_messages = UINT_MAX;
1455 struct stat stat_buf;
1457 struct sockaddr_in their_addr; // connector's address information
1458 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1459 herror("gethostbyname");
1464 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1466 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1469 goto next_iteration;
1472 their_addr.sin_family = AF_INET; // host byte order
1473 their_addr.sin_port = htons(mail->port); // short, network byte order
1474 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1475 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1478 (sockfd, (struct sockaddr *) &their_addr,
1479 sizeof(struct sockaddr)) == -1) {
1482 goto next_iteration;
1484 struct timeval timeout;
1487 timeout.tv_sec = 60; // 60 second timeout i guess
1488 timeout.tv_usec = 0;
1490 FD_SET(sockfd, &fdset);
1491 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1494 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1498 goto next_iteration;
1501 ERR("IMAP connection failed: timeout");
1503 goto next_iteration;
1505 recvbuf[numbytes] = '\0';
1506 if (strstr(recvbuf, "* OK") != recvbuf) {
1507 ERR("IMAP connection failed, probably not an IMAP server");
1509 goto next_iteration;
1511 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1512 strncat(sendbuf, mail->user,
1513 MAXDATASIZE - strlen(sendbuf) - 1);
1514 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1515 strncat(sendbuf, mail->pass,
1516 MAXDATASIZE - strlen(sendbuf) - 1);
1517 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1518 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1521 goto next_iteration;
1523 timeout.tv_sec = 60; // 60 second timeout i guess
1524 timeout.tv_usec = 0;
1526 FD_SET(sockfd, &fdset);
1527 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1530 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1534 goto next_iteration;
1537 recvbuf[numbytes] = '\0';
1538 if (strstr(recvbuf, "a1 OK") == NULL) {
1539 ERR("IMAP server login failed: %s", recvbuf);
1541 goto next_iteration;
1543 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1544 strncat(sendbuf, mail->folder,
1545 MAXDATASIZE - strlen(sendbuf) - 1);
1546 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1547 MAXDATASIZE - strlen(sendbuf) - 1);
1548 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1551 goto next_iteration;
1553 timeout.tv_sec = 60; // 60 second timeout i guess
1554 timeout.tv_usec = 0;
1556 FD_SET(sockfd, &fdset);
1557 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1560 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1564 goto next_iteration;
1567 recvbuf[numbytes] = '\0';
1568 if (strstr(recvbuf, "a2 OK") == NULL) {
1569 ERR("IMAP status failed: %s", recvbuf);
1571 goto next_iteration;
1573 // now we get the data
1574 reply = strstr(recvbuf, " (MESSAGES ");
1576 *strchr(reply, ')') = '\0';
1577 if (reply == NULL) {
1578 ERR("Error parsing IMAP response: %s", recvbuf);
1580 goto next_iteration;
1582 timed_thread_lock (mail->p_timed_thread);
1583 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1586 timed_thread_unlock (mail->p_timed_thread);
1588 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1589 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1592 goto next_iteration;
1594 timeout.tv_sec = 60; // 60 second timeout i guess
1595 timeout.tv_usec = 0;
1597 FD_SET(sockfd, &fdset);
1598 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1601 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1605 goto next_iteration;
1608 recvbuf[numbytes] = '\0';
1609 if (strstr(recvbuf, "a3 OK") == NULL) {
1610 ERR("IMAP logout failed: %s", recvbuf);
1612 goto next_iteration;
1614 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1615 if (system(mail->command) == -1) {
1620 old_unseen = mail->unseen;
1621 old_messages = mail->messages;
1623 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1624 /* if a valid socket, close it */
1626 if (timed_thread_test (mail->p_timed_thread))
1627 timed_thread_exit (mail->p_timed_thread);
1634 void *pop3_thread(struct mail_s *mail)
1636 int sockfd, numbytes;
1637 char recvbuf[MAXDATASIZE];
1638 char sendbuf[MAXDATASIZE];
1641 unsigned int old_unseen = UINT_MAX;
1642 struct stat stat_buf;
1644 struct sockaddr_in their_addr; // connector's address information
1645 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1646 herror("gethostbyname");
1651 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1653 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1656 goto next_iteration;
1659 their_addr.sin_family = AF_INET; // host byte order
1660 their_addr.sin_port = htons(mail->port); // short, network byte order
1661 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1662 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1665 (sockfd, (struct sockaddr *) &their_addr,
1666 sizeof(struct sockaddr)) == -1) {
1669 goto next_iteration;
1671 struct timeval timeout;
1674 timeout.tv_sec = 60; // 60 second timeout i guess
1675 timeout.tv_usec = 0;
1677 FD_SET(sockfd, &fdset);
1678 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1681 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1685 goto next_iteration;
1688 ERR("POP3 connection failed: timeout\n");
1690 goto next_iteration;
1692 recvbuf[numbytes] = '\0';
1693 if (strstr(recvbuf, "+OK ") != recvbuf) {
1694 ERR("POP3 connection failed, probably not a POP3 server");
1696 goto next_iteration;
1698 strncpy(sendbuf, "USER ", MAXDATASIZE);
1699 strncat(sendbuf, mail->user,
1700 MAXDATASIZE - strlen(sendbuf) - 1);
1701 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1702 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1703 perror("send USER");
1705 goto next_iteration;
1707 timeout.tv_sec = 60; // 60 second timeout i guess
1708 timeout.tv_usec = 0;
1710 FD_SET(sockfd, &fdset);
1711 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1714 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1716 perror("recv USER");
1718 goto next_iteration;
1721 recvbuf[numbytes] = '\0';
1722 if (strstr(recvbuf, "+OK ") == NULL) {
1723 ERR("POP3 server login failed: %s", recvbuf);
1725 goto next_iteration;
1727 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1728 strncat(sendbuf, mail->pass,
1729 MAXDATASIZE - strlen(sendbuf) - 1);
1730 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1731 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1732 perror("send PASS");
1734 goto next_iteration;
1736 timeout.tv_sec = 60; // 60 second timeout i guess
1737 timeout.tv_usec = 0;
1739 FD_SET(sockfd, &fdset);
1740 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1743 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1745 perror("recv PASS");
1747 goto next_iteration;
1750 recvbuf[numbytes] = '\0';
1751 if (strstr(recvbuf, "+OK ") == NULL) {
1752 ERR("POP3 server login failed: %s", recvbuf);
1754 goto next_iteration;
1756 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1757 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1758 perror("send STAT");
1760 goto next_iteration;
1762 timeout.tv_sec = 60; // 60 second timeout i guess
1763 timeout.tv_usec = 0;
1765 FD_SET(sockfd, &fdset);
1766 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1769 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1771 perror("recv STAT");
1773 goto next_iteration;
1776 recvbuf[numbytes] = '\0';
1777 if (strstr(recvbuf, "+OK ") == NULL) {
1778 ERR("POP3 status failed: %s", recvbuf);
1780 goto next_iteration;
1782 // now we get the data
1783 reply = recvbuf + 4;
1784 if (reply == NULL) {
1785 ERR("Error parsing POP3 response: %s", recvbuf);
1787 goto next_iteration;
1789 timed_thread_lock (mail->p_timed_thread);
1790 sscanf(reply, "%lu %lu", &mail->unseen,
1792 timed_thread_unlock (mail->p_timed_thread);
1794 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1795 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1796 perror("send QUIT");
1798 goto next_iteration;
1800 timeout.tv_sec = 60; // 60 second timeout i guess
1801 timeout.tv_usec = 0;
1803 FD_SET(sockfd, &fdset);
1804 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1807 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1809 perror("recv QUIT");
1811 goto next_iteration;
1814 recvbuf[numbytes] = '\0';
1815 if (strstr(recvbuf, "+OK") == NULL) {
1816 ERR("POP3 logout failed: %s", recvbuf);
1818 goto next_iteration;
1820 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1821 if (system(mail->command) == -1) {
1826 old_unseen = mail->unseen;
1828 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1829 /* if a valid socket, close it */
1831 if (timed_thread_test (mail->p_timed_thread))
1832 timed_thread_exit (mail->p_timed_thread);
1840 void *threaded_exec(struct text_object *obj) {
1842 char *p2 = obj->data.texeci.buffer;
1843 FILE *fp = popen(obj->data.texeci.cmd,"r");
1844 timed_thread_lock (obj->data.texeci.p_timed_thread);
1845 int n2 = fread(p2, 1, text_buffer_size, fp);
1848 if (n2 && p2[n2 - 1] == '\n') {
1852 if (*p2 == '\001') {
1857 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1858 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1859 timed_thread_exit (obj->data.texeci.p_timed_thread);
1864 static struct text_object *new_text_object_internal()
1866 struct text_object *obj = malloc(sizeof(struct text_object));
1867 memset(obj, 0, sizeof(struct text_object));
1871 static void free_text_objects(unsigned int count, struct text_object *objs)
1874 for (i = 0; i < count; i++) {
1875 switch (objs[i].type) {
1878 close(objs[i].data.i);
1881 close(objs[i].data.i);
1884 close(objs[i].data.sysfs.fd);
1887 close(objs[i].data.sysfs.fd);
1890 close(objs[i].data.sysfs.fd);
1892 #endif /* !__OpenBSD__ */
1894 free(objs[i].data.s);
1897 free(objs[i].data.s);
1900 free(objs[i].data.tztime.tz);
1901 free(objs[i].data.tztime.fmt);
1904 free(objs[i].data.mboxscan.args);
1905 free(objs[i].data.mboxscan.output);
1909 free(objs[i].data.local_mail.box);
1914 case OBJ_imap_unseen:
1915 if (!objs[i].global_mode) {
1916 free(objs[i].data.mail);
1919 case OBJ_imap_messages:
1920 if (!objs[i].global_mode) {
1921 free(objs[i].data.mail);
1927 case OBJ_pop3_unseen:
1928 if (!objs[i].global_mode) {
1929 free(objs[i].data.mail);
1933 if (!objs[i].global_mode) {
1934 free(objs[i].data.mail);
1938 case OBJ_if_existing:
1939 case OBJ_if_mounted:
1940 case OBJ_if_running:
1941 free(objs[i].data.ifblock.s);
1942 free(objs[i].data.ifblock.str);
1945 free(objs[i].data.tail.logfile);
1946 free(objs[i].data.tail.buffer);
1950 free(objs[i].data.s);
1953 free(objs[i].data.s);
1956 free(objs[i].data.s);
1959 free(objs[i].data.s);
1962 free(objs[i].data.s);
1964 /* case OBJ_execibar:
1965 free(objs[i].data.s);
1967 case OBJ_execigraph:
1968 free(objs[i].data.s);
1971 case OBJ_iconv_start:
1976 case OBJ_xmms2_artist:
1977 if (info.xmms2.artist) {
1978 free(info.xmms2.artist);
1979 info.xmms2.artist = 0;
1982 case OBJ_xmms2_album:
1983 if (info.xmms2.album) {
1984 free(info.xmms2.album);
1985 info.xmms2.album = 0;
1988 case OBJ_xmms2_title:
1989 if (info.xmms2.title) {
1990 free(info.xmms2.title);
1991 info.xmms2.title = 0;
1994 case OBJ_xmms2_genre:
1995 if (info.xmms2.genre) {
1996 free(info.xmms2.genre);
1997 info.xmms2.genre = 0;
2000 case OBJ_xmms2_comment:
2001 if (info.xmms2.comment) {
2002 free(info.xmms2.comment);
2003 info.xmms2.comment = 0;
2006 case OBJ_xmms2_decoder:
2007 if (info.xmms2.decoder) {
2008 free(info.xmms2.decoder);
2012 case OBJ_xmms2_transport:
2013 if (info.xmms2.transport) {
2014 free(info.xmms2.transport);
2019 if (info.xmms2.url) {
2020 free(info.xmms2.url);
2024 case OBJ_xmms2_date:
2025 if (info.xmms2.date) {
2026 free(info.xmms2.date);
2027 info.xmms2.date = 0;
2030 case OBJ_xmms2_status:
2031 if (info.xmms2.status) {
2032 free(info.xmms2.status);
2033 info.xmms2.status = 0;
2036 case OBJ_xmms2_smart:
2037 if (info.xmms2.artist) {
2038 free(info.xmms2.artist);
2039 info.xmms2.artist = 0;
2041 if (info.xmms2.title) {
2042 free(info.xmms2.title);
2043 info.xmms2.title = 0;
2045 if (info.xmms2.url) {
2046 free(info.xmms2.url);
2052 case OBJ_bmpx_title:
2053 case OBJ_bmpx_artist:
2054 case OBJ_bmpx_album:
2055 case OBJ_bmpx_track:
2057 case OBJ_bmpx_bitrate:
2062 free(objs[i].data.rss.uri);
2063 free(objs[i].data.rss.action);
2070 free(objs[i].data.s);
2072 case OBJ_battery_time:
2073 free(objs[i].data.s);
2075 #endif /* !__OpenBSD__ */
2077 free(objs[i].data.execi.cmd);
2078 free(objs[i].data.execi.buffer);
2081 free(objs[i].data.texeci.cmd);
2082 free(objs[i].data.texeci.buffer);
2085 if (info.first_process) {
2086 free_all_processes();
2087 info.first_process = NULL;
2091 if (info.first_process) {
2092 free_all_processes();
2093 info.first_process = NULL;
2098 free(objs[i].data.hddtemp.dev);
2099 free(objs[i].data.hddtemp.addr);
2102 case OBJ_entropy_avail:
2103 case OBJ_entropy_poolsize:
2104 case OBJ_entropy_bar:
2111 if (info.mpd.title) {
2112 free(info.mpd.title);
2115 if (info.mpd.artist) {
2116 free(info.mpd.artist);
2117 info.mpd.artist = 0;
2119 if (info.mpd.album) {
2120 free(info.mpd.album);
2123 if (info.mpd.random) {
2124 free(info.mpd.random);
2125 info.mpd.random = 0;
2127 if (info.mpd.repeat) {
2128 free(info.mpd.repeat);
2129 info.mpd.repeat = 0;
2131 if (info.mpd.track) {
2132 free(info.mpd.track);
2135 if (info.mpd.name) {
2136 free(info.mpd.name);
2139 if (info.mpd.file) {
2140 free(info.mpd.file);
2143 if (info.mpd.status) {
2144 free(info.mpd.status);
2145 info.mpd.status = 0;
2149 //text_objects = NULL;
2150 //text_object_count = 0;
2153 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2158 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2159 *a = mixer_init(buf1);
2160 (void) scan_bar(arg + n, w, h);
2163 (void) scan_bar(arg, w, h);
2168 /* construct_text_object() creates a new text_object */
2169 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2171 //struct text_object *obj = new_text_object();
2172 struct text_object *obj = new_text_object_internal();
2175 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2176 #define END ; } } else
2180 obj->type = OBJ_color;
2181 obj->data.l = get_x11_color(s);
2185 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2186 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2187 END OBJ(acpiacadapter, 0)
2188 #endif /* !__OpenBSD__ */
2190 OBJ(freq, INFO_FREQ)
2192 END OBJ(freq, INFO_FREQ)
2199 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2201 obj->data.cpu_index=1;
2202 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2206 obj->data.cpu_index=atoi(&arg[0]);
2209 END OBJ(freq_g, INFO_FREQ)
2215 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2217 obj->data.cpu_index=1;
2218 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2222 obj->data.cpu_index=atoi(&arg[0]);
2225 #if defined(__linux__)
2226 END OBJ(voltage_mv, 0)
2232 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2234 obj->data.cpu_index=1;
2235 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2239 obj->data.cpu_index=atoi(&arg[0]);
2242 END OBJ(voltage_v, 0)
2248 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2250 obj->data.cpu_index=1;
2251 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2255 obj->data.cpu_index=atoi(&arg[0]);
2260 END OBJ(wireless_essid, INFO_NET)
2262 obj->data.net = get_net_stat(arg);
2264 CRIT_ERR("wireless_essid: needs an argument");
2265 END OBJ(wireless_mode, INFO_NET)
2267 obj->data.net = get_net_stat(arg);
2269 CRIT_ERR("wireless_mode: needs an argument");
2270 END OBJ(wireless_bitrate, INFO_NET)
2272 obj->data.net = get_net_stat(arg);
2274 CRIT_ERR("wireless_bitrate: needs an argument");
2275 END OBJ(wireless_ap, INFO_NET)
2277 obj->data.net = get_net_stat(arg);
2279 CRIT_ERR("wireless_ap: needs an argument");
2280 END OBJ(wireless_link_qual, INFO_NET)
2282 obj->data.net = get_net_stat(arg);
2284 CRIT_ERR("wireless_link_qual: needs an argument");
2285 END OBJ(wireless_link_qual_max, INFO_NET)
2287 obj->data.net = get_net_stat(arg);
2289 CRIT_ERR("wireless_link_qual_max: needs an argument");
2290 END OBJ(wireless_link_qual_perc, INFO_NET)
2292 obj->data.net = get_net_stat(arg);
2294 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2295 END OBJ(wireless_link_bar, INFO_NET)
2297 arg = scan_bar(arg, &obj->a, &obj->b);
2298 obj->data.net = get_net_stat(arg);
2300 CRIT_ERR("wireless_link_bar: needs an argument");
2301 #endif /* HAVE_IWLIB */
2303 #endif /* __linux__ */
2304 END OBJ(freq_dyn, 0)
2305 END OBJ(freq_dyn_g, 0)
2311 sscanf(arg, "%63s", bat);
2313 strcpy(bat, "BAT0");
2314 obj->data.s = strdup(bat);
2315 END OBJ(battery_time, 0)
2318 sscanf(arg, "%63s", bat);
2320 strcpy(bat, "BAT0");
2321 obj->data.s = strdup(bat);
2322 END OBJ(battery_percent, 0)
2325 sscanf(arg, "%63s", bat);
2327 strcpy(bat, "BAT0");
2328 obj->data.s = strdup(bat);
2329 END OBJ(battery_bar, 0)
2332 arg = scan_bar(arg, &obj->a, &obj->b);
2333 sscanf(arg, "%63s", bat);
2335 strcpy(bat, "BAT0");
2337 obj->data.s = strdup(bat);
2338 #endif /* !__OpenBSD__ */
2339 #if defined(__linux__)
2340 END OBJ(i8k_version, INFO_I8K)
2341 END OBJ(i8k_bios, INFO_I8K)
2342 END OBJ(i8k_serial, INFO_I8K)
2343 END OBJ(i8k_cpu_temp, INFO_I8K)
2344 END OBJ(i8k_cpu_tempf, INFO_I8K)
2345 END OBJ(i8k_left_fan_status, INFO_I8K)
2346 END OBJ(i8k_right_fan_status, INFO_I8K)
2347 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2348 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2349 END OBJ(i8k_ac_status, INFO_I8K)
2350 END OBJ(i8k_buttons_status, INFO_I8K)
2352 END OBJ(ibm_temps, 0)
2354 CRIT_ERR("ibm_temps: needs an argument");
2356 if (!isdigit(arg[0])
2358 || atoi(&arg[0]) >=8)
2361 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2363 obj->data.sensor = atoi(&arg[0]);
2364 END OBJ(ibm_volume, 0)
2365 END OBJ(ibm_brightness, 0)
2366 END OBJ(pb_battery, 0)
2367 if (arg && strcmp(arg, "status") == 0) {
2368 obj->data.i = PB_BATT_STATUS;
2369 } else if (arg && strcmp(arg, "percent") == 0) {
2370 obj->data.i = PB_BATT_PERCENT;
2371 } else if (arg && strcmp(arg, "time") == 0) {
2372 obj->data.i = PB_BATT_TIME;
2374 ERR("pb_battery: needs one argument: status, percent or time");
2379 #endif /* __linux__ */
2380 #if defined(__OpenBSD__)
2381 END OBJ(obsd_sensors_temp, 0)
2383 CRIT_ERR("obsd_sensors_temp: needs an argument");
2385 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2387 ERR("Invalid temperature sensor number!");
2389 obj->data.sensor = atoi(&arg[0]);
2390 END OBJ(obsd_sensors_fan, 0)
2392 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor number)");
2394 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2396 ERR("Invalid fan sensor number!");
2398 obj->data.sensor = atoi(&arg[0]);
2399 END OBJ(obsd_sensors_volt, 0)
2401 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor number)");
2403 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2405 ERR("Invalid voltage sensor number!");
2407 obj->data.sensor = atoi(&arg[0]);
2408 END OBJ(obsd_vendor, 0)
2409 END OBJ(obsd_product, 0)
2410 #endif /* __OpenBSD__ */
2411 END OBJ(buffers, INFO_BUFFERS)
2412 END OBJ(cached, INFO_BUFFERS)
2413 END OBJ(cpu, INFO_CPU)
2415 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2416 obj->data.cpu_index = atoi(&arg[3]);
2418 } else {obj->data.cpu_index = 0; }
2420 obj->data.cpu_index = 0;
2422 END OBJ(cpubar, INFO_CPU)
2424 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2425 obj->data.cpu_index = atoi(&arg[3]);
2428 else {obj->data.cpu_index = 0;}
2429 (void) scan_bar(arg, &obj->a, &obj->b);
2431 (void) scan_bar(arg, &obj->a, &obj->b);
2432 obj->data.cpu_index = 0;
2434 END OBJ(cpugraph, INFO_CPU)
2435 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2439 if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
2440 obj->data.cpu_index = atoi(&buf[3]);
2442 obj->data.cpu_index = 0;
2446 END OBJ(diskio, INFO_DISKIO)
2448 obj->data.diskio = prepare_diskio_stat(arg);
2450 obj->data.diskio = NULL;
2452 END OBJ(diskio_read, INFO_DISKIO)
2454 obj->data.diskio = prepare_diskio_stat(arg);
2456 obj->data.diskio = NULL;
2458 END OBJ(diskio_write, INFO_DISKIO)
2460 obj->data.diskio = prepare_diskio_stat(arg);
2462 obj->data.diskio = NULL;
2464 END OBJ(diskiograph, INFO_DISKIO)
2465 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2469 obj->data.diskio = prepare_diskio_stat(buf);
2472 obj->data.diskio = NULL;
2474 END OBJ(diskiograph_read, INFO_DISKIO)
2475 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2479 obj->data.diskio = prepare_diskio_stat(buf);
2482 obj->data.diskio = NULL;
2484 END OBJ(diskiograph_write, INFO_DISKIO)
2485 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2489 obj->data.diskio = prepare_diskio_stat(buf);
2492 obj->data.diskio = NULL;
2496 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2499 obj->data.l = color0;
2501 obj->data.l = color1;
2503 obj->data.l = color2;
2505 obj->data.l = color3;
2507 obj->data.l = color4;
2509 obj->data.l = color5;
2511 obj->data.l = color6;
2513 obj->data.l = color7;
2515 obj->data.l = color8;
2517 obj->data.l = color9;
2519 obj->data.s = scan_font(arg);
2520 END OBJ(downspeed, INFO_NET)
2522 obj->data.net = get_net_stat(arg);
2525 CRIT_ERR("downspeed needs argument");
2527 END OBJ(downspeedf, INFO_NET)
2529 obj->data.net = get_net_stat(arg);
2532 CRIT_ERR("downspeedf needs argument");
2534 END OBJ(downspeedgraph, INFO_NET)
2535 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2539 obj->data.net = get_net_stat(buf);
2544 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2545 blockstart[blockdepth - 1] = object_count;
2546 obj->data.ifblock.pos = object_count + 2;
2548 ERR("$else: no matching $if_*");
2553 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2555 ERR("$endif: no matching $if_*");
2558 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2561 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2562 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2563 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2564 END OBJ(execibar, 0) unsigned int n;
2565 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2567 ERR("${execibar <interval> command}");
2568 obj->type = OBJ_text;
2569 snprintf(buf, 256, "${%s}", s);
2570 obj->data.s = strdup(buf);
2572 obj->data.execi.cmd = strdup(arg + n);
2574 END OBJ(execigraph, 0) unsigned int n;
2575 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2577 ERR("${execigraph <interval> command}");
2578 obj->type = OBJ_text;
2579 snprintf(buf, 256, "${%s}", s);
2580 obj->data.s = strdup(buf);
2582 obj->data.execi.cmd = strdup(arg + n);
2584 END OBJ(execi, 0) unsigned int n;
2585 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2587 ERR("${execi <interval> command}");
2588 obj->type = OBJ_text;
2589 snprintf(buf, 256, "${%s}", s);
2590 obj->data.s = strdup(buf);
2592 obj->data.execi.cmd = strdup(arg + n);
2593 obj->data.execi.buffer =
2594 (char *) calloc(1, text_buffer_size);
2596 END OBJ(texeci, 0) unsigned int n;
2597 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2599 ERR("${texeci <interval> command}");
2600 obj->type = OBJ_text;
2601 snprintf(buf, 256, "${%s}", s);
2602 obj->data.s = strdup(buf);
2604 obj->data.texeci.cmd = strdup(arg + n);
2605 obj->data.texeci.buffer =
2606 (char *) calloc(1, text_buffer_size);
2608 obj->data.texeci.p_timed_thread = NULL;
2609 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2611 FILE *fp = popen(arg, "r");
2615 n = fread(buf, 1, 2048, fp);
2618 if (n && buf[n - 1] == '\n')
2623 obj->data.s = strdup(buf);
2625 obj->data.s = strdup("");
2628 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2629 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2631 while (isspace(*arg))
2637 obj->data.fsbar.fs = prepare_fs_stat(arg);
2638 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2641 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2645 obj->data.fsbar.fs = prepare_fs_stat(arg);
2646 END OBJ(fs_free, INFO_FS) if (!arg)
2648 obj->data.fs = prepare_fs_stat(arg);
2649 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2651 obj->data.fs = prepare_fs_stat(arg);
2652 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2654 obj->data.fs = prepare_fs_stat(arg);
2655 END OBJ(fs_size, INFO_FS) if (!arg)
2657 obj->data.fs = prepare_fs_stat(arg);
2658 END OBJ(fs_used, INFO_FS) if (!arg)
2660 obj->data.fs = prepare_fs_stat(arg);
2661 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2662 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2663 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2667 ERR("goto needs arguments");
2668 obj->type = OBJ_text;
2669 obj->data.s = strdup("${goto}");
2673 obj->data.i = atoi(arg);
2678 if (sscanf(arg, "%d %d", &a, &b) != 2)
2679 sscanf(arg, "%d", &b);
2683 obj->data.pair.a = a;
2684 obj->data.pair.b = b;
2687 END OBJ(i2c, INFO_SYSFS)
2688 char buf1[64], buf2[64];
2692 ERR("i2c needs arguments");
2693 obj->type = OBJ_text;
2694 //obj->data.s = strdup("${i2c}");
2698 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2699 /* if scanf couldn't read three values, read type and num and use default device */
2700 sscanf(arg, "%63s %d", buf2, &n);
2701 obj->data.sysfs.fd =
2702 open_i2c_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2703 strncpy(obj->data.sysfs.type, buf2, 63);
2705 obj->data.sysfs.fd =
2706 open_i2c_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2707 strncpy(obj->data.sysfs.type, buf2, 63);
2710 END OBJ(platform, INFO_SYSFS)
2711 char buf1[64], buf2[64];
2715 ERR("platform needs arguments");
2716 obj->type = OBJ_text;
2720 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2721 /* if scanf couldn't read three values, read type and num and use default device */
2722 sscanf(arg, "%63s %d", buf2, &n);
2723 obj->data.sysfs.fd =
2724 open_platform_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2725 strncpy(obj->data.sysfs.type, buf2, 63);
2727 obj->data.sysfs.fd =
2728 open_platform_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2729 strncpy(obj->data.sysfs.type, buf2, 63);
2732 END OBJ(hwmon, INFO_SYSFS)
2733 char buf1[64], buf2[64];
2737 ERR("hwmon needs argumanets");
2738 obj->type = OBJ_text;
2742 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2743 /* if scanf couldn't read three values, read type and num and use default device */
2744 sscanf(arg, "%63s %d", buf2, &n);
2745 obj->data.sysfs.fd =
2746 open_hwmon_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2747 strncpy(obj->data.sysfs.type, buf2, 63);
2749 obj->data.sysfs.fd =
2750 open_hwmon_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2751 strncpy(obj->data.sysfs.type, buf2, 63);
2753 #endif /* !__OpenBSD__ */
2755 END OBJ(top, INFO_TOP)
2759 ERR("top needs arguments");
2760 obj->type = OBJ_text;
2761 //obj->data.s = strdup("${top}");
2764 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2765 if (strcmp(buf, "name") == 0) {
2766 obj->data.top.type = TOP_NAME;
2767 } else if (strcmp(buf, "cpu") == 0) {
2768 obj->data.top.type = TOP_CPU;
2769 } else if (strcmp(buf, "pid") == 0) {
2770 obj->data.top.type = TOP_PID;
2771 } else if (strcmp(buf, "mem") == 0) {
2772 obj->data.top.type = TOP_MEM;
2773 } else if (strcmp(buf, "time") == 0) {
2774 obj->data.top.type = TOP_TIME;
2776 ERR("invalid arg for top");
2779 if (n < 1 || n > 10) {
2780 CRIT_ERR("invalid arg for top");
2783 obj->data.top.num = n - 1;
2787 ERR("invalid args given for top");
2790 END OBJ(top_mem, INFO_TOP)
2794 ERR("top_mem needs arguments");
2795 obj->type = OBJ_text;
2796 obj->data.s = strdup("${top_mem}");
2799 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2800 if (strcmp(buf, "name") == 0) {
2801 obj->data.top.type = TOP_NAME;
2802 } else if (strcmp(buf, "cpu") == 0) {
2803 obj->data.top.type = TOP_CPU;
2804 } else if (strcmp(buf, "pid") == 0) {
2805 obj->data.top.type = TOP_PID;
2806 } else if (strcmp(buf, "mem") == 0) {
2807 obj->data.top.type = TOP_MEM;
2808 } else if (strcmp(buf, "time") == 0) {
2809 obj->data.top.type = TOP_TIME;
2811 ERR("invalid arg for top");
2814 if (n < 1 || n > 10) {
2815 CRIT_ERR("invalid arg for top");
2818 obj->data.top.num = n - 1;
2822 ERR("invalid args given for top");
2825 END OBJ(addr, INFO_NET)
2827 obj->data.net = get_net_stat(arg);
2830 CRIT_ERR("addr needs argument");
2837 ERR("tail needs arguments");
2838 obj->type = OBJ_text;
2839 obj->data.s = strdup("${tail}");
2842 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2843 if (n1 < 1 || n1 > 30) {
2844 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2850 obj->data.tail.fd = -1;
2852 if (stat(buf, &st) == 0) {
2853 if (S_ISFIFO(st.st_mode)) {
2854 fd = open(buf, O_RDONLY|O_NONBLOCK);
2857 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2859 obj->data.tail.fd = fd;
2863 fp = fopen(buf, "r");
2866 if (fp || obj->data.tail.fd != -1) {
2867 obj->data.tail.logfile =
2868 malloc(text_buffer_size);
2869 strcpy(obj->data.tail.logfile, buf);
2870 obj->data.tail.wantedlines = n1;
2871 obj->data.tail.interval =
2872 update_interval * 2;
2874 if (obj->data.tail.fd == -1)
2878 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2881 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2882 if (n1 < 1 || n1 > 30) {
2884 ("invalid arg for tail, number of lines must be between 1 and 30");
2886 } else if (n2 < 1 || n2 < update_interval) {
2888 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2894 obj->data.tail.fd = -1;
2896 if (stat(buf, &st) == 0) {
2897 if (S_ISFIFO(st.st_mode)) {
2898 fd = open(buf, O_RDONLY|O_NONBLOCK);
2901 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2903 obj->data.tail.fd = fd;
2906 fp = fopen(buf, "r");
2909 if (fp || obj->data.tail.fd != -1) {
2910 obj->data.tail.logfile =
2911 malloc(text_buffer_size);
2912 strcpy(obj->data.tail.logfile, buf);
2913 obj->data.tail.wantedlines = n1;
2914 obj->data.tail.interval = n2;
2916 if (obj->data.tail.fd == -1)
2920 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2926 ERR("invalid args given for tail");
2929 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2934 ERR("head needs arguments");
2935 obj->type = OBJ_text;
2936 obj->data.s = strdup("${head}");
2939 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2940 if (n1 < 1 || n1 > 30) {
2941 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2945 fp = fopen(buf, "r");
2947 obj->data.tail.logfile =
2948 malloc(text_buffer_size);
2949 strcpy(obj->data.tail.logfile, buf);
2950 obj->data.tail.wantedlines = n1;
2951 obj->data.tail.interval =
2952 update_interval * 2;
2956 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2959 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2960 if (n1 < 1 || n1 > 30) {
2962 ("invalid arg for head, number of lines must be between 1 and 30");
2964 } else if (n2 < 1 || n2 < update_interval) {
2966 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2970 fp = fopen(buf, "r");
2972 obj->data.tail.logfile =
2973 malloc(text_buffer_size);
2974 strcpy(obj->data.tail.logfile, buf);
2975 obj->data.tail.wantedlines = n1;
2976 obj->data.tail.interval = n2;
2980 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2986 ERR("invalid args given for head");
2989 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2990 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2992 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2993 if (r >= 3 && (c < 1 || c > 3))
2995 if (r >= 2 && (b < 1 || b > 3))
2997 if (r >= 1 && (a < 1 || a > 3))
3000 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
3001 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
3002 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
3003 END OBJ(if_empty, 0)
3004 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3005 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3008 ERR("if_empty needs an argument");
3009 obj->data.ifblock.s = 0;
3011 obj->data.ifblock.s = strdup(arg);
3012 blockstart[blockdepth] = object_count;
3013 obj->data.ifblock.pos = object_count + 2;
3015 END OBJ(if_existing, 0)
3016 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3017 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3020 ERR("if_existing needs an argument or two");
3021 obj->data.ifblock.s = NULL;
3022 obj->data.ifblock.str = NULL;
3024 char buf1[256], buf2[256];
3025 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3027 obj->data.ifblock.s = strdup(buf1);
3028 obj->data.ifblock.str = NULL;
3030 obj->data.ifblock.s = strdup(buf1);
3031 obj->data.ifblock.str = strdup(buf2);
3034 blockstart[blockdepth] = object_count;
3035 obj->data.ifblock.pos = object_count + 2;
3037 END OBJ(if_mounted, 0)
3038 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3039 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3042 ERR("if_mounted needs an argument");
3043 obj->data.ifblock.s = 0;
3045 obj->data.ifblock.s = strdup(arg);
3046 blockstart[blockdepth] = object_count;
3047 obj->data.ifblock.pos = object_count + 2;
3049 END OBJ(if_running, 0)
3050 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3051 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3055 snprintf(buf, 256, "pidof %s >/dev/null", arg);
3056 obj->data.ifblock.s = strdup(buf);
3058 ERR("if_running needs an argument");
3059 obj->data.ifblock.s = 0;
3061 blockstart[blockdepth] = object_count;
3062 obj->data.ifblock.pos = object_count + 2;
3068 char box[256], dst[256];
3072 strncpy(box, MAIL_FILE, sizeof(box));
3075 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3077 strncpy(box, arg, sizeof(box));
3081 variable_substitute(box, dst, sizeof(dst));
3082 obj->data.local_mail.box = strdup(dst);
3083 obj->data.local_mail.interval = n1;
3086 END OBJ(mboxscan, 0)
3087 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
3088 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
3089 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
3090 obj->data.mboxscan.output[0] = 1;
3091 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
3092 END OBJ(mem, INFO_MEM)
3093 END OBJ(memmax, INFO_MEM)
3094 END OBJ(memperc, INFO_MEM)
3095 END OBJ(membar, INFO_MEM)
3096 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3097 END OBJ(memgraph, INFO_MEM)
3098 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3104 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
3105 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
3106 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
3107 END OBJ(mixerbar, INFO_MIXER)
3108 scan_mixer_bar(arg, &obj->data.mixerbar.l,
3109 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
3110 END OBJ(mixerlbar, INFO_MIXER)
3111 scan_mixer_bar(arg, &obj->data.mixerbar.l,
3112 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
3113 END OBJ(mixerrbar, INFO_MIXER)
3114 scan_mixer_bar(arg, &obj->data.mixerbar.l,
3115 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
3119 char box[256], dst[256];
3123 strncpy(box, MAIL_FILE, sizeof(box));
3126 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3128 strncpy(box, arg, sizeof(box));
3132 variable_substitute(box, dst, sizeof(dst));
3133 obj->data.local_mail.box = strdup(dst);
3134 obj->data.local_mail.interval = n1;
3137 END OBJ(nodename, 0)
3138 END OBJ(processes, INFO_PROCS)
3139 END OBJ(running_processes, INFO_RUN_PROCS)
3140 END OBJ(shadecolor, 0)
3142 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
3144 END OBJ(outlinecolor, 0)
3146 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
3148 END OBJ(stippled_hr, 0)
3150 int a = stippled_borders, b = 1;
3152 if (sscanf(arg, "%d %d", &a, &b) != 2)
3153 sscanf(arg, "%d", &b);
3157 obj->data.pair.a = a;
3158 obj->data.pair.b = b;
3160 END OBJ(swap, INFO_MEM)
3161 END OBJ(swapmax, INFO_MEM)
3162 END OBJ(swapperc, INFO_MEM)
3163 END OBJ(swapbar, INFO_MEM)
3164 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3167 END OBJ(temp1, INFO_SYSFS) obj->type = OBJ_i2c;
3168 obj->data.sysfs.fd =
3169 open_i2c_sensor(0, "temp", 1, &obj->data.sysfs.arg,
3170 obj->data.sysfs.devtype);
3171 END OBJ(temp2, INFO_SYSFS) obj->type = OBJ_i2c;
3172 obj->data.sysfs.fd =
3173 open_i2c_sensor(0, "temp", 2, &obj->data.sysfs.arg,
3174 obj->data.sysfs.devtype);
3176 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
3177 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
3179 char buf1[256], buf2[256], *fmt, *tz;
3182 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3191 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
3192 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
3194 END OBJ(iconv_start, 0)
3195 if (iconv_converting) {
3196 CRIT_ERR("You must stop your last iconv conversion before starting another");
3199 char iconv_from[CODEPAGE_LENGTH];
3200 char iconv_to[CODEPAGE_LENGTH];
3201 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3202 CRIT_ERR("Invalid arguments for iconv_start");
3205 new_iconv = iconv_open(iconv_to, iconv_from);
3206 if (new_iconv == (iconv_t)(-1)) {
3207 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3209 obj->a = register_iconv(&new_iconv);
3210 iconv_converting = 1;
3214 CRIT_ERR("Iconv requires arguments");
3216 END OBJ(iconv_stop, 0)
3217 iconv_converting = 0;
3220 END OBJ(totaldown, INFO_NET)
3222 obj->data.net = get_net_stat(arg);
3225 CRIT_ERR("totaldown needs argument");
3227 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
3229 obj->data.net = get_net_stat(arg);
3232 CRIT_ERR("totalup needs argument");
3235 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
3236 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
3237 END OBJ(upspeed, INFO_NET)
3239 obj->data.net = get_net_stat(arg);
3242 CRIT_ERR("upspeed needs argument");
3244 END OBJ(upspeedf, INFO_NET)
3246 obj->data.net = get_net_stat(arg);
3249 CRIT_ERR("upspeedf needs argument");
3252 END OBJ(upspeedgraph, INFO_NET)
3253 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3257 obj->data.net = get_net_stat(buf);
3260 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
3262 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
3263 #endif /* !__OpenBSD__ */
3264 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3265 OBJ(apm_adapter, 0) END
3266 OBJ(apm_battery_life, 0) END
3267 OBJ(apm_battery_time, 0) END
3268 #endif /* __FreeBSD__ */
3272 obj->data.mail = parse_mail_args(IMAP, arg);
3273 obj->global_mode = 0;
3275 obj->global_mode = 1;
3278 OBJ(imap_messages, 0)
3281 obj->data.mail = parse_mail_args(IMAP, arg);
3282 obj->global_mode = 0;
3284 obj->global_mode = 1;
3290 obj->data.mail = parse_mail_args(POP3, arg);
3291 obj->global_mode = 0;
3293 obj->global_mode = 1;
3299 obj->data.mail = parse_mail_args(POP3, arg);
3300 obj->global_mode = 0;
3302 obj->global_mode = 1;
3306 OBJ(mpd_artist, INFO_MPD) END
3307 OBJ(mpd_title, INFO_MPD)
3310 sscanf (arg, "%d", &info.mpd.max_title_len);
3311 if (info.mpd.max_title_len > 0) {
3312 info.mpd.max_title_len++;
3314 CRIT_ERR ("mpd_title: invalid length argument");
3317 info.mpd.max_title_len = 0;
3320 END OBJ(mpd_random, INFO_MPD)
3321 END OBJ(mpd_repeat, INFO_MPD)
3322 END OBJ(mpd_elapsed, INFO_MPD)
3323 END OBJ(mpd_length, INFO_MPD)
3324 END OBJ(mpd_track, INFO_MPD)
3325 END OBJ(mpd_name, INFO_MPD)
3326 END OBJ(mpd_file, INFO_MPD)
3327 END OBJ(mpd_percent, INFO_MPD)
3328 END OBJ(mpd_album, INFO_MPD)
3329 END OBJ(mpd_vol, INFO_MPD)
3330 END OBJ(mpd_bitrate, INFO_MPD)
3331 END OBJ(mpd_status, INFO_MPD)
3332 END OBJ(mpd_bar, INFO_MPD)
3333 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3334 END OBJ(mpd_smart, INFO_MPD) END
3337 OBJ(xmms2_artist, INFO_XMMS2)
3338 END OBJ(xmms2_album, INFO_XMMS2)
3339 END OBJ(xmms2_title, INFO_XMMS2)
3340 END OBJ(xmms2_genre, INFO_XMMS2)
3341 END OBJ(xmms2_comment, INFO_XMMS2)
3342 END OBJ(xmms2_decoder, INFO_XMMS2)
3343 END OBJ(xmms2_transport, INFO_XMMS2)
3344 END OBJ(xmms2_url, INFO_XMMS2)
3345 END OBJ(xmms2_tracknr, INFO_XMMS2)
3346 END OBJ(xmms2_bitrate, INFO_XMMS2)
3347 END OBJ(xmms2_date, INFO_XMMS2)
3348 END OBJ(xmms2_id, INFO_XMMS2)
3349 END OBJ(xmms2_duration, INFO_XMMS2)
3350 END OBJ(xmms2_elapsed, INFO_XMMS2)
3351 END OBJ(xmms2_size, INFO_XMMS2)
3352 END OBJ(xmms2_status, INFO_XMMS2)
3353 END OBJ(xmms2_percent, INFO_XMMS2)
3354 END OBJ(xmms2_bar, INFO_XMMS2)
3355 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3356 END OBJ(xmms2_smart, INFO_XMMS2)
3360 OBJ(audacious_status, INFO_AUDACIOUS) END
3361 OBJ(audacious_title, INFO_AUDACIOUS)
3364 sscanf (arg, "%d", &info.audacious.max_title_len);
3365 if (info.audacious.max_title_len > 0) {
3366 info.audacious.max_title_len++;
3368 CRIT_ERR ("audacious_title: invalid length argument");
3373 OBJ(audacious_length, INFO_AUDACIOUS) END
3374 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3375 OBJ(audacious_position, INFO_AUDACIOUS) END
3376 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3377 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3378 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3379 OBJ(audacious_channels, INFO_AUDACIOUS) END
3380 OBJ(audacious_filename, INFO_AUDACIOUS) END
3381 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3382 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3383 OBJ(audacious_bar, INFO_AUDACIOUS)
3384 (void) scan_bar(arg, &obj->a, &obj->b);
3388 OBJ(bmpx_title, INFO_BMPX)
3389 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3391 OBJ(bmpx_artist, INFO_BMPX)
3392 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3394 OBJ(bmpx_album, INFO_BMPX)
3395 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3397 OBJ(bmpx_track, INFO_BMPX)
3398 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3400 OBJ(bmpx_uri, INFO_BMPX)
3401 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3403 OBJ(bmpx_bitrate, INFO_BMPX)
3404 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3410 int argc, delay, act_par;
3411 char *uri = (char *)malloc(128 * sizeof(char));
3412 char *action = (char *)malloc(64 * sizeof(char));
3414 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par);
3415 obj->data.rss.uri = uri;
3416 obj->data.rss.delay = delay;
3417 obj->data.rss.action = action;
3418 obj->data.rss.act_par = act_par;
3422 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
3428 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3429 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3430 ERR("hddtemp needs arguments");
3431 obj->type = OBJ_text;
3432 obj->data.s = strdup("${hddtemp}");
3437 #ifdef TCP_PORT_MONITOR
3438 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3439 int argc, port_begin, port_end, item, connection_index;
3441 memset(itembuf,0,sizeof(itembuf));
3443 /* massive argument checking */
3445 CRIT_ERR("tcp_portmon: needs arguments");
3447 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3448 if ( (argc != 3) && (argc != 4) )
3450 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3452 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3454 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3456 if ( port_begin > port_end )
3458 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3460 if ( strncmp(itembuf,"count",31) == 0 )
3462 else if ( strncmp(itembuf,"rip",31) == 0 )
3464 else if ( strncmp(itembuf,"rhost",31) == 0 )
3466 else if ( strncmp(itembuf,"rport",31) == 0 )
3468 else if ( strncmp(itembuf,"rservice",31) == 0 )
3470 else if ( strncmp(itembuf,"lip",31) == 0 )
3472 else if ( strncmp(itembuf,"lhost",31) == 0 )
3474 else if ( strncmp(itembuf,"lport",31) == 0 )
3476 else if ( strncmp(itembuf,"lservice",31) == 0 )
3480 CRIT_ERR("tcp_portmon: invalid item specified");
3482 if ( (argc==3) && (item!=COUNT) )
3484 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3486 if ( (argc==4) && (connection_index<0) )
3488 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3490 /* ok, args looks good. save the text object data */
3491 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3492 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3493 obj->data.tcp_port_monitor.item = item;
3494 obj->data.tcp_port_monitor.connection_index = connection_index;
3496 /* if the port monitor collection hasn't been created, we must create it */
3497 if ( !info.p_tcp_port_monitor_collection )
3499 info.p_tcp_port_monitor_collection =
3500 create_tcp_port_monitor_collection ();
3501 if ( !info.p_tcp_port_monitor_collection )
3503 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3507 /* if a port monitor for this port does not exist, create one and add it to the collection */
3508 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3510 tcp_port_monitor_t * p_monitor =
3511 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3514 CRIT_ERR("tcp_portmon: unable to create port monitor");
3516 /* add the newly created monitor to the collection */
3517 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3520 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3525 OBJ(entropy_avail, INFO_ENTROPY) END
3526 OBJ(entropy_poolsize, INFO_ENTROPY) END
3527 OBJ(entropy_bar, INFO_ENTROPY)
3528 (void) scan_bar(arg, &obj->a, &obj->b);
3533 ERR("unknown variable %s", s);
3534 obj->type = OBJ_text;
3535 snprintf(buf, 256, "${%s}", s);
3536 obj->data.s = strdup(buf);
3543 static struct text_object *create_plain_text(const char *s)
3545 struct text_object *obj;
3547 if (s == NULL || *s == '\0') {
3551 obj = new_text_object_internal();
3553 obj->type = OBJ_text;
3554 obj->data.s = strdup(s);
3558 static struct text_object_list *extract_variable_text_internal(const char *p)
3560 struct text_object_list *retval;
3561 struct text_object *obj;
3564 retval = malloc(sizeof(struct text_object_list));
3565 memset(retval, 0, sizeof(struct text_object_list));
3566 retval->text_object_count = 0;
3568 long line = text_lines;
3576 obj = create_plain_text(s);
3578 // allocate memory for the object
3579 retval->text_objects = realloc(retval->text_objects,
3580 sizeof(struct text_object) * (retval->text_object_count+1));
3581 // assign the new object to the end of the list.
3582 memcpy(&retval->text_objects[retval->text_object_count++],
3583 obj, sizeof(struct text_object));
3595 /* variable is either $foo or ${foo} */
3597 unsigned int brl = 1, brr = 0;
3600 while (*p && brl != brr) {
3601 if (*p == '{') brl++;
3602 if (*p == '}') brr++;
3610 while (*p && (isalnum((int) *p)
3615 /* copy variable to buffer */
3616 len = (p - s > 255) ? 255 : (p - s);
3617 strncpy(buf, s, len);
3626 /* if variable wasn't found from environment, use some special */
3632 if (strchr(buf, ' ')) {
3633 arg = strchr(buf, ' ');
3636 while (isspace((int) *arg))
3642 /* lowercase variable name */
3649 // create new object
3650 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3652 // allocate memory for the object
3653 retval->text_objects = realloc(retval->text_objects,
3654 sizeof(struct text_object) * (retval->text_object_count+1));
3655 // assign the new object to the end of the list.
3656 memcpy(&retval->text_objects[retval->text_object_count++],
3657 obj, sizeof(struct text_object));
3663 obj = create_plain_text("$");
3665 // allocate memory for the object
3666 retval->text_objects = realloc(retval->text_objects,
3667 sizeof(struct text_object) * (retval->text_object_count+1));
3668 // assign the new object to the end of the list.
3669 memcpy(&retval->text_objects[retval->text_object_count++],
3670 obj, sizeof(struct text_object));
3677 obj = create_plain_text(s);
3679 // allocate memory for the object
3680 retval->text_objects = realloc(retval->text_objects,
3681 sizeof(struct text_object) * (retval->text_object_count+1));
3682 // assign the new object to the end of the list.
3683 memcpy(&retval->text_objects[retval->text_object_count++],
3684 obj, sizeof(struct text_object));
3689 ERR("one or more $endif's are missing");
3695 static void extract_variable_text(const char *p)
3697 struct text_object_list *list;
3699 free_text_objects(text_object_count, text_objects);
3700 text_object_count = 0;
3701 text_objects = NULL;
3704 list = extract_variable_text_internal(p);
3705 text_objects = list->text_objects;
3706 text_object_count = list->text_object_count;
3713 void parse_conky_vars(char * text, char * p, struct information *cur) {
3714 struct text_object_list *object_list = extract_variable_text_internal(text);
3715 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3720 * Allows reading from a FIFO (i.e., /dev/xconsole). The file descriptor is
3721 * set to non-blocking which makes this possible.
3724 * Since lseek cannot seek a file descriptor long lines will break.
3726 static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
3728 #define TAIL_PIPE_BUFSIZE 4096
3732 int fd = obj->data.tail.fd;
3735 char buf[TAIL_PIPE_BUFSIZE];
3736 ssize_t len = read(fd, buf, sizeof(buf));
3740 if (errno != EAGAIN) {
3741 strcpy(obj->data.tail.buffer, "Logfile Read Error");
3742 snprintf(dst, dst_size, "Logfile Read Error");
3747 else if (len == 0) {
3748 strcpy(obj->data.tail.buffer, "Logfile Empty");
3749 snprintf(dst, dst_size, "Logfile Empty");
3753 for (line_len = 0, i = 0; i < len; i++) {
3757 if (buf[i] == '\n') {
3760 if (obj->data.tail.readlines > 0) {
3765 for (n = 0; obj->data.tail.buffer[n]; n++) {
3766 if (obj->data.tail.buffer[n] == '\n') {
3770 if (++olines < obj->data.tail.wantedlines) {
3776 p = obj->data.tail.buffer + first_line;
3777 pos = n - first_line;
3778 memmove(obj->data.tail.buffer, obj->data.tail.buffer + first_line, strlen(p));
3779 obj->data.tail.buffer[pos] = 0;
3785 p = buf + last_line;
3787 memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
3788 obj->data.tail.buffer[pos + line_len] = 0;
3791 obj->data.tail.readlines = lines;
3799 snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
3802 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3807 char buff_in[P_MAX_SIZE] = {0};
3808 iconv_converting = 0;
3811 for (i = 0; i < object_count; i++) {
3812 struct text_object *obj = &objs[i];
3814 #define OBJ(a) break; case OBJ_##a:
3816 switch (obj->type) {
3819 ERR("not implemented obj type %d",
3824 /* does anyone have decimals in acpi temperature? */
3825 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
3826 round_to_int(get_acpi_temperature(obj->data.i)));
3829 /* does anyone have decimals in acpi temperature? */
3830 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
3831 round_to_int((get_acpi_temperature(obj->data.i) + 40) *
3834 #endif /* !__OpenBSD__ */
3837 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3843 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3845 /* OpenBSD has no such flag (SUSv2) */
3846 obj->a = get_freq(p, p_max_size, "%.2f", 1000, obj->data.cpu_index);
3851 #if defined(__linux__)
3854 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3859 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3863 OBJ(wireless_essid) {
3864 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3866 OBJ(wireless_mode) {
3867 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3869 OBJ(wireless_bitrate) {
3870 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3873 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3875 OBJ(wireless_link_qual) {
3876 spaced_print(p, p_max_size, "%d", 4, "wireless_link_qual",
3877 obj->data.net->link_qual);
3879 OBJ(wireless_link_qual_max) {
3880 spaced_print(p, p_max_size, "%d", 4,
3881 "wireless_link_qual_max", obj->data.net->link_qual_max);
3883 OBJ(wireless_link_qual_perc) {
3884 if(obj->data.net->link_qual_max > 0) {
3885 spaced_print(p, p_max_size, "%.0f%%", 5,
3886 "wireless_link_qual_perc",
3887 (double) obj->data.net->link_qual /
3888 obj->data.net->link_qual_max * 100);
3890 spaced_print(p, p_max_size, "unk", 5,
3891 "wireless_link_qual_perc");
3894 OBJ(wireless_link_bar) {
3895 new_bar(p, obj->a, obj->b, ((double)obj->data.net->link_qual/obj->data.net->link_qual_max)*255.0);
3897 #endif /* HAVE_IWLIB */
3899 #endif /* __linux__ */
3902 get_freq_dynamic(p, p_max_size, "%.0f", 1);
3903 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
3907 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3909 get_freq_dynamic(p, p_max_size, "%.2f", 1000);
3911 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
3915 get_adt746x_cpu(p, p_max_size);
3918 get_adt746x_fan(p, p_max_size);
3921 get_acpi_fan(p, p_max_size);
3923 OBJ(acpiacadapter) {
3924 get_acpi_ac_adapter(p, p_max_size);
3927 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3930 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3932 OBJ(battery_percent) {
3933 snprintf(p, p_max_size, "%d",
3934 get_battery_perct(obj->data.s));
3937 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3939 #endif /* __OpenBSD__ */
3941 human_readable(cur->buffers * 1024, p, 255, "buffers");
3944 human_readable(cur->cached * 1024, p, 255, "buffers");
3947 if (obj->data.cpu_index > info.cpu_count) {
3948 printf("obj->data.cpu_index %i info.cpu_count %i",
3949 obj->data.cpu_index, info.cpu_count);
3950 CRIT_ERR("attempting to use more CPUs then you have!");
3952 spaced_print(p, p_max_size, "%*d", 4, "cpu", pad_percents,
3953 round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3959 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3962 new_graph(p, obj->a,
3963 obj->b, obj->c, obj->d,
3964 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3968 new_fg(p, obj->data.l);
4000 #if defined(__linux__)
4002 snprintf(p, p_max_size, "%s", i8k.version);
4005 snprintf(p, p_max_size, "%s", i8k.bios);
4008 snprintf(p, p_max_size, "%s", i8k.serial);
4011 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
4013 OBJ(i8k_cpu_tempf) {
4015 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
4016 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
4018 OBJ(i8k_left_fan_status) {
4019 int left_fan_status;
4020 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
4021 if(left_fan_status == 0) {
4022 snprintf(p, p_max_size,"off");
4023 } if(left_fan_status == 1) {
4024 snprintf(p, p_max_size, "low");
4025 } if(left_fan_status == 2) {
4026 snprintf(p, p_max_size, "high");
4030 OBJ(i8k_right_fan_status) {
4031 int right_fan_status;
4032 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
4033 if(right_fan_status == 0) {
4034 snprintf(p, p_max_size,"off");
4035 } if(right_fan_status == 1) {
4036 snprintf(p, p_max_size, "low");
4037 } if(right_fan_status == 2) {
4038 snprintf(p, p_max_size, "high");
4041 OBJ(i8k_left_fan_rpm) {
4042 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
4044 OBJ(i8k_right_fan_rpm) {
4045 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
4047 OBJ(i8k_ac_status) {
4049 sscanf(i8k.ac_status, "%d", &ac_status);
4050 if(ac_status == -1) {
4051 snprintf(p, p_max_size,"disabled (read i8k docs)");
4052 } if(ac_status == 0) {
4053 snprintf(p, p_max_size, "off");
4054 } if(ac_status == 1) {
4055 snprintf(p, p_max_size, "on");
4058 OBJ(i8k_buttons_status) {
4059 snprintf(p, p_max_size, "%s", i8k.buttons_status);
4063 get_ibm_acpi_fan(p, p_max_size);
4066 get_ibm_acpi_temps();
4067 snprintf(p, p_max_size, "%d",
4068 ibm_acpi.temps[obj->data.sensor]);
4071 get_ibm_acpi_volume(p, p_max_size);
4073 OBJ(ibm_brightness) {
4074 get_ibm_acpi_brightness(p, p_max_size);
4077 get_powerbook_batt_info(p, p_max_size, obj->data.i);
4079 #endif /* __linux__ */
4082 OBJ(obsd_sensors_temp) {
4083 obsd_sensors.device = sensor_device;
4084 update_obsd_sensors();
4085 snprintf(p, p_max_size, "%.1f",
4086 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
4089 OBJ(obsd_sensors_fan) {
4090 obsd_sensors.device = sensor_device;
4091 update_obsd_sensors();
4092 snprintf(p, p_max_size, "%d",
4093 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
4096 OBJ(obsd_sensors_volt) {
4097 obsd_sensors.device = sensor_device;
4098 update_obsd_sensors();
4099 snprintf(p, p_max_size, "%.2f",
4100 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4104 get_obsd_vendor(p, p_max_size);
4108 get_obsd_product(p, p_max_size);
4110 #endif /* __OpenBSD__ */
4114 new_font(p, obj->data.s);
4117 /* TODO: move this correction from kB to kB/s elsewhere
4118 * (or get rid of it??) */
4120 if (obj->data.diskio) {
4121 human_readable((obj->data.diskio->current / update_interval) * 1024LL, p, p_max_size, "diskio");
4123 human_readable(diskio_value * 1024LL, p, p_max_size, "diskio");
4127 if (obj->data.diskio) {
4128 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL, p, p_max_size,
4131 human_readable(diskio_write_value * 1024LL, p, p_max_size,
4136 if (obj->data.diskio) {
4137 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL, p, p_max_size,
4140 human_readable(diskio_read_value * 1024LL, p, p_max_size,
4145 if (obj->data.diskio) {
4146 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4147 obj->data.diskio->current, obj->e, 1);
4149 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4150 diskio_value, obj->e, 1);
4153 OBJ(diskiograph_read) {
4154 if (obj->data.diskio) {
4155 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4156 obj->data.diskio->current_read, obj->e, 1);
4158 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4159 diskio_read_value, obj->e, 1);
4162 OBJ(diskiograph_write) {
4163 if (obj->data.diskio) {
4164 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4165 obj->data.diskio->current_write, obj->e, 1);
4167 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4168 diskio_write_value, obj->e, 1);
4172 spaced_print(p, p_max_size, "%d", 6, "downspeed",
4173 round_to_int(obj->data.net->recv_speed / 1024));
4176 spaced_print(p, p_max_size, "%.1f", 8, "downspeedf",
4177 obj->data.net->recv_speed / 1024.0);
4179 OBJ(downspeedgraph) {
4180 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4181 (obj->data.net->recv_speed / 1024.0), obj->e, 1);
4185 i = obj->data.ifblock.pos - 1;
4195 snprintf(p, p_max_size, "%u.%u.%u.%u",
4196 obj->data.net->addr.
4198 obj->data.net->addr.
4200 obj->data.net->addr.
4202 obj->data.net->addr.
4206 #if defined(IMLIB2) && defined(X11)
4211 Imlib_Image image, buffer;
4212 image = imlib_load_image(obj->data.s);
4213 imlib_context_set_image(image);
4216 w = imlib_image_get_width();
4217 h = imlib_image_get_height();
4218 buffer = imlib_create_image(w, h);
4219 imlib_context_set_display(display);
4220 imlib_context_set_drawable(window.drawable);
4221 imlib_context_set_colormap(DefaultColormap(display, screen));
4222 imlib_context_set_visual(DefaultVisual(display, screen));
4223 imlib_context_set_image(buffer);
4224 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
4225 imlib_render_image_on_drawable(text_start_x, text_start_y);
4227 imlib_context_set_image(image);
4234 FILE *fp = popen(obj->data.s, "r");
4235 int length = fread(p, 1, p_max_size, fp);
4238 /*output[length] = '\0';
4239 if (length > 0 && output[length - 1] == '\n') {
4240 output[length - 1] = '\0';
4243 if (length > 0 && p[length - 1] == '\n') {
4244 p[length - 1] = '\0';
4247 //parse_conky_vars(output, p, cur);
4251 FILE *fp = popen(obj->data.s, "r");
4252 int n2 = fread(p, 1, p_max_size, fp);
4256 if (n2 && p[n2 - 1] == '\n')
4265 if (sscanf(p, "%lf", &barnum) == 0) {
4266 ERR("reading execbar value failed (perhaps it's not the correct format?)");
4268 if (barnum > 100 || barnum < 0) {
4269 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
4271 barnum = barnum / 100.0;
4272 new_bar(p, 0, 4, (int) (barnum * 255.0));
4278 FILE *fp = popen(obj->data.s, "r");
4279 int n2 = fread(p, 1, p_max_size, fp);
4283 if (n2 && p[n2 - 1] == '\n')
4292 if (sscanf(p, "%lf", &barnum) == 0) {
4293 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
4295 if (barnum > 100 || barnum < 0) {
4296 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
4298 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
4303 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
4304 new_bar(p, 0, 4, (int) obj->f);
4307 FILE *fp = popen(obj->data.execi.cmd, "r");
4308 int n2 = fread(p, 1, p_max_size, fp);
4311 if (n2 && p[n2 - 1] == '\n')
4320 if (sscanf(p, "%f", &barnum) == 0) {
4321 ERR("reading execibar value failed (perhaps it's not the correct format?)");
4323 if (barnum > 100 || barnum < 0) {
4324 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
4326 obj->f = 255 * barnum / 100.0;
4327 new_bar(p, 0, 4, (int) obj->f);
4329 obj->data.execi.last_update =
4330 current_update_time;
4334 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
4335 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
4338 FILE *fp = popen(obj->data.execi.cmd, "r");
4339 int n2 = fread(p, 1, p_max_size, fp);
4342 if (n2 && p[n2 - 1] == '\n')
4351 if (sscanf(p, "%f", &barnum) == 0) {
4352 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
4354 if (barnum > 100 || barnum < 0) {
4355 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
4358 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
4360 obj->data.execi.last_update = current_update_time;
4366 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
4367 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4369 char *output = obj->data.execi.buffer;
4370 FILE *fp = popen(obj->data.execi.cmd, "r");
4371 //int length = fread(output, 1, text_buffer_size, fp);
4372 int length = fread(output, 1, text_buffer_size, fp);
4375 output[length] = '\0';
4376 if (length > 0 && output[length - 1] == '\n') {
4377 output[length - 1] = '\0';
4379 obj->data.execi.last_update = current_update_time;
4380 snprintf(p, p_max_size, "%s", output);
4382 //parse_conky_vars(output, p, cur);
4385 if (!obj->data.texeci.p_timed_thread)
4387 obj->data.texeci.p_timed_thread=
4388 timed_thread_create ((void*)threaded_exec, (void*) obj, obj->data.texeci.interval * 1000000);
4389 if (!obj->data.texeci.p_timed_thread)
4390 ERR("Error creating texeci timed thread");
4391 timed_thread_register (obj->data.texeci.p_timed_thread, &obj->data.texeci.p_timed_thread);
4392 if (timed_thread_run (obj->data.texeci.p_timed_thread))
4393 ERR("Error running texeci timed thread");
4395 timed_thread_lock (obj->data.texeci.p_timed_thread);
4396 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4397 timed_thread_unlock (obj->data.texeci.p_timed_thread);
4399 #endif /* HAVE_POPEN */
4401 if (obj->global_mode && info.mail) { // this means we use info
4402 if (!info.mail->p_timed_thread)
4404 info.mail->p_timed_thread =
4405 timed_thread_create ((void*)imap_thread, (void*)info.mail, info.mail->interval * 1000000);
4406 if (!info.mail->p_timed_thread)
4407 ERR("Error creating imap timed thread");
4408 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4409 if (timed_thread_run (info.mail->p_timed_thread))
4410 ERR("Error running imap timed thread");
4412 timed_thread_lock (info.mail->p_timed_thread);
4413 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4414 timed_thread_unlock (info.mail->p_timed_thread);
4415 } else if (obj->data.mail) { // this means we use obj
4416 if (!obj->data.mail->p_timed_thread)
4418 obj->data.mail->p_timed_thread =
4419 timed_thread_create ((void*)imap_thread, (void*)obj->data.mail,
4420 obj->data.mail->interval * 1000000);
4421 if (!obj->data.mail->p_timed_thread)
4422 ERR("Error creating imap timed thread");
4423 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4424 if (timed_thread_run (obj->data.mail->p_timed_thread))
4425 ERR("Error running imap timed thread");
4427 timed_thread_lock (obj->data.mail->p_timed_thread);
4428 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4429 timed_thread_unlock (obj->data.mail->p_timed_thread);
4430 } else if (!obj->a) { // something is wrong, warn once then stop
4431 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4435 OBJ(imap_messages) {
4436 if (obj->global_mode && info.mail) { // this means we use info
4437 if (!info.mail->p_timed_thread)
4439 info.mail->p_timed_thread =
4440 timed_thread_create ((void*)imap_thread, (void*)info.mail, info.mail->interval * 1000000);
4441 if (!info.mail->p_timed_thread)
4442 ERR("Error creating imap timed thread");
4443 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4444 if (timed_thread_run (info.mail->p_timed_thread))
4445 ERR("Error running imap timed thread");
4447 timed_thread_lock (info.mail->p_timed_thread);
4448 snprintf(p, p_max_size, "%lu", info.mail->messages);
4449 timed_thread_unlock (info.mail->p_timed_thread);
4450 } else if (obj->data.mail) { // this means we use obj
4451 if (!obj->data.mail->p_timed_thread)
4453 obj->data.mail->p_timed_thread =
4454 timed_thread_create ((void*)imap_thread, (void*)obj->data.mail,
4455 obj->data.mail->interval * 1000000);
4456 if (!obj->data.mail->p_timed_thread)
4457 ERR("Error creating imap timed thread");
4458 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4459 if (timed_thread_run (obj->data.mail->p_timed_thread))
4460 ERR("Error runninging imap timed thread");
4462 timed_thread_lock (obj->data.mail->p_timed_thread);
4463 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4464 timed_thread_lock (obj->data.mail->p_timed_thread);
4465 } else if (!obj->a) { // something is wrong, warn once then stop
4466 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4471 if (obj->global_mode && info.mail) { // this means we use info
4472 if (!info.mail->p_timed_thread)
4474 info.mail->p_timed_thread =
4475 timed_thread_create ((void*)pop3_thread, (void*)info.mail, info.mail->interval * 1000000);
4476 if (!info.mail->p_timed_thread)
4477 ERR("Error creating pop3 timed thread");
4478 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4479 if (timed_thread_run (info.mail->p_timed_thread))
4480 ERR("Error running pop3 timed thread");
4482 timed_thread_lock (info.mail->p_timed_thread);
4483 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4484 timed_thread_unlock (info.mail->p_timed_thread);
4485 } else if (obj->data.mail) { // this means we use obj
4486 if (!obj->data.mail->p_timed_thread)
4488 obj->data.mail->p_timed_thread =
4489 timed_thread_create ((void*)pop3_thread, (void*)obj->data.mail,
4490 obj->data.mail->interval * 1000000);
4491 if (!obj->data.mail->p_timed_thread)
4492 ERR("Error creating pop3 timed thread");
4493 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4494 if (timed_thread_run (obj->data.mail->p_timed_thread))
4495 ERR("Error running pop3 timed thread");
4497 timed_thread_lock (obj->data.mail->p_timed_thread);
4498 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4499 timed_thread_unlock (obj->data.mail->p_timed_thread);
4500 } else if (!obj->a) { // something is wrong, warn once then stop
4501 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4506 if (obj->global_mode && info.mail) { // this means we use info
4507 if (!info.mail->p_timed_thread)
4509 info.mail->p_timed_thread =
4510 timed_thread_create ((void*)pop3_thread, (void*)info.mail, info.mail->interval * 1000000);
4511 if (!info.mail->p_timed_thread)
4512 ERR("Error creating pop3 timed thread");
4513 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4514 if (timed_thread_run (info.mail->p_timed_thread))
4515 ERR("Error running pop3 timed thread");
4517 timed_thread_lock (info.mail->p_timed_thread);
4518 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4519 timed_thread_unlock (info.mail->p_timed_thread);
4520 } else if (obj->data.mail) { // this means we use obj
4521 if (!obj->data.mail->p_timed_thread)
4523 obj->data.mail->p_timed_thread =
4524 timed_thread_create ((void*)pop3_thread, (void*)obj->data.mail,
4525 obj->data.mail->interval * 1000000);
4526 if (!obj->data.mail->p_timed_thread)
4527 ERR("Error creating pop3 timed thread");
4528 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4529 if (timed_thread_run (obj->data.mail->p_timed_thread))
4530 ERR("Error running pop3 timed thread");
4532 timed_thread_lock (obj->data.mail->p_timed_thread);
4533 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4534 timed_thread_unlock (obj->data.mail->p_timed_thread);
4535 } else if (!obj->a) { // something is wrong, warn once then stop
4536 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4541 if (obj->data.fs != NULL) {
4542 if (obj->data.fs->size == 0)
4561 if (obj->data.fs != NULL) {
4562 human_readable(obj->data.fs->avail, p, 255, "fs_free");
4566 if (obj->data.fs != NULL) {
4567 if (obj->data.fs->size)
4568 snprintf(p, p_max_size, "%*d",
4577 snprintf(p, p_max_size, "0");
4581 if (obj->data.fs != NULL) {
4582 human_readable(obj->data.fs->size, p, 255, "fs_size");
4586 if (obj->data.fs != NULL) {
4587 human_readable(obj->data.fs->size -
4588 (obj->data.fs->free ? obj->data.fs->free :
4589 obj->data.fs->avail), p, 255, "fs_used");
4593 if (obj->data.fs != NULL) {
4594 if (obj->data.fs->size == 0)
4612 if (obj->data.fs != NULL) {
4613 if (obj->data.fs->size)
4614 snprintf(p, 4, "%d",
4624 snprintf(p, p_max_size, "0");
4628 float *v = info.loadavg;
4630 if (obj->data.loadavg[2])
4631 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4632 v[obj->data.loadavg[0] -
4634 v[obj->data.loadavg[1] -
4636 v[obj->data.loadavg[2] -
4638 else if (obj->data.loadavg[1])
4639 snprintf(p, p_max_size, "%.2f %.2f",
4640 v[obj->data.loadavg[0] -
4642 v[obj->data.loadavg[1] -
4644 else if (obj->data.loadavg[0])
4645 snprintf(p, p_max_size, "%.2f",
4646 v[obj->data.loadavg[0] -
4650 new_goto(p, obj->data.i);
4653 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4656 new_hr(p, obj->data.i);
4660 PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay);
4663 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4665 if(!strcmp(obj->data.rss.action, "feed_title")) {
4667 if(str[strlen(str)-1] == '\n')
4668 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4669 snprintf(p, p_max_size, "%s", str);
4670 } else if(!strcmp(obj->data.rss.action, "item_title")) {
4671 if(obj->data.rss.act_par < data->item_count) {
4672 str = data->items[obj->data.rss.act_par].title;
4673 if(str[strlen(str)-1] == '\n')
4674 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4675 snprintf(p, p_max_size, "%s", str);
4677 } else if(!strcmp(obj->data.rss.action, "item_desc")) {
4678 if(obj->data.rss.act_par < data->item_count) {
4679 str = data->items[obj->data.rss.act_par].description;
4680 if(str[strlen(str)-1] == '\n')
4681 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4682 snprintf(p, p_max_size, "%s", str);
4684 } else if(!strcmp(obj->data.rss.action, "item_titles")) {
4685 if(data->item_count > 0) {
4689 if(obj->data.rss.act_par > data->item_count)
4690 show = data->item_count;
4691 else show = obj->data.rss.act_par;
4692 for(itmp = 0; itmp < show; itmp++) {
4693 PRSS_Item *item = &data->items[itmp];
4696 if(itmp>0) // don't add new line before first item
4697 strncat(p, "\n", p_max_size);
4698 if(str[strlen(str)-1] == '\n')
4699 str[strlen(str)-1] = 0; // remove trailing new line if one exists, we have our own
4700 strncat(p, str, p_max_size);
4713 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4714 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4716 snprintf(p, p_max_size, "N/A");
4717 } else if (unit == '*') {
4718 snprintf(p, p_max_size, "%s", temp);
4720 snprintf(p, p_max_size, "%s°%c", temp, unit);
4725 new_offset(p, obj->data.i);
4728 new_voffset(p, obj->data.i);
4734 r = get_sysfs_info(&obj->data.sysfs.fd,
4735 obj->data.sysfs.arg,
4736 obj->data.sysfs.devtype,
4737 obj->data.sysfs.type);
4739 if (r >= 100.0 || r == 0)
4740 snprintf(p, p_max_size, "%d", (int) r);
4742 snprintf(p, p_max_size, "%.1f", r);
4747 r = get_sysfs_info(&obj->data.sysfs.fd,
4748 obj->data.sysfs.arg,
4749 obj->data.sysfs.devtype,
4750 obj->data.sysfs.type);
4752 if (r >= 100.0 || r == 0)
4753 snprintf(p, p_max_size, "%d", (int) r);
4755 snprintf(p, p_max_size, "%.1f", r);
4760 r = get_sysfs_info(&obj->data.sysfs.fd,
4761 obj->data.sysfs.arg,
4762 obj->data.sysfs.devtype,
4763 obj->data.sysfs.type);
4765 if (r >= 100.0 || r == 0)
4766 snprintf(p, p_max_size, "%d", (int) r);
4768 snprintf(p, p_max_size, "%.1f", r);
4770 #endif /* !__OpenBSD__ */
4772 new_alignr(p, obj->data.i);
4775 new_alignc(p, obj->data.i);
4778 struct information *my_info =
4779 malloc(sizeof(struct information));
4780 memcpy(my_info, cur, sizeof(struct information));
4781 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4782 if (strlen(p) != 0) {
4783 i = obj->data.ifblock.pos;
4793 if ((obj->data.ifblock.s)
4794 && (stat(obj->data.ifblock.s, &tmp) ==
4796 i = obj->data.ifblock.pos;
4799 if (obj->data.ifblock.str) {
4800 if (!check_contains(obj->data.ifblock.s,
4801 obj->data.ifblock.str)) {
4802 i = obj->data.ifblock.pos;
4811 if ((obj->data.ifblock.s)
4812 && (!check_mount(obj->data.ifblock.s))) {
4813 i = obj->data.ifblock.pos;
4820 if ((obj->data.ifblock.s)
4821 && system(obj->data.ifblock.s)) {
4822 i = obj->data.ifblock.pos;
4829 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4832 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4837 human_readable(cur->mem * 1024, p, 255, "mem");
4840 human_readable(cur->memmax * 1024, p, 255, "memmax");
4844 spaced_print(p, p_max_size, "%*Lu", 4, "memperc",
4845 pad_percents, cur->mem * 100 / cur->memmax);
4849 new_bar(p, obj->data.pair.a,
4851 cur->memmax ? (cur->mem * 255) /
4856 new_graph(p, obj->a,
4857 obj->b, obj->c, obj->d,
4858 cur->memmax ? (cur->mem * 100.0) /
4859 (cur->memmax) : 0.0, 100, 1);
4863 snprintf(p, p_max_size, "%d",
4864 mixer_get_avg(obj->data.l));
4867 snprintf(p, p_max_size, "%d",
4868 mixer_get_left(obj->data.l));
4871 snprintf(p, p_max_size, "%d",
4872 mixer_get_right(obj->data.l));
4875 new_bar(p, obj->data.mixerbar.w,
4876 obj->data.mixerbar.h,
4877 mixer_get_avg(obj->data.mixerbar.
4881 new_bar(p, obj->data.mixerbar.w,
4882 obj->data.mixerbar.h,
4883 mixer_get_left(obj->data.mixerbar.
4887 new_bar(p, obj->data.mixerbar.w,
4888 obj->data.mixerbar.h,
4889 mixer_get_right(obj->data.mixerbar.
4895 update_mail_count(&obj->data.local_mail);
4896 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
4899 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4900 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4903 update_mail_count(&obj->data.local_mail);
4904 snprintf(p, p_max_size, "%d", obj->data.local_mail.new_mail_count);
4908 snprintf(p, p_max_size, "%s",
4909 cur->uname_s.nodename);
4912 new_outline(p, obj->data.l);
4915 spaced_print(p, p_max_size, "%hu", 5, "processes", cur->procs);
4917 OBJ(running_processes) {
4918 spaced_print(p, p_max_size, "%hu", 3, "running_processes",
4922 snprintf(p, p_max_size, "%s", obj->data.s);
4925 new_bg(p, obj->data.l);
4928 new_stippled_hr(p, obj->data.pair.a,
4932 human_readable(cur->swap * 1024, p, 255, "swap");
4935 human_readable(cur->swapmax * 1024, p, 255, "swapmax");
4938 if (cur->swapmax == 0) {
4939 strncpy(p, "No swap", p_max_size);
4941 spaced_print(p, p_max_size, "%*Lu", 4, "swapperc",
4942 pad_percents, cur->swap * 100 / cur->swapmax);
4946 new_bar(p, obj->data.pair.a,
4948 cur->swapmax ? (cur->swap * 255) /
4949 (cur->swapmax) : 0);
4952 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4955 time_t t = time(NULL);
4956 struct tm *tm = localtime(&t);
4957 setlocale(LC_TIME, "");
4958 strftime(p, p_max_size, obj->data.s, tm);
4961 time_t t = time(NULL);
4962 struct tm *tm = gmtime(&t);
4963 strftime(p, p_max_size, obj->data.s, tm);
4967 if (obj->data.tztime.tz) {
4968 oldTZ = getenv("TZ");
4969 setenv("TZ", obj->data.tztime.tz, 1);
4972 time_t t = time(NULL);
4973 struct tm *tm = localtime(&t);
4974 setlocale(LC_TIME, "");
4975 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4977 setenv("TZ", oldTZ, 1);
4982 // Needless to free oldTZ since getenv gives ptr to static data
4985 human_readable(obj->data.net->recv, p, 255, "totaldown");
4988 human_readable(obj->data.net->trans, p, 255, "totalup");
4991 snprintf(p, p_max_size, "%d", total_updates);
4994 spaced_print(p, p_max_size, "%d", 6, "upspeed",
4995 round_to_int(obj->data.net->trans_speed / 1024));
4998 spaced_print(p, p_max_size, "%.1f", 8, "upspeedf",
4999 obj->data.net->trans_speed / 1024.0);
5002 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5003 (obj->data.net->trans_speed / 1024.0), obj->e, 1);
5006 format_seconds_short(p, p_max_size,
5010 format_seconds(p, p_max_size, (int) cur->uptime);
5013 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5016 msg = get_apm_adapter();
5017 snprintf(p, p_max_size, "%s", msg);
5020 OBJ(apm_battery_life) {
5022 msg = get_apm_battery_life();
5023 snprintf(p, p_max_size, "%s", msg);
5026 OBJ(apm_battery_time) {
5028 msg = get_apm_battery_time();
5029 snprintf(p, p_max_size, "%s", msg);
5032 #endif /* __FreeBSD__ __OpenBSD__ */
5036 snprintf(p, cur->mpd.max_title_len > 0 ?
5037 cur->mpd.max_title_len : p_max_size, "%s",
5041 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5044 snprintf(p, p_max_size, "%s", cur->mpd.album);
5047 snprintf(p, p_max_size, "%s", cur->mpd.random);
5050 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
5053 snprintf(p, p_max_size, "%s", cur->mpd.track);
5056 snprintf(p, p_max_size, "%s", cur->mpd.name);
5059 snprintf(p, p_max_size, "%s", cur->mpd.file);
5062 snprintf(p, p_max_size, "%i", cur->mpd.volume);
5065 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
5068 snprintf(p, p_max_size, "%s", cur->mpd.status);
5071 int days = 0, hours = 0, minutes =
5073 int tmp = cur->mpd.elapsed;
5074 while (tmp >= 86400) {
5078 while (tmp >= 3600) {
5088 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
5089 days, hours, minutes,
5092 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
5095 snprintf(p, p_max_size, "%i:%02i", minutes,
5099 int days = 0, hours = 0, minutes =
5101 int tmp = cur->mpd.length;
5102 while (tmp >= 86400) {
5106 while (tmp >= 3600) {
5116 snprintf(p, p_max_size,
5117 "%i days %i:%02i:%02i",
5118 days, hours, minutes,
5121 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
5124 snprintf(p, p_max_size, "%i:%02i", minutes,
5128 snprintf(p, p_max_size, "%2.0f",
5129 cur->mpd.progress * 100);
5132 new_bar(p, obj->data.pair.a,
5134 (int) (cur->mpd.progress *
5138 memset (p, 0, p_max_size);
5139 if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title && *cur->mpd.title) {
5140 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
5142 else if (cur->mpd.title && *cur->mpd.title) {
5143 snprintf(p, p_max_size, "%s", cur->mpd.title);
5145 else if (cur->mpd.artist && *cur->mpd.artist) {
5146 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5148 else if (cur->mpd.file && *cur->mpd.file) {
5149 snprintf(p, p_max_size, "%s", cur->mpd.file);
5158 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5161 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5164 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5167 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5169 OBJ(xmms2_comment) {
5170 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5172 OBJ(xmms2_decoder) {
5173 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
5175 OBJ(xmms2_transport) {
5176 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
5179 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5182 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5185 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5187 OBJ(xmms2_tracknr) {
5188 if (cur->xmms2.tracknr != -1)
5189 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5191 OBJ(xmms2_bitrate) {
5192 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5195 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5198 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5200 OBJ(xmms2_elapsed) {
5201 int tmp = cur->xmms2.elapsed;
5202 snprintf(p, p_max_size, "%02d:%02d",
5203 tmp / 60000, (tmp / 1000) % 60);
5205 OBJ(xmms2_duration) {
5206 int tmp = cur->xmms2.duration;
5207 snprintf(p, p_max_size, "%02d:%02d",
5208 tmp / 60000, (tmp / 1000) % 60);
5210 OBJ(xmms2_percent) {
5211 snprintf(p, p_max_size, "%2.0f",
5212 cur->xmms2.progress * 100);
5215 new_bar(p, obj->data.pair.a,
5217 (int) (cur->xmms2.progress *
5221 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
5222 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5224 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
5229 OBJ(audacious_status) {
5230 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
5232 OBJ(audacious_title) {
5233 snprintf(p, cur->audacious.max_title_len > 0 ?
5234 cur->audacious.max_title_len : p_max_size, "%s",
5235 cur->audacious.items[AUDACIOUS_TITLE]);
5237 OBJ(audacious_length) {
5238 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
5240 OBJ(audacious_length_seconds) {
5241 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5243 OBJ(audacious_position) {
5244 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
5246 OBJ(audacious_position_seconds) {
5247 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5249 OBJ(audacious_bitrate) {
5250 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
5252 OBJ(audacious_frequency) {
5253 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
5255 OBJ(audacious_channels) {
5256 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
5258 OBJ(audacious_filename) {
5259 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
5261 OBJ(audacious_playlist_length) {
5262 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5264 OBJ(audacious_playlist_position) {
5265 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5267 OBJ(audacious_bar) {
5269 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5270 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5271 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
5276 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5279 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5282 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5285 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5288 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5291 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5295 char *format_time(unsigned long time, const int width) {
5297 unsigned long nt; // narrow time, for speed on
5300 unsigned cc; // centiseconds
5301 unsigned nn; // multi-purpose whatever
5304 cc = nt % 100; // centiseconds past second
5305 nt /= 100; // total seconds
5306 nn = nt % 60; // seconds past the minute
5307 nt /= 60; // total minutes
5308 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u", nt,
5311 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn))
5313 nn = nt % 60; // minutes past the hour
5314 nt /= 60; // total hours
5315 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn))
5317 nn = nt; // now also hours
5318 if (width >= snprintf(buf, sizeof buf, "%uh", nn))
5320 nn /= 24; // now days
5321 if (width >= snprintf(buf, sizeof buf, "%ud", nn))
5323 nn /= 7; // now weeks
5324 if (width >= snprintf(buf, sizeof buf, "%uw", nn))
5326 // well shoot, this outta' fit...
5327 return strdup("<inf>");
5331 if (obj->data.top.type == TOP_NAME
5332 && obj->data.top.num >= 0
5333 && obj->data.top.num < 10) {
5334 snprintf(p, 17, "%-17s", cur->cpu[obj->data.top.num]->name);
5335 } else if (obj->data.top.type == TOP_CPU
5336 && obj->data.top.num >= 0
5337 && obj->data.top.num < 10) {
5338 snprintf(p, 7, "%7.3f",
5339 cur->cpu[obj->data.top.
5341 } else if (obj->data.top.type == TOP_PID
5342 && obj->data.top.num >= 0
5343 && obj->data.top.num < 10) {
5344 snprintf(p, 8, "%7i",
5345 cur->cpu[obj->data.top.
5347 } else if (obj->data.top.type == TOP_MEM
5348 && obj->data.top.num >= 0
5349 && obj->data.top.num < 10) {
5350 snprintf(p, 7, "%7.3f",
5351 cur->cpu[obj->data.top.
5353 } else if (obj->data.top.type == TOP_TIME
5354 && obj->data.top.num >= 0
5355 && obj->data.top.num < 10) {
5356 char *time = format_time(cur->cpu[obj->data.top.num]->
5358 snprintf(p, 10, "%9s", time);
5363 if (obj->data.top.type == TOP_NAME
5364 && obj->data.top.num >= 0
5365 && obj->data.top.num < 10) {
5366 snprintf(p, 17, "%-17s",
5367 cur->memu[obj->data.top.
5369 } else if (obj->data.top.type == TOP_CPU
5370 && obj->data.top.num >= 0
5371 && obj->data.top.num < 10) {
5372 snprintf(p, 7, "%7.3f",
5373 cur->memu[obj->data.top.
5375 } else if (obj->data.top.type == TOP_PID
5376 && obj->data.top.num >= 0
5377 && obj->data.top.num < 10) {
5378 snprintf(p, 8, "%7i",
5379 cur->memu[obj->data.top.
5381 } else if (obj->data.top.type == TOP_MEM
5382 && obj->data.top.num >= 0
5383 && obj->data.top.num < 10) {
5384 snprintf(p, 7, "%7.3f",
5385 cur->memu[obj->data.top.
5387 } else if (obj->data.top.type == TOP_TIME
5388 && obj->data.top.num >= 0
5389 && obj->data.top.num < 10) {
5390 char *time = format_time(cur->memu[obj->data.top.num]->
5392 snprintf(p, 10, "%9s", time);
5399 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5400 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5402 obj->data.tail.last_update = current_update_time;
5407 if (obj->data.tail.fd != -1) {
5408 tail_pipe(obj, p, p_max_size);
5412 fp = fopen(obj->data.tail.logfile, "rt");
5415 /* Send one message, but do not consistently spam on
5416 * missing logfiles. */
5417 if(obj->data.tail.readlines != 0) {
5418 ERR("tail logfile failed to open");
5419 strcpy(obj->data.tail.buffer, "Logfile Missing");
5421 obj->data.tail.readlines = 0;
5422 snprintf(p, p_max_size, "Logfile Missing");
5425 obj->data.tail.readlines = 0;
5426 /* -1 instead of 0 to avoid counting a trailing newline */
5427 fseek(fp, -1, SEEK_END);
5428 bsize = ftell(fp) + 1;
5429 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5430 nl = rev_fcharfind(fp, '\n', iter);
5434 obj->data.tail.readlines = iter;
5435 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
5436 fseek(fp, 0, SEEK_SET);
5439 fseek(fp, nl+1, SEEK_SET);
5442 /* Make sure bsize is at least 1 byte smaller than
5443 * the buffer max size. */
5444 if(bsize > (long)((text_buffer_size*20) - 1)) {
5445 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
5446 bsize = text_buffer_size*20 - 1;
5448 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5451 /* Clean up trailing newline, make sure the buffer
5452 * is null terminated. */
5453 if(obj->data.tail.buffer[bsize-1] == '\n')
5454 obj->data.tail.buffer[bsize-1] = '\0';
5456 obj->data.tail.buffer[bsize] = '\0';
5457 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5460 strcpy(obj->data.tail.buffer, "Logfile Empty");
5461 snprintf(p, p_max_size, "Logfile Empty");
5464 } /* if cur_upd_time >= */
5466 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5471 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5472 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5474 obj->data.tail.last_update = current_update_time;
5478 fp = fopen(obj->data.tail.logfile, "rt");
5480 /* Send one message, but do not consistently spam on
5481 * missing logfiles. */
5482 if(obj->data.tail.readlines != 0) {
5483 ERR("head logfile failed to open");
5484 strcpy(obj->data.tail.buffer, "Logfile Missing");
5486 obj->data.tail.readlines = 0;
5487 snprintf(p, p_max_size, "Logfile Missing");
5489 obj->data.tail.readlines = 0;
5490 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5491 nl = fwd_fcharfind(fp, '\n', iter);
5495 obj->data.tail.readlines = iter;
5496 /* Make sure nl is at least 1 byte smaller than
5497 * the buffer max size. */
5498 if(nl > (long)((text_buffer_size*20) - 1)) {
5499 nl = text_buffer_size*20 - 1;
5501 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5504 /* Clean up trailing newline, make sure the buffer
5505 * is null terminated. */
5506 if (obj->data.tail.buffer[nl-1] == '\n') {
5507 obj->data.tail.buffer[nl-1] = '\0';
5510 obj->data.tail.buffer[nl] = '\0';
5512 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5515 strcpy(obj->data.tail.buffer, "Logfile Empty");
5516 snprintf(p, p_max_size, "Logfile Empty");
5518 } /* if fp == null */
5519 } /* cur_upd_time >= */
5521 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5524 #ifdef TCP_PORT_MONITOR
5527 /* grab a pointer to this port monitor */
5528 tcp_port_monitor_t * p_monitor =
5529 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
5530 obj->data.tcp_port_monitor.port_range_begin,
5531 obj->data.tcp_port_monitor.port_range_end );
5533 snprintf(p, p_max_size, "monitor not found");
5537 /* now grab the text of interest */
5538 if ( peek_tcp_port_monitor( p_monitor,
5539 obj->data.tcp_port_monitor.item,
5540 obj->data.tcp_port_monitor.connection_index,
5541 p, p_max_size ) != 0 )
5543 snprintf(p, p_max_size, "monitor peek error");
5552 iconv_converting = 1;
5553 iconv_selected = obj->a;
5558 iconv_converting = 0;
5564 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5566 OBJ(entropy_poolsize)
5568 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5572 double entropy_perc;
5573 entropy_perc = (double)cur->entropy.entropy_avail /
5574 (double)cur->entropy.poolsize;
5575 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5583 unsigned int a = strlen(p);
5586 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5588 size_t dummy1, dummy2;
5589 char *ptr = buff_in;
5592 dummy1 = dummy2 = a;
5594 strncpy(buff_in, p, P_MAX_SIZE);
5596 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5597 while (dummy1 > 0) {
5598 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5600 ERR("Iconv codeset conversion failed");
5605 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5616 double current_update_time, last_update_time;
5618 static void generate_text()
5620 struct information *cur = &info;
5628 current_update_time = get_time();
5631 /* fix diskio rates to b/s (use update_interval */
5632 diskio_read_value = diskio_read_value / update_interval;
5633 diskio_write_value = diskio_write_value / update_interval;
5634 diskio_value = diskio_value / update_interval;
5637 /* add things to the buffer */
5643 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5645 if (stuff_in_upper_case) {
5656 last_update_time = current_update_time;
5663 static void set_font()
5667 if (window.xftdraw != NULL) {
5668 XftDrawDestroy(window.xftdraw);
5670 window.xftdraw = XftDrawCreate(display, window.drawable,
5671 DefaultVisual(display,
5673 DefaultColormap(display,
5678 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5684 static inline int get_string_width(const char *s)
5687 return *s ? calc_text_width(s, strlen(s)) : 0;
5693 static inline int get_string_width_special(char *s)
5706 if (*p == SPECIAL_CHAR) {
5707 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5708 for (i = 0; i < strlen(p); i++) {
5709 *(p + i) = *(p + i + 1);
5711 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5712 width += specials[special_index+index].width;
5719 if (strlen(final) > 1) {
5720 width += calc_text_width(final, strlen(final));
5730 static void text_size_updater(char *s);
5732 int last_font_height;
5733 static void update_text_area()
5737 /* update text size if it isn't fixed */
5742 text_width = minimum_width;
5745 last_font_height = font_height();
5746 for_each_line(text_buffer, text_size_updater);
5748 if (text_height < minimum_height)
5749 text_height = minimum_height;
5750 if (text_width > maximum_width && maximum_width > 0)
5751 text_width = maximum_width;
5754 /* get text position on workarea */
5755 switch (text_alignment) {
5762 x = workarea[2] - text_width - gap_x;
5769 y = workarea[3] - text_height - gap_y;
5773 x = workarea[2] - text_width - gap_x;
5774 y = workarea[3] - text_height - gap_y;
5778 case NONE: // Let the WM manage the window
5789 if (own_window && !fixed_pos) {
5792 text_start_x = border_margin + 1;
5793 text_start_y = border_margin + 1;
5794 window.x = x - border_margin - 1;
5795 window.y = y - border_margin - 1;
5799 /* If window size doesn't match to workarea's size, then window
5800 * probably includes panels (gnome).
5801 * Blah, doesn't work on KDE. */
5802 if (workarea[2] != window.width
5803 || workarea[3] != window.height) {
5817 static int cur_x, cur_y; /* current x and y for drawing */
5818 static int draw_mode; /* FG, BG or OUTLINE */
5819 static long current_color;
5822 static void text_size_updater(char *s)
5826 /* get string widths and skip specials */
5829 if (*p == SPECIAL_CHAR) {
5831 w += get_string_width(s);
5834 if (specials[special_index].type == BAR
5835 || specials[special_index].type == GRAPH) {
5836 w += specials[special_index].width;
5837 if (specials[special_index].height > last_font_height) {
5838 last_font_height = specials[special_index].height;
5839 last_font_height += font_ascent();
5841 } else if (specials[special_index].type == OFFSET) {
5842 if (specials[special_index].arg > 0) {
5843 w += specials[special_index].arg;
5845 } else if (specials[special_index].type == VOFFSET) {
5846 last_font_height += specials[special_index].arg;
5847 } else if (specials[special_index].type == GOTO) {
5848 if (specials[special_index].arg > cur_x) {
5849 w = (int)specials[special_index].arg;
5851 } else if (specials[special_index].type == TAB) {
5852 int start = specials[special_index].arg;
5853 int step = specials[special_index].width;
5854 if (!step || step < 0)
5856 w += step - (cur_x - text_start_x - start) % step;
5857 } else if (specials[special_index].type == FONT) {
5858 selected_font = specials[special_index].font_added;
5859 if (font_height() > last_font_height) {
5860 last_font_height = font_height();
5869 w += get_string_width(s);
5870 if (w > text_width) {
5873 if (text_width > maximum_width && maximum_width) {
5874 text_width = maximum_width;
5877 text_height += last_font_height;
5878 last_font_height = font_height();
5882 static inline void set_foreground_color(long c)
5885 XSetForeground(display, window.gc, c);
5889 static void draw_string(const char *s)
5893 int i, i2, pos, width_of_s;
5896 width_of_s = get_string_width(s);
5897 if (out_to_console) {
5899 fflush(stdout); /* output immediately, don't buffer */
5901 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5902 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5903 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5907 snprintf(space, 2, " ");
5909 max = ((text_width - width_of_s) / get_string_width(space));
5912 * This code looks for tabs in the text and coverts them to spaces.
5913 * The trick is getting the correct number of spaces,
5914 * and not going over the window's size without forcing
5915 * the window larger.
5917 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5918 if (tmpstring1[i] == '\t') // 9 is ascii tab
5922 i2 < (8 - (1 + pos) % 8) && added <= max;
5925 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5926 fprintf(stderr,"buffer overrun detected\n");
5928 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5933 if (tmpstring1[i] != 9) {
5935 if ( pos > TEXT_BUFFER_SIZE-1 )
5936 fprintf(stderr,"buffer overrun detected\n");
5938 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5944 if (text_width == maximum_width) {
5945 /* this means the text is probably pushing the limit, so we'll chop it */
5946 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5947 tmpstring2[strlen(tmpstring2)-1] = '\0';
5957 c.pixel = current_color;
5958 XQueryColor(display, DefaultColormap(display, screen), &c);
5961 c2.color.red = c.red;
5962 c2.color.green = c.green;
5963 c2.color.blue = c.blue;
5964 c2.color.alpha = fonts[selected_font].font_alpha;
5966 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5967 cur_x, cur_y, (XftChar8 *) s,
5970 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5971 cur_x, cur_y, (XftChar8 *) s,
5977 XDrawString(display, window.drawable, window.gc,
5978 cur_x, cur_y, s, strlen(s));
5980 cur_x += width_of_s;
5982 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5985 long redmask, greenmask, bluemask;
5987 void set_up_gradient()
5990 colour_depth = DisplayPlanes(display, screen);
5994 if (colour_depth != 24 && colour_depth != 16) {
5995 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
6001 for(i = (colour_depth / 3)-1; i>=0; i--) {
6003 greenmask |= 1 << i;
6006 if (colour_depth%3 == 1) {
6007 greenmask |= 1 << (colour_depth / 3);
6009 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
6010 greenmask = greenmask << (colour_depth / 3);
6013 inline unsigned long do_gradient(unsigned long first_colour, unsigned long last_colour) { /* this function returns the next colour between two colours for a gradient */
6015 int red1, green1, blue1; // first colour
6016 int red2, green2, blue2; // second colour
6017 int red3 = 0, green3 = 0, blue3 = 0; // difference
6018 short redshift = (2*colour_depth / 3 + colour_depth%3);
6019 short greenshift = (colour_depth / 3);
6020 red1 = (first_colour & redmask) >> redshift;
6021 green1 = (first_colour & greenmask) >> greenshift;
6022 blue1 = first_colour & bluemask;
6023 red2 = (last_colour & redmask) >> redshift;
6024 green2 = (last_colour & greenmask) >> greenshift;
6025 blue2 = last_colour & bluemask;
6032 if (green1 > green2) {
6035 if (green1 < green2) {
6038 if (blue1 > blue2) {
6041 if (blue1 < blue2) {
6056 if (red1 > bluemask) {
6059 if (green1 > bluemask) {
6062 if (blue1 > bluemask) {
6065 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
6069 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
6070 if (colour_depth == 0) {
6073 int red1, green1, blue1; // first colour
6074 int red2, green2, blue2; // second colour
6075 long redshift = (2*colour_depth / 3 + colour_depth%3);
6076 long greenshift = (colour_depth / 3);
6077 int red3 = 0, green3 = 0, blue3 = 0; // difference
6078 red1 = (first_colour & redmask) >> redshift;
6079 green1 = (first_colour & greenmask) >> greenshift;
6080 blue1 = first_colour & bluemask;
6081 red2 = (last_colour & redmask) >> redshift;
6082 green2 = (last_colour & greenmask) >> greenshift;
6083 blue2 = last_colour & bluemask;
6084 red3 = abs(red1 - red2);
6085 green3 = abs(green1 - green2);
6086 blue3 = abs(blue1 - blue2);
6095 static void draw_line(char *s)
6099 cur_x = text_start_x;
6100 cur_y += font_ascent();
6102 short font_h = font_height();
6104 /* find specials and draw stuff */
6107 if (*p == SPECIAL_CHAR) {
6110 /* draw string before special */
6117 switch (specials[special_index].type) {
6118 case HORIZONTAL_LINE:
6121 specials[special_index].height;
6122 int mid = font_ascent() / 2;
6123 w = text_start_x + text_width -
6126 XSetLineAttributes(display,
6131 XDrawLine(display, window.drawable,
6142 specials[special_index].height;
6144 specials[special_index].arg;
6145 int mid = font_ascent() / 2;
6146 char ss[2] = { s, s };
6147 w = text_start_x + text_width -
6150 XSetLineAttributes(display,
6155 XSetDashes(display, window.gc, 0,
6157 XDrawLine(display, window.drawable,
6167 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
6171 specials[special_index].height;
6173 specials[special_index].arg;
6174 int by = cur_y - (font_ascent() / 2) - 1;
6175 if (h < font_height()) {
6178 w = specials[special_index].width;
6181 text_width - cur_x - 1;
6185 XSetLineAttributes(display,
6191 XDrawRectangle(display,
6195 XFillRectangle(display,
6199 w * bar_usage / 255,
6201 if (specials[special_index].
6203 && specials[special_index].
6207 [special_index].height;
6214 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
6218 specials[special_index].height;
6219 unsigned long last_colour = current_color;
6220 int by = cur_y - (font_ascent()/2) - 1;
6221 if (h < font_height()) {
6224 w = specials[special_index].width;
6226 w = text_start_x + text_width - cur_x - 1;
6229 if (draw_graph_borders) {
6230 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
6231 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
6233 XSetLineAttributes(display,
6240 int gradient_size = 0;
6241 float gradient_factor = 0;
6242 float gradient_update = 0;
6243 unsigned long tmpcolour = current_color;
6244 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
6245 tmpcolour = specials[special_index].last_colour;
6246 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
6247 gradient_factor = (float)gradient_size / (w - 2);
6249 for (i = w - 2; i > -1; i--) {
6250 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
6251 XSetForeground(display, window.gc, tmpcolour);
6252 gradient_update += gradient_factor;
6253 while (gradient_update > 0) {
6254 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
6258 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
6261 XDrawLine(display, window.drawable, window.gc, cur_x + i + 1, by + h, cur_x + i + 1, by + h - specials[special_index].graph[j] * (h - 1) / specials[special_index].graph_scale); /* this is mugfugly, but it works */
6263 if (specials[special_index].
6265 && specials[special_index].
6269 [special_index].height;
6271 /* if (draw_mode == BG) {
6272 set_foreground_color(default_bg_color);
6274 else if (draw_mode == OUTLINE) {
6275 set_foreground_color(default_out_color);
6277 set_foreground_color(default_fg_color);
6279 set_foreground_color(last_colour);
6285 int old = font_ascent();
6286 cur_y -= font_ascent();
6287 selected_font = specials[special_index].font_added;
6288 if (cur_y + font_ascent() < cur_y + old) {
6291 cur_y += font_ascent();
6297 if (draw_mode == FG)
6298 set_foreground_color(specials
6304 if (draw_mode == BG)
6305 set_foreground_color(specials
6311 if (draw_mode == OUTLINE)
6312 set_foreground_color(specials
6318 w += specials[special_index].arg;
6322 cur_y += specials[special_index].arg;
6326 if (specials[special_index].arg >= 0)
6327 cur_x = (int)specials[special_index].arg;
6332 int start = specials[special_index].arg;
6333 int step = specials[special_index].width;
6334 if (!step || step < 0)
6336 w = step - (cur_x - text_start_x - start) % step;
6342 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
6343 /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i border_margin %i border_width %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width_special(s), gap_x, specials[special_index].arg, border_margin, border_width);*/
6344 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6345 cur_x = pos_x - specials[special_index].arg;
6352 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
6353 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
6354 /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width(s), gap_x, specials[special_index].arg);*/
6356 specials[special_index].arg)
6359 [special_index].arg;
6376 if (cur_y_add > 0) {
6378 cur_y -= font_descent();
6383 cur_y += font_descent();
6387 static void draw_text()
6390 cur_y = text_start_y;
6393 if (draw_borders && border_width > 0) {
6394 unsigned int b = (border_width + 1) / 2;
6396 if (stippled_borders) {
6398 { stippled_borders, stippled_borders };
6399 XSetLineAttributes(display, window.gc,
6400 border_width, LineOnOffDash,
6401 CapButt, JoinMiter);
6402 XSetDashes(display, window.gc, 0, ss, 2);
6404 XSetLineAttributes(display, window.gc,
6405 border_width, LineSolid,
6406 CapButt, JoinMiter);
6409 XDrawRectangle(display, window.drawable, window.gc,
6410 text_start_x - border_margin + b,
6411 text_start_y - border_margin + b,
6412 text_width + border_margin * 2 - 1 - b * 2,
6413 text_height + border_margin * 2 - 1 -
6420 for_each_line(text_buffer, draw_line);
6423 static void draw_stuff()
6427 if (draw_shades && !draw_outline) {
6430 set_foreground_color(default_bg_color);
6440 for (i = -1; i < 2; i++)
6441 for (j = -1; j < 2; j++) {
6442 if (i == 0 && j == 0)
6446 set_foreground_color(default_out_color);
6447 draw_mode = OUTLINE;
6454 set_foreground_color(default_fg_color);
6462 swap.swap_window = window.window;
6463 swap.swap_action = XdbeBackground;
6464 XdbeSwapBuffers(display, &swap, 1);
6470 static void clear_text(int exposures)
6474 return; /* The swap action is XdbeBackground, which clears */
6478 /* there is some extra space for borders and outlines */
6479 XClearArea(display, window.window,
6480 text_start_x - border_margin - 1,
6481 text_start_y - border_margin - 1,
6482 text_width + border_margin * 2 + 2,
6483 text_height + border_margin * 2 + 2,
6484 exposures ? True : 0);
6489 static int need_to_update;
6491 /* update_text() generates new text and clears old text area */
6492 static void update_text()
6501 static void main_loop()
6503 #ifdef SIGNAL_BLOCKING
6504 sigset_t newmask, oldmask;
6506 sigemptyset(&newmask);
6507 sigaddset(&newmask,SIGINT);
6508 sigaddset(&newmask,SIGTERM);
6509 sigaddset(&newmask,SIGUSR1);
6513 Region region = XCreateRegion();
6515 int event_base, error_base;
6516 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
6517 ERR("Xdamage extension unavailable");
6519 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
6520 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
6521 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
6522 #endif /* HAVE_XDAMAGE */
6526 while (total_run_times == 0 || info.looped < total_run_times) {
6529 #ifdef SIGNAL_BLOCKING
6530 /* block signals. we will inspect for pending signals later */
6531 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
6532 CRIT_ERR("unable to sigprocmask()");
6538 /* wait for X event or timeout */
6540 if (!XPending(display)) {
6545 update_interval - (get_time() -
6551 tv.tv_sec = (long) t;
6552 tv.tv_usec = (long) (t * 1000000) % 1000000;
6554 FD_SET(ConnectionNumber(display), &fdsr);
6557 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
6560 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
6565 ERR("can't select(): %s",
6576 if (need_to_update) {
6578 int wx = window.x, wy = window.y;
6586 /* resize window if it isn't right size */
6588 (text_width + border_margin * 2 + 1 !=
6590 || text_height + border_margin * 2 + 1 !=
6594 border_margin * 2 + 1;
6597 border_margin * 2 + 1;
6598 XResizeWindow(display,
6603 set_transparent_background(window.window);
6607 /* move window if it isn't in right position */
6610 || window.y != wy)) {
6611 XMoveWindow(display, window.window,
6612 window.x, window.y);
6622 r.x = text_start_x - border_margin;
6623 r.y = text_start_y - border_margin;
6624 r.width = text_width + border_margin * 2;
6625 r.height = text_height + border_margin * 2;
6626 XUnionRectWithRegion(&r, region, region);
6631 /* handle X events */
6633 while (XPending(display)) {
6635 XNextEvent(display, &ev);
6642 r.width = ev.xexpose.width;
6643 r.height = ev.xexpose.height;
6644 XUnionRectWithRegion(&r, region,
6650 case ReparentNotify:
6651 /* set background to ParentRelative for all parents */
6653 set_transparent_background(window.
6658 case ConfigureNotify:
6660 /* if window size isn't what expected, set fixed size */
6661 if (ev.xconfigure.width !=
6663 || ev.xconfigure.height !=
6665 if (window.width != 0
6666 && window.height != 0)
6669 /* clear old stuff before screwing up size and pos */
6675 if (XGetWindowAttributes(display, window.window, &attrs)) {
6690 border_margin * 2 - 1;
6693 border_margin * 2 - 1;
6694 if (text_width > maximum_width && maximum_width > 0)
6695 text_width = maximum_width;
6698 /* if position isn't what expected, set fixed pos, total_updates
6699 * avoids setting fixed_pos when window is set to weird locations
6701 /*if (total_updates >= 2 this is broken
6703 && (window.x != ev.xconfigure.x
6706 && (ev.xconfigure.x != 0
6707 || ev.xconfigure.y != 0)) {
6717 /* if an ordinary window with decorations */
6718 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6720 /* allow conky to hold input focus.*/
6725 /* forward the click to the desktop window */
6726 XUngrabPointer(display, ev.xbutton.time);
6727 ev.xbutton.window = window.desktop;
6728 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6729 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6737 /* if an ordinary window with decorations */
6738 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6740 /* allow conky to hold input focus.*/
6745 /* forward the release to the desktop window */
6746 ev.xbutton.window = window.desktop;
6747 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6756 if (ev.type == event_base + XDamageNotify) {
6757 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6758 XFixesSetRegion(display, part, &dev->area, 1);
6759 XFixesUnionRegion(display, region2, region2, part);
6761 #endif /* HAVE_XDAMAGE */
6766 XDamageSubtract(display, damage, region2, None);
6767 XFixesSetRegion(display, region2, 0, 0);
6768 #endif /* HAVE_XDAMAGE */
6770 /* XDBE doesn't seem to provide a way to clear the back buffer without
6771 * interfering with the front buffer, other than passing XdbeBackground
6772 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6773 * redraw the text even if it wasn't part of the exposed area. OTOH,
6774 * if we're not going to call draw_stuff at all, then no swap happens
6775 * and we can safely do nothing.
6778 if (!XEmptyRegion(region)) {
6782 r.x = text_start_x - border_margin;
6783 r.y = text_start_y - border_margin;
6784 r.width = text_width + border_margin * 2;
6785 r.height = text_height + border_margin * 2;
6786 XUnionRectWithRegion(&r, region, region);
6789 XSetRegion(display, window.gc, region);
6792 XftDrawSetClip(window.xftdraw, region);
6798 XDestroyRegion(region);
6799 region = XCreateRegion();
6803 #ifdef SIGNAL_BLOCKING
6804 /* unblock signals of interest and let handler fly */
6805 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6806 CRIT_ERR("unable to sigprocmask()");
6809 switch(g_signal_pending) {
6812 ERR("received SIGUSR1. reloading the config file.");
6819 ERR("received SIGINT or SIGTERM to terminate. bye!");
6822 XDestroyRegion(region);
6825 return; /* return from main_loop */
6830 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6831 * but didn't write any code to deal with it. if you don't want to
6832 * handle a signal, don't set a handler on it in the first place. */
6833 if (g_signal_pending)
6834 ERR("ignoring signal (%d)", g_signal_pending);
6841 #if defined(X11) && defined(HAVE_XDAMAGE)
6842 XDamageDestroy(display, damage);
6843 XFixesDestroyRegion(display, region2);
6844 XFixesDestroyRegion(display, part);
6845 XDestroyRegion(region);
6847 #endif /* X11 && HAVE_XDAMAGE */
6850 static void load_config_file(const char *);
6852 /* reload the config file */
6853 void reload_config(void)
6855 timed_thread_destroy_registered_threads ();
6857 if (info.cpu_usage) {
6858 free(info.cpu_usage);
6859 info.cpu_usage = NULL;
6868 if (info.mpd.title) {
6869 free(info.mpd.title);
6872 if (info.mpd.artist) {
6873 free(info.mpd.artist);
6874 info.mpd.artist = 0;
6876 if (info.mpd.album) {
6877 free(info.mpd.album);
6880 if (info.mpd.random) {
6881 free(info.mpd.random);
6882 info.mpd.random = 0;
6884 if (info.mpd.repeat) {
6885 free(info.mpd.repeat);
6886 info.mpd.repeat = 0;
6888 if (info.mpd.track) {
6889 free(info.mpd.track);
6892 if (info.mpd.name) {
6893 free(info.mpd.name);
6896 if (info.mpd.file) {
6897 free(info.mpd.file);
6900 if (info.mpd.status) {
6901 free(info.mpd.status);
6902 info.mpd.status = 0;
6910 #ifdef TCP_PORT_MONITOR
6911 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6914 if (current_config) {
6916 load_config_file(current_config);
6918 /* re-init specials array */
6919 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6920 ERR("failed to realloc specials array");
6925 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6928 #ifdef TCP_PORT_MONITOR
6929 info.p_tcp_port_monitor_collection = NULL;
6932 if (create_audacious_thread() !=0)
6933 CRIT_ERR("unable to create audacious thread!");
6934 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6936 extract_variable_text(text);
6945 timed_thread_destroy_registered_threads ();
6947 if (info.cpu_usage) {
6948 free(info.cpu_usage);
6949 info.cpu_usage = NULL;
6954 XdbeDeallocateBackBufferName(display, window.back_buffer);
6960 XDestroyWindow(display, window.window);
6961 XClearWindow(display, RootWindow(display, screen));
6967 XClearWindow(display, RootWindow(display, screen));
6972 XFreeGC(display, window.gc);
6976 free_text_objects(text_object_count, text_objects);
6977 text_object_count = 0;
6978 text_objects = NULL;
6983 free(current_config);
6985 #ifdef TCP_PORT_MONITOR
6986 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6987 info.p_tcp_port_monitor_collection = NULL;
6995 for(i=0;i<special_count;i++)
6996 if(specials[i].type == GRAPH)
6997 free(specials[i].graph);
7002 clear_diskio_stats();
7005 static int string_to_bool(const char *s)
7009 if (strcasecmp(s, "yes") == 0)
7011 if (strcasecmp(s, "true") == 0)
7013 if (strcasecmp(s, "1") == 0)
7018 static enum alignment string_to_alignment(const char *s)
7020 if (strcasecmp(s, "top_left") == 0)
7022 else if (strcasecmp(s, "top_right") == 0)
7024 else if (strcasecmp(s, "bottom_left") == 0)
7026 else if (strcasecmp(s, "bottom_right") == 0)
7027 return BOTTOM_RIGHT;
7028 else if (strcasecmp(s, "tl") == 0)
7030 else if (strcasecmp(s, "tr") == 0)
7032 else if (strcasecmp(s, "bl") == 0)
7034 else if (strcasecmp(s, "br") == 0)
7035 return BOTTOM_RIGHT;
7036 else if (strcasecmp(s, "none") == 0)
7043 static void set_default_configurations(void)
7045 fork_to_background = 0;
7046 total_run_times = 0;
7047 info.cpu_avg_samples = 2;
7048 info.net_avg_samples = 2;
7055 strcpy(info.mpd.host, "localhost");
7056 info.mpd.port = 6600;
7057 info.mpd.status = NULL;
7058 info.mpd.artist = NULL;
7059 info.mpd.album = NULL;
7060 info.mpd.title = NULL;
7061 info.mpd.random = NULL;
7062 info.mpd.track = NULL;
7063 info.mpd.name = NULL;
7064 info.mpd.file = NULL;
7067 info.xmms2.artist = NULL;
7068 info.xmms2.album = NULL;
7069 info.xmms2.title = NULL;
7070 info.xmms2.genre = NULL;
7071 info.xmms2.comment = NULL;
7072 info.xmms2.decoder = NULL;
7073 info.xmms2.transport = NULL;
7074 info.xmms2.url = NULL;
7075 info.xmms2.status = NULL;
7077 use_spacer = NO_SPACER;
7084 default_fg_color = WhitePixel(display, screen);
7085 default_bg_color = BlackPixel(display, screen);
7086 default_out_color = BlackPixel(display, screen);
7087 color0 = default_fg_color;
7088 color1 = default_fg_color;
7089 color2 = default_fg_color;
7090 color3 = default_fg_color;
7091 color4 = default_fg_color;
7092 color5 = default_fg_color;
7093 color6 = default_fg_color;
7094 color7 = default_fg_color;
7095 color8 = default_fg_color;
7096 color9 = default_fg_color;
7099 draw_graph_borders = 1;
7101 set_first_font("6x10");
7109 window.type=TYPE_NORMAL;
7111 strcpy(window.class_name, "Conky");
7113 sprintf(window.title,"Conky (%s)",info.uname_s.nodename);
7115 stippled_borders = 0;
7118 text_alignment = BOTTOM_LEFT;
7121 free(current_mail_spool);
7124 variable_substitute(MAIL_FILE, buf, 256);
7126 current_mail_spool = strdup(buf);
7130 update_interval = 3.0;
7131 info.music_player_interval = 1.0;
7132 stuff_in_upper_case = 0;
7134 #ifdef TCP_PORT_MONITOR
7135 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7139 static void load_config_file(const char *f)
7141 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7145 set_default_configurations();
7151 char buf[256], *p, *p2, *name, *value;
7153 if (fgets(buf, 256, fp) == NULL)
7158 /* break at comment */
7159 p2 = strchr(p, '#');
7164 while (*p && isspace((int) *p))
7167 continue; /* empty line */
7173 while (*p2 && !isspace((int) *p2))
7176 *p2 = '\0'; /* break at name's end */
7183 while (*p && isspace((int) *p))
7188 p2 = value + strlen(value);
7189 while (isspace((int) *(p2 - 1)))
7195 #define CONF2(a) if (strcasecmp(name, a) == 0)
7196 #define CONF(a) else CONF2(a)
7197 #define CONF3(a,b) \
7198 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
7202 CONF2("alignment") {
7204 int a = string_to_alignment(value);
7212 CONF("background") {
7213 fork_to_background = string_to_bool(value);
7217 CONF2("background") {
7218 fork_to_background = string_to_bool(value);
7222 CONF("border_margin") {
7224 border_margin = strtol(value, 0, 0);
7228 CONF("border_width") {
7230 border_width = strtol(value, 0, 0);
7236 color0 = get_x11_color(value);
7242 color1 = get_x11_color(value);
7248 color2 = get_x11_color(value);
7254 color3 = get_x11_color(value);
7260 color4 = get_x11_color(value);
7266 color5 = get_x11_color(value);
7272 color6 = get_x11_color(value);
7278 color7 = get_x11_color(value);
7284 color8 = get_x11_color(value);
7290 color9 = get_x11_color(value);
7294 CONF("default_color") {
7296 default_fg_color = get_x11_color(value);
7300 CONF3("default_shade_color", "default_shadecolor") {
7302 default_bg_color = get_x11_color(value);
7306 CONF3("default_outline_color", "default_outlinecolor") {
7308 default_out_color = get_x11_color(value);
7315 info.mail = parse_mail_args(IMAP, value);
7322 info.mail = parse_mail_args(POP3, value);
7330 strncpy(info.mpd.host, value, 127);
7336 info.mpd.port = strtol(value, 0, 0);
7337 if (info.mpd.port < 1
7338 || info.mpd.port > 0xffff)
7342 CONF("mpd_password") {
7344 strncpy(info.mpd.password, value, 127);
7349 CONF("music_player_interval") {
7351 info.music_player_interval = strtod(value, 0);
7356 CONF("sensor_device") {
7358 sensor_device = strtol(value, 0, 0);
7363 CONF("cpu_avg_samples") {
7365 cpu_avg_samples = strtol(value, 0, 0);
7366 if (cpu_avg_samples < 1
7367 || cpu_avg_samples > 14)
7376 CONF("net_avg_samples") {
7378 net_avg_samples = strtol(value, 0, 0);
7379 if (net_avg_samples < 1
7380 || net_avg_samples > 14)
7396 CONF("double_buffer") {
7397 use_xdbe = string_to_bool(value);
7401 CONF("override_utf8_locale") {
7402 utf8_mode = string_to_bool(value);
7405 CONF("draw_borders") {
7406 draw_borders = string_to_bool(value);
7408 CONF("draw_graph_borders") {
7409 draw_graph_borders = string_to_bool(value);
7411 CONF("draw_shades") {
7412 draw_shades = string_to_bool(value);
7414 CONF("draw_outline") {
7415 draw_outline = string_to_bool(value);
7418 CONF("out_to_console") {
7419 out_to_console = string_to_bool(value);
7421 CONF("use_spacer") {
7423 if (strcasecmp(value, "left") == 0) {
7424 use_spacer = LEFT_SPACER;
7425 } else if (strcasecmp(value, "right") == 0) {
7426 use_spacer = RIGHT_SPACER;
7427 } else if (strcasecmp(value, "none") == 0) {
7428 use_spacer = NO_SPACER;
7430 use_spacer = string_to_bool(value);
7431 ERR("use_spacer should have an argument of left, right, or"
7432 " none. '%s' seems to be some form of '%s', so"
7433 " defaulting to %s.", value,
7434 use_spacer ? "true" : "false",
7435 use_spacer ? "right" : "none");
7437 use_spacer = RIGHT_SPACER;
7439 use_spacer = NO_SPACER;
7443 ERR("use_spacer should have an argument. Defaulting to right.");
7444 use_spacer = RIGHT_SPACER;
7450 use_xft = string_to_bool(value);
7454 set_first_font(value);
7459 if (value && font_count >= 0)
7460 fonts[0].font_alpha = atof(value)
7469 if (string_to_bool(value))
7470 ERR("Xft not enabled");
7473 /* xftfont silently ignored when no Xft */
7476 /* xftalpha is silently ignored when no Xft */
7481 set_first_font(value);
7490 gap_x = atoi(value);
7496 gap_y = atoi(value);
7501 CONF("mail_spool") {
7504 variable_substitute(value, buf, 256);
7508 if (current_mail_spool)
7509 free(current_mail_spool);
7510 current_mail_spool = strdup(buf);
7516 CONF("minimum_size") {
7519 (value, "%d %d", &minimum_width,
7520 &minimum_height) != 2)
7523 &minimum_width) != 1)
7528 CONF("maximum_width") {
7530 if (sscanf(value, "%d", &maximum_width) != 1)
7536 CONF("no_buffers") {
7537 no_buffers = string_to_bool(value);
7539 CONF("top_cpu_separate") {
7540 cpu_separate = string_to_bool(value);
7542 CONF("short_units") {
7543 short_units = string_to_bool(value);
7545 CONF("pad_percents") {
7546 pad_percents = atoi(value);
7550 CONF("own_window") {
7552 own_window = string_to_bool(value);
7556 CONF("own_window_class") {
7559 memset(window.class_name,0,sizeof(window.class_name));
7560 strncpy(window.class_name, value, sizeof(window.class_name)-1);
7565 CONF("own_window_title") {
7568 memset(window.title,0,sizeof(window.title));
7569 strncpy(window.title, value, sizeof(window.title)-1);
7574 CONF("own_window_transparent") {
7576 set_transparent = string_to_bool(value);
7580 CONF("own_window_colour") {
7582 background_colour = get_x11_color(value);
7584 ERR("Invalid colour for own_window_colour (try omitting the '#' for hex colours");
7587 CONF("own_window_hints") {
7589 char *p_hint, *p_save;
7590 char delim[] = ", ";
7592 /* tokenize the value into individual hints */
7593 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
7595 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
7596 if (strncmp(p_hint,"undecorate",10) == 0)
7597 SET_HINT(window.hints,HINT_UNDECORATED);
7598 else if (strncmp(p_hint,"below",5) == 0)
7599 SET_HINT(window.hints,HINT_BELOW);
7600 else if (strncmp(p_hint,"above",5) == 0)
7601 SET_HINT(window.hints,HINT_ABOVE);
7602 else if (strncmp(p_hint,"sticky",6) == 0)
7603 SET_HINT(window.hints,HINT_STICKY);
7604 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
7605 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
7606 else if (strncmp(p_hint,"skip_pager",10) == 0)
7607 SET_HINT(window.hints,HINT_SKIP_PAGER);
7611 p_hint=strtok_r(NULL, delim, &p_save);
7613 while (p_hint!=NULL);
7618 CONF("own_window_type") {
7620 if (strncmp(value,"normal",6)==0)
7621 window.type = TYPE_NORMAL;
7622 else if (strncmp(value,"desktop",7)==0)
7623 window.type = TYPE_DESKTOP;
7624 else if (strncmp(value,"override",8)==0)
7625 window.type = TYPE_OVERRIDE;
7633 CONF("stippled_borders") {
7635 stippled_borders = strtol(value, 0, 0);
7637 stippled_borders = 4;
7641 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
7644 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
7646 CONF("update_interval") {
7648 update_interval = strtod(value, 0);
7651 if (info.music_player_interval == 0) {
7652 // default to update_interval
7653 info.music_player_interval = update_interval;
7656 CONF("total_run_times") {
7658 total_run_times = strtod(value, 0);
7663 stuff_in_upper_case = string_to_bool(value);
7665 CONF("max_specials") {
7667 max_specials = atoi(value);
7671 CONF("max_user_text") {
7673 max_user_text = atoi(value);
7677 CONF("text_buffer_size") {
7679 text_buffer_size = atoi(value);
7694 int l = strlen(text);
7695 if (fgets(buf, 256, fp) == NULL)
7698 realloc(text, l + strlen(buf)
7702 if (strlen(text) > max_user_text)
7706 text_lines = line + 1;
7709 #ifdef TCP_PORT_MONITOR
7710 CONF("max_port_monitor_connections")
7713 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7714 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
7716 /* an error. use default, warn and continue. */
7717 tcp_port_monitor_args.max_port_monitor_connections =
7718 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7721 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
7723 /* no error, just use default */
7724 tcp_port_monitor_args.max_port_monitor_connections =
7725 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7727 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
7732 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7741 if (info.music_player_interval == 0) {
7742 // default to update_interval
7743 info.music_player_interval = update_interval;
7748 /* : means that character before that takes an argument */
7749 static const char *getopt_string = "vVdt:u:i:hc:"
7761 static const struct option
7763 { "help", 0, NULL, 'h' },
7764 { "version", 0, NULL, 'V' },
7765 { "config", 1, NULL, 'c' },
7766 { "daemonize", 0, NULL, 'd' },
7768 { "alignment", 1, NULL, 'a'},
7769 { "font", 1, NULL, 'f'},
7771 { "own-window", 0, NULL, 'o'},
7774 { "double-buffer", 0, NULL, 'b'},
7776 { "window-id", 1, NULL, 'w'},
7778 { "text", 1, NULL, 't' },
7779 { "interval", 0, NULL, 'u' },
7783 int main(int argc, char **argv)
7785 struct sigaction act, oact;
7788 memset(&info, 0, sizeof(info));
7790 #ifdef TCP_PORT_MONITOR
7791 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7794 /* handle command line parameters that don't change configs */
7799 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7800 *s) || ((s = getenv("LANG")) && *s)) {
7801 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7803 ERR("malloc failed");
7805 for (x = 0; x < strlen(s); x++) {
7806 temp[x] = tolower(s[x]);
7809 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7815 if (!setlocale(LC_CTYPE, "")) {
7816 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7820 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
7833 free(current_config);
7834 current_config = strdup(optarg);
7839 "Usage: %s [OPTION]...\n"
7840 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7841 "window. Command line options will override configurations defined in config\n"
7843 " -V, --version version\n"
7844 " -c, --config=FILE config file to load\n"
7845 " -d, --daemonize daemonize, fork to background\n"
7846 " -h, --help help\n"
7848 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7849 " -f, --font=FONT font to use\n"
7851 " -o, --own-window create own window to draw\n"
7854 " -b, --double-buffer double buffer (prevents flickering)\n"
7856 " -w, --window-id=WIN_ID window id to draw\n"
7857 " -x X x position\n"
7858 " -y Y y position\n"
7860 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
7861 " -u, --interval=SECS update interval\n"
7862 " -i NUM number of times to update Conky\n",
7868 window.window = strtol(optarg, 0, 0);
7877 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7881 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
7883 if (!current_config) {
7884 /* load default config file */
7888 /* Try to use personal config file first */
7889 variable_substitute(CONFIG_FILE, buf, sizeof(buf));
7890 if (buf[0] && (fp=fopen(buf,"r"))) {
7891 current_config = strdup(buf);
7895 /* Try to use system config file if personal config not readable */
7896 if (!current_config && (fp=fopen(SYSTEM_CONFIG_FILE,"r"))) {
7897 current_config = strdup(SYSTEM_CONFIG_FILE);
7901 /* No readable config found */
7902 if (!current_config)
7903 CRIT_ERR("no readable personal or system-wide config file found");
7906 load_config_file(current_config);
7908 /* init specials array */
7909 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7910 ERR("failed to create specials array");
7913 if (current_mail_spool == NULL) {
7915 variable_substitute(MAIL_FILE, buf, 256);
7918 current_mail_spool = strdup(buf);
7922 /* handle other command line arguments */
7924 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
7925 || defined(__NetBSD__)
7926 optind = optreset = 1;
7931 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
7932 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7933 O_RDONLY, "kvm_open")) == NULL)
7934 CRIT_ERR( "cannot read kvm");
7938 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
7947 fork_to_background = 1;
7952 set_first_font(optarg);
7955 text_alignment = string_to_alignment(optarg);
7972 text = strdup(optarg);
7973 convert_escapes(text);
7977 update_interval = strtod(optarg, 0);
7978 if (info.music_player_interval == 0) {
7979 // default to update_interval
7980 info.music_player_interval = update_interval;
7985 total_run_times = strtod(optarg, 0);
7989 gap_x = atoi(optarg);
7993 gap_y = atoi(optarg);
8007 /* generate text and get initial size */
8008 extract_variable_text(text);
8014 if (fork_to_background) {
8018 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
8024 fprintf(stderr,"\n"); fflush(stderr);
8028 /* parent process */
8029 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
8036 update_text_area(); /* to get initial size of the window */
8040 text_width + border_margin * 2 + 1,
8041 text_height + border_margin * 2 + 1,
8042 set_transparent, background_colour, argv, argc);
8045 update_text_area(); /* to position text/window on screen */
8050 if (own_window && !fixed_pos) {
8051 XMoveWindow(display, window.window, window.x, window.y);
8054 set_transparent_background(window.window);
8065 /* Set signal handlers */
8066 act.sa_handler = signal_handler;
8067 sigemptyset(&act.sa_mask);
8070 act.sa_flags |= SA_RESTART;
8073 if ( sigaction(SIGINT,&act,&oact) < 0 ||
8074 sigaction(SIGUSR1,&act,&oact) < 0 ||
8075 sigaction(SIGTERM,&act,&oact) < 0 )
8077 ERR("error setting signal handler: %s", strerror(errno) );
8081 if (create_audacious_thread() !=0)
8082 CRIT_ERR("unable to create audacious thread!");
8083 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
8094 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8101 void signal_handler(int sig)
8103 /* signal handler is light as a feather, as it should be.
8104 * we will poll g_signal_pending with each loop of conky
8105 * and do any signal processing there, NOT here. */
8106 g_signal_pending=sig;