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, enum special_types 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);
563 void *memrchr(const void *buffer, char c, size_t n)
565 const unsigned char *p = buffer;
567 for (p += n; n ; n--)
573 long rev_fcharfind(FILE* fp, char val, unsigned int step) {
576 unsigned int count = 0;
577 static char buf[BUFSZ];
578 long orig_pos = ftell(fp);
580 long file_pos = orig_pos;
581 long buf_size = BUFSZ;
583 while(count < step) {
585 if(file_pos > BUFSZ) {
586 fseek(fp, file_pos-BUFSZ, SEEK_SET);
590 fseek(fp, 0, SEEK_SET);
592 file_pos = ftell(fp);
593 buf_pos = fread(buf, 1, buf_size, fp);
595 cur_found = memrchr(buf, val, (size_t) buf_pos);
596 if(cur_found != NULL) {
597 buf_pos = cur_found-buf;
606 fseek(fp, orig_pos, SEEK_SET);
608 ret = file_pos + buf_pos;
613 static void new_bar(char *buf, int w, int h, int usage)
615 struct special_t *s = new_special(buf, BAR);
616 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
621 static const char *scan_bar(const char *args, int *w, int *h)
623 *w = 0; /* zero width means all space that is available */
625 /* bar's argument is either height or height,width */
628 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
629 sscanf(args, "%d %n", h, &n);
636 static char *scan_font(const char *args)
645 static void new_font(char *buf, char * args) {
647 struct special_t *s = new_special(buf, FONT);
648 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
649 int tmp = selected_font;
650 selected_font = s->font_added = addfont(args);
655 struct special_t *s = new_special(buf, FONT);
656 int tmp = selected_font;
657 selected_font = s->font_added = 0;
663 inline void graph_append(struct special_t *graph, double f)
665 if (!graph->scaled && f > graph->graph_scale) {
666 f = graph->graph_scale;
670 graph->graph_scale = 1;
672 graph->graph[0] = f; /* add new data */
673 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
674 graph->graph[i] = graph->graph[i - 1];
675 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
676 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
681 short colour_depth = 0;
682 void set_up_gradient();
684 /* precalculated: 31/255, and 63/255 */
685 #define CONST_8_TO_5_BITS 0.12156862745098
686 #define CONST_8_TO_6_BITS 0.247058823529412
688 /* adjust color values depending on color depth*/
689 static unsigned int adjust_colors(unsigned int color)
692 if (colour_depth == 0) {
695 if (colour_depth == 16) {
696 r = (color & 0xff0000) >> 16;
697 g = (color & 0xff00) >> 8;
699 color = (int)(r * CONST_8_TO_5_BITS) << 11;
700 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
701 color |= (int)(b * CONST_8_TO_5_BITS);
706 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
708 struct special_t *s = new_special(buf, GRAPH);
710 if (s->graph == NULL) {
711 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
712 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
714 s->graph_width = MAX_GRAPH_DEPTH - 2;
716 s->graph = malloc(s->graph_width * sizeof(double));
717 memset(s->graph, 0, s->graph_width * sizeof(double));
718 s->graph_scale = 100;
721 s->first_colour = adjust_colors(first_colour);
722 s->last_colour = adjust_colors(second_colour);
729 s->graph_width = s->width - 2; // subtract 2 for rectangle around
734 s->graph_scale = scale;
741 static char *scan_graph(const char *args, int *w, int *h,
742 unsigned int *first_colour, unsigned int *last_colour,
747 /* zero width means all space that is available */
753 /* graph's argument is either height or height,width */
755 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour,
760 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) {
763 if (sscanf(args, "%63s %d,%d %x %x %i", buf, h, w, first_colour,
764 last_colour, scale) == 6) {
768 if (sscanf(args, "%63s %d,%d %x %x", buf, h, w, first_colour,
775 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) == 3) {
779 if (sscanf(args, "%x %x", first_colour, last_colour) == 2) {
782 if (sscanf(args, "%63s %x %x %i", buf, first_colour, last_colour,
787 if (sscanf(args, "%63s %x %x", buf, first_colour, last_colour) == 3) {
793 if (sscanf(args, "%d,%d %i", h, w, scale) == 3) {
797 if (sscanf(args, "%d,%d", h, w) == 2) {
800 if (sscanf(args, "%63s %d,%d %i", buf, h, w, scale) < 4) {
802 //TODO: check the return value and throw an error?
803 sscanf(args, "%63s %d,%d", buf, h, w);
809 if (buf[0] == '\0') {
817 static inline void new_hr(char *buf, int a)
819 new_special(buf, HORIZONTAL_LINE)->height = a;
822 static inline void new_stippled_hr(char *buf, int a, int b)
824 struct special_t *s = new_special(buf, STIPPLED_HR);
829 static inline void new_fg(char *buf, long c)
831 new_special(buf, FG)->arg = c;
834 static inline void new_bg(char *buf, long c)
836 new_special(buf, BG)->arg = c;
839 static inline void new_outline(char *buf, long c)
841 new_special(buf, OUTLINE)->arg = c;
844 static inline void new_offset(char *buf, long c)
846 new_special(buf, OFFSET)->arg = c;
849 static inline void new_voffset(char *buf, long c)
851 new_special(buf, VOFFSET)->arg = c;
854 static inline void new_alignr(char *buf, long c)
856 new_special(buf, ALIGNR)->arg = c;
859 static inline void new_alignc(char *buf, long c)
861 new_special(buf, ALIGNC)->arg = c;
864 static inline void new_goto(char *buf, long c)
866 new_special(buf, GOTO)->arg = c;
869 static inline void new_tab(char *buf, int a, int b) {
870 struct special_t *s = new_special(buf, TAB);
875 /* quite boring functions */
877 static inline void for_each_line(char *b, void (*f) (char *))
881 for (ps = b, pe = b; *pe; pe++) {
894 static void convert_escapes(char *buf)
896 char *p = buf, *s = buf;
912 /* Prints anything normally printed with snprintf according to the current value
913 * of use_spacer. Actually slightly more flexible than snprintf, as you can
914 * safely specify the destination buffer as one of your inputs. */
915 static int spaced_print(char *buf, int size, char *format, int width,
916 char *func_name, ...) {
919 char *tempbuf = malloc(size * sizeof(char));
921 // Passes the varargs along to vsnprintf
922 va_start(argp, func_name);
923 vsnprintf(tempbuf, size, format, argp);
926 switch (use_spacer) {
928 len = snprintf(buf, size, "%s", tempbuf);
931 len = snprintf(buf, width, "%*s", width - 1, tempbuf);
934 len = snprintf(buf, width, "%-*s", width - 1, tempbuf);
937 CRIT_ERR("%s encountered invalid use_spacer value (%d)", func_name,
946 /* converts from bytes to human readable format (k, M, G, T) */
947 static void human_readable(long long num, char *buf, int size, char *func_name)
949 char ** suffix = suffixes;
952 static const int WIDTH = 10, SHORT_WIDTH = 8;
956 spaced_print(buf, size, "%lld%c", SHORT_WIDTH, func_name, num,
959 spaced_print(buf, size, "%lld%s", WIDTH, func_name, num, *suffix);
964 while (num / 1024 >= 1000LL && **(suffix + 2)) {
979 len = spaced_print(buf, size, "%.*f%c", SHORT_WIDTH, func_name,
980 precision, fnum, **suffix);
982 len = spaced_print(buf, size, "%.*f%s", WIDTH, func_name, precision,
985 } while (len >= (short_units ? SHORT_WIDTH : WIDTH) || len >= size);
990 enum text_object_type {
1001 OBJ_battery_percent,
1003 #endif /* !__OpenBSD__ */
1025 OBJ_diskiograph_read,
1026 OBJ_diskiograph_write,
1061 #if defined(__linux__)
1067 OBJ_i8k_left_fan_status,
1068 OBJ_i8k_right_fan_status,
1069 OBJ_i8k_left_fan_rpm,
1070 OBJ_i8k_right_fan_rpm,
1072 OBJ_i8k_buttons_status,
1082 OBJ_wireless_bitrate,
1084 OBJ_wireless_link_qual,
1085 OBJ_wireless_link_qual_max,
1086 OBJ_wireless_link_qual_perc,
1087 OBJ_wireless_link_bar,
1088 #endif /* __linux__ */
1117 OBJ_running_processes,
1126 OBJ_temp1, /* i2c is used instead in these */
1146 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1148 OBJ_apm_battery_time,
1149 OBJ_apm_battery_life,
1150 #endif /* __FreeBSD__ __OpenBSD__ */
1152 OBJ_obsd_sensors_temp,
1153 OBJ_obsd_sensors_fan,
1154 OBJ_obsd_sensors_volt,
1157 #endif /* __OpenBSD__ */
1179 OBJ_music_player_interval,
1187 OBJ_xmms2_transport,
1202 OBJ_audacious_status,
1203 OBJ_audacious_title,
1204 OBJ_audacious_length,
1205 OBJ_audacious_length_seconds,
1206 OBJ_audacious_position,
1207 OBJ_audacious_position_seconds,
1208 OBJ_audacious_bitrate,
1209 OBJ_audacious_frequency,
1210 OBJ_audacious_channels,
1211 OBJ_audacious_filename,
1212 OBJ_audacious_playlist_length,
1213 OBJ_audacious_playlist_position,
1227 #ifdef TCP_PORT_MONITOR
1238 OBJ_entropy_poolsize,
1242 struct text_object {
1244 char *s; /* some string */
1245 int i; /* some integer */
1246 long l; /* some other integer */
1247 unsigned int sensor;
1248 struct net_stat *net;
1250 struct diskio_stat *diskio;
1251 unsigned char loadavg[3];
1252 unsigned int cpu_index;
1253 struct mail_s *mail;
1261 char *tz; /* timezone variable */
1262 char *fmt; /* time display formatting */
1300 /* If not -1, a file descriptor to read from when
1301 * logfile is a FIFO. */
1318 timed_thread *p_timed_thread;
1324 #ifdef TCP_PORT_MONITOR
1326 in_port_t port_range_begin; /* starting port to monitor */
1327 in_port_t port_range_end; /* ending port to monitor */
1328 int item; /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1329 int connection_index; /* 0 to n-1 connections. */
1347 struct local_mail_s local_mail;
1352 unsigned int c, d, e;
1357 struct text_object_list {
1358 unsigned int text_object_count;
1359 struct text_object *text_objects;
1362 static unsigned int text_object_count;
1363 static struct text_object *text_objects;
1364 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1366 #define MAXDATASIZE 1000
1370 struct mail_s* parse_mail_args(char type, const char *arg) {
1371 struct mail_s *mail;
1372 mail = malloc(sizeof(struct mail_s));
1373 memset(mail, 0, sizeof(struct mail_s));
1375 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1377 ERR("Scanning IMAP args failed");
1378 } else if (type == IMAP) {
1379 ERR("Scanning POP3 args failed");
1382 // see if password needs prompting
1383 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1384 int fp = fileno(stdin);
1385 struct termios term;
1386 tcgetattr(fp, &term);
1387 term.c_lflag &= ~ECHO;
1388 tcsetattr(fp, TCSANOW, &term);
1389 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1390 scanf("%128s", mail->pass);
1392 term.c_lflag |= ECHO;
1393 tcsetattr(fp, TCSANOW, &term);
1395 // now we check for optional args
1396 tmp = strstr(arg, "-i ");
1399 sscanf(tmp, "%f", &mail->interval);
1401 mail->interval = 300; // 5 minutes
1403 tmp = strstr(arg, "-p ");
1406 sscanf(tmp, "%lu", &mail->port);
1409 mail->port = 110; // default pop3 port
1410 } else if (type == IMAP) {
1411 mail->port = 143; // default imap port
1415 tmp = strstr(arg, "-f ");
1418 sscanf(tmp, "%s", mail->folder);
1420 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1423 tmp = strstr(arg, "-e ");
1427 if (tmp[0] == '\'') {
1428 len = strstr(tmp+1, "'") - tmp - 1;
1433 strncpy(mail->command, tmp+1, len);
1435 mail->command[0] = '\0';
1437 mail->p_timed_thread = NULL;
1441 void *imap_thread(struct mail_s* mail)
1443 int sockfd, numbytes;
1444 char recvbuf[MAXDATASIZE];
1445 char sendbuf[MAXDATASIZE];
1448 unsigned int old_unseen = UINT_MAX;
1449 unsigned int old_messages = UINT_MAX;
1450 struct stat stat_buf;
1452 struct sockaddr_in their_addr; // connector's address information
1453 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1454 herror("gethostbyname");
1459 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1461 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1464 goto next_iteration;
1467 their_addr.sin_family = AF_INET; // host byte order
1468 their_addr.sin_port = htons(mail->port); // short, network byte order
1469 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1470 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1473 (sockfd, (struct sockaddr *) &their_addr,
1474 sizeof(struct sockaddr)) == -1) {
1477 goto next_iteration;
1479 struct timeval timeout;
1482 timeout.tv_sec = 60; // 60 second timeout i guess
1483 timeout.tv_usec = 0;
1485 FD_SET(sockfd, &fdset);
1486 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1489 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1493 goto next_iteration;
1496 ERR("IMAP connection failed: timeout");
1498 goto next_iteration;
1500 recvbuf[numbytes] = '\0';
1501 if (strstr(recvbuf, "* OK") != recvbuf) {
1502 ERR("IMAP connection failed, probably not an IMAP server");
1504 goto next_iteration;
1506 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1507 strncat(sendbuf, mail->user,
1508 MAXDATASIZE - strlen(sendbuf) - 1);
1509 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1510 strncat(sendbuf, mail->pass,
1511 MAXDATASIZE - strlen(sendbuf) - 1);
1512 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1513 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1516 goto next_iteration;
1518 timeout.tv_sec = 60; // 60 second timeout i guess
1519 timeout.tv_usec = 0;
1521 FD_SET(sockfd, &fdset);
1522 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1525 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1529 goto next_iteration;
1532 recvbuf[numbytes] = '\0';
1533 if (strstr(recvbuf, "a1 OK") == NULL) {
1534 ERR("IMAP server login failed: %s", recvbuf);
1536 goto next_iteration;
1538 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1539 strncat(sendbuf, mail->folder,
1540 MAXDATASIZE - strlen(sendbuf) - 1);
1541 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1542 MAXDATASIZE - strlen(sendbuf) - 1);
1543 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1546 goto next_iteration;
1548 timeout.tv_sec = 60; // 60 second timeout i guess
1549 timeout.tv_usec = 0;
1551 FD_SET(sockfd, &fdset);
1552 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1555 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1559 goto next_iteration;
1562 recvbuf[numbytes] = '\0';
1563 if (strstr(recvbuf, "a2 OK") == NULL) {
1564 ERR("IMAP status failed: %s", recvbuf);
1566 goto next_iteration;
1568 // now we get the data
1569 reply = strstr(recvbuf, " (MESSAGES ");
1571 *strchr(reply, ')') = '\0';
1572 if (reply == NULL) {
1573 ERR("Error parsing IMAP response: %s", recvbuf);
1575 goto next_iteration;
1577 timed_thread_lock (mail->p_timed_thread);
1578 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1581 timed_thread_unlock (mail->p_timed_thread);
1583 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1584 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1587 goto next_iteration;
1589 timeout.tv_sec = 60; // 60 second timeout i guess
1590 timeout.tv_usec = 0;
1592 FD_SET(sockfd, &fdset);
1593 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1596 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1600 goto next_iteration;
1603 recvbuf[numbytes] = '\0';
1604 if (strstr(recvbuf, "a3 OK") == NULL) {
1605 ERR("IMAP logout failed: %s", recvbuf);
1607 goto next_iteration;
1609 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1610 if (system(mail->command) == -1) {
1615 old_unseen = mail->unseen;
1616 old_messages = mail->messages;
1618 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1619 /* if a valid socket, close it */
1621 if (timed_thread_test (mail->p_timed_thread))
1622 timed_thread_exit (mail->p_timed_thread);
1629 void *pop3_thread(struct mail_s *mail)
1631 int sockfd, numbytes;
1632 char recvbuf[MAXDATASIZE];
1633 char sendbuf[MAXDATASIZE];
1636 unsigned int old_unseen = UINT_MAX;
1637 struct stat stat_buf;
1639 struct sockaddr_in their_addr; // connector's address information
1640 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1641 herror("gethostbyname");
1646 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1648 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1651 goto next_iteration;
1654 their_addr.sin_family = AF_INET; // host byte order
1655 their_addr.sin_port = htons(mail->port); // short, network byte order
1656 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1657 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1660 (sockfd, (struct sockaddr *) &their_addr,
1661 sizeof(struct sockaddr)) == -1) {
1664 goto next_iteration;
1666 struct timeval timeout;
1669 timeout.tv_sec = 60; // 60 second timeout i guess
1670 timeout.tv_usec = 0;
1672 FD_SET(sockfd, &fdset);
1673 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1676 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1680 goto next_iteration;
1683 ERR("POP3 connection failed: timeout\n");
1685 goto next_iteration;
1687 recvbuf[numbytes] = '\0';
1688 if (strstr(recvbuf, "+OK ") != recvbuf) {
1689 ERR("POP3 connection failed, probably not a POP3 server");
1691 goto next_iteration;
1693 strncpy(sendbuf, "USER ", MAXDATASIZE);
1694 strncat(sendbuf, mail->user,
1695 MAXDATASIZE - strlen(sendbuf) - 1);
1696 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1697 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1698 perror("send USER");
1700 goto next_iteration;
1702 timeout.tv_sec = 60; // 60 second timeout i guess
1703 timeout.tv_usec = 0;
1705 FD_SET(sockfd, &fdset);
1706 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1709 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1711 perror("recv USER");
1713 goto next_iteration;
1716 recvbuf[numbytes] = '\0';
1717 if (strstr(recvbuf, "+OK ") == NULL) {
1718 ERR("POP3 server login failed: %s", recvbuf);
1720 goto next_iteration;
1722 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1723 strncat(sendbuf, mail->pass,
1724 MAXDATASIZE - strlen(sendbuf) - 1);
1725 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1726 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1727 perror("send PASS");
1729 goto next_iteration;
1731 timeout.tv_sec = 60; // 60 second timeout i guess
1732 timeout.tv_usec = 0;
1734 FD_SET(sockfd, &fdset);
1735 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1738 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1740 perror("recv PASS");
1742 goto next_iteration;
1745 recvbuf[numbytes] = '\0';
1746 if (strstr(recvbuf, "+OK ") == NULL) {
1747 ERR("POP3 server login failed: %s", recvbuf);
1749 goto next_iteration;
1751 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1752 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1753 perror("send STAT");
1755 goto next_iteration;
1757 timeout.tv_sec = 60; // 60 second timeout i guess
1758 timeout.tv_usec = 0;
1760 FD_SET(sockfd, &fdset);
1761 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1764 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1766 perror("recv STAT");
1768 goto next_iteration;
1771 recvbuf[numbytes] = '\0';
1772 if (strstr(recvbuf, "+OK ") == NULL) {
1773 ERR("POP3 status failed: %s", recvbuf);
1775 goto next_iteration;
1777 // now we get the data
1778 reply = recvbuf + 4;
1779 if (reply == NULL) {
1780 ERR("Error parsing POP3 response: %s", recvbuf);
1782 goto next_iteration;
1784 timed_thread_lock (mail->p_timed_thread);
1785 sscanf(reply, "%lu %lu", &mail->unseen,
1787 timed_thread_unlock (mail->p_timed_thread);
1789 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1790 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1791 perror("send QUIT");
1793 goto next_iteration;
1795 timeout.tv_sec = 60; // 60 second timeout i guess
1796 timeout.tv_usec = 0;
1798 FD_SET(sockfd, &fdset);
1799 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1802 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1804 perror("recv QUIT");
1806 goto next_iteration;
1809 recvbuf[numbytes] = '\0';
1810 if (strstr(recvbuf, "+OK") == NULL) {
1811 ERR("POP3 logout failed: %s", recvbuf);
1813 goto next_iteration;
1815 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1816 if (system(mail->command) == -1) {
1821 old_unseen = mail->unseen;
1823 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1824 /* if a valid socket, close it */
1826 if (timed_thread_test (mail->p_timed_thread))
1827 timed_thread_exit (mail->p_timed_thread);
1835 void *threaded_exec(struct text_object *obj) {
1837 char *p2 = obj->data.texeci.buffer;
1838 FILE *fp = popen(obj->data.texeci.cmd,"r");
1839 timed_thread_lock (obj->data.texeci.p_timed_thread);
1840 int n2 = fread(p2, 1, text_buffer_size, fp);
1843 if (n2 && p2[n2 - 1] == '\n') {
1847 if (*p2 == '\001') {
1852 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1853 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1854 timed_thread_exit (obj->data.texeci.p_timed_thread);
1859 static struct text_object *new_text_object_internal()
1861 struct text_object *obj = malloc(sizeof(struct text_object));
1862 memset(obj, 0, sizeof(struct text_object));
1866 static void free_text_objects(unsigned int count, struct text_object *objs)
1869 for (i = 0; i < count; i++) {
1870 switch (objs[i].type) {
1873 close(objs[i].data.i);
1876 close(objs[i].data.i);
1879 close(objs[i].data.sysfs.fd);
1882 close(objs[i].data.sysfs.fd);
1885 close(objs[i].data.sysfs.fd);
1887 #endif /* !__OpenBSD__ */
1889 free(objs[i].data.s);
1892 free(objs[i].data.s);
1895 free(objs[i].data.tztime.tz);
1896 free(objs[i].data.tztime.fmt);
1899 free(objs[i].data.mboxscan.args);
1900 free(objs[i].data.mboxscan.output);
1904 free(objs[i].data.local_mail.box);
1909 case OBJ_imap_unseen:
1910 if (!objs[i].global_mode) {
1911 free(objs[i].data.mail);
1914 case OBJ_imap_messages:
1915 if (!objs[i].global_mode) {
1916 free(objs[i].data.mail);
1922 case OBJ_pop3_unseen:
1923 if (!objs[i].global_mode) {
1924 free(objs[i].data.mail);
1928 if (!objs[i].global_mode) {
1929 free(objs[i].data.mail);
1933 case OBJ_if_existing:
1934 case OBJ_if_mounted:
1935 case OBJ_if_running:
1936 free(objs[i].data.ifblock.s);
1937 free(objs[i].data.ifblock.str);
1940 free(objs[i].data.tail.logfile);
1941 free(objs[i].data.tail.buffer);
1945 free(objs[i].data.s);
1948 free(objs[i].data.s);
1951 free(objs[i].data.s);
1954 free(objs[i].data.s);
1957 free(objs[i].data.s);
1959 /* case OBJ_execibar:
1960 free(objs[i].data.s);
1962 case OBJ_execigraph:
1963 free(objs[i].data.s);
1966 case OBJ_iconv_start:
1971 case OBJ_xmms2_artist:
1972 if (info.xmms2.artist) {
1973 free(info.xmms2.artist);
1974 info.xmms2.artist = 0;
1977 case OBJ_xmms2_album:
1978 if (info.xmms2.album) {
1979 free(info.xmms2.album);
1980 info.xmms2.album = 0;
1983 case OBJ_xmms2_title:
1984 if (info.xmms2.title) {
1985 free(info.xmms2.title);
1986 info.xmms2.title = 0;
1989 case OBJ_xmms2_genre:
1990 if (info.xmms2.genre) {
1991 free(info.xmms2.genre);
1992 info.xmms2.genre = 0;
1995 case OBJ_xmms2_comment:
1996 if (info.xmms2.comment) {
1997 free(info.xmms2.comment);
1998 info.xmms2.comment = 0;
2001 case OBJ_xmms2_decoder:
2002 if (info.xmms2.decoder) {
2003 free(info.xmms2.decoder);
2007 case OBJ_xmms2_transport:
2008 if (info.xmms2.transport) {
2009 free(info.xmms2.transport);
2014 if (info.xmms2.url) {
2015 free(info.xmms2.url);
2019 case OBJ_xmms2_date:
2020 if (info.xmms2.date) {
2021 free(info.xmms2.date);
2022 info.xmms2.date = 0;
2025 case OBJ_xmms2_status:
2026 if (info.xmms2.status) {
2027 free(info.xmms2.status);
2028 info.xmms2.status = 0;
2031 case OBJ_xmms2_smart:
2032 if (info.xmms2.artist) {
2033 free(info.xmms2.artist);
2034 info.xmms2.artist = 0;
2036 if (info.xmms2.title) {
2037 free(info.xmms2.title);
2038 info.xmms2.title = 0;
2040 if (info.xmms2.url) {
2041 free(info.xmms2.url);
2047 case OBJ_bmpx_title:
2048 case OBJ_bmpx_artist:
2049 case OBJ_bmpx_album:
2050 case OBJ_bmpx_track:
2052 case OBJ_bmpx_bitrate:
2057 free(objs[i].data.rss.uri);
2058 free(objs[i].data.rss.action);
2065 free(objs[i].data.s);
2067 case OBJ_battery_time:
2068 free(objs[i].data.s);
2070 #endif /* !__OpenBSD__ */
2072 free(objs[i].data.execi.cmd);
2073 free(objs[i].data.execi.buffer);
2076 free(objs[i].data.texeci.cmd);
2077 free(objs[i].data.texeci.buffer);
2080 if (info.first_process) {
2081 free_all_processes();
2082 info.first_process = NULL;
2086 if (info.first_process) {
2087 free_all_processes();
2088 info.first_process = NULL;
2093 free(objs[i].data.hddtemp.dev);
2094 free(objs[i].data.hddtemp.addr);
2097 case OBJ_entropy_avail:
2098 case OBJ_entropy_poolsize:
2099 case OBJ_entropy_bar:
2106 if (info.mpd.title) {
2107 free(info.mpd.title);
2110 if (info.mpd.artist) {
2111 free(info.mpd.artist);
2112 info.mpd.artist = 0;
2114 if (info.mpd.album) {
2115 free(info.mpd.album);
2118 if (info.mpd.random) {
2119 free(info.mpd.random);
2120 info.mpd.random = 0;
2122 if (info.mpd.repeat) {
2123 free(info.mpd.repeat);
2124 info.mpd.repeat = 0;
2126 if (info.mpd.track) {
2127 free(info.mpd.track);
2130 if (info.mpd.name) {
2131 free(info.mpd.name);
2134 if (info.mpd.file) {
2135 free(info.mpd.file);
2138 if (info.mpd.status) {
2139 free(info.mpd.status);
2140 info.mpd.status = 0;
2144 //text_objects = NULL;
2145 //text_object_count = 0;
2148 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2153 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2154 *a = mixer_init(buf1);
2155 (void) scan_bar(arg + n, w, h);
2158 (void) scan_bar(arg, w, h);
2163 /* construct_text_object() creates a new text_object */
2164 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2166 //struct text_object *obj = new_text_object();
2167 struct text_object *obj = new_text_object_internal();
2170 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2171 #define END ; } } else
2175 obj->type = OBJ_color;
2176 obj->data.l = get_x11_color(s);
2180 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2181 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2182 END OBJ(acpiacadapter, 0)
2183 #endif /* !__OpenBSD__ */
2185 OBJ(freq, INFO_FREQ)
2187 END OBJ(freq, INFO_FREQ)
2194 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2196 obj->data.cpu_index=1;
2197 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2201 obj->data.cpu_index=atoi(&arg[0]);
2204 END OBJ(freq_g, INFO_FREQ)
2210 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2212 obj->data.cpu_index=1;
2213 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2217 obj->data.cpu_index=atoi(&arg[0]);
2220 #if defined(__linux__)
2221 END OBJ(voltage_mv, 0)
2227 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2229 obj->data.cpu_index=1;
2230 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2234 obj->data.cpu_index=atoi(&arg[0]);
2237 END OBJ(voltage_v, 0)
2243 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2245 obj->data.cpu_index=1;
2246 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2250 obj->data.cpu_index=atoi(&arg[0]);
2255 END OBJ(wireless_essid, INFO_NET)
2257 obj->data.net = get_net_stat(arg);
2259 CRIT_ERR("wireless_essid: needs an argument");
2260 END OBJ(wireless_mode, INFO_NET)
2262 obj->data.net = get_net_stat(arg);
2264 CRIT_ERR("wireless_mode: needs an argument");
2265 END OBJ(wireless_bitrate, INFO_NET)
2267 obj->data.net = get_net_stat(arg);
2269 CRIT_ERR("wireless_bitrate: needs an argument");
2270 END OBJ(wireless_ap, INFO_NET)
2272 obj->data.net = get_net_stat(arg);
2274 CRIT_ERR("wireless_ap: needs an argument");
2275 END OBJ(wireless_link_qual, INFO_NET)
2277 obj->data.net = get_net_stat(arg);
2279 CRIT_ERR("wireless_link_qual: needs an argument");
2280 END OBJ(wireless_link_qual_max, INFO_NET)
2282 obj->data.net = get_net_stat(arg);
2284 CRIT_ERR("wireless_link_qual_max: needs an argument");
2285 END OBJ(wireless_link_qual_perc, INFO_NET)
2287 obj->data.net = get_net_stat(arg);
2289 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2290 END OBJ(wireless_link_bar, INFO_NET)
2292 arg = scan_bar(arg, &obj->a, &obj->b);
2293 obj->data.net = get_net_stat(arg);
2295 CRIT_ERR("wireless_link_bar: needs an argument");
2296 #endif /* HAVE_IWLIB */
2298 #endif /* __linux__ */
2299 END OBJ(freq_dyn, 0)
2300 END OBJ(freq_dyn_g, 0)
2306 sscanf(arg, "%63s", bat);
2308 strcpy(bat, "BAT0");
2309 obj->data.s = strdup(bat);
2310 END OBJ(battery_time, 0)
2313 sscanf(arg, "%63s", bat);
2315 strcpy(bat, "BAT0");
2316 obj->data.s = strdup(bat);
2317 END OBJ(battery_percent, 0)
2320 sscanf(arg, "%63s", bat);
2322 strcpy(bat, "BAT0");
2323 obj->data.s = strdup(bat);
2324 END OBJ(battery_bar, 0)
2327 arg = scan_bar(arg, &obj->a, &obj->b);
2328 sscanf(arg, "%63s", bat);
2330 strcpy(bat, "BAT0");
2332 obj->data.s = strdup(bat);
2333 #endif /* !__OpenBSD__ */
2334 #if defined(__linux__)
2335 END OBJ(i8k_version, INFO_I8K)
2336 END OBJ(i8k_bios, INFO_I8K)
2337 END OBJ(i8k_serial, INFO_I8K)
2338 END OBJ(i8k_cpu_temp, INFO_I8K)
2339 END OBJ(i8k_cpu_tempf, INFO_I8K)
2340 END OBJ(i8k_left_fan_status, INFO_I8K)
2341 END OBJ(i8k_right_fan_status, INFO_I8K)
2342 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2343 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2344 END OBJ(i8k_ac_status, INFO_I8K)
2345 END OBJ(i8k_buttons_status, INFO_I8K)
2347 END OBJ(ibm_temps, 0)
2349 CRIT_ERR("ibm_temps: needs an argument");
2351 if (!isdigit(arg[0])
2353 || atoi(&arg[0]) >=8)
2356 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2358 obj->data.sensor = atoi(&arg[0]);
2359 END OBJ(ibm_volume, 0)
2360 END OBJ(ibm_brightness, 0)
2361 END OBJ(pb_battery, 0)
2362 if (arg && strcmp(arg, "status") == 0) {
2363 obj->data.i = PB_BATT_STATUS;
2364 } else if (arg && strcmp(arg, "percent") == 0) {
2365 obj->data.i = PB_BATT_PERCENT;
2366 } else if (arg && strcmp(arg, "time") == 0) {
2367 obj->data.i = PB_BATT_TIME;
2369 ERR("pb_battery: needs one argument: status, percent or time");
2374 #endif /* __linux__ */
2375 #if defined(__OpenBSD__)
2376 END OBJ(obsd_sensors_temp, 0)
2378 CRIT_ERR("obsd_sensors_temp: needs an argument");
2380 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2382 ERR("Invalid temperature sensor number!");
2384 obj->data.sensor = atoi(&arg[0]);
2385 END OBJ(obsd_sensors_fan, 0)
2387 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor number)");
2389 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2391 ERR("Invalid fan sensor number!");
2393 obj->data.sensor = atoi(&arg[0]);
2394 END OBJ(obsd_sensors_volt, 0)
2396 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor number)");
2398 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2400 ERR("Invalid voltage sensor number!");
2402 obj->data.sensor = atoi(&arg[0]);
2403 END OBJ(obsd_vendor, 0)
2404 END OBJ(obsd_product, 0)
2405 #endif /* __OpenBSD__ */
2406 END OBJ(buffers, INFO_BUFFERS)
2407 END OBJ(cached, INFO_BUFFERS)
2408 END OBJ(cpu, INFO_CPU)
2410 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2411 obj->data.cpu_index = atoi(&arg[3]);
2413 } else {obj->data.cpu_index = 0; }
2415 obj->data.cpu_index = 0;
2417 END OBJ(cpubar, INFO_CPU)
2419 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2420 obj->data.cpu_index = atoi(&arg[3]);
2423 else {obj->data.cpu_index = 0;}
2424 (void) scan_bar(arg, &obj->a, &obj->b);
2426 (void) scan_bar(arg, &obj->a, &obj->b);
2427 obj->data.cpu_index = 0;
2429 END OBJ(cpugraph, INFO_CPU)
2430 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2434 if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
2435 obj->data.cpu_index = atoi(&buf[3]);
2437 obj->data.cpu_index = 0;
2441 END OBJ(diskio, INFO_DISKIO)
2443 obj->data.diskio = prepare_diskio_stat(arg);
2445 obj->data.diskio = NULL;
2447 END OBJ(diskio_read, INFO_DISKIO)
2449 obj->data.diskio = prepare_diskio_stat(arg);
2451 obj->data.diskio = NULL;
2453 END OBJ(diskio_write, INFO_DISKIO)
2455 obj->data.diskio = prepare_diskio_stat(arg);
2457 obj->data.diskio = NULL;
2459 END OBJ(diskiograph, INFO_DISKIO)
2460 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2464 obj->data.diskio = prepare_diskio_stat(buf);
2467 obj->data.diskio = NULL;
2469 END OBJ(diskiograph_read, INFO_DISKIO)
2470 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2474 obj->data.diskio = prepare_diskio_stat(buf);
2477 obj->data.diskio = NULL;
2479 END OBJ(diskiograph_write, INFO_DISKIO)
2480 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2484 obj->data.diskio = prepare_diskio_stat(buf);
2487 obj->data.diskio = NULL;
2491 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2494 obj->data.l = color0;
2496 obj->data.l = color1;
2498 obj->data.l = color2;
2500 obj->data.l = color3;
2502 obj->data.l = color4;
2504 obj->data.l = color5;
2506 obj->data.l = color6;
2508 obj->data.l = color7;
2510 obj->data.l = color8;
2512 obj->data.l = color9;
2514 obj->data.s = scan_font(arg);
2515 END OBJ(downspeed, INFO_NET)
2517 obj->data.net = get_net_stat(arg);
2520 CRIT_ERR("downspeed needs argument");
2522 END OBJ(downspeedf, INFO_NET)
2524 obj->data.net = get_net_stat(arg);
2527 CRIT_ERR("downspeedf needs argument");
2529 END OBJ(downspeedgraph, INFO_NET)
2530 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2534 obj->data.net = get_net_stat(buf);
2539 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2540 blockstart[blockdepth - 1] = object_count;
2541 obj->data.ifblock.pos = object_count + 2;
2543 ERR("$else: no matching $if_*");
2548 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2550 ERR("$endif: no matching $if_*");
2553 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2556 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2557 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2558 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2559 END OBJ(execibar, 0) unsigned int n;
2560 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2562 ERR("${execibar <interval> command}");
2563 obj->type = OBJ_text;
2564 snprintf(buf, 256, "${%s}", s);
2565 obj->data.s = strdup(buf);
2567 obj->data.execi.cmd = strdup(arg + n);
2569 END OBJ(execigraph, 0) unsigned int n;
2570 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2572 ERR("${execigraph <interval> command}");
2573 obj->type = OBJ_text;
2574 snprintf(buf, 256, "${%s}", s);
2575 obj->data.s = strdup(buf);
2577 obj->data.execi.cmd = strdup(arg + n);
2579 END OBJ(execi, 0) unsigned int n;
2580 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2582 ERR("${execi <interval> command}");
2583 obj->type = OBJ_text;
2584 snprintf(buf, 256, "${%s}", s);
2585 obj->data.s = strdup(buf);
2587 obj->data.execi.cmd = strdup(arg + n);
2588 obj->data.execi.buffer =
2589 (char *) calloc(1, text_buffer_size);
2591 END OBJ(texeci, 0) unsigned int n;
2592 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2594 ERR("${texeci <interval> command}");
2595 obj->type = OBJ_text;
2596 snprintf(buf, 256, "${%s}", s);
2597 obj->data.s = strdup(buf);
2599 obj->data.texeci.cmd = strdup(arg + n);
2600 obj->data.texeci.buffer =
2601 (char *) calloc(1, text_buffer_size);
2603 obj->data.texeci.p_timed_thread = NULL;
2604 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2606 FILE *fp = popen(arg, "r");
2610 n = fread(buf, 1, 2048, fp);
2613 if (n && buf[n - 1] == '\n')
2618 obj->data.s = strdup(buf);
2620 obj->data.s = strdup("");
2623 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2624 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2626 while (isspace(*arg))
2632 obj->data.fsbar.fs = prepare_fs_stat(arg);
2633 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2636 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2640 obj->data.fsbar.fs = prepare_fs_stat(arg);
2641 END OBJ(fs_free, INFO_FS) if (!arg)
2643 obj->data.fs = prepare_fs_stat(arg);
2644 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2646 obj->data.fs = prepare_fs_stat(arg);
2647 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2649 obj->data.fs = prepare_fs_stat(arg);
2650 END OBJ(fs_size, INFO_FS) if (!arg)
2652 obj->data.fs = prepare_fs_stat(arg);
2653 END OBJ(fs_used, INFO_FS) if (!arg)
2655 obj->data.fs = prepare_fs_stat(arg);
2656 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2657 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2658 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2662 ERR("goto needs arguments");
2663 obj->type = OBJ_text;
2664 obj->data.s = strdup("${goto}");
2668 obj->data.i = atoi(arg);
2673 if (sscanf(arg, "%d %d", &a, &b) != 2)
2674 sscanf(arg, "%d", &b);
2678 obj->data.pair.a = a;
2679 obj->data.pair.b = b;
2682 END OBJ(i2c, INFO_SYSFS)
2683 char buf1[64], buf2[64];
2687 ERR("i2c needs arguments");
2688 obj->type = OBJ_text;
2689 //obj->data.s = strdup("${i2c}");
2693 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2694 /* if scanf couldn't read three values, read type and num and use default device */
2695 sscanf(arg, "%63s %d", buf2, &n);
2696 obj->data.sysfs.fd =
2697 open_i2c_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2698 strncpy(obj->data.sysfs.type, buf2, 63);
2700 obj->data.sysfs.fd =
2701 open_i2c_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2702 strncpy(obj->data.sysfs.type, buf2, 63);
2705 END OBJ(platform, INFO_SYSFS)
2706 char buf1[64], buf2[64];
2710 ERR("platform needs arguments");
2711 obj->type = OBJ_text;
2715 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2716 /* if scanf couldn't read three values, read type and num and use default device */
2717 sscanf(arg, "%63s %d", buf2, &n);
2718 obj->data.sysfs.fd =
2719 open_platform_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2720 strncpy(obj->data.sysfs.type, buf2, 63);
2722 obj->data.sysfs.fd =
2723 open_platform_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2724 strncpy(obj->data.sysfs.type, buf2, 63);
2727 END OBJ(hwmon, INFO_SYSFS)
2728 char buf1[64], buf2[64];
2732 ERR("hwmon needs argumanets");
2733 obj->type = OBJ_text;
2737 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2738 /* if scanf couldn't read three values, read type and num and use default device */
2739 sscanf(arg, "%63s %d", buf2, &n);
2740 obj->data.sysfs.fd =
2741 open_hwmon_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2742 strncpy(obj->data.sysfs.type, buf2, 63);
2744 obj->data.sysfs.fd =
2745 open_hwmon_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2746 strncpy(obj->data.sysfs.type, buf2, 63);
2748 #endif /* !__OpenBSD__ */
2750 END OBJ(top, INFO_TOP)
2754 ERR("top needs arguments");
2755 obj->type = OBJ_text;
2756 //obj->data.s = strdup("${top}");
2759 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2760 if (strcmp(buf, "name") == 0) {
2761 obj->data.top.type = TOP_NAME;
2762 } else if (strcmp(buf, "cpu") == 0) {
2763 obj->data.top.type = TOP_CPU;
2764 } else if (strcmp(buf, "pid") == 0) {
2765 obj->data.top.type = TOP_PID;
2766 } else if (strcmp(buf, "mem") == 0) {
2767 obj->data.top.type = TOP_MEM;
2768 } else if (strcmp(buf, "time") == 0) {
2769 obj->data.top.type = TOP_TIME;
2771 ERR("invalid arg for top");
2774 if (n < 1 || n > 10) {
2775 CRIT_ERR("invalid arg for top");
2778 obj->data.top.num = n - 1;
2782 ERR("invalid args given for top");
2785 END OBJ(top_mem, INFO_TOP)
2789 ERR("top_mem needs arguments");
2790 obj->type = OBJ_text;
2791 obj->data.s = strdup("${top_mem}");
2794 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2795 if (strcmp(buf, "name") == 0) {
2796 obj->data.top.type = TOP_NAME;
2797 } else if (strcmp(buf, "cpu") == 0) {
2798 obj->data.top.type = TOP_CPU;
2799 } else if (strcmp(buf, "pid") == 0) {
2800 obj->data.top.type = TOP_PID;
2801 } else if (strcmp(buf, "mem") == 0) {
2802 obj->data.top.type = TOP_MEM;
2803 } else if (strcmp(buf, "time") == 0) {
2804 obj->data.top.type = TOP_TIME;
2806 ERR("invalid arg for top");
2809 if (n < 1 || n > 10) {
2810 CRIT_ERR("invalid arg for top");
2813 obj->data.top.num = n - 1;
2817 ERR("invalid args given for top");
2820 END OBJ(addr, INFO_NET)
2822 obj->data.net = get_net_stat(arg);
2825 CRIT_ERR("addr needs argument");
2832 ERR("tail needs arguments");
2833 obj->type = OBJ_text;
2834 obj->data.s = strdup("${tail}");
2837 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2838 if (n1 < 1 || n1 > 30) {
2839 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2845 obj->data.tail.fd = -1;
2847 if (stat(buf, &st) == 0) {
2848 if (S_ISFIFO(st.st_mode)) {
2849 fd = open(buf, O_RDONLY|O_NONBLOCK);
2852 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2854 obj->data.tail.fd = fd;
2858 fp = fopen(buf, "r");
2861 if (fp || obj->data.tail.fd != -1) {
2862 obj->data.tail.logfile =
2863 malloc(text_buffer_size);
2864 strcpy(obj->data.tail.logfile, buf);
2865 obj->data.tail.wantedlines = n1;
2866 obj->data.tail.interval =
2867 update_interval * 2;
2869 if (obj->data.tail.fd == -1)
2873 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2876 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2877 if (n1 < 1 || n1 > 30) {
2879 ("invalid arg for tail, number of lines must be between 1 and 30");
2881 } else if (n2 < 1 || n2 < update_interval) {
2883 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2889 obj->data.tail.fd = -1;
2891 if (stat(buf, &st) == 0) {
2892 if (S_ISFIFO(st.st_mode)) {
2893 fd = open(buf, O_RDONLY|O_NONBLOCK);
2896 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2898 obj->data.tail.fd = fd;
2901 fp = fopen(buf, "r");
2904 if (fp || obj->data.tail.fd != -1) {
2905 obj->data.tail.logfile =
2906 malloc(text_buffer_size);
2907 strcpy(obj->data.tail.logfile, buf);
2908 obj->data.tail.wantedlines = n1;
2909 obj->data.tail.interval = n2;
2911 if (obj->data.tail.fd == -1)
2915 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2921 ERR("invalid args given for tail");
2924 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2929 ERR("head needs arguments");
2930 obj->type = OBJ_text;
2931 obj->data.s = strdup("${head}");
2934 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2935 if (n1 < 1 || n1 > 30) {
2936 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2940 fp = fopen(buf, "r");
2942 obj->data.tail.logfile =
2943 malloc(text_buffer_size);
2944 strcpy(obj->data.tail.logfile, buf);
2945 obj->data.tail.wantedlines = n1;
2946 obj->data.tail.interval =
2947 update_interval * 2;
2951 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2954 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2955 if (n1 < 1 || n1 > 30) {
2957 ("invalid arg for head, number of lines must be between 1 and 30");
2959 } else if (n2 < 1 || n2 < update_interval) {
2961 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2965 fp = fopen(buf, "r");
2967 obj->data.tail.logfile =
2968 malloc(text_buffer_size);
2969 strcpy(obj->data.tail.logfile, buf);
2970 obj->data.tail.wantedlines = n1;
2971 obj->data.tail.interval = n2;
2975 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2981 ERR("invalid args given for head");
2984 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2985 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2987 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2988 if (r >= 3 && (c < 1 || c > 3))
2990 if (r >= 2 && (b < 1 || b > 3))
2992 if (r >= 1 && (a < 1 || a > 3))
2995 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2996 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2997 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2998 END OBJ(if_empty, 0)
2999 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3000 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3003 ERR("if_empty needs an argument");
3004 obj->data.ifblock.s = 0;
3006 obj->data.ifblock.s = strdup(arg);
3007 blockstart[blockdepth] = object_count;
3008 obj->data.ifblock.pos = object_count + 2;
3010 END OBJ(if_existing, 0)
3011 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3012 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3015 ERR("if_existing needs an argument or two");
3016 obj->data.ifblock.s = NULL;
3017 obj->data.ifblock.str = NULL;
3019 char buf1[256], buf2[256];
3020 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3022 obj->data.ifblock.s = strdup(buf1);
3023 obj->data.ifblock.str = NULL;
3025 obj->data.ifblock.s = strdup(buf1);
3026 obj->data.ifblock.str = strdup(buf2);
3029 blockstart[blockdepth] = object_count;
3030 obj->data.ifblock.pos = object_count + 2;
3032 END OBJ(if_mounted, 0)
3033 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3034 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3037 ERR("if_mounted needs an argument");
3038 obj->data.ifblock.s = 0;
3040 obj->data.ifblock.s = strdup(arg);
3041 blockstart[blockdepth] = object_count;
3042 obj->data.ifblock.pos = object_count + 2;
3044 END OBJ(if_running, 0)
3045 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3046 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3050 snprintf(buf, 256, "pidof %s >/dev/null", arg);
3051 obj->data.ifblock.s = strdup(buf);
3053 ERR("if_running needs an argument");
3054 obj->data.ifblock.s = 0;
3056 blockstart[blockdepth] = object_count;
3057 obj->data.ifblock.pos = object_count + 2;
3063 char box[256], dst[256];
3067 strncpy(box, MAIL_FILE, sizeof(box));
3070 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3072 strncpy(box, arg, sizeof(box));
3076 variable_substitute(box, dst, sizeof(dst));
3077 obj->data.local_mail.box = strdup(dst);
3078 obj->data.local_mail.interval = n1;
3081 END OBJ(mboxscan, 0)
3082 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
3083 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
3084 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
3085 obj->data.mboxscan.output[0] = 1;
3086 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
3087 END OBJ(mem, INFO_MEM)
3088 END OBJ(memmax, INFO_MEM)
3089 END OBJ(memperc, INFO_MEM)
3090 END OBJ(membar, INFO_MEM)
3091 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3092 END OBJ(memgraph, INFO_MEM)
3093 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3099 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
3100 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
3101 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
3102 END OBJ(mixerbar, INFO_MIXER)
3103 scan_mixer_bar(arg, &obj->data.mixerbar.l,
3104 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
3105 END OBJ(mixerlbar, INFO_MIXER)
3106 scan_mixer_bar(arg, &obj->data.mixerbar.l,
3107 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
3108 END OBJ(mixerrbar, INFO_MIXER)
3109 scan_mixer_bar(arg, &obj->data.mixerbar.l,
3110 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
3114 char box[256], dst[256];
3118 strncpy(box, MAIL_FILE, sizeof(box));
3121 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3123 strncpy(box, arg, sizeof(box));
3127 variable_substitute(box, dst, sizeof(dst));
3128 obj->data.local_mail.box = strdup(dst);
3129 obj->data.local_mail.interval = n1;
3132 END OBJ(nodename, 0)
3133 END OBJ(processes, INFO_PROCS)
3134 END OBJ(running_processes, INFO_RUN_PROCS)
3135 END OBJ(shadecolor, 0)
3137 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
3139 END OBJ(outlinecolor, 0)
3141 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
3143 END OBJ(stippled_hr, 0)
3145 int a = stippled_borders, b = 1;
3147 if (sscanf(arg, "%d %d", &a, &b) != 2)
3148 sscanf(arg, "%d", &b);
3152 obj->data.pair.a = a;
3153 obj->data.pair.b = b;
3155 END OBJ(swap, INFO_MEM)
3156 END OBJ(swapmax, INFO_MEM)
3157 END OBJ(swapperc, INFO_MEM)
3158 END OBJ(swapbar, INFO_MEM)
3159 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3162 END OBJ(temp1, INFO_SYSFS) obj->type = OBJ_i2c;
3163 obj->data.sysfs.fd =
3164 open_i2c_sensor(0, "temp", 1, &obj->data.sysfs.arg,
3165 obj->data.sysfs.devtype);
3166 END OBJ(temp2, INFO_SYSFS) obj->type = OBJ_i2c;
3167 obj->data.sysfs.fd =
3168 open_i2c_sensor(0, "temp", 2, &obj->data.sysfs.arg,
3169 obj->data.sysfs.devtype);
3171 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
3172 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
3174 char buf1[256], buf2[256], *fmt, *tz;
3177 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3186 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
3187 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
3189 END OBJ(iconv_start, 0)
3190 if (iconv_converting) {
3191 CRIT_ERR("You must stop your last iconv conversion before starting another");
3194 char iconv_from[CODEPAGE_LENGTH];
3195 char iconv_to[CODEPAGE_LENGTH];
3196 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3197 CRIT_ERR("Invalid arguments for iconv_start");
3200 new_iconv = iconv_open(iconv_to, iconv_from);
3201 if (new_iconv == (iconv_t)(-1)) {
3202 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3204 obj->a = register_iconv(&new_iconv);
3205 iconv_converting = 1;
3209 CRIT_ERR("Iconv requires arguments");
3211 END OBJ(iconv_stop, 0)
3212 iconv_converting = 0;
3215 END OBJ(totaldown, INFO_NET)
3217 obj->data.net = get_net_stat(arg);
3220 CRIT_ERR("totaldown needs argument");
3222 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
3224 obj->data.net = get_net_stat(arg);
3227 CRIT_ERR("totalup needs argument");
3230 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
3231 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
3232 END OBJ(upspeed, INFO_NET)
3234 obj->data.net = get_net_stat(arg);
3237 CRIT_ERR("upspeed needs argument");
3239 END OBJ(upspeedf, INFO_NET)
3241 obj->data.net = get_net_stat(arg);
3244 CRIT_ERR("upspeedf needs argument");
3247 END OBJ(upspeedgraph, INFO_NET)
3248 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3252 obj->data.net = get_net_stat(buf);
3255 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
3257 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
3258 #endif /* !__OpenBSD__ */
3259 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3260 OBJ(apm_adapter, 0) END
3261 OBJ(apm_battery_life, 0) END
3262 OBJ(apm_battery_time, 0) END
3263 #endif /* __FreeBSD__ */
3267 obj->data.mail = parse_mail_args(IMAP, arg);
3268 obj->global_mode = 0;
3270 obj->global_mode = 1;
3273 OBJ(imap_messages, 0)
3276 obj->data.mail = parse_mail_args(IMAP, arg);
3277 obj->global_mode = 0;
3279 obj->global_mode = 1;
3285 obj->data.mail = parse_mail_args(POP3, arg);
3286 obj->global_mode = 0;
3288 obj->global_mode = 1;
3294 obj->data.mail = parse_mail_args(POP3, arg);
3295 obj->global_mode = 0;
3297 obj->global_mode = 1;
3301 OBJ(mpd_artist, INFO_MPD) END
3302 OBJ(mpd_title, INFO_MPD)
3305 sscanf (arg, "%d", &info.mpd.max_title_len);
3306 if (info.mpd.max_title_len > 0) {
3307 info.mpd.max_title_len++;
3309 CRIT_ERR ("mpd_title: invalid length argument");
3312 info.mpd.max_title_len = 0;
3315 END OBJ(mpd_random, INFO_MPD)
3316 END OBJ(mpd_repeat, INFO_MPD)
3317 END OBJ(mpd_elapsed, INFO_MPD)
3318 END OBJ(mpd_length, INFO_MPD)
3319 END OBJ(mpd_track, INFO_MPD)
3320 END OBJ(mpd_name, INFO_MPD)
3321 END OBJ(mpd_file, INFO_MPD)
3322 END OBJ(mpd_percent, INFO_MPD)
3323 END OBJ(mpd_album, INFO_MPD)
3324 END OBJ(mpd_vol, INFO_MPD)
3325 END OBJ(mpd_bitrate, INFO_MPD)
3326 END OBJ(mpd_status, INFO_MPD)
3327 END OBJ(mpd_bar, INFO_MPD)
3328 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3329 END OBJ(mpd_smart, INFO_MPD) END
3332 OBJ(xmms2_artist, INFO_XMMS2)
3333 END OBJ(xmms2_album, INFO_XMMS2)
3334 END OBJ(xmms2_title, INFO_XMMS2)
3335 END OBJ(xmms2_genre, INFO_XMMS2)
3336 END OBJ(xmms2_comment, INFO_XMMS2)
3337 END OBJ(xmms2_decoder, INFO_XMMS2)
3338 END OBJ(xmms2_transport, INFO_XMMS2)
3339 END OBJ(xmms2_url, INFO_XMMS2)
3340 END OBJ(xmms2_tracknr, INFO_XMMS2)
3341 END OBJ(xmms2_bitrate, INFO_XMMS2)
3342 END OBJ(xmms2_date, INFO_XMMS2)
3343 END OBJ(xmms2_id, INFO_XMMS2)
3344 END OBJ(xmms2_duration, INFO_XMMS2)
3345 END OBJ(xmms2_elapsed, INFO_XMMS2)
3346 END OBJ(xmms2_size, INFO_XMMS2)
3347 END OBJ(xmms2_status, INFO_XMMS2)
3348 END OBJ(xmms2_percent, INFO_XMMS2)
3349 END OBJ(xmms2_bar, INFO_XMMS2)
3350 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3351 END OBJ(xmms2_smart, INFO_XMMS2)
3355 OBJ(audacious_status, INFO_AUDACIOUS) END
3356 OBJ(audacious_title, INFO_AUDACIOUS)
3359 sscanf (arg, "%d", &info.audacious.max_title_len);
3360 if (info.audacious.max_title_len > 0) {
3361 info.audacious.max_title_len++;
3363 CRIT_ERR ("audacious_title: invalid length argument");
3368 OBJ(audacious_length, INFO_AUDACIOUS) END
3369 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3370 OBJ(audacious_position, INFO_AUDACIOUS) END
3371 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3372 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3373 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3374 OBJ(audacious_channels, INFO_AUDACIOUS) END
3375 OBJ(audacious_filename, INFO_AUDACIOUS) END
3376 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3377 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3378 OBJ(audacious_bar, INFO_AUDACIOUS)
3379 (void) scan_bar(arg, &obj->a, &obj->b);
3383 OBJ(bmpx_title, INFO_BMPX)
3384 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3386 OBJ(bmpx_artist, INFO_BMPX)
3387 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3389 OBJ(bmpx_album, INFO_BMPX)
3390 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3392 OBJ(bmpx_track, INFO_BMPX)
3393 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3395 OBJ(bmpx_uri, INFO_BMPX)
3396 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3398 OBJ(bmpx_bitrate, INFO_BMPX)
3399 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3405 int argc, delay, act_par;
3406 char *uri = (char *)malloc(128 * sizeof(char));
3407 char *action = (char *)malloc(64 * sizeof(char));
3409 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par);
3410 obj->data.rss.uri = uri;
3411 obj->data.rss.delay = delay;
3412 obj->data.rss.action = action;
3413 obj->data.rss.act_par = act_par;
3417 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
3423 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3424 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3425 ERR("hddtemp needs arguments");
3426 obj->type = OBJ_text;
3427 obj->data.s = strdup("${hddtemp}");
3432 #ifdef TCP_PORT_MONITOR
3433 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3434 int argc, port_begin, port_end, item, connection_index;
3436 memset(itembuf,0,sizeof(itembuf));
3438 /* massive argument checking */
3440 CRIT_ERR("tcp_portmon: needs arguments");
3442 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3443 if ( (argc != 3) && (argc != 4) )
3445 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3447 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3449 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3451 if ( port_begin > port_end )
3453 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3455 if ( strncmp(itembuf,"count",31) == 0 )
3457 else if ( strncmp(itembuf,"rip",31) == 0 )
3459 else if ( strncmp(itembuf,"rhost",31) == 0 )
3461 else if ( strncmp(itembuf,"rport",31) == 0 )
3463 else if ( strncmp(itembuf,"rservice",31) == 0 )
3465 else if ( strncmp(itembuf,"lip",31) == 0 )
3467 else if ( strncmp(itembuf,"lhost",31) == 0 )
3469 else if ( strncmp(itembuf,"lport",31) == 0 )
3471 else if ( strncmp(itembuf,"lservice",31) == 0 )
3475 CRIT_ERR("tcp_portmon: invalid item specified");
3477 if ( (argc==3) && (item!=COUNT) )
3479 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3481 if ( (argc==4) && (connection_index<0) )
3483 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3485 /* ok, args looks good. save the text object data */
3486 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3487 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3488 obj->data.tcp_port_monitor.item = item;
3489 obj->data.tcp_port_monitor.connection_index = connection_index;
3491 /* if the port monitor collection hasn't been created, we must create it */
3492 if ( !info.p_tcp_port_monitor_collection )
3494 info.p_tcp_port_monitor_collection =
3495 create_tcp_port_monitor_collection ();
3496 if ( !info.p_tcp_port_monitor_collection )
3498 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3502 /* if a port monitor for this port does not exist, create one and add it to the collection */
3503 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3505 tcp_port_monitor_t * p_monitor =
3506 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3509 CRIT_ERR("tcp_portmon: unable to create port monitor");
3511 /* add the newly created monitor to the collection */
3512 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3515 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3520 OBJ(entropy_avail, INFO_ENTROPY) END
3521 OBJ(entropy_poolsize, INFO_ENTROPY) END
3522 OBJ(entropy_bar, INFO_ENTROPY)
3523 (void) scan_bar(arg, &obj->a, &obj->b);
3528 ERR("unknown variable %s", s);
3529 obj->type = OBJ_text;
3530 snprintf(buf, 256, "${%s}", s);
3531 obj->data.s = strdup(buf);
3538 static struct text_object *create_plain_text(const char *s)
3540 struct text_object *obj;
3542 if (s == NULL || *s == '\0') {
3546 obj = new_text_object_internal();
3548 obj->type = OBJ_text;
3549 obj->data.s = strdup(s);
3553 static struct text_object_list *extract_variable_text_internal(const char *p)
3555 struct text_object_list *retval;
3556 struct text_object *obj;
3559 retval = malloc(sizeof(struct text_object_list));
3560 memset(retval, 0, sizeof(struct text_object_list));
3561 retval->text_object_count = 0;
3563 long line = text_lines;
3571 obj = create_plain_text(s);
3573 // allocate memory for the object
3574 retval->text_objects = realloc(retval->text_objects,
3575 sizeof(struct text_object) * (retval->text_object_count+1));
3576 // assign the new object to the end of the list.
3577 memcpy(&retval->text_objects[retval->text_object_count++],
3578 obj, sizeof(struct text_object));
3590 /* variable is either $foo or ${foo} */
3592 unsigned int brl = 1, brr = 0;
3595 while (*p && brl != brr) {
3596 if (*p == '{') brl++;
3597 if (*p == '}') brr++;
3605 while (*p && (isalnum((int) *p)
3610 /* copy variable to buffer */
3611 len = (p - s > 255) ? 255 : (p - s);
3612 strncpy(buf, s, len);
3621 /* if variable wasn't found from environment, use some special */
3627 if (strchr(buf, ' ')) {
3628 arg = strchr(buf, ' ');
3631 while (isspace((int) *arg))
3637 /* lowercase variable name */
3644 // create new object
3645 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3647 // allocate memory for the object
3648 retval->text_objects = realloc(retval->text_objects,
3649 sizeof(struct text_object) * (retval->text_object_count+1));
3650 // assign the new object to the end of the list.
3651 memcpy(&retval->text_objects[retval->text_object_count++],
3652 obj, sizeof(struct text_object));
3658 obj = create_plain_text("$");
3660 // allocate memory for the object
3661 retval->text_objects = realloc(retval->text_objects,
3662 sizeof(struct text_object) * (retval->text_object_count+1));
3663 // assign the new object to the end of the list.
3664 memcpy(&retval->text_objects[retval->text_object_count++],
3665 obj, sizeof(struct text_object));
3672 obj = create_plain_text(s);
3674 // allocate memory for the object
3675 retval->text_objects = realloc(retval->text_objects,
3676 sizeof(struct text_object) * (retval->text_object_count+1));
3677 // assign the new object to the end of the list.
3678 memcpy(&retval->text_objects[retval->text_object_count++],
3679 obj, sizeof(struct text_object));
3684 ERR("one or more $endif's are missing");
3690 static void extract_variable_text(const char *p)
3692 struct text_object_list *list;
3694 free_text_objects(text_object_count, text_objects);
3695 text_object_count = 0;
3696 text_objects = NULL;
3699 list = extract_variable_text_internal(p);
3700 text_objects = list->text_objects;
3701 text_object_count = list->text_object_count;
3708 void parse_conky_vars(char * text, char * p, struct information *cur) {
3709 struct text_object_list *object_list = extract_variable_text_internal(text);
3710 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3715 * Allows reading from a FIFO (i.e., /dev/xconsole). The file descriptor is
3716 * set to non-blocking which makes this possible.
3719 * Since lseek cannot seek a file descriptor long lines will break.
3721 static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
3723 #define TAIL_PIPE_BUFSIZE 4096
3727 int fd = obj->data.tail.fd;
3730 char buf[TAIL_PIPE_BUFSIZE];
3731 ssize_t len = read(fd, buf, sizeof(buf));
3735 if (errno != EAGAIN) {
3736 strcpy(obj->data.tail.buffer, "Logfile Read Error");
3737 snprintf(dst, dst_size, "Logfile Read Error");
3742 else if (len == 0) {
3743 strcpy(obj->data.tail.buffer, "Logfile Empty");
3744 snprintf(dst, dst_size, "Logfile Empty");
3748 for (line_len = 0, i = 0; i < len; i++) {
3752 if (buf[i] == '\n') {
3755 if (obj->data.tail.readlines > 0) {
3760 for (n = 0; obj->data.tail.buffer[n]; n++) {
3761 if (obj->data.tail.buffer[n] == '\n') {
3765 if (++olines < obj->data.tail.wantedlines) {
3771 p = obj->data.tail.buffer + first_line;
3772 pos = n - first_line;
3773 memmove(obj->data.tail.buffer, obj->data.tail.buffer + first_line, strlen(p));
3774 obj->data.tail.buffer[pos] = 0;
3780 p = buf + last_line;
3782 memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
3783 obj->data.tail.buffer[pos + line_len] = 0;
3786 obj->data.tail.readlines = lines;
3794 snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
3797 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3802 char buff_in[P_MAX_SIZE] = {0};
3803 iconv_converting = 0;
3806 for (i = 0; i < object_count; i++) {
3807 struct text_object *obj = &objs[i];
3809 #define OBJ(a) break; case OBJ_##a:
3811 switch (obj->type) {
3814 ERR("not implemented obj type %d",
3819 /* does anyone have decimals in acpi temperature? */
3820 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
3821 round_to_int(get_acpi_temperature(obj->data.i)));
3824 /* does anyone have decimals in acpi temperature? */
3825 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
3826 round_to_int((get_acpi_temperature(obj->data.i) + 40) *
3829 #endif /* !__OpenBSD__ */
3832 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3838 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3840 /* OpenBSD has no such flag (SUSv2) */
3841 obj->a = get_freq(p, p_max_size, "%.2f", 1000, obj->data.cpu_index);
3846 #if defined(__linux__)
3849 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3854 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3858 OBJ(wireless_essid) {
3859 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3861 OBJ(wireless_mode) {
3862 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3864 OBJ(wireless_bitrate) {
3865 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3868 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3870 OBJ(wireless_link_qual) {
3871 spaced_print(p, p_max_size, "%d", 4, "wireless_link_qual",
3872 obj->data.net->link_qual);
3874 OBJ(wireless_link_qual_max) {
3875 spaced_print(p, p_max_size, "%d", 4,
3876 "wireless_link_qual_max", obj->data.net->link_qual_max);
3878 OBJ(wireless_link_qual_perc) {
3879 if(obj->data.net->link_qual_max > 0) {
3880 spaced_print(p, p_max_size, "%.0f%%", 5,
3881 "wireless_link_qual_perc",
3882 (double) obj->data.net->link_qual /
3883 obj->data.net->link_qual_max * 100);
3885 spaced_print(p, p_max_size, "unk", 5,
3886 "wireless_link_qual_perc");
3889 OBJ(wireless_link_bar) {
3890 new_bar(p, obj->a, obj->b, ((double)obj->data.net->link_qual/obj->data.net->link_qual_max)*255.0);
3892 #endif /* HAVE_IWLIB */
3894 #endif /* __linux__ */
3897 get_freq_dynamic(p, p_max_size, "%.0f", 1);
3898 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
3902 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3904 get_freq_dynamic(p, p_max_size, "%.2f", 1000);
3906 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
3910 get_adt746x_cpu(p, p_max_size);
3913 get_adt746x_fan(p, p_max_size);
3916 get_acpi_fan(p, p_max_size);
3918 OBJ(acpiacadapter) {
3919 get_acpi_ac_adapter(p, p_max_size);
3922 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3925 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3927 OBJ(battery_percent) {
3928 snprintf(p, p_max_size, "%d",
3929 get_battery_perct(obj->data.s));
3932 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3934 #endif /* __OpenBSD__ */
3936 human_readable(cur->buffers * 1024, p, 255, "buffers");
3939 human_readable(cur->cached * 1024, p, 255, "buffers");
3942 if (obj->data.cpu_index > info.cpu_count) {
3943 printf("obj->data.cpu_index %i info.cpu_count %i",
3944 obj->data.cpu_index, info.cpu_count);
3945 CRIT_ERR("attempting to use more CPUs then you have!");
3947 spaced_print(p, p_max_size, "%*d", 4, "cpu", pad_percents,
3948 round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3954 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3957 new_graph(p, obj->a,
3958 obj->b, obj->c, obj->d,
3959 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3963 new_fg(p, obj->data.l);
3995 #if defined(__linux__)
3997 snprintf(p, p_max_size, "%s", i8k.version);
4000 snprintf(p, p_max_size, "%s", i8k.bios);
4003 snprintf(p, p_max_size, "%s", i8k.serial);
4006 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
4008 OBJ(i8k_cpu_tempf) {
4010 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
4011 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
4013 OBJ(i8k_left_fan_status) {
4014 int left_fan_status;
4015 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
4016 if(left_fan_status == 0) {
4017 snprintf(p, p_max_size,"off");
4018 } if(left_fan_status == 1) {
4019 snprintf(p, p_max_size, "low");
4020 } if(left_fan_status == 2) {
4021 snprintf(p, p_max_size, "high");
4025 OBJ(i8k_right_fan_status) {
4026 int right_fan_status;
4027 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
4028 if(right_fan_status == 0) {
4029 snprintf(p, p_max_size,"off");
4030 } if(right_fan_status == 1) {
4031 snprintf(p, p_max_size, "low");
4032 } if(right_fan_status == 2) {
4033 snprintf(p, p_max_size, "high");
4036 OBJ(i8k_left_fan_rpm) {
4037 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
4039 OBJ(i8k_right_fan_rpm) {
4040 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
4042 OBJ(i8k_ac_status) {
4044 sscanf(i8k.ac_status, "%d", &ac_status);
4045 if(ac_status == -1) {
4046 snprintf(p, p_max_size,"disabled (read i8k docs)");
4047 } if(ac_status == 0) {
4048 snprintf(p, p_max_size, "off");
4049 } if(ac_status == 1) {
4050 snprintf(p, p_max_size, "on");
4053 OBJ(i8k_buttons_status) {
4054 snprintf(p, p_max_size, "%s", i8k.buttons_status);
4058 get_ibm_acpi_fan(p, p_max_size);
4061 get_ibm_acpi_temps();
4062 snprintf(p, p_max_size, "%d",
4063 ibm_acpi.temps[obj->data.sensor]);
4066 get_ibm_acpi_volume(p, p_max_size);
4068 OBJ(ibm_brightness) {
4069 get_ibm_acpi_brightness(p, p_max_size);
4072 get_powerbook_batt_info(p, p_max_size, obj->data.i);
4074 #endif /* __linux__ */
4077 OBJ(obsd_sensors_temp) {
4078 obsd_sensors.device = sensor_device;
4079 update_obsd_sensors();
4080 snprintf(p, p_max_size, "%.1f",
4081 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
4084 OBJ(obsd_sensors_fan) {
4085 obsd_sensors.device = sensor_device;
4086 update_obsd_sensors();
4087 snprintf(p, p_max_size, "%d",
4088 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
4091 OBJ(obsd_sensors_volt) {
4092 obsd_sensors.device = sensor_device;
4093 update_obsd_sensors();
4094 snprintf(p, p_max_size, "%.2f",
4095 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4099 get_obsd_vendor(p, p_max_size);
4103 get_obsd_product(p, p_max_size);
4105 #endif /* __OpenBSD__ */
4109 new_font(p, obj->data.s);
4112 /* TODO: move this correction from kB to kB/s elsewhere
4113 * (or get rid of it??) */
4115 if (obj->data.diskio) {
4116 human_readable((obj->data.diskio->current / update_interval) * 1024LL, p, p_max_size, "diskio");
4118 human_readable(diskio_value * 1024LL, p, p_max_size, "diskio");
4122 if (obj->data.diskio) {
4123 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL, p, p_max_size,
4126 human_readable(diskio_write_value * 1024LL, p, p_max_size,
4131 if (obj->data.diskio) {
4132 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL, p, p_max_size,
4135 human_readable(diskio_read_value * 1024LL, p, p_max_size,
4140 if (obj->data.diskio) {
4141 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4142 obj->data.diskio->current, obj->e, 1);
4144 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4145 diskio_value, obj->e, 1);
4148 OBJ(diskiograph_read) {
4149 if (obj->data.diskio) {
4150 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4151 obj->data.diskio->current_read, obj->e, 1);
4153 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4154 diskio_read_value, obj->e, 1);
4157 OBJ(diskiograph_write) {
4158 if (obj->data.diskio) {
4159 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4160 obj->data.diskio->current_write, obj->e, 1);
4162 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4163 diskio_write_value, obj->e, 1);
4167 spaced_print(p, p_max_size, "%d", 6, "downspeed",
4168 round_to_int(obj->data.net->recv_speed / 1024));
4171 spaced_print(p, p_max_size, "%.1f", 8, "downspeedf",
4172 obj->data.net->recv_speed / 1024.0);
4174 OBJ(downspeedgraph) {
4175 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4176 (obj->data.net->recv_speed / 1024.0), obj->e, 1);
4180 i = obj->data.ifblock.pos - 1;
4190 snprintf(p, p_max_size, "%u.%u.%u.%u",
4191 obj->data.net->addr.
4193 obj->data.net->addr.
4195 obj->data.net->addr.
4197 obj->data.net->addr.
4201 #if defined(IMLIB2) && defined(X11)
4206 Imlib_Image image, buffer;
4207 image = imlib_load_image(obj->data.s);
4208 imlib_context_set_image(image);
4211 w = imlib_image_get_width();
4212 h = imlib_image_get_height();
4213 buffer = imlib_create_image(w, h);
4214 imlib_context_set_display(display);
4215 imlib_context_set_drawable(window.drawable);
4216 imlib_context_set_colormap(DefaultColormap(display, screen));
4217 imlib_context_set_visual(DefaultVisual(display, screen));
4218 imlib_context_set_image(buffer);
4219 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
4220 imlib_render_image_on_drawable(text_start_x, text_start_y);
4222 imlib_context_set_image(image);
4229 FILE *fp = popen(obj->data.s, "r");
4230 int length = fread(p, 1, p_max_size, fp);
4233 /*output[length] = '\0';
4234 if (length > 0 && output[length - 1] == '\n') {
4235 output[length - 1] = '\0';
4238 if (length > 0 && p[length - 1] == '\n') {
4239 p[length - 1] = '\0';
4242 //parse_conky_vars(output, p, cur);
4246 FILE *fp = popen(obj->data.s, "r");
4247 int n2 = fread(p, 1, p_max_size, fp);
4251 if (n2 && p[n2 - 1] == '\n')
4260 if (sscanf(p, "%lf", &barnum) == 0) {
4261 ERR("reading execbar value failed (perhaps it's not the correct format?)");
4263 if (barnum > 100 || barnum < 0) {
4264 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
4266 barnum = barnum / 100.0;
4267 new_bar(p, 0, 4, (int) (barnum * 255.0));
4273 FILE *fp = popen(obj->data.s, "r");
4274 int n2 = fread(p, 1, p_max_size, fp);
4278 if (n2 && p[n2 - 1] == '\n')
4287 if (sscanf(p, "%lf", &barnum) == 0) {
4288 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
4290 if (barnum > 100 || barnum < 0) {
4291 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
4293 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
4298 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
4299 new_bar(p, 0, 4, (int) obj->f);
4302 FILE *fp = popen(obj->data.execi.cmd, "r");
4303 int n2 = fread(p, 1, p_max_size, fp);
4306 if (n2 && p[n2 - 1] == '\n')
4315 if (sscanf(p, "%f", &barnum) == 0) {
4316 ERR("reading execibar value failed (perhaps it's not the correct format?)");
4318 if (barnum > 100 || barnum < 0) {
4319 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
4321 obj->f = 255 * barnum / 100.0;
4322 new_bar(p, 0, 4, (int) obj->f);
4324 obj->data.execi.last_update =
4325 current_update_time;
4329 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
4330 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
4333 FILE *fp = popen(obj->data.execi.cmd, "r");
4334 int n2 = fread(p, 1, p_max_size, fp);
4337 if (n2 && p[n2 - 1] == '\n')
4346 if (sscanf(p, "%f", &barnum) == 0) {
4347 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
4349 if (barnum > 100 || barnum < 0) {
4350 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
4353 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
4355 obj->data.execi.last_update = current_update_time;
4361 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
4362 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4364 char *output = obj->data.execi.buffer;
4365 FILE *fp = popen(obj->data.execi.cmd, "r");
4366 //int length = fread(output, 1, text_buffer_size, fp);
4367 int length = fread(output, 1, text_buffer_size, fp);
4370 output[length] = '\0';
4371 if (length > 0 && output[length - 1] == '\n') {
4372 output[length - 1] = '\0';
4374 obj->data.execi.last_update = current_update_time;
4375 snprintf(p, p_max_size, "%s", output);
4377 //parse_conky_vars(output, p, cur);
4380 if (!obj->data.texeci.p_timed_thread)
4382 obj->data.texeci.p_timed_thread=
4383 timed_thread_create ((void*)threaded_exec, (void*) obj, obj->data.texeci.interval * 1000000);
4384 if (!obj->data.texeci.p_timed_thread)
4385 ERR("Error creating texeci timed thread");
4386 timed_thread_register (obj->data.texeci.p_timed_thread, &obj->data.texeci.p_timed_thread);
4387 if (timed_thread_run (obj->data.texeci.p_timed_thread))
4388 ERR("Error running texeci timed thread");
4390 timed_thread_lock (obj->data.texeci.p_timed_thread);
4391 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4392 timed_thread_unlock (obj->data.texeci.p_timed_thread);
4394 #endif /* HAVE_POPEN */
4396 if (obj->global_mode && info.mail) { // this means we use info
4397 if (!info.mail->p_timed_thread)
4399 info.mail->p_timed_thread =
4400 timed_thread_create ((void*)imap_thread, (void*)info.mail, info.mail->interval * 1000000);
4401 if (!info.mail->p_timed_thread)
4402 ERR("Error creating imap timed thread");
4403 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4404 if (timed_thread_run (info.mail->p_timed_thread))
4405 ERR("Error running imap timed thread");
4407 timed_thread_lock (info.mail->p_timed_thread);
4408 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4409 timed_thread_unlock (info.mail->p_timed_thread);
4410 } else if (obj->data.mail) { // this means we use obj
4411 if (!obj->data.mail->p_timed_thread)
4413 obj->data.mail->p_timed_thread =
4414 timed_thread_create ((void*)imap_thread, (void*)obj->data.mail,
4415 obj->data.mail->interval * 1000000);
4416 if (!obj->data.mail->p_timed_thread)
4417 ERR("Error creating imap timed thread");
4418 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4419 if (timed_thread_run (obj->data.mail->p_timed_thread))
4420 ERR("Error running imap timed thread");
4422 timed_thread_lock (obj->data.mail->p_timed_thread);
4423 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4424 timed_thread_unlock (obj->data.mail->p_timed_thread);
4425 } else if (!obj->a) { // something is wrong, warn once then stop
4426 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4430 OBJ(imap_messages) {
4431 if (obj->global_mode && info.mail) { // this means we use info
4432 if (!info.mail->p_timed_thread)
4434 info.mail->p_timed_thread =
4435 timed_thread_create ((void*)imap_thread, (void*)info.mail, info.mail->interval * 1000000);
4436 if (!info.mail->p_timed_thread)
4437 ERR("Error creating imap timed thread");
4438 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4439 if (timed_thread_run (info.mail->p_timed_thread))
4440 ERR("Error running imap timed thread");
4442 timed_thread_lock (info.mail->p_timed_thread);
4443 snprintf(p, p_max_size, "%lu", info.mail->messages);
4444 timed_thread_unlock (info.mail->p_timed_thread);
4445 } else if (obj->data.mail) { // this means we use obj
4446 if (!obj->data.mail->p_timed_thread)
4448 obj->data.mail->p_timed_thread =
4449 timed_thread_create ((void*)imap_thread, (void*)obj->data.mail,
4450 obj->data.mail->interval * 1000000);
4451 if (!obj->data.mail->p_timed_thread)
4452 ERR("Error creating imap timed thread");
4453 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4454 if (timed_thread_run (obj->data.mail->p_timed_thread))
4455 ERR("Error runninging imap timed thread");
4457 timed_thread_lock (obj->data.mail->p_timed_thread);
4458 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4459 timed_thread_lock (obj->data.mail->p_timed_thread);
4460 } else if (!obj->a) { // something is wrong, warn once then stop
4461 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4466 if (obj->global_mode && info.mail) { // this means we use info
4467 if (!info.mail->p_timed_thread)
4469 info.mail->p_timed_thread =
4470 timed_thread_create ((void*)pop3_thread, (void*)info.mail, info.mail->interval * 1000000);
4471 if (!info.mail->p_timed_thread)
4472 ERR("Error creating pop3 timed thread");
4473 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4474 if (timed_thread_run (info.mail->p_timed_thread))
4475 ERR("Error running pop3 timed thread");
4477 timed_thread_lock (info.mail->p_timed_thread);
4478 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4479 timed_thread_unlock (info.mail->p_timed_thread);
4480 } else if (obj->data.mail) { // this means we use obj
4481 if (!obj->data.mail->p_timed_thread)
4483 obj->data.mail->p_timed_thread =
4484 timed_thread_create ((void*)pop3_thread, (void*)obj->data.mail,
4485 obj->data.mail->interval * 1000000);
4486 if (!obj->data.mail->p_timed_thread)
4487 ERR("Error creating pop3 timed thread");
4488 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4489 if (timed_thread_run (obj->data.mail->p_timed_thread))
4490 ERR("Error running pop3 timed thread");
4492 timed_thread_lock (obj->data.mail->p_timed_thread);
4493 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4494 timed_thread_unlock (obj->data.mail->p_timed_thread);
4495 } else if (!obj->a) { // something is wrong, warn once then stop
4496 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4501 if (obj->global_mode && info.mail) { // this means we use info
4502 if (!info.mail->p_timed_thread)
4504 info.mail->p_timed_thread =
4505 timed_thread_create ((void*)pop3_thread, (void*)info.mail, info.mail->interval * 1000000);
4506 if (!info.mail->p_timed_thread)
4507 ERR("Error creating pop3 timed thread");
4508 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4509 if (timed_thread_run (info.mail->p_timed_thread))
4510 ERR("Error running pop3 timed thread");
4512 timed_thread_lock (info.mail->p_timed_thread);
4513 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4514 timed_thread_unlock (info.mail->p_timed_thread);
4515 } else if (obj->data.mail) { // this means we use obj
4516 if (!obj->data.mail->p_timed_thread)
4518 obj->data.mail->p_timed_thread =
4519 timed_thread_create ((void*)pop3_thread, (void*)obj->data.mail,
4520 obj->data.mail->interval * 1000000);
4521 if (!obj->data.mail->p_timed_thread)
4522 ERR("Error creating pop3 timed thread");
4523 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4524 if (timed_thread_run (obj->data.mail->p_timed_thread))
4525 ERR("Error running pop3 timed thread");
4527 timed_thread_lock (obj->data.mail->p_timed_thread);
4528 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4529 timed_thread_unlock (obj->data.mail->p_timed_thread);
4530 } else if (!obj->a) { // something is wrong, warn once then stop
4531 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4536 if (obj->data.fs != NULL) {
4537 if (obj->data.fs->size == 0)
4556 if (obj->data.fs != NULL) {
4557 human_readable(obj->data.fs->avail, p, 255, "fs_free");
4561 if (obj->data.fs != NULL) {
4562 if (obj->data.fs->size)
4563 snprintf(p, p_max_size, "%*d",
4572 snprintf(p, p_max_size, "0");
4576 if (obj->data.fs != NULL) {
4577 human_readable(obj->data.fs->size, p, 255, "fs_size");
4581 if (obj->data.fs != NULL) {
4582 human_readable(obj->data.fs->size -
4583 (obj->data.fs->free ? obj->data.fs->free :
4584 obj->data.fs->avail), p, 255, "fs_used");
4588 if (obj->data.fs != NULL) {
4589 if (obj->data.fs->size == 0)
4607 if (obj->data.fs != NULL) {
4608 if (obj->data.fs->size)
4609 snprintf(p, 4, "%d",
4619 snprintf(p, p_max_size, "0");
4623 float *v = info.loadavg;
4625 if (obj->data.loadavg[2])
4626 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4627 v[obj->data.loadavg[0] -
4629 v[obj->data.loadavg[1] -
4631 v[obj->data.loadavg[2] -
4633 else if (obj->data.loadavg[1])
4634 snprintf(p, p_max_size, "%.2f %.2f",
4635 v[obj->data.loadavg[0] -
4637 v[obj->data.loadavg[1] -
4639 else if (obj->data.loadavg[0])
4640 snprintf(p, p_max_size, "%.2f",
4641 v[obj->data.loadavg[0] -
4645 new_goto(p, obj->data.i);
4648 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4651 new_hr(p, obj->data.i);
4655 PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay);
4658 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4660 if(!strcmp(obj->data.rss.action, "feed_title")) {
4662 if(str[strlen(str)-1] == '\n')
4663 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4664 snprintf(p, p_max_size, "%s", str);
4665 } else if(!strcmp(obj->data.rss.action, "item_title")) {
4666 if(obj->data.rss.act_par < data->item_count) {
4667 str = data->items[obj->data.rss.act_par].title;
4668 if(str[strlen(str)-1] == '\n')
4669 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4670 snprintf(p, p_max_size, "%s", str);
4672 } else if(!strcmp(obj->data.rss.action, "item_desc")) {
4673 if(obj->data.rss.act_par < data->item_count) {
4674 str = data->items[obj->data.rss.act_par].description;
4675 if(str[strlen(str)-1] == '\n')
4676 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4677 snprintf(p, p_max_size, "%s", str);
4679 } else if(!strcmp(obj->data.rss.action, "item_titles")) {
4680 if(data->item_count > 0) {
4684 if(obj->data.rss.act_par > data->item_count)
4685 show = data->item_count;
4686 else show = obj->data.rss.act_par;
4687 for(itmp = 0; itmp < show; itmp++) {
4688 PRSS_Item *item = &data->items[itmp];
4691 if(itmp>0) // don't add new line before first item
4692 strncat(p, "\n", p_max_size);
4693 if(str[strlen(str)-1] == '\n')
4694 str[strlen(str)-1] = 0; // remove trailing new line if one exists, we have our own
4695 strncat(p, str, p_max_size);
4708 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4709 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4711 snprintf(p, p_max_size, "N/A");
4712 } else if (unit == '*') {
4713 snprintf(p, p_max_size, "%s", temp);
4715 snprintf(p, p_max_size, "%s°%c", temp, unit);
4720 new_offset(p, obj->data.i);
4723 new_voffset(p, obj->data.i);
4729 r = get_sysfs_info(&obj->data.sysfs.fd,
4730 obj->data.sysfs.arg,
4731 obj->data.sysfs.devtype,
4732 obj->data.sysfs.type);
4734 if (r >= 100.0 || r == 0)
4735 snprintf(p, p_max_size, "%d", (int) r);
4737 snprintf(p, p_max_size, "%.1f", r);
4742 r = get_sysfs_info(&obj->data.sysfs.fd,
4743 obj->data.sysfs.arg,
4744 obj->data.sysfs.devtype,
4745 obj->data.sysfs.type);
4747 if (r >= 100.0 || r == 0)
4748 snprintf(p, p_max_size, "%d", (int) r);
4750 snprintf(p, p_max_size, "%.1f", r);
4755 r = get_sysfs_info(&obj->data.sysfs.fd,
4756 obj->data.sysfs.arg,
4757 obj->data.sysfs.devtype,
4758 obj->data.sysfs.type);
4760 if (r >= 100.0 || r == 0)
4761 snprintf(p, p_max_size, "%d", (int) r);
4763 snprintf(p, p_max_size, "%.1f", r);
4765 #endif /* !__OpenBSD__ */
4767 new_alignr(p, obj->data.i);
4770 new_alignc(p, obj->data.i);
4773 struct information *my_info =
4774 malloc(sizeof(struct information));
4775 memcpy(my_info, cur, sizeof(struct information));
4776 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4777 if (strlen(p) != 0) {
4778 i = obj->data.ifblock.pos;
4788 if ((obj->data.ifblock.s)
4789 && (stat(obj->data.ifblock.s, &tmp) ==
4791 i = obj->data.ifblock.pos;
4794 if (obj->data.ifblock.str) {
4795 if (!check_contains(obj->data.ifblock.s,
4796 obj->data.ifblock.str)) {
4797 i = obj->data.ifblock.pos;
4806 if ((obj->data.ifblock.s)
4807 && (!check_mount(obj->data.ifblock.s))) {
4808 i = obj->data.ifblock.pos;
4815 if ((obj->data.ifblock.s)
4816 && system(obj->data.ifblock.s)) {
4817 i = obj->data.ifblock.pos;
4824 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4827 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4832 human_readable(cur->mem * 1024, p, 255, "mem");
4835 human_readable(cur->memmax * 1024, p, 255, "memmax");
4839 spaced_print(p, p_max_size, "%*Lu", 4, "memperc",
4840 pad_percents, cur->mem * 100 / cur->memmax);
4844 new_bar(p, obj->data.pair.a,
4846 cur->memmax ? (cur->mem * 255) /
4851 new_graph(p, obj->a,
4852 obj->b, obj->c, obj->d,
4853 cur->memmax ? (cur->mem * 100.0) /
4854 (cur->memmax) : 0.0, 100, 1);
4858 snprintf(p, p_max_size, "%d",
4859 mixer_get_avg(obj->data.l));
4862 snprintf(p, p_max_size, "%d",
4863 mixer_get_left(obj->data.l));
4866 snprintf(p, p_max_size, "%d",
4867 mixer_get_right(obj->data.l));
4870 new_bar(p, obj->data.mixerbar.w,
4871 obj->data.mixerbar.h,
4872 mixer_get_avg(obj->data.mixerbar.
4876 new_bar(p, obj->data.mixerbar.w,
4877 obj->data.mixerbar.h,
4878 mixer_get_left(obj->data.mixerbar.
4882 new_bar(p, obj->data.mixerbar.w,
4883 obj->data.mixerbar.h,
4884 mixer_get_right(obj->data.mixerbar.
4890 update_mail_count(&obj->data.local_mail);
4891 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
4894 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4895 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4898 update_mail_count(&obj->data.local_mail);
4899 snprintf(p, p_max_size, "%d", obj->data.local_mail.new_mail_count);
4903 snprintf(p, p_max_size, "%s",
4904 cur->uname_s.nodename);
4907 new_outline(p, obj->data.l);
4910 spaced_print(p, p_max_size, "%hu", 5, "processes", cur->procs);
4912 OBJ(running_processes) {
4913 spaced_print(p, p_max_size, "%hu", 3, "running_processes",
4917 snprintf(p, p_max_size, "%s", obj->data.s);
4920 new_bg(p, obj->data.l);
4923 new_stippled_hr(p, obj->data.pair.a,
4927 human_readable(cur->swap * 1024, p, 255, "swap");
4930 human_readable(cur->swapmax * 1024, p, 255, "swapmax");
4933 if (cur->swapmax == 0) {
4934 strncpy(p, "No swap", p_max_size);
4936 spaced_print(p, p_max_size, "%*Lu", 4, "swapperc",
4937 pad_percents, cur->swap * 100 / cur->swapmax);
4941 new_bar(p, obj->data.pair.a,
4943 cur->swapmax ? (cur->swap * 255) /
4944 (cur->swapmax) : 0);
4947 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4950 time_t t = time(NULL);
4951 struct tm *tm = localtime(&t);
4952 setlocale(LC_TIME, "");
4953 strftime(p, p_max_size, obj->data.s, tm);
4956 time_t t = time(NULL);
4957 struct tm *tm = gmtime(&t);
4958 strftime(p, p_max_size, obj->data.s, tm);
4962 if (obj->data.tztime.tz) {
4963 oldTZ = getenv("TZ");
4964 setenv("TZ", obj->data.tztime.tz, 1);
4967 time_t t = time(NULL);
4968 struct tm *tm = localtime(&t);
4969 setlocale(LC_TIME, "");
4970 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4972 setenv("TZ", oldTZ, 1);
4977 // Needless to free oldTZ since getenv gives ptr to static data
4980 human_readable(obj->data.net->recv, p, 255, "totaldown");
4983 human_readable(obj->data.net->trans, p, 255, "totalup");
4986 snprintf(p, p_max_size, "%d", total_updates);
4989 spaced_print(p, p_max_size, "%d", 6, "upspeed",
4990 round_to_int(obj->data.net->trans_speed / 1024));
4993 spaced_print(p, p_max_size, "%.1f", 8, "upspeedf",
4994 obj->data.net->trans_speed / 1024.0);
4997 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4998 (obj->data.net->trans_speed / 1024.0), obj->e, 1);
5001 format_seconds_short(p, p_max_size,
5005 format_seconds(p, p_max_size, (int) cur->uptime);
5008 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5011 msg = get_apm_adapter();
5012 snprintf(p, p_max_size, "%s", msg);
5015 OBJ(apm_battery_life) {
5017 msg = get_apm_battery_life();
5018 snprintf(p, p_max_size, "%s", msg);
5021 OBJ(apm_battery_time) {
5023 msg = get_apm_battery_time();
5024 snprintf(p, p_max_size, "%s", msg);
5027 #endif /* __FreeBSD__ __OpenBSD__ */
5031 snprintf(p, cur->mpd.max_title_len > 0 ?
5032 cur->mpd.max_title_len : p_max_size, "%s",
5036 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5039 snprintf(p, p_max_size, "%s", cur->mpd.album);
5042 snprintf(p, p_max_size, "%s", cur->mpd.random);
5045 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
5048 snprintf(p, p_max_size, "%s", cur->mpd.track);
5051 snprintf(p, p_max_size, "%s", cur->mpd.name);
5054 snprintf(p, p_max_size, "%s", cur->mpd.file);
5057 snprintf(p, p_max_size, "%i", cur->mpd.volume);
5060 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
5063 snprintf(p, p_max_size, "%s", cur->mpd.status);
5066 int days = 0, hours = 0, minutes =
5068 int tmp = cur->mpd.elapsed;
5069 while (tmp >= 86400) {
5073 while (tmp >= 3600) {
5083 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
5084 days, hours, minutes,
5087 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
5090 snprintf(p, p_max_size, "%i:%02i", minutes,
5094 int days = 0, hours = 0, minutes =
5096 int tmp = cur->mpd.length;
5097 while (tmp >= 86400) {
5101 while (tmp >= 3600) {
5111 snprintf(p, p_max_size,
5112 "%i days %i:%02i:%02i",
5113 days, hours, minutes,
5116 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
5119 snprintf(p, p_max_size, "%i:%02i", minutes,
5123 snprintf(p, p_max_size, "%2.0f",
5124 cur->mpd.progress * 100);
5127 new_bar(p, obj->data.pair.a,
5129 (int) (cur->mpd.progress *
5133 memset (p, 0, p_max_size);
5134 if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title && *cur->mpd.title) {
5135 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
5137 else if (cur->mpd.title && *cur->mpd.title) {
5138 snprintf(p, p_max_size, "%s", cur->mpd.title);
5140 else if (cur->mpd.artist && *cur->mpd.artist) {
5141 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5143 else if (cur->mpd.file && *cur->mpd.file) {
5144 snprintf(p, p_max_size, "%s", cur->mpd.file);
5153 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5156 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5159 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5162 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5164 OBJ(xmms2_comment) {
5165 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5167 OBJ(xmms2_decoder) {
5168 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
5170 OBJ(xmms2_transport) {
5171 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
5174 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5177 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5180 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5182 OBJ(xmms2_tracknr) {
5183 if (cur->xmms2.tracknr != -1)
5184 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5186 OBJ(xmms2_bitrate) {
5187 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5190 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5193 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5195 OBJ(xmms2_elapsed) {
5196 int tmp = cur->xmms2.elapsed;
5197 snprintf(p, p_max_size, "%02d:%02d",
5198 tmp / 60000, (tmp / 1000) % 60);
5200 OBJ(xmms2_duration) {
5201 int tmp = cur->xmms2.duration;
5202 snprintf(p, p_max_size, "%02d:%02d",
5203 tmp / 60000, (tmp / 1000) % 60);
5205 OBJ(xmms2_percent) {
5206 snprintf(p, p_max_size, "%2.0f",
5207 cur->xmms2.progress * 100);
5210 new_bar(p, obj->data.pair.a,
5212 (int) (cur->xmms2.progress *
5216 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
5217 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5219 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
5224 OBJ(audacious_status) {
5225 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
5227 OBJ(audacious_title) {
5228 snprintf(p, cur->audacious.max_title_len > 0 ?
5229 cur->audacious.max_title_len : p_max_size, "%s",
5230 cur->audacious.items[AUDACIOUS_TITLE]);
5232 OBJ(audacious_length) {
5233 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
5235 OBJ(audacious_length_seconds) {
5236 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5238 OBJ(audacious_position) {
5239 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
5241 OBJ(audacious_position_seconds) {
5242 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5244 OBJ(audacious_bitrate) {
5245 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
5247 OBJ(audacious_frequency) {
5248 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
5250 OBJ(audacious_channels) {
5251 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
5253 OBJ(audacious_filename) {
5254 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
5256 OBJ(audacious_playlist_length) {
5257 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5259 OBJ(audacious_playlist_position) {
5260 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5262 OBJ(audacious_bar) {
5264 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5265 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5266 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
5271 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5274 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5277 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5280 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5283 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5286 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5290 char *format_time(unsigned long time, const int width) {
5292 unsigned long nt; // narrow time, for speed on
5295 unsigned cc; // centiseconds
5296 unsigned nn; // multi-purpose whatever
5299 cc = nt % 100; // centiseconds past second
5300 nt /= 100; // total seconds
5301 nn = nt % 60; // seconds past the minute
5302 nt /= 60; // total minutes
5303 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u", nt,
5306 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn))
5308 nn = nt % 60; // minutes past the hour
5309 nt /= 60; // total hours
5310 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn))
5312 nn = nt; // now also hours
5313 if (width >= snprintf(buf, sizeof buf, "%uh", nn))
5315 nn /= 24; // now days
5316 if (width >= snprintf(buf, sizeof buf, "%ud", nn))
5318 nn /= 7; // now weeks
5319 if (width >= snprintf(buf, sizeof buf, "%uw", nn))
5321 // well shoot, this outta' fit...
5322 return strdup("<inf>");
5326 if (obj->data.top.type == TOP_NAME
5327 && obj->data.top.num >= 0
5328 && obj->data.top.num < 10) {
5329 snprintf(p, 17, "%-17s", cur->cpu[obj->data.top.num]->name);
5330 } else if (obj->data.top.type == TOP_CPU
5331 && obj->data.top.num >= 0
5332 && obj->data.top.num < 10) {
5333 snprintf(p, 7, "%7.3f",
5334 cur->cpu[obj->data.top.
5336 } else if (obj->data.top.type == TOP_PID
5337 && obj->data.top.num >= 0
5338 && obj->data.top.num < 10) {
5339 snprintf(p, 8, "%7i",
5340 cur->cpu[obj->data.top.
5342 } else if (obj->data.top.type == TOP_MEM
5343 && obj->data.top.num >= 0
5344 && obj->data.top.num < 10) {
5345 snprintf(p, 7, "%7.3f",
5346 cur->cpu[obj->data.top.
5348 } else if (obj->data.top.type == TOP_TIME
5349 && obj->data.top.num >= 0
5350 && obj->data.top.num < 10) {
5351 char *time = format_time(cur->cpu[obj->data.top.num]->
5353 snprintf(p, 10, "%9s", time);
5358 if (obj->data.top.type == TOP_NAME
5359 && obj->data.top.num >= 0
5360 && obj->data.top.num < 10) {
5361 snprintf(p, 17, "%-17s",
5362 cur->memu[obj->data.top.
5364 } else if (obj->data.top.type == TOP_CPU
5365 && obj->data.top.num >= 0
5366 && obj->data.top.num < 10) {
5367 snprintf(p, 7, "%7.3f",
5368 cur->memu[obj->data.top.
5370 } else if (obj->data.top.type == TOP_PID
5371 && obj->data.top.num >= 0
5372 && obj->data.top.num < 10) {
5373 snprintf(p, 8, "%7i",
5374 cur->memu[obj->data.top.
5376 } else if (obj->data.top.type == TOP_MEM
5377 && obj->data.top.num >= 0
5378 && obj->data.top.num < 10) {
5379 snprintf(p, 7, "%7.3f",
5380 cur->memu[obj->data.top.
5382 } else if (obj->data.top.type == TOP_TIME
5383 && obj->data.top.num >= 0
5384 && obj->data.top.num < 10) {
5385 char *time = format_time(cur->memu[obj->data.top.num]->
5387 snprintf(p, 10, "%9s", time);
5394 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5395 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5397 obj->data.tail.last_update = current_update_time;
5402 if (obj->data.tail.fd != -1) {
5403 tail_pipe(obj, p, p_max_size);
5407 fp = fopen(obj->data.tail.logfile, "rt");
5410 /* Send one message, but do not consistently spam on
5411 * missing logfiles. */
5412 if(obj->data.tail.readlines != 0) {
5413 ERR("tail logfile failed to open");
5414 strcpy(obj->data.tail.buffer, "Logfile Missing");
5416 obj->data.tail.readlines = 0;
5417 snprintf(p, p_max_size, "Logfile Missing");
5420 obj->data.tail.readlines = 0;
5421 /* -1 instead of 0 to avoid counting a trailing newline */
5422 fseek(fp, -1, SEEK_END);
5423 bsize = ftell(fp) + 1;
5424 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5425 nl = rev_fcharfind(fp, '\n', iter);
5429 obj->data.tail.readlines = iter;
5430 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
5431 fseek(fp, 0, SEEK_SET);
5434 fseek(fp, nl+1, SEEK_SET);
5437 /* Make sure bsize is at least 1 byte smaller than
5438 * the buffer max size. */
5439 if(bsize > (long)((text_buffer_size*20) - 1)) {
5440 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
5441 bsize = text_buffer_size*20 - 1;
5443 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5446 /* Clean up trailing newline, make sure the buffer
5447 * is null terminated. */
5448 if(obj->data.tail.buffer[bsize-1] == '\n')
5449 obj->data.tail.buffer[bsize-1] = '\0';
5451 obj->data.tail.buffer[bsize] = '\0';
5452 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5455 strcpy(obj->data.tail.buffer, "Logfile Empty");
5456 snprintf(p, p_max_size, "Logfile Empty");
5459 } /* if cur_upd_time >= */
5461 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5466 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5467 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5469 obj->data.tail.last_update = current_update_time;
5473 fp = fopen(obj->data.tail.logfile, "rt");
5475 /* Send one message, but do not consistently spam on
5476 * missing logfiles. */
5477 if(obj->data.tail.readlines != 0) {
5478 ERR("head logfile failed to open");
5479 strcpy(obj->data.tail.buffer, "Logfile Missing");
5481 obj->data.tail.readlines = 0;
5482 snprintf(p, p_max_size, "Logfile Missing");
5484 obj->data.tail.readlines = 0;
5485 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5486 nl = fwd_fcharfind(fp, '\n', iter);
5490 obj->data.tail.readlines = iter;
5491 /* Make sure nl is at least 1 byte smaller than
5492 * the buffer max size. */
5493 if(nl > (long)((text_buffer_size*20) - 1)) {
5494 nl = text_buffer_size*20 - 1;
5496 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5499 /* Clean up trailing newline, make sure the buffer
5500 * is null terminated. */
5501 if (obj->data.tail.buffer[nl-1] == '\n') {
5502 obj->data.tail.buffer[nl-1] = '\0';
5505 obj->data.tail.buffer[nl] = '\0';
5507 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5510 strcpy(obj->data.tail.buffer, "Logfile Empty");
5511 snprintf(p, p_max_size, "Logfile Empty");
5513 } /* if fp == null */
5514 } /* cur_upd_time >= */
5516 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5519 #ifdef TCP_PORT_MONITOR
5522 /* grab a pointer to this port monitor */
5523 tcp_port_monitor_t * p_monitor =
5524 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
5525 obj->data.tcp_port_monitor.port_range_begin,
5526 obj->data.tcp_port_monitor.port_range_end );
5528 snprintf(p, p_max_size, "monitor not found");
5532 /* now grab the text of interest */
5533 if ( peek_tcp_port_monitor( p_monitor,
5534 obj->data.tcp_port_monitor.item,
5535 obj->data.tcp_port_monitor.connection_index,
5536 p, p_max_size ) != 0 )
5538 snprintf(p, p_max_size, "monitor peek error");
5547 iconv_converting = 1;
5548 iconv_selected = obj->a;
5553 iconv_converting = 0;
5559 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5561 OBJ(entropy_poolsize)
5563 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5567 double entropy_perc;
5568 entropy_perc = (double)cur->entropy.entropy_avail /
5569 (double)cur->entropy.poolsize;
5570 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5578 unsigned int a = strlen(p);
5581 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5583 size_t dummy1, dummy2;
5584 char *ptr = buff_in;
5587 dummy1 = dummy2 = a;
5589 strncpy(buff_in, p, P_MAX_SIZE);
5591 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5592 while (dummy1 > 0) {
5593 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5595 ERR("Iconv codeset conversion failed");
5600 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5611 double current_update_time, last_update_time;
5613 static void generate_text()
5615 struct information *cur = &info;
5623 current_update_time = get_time();
5626 /* fix diskio rates to b/s (use update_interval */
5627 diskio_read_value = diskio_read_value / update_interval;
5628 diskio_write_value = diskio_write_value / update_interval;
5629 diskio_value = diskio_value / update_interval;
5632 /* add things to the buffer */
5638 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5640 if (stuff_in_upper_case) {
5651 last_update_time = current_update_time;
5658 static void set_font()
5662 if (window.xftdraw != NULL) {
5663 XftDrawDestroy(window.xftdraw);
5665 window.xftdraw = XftDrawCreate(display, window.drawable,
5666 DefaultVisual(display,
5668 DefaultColormap(display,
5673 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5679 static inline int get_string_width(const char *s)
5682 return *s ? calc_text_width(s, strlen(s)) : 0;
5688 static inline int get_string_width_special(char *s)
5701 if (*p == SPECIAL_CHAR) {
5702 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5703 for (i = 0; i < strlen(p); i++) {
5704 *(p + i) = *(p + i + 1);
5706 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5707 width += specials[special_index+index].width;
5714 if (strlen(final) > 1) {
5715 width += calc_text_width(final, strlen(final));
5725 static void text_size_updater(char *s);
5727 int last_font_height;
5728 static void update_text_area()
5732 /* update text size if it isn't fixed */
5737 text_width = minimum_width;
5740 last_font_height = font_height();
5741 for_each_line(text_buffer, text_size_updater);
5743 if (text_height < minimum_height)
5744 text_height = minimum_height;
5745 if (text_width > maximum_width && maximum_width > 0)
5746 text_width = maximum_width;
5749 /* get text position on workarea */
5750 switch (text_alignment) {
5757 x = workarea[2] - text_width - gap_x;
5764 y = workarea[3] - text_height - gap_y;
5768 x = workarea[2] - text_width - gap_x;
5769 y = workarea[3] - text_height - gap_y;
5773 case NONE: // Let the WM manage the window
5784 if (own_window && !fixed_pos) {
5787 text_start_x = border_margin + 1;
5788 text_start_y = border_margin + 1;
5789 window.x = x - border_margin - 1;
5790 window.y = y - border_margin - 1;
5794 /* If window size doesn't match to workarea's size, then window
5795 * probably includes panels (gnome).
5796 * Blah, doesn't work on KDE. */
5797 if (workarea[2] != window.width
5798 || workarea[3] != window.height) {
5812 static int cur_x, cur_y; /* current x and y for drawing */
5813 static int draw_mode; /* FG, BG or OUTLINE */
5814 static long current_color;
5817 static void text_size_updater(char *s)
5821 /* get string widths and skip specials */
5824 if (*p == SPECIAL_CHAR) {
5826 w += get_string_width(s);
5829 if (specials[special_index].type == BAR
5830 || specials[special_index].type == GRAPH) {
5831 w += specials[special_index].width;
5832 if (specials[special_index].height > last_font_height) {
5833 last_font_height = specials[special_index].height;
5834 last_font_height += font_ascent();
5836 } else if (specials[special_index].type == OFFSET) {
5837 if (specials[special_index].arg > 0) {
5838 w += specials[special_index].arg;
5840 } else if (specials[special_index].type == VOFFSET) {
5841 last_font_height += specials[special_index].arg;
5842 } else if (specials[special_index].type == GOTO) {
5843 if (specials[special_index].arg > cur_x) {
5844 w = (int)specials[special_index].arg;
5846 } else if (specials[special_index].type == TAB) {
5847 int start = specials[special_index].arg;
5848 int step = specials[special_index].width;
5849 if (!step || step < 0)
5851 w += step - (cur_x - text_start_x - start) % step;
5852 } else if (specials[special_index].type == FONT) {
5853 selected_font = specials[special_index].font_added;
5854 if (font_height() > last_font_height) {
5855 last_font_height = font_height();
5864 w += get_string_width(s);
5865 if (w > text_width) {
5868 if (text_width > maximum_width && maximum_width) {
5869 text_width = maximum_width;
5872 text_height += last_font_height;
5873 last_font_height = font_height();
5877 static inline void set_foreground_color(long c)
5880 XSetForeground(display, window.gc, c);
5884 static void draw_string(const char *s)
5888 int i, i2, pos, width_of_s;
5891 width_of_s = get_string_width(s);
5892 if (out_to_console) {
5894 fflush(stdout); /* output immediately, don't buffer */
5896 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5897 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5898 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5902 snprintf(space, 2, " ");
5904 max = ((text_width - width_of_s) / get_string_width(space));
5907 * This code looks for tabs in the text and coverts them to spaces.
5908 * The trick is getting the correct number of spaces,
5909 * and not going over the window's size without forcing
5910 * the window larger.
5912 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5913 if (tmpstring1[i] == '\t') // 9 is ascii tab
5917 i2 < (8 - (1 + pos) % 8) && added <= max;
5920 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5921 fprintf(stderr,"buffer overrun detected\n");
5923 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5928 if (tmpstring1[i] != 9) {
5930 if ( pos > TEXT_BUFFER_SIZE-1 )
5931 fprintf(stderr,"buffer overrun detected\n");
5933 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5939 if (text_width == maximum_width) {
5940 /* this means the text is probably pushing the limit, so we'll chop it */
5941 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5942 tmpstring2[strlen(tmpstring2)-1] = '\0';
5952 c.pixel = current_color;
5953 XQueryColor(display, DefaultColormap(display, screen), &c);
5956 c2.color.red = c.red;
5957 c2.color.green = c.green;
5958 c2.color.blue = c.blue;
5959 c2.color.alpha = fonts[selected_font].font_alpha;
5961 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5962 cur_x, cur_y, (XftChar8 *) s,
5965 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5966 cur_x, cur_y, (XftChar8 *) s,
5972 XDrawString(display, window.drawable, window.gc,
5973 cur_x, cur_y, s, strlen(s));
5975 cur_x += width_of_s;
5977 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5980 long redmask, greenmask, bluemask;
5982 void set_up_gradient()
5985 colour_depth = DisplayPlanes(display, screen);
5989 if (colour_depth != 24 && colour_depth != 16) {
5990 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5996 for(i = (colour_depth / 3)-1; i>=0; i--) {
5998 greenmask |= 1 << i;
6001 if (colour_depth%3 == 1) {
6002 greenmask |= 1 << (colour_depth / 3);
6004 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
6005 greenmask = greenmask << (colour_depth / 3);
6008 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 */
6010 int red1, green1, blue1; // first colour
6011 int red2, green2, blue2; // second colour
6012 int red3 = 0, green3 = 0, blue3 = 0; // difference
6013 short redshift = (2*colour_depth / 3 + colour_depth%3);
6014 short greenshift = (colour_depth / 3);
6015 red1 = (first_colour & redmask) >> redshift;
6016 green1 = (first_colour & greenmask) >> greenshift;
6017 blue1 = first_colour & bluemask;
6018 red2 = (last_colour & redmask) >> redshift;
6019 green2 = (last_colour & greenmask) >> greenshift;
6020 blue2 = last_colour & bluemask;
6027 if (green1 > green2) {
6030 if (green1 < green2) {
6033 if (blue1 > blue2) {
6036 if (blue1 < blue2) {
6051 if (red1 > bluemask) {
6054 if (green1 > bluemask) {
6057 if (blue1 > bluemask) {
6060 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
6064 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
6065 if (colour_depth == 0) {
6068 int red1, green1, blue1; // first colour
6069 int red2, green2, blue2; // second colour
6070 long redshift = (2*colour_depth / 3 + colour_depth%3);
6071 long greenshift = (colour_depth / 3);
6072 int red3 = 0, green3 = 0, blue3 = 0; // difference
6073 red1 = (first_colour & redmask) >> redshift;
6074 green1 = (first_colour & greenmask) >> greenshift;
6075 blue1 = first_colour & bluemask;
6076 red2 = (last_colour & redmask) >> redshift;
6077 green2 = (last_colour & greenmask) >> greenshift;
6078 blue2 = last_colour & bluemask;
6079 red3 = abs(red1 - red2);
6080 green3 = abs(green1 - green2);
6081 blue3 = abs(blue1 - blue2);
6090 static void draw_line(char *s)
6094 cur_x = text_start_x;
6095 cur_y += font_ascent();
6097 short font_h = font_height();
6099 /* find specials and draw stuff */
6102 if (*p == SPECIAL_CHAR) {
6105 /* draw string before special */
6112 switch (specials[special_index].type) {
6113 case HORIZONTAL_LINE:
6116 specials[special_index].height;
6117 int mid = font_ascent() / 2;
6118 w = text_start_x + text_width -
6121 XSetLineAttributes(display,
6126 XDrawLine(display, window.drawable,
6137 specials[special_index].height;
6139 specials[special_index].arg;
6140 int mid = font_ascent() / 2;
6141 char ss[2] = { s, s };
6142 w = text_start_x + text_width -
6145 XSetLineAttributes(display,
6150 XSetDashes(display, window.gc, 0,
6152 XDrawLine(display, window.drawable,
6162 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
6166 specials[special_index].height;
6168 specials[special_index].arg;
6169 int by = cur_y - (font_ascent() / 2) - 1;
6170 if (h < font_height()) {
6173 w = specials[special_index].width;
6176 text_width - cur_x - 1;
6180 XSetLineAttributes(display,
6186 XDrawRectangle(display,
6190 XFillRectangle(display,
6194 w * bar_usage / 255,
6196 if (specials[special_index].
6198 && specials[special_index].
6202 [special_index].height;
6209 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
6213 specials[special_index].height;
6214 unsigned long last_colour = current_color;
6215 int by = cur_y - (font_ascent()/2) - 1;
6216 if (h < font_height()) {
6219 w = specials[special_index].width;
6221 w = text_start_x + text_width - cur_x - 1;
6224 if (draw_graph_borders) {
6225 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
6226 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
6228 XSetLineAttributes(display,
6235 int gradient_size = 0;
6236 float gradient_factor = 0;
6237 float gradient_update = 0;
6238 unsigned long tmpcolour = current_color;
6239 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
6240 tmpcolour = specials[special_index].last_colour;
6241 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
6242 gradient_factor = (float)gradient_size / (w - 2);
6244 for (i = w - 2; i > -1; i--) {
6245 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
6246 XSetForeground(display, window.gc, tmpcolour);
6247 gradient_update += gradient_factor;
6248 while (gradient_update > 0) {
6249 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
6253 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
6256 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 */
6258 if (specials[special_index].
6260 && specials[special_index].
6264 [special_index].height;
6266 /* if (draw_mode == BG) {
6267 set_foreground_color(default_bg_color);
6269 else if (draw_mode == OUTLINE) {
6270 set_foreground_color(default_out_color);
6272 set_foreground_color(default_fg_color);
6274 set_foreground_color(last_colour);
6280 int old = font_ascent();
6281 cur_y -= font_ascent();
6282 selected_font = specials[special_index].font_added;
6283 if (cur_y + font_ascent() < cur_y + old) {
6286 cur_y += font_ascent();
6292 if (draw_mode == FG)
6293 set_foreground_color(specials
6299 if (draw_mode == BG)
6300 set_foreground_color(specials
6306 if (draw_mode == OUTLINE)
6307 set_foreground_color(specials
6313 w += specials[special_index].arg;
6317 cur_y += specials[special_index].arg;
6321 if (specials[special_index].arg >= 0)
6322 cur_x = (int)specials[special_index].arg;
6327 int start = specials[special_index].arg;
6328 int step = specials[special_index].width;
6329 if (!step || step < 0)
6331 w = step - (cur_x - text_start_x - start) % step;
6337 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
6338 /*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);*/
6339 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6340 cur_x = pos_x - specials[special_index].arg;
6347 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
6348 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
6349 /*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);*/
6351 specials[special_index].arg)
6354 [special_index].arg;
6371 if (cur_y_add > 0) {
6373 cur_y -= font_descent();
6378 cur_y += font_descent();
6382 static void draw_text()
6385 cur_y = text_start_y;
6388 if (draw_borders && border_width > 0) {
6389 unsigned int b = (border_width + 1) / 2;
6391 if (stippled_borders) {
6393 { stippled_borders, stippled_borders };
6394 XSetLineAttributes(display, window.gc,
6395 border_width, LineOnOffDash,
6396 CapButt, JoinMiter);
6397 XSetDashes(display, window.gc, 0, ss, 2);
6399 XSetLineAttributes(display, window.gc,
6400 border_width, LineSolid,
6401 CapButt, JoinMiter);
6404 XDrawRectangle(display, window.drawable, window.gc,
6405 text_start_x - border_margin + b,
6406 text_start_y - border_margin + b,
6407 text_width + border_margin * 2 - 1 - b * 2,
6408 text_height + border_margin * 2 - 1 -
6415 for_each_line(text_buffer, draw_line);
6418 static void draw_stuff()
6422 if (draw_shades && !draw_outline) {
6425 set_foreground_color(default_bg_color);
6435 for (i = -1; i < 2; i++)
6436 for (j = -1; j < 2; j++) {
6437 if (i == 0 && j == 0)
6441 set_foreground_color(default_out_color);
6442 draw_mode = OUTLINE;
6449 set_foreground_color(default_fg_color);
6457 swap.swap_window = window.window;
6458 swap.swap_action = XdbeBackground;
6459 XdbeSwapBuffers(display, &swap, 1);
6465 static void clear_text(int exposures)
6469 return; /* The swap action is XdbeBackground, which clears */
6473 /* there is some extra space for borders and outlines */
6474 XClearArea(display, window.window,
6475 text_start_x - border_margin - 1,
6476 text_start_y - border_margin - 1,
6477 text_width + border_margin * 2 + 2,
6478 text_height + border_margin * 2 + 2,
6479 exposures ? True : 0);
6484 static int need_to_update;
6486 /* update_text() generates new text and clears old text area */
6487 static void update_text()
6496 static void main_loop()
6498 #ifdef SIGNAL_BLOCKING
6499 sigset_t newmask, oldmask;
6501 sigemptyset(&newmask);
6502 sigaddset(&newmask,SIGINT);
6503 sigaddset(&newmask,SIGTERM);
6504 sigaddset(&newmask,SIGUSR1);
6508 Region region = XCreateRegion();
6510 int event_base, error_base;
6511 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
6512 ERR("Xdamage extension unavailable");
6514 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
6515 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
6516 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
6517 #endif /* HAVE_XDAMAGE */
6521 while (total_run_times == 0 || info.looped < total_run_times) {
6524 #ifdef SIGNAL_BLOCKING
6525 /* block signals. we will inspect for pending signals later */
6526 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
6527 CRIT_ERR("unable to sigprocmask()");
6533 /* wait for X event or timeout */
6535 if (!XPending(display)) {
6540 update_interval - (get_time() -
6546 tv.tv_sec = (long) t;
6547 tv.tv_usec = (long) (t * 1000000) % 1000000;
6549 FD_SET(ConnectionNumber(display), &fdsr);
6552 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
6555 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
6560 ERR("can't select(): %s",
6571 if (need_to_update) {
6573 int wx = window.x, wy = window.y;
6581 /* resize window if it isn't right size */
6583 (text_width + border_margin * 2 + 1 !=
6585 || text_height + border_margin * 2 + 1 !=
6589 border_margin * 2 + 1;
6592 border_margin * 2 + 1;
6593 XResizeWindow(display,
6598 set_transparent_background(window.window);
6602 /* move window if it isn't in right position */
6605 || window.y != wy)) {
6606 XMoveWindow(display, window.window,
6607 window.x, window.y);
6617 r.x = text_start_x - border_margin;
6618 r.y = text_start_y - border_margin;
6619 r.width = text_width + border_margin * 2;
6620 r.height = text_height + border_margin * 2;
6621 XUnionRectWithRegion(&r, region, region);
6626 /* handle X events */
6628 while (XPending(display)) {
6630 XNextEvent(display, &ev);
6637 r.width = ev.xexpose.width;
6638 r.height = ev.xexpose.height;
6639 XUnionRectWithRegion(&r, region,
6645 case ReparentNotify:
6646 /* set background to ParentRelative for all parents */
6648 set_transparent_background(window.
6653 case ConfigureNotify:
6655 /* if window size isn't what expected, set fixed size */
6656 if (ev.xconfigure.width !=
6658 || ev.xconfigure.height !=
6660 if (window.width != 0
6661 && window.height != 0)
6664 /* clear old stuff before screwing up size and pos */
6670 if (XGetWindowAttributes(display, window.window, &attrs)) {
6685 border_margin * 2 - 1;
6688 border_margin * 2 - 1;
6689 if (text_width > maximum_width && maximum_width > 0)
6690 text_width = maximum_width;
6693 /* if position isn't what expected, set fixed pos, total_updates
6694 * avoids setting fixed_pos when window is set to weird locations
6696 /*if (total_updates >= 2 this is broken
6698 && (window.x != ev.xconfigure.x
6701 && (ev.xconfigure.x != 0
6702 || ev.xconfigure.y != 0)) {
6712 /* if an ordinary window with decorations */
6713 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6715 /* allow conky to hold input focus.*/
6720 /* forward the click to the desktop window */
6721 XUngrabPointer(display, ev.xbutton.time);
6722 ev.xbutton.window = window.desktop;
6723 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6724 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6732 /* if an ordinary window with decorations */
6733 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6735 /* allow conky to hold input focus.*/
6740 /* forward the release to the desktop window */
6741 ev.xbutton.window = window.desktop;
6742 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6751 if (ev.type == event_base + XDamageNotify) {
6752 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6753 XFixesSetRegion(display, part, &dev->area, 1);
6754 XFixesUnionRegion(display, region2, region2, part);
6756 #endif /* HAVE_XDAMAGE */
6761 XDamageSubtract(display, damage, region2, None);
6762 XFixesSetRegion(display, region2, 0, 0);
6763 #endif /* HAVE_XDAMAGE */
6765 /* XDBE doesn't seem to provide a way to clear the back buffer without
6766 * interfering with the front buffer, other than passing XdbeBackground
6767 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6768 * redraw the text even if it wasn't part of the exposed area. OTOH,
6769 * if we're not going to call draw_stuff at all, then no swap happens
6770 * and we can safely do nothing.
6773 if (!XEmptyRegion(region)) {
6777 r.x = text_start_x - border_margin;
6778 r.y = text_start_y - border_margin;
6779 r.width = text_width + border_margin * 2;
6780 r.height = text_height + border_margin * 2;
6781 XUnionRectWithRegion(&r, region, region);
6784 XSetRegion(display, window.gc, region);
6787 XftDrawSetClip(window.xftdraw, region);
6793 XDestroyRegion(region);
6794 region = XCreateRegion();
6798 #ifdef SIGNAL_BLOCKING
6799 /* unblock signals of interest and let handler fly */
6800 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6801 CRIT_ERR("unable to sigprocmask()");
6804 switch(g_signal_pending) {
6807 ERR("received SIGUSR1. reloading the config file.");
6814 ERR("received SIGINT or SIGTERM to terminate. bye!");
6817 XDestroyRegion(region);
6820 return; /* return from main_loop */
6825 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6826 * but didn't write any code to deal with it. if you don't want to
6827 * handle a signal, don't set a handler on it in the first place. */
6828 if (g_signal_pending)
6829 ERR("ignoring signal (%d)", g_signal_pending);
6836 #if defined(X11) && defined(HAVE_XDAMAGE)
6837 XDamageDestroy(display, damage);
6838 XFixesDestroyRegion(display, region2);
6839 XFixesDestroyRegion(display, part);
6840 XDestroyRegion(region);
6842 #endif /* X11 && HAVE_XDAMAGE */
6845 static void load_config_file(const char *);
6847 /* reload the config file */
6848 void reload_config(void)
6850 timed_thread_destroy_registered_threads ();
6852 if (info.cpu_usage) {
6853 free(info.cpu_usage);
6854 info.cpu_usage = NULL;
6863 if (info.mpd.title) {
6864 free(info.mpd.title);
6867 if (info.mpd.artist) {
6868 free(info.mpd.artist);
6869 info.mpd.artist = 0;
6871 if (info.mpd.album) {
6872 free(info.mpd.album);
6875 if (info.mpd.random) {
6876 free(info.mpd.random);
6877 info.mpd.random = 0;
6879 if (info.mpd.repeat) {
6880 free(info.mpd.repeat);
6881 info.mpd.repeat = 0;
6883 if (info.mpd.track) {
6884 free(info.mpd.track);
6887 if (info.mpd.name) {
6888 free(info.mpd.name);
6891 if (info.mpd.file) {
6892 free(info.mpd.file);
6895 if (info.mpd.status) {
6896 free(info.mpd.status);
6897 info.mpd.status = 0;
6905 #ifdef TCP_PORT_MONITOR
6906 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6909 if (current_config) {
6911 load_config_file(current_config);
6913 /* re-init specials array */
6914 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6915 ERR("failed to realloc specials array");
6920 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6923 #ifdef TCP_PORT_MONITOR
6924 info.p_tcp_port_monitor_collection = NULL;
6927 if (create_audacious_thread() !=0)
6928 CRIT_ERR("unable to create audacious thread!");
6929 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6931 extract_variable_text(text);
6940 timed_thread_destroy_registered_threads ();
6942 if (info.cpu_usage) {
6943 free(info.cpu_usage);
6944 info.cpu_usage = NULL;
6949 XdbeDeallocateBackBufferName(display, window.back_buffer);
6955 XDestroyWindow(display, window.window);
6956 XClearWindow(display, RootWindow(display, screen));
6962 XClearWindow(display, RootWindow(display, screen));
6967 XFreeGC(display, window.gc);
6971 free_text_objects(text_object_count, text_objects);
6972 text_object_count = 0;
6973 text_objects = NULL;
6978 free(current_config);
6980 #ifdef TCP_PORT_MONITOR
6981 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6982 info.p_tcp_port_monitor_collection = NULL;
6990 for(i=0;i<special_count;i++)
6991 if(specials[i].type == GRAPH)
6992 free(specials[i].graph);
6997 clear_diskio_stats();
7000 static int string_to_bool(const char *s)
7004 if (strcasecmp(s, "yes") == 0)
7006 if (strcasecmp(s, "true") == 0)
7008 if (strcasecmp(s, "1") == 0)
7013 static enum alignment string_to_alignment(const char *s)
7015 if (strcasecmp(s, "top_left") == 0)
7017 else if (strcasecmp(s, "top_right") == 0)
7019 else if (strcasecmp(s, "bottom_left") == 0)
7021 else if (strcasecmp(s, "bottom_right") == 0)
7022 return BOTTOM_RIGHT;
7023 else if (strcasecmp(s, "tl") == 0)
7025 else if (strcasecmp(s, "tr") == 0)
7027 else if (strcasecmp(s, "bl") == 0)
7029 else if (strcasecmp(s, "br") == 0)
7030 return BOTTOM_RIGHT;
7031 else if (strcasecmp(s, "none") == 0)
7038 static void set_default_configurations(void)
7040 fork_to_background = 0;
7041 total_run_times = 0;
7042 info.cpu_avg_samples = 2;
7043 info.net_avg_samples = 2;
7050 strcpy(info.mpd.host, "localhost");
7051 info.mpd.port = 6600;
7052 info.mpd.status = NULL;
7053 info.mpd.artist = NULL;
7054 info.mpd.album = NULL;
7055 info.mpd.title = NULL;
7056 info.mpd.random = NULL;
7057 info.mpd.track = NULL;
7058 info.mpd.name = NULL;
7059 info.mpd.file = NULL;
7062 info.xmms2.artist = NULL;
7063 info.xmms2.album = NULL;
7064 info.xmms2.title = NULL;
7065 info.xmms2.genre = NULL;
7066 info.xmms2.comment = NULL;
7067 info.xmms2.decoder = NULL;
7068 info.xmms2.transport = NULL;
7069 info.xmms2.url = NULL;
7070 info.xmms2.status = NULL;
7072 use_spacer = NO_SPACER;
7079 default_fg_color = WhitePixel(display, screen);
7080 default_bg_color = BlackPixel(display, screen);
7081 default_out_color = BlackPixel(display, screen);
7082 color0 = default_fg_color;
7083 color1 = default_fg_color;
7084 color2 = default_fg_color;
7085 color3 = default_fg_color;
7086 color4 = default_fg_color;
7087 color5 = default_fg_color;
7088 color6 = default_fg_color;
7089 color7 = default_fg_color;
7090 color8 = default_fg_color;
7091 color9 = default_fg_color;
7094 draw_graph_borders = 1;
7096 set_first_font("6x10");
7104 window.type=TYPE_NORMAL;
7106 strcpy(window.class_name, "Conky");
7108 sprintf(window.title,"Conky (%s)",info.uname_s.nodename);
7110 stippled_borders = 0;
7113 text_alignment = BOTTOM_LEFT;
7116 free(current_mail_spool);
7119 variable_substitute(MAIL_FILE, buf, 256);
7121 current_mail_spool = strdup(buf);
7125 update_interval = 3.0;
7126 info.music_player_interval = 1.0;
7127 stuff_in_upper_case = 0;
7129 #ifdef TCP_PORT_MONITOR
7130 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7134 static void load_config_file(const char *f)
7136 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7140 set_default_configurations();
7146 char buf[256], *p, *p2, *name, *value;
7148 if (fgets(buf, 256, fp) == NULL)
7153 /* break at comment */
7154 p2 = strchr(p, '#');
7159 while (*p && isspace((int) *p))
7162 continue; /* empty line */
7168 while (*p2 && !isspace((int) *p2))
7171 *p2 = '\0'; /* break at name's end */
7178 while (*p && isspace((int) *p))
7183 p2 = value + strlen(value);
7184 while (isspace((int) *(p2 - 1)))
7190 #define CONF2(a) if (strcasecmp(name, a) == 0)
7191 #define CONF(a) else CONF2(a)
7192 #define CONF3(a,b) \
7193 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
7197 CONF2("alignment") {
7199 int a = string_to_alignment(value);
7207 CONF("background") {
7208 fork_to_background = string_to_bool(value);
7212 CONF2("background") {
7213 fork_to_background = string_to_bool(value);
7217 CONF("border_margin") {
7219 border_margin = strtol(value, 0, 0);
7223 CONF("border_width") {
7225 border_width = strtol(value, 0, 0);
7231 color0 = get_x11_color(value);
7237 color1 = get_x11_color(value);
7243 color2 = get_x11_color(value);
7249 color3 = get_x11_color(value);
7255 color4 = get_x11_color(value);
7261 color5 = get_x11_color(value);
7267 color6 = get_x11_color(value);
7273 color7 = get_x11_color(value);
7279 color8 = get_x11_color(value);
7285 color9 = get_x11_color(value);
7289 CONF("default_color") {
7291 default_fg_color = get_x11_color(value);
7295 CONF3("default_shade_color", "default_shadecolor") {
7297 default_bg_color = get_x11_color(value);
7301 CONF3("default_outline_color", "default_outlinecolor") {
7303 default_out_color = get_x11_color(value);
7310 info.mail = parse_mail_args(IMAP, value);
7317 info.mail = parse_mail_args(POP3, value);
7325 strncpy(info.mpd.host, value, 127);
7331 info.mpd.port = strtol(value, 0, 0);
7332 if (info.mpd.port < 1
7333 || info.mpd.port > 0xffff)
7337 CONF("mpd_password") {
7339 strncpy(info.mpd.password, value, 127);
7344 CONF("music_player_interval") {
7346 info.music_player_interval = strtod(value, 0);
7351 CONF("sensor_device") {
7353 sensor_device = strtol(value, 0, 0);
7358 CONF("cpu_avg_samples") {
7360 cpu_avg_samples = strtol(value, 0, 0);
7361 if (cpu_avg_samples < 1
7362 || cpu_avg_samples > 14)
7371 CONF("net_avg_samples") {
7373 net_avg_samples = strtol(value, 0, 0);
7374 if (net_avg_samples < 1
7375 || net_avg_samples > 14)
7391 CONF("double_buffer") {
7392 use_xdbe = string_to_bool(value);
7396 CONF("override_utf8_locale") {
7397 utf8_mode = string_to_bool(value);
7400 CONF("draw_borders") {
7401 draw_borders = string_to_bool(value);
7403 CONF("draw_graph_borders") {
7404 draw_graph_borders = string_to_bool(value);
7406 CONF("draw_shades") {
7407 draw_shades = string_to_bool(value);
7409 CONF("draw_outline") {
7410 draw_outline = string_to_bool(value);
7413 CONF("out_to_console") {
7414 out_to_console = string_to_bool(value);
7416 CONF("use_spacer") {
7418 if (strcasecmp(value, "left") == 0) {
7419 use_spacer = LEFT_SPACER;
7420 } else if (strcasecmp(value, "right") == 0) {
7421 use_spacer = RIGHT_SPACER;
7422 } else if (strcasecmp(value, "none") == 0) {
7423 use_spacer = NO_SPACER;
7425 use_spacer = string_to_bool(value);
7426 ERR("use_spacer should have an argument of left, right, or"
7427 " none. '%s' seems to be some form of '%s', so"
7428 " defaulting to %s.", value,
7429 use_spacer ? "true" : "false",
7430 use_spacer ? "right" : "none");
7432 use_spacer = RIGHT_SPACER;
7434 use_spacer = NO_SPACER;
7438 ERR("use_spacer should have an argument. Defaulting to right.");
7439 use_spacer = RIGHT_SPACER;
7445 use_xft = string_to_bool(value);
7449 set_first_font(value);
7454 if (value && font_count >= 0)
7455 fonts[0].font_alpha = atof(value)
7464 if (string_to_bool(value))
7465 ERR("Xft not enabled");
7468 /* xftfont silently ignored when no Xft */
7471 /* xftalpha is silently ignored when no Xft */
7476 set_first_font(value);
7485 gap_x = atoi(value);
7491 gap_y = atoi(value);
7496 CONF("mail_spool") {
7499 variable_substitute(value, buf, 256);
7503 if (current_mail_spool)
7504 free(current_mail_spool);
7505 current_mail_spool = strdup(buf);
7511 CONF("minimum_size") {
7514 (value, "%d %d", &minimum_width,
7515 &minimum_height) != 2)
7518 &minimum_width) != 1)
7523 CONF("maximum_width") {
7525 if (sscanf(value, "%d", &maximum_width) != 1)
7531 CONF("no_buffers") {
7532 no_buffers = string_to_bool(value);
7534 CONF("top_cpu_separate") {
7535 cpu_separate = string_to_bool(value);
7537 CONF("short_units") {
7538 short_units = string_to_bool(value);
7540 CONF("pad_percents") {
7541 pad_percents = atoi(value);
7545 CONF("own_window") {
7547 own_window = string_to_bool(value);
7551 CONF("own_window_class") {
7554 memset(window.class_name,0,sizeof(window.class_name));
7555 strncpy(window.class_name, value, sizeof(window.class_name)-1);
7560 CONF("own_window_title") {
7563 memset(window.title,0,sizeof(window.title));
7564 strncpy(window.title, value, sizeof(window.title)-1);
7569 CONF("own_window_transparent") {
7571 set_transparent = string_to_bool(value);
7575 CONF("own_window_colour") {
7577 background_colour = get_x11_color(value);
7579 ERR("Invalid colour for own_window_colour (try omitting the '#' for hex colours");
7582 CONF("own_window_hints") {
7584 char *p_hint, *p_save;
7585 char delim[] = ", ";
7587 /* tokenize the value into individual hints */
7588 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
7590 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
7591 if (strncmp(p_hint,"undecorate",10) == 0)
7592 SET_HINT(window.hints,HINT_UNDECORATED);
7593 else if (strncmp(p_hint,"below",5) == 0)
7594 SET_HINT(window.hints,HINT_BELOW);
7595 else if (strncmp(p_hint,"above",5) == 0)
7596 SET_HINT(window.hints,HINT_ABOVE);
7597 else if (strncmp(p_hint,"sticky",6) == 0)
7598 SET_HINT(window.hints,HINT_STICKY);
7599 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
7600 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
7601 else if (strncmp(p_hint,"skip_pager",10) == 0)
7602 SET_HINT(window.hints,HINT_SKIP_PAGER);
7606 p_hint=strtok_r(NULL, delim, &p_save);
7608 while (p_hint!=NULL);
7613 CONF("own_window_type") {
7615 if (strncmp(value,"normal",6)==0)
7616 window.type = TYPE_NORMAL;
7617 else if (strncmp(value,"desktop",7)==0)
7618 window.type = TYPE_DESKTOP;
7619 else if (strncmp(value,"override",8)==0)
7620 window.type = TYPE_OVERRIDE;
7628 CONF("stippled_borders") {
7630 stippled_borders = strtol(value, 0, 0);
7632 stippled_borders = 4;
7636 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
7639 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
7641 CONF("update_interval") {
7643 update_interval = strtod(value, 0);
7646 if (info.music_player_interval == 0) {
7647 // default to update_interval
7648 info.music_player_interval = update_interval;
7651 CONF("total_run_times") {
7653 total_run_times = strtod(value, 0);
7658 stuff_in_upper_case = string_to_bool(value);
7660 CONF("max_specials") {
7662 max_specials = atoi(value);
7666 CONF("max_user_text") {
7668 max_user_text = atoi(value);
7672 CONF("text_buffer_size") {
7674 text_buffer_size = atoi(value);
7689 int l = strlen(text);
7690 if (fgets(buf, 256, fp) == NULL)
7693 realloc(text, l + strlen(buf)
7697 if (strlen(text) > max_user_text)
7701 text_lines = line + 1;
7704 #ifdef TCP_PORT_MONITOR
7705 CONF("max_port_monitor_connections")
7708 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7709 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
7711 /* an error. use default, warn and continue. */
7712 tcp_port_monitor_args.max_port_monitor_connections =
7713 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7716 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
7718 /* no error, just use default */
7719 tcp_port_monitor_args.max_port_monitor_connections =
7720 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7722 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
7727 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7736 if (info.music_player_interval == 0) {
7737 // default to update_interval
7738 info.music_player_interval = update_interval;
7743 /* : means that character before that takes an argument */
7744 static const char *getopt_string = "vVdt:u:i:hc:"
7756 static const struct option
7758 { "help", 0, NULL, 'h' },
7759 { "version", 0, NULL, 'V' },
7760 { "config", 1, NULL, 'c' },
7761 { "daemonize", 0, NULL, 'd' },
7763 { "alignment", 1, NULL, 'a'},
7764 { "font", 1, NULL, 'f'},
7766 { "own-window", 0, NULL, 'o'},
7769 { "double-buffer", 0, NULL, 'b'},
7771 { "window-id", 1, NULL, 'w'},
7773 { "text", 1, NULL, 't' },
7774 { "interval", 0, NULL, 'u' },
7778 int main(int argc, char **argv)
7780 struct sigaction act, oact;
7783 memset(&info, 0, sizeof(info));
7785 #ifdef TCP_PORT_MONITOR
7786 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7789 /* handle command line parameters that don't change configs */
7794 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7795 *s) || ((s = getenv("LANG")) && *s)) {
7796 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7798 ERR("malloc failed");
7800 for (x = 0; x < strlen(s); x++) {
7801 temp[x] = tolower(s[x]);
7804 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7810 if (!setlocale(LC_CTYPE, "")) {
7811 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7815 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
7828 free(current_config);
7829 current_config = strdup(optarg);
7834 "Usage: %s [OPTION]...\n"
7835 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7836 "window. Command line options will override configurations defined in config\n"
7838 " -V, --version version\n"
7839 " -c, --config=FILE config file to load\n"
7840 " -d, --daemonize daemonize, fork to background\n"
7841 " -h, --help help\n"
7843 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7844 " -f, --font=FONT font to use\n"
7846 " -o, --own-window create own window to draw\n"
7849 " -b, --double-buffer double buffer (prevents flickering)\n"
7851 " -w, --window-id=WIN_ID window id to draw\n"
7852 " -x X x position\n"
7853 " -y Y y position\n"
7855 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
7856 " -u, --interval=SECS update interval\n"
7857 " -i NUM number of times to update Conky\n",
7863 window.window = strtol(optarg, 0, 0);
7872 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7876 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
7878 if (!current_config) {
7879 /* load default config file */
7883 /* Try to use personal config file first */
7884 variable_substitute(CONFIG_FILE, buf, sizeof(buf));
7885 if (buf[0] && (fp=fopen(buf,"r"))) {
7886 current_config = strdup(buf);
7890 /* Try to use system config file if personal config not readable */
7891 if (!current_config && (fp=fopen(SYSTEM_CONFIG_FILE,"r"))) {
7892 current_config = strdup(SYSTEM_CONFIG_FILE);
7896 /* No readable config found */
7897 if (!current_config)
7898 CRIT_ERR("no readable personal or system-wide config file found");
7901 load_config_file(current_config);
7903 /* init specials array */
7904 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7905 ERR("failed to create specials array");
7908 if (current_mail_spool == NULL) {
7910 variable_substitute(MAIL_FILE, buf, 256);
7913 current_mail_spool = strdup(buf);
7917 /* handle other command line arguments */
7919 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
7920 || defined(__NetBSD__)
7921 optind = optreset = 1;
7926 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
7927 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7928 O_RDONLY, "kvm_open")) == NULL)
7929 CRIT_ERR( "cannot read kvm");
7933 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
7942 fork_to_background = 1;
7947 set_first_font(optarg);
7950 text_alignment = string_to_alignment(optarg);
7967 text = strdup(optarg);
7968 convert_escapes(text);
7972 update_interval = strtod(optarg, 0);
7973 if (info.music_player_interval == 0) {
7974 // default to update_interval
7975 info.music_player_interval = update_interval;
7980 total_run_times = strtod(optarg, 0);
7984 gap_x = atoi(optarg);
7988 gap_y = atoi(optarg);
8002 /* generate text and get initial size */
8003 extract_variable_text(text);
8009 if (fork_to_background) {
8013 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
8019 fprintf(stderr,"\n"); fflush(stderr);
8023 /* parent process */
8024 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
8031 update_text_area(); /* to get initial size of the window */
8035 text_width + border_margin * 2 + 1,
8036 text_height + border_margin * 2 + 1,
8037 set_transparent, background_colour, argv, argc);
8040 update_text_area(); /* to position text/window on screen */
8045 if (own_window && !fixed_pos) {
8046 XMoveWindow(display, window.window, window.x, window.y);
8049 set_transparent_background(window.window);
8060 /* Set signal handlers */
8061 act.sa_handler = signal_handler;
8062 sigemptyset(&act.sa_mask);
8065 act.sa_flags |= SA_RESTART;
8068 if ( sigaction(SIGINT,&act,&oact) < 0 ||
8069 sigaction(SIGUSR1,&act,&oact) < 0 ||
8070 sigaction(SIGTERM,&act,&oact) < 0 )
8072 ERR("error setting signal handler: %s", strerror(errno) );
8076 if (create_audacious_thread() !=0)
8077 CRIT_ERR("unable to create audacious thread!");
8078 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
8089 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8096 void signal_handler(int sig)
8098 /* signal handler is light as a feather, as it should be.
8099 * we will poll g_signal_pending with each loop of conky
8100 * and do any signal processing there, NOT here. */
8101 g_signal_pending=sig;