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:
2061 free(objs[i].data.rss.uri);
2062 free(objs[i].data.rss.action);
2068 free(objs[i].data.s);
2070 case OBJ_battery_time:
2071 free(objs[i].data.s);
2073 #endif /* !__OpenBSD__ */
2075 free(objs[i].data.execi.cmd);
2076 free(objs[i].data.execi.buffer);
2079 free(objs[i].data.texeci.cmd);
2080 free(objs[i].data.texeci.buffer);
2083 if (info.first_process) {
2084 free_all_processes();
2085 info.first_process = NULL;
2089 if (info.first_process) {
2090 free_all_processes();
2091 info.first_process = NULL;
2096 free(objs[i].data.hddtemp.dev);
2097 free(objs[i].data.hddtemp.addr);
2100 case OBJ_entropy_avail:
2101 case OBJ_entropy_poolsize:
2102 case OBJ_entropy_bar:
2109 if (info.mpd.title) {
2110 free(info.mpd.title);
2113 if (info.mpd.artist) {
2114 free(info.mpd.artist);
2115 info.mpd.artist = 0;
2117 if (info.mpd.album) {
2118 free(info.mpd.album);
2121 if (info.mpd.random) {
2122 free(info.mpd.random);
2123 info.mpd.random = 0;
2125 if (info.mpd.repeat) {
2126 free(info.mpd.repeat);
2127 info.mpd.repeat = 0;
2129 if (info.mpd.track) {
2130 free(info.mpd.track);
2133 if (info.mpd.name) {
2134 free(info.mpd.name);
2137 if (info.mpd.file) {
2138 free(info.mpd.file);
2141 if (info.mpd.status) {
2142 free(info.mpd.status);
2143 info.mpd.status = 0;
2147 //text_objects = NULL;
2148 //text_object_count = 0;
2151 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2156 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2157 *a = mixer_init(buf1);
2158 (void) scan_bar(arg + n, w, h);
2161 (void) scan_bar(arg, w, h);
2166 /* construct_text_object() creates a new text_object */
2167 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2169 //struct text_object *obj = new_text_object();
2170 struct text_object *obj = new_text_object_internal();
2173 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2174 #define END ; } } else
2178 obj->type = OBJ_color;
2179 obj->data.l = get_x11_color(s);
2183 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2184 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2185 END OBJ(acpiacadapter, 0)
2186 #endif /* !__OpenBSD__ */
2188 OBJ(freq, INFO_FREQ)
2190 END OBJ(freq, INFO_FREQ)
2197 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2199 obj->data.cpu_index=1;
2200 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2204 obj->data.cpu_index=atoi(&arg[0]);
2207 END OBJ(freq_g, INFO_FREQ)
2213 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2215 obj->data.cpu_index=1;
2216 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2220 obj->data.cpu_index=atoi(&arg[0]);
2223 #if defined(__linux__)
2224 END OBJ(voltage_mv, 0)
2230 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2232 obj->data.cpu_index=1;
2233 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2237 obj->data.cpu_index=atoi(&arg[0]);
2240 END OBJ(voltage_v, 0)
2246 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2248 obj->data.cpu_index=1;
2249 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2253 obj->data.cpu_index=atoi(&arg[0]);
2258 END OBJ(wireless_essid, INFO_NET)
2260 obj->data.net = get_net_stat(arg);
2262 CRIT_ERR("wireless_essid: needs an argument");
2263 END OBJ(wireless_mode, INFO_NET)
2265 obj->data.net = get_net_stat(arg);
2267 CRIT_ERR("wireless_mode: needs an argument");
2268 END OBJ(wireless_bitrate, INFO_NET)
2270 obj->data.net = get_net_stat(arg);
2272 CRIT_ERR("wireless_bitrate: needs an argument");
2273 END OBJ(wireless_ap, INFO_NET)
2275 obj->data.net = get_net_stat(arg);
2277 CRIT_ERR("wireless_ap: needs an argument");
2278 END OBJ(wireless_link_qual, INFO_NET)
2280 obj->data.net = get_net_stat(arg);
2282 CRIT_ERR("wireless_link_qual: needs an argument");
2283 END OBJ(wireless_link_qual_max, INFO_NET)
2285 obj->data.net = get_net_stat(arg);
2287 CRIT_ERR("wireless_link_qual_max: needs an argument");
2288 END OBJ(wireless_link_qual_perc, INFO_NET)
2290 obj->data.net = get_net_stat(arg);
2292 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2293 END OBJ(wireless_link_bar, INFO_NET)
2295 arg = scan_bar(arg, &obj->a, &obj->b);
2296 obj->data.net = get_net_stat(arg);
2298 CRIT_ERR("wireless_link_bar: needs an argument");
2299 #endif /* HAVE_IWLIB */
2301 #endif /* __linux__ */
2302 END OBJ(freq_dyn, 0)
2303 END OBJ(freq_dyn_g, 0)
2309 sscanf(arg, "%63s", bat);
2311 strcpy(bat, "BAT0");
2312 obj->data.s = strdup(bat);
2313 END OBJ(battery_time, 0)
2316 sscanf(arg, "%63s", bat);
2318 strcpy(bat, "BAT0");
2319 obj->data.s = strdup(bat);
2320 END OBJ(battery_percent, 0)
2323 sscanf(arg, "%63s", bat);
2325 strcpy(bat, "BAT0");
2326 obj->data.s = strdup(bat);
2327 END OBJ(battery_bar, 0)
2330 arg = scan_bar(arg, &obj->a, &obj->b);
2331 sscanf(arg, "%63s", bat);
2333 strcpy(bat, "BAT0");
2335 obj->data.s = strdup(bat);
2336 #endif /* !__OpenBSD__ */
2337 #if defined(__linux__)
2338 END OBJ(i8k_version, INFO_I8K)
2339 END OBJ(i8k_bios, INFO_I8K)
2340 END OBJ(i8k_serial, INFO_I8K)
2341 END OBJ(i8k_cpu_temp, INFO_I8K)
2342 END OBJ(i8k_cpu_tempf, INFO_I8K)
2343 END OBJ(i8k_left_fan_status, INFO_I8K)
2344 END OBJ(i8k_right_fan_status, INFO_I8K)
2345 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2346 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2347 END OBJ(i8k_ac_status, INFO_I8K)
2348 END OBJ(i8k_buttons_status, INFO_I8K)
2350 END OBJ(ibm_temps, 0)
2352 CRIT_ERR("ibm_temps: needs an argument");
2354 if (!isdigit(arg[0])
2356 || atoi(&arg[0]) >=8)
2359 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2361 obj->data.sensor = atoi(&arg[0]);
2362 END OBJ(ibm_volume, 0)
2363 END OBJ(ibm_brightness, 0)
2364 END OBJ(pb_battery, 0)
2365 if (arg && strcmp(arg, "status") == 0) {
2366 obj->data.i = PB_BATT_STATUS;
2367 } else if (arg && strcmp(arg, "percent") == 0) {
2368 obj->data.i = PB_BATT_PERCENT;
2369 } else if (arg && strcmp(arg, "time") == 0) {
2370 obj->data.i = PB_BATT_TIME;
2372 ERR("pb_battery: needs one argument: status, percent or time");
2377 #endif /* __linux__ */
2378 #if defined(__OpenBSD__)
2379 END OBJ(obsd_sensors_temp, 0)
2381 CRIT_ERR("obsd_sensors_temp: needs an argument");
2383 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2385 ERR("Invalid temperature sensor number!");
2387 obj->data.sensor = atoi(&arg[0]);
2388 END OBJ(obsd_sensors_fan, 0)
2390 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor number)");
2392 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2394 ERR("Invalid fan sensor number!");
2396 obj->data.sensor = atoi(&arg[0]);
2397 END OBJ(obsd_sensors_volt, 0)
2399 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor number)");
2401 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2403 ERR("Invalid voltage sensor number!");
2405 obj->data.sensor = atoi(&arg[0]);
2406 END OBJ(obsd_vendor, 0)
2407 END OBJ(obsd_product, 0)
2408 #endif /* __OpenBSD__ */
2409 END OBJ(buffers, INFO_BUFFERS)
2410 END OBJ(cached, INFO_BUFFERS)
2411 END OBJ(cpu, INFO_CPU)
2413 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2414 obj->data.cpu_index = atoi(&arg[3]);
2416 } else {obj->data.cpu_index = 0; }
2418 obj->data.cpu_index = 0;
2420 END OBJ(cpubar, INFO_CPU)
2422 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2423 obj->data.cpu_index = atoi(&arg[3]);
2426 else {obj->data.cpu_index = 0;}
2427 (void) scan_bar(arg, &obj->a, &obj->b);
2429 (void) scan_bar(arg, &obj->a, &obj->b);
2430 obj->data.cpu_index = 0;
2432 END OBJ(cpugraph, INFO_CPU)
2433 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2437 if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
2438 obj->data.cpu_index = atoi(&buf[3]);
2440 obj->data.cpu_index = 0;
2444 END OBJ(diskio, INFO_DISKIO)
2446 obj->data.diskio = prepare_diskio_stat(arg);
2448 obj->data.diskio = NULL;
2450 END OBJ(diskio_read, INFO_DISKIO)
2452 obj->data.diskio = prepare_diskio_stat(arg);
2454 obj->data.diskio = NULL;
2456 END OBJ(diskio_write, INFO_DISKIO)
2458 obj->data.diskio = prepare_diskio_stat(arg);
2460 obj->data.diskio = NULL;
2462 END OBJ(diskiograph, INFO_DISKIO)
2463 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2467 obj->data.diskio = prepare_diskio_stat(buf);
2470 obj->data.diskio = NULL;
2472 END OBJ(diskiograph_read, INFO_DISKIO)
2473 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2477 obj->data.diskio = prepare_diskio_stat(buf);
2480 obj->data.diskio = NULL;
2482 END OBJ(diskiograph_write, INFO_DISKIO)
2483 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2487 obj->data.diskio = prepare_diskio_stat(buf);
2490 obj->data.diskio = NULL;
2494 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2497 obj->data.l = color0;
2499 obj->data.l = color1;
2501 obj->data.l = color2;
2503 obj->data.l = color3;
2505 obj->data.l = color4;
2507 obj->data.l = color5;
2509 obj->data.l = color6;
2511 obj->data.l = color7;
2513 obj->data.l = color8;
2515 obj->data.l = color9;
2517 obj->data.s = scan_font(arg);
2518 END OBJ(downspeed, INFO_NET)
2520 obj->data.net = get_net_stat(arg);
2523 CRIT_ERR("downspeed needs argument");
2525 END OBJ(downspeedf, INFO_NET)
2527 obj->data.net = get_net_stat(arg);
2530 CRIT_ERR("downspeedf needs argument");
2532 END OBJ(downspeedgraph, INFO_NET)
2533 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2537 obj->data.net = get_net_stat(buf);
2542 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2543 blockstart[blockdepth - 1] = object_count;
2544 obj->data.ifblock.pos = object_count + 2;
2546 ERR("$else: no matching $if_*");
2551 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2553 ERR("$endif: no matching $if_*");
2556 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2559 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2560 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2561 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2562 END OBJ(execibar, 0) unsigned int n;
2563 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2565 ERR("${execibar <interval> command}");
2566 obj->type = OBJ_text;
2567 snprintf(buf, 256, "${%s}", s);
2568 obj->data.s = strdup(buf);
2570 obj->data.execi.cmd = strdup(arg + n);
2572 END OBJ(execigraph, 0) unsigned int n;
2573 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2575 ERR("${execigraph <interval> command}");
2576 obj->type = OBJ_text;
2577 snprintf(buf, 256, "${%s}", s);
2578 obj->data.s = strdup(buf);
2580 obj->data.execi.cmd = strdup(arg + n);
2582 END OBJ(execi, 0) unsigned int n;
2583 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2585 ERR("${execi <interval> command}");
2586 obj->type = OBJ_text;
2587 snprintf(buf, 256, "${%s}", s);
2588 obj->data.s = strdup(buf);
2590 obj->data.execi.cmd = strdup(arg + n);
2591 obj->data.execi.buffer =
2592 (char *) calloc(1, text_buffer_size);
2594 END OBJ(texeci, 0) unsigned int n;
2595 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2597 ERR("${texeci <interval> command}");
2598 obj->type = OBJ_text;
2599 snprintf(buf, 256, "${%s}", s);
2600 obj->data.s = strdup(buf);
2602 obj->data.texeci.cmd = strdup(arg + n);
2603 obj->data.texeci.buffer =
2604 (char *) calloc(1, text_buffer_size);
2606 obj->data.texeci.p_timed_thread = NULL;
2607 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2609 FILE *fp = popen(arg, "r");
2613 n = fread(buf, 1, 2048, fp);
2616 if (n && buf[n - 1] == '\n')
2621 obj->data.s = strdup(buf);
2623 obj->data.s = strdup("");
2626 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2627 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2629 while (isspace(*arg))
2635 obj->data.fsbar.fs = prepare_fs_stat(arg);
2636 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2639 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2643 obj->data.fsbar.fs = prepare_fs_stat(arg);
2644 END OBJ(fs_free, INFO_FS) if (!arg)
2646 obj->data.fs = prepare_fs_stat(arg);
2647 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2649 obj->data.fs = prepare_fs_stat(arg);
2650 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2652 obj->data.fs = prepare_fs_stat(arg);
2653 END OBJ(fs_size, INFO_FS) if (!arg)
2655 obj->data.fs = prepare_fs_stat(arg);
2656 END OBJ(fs_used, INFO_FS) if (!arg)
2658 obj->data.fs = prepare_fs_stat(arg);
2659 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2660 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2661 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2665 ERR("goto needs arguments");
2666 obj->type = OBJ_text;
2667 obj->data.s = strdup("${goto}");
2671 obj->data.i = atoi(arg);
2676 if (sscanf(arg, "%d %d", &a, &b) != 2)
2677 sscanf(arg, "%d", &b);
2681 obj->data.pair.a = a;
2682 obj->data.pair.b = b;
2685 END OBJ(i2c, INFO_SYSFS)
2686 char buf1[64], buf2[64];
2690 ERR("i2c needs arguments");
2691 obj->type = OBJ_text;
2692 //obj->data.s = strdup("${i2c}");
2696 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2697 /* if scanf couldn't read three values, read type and num and use default device */
2698 sscanf(arg, "%63s %d", buf2, &n);
2699 obj->data.sysfs.fd =
2700 open_i2c_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2701 strncpy(obj->data.sysfs.type, buf2, 63);
2703 obj->data.sysfs.fd =
2704 open_i2c_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2705 strncpy(obj->data.sysfs.type, buf2, 63);
2708 END OBJ(platform, INFO_SYSFS)
2709 char buf1[64], buf2[64];
2713 ERR("platform needs arguments");
2714 obj->type = OBJ_text;
2718 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2719 /* if scanf couldn't read three values, read type and num and use default device */
2720 sscanf(arg, "%63s %d", buf2, &n);
2721 obj->data.sysfs.fd =
2722 open_platform_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2723 strncpy(obj->data.sysfs.type, buf2, 63);
2725 obj->data.sysfs.fd =
2726 open_platform_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2727 strncpy(obj->data.sysfs.type, buf2, 63);
2730 END OBJ(hwmon, INFO_SYSFS)
2731 char buf1[64], buf2[64];
2735 ERR("hwmon needs argumanets");
2736 obj->type = OBJ_text;
2740 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2741 /* if scanf couldn't read three values, read type and num and use default device */
2742 sscanf(arg, "%63s %d", buf2, &n);
2743 obj->data.sysfs.fd =
2744 open_hwmon_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2745 strncpy(obj->data.sysfs.type, buf2, 63);
2747 obj->data.sysfs.fd =
2748 open_hwmon_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2749 strncpy(obj->data.sysfs.type, buf2, 63);
2751 #endif /* !__OpenBSD__ */
2753 END OBJ(top, INFO_TOP)
2757 ERR("top needs arguments");
2758 obj->type = OBJ_text;
2759 //obj->data.s = strdup("${top}");
2762 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2763 if (strcmp(buf, "name") == 0) {
2764 obj->data.top.type = TOP_NAME;
2765 } else if (strcmp(buf, "cpu") == 0) {
2766 obj->data.top.type = TOP_CPU;
2767 } else if (strcmp(buf, "pid") == 0) {
2768 obj->data.top.type = TOP_PID;
2769 } else if (strcmp(buf, "mem") == 0) {
2770 obj->data.top.type = TOP_MEM;
2771 } else if (strcmp(buf, "time") == 0) {
2772 obj->data.top.type = TOP_TIME;
2774 ERR("invalid arg for top");
2777 if (n < 1 || n > 10) {
2778 CRIT_ERR("invalid arg for top");
2781 obj->data.top.num = n - 1;
2785 ERR("invalid args given for top");
2788 END OBJ(top_mem, INFO_TOP)
2792 ERR("top_mem needs arguments");
2793 obj->type = OBJ_text;
2794 obj->data.s = strdup("${top_mem}");
2797 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2798 if (strcmp(buf, "name") == 0) {
2799 obj->data.top.type = TOP_NAME;
2800 } else if (strcmp(buf, "cpu") == 0) {
2801 obj->data.top.type = TOP_CPU;
2802 } else if (strcmp(buf, "pid") == 0) {
2803 obj->data.top.type = TOP_PID;
2804 } else if (strcmp(buf, "mem") == 0) {
2805 obj->data.top.type = TOP_MEM;
2806 } else if (strcmp(buf, "time") == 0) {
2807 obj->data.top.type = TOP_TIME;
2809 ERR("invalid arg for top");
2812 if (n < 1 || n > 10) {
2813 CRIT_ERR("invalid arg for top");
2816 obj->data.top.num = n - 1;
2820 ERR("invalid args given for top");
2823 END OBJ(addr, INFO_NET)
2825 obj->data.net = get_net_stat(arg);
2828 CRIT_ERR("addr needs argument");
2835 ERR("tail needs arguments");
2836 obj->type = OBJ_text;
2837 obj->data.s = strdup("${tail}");
2840 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2841 if (n1 < 1 || n1 > 30) {
2842 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2848 obj->data.tail.fd = -1;
2850 if (stat(buf, &st) == 0) {
2851 if (S_ISFIFO(st.st_mode)) {
2852 fd = open(buf, O_RDONLY|O_NONBLOCK);
2855 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2857 obj->data.tail.fd = fd;
2861 fp = fopen(buf, "r");
2864 if (fp || obj->data.tail.fd != -1) {
2865 obj->data.tail.logfile =
2866 malloc(text_buffer_size);
2867 strcpy(obj->data.tail.logfile, buf);
2868 obj->data.tail.wantedlines = n1;
2869 obj->data.tail.interval =
2870 update_interval * 2;
2872 if (obj->data.tail.fd == -1)
2876 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2879 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2880 if (n1 < 1 || n1 > 30) {
2882 ("invalid arg for tail, number of lines must be between 1 and 30");
2884 } else if (n2 < 1 || n2 < update_interval) {
2886 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2892 obj->data.tail.fd = -1;
2894 if (stat(buf, &st) == 0) {
2895 if (S_ISFIFO(st.st_mode)) {
2896 fd = open(buf, O_RDONLY|O_NONBLOCK);
2899 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2901 obj->data.tail.fd = fd;
2904 fp = fopen(buf, "r");
2907 if (fp || obj->data.tail.fd != -1) {
2908 obj->data.tail.logfile =
2909 malloc(text_buffer_size);
2910 strcpy(obj->data.tail.logfile, buf);
2911 obj->data.tail.wantedlines = n1;
2912 obj->data.tail.interval = n2;
2914 if (obj->data.tail.fd == -1)
2918 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2924 ERR("invalid args given for tail");
2927 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2932 ERR("head needs arguments");
2933 obj->type = OBJ_text;
2934 obj->data.s = strdup("${head}");
2937 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2938 if (n1 < 1 || n1 > 30) {
2939 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2943 fp = fopen(buf, "r");
2945 obj->data.tail.logfile =
2946 malloc(text_buffer_size);
2947 strcpy(obj->data.tail.logfile, buf);
2948 obj->data.tail.wantedlines = n1;
2949 obj->data.tail.interval =
2950 update_interval * 2;
2954 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2957 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2958 if (n1 < 1 || n1 > 30) {
2960 ("invalid arg for head, number of lines must be between 1 and 30");
2962 } else if (n2 < 1 || n2 < update_interval) {
2964 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2968 fp = fopen(buf, "r");
2970 obj->data.tail.logfile =
2971 malloc(text_buffer_size);
2972 strcpy(obj->data.tail.logfile, buf);
2973 obj->data.tail.wantedlines = n1;
2974 obj->data.tail.interval = n2;
2978 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2984 ERR("invalid args given for head");
2987 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2988 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2990 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2991 if (r >= 3 && (c < 1 || c > 3))
2993 if (r >= 2 && (b < 1 || b > 3))
2995 if (r >= 1 && (a < 1 || a > 3))
2998 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2999 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
3000 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
3001 END OBJ(if_empty, 0)
3002 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3003 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3006 ERR("if_empty needs an argument");
3007 obj->data.ifblock.s = 0;
3009 obj->data.ifblock.s = strdup(arg);
3010 blockstart[blockdepth] = object_count;
3011 obj->data.ifblock.pos = object_count + 2;
3013 END OBJ(if_existing, 0)
3014 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3015 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3018 ERR("if_existing needs an argument or two");
3019 obj->data.ifblock.s = NULL;
3020 obj->data.ifblock.str = NULL;
3022 char buf1[256], buf2[256];
3023 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3025 obj->data.ifblock.s = strdup(buf1);
3026 obj->data.ifblock.str = NULL;
3028 obj->data.ifblock.s = strdup(buf1);
3029 obj->data.ifblock.str = strdup(buf2);
3032 blockstart[blockdepth] = object_count;
3033 obj->data.ifblock.pos = object_count + 2;
3035 END OBJ(if_mounted, 0)
3036 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3037 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3040 ERR("if_mounted needs an argument");
3041 obj->data.ifblock.s = 0;
3043 obj->data.ifblock.s = strdup(arg);
3044 blockstart[blockdepth] = object_count;
3045 obj->data.ifblock.pos = object_count + 2;
3047 END OBJ(if_running, 0)
3048 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3049 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3053 snprintf(buf, 256, "pidof %s >/dev/null", arg);
3054 obj->data.ifblock.s = strdup(buf);
3056 ERR("if_running needs an argument");
3057 obj->data.ifblock.s = 0;
3059 blockstart[blockdepth] = object_count;
3060 obj->data.ifblock.pos = object_count + 2;
3066 char box[256], dst[256];
3070 strncpy(box, MAIL_FILE, sizeof(box));
3073 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3075 strncpy(box, arg, sizeof(box));
3079 variable_substitute(box, dst, sizeof(dst));
3080 obj->data.local_mail.box = strdup(dst);
3081 obj->data.local_mail.interval = n1;
3084 END OBJ(mboxscan, 0)
3085 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
3086 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
3087 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
3088 obj->data.mboxscan.output[0] = 1;
3089 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
3090 END OBJ(mem, INFO_MEM)
3091 END OBJ(memmax, INFO_MEM)
3092 END OBJ(memperc, INFO_MEM)
3093 END OBJ(membar, INFO_MEM)
3094 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3095 END OBJ(memgraph, INFO_MEM)
3096 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3102 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
3103 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
3104 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
3105 END OBJ(mixerbar, INFO_MIXER)
3106 scan_mixer_bar(arg, &obj->data.mixerbar.l,
3107 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
3108 END OBJ(mixerlbar, INFO_MIXER)
3109 scan_mixer_bar(arg, &obj->data.mixerbar.l,
3110 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
3111 END OBJ(mixerrbar, INFO_MIXER)
3112 scan_mixer_bar(arg, &obj->data.mixerbar.l,
3113 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
3117 char box[256], dst[256];
3121 strncpy(box, MAIL_FILE, sizeof(box));
3124 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3126 strncpy(box, arg, sizeof(box));
3130 variable_substitute(box, dst, sizeof(dst));
3131 obj->data.local_mail.box = strdup(dst);
3132 obj->data.local_mail.interval = n1;
3135 END OBJ(nodename, 0)
3136 END OBJ(processes, INFO_PROCS)
3137 END OBJ(running_processes, INFO_RUN_PROCS)
3138 END OBJ(shadecolor, 0)
3140 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
3142 END OBJ(outlinecolor, 0)
3144 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
3146 END OBJ(stippled_hr, 0)
3148 int a = stippled_borders, b = 1;
3150 if (sscanf(arg, "%d %d", &a, &b) != 2)
3151 sscanf(arg, "%d", &b);
3155 obj->data.pair.a = a;
3156 obj->data.pair.b = b;
3158 END OBJ(swap, INFO_MEM)
3159 END OBJ(swapmax, INFO_MEM)
3160 END OBJ(swapperc, INFO_MEM)
3161 END OBJ(swapbar, INFO_MEM)
3162 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3165 END OBJ(temp1, INFO_SYSFS) obj->type = OBJ_i2c;
3166 obj->data.sysfs.fd =
3167 open_i2c_sensor(0, "temp", 1, &obj->data.sysfs.arg,
3168 obj->data.sysfs.devtype);
3169 END OBJ(temp2, INFO_SYSFS) obj->type = OBJ_i2c;
3170 obj->data.sysfs.fd =
3171 open_i2c_sensor(0, "temp", 2, &obj->data.sysfs.arg,
3172 obj->data.sysfs.devtype);
3174 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
3175 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
3177 char buf1[256], buf2[256], *fmt, *tz;
3180 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3189 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
3190 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
3192 END OBJ(iconv_start, 0)
3193 if (iconv_converting) {
3194 CRIT_ERR("You must stop your last iconv conversion before starting another");
3197 char iconv_from[CODEPAGE_LENGTH];
3198 char iconv_to[CODEPAGE_LENGTH];
3199 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3200 CRIT_ERR("Invalid arguments for iconv_start");
3203 new_iconv = iconv_open(iconv_to, iconv_from);
3204 if (new_iconv == (iconv_t)(-1)) {
3205 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3207 obj->a = register_iconv(&new_iconv);
3208 iconv_converting = 1;
3212 CRIT_ERR("Iconv requires arguments");
3214 END OBJ(iconv_stop, 0)
3215 iconv_converting = 0;
3218 END OBJ(totaldown, INFO_NET)
3220 obj->data.net = get_net_stat(arg);
3223 CRIT_ERR("totaldown needs argument");
3225 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
3227 obj->data.net = get_net_stat(arg);
3230 CRIT_ERR("totalup needs argument");
3233 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
3234 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
3235 END OBJ(upspeed, INFO_NET)
3237 obj->data.net = get_net_stat(arg);
3240 CRIT_ERR("upspeed needs argument");
3242 END OBJ(upspeedf, INFO_NET)
3244 obj->data.net = get_net_stat(arg);
3247 CRIT_ERR("upspeedf needs argument");
3250 END OBJ(upspeedgraph, INFO_NET)
3251 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3255 obj->data.net = get_net_stat(buf);
3258 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
3260 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
3261 #endif /* !__OpenBSD__ */
3262 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3263 OBJ(apm_adapter, 0) END
3264 OBJ(apm_battery_life, 0) END
3265 OBJ(apm_battery_time, 0) END
3266 #endif /* __FreeBSD__ */
3270 obj->data.mail = parse_mail_args(IMAP, arg);
3271 obj->global_mode = 0;
3273 obj->global_mode = 1;
3276 OBJ(imap_messages, 0)
3279 obj->data.mail = parse_mail_args(IMAP, arg);
3280 obj->global_mode = 0;
3282 obj->global_mode = 1;
3288 obj->data.mail = parse_mail_args(POP3, arg);
3289 obj->global_mode = 0;
3291 obj->global_mode = 1;
3297 obj->data.mail = parse_mail_args(POP3, arg);
3298 obj->global_mode = 0;
3300 obj->global_mode = 1;
3304 OBJ(mpd_artist, INFO_MPD) END
3305 OBJ(mpd_title, INFO_MPD)
3308 sscanf (arg, "%d", &info.mpd.max_title_len);
3309 if (info.mpd.max_title_len > 0) {
3310 info.mpd.max_title_len++;
3312 CRIT_ERR ("mpd_title: invalid length argument");
3315 info.mpd.max_title_len = 0;
3318 END OBJ(mpd_random, INFO_MPD)
3319 END OBJ(mpd_repeat, INFO_MPD)
3320 END OBJ(mpd_elapsed, INFO_MPD)
3321 END OBJ(mpd_length, INFO_MPD)
3322 END OBJ(mpd_track, INFO_MPD)
3323 END OBJ(mpd_name, INFO_MPD)
3324 END OBJ(mpd_file, INFO_MPD)
3325 END OBJ(mpd_percent, INFO_MPD)
3326 END OBJ(mpd_album, INFO_MPD)
3327 END OBJ(mpd_vol, INFO_MPD)
3328 END OBJ(mpd_bitrate, INFO_MPD)
3329 END OBJ(mpd_status, INFO_MPD)
3330 END OBJ(mpd_bar, INFO_MPD)
3331 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3332 END OBJ(mpd_smart, INFO_MPD) END
3335 OBJ(xmms2_artist, INFO_XMMS2)
3336 END OBJ(xmms2_album, INFO_XMMS2)
3337 END OBJ(xmms2_title, INFO_XMMS2)
3338 END OBJ(xmms2_genre, INFO_XMMS2)
3339 END OBJ(xmms2_comment, INFO_XMMS2)
3340 END OBJ(xmms2_decoder, INFO_XMMS2)
3341 END OBJ(xmms2_transport, INFO_XMMS2)
3342 END OBJ(xmms2_url, INFO_XMMS2)
3343 END OBJ(xmms2_tracknr, INFO_XMMS2)
3344 END OBJ(xmms2_bitrate, INFO_XMMS2)
3345 END OBJ(xmms2_date, INFO_XMMS2)
3346 END OBJ(xmms2_id, INFO_XMMS2)
3347 END OBJ(xmms2_duration, INFO_XMMS2)
3348 END OBJ(xmms2_elapsed, INFO_XMMS2)
3349 END OBJ(xmms2_size, INFO_XMMS2)
3350 END OBJ(xmms2_status, INFO_XMMS2)
3351 END OBJ(xmms2_percent, INFO_XMMS2)
3352 END OBJ(xmms2_bar, INFO_XMMS2)
3353 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3354 END OBJ(xmms2_smart, INFO_XMMS2)
3358 OBJ(audacious_status, INFO_AUDACIOUS) END
3359 OBJ(audacious_title, INFO_AUDACIOUS)
3362 sscanf (arg, "%d", &info.audacious.max_title_len);
3363 if (info.audacious.max_title_len > 0) {
3364 info.audacious.max_title_len++;
3366 CRIT_ERR ("audacious_title: invalid length argument");
3371 OBJ(audacious_length, INFO_AUDACIOUS) END
3372 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3373 OBJ(audacious_position, INFO_AUDACIOUS) END
3374 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3375 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3376 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3377 OBJ(audacious_channels, INFO_AUDACIOUS) END
3378 OBJ(audacious_filename, INFO_AUDACIOUS) END
3379 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3380 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3381 OBJ(audacious_bar, INFO_AUDACIOUS)
3382 (void) scan_bar(arg, &obj->a, &obj->b);
3386 OBJ(bmpx_title, INFO_BMPX)
3387 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3389 OBJ(bmpx_artist, INFO_BMPX)
3390 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3392 OBJ(bmpx_album, INFO_BMPX)
3393 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3395 OBJ(bmpx_track, INFO_BMPX)
3396 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3398 OBJ(bmpx_uri, INFO_BMPX)
3399 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3401 OBJ(bmpx_bitrate, INFO_BMPX)
3402 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3408 int argc, delay, act_par;
3409 char *uri = (char *)malloc(128 * sizeof(char));
3410 char *action = (char *)malloc(64 * sizeof(char));
3412 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par);
3413 obj->data.rss.uri = uri;
3414 obj->data.rss.delay = delay;
3415 obj->data.rss.action = action;
3416 obj->data.rss.act_par = act_par;
3420 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
3426 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3427 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3428 ERR("hddtemp needs arguments");
3429 obj->type = OBJ_text;
3430 obj->data.s = strdup("${hddtemp}");
3435 #ifdef TCP_PORT_MONITOR
3436 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3437 int argc, port_begin, port_end, item, connection_index;
3439 memset(itembuf,0,sizeof(itembuf));
3441 /* massive argument checking */
3443 CRIT_ERR("tcp_portmon: needs arguments");
3445 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3446 if ( (argc != 3) && (argc != 4) )
3448 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3450 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3452 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3454 if ( port_begin > port_end )
3456 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3458 if ( strncmp(itembuf,"count",31) == 0 )
3460 else if ( strncmp(itembuf,"rip",31) == 0 )
3462 else if ( strncmp(itembuf,"rhost",31) == 0 )
3464 else if ( strncmp(itembuf,"rport",31) == 0 )
3466 else if ( strncmp(itembuf,"rservice",31) == 0 )
3468 else if ( strncmp(itembuf,"lip",31) == 0 )
3470 else if ( strncmp(itembuf,"lhost",31) == 0 )
3472 else if ( strncmp(itembuf,"lport",31) == 0 )
3474 else if ( strncmp(itembuf,"lservice",31) == 0 )
3478 CRIT_ERR("tcp_portmon: invalid item specified");
3480 if ( (argc==3) && (item!=COUNT) )
3482 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3484 if ( (argc==4) && (connection_index<0) )
3486 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3488 /* ok, args looks good. save the text object data */
3489 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3490 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3491 obj->data.tcp_port_monitor.item = item;
3492 obj->data.tcp_port_monitor.connection_index = connection_index;
3494 /* if the port monitor collection hasn't been created, we must create it */
3495 if ( !info.p_tcp_port_monitor_collection )
3497 info.p_tcp_port_monitor_collection =
3498 create_tcp_port_monitor_collection ();
3499 if ( !info.p_tcp_port_monitor_collection )
3501 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3505 /* if a port monitor for this port does not exist, create one and add it to the collection */
3506 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3508 tcp_port_monitor_t * p_monitor =
3509 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3512 CRIT_ERR("tcp_portmon: unable to create port monitor");
3514 /* add the newly created monitor to the collection */
3515 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3518 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3523 OBJ(entropy_avail, INFO_ENTROPY) END
3524 OBJ(entropy_poolsize, INFO_ENTROPY) END
3525 OBJ(entropy_bar, INFO_ENTROPY)
3526 (void) scan_bar(arg, &obj->a, &obj->b);
3531 ERR("unknown variable %s", s);
3532 obj->type = OBJ_text;
3533 snprintf(buf, 256, "${%s}", s);
3534 obj->data.s = strdup(buf);
3541 static struct text_object *create_plain_text(const char *s)
3543 struct text_object *obj;
3545 if (s == NULL || *s == '\0') {
3549 obj = new_text_object_internal();
3551 obj->type = OBJ_text;
3552 obj->data.s = strdup(s);
3556 static struct text_object_list *extract_variable_text_internal(const char *p)
3558 struct text_object_list *retval;
3559 struct text_object *obj;
3562 retval = malloc(sizeof(struct text_object_list));
3563 memset(retval, 0, sizeof(struct text_object_list));
3564 retval->text_object_count = 0;
3566 long line = text_lines;
3574 obj = create_plain_text(s);
3576 // allocate memory for the object
3577 retval->text_objects = realloc(retval->text_objects,
3578 sizeof(struct text_object) * (retval->text_object_count+1));
3579 // assign the new object to the end of the list.
3580 memcpy(&retval->text_objects[retval->text_object_count++],
3581 obj, sizeof(struct text_object));
3593 /* variable is either $foo or ${foo} */
3595 unsigned int brl = 1, brr = 0;
3598 while (*p && brl != brr) {
3599 if (*p == '{') brl++;
3600 if (*p == '}') brr++;
3608 while (*p && (isalnum((int) *p)
3613 /* copy variable to buffer */
3614 len = (p - s > 255) ? 255 : (p - s);
3615 strncpy(buf, s, len);
3624 /* if variable wasn't found from environment, use some special */
3630 if (strchr(buf, ' ')) {
3631 arg = strchr(buf, ' ');
3634 while (isspace((int) *arg))
3640 /* lowercase variable name */
3647 // create new object
3648 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3650 // allocate memory for the object
3651 retval->text_objects = realloc(retval->text_objects,
3652 sizeof(struct text_object) * (retval->text_object_count+1));
3653 // assign the new object to the end of the list.
3654 memcpy(&retval->text_objects[retval->text_object_count++],
3655 obj, sizeof(struct text_object));
3661 obj = create_plain_text("$");
3663 // allocate memory for the object
3664 retval->text_objects = realloc(retval->text_objects,
3665 sizeof(struct text_object) * (retval->text_object_count+1));
3666 // assign the new object to the end of the list.
3667 memcpy(&retval->text_objects[retval->text_object_count++],
3668 obj, sizeof(struct text_object));
3675 obj = create_plain_text(s);
3677 // allocate memory for the object
3678 retval->text_objects = realloc(retval->text_objects,
3679 sizeof(struct text_object) * (retval->text_object_count+1));
3680 // assign the new object to the end of the list.
3681 memcpy(&retval->text_objects[retval->text_object_count++],
3682 obj, sizeof(struct text_object));
3687 ERR("one or more $endif's are missing");
3693 static void extract_variable_text(const char *p)
3695 struct text_object_list *list;
3697 free_text_objects(text_object_count, text_objects);
3698 text_object_count = 0;
3699 text_objects = NULL;
3702 list = extract_variable_text_internal(p);
3703 text_objects = list->text_objects;
3704 text_object_count = list->text_object_count;
3711 void parse_conky_vars(char * text, char * p, struct information *cur) {
3712 struct text_object_list *object_list = extract_variable_text_internal(text);
3713 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3718 * Allows reading from a FIFO (i.e., /dev/xconsole). The file descriptor is
3719 * set to non-blocking which makes this possible.
3722 * Since lseek cannot seek a file descriptor long lines will break.
3724 static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
3726 #define TAIL_PIPE_BUFSIZE 4096
3730 int fd = obj->data.tail.fd;
3733 char buf[TAIL_PIPE_BUFSIZE];
3734 ssize_t len = read(fd, buf, sizeof(buf));
3738 if (errno != EAGAIN) {
3739 strcpy(obj->data.tail.buffer, "Logfile Read Error");
3740 snprintf(dst, dst_size, "Logfile Read Error");
3745 else if (len == 0) {
3746 strcpy(obj->data.tail.buffer, "Logfile Empty");
3747 snprintf(dst, dst_size, "Logfile Empty");
3751 for (line_len = 0, i = 0; i < len; i++) {
3755 if (buf[i] == '\n') {
3758 if (obj->data.tail.readlines > 0) {
3763 for (n = 0; obj->data.tail.buffer[n]; n++) {
3764 if (obj->data.tail.buffer[n] == '\n') {
3768 if (++olines < obj->data.tail.wantedlines) {
3774 p = obj->data.tail.buffer + first_line;
3775 pos = n - first_line;
3776 memmove(obj->data.tail.buffer, obj->data.tail.buffer + first_line, strlen(p));
3777 obj->data.tail.buffer[pos] = 0;
3783 p = buf + last_line;
3785 memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
3786 obj->data.tail.buffer[pos + line_len] = 0;
3789 obj->data.tail.readlines = lines;
3797 snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
3800 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3805 char buff_in[P_MAX_SIZE] = {0};
3806 iconv_converting = 0;
3809 for (i = 0; i < object_count; i++) {
3810 struct text_object *obj = &objs[i];
3812 #define OBJ(a) break; case OBJ_##a:
3814 switch (obj->type) {
3817 ERR("not implemented obj type %d",
3822 /* does anyone have decimals in acpi temperature? */
3823 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
3824 round_to_int(get_acpi_temperature(obj->data.i)));
3827 /* does anyone have decimals in acpi temperature? */
3828 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
3829 round_to_int((get_acpi_temperature(obj->data.i) + 40) *
3832 #endif /* !__OpenBSD__ */
3835 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3841 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3843 /* OpenBSD has no such flag (SUSv2) */
3844 obj->a = get_freq(p, p_max_size, "%.2f", 1000, obj->data.cpu_index);
3849 #if defined(__linux__)
3852 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3857 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3861 OBJ(wireless_essid) {
3862 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3864 OBJ(wireless_mode) {
3865 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3867 OBJ(wireless_bitrate) {
3868 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3871 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3873 OBJ(wireless_link_qual) {
3874 spaced_print(p, p_max_size, "%d", 4, "wireless_link_qual",
3875 obj->data.net->link_qual);
3877 OBJ(wireless_link_qual_max) {
3878 spaced_print(p, p_max_size, "%d", 4,
3879 "wireless_link_qual_max", obj->data.net->link_qual_max);
3881 OBJ(wireless_link_qual_perc) {
3882 if(obj->data.net->link_qual_max > 0) {
3883 spaced_print(p, p_max_size, "%.0f%%", 5,
3884 "wireless_link_qual_perc",
3885 (double) obj->data.net->link_qual /
3886 obj->data.net->link_qual_max * 100);
3888 spaced_print(p, p_max_size, "unk", 5,
3889 "wireless_link_qual_perc");
3892 OBJ(wireless_link_bar) {
3893 new_bar(p, obj->a, obj->b, ((double)obj->data.net->link_qual/obj->data.net->link_qual_max)*255.0);
3895 #endif /* HAVE_IWLIB */
3897 #endif /* __linux__ */
3900 get_freq_dynamic(p, p_max_size, "%.0f", 1);
3901 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
3905 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3907 get_freq_dynamic(p, p_max_size, "%.2f", 1000);
3909 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
3913 get_adt746x_cpu(p, p_max_size);
3916 get_adt746x_fan(p, p_max_size);
3919 get_acpi_fan(p, p_max_size);
3921 OBJ(acpiacadapter) {
3922 get_acpi_ac_adapter(p, p_max_size);
3925 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3928 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3930 OBJ(battery_percent) {
3931 snprintf(p, p_max_size, "%d",
3932 get_battery_perct(obj->data.s));
3935 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3937 #endif /* __OpenBSD__ */
3939 human_readable(cur->buffers * 1024, p, 255, "buffers");
3942 human_readable(cur->cached * 1024, p, 255, "buffers");
3945 if (obj->data.cpu_index > info.cpu_count) {
3946 printf("obj->data.cpu_index %i info.cpu_count %i",
3947 obj->data.cpu_index, info.cpu_count);
3948 CRIT_ERR("attempting to use more CPUs then you have!");
3950 spaced_print(p, p_max_size, "%*d", 4, "cpu", pad_percents,
3951 round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3957 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3960 new_graph(p, obj->a,
3961 obj->b, obj->c, obj->d,
3962 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3966 new_fg(p, obj->data.l);
3998 #if defined(__linux__)
4000 snprintf(p, p_max_size, "%s", i8k.version);
4003 snprintf(p, p_max_size, "%s", i8k.bios);
4006 snprintf(p, p_max_size, "%s", i8k.serial);
4009 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
4011 OBJ(i8k_cpu_tempf) {
4013 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
4014 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
4016 OBJ(i8k_left_fan_status) {
4017 int left_fan_status;
4018 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
4019 if(left_fan_status == 0) {
4020 snprintf(p, p_max_size,"off");
4021 } if(left_fan_status == 1) {
4022 snprintf(p, p_max_size, "low");
4023 } if(left_fan_status == 2) {
4024 snprintf(p, p_max_size, "high");
4028 OBJ(i8k_right_fan_status) {
4029 int right_fan_status;
4030 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
4031 if(right_fan_status == 0) {
4032 snprintf(p, p_max_size,"off");
4033 } if(right_fan_status == 1) {
4034 snprintf(p, p_max_size, "low");
4035 } if(right_fan_status == 2) {
4036 snprintf(p, p_max_size, "high");
4039 OBJ(i8k_left_fan_rpm) {
4040 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
4042 OBJ(i8k_right_fan_rpm) {
4043 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
4045 OBJ(i8k_ac_status) {
4047 sscanf(i8k.ac_status, "%d", &ac_status);
4048 if(ac_status == -1) {
4049 snprintf(p, p_max_size,"disabled (read i8k docs)");
4050 } if(ac_status == 0) {
4051 snprintf(p, p_max_size, "off");
4052 } if(ac_status == 1) {
4053 snprintf(p, p_max_size, "on");
4056 OBJ(i8k_buttons_status) {
4057 snprintf(p, p_max_size, "%s", i8k.buttons_status);
4061 get_ibm_acpi_fan(p, p_max_size);
4064 get_ibm_acpi_temps();
4065 snprintf(p, p_max_size, "%d",
4066 ibm_acpi.temps[obj->data.sensor]);
4069 get_ibm_acpi_volume(p, p_max_size);
4071 OBJ(ibm_brightness) {
4072 get_ibm_acpi_brightness(p, p_max_size);
4075 get_powerbook_batt_info(p, p_max_size, obj->data.i);
4077 #endif /* __linux__ */
4080 OBJ(obsd_sensors_temp) {
4081 obsd_sensors.device = sensor_device;
4082 update_obsd_sensors();
4083 snprintf(p, p_max_size, "%.1f",
4084 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
4087 OBJ(obsd_sensors_fan) {
4088 obsd_sensors.device = sensor_device;
4089 update_obsd_sensors();
4090 snprintf(p, p_max_size, "%d",
4091 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
4094 OBJ(obsd_sensors_volt) {
4095 obsd_sensors.device = sensor_device;
4096 update_obsd_sensors();
4097 snprintf(p, p_max_size, "%.2f",
4098 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4102 get_obsd_vendor(p, p_max_size);
4106 get_obsd_product(p, p_max_size);
4108 #endif /* __OpenBSD__ */
4112 new_font(p, obj->data.s);
4115 /* TODO: move this correction from kB to kB/s elsewhere
4116 * (or get rid of it??) */
4118 if (obj->data.diskio) {
4119 human_readable((obj->data.diskio->current / update_interval) * 1024LL, p, p_max_size, "diskio");
4121 human_readable(diskio_value * 1024LL, p, p_max_size, "diskio");
4125 if (obj->data.diskio) {
4126 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL, p, p_max_size,
4129 human_readable(diskio_write_value * 1024LL, p, p_max_size,
4134 if (obj->data.diskio) {
4135 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL, p, p_max_size,
4138 human_readable(diskio_read_value * 1024LL, p, p_max_size,
4143 if (obj->data.diskio) {
4144 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4145 obj->data.diskio->current, obj->e, 1);
4147 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4148 diskio_value, obj->e, 1);
4151 OBJ(diskiograph_read) {
4152 if (obj->data.diskio) {
4153 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4154 obj->data.diskio->current_read, obj->e, 1);
4156 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4157 diskio_read_value, obj->e, 1);
4160 OBJ(diskiograph_write) {
4161 if (obj->data.diskio) {
4162 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4163 obj->data.diskio->current_write, obj->e, 1);
4165 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4166 diskio_write_value, obj->e, 1);
4170 spaced_print(p, p_max_size, "%d", 6, "downspeed",
4171 round_to_int(obj->data.net->recv_speed / 1024));
4174 spaced_print(p, p_max_size, "%.1f", 8, "downspeedf",
4175 obj->data.net->recv_speed / 1024.0);
4177 OBJ(downspeedgraph) {
4178 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4179 (obj->data.net->recv_speed / 1024.0), obj->e, 1);
4183 i = obj->data.ifblock.pos - 1;
4193 snprintf(p, p_max_size, "%u.%u.%u.%u",
4194 obj->data.net->addr.
4196 obj->data.net->addr.
4198 obj->data.net->addr.
4200 obj->data.net->addr.
4204 #if defined(IMLIB2) && defined(X11)
4209 Imlib_Image image, buffer;
4210 image = imlib_load_image(obj->data.s);
4211 imlib_context_set_image(image);
4214 w = imlib_image_get_width();
4215 h = imlib_image_get_height();
4216 buffer = imlib_create_image(w, h);
4217 imlib_context_set_display(display);
4218 imlib_context_set_drawable(window.drawable);
4219 imlib_context_set_colormap(DefaultColormap(display, screen));
4220 imlib_context_set_visual(DefaultVisual(display, screen));
4221 imlib_context_set_image(buffer);
4222 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
4223 imlib_render_image_on_drawable(text_start_x, text_start_y);
4225 imlib_context_set_image(image);
4232 FILE *fp = popen(obj->data.s, "r");
4233 int length = fread(p, 1, p_max_size, fp);
4236 /*output[length] = '\0';
4237 if (length > 0 && output[length - 1] == '\n') {
4238 output[length - 1] = '\0';
4241 if (length > 0 && p[length - 1] == '\n') {
4242 p[length - 1] = '\0';
4245 //parse_conky_vars(output, p, cur);
4249 FILE *fp = popen(obj->data.s, "r");
4250 int n2 = fread(p, 1, p_max_size, fp);
4254 if (n2 && p[n2 - 1] == '\n')
4263 if (sscanf(p, "%lf", &barnum) == 0) {
4264 ERR("reading execbar value failed (perhaps it's not the correct format?)");
4266 if (barnum > 100 || barnum < 0) {
4267 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
4269 barnum = barnum / 100.0;
4270 new_bar(p, 0, 4, (int) (barnum * 255.0));
4276 FILE *fp = popen(obj->data.s, "r");
4277 int n2 = fread(p, 1, p_max_size, fp);
4281 if (n2 && p[n2 - 1] == '\n')
4290 if (sscanf(p, "%lf", &barnum) == 0) {
4291 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
4293 if (barnum > 100 || barnum < 0) {
4294 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
4296 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
4301 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
4302 new_bar(p, 0, 4, (int) obj->f);
4305 FILE *fp = popen(obj->data.execi.cmd, "r");
4306 int n2 = fread(p, 1, p_max_size, fp);
4309 if (n2 && p[n2 - 1] == '\n')
4318 if (sscanf(p, "%f", &barnum) == 0) {
4319 ERR("reading execibar value failed (perhaps it's not the correct format?)");
4321 if (barnum > 100 || barnum < 0) {
4322 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
4324 obj->f = 255 * barnum / 100.0;
4325 new_bar(p, 0, 4, (int) obj->f);
4327 obj->data.execi.last_update =
4328 current_update_time;
4332 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
4333 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
4336 FILE *fp = popen(obj->data.execi.cmd, "r");
4337 int n2 = fread(p, 1, p_max_size, fp);
4340 if (n2 && p[n2 - 1] == '\n')
4349 if (sscanf(p, "%f", &barnum) == 0) {
4350 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
4352 if (barnum > 100 || barnum < 0) {
4353 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
4356 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
4358 obj->data.execi.last_update = current_update_time;
4364 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
4365 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4367 char *output = obj->data.execi.buffer;
4368 FILE *fp = popen(obj->data.execi.cmd, "r");
4369 //int length = fread(output, 1, text_buffer_size, fp);
4370 int length = fread(output, 1, text_buffer_size, fp);
4373 output[length] = '\0';
4374 if (length > 0 && output[length - 1] == '\n') {
4375 output[length - 1] = '\0';
4377 obj->data.execi.last_update = current_update_time;
4378 snprintf(p, p_max_size, "%s", output);
4380 //parse_conky_vars(output, p, cur);
4383 if (!obj->data.texeci.p_timed_thread)
4385 obj->data.texeci.p_timed_thread=
4386 timed_thread_create ((void*)threaded_exec, (void*) obj, obj->data.texeci.interval * 1000000);
4387 if (!obj->data.texeci.p_timed_thread)
4388 ERR("Error creating texeci timed thread");
4389 timed_thread_register (obj->data.texeci.p_timed_thread, &obj->data.texeci.p_timed_thread);
4390 if (timed_thread_run (obj->data.texeci.p_timed_thread))
4391 ERR("Error running texeci timed thread");
4393 timed_thread_lock (obj->data.texeci.p_timed_thread);
4394 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4395 timed_thread_unlock (obj->data.texeci.p_timed_thread);
4397 #endif /* HAVE_POPEN */
4399 if (obj->global_mode && info.mail) { // this means we use info
4400 if (!info.mail->p_timed_thread)
4402 info.mail->p_timed_thread =
4403 timed_thread_create ((void*)imap_thread, (void*)info.mail, info.mail->interval * 1000000);
4404 if (!info.mail->p_timed_thread)
4405 ERR("Error creating imap timed thread");
4406 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4407 if (timed_thread_run (info.mail->p_timed_thread))
4408 ERR("Error running imap timed thread");
4410 timed_thread_lock (info.mail->p_timed_thread);
4411 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4412 timed_thread_unlock (info.mail->p_timed_thread);
4413 } else if (obj->data.mail) { // this means we use obj
4414 if (!obj->data.mail->p_timed_thread)
4416 obj->data.mail->p_timed_thread =
4417 timed_thread_create ((void*)imap_thread, (void*)obj->data.mail,
4418 obj->data.mail->interval * 1000000);
4419 if (!obj->data.mail->p_timed_thread)
4420 ERR("Error creating imap timed thread");
4421 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4422 if (timed_thread_run (obj->data.mail->p_timed_thread))
4423 ERR("Error running imap timed thread");
4425 timed_thread_lock (obj->data.mail->p_timed_thread);
4426 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4427 timed_thread_unlock (obj->data.mail->p_timed_thread);
4428 } else if (!obj->a) { // something is wrong, warn once then stop
4429 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4433 OBJ(imap_messages) {
4434 if (obj->global_mode && info.mail) { // this means we use info
4435 if (!info.mail->p_timed_thread)
4437 info.mail->p_timed_thread =
4438 timed_thread_create ((void*)imap_thread, (void*)info.mail, info.mail->interval * 1000000);
4439 if (!info.mail->p_timed_thread)
4440 ERR("Error creating imap timed thread");
4441 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4442 if (timed_thread_run (info.mail->p_timed_thread))
4443 ERR("Error running imap timed thread");
4445 timed_thread_lock (info.mail->p_timed_thread);
4446 snprintf(p, p_max_size, "%lu", info.mail->messages);
4447 timed_thread_unlock (info.mail->p_timed_thread);
4448 } else if (obj->data.mail) { // this means we use obj
4449 if (!obj->data.mail->p_timed_thread)
4451 obj->data.mail->p_timed_thread =
4452 timed_thread_create ((void*)imap_thread, (void*)obj->data.mail,
4453 obj->data.mail->interval * 1000000);
4454 if (!obj->data.mail->p_timed_thread)
4455 ERR("Error creating imap timed thread");
4456 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4457 if (timed_thread_run (obj->data.mail->p_timed_thread))
4458 ERR("Error runninging imap timed thread");
4460 timed_thread_lock (obj->data.mail->p_timed_thread);
4461 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4462 timed_thread_lock (obj->data.mail->p_timed_thread);
4463 } else if (!obj->a) { // something is wrong, warn once then stop
4464 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4469 if (obj->global_mode && info.mail) { // this means we use info
4470 if (!info.mail->p_timed_thread)
4472 info.mail->p_timed_thread =
4473 timed_thread_create ((void*)pop3_thread, (void*)info.mail, info.mail->interval * 1000000);
4474 if (!info.mail->p_timed_thread)
4475 ERR("Error creating pop3 timed thread");
4476 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4477 if (timed_thread_run (info.mail->p_timed_thread))
4478 ERR("Error running pop3 timed thread");
4480 timed_thread_lock (info.mail->p_timed_thread);
4481 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4482 timed_thread_unlock (info.mail->p_timed_thread);
4483 } else if (obj->data.mail) { // this means we use obj
4484 if (!obj->data.mail->p_timed_thread)
4486 obj->data.mail->p_timed_thread =
4487 timed_thread_create ((void*)pop3_thread, (void*)obj->data.mail,
4488 obj->data.mail->interval * 1000000);
4489 if (!obj->data.mail->p_timed_thread)
4490 ERR("Error creating pop3 timed thread");
4491 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4492 if (timed_thread_run (obj->data.mail->p_timed_thread))
4493 ERR("Error running pop3 timed thread");
4495 timed_thread_lock (obj->data.mail->p_timed_thread);
4496 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4497 timed_thread_unlock (obj->data.mail->p_timed_thread);
4498 } else if (!obj->a) { // something is wrong, warn once then stop
4499 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4504 if (obj->global_mode && info.mail) { // this means we use info
4505 if (!info.mail->p_timed_thread)
4507 info.mail->p_timed_thread =
4508 timed_thread_create ((void*)pop3_thread, (void*)info.mail, info.mail->interval * 1000000);
4509 if (!info.mail->p_timed_thread)
4510 ERR("Error creating pop3 timed thread");
4511 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4512 if (timed_thread_run (info.mail->p_timed_thread))
4513 ERR("Error running pop3 timed thread");
4515 timed_thread_lock (info.mail->p_timed_thread);
4516 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4517 timed_thread_unlock (info.mail->p_timed_thread);
4518 } else if (obj->data.mail) { // this means we use obj
4519 if (!obj->data.mail->p_timed_thread)
4521 obj->data.mail->p_timed_thread =
4522 timed_thread_create ((void*)pop3_thread, (void*)obj->data.mail,
4523 obj->data.mail->interval * 1000000);
4524 if (!obj->data.mail->p_timed_thread)
4525 ERR("Error creating pop3 timed thread");
4526 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4527 if (timed_thread_run (obj->data.mail->p_timed_thread))
4528 ERR("Error running pop3 timed thread");
4530 timed_thread_lock (obj->data.mail->p_timed_thread);
4531 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4532 timed_thread_unlock (obj->data.mail->p_timed_thread);
4533 } else if (!obj->a) { // something is wrong, warn once then stop
4534 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4539 if (obj->data.fs != NULL) {
4540 if (obj->data.fs->size == 0)
4559 if (obj->data.fs != NULL) {
4560 human_readable(obj->data.fs->avail, p, 255, "fs_free");
4564 if (obj->data.fs != NULL) {
4565 if (obj->data.fs->size)
4566 snprintf(p, p_max_size, "%*d",
4575 snprintf(p, p_max_size, "0");
4579 if (obj->data.fs != NULL) {
4580 human_readable(obj->data.fs->size, p, 255, "fs_size");
4584 if (obj->data.fs != NULL) {
4585 human_readable(obj->data.fs->size -
4586 (obj->data.fs->free ? obj->data.fs->free :
4587 obj->data.fs->avail), p, 255, "fs_used");
4591 if (obj->data.fs != NULL) {
4592 if (obj->data.fs->size == 0)
4610 if (obj->data.fs != NULL) {
4611 if (obj->data.fs->size)
4612 snprintf(p, 4, "%d",
4622 snprintf(p, p_max_size, "0");
4626 float *v = info.loadavg;
4628 if (obj->data.loadavg[2])
4629 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4630 v[obj->data.loadavg[0] -
4632 v[obj->data.loadavg[1] -
4634 v[obj->data.loadavg[2] -
4636 else if (obj->data.loadavg[1])
4637 snprintf(p, p_max_size, "%.2f %.2f",
4638 v[obj->data.loadavg[0] -
4640 v[obj->data.loadavg[1] -
4642 else if (obj->data.loadavg[0])
4643 snprintf(p, p_max_size, "%.2f",
4644 v[obj->data.loadavg[0] -
4648 new_goto(p, obj->data.i);
4651 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4654 new_hr(p, obj->data.i);
4658 PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay);
4661 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4663 if(!strcmp(obj->data.rss.action, "feed_title")) {
4665 if(str[strlen(str)-1] == '\n')
4666 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4667 snprintf(p, p_max_size, "%s", str);
4668 } else if(!strcmp(obj->data.rss.action, "item_title")) {
4669 if(obj->data.rss.act_par < data->item_count) {
4670 str = data->items[obj->data.rss.act_par].title;
4671 if(str[strlen(str)-1] == '\n')
4672 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4673 snprintf(p, p_max_size, "%s", str);
4675 } else if(!strcmp(obj->data.rss.action, "item_desc")) {
4676 if(obj->data.rss.act_par < data->item_count) {
4677 str = data->items[obj->data.rss.act_par].description;
4678 if(str[strlen(str)-1] == '\n')
4679 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4680 snprintf(p, p_max_size, "%s", str);
4682 } else if(!strcmp(obj->data.rss.action, "item_titles")) {
4683 if(data->item_count > 0) {
4687 if(obj->data.rss.act_par > data->item_count)
4688 show = data->item_count;
4689 else show = obj->data.rss.act_par;
4690 for(itmp = 0; itmp < show; itmp++) {
4691 PRSS_Item *item = &data->items[itmp];
4694 if(itmp>0) // don't add new line before first item
4695 strncat(p, "\n", p_max_size);
4696 if(str[strlen(str)-1] == '\n')
4697 str[strlen(str)-1] = 0; // remove trailing new line if one exists, we have our own
4698 strncat(p, str, p_max_size);
4711 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4712 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4714 snprintf(p, p_max_size, "N/A");
4715 } else if (unit == '*') {
4716 snprintf(p, p_max_size, "%s", temp);
4718 snprintf(p, p_max_size, "%s°%c", temp, unit);
4723 new_offset(p, obj->data.i);
4726 new_voffset(p, obj->data.i);
4732 r = get_sysfs_info(&obj->data.sysfs.fd,
4733 obj->data.sysfs.arg,
4734 obj->data.sysfs.devtype,
4735 obj->data.sysfs.type);
4737 if (r >= 100.0 || r == 0)
4738 snprintf(p, p_max_size, "%d", (int) r);
4740 snprintf(p, p_max_size, "%.1f", r);
4745 r = get_sysfs_info(&obj->data.sysfs.fd,
4746 obj->data.sysfs.arg,
4747 obj->data.sysfs.devtype,
4748 obj->data.sysfs.type);
4750 if (r >= 100.0 || r == 0)
4751 snprintf(p, p_max_size, "%d", (int) r);
4753 snprintf(p, p_max_size, "%.1f", r);
4758 r = get_sysfs_info(&obj->data.sysfs.fd,
4759 obj->data.sysfs.arg,
4760 obj->data.sysfs.devtype,
4761 obj->data.sysfs.type);
4763 if (r >= 100.0 || r == 0)
4764 snprintf(p, p_max_size, "%d", (int) r);
4766 snprintf(p, p_max_size, "%.1f", r);
4768 #endif /* !__OpenBSD__ */
4770 new_alignr(p, obj->data.i);
4773 new_alignc(p, obj->data.i);
4776 struct information *my_info =
4777 malloc(sizeof(struct information));
4778 memcpy(my_info, cur, sizeof(struct information));
4779 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4780 if (strlen(p) != 0) {
4781 i = obj->data.ifblock.pos;
4791 if ((obj->data.ifblock.s)
4792 && (stat(obj->data.ifblock.s, &tmp) ==
4794 i = obj->data.ifblock.pos;
4797 if (obj->data.ifblock.str) {
4798 if (!check_contains(obj->data.ifblock.s,
4799 obj->data.ifblock.str)) {
4800 i = obj->data.ifblock.pos;
4809 if ((obj->data.ifblock.s)
4810 && (!check_mount(obj->data.ifblock.s))) {
4811 i = obj->data.ifblock.pos;
4818 if ((obj->data.ifblock.s)
4819 && system(obj->data.ifblock.s)) {
4820 i = obj->data.ifblock.pos;
4827 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4830 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4835 human_readable(cur->mem * 1024, p, 255, "mem");
4838 human_readable(cur->memmax * 1024, p, 255, "memmax");
4842 spaced_print(p, p_max_size, "%*Lu", 4, "memperc",
4843 pad_percents, cur->mem * 100 / cur->memmax);
4847 new_bar(p, obj->data.pair.a,
4849 cur->memmax ? (cur->mem * 255) /
4854 new_graph(p, obj->a,
4855 obj->b, obj->c, obj->d,
4856 cur->memmax ? (cur->mem * 100.0) /
4857 (cur->memmax) : 0.0, 100, 1);
4861 snprintf(p, p_max_size, "%d",
4862 mixer_get_avg(obj->data.l));
4865 snprintf(p, p_max_size, "%d",
4866 mixer_get_left(obj->data.l));
4869 snprintf(p, p_max_size, "%d",
4870 mixer_get_right(obj->data.l));
4873 new_bar(p, obj->data.mixerbar.w,
4874 obj->data.mixerbar.h,
4875 mixer_get_avg(obj->data.mixerbar.
4879 new_bar(p, obj->data.mixerbar.w,
4880 obj->data.mixerbar.h,
4881 mixer_get_left(obj->data.mixerbar.
4885 new_bar(p, obj->data.mixerbar.w,
4886 obj->data.mixerbar.h,
4887 mixer_get_right(obj->data.mixerbar.
4893 update_mail_count(&obj->data.local_mail);
4894 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
4897 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4898 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4901 update_mail_count(&obj->data.local_mail);
4902 snprintf(p, p_max_size, "%d", obj->data.local_mail.new_mail_count);
4906 snprintf(p, p_max_size, "%s",
4907 cur->uname_s.nodename);
4910 new_outline(p, obj->data.l);
4913 spaced_print(p, p_max_size, "%hu", 5, "processes", cur->procs);
4915 OBJ(running_processes) {
4916 spaced_print(p, p_max_size, "%hu", 3, "running_processes",
4920 snprintf(p, p_max_size, "%s", obj->data.s);
4923 new_bg(p, obj->data.l);
4926 new_stippled_hr(p, obj->data.pair.a,
4930 human_readable(cur->swap * 1024, p, 255, "swap");
4933 human_readable(cur->swapmax * 1024, p, 255, "swapmax");
4936 if (cur->swapmax == 0) {
4937 strncpy(p, "No swap", p_max_size);
4939 spaced_print(p, p_max_size, "%*Lu", 4, "swapperc",
4940 pad_percents, cur->swap * 100 / cur->swapmax);
4944 new_bar(p, obj->data.pair.a,
4946 cur->swapmax ? (cur->swap * 255) /
4947 (cur->swapmax) : 0);
4950 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4953 time_t t = time(NULL);
4954 struct tm *tm = localtime(&t);
4955 setlocale(LC_TIME, "");
4956 strftime(p, p_max_size, obj->data.s, tm);
4959 time_t t = time(NULL);
4960 struct tm *tm = gmtime(&t);
4961 strftime(p, p_max_size, obj->data.s, tm);
4965 if (obj->data.tztime.tz) {
4966 oldTZ = getenv("TZ");
4967 setenv("TZ", obj->data.tztime.tz, 1);
4970 time_t t = time(NULL);
4971 struct tm *tm = localtime(&t);
4972 setlocale(LC_TIME, "");
4973 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4975 setenv("TZ", oldTZ, 1);
4980 // Needless to free oldTZ since getenv gives ptr to static data
4983 human_readable(obj->data.net->recv, p, 255, "totaldown");
4986 human_readable(obj->data.net->trans, p, 255, "totalup");
4989 snprintf(p, p_max_size, "%d", total_updates);
4992 spaced_print(p, p_max_size, "%d", 6, "upspeed",
4993 round_to_int(obj->data.net->trans_speed / 1024));
4996 spaced_print(p, p_max_size, "%.1f", 8, "upspeedf",
4997 obj->data.net->trans_speed / 1024.0);
5000 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5001 (obj->data.net->trans_speed / 1024.0), obj->e, 1);
5004 format_seconds_short(p, p_max_size,
5008 format_seconds(p, p_max_size, (int) cur->uptime);
5011 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5014 msg = get_apm_adapter();
5015 snprintf(p, p_max_size, "%s", msg);
5018 OBJ(apm_battery_life) {
5020 msg = get_apm_battery_life();
5021 snprintf(p, p_max_size, "%s", msg);
5024 OBJ(apm_battery_time) {
5026 msg = get_apm_battery_time();
5027 snprintf(p, p_max_size, "%s", msg);
5030 #endif /* __FreeBSD__ __OpenBSD__ */
5034 snprintf(p, cur->mpd.max_title_len > 0 ?
5035 cur->mpd.max_title_len : p_max_size, "%s",
5039 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5042 snprintf(p, p_max_size, "%s", cur->mpd.album);
5045 snprintf(p, p_max_size, "%s", cur->mpd.random);
5048 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
5051 snprintf(p, p_max_size, "%s", cur->mpd.track);
5054 snprintf(p, p_max_size, "%s", cur->mpd.name);
5057 snprintf(p, p_max_size, "%s", cur->mpd.file);
5060 snprintf(p, p_max_size, "%i", cur->mpd.volume);
5063 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
5066 snprintf(p, p_max_size, "%s", cur->mpd.status);
5069 int days = 0, hours = 0, minutes =
5071 int tmp = cur->mpd.elapsed;
5072 while (tmp >= 86400) {
5076 while (tmp >= 3600) {
5086 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
5087 days, hours, minutes,
5090 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
5093 snprintf(p, p_max_size, "%i:%02i", minutes,
5097 int days = 0, hours = 0, minutes =
5099 int tmp = cur->mpd.length;
5100 while (tmp >= 86400) {
5104 while (tmp >= 3600) {
5114 snprintf(p, p_max_size,
5115 "%i days %i:%02i:%02i",
5116 days, hours, minutes,
5119 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
5122 snprintf(p, p_max_size, "%i:%02i", minutes,
5126 snprintf(p, p_max_size, "%2.0f",
5127 cur->mpd.progress * 100);
5130 new_bar(p, obj->data.pair.a,
5132 (int) (cur->mpd.progress *
5136 memset (p, 0, p_max_size);
5137 if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title && *cur->mpd.title) {
5138 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
5140 else if (cur->mpd.title && *cur->mpd.title) {
5141 snprintf(p, p_max_size, "%s", cur->mpd.title);
5143 else if (cur->mpd.artist && *cur->mpd.artist) {
5144 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5146 else if (cur->mpd.file && *cur->mpd.file) {
5147 snprintf(p, p_max_size, "%s", cur->mpd.file);
5156 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5159 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5162 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5165 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5167 OBJ(xmms2_comment) {
5168 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5170 OBJ(xmms2_decoder) {
5171 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
5173 OBJ(xmms2_transport) {
5174 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
5177 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5180 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5183 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5185 OBJ(xmms2_tracknr) {
5186 if (cur->xmms2.tracknr != -1)
5187 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5189 OBJ(xmms2_bitrate) {
5190 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5193 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5196 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5198 OBJ(xmms2_elapsed) {
5199 int tmp = cur->xmms2.elapsed;
5200 snprintf(p, p_max_size, "%02d:%02d",
5201 tmp / 60000, (tmp / 1000) % 60);
5203 OBJ(xmms2_duration) {
5204 int tmp = cur->xmms2.duration;
5205 snprintf(p, p_max_size, "%02d:%02d",
5206 tmp / 60000, (tmp / 1000) % 60);
5208 OBJ(xmms2_percent) {
5209 snprintf(p, p_max_size, "%2.0f",
5210 cur->xmms2.progress * 100);
5213 new_bar(p, obj->data.pair.a,
5215 (int) (cur->xmms2.progress *
5219 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
5220 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5222 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
5227 OBJ(audacious_status) {
5228 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
5230 OBJ(audacious_title) {
5231 snprintf(p, cur->audacious.max_title_len > 0 ?
5232 cur->audacious.max_title_len : p_max_size, "%s",
5233 cur->audacious.items[AUDACIOUS_TITLE]);
5235 OBJ(audacious_length) {
5236 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
5238 OBJ(audacious_length_seconds) {
5239 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5241 OBJ(audacious_position) {
5242 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
5244 OBJ(audacious_position_seconds) {
5245 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5247 OBJ(audacious_bitrate) {
5248 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
5250 OBJ(audacious_frequency) {
5251 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
5253 OBJ(audacious_channels) {
5254 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
5256 OBJ(audacious_filename) {
5257 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
5259 OBJ(audacious_playlist_length) {
5260 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5262 OBJ(audacious_playlist_position) {
5263 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5265 OBJ(audacious_bar) {
5267 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5268 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5269 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
5274 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5277 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5280 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5283 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5286 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5289 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5293 char *format_time(unsigned long time, const int width) {
5295 unsigned long nt; // narrow time, for speed on
5298 unsigned cc; // centiseconds
5299 unsigned nn; // multi-purpose whatever
5302 cc = nt % 100; // centiseconds past second
5303 nt /= 100; // total seconds
5304 nn = nt % 60; // seconds past the minute
5305 nt /= 60; // total minutes
5306 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u", nt,
5309 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn))
5311 nn = nt % 60; // minutes past the hour
5312 nt /= 60; // total hours
5313 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn))
5315 nn = nt; // now also hours
5316 if (width >= snprintf(buf, sizeof buf, "%uh", nn))
5318 nn /= 24; // now days
5319 if (width >= snprintf(buf, sizeof buf, "%ud", nn))
5321 nn /= 7; // now weeks
5322 if (width >= snprintf(buf, sizeof buf, "%uw", nn))
5324 // well shoot, this outta' fit...
5325 return strdup("<inf>");
5329 if (obj->data.top.type == TOP_NAME
5330 && obj->data.top.num >= 0
5331 && obj->data.top.num < 10) {
5332 snprintf(p, 17, "%-17s", cur->cpu[obj->data.top.num]->name);
5333 } else if (obj->data.top.type == TOP_CPU
5334 && obj->data.top.num >= 0
5335 && obj->data.top.num < 10) {
5336 snprintf(p, 7, "%7.3f",
5337 cur->cpu[obj->data.top.
5339 } else if (obj->data.top.type == TOP_PID
5340 && obj->data.top.num >= 0
5341 && obj->data.top.num < 10) {
5342 snprintf(p, 8, "%7i",
5343 cur->cpu[obj->data.top.
5345 } else if (obj->data.top.type == TOP_MEM
5346 && obj->data.top.num >= 0
5347 && obj->data.top.num < 10) {
5348 snprintf(p, 7, "%7.3f",
5349 cur->cpu[obj->data.top.
5351 } else if (obj->data.top.type == TOP_TIME
5352 && obj->data.top.num >= 0
5353 && obj->data.top.num < 10) {
5354 char *time = format_time(cur->cpu[obj->data.top.num]->
5356 snprintf(p, 10, "%9s", time);
5361 if (obj->data.top.type == TOP_NAME
5362 && obj->data.top.num >= 0
5363 && obj->data.top.num < 10) {
5364 snprintf(p, 17, "%-17s",
5365 cur->memu[obj->data.top.
5367 } else if (obj->data.top.type == TOP_CPU
5368 && obj->data.top.num >= 0
5369 && obj->data.top.num < 10) {
5370 snprintf(p, 7, "%7.3f",
5371 cur->memu[obj->data.top.
5373 } else if (obj->data.top.type == TOP_PID
5374 && obj->data.top.num >= 0
5375 && obj->data.top.num < 10) {
5376 snprintf(p, 8, "%7i",
5377 cur->memu[obj->data.top.
5379 } else if (obj->data.top.type == TOP_MEM
5380 && obj->data.top.num >= 0
5381 && obj->data.top.num < 10) {
5382 snprintf(p, 7, "%7.3f",
5383 cur->memu[obj->data.top.
5385 } else if (obj->data.top.type == TOP_TIME
5386 && obj->data.top.num >= 0
5387 && obj->data.top.num < 10) {
5388 char *time = format_time(cur->memu[obj->data.top.num]->
5390 snprintf(p, 10, "%9s", time);
5397 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5398 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5400 obj->data.tail.last_update = current_update_time;
5405 if (obj->data.tail.fd != -1) {
5406 tail_pipe(obj, p, p_max_size);
5410 fp = fopen(obj->data.tail.logfile, "rt");
5413 /* Send one message, but do not consistently spam on
5414 * missing logfiles. */
5415 if(obj->data.tail.readlines != 0) {
5416 ERR("tail logfile failed to open");
5417 strcpy(obj->data.tail.buffer, "Logfile Missing");
5419 obj->data.tail.readlines = 0;
5420 snprintf(p, p_max_size, "Logfile Missing");
5423 obj->data.tail.readlines = 0;
5424 /* -1 instead of 0 to avoid counting a trailing newline */
5425 fseek(fp, -1, SEEK_END);
5426 bsize = ftell(fp) + 1;
5427 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5428 nl = rev_fcharfind(fp, '\n', iter);
5432 obj->data.tail.readlines = iter;
5433 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
5434 fseek(fp, 0, SEEK_SET);
5437 fseek(fp, nl+1, SEEK_SET);
5440 /* Make sure bsize is at least 1 byte smaller than
5441 * the buffer max size. */
5442 if(bsize > (long)((text_buffer_size*20) - 1)) {
5443 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
5444 bsize = text_buffer_size*20 - 1;
5446 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5449 /* Clean up trailing newline, make sure the buffer
5450 * is null terminated. */
5451 if(obj->data.tail.buffer[bsize-1] == '\n')
5452 obj->data.tail.buffer[bsize-1] = '\0';
5454 obj->data.tail.buffer[bsize] = '\0';
5455 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5458 strcpy(obj->data.tail.buffer, "Logfile Empty");
5459 snprintf(p, p_max_size, "Logfile Empty");
5462 } /* if cur_upd_time >= */
5464 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5469 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5470 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5472 obj->data.tail.last_update = current_update_time;
5476 fp = fopen(obj->data.tail.logfile, "rt");
5478 /* Send one message, but do not consistently spam on
5479 * missing logfiles. */
5480 if(obj->data.tail.readlines != 0) {
5481 ERR("head logfile failed to open");
5482 strcpy(obj->data.tail.buffer, "Logfile Missing");
5484 obj->data.tail.readlines = 0;
5485 snprintf(p, p_max_size, "Logfile Missing");
5487 obj->data.tail.readlines = 0;
5488 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5489 nl = fwd_fcharfind(fp, '\n', iter);
5493 obj->data.tail.readlines = iter;
5494 /* Make sure nl is at least 1 byte smaller than
5495 * the buffer max size. */
5496 if(nl > (long)((text_buffer_size*20) - 1)) {
5497 nl = text_buffer_size*20 - 1;
5499 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5502 /* Clean up trailing newline, make sure the buffer
5503 * is null terminated. */
5504 if (obj->data.tail.buffer[nl-1] == '\n') {
5505 obj->data.tail.buffer[nl-1] = '\0';
5508 obj->data.tail.buffer[nl] = '\0';
5510 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5513 strcpy(obj->data.tail.buffer, "Logfile Empty");
5514 snprintf(p, p_max_size, "Logfile Empty");
5516 } /* if fp == null */
5517 } /* cur_upd_time >= */
5519 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5522 #ifdef TCP_PORT_MONITOR
5525 /* grab a pointer to this port monitor */
5526 tcp_port_monitor_t * p_monitor =
5527 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
5528 obj->data.tcp_port_monitor.port_range_begin,
5529 obj->data.tcp_port_monitor.port_range_end );
5531 snprintf(p, p_max_size, "monitor not found");
5535 /* now grab the text of interest */
5536 if ( peek_tcp_port_monitor( p_monitor,
5537 obj->data.tcp_port_monitor.item,
5538 obj->data.tcp_port_monitor.connection_index,
5539 p, p_max_size ) != 0 )
5541 snprintf(p, p_max_size, "monitor peek error");
5550 iconv_converting = 1;
5551 iconv_selected = obj->a;
5556 iconv_converting = 0;
5562 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5564 OBJ(entropy_poolsize)
5566 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5570 double entropy_perc;
5571 entropy_perc = (double)cur->entropy.entropy_avail /
5572 (double)cur->entropy.poolsize;
5573 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5581 unsigned int a = strlen(p);
5584 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5586 size_t dummy1, dummy2;
5587 char *ptr = buff_in;
5590 dummy1 = dummy2 = a;
5592 strncpy(buff_in, p, P_MAX_SIZE);
5594 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5595 while (dummy1 > 0) {
5596 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5598 ERR("Iconv codeset conversion failed");
5603 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5614 double current_update_time, last_update_time;
5616 static void generate_text()
5618 struct information *cur = &info;
5626 current_update_time = get_time();
5629 /* fix diskio rates to b/s (use update_interval */
5630 diskio_read_value = diskio_read_value / update_interval;
5631 diskio_write_value = diskio_write_value / update_interval;
5632 diskio_value = diskio_value / update_interval;
5635 /* add things to the buffer */
5641 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5643 if (stuff_in_upper_case) {
5654 last_update_time = current_update_time;
5661 static void set_font()
5665 if (window.xftdraw != NULL) {
5666 XftDrawDestroy(window.xftdraw);
5668 window.xftdraw = XftDrawCreate(display, window.drawable,
5669 DefaultVisual(display,
5671 DefaultColormap(display,
5676 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5682 static inline int get_string_width(const char *s)
5685 return *s ? calc_text_width(s, strlen(s)) : 0;
5691 static inline int get_string_width_special(char *s)
5704 if (*p == SPECIAL_CHAR) {
5705 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5706 for (i = 0; i < strlen(p); i++) {
5707 *(p + i) = *(p + i + 1);
5709 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5710 width += specials[special_index+index].width;
5717 if (strlen(final) > 1) {
5718 width += calc_text_width(final, strlen(final));
5728 static void text_size_updater(char *s);
5730 int last_font_height;
5731 static void update_text_area()
5735 /* update text size if it isn't fixed */
5740 text_width = minimum_width;
5743 last_font_height = font_height();
5744 for_each_line(text_buffer, text_size_updater);
5746 if (text_height < minimum_height)
5747 text_height = minimum_height;
5748 if (text_width > maximum_width && maximum_width > 0)
5749 text_width = maximum_width;
5752 /* get text position on workarea */
5753 switch (text_alignment) {
5760 x = workarea[2] - text_width - gap_x;
5767 y = workarea[3] - text_height - gap_y;
5771 x = workarea[2] - text_width - gap_x;
5772 y = workarea[3] - text_height - gap_y;
5776 case NONE: // Let the WM manage the window
5787 if (own_window && !fixed_pos) {
5790 text_start_x = border_margin + 1;
5791 text_start_y = border_margin + 1;
5792 window.x = x - border_margin - 1;
5793 window.y = y - border_margin - 1;
5797 /* If window size doesn't match to workarea's size, then window
5798 * probably includes panels (gnome).
5799 * Blah, doesn't work on KDE. */
5800 if (workarea[2] != window.width
5801 || workarea[3] != window.height) {
5815 static int cur_x, cur_y; /* current x and y for drawing */
5816 static int draw_mode; /* FG, BG or OUTLINE */
5817 static long current_color;
5820 static void text_size_updater(char *s)
5824 /* get string widths and skip specials */
5827 if (*p == SPECIAL_CHAR) {
5829 w += get_string_width(s);
5832 if (specials[special_index].type == BAR
5833 || specials[special_index].type == GRAPH) {
5834 w += specials[special_index].width;
5835 if (specials[special_index].height > last_font_height) {
5836 last_font_height = specials[special_index].height;
5837 last_font_height += font_ascent();
5839 } else if (specials[special_index].type == OFFSET) {
5840 if (specials[special_index].arg > 0) {
5841 w += specials[special_index].arg;
5843 } else if (specials[special_index].type == VOFFSET) {
5844 last_font_height += specials[special_index].arg;
5845 } else if (specials[special_index].type == GOTO) {
5846 if (specials[special_index].arg > cur_x) {
5847 w = (int)specials[special_index].arg;
5849 } else if (specials[special_index].type == TAB) {
5850 int start = specials[special_index].arg;
5851 int step = specials[special_index].width;
5852 if (!step || step < 0)
5854 w += step - (cur_x - text_start_x - start) % step;
5855 } else if (specials[special_index].type == FONT) {
5856 selected_font = specials[special_index].font_added;
5857 if (font_height() > last_font_height) {
5858 last_font_height = font_height();
5867 w += get_string_width(s);
5868 if (w > text_width) {
5871 if (text_width > maximum_width && maximum_width) {
5872 text_width = maximum_width;
5875 text_height += last_font_height;
5876 last_font_height = font_height();
5880 static inline void set_foreground_color(long c)
5883 XSetForeground(display, window.gc, c);
5887 static void draw_string(const char *s)
5891 int i, i2, pos, width_of_s;
5894 width_of_s = get_string_width(s);
5895 if (out_to_console) {
5897 fflush(stdout); /* output immediately, don't buffer */
5899 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5900 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5901 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5905 snprintf(space, 2, " ");
5907 max = ((text_width - width_of_s) / get_string_width(space));
5910 * This code looks for tabs in the text and coverts them to spaces.
5911 * The trick is getting the correct number of spaces,
5912 * and not going over the window's size without forcing
5913 * the window larger.
5915 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5916 if (tmpstring1[i] == '\t') // 9 is ascii tab
5920 i2 < (8 - (1 + pos) % 8) && added <= max;
5923 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5924 fprintf(stderr,"buffer overrun detected\n");
5926 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5931 if (tmpstring1[i] != 9) {
5933 if ( pos > TEXT_BUFFER_SIZE-1 )
5934 fprintf(stderr,"buffer overrun detected\n");
5936 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5942 if (text_width == maximum_width) {
5943 /* this means the text is probably pushing the limit, so we'll chop it */
5944 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5945 tmpstring2[strlen(tmpstring2)-1] = '\0';
5955 c.pixel = current_color;
5956 XQueryColor(display, DefaultColormap(display, screen), &c);
5959 c2.color.red = c.red;
5960 c2.color.green = c.green;
5961 c2.color.blue = c.blue;
5962 c2.color.alpha = fonts[selected_font].font_alpha;
5964 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5965 cur_x, cur_y, (XftChar8 *) s,
5968 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5969 cur_x, cur_y, (XftChar8 *) s,
5975 XDrawString(display, window.drawable, window.gc,
5976 cur_x, cur_y, s, strlen(s));
5978 cur_x += width_of_s;
5980 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5983 long redmask, greenmask, bluemask;
5985 void set_up_gradient()
5988 colour_depth = DisplayPlanes(display, screen);
5992 if (colour_depth != 24 && colour_depth != 16) {
5993 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5999 for(i = (colour_depth / 3)-1; i>=0; i--) {
6001 greenmask |= 1 << i;
6004 if (colour_depth%3 == 1) {
6005 greenmask |= 1 << (colour_depth / 3);
6007 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
6008 greenmask = greenmask << (colour_depth / 3);
6011 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 */
6013 int red1, green1, blue1; // first colour
6014 int red2, green2, blue2; // second colour
6015 int red3 = 0, green3 = 0, blue3 = 0; // difference
6016 short redshift = (2*colour_depth / 3 + colour_depth%3);
6017 short greenshift = (colour_depth / 3);
6018 red1 = (first_colour & redmask) >> redshift;
6019 green1 = (first_colour & greenmask) >> greenshift;
6020 blue1 = first_colour & bluemask;
6021 red2 = (last_colour & redmask) >> redshift;
6022 green2 = (last_colour & greenmask) >> greenshift;
6023 blue2 = last_colour & bluemask;
6030 if (green1 > green2) {
6033 if (green1 < green2) {
6036 if (blue1 > blue2) {
6039 if (blue1 < blue2) {
6054 if (red1 > bluemask) {
6057 if (green1 > bluemask) {
6060 if (blue1 > bluemask) {
6063 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
6067 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
6068 if (colour_depth == 0) {
6071 int red1, green1, blue1; // first colour
6072 int red2, green2, blue2; // second colour
6073 long redshift = (2*colour_depth / 3 + colour_depth%3);
6074 long greenshift = (colour_depth / 3);
6075 int red3 = 0, green3 = 0, blue3 = 0; // difference
6076 red1 = (first_colour & redmask) >> redshift;
6077 green1 = (first_colour & greenmask) >> greenshift;
6078 blue1 = first_colour & bluemask;
6079 red2 = (last_colour & redmask) >> redshift;
6080 green2 = (last_colour & greenmask) >> greenshift;
6081 blue2 = last_colour & bluemask;
6082 red3 = abs(red1 - red2);
6083 green3 = abs(green1 - green2);
6084 blue3 = abs(blue1 - blue2);
6093 static void draw_line(char *s)
6097 cur_x = text_start_x;
6098 cur_y += font_ascent();
6100 short font_h = font_height();
6102 /* find specials and draw stuff */
6105 if (*p == SPECIAL_CHAR) {
6108 /* draw string before special */
6115 switch (specials[special_index].type) {
6116 case HORIZONTAL_LINE:
6119 specials[special_index].height;
6120 int mid = font_ascent() / 2;
6121 w = text_start_x + text_width -
6124 XSetLineAttributes(display,
6129 XDrawLine(display, window.drawable,
6140 specials[special_index].height;
6142 specials[special_index].arg;
6143 int mid = font_ascent() / 2;
6144 char ss[2] = { s, s };
6145 w = text_start_x + text_width -
6148 XSetLineAttributes(display,
6153 XSetDashes(display, window.gc, 0,
6155 XDrawLine(display, window.drawable,
6165 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
6169 specials[special_index].height;
6171 specials[special_index].arg;
6172 int by = cur_y - (font_ascent() / 2) - 1;
6173 if (h < font_height()) {
6176 w = specials[special_index].width;
6179 text_width - cur_x - 1;
6183 XSetLineAttributes(display,
6189 XDrawRectangle(display,
6193 XFillRectangle(display,
6197 w * bar_usage / 255,
6199 if (specials[special_index].
6201 && specials[special_index].
6205 [special_index].height;
6212 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
6216 specials[special_index].height;
6217 unsigned long last_colour = current_color;
6218 int by = cur_y - (font_ascent()/2) - 1;
6219 if (h < font_height()) {
6222 w = specials[special_index].width;
6224 w = text_start_x + text_width - cur_x - 1;
6227 if (draw_graph_borders) {
6228 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
6229 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
6231 XSetLineAttributes(display,
6238 int gradient_size = 0;
6239 float gradient_factor = 0;
6240 float gradient_update = 0;
6241 unsigned long tmpcolour = current_color;
6242 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
6243 tmpcolour = specials[special_index].last_colour;
6244 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
6245 gradient_factor = (float)gradient_size / (w - 2);
6247 for (i = w - 2; i > -1; i--) {
6248 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
6249 XSetForeground(display, window.gc, tmpcolour);
6250 gradient_update += gradient_factor;
6251 while (gradient_update > 0) {
6252 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
6256 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
6259 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 */
6261 if (specials[special_index].
6263 && specials[special_index].
6267 [special_index].height;
6269 /* if (draw_mode == BG) {
6270 set_foreground_color(default_bg_color);
6272 else if (draw_mode == OUTLINE) {
6273 set_foreground_color(default_out_color);
6275 set_foreground_color(default_fg_color);
6277 set_foreground_color(last_colour);
6283 int old = font_ascent();
6284 cur_y -= font_ascent();
6285 selected_font = specials[special_index].font_added;
6286 if (cur_y + font_ascent() < cur_y + old) {
6289 cur_y += font_ascent();
6295 if (draw_mode == FG)
6296 set_foreground_color(specials
6302 if (draw_mode == BG)
6303 set_foreground_color(specials
6309 if (draw_mode == OUTLINE)
6310 set_foreground_color(specials
6316 w += specials[special_index].arg;
6320 cur_y += specials[special_index].arg;
6324 if (specials[special_index].arg >= 0)
6325 cur_x = (int)specials[special_index].arg;
6330 int start = specials[special_index].arg;
6331 int step = specials[special_index].width;
6332 if (!step || step < 0)
6334 w = step - (cur_x - text_start_x - start) % step;
6340 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
6341 /*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);*/
6342 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6343 cur_x = pos_x - specials[special_index].arg;
6350 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
6351 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
6352 /*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);*/
6354 specials[special_index].arg)
6357 [special_index].arg;
6374 if (cur_y_add > 0) {
6376 cur_y -= font_descent();
6381 cur_y += font_descent();
6385 static void draw_text()
6388 cur_y = text_start_y;
6391 if (draw_borders && border_width > 0) {
6392 unsigned int b = (border_width + 1) / 2;
6394 if (stippled_borders) {
6396 { stippled_borders, stippled_borders };
6397 XSetLineAttributes(display, window.gc,
6398 border_width, LineOnOffDash,
6399 CapButt, JoinMiter);
6400 XSetDashes(display, window.gc, 0, ss, 2);
6402 XSetLineAttributes(display, window.gc,
6403 border_width, LineSolid,
6404 CapButt, JoinMiter);
6407 XDrawRectangle(display, window.drawable, window.gc,
6408 text_start_x - border_margin + b,
6409 text_start_y - border_margin + b,
6410 text_width + border_margin * 2 - 1 - b * 2,
6411 text_height + border_margin * 2 - 1 -
6418 for_each_line(text_buffer, draw_line);
6421 static void draw_stuff()
6425 if (draw_shades && !draw_outline) {
6428 set_foreground_color(default_bg_color);
6438 for (i = -1; i < 2; i++)
6439 for (j = -1; j < 2; j++) {
6440 if (i == 0 && j == 0)
6444 set_foreground_color(default_out_color);
6445 draw_mode = OUTLINE;
6452 set_foreground_color(default_fg_color);
6460 swap.swap_window = window.window;
6461 swap.swap_action = XdbeBackground;
6462 XdbeSwapBuffers(display, &swap, 1);
6468 static void clear_text(int exposures)
6472 return; /* The swap action is XdbeBackground, which clears */
6476 /* there is some extra space for borders and outlines */
6477 XClearArea(display, window.window,
6478 text_start_x - border_margin - 1,
6479 text_start_y - border_margin - 1,
6480 text_width + border_margin * 2 + 2,
6481 text_height + border_margin * 2 + 2,
6482 exposures ? True : 0);
6487 static int need_to_update;
6489 /* update_text() generates new text and clears old text area */
6490 static void update_text()
6499 static void main_loop()
6501 #ifdef SIGNAL_BLOCKING
6502 sigset_t newmask, oldmask;
6504 sigemptyset(&newmask);
6505 sigaddset(&newmask,SIGINT);
6506 sigaddset(&newmask,SIGTERM);
6507 sigaddset(&newmask,SIGUSR1);
6511 Region region = XCreateRegion();
6513 int event_base, error_base;
6514 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
6515 ERR("Xdamage extension unavailable");
6517 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
6518 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
6519 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
6520 #endif /* HAVE_XDAMAGE */
6524 while (total_run_times == 0 || info.looped < total_run_times) {
6527 #ifdef SIGNAL_BLOCKING
6528 /* block signals. we will inspect for pending signals later */
6529 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
6530 CRIT_ERR("unable to sigprocmask()");
6536 /* wait for X event or timeout */
6538 if (!XPending(display)) {
6543 update_interval - (get_time() -
6549 tv.tv_sec = (long) t;
6550 tv.tv_usec = (long) (t * 1000000) % 1000000;
6552 FD_SET(ConnectionNumber(display), &fdsr);
6555 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
6558 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
6563 ERR("can't select(): %s",
6574 if (need_to_update) {
6576 int wx = window.x, wy = window.y;
6584 /* resize window if it isn't right size */
6586 (text_width + border_margin * 2 + 1 !=
6588 || text_height + border_margin * 2 + 1 !=
6592 border_margin * 2 + 1;
6595 border_margin * 2 + 1;
6596 XResizeWindow(display,
6601 set_transparent_background(window.window);
6605 /* move window if it isn't in right position */
6608 || window.y != wy)) {
6609 XMoveWindow(display, window.window,
6610 window.x, window.y);
6620 r.x = text_start_x - border_margin;
6621 r.y = text_start_y - border_margin;
6622 r.width = text_width + border_margin * 2;
6623 r.height = text_height + border_margin * 2;
6624 XUnionRectWithRegion(&r, region, region);
6629 /* handle X events */
6631 while (XPending(display)) {
6633 XNextEvent(display, &ev);
6640 r.width = ev.xexpose.width;
6641 r.height = ev.xexpose.height;
6642 XUnionRectWithRegion(&r, region,
6648 case ReparentNotify:
6649 /* set background to ParentRelative for all parents */
6651 set_transparent_background(window.
6656 case ConfigureNotify:
6658 /* if window size isn't what expected, set fixed size */
6659 if (ev.xconfigure.width !=
6661 || ev.xconfigure.height !=
6663 if (window.width != 0
6664 && window.height != 0)
6667 /* clear old stuff before screwing up size and pos */
6673 if (XGetWindowAttributes(display, window.window, &attrs)) {
6688 border_margin * 2 - 1;
6691 border_margin * 2 - 1;
6692 if (text_width > maximum_width && maximum_width > 0)
6693 text_width = maximum_width;
6696 /* if position isn't what expected, set fixed pos, total_updates
6697 * avoids setting fixed_pos when window is set to weird locations
6699 /*if (total_updates >= 2 this is broken
6701 && (window.x != ev.xconfigure.x
6704 && (ev.xconfigure.x != 0
6705 || ev.xconfigure.y != 0)) {
6715 /* if an ordinary window with decorations */
6716 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6718 /* allow conky to hold input focus.*/
6723 /* forward the click to the desktop window */
6724 XUngrabPointer(display, ev.xbutton.time);
6725 ev.xbutton.window = window.desktop;
6726 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6727 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6735 /* if an ordinary window with decorations */
6736 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6738 /* allow conky to hold input focus.*/
6743 /* forward the release to the desktop window */
6744 ev.xbutton.window = window.desktop;
6745 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6754 if (ev.type == event_base + XDamageNotify) {
6755 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6756 XFixesSetRegion(display, part, &dev->area, 1);
6757 XFixesUnionRegion(display, region2, region2, part);
6759 #endif /* HAVE_XDAMAGE */
6764 XDamageSubtract(display, damage, region2, None);
6765 XFixesSetRegion(display, region2, 0, 0);
6766 #endif /* HAVE_XDAMAGE */
6768 /* XDBE doesn't seem to provide a way to clear the back buffer without
6769 * interfering with the front buffer, other than passing XdbeBackground
6770 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6771 * redraw the text even if it wasn't part of the exposed area. OTOH,
6772 * if we're not going to call draw_stuff at all, then no swap happens
6773 * and we can safely do nothing.
6776 if (!XEmptyRegion(region)) {
6780 r.x = text_start_x - border_margin;
6781 r.y = text_start_y - border_margin;
6782 r.width = text_width + border_margin * 2;
6783 r.height = text_height + border_margin * 2;
6784 XUnionRectWithRegion(&r, region, region);
6787 XSetRegion(display, window.gc, region);
6790 XftDrawSetClip(window.xftdraw, region);
6796 XDestroyRegion(region);
6797 region = XCreateRegion();
6801 #ifdef SIGNAL_BLOCKING
6802 /* unblock signals of interest and let handler fly */
6803 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6804 CRIT_ERR("unable to sigprocmask()");
6807 switch(g_signal_pending) {
6810 ERR("received SIGUSR1. reloading the config file.");
6817 ERR("received SIGINT or SIGTERM to terminate. bye!");
6820 XDestroyRegion(region);
6823 return; /* return from main_loop */
6828 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6829 * but didn't write any code to deal with it. if you don't want to
6830 * handle a signal, don't set a handler on it in the first place. */
6831 if (g_signal_pending)
6832 ERR("ignoring signal (%d)", g_signal_pending);
6839 #if defined(X11) && defined(HAVE_XDAMAGE)
6840 XDamageDestroy(display, damage);
6841 XFixesDestroyRegion(display, region2);
6842 XFixesDestroyRegion(display, part);
6843 XDestroyRegion(region);
6845 #endif /* X11 && HAVE_XDAMAGE */
6848 static void load_config_file(const char *);
6850 /* reload the config file */
6851 void reload_config(void)
6853 timed_thread_destroy_registered_threads ();
6855 if (info.cpu_usage) {
6856 free(info.cpu_usage);
6857 info.cpu_usage = NULL;
6866 if (info.mpd.title) {
6867 free(info.mpd.title);
6870 if (info.mpd.artist) {
6871 free(info.mpd.artist);
6872 info.mpd.artist = 0;
6874 if (info.mpd.album) {
6875 free(info.mpd.album);
6878 if (info.mpd.random) {
6879 free(info.mpd.random);
6880 info.mpd.random = 0;
6882 if (info.mpd.repeat) {
6883 free(info.mpd.repeat);
6884 info.mpd.repeat = 0;
6886 if (info.mpd.track) {
6887 free(info.mpd.track);
6890 if (info.mpd.name) {
6891 free(info.mpd.name);
6894 if (info.mpd.file) {
6895 free(info.mpd.file);
6898 if (info.mpd.status) {
6899 free(info.mpd.status);
6900 info.mpd.status = 0;
6908 #ifdef TCP_PORT_MONITOR
6909 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6912 if (current_config) {
6914 load_config_file(current_config);
6916 /* re-init specials array */
6917 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6918 ERR("failed to realloc specials array");
6923 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6926 #ifdef TCP_PORT_MONITOR
6927 info.p_tcp_port_monitor_collection = NULL;
6930 if (create_audacious_thread() !=0)
6931 CRIT_ERR("unable to create audacious thread!");
6932 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6934 extract_variable_text(text);
6943 timed_thread_destroy_registered_threads ();
6945 if (info.cpu_usage) {
6946 free(info.cpu_usage);
6947 info.cpu_usage = NULL;
6952 XdbeDeallocateBackBufferName(display, window.back_buffer);
6958 XDestroyWindow(display, window.window);
6959 XClearWindow(display, RootWindow(display, screen));
6965 XClearWindow(display, RootWindow(display, screen));
6970 XFreeGC(display, window.gc);
6974 free_text_objects(text_object_count, text_objects);
6975 text_object_count = 0;
6976 text_objects = NULL;
6981 free(current_config);
6983 #ifdef TCP_PORT_MONITOR
6984 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6985 info.p_tcp_port_monitor_collection = NULL;
6993 for(i=0;i<special_count;i++)
6994 if(specials[i].type == GRAPH)
6995 free(specials[i].graph);
7000 clear_diskio_stats();
7003 static int string_to_bool(const char *s)
7007 if (strcasecmp(s, "yes") == 0)
7009 if (strcasecmp(s, "true") == 0)
7011 if (strcasecmp(s, "1") == 0)
7016 static enum alignment string_to_alignment(const char *s)
7018 if (strcasecmp(s, "top_left") == 0)
7020 else if (strcasecmp(s, "top_right") == 0)
7022 else if (strcasecmp(s, "bottom_left") == 0)
7024 else if (strcasecmp(s, "bottom_right") == 0)
7025 return BOTTOM_RIGHT;
7026 else if (strcasecmp(s, "tl") == 0)
7028 else if (strcasecmp(s, "tr") == 0)
7030 else if (strcasecmp(s, "bl") == 0)
7032 else if (strcasecmp(s, "br") == 0)
7033 return BOTTOM_RIGHT;
7034 else if (strcasecmp(s, "none") == 0)
7041 static void set_default_configurations(void)
7043 fork_to_background = 0;
7044 total_run_times = 0;
7045 info.cpu_avg_samples = 2;
7046 info.net_avg_samples = 2;
7053 strcpy(info.mpd.host, "localhost");
7054 info.mpd.port = 6600;
7055 info.mpd.status = NULL;
7056 info.mpd.artist = NULL;
7057 info.mpd.album = NULL;
7058 info.mpd.title = NULL;
7059 info.mpd.random = NULL;
7060 info.mpd.track = NULL;
7061 info.mpd.name = NULL;
7062 info.mpd.file = NULL;
7065 info.xmms2.artist = NULL;
7066 info.xmms2.album = NULL;
7067 info.xmms2.title = NULL;
7068 info.xmms2.genre = NULL;
7069 info.xmms2.comment = NULL;
7070 info.xmms2.decoder = NULL;
7071 info.xmms2.transport = NULL;
7072 info.xmms2.url = NULL;
7073 info.xmms2.status = NULL;
7075 use_spacer = NO_SPACER;
7082 default_fg_color = WhitePixel(display, screen);
7083 default_bg_color = BlackPixel(display, screen);
7084 default_out_color = BlackPixel(display, screen);
7085 color0 = default_fg_color;
7086 color1 = default_fg_color;
7087 color2 = default_fg_color;
7088 color3 = default_fg_color;
7089 color4 = default_fg_color;
7090 color5 = default_fg_color;
7091 color6 = default_fg_color;
7092 color7 = default_fg_color;
7093 color8 = default_fg_color;
7094 color9 = default_fg_color;
7097 draw_graph_borders = 1;
7099 set_first_font("6x10");
7107 window.type=TYPE_NORMAL;
7109 strcpy(window.class_name, "Conky");
7111 sprintf(window.title,"Conky (%s)",info.uname_s.nodename);
7113 stippled_borders = 0;
7116 text_alignment = BOTTOM_LEFT;
7119 free(current_mail_spool);
7122 variable_substitute(MAIL_FILE, buf, 256);
7124 current_mail_spool = strdup(buf);
7128 update_interval = 3.0;
7129 info.music_player_interval = 1.0;
7130 stuff_in_upper_case = 0;
7132 #ifdef TCP_PORT_MONITOR
7133 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7137 static void load_config_file(const char *f)
7139 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7143 set_default_configurations();
7149 char buf[256], *p, *p2, *name, *value;
7151 if (fgets(buf, 256, fp) == NULL)
7156 /* break at comment */
7157 p2 = strchr(p, '#');
7162 while (*p && isspace((int) *p))
7165 continue; /* empty line */
7171 while (*p2 && !isspace((int) *p2))
7174 *p2 = '\0'; /* break at name's end */
7181 while (*p && isspace((int) *p))
7186 p2 = value + strlen(value);
7187 while (isspace((int) *(p2 - 1)))
7193 #define CONF2(a) if (strcasecmp(name, a) == 0)
7194 #define CONF(a) else CONF2(a)
7195 #define CONF3(a,b) \
7196 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
7200 CONF2("alignment") {
7202 int a = string_to_alignment(value);
7210 CONF("background") {
7211 fork_to_background = string_to_bool(value);
7215 CONF2("background") {
7216 fork_to_background = string_to_bool(value);
7220 CONF("border_margin") {
7222 border_margin = strtol(value, 0, 0);
7226 CONF("border_width") {
7228 border_width = strtol(value, 0, 0);
7234 color0 = get_x11_color(value);
7240 color1 = get_x11_color(value);
7246 color2 = get_x11_color(value);
7252 color3 = get_x11_color(value);
7258 color4 = get_x11_color(value);
7264 color5 = get_x11_color(value);
7270 color6 = get_x11_color(value);
7276 color7 = get_x11_color(value);
7282 color8 = get_x11_color(value);
7288 color9 = get_x11_color(value);
7292 CONF("default_color") {
7294 default_fg_color = get_x11_color(value);
7298 CONF3("default_shade_color", "default_shadecolor") {
7300 default_bg_color = get_x11_color(value);
7304 CONF3("default_outline_color", "default_outlinecolor") {
7306 default_out_color = get_x11_color(value);
7313 info.mail = parse_mail_args(IMAP, value);
7320 info.mail = parse_mail_args(POP3, value);
7328 strncpy(info.mpd.host, value, 127);
7334 info.mpd.port = strtol(value, 0, 0);
7335 if (info.mpd.port < 1
7336 || info.mpd.port > 0xffff)
7340 CONF("mpd_password") {
7342 strncpy(info.mpd.password, value, 127);
7347 CONF("music_player_interval") {
7349 info.music_player_interval = strtod(value, 0);
7354 CONF("sensor_device") {
7356 sensor_device = strtol(value, 0, 0);
7361 CONF("cpu_avg_samples") {
7363 cpu_avg_samples = strtol(value, 0, 0);
7364 if (cpu_avg_samples < 1
7365 || cpu_avg_samples > 14)
7374 CONF("net_avg_samples") {
7376 net_avg_samples = strtol(value, 0, 0);
7377 if (net_avg_samples < 1
7378 || net_avg_samples > 14)
7394 CONF("double_buffer") {
7395 use_xdbe = string_to_bool(value);
7399 CONF("override_utf8_locale") {
7400 utf8_mode = string_to_bool(value);
7403 CONF("draw_borders") {
7404 draw_borders = string_to_bool(value);
7406 CONF("draw_graph_borders") {
7407 draw_graph_borders = string_to_bool(value);
7409 CONF("draw_shades") {
7410 draw_shades = string_to_bool(value);
7412 CONF("draw_outline") {
7413 draw_outline = string_to_bool(value);
7416 CONF("out_to_console") {
7417 out_to_console = string_to_bool(value);
7419 CONF("use_spacer") {
7421 if (strcasecmp(value, "left") == 0) {
7422 use_spacer = LEFT_SPACER;
7423 } else if (strcasecmp(value, "right") == 0) {
7424 use_spacer = RIGHT_SPACER;
7425 } else if (strcasecmp(value, "none") == 0) {
7426 use_spacer = NO_SPACER;
7428 use_spacer = string_to_bool(value);
7429 ERR("use_spacer should have an argument of left, right, or"
7430 " none. '%s' seems to be some form of '%s', so"
7431 " defaulting to %s.", value,
7432 use_spacer ? "true" : "false",
7433 use_spacer ? "right" : "none");
7435 use_spacer = RIGHT_SPACER;
7437 use_spacer = NO_SPACER;
7441 ERR("use_spacer should have an argument. Defaulting to right.");
7442 use_spacer = RIGHT_SPACER;
7448 use_xft = string_to_bool(value);
7452 set_first_font(value);
7457 if (value && font_count >= 0)
7458 fonts[0].font_alpha = atof(value)
7467 if (string_to_bool(value))
7468 ERR("Xft not enabled");
7471 /* xftfont silently ignored when no Xft */
7474 /* xftalpha is silently ignored when no Xft */
7479 set_first_font(value);
7488 gap_x = atoi(value);
7494 gap_y = atoi(value);
7499 CONF("mail_spool") {
7502 variable_substitute(value, buf, 256);
7506 if (current_mail_spool)
7507 free(current_mail_spool);
7508 current_mail_spool = strdup(buf);
7514 CONF("minimum_size") {
7517 (value, "%d %d", &minimum_width,
7518 &minimum_height) != 2)
7521 &minimum_width) != 1)
7526 CONF("maximum_width") {
7528 if (sscanf(value, "%d", &maximum_width) != 1)
7534 CONF("no_buffers") {
7535 no_buffers = string_to_bool(value);
7537 CONF("top_cpu_separate") {
7538 cpu_separate = string_to_bool(value);
7540 CONF("short_units") {
7541 short_units = string_to_bool(value);
7543 CONF("pad_percents") {
7544 pad_percents = atoi(value);
7548 CONF("own_window") {
7550 own_window = string_to_bool(value);
7554 CONF("own_window_class") {
7557 memset(window.class_name,0,sizeof(window.class_name));
7558 strncpy(window.class_name, value, sizeof(window.class_name)-1);
7563 CONF("own_window_title") {
7566 memset(window.title,0,sizeof(window.title));
7567 strncpy(window.title, value, sizeof(window.title)-1);
7572 CONF("own_window_transparent") {
7574 set_transparent = string_to_bool(value);
7578 CONF("own_window_colour") {
7580 background_colour = get_x11_color(value);
7582 ERR("Invalid colour for own_window_colour (try omitting the '#' for hex colours");
7585 CONF("own_window_hints") {
7587 char *p_hint, *p_save;
7588 char delim[] = ", ";
7590 /* tokenize the value into individual hints */
7591 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
7593 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
7594 if (strncmp(p_hint,"undecorate",10) == 0)
7595 SET_HINT(window.hints,HINT_UNDECORATED);
7596 else if (strncmp(p_hint,"below",5) == 0)
7597 SET_HINT(window.hints,HINT_BELOW);
7598 else if (strncmp(p_hint,"above",5) == 0)
7599 SET_HINT(window.hints,HINT_ABOVE);
7600 else if (strncmp(p_hint,"sticky",6) == 0)
7601 SET_HINT(window.hints,HINT_STICKY);
7602 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
7603 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
7604 else if (strncmp(p_hint,"skip_pager",10) == 0)
7605 SET_HINT(window.hints,HINT_SKIP_PAGER);
7609 p_hint=strtok_r(NULL, delim, &p_save);
7611 while (p_hint!=NULL);
7616 CONF("own_window_type") {
7618 if (strncmp(value,"normal",6)==0)
7619 window.type = TYPE_NORMAL;
7620 else if (strncmp(value,"desktop",7)==0)
7621 window.type = TYPE_DESKTOP;
7622 else if (strncmp(value,"override",8)==0)
7623 window.type = TYPE_OVERRIDE;
7631 CONF("stippled_borders") {
7633 stippled_borders = strtol(value, 0, 0);
7635 stippled_borders = 4;
7639 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
7642 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
7644 CONF("update_interval") {
7646 update_interval = strtod(value, 0);
7649 if (info.music_player_interval == 0) {
7650 // default to update_interval
7651 info.music_player_interval = update_interval;
7654 CONF("total_run_times") {
7656 total_run_times = strtod(value, 0);
7661 stuff_in_upper_case = string_to_bool(value);
7663 CONF("max_specials") {
7665 max_specials = atoi(value);
7669 CONF("max_user_text") {
7671 max_user_text = atoi(value);
7675 CONF("text_buffer_size") {
7677 text_buffer_size = atoi(value);
7692 int l = strlen(text);
7693 if (fgets(buf, 256, fp) == NULL)
7696 realloc(text, l + strlen(buf)
7700 if (strlen(text) > max_user_text)
7704 text_lines = line + 1;
7707 #ifdef TCP_PORT_MONITOR
7708 CONF("max_port_monitor_connections")
7711 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7712 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
7714 /* an error. use default, warn and continue. */
7715 tcp_port_monitor_args.max_port_monitor_connections =
7716 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7719 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
7721 /* no error, just use default */
7722 tcp_port_monitor_args.max_port_monitor_connections =
7723 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7725 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
7730 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7739 if (info.music_player_interval == 0) {
7740 // default to update_interval
7741 info.music_player_interval = update_interval;
7746 /* : means that character before that takes an argument */
7747 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
7759 static const struct option
7761 { "help", 0, NULL, 'h' },
7762 { "version", 0, NULL, 'V' },
7763 { "config", 1, NULL, 'c' },
7764 { "daemonize", 0, NULL, 'd' },
7766 { "alignment", 1, NULL, 'a'},
7767 { "font", 1, NULL, 'f'},
7769 { "own-window", 0, NULL, 'o'},
7772 { "double-buffer", 0, NULL, 'b'},
7774 { "window-id", 1, NULL, 'w'},
7776 { "text", 1, NULL, 't' },
7777 { "interval", 0, NULL, 'u' },
7781 int main(int argc, char **argv)
7783 struct sigaction act, oact;
7786 memset(&info, 0, sizeof(info));
7788 #ifdef TCP_PORT_MONITOR
7789 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7792 /* handle command line parameters that don't change configs */
7797 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7798 *s) || ((s = getenv("LANG")) && *s)) {
7799 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7801 ERR("malloc failed");
7803 for (x = 0; x < strlen(s); x++) {
7804 temp[x] = tolower(s[x]);
7807 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7813 if (!setlocale(LC_CTYPE, "")) {
7814 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7818 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
7831 free(current_config);
7832 current_config = strdup(optarg);
7837 "Usage: %s [OPTION]...\n"
7838 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7839 "window. Command line options will override configurations defined in config\n"
7841 " -V, --version version\n"
7842 " -c, --config=FILE config file to load\n"
7843 " -d, --daemonize daemonize, fork to background\n"
7844 " -h, --help help\n"
7846 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7847 " -f, --font=FONT font to use\n"
7849 " -o, --own-window create own window to draw\n"
7852 " -b, --double-buffer double buffer (prevents flickering)\n"
7854 " -w, --window-id=WIN_ID window id to draw\n"
7855 " -x X x position\n"
7856 " -y Y y position\n"
7858 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
7859 " -u, --interval=SECS update interval\n"
7860 " -i NUM number of times to update Conky\n",
7866 window.window = strtol(optarg, 0, 0);
7875 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7879 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
7881 if (!current_config) {
7882 /* load default config file */
7886 /* Try to use personal config file first */
7887 variable_substitute(CONFIG_FILE, buf, sizeof(buf));
7888 if (buf[0] && (fp=fopen(buf,"r"))) {
7889 current_config = strdup(buf);
7893 /* Try to use system config file if personal config not readable */
7894 if (!current_config && (fp=fopen(SYSTEM_CONFIG_FILE,"r"))) {
7895 current_config = strdup(SYSTEM_CONFIG_FILE);
7899 /* No readable config found */
7900 if (!current_config)
7901 CRIT_ERR("no readable personal or system-wide config file found");
7904 load_config_file(current_config);
7906 /* init specials array */
7907 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7908 ERR("failed to create specials array");
7911 if (current_mail_spool == NULL) {
7913 variable_substitute(MAIL_FILE, buf, 256);
7916 current_mail_spool = strdup(buf);
7920 /* handle other command line arguments */
7922 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
7923 optind = optreset = 1;
7928 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
7929 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7930 O_RDONLY, "kvm_open")) == NULL)
7931 CRIT_ERR( "cannot read kvm");
7935 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
7944 fork_to_background = 1;
7949 set_first_font(optarg);
7952 text_alignment = string_to_alignment(optarg);
7969 text = strdup(optarg);
7970 convert_escapes(text);
7974 update_interval = strtod(optarg, 0);
7975 if (info.music_player_interval == 0) {
7976 // default to update_interval
7977 info.music_player_interval = update_interval;
7982 total_run_times = strtod(optarg, 0);
7986 gap_x = atoi(optarg);
7990 gap_y = atoi(optarg);
8004 /* generate text and get initial size */
8005 extract_variable_text(text);
8011 if (fork_to_background) {
8015 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
8021 fprintf(stderr,"\n"); fflush(stderr);
8025 /* parent process */
8026 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
8033 update_text_area(); /* to get initial size of the window */
8037 text_width + border_margin * 2 + 1,
8038 text_height + border_margin * 2 + 1,
8039 set_transparent, background_colour, argv, argc);
8042 update_text_area(); /* to position text/window on screen */
8047 if (own_window && !fixed_pos) {
8048 XMoveWindow(display, window.window, window.x, window.y);
8051 set_transparent_background(window.window);
8062 /* Set signal handlers */
8063 act.sa_handler = signal_handler;
8064 sigemptyset(&act.sa_mask);
8067 act.sa_flags |= SA_RESTART;
8070 if ( sigaction(SIGINT,&act,&oact) < 0 ||
8071 sigaction(SIGUSR1,&act,&oact) < 0 ||
8072 sigaction(SIGTERM,&act,&oact) < 0 )
8074 ERR("error setting signal handler: %s", strerror(errno) );
8078 if (create_audacious_thread() !=0)
8079 CRIT_ERR("unable to create audacious thread!");
8080 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
8091 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8098 void signal_handler(int sig)
8100 /* signal handler is light as a feather, as it should be.
8101 * we will poll g_signal_pending with each loop of conky
8102 * and do any signal processing there, NOT here. */
8103 g_signal_pending=sig;