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;
169 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + fonts[selected_font].xftfont->descent) : \
170 (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent))
171 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent : fonts[selected_font].font->max_bounds.ascent)
172 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent : fonts[selected_font].font->max_bounds.descent)
176 #define font_height() (fonts[selected_font].font->max_bounds.ascent + fonts[selected_font].font->max_bounds.descent)
177 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
178 #define font_descent() fonts[selected_font].font->max_bounds.descent
182 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
185 static void set_font();
187 int addfont(const char *data_in)
189 if (font_count > MAX_FONTS) {
190 CRIT_ERR("you don't need that many fonts, sorry.");
193 if (font_count == 0) {
197 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
201 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count+1)));
203 CRIT_ERR("realloc in addfont");
205 if (strlen(data_in) < TEXT_BUFFER_SIZE) { // must account for null terminator
206 strncpy(fonts[font_count].name, data_in, TEXT_BUFFER_SIZE);
208 fonts[font_count].font_alpha = 0xffff;
211 CRIT_ERR("Oops...looks like something overflowed in addfont().");
216 void set_first_font(const char *data_in)
218 if (font_count < 0) {
219 if ((fonts = (struct font_list*)malloc(sizeof(struct font_list))) == NULL) {
224 if (strlen(data_in) > 1) {
225 strncpy(fonts[0].name, data_in, TEXT_BUFFER_SIZE-1);
227 fonts[0].font_alpha = 0xffff;
235 for (i = 0; i <= font_count; i++) {
238 XftFontClose(display, fonts[i].xftfont);
242 XFreeFont(display, fonts[i].font);
252 static void load_fonts()
255 for (i=0; i <= font_count; i++) {
259 /*if (fonts[i].xftfont != NULL && selected_font == 0) {
260 XftFontClose(display, fonts[i].xftfont);
262 if ((fonts[i].xftfont =
263 XftFontOpenName(display, screen, fonts[i].name)) != NULL)
266 ERR("can't load Xft font '%s'", fonts[i].name);
267 if ((fonts[i].xftfont =
268 XftFontOpenName(display, screen,
269 "courier-12")) != NULL)
272 ERR("can't load Xft font '%s'", "courier-12");
274 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
275 CRIT_ERR("can't load font '%s'", "fixed");
282 /* load normal font */
283 /* if (fonts[i].font != NULL)
284 XFreeFont(display, fonts[i].font);*/
286 if ((fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
287 ERR("can't load font '%s'", fonts[i].name);
288 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
289 CRIT_ERR("can't load font '%s'", "fixed");
290 printf("loaded fixed?\n");
298 /* default config file */
299 static char *current_config;
301 /* set to 1 if you want all text to be in uppercase */
302 static unsigned int stuff_in_upper_case;
304 /* Run how many times? */
305 static unsigned long total_run_times;
308 static int fork_to_background;
310 static int cpu_avg_samples, net_avg_samples;
314 /* Position on the screen */
315 static int text_alignment;
316 static int gap_x, gap_y;
319 static int draw_borders;
320 static int draw_graph_borders;
321 static int stippled_borders;
323 static int draw_shades, draw_outline;
325 static int border_margin, border_width;
327 static long default_fg_color, default_bg_color, default_out_color;
329 /* create own window or draw stuff to root? */
330 static int set_transparent = 0;
334 static int own_window = 0;
335 static int background_colour = 0;
336 /* fixed size/pos is set if wm/user changes them */
337 static int fixed_size = 0, fixed_pos = 0;
340 static int minimum_width, minimum_height;
341 static int maximum_width;
346 static int sensor_device;
349 static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
351 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
352 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
354 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
355 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
357 /* maximum size of individual text buffers, ie $exec buffer size */
358 unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
361 #define CODEPAGE_LENGTH 20
363 long iconv_count = 0;
364 char iconv_converting;
365 static iconv_t **iconv_cd = 0;
367 int register_iconv(iconv_t *new_iconv)
370 iconv_cd = realloc(iconv, sizeof(iconv_t *) * (iconv_count + 1));
372 iconv_cd = malloc(sizeof(iconv_t *));
375 CRIT_ERR("Out of memory");
377 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
378 if (!iconv_cd[iconv_count]) {
379 CRIT_ERR("Out of memory");
381 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
386 void free_iconv(void)
390 for (i = 0; i < iconv_count; i++) {
392 iconv_close(*iconv_cd[i]);
407 /* no buffers in used memory? */
410 /* pad percentages to decimals? */
411 static int pad_percents = 0;
413 #ifdef TCP_PORT_MONITOR
414 tcp_port_monitor_args_t tcp_port_monitor_args;
417 static char *text = 0;
420 static int total_updates;
423 static int blockdepth = 0;
424 static int if_jumped = 0;
425 static int blockstart[MAX_IF_BLOCK_DEPTH];
427 int check_contains(char *f, char *s)
430 FILE *where = fopen(f, "r");
432 char buf1[256], buf2[256];
433 while (fgets(buf1, 256, where)) {
434 sscanf(buf1, "%255s", buf2);
435 if (strstr(buf2, s)) {
442 ERR("Could not open the file");
449 static inline int calc_text_width(const char *s, int l)
455 XftTextExtentsUtf8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
457 XftTextExtents8(display, fonts[selected_font].xftfont, (FcChar8 *)s, l, &gi);
463 return XTextWidth(fonts[selected_font].font, s, l);
468 /* formatted text to render on screen, generated in generate_text(),
469 * drawn in draw_stuff() */
471 static char text_buffer[TEXT_BUFFER_SIZE * 4];
473 /* special stuff in text_buffer */
475 #define SPECIAL_CHAR '\x01'
503 unsigned long first_colour; // for graph gradient
504 unsigned long last_colour;
508 /* create specials array on heap instead of stack with introduction of max_specials */
509 static struct special_t *specials = NULL;
511 static unsigned int special_count;
513 static unsigned int special_index; /* used when drawing */
516 #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? */
518 static struct special_t *new_special(char *buf, int t)
520 if (special_count >= max_specials)
521 CRIT_ERR("too many special things in text");
523 buf[0] = SPECIAL_CHAR;
525 specials[special_count].type = t;
526 return &specials[special_count++];
529 long fwd_fcharfind(FILE* fp, char val, unsigned int step) {
532 unsigned int count = 0;
533 static char buf[BUFSZ];
534 long orig_pos = ftell(fp);
536 long buf_size = BUFSZ;
537 char* cur_found = NULL;
538 while(count < step) {
539 if(cur_found == NULL) {
540 buf_size = fread(buf, 1, buf_size, fp);
543 cur_found = memchr(buf+buf_pos, val, buf_size-buf_pos);
544 if(cur_found != NULL) {
545 buf_pos = cur_found-buf+1;
554 ret = ftell(fp) - buf_size + buf_pos - 1;
555 fseek(fp, orig_pos, SEEK_SET);
562 memrchr (const void *buffer, int c, size_t n)
564 const unsigned char *p = buffer;
566 for (p += n; n ; n--)
572 long rev_fcharfind(FILE* fp, char val, unsigned int step) {
575 unsigned int count = 0;
576 static char buf[BUFSZ];
577 long orig_pos = ftell(fp);
579 long file_pos = orig_pos;
580 long buf_size = BUFSZ;
582 while(count < step) {
584 if(file_pos > BUFSZ) {
585 fseek(fp, file_pos-BUFSZ, SEEK_SET);
589 fseek(fp, 0, SEEK_SET);
591 file_pos = ftell(fp);
592 buf_pos = fread(buf, 1, buf_size, fp);
599 if(cur_found != NULL) {
600 buf_pos = cur_found-buf;
609 fseek(fp, orig_pos, SEEK_SET);
611 ret = file_pos + buf_pos;
616 static void new_bar(char *buf, int w, int h, int usage)
618 struct special_t *s = new_special(buf, BAR);
619 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
624 static const char *scan_bar(const char *args, int *w, int *h)
626 *w = 0; /* zero width means all space that is available */
628 /* bar's argument is either height or height,width */
631 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
632 sscanf(args, "%d %n", h, &n);
639 static char *scan_font(const char *args)
648 static void new_font(char *buf, char * args) {
650 struct special_t *s = new_special(buf, FONT);
651 if (!s->font_added || strcmp(args, fonts[s->font_added].name)) {
652 int tmp = selected_font;
653 selected_font = s->font_added = addfont(args);
658 struct special_t *s = new_special(buf, FONT);
659 int tmp = selected_font;
660 selected_font = s->font_added = 0;
666 inline void graph_append(struct special_t *graph, double f)
668 if (!graph->scaled && f > graph->graph_scale) {
669 f = graph->graph_scale;
673 graph->graph_scale = 1;
675 graph->graph[0] = f; /* add new data */
676 for (i = graph->graph_width - 1; i > 0; i--) { /* shift all the data by 1 */
677 graph->graph[i] = graph->graph[i - 1];
678 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
679 graph->graph_scale = graph->graph[i]; /* check if we need to update the scale */
684 short colour_depth = 0;
685 void set_up_gradient();
687 /* precalculated: 31/255, and 63/255 */
688 #define CONST_8_TO_5_BITS 0.12156862745098
689 #define CONST_8_TO_6_BITS 0.247058823529412
691 /* adjust color values depending on color depth*/
692 static unsigned int adjust_colors(unsigned int color)
695 if (colour_depth == 0) {
698 if (colour_depth == 16) {
699 r = (color & 0xff0000) >> 16;
700 g = (color & 0xff00) >> 8;
702 color = (int)(r * CONST_8_TO_5_BITS) << 11;
703 color |= (int)(g * CONST_8_TO_6_BITS) << 5;
704 color |= (int)(b * CONST_8_TO_5_BITS);
709 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
711 struct special_t *s = new_special(buf, GRAPH);
713 if (s->graph == NULL) {
714 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
715 s->graph_width = s->width/* - 2*/; // subtract 2 for the box
717 s->graph_width = MAX_GRAPH_DEPTH - 2;
719 s->graph = malloc(s->graph_width * sizeof(double));
720 memset(s->graph, 0, s->graph_width * sizeof(double));
721 s->graph_scale = 100;
724 s->first_colour = adjust_colors(first_colour);
725 s->last_colour = adjust_colors(second_colour);
732 s->graph_width = s->width - 2; // subtract 2 for rectangle around
737 s->graph_scale = scale;
744 static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale)
746 *w = 0; /* zero width means all space that is available */
750 /* graph's argument is either height or height,width */
752 if (sscanf(args, "%*s %d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
753 if (sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour) < 4) {
755 if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour, scale) < 5) {
757 if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
760 if (sscanf(args, "%*s %x %x %i", first_colour, last_colour, scale) < 3) {
764 if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
767 if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) < 3) {
771 if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
774 if (sscanf(args, "%d,%d %i", h, w, scale) < 3) {
778 if (sscanf(args, "%d,%d", h, w) < 2) {
781 sscanf(args, "%*s %d,%d", h, w);
787 static inline void new_hr(char *buf, int a)
789 new_special(buf, HORIZONTAL_LINE)->height = a;
792 static inline void new_stippled_hr(char *buf, int a, int b)
794 struct special_t *s = new_special(buf, STIPPLED_HR);
799 static inline void new_fg(char *buf, long c)
801 new_special(buf, FG)->arg = c;
804 static inline void new_bg(char *buf, long c)
806 new_special(buf, BG)->arg = c;
809 static inline void new_outline(char *buf, long c)
811 new_special(buf, OUTLINE)->arg = c;
814 static inline void new_offset(char *buf, long c)
816 new_special(buf, OFFSET)->arg = c;
819 static inline void new_voffset(char *buf, long c)
821 new_special(buf, VOFFSET)->arg = c;
824 static inline void new_alignr(char *buf, long c)
826 new_special(buf, ALIGNR)->arg = c;
829 static inline void new_alignc(char *buf, long c)
831 new_special(buf, ALIGNC)->arg = c;
834 static inline void new_goto(char *buf, long c)
836 new_special(buf, GOTO)->arg = c;
839 static inline void new_tab(char *buf, int a, int b) {
840 struct special_t *s = new_special(buf, TAB);
845 /* quite boring functions */
847 static inline void for_each_line(char *b, void (*f) (char *))
851 for (ps = b, pe = b; *pe; pe++) {
864 static void convert_escapes(char *buf)
866 char *p = buf, *s = buf;
882 /* converts from bytes to human readable format (k, M, G, T) */
883 static void human_readable(long long a, char *buf, int size)
885 // Strange conditional due to possible overflows
886 if(a / 1024 / 1024 / 1024.0 > 1024.0){
887 snprintf(buf, size, "%.2fTiB", (a / 1024 / 1024 / 1024) / 1024.0);
889 else if (a >= 1024 * 1024 * 1024) {
890 snprintf(buf, size, "%.2fGiB", (a / 1024 / 1024) / 1024.0);
892 else if (a >= 1024 * 1024) {
893 double m = (a / 1024) / 1024.0;
895 snprintf(buf, size, "%.0fMiB", m);
897 snprintf(buf, size, "%.1fMiB", m);
898 } else if (a >= 1024)
899 snprintf(buf, size, "%LdKiB", a / (long long) 1024);
901 snprintf(buf, size, "%LdB", a);
906 enum text_object_type {
919 #endif /* !__OpenBSD__ */
941 OBJ_diskiograph_read,
942 OBJ_diskiograph_write,
977 #if defined(__linux__)
983 OBJ_i8k_left_fan_status,
984 OBJ_i8k_right_fan_status,
985 OBJ_i8k_left_fan_rpm,
986 OBJ_i8k_right_fan_rpm,
988 OBJ_i8k_buttons_status,
998 OBJ_wireless_bitrate,
1000 OBJ_wireless_link_qual,
1001 OBJ_wireless_link_qual_max,
1002 OBJ_wireless_link_qual_perc,
1003 OBJ_wireless_link_bar,
1004 #endif /* __linux__ */
1033 OBJ_running_processes,
1042 OBJ_temp1, /* i2c is used instead in these */
1062 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1064 OBJ_apm_battery_time,
1065 OBJ_apm_battery_life,
1066 #endif /* __FreeBSD__ __OpenBSD__ */
1068 OBJ_obsd_sensors_temp,
1069 OBJ_obsd_sensors_fan,
1070 OBJ_obsd_sensors_volt,
1073 #endif /* __OpenBSD__ */
1095 OBJ_music_player_interval,
1103 OBJ_xmms2_transport,
1118 OBJ_audacious_status,
1119 OBJ_audacious_title,
1120 OBJ_audacious_length,
1121 OBJ_audacious_length_seconds,
1122 OBJ_audacious_position,
1123 OBJ_audacious_position_seconds,
1124 OBJ_audacious_bitrate,
1125 OBJ_audacious_frequency,
1126 OBJ_audacious_channels,
1127 OBJ_audacious_filename,
1128 OBJ_audacious_playlist_length,
1129 OBJ_audacious_playlist_position,
1143 #ifdef TCP_PORT_MONITOR
1154 OBJ_entropy_poolsize,
1158 struct text_object {
1160 char *s; /* some string */
1161 int i; /* some integer */
1162 long l; /* some other integer */
1163 unsigned int sensor;
1164 struct net_stat *net;
1166 unsigned char loadavg[3];
1167 unsigned int cpu_index;
1168 struct mail_s *mail;
1176 char *tz; /* timezone variable */
1177 char *fmt; /* time display formatting */
1215 /* If not -1, a file descriptor to read from when
1216 * logfile is a FIFO. */
1233 timed_thread *p_timed_thread;
1239 #ifdef TCP_PORT_MONITOR
1241 in_port_t port_range_begin; /* starting port to monitor */
1242 in_port_t port_range_end; /* ending port to monitor */
1243 int item; /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1244 int connection_index; /* 0 to n-1 connections. */
1262 struct local_mail_s local_mail;
1267 unsigned int c, d, e;
1272 struct text_object_list {
1273 unsigned int text_object_count;
1274 struct text_object *text_objects;
1277 static unsigned int text_object_count;
1278 static struct text_object *text_objects;
1279 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
1281 #define MAXDATASIZE 1000
1285 struct mail_s* parse_mail_args(char type, const char *arg) {
1286 struct mail_s *mail;
1287 mail = malloc(sizeof(struct mail_s));
1288 memset(mail, 0, sizeof(struct mail_s));
1290 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass) != 3) {
1292 ERR("Scanning IMAP args failed");
1293 } else if (type == IMAP) {
1294 ERR("Scanning POP3 args failed");
1297 // see if password needs prompting
1298 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1299 int fp = fileno(stdin);
1300 struct termios term;
1301 tcgetattr(fp, &term);
1302 term.c_lflag &= ~ECHO;
1303 tcsetattr(fp, TCSANOW, &term);
1304 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1305 scanf("%128s", mail->pass);
1307 term.c_lflag |= ECHO;
1308 tcsetattr(fp, TCSANOW, &term);
1310 // now we check for optional args
1311 tmp = strstr(arg, "-i ");
1314 sscanf(tmp, "%f", &mail->interval);
1316 mail->interval = 300; // 5 minutes
1318 tmp = strstr(arg, "-p ");
1321 sscanf(tmp, "%lu", &mail->port);
1324 mail->port = 110; // default pop3 port
1325 } else if (type == IMAP) {
1326 mail->port = 143; // default imap port
1330 tmp = strstr(arg, "-f ");
1333 sscanf(tmp, "%s", mail->folder);
1335 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1338 tmp = strstr(arg, "-e ");
1342 if (tmp[0] == '\'') {
1343 len = strstr(tmp+1, "'") - tmp - 1;
1348 strncpy(mail->command, tmp+1, len);
1350 mail->command[0] = '\0';
1352 mail->p_timed_thread = NULL;
1356 void *imap_thread(struct mail_s* mail)
1358 int sockfd, numbytes;
1359 char recvbuf[MAXDATASIZE];
1360 char sendbuf[MAXDATASIZE];
1363 unsigned int old_unseen = UINT_MAX;
1364 unsigned int old_messages = UINT_MAX;
1365 struct stat stat_buf;
1367 struct sockaddr_in their_addr; // connector's address information
1368 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1369 herror("gethostbyname");
1374 ERR("Trying IMAP connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1376 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1379 goto next_iteration;
1382 their_addr.sin_family = AF_INET; // host byte order
1383 their_addr.sin_port = htons(mail->port); // short, network byte order
1384 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1385 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1388 (sockfd, (struct sockaddr *) &their_addr,
1389 sizeof(struct sockaddr)) == -1) {
1392 goto next_iteration;
1394 struct timeval timeout;
1397 timeout.tv_sec = 60; // 60 second timeout i guess
1398 timeout.tv_usec = 0;
1400 FD_SET(sockfd, &fdset);
1401 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1404 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1408 goto next_iteration;
1411 ERR("IMAP connection failed: timeout");
1413 goto next_iteration;
1415 recvbuf[numbytes] = '\0';
1416 if (strstr(recvbuf, "* OK") != recvbuf) {
1417 ERR("IMAP connection failed, probably not an IMAP server");
1419 goto next_iteration;
1421 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1422 strncat(sendbuf, mail->user,
1423 MAXDATASIZE - strlen(sendbuf) - 1);
1424 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1425 strncat(sendbuf, mail->pass,
1426 MAXDATASIZE - strlen(sendbuf) - 1);
1427 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1428 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1431 goto next_iteration;
1433 timeout.tv_sec = 60; // 60 second timeout i guess
1434 timeout.tv_usec = 0;
1436 FD_SET(sockfd, &fdset);
1437 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1440 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1444 goto next_iteration;
1447 recvbuf[numbytes] = '\0';
1448 if (strstr(recvbuf, "a1 OK") == NULL) {
1449 ERR("IMAP server login failed: %s", recvbuf);
1451 goto next_iteration;
1453 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1454 strncat(sendbuf, mail->folder,
1455 MAXDATASIZE - strlen(sendbuf) - 1);
1456 strncat(sendbuf, " (MESSAGES UNSEEN)\n",
1457 MAXDATASIZE - strlen(sendbuf) - 1);
1458 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1461 goto next_iteration;
1463 timeout.tv_sec = 60; // 60 second timeout i guess
1464 timeout.tv_usec = 0;
1466 FD_SET(sockfd, &fdset);
1467 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1470 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1474 goto next_iteration;
1477 recvbuf[numbytes] = '\0';
1478 if (strstr(recvbuf, "a2 OK") == NULL) {
1479 ERR("IMAP status failed: %s", recvbuf);
1481 goto next_iteration;
1483 // now we get the data
1484 reply = strstr(recvbuf, " (MESSAGES ");
1486 *strchr(reply, ')') = '\0';
1487 if (reply == NULL) {
1488 ERR("Error parsing IMAP response: %s", recvbuf);
1490 goto next_iteration;
1492 timed_thread_lock (mail->p_timed_thread);
1493 sscanf(reply, "MESSAGES %lu UNSEEN %lu",
1496 timed_thread_unlock (mail->p_timed_thread);
1498 strncpy(sendbuf, "a3 logout\n", MAXDATASIZE);
1499 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1502 goto next_iteration;
1504 timeout.tv_sec = 60; // 60 second timeout i guess
1505 timeout.tv_usec = 0;
1507 FD_SET(sockfd, &fdset);
1508 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1511 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1515 goto next_iteration;
1518 recvbuf[numbytes] = '\0';
1519 if (strstr(recvbuf, "a3 OK") == NULL) {
1520 ERR("IMAP logout failed: %s", recvbuf);
1522 goto next_iteration;
1524 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen || (mail->messages > old_messages && mail->unseen > 0))) { // new mail goodie
1525 if (system(mail->command) == -1) {
1530 old_unseen = mail->unseen;
1531 old_messages = mail->messages;
1533 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1534 /* if a valid socket, close it */
1536 if (timed_thread_test (mail->p_timed_thread))
1537 timed_thread_exit (mail->p_timed_thread);
1544 void *pop3_thread(struct mail_s *mail)
1546 int sockfd, numbytes;
1547 char recvbuf[MAXDATASIZE];
1548 char sendbuf[MAXDATASIZE];
1551 unsigned int old_unseen = UINT_MAX;
1552 struct stat stat_buf;
1554 struct sockaddr_in their_addr; // connector's address information
1555 if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
1556 herror("gethostbyname");
1561 ERR("Trying POP3 connection again for %s@%s (try %i/5)", mail->user, mail->host, fail + 1);
1563 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1566 goto next_iteration;
1569 their_addr.sin_family = AF_INET; // host byte order
1570 their_addr.sin_port = htons(mail->port); // short, network byte order
1571 their_addr.sin_addr = *((struct in_addr *) he->h_addr);
1572 memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
1575 (sockfd, (struct sockaddr *) &their_addr,
1576 sizeof(struct sockaddr)) == -1) {
1579 goto next_iteration;
1581 struct timeval timeout;
1584 timeout.tv_sec = 60; // 60 second timeout i guess
1585 timeout.tv_usec = 0;
1587 FD_SET(sockfd, &fdset);
1588 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1591 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1595 goto next_iteration;
1598 ERR("POP3 connection failed: timeout\n");
1600 goto next_iteration;
1602 recvbuf[numbytes] = '\0';
1603 if (strstr(recvbuf, "+OK ") != recvbuf) {
1604 ERR("POP3 connection failed, probably not a POP3 server");
1606 goto next_iteration;
1608 strncpy(sendbuf, "USER ", MAXDATASIZE);
1609 strncat(sendbuf, mail->user,
1610 MAXDATASIZE - strlen(sendbuf) - 1);
1611 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1612 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1613 perror("send USER");
1615 goto next_iteration;
1617 timeout.tv_sec = 60; // 60 second timeout i guess
1618 timeout.tv_usec = 0;
1620 FD_SET(sockfd, &fdset);
1621 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1624 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1626 perror("recv USER");
1628 goto next_iteration;
1631 recvbuf[numbytes] = '\0';
1632 if (strstr(recvbuf, "+OK ") == NULL) {
1633 ERR("POP3 server login failed: %s", recvbuf);
1635 goto next_iteration;
1637 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1638 strncat(sendbuf, mail->pass,
1639 MAXDATASIZE - strlen(sendbuf) - 1);
1640 strncat(sendbuf, "\n", MAXDATASIZE - strlen(sendbuf) - 1);
1641 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1642 perror("send PASS");
1644 goto next_iteration;
1646 timeout.tv_sec = 60; // 60 second timeout i guess
1647 timeout.tv_usec = 0;
1649 FD_SET(sockfd, &fdset);
1650 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1653 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1655 perror("recv PASS");
1657 goto next_iteration;
1660 recvbuf[numbytes] = '\0';
1661 if (strstr(recvbuf, "+OK ") == NULL) {
1662 ERR("POP3 server login failed: %s", recvbuf);
1664 goto next_iteration;
1666 strncpy(sendbuf, "STAT\n", MAXDATASIZE);
1667 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1668 perror("send STAT");
1670 goto next_iteration;
1672 timeout.tv_sec = 60; // 60 second timeout i guess
1673 timeout.tv_usec = 0;
1675 FD_SET(sockfd, &fdset);
1676 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1679 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1681 perror("recv STAT");
1683 goto next_iteration;
1686 recvbuf[numbytes] = '\0';
1687 if (strstr(recvbuf, "+OK ") == NULL) {
1688 ERR("POP3 status failed: %s", recvbuf);
1690 goto next_iteration;
1692 // now we get the data
1693 reply = recvbuf + 4;
1694 if (reply == NULL) {
1695 ERR("Error parsing POP3 response: %s", recvbuf);
1697 goto next_iteration;
1699 timed_thread_lock (mail->p_timed_thread);
1700 sscanf(reply, "%lu %lu", &mail->unseen,
1702 timed_thread_unlock (mail->p_timed_thread);
1704 strncpy(sendbuf, "QUIT\n", MAXDATASIZE);
1705 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1706 perror("send QUIT");
1708 goto next_iteration;
1710 timeout.tv_sec = 60; // 60 second timeout i guess
1711 timeout.tv_usec = 0;
1713 FD_SET(sockfd, &fdset);
1714 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1717 recv(sockfd, recvbuf, MAXDATASIZE - 1,
1719 perror("recv QUIT");
1721 goto next_iteration;
1724 recvbuf[numbytes] = '\0';
1725 if (strstr(recvbuf, "+OK") == NULL) {
1726 ERR("POP3 logout failed: %s", recvbuf);
1728 goto next_iteration;
1730 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) { // new mail goodie
1731 if (system(mail->command) == -1) {
1736 old_unseen = mail->unseen;
1738 if ((fstat(sockfd, &stat_buf)==0) && S_ISSOCK(stat_buf.st_mode))
1739 /* if a valid socket, close it */
1741 if (timed_thread_test (mail->p_timed_thread))
1742 timed_thread_exit (mail->p_timed_thread);
1750 void *threaded_exec(struct text_object *obj) {
1752 char *p2 = obj->data.texeci.buffer;
1753 FILE *fp = popen(obj->data.texeci.cmd,"r");
1754 timed_thread_lock (obj->data.texeci.p_timed_thread);
1755 int n2 = fread(p2, 1, text_buffer_size, fp);
1758 if (n2 && p2[n2 - 1] == '\n') {
1762 if (*p2 == '\001') {
1767 timed_thread_unlock (obj->data.texeci.p_timed_thread);
1768 if (timed_thread_test (obj->data.texeci.p_timed_thread))
1769 timed_thread_exit (obj->data.texeci.p_timed_thread);
1774 static struct text_object *new_text_object_internal()
1776 struct text_object *obj = malloc(sizeof(struct text_object));
1777 memset(obj, 0, sizeof(struct text_object));
1781 static void free_text_objects(unsigned int count, struct text_object *objs)
1784 for (i = 0; i < count; i++) {
1785 switch (objs[i].type) {
1788 close(objs[i].data.i);
1791 close(objs[i].data.i);
1794 close(objs[i].data.sysfs.fd);
1797 close(objs[i].data.sysfs.fd);
1800 close(objs[i].data.sysfs.fd);
1802 #endif /* !__OpenBSD__ */
1804 free(objs[i].data.s);
1807 free(objs[i].data.s);
1810 free(objs[i].data.tztime.tz);
1811 free(objs[i].data.tztime.fmt);
1814 free(objs[i].data.mboxscan.args);
1815 free(objs[i].data.mboxscan.output);
1819 free(objs[i].data.local_mail.box);
1824 case OBJ_imap_unseen:
1825 if (!objs[i].global_mode) {
1826 free(objs[i].data.mail);
1829 case OBJ_imap_messages:
1830 if (!objs[i].global_mode) {
1831 free(objs[i].data.mail);
1837 case OBJ_pop3_unseen:
1838 if (!objs[i].global_mode) {
1839 free(objs[i].data.mail);
1843 if (!objs[i].global_mode) {
1844 free(objs[i].data.mail);
1848 case OBJ_if_existing:
1849 case OBJ_if_mounted:
1850 case OBJ_if_running:
1851 free(objs[i].data.ifblock.s);
1852 free(objs[i].data.ifblock.str);
1855 free(objs[i].data.tail.logfile);
1856 free(objs[i].data.tail.buffer);
1860 free(objs[i].data.s);
1863 free(objs[i].data.s);
1866 free(objs[i].data.s);
1869 free(objs[i].data.s);
1872 free(objs[i].data.s);
1874 /* case OBJ_execibar:
1875 free(objs[i].data.s);
1877 case OBJ_execigraph:
1878 free(objs[i].data.s);
1881 case OBJ_iconv_start:
1886 case OBJ_xmms2_artist:
1887 if (info.xmms2.artist) {
1888 free(info.xmms2.artist);
1889 info.xmms2.artist = 0;
1892 case OBJ_xmms2_album:
1893 if (info.xmms2.album) {
1894 free(info.xmms2.album);
1895 info.xmms2.album = 0;
1898 case OBJ_xmms2_title:
1899 if (info.xmms2.title) {
1900 free(info.xmms2.title);
1901 info.xmms2.title = 0;
1904 case OBJ_xmms2_genre:
1905 if (info.xmms2.genre) {
1906 free(info.xmms2.genre);
1907 info.xmms2.genre = 0;
1910 case OBJ_xmms2_comment:
1911 if (info.xmms2.comment) {
1912 free(info.xmms2.comment);
1913 info.xmms2.comment = 0;
1916 case OBJ_xmms2_decoder:
1917 if (info.xmms2.decoder) {
1918 free(info.xmms2.decoder);
1922 case OBJ_xmms2_transport:
1923 if (info.xmms2.transport) {
1924 free(info.xmms2.transport);
1929 if (info.xmms2.url) {
1930 free(info.xmms2.url);
1934 case OBJ_xmms2_date:
1935 if (info.xmms2.date) {
1936 free(info.xmms2.date);
1937 info.xmms2.date = 0;
1940 case OBJ_xmms2_status:
1941 if (info.xmms2.status) {
1942 free(info.xmms2.status);
1943 info.xmms2.status = 0;
1946 case OBJ_xmms2_smart:
1947 if (info.xmms2.artist) {
1948 free(info.xmms2.artist);
1949 info.xmms2.artist = 0;
1951 if (info.xmms2.title) {
1952 free(info.xmms2.title);
1953 info.xmms2.title = 0;
1955 if (info.xmms2.url) {
1956 free(info.xmms2.url);
1962 case OBJ_bmpx_title:
1963 case OBJ_bmpx_artist:
1964 case OBJ_bmpx_album:
1965 case OBJ_bmpx_track:
1967 case OBJ_bmpx_bitrate:
1971 free(objs[i].data.rss.uri);
1972 free(objs[i].data.rss.action);
1978 free(objs[i].data.s);
1980 case OBJ_battery_time:
1981 free(objs[i].data.s);
1983 #endif /* !__OpenBSD__ */
1985 free(objs[i].data.execi.cmd);
1986 free(objs[i].data.execi.buffer);
1989 free(objs[i].data.texeci.cmd);
1990 free(objs[i].data.texeci.buffer);
1993 if (info.first_process) {
1994 free_all_processes();
1995 info.first_process = NULL;
1999 if (info.first_process) {
2000 free_all_processes();
2001 info.first_process = NULL;
2006 free(objs[i].data.hddtemp.dev);
2007 free(objs[i].data.hddtemp.addr);
2010 case OBJ_entropy_avail:
2011 case OBJ_entropy_poolsize:
2012 case OBJ_entropy_bar:
2019 if (info.mpd.title) {
2020 free(info.mpd.title);
2023 if (info.mpd.artist) {
2024 free(info.mpd.artist);
2025 info.mpd.artist = 0;
2027 if (info.mpd.album) {
2028 free(info.mpd.album);
2031 if (info.mpd.random) {
2032 free(info.mpd.random);
2033 info.mpd.random = 0;
2035 if (info.mpd.repeat) {
2036 free(info.mpd.repeat);
2037 info.mpd.repeat = 0;
2039 if (info.mpd.track) {
2040 free(info.mpd.track);
2043 if (info.mpd.name) {
2044 free(info.mpd.name);
2047 if (info.mpd.file) {
2048 free(info.mpd.file);
2051 if (info.mpd.status) {
2052 free(info.mpd.status);
2053 info.mpd.status = 0;
2057 //text_objects = NULL;
2058 //text_object_count = 0;
2061 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2066 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2067 *a = mixer_init(buf1);
2068 (void) scan_bar(arg + n, w, h);
2071 (void) scan_bar(arg, w, h);
2076 /* construct_text_object() creates a new text_object */
2077 static struct text_object *construct_text_object(const char *s, const char *arg, unsigned int object_count, struct text_object *text_objects, long line)
2079 //struct text_object *obj = new_text_object();
2080 struct text_object *obj = new_text_object_internal();
2083 #define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
2084 #define END ; } } else
2088 obj->type = OBJ_color;
2089 obj->data.l = get_x11_color(s);
2093 OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg);
2094 END OBJ(acpitempf, 0) obj->data.i = open_acpi_temperature(arg);
2095 END OBJ(acpiacadapter, 0)
2096 #endif /* !__OpenBSD__ */
2098 OBJ(freq, INFO_FREQ)
2100 END OBJ(freq, INFO_FREQ)
2107 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2109 obj->data.cpu_index=1;
2110 // ERR("freq: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2114 obj->data.cpu_index=atoi(&arg[0]);
2117 END OBJ(freq_g, INFO_FREQ)
2123 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2125 obj->data.cpu_index=1;
2126 // ERR("freq_g: Invalid CPU number or you don't have that many CPUs! Displaying the clock for CPU 1.");
2130 obj->data.cpu_index=atoi(&arg[0]);
2133 #if defined(__linux__)
2134 END OBJ(voltage_mv, 0)
2140 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2142 obj->data.cpu_index=1;
2143 // ERR("voltage_mv: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2147 obj->data.cpu_index=atoi(&arg[0]);
2150 END OBJ(voltage_v, 0)
2156 || (unsigned int)atoi(&arg[0])>info.cpu_count)
2158 obj->data.cpu_index=1;
2159 // ERR("voltage_v: Invalid CPU number or you don't have that many CPUs! Displaying voltage for CPU 1.");
2163 obj->data.cpu_index=atoi(&arg[0]);
2168 END OBJ(wireless_essid, INFO_NET)
2170 obj->data.net = get_net_stat(arg);
2172 CRIT_ERR("wireless_essid: needs an argument");
2173 END OBJ(wireless_mode, INFO_NET)
2175 obj->data.net = get_net_stat(arg);
2177 CRIT_ERR("wireless_mode: needs an argument");
2178 END OBJ(wireless_bitrate, INFO_NET)
2180 obj->data.net = get_net_stat(arg);
2182 CRIT_ERR("wireless_bitrate: needs an argument");
2183 END OBJ(wireless_ap, INFO_NET)
2185 obj->data.net = get_net_stat(arg);
2187 CRIT_ERR("wireless_ap: needs an argument");
2188 END OBJ(wireless_link_qual, INFO_NET)
2190 obj->data.net = get_net_stat(arg);
2192 CRIT_ERR("wireless_link_qual: needs an argument");
2193 END OBJ(wireless_link_qual_max, INFO_NET)
2195 obj->data.net = get_net_stat(arg);
2197 CRIT_ERR("wireless_link_qual_max: needs an argument");
2198 END OBJ(wireless_link_qual_perc, INFO_NET)
2200 obj->data.net = get_net_stat(arg);
2202 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2203 END OBJ(wireless_link_bar, INFO_NET)
2205 arg = scan_bar(arg, &obj->a, &obj->b);
2206 obj->data.net = get_net_stat(arg);
2208 CRIT_ERR("wireless_link_bar: needs an argument");
2209 #endif /* HAVE_IWLIB */
2211 #endif /* __linux__ */
2212 END OBJ(freq_dyn, 0);
2213 END OBJ(freq_dyn_g, 0);
2215 END OBJ(acpifan, 0);
2216 END OBJ(battery, 0);
2219 sscanf(arg, "%63s", bat);
2221 strcpy(bat, "BAT0");
2222 obj->data.s = strdup(bat);
2223 END OBJ(battery_time, 0);
2226 sscanf(arg, "%63s", bat);
2228 strcpy(bat, "BAT0");
2229 obj->data.s = strdup(bat);
2230 END OBJ(battery_percent, 0);
2233 sscanf(arg, "%63s", bat);
2235 strcpy(bat, "BAT0");
2236 obj->data.s = strdup(bat);
2237 END OBJ(battery_bar, 0);
2240 arg = scan_bar(arg, &obj->a, &obj->b);
2241 sscanf(arg, "%63s", bat);
2243 strcpy(bat, "BAT0");
2245 obj->data.s = strdup(bat);
2246 #endif /* !__OpenBSD__ */
2247 #if defined(__linux__)
2248 END OBJ(i8k_version, INFO_I8K)
2249 END OBJ(i8k_bios, INFO_I8K)
2250 END OBJ(i8k_serial, INFO_I8K)
2251 END OBJ(i8k_cpu_temp, INFO_I8K)
2252 END OBJ(i8k_cpu_tempf, INFO_I8K)
2253 END OBJ(i8k_left_fan_status, INFO_I8K)
2254 END OBJ(i8k_right_fan_status, INFO_I8K)
2255 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2256 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2257 END OBJ(i8k_ac_status, INFO_I8K)
2258 END OBJ(i8k_buttons_status, INFO_I8K)
2260 END OBJ(ibm_temps, 0)
2262 CRIT_ERR("ibm_temps: needs an argument");
2264 if (!isdigit(arg[0])
2266 || atoi(&arg[0]) >=8)
2269 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. Using 0 (CPU temp sensor).");
2271 obj->data.sensor = atoi(&arg[0]);
2272 END OBJ(ibm_volume, 0)
2273 END OBJ(ibm_brightness, 0)
2274 END OBJ(pb_battery, 0)
2275 if (arg && strcmp(arg, "status") == 0) {
2276 obj->data.i = PB_BATT_STATUS;
2277 } else if (arg && strcmp(arg, "percent") == 0) {
2278 obj->data.i = PB_BATT_PERCENT;
2279 } else if (arg && strcmp(arg, "time") == 0) {
2280 obj->data.i = PB_BATT_TIME;
2282 ERR("pb_battery: needs one argument: status, percent or time");
2287 #endif /* __linux__ */
2288 #if defined(__OpenBSD__)
2289 END OBJ(obsd_sensors_temp, 0);
2291 CRIT_ERR("obsd_sensors_temp: needs an argument");
2293 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2295 ERR("Invalid temperature sensor number!");
2297 obj->data.sensor = atoi(&arg[0]);
2298 END OBJ(obsd_sensors_fan, 0);
2300 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor number)");
2302 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2304 ERR("Invalid fan sensor number!");
2306 obj->data.sensor = atoi(&arg[0]);
2307 END OBJ(obsd_sensors_volt, 0);
2309 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor number)");
2311 if(!isdigit(arg[0]) || atoi(&arg[0]) < 0 || atoi(&arg[0]) > OBSD_MAX_SENSORS-1) {
2313 ERR("Invalid voltage sensor number!");
2315 obj->data.sensor = atoi(&arg[0]);
2316 END OBJ(obsd_vendor, 0);
2317 END OBJ(obsd_product, 0);
2318 #endif /* __OpenBSD__ */
2319 END OBJ(buffers, INFO_BUFFERS)
2320 END OBJ(cached, INFO_BUFFERS)
2321 END OBJ(cpu, INFO_CPU)
2323 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2324 obj->data.cpu_index = atoi(&arg[3]);
2326 } else {obj->data.cpu_index = 0; }
2328 obj->data.cpu_index = 0;
2330 END OBJ(cpubar, INFO_CPU)
2332 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2333 obj->data.cpu_index = atoi(&arg[3]);
2336 else {obj->data.cpu_index = 0;}
2337 (void) scan_bar(arg, &obj->a, &obj->b);
2339 (void) scan_bar(arg, &obj->a, &obj->b);
2340 obj->data.cpu_index = 0;
2342 END OBJ(cpugraph, INFO_CPU)
2344 if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
2345 obj->data.cpu_index = atoi(&arg[3]);
2348 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2350 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2351 obj->data.cpu_index = 0;
2353 END OBJ(diskio, INFO_DISKIO)
2354 END OBJ(diskio_read, INFO_DISKIO)
2355 END OBJ(diskio_write, INFO_DISKIO)
2356 END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2357 END OBJ(diskiograph_read, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2358 END OBJ(diskiograph_write, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2361 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2364 obj->data.l = color0;
2366 obj->data.l = color1;
2368 obj->data.l = color2;
2370 obj->data.l = color3;
2372 obj->data.l = color4;
2374 obj->data.l = color5;
2376 obj->data.l = color6;
2378 obj->data.l = color7;
2380 obj->data.l = color8;
2382 obj->data.l = color9;
2384 obj->data.s = scan_font(arg);
2385 END OBJ(downspeed, INFO_NET)
2387 obj->data.net = get_net_stat(arg);
2390 CRIT_ERR("downspeed needs argument");
2392 END OBJ(downspeedf, INFO_NET)
2394 obj->data.net = get_net_stat(arg);
2397 CRIT_ERR("downspeedf needs argument");
2399 END OBJ(downspeedgraph, INFO_NET)
2400 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2402 sscanf(arg, "%63s %*i,%*i %*i", buf);
2403 obj->data.net = get_net_stat(buf);
2404 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
2405 if (sscanf(arg, "%*s %d,%d", &obj->b, &obj->a) <= 1) {
2412 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos = object_count;
2413 blockstart[blockdepth - 1] = object_count;
2414 obj->data.ifblock.pos = object_count + 2;
2416 ERR("$else: no matching $if_*");
2421 text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
2423 ERR("$endif: no matching $if_*");
2426 OBJ(image, 0) obj->data.s = strdup(arg ? arg : "");
2429 OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
2430 END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
2431 END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
2432 END OBJ(execibar, 0) unsigned int n;
2433 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2435 ERR("${execibar <interval> command}");
2436 obj->type = OBJ_text;
2437 snprintf(buf, 256, "${%s}", s);
2438 obj->data.s = strdup(buf);
2440 obj->data.execi.cmd = strdup(arg + n);
2442 END OBJ(execigraph, 0) unsigned int n;
2443 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2445 ERR("${execigraph <interval> command}");
2446 obj->type = OBJ_text;
2447 snprintf(buf, 256, "${%s}", s);
2448 obj->data.s = strdup(buf);
2450 obj->data.execi.cmd = strdup(arg + n);
2452 END OBJ(execi, 0) unsigned int n;
2453 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2455 ERR("${execi <interval> command}");
2456 obj->type = OBJ_text;
2457 snprintf(buf, 256, "${%s}", s);
2458 obj->data.s = strdup(buf);
2460 obj->data.execi.cmd = strdup(arg + n);
2461 obj->data.execi.buffer =
2462 (char *) calloc(1, text_buffer_size);
2464 END OBJ(texeci, 0) unsigned int n;
2465 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2467 ERR("${texeci <interval> command}");
2468 obj->type = OBJ_text;
2469 snprintf(buf, 256, "${%s}", s);
2470 obj->data.s = strdup(buf);
2472 obj->data.texeci.cmd = strdup(arg + n);
2473 obj->data.texeci.buffer =
2474 (char *) calloc(1, text_buffer_size);
2476 obj->data.texeci.p_timed_thread = NULL;
2477 END OBJ(pre_exec, 0) obj->type = OBJ_text;
2479 FILE *fp = popen(arg, "r");
2483 n = fread(buf, 1, 2048, fp);
2486 if (n && buf[n - 1] == '\n')
2491 obj->data.s = strdup(buf);
2493 obj->data.s = strdup("");
2496 OBJ(fs_bar, INFO_FS) obj->data.fsbar.h = 4;
2497 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2499 while (isspace(*arg))
2505 obj->data.fsbar.fs = prepare_fs_stat(arg);
2506 END OBJ(fs_bar_free, INFO_FS) obj->data.fsbar.h = 4;
2509 if (sscanf(arg, "%d %n", &obj->data.fsbar.h, &n) >= 1)
2513 obj->data.fsbar.fs = prepare_fs_stat(arg);
2514 END OBJ(fs_free, INFO_FS) if (!arg)
2516 obj->data.fs = prepare_fs_stat(arg);
2517 END OBJ(fs_used_perc, INFO_FS) if (!arg)
2519 obj->data.fs = prepare_fs_stat(arg);
2520 END OBJ(fs_free_perc, INFO_FS) if (!arg)
2522 obj->data.fs = prepare_fs_stat(arg);
2523 END OBJ(fs_size, INFO_FS) if (!arg)
2525 obj->data.fs = prepare_fs_stat(arg);
2526 END OBJ(fs_used, INFO_FS) if (!arg)
2528 obj->data.fs = prepare_fs_stat(arg);
2529 END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
2530 END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
2531 END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
2535 ERR("goto needs arguments");
2536 obj->type = OBJ_text;
2537 obj->data.s = strdup("${goto}");
2541 obj->data.i = atoi(arg);
2546 if (sscanf(arg, "%d %d", &a, &b) != 2)
2547 sscanf(arg, "%d", &b);
2551 obj->data.pair.a = a;
2552 obj->data.pair.b = b;
2555 END OBJ(i2c, INFO_SYSFS)
2556 char buf1[64], buf2[64];
2560 ERR("i2c needs arguments");
2561 obj->type = OBJ_text;
2562 //obj->data.s = strdup("${i2c}");
2566 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2567 /* if scanf couldn't read three values, read type and num and use default device */
2568 sscanf(arg, "%63s %d", buf2, &n);
2569 obj->data.sysfs.fd =
2570 open_i2c_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2571 strncpy(obj->data.sysfs.type, buf2, 63);
2573 obj->data.sysfs.fd =
2574 open_i2c_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2575 strncpy(obj->data.sysfs.type, buf2, 63);
2578 END OBJ(platform, INFO_SYSFS)
2579 char buf1[64], buf2[64];
2583 ERR("platform needs arguments");
2584 obj->type = OBJ_text;
2588 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2589 /* if scanf couldn't read three values, read type and num and use default device */
2590 sscanf(arg, "%63s %d", buf2, &n);
2591 obj->data.sysfs.fd =
2592 open_platform_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2593 strncpy(obj->data.sysfs.type, buf2, 63);
2595 obj->data.sysfs.fd =
2596 open_platform_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2597 strncpy(obj->data.sysfs.type, buf2, 63);
2600 END OBJ(hwmon, INFO_SYSFS)
2601 char buf1[64], buf2[64];
2605 ERR("hwmon needs argumanets");
2606 obj->type = OBJ_text;
2610 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
2611 /* if scanf couldn't read three values, read type and num and use default device */
2612 sscanf(arg, "%63s %d", buf2, &n);
2613 obj->data.sysfs.fd =
2614 open_hwmon_sensor(0, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2615 strncpy(obj->data.sysfs.type, buf2, 63);
2617 obj->data.sysfs.fd =
2618 open_hwmon_sensor(buf1, buf2, n, &obj->data.sysfs.arg, obj->data.sysfs.devtype);
2619 strncpy(obj->data.sysfs.type, buf2, 63);
2621 #endif /* !__OpenBSD__ */
2623 END OBJ(top, INFO_TOP)
2627 ERR("top needs arguments");
2628 obj->type = OBJ_text;
2629 //obj->data.s = strdup("${top}");
2632 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2633 if (strcmp(buf, "name") == 0) {
2634 obj->data.top.type = TOP_NAME;
2635 } else if (strcmp(buf, "cpu") == 0) {
2636 obj->data.top.type = TOP_CPU;
2637 } else if (strcmp(buf, "pid") == 0) {
2638 obj->data.top.type = TOP_PID;
2639 } else if (strcmp(buf, "mem") == 0) {
2640 obj->data.top.type = TOP_MEM;
2641 } else if (strcmp(buf, "time") == 0) {
2642 obj->data.top.type = TOP_TIME;
2644 ERR("invalid arg for top");
2647 if (n < 1 || n > 10) {
2648 CRIT_ERR("invalid arg for top");
2651 obj->data.top.num = n - 1;
2655 ERR("invalid args given for top");
2658 END OBJ(top_mem, INFO_TOP)
2662 ERR("top_mem needs arguments");
2663 obj->type = OBJ_text;
2664 obj->data.s = strdup("${top_mem}");
2667 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
2668 if (strcmp(buf, "name") == 0) {
2669 obj->data.top.type = TOP_NAME;
2670 } else if (strcmp(buf, "cpu") == 0) {
2671 obj->data.top.type = TOP_CPU;
2672 } else if (strcmp(buf, "pid") == 0) {
2673 obj->data.top.type = TOP_PID;
2674 } else if (strcmp(buf, "mem") == 0) {
2675 obj->data.top.type = TOP_MEM;
2676 } else if (strcmp(buf, "time") == 0) {
2677 obj->data.top.type = TOP_TIME;
2679 ERR("invalid arg for top");
2682 if (n < 1 || n > 10) {
2683 CRIT_ERR("invalid arg for top");
2686 obj->data.top.num = n - 1;
2690 ERR("invalid args given for top");
2693 END OBJ(addr, INFO_NET)
2695 obj->data.net = get_net_stat(arg);
2698 CRIT_ERR("addr needs argument");
2705 ERR("tail needs arguments");
2706 obj->type = OBJ_text;
2707 obj->data.s = strdup("${tail}");
2710 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2711 if (n1 < 1 || n1 > 30) {
2712 CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
2718 obj->data.tail.fd = -1;
2720 if (stat(buf, &st) == 0) {
2721 if (S_ISFIFO(st.st_mode)) {
2722 fd = open(buf, O_RDONLY|O_NONBLOCK);
2725 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2727 obj->data.tail.fd = fd;
2731 fp = fopen(buf, "r");
2734 if (fp || obj->data.tail.fd != -1) {
2735 obj->data.tail.logfile =
2736 malloc(text_buffer_size);
2737 strcpy(obj->data.tail.logfile, buf);
2738 obj->data.tail.wantedlines = n1;
2739 obj->data.tail.interval =
2740 update_interval * 2;
2742 if (obj->data.tail.fd == -1)
2746 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2749 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2750 if (n1 < 1 || n1 > 30) {
2752 ("invalid arg for tail, number of lines must be between 1 and 30");
2754 } else if (n2 < 1 || n2 < update_interval) {
2756 ("invalid arg for tail, interval must be greater than 0 and Conky's interval");
2762 obj->data.tail.fd = -1;
2764 if (stat(buf, &st) == 0) {
2765 if (S_ISFIFO(st.st_mode)) {
2766 fd = open(buf, O_RDONLY|O_NONBLOCK);
2769 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2771 obj->data.tail.fd = fd;
2774 fp = fopen(buf, "r");
2777 if (fp || obj->data.tail.fd != -1) {
2778 obj->data.tail.logfile =
2779 malloc(text_buffer_size);
2780 strcpy(obj->data.tail.logfile, buf);
2781 obj->data.tail.wantedlines = n1;
2782 obj->data.tail.interval = n2;
2784 if (obj->data.tail.fd == -1)
2788 CRIT_ERR("tail logfile does not exist, or you do not have correct permissions");
2794 ERR("invalid args given for tail");
2797 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2802 ERR("head needs arguments");
2803 obj->type = OBJ_text;
2804 obj->data.s = strdup("${head}");
2807 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
2808 if (n1 < 1 || n1 > 30) {
2809 CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
2813 fp = fopen(buf, "r");
2815 obj->data.tail.logfile =
2816 malloc(text_buffer_size);
2817 strcpy(obj->data.tail.logfile, buf);
2818 obj->data.tail.wantedlines = n1;
2819 obj->data.tail.interval =
2820 update_interval * 2;
2824 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2827 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
2828 if (n1 < 1 || n1 > 30) {
2830 ("invalid arg for head, number of lines must be between 1 and 30");
2832 } else if (n2 < 1 || n2 < update_interval) {
2834 ("invalid arg for head, interval must be greater than 0 and Conky's interval");
2838 fp = fopen(buf, "r");
2840 obj->data.tail.logfile =
2841 malloc(text_buffer_size);
2842 strcpy(obj->data.tail.logfile, buf);
2843 obj->data.tail.wantedlines = n1;
2844 obj->data.tail.interval = n2;
2848 CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
2854 ERR("invalid args given for head");
2857 obj->data.tail.buffer = malloc(text_buffer_size * 20); /* asumming all else worked */
2858 END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
2860 r = sscanf(arg, "%d %d %d", &a, &b, &c);
2861 if (r >= 3 && (c < 1 || c > 3))
2863 if (r >= 2 && (b < 1 || b > 3))
2865 if (r >= 1 && (a < 1 || a > 3))
2868 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2869 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
2870 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
2871 END OBJ(if_empty, 0)
2872 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2873 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2876 ERR("if_empty needs an argument");
2877 obj->data.ifblock.s = 0;
2879 obj->data.ifblock.s = strdup(arg);
2880 blockstart[blockdepth] = object_count;
2881 obj->data.ifblock.pos = object_count + 2;
2883 END OBJ(if_existing, 0)
2884 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2885 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2888 ERR("if_existing needs an argument or two");
2889 obj->data.ifblock.s = NULL;
2890 obj->data.ifblock.str = NULL;
2892 char buf1[256], buf2[256];
2893 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
2895 obj->data.ifblock.s = strdup(buf1);
2896 obj->data.ifblock.str = NULL;
2898 obj->data.ifblock.s = strdup(buf1);
2899 obj->data.ifblock.str = strdup(buf2);
2902 blockstart[blockdepth] = object_count;
2903 obj->data.ifblock.pos = object_count + 2;
2905 END OBJ(if_mounted, 0)
2906 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2907 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2910 ERR("if_mounted needs an argument");
2911 obj->data.ifblock.s = 0;
2913 obj->data.ifblock.s = strdup(arg);
2914 blockstart[blockdepth] = object_count;
2915 obj->data.ifblock.pos = object_count + 2;
2917 END OBJ(if_running, 0)
2918 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2919 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2923 snprintf(buf, 256, "pidof %s >/dev/null", arg);
2924 obj->data.ifblock.s = strdup(buf);
2926 ERR("if_running needs an argument");
2927 obj->data.ifblock.s = 0;
2929 blockstart[blockdepth] = object_count;
2930 obj->data.ifblock.pos = object_count + 2;
2936 char box[256], dst[256];
2940 strncpy(box, MAIL_FILE, sizeof(box));
2943 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2945 strncpy(box, arg, sizeof(box));
2949 variable_substitute(box, dst, sizeof(dst));
2950 obj->data.local_mail.box = strdup(dst);
2951 obj->data.local_mail.interval = n1;
2954 END OBJ(mboxscan, 0)
2955 obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
2956 obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
2957 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
2958 obj->data.mboxscan.output[0] = 1;
2959 strncpy(obj->data.mboxscan.args, arg, TEXT_BUFFER_SIZE);
2960 END OBJ(mem, INFO_MEM)
2961 END OBJ(memmax, INFO_MEM)
2962 END OBJ(memperc, INFO_MEM)
2963 END OBJ(membar, INFO_MEM)
2964 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
2965 END OBJ(memgraph, INFO_MEM)
2966 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
2967 END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
2968 END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
2969 END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
2970 END OBJ(mixerbar, INFO_MIXER)
2971 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2972 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2973 END OBJ(mixerlbar, INFO_MIXER)
2974 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2975 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2976 END OBJ(mixerrbar, INFO_MIXER)
2977 scan_mixer_bar(arg, &obj->data.mixerbar.l,
2978 &obj->data.mixerbar.w, &obj->data.mixerbar.h);
2982 char box[256], dst[256];
2986 strncpy(box, MAIL_FILE, sizeof(box));
2989 if (sscanf(arg, "%s %f", box, &n1) != 2) {
2991 strncpy(box, arg, sizeof(box));
2995 variable_substitute(box, dst, sizeof(dst));
2996 obj->data.local_mail.box = strdup(dst);
2997 obj->data.local_mail.interval = n1;
3000 END OBJ(nodename, 0)
3001 END OBJ(processes, INFO_PROCS)
3002 END OBJ(running_processes, INFO_RUN_PROCS)
3003 END OBJ(shadecolor, 0)
3005 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
3007 END OBJ(outlinecolor, 0)
3009 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
3011 END OBJ(stippled_hr, 0)
3013 int a = stippled_borders, b = 1;
3015 if (sscanf(arg, "%d %d", &a, &b) != 2)
3016 sscanf(arg, "%d", &b);
3020 obj->data.pair.a = a;
3021 obj->data.pair.b = b;
3023 END OBJ(swap, INFO_MEM)
3024 END OBJ(swapmax, INFO_MEM)
3025 END OBJ(swapperc, INFO_MEM)
3026 END OBJ(swapbar, INFO_MEM)
3027 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3030 END OBJ(temp1, INFO_SYSFS) obj->type = OBJ_i2c;
3031 obj->data.sysfs.fd =
3032 open_i2c_sensor(0, "temp", 1, &obj->data.sysfs.arg,
3033 obj->data.sysfs.devtype);
3034 END OBJ(temp2, INFO_SYSFS) obj->type = OBJ_i2c;
3035 obj->data.sysfs.fd =
3036 open_i2c_sensor(0, "temp", 2, &obj->data.sysfs.arg,
3037 obj->data.sysfs.devtype);
3039 END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
3040 END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
3042 char buf1[256], buf2[256], *fmt, *tz;
3045 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3054 obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
3055 obj->data.tztime.tz = tz ? strdup(tz) : NULL;
3057 END OBJ(iconv_start, 0)
3058 if (iconv_converting) {
3059 CRIT_ERR("You must stop your last iconv conversion before starting another");
3062 char iconv_from[CODEPAGE_LENGTH];
3063 char iconv_to[CODEPAGE_LENGTH];
3064 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3065 CRIT_ERR("Invalid arguments for iconv_start");
3068 new_iconv = iconv_open(iconv_to, iconv_from);
3069 if (new_iconv == (iconv_t)(-1)) {
3070 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3072 obj->a = register_iconv(&new_iconv);
3073 iconv_converting = 1;
3077 CRIT_ERR("Iconv requires arguments");
3079 END OBJ(iconv_stop, 0)
3080 iconv_converting = 0;
3083 END OBJ(totaldown, INFO_NET)
3085 obj->data.net = get_net_stat(arg);
3088 CRIT_ERR("totaldown needs argument");
3090 END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
3092 obj->data.net = get_net_stat(arg);
3095 CRIT_ERR("totalup needs argument");
3098 END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
3099 END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
3100 END OBJ(upspeed, INFO_NET)
3102 obj->data.net = get_net_stat(arg);
3105 CRIT_ERR("upspeed needs argument");
3107 END OBJ(upspeedf, INFO_NET)
3109 obj->data.net = get_net_stat(arg);
3112 CRIT_ERR("upspeedf needs argument");
3115 END OBJ(upspeedgraph, INFO_NET)
3116 (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
3118 sscanf(arg, "%63s %*i,%*i %*i", buf);
3119 obj->data.net = get_net_stat(buf);
3120 if (sscanf(arg, "%*s %d,%d %*d", &obj->b, &obj->a) <= 1) {
3121 if (sscanf(arg, "%*s %d,%d", &obj->a, &obj->a) <= 1) {
3126 END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
3128 OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
3129 #endif /* !__OpenBSD__ */
3130 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3131 OBJ(apm_adapter, 0) END
3132 OBJ(apm_battery_life, 0) END
3133 OBJ(apm_battery_time, 0) END
3134 #endif /* __FreeBSD__ */
3138 obj->data.mail = parse_mail_args(IMAP, arg);
3139 obj->global_mode = 0;
3141 obj->global_mode = 1;
3144 OBJ(imap_messages, 0)
3147 obj->data.mail = parse_mail_args(IMAP, arg);
3148 obj->global_mode = 0;
3150 obj->global_mode = 1;
3156 obj->data.mail = parse_mail_args(POP3, arg);
3157 obj->global_mode = 0;
3159 obj->global_mode = 1;
3165 obj->data.mail = parse_mail_args(POP3, arg);
3166 obj->global_mode = 0;
3168 obj->global_mode = 1;
3172 OBJ(mpd_artist, INFO_MPD) END
3173 OBJ(mpd_title, INFO_MPD)
3176 sscanf (arg, "%d", &info.mpd.max_title_len);
3177 if (info.mpd.max_title_len > 0) {
3178 info.mpd.max_title_len++;
3180 CRIT_ERR ("mpd_title: invalid length argument");
3183 info.mpd.max_title_len = 0;
3186 END OBJ(mpd_random, INFO_MPD)
3187 END OBJ(mpd_repeat, INFO_MPD)
3188 END OBJ(mpd_elapsed, INFO_MPD)
3189 END OBJ(mpd_length, INFO_MPD)
3190 END OBJ(mpd_track, INFO_MPD)
3191 END OBJ(mpd_name, INFO_MPD)
3192 END OBJ(mpd_file, INFO_MPD)
3193 END OBJ(mpd_percent, INFO_MPD)
3194 END OBJ(mpd_album, INFO_MPD)
3195 END OBJ(mpd_vol, INFO_MPD)
3196 END OBJ(mpd_bitrate, INFO_MPD)
3197 END OBJ(mpd_status, INFO_MPD)
3198 END OBJ(mpd_bar, INFO_MPD)
3199 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3200 END OBJ(mpd_smart, INFO_MPD) END
3203 OBJ(xmms2_artist, INFO_XMMS2)
3204 END OBJ(xmms2_album, INFO_XMMS2)
3205 END OBJ(xmms2_title, INFO_XMMS2)
3206 END OBJ(xmms2_genre, INFO_XMMS2)
3207 END OBJ(xmms2_comment, INFO_XMMS2)
3208 END OBJ(xmms2_decoder, INFO_XMMS2)
3209 END OBJ(xmms2_transport, INFO_XMMS2)
3210 END OBJ(xmms2_url, INFO_XMMS2)
3211 END OBJ(xmms2_tracknr, INFO_XMMS2)
3212 END OBJ(xmms2_bitrate, INFO_XMMS2)
3213 END OBJ(xmms2_date, INFO_XMMS2)
3214 END OBJ(xmms2_id, INFO_XMMS2)
3215 END OBJ(xmms2_duration, INFO_XMMS2)
3216 END OBJ(xmms2_elapsed, INFO_XMMS2)
3217 END OBJ(xmms2_size, INFO_XMMS2)
3218 END OBJ(xmms2_status, INFO_XMMS2)
3219 END OBJ(xmms2_percent, INFO_XMMS2)
3220 END OBJ(xmms2_bar, INFO_XMMS2)
3221 (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3222 END OBJ(xmms2_smart, INFO_XMMS2)
3226 OBJ(audacious_status, INFO_AUDACIOUS) END
3227 OBJ(audacious_title, INFO_AUDACIOUS)
3230 sscanf (arg, "%d", &info.audacious.max_title_len);
3231 if (info.audacious.max_title_len > 0) {
3232 info.audacious.max_title_len++;
3234 CRIT_ERR ("audacious_title: invalid length argument");
3239 OBJ(audacious_length, INFO_AUDACIOUS) END
3240 OBJ(audacious_length_seconds, INFO_AUDACIOUS) END
3241 OBJ(audacious_position, INFO_AUDACIOUS) END
3242 OBJ(audacious_position_seconds, INFO_AUDACIOUS) END
3243 OBJ(audacious_bitrate, INFO_AUDACIOUS) END
3244 OBJ(audacious_frequency, INFO_AUDACIOUS) END
3245 OBJ(audacious_channels, INFO_AUDACIOUS) END
3246 OBJ(audacious_filename, INFO_AUDACIOUS) END
3247 OBJ(audacious_playlist_length, INFO_AUDACIOUS) END
3248 OBJ(audacious_playlist_position, INFO_AUDACIOUS) END
3249 OBJ(audacious_bar, INFO_AUDACIOUS)
3250 (void) scan_bar(arg, &obj->a, &obj->b);
3254 OBJ(bmpx_title, INFO_BMPX)
3255 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3257 OBJ(bmpx_artist, INFO_BMPX)
3258 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3260 OBJ(bmpx_album, INFO_BMPX)
3261 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3263 OBJ(bmpx_track, INFO_BMPX)
3264 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3266 OBJ(bmpx_uri, INFO_BMPX)
3267 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3269 OBJ(bmpx_bitrate, INFO_BMPX)
3270 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3276 int argc, delay, act_par;
3277 char *uri = (char *)malloc(128 * sizeof(char));
3278 char *action = (char *)malloc(64 * sizeof(char));
3280 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par);
3281 obj->data.rss.uri = uri;
3282 obj->data.rss.delay = delay;
3283 obj->data.rss.action = action;
3284 obj->data.rss.act_par = act_par;
3288 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
3294 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3295 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
3296 ERR("hddtemp needs arguments");
3297 obj->type = OBJ_text;
3298 obj->data.s = strdup("${hddtemp}");
3303 #ifdef TCP_PORT_MONITOR
3304 OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3305 int argc, port_begin, port_end, item, connection_index;
3307 memset(itembuf,0,sizeof(itembuf));
3309 /* massive argument checking */
3311 CRIT_ERR("tcp_portmon: needs arguments");
3313 argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
3314 if ( (argc != 3) && (argc != 4) )
3316 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3318 if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
3320 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3322 if ( port_begin > port_end )
3324 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3326 if ( strncmp(itembuf,"count",31) == 0 )
3328 else if ( strncmp(itembuf,"rip",31) == 0 )
3330 else if ( strncmp(itembuf,"rhost",31) == 0 )
3332 else if ( strncmp(itembuf,"rport",31) == 0 )
3334 else if ( strncmp(itembuf,"rservice",31) == 0 )
3336 else if ( strncmp(itembuf,"lip",31) == 0 )
3338 else if ( strncmp(itembuf,"lhost",31) == 0 )
3340 else if ( strncmp(itembuf,"lport",31) == 0 )
3342 else if ( strncmp(itembuf,"lservice",31) == 0 )
3346 CRIT_ERR("tcp_portmon: invalid item specified");
3348 if ( (argc==3) && (item!=COUNT) )
3350 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
3352 if ( (argc==4) && (connection_index<0) )
3354 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3356 /* ok, args looks good. save the text object data */
3357 obj->data.tcp_port_monitor.port_range_begin = (in_port_t)port_begin;
3358 obj->data.tcp_port_monitor.port_range_end = (in_port_t)port_end;
3359 obj->data.tcp_port_monitor.item = item;
3360 obj->data.tcp_port_monitor.connection_index = connection_index;
3362 /* if the port monitor collection hasn't been created, we must create it */
3363 if ( !info.p_tcp_port_monitor_collection )
3365 info.p_tcp_port_monitor_collection =
3366 create_tcp_port_monitor_collection ();
3367 if ( !info.p_tcp_port_monitor_collection )
3369 CRIT_ERR("tcp_portmon: unable to create port monitor collection");
3373 /* if a port monitor for this port does not exist, create one and add it to the collection */
3374 if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
3376 tcp_port_monitor_t * p_monitor =
3377 create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
3380 CRIT_ERR("tcp_portmon: unable to create port monitor");
3382 /* add the newly created monitor to the collection */
3383 if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
3386 CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
3391 OBJ(entropy_avail, INFO_ENTROPY) END
3392 OBJ(entropy_poolsize, INFO_ENTROPY) END
3393 OBJ(entropy_bar, INFO_ENTROPY)
3394 (void) scan_bar(arg, &obj->a, &obj->b);
3399 ERR("unknown variable %s", s);
3400 obj->type = OBJ_text;
3401 snprintf(buf, 256, "${%s}", s);
3402 obj->data.s = strdup(buf);
3409 static struct text_object *create_plain_text(const char *s)
3411 struct text_object *obj;
3413 if (s == NULL || *s == '\0') {
3417 obj = new_text_object_internal();
3419 obj->type = OBJ_text;
3420 obj->data.s = strdup(s);
3424 static struct text_object_list *extract_variable_text_internal(const char *p)
3426 struct text_object_list *retval;
3427 struct text_object *obj;
3430 retval = malloc(sizeof(struct text_object_list));
3431 memset(retval, 0, sizeof(struct text_object_list));
3432 retval->text_object_count = 0;
3434 long line = text_lines;
3442 obj = create_plain_text(s);
3444 // allocate memory for the object
3445 retval->text_objects = realloc(retval->text_objects,
3446 sizeof(struct text_object) * (retval->text_object_count+1));
3447 // assign the new object to the end of the list.
3448 memcpy(&retval->text_objects[retval->text_object_count++],
3449 obj, sizeof(struct text_object));
3461 /* variable is either $foo or ${foo} */
3463 unsigned int brl = 1, brr = 0;
3466 while (*p && brl != brr) {
3467 if (*p == '{') brl++;
3468 if (*p == '}') brr++;
3476 while (*p && (isalnum((int) *p)
3481 /* copy variable to buffer */
3482 len = (p - s > 255) ? 255 : (p - s);
3483 strncpy(buf, s, len);
3492 /* if variable wasn't found from environment, use some special */
3498 if (strchr(buf, ' ')) {
3499 arg = strchr(buf, ' ');
3502 while (isspace((int) *arg))
3508 /* lowercase variable name */
3515 // create new object
3516 obj = construct_text_object(buf, arg, retval->text_object_count, retval->text_objects, line);
3518 // allocate memory for the object
3519 retval->text_objects = realloc(retval->text_objects,
3520 sizeof(struct text_object) * (retval->text_object_count+1));
3521 // assign the new object to the end of the list.
3522 memcpy(&retval->text_objects[retval->text_object_count++],
3523 obj, sizeof(struct text_object));
3529 obj = create_plain_text("$");
3531 // allocate memory for the object
3532 retval->text_objects = realloc(retval->text_objects,
3533 sizeof(struct text_object) * (retval->text_object_count+1));
3534 // assign the new object to the end of the list.
3535 memcpy(&retval->text_objects[retval->text_object_count++],
3536 obj, sizeof(struct text_object));
3543 obj = create_plain_text(s);
3545 // allocate memory for the object
3546 retval->text_objects = realloc(retval->text_objects,
3547 sizeof(struct text_object) * (retval->text_object_count+1));
3548 // assign the new object to the end of the list.
3549 memcpy(&retval->text_objects[retval->text_object_count++],
3550 obj, sizeof(struct text_object));
3555 ERR("one or more $endif's are missing");
3561 static void extract_variable_text(const char *p)
3563 struct text_object_list *list;
3565 free_text_objects(text_object_count, text_objects);
3566 text_object_count = 0;
3567 text_objects = NULL;
3570 list = extract_variable_text_internal(p);
3571 text_objects = list->text_objects;
3572 text_object_count = list->text_object_count;
3579 void parse_conky_vars(char * text, char * p, struct information *cur) {
3580 struct text_object_list *object_list = extract_variable_text_internal(text);
3581 generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
3586 * Allows reading from a FIFO (i.e., /dev/xconsole). The file descriptor is
3587 * set to non-blocking which makes this possible.
3590 * Since lseek cannot seek a file descriptor long lines will break.
3592 static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
3594 #define TAIL_PIPE_BUFSIZE 4096
3598 int fd = obj->data.tail.fd;
3601 char buf[TAIL_PIPE_BUFSIZE];
3602 ssize_t len = read(fd, buf, sizeof(buf));
3606 if (errno != EAGAIN) {
3607 strcpy(obj->data.tail.buffer, "Logfile Read Error");
3608 snprintf(dst, dst_size, "Logfile Read Error");
3613 else if (len == 0) {
3614 strcpy(obj->data.tail.buffer, "Logfile Empty");
3615 snprintf(dst, dst_size, "Logfile Empty");
3619 for (line_len = 0, i = 0; i < len; i++) {
3623 if (buf[i] == '\n') {
3626 if (obj->data.tail.readlines > 0) {
3631 for (n = 0; obj->data.tail.buffer[n]; n++) {
3632 if (obj->data.tail.buffer[n] == '\n') {
3636 if (++olines < obj->data.tail.wantedlines) {
3642 p = obj->data.tail.buffer + first_line;
3643 pos = n - first_line;
3644 memmove(obj->data.tail.buffer, obj->data.tail.buffer + first_line, strlen(p));
3645 obj->data.tail.buffer[pos] = 0;
3651 p = buf + last_line;
3653 memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
3654 obj->data.tail.buffer[pos + line_len] = 0;
3657 obj->data.tail.readlines = lines;
3665 snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
3668 static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
3673 char buff_in[P_MAX_SIZE] = {0};
3674 iconv_converting = 0;
3677 for (i = 0; i < object_count; i++) {
3678 struct text_object *obj = &objs[i];
3680 #define OBJ(a) break; case OBJ_##a:
3682 switch (obj->type) {
3685 ERR("not implemented obj type %d",
3690 /* does anyone have decimals in acpi temperature? */
3692 snprintf(p, p_max_size, "%d", (int)
3693 get_acpi_temperature(obj->
3697 snprintf(p, 5, "%d ", (int)
3698 get_acpi_temperature(obj->
3703 /* does anyone have decimals in acpi temperature? */
3705 snprintf(p, p_max_size, "%d", (int)
3706 ((get_acpi_temperature(obj->
3708 i)+ 40) * 9.0 / 5 - 40));
3710 snprintf(p, 5, "%d ", (int)
3711 ((get_acpi_temperature(obj->
3713 i)+ 40) * 9.0 / 5 - 40));
3715 #endif /* !__OpenBSD__ */
3718 obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3724 obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->data.cpu_index);
3726 /* OpenBSD has no such flag (SUSv2) */
3727 obj->a = get_freq(p, p_max_size, "%.2f", 1000, obj->data.cpu_index);
3732 #if defined(__linux__)
3735 obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->data.cpu_index);
3740 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
3744 OBJ(wireless_essid) {
3745 snprintf(p, p_max_size, "%s", obj->data.net->essid);
3747 OBJ(wireless_mode) {
3748 snprintf(p, p_max_size, "%s", obj->data.net->mode);
3750 OBJ(wireless_bitrate) {
3751 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
3754 snprintf(p, p_max_size, "%s", obj->data.net->ap);
3756 OBJ(wireless_link_qual) {
3758 snprintf(p, p_max_size, "%d", obj->data.net->link_qual);
3760 snprintf(p, 4, "%d ", obj->data.net->link_qual);
3762 OBJ(wireless_link_qual_max) {
3764 snprintf(p, p_max_size, "%d", obj->data.net->link_qual_max);
3766 snprintf(p, 4, "%d ", obj->data.net->link_qual_max);
3768 OBJ(wireless_link_qual_perc) {
3769 if(obj->data.net->link_qual_max > 0) {
3771 snprintf(p, p_max_size, "%.0f%%", (double)obj->data.net->link_qual / obj->data.net->link_qual_max * 100);
3773 snprintf(p, 5, "%.0f%% ", (double)obj->data.net->link_qual / obj->data.net->link_qual_max * 100);
3774 } else snprintf(p, p_max_size, "unk");
3776 OBJ(wireless_link_bar) {
3777 new_bar(p, obj->a, obj->b, ((double)obj->data.net->link_qual/obj->data.net->link_qual_max)*255.0);
3779 #endif /* HAVE_IWLIB */
3781 #endif /* __linux__ */
3785 get_freq_dynamic(p, 6, "%.0f ", 1 );
3787 get_freq_dynamic(p, p_max_size, "%.0f", 1 );
3793 get_freq_dynamic(p, 6, "%'.2f ", 1000);
3795 get_freq_dynamic(p, 6, "%.2f ", 1000);
3799 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
3801 get_freq_dynamic(p, p_max_size, "%.2f", 1000);
3807 get_adt746x_cpu(p, p_max_size);
3810 get_adt746x_fan(p, p_max_size);
3813 get_acpi_fan(p, p_max_size);
3815 OBJ(acpiacadapter) {
3816 get_acpi_ac_adapter(p, p_max_size);
3819 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
3822 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
3824 OBJ(battery_percent) {
3825 snprintf(p, p_max_size, "%d",
3826 get_battery_perct(obj->data.s));
3829 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
3831 #endif /* __OpenBSD__ */
3833 human_readable(cur->buffers * 1024, p, 255);
3836 human_readable(cur->cached * 1024, p, 255);
3839 if (obj->data.cpu_index > info.cpu_count) {
3840 printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
3841 CRIT_ERR("attempting to use more CPUs then you have!");
3844 snprintf(p, p_max_size, "%*d", pad_percents,
3845 round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3848 snprintf(p, 4, "%*d ",
3850 round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3856 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
3859 new_graph(p, obj->a,
3860 obj->b, obj->c, obj->d,
3861 (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
3865 new_fg(p, obj->data.l);
3897 #if defined(__linux__)
3899 snprintf(p, p_max_size, "%s", i8k.version);
3902 snprintf(p, p_max_size, "%s", i8k.bios);
3905 snprintf(p, p_max_size, "%s", i8k.serial);
3908 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
3910 OBJ(i8k_cpu_tempf) {
3912 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
3913 snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
3915 OBJ(i8k_left_fan_status) {
3916 int left_fan_status;
3917 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
3918 if(left_fan_status == 0) {
3919 snprintf(p, p_max_size,"off");
3920 } if(left_fan_status == 1) {
3921 snprintf(p, p_max_size, "low");
3922 } if(left_fan_status == 2) {
3923 snprintf(p, p_max_size, "high");
3927 OBJ(i8k_right_fan_status) {
3928 int right_fan_status;
3929 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
3930 if(right_fan_status == 0) {
3931 snprintf(p, p_max_size,"off");
3932 } if(right_fan_status == 1) {
3933 snprintf(p, p_max_size, "low");
3934 } if(right_fan_status == 2) {
3935 snprintf(p, p_max_size, "high");
3938 OBJ(i8k_left_fan_rpm) {
3939 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
3941 OBJ(i8k_right_fan_rpm) {
3942 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
3944 OBJ(i8k_ac_status) {
3946 sscanf(i8k.ac_status, "%d", &ac_status);
3947 if(ac_status == -1) {
3948 snprintf(p, p_max_size,"disabled (read i8k docs)");
3949 } if(ac_status == 0) {
3950 snprintf(p, p_max_size, "off");
3951 } if(ac_status == 1) {
3952 snprintf(p, p_max_size, "on");
3955 OBJ(i8k_buttons_status) {
3956 snprintf(p, p_max_size, "%s", i8k.buttons_status);
3960 get_ibm_acpi_fan(p, p_max_size);
3963 get_ibm_acpi_temps();
3964 snprintf(p, p_max_size, "%d",
3965 ibm_acpi.temps[obj->data.sensor]);
3968 get_ibm_acpi_volume(p, p_max_size);
3970 OBJ(ibm_brightness) {
3971 get_ibm_acpi_brightness(p, p_max_size);
3974 get_powerbook_batt_info(p, p_max_size, obj->data.i);
3976 #endif /* __linux__ */
3979 OBJ(obsd_sensors_temp) {
3980 obsd_sensors.device = sensor_device;
3981 update_obsd_sensors();
3982 snprintf(p, p_max_size, "%.1f",
3983 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
3986 OBJ(obsd_sensors_fan) {
3987 obsd_sensors.device = sensor_device;
3988 update_obsd_sensors();
3989 snprintf(p, p_max_size, "%d",
3990 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
3993 OBJ(obsd_sensors_volt) {
3994 obsd_sensors.device = sensor_device;
3995 update_obsd_sensors();
3996 snprintf(p, p_max_size, "%.2f",
3997 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4001 get_obsd_vendor(p, p_max_size);
4005 get_obsd_product(p, p_max_size);
4007 #endif /* __OpenBSD__ */
4011 new_font(p, obj->data.s);
4014 void format_diskio(unsigned int diskio_value)
4017 if (diskio_value > 1024*1024) {
4018 snprintf(p, p_max_size, "%.1fGiB",
4019 (double)diskio_value/1024/1024);
4020 } else if (diskio_value > 1024) {
4021 snprintf(p, p_max_size, "%.1fMiB",
4022 (double)diskio_value/1024);
4023 } else if (diskio_value > 0) {
4024 snprintf(p, p_max_size, "%dKiB", diskio_value);
4026 snprintf(p, p_max_size, "%dB", diskio_value);
4029 if (diskio_value > 1024*1024) {
4030 snprintf(p, 12, "%.1fGiB ",
4031 (double)diskio_value/1024/1024);
4032 } else if (diskio_value > 1024) {
4033 snprintf(p, 12, "%.1fMiB ",
4034 (double)diskio_value/1024);
4035 } else if (diskio_value > 0) {
4036 snprintf(p, 12, "%dKiB ", diskio_value);
4038 snprintf(p, 12, "%dB ", diskio_value);
4043 format_diskio(diskio_value);
4046 format_diskio(diskio_write_value);
4049 format_diskio(diskio_read_value);
4052 new_graph(p, obj->a,
4053 obj->b, obj->c, obj->d,
4054 diskio_value, obj->e, 1);
4056 OBJ(diskiograph_read) {
4057 new_graph(p, obj->a,
4058 obj->b, obj->c, obj->d,
4059 diskio_read_value, obj->e, 1);
4061 OBJ(diskiograph_write) {
4062 new_graph(p, obj->a,
4063 obj->b, obj->c, obj->d,
4064 diskio_write_value, obj->e, 1);
4068 snprintf(p, p_max_size, "%d",
4069 (int) (obj->data.net->
4073 snprintf(p, 6, "%d ",
4074 (int) (obj->data.net->
4080 snprintf(p, p_max_size, "%.1f",
4082 recv_speed / 1024.0);
4084 snprintf(p, 8, "%.1f ",
4086 recv_speed / 1024.0);
4088 OBJ(downspeedgraph) {
4090 if (obj->data.net->recv_speed == 0)
4091 obj->data.net->recv_speed = 0.01;
4093 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4094 (obj->data.net->recv_speed /
4095 1024.0), obj->e, 1);
4099 i = obj->data.ifblock.pos - 1;
4109 snprintf(p, p_max_size, "%u.%u.%u.%u",
4110 obj->data.net->addr.
4112 obj->data.net->addr.
4114 obj->data.net->addr.
4116 obj->data.net->addr.
4120 #if defined(IMLIB2) && defined(X11)
4125 Imlib_Image image, buffer;
4126 image = imlib_load_image(obj->data.s);
4127 imlib_context_set_image(image);
4130 w = imlib_image_get_width();
4131 h = imlib_image_get_height();
4132 buffer = imlib_create_image(w, h);
4133 imlib_context_set_display(display);
4134 imlib_context_set_drawable(window.drawable);
4135 imlib_context_set_colormap(DefaultColormap(display, screen));
4136 imlib_context_set_visual(DefaultVisual(display, screen));
4137 imlib_context_set_image(buffer);
4138 imlib_blend_image_onto_image(image, 0, 0, 0, w, h, text_start_x, text_start_y, w, h);
4139 imlib_render_image_on_drawable(text_start_x, text_start_y);
4141 imlib_context_set_image(image);
4148 FILE *fp = popen(obj->data.s, "r");
4149 int length = fread(p, 1, p_max_size, fp);
4152 /*output[length] = '\0';
4153 if (length > 0 && output[length - 1] == '\n') {
4154 output[length - 1] = '\0';
4157 if (length > 0 && p[length - 1] == '\n') {
4158 p[length - 1] = '\0';
4161 //parse_conky_vars(output, p, cur);
4165 FILE *fp = popen(obj->data.s, "r");
4166 int n2 = fread(p, 1, p_max_size, fp);
4170 if (n2 && p[n2 - 1] == '\n')
4179 if (sscanf(p, "%lf", &barnum) == 0) {
4180 ERR("reading execbar value failed (perhaps it's not the correct format?)");
4182 if (barnum > 100 || barnum < 0) {
4183 ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
4185 barnum = barnum / 100.0;
4186 new_bar(p, 0, 4, (int) (barnum * 255.0));
4192 FILE *fp = popen(obj->data.s, "r");
4193 int n2 = fread(p, 1, p_max_size, fp);
4197 if (n2 && p[n2 - 1] == '\n')
4206 if (sscanf(p, "%lf", &barnum) == 0) {
4207 ERR("reading execgraph value failed (perhaps it's not the correct format?)");
4209 if (barnum > 100 || barnum < 0) {
4210 ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
4212 new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), obj->e, 1);
4217 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
4218 new_bar(p, 0, 4, (int) obj->f);
4221 FILE *fp = popen(obj->data.execi.cmd, "r");
4222 int n2 = fread(p, 1, p_max_size, fp);
4225 if (n2 && p[n2 - 1] == '\n')
4234 if (sscanf(p, "%f", &barnum) == 0) {
4235 ERR("reading execibar value failed (perhaps it's not the correct format?)");
4237 if (barnum > 100 || barnum < 0) {
4238 ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
4240 obj->f = 255 * barnum / 100.0;
4241 new_bar(p, 0, 4, (int) obj->f);
4243 obj->data.execi.last_update =
4244 current_update_time;
4248 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
4249 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
4252 FILE *fp = popen(obj->data.execi.cmd, "r");
4253 int n2 = fread(p, 1, p_max_size, fp);
4256 if (n2 && p[n2 - 1] == '\n')
4265 if (sscanf(p, "%f", &barnum) == 0) {
4266 ERR("reading execigraph value failed (perhaps it's not the correct format?)");
4268 if (barnum > 100 || barnum < 0) {
4269 ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
4272 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1);
4274 obj->data.execi.last_update = current_update_time;
4280 if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
4281 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
4283 char *output = obj->data.execi.buffer;
4284 FILE *fp = popen(obj->data.execi.cmd, "r");
4285 //int length = fread(output, 1, text_buffer_size, fp);
4286 int length = fread(output, 1, text_buffer_size, fp);
4289 output[length] = '\0';
4290 if (length > 0 && output[length - 1] == '\n') {
4291 output[length - 1] = '\0';
4293 obj->data.execi.last_update = current_update_time;
4294 snprintf(p, p_max_size, "%s", output);
4296 //parse_conky_vars(output, p, cur);
4299 if (!obj->data.texeci.p_timed_thread)
4301 obj->data.texeci.p_timed_thread=
4302 timed_thread_create ((void*)threaded_exec, (void*) obj, obj->data.texeci.interval * 1000000);
4303 if (!obj->data.texeci.p_timed_thread)
4304 ERR("Error creating texeci timed thread");
4305 timed_thread_register (obj->data.texeci.p_timed_thread, &obj->data.texeci.p_timed_thread);
4306 if (timed_thread_run (obj->data.texeci.p_timed_thread))
4307 ERR("Error running texeci timed thread");
4309 timed_thread_lock (obj->data.texeci.p_timed_thread);
4310 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
4311 timed_thread_unlock (obj->data.texeci.p_timed_thread);
4313 #endif /* HAVE_POPEN */
4315 if (obj->global_mode && info.mail) { // this means we use info
4316 if (!info.mail->p_timed_thread)
4318 info.mail->p_timed_thread =
4319 timed_thread_create ((void*)imap_thread, (void*)info.mail, info.mail->interval * 1000000);
4320 if (!info.mail->p_timed_thread)
4321 ERR("Error creating imap timed thread");
4322 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4323 if (timed_thread_run (info.mail->p_timed_thread))
4324 ERR("Error running imap timed thread");
4326 timed_thread_lock (info.mail->p_timed_thread);
4327 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4328 timed_thread_unlock (info.mail->p_timed_thread);
4329 } else if (obj->data.mail) { // this means we use obj
4330 if (!obj->data.mail->p_timed_thread)
4332 obj->data.mail->p_timed_thread =
4333 timed_thread_create ((void*)imap_thread, (void*)obj->data.mail,
4334 obj->data.mail->interval * 1000000);
4335 if (!obj->data.mail->p_timed_thread)
4336 ERR("Error creating imap timed thread");
4337 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4338 if (timed_thread_run (obj->data.mail->p_timed_thread))
4339 ERR("Error running imap timed thread");
4341 timed_thread_lock (obj->data.mail->p_timed_thread);
4342 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4343 timed_thread_unlock (obj->data.mail->p_timed_thread);
4344 } else if (!obj->a) { // something is wrong, warn once then stop
4345 ERR("Theres a problem with your imap_unseen settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4349 OBJ(imap_messages) {
4350 if (obj->global_mode && info.mail) { // this means we use info
4351 if (!info.mail->p_timed_thread)
4353 info.mail->p_timed_thread =
4354 timed_thread_create ((void*)imap_thread, (void*)info.mail, info.mail->interval * 1000000);
4355 if (!info.mail->p_timed_thread)
4356 ERR("Error creating imap timed thread");
4357 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4358 if (timed_thread_run (info.mail->p_timed_thread))
4359 ERR("Error running imap timed thread");
4361 timed_thread_lock (info.mail->p_timed_thread);
4362 snprintf(p, p_max_size, "%lu", info.mail->messages);
4363 timed_thread_unlock (info.mail->p_timed_thread);
4364 } else if (obj->data.mail) { // this means we use obj
4365 if (!obj->data.mail->p_timed_thread)
4367 obj->data.mail->p_timed_thread =
4368 timed_thread_create ((void*)imap_thread, (void*)obj->data.mail,
4369 obj->data.mail->interval * 1000000);
4370 if (!obj->data.mail->p_timed_thread)
4371 ERR("Error creating imap timed thread");
4372 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4373 if (timed_thread_run (obj->data.mail->p_timed_thread))
4374 ERR("Error runninging imap timed thread");
4376 timed_thread_lock (obj->data.mail->p_timed_thread);
4377 snprintf(p, p_max_size, "%lu", obj->data.mail->messages);
4378 timed_thread_lock (obj->data.mail->p_timed_thread);
4379 } else if (!obj->a) { // something is wrong, warn once then stop
4380 ERR("Theres a problem with your imap_messages settings. Check that the global IMAP settings are defined properly (line %li).", obj->line);
4385 if (obj->global_mode && info.mail) { // this means we use info
4386 if (!info.mail->p_timed_thread)
4388 info.mail->p_timed_thread =
4389 timed_thread_create ((void*)pop3_thread, (void*)info.mail, info.mail->interval * 1000000);
4390 if (!info.mail->p_timed_thread)
4391 ERR("Error creating pop3 timed thread");
4392 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4393 if (timed_thread_run (info.mail->p_timed_thread))
4394 ERR("Error running pop3 timed thread");
4396 timed_thread_lock (info.mail->p_timed_thread);
4397 snprintf(p, p_max_size, "%lu", info.mail->unseen);
4398 timed_thread_unlock (info.mail->p_timed_thread);
4399 } else if (obj->data.mail) { // this means we use obj
4400 if (!obj->data.mail->p_timed_thread)
4402 obj->data.mail->p_timed_thread =
4403 timed_thread_create ((void*)pop3_thread, (void*)obj->data.mail,
4404 obj->data.mail->interval * 1000000);
4405 if (!obj->data.mail->p_timed_thread)
4406 ERR("Error creating pop3 timed thread");
4407 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4408 if (timed_thread_run (obj->data.mail->p_timed_thread))
4409 ERR("Error running pop3 timed thread");
4411 timed_thread_lock (obj->data.mail->p_timed_thread);
4412 snprintf(p, p_max_size, "%lu", obj->data.mail->unseen);
4413 timed_thread_unlock (obj->data.mail->p_timed_thread);
4414 } else if (!obj->a) { // something is wrong, warn once then stop
4415 ERR("Theres a problem with your pop3_unseen settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4420 if (obj->global_mode && info.mail) { // this means we use info
4421 if (!info.mail->p_timed_thread)
4423 info.mail->p_timed_thread =
4424 timed_thread_create ((void*)pop3_thread, (void*)info.mail, info.mail->interval * 1000000);
4425 if (!info.mail->p_timed_thread)
4426 ERR("Error creating pop3 timed thread");
4427 timed_thread_register (info.mail->p_timed_thread, &info.mail->p_timed_thread);
4428 if (timed_thread_run (info.mail->p_timed_thread))
4429 ERR("Error running pop3 timed thread");
4431 timed_thread_lock (info.mail->p_timed_thread);
4432 snprintf(p, p_max_size, "%.1f", info.mail->used/1024.0/1024.0);
4433 timed_thread_unlock (info.mail->p_timed_thread);
4434 } else if (obj->data.mail) { // this means we use obj
4435 if (!obj->data.mail->p_timed_thread)
4437 obj->data.mail->p_timed_thread =
4438 timed_thread_create ((void*)pop3_thread, (void*)obj->data.mail,
4439 obj->data.mail->interval * 1000000);
4440 if (!obj->data.mail->p_timed_thread)
4441 ERR("Error creating pop3 timed thread");
4442 timed_thread_register (obj->data.mail->p_timed_thread, &obj->data.mail->p_timed_thread);
4443 if (timed_thread_run (obj->data.mail->p_timed_thread))
4444 ERR("Error running pop3 timed thread");
4446 timed_thread_lock (obj->data.mail->p_timed_thread);
4447 snprintf(p, p_max_size, "%.1f", obj->data.mail->used/1024.0/1024.0);
4448 timed_thread_unlock (obj->data.mail->p_timed_thread);
4449 } else if (!obj->a) { // something is wrong, warn once then stop
4450 ERR("Theres a problem with your pop3_used settings. Check that the global POP3 settings are defined properly (line %li).", obj->line);
4455 if (obj->data.fs != NULL) {
4456 if (obj->data.fs->size == 0)
4475 if (obj->data.fs != NULL)
4476 human_readable(obj->data.fs->avail,
4480 if (obj->data.fs != NULL) {
4481 if (obj->data.fs->size)
4482 snprintf(p, p_max_size, "%*d",
4491 snprintf(p, p_max_size, "0");
4495 if (obj->data.fs != NULL)
4496 human_readable(obj->data.fs->size,
4500 if (obj->data.fs != NULL)
4501 human_readable(obj->data.fs->size -
4502 (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
4506 if (obj->data.fs != NULL) {
4507 if (obj->data.fs->size == 0)
4525 if (obj->data.fs != NULL) {
4526 if (obj->data.fs->size)
4527 snprintf(p, 4, "%d",
4537 snprintf(p, p_max_size, "0");
4541 float *v = info.loadavg;
4543 if (obj->data.loadavg[2])
4544 snprintf(p, p_max_size, "%.2f %.2f %.2f",
4545 v[obj->data.loadavg[0] -
4547 v[obj->data.loadavg[1] -
4549 v[obj->data.loadavg[2] -
4551 else if (obj->data.loadavg[1])
4552 snprintf(p, p_max_size, "%.2f %.2f",
4553 v[obj->data.loadavg[0] -
4555 v[obj->data.loadavg[1] -
4557 else if (obj->data.loadavg[0])
4558 snprintf(p, p_max_size, "%.2f",
4559 v[obj->data.loadavg[0] -
4563 new_goto(p, obj->data.i);
4566 new_tab(p, obj->data.pair.a, obj->data.pair.b);
4569 new_hr(p, obj->data.i);
4573 PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay);
4576 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
4578 if(!strcmp(obj->data.rss.action, "feed_title")) {
4580 if(str[strlen(str)-1] == '\n')
4581 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4582 snprintf(p, p_max_size, "%s", str);
4583 } else if(!strcmp(obj->data.rss.action, "item_title")) {
4584 if(obj->data.rss.act_par < data->item_count) {
4585 str = data->items[obj->data.rss.act_par].title;
4586 if(str[strlen(str)-1] == '\n')
4587 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4588 snprintf(p, p_max_size, "%s", str);
4590 } else if(!strcmp(obj->data.rss.action, "item_desc")) {
4591 if(obj->data.rss.act_par < data->item_count) {
4592 str = data->items[obj->data.rss.act_par].description;
4593 if(str[strlen(str)-1] == '\n')
4594 str[strlen(str)-1] = 0; // remove trailing new line if one exists
4595 snprintf(p, p_max_size, "%s", str);
4597 } else if(!strcmp(obj->data.rss.action, "item_titles")) {
4598 if(data->item_count > 0) {
4602 if(obj->data.rss.act_par > data->item_count)
4603 show = data->item_count;
4604 else show = obj->data.rss.act_par;
4605 for(itmp = 0; itmp < show; itmp++) {
4606 PRSS_Item *item = &data->items[itmp];
4609 if(itmp>0) // don't add new line before first item
4610 strncat(p, "\n", p_max_size);
4611 if(str[strlen(str)-1] == '\n')
4612 str[strlen(str)-1] = 0; // remove trailing new line if one exists, we have our own
4613 strncat(p, str, p_max_size);
4626 temp = get_hddtemp_info(obj->data.hddtemp.dev,
4627 obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit);
4629 snprintf(p, p_max_size, "N/A");
4630 } else if (unit == '*') {
4631 snprintf(p, p_max_size, "%s", temp);
4633 snprintf(p, p_max_size, "%s°%c", temp, unit);
4638 new_offset(p, obj->data.i);
4641 new_voffset(p, obj->data.i);
4647 r = get_sysfs_info(&obj->data.sysfs.fd,
4648 obj->data.sysfs.arg,
4649 obj->data.sysfs.devtype,
4650 obj->data.sysfs.type);
4652 if (r >= 100.0 || r == 0)
4653 snprintf(p, p_max_size, "%d", (int) r);
4655 snprintf(p, p_max_size, "%.1f", r);
4660 r = get_sysfs_info(&obj->data.sysfs.fd,
4661 obj->data.sysfs.arg,
4662 obj->data.sysfs.devtype,
4663 obj->data.sysfs.type);
4665 if (r >= 100.0 || r == 0)
4666 snprintf(p, p_max_size, "%d", (int) r);
4668 snprintf(p, p_max_size, "%.1f", r);
4673 r = get_sysfs_info(&obj->data.sysfs.fd,
4674 obj->data.sysfs.arg,
4675 obj->data.sysfs.devtype,
4676 obj->data.sysfs.type);
4678 if (r >= 100.0 || r == 0)
4679 snprintf(p, p_max_size, "%d", (int) r);
4681 snprintf(p, p_max_size, "%.1f", r);
4683 #endif /* !__OpenBSD__ */
4685 new_alignr(p, obj->data.i);
4688 new_alignc(p, obj->data.i);
4691 struct information *my_info =
4692 malloc(sizeof(struct information));
4693 memcpy(my_info, cur, sizeof(struct information));
4694 parse_conky_vars(obj->data.ifblock.s, p, my_info);
4695 if (strlen(p) != 0) {
4696 i = obj->data.ifblock.pos;
4706 if ((obj->data.ifblock.s)
4707 && (stat(obj->data.ifblock.s, &tmp) ==
4709 i = obj->data.ifblock.pos;
4712 if (obj->data.ifblock.str) {
4713 if (!check_contains(obj->data.ifblock.s,
4714 obj->data.ifblock.str)) {
4715 i = obj->data.ifblock.pos;
4724 if ((obj->data.ifblock.s)
4725 && (!check_mount(obj->data.ifblock.s))) {
4726 i = obj->data.ifblock.pos;
4733 if ((obj->data.ifblock.s)
4734 && system(obj->data.ifblock.s)) {
4735 i = obj->data.ifblock.pos;
4742 snprintf(p, p_max_size, "%s", cur->uname_s.release);
4745 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
4750 human_readable(cur->mem * 1024, p, 255);
4753 human_readable(cur->memmax * 1024, p, 255);
4758 snprintf(p, p_max_size, "%*Lu",
4763 snprintf(p, 4, "%*Lu ",
4770 new_bar(p, obj->data.pair.a,
4772 cur->memmax ? (cur->mem * 255) /
4777 new_graph(p, obj->a,
4778 obj->b, obj->c, obj->d,
4779 cur->memmax ? (cur->mem * 100.0) /
4780 (cur->memmax) : 0.0, 100, 1);
4784 snprintf(p, p_max_size, "%d",
4785 mixer_get_avg(obj->data.l));
4788 snprintf(p, p_max_size, "%d",
4789 mixer_get_left(obj->data.l));
4792 snprintf(p, p_max_size, "%d",
4793 mixer_get_right(obj->data.l));
4796 new_bar(p, obj->data.mixerbar.w,
4797 obj->data.mixerbar.h,
4798 mixer_get_avg(obj->data.mixerbar.
4802 new_bar(p, obj->data.mixerbar.w,
4803 obj->data.mixerbar.h,
4804 mixer_get_left(obj->data.mixerbar.
4808 new_bar(p, obj->data.mixerbar.w,
4809 obj->data.mixerbar.h,
4810 mixer_get_right(obj->data.mixerbar.
4816 update_mail_count(&obj->data.local_mail);
4817 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
4820 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
4821 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
4824 update_mail_count(&obj->data.local_mail);
4825 snprintf(p, p_max_size, "%d", obj->data.local_mail.new_mail_count);
4829 snprintf(p, p_max_size, "%s",
4830 cur->uname_s.nodename);
4833 new_outline(p, obj->data.l);
4837 snprintf(p, p_max_size, "%hu", cur->procs);
4839 snprintf(p, 5, "%hu ",
4842 OBJ(running_processes) {
4844 snprintf(p, p_max_size, "%hu",
4847 snprintf(p, 3, "%hu ",
4851 snprintf(p, p_max_size, "%s", obj->data.s);
4854 new_bg(p, obj->data.l);
4857 new_stippled_hr(p, obj->data.pair.a,
4861 human_readable(cur->swap * 1024, p, 255);
4864 human_readable(cur->swapmax * 1024, p,
4868 if (cur->swapmax == 0) {
4869 strncpy(p, "No swap", 255);
4872 snprintf(p, 255, "%*Lu",
4878 snprintf(p, 4, "%*Lu ",
4886 new_bar(p, obj->data.pair.a,
4888 cur->swapmax ? (cur->swap * 255) /
4889 (cur->swapmax) : 0);
4892 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
4895 time_t t = time(NULL);
4896 struct tm *tm = localtime(&t);
4897 setlocale(LC_TIME, "");
4898 strftime(p, p_max_size, obj->data.s, tm);
4901 time_t t = time(NULL);
4902 struct tm *tm = gmtime(&t);
4903 strftime(p, p_max_size, obj->data.s, tm);
4907 if (obj->data.tztime.tz) {
4908 oldTZ = getenv("TZ");
4909 setenv("TZ", obj->data.tztime.tz, 1);
4912 time_t t = time(NULL);
4913 struct tm *tm = localtime(&t);
4914 setlocale(LC_TIME, "");
4915 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
4917 setenv("TZ", oldTZ, 1);
4922 // Needless to free oldTZ since getenv gives ptr to static data
4925 human_readable(obj->data.net->recv, p,
4929 human_readable(obj->data.net->trans, p,
4933 snprintf(p, p_max_size, "%d", total_updates);
4937 snprintf(p, p_max_size, "%d",
4938 (int) (obj->data.net->
4942 snprintf(p, 6, "%d ",
4943 (int) (obj->data.net->
4949 snprintf(p, p_max_size, "%.1f",
4951 trans_speed / 1024.0);
4953 snprintf(p, 8, "%.1f ",
4955 trans_speed / 1024.0);
4959 if (obj->data.net->trans_speed == 0)
4960 obj->data.net->trans_speed = 0.01;
4962 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4963 (obj->data.net->trans_speed /
4964 1024.0), obj->e, 1);
4967 format_seconds_short(p, p_max_size,
4971 format_seconds(p, p_max_size, (int) cur->uptime);
4974 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
4977 msg = get_apm_adapter();
4978 snprintf(p, p_max_size, "%s", msg);
4981 OBJ(apm_battery_life) {
4983 msg = get_apm_battery_life();
4984 snprintf(p, p_max_size, "%s", msg);
4987 OBJ(apm_battery_time) {
4989 msg = get_apm_battery_time();
4990 snprintf(p, p_max_size, "%s", msg);
4993 #endif /* __FreeBSD__ __OpenBSD__ */
4997 snprintf(p, cur->mpd.max_title_len > 0 ?
4998 cur->mpd.max_title_len : p_max_size, "%s",
5002 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5005 snprintf(p, p_max_size, "%s", cur->mpd.album);
5008 snprintf(p, p_max_size, "%s", cur->mpd.random);
5011 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
5014 snprintf(p, p_max_size, "%s", cur->mpd.track);
5017 snprintf(p, p_max_size, "%s", cur->mpd.name);
5020 snprintf(p, p_max_size, "%s", cur->mpd.file);
5023 snprintf(p, p_max_size, "%i", cur->mpd.volume);
5026 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
5029 snprintf(p, p_max_size, "%s", cur->mpd.status);
5032 int days = 0, hours = 0, minutes =
5034 int tmp = cur->mpd.elapsed;
5035 while (tmp >= 86400) {
5039 while (tmp >= 3600) {
5049 snprintf(p, p_max_size, "%i days %i:%02i:%02i",
5050 days, hours, minutes,
5053 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
5056 snprintf(p, p_max_size, "%i:%02i", minutes,
5060 int days = 0, hours = 0, minutes =
5062 int tmp = cur->mpd.length;
5063 while (tmp >= 86400) {
5067 while (tmp >= 3600) {
5077 snprintf(p, p_max_size,
5078 "%i days %i:%02i:%02i",
5079 days, hours, minutes,
5082 snprintf(p, p_max_size, "%i:%02i:%02i", hours,
5085 snprintf(p, p_max_size, "%i:%02i", minutes,
5089 snprintf(p, p_max_size, "%2.0f",
5090 cur->mpd.progress * 100);
5093 new_bar(p, obj->data.pair.a,
5095 (int) (cur->mpd.progress *
5099 memset (p, 0, p_max_size);
5100 if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title && *cur->mpd.title) {
5101 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist, cur->mpd.title);
5103 else if (cur->mpd.title && *cur->mpd.title) {
5104 snprintf(p, p_max_size, "%s", cur->mpd.title);
5106 else if (cur->mpd.artist && *cur->mpd.artist) {
5107 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5109 else if (cur->mpd.file && *cur->mpd.file) {
5110 snprintf(p, p_max_size, "%s", cur->mpd.file);
5119 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5122 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5125 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5128 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5130 OBJ(xmms2_comment) {
5131 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5133 OBJ(xmms2_decoder) {
5134 snprintf(p, p_max_size, "%s", cur->xmms2.decoder);
5136 OBJ(xmms2_transport) {
5137 snprintf(p, p_max_size, "%s", cur->xmms2.transport);
5140 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5143 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5146 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5148 OBJ(xmms2_tracknr) {
5149 if (cur->xmms2.tracknr != -1)
5150 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5152 OBJ(xmms2_bitrate) {
5153 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5156 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5159 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5161 OBJ(xmms2_elapsed) {
5162 int tmp = cur->xmms2.elapsed;
5163 snprintf(p, p_max_size, "%02d:%02d",
5164 tmp / 60000, (tmp / 1000) % 60);
5166 OBJ(xmms2_duration) {
5167 int tmp = cur->xmms2.duration;
5168 snprintf(p, p_max_size, "%02d:%02d",
5169 tmp / 60000, (tmp / 1000) % 60);
5171 OBJ(xmms2_percent) {
5172 snprintf(p, p_max_size, "%2.0f",
5173 cur->xmms2.progress * 100);
5176 new_bar(p, obj->data.pair.a,
5178 (int) (cur->xmms2.progress *
5182 if (strlen(cur->xmms2.title) < 2 && strlen(cur->xmms2.title) < 2) {
5183 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5185 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist, cur->xmms2.title);
5190 OBJ(audacious_status) {
5191 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
5193 OBJ(audacious_title) {
5194 snprintf(p, cur->audacious.max_title_len > 0 ?
5195 cur->audacious.max_title_len : p_max_size, "%s",
5196 cur->audacious.items[AUDACIOUS_TITLE]);
5198 OBJ(audacious_length) {
5199 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH]);
5201 OBJ(audacious_length_seconds) {
5202 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5204 OBJ(audacious_position) {
5205 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION]);
5207 OBJ(audacious_position_seconds) {
5208 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5210 OBJ(audacious_bitrate) {
5211 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_BITRATE]);
5213 OBJ(audacious_frequency) {
5214 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FREQUENCY]);
5216 OBJ(audacious_channels) {
5217 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_CHANNELS]);
5219 OBJ(audacious_filename) {
5220 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_FILENAME]);
5222 OBJ(audacious_playlist_length) {
5223 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5225 OBJ(audacious_playlist_position) {
5226 snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5228 OBJ(audacious_bar) {
5230 progress= atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5231 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5232 new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
5237 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5240 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5243 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5246 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5249 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5252 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5256 char *format_time(unsigned long time, const int width) {
5258 unsigned long nt; // narrow time, for speed on
5261 unsigned cc; // centiseconds
5262 unsigned nn; // multi-purpose whatever
5265 cc = nt % 100; // centiseconds past second
5266 nt /= 100; // total seconds
5267 nn = nt % 60; // seconds past the minute
5268 nt /= 60; // total minutes
5269 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u", nt,
5272 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn))
5274 nn = nt % 60; // minutes past the hour
5275 nt /= 60; // total hours
5276 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn))
5278 nn = nt; // now also hours
5279 if (width >= snprintf(buf, sizeof buf, "%uh", nn))
5281 nn /= 24; // now days
5282 if (width >= snprintf(buf, sizeof buf, "%ud", nn))
5284 nn /= 7; // now weeks
5285 if (width >= snprintf(buf, sizeof buf, "%uw", nn))
5287 // well shoot, this outta' fit...
5288 return strdup("<inf>");
5292 if (obj->data.top.type == TOP_NAME
5293 && obj->data.top.num >= 0
5294 && obj->data.top.num < 10) {
5295 snprintf(p, 17, "%-17s", cur->cpu[obj->data.top.num]->name);
5296 } else if (obj->data.top.type == TOP_CPU
5297 && obj->data.top.num >= 0
5298 && obj->data.top.num < 10) {
5299 snprintf(p, 7, "%7.3f",
5300 cur->cpu[obj->data.top.
5302 } else if (obj->data.top.type == TOP_PID
5303 && obj->data.top.num >= 0
5304 && obj->data.top.num < 10) {
5305 snprintf(p, 8, "%7i",
5306 cur->cpu[obj->data.top.
5308 } else if (obj->data.top.type == TOP_MEM
5309 && obj->data.top.num >= 0
5310 && obj->data.top.num < 10) {
5311 snprintf(p, 7, "%7.3f",
5312 cur->cpu[obj->data.top.
5314 } else if (obj->data.top.type == TOP_TIME
5315 && obj->data.top.num >= 0
5316 && obj->data.top.num < 10) {
5317 char *time = format_time(cur->cpu[obj->data.top.num]->
5319 snprintf(p, 10, "%9s", time);
5324 if (obj->data.top.type == TOP_NAME
5325 && obj->data.top.num >= 0
5326 && obj->data.top.num < 10) {
5327 snprintf(p, 17, "%-17s",
5328 cur->memu[obj->data.top.
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->memu[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->memu[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->memu[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->memu[obj->data.top.num]->
5353 snprintf(p, 10, "%9s", time);
5360 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5361 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5363 obj->data.tail.last_update = current_update_time;
5368 if (obj->data.tail.fd != -1) {
5369 tail_pipe(obj, p, p_max_size);
5373 fp = fopen(obj->data.tail.logfile, "rt");
5376 /* Send one message, but do not consistently spam on
5377 * missing logfiles. */
5378 if(obj->data.tail.readlines != 0) {
5379 ERR("tail logfile failed to open");
5380 strcpy(obj->data.tail.buffer, "Logfile Missing");
5382 obj->data.tail.readlines = 0;
5383 snprintf(p, p_max_size, "Logfile Missing");
5386 obj->data.tail.readlines = 0;
5387 /* -1 instead of 0 to avoid counting a trailing newline */
5388 fseek(fp, -1, SEEK_END);
5389 bsize = ftell(fp) + 1;
5390 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5391 nl = rev_fcharfind(fp, '\n', iter);
5395 obj->data.tail.readlines = iter;
5396 if(obj->data.tail.readlines < obj->data.tail.wantedlines) {
5397 fseek(fp, 0, SEEK_SET);
5400 fseek(fp, nl+1, SEEK_SET);
5403 /* Make sure bsize is at least 1 byte smaller than
5404 * the buffer max size. */
5405 if(bsize > (long)((text_buffer_size*20) - 1)) {
5406 fseek(fp, bsize - text_buffer_size*20 - 1, SEEK_CUR);
5407 bsize = text_buffer_size*20 - 1;
5409 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
5412 /* Clean up trailing newline, make sure the buffer
5413 * is null terminated. */
5414 if(obj->data.tail.buffer[bsize-1] == '\n')
5415 obj->data.tail.buffer[bsize-1] = '\0';
5417 obj->data.tail.buffer[bsize] = '\0';
5418 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5421 strcpy(obj->data.tail.buffer, "Logfile Empty");
5422 snprintf(p, p_max_size, "Logfile Empty");
5425 } /* if cur_upd_time >= */
5427 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5432 if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
5433 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5435 obj->data.tail.last_update = current_update_time;
5439 fp = fopen(obj->data.tail.logfile, "rt");
5441 /* Send one message, but do not consistently spam on
5442 * missing logfiles. */
5443 if(obj->data.tail.readlines != 0) {
5444 ERR("head logfile failed to open");
5445 strcpy(obj->data.tail.buffer, "Logfile Missing");
5447 obj->data.tail.readlines = 0;
5448 snprintf(p, p_max_size, "Logfile Missing");
5450 obj->data.tail.readlines = 0;
5451 for(iter = obj->data.tail.wantedlines; iter > 0; iter--) {
5452 nl = fwd_fcharfind(fp, '\n', iter);
5456 obj->data.tail.readlines = iter;
5457 /* Make sure nl is at least 1 byte smaller than
5458 * the buffer max size. */
5459 if(nl > (long)((text_buffer_size*20) - 1)) {
5460 nl = text_buffer_size*20 - 1;
5462 nl = fread(obj->data.tail.buffer, 1, nl, fp);
5465 /* Clean up trailing newline, make sure the buffer
5466 * is null terminated. */
5467 if (obj->data.tail.buffer[nl-1] == '\n') {
5468 obj->data.tail.buffer[nl-1] = '\0';
5471 obj->data.tail.buffer[nl] = '\0';
5473 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
5476 strcpy(obj->data.tail.buffer, "Logfile Empty");
5477 snprintf(p, p_max_size, "Logfile Empty");
5479 } /* if fp == null */
5480 } /* cur_upd_time >= */
5482 //parse_conky_vars(obj->data.tail.buffer, p, cur);
5485 #ifdef TCP_PORT_MONITOR
5488 /* grab a pointer to this port monitor */
5489 tcp_port_monitor_t * p_monitor =
5490 find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
5491 obj->data.tcp_port_monitor.port_range_begin,
5492 obj->data.tcp_port_monitor.port_range_end );
5494 snprintf(p, p_max_size, "monitor not found");
5498 /* now grab the text of interest */
5499 if ( peek_tcp_port_monitor( p_monitor,
5500 obj->data.tcp_port_monitor.item,
5501 obj->data.tcp_port_monitor.connection_index,
5502 p, p_max_size ) != 0 )
5504 snprintf(p, p_max_size, "monitor peek error");
5513 iconv_converting = 1;
5514 iconv_selected = obj->a;
5519 iconv_converting = 0;
5525 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
5527 OBJ(entropy_poolsize)
5529 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
5533 double entropy_perc;
5534 entropy_perc = (double)cur->entropy.entropy_avail /
5535 (double)cur->entropy.poolsize;
5536 new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f));
5544 unsigned int a = strlen(p);
5547 if (a > 0 && iconv_converting && iconv_selected > 0 && (iconv_cd[iconv_selected - 1] != (iconv_t)(-1))) {
5549 size_t dummy1, dummy2;
5550 char *ptr = buff_in;
5553 dummy1 = dummy2 = a;
5555 strncpy(buff_in, p, P_MAX_SIZE);
5557 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
5558 while (dummy1 > 0) {
5559 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, &outptr, &dummy2);
5561 ERR("Iconv codeset conversion failed");
5566 /* It is nessecary when we are converting from multibyte to singlebyte codepage */
5577 double current_update_time, last_update_time;
5579 static void generate_text()
5581 struct information *cur = &info;
5589 current_update_time = get_time();
5592 /* fix diskio rates to b/s (use update_interval */
5593 diskio_read_value = diskio_read_value / update_interval;
5594 diskio_write_value = diskio_write_value / update_interval;
5595 diskio_value = diskio_value / update_interval;
5598 /* add things to the buffer */
5604 generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
5606 if (stuff_in_upper_case) {
5617 last_update_time = current_update_time;
5624 static void set_font()
5628 if (window.xftdraw != NULL) {
5629 XftDrawDestroy(window.xftdraw);
5631 window.xftdraw = XftDrawCreate(display, window.drawable,
5632 DefaultVisual(display,
5634 DefaultColormap(display,
5639 XSetFont(display, window.gc, fonts[selected_font].font->fid);
5645 static inline int get_string_width(const char *s)
5648 return *s ? calc_text_width(s, strlen(s)) : 0;
5654 static inline int get_string_width_special(char *s)
5667 if (*p == SPECIAL_CHAR) {
5668 /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
5669 for (i = 0; i < strlen(p); i++) {
5670 *(p + i) = *(p + i + 1);
5672 if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
5673 width += specials[special_index+index].width;
5680 if (strlen(final) > 1) {
5681 width += calc_text_width(final, strlen(final));
5691 static void text_size_updater(char *s);
5693 int last_font_height;
5694 static void update_text_area()
5698 /* update text size if it isn't fixed */
5703 text_width = minimum_width;
5706 last_font_height = font_height();
5707 for_each_line(text_buffer, text_size_updater);
5709 if (text_height < minimum_height)
5710 text_height = minimum_height;
5711 if (text_width > maximum_width && maximum_width > 0)
5712 text_width = maximum_width;
5715 /* get text position on workarea */
5716 switch (text_alignment) {
5723 x = workarea[2] - text_width - gap_x;
5730 y = workarea[3] - text_height - gap_y;
5734 x = workarea[2] - text_width - gap_x;
5735 y = workarea[3] - text_height - gap_y;
5739 case NONE: // Let the WM manage the window
5750 if (own_window && !fixed_pos) {
5753 text_start_x = border_margin + 1;
5754 text_start_y = border_margin + 1;
5755 window.x = x - border_margin - 1;
5756 window.y = y - border_margin - 1;
5760 /* If window size doesn't match to workarea's size, then window
5761 * probably includes panels (gnome).
5762 * Blah, doesn't work on KDE. */
5763 if (workarea[2] != window.width
5764 || workarea[3] != window.height) {
5778 static int cur_x, cur_y; /* current x and y for drawing */
5779 static int draw_mode; /* FG, BG or OUTLINE */
5780 static long current_color;
5783 static void text_size_updater(char *s)
5787 /* get string widths and skip specials */
5790 if (*p == SPECIAL_CHAR) {
5792 w += get_string_width(s);
5795 if (specials[special_index].type == BAR
5796 || specials[special_index].type == GRAPH) {
5797 w += specials[special_index].width;
5798 if (specials[special_index].height > last_font_height) {
5799 last_font_height = specials[special_index].height;
5800 last_font_height += font_ascent();
5802 } else if (specials[special_index].type == OFFSET) {
5803 if (specials[special_index].arg > 0) {
5804 w += specials[special_index].arg;
5806 } else if (specials[special_index].type == VOFFSET) {
5807 last_font_height += specials[special_index].arg;
5808 } else if (specials[special_index].type == GOTO) {
5809 if (specials[special_index].arg > cur_x) {
5810 w = (int)specials[special_index].arg;
5812 } else if (specials[special_index].type == TAB) {
5813 int start = specials[special_index].arg;
5814 int step = specials[special_index].width;
5815 if (!step || step < 0)
5817 w += step - (cur_x - text_start_x - start) % step;
5818 } else if (specials[special_index].type == FONT) {
5819 selected_font = specials[special_index].font_added;
5820 if (font_height() > last_font_height) {
5821 last_font_height = font_height();
5830 w += get_string_width(s);
5831 if (w > text_width) {
5834 if (text_width > maximum_width && maximum_width) {
5835 text_width = maximum_width;
5838 text_height += last_font_height;
5839 last_font_height = font_height();
5843 static inline void set_foreground_color(long c)
5846 XSetForeground(display, window.gc, c);
5850 static void draw_string(const char *s)
5854 int i, i2, pos, width_of_s;
5857 width_of_s = get_string_width(s);
5858 if (out_to_console) {
5860 fflush(stdout); /* output immediately, don't buffer */
5862 memset(tmpstring1,0,TEXT_BUFFER_SIZE);
5863 memset(tmpstring2,0,TEXT_BUFFER_SIZE);
5864 strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
5868 snprintf(space, 2, " ");
5870 max = ((text_width - width_of_s) / get_string_width(space));
5873 * This code looks for tabs in the text and coverts them to spaces.
5874 * The trick is getting the correct number of spaces,
5875 * and not going over the window's size without forcing
5876 * the window larger.
5878 for (i = 0; i < TEXT_BUFFER_SIZE; i++) {
5879 if (tmpstring1[i] == '\t') // 9 is ascii tab
5883 i2 < (8 - (1 + pos) % 8) && added <= max;
5886 if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
5887 fprintf(stderr,"buffer overrun detected\n");
5889 tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
5894 if (tmpstring1[i] != 9) {
5896 if ( pos > TEXT_BUFFER_SIZE-1 )
5897 fprintf(stderr,"buffer overrun detected\n");
5899 tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
5905 if (text_width == maximum_width) {
5906 /* this means the text is probably pushing the limit, so we'll chop it */
5907 while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
5908 tmpstring2[strlen(tmpstring2)-1] = '\0';
5918 c.pixel = current_color;
5919 XQueryColor(display, DefaultColormap(display, screen), &c);
5922 c2.color.red = c.red;
5923 c2.color.green = c.green;
5924 c2.color.blue = c.blue;
5925 c2.color.alpha = fonts[selected_font].font_alpha;
5927 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5928 cur_x, cur_y, (XftChar8 *) s,
5931 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
5932 cur_x, cur_y, (XftChar8 *) s,
5938 XDrawString(display, window.drawable, window.gc,
5939 cur_x, cur_y, s, strlen(s));
5941 cur_x += width_of_s;
5943 memcpy(tmpstring1, s, TEXT_BUFFER_SIZE);
5946 long redmask, greenmask, bluemask;
5948 void set_up_gradient()
5951 colour_depth = DisplayPlanes(display, screen);
5955 if (colour_depth != 24 && colour_depth != 16) {
5956 ERR("using non-standard colour depth, gradients may look like a lolly-pop");
5962 for(i = (colour_depth / 3)-1; i>=0; i--) {
5964 greenmask |= 1 << i;
5967 if (colour_depth%3 == 1) {
5968 greenmask |= 1 << (colour_depth / 3);
5970 redmask = redmask << (2*colour_depth / 3 + colour_depth%3);
5971 greenmask = greenmask << (colour_depth / 3);
5974 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 */
5976 int red1, green1, blue1; // first colour
5977 int red2, green2, blue2; // second colour
5978 int red3 = 0, green3 = 0, blue3 = 0; // difference
5979 short redshift = (2*colour_depth / 3 + colour_depth%3);
5980 short greenshift = (colour_depth / 3);
5981 red1 = (first_colour & redmask) >> redshift;
5982 green1 = (first_colour & greenmask) >> greenshift;
5983 blue1 = first_colour & bluemask;
5984 red2 = (last_colour & redmask) >> redshift;
5985 green2 = (last_colour & greenmask) >> greenshift;
5986 blue2 = last_colour & bluemask;
5993 if (green1 > green2) {
5996 if (green1 < green2) {
5999 if (blue1 > blue2) {
6002 if (blue1 < blue2) {
6017 if (red1 > bluemask) {
6020 if (green1 > bluemask) {
6023 if (blue1 > bluemask) {
6026 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
6030 inline unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
6031 if (colour_depth == 0) {
6034 int red1, green1, blue1; // first colour
6035 int red2, green2, blue2; // second colour
6036 long redshift = (2*colour_depth / 3 + colour_depth%3);
6037 long greenshift = (colour_depth / 3);
6038 int red3 = 0, green3 = 0, blue3 = 0; // difference
6039 red1 = (first_colour & redmask) >> redshift;
6040 green1 = (first_colour & greenmask) >> greenshift;
6041 blue1 = first_colour & bluemask;
6042 red2 = (last_colour & redmask) >> redshift;
6043 green2 = (last_colour & greenmask) >> greenshift;
6044 blue2 = last_colour & bluemask;
6045 red3 = abs(red1 - red2);
6046 green3 = abs(green1 - green2);
6047 blue3 = abs(blue1 - blue2);
6056 static void draw_line(char *s)
6060 cur_x = text_start_x;
6061 cur_y += font_ascent();
6063 short font_h = font_height();
6065 /* find specials and draw stuff */
6068 if (*p == SPECIAL_CHAR) {
6071 /* draw string before special */
6078 switch (specials[special_index].type) {
6079 case HORIZONTAL_LINE:
6082 specials[special_index].height;
6083 int mid = font_ascent() / 2;
6084 w = text_start_x + text_width -
6087 XSetLineAttributes(display,
6092 XDrawLine(display, window.drawable,
6103 specials[special_index].height;
6105 specials[special_index].arg;
6106 int mid = font_ascent() / 2;
6107 char ss[2] = { s, s };
6108 w = text_start_x + text_width -
6111 XSetLineAttributes(display,
6116 XSetDashes(display, window.gc, 0,
6118 XDrawLine(display, window.drawable,
6128 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
6132 specials[special_index].height;
6134 specials[special_index].arg;
6135 int by = cur_y - (font_ascent() / 2) - 1;
6136 if (h < font_height()) {
6139 w = specials[special_index].width;
6142 text_width - cur_x - 1;
6146 XSetLineAttributes(display,
6152 XDrawRectangle(display,
6156 XFillRectangle(display,
6160 w * bar_usage / 255,
6162 if (specials[special_index].
6164 && specials[special_index].
6168 [special_index].height;
6175 if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
6179 specials[special_index].height;
6180 unsigned long last_colour = current_color;
6181 int by = cur_y - (font_ascent()/2) - 1;
6182 if (h < font_height()) {
6185 w = specials[special_index].width;
6187 w = text_start_x + text_width - cur_x - 1;
6190 if (draw_graph_borders) {
6191 XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
6192 XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
6194 XSetLineAttributes(display,
6201 int gradient_size = 0;
6202 float gradient_factor = 0;
6203 float gradient_update = 0;
6204 unsigned long tmpcolour = current_color;
6205 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
6206 tmpcolour = specials[special_index].last_colour;
6207 gradient_size = gradient_max(specials[special_index].last_colour, specials[special_index].first_colour);
6208 gradient_factor = (float)gradient_size / (w - 2);
6210 for (i = w - 2; i > -1; i--) {
6211 if (specials[special_index].last_colour != 0 || specials[special_index].first_colour != 0) {
6212 XSetForeground(display, window.gc, tmpcolour);
6213 gradient_update += gradient_factor;
6214 while (gradient_update > 0) {
6215 tmpcolour = do_gradient(tmpcolour, specials[special_index].first_colour);
6219 if ((w - i) / ((float) (w - 2) / (specials[special_index].graph_width)) > j && j < MAX_GRAPH_DEPTH - 3) {
6222 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 */
6224 if (specials[special_index].
6226 && specials[special_index].
6230 [special_index].height;
6232 /* if (draw_mode == BG) {
6233 set_foreground_color(default_bg_color);
6235 else if (draw_mode == OUTLINE) {
6236 set_foreground_color(default_out_color);
6238 set_foreground_color(default_fg_color);
6240 set_foreground_color(last_colour);
6246 int old = font_ascent();
6247 cur_y -= font_ascent();
6248 selected_font = specials[special_index].font_added;
6249 if (cur_y + font_ascent() < cur_y + old) {
6252 cur_y += font_ascent();
6258 if (draw_mode == FG)
6259 set_foreground_color(specials
6265 if (draw_mode == BG)
6266 set_foreground_color(specials
6272 if (draw_mode == OUTLINE)
6273 set_foreground_color(specials
6279 w += specials[special_index].arg;
6283 cur_y += specials[special_index].arg;
6287 if (specials[special_index].arg >= 0)
6288 cur_x = (int)specials[special_index].arg;
6293 int start = specials[special_index].arg;
6294 int step = specials[special_index].width;
6295 if (!step || step < 0)
6297 w = step - (cur_x - text_start_x - start) % step;
6303 int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
6304 /*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);*/
6305 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
6306 cur_x = pos_x - specials[special_index].arg;
6313 int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
6314 /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
6315 /*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);*/
6317 specials[special_index].arg)
6320 [special_index].arg;
6337 if (cur_y_add > 0) {
6339 cur_y -= font_descent();
6344 cur_y += font_descent();
6348 static void draw_text()
6351 cur_y = text_start_y;
6354 if (draw_borders && border_width > 0) {
6355 unsigned int b = (border_width + 1) / 2;
6357 if (stippled_borders) {
6359 { stippled_borders, stippled_borders };
6360 XSetLineAttributes(display, window.gc,
6361 border_width, LineOnOffDash,
6362 CapButt, JoinMiter);
6363 XSetDashes(display, window.gc, 0, ss, 2);
6365 XSetLineAttributes(display, window.gc,
6366 border_width, LineSolid,
6367 CapButt, JoinMiter);
6370 XDrawRectangle(display, window.drawable, window.gc,
6371 text_start_x - border_margin + b,
6372 text_start_y - border_margin + b,
6373 text_width + border_margin * 2 - 1 - b * 2,
6374 text_height + border_margin * 2 - 1 -
6381 for_each_line(text_buffer, draw_line);
6384 static void draw_stuff()
6388 if (draw_shades && !draw_outline) {
6391 set_foreground_color(default_bg_color);
6401 for (i = -1; i < 2; i++)
6402 for (j = -1; j < 2; j++) {
6403 if (i == 0 && j == 0)
6407 set_foreground_color(default_out_color);
6408 draw_mode = OUTLINE;
6415 set_foreground_color(default_fg_color);
6423 swap.swap_window = window.window;
6424 swap.swap_action = XdbeBackground;
6425 XdbeSwapBuffers(display, &swap, 1);
6431 static void clear_text(int exposures)
6435 return; /* The swap action is XdbeBackground, which clears */
6439 /* there is some extra space for borders and outlines */
6440 XClearArea(display, window.window,
6441 text_start_x - border_margin - 1,
6442 text_start_y - border_margin - 1,
6443 text_width + border_margin * 2 + 2,
6444 text_height + border_margin * 2 + 2,
6445 exposures ? True : 0);
6450 static int need_to_update;
6452 /* update_text() generates new text and clears old text area */
6453 static void update_text()
6462 static void main_loop()
6464 #ifdef SIGNAL_BLOCKING
6465 sigset_t newmask, oldmask;
6467 sigemptyset(&newmask);
6468 sigaddset(&newmask,SIGINT);
6469 sigaddset(&newmask,SIGTERM);
6470 sigaddset(&newmask,SIGUSR1);
6474 Region region = XCreateRegion();
6476 int event_base, error_base;
6477 if (!XDamageQueryExtension (display, &event_base, &error_base)) {
6478 ERR("Xdamage extension unavailable");
6480 Damage damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
6481 XserverRegion region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
6482 XserverRegion part = XFixesCreateRegionFromWindow(display, window.window, 0);
6483 #endif /* HAVE_XDAMAGE */
6487 while (total_run_times == 0 || info.looped < total_run_times) {
6490 #ifdef SIGNAL_BLOCKING
6491 /* block signals. we will inspect for pending signals later */
6492 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
6493 CRIT_ERR("unable to sigprocmask()");
6499 /* wait for X event or timeout */
6501 if (!XPending(display)) {
6506 update_interval - (get_time() -
6512 tv.tv_sec = (long) t;
6513 tv.tv_usec = (long) (t * 1000000) % 1000000;
6515 FD_SET(ConnectionNumber(display), &fdsr);
6518 s = select(ConnectionNumber(display) + 1, &fdsr, 0,
6521 usleep(update_interval*1000000); /* FIXME just sleep for the interval time if no X11 */
6526 ERR("can't select(): %s",
6537 if (need_to_update) {
6539 int wx = window.x, wy = window.y;
6547 /* resize window if it isn't right size */
6549 (text_width + border_margin * 2 + 1 !=
6551 || text_height + border_margin * 2 + 1 !=
6555 border_margin * 2 + 1;
6558 border_margin * 2 + 1;
6559 XResizeWindow(display,
6564 set_transparent_background(window.window);
6568 /* move window if it isn't in right position */
6571 || window.y != wy)) {
6572 XMoveWindow(display, window.window,
6573 window.x, window.y);
6583 r.x = text_start_x - border_margin;
6584 r.y = text_start_y - border_margin;
6585 r.width = text_width + border_margin * 2;
6586 r.height = text_height + border_margin * 2;
6587 XUnionRectWithRegion(&r, region, region);
6592 /* handle X events */
6594 while (XPending(display)) {
6596 XNextEvent(display, &ev);
6603 r.width = ev.xexpose.width;
6604 r.height = ev.xexpose.height;
6605 XUnionRectWithRegion(&r, region,
6611 case ReparentNotify:
6612 /* set background to ParentRelative for all parents */
6614 set_transparent_background(window.
6619 case ConfigureNotify:
6621 /* if window size isn't what expected, set fixed size */
6622 if (ev.xconfigure.width !=
6624 || ev.xconfigure.height !=
6626 if (window.width != 0
6627 && window.height != 0)
6630 /* clear old stuff before screwing up size and pos */
6636 if (XGetWindowAttributes(display, window.window, &attrs)) {
6651 border_margin * 2 - 1;
6654 border_margin * 2 - 1;
6655 if (text_width > maximum_width && maximum_width > 0)
6656 text_width = maximum_width;
6659 /* if position isn't what expected, set fixed pos, total_updates
6660 * avoids setting fixed_pos when window is set to weird locations
6662 /*if (total_updates >= 2 this is broken
6664 && (window.x != ev.xconfigure.x
6667 && (ev.xconfigure.x != 0
6668 || ev.xconfigure.y != 0)) {
6678 /* if an ordinary window with decorations */
6679 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6681 /* allow conky to hold input focus.*/
6686 /* forward the click to the desktop window */
6687 XUngrabPointer(display, ev.xbutton.time);
6688 ev.xbutton.window = window.desktop;
6689 XSendEvent(display, ev.xbutton.window, False, ButtonPressMask, &ev);
6690 XSetInputFocus(display, ev.xbutton.window,RevertToParent,ev.xbutton.time);
6698 /* if an ordinary window with decorations */
6699 if ((window.type==TYPE_NORMAL) && (!TEST_HINT(window.hints,HINT_UNDECORATED)))
6701 /* allow conky to hold input focus.*/
6706 /* forward the release to the desktop window */
6707 ev.xbutton.window = window.desktop;
6708 XSendEvent(display, ev.xbutton.window, False, ButtonReleaseMask, &ev);
6717 if (ev.type == event_base + XDamageNotify) {
6718 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
6719 XFixesSetRegion(display, part, &dev->area, 1);
6720 XFixesUnionRegion(display, region2, region2, part);
6722 #endif /* HAVE_XDAMAGE */
6727 XDamageSubtract(display, damage, region2, None);
6728 XFixesSetRegion(display, region2, 0, 0);
6729 #endif /* HAVE_XDAMAGE */
6731 /* XDBE doesn't seem to provide a way to clear the back buffer without
6732 * interfering with the front buffer, other than passing XdbeBackground
6733 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
6734 * redraw the text even if it wasn't part of the exposed area. OTOH,
6735 * if we're not going to call draw_stuff at all, then no swap happens
6736 * and we can safely do nothing.
6739 if (!XEmptyRegion(region)) {
6743 r.x = text_start_x - border_margin;
6744 r.y = text_start_y - border_margin;
6745 r.width = text_width + border_margin * 2;
6746 r.height = text_height + border_margin * 2;
6747 XUnionRectWithRegion(&r, region, region);
6750 XSetRegion(display, window.gc, region);
6753 XftDrawSetClip(window.xftdraw, region);
6759 XDestroyRegion(region);
6760 region = XCreateRegion();
6764 #ifdef SIGNAL_BLOCKING
6765 /* unblock signals of interest and let handler fly */
6766 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
6767 CRIT_ERR("unable to sigprocmask()");
6770 switch(g_signal_pending) {
6773 ERR("received SIGUSR1. reloading the config file.");
6780 ERR("received SIGINT or SIGTERM to terminate. bye!");
6783 XDestroyRegion(region);
6786 return; /* return from main_loop */
6791 /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
6792 * but didn't write any code to deal with it. if you don't want to
6793 * handle a signal, don't set a handler on it in the first place. */
6794 if (g_signal_pending)
6795 ERR("ignoring signal (%d)", g_signal_pending);
6802 #if defined(X11) && defined(HAVE_XDAMAGE)
6803 XDamageDestroy(display, damage);
6804 XFixesDestroyRegion(display, region2);
6805 XFixesDestroyRegion(display, part);
6806 XDestroyRegion(region);
6808 #endif /* X11 && HAVE_XDAMAGE */
6811 static void load_config_file(const char *);
6813 /* reload the config file */
6814 void reload_config(void)
6816 timed_thread_destroy_registered_threads ();
6818 if (info.cpu_usage) {
6819 free(info.cpu_usage);
6820 info.cpu_usage = NULL;
6829 if (info.mpd.title) {
6830 free(info.mpd.title);
6833 if (info.mpd.artist) {
6834 free(info.mpd.artist);
6835 info.mpd.artist = 0;
6837 if (info.mpd.album) {
6838 free(info.mpd.album);
6841 if (info.mpd.random) {
6842 free(info.mpd.random);
6843 info.mpd.random = 0;
6845 if (info.mpd.repeat) {
6846 free(info.mpd.repeat);
6847 info.mpd.repeat = 0;
6849 if (info.mpd.track) {
6850 free(info.mpd.track);
6853 if (info.mpd.name) {
6854 free(info.mpd.name);
6857 if (info.mpd.file) {
6858 free(info.mpd.file);
6861 if (info.mpd.status) {
6862 free(info.mpd.status);
6863 info.mpd.status = 0;
6871 #ifdef TCP_PORT_MONITOR
6872 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6875 if (current_config) {
6877 load_config_file(current_config);
6879 /* re-init specials array */
6880 if ((specials = realloc ((void *)specials, sizeof(struct special_t)*max_specials)) == 0)
6881 ERR("failed to realloc specials array");
6886 XClearWindow(display, RootWindow(display, screen)); // clear the window first
6889 #ifdef TCP_PORT_MONITOR
6890 info.p_tcp_port_monitor_collection = NULL;
6893 if (create_audacious_thread() !=0)
6894 CRIT_ERR("unable to create audacious thread!");
6895 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
6897 extract_variable_text(text);
6906 timed_thread_destroy_registered_threads ();
6908 if (info.cpu_usage) {
6909 free(info.cpu_usage);
6910 info.cpu_usage = NULL;
6915 XdbeDeallocateBackBufferName(display, window.back_buffer);
6921 XDestroyWindow(display, window.window);
6922 XClearWindow(display, RootWindow(display, screen));
6928 XClearWindow(display, RootWindow(display, screen));
6933 XFreeGC(display, window.gc);
6937 free_text_objects(text_object_count, text_objects);
6938 text_object_count = 0;
6939 text_objects = NULL;
6944 free(current_config);
6946 #ifdef TCP_PORT_MONITOR
6947 destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
6948 info.p_tcp_port_monitor_collection = NULL;
6956 for(i=0;i<special_count;i++)
6957 if(specials[i].type == GRAPH)
6958 free(specials[i].graph);
6964 static int string_to_bool(const char *s)
6968 if (strcasecmp(s, "yes") == 0)
6970 if (strcasecmp(s, "true") == 0)
6972 if (strcasecmp(s, "1") == 0)
6977 static enum alignment string_to_alignment(const char *s)
6979 if (strcasecmp(s, "top_left") == 0)
6981 else if (strcasecmp(s, "top_right") == 0)
6983 else if (strcasecmp(s, "bottom_left") == 0)
6985 else if (strcasecmp(s, "bottom_right") == 0)
6986 return BOTTOM_RIGHT;
6987 else if (strcasecmp(s, "tl") == 0)
6989 else if (strcasecmp(s, "tr") == 0)
6991 else if (strcasecmp(s, "bl") == 0)
6993 else if (strcasecmp(s, "br") == 0)
6994 return BOTTOM_RIGHT;
6995 else if (strcasecmp(s, "none") == 0)
7002 static void set_default_configurations(void)
7004 fork_to_background = 0;
7005 total_run_times = 0;
7006 info.cpu_avg_samples = 2;
7007 info.net_avg_samples = 2;
7013 strcpy(info.mpd.host, "localhost");
7014 info.mpd.port = 6600;
7015 info.mpd.status = NULL;
7016 info.mpd.artist = NULL;
7017 info.mpd.album = NULL;
7018 info.mpd.title = NULL;
7019 info.mpd.random = NULL;
7020 info.mpd.track = NULL;
7021 info.mpd.name = NULL;
7022 info.mpd.file = NULL;
7025 info.xmms2.artist = NULL;
7026 info.xmms2.album = NULL;
7027 info.xmms2.title = NULL;
7028 info.xmms2.genre = NULL;
7029 info.xmms2.comment = NULL;
7030 info.xmms2.decoder = NULL;
7031 info.xmms2.transport = NULL;
7032 info.xmms2.url = NULL;
7033 info.xmms2.status = NULL;
7042 default_fg_color = WhitePixel(display, screen);
7043 default_bg_color = BlackPixel(display, screen);
7044 default_out_color = BlackPixel(display, screen);
7045 color0 = default_fg_color;
7046 color1 = default_fg_color;
7047 color2 = default_fg_color;
7048 color3 = default_fg_color;
7049 color4 = default_fg_color;
7050 color5 = default_fg_color;
7051 color6 = default_fg_color;
7052 color7 = default_fg_color;
7053 color8 = default_fg_color;
7054 color9 = default_fg_color;
7057 draw_graph_borders = 1;
7059 set_first_font("6x10");
7067 window.type=TYPE_NORMAL;
7069 strcpy(window.class_name, "Conky");
7071 sprintf(window.title,"Conky (%s)",info.uname_s.nodename);
7073 stippled_borders = 0;
7076 text_alignment = BOTTOM_LEFT;
7079 free(current_mail_spool);
7082 variable_substitute(MAIL_FILE, buf, 256);
7084 current_mail_spool = strdup(buf);
7088 update_interval = 3.0;
7089 info.music_player_interval = 1.0;
7090 stuff_in_upper_case = 0;
7092 #ifdef TCP_PORT_MONITOR
7093 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7097 static void load_config_file(const char *f)
7099 #define CONF_ERR ERR("%s: %d: config file error", f, line)
7103 set_default_configurations();
7109 char buf[256], *p, *p2, *name, *value;
7111 if (fgets(buf, 256, fp) == NULL)
7116 /* break at comment */
7117 p2 = strchr(p, '#');
7122 while (*p && isspace((int) *p))
7125 continue; /* empty line */
7131 while (*p2 && !isspace((int) *p2))
7134 *p2 = '\0'; /* break at name's end */
7141 while (*p && isspace((int) *p))
7146 p2 = value + strlen(value);
7147 while (isspace((int) *(p2 - 1)))
7153 #define CONF2(a) if (strcasecmp(name, a) == 0)
7154 #define CONF(a) else CONF2(a)
7155 #define CONF3(a,b) \
7156 else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
7160 CONF2("alignment") {
7162 int a = string_to_alignment(value);
7170 CONF("background") {
7171 fork_to_background = string_to_bool(value);
7175 CONF2("background") {
7176 fork_to_background = string_to_bool(value);
7180 CONF("border_margin") {
7182 border_margin = strtol(value, 0, 0);
7186 CONF("border_width") {
7188 border_width = strtol(value, 0, 0);
7194 color0 = get_x11_color(value);
7200 color1 = get_x11_color(value);
7206 color2 = get_x11_color(value);
7212 color3 = get_x11_color(value);
7218 color4 = get_x11_color(value);
7224 color5 = get_x11_color(value);
7230 color6 = get_x11_color(value);
7236 color7 = get_x11_color(value);
7242 color8 = get_x11_color(value);
7248 color9 = get_x11_color(value);
7252 CONF("default_color") {
7254 default_fg_color = get_x11_color(value);
7258 CONF3("default_shade_color", "default_shadecolor") {
7260 default_bg_color = get_x11_color(value);
7264 CONF3("default_outline_color", "default_outlinecolor") {
7266 default_out_color = get_x11_color(value);
7273 info.mail = parse_mail_args(IMAP, value);
7280 info.mail = parse_mail_args(POP3, value);
7288 strncpy(info.mpd.host, value, 127);
7294 info.mpd.port = strtol(value, 0, 0);
7295 if (info.mpd.port < 1
7296 || info.mpd.port > 0xffff)
7300 CONF("mpd_password") {
7302 strncpy(info.mpd.password, value, 127);
7307 CONF("music_player_interval") {
7309 info.music_player_interval = strtod(value, 0);
7314 CONF("sensor_device") {
7316 sensor_device = strtol(value, 0, 0);
7321 CONF("cpu_avg_samples") {
7323 cpu_avg_samples = strtol(value, 0, 0);
7324 if (cpu_avg_samples < 1
7325 || cpu_avg_samples > 14)
7334 CONF("net_avg_samples") {
7336 net_avg_samples = strtol(value, 0, 0);
7337 if (net_avg_samples < 1
7338 || net_avg_samples > 14)
7354 CONF("double_buffer") {
7355 use_xdbe = string_to_bool(value);
7359 CONF("override_utf8_locale") {
7360 utf8_mode = string_to_bool(value);
7363 CONF("draw_borders") {
7364 draw_borders = string_to_bool(value);
7366 CONF("draw_graph_borders") {
7367 draw_graph_borders = string_to_bool(value);
7369 CONF("draw_shades") {
7370 draw_shades = string_to_bool(value);
7372 CONF("draw_outline") {
7373 draw_outline = string_to_bool(value);
7376 CONF("out_to_console") {
7377 out_to_console = string_to_bool(value);
7379 CONF("use_spacer") {
7380 use_spacer = string_to_bool(value);
7385 use_xft = string_to_bool(value);
7389 set_first_font(value);
7394 if (value && font_count >= 0)
7395 fonts[0].font_alpha = atof(value)
7404 if (string_to_bool(value))
7405 ERR("Xft not enabled");
7408 /* xftfont silently ignored when no Xft */
7411 /* xftalpha is silently ignored when no Xft */
7416 set_first_font(value);
7425 gap_x = atoi(value);
7431 gap_y = atoi(value);
7436 CONF("mail_spool") {
7439 variable_substitute(value, buf, 256);
7443 if (current_mail_spool)
7444 free(current_mail_spool);
7445 current_mail_spool = strdup(buf);
7451 CONF("minimum_size") {
7454 (value, "%d %d", &minimum_width,
7455 &minimum_height) != 2)
7458 &minimum_width) != 1)
7463 CONF("maximum_width") {
7465 if (sscanf(value, "%d", &maximum_width) != 1)
7471 CONF("no_buffers") {
7472 no_buffers = string_to_bool(value);
7474 CONF("top_cpu_separate") {
7475 cpu_separate = string_to_bool(value);
7477 CONF("pad_percents") {
7478 pad_percents = atoi(value);
7482 CONF("own_window") {
7484 own_window = string_to_bool(value);
7488 CONF("own_window_class") {
7491 memset(window.class_name,0,sizeof(window.class_name));
7492 strncpy(window.class_name, value, sizeof(window.class_name)-1);
7497 CONF("own_window_title") {
7500 memset(window.title,0,sizeof(window.title));
7501 strncpy(window.title, value, sizeof(window.title)-1);
7506 CONF("own_window_transparent") {
7508 set_transparent = string_to_bool(value);
7512 CONF("own_window_colour") {
7514 background_colour = get_x11_color(value);
7516 ERR("Invalid colour for own_winder_colour (try omitting the '#' for hex colours");
7519 CONF("own_window_hints") {
7521 char *p_hint, *p_save;
7522 char delim[] = ", ";
7524 /* tokenize the value into individual hints */
7525 if ((p_hint=strtok_r(value, delim, &p_save)) != NULL)
7527 /*fprintf(stderr, "hint [%s] parsed\n", p_hint);*/
7528 if (strncmp(p_hint,"undecorate",10) == 0)
7529 SET_HINT(window.hints,HINT_UNDECORATED);
7530 else if (strncmp(p_hint,"below",5) == 0)
7531 SET_HINT(window.hints,HINT_BELOW);
7532 else if (strncmp(p_hint,"above",5) == 0)
7533 SET_HINT(window.hints,HINT_ABOVE);
7534 else if (strncmp(p_hint,"sticky",6) == 0)
7535 SET_HINT(window.hints,HINT_STICKY);
7536 else if (strncmp(p_hint,"skip_taskbar",12) == 0)
7537 SET_HINT(window.hints,HINT_SKIP_TASKBAR);
7538 else if (strncmp(p_hint,"skip_pager",10) == 0)
7539 SET_HINT(window.hints,HINT_SKIP_PAGER);
7543 p_hint=strtok_r(NULL, delim, &p_save);
7545 while (p_hint!=NULL);
7550 CONF("own_window_type") {
7552 if (strncmp(value,"normal",6)==0)
7553 window.type = TYPE_NORMAL;
7554 else if (strncmp(value,"desktop",7)==0)
7555 window.type = TYPE_DESKTOP;
7556 else if (strncmp(value,"override",8)==0)
7557 window.type = TYPE_OVERRIDE;
7565 CONF("stippled_borders") {
7567 stippled_borders = strtol(value, 0, 0);
7569 stippled_borders = 4;
7573 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> temp 1}");
7576 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> temp 2}");
7578 CONF("update_interval") {
7580 update_interval = strtod(value, 0);
7583 if (info.music_player_interval == 0) {
7584 // default to update_interval
7585 info.music_player_interval = update_interval;
7588 CONF("total_run_times") {
7590 total_run_times = strtod(value, 0);
7595 stuff_in_upper_case = string_to_bool(value);
7597 CONF("max_specials") {
7599 max_specials = atoi(value);
7603 CONF("max_user_text") {
7605 max_user_text = atoi(value);
7609 CONF("text_buffer_size") {
7611 text_buffer_size = atoi(value);
7626 int l = strlen(text);
7627 if (fgets(buf, 256, fp) == NULL)
7630 realloc(text, l + strlen(buf)
7634 if (strlen(text) > max_user_text)
7638 text_lines = line + 1;
7641 #ifdef TCP_PORT_MONITOR
7642 CONF("max_port_monitor_connections")
7645 (sscanf(value, "%d", &tcp_port_monitor_args.max_port_monitor_connections) != 1)
7646 || tcp_port_monitor_args.max_port_monitor_connections < 0 )
7648 /* an error. use default, warn and continue. */
7649 tcp_port_monitor_args.max_port_monitor_connections =
7650 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7653 else if ( tcp_port_monitor_args.max_port_monitor_connections == 0 )
7655 /* no error, just use default */
7656 tcp_port_monitor_args.max_port_monitor_connections =
7657 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7659 /* else tcp_port_monitor_args.max_port_monitor_connections > 0 as per config */
7664 ERR("%s: %d: no such configuration: '%s'", f, line, name);
7673 if (info.music_player_interval == 0) {
7674 // default to update_interval
7675 info.music_player_interval = update_interval;
7680 /* : means that character before that takes an argument */
7681 static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
7693 static const struct option
7695 { "help", 0, NULL, 'h' },
7696 { "version", 0, NULL, 'V' },
7697 { "config", 1, NULL, 'c' },
7698 { "daemonize", 0, NULL, 'd' },
7700 { "alignment", 1, NULL, 'a'},
7701 { "font", 1, NULL, 'f'},
7703 { "own-window", 0, NULL, 'o'},
7706 { "double-buffer", 0, NULL, 'b'},
7708 { "window-id", 1, NULL, 'w'},
7710 { "text", 1, NULL, 't' },
7711 { "interval", 0, NULL, 'u' },
7715 int main(int argc, char **argv)
7717 struct sigaction act, oact;
7720 memset(&info, 0, sizeof(info));
7722 #ifdef TCP_PORT_MONITOR
7723 tcp_port_monitor_args.max_port_monitor_connections = MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
7726 /* handle command line parameters that don't change configs */
7731 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) &&
7732 *s) || ((s = getenv("LANG")) && *s)) {
7733 temp = (char *)malloc((strlen(s) + 1) * sizeof(char));
7735 ERR("malloc failed");
7737 for (x = 0; x < strlen(s); x++) {
7738 temp[x] = tolower(s[x]);
7741 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
7747 if (!setlocale(LC_CTYPE, "")) {
7748 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
7752 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
7765 free(current_config);
7766 current_config = strdup(optarg);
7771 "Usage: %s [OPTION]...\n"
7772 "Conky is a system monitor that renders text on desktop or to own transparent\n"
7773 "window. Command line options will override configurations defined in config\n"
7775 " -V, --version version\n"
7776 " -c, --config=FILE config file to load\n"
7777 " -d, --daemonize daemonize, fork to background\n"
7778 " -h, --help help\n"
7780 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom}_{left,right}\n"
7781 " -f, --font=FONT font to use\n"
7783 " -o, --own-window create own window to draw\n"
7786 " -b, --double-buffer double buffer (prevents flickering)\n"
7788 " -w, --window-id=WIN_ID window id to draw\n"
7789 " -x X x position\n"
7790 " -y Y y position\n"
7792 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
7793 " -u, --interval=SECS update interval\n"
7794 " -i NUM number of times to update Conky\n",
7800 window.window = strtol(optarg, 0, 0);
7809 /* initalize X BEFORE we load config. (we need to so that 'screen' is set) */
7813 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
7815 if (!current_config) {
7816 /* load default config file */
7820 /* Try to use personal config file first */
7821 variable_substitute(CONFIG_FILE, buf, sizeof(buf));
7822 if (buf[0] && (fp=fopen(buf,"r"))) {
7823 current_config = strdup(buf);
7827 /* Try to use system config file if personal config not readable */
7828 if (!current_config && (fp=fopen(SYSTEM_CONFIG_FILE,"r"))) {
7829 current_config = strdup(SYSTEM_CONFIG_FILE);
7833 /* No readable config found */
7834 if (!current_config)
7835 CRIT_ERR("no readable personal or system-wide config file found");
7838 load_config_file(current_config);
7840 /* init specials array */
7841 if ((specials = calloc (sizeof(struct special_t), max_specials)) == 0)
7842 ERR("failed to create specials array");
7845 if (current_mail_spool == NULL) {
7847 variable_substitute(MAIL_FILE, buf, 256);
7850 current_mail_spool = strdup(buf);
7854 /* handle other command line arguments */
7856 #if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__)
7857 optind = optreset = 1;
7862 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
7863 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
7864 O_RDONLY, "kvm_open")) == NULL)
7865 CRIT_ERR( "cannot read kvm");
7869 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
7878 fork_to_background = 1;
7883 set_first_font(optarg);
7886 text_alignment = string_to_alignment(optarg);
7903 text = strdup(optarg);
7904 convert_escapes(text);
7908 update_interval = strtod(optarg, 0);
7909 if (info.music_player_interval == 0) {
7910 // default to update_interval
7911 info.music_player_interval = update_interval;
7916 total_run_times = strtod(optarg, 0);
7920 gap_x = atoi(optarg);
7924 gap_y = atoi(optarg);
7938 /* generate text and get initial size */
7939 extract_variable_text(text);
7945 if (fork_to_background) {
7949 ERR("Conky: couldn't fork() to background: %s", strerror(errno));
7955 fprintf(stderr,"\n"); fflush(stderr);
7959 /* parent process */
7960 fprintf(stderr,"Conky: forked to background, pid is %d\n", pid); fflush(stderr);
7967 update_text_area(); /* to get initial size of the window */
7971 text_width + border_margin * 2 + 1,
7972 text_height + border_margin * 2 + 1,
7973 set_transparent, background_colour, argv, argc);
7976 update_text_area(); /* to position text/window on screen */
7981 if (own_window && !fixed_pos) {
7982 XMoveWindow(display, window.window, window.x, window.y);
7985 set_transparent_background(window.window);
7996 /* Set signal handlers */
7997 act.sa_handler = signal_handler;
7998 sigemptyset(&act.sa_mask);
8001 act.sa_flags |= SA_RESTART;
8004 if ( sigaction(SIGINT,&act,&oact) < 0 ||
8005 sigaction(SIGUSR1,&act,&oact) < 0 ||
8006 sigaction(SIGTERM,&act,&oact) < 0 )
8008 ERR("error setting signal handler: %s", strerror(errno) );
8012 if (create_audacious_thread() !=0)
8013 CRIT_ERR("unable to create audacious thread!");
8014 timed_thread_register (info.audacious.p_timed_thread, &info.audacious.p_timed_thread);
8025 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8032 void signal_handler(int sig)
8034 /* signal handler is light as a feather, as it should be.
8035 * we will poll g_signal_pending with each loop of conky
8036 * and do any signal processing there, NOT here. */
8037 g_signal_pending=sig;